@leviyuan/lodestar 0.16.4 → 0.16.5
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.
- package/dist/lodestar-agent.js +1 -1
- package/dist/lodestar.js +163 -159
- package/package.json +1 -1
package/dist/lodestar-agent.js
CHANGED
|
@@ -6,7 +6,7 @@ import{resolve as E}from"node:path";import{fileURLToPath as b}from"node:url";asy
|
|
|
6
6
|
`);return}await h(e,r)}async function h(e,n){let t=!1,r=()=>{if(t)return;t=!0,d(e,"DELETE",`/agents/runs/${encodeURIComponent(n)}`).then(()=>process.exit(130),(s)=>{process.stderr.write(`lodestar-agent: cancellation failed: ${_(s)}
|
|
7
7
|
`),process.exit(1)})};process.once("SIGINT",r),process.once("SIGTERM",r);try{while(!0){let s=await d(e,"GET",`/agents/runs/${encodeURIComponent(n)}`);if(s.status==="needs_input"||s.status==="completed"||s.status==="failed"||s.status==="cancelled"){if(process.stdout.write($(s)),s.status==="failed"||s.status==="cancelled")process.exitCode=1;return}await new Promise((i)=>setTimeout(i,1000))}}finally{process.off("SIGINT",r),process.off("SIGTERM",r)}}function q(){let e=String(process.env.LODESTAR_AGENT_URL??"").replace(/\/+$/,""),n=String(process.env.LODESTAR_AGENT_CAPABILITY??"");if(!e||!n)throw Error("lodestar-agent must run inside a Lodestar-managed Agent session (missing capability)");return{baseUrl:e,capability:n}}async function d(e,n,t,r){let s=await fetch(`${e.baseUrl}${t}`,{method:n,headers:{authorization:`Bearer ${e.capability}`,...r?{"content-type":"application/json"}:{}},...r?{body:JSON.stringify(r)}:{}}),i=await s.text(),o;try{o=JSON.parse(i)}catch{throw Error(`agent API ${n} ${t} returned HTTP ${s.status}: ${i||"(empty)"}`)}if(!s.ok)throw Error(o?.error??`agent API HTTP ${s.status}`);return o}function A(e){let n=[`catalog ${e.catalog_generation??"MISS"}`];for(let t of e.identities??[])n.push([t.status==="ready"?"✅":"MISS",t.id,t.display_name,t.model,`default-effort=${t.default_effort}`,t.source_default?"source-default":"",t.reason??""].filter(Boolean).join(" · "));for(let t of e.source_failures??[])n.push(`MISS · ${t.display} · ${t.reason}`);return`${n.join(`
|
|
8
8
|
`)}
|
|
9
|
-
`}function $(e){let n=[`# Lodestar agent ${e.run_id??"MISS"}`,"",`- Status: ${e.status??"MISS"}
|
|
9
|
+
`}function $(e){let n=[`# Lodestar agent ${e.run_id??"MISS"}`,"",`- Status: ${e.status??"MISS"}`,...e.parent_run_id?[`- Parent: ${e.parent_run_id} (${e.parent_kind??"delegate"})`]:[]];if(e.error)n.push(`- Error: ${e.error}`);for(let t of e.workers??[]){if(n.push("",`## ${t.identity_name??t.identity_id}`,"",`Status: ${t.status}`),t.session_id)n.push(`Session: ${t.session_id}`);if(t.error)n.push("",`Error: ${t.error}`);if(t.pending_input){n.push("",`Input request: ${t.pending_input.request_id}`);for(let r of t.pending_input.questions??[])if(n.push(`- [${r.id}] ${r.question}`),r.options?.length)n.push(` Options: ${r.options.map((s)=>s.label).join(" / ")}`);n.push("","Answer with:",`lodestar-agent answer ${e.run_id} --identity '${t.identity_id}' --request '${t.pending_input.request_id}' --stdin`)}if(t.output)n.push("",t.output)}if(e.presentation_errors?.length)n.push("","Presentation errors:",...e.presentation_errors.map((t)=>`- ${t}`));return`${n.join(`
|
|
10
10
|
`)}
|
|
11
11
|
`}async function S(){if(process.stdin.isTTY)return"";let e=[];for await(let n of process.stdin)e.push(Buffer.isBuffer(n)?n:Buffer.from(n));return Buffer.concat(e).toString("utf8")}function c(e,n){if(!e?.trim())throw Error(n);return e.trim()}function w(){return["Usage:"," lodestar-agent identities [--json]"," lodestar-agent run --identity <id> [--identity <id>...] [--effort <level>] --stdin"," lodestar-agent follow-up <run_id> [--identity <id>] [--effort <level>] --stdin"," lodestar-agent answer <run_id> [--identity <id>] --request <id> (--answer key=value | --stdin)"," lodestar-agent status <run_id>"," lodestar-agent cancel <run_id>"].join(`
|
|
12
12
|
`)}function _(e){return e instanceof Error?e.message:String(e)}if(process.argv[1]&&E(process.argv[1])===b(import.meta.url))C().catch((e)=>{process.stderr.write(`lodestar-agent: ${_(e)}
|