omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / apps / interplane-forge / server / agents.om
| 1 | note forged server/agents.om (ForgeServer, prefix fqa / tfqa): <base>agents.json, schema interplane/agents/1 |
| 2 | note (docs/API.md, docs/AGENT-DOOR.md): the one document an agent reads first. Its routes come from |
| 3 | note server/agents.tsv, which run.sh compiles into .build/agents.om (the text tfqatsv, composed just |
| 4 | note above this unit) at every build, so the list cannot drift from the table; server/tests/agentdoor.sh |
| 5 | note fetches every row and checks the schema it answers. Rows whose first field is "none" are the |
| 6 | note not_available list. The event rows move to not_available in a build without the event store |
| 7 | note (server/nodoor.om: evon is false, those pages answer 501). |
| 8 | text tfqapj "/agents.json" |
| 9 | text tfqa1 "{\"schema\":\"interplane/agents/1\",\"base\":\"" |
| 10 | text tfqa2 "\",\n\"read_first\":\"" |
| 11 | text tfqa3 "agents.json\",\n\"how_to_ask\":{\"suffix\":\"the path itself is the JSON name\",\"accept\":\"send Accept: application/json (and not text/html); the HTML page names the same address in <link rel=alternate type=application/json>\",\"always\":\"JSON whatever the headers say\"},\n\"text_form\":\"add format=text to the query of any HTML page for its plain-text form (text/plain; charset=utf-8)\",\n\"error_schema\":\"forge/error/1\",\n\"events\":" |
| 12 | text tfqae1 "{\"path\":\"" |
| 13 | text tfqae2 "events.json\",\"schema\":\"interplane/events/1\",\"after\":\"after=<seq> answers the events with a higher seq, oldest first; next is the address to read next\",\"limit_default\":50,\"limit_max\":200,\"etag\":\"send If-None-Match with the ETag of the last answer: an unchanged stream answers 304\",\"feed\":\"" |
| 14 | text tfqae3 "feed\"}" |
| 15 | text tfqar ",\n\"routes\":[" |
| 16 | text tfqan "\n],\n\"not_available\":[" |
| 17 | text tfqaz "\n]}\n" |
| 18 | text tfqanone "none" |
| 19 | text tfqameth "method" |
| 20 | text tfqadash "-" |
| 21 | text tfqaevs "interplane/events/1" |
| 22 | text tfqano "this build has no event store (server/nodoor.om): the address answers 501" |
| 23 | text tfqk1 "\n{\"method\":" |
| 24 | text tfqk2 ",\"path\":" |
| 25 | text tfqk3 ",\"json\":" |
| 26 | text tfqk4 ",\"schema\":" |
| 27 | text tfqk5 ",\"auth\":" |
| 28 | text tfqk6 ",\"doc\":" |
| 29 | text tfqk7 ",\"purpose\":" |
| 30 | text tfqw1 "\n{\"what\":" |
| 31 | text tfqw2 ",\"why\":" |
| 32 | global fqan ulong 1 |
| 33 | global fqatb ulong 8 |
| 34 | note fqajsn: a request for a .json name asks for JSON, so its errors are forge/error/1 documents too |
| 35 | note (ferrpage answers JSON when fjwant is true) |
| 36 | fn fqajsn to void |
| 37 | for i ulong len tfjaj bound 64 |
| 38 | put facc i get tfjaj i |
| 39 | end |
| 40 | put faccl 0 len tfjaj |
| 41 | end |
| 42 | fn fqaroute to long |
| 43 | if not fpeq tfqapj |
| 44 | ret 0 |
| 45 | end |
| 46 | fqajsn |
| 47 | if not fget |
| 48 | ret 405 |
| 49 | end |
| 50 | fjstart |
| 51 | fput tfqa1 |
| 52 | fputb |
| 53 | fput tfqa2 |
| 54 | fputb |
| 55 | fput tfqa3 |
| 56 | if evon |
| 57 | fput tfqae1 |
| 58 | fputb |
| 59 | fput tfqae2 |
| 60 | fputb |
| 61 | fput tfqae3 |
| 62 | else |
| 63 | fynull |
| 64 | end |
| 65 | fput tfqar |
| 66 | fqarows 1 |
| 67 | fput tfqan |
| 68 | fqarows 2 |
| 69 | fput tfqaz |
| 70 | ret 200 |
| 71 | end |
| 72 | note fqarows mode: walk the lines of tfqatsv; mode 1 the routes, mode 2 the not_available list |
| 73 | fn fqarows mode ulong to void |
| 74 | put fqan 0 0 |
| 75 | n = len tfqatsv |
| 76 | p = ulong 0 |
| 77 | for it ulong 4096 |
| 78 | if ge p n |
| 79 | break |
| 80 | end |
| 81 | q = p |
| 82 | for k ulong 65536 |
| 83 | if ge q n |
| 84 | break |
| 85 | end |
| 86 | if eq get tfqatsv q 10 |
| 87 | break |
| 88 | end |
| 89 | q = add q 1 |
| 90 | end |
| 91 | fqaline p q mode |
| 92 | p = add q 1 |
| 93 | end |
| 94 | end |
| 95 | note fqaline p q mode: one row tfqatsv[p, q) with 7 tab-separated fields (the header row is skipped) |
| 96 | fn fqaline p ulong q ulong mode ulong to void |
| 97 | k = ulong 0 |
| 98 | for i ulong sub q p bound 65536 |
| 99 | if eq get tfqatsv add p i 9 |
| 100 | if lt k 8 |
| 101 | put fqatb k add p i |
| 102 | end |
| 103 | k = add k 1 |
| 104 | end |
| 105 | end |
| 106 | if ne k 6 |
| 107 | ret |
| 108 | end |
| 109 | if fqaeq p get fqatb 0 tfqameth |
| 110 | ret |
| 111 | end |
| 112 | none = fqaeq p get fqatb 0 tfqanone |
| 113 | ev = fqaeq fqafa 3 get fqatb 3 tfqaevs |
| 114 | off = and ev not evon |
| 115 | if eq mode 1 |
| 116 | if or none off |
| 117 | ret |
| 118 | end |
| 119 | fqasep |
| 120 | fput tfqk1 |
| 121 | fqastr p get fqatb 0 false |
| 122 | fput tfqk2 |
| 123 | fqastr fqafa 1 get fqatb 1 true |
| 124 | fqarow2 q |
| 125 | ret |
| 126 | end |
| 127 | if none |
| 128 | fqasep |
| 129 | fput tfqw1 |
| 130 | fqastr fqafa 1 get fqatb 1 false |
| 131 | fput tfqw2 |
| 132 | fqastr fqafa 6 q false |
| 133 | fputc 125 |
| 134 | ret |
| 135 | end |
| 136 | if off |
| 137 | fqasep |
| 138 | fput tfqw1 |
| 139 | fqastr fqafa 1 get fqatb 1 true |
| 140 | fput tfqw2 |
| 141 | fjtxt tfqano |
| 142 | fputc 125 |
| 143 | end |
| 144 | end |
| 145 | fn fqarow2 q ulong to void |
| 146 | fput tfqk3 |
| 147 | fqastr fqafa 2 get fqatb 2 false |
| 148 | fput tfqk4 |
| 149 | if fqaeq fqafa 3 get fqatb 3 tfqadash |
| 150 | fynull |
| 151 | else |
| 152 | fqastr fqafa 3 get fqatb 3 false |
| 153 | end |
| 154 | fput tfqk5 |
| 155 | fqastr fqafa 4 get fqatb 4 false |
| 156 | fput tfqk6 |
| 157 | fqastr fqafa 5 get fqatb 5 false |
| 158 | fput tfqk7 |
| 159 | fqastr fqafa 6 q false |
| 160 | fputc 125 |
| 161 | end |
| 162 | note fqafa f: the start of field f (f >= 1): just after tab f-1 |
| 163 | fn fqafa f ulong to ulong |
| 164 | ret add get fqatb sub f 1 1 |
| 165 | end |
| 166 | fn fqasep to void |
| 167 | if gt get fqan 0 0 |
| 168 | fputc 44 |
| 169 | end |
| 170 | put fqan 0 add get fqan 0 1 |
| 171 | end |
| 172 | fn fqaeq a ulong e ulong t view uchar * to bool |
| 173 | if ne sub e a len t |
| 174 | ret false |
| 175 | end |
| 176 | for i ulong len t bound 64 |
| 177 | if ne get tfqatsv add a i get t i |
| 178 | ret false |
| 179 | end |
| 180 | end |
| 181 | ret true |
| 182 | end |
| 183 | note fqastr a e base: tfqatsv[a, e) as a JSON string, after the base when base is true |
| 184 | fn fqastr a ulong e ulong base bool to void |
| 185 | fjtb |
| 186 | if base |
| 187 | for i ulong get fbasel 0 bound 64 |
| 188 | fjtc get fbase i |
| 189 | end |
| 190 | end |
| 191 | for i ulong sub e a bound 65536 |
| 192 | fjtc get tfqatsv add a i |
| 193 | end |
| 194 | fjstr |
| 195 | end |