coding-agents-sdk 0.7.0 → 0.9.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 +3 -4
- package/dist/adapters/claude-code-cli/index.d.mts +1 -1
- package/dist/adapters/claude-code-cli/index.mjs +1 -1
- package/dist/adapters/claude-code-sdk/index.d.mts +1 -1
- package/dist/adapters/codex-cli/index.d.mts +1 -1
- package/dist/adapters/codex-cli/index.mjs +1 -1
- package/dist/adapters/codex-sdk/index.d.mts +1 -1
- package/dist/adapters/codex-sdk/index.mjs +1 -1
- package/dist/adapters/cursor-cli/index.d.mts +2 -0
- package/dist/adapters/cursor-cli/index.mjs +1 -0
- package/dist/adapters/cursor-sdk/index.d.mts +2 -0
- package/dist/adapters/cursor-sdk/index.mjs +1 -0
- package/dist/adapters/gemini-cli/index.d.mts +1 -1
- package/dist/adapters/gemini-cli/index.mjs +1 -1
- package/dist/adapters/opencode-cli/index.d.mts +2 -0
- package/dist/adapters/opencode-cli/index.mjs +1 -0
- package/dist/adapters/pi-cli/index.d.mts +2 -0
- package/dist/adapters/pi-cli/index.mjs +1 -0
- package/dist/container/index.d.mts +1 -1
- package/dist/container/index.mjs +1 -1
- package/dist/{container-DLkTfO-H.mjs → container--0TOW4sB.mjs} +1 -1
- package/dist/{container-LBwTeVQB.mjs → container-BuaAmhBf.mjs} +1 -1
- package/dist/{container-rp_YHXtW.mjs → container-C5h5Bdf_.mjs} +1 -1
- package/dist/{container-CC41a5S0.mjs → container-RMYjapoN.mjs} +1 -1
- package/dist/{execution-target-DjI5SnsB.mjs → execution-target-Dr2SFmkz.mjs} +1 -1
- package/dist/{index-BexN1NIq.d.mts → index-BC_KQvvz.d.mts} +4 -4
- package/dist/{index-ClPF9ivJ.d.mts → index-BTcDyVsX.d.mts} +4 -4
- package/dist/index-BsTS0n1I.d.mts +46 -0
- package/dist/{index-Chdt3rB6.d.mts → index-BsWb681o.d.mts} +2 -2
- package/dist/index-CK9BK1t2.d.mts +42 -0
- package/dist/{index-Bg_PhFYu.d.mts → index-CkX15fCQ.d.mts} +1 -1
- package/dist/index-Cpz-hhM0.d.mts +42 -0
- package/dist/{index-DLrYZB-u.d.mts → index-CzjmvgZI.d.mts} +3 -3
- package/dist/index-DM6yXz_N.d.mts +127 -0
- package/dist/{index-DxBlMT3n.d.mts → index-l1U15W0k.d.mts} +2 -2
- package/dist/{index-v6kfcMNF.d.mts → index-nx85iU6i.d.mts} +1 -1
- package/dist/index.d.mts +16 -84
- package/dist/index.mjs +1 -1
- package/dist/{oci-WGkk88hR.mjs → oci-BVYPHn7b.mjs} +1 -1
- package/dist/sandbox/index.d.mts +1 -1
- package/dist/schemas/index.d.mts +1 -1
- package/dist/{types-BeoSSi-l.d.mts → types-BnnsL3U5.d.mts} +2 -2
- package/package.json +25 -15
- package/dist/adapters/droid-cli/index.d.mts +0 -2
- package/dist/adapters/droid-cli/index.mjs +0 -1
- package/dist/index-PVFQgWRb.d.mts +0 -47
- package/dist/opencode-cli-kNTuVeZx.mjs +0 -1
- package/dist/pi-cli-J5YpX_ei.mjs +0 -1
- /package/dist/{diff-e89u7roM.mjs → diff-DkMPJCxL.mjs} +0 -0
- /package/dist/{events-D86KNGqO.d.mts → events-BE9s04ko.d.mts} +0 -0
package/README.md
CHANGED
|
@@ -29,7 +29,6 @@ Before you call `await createAgent(...)`, make sure the runtime for that adapter
|
|
|
29
29
|
- `claude-code-sdk` uses `@anthropic-ai/claude-agent-sdk` and launches Claude Code locally.
|
|
30
30
|
- `codex-cli` runs Codex CLI.
|
|
31
31
|
- `codex-sdk` uses `@openai/codex-sdk` and launches Codex locally.
|
|
32
|
-
- `droid-cli` runs Factory's Droid CLI.
|
|
33
32
|
- `gemini-cli` runs Gemini CLI.
|
|
34
33
|
- `opencode-cli` runs OpenCode CLI.
|
|
35
34
|
- `pi-cli` runs Pi CLI.
|
|
@@ -142,7 +141,7 @@ if (result.status === "completed") {
|
|
|
142
141
|
|
|
143
142
|
If you want to pass Zod schemas, depend on `zod` in your app.
|
|
144
143
|
|
|
145
|
-
`schema` accepts a raw JSON Schema object or a Zod schema. This wrapper validates only the Zod path. `
|
|
144
|
+
`schema` accepts a raw JSON Schema object or a Zod schema. This wrapper validates only the Zod path. `gemini-cli`, `opencode-cli`, and `pi-cli` do not support structured output.
|
|
146
145
|
|
|
147
146
|
If you need to name these shapes in your own helpers, import `RunRequest`, `JsonSchemaRunRequest`, `ZodRunRequest`, `RunResult`, or `CompletedRunResult` from the package.
|
|
148
147
|
|
|
@@ -198,11 +197,11 @@ This wrapper exposes MCP configuration directly on:
|
|
|
198
197
|
- `codex-cli`: `mcpConfig`, `mcpServers`
|
|
199
198
|
- `opencode-cli`: MCP is supported by the runtime (configure via opencode's own settings)
|
|
200
199
|
|
|
201
|
-
For `codex-sdk`, `gemini-cli`,
|
|
200
|
+
For `codex-sdk`, `gemini-cli`, and `pi-cli`, use the runtime's own MCP setup. This wrapper does not add separate MCP config options for them.
|
|
202
201
|
|
|
203
202
|
## Containers
|
|
204
203
|
|
|
205
|
-
Containers are supported on the CLI adapters: `claude-code-cli`, `codex-cli`, `
|
|
204
|
+
Containers are supported on the CLI adapters: `claude-code-cli`, `codex-cli`, `gemini-cli`, `opencode-cli`, and `pi-cli`.
|
|
206
205
|
Built-in container providers are:
|
|
207
206
|
|
|
208
207
|
- `docker`
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as ClaudeCodeCliRunOptions, c as ClaudeRateLimitEvent, d as ClaudeUserEvent, i as ClaudeCodeCliPermissionMode, l as ClaudeResultEvent, n as ClaudeCodeCliAgent, o as ClaudeAssistantEvent, r as ClaudeCodeCliAgentOptions, s as ClaudeEvent, t as createClaudeCodeCliAgent, u as ClaudeSystemEvent } from "../../index-
|
|
1
|
+
import { a as ClaudeCodeCliRunOptions, c as ClaudeRateLimitEvent, d as ClaudeUserEvent, i as ClaudeCodeCliPermissionMode, l as ClaudeResultEvent, n as ClaudeCodeCliAgent, o as ClaudeAssistantEvent, r as ClaudeCodeCliAgentOptions, s as ClaudeEvent, t as createClaudeCodeCliAgent, u as ClaudeSystemEvent } from "../../index-BC_KQvvz.mjs";
|
|
2
2
|
export { ClaudeAssistantEvent, ClaudeCodeCliAgent, ClaudeCodeCliAgentOptions, ClaudeCodeCliPermissionMode, ClaudeCodeCliRunOptions, ClaudeEvent, ClaudeRateLimitEvent, ClaudeResultEvent, ClaudeSystemEvent, ClaudeUserEvent, createClaudeCodeCliAgent };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{n as e}from"../../types-CwvWHEpy.mjs";import{a as t,i as n}from"../../util-CGg8cK92.mjs";import{t as r}from"../../env-DIXTVzTs.mjs";import{a as i,c as a,o,s}from"../../classify-error-DoH0BqEA.mjs";import{n as c,t as l}from"../../execution-target-
|
|
1
|
+
import{n as e}from"../../types-CwvWHEpy.mjs";import{a as t,i as n}from"../../util-CGg8cK92.mjs";import{t as r}from"../../env-DIXTVzTs.mjs";import{a as i,c as a,o,s}from"../../classify-error-DoH0BqEA.mjs";import{n as c,t as l}from"../../execution-target-Dr2SFmkz.mjs";import{t as u}from"../../structured-output-nPFh_ZoY.mjs";import{join as d}from"node:path";import{mkdtempSync as f,rmSync as p,writeFileSync as m}from"node:fs";import{tmpdir as h}from"node:os";import{z as g}from"zod/v4";import{rm as _}from"node:fs/promises";const v=e=>`session_id`in e?e.session_id:void 0,y=e=>typeof e.content==`string`?e.content:e.content.map(e=>e.text).join(`
|
|
2
2
|
`),b=e=>typeof e.result==`string`&&e.result.trim()!==``?e.result:e.subtype,x=(e,t)=>{let n=[`[${e.subtype}]`];if(e.subtype===`init`){if(e.tools&&n.push(`tools: ${e.tools.length}`),e.mcp_servers){let t=e.mcp_servers.filter(e=>e.status===`connected`).length;n.push(`mcp: ${t}/${e.mcp_servers.length} connected`)}}else e.hook_name&&(n.push(e.hook_name),e.exit_code!==void 0&&n.push(`exit: ${e.exit_code}`));let r=n.join(` `);return{events:[i(t.runId,`message`,{sessionId:t.sessionId,model:e.model??null,role:`system`,content:[a(r)],text:r})]}},S=(e,t)=>{let n=[],r=[];for(let o of e.message.content)switch(o.type){case`text`:n.push(i(t.runId,`message`,{sessionId:t.sessionId,model:e.message.model??null,role:`assistant`,content:[a(o.text)],text:o.text}));break;case`thinking`:n.push(i(t.runId,`reasoning`,{sessionId:t.sessionId,model:e.message.model??null,content:[a(o.thinking)],text:o.thinking}));break;case`tool_use`:r.push({toolCallId:o.id,toolName:o.name,input:o.input}),n.push(i(t.runId,`tool-call`,{sessionId:t.sessionId,model:e.message.model??null,toolCallId:o.id,toolName:o.name,input:o.input}));break;default:break}return{events:n,toolCalls:r}},C=(e,t)=>{let n=[];for(let r of e.message.content)switch(r.type){case`text`:n.push(i(t.runId,`message`,{sessionId:t.sessionId,model:null,role:`user`,content:[a(r.text)],text:r.text}));break;case`tool_result`:{let e=t.toolCalls.get(r.tool_use_id),a=y(r);n.push(i(t.runId,`tool-result`,{sessionId:t.sessionId,toolCallId:r.tool_use_id,toolName:e?.toolName,input:e?.input,output:a,isError:r.is_error,error:r.is_error?a:void 0}));break}default:break}return{events:n}},w=(e,t)=>{let r=e.usage?.input_tokens,i=e.usage?.cache_creation_input_tokens,a=e.usage?.cache_read_input_tokens,o=e.usage?.output_tokens,s=n(r,i,a,o),c={stats:{durationMs:e.duration_ms,apiDurationMs:e.duration_api_ms,turns:e.num_turns,inputTokens:r,cacheCreationInputTokens:i,cacheReadInputTokens:a,outputTokens:o,totalTokens:s,costUsd:e.total_cost_usd}};typeof e.result==`string`&&(c.output={...c.output,text:e.result});let l=u(e.structured_output,t,{isSuccess:!e.is_error&&e.subtype===`success`},`Structured output was requested but Claude did not return structured_output.`);return l.value!==void 0&&(c.output={...c.output,value:l.value}),l.error&&(c.error=l.error),e.is_error||e.subtype!==`success`?(c.status=`failed`,c.error={kind:`provider`,message:b(e)}):c.error||(c.status=`completed`),{events:[],state:c}},T=(e,t)=>{let n=`rate limited: ${e.rate_limit_info.status}`;return{events:[i(t.runId,`message`,{sessionId:t.sessionId,model:null,role:`system`,content:[a(n)],text:n})]}},E=(e,t)=>{switch(e.type){case`system`:return x(e,t);case`assistant`:return S(e,t);case`user`:return C(e,t);case`result`:return w(e,t);case`rate_limit_event`:return T(e,t);default:return{events:[]}}},D=g.enum([`init`,`hook_response`,`hook_started`,`hook_finished`,`hook_failed`,`hook_skipped`]),O=g.object({type:g.literal(`system`),session_id:g.string(),subtype:D,uuid:g.string(),tools:g.array(g.string()).optional(),mcp_servers:g.array(g.object({name:g.string(),status:g.enum([`connected`,`disconnected`,`error`,`failed`])})).optional(),model:g.string().optional(),cwd:g.string().optional(),hook_name:g.string().optional(),hook_event:g.string().optional(),stdout:g.string().optional(),stderr:g.string().optional(),exit_code:g.number().optional()}),k=g.object({type:g.literal(`assistant`),session_id:g.string(),uuid:g.string(),parent_tool_use_id:g.string().nullable().optional(),message:g.object({id:g.string(),type:g.literal(`message`),role:g.literal(`assistant`),model:g.string(),content:g.array(g.union([g.object({type:g.literal(`text`),text:g.string()}),g.object({type:g.literal(`tool_use`),id:g.string(),name:g.string(),input:g.record(g.string(),g.unknown())}),g.object({type:g.literal(`thinking`),thinking:g.string(),signature:g.string().optional()})])),stop_reason:g.enum([`end_turn`,`max_tokens`,`tool_use`,`stop_sequence`]).nullable(),stop_sequence:g.string().nullable().optional(),context_management:g.unknown().nullable().optional(),usage:g.object({input_tokens:g.number(),output_tokens:g.number(),cache_creation_input_tokens:g.number().optional(),cache_read_input_tokens:g.number().optional(),service_tier:g.enum([`premium`,`standard`]).nullable().optional()}),ttftMs:g.number().optional()})}),A=g.object({type:g.literal(`user`),session_id:g.string(),message:g.object({role:g.literal(`user`),content:g.array(g.union([g.object({type:g.literal(`tool_result`),tool_use_id:g.string(),content:g.union([g.string(),g.array(g.object({type:g.literal(`text`),text:g.string()}))]),is_error:g.boolean().optional()}),g.object({type:g.literal(`text`),text:g.string()})]))}),parent_tool_use_id:g.string().nullable().optional(),uuid:g.string(),isSynthetic:g.boolean().optional()}),j=g.object({type:g.literal(`result`),session_id:g.string(),uuid:g.string(),subtype:g.enum([`success`,`error_max_turns`,`error_during_execution`]),duration_ms:g.number(),duration_api_ms:g.number(),is_error:g.boolean(),num_turns:g.number(),result:g.unknown().optional(),structured_output:g.unknown().optional(),total_cost_usd:g.number(),usage:g.object({input_tokens:g.number(),cache_creation_input_tokens:g.number().optional(),cache_read_input_tokens:g.number().optional(),output_tokens:g.number(),server_tool_use:g.object({web_search_requests:g.number()}).optional()}).optional()}),M=g.object({type:g.literal(`rate_limit_event`),uuid:g.string(),session_id:g.string().optional(),rate_limit_info:g.object({status:g.string(),resetsAt:g.number().optional(),rateLimitType:g.string().optional(),overageStatus:g.string().optional(),overageDisabledReason:g.string().optional(),isUsingOverage:g.boolean().optional()})}),N=o(g.discriminatedUnion(`type`,[O,k,A,j,M])),P={structuredOutput:!0,sessionResume:!0,imageInput:!1,mcp:!0,eventStreaming:!0,sessionFork:!0},F=e=>{let{$schema:t,...n}=e;return n};var I=class n extends c{type=`claude-code-cli`;creationOptions;runDefaults;forkOnNextRun;mcpTempDir;constructor(e={}){super({type:`claude-code-cli`,capabilities:P,defaults:{cwd:e.cwd,env:e.env,command:e.command?t(e.command):void 0,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,command:e.command?[...t(e.command)]:void 0,env:e.env?{...e.env}:void 0,allowedTools:e.allowedTools?[...e.allowedTools]:void 0,disallowedTools:e.disallowedTools?[...e.disallowedTools]:void 0,mcpConfig:Array.isArray(e.mcpConfig)?[...e.mcpConfig]:e.mcpConfig,mcpServers:e.mcpServers?{...e.mcpServers}:void 0,extraArgs:e.extraArgs?[...e.extraArgs]:void 0},this.runDefaults={allowedTools:e.allowedTools?[...e.allowedTools]:void 0,disallowedTools:e.disallowedTools?[...e.disallowedTools]:void 0,appendSystemPrompt:e.appendSystemPrompt,permissionMode:e.permissionMode,mcpConfig:Array.isArray(e.mcpConfig)?[...e.mcpConfig]:e.mcpConfig,mcpServers:e.mcpServers?{...e.mcpServers}:void 0,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 Claude Code 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.`)}async onRunFinished(e){await super.onRunFinished(e),await this.cleanupMcpTempDir()}async onDispose(){await super.onDispose(),await this.cleanupMcpTempDir()}async cleanupMcpTempDir(){if(this.mcpTempDir){let e=this.mcpTempDir;this.mcpTempDir=void 0,await _(e,{recursive:!0,force:!0}).catch(()=>{})}}ensureMcpTempFile(e){this.mcpTempDir&&=(p(this.mcpTempDir,{recursive:!0,force:!0}),void 0),this.mcpTempDir=f(d(h(),`cw-mcp-`));let t=d(this.mcpTempDir,`mcp.json`);return m(t,JSON.stringify({mcpServers:e}),{encoding:`utf8`,mode:384}),t}buildArgs(e,n){let r=[`--verbose`,`--output-format`,`stream-json`],i=s(e.input),a=e.permissionMode??this.runDefaults.permissionMode,o=e.appendSystemPrompt??this.runDefaults.appendSystemPrompt,c=e.allowedTools??this.runDefaults.allowedTools,l=e.disallowedTools??this.runDefaults.disallowedTools,u=e.mcpConfig??this.runDefaults.mcpConfig,d=e.mcpServers??this.runDefaults.mcpServers,f=e.extraArgs??this.runDefaults.extraArgs,p=e.forkSession??this.runDefaults.forkSession??this.forkOnNextRun;if(e.model&&r.push(`--model`,e.model),e.systemPrompt&&r.push(`--system-prompt`,e.systemPrompt),o&&r.push(`--append-system-prompt`,o),a&&r.push(`--permission-mode`,a),c&&c.length>0&&r.push(`--allowed-tools`,c.join(`,`)),l&&l.length>0&&r.push(`--disallowed-tools`,l.join(`,`)),u)for(let e of t(u))r.push(`--mcp-config`,e);return d&&r.push(`--mcp-config`,this.ensureMcpTempFile(d)),e.schema.kind!==`none`&&r.push(`--json-schema`,JSON.stringify(F(e.schema.jsonSchema))),n.requestedSessionId&&(r.push(`--resume`,n.requestedSessionId),p&&r.push(`--fork-session`)),f&&f.length>0&&r.push(...f),r.push(`--print`,i),r}buildEnv(e,t){let n=r({propagateEnv:this.creationOptions.propagateEnv});return this.creationOptions.ci!==!1&&(n.CI=n.CI??`true`),this.defaults.env&&Object.assign(n,this.defaults.env),delete n.CLAUDECODE,n}mapRawEvent(e,t){this.appendRawLog(e);let n=N(e);if(!n)return this.onParseError(JSON.stringify(e).slice(0,200),Error(`schema validation failed`)),{events:[]};let r=v(n)??t.sessionId;this.forkOnNextRun&&t.requestedSessionId&&r&&r!==t.requestedSessionId&&(this.forkOnNextRun=!1);let i=E(n,{...t,sessionId:r});return r&&i.sessionId===void 0&&(i.sessionId=r),i}};const L=e=>new I(l(e).options);export{L as createClaudeCodeCliAgent};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as ClaudeCodeSdkExecutable, c as ClaudeCodeSdkSettingSource, i as ClaudeCodeSdkEvent, l as ClaudeCodeSdkSettings, n as ClaudeCodeSdkAgent, o as ClaudeCodeSdkPermissionMode, r as ClaudeCodeSdkAgentOptions, s as ClaudeCodeSdkRunOptions, t as createClaudeCodeSdkAgent } from "../../index-
|
|
1
|
+
import { a as ClaudeCodeSdkExecutable, c as ClaudeCodeSdkSettingSource, i as ClaudeCodeSdkEvent, l as ClaudeCodeSdkSettings, n as ClaudeCodeSdkAgent, o as ClaudeCodeSdkPermissionMode, r as ClaudeCodeSdkAgentOptions, s as ClaudeCodeSdkRunOptions, t as createClaudeCodeSdkAgent } from "../../index-l1U15W0k.mjs";
|
|
2
2
|
export { ClaudeCodeSdkAgent, ClaudeCodeSdkAgentOptions, ClaudeCodeSdkEvent, ClaudeCodeSdkExecutable, ClaudeCodeSdkPermissionMode, ClaudeCodeSdkRunOptions, ClaudeCodeSdkSettingSource, ClaudeCodeSdkSettings, createClaudeCodeSdkAgent };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as CodexCliRunOptions, c as CodexEvent, d as CodexItemUpdatedEvent, f as CodexThreadStartedEvent, i as CodexCliPermissionMode, l as CodexItemCompletedEvent, m as CodexTurnFailedEvent, n as CodexCliAgent, o as CodexCliSandboxMode, p as CodexTurnCompletedEvent, r as CodexCliAgentOptions, s as CodexErrorEvent, t as createCodexCliAgent, u as CodexItemStartedEvent } from "../../index-
|
|
1
|
+
import { a as CodexCliRunOptions, c as CodexEvent, d as CodexItemUpdatedEvent, f as CodexThreadStartedEvent, i as CodexCliPermissionMode, l as CodexItemCompletedEvent, m as CodexTurnFailedEvent, n as CodexCliAgent, o as CodexCliSandboxMode, p as CodexTurnCompletedEvent, r as CodexCliAgentOptions, s as CodexErrorEvent, t as createCodexCliAgent, u as CodexItemStartedEvent } from "../../index-BTcDyVsX.mjs";
|
|
2
2
|
export { CodexCliAgent, CodexCliAgentOptions, CodexCliPermissionMode, CodexCliRunOptions, CodexCliSandboxMode, CodexErrorEvent, CodexEvent, CodexItemCompletedEvent, CodexItemStartedEvent, CodexItemUpdatedEvent, CodexThreadStartedEvent, CodexTurnCompletedEvent, CodexTurnFailedEvent, createCodexCliAgent };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{n as e}from"../../types-CwvWHEpy.mjs";import{a as t,i as n,n as r,r as i}from"../../util-CGg8cK92.mjs";import{a,c as o,o as s,s as c}from"../../classify-error-DoH0BqEA.mjs";import{n as l,t as u}from"../../execution-target-
|
|
1
|
+
import{n as e}from"../../types-CwvWHEpy.mjs";import{a as t,i as n,n as r,r as i}from"../../util-CGg8cK92.mjs";import{a,c as o,o as s,s as c}from"../../classify-error-DoH0BqEA.mjs";import{n as l,t as u}from"../../execution-target-Dr2SFmkz.mjs";import{join as d}from"node:path";import{mkdtempSync as f,readFileSync as ee,rmSync as te,writeFileSync as p}from"node:fs";import{tmpdir as m}from"node:os";import{z as h}from"zod/v4";const ne=h.object({type:h.string()}).passthrough(),g=h.object({input_tokens:h.number().optional(),cached_input_tokens:h.number().optional(),output_tokens:h.number().optional(),reasoning_output_tokens:h.number().optional(),total_tokens:h.number().optional()}).passthrough(),_=h.object({type:h.literal(`thread.started`),thread_id:h.string()}).passthrough(),v=h.object({type:h.literal(`turn.completed`),usage:g.optional(),last_agent_message:h.string().optional(),duration_ms:h.number().optional(),num_turns:h.number().optional()}).passthrough(),re=h.object({type:h.literal(`turn.failed`),usage:g.optional(),last_agent_message:h.string().optional(),duration_ms:h.number().optional(),num_turns:h.number().optional(),message:h.string().optional(),error:h.unknown().optional()}).passthrough(),y=h.object({id:h.string(),type:h.string()}).passthrough(),ie=h.object({type:h.literal(`item.started`),item:y}).passthrough(),b=h.object({type:h.literal(`item.updated`),item:y}).passthrough(),x=h.object({type:h.literal(`item.completed`),item:y}).passthrough(),S=h.object({type:h.literal(`error`),message:h.string().optional(),error:h.unknown().optional()}).passthrough(),C=e=>r(e)?e:void 0,w=(e,t)=>{if(e){for(let n of t)if(n in e)return e[n]}},T=(e,t)=>{let n=w(e,t);return typeof n==`string`?n:void 0},E=(e,t)=>{let n=w(e,t);return typeof n==`number`?n:void 0},D=e=>{let t=Object.entries(e).filter(([,e])=>e!==void 0);if(t.length!==0)return Object.fromEntries(t)},O=e=>e.replace(/([\da-z])([A-Z])/g,`$1_$2`).toLowerCase(),k=(e,t)=>{if(typeof e==`string`&&e.trim()!==``)return e;let n=C(e);return n?T(n,[`message`,`error`,`status_message`])??T(C(n.additional_details),[`message`])??t:t},A=e=>{let t=C(e.usage),r=E(t,[`input_tokens`]),i=E(t,[`cached_input_tokens`]),a=E(t,[`output_tokens`]),o=E(t,[`reasoning_output_tokens`]),s=E(t,[`total_tokens`])??n(r,i,a,o);return{durationMs:E(e,[`duration_ms`,`durationMs`])??0,apiDurationMs:E(e,[`duration_ms`,`durationMs`])??0,turns:E(e,[`num_turns`,`numTurns`])??1,costUsd:0,inputTokens:r,cacheReadInputTokens:i,outputTokens:a,totalTokens:s}},j=e=>({toolName:`Bash`,input:D({command:T(e,[`command`]),cwd:T(e,[`cwd`,`working_directory`]),parsedCommand:w(e,[`parsed_cmd`,`parsedCommand`])})}),M=e=>{let t=T(e,[`tool`,`tool_name`])??`mcp_tool_call`,n=T(e,[`server`]),r=w(e,[`arguments`,`invocation`,`input`]);return{toolName:t,input:n===void 0?r:D({server:n,arguments:r})}},N=e=>({toolName:`WebSearch`,input:D({query:T(e,[`query`]),action:w(e,[`action`])})}),P=e=>{let t=T(e,[`status`]),n=E(e,[`exit_code`,`exitCode`]),r=T(e,[`error`])??T(C(e.result),[`error`]);return{isError:t===`error`||t===`failed`||t===`errored`||t===`interrupted`||n!==void 0&&n!==0||r!==void 0,error:r}},F=e=>({events:[],sessionId:e.thread_id}),I=(e,t)=>{let n={stats:A(e),status:`completed`};if(e.last_agent_message!==void 0&&(n.output={text:e.last_agent_message}),t.schemaRequested&&e.last_agent_message)try{n.output={...n.output,value:i(e.last_agent_message)}}catch{}return{events:[],state:n}},L=e=>({events:[],state:{stats:A(e),status:`failed`,output:e.last_agent_message===void 0?void 0:{text:e.last_agent_message},error:{kind:`provider`,message:k(e.error??e.message,`Codex turn failed.`)}}}),R=e=>({events:[],state:{status:`failed`,error:{kind:`provider`,message:k(e.error??e.message,`Codex emitted an error event.`)}}}),z=(e,t,n,r)=>{let i=T(e,[`id`]);return i?{events:[a(t.runId,`tool-call`,{sessionId:t.sessionId,model:r.model??null,toolCallId:i,toolName:n.toolName,input:n.input})],toolCalls:[{toolCallId:i,toolName:n.toolName,input:n.input}]}:{events:[]}},B=e=>w(e,[`aggregated_output`,`aggregatedOutput`,`output`,`result`,`text`])??``,V=e=>w(e,[`result`,`output`])??T(e,[`error`])??``,H=e=>w(e,[`results`,`result`,`action`])??``,U=(e,t,n,r,i)=>{let o=T(e,[`id`]);if(!o)return{events:[]};let s=t.toolCalls.get(o),c=s??n,l=P(e),u=[],d=[];return s||(u.push(a(t.runId,`tool-call`,{sessionId:t.sessionId,model:i.model??null,toolCallId:o,toolName:n.toolName,input:n.input})),d.push({toolCallId:o,toolName:n.toolName,input:n.input})),u.push(a(t.runId,`tool-result`,{sessionId:t.sessionId,toolCallId:o,toolName:c.toolName,input:c.input,output:r,isError:l.isError||void 0,error:l.error})),{events:u,toolCalls:d}},W=e=>{let t=T(e,[`summary_text`,`reasoning_text`,`text`,`summary`,`raw_content`]);if(t)return t;let n=w(e,[`summary`]);if(Array.isArray(n)){let e=n.flatMap(e=>{if(typeof e==`string`)return[e];let t=T(C(e),[`text`,`summary_text`]);return t?[t]:[]}).join(`
|
|
2
2
|
`);if(e)return e}},G=(e,t)=>{let n=T(e,[`id`]);if(!n||!t.itemCache)return;let r=t.itemCache.get(n);t.itemCache.set(n,r?{...r,...e}:{...e})},K=(e,t)=>{let n=T(e,[`id`]);if(!n||!t.itemCache)return e;let r=t.itemCache.get(n);return t.itemCache.delete(n),r?{...r,...e}:e},ae=(e,t,n)=>{let r=C(e.item);if(!r)return{events:[]};switch(G(r,n),O(T(r,[`type`])??``)){case`command_execution`:return z(r,t,j(r),n);case`mcp_tool_call`:return z(r,t,M(r),n);case`web_search`:return z(r,t,N(r),n);default:return{events:[]}}},q=(e,t)=>{let n=C(e.item);return n&&G(n,t),{events:[]}},J=(e,t,n)=>{let r=C(e.item);if(!r)return{events:[]};let s=K(r,n);switch(O(T(s,[`type`])??``)){case`agent_message`:{let e=T(s,[`text`]);if(!e)return{events:[]};let r=t.schemaRequested&&(T(s,[`phase`])===void 0||T(s,[`phase`])===`final_answer`),c;if(r)try{c=i(e)}catch{}return{events:[a(t.runId,`message`,{sessionId:t.sessionId,model:n.model??null,role:`assistant`,content:[o(e)],text:e})],state:{output:{text:e,...c===void 0?{}:{value:c}}}}}case`reasoning`:{let e=W(s);return e?{events:[a(t.runId,`reasoning`,{sessionId:t.sessionId,model:n.model??null,content:[o(e)],text:e})]}:{events:[]}}case`command_execution`:return U(s,t,j(s),B(s),n);case`mcp_tool_call`:return U(s,t,M(s),V(s),n);case`web_search`:return U(s,t,N(s),H(s),n);default:return{events:[]}}};function oe(e,t,n={}){let r=_.safeParse(e);if(r.success)return{batch:F(r.data),disposition:`mapped`};if(e.type===`turn.started`)return{batch:{events:[]},disposition:`known-ignored`};let i=v.safeParse(e);if(i.success)return{batch:I(i.data,t),disposition:`mapped`};let a=re.safeParse(e);if(a.success)return{batch:L(a.data),disposition:`mapped`};let o=S.safeParse(e);if(o.success)return{batch:R(o.data),disposition:`mapped`};let s=ie.safeParse(e);if(s.success){let e=ae(s.data,t,n);return{batch:e,disposition:e.events.length>0||(e.toolCalls?.length??0)>0?`mapped`:`known-ignored`}}let c=b.safeParse(e);if(c.success)return{batch:q(c.data,n),disposition:`known-ignored`};let l=x.safeParse(e);if(l.success){let e=J(l.data,t,n);return{batch:e,disposition:e.events.length>0||e.state!==void 0||(e.toolCalls?.length??0)>0||e.sessionId!==void 0?`mapped`:`known-ignored`}}switch(e.type){case`thread.started`:case`turn.started`:case`turn.completed`:case`turn.failed`:case`item.started`:case`item.updated`:case`item.completed`:case`error`:return{batch:{events:[]},disposition:`known-malformed`};default:return{batch:{events:[]},disposition:`unknown`}}}const se=s(ne),ce={structuredOutput:!0,sessionResume:!0,imageInput:!1,mcp:!0,eventStreaming:!0},le=e=>/^\w+$/.test(e),ue=e=>le(e)?e:JSON.stringify(e),Y=(...e)=>e.map(ue).join(`.`),X=e=>JSON.stringify(e),de=e=>`[${e.map(e=>JSON.stringify(e)).join(`,`)}]`,Z=e=>{let t=[];for(let[n,r]of Object.entries(e)){let e=Y(`mcp_servers`,n);if(r.url&&t.push(`--config`,`${e}.url=${X(r.url)}`),r.command&&t.push(`--config`,`${e}.command=${X(r.command)}`),r.args&&r.args.length>0&&t.push(`--config`,`${e}.args=${de(r.args)}`),r.cwd&&t.push(`--config`,`${e}.cwd=${X(r.cwd)}`),r.headers)for(let[e,i]of Object.entries(r.headers))t.push(`--config`,`${Y(`mcp_servers`,n,`http_headers`,e)}=${X(i)}`);if(r.env)for(let[e,i]of Object.entries(r.env))t.push(`--config`,`${Y(`mcp_servers`,n,`env`,e)}=${X(i)}`)}return t},fe=(t,n)=>{if(t!==void 0){if(!Array.isArray(t)||t.some(e=>typeof e!=`string`))throw new e(`${n} must be an array of strings.`);return[...t]}},Q=(t,n)=>{if(t===void 0)return;if(!r(t)||Array.isArray(t))throw new e(`${n} must be an object.`);let i={};for(let[r,a]of Object.entries(t)){if(typeof a!=`string`)throw new e(`${n}.${r} must be a string.`);i[r]=a}return i},pe=(t,n)=>{if(!r(t)||Array.isArray(t))throw new e(`${n} must be an object.`);let i=t.command,a=t.url,o=t.cwd;if(i!==void 0&&typeof i!=`string`)throw new e(`${n}.command must be a string.`);if(a!==void 0&&typeof a!=`string`)throw new e(`${n}.url must be a string.`);if(o!==void 0&&typeof o!=`string`)throw new e(`${n}.cwd must be a string.`);return{command:i,url:a,cwd:o,args:fe(t.args,`${n}.args`),env:Q(t.env,`${n}.env`),headers:Q(t.headers,`${n}.headers`)}},$=t=>{let n;try{n=JSON.parse(ee(t,`utf8`))}catch(n){throw n instanceof Error&&`code`in n&&n.code===`ENOENT`?new e(`mcpConfig file not found: ${t}`):new e(`mcpConfig must be valid JSON: ${t}`)}if(!r(n)||Array.isArray(n))throw new e(`mcpConfig must contain a JSON object: ${t}`);let i=n.mcpServers;if(i===void 0)return;if(!r(i)||Array.isArray(i))throw new e(`mcpConfig.mcpServers must be an object: ${t}`);let a={};for(let[e,t]of Object.entries(i))a[e]=pe(t,`mcpConfig.mcpServers.${e}`);return a},me=e=>{let t=$(e);return t?Z(t):[]};var he=class extends l{type=`codex-cli`;creationOptions;runDefaults;schemaDirs=new Map;runModels=new Map;itemCaches=new Map;constructor(e={}){super({type:`codex-cli`,capabilities:ce,defaults:{cwd:e.cwd,env:e.env,command:t(e.command??`codex`),sessionId:e.sessionId,model:e.model},spawner:e.spawner,executionTarget:e.container??e.sandbox,logPath:e.logPath,onEvent:e.onEvent}),this.creationOptions=e,this.runDefaults={codexSandboxMode:e.codexSandboxMode,additionalDirectories:e.additionalDirectories?[...e.additionalDirectories]:void 0,skipGitRepoCheck:e.skipGitRepoCheck,permissionMode:e.permissionMode,ephemeral:e.ephemeral,mcpConfig:e.mcpConfig,mcpServers:e.mcpServers?{...e.mcpServers}:void 0,extraArgs:e.extraArgs?[...e.extraArgs]:void 0}}onValidateRun(e,t){let n=e.mcpConfig??this.runDefaults.mcpConfig;n&&$(n)}buildArgs(e,t){let n=[`exec`,`--json`],r=e.codexSandboxMode??this.runDefaults.codexSandboxMode,i=e.additionalDirectories??this.runDefaults.additionalDirectories,a=e.skipGitRepoCheck??this.runDefaults.skipGitRepoCheck,o=e.permissionMode??this.runDefaults.permissionMode,s=e.ephemeral??this.runDefaults.ephemeral,l=e.extraArgs??this.runDefaults.extraArgs;this.runModels.set(t.runId,e.model),e.model&&n.push(`--model`,e.model),r&&n.push(`--sandbox`,r),o===`auto-approve`?n.push(`--full-auto`):o===`bypass-sandbox`&&n.push(`--dangerously-bypass-approvals-and-sandbox`),a&&n.push(`--skip-git-repo-check`),s&&n.push(`--ephemeral`);for(let e of i??[])n.push(`--add-dir`,e);e.schema.kind!==`none`&&n.push(`--output-schema`,this.createSchemaFile(t.runId,e.schema.jsonSchema));let u=e.mcpConfig??this.runDefaults.mcpConfig;u&&n.push(...me(u));let d=e.mcpServers??this.runDefaults.mcpServers;d&&n.push(...Z(d)),l&&l.length>0&&n.push(...l),t.requestedSessionId&&n.push(`resume`,t.requestedSessionId);let f=c(e.input);return f.trim().startsWith(`-`)?n.push(`--`,f):n.push(f),n}buildEnv(e,t){return this.buildDefaultEnv(this.creationOptions.propagateEnv)}mapRawEvent(e,t){this.appendRawLog(e);let n=se(e);if(!n)return this.onParseError(JSON.stringify(e).slice(0,200),Error(`schema validation failed`)),{events:[]};let r=this.itemCaches.get(t.runId);r||(r=new Map,this.itemCaches.set(t.runId,r));let i=oe(n,t,{model:this.runModels.get(t.runId),itemCache:r});return i.disposition===`known-malformed`&&this.onParseError(JSON.stringify(e).slice(0,200),Error(`known Codex event "${n.type}" did not match the expected payload shape`)),i.batch}async onRunFinished(e){await super.onRunFinished(e),this.runModels.delete(e.runId),this.itemCaches.delete(e.runId);let t=this.schemaDirs.get(e.runId);t&&(this.schemaDirs.delete(e.runId),te(t,{recursive:!0,force:!0}))}createSchemaFile(e,t){let n=f(d(m(),`coding-agents-sdk-codex-cli-`)),r=d(n,`output-schema.json`);return p(r,JSON.stringify(t,null,2),{encoding:`utf8`,mode:384}),this.schemaDirs.set(e,n),r}};const ge=e=>new he(u(e).options);export{ge as createCodexCliAgent};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as CodexSdkItem, i as CodexSdkEvent, n as CodexSdkAgent, o as CodexSdkPermissionMode, r as CodexSdkAgentOptions, s as CodexSdkRunOptions, t as createCodexSdkAgent } from "../../index-
|
|
1
|
+
import { a as CodexSdkItem, i as CodexSdkEvent, n as CodexSdkAgent, o as CodexSdkPermissionMode, r as CodexSdkAgentOptions, s as CodexSdkRunOptions, t as createCodexSdkAgent } from "../../index-nx85iU6i.mjs";
|
|
2
2
|
export { CodexSdkAgent, CodexSdkAgentOptions, CodexSdkEvent, CodexSdkItem, CodexSdkPermissionMode, CodexSdkRunOptions, createCodexSdkAgent };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"../../util-CGg8cK92.mjs";import{t}from"../../env-DIXTVzTs.mjs";import{a as n,c as r,r as i}from"../../classify-error-DoH0BqEA.mjs";import{t as a}from"../../SdkAgent-CxDlEycD.mjs";import{Codex as o}from"@openai/codex-sdk";const s=e=>
|
|
1
|
+
import{r as e}from"../../util-CGg8cK92.mjs";import{t}from"../../env-DIXTVzTs.mjs";import{a as n,c as r,r as i}from"../../classify-error-DoH0BqEA.mjs";import{t as a}from"../../SdkAgent-CxDlEycD.mjs";import{Codex as o}from"@openai/codex-sdk";const s=e=>{let t=e.reasoning_output_tokens;return{turns:1,costUsd:0,inputTokens:e.input_tokens,cacheReadInputTokens:e.cached_input_tokens,outputTokens:e.output_tokens,totalTokens:e.input_tokens+e.cached_input_tokens+e.output_tokens+t}},c=e=>({toolCallId:e.id,toolName:`Bash`,input:{command:e.command}}),l=e=>({toolCallId:e.id,toolName:e.tool,input:{server:e.server,arguments:e.arguments}}),u=e=>({toolCallId:e.id,toolName:`WebSearch`,input:{query:e.query}}),d=(e,t,r)=>({events:[n(t.runId,`tool-call`,{sessionId:t.sessionId,model:r.model??null,toolCallId:e.toolCallId,toolName:e.toolName,input:e.input})],toolCalls:[{toolCallId:e.toolCallId,toolName:e.toolName,input:e.input}]}),f=(e,t,r,i,a)=>{let o=i.toolCalls.get(e.toolCallId),s=o??e,c=[],l=[];return o||(c.push(n(i.runId,`tool-call`,{sessionId:i.sessionId,model:a.model??null,toolCallId:e.toolCallId,toolName:e.toolName,input:e.input})),l.push({toolCallId:e.toolCallId,toolName:e.toolName,input:e.input})),c.push(n(i.runId,`tool-result`,{sessionId:i.sessionId,toolCallId:e.toolCallId,toolName:s.toolName,input:s.input,output:t,isError:r.isError||void 0,error:r.error})),{events:c,toolCalls:l.length>0?l:void 0}},p=e=>{let t=e.status===`failed`||e.exit_code!==void 0&&e.exit_code!==0;return{isError:t,error:t?`Command exited with code ${e.exit_code??1}.`:void 0}},m=e=>e.result?.structured_content??e.result?.content??e.error?.message??``,h=e=>({isError:e.status===`failed`||e.error!==void 0,error:e.error?.message}),g=(e,t)=>({events:[n(t.runId,`stderr`,{sessionId:t.sessionId,text:e.message})],state:{error:{kind:`provider`,message:e.message}}}),_=(e,t,n)=>{switch(e.item.type){case`command_execution`:return d(c(e.item),t,n);case`mcp_tool_call`:return d(l(e.item),t,n);case`web_search`:return d(u(e.item),t,n);default:return{events:[]}}},v=(e,t,i)=>{switch(e.item.type){case`agent_message`:return{events:[n(t.runId,`message`,{sessionId:t.sessionId,model:i.model??null,role:`assistant`,content:[r(e.item.text)],text:e.item.text})],state:{output:{text:e.item.text}}};case`reasoning`:return{events:[n(t.runId,`reasoning`,{sessionId:t.sessionId,model:i.model??null,content:[r(e.item.text)],text:e.item.text})]};case`command_execution`:return f(c(e.item),e.item.aggregated_output,p(e.item),t,i);case`mcp_tool_call`:return f(l(e.item),m(e.item),h(e.item),t,i);case`web_search`:return f(u(e.item),``,{isError:!1},t,i);case`error`:return g(e.item,t);default:return{events:[]}}},y=(e,t,n={})=>{switch(e.type){case`thread.started`:return{events:[],sessionId:e.thread_id};case`turn.started`:return{events:[]};case`turn.completed`:return{events:[],state:{stats:s(e.usage),status:`completed`,error:void 0}};case`turn.failed`:return{events:[],state:{status:`failed`,error:{kind:`provider`,message:e.error.message}}};case`item.started`:return _(e,t,n);case`item.updated`:return{events:[]};case`item.completed`:return v(e,t,n);case`error`:return{events:[],state:{status:`failed`,error:{kind:`provider`,message:e.message}}};default:return{events:[]}}},b={structuredOutput:!0,sessionResume:!0,imageInput:!0,mcp:!0,eventStreaming:!0},x=e=>e.length===1&&e[0]?.type===`text`?e[0].text:e.map(e=>e.type===`text`?{type:`text`,text:e.text}:{type:`local_image`,path:e.path}),S=(e,t)=>({outputSchema:e.normalizedRequest.schema.kind===`none`?void 0:e.normalizedRequest.schema.jsonSchema,signal:t});var C=class extends a{type=`codex-sdk`;defaults;runDefaults;command;codex;resolvedEnv;constructor(e={}){super({type:`codex-sdk`,capabilities:b,sessionId:e.sessionId,onEvent:e.onEvent}),this.command=e.command,this.defaults={cwd:e.cwd,model:e.model},this.runDefaults={permissionMode:e.permissionMode,sandboxMode:e.sandboxMode,skipGitRepoCheck:e.skipGitRepoCheck,modelReasoningEffort:e.modelReasoningEffort,networkAccessEnabled:e.networkAccessEnabled,webSearchMode:e.webSearchMode,webSearchEnabled:e.webSearchEnabled,additionalDirectories:e.additionalDirectories?[...e.additionalDirectories]:void 0};let n=t({propagateEnv:e.propagateEnv});e.env&&Object.assign(n,e.env),this.resolvedEnv=n,this.codex=e.codex??new o({codexPathOverride:this.command,baseUrl:e.baseUrl,apiKey:e.apiKey,config:e.config,env:n})}getResolvedEnvForTesting(){return this.resolvedEnv}get runRequestDefaults(){return this.defaults}async executeSdkRun(t,n,r){let a=this.buildThreadOptions(n,t),o=t.requestedSessionId?this.codex.resumeThread(t.requestedSessionId,a):this.codex.startThread(a);if(!t.sessionId&&o.id&&(t.sessionId=o.id,this.setSessionId(o.id)),t.sessionId&&this.emitSessionStart(t),t.stopReason)return;let s=await o.runStreamed(x(t.normalizedRequest.input),S(t,r.signal));for await(let e of s.events){let n=y(e,{runId:t.runId,requestedSessionId:t.requestedSessionId,sessionId:t.sessionId,schemaRequested:t.normalizedRequest.schema.kind!==`none`,toolCalls:t.toolCalls},{model:t.normalizedRequest.model});this.applyBatch(t,n)}if(t.normalizedRequest.schema.kind!==`none`&&t.output.value===void 0&&t.error===void 0&&t.status!==`failed`&&t.output.text)try{i(t,{events:[],state:{output:{value:e(t.output.text)}}})}catch{}}buildThreadOptions(e,t){return{model:t.normalizedRequest.model,workingDirectory:t.normalizedRequest.cwd,approvalPolicy:e.permissionMode??this.runDefaults.permissionMode,sandboxMode:e.sandboxMode??this.runDefaults.sandboxMode,skipGitRepoCheck:e.skipGitRepoCheck??this.runDefaults.skipGitRepoCheck,modelReasoningEffort:e.modelReasoningEffort??this.runDefaults.modelReasoningEffort,networkAccessEnabled:e.networkAccessEnabled??this.runDefaults.networkAccessEnabled,webSearchMode:e.webSearchMode??this.runDefaults.webSearchMode,webSearchEnabled:e.webSearchEnabled??this.runDefaults.webSearchEnabled,additionalDirectories:e.additionalDirectories??this.runDefaults.additionalDirectories}}};const w=e=>new C(e);export{w as createCodexSdkAgent};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as CursorCliRunOptions, i as CursorCliMode, n as CursorCliAgent, o as CursorCliSandboxMode, r as CursorCliAgentOptions, s as CursorCliEvent, t as createCursorCliAgent } from "../../index-Cpz-hhM0.mjs";
|
|
2
|
+
export { CursorCliAgent, CursorCliAgentOptions, CursorCliEvent, CursorCliMode, CursorCliRunOptions, CursorCliSandboxMode, createCursorCliAgent };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as e,n as t}from"../../util-CGg8cK92.mjs";import{a as n,c as r,o as i,s as a}from"../../classify-error-DoH0BqEA.mjs";import{n as o,t as s}from"../../execution-target-Dr2SFmkz.mjs";import{z as c}from"zod/v4";const l=e=>typeof e==`number`&&Number.isFinite(e)?e:void 0,u=e=>typeof e==`string`?e:void 0,d=e=>{if(!t(e))return;let[n,r]=Object.entries(e)[0]??[];if(!(!n||!t(r)))return{rawName:n,value:r}},f=e=>{let t=e.replace(/ToolCall$/,``).replace(/([\da-z])([A-Z])/g,`$1 $2`);return t.charAt(0).toUpperCase()+t.slice(1)},p=e=>t(e)?`success`in e?e.success:`error`in e?e.error:`failure`in e?e.failure:e:e??``,m=e=>{if(t(e)){if(`error`in e)return JSON.stringify(e.error);if(`failure`in e)return JSON.stringify(e.failure)}},h=e=>u(e.session_id)??u(e.sessionId),g=(e,i,a)=>{let o=e.message;return!t(o)||!Array.isArray(o.content)?{events:[]}:{events:o.content.flatMap(e=>!t(e)||e.type!==`text`||typeof e.text!=`string`?[]:[n(i.runId,`message`,{sessionId:i.sessionId,model:a??null,role:`assistant`,content:[r(e.text)],text:e.text})])}},_=(e,t,r)=>{let i=d(e.tool_call),a=u(e.call_id),o=u(e.subtype);if(!i||!a||!o)return{events:[]};let s=f(i.rawName),c=i.value.args;if(o===`started`)return{events:[n(t.runId,`tool-call`,{sessionId:t.sessionId,model:r??null,toolCallId:a,toolName:s,input:c})],toolCalls:[{toolCallId:a,toolName:s,input:c}]};if(o!==`completed`)return{events:[]};let l=t.toolCalls.get(a),h=l?.toolName??s,g=l?.input??c,_=i.value.result,v=p(_),y=m(_),b=[],x=[];return l||(b.push(n(t.runId,`tool-call`,{sessionId:t.sessionId,model:r??null,toolCallId:a,toolName:h,input:g})),x.push({toolCallId:a,toolName:h,input:g})),b.push(n(t.runId,`tool-result`,{sessionId:t.sessionId,toolCallId:a,toolName:h,input:g,output:v,isError:y!==void 0||void 0,error:y})),{events:b,toolCalls:x.length>0?x:void 0}},v=e=>{let t=l(e.duration_ms)??l(e.durationMs)??0,n=l(e.duration_api_ms)??t,r=u(e.result);return{events:[],state:{output:r===void 0?void 0:{text:r},stats:{durationMs:t,apiDurationMs:n,turns:1,costUsd:0},status:e.is_error===!0?`failed`:`completed`,error:e.is_error===!0?{kind:`provider`,message:r??`Cursor CLI run failed.`}:void 0}}},y=(e,t)=>{let r=u(e.message)??u(e.error)??`Cursor CLI emitted an error event.`;return{events:[n(t.runId,`stderr`,{sessionId:t.sessionId,text:r})]}},b=(e,t,n)=>{let r=e;switch(u(r.type)??``){case`assistant`:return g(r,t,n);case`tool_call`:return _(r,t,n);case`result`:return v(r);case`error`:return y(r,t);default:return{events:[]}}},x=i(c.object({type:c.string()}).passthrough()),S={structuredOutput:!1,sessionResume:!0,imageInput:!1,mcp:!0,eventStreaming:!0};var C=class extends o{type=`cursor-cli`;creationOptions;runDefaults;runModels=new Map;runTextBuffers=new Map;constructor(t={}){super({type:`cursor-cli`,capabilities:S,defaults:{cwd:t.cwd,env:t.env,command:e(t.command??`agent`),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={approveMcps:t.approveMcps,extraArgs:t.extraArgs?[...t.extraArgs]:void 0,force:t.force,mode:t.mode,sandboxMode:t.sandboxMode,trust:t.trust}}buildArgs(e,t){let n=[`--print`,`--output-format`,`stream-json`],r=e.mode??this.runDefaults.mode,i=e.force??this.runDefaults.force,o=e.sandboxMode??this.runDefaults.sandboxMode,s=e.approveMcps??this.runDefaults.approveMcps,c=e.trust??this.runDefaults.trust,l=e.extraArgs??this.runDefaults.extraArgs,u=a(e.input);return this.runModels.set(t.runId,e.model),e.cwd&&n.push(`--workspace`,e.cwd),e.model&&n.push(`--model`,e.model),r&&n.push(`--mode`,r),i&&n.push(`--force`),o&&n.push(`--sandbox`,o),s&&n.push(`--approve-mcps`),c&&n.push(`--trust`),t.requestedSessionId&&n.push(`--resume`,t.requestedSessionId),l&&l.length>0&&n.push(...l),n.push(`--`,u),n}buildEnv(e,t){return this.buildDefaultEnv(this.creationOptions.propagateEnv)}mapRawEvent(e,t){this.appendRawLog(e);let n=x(e);if(!n)return this.onParseError(JSON.stringify(e).slice(0,200),Error(`schema validation failed`)),{events:[]};let r=h(n)??t.sessionId,i=b(n,{...t,sessionId:r},this.runModels.get(t.runId));r&&i.sessionId===void 0&&(i.sessionId=r);let a;for(let e of i.events){if(e.type!==`message`||e.role!==`assistant`||!e.text)continue;let n=`${this.runTextBuffers.get(t.runId)??``}${e.text}`;this.runTextBuffers.set(t.runId,n),a=n}return n.type===`result`&&i.state?.output?.text!==void 0?this.runTextBuffers.set(t.runId,i.state.output.text):a!==void 0&&(i.state={...i.state,output:{...i.state?.output,text:a}}),i}async onRunFinished(e){await super.onRunFinished(e),this.runModels.delete(e.runId),this.runTextBuffers.delete(e.runId)}};const w=e=>new C(s(e).options);export{w as createCursorCliAgent};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as CursorSdkMcpHttpAuth, c as CursorSdkModelSelection, i as CursorSdkEvent, l as CursorSdkRunOptions, n as CursorSdkAgent, o as CursorSdkMcpServerConfig, r as CursorSdkAgentOptions, s as CursorSdkModelParameterValue, t as createCursorSdkAgent, u as CursorSdkSettingSource } from "../../index-DM6yXz_N.mjs";
|
|
2
|
+
export { CursorSdkAgent, CursorSdkAgentOptions, CursorSdkEvent, CursorSdkMcpHttpAuth, CursorSdkMcpServerConfig, CursorSdkModelParameterValue, CursorSdkModelSelection, CursorSdkRunOptions, CursorSdkSettingSource, createCursorSdkAgent };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e}from"../../types-CwvWHEpy.mjs";import{a as t,c as n,s as r}from"../../classify-error-DoH0BqEA.mjs";import{t as i}from"../../SdkAgent-CxDlEycD.mjs";const a=`Cursor SDK requested user input or approval, which cursor-sdk does not support.`,o=e=>{if(!e)return;if(!e.params||e.params.length===0)return e.id;let t=[...e.params].sort((e,t)=>e.id.localeCompare(t.id)).map(e=>`${e.id}=${e.value}`).join(`,`);return`${e.id}(${t})`},s=(e,n,r,i,a)=>({events:[t(i.runId,`tool-call`,{sessionId:i.sessionId,model:a??null,toolCallId:e,toolName:n,input:r})],toolCalls:[{toolCallId:e,toolName:n,input:r}]}),c=(e,r,i)=>{let a=[],o=[],c=i.model,l=i.textBuffer??``;for(let i of e.message.content){if(i.type===`text`){a.push(t(r.runId,`message`,{sessionId:r.sessionId,model:c??null,role:`assistant`,content:[n(i.text)],text:i.text})),l+=i.text;continue}let e=s(i.id,i.name,i.input,r,c);a.push(...e.events),o.push(...e.toolCalls??[])}return{events:a,toolCalls:o.length>0?o:void 0,state:l===(i.textBuffer??``)?void 0:{output:{text:l}}}},l=(e,r)=>({events:e.message.content.map(e=>t(r.runId,`message`,{sessionId:r.sessionId,model:null,role:`user`,content:[n(e.text)],text:e.text}))}),u=(e,r,i)=>({events:[t(r.runId,`reasoning`,{sessionId:r.sessionId,model:i.model??null,content:[n(e.text)],text:e.text})]}),d=(e,n,r)=>{let i=n.toolCalls.get(e.call_id),a=i?.toolName??e.name,o=i?.input??e.args,c=[],l=[];if(!i){let t=s(e.call_id,e.name,e.args,n,r.model);c.push(...t.events),l.push(...t.toolCalls??[])}return c.push(t(n.runId,`tool-result`,{sessionId:n.sessionId,toolCallId:e.call_id,toolName:a,input:o,output:e.result??``,isError:e.status===`error`||void 0,error:e.status===`error`?`Cursor SDK tool call failed.`:void 0})),{events:c,toolCalls:l.length>0?l:void 0}},f=(e,t,n)=>e.status===`running`?t.toolCalls.has(e.call_id)?{events:[]}:s(e.call_id,e.name,e.args,t,n.model):d(e,t,n),p=e=>({durationMs:e.durationMs,apiDurationMs:e.durationMs,turns:1,costUsd:0}),m=e=>e===`finished`?`completed`:e===`cancelled`?`cancelled`:`failed`,h=e=>e.type===`request`,g=(e,n)=>({events:[t(n.runId,`stderr`,{sessionId:n.sessionId,text:`${a} request_id=${e.request_id}`})],state:{error:{kind:`provider`,message:a}}}),_=(e,t,n={})=>{switch(e.type){case`assistant`:return c(e,t,n);case`thinking`:return u(e,t,n);case`tool_call`:return f(e,t,n);case`user`:return l(e,t);default:return{events:[]}}},v=e=>({events:[],state:{output:e.result===void 0?void 0:{text:e.result},stats:p(e),status:m(e.status),error:e.status===`error`?{kind:`provider`,message:`Cursor SDK run failed.`}:void 0}}),y=o;let b;const x=async()=>(b||=import(`@cursor/sdk`).then(({Agent:e})=>({create:t=>e.create(t),resume:(t,n)=>e.resume(t,n)})),b),S=()=>({async create(e){return(await x()).create(e)},async resume(e,t){return(await x()).resume(e,t)}}),C={structuredOutput:!1,sessionResume:!0,imageInput:!1,mcp:!0,eventStreaming:!0},w=e=>{if(e)return Object.fromEntries(Object.entries(e).map(([e,t])=>[e,{...t}]))},T=e=>e===void 0?void 0:{id:e};var E=class t extends i{type=`cursor-sdk`;defaults;creationOptions;runDefaults;factory;cursorAgent;currentRunHandle;runTextBuffers=new Map;constructor(e={}){super({type:`cursor-sdk`,capabilities:C,sessionId:e.sessionId,onEvent:e.onEvent}),this.defaults={cwd:e.cwd,model:e.model},this.creationOptions={apiKey:e.apiKey,mcpServers:e.mcpServers?{...e.mcpServers}:void 0,settingSources:e.settingSources?[...e.settingSources]:void 0},this.runDefaults={localForce:e.localForce,mcpServers:e.mcpServers?{...e.mcpServers}:void 0},this.factory=e.factory??S()}get runRequestDefaults(){return this.defaults}reset(){this.cursorAgent?.close(),this.cursorAgent=void 0,this.currentRunHandle=void 0,this.runTextBuffers.clear(),super.reset()}onStopRequested(e){this.currentRunHandle?.cancel().catch(()=>{}),this.runTextBuffers.delete(e.runId),super.onStopRequested(e)}async onDispose(){this.currentRunHandle=void 0,this.runTextBuffers.clear(),this.cursorAgent&&=(await this.cursorAgent[Symbol.asyncDispose](),void 0)}async executeSdkRun(e,n,i){let a=e,o=await this.getOrCreateCursorAgent(e);a.sessionId||(a.sessionId=o.agentId,this.setSessionId(o.agentId)),a.sessionId&&this.emitSessionStart(a);let s=await o.send(r(e.normalizedRequest.input),this.buildSendOptions(n,e));this.currentRunHandle=s;try{try{for await(let n of s.stream()){let r={runId:e.runId,requestedSessionId:e.requestedSessionId,sessionId:e.sessionId,schemaRequested:!1,toolCalls:e.toolCalls};if(h(n)){this.applyBatch(e,g(n,r)),await s.cancel().catch(()=>{});return}let i=_(n,r,{model:t.getCurrentModelString(o,e),textBuffer:this.runTextBuffers.get(e.runId)}),a=i.state?.output?.text;a!==void 0&&this.runTextBuffers.set(e.runId,a),this.applyBatch(e,i)}}catch(t){if(!e.stopReason&&!e.error)throw t}let n=v(await s.wait()),r=n.state?.output?.text;r!==void 0&&this.runTextBuffers.set(e.runId,r),this.applyBatch(e,n)}finally{this.currentRunHandle=void 0,this.runTextBuffers.delete(e.runId)}}async getOrCreateCursorAgent(t){if(this.cursorAgent)return this.cursorAgent;let n=T(t.normalizedRequest.model);if(!t.requestedSessionId&&!n)throw new e(`cursor-sdk requires a model for new local agents.`);let r=t.requestedSessionId?await this.factory.resume(t.requestedSessionId,this.buildAgentOptions(t,n)):await this.factory.create(this.buildCreateOptions(t,n));return this.cursorAgent=r,this.setSessionId(r.agentId),r}buildCreateOptions(t,n){if(!n)throw new e(`cursor-sdk requires a model for new local agents.`);return{apiKey:this.creationOptions.apiKey,model:n,local:{cwd:t.normalizedRequest.cwd,settingSources:this.creationOptions.settingSources},mcpServers:w(this.creationOptions.mcpServers)}}buildAgentOptions(e,t){return{apiKey:this.creationOptions.apiKey,model:t,local:{cwd:e.normalizedRequest.cwd,settingSources:this.creationOptions.settingSources},mcpServers:w(this.creationOptions.mcpServers)}}buildSendOptions(e,t){let n=e.localForce??this.runDefaults.localForce,r=T(t.normalizedRequest.model),i=e.mcpServers?w(e.mcpServers):void 0;if(!(!n&&!r&&!i))return{model:r,mcpServers:i,local:n?{force:!0}:void 0}}static getCurrentModelString(e,t){return y(e.model)??t.normalizedRequest.model}};const D=e=>new E(e);export{D as createCursorSdkAgent};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as GeminiCliRunOptions, i as GeminiCliPermissionMode, n as GeminiCliAgent, o as GeminiEvent, r as GeminiCliAgentOptions, t as createGeminiCliAgent } from "../../index-
|
|
1
|
+
import { a as GeminiCliRunOptions, i as GeminiCliPermissionMode, n as GeminiCliAgent, o as GeminiEvent, r as GeminiCliAgentOptions, t as createGeminiCliAgent } from "../../index-CzjmvgZI.mjs";
|
|
2
2
|
export { GeminiCliAgent, GeminiCliAgentOptions, GeminiCliPermissionMode, GeminiCliRunOptions, GeminiEvent, createGeminiCliAgent };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as e,n as t}from"../../util-CGg8cK92.mjs";import{a as n,c as r,o as i,s as a}from"../../classify-error-DoH0BqEA.mjs";import{n as o,t as s}from"../../execution-target-
|
|
1
|
+
import{a as e,n as t}from"../../util-CGg8cK92.mjs";import{a as n,c as r,o as i,s as a}from"../../classify-error-DoH0BqEA.mjs";import{n as o,t as s}from"../../execution-target-Dr2SFmkz.mjs";import{z as c}from"zod/v4";const l=e=>typeof e==`string`?e:void 0,u=e=>typeof e==`number`&&Number.isFinite(e)?e:void 0,d=e=>{if(typeof e==`string`)return e;if(Array.isArray(e))return e.map(d).join(``);if(t(e)){let t=l(e.text);if(t)return t;let n=e.parts??e.content;if(Array.isArray(n))return n.map(d).join(``)}return``},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=e=>{let n=e,r=l(n.session_id)??l(n.sessionId);if(r)return r;if(t(n.message))return l(n.message.session_id)??l(n.message.sessionId)},h=(e,t)=>{let i=`[init]`;return{events:[n(t.runId,`message`,{sessionId:t.sessionId,model:null,role:`system`,content:[r(i)],text:i})]}},g=(e,i,a)=>{let o=t(e.message)?e.message:e,s=l(o.role)??l(e.role)??`assistant`,c=l(o.model)??l(e.model)??a.model??null,u=d(o.content??o.parts??o.text??e.content??e.text);return u?.trim()?s===`assistant`?{events:[n(i.runId,`message`,{sessionId:i.sessionId,model:c,role:`assistant`,content:[r(u)],text:u})]}:{events:[n(i.runId,`message`,{sessionId:i.sessionId,model:null,role:`user`,content:[r(u)],text:u})]}:{events:[]}},_=(e,t,i)=>{let a=l(e.thought)??l(e.text)??l(e.content)??``;return a.trim()?{events:[n(t.runId,`reasoning`,{sessionId:t.sessionId,model:i.model??null,content:[r(a)],text:a})]}:{events:[]}},v=(e,r,i)=>{let a=l(e.tool_id)??l(e.id)??p(),o=l(e.tool_name)??l(e.name)??`tool`,s=(t(e.parameters)?e.parameters:void 0)??(t(e.args)?e.args:void 0)??(t(e.input)?e.input:void 0)??{};return{events:[n(r.runId,`tool-call`,{sessionId:r.sessionId,model:i.model??null,toolCallId:a,toolName:o,input:s})],toolCalls:[{toolCallId:a,toolName:o,input:s}]}},y=(e,t)=>{let r=l(e.tool_id)??l(e.tool_use_id)??l(e.id)??p(),i=l(e.status),a=i?i!==`success`:!!e.error,o=e.output??e.result??e.content??e.message??(typeof e.error==`string`?e.error:void 0),s=f(o),c=t.toolCalls.get(r);return{events:[n(t.runId,`tool-result`,{sessionId:t.sessionId,toolCallId:r,toolName:c?.toolName,input:c?.input,output:s,isError:a||void 0,error:a?f(e.error??o):void 0})]}},b=e=>{let n=(t(e.token_count)?e.token_count:void 0)??(t(e.tokenCount)?e.tokenCount:void 0)??(t(e.usage)?e.usage:void 0)??(t(e.usage_metadata)?e.usage_metadata:void 0)??(t(e.usageMetadata)?e.usageMetadata:void 0)??(t(e.stats)?e.stats:void 0);if(!n)return;let r=u(n.prompt_tokens)??u(n.promptTokens)??u(n.input_tokens)??u(n.inputTokens)??u(n.prompt_token_count),i=u(n.completion_tokens)??u(n.output_tokens)??u(n.outputTokens)??u(n.candidates_token_count)??u(n.completion_token_count);if(!(r===void 0&&i===void 0))return{inputTokens:r??0,outputTokens:i??0}},x=(e,n)=>{let r=l(e.status)??l(e.subtype)??`success`,i=r!==`success`||!!e.error||e.is_error===!0,a=e.result??e.output??e.text??e.content,o=u(e.duration_ms)??u(e.durationMs)??(t(e.stats)?u(e.stats.total_time_ms):void 0)??0,s=b(e),c=s?s.inputTokens+s.outputTokens:void 0,d={stats:{durationMs:o,apiDurationMs:o,turns:u(e.num_turns)??1,costUsd:u(e.total_cost_usd)??0,inputTokens:s?.inputTokens,outputTokens:s?.outputTokens,totalTokens:c}};return typeof a==`string`&&(d.output={text:a}),e.structured_output===void 0?n.schemaRequested&&a!==void 0&&(d.output={...d.output,value:a}):d.output={...d.output,value:e.structured_output},i?(d.status=`failed`,d.error={kind:`provider`,message:l(e.error)??(typeof a==`string`&&a.trim()?a:f(e.error??a??r))}):d.status=`completed`,{events:[],state:d}},S=(e,t)=>{let r=l(e.message)??(e.error===void 0?void 0:f(e.error))??(e.details===void 0?void 0:f(e.details))??`Gemini emitted an error event.`;return{events:[n(t.runId,`stderr`,{sessionId:t.sessionId,text:r})]}},C=(e,t,n={})=>{let r=e;switch(e.type){case`init`:return h(r,t);case`message`:return g(r,t,n);case`thought`:return _(r,t,n);case`tool_use`:return v(r,t,n);case`tool_result`:return y(r,t);case`result`:return x(r,t);case`error`:return S(r,t);default:return{events:[]}}},w=i(c.object({type:c.string()}).passthrough()),T={structuredOutput:!1,sessionResume:!0,imageInput:!1,mcp:!0,eventStreaming:!0};var E=class extends o{type=`gemini-cli`;creationOptions;runDefaults;runModels=new Map;runTextBuffers=new Map;constructor(t={}){super({type:`gemini-cli`,capabilities:T,defaults:{cwd:t.cwd,env:t.env,command:e(t.command??`gemini`),sessionId:t.sessionId,model:t.model,systemPrompt:t.systemPrompt},spawner:t.spawner,executionTarget:t.container??t.sandbox,logPath:t.logPath,onEvent:t.onEvent}),this.creationOptions=t,this.runDefaults={allowedTools:t.allowedTools?[...t.allowedTools]:void 0,disallowedTools:t.disallowedTools?[...t.disallowedTools]:void 0,permissionMode:t.permissionMode,extraArgs:t.extraArgs?[...t.extraArgs]:void 0}}buildArgs(e,t){let n=[`--output-format`,`stream-json`],r=a(e.input),i=e.allowedTools??this.runDefaults.allowedTools,o=e.disallowedTools??this.runDefaults.disallowedTools,s=e.permissionMode??this.runDefaults.permissionMode,c=e.extraArgs??this.runDefaults.extraArgs;if(this.runModels.set(t.runId,e.model),e.model&&n.push(`--model`,e.model),e.systemPrompt&&n.push(`--system-prompt`,e.systemPrompt),s===`full`&&n.push(`--approval-mode`,`yolo`),i&&i.length>0){let e=new Set((o??[]).map(e=>e.toLowerCase())),t=i.filter(t=>!e.has(t.toLowerCase()));for(let e of t)n.push(`--allowed-tools`,e)}return t.requestedSessionId&&n.push(`--resume`,t.requestedSessionId),c&&c.length>0&&n.push(...c),r.trim().startsWith(`-`)?n.push(`--prompt`,r):n.push(r),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=m(n)??t.sessionId,i=C(n,{...t,sessionId:r},{model:this.runModels.get(t.runId)});r&&i.sessionId===void 0&&(i.sessionId=r);let a;for(let e of i.events){if(e.type!==`message`||e.role!==`assistant`||!e.text)continue;let n=`${this.runTextBuffers.get(t.runId)??``}${e.text}`;this.runTextBuffers.set(t.runId,n),a=n}return n.type===`result`&&i.state?.output?.text!==void 0?this.runTextBuffers.set(t.runId,i.state.output.text):a!==void 0&&(i.state={...i.state,output:{...i.state?.output,text:a}}),i}async onRunFinished(e){await super.onRunFinished(e),this.runModels.delete(e.runId),this.runTextBuffers.delete(e.runId)}};const D=e=>new E(s(e).options);export{D as createGeminiCliAgent};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as OpencodeEvent, i as OpencodeCliRunOptions, n as OpencodeCliAgent, r as OpencodeCliAgentOptions, t as createOpencodeCliAgent } from "../../index-CK9BK1t2.mjs";
|
|
2
|
+
export { OpencodeCliAgent, OpencodeCliAgentOptions, OpencodeCliRunOptions, OpencodeEvent, createOpencodeCliAgent };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as e,i as t,n}from"../../util-CGg8cK92.mjs";import{a as r,c as i,o as a,s as o}from"../../classify-error-DoH0BqEA.mjs";import{n as s,t as c}from"../../execution-target-Dr2SFmkz.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 a=u((n(e.part)?e.part:void 0)?.text)??``;return a.trim()?{events:[r(t.runId,`message`,{sessionId:t.sessionId,model:null,role:`assistant`,content:[i(a)],text:a})]}:{events:[]}},_=(e,t)=>{let a=u((n(e.part)?e.part:void 0)?.text)??``;return a.trim()?{events:[r(t.runId,`reasoning`,{sessionId:t.sessionId,model:null,content:[i(a)],text:a})]}:{events:[]}},v=(e,t)=>{let i=n(e.part)?e.part:void 0;if(!i)return{events:[]};let a=u(i.callID)??p(),o=u(i.tool)??`tool`,s=n(i.state)?i.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:[r(t.runId,`tool-call`,{sessionId:t.sessionId,model:null,toolCallId:a,toolName:o,input:c}),r(t.runId,`tool-result`,{sessionId:t.sessionId,toolCallId:a,toolName:o,input:c,output:d,isError:l||void 0,error:l?d:void 0})],toolCalls:[{toolCallId:a,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 i=n(e.error)?e.error:void 0,a=u((n(i?.data)?i.data:void 0)?.message)??u(i?.message)??u(i?.name)??`unknown error`;return{events:[r(t.runId,`stderr`,{sessionId:t.sessionId,text:a})],state:{status:`failed`,error:{kind:`provider`,message:a}}}},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=a(l.object({type:l.string()}).passthrough()),C={structuredOutput:!1,sessionResume:!0,sessionFork:!0,imageInput:!1,mcp:!0,eventStreaming:!0};var w=class extends s{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`],r=o(e.input),i=e.agent??this.runDefaults.agent,a=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),i&&n.push(`--agent`,i),a&&a.length>0)for(let e of a)n.push(`--file`,e);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);let p=r.trim().split(/\s+/).filter(Boolean);return n.push(`--`,...p),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(c(e).options);export{T as createOpencodeCliAgent};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e}from"../../types-CwvWHEpy.mjs";import{a as t,n}from"../../util-CGg8cK92.mjs";import{a as r,c as i,o as a,s as o}from"../../classify-error-DoH0BqEA.mjs";import{n as s,t as c}from"../../execution-target-Dr2SFmkz.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,a)=>{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)??a.model??null,l=[];return a.reasoningText&&l.push(r(t.runId,`reasoning`,{sessionId:t.sessionId,model:c,content:[i(a.reasoningText)],text:a.reasoningText})),s&&l.push(r(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 i=u(e.toolCallId)??f(),a=u(e.toolName)??`tool`,o=e.args===void 0?void 0:e.args;return{events:[r(t.runId,`tool-call`,{sessionId:t.sessionId,model:n.model??null,toolCallId:i,toolName:a,input:o})],toolCalls:[{toolCallId:i,toolName:a,input:o}]}},b=(e,t)=>{let n=u(e.toolCallId)??f(),i=!!e.isError,a=e.result,o=t.toolCalls.get(n),s=u(e.toolName)??o?.toolName;return{events:[r(t.runId,`tool-result`,{sessionId:t.sessionId,toolCallId:n,toolName:s,input:o?.input,output:a,isError:i||void 0,error:i?p(a):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=a(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 s{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`],r=e.provider??this.runDefaults.provider,i=e.thinking??this.runDefaults.thinking,a=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?r?n.push(`--model`,`${r}/${e.model}`):n.push(`--model`,e.model):r&&n.push(`--provider`,r),e.systemPrompt&&n.push(`--system-prompt`,e.systemPrompt),a&&n.push(`--append-system-prompt`,a),i&&n.push(`--thinking`,i),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=o(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(c(e).options);export{O as createPiCliAgent};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { $ as WorkdirFileChange, A as E2BProviderConfig, B as ContainerFileSystem, C as NerdctlProviderConfig, D as E2BContainerBase, E as E2BContainer, F as DockerContainerConfig, G as ContainerType, H as ContainerLifecycle, I as DockerProviderConfig, J as PortMapping, K as ExecOptions, L as ContainerBase, M as DockerBuildConfig, N as DockerContainer, O as E2BContainerConfig, P as DockerContainerBase, Q as WorkdirDiffStats, R as ContainerConfigBase, S as NerdctlProviderBase, T as E2BConnectionConfig, U as ContainerObservability, V as ContainerIdentity, W as ContainerStatus, X as WorkdirChangeKind, Y as VolumeMount, Z as WorkdirDiff, _ as NerdctlBuildBase, a as ContainerDiffError, b as NerdctlContainerBase, c as ContainerExecError, d as PodmanBuildBase, et as WorkdirSnapshot, f as PodmanBuildConfig, g as PodmanProviderConfig, h as PodmanContainerConfig, i as ContainerCreateError, j as DockerBuildBase, k as E2BCreateConfig, l as ContainerNotRunningError, m as PodmanContainerBase, n as ContainerConfig, o as ContainerDisposedError, p as PodmanContainer, q as ExecResult, r as createContainer, s as ContainerError, t as Container, tt as WorkdirSnapshotOptions, u as ContainerStartError, v as NerdctlBuildConfig, w as E2BConnectConfig, x as NerdctlContainerConfig, y as NerdctlContainer, z as ContainerExecution } from "../index-
|
|
1
|
+
import { $ as WorkdirFileChange, A as E2BProviderConfig, B as ContainerFileSystem, C as NerdctlProviderConfig, D as E2BContainerBase, E as E2BContainer, F as DockerContainerConfig, G as ContainerType, H as ContainerLifecycle, I as DockerProviderConfig, J as PortMapping, K as ExecOptions, L as ContainerBase, M as DockerBuildConfig, N as DockerContainer, O as E2BContainerConfig, P as DockerContainerBase, Q as WorkdirDiffStats, R as ContainerConfigBase, S as NerdctlProviderBase, T as E2BConnectionConfig, U as ContainerObservability, V as ContainerIdentity, W as ContainerStatus, X as WorkdirChangeKind, Y as VolumeMount, Z as WorkdirDiff, _ as NerdctlBuildBase, a as ContainerDiffError, b as NerdctlContainerBase, c as ContainerExecError, d as PodmanBuildBase, et as WorkdirSnapshot, f as PodmanBuildConfig, g as PodmanProviderConfig, h as PodmanContainerConfig, i as ContainerCreateError, j as DockerBuildBase, k as E2BCreateConfig, l as ContainerNotRunningError, m as PodmanContainerBase, n as ContainerConfig, o as ContainerDisposedError, p as PodmanContainer, q as ExecResult, r as createContainer, s as ContainerError, t as Container, tt as WorkdirSnapshotOptions, u as ContainerStartError, v as NerdctlBuildConfig, w as E2BConnectConfig, x as NerdctlContainerConfig, y as NerdctlContainer, z as ContainerExecution } from "../index-CkX15fCQ.mjs";
|
|
2
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, NerdctlBuildBase, NerdctlBuildConfig, NerdctlContainer, NerdctlContainerBase, NerdctlContainerConfig, NerdctlProviderBase, NerdctlProviderConfig, PodmanBuildBase, PodmanBuildConfig, PodmanContainer, PodmanContainerBase, PodmanContainerConfig, PodmanProviderConfig, PortMapping, VolumeMount, WorkdirChangeKind, WorkdirDiff, WorkdirDiffStats, WorkdirFileChange, WorkdirSnapshot, WorkdirSnapshotOptions, createContainer };
|
package/dist/container/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as e,i as t,n,o as r,r as i,s as a,t as o}from"../errors-XV0frS3r.mjs";async function s(e){switch(e.type){case`docker`:{let{createDockerContainer:t}=await import(`../container-
|
|
1
|
+
import{a as e,i as t,n,o as r,r as i,s as a,t as o}from"../errors-XV0frS3r.mjs";async function s(e){switch(e.type){case`docker`:{let{createDockerContainer:t}=await import(`../container-C5h5Bdf_.mjs`);return t(e)}case`e2b`:try{let{createE2BContainer:t}=await import(`../container-BuaAmhBf.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 o(`Container type "e2b" requires the optional peer dependency "e2b". Install it to use this provider.`):e}case`nerdctl`:{let{createNerdctlContainer:t}=await import(`../container-RMYjapoN.mjs`);return t(e)}case`podman`:{let{createPodmanContainer:t}=await import(`../container--0TOW4sB.mjs`);return t(e)}default:throw new o(`Unsupported container type.`)}}export{o as ContainerCreateError,n as ContainerDiffError,i as ContainerDisposedError,t as ContainerError,e as ContainerExecError,r as ContainerNotRunningError,a as ContainerStartError,s as createContainer};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e,t}from"./oci-
|
|
1
|
+
import{n as e,t}from"./oci-BVYPHn7b.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,extraArgs:n.extraArgs,image:i,builtImage:n.build!==void 0&&!n.build.tag},n)};export{n as createPodmanContainer};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./util-CGg8cK92.mjs";import{n as t,o as n,r,s as i,t as a}from"./errors-XV0frS3r.mjs";import{t as o}from"./shell-Dewbmt9R.mjs";import{n as s}from"./diff-
|
|
1
|
+
import{t as e}from"./util-CGg8cK92.mjs";import{n as t,o as n,r,s as i,t as a}from"./errors-XV0frS3r.mjs";import{t as o}from"./shell-Dewbmt9R.mjs";import{n as s}from"./diff-DkMPJCxL.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 a(`E2B create failed: ${e(t)}`)}let l=o.name??c.sandboxId,d=`running`,p=k(c,o),m={},h=()=>{if(d===`disposed`)throw new r},g=()=>{if(h(),d!==`running`)throw new n},_=s({owner:m,workdir:o.workdir,materialize:async(e,n)=>{g();let r=x(o),i=await R(c,e,r);if(!i)throw new t(`Target path does not exist: ${e}`);if(i.type!==v.DIR)throw new t(`Target path is not a directory: ${e}`);await f(n,{recursive:!0});for(let t of await c.files.list(e,{user:r}))await H(c,t.path,u(n,t.name),r)}}),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(t){throw new i(`E2B start failed: ${e(t)}`)}},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-BVYPHn7b.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,extraArgs:n.extraArgs,image:i,builtImage:n.build!==void 0&&!n.build.tag},n)};export{n as createDockerContainer};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e,t}from"./oci-
|
|
1
|
+
import{n as e,t}from"./oci-BVYPHn7b.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,extraArgs:n.extraArgs,image:a,builtImage:n.build!==void 0&&!n.build.tag},n)};export{a as createNerdctlContainer};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import{n as e}from"./types-CwvWHEpy.mjs";import{t}from"./util-CGg8cK92.mjs";import{t as n}from"./env-DIXTVzTs.mjs";import{t as r}from"./spawner-BJesLc8I.mjs";import{a as i,i as a,n as o,t as s}from"./classify-error-DoH0BqEA.mjs";import{dirname as c}from"node:path";import{createWriteStream as l,mkdirSync as u}from"node:fs";async function*d(e){let t=new TextDecoder,n=``;for await(let r of e){let e=t.decode(r,{stream:!0});n+=e;let i=n.split(`
|
|
2
|
-
`);n=i.pop()??``;for(let e of i){let t=e.trim();t&&(yield t)}}let r=t.decode();r&&(n+=r);let i=n.trim();i&&(yield i)}const f=e=>e.status===`rejected`?t(e.reason):void 0,p=(e,t)=>{if(e.stopReason)return;let n=f(t.
|
|
2
|
+
`);n=i.pop()??``;for(let e of i){let t=e.trim();t&&(yield t)}}let r=t.decode();r&&(n+=r);let i=n.trim();i&&(yield i)}const f=e=>e.status===`rejected`?t(e.reason):void 0,p=(e,t)=>{if(e.stopReason)return;let n=f(t.processResult);if(n)return{kind:`spawn`,message:n};let r=f(t.stdoutResult);if(r)return{kind:`process`,message:r};let i=f(t.stderrResult);if(i)return{kind:`process`,message:i};if(!e.status&&!e.error){let t=e.processResult,n=e.stderrLines.join(`
|
|
3
3
|
`);if(t&&t.exitCode!==null&&t.exitCode!==0)return{kind:`process`,message:n||`Process exited with code ${t.exitCode}.`};if(!a(e)&&e.stderrLines.length>0)return{kind:`process`,message:n}}},m=e=>{let t=s(e);return t.kind===`provider`?{kind:`process`,message:t.message}:t};var h=class extends o{spawner;defaults;executionTargetRef;autoStartExecutionTarget;autoStopExecutionTarget;executionTargetStopPromise;logStream;sigkillTimer;constructor(e){super({type:e.type,capabilities:e.capabilities,sessionId:e.defaults?.sessionId,onEvent:e.onEvent}),this.spawner=e.spawner??r,this.defaults=e.defaults??{},this.executionTargetRef=e.executionTarget,this.autoStartExecutionTarget=e.autoStartExecutionTarget??!0,this.autoStopExecutionTarget=e.autoStopExecutionTarget??!1,e.logPath&&this.initLogStream(e.logPath)}onParseError(e,n){this.appendRawLog(`[parse-error] ${t(n)} ${e.slice(0,200)}`)}buildDefaultEnv(e){let t=n({propagateEnv:e});return t.CI=t.CI??`true`,this.defaults.env&&Object.assign(t,this.defaults.env),t}async executeRunCore(e,n){let r=this.setupRunLifecycle(e);try{if(r.abortedBeforeStart)return this.buildResult(e,new Date);try{await this.onBeforeRun(e);let t={...n,...e.normalizedRequest},r=this.buildArgs(t,e),i=this.buildEnv(t,e),a=this.defaults.command?.[0]??`claude`,o=[...this.defaults.command?.slice(1)??[],...r];if(e.stopReason)return this.buildResult(e,new Date);e.sessionId&&this.emitSessionStart(e),e.process=this.spawner.spawn(a,o,{cwd:e.normalizedRequest.cwd,env:i,stdio:[`pipe`,`pipe`,`pipe`]}),e.process.stdin?.end();let[s,c,l]=await Promise.allSettled([this.watchStdout(e),this.watchStderr(e),e.process.wait()]);l.status===`fulfilled`&&(e.processResult=l.value);let u=p(e,{stdoutResult:s,stderrResult:c,processResult:l});u&&(e.error=u)}catch(t){!e.stopReason&&!e.error&&(e.error=m(t))}return this.buildResult(e,new Date)}finally{r.cleanup(),this.sigkillTimer&&=(clearTimeout(this.sigkillTimer),void 0);try{await this.onRunFinished(e)}catch(e){this.appendRawLog(`[cleanup-error] ${t(e)}`)}}}async watchStdout(e){let t=e.process?.stdout;if(t)for await(let n of d(t))this.appendLog(`stdout`,n),this.processLine(e,n)}async watchStderr(e){let t=e.process?.stderr;if(t)for await(let n of d(t))this.appendLog(`stderr`,n),e.stderrLines.push(n),this.emit(e,i(e.runId,`stderr`,{sessionId:e.sessionId,text:n}))}processLine(e,t){let n;try{n=JSON.parse(t)}catch(e){this.onParseError(t,e);return}let r;try{r=this.mapRawEvent(n,{runId:e.runId,requestedSessionId:e.requestedSessionId,sessionId:e.sessionId,schemaRequested:e.normalizedRequest.schema.kind!==`none`,toolCalls:e.toolCalls})}catch(e){this.onParseError(t,e);return}this.applyBatch(e,r)}get runRequestDefaults(){return this.defaults}onHandlerError(e){this.appendRawLog(`[handler-error] ${t(e)}`)}async onDispose(){let e=this.logStream;this.logStream=void 0,e&&await new Promise(t=>{e.end(t)})}onStopRequested(e){e.process?.kill(),this.sigkillTimer=setTimeout(()=>{e.process?.kill(`SIGKILL`)},5e3),this.sigkillTimer.unref?.()}onBeforeRun(e){return this.ensureExecutionTarget()}async onRunFinished(e){this.autoStopExecutionTarget&&this.executionTargetRef&&this.executionTargetRef.status===`running`&&(this.executionTargetStopPromise=this.executionTargetRef.stop().catch(e=>{this.appendRawLog(`[auto-stop-error] ${t(e)}`)}),await this.executionTargetStopPromise)}appendRawLog(e){if(!this.logStream)return;let t=typeof e==`string`?e:JSON.stringify(e);this.logStream.write(`${t}\n`)}initLogStream(e){try{u(c(e),{recursive:!0}),this.logStream=l(e,{flags:`a`}),this.logStream.write(`\n--- ${new Date().toISOString()} ---\n`)}catch{this.logStream=void 0}}appendLog(e,t){if(!this.logStream||!t)return;let n=e===`stderr`?`STDERR`:`STDOUT`,r=new Date().toISOString();for(let e of t.split(`
|
|
4
4
|
`))e&&this.logStream.write(`[${r}] ${n} ${e}\n`)}async ensureExecutionTarget(){this.executionTargetStopPromise&&=(await this.executionTargetStopPromise,void 0),this.autoStartExecutionTarget&&this.executionTargetRef&&this.executionTargetRef.status!==`running`&&await this.executionTargetRef.start()}};const g=t=>{if(t){if(t.container&&t.sandbox)throw new e(`Pass either "container" or "sandbox", not both.`);return t.container??t.sandbox}},_=e=>{let t=g(e);return!e||!t?{executionTarget:t,options:e}:{executionTarget:t,options:{...e,cwd:e.cwd??t.workdir,propagateEnv:e.container&&e.propagateEnv===void 0?!1:e.propagateEnv,spawner:t.spawner}}};export{h as n,_ as t};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { S as McpServerConfig } from "./events-
|
|
2
|
-
import { D as ProcessSpawner, f as EnsureDisjoint, l as BaseAgent, p as ExclusiveExecutionTargetOptions, t as AgentEventHandler } from "./types-
|
|
3
|
-
import { t as Container } from "./index-
|
|
4
|
-
import { c as Sandbox } from "./index-
|
|
1
|
+
import { S as McpServerConfig } from "./events-BE9s04ko.mjs";
|
|
2
|
+
import { D as ProcessSpawner, f as EnsureDisjoint, l as BaseAgent, p as ExclusiveExecutionTargetOptions, t as AgentEventHandler } from "./types-BnnsL3U5.mjs";
|
|
3
|
+
import { t as Container } from "./index-CkX15fCQ.mjs";
|
|
4
|
+
import { c as Sandbox } from "./index-BsWb681o.mjs";
|
|
5
5
|
import { z } from "zod/v4";
|
|
6
6
|
|
|
7
7
|
//#region src/adapters/claude-code-cli/events/schemas.d.ts
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { S as McpServerConfig } from "./events-
|
|
2
|
-
import { D as ProcessSpawner, f as EnsureDisjoint, l as BaseAgent, p as ExclusiveExecutionTargetOptions, t as AgentEventHandler } from "./types-
|
|
3
|
-
import { t as Container } from "./index-
|
|
4
|
-
import { c as Sandbox } from "./index-
|
|
1
|
+
import { S as McpServerConfig } from "./events-BE9s04ko.mjs";
|
|
2
|
+
import { D as ProcessSpawner, f as EnsureDisjoint, l as BaseAgent, p as ExclusiveExecutionTargetOptions, t as AgentEventHandler } from "./types-BnnsL3U5.mjs";
|
|
3
|
+
import { t as Container } from "./index-CkX15fCQ.mjs";
|
|
4
|
+
import { c as Sandbox } from "./index-BsWb681o.mjs";
|
|
5
5
|
import { z } from "zod/v4";
|
|
6
6
|
|
|
7
7
|
//#region src/adapters/codex-cli/events/schemas.d.ts
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { D as ProcessSpawner, f as EnsureDisjoint, l as BaseAgent, p as ExclusiveExecutionTargetOptions, t as AgentEventHandler } from "./types-BnnsL3U5.mjs";
|
|
2
|
+
import { t as Container } from "./index-CkX15fCQ.mjs";
|
|
3
|
+
import { c as Sandbox } from "./index-BsWb681o.mjs";
|
|
4
|
+
import { z } from "zod/v4";
|
|
5
|
+
|
|
6
|
+
//#region src/adapters/pi-cli/events/schemas.d.ts
|
|
7
|
+
declare const piEventSchema: z.ZodObject<{
|
|
8
|
+
type: z.ZodString;
|
|
9
|
+
}, z.core.$loose>;
|
|
10
|
+
type PiEvent = z.infer<typeof piEventSchema>;
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/adapters/pi-cli/types.d.ts
|
|
13
|
+
type PiCliThinkingLevel = "high" | "low" | "medium" | "minimal" | "off" | "xhigh";
|
|
14
|
+
interface PiCliRunOptions {
|
|
15
|
+
provider?: string;
|
|
16
|
+
thinking?: PiCliThinkingLevel;
|
|
17
|
+
appendSystemPrompt?: string;
|
|
18
|
+
tools?: string[];
|
|
19
|
+
noTools?: boolean;
|
|
20
|
+
noSession?: boolean;
|
|
21
|
+
sessionDir?: string;
|
|
22
|
+
forkSession?: boolean;
|
|
23
|
+
extraArgs?: string[];
|
|
24
|
+
}
|
|
25
|
+
type PiCliAgentOptions = ExclusiveExecutionTargetOptions<Container, Sandbox> & PiCliRunOptions & {
|
|
26
|
+
command?: string[] | string;
|
|
27
|
+
cwd?: string;
|
|
28
|
+
env?: Record<string, string>;
|
|
29
|
+
propagateEnv?: boolean;
|
|
30
|
+
sessionId?: string;
|
|
31
|
+
model?: string;
|
|
32
|
+
systemPrompt?: string;
|
|
33
|
+
logPath?: string;
|
|
34
|
+
spawner?: ProcessSpawner;
|
|
35
|
+
onEvent?: AgentEventHandler;
|
|
36
|
+
};
|
|
37
|
+
interface PiCliAgent extends BaseAgent<EnsureDisjoint<PiCliRunOptions>> {
|
|
38
|
+
readonly type: "pi-cli";
|
|
39
|
+
fork: () => PiCliAgent;
|
|
40
|
+
dispose: () => Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
//#endregion
|
|
43
|
+
//#region src/adapters/pi-cli/adapter.d.ts
|
|
44
|
+
declare const createPiCliAgent: (options?: PiCliAgentOptions) => PiCliAgent;
|
|
45
|
+
//#endregion
|
|
46
|
+
export { PiCliThinkingLevel as a, PiCliRunOptions as i, PiCliAgent as n, PiEvent as o, PiCliAgentOptions as r, createPiCliAgent as t };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { D as ProcessSpawner } from "./types-
|
|
2
|
-
import { Y as VolumeMount } from "./index-
|
|
1
|
+
import { D as ProcessSpawner } from "./types-BnnsL3U5.mjs";
|
|
2
|
+
import { Y as VolumeMount } from "./index-CkX15fCQ.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/sandbox/types.d.ts
|
|
5
5
|
type SandboxType = "bubblewrap" | "firejail" | "nsjail";
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { D as ProcessSpawner, f as EnsureDisjoint, l as BaseAgent, p as ExclusiveExecutionTargetOptions, t as AgentEventHandler } from "./types-BnnsL3U5.mjs";
|
|
2
|
+
import { t as Container } from "./index-CkX15fCQ.mjs";
|
|
3
|
+
import { c as Sandbox } from "./index-BsWb681o.mjs";
|
|
4
|
+
import { z } from "zod/v4";
|
|
5
|
+
|
|
6
|
+
//#region src/adapters/opencode-cli/events/schemas.d.ts
|
|
7
|
+
declare const opencodeEventSchema: z.ZodObject<{
|
|
8
|
+
type: z.ZodString;
|
|
9
|
+
}, z.core.$loose>;
|
|
10
|
+
type OpencodeEvent = z.infer<typeof opencodeEventSchema>;
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/adapters/opencode-cli/types.d.ts
|
|
13
|
+
interface OpencodeCliRunOptions {
|
|
14
|
+
agent?: string;
|
|
15
|
+
files?: string[];
|
|
16
|
+
forkSession?: boolean;
|
|
17
|
+
share?: boolean;
|
|
18
|
+
thinking?: boolean;
|
|
19
|
+
title?: string;
|
|
20
|
+
variant?: string;
|
|
21
|
+
extraArgs?: string[];
|
|
22
|
+
systemPrompt?: never;
|
|
23
|
+
}
|
|
24
|
+
type OpencodeCliAgentOptions = ExclusiveExecutionTargetOptions<Container, Sandbox> & OpencodeCliRunOptions & {
|
|
25
|
+
command?: string[] | string;
|
|
26
|
+
cwd?: string;
|
|
27
|
+
env?: Record<string, string>;
|
|
28
|
+
propagateEnv?: boolean;
|
|
29
|
+
sessionId?: string;
|
|
30
|
+
model?: string;
|
|
31
|
+
logPath?: string;
|
|
32
|
+
spawner?: ProcessSpawner;
|
|
33
|
+
onEvent?: AgentEventHandler;
|
|
34
|
+
};
|
|
35
|
+
interface OpencodeCliAgent extends BaseAgent<EnsureDisjoint<OpencodeCliRunOptions>> {
|
|
36
|
+
readonly type: "opencode-cli";
|
|
37
|
+
}
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region src/adapters/opencode-cli/adapter.d.ts
|
|
40
|
+
declare const createOpencodeCliAgent: (options?: OpencodeCliAgentOptions) => OpencodeCliAgent;
|
|
41
|
+
//#endregion
|
|
42
|
+
export { OpencodeEvent as a, OpencodeCliRunOptions as i, OpencodeCliAgent as n, OpencodeCliAgentOptions as r, createOpencodeCliAgent as t };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { D as ProcessSpawner, f as EnsureDisjoint, l as BaseAgent, p as ExclusiveExecutionTargetOptions, t as AgentEventHandler } from "./types-BnnsL3U5.mjs";
|
|
2
|
+
import { t as Container } from "./index-CkX15fCQ.mjs";
|
|
3
|
+
import { c as Sandbox } from "./index-BsWb681o.mjs";
|
|
4
|
+
import { z } from "zod/v4";
|
|
5
|
+
|
|
6
|
+
//#region src/adapters/cursor-cli/events/schemas.d.ts
|
|
7
|
+
declare const cursorCliEventSchema: z.ZodObject<{
|
|
8
|
+
type: z.ZodString;
|
|
9
|
+
}, z.core.$loose>;
|
|
10
|
+
type CursorCliEvent = z.infer<typeof cursorCliEventSchema>;
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/adapters/cursor-cli/types.d.ts
|
|
13
|
+
type CursorCliMode = "ask" | "plan";
|
|
14
|
+
type CursorCliSandboxMode = "disabled" | "enabled";
|
|
15
|
+
interface CursorCliRunOptions {
|
|
16
|
+
approveMcps?: boolean;
|
|
17
|
+
extraArgs?: string[];
|
|
18
|
+
force?: boolean;
|
|
19
|
+
mode?: CursorCliMode;
|
|
20
|
+
sandboxMode?: CursorCliSandboxMode;
|
|
21
|
+
trust?: boolean;
|
|
22
|
+
systemPrompt?: never;
|
|
23
|
+
}
|
|
24
|
+
type CursorCliAgentOptions = CursorCliRunOptions & ExclusiveExecutionTargetOptions<Container, Sandbox> & {
|
|
25
|
+
command?: string[] | string;
|
|
26
|
+
cwd?: string;
|
|
27
|
+
env?: Record<string, string>;
|
|
28
|
+
propagateEnv?: boolean;
|
|
29
|
+
sessionId?: string;
|
|
30
|
+
model?: string;
|
|
31
|
+
logPath?: string;
|
|
32
|
+
spawner?: ProcessSpawner;
|
|
33
|
+
onEvent?: AgentEventHandler;
|
|
34
|
+
};
|
|
35
|
+
interface CursorCliAgent extends BaseAgent<EnsureDisjoint<CursorCliRunOptions>> {
|
|
36
|
+
readonly type: "cursor-cli";
|
|
37
|
+
}
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region src/adapters/cursor-cli/adapter.d.ts
|
|
40
|
+
declare const createCursorCliAgent: (options?: CursorCliAgentOptions) => CursorCliAgent;
|
|
41
|
+
//#endregion
|
|
42
|
+
export { CursorCliRunOptions as a, CursorCliMode as i, CursorCliAgent as n, CursorCliSandboxMode as o, CursorCliAgentOptions as r, CursorCliEvent as s, createCursorCliAgent as t };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { D as ProcessSpawner, f as EnsureDisjoint, l as BaseAgent, p as ExclusiveExecutionTargetOptions, t as AgentEventHandler } from "./types-
|
|
2
|
-
import { t as Container } from "./index-
|
|
3
|
-
import { c as Sandbox } from "./index-
|
|
1
|
+
import { D as ProcessSpawner, f as EnsureDisjoint, l as BaseAgent, p as ExclusiveExecutionTargetOptions, t as AgentEventHandler } from "./types-BnnsL3U5.mjs";
|
|
2
|
+
import { t as Container } from "./index-CkX15fCQ.mjs";
|
|
3
|
+
import { c as Sandbox } from "./index-BsWb681o.mjs";
|
|
4
4
|
import { z } from "zod/v4";
|
|
5
5
|
|
|
6
6
|
//#region src/adapters/gemini-cli/events/schemas.d.ts
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { f as EnsureDisjoint, l as BaseAgent, t as AgentEventHandler } from "./types-BnnsL3U5.mjs";
|
|
2
|
+
//#region src/adapters/cursor-sdk/types.d.ts
|
|
3
|
+
interface CursorSdkMcpHttpAuth {
|
|
4
|
+
CLIENT_ID: string;
|
|
5
|
+
CLIENT_SECRET?: string;
|
|
6
|
+
scopes?: string[];
|
|
7
|
+
}
|
|
8
|
+
type CursorSdkMcpServerConfig = {
|
|
9
|
+
type?: "http" | "sse";
|
|
10
|
+
url: string;
|
|
11
|
+
headers?: Record<string, string>;
|
|
12
|
+
auth?: CursorSdkMcpHttpAuth;
|
|
13
|
+
} | {
|
|
14
|
+
type?: "stdio";
|
|
15
|
+
command: string;
|
|
16
|
+
args?: string[];
|
|
17
|
+
env?: Record<string, string>;
|
|
18
|
+
cwd?: string;
|
|
19
|
+
};
|
|
20
|
+
type CursorSdkSettingSource = "all" | "mdm" | "plugins" | "project" | "team" | "user";
|
|
21
|
+
interface CursorSdkModelParameterValue {
|
|
22
|
+
id: string;
|
|
23
|
+
value: string;
|
|
24
|
+
}
|
|
25
|
+
interface CursorSdkModelSelection {
|
|
26
|
+
id: string;
|
|
27
|
+
params?: CursorSdkModelParameterValue[];
|
|
28
|
+
}
|
|
29
|
+
interface CursorSdkTextBlock {
|
|
30
|
+
type: "text";
|
|
31
|
+
text: string;
|
|
32
|
+
}
|
|
33
|
+
interface CursorSdkToolUseBlock {
|
|
34
|
+
type: "tool_use";
|
|
35
|
+
id: string;
|
|
36
|
+
name: string;
|
|
37
|
+
input: unknown;
|
|
38
|
+
}
|
|
39
|
+
interface CursorSdkSystemEvent {
|
|
40
|
+
type: "system";
|
|
41
|
+
agent_id: string;
|
|
42
|
+
run_id: string;
|
|
43
|
+
subtype?: "init";
|
|
44
|
+
model?: CursorSdkModelSelection;
|
|
45
|
+
tools?: string[];
|
|
46
|
+
}
|
|
47
|
+
interface CursorSdkAssistantEvent {
|
|
48
|
+
type: "assistant";
|
|
49
|
+
agent_id: string;
|
|
50
|
+
run_id: string;
|
|
51
|
+
message: {
|
|
52
|
+
role: "assistant";
|
|
53
|
+
content: (CursorSdkTextBlock | CursorSdkToolUseBlock)[];
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
interface CursorSdkUserEvent {
|
|
57
|
+
type: "user";
|
|
58
|
+
agent_id: string;
|
|
59
|
+
run_id: string;
|
|
60
|
+
message: {
|
|
61
|
+
role: "user";
|
|
62
|
+
content: CursorSdkTextBlock[];
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
interface CursorSdkToolCallEvent {
|
|
66
|
+
type: "tool_call";
|
|
67
|
+
agent_id: string;
|
|
68
|
+
run_id: string;
|
|
69
|
+
call_id: string;
|
|
70
|
+
name: string;
|
|
71
|
+
status: "completed" | "error" | "running";
|
|
72
|
+
args?: unknown;
|
|
73
|
+
result?: unknown;
|
|
74
|
+
truncated?: {
|
|
75
|
+
args?: boolean;
|
|
76
|
+
result?: boolean;
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
interface CursorSdkThinkingEvent {
|
|
80
|
+
type: "thinking";
|
|
81
|
+
agent_id: string;
|
|
82
|
+
run_id: string;
|
|
83
|
+
text: string;
|
|
84
|
+
thinking_duration_ms?: number;
|
|
85
|
+
}
|
|
86
|
+
interface CursorSdkStatusEvent {
|
|
87
|
+
type: "status";
|
|
88
|
+
agent_id: string;
|
|
89
|
+
run_id: string;
|
|
90
|
+
status: "CANCELLED" | "CREATING" | "ERROR" | "EXPIRED" | "FINISHED" | "RUNNING";
|
|
91
|
+
message?: string;
|
|
92
|
+
}
|
|
93
|
+
interface CursorSdkRequestEvent {
|
|
94
|
+
type: "request";
|
|
95
|
+
agent_id: string;
|
|
96
|
+
run_id: string;
|
|
97
|
+
request_id: string;
|
|
98
|
+
}
|
|
99
|
+
interface CursorSdkTaskEvent {
|
|
100
|
+
type: "task";
|
|
101
|
+
agent_id: string;
|
|
102
|
+
run_id: string;
|
|
103
|
+
status?: string;
|
|
104
|
+
text?: string;
|
|
105
|
+
}
|
|
106
|
+
type CursorSdkEvent = CursorSdkAssistantEvent | CursorSdkRequestEvent | CursorSdkStatusEvent | CursorSdkSystemEvent | CursorSdkTaskEvent | CursorSdkThinkingEvent | CursorSdkToolCallEvent | CursorSdkUserEvent;
|
|
107
|
+
interface CursorSdkRunOptions {
|
|
108
|
+
localForce?: boolean;
|
|
109
|
+
mcpServers?: Record<string, CursorSdkMcpServerConfig>;
|
|
110
|
+
systemPrompt?: never;
|
|
111
|
+
}
|
|
112
|
+
interface CursorSdkAgentOptions extends CursorSdkRunOptions {
|
|
113
|
+
apiKey?: string;
|
|
114
|
+
cwd?: string;
|
|
115
|
+
sessionId?: string;
|
|
116
|
+
model?: string;
|
|
117
|
+
settingSources?: CursorSdkSettingSource[];
|
|
118
|
+
onEvent?: AgentEventHandler;
|
|
119
|
+
}
|
|
120
|
+
interface CursorSdkAgent extends BaseAgent<EnsureDisjoint<CursorSdkRunOptions>> {
|
|
121
|
+
readonly type: "cursor-sdk";
|
|
122
|
+
}
|
|
123
|
+
//#endregion
|
|
124
|
+
//#region src/adapters/cursor-sdk/adapter.d.ts
|
|
125
|
+
declare const createCursorSdkAgent: (options?: CursorSdkAgentOptions) => CursorSdkAgent;
|
|
126
|
+
//#endregion
|
|
127
|
+
export { CursorSdkMcpHttpAuth as a, CursorSdkModelSelection as c, CursorSdkEvent as i, CursorSdkRunOptions as l, CursorSdkAgent as n, CursorSdkMcpServerConfig as o, CursorSdkAgentOptions as r, CursorSdkModelParameterValue as s, createCursorSdkAgent as t, CursorSdkSettingSource as u };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as McpServerConfig } from "./events-
|
|
2
|
-
import { f as EnsureDisjoint, l as BaseAgent, t as AgentEventHandler } from "./types-
|
|
1
|
+
import { S as McpServerConfig } from "./events-BE9s04ko.mjs";
|
|
2
|
+
import { f as EnsureDisjoint, l as BaseAgent, t as AgentEventHandler } from "./types-BnnsL3U5.mjs";
|
|
3
3
|
//#region src/adapters/claude-code-sdk/types.d.ts
|
|
4
4
|
type ClaudeCodeSdkPermissionMode = "acceptEdits" | "auto" | "bypassPermissions" | "default" | "dontAsk" | "plan";
|
|
5
5
|
type ClaudeCodeSdkExecutable = "bun" | "deno" | "node";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { f as EnsureDisjoint, l as BaseAgent, t as AgentEventHandler } from "./types-
|
|
1
|
+
import { f as EnsureDisjoint, l as BaseAgent, t as AgentEventHandler } from "./types-BnnsL3U5.mjs";
|
|
2
2
|
//#region src/adapters/codex-sdk/types.d.ts
|
|
3
3
|
type CodexSdkSandboxMode = "danger-full-access" | "read-only" | "workspace-write";
|
|
4
4
|
type CodexSdkModelReasoningEffort = "high" | "low" | "medium" | "minimal" | "xhigh";
|
package/dist/index.d.mts
CHANGED
|
@@ -1,93 +1,25 @@
|
|
|
1
|
-
import { C as OutputSchema, S as McpServerConfig, T as agentCapabilitiesSchema, a as SessionStartEvent, b as ImageContentPart, c as ToolResultEvent, i as SessionEndEvent, n as MessageEvent, o as StderrEvent, r as ReasoningEvent, s as ToolCallEvent, t as AgentEvent, u as eventSchema, v as AgentCapabilities, w as TextContentPart, x as JsonSchema, y as ContentPart } from "./events-
|
|
2
|
-
import { C as RunTiming,
|
|
3
|
-
import { $ as WorkdirFileChange, A as E2BProviderConfig, B as ContainerFileSystem, C as NerdctlProviderConfig, D as E2BContainerBase, E as E2BContainer, F as DockerContainerConfig, G as ContainerType, H as ContainerLifecycle, I as DockerProviderConfig, J as PortMapping, K as ExecOptions, L as ContainerBase, M as DockerBuildConfig, N as DockerContainer, O as E2BContainerConfig, P as DockerContainerBase, Q as WorkdirDiffStats, R as ContainerConfigBase, S as NerdctlProviderBase, T as E2BConnectionConfig, U as ContainerObservability, V as ContainerIdentity, W as ContainerStatus, X as WorkdirChangeKind, Y as VolumeMount, Z as WorkdirDiff, _ as NerdctlBuildBase, a as ContainerDiffError, b as NerdctlContainerBase, c as ContainerExecError, d as PodmanBuildBase, et as WorkdirSnapshot, f as PodmanBuildConfig, g as PodmanProviderConfig, h as PodmanContainerConfig, i as ContainerCreateError, j as DockerBuildBase, k as E2BCreateConfig, l as ContainerNotRunningError, m as PodmanContainerBase, n as ContainerConfig, o as ContainerDisposedError, p as PodmanContainer, q as ExecResult, r as createContainer, s as ContainerError, t as Container, tt as WorkdirSnapshotOptions, u as ContainerStartError, v as NerdctlBuildConfig, w as E2BConnectConfig, x as NerdctlContainerConfig, y as NerdctlContainer, z as ContainerExecution } from "./index-
|
|
4
|
-
import { a as FirejailSandboxConfig, c as Sandbox, d as SandboxConfigBase, f as SandboxExecution, g as SandboxType, h as SandboxStatus, i as FirejailSandbox, l as SandboxBase, m as SandboxLifecycle, n as BubblewrapSandbox, o as NsjailSandbox, p as SandboxIdentity, r as BubblewrapSandboxConfig, s as NsjailSandboxConfig, t as createSandbox, u as SandboxConfig } from "./index-
|
|
5
|
-
import { a as ClaudeCodeCliRunOptions, c as ClaudeRateLimitEvent, d as ClaudeUserEvent, i as ClaudeCodeCliPermissionMode, l as ClaudeResultEvent, n as ClaudeCodeCliAgent, o as ClaudeAssistantEvent, r as ClaudeCodeCliAgentOptions, s as ClaudeEvent, u as ClaudeSystemEvent } from "./index-
|
|
6
|
-
import { a as ClaudeCodeSdkExecutable, c as ClaudeCodeSdkSettingSource, i as ClaudeCodeSdkEvent, l as ClaudeCodeSdkSettings, n as ClaudeCodeSdkAgent, o as ClaudeCodeSdkPermissionMode, r as ClaudeCodeSdkAgentOptions, s as ClaudeCodeSdkRunOptions } from "./index-
|
|
7
|
-
import { a as CodexCliRunOptions, c as CodexEvent, d as CodexItemUpdatedEvent, f as CodexThreadStartedEvent, i as CodexCliPermissionMode, l as CodexItemCompletedEvent, m as CodexTurnFailedEvent, n as CodexCliAgent, o as CodexCliSandboxMode, p as CodexTurnCompletedEvent, r as CodexCliAgentOptions, s as CodexErrorEvent, u as CodexItemStartedEvent } from "./index-
|
|
8
|
-
import { a as CodexSdkItem, i as CodexSdkEvent, n as CodexSdkAgent, o as CodexSdkPermissionMode, r as CodexSdkAgentOptions, s as CodexSdkRunOptions } from "./index-
|
|
9
|
-
import { a as
|
|
10
|
-
import { a as
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
declare const opencodeEventSchema: z.ZodObject<{
|
|
15
|
-
type: z.ZodString;
|
|
16
|
-
}, z.core.$loose>;
|
|
17
|
-
type OpencodeEvent = z.infer<typeof opencodeEventSchema>;
|
|
18
|
-
//#endregion
|
|
19
|
-
//#region src/adapters/opencode-cli/types.d.ts
|
|
20
|
-
interface OpencodeCliRunOptions {
|
|
21
|
-
agent?: string;
|
|
22
|
-
files?: string[];
|
|
23
|
-
forkSession?: boolean;
|
|
24
|
-
share?: boolean;
|
|
25
|
-
thinking?: boolean;
|
|
26
|
-
title?: string;
|
|
27
|
-
variant?: string;
|
|
28
|
-
extraArgs?: string[];
|
|
29
|
-
systemPrompt?: never;
|
|
30
|
-
}
|
|
31
|
-
type OpencodeCliAgentOptions = ExclusiveExecutionTargetOptions<Container, Sandbox> & OpencodeCliRunOptions & {
|
|
32
|
-
command?: string[] | string;
|
|
33
|
-
cwd?: string;
|
|
34
|
-
env?: Record<string, string>;
|
|
35
|
-
propagateEnv?: boolean;
|
|
36
|
-
sessionId?: string;
|
|
37
|
-
model?: string;
|
|
38
|
-
logPath?: string;
|
|
39
|
-
spawner?: ProcessSpawner;
|
|
40
|
-
onEvent?: AgentEventHandler;
|
|
41
|
-
};
|
|
42
|
-
interface OpencodeCliAgent extends BaseAgent<EnsureDisjoint<OpencodeCliRunOptions>> {
|
|
43
|
-
readonly type: "opencode-cli";
|
|
44
|
-
}
|
|
45
|
-
//#endregion
|
|
46
|
-
//#region src/adapters/pi-cli/events/schemas.d.ts
|
|
47
|
-
declare const piEventSchema: z.ZodObject<{
|
|
48
|
-
type: z.ZodString;
|
|
49
|
-
}, z.core.$loose>;
|
|
50
|
-
type PiEvent = z.infer<typeof piEventSchema>;
|
|
51
|
-
//#endregion
|
|
52
|
-
//#region src/adapters/pi-cli/types.d.ts
|
|
53
|
-
type PiCliThinkingLevel = "high" | "low" | "medium" | "minimal" | "off" | "xhigh";
|
|
54
|
-
interface PiCliRunOptions {
|
|
55
|
-
provider?: string;
|
|
56
|
-
thinking?: PiCliThinkingLevel;
|
|
57
|
-
appendSystemPrompt?: string;
|
|
58
|
-
tools?: string[];
|
|
59
|
-
noTools?: boolean;
|
|
60
|
-
noSession?: boolean;
|
|
61
|
-
sessionDir?: string;
|
|
62
|
-
forkSession?: boolean;
|
|
63
|
-
extraArgs?: string[];
|
|
64
|
-
}
|
|
65
|
-
type PiCliAgentOptions = ExclusiveExecutionTargetOptions<Container, Sandbox> & PiCliRunOptions & {
|
|
66
|
-
command?: string[] | string;
|
|
67
|
-
cwd?: string;
|
|
68
|
-
env?: Record<string, string>;
|
|
69
|
-
propagateEnv?: boolean;
|
|
70
|
-
sessionId?: string;
|
|
71
|
-
model?: string;
|
|
72
|
-
systemPrompt?: string;
|
|
73
|
-
logPath?: string;
|
|
74
|
-
spawner?: ProcessSpawner;
|
|
75
|
-
onEvent?: AgentEventHandler;
|
|
76
|
-
};
|
|
77
|
-
interface PiCliAgent extends BaseAgent<EnsureDisjoint<PiCliRunOptions>> {
|
|
78
|
-
readonly type: "pi-cli";
|
|
79
|
-
fork: () => PiCliAgent;
|
|
80
|
-
dispose: () => Promise<void>;
|
|
81
|
-
}
|
|
82
|
-
//#endregion
|
|
1
|
+
import { C as OutputSchema, S as McpServerConfig, T as agentCapabilitiesSchema, a as SessionStartEvent, b as ImageContentPart, c as ToolResultEvent, i as SessionEndEvent, n as MessageEvent, o as StderrEvent, r as ReasoningEvent, s as ToolCallEvent, t as AgentEvent, u as eventSchema, v as AgentCapabilities, w as TextContentPart, x as JsonSchema, y as ContentPart } from "./events-BE9s04ko.mjs";
|
|
2
|
+
import { C as RunTiming, E as ZodRunRequest, S as RunStatus, T as StructuredRunRequest, _ as RunProcessInfo, a as AgentValidationError, b as RunResultBase, c as AnyRunResult, d as CompletedRunResult, f as EnsureDisjoint, g as RunError, h as JsonSchemaRunRequest, i as AgentType, l as BaseAgent, m as FailedRunResult, n as AgentMetrics, o as AnyCompletedRunResult, r as AgentRunError, s as AnyRunRequest, t as AgentEventHandler, u as CancelledRunResult, v as RunRequest, w as StopReason, x as RunStats, y as RunResult } from "./types-BnnsL3U5.mjs";
|
|
3
|
+
import { $ as WorkdirFileChange, A as E2BProviderConfig, B as ContainerFileSystem, C as NerdctlProviderConfig, D as E2BContainerBase, E as E2BContainer, F as DockerContainerConfig, G as ContainerType, H as ContainerLifecycle, I as DockerProviderConfig, J as PortMapping, K as ExecOptions, L as ContainerBase, M as DockerBuildConfig, N as DockerContainer, O as E2BContainerConfig, P as DockerContainerBase, Q as WorkdirDiffStats, R as ContainerConfigBase, S as NerdctlProviderBase, T as E2BConnectionConfig, U as ContainerObservability, V as ContainerIdentity, W as ContainerStatus, X as WorkdirChangeKind, Y as VolumeMount, Z as WorkdirDiff, _ as NerdctlBuildBase, a as ContainerDiffError, b as NerdctlContainerBase, c as ContainerExecError, d as PodmanBuildBase, et as WorkdirSnapshot, f as PodmanBuildConfig, g as PodmanProviderConfig, h as PodmanContainerConfig, i as ContainerCreateError, j as DockerBuildBase, k as E2BCreateConfig, l as ContainerNotRunningError, m as PodmanContainerBase, n as ContainerConfig, o as ContainerDisposedError, p as PodmanContainer, q as ExecResult, r as createContainer, s as ContainerError, t as Container, tt as WorkdirSnapshotOptions, u as ContainerStartError, v as NerdctlBuildConfig, w as E2BConnectConfig, x as NerdctlContainerConfig, y as NerdctlContainer, z as ContainerExecution } from "./index-CkX15fCQ.mjs";
|
|
4
|
+
import { a as FirejailSandboxConfig, c as Sandbox, d as SandboxConfigBase, f as SandboxExecution, g as SandboxType, h as SandboxStatus, i as FirejailSandbox, l as SandboxBase, m as SandboxLifecycle, n as BubblewrapSandbox, o as NsjailSandbox, p as SandboxIdentity, r as BubblewrapSandboxConfig, s as NsjailSandboxConfig, t as createSandbox, u as SandboxConfig } from "./index-BsWb681o.mjs";
|
|
5
|
+
import { a as ClaudeCodeCliRunOptions, c as ClaudeRateLimitEvent, d as ClaudeUserEvent, i as ClaudeCodeCliPermissionMode, l as ClaudeResultEvent, n as ClaudeCodeCliAgent, o as ClaudeAssistantEvent, r as ClaudeCodeCliAgentOptions, s as ClaudeEvent, u as ClaudeSystemEvent } from "./index-BC_KQvvz.mjs";
|
|
6
|
+
import { a as ClaudeCodeSdkExecutable, c as ClaudeCodeSdkSettingSource, i as ClaudeCodeSdkEvent, l as ClaudeCodeSdkSettings, n as ClaudeCodeSdkAgent, o as ClaudeCodeSdkPermissionMode, r as ClaudeCodeSdkAgentOptions, s as ClaudeCodeSdkRunOptions } from "./index-l1U15W0k.mjs";
|
|
7
|
+
import { a as CodexCliRunOptions, c as CodexEvent, d as CodexItemUpdatedEvent, f as CodexThreadStartedEvent, i as CodexCliPermissionMode, l as CodexItemCompletedEvent, m as CodexTurnFailedEvent, n as CodexCliAgent, o as CodexCliSandboxMode, p as CodexTurnCompletedEvent, r as CodexCliAgentOptions, s as CodexErrorEvent, u as CodexItemStartedEvent } from "./index-BTcDyVsX.mjs";
|
|
8
|
+
import { a as CodexSdkItem, i as CodexSdkEvent, n as CodexSdkAgent, o as CodexSdkPermissionMode, r as CodexSdkAgentOptions, s as CodexSdkRunOptions } from "./index-nx85iU6i.mjs";
|
|
9
|
+
import { a as CursorCliRunOptions, i as CursorCliMode, n as CursorCliAgent, o as CursorCliSandboxMode, r as CursorCliAgentOptions, s as CursorCliEvent } from "./index-Cpz-hhM0.mjs";
|
|
10
|
+
import { a as CursorSdkMcpHttpAuth, c as CursorSdkModelSelection, i as CursorSdkEvent, l as CursorSdkRunOptions, n as CursorSdkAgent, o as CursorSdkMcpServerConfig, r as CursorSdkAgentOptions, s as CursorSdkModelParameterValue, u as CursorSdkSettingSource } from "./index-DM6yXz_N.mjs";
|
|
11
|
+
import { a as GeminiCliRunOptions, i as GeminiCliPermissionMode, n as GeminiCliAgent, o as GeminiEvent, r as GeminiCliAgentOptions } from "./index-CzjmvgZI.mjs";
|
|
12
|
+
import { a as OpencodeEvent, i as OpencodeCliRunOptions, n as OpencodeCliAgent, r as OpencodeCliAgentOptions } from "./index-CK9BK1t2.mjs";
|
|
13
|
+
import { a as PiCliThinkingLevel, i as PiCliRunOptions, n as PiCliAgent, o as PiEvent, r as PiCliAgentOptions } from "./index-BsTS0n1I.mjs";
|
|
83
14
|
//#region src/core/agent/create-agent.d.ts
|
|
84
15
|
declare function createAgent(type: "claude-code-cli", options?: ClaudeCodeCliAgentOptions): Promise<ClaudeCodeCliAgent>;
|
|
85
16
|
declare function createAgent(type: "claude-code-sdk", options?: ClaudeCodeSdkAgentOptions): Promise<ClaudeCodeSdkAgent>;
|
|
86
17
|
declare function createAgent(type: "codex-cli", options?: CodexCliAgentOptions): Promise<CodexCliAgent>;
|
|
87
18
|
declare function createAgent(type: "codex-sdk", options?: CodexSdkAgentOptions): Promise<CodexSdkAgent>;
|
|
88
|
-
declare function createAgent(type: "
|
|
19
|
+
declare function createAgent(type: "cursor-cli", options?: CursorCliAgentOptions): Promise<CursorCliAgent>;
|
|
20
|
+
declare function createAgent(type: "cursor-sdk", options?: CursorSdkAgentOptions): Promise<CursorSdkAgent>;
|
|
89
21
|
declare function createAgent(type: "gemini-cli", options?: GeminiCliAgentOptions): Promise<GeminiCliAgent>;
|
|
90
22
|
declare function createAgent(type: "opencode-cli", options?: OpencodeCliAgentOptions): Promise<OpencodeCliAgent>;
|
|
91
23
|
declare function createAgent(type: "pi-cli", options?: PiCliAgentOptions): Promise<PiCliAgent>;
|
|
92
24
|
//#endregion
|
|
93
|
-
export { type AgentCapabilities, type AgentEvent, type AgentEventHandler, type AgentMetrics, AgentRunError, type AgentType, AgentValidationError, type AnyCompletedRunResult, type AnyRunRequest, type AnyRunResult, type BaseAgent, type BubblewrapSandbox, type BubblewrapSandboxConfig, type CancelledRunResult, type ClaudeAssistantEvent, type ClaudeCodeCliAgent, type ClaudeCodeCliAgentOptions, type ClaudeCodeCliPermissionMode, type ClaudeCodeCliRunOptions, type ClaudeCodeSdkAgent, type ClaudeCodeSdkAgentOptions, type ClaudeCodeSdkEvent, type ClaudeCodeSdkExecutable, type ClaudeCodeSdkPermissionMode, type ClaudeCodeSdkRunOptions, type ClaudeCodeSdkSettingSource, type ClaudeCodeSdkSettings, type ClaudeEvent, type ClaudeRateLimitEvent, type ClaudeResultEvent, type ClaudeSystemEvent, type ClaudeUserEvent, type CodexCliAgent, type CodexCliAgentOptions, type CodexCliPermissionMode, type CodexCliRunOptions, type CodexCliSandboxMode, type CodexErrorEvent, type CodexEvent, type CodexItemCompletedEvent, type CodexItemStartedEvent, type CodexItemUpdatedEvent, type CodexSdkAgent, type CodexSdkAgentOptions, type CodexSdkEvent, type CodexSdkItem, type CodexSdkPermissionMode, type CodexSdkRunOptions, type CodexThreadStartedEvent, type CodexTurnCompletedEvent, type CodexTurnFailedEvent, type CompletedRunResult, type Container, type ContainerBase, type 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 ContentPart, type
|
|
25
|
+
export { type AgentCapabilities, type AgentEvent, type AgentEventHandler, type AgentMetrics, AgentRunError, type AgentType, AgentValidationError, type AnyCompletedRunResult, type AnyRunRequest, type AnyRunResult, type BaseAgent, type BubblewrapSandbox, type BubblewrapSandboxConfig, type CancelledRunResult, type ClaudeAssistantEvent, type ClaudeCodeCliAgent, type ClaudeCodeCliAgentOptions, type ClaudeCodeCliPermissionMode, type ClaudeCodeCliRunOptions, type ClaudeCodeSdkAgent, type ClaudeCodeSdkAgentOptions, type ClaudeCodeSdkEvent, type ClaudeCodeSdkExecutable, type ClaudeCodeSdkPermissionMode, type ClaudeCodeSdkRunOptions, type ClaudeCodeSdkSettingSource, type ClaudeCodeSdkSettings, type ClaudeEvent, type ClaudeRateLimitEvent, type ClaudeResultEvent, type ClaudeSystemEvent, type ClaudeUserEvent, type CodexCliAgent, type CodexCliAgentOptions, type CodexCliPermissionMode, type CodexCliRunOptions, type CodexCliSandboxMode, type CodexErrorEvent, type CodexEvent, type CodexItemCompletedEvent, type CodexItemStartedEvent, type CodexItemUpdatedEvent, type CodexSdkAgent, type CodexSdkAgentOptions, type CodexSdkEvent, type CodexSdkItem, type CodexSdkPermissionMode, type CodexSdkRunOptions, type CodexThreadStartedEvent, type CodexTurnCompletedEvent, type CodexTurnFailedEvent, type CompletedRunResult, type Container, type ContainerBase, type 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 ContentPart, type CursorCliAgent, type CursorCliAgentOptions, type CursorCliEvent, type CursorCliMode, type CursorCliRunOptions, type CursorCliSandboxMode, type CursorSdkAgent, type CursorSdkAgentOptions, type CursorSdkEvent, type CursorSdkMcpHttpAuth, type CursorSdkMcpServerConfig, type CursorSdkModelParameterValue, type CursorSdkModelSelection, type CursorSdkRunOptions, type CursorSdkSettingSource, 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 EnsureDisjoint, type ExecOptions, type ExecResult, type FailedRunResult, type FirejailSandbox, type FirejailSandboxConfig, type GeminiCliAgent, type GeminiCliAgentOptions, type GeminiCliPermissionMode, type GeminiCliRunOptions, type GeminiEvent, type ImageContentPart, type JsonSchema, type JsonSchemaRunRequest, type McpServerConfig, type MessageEvent, type NerdctlBuildBase, type NerdctlBuildConfig, type NerdctlContainer, type NerdctlContainerBase, type NerdctlContainerConfig, type NerdctlProviderBase, type NerdctlProviderConfig, type NsjailSandbox, type NsjailSandboxConfig, type OpencodeCliAgent, type OpencodeCliAgentOptions, type OpencodeCliRunOptions, type OpencodeEvent, type OutputSchema, type PiCliAgent, type PiCliAgentOptions, type PiCliRunOptions, type PiCliThinkingLevel, type PiEvent, type PodmanBuildBase, type PodmanBuildConfig, type PodmanContainer, type PodmanContainerBase, type PodmanContainerConfig, type PodmanProviderConfig, type PortMapping, type ReasoningEvent, type RunError, type RunProcessInfo, type RunRequest, type RunResult, type RunResultBase, type RunStats, type RunStatus, type RunTiming, type Sandbox, type SandboxBase, type SandboxConfig, type SandboxConfigBase, type SandboxExecution, type SandboxIdentity, type SandboxLifecycle, type SandboxStatus, type SandboxType, type SessionEndEvent, type SessionStartEvent, type StderrEvent, type StopReason, type StructuredRunRequest, type TextContentPart, type ToolCallEvent, type ToolResultEvent, type VolumeMount, type WorkdirChangeKind, type WorkdirDiff, type WorkdirDiffStats, type WorkdirFileChange, type WorkdirSnapshot, type WorkdirSnapshotOptions, type ZodRunRequest, agentCapabilitiesSchema, createAgent, createContainer, createSandbox, eventSchema };
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e,t}from"./types-CwvWHEpy.mjs";import{a as n,i as r,n as i,o as a,r as o,s,t as c}from"./errors-XV0frS3r.mjs";import{createContainer as l}from"./container/index.mjs";import{t as u}from"./sandbox-_As0qZWn.mjs";import{n as d,u as f}from"./schemas-CXVWDOoT.mjs";const p=(e,t)=>{if(!(e instanceof Error)||!e.message.includes(t))return!1;let n=typeof e==`object`&&e&&`code`in e?e.code:void 0;return n===`ERR_MODULE_NOT_FOUND`||n===`MODULE_NOT_FOUND`},m=(t,n,r)=>{throw p(r,n)?new e(`Agent type "${t}" requires the optional peer dependency "${n}". Install it to use this adapter.`):r};async function h(t,n){switch(t){case`claude-code-cli`:{let{createClaudeCodeCliAgent:e}=await import(`./adapters/claude-code-cli/index.mjs`);return e(n)}case`claude-code-sdk`:{let e=n;try{let{createClaudeCodeSdkAgent:t}=await import(`./adapters/claude-code-sdk/index.mjs`);return t(e)}catch(e){return m(`claude-code-sdk`,`@anthropic-ai/claude-agent-sdk`,e)}}case`codex-cli`:{let{createCodexCliAgent:e}=await import(`./adapters/codex-cli/index.mjs`);return e(n)}case`codex-sdk`:{let e=n;try{let{createCodexSdkAgent:t}=await import(`./adapters/codex-sdk/index.mjs`);return t(e)}catch(e){return m(`codex-sdk`,`@openai/codex-sdk`,e)}}case`
|
|
1
|
+
import{n as e,t}from"./types-CwvWHEpy.mjs";import{a as n,i as r,n as i,o as a,r as o,s,t as c}from"./errors-XV0frS3r.mjs";import{createContainer as l}from"./container/index.mjs";import{t as u}from"./sandbox-_As0qZWn.mjs";import{n as d,u as f}from"./schemas-CXVWDOoT.mjs";const p=(e,t)=>{if(!(e instanceof Error)||!e.message.includes(t))return!1;let n=typeof e==`object`&&e&&`code`in e?e.code:void 0;return n===`ERR_MODULE_NOT_FOUND`||n===`MODULE_NOT_FOUND`},m=(t,n,r)=>{throw p(r,n)?new e(`Agent type "${t}" requires the optional peer dependency "${n}". Install it to use this adapter.`):r};async function h(t,n){switch(t){case`claude-code-cli`:{let{createClaudeCodeCliAgent:e}=await import(`./adapters/claude-code-cli/index.mjs`);return e(n)}case`claude-code-sdk`:{let e=n;try{let{createClaudeCodeSdkAgent:t}=await import(`./adapters/claude-code-sdk/index.mjs`);return t(e)}catch(e){return m(`claude-code-sdk`,`@anthropic-ai/claude-agent-sdk`,e)}}case`codex-cli`:{let{createCodexCliAgent:e}=await import(`./adapters/codex-cli/index.mjs`);return e(n)}case`codex-sdk`:{let e=n;try{let{createCodexSdkAgent:t}=await import(`./adapters/codex-sdk/index.mjs`);return t(e)}catch(e){return m(`codex-sdk`,`@openai/codex-sdk`,e)}}case`cursor-cli`:{let{createCursorCliAgent:e}=await import(`./adapters/cursor-cli/index.mjs`);return e(n)}case`cursor-sdk`:{let e=n;try{let{createCursorSdkAgent:t}=await import(`./adapters/cursor-sdk/index.mjs`);return t(e)}catch(e){return m(`cursor-sdk`,`@cursor/sdk`,e)}}case`gemini-cli`:{let{createGeminiCliAgent:e}=await import(`./adapters/gemini-cli/index.mjs`);return e(n)}case`opencode-cli`:{let{createOpencodeCliAgent:e}=await import(`./adapters/opencode-cli/index.mjs`);return e(n)}case`pi-cli`:{let{createPiCliAgent:e}=await import(`./adapters/pi-cli/index.mjs`);return e(n)}default:throw new e(`Unsupported agent type.`)}}export{t as AgentRunError,e as AgentValidationError,c as ContainerCreateError,i as ContainerDiffError,o as ContainerDisposedError,r as ContainerError,n as ContainerExecError,a as ContainerNotRunningError,s as ContainerStartError,f as agentCapabilitiesSchema,h as createAgent,l as createContainer,u as createSandbox,d as eventSchema};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./util-CGg8cK92.mjs";import{a as t,n,o as r,r as i,s as a,t as o}from"./errors-XV0frS3r.mjs";import{n as s}from"./env-DIXTVzTs.mjs";import{t as c}from"./spawner-BJesLc8I.mjs";import{t as l}from"./shell-Dewbmt9R.mjs";import{n as u,r as d,t as f}from"./diff-
|
|
1
|
+
import{t as e}from"./util-CGg8cK92.mjs";import{a as t,n,o as r,r as i,s as a,t as o}from"./errors-XV0frS3r.mjs";import{n as s}from"./env-DIXTVzTs.mjs";import{t as c}from"./spawner-BJesLc8I.mjs";import{t as l}from"./shell-Dewbmt9R.mjs";import{n as u,r as d,t as f}from"./diff-DkMPJCxL.mjs";import{execFile as p}from"node:child_process";import{isAbsolute as m,join as h,posix as g}from"node:path";import{promisify as _}from"node:util";import{tmpdir as v}from"node:os";import{mkdtemp as y,rm as b,writeFile as x}from"node:fs/promises";import{randomBytes as S}from"node:crypto";const C=(e,t)=>{let n=g.relative(e,t);return n===``||!n.startsWith(`..`)&&!g.isAbsolute(n)},w=(e,t)=>{if(!e||e.length===0)return;let n=g.normalize(t),r;for(let t of e){if(!m(t.source))continue;let e=g.normalize(t.target);C(e,n)&&(!r||e.length>g.normalize(r.target).length)&&(r=t)}if(!r)return;let i=g.relative(g.normalize(r.target),n);return i===``?r.source:h(r.source,...i.split(`/`))},T=_(p),E=()=>`cw-${S(6).toString(`hex`)}`,D=(e,t)=>e.baseArgs?[...e.baseArgs,...t]:t,O=e=>{if(e.env)return{...s(),...e.env}},k=async(e,t,n)=>{let r=await T(e.binary,D(e,t),{encoding:`utf8`,env:O(e),timeout:n?.timeoutMs,signal:n?.signal,maxBuffer:50*1024*1024});return{stdout:r.stdout,stderr:r.stderr}},A=async(t,n)=>{let r=n.tag??`cw-build-${S(4).toString(`hex`)}`,i=[`build`,`-t`,r];if(n.args)for(let[e,t]of Object.entries(n.args))i.push(`--build-arg`,`${e}=${t}`);`dockerfile`in n&&n.dockerfile&&(i.push(`-f`,n.dockerfile),i.push(n.context??`.`));let a;if(`content`in n&&n.content){a=await y(h(v(),`cw-oci-build-`));let e=h(a,`Dockerfile`);await x(e,n.content,{encoding:`utf8`,mode:384}),i.push(`-f`,e),i.push(n.context??a)}try{await k(t,i)}catch(t){throw new o(`Image build failed: ${e(t)}`)}finally{a&&await b(a,{recursive:!0,force:!0}).catch(()=>{})}return r},j=async(e,t,n)=>{let r=await Promise.all(n.map(async n=>{try{let{container:r,protocol:i=`tcp`}=n,{stdout:a}=await k(e,[`port`,t,`${r}/${i}`]),o=/:(\d+)$/m.exec(a.trim());if(o?.[1])return[r,Number(o[1])]}catch{}})),i=new Map;for(let e of r)e&&i.set(e[0],e[1]);return i},M=(e,t)=>({spawn:(n,r,i={})=>{let a=[`exec`,`-i`];if(i.cwd&&a.push(`-w`,i.cwd),i.env)for(let[e,t]of Object.entries(i.env))a.push(`-e`,`${e}=${t}`);return a.push(e,n,...r),c.spawn(t.binary,D(t,a),{env:O(t),stdio:i.stdio})}}),N=async(s,p,m)=>{let{commandContext:h,builtImage:_,containerName:v,workdir:y,user:b,network:x,platform:S,env:C,ports:T,mounts:A,extraArgs:N,image:P}=p,F=v??E(),I=[`create`,`--name`,F];if(b&&I.push(`--user`,b),x&&I.push(`--network`,x),S&&I.push(`--platform`,S),C)for(let[e,t]of Object.entries(C))I.push(`-e`,`${e}=${t}`);if(T)for(let e of T){let{host:t,container:n,protocol:r=`tcp`}=e;I.push(`-p`,`${t??``}:${n}/${r}`)}if(A)for(let e of A){let{readonly:t,source:n,target:r}=e,i=t?`ro`:`rw`;I.push(`-v`,`${n}:${r}:${i}`)}N&&I.push(...N),I.push(P,`sleep`,`infinity`);let L;try{let{stdout:e}=await k(h,I);L=e.trim()}catch(t){throw new o(`Container create failed: ${e(t)}`)}let R=`created`,z=new Map,B=()=>{if(R===`disposed`)throw new i},V=()=>{if(B(),R!==`running`)throw new r},H=M(L,h),U=u({owner:{},workdir:y,materialize:async(t,r)=>{B();let i=w(A,t);if(i){await f(i,r);return}V();try{await k(h,[`exec`,L,`sh`,`-c`,`test -d ${l(t)}`])}catch{throw new n(`Target path is not a directory: ${t}`)}try{await k(h,[`cp`,`${L}:${t}/.`,r])}catch(r){throw new n(`Failed to materialize container path ${t}: ${e(r)}`)}}}),W={get type(){return s},get id(){return L},get name(){return F},get config(){return m},get status(){return R},get workdir(){return y},get spawner(){return H},async start(){if(B(),R!==`running`){try{await k(h,[`start`,L])}catch(t){throw new a(`Container start failed: ${e(t)}`)}try{await k(h,[`exec`,L,`mkdir`,`-p`,y])}catch(t){try{await k(h,[`stop`,`-t`,`0`,L]),R=`stopped`}catch{try{let{stdout:e}=await k(h,[`inspect`,`--format`,`{{.State.Status}}`,L]);R=e.trim()===`running`?`running`:`stopped`}catch{R=`disposed`}}throw new a(`Container start failed: ${e(t)}`)}R=`running`,T?.length&&(z=await j(h,L,T))}},async stop(){if(B(),R===`running`){try{await k(h,[`stop`,`-t`,`2`,L])}catch{try{let{stdout:e}=await k(h,[`inspect`,`--format`,`{{.State.Status}}`,L]);if(e.trim()===`running`)return}catch{R=`disposed`;return}}R=`stopped`}},async dispose(){if(R!==`disposed`){try{await k(h,[`stop`,`-t`,`0`,L])}catch{}try{await k(h,[`rm`,`-f`,L])}catch{}_&&await k(h,[`rmi`,P]).catch(()=>{}),await U.disposeSnapshots().catch(()=>{}),R=`disposed`}},async exec(e,t,n={}){V();let r=[`exec`];if(n.cwd&&r.push(`-w`,n.cwd),n.env)for(let[e,t]of Object.entries(n.env))r.push(`-e`,`${e}=${t}`);r.push(L,e,...t);try{let{stdout:e,stderr:t}=await k(h,r,{timeoutMs:n.timeoutMs,signal:n.signal});return{exitCode:0,stdout:e,stderr:t}}catch(e){if(d(e))return{exitCode:typeof e.code==`number`?e.code:-1,stdout:String(e.stdout??``),stderr:String(e.stderr??``)};throw e}},async copyTo(e,t){V(),await k(h,[`cp`,e,`${L}:${t}`])},async copyFrom(e,t){V(),await k(h,[`cp`,`${L}:${e}`,t])},async writeFile(e,n){V();let r=g.isAbsolute(e)?e:g.resolve(y,e),i=g.dirname(r),a=typeof n==`string`?Buffer.from(n,`utf8`):n,o=[`exec`,`-i`];b&&o.push(`--user`,b),o.push(L,`sh`,`-c`,`mkdir -p ${l(i)} && cat > ${l(r)}`);let s=c.spawn(h.binary,D(h,o),{env:O(h),stdio:[`pipe`,`ignore`,`ignore`]});s.stdin?.write?.(a),s.stdin?.end();let u=await s.wait();if(u.exitCode!==0)throw new t(`writeFile failed for ${r} (exit ${u.exitCode})`)},async readFile(e){V();let t=g.isAbsolute(e)?e:g.resolve(y,e),{stdout:n}=await k(h,[`exec`,L,`cat`,t]);return n},async fileExists(e){V();let t=g.isAbsolute(e)?e:g.resolve(y,e);try{return await k(h,[`exec`,L,`test`,`-e`,t]),!0}catch{return!1}},async mkdir(e){V();let t=g.isAbsolute(e)?e:g.resolve(y,e);await k(h,[`exec`,L,`mkdir`,`-p`,t])},async execShell(e,t={}){return W.exec(`sh`,[`-c`,e],t)},async logs(e={}){B();let t=[`logs`];e.tail!==void 0&&t.push(`--tail`,String(e.tail)),t.push(L);let{stdout:n}=await k(h,t);return n},async syncStatus(){B();try{let{stdout:e}=await k(h,[`inspect`,`--format`,`{{.State.Status}}`,L]),t=e.trim();R=t===`running`?`running`:t===`created`?`created`:`stopped`}catch{R=`disposed`}return R},async snapshotWorkdir(e={}){return U.snapshotWorkdir(e)},async diffWorkdir(e){return U.diffWorkdir(e)},async releaseWorkdirSnapshot(e){return U.releaseWorkdirSnapshot(e)},getMappedPort(e){return z.get(e)},[Symbol.asyncDispose](){return W.dispose()}};return W},P=async(e,t)=>{if(t.image)return t.image;if(t.build)return A(e,t.build);throw new o(`Either image or build must be provided.`)};export{P as n,N as t};
|
package/dist/sandbox/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as FirejailSandboxConfig, c as Sandbox, d as SandboxConfigBase, f as SandboxExecution, g as SandboxType, h as SandboxStatus, i as FirejailSandbox, l as SandboxBase, m as SandboxLifecycle, n as BubblewrapSandbox, o as NsjailSandbox, p as SandboxIdentity, r as BubblewrapSandboxConfig, s as NsjailSandboxConfig, t as createSandbox, u as SandboxConfig } from "../index-
|
|
1
|
+
import { a as FirejailSandboxConfig, c as Sandbox, d as SandboxConfigBase, f as SandboxExecution, g as SandboxType, h as SandboxStatus, i as FirejailSandbox, l as SandboxBase, m as SandboxLifecycle, n as BubblewrapSandbox, o as NsjailSandbox, p as SandboxIdentity, r as BubblewrapSandboxConfig, s as NsjailSandboxConfig, t as createSandbox, u as SandboxConfig } from "../index-BsWb681o.mjs";
|
|
2
2
|
export { BubblewrapSandbox, BubblewrapSandboxConfig, FirejailSandbox, FirejailSandboxConfig, NsjailSandbox, NsjailSandboxConfig, Sandbox, SandboxBase, SandboxConfig, SandboxConfigBase, SandboxExecution, SandboxIdentity, SandboxLifecycle, SandboxStatus, SandboxType, createSandbox };
|
package/dist/schemas/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { C as OutputSchema, D as imageContentPartSchema, E as contentPartSchema, O as textContentPartSchema, S as McpServerConfig, T as agentCapabilitiesSchema, _ as toolResultEventSchema, a as SessionStartEvent, b as ImageContentPart, c as ToolResultEvent, d as messageEventSchema, f as reasoningEventSchema, g as toolCallEventSchema, h as stderrEventSchema, i as SessionEndEvent, l as baseEventSchema, m as sessionStartEventSchema, n as MessageEvent, o as StderrEvent, p as sessionEndEventSchema, r as ReasoningEvent, s as ToolCallEvent, t as AgentEvent, u as eventSchema, v as AgentCapabilities, w as TextContentPart, x as JsonSchema, y as ContentPart } from "../events-
|
|
1
|
+
import { C as OutputSchema, D as imageContentPartSchema, E as contentPartSchema, O as textContentPartSchema, S as McpServerConfig, T as agentCapabilitiesSchema, _ as toolResultEventSchema, a as SessionStartEvent, b as ImageContentPart, c as ToolResultEvent, d as messageEventSchema, f as reasoningEventSchema, g as toolCallEventSchema, h as stderrEventSchema, i as SessionEndEvent, l as baseEventSchema, m as sessionStartEventSchema, n as MessageEvent, o as StderrEvent, p as sessionEndEventSchema, r as ReasoningEvent, s as ToolCallEvent, t as AgentEvent, u as eventSchema, v as AgentCapabilities, w as TextContentPart, x as JsonSchema, y as ContentPart } from "../events-BE9s04ko.mjs";
|
|
2
2
|
export { type AgentCapabilities, type AgentEvent, type ContentPart, type ImageContentPart, type JsonSchema, type McpServerConfig, type MessageEvent, type OutputSchema, type ReasoningEvent, type SessionEndEvent, type SessionStartEvent, type StderrEvent, type TextContentPart, type ToolCallEvent, type ToolResultEvent, agentCapabilitiesSchema, baseEventSchema, contentPartSchema, eventSchema, imageContentPartSchema, messageEventSchema, reasoningEventSchema, sessionEndEventSchema, sessionStartEventSchema, stderrEventSchema, textContentPartSchema, toolCallEventSchema, toolResultEventSchema };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as AgentEvent, v as AgentCapabilities, x as JsonSchema, y as ContentPart } from "./events-
|
|
1
|
+
import { t as AgentEvent, v as AgentCapabilities, x as JsonSchema, y as ContentPart } from "./events-BE9s04ko.mjs";
|
|
2
2
|
import { ZodType } from "zod/v4";
|
|
3
3
|
|
|
4
4
|
//#region src/core/process/types.d.ts
|
|
@@ -28,7 +28,7 @@ interface ProcessSpawner {
|
|
|
28
28
|
}
|
|
29
29
|
//#endregion
|
|
30
30
|
//#region src/core/agent/types.d.ts
|
|
31
|
-
type AgentType = "claude-code-cli" | "claude-code-sdk" | "codex-cli" | "codex-sdk" | "
|
|
31
|
+
type AgentType = "claude-code-cli" | "claude-code-sdk" | "codex-cli" | "codex-sdk" | "cursor-cli" | "cursor-sdk" | "gemini-cli" | "opencode-cli" | "pi-cli";
|
|
32
32
|
type RunStatus = "cancelled" | "completed" | "failed";
|
|
33
33
|
type StopReason = "abort" | "timeout" | "user";
|
|
34
34
|
interface RunStats {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "coding-agents-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"types": "./dist/index.d.mts",
|
|
6
6
|
"exports": {
|
|
@@ -36,9 +36,13 @@
|
|
|
36
36
|
"types": "./dist/adapters/codex-sdk/index.d.mts",
|
|
37
37
|
"default": "./dist/adapters/codex-sdk/index.mjs"
|
|
38
38
|
},
|
|
39
|
-
"./adapters/
|
|
40
|
-
"types": "./dist/adapters/
|
|
41
|
-
"default": "./dist/adapters/
|
|
39
|
+
"./adapters/cursor-cli": {
|
|
40
|
+
"types": "./dist/adapters/cursor-cli/index.d.mts",
|
|
41
|
+
"default": "./dist/adapters/cursor-cli/index.mjs"
|
|
42
|
+
},
|
|
43
|
+
"./adapters/cursor-sdk": {
|
|
44
|
+
"types": "./dist/adapters/cursor-sdk/index.d.mts",
|
|
45
|
+
"default": "./dist/adapters/cursor-sdk/index.mjs"
|
|
42
46
|
},
|
|
43
47
|
"./adapters/gemini-cli": {
|
|
44
48
|
"types": "./dist/adapters/gemini-cli/index.d.mts",
|
|
@@ -70,7 +74,8 @@
|
|
|
70
74
|
"test:agent:claude-code-sdk": "CODE_WORKFLOW_TEST_AGENTS=claude-code-sdk bun run test:agent",
|
|
71
75
|
"test:agent:codex-cli": "CODE_WORKFLOW_TEST_AGENTS=codex-cli bun run test:agent",
|
|
72
76
|
"test:agent:codex-sdk": "CODE_WORKFLOW_TEST_AGENTS=codex-sdk bun run test:agent",
|
|
73
|
-
"test:agent:
|
|
77
|
+
"test:agent:cursor-cli": "CODE_WORKFLOW_TEST_AGENTS=cursor-cli bun run test:agent",
|
|
78
|
+
"test:agent:cursor-sdk": "CODE_WORKFLOW_TEST_AGENTS=cursor-sdk bun run test:agent",
|
|
74
79
|
"test:agent:gemini-cli": "CODE_WORKFLOW_TEST_AGENTS=gemini-cli bun run test:agent",
|
|
75
80
|
"test:agent:opencode-cli": "CODE_WORKFLOW_TEST_AGENTS=opencode-cli bun run test:agent",
|
|
76
81
|
"test:agent:pi-cli": "CODE_WORKFLOW_TEST_AGENTS=pi-cli bun run test:agent",
|
|
@@ -79,25 +84,30 @@
|
|
|
79
84
|
"typecheck": "bun run tsc"
|
|
80
85
|
},
|
|
81
86
|
"devDependencies": {
|
|
82
|
-
"@anthropic-ai/claude-agent-sdk": "^0.2.
|
|
83
|
-
"@
|
|
84
|
-
"@
|
|
87
|
+
"@anthropic-ai/claude-agent-sdk": "^0.2.119",
|
|
88
|
+
"@cursor/sdk": "^1.0.7",
|
|
89
|
+
"@openai/codex-sdk": "^0.125.0",
|
|
90
|
+
"@types/bun": "^1.3.13",
|
|
85
91
|
"@types/node": "^25.6.0",
|
|
86
|
-
"e2b": "^2.19.
|
|
87
|
-
"knip": "^6.
|
|
92
|
+
"e2b": "^2.19.1",
|
|
93
|
+
"knip": "^6.7.0",
|
|
88
94
|
"picoprint": "^2.0.0",
|
|
89
|
-
"tsdown": "^0.21.
|
|
95
|
+
"tsdown": "^0.21.10"
|
|
90
96
|
},
|
|
91
97
|
"peerDependencies": {
|
|
92
|
-
"@anthropic-ai/claude-agent-sdk": "^0.2.
|
|
93
|
-
"@
|
|
94
|
-
"
|
|
95
|
-
"
|
|
98
|
+
"@anthropic-ai/claude-agent-sdk": "^0.2.119",
|
|
99
|
+
"@cursor/sdk": "^1.0.7",
|
|
100
|
+
"@openai/codex-sdk": "^0.125.0",
|
|
101
|
+
"e2b": "^2.19.1",
|
|
102
|
+
"typescript": "^6.0.3"
|
|
96
103
|
},
|
|
97
104
|
"peerDependenciesMeta": {
|
|
98
105
|
"@anthropic-ai/claude-agent-sdk": {
|
|
99
106
|
"optional": true
|
|
100
107
|
},
|
|
108
|
+
"@cursor/sdk": {
|
|
109
|
+
"optional": true
|
|
110
|
+
},
|
|
101
111
|
"@openai/codex-sdk": {
|
|
102
112
|
"optional": true
|
|
103
113
|
},
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import { a as DroidCliReasoningEffort, i as DroidCliAutonomyLevel, n as DroidCliAgent, o as DroidCliRunOptions, r as DroidCliAgentOptions, s as DroidEvent, t as createDroidCliAgent } from "../../index-PVFQgWRb.mjs";
|
|
2
|
-
export { DroidCliAgent, DroidCliAgentOptions, DroidCliAutonomyLevel, DroidCliReasoningEffort, DroidCliRunOptions, DroidEvent, createDroidCliAgent };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as e,n as t}from"../../util-CGg8cK92.mjs";import{a as n,c as r,o as i,s as a}from"../../classify-error-DoH0BqEA.mjs";import{n as o,t as s}from"../../execution-target-DjI5SnsB.mjs";import{z as c}from"zod/v4";const l=e=>typeof e==`string`?e:void 0,u=e=>typeof e==`number`&&Number.isFinite(e)?e:void 0,d=()=>crypto.randomUUID(),f=e=>l(e.session_id)??l(e.sessionId),p=(e,t)=>({events:[],sessionId:f(e)??void 0}),m=(e,t,i)=>{let a=l(e.role)??`assistant`,o=l(e.text)??``;return o.trim()?a===`assistant`?{events:[n(t.runId,`message`,{sessionId:t.sessionId,model:i??null,role:`assistant`,content:[r(o)],text:o})]}:a===`user`?{events:[n(t.runId,`message`,{sessionId:t.sessionId,model:null,role:`user`,content:[r(o)],text:o})]}:{events:[]}:{events:[]}},h=(e,r,i)=>{let a=l(e.id)??d(),o=l(e.toolName)??l(e.tool_name)??`tool`,s=t(e.parameters)?e.parameters:{};return{events:[n(r.runId,`tool-call`,{sessionId:r.sessionId,model:i??null,toolCallId:a,toolName:o,input:s})],toolCalls:[{toolCallId:a,toolName:o,input:s}]}},g=(e,t)=>{let r=l(e.id)??d(),i=!!e.isError||!!e.is_error,a=e.value??e.output??e.result??``,o=typeof a==`string`?a:JSON.stringify(a),s=t.toolCalls.get(r);return{events:[n(t.runId,`tool-result`,{sessionId:t.sessionId,toolCallId:r,toolName:s?.toolName,input:s?.input,output:o,isError:i||void 0,error:i?o:void 0})]}},_=(e,t)=>{let n=l(e.finalText)??l(e.result)??l(e.text),r=u(e.durationMs)??u(e.duration_ms)??0,i={durationMs:r,apiDurationMs:r,turns:u(e.numTurns)??u(e.num_turns)??1,costUsd:0},a=f(e),o={stats:i,status:`completed`};return n!==void 0&&(o.output={text:n}),{events:[],sessionId:a??void 0,state:o}},v=(e,t)=>{let r=l(e.message)??l(e.error)??l(e.text)??`droid emitted an error event.`;return{events:[n(t.runId,`stderr`,{sessionId:t.sessionId,text:r})]}},y=(e,t,n)=>{let r=e;switch(l(r.type)??``){case`system`:return p(r,t);case`message`:return m(r,t,n);case`tool_call`:return h(r,t,n);case`tool_result`:return g(r,t);case`completion`:return _(r,t);case`error`:return v(r,t);default:return{events:[]}}},b=i(c.object({type:c.string()}).passthrough()),x={structuredOutput:!1,sessionResume:!0,imageInput:!1,mcp:!1,eventStreaming:!0};var S=class extends o{type=`droid-cli`;creationOptions;runDefaults;runModels=new Map;runTextBuffers=new Map;constructor(t={}){super({type:`droid-cli`,capabilities:x,defaults:{cwd:t.cwd,env:t.env,command:e(t.command??`droid`),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={autonomyLevel:t.autonomyLevel,enabledTools:t.enabledTools?[...t.enabledTools]:void 0,disabledTools:t.disabledTools?[...t.disabledTools]:void 0,reasoningEffort:t.reasoningEffort,specModel:t.specModel,specReasoningEffort:t.specReasoningEffort,useSpec:t.useSpec,skipPermissionsUnsafe:t.skipPermissionsUnsafe,tags:t.tags?[...t.tags]:void 0,logGroupId:t.logGroupId,extraArgs:t.extraArgs?[...t.extraArgs]:void 0}}buildArgs(e,t){let n=[`exec`,`--output-format`,`stream-json`],r=e.autonomyLevel??this.runDefaults.autonomyLevel,i=e.enabledTools??this.runDefaults.enabledTools,o=e.disabledTools??this.runDefaults.disabledTools,s=e.reasoningEffort??this.runDefaults.reasoningEffort,c=e.specModel??this.runDefaults.specModel,l=e.specReasoningEffort??this.runDefaults.specReasoningEffort,u=e.useSpec??this.runDefaults.useSpec,d=e.skipPermissionsUnsafe??this.runDefaults.skipPermissionsUnsafe,f=e.tags??this.runDefaults.tags,p=e.logGroupId??this.runDefaults.logGroupId,m=e.extraArgs??this.runDefaults.extraArgs;if(this.runModels.set(t.runId,e.model),e.model&&n.push(`--model`,e.model),r&&n.push(`--auto`,r),s&&n.push(`--reasoning-effort`,s),u&&n.push(`--use-spec`),c&&n.push(`--spec-model`,c),l&&n.push(`--spec-reasoning-effort`,l),d&&n.push(`--skip-permissions-unsafe`),i&&i.length>0&&n.push(`--enabled-tools`,i.join(`,`)),o&&o.length>0&&n.push(`--disabled-tools`,o.join(`,`)),f&&f.length>0)for(let e of f)n.push(`--tag`,e);p&&n.push(`--log-group-id`,p),t.requestedSessionId&&n.push(`--session-id`,t.requestedSessionId),m&&m.length>0&&n.push(...m);let h=a(e.input);return h.trim().startsWith(`-`)?n.push(`--`,h):n.push(h),n}buildEnv(e,t){return this.buildDefaultEnv(this.creationOptions.propagateEnv)}mapRawEvent(e,t){this.appendRawLog(e);let n=b(e);if(!n)return this.onParseError(JSON.stringify(e).slice(0,200),Error(`schema validation failed`)),{events:[]};let r=f(n)??t.sessionId,i=y(n,{...t,sessionId:r},this.runModels.get(t.runId));r&&i.sessionId===void 0&&(i.sessionId=r);let a;for(let e of i.events){if(e.type!==`message`||e.role!==`assistant`||!e.text)continue;let n=`${this.runTextBuffers.get(t.runId)??``}${e.text}`;this.runTextBuffers.set(t.runId,n),a=n}return n.type===`completion`&&i.state?.output?.text!==void 0?this.runTextBuffers.set(t.runId,i.state.output.text):a!==void 0&&(i.state={...i.state,output:{...i.state?.output,text:a}}),i}async onRunFinished(e){await super.onRunFinished(e),this.runModels.delete(e.runId),this.runTextBuffers.delete(e.runId)}};const C=e=>new S(s(e).options);export{C as createDroidCliAgent};
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { D as ProcessSpawner, f as EnsureDisjoint, l as BaseAgent, p as ExclusiveExecutionTargetOptions, t as AgentEventHandler } from "./types-BeoSSi-l.mjs";
|
|
2
|
-
import { t as Container } from "./index-Bg_PhFYu.mjs";
|
|
3
|
-
import { c as Sandbox } from "./index-Chdt3rB6.mjs";
|
|
4
|
-
import { z } from "zod/v4";
|
|
5
|
-
|
|
6
|
-
//#region src/adapters/droid-cli/events/schemas.d.ts
|
|
7
|
-
declare const droidEventSchema: z.ZodObject<{
|
|
8
|
-
type: z.ZodString;
|
|
9
|
-
}, z.core.$loose>;
|
|
10
|
-
type DroidEvent = z.infer<typeof droidEventSchema>;
|
|
11
|
-
//#endregion
|
|
12
|
-
//#region src/adapters/droid-cli/types.d.ts
|
|
13
|
-
type DroidCliAutonomyLevel = "high" | "low" | "medium";
|
|
14
|
-
type DroidCliReasoningEffort = "high" | "low" | "medium" | "none" | "off";
|
|
15
|
-
interface DroidCliRunOptions {
|
|
16
|
-
autonomyLevel?: DroidCliAutonomyLevel;
|
|
17
|
-
enabledTools?: string[];
|
|
18
|
-
disabledTools?: string[];
|
|
19
|
-
reasoningEffort?: DroidCliReasoningEffort;
|
|
20
|
-
specModel?: string;
|
|
21
|
-
specReasoningEffort?: DroidCliReasoningEffort;
|
|
22
|
-
useSpec?: boolean;
|
|
23
|
-
skipPermissionsUnsafe?: boolean;
|
|
24
|
-
tags?: string[];
|
|
25
|
-
logGroupId?: string;
|
|
26
|
-
extraArgs?: string[];
|
|
27
|
-
systemPrompt?: never;
|
|
28
|
-
}
|
|
29
|
-
type DroidCliAgentOptions = DroidCliRunOptions & ExclusiveExecutionTargetOptions<Container, Sandbox> & {
|
|
30
|
-
command?: string[] | string;
|
|
31
|
-
cwd?: string;
|
|
32
|
-
env?: Record<string, string>;
|
|
33
|
-
propagateEnv?: boolean;
|
|
34
|
-
sessionId?: string;
|
|
35
|
-
model?: string;
|
|
36
|
-
logPath?: string;
|
|
37
|
-
spawner?: ProcessSpawner;
|
|
38
|
-
onEvent?: AgentEventHandler;
|
|
39
|
-
};
|
|
40
|
-
interface DroidCliAgent extends BaseAgent<EnsureDisjoint<DroidCliRunOptions>> {
|
|
41
|
-
readonly type: "droid-cli";
|
|
42
|
-
}
|
|
43
|
-
//#endregion
|
|
44
|
-
//#region src/adapters/droid-cli/adapter.d.ts
|
|
45
|
-
declare const createDroidCliAgent: (options?: DroidCliAgentOptions) => DroidCliAgent;
|
|
46
|
-
//#endregion
|
|
47
|
-
export { DroidCliReasoningEffort as a, DroidCliAutonomyLevel as i, DroidCliAgent as n, DroidCliRunOptions as o, DroidCliAgentOptions as r, DroidEvent as s, createDroidCliAgent as t };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as e,i as t,n}from"./util-CGg8cK92.mjs";import{a as r,c as i,o as a,s as o}from"./classify-error-DoH0BqEA.mjs";import{n as s,t as c}from"./execution-target-DjI5SnsB.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 a=u((n(e.part)?e.part:void 0)?.text)??``;return a.trim()?{events:[r(t.runId,`message`,{sessionId:t.sessionId,model:null,role:`assistant`,content:[i(a)],text:a})]}:{events:[]}},_=(e,t)=>{let a=u((n(e.part)?e.part:void 0)?.text)??``;return a.trim()?{events:[r(t.runId,`reasoning`,{sessionId:t.sessionId,model:null,content:[i(a)],text:a})]}:{events:[]}},v=(e,t)=>{let i=n(e.part)?e.part:void 0;if(!i)return{events:[]};let a=u(i.callID)??p(),o=u(i.tool)??`tool`,s=n(i.state)?i.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:[r(t.runId,`tool-call`,{sessionId:t.sessionId,model:null,toolCallId:a,toolName:o,input:c}),r(t.runId,`tool-result`,{sessionId:t.sessionId,toolCallId:a,toolName:o,input:c,output:d,isError:l||void 0,error:l?d:void 0})],toolCalls:[{toolCallId:a,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 i=n(e.error)?e.error:void 0,a=u((n(i?.data)?i.data:void 0)?.message)??u(i?.message)??u(i?.name)??`unknown error`;return{events:[r(t.runId,`stderr`,{sessionId:t.sessionId,text:a})],state:{status:`failed`,error:{kind:`provider`,message:a}}}},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=a(l.object({type:l.string()}).passthrough()),C={structuredOutput:!1,sessionResume:!0,sessionFork:!0,imageInput:!1,mcp:!0,eventStreaming:!0};var w=class extends s{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`],r=o(e.input),i=e.agent??this.runDefaults.agent,a=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),i&&n.push(`--agent`,i),a&&a.length>0)for(let e of a)n.push(`--file`,e);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);let p=r.trim().split(/\s+/).filter(Boolean);return n.push(`--`,...p),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(c(e).options);export{T as createOpencodeCliAgent};
|
package/dist/pi-cli-J5YpX_ei.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{n as e}from"./types-CwvWHEpy.mjs";import{a as t,n}from"./util-CGg8cK92.mjs";import{a as r,c as i,o as a,s as o}from"./classify-error-DoH0BqEA.mjs";import{n as s,t as c}from"./execution-target-DjI5SnsB.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,a)=>{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)??a.model??null,l=[];return a.reasoningText&&l.push(r(t.runId,`reasoning`,{sessionId:t.sessionId,model:c,content:[i(a.reasoningText)],text:a.reasoningText})),s&&l.push(r(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 i=u(e.toolCallId)??f(),a=u(e.toolName)??`tool`,o=e.args===void 0?void 0:e.args;return{events:[r(t.runId,`tool-call`,{sessionId:t.sessionId,model:n.model??null,toolCallId:i,toolName:a,input:o})],toolCalls:[{toolCallId:i,toolName:a,input:o}]}},b=(e,t)=>{let n=u(e.toolCallId)??f(),i=!!e.isError,a=e.result,o=t.toolCalls.get(n),s=u(e.toolName)??o?.toolName;return{events:[r(t.runId,`tool-result`,{sessionId:t.sessionId,toolCallId:n,toolName:s,input:o?.input,output:a,isError:i||void 0,error:i?p(a):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=a(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 s{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`],r=e.provider??this.runDefaults.provider,i=e.thinking??this.runDefaults.thinking,a=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?r?n.push(`--model`,`${r}/${e.model}`):n.push(`--model`,e.model):r&&n.push(`--provider`,r),e.systemPrompt&&n.push(`--system-prompt`,e.systemPrompt),a&&n.push(`--append-system-prompt`,a),i&&n.push(`--thinking`,i),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=o(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(c(e).options);export{O as createPiCliAgent};
|
|
File without changes
|
|
File without changes
|