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
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { S as McpServerConfig } from "./events-
|
|
2
|
-
import { A as ProcessSpawner, f as EnsureDisjoint, l as BaseAgent, p as ExclusiveExecutionTargetOptions, t as AgentEventHandler } from "./types-
|
|
3
|
-
import { t as Container } from "./index-
|
|
4
|
-
import { c as Sandbox } from "./index-
|
|
1
|
+
import { S as McpServerConfig } from "./events-Bwfw__Q3.mjs";
|
|
2
|
+
import { A as ProcessSpawner, 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
5
|
import { z } from "zod/v4";
|
|
6
6
|
|
|
7
7
|
//#region src/adapters/claude-code-cli/events/schemas.d.ts
|
|
@@ -145,6 +145,12 @@ declare const claudeRateLimitEventSchema: z.ZodObject<{
|
|
|
145
145
|
}, z.core.$strip>;
|
|
146
146
|
}, z.core.$strip>;
|
|
147
147
|
type ClaudeRateLimitEvent = z.infer<typeof claudeRateLimitEventSchema>;
|
|
148
|
+
/**
|
|
149
|
+
* Discriminated union of the raw stream-JSON events Claude Code CLI emits
|
|
150
|
+
* before this adapter normalizes them. Surfaced for callers that want
|
|
151
|
+
* provider-specific fidelity (rate-limit signals, init metadata, etc.) that
|
|
152
|
+
* the normalized `AgentEvent` shape drops. Narrow on `event.type`.
|
|
153
|
+
*/
|
|
148
154
|
declare const claudeEventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
149
155
|
type: z.ZodLiteral<"system">;
|
|
150
156
|
session_id: z.ZodString;
|
|
@@ -279,34 +285,59 @@ declare const claudeEventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
279
285
|
type ClaudeEvent = z.infer<typeof claudeEventSchema>;
|
|
280
286
|
//#endregion
|
|
281
287
|
//#region src/adapters/claude-code-cli/types.d.ts
|
|
288
|
+
/**
|
|
289
|
+
* How Claude Code CLI handles tool-permission prompts.
|
|
290
|
+
* - `"default"`: stop and ask via the permission handler.
|
|
291
|
+
* - `"acceptEdits"`: auto-accept file edits, still ask for shell commands.
|
|
292
|
+
* - `"auto"`: a model classifier decides per-call whether to approve.
|
|
293
|
+
* - `"dontAsk"`: don't prompt; deny anything not pre-approved.
|
|
294
|
+
* - `"bypassPermissions"`: disable the permission system entirely (dangerous).
|
|
295
|
+
* - `"plan"`: read-only planning mode; no edits, no shell.
|
|
296
|
+
*/
|
|
282
297
|
type ClaudeCodeCliPermissionMode = "acceptEdits" | "auto" | "bypassPermissions" | "default" | "dontAsk" | "plan";
|
|
298
|
+
/** Per-run options for the `claude-code-cli` adapter. */
|
|
283
299
|
interface ClaudeCodeCliRunOptions {
|
|
300
|
+
/** Allowlist of tool names. */
|
|
284
301
|
allowedTools?: string[];
|
|
302
|
+
/** Denylist of tool names. */
|
|
285
303
|
disallowedTools?: string[];
|
|
304
|
+
/** Text appended to Claude Code's default system prompt. */
|
|
286
305
|
appendSystemPrompt?: string;
|
|
306
|
+
/** Permission strategy for this run. */
|
|
287
307
|
permissionMode?: ClaudeCodeCliPermissionMode;
|
|
308
|
+
/** Path(s) to MCP server config files passed via `--mcp-config`. */
|
|
288
309
|
mcpConfig?: string[] | string;
|
|
310
|
+
/** Inline MCP server config map. Merged with `mcpConfig` file contents. */
|
|
289
311
|
mcpServers?: Record<string, McpServerConfig>;
|
|
312
|
+
/** Start a fresh fork off the current session rather than continuing it. */
|
|
290
313
|
forkSession?: boolean;
|
|
314
|
+
/** Extra CLI flags appended verbatim. Use sparingly — the adapter sets most flags. */
|
|
291
315
|
extraArgs?: string[];
|
|
292
316
|
}
|
|
317
|
+
/** Constructor options for `createAgent("claude-code-cli", ...)`. */
|
|
293
318
|
type ClaudeCodeCliAgentOptions = ClaudeCodeCliRunOptions & ExclusiveExecutionTargetOptions<Container, Sandbox> & {
|
|
294
|
-
command?: string[] | string;
|
|
295
|
-
cwd?: string;
|
|
296
|
-
env?: Record<string, string>;
|
|
297
|
-
propagateEnv?: boolean;
|
|
298
|
-
sessionId?: string;
|
|
299
|
-
model?: string;
|
|
300
|
-
systemPrompt?: string;
|
|
301
|
-
logPath?: string;
|
|
302
|
-
ci?: boolean;
|
|
303
|
-
spawner?: ProcessSpawner;
|
|
319
|
+
/** Path or argv to the `claude` binary. Defaults to looking up `claude` on `PATH`. */command?: string[] | string; /** Working directory the agent operates against. */
|
|
320
|
+
cwd?: string; /** Environment variables for the subprocess. */
|
|
321
|
+
env?: Record<string, string>; /** Inherit `process.env` and overlay `env` on top, instead of replacing. */
|
|
322
|
+
propagateEnv?: boolean; /** Existing session ID to resume via `--resume`. */
|
|
323
|
+
sessionId?: string; /** Model identifier (e.g. `"claude-sonnet-4-6"`). */
|
|
324
|
+
model?: string; /** Replaces the default system prompt entirely. */
|
|
325
|
+
systemPrompt?: string; /** File path to write the raw CLI log to (useful for debugging). */
|
|
326
|
+
logPath?: string; /** Sets `CI=true` in the subprocess env unless explicitly `false`. Default: `true`. Does not change Claude Code's output formatting on its own. */
|
|
327
|
+
ci?: boolean; /** Custom process spawner; set by `createContainer`/`createSandbox`, rarely needed manually. */
|
|
328
|
+
spawner?: ProcessSpawner; /** Convenience: equivalent to calling `agent.onEvent(handler)` post-construction. */
|
|
304
329
|
onEvent?: AgentEventHandler;
|
|
305
330
|
};
|
|
331
|
+
/** Agent instance returned by `createAgent("claude-code-cli", ...)`. */
|
|
306
332
|
interface ClaudeCodeCliAgent extends BaseAgent<EnsureDisjoint<ClaudeCodeCliRunOptions>> {
|
|
307
333
|
readonly type: "claude-code-cli";
|
|
334
|
+
/**
|
|
335
|
+
* Branch a sibling agent from the current session.
|
|
336
|
+
*
|
|
337
|
+
* Throws `AgentValidationError` when called before this agent has
|
|
338
|
+
* acquired a session ID — run at least one prompt first.
|
|
339
|
+
*/
|
|
308
340
|
fork: () => ClaudeCodeCliAgent;
|
|
309
|
-
dispose: () => Promise<void>;
|
|
310
341
|
}
|
|
311
342
|
//#endregion
|
|
312
343
|
//#region src/adapters/claude-code-cli/adapter.d.ts
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { A as ProcessSpawner, f as EnsureDisjoint, l as BaseAgent, p as ExclusiveExecutionTargetOptions, t as AgentEventHandler } from "./types-Bk-YpdbX.mjs";
|
|
2
|
+
import { t as Container } from "./index-BeejNCvc.mjs";
|
|
3
|
+
import { c as Sandbox } from "./index-C8wbKjj3.mjs";
|
|
4
|
+
import { z } from "zod/v4";
|
|
5
|
+
|
|
6
|
+
//#region src/adapters/gemini-cli/events/schemas.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* Permissive raw-event shape for Gemini CLI: `{ type: string }` plus
|
|
9
|
+
* arbitrary additional fields the CLI may emit.
|
|
10
|
+
*/
|
|
11
|
+
declare const geminiEventSchema: z.ZodObject<{
|
|
12
|
+
type: z.ZodString;
|
|
13
|
+
}, z.core.$loose>;
|
|
14
|
+
type GeminiEvent = z.infer<typeof geminiEventSchema>;
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/adapters/gemini-cli/types.d.ts
|
|
17
|
+
/**
|
|
18
|
+
* Permission handling for Gemini CLI.
|
|
19
|
+
* - `"default"`: prompt before risky tool calls.
|
|
20
|
+
* - `"full"`: full-auto (no prompts).
|
|
21
|
+
*/
|
|
22
|
+
type GeminiCliPermissionMode = "default" | "full";
|
|
23
|
+
/** Per-run options for the `gemini-cli` adapter. */
|
|
24
|
+
interface GeminiCliRunOptions {
|
|
25
|
+
/** Allowlist of tool names. */
|
|
26
|
+
allowedTools?: string[];
|
|
27
|
+
/**
|
|
28
|
+
* Filter applied against `allowedTools` — tool names listed here are
|
|
29
|
+
* removed from the allowlist before it's passed to Gemini. Ignored when
|
|
30
|
+
* `allowedTools` is empty/undefined (Gemini CLI has no standalone
|
|
31
|
+
* denylist flag).
|
|
32
|
+
*/
|
|
33
|
+
disallowedTools?: string[];
|
|
34
|
+
/** Permission strategy. See {@link GeminiCliPermissionMode}. */
|
|
35
|
+
permissionMode?: GeminiCliPermissionMode;
|
|
36
|
+
/** Extra CLI flags appended verbatim. */
|
|
37
|
+
extraArgs?: string[];
|
|
38
|
+
}
|
|
39
|
+
/** Constructor options for `createAgent("gemini-cli", ...)`. */
|
|
40
|
+
type GeminiCliAgentOptions = ExclusiveExecutionTargetOptions<Container, Sandbox> & GeminiCliRunOptions & {
|
|
41
|
+
/** Path or argv to the `gemini` binary. */command?: string[] | string; /** Working directory the agent operates against. */
|
|
42
|
+
cwd?: string; /** Environment variables for the subprocess. Layered on top of host env when `propagateEnv` is `true` (default). */
|
|
43
|
+
env?: Record<string, string>; /** Default `true`: `process.env` is inherited and `env` overlays it. Set `false` to suppress host-env propagation. */
|
|
44
|
+
propagateEnv?: boolean; /** Existing Gemini session ID to resume. */
|
|
45
|
+
sessionId?: string; /** Gemini model identifier. */
|
|
46
|
+
model?: string; /** Replaces Gemini's default system prompt entirely. */
|
|
47
|
+
systemPrompt?: string; /** File path to write the raw CLI log to (useful for debugging). */
|
|
48
|
+
logPath?: string; /** Custom process spawner; set by `createContainer`/`createSandbox`, rarely needed manually. */
|
|
49
|
+
spawner?: ProcessSpawner; /** Convenience: equivalent to calling `agent.onEvent(handler)` post-construction. */
|
|
50
|
+
onEvent?: AgentEventHandler;
|
|
51
|
+
};
|
|
52
|
+
/** Agent instance returned by `createAgent("gemini-cli", ...)`. */
|
|
53
|
+
interface GeminiCliAgent extends BaseAgent<EnsureDisjoint<GeminiCliRunOptions>> {
|
|
54
|
+
readonly type: "gemini-cli";
|
|
55
|
+
}
|
|
56
|
+
//#endregion
|
|
57
|
+
//#region src/adapters/gemini-cli/adapter.d.ts
|
|
58
|
+
declare const createGeminiCliAgent: (options?: GeminiCliAgentOptions) => GeminiCliAgent;
|
|
59
|
+
//#endregion
|
|
60
|
+
export { GeminiCliRunOptions as a, GeminiCliPermissionMode as i, GeminiCliAgent as n, GeminiEvent as o, GeminiCliAgentOptions as r, createGeminiCliAgent as t };
|
|
@@ -0,0 +1,429 @@
|
|
|
1
|
+
import { A as ProcessSpawner } from "./types-Bk-YpdbX.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/container/types.d.ts
|
|
4
|
+
/** Which provider backs a container. Selects which CLI/SDK the adapter speaks. */
|
|
5
|
+
type ContainerType = "docker" | "e2b" | "nerdctl" | "podman";
|
|
6
|
+
/** Container port → host port mapping for `start`/`run`. */
|
|
7
|
+
interface PortMapping {
|
|
8
|
+
/** Port number exposed inside the container. */
|
|
9
|
+
container: number;
|
|
10
|
+
/** Host port to bind to. Defaults to a random free port if omitted. */
|
|
11
|
+
host?: number;
|
|
12
|
+
/** Transport protocol. Defaults to `"tcp"`. */
|
|
13
|
+
protocol?: "tcp" | "udp";
|
|
14
|
+
}
|
|
15
|
+
/** Bind mount or volume binding from host to container. */
|
|
16
|
+
interface VolumeMount {
|
|
17
|
+
/** Host path (absolute) or named volume. */
|
|
18
|
+
source: string;
|
|
19
|
+
/** Container path to mount at (absolute). */
|
|
20
|
+
target: string;
|
|
21
|
+
/** When `true`, mount is read-only inside the container. */
|
|
22
|
+
readonly?: boolean;
|
|
23
|
+
}
|
|
24
|
+
/** Fields shared by every provider-specific container config. */
|
|
25
|
+
interface ContainerConfigBase<TType extends ContainerType> {
|
|
26
|
+
type: TType;
|
|
27
|
+
/** Default working directory for `exec` and the agent's session. */
|
|
28
|
+
workdir: string;
|
|
29
|
+
/** Optional human-readable name. Defaults to a random unique name. */
|
|
30
|
+
name?: string;
|
|
31
|
+
/** Environment variables baked into the container. */
|
|
32
|
+
env?: Record<string, string>;
|
|
33
|
+
}
|
|
34
|
+
/** Per-call execution options for {@link ContainerExecution.exec}. */
|
|
35
|
+
interface ExecOptions {
|
|
36
|
+
/** Working directory inside the container; defaults to the container's `workdir`. */
|
|
37
|
+
cwd?: string;
|
|
38
|
+
/** Environment overrides layered on top of the container env. */
|
|
39
|
+
env?: Record<string, string>;
|
|
40
|
+
/** Hard timeout in milliseconds. */
|
|
41
|
+
timeoutMs?: number;
|
|
42
|
+
/** Caller-supplied AbortSignal that cancels the exec. */
|
|
43
|
+
signal?: AbortSignal;
|
|
44
|
+
}
|
|
45
|
+
/** Result of an exec call. */
|
|
46
|
+
interface ExecResult {
|
|
47
|
+
/** Exit code reported by the command. */
|
|
48
|
+
exitCode: number;
|
|
49
|
+
/** Captured stdout. */
|
|
50
|
+
stdout: string;
|
|
51
|
+
/** Captured stderr. */
|
|
52
|
+
stderr: string;
|
|
53
|
+
}
|
|
54
|
+
/** Lifecycle state of a container. */
|
|
55
|
+
type ContainerStatus = "created" | "disposed" | "running" | "stopped";
|
|
56
|
+
/** Per-file change kind in a {@link WorkdirDiff}. */
|
|
57
|
+
type WorkdirChangeKind = "added" | "deleted" | "modified" | "renamed";
|
|
58
|
+
/** Options for {@link ContainerObservability.snapshotWorkdir}. */
|
|
59
|
+
interface WorkdirSnapshotOptions {
|
|
60
|
+
/** Directory to snapshot; defaults to the container's `workdir`. */
|
|
61
|
+
cwd?: string;
|
|
62
|
+
}
|
|
63
|
+
/** Opaque snapshot reference used to compute a diff later. Release with {@link ContainerObservability.releaseWorkdirSnapshot}. */
|
|
64
|
+
interface WorkdirSnapshot {
|
|
65
|
+
readonly cwd: string;
|
|
66
|
+
readonly createdAt: Date;
|
|
67
|
+
}
|
|
68
|
+
/** Single-file entry in a {@link WorkdirDiff}. */
|
|
69
|
+
interface WorkdirFileChange {
|
|
70
|
+
readonly path: string;
|
|
71
|
+
/** For `kind: "renamed"`, the original path. */
|
|
72
|
+
readonly previousPath?: string;
|
|
73
|
+
readonly kind: WorkdirChangeKind;
|
|
74
|
+
readonly beforeHash?: string;
|
|
75
|
+
readonly afterHash?: string;
|
|
76
|
+
readonly beforeSize?: number;
|
|
77
|
+
readonly afterSize?: number;
|
|
78
|
+
}
|
|
79
|
+
/** Summary stats for a workdir diff operation. */
|
|
80
|
+
interface WorkdirDiffStats {
|
|
81
|
+
readonly durationMs: number;
|
|
82
|
+
readonly filesCompared: number;
|
|
83
|
+
}
|
|
84
|
+
/** Difference between a {@link WorkdirSnapshot} and the current container state. */
|
|
85
|
+
interface WorkdirDiff {
|
|
86
|
+
readonly cwd: string;
|
|
87
|
+
/** Convenience flat list of changed paths. */
|
|
88
|
+
readonly changedFiles: readonly string[];
|
|
89
|
+
/** Detailed per-file change records. */
|
|
90
|
+
readonly fileChanges: readonly WorkdirFileChange[];
|
|
91
|
+
readonly stats: WorkdirDiffStats;
|
|
92
|
+
}
|
|
93
|
+
/** Identity facet of a container — id, name, status, config. */
|
|
94
|
+
interface ContainerIdentity<TType extends ContainerType, TConfig extends ContainerConfigBase<TType>> {
|
|
95
|
+
readonly type: TType;
|
|
96
|
+
/** Provider-assigned container ID (Docker/Podman id, E2B sandbox id, etc.). */
|
|
97
|
+
readonly id: string;
|
|
98
|
+
readonly name: string;
|
|
99
|
+
readonly config: TConfig;
|
|
100
|
+
readonly status: ContainerStatus;
|
|
101
|
+
readonly workdir: string;
|
|
102
|
+
}
|
|
103
|
+
/** Lifecycle facet — start/stop/dispose plus `await using` support. */
|
|
104
|
+
interface ContainerLifecycle {
|
|
105
|
+
/** Start the container. Idempotent for already-running containers. */
|
|
106
|
+
start: () => Promise<void>;
|
|
107
|
+
/** Stop the container without removing it. */
|
|
108
|
+
stop: () => Promise<void>;
|
|
109
|
+
/** Stop and remove the container. Idempotent. */
|
|
110
|
+
dispose: () => Promise<void>;
|
|
111
|
+
[Symbol.asyncDispose]: () => Promise<void>;
|
|
112
|
+
}
|
|
113
|
+
/** Execution facet — run commands inside the container. */
|
|
114
|
+
interface ContainerExecution {
|
|
115
|
+
/**
|
|
116
|
+
* Execute `command` with `args` inside the container, returning the
|
|
117
|
+
* complete {@link ExecResult} once the process exits. Streams of stdout
|
|
118
|
+
* and stderr are buffered into the result strings.
|
|
119
|
+
*/
|
|
120
|
+
exec: (command: string, args: string[], options?: ExecOptions) => Promise<ExecResult>;
|
|
121
|
+
/** Convenience wrapper that runs `script` under `/bin/sh -lc`. */
|
|
122
|
+
execShell: (script: string, options?: ExecOptions) => Promise<ExecResult>;
|
|
123
|
+
/** Process spawner used by agent adapters when wiring this container as `container`. */
|
|
124
|
+
readonly spawner: ProcessSpawner;
|
|
125
|
+
}
|
|
126
|
+
/** Filesystem facet — file I/O between host and container. */
|
|
127
|
+
interface ContainerFileSystem {
|
|
128
|
+
/** Copy a host file or directory into the container. */
|
|
129
|
+
copyTo: (hostPath: string, containerPath: string) => Promise<void>;
|
|
130
|
+
/** Copy a container file or directory out to the host. */
|
|
131
|
+
copyFrom: (containerPath: string, hostPath: string) => Promise<void>;
|
|
132
|
+
/** Write `content` to `path` inside the container, replacing any existing file. */
|
|
133
|
+
writeFile: (path: string, content: Uint8Array | string) => Promise<void>;
|
|
134
|
+
/** Read `path` as a UTF-8 string. */
|
|
135
|
+
readFile: (path: string) => Promise<string>;
|
|
136
|
+
/** Check whether `path` exists inside the container. */
|
|
137
|
+
fileExists: (path: string) => Promise<boolean>;
|
|
138
|
+
/** Create a directory (and parents) inside the container. */
|
|
139
|
+
mkdir: (path: string) => Promise<void>;
|
|
140
|
+
}
|
|
141
|
+
/** Observability facet — logs, status sync, workdir diffing. */
|
|
142
|
+
interface ContainerObservability {
|
|
143
|
+
/** Tail the container's log output. `tail` limits the number of trailing lines. */
|
|
144
|
+
logs: (options?: {
|
|
145
|
+
tail?: number;
|
|
146
|
+
}) => Promise<string>;
|
|
147
|
+
/** Re-query the provider for the container's current status. */
|
|
148
|
+
syncStatus: () => Promise<ContainerStatus>;
|
|
149
|
+
/** Capture an immutable snapshot of `workdir` for later diffing. */
|
|
150
|
+
snapshotWorkdir: (options?: WorkdirSnapshotOptions) => Promise<WorkdirSnapshot>;
|
|
151
|
+
/** Compute the diff between an earlier snapshot and the current workdir. */
|
|
152
|
+
diffWorkdir: (snapshot: WorkdirSnapshot) => Promise<WorkdirDiff>;
|
|
153
|
+
/** Release storage held by a snapshot. Safe to call multiple times. */
|
|
154
|
+
releaseWorkdirSnapshot: (snapshot: WorkdirSnapshot) => Promise<void>;
|
|
155
|
+
}
|
|
156
|
+
/** Composed shape of every concrete container instance. */
|
|
157
|
+
interface ContainerBase<TType extends ContainerType, TConfig extends ContainerConfigBase<TType>> extends ContainerExecution, ContainerFileSystem, ContainerIdentity<TType, TConfig>, ContainerLifecycle, ContainerObservability {}
|
|
158
|
+
//#endregion
|
|
159
|
+
//#region src/container/oci.d.ts
|
|
160
|
+
interface OciBuildBase {
|
|
161
|
+
context?: string;
|
|
162
|
+
args?: Record<string, string>;
|
|
163
|
+
tag?: string;
|
|
164
|
+
}
|
|
165
|
+
type OciBuildConfig = OciBuildBase & ({
|
|
166
|
+
dockerfile: string;
|
|
167
|
+
content?: never;
|
|
168
|
+
} | {
|
|
169
|
+
dockerfile?: never;
|
|
170
|
+
content: string;
|
|
171
|
+
});
|
|
172
|
+
interface OciProviderBase {
|
|
173
|
+
ports?: PortMapping[];
|
|
174
|
+
mounts?: VolumeMount[];
|
|
175
|
+
mountCwd?: string;
|
|
176
|
+
user?: string;
|
|
177
|
+
binary?: string;
|
|
178
|
+
extraArgs?: string[];
|
|
179
|
+
network?: string;
|
|
180
|
+
platform?: string;
|
|
181
|
+
}
|
|
182
|
+
type OciProviderConfig = OciProviderBase & ({
|
|
183
|
+
image: string;
|
|
184
|
+
build?: never;
|
|
185
|
+
} | {
|
|
186
|
+
image?: never;
|
|
187
|
+
build: OciBuildConfig;
|
|
188
|
+
});
|
|
189
|
+
//#endregion
|
|
190
|
+
//#region src/container/docker/types.d.ts
|
|
191
|
+
/** Inline Dockerfile content and build-context shape (re-exported from OCI). */
|
|
192
|
+
type DockerBuildBase = OciBuildBase;
|
|
193
|
+
/** Docker `docker build` configuration: image tag, context, build args. */
|
|
194
|
+
type DockerBuildConfig = OciBuildConfig;
|
|
195
|
+
/** Common provider fields shared with other OCI-style providers. */
|
|
196
|
+
type DockerContainerBase = OciProviderBase;
|
|
197
|
+
/** Provider-specific fields for Docker (image, build, mounts, ports, env). */
|
|
198
|
+
type DockerProviderConfig = OciProviderConfig;
|
|
199
|
+
/** Full config passed to `createContainer({ type: "docker", ... })`. */
|
|
200
|
+
type DockerContainerConfig = ContainerConfigBase<"docker"> & OciProviderConfig;
|
|
201
|
+
/** Docker container instance. */
|
|
202
|
+
interface DockerContainer extends ContainerBase<"docker", DockerContainerConfig> {
|
|
203
|
+
/** Resolve the host port bound to a container port from {@link PortMapping}, or `undefined` if unmapped. */
|
|
204
|
+
getMappedPort: (containerPort: number) => number | undefined;
|
|
205
|
+
}
|
|
206
|
+
//#endregion
|
|
207
|
+
//#region src/container/e2b/types.d.ts
|
|
208
|
+
interface E2BSandboxNetworkOptions {
|
|
209
|
+
allowOut?: string[];
|
|
210
|
+
denyOut?: string[];
|
|
211
|
+
allowPublicTraffic?: boolean;
|
|
212
|
+
maskRequestHost?: string;
|
|
213
|
+
}
|
|
214
|
+
interface E2BSandboxLifecycleOptions {
|
|
215
|
+
onTimeout: "kill" | "pause";
|
|
216
|
+
autoResume?: boolean;
|
|
217
|
+
}
|
|
218
|
+
/** Auth and transport fields shared by every E2B operation. */
|
|
219
|
+
interface E2BConnectionConfig {
|
|
220
|
+
/** E2B API key. Falls back to `E2B_API_KEY` if omitted. */
|
|
221
|
+
apiKey?: string;
|
|
222
|
+
/** Personal access token; an alternative to `apiKey`. Falls back to `E2B_ACCESS_TOKEN`. */
|
|
223
|
+
accessToken?: string;
|
|
224
|
+
/** Override the E2B API domain. Use for self-hosted or staging endpoints. */
|
|
225
|
+
domain?: string;
|
|
226
|
+
/** HTTP request timeout in milliseconds. */
|
|
227
|
+
requestTimeoutMs?: number;
|
|
228
|
+
/** Extra HTTP headers attached to every E2B API call. */
|
|
229
|
+
headers?: Record<string, string>;
|
|
230
|
+
}
|
|
231
|
+
/** Connection + sandbox-instance options shared by create and connect modes. */
|
|
232
|
+
interface E2BContainerBase extends E2BConnectionConfig {
|
|
233
|
+
/** Unix user inside the sandbox. */
|
|
234
|
+
user?: string;
|
|
235
|
+
/** Sandbox lifetime in milliseconds before E2B auto-pauses or kills it. */
|
|
236
|
+
timeoutMs?: number;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Create a fresh E2B sandbox. Use this when you don't have an existing
|
|
240
|
+
* sandbox ID to attach to.
|
|
241
|
+
*/
|
|
242
|
+
interface E2BCreateConfig extends E2BContainerBase {
|
|
243
|
+
/** Type-level discriminator — `sandboxId` is forbidden on create. */
|
|
244
|
+
sandboxId?: never;
|
|
245
|
+
/** E2B template ID or alias. Defaults to E2B's `base` template. */
|
|
246
|
+
template?: string;
|
|
247
|
+
/** Arbitrary metadata attached to the sandbox. */
|
|
248
|
+
metadata?: Record<string, string>;
|
|
249
|
+
/** Run in secure mode (no outbound network unless `network` allows it). */
|
|
250
|
+
secure?: boolean;
|
|
251
|
+
/** Convenience toggle: opens unrestricted outbound network access. */
|
|
252
|
+
allowInternetAccess?: boolean;
|
|
253
|
+
/** Network allowlist/denylist for outbound traffic. */
|
|
254
|
+
network?: E2BSandboxNetworkOptions;
|
|
255
|
+
/** What to do when `timeoutMs` expires (`"kill"` or `"pause"`). */
|
|
256
|
+
lifecycle?: E2BSandboxLifecycleOptions;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Re-attach to an existing E2B sandbox by ID. The create-only fields are
|
|
260
|
+
* forbidden here so the type-system rules out "create-or-connect" ambiguity.
|
|
261
|
+
*/
|
|
262
|
+
interface E2BConnectConfig extends E2BContainerBase {
|
|
263
|
+
/** Existing E2B sandbox ID to attach to. Required. */
|
|
264
|
+
sandboxId: string;
|
|
265
|
+
template?: never;
|
|
266
|
+
metadata?: never;
|
|
267
|
+
secure?: never;
|
|
268
|
+
allowInternetAccess?: never;
|
|
269
|
+
network?: never;
|
|
270
|
+
lifecycle?: never;
|
|
271
|
+
}
|
|
272
|
+
/** Provider-specific fields: either create-new or connect-to-existing. */
|
|
273
|
+
type E2BProviderConfig = E2BConnectConfig | E2BCreateConfig;
|
|
274
|
+
/** Full config passed to `createContainer({ type: "e2b", ... })`. */
|
|
275
|
+
type E2BContainerConfig = ContainerConfigBase<"e2b"> & E2BProviderConfig;
|
|
276
|
+
/** E2B container instance. */
|
|
277
|
+
interface E2BContainer extends ContainerBase<"e2b", E2BContainerConfig> {
|
|
278
|
+
/** Resolve the externally-reachable hostname for a sandbox port. */
|
|
279
|
+
getHost: (port: number) => string;
|
|
280
|
+
}
|
|
281
|
+
//#endregion
|
|
282
|
+
//#region src/container/nerdctl/types.d.ts
|
|
283
|
+
/** Inline Dockerfile content and build-context shape (re-exported from OCI). */
|
|
284
|
+
type NerdctlBuildBase = OciBuildBase;
|
|
285
|
+
/** nerdctl `nerdctl build` configuration: image tag, context, build args. */
|
|
286
|
+
type NerdctlBuildConfig = OciBuildConfig;
|
|
287
|
+
/** Common provider fields shared with other OCI-style providers. */
|
|
288
|
+
type NerdctlContainerBase = NerdctlProviderBase;
|
|
289
|
+
/** Provider-specific fields for nerdctl, layered on top of generic OCI provider options. */
|
|
290
|
+
interface NerdctlProviderBase extends OciProviderBase {
|
|
291
|
+
/** containerd namespace. Defaults to `"default"`. */
|
|
292
|
+
namespace?: string;
|
|
293
|
+
/** Address of the containerd socket (e.g. `unix:///run/containerd/containerd.sock`). */
|
|
294
|
+
address?: string;
|
|
295
|
+
/** Address of the BuildKit daemon used for `nerdctl build`. */
|
|
296
|
+
buildkitHost?: string;
|
|
297
|
+
/** Snapshotter to use (`overlayfs`, `stargz`, etc.). */
|
|
298
|
+
snapshotter?: string;
|
|
299
|
+
/** Extra `nerdctl` flags appended verbatim. */
|
|
300
|
+
args?: string[];
|
|
301
|
+
}
|
|
302
|
+
/** Provider-specific config: nerdctl-specific fields plus generic OCI provider config. */
|
|
303
|
+
type NerdctlProviderConfig = NerdctlProviderBase & OciProviderConfig;
|
|
304
|
+
/** Full config passed to `createContainer({ type: "nerdctl", ... })`. */
|
|
305
|
+
type NerdctlContainerConfig = ContainerConfigBase<"nerdctl"> & NerdctlProviderConfig;
|
|
306
|
+
/** nerdctl container instance. */
|
|
307
|
+
interface NerdctlContainer extends ContainerBase<"nerdctl", NerdctlContainerConfig> {
|
|
308
|
+
/** Resolve the host port bound to a container port from {@link PortMapping}, or `undefined` if unmapped. */
|
|
309
|
+
getMappedPort: (containerPort: number) => number | undefined;
|
|
310
|
+
}
|
|
311
|
+
//#endregion
|
|
312
|
+
//#region src/container/podman/types.d.ts
|
|
313
|
+
/** Inline Dockerfile content and build-context shape (re-exported from OCI). */
|
|
314
|
+
type PodmanBuildBase = OciBuildBase;
|
|
315
|
+
/** Podman `podman build` configuration: image tag, context, build args. */
|
|
316
|
+
type PodmanBuildConfig = OciBuildConfig;
|
|
317
|
+
/** Common provider fields shared with other OCI-style providers. */
|
|
318
|
+
type PodmanContainerBase = OciProviderBase;
|
|
319
|
+
/** Provider-specific fields for Podman (image, build, mounts, ports, env). */
|
|
320
|
+
type PodmanProviderConfig = OciProviderConfig;
|
|
321
|
+
/** Full config passed to `createContainer({ type: "podman", ... })`. */
|
|
322
|
+
type PodmanContainerConfig = ContainerConfigBase<"podman"> & OciProviderConfig;
|
|
323
|
+
/** Podman container instance. */
|
|
324
|
+
interface PodmanContainer extends ContainerBase<"podman", PodmanContainerConfig> {
|
|
325
|
+
/** Resolve the host port bound to a container port from {@link PortMapping}, or `undefined` if unmapped. */
|
|
326
|
+
getMappedPort: (containerPort: number) => number | undefined;
|
|
327
|
+
}
|
|
328
|
+
//#endregion
|
|
329
|
+
//#region src/container/errors.d.ts
|
|
330
|
+
/**
|
|
331
|
+
* Base class for every error thrown by `createContainer(...)` and the
|
|
332
|
+
* resulting container instance. Catch this if you want to handle any
|
|
333
|
+
* container failure uniformly.
|
|
334
|
+
*/
|
|
335
|
+
declare class ContainerError extends Error {
|
|
336
|
+
constructor(message: string);
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Thrown by `createContainer(...)` before the container is started — e.g. the
|
|
340
|
+
* configured provider isn't available, a required peer dependency is missing,
|
|
341
|
+
* the image can't be pulled, or required environment variables are absent.
|
|
342
|
+
*/
|
|
343
|
+
declare class ContainerCreateError extends ContainerError {
|
|
344
|
+
constructor(message: string);
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Thrown when a configured `mounts` entry fails pre-flight validation —
|
|
348
|
+
* typically a missing or unreadable source path on the host.
|
|
349
|
+
*/
|
|
350
|
+
declare class MountValidationError extends ContainerError {
|
|
351
|
+
constructor(message: string);
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Thrown when the container has been created but fails to enter the running
|
|
355
|
+
* state — daemon refused, image entrypoint exited immediately, etc.
|
|
356
|
+
*/
|
|
357
|
+
declare class ContainerStartError extends ContainerError {
|
|
358
|
+
constructor(message: string);
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Thrown by `container.exec(...)` when the command could not be dispatched
|
|
362
|
+
* (the inner command's non-zero exit code is reported on the `ExecResult`
|
|
363
|
+
* itself, not as a thrown error).
|
|
364
|
+
*/
|
|
365
|
+
declare class ContainerExecError extends ContainerError {
|
|
366
|
+
constructor(message: string);
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* Thrown when an operation requires the container to be running but it is in
|
|
370
|
+
* `"created"` or `"stopped"` state.
|
|
371
|
+
*/
|
|
372
|
+
declare class ContainerNotRunningError extends ContainerError {
|
|
373
|
+
constructor(message?: string);
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Thrown when any operation is attempted on a container after `dispose()` (or
|
|
377
|
+
* `await using` cleanup) has run.
|
|
378
|
+
*/
|
|
379
|
+
declare class ContainerDisposedError extends ContainerError {
|
|
380
|
+
constructor(message?: string);
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Thrown by `container.diffWorkdir(...)` when the diff cannot be computed —
|
|
384
|
+
* e.g. the snapshot reference is invalid, the working directory disappeared,
|
|
385
|
+
* or the provider does not support diffs for the current configuration.
|
|
386
|
+
*/
|
|
387
|
+
declare class ContainerDiffError extends ContainerError {
|
|
388
|
+
constructor(message: string);
|
|
389
|
+
}
|
|
390
|
+
//#endregion
|
|
391
|
+
//#region src/container/index.d.ts
|
|
392
|
+
/** Union of every provider config accepted by `createContainer(...)`. Narrow on `type` to pick a provider. */
|
|
393
|
+
type ContainerConfig = DockerContainerConfig | E2BContainerConfig | NerdctlContainerConfig | PodmanContainerConfig;
|
|
394
|
+
/** Union of every provider's running container instance. Narrow on `container.type` to access provider-specific methods. */
|
|
395
|
+
type Container = DockerContainer | E2BContainer | NerdctlContainer | PodmanContainer;
|
|
396
|
+
/**
|
|
397
|
+
* Create a container for sandboxed agent execution.
|
|
398
|
+
*
|
|
399
|
+
* The `type` field on `config` selects the provider; supported values are
|
|
400
|
+
* `"docker"`, `"e2b"`, `"nerdctl"`, and `"podman"`. The provider's daemon
|
|
401
|
+
* (Docker, Podman, etc.) must be running locally, except for `"e2b"` which
|
|
402
|
+
* requires `E2B_API_KEY` / `E2B_ACCESS_TOKEN` and the optional `e2b` peer
|
|
403
|
+
* dependency.
|
|
404
|
+
*
|
|
405
|
+
* Containers are async-disposable. Use `await using` to ensure cleanup:
|
|
406
|
+
*
|
|
407
|
+
* ```ts
|
|
408
|
+
* await using container = await createContainer({
|
|
409
|
+
* type: "docker",
|
|
410
|
+
* image: "node:22",
|
|
411
|
+
* workdir: "/workspace",
|
|
412
|
+
* });
|
|
413
|
+
* await container.exec({ command: ["npm", "install"] });
|
|
414
|
+
* ```
|
|
415
|
+
*
|
|
416
|
+
* Pass the resulting container to a cli-adapter's `container` option to run
|
|
417
|
+
* the agent inside it.
|
|
418
|
+
*
|
|
419
|
+
* @param config Provider-specific configuration. Each provider accepts at minimum `image` or `template` and `workdir`.
|
|
420
|
+
* @returns A promise that resolves to a started container of the selected provider type.
|
|
421
|
+
* @throws {ContainerCreateError} If the provider isn't available, the image can't be pulled, or required env vars are missing.
|
|
422
|
+
* @throws {ContainerStartError} If the container fails to start.
|
|
423
|
+
*/
|
|
424
|
+
declare function createContainer(config: DockerContainerConfig): Promise<DockerContainer>;
|
|
425
|
+
declare function createContainer(config: E2BContainerConfig): Promise<E2BContainer>;
|
|
426
|
+
declare function createContainer(config: NerdctlContainerConfig): Promise<NerdctlContainer>;
|
|
427
|
+
declare function createContainer(config: PodmanContainerConfig): Promise<PodmanContainer>;
|
|
428
|
+
//#endregion
|
|
429
|
+
export { WorkdirDiffStats as $, E2BCreateConfig as A, ContainerExecution as B, NerdctlProviderBase as C, E2BContainer as D, E2BConnectionConfig as E, DockerContainerBase as F, ContainerStatus as G, ContainerIdentity as H, DockerContainerConfig as I, ExecResult as J, ContainerType as K, DockerProviderConfig as L, DockerBuildBase as M, DockerBuildConfig as N, E2BContainerBase as O, DockerContainer as P, WorkdirDiff as Q, ContainerBase as R, NerdctlContainerConfig as S, E2BConnectConfig as T, ContainerLifecycle as U, ContainerFileSystem as V, ContainerObservability as W, VolumeMount as X, PortMapping as Y, WorkdirChangeKind as Z, PodmanProviderConfig as _, ContainerDiffError as a, NerdctlContainer as b, ContainerExecError as c, MountValidationError as d, WorkdirFileChange as et, PodmanBuildBase as f, PodmanContainerConfig as g, PodmanContainerBase as h, ContainerCreateError as i, E2BProviderConfig as j, E2BContainerConfig as k, ContainerNotRunningError as l, PodmanContainer as m, ContainerConfig as n, WorkdirSnapshotOptions as nt, ContainerDisposedError as o, PodmanBuildConfig as p, ExecOptions as q, createContainer as r, ContainerError as s, Container as t, WorkdirSnapshot as tt, ContainerStartError as u, NerdctlBuildBase as v, NerdctlProviderConfig as w, NerdctlContainerBase as x, NerdctlBuildConfig as y, ContainerConfigBase as z };
|