interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / core / sovereign-core / om / qwen-native / flash / serve.om

600 lines · 11989 bytes Raw Blame History
1note flash-serve 38 MODEL_DIR PORT KEYFILE [SLOTS]: one Flash-Next text model behind HTTP/1.1 on 127.0.0.1.
2note Writes `PORT n` to stderr once the model is loaded and the socket listens.
3note GET /health 200 application/json
4note POST /v1/chat/completions messages, max_tokens (default 256, at most 1024), stream; Authorization: Bearer KEY
5note One request at a time. Each request is a fresh sequence. Greedy decoding, reasoning off.
6text snhealth "/health"
7text snchat "/v1/chat/completions"
8text sget "GET"
9text spost "POST"
10text sjson "application/json"
11text sctype "Content-Type"
12text sauth "authorization"
13text sbearer "Bearer "
14text shealth "{\"status\":\"ok\",\"model\":\"qwen3.8-flash-next-fp8\",\"engine\":\"omega\"}"
15text skmsg "messages"
16text skrole "role"
17text skcontent "content"
18text skmax "max_tokens"
19text skstream "stream"
20text sims "<|im_start|>"
21text sime "<|im_end|>\n"
22text sgen "<|im_start|>assistant\n<think>\n\n</think>\n\n"
23text sport "PORT "
24text sc0 "{\"id\":\"flash-next\",\"object\":\"chat.completion.chunk\",\"model\":\"qwen3.8-flash-next-fp8\",\"choices\":[{\"index\":0,\"delta\":{\"content\":\""
25text sc1 "\"},\"finish_reason\":null}]}"
26text sf0 "{\"id\":\"flash-next\",\"object\":\"chat.completion.chunk\",\"model\":\"qwen3.8-flash-next-fp8\",\"choices\":[{\"index\":0,\"delta\":{},\"finish_reason\":\""
27text sf1 "\"}],\"usage\":{\"prompt_tokens\":"
28text sstop "stop"
29text slength "length"
30text su1 ",\"completion_tokens\":"
31text su2 ",\"total_tokens\":"
32text su3 "},\"timings\":{\"first_token_ms\":"
33text su4 ",\"decode_ms\":"
34text su5 ",\"expert_loads\":"
35text su6 ",\"expert_evictions\":"
36text su7 "}}"
37text sdone "[DONE]"
38text sm0 "{\"id\":\"flash-next\",\"object\":\"chat.completion\",\"model\":\"qwen3.8-flash-next-fp8\",\"choices\":[{\"index\":0,\"message\":{\"role\":\"assistant\",\"content\":\""
39text sm1 "\"},\"finish_reason\":\""
40global skey uchar 160
41note sreq: 0 max tokens, 1 stream, 2 rendered bytes, 3 start ns, 4 first-token ns, 5 end ns, 6 completion tokens, 7 stopped at end of turn, 8 key bytes.
42global sreq ulong 9
43global sacc uchar 4096
44global saccn ulong 1
45
46fn sputc c uchar to bool
47n = get sreq 2
48if ge n len input
49r = enlarge input add mul 2 n 4096
50if lt r 0
51ret false
52end
53end
54put input n c
55put sreq 2 add n 1
56ret true
57end
58
59fn sputs t view uchar * to bool
60for i ulong len t
61if not sputc get t i
62ret false
63end
64end
65ret true
66end
67
68note Value token of member name in object obj, or jsnone.
69fn sfind src view uchar 1048576 tape edit uint 262160 obj ulong name view uchar * to ulong
70if ne js_type tape obj jsobj
71ret jsnone
72end
73k = js_first tape obj
74while ne k jsnone bound 4096
75if js_streq src js_off tape k name
76ret add k 1
77end
78k = js_mnext tape k
79end
80ret jsnone
81end
82
83fn smessage src view uchar 1048576 tape edit uint 262160 m ulong txt edit uchar 1048576 to bool
84r = sfind src tape m skrole
85c = sfind src tape m skcontent
86if or eq r jsnone eq c jsnone
87ret false
88end
89if or ne js_type tape r jsstr ne js_type tape c jsstr
90ret false
91end
92n = js_sget src js_off tape r txt
93if or le n 0 gt n 16
94ret false
95end
96ok = sputs sims
97for i ulong ulong n
98ch = get txt i
99if or lt ch 97 gt ch 122
100ret false
101end
102ok = and ok sputc ch
103end
104ok = and ok sputc 10
105n = js_sget src js_off tape c txt
106if lt n 0
107ret false
108end
109for i ulong ulong n
110ok = and ok sputc get txt i
111end
112ret and ok sputs sime
113end
114
115note Parse the request body of nb bytes and render the chat into the tokenizer input. False refuses the request.
116fn srender src view uchar 1048576 tape edit uint 262160 nb ulong txt edit uchar 1048576 to bool
117put sreq 0 256
118put sreq 1 0
119put sreq 2 0
120if lt js_init tape nb 32 0
121ret false
122end
123if lt js_parse src tape nb 0
124ret false
125end
126v = sfind src tape 0 skmax
127if ne v jsnone
128if ne js_type tape v jsnum
129ret false
130end
131if not js_isu src js_off tape v
132ret false
133end
134mx = js_tou src js_off tape v
135if or eq mx 0 gt mx 1024
136ret false
137end
138put sreq 0 mx
139end
140v = sfind src tape 0 skstream
141if ne v jsnone
142if eq js_type tape v jstrue
143put sreq 1 1
144end
145end
146v = sfind src tape 0 skmsg
147if eq v jsnone
148ret false
149end
150if or ne js_type tape v jsarr eq js_nkids tape v 0
151ret false
152end
153m = js_first tape v
154while ne m jsnone bound 4096
155if not smessage src tape m txt
156ret false
157end
158m = js_enext tape m
159end
160ret sputs sgen
161end
162
163fn sdec b edit uchar 8192 p ulong v ulong to ulong
164d = new uchar 20 0
165i = ulong 20
166x = v
167for it ulong 20
168i = sub i 1
169put d i uchar add rem x 10 48
170x = div x 10
171if eq x 0
172break
173end
174end
175q = p
176for k ulong sub 20 i
177put b q get d add i k
178q = add q 1
179end
180ret q
181end
182
183fn scat b edit uchar 8192 p ulong t view uchar * to ulong
184for i ulong len t
185put b add p i get t i
186end
187ret add p len t
188end
189
190note JSON string escape of one byte into b at p.
191fn sesc b edit uchar 8192 p ulong c uchar to ulong
192if or eq c 34 eq c 92
193put b p 92
194put b add p 1 c
195ret add p 2
196end
197if ge c 32
198put b p c
199ret add p 1
200end
201put b p 92
202put b add p 1 117
203put b add p 2 48
204put b add p 3 48
205put b add p 4 hhexd shr ulong c 4
206put b add p 5 hhexd and ulong c 15
207ret add p 6
208end
209
210note Bytes at the start of sacc that end on a UTF-8 character boundary.
211fn swhole to ulong
212n = get saccn 0
213back = ulong 0
214while and lt back 4 lt back n bound 4
215c = get sacc sub sub n 1 back
216if lt c 128
217ret n
218end
219if ge c 192
220need = ulong 2
221if ge c 224
222need = ulong 3
223end
224if ge c 240
225need = ulong 4
226end
227if ge add back 1 need
228ret n
229end
230ret sub sub n 1 back
231end
232back = add back 1
233end
234ret n
235end
236
237fn stoken id ulong to void
238if ge id len sizes
239ret
240end
241w = ulong get sizes id
242n = get saccn 0
243if gt add n w len sacc
244ret
245end
246o = get starts id
247for j ulong w
248c = get spelling add o j
249put sacc add n j c
250end
251put saccn 0 add n w
252end
253
254note Drop the first k bytes of sacc.
255fn sdrop k ulong to void
256n = get saccn 0
257for j ulong sub n k
258put sacc j get sacc add k j
259end
260put saccn 0 sub n k
261end
262
263note Usage and timing members shared by both response forms, appended to b at p.
264fn susage b edit uchar 8192 p ulong to ulong
265count = get qnids 0
266made = get sreq 6
267q = sdec b p count
268q = scat b q su1
269q = sdec b q made
270q = scat b q su2
271q = sdec b q add count made
272q = scat b q su3
273q = sdec b q div sub get sreq 4 get sreq 3 1000000
274q = scat b q su4
275q = sdec b q div sub get sreq 5 get sreq 4 1000000
276q = scat b q su5
277q = sdec b q get qecfg 4
278q = scat b q su6
279q = sdec b q get qecfg 5
280ret scat b q su7
281end
282
283fn sreason b edit uchar 8192 p ulong to ulong
284if eq get sreq 7 1
285ret scat b p sstop
286end
287ret scat b p slength
288end
289
290note One streamed content event from the whole characters now in sacc.
291fn sevent cs edit ulong 320 io edit uchar 131072 ev edit uchar 8192 to long
292k = swhole
293if eq k 0
294ret 0
295end
296if gt k 1024
297k = 1024
298end
299q = scat ev 0 sc0
300for j ulong k
301q = sesc ev q get sacc j
302end
303q = scat ev q sc1
304sdrop k
305r = hssedat cs io view part ev 0 q
306ret hfe r hsseend cs io
307end
308
309note sst: 0 current token, 1 escaped text bytes gathered in txt.
310global sst ulong 2
311fn sprefill to void
312count = get qnids 0
313put sreq 3 ulong monons
314put sreq 6 0
315put sreq 7 0
316put saccn 0 0
317put sst 1 0
318id = ulong 0
319for j ulong count
320id = qtoken ulong get qids j j eq add j 1 count
321end
322put sst 0 id
323put sreq 4 ulong monons
324end
325
326fn sgather ev edit uchar 8192 txt edit uchar 1048576 to bool
327k = get saccn 0
328n = get sst 1
329if gt add n mul k 6 len txt
330ret false
331end
332q = ulong 0
333for i ulong k
334q = sesc ev q get sacc i
335end
336for i ulong q
337put txt add n i get ev i
338end
339put sst 1 add n q
340put saccn 0 0
341ret true
342end
343
344note Prefill the prompt, then decode. With stream set each token is sent as it is made; otherwise text gathers in txt.
345fn sdecode cs edit ulong 320 io edit uchar 131072 ev edit uchar 8192 txt edit uchar 1048576 to long
346sprefill
347count = get qnids 0
348for j ulong get sreq 0
349id = get sst 0
350if or eq id 248044 eq id 248046
351put sreq 7 1
352break
353end
354put sreq 6 add j 1
355stoken id
356if eq get sreq 1 1
357r = sevent cs io ev
358if lt r 0
359ret r
360end
361else
362if not sgather ev txt
363ret HEBIG
364end
365end
366if lt add j 1 get sreq 0
367put sst 0 qtoken id add count j true
368end
369end
370put sreq 5 ulong monons
371ret long get sst 1
372end
373
374fn sfinish cs edit ulong 320 io edit uchar 131072 ev edit uchar 8192 to long
375q = scat ev 0 sf0
376q = sreason ev q
377q = scat ev q sf1
378q = susage ev q
379r = hssedat cs io view part ev 0 q
380r = hfe r hsseend cs io
381r = hfe r hssedat cs io sdone
382r = hfe r hsseend cs io
383ret hfe r hwfin cs io
384end
385
386fn swhole1 cs edit ulong 320 io edit uchar 131072 ev edit uchar 8192 txt edit uchar 1048576 n ulong to long
387q = scat ev 0 sm1
388q = sreason ev q
389q = scat ev q sf1
390q = susage ev q
391r = hrspst cs io 200
392r = hfe r hhname cs io sctype
393r = hfe r hhval cs io sjson
394r = hfe r hhend cs io 0 add add len sm0 n q
395r = hfe r hput cs io sm0
396r = hfe r hput cs io view part txt 0 n
397r = hfe r hput cs io view part ev 0 q
398ret hfe r hwfin cs io
399end
400
401fn sauthorized cs edit ulong 320 io edit uchar 131072 to bool
402i = hhfind cs io sauth
403if lt i 0
404ret false
405end
406o = hhvoff cs ulong i
407n = hhvlen cs ulong i
408kn = get sreq 8
409if ne n add len sbearer kn
410ret false
411end
412diff = ulong 0
413for j ulong len sbearer
414diff = or diff ulong xor get io add o j get sbearer j
415end
416for j ulong kn
417diff = or diff ulong xor get io add add o len sbearer j get skey j
418end
419ret eq diff 0
420end
421
422fn schat cs edit ulong 320 io edit uchar 131072 body edit uchar 1048576 tape edit uint 262160 to long
423txt = new uchar 1048576 0
424ev = new uchar 8192 0
425if not sauthorized cs io
426ret hrspempty cs io 401
427end
428put cs HBCAP 1048576
429nb = hbodyall cs io body
430if lt nb 0
431if eq nb HEBIG
432ret hrsperr cs io 413
433end
434ret hrsperr cs io 400
435end
436if not srender body tape ulong nb txt
437ret hrsperr cs io 400
438end
439put qnids 0 0
440encodeinput get sreq 2
441count = get qnids 0
442if or eq count 0 gt add count sub get sreq 0 1 2048
443ret hrsperr cs io 413
444end
445qdiskrecheck
446if eq get sreq 1 1
447r = hrspsse cs io
448if lt r 0
449ret r
450end
451r = sdecode cs io ev txt
452if lt r 0
453ret r
454end
455r = sevent cs io ev
456ret sfinish cs io ev
457end
458r = sdecode cs io ev txt
459if lt r 0
460ret hrsperr cs io 500
461end
462ret swhole1 cs io ev txt ulong r
463end
464
465fn shealthy cs edit ulong 320 io edit uchar 131072 to long
466r = hrspst cs io 200
467r = hfe r hhname cs io sctype
468r = hfe r hhval cs io sjson
469r = hfe r hhend cs io 0 len shealth
470r = hfe r hput cs io shealth
471ret hfe r hwfin cs io
472end
473
474fn sroute cs edit ulong 320 io edit uchar 131072 body edit uchar 1048576 tape edit uint 262160 to long
475if hispath cs io snhealth
476if hismeth cs io sget
477ret shealthy cs io
478end
479ret hrspempty cs io 405
480end
481if hispath cs io snchat
482if hismeth cs io spost
483ret schat cs io body tape
484end
485ret hrspempty cs io 405
486end
487ret hrspempty cs io 404
488end
489
490fn sserve lf int cs edit ulong 320 io edit uchar 131072 body edit uchar 1048576 tape edit uint 262160 to void
491c = haccept lf 30000000000
492if lt c 0
493ret
494end
495r = hinit cs io int c 1
496if lt r 0
497x = hclose cs
498ret
499end
500hsettmo cs 10000000000 10000000000
501hsetbdl cs 3600000000000
502for k ulong 100
503r = hreqrd cs io
504if le r 0
505if lt r 0
506x = hreject cs io r
507end
508break
509end
510r = sroute cs io body tape
511if lt r 0
512break
513end
514if eq hnext cs io 0
515break
516end
517end
518r = hclose cs
519end
520
521fn skeyload to bool
522path = new uchar 4096 0
523n = argread 4 path 0 4095
524if le n 0
525ret false
526end
527fd = fopen path 0 ulong n 0 0
528if lt fd 0
529ret false
530end
531r = read int fd skey 0 160
532x = fclose int fd
533if lt r 16
534ret false
535end
536k = ulong r
537while gt k 0 bound 160
538c = get skey sub k 1
539if and ne c 10 ne c 13
540break
541end
542k = sub k 1
543end
544if or lt k 16 ge k 160
545ret false
546end
547put sreq 8 k
548ret true
549end
550
551fn main to int
552cs = new ulong 320 0
553io = new uchar 131072 0
554body = new uchar 1048576 0
555tape = new uint 262160 0
556a = new uchar 16 0
557if or lt argcnt 5 gt argcnt 6
558ret 2
559end
560if ne qnumericarg 1 38
561ret 2
562end
563port = qnumericarg 3
564if or lt port 1024 gt port 65535
565ret 2
566end
567slots = ulong 8320
568if eq argcnt 6
569slots = qnumericarg 5
570if or lt slots 16 gt slots 26624
571ret 2
572end
573end
574if not skeyload
575ret 2
576end
577put qecfg 1 slots
578loadmodel
579if ne get qtidentity 0 27
580qwfail 59
581end
582unicodeinit
583qwload 2 48
584qprofile 48
585put qrun 0 38
586qgpuopen
587r = haddr4 a 2130706433 port
588lf = hlisten a 16
589if lt lf 0
590ret 3
591end
592w = write 2 sport 0 len sport
593fstatnum hport a
594nl = new uchar 1 10
595w = write 2 nl 0 1
596while true
597sserve int lf cs io body tape
598end
599ret 0
600end