coding-agents-sdk 0.10.0 → 0.11.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 +8 -7
- package/dist/adapters/claude-code-cli/index.d.mts +1 -1
- package/dist/adapters/claude-code-cli-pty/index.d.mts +3 -0
- package/dist/adapters/claude-code-cli-pty/index.mjs +35 -0
- package/dist/adapters/claude-code-sdk/index.d.mts +1 -1
- package/dist/adapters/codex-cli/index.d.mts +1 -1
- package/dist/adapters/codex-sdk/index.d.mts +1 -1
- package/dist/adapters/cursor-cli/index.d.mts +1 -1
- package/dist/adapters/cursor-sdk/index.d.mts +1 -1
- package/dist/adapters/cursor-sdk/index.mjs +1 -1
- package/dist/adapters/gemini-cli/index.d.mts +1 -1
- package/dist/adapters/opencode-cli/index.d.mts +1 -1
- package/dist/adapters/pi-cli/index.d.mts +1 -1
- package/dist/container/index.d.mts +1 -1
- package/dist/{events-Dd9r9luo.d.mts → events-Bwfw__Q3.d.mts} +139 -0
- package/dist/index-B0x76PaA.d.mts +104 -0
- package/dist/{index-J7V9dJTb.d.mts → index-BQNj8DHq.d.mts} +46 -15
- package/dist/index-B_MIEnNS.d.mts +60 -0
- package/dist/index-BeejNCvc.d.mts +429 -0
- package/dist/index-C8wbKjj3.d.mts +188 -0
- package/dist/index-CEHYyi4k.d.mts +68 -0
- package/dist/{index-BNeL0BbU.d.mts → index-ClURbAqF.d.mts} +67 -1
- package/dist/index-CyxdNK5W.d.mts +58 -0
- package/dist/{index-DZDlHIep.d.mts → index-D5zrCo6s.d.mts} +43 -12
- package/dist/index-ILgtPW1P.d.mts +97 -0
- package/dist/index-dPV54_sZ.d.mts +69 -0
- package/dist/{index-B-rto_J2.d.mts → index-p8MJ49dZ.d.mts} +77 -1
- package/dist/index.d.mts +69 -19
- package/dist/index.mjs +1 -1
- package/dist/sandbox/index.d.mts +1 -1
- package/dist/schemas/index.d.mts +1 -1
- package/dist/types-Bk-YpdbX.d.mts +476 -0
- package/package.json +14 -14
- package/dist/adapters/claude-cli-pty/index.d.mts +0 -3
- package/dist/adapters/claude-cli-pty/index.mjs +0 -7
- package/dist/index-B4RAMnx_.d.mts +0 -46
- package/dist/index-BdDz7C4J.d.mts +0 -39
- package/dist/index-BiWkGgnz.d.mts +0 -46
- package/dist/index-BllemWbi.d.mts +0 -42
- package/dist/index-C7J_hmQs.d.mts +0 -67
- package/dist/index-CaUzD36R.d.mts +0 -42
- package/dist/index-D-8EmRnQ.d.mts +0 -85
- package/dist/index-lGZ1lQkG.d.mts +0 -246
- package/dist/types-D6kxBNzj.d.mts +0 -195
package/README.md
CHANGED
|
@@ -26,7 +26,7 @@ bun add e2b
|
|
|
26
26
|
Before you call `await createAgent(...)`, make sure the runtime for that adapter is available.
|
|
27
27
|
|
|
28
28
|
- `claude-code-cli` runs Claude Code CLI.
|
|
29
|
-
- `claude-cli-pty` runs interactive Claude Code behind a PTY and requires `socat` on `PATH`.
|
|
29
|
+
- `claude-code-cli-pty` runs interactive Claude Code behind a PTY and requires `socat` on `PATH`.
|
|
30
30
|
- `claude-code-sdk` uses `@anthropic-ai/claude-agent-sdk` and launches Claude Code locally.
|
|
31
31
|
- `codex-cli` runs Codex CLI.
|
|
32
32
|
- `codex-sdk` uses `@openai/codex-sdk` and launches Codex locally.
|
|
@@ -194,7 +194,7 @@ MCP tool calls can show up in the event stream when the underlying runtime suppo
|
|
|
194
194
|
This wrapper exposes MCP configuration directly on:
|
|
195
195
|
|
|
196
196
|
- `claude-code-cli`: `mcpConfig`, `mcpServers`
|
|
197
|
-
- `claude-cli-pty`: `mcpConfig`, `mcpServers`
|
|
197
|
+
- `claude-code-cli-pty`: `mcpConfig`, `mcpServers`
|
|
198
198
|
- `claude-code-sdk`: `mcpServers`
|
|
199
199
|
- `codex-cli`: `mcpConfig`, `mcpServers`
|
|
200
200
|
- `opencode-cli`: MCP is supported by the runtime (configure via opencode's own settings)
|
|
@@ -203,7 +203,7 @@ For `codex-sdk`, `gemini-cli`, and `pi-cli`, use the runtime's own MCP setup. Th
|
|
|
203
203
|
|
|
204
204
|
## Containers
|
|
205
205
|
|
|
206
|
-
Containers are supported on the CLI adapters: `claude-code-cli`, `claude-cli-pty`, `codex-cli`, `gemini-cli`, `opencode-cli`, and `pi-cli`.
|
|
206
|
+
Containers are supported on the CLI adapters: `claude-code-cli`, `claude-code-cli-pty`, `codex-cli`, `gemini-cli`, `opencode-cli`, and `pi-cli`.
|
|
207
207
|
Built-in container providers are:
|
|
208
208
|
|
|
209
209
|
- `docker`
|
|
@@ -249,7 +249,7 @@ if (result.status === "completed") {
|
|
|
249
249
|
}
|
|
250
250
|
```
|
|
251
251
|
|
|
252
|
-
Your image needs the runtime for the adapter you picked available inside the container. For `claude-cli-pty`, install both `claude` and `socat` in the image; the Stop hook also expects `sh` and `cat`.
|
|
252
|
+
Your image needs the runtime for the adapter you picked available inside the container. For `claude-code-cli-pty`, install both `claude` and `socat` in the image; the Stop hook also expects `sh` and `cat`.
|
|
253
253
|
|
|
254
254
|
If you omit `cwd`, the agent uses `container.workdir`. The container is started automatically on the first run. Use `snapshotWorkdir()`, `diffWorkdir()`, and `releaseWorkdirSnapshot()` when you need a reliable before/after file diff.
|
|
255
255
|
|
|
@@ -290,9 +290,10 @@ await using agent = await createAgent("codex-cli", {
|
|
|
290
290
|
Notes:
|
|
291
291
|
|
|
292
292
|
- CLI adapters accept `container` or `sandbox`, but not both
|
|
293
|
-
- `claude-cli-pty` runs `socat` through the execution target, so `socat` must be available inside the container or sandbox environment
|
|
294
|
-
- `claude-cli-pty` writes per-run Stop hook files under the sandbox workdir, so
|
|
295
|
-
- `claude-cli-pty`
|
|
293
|
+
- `claude-code-cli-pty` runs `socat` through the execution target, so `socat` must be available inside the container or sandbox environment
|
|
294
|
+
- `claude-code-cli-pty` writes per-run Stop and PermissionRequest hook files to its run directory; sandbox-backed runs place that directory under the sandbox workdir, so it must be writable
|
|
295
|
+
- `claude-code-cli-pty` supports `onPermissionRequest` through a run-local Claude `PermissionRequest` hook and does not parse terminal permission prompts; the generated `--settings` payload contains only SDK hook entries so Claude can merge it with existing user and project hooks
|
|
296
|
+
- `claude-code-cli-pty` container runs cannot use `onPermissionRequest` because the generated hook calls a host loopback bridge that is not reachable from the container network namespace
|
|
296
297
|
- sandbox-backed CLI runs keep the normal `propagateEnv` default and inherit the host env unless you set `propagateEnv: false`
|
|
297
298
|
- built-in sandbox providers are `bubblewrap`, `firejail`, and `nsjail`
|
|
298
299
|
- `codex-cli` uses `codexSandboxMode` for the Codex CLI `--sandbox` flag so it does not conflict with the `sandbox` execution target option
|
|
@@ -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-BQNj8DHq.mjs";
|
|
2
2
|
export { ClaudeAssistantEvent, ClaudeCodeCliAgent, ClaudeCodeCliAgentOptions, ClaudeCodeCliPermissionMode, ClaudeCodeCliRunOptions, ClaudeEvent, ClaudeRateLimitEvent, ClaudeResultEvent, ClaudeSystemEvent, ClaudeUserEvent, createClaudeCodeCliAgent };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { c as ClaudeRateLimitEvent, d as ClaudeUserEvent, l as ClaudeResultEvent, o as ClaudeAssistantEvent, s as ClaudeEvent, u as ClaudeSystemEvent } from "../../index-BQNj8DHq.mjs";
|
|
2
|
+
import { a as ClaudeCodeCliPtyPermissionMode, i as ClaudeCodeCliPtyModule, n as ClaudeCodeCliPtyAgent, o as ClaudeCodeCliPtyProcess, r as ClaudeCodeCliPtyAgentOptions, s as ClaudeCodeCliPtyRunOptions, t as createClaudeCodeCliPtyAgent } from "../../index-B0x76PaA.mjs";
|
|
3
|
+
export { ClaudeAssistantEvent, ClaudeCodeCliPtyAgent, ClaudeCodeCliPtyAgentOptions, ClaudeCodeCliPtyModule, ClaudeCodeCliPtyPermissionMode, ClaudeCodeCliPtyProcess, ClaudeCodeCliPtyRunOptions, ClaudeEvent, ClaudeRateLimitEvent, ClaudeResultEvent, ClaudeSystemEvent, ClaudeUserEvent, createClaudeCodeCliPtyAgent };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import{n as e}from"../../types-CwvWHEpy.mjs";import{a as t,n,r,t as i}from"../../util-CGg8cK92.mjs";import{t as a}from"../../env-DIXTVzTs.mjs";import{t as o}from"../../spawner-BJesLc8I.mjs";import{a as s,c,n as l,s as u,t as d}from"../../classify-error-BcWmNftw.mjs";import{t as f}from"../../execution-target-CGTSqVEP.mjs";import{n as p,r as m,t as h}from"../../parser-BBJPNGZ2.mjs";import{join as g,posix as _}from"node:path";import{appendFileSync as v,existsSync as y,mkdtempSync as b,readFileSync as x,writeFileSync as S}from"node:fs";import{tmpdir as C}from"node:os";import{rm as w}from"node:fs/promises";import{randomUUID as T}from"node:crypto";import{createServer as E}from"node:http";const D=e=>typeof e==`object`&&!!e&&!Array.isArray(e),O=async e=>{let t=[];for await(let n of e)t.push(Buffer.isBuffer(n)?n:Buffer.from(n));if(t.length===0)return;let n;try{n=JSON.parse(Buffer.concat(t).toString(`utf8`))}catch{return}if(D(n)&&n.hook_event_name===`PermissionRequest`&&!(typeof n.tool_name!=`string`||n.tool_name.length===0)&&D(n.tool_input))return{toolName:n.tool_name,input:n.tool_input,toolUseId:typeof n.tool_use_id==`string`&&n.tool_use_id.length>0?n.tool_use_id:T()}},k=(e,t)=>{e.writeHead(200,{"content-type":`application/json`}),e.end(JSON.stringify(t))},A=e=>e.decision===`allow`?{hookSpecificOutput:{hookEventName:`PermissionRequest`,decision:{behavior:`allow`,...e.updatedInput?{updatedInput:e.updatedInput}:{}}}}:{hookSpecificOutput:{hookEventName:`PermissionRequest`,decision:{behavior:`deny`,message:e.message??`Tool call denied.`}}},ee=()=>`import { Buffer } from "node:buffer";
|
|
2
|
+
|
|
3
|
+
const url = process.argv[2];
|
|
4
|
+
if (!url) {
|
|
5
|
+
console.error("missing permission hook bridge url");
|
|
6
|
+
process.exit(2);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const chunks = [];
|
|
10
|
+
for await (const chunk of process.stdin) {
|
|
11
|
+
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
try {
|
|
15
|
+
const response = await fetch(url, {
|
|
16
|
+
method: "POST",
|
|
17
|
+
headers: { "content-type": "application/json" },
|
|
18
|
+
body: Buffer.concat(chunks).toString("utf8"),
|
|
19
|
+
});
|
|
20
|
+
const text = await response.text();
|
|
21
|
+
if (!response.ok) {
|
|
22
|
+
console.error(text || \`permission hook bridge returned \${response.status}\`);
|
|
23
|
+
process.exit(2);
|
|
24
|
+
}
|
|
25
|
+
process.stdout.write(text);
|
|
26
|
+
} catch (error) {
|
|
27
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
28
|
+
process.exit(2);
|
|
29
|
+
}
|
|
30
|
+
`,te=async({handler:e,signal:t})=>{let n=E(async(n,r)=>{if(n.method!==`POST`){r.writeHead(405).end();return}let i=await O(n);if(!i){r.writeHead(400).end();return}try{k(r,A(await e({toolName:i.toolName,input:i.input,toolUseId:i.toolUseId,signal:t})))}catch(e){k(r,A({decision:`deny`,message:e instanceof Error?e.message:String(e)}))}});return await new Promise((e,t)=>{n.once(`error`,t),n.listen(0,`127.0.0.1`,()=>{n.removeListener(`error`,t),e()})}),{url:`http://127.0.0.1:${n.address().port}/permission-hook`,dispose:()=>new Promise(e=>{n.close(()=>e())})}},ne={structuredOutput:!0,sessionResume:!0,imageInput:!1,mcp:!0,eventStreaming:!0,sessionFork:!0,permissionRequests:!0},j=new Set(`SIGABRT.SIGALRM.SIGBREAK.SIGBUS.SIGCHLD.SIGCONT.SIGFPE.SIGHUP.SIGILL.SIGINT.SIGIO.SIGIOT.SIGKILL.SIGPIPE.SIGPOLL.SIGPROF.SIGPWR.SIGQUIT.SIGSEGV.SIGSTKFLT.SIGSTOP.SIGSYS.SIGTERM.SIGTRAP.SIGTSTP.SIGTTIN.SIGTTOU.SIGUNUSED.SIGURG.SIGUSR1.SIGUSR2.SIGVTALRM.SIGWINCH.SIGXCPU.SIGXFSZ`.split(`.`)),M=e=>new Promise(t=>{setTimeout(t,e)}),N=e=>{let{$schema:t,...n}={...e};return n},P=(e,t)=>{Object.assign(e,t)},F=e=>`'${e.replace(/'/g,`'\\''`)}'`,I=(e,t)=>[e,...t].map(F).join(` `),L=(e,t)=>[process.execPath,e,t].map(F).join(` `),R=e=>e.replace(/\\/g,`\\\\`).replace(/,/g,`\\,`),z=e=>{if(!(!e||!j.has(e)))return e},B=(e=o)=>({spawn:(t,n,r)=>{let a=new Set,o=new Set,s=r.initialInputPath&&r.initialInputBootstrapPath?[r.initialInputBootstrapPath,r.initialInputPath,t,...n]:n,c=`EXEC:${R(I(r.initialInputPath&&r.initialInputBootstrapPath?`/bin/sh`:t,s))},pty,setsid,ctty`,l=e.spawn(`socat`,[`-`,c],{cwd:r.cwd,env:r.env,stdio:[`pipe`,`pipe`,`pipe`]}),u=e=>{for(let t of o)t(e)},d=e=>{for(let t of a)t(e)},f=async e=>{if(!e)return;let t=new TextDecoder;for await(let n of e)u(t.decode(n,{stream:!0}));let n=t.decode();n&&u(n)};return f(l.stdout).catch(e=>{u(i(e))}),f(l.stderr).catch(e=>{u(i(e))}),l.wait().then(e=>{d({exitCode:e.exitCode??0,signal:e.signal??void 0})}).catch(e=>{u(i(e)),d({exitCode:127})}),{write:e=>{l.stdin?.write?.(e)},kill:e=>{l.kill(z(e))},onData:e=>(o.add(e),{dispose:()=>o.delete(e)}),onExit:e=>(a.add(e),{dispose:()=>a.delete(e)})}}}),V=({sentinelPath:e,permissionHookCommand:t,skipDangerousModePermissionPrompt:n})=>{let r={Stop:[{hooks:[{type:`command`,command:`sh -c ${F(`cat > ${F(e)}`)}`}]}]};t&&(r.PermissionRequest=[{hooks:[{type:`command`,command:t}]}]);let i={...n&&{skipDangerousModePermissionPrompt:!0},hooks:r};return JSON.stringify(i)},H=e=>{let t=JSON.parse(e);return n(t)?{sessionId:typeof t.session_id==`string`?t.session_id:void 0,transcriptPath:typeof t.transcript_path==`string`?t.transcript_path:void 0,lastAssistantMessage:t.last_assistant_message}:{}},U=e=>{try{return H(e)}catch{return}},W=e=>{if(typeof e==`string`)return e;if(!n(e))return;if(typeof e.text==`string`)return e.text;let t=e.content;if(!Array.isArray(t))return;let r=t.flatMap(e=>!n(e)||e.type!==`text`||typeof e.text!=`string`?[]:[e.text]);return r.length>0?r.join(`
|
|
31
|
+
`):void 0},G=(e,t)=>{let n=e[t];return typeof n==`string`?n:void 0},K=e=>G(e,`session_id`)??G(e,`sessionId`),q=e=>{let t;try{t=JSON.parse(e)}catch{return}if(Array.isArray(t))return t.some(e=>n(e)&&e.type===`tool_result`)?t:void 0},J=e=>{if(e.type!==`user`||!n(e.message))return;let t=e.message.content;if(typeof t==`string`)return q(t)?void 0:t;if(!Array.isArray(t)||t.some(e=>n(e)&&e.type===`tool_result`))return;let r=t.flatMap(e=>!n(e)||e.type!==`text`||typeof e.text!=`string`?[]:[e.text]);return r.length>0?r.join(`
|
|
32
|
+
`):void 0},Y=e=>{if(e.type!==`attachment`||!n(e.attachment))return;let t=e.attachment;return`[${[G(t,`type`)??`attachment`,G(t,`hookEvent`)??G(t,`hook_event`),G(t,`hookName`)??G(t,`hook_name`)].filter(e=>e!==void 0).join(` `)}]`},X=(e,t)=>`${e} Return only valid JSON matching this JSON Schema. Do not wrap the JSON in Markdown. ${JSON.stringify(N(t))}`,re=e=>{let t=u(e.input);return e.schema.kind===`none`?t:X(t,e.schema.jsonSchema)},Z=e=>e.replace(/[/:\\]/g,`-`),ie=e=>Promise.resolve(y(e)),ae=e=>{if(!e)return;let t=e.split(`:`)[0];if(!(!t||/^\d+$/.test(t)))return t===`root`?`/root`:`/home/${t}`},oe=e=>{if(!(e.type!==`assistant`||!n(e.message))&&G(e.message,`stop_reason`)!==`tool_use`)return W(e.message)},Q=(e,t)=>{let r=e.split(/\r?\n/).filter(e=>e.trim().length>0),i=!1,a=!1,o=t.replace(/\r?\n$/,``);for(let e of r){let t;try{t=JSON.parse(e)}catch{continue}if(!n(t))continue;let r=J(t);if(r!==void 0){i=r.replace(/\r?\n$/,``)===o,a=!1;continue}i&&oe(t)!==void 0&&(a=!0)}return a},$=e=>{if(!n(e)||`session_id`in e)return e;let t=K(e);if(!t)return e;if(e.type===`user`&&n(e.message)&&typeof e.message.content==`string`){let n=q(e.message.content);if(n)return{...e,session_id:t,message:{...e.message,content:n}}}return{...e,session_id:t}},se=async(e,t,n)=>{let r=e.sessionId??e.requestedSessionId;if(r)for(let e of t.transcriptPathsForSession(r)){let r=await t.readText(e);if(r!==void 0&&Q(r,n))return e}};var ce=class o extends l{type=`claude-code-cli-pty`;creationOptions;runDefaults;forkOnNextRun;activePty;executionTargetRef;tempDirs=new Set;logPath;constructor(e={}){super({type:`claude-code-cli-pty`,capabilities:ne,sessionId:e.sessionId,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,readinessTimeoutMs:e.readinessTimeoutMs,stopHookTimeoutMs:e.stopHookTimeoutMs},this.forkOnNextRun=e.forkOnNextRun??!1,this.executionTargetRef=e.container??e.sandbox,this.logPath=e.logPath}get runRequestDefaults(){return{cwd:this.creationOptions.cwd,model:this.creationOptions.model,systemPrompt:this.creationOptions.systemPrompt}}fork(){if(!this.sessionId)throw new e(`Cannot fork a Claude Code CLI PTY agent before it has a sessionId.`);return new o({...this.creationOptions,sessionId:this.sessionId,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 executeRunCore(e,t){let n=this.setupRunLifecycle(e),r,i;try{if(n.abortedBeforeStart)return this.buildResult(e,new Date);this.validatePermissionHandlerSupported(),await this.ensureExecutionTarget();let a={...t,...e.normalizedRequest},o=this.getPermissionHandler();o&&(i=await te({handler:o,signal:e.normalizedRequest.signal??new AbortController().signal})),r=await this.createRunFiles(e);let s=i?L(r.permissionHookPath,i.url):void 0;i&&await r.writeText(r.permissionHookPath,ee());let c=a.permissionMode??this.runDefaults.permissionMode;await r.writeText(r.settingsPath,V({sentinelPath:r.sentinelPath,permissionHookCommand:s,skipDangerousModePermissionPrompt:c===`bypassPermissions`}));let l=this.creationOptions.pty??B(this.creationOptions.spawner),u=re(a);await r.writeText(r.bootstrapPath,`prompt_path=$1
|
|
33
|
+
shift
|
|
34
|
+
cat "$prompt_path" | exec "$@"
|
|
35
|
+
`),await r.writeText(r.promptPath,`${u}\n`);let{command:d,args:f}=await this.buildCommand(a,e,r),p=this.buildEnv(),m=this.spawnPty({run:e,ptyModule:l,command:d,args:f,env:p,initialInputBootstrapPath:r.bootstrapPath,initialInputPath:r.promptPath});e.sessionId&&this.emitSessionStart(e),await this.waitForReadiness(a,e);let h=await this.waitForStopSentinel(a,e,r,m,u);return h&&await this.applyStopSentinel(e,h,r),e.stopReason||this.activePty?.write(`/exit\r`),P(e,{processResult:await this.waitForExit(m)}),!e.stopReason&&!e.error&&!e.status&&P(e,{status:`completed`}),this.buildResult(e,new Date)}catch(t){return this.activePty?.kill(),!e.stopReason&&!e.error&&P(e,{error:d(t)}),this.buildResult(e,new Date)}finally{n.cleanup(),this.activePty=void 0,await i?.dispose(),await r?.cleanup()}}onStopRequested(e){this.activePty?.kill()}async onDispose(){for(let e of this.tempDirs)await w(e,{recursive:!0,force:!0}).catch(()=>{});this.tempDirs.clear()}onHandlerError(e){this.appendRawLog(`[handler-error] ${i(e)}`)}validatePermissionHandlerSupported(){if(this.getPermissionHandler()&&this.creationOptions.container)throw new e(`onPermissionRequest is not supported when running claude-code-cli-pty inside a container: the generated PermissionRequest hook calls a host loopback bridge and is unreachable from the container's network namespace.`)}async ensureExecutionTarget(){this.executionTargetRef&&this.executionTargetRef.status!==`running`&&await this.executionTargetRef.start()}async createRunFiles(e){let t=this.creationOptions.container,n=this.creationOptions.container?.workdir??this.creationOptions.sandbox?.workdir,r=e.normalizedRequest.cwd??this.creationOptions.cwd??n??process.cwd();if(t){let e=_.join(`/tmp`,`coding-agents-claude-pty-${crypto.randomUUID()}`),n=_.join(e,`prompt-bootstrap.sh`),i=_.join(e,`permission-hook.mjs`),a=_.join(e,`prompt.txt`),o=_.join(e,`settings.json`),s=_.join(e,`stop-sentinel.json`),c=Z(r),l=`user`in t.config?t.config.user:void 0,u=[this.creationOptions.env?.HOME,t.config.env?.HOME,ae(l),`/root`,`/home/node`,`/home/bun`,`/home/agent`,`/home/user`].filter(e=>typeof e==`string`&&e.length>0);return await t.mkdir(e),{runDir:e,bootstrapPath:n,permissionHookPath:i,promptPath:a,settingsPath:o,sentinelPath:s,exists:t.fileExists,readText:async e=>await t.fileExists(e)?t.readFile(e):void 0,writeText:(e,n)=>t.writeFile(e,n),transcriptPathsForSession:e=>Array.from(new Set(u)).map(t=>_.join(t,`.claude`,`projects`,c,`${e}.jsonl`)),cleanup:async()=>{await t.exec(`rm`,[`-rf`,e]).catch(()=>void 0)}}}let i=b(g(this.creationOptions.sandbox?r:C(),`.coding-agents-claude-pty-`)),a=g(i,`prompt-bootstrap.sh`),o=g(i,`permission-hook.mjs`),s=g(i,`prompt.txt`),c=g(i,`settings.json`),l=g(i,`stop-sentinel.json`),u=[this.creationOptions.env?.HOME,this.creationOptions.sandbox?.config.setEnv?.HOME,process.env.HOME].filter(e=>typeof e==`string`&&e.length>0),d=Array.from(new Set(u)).map(e=>g(e,`.claude`,`projects`,Z(r)));return this.tempDirs.add(i),{runDir:i,bootstrapPath:a,permissionHookPath:o,promptPath:s,settingsPath:c,sentinelPath:l,exists:ie,readText:async e=>y(e)?x(e,`utf8`):void 0,writeText:async(e,t)=>{S(e,t,{encoding:`utf8`,mode:384})},transcriptPathsForSession:e=>d.map(t=>g(t,`${e}.jsonl`)),cleanup:async()=>{this.tempDirs.delete(i),await w(i,{recursive:!0,force:!0}).catch(()=>{})}}}async buildCommand(e,n,r){let i=this.creationOptions.command?.[0]??`claude`,a=[...this.creationOptions.command?.slice(1)??[]],o=e.permissionMode??this.runDefaults.permissionMode,s=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&&a.push(`--model`,e.model),e.systemPrompt&&a.push(`--system-prompt`,e.systemPrompt),s&&a.push(`--append-system-prompt`,s),o&&a.push(`--permission-mode`,o),c&&c.length>0&&a.push(`--allowed-tools`,c.join(`,`)),l&&l.length>0&&a.push(`--disallowed-tools`,l.join(`,`)),u)for(let e of t(u))a.push(`--mcp-config`,e);if(d){let e=this.creationOptions.container?_.join(r.runDir,`mcp.json`):g(r.runDir,`mcp.json`);await r.writeText(e,JSON.stringify({mcpServers:d})),a.push(`--mcp-config`,e)}if(a.push(`--settings`,r.settingsPath),n.requestedSessionId)a.push(`--resume`,n.requestedSessionId),p&&a.push(`--fork-session`);else{let e=crypto.randomUUID();P(n,{sessionId:e}),this.setSessionId(e),a.push(`--session-id`,e)}return f&&f.length>0&&a.push(...f),this.forkOnNextRun=!1,{command:i,args:a}}buildEnv(){let e=a({propagateEnv:this.creationOptions.propagateEnv});return this.creationOptions.ci!==!1&&(e.CI=e.CI??`true`),this.creationOptions.env&&Object.assign(e,this.creationOptions.env),delete e.CLAUDECODE,e}spawnPty({run:e,ptyModule:t,command:n,args:r,env:i,initialInputBootstrapPath:a,initialInputPath:o}){this.appendRawLog(`[spawn] ${n} ${r.join(` `)}`);let s=t.spawn(n,r,{cols:120,rows:40,cwd:e.normalizedRequest.cwd,env:i,initialInputBootstrapPath:a,initialInputPath:o});this.activePty=s;let c=new Promise(e=>{s.onExit(t=>{e({exitCode:t.exitCode,signal:typeof t.signal==`string`?z(t.signal)??null:null})})});return P(e,{process:{stdout:null,stderr:null,stdin:{write:e=>s.write(typeof e==`string`?e:new TextDecoder().decode(e)),end:()=>{}},kill:e=>{s.kill(typeof e==`string`?e:void 0)},wait:()=>c}}),s.onData(e=>{this.appendRawLog(`[pty] ${e}`)}),c}async waitForReadiness(e,t){let n=e.readinessTimeoutMs??this.runDefaults.readinessTimeoutMs??5e3,r=this.activePty;!r||n<=0||await new Promise(e=>{let i=!1,a={},o=()=>{i||(i=!0,a.idle&&clearTimeout(a.idle),a.timeout&&clearTimeout(a.timeout),a.subscription?.dispose(),e())};a.timeout=setTimeout(o,n),a.subscription=r.onData(()=>{a.idle&&clearTimeout(a.idle),a.idle=setTimeout(o,Math.min(250,n)),a.idle.unref?.()}),a.timeout.unref?.(),t.stopReason&&o()})}async waitForStopSentinel(e,t,n,r,i){let a=e.stopHookTimeoutMs??this.runDefaults.stopHookTimeoutMs??12e4,o=Date.now()+a,s;for(r.then(e=>{s=e});;){let e=await n.exists(n.sentinelPath)?await n.readText(n.sentinelPath):void 0,r=e===void 0?void 0:U(e);if(r?.transcriptPath){let e=await n.readText(r.transcriptPath);if(e!==void 0&&Q(e,i))return r}let c=await se(t,n,i);if(c)return this.appendRawLog(`[transcript] completed turn from ${c}`),{...r,transcriptPath:c};if(t.stopReason)return;if(s)throw P(t,{processResult:s}),Error(`Claude exited before the Stop hook created a sentinel.`);if(Date.now()>=o)throw Error(`Claude Stop hook did not create a sentinel within ${a}ms.`);await M(50)}}async applyStopSentinel(e,t,n){if(t.sessionId&&(P(e,{sessionId:t.sessionId}),this.setSessionId(t.sessionId),this.emitSessionStart(e)),t.transcriptPath){let r=await n.readText(t.transcriptPath);r!==void 0&&this.applyTranscript(e,r)}if(e.assistantTexts.length===0){let n=W(t.lastAssistantMessage);n&&this.emitAssistantText(e,n)}let i=e.output.text??e.assistantTexts.at(-1);if(e.normalizedRequest.schema.kind!==`none`&&i&&e.output.value===void 0)try{let t=e.error?.kind===`parse`&&e.error.message.includes(`structured_output`);this.applyBatch(e,{events:[],state:{output:{value:r(i)}}}),t&&e.output.value!==void 0&&P(e,{error:void 0,status:void 0})}catch(t){P(e,{error:d(t),status:`failed`})}e.assistantTexts.length===0&&!e.output.text&&!e.error&&P(e,{error:{kind:`parse`,message:`Claude Stop hook completed without assistant output.`},status:`failed`})}applyTranscript(e,t){let n=t.split(/\r?\n/).filter(e=>e.trim().length>0);for(let t of n){let n;try{n=JSON.parse(t)}catch(t){P(e,{error:d(t),status:`failed`});return}if(this.applyTranscriptNativeEvent(e,n))continue;let r=h($(n));if(!r)continue;let i=p(r)??e.sessionId,a=m(r,{runId:e.runId,requestedSessionId:e.requestedSessionId,sessionId:i,schemaRequested:e.normalizedRequest.schema.kind!==`none`,toolCalls:e.toolCalls});i&&!a.sessionId&&(a.sessionId=i),this.applyBatch(e,a)}}applyTranscriptNativeEvent(e,t){if(!n(t))return!1;let r=K(t)??e.sessionId,i=J(t);if(i!==void 0)return this.emitTextMessage(e,`user`,i,r),!0;let a=Y(t);return a===void 0?!1:(this.emitTextMessage(e,`system`,a,r),!0)}emitTextMessage(e,t,n,r=e.sessionId){r&&!e.sessionId&&(P(e,{sessionId:r}),this.setSessionId(r)),e.sessionId&&this.emitSessionStart(e),this.emit(e,s(e.runId,`message`,{sessionId:e.sessionId,model:null,role:t,content:[c(n)],text:n}))}emitAssistantText(e,t){this.emitTextMessage(e,`assistant`,t),this.applyBatch(e,{events:[],state:{output:{text:t}}})}async waitForExit(e){let t=this.activePty,n,r=new Promise(e=>{n=setTimeout(()=>{t?.kill(),e({exitCode:null,signal:`SIGKILL`})},2e3),n.unref?.()});try{return await Promise.race([e,r])}finally{n&&clearTimeout(n)}}appendRawLog(e){if(this.logPath)try{v(this.logPath,`${e}\n`,`utf8`)}catch{}}};const le=e=>new ce(f(e).options??e);export{le as createClaudeCodeCliPtyAgent};
|
|
@@ -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-ILgtPW1P.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-D5zrCo6s.mjs";
|
|
2
2
|
export { CodexCliAgent, CodexCliAgentOptions, CodexCliPermissionMode, CodexCliRunOptions, CodexCliSandboxMode, CodexErrorEvent, CodexEvent, CodexItemCompletedEvent, CodexItemStartedEvent, CodexItemUpdatedEvent, CodexThreadStartedEvent, CodexTurnCompletedEvent, CodexTurnFailedEvent, 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-p8MJ49dZ.mjs";
|
|
2
2
|
export { CodexSdkAgent, CodexSdkAgentOptions, CodexSdkEvent, CodexSdkItem, CodexSdkPermissionMode, CodexSdkRunOptions, createCodexSdkAgent };
|
|
@@ -1,2 +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-
|
|
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-dPV54_sZ.mjs";
|
|
2
2
|
export { CursorCliAgent, CursorCliAgentOptions, CursorCliEvent, CursorCliMode, CursorCliRunOptions, CursorCliSandboxMode, createCursorCliAgent };
|
|
@@ -1,2 +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-
|
|
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-ClURbAqF.mjs";
|
|
2
2
|
export { CursorSdkAgent, CursorSdkAgentOptions, CursorSdkEvent, CursorSdkMcpHttpAuth, CursorSdkMcpServerConfig, CursorSdkModelParameterValue, CursorSdkModelSelection, CursorSdkRunOptions, CursorSdkSettingSource, createCursorSdkAgent };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e}from"../../types-CwvWHEpy.mjs";import{a as t,c as n,s as r}from"../../classify-error-BcWmNftw.mjs";import{t as i}from"../../SdkAgent-DQfLwPwY.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,
|
|
1
|
+
import{n as e}from"../../types-CwvWHEpy.mjs";import{a as t,c as n,s as r}from"../../classify-error-BcWmNftw.mjs";import{t as i}from"../../SdkAgent-DQfLwPwY.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,t,n)=>{let r=[],i=[],a=n.model,o=n.textBuffer??``;for(let n of e.message.content){if(n.type===`text`){o+=n.text;continue}let e=s(n.id,n.name,n.input,t,a);r.push(...e.events),i.push(...e.toolCalls??[])}return{events:r,toolCalls:i.length>0?i:void 0,state:o===(n.textBuffer??``)?void 0:{output:{text:o}}}},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,r,i={})=>{let a=e.result!==void 0&&e.result.length>0?e.result:i.textBuffer,o=[];return a!==void 0&&a.length>0&&o.push(t(r.runId,`message`,{sessionId:r.sessionId,model:i.model??null,role:`assistant`,content:[n(a)],text:a})),{events:o,state:{output:a===void 0?void 0:{text:a},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(),{runId:e.runId,requestedSessionId:e.requestedSessionId,sessionId:e.sessionId,schemaRequested:!1,toolCalls:e.toolCalls},{model:t.getCurrentModelString(o,e),textBuffer:this.runTextBuffers.get(e.runId)}),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-B_MIEnNS.mjs";
|
|
2
2
|
export { GeminiCliAgent, GeminiCliAgentOptions, GeminiCliPermissionMode, GeminiCliRunOptions, GeminiEvent, createGeminiCliAgent };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as OpencodeEvent, i as OpencodeCliRunOptions, n as OpencodeCliAgent, r as OpencodeCliAgentOptions, t as createOpencodeCliAgent } from "../../index-
|
|
1
|
+
import { a as OpencodeEvent, i as OpencodeCliRunOptions, n as OpencodeCliAgent, r as OpencodeCliAgentOptions, t as createOpencodeCliAgent } from "../../index-CyxdNK5W.mjs";
|
|
2
2
|
export { OpencodeCliAgent, OpencodeCliAgentOptions, OpencodeCliRunOptions, OpencodeEvent, createOpencodeCliAgent };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as PiCliThinkingLevel, i as PiCliRunOptions, n as PiCliAgent, o as PiEvent, r as PiCliAgentOptions, t as createPiCliAgent } from "../../index-
|
|
1
|
+
import { a as PiCliThinkingLevel, i as PiCliRunOptions, n as PiCliAgent, o as PiEvent, r as PiCliAgentOptions, t as createPiCliAgent } from "../../index-CEHYyi4k.mjs";
|
|
2
2
|
export { PiCliAgent, PiCliAgentOptions, PiCliRunOptions, PiCliThinkingLevel, PiEvent, createPiCliAgent };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { $ as WorkdirDiffStats, A as E2BCreateConfig, B as ContainerExecution, C as NerdctlProviderBase, D as E2BContainer, E as E2BConnectionConfig, F as DockerContainerBase, G as ContainerStatus, H as ContainerIdentity, I as DockerContainerConfig, J as ExecResult, K as ContainerType, L as DockerProviderConfig, M as DockerBuildBase, N as DockerBuildConfig, O as E2BContainerBase, P as DockerContainer, Q as WorkdirDiff, R as ContainerBase, S as NerdctlContainerConfig, T as E2BConnectConfig, U as ContainerLifecycle, V as ContainerFileSystem, W as ContainerObservability, X as VolumeMount, Y as PortMapping, Z as WorkdirChangeKind, _ as PodmanProviderConfig, a as ContainerDiffError, b as NerdctlContainer, c as ContainerExecError, d as MountValidationError, et as WorkdirFileChange, f as PodmanBuildBase, g as PodmanContainerConfig, h as PodmanContainerBase, i as ContainerCreateError, j as E2BProviderConfig, k as E2BContainerConfig, l as ContainerNotRunningError, m as PodmanContainer, n as ContainerConfig, nt as WorkdirSnapshotOptions, o as ContainerDisposedError, p as PodmanBuildConfig, q as ExecOptions, r as createContainer, s as ContainerError, t as Container, tt as WorkdirSnapshot, u as ContainerStartError, v as NerdctlBuildBase, w as NerdctlProviderConfig, x as NerdctlContainerBase, y as NerdctlBuildConfig, z as ContainerConfigBase } from "../index-
|
|
1
|
+
import { $ as WorkdirDiffStats, A as E2BCreateConfig, B as ContainerExecution, C as NerdctlProviderBase, D as E2BContainer, E as E2BConnectionConfig, F as DockerContainerBase, G as ContainerStatus, H as ContainerIdentity, I as DockerContainerConfig, J as ExecResult, K as ContainerType, L as DockerProviderConfig, M as DockerBuildBase, N as DockerBuildConfig, O as E2BContainerBase, P as DockerContainer, Q as WorkdirDiff, R as ContainerBase, S as NerdctlContainerConfig, T as E2BConnectConfig, U as ContainerLifecycle, V as ContainerFileSystem, W as ContainerObservability, X as VolumeMount, Y as PortMapping, Z as WorkdirChangeKind, _ as PodmanProviderConfig, a as ContainerDiffError, b as NerdctlContainer, c as ContainerExecError, d as MountValidationError, et as WorkdirFileChange, f as PodmanBuildBase, g as PodmanContainerConfig, h as PodmanContainerBase, i as ContainerCreateError, j as E2BProviderConfig, k as E2BContainerConfig, l as ContainerNotRunningError, m as PodmanContainer, n as ContainerConfig, nt as WorkdirSnapshotOptions, o as ContainerDisposedError, p as PodmanBuildConfig, q as ExecOptions, r as createContainer, s as ContainerError, t as Container, tt as WorkdirSnapshot, u as ContainerStartError, v as NerdctlBuildBase, w as NerdctlProviderConfig, x as NerdctlContainerBase, y as NerdctlBuildConfig, z as ContainerConfigBase } from "../index-BeejNCvc.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, MountValidationError, NerdctlBuildBase, NerdctlBuildConfig, NerdctlContainer, NerdctlContainerBase, NerdctlContainerConfig, NerdctlProviderBase, NerdctlProviderConfig, PodmanBuildBase, PodmanBuildConfig, PodmanContainer, PodmanContainerBase, PodmanContainerConfig, PodmanProviderConfig, PortMapping, VolumeMount, WorkdirChangeKind, WorkdirDiff, WorkdirDiffStats, WorkdirFileChange, WorkdirSnapshot, WorkdirSnapshotOptions, createContainer };
|
|
@@ -1,17 +1,32 @@
|
|
|
1
1
|
import { ZodType, z } from "zod/v4";
|
|
2
2
|
|
|
3
3
|
//#region src/schemas/agent.d.ts
|
|
4
|
+
/** Plain text content block in a {@link ContentPart} array. */
|
|
4
5
|
declare const textContentPartSchema: z.ZodObject<{
|
|
5
6
|
type: z.ZodLiteral<"text">;
|
|
6
7
|
text: z.ZodString;
|
|
7
8
|
}, z.core.$strip>;
|
|
9
|
+
/** Plain text content block in a {@link ContentPart} array. */
|
|
8
10
|
type TextContentPart = z.infer<typeof textContentPartSchema>;
|
|
11
|
+
/**
|
|
12
|
+
* Image content block. `path` is a filesystem path readable by the adapter
|
|
13
|
+
* (local images for `local_image`-style SDKs); `mediaType` defaults to being
|
|
14
|
+
* inferred from the file extension.
|
|
15
|
+
*/
|
|
9
16
|
declare const imageContentPartSchema: z.ZodObject<{
|
|
10
17
|
type: z.ZodLiteral<"image">;
|
|
11
18
|
path: z.ZodString;
|
|
12
19
|
mediaType: z.ZodOptional<z.ZodString>;
|
|
13
20
|
}, z.core.$strip>;
|
|
21
|
+
/**
|
|
22
|
+
* Image content block. `path` is a filesystem path readable by the adapter;
|
|
23
|
+
* `mediaType` defaults to being inferred from the file extension.
|
|
24
|
+
*/
|
|
14
25
|
type ImageContentPart = z.infer<typeof imageContentPartSchema>;
|
|
26
|
+
/**
|
|
27
|
+
* Multimodal content union. Pass an array of these as `RunRequest.input` to
|
|
28
|
+
* include images alongside text; pass a plain string for text-only input.
|
|
29
|
+
*/
|
|
15
30
|
declare const contentPartSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
16
31
|
type: z.ZodLiteral<"text">;
|
|
17
32
|
text: z.ZodString;
|
|
@@ -20,7 +35,17 @@ declare const contentPartSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
20
35
|
path: z.ZodString;
|
|
21
36
|
mediaType: z.ZodOptional<z.ZodString>;
|
|
22
37
|
}, z.core.$strip>], "type">;
|
|
38
|
+
/**
|
|
39
|
+
* Multimodal content union — the discriminated shape of `RunRequest.input`
|
|
40
|
+
* when passed as an array. Pass a plain string for text-only input; pass
|
|
41
|
+
* `ContentPart[]` to include images alongside text. Narrow on `part.type`.
|
|
42
|
+
*/
|
|
23
43
|
type ContentPart = z.infer<typeof contentPartSchema>;
|
|
44
|
+
/**
|
|
45
|
+
* Feature flags published by an adapter via `agent.capabilities`. Use to
|
|
46
|
+
* branch on capability before sending a request the adapter doesn't support
|
|
47
|
+
* (e.g. structured output, image input, MCP servers).
|
|
48
|
+
*/
|
|
24
49
|
declare const agentCapabilitiesSchema: z.ZodObject<{
|
|
25
50
|
structuredOutput: z.ZodBoolean;
|
|
26
51
|
sessionResume: z.ZodBoolean;
|
|
@@ -30,24 +55,48 @@ declare const agentCapabilitiesSchema: z.ZodObject<{
|
|
|
30
55
|
sessionFork: z.ZodOptional<z.ZodBoolean>;
|
|
31
56
|
permissionRequests: z.ZodOptional<z.ZodBoolean>;
|
|
32
57
|
}, z.core.$strip>;
|
|
58
|
+
/**
|
|
59
|
+
* Feature flags published by an adapter via `agent.capabilities`. Use to
|
|
60
|
+
* branch on capability before sending a request the adapter doesn't support
|
|
61
|
+
* (e.g. structured output, image input, MCP servers, permission handlers).
|
|
62
|
+
*/
|
|
33
63
|
type AgentCapabilities = z.infer<typeof agentCapabilitiesSchema>;
|
|
64
|
+
/** JSON Schema (Draft 7+) object, or a value produced by `z.toJSONSchema(...)`. */
|
|
34
65
|
type JsonSchema = Record<string, unknown> | ReturnType<typeof z.toJSONSchema>;
|
|
66
|
+
/** Either a JSON Schema or a Zod schema. Accepted by structured-output requests. */
|
|
35
67
|
type OutputSchema = JsonSchema | ZodType;
|
|
68
|
+
/**
|
|
69
|
+
* Common shape for MCP (Model Context Protocol) server configurations passed
|
|
70
|
+
* through to adapters. Adapters interpret the fields as needed — most accept
|
|
71
|
+
* both stdio (`command` + `args`) and HTTP (`url`) transports.
|
|
72
|
+
*/
|
|
36
73
|
interface McpServerConfig {
|
|
74
|
+
/** Executable for stdio-transport MCP servers. */
|
|
37
75
|
command?: string;
|
|
76
|
+
/** Arguments for the stdio executable. */
|
|
38
77
|
args?: string[];
|
|
78
|
+
/** Endpoint URL for HTTP/SSE-transport MCP servers. */
|
|
39
79
|
url?: string;
|
|
80
|
+
/** Working directory for the stdio MCP server subprocess. */
|
|
40
81
|
cwd?: string;
|
|
82
|
+
/** Environment variables for the stdio MCP server subprocess. */
|
|
41
83
|
env?: Record<string, string>;
|
|
84
|
+
/** HTTP headers for HTTP/SSE-transport MCP servers. */
|
|
42
85
|
headers?: Record<string, string>;
|
|
43
86
|
}
|
|
44
87
|
//#endregion
|
|
45
88
|
//#region src/schemas/events.d.ts
|
|
89
|
+
/** Fields shared by every {@link AgentEvent}. */
|
|
46
90
|
declare const baseEventSchema: z.ZodObject<{
|
|
47
91
|
id: z.ZodString;
|
|
48
92
|
runId: z.ZodString;
|
|
49
93
|
timestamp: z.ZodDate;
|
|
50
94
|
}, z.core.$strip>;
|
|
95
|
+
/**
|
|
96
|
+
* Emitted once at the start of a run, after the session has been created or
|
|
97
|
+
* resumed but before any model output. `resumed` is `true` when the run
|
|
98
|
+
* attached to an existing session via `requestedSessionId`.
|
|
99
|
+
*/
|
|
51
100
|
declare const sessionStartEventSchema: z.ZodObject<{
|
|
52
101
|
id: z.ZodString;
|
|
53
102
|
runId: z.ZodString;
|
|
@@ -57,7 +106,17 @@ declare const sessionStartEventSchema: z.ZodObject<{
|
|
|
57
106
|
sessionId: z.ZodOptional<z.ZodString>;
|
|
58
107
|
resumed: z.ZodBoolean;
|
|
59
108
|
}, z.core.$strip>;
|
|
109
|
+
/**
|
|
110
|
+
* Emitted once at the start of a run, after the session has been created or
|
|
111
|
+
* resumed but before any model output. `resumed` is `true` when the run
|
|
112
|
+
* attached to an existing session via `requestedSessionId`.
|
|
113
|
+
*/
|
|
60
114
|
type SessionStartEvent = z.infer<typeof sessionStartEventSchema>;
|
|
115
|
+
/**
|
|
116
|
+
* A complete chat message — assistant, user echo, or system. Adapters that
|
|
117
|
+
* emit assistant messages mid-stream coalesce them into one event per logical
|
|
118
|
+
* message; consumers should not expect per-token deltas.
|
|
119
|
+
*/
|
|
61
120
|
declare const messageEventSchema: z.ZodObject<{
|
|
62
121
|
id: z.ZodString;
|
|
63
122
|
runId: z.ZodString;
|
|
@@ -80,7 +139,18 @@ declare const messageEventSchema: z.ZodObject<{
|
|
|
80
139
|
}, z.core.$strip>], "type">>;
|
|
81
140
|
text: z.ZodOptional<z.ZodString>;
|
|
82
141
|
}, z.core.$strip>;
|
|
142
|
+
/**
|
|
143
|
+
* A complete chat message — assistant, user echo, or system. Adapters that
|
|
144
|
+
* stream assistant text coalesce chunks into one event per logical message;
|
|
145
|
+
* consumers should not expect per-token deltas. The `text` field is a flat
|
|
146
|
+
* convenience concatenation of all text blocks in `content`.
|
|
147
|
+
*/
|
|
83
148
|
type MessageEvent = z.infer<typeof messageEventSchema>;
|
|
149
|
+
/**
|
|
150
|
+
* Model reasoning / chain-of-thought output, emitted by providers that
|
|
151
|
+
* support it (Claude extended thinking, Codex reasoning summaries). Not all
|
|
152
|
+
* adapters emit these.
|
|
153
|
+
*/
|
|
84
154
|
declare const reasoningEventSchema: z.ZodObject<{
|
|
85
155
|
id: z.ZodString;
|
|
86
156
|
runId: z.ZodString;
|
|
@@ -98,7 +168,16 @@ declare const reasoningEventSchema: z.ZodObject<{
|
|
|
98
168
|
}, z.core.$strip>], "type">>;
|
|
99
169
|
text: z.ZodOptional<z.ZodString>;
|
|
100
170
|
}, z.core.$strip>;
|
|
171
|
+
/**
|
|
172
|
+
* Model reasoning / chain-of-thought output, emitted by providers that
|
|
173
|
+
* support it (Claude extended thinking, Codex reasoning summaries). Not all
|
|
174
|
+
* adapters emit these.
|
|
175
|
+
*/
|
|
101
176
|
type ReasoningEvent = z.infer<typeof reasoningEventSchema>;
|
|
177
|
+
/**
|
|
178
|
+
* Model invoked a tool with the given input. Pair with the subsequent
|
|
179
|
+
* {@link ToolResultEvent} sharing the same `toolCallId`.
|
|
180
|
+
*/
|
|
102
181
|
declare const toolCallEventSchema: z.ZodObject<{
|
|
103
182
|
id: z.ZodString;
|
|
104
183
|
runId: z.ZodString;
|
|
@@ -110,7 +189,16 @@ declare const toolCallEventSchema: z.ZodObject<{
|
|
|
110
189
|
toolName: z.ZodString;
|
|
111
190
|
input: z.ZodOptional<z.ZodUnknown>;
|
|
112
191
|
}, z.core.$strip>;
|
|
192
|
+
/**
|
|
193
|
+
* The model invoked a tool with the given input. Pair with the subsequent
|
|
194
|
+
* {@link ToolResultEvent} sharing the same `toolCallId`.
|
|
195
|
+
*/
|
|
113
196
|
type ToolCallEvent = z.infer<typeof toolCallEventSchema>;
|
|
197
|
+
/**
|
|
198
|
+
* Result of a tool invocation. `isError`/`error` populated when the tool
|
|
199
|
+
* itself returned a failure (not when the framework couldn't dispatch the
|
|
200
|
+
* call — that yields a {@link StderrEvent} or a failed run instead).
|
|
201
|
+
*/
|
|
114
202
|
declare const toolResultEventSchema: z.ZodObject<{
|
|
115
203
|
id: z.ZodString;
|
|
116
204
|
runId: z.ZodString;
|
|
@@ -124,7 +212,16 @@ declare const toolResultEventSchema: z.ZodObject<{
|
|
|
124
212
|
isError: z.ZodOptional<z.ZodBoolean>;
|
|
125
213
|
error: z.ZodOptional<z.ZodString>;
|
|
126
214
|
}, z.core.$strip>;
|
|
215
|
+
/**
|
|
216
|
+
* Result of a tool invocation. `isError` / `error` are populated when the
|
|
217
|
+
* tool itself reported failure (framework-level dispatch failures yield a
|
|
218
|
+
* {@link StderrEvent} or a failed run instead).
|
|
219
|
+
*/
|
|
127
220
|
type ToolResultEvent = z.infer<typeof toolResultEventSchema>;
|
|
221
|
+
/**
|
|
222
|
+
* Captured stderr text from the underlying CLI subprocess (CLI adapters
|
|
223
|
+
* only). Useful for surfacing provider diagnostics.
|
|
224
|
+
*/
|
|
128
225
|
declare const stderrEventSchema: z.ZodObject<{
|
|
129
226
|
id: z.ZodString;
|
|
130
227
|
runId: z.ZodString;
|
|
@@ -133,7 +230,16 @@ declare const stderrEventSchema: z.ZodObject<{
|
|
|
133
230
|
sessionId: z.ZodOptional<z.ZodString>;
|
|
134
231
|
text: z.ZodString;
|
|
135
232
|
}, z.core.$strip>;
|
|
233
|
+
/**
|
|
234
|
+
* Captured stderr text from the underlying CLI subprocess (CLI adapters
|
|
235
|
+
* only). Useful for surfacing provider diagnostics.
|
|
236
|
+
*/
|
|
136
237
|
type StderrEvent = z.infer<typeof stderrEventSchema>;
|
|
238
|
+
/**
|
|
239
|
+
* Emitted exactly once at the end of a run, just before the `RunResult`
|
|
240
|
+
* promise resolves. Mirrors the run's terminal status; on failure, `error`
|
|
241
|
+
* carries a human-readable summary.
|
|
242
|
+
*/
|
|
137
243
|
declare const sessionEndEventSchema: z.ZodObject<{
|
|
138
244
|
id: z.ZodString;
|
|
139
245
|
runId: z.ZodString;
|
|
@@ -147,7 +253,26 @@ declare const sessionEndEventSchema: z.ZodObject<{
|
|
|
147
253
|
}>;
|
|
148
254
|
error: z.ZodOptional<z.ZodString>;
|
|
149
255
|
}, z.core.$strip>;
|
|
256
|
+
/**
|
|
257
|
+
* Emitted exactly once at the end of a run, just before the `RunResult`
|
|
258
|
+
* promise resolves. Mirrors the run's terminal status; on failure, `error`
|
|
259
|
+
* carries a human-readable summary.
|
|
260
|
+
*/
|
|
150
261
|
type SessionEndEvent = z.infer<typeof sessionEndEventSchema>;
|
|
262
|
+
/**
|
|
263
|
+
* Discriminated union over every event type. Listeners registered via
|
|
264
|
+
* `agent.onEvent(...)` receive one of these. Narrow on `event.type`:
|
|
265
|
+
*
|
|
266
|
+
* ```ts
|
|
267
|
+
* agent.onEvent((event) => {
|
|
268
|
+
* switch (event.type) {
|
|
269
|
+
* case "message": console.log(event.role, event.text); break;
|
|
270
|
+
* case "tool-call": console.log(event.toolName, event.input); break;
|
|
271
|
+
* case "session-end": console.log("done", event.status); break;
|
|
272
|
+
* }
|
|
273
|
+
* });
|
|
274
|
+
* ```
|
|
275
|
+
*/
|
|
151
276
|
declare const eventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
152
277
|
id: z.ZodString;
|
|
153
278
|
runId: z.ZodString;
|
|
@@ -235,6 +360,20 @@ declare const eventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
235
360
|
}>;
|
|
236
361
|
error: z.ZodOptional<z.ZodString>;
|
|
237
362
|
}, z.core.$strip>], "type">;
|
|
363
|
+
/**
|
|
364
|
+
* Discriminated union over every event the SDK emits during a run.
|
|
365
|
+
* Registered via `agent.onEvent(handler)`. Narrow on `event.type`:
|
|
366
|
+
*
|
|
367
|
+
* ```ts
|
|
368
|
+
* agent.onEvent((event) => {
|
|
369
|
+
* switch (event.type) {
|
|
370
|
+
* case "message": console.log(event.role, event.text); break;
|
|
371
|
+
* case "tool-call": console.log(event.toolName, event.input); break;
|
|
372
|
+
* case "session-end": console.log("done", event.status); break;
|
|
373
|
+
* }
|
|
374
|
+
* });
|
|
375
|
+
* ```
|
|
376
|
+
*/
|
|
238
377
|
type AgentEvent = z.infer<typeof eventSchema>;
|
|
239
378
|
//#endregion
|
|
240
379
|
export { OutputSchema as C, imageContentPartSchema as D, contentPartSchema as E, textContentPartSchema as O, McpServerConfig as S, agentCapabilitiesSchema as T, toolResultEventSchema as _, SessionStartEvent as a, ImageContentPart as b, ToolResultEvent as c, messageEventSchema as d, reasoningEventSchema as f, toolCallEventSchema as g, stderrEventSchema as h, SessionEndEvent as i, baseEventSchema as l, sessionStartEventSchema as m, MessageEvent as n, StderrEvent as o, sessionEndEventSchema as p, ReasoningEvent as r, ToolCallEvent as s, AgentEvent as t, eventSchema as u, AgentCapabilities as v, TextContentPart as w, JsonSchema as x, ContentPart as y };
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { S as McpServerConfig } from "./events-Bwfw__Q3.mjs";
|
|
2
|
+
import { f as EnsureDisjoint, l as BaseAgent, p as ExclusiveExecutionTargetOptions, t as AgentEventHandler } from "./types-Bk-YpdbX.mjs";
|
|
3
|
+
import { t as Container } from "./index-BeejNCvc.mjs";
|
|
4
|
+
import { c as Sandbox } from "./index-C8wbKjj3.mjs";
|
|
5
|
+
import { i as ClaudeCodeCliPermissionMode } from "./index-BQNj8DHq.mjs";
|
|
6
|
+
|
|
7
|
+
//#region src/adapters/claude-code-cli-pty/types.d.ts
|
|
8
|
+
/** Same modes as {@link ClaudeCodeCliPermissionMode}; re-exported for convenience. */
|
|
9
|
+
type ClaudeCodeCliPtyPermissionMode = ClaudeCodeCliPermissionMode;
|
|
10
|
+
interface ClaudeCodeCliPtyExitEvent {
|
|
11
|
+
exitCode: number;
|
|
12
|
+
signal?: number | string;
|
|
13
|
+
}
|
|
14
|
+
/** Minimal pseudo-terminal handle the adapter speaks to. Returned by {@link ClaudeCodeCliPtyModule.spawn}. */
|
|
15
|
+
interface ClaudeCodeCliPtyProcess {
|
|
16
|
+
/** Send bytes (typically input or a control sequence) to the PTY. May buffer; not required to flush synchronously. */
|
|
17
|
+
write: (data: string) => void;
|
|
18
|
+
/** Send a signal (default `"SIGTERM"`) to the underlying process. Idempotent — repeat calls after exit are ignored. */
|
|
19
|
+
kill: (signal?: string) => void;
|
|
20
|
+
/** Subscribe to raw stdout/stderr chunks from the PTY. Returns a disposer that unsubscribes. */
|
|
21
|
+
onData: (handler: (data: string) => void) => {
|
|
22
|
+
dispose: () => void;
|
|
23
|
+
};
|
|
24
|
+
/** Subscribe to the PTY's exit event. Fires once with exit code and optional signal. Returns a disposer. */
|
|
25
|
+
onExit: (handler: (event: ClaudeCodeCliPtyExitEvent) => void) => {
|
|
26
|
+
dispose: () => void;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Bring-your-own PTY backend. Supply a module exposing `spawn` to use a
|
|
31
|
+
* specific PTY implementation (e.g. `node-pty`); the adapter will use it
|
|
32
|
+
* instead of falling back to the bundled spawner.
|
|
33
|
+
*/
|
|
34
|
+
interface ClaudeCodeCliPtyModule {
|
|
35
|
+
spawn: (command: string, args: string[], options: {
|
|
36
|
+
cols?: number;
|
|
37
|
+
rows?: number;
|
|
38
|
+
cwd?: string;
|
|
39
|
+
env?: Record<string, string>;
|
|
40
|
+
initialInputBootstrapPath?: string;
|
|
41
|
+
initialInputPath?: string;
|
|
42
|
+
}) => ClaudeCodeCliPtyProcess;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Per-run options for the `claude-code-cli-pty` adapter — same as
|
|
46
|
+
* `claude-code-cli` plus PTY-specific timing knobs.
|
|
47
|
+
*/
|
|
48
|
+
interface ClaudeCodeCliPtyRunOptions {
|
|
49
|
+
/** Allowlist of tool names. */
|
|
50
|
+
allowedTools?: string[];
|
|
51
|
+
/** Denylist of tool names. */
|
|
52
|
+
disallowedTools?: string[];
|
|
53
|
+
/** Text appended to Claude Code's default system prompt. */
|
|
54
|
+
appendSystemPrompt?: string;
|
|
55
|
+
/** Permission strategy for this run. See {@link ClaudeCodeCliPtyPermissionMode}. */
|
|
56
|
+
permissionMode?: ClaudeCodeCliPtyPermissionMode;
|
|
57
|
+
/** Path(s) to MCP server config files passed via `--mcp-config`. */
|
|
58
|
+
mcpConfig?: string[] | string;
|
|
59
|
+
/** Inline MCP server config map. */
|
|
60
|
+
mcpServers?: Record<string, McpServerConfig>;
|
|
61
|
+
/** Start a fresh fork off the current session rather than continuing it. */
|
|
62
|
+
forkSession?: boolean;
|
|
63
|
+
/** Extra CLI flags appended verbatim. */
|
|
64
|
+
extraArgs?: string[];
|
|
65
|
+
/** How long to wait for the PTY to report ready, in milliseconds. */
|
|
66
|
+
readinessTimeoutMs?: number;
|
|
67
|
+
/** How long to wait for Claude Code's Stop hook to drain, in milliseconds. */
|
|
68
|
+
stopHookTimeoutMs?: number;
|
|
69
|
+
}
|
|
70
|
+
/** Constructor options for `createAgent("claude-code-cli-pty", ...)`. */
|
|
71
|
+
type ClaudeCodeCliPtyAgentOptions = ClaudeCodeCliPtyRunOptions & ExclusiveExecutionTargetOptions<Container, Sandbox> & {
|
|
72
|
+
/** Path or argv to the `claude` binary. */command?: string[] | string; /** Working directory the agent operates against. */
|
|
73
|
+
cwd?: string; /** Environment variables for the subprocess. */
|
|
74
|
+
env?: Record<string, string>; /** Inherit `process.env` and overlay `env` on top, instead of replacing. */
|
|
75
|
+
propagateEnv?: boolean; /** Existing session ID to resume via `--resume`. */
|
|
76
|
+
sessionId?: string; /** Model identifier (e.g. `"claude-sonnet-4-6"`). */
|
|
77
|
+
model?: string; /** Replaces Claude Code's default system prompt entirely. */
|
|
78
|
+
systemPrompt?: string; /** File path to write the raw CLI log to (useful for debugging). */
|
|
79
|
+
logPath?: string; /** Sets `CI=true` in the subprocess env unless explicitly `false`. Default: `true`. */
|
|
80
|
+
ci?: boolean; /** Optional PTY module override. See {@link ClaudeCodeCliPtyModule}. */
|
|
81
|
+
pty?: ClaudeCodeCliPtyModule; /** Convenience: equivalent to calling `agent.onEvent(handler)` post-construction. */
|
|
82
|
+
onEvent?: AgentEventHandler;
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Agent instance returned by `createAgent("claude-code-cli-pty", ...)`.
|
|
86
|
+
*
|
|
87
|
+
* Runs Claude Code under a pseudo-terminal — required for permission prompts
|
|
88
|
+
* to render interactively. Prefer `claude-code-cli` for non-interactive use.
|
|
89
|
+
*/
|
|
90
|
+
interface ClaudeCodeCliPtyAgent extends BaseAgent<EnsureDisjoint<ClaudeCodeCliPtyRunOptions>> {
|
|
91
|
+
readonly type: "claude-code-cli-pty";
|
|
92
|
+
/**
|
|
93
|
+
* Branch a sibling agent from the current session.
|
|
94
|
+
*
|
|
95
|
+
* Throws `AgentValidationError` when called before this agent has
|
|
96
|
+
* acquired a session ID — run at least one prompt first.
|
|
97
|
+
*/
|
|
98
|
+
fork: () => ClaudeCodeCliPtyAgent;
|
|
99
|
+
}
|
|
100
|
+
//#endregion
|
|
101
|
+
//#region src/adapters/claude-code-cli-pty/adapter.d.ts
|
|
102
|
+
declare const createClaudeCodeCliPtyAgent: (options?: ClaudeCodeCliPtyAgentOptions) => ClaudeCodeCliPtyAgent;
|
|
103
|
+
//#endregion
|
|
104
|
+
export { ClaudeCodeCliPtyPermissionMode as a, ClaudeCodeCliPtyModule as i, ClaudeCodeCliPtyAgent as n, ClaudeCodeCliPtyProcess as o, ClaudeCodeCliPtyAgentOptions as r, ClaudeCodeCliPtyRunOptions as s, createClaudeCodeCliPtyAgent as t };
|