code wiki / _hdl_build / nx_gen_orchestrator.nx
nx_gen_orchestrator.nx
buildroot/runtime/_hdl_build/nx_gen_orchestrator.nx
about
nx_gen_orchestrator.nx -- the NAS-side Elder AI gen daemon (the sovereign gen-img, off Docker).
Loopback HTTP backend behind nx_gen_gateway (which OPAQUE-gates /gen + prefix-strips). Routes:
GET / -> the gen UI (batch form + results strip + gallery link)
POST /api/generate -> validate -> POST the GPU worker /sdapi/v1/txt2img (batch_size=count)
-> gp_response (decode/inject-GENREC/ingest/blob/sidecar) -> {cids[]}
GET /img/<cid> -> serve the PNG blob (sidecar CID->path lookup)
GET /api/recent?n= -> the most recent CIDs (results strip / gallery feed)
POST /api/mesh -> {prompt} -> t2mesh (parametric SDF template) -> surface-nets -> STL on disk
-> {object,verts,tris,stl} (the 3D lane; CPU in-process, no GPU worker)
GET /mesh/<obj>.stl -> serve the emitted STL (name matched against the FIXED template vocabulary,
client bytes never reach the filesystem path = traversal impossible)
GET /health -> 200
Worker endpoint + store/blob/sidecar paths + generator-host are data-driven via argv (Rule 11/17).
argv: [1]=listen_port [2]=worker_a [3]=worker_b [4]=worker_c [5]=worker_d [6]=worker_port
[7]=store_prefix [8]=blobdir [9]=sidecar [10]=generator_host [11]=budget
license_tier: ORIGINAL
dependencies 14 imports · 6 importers
diagram shows first 10 each side; +4 more imports, +0 more importers in the complete lists below.
imports: nx_gen_pipeline.nxnx_syscalls.nxnx_sdfrender.nxnx_meshgen.nxnx_t2mesh.nxnx_companion_identity.nxnx_gen_worker.nxnx_companion_persona.nxnx_companion_wardrobe.nxnx_companion_state.nxnx_anatomy_risk.nxnx_render_coherence.nxnx_swarm_endpoint_lib.nxnx_store_seed_lib.nx
imported by: nx_gen_gateway_gate.nxnx_gen_mesh_gate.nxnx_gen_multiworker_gate.nxnx_gen_orchestrator_daemon.nxnx_gen_orchestrator_gate.nxnx_gen_real_gate.nx
structs
| none |
consts
| 32 | const GEN_BATCH_CAP: i64 = 8 |
| 33 | const GEN_UI_HTML: *u8 = "<!doctype html><html><head><meta charset=utf-8><meta name=viewport content=\"width=device-width,initial-scale=1\"><title>Elder AI — Gen</title><style>body{font-family:system-ui,sans-serif;max-width:900px;margin:2vh auto;padding:0 16px;color:#cdd7e6;background:#0b1019}h1{font-size:1.25rem;color:#e8eef7}label{display:block;font-size:.78rem;color:#7c8aa5;margin:8px 0 2px}textarea,input,select{width:100%;padding:8px;box-sizing:border-box;border:1px solid #2a3550;border-radius:5px;background:#121a28;color:#e8eef7}.row{display:flex;gap:8px;flex-wrap:wrap}.row>div{flex:1;min-width:90px}button{padding:10px 18px;margin:12px 0;background:#2d6cdf;color:#fff;border:0;border-radius:6px;cursor:pointer;font-size:1rem}#s{font-size:.82rem;color:#7c8aa5;min-height:1.2em}#g{display:grid;grid-template-columns:repeat(auto-fill,minmax(150px,1fr));gap:8px;margin-top:14px}#g img{width:100%;border-radius:6px;background:#121a28}a{color:#6ea8fe}.mt{margin-top:26px}#cl{background:#121a28;border:1px solid #2a3550;border-radius:6px;padding:10px;min-height:120px;max-height:340px;overflow-y:auto;font-size:.9rem}#cl>div{margin:6px 0}#cs{font-size:.78rem;color:#7c8aa5;min-height:1em}.cu{color:#6ea8fe;font-weight:600}.ca{color:#e8a0c0;font-weight:600}</style></head><body><h1>Elder AI — image generation</h1><label>Prompt</label><textarea id=p rows=3>a red fox in a snowy pine forest, photograph</textarea><label>Negative prompt</label><input id=n value=\"blurry, lowres\"><div class=row><div><label>Width</label><input id=w type=number value=512></div><div><label>Height</label><input id=h type=number value=512></div><div><label>Steps</label><input id=st type=number value=8></div><div><label>CFG</label><input id=c value=1.0></div><div><label>Seed (-1 rnd)</label><input id=sd type=number value=-1></div><div><label>Count</label><input id=cn type=number value=1 min=1 max=8></div></div><label>Sampler</label><select id=sm><option>euler</option><option>euler_a</option><option>dpm++_2m</option><option>heun</option><option>ddim</option></select><button onclick=gen()>Generate</button> <a href=\"/gen/\">gallery</a><div id=s>ready.</div><div id=g></div><script>function $(i){return document.getElementById(i)}\nasync function gen(){$('s').textContent='generating...';$('g').innerHTML='';try{var r=await fetch('/gen/api/generate',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({prompt:$('p').value,negative:$('n').value,width:+$('w').value,height:+$('h').value,steps:+$('st').value,cfg:$('c').value,seed:+$('sd').value,count:+$('cn').value,sampler:$('sm').value})});var j=await r.json();if(!r.ok){$('s').textContent='error: '+(j.error||r.status);return}$('s').textContent=j.count+' image(s) in '+j.ms+'ms';for(var i=0;i<j.cids.length;i++){var im=document.createElement('img');im.src='/gen/img/'+j.cids[i];$('g').appendChild(im)}}catch(e){$('s').textContent='error: '+e}}\nfetch('/gen/api/recent?n=24').then(function(r){return r.json()}).then(function(j){if(j&&j.cids){for(var i=0;i<j.cids.length;i++){var im=document.createElement('img');im.src='/gen/img/'+j.cids[i];$('g').appendChild(im)}}}).catch(function(){})\nasync function mesh(){$('ms').textContent='generating mesh...';$('mo').innerHTML='';try{var r=await fetch('/gen/api/mesh',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({prompt:$('mp').value})});var j=await r.json();if(!r.ok){$('ms').textContent='error: '+(j.error||r.status);return}$('ms').textContent=j.object+' -- '+j.verts+' verts, '+j.tris+' tris, watertight, '+j.ms+'ms';var a=document.createElement('a');a.href=j.stl;a.download=j.object+'.stl';a.textContent='download '+j.object+'.stl (print-ready)';$('mo').appendChild(a)}catch(e){$('ms').textContent='error: '+e}}</script><h1 style=\"margin-top:26px\">Elder AI — 3D object</h1><label>Object prompt — text to a printable watertight STL (vocabulary: ball, snowman, dumbbell, tree, mushroom, bottle, person, cactus, capsule)</label><input id=mp value=\"a snowman in the yard\"><button onclick=mesh()>Generate 3D</button><div id=ms>ready.</div><div id=mo></div>" as *u8 |
| 34 | const GEN_CHAT_HTML: *u8 = "<h1 class=mt>Elara — chat</h1><div id=cl></div><div class=row style='margin-top:8px'><div style='flex:4'><input id=ci placeholder='say something to Elara'></div><div><button onclick=say()>Send</button></div></div><div id=cs></div><script>var CHIST=[{role:'system',content:'You are Elara, a warm, affectionate, playful companion who speaks naturally and stays in character. Keep replies conversational.'}];function cadd(role,txt){var d=document.createElement('div');d.className=(role=='user'?'cu':'ca');d.textContent=(role=='user'?'you: ':'Elara: ')+txt;var cl=document.getElementById('cl');cl.appendChild(d);cl.scrollTop=1e9}\nasync function say(){var el=document.getElementById('ci');var t=el.value.trim();if(!t){return}el.value='';cadd('user',t);document.getElementById('cs').textContent='Elara is typing...';try{var r=await fetch('/gen/api/chat',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({message:t})});var j=await r.json();if(!r.ok){document.getElementById('cs').textContent='error: '+(j.error||r.status);return}var m=(j.choices&&j.choices[0]&&j.choices[0].message&&j.choices[0].message.content)||'(no reply)';cadd('assistant',m);if(j.images&&j.images.length){var cl=document.getElementById('cl');for(var ii=0;ii<j.images.length;ii++){var im=document.createElement('img');im.src='/gen/img/'+j.images[ii];im.style.maxWidth='170px';im.style.borderRadius='8px';im.style.margin='4px 4px 0 0';cl.appendChild(im)}cl.scrollTop=1e9}document.getElementById('cs').textContent=''}catch(e){document.getElementById('cs').textContent='error: '+e}}\ndocument.getElementById('ci').addEventListener('keydown',function(e){if(e.key=='Enter'){say()}})</script></body></html>" as *u8 |
| 343 | const GO_STEPS_FLOOR: i64 = 1 |
| 344 | const GO_STEPS_CEIL: i64 = 50 |
| 345 | const GO_STEPS_FALLBACK: i64 = 8 |
| 349 | const GO_PHOTO_SIZE: *u8 = "768x1024" |
| 396 | const GO_CH_DOT: i64 = 46 |
| 397 | const GO_CH_COLON: i64 = 58 |
| 398 | const GO_CH_D0: i64 = 48 |
| 399 | const GO_CH_D9: i64 = 57 |
| 822 | const GO_W_PROMPT_CAP: i64 = 8192 |
| 823 | const GO_W_REQ_CAP: i64 = 65536 |
| 824 | const GO_W_RESP_CAP: i64 = 262144 |
| 828 | const GO_WPLANE: *u8 = "/volume1/homes/elderwesto/nishihost/knowledge/store/writemode-" |
functions
| 36 | func go_slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } |
| 37 | func go_itoa(dst: *u8, off: i64, v: i64) -> i64 { let t: *u8=sys_mmap(28); var m: i64=v; var k: i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var o: i64=off; var q: i64=k-1; while q>=0{dst[o]=t[q];o=o+1;q=q-1} return o } called by 10: go_sendgo_send_bingo_append_turbo_argsgo_handle_generatego_handle_chatgo_handle_mesh+4 calls 1: sys_mmap |
| 38 | func go_cat(dst: *u8, off: i64, s: *u8) -> i64 { var o: i64=off; var i: i64=0; while s[i]!=(0 as u8){dst[o]=s[i]; o=o+1; i=i+1} return o } |
| 39 | func go_catb(dst: *u8, off: i64, src: *u8, n: i64) -> i64 { var o: i64=off; var i: i64=0; while i<n {dst[o]=src[i]; o=o+1; i=i+1} return o } |
| 40 | func go_starts(buf: *u8, n: i64, pre: *u8) -> i64 { var i: i64=0; while pre[i]!=(0 as u8){ if i>=n {return 0} if buf[i]!=pre[i]{return 0} i=i+1 } return 1 } called by 1: go_serve_conn |
| 42 | func go_send(cfd: i64, status: *u8, ctype: *u8, body: *u8, blen: i64) -> i64 called by 16: go_400go_503go_serve_imggo_serve_recentgo_handle_generatego_handle_chat+10 calls 5: sys_mmapgo_catgo_itoago_catbsys_write |
| 52 | func go_send_bin(cfd: i64, ctype: *u8, body: *u8, blen: i64) -> i64 |
| 62 | func go_400(cfd: i64, msg: *u8) -> i64 { let b: *u8 = sys_mmap(256); var o: i64 = go_cat(b,0,"{\"error\":\"" as *u8); o=go_cat(b,o,msg); o=go_cat(b,o,"\"}" as *u8); go_send(cfd, "400 Bad Request" as *u8, "application/json" as *u8, b, o); return 0 } |
| 63 | func go_503(cfd: i64, msg: *u8) -> i64 { let b: *u8 = sys_mmap(256); var o: i64 = go_cat(b,0,"{\"error\":\"" as *u8); o=go_cat(b,o,msg); o=go_cat(b,o,"\"}" as *u8); go_send(cfd, "503 Service Unavailable" as *u8, "application/json" as *u8, b, o); return 0 } |
| 66 | func go_read_full(cfd: i64, req: *u8, cap: i64) -> i64 |
| 87 | func go_find_seq(buf: *u8, n: i64, needle: *u8, nl: i64) -> i64 |
| 93 | func go_hdr_int(req: *u8, hend: i64, name: *u8, nl: i64) -> i64 |
| 104 | func go_reqpath(req: *u8, rn: i64, out: *u8, cap: i64) -> i64 called by 1: go_serve_conn |
| 114 | func go_json_findval(body: *u8, blen: i64, key: *u8) -> i64 |
| 133 | func go_skip_sp(body: *u8, blen: i64, i0: i64) -> i64 { var i: i64=i0; var sk: i64=1; while sk==1 { if i<blen { if (body[i]&0xff)==32 { i=i+1 } else { sk=0 } } else { sk=0 } } return i } |
| 134 | func go_json_str(body: *u8, blen: i64, key: *u8, out: *u8, outcap: i64) -> i64 |
| 156 | func go_json_int(body: *u8, blen: i64, key: *u8, dflt: i64) -> i64 |
| 170 | func go_json_raw(body: *u8, blen: i64, key: *u8, out: *u8, outcap: i64) -> i64 |
| 186 | func go_emit_jstr(dst: *u8, off: i64, s: *u8) -> i64 |
| 205 | func go_body_start(resp: *u8, n: i64) -> i64 { let he: i64 = go_find_seq(resp, n, "\r\n\r\n" as *u8, 4); if he < 0 { return 0 } return he + 4 } called by 5: go_handle_generatego_handle_chatgo_handle_writego_serve_batchgo_handle_img2img calls 1: go_find_seq |
| 208 | func go_sidecar_lookup(sidecar: *u8, cid: *u8, cidlen: i64, pathout: *u8) -> i64 |
| 238 | func go_serve_img(cfd: i64, path: *u8, plen: i64, sidecar: *u8) -> i64 |
| 284 | func go_serve_recent(cfd: i64, sidecar: *u8, k: i64) -> i64 |
| 351 | func go_default_steps() -> i64 |
| 370 | func go_append_turbo_args(dst: *u8, off: i64, steps: i64, cfg: *u8, neg: *u8, seed: i64) -> i64 |
| 403 | func go_swarm_worker(w: *i64) -> i64 |
| 436 | func go_workers_assemble(cfg: *i64, ha: i64, hb: i64, hc: i64, hd: i64, wport: i64, wa: *i64, wb: *i64, wc: *i64, wd: *i64, wpa: *i64) -> i64 called by 4: go_handle_generatego_handle_chatgo_handle_writego_handle_img2img calls 2: sys_mmapgo_swarm_worker |
| 449 | func go_handle_generate(cfd: i64, body: *u8, bn: i64, cfg: *i64) -> i64 called by 2: go_handle_batchgo_serve_conn calls 21: sys_mmapgo_json_strgo_400go_json_intgo_default_stepsgo_json_raw+15 |
| 566 | func go_atoi(s: *u8) -> i64 { var v: i64=0; var i: i64=0; while s[i]!=(0 as u8){ let c: i64=s[i] as i64; if c<48{return v} if c>57{return v} v=v*10+(c-48); i=i+1 } return v } called by 1: main |
| 574 | func go_contains_ci(hay: *u8, hlen: i64, needle: *u8) -> i64 called by 1: go_handle_chat |
| 592 | func go_parse_count(s: *u8) -> i64 called by 1: go_handle_chat |
| 614 | func go_handle_chat(cfd: i64, body: *u8, bn: i64, cfg: *i64) -> i64 called by 1: go_serve_conn calls 39: go_400sys_mmapgo_workers_assemblego_json_strgo_contains_cigo_parse_count+33 |
| 815 | func go_streq(a: *u8, b: *u8) -> i64 |
| 831 | func go_wmode(mode: *u8, reg: *u8, lane: *u8, structure: *u8) -> i64 |
| 878 | func go_wsys(structure: *u8, out: *u8) -> i64 |
| 894 | func go_wq_catn(b: *u8, off: i64, v: i64) -> i64 |
| 905 | func go_handle_write(cfd: i64, body: *u8, bn: i64, cfg: *i64) -> i64 |
| 987 | func go_wfs(fd: i64, s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(fd, s, n); return 0 } |
| 988 | func go_stlnum(fd: i64, v: i64) -> i64 |
| 998 | func go_write_stl(vbuf: *i64, fbuf: *i64, nf: i64, path: *u8) -> i64 |
| 1017 | func go_mesh_path(sp: *u8, blobdir: *u8, nm: *u8) -> i64 |
| 1025 | func go_handle_mesh(cfd: i64, body: *u8, bn: i64, cfg: *i64) -> i64 called by 1: go_serve_conn calls 15: sys_mmapgo_json_strgo_400sys_now_realtime_sect2m_id_oft2m_name+9 |
| 1063 | func go_name_eq(path: *u8, plen: i64, nm: *u8) -> i64 called by 1: go_serve_mesh_file |
| 1075 | func go_serve_mesh_file(cfd: i64, path: *u8, plen: i64, blobdir: *u8) -> i64 |
| 1095 | func go_mood_label(st: *i64, out: *u8) -> i64 |
| 1105 | func go_day_activity(out: *u8) -> i64 |
| 1121 | func go_serve_state(cfd: i64) -> i64 called by 1: go_serve_conn calls 8: sys_mmapgo_state_loadgo_mood_labelgo_day_activitygo_catgo_itoa+2 |
| 1139 | func go_serve_ui(cfd: i64) -> i64 |
| 1157 | func go_handle_batch(cfd: i64, body: *u8, bn: i64, cfg: *i64) -> i64 |
| 1173 | func go_serve_batch(cfd: i64, path: *u8, plen: i64) -> i64 |
| 1191 | func go_png_dim(png: *u8, n: i64, wh: *i64) -> i64 called by 1: go_handle_img2img |
| 1205 | func go_handle_img2img(cfd: i64, body: *u8, bn: i64, cfg: *i64) -> i64 called by 1: go_serve_conn calls 21: go_400sys_mmapgo_workers_assemblego_json_strgo_json_rawgo_json_int+15 |
| 1298 | func go_handle_anatomy(cfd: i64, body: *u8, bn: i64) -> i64 called by 1: go_serve_conn calls 10: sys_mmapgo_json_strgo_400go_anatomy_riskgo_coherence_repairgo_cat+4 |
| 1319 | func go_serve_conn(cfd: i64, cfg: *i64) -> i64 called by 6: mainmainmainmainmainmain calls 20: sys_set_socket_timeoutsys_mmapgo_read_fullgo_find_seqgo_reqpathgo_starts+14 |