okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
99866a47a
main
1// Throwaway: serves the demo host unchanged, except POST /api/chat/stream, which streams a long scripted reply (NDJSON frames like the real host). 2import http from 'node:http' ; 3const UP = Number ( process . env . UP ?? 18791 ), PORT = Number ( process . env . PORT ?? 18790 ); 4const TOK = Number ( process . env . REPLY_TOKENS ?? 12000 ), REASON = Number ( process . env . REASON_TOKENS ?? 3000 ), RATE = Number ( process . env . RATE ?? 400 ); 5const sleep = ms => new Promise ( r => setTimeout ( r , ms )); 6const para = i => `### Section ${ i } \n\nThis is paragraph ${ i } with **bold**, *italic*, \`inline code\` and a link [x](https://example.com/ ${ i } ). The measured value is about ${ i } units and the results agree with the earlier runs, which is what we expected from the model. 7 8More prose follows here so that a paragraph looks like real writing and not like a stress pattern.\n\n- item one of ${ i } \n- item two of ${ i } \n\n\`\`\`python\ndef f_ ${ i } (a, b):\n total = a + b * ${ i } \n return total\n\`\`\`\n\n| a | b |\n|---|---|\n| ${ i } | ${ i * 2 } |\n\n` ; 9http . createServer ( async ( req , res ) => { 10if ( req . method === 'POST' && req . url . startsWith ( '/api/chat/stream' )) { 11let raw = '' ; for await ( const c of req ) raw += c ; 12res . writeHead ( 200 , { 'content-type' :'application/x-ndjson' }); 13const w = o => res . write ( JSON . stringify ( o ) + '\n' ); 14w ({ type :'start' , model :'Mock' , contextMax :131072 , requestId :'r' + Date . now () }); 15let sent = 0 , i = 0 ; 16const per = Math . max ( 1 , Math . round ( RATE / 50 )); 17while ( sent < REASON ) { w ({ type :'reasoning' , text :'thinking about step ' + ( i ++ ) + ' of the problem. ' . repeat ( 1 ) }); sent += 9 ; if ( sent % per < 9 ) await sleep ( 20 ); } 18sent = 0 ; i = 0 ; 19while ( sent < TOK ) { const p = para ( i ++ ); for ( let k = 0 ; k < p . length ; k += 24 ) { w ({ type :'delta' , text :p . slice ( k , k + 24 ) }); sent += 6 ; if (( sent / 6 ) % Math . max ( 1 , Math . round ( per / 2 )) === 0 ) await sleep ( 10 ); } w ({ type :'stats' , tokensOut :sent , tps :90 }); } 20w ({ type :'done' , tokensIn :100 , tokensOut :sent , tps :90 , durationMs :1000 , usageSource :'engine' }); 21return res . end (); 22} 23const up = http . request ({ host :'127.0.0.1' , port :UP , path :req . url , method :req . method , headers :req . headers }, r => { res . writeHead ( r . statusCode , r . headers ); r . pipe ( res ); }); 24up . on ( 'error' , () => { res . writeHead ( 502 ); res . end (); }); 25req . pipe ( up ); 26}). listen ( PORT , '127.0.0.1' , () => console . log ( 'proxy on' , PORT ));