coding-agents-sdk 0.18.0 → 0.20.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 +221 -4
- package/dist/Agent-DjrM6eSk.mjs +4 -0
- package/dist/SdkAgent-DYmXd2QH.mjs +1 -0
- 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 +2 -2
- package/dist/adapters/claude-code-cli-pty/index.mjs +5 -5
- package/dist/adapters/claude-code-sdk/index.d.mts +1 -1
- package/dist/adapters/claude-code-sdk/index.mjs +4 -4
- package/dist/adapters/codex-cli/index.d.mts +1 -1
- package/dist/adapters/codex-cli/index.mjs +4 -2
- package/dist/adapters/codex-sdk/index.d.mts +1 -1
- package/dist/adapters/codex-sdk/index.mjs +1 -1
- package/dist/adapters/cursor-cli/index.d.mts +1 -1
- package/dist/adapters/cursor-cli/index.mjs +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/gemini-cli/index.mjs +1 -1
- package/dist/adapters/opencode-cli/index.d.mts +1 -1
- package/dist/adapters/opencode-cli/index.mjs +1 -1
- package/dist/adapters/pi-cli/index.d.mts +1 -1
- package/dist/adapters/pi-cli/index.mjs +1 -1
- package/dist/classify-error-DJq_uoy2.mjs +8 -0
- package/dist/container/index.d.mts +2 -2
- package/dist/container/index.mjs +1 -1
- package/dist/container-BlsSoBe1.mjs +1 -0
- package/dist/container-C7oWwLGK.mjs +1 -0
- package/dist/container-DUoj_mnh.mjs +1 -0
- package/dist/container-DXQ92RVu.mjs +1 -0
- package/dist/container-MazMFZg8.mjs +1 -0
- package/dist/control-requests-DtjV0e4o.mjs +1 -0
- package/dist/core/process/index.d.mts +2 -2
- package/dist/core/process/index.mjs +1 -1
- package/dist/diff-CMWH9a0d.mjs +1 -0
- package/dist/{errors-aYGbvsaq.mjs → errors-BauhTL3l.mjs} +1 -1
- package/dist/{events-BxEB6zHt.d.mts → events-DoTNE9UF.d.mts} +64 -5
- package/dist/{index-DWv7tLOX.d.mts → index--TbBtTi8.d.mts} +4 -10
- package/dist/{index-BWAsLSN3.d.mts → index-B6HqsIFZ.d.mts} +4 -10
- package/dist/{index-CmRm10Lo.d.mts → index-BA-SATzW.d.mts} +3 -7
- package/dist/{index-DB0fLwpu.d.mts → index-BOpfjzkT.d.mts} +1 -5
- package/dist/{index-DH2vDD3l.d.mts → index-BUsykYQW.d.mts} +5 -9
- package/dist/index-BimeR91j.d.mts +6 -0
- package/dist/{index-CPhcEEAp.d.mts → index-Bs2PNdMx.d.mts} +4 -10
- package/dist/{index-BrFs4M0Z.d.mts → index-CDN7Re-3.d.mts} +3 -7
- package/dist/{index-DWmHDEQL.d.mts → index-DOsWiOqK.d.mts} +88 -25
- package/dist/{index-Ssb7kE6D.d.mts → index-DP-w59TG.d.mts} +1 -5
- package/dist/{index-BEEVpHOg.d.mts → index-DmzP2soo.d.mts} +4 -10
- package/dist/{index-DCQu5ZAu.d.mts → index-DoVEbwlx.d.mts} +63 -24
- package/dist/{index-DpPNo3dX.d.mts → index-_lsNncl5.d.mts} +29 -18
- package/dist/index.d.mts +17 -19
- package/dist/index.mjs +1 -1
- package/dist/oci-t88M5ODN.mjs +2 -0
- package/dist/parser-D-7JMlQr.mjs +2 -0
- package/dist/{session-markers-BHsJLWJk.mjs → permission-updates-lGl8T2lW.mjs} +1 -1
- package/dist/sandbox/index.d.mts +1 -1
- package/dist/sandbox/index.mjs +1 -1
- package/dist/{sandbox-CYA69miM.mjs → sandbox-BemAIoIo.mjs} +2 -2
- package/dist/schemas/index.d.mts +2 -2
- package/dist/schemas/index.mjs +1 -1
- package/dist/schemas-CF1pu_vW.mjs +1 -0
- package/dist/spawner-CYAQQABs.mjs +1 -0
- package/dist/{types-D0ejXDa9.d.mts → types-1ueeWtwd.d.mts} +69 -9
- package/dist/{types-COmjfh8B.d.mts → types-BetgZysV.d.mts} +0 -2
- package/dist/util-CCXryPDO.mjs +1 -0
- package/package.json +10 -10
- package/dist/Agent-WqGee5TR.mjs +0 -4
- package/dist/SdkAgent-BjdSrtFe.mjs +0 -1
- package/dist/classify-error-DK2WpxiL.mjs +0 -8
- package/dist/container-Bdb90GJb.mjs +0 -1
- package/dist/container-DMFxf-kn.mjs +0 -1
- package/dist/container-Dvr-p53c.mjs +0 -1
- package/dist/container-dCRMBvQw.mjs +0 -1
- package/dist/container-w0rl1QMH.mjs +0 -1
- package/dist/diff-Dqyk2cdt.mjs +0 -1
- package/dist/index-DvwVRB7K.d.mts +0 -10
- package/dist/oci-DTNwW-WH.mjs +0 -1
- package/dist/parser-jSS5vOTN.mjs +0 -2
- package/dist/schemas-CkdQXAep.mjs +0 -1
- package/dist/spawner-CgfyvnR4.mjs +0 -1
- package/dist/util-B4HTdOSc.mjs +0 -1
|
@@ -1,10 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { i as ProcessSpawner } from "./types-
|
|
3
|
-
import { _ as ProviderEventHandler, f as EnsureDisjoint, l as BaseAgent, p as ExclusiveExecutionTargetOptions, t as AgentEventHandler } from "./types-
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import { t as Container } from "./index-DOsWiOqK.mjs";
|
|
2
|
+
import { i as ProcessSpawner } from "./types-BetgZysV.mjs";
|
|
3
|
+
import { N as ClaudePermissionMode, _ as ProviderEventHandler, f as EnsureDisjoint, l as BaseAgent, p as ExclusiveExecutionTargetOptions, t as AgentEventHandler } from "./types-1ueeWtwd.mjs";
|
|
4
|
+
import { l as Sandbox } from "./index-BA-SATzW.mjs";
|
|
5
|
+
import { E as McpServerConfig } from "./events-DoTNE9UF.mjs";
|
|
6
6
|
import { z } from "zod/v4";
|
|
7
|
-
|
|
7
|
+
/** A control request Claude Code accepts on its stream-json input, such as `{ subtype: "stop_task", task_id }`. */
|
|
8
|
+
type ClaudeControlRequestPayload = {
|
|
9
|
+
subtype: string;
|
|
10
|
+
} & Record<string, unknown>;
|
|
11
|
+
/**
|
|
12
|
+
* Why a control request did not get a success answer:
|
|
13
|
+
* - `"no-open-input"`: no run of this agent has Claude Code's input open; start the run with `keepInputOpen: true` or a
|
|
14
|
+
* permission handler.
|
|
15
|
+
* - `"input-closed"`: the run ended, or its input closed, before Claude Code answered.
|
|
16
|
+
* - `"refused"`: Claude Code answered with an error, for example for a request subtype it does not support; `message`
|
|
17
|
+
* holds its text.
|
|
18
|
+
*/
|
|
19
|
+
type ClaudeControlRequestFailure = "no-open-input" | "input-closed" | "refused";
|
|
20
|
+
/** Rejection of `sendControlRequest()` and `stopTask()` on a `claude-code-cli` agent. */
|
|
21
|
+
declare class ClaudeControlRequestError extends Error {
|
|
22
|
+
readonly reason: ClaudeControlRequestFailure;
|
|
23
|
+
constructor(reason: ClaudeControlRequestFailure, message: string);
|
|
24
|
+
}
|
|
8
25
|
declare const claudeSystemEventSchema: z.ZodObject<{
|
|
9
26
|
type: z.ZodLiteral<"system">;
|
|
10
27
|
session_id: z.ZodString;
|
|
@@ -16,6 +33,7 @@ declare const claudeSystemEventSchema: z.ZodObject<{
|
|
|
16
33
|
hook_started: "hook_started";
|
|
17
34
|
init: "init";
|
|
18
35
|
session_state_changed: "session_state_changed";
|
|
36
|
+
task_started: "task_started";
|
|
19
37
|
}>;
|
|
20
38
|
uuid: z.ZodString;
|
|
21
39
|
tools: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
@@ -40,6 +58,8 @@ declare const claudeSystemEventSchema: z.ZodObject<{
|
|
|
40
58
|
requires_action: "requires_action";
|
|
41
59
|
running: "running";
|
|
42
60
|
}>>;
|
|
61
|
+
task_id: z.ZodOptional<z.ZodString>;
|
|
62
|
+
tool_use_id: z.ZodOptional<z.ZodString>;
|
|
43
63
|
}, z.core.$strip>;
|
|
44
64
|
type ClaudeSystemEvent = z.infer<typeof claudeSystemEventSchema>;
|
|
45
65
|
declare const claudeAssistantEventSchema: z.ZodObject<{
|
|
@@ -176,6 +196,7 @@ declare const claudeEventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
176
196
|
hook_started: "hook_started";
|
|
177
197
|
init: "init";
|
|
178
198
|
session_state_changed: "session_state_changed";
|
|
199
|
+
task_started: "task_started";
|
|
179
200
|
}>;
|
|
180
201
|
uuid: z.ZodString;
|
|
181
202
|
tools: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
@@ -200,6 +221,8 @@ declare const claudeEventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
200
221
|
requires_action: "requires_action";
|
|
201
222
|
running: "running";
|
|
202
223
|
}>>;
|
|
224
|
+
task_id: z.ZodOptional<z.ZodString>;
|
|
225
|
+
tool_use_id: z.ZodOptional<z.ZodString>;
|
|
203
226
|
}, z.core.$strip>, z.ZodObject<{
|
|
204
227
|
type: z.ZodLiteral<"assistant">;
|
|
205
228
|
session_id: z.ZodString;
|
|
@@ -314,15 +337,6 @@ type ClaudeEvent = z.infer<typeof claudeEventSchema>;
|
|
|
314
337
|
declare const claudeProviderEventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
315
338
|
type: z.ZodLiteral<"system">;
|
|
316
339
|
session_id: z.ZodString;
|
|
317
|
-
subtype: z.ZodEnum<{
|
|
318
|
-
hook_failed: "hook_failed";
|
|
319
|
-
hook_finished: "hook_finished";
|
|
320
|
-
hook_response: "hook_response";
|
|
321
|
-
hook_skipped: "hook_skipped";
|
|
322
|
-
hook_started: "hook_started";
|
|
323
|
-
init: "init";
|
|
324
|
-
session_state_changed: "session_state_changed";
|
|
325
|
-
}>;
|
|
326
340
|
tools: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
327
341
|
model: z.ZodOptional<z.ZodString>;
|
|
328
342
|
cwd: z.ZodOptional<z.ZodString>;
|
|
@@ -336,12 +350,15 @@ declare const claudeProviderEventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
336
350
|
requires_action: "requires_action";
|
|
337
351
|
running: "running";
|
|
338
352
|
}>>;
|
|
353
|
+
task_id: z.ZodOptional<z.ZodString>;
|
|
354
|
+
tool_use_id: z.ZodOptional<z.ZodString>;
|
|
355
|
+
subtype: z.ZodString;
|
|
339
356
|
uuid: z.ZodOptional<z.ZodString>;
|
|
340
357
|
mcp_servers: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
341
358
|
name: z.ZodString;
|
|
342
359
|
status: z.ZodString;
|
|
343
|
-
}, z.core.$
|
|
344
|
-
}, z.core.$
|
|
360
|
+
}, z.core.$loose>>>;
|
|
361
|
+
}, z.core.$loose>, z.ZodObject<{
|
|
345
362
|
type: z.ZodLiteral<"assistant">;
|
|
346
363
|
session_id: z.ZodString;
|
|
347
364
|
parent_tool_use_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
@@ -446,8 +463,6 @@ declare const claudeProviderEventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
446
463
|
}, z.core.$strip>;
|
|
447
464
|
}, z.core.$strip>], "type">;
|
|
448
465
|
type ClaudeProviderEvent = z.infer<typeof claudeProviderEventSchema>;
|
|
449
|
-
//#endregion
|
|
450
|
-
//#region src/adapters/claude-code-cli/types.d.ts
|
|
451
466
|
/**
|
|
452
467
|
* How Claude Code CLI handles tool-permission prompts.
|
|
453
468
|
* - `"default"`: stop and ask via the permission handler.
|
|
@@ -457,7 +472,7 @@ type ClaudeProviderEvent = z.infer<typeof claudeProviderEventSchema>;
|
|
|
457
472
|
* - `"bypassPermissions"`: disable the permission system entirely (dangerous).
|
|
458
473
|
* - `"plan"`: read-only planning mode; no edits, no shell.
|
|
459
474
|
*/
|
|
460
|
-
type ClaudeCodeCliPermissionMode =
|
|
475
|
+
type ClaudeCodeCliPermissionMode = ClaudePermissionMode;
|
|
461
476
|
/** Per-run options for the `claude-code-cli` adapter. */
|
|
462
477
|
interface ClaudeCodeCliRunOptions {
|
|
463
478
|
/** Allowlist of tool names. */
|
|
@@ -497,6 +512,18 @@ type ClaudeCodeCliAgentOptions = ClaudeCodeCliRunOptions & ExclusiveExecutionTar
|
|
|
497
512
|
logPath?: string;
|
|
498
513
|
/** Sets `CI=true` in the subprocess env unless explicitly `false`. Default: `true`. Does not change Claude Code's output formatting on its own. */
|
|
499
514
|
ci?: boolean;
|
|
515
|
+
/**
|
|
516
|
+
* Keep Claude Code's input open in stream-json mode for each run, so `sendInput()`, `sendControlRequest()`, and
|
|
517
|
+
* `stopTask()` can reach the running process. The input closes once Claude Code reports the session idle after the
|
|
518
|
+
* run's result, or when the run stops. A registered permission or question handler keeps the input open the same
|
|
519
|
+
* way without this option, but only this option makes the agent report `capabilities.midRunInput`.
|
|
520
|
+
*/
|
|
521
|
+
keepInputOpen?: boolean;
|
|
522
|
+
/**
|
|
523
|
+
* Emit `message-delta` and `reasoning-delta` events while Claude generates text, by running Claude Code with
|
|
524
|
+
* `--include-partial-messages`. The whole `message` and `reasoning` events still follow.
|
|
525
|
+
*/
|
|
526
|
+
streamText?: boolean;
|
|
500
527
|
/** Custom process spawner; set by `createContainer`/`createSandbox`, rarely needed manually. */
|
|
501
528
|
spawner?: ProcessSpawner;
|
|
502
529
|
/** Convenience: equivalent to calling `agent.onEvent(handler)` post-construction. */
|
|
@@ -514,9 +541,21 @@ interface ClaudeCodeCliAgent extends BaseAgent<EnsureDisjoint<ClaudeCodeCliRunOp
|
|
|
514
541
|
* acquired a session ID — run at least one prompt first.
|
|
515
542
|
*/
|
|
516
543
|
fork: () => ClaudeCodeCliAgent;
|
|
544
|
+
/**
|
|
545
|
+
* Sends a control request to the running Claude Code process and resolves with the `response` of its success answer.
|
|
546
|
+
*
|
|
547
|
+
* Requires a run whose input is open (`keepInputOpen: true` or a permission handler). Rejects with
|
|
548
|
+
* `ClaudeControlRequestError`: `"no-open-input"` when no such run is active, `"input-closed"` when the run ends before
|
|
549
|
+
* Claude Code answers, and `"refused"` when Claude Code answers with an error.
|
|
550
|
+
*/
|
|
551
|
+
sendControlRequest: (request: ClaudeControlRequestPayload) => Promise<unknown>;
|
|
552
|
+
/**
|
|
553
|
+
* Stops one running task, such as a subagent started with the Task tool, while the rest of the run continues. `taskId`
|
|
554
|
+
* is the `task_id` of the task's `system` `task_started` event, not its tool use id. Rejects like
|
|
555
|
+
* `sendControlRequest()`. Claude Code can answer success for an ID it does not know, so resolving does not confirm that
|
|
556
|
+
* a task stopped.
|
|
557
|
+
*/
|
|
558
|
+
stopTask: (taskId: string) => Promise<void>;
|
|
517
559
|
}
|
|
518
|
-
//#endregion
|
|
519
|
-
//#region src/adapters/claude-code-cli/adapter.d.ts
|
|
520
560
|
declare const createClaudeCodeCliAgent: (options?: ClaudeCodeCliAgentOptions) => ClaudeCodeCliAgent;
|
|
521
|
-
|
|
522
|
-
export { ClaudeCodeCliRunOptions as a, ClaudeProviderEvent as c, ClaudeSystemEvent as d, ClaudeUserEvent as f, ClaudeCodeCliPermissionMode as i, ClaudeRateLimitEvent as l, ClaudeCodeCliAgent as n, ClaudeAssistantEvent as o, ClaudeCodeCliAgentOptions as r, ClaudeEvent as s, createClaudeCodeCliAgent as t, ClaudeResultEvent as u };
|
|
561
|
+
export { ClaudeCodeCliRunOptions as a, ClaudeProviderEvent as c, ClaudeSystemEvent as d, ClaudeUserEvent as f, ClaudeControlRequestPayload as h, ClaudeCodeCliPermissionMode as i, ClaudeRateLimitEvent as l, ClaudeControlRequestFailure as m, ClaudeCodeCliAgent as n, ClaudeAssistantEvent as o, ClaudeControlRequestError as p, ClaudeCodeCliAgentOptions as r, ClaudeEvent as s, createClaudeCodeCliAgent as t, ClaudeResultEvent as u };
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { i as ProcessSpawner } from "./types-
|
|
3
|
-
import { _ as ProviderEventHandler, f as EnsureDisjoint, l as BaseAgent, p as ExclusiveExecutionTargetOptions, t as AgentEventHandler } from "./types-
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import { t as Container } from "./index-DOsWiOqK.mjs";
|
|
2
|
+
import { i as ProcessSpawner } from "./types-BetgZysV.mjs";
|
|
3
|
+
import { _ as ProviderEventHandler, f as EnsureDisjoint, l as BaseAgent, p as ExclusiveExecutionTargetOptions, t as AgentEventHandler } from "./types-1ueeWtwd.mjs";
|
|
4
|
+
import { l as Sandbox } from "./index-BA-SATzW.mjs";
|
|
5
|
+
import { E as McpServerConfig } from "./events-DoTNE9UF.mjs";
|
|
6
6
|
import { z } from "zod/v4";
|
|
7
|
-
//#region src/adapters/codex-cli/events/schemas.d.ts
|
|
8
7
|
/**
|
|
9
8
|
* Permissive shape for any raw event Codex CLI emits — `{ type: string }`
|
|
10
9
|
* plus arbitrary additional fields. Narrow on `event.type` against the
|
|
@@ -341,8 +340,6 @@ declare const codexProviderEventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
341
340
|
}, z.core.$loose>]>>;
|
|
342
341
|
}, z.core.$loose>], "type">;
|
|
343
342
|
type CodexProviderEvent = z.infer<typeof codexProviderEventSchema>;
|
|
344
|
-
//#endregion
|
|
345
|
-
//#region src/adapters/codex-cli/types.d.ts
|
|
346
343
|
/**
|
|
347
344
|
* Filesystem sandbox policy for Codex CLI.
|
|
348
345
|
* - `"read-only"`: tools cannot write.
|
|
@@ -352,13 +349,20 @@ type CodexProviderEvent = z.infer<typeof codexProviderEventSchema>;
|
|
|
352
349
|
type CodexCliSandboxMode = "danger-full-access" | "read-only" | "workspace-write";
|
|
353
350
|
/**
|
|
354
351
|
* How Codex CLI handles approval prompts.
|
|
355
|
-
* - `"default"`: leave
|
|
356
|
-
* - `"auto-approve"`:
|
|
357
|
-
* - `"bypass-sandbox"`:
|
|
352
|
+
* - `"default"`: leave the configured approval behavior in place. The app-server transport bridges native requests to a permission handler.
|
|
353
|
+
* - `"auto-approve"`: use automatic review in the `workspace-write` sandbox.
|
|
354
|
+
* - `"bypass-sandbox"`: disable approvals and Codex's sandbox for externally isolated execution.
|
|
358
355
|
*/
|
|
359
356
|
type CodexCliPermissionMode = "auto-approve" | "bypass-sandbox" | "default";
|
|
360
357
|
/** Per-run options for the `codex-cli` adapter. */
|
|
361
358
|
interface CodexCliRunOptions {
|
|
359
|
+
/** Fork the current session before this run. Requires the app-server transport and an existing sessionId. */
|
|
360
|
+
forkSession?: boolean;
|
|
361
|
+
/**
|
|
362
|
+
* Native collaboration mode. Requires the app-server transport. In `"plan"` mode, a plan Codex proposes is the run's
|
|
363
|
+
* `text`.
|
|
364
|
+
*/
|
|
365
|
+
collaborationMode?: "default" | "plan";
|
|
362
366
|
/**
|
|
363
367
|
* Filesystem sandbox policy for the default approval strategy.
|
|
364
368
|
* Other permission modes select their own sandbox behavior.
|
|
@@ -366,23 +370,33 @@ interface CodexCliRunOptions {
|
|
|
366
370
|
sandboxMode?: CodexCliSandboxMode;
|
|
367
371
|
/** Extra directories outside `cwd` writable under `workspace-write`. */
|
|
368
372
|
additionalDirectories?: string[];
|
|
369
|
-
/** Suppress
|
|
373
|
+
/** Suppress the exec transport's "not a git repo" confirmation prompt. App-server does not require a Git repository. */
|
|
370
374
|
skipGitRepoCheck?: boolean;
|
|
371
375
|
/** Approval prompt strategy. */
|
|
372
376
|
permissionMode?: CodexCliPermissionMode;
|
|
373
|
-
/**
|
|
377
|
+
/**
|
|
378
|
+
* When `true`, Codex does not persist this run's history. App-server continuation requires `forkSession: true`, and
|
|
379
|
+
* an ephemeral app-server run's session ID does not become `agent.sessionId`.
|
|
380
|
+
*/
|
|
374
381
|
ephemeral?: boolean;
|
|
375
382
|
/** Path to an MCP config file passed via `--mcp-config`. */
|
|
376
383
|
mcpConfig?: string;
|
|
377
384
|
/** Inline MCP server config map. */
|
|
378
385
|
mcpServers?: Record<string, McpServerConfig>;
|
|
379
|
-
/** Extra CLI flags
|
|
386
|
+
/** Extra CLI flags. Exec forwards them verbatim; app-server rejects exec-only flags and externally configured listeners. */
|
|
380
387
|
extraArgs?: string[];
|
|
381
388
|
/** Not supported — Codex manages its own system prompt. */
|
|
382
389
|
systemPrompt?: never;
|
|
383
390
|
}
|
|
384
391
|
/** Constructor options for `createAgent("codex-cli", ...)`. */
|
|
385
392
|
type CodexCliAgentOptions = CodexCliRunOptions & ExclusiveExecutionTargetOptions<Container, Sandbox> & {
|
|
393
|
+
/** Default `exec` preserves the CLI JSON stream. `app-server` enables interactive permission handlers. */
|
|
394
|
+
transport?: "app-server" | "exec";
|
|
395
|
+
/**
|
|
396
|
+
* Emit `message-delta` and `reasoning-delta` events while Codex generates text. The whole `message` and
|
|
397
|
+
* `reasoning` events still follow. Has no effect on the `exec` transport, where Codex prints whole items only.
|
|
398
|
+
*/
|
|
399
|
+
streamText?: boolean;
|
|
386
400
|
/** Path or argv to the `codex` binary. */
|
|
387
401
|
command?: string[] | string;
|
|
388
402
|
/** Working directory the agent operates against. */
|
|
@@ -391,7 +405,7 @@ type CodexCliAgentOptions = CodexCliRunOptions & ExclusiveExecutionTargetOptions
|
|
|
391
405
|
env?: Record<string, string>;
|
|
392
406
|
/** Default `true`: `process.env` is inherited and `env` overlays it. Set `false` to suppress host-env propagation. */
|
|
393
407
|
propagateEnv?: boolean;
|
|
394
|
-
/** Existing Codex thread ID to resume
|
|
408
|
+
/** Existing Codex thread ID to resume. */
|
|
395
409
|
sessionId?: string;
|
|
396
410
|
/** Codex model identifier. */
|
|
397
411
|
model?: string;
|
|
@@ -408,8 +422,5 @@ interface CodexCliAgent extends BaseAgent<EnsureDisjoint<CodexCliRunOptions>> {
|
|
|
408
422
|
readonly type: "codex-cli";
|
|
409
423
|
onProviderEvent: (handler: ProviderEventHandler<CodexProviderEvent>) => () => void;
|
|
410
424
|
}
|
|
411
|
-
//#endregion
|
|
412
|
-
//#region src/adapters/codex-cli/adapter.d.ts
|
|
413
425
|
declare const createCodexCliAgent: (options?: CodexCliAgentOptions) => CodexCliAgent;
|
|
414
|
-
//#endregion
|
|
415
426
|
export { CodexCliRunOptions as a, CodexEvent as c, CodexItemUpdatedEvent as d, CodexProviderEvent as f, CodexTurnFailedEvent as g, CodexTurnCompletedEvent as h, CodexCliPermissionMode as i, CodexItemCompletedEvent as l, CodexThreadStartedEvent as m, CodexCliAgent as n, CodexCliSandboxMode as o, CodexProviderItem as p, CodexCliAgentOptions as r, CodexErrorEvent as s, createCodexCliAgent as t, CodexItemStartedEvent as u };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as SpawnOptions, i as ProcessSpawner, n as ProcessResult, r as ProcessSignal, t as AgentProcess } from "./types-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { a as
|
|
6
|
-
import { a as
|
|
7
|
-
import { a as
|
|
8
|
-
import { a as
|
|
9
|
-
import { a as
|
|
10
|
-
import { a as
|
|
11
|
-
import { a as
|
|
12
|
-
import { a as
|
|
13
|
-
import { a as
|
|
14
|
-
import { a as
|
|
15
|
-
import {
|
|
16
|
-
import { n as spawnProcess, t as ProcessStdinError } from "./index-DvwVRB7K.mjs";
|
|
1
|
+
import { a as ClaudeCodeCliRunOptions, c as ClaudeProviderEvent, d as ClaudeSystemEvent, f as ClaudeUserEvent, h as ClaudeControlRequestPayload, i as ClaudeCodeCliPermissionMode, l as ClaudeRateLimitEvent, m as ClaudeControlRequestFailure, n as ClaudeCodeCliAgent, o as ClaudeAssistantEvent, p as ClaudeControlRequestError, r as ClaudeCodeCliAgentOptions, s as ClaudeEvent, u as ClaudeResultEvent } from "./index-DoVEbwlx.mjs";
|
|
2
|
+
import { a as SpawnOptions, i as ProcessSpawner, n as ProcessResult, r as ProcessSignal, t as AgentProcess } from "./types-BetgZysV.mjs";
|
|
3
|
+
import { a as ClaudeCodeCliPtyPermissionMode, i as ClaudeCodeCliPtyModule, n as ClaudeCodeCliPtyAgent, o as ClaudeCodeCliPtyProcess, r as ClaudeCodeCliPtyAgentOptions, s as ClaudeCodeCliPtyRunOptions } from "./index-BUsykYQW.mjs";
|
|
4
|
+
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-CDN7Re-3.mjs";
|
|
5
|
+
import { a as CodexCliRunOptions, c as CodexEvent, d as CodexItemUpdatedEvent, f as CodexProviderEvent, g as CodexTurnFailedEvent, h as CodexTurnCompletedEvent, i as CodexCliPermissionMode, l as CodexItemCompletedEvent, m as CodexThreadStartedEvent, n as CodexCliAgent, o as CodexCliSandboxMode, p as CodexProviderItem, r as CodexCliAgentOptions, s as CodexErrorEvent, u as CodexItemStartedEvent } from "./index-_lsNncl5.mjs";
|
|
6
|
+
import { a as CodexSdkItem, i as CodexSdkEvent, n as CodexSdkAgent, o as CodexSdkPermissionMode, r as CodexSdkAgentOptions, s as CodexSdkRunOptions } from "./index-BOpfjzkT.mjs";
|
|
7
|
+
import { a as CursorCliRunOptions, i as CursorCliPermissionMode, n as CursorCliAgent, o as CursorCliSandboxMode, r as CursorCliAgentOptions, s as CursorCliEvent } from "./index-B6HqsIFZ.mjs";
|
|
8
|
+
import { a as CursorSdkMcpHttpAuth, c as CursorSdkSettingSource, i as CursorSdkEvent, n as CursorSdkAgent, o as CursorSdkMcpServerConfig, r as CursorSdkAgentOptions, s as CursorSdkRunOptions } from "./index-DP-w59TG.mjs";
|
|
9
|
+
import { a as GeminiCliRunOptions, i as GeminiCliPermissionMode, n as GeminiCliAgent, o as GeminiEvent, r as GeminiCliAgentOptions } from "./index-Bs2PNdMx.mjs";
|
|
10
|
+
import { a as OpencodeEvent, i as OpencodeCliRunOptions, n as OpencodeCliAgent, r as OpencodeCliAgentOptions } from "./index--TbBtTi8.mjs";
|
|
11
|
+
import { a as PiCliThinkingLevel, i as PiCliRunOptions, n as PiCliAgent, o as PiEvent, r as PiCliAgentOptions } from "./index-DmzP2soo.mjs";
|
|
12
|
+
import { A as QuestionHandler, C as RunStatus, D as ZodRunRequest, E as StructuredRunRequest, F as PermissionHandler, I as PermissionRequest, M as QuestionRequest, N as ClaudePermissionMode, O as Question, P as PermissionDecision, S as RunStats, T as StopReason, _ as ProviderEventHandler, a as AgentValidationError, b as RunRequest, c as AnyRunResult, d as CompletedRunResult, g as ProviderEvent, h as JsonSchemaRunRequest, i as AgentType, j as QuestionOption, k as QuestionAnswers, 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 RunError, w as RunTiming, x as RunResult, y as RunProcessInfo } from "./types-1ueeWtwd.mjs";
|
|
13
|
+
import { A as DockerAttachConfig, B as WorkdirDiff, C as E2BConnectConfig, D as E2BCreateConfig, E as E2BContainerConfig, F as ExecOptions, H as WorkdirFileChange, I as ExecResult, L as PortMapping, M as DockerContainerConfig, N as ContainerStatus, O as E2BProviderConfig, P as ContainerType, R as VolumeMount, S as NerdctlProviderConfig, T as E2BContainer, U as WorkdirSnapshot, V as WorkdirDiffStats, W as WorkdirSnapshotOptions, _ as PodmanAttachConfig, a as ContainerAttachError, b as NerdctlContainer, c as ContainerDisposedError, d as ContainerNotFoundError, f as ContainerNotRunningError, g as AttachedPodmanContainer, h as MountValidationError, i as createContainer, j as DockerContainer, k as AttachedDockerContainer, l as ContainerError, m as ContainerStartError, n as ContainerConfig, o as ContainerCreateError, p as ContainerRemoveError, r as attachContainer, s as ContainerDiffError, t as Container, u as ContainerExecError, v as PodmanContainer, w as E2BConnectionConfig, x as NerdctlContainerConfig, y as PodmanContainerConfig, z as WorkdirChangeKind } from "./index-DOsWiOqK.mjs";
|
|
14
|
+
import { a as FirejailSandbox, c as NsjailSandboxConfig, d as SandboxStatus, f as SandboxType, i as BubblewrapSandboxConfig, l as Sandbox, n as createSandbox, o as FirejailSandboxConfig, r as BubblewrapSandbox, s as NsjailSandbox, t as SandboxCreateError, u as SandboxConfig } from "./index-BA-SATzW.mjs";
|
|
15
|
+
import { n as spawnProcess, t as ProcessStdinError } from "./index-BimeR91j.mjs";
|
|
17
16
|
import "./schemas/index.mjs";
|
|
18
|
-
|
|
17
|
+
import { C as ContentPart, D as TextContentPart, E as McpServerConfig, O as agentCapabilitiesSchema, S as AgentCapabilities, T as JsonSchema, a as ReasoningEvent, c as StderrEvent, f as eventSchema, i as ReasoningDeltaEvent, l as ToolCallEvent, n as MessageDeltaEvent, o as SessionEndEvent, r as MessageEvent, s as SessionStartEvent, t as AgentEvent, u as ToolResultEvent, w as ImageContentPart } from "./events-DoTNE9UF.mjs";
|
|
19
18
|
interface AgentOptionsByType {
|
|
20
19
|
"claude-code-cli-pty": ClaudeCodeCliPtyAgentOptions;
|
|
21
20
|
"claude-code-cli": ClaudeCodeCliAgentOptions;
|
|
@@ -79,5 +78,4 @@ export declare function createAgent(type: "gemini-cli", options?: GeminiCliAgent
|
|
|
79
78
|
export declare function createAgent(type: "opencode-cli", options?: OpencodeCliAgentOptions): Promise<OpencodeCliAgent>;
|
|
80
79
|
export declare function createAgent(type: "pi-cli", options?: PiCliAgentOptions): Promise<PiCliAgent>;
|
|
81
80
|
export declare function createAgent<T extends AgentType>(type: T, options?: AgentOptionsByType[T]): Promise<AgentInstanceByType[T]>;
|
|
82
|
-
|
|
83
|
-
export { type AgentCapabilities, type AgentEvent, type AgentEventHandler, type AgentMetrics, type AgentProcess, 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 ClaudeProviderEvent, 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 CodexProviderEvent, type CodexProviderItem, type CodexSdkAgent, type CodexSdkAgentOptions, type CodexSdkEvent, type CodexSdkItem, type CodexSdkPermissionMode, type CodexSdkRunOptions, type CodexThreadStartedEvent, type CodexTurnCompletedEvent, type CodexTurnFailedEvent, type CompletedRunResult, type Container, type ContainerConfig, ContainerCreateError, ContainerDiffError, ContainerDisposedError, ContainerError, ContainerExecError, ContainerNotRunningError, ContainerStartError, type ContainerStatus, type ContainerType, type ContentPart, type CursorCliAgent, type CursorCliAgentOptions, type CursorCliEvent, type CursorCliPermissionMode, type CursorCliRunOptions, type CursorCliSandboxMode, type CursorSdkAgent, type CursorSdkAgentOptions, type CursorSdkEvent, type CursorSdkMcpHttpAuth, type CursorSdkMcpServerConfig, type CursorSdkRunOptions, type CursorSdkSettingSource, type DockerContainer, type DockerContainerConfig, type E2BConnectConfig, type E2BConnectionConfig, type E2BContainer, type E2BContainerConfig, type E2BCreateConfig, type E2BProviderConfig, 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 NerdctlContainer, type NerdctlContainerConfig, type NerdctlProviderConfig, type NsjailSandbox, type NsjailSandboxConfig, type OpencodeCliAgent, type OpencodeCliAgentOptions, type OpencodeCliRunOptions, type OpencodeEvent, type PermissionDecision, type PermissionHandler, type PermissionRequest, type PiCliAgent, type PiCliAgentOptions, type PiCliRunOptions, type PiCliThinkingLevel, type PiEvent, type PodmanContainer, type PodmanContainerConfig, type PortMapping, type ProcessResult, type ProcessSignal, type ProcessSpawner, ProcessStdinError, type ProviderEvent, type ProviderEventHandler, type ReasoningEvent, type RunError, type RunProcessInfo, type RunRequest, type RunResult, type RunStats, type RunStatus, type RunTiming, type Sandbox, type SandboxConfig, SandboxCreateError, type SandboxStatus, type SandboxType, type SessionEndEvent, type SessionStartEvent, type SpawnOptions, 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, createContainer, createSandbox, eventSchema, spawnProcess };
|
|
81
|
+
export { type AgentCapabilities, type AgentEvent, type AgentEventHandler, type AgentMetrics, type AgentProcess, AgentRunError, type AgentType, AgentValidationError, type AnyCompletedRunResult, type AnyRunRequest, type AnyRunResult, type AttachedDockerContainer, type AttachedPodmanContainer, 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, ClaudeControlRequestError, type ClaudeControlRequestFailure, type ClaudeControlRequestPayload, type ClaudeEvent, type ClaudePermissionMode, type ClaudeProviderEvent, 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 CodexProviderEvent, type CodexProviderItem, type CodexSdkAgent, type CodexSdkAgentOptions, type CodexSdkEvent, type CodexSdkItem, type CodexSdkPermissionMode, type CodexSdkRunOptions, type CodexThreadStartedEvent, type CodexTurnCompletedEvent, type CodexTurnFailedEvent, type CompletedRunResult, type Container, ContainerAttachError, type ContainerConfig, ContainerCreateError, ContainerDiffError, ContainerDisposedError, ContainerError, ContainerExecError, ContainerNotFoundError, ContainerNotRunningError, ContainerRemoveError, ContainerStartError, type ContainerStatus, type ContainerType, type ContentPart, type CursorCliAgent, type CursorCliAgentOptions, type CursorCliEvent, type CursorCliPermissionMode, type CursorCliRunOptions, type CursorCliSandboxMode, type CursorSdkAgent, type CursorSdkAgentOptions, type CursorSdkEvent, type CursorSdkMcpHttpAuth, type CursorSdkMcpServerConfig, type CursorSdkRunOptions, type CursorSdkSettingSource, type DockerAttachConfig, type DockerContainer, type DockerContainerConfig, type E2BConnectConfig, type E2BConnectionConfig, type E2BContainer, type E2BContainerConfig, type E2BCreateConfig, type E2BProviderConfig, 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 MessageDeltaEvent, type MessageEvent, MountValidationError, type NerdctlContainer, type NerdctlContainerConfig, type NerdctlProviderConfig, type NsjailSandbox, type NsjailSandboxConfig, type OpencodeCliAgent, type OpencodeCliAgentOptions, type OpencodeCliRunOptions, type OpencodeEvent, type PermissionDecision, type PermissionHandler, type PermissionRequest, type PiCliAgent, type PiCliAgentOptions, type PiCliRunOptions, type PiCliThinkingLevel, type PiEvent, type PodmanAttachConfig, type PodmanContainer, type PodmanContainerConfig, type PortMapping, type ProcessResult, type ProcessSignal, type ProcessSpawner, ProcessStdinError, type ProviderEvent, type ProviderEventHandler, type Question, type QuestionAnswers, type QuestionHandler, type QuestionOption, type QuestionRequest, type ReasoningDeltaEvent, type ReasoningEvent, type RunError, type RunProcessInfo, type RunRequest, type RunResult, type RunStats, type RunStatus, type RunTiming, type Sandbox, type SandboxConfig, SandboxCreateError, type SandboxStatus, type SandboxType, type SessionEndEvent, type SessionStartEvent, type SpawnOptions, 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, attachContainer, createContainer, createSandbox, eventSchema, spawnProcess };
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e,t}from"./types-B72tDMEZ.mjs";import{a as n,c as r,i,
|
|
1
|
+
import{n as e,t}from"./types-B72tDMEZ.mjs";import{a as n,c as r,d as i,f as a,i as o,l as s,n as c,o as l,p as u,r as d,s as f,t as p,u as m}from"./container-DUoj_mnh.mjs";import{n as h,t as g}from"./sandbox-BemAIoIo.mjs";import{n as _}from"./spawner-CYAQQABs.mjs";import{t as v}from"./errors-BauhTL3l.mjs";import"./core/process/index.mjs";import{t as y}from"./control-requests-DtjV0e4o.mjs";import{f as b,n as x}from"./schemas-CF1pu_vW.mjs";const S=(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`},C=(t,n,r)=>{throw S(r,n)?new e(`Agent type "${t}" requires the optional peer dependency "${n}". Install it to use this adapter.`):r};async function w(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 C(`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 C(`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 C(`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,y as ClaudeControlRequestError,d as ContainerAttachError,o as ContainerCreateError,n as ContainerDiffError,l as ContainerDisposedError,f as ContainerError,r as ContainerExecError,s as ContainerNotFoundError,m as ContainerNotRunningError,i as ContainerRemoveError,a as ContainerStartError,u as MountValidationError,v as ProcessStdinError,g as SandboxCreateError,b as agentCapabilitiesSchema,p as attachContainer,w as createAgent,c as createContainer,h as createSandbox,x as eventSchema,_ as spawnProcess};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{t as e}from"./util-CCXryPDO.mjs";import{n as t}from"./env-Cb8MIvH7.mjs";import{n}from"./errors-BauhTL3l.mjs";import{t as r}from"./shell-DvWFuFKb.mjs";import{t as i}from"./spawner-CYAQQABs.mjs";import{n as a,t as o}from"./diff-CMWH9a0d.mjs";import{a as s,c,d as l,f as u,i as d,l as f,o as p,p as m,r as h,u as g}from"./container-DUoj_mnh.mjs";import{execFile as _}from"node:child_process";import{isAbsolute as v,join as y,posix as b,resolve as x}from"node:path";import{promisify as S}from"node:util";import{existsSync as C,mkdtempSync as w,rmSync as T,writeFileSync as E}from"node:fs";import{tmpdir as D}from"node:os";import{mkdtemp as O,rm as k,writeFile as A}from"node:fs/promises";import{randomBytes as j}from"node:crypto";const M=/[\s=\0]/,N=/[\r\n\0]/,P=65536,F=`\\t\\n\\v\\f\\r \\u0085\\u00a0\\u1680\\u2000-\\u200a\\u2028\\u2029\\u202f\\u205f\\u3000`,I=RegExp(`^[${F}]|[${F}]$`),L=(e,t)=>{for(let[n,r]of e){if(n===``||n.startsWith(`#`)||M.test(n))return`The environment variable name ${JSON.stringify(n)} cannot be passed to the container engine.`;if(N.test(r))return`The value of the environment variable ${n} contains a line break or a NUL character, which the container engine cannot receive.`;let e=`${n}=${r}`,i=Buffer.byteLength(`${e}\n`);if(i>P){let e=Buffer.byteLength(r);return`The value of the environment variable ${n} is ${e} bytes, more than the ${e-(i-P)} bytes the container engine can receive for it.`}if(t===`nerdctl`&&I.test(e))return`The environment variable ${n} has whitespace at the start of its name or the end of its value, which nerdctl removes.`}},R=(e,t,n)=>{let r=Object.entries(e??{});if(r.length===0)return;let i=L(r,t);if(i!==void 0)throw n(i);let a=w(y(D(),`cw-oci-env-`)),o=y(a,`env`);try{E(o,r.map(([e,t])=>`${e}=${t}\n`).join(``),{mode:384})}catch(e){throw T(a,{recursive:!0,force:!0}),e}return{path:o,remove:()=>T(a,{recursive:!0,force:!0})}},z=(e,t)=>{let n=b.relative(e,t);return n===``||!n.startsWith(`..`)&&!b.isAbsolute(n)},B=(e,t)=>{if(!e||e.length===0)return;let n=b.normalize(t),r;for(let t of e){if(!v(t.source))continue;let e=b.normalize(t.target);z(e,n)&&(!r||e.length>b.normalize(r.target).length)&&(r=t)}if(!r)return;let i=b.relative(b.normalize(r.target),n);return i===``?r.source:b.join(r.source,...i.split(`/`))},V=(e,t)=>{let n=v(e.source)?e.source:x(t.cwd,e.source);if(!C(n))throw new m(`Mount source does not exist: ${n}`);return{...e,source:n}},H=S(_),U=()=>`cw-${j(6).toString(`hex`)}`,W=(e,t)=>e.baseArgs?[...e.baseArgs,...t]:t,G=e=>{if(e.env)return{...t(),...e.env}},K=async(e,t,n)=>{let r=await H(e.binary,W(e,t),{encoding:`utf8`,env:G(e),timeout:n?.timeoutMs,signal:n?.signal,maxBuffer:52428800});return{stdout:r.stdout,stderr:r.stderr}},q=e=>e===`running`?`running`:e===`created`?`created`:`stopped`,J=async(t,n)=>{let r=n.tag??`cw-build-${j(4).toString(`hex`)}`,i=[`build`,`-t`,r];if(n.args)for(let[e,t]of Object.entries(n.args))i.push(`--build-arg`,`${e}=${t}`);`dockerfile`in n&&n.dockerfile&&(i.push(`-f`,n.dockerfile),i.push(n.context??`.`));let a;if(`content`in n&&n.content){a=await O(y(D(),`cw-oci-build-`));let e=y(a,`Dockerfile`);await A(e,n.content,{encoding:`utf8`,mode:384}),i.push(`-f`,e),i.push(n.context??a)}try{await K(t,i)}catch(t){throw new d(`Image build failed: ${e(t)}`)}finally{a&&await k(a,{recursive:!0,force:!0}).catch(()=>{})}return r},Y=async(e,t,n)=>{let r=await Promise.all(n.map(async n=>{try{let{container:r,protocol:i=`tcp`}=n,{stdout:a}=await K(e,[`port`,t,`${r}/${i}`]),o=/:(\d+)$/m.exec(a.trim());if(o?.[1])return[r,Number(o[1])]}catch{}})),i=/* @__PURE__ */ new Map;for(let e of r)e&&i.set(e[0],e[1]);return i},X=(e,t,n)=>({spawn:(r,a,o={})=>{let s=[`exec`,`-i`];o.cwd&&s.push(`-w`,o.cwd);let l=R(o.env,e,e=>new c(e));l&&s.push(`--env-file`,l.path),s.push(t,r,...a);let u;try{u=i.spawn(n.binary,W(n,s),{env:G(n),stdio:o.stdio})}catch(e){throw l?.remove(),e}if(l===void 0)return u;let d=u.wait().finally(l.remove);return{...u,wait:()=>d}}}),Z=async(e,t,n)=>{try{await K(e,[`stop`,`-t`,`0`,t])}catch{}let r=n.anonymousVolumes===`remove`?[`-v`]:[];await K(e,[`rm`,`-f`,...r,t])},Q=async(t,n,r)=>{let{commandContext:i,builtImage:a,containerName:o,workdir:s,user:c,network:l,platform:u,env:f,ports:p,mounts:m,mountCwd:h,extraArgs:g,image:_}=n,v=o??U(),y=m?.map(e=>V(e,{cwd:h??process.cwd()})),b=[`create`,`--name`,v];if(c&&b.push(`--user`,c),l&&b.push(`--network`,l),u&&b.push(`--platform`,u),p)for(let e of p){let{host:t,container:n,protocol:r=`tcp`}=e;b.push(`-p`,`${t??``}:${n}/${r}`)}if(y)for(let e of y){let{readonly:t,source:n,target:r}=e,i=t?`ro`:`rw`;b.push(`-v`,`${n}:${r}:${i}`)}g&&b.push(...g);let x=R(f,t,e=>new d(e));x&&b.push(`--env-file`,x.path),b.push(_,`sleep`,`infinity`);let S;try{let{stdout:e}=await K(i,b);S=e.trim()}catch(t){throw new d(`Container create failed: ${e(t)}`)}finally{x?.remove()}return $(t,{commandContext:i,containerId:S,containerName:v,status:`created`,workdir:s,user:c,ports:p,normalizedMounts:y,removeOnDispose:async()=>{try{await Z(i,S,{anonymousVolumes:`keep`})}catch{}a&&await K(i,[`rmi`,_]).catch(()=>{})}},r)},$=(t,l,d)=>{let{commandContext:f,containerId:m,containerName:h,workdir:_,user:v,ports:y,normalizedMounts:x,removeOnDispose:S}=l,C=l.status,w=/* @__PURE__ */ new Map,T=()=>{if(C===`disposed`)throw new p},E=()=>{if(T(),C!==`running`)throw new g},D=X(t,m,f),O=a({owner:{},workdir:_,materialize:async(t,n)=>{T();let i=B(x,t);if(i)await o(i,n);else{E();try{await K(f,[`exec`,m,`sh`,`-c`,`test -d ${r(t)}`])}catch{throw new s(`Target path is not a directory: ${t}`)}try{await K(f,[`cp`,`${m}:${t}/.`,n])}catch(n){throw new s(`Failed to materialize container path ${t}: ${e(n)}`)}}}}),k={get type(){return t},get id(){return m},get name(){return h},get config(){return d},get status(){return C},get workdir(){return _},get spawner(){return D},async start(){if(T(),C!==`running`){try{await K(f,[`start`,m])}catch(t){throw new u(`Container start failed: ${e(t)}`)}try{await K(f,[`exec`,m,`mkdir`,`-p`,_])}catch(t){try{await K(f,[`stop`,`-t`,`0`,m]),C=`stopped`}catch{try{let{stdout:e}=await K(f,[`inspect`,`--format`,`{{.State.Status}}`,m]);C=e.trim()===`running`?`running`:`stopped`}catch{C=`disposed`}}throw new u(`Container start failed: ${e(t)}`)}C=`running`,y?.length&&(w=await Y(f,m,y))}},async stop(){if(T(),C===`running`){try{await K(f,[`stop`,`-t`,`2`,m])}catch{try{let{stdout:e}=await K(f,[`inspect`,`--format`,`{{.State.Status}}`,m]);if(e.trim()===`running`)return}catch{C=`disposed`;return}}C=`stopped`}},async dispose(){C!==`disposed`&&(await S?.(),await O.disposeSnapshots().catch(()=>{}),C=`disposed`)},async exec(e,r,i={}){E();let a=[`exec`];i.cwd&&a.push(`-w`,i.cwd);let o=R(i.env,t,e=>new c(e));o&&a.push(`--env-file`,o.path),a.push(m,e,...r);try{let{stdout:e,stderr:t}=await K(f,a,{timeoutMs:i.timeoutMs,signal:i.signal});return{exitCode:0,stdout:e,stderr:t}}catch(e){if(n(e))return{exitCode:typeof e.code==`number`?e.code:-1,stdout:String(e.stdout??``),stderr:String(e.stderr??``)};throw e}finally{o?.remove()}},async copyTo(e,t){E(),await K(f,[`cp`,e,`${m}:${t}`])},async copyFrom(e,t){E(),await K(f,[`cp`,`${m}:${e}`,t])},async writeFile(t,n){E();let a=b.isAbsolute(t)?t:b.resolve(_,t),o=b.dirname(a),s=typeof n==`string`?Buffer.from(n,`utf8`):n,l=[`exec`,`-i`];v&&l.push(`--user`,v),l.push(m,`sh`,`-c`,`mkdir -p ${r(o)} && cat > ${r(a)}`);let u=i.spawn(f.binary,W(f,l),{env:G(f),stdio:[`pipe`,`ignore`,`ignore`]}),d;try{u.stdin?.write?.(s),u.stdin?.end(),d=await u.wait()}catch(t){throw u.kill(),u.wait().catch(()=>{}),new c(`writeFile failed for ${a}: ${e(t)}`)}if(d.exitCode!==0)throw new c(`writeFile failed for ${a} (exit ${d.exitCode})`)},async readFile(e){E();let t=b.isAbsolute(e)?e:b.resolve(_,e),{stdout:n}=await K(f,[`exec`,m,`cat`,t]);return n},async fileExists(e){E();let t=b.isAbsolute(e)?e:b.resolve(_,e);try{return await K(f,[`exec`,m,`test`,`-e`,t]),!0}catch{return!1}},async mkdir(e){E();let t=b.isAbsolute(e)?e:b.resolve(_,e);await K(f,[`exec`,m,`mkdir`,`-p`,t])},async execShell(e,t={}){return k.exec(`sh`,[`-c`,e],t)},async logs(e={}){T();let t=[`logs`];e.tail!==void 0&&t.push(`--tail`,String(e.tail)),t.push(m);let{stdout:n}=await K(f,t);return n},async syncStatus(){T();try{let{stdout:e}=await K(f,[`inspect`,`--format`,`{{.State.Status}}`,m]);C=q(e.trim())}catch{C=`disposed`}return C},async snapshotWorkdir(e={}){return O.snapshotWorkdir(e)},async diffWorkdir(e){return O.diffWorkdir(e)},async releaseWorkdirSnapshot(e){return O.releaseWorkdirSnapshot(e)},getMappedPort(e){return w.get(e)},[Symbol.asyncDispose](){return k.dispose()}};return k},ee=async(e,t)=>{let{stdout:n}=await K(e,[`ps`,`--all`,`--no-trunc`,`--format`,`{{.ID}} {{.Names}}`]);return n.split(`
|
|
2
|
+
`).some(e=>{let[n=``,r=``]=e.split(` `);return n.startsWith(t)||r.split(`,`).includes(t)})},te=async(e,t)=>{let n;try{({stdout:n}=await K(e,[`inspect`,`--type`,`container`,`--format`,`{{.Id}} {{.Name}} {{.State.Status}}`,`--`,t]))}catch(n){throw await ee(e,t)?n:new f(`Container not found: ${t}`)}let[r,i,a]=n.trim().split(` `);if(!r||!i||!a)throw Error(`Unexpected inspect output: ${n.trim()}`);return{containerId:r,containerName:i.replace(/^\//,``),status:q(a)}},ne=async(t,n)=>{try{let r=await te(t,n.containerId),i=$(n.type,{commandContext:t,...r,workdir:n.workdir},n);return i.status===`running`&&await i.mkdir(n.workdir),Object.assign(i,{async remove(){try{await Z(t,r.containerId,{anonymousVolumes:`remove`})}catch(t){throw new l(`Container remove failed: ${e(t)}`)}await i.dispose()}})}catch(t){throw t instanceof f?t:new h(`Container attach failed: ${e(t)}`)}},re=async(e,t)=>{if(t.image)return t.image;if(t.build)return J(e,t.build);throw new d(`Either image or build must be provided.`)};export{Q as n,re as r,ne as t};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{c as e,d as t,l as n}from"./classify-error-DJq_uoy2.mjs";import{a as r,i}from"./permission-updates-lGl8T2lW.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=>{switch(e.subtype){case`init`:{let t=[`[init]`];if(e.tools&&t.push(`tools: ${e.tools.length}`),e.mcp_servers){let n=e.mcp_servers.filter(e=>e.status===`connected`).length;t.push(`mcp: ${n}/${e.mcp_servers.length} connected`)}return t.join(` `)}case`hook_response`:case`hook_started`:case`hook_finished`:case`hook_failed`:case`hook_skipped`:{let t=[`[${e.subtype}]`];return e.hook_name&&(t.push(e.hook_name),e.exit_code!==void 0&&t.push(`exit: ${e.exit_code}`)),t.join(` `)}case`session_state_changed`:case`task_started`:return;default:throw Error(`Unhandled Claude system event subtype: ${e.subtype}`)}},u=(n,r)=>{let i=l(n);return i===void 0?{events:[]}:{events:[e(r.runId,`message`,{sessionId:r.sessionId,model:n.model??null,role:`system`,content:[t(i)],text:i})]}},d=(n,r,i)=>{let a=[],o=[];for(let s of n.message.content)switch(s.type){case`text`:{let o=i?.takeReservedEventId(`message`,n.message.id);a.push(e(r.runId,`message`,{...o===void 0?{}:{id:o},sessionId:r.sessionId,model:n.message.model??null,role:`assistant`,content:[t(s.text)],text:s.text}));break}case`thinking`:{let o=i?.takeReservedEventId(`reasoning`,n.message.id);a.push(e(r.runId,`reasoning`,{...o===void 0?{}:{id:o},sessionId:r.sessionId,model:n.message.model??null,content:[t(s.thinking)],text:s.thinking}));break}case`tool_use`:o.push({toolCallId:s.id,toolName:s.name,input:s.input}),a.push(e(r.runId,`tool-call`,{sessionId:r.sessionId,model:n.message.model??null,toolCallId:s.id,toolName:s.name,input:s.input}))}return{events:a,toolCalls:o}},f=(n,r)=>{let i=[];for(let a of n.message.content)switch(a.type){case`text`:i.push(e(r.runId,`message`,{sessionId:r.sessionId,model:null,role:`user`,content:[t(a.text)],text:a.text}));break;case`tool_result`:{let t=r.toolCalls.get(a.tool_use_id),n=s(a);i.push(e(r.runId,`tool-result`,{sessionId:r.sessionId,toolCallId:a.tool_use_id,toolName:t?.toolName,input:t?.input,output:n,isError:a.is_error,error:a.is_error?n:void 0}));break}}return{events:i}},p=(e,t,n)=>{let a={stats:(n??new i(t)).addResult(e)};typeof e.result==`string`&&(a.output={...a.output,text:e.result});let o=!e.is_error&&e.subtype===`success`,s=r(e.structured_output,{schemaRequested:t.schemaRequested,toolCalls:t.toolCalls,allowToolCallFallback:!1},{isSuccess:o},`Structured output was requested but Claude did not return structured_output.`);return s.value!==void 0&&(a.output={...a.output,value:s.value}),s.error&&(a.status=`failed`,a.error=s.error),e.is_error||e.subtype!==`success`?(a.status=`failed`,a.error={kind:`provider`,message:c(e)}):a.error||=(a.status=`completed`,void 0),{events:[],state:a}},m=(n,r)=>{let i=`rate limited: ${n.rate_limit_info.status}`;return{events:[e(r.runId,`message`,{sessionId:r.sessionId,model:null,role:`system`,content:[t(i)],text:i})]}},h=(e,t,n={})=>{switch(e.type){case`system`:return u(e,t);case`assistant`:return d(e,t,n.textStream);case`user`:return f(e,t);case`result`:return p(e,t,n.statsAccumulator);case`rate_limit_event`:return m(e,t);default:return{events:[]}}},g=a.enum([`init`,`hook_response`,`hook_started`,`hook_finished`,`hook_failed`,`hook_skipped`,`session_state_changed`,`task_started`]),_=a.enum([`idle`,`running`,`requires_action`]),v=a.object({name:a.string(),status:a.string()}),y=a.object({type:a.literal(`system`),session_id:a.string(),subtype:g,uuid:a.string(),tools:a.array(a.string()).optional(),mcp_servers:a.array(v.extend({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(),state:_.optional(),task_id:a.string().optional(),tool_use_id:a.string().optional()}),b=a.looseObject({type:a.literal(`system`),subtype:a.string().refine(e=>!g.safeParse(e).success)}),x=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()})}),S=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()}),C=a.object({type:a.literal(`result`),session_id:a.string(),uuid:a.string(),subtype:a.enum([`success`,`error_max_turns`,`error_during_execution`,`error_max_budget_usd`,`error_max_structured_output_retries`]),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(),modelUsage:a.record(a.string(),a.object({inputTokens:a.number(),outputTokens:a.number(),cacheReadInputTokens:a.number(),cacheCreationInputTokens:a.number()})).optional()}),w=a.discriminatedUnion(`type`,[C.pick({type:!0}).extend({user_message_uuids:a.array(a.string()).optional()}),a.object({type:a.literal(`system`),subtype:a.literal(`session_state_changed`),state:_})]),T=a.looseObject({type:a.literal(`command_lifecycle`)}),E=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()})}),D=a.discriminatedUnion(`type`,[y,x,S,C,E]),O=a.discriminatedUnion(`type`,[y.extend({subtype:a.string(),uuid:a.string().optional(),mcp_servers:a.array(v.loose()).optional()}).loose(),x.extend({uuid:a.string().optional()}),S.extend({uuid:a.string().optional()}),C.extend({uuid:a.string().optional(),subtype:a.string()}),E]),k=a.object({type:a.literal(`stream_event`),session_id:a.string(),event:a.looseObject({type:a.string()})}),A=a.object({message:a.object({id:a.string()})}),j=a.object({index:a.number(),delta:a.looseObject({type:a.string()})}),M=a.object({text:a.string()}),N=a.object({thinking:a.string()}),P=a.object({subtype:a.literal(`can_use_tool`),tool_name:a.string(),input:a.record(a.string(),a.unknown()),tool_use_id:a.string(),decision_reason:a.string().optional(),blocked_path:a.string().optional(),title:a.string().optional(),description:a.string().optional()}),F=a.discriminatedUnion(`type`,[a.object({type:a.literal(`control_request`),request_id:a.string(),request:a.looseObject({subtype:a.string()})}),a.looseObject({type:a.literal(`control_response`)}),a.looseObject({type:a.literal(`control_cancel_request`),request_id:a.string()})]),I=a.object({type:a.literal(`control_response`),response:a.discriminatedUnion(`subtype`,[a.object({subtype:a.literal(`success`),request_id:a.string(),response:a.unknown().optional()}),a.object({subtype:a.literal(`error`),request_id:a.string(),error:a.string()})])}),L=n(D);export{F as a,O as c,M as d,N as f,h,j as i,w as l,o as m,P as n,I as o,b as p,T as r,A as s,L as t,k as u};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{i as e}from"./util-
|
|
1
|
+
import{i as e}from"./util-CCXryPDO.mjs";const t=`SendUserMessage`,n=e=>e?.includes(t)?[...e]:[...e??[],t],r=e=>{let t;for(let[,n]of e)n.toolName===`StructuredOutput`&&n.input!==void 0&&(t=n.input);return t},i=(e,t,n,i)=>{if(e!=null)return{value:e};if(!t.schemaRequested)return{};if(t.allowToolCallFallback??!0){let e=r(t.toolCalls);if(e!==void 0)return{value:e}}return n.isSuccess?{error:{kind:`parse`,message:i}}:{}},a=e=>{let t=Object.values(e??{});if(t.length!==0)return{inputTokens:t.reduce((e,t)=>e+t.inputTokens,0),cacheCreationInputTokens:t.reduce((e,t)=>e+t.cacheCreationInputTokens,0),cacheReadInputTokens:t.reduce((e,t)=>e+t.cacheReadInputTokens,0),outputTokens:t.reduce((e,t)=>e+t.outputTokens,0)}},o=(e,t)=>e>=t?e-t:e,s=(e,t)=>({inputTokens:o(e.inputTokens,t?.inputTokens??0),cacheCreationInputTokens:o(e.cacheCreationInputTokens,t?.cacheCreationInputTokens??0),cacheReadInputTokens:o(e.cacheReadInputTokens,t?.cacheReadInputTokens??0),outputTokens:o(e.outputTokens,t?.outputTokens??0)});var c=class{canUseModelUsage;restoredTotals;latestResult;durationMs=0;turns=0;inputTokens;cacheCreationInputTokens;cacheReadInputTokens;outputTokens;constructor({requestedSessionId:e,recordedSessionTotals:t,mayResumeUntrackedSession:n=!1}){let r=!n&&e===void 0,i=!n&&e!==void 0&&t?.sessionId===e;this.restoredTotals=i?t:void 0,this.canUseModelUsage=r||i}get sessionTotals(){if(!this.latestResult)return;let e={sessionId:this.latestResult.session_id,apiDurationMs:this.latestResult.duration_api_ms,costUsd:this.latestResult.total_cost_usd,modelUsage:this.latestResult.modelUsage},t=this.restoredTotals;return t!==void 0&&(e.costUsd<t.costUsd||e.apiDurationMs<t.apiDurationMs)?t:e}addResult(t){this.latestResult=t,this.durationMs+=t.duration_ms,this.turns+=t.num_turns,this.inputTokens=e(this.inputTokens,t.usage?.input_tokens),this.cacheCreationInputTokens=e(this.cacheCreationInputTokens,t.usage?.cache_creation_input_tokens),this.cacheReadInputTokens=e(this.cacheReadInputTokens,t.usage?.cache_read_input_tokens),this.outputTokens=e(this.outputTokens,t.usage?.output_tokens);let n={inputTokens:this.inputTokens,cacheCreationInputTokens:this.cacheCreationInputTokens,cacheReadInputTokens:this.cacheReadInputTokens,outputTokens:this.outputTokens},r=this.canUseModelUsage?a(t.modelUsage):void 0,i=a(this.restoredTotals?.modelUsage),c=r?s(r,i):n;return{durationMs:this.durationMs,apiDurationMs:o(t.duration_api_ms,this.restoredTotals?.apiDurationMs??0),turns:this.turns,...c,totalTokens:e(c.inputTokens,c.cacheCreationInputTokens,c.cacheReadInputTokens,c.outputTokens),costUsd:o(t.total_cost_usd,this.restoredTotals?.costUsd??0)}}};const l=e=>{let t={...e};return delete t.$schema,t},u=[`CLAUDECODE`,`CLAUDE_CODE_CHILD_SESSION`],d=e=>{for(let t of u)delete e[t]},f=e=>{if(e.permissionMode!==void 0)return[{type:`setMode`,mode:e.permissionMode,destination:`session`}]};export{i as a,c as i,d as n,n as o,l as r,f as t};
|
package/dist/sandbox/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as FirejailSandbox, c as NsjailSandboxConfig, d as SandboxStatus, f as SandboxType, i as BubblewrapSandboxConfig, l as Sandbox, n as createSandbox, o as FirejailSandboxConfig, r as BubblewrapSandbox, s as NsjailSandbox, t as SandboxCreateError, u as SandboxConfig } from "../index-
|
|
1
|
+
import { a as FirejailSandbox, c as NsjailSandboxConfig, d as SandboxStatus, f as SandboxType, i as BubblewrapSandboxConfig, l as Sandbox, n as createSandbox, o as FirejailSandboxConfig, r as BubblewrapSandbox, s as NsjailSandbox, t as SandboxCreateError, u as SandboxConfig } from "../index-BA-SATzW.mjs";
|
|
2
2
|
export { type BubblewrapSandbox, type BubblewrapSandboxConfig, type FirejailSandbox, type FirejailSandboxConfig, type NsjailSandbox, type NsjailSandboxConfig, type Sandbox, type SandboxConfig, SandboxCreateError, type SandboxStatus, type SandboxType, createSandbox };
|
package/dist/sandbox/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export{t as SandboxCreateError,n as createSandbox}from"../sandbox-BemAIoIo.mjs";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{t as
|
|
1
|
+
import{n as e,r as t,t as n}from"./env-Cb8MIvH7.mjs";import{t as r}from"./spawner-CYAQQABs.mjs";import{t as i}from"./util-CCXryPDO.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 v}from"node:fs";import{tmpdir as y}from"node:os";const b=e=>{let t=e.type.charAt(0).toUpperCase()+e.type.slice(1),n=`created`,r=/* @__PURE__ */ 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},x=`bwrap`,S=[`/tmp`],C=f(o),w=(e,t)=>e.binds?.some(e=>e.target===t)??!1,T=(e,t)=>{let n=u.relative(e,t);return n===``||!n.startsWith(`..`)&&!u.isAbsolute(n)},E=(e,t)=>e.target.length-t.target.length,ee=e=>{let t=w(e,e.workdir)?[...e.binds??[]]:[{source:e.workdir,target:e.workdir},...e.binds??[]],n=e.tmpfs??S,r=t.filter(e=>!n.some(t=>T(t,e.target))).toSorted(E),i=t.filter(e=>n.some(t=>T(t,e.target))).toSorted(E);return[...r,...i]},te=e=>{let t=[`--ro-bind`,`/`,`/`];for(let n of ee(e))t.push(n.readonly?`--ro-bind`:`--bind`,n.source,n.target);return t},ne=(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},re=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},ie=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??S)t.push(`--tmpfs`,n);t.push(...te(e).slice(3));for(let n of e.remountReadonly??[])t.push(`--remount-ro`,n);return t},ae=(e,t,n,r={})=>[...re(e),...ie(e),...ne(e,r),`--chdir`,r.cwd??e.workdir,...e.args??[],`--`,t,...n],oe=async e=>{try{await C(e,[`--version`],{env:n(),encoding:`utf8`})}catch(e){throw Error(`Bubblewrap start failed: ${i(e)}`)}},D=(e,t,r,i)=>({spawn(a,o,s={}){return t(),r(i.spawn(e.binary??x,ae(e,a,o,s),{env:n(),stdio:s.stdio}))}}),O=async(e,t=r)=>b({type:`bubblewrap`,config:e,onValidate:()=>oe(e.binary??x),createSpawner:(n,r)=>D(e,n,r,t)}),k=e=>new Set((e??[]).flatMap(e=>[e,e.toUpperCase(),e.toLowerCase()])),A=(e,t)=>{let n=k(t);return n.size===0?e:Object.fromEntries(Object.entries(e).filter(([e])=>!n.has(e)))},j=e=>{try{return p(e,m.X_OK),!0}catch{return!1}},M=(e,t)=>c(e)?e:d(t,e),N=(e,n,r)=>{if(c(e)||e.includes(`/`))return e;let i=n[t(n)];if(!i)return e;for(let t of i.split(s)){let n=l(M(t,r),e);if(j(n))return n}return e},P=(n,r)=>{if((r??[]).some(e=>e.toLowerCase()===`path`))return;let i=t(n);if(i in n)return;let a=e(),o=a[t(a)];o&&Object.assign(n,{[i]:o})},F=[`/run/wrappers/bin`,`/usr/local/bin`,`/usr/bin`,`/bin`],I=f(o),L=e=>e.binary??`firejail`,R=()=>{let n=e();return n[t(n)]},z=e=>{if(e.clearEnv===!1)return n({extraPaths:F});let r=n({propagateEnv:!1,extraPaths:F}),i=R();return i&&(r[t(r)]=[...F,i].filter(Boolean).join(s)),r},B=(e,t,n)=>{let r=A({...n,...e.setEnv,...t.env},e.unsetEnv);return P(r,e.unsetEnv),r},V=(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},H=(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(...V(e,r,i)),e.args?.length&&a.push(...e.args),a.push(`--`,t,...n),a},U=async e=>{try{await I(e,[`--version`],{env:n({extraPaths:F}),encoding:`utf8`})}catch(e){throw Error(`Firejail start failed: ${i(e)}`)}},W=(e,t,n,r)=>({spawn(i,o,s={}){t();let c=s.cwd??e.workdir,l=z(e),u=`exec ${[N(i,B(e,s,l),c),...o].map(a).join(` `)}`;return n(r.spawn(L(e),H(e,`sh`,[`-c`,u],s,l),{cwd:c,env:l,stdio:s.stdio}))}}),G=async(e,t=r)=>b({type:`firejail`,config:e,onValidate:()=>U(L(e)),createSpawner:(n,r)=>W(e,n,r,t)}),K=`nsjail`,se=[`/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??[...se],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 r=A(e.clearEnv===!1?n():n({propagateEnv:!1}),e.unsetEnv);return Object.assign(r,e.setEnv,t.env),P(r,e.unsetEnv),r},Z=(e,t,n)=>[`${e} {`,` inside_id: ${q(String(t))}`,` outside_id: ${q(String(n))}`,` count: 1`,`}`].join(`
|
|
2
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
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
|
|
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 e=>{try{await ce(e,[`--help`],{env:n(),encoding:`utf8`})}catch(e){throw Error(`Nsjail start failed: ${i(e)}`)}},ve=(e,t,r,i,a)=>({spawn(o,s,c={}){r();let u=t(),d=X(e,c),f=c.cwd??e.workdir,p=N(o,d,f),m=l(u.configDir,`spawn-${Date.now()}-${Math.random().toString(16).slice(2)}.cfg`);v(m,he(e,c,d),{encoding:`utf8`,mode:384});try{let t=i(a.spawn(e.binary??K,ge(e,m,p,s),{env:n(),stdio:c.stdio})),r=t.wait().finally(()=>{_(m,{force:!0})});return{...t,wait:()=>r}}catch(e){throw _(m,{force:!0}),e}}}),ye=async(e,t=r)=>{let n,i=()=>{if(!n)throw Error(`Nsjail sandbox has not been started.`);return n};return b({type:`nsjail`,config:e,async onValidate(){await _e(e.binary??K),n??={configDir:h(l(y(),`cw-nsjail-`))}},onDispose(){n&&_(n.configDir,{recursive:!0,force:!0})},createSpawner:(n,r)=>ve(e,i,n,r,t)})};var $=class extends Error{constructor(e){super(e),this.name=`SandboxCreateError`}};async function be(e){switch(e.type){case`bubblewrap`:return O(e);case`firejail`:return G(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
|
|
2
|
-
export { type AgentCapabilities, type AgentEvent, type ContentPart, type ImageContentPart, type JsonSchema, type McpServerConfig, type MessageEvent, type ReasoningEvent, type SessionEndEvent, type SessionStartEvent, type StderrEvent, type TextContentPart, type ToolCallEvent, type ToolResultEvent, agentCapabilitiesSchema, baseEventSchema, contentPartSchema, eventSchema, imageContentPartSchema, messageEventSchema, reasoningEventSchema, sessionEndEventSchema, sessionStartEventSchema, stderrEventSchema, textContentPartSchema, toolCallEventSchema, toolResultEventSchema };
|
|
1
|
+
import { A as imageContentPartSchema, C as ContentPart, D as TextContentPart, E as McpServerConfig, O as agentCapabilitiesSchema, S as AgentCapabilities, T as JsonSchema, _ as sessionEndEventSchema, a as ReasoningEvent, b as toolCallEventSchema, c as StderrEvent, d as baseEventSchema, f as eventSchema, g as reasoningEventSchema, h as reasoningDeltaEventSchema, i as ReasoningDeltaEvent, j as textContentPartSchema, k as contentPartSchema, l as ToolCallEvent, m as messageEventSchema, n as MessageDeltaEvent, o as SessionEndEvent, p as messageDeltaEventSchema, r as MessageEvent, s as SessionStartEvent, t as AgentEvent, u as ToolResultEvent, v as sessionStartEventSchema, w as ImageContentPart, x as toolResultEventSchema, y as stderrEventSchema } from "../events-DoTNE9UF.mjs";
|
|
2
|
+
export { type AgentCapabilities, type AgentEvent, type ContentPart, type ImageContentPart, type JsonSchema, type McpServerConfig, type MessageDeltaEvent, type MessageEvent, type ReasoningDeltaEvent, type ReasoningEvent, type SessionEndEvent, type SessionStartEvent, type StderrEvent, type TextContentPart, type ToolCallEvent, type ToolResultEvent, agentCapabilitiesSchema, baseEventSchema, contentPartSchema, eventSchema, imageContentPartSchema, messageDeltaEventSchema, messageEventSchema, reasoningDeltaEventSchema, reasoningEventSchema, sessionEndEventSchema, sessionStartEventSchema, stderrEventSchema, textContentPartSchema, toolCallEventSchema, toolResultEventSchema };
|
package/dist/schemas/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export{f as agentCapabilitiesSchema,t as baseEventSchema,p as contentPartSchema,n as eventSchema,m as imageContentPartSchema,r as messageDeltaEventSchema,i as messageEventSchema,a as reasoningDeltaEventSchema,o as reasoningEventSchema,s as sessionEndEventSchema,c as sessionStartEventSchema,l as stderrEventSchema,h as textContentPartSchema,u as toolCallEventSchema,d as toolResultEventSchema}from"../schemas-CF1pu_vW.mjs";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{z as e}from"zod/v4";const t=e.object({type:e.literal(`text`),text:e.string()}),n=e.object({type:e.literal(`image`),path:e.string(),mediaType:e.string().optional()}),r=e.discriminatedUnion(`type`,[t,n]),i=e.object({structuredOutput:e.boolean(),sessionResume:e.boolean(),imageInput:e.boolean(),mcp:e.boolean(),eventStreaming:e.boolean(),sessionFork:e.boolean().optional(),permissionRequests:e.boolean().optional(),textStreaming:e.boolean().optional(),midRunInput:e.boolean().optional(),questionRequests:e.boolean().optional()}),a=e.object({id:e.string(),runId:e.string(),timestamp:e.date()}),o=a.extend({type:e.literal(`session-start`),requestedSessionId:e.string().optional(),sessionId:e.string().optional(),resumed:e.boolean()}),s=a.extend({type:e.literal(`message`),sessionId:e.string().optional(),model:e.string().nullable(),role:e.enum([`system`,`user`,`assistant`]),content:e.array(r),text:e.string().optional()}),c=a.extend({type:e.literal(`reasoning`),sessionId:e.string().optional(),model:e.string().nullable(),content:e.array(r),text:e.string().optional()}),l=a.extend({type:e.literal(`message-delta`),sessionId:e.string().optional(),messageId:e.string(),text:e.string()}),u=a.extend({type:e.literal(`reasoning-delta`),sessionId:e.string().optional(),reasoningId:e.string(),text:e.string()}),d=a.extend({type:e.literal(`tool-call`),sessionId:e.string().optional(),model:e.string().nullable(),toolCallId:e.string(),toolName:e.string(),input:e.unknown().optional()}),f=a.extend({type:e.literal(`tool-result`),sessionId:e.string().optional(),toolCallId:e.string(),toolName:e.string().optional(),input:e.unknown().optional(),output:e.unknown(),isError:e.boolean().optional(),error:e.string().optional()}),p=a.extend({type:e.literal(`stderr`),sessionId:e.string().optional(),text:e.string()}),m=a.extend({type:e.literal(`session-end`),sessionId:e.string().optional(),status:e.enum([`completed`,`failed`,`cancelled`]),error:e.string().optional()}),h=e.discriminatedUnion(`type`,[o,s,c,l,u,d,f,p,m]);export{u as a,o as c,f as d,i as f,t as h,s as i,p as l,n as m,h as n,c as o,r as p,l as r,m as s,a as t,d as u};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as e}from"./errors-BauhTL3l.mjs";import{spawn as t}from"node:child_process";const n=e=>({async*[Symbol.asyncIterator](){for await(let t of e)if(t instanceof Buffer)yield new Uint8Array(t);else if(typeof t==`string`)yield new TextEncoder().encode(t);else if(t instanceof Uint8Array)yield t;else throw Error(`Unsupported stdout/stderr chunk type: ${typeof t}`)}}),r=(r,i,a={})=>{let o=t(r,i,{cwd:a.cwd,env:a.env,stdio:a.stdio,detached:!0}),s,c=t=>{s??=new e(t)};o.stdin?.on(`error`,c);let l=new Promise((e,t)=>{let n=(n,i)=>{o.removeListener(`error`,r),s?t(s):e({exitCode:n,signal:i})},r=e=>{o.removeListener(`close`,n),t(e)};o.once(`error`,r),o.once(`close`,n)}),u=o.stdin;return{stdout:o.stdout?n(o.stdout):null,stderr:o.stderr?n(o.stderr):null,stdin:u?{write:e=>{let t=new Promise((t,n)=>{u.write(e,e=>{e?n(e):t()})});return t.catch(c),t},end:()=>{let e=new Promise((e,t)=>{u.end(n=>{n?t(n):e()})});return e.catch(c),e}}:null,kill:e=>{if(o.pid===void 0)o.kill(e);else try{process.kill(-o.pid,e??`SIGTERM`)}catch{o.kill(e)}},wait:()=>l}},i={spawn:r};export{r as n,i as t};
|