interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / server / agents.om

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