coding-agents-sdk 0.10.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -9
- package/dist/Agent-4TZ8JK66.mjs +4 -0
- package/dist/{SdkAgent-DQfLwPwY.mjs → SdkAgent-p0nJ6dWV.mjs} +1 -1
- package/dist/adapters/claude-code-cli/index.d.mts +2 -2
- package/dist/adapters/claude-code-cli/index.mjs +1 -1
- package/dist/adapters/claude-code-cli-pty/index.d.mts +3 -0
- package/dist/adapters/claude-code-cli-pty/index.mjs +35 -0
- package/dist/adapters/claude-code-sdk/index.d.mts +2 -2
- package/dist/adapters/claude-code-sdk/index.mjs +4 -4
- package/dist/adapters/codex-cli/index.d.mts +2 -2
- package/dist/adapters/codex-cli/index.mjs +2 -2
- package/dist/adapters/codex-sdk/index.d.mts +2 -2
- package/dist/adapters/codex-sdk/index.mjs +1 -1
- package/dist/adapters/cursor-cli/index.d.mts +2 -2
- package/dist/adapters/cursor-cli/index.mjs +1 -1
- package/dist/adapters/cursor-sdk/index.d.mts +2 -2
- package/dist/adapters/cursor-sdk/index.mjs +1 -1
- package/dist/adapters/gemini-cli/index.d.mts +2 -2
- package/dist/adapters/gemini-cli/index.mjs +1 -1
- package/dist/adapters/opencode-cli/index.d.mts +2 -2
- package/dist/adapters/opencode-cli/index.mjs +1 -1
- package/dist/adapters/pi-cli/index.d.mts +2 -2
- package/dist/adapters/pi-cli/index.mjs +1 -1
- package/dist/{classify-error-BcWmNftw.mjs → classify-error-BPQtzEVV.mjs} +4 -4
- package/dist/container/index.d.mts +2 -2
- package/dist/container/index.mjs +1 -1
- package/dist/{container-D31bbA4L.mjs → container-46QA1d3v.mjs} +1 -1
- package/dist/container-DBXaA-Iv.mjs +1 -0
- package/dist/container-DRj7xq5x.mjs +1 -0
- package/dist/{container-BhXUiAiK.mjs → container-Dg68bfte.mjs} +1 -1
- package/dist/{container-TizHce_7.mjs → container-gJ8B-Z5B.mjs} +1 -1
- package/dist/diff-BJWXJsjx.mjs +1 -0
- package/dist/{events-Dd9r9luo.d.mts → events-B0BpIsW2.d.mts} +143 -4
- package/dist/execution-target-CdlYXh6Z.mjs +1 -0
- package/dist/index-5bx9TIY_.d.mts +60 -0
- package/dist/index-B5NFoNlS.d.mts +195 -0
- package/dist/index-B9ze9hTN.d.mts +97 -0
- package/dist/{index-DZDlHIep.d.mts → index-BKK-3gye.d.mts} +44 -13
- package/dist/{index-J7V9dJTb.d.mts → index-BQ8cUo2i.d.mts} +50 -19
- package/dist/index-C9XD71QR.d.mts +429 -0
- package/dist/{index-B-rto_J2.d.mts → index-CG2m7pFJ.d.mts} +77 -1
- package/dist/index-CG5DS_NB.d.mts +58 -0
- package/dist/index-DPP4zoiJ.d.mts +68 -0
- package/dist/{index-BNeL0BbU.d.mts → index-DdyD2ji1.d.mts} +68 -2
- package/dist/index-DzFF15zC.d.mts +104 -0
- package/dist/index-XWqpUSBc.d.mts +69 -0
- package/dist/index.d.mts +69 -16
- package/dist/index.mjs +1 -1
- package/dist/oci-DmEG3Ia3.mjs +1 -0
- package/dist/{parser-BBJPNGZ2.mjs → parser-Dz239_vv.mjs} +2 -2
- package/dist/sandbox/index.d.mts +2 -2
- package/dist/sandbox/index.mjs +1 -1
- package/dist/sandbox-C5vzNxZR.mjs +4 -0
- package/dist/schemas/index.d.mts +1 -1
- package/dist/schemas/index.mjs +1 -1
- package/dist/spawner-BB6W3FVi.mjs +1 -0
- package/dist/types-CGzSzwfB.d.mts +476 -0
- package/dist/util-DcPzh_0u.mjs +1 -0
- package/package.json +24 -24
- package/dist/Agent-BD2xHVi0.mjs +0 -4
- package/dist/adapters/claude-cli-pty/index.d.mts +0 -3
- package/dist/adapters/claude-cli-pty/index.mjs +0 -7
- package/dist/container-BurV5WG9.mjs +0 -1
- package/dist/diff-DWM1ciiV.mjs +0 -1
- package/dist/errors-CeKI_bYK.mjs +0 -1
- package/dist/execution-target-CGTSqVEP.mjs +0 -1
- package/dist/index-B4RAMnx_.d.mts +0 -46
- package/dist/index-BdDz7C4J.d.mts +0 -39
- package/dist/index-BiWkGgnz.d.mts +0 -46
- package/dist/index-BllemWbi.d.mts +0 -42
- package/dist/index-C7J_hmQs.d.mts +0 -67
- package/dist/index-CaUzD36R.d.mts +0 -42
- package/dist/index-D-8EmRnQ.d.mts +0 -85
- package/dist/index-lGZ1lQkG.d.mts +0 -246
- package/dist/oci-tjdSZfTm.mjs +0 -1
- package/dist/sandbox-_As0qZWn.mjs +0 -4
- package/dist/spawner-BJesLc8I.mjs +0 -1
- package/dist/types-D6kxBNzj.d.mts +0 -195
- package/dist/util-CGg8cK92.mjs +0 -1
- /package/dist/{env-DIXTVzTs.mjs → env-Cb8MIvH7.mjs} +0 -0
- /package/dist/{schemas-mNF2Xlg_.mjs → schemas-CkdQXAep.mjs} +0 -0
- /package/dist/{shell-Dewbmt9R.mjs → shell-DvWFuFKb.mjs} +0 -0
- /package/dist/{structured-output-nPFh_ZoY.mjs → structured-output-cpLrrrTN.mjs} +0 -0
- /package/dist/{types-CwvWHEpy.mjs → types-B72tDMEZ.mjs} +0 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { A as ProcessSpawner, f as EnsureDisjoint, l as BaseAgent, p as ExclusiveExecutionTargetOptions, t as AgentEventHandler } from "./types-CGzSzwfB.mjs";
|
|
2
|
+
import { t as Container } from "./index-C9XD71QR.mjs";
|
|
3
|
+
import { l as Sandbox } from "./index-B5NFoNlS.mjs";
|
|
4
|
+
import { z } from "zod/v4";
|
|
5
|
+
|
|
6
|
+
//#region src/adapters/pi-cli/events/schemas.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* Permissive raw-event shape for Pi CLI: `{ type: string }` plus arbitrary
|
|
9
|
+
* additional fields the CLI may emit.
|
|
10
|
+
*/
|
|
11
|
+
declare const piEventSchema: z.ZodObject<{
|
|
12
|
+
type: z.ZodString;
|
|
13
|
+
}, z.core.$loose>;
|
|
14
|
+
type PiEvent = z.infer<typeof piEventSchema>;
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/adapters/pi-cli/types.d.ts
|
|
17
|
+
/** How much hidden reasoning Pi should perform per turn. */
|
|
18
|
+
type PiCliThinkingLevel = "high" | "low" | "medium" | "minimal" | "off" | "xhigh";
|
|
19
|
+
/** Per-run options for the `pi-cli` adapter. */
|
|
20
|
+
interface PiCliRunOptions {
|
|
21
|
+
/** Backend provider override (`"anthropic"`, `"openai"`, etc.). */
|
|
22
|
+
provider?: string;
|
|
23
|
+
/** Thinking budget for the run. */
|
|
24
|
+
thinking?: PiCliThinkingLevel;
|
|
25
|
+
/** Text appended to Pi's default system prompt. */
|
|
26
|
+
appendSystemPrompt?: string;
|
|
27
|
+
/** Allowlist of tool names. */
|
|
28
|
+
tools?: string[];
|
|
29
|
+
/** Disable all tool use for this run. */
|
|
30
|
+
noTools?: boolean;
|
|
31
|
+
/** Run without persisting session history. */
|
|
32
|
+
noSession?: boolean;
|
|
33
|
+
/** Directory where session files are persisted. */
|
|
34
|
+
sessionDir?: string;
|
|
35
|
+
/** Branch a new session off the current one. */
|
|
36
|
+
forkSession?: boolean;
|
|
37
|
+
/** Extra CLI flags appended verbatim. */
|
|
38
|
+
extraArgs?: string[];
|
|
39
|
+
}
|
|
40
|
+
/** Constructor options for `createAgent("pi-cli", ...)`. */
|
|
41
|
+
type PiCliAgentOptions = ExclusiveExecutionTargetOptions<Container, Sandbox> & PiCliRunOptions & {
|
|
42
|
+
/** Path or argv to the `pi` binary. */command?: string[] | string; /** Working directory the agent operates against. */
|
|
43
|
+
cwd?: string; /** Environment variables for the subprocess. Layered on top of host env when `propagateEnv` is `true` (default). */
|
|
44
|
+
env?: Record<string, string>; /** Default `true`: `process.env` is inherited and `env` overlays it. Set `false` to suppress host-env propagation. */
|
|
45
|
+
propagateEnv?: boolean; /** Existing Pi session ID to resume. */
|
|
46
|
+
sessionId?: string; /** Pi model identifier (provider-dependent). */
|
|
47
|
+
model?: string; /** Replaces Pi's default system prompt entirely; use `appendSystemPrompt` to add to it. */
|
|
48
|
+
systemPrompt?: string; /** File path to write the raw CLI log to (useful for debugging). */
|
|
49
|
+
logPath?: string; /** Custom process spawner; set by `createContainer`/`createSandbox`, rarely needed manually. */
|
|
50
|
+
spawner?: ProcessSpawner; /** Convenience: equivalent to calling `agent.onEvent(handler)` post-construction. */
|
|
51
|
+
onEvent?: AgentEventHandler;
|
|
52
|
+
};
|
|
53
|
+
/** Agent instance returned by `createAgent("pi-cli", ...)`. */
|
|
54
|
+
interface PiCliAgent extends BaseAgent<EnsureDisjoint<PiCliRunOptions>> {
|
|
55
|
+
readonly type: "pi-cli";
|
|
56
|
+
/**
|
|
57
|
+
* Branch a sibling agent from the current session.
|
|
58
|
+
*
|
|
59
|
+
* Throws `AgentValidationError` when called before this agent has
|
|
60
|
+
* acquired a session ID — run at least one prompt first.
|
|
61
|
+
*/
|
|
62
|
+
fork: () => PiCliAgent;
|
|
63
|
+
}
|
|
64
|
+
//#endregion
|
|
65
|
+
//#region src/adapters/pi-cli/adapter.d.ts
|
|
66
|
+
declare const createPiCliAgent: (options?: PiCliAgentOptions) => PiCliAgent;
|
|
67
|
+
//#endregion
|
|
68
|
+
export { PiCliThinkingLevel as a, PiCliRunOptions as i, PiCliAgent as n, PiEvent as o, PiCliAgentOptions as r, createPiCliAgent as t };
|
|
@@ -1,10 +1,15 @@
|
|
|
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-CGzSzwfB.mjs";
|
|
2
2
|
//#region src/adapters/cursor-sdk/types.d.ts
|
|
3
|
+
/** OAuth-style credentials for HTTP/SSE MCP servers configured for the agent. */
|
|
3
4
|
interface CursorSdkMcpHttpAuth {
|
|
4
5
|
CLIENT_ID: string;
|
|
5
6
|
CLIENT_SECRET?: string;
|
|
6
7
|
scopes?: string[];
|
|
7
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* MCP server config accepted by the Cursor SDK. Either an HTTP/SSE endpoint
|
|
11
|
+
* or a stdio command spawned by the SDK runtime.
|
|
12
|
+
*/
|
|
8
13
|
type CursorSdkMcpServerConfig = {
|
|
9
14
|
type?: "http" | "sse";
|
|
10
15
|
url: string;
|
|
@@ -17,11 +22,21 @@ type CursorSdkMcpServerConfig = {
|
|
|
17
22
|
env?: Record<string, string>;
|
|
18
23
|
cwd?: string;
|
|
19
24
|
};
|
|
25
|
+
/**
|
|
26
|
+
* Which Cursor settings layers to load from the local filesystem. Forwarded
|
|
27
|
+
* as `local.settingSources` to `Agent.create`. `"all"` loads everything;
|
|
28
|
+
* `"project"`, `"user"`, `"team"`, `"plugins"`, `"mdm"` load only that layer.
|
|
29
|
+
*/
|
|
20
30
|
type CursorSdkSettingSource = "all" | "mdm" | "plugins" | "project" | "team" | "user";
|
|
31
|
+
/** One model parameter (e.g. reasoning effort) for {@link CursorSdkModelSelection}. */
|
|
21
32
|
interface CursorSdkModelParameterValue {
|
|
22
33
|
id: string;
|
|
23
34
|
value: string;
|
|
24
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* Internal model selection shape used by the Cursor SDK. Most callers pass a
|
|
38
|
+
* plain model ID string and let the adapter wrap it.
|
|
39
|
+
*/
|
|
25
40
|
interface CursorSdkModelSelection {
|
|
26
41
|
id: string;
|
|
27
42
|
params?: CursorSdkModelParameterValue[];
|
|
@@ -103,20 +118,71 @@ interface CursorSdkTaskEvent {
|
|
|
103
118
|
status?: string;
|
|
104
119
|
text?: string;
|
|
105
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* Discriminated union of raw events the Cursor SDK emits before this adapter
|
|
123
|
+
* normalizes them. Narrow on `event.type`:
|
|
124
|
+
*
|
|
125
|
+
* - `"system"` — init metadata (model, tools).
|
|
126
|
+
* - `"user"` — echo of the user prompt for this run.
|
|
127
|
+
* - `"assistant"` — model text/tool-use chunk (may arrive in fragments).
|
|
128
|
+
* - `"thinking"` — reasoning content with duration.
|
|
129
|
+
* - `"tool_call"` — tool invocation lifecycle (`running` → `completed`/`error`).
|
|
130
|
+
* - `"status"` — run lifecycle (`RUNNING`, `FINISHED`, etc.).
|
|
131
|
+
* - `"task"` — task-level milestones.
|
|
132
|
+
* - `"request"` — Cursor is asking for user input/approval (unsupported by this adapter).
|
|
133
|
+
*/
|
|
106
134
|
type CursorSdkEvent = CursorSdkAssistantEvent | CursorSdkRequestEvent | CursorSdkStatusEvent | CursorSdkSystemEvent | CursorSdkTaskEvent | CursorSdkThinkingEvent | CursorSdkToolCallEvent | CursorSdkUserEvent;
|
|
135
|
+
/**
|
|
136
|
+
* Per-run options for the `cursor-sdk` adapter. Merge with {@link RunRequest}
|
|
137
|
+
* when calling `agent.run(...)`.
|
|
138
|
+
*/
|
|
107
139
|
interface CursorSdkRunOptions {
|
|
108
|
-
|
|
140
|
+
/**
|
|
141
|
+
* Recovery-only flag. Forwards to `local.force` on `Agent.send(...)`, which
|
|
142
|
+
* expires a stale persisted "active run" left by a crashed previous
|
|
143
|
+
* process. Set this only when a normal send errors with "agent busy" /
|
|
144
|
+
* "active run exists." Not a routine option.
|
|
145
|
+
*/
|
|
146
|
+
force?: boolean;
|
|
147
|
+
/**
|
|
148
|
+
* Per-run MCP server overrides. Replaces the agent-level set if provided.
|
|
149
|
+
*/
|
|
109
150
|
mcpServers?: Record<string, CursorSdkMcpServerConfig>;
|
|
151
|
+
/** Not supported by the Cursor SDK — cursor manages its own system prompt. */
|
|
110
152
|
systemPrompt?: never;
|
|
111
153
|
}
|
|
154
|
+
/**
|
|
155
|
+
* Constructor options for `createAgent("cursor-sdk", ...)`. Passed to
|
|
156
|
+
* `Agent.create` (or `Agent.resume` if `sessionId` is set) under the hood.
|
|
157
|
+
*/
|
|
112
158
|
interface CursorSdkAgentOptions extends CursorSdkRunOptions {
|
|
159
|
+
/**
|
|
160
|
+
* Cursor API key. Falls back to `process.env.CURSOR_API_KEY` for some
|
|
161
|
+
* surfaces but the local `send` path requires it to be set explicitly.
|
|
162
|
+
*/
|
|
113
163
|
apiKey?: string;
|
|
164
|
+
/** Working directory passed as `local.cwd`. Defaults to `process.cwd()`. */
|
|
114
165
|
cwd?: string;
|
|
166
|
+
/**
|
|
167
|
+
* Existing Cursor agent ID to resume. When set, the adapter calls
|
|
168
|
+
* `Agent.resume(sessionId, ...)` on the first run instead of
|
|
169
|
+
* `Agent.create(...)`. Required if you don't pass a `model`.
|
|
170
|
+
*/
|
|
115
171
|
sessionId?: string;
|
|
172
|
+
/**
|
|
173
|
+
* Cursor model identifier (e.g. `"composer-2.5"`, `"claude-sonnet-4-6"`).
|
|
174
|
+
* Use `Cursor.models.list()` to enumerate; required for new local agents.
|
|
175
|
+
*/
|
|
116
176
|
model?: string;
|
|
177
|
+
/**
|
|
178
|
+
* Cursor settings layers to load from the local filesystem (`"project"`,
|
|
179
|
+
* `"user"`, etc.). Defaults to nothing if omitted.
|
|
180
|
+
*/
|
|
117
181
|
settingSources?: CursorSdkSettingSource[];
|
|
182
|
+
/** Convenience: equivalent to calling `agent.onEvent(handler)` post-construction. */
|
|
118
183
|
onEvent?: AgentEventHandler;
|
|
119
184
|
}
|
|
185
|
+
/** Agent instance returned by `createAgent("cursor-sdk", ...)`. */
|
|
120
186
|
interface CursorSdkAgent extends BaseAgent<EnsureDisjoint<CursorSdkRunOptions>> {
|
|
121
187
|
readonly type: "cursor-sdk";
|
|
122
188
|
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { S as McpServerConfig } from "./events-B0BpIsW2.mjs";
|
|
2
|
+
import { f as EnsureDisjoint, l as BaseAgent, p as ExclusiveExecutionTargetOptions, t as AgentEventHandler } from "./types-CGzSzwfB.mjs";
|
|
3
|
+
import { t as Container } from "./index-C9XD71QR.mjs";
|
|
4
|
+
import { l as Sandbox } from "./index-B5NFoNlS.mjs";
|
|
5
|
+
import { i as ClaudeCodeCliPermissionMode } from "./index-BQ8cUo2i.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 };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { A as ProcessSpawner, f as EnsureDisjoint, l as BaseAgent, p as ExclusiveExecutionTargetOptions, t as AgentEventHandler } from "./types-CGzSzwfB.mjs";
|
|
2
|
+
import { t as Container } from "./index-C9XD71QR.mjs";
|
|
3
|
+
import { l as Sandbox } from "./index-B5NFoNlS.mjs";
|
|
4
|
+
import { z } from "zod/v4";
|
|
5
|
+
|
|
6
|
+
//#region src/adapters/cursor-cli/events/schemas.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* Permissive raw-event shape for Cursor CLI: `{ type: string }` plus
|
|
9
|
+
* arbitrary additional fields the CLI may emit.
|
|
10
|
+
*/
|
|
11
|
+
declare const cursorCliEventSchema: z.ZodObject<{
|
|
12
|
+
type: z.ZodString;
|
|
13
|
+
}, z.core.$loose>;
|
|
14
|
+
type CursorCliEvent = z.infer<typeof cursorCliEventSchema>;
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/adapters/cursor-cli/types.d.ts
|
|
17
|
+
/**
|
|
18
|
+
* Cursor CLI run mode.
|
|
19
|
+
* - `"ask"`: interactive question-answering mode (default).
|
|
20
|
+
* - `"plan"`: read-only planning mode; the agent proposes changes but doesn't apply them.
|
|
21
|
+
*/
|
|
22
|
+
type CursorCliMode = "ask" | "plan";
|
|
23
|
+
/**
|
|
24
|
+
* Cursor CLI sandbox toggle. Cursor's CLI exposes a binary on/off knob; for
|
|
25
|
+
* granular policy, use the `sandbox` option from `createSandbox(...)`.
|
|
26
|
+
*/
|
|
27
|
+
type CursorCliSandboxMode = "disabled" | "enabled";
|
|
28
|
+
/** Per-run options for the `cursor-cli` adapter. */
|
|
29
|
+
interface CursorCliRunOptions {
|
|
30
|
+
/** Auto-approve MCP tool prompts that would otherwise wait for user confirmation. */
|
|
31
|
+
approveMcps?: boolean;
|
|
32
|
+
/** Extra CLI flags appended verbatim. */
|
|
33
|
+
extraArgs?: string[];
|
|
34
|
+
/**
|
|
35
|
+
* Recovery flag — expire a stale active run on the local agent before
|
|
36
|
+
* starting this one. See cursor-sdk's `force` for context. Routine
|
|
37
|
+
* sends should leave this unset.
|
|
38
|
+
*/
|
|
39
|
+
force?: boolean;
|
|
40
|
+
/** Run mode (`"ask"` or `"plan"`). */
|
|
41
|
+
mode?: CursorCliMode;
|
|
42
|
+
/** Sandbox toggle. See {@link CursorCliSandboxMode}. */
|
|
43
|
+
sandboxMode?: CursorCliSandboxMode;
|
|
44
|
+
/** Mark the working directory as trusted, bypassing first-run trust prompts. */
|
|
45
|
+
trust?: boolean;
|
|
46
|
+
/** Not supported — Cursor manages its own system prompt. */
|
|
47
|
+
systemPrompt?: never;
|
|
48
|
+
}
|
|
49
|
+
/** Constructor options for `createAgent("cursor-cli", ...)`. */
|
|
50
|
+
type CursorCliAgentOptions = CursorCliRunOptions & ExclusiveExecutionTargetOptions<Container, Sandbox> & {
|
|
51
|
+
/** Path or argv to the Cursor agent binary. Defaults to `"agent"` on `PATH`. */command?: string[] | string; /** Working directory the agent operates against. */
|
|
52
|
+
cwd?: string; /** Environment variables for the subprocess. Layered on top of host env when `propagateEnv` is `true` (default). */
|
|
53
|
+
env?: Record<string, string>; /** Default `true`: `process.env` is inherited and `env` overlays it. Set `false` to suppress host-env propagation. */
|
|
54
|
+
propagateEnv?: boolean; /** Existing Cursor agent ID to resume via `--resume`. */
|
|
55
|
+
sessionId?: string; /** Cursor model identifier. */
|
|
56
|
+
model?: string; /** File path to write the raw CLI log to (useful for debugging). */
|
|
57
|
+
logPath?: string; /** Custom process spawner; set by `createContainer`/`createSandbox`, rarely needed manually. */
|
|
58
|
+
spawner?: ProcessSpawner; /** Convenience: equivalent to calling `agent.onEvent(handler)` post-construction. */
|
|
59
|
+
onEvent?: AgentEventHandler;
|
|
60
|
+
};
|
|
61
|
+
/** Agent instance returned by `createAgent("cursor-cli", ...)`. */
|
|
62
|
+
interface CursorCliAgent extends BaseAgent<EnsureDisjoint<CursorCliRunOptions>> {
|
|
63
|
+
readonly type: "cursor-cli";
|
|
64
|
+
}
|
|
65
|
+
//#endregion
|
|
66
|
+
//#region src/adapters/cursor-cli/adapter.d.ts
|
|
67
|
+
declare const createCursorCliAgent: (options?: CursorCliAgentOptions) => CursorCliAgent;
|
|
68
|
+
//#endregion
|
|
69
|
+
export { CursorCliRunOptions as a, CursorCliMode as i, CursorCliAgent as n, CursorCliSandboxMode as o, CursorCliAgentOptions as r, CursorCliEvent as s, createCursorCliAgent as t };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,19 +1,71 @@
|
|
|
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, D as PermissionDecision, E as ZodRunRequest, O as PermissionHandler, 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, k as PermissionRequest, 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-
|
|
3
|
-
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, 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-
|
|
4
|
-
import { a as
|
|
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
|
|
7
|
-
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-
|
|
8
|
-
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-
|
|
9
|
-
import { a as CodexSdkItem, i as CodexSdkEvent, n as CodexSdkAgent, o as CodexSdkPermissionMode, r as CodexSdkAgentOptions, s as CodexSdkRunOptions } from "./index-
|
|
10
|
-
import { a as CursorCliRunOptions, i as CursorCliMode, n as CursorCliAgent, o as CursorCliSandboxMode, r as CursorCliAgentOptions, s as CursorCliEvent } from "./index-
|
|
11
|
-
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-
|
|
12
|
-
import { a as GeminiCliRunOptions, i as GeminiCliPermissionMode, n as GeminiCliAgent, o as GeminiEvent, r as GeminiCliAgentOptions } from "./index-
|
|
13
|
-
import { a as OpencodeEvent, i as OpencodeCliRunOptions, n as OpencodeCliAgent, r as OpencodeCliAgentOptions } from "./index-
|
|
14
|
-
import { a as PiCliThinkingLevel, i as PiCliRunOptions, n as PiCliAgent, o as PiEvent, r as PiCliAgentOptions } from "./index-
|
|
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-B0BpIsW2.mjs";
|
|
2
|
+
import { C as RunTiming, D as PermissionDecision, E as ZodRunRequest, O as PermissionHandler, 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, k as PermissionRequest, 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-CGzSzwfB.mjs";
|
|
3
|
+
import { $ as WorkdirDiffStats, A as E2BCreateConfig, B as ContainerExecution, C as NerdctlProviderBase, D as E2BContainer, E as E2BConnectionConfig, F as DockerContainerBase, G as ContainerStatus, H as ContainerIdentity, I as DockerContainerConfig, J as ExecResult, K as ContainerType, L as DockerProviderConfig, M as DockerBuildBase, N as DockerBuildConfig, O as E2BContainerBase, P as DockerContainer, Q as WorkdirDiff, R as ContainerBase, S as NerdctlContainerConfig, T as E2BConnectConfig, U as ContainerLifecycle, V as ContainerFileSystem, W as ContainerObservability, X as VolumeMount, Y as PortMapping, Z as WorkdirChangeKind, _ as PodmanProviderConfig, a as ContainerDiffError, b as NerdctlContainer, c as ContainerExecError, d as MountValidationError, et as WorkdirFileChange, f as PodmanBuildBase, g as PodmanContainerConfig, h as PodmanContainerBase, i as ContainerCreateError, j as E2BProviderConfig, k as E2BContainerConfig, l as ContainerNotRunningError, m as PodmanContainer, n as ContainerConfig, nt as WorkdirSnapshotOptions, o as ContainerDisposedError, p as PodmanBuildConfig, q as ExecOptions, r as createContainer, s as ContainerError, t as Container, tt as WorkdirSnapshot, u as ContainerStartError, v as NerdctlBuildBase, w as NerdctlProviderConfig, x as NerdctlContainerBase, y as NerdctlBuildConfig, z as ContainerConfigBase } from "./index-C9XD71QR.mjs";
|
|
4
|
+
import { _ as SandboxType, a as FirejailSandbox, c as NsjailSandboxConfig, d as SandboxConfig, f as SandboxConfigBase, g as SandboxStatus, h as SandboxLifecycle, i as BubblewrapSandboxConfig, l as Sandbox, m as SandboxIdentity, n as createSandbox, o as FirejailSandboxConfig, p as SandboxExecution, r as BubblewrapSandbox, s as NsjailSandbox, t as SandboxCreateError, u as SandboxBase } from "./index-B5NFoNlS.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-BQ8cUo2i.mjs";
|
|
6
|
+
import { a as ClaudeCodeCliPtyPermissionMode, i as ClaudeCodeCliPtyModule, n as ClaudeCodeCliPtyAgent, o as ClaudeCodeCliPtyProcess, r as ClaudeCodeCliPtyAgentOptions, s as ClaudeCodeCliPtyRunOptions } from "./index-DzFF15zC.mjs";
|
|
7
|
+
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-B9ze9hTN.mjs";
|
|
8
|
+
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-BKK-3gye.mjs";
|
|
9
|
+
import { a as CodexSdkItem, i as CodexSdkEvent, n as CodexSdkAgent, o as CodexSdkPermissionMode, r as CodexSdkAgentOptions, s as CodexSdkRunOptions } from "./index-CG2m7pFJ.mjs";
|
|
10
|
+
import { a as CursorCliRunOptions, i as CursorCliMode, n as CursorCliAgent, o as CursorCliSandboxMode, r as CursorCliAgentOptions, s as CursorCliEvent } from "./index-XWqpUSBc.mjs";
|
|
11
|
+
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-DdyD2ji1.mjs";
|
|
12
|
+
import { a as GeminiCliRunOptions, i as GeminiCliPermissionMode, n as GeminiCliAgent, o as GeminiEvent, r as GeminiCliAgentOptions } from "./index-5bx9TIY_.mjs";
|
|
13
|
+
import { a as OpencodeEvent, i as OpencodeCliRunOptions, n as OpencodeCliAgent, r as OpencodeCliAgentOptions } from "./index-CG5DS_NB.mjs";
|
|
14
|
+
import { a as PiCliThinkingLevel, i as PiCliRunOptions, n as PiCliAgent, o as PiEvent, r as PiCliAgentOptions } from "./index-DPP4zoiJ.mjs";
|
|
15
15
|
//#region src/core/agent/create-agent.d.ts
|
|
16
|
-
|
|
16
|
+
interface AgentOptionsByType {
|
|
17
|
+
"claude-code-cli-pty": ClaudeCodeCliPtyAgentOptions;
|
|
18
|
+
"claude-code-cli": ClaudeCodeCliAgentOptions;
|
|
19
|
+
"claude-code-sdk": ClaudeCodeSdkAgentOptions;
|
|
20
|
+
"codex-cli": CodexCliAgentOptions;
|
|
21
|
+
"codex-sdk": CodexSdkAgentOptions;
|
|
22
|
+
"cursor-cli": CursorCliAgentOptions;
|
|
23
|
+
"cursor-sdk": CursorSdkAgentOptions;
|
|
24
|
+
"gemini-cli": GeminiCliAgentOptions;
|
|
25
|
+
"opencode-cli": OpencodeCliAgentOptions;
|
|
26
|
+
"pi-cli": PiCliAgentOptions;
|
|
27
|
+
}
|
|
28
|
+
interface AgentInstanceByType {
|
|
29
|
+
"claude-code-cli-pty": ClaudeCodeCliPtyAgent;
|
|
30
|
+
"claude-code-cli": ClaudeCodeCliAgent;
|
|
31
|
+
"claude-code-sdk": ClaudeCodeSdkAgent;
|
|
32
|
+
"codex-cli": CodexCliAgent;
|
|
33
|
+
"codex-sdk": CodexSdkAgent;
|
|
34
|
+
"cursor-cli": CursorCliAgent;
|
|
35
|
+
"cursor-sdk": CursorSdkAgent;
|
|
36
|
+
"gemini-cli": GeminiCliAgent;
|
|
37
|
+
"opencode-cli": OpencodeCliAgent;
|
|
38
|
+
"pi-cli": PiCliAgent;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Create an agent of the requested type.
|
|
42
|
+
*
|
|
43
|
+
* The `type` literal selects the adapter and narrows `options` to that
|
|
44
|
+
* adapter's `*AgentOptions` shape and the returned agent to its instance type.
|
|
45
|
+
* Each adapter wraps a third-party coding agent (Claude Code, Codex, Cursor,
|
|
46
|
+
* Gemini, OpenCode, Pi) behind a uniform `BaseAgent` surface.
|
|
47
|
+
*
|
|
48
|
+
* SDK-backed adapters (`claude-code-sdk`, `codex-sdk`, `cursor-sdk`) require
|
|
49
|
+
* their respective peer package to be installed; a missing package throws
|
|
50
|
+
* {@link AgentValidationError} with a hint to install it.
|
|
51
|
+
*
|
|
52
|
+
* Agents are async-disposable. Prefer `await using` so the underlying process
|
|
53
|
+
* or SDK handle is closed deterministically:
|
|
54
|
+
*
|
|
55
|
+
* ```ts
|
|
56
|
+
* await using agent = await createAgent("cursor-sdk", {
|
|
57
|
+
* apiKey: process.env.CURSOR_API_KEY,
|
|
58
|
+
* model: "composer-2.5",
|
|
59
|
+
* });
|
|
60
|
+
* const result = await agent.run({ input: "summarize this repo" });
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* @param type Adapter identifier — selects which third-party agent backs this instance.
|
|
64
|
+
* @param options Adapter-specific creation options. Each adapter accepts at minimum `cwd`, `sessionId`, `model`, and `onEvent`.
|
|
65
|
+
* @returns A promise that resolves to the typed agent instance.
|
|
66
|
+
* @throws {AgentValidationError} If a required peer dependency is missing or required options are absent.
|
|
67
|
+
*/
|
|
68
|
+
declare function createAgent(type: "claude-code-cli-pty", options?: ClaudeCodeCliPtyAgentOptions): Promise<ClaudeCodeCliPtyAgent>;
|
|
17
69
|
declare function createAgent(type: "claude-code-cli", options?: ClaudeCodeCliAgentOptions): Promise<ClaudeCodeCliAgent>;
|
|
18
70
|
declare function createAgent(type: "claude-code-sdk", options?: ClaudeCodeSdkAgentOptions): Promise<ClaudeCodeSdkAgent>;
|
|
19
71
|
declare function createAgent(type: "codex-cli", options?: CodexCliAgentOptions): Promise<CodexCliAgent>;
|
|
@@ -23,5 +75,6 @@ declare function createAgent(type: "cursor-sdk", options?: CursorSdkAgentOptions
|
|
|
23
75
|
declare function createAgent(type: "gemini-cli", options?: GeminiCliAgentOptions): Promise<GeminiCliAgent>;
|
|
24
76
|
declare function createAgent(type: "opencode-cli", options?: OpencodeCliAgentOptions): Promise<OpencodeCliAgent>;
|
|
25
77
|
declare function createAgent(type: "pi-cli", options?: PiCliAgentOptions): Promise<PiCliAgent>;
|
|
78
|
+
declare function createAgent<T extends AgentType>(type: T, options?: AgentOptionsByType[T]): Promise<AgentInstanceByType[T]>;
|
|
26
79
|
//#endregion
|
|
27
|
-
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
|
|
80
|
+
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 ClaudeCodeCliPtyAgent, type ClaudeCodeCliPtyAgentOptions, type ClaudeCodeCliPtyModule, type ClaudeCodeCliPtyPermissionMode, type ClaudeCodeCliPtyProcess, type ClaudeCodeCliPtyRunOptions, 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, MountValidationError, 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 PermissionDecision, type PermissionHandler, type PermissionRequest, 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, SandboxCreateError, 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-
|
|
1
|
+
import{n as e,t}from"./types-B72tDMEZ.mjs";import{a as n,c as r,i,l as a,n as o,o as s,r as c,s as l,t as u}from"./container-DBXaA-Iv.mjs";import{n as d,t as f}from"./sandbox-C5vzNxZR.mjs";import{n as p,u as m}from"./schemas-CkdQXAep.mjs";const h=(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`},g=(t,n,r)=>{throw h(r,n)?new e(`Agent type "${t}" requires the optional peer dependency "${n}". Install it to use this adapter.`):r};async function _(t,n){switch(t){case`claude-code-cli-pty`:{let{createClaudeCodeCliPtyAgent:e}=await import(`./adapters/claude-code-cli-pty/index.mjs`);return e(n)}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 g(`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 g(`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 g(`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,o as ContainerCreateError,c as ContainerDiffError,i as ContainerDisposedError,n as ContainerError,s as ContainerExecError,l as ContainerNotRunningError,r as ContainerStartError,a as MountValidationError,f as SandboxCreateError,m as agentCapabilitiesSchema,_ as createAgent,u as createContainer,d as createSandbox,p as eventSchema};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as e}from"./util-DcPzh_0u.mjs";import{c as t,i as n,l as r,n as i,o as a,r as o,s}from"./container-DBXaA-Iv.mjs";import{n as c}from"./env-Cb8MIvH7.mjs";import{t as l}from"./spawner-BB6W3FVi.mjs";import{t as u}from"./shell-DvWFuFKb.mjs";import{n as d,r as f,t as p}from"./diff-BJWXJsjx.mjs";import{execFile as m}from"node:child_process";import{isAbsolute as h,join as g,posix as _,resolve as v}from"node:path";import{promisify as y}from"node:util";import{existsSync as b}from"node:fs";import{tmpdir as x}from"node:os";import{mkdtemp as S,rm as C,writeFile as w}from"node:fs/promises";import{randomBytes as T}from"node:crypto";const E=(e,t)=>{let n=_.relative(e,t);return n===``||!n.startsWith(`..`)&&!_.isAbsolute(n)},D=(e,t)=>{if(!e||e.length===0)return;let n=_.normalize(t),r;for(let t of e){if(!h(t.source))continue;let e=_.normalize(t.target);E(e,n)&&(!r||e.length>_.normalize(r.target).length)&&(r=t)}if(!r)return;let i=_.relative(_.normalize(r.target),n);return i===``?r.source:_.join(r.source,...i.split(`/`))},O=(e,t)=>{let n=h(e.source)?e.source:v(t.cwd,e.source);if(!b(n))throw new r(`Mount source does not exist: ${n}`);return{...e,source:n}},k=y(m),A=()=>`cw-${T(6).toString(`hex`)}`,j=(e,t)=>e.baseArgs?[...e.baseArgs,...t]:t,M=e=>{if(e.env)return{...c(),...e.env}},N=async(e,t,n)=>{let r=await k(e.binary,j(e,t),{encoding:`utf8`,env:M(e),timeout:n?.timeoutMs,signal:n?.signal,maxBuffer:50*1024*1024});return{stdout:r.stdout,stderr:r.stderr}},P=async(t,n)=>{let r=n.tag??`cw-build-${T(4).toString(`hex`)}`,a=[`build`,`-t`,r];if(n.args)for(let[e,t]of Object.entries(n.args))a.push(`--build-arg`,`${e}=${t}`);`dockerfile`in n&&n.dockerfile&&(a.push(`-f`,n.dockerfile),a.push(n.context??`.`));let o;if(`content`in n&&n.content){o=await S(g(x(),`cw-oci-build-`));let e=g(o,`Dockerfile`);await w(e,n.content,{encoding:`utf8`,mode:384}),a.push(`-f`,e),a.push(n.context??o)}try{await N(t,a)}catch(t){throw new i(`Image build failed: ${e(t)}`)}finally{o&&await C(o,{recursive:!0,force:!0}).catch(()=>{})}return r},F=async(e,t,n)=>{let r=await Promise.all(n.map(async n=>{try{let{container:r,protocol:i=`tcp`}=n,{stdout:a}=await N(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},I=(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),l.spawn(t.binary,j(t,a),{env:M(t),stdio:i.stdio})}}),L=async(r,c,m)=>{let{commandContext:h,builtImage:g,containerName:v,workdir:y,user:b,network:x,platform:S,env:C,ports:w,mounts:T,mountCwd:E,extraArgs:k,image:P}=c,L=v??A(),R=T?.map(e=>O(e,{cwd:E??process.cwd()})),z=[`create`,`--name`,L];if(b&&z.push(`--user`,b),x&&z.push(`--network`,x),S&&z.push(`--platform`,S),C)for(let[e,t]of Object.entries(C))z.push(`-e`,`${e}=${t}`);if(w)for(let e of w){let{host:t,container:n,protocol:r=`tcp`}=e;z.push(`-p`,`${t??``}:${n}/${r}`)}if(R)for(let e of R){let{readonly:t,source:n,target:r}=e,i=t?`ro`:`rw`;z.push(`-v`,`${n}:${r}:${i}`)}k&&z.push(...k),z.push(P,`sleep`,`infinity`);let B;try{let{stdout:e}=await N(h,z);B=e.trim()}catch(t){throw new i(`Container create failed: ${e(t)}`)}let V=`created`,H=new Map,U=()=>{if(V===`disposed`)throw new n},W=()=>{if(U(),V!==`running`)throw new s},G=I(B,h),K=d({owner:{},workdir:y,materialize:async(t,n)=>{U();let r=D(R,t);if(r){await p(r,n);return}W();try{await N(h,[`exec`,B,`sh`,`-c`,`test -d ${u(t)}`])}catch{throw new o(`Target path is not a directory: ${t}`)}try{await N(h,[`cp`,`${B}:${t}/.`,n])}catch(n){throw new o(`Failed to materialize container path ${t}: ${e(n)}`)}}}),q={get type(){return r},get id(){return B},get name(){return L},get config(){return m},get status(){return V},get workdir(){return y},get spawner(){return G},async start(){if(U(),V!==`running`){try{await N(h,[`start`,B])}catch(n){throw new t(`Container start failed: ${e(n)}`)}try{await N(h,[`exec`,B,`mkdir`,`-p`,y])}catch(n){try{await N(h,[`stop`,`-t`,`0`,B]),V=`stopped`}catch{try{let{stdout:e}=await N(h,[`inspect`,`--format`,`{{.State.Status}}`,B]);V=e.trim()===`running`?`running`:`stopped`}catch{V=`disposed`}}throw new t(`Container start failed: ${e(n)}`)}V=`running`,w?.length&&(H=await F(h,B,w))}},async stop(){if(U(),V===`running`){try{await N(h,[`stop`,`-t`,`2`,B])}catch{try{let{stdout:e}=await N(h,[`inspect`,`--format`,`{{.State.Status}}`,B]);if(e.trim()===`running`)return}catch{V=`disposed`;return}}V=`stopped`}},async dispose(){if(V!==`disposed`){try{await N(h,[`stop`,`-t`,`0`,B])}catch{}try{await N(h,[`rm`,`-f`,B])}catch{}g&&await N(h,[`rmi`,P]).catch(()=>{}),await K.disposeSnapshots().catch(()=>{}),V=`disposed`}},async exec(e,t,n={}){W();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(B,e,...t);try{let{stdout:e,stderr:t}=await N(h,r,{timeoutMs:n.timeoutMs,signal:n.signal});return{exitCode:0,stdout:e,stderr:t}}catch(e){if(f(e))return{exitCode:typeof e.code==`number`?e.code:-1,stdout:String(e.stdout??``),stderr:String(e.stderr??``)};throw e}},async copyTo(e,t){W(),await N(h,[`cp`,e,`${B}:${t}`])},async copyFrom(e,t){W(),await N(h,[`cp`,`${B}:${e}`,t])},async writeFile(t,n){W();let r=_.isAbsolute(t)?t:_.resolve(y,t),i=_.dirname(r),o=typeof n==`string`?Buffer.from(n,`utf8`):n,s=[`exec`,`-i`];b&&s.push(`--user`,b),s.push(B,`sh`,`-c`,`mkdir -p ${u(i)} && cat > ${u(r)}`);let c=l.spawn(h.binary,j(h,s),{env:M(h),stdio:[`pipe`,`ignore`,`ignore`]});try{c.stdin?.write?.(o),c.stdin?.end()}catch(t){throw c.kill(),c.wait().catch(()=>{}),new a(`writeFile failed for ${r}: ${e(t)}`)}let d=await c.wait();if(d.exitCode!==0)throw new a(`writeFile failed for ${r} (exit ${d.exitCode})`)},async readFile(e){W();let t=_.isAbsolute(e)?e:_.resolve(y,e),{stdout:n}=await N(h,[`exec`,B,`cat`,t]);return n},async fileExists(e){W();let t=_.isAbsolute(e)?e:_.resolve(y,e);try{return await N(h,[`exec`,B,`test`,`-e`,t]),!0}catch{return!1}},async mkdir(e){W();let t=_.isAbsolute(e)?e:_.resolve(y,e);await N(h,[`exec`,B,`mkdir`,`-p`,t])},async execShell(e,t={}){return q.exec(`sh`,[`-c`,e],t)},async logs(e={}){U();let t=[`logs`];e.tail!==void 0&&t.push(`--tail`,String(e.tail)),t.push(B);let{stdout:n}=await N(h,t);return n},async syncStatus(){U();try{let{stdout:e}=await N(h,[`inspect`,`--format`,`{{.State.Status}}`,B]),t=e.trim();V=t===`running`?`running`:t===`created`?`created`:`stopped`}catch{V=`disposed`}return V},async snapshotWorkdir(e={}){return K.snapshotWorkdir(e)},async diffWorkdir(e){return K.diffWorkdir(e)},async releaseWorkdirSnapshot(e){return K.releaseWorkdirSnapshot(e)},getMappedPort(e){return H.get(e)},[Symbol.asyncDispose](){return q.dispose()}};return q},R=async(e,t)=>{if(t.image)return t.image;if(t.build)return P(e,t.build);throw new i(`Either image or build must be provided.`)};export{R as n,L as t};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{i as e}from"./util-
|
|
2
|
-
`),c=e=>typeof e.result==`string`&&e.result.trim()!==``?e.result:e.subtype,l=(e,r)=>{let i=[`[${e.subtype}]`];if(e.subtype===`init`){if(e.tools&&i.push(`tools: ${e.tools.length}`),e.mcp_servers){let t=e.mcp_servers.filter(e=>e.status===`connected`).length;i.push(`mcp: ${t}/${e.mcp_servers.length} connected`)}}else e.hook_name&&(i.push(e.hook_name),e.exit_code!==void 0&&i.push(`exit: ${e.exit_code}`));let a=i.join(` `);return{events:[
|
|
1
|
+
import{i as e}from"./util-DcPzh_0u.mjs";import{l as t,o as n,s as r}from"./classify-error-BPQtzEVV.mjs";import{t as i}from"./structured-output-cpLrrrTN.mjs";import{z as a}from"zod/v4";const o=e=>`session_id`in e?e.session_id:void 0,s=e=>typeof e.content==`string`?e.content:e.content.map(e=>e.text).join(`
|
|
2
|
+
`),c=e=>typeof e.result==`string`&&e.result.trim()!==``?e.result:e.subtype,l=(e,r)=>{let i=[`[${e.subtype}]`];if(e.subtype===`init`){if(e.tools&&i.push(`tools: ${e.tools.length}`),e.mcp_servers){let t=e.mcp_servers.filter(e=>e.status===`connected`).length;i.push(`mcp: ${t}/${e.mcp_servers.length} connected`)}}else e.hook_name&&(i.push(e.hook_name),e.exit_code!==void 0&&i.push(`exit: ${e.exit_code}`));let a=i.join(` `);return{events:[n(r.runId,`message`,{sessionId:r.sessionId,model:e.model??null,role:`system`,content:[t(a)],text:a})]}},u=(e,r)=>{let i=[],a=[];for(let o of e.message.content)switch(o.type){case`text`:i.push(n(r.runId,`message`,{sessionId:r.sessionId,model:e.message.model??null,role:`assistant`,content:[t(o.text)],text:o.text}));break;case`thinking`:i.push(n(r.runId,`reasoning`,{sessionId:r.sessionId,model:e.message.model??null,content:[t(o.thinking)],text:o.thinking}));break;case`tool_use`:a.push({toolCallId:o.id,toolName:o.name,input:o.input}),i.push(n(r.runId,`tool-call`,{sessionId:r.sessionId,model:e.message.model??null,toolCallId:o.id,toolName:o.name,input:o.input}));break;default:break}return{events:i,toolCalls:a}},d=(e,r)=>{let i=[];for(let a of e.message.content)switch(a.type){case`text`:i.push(n(r.runId,`message`,{sessionId:r.sessionId,model:null,role:`user`,content:[t(a.text)],text:a.text}));break;case`tool_result`:{let e=r.toolCalls.get(a.tool_use_id),t=s(a);i.push(n(r.runId,`tool-result`,{sessionId:r.sessionId,toolCallId:a.tool_use_id,toolName:e?.toolName,input:e?.input,output:t,isError:a.is_error,error:a.is_error?t:void 0}));break}default:break}return{events:i}},f=(t,n)=>{let r=t.usage?.input_tokens,a=t.usage?.cache_creation_input_tokens,o=t.usage?.cache_read_input_tokens,s=t.usage?.output_tokens,l=e(r,a,o,s),u={stats:{durationMs:t.duration_ms,apiDurationMs:t.duration_api_ms,turns:t.num_turns,inputTokens:r,cacheCreationInputTokens:a,cacheReadInputTokens:o,outputTokens:s,totalTokens:l,costUsd:t.total_cost_usd}};typeof t.result==`string`&&(u.output={...u.output,text:t.result});let d=i(t.structured_output,n,{isSuccess:!t.is_error&&t.subtype===`success`},`Structured output was requested but Claude did not return structured_output.`);return d.value!==void 0&&(u.output={...u.output,value:d.value}),d.error&&(u.error=d.error),t.is_error||t.subtype!==`success`?(u.status=`failed`,u.error={kind:`provider`,message:c(t)}):u.error||(u.status=`completed`),{events:[],state:u}},p=(e,r)=>{let i=`rate limited: ${e.rate_limit_info.status}`;return{events:[n(r.runId,`message`,{sessionId:r.sessionId,model:null,role:`system`,content:[t(i)],text:i})]}},m=(e,t)=>{switch(e.type){case`system`:return l(e,t);case`assistant`:return u(e,t);case`user`:return d(e,t);case`result`:return f(e,t);case`rate_limit_event`:return p(e,t);default:return{events:[]}}},h=a.enum([`init`,`hook_response`,`hook_started`,`hook_finished`,`hook_failed`,`hook_skipped`]),g=a.object({type:a.literal(`system`),session_id:a.string(),subtype:h,uuid:a.string(),tools:a.array(a.string()).optional(),mcp_servers:a.array(a.object({name:a.string(),status:a.enum([`connected`,`disconnected`,`error`,`failed`])})).optional(),model:a.string().optional(),cwd:a.string().optional(),hook_name:a.string().optional(),hook_event:a.string().optional(),stdout:a.string().optional(),stderr:a.string().optional(),exit_code:a.number().optional()}),_=a.object({type:a.literal(`assistant`),session_id:a.string(),uuid:a.string(),parent_tool_use_id:a.string().nullable().optional(),message:a.object({id:a.string(),type:a.literal(`message`),role:a.literal(`assistant`),model:a.string(),content:a.array(a.union([a.object({type:a.literal(`text`),text:a.string()}),a.object({type:a.literal(`tool_use`),id:a.string(),name:a.string(),input:a.record(a.string(),a.unknown())}),a.object({type:a.literal(`thinking`),thinking:a.string(),signature:a.string().optional()})])),stop_reason:a.enum([`end_turn`,`max_tokens`,`tool_use`,`stop_sequence`]).nullable(),stop_sequence:a.string().nullable().optional(),context_management:a.unknown().nullable().optional(),usage:a.object({input_tokens:a.number(),output_tokens:a.number(),cache_creation_input_tokens:a.number().optional(),cache_read_input_tokens:a.number().optional(),service_tier:a.enum([`premium`,`standard`]).nullable().optional()}),ttftMs:a.number().optional()})}),v=a.object({type:a.literal(`user`),session_id:a.string(),message:a.object({role:a.literal(`user`),content:a.array(a.union([a.object({type:a.literal(`tool_result`),tool_use_id:a.string(),content:a.union([a.string(),a.array(a.object({type:a.literal(`text`),text:a.string()}))]),is_error:a.boolean().optional()}),a.object({type:a.literal(`text`),text:a.string()})]))}),parent_tool_use_id:a.string().nullable().optional(),uuid:a.string(),isSynthetic:a.boolean().optional()}),y=a.object({type:a.literal(`result`),session_id:a.string(),uuid:a.string(),subtype:a.enum([`success`,`error_max_turns`,`error_during_execution`]),duration_ms:a.number(),duration_api_ms:a.number(),is_error:a.boolean(),num_turns:a.number(),result:a.unknown().optional(),structured_output:a.unknown().optional(),total_cost_usd:a.number(),usage:a.object({input_tokens:a.number(),cache_creation_input_tokens:a.number().optional(),cache_read_input_tokens:a.number().optional(),output_tokens:a.number(),server_tool_use:a.object({web_search_requests:a.number()}).optional()}).optional()}),b=a.object({type:a.literal(`rate_limit_event`),uuid:a.string(),session_id:a.string().optional(),rate_limit_info:a.object({status:a.string(),resetsAt:a.number().optional(),rateLimitType:a.string().optional(),overageStatus:a.string().optional(),overageDisabledReason:a.string().optional(),isUsingOverage:a.boolean().optional()})}),x=r(a.discriminatedUnion(`type`,[g,_,v,y,b]));export{o as n,m as r,x as t};
|
package/dist/sandbox/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
export { BubblewrapSandbox, BubblewrapSandboxConfig, FirejailSandbox, FirejailSandboxConfig, NsjailSandbox, NsjailSandboxConfig, Sandbox, SandboxBase, SandboxConfig, SandboxConfigBase, SandboxExecution, SandboxIdentity, SandboxLifecycle, SandboxStatus, SandboxType, createSandbox };
|
|
1
|
+
import { _ as SandboxType, a as FirejailSandbox, c as NsjailSandboxConfig, d as SandboxConfig, f as SandboxConfigBase, g as SandboxStatus, h as SandboxLifecycle, i as BubblewrapSandboxConfig, l as Sandbox, m as SandboxIdentity, n as createSandbox, o as FirejailSandboxConfig, p as SandboxExecution, r as BubblewrapSandbox, s as NsjailSandbox, t as SandboxCreateError, u as SandboxBase } from "../index-B5NFoNlS.mjs";
|
|
2
|
+
export { type BubblewrapSandbox, type BubblewrapSandboxConfig, type FirejailSandbox, type FirejailSandboxConfig, type NsjailSandbox, type NsjailSandboxConfig, type Sandbox, type SandboxBase, type SandboxConfig, type SandboxConfigBase, SandboxCreateError, type SandboxExecution, type SandboxIdentity, type SandboxLifecycle, type SandboxStatus, type SandboxType, createSandbox };
|
package/dist/sandbox/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{n as e,t}from"../sandbox-C5vzNxZR.mjs";export{t as SandboxCreateError,e as createSandbox};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{t as e}from"./util-DcPzh_0u.mjs";import{n as t,r as n,t as r}from"./env-Cb8MIvH7.mjs";import{t as i}from"./spawner-BB6W3FVi.mjs";import{t as a}from"./shell-DvWFuFKb.mjs";import{execFile as o}from"node:child_process";import{delimiter as s,isAbsolute as c,join as l,posix as u,resolve as d}from"node:path";import{promisify as f}from"node:util";import{accessSync as p,constants as m,mkdtempSync as h,realpathSync as g,rmSync as _,writeFileSync as ee}from"node:fs";import{tmpdir as te}from"node:os";const v=e=>{let t=e.type.charAt(0).toUpperCase()+e.type.slice(1),n=`created`,r=new Set,i=()=>{if(n===`disposed`)throw Error(`${t} sandbox has been disposed.`)},a=()=>{if(i(),n!==`running`)throw Error(`${t} sandbox is not running.`)},o=e=>{let t={process:e,waitPromise:e.wait().finally(()=>{r.delete(t)})};return r.add(t),{...e,wait:()=>t.waitPromise}},s=async()=>{let e=Array.from(r,e=>(e.process.kill(`SIGKILL`),e.waitPromise));await Promise.allSettled(e)},c=e.createSpawner(a,o),l={type:e.type,config:e.config,get status(){return n},get workdir(){return e.config.workdir},get spawner(){return c},async start(){i(),n!==`running`&&(await e.onValidate(),n=`running`)},async stop(){i(),n===`running`&&(n=`stopped`,await s())},async dispose(){n!==`disposed`&&(n=`disposed`,await s(),await e.onDispose?.())},[Symbol.asyncDispose](){return l.dispose()}};return e.extend?e.extend(l):l},y=`bwrap`,b=[`/tmp`],x=f(o),S=(e,t)=>e.binds?.some(e=>e.target===t)??!1,C=(e,t)=>{let n=u.relative(e,t);return n===``||!n.startsWith(`..`)&&!u.isAbsolute(n)},w=(e,t)=>e.target.length-t.target.length,ne=e=>{let t=S(e,e.workdir)?[...e.binds??[]]:[{source:e.workdir,target:e.workdir},...e.binds??[]],n=e.tmpfs??b,r=t.filter(e=>!n.some(t=>C(t,e.target))).toSorted(w),i=t.filter(e=>n.some(t=>C(t,e.target))).toSorted(w);return[...r,...i]},re=e=>{let t=[`--ro-bind`,`/`,`/`];for(let n of ne(e))t.push(n.readonly?`--ro-bind`:`--bind`,n.source,n.target);return t},ie=(e,t)=>{let n=[];(e.clearEnv??!0)&&n.push(`--clearenv`);for(let t of e.unsetEnv??[])n.push(`--unsetenv`,t);let r={...e.setEnv,...t.env};for(let[e,t]of Object.entries(r))n.push(`--setenv`,e,t);return n},ae=e=>{let t=[`--die-with-parent`,`--new-session`];return(e.unshareAll??!0)&&t.push(`--unshare-all`),e.shareNetwork&&t.push(`--share-net`),e.uid!==void 0&&t.push(`--uid`,String(e.uid)),e.gid!==void 0&&t.push(`--gid`,String(e.gid)),e.hostname&&t.push(`--hostname`,e.hostname),t},oe=e=>{let t=[`--ro-bind`,`/`,`/`];e.proc!==!1&&t.push(`--proc`,e.proc??`/proc`),e.dev!==!1&&t.push(`--dev`,e.dev??`/dev`);for(let n of e.tmpfs??b)t.push(`--tmpfs`,n);t.push(...re(e).slice(3));for(let n of e.remountReadonly??[])t.push(`--remount-ro`,n);return t},se=(e,t,n,r={})=>[...ae(e),...oe(e),...ie(e,r),`--chdir`,r.cwd??e.workdir,...e.args??[],`--`,t,...n],T=async t=>{try{await x(t,[`--version`],{env:r(),encoding:`utf8`})}catch(t){throw Error(`Bubblewrap start failed: ${e(t)}`)}},E=(e,t,n,i)=>({spawn(a,o,s={}){return t(),n(i.spawn(e.binary??y,se(e,a,o,s),{env:r(),stdio:s.stdio}))}}),D=async(e,t=i)=>v({type:`bubblewrap`,config:e,onValidate:()=>T(e.binary??y),createSpawner:(n,r)=>E(e,n,r,t)}),O=e=>new Set((e??[]).flatMap(e=>[e,e.toUpperCase(),e.toLowerCase()])),k=(e,t)=>{let n=O(t);return n.size===0?e:Object.fromEntries(Object.entries(e).filter(([e])=>!n.has(e)))},A=e=>{try{return p(e,m.X_OK),!0}catch{return!1}},j=(e,t)=>c(e)?e:d(t,e),M=(e,t,r)=>{if(c(e)||e.includes(`/`))return e;let i=t[n(t)];if(!i)return e;for(let t of i.split(s)){let n=l(j(t,r),e);if(A(n))return n}return e},N=(e,r)=>{if((r??[]).some(e=>e.toLowerCase()===`path`))return;let i=n(e);if(i in e)return;let a=t(),o=a[n(a)];o&&Object.assign(e,{[i]:o})},P=[`/run/wrappers/bin`,`/usr/local/bin`,`/usr/bin`,`/bin`],F=f(o),I=e=>e.binary??`firejail`,L=()=>{let e=t();return e[n(e)]},R=e=>{if(e.clearEnv===!1)return r({extraPaths:P});let t=r({propagateEnv:!1,extraPaths:P}),i=L();return i&&(t[n(t)]=[...P,i].filter(Boolean).join(s)),t},z=(e,t,n)=>{let r=k({...n,...e.setEnv,...t.env},e.unsetEnv);return N(r,e.unsetEnv),r},B=(e,t,n)=>{let r=[];for(let t of e.unsetEnv??[])r.push(`--rmenv=${t}`);let i={...e.setEnv,...t.env};for(let[e,t]of Object.entries(i))n[e]!==t&&r.push(`--env=${e}=${t}`);return r},V=(e,t,n,r={},i={})=>{let a=[`--noprofile`];e.shareNetwork||a.push(`--net=none`);for(let t of e.whitelist??[])a.push(`--whitelist=${t}`);for(let t of e.blacklist??[])a.push(`--blacklist=${t}`);for(let t of e.readOnly??[])a.push(`--read-only=${t}`);for(let t of e.readWrite??[])a.push(`--read-write=${t}`);return e.privateTmp&&a.push(`--private-tmp`),a.push(...B(e,r,i)),e.args?.length&&a.push(...e.args),a.push(`--`,t,...n),a},H=async t=>{try{await F(t,[`--version`],{env:r({extraPaths:P}),encoding:`utf8`})}catch(t){throw Error(`Firejail start failed: ${e(t)}`)}},U=(e,t,n,r)=>({spawn(i,o,s={}){t();let c=s.cwd??e.workdir,l=R(e),u=`exec ${[M(i,z(e,s,l),c),...o].map(a).join(` `)}`;return n(r.spawn(I(e),V(e,`sh`,[`-c`,u],s,l),{cwd:c,env:l,stdio:s.stdio}))}}),W=async(e,t=i)=>v({type:`firejail`,config:e,onValidate:()=>H(I(e)),createSpawner:(n,r)=>U(e,n,r,t)}),G=`nsjail`,K=[`/tmp`],ce=f(o),q=e=>JSON.stringify(e),J=(e,t)=>e.target.length-t.target.length||Number(!!e.readonly)-Number(!!t.readonly),le=(e,t)=>e.binds?.some(e=>e.target===t)??!1,Y=e=>e.tmpfs??[...K],ue=(e,t)=>Y(e).includes(t),de=e=>{let t=le(e,e.workdir)?[...e.binds??[]]:[{source:e.workdir,target:e.workdir},...e.binds??[]],n=(e.readOnly??[]).map(e=>({source:e,target:e,readonly:!0,type:`bind`}));return[...t.map(e=>({source:e.source,target:e.target,readonly:e.readonly,type:`bind`})),...n].filter(t=>!ue(e,t.target)).toSorted(J)},fe=e=>Y(e).map(t=>({target:t,readonly:e.readOnly?.includes(t),type:`tmpfs`})).toSorted(J),pe=e=>[{source:`/`,target:`/`,readonly:!0,type:`bind`},...fe(e),...de(e)],X=(e,t)=>{let n=k(e.clearEnv===!1?r():r({propagateEnv:!1}),e.unsetEnv);return Object.assign(n,e.setEnv,t.env),N(n,e.unsetEnv),n},Z=(e,t,n)=>[`${e} {`,` inside_id: ${q(String(t))}`,` outside_id: ${q(String(n))}`,` count: 1`,`}`].join(`
|
|
2
|
+
`),me=e=>{if(e!==void 0)try{return g(e)}catch{return e}},Q=e=>{let t=[`mount {`],n=me(e.source);return n!==void 0&&t.push(` src: ${q(n)}`),t.push(` dst: ${q(e.target)}`),e.type===`tmpfs`?t.push(` fstype: ${q(`tmpfs`)}`):t.push(` is_bind: true`),t.push(` rw: ${e.readonly?`false`:`true`}`),t.push(` mandatory: true`),t.push(`}`),t.join(`
|
|
3
|
+
`)},he=(e,t,n)=>{let r=t.cwd??e.workdir,i=n??X(e,t),a=e.hostname??`NSJAIL`,o=typeof process.getuid==`function`?process.getuid():0,s=typeof process.getgid==`function`?process.getgid():0,c=e.uid??o,l=e.gid??s,u=e.clearEnv===!1&&(e.unsetEnv?.length??0)===0,d=[`name: "coding-agents-sdk"`,`mode: ONCE`,`hostname: ${q(a)}`,`cwd: ${q(r)}`,`keep_env: ${u?`true`:`false`}`,`clone_newnet: ${e.shareNetwork?`false`:`true`}`,`clone_newuser: true`,`clone_newns: true`,`clone_newpid: true`,`clone_newipc: true`,`clone_newuts: true`,`mount_proc: true`,`time_limit: ${String(e.timeLimitSec??0)}`,Z(`uidmap`,c,o),Z(`gidmap`,l,s)];e.seccompString&&d.push(`seccomp_string: ${q(e.seccompString)}`);for(let[e,t]of Object.entries(i)){let n=`${e}=${t}`;d.push(`envar: ${q(n)}`)}for(let t of pe(e))d.push(Q(t));return`${d.join(`
|
|
4
|
+
`)}\n`},ge=(e,t,n,r)=>{let i=[`-C`,t];return(e.disableRlimits??!0)&&i.push(`--disable_rlimits`),i.push(...e.args??[],`--`,n,...r),i},_e=async t=>{try{await ce(t,[`--help`],{env:r(),encoding:`utf8`})}catch(t){throw Error(`Nsjail start failed: ${e(t)}`)}},ve=(e,t,n,i,a)=>({spawn(o,s,c={}){n();let u=t(),d=X(e,c),f=M(o,d,c.cwd??e.workdir),p=l(u.configDir,`spawn-${Date.now()}-${Math.random().toString(16).slice(2)}.cfg`);ee(p,he(e,c,d),{encoding:`utf8`,mode:384});try{let t=i(a.spawn(e.binary??G,ge(e,p,f,s),{env:r(),stdio:c.stdio})),n=t.wait().finally(()=>{_(p,{force:!0})});return{...t,wait:()=>n}}catch(e){throw _(p,{force:!0}),e}}}),ye=async(e,t=i)=>{let n,r=()=>{if(!n)throw Error(`Nsjail sandbox has not been started.`);return n};return v({type:`nsjail`,config:e,async onValidate(){await _e(e.binary??G),n??={configDir:h(l(te(),`cw-nsjail-`))}},onDispose(){n&&_(n.configDir,{recursive:!0,force:!0})},createSpawner:(n,i)=>ve(e,r,n,i,t)})};var $=class extends Error{constructor(e){super(e),this.name=`SandboxCreateError`}};async function be(e){switch(e.type){case`bubblewrap`:return D(e);case`firejail`:return W(e);case`nsjail`:return ye(e);default:throw new $(`Unsupported sandbox type.`)}}export{be as n,$ as t};
|
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-B0BpIsW2.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 };
|
package/dist/schemas/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as e,c as t,d as n,f as r,i,l as a,n as o,o as s,p as c,r as l,s as u,t as d,u as f}from"../schemas-
|
|
1
|
+
import{a as e,c as t,d as n,f as r,i,l as a,n as o,o as s,p as c,r as l,s as u,t as d,u as f}from"../schemas-CkdQXAep.mjs";export{f as agentCapabilitiesSchema,d as baseEventSchema,n as contentPartSchema,o as eventSchema,r as imageContentPartSchema,l as messageEventSchema,i as reasoningEventSchema,e as sessionEndEventSchema,s as sessionStartEventSchema,u as stderrEventSchema,c as textContentPartSchema,t as toolCallEventSchema,a as toolResultEventSchema};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{spawn as e}from"node:child_process";const t=e=>({async*[Symbol.asyncIterator](){for await(let t of e){if(t instanceof Buffer){yield new Uint8Array(t);continue}if(typeof t==`string`){yield new TextEncoder().encode(t);continue}if(t instanceof Uint8Array){yield t;continue}throw Error(`Unsupported stdout/stderr chunk type: ${typeof t}`)}}}),n={spawn:(n,r,i={})=>{let a=e(n,r,{cwd:i.cwd,env:i.env,stdio:i.stdio});a.stdin?.on(`error`,()=>{});let o=new Promise((e,t)=>{let n=(t,n)=>{a.removeListener(`error`,r),e({exitCode:t,signal:n})},r=e=>{a.removeListener(`close`,n),t(e)};a.once(`error`,r),a.once(`close`,n)});return{stdout:a.stdout?t(a.stdout):null,stderr:a.stderr?t(a.stderr):null,stdin:a.stdin?{write:e=>a.stdin?.write(e),end:()=>a.stdin?.end()}:null,kill:e=>a.kill(e),wait:()=>o}}};export{n as t};
|