coding-agents-sdk 0.10.0 → 0.12.0
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/README.md +12 -9
- package/dist/Agent-4TZ8JK66.mjs +4 -0
- package/dist/{SdkAgent-DQfLwPwY.mjs → SdkAgent-p0nJ6dWV.mjs} +1 -1
- package/dist/adapters/claude-code-cli/index.d.mts +2 -2
- package/dist/adapters/claude-code-cli/index.mjs +1 -1
- package/dist/adapters/claude-code-cli-pty/index.d.mts +3 -0
- package/dist/adapters/claude-code-cli-pty/index.mjs +35 -0
- package/dist/adapters/claude-code-sdk/index.d.mts +2 -2
- package/dist/adapters/claude-code-sdk/index.mjs +4 -4
- package/dist/adapters/codex-cli/index.d.mts +2 -2
- package/dist/adapters/codex-cli/index.mjs +2 -2
- package/dist/adapters/codex-sdk/index.d.mts +2 -2
- package/dist/adapters/codex-sdk/index.mjs +1 -1
- package/dist/adapters/cursor-cli/index.d.mts +2 -2
- package/dist/adapters/cursor-cli/index.mjs +1 -1
- package/dist/adapters/cursor-sdk/index.d.mts +2 -2
- package/dist/adapters/cursor-sdk/index.mjs +1 -1
- package/dist/adapters/gemini-cli/index.d.mts +2 -2
- package/dist/adapters/gemini-cli/index.mjs +1 -1
- package/dist/adapters/opencode-cli/index.d.mts +2 -2
- package/dist/adapters/opencode-cli/index.mjs +1 -1
- package/dist/adapters/pi-cli/index.d.mts +2 -2
- package/dist/adapters/pi-cli/index.mjs +1 -1
- package/dist/{classify-error-BcWmNftw.mjs → classify-error-BPQtzEVV.mjs} +4 -4
- package/dist/container/index.d.mts +2 -2
- package/dist/container/index.mjs +1 -1
- package/dist/{container-D31bbA4L.mjs → container-46QA1d3v.mjs} +1 -1
- package/dist/container-DBXaA-Iv.mjs +1 -0
- package/dist/container-DRj7xq5x.mjs +1 -0
- package/dist/{container-BhXUiAiK.mjs → container-Dg68bfte.mjs} +1 -1
- package/dist/{container-TizHce_7.mjs → container-gJ8B-Z5B.mjs} +1 -1
- package/dist/diff-BJWXJsjx.mjs +1 -0
- package/dist/{events-Dd9r9luo.d.mts → events-B0BpIsW2.d.mts} +143 -4
- package/dist/execution-target-CdlYXh6Z.mjs +1 -0
- package/dist/index-5bx9TIY_.d.mts +60 -0
- package/dist/index-B5NFoNlS.d.mts +195 -0
- package/dist/index-B9ze9hTN.d.mts +97 -0
- package/dist/{index-DZDlHIep.d.mts → index-BKK-3gye.d.mts} +44 -13
- package/dist/{index-J7V9dJTb.d.mts → index-BQ8cUo2i.d.mts} +50 -19
- package/dist/index-C9XD71QR.d.mts +429 -0
- package/dist/{index-B-rto_J2.d.mts → index-CG2m7pFJ.d.mts} +77 -1
- package/dist/index-CG5DS_NB.d.mts +58 -0
- package/dist/index-DPP4zoiJ.d.mts +68 -0
- package/dist/{index-BNeL0BbU.d.mts → index-DdyD2ji1.d.mts} +68 -2
- package/dist/index-DzFF15zC.d.mts +104 -0
- package/dist/index-XWqpUSBc.d.mts +69 -0
- package/dist/index.d.mts +69 -16
- package/dist/index.mjs +1 -1
- package/dist/oci-DmEG3Ia3.mjs +1 -0
- package/dist/{parser-BBJPNGZ2.mjs → parser-Dz239_vv.mjs} +2 -2
- package/dist/sandbox/index.d.mts +2 -2
- package/dist/sandbox/index.mjs +1 -1
- package/dist/sandbox-C5vzNxZR.mjs +4 -0
- package/dist/schemas/index.d.mts +1 -1
- package/dist/schemas/index.mjs +1 -1
- package/dist/spawner-BB6W3FVi.mjs +1 -0
- package/dist/types-CGzSzwfB.d.mts +476 -0
- package/dist/util-DcPzh_0u.mjs +1 -0
- package/package.json +24 -24
- package/dist/Agent-BD2xHVi0.mjs +0 -4
- package/dist/adapters/claude-cli-pty/index.d.mts +0 -3
- package/dist/adapters/claude-cli-pty/index.mjs +0 -7
- package/dist/container-BurV5WG9.mjs +0 -1
- package/dist/diff-DWM1ciiV.mjs +0 -1
- package/dist/errors-CeKI_bYK.mjs +0 -1
- package/dist/execution-target-CGTSqVEP.mjs +0 -1
- package/dist/index-B4RAMnx_.d.mts +0 -46
- package/dist/index-BdDz7C4J.d.mts +0 -39
- package/dist/index-BiWkGgnz.d.mts +0 -46
- package/dist/index-BllemWbi.d.mts +0 -42
- package/dist/index-C7J_hmQs.d.mts +0 -67
- package/dist/index-CaUzD36R.d.mts +0 -42
- package/dist/index-D-8EmRnQ.d.mts +0 -85
- package/dist/index-lGZ1lQkG.d.mts +0 -246
- package/dist/oci-tjdSZfTm.mjs +0 -1
- package/dist/sandbox-_As0qZWn.mjs +0 -4
- package/dist/spawner-BJesLc8I.mjs +0 -1
- package/dist/types-D6kxBNzj.d.mts +0 -195
- package/dist/util-CGg8cK92.mjs +0 -1
- /package/dist/{env-DIXTVzTs.mjs → env-Cb8MIvH7.mjs} +0 -0
- /package/dist/{schemas-mNF2Xlg_.mjs → schemas-CkdQXAep.mjs} +0 -0
- /package/dist/{shell-Dewbmt9R.mjs → shell-DvWFuFKb.mjs} +0 -0
- /package/dist/{structured-output-nPFh_ZoY.mjs → structured-output-cpLrrrTN.mjs} +0 -0
- /package/dist/{types-CwvWHEpy.mjs → types-B72tDMEZ.mjs} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as e,i as t,n}from"../../util-
|
|
1
|
+
import{a as e,i as t,n}from"../../util-DcPzh_0u.mjs";import{c as r,l as i,o as a,s as o}from"../../classify-error-BPQtzEVV.mjs";import{t as s}from"../../execution-target-CdlYXh6Z.mjs";import{t as c}from"../../Agent-4TZ8JK66.mjs";import{z as l}from"zod/v4";const u=e=>typeof e==`string`?e:void 0,d=e=>typeof e==`number`&&Number.isFinite(e)?e:void 0,f=e=>{if(typeof e==`string`)return e;if(e===null)return``;try{return JSON.stringify(e)}catch{return String(e)}},p=()=>crypto.randomUUID(),m=()=>({steps:0,cost:0,inputTokens:0,outputTokens:0,cacheReadTokens:0,cacheWriteTokens:0}),h=e=>{let t=e;return u(t.sessionID)??u(t.session_id)},g=(e,t)=>{let r=u((n(e.part)?e.part:void 0)?.text)??``;return r.trim()?{events:[a(t.runId,`message`,{sessionId:t.sessionId,model:null,role:`assistant`,content:[i(r)],text:r})]}:{events:[]}},_=(e,t)=>{let r=u((n(e.part)?e.part:void 0)?.text)??``;return r.trim()?{events:[a(t.runId,`reasoning`,{sessionId:t.sessionId,model:null,content:[i(r)],text:r})]}:{events:[]}},v=(e,t)=>{let r=n(e.part)?e.part:void 0;if(!r)return{events:[]};let i=u(r.callID)??p(),o=u(r.tool)??`tool`,s=n(r.state)?r.state:void 0;if(!s)return{events:[]};let c=n(s.input)?s.input:void 0,l=s.status===`error`,d=l?u(s.error)??f(s.output)??`Tool call failed.`:f(s.output);return{events:[a(t.runId,`tool-call`,{sessionId:t.sessionId,model:null,toolCallId:i,toolName:o,input:c}),a(t.runId,`tool-result`,{sessionId:t.sessionId,toolCallId:i,toolName:o,input:c,output:d,isError:l||void 0,error:l?d:void 0})],toolCalls:[{toolCallId:i,toolName:o,input:c}]}},y=(e,r,i)=>{let a=n(e.part)?e.part:void 0;if(!a)return{events:[]};let o=u(a.reason),s=d(a.cost)??0,c=n(a.tokens)?a.tokens:void 0,l=n(c?.cache)?c.cache:void 0;return i.steps+=1,i.cost+=s,i.inputTokens+=d(c?.input)??0,i.outputTokens+=d(c?.output)??0,i.cacheReadTokens+=d(l?.read)??0,i.cacheWriteTokens+=d(l?.write)??0,o===`stop`?{events:[],state:{stats:{turns:i.steps,costUsd:i.cost,inputTokens:i.inputTokens,outputTokens:i.outputTokens,cacheReadInputTokens:i.cacheReadTokens,cacheCreationInputTokens:i.cacheWriteTokens,totalTokens:t(i.inputTokens,i.outputTokens,i.cacheReadTokens,i.cacheWriteTokens)},status:`completed`}}:{events:[]}},b=(e,t)=>{let r=n(e.error)?e.error:void 0,i=u((n(r?.data)?r.data:void 0)?.message)??u(r?.message)??u(r?.name)??`unknown error`;return{events:[a(t.runId,`stderr`,{sessionId:t.sessionId,text:i})],state:{status:`failed`,error:{kind:`provider`,message:i}}}},x=(e,t,n)=>{let r=e;switch(e.type){case`text`:return g(r,t);case`reasoning`:return _(r,t);case`tool_use`:return v(r,t);case`step_finish`:return y(r,t,n);case`error`:return b(r,t);default:return{events:[]}}},S=o(l.object({type:l.string()}).passthrough()),C={structuredOutput:!1,sessionResume:!0,sessionFork:!0,imageInput:!1,mcp:!0,eventStreaming:!0};var w=class extends c{type=`opencode-cli`;creationOptions;runDefaults;stepAccumulators=new Map;constructor(t={}){super({type:`opencode-cli`,capabilities:C,defaults:{cwd:t.cwd,env:t.env,command:e(t.command??`opencode`),sessionId:t.sessionId,model:t.model},spawner:t.spawner,executionTarget:t.container??t.sandbox,logPath:t.logPath,onEvent:t.onEvent}),this.creationOptions=t,this.runDefaults={agent:t.agent,files:t.files?[...t.files]:void 0,forkSession:t.forkSession,share:t.share,thinking:t.thinking,title:t.title,variant:t.variant,extraArgs:t.extraArgs?[...t.extraArgs]:void 0}}buildArgs(e,t){let n=[`run`,`--format`,`json`],i=r(e.input),a=e.agent??this.runDefaults.agent,o=e.files??this.runDefaults.files,s=e.forkSession??this.runDefaults.forkSession,c=e.share??this.runDefaults.share,l=e.thinking??this.runDefaults.thinking,u=e.title??this.runDefaults.title,d=e.variant??this.runDefaults.variant,f=e.extraArgs??this.runDefaults.extraArgs;if(e.model&&n.push(`--model`,e.model),a&&n.push(`--agent`,a),o&&o.length>0)for(let e of o)n.push(`--file`,e);return t.requestedSessionId&&(n.push(`--session`,t.requestedSessionId),s&&n.push(`--fork`)),c&&n.push(`--share`),l&&n.push(`--thinking`),u!==void 0&&n.push(`--title`,u),d&&n.push(`--variant`,d),f&&f.length>0&&n.push(...f),n.push(`--`,i),n}buildEnv(e,t){return this.buildDefaultEnv(this.creationOptions.propagateEnv)}mapRawEvent(e,t){this.appendRawLog(e);let n=S(e);if(!n)return this.onParseError(JSON.stringify(e).slice(0,200),Error(`schema validation failed`)),{events:[]};let r=h(n)??t.sessionId,i=this.stepAccumulators.get(t.runId);i||(i=m(),this.stepAccumulators.set(t.runId,i));let a=x(n,{...t,sessionId:r},i);return r&&a.sessionId===void 0&&(a.sessionId=r),a}async onRunFinished(e){await super.onRunFinished(e),this.stepAccumulators.delete(e.runId)}};const T=e=>new w(s(e));export{T as createOpencodeCliAgent};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as PiCliThinkingLevel, i as PiCliRunOptions, n as PiCliAgent, o as PiEvent, r as PiCliAgentOptions, t as createPiCliAgent } from "../../index-
|
|
2
|
-
export { PiCliAgent, PiCliAgentOptions, PiCliRunOptions, PiCliThinkingLevel, PiEvent, createPiCliAgent };
|
|
1
|
+
import { a as PiCliThinkingLevel, i as PiCliRunOptions, n as PiCliAgent, o as PiEvent, r as PiCliAgentOptions, t as createPiCliAgent } from "../../index-DPP4zoiJ.mjs";
|
|
2
|
+
export { type PiCliAgent, type PiCliAgentOptions, type PiCliRunOptions, type PiCliThinkingLevel, type PiEvent, createPiCliAgent };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e}from"../../types-
|
|
1
|
+
import{n as e}from"../../types-B72tDMEZ.mjs";import{a as t,n}from"../../util-DcPzh_0u.mjs";import{c as r,l as i,o as a,s as o}from"../../classify-error-BPQtzEVV.mjs";import{t as s}from"../../execution-target-CdlYXh6Z.mjs";import{t as c}from"../../Agent-4TZ8JK66.mjs";import{z as l}from"zod/v4";const u=e=>typeof e==`string`?e:void 0,d=e=>typeof e==`number`&&Number.isFinite(e)?e:void 0,f=()=>crypto.randomUUID(),p=e=>{if(typeof e==`string`)return e;if(e==null)return``;try{return JSON.stringify(e)}catch{return String(e)}},m=e=>{if(typeof e==`string`)return e;if(!Array.isArray(e))return``;let t=[];for(let r of e)n(r)&&r.type===`text`&&typeof r.text==`string`&&t.push(r.text);return t.join(``)},h=e=>{let t=e;if(t.type===`session`)return u(t.id)},g=e=>({events:[],sessionId:u(e.id)??void 0}),_=()=>({events:[]}),v=(e,t,r)=>{let o=n(e.message)?e.message:void 0;if(!o||u(o.role)!==`assistant`)return{events:[]};let s=m(o.content),c=u(o.model)??r.model??null,l=[];return r.reasoningText&&l.push(a(t.runId,`reasoning`,{sessionId:t.sessionId,model:c,content:[i(r.reasoningText)],text:r.reasoningText})),s&&l.push(a(t.runId,`message`,{sessionId:t.sessionId,model:c,role:`assistant`,content:[i(s)],text:s})),u(o.stopReason)===`error`?{events:l,state:{output:{text:s||void 0},status:`failed`,error:{kind:`provider`,message:`Pi model returned an error stop reason.`}}}:s?{events:l,state:{output:{text:s}}}:{events:l}},y=(e,t,n)=>{let r=u(e.toolCallId)??f(),i=u(e.toolName)??`tool`,o=e.args===void 0?void 0:e.args;return{events:[a(t.runId,`tool-call`,{sessionId:t.sessionId,model:n.model??null,toolCallId:r,toolName:i,input:o})],toolCalls:[{toolCallId:r,toolName:i,input:o}]}},b=(e,t)=>{let n=u(e.toolCallId)??f(),r=!!e.isError,i=e.result,o=t.toolCalls.get(n),s=u(e.toolName)??o?.toolName;return{events:[a(t.runId,`tool-result`,{sessionId:t.sessionId,toolCallId:n,toolName:s,input:o?.input,output:i,isError:r||void 0,error:r?p(i):void 0})]}},x=e=>{let t=n(e.message)?e.message:void 0;if(!t)return;let r=n(t.usage)?t.usage:void 0;if(!r)return;let i=d(r.input),a=d(r.output),o=d(r.cacheRead)||void 0,s=d(r.cacheWrite)||void 0;return{turns:1,durationMs:0,costUsd:n(r.cost)?d(r.cost.total)??0:d(r.cost)??0,inputTokens:i,outputTokens:a,cacheReadInputTokens:o,cacheCreationInputTokens:s,totalTokens:(i??0)+(a??0)+(o??0)+(s??0)||void 0}},S=e=>{let t=x(e);return t?{events:[],state:{stats:t}}:{events:[]}},C=(e,t,n={})=>{let r=e;switch(e.type){case`session`:return g(r);case`message_update`:return _();case`message_end`:return v(r,t,n);case`tool_execution_start`:return y(r,t,n);case`tool_execution_end`:return b(r,t);case`turn_end`:return S(r);default:return{events:[]}}},w=o(l.object({type:l.string()}).passthrough()),T={structuredOutput:!1,sessionResume:!0,imageInput:!0,mcp:!1,eventStreaming:!0,sessionFork:!0},E=(e,t)=>({turns:(e?.turns??0)+t.turns,durationMs:(e?.durationMs??0)+(t.durationMs??0),apiDurationMs:(e?.apiDurationMs??0)+(t.apiDurationMs??0),costUsd:(e?.costUsd??0)+t.costUsd,inputTokens:t.inputTokens!==void 0||e?.inputTokens!==void 0?(e?.inputTokens??0)+(t.inputTokens??0):void 0,outputTokens:t.outputTokens!==void 0||e?.outputTokens!==void 0?(e?.outputTokens??0)+(t.outputTokens??0):void 0,cacheReadInputTokens:t.cacheReadInputTokens!==void 0||e?.cacheReadInputTokens!==void 0?(e?.cacheReadInputTokens??0)+(t.cacheReadInputTokens??0):void 0,cacheCreationInputTokens:t.cacheCreationInputTokens!==void 0||e?.cacheCreationInputTokens!==void 0?(e?.cacheCreationInputTokens??0)+(t.cacheCreationInputTokens??0):void 0,totalTokens:t.totalTokens!==void 0||e?.totalTokens!==void 0?(e?.totalTokens??0)+(t.totalTokens??0):void 0});var D=class n extends c{type=`pi-cli`;creationOptions;runDefaults;runTextBuffers=new Map;runReasoningBuffers=new Map;runAccumulatedStats=new Map;forkOnNextRun;constructor(e={}){super({type:`pi-cli`,capabilities:T,defaults:{cwd:e.cwd,env:e.env,command:t(e.command??`pi`),sessionId:e.sessionId,model:e.model,systemPrompt:e.systemPrompt},spawner:e.spawner,executionTarget:e.container??e.sandbox,logPath:e.logPath,onEvent:e.onEvent}),this.creationOptions=e,this.runDefaults={provider:e.provider,thinking:e.thinking,appendSystemPrompt:e.appendSystemPrompt,tools:e.tools?[...e.tools]:void 0,noTools:e.noTools,noSession:e.noSession,sessionDir:e.sessionDir,forkSession:e.forkSession,extraArgs:e.extraArgs?[...e.extraArgs]:void 0},this.forkOnNextRun=e.forkOnNextRun??!1}fork(){if(!this.sessionId)throw new e(`Cannot fork a Pi CLI agent before it has a sessionId.`);return new n({...this.creationOptions,sessionId:this.sessionId,forkSession:void 0,forkOnNextRun:!0})}onValidateRun(t,n){if((t.forkSession??this.runDefaults.forkSession??this.forkOnNextRun)&&!this.sessionId)throw new e(`forkSession requires an existing sessionId on the agent.`)}buildArgs(e,t){let n=[`--mode`,`json`],i=e.provider??this.runDefaults.provider,a=e.thinking??this.runDefaults.thinking,o=e.appendSystemPrompt??this.runDefaults.appendSystemPrompt,s=e.tools??this.runDefaults.tools,c=e.noTools??this.runDefaults.noTools,l=e.noSession??this.runDefaults.noSession,u=e.sessionDir??this.runDefaults.sessionDir,d=e.forkSession??this.runDefaults.forkSession??this.forkOnNextRun,f=e.extraArgs??this.runDefaults.extraArgs;e.model?i?n.push(`--model`,`${i}/${e.model}`):n.push(`--model`,e.model):i&&n.push(`--provider`,i),e.systemPrompt&&n.push(`--system-prompt`,e.systemPrompt),o&&n.push(`--append-system-prompt`,o),a&&n.push(`--thinking`,a),c?n.push(`--no-tools`):s&&s.length>0&&n.push(`--tools`,s.join(`,`)),t.requestedSessionId?d?n.push(`--fork`,t.requestedSessionId):n.push(`--session`,t.requestedSessionId):l?n.push(`--no-session`):u&&n.push(`--session-dir`,u),f&&f.length>0&&n.push(...f);for(let t of e.input)t.type===`image`&&n.push(`@${t.path}`);let p=r(e.input);return n.push(p),n}buildEnv(e,t){return this.buildDefaultEnv(this.creationOptions.propagateEnv)}mapRawEvent(e,t){this.appendRawLog(e);let n=w(e);if(!n)return this.onParseError(JSON.stringify(e).slice(0,200),Error(`schema validation failed`)),{events:[]};let r=h(n)??t.sessionId;if(this.forkOnNextRun&&t.requestedSessionId&&r&&r!==t.requestedSessionId&&(this.forkOnNextRun=!1),n.type===`message_update`){let e=n.assistantMessageEvent,r=typeof e?.type==`string`?e.type:void 0,i=typeof e?.delta==`string`?e.delta:``;if(r===`text_delta`&&i){let e=`${this.runTextBuffers.get(t.runId)??``}${i}`;this.runTextBuffers.set(t.runId,e)}else if(r===`thinking_delta`&&i){let e=`${this.runReasoningBuffers.get(t.runId)??``}${i}`;this.runReasoningBuffers.set(t.runId,e)}}let i={model:void 0};n.type===`message_end`&&(i.reasoningText=this.runReasoningBuffers.get(t.runId),this.runReasoningBuffers.delete(t.runId));let a=C(n,{...t,sessionId:r},i);if(r&&a.sessionId===void 0&&(a.sessionId=r),a.state?.output?.text!==void 0&&this.runTextBuffers.set(t.runId,a.state.output.text),n.type===`turn_end`&&a.state?.stats){let e=E(this.runAccumulatedStats.get(t.runId),a.state.stats);this.runAccumulatedStats.set(t.runId,e),a.state.stats=e}return a}async onRunFinished(e){await super.onRunFinished(e),this.runTextBuffers.delete(e.runId),this.runReasoningBuffers.delete(e.runId),this.runAccumulatedStats.delete(e.runId)}};const O=e=>new D(s(e));export{O as createPiCliAgent};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import{n as e,t}from"./types-
|
|
1
|
+
import{n as e,t}from"./types-B72tDMEZ.mjs";import{z as n}from"zod/v4";const r=()=>crypto.randomUUID(),i=()=>`evt_${crypto.randomUUID()}`,a=e=>({type:`text`,text:e}),o=e=>e.flatMap(e=>e.type===`text`?[e.text]:[]).join(`
|
|
2
2
|
`),s=e=>e.flatMap(e=>e.type===`text`?[e.text]:[]).join(`
|
|
3
3
|
|
|
4
|
-
`),c=e=>t=>{let n=e.safeParse(t);return n.success?n.data:null},l=(e,t,n)=>({id:n.id??i(),runId:e,timestamp:new Date,type:t,...n}),u=e=>e instanceof n.ZodType,d=e=>{if(!(`schema`in e))return{kind:`none`};let{schema:t}=e;return u(t)?{kind:`zod`,jsonSchema:n.toJSONSchema(t),zodSchema:t}:{kind:`json-schema`,jsonSchema:t}},f=(t,n,r,i)=>{let a=typeof i.input==`string`?[{type:`text`,text:i.input}]:i.input;if(a.length===0||a.every(e=>e.type===`text`&&e.text.trim()===``))throw new e(`Run input cannot be empty.`);if(!n.imageInput&&a.some(e=>e.type===`image`))throw new e(`${t} does not support image input.`);let o=d(i);if(!n.structuredOutput&&o.kind!==`none`)throw new e(`${t} does not support structured output.`);if(i.timeoutMs!==void 0&&(!Number.isFinite(i.timeoutMs)||i.timeoutMs<=0))throw new e(`timeoutMs must be a positive finite number.`);return{input:a,schema:o,cwd:i.cwd??r?.cwd,model:i.model??r?.model,systemPrompt:i.systemPrompt??r?.systemPrompt,timeoutMs:i.timeoutMs,signal:i.signal}},p=(e,t)=>{if(!e.stats)return;let n=Math.max(0,t.getTime()-e.startedAt.getTime());e.stats={...e.stats,durationMs:e.stats.durationMs??n,apiDurationMs:e.stats.apiDurationMs??n}},
|
|
5
|
-
`);if(e.stopReason===`user`)return{kind:`abort`,message:`Run stopped by user.`};if(e.stopReason===`abort`)return{kind:`abort`,message:`Run aborted.`};if(e.stopReason===`timeout`)return{kind:`abort`,message:`Run timed out after ${e.normalizedRequest.timeoutMs}ms.`};if(e.error)return e.error;if(n&&n.exitCode!==null&&n.exitCode!==0)return{kind:`process`,message:r||`Process exited with code ${n.exitCode}.`};if(t===`failed`&&e.stderrLines.length>0)return{kind:`process`,message:r};if(t===`failed`&&e.normalizedRequest.schema.kind!==`none`&&e.output.value===void 0)return{kind:`parse`,message:`Structured output was requested but no structured output value was produced.`}},
|
|
4
|
+
`),c=e=>t=>{let n=e.safeParse(t);return n.success?n.data:null},l=(e,t,n)=>({id:n.id??i(),runId:e,timestamp:new Date,type:t,...n}),u=e=>e instanceof n.ZodType,d=e=>{if(!(`schema`in e))return{kind:`none`};let{schema:t}=e;return u(t)?{kind:`zod`,jsonSchema:n.toJSONSchema(t),zodSchema:t}:{kind:`json-schema`,jsonSchema:t}},f=(t,n,r,i)=>{let a=typeof i.input==`string`?[{type:`text`,text:i.input}]:i.input;if(a.length===0||a.every(e=>e.type===`text`&&e.text.trim()===``))throw new e(`Run input cannot be empty.`);if(!n.imageInput&&a.some(e=>e.type===`image`))throw new e(`${t} does not support image input.`);let o=d(i);if(!n.structuredOutput&&o.kind!==`none`)throw new e(`${t} does not support structured output.`);if(i.timeoutMs!==void 0&&(!Number.isFinite(i.timeoutMs)||i.timeoutMs<=0))throw new e(`timeoutMs must be a positive finite number.`);return{input:a,schema:o,cwd:i.cwd??r?.cwd,model:i.model??r?.model,systemPrompt:i.systemPrompt??r?.systemPrompt,timeoutMs:i.timeoutMs,signal:i.signal}},p=(e,t)=>({runId:e.runId,requestedSessionId:e.requestedSessionId,sessionId:e.sessionId,schemaRequested:e.normalizedRequest.schema.kind!==`none`,toolCalls:e.toolCalls,...t}),m=(e,t)=>{if(!e.stats)return;let n=Math.max(0,t.getTime()-e.startedAt.getTime());e.stats={...e.stats,durationMs:e.stats.durationMs??n,apiDurationMs:e.stats.apiDurationMs??n}},h=(e,t)=>{let n=e.normalizedRequest.schema;if(n.kind!==`none`){if(n.kind===`zod`){let r=n.zodSchema.safeParse(t);if(!r.success){e.status=`failed`,e.error={kind:`parse`,message:r.error.message};return}e.output.value=r.data;return}e.output.value=t}},g=(e,t)=>{if(e.events.push(t),t.type!==`message`||t.role!==`assistant`)return;let n=t.text??o(t.content);n&&e.assistantTexts.push(n)},_=(e,t,n={})=>{t.sessionId&&(e.sessionId=t.sessionId,n.onSessionId?.(t.sessionId));for(let n of t.toolCalls??[])e.toolCalls.set(n.toolCallId,{toolName:n.toolName,input:n.input});if(!t.state)return;let r=t.state;r.output&&(`text`in r.output&&(e.output.text=r.output.text),`value`in r.output&&h(e,r.output.value)),`stats`in r&&(e.stats=r.stats),`status`in r&&(e.status=r.status),`error`in r&&(e.error=r.error)},v=e=>e.events.some(e=>e.type===`message`||e.type===`reasoning`||e.type===`tool-call`||e.type===`tool-result`),y=e=>{let t=e.normalizedRequest.schema.kind!==`none`&&e.output.value===void 0;return e.stopReason===`user`||e.stopReason===`abort`||e.stopReason===`timeout`?`cancelled`:e.error?e.error.kind===`abort`?`cancelled`:`failed`:e.status?e.status===`completed`&&t?`failed`:e.status:e.processResult&&e.processResult.exitCode!==null&&e.processResult.exitCode!==0||!v(e)&&e.stderrLines.length>0||t?`failed`:`completed`},b=(e,t)=>{let n=e.processResult,r=e.stderrLines.join(`
|
|
5
|
+
`);if(e.stopReason===`user`)return{kind:`abort`,message:`Run stopped by user.`};if(e.stopReason===`abort`)return{kind:`abort`,message:`Run aborted.`};if(e.stopReason===`timeout`)return{kind:`abort`,message:`Run timed out after ${e.normalizedRequest.timeoutMs}ms.`};if(e.error)return e.error;if(n&&n.exitCode!==null&&n.exitCode!==0)return{kind:`process`,message:r||`Process exited with code ${n.exitCode}.`};if(t===`failed`&&e.stderrLines.length>0)return{kind:`process`,message:r};if(t===`failed`&&e.normalizedRequest.schema.kind!==`none`&&e.output.value===void 0)return{kind:`parse`,message:`Structured output was requested but no structured output value was produced.`}},x=(e,t,n,r,i)=>{let a=t.stderrLines.join(`
|
|
6
6
|
`),o={type:e,runId:t.runId,sessionId:t.sessionId,text:t.output.text??t.assistantTexts.join(`
|
|
7
7
|
|
|
8
|
-
`),events:[...t.events],stats:t.stats,timing:{startedAt:t.startedAt,endedAt:n,durationMs:n.getTime()-t.startedAt.getTime()},process:t.processResult?{exitCode:t.processResult.exitCode,signal:t.processResult.signal,stderr:a}:void 0};switch(r){case`completed`:return t.normalizedRequest.schema.kind===`none`?{...o,status:r,error:void 0,cancelReason:void 0}:{...o,status:r,output:t.output.value,error:void 0,cancelReason:void 0};case`failed`:return{...o,status:r,output:void 0,error:i??{kind:`process`,message:`Unknown error.`},cancelReason:void 0};case`cancelled`:return{...o,status:r,output:void 0,error:i??{kind:`abort`,message:`Run cancelled.`},cancelReason:t.stopReason??`user`};default:throw Error(`Unsupported run status.`)}},
|
|
8
|
+
`),events:[...t.events],stats:t.stats,timing:{startedAt:t.startedAt,endedAt:n,durationMs:n.getTime()-t.startedAt.getTime()},process:t.processResult?{exitCode:t.processResult.exitCode,signal:t.processResult.signal,stderr:a}:void 0};switch(r){case`completed`:return t.normalizedRequest.schema.kind===`none`?{...o,status:r,error:void 0,cancelReason:void 0}:{...o,status:r,output:t.output.value,error:void 0,cancelReason:void 0};case`failed`:return{...o,status:r,output:void 0,error:i??{kind:`process`,message:`Unknown error.`},cancelReason:void 0};case`cancelled`:return{...o,status:r,output:void 0,error:i??{kind:`abort`,message:`Run cancelled.`},cancelReason:t.stopReason??`user`};default:throw Error(`Unsupported run status.`)}},S=()=>{let e=new Date;return{runCount:0,messagesReceived:0,toolCalls:0,errors:0,startedAt:e,lastActivityAt:e}};var C=class{type;capabilities;currentRun;eventHandlers=[];permissionHandler;_sessionId;_metrics;constructor(e){this.type=e.type,this.capabilities=e.capabilities,this._sessionId=e.sessionId,this._metrics=S(),e.onEvent&&this.onEvent(e.onEvent)}onValidateRun(e,t){}async onDispose(){}onHandlerError(e){}get sessionId(){return this._sessionId}get metrics(){return this._metrics}get isRunning(){return this.currentRun?.running??!1}onEvent(e){return this.eventHandlers.push(e),()=>{let t=this.eventHandlers.indexOf(e);t>=0&&this.eventHandlers.splice(t,1)}}onPermissionRequest(e){return this.permissionHandler=e,()=>{this.permissionHandler===e&&(this.permissionHandler=void 0)}}getPermissionHandler(){return this.permissionHandler}async run(t){if(this.currentRun?.running)throw new e(`This agent is already running. Wait for it to finish first.`);let n=f(this.type,this.capabilities,this.runRequestDefaults,t);this.onValidateRun(t,n);let i={runId:r(),startedAt:new Date,requestedSessionId:this._sessionId,sessionId:this._sessionId,normalizedRequest:n,events:[],stderrLines:[],assistantTexts:[],toolCalls:new Map,output:{}},a={context:i,running:!0,promise:new Promise(()=>{})};this._metrics.runCount++;let o=Promise.resolve().then(()=>this.executeRunCore(i,t)).finally(()=>{a.running=!1});return a.promise=o,this.currentRun=a,o}async runOrThrow(e){let n=await this.run(e);if(n.status!==`completed`)throw new t(n);return n}async stop(){let e=this.currentRun?.context;if(!(!e||!this.currentRun?.running)){this.requestStop(e,`user`);try{return await this.currentRun.promise}catch{return}}}reset(){if(this.currentRun?.running)throw new e(`Cannot reset agent state while a run is active. Call stop() and wait() first.`);this.currentRun=void 0,this._sessionId=void 0,this._metrics=S()}wait(){if(!this.currentRun)throw new e(`There is no run to wait for.`);return this.currentRun.promise}async dispose(){if(this.currentRun?.running){this.requestStop(this.currentRun.context,`user`);try{await this.currentRun.promise}catch{}}await this.onDispose()}async[Symbol.asyncDispose](){await this.dispose()}applyBatch(e,t){_(e,t,{onSessionId:e=>{this.setSessionId(e)}}),e.sessionId&&this.emitSessionStart(e);for(let n of t.events)this.emit(e,n)}setupRunLifecycle(e){let t=!1,n=()=>{t||this.requestStop(e,`abort`)},r=e.normalizedRequest.timeoutMs===void 0?void 0:setTimeout(()=>{t||this.requestStop(e,`timeout`)},e.normalizedRequest.timeoutMs);r?.unref?.(),e.normalizedRequest.signal?.addEventListener(`abort`,n,{once:!0});let i=e.normalizedRequest.signal?.aborted===!0;return i&&this.requestStop(e,`abort`),{abortedBeforeStart:i,cleanup:()=>{t=!0,r&&clearTimeout(r),e.normalizedRequest.signal?.removeEventListener(`abort`,n)}}}emitSessionStart(e){e.sessionStarted||(e.sessionStarted=!0,this.emit(e,l(e.runId,`session-start`,{requestedSessionId:e.requestedSessionId,sessionId:e.sessionId,resumed:e.requestedSessionId!==void 0})))}emit(e,t){g(e,t),this.updateMetrics(t);for(let e of this.eventHandlers)try{e(t)}catch(e){this.onHandlerError(e)}}requestStop(e,t){e.stopReason||(e.stopReason=t,this.onStopRequested(e))}buildResult(e,t){m(e,t);let n=y(e),r=b(e,n);return e.sessionStarted&&this.emit(e,l(e.runId,`session-end`,{sessionId:e.sessionId,status:n,error:r?.message})),x(this.type,e,t,n,r)}setSessionId(e){this._sessionId=e}updateMetrics(e){switch(this._metrics.lastActivityAt=e.timestamp,e.type){case`message`:e.role===`assistant`&&this._metrics.messagesReceived++;break;case`tool-call`:this._metrics.toolCalls++;break;case`session-end`:e.status===`failed`&&this._metrics.errors++;break;default:break}}};const w=new Set([`ENOENT`,`ERR_MODULE_NOT_FOUND`]),T=e=>`code`in e,E=(e,t)=>{let n=t??(e instanceof Error?e.message:String(e));if(e instanceof Error){if(e.name===`AbortError`)return{kind:`abort`,message:n};if(T(e)&&w.has(String(e.code)))return{kind:`spawn`,message:n};if(e instanceof SyntaxError)return{kind:`parse`,message:n}}return{kind:`provider`,message:n}};export{v as a,s as c,p as i,a as l,C as n,l as o,_ as r,c as s,E as t};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { $ as WorkdirDiffStats, A as E2BCreateConfig, B as ContainerExecution, C as NerdctlProviderBase, D as E2BContainer, E as E2BConnectionConfig, F as DockerContainerBase, G as ContainerStatus, H as ContainerIdentity, I as DockerContainerConfig, J as ExecResult, K as ContainerType, L as DockerProviderConfig, M as DockerBuildBase, N as DockerBuildConfig, O as E2BContainerBase, P as DockerContainer, Q as WorkdirDiff, R as ContainerBase, S as NerdctlContainerConfig, T as E2BConnectConfig, U as ContainerLifecycle, V as ContainerFileSystem, W as ContainerObservability, X as VolumeMount, Y as PortMapping, Z as WorkdirChangeKind, _ as PodmanProviderConfig, a as ContainerDiffError, b as NerdctlContainer, c as ContainerExecError, d as MountValidationError, et as WorkdirFileChange, f as PodmanBuildBase, g as PodmanContainerConfig, h as PodmanContainerBase, i as ContainerCreateError, j as E2BProviderConfig, k as E2BContainerConfig, l as ContainerNotRunningError, m as PodmanContainer, n as ContainerConfig, nt as WorkdirSnapshotOptions, o as ContainerDisposedError, p as PodmanBuildConfig, q as ExecOptions, r as createContainer, s as ContainerError, t as Container, tt as WorkdirSnapshot, u as ContainerStartError, v as NerdctlBuildBase, w as NerdctlProviderConfig, x as NerdctlContainerBase, y as NerdctlBuildConfig, z as ContainerConfigBase } from "../index-
|
|
2
|
-
export { Container, ContainerBase, ContainerConfig, ContainerConfigBase, ContainerCreateError, ContainerDiffError, ContainerDisposedError, ContainerError, ContainerExecError, ContainerExecution, ContainerFileSystem, ContainerIdentity, ContainerLifecycle, ContainerNotRunningError, ContainerObservability, ContainerStartError, ContainerStatus, ContainerType, DockerBuildBase, DockerBuildConfig, DockerContainer, DockerContainerBase, DockerContainerConfig, DockerProviderConfig, E2BConnectConfig, E2BConnectionConfig, E2BContainer, E2BContainerBase, E2BContainerConfig, E2BCreateConfig, E2BProviderConfig, ExecOptions, ExecResult, MountValidationError, NerdctlBuildBase, NerdctlBuildConfig, NerdctlContainer, NerdctlContainerBase, NerdctlContainerConfig, NerdctlProviderBase, NerdctlProviderConfig, PodmanBuildBase, PodmanBuildConfig, PodmanContainer, PodmanContainerBase, PodmanContainerConfig, PodmanProviderConfig, PortMapping, VolumeMount, WorkdirChangeKind, WorkdirDiff, WorkdirDiffStats, WorkdirFileChange, WorkdirSnapshot, WorkdirSnapshotOptions, createContainer };
|
|
1
|
+
import { $ as WorkdirDiffStats, A as E2BCreateConfig, B as ContainerExecution, C as NerdctlProviderBase, D as E2BContainer, E as E2BConnectionConfig, F as DockerContainerBase, G as ContainerStatus, H as ContainerIdentity, I as DockerContainerConfig, J as ExecResult, K as ContainerType, L as DockerProviderConfig, M as DockerBuildBase, N as DockerBuildConfig, O as E2BContainerBase, P as DockerContainer, Q as WorkdirDiff, R as ContainerBase, S as NerdctlContainerConfig, T as E2BConnectConfig, U as ContainerLifecycle, V as ContainerFileSystem, W as ContainerObservability, X as VolumeMount, Y as PortMapping, Z as WorkdirChangeKind, _ as PodmanProviderConfig, a as ContainerDiffError, b as NerdctlContainer, c as ContainerExecError, d as MountValidationError, et as WorkdirFileChange, f as PodmanBuildBase, g as PodmanContainerConfig, h as PodmanContainerBase, i as ContainerCreateError, j as E2BProviderConfig, k as E2BContainerConfig, l as ContainerNotRunningError, m as PodmanContainer, n as ContainerConfig, nt as WorkdirSnapshotOptions, o as ContainerDisposedError, p as PodmanBuildConfig, q as ExecOptions, r as createContainer, s as ContainerError, t as Container, tt as WorkdirSnapshot, u as ContainerStartError, v as NerdctlBuildBase, w as NerdctlProviderConfig, x as NerdctlContainerBase, y as NerdctlBuildConfig, z as ContainerConfigBase } from "../index-C9XD71QR.mjs";
|
|
2
|
+
export { Container, type ContainerBase, ContainerConfig, type ContainerConfigBase, ContainerCreateError, ContainerDiffError, ContainerDisposedError, ContainerError, ContainerExecError, type ContainerExecution, type ContainerFileSystem, type ContainerIdentity, type ContainerLifecycle, ContainerNotRunningError, type ContainerObservability, ContainerStartError, type ContainerStatus, type ContainerType, type DockerBuildBase, type DockerBuildConfig, type DockerContainer, type DockerContainerBase, type DockerContainerConfig, type DockerProviderConfig, type E2BConnectConfig, type E2BConnectionConfig, type E2BContainer, type E2BContainerBase, type E2BContainerConfig, type E2BCreateConfig, type E2BProviderConfig, type ExecOptions, type ExecResult, MountValidationError, type NerdctlBuildBase, type NerdctlBuildConfig, type NerdctlContainer, type NerdctlContainerBase, type NerdctlContainerConfig, type NerdctlProviderBase, type NerdctlProviderConfig, type PodmanBuildBase, type PodmanBuildConfig, type PodmanContainer, type PodmanContainerBase, type PodmanContainerConfig, type PodmanProviderConfig, type PortMapping, type VolumeMount, type WorkdirChangeKind, type WorkdirDiff, type WorkdirDiffStats, type WorkdirFileChange, type WorkdirSnapshot, type WorkdirSnapshotOptions, createContainer };
|
package/dist/container/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as e,c as t,i as n,
|
|
1
|
+
import{a as e,c as t,i as n,l as r,n as i,o as a,r as o,s,t as c}from"../container-DBXaA-Iv.mjs";export{i as ContainerCreateError,o as ContainerDiffError,n as ContainerDisposedError,e as ContainerError,a as ContainerExecError,s as ContainerNotRunningError,t as ContainerStartError,r as MountValidationError,c as createContainer};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e,t}from"./oci-
|
|
1
|
+
import{n as e,t}from"./oci-DmEG3Ia3.mjs";const n=async n=>{let r={binary:n.binary??`docker`},i=await e(r,n);return t(`docker`,{commandContext:r,containerName:n.name,workdir:n.workdir,user:n.user,network:n.network,platform:n.platform,env:n.env,ports:n.ports,mounts:n.mounts,mountCwd:n.mountCwd,extraArgs:n.extraArgs,image:i,builtImage:n.build!==void 0&&!n.build.tag},n)};export{n as createDockerContainer};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=class extends Error{constructor(e){super(e),this.name=`ContainerError`}},t=class extends e{constructor(e){super(e),this.name=`ContainerCreateError`}},n=class extends e{constructor(e){super(e),this.name=`MountValidationError`}},r=class extends e{constructor(e){super(e),this.name=`ContainerStartError`}},i=class extends e{constructor(e){super(e),this.name=`ContainerExecError`}},a=class extends e{constructor(e=`Container is not running.`){super(e),this.name=`ContainerNotRunningError`}},o=class extends e{constructor(e=`Container has been disposed.`){super(e),this.name=`ContainerDisposedError`}},s=class extends e{constructor(e){super(e),this.name=`ContainerDiffError`}};async function c(e){switch(e.type){case`docker`:{let{createDockerContainer:t}=await import(`./container-46QA1d3v.mjs`);return t(e)}case`e2b`:try{let{createE2BContainer:t}=await import(`./container-DRj7xq5x.mjs`);return await t(e)}catch(e){throw e instanceof Error&&e.message.includes(`e2b`)&&(e.code===`ERR_MODULE_NOT_FOUND`||e.code===`MODULE_NOT_FOUND`)?new t(`Container type "e2b" requires the optional peer dependency "e2b". Install it to use this provider.`):e}case`nerdctl`:{let{createNerdctlContainer:t}=await import(`./container-gJ8B-Z5B.mjs`);return t(e)}case`podman`:{let{createPodmanContainer:t}=await import(`./container-Dg68bfte.mjs`);return t(e)}default:throw new t(`Unsupported container type.`)}}export{e as a,r as c,o as i,n as l,t as n,i as o,s as r,a as s,c as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as e}from"./util-DcPzh_0u.mjs";import{c as t,i as n,n as r,r as i,s as a}from"./container-DBXaA-Iv.mjs";import{t as o}from"./shell-DvWFuFKb.mjs";import{n as s}from"./diff-BJWXJsjx.mjs";import{basename as c,dirname as l,join as u,posix as d}from"node:path";import{mkdir as f,readFile as p,readdir as m,stat as h,writeFile as g}from"node:fs/promises";import{CommandExitError as _,FileType as v,Sandbox as y}from"e2b";const b=(e,t)=>[e,...t].map(o).join(` `),x=e=>e.user,S=(e,t)=>{let n={...e.env,...t};return Object.keys(n).length>0?n:void 0},C=(e,t)=>t??e.workdir,w=new TextEncoder,T=e=>e instanceof Error?e:Error(String(e)),E=e=>typeof e==`string`?e:`SIGKILL`,D=(e,t)=>{let n=e?.stdio?.[t];return n===`ignore`||n===`inherit`||n===`pipe`?n:n===void 0?`pipe`:`ignore`},O=()=>{let e=[],t=[],n=!1,r,i=()=>{for(;t.length>0&&e.length>0;)t.shift().resolve({done:!1,value:e.shift()});if(r){for(;t.length>0;)t.shift().reject(r);return}if(n)for(;t.length>0;)t.shift().resolve({done:!0,value:void 0})};return{iterable:{async*[Symbol.asyncIterator](){for(;;){if(e.length>0){yield e.shift();continue}if(r)throw T(r);if(n)return;let i=await new Promise((e,n)=>{t.push({resolve:e,reject:n})});if(i.done)return;yield i.value}}},push(t){t.length===0||n||r||(e.push(w.encode(t)),i())},end(){n||r||(n=!0,i())},fail(e){n||r||(r=e,i())}}},k=(e,t)=>({spawn:(n,r,i={})=>{let a=D(i,0),o=D(i,1),s=D(i,2),c=o===`pipe`?O():void 0,l=s===`pipe`?O():void 0,u=null,d={background:!0,stdin:a===`pipe`,cwd:C(t,i.cwd),envs:S(t,i.env),user:x(t),requestTimeoutMs:t.requestTimeoutMs,onStdout:e=>{if(o===`inherit`){process.stdout.write(e);return}c?.push(e)},onStderr:e=>{if(s===`inherit`){process.stderr.write(e);return}l?.push(e)}},f=e.commands.run(b(n,r),d);return f.catch(e=>{c?.fail(e),l?.fail(e)}),{stdout:c?.iterable??null,stderr:l?.iterable??null,stdin:a===`pipe`?{write:n=>{f.then(r=>{e.commands.sendStdin(r.pid,n,{requestTimeoutMs:t.requestTimeoutMs})}).catch(()=>{})},end:()=>{f.then(n=>{e.commands.closeStdin(n.pid,{requestTimeoutMs:t.requestTimeoutMs})}).catch(()=>{})}}:null,kill:e=>{u=E(e),f.then(e=>e.kill()).catch(()=>{})},wait:async()=>{try{let e=await(await f).wait();return c?.end(),l?.end(),u?{exitCode:null,signal:u}:{exitCode:e.exitCode,signal:null}}catch(e){if(c?.end(),l?.end(),e instanceof _)return u?{exitCode:null,signal:u}:{exitCode:e.exitCode,signal:null};throw e}}}}}),A=e=>({apiKey:e.apiKey,accessToken:e.accessToken,domain:e.domain,requestTimeoutMs:e.requestTimeoutMs,headers:e.headers}),j=e=>`sandboxId`in e&&typeof e.sandboxId==`string`,M=e=>{let t=A(e);return j(e)?t:{...t,envs:e.env,timeoutMs:e.timeoutMs,metadata:e.metadata,secure:e.secure,allowInternetAccess:e.allowInternetAccess,network:e.network,lifecycle:e.lifecycle}},N=async(e,t)=>{await e.files.makeDir(t.workdir,{user:x(t)})},P=e=>e instanceof Error&&e.name===`AbortError`,F=e=>Uint8Array.from(e).buffer,I=e=>{let t=e.endsWith(`/`)&&e!==`/`?e.slice(0,-1):e;return d.basename(t)},L=async e=>{try{return await h(e)}catch(e){if(e instanceof Error&&`code`in e&&e.code===`ENOENT`)return;throw e}},R=async(e,t,n)=>{if(await e.files.exists(t,{user:n}))return e.files.getInfo(t,{user:n})},z=async(e,t,n,r)=>(await R(e,n,r))?.type===v.DIR?d.join(n,c(t)):n,B=async(e,t)=>(await L(t))?.isDirectory()?u(t,I(e)):t,V=async(e,t,n,r)=>{let i=await h(t);if(i.isDirectory()){await e.files.makeDir(n,{user:r});let i=await m(t);await Promise.all(i.map(i=>V(e,u(t,i),d.join(n,i),r)));return}if(!i.isFile())throw Error(`Unsupported local filesystem entry at ${t}.`);let a=await p(t);await e.files.write(n,F(a),{user:r})},H=async(e,t,n,r)=>{if((await e.files.getInfo(t,{user:r})).type===v.DIR){await f(n,{recursive:!0});let i=await e.files.list(t,{user:r});await Promise.all(i.map(t=>H(e,t.path,u(n,t.name),r)));return}let i=await e.files.read(t,{format:`bytes`,user:r});await f(l(n),{recursive:!0}),await g(n,i)},U=async e=>{if(j(e))return y.connect(e.sandboxId,A(e));let t=M(e);return e.template?y.create(e.template,t):y.create(t)},W=async(e,t)=>e.connect(A(t)),G=async(e,t)=>{let n=t.signal;if(n?.aborted){let e=n.reason;throw e instanceof Error?e:new DOMException(`The operation was aborted.`,`AbortError`)}let r=!1,i=()=>{r=!0,e.kill()};n?.addEventListener(`abort`,i,{once:!0});try{let t=await e.wait();if(r)throw new DOMException(`The operation was aborted.`,`AbortError`);return{exitCode:t.exitCode,stdout:t.stdout,stderr:t.stderr}}catch(e){if(r||P(e))throw new DOMException(`The operation was aborted.`,`AbortError`);if(e instanceof _)return{exitCode:e.exitCode,stdout:e.stdout,stderr:e.stderr};throw e}finally{n?.removeEventListener(`abort`,i)}},K=async o=>{let c;try{c=await U(o),await N(c,o)}catch(t){throw new r(`E2B create failed: ${e(t)}`)}let l=o.name??c.sandboxId,d=`running`,p=k(c,o),m={},h=()=>{if(d===`disposed`)throw new n},g=()=>{if(h(),d!==`running`)throw new a},_=s({owner:m,workdir:o.workdir,materialize:async(e,t)=>{g();let n=x(o),r=await R(c,e,n);if(!r)throw new i(`Target path does not exist: ${e}`);if(r.type!==v.DIR)throw new i(`Target path is not a directory: ${e}`);await f(t,{recursive:!0});for(let r of await c.files.list(e,{user:n}))await H(c,r.path,u(t,r.name),n)}}),y={get type(){return`e2b`},get id(){return c.sandboxId},get name(){return l},get config(){return o},get status(){return d},get workdir(){return o.workdir},get spawner(){return p},async start(){if(h(),d!==`running`)try{c=await W(c,o),await N(c,o),p=k(c,o),d=`running`}catch(n){throw new t(`E2B start failed: ${e(n)}`)}},async stop(){h(),d===`running`&&(await c.pause({requestTimeoutMs:o.requestTimeoutMs}),d=`stopped`)},async dispose(){if(d!==`disposed`){try{await c.kill({requestTimeoutMs:o.requestTimeoutMs})}catch{}await _.disposeSnapshots().catch(()=>{}),d=`disposed`}},async exec(e,t,n={}){g();let r={background:!0,cwd:C(o,n.cwd),envs:S(o,n.env),user:x(o),timeoutMs:n.timeoutMs,requestTimeoutMs:o.requestTimeoutMs};return G(await c.commands.run(b(e,t),r),n)},async copyTo(e,t){g();let n=await z(c,e,t,x(o));await V(c,e,n,x(o))},async copyFrom(e,t){g();let n=await B(e,t);await H(c,e,n,x(o))},async writeFile(e,t){g(),await c.files.write(e,typeof t==`string`?t:F(t),{user:x(o)})},async readFile(e){return g(),c.files.read(e,{format:`text`,user:x(o)})},async fileExists(e){return g(),c.files.exists(e,{user:x(o)})},async mkdir(e){g(),await c.files.makeDir(e,{user:x(o)})},async execShell(e,t={}){return y.exec(`sh`,[`-c`,e],t)},async logs(){return``},async syncStatus(){return d},async snapshotWorkdir(e={}){return _.snapshotWorkdir(e)},async diffWorkdir(e){return _.diffWorkdir(e)},async releaseWorkdirSnapshot(e){return _.releaseWorkdirSnapshot(e)},getHost(e){return g(),c.getHost(e)},[Symbol.asyncDispose](){return y.dispose()}};return y};export{K as createE2BContainer};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e,t}from"./oci-
|
|
1
|
+
import{n as e,t}from"./oci-DmEG3Ia3.mjs";const n=async n=>{let r={binary:n.binary??`podman`},i=await e(r,n);return t(`podman`,{commandContext:r,containerName:n.name,workdir:n.workdir,user:n.user,network:n.network,platform:n.platform,env:n.env,ports:n.ports,mounts:n.mounts,mountCwd:n.mountCwd,extraArgs:n.extraArgs,image:i,builtImage:n.build!==void 0&&!n.build.tag},n)};export{n as createPodmanContainer};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e,t}from"./oci-
|
|
1
|
+
import{n as e,t}from"./oci-DmEG3Ia3.mjs";const n=e=>{let t={};return e.address&&(t.CONTAINERD_ADDRESS=e.address),e.namespace&&(t.CONTAINERD_NAMESPACE=e.namespace),e.buildkitHost&&(t.BUILDKIT_HOST=e.buildkitHost),Object.keys(t).length>0?t:void 0},r=e=>{let t=[];return e.namespace&&t.push(`--namespace`,e.namespace),e.address&&t.push(`--address`,e.address),e.snapshotter&&t.push(`--snapshotter`,e.snapshotter),e.args&&t.push(...e.args),t.length>0?t:void 0},i=e=>({binary:e.binary??`nerdctl`,baseArgs:r(e),env:n(e)}),a=async n=>{let r=i(n),a=await e(r,n);return t(`nerdctl`,{commandContext:r,containerName:n.name,workdir:n.workdir,user:n.user,network:n.network,platform:n.platform,env:n.env,ports:n.ports,mounts:n.mounts,mountCwd:n.mountCwd,extraArgs:n.extraArgs,image:a,builtImage:n.build!==void 0&&!n.build.tag},n)};export{a as createNerdctlContainer};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as e}from"./util-DcPzh_0u.mjs";import{i as t,r as n,s as r}from"./container-DBXaA-Iv.mjs";import{execFile as i}from"node:child_process";import{dirname as a,isAbsolute as o,join as s,posix as c,relative as l,sep as u}from"node:path";import{promisify as d}from"node:util";import{createReadStream as f}from"node:fs";import{tmpdir as p}from"node:os";import{copyFile as m,lstat as h,mkdir as g,mkdtemp as _,readdir as v,readlink as y,rm as b,stat as x,symlink as S}from"node:fs/promises";import{createHash as C}from"node:crypto";import{pipeline as w}from"node:stream/promises";const T=e=>e instanceof Error&&`code`in e&&(`stdout`in e||`stderr`in e),E=d(i),D=e=>e!==`..`&&!e.startsWith(`..${u}`)&&!o(e),O=(e,t)=>{let n=l(e,t);if(D(n))return n.split(u).join(c.sep)},k=(e,t,r)=>{let i=O(t,e);if(i!==void 0)return i;let a=O(r,e);if(a!==void 0)return a;throw new n(`Git diff produced a path outside the materialized trees: ${e}`)},A=e=>e.sort((e,t)=>e.path===t.path?(e.previousPath??``).localeCompare(t.previousPath??``):e.path.localeCompare(t.path)),j=async e=>{let t=await v(e,{withFileTypes:!0});for(let n of t){let t=s(e,n.name);if(n.name===`.git`){await b(t,{recursive:!0,force:!0});continue}n.isDirectory()&&await j(t)}},M=()=>_(s(p(),`cw-workdir-diff-`)),N=async e=>{e&&await b(e,{recursive:!0,force:!0}).catch(()=>{})},P=(e,t)=>{let n={cwd:e.cwd,createdAt:new Date};return t.set(n,e),n},F=(e,t,r)=>{if(typeof t!=`object`||!t)throw new n(`Invalid workdir snapshot.`);let i=r.get(t);if(!i)throw new n(`Invalid workdir snapshot.`);if(i.owner!==e)throw new n(`Workdir snapshot was created by a different container instance.`);return i},I=(e,t)=>{if(!t.has(e))throw new n(`Workdir snapshot has been released.`)},L=e=>C(`sha256`).update(e).digest(`hex`),R=e=>Buffer.isBuffer(e)?e:Buffer.from(e,`utf8`),z=async e=>{let t=C(`sha256`);return await w(f(e),t),t.digest(`hex`)},B=async(e,t,r)=>{let i=`${e}:${t}`;if(r.has(i))return r.get(i);let a=s(e,...t.split(c.sep));try{let e=await h(a),t,o;if(e.isSymbolicLink()){let e=Buffer.from(await y(a));t=L(e),o=e.byteLength}else if(e.isFile())t=await z(a),o=e.size;else throw new n(`Unsupported filesystem entry in diff metadata: ${a}`);let s={hash:t,size:o};return r.set(i,s),s}catch(e){if(e instanceof Error&&`code`in e&&e.code===`ENOENT`){r.set(i,void 0);return}throw e}},V=(e,t,r)=>{if(e.byteLength===0)return[];let i=e.toString(`utf8`).split(`\0`);i[i.length-1]===``&&i.pop();let a=[];for(let e=0;e<i.length;){let o=i[e++];if(!o)continue;if(o.startsWith(`R`)){let o=i[e++],s=i[e++];if(!o||!s)throw new n(`Failed to parse git rename entry.`);a.push({kind:`renamed`,previousPath:k(o,t,r),path:k(s,t,r)});continue}let s=i[e++];if(!s)throw new n(`Failed to parse git diff entry.`);switch(o){case`A`:a.push({kind:`added`,path:k(s,t,r)});break;case`D`:a.push({kind:`deleted`,path:k(s,t,r)});break;case`M`:a.push({kind:`modified`,path:k(s,t,r)});break;case`T`:a.push({kind:`modified`,path:k(s,t,r)});break;default:throw new n(`Unsupported git diff change kind: ${o}`)}}return a},H=async(t,r)=>{try{return V(R((await E(`git`,[`diff`,`--no-index`,`-z`,`--name-status`,`-M`,`--find-renames=100%`,t,r],{cwd:p(),encoding:`buffer`,maxBuffer:50*1024*1024})).stdout),t,r)}catch(i){if(!T(i))throw new n(`Failed to run git diff: ${e(i)}`);let a=i.code??1,o=Buffer.isBuffer(i.stdout)?i.stdout:Buffer.from(String(i.stdout??``),`utf8`),s=Buffer.isBuffer(i.stderr)?i.stderr:Buffer.from(String(i.stderr??``),`utf8`);if(a===0||a===1)return V(o,t,r);throw new n(`Failed to run git diff: ${s.toString(`utf8`).trim()||o.toString(`utf8`).trim()||`exit code ${a}`}`)}},U=async(e,t,n)=>{let r=new Map;return A(await Promise.all(e.map(async e=>{let i;i=e.kind===`added`?void 0:e.kind===`renamed`?e.previousPath:e.path;let a=e.kind===`deleted`?void 0:e.path,[o,s]=await Promise.all([i===void 0?void 0:B(t,i,r),a===void 0?void 0:B(n,a,r)]);return{path:e.path,previousPath:e.previousPath,kind:e.kind,beforeHash:o?.hash,afterHash:s?.hash,beforeSize:o?.size,afterSize:s?.size}})))},W=e=>{let t=new Set;for(let n of e)t.add(n.path),n.kind===`renamed`&&n.previousPath&&t.add(n.previousPath);return[...t].sort((e,t)=>e.localeCompare(t))},G=(i,a)=>{throw a instanceof n||a instanceof t||a instanceof r?a:new n(`${i}: ${e(a)}`)},K=async(e,t)=>{if(!(await x(e)).isDirectory())throw new n(`Target path is not a directory: ${e}`);await g(t,{recursive:!0});let r=await v(e,{withFileTypes:!0});await Promise.all(r.filter(e=>e.name!==`.git`).map(async r=>{let i=s(e,r.name),o=s(t,r.name);if(r.isDirectory()){await K(i,o);return}if(r.isSymbolicLink()){await g(a(o),{recursive:!0}),await S(await y(i),o);return}if(r.isFile()){await g(a(o),{recursive:!0}),await m(i,o);return}throw new n(`Unsupported filesystem entry in workdir diff: ${i}`)}))},q=e=>{let t=new Set,n=new WeakMap,r=async(r={})=>{let i=r.cwd??e.workdir,a;try{a=await M(),await e.materialize(i,a),await j(a);let r={owner:e.owner,tempDir:a,cwd:i,inFlightDiffs:0,released:!1};return t.add(r),a=void 0,P(r,n)}catch(e){return await N(a),G(`Failed to materialize workdir snapshot`,e)}},i=async r=>{let i=Date.now(),a=F(e.owner,r,n);I(a,t),a.inFlightDiffs++;let o;try{o=await M(),await e.materialize(a.cwd,o),await j(o);let t=await U(await H(a.tempDir,o),a.tempDir,o),n=W(t);return{cwd:a.cwd,changedFiles:n,fileChanges:t,stats:{durationMs:Date.now()-i,filesCompared:n.length}}}catch(e){return G(`Failed to diff workdir snapshot`,e)}finally{a.inFlightDiffs--,a.inFlightDiffs===0&&(a.resolveIdle?.(),a.resolveIdle=void 0),await N(o)}},a=e=>{let n=e;return n.releasePromise?n.releasePromise:(n.released=!0,t.delete(n),n.releasePromise=(async()=>{n.inFlightDiffs>0&&await new Promise(e=>{n.resolveIdle=e}),await N(n.tempDir)})(),n.releasePromise)};return{snapshotWorkdir:r,diffWorkdir:i,releaseWorkdirSnapshot:async t=>{await a(F(e.owner,t,n))},disposeSnapshots:async()=>{await Promise.all(Array.from(t).map(a))}}};export{q as n,T as r,K as t};
|
|
@@ -1,17 +1,32 @@
|
|
|
1
1
|
import { ZodType, z } from "zod/v4";
|
|
2
2
|
|
|
3
3
|
//#region src/schemas/agent.d.ts
|
|
4
|
+
/** Plain text content block in a {@link ContentPart} array. */
|
|
4
5
|
declare const textContentPartSchema: z.ZodObject<{
|
|
5
6
|
type: z.ZodLiteral<"text">;
|
|
6
7
|
text: z.ZodString;
|
|
7
8
|
}, z.core.$strip>;
|
|
9
|
+
/** Plain text content block in a {@link ContentPart} array. */
|
|
8
10
|
type TextContentPart = z.infer<typeof textContentPartSchema>;
|
|
11
|
+
/**
|
|
12
|
+
* Image content block. `path` is a filesystem path readable by the adapter
|
|
13
|
+
* (local images for `local_image`-style SDKs); `mediaType` defaults to being
|
|
14
|
+
* inferred from the file extension.
|
|
15
|
+
*/
|
|
9
16
|
declare const imageContentPartSchema: z.ZodObject<{
|
|
10
17
|
type: z.ZodLiteral<"image">;
|
|
11
18
|
path: z.ZodString;
|
|
12
19
|
mediaType: z.ZodOptional<z.ZodString>;
|
|
13
20
|
}, z.core.$strip>;
|
|
21
|
+
/**
|
|
22
|
+
* Image content block. `path` is a filesystem path readable by the adapter;
|
|
23
|
+
* `mediaType` defaults to being inferred from the file extension.
|
|
24
|
+
*/
|
|
14
25
|
type ImageContentPart = z.infer<typeof imageContentPartSchema>;
|
|
26
|
+
/**
|
|
27
|
+
* Multimodal content union. Pass an array of these as `RunRequest.input` to
|
|
28
|
+
* include images alongside text; pass a plain string for text-only input.
|
|
29
|
+
*/
|
|
15
30
|
declare const contentPartSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
16
31
|
type: z.ZodLiteral<"text">;
|
|
17
32
|
text: z.ZodString;
|
|
@@ -20,7 +35,17 @@ declare const contentPartSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
20
35
|
path: z.ZodString;
|
|
21
36
|
mediaType: z.ZodOptional<z.ZodString>;
|
|
22
37
|
}, z.core.$strip>], "type">;
|
|
38
|
+
/**
|
|
39
|
+
* Multimodal content union — the discriminated shape of `RunRequest.input`
|
|
40
|
+
* when passed as an array. Pass a plain string for text-only input; pass
|
|
41
|
+
* `ContentPart[]` to include images alongside text. Narrow on `part.type`.
|
|
42
|
+
*/
|
|
23
43
|
type ContentPart = z.infer<typeof contentPartSchema>;
|
|
44
|
+
/**
|
|
45
|
+
* Feature flags published by an adapter via `agent.capabilities`. Use to
|
|
46
|
+
* branch on capability before sending a request the adapter doesn't support
|
|
47
|
+
* (e.g. structured output, image input, MCP servers).
|
|
48
|
+
*/
|
|
24
49
|
declare const agentCapabilitiesSchema: z.ZodObject<{
|
|
25
50
|
structuredOutput: z.ZodBoolean;
|
|
26
51
|
sessionResume: z.ZodBoolean;
|
|
@@ -30,24 +55,48 @@ declare const agentCapabilitiesSchema: z.ZodObject<{
|
|
|
30
55
|
sessionFork: z.ZodOptional<z.ZodBoolean>;
|
|
31
56
|
permissionRequests: z.ZodOptional<z.ZodBoolean>;
|
|
32
57
|
}, z.core.$strip>;
|
|
58
|
+
/**
|
|
59
|
+
* Feature flags published by an adapter via `agent.capabilities`. Use to
|
|
60
|
+
* branch on capability before sending a request the adapter doesn't support
|
|
61
|
+
* (e.g. structured output, image input, MCP servers, permission handlers).
|
|
62
|
+
*/
|
|
33
63
|
type AgentCapabilities = z.infer<typeof agentCapabilitiesSchema>;
|
|
64
|
+
/** JSON Schema (Draft 7+) object, or a value produced by `z.toJSONSchema(...)`. */
|
|
34
65
|
type JsonSchema = Record<string, unknown> | ReturnType<typeof z.toJSONSchema>;
|
|
66
|
+
/** Either a JSON Schema or a Zod schema. Accepted by structured-output requests. */
|
|
35
67
|
type OutputSchema = JsonSchema | ZodType;
|
|
68
|
+
/**
|
|
69
|
+
* Common shape for MCP (Model Context Protocol) server configurations passed
|
|
70
|
+
* through to adapters. Adapters interpret the fields as needed — most accept
|
|
71
|
+
* both stdio (`command` + `args`) and HTTP (`url`) transports.
|
|
72
|
+
*/
|
|
36
73
|
interface McpServerConfig {
|
|
74
|
+
/** Executable for stdio-transport MCP servers. */
|
|
37
75
|
command?: string;
|
|
76
|
+
/** Arguments for the stdio executable. */
|
|
38
77
|
args?: string[];
|
|
78
|
+
/** Endpoint URL for HTTP/SSE-transport MCP servers. */
|
|
39
79
|
url?: string;
|
|
80
|
+
/** Working directory for the stdio MCP server subprocess. */
|
|
40
81
|
cwd?: string;
|
|
82
|
+
/** Environment variables for the stdio MCP server subprocess. */
|
|
41
83
|
env?: Record<string, string>;
|
|
84
|
+
/** HTTP headers for HTTP/SSE-transport MCP servers. */
|
|
42
85
|
headers?: Record<string, string>;
|
|
43
86
|
}
|
|
44
87
|
//#endregion
|
|
45
88
|
//#region src/schemas/events.d.ts
|
|
89
|
+
/** Fields shared by every {@link AgentEvent}. */
|
|
46
90
|
declare const baseEventSchema: z.ZodObject<{
|
|
47
91
|
id: z.ZodString;
|
|
48
92
|
runId: z.ZodString;
|
|
49
93
|
timestamp: z.ZodDate;
|
|
50
94
|
}, z.core.$strip>;
|
|
95
|
+
/**
|
|
96
|
+
* Emitted once at the start of a run, after the session has been created or
|
|
97
|
+
* resumed but before any model output. `resumed` is `true` when the run
|
|
98
|
+
* attached to an existing session via `requestedSessionId`.
|
|
99
|
+
*/
|
|
51
100
|
declare const sessionStartEventSchema: z.ZodObject<{
|
|
52
101
|
id: z.ZodString;
|
|
53
102
|
runId: z.ZodString;
|
|
@@ -57,7 +106,17 @@ declare const sessionStartEventSchema: z.ZodObject<{
|
|
|
57
106
|
sessionId: z.ZodOptional<z.ZodString>;
|
|
58
107
|
resumed: z.ZodBoolean;
|
|
59
108
|
}, z.core.$strip>;
|
|
109
|
+
/**
|
|
110
|
+
* Emitted once at the start of a run, after the session has been created or
|
|
111
|
+
* resumed but before any model output. `resumed` is `true` when the run
|
|
112
|
+
* attached to an existing session via `requestedSessionId`.
|
|
113
|
+
*/
|
|
60
114
|
type SessionStartEvent = z.infer<typeof sessionStartEventSchema>;
|
|
115
|
+
/**
|
|
116
|
+
* A complete chat message — assistant, user echo, or system. Adapters that
|
|
117
|
+
* emit assistant messages mid-stream coalesce them into one event per logical
|
|
118
|
+
* message; consumers should not expect per-token deltas.
|
|
119
|
+
*/
|
|
61
120
|
declare const messageEventSchema: z.ZodObject<{
|
|
62
121
|
id: z.ZodString;
|
|
63
122
|
runId: z.ZodString;
|
|
@@ -67,8 +126,8 @@ declare const messageEventSchema: z.ZodObject<{
|
|
|
67
126
|
model: z.ZodNullable<z.ZodString>;
|
|
68
127
|
role: z.ZodEnum<{
|
|
69
128
|
system: "system";
|
|
70
|
-
user: "user";
|
|
71
129
|
assistant: "assistant";
|
|
130
|
+
user: "user";
|
|
72
131
|
}>;
|
|
73
132
|
content: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
74
133
|
type: z.ZodLiteral<"text">;
|
|
@@ -80,7 +139,18 @@ declare const messageEventSchema: z.ZodObject<{
|
|
|
80
139
|
}, z.core.$strip>], "type">>;
|
|
81
140
|
text: z.ZodOptional<z.ZodString>;
|
|
82
141
|
}, z.core.$strip>;
|
|
142
|
+
/**
|
|
143
|
+
* A complete chat message — assistant, user echo, or system. Adapters that
|
|
144
|
+
* stream assistant text coalesce chunks into one event per logical message;
|
|
145
|
+
* consumers should not expect per-token deltas. The `text` field is a flat
|
|
146
|
+
* convenience concatenation of all text blocks in `content`.
|
|
147
|
+
*/
|
|
83
148
|
type MessageEvent = z.infer<typeof messageEventSchema>;
|
|
149
|
+
/**
|
|
150
|
+
* Model reasoning / chain-of-thought output, emitted by providers that
|
|
151
|
+
* support it (Claude extended thinking, Codex reasoning summaries). Not all
|
|
152
|
+
* adapters emit these.
|
|
153
|
+
*/
|
|
84
154
|
declare const reasoningEventSchema: z.ZodObject<{
|
|
85
155
|
id: z.ZodString;
|
|
86
156
|
runId: z.ZodString;
|
|
@@ -98,7 +168,16 @@ declare const reasoningEventSchema: z.ZodObject<{
|
|
|
98
168
|
}, z.core.$strip>], "type">>;
|
|
99
169
|
text: z.ZodOptional<z.ZodString>;
|
|
100
170
|
}, z.core.$strip>;
|
|
171
|
+
/**
|
|
172
|
+
* Model reasoning / chain-of-thought output, emitted by providers that
|
|
173
|
+
* support it (Claude extended thinking, Codex reasoning summaries). Not all
|
|
174
|
+
* adapters emit these.
|
|
175
|
+
*/
|
|
101
176
|
type ReasoningEvent = z.infer<typeof reasoningEventSchema>;
|
|
177
|
+
/**
|
|
178
|
+
* Model invoked a tool with the given input. Pair with the subsequent
|
|
179
|
+
* {@link ToolResultEvent} sharing the same `toolCallId`.
|
|
180
|
+
*/
|
|
102
181
|
declare const toolCallEventSchema: z.ZodObject<{
|
|
103
182
|
id: z.ZodString;
|
|
104
183
|
runId: z.ZodString;
|
|
@@ -110,7 +189,16 @@ declare const toolCallEventSchema: z.ZodObject<{
|
|
|
110
189
|
toolName: z.ZodString;
|
|
111
190
|
input: z.ZodOptional<z.ZodUnknown>;
|
|
112
191
|
}, z.core.$strip>;
|
|
192
|
+
/**
|
|
193
|
+
* The model invoked a tool with the given input. Pair with the subsequent
|
|
194
|
+
* {@link ToolResultEvent} sharing the same `toolCallId`.
|
|
195
|
+
*/
|
|
113
196
|
type ToolCallEvent = z.infer<typeof toolCallEventSchema>;
|
|
197
|
+
/**
|
|
198
|
+
* Result of a tool invocation. `isError`/`error` populated when the tool
|
|
199
|
+
* itself returned a failure (not when the framework couldn't dispatch the
|
|
200
|
+
* call — that yields a {@link StderrEvent} or a failed run instead).
|
|
201
|
+
*/
|
|
114
202
|
declare const toolResultEventSchema: z.ZodObject<{
|
|
115
203
|
id: z.ZodString;
|
|
116
204
|
runId: z.ZodString;
|
|
@@ -124,7 +212,16 @@ declare const toolResultEventSchema: z.ZodObject<{
|
|
|
124
212
|
isError: z.ZodOptional<z.ZodBoolean>;
|
|
125
213
|
error: z.ZodOptional<z.ZodString>;
|
|
126
214
|
}, z.core.$strip>;
|
|
215
|
+
/**
|
|
216
|
+
* Result of a tool invocation. `isError` / `error` are populated when the
|
|
217
|
+
* tool itself reported failure (framework-level dispatch failures yield a
|
|
218
|
+
* {@link StderrEvent} or a failed run instead).
|
|
219
|
+
*/
|
|
127
220
|
type ToolResultEvent = z.infer<typeof toolResultEventSchema>;
|
|
221
|
+
/**
|
|
222
|
+
* Captured stderr text from the underlying CLI subprocess (CLI adapters
|
|
223
|
+
* only). Useful for surfacing provider diagnostics.
|
|
224
|
+
*/
|
|
128
225
|
declare const stderrEventSchema: z.ZodObject<{
|
|
129
226
|
id: z.ZodString;
|
|
130
227
|
runId: z.ZodString;
|
|
@@ -133,7 +230,16 @@ declare const stderrEventSchema: z.ZodObject<{
|
|
|
133
230
|
sessionId: z.ZodOptional<z.ZodString>;
|
|
134
231
|
text: z.ZodString;
|
|
135
232
|
}, z.core.$strip>;
|
|
233
|
+
/**
|
|
234
|
+
* Captured stderr text from the underlying CLI subprocess (CLI adapters
|
|
235
|
+
* only). Useful for surfacing provider diagnostics.
|
|
236
|
+
*/
|
|
136
237
|
type StderrEvent = z.infer<typeof stderrEventSchema>;
|
|
238
|
+
/**
|
|
239
|
+
* Emitted exactly once at the end of a run, just before the `RunResult`
|
|
240
|
+
* promise resolves. Mirrors the run's terminal status; on failure, `error`
|
|
241
|
+
* carries a human-readable summary.
|
|
242
|
+
*/
|
|
137
243
|
declare const sessionEndEventSchema: z.ZodObject<{
|
|
138
244
|
id: z.ZodString;
|
|
139
245
|
runId: z.ZodString;
|
|
@@ -141,13 +247,32 @@ declare const sessionEndEventSchema: z.ZodObject<{
|
|
|
141
247
|
type: z.ZodLiteral<"session-end">;
|
|
142
248
|
sessionId: z.ZodOptional<z.ZodString>;
|
|
143
249
|
status: z.ZodEnum<{
|
|
144
|
-
completed: "completed";
|
|
145
250
|
failed: "failed";
|
|
251
|
+
completed: "completed";
|
|
146
252
|
cancelled: "cancelled";
|
|
147
253
|
}>;
|
|
148
254
|
error: z.ZodOptional<z.ZodString>;
|
|
149
255
|
}, z.core.$strip>;
|
|
256
|
+
/**
|
|
257
|
+
* Emitted exactly once at the end of a run, just before the `RunResult`
|
|
258
|
+
* promise resolves. Mirrors the run's terminal status; on failure, `error`
|
|
259
|
+
* carries a human-readable summary.
|
|
260
|
+
*/
|
|
150
261
|
type SessionEndEvent = z.infer<typeof sessionEndEventSchema>;
|
|
262
|
+
/**
|
|
263
|
+
* Discriminated union over every event type. Listeners registered via
|
|
264
|
+
* `agent.onEvent(...)` receive one of these. Narrow on `event.type`:
|
|
265
|
+
*
|
|
266
|
+
* ```ts
|
|
267
|
+
* agent.onEvent((event) => {
|
|
268
|
+
* switch (event.type) {
|
|
269
|
+
* case "message": console.log(event.role, event.text); break;
|
|
270
|
+
* case "tool-call": console.log(event.toolName, event.input); break;
|
|
271
|
+
* case "session-end": console.log("done", event.status); break;
|
|
272
|
+
* }
|
|
273
|
+
* });
|
|
274
|
+
* ```
|
|
275
|
+
*/
|
|
151
276
|
declare const eventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
152
277
|
id: z.ZodString;
|
|
153
278
|
runId: z.ZodString;
|
|
@@ -165,8 +290,8 @@ declare const eventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
165
290
|
model: z.ZodNullable<z.ZodString>;
|
|
166
291
|
role: z.ZodEnum<{
|
|
167
292
|
system: "system";
|
|
168
|
-
user: "user";
|
|
169
293
|
assistant: "assistant";
|
|
294
|
+
user: "user";
|
|
170
295
|
}>;
|
|
171
296
|
content: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
172
297
|
type: z.ZodLiteral<"text">;
|
|
@@ -229,12 +354,26 @@ declare const eventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
229
354
|
type: z.ZodLiteral<"session-end">;
|
|
230
355
|
sessionId: z.ZodOptional<z.ZodString>;
|
|
231
356
|
status: z.ZodEnum<{
|
|
232
|
-
completed: "completed";
|
|
233
357
|
failed: "failed";
|
|
358
|
+
completed: "completed";
|
|
234
359
|
cancelled: "cancelled";
|
|
235
360
|
}>;
|
|
236
361
|
error: z.ZodOptional<z.ZodString>;
|
|
237
362
|
}, z.core.$strip>], "type">;
|
|
363
|
+
/**
|
|
364
|
+
* Discriminated union over every event the SDK emits during a run.
|
|
365
|
+
* Registered via `agent.onEvent(handler)`. Narrow on `event.type`:
|
|
366
|
+
*
|
|
367
|
+
* ```ts
|
|
368
|
+
* agent.onEvent((event) => {
|
|
369
|
+
* switch (event.type) {
|
|
370
|
+
* case "message": console.log(event.role, event.text); break;
|
|
371
|
+
* case "tool-call": console.log(event.toolName, event.input); break;
|
|
372
|
+
* case "session-end": console.log("done", event.status); break;
|
|
373
|
+
* }
|
|
374
|
+
* });
|
|
375
|
+
* ```
|
|
376
|
+
*/
|
|
238
377
|
type AgentEvent = z.infer<typeof eventSchema>;
|
|
239
378
|
//#endregion
|
|
240
379
|
export { OutputSchema as C, imageContentPartSchema as D, contentPartSchema as E, textContentPartSchema as O, McpServerConfig as S, agentCapabilitiesSchema as T, toolResultEventSchema as _, SessionStartEvent as a, ImageContentPart as b, ToolResultEvent as c, messageEventSchema as d, reasoningEventSchema as f, toolCallEventSchema as g, stderrEventSchema as h, SessionEndEvent as i, baseEventSchema as l, sessionStartEventSchema as m, MessageEvent as n, StderrEvent as o, sessionEndEventSchema as p, ReasoningEvent as r, ToolCallEvent as s, AgentEvent as t, eventSchema as u, AgentCapabilities as v, TextContentPart as w, JsonSchema as x, ContentPart as y };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e}from"./types-B72tDMEZ.mjs";const t=t=>{if(t){if(t.container&&t.sandbox)throw new e(`Pass either "container" or "sandbox", not both.`);return t.container??t.sandbox}},n=e=>{let n=t(e);return!e||!n?e:{...e,cwd:e.cwd??n.workdir,propagateEnv:e.container&&e.propagateEnv===void 0?!1:e.propagateEnv,spawner:n.spawner}};export{n as t};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { A as ProcessSpawner, f as EnsureDisjoint, l as BaseAgent, p as ExclusiveExecutionTargetOptions, t as AgentEventHandler } from "./types-CGzSzwfB.mjs";
|
|
2
|
+
import { t as Container } from "./index-C9XD71QR.mjs";
|
|
3
|
+
import { l as Sandbox } from "./index-B5NFoNlS.mjs";
|
|
4
|
+
import { z } from "zod/v4";
|
|
5
|
+
|
|
6
|
+
//#region src/adapters/gemini-cli/events/schemas.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* Permissive raw-event shape for Gemini CLI: `{ type: string }` plus
|
|
9
|
+
* arbitrary additional fields the CLI may emit.
|
|
10
|
+
*/
|
|
11
|
+
declare const geminiEventSchema: z.ZodObject<{
|
|
12
|
+
type: z.ZodString;
|
|
13
|
+
}, z.core.$loose>;
|
|
14
|
+
type GeminiEvent = z.infer<typeof geminiEventSchema>;
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/adapters/gemini-cli/types.d.ts
|
|
17
|
+
/**
|
|
18
|
+
* Permission handling for Gemini CLI.
|
|
19
|
+
* - `"default"`: prompt before risky tool calls.
|
|
20
|
+
* - `"full"`: full-auto (no prompts).
|
|
21
|
+
*/
|
|
22
|
+
type GeminiCliPermissionMode = "default" | "full";
|
|
23
|
+
/** Per-run options for the `gemini-cli` adapter. */
|
|
24
|
+
interface GeminiCliRunOptions {
|
|
25
|
+
/** Allowlist of tool names. */
|
|
26
|
+
allowedTools?: string[];
|
|
27
|
+
/**
|
|
28
|
+
* Filter applied against `allowedTools` — tool names listed here are
|
|
29
|
+
* removed from the allowlist before it's passed to Gemini. Ignored when
|
|
30
|
+
* `allowedTools` is empty/undefined (Gemini CLI has no standalone
|
|
31
|
+
* denylist flag).
|
|
32
|
+
*/
|
|
33
|
+
disallowedTools?: string[];
|
|
34
|
+
/** Permission strategy. See {@link GeminiCliPermissionMode}. */
|
|
35
|
+
permissionMode?: GeminiCliPermissionMode;
|
|
36
|
+
/** Extra CLI flags appended verbatim. */
|
|
37
|
+
extraArgs?: string[];
|
|
38
|
+
}
|
|
39
|
+
/** Constructor options for `createAgent("gemini-cli", ...)`. */
|
|
40
|
+
type GeminiCliAgentOptions = ExclusiveExecutionTargetOptions<Container, Sandbox> & GeminiCliRunOptions & {
|
|
41
|
+
/** Path or argv to the `gemini` binary. */command?: string[] | string; /** Working directory the agent operates against. */
|
|
42
|
+
cwd?: string; /** Environment variables for the subprocess. Layered on top of host env when `propagateEnv` is `true` (default). */
|
|
43
|
+
env?: Record<string, string>; /** Default `true`: `process.env` is inherited and `env` overlays it. Set `false` to suppress host-env propagation. */
|
|
44
|
+
propagateEnv?: boolean; /** Existing Gemini session ID to resume. */
|
|
45
|
+
sessionId?: string; /** Gemini model identifier. */
|
|
46
|
+
model?: string; /** Replaces Gemini's default system prompt entirely. */
|
|
47
|
+
systemPrompt?: string; /** File path to write the raw CLI log to (useful for debugging). */
|
|
48
|
+
logPath?: string; /** Custom process spawner; set by `createContainer`/`createSandbox`, rarely needed manually. */
|
|
49
|
+
spawner?: ProcessSpawner; /** Convenience: equivalent to calling `agent.onEvent(handler)` post-construction. */
|
|
50
|
+
onEvent?: AgentEventHandler;
|
|
51
|
+
};
|
|
52
|
+
/** Agent instance returned by `createAgent("gemini-cli", ...)`. */
|
|
53
|
+
interface GeminiCliAgent extends BaseAgent<EnsureDisjoint<GeminiCliRunOptions>> {
|
|
54
|
+
readonly type: "gemini-cli";
|
|
55
|
+
}
|
|
56
|
+
//#endregion
|
|
57
|
+
//#region src/adapters/gemini-cli/adapter.d.ts
|
|
58
|
+
declare const createGeminiCliAgent: (options?: GeminiCliAgentOptions) => GeminiCliAgent;
|
|
59
|
+
//#endregion
|
|
60
|
+
export { GeminiCliRunOptions as a, GeminiCliPermissionMode as i, GeminiCliAgent as n, GeminiEvent as o, GeminiCliAgentOptions as r, createGeminiCliAgent as t };
|