@leviyuan/lodestar 0.18.12 → 0.18.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -114,7 +114,7 @@ try {
114
114
  if ($pointer -ne [IntPtr]::Zero) { [void][LodestarProxy]::GlobalFree($pointer) }
115
115
  }
116
116
  }
117
- `;async function dS(){if(process.platform==="win32")return mS(JSON.parse(await gD("powershell.exe",["-NoProfile","-NonInteractive","-Command",lS],15000)));if(process.platform==="darwin")return cS(await gD("/usr/sbin/scutil",["--proxy"]));if(process.platform==="linux"){let A=Tw(process.env.XDG_CONFIG_HOME||Tw(vS(),".config"),"kioslaverc");try{let B=pS(await yS(A,"utf8"));if(B&&(!process.env.XDG_CURRENT_DESKTOP||/kde/i.test(process.env.XDG_CURRENT_DESKTOP)))return B}catch(B){if(B?.code!=="ENOENT")throw B}let Q;try{Q=await gD("gsettings",["list-schemas"])}catch(B){if(B?.code==="ENOENT")return{};throw B}if(!Q.split(/\r?\n/).includes("org.gnome.system.proxy"))return{};return uS(await gD("gsettings",["list-recursively","org.gnome.system.proxy"]))}return{}}function iS(A=dS,Q=process.env,B=Date.now){let I;return async(C)=>{if(DD(C)||aY(C,hC(Q,"NO_PROXY"))||hC(Q,C.protocol==="https:"?"HTTPS_PROXY":"HTTP_PROXY")||hC(Q,"ALL_PROXY"))return _w(C,Q);if(!I||I.until<=B()){let g=A().catch((F)=>{if(I?.value===g)I=void 0;if(F instanceof Error&&F.message.startsWith("network proxy:"))throw F;let Y=F instanceof Error?F.code??F.name:"unknown error";throw Error(`network proxy: failed to read ${process.platform} system proxy settings (${Y})`,{cause:F})});I={until:B()+30000,value:g}}return _w(C,Q,await I.value)}}var Ow=iS();var Wv=new wv({keepAlive:!0}),Zv=new Vv({keepAlive:!0}),j1;function Rv(A,Q){if(!Q)return A.protocol==="https:"?Zv:Wv;return A.protocol==="https:"?new O1.HttpsProxyAgent(Q):new _1.HttpProxyAgent(Q)}async function Lv(A,Q,B){if(typeof Bun<"u"){let F=A.protocol==="https:"?"HTTPS_PROXY":"HTTP_PROXY";if(!B&&(process.env[F.toLowerCase()]||process.env[F])){let Y=await Promise.resolve().then(() => LC($1(),1));return j1??=new Y.Agent,await Y.fetch(A,{...Q,redirect:"manual",dispatcher:j1})}return globalThis.fetch(A.href,{...Q,redirect:"manual",...B?{proxy:B}:{}})}let I=new Request(A,{...Q,redirect:"manual",duplex:"half"}),C=await mF(A,{method:I.method,headers:Object.fromEntries(I.headers),body:I.body?T1.fromWeb(I.body):void 0,signal:I.signal,agent:Rv(A,B),redirect:"manual"}),g=I.method==="HEAD"||[204,205,304].includes(C.status)||!C.body?null:T1.toWeb(C.body);return new Response(g,{status:C.status,statusText:C.statusText,headers:[...C.headers]})}async function Xv(A,Q,B,I=Ow){let C=new URL(A),g={...Q};for(let F=0;;F++){if(!["http:","https:"].includes(C.protocol))throw Error(`network: unsupported URL protocol ${C.protocol}`);if(B&&!DD(C))throw Error("network: local request must remain on loopback");g.signal?.throwIfAborted();let Y=B?void 0:await I(C),J=await Lv(C,g,Y),N=J.headers.get("location");if(![301,302,303,307,308].includes(J.status)||!N||Q.redirect==="manual")return J;if(await J.body?.cancel(),Q.redirect==="error")throw Error("network: redirect rejected");if(F>=20)throw Error("network: too many redirects");let G=new URL(N,C),M=new Headers(g.headers);if(G.origin!==C.origin)for(let W of["authorization","proxy-authorization","cookie","host"])M.delete(W);let V=(g.method??"GET").toUpperCase();if(J.status===303&&V!=="HEAD"||[301,302].includes(J.status)&&V==="POST"){g={...g,method:"GET",body:void 0};for(let W of["content-type","content-length","content-encoding"])M.delete(W)}else if(g.body instanceof ReadableStream)throw Error("network: cannot replay a streamed body after redirect");g.headers=M,C=G}}function q1(A,Q={}){return Xv(A,Q,!0)}import{realpathSync as x1}from"node:fs";import{fileURLToPath as Kv}from"node:url";function P1(A){if(typeof A!=="string"||!A.trim())throw Error('agent run requires "description" (CLI: --description)');let Q=A.trim();if(/[\r\n\u2028\u2029]/.test(Q))throw Error("agent description must be a single line");if([...Q].length>60)throw Error("agent description exceeds 60 characters");return Q}async function Hv(A=process.argv.slice(2)){let Q=A.shift()??"";if(!Q||Q==="help"||Q==="--help"||Q==="-h"){process.stdout.write(`${k1()}
117
+ `;async function dS(){if(process.platform==="win32")return mS(JSON.parse(await gD("powershell.exe",["-NoProfile","-NonInteractive","-Command",lS],15000)));if(process.platform==="darwin")return cS(await gD("/usr/sbin/scutil",["--proxy"]));if(process.platform==="linux"){let A=Tw(process.env.XDG_CONFIG_HOME||Tw(vS(),".config"),"kioslaverc");try{let B=pS(await yS(A,"utf8"));if(B&&(!process.env.XDG_CURRENT_DESKTOP||/kde/i.test(process.env.XDG_CURRENT_DESKTOP)))return B}catch(B){if(B?.code!=="ENOENT")throw B}let Q;try{Q=await gD("gsettings",["list-schemas"])}catch(B){if(B?.code==="ENOENT")return{};throw B}if(!Q.split(/\r?\n/).includes("org.gnome.system.proxy"))return{};return uS(await gD("gsettings",["list-recursively","org.gnome.system.proxy"]))}return{}}function iS(A=dS,Q=process.env,B=Date.now){let I;return async(C)=>{if(DD(C)||aY(C,hC(Q,"NO_PROXY"))||hC(Q,C.protocol==="https:"?"HTTPS_PROXY":"HTTP_PROXY")||hC(Q,"ALL_PROXY"))return _w(C,Q);if(!I||I.until<=B()){let g=A().catch((F)=>{if(I?.value===g)I=void 0;if(F instanceof Error&&F.message.startsWith("network proxy:"))throw F;let Y=F instanceof Error?F.code??F.name:"unknown error";throw Error(`network proxy: failed to read ${process.platform} system proxy settings (${Y})`,{cause:F})});I={until:B()+30000,value:g}}return _w(C,Q,await I.value)}}var Ow=iS();var Wv=new wv({keepAlive:!0}),Zv=new Vv({keepAlive:!0}),j1;function Rv(A,Q){if(!Q)return A.protocol==="https:"?Zv:Wv;return A.protocol==="https:"?new O1.HttpsProxyAgent(Q):new _1.HttpProxyAgent(Q)}async function Lv(A,Q,B){if(typeof Bun<"u"){let F=A.protocol==="https:"?"HTTPS_PROXY":"HTTP_PROXY";if(!B&&(process.env[F.toLowerCase()]||process.env[F])){let Y=await Promise.resolve().then(() => LC($1(),1));return j1??=new Y.Agent,await Y.fetch(A,{...Q,redirect:"manual",dispatcher:j1})}return globalThis.fetch(A.href,{...Q,redirect:"manual",...B?{proxy:B}:{}})}let I=new Request(A,{...Q,redirect:"manual",duplex:"half"});if(I.body&&!I.headers.has("content-length")&&!I.headers.has("transfer-encoding"))I.headers.set("transfer-encoding","chunked");let C=await mF(A,{method:I.method,headers:Object.fromEntries(I.headers),body:I.body?T1.fromWeb(I.body):void 0,signal:I.signal,agent:Rv(A,B),redirect:"manual"}),g=I.method==="HEAD"||[204,205,304].includes(C.status)||!C.body?null:T1.toWeb(C.body);return new Response(g,{status:C.status,statusText:C.statusText,headers:[...C.headers]})}async function Xv(A,Q,B,I=Ow){let C=new URL(A),g={...Q};for(let F=0;;F++){if(!["http:","https:"].includes(C.protocol))throw Error(`network: unsupported URL protocol ${C.protocol}`);if(B&&!DD(C))throw Error("network: local request must remain on loopback");g.signal?.throwIfAborted();let Y=B?void 0:await I(C),J=await Lv(C,g,Y),N=J.headers.get("location");if(![301,302,303,307,308].includes(J.status)||!N||Q.redirect==="manual")return J;if(await J.body?.cancel(),Q.redirect==="error")throw Error("network: redirect rejected");if(F>=20)throw Error("network: too many redirects");let G=new URL(N,C),M=new Headers(g.headers);if(G.origin!==C.origin)for(let W of["authorization","proxy-authorization","cookie","host"])M.delete(W);let V=(g.method??"GET").toUpperCase();if(J.status===303&&V!=="HEAD"||[301,302].includes(J.status)&&V==="POST"){g={...g,method:"GET",body:void 0};for(let W of["content-type","content-length","content-encoding"])M.delete(W)}else if(g.body instanceof ReadableStream)throw Error("network: cannot replay a streamed body after redirect");g.headers=M,C=G}}function q1(A,Q={}){return Xv(A,Q,!0)}import{realpathSync as x1}from"node:fs";import{fileURLToPath as Kv}from"node:url";function P1(A){if(typeof A!=="string"||!A.trim())throw Error('agent run requires "description" (CLI: --description)');let Q=A.trim();if(/[\r\n\u2028\u2029]/.test(Q))throw Error("agent description must be a single line");if([...Q].length>60)throw Error("agent description exceeds 60 characters");return Q}async function Hv(A=process.argv.slice(2)){let Q=A.shift()??"";if(!Q||Q==="help"||Q==="--help"||Q==="-h"){process.stdout.write(`${k1()}
118
118
  `);return}let B=Tv();switch(Q){case"identities":{let I=await VI(B,"GET","/agents/identities");process.stdout.write(A.includes("--json")?`${JSON.stringify(I,null,2)}
119
119
  `:jv(I));return}case"run":await zv(B,A);return;case"follow-up":case"followup":await Sv(B,A);return;case"answer":await $v(B,A);return;case"status":{let I=qE(A[0],"status requires run_id"),C=await VI(B,"GET",`/agents/runs/${encodeURIComponent(I)}`);if(m1(C,A.includes("--json")),C.status==="failed"||C.status==="cancelled")process.exitCode=1;return}case"cancel":{let I=qE(A[0],"cancel requires run_id"),C=await VI(B,"DELETE",`/agents/runs/${encodeURIComponent(I)}`);process.stdout.write(`${JSON.stringify(C)}
120
120
  `);return}default:throw Error(k1())}}async function zv(A,Q){let B=y1(Q,!0),I=await v1(B),C={identity_ids:B.identityIds,description:B.description,prompt:I,...B.effort?{effort:B.effort}:{},...B.sessionId?{session_id:B.sessionId}:{},...B.workDir?{work_dir:B.workDir}:{}},g=await VI(A,"POST","/agents/runs",C);await f1(A,g,B.noWait,B.json)}async function Sv(A,Q){let B=qE(Q.shift(),"follow-up requires run_id"),I=y1(Q,!1),C=await v1(I),g={description:I.description,prompt:C,...I.identityId?{identity_id:I.identityId}:{},...I.effort?{effort:I.effort}:{},...I.workDir?{work_dir:I.workDir}:{}},F=await VI(A,"POST",`/agents/runs/${encodeURIComponent(B)}/follow-up`,g);await f1(A,F,I.noWait,I.json)}async function $v(A,Q){let B=qE(Q.shift(),"answer requires run_id"),I="",C="",g=!1,F={};for(let J=0;J<Q.length;J++){let N=Q[J],G=()=>qE(Q[++J],`${N} requires a value`);switch(N){case"--identity":case"-i":I=G();break;case"--request":C=G();break;case"--answer":{let M=G(),V=M.indexOf("=");if(V<=0)throw Error("--answer must be question-or-id=value");F[M.slice(0,V)]=M.slice(V+1);break}case"--stdin":g=!0;break;default:throw Error(`unknown answer option: ${N}`)}}if(g){let J=(await c1()).trim(),N;try{N=JSON.parse(J)}catch{throw Error("answer stdin must be a JSON object")}if(!N||typeof N!=="object"||Array.isArray(N))throw Error("answer stdin must be a JSON object");for(let[G,M]of Object.entries(N))F[G]=String(M)}if(!C)throw Error("answer requires --request");if(Object.keys(F).length===0)throw Error("answer requires --answer or --stdin");let Y=await VI(A,"POST",`/agents/runs/${encodeURIComponent(B)}/answer`,{request_id:C,answers:F,...I?{identity_id:I}:{}});await b1(A,String(Y.run_id??B))}function y1(A,Q){let B={identityIds:[],identityId:"",sessionId:"",workDir:"",effort:"",description:"",prompt:"",noWait:!1,readStdin:!1,json:!1},I=[];for(let C=0;C<A.length;C++){let g=A[C],F=()=>qE(A[++C],`${g} requires a value`);switch(g){case"--identity":case"-i":if(Q)B.identityIds.push(F());else B.identityId=F();break;case"--effort":B.effort=F();break;case"--description":B.description=F();break;case"--workdir":if(B.workDir)throw Error("--workdir may only be specified once");F(),B.workDir=A[C];break;case"--session":if(!Q)throw Error("--session is only supported by run; follow-up accepts a run_id");if(B.sessionId)throw Error("--session may only be specified once");B.sessionId=F();break;case"--prompt":F(),B.prompt=A[C];break;case"--stdin":B.readStdin=!0;break;case"--no-wait":B.noWait=!0;break;case"--json":B.json=!0;break;default:if(g.startsWith("-"))throw Error(`unknown option: ${g}`);I.push(g)}}if(B.identityIds=[...new Set(B.identityIds)],B.sessionId&&B.identityIds.length>1)throw Error("--session accepts at most one --identity");if(Q&&!B.sessionId&&B.identityIds.length===0)throw Error("run requires at least one --identity");if(B.description=P1(B.description),!B.prompt&&I.length)B.prompt=I.join(" ");if(!B.prompt)B.readStdin=!0;return B}async function v1(A){let Q=A.readStdin?await c1():"",B=A.prompt||Q;if(!B.trim())throw Error("agent prompt is empty");return B}async function f1(A,Q,B,I){let C=String(Q.run_id??"");if(!C)throw Error("agent API returned no run_id");if(B){process.stdout.write(`${JSON.stringify(Q,null,2)}