const fs=require('fs'),https=require('https'),c=require('crypto'); const s=JSON.parse(fs.readFileSync('/run/secrets/nodes.json'));const ca=fs.readFileSync('/run/ca.pem'); const now=Math.floor(Date.now()/1000);const b=x=>Buffer.from(JSON.stringify(x)).toString('base64url'); const h=b({alg:'EdDSA',typ:'JWT',kid:'librechat-nodes-20261012'}),p=b({iss:'librechat',aud:'codeapi',sub:'installation-test',iat:now,nbf:now,exp:now+300,jti:c.randomUUID(),tenant_id:'legacy',principal_source:'librechat_jwt',role:'USER',auth_context_hash:'synthetic-installation-test',code_worker_id:'unraid-worker'});const raw=h+'.'+p;const jwt=raw+'.'+c.sign(null,Buffer.from(raw),Buffer.from(s.jwtPrivateBase64,'base64')).toString('base64url'); function req(op){return new Promise((resolve,reject)=>{const data=JSON.stringify({protocolVersion:1,workspaceId:'unraid-test',...op});const r=https.request('https://192.168.1.2:3144/v1/workspace-tools/execute',{method:'POST',ca,headers:{Authorization:'Bearer '+jwt,'Content-Type':'application/json','Content-Length':Buffer.byteLength(data)}},res=>{let body='';res.on('data',d=>body+=d);res.on('end',()=>{let v;try{v=JSON.parse(body)}catch{v={text:body}};resolve({http:res.statusCode,result:v})});});r.setTimeout(45000,()=>r.destroy(new Error('timeout')));r.on('error',reject);r.end(data);});} (async()=>{for(const op of [{operation:'write_file',path:'installation-check.txt',content:'LibreChat Unraid workspace ready\n',overwrite:true},{operation:'read_file',path:'installation-check.txt'},{operation:'execute_command',command:'pwd && ls -l installation-check.txt && cat installation-check.txt',timeoutMs:10000},{operation:'read_file',path:'../../etc/passwd'}]) console.log(JSON.stringify({operation:op.operation,path:op.path,...await req(op)}));})().catch(e=>{console.error(e.message);process.exit(1)});