interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / research / route.om

508 lines · 10790 bytes Raw Blame History
1note research/route.om: the research pages inside forged. Prefix rx* (functions), gx* (globals), tx* (texts).
2note forged builds nothing here. research-build (research/build.om, its own program, run by
3note research/publish.sh) writes the pages into <data>research/; forged streams those files:
4note /research, /research/ research/index.html
5note /research.json .bib .txt research/index.json, works.bib, agents.txt
6note /assets/research.css research/research.css
7note /research/<slug>[.json|.bib] research/w/<slug>.html, .json, .bib
8note Questions: GET /research/ask?q=... writes the question to research/ask/<id>.q, appends one
9note line "<id> <tab> <question>" to research/ask/queue and answers 303 to /research/ask/<id>.
10note forged has no network and never calls a model. The research agent (research/agent.om, its own
11note service outside the sandbox) reads the queue and writes research/ask/<id>.html and .json.
12note /research/ask/<id>[.json] streams the answer when it exists, else a page that reloads itself.
13note <id> is the first 32 hex characters of SHA-256 over the lowercased, space-collapsed question, so
14note the same question is asked once. Served on the interplane.io base "/" only, as the galaxy is.
15text txp "/research"
16text txps "/research/"
17text txpj "/research.json"
18text txpb "/research.bib"
19text txpt "/research.txt"
20text txpc "/assets/research.css"
21text txpa "/research/ask"
22text txpas "/research/ask/"
23text txdir "research/"
24text txask "research/ask/"
25text txw "research/w/"
26text txfi "index.html"
27text txfj "index.json"
28text txfb "works.bib"
29text txft "agents.txt"
30text txfc "research.css"
31text txfq "queue"
32text txeh ".html"
33text txej ".json"
34text txeb ".bib"
35text txeq ".q"
36text txno ""
37text txcth "text/html; charset=utf-8"
38text txctj "application/json; charset=utf-8"
39text txctt "text/plain; charset=utf-8"
40text txctc "text/css; charset=utf-8"
41text txcc "public, max-age=60"
42text txq "q"
43text txhex "0123456789abcdef"
44text txloc "research/ask/"
45text txhome "research"
46text txw1 "<!doctype html><html lang='en' data-theme='dark'><head><meta charset='utf-8'><meta name='viewport' content='width=device-width,initial-scale=1'><meta http-equiv='refresh' content='4'><title>Reading the papers</title><link rel='stylesheet' href='/assets/tokens.css'><link rel='stylesheet' href='/assets/research.css'></head><body>\n<header class='top'><a class='wm' href='/'>INTERPLANE</a><nav><a href='/galaxy'>Galaxy</a><a href='/explore'>Explore</a><a class='on' href='/research'>Research</a><a href='/open/'>Open builds</a><a href='/salvage/'>Bring your build</a></nav></header>\n<main><section class='card'><p class='eyebrow'>Question</p><h2>"
47text txw2 "</h2><p class='wait'>The agent on the Spark is reading the papers. Its model answers one question at a time, so this can take a minute. This page reloads by itself. You can also keep the link and come back.</p><p class='try'><a href='/research'>Back to the research</a></p></section></main></body></html>\n"
48text txj1 "{\"schema\":\"interplane/research-answer/1\",\"status\":\"pending\",\"id\":\""
49text txj2 "\"}\n"
50global gxq uchar 304
51global gxql ulong 1
52global gxid uchar 32
53text txcur "current"
54text txgen "gen/public."
55note rxfile: pin current once; fsend3 may open later, so ffile must not contain current.
56note Every published generation is retained; mutable ask/add paths do not use this function.
57fn rxroot to void
58v = new uchar 4096 0
59put ffilel 0 0
60for i ulong len tfdata bound 128
61ffilc get tfdata i
62end
63for i ulong len txdir bound 64
64ffilc get txdir i
65end
66base = get ffilel 0
67for i ulong len txcur bound 16
68ffilc get txcur i
69end
70k = readlnk ffile 0 get ffilel 0 v 0 4096
71put ffilel 0 0
72if or le k long len txgen ge k 4096
73ret
74end
75for i ulong len txgen bound 16
76if ne get v i get txgen i
77ret
78end
79end
80for i ulong sub ulong k len txgen bound 4096
81c = get v add i len txgen
82ok = or and ge c 48 le c 57 and ge c 65 le c 90
83ok = or ok and ge c 97 le c 122
84if not ok
85ret
86end
87end
88put ffilel 0 base
89for i ulong ulong k bound 4096
90ffilc get v i
91end
92ffilc 47
93end
94fn rxfile dir view uchar * a ulong n ulong ext view uchar * to void
95rxroot
96if eq get ffilel 0 0
97ret
98end
99for i ulong sub len dir len txdir bound 64
100ffilc get dir add len txdir i
101end
102for i ulong n bound 64
103ffilc fpathat add a i
104end
105for i ulong len ext bound 16
106ffilc get ext i
107end
108end
109note rxidfile: ffile = <data>research/ask/<gxid><ext>
110fn rxidfile ext view uchar * to void
111put ffilel 0 0
112for i ulong len tfdata bound 128
113ffilc get tfdata i
114end
115for i ulong len txask bound 64
116ffilc get txask i
117end
118for i ulong 32
119ffilc get gxid i
120end
121for i ulong len ext bound 16
122ffilc get ext i
123end
124end
125fn rxhas to bool
126if eq get ffilel 0 0
127ret false
128end
129ret eq faccess ffile 0 get ffilel 0 4 0
130end
131note rxsend: stream ffile (kind 3). GET only; a file that is not there is 404.
132fn rxsend ct view uchar * to long
133if not fget
134ret 405
135end
136if not rxhas
137ret 404
138end
139put fobl 0 0
140put fkind 0 3
141fsetct ct
142fsetcc txcc
143ret 200
144end
145note rxends: fpath ends with t
146fn rxends t view uchar * to bool
147n = get fpathl 0
148if lt n len t
149ret false
150end
151b = sub n len t
152for i ulong len t bound 16
153if ne fpathat add b i get t i
154ret false
155end
156end
157ret true
158end
159note rxslug: fpath[a, a+n) is 1 to 64 bytes of a-z, 0-9 and -
160fn rxslug a ulong n ulong to bool
161if or eq n 0 gt n 64
162ret false
163end
164for i ulong n bound 64
165c = fpathat add a i
166ok = false
167if and ge c 97 le c 122
168ok = true
169end
170if and ge c 48 le c 57
171ok = true
172end
173if eq c 45
174ok = true
175end
176if not ok
177ret false
178end
179end
180ret true
181end
182note rxhexs: fpath[a, a+32) is 32 lowercase hex characters; they are copied into gxid
183fn rxhexs a ulong n ulong to bool
184if ne n 32
185ret false
186end
187for i ulong 32
188c = fpathat add a i
189ok = false
190if and ge c 48 le c 57
191ok = true
192end
193if and ge c 97 le c 102
194ok = true
195end
196if not ok
197ret false
198end
199put gxid i c
200end
201ret true
202end
203note rxwork: /research/<slug>[.json|.bib]
204fn rxwork to long
205a = len txps
206n = sub get fpathl 0 a
207if rxends txej
208n = sub n len txej
209if not rxslug a n
210ret 404
211end
212rxfile txw a n txej
213ret rxsend txctj
214end
215if rxends txeb
216n = sub n len txeb
217if not rxslug a n
218ret 404
219end
220rxfile txw a n txeb
221ret rxsend txctt
222end
223if not rxslug a n
224ret 404
225end
226rxfile txw a n txeh
227ret rxsend txcth
228end
229note rxnorm: the decoded question fval[0, n) into gxq: control bytes become a space, runs of spaces
230note become one, no space at either end. False when nothing is left or it is over 300 bytes.
231fn rxnorm n ulong to bool
232o = ulong 0
233sp = true
234for i ulong n bound 4096
235c = get fval i
236if or lt c 32 eq c 127
237c = uchar 32
238end
239if eq c 32
240if not sp
241if ge o 300
242ret false
243end
244put gxq o c
245o = add o 1
246end
247sp = true
248else
249if ge o 300
250ret false
251end
252put gxq o c
253o = add o 1
254sp = false
255end
256end
257if gt o 0
258if eq get gxq sub o 1 32
259o = sub o 1
260end
261end
262put gxql 0 o
263ret gt o 0
264end
265note rxmkid: gxid from gxq (ASCII letters lowercased before hashing)
266fn rxmkid to void
267b = new uchar 304 0
268d = new uchar 32 0
269n = get gxql 0
270for i ulong n bound 304
271c = get gxq i
272if and ge c 65 le c 90
273c = uchar add c 32
274end
275put b i c
276end
277r = sha2_digest 256 view part b 0 n d
278for i ulong 16
279v = get d i
280put gxid mul i 2 get txhex ulong shr v 4
281put gxid add mul i 2 1 get txhex ulong and v 15
282end
283end
284note rxgo: 303 to <base>research/ask/<gxid>
285fn rxgo to long
286flocb
287floct txloc
288for i ulong 32
289flocc get gxid i
290end
291put fkind 0 2
292ret 303
293end
294note rxqueue: write the question file and append the queue line. 0 done, else the status to answer.
295fn rxqueue to long
296b = new uchar 352 0
297st = new uchar 128 0
298n = get gxql 0
299put ffilel 0 0
300for i ulong len tfdata bound 128
301ffilc get tfdata i
302end
303for i ulong len txdir bound 64
304ffilc get txdir i
305end
306r = makedir ffile 0 get ffilel 0 448
307for i ulong sub len txask len txdir bound 64
308ffilc get txask add len txdir i
309end
310r = makedir ffile 0 get ffilel 0 448
311for i ulong len txfq bound 16
312ffilc get txfq i
313end
314fd = fopen ffile 0 get ffilel 0 558145 384
315if lt fd 0
316ret 503
317end
318r = fstat int fd st 0 128
319sz = or or ulong get st 48 shl ulong get st 49 8 or shl ulong get st 50 16 shl ulong get st 51 24
320if or ne r 0 gt sz 4194304
321x = fclose int fd
322put fretry 0 60
323ret 503
324end
325for i ulong 32
326put b i get gxid i
327end
328put b 32 9
329for i ulong n bound 304
330put b add 33 i get gxq i
331end
332put b add 33 n 10
333w = write int fd b 0 add 34 n
334x = fclose int fd
335if ne w long add 34 n
336ret 503
337end
338rxidfile txeq
339fd = fopen ffile 0 get ffilel 0 557249 384
340if ge fd 0
341w = write int fd b 33 n
342x = fclose int fd
343end
344ret 0
345end
346note rxask: /research/ask?q=...
347fn rxask to long
348if not fget
349ret 405
350end
351n = fqget txq
352if le n 0
353flocb
354floct txhome
355put fkind 0 2
356ret 303
357end
358if not rxnorm ulong n
359ret 400
360end
361rxmkid
362rxidfile txeh
363if rxhas
364ret rxgo
365end
366rxidfile txeq
367if rxhas
368ret rxgo
369end
370if not fratelim
371ret 429
372end
373r = rxqueue
374if ne r 0
375ret r
376end
377ret rxgo
378end
379note rxpend: the answer is not written yet. The question file must exist (else 404).
380fn rxpend json bool to long
381b = new uchar 304 0
382if not fget
383ret 405
384end
385rxidfile txeq
386fd = fopen ffile 0 get ffilel 0 557056 0
387if lt fd 0
388ret 404
389end
390n = read int fd b 0 300
391x = fclose int fd
392put fobl 0 0
393put fkind 0 1
394if json
395fput txj1
396for i ulong 32
397fputc get gxid i
398end
399fput txj2
400fsetct txctj
401ret 200
402end
403fput txw1
404if gt n 0
405for i ulong ulong n bound 300
406fescc get b i
407end
408end
409fput txw2
410fsetct txcth
411ret 200
412end
413note rxans: /research/ask/<id>[.json]
414fn rxans to long
415a = len txpas
416n = sub get fpathl 0 a
417json = rxends txej
418if json
419n = sub n len txej
420end
421if not rxhexs a n
422ret 404
423end
424if json
425rxidfile txej
426else
427rxidfile txeh
428end
429if rxhas
430if json
431ret rxsend txctj
432end
433ret rxsend txcth
434end
435ret rxpend json
436end
437note rxone: ffile = <data>research/<name>, then stream it
438fn rxone name view uchar * ct view uchar * to long
439rxfile txdir 0 0 name
440ret rxsend ct
441end
442text txnav "<a href=\"/research\">Research</a>"
443note rxnav: the forge row entry (server/pages.om fhead); the research pages exist on base "/" only
444fn rxnav to void
445if eq get fbasel 0 1
446fput txnav
447end
448end
449text txauth "/research/authors/"
450text txadir "research/a/"
451text txadd "/research/add"
452text txdoi "/research/doi"
453text txaf "add.html"
454text txdf "doi.html"
455note rxauthor: one validated author id, no path separators, into research/a/<id>.html
456fn rxauthor to long
457a = len txauth
458n = sub get fpathl 0 a
459if not rxslug a n
460ret 404
461end
462rxfile txadir a n txeh
463ret rxsend txcth
464end
465note rxroute: 0 = not a research path
466fn rxroute to long
467if ne get fbasel 0 1
468ret 0
469end
470r = rxint
471if ne r 0
472ret r
473end
474if fpre txauth
475ret rxauthor
476end
477if fpeq txadd
478ret rxone txaf txcth
479end
480if fpeq txdoi
481ret rxone txdf txcth
482end
483if fpeq txpc
484ret rxone txfc txctc
485end
486if fpeq txpj
487ret rxone txfj txctj
488end
489if fpeq txpb
490ret rxone txfb txctt
491end
492if fpeq txpt
493ret rxone txft txctt
494end
495if or fpeq txp fpeq txps
496ret rxone txfi txcth
497end
498if not fpre txps
499ret 0
500end
501if fpeq txpa
502ret rxask
503end
504if fpre txpas
505ret rxans
506end
507ret rxwork
508end