omega-tool-model
First-party Omega tool-use model source, serving harnesses, and verification records
Brought by drakestapleton
omega-tool-model / deployment / ui / server.om
| 1 | note Private local protocol. No model-generated bytes are executed. |
| 2 | global naddr uchar 110 |
| 3 | global nbuf uchar 8192 |
| 4 | global nfd int 1 |
| 5 | global nerr ulong 1 |
| 6 | text nsock "$HOME/.local/share/omega-tool-model/run/model.sock" |
| 7 | text nlock "$HOME/.local/share/omega-tool-model/run/model.lock" |
| 8 | |
| 9 | fn naddress to void |
| 10 | put naddr 0 1 |
| 11 | for i ulong len nsock |
| 12 | put naddr add i 2 get nsock i |
| 13 | end |
| 14 | end |
| 15 | |
| 16 | fn nreceive off ulong n ulong timeout long to bool |
| 17 | p = ulong 0 |
| 18 | deadline = add monons timeout |
| 19 | while lt p n bound 8192 |
| 20 | left = sub deadline monons |
| 21 | if le left 0 |
| 22 | ret false |
| 23 | end |
| 24 | r = waitio get nfd 0 1 left |
| 25 | if le r 0 |
| 26 | ret false |
| 27 | end |
| 28 | r = recv get nfd 0 nbuf add off p sub n p 64 |
| 29 | if eq r neg long 11 |
| 30 | continue |
| 31 | end |
| 32 | if le r 0 |
| 33 | ret false |
| 34 | end |
| 35 | p = add p ulong r |
| 36 | end |
| 37 | ret true |
| 38 | end |
| 39 | |
| 40 | fn nsend off ulong n ulong to bool |
| 41 | p = ulong 0 |
| 42 | deadline = add monons long 2000000000 |
| 43 | while lt p n bound 8192 |
| 44 | left = sub deadline monons |
| 45 | if le left 0 |
| 46 | ret false |
| 47 | end |
| 48 | r = waitio get nfd 0 4 left |
| 49 | if le r 0 |
| 50 | ret false |
| 51 | end |
| 52 | r = send get nfd 0 nbuf add off p sub n p 64 |
| 53 | if eq r neg long 11 |
| 54 | continue |
| 55 | end |
| 56 | if le r 0 |
| 57 | ret false |
| 58 | end |
| 59 | p = add p ulong r |
| 60 | end |
| 61 | ret true |
| 62 | end |
| 63 | |
| 64 | fn nlength to ulong |
| 65 | ret add ulong get nbuf 0 mul ulong get nbuf 1 256 |
| 66 | end |
| 67 | |
| 68 | fn nheader n ulong to void |
| 69 | put nbuf 0 uchar and n 255 |
| 70 | put nbuf 1 uchar and shr n 8 255 |
| 71 | end |
| 72 | |
| 73 | fn nstatus code ulong to void |
| 74 | if eq code 0 |
| 75 | nheader 0 |
| 76 | r = nsend 0 2 |
| 77 | else |
| 78 | nheader 65535 |
| 79 | put nbuf 2 uchar code |
| 80 | r = nsend 0 3 |
| 81 | end |
| 82 | end |
| 83 | |
| 84 | note Private, bounded HTTP adapter. No generated text is executed or interpreted as HTML. |
| 85 | global hreq uchar 12288 |
| 86 | global hbuf uchar 16384 |
| 87 | global haddr uchar 16 |
| 88 | global hopt uchar 4 |
| 89 | global hstat uchar 4 |
| 90 | global hfd int 1 |
| 91 | global hcount ulong 1 |
| 92 | global hend ulong 1 |
| 93 | global hsize ulong 1 |
| 94 | global hseen ulong 1 |
| 95 | global hguard ulong 1 |
| 96 | global hhost ulong 1 |
| 97 | global hroute ulong 1 |
| 98 | text hex "0123456789abcdef" |
| 99 | |
| 100 | fn hsend n ulong to bool |
| 101 | p = ulong 0 |
| 102 | deadline = add monons long 3000000000 |
| 103 | while lt p n bound 16384 |
| 104 | left = sub deadline monons |
| 105 | if le left 0 |
| 106 | ret false |
| 107 | end |
| 108 | r = waitio get hfd 0 4 left |
| 109 | if le r 0 |
| 110 | ret false |
| 111 | end |
| 112 | r = send get hfd 0 hbuf p sub n p 64 |
| 113 | if eq r neg long 11 |
| 114 | continue |
| 115 | end |
| 116 | if le r 0 |
| 117 | ret false |
| 118 | end |
| 119 | p = add p ulong r |
| 120 | end |
| 121 | ret true |
| 122 | end |
| 123 | |
| 124 | fn hfind start ulong total ulong to bool |
| 125 | while lt add start 3 total bound 8192 |
| 126 | if and eq get hreq start 13 eq get hreq add start 1 10 |
| 127 | if and eq get hreq add start 2 13 eq get hreq add start 3 10 |
| 128 | put hend 0 add start 4 |
| 129 | ret true |
| 130 | end |
| 131 | end |
| 132 | start = add start 1 |
| 133 | end |
| 134 | ret false |
| 135 | end |
| 136 | |
| 137 | fn hread to bool |
| 138 | put hcount 0 0 |
| 139 | put hend 0 0 |
| 140 | deadline = add monons long 5000000000 |
| 141 | for step ulong 8192 |
| 142 | n = get hcount 0 |
| 143 | if ge n 8192 |
| 144 | ret false |
| 145 | end |
| 146 | left = sub deadline monons |
| 147 | if le left 0 |
| 148 | ret false |
| 149 | end |
| 150 | if le waitio get hfd 0 1 left 0 |
| 151 | ret false |
| 152 | end |
| 153 | r = recv get hfd 0 hreq n sub 8192 n 64 |
| 154 | if eq r neg long 11 |
| 155 | continue |
| 156 | end |
| 157 | if le r 0 |
| 158 | ret false |
| 159 | end |
| 160 | total = add n ulong r |
| 161 | put hcount 0 total |
| 162 | start = ulong 0 |
| 163 | if gt n 3 |
| 164 | start = sub n 3 |
| 165 | end |
| 166 | if hfind start total |
| 167 | ret true |
| 168 | end |
| 169 | end |
| 170 | ret false |
| 171 | end |
| 172 | |
| 173 | fn hline a ulong b ulong to bool |
| 174 | if eq a b |
| 175 | ret true |
| 176 | end |
| 177 | if iscl a b |
| 178 | if ne get hseen 0 0 |
| 179 | ret false |
| 180 | end |
| 181 | put hseen 0 1 |
| 182 | p = add a 15 |
| 183 | while lt p b bound 8192 |
| 184 | if not or eq get hreq p 32 eq get hreq p 9 |
| 185 | break |
| 186 | end |
| 187 | p = add p 1 |
| 188 | end |
| 189 | if eq p b |
| 190 | ret false |
| 191 | end |
| 192 | v = ulong 0 |
| 193 | while lt p b bound 8192 |
| 194 | c = get hreq p |
| 195 | if or lt c 48 gt c 57 |
| 196 | ret false |
| 197 | end |
| 198 | v = add mul v 10 ulong sub c 48 |
| 199 | if gt v 4000 |
| 200 | ret false |
| 201 | end |
| 202 | p = add p 1 |
| 203 | end |
| 204 | put hsize 0 v |
| 205 | ret true |
| 206 | end |
| 207 | if iste a b |
| 208 | ret false |
| 209 | end |
| 210 | if isguard a b |
| 211 | put hguard 0 add get hguard 0 1 |
| 212 | end |
| 213 | if ishost a b |
| 214 | if not goodhost a b |
| 215 | ret false |
| 216 | end |
| 217 | put hhost 0 add get hhost 0 1 |
| 218 | end |
| 219 | ret true |
| 220 | end |
| 221 | |
| 222 | fn hparse to bool |
| 223 | put hsize 0 0 |
| 224 | put hseen 0 0 |
| 225 | put hguard 0 0 |
| 226 | put hhost 0 0 |
| 227 | put hroute 0 0 |
| 228 | n = get hend 0 |
| 229 | a = ulong 0 |
| 230 | first = true |
| 231 | for i ulong sub n 1 |
| 232 | c = get hreq i |
| 233 | if and eq c 13 eq get hreq add i 1 10 |
| 234 | if first |
| 235 | if isroot a i |
| 236 | put hroute 0 1 |
| 237 | end |
| 238 | if isgen a i |
| 239 | put hroute 0 2 |
| 240 | end |
| 241 | first = false |
| 242 | else |
| 243 | if not hline a i |
| 244 | ret false |
| 245 | end |
| 246 | end |
| 247 | a = add i 2 |
| 248 | else |
| 249 | if not first |
| 250 | if and ge c 65 le c 90 |
| 251 | put hreq i add c 32 |
| 252 | end |
| 253 | end |
| 254 | end |
| 255 | end |
| 256 | ret eq get hhost 0 1 |
| 257 | end |
| 258 | |
| 259 | fn hbody to bool |
| 260 | n = get hsize 0 |
| 261 | off = get hend 0 |
| 262 | total = add off n |
| 263 | if or eq n 0 gt n 4000 |
| 264 | ret false |
| 265 | end |
| 266 | if gt get hcount 0 total |
| 267 | ret false |
| 268 | end |
| 269 | deadline = add monons long 5000000000 |
| 270 | while lt get hcount 0 total bound 4000 |
| 271 | p = get hcount 0 |
| 272 | left = sub deadline monons |
| 273 | if le left 0 |
| 274 | ret false |
| 275 | end |
| 276 | if le waitio get hfd 0 1 left 0 |
| 277 | ret false |
| 278 | end |
| 279 | r = recv get hfd 0 hreq p sub total p 64 |
| 280 | if eq r neg long 11 |
| 281 | continue |
| 282 | end |
| 283 | if le r 0 |
| 284 | ret false |
| 285 | end |
| 286 | put hcount 0 add p ulong r |
| 287 | end |
| 288 | nheader n |
| 289 | for i ulong n |
| 290 | c = get hreq add off i |
| 291 | if eq c 0 |
| 292 | ret false |
| 293 | end |
| 294 | put nbuf add i 2 c |
| 295 | end |
| 296 | ret true |
| 297 | end |
| 298 | |
| 299 | fn hchunk n ulong to bool |
| 300 | for i ulong 4 |
| 301 | shift = mul sub 3 i 4 |
| 302 | put hbuf i get hex and shr n shift 15 |
| 303 | end |
| 304 | put hbuf 4 13 |
| 305 | put hbuf 5 10 |
| 306 | for i ulong n |
| 307 | put hbuf add i 6 get nbuf i |
| 308 | end |
| 309 | put hbuf add n 6 13 |
| 310 | put hbuf add n 7 10 |
| 311 | ret hsend add n 8 |
| 312 | end |
| 313 | |
| 314 | fn hstream to void |
| 315 | started = false |
| 316 | for frame ulong 1024 |
| 317 | if not nreceive 0 2 30000000000 |
| 318 | if not started |
| 319 | r = respond502 |
| 320 | end |
| 321 | ret |
| 322 | end |
| 323 | n = nlength |
| 324 | if eq n 65535 |
| 325 | if not started |
| 326 | if nreceive 0 1 2000000000 |
| 327 | if eq get nbuf 0 3 |
| 328 | r = respond422 |
| 329 | else |
| 330 | r = respond502 |
| 331 | end |
| 332 | else |
| 333 | r = respond502 |
| 334 | end |
| 335 | end |
| 336 | ret |
| 337 | end |
| 338 | if gt n 4096 |
| 339 | if not started |
| 340 | r = respond502 |
| 341 | end |
| 342 | ret |
| 343 | end |
| 344 | if not started |
| 345 | if not streamhead |
| 346 | ret |
| 347 | end |
| 348 | started = true |
| 349 | end |
| 350 | if eq n 0 |
| 351 | r = streamend |
| 352 | ret |
| 353 | end |
| 354 | if not nreceive 0 n 2000000000 |
| 355 | ret |
| 356 | end |
| 357 | if not hchunk n |
| 358 | ret |
| 359 | end |
| 360 | end |
| 361 | end |
| 362 | |
| 363 | fn hmodel to void |
| 364 | naddress |
| 365 | fd = socknew 1 524289 0 |
| 366 | if lt fd 0 |
| 367 | r = respond503 |
| 368 | ret |
| 369 | end |
| 370 | if ne connect int fd naddr 0 add len nsock 3 0 |
| 371 | closed = fclose int fd |
| 372 | r = respond503 |
| 373 | ret |
| 374 | end |
| 375 | put nfd 0 int fd |
| 376 | if nsend 0 add get hsize 0 2 |
| 377 | hstream |
| 378 | else |
| 379 | r = respond502 |
| 380 | end |
| 381 | closed = fclose int fd |
| 382 | end |
| 383 | |
| 384 | fn hserve to void |
| 385 | if not hread |
| 386 | r = respond400 |
| 387 | ret |
| 388 | end |
| 389 | if not hparse |
| 390 | r = respond400 |
| 391 | ret |
| 392 | end |
| 393 | route = get hroute 0 |
| 394 | if eq route 1 |
| 395 | if ne get hsize 0 0 |
| 396 | r = respond400 |
| 397 | ret |
| 398 | end |
| 399 | r = respondpage |
| 400 | ret |
| 401 | end |
| 402 | if eq route 2 |
| 403 | if or ne get hguard 0 1 ne get hseen 0 1 |
| 404 | r = respond400 |
| 405 | ret |
| 406 | end |
| 407 | if not hbody |
| 408 | r = respond400 |
| 409 | ret |
| 410 | end |
| 411 | hmodel |
| 412 | else |
| 413 | r = respond404 |
| 414 | end |
| 415 | end |
| 416 | |
| 417 | fn main to int |
| 418 | put haddr 0 2 |
| 419 | put haddr 2 70 |
| 420 | put haddr 3 253 |
| 421 | put haddr 4 127 |
| 422 | put haddr 7 1 |
| 423 | put hopt 0 1 |
| 424 | fd = socknew 2 524289 0 |
| 425 | if lt fd 0 |
| 426 | ret 70 |
| 427 | end |
| 428 | r = sockopt int fd 1 2 hopt 0 4 |
| 429 | if ne bind int fd haddr 0 16 0 |
| 430 | ret 71 |
| 431 | end |
| 432 | if ne listen int fd 16 0 |
| 433 | ret 72 |
| 434 | end |
| 435 | active = ulong 0 |
| 436 | for request ulong 1000000 |
| 437 | for reap ulong 16 |
| 438 | done = waitpid -1 hstat 0 4 1 |
| 439 | if le done 0 |
| 440 | break |
| 441 | end |
| 442 | if gt active 0 |
| 443 | active = sub active 1 |
| 444 | end |
| 445 | end |
| 446 | if ge active 16 |
| 447 | r = sleepns 10000000 |
| 448 | continue |
| 449 | end |
| 450 | if le waitio int fd 1 1000000000 0 |
| 451 | continue |
| 452 | end |
| 453 | client = accept int fd 524288 |
| 454 | if lt client 0 |
| 455 | continue |
| 456 | end |
| 457 | pid = fork |
| 458 | if eq pid 0 |
| 459 | r = fclose int fd |
| 460 | put hfd 0 int client |
| 461 | r = sockopt int client 6 1 hopt 0 4 |
| 462 | hserve |
| 463 | r = fclose int client |
| 464 | ret 0 |
| 465 | end |
| 466 | r = fclose int client |
| 467 | if gt pid 0 |
| 468 | active = add active 1 |
| 469 | end |
| 470 | end |
| 471 | ret 0 |
| 472 | end |
| 473 | |
| 474 | text t0 "HTTP/1.1 200 OK\nConnection: close\nCache-Control: no-store\nX-Content-Type-Options: nosniff\nReferrer-Policy: no-referrer\nContent-Security-Policy: default-src 'none'; script-src 'sha256-5SHsnAF2/hAOBEsKCZQlJG0wlxw7hSWS7p2IGep8vuM='; style-src 'unsafe-inline'; connect-src 'self'; base-uri 'none'; form-action 'none'; frame-ancestors 'none'\nContent-Type: text/html; charset=utf-8\nContent-Length: 6781\n\n" |
| 475 | text page "<!doctype html>\n<html lang=\"en\"><head><meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width,initial-scale=1\"><title>Omega · Your model</title>\n<style>\n:root{color-scheme:dark;font:16px/1.55 system-ui,sans-serif;color:#e7edef;background:#101719}*{box-sizing:border-box}body{margin:0}main{max-width:860px;margin:auto;padding:44px 24px}header{display:flex;justify-content:space-between;gap:20px;align-items:center}.mark{letter-spacing:.2em;color:#b8ddc9;font-weight:700;font-size:13px}.badge{border:1px solid #3e5850;border-radius:30px;padding:5px 13px;font-size:13px;color:#b8ddc9}h1{font-size:clamp(30px,6vw,45px);line-height:1.15;margin:34px 0 14px;font-weight:600;letter-spacing:-.035em}p{color:#aab9bc;margin:0 0 22px}.panel{background:#172124;border:1px solid #304044;border-radius:16px;padding:24px;margin-top:24px}label{display:block;font-weight:600;margin-bottom:9px}select,textarea,button{font:inherit}select{background:#101719;color:#e7edef;border:1px solid #4a6268;border-radius:8px;padding:8px 12px;margin-bottom:20px}textarea{width:100%;min-height:150px;resize:vertical;background:#101719;color:#eef5f4;border:1px solid #4a6268;border-radius:10px;padding:15px}textarea:focus,select:focus,button:focus-visible{outline:2px solid #a4dbbc;outline-offset:3px}.hint{font-size:13px;margin-top:8px}.actions{display:flex;gap:12px;align-items:center;flex-wrap:wrap;margin-top:18px}button{cursor:pointer;border:0;border-radius:9px;padding:10px 17px;font-weight:600;background:#b8ddc9;color:#14231a}button:disabled{opacity:.5;cursor:wait}.secondary{background:transparent;color:#c0d5dc;border:1px solid #486169;font-size:13px;padding:7px 12px}.examples{display:flex;flex-wrap:wrap;gap:8px;margin-top:14px}.output-title{display:flex;justify-content:space-between;align-items:center;gap:12px}h2{font-size:17px;margin:0}pre{white-space:pre-wrap;overflow-wrap:anywhere;min-height:70px;line-height:1.6;font-size:14px;margin:18px 0 0;color:#d0eadc}#status{font-size:14px;color:#b8cccf}#status.error{color:#ffb5a9}footer{margin-top:24px;font-size:13px;color:#9aafb4}button:hover{filter:brightness(1.08)}@media(max-width:500px){main{padding:26px 16px}.panel{padding:18px}}\n</style></head><body><main>\n<header><span class=\"mark\">OMEGA</span><span class=\"badge\">Round 40 · Fast model</span></header>\n<h1>Your model, ready to try.</h1>\n<p>Give it a small Omega coding task, or explore what it writes next. This is the model you trained, running on your Spark.</p>\n<form id=\"ask\" class=\"panel\"><label for=\"mode\">What would you like to try?</label>\n<select id=\"mode\"><option value=\"task\">An Omega task</option><option value=\"raw\">Continue text / exact prompt</option></select>\n<label for=\"prompt\">Your request</label><textarea id=\"prompt\" maxlength=\"4000\" required placeholder=\"Write Omega that returns the larger of 24 and 27.\"></textarea>\n<p class=\"hint\">Keep it short. Each request starts fresh, without previous messages.</p>\n<div class=\"examples\"><button type=\"button\" class=\"secondary\" data-example=\"larger\">Compare two numbers</button><button type=\"button\" class=\"secondary\" data-example=\"tool\">Try a tool response</button></div>\n<div class=\"actions\"><button id=\"run\" type=\"submit\">Ask the model</button><button id=\"stop\" class=\"secondary\" type=\"button\" hidden>Stop</button><span id=\"status\" role=\"status\" aria-live=\"polite\">Ready when you are.</span></div></form>\n<section class=\"panel\" aria-label=\"Model response\"><div class=\"output-title\"><h2>Model response</h2><button type=\"button\" id=\"copy\" class=\"secondary\" disabled>Copy</button></div><pre id=\"output\" tabindex=\"0\">Its response will appear here.</pre></section>\n<footer>This is a small model trained for specific Omega tasks and tool responses. General conversation and unfamiliar tasks may produce mistakes. Tool requests are displayed here; they do not run or change files.</footer>\n</main><script>\nconst $=id=>document.getElementById(id);\nlet controller=null;\nconst examples={larger:{mode:'task',text:'Write Omega that returns the larger of 24 and 27.'},tool:{mode:'raw',text:'Task: Fix the error in this file and confirm its goal.\\nFile: jobs/item76666.om\\nGoal: calc starts with x and adds 4 exactly 3 times in a for loop. main calls calc with 70.\\nState: unread\\nAnswer:\\n'}};\ndocument.querySelectorAll('[data-example]').forEach(b=>b.addEventListener('click',()=>{const e=examples[b.dataset.example];$('mode').value=e.mode;$('prompt').value=e.text;$('prompt').focus();}));\nfunction status(text,error=false){$('status').textContent=text;$('status').className=error?'error':'';}\n$('stop').addEventListener('click',()=>controller?.abort());\n$('ask').addEventListener('submit',async e=>{\n e.preventDefault();if(controller)return;\n const input=$('prompt').value;if(!input.trim())return;\n const prompt=$('mode').value==='task'?'Task: '+input.trim()+'\\nAnswer:\\n':input;\n if(new TextEncoder().encode(prompt).length>4000){status('Please shorten your request.',true);return;}\n controller=new AbortController();const started=performance.now();let timer=setTimeout(()=>controller?.abort(),45000);\n $('run').disabled=true;$('stop').hidden=false;$('copy').disabled=true;$('output').textContent='';status('Waiting for the model…');\n try{\n const response=await fetch('/generate',{method:'POST',headers:{'Content-Type':'text/plain;charset=UTF-8','X-Omega-UI':'1'},body:prompt,signal:controller.signal});\n if(!response.ok)throw new Error((await response.text()).trim()||'The request could not be completed.');\n const reader=response.body.getReader(),decoder=new TextDecoder();let first=true;\n while(true){const {value,done}=await reader.read();if(done)break;$('output').textContent+=decoder.decode(value,{stream:true});if(first){status('Receiving the response…');first=false;}}\n $('output').textContent+=decoder.decode();status('Finished in '+Math.round(performance.now()-started)+' ms.');\n if(!$('output').textContent)$('output').textContent='The model finished without any text. Try one of the examples.';\n }catch(error){status(error.name==='AbortError'?'Stopped. Any response shown may be incomplete.':error.message,true);}\n finally{clearTimeout(timer);controller=null;$('run').disabled=false;$('stop').hidden=true;$('copy').disabled=!$('output').textContent;}\n});\n$('copy').addEventListener('click',async()=>{\n const text=$('output').textContent;\n try{if(navigator.clipboard&&window.isSecureContext){await navigator.clipboard.writeText(text);}else{const area=document.createElement('textarea');area.value=text;area.style.position='fixed';area.style.opacity='0';document.body.appendChild(area);area.select();const ok=document.execCommand('copy');area.remove();if(!ok)throw new Error('copy');}status('Response copied.');}catch{status('Select the response text to copy it.',true);}\n});\n</script></body></html>\n" |
| 476 | fn respondpage to bool |
| 477 | p = ulong 0 |
| 478 | for i ulong len t0 |
| 479 | c = get t0 i |
| 480 | if eq c 10 |
| 481 | put hbuf p 13 |
| 482 | p = add p 1 |
| 483 | end |
| 484 | put hbuf p c |
| 485 | p = add p 1 |
| 486 | end |
| 487 | for i ulong len page |
| 488 | put hbuf p get page i |
| 489 | p = add p 1 |
| 490 | end |
| 491 | ret hsend p |
| 492 | end |
| 493 | text t1 "HTTP/1.1 400 Bad Request\nConnection: close\nCache-Control: no-store\nX-Content-Type-Options: nosniff\nReferrer-Policy: no-referrer\nContent-Security-Policy: default-src 'none'; script-src 'sha256-5SHsnAF2/hAOBEsKCZQlJG0wlxw7hSWS7p2IGep8vuM='; style-src 'unsafe-inline'; connect-src 'self'; base-uri 'none'; form-action 'none'; frame-ancestors 'none'\nContent-Type: text/plain; charset=utf-8\nContent-Length: 55\n\nPlease send a short, nonempty request using this page.\n" |
| 494 | fn respond400 to bool |
| 495 | p = ulong 0 |
| 496 | for i ulong len t1 |
| 497 | c = get t1 i |
| 498 | if eq c 10 |
| 499 | put hbuf p 13 |
| 500 | p = add p 1 |
| 501 | end |
| 502 | put hbuf p c |
| 503 | p = add p 1 |
| 504 | end |
| 505 | put hbuf sub p 2 10 |
| 506 | p = sub p 1 |
| 507 | ret hsend p |
| 508 | end |
| 509 | text t2 "HTTP/1.1 404 Not Found\nConnection: close\nCache-Control: no-store\nX-Content-Type-Options: nosniff\nReferrer-Policy: no-referrer\nContent-Security-Policy: default-src 'none'; script-src 'sha256-5SHsnAF2/hAOBEsKCZQlJG0wlxw7hSWS7p2IGep8vuM='; style-src 'unsafe-inline'; connect-src 'self'; base-uri 'none'; form-action 'none'; frame-ancestors 'none'\nContent-Type: text/plain; charset=utf-8\nContent-Length: 16\n\nPage not found.\n" |
| 510 | fn respond404 to bool |
| 511 | p = ulong 0 |
| 512 | for i ulong len t2 |
| 513 | c = get t2 i |
| 514 | if eq c 10 |
| 515 | put hbuf p 13 |
| 516 | p = add p 1 |
| 517 | end |
| 518 | put hbuf p c |
| 519 | p = add p 1 |
| 520 | end |
| 521 | put hbuf sub p 2 10 |
| 522 | p = sub p 1 |
| 523 | ret hsend p |
| 524 | end |
| 525 | text t3 "HTTP/1.1 422 Unprocessable Content\nConnection: close\nCache-Control: no-store\nX-Content-Type-Options: nosniff\nReferrer-Policy: no-referrer\nContent-Security-Policy: default-src 'none'; script-src 'sha256-5SHsnAF2/hAOBEsKCZQlJG0wlxw7hSWS7p2IGep8vuM='; style-src 'unsafe-inline'; connect-src 'self'; base-uri 'none'; form-action 'none'; frame-ancestors 'none'\nContent-Type: text/plain; charset=utf-8\nContent-Length: 73\n\nThis request is too long for the model. Please shorten it and try again.\n" |
| 526 | fn respond422 to bool |
| 527 | p = ulong 0 |
| 528 | for i ulong len t3 |
| 529 | c = get t3 i |
| 530 | if eq c 10 |
| 531 | put hbuf p 13 |
| 532 | p = add p 1 |
| 533 | end |
| 534 | put hbuf p c |
| 535 | p = add p 1 |
| 536 | end |
| 537 | put hbuf sub p 2 10 |
| 538 | p = sub p 1 |
| 539 | ret hsend p |
| 540 | end |
| 541 | text t4 "HTTP/1.1 502 Bad Gateway\nConnection: close\nCache-Control: no-store\nX-Content-Type-Options: nosniff\nReferrer-Policy: no-referrer\nContent-Security-Policy: default-src 'none'; script-src 'sha256-5SHsnAF2/hAOBEsKCZQlJG0wlxw7hSWS7p2IGep8vuM='; style-src 'unsafe-inline'; connect-src 'self'; base-uri 'none'; form-action 'none'; frame-ancestors 'none'\nContent-Type: text/plain; charset=utf-8\nContent-Length: 54\n\nThe model response was interrupted. Please try again.\n" |
| 542 | fn respond502 to bool |
| 543 | p = ulong 0 |
| 544 | for i ulong len t4 |
| 545 | c = get t4 i |
| 546 | if eq c 10 |
| 547 | put hbuf p 13 |
| 548 | p = add p 1 |
| 549 | end |
| 550 | put hbuf p c |
| 551 | p = add p 1 |
| 552 | end |
| 553 | put hbuf sub p 2 10 |
| 554 | p = sub p 1 |
| 555 | ret hsend p |
| 556 | end |
| 557 | text t5 "HTTP/1.1 503 Service Unavailable\nConnection: close\nCache-Control: no-store\nX-Content-Type-Options: nosniff\nReferrer-Policy: no-referrer\nContent-Security-Policy: default-src 'none'; script-src 'sha256-5SHsnAF2/hAOBEsKCZQlJG0wlxw7hSWS7p2IGep8vuM='; style-src 'unsafe-inline'; connect-src 'self'; base-uri 'none'; form-action 'none'; frame-ancestors 'none'\nContent-Type: text/plain; charset=utf-8\nContent-Length: 60\n\nThe model service is unavailable. Please try again shortly.\n" |
| 558 | fn respond503 to bool |
| 559 | p = ulong 0 |
| 560 | for i ulong len t5 |
| 561 | c = get t5 i |
| 562 | if eq c 10 |
| 563 | put hbuf p 13 |
| 564 | p = add p 1 |
| 565 | end |
| 566 | put hbuf p c |
| 567 | p = add p 1 |
| 568 | end |
| 569 | put hbuf sub p 2 10 |
| 570 | p = sub p 1 |
| 571 | ret hsend p |
| 572 | end |
| 573 | text t6 "HTTP/1.1 200 OK\nConnection: close\nCache-Control: no-store\nX-Content-Type-Options: nosniff\nReferrer-Policy: no-referrer\nContent-Security-Policy: default-src 'none'; script-src 'sha256-5SHsnAF2/hAOBEsKCZQlJG0wlxw7hSWS7p2IGep8vuM='; style-src 'unsafe-inline'; connect-src 'self'; base-uri 'none'; form-action 'none'; frame-ancestors 'none'\nContent-Type: text/plain; charset=utf-8\nTransfer-Encoding: chunked\nX-Accel-Buffering: no\n\n" |
| 574 | fn streamhead to bool |
| 575 | p = ulong 0 |
| 576 | for i ulong len t6 |
| 577 | c = get t6 i |
| 578 | if eq c 10 |
| 579 | put hbuf p 13 |
| 580 | p = add p 1 |
| 581 | end |
| 582 | put hbuf p c |
| 583 | p = add p 1 |
| 584 | end |
| 585 | ret hsend p |
| 586 | end |
| 587 | text t7 "0\n\n" |
| 588 | fn streamend to bool |
| 589 | p = ulong 0 |
| 590 | for i ulong len t7 |
| 591 | c = get t7 i |
| 592 | if eq c 10 |
| 593 | put hbuf p 13 |
| 594 | p = add p 1 |
| 595 | end |
| 596 | put hbuf p c |
| 597 | p = add p 1 |
| 598 | end |
| 599 | ret hsend p |
| 600 | end |
| 601 | text m0 "GET / HTTP/1.1" |
| 602 | fn isroot a ulong b ulong to bool |
| 603 | if ne sub b a len m0 |
| 604 | ret false |
| 605 | end |
| 606 | for i ulong len m0 |
| 607 | if ne get hreq add a i get m0 i |
| 608 | ret false |
| 609 | end |
| 610 | end |
| 611 | ret true |
| 612 | end |
| 613 | text m1 "POST /generate HTTP/1.1" |
| 614 | fn isgen a ulong b ulong to bool |
| 615 | if ne sub b a len m1 |
| 616 | ret false |
| 617 | end |
| 618 | for i ulong len m1 |
| 619 | if ne get hreq add a i get m1 i |
| 620 | ret false |
| 621 | end |
| 622 | end |
| 623 | ret true |
| 624 | end |
| 625 | text m2 "content-length:" |
| 626 | fn iscl a ulong b ulong to bool |
| 627 | if lt sub b a len m2 |
| 628 | ret false |
| 629 | end |
| 630 | for i ulong len m2 |
| 631 | if ne get hreq add a i get m2 i |
| 632 | ret false |
| 633 | end |
| 634 | end |
| 635 | ret true |
| 636 | end |
| 637 | text m3 "transfer-encoding:" |
| 638 | fn iste a ulong b ulong to bool |
| 639 | if lt sub b a len m3 |
| 640 | ret false |
| 641 | end |
| 642 | for i ulong len m3 |
| 643 | if ne get hreq add a i get m3 i |
| 644 | ret false |
| 645 | end |
| 646 | end |
| 647 | ret true |
| 648 | end |
| 649 | text m4 "x-omega-ui: 1" |
| 650 | fn isguard a ulong b ulong to bool |
| 651 | if ne sub b a len m4 |
| 652 | ret false |
| 653 | end |
| 654 | for i ulong len m4 |
| 655 | if ne get hreq add a i get m4 i |
| 656 | ret false |
| 657 | end |
| 658 | end |
| 659 | ret true |
| 660 | end |
| 661 | text m5 "host:" |
| 662 | fn ishost a ulong b ulong to bool |
| 663 | if lt sub b a len m5 |
| 664 | ret false |
| 665 | end |
| 666 | for i ulong len m5 |
| 667 | if ne get hreq add a i get m5 i |
| 668 | ret false |
| 669 | end |
| 670 | end |
| 671 | ret true |
| 672 | end |
| 673 | text m6 "host: 127.0.0.1:18173" |
| 674 | fn host0 a ulong b ulong to bool |
| 675 | if ne sub b a len m6 |
| 676 | ret false |
| 677 | end |
| 678 | for i ulong len m6 |
| 679 | if ne get hreq add a i get m6 i |
| 680 | ret false |
| 681 | end |
| 682 | end |
| 683 | ret true |
| 684 | end |
| 685 | text m7 "host: localhost:18173" |
| 686 | fn host1 a ulong b ulong to bool |
| 687 | if ne sub b a len m7 |
| 688 | ret false |
| 689 | end |
| 690 | for i ulong len m7 |
| 691 | if ne get hreq add a i get m7 i |
| 692 | ret false |
| 693 | end |
| 694 | end |
| 695 | ret true |
| 696 | end |
| 697 | text m8 "host: 127.0.0.1:18174" |
| 698 | fn host2 a ulong b ulong to bool |
| 699 | if ne sub b a len m8 |
| 700 | ret false |
| 701 | end |
| 702 | for i ulong len m8 |
| 703 | if ne get hreq add a i get m8 i |
| 704 | ret false |
| 705 | end |
| 706 | end |
| 707 | ret true |
| 708 | end |
| 709 | text m9 "host: localhost:18174" |
| 710 | fn host3 a ulong b ulong to bool |
| 711 | if ne sub b a len m9 |
| 712 | ret false |
| 713 | end |
| 714 | for i ulong len m9 |
| 715 | if ne get hreq add a i get m9 i |
| 716 | ret false |
| 717 | end |
| 718 | end |
| 719 | ret true |
| 720 | end |
| 721 | fn goodhost a ulong b ulong to bool |
| 722 | ret or or host0 a b host1 a b or host2 a b host3 a b |
| 723 | end |