coding-agents-sdk 0.3.0 → 0.5.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 +36 -9
- package/dist/SdkAgent-CxDlEycD.mjs +1 -0
- package/dist/adapters/claude-code-cli/index.d.mts +1 -1
- package/dist/adapters/claude-code-cli/index.mjs +2 -2
- package/dist/adapters/claude-code-sdk/index.d.mts +1 -1
- package/dist/adapters/claude-code-sdk/index.mjs +1 -1
- package/dist/adapters/codex-cli/index.d.mts +1 -1
- package/dist/adapters/codex-cli/index.mjs +2 -2
- package/dist/adapters/codex-sdk/index.d.mts +1 -1
- package/dist/adapters/codex-sdk/index.mjs +1 -1
- package/dist/adapters/droid-cli/index.d.mts +2 -0
- package/dist/adapters/droid-cli/index.mjs +1 -0
- package/dist/adapters/gemini-cli/index.d.mts +1 -1
- package/dist/adapters/gemini-cli/index.mjs +1 -1
- package/dist/{classify-error-V6x6jP_R.mjs → classify-error-DoH0BqEA.mjs} +1 -1
- package/dist/container/index.d.mts +2 -2
- package/dist/container/index.mjs +1 -1
- package/dist/container-CC41a5S0.mjs +1 -0
- package/dist/container-DLkTfO-H.mjs +1 -0
- package/dist/container-LBwTeVQB.mjs +1 -0
- package/dist/container-rp_YHXtW.mjs +1 -0
- package/dist/diff-e89u7roM.mjs +1 -0
- package/dist/env-DIXTVzTs.mjs +1 -0
- package/dist/execution-target-DjI5SnsB.mjs +4 -0
- package/dist/{index-R77YR8ak.d.mts → index-Bg_PhFYu.d.mts} +23 -5
- package/dist/index-Chdt3rB6.d.mts +85 -0
- package/dist/{index-DP4Jxoax.d.mts → index-ClPF9ivJ.d.mts} +5 -5
- package/dist/{index-DNyKelMh.d.mts → index-DLrYZB-u.d.mts} +3 -3
- package/dist/{index-COHwWTg_.d.mts → index-DyF9byXC.d.mts} +4 -4
- package/dist/index-PVFQgWRb.d.mts +47 -0
- package/dist/{index-CzvanLE_.d.mts → index-dft9nZY4.d.mts} +2 -2
- package/dist/{index-jUwKDQ34.d.mts → index-v6kfcMNF.d.mts} +1 -1
- package/dist/index.d.mts +86 -10
- package/dist/index.mjs +1 -1
- package/dist/oci-WGkk88hR.mjs +1 -0
- package/dist/opencode-cli-EwDtW0sd.mjs +1 -0
- package/dist/pi-cli-J5YpX_ei.mjs +1 -0
- package/dist/sandbox/index.d.mts +2 -2
- package/dist/sandbox/index.mjs +1 -1
- package/dist/sandbox-_As0qZWn.mjs +4 -0
- package/dist/schemas/index.d.mts +1 -1
- package/dist/schemas/index.mjs +1 -1
- package/dist/shell-Dewbmt9R.mjs +1 -0
- package/dist/{types-COlDAzs5.d.mts → types-BeoSSi-l.d.mts} +2 -2
- package/package.json +18 -3
- package/dist/SdkAgent-a97nkDuR.mjs +0 -1
- package/dist/container-BY7JDOGo.mjs +0 -1
- package/dist/container-DWTITDhL.mjs +0 -1
- package/dist/container-vkn5-3Xl.mjs +0 -1
- package/dist/diff-BCfLDXNN.mjs +0 -1
- package/dist/env-Dkd8Sgjf.mjs +0 -1
- package/dist/execution-target-BJ5mWjDM.mjs +0 -4
- package/dist/index-DCaZeLrI.d.mts +0 -51
- package/dist/oci-C_S_FKHj.mjs +0 -1
- package/dist/sandbox-DeKpyenZ.mjs +0 -1
- /package/dist/{events-D31_b0sA.d.mts → events-D86KNGqO.d.mts} +0 -0
- /package/dist/{schemas-BM6qORw3.mjs → schemas-CXVWDOoT.mjs} +0 -0
- /package/dist/{structured-output-DEkBQ-1Z.mjs → structured-output-nPFh_ZoY.mjs} +0 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { D as ProcessSpawner } from "./types-BeoSSi-l.mjs";
|
|
2
|
+
import { Y as VolumeMount } from "./index-Bg_PhFYu.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/sandbox/types.d.ts
|
|
5
|
+
type SandboxType = "bubblewrap" | "firejail" | "nsjail";
|
|
6
|
+
type SandboxStatus = "created" | "disposed" | "running" | "stopped";
|
|
7
|
+
interface SandboxConfigBase<TType extends SandboxType> {
|
|
8
|
+
type: TType;
|
|
9
|
+
workdir: string;
|
|
10
|
+
}
|
|
11
|
+
interface SandboxIdentity<TType extends SandboxType, TConfig extends SandboxConfigBase<TType>> {
|
|
12
|
+
readonly type: TType;
|
|
13
|
+
readonly config: TConfig;
|
|
14
|
+
readonly status: SandboxStatus;
|
|
15
|
+
readonly workdir: string;
|
|
16
|
+
}
|
|
17
|
+
interface SandboxLifecycle {
|
|
18
|
+
start: () => Promise<void>;
|
|
19
|
+
stop: () => Promise<void>;
|
|
20
|
+
dispose: () => Promise<void>;
|
|
21
|
+
[Symbol.asyncDispose]: () => Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
interface SandboxExecution {
|
|
24
|
+
readonly spawner: ProcessSpawner;
|
|
25
|
+
}
|
|
26
|
+
interface SandboxBase<TType extends SandboxType, TConfig extends SandboxConfigBase<TType>> extends SandboxExecution, SandboxIdentity<TType, TConfig>, SandboxLifecycle {}
|
|
27
|
+
interface BubblewrapSandboxConfig extends SandboxConfigBase<"bubblewrap"> {
|
|
28
|
+
binary?: string;
|
|
29
|
+
binds?: VolumeMount[];
|
|
30
|
+
clearEnv?: boolean;
|
|
31
|
+
setEnv?: Record<string, string>;
|
|
32
|
+
unsetEnv?: string[];
|
|
33
|
+
unshareAll?: boolean;
|
|
34
|
+
shareNetwork?: boolean;
|
|
35
|
+
hostname?: string;
|
|
36
|
+
uid?: number;
|
|
37
|
+
gid?: number;
|
|
38
|
+
tmpfs?: string[];
|
|
39
|
+
remountReadonly?: string[];
|
|
40
|
+
proc?: false | string;
|
|
41
|
+
dev?: false | string;
|
|
42
|
+
args?: string[];
|
|
43
|
+
}
|
|
44
|
+
interface BubblewrapSandbox extends SandboxBase<"bubblewrap", BubblewrapSandboxConfig> {}
|
|
45
|
+
interface FirejailSandboxConfig extends SandboxConfigBase<"firejail"> {
|
|
46
|
+
binary?: string;
|
|
47
|
+
clearEnv?: boolean;
|
|
48
|
+
setEnv?: Record<string, string>;
|
|
49
|
+
unsetEnv?: string[];
|
|
50
|
+
shareNetwork?: boolean;
|
|
51
|
+
whitelist?: string[];
|
|
52
|
+
blacklist?: string[];
|
|
53
|
+
readOnly?: string[];
|
|
54
|
+
readWrite?: string[];
|
|
55
|
+
privateTmp?: boolean;
|
|
56
|
+
args?: string[];
|
|
57
|
+
}
|
|
58
|
+
interface FirejailSandbox extends SandboxBase<"firejail", FirejailSandboxConfig> {}
|
|
59
|
+
interface NsjailSandboxConfig extends SandboxConfigBase<"nsjail"> {
|
|
60
|
+
binary?: string;
|
|
61
|
+
binds?: VolumeMount[];
|
|
62
|
+
readOnly?: string[];
|
|
63
|
+
clearEnv?: boolean;
|
|
64
|
+
setEnv?: Record<string, string>;
|
|
65
|
+
unsetEnv?: string[];
|
|
66
|
+
shareNetwork?: boolean;
|
|
67
|
+
uid?: number;
|
|
68
|
+
gid?: number;
|
|
69
|
+
hostname?: string;
|
|
70
|
+
tmpfs?: string[];
|
|
71
|
+
timeLimitSec?: number;
|
|
72
|
+
disableRlimits?: boolean;
|
|
73
|
+
seccompString?: string;
|
|
74
|
+
args?: string[];
|
|
75
|
+
}
|
|
76
|
+
interface NsjailSandbox extends SandboxBase<"nsjail", NsjailSandboxConfig> {}
|
|
77
|
+
type SandboxConfig = BubblewrapSandboxConfig | FirejailSandboxConfig | NsjailSandboxConfig;
|
|
78
|
+
type Sandbox = BubblewrapSandbox | FirejailSandbox | NsjailSandbox;
|
|
79
|
+
//#endregion
|
|
80
|
+
//#region src/sandbox/index.d.ts
|
|
81
|
+
declare function createSandbox(config: BubblewrapSandboxConfig): Promise<BubblewrapSandbox>;
|
|
82
|
+
declare function createSandbox(config: FirejailSandboxConfig): Promise<FirejailSandbox>;
|
|
83
|
+
declare function createSandbox(config: NsjailSandboxConfig): Promise<NsjailSandbox>;
|
|
84
|
+
//#endregion
|
|
85
|
+
export { FirejailSandboxConfig as a, Sandbox as c, SandboxConfigBase as d, SandboxExecution as f, SandboxType as g, SandboxStatus as h, FirejailSandbox as i, SandboxBase as l, SandboxLifecycle as m, BubblewrapSandbox as n, NsjailSandbox as o, SandboxIdentity as p, BubblewrapSandboxConfig as r, NsjailSandboxConfig as s, createSandbox as t, SandboxConfig as u };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { S as McpServerConfig } from "./events-
|
|
2
|
-
import { D as ProcessSpawner, f as EnsureDisjoint, l as BaseAgent, p as ExclusiveExecutionTargetOptions, t as AgentEventHandler } from "./types-
|
|
3
|
-
import { t as Container } from "./index-
|
|
4
|
-
import {
|
|
1
|
+
import { S as McpServerConfig } from "./events-D86KNGqO.mjs";
|
|
2
|
+
import { D as ProcessSpawner, f as EnsureDisjoint, l as BaseAgent, p as ExclusiveExecutionTargetOptions, t as AgentEventHandler } from "./types-BeoSSi-l.mjs";
|
|
3
|
+
import { t as Container } from "./index-Bg_PhFYu.mjs";
|
|
4
|
+
import { c as Sandbox } from "./index-Chdt3rB6.mjs";
|
|
5
5
|
import { z } from "zod/v4";
|
|
6
6
|
|
|
7
7
|
//#region src/adapters/codex-cli/events/schemas.d.ts
|
|
@@ -77,7 +77,7 @@ type CodexErrorEvent = z.infer<typeof codexErrorEventSchema>;
|
|
|
77
77
|
//#endregion
|
|
78
78
|
//#region src/adapters/codex-cli/types.d.ts
|
|
79
79
|
type CodexCliSandboxMode = "danger-full-access" | "read-only" | "workspace-write";
|
|
80
|
-
type CodexCliPermissionMode = "
|
|
80
|
+
type CodexCliPermissionMode = "auto-approve" | "bypass-sandbox" | "default";
|
|
81
81
|
interface CodexCliRunOptions {
|
|
82
82
|
codexSandboxMode?: CodexCliSandboxMode;
|
|
83
83
|
additionalDirectories?: string[];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { D as ProcessSpawner, f as EnsureDisjoint, l as BaseAgent, p as ExclusiveExecutionTargetOptions, t as AgentEventHandler } from "./types-
|
|
2
|
-
import { t as Container } from "./index-
|
|
3
|
-
import {
|
|
1
|
+
import { D as ProcessSpawner, f as EnsureDisjoint, l as BaseAgent, p as ExclusiveExecutionTargetOptions, t as AgentEventHandler } from "./types-BeoSSi-l.mjs";
|
|
2
|
+
import { t as Container } from "./index-Bg_PhFYu.mjs";
|
|
3
|
+
import { c as Sandbox } from "./index-Chdt3rB6.mjs";
|
|
4
4
|
import { z } from "zod/v4";
|
|
5
5
|
|
|
6
6
|
//#region src/adapters/gemini-cli/events/schemas.d.ts
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { S as McpServerConfig } from "./events-
|
|
2
|
-
import { D as ProcessSpawner, f as EnsureDisjoint, l as BaseAgent, p as ExclusiveExecutionTargetOptions, t as AgentEventHandler } from "./types-
|
|
3
|
-
import { t as Container } from "./index-
|
|
4
|
-
import {
|
|
1
|
+
import { S as McpServerConfig } from "./events-D86KNGqO.mjs";
|
|
2
|
+
import { D as ProcessSpawner, f as EnsureDisjoint, l as BaseAgent, p as ExclusiveExecutionTargetOptions, t as AgentEventHandler } from "./types-BeoSSi-l.mjs";
|
|
3
|
+
import { t as Container } from "./index-Bg_PhFYu.mjs";
|
|
4
|
+
import { c as Sandbox } from "./index-Chdt3rB6.mjs";
|
|
5
5
|
import { z } from "zod/v4";
|
|
6
6
|
|
|
7
7
|
//#region src/adapters/claude-code-cli/events/schemas.d.ts
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { D as ProcessSpawner, f as EnsureDisjoint, l as BaseAgent, p as ExclusiveExecutionTargetOptions, t as AgentEventHandler } from "./types-BeoSSi-l.mjs";
|
|
2
|
+
import { t as Container } from "./index-Bg_PhFYu.mjs";
|
|
3
|
+
import { c as Sandbox } from "./index-Chdt3rB6.mjs";
|
|
4
|
+
import { z } from "zod/v4";
|
|
5
|
+
|
|
6
|
+
//#region src/adapters/droid-cli/events/schemas.d.ts
|
|
7
|
+
declare const droidEventSchema: z.ZodObject<{
|
|
8
|
+
type: z.ZodString;
|
|
9
|
+
}, z.core.$loose>;
|
|
10
|
+
type DroidEvent = z.infer<typeof droidEventSchema>;
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/adapters/droid-cli/types.d.ts
|
|
13
|
+
type DroidCliAutonomyLevel = "high" | "low" | "medium";
|
|
14
|
+
type DroidCliReasoningEffort = "high" | "low" | "medium" | "none" | "off";
|
|
15
|
+
interface DroidCliRunOptions {
|
|
16
|
+
autonomyLevel?: DroidCliAutonomyLevel;
|
|
17
|
+
enabledTools?: string[];
|
|
18
|
+
disabledTools?: string[];
|
|
19
|
+
reasoningEffort?: DroidCliReasoningEffort;
|
|
20
|
+
specModel?: string;
|
|
21
|
+
specReasoningEffort?: DroidCliReasoningEffort;
|
|
22
|
+
useSpec?: boolean;
|
|
23
|
+
skipPermissionsUnsafe?: boolean;
|
|
24
|
+
tags?: string[];
|
|
25
|
+
logGroupId?: string;
|
|
26
|
+
extraArgs?: string[];
|
|
27
|
+
systemPrompt?: never;
|
|
28
|
+
}
|
|
29
|
+
type DroidCliAgentOptions = DroidCliRunOptions & ExclusiveExecutionTargetOptions<Container, Sandbox> & {
|
|
30
|
+
command?: string[] | string;
|
|
31
|
+
cwd?: string;
|
|
32
|
+
env?: Record<string, string>;
|
|
33
|
+
propagateEnv?: boolean;
|
|
34
|
+
sessionId?: string;
|
|
35
|
+
model?: string;
|
|
36
|
+
logPath?: string;
|
|
37
|
+
spawner?: ProcessSpawner;
|
|
38
|
+
onEvent?: AgentEventHandler;
|
|
39
|
+
};
|
|
40
|
+
interface DroidCliAgent extends BaseAgent<EnsureDisjoint<DroidCliRunOptions>> {
|
|
41
|
+
readonly type: "droid-cli";
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region src/adapters/droid-cli/adapter.d.ts
|
|
45
|
+
declare const createDroidCliAgent: (options?: DroidCliAgentOptions) => DroidCliAgent;
|
|
46
|
+
//#endregion
|
|
47
|
+
export { DroidCliReasoningEffort as a, DroidCliAutonomyLevel as i, DroidCliAgent as n, DroidCliRunOptions as o, DroidCliAgentOptions as r, DroidEvent as s, createDroidCliAgent as t };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as McpServerConfig } from "./events-
|
|
2
|
-
import { f as EnsureDisjoint, l as BaseAgent, t as AgentEventHandler } from "./types-
|
|
1
|
+
import { S as McpServerConfig } from "./events-D86KNGqO.mjs";
|
|
2
|
+
import { f as EnsureDisjoint, l as BaseAgent, t as AgentEventHandler } from "./types-BeoSSi-l.mjs";
|
|
3
3
|
//#region src/adapters/claude-code-sdk/types.d.ts
|
|
4
4
|
type ClaudeCodeSdkPermissionMode = "acceptEdits" | "bypassPermissions" | "default" | "dontAsk" | "plan";
|
|
5
5
|
type ClaudeCodeSdkExecutable = "bun" | "deno" | "node";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { f as EnsureDisjoint, l as BaseAgent, t as AgentEventHandler } from "./types-
|
|
1
|
+
import { f as EnsureDisjoint, l as BaseAgent, t as AgentEventHandler } from "./types-BeoSSi-l.mjs";
|
|
2
2
|
//#region src/adapters/codex-sdk/types.d.ts
|
|
3
3
|
type CodexSdkSandboxMode = "danger-full-access" | "read-only" | "workspace-write";
|
|
4
4
|
type CodexSdkModelReasoningEffort = "high" | "low" | "medium" | "minimal" | "xhigh";
|
package/dist/index.d.mts
CHANGED
|
@@ -1,17 +1,93 @@
|
|
|
1
|
-
import { C as OutputSchema, S as McpServerConfig, T as agentCapabilitiesSchema, a as SessionStartEvent, b as ImageContentPart, c as ToolResultEvent, i as SessionEndEvent, n as MessageEvent, o as StderrEvent, r as ReasoningEvent, s as ToolCallEvent, t as AgentEvent, u as eventSchema, v as AgentCapabilities, w as TextContentPart, x as JsonSchema, y as ContentPart } from "./events-
|
|
2
|
-
import { C as RunTiming, E as ZodRunRequest, S as RunStatus, T as StructuredRunRequest, _ as RunProcessInfo, a as AgentValidationError, b as RunResultBase, c as AnyRunResult, d as CompletedRunResult, f as EnsureDisjoint, g as RunError, h as JsonSchemaRunRequest, i as AgentType, l as BaseAgent, m as FailedRunResult, n as AgentMetrics, o as AnyCompletedRunResult, r as AgentRunError, s as AnyRunRequest, t as AgentEventHandler, u as CancelledRunResult, v as RunRequest, w as StopReason, x as RunStats, y as RunResult } from "./types-
|
|
3
|
-
import { A as
|
|
4
|
-
import { a as
|
|
5
|
-
import { a as ClaudeCodeCliRunOptions, c as ClaudeRateLimitEvent, d as ClaudeUserEvent, i as ClaudeCodeCliPermissionMode, l as ClaudeResultEvent, n as ClaudeCodeCliAgent, o as ClaudeAssistantEvent, r as ClaudeCodeCliAgentOptions, s as ClaudeEvent, u as ClaudeSystemEvent } from "./index-
|
|
6
|
-
import { a as ClaudeCodeSdkExecutable, c as ClaudeCodeSdkSettingSource, i as ClaudeCodeSdkEvent, l as ClaudeCodeSdkSettings, n as ClaudeCodeSdkAgent, o as ClaudeCodeSdkPermissionMode, r as ClaudeCodeSdkAgentOptions, s as ClaudeCodeSdkRunOptions } from "./index-
|
|
7
|
-
import { a as CodexCliRunOptions, c as CodexEvent, d as CodexItemUpdatedEvent, f as CodexThreadStartedEvent, i as CodexCliPermissionMode, l as CodexItemCompletedEvent, m as CodexTurnFailedEvent, n as CodexCliAgent, o as CodexCliSandboxMode, p as CodexTurnCompletedEvent, r as CodexCliAgentOptions, s as CodexErrorEvent, u as CodexItemStartedEvent } from "./index-
|
|
8
|
-
import { a as CodexSdkItem, i as CodexSdkEvent, n as CodexSdkAgent, o as CodexSdkPermissionMode, r as CodexSdkAgentOptions, s as CodexSdkRunOptions } from "./index-
|
|
9
|
-
import { a as
|
|
1
|
+
import { C as OutputSchema, S as McpServerConfig, T as agentCapabilitiesSchema, a as SessionStartEvent, b as ImageContentPart, c as ToolResultEvent, i as SessionEndEvent, n as MessageEvent, o as StderrEvent, r as ReasoningEvent, s as ToolCallEvent, t as AgentEvent, u as eventSchema, v as AgentCapabilities, w as TextContentPart, x as JsonSchema, y as ContentPart } from "./events-D86KNGqO.mjs";
|
|
2
|
+
import { C as RunTiming, D as ProcessSpawner, E as ZodRunRequest, S as RunStatus, T as StructuredRunRequest, _ as RunProcessInfo, a as AgentValidationError, b as RunResultBase, c as AnyRunResult, d as CompletedRunResult, f as EnsureDisjoint, g as RunError, h as JsonSchemaRunRequest, i as AgentType, l as BaseAgent, m as FailedRunResult, n as AgentMetrics, o as AnyCompletedRunResult, p as ExclusiveExecutionTargetOptions, r as AgentRunError, s as AnyRunRequest, t as AgentEventHandler, u as CancelledRunResult, v as RunRequest, w as StopReason, x as RunStats, y as RunResult } from "./types-BeoSSi-l.mjs";
|
|
3
|
+
import { $ as WorkdirFileChange, A as E2BProviderConfig, B as ContainerFileSystem, C as NerdctlProviderConfig, D as E2BContainerBase, E as E2BContainer, F as DockerContainerConfig, G as ContainerType, H as ContainerLifecycle, I as DockerProviderConfig, J as PortMapping, K as ExecOptions, L as ContainerBase, M as DockerBuildConfig, N as DockerContainer, O as E2BContainerConfig, P as DockerContainerBase, Q as WorkdirDiffStats, R as ContainerConfigBase, S as NerdctlProviderBase, T as E2BConnectionConfig, U as ContainerObservability, V as ContainerIdentity, W as ContainerStatus, X as WorkdirChangeKind, Y as VolumeMount, Z as WorkdirDiff, _ as NerdctlBuildBase, a as ContainerDiffError, b as NerdctlContainerBase, c as ContainerExecError, d as PodmanBuildBase, et as WorkdirSnapshot, f as PodmanBuildConfig, g as PodmanProviderConfig, h as PodmanContainerConfig, i as ContainerCreateError, j as DockerBuildBase, k as E2BCreateConfig, l as ContainerNotRunningError, m as PodmanContainerBase, n as ContainerConfig, o as ContainerDisposedError, p as PodmanContainer, q as ExecResult, r as createContainer, s as ContainerError, t as Container, tt as WorkdirSnapshotOptions, u as ContainerStartError, v as NerdctlBuildConfig, w as E2BConnectConfig, x as NerdctlContainerConfig, y as NerdctlContainer, z as ContainerExecution } from "./index-Bg_PhFYu.mjs";
|
|
4
|
+
import { a as FirejailSandboxConfig, c as Sandbox, d as SandboxConfigBase, f as SandboxExecution, g as SandboxType, h as SandboxStatus, i as FirejailSandbox, l as SandboxBase, m as SandboxLifecycle, n as BubblewrapSandbox, o as NsjailSandbox, p as SandboxIdentity, r as BubblewrapSandboxConfig, s as NsjailSandboxConfig, t as createSandbox, u as SandboxConfig } from "./index-Chdt3rB6.mjs";
|
|
5
|
+
import { a as ClaudeCodeCliRunOptions, c as ClaudeRateLimitEvent, d as ClaudeUserEvent, i as ClaudeCodeCliPermissionMode, l as ClaudeResultEvent, n as ClaudeCodeCliAgent, o as ClaudeAssistantEvent, r as ClaudeCodeCliAgentOptions, s as ClaudeEvent, u as ClaudeSystemEvent } from "./index-DyF9byXC.mjs";
|
|
6
|
+
import { a as ClaudeCodeSdkExecutable, c as ClaudeCodeSdkSettingSource, i as ClaudeCodeSdkEvent, l as ClaudeCodeSdkSettings, n as ClaudeCodeSdkAgent, o as ClaudeCodeSdkPermissionMode, r as ClaudeCodeSdkAgentOptions, s as ClaudeCodeSdkRunOptions } from "./index-dft9nZY4.mjs";
|
|
7
|
+
import { a as CodexCliRunOptions, c as CodexEvent, d as CodexItemUpdatedEvent, f as CodexThreadStartedEvent, i as CodexCliPermissionMode, l as CodexItemCompletedEvent, m as CodexTurnFailedEvent, n as CodexCliAgent, o as CodexCliSandboxMode, p as CodexTurnCompletedEvent, r as CodexCliAgentOptions, s as CodexErrorEvent, u as CodexItemStartedEvent } from "./index-ClPF9ivJ.mjs";
|
|
8
|
+
import { a as CodexSdkItem, i as CodexSdkEvent, n as CodexSdkAgent, o as CodexSdkPermissionMode, r as CodexSdkAgentOptions, s as CodexSdkRunOptions } from "./index-v6kfcMNF.mjs";
|
|
9
|
+
import { a as DroidCliReasoningEffort, i as DroidCliAutonomyLevel, n as DroidCliAgent, o as DroidCliRunOptions, r as DroidCliAgentOptions, s as DroidEvent } from "./index-PVFQgWRb.mjs";
|
|
10
|
+
import { a as GeminiCliRunOptions, i as GeminiCliPermissionMode, n as GeminiCliAgent, o as GeminiEvent, r as GeminiCliAgentOptions } from "./index-DLrYZB-u.mjs";
|
|
11
|
+
import { z } from "zod/v4";
|
|
12
|
+
|
|
13
|
+
//#region src/adapters/opencode-cli/events/schemas.d.ts
|
|
14
|
+
declare const opencodeEventSchema: z.ZodObject<{
|
|
15
|
+
type: z.ZodString;
|
|
16
|
+
}, z.core.$loose>;
|
|
17
|
+
type OpencodeEvent = z.infer<typeof opencodeEventSchema>;
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/adapters/opencode-cli/types.d.ts
|
|
20
|
+
interface OpencodeCliRunOptions {
|
|
21
|
+
agent?: string;
|
|
22
|
+
files?: string[];
|
|
23
|
+
forkSession?: boolean;
|
|
24
|
+
share?: boolean;
|
|
25
|
+
thinking?: boolean;
|
|
26
|
+
title?: string;
|
|
27
|
+
variant?: string;
|
|
28
|
+
extraArgs?: string[];
|
|
29
|
+
systemPrompt?: never;
|
|
30
|
+
}
|
|
31
|
+
type OpencodeCliAgentOptions = ExclusiveExecutionTargetOptions<Container, Sandbox> & OpencodeCliRunOptions & {
|
|
32
|
+
command?: string[] | string;
|
|
33
|
+
cwd?: string;
|
|
34
|
+
env?: Record<string, string>;
|
|
35
|
+
propagateEnv?: boolean;
|
|
36
|
+
sessionId?: string;
|
|
37
|
+
model?: string;
|
|
38
|
+
logPath?: string;
|
|
39
|
+
spawner?: ProcessSpawner;
|
|
40
|
+
onEvent?: AgentEventHandler;
|
|
41
|
+
};
|
|
42
|
+
interface OpencodeCliAgent extends BaseAgent<EnsureDisjoint<OpencodeCliRunOptions>> {
|
|
43
|
+
readonly type: "opencode-cli";
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region src/adapters/pi-cli/events/schemas.d.ts
|
|
47
|
+
declare const piEventSchema: z.ZodObject<{
|
|
48
|
+
type: z.ZodString;
|
|
49
|
+
}, z.core.$loose>;
|
|
50
|
+
type PiEvent = z.infer<typeof piEventSchema>;
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/adapters/pi-cli/types.d.ts
|
|
53
|
+
type PiCliThinkingLevel = "high" | "low" | "medium" | "minimal" | "off" | "xhigh";
|
|
54
|
+
interface PiCliRunOptions {
|
|
55
|
+
provider?: string;
|
|
56
|
+
thinking?: PiCliThinkingLevel;
|
|
57
|
+
appendSystemPrompt?: string;
|
|
58
|
+
tools?: string[];
|
|
59
|
+
noTools?: boolean;
|
|
60
|
+
noSession?: boolean;
|
|
61
|
+
sessionDir?: string;
|
|
62
|
+
forkSession?: boolean;
|
|
63
|
+
extraArgs?: string[];
|
|
64
|
+
}
|
|
65
|
+
type PiCliAgentOptions = ExclusiveExecutionTargetOptions<Container, Sandbox> & PiCliRunOptions & {
|
|
66
|
+
command?: string[] | string;
|
|
67
|
+
cwd?: string;
|
|
68
|
+
env?: Record<string, string>;
|
|
69
|
+
propagateEnv?: boolean;
|
|
70
|
+
sessionId?: string;
|
|
71
|
+
model?: string;
|
|
72
|
+
systemPrompt?: string;
|
|
73
|
+
logPath?: string;
|
|
74
|
+
spawner?: ProcessSpawner;
|
|
75
|
+
onEvent?: AgentEventHandler;
|
|
76
|
+
};
|
|
77
|
+
interface PiCliAgent extends BaseAgent<EnsureDisjoint<PiCliRunOptions>> {
|
|
78
|
+
readonly type: "pi-cli";
|
|
79
|
+
fork: () => PiCliAgent;
|
|
80
|
+
dispose: () => Promise<void>;
|
|
81
|
+
}
|
|
82
|
+
//#endregion
|
|
10
83
|
//#region src/core/agent/create-agent.d.ts
|
|
11
84
|
declare function createAgent(type: "claude-code-cli", options?: ClaudeCodeCliAgentOptions): Promise<ClaudeCodeCliAgent>;
|
|
12
85
|
declare function createAgent(type: "claude-code-sdk", options?: ClaudeCodeSdkAgentOptions): Promise<ClaudeCodeSdkAgent>;
|
|
13
86
|
declare function createAgent(type: "codex-cli", options?: CodexCliAgentOptions): Promise<CodexCliAgent>;
|
|
14
87
|
declare function createAgent(type: "codex-sdk", options?: CodexSdkAgentOptions): Promise<CodexSdkAgent>;
|
|
88
|
+
declare function createAgent(type: "droid-cli", options?: DroidCliAgentOptions): Promise<DroidCliAgent>;
|
|
15
89
|
declare function createAgent(type: "gemini-cli", options?: GeminiCliAgentOptions): Promise<GeminiCliAgent>;
|
|
90
|
+
declare function createAgent(type: "opencode-cli", options?: OpencodeCliAgentOptions): Promise<OpencodeCliAgent>;
|
|
91
|
+
declare function createAgent(type: "pi-cli", options?: PiCliAgentOptions): Promise<PiCliAgent>;
|
|
16
92
|
//#endregion
|
|
17
|
-
export { type AgentCapabilities, type AgentEvent, type AgentEventHandler, type AgentMetrics, AgentRunError, type AgentType, AgentValidationError, type AnyCompletedRunResult, type AnyRunRequest, type AnyRunResult, type BaseAgent, type BubblewrapSandbox, type BubblewrapSandboxConfig, type CancelledRunResult, type ClaudeAssistantEvent, type ClaudeCodeCliAgent, type ClaudeCodeCliAgentOptions, type ClaudeCodeCliPermissionMode, type ClaudeCodeCliRunOptions, type ClaudeCodeSdkAgent, type ClaudeCodeSdkAgentOptions, type ClaudeCodeSdkEvent, type ClaudeCodeSdkExecutable, type ClaudeCodeSdkPermissionMode, type ClaudeCodeSdkRunOptions, type ClaudeCodeSdkSettingSource, type ClaudeCodeSdkSettings, type ClaudeEvent, type ClaudeRateLimitEvent, type ClaudeResultEvent, type ClaudeSystemEvent, type ClaudeUserEvent, type CodexCliAgent, type CodexCliAgentOptions, type CodexCliPermissionMode, type CodexCliRunOptions, type CodexCliSandboxMode, type CodexErrorEvent, type CodexEvent, type CodexItemCompletedEvent, type CodexItemStartedEvent, type CodexItemUpdatedEvent, type CodexSdkAgent, type CodexSdkAgentOptions, type CodexSdkEvent, type CodexSdkItem, type CodexSdkPermissionMode, type CodexSdkRunOptions, type CodexThreadStartedEvent, type CodexTurnCompletedEvent, type CodexTurnFailedEvent, type CompletedRunResult, type Container, type ContainerBase, type ContainerConfig, type ContainerConfigBase, ContainerCreateError, ContainerDiffError, ContainerDisposedError, ContainerError, ContainerExecError, type ContainerExecution, type ContainerFileSystem, type ContainerIdentity, type ContainerLifecycle, ContainerNotRunningError, type ContainerObservability, ContainerStartError, type ContainerStatus, type ContainerType, type ContentPart, type DockerBuildBase, type DockerBuildConfig, type DockerContainer, type DockerContainerBase, type DockerContainerConfig, type DockerProviderConfig, type E2BConnectConfig, type E2BConnectionConfig, type E2BContainer, type E2BContainerBase, type E2BContainerConfig, type E2BCreateConfig, type E2BProviderConfig, type EnsureDisjoint, type ExecOptions, type ExecResult, type FailedRunResult, type GeminiCliAgent, type GeminiCliAgentOptions, type GeminiCliPermissionMode, type GeminiCliRunOptions, type GeminiEvent, type ImageContentPart, type JsonSchema, type JsonSchemaRunRequest, type McpServerConfig, type MessageEvent, type OutputSchema, type PodmanBuildBase, type PodmanBuildConfig, type PodmanContainer, type PodmanContainerBase, type PodmanContainerConfig, type PodmanProviderConfig, type PortMapping, type ReasoningEvent, type RunError, type RunProcessInfo, type RunRequest, type RunResult, type RunResultBase, type RunStats, type RunStatus, type RunTiming, type Sandbox, type SandboxBase, type SandboxConfig, type SandboxConfigBase, type SandboxExecution, type SandboxIdentity, type SandboxLifecycle, type SandboxStatus, type SandboxType, type SessionEndEvent, type SessionStartEvent, type StderrEvent, type StopReason, type StructuredRunRequest, type TextContentPart, type ToolCallEvent, type ToolResultEvent, type VolumeMount, type WorkdirChangeKind, type WorkdirDiff, type WorkdirDiffStats, type WorkdirFileChange, type WorkdirSnapshot, type WorkdirSnapshotOptions, type ZodRunRequest, agentCapabilitiesSchema, createAgent, createContainer, createSandbox, eventSchema };
|
|
93
|
+
export { type AgentCapabilities, type AgentEvent, type AgentEventHandler, type AgentMetrics, AgentRunError, type AgentType, AgentValidationError, type AnyCompletedRunResult, type AnyRunRequest, type AnyRunResult, type BaseAgent, type BubblewrapSandbox, type BubblewrapSandboxConfig, type CancelledRunResult, type ClaudeAssistantEvent, type ClaudeCodeCliAgent, type ClaudeCodeCliAgentOptions, type ClaudeCodeCliPermissionMode, type ClaudeCodeCliRunOptions, type ClaudeCodeSdkAgent, type ClaudeCodeSdkAgentOptions, type ClaudeCodeSdkEvent, type ClaudeCodeSdkExecutable, type ClaudeCodeSdkPermissionMode, type ClaudeCodeSdkRunOptions, type ClaudeCodeSdkSettingSource, type ClaudeCodeSdkSettings, type ClaudeEvent, type ClaudeRateLimitEvent, type ClaudeResultEvent, type ClaudeSystemEvent, type ClaudeUserEvent, type CodexCliAgent, type CodexCliAgentOptions, type CodexCliPermissionMode, type CodexCliRunOptions, type CodexCliSandboxMode, type CodexErrorEvent, type CodexEvent, type CodexItemCompletedEvent, type CodexItemStartedEvent, type CodexItemUpdatedEvent, type CodexSdkAgent, type CodexSdkAgentOptions, type CodexSdkEvent, type CodexSdkItem, type CodexSdkPermissionMode, type CodexSdkRunOptions, type CodexThreadStartedEvent, type CodexTurnCompletedEvent, type CodexTurnFailedEvent, type CompletedRunResult, type Container, type ContainerBase, type ContainerConfig, type ContainerConfigBase, ContainerCreateError, ContainerDiffError, ContainerDisposedError, ContainerError, ContainerExecError, type ContainerExecution, type ContainerFileSystem, type ContainerIdentity, type ContainerLifecycle, ContainerNotRunningError, type ContainerObservability, ContainerStartError, type ContainerStatus, type ContainerType, type ContentPart, type DockerBuildBase, type DockerBuildConfig, type DockerContainer, type DockerContainerBase, type DockerContainerConfig, type DockerProviderConfig, type DroidCliAgent, type DroidCliAgentOptions, type DroidCliAutonomyLevel, type DroidCliReasoningEffort, type DroidCliRunOptions, type DroidEvent, type E2BConnectConfig, type E2BConnectionConfig, type E2BContainer, type E2BContainerBase, type E2BContainerConfig, type E2BCreateConfig, type E2BProviderConfig, type EnsureDisjoint, type ExecOptions, type ExecResult, type FailedRunResult, type FirejailSandbox, type FirejailSandboxConfig, type GeminiCliAgent, type GeminiCliAgentOptions, type GeminiCliPermissionMode, type GeminiCliRunOptions, type GeminiEvent, type ImageContentPart, type JsonSchema, type JsonSchemaRunRequest, type McpServerConfig, type MessageEvent, type NerdctlBuildBase, type NerdctlBuildConfig, type NerdctlContainer, type NerdctlContainerBase, type NerdctlContainerConfig, type NerdctlProviderBase, type NerdctlProviderConfig, type NsjailSandbox, type NsjailSandboxConfig, type OpencodeCliAgent, type OpencodeCliAgentOptions, type OpencodeCliRunOptions, type OpencodeEvent, type OutputSchema, type PiCliAgent, type PiCliAgentOptions, type PiCliRunOptions, type PiCliThinkingLevel, type PiEvent, type PodmanBuildBase, type PodmanBuildConfig, type PodmanContainer, type PodmanContainerBase, type PodmanContainerConfig, type PodmanProviderConfig, type PortMapping, type ReasoningEvent, type RunError, type RunProcessInfo, type RunRequest, type RunResult, type RunResultBase, type RunStats, type RunStatus, type RunTiming, type Sandbox, type SandboxBase, type SandboxConfig, type SandboxConfigBase, type SandboxExecution, type SandboxIdentity, type SandboxLifecycle, type SandboxStatus, type SandboxType, type SessionEndEvent, type SessionStartEvent, type StderrEvent, type StopReason, type StructuredRunRequest, type TextContentPart, type ToolCallEvent, type ToolResultEvent, type VolumeMount, type WorkdirChangeKind, type WorkdirDiff, type WorkdirDiffStats, type WorkdirFileChange, type WorkdirSnapshot, type WorkdirSnapshotOptions, type ZodRunRequest, agentCapabilitiesSchema, createAgent, createContainer, createSandbox, eventSchema };
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e,t}from"./types-CwvWHEpy.mjs";import{a as n,i as r,n as i,o as a,r as o,s,t as c}from"./errors-XV0frS3r.mjs";import{createContainer as l}from"./container/index.mjs";import{t as u}from"./sandbox-
|
|
1
|
+
import{n as e,t}from"./types-CwvWHEpy.mjs";import{a as n,i as r,n as i,o as a,r as o,s,t as c}from"./errors-XV0frS3r.mjs";import{createContainer as l}from"./container/index.mjs";import{t as u}from"./sandbox-_As0qZWn.mjs";import{n as d,u as f}from"./schemas-CXVWDOoT.mjs";const p=(e,t)=>{if(!(e instanceof Error)||!e.message.includes(t))return!1;let n=typeof e==`object`&&e&&`code`in e?e.code:void 0;return n===`ERR_MODULE_NOT_FOUND`||n===`MODULE_NOT_FOUND`},m=(t,n,r)=>{throw p(r,n)?new e(`Agent type "${t}" requires the optional peer dependency "${n}". Install it to use this adapter.`):r};async function h(t,n){switch(t){case`claude-code-cli`:{let{createClaudeCodeCliAgent:e}=await import(`./adapters/claude-code-cli/index.mjs`);return e(n)}case`claude-code-sdk`:{let e=n;try{let{createClaudeCodeSdkAgent:t}=await import(`./adapters/claude-code-sdk/index.mjs`);return t(e)}catch(e){return m(`claude-code-sdk`,`@anthropic-ai/claude-agent-sdk`,e)}}case`codex-cli`:{let{createCodexCliAgent:e}=await import(`./adapters/codex-cli/index.mjs`);return e(n)}case`codex-sdk`:{let e=n;try{let{createCodexSdkAgent:t}=await import(`./adapters/codex-sdk/index.mjs`);return t(e)}catch(e){return m(`codex-sdk`,`@openai/codex-sdk`,e)}}case`droid-cli`:{let{createDroidCliAgent:e}=await import(`./adapters/droid-cli/index.mjs`);return e(n)}case`gemini-cli`:{let{createGeminiCliAgent:e}=await import(`./adapters/gemini-cli/index.mjs`);return e(n)}case`opencode-cli`:{let{createOpencodeCliAgent:e}=await import(`./opencode-cli-EwDtW0sd.mjs`);return e(n)}case`pi-cli`:{let{createPiCliAgent:e}=await import(`./pi-cli-J5YpX_ei.mjs`);return e(n)}default:throw new e(`Unsupported agent type.`)}}export{t as AgentRunError,e as AgentValidationError,c as ContainerCreateError,i as ContainerDiffError,o as ContainerDisposedError,r as ContainerError,n as ContainerExecError,a as ContainerNotRunningError,s as ContainerStartError,f as agentCapabilitiesSchema,h as createAgent,l as createContainer,u as createSandbox,d as eventSchema};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as e}from"./util-CGg8cK92.mjs";import{a as t,n,o as r,r as i,s as a,t as o}from"./errors-XV0frS3r.mjs";import{n as s}from"./env-DIXTVzTs.mjs";import{t as c}from"./spawner-BJesLc8I.mjs";import{t as l}from"./shell-Dewbmt9R.mjs";import{n as u,r as d,t as f}from"./diff-e89u7roM.mjs";import{execFile as p}from"node:child_process";import{isAbsolute as m,join as h,posix as g}from"node:path";import{promisify as _}from"node:util";import{tmpdir as v}from"node:os";import{mkdtemp as y,rm as b,writeFile as x}from"node:fs/promises";import{randomBytes as S}from"node:crypto";const C=(e,t)=>{let n=g.relative(e,t);return n===``||!n.startsWith(`..`)&&!g.isAbsolute(n)},w=(e,t)=>{if(!e||e.length===0)return;let n=g.normalize(t),r;for(let t of e){if(!m(t.source))continue;let e=g.normalize(t.target);C(e,n)&&(!r||e.length>g.normalize(r.target).length)&&(r=t)}if(!r)return;let i=g.relative(g.normalize(r.target),n);return i===``?r.source:h(r.source,...i.split(`/`))},T=_(p),E=()=>`cw-${S(6).toString(`hex`)}`,D=(e,t)=>e.baseArgs?[...e.baseArgs,...t]:t,O=e=>{if(e.env)return{...s(),...e.env}},k=async(e,t,n)=>{let r=await T(e.binary,D(e,t),{encoding:`utf8`,env:O(e),timeout:n?.timeoutMs,signal:n?.signal,maxBuffer:50*1024*1024});return{stdout:r.stdout,stderr:r.stderr}},A=async(t,n)=>{let r=n.tag??`cw-build-${S(4).toString(`hex`)}`,i=[`build`,`-t`,r];if(n.args)for(let[e,t]of Object.entries(n.args))i.push(`--build-arg`,`${e}=${t}`);`dockerfile`in n&&n.dockerfile&&(i.push(`-f`,n.dockerfile),i.push(n.context??`.`));let a;if(`content`in n&&n.content){a=await y(h(v(),`cw-oci-build-`));let e=h(a,`Dockerfile`);await x(e,n.content,{encoding:`utf8`,mode:384}),i.push(`-f`,e),i.push(n.context??a)}try{await k(t,i)}catch(t){throw new o(`Image build failed: ${e(t)}`)}finally{a&&await b(a,{recursive:!0,force:!0}).catch(()=>{})}return r},j=async(e,t,n)=>{let r=await Promise.all(n.map(async n=>{try{let{container:r,protocol:i=`tcp`}=n,{stdout:a}=await k(e,[`port`,t,`${r}/${i}`]),o=/:(\d+)$/m.exec(a.trim());if(o?.[1])return[r,Number(o[1])]}catch{}})),i=new Map;for(let e of r)e&&i.set(e[0],e[1]);return i},M=(e,t)=>({spawn:(n,r,i={})=>{let a=[`exec`,`-i`];if(i.cwd&&a.push(`-w`,i.cwd),i.env)for(let[e,t]of Object.entries(i.env))a.push(`-e`,`${e}=${t}`);return a.push(e,n,...r),c.spawn(t.binary,D(t,a),{env:O(t),stdio:i.stdio})}}),N=async(s,p,m)=>{let{commandContext:h,builtImage:_,containerName:v,workdir:y,user:b,network:x,platform:S,env:C,ports:T,mounts:A,extraArgs:N,image:P}=p,F=v??E(),I=[`create`,`--name`,F];if(b&&I.push(`--user`,b),x&&I.push(`--network`,x),S&&I.push(`--platform`,S),C)for(let[e,t]of Object.entries(C))I.push(`-e`,`${e}=${t}`);if(T)for(let e of T){let{host:t,container:n,protocol:r=`tcp`}=e;I.push(`-p`,`${t??``}:${n}/${r}`)}if(A)for(let e of A){let{readonly:t,source:n,target:r}=e,i=t?`ro`:`rw`;I.push(`-v`,`${n}:${r}:${i}`)}N&&I.push(...N),I.push(P,`sleep`,`infinity`);let L;try{let{stdout:e}=await k(h,I);L=e.trim()}catch(t){throw new o(`Container create failed: ${e(t)}`)}let R=`created`,z=new Map,B=()=>{if(R===`disposed`)throw new i},V=()=>{if(B(),R!==`running`)throw new r},H=M(L,h),U=u({owner:{},workdir:y,materialize:async(t,r)=>{B();let i=w(A,t);if(i){await f(i,r);return}V();try{await k(h,[`exec`,L,`sh`,`-c`,`test -d ${l(t)}`])}catch{throw new n(`Target path is not a directory: ${t}`)}try{await k(h,[`cp`,`${L}:${t}/.`,r])}catch(r){throw new n(`Failed to materialize container path ${t}: ${e(r)}`)}}}),W={get type(){return s},get id(){return L},get name(){return F},get config(){return m},get status(){return R},get workdir(){return y},get spawner(){return H},async start(){if(B(),R!==`running`){try{await k(h,[`start`,L])}catch(t){throw new a(`Container start failed: ${e(t)}`)}try{await k(h,[`exec`,L,`mkdir`,`-p`,y])}catch(t){try{await k(h,[`stop`,`-t`,`0`,L]),R=`stopped`}catch{try{let{stdout:e}=await k(h,[`inspect`,`--format`,`{{.State.Status}}`,L]);R=e.trim()===`running`?`running`:`stopped`}catch{R=`disposed`}}throw new a(`Container start failed: ${e(t)}`)}R=`running`,T?.length&&(z=await j(h,L,T))}},async stop(){if(B(),R===`running`){try{await k(h,[`stop`,`-t`,`2`,L])}catch{try{let{stdout:e}=await k(h,[`inspect`,`--format`,`{{.State.Status}}`,L]);if(e.trim()===`running`)return}catch{R=`disposed`;return}}R=`stopped`}},async dispose(){if(R!==`disposed`){try{await k(h,[`stop`,`-t`,`0`,L])}catch{}try{await k(h,[`rm`,`-f`,L])}catch{}_&&await k(h,[`rmi`,P]).catch(()=>{}),await U.disposeSnapshots().catch(()=>{}),R=`disposed`}},async exec(e,t,n={}){V();let r=[`exec`];if(n.cwd&&r.push(`-w`,n.cwd),n.env)for(let[e,t]of Object.entries(n.env))r.push(`-e`,`${e}=${t}`);r.push(L,e,...t);try{let{stdout:e,stderr:t}=await k(h,r,{timeoutMs:n.timeoutMs,signal:n.signal});return{exitCode:0,stdout:e,stderr:t}}catch(e){if(d(e))return{exitCode:typeof e.code==`number`?e.code:-1,stdout:String(e.stdout??``),stderr:String(e.stderr??``)};throw e}},async copyTo(e,t){V(),await k(h,[`cp`,e,`${L}:${t}`])},async copyFrom(e,t){V(),await k(h,[`cp`,`${L}:${e}`,t])},async writeFile(e,n){V();let r=g.isAbsolute(e)?e:g.resolve(y,e),i=g.dirname(r),a=typeof n==`string`?Buffer.from(n,`utf8`):n,o=[`exec`,`-i`];b&&o.push(`--user`,b),o.push(L,`sh`,`-c`,`mkdir -p ${l(i)} && cat > ${l(r)}`);let s=c.spawn(h.binary,D(h,o),{env:O(h),stdio:[`pipe`,`ignore`,`ignore`]});s.stdin?.write?.(a),s.stdin?.end();let u=await s.wait();if(u.exitCode!==0)throw new t(`writeFile failed for ${r} (exit ${u.exitCode})`)},async readFile(e){V();let t=g.isAbsolute(e)?e:g.resolve(y,e),{stdout:n}=await k(h,[`exec`,L,`cat`,t]);return n},async fileExists(e){V();let t=g.isAbsolute(e)?e:g.resolve(y,e);try{return await k(h,[`exec`,L,`test`,`-e`,t]),!0}catch{return!1}},async mkdir(e){V();let t=g.isAbsolute(e)?e:g.resolve(y,e);await k(h,[`exec`,L,`mkdir`,`-p`,t])},async execShell(e,t={}){return W.exec(`sh`,[`-c`,e],t)},async logs(e={}){B();let t=[`logs`];e.tail!==void 0&&t.push(`--tail`,String(e.tail)),t.push(L);let{stdout:n}=await k(h,t);return n},async syncStatus(){B();try{let{stdout:e}=await k(h,[`inspect`,`--format`,`{{.State.Status}}`,L]),t=e.trim();R=t===`running`?`running`:t===`created`?`created`:`stopped`}catch{R=`disposed`}return R},async snapshotWorkdir(e={}){return U.snapshotWorkdir(e)},async diffWorkdir(e){return U.diffWorkdir(e)},async releaseWorkdirSnapshot(e){return U.releaseWorkdirSnapshot(e)},getMappedPort(e){return z.get(e)},[Symbol.asyncDispose](){return W.dispose()}};return W},P=async(e,t)=>{if(t.image)return t.image;if(t.build)return A(e,t.build);throw new o(`Either image or build must be provided.`)};export{P as n,N as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as e,i as t,n}from"./util-CGg8cK92.mjs";import{a as r,c as i,o as a,s as o}from"./classify-error-DoH0BqEA.mjs";import{n as s,t as c}from"./execution-target-DjI5SnsB.mjs";import{z as l}from"zod/v4";const u=e=>typeof e==`string`?e:void 0,d=e=>typeof e==`number`&&Number.isFinite(e)?e:void 0,f=e=>{if(typeof e==`string`)return e;if(e==null)return``;try{return JSON.stringify(e)}catch{return String(e)}},p=()=>crypto.randomUUID(),m=()=>({steps:0,cost:0,inputTokens:0,outputTokens:0,cacheReadTokens:0,cacheWriteTokens:0}),h=e=>{let t=e;return u(t.sessionID)??u(t.session_id)},g=(e,t)=>{let a=u((n(e.part)?e.part:void 0)?.text)??``;return a.trim()?{events:[r(t.runId,`message`,{sessionId:t.sessionId,model:null,role:`assistant`,content:[i(a)],text:a})]}:{events:[]}},_=(e,t)=>{let a=u((n(e.part)?e.part:void 0)?.text)??``;return a.trim()?{events:[r(t.runId,`reasoning`,{sessionId:t.sessionId,model:null,content:[i(a)],text:a})]}:{events:[]}},v=(e,t)=>{let i=n(e.part)?e.part:void 0;if(!i)return{events:[]};let a=u(i.callID)??p(),o=u(i.tool)??`tool`,s=n(i.state)?i.state:void 0;if(!s)return{events:[]};let c=n(s.input)?s.input:void 0,l=s.status===`error`,d=l?u(s.error)??f(s.output)??`Tool call failed.`:f(s.output);return{events:[r(t.runId,`tool-call`,{sessionId:t.sessionId,model:null,toolCallId:a,toolName:o,input:c}),r(t.runId,`tool-result`,{sessionId:t.sessionId,toolCallId:a,toolName:o,input:c,output:d,isError:l||void 0,error:l?d:void 0})],toolCalls:[{toolCallId:a,toolName:o,input:c}]}},y=(e,r,i)=>{let a=n(e.part)?e.part:void 0;if(!a)return{events:[]};let o=u(a.reason),s=d(a.cost)??0,c=n(a.tokens)?a.tokens:void 0,l=n(c?.cache)?c.cache:void 0;return i.steps+=1,i.cost+=s,i.inputTokens+=d(c?.input)??0,i.outputTokens+=d(c?.output)??0,i.cacheReadTokens+=d(l?.read)??0,i.cacheWriteTokens+=d(l?.write)??0,o===`stop`?{events:[],state:{stats:{turns:i.steps,costUsd:i.cost,inputTokens:i.inputTokens,outputTokens:i.outputTokens,cacheReadInputTokens:i.cacheReadTokens,cacheCreationInputTokens:i.cacheWriteTokens,totalTokens:t(i.inputTokens,i.outputTokens,i.cacheReadTokens,i.cacheWriteTokens)},status:`completed`}}:{events:[]}},b=(e,t)=>{let i=n(e.error)?e.error:void 0,a=u((n(i?.data)?i.data:void 0)?.message)??u(i?.message)??u(i?.name)??`unknown error`;return{events:[r(t.runId,`stderr`,{sessionId:t.sessionId,text:a})],state:{status:`failed`,error:{kind:`provider`,message:a}}}},x=(e,t,n)=>{let r=e;switch(e.type){case`text`:return g(r,t);case`reasoning`:return _(r,t);case`tool_use`:return v(r,t);case`step_finish`:return y(r,t,n);case`error`:return b(r,t);default:return{events:[]}}},S=a(l.object({type:l.string()}).passthrough()),C={structuredOutput:!1,sessionResume:!0,sessionFork:!0,imageInput:!1,mcp:!0,eventStreaming:!0};var w=class extends s{type=`opencode-cli`;creationOptions;runDefaults;stepAccumulators=new Map;constructor(t={}){super({type:`opencode-cli`,capabilities:C,defaults:{cwd:t.cwd,env:t.env,command:e(t.command??`opencode`),sessionId:t.sessionId,model:t.model},spawner:t.spawner,executionTarget:t.container??t.sandbox,logPath:t.logPath,onEvent:t.onEvent}),this.creationOptions=t,this.runDefaults={agent:t.agent,files:t.files?[...t.files]:void 0,forkSession:t.forkSession,share:t.share,thinking:t.thinking,title:t.title,variant:t.variant,extraArgs:t.extraArgs?[...t.extraArgs]:void 0}}buildArgs(e,t){let n=[`run`,`--format`,`json`],r=o(e.input),i=e.agent??this.runDefaults.agent,a=e.files??this.runDefaults.files,s=e.forkSession??this.runDefaults.forkSession,c=e.share??this.runDefaults.share,l=e.thinking??this.runDefaults.thinking,u=e.title??this.runDefaults.title,d=e.variant??this.runDefaults.variant,f=e.extraArgs??this.runDefaults.extraArgs;if(e.model&&n.push(`--model`,e.model),i&&n.push(`--agent`,i),a&&a.length>0)for(let e of a)n.push(`--file`,e);t.requestedSessionId&&(n.push(`--session`,t.requestedSessionId),s&&n.push(`--fork`)),c&&n.push(`--share`),l&&n.push(`--thinking`),u!==void 0&&n.push(`--title`,u),d&&n.push(`--variant`,d),f&&f.length>0&&n.push(...f);let p=r.trim().split(/\s+/).filter(Boolean);return n.push(`--`,...p),n}buildEnv(e,t){return this.buildDefaultEnv(this.creationOptions.propagateEnv)}mapRawEvent(e,t){this.appendRawLog(e);let n=S(e);if(!n)return this.onParseError(JSON.stringify(e).slice(0,200),Error(`schema validation failed`)),{events:[]};let r=h(n)??t.sessionId,i=this.stepAccumulators.get(t.runId);i||(i=m(),this.stepAccumulators.set(t.runId,i));let a=x(n,{...t,sessionId:r},i);return r&&a.sessionId===void 0&&(a.sessionId=r),a}async onRunFinished(e){await super.onRunFinished(e),this.stepAccumulators.delete(e.runId)}};const T=e=>new w(c(e).options);export{T as createOpencodeCliAgent};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e}from"./types-CwvWHEpy.mjs";import{a as t,n}from"./util-CGg8cK92.mjs";import{a as r,c as i,o as a,s as o}from"./classify-error-DoH0BqEA.mjs";import{n as s,t as c}from"./execution-target-DjI5SnsB.mjs";import{z as l}from"zod/v4";const u=e=>typeof e==`string`?e:void 0,d=e=>typeof e==`number`&&Number.isFinite(e)?e:void 0,f=()=>crypto.randomUUID(),p=e=>{if(typeof e==`string`)return e;if(e==null)return``;try{return JSON.stringify(e)}catch{return String(e)}},m=e=>{if(typeof e==`string`)return e;if(!Array.isArray(e))return``;let t=[];for(let r of e)n(r)&&r.type===`text`&&typeof r.text==`string`&&t.push(r.text);return t.join(``)},h=e=>{let t=e;if(t.type===`session`)return u(t.id)},g=e=>({events:[],sessionId:u(e.id)??void 0}),_=()=>({events:[]}),v=(e,t,a)=>{let o=n(e.message)?e.message:void 0;if(!o||u(o.role)!==`assistant`)return{events:[]};let s=m(o.content),c=u(o.model)??a.model??null,l=[];return a.reasoningText&&l.push(r(t.runId,`reasoning`,{sessionId:t.sessionId,model:c,content:[i(a.reasoningText)],text:a.reasoningText})),s&&l.push(r(t.runId,`message`,{sessionId:t.sessionId,model:c,role:`assistant`,content:[i(s)],text:s})),u(o.stopReason)===`error`?{events:l,state:{output:{text:s||void 0},status:`failed`,error:{kind:`provider`,message:`Pi model returned an error stop reason.`}}}:s?{events:l,state:{output:{text:s}}}:{events:l}},y=(e,t,n)=>{let i=u(e.toolCallId)??f(),a=u(e.toolName)??`tool`,o=e.args===void 0?void 0:e.args;return{events:[r(t.runId,`tool-call`,{sessionId:t.sessionId,model:n.model??null,toolCallId:i,toolName:a,input:o})],toolCalls:[{toolCallId:i,toolName:a,input:o}]}},b=(e,t)=>{let n=u(e.toolCallId)??f(),i=!!e.isError,a=e.result,o=t.toolCalls.get(n),s=u(e.toolName)??o?.toolName;return{events:[r(t.runId,`tool-result`,{sessionId:t.sessionId,toolCallId:n,toolName:s,input:o?.input,output:a,isError:i||void 0,error:i?p(a):void 0})]}},x=e=>{let t=n(e.message)?e.message:void 0;if(!t)return;let r=n(t.usage)?t.usage:void 0;if(!r)return;let i=d(r.input),a=d(r.output),o=d(r.cacheRead)||void 0,s=d(r.cacheWrite)||void 0;return{turns:1,durationMs:0,costUsd:n(r.cost)?d(r.cost.total)??0:d(r.cost)??0,inputTokens:i,outputTokens:a,cacheReadInputTokens:o,cacheCreationInputTokens:s,totalTokens:(i??0)+(a??0)+(o??0)+(s??0)||void 0}},S=e=>{let t=x(e);return t?{events:[],state:{stats:t}}:{events:[]}},C=(e,t,n={})=>{let r=e;switch(e.type){case`session`:return g(r);case`message_update`:return _();case`message_end`:return v(r,t,n);case`tool_execution_start`:return y(r,t,n);case`tool_execution_end`:return b(r,t);case`turn_end`:return S(r);default:return{events:[]}}},w=a(l.object({type:l.string()}).passthrough()),T={structuredOutput:!1,sessionResume:!0,imageInput:!0,mcp:!1,eventStreaming:!0,sessionFork:!0},E=(e,t)=>({turns:(e?.turns??0)+t.turns,durationMs:(e?.durationMs??0)+(t.durationMs??0),apiDurationMs:(e?.apiDurationMs??0)+(t.apiDurationMs??0),costUsd:(e?.costUsd??0)+t.costUsd,inputTokens:t.inputTokens!==void 0||e?.inputTokens!==void 0?(e?.inputTokens??0)+(t.inputTokens??0):void 0,outputTokens:t.outputTokens!==void 0||e?.outputTokens!==void 0?(e?.outputTokens??0)+(t.outputTokens??0):void 0,cacheReadInputTokens:t.cacheReadInputTokens!==void 0||e?.cacheReadInputTokens!==void 0?(e?.cacheReadInputTokens??0)+(t.cacheReadInputTokens??0):void 0,cacheCreationInputTokens:t.cacheCreationInputTokens!==void 0||e?.cacheCreationInputTokens!==void 0?(e?.cacheCreationInputTokens??0)+(t.cacheCreationInputTokens??0):void 0,totalTokens:t.totalTokens!==void 0||e?.totalTokens!==void 0?(e?.totalTokens??0)+(t.totalTokens??0):void 0});var D=class n extends s{type=`pi-cli`;creationOptions;runDefaults;runTextBuffers=new Map;runReasoningBuffers=new Map;runAccumulatedStats=new Map;forkOnNextRun;constructor(e={}){super({type:`pi-cli`,capabilities:T,defaults:{cwd:e.cwd,env:e.env,command:t(e.command??`pi`),sessionId:e.sessionId,model:e.model,systemPrompt:e.systemPrompt},spawner:e.spawner,executionTarget:e.container??e.sandbox,logPath:e.logPath,onEvent:e.onEvent}),this.creationOptions=e,this.runDefaults={provider:e.provider,thinking:e.thinking,appendSystemPrompt:e.appendSystemPrompt,tools:e.tools?[...e.tools]:void 0,noTools:e.noTools,noSession:e.noSession,sessionDir:e.sessionDir,forkSession:e.forkSession,extraArgs:e.extraArgs?[...e.extraArgs]:void 0},this.forkOnNextRun=e.forkOnNextRun??!1}fork(){if(!this.sessionId)throw new e(`Cannot fork a Pi CLI agent before it has a sessionId.`);return new n({...this.creationOptions,sessionId:this.sessionId,forkSession:void 0,forkOnNextRun:!0})}onValidateRun(t,n){if((t.forkSession??this.runDefaults.forkSession??this.forkOnNextRun)&&!this.sessionId)throw new e(`forkSession requires an existing sessionId on the agent.`)}buildArgs(e,t){let n=[`--mode`,`json`],r=e.provider??this.runDefaults.provider,i=e.thinking??this.runDefaults.thinking,a=e.appendSystemPrompt??this.runDefaults.appendSystemPrompt,s=e.tools??this.runDefaults.tools,c=e.noTools??this.runDefaults.noTools,l=e.noSession??this.runDefaults.noSession,u=e.sessionDir??this.runDefaults.sessionDir,d=e.forkSession??this.runDefaults.forkSession??this.forkOnNextRun,f=e.extraArgs??this.runDefaults.extraArgs;e.model?r?n.push(`--model`,`${r}/${e.model}`):n.push(`--model`,e.model):r&&n.push(`--provider`,r),e.systemPrompt&&n.push(`--system-prompt`,e.systemPrompt),a&&n.push(`--append-system-prompt`,a),i&&n.push(`--thinking`,i),c?n.push(`--no-tools`):s&&s.length>0&&n.push(`--tools`,s.join(`,`)),t.requestedSessionId?d?n.push(`--fork`,t.requestedSessionId):n.push(`--session`,t.requestedSessionId):l?n.push(`--no-session`):u&&n.push(`--session-dir`,u),f&&f.length>0&&n.push(...f);for(let t of e.input)t.type===`image`&&n.push(`@${t.path}`);let p=o(e.input);return n.push(p),n}buildEnv(e,t){return this.buildDefaultEnv(this.creationOptions.propagateEnv)}mapRawEvent(e,t){this.appendRawLog(e);let n=w(e);if(!n)return this.onParseError(JSON.stringify(e).slice(0,200),Error(`schema validation failed`)),{events:[]};let r=h(n)??t.sessionId;if(this.forkOnNextRun&&t.requestedSessionId&&r&&r!==t.requestedSessionId&&(this.forkOnNextRun=!1),n.type===`message_update`){let e=n.assistantMessageEvent,r=typeof e?.type==`string`?e.type:void 0,i=typeof e?.delta==`string`?e.delta:``;if(r===`text_delta`&&i){let e=`${this.runTextBuffers.get(t.runId)??``}${i}`;this.runTextBuffers.set(t.runId,e)}else if(r===`thinking_delta`&&i){let e=`${this.runReasoningBuffers.get(t.runId)??``}${i}`;this.runReasoningBuffers.set(t.runId,e)}}let i={model:void 0};n.type===`message_end`&&(i.reasoningText=this.runReasoningBuffers.get(t.runId),this.runReasoningBuffers.delete(t.runId));let a=C(n,{...t,sessionId:r},i);if(r&&a.sessionId===void 0&&(a.sessionId=r),a.state?.output?.text!==void 0&&this.runTextBuffers.set(t.runId,a.state.output.text),n.type===`turn_end`&&a.state?.stats){let e=E(this.runAccumulatedStats.get(t.runId),a.state.stats);this.runAccumulatedStats.set(t.runId,e),a.state.stats=e}return a}async onRunFinished(e){await super.onRunFinished(e),this.runTextBuffers.delete(e.runId),this.runReasoningBuffers.delete(e.runId),this.runAccumulatedStats.delete(e.runId)}};const O=e=>new D(c(e).options);export{O as createPiCliAgent};
|
package/dist/sandbox/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
export { BubblewrapSandbox, BubblewrapSandboxConfig, Sandbox, SandboxBase, SandboxConfig, SandboxConfigBase, SandboxExecution, SandboxIdentity, SandboxLifecycle, SandboxStatus, SandboxType, createSandbox };
|
|
1
|
+
import { a as FirejailSandboxConfig, c as Sandbox, d as SandboxConfigBase, f as SandboxExecution, g as SandboxType, h as SandboxStatus, i as FirejailSandbox, l as SandboxBase, m as SandboxLifecycle, n as BubblewrapSandbox, o as NsjailSandbox, p as SandboxIdentity, r as BubblewrapSandboxConfig, s as NsjailSandboxConfig, t as createSandbox, u as SandboxConfig } from "../index-Chdt3rB6.mjs";
|
|
2
|
+
export { BubblewrapSandbox, BubblewrapSandboxConfig, FirejailSandbox, FirejailSandboxConfig, NsjailSandbox, NsjailSandboxConfig, Sandbox, SandboxBase, SandboxConfig, SandboxConfigBase, SandboxExecution, SandboxIdentity, SandboxLifecycle, SandboxStatus, SandboxType, createSandbox };
|
package/dist/sandbox/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"../sandbox-
|
|
1
|
+
import{t as e}from"../sandbox-_As0qZWn.mjs";export{e as createSandbox};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{t as e}from"./util-CGg8cK92.mjs";import{n as t,r as n,t as r}from"./env-DIXTVzTs.mjs";import{t as i}from"./spawner-BJesLc8I.mjs";import{t as a}from"./shell-Dewbmt9R.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 ee}from"node:os";const y=e=>{let t=e.type.charAt(0).toUpperCase()+e.type.slice(1),n=`created`,r=new Set,i=()=>{if(n===`disposed`)throw Error(`${t} sandbox has been disposed.`)},a=()=>{if(i(),n!==`running`)throw Error(`${t} sandbox is not running.`)},o=e=>{let t={process:e,waitPromise:e.wait().finally(()=>{r.delete(t)})};return r.add(t),{...e,wait:()=>t.waitPromise}},s=async()=>{let e=Array.from(r,e=>(e.process.kill(`SIGKILL`),e.waitPromise));await Promise.allSettled(e)},c=e.createSpawner(a,o),l={type:e.type,config:e.config,get status(){return n},get workdir(){return e.config.workdir},get spawner(){return c},async start(){i(),n!==`running`&&(await e.onValidate(),n=`running`)},async stop(){i(),n===`running`&&(n=`stopped`,await s())},async dispose(){n!==`disposed`&&(n=`disposed`,await s(),await e.onDispose?.())},[Symbol.asyncDispose](){return l.dispose()}};return e.extend?e.extend(l):l},b=`bwrap`,x=[`/tmp`],S=f(o),C=(e,t)=>e.binds?.some(e=>e.target===t)??!1,w=(e,t)=>{let n=u.relative(e,t);return n===``||!n.startsWith(`..`)&&!u.isAbsolute(n)},T=(e,t)=>e.target.length-t.target.length,te=e=>{let t=C(e,e.workdir)?[...e.binds??[]]:[{source:e.workdir,target:e.workdir},...e.binds??[]],n=e.tmpfs??x,r=t.filter(e=>!n.some(t=>w(t,e.target))).toSorted(T),i=t.filter(e=>n.some(t=>w(t,e.target))).toSorted(T);return[...r,...i]},ne=e=>{let t=[`--ro-bind`,`/`,`/`];for(let n of te(e))t.push(n.readonly?`--ro-bind`:`--bind`,n.source,n.target);return t},re=(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},ie=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},ae=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??x)t.push(`--tmpfs`,n);t.push(...ne(e).slice(3));for(let n of e.remountReadonly??[])t.push(`--remount-ro`,n);return t},E=(e,t,n,r={})=>[...ie(e),...ae(e),...re(e,r),`--chdir`,r.cwd??e.workdir,...e.args??[],`--`,t,...n],D=async t=>{try{await S(t,[`--version`],{env:r(),encoding:`utf8`})}catch(t){throw Error(`Bubblewrap start failed: ${e(t)}`)}},O=(e,t,n,i)=>({spawn(a,o,s={}){return t(),n(i.spawn(e.binary??b,E(e,a,o,s),{env:r(),stdio:s.stdio}))}}),k=async(e,t=i)=>y({type:`bubblewrap`,config:e,onValidate:()=>D(e.binary??b),createSpawner:(n,r)=>O(e,n,r,t)}),A=e=>new Set((e??[]).flatMap(e=>[e,e.toUpperCase(),e.toLowerCase()])),j=(e,t)=>{let n=A(t);return n.size===0?e:Object.fromEntries(Object.entries(e).filter(([e])=>!n.has(e)))},M=e=>{try{return p(e,m.X_OK),!0}catch{return!1}},N=(e,t)=>c(e)?e:d(t,e),P=(e,t,r)=>{if(c(e)||e.includes(`/`))return e;let i=t[n(t)];if(!i)return e;for(let t of i.split(s)){let n=l(N(t,r),e);if(M(n))return n}return e},F=(e,r)=>{if((r??[]).some(e=>e.toLowerCase()===`path`))return;let i=n(e);if(i in e)return;let a=t(),o=a[n(a)];o&&Object.assign(e,{[i]:o})},I=[`/run/wrappers/bin`,`/usr/local/bin`,`/usr/bin`,`/bin`],L=f(o),R=e=>e.binary??`firejail`,z=()=>{let e=t();return e[n(e)]},B=e=>{if(e.clearEnv===!1)return r({extraPaths:I});let t=r({propagateEnv:!1,extraPaths:I}),i=z();return i&&(t[n(t)]=[...I,i].filter(Boolean).join(s)),t},V=(e,t,n)=>{let r=j({...n,...e.setEnv,...t.env},e.unsetEnv);return F(r,e.unsetEnv),r},H=(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},U=(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(...H(e,r,i)),e.args?.length&&a.push(...e.args),a.push(`--`,t,...n),a},W=async t=>{try{await L(t,[`--version`],{env:r({extraPaths:I}),encoding:`utf8`})}catch(t){throw Error(`Firejail start failed: ${e(t)}`)}},G=(e,t,n,r)=>({spawn(i,o,s={}){t();let c=s.cwd??e.workdir,l=B(e),u=`exec ${[P(i,V(e,s,l),c),...o].map(a).join(` `)}`;return n(r.spawn(R(e),U(e,`sh`,[`-c`,u],s,l),{cwd:c,env:l,stdio:s.stdio}))}}),oe=async(e,t=i)=>y({type:`firejail`,config:e,onValidate:()=>W(R(e)),createSpawner:(n,r)=>G(e,n,r,t)}),K=`nsjail`,q=[`/tmp`],se=f(o),J=e=>JSON.stringify(e),Y=(e,t)=>e.target.length-t.target.length||Number(!!e.readonly)-Number(!!t.readonly),ce=(e,t)=>e.binds?.some(e=>e.target===t)??!1,X=e=>e.tmpfs??[...q],le=(e,t)=>X(e).includes(t),ue=e=>{let t=ce(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=>!le(e,t.target)).toSorted(Y)},de=e=>X(e).map(t=>({target:t,readonly:e.readOnly?.includes(t),type:`tmpfs`})).toSorted(Y),fe=e=>[{source:`/`,target:`/`,readonly:!0,type:`bind`},...de(e),...ue(e)],Z=(e,t)=>{let n=j(e.clearEnv===!1?r():r({propagateEnv:!1}),e.unsetEnv);return Object.assign(n,e.setEnv,t.env),F(n,e.unsetEnv),n},Q=(e,t,n)=>[`${e} {`,` inside_id: ${J(String(t))}`,` outside_id: ${J(String(n))}`,` count: 1`,`}`].join(`
|
|
2
|
+
`),pe=e=>{if(e!==void 0)try{return g(e)}catch{return e}},$=e=>{let t=[`mount {`],n=pe(e.source);return n!==void 0&&t.push(` src: ${J(n)}`),t.push(` dst: ${J(e.target)}`),e.type===`tmpfs`?t.push(` fstype: ${J(`tmpfs`)}`):t.push(` is_bind: true`),t.push(` rw: ${e.readonly?`false`:`true`}`),t.push(` mandatory: true`),t.push(`}`),t.join(`
|
|
3
|
+
`)},me=(e,t,n)=>{let r=t.cwd??e.workdir,i=n??Z(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: ${J(a)}`,`cwd: ${J(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)}`,Q(`uidmap`,c,o),Q(`gidmap`,l,s)];e.seccompString&&d.push(`seccomp_string: ${J(e.seccompString)}`);for(let[e,t]of Object.entries(i)){let n=`${e}=${t}`;d.push(`envar: ${J(n)}`)}for(let t of fe(e))d.push($(t));return`${d.join(`
|
|
4
|
+
`)}\n`},he=(e,t,n,r)=>{let i=[`-C`,t];return(e.disableRlimits??!0)&&i.push(`--disable_rlimits`),i.push(...e.args??[],`--`,n,...r),i},ge=async t=>{try{await se(t,[`--help`],{env:r(),encoding:`utf8`})}catch(t){throw Error(`Nsjail start failed: ${e(t)}`)}},_e=(e,t,n,i,a)=>({spawn(o,s,c={}){n();let u=t(),d=Z(e,c),f=P(o,d,c.cwd??e.workdir),p=l(u.configDir,`spawn-${Date.now()}-${Math.random().toString(16).slice(2)}.cfg`);v(p,me(e,c,d),{encoding:`utf8`,mode:384});try{let t=i(a.spawn(e.binary??K,he(e,p,f,s),{env:r(),stdio:c.stdio})),n=t.wait().finally(()=>{_(p,{force:!0})});return{...t,wait:()=>n}}catch(e){throw _(p,{force:!0}),e}}}),ve=async(e,t=i)=>{let n,r=()=>{if(!n)throw Error(`Nsjail sandbox has not been started.`);return n};return y({type:`nsjail`,config:e,async onValidate(){await ge(e.binary??K),n??={configDir:h(l(ee(),`cw-nsjail-`))}},onDispose(){n&&_(n.configDir,{recursive:!0,force:!0})},createSpawner:(n,i)=>_e(e,r,n,i,t)})};async function ye(e){switch(e.type){case`bubblewrap`:return k(e);case`firejail`:return oe(e);case`nsjail`:return ve(e);default:throw Error(`Unsupported sandbox type.`)}}export{ye as t};
|
package/dist/schemas/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { C as OutputSchema, D as imageContentPartSchema, E as contentPartSchema, O as textContentPartSchema, S as McpServerConfig, T as agentCapabilitiesSchema, _ as toolResultEventSchema, a as SessionStartEvent, b as ImageContentPart, c as ToolResultEvent, d as messageEventSchema, f as reasoningEventSchema, g as toolCallEventSchema, h as stderrEventSchema, i as SessionEndEvent, l as baseEventSchema, m as sessionStartEventSchema, n as MessageEvent, o as StderrEvent, p as sessionEndEventSchema, r as ReasoningEvent, s as ToolCallEvent, t as AgentEvent, u as eventSchema, v as AgentCapabilities, w as TextContentPart, x as JsonSchema, y as ContentPart } from "../events-
|
|
1
|
+
import { C as OutputSchema, D as imageContentPartSchema, E as contentPartSchema, O as textContentPartSchema, S as McpServerConfig, T as agentCapabilitiesSchema, _ as toolResultEventSchema, a as SessionStartEvent, b as ImageContentPart, c as ToolResultEvent, d as messageEventSchema, f as reasoningEventSchema, g as toolCallEventSchema, h as stderrEventSchema, i as SessionEndEvent, l as baseEventSchema, m as sessionStartEventSchema, n as MessageEvent, o as StderrEvent, p as sessionEndEventSchema, r as ReasoningEvent, s as ToolCallEvent, t as AgentEvent, u as eventSchema, v as AgentCapabilities, w as TextContentPart, x as JsonSchema, y as ContentPart } from "../events-D86KNGqO.mjs";
|
|
2
2
|
export { type AgentCapabilities, type AgentEvent, type ContentPart, type ImageContentPart, type JsonSchema, type McpServerConfig, type MessageEvent, type OutputSchema, type ReasoningEvent, type SessionEndEvent, type SessionStartEvent, type StderrEvent, type TextContentPart, type ToolCallEvent, type ToolResultEvent, agentCapabilitiesSchema, baseEventSchema, contentPartSchema, eventSchema, imageContentPartSchema, messageEventSchema, reasoningEventSchema, sessionEndEventSchema, sessionStartEventSchema, stderrEventSchema, textContentPartSchema, toolCallEventSchema, toolResultEventSchema };
|
package/dist/schemas/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as e,c as t,d as n,f as r,i,l as a,n as o,o as s,p as c,r as l,s as u,t as d,u as f}from"../schemas-
|
|
1
|
+
import{a as e,c as t,d as n,f as r,i,l as a,n as o,o as s,p as c,r as l,s as u,t as d,u as f}from"../schemas-CXVWDOoT.mjs";export{f as agentCapabilitiesSchema,d as baseEventSchema,n as contentPartSchema,o as eventSchema,r as imageContentPartSchema,l as messageEventSchema,i as reasoningEventSchema,e as sessionEndEventSchema,s as sessionStartEventSchema,u as stderrEventSchema,c as textContentPartSchema,t as toolCallEventSchema,a as toolResultEventSchema};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=e=>`'${e.replace(/'/g,`'\\''`)}'`;export{e as t};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as AgentEvent, v as AgentCapabilities, x as JsonSchema, y as ContentPart } from "./events-
|
|
1
|
+
import { t as AgentEvent, v as AgentCapabilities, x as JsonSchema, y as ContentPart } from "./events-D86KNGqO.mjs";
|
|
2
2
|
import { ZodType } from "zod/v4";
|
|
3
3
|
|
|
4
4
|
//#region src/core/process/types.d.ts
|
|
@@ -28,7 +28,7 @@ interface ProcessSpawner {
|
|
|
28
28
|
}
|
|
29
29
|
//#endregion
|
|
30
30
|
//#region src/core/agent/types.d.ts
|
|
31
|
-
type AgentType = "claude-code-cli" | "claude-code-sdk" | "codex-cli" | "codex-sdk" | "gemini-cli";
|
|
31
|
+
type AgentType = "claude-code-cli" | "claude-code-sdk" | "codex-cli" | "codex-sdk" | "droid-cli" | "gemini-cli" | "opencode-cli" | "pi-cli";
|
|
32
32
|
type RunStatus = "cancelled" | "completed" | "failed";
|
|
33
33
|
type StopReason = "abort" | "timeout" | "user";
|
|
34
34
|
interface RunStats {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "coding-agents-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"types": "./dist/index.d.mts",
|
|
6
6
|
"exports": {
|
|
@@ -36,10 +36,22 @@
|
|
|
36
36
|
"types": "./dist/adapters/codex-sdk/index.d.mts",
|
|
37
37
|
"default": "./dist/adapters/codex-sdk/index.mjs"
|
|
38
38
|
},
|
|
39
|
+
"./adapters/droid-cli": {
|
|
40
|
+
"types": "./dist/adapters/droid-cli/index.d.mts",
|
|
41
|
+
"default": "./dist/adapters/droid-cli/index.mjs"
|
|
42
|
+
},
|
|
39
43
|
"./adapters/gemini-cli": {
|
|
40
44
|
"types": "./dist/adapters/gemini-cli/index.d.mts",
|
|
41
45
|
"default": "./dist/adapters/gemini-cli/index.mjs"
|
|
42
46
|
},
|
|
47
|
+
"./adapters/opencode-cli": {
|
|
48
|
+
"types": "./dist/adapters/opencode-cli/index.d.mts",
|
|
49
|
+
"default": "./dist/adapters/opencode-cli/index.mjs"
|
|
50
|
+
},
|
|
51
|
+
"./adapters/pi-cli": {
|
|
52
|
+
"types": "./dist/adapters/pi-cli/index.d.mts",
|
|
53
|
+
"default": "./dist/adapters/pi-cli/index.mjs"
|
|
54
|
+
},
|
|
43
55
|
"./package.json": "./package.json"
|
|
44
56
|
},
|
|
45
57
|
"files": [
|
|
@@ -48,7 +60,7 @@
|
|
|
48
60
|
],
|
|
49
61
|
"sideEffects": false,
|
|
50
62
|
"scripts": {
|
|
51
|
-
"build": "tsdown && bun run test:package",
|
|
63
|
+
"build": "bun run typecheck && tsdown && bun run test:package",
|
|
52
64
|
"start": "bun run examples/claude-code-cli/simple.ts",
|
|
53
65
|
"test": "bun test",
|
|
54
66
|
"test:agent": "bun test ./tests",
|
|
@@ -58,13 +70,16 @@
|
|
|
58
70
|
"test:agent:claude-code-sdk": "CODE_WORKFLOW_TEST_AGENTS=claude-code-sdk bun run test:agent",
|
|
59
71
|
"test:agent:codex-cli": "CODE_WORKFLOW_TEST_AGENTS=codex-cli bun run test:agent",
|
|
60
72
|
"test:agent:codex-sdk": "CODE_WORKFLOW_TEST_AGENTS=codex-sdk bun run test:agent",
|
|
73
|
+
"test:agent:droid-cli": "CODE_WORKFLOW_TEST_AGENTS=droid-cli bun run test:agent",
|
|
61
74
|
"test:agent:gemini-cli": "CODE_WORKFLOW_TEST_AGENTS=gemini-cli bun run test:agent",
|
|
75
|
+
"test:agent:opencode-cli": "CODE_WORKFLOW_TEST_AGENTS=opencode-cli bun run test:agent",
|
|
76
|
+
"test:agent:pi-cli": "CODE_WORKFLOW_TEST_AGENTS=pi-cli bun run test:agent",
|
|
62
77
|
"knip": "knip",
|
|
63
78
|
"tsc": "tsc --noEmit --pretty",
|
|
64
79
|
"typecheck": "bun run tsc"
|
|
65
80
|
},
|
|
66
81
|
"devDependencies": {
|
|
67
|
-
"@anthropic-ai/claude-agent-sdk": "
|
|
82
|
+
"@anthropic-ai/claude-agent-sdk": "0.2.74",
|
|
68
83
|
"@openai/codex-sdk": "^0.114.0",
|
|
69
84
|
"@types/bun": "latest",
|
|
70
85
|
"@types/node": "^25.5.0",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{n as e,t}from"./classify-error-V6x6jP_R.mjs";var n=class extends e{currentAbortController;cleanupSdkResources(){}onStopRequested(e){this.currentAbortController?.abort()}async executeRunCore(e,n){let r=new AbortController;this.currentAbortController=r;let i=this.setupRunLifecycle(e);try{return i.abortedBeforeStart||e.stopReason?this.buildResult(e,new Date):(this.emitSessionStart(e),await this.executeSdkRun(e,n,r),this.buildResult(e,new Date))}catch(n){return!e.stopReason&&!e.error&&(e.error=t(n)),this.buildResult(e,new Date)}finally{i.cleanup();try{await this.cleanupSdkResources()}catch{}this.currentAbortController===r&&(this.currentAbortController=void 0)}}};export{n as t};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{t as e}from"./util-CGg8cK92.mjs";import{n as t,o as n,r,s as i,t as a}from"./errors-XV0frS3r.mjs";import{n as o,r as s}from"./diff-BCfLDXNN.mjs";import{basename as c,dirname as l,join as u,posix as d}from"node:path";import{mkdir as f,readFile as p,readdir as m,stat as h,writeFile as g}from"node:fs/promises";import{CommandExitError as _,FileType as v,Sandbox as y}from"e2b";const b=(e,t)=>[e,...t].map(s).join(` `),x=e=>e.user,S=(e,t)=>{let n={...e.env,...t};return Object.keys(n).length>0?n:void 0},C=(e,t)=>t??e.workdir,w=new TextEncoder,T=e=>e instanceof Error?e:Error(String(e)),E=e=>typeof e==`string`?e:`SIGKILL`,D=(e,t)=>{let n=e?.stdio?.[t];return n===`ignore`||n===`inherit`||n===`pipe`?n:n===void 0?`pipe`:`ignore`},O=()=>{let e=[],t=[],n=!1,r,i=()=>{for(;t.length>0&&e.length>0;)t.shift().resolve({done:!1,value:e.shift()});if(r){for(;t.length>0;)t.shift().reject(r);return}if(n)for(;t.length>0;)t.shift().resolve({done:!0,value:void 0})};return{iterable:{async*[Symbol.asyncIterator](){for(;;){if(e.length>0){yield e.shift();continue}if(r)throw T(r);if(n)return;let i=await new Promise((e,n)=>{t.push({resolve:e,reject:n})});if(i.done)return;yield i.value}}},push(t){t.length===0||n||r||(e.push(w.encode(t)),i())},end(){n||r||(n=!0,i())},fail(e){n||r||(r=e,i())}}},k=(e,t)=>({spawn:(n,r,i={})=>{let a=D(i,0),o=D(i,1),s=D(i,2),c=o===`pipe`?O():void 0,l=s===`pipe`?O():void 0,u=null,d={background:!0,stdin:a===`pipe`,cwd:C(t,i.cwd),envs:S(t,i.env),user:x(t),requestTimeoutMs:t.requestTimeoutMs,onStdout:e=>{if(o===`inherit`){process.stdout.write(e);return}c?.push(e)},onStderr:e=>{if(s===`inherit`){process.stderr.write(e);return}l?.push(e)}},f=e.commands.run(b(n,r),d);return f.catch(e=>{c?.fail(e),l?.fail(e)}),{stdout:c?.iterable??null,stderr:l?.iterable??null,stdin:a===`pipe`?{write:n=>{f.then(r=>{e.commands.sendStdin(r.pid,n,{requestTimeoutMs:t.requestTimeoutMs})}).catch(()=>{})},end:()=>{f.then(n=>{e.commands.closeStdin(n.pid,{requestTimeoutMs:t.requestTimeoutMs})}).catch(()=>{})}}:null,kill:e=>{u=E(e),f.then(e=>e.kill()).catch(()=>{})},wait:async()=>{try{let e=await(await f).wait();return c?.end(),l?.end(),u?{exitCode:null,signal:u}:{exitCode:e.exitCode,signal:null}}catch(e){if(c?.end(),l?.end(),e instanceof _)return u?{exitCode:null,signal:u}:{exitCode:e.exitCode,signal:null};throw e}}}}}),A=e=>({apiKey:e.apiKey,accessToken:e.accessToken,domain:e.domain,requestTimeoutMs:e.requestTimeoutMs,headers:e.headers}),j=e=>`sandboxId`in e&&typeof e.sandboxId==`string`,M=e=>{let t=A(e);return j(e)?t:{...t,envs:e.env,timeoutMs:e.timeoutMs,metadata:e.metadata,secure:e.secure,allowInternetAccess:e.allowInternetAccess,network:e.network,lifecycle:e.lifecycle}},N=async(e,t)=>{await e.files.makeDir(t.workdir,{user:x(t)})},P=e=>e instanceof Error&&e.name===`AbortError`,F=e=>Uint8Array.from(e).buffer,I=e=>{let t=e.endsWith(`/`)&&e!==`/`?e.slice(0,-1):e;return d.basename(t)},L=async e=>{try{return await h(e)}catch(e){if(e instanceof Error&&`code`in e&&e.code===`ENOENT`)return;throw e}},R=async(e,t,n)=>{if(await e.files.exists(t,{user:n}))return e.files.getInfo(t,{user:n})},z=async(e,t,n,r)=>(await R(e,n,r))?.type===v.DIR?d.join(n,c(t)):n,B=async(e,t)=>(await L(t))?.isDirectory()?u(t,I(e)):t,V=async(e,t,n,r)=>{let i=await h(t);if(i.isDirectory()){await e.files.makeDir(n,{user:r});let i=await m(t);await Promise.all(i.map(i=>V(e,u(t,i),d.join(n,i),r)));return}if(!i.isFile())throw Error(`Unsupported local filesystem entry at ${t}.`);let a=await p(t);await e.files.write(n,F(a),{user:r})},H=async(e,t,n,r)=>{if((await e.files.getInfo(t,{user:r})).type===v.DIR){await f(n,{recursive:!0});let i=await e.files.list(t,{user:r});await Promise.all(i.map(t=>H(e,t.path,u(n,t.name),r)));return}let i=await e.files.read(t,{format:`bytes`,user:r});await f(l(n),{recursive:!0}),await g(n,i)},U=async e=>{if(j(e))return y.connect(e.sandboxId,A(e));let t=M(e);return e.template?y.create(e.template,t):y.create(t)},W=async(e,t)=>e.connect(A(t)),G=async(e,t)=>{let n=t.signal;if(n?.aborted){let e=n.reason;throw e instanceof Error?e:new DOMException(`The operation was aborted.`,`AbortError`)}let r=!1,i=()=>{r=!0,e.kill()};n?.addEventListener(`abort`,i,{once:!0});try{let t=await e.wait();if(r)throw new DOMException(`The operation was aborted.`,`AbortError`);return{exitCode:t.exitCode,stdout:t.stdout,stderr:t.stderr}}catch(e){if(r||P(e))throw new DOMException(`The operation was aborted.`,`AbortError`);if(e instanceof _)return{exitCode:e.exitCode,stdout:e.stdout,stderr:e.stderr};throw e}finally{n?.removeEventListener(`abort`,i)}},K=async s=>{let c;try{c=await U(s),await N(c,s)}catch(t){throw new a(`E2B create failed: ${e(t)}`)}let l=s.name??c.sandboxId,d=`running`,p=k(c,s),m={},h=()=>{if(d===`disposed`)throw new r},g=()=>{if(h(),d!==`running`)throw new n},_=o({owner:m,workdir:s.workdir,materialize:async(e,n)=>{g();let r=x(s),i=await R(c,e,r);if(!i)throw new t(`Target path does not exist: ${e}`);if(i.type!==v.DIR)throw new t(`Target path is not a directory: ${e}`);await f(n,{recursive:!0});for(let t of await c.files.list(e,{user:r}))await H(c,t.path,u(n,t.name),r)}}),y={get type(){return`e2b`},get id(){return c.sandboxId},get name(){return l},get config(){return s},get status(){return d},get workdir(){return s.workdir},get spawner(){return p},async start(){if(h(),d!==`running`)try{c=await W(c,s),await N(c,s),p=k(c,s),d=`running`}catch(t){throw new i(`E2B start failed: ${e(t)}`)}},async stop(){h(),d===`running`&&(await c.pause({requestTimeoutMs:s.requestTimeoutMs}),d=`stopped`)},async dispose(){if(d!==`disposed`){try{await c.kill({requestTimeoutMs:s.requestTimeoutMs})}catch{}await _.disposeSnapshots().catch(()=>{}),d=`disposed`}},async exec(e,t,n={}){g();let r={background:!0,cwd:C(s,n.cwd),envs:S(s,n.env),user:x(s),timeoutMs:n.timeoutMs,requestTimeoutMs:s.requestTimeoutMs};return G(await c.commands.run(b(e,t),r),n)},async copyTo(e,t){g();let n=await z(c,e,t,x(s));await V(c,e,n,x(s))},async copyFrom(e,t){g();let n=await B(e,t);await H(c,e,n,x(s))},async writeFile(e,t){g(),await c.files.write(e,typeof t==`string`?t:F(t),{user:x(s)})},async readFile(e){return g(),c.files.read(e,{format:`text`,user:x(s)})},async fileExists(e){return g(),c.files.exists(e,{user:x(s)})},async mkdir(e){g(),await c.files.makeDir(e,{user:x(s)})},async execShell(e,t={}){return y.exec(`sh`,[`-c`,e],t)},async logs(){return``},async syncStatus(){return d},async snapshotWorkdir(e={}){return _.snapshotWorkdir(e)},async diffWorkdir(e){return _.diffWorkdir(e)},async releaseWorkdirSnapshot(e){return _.releaseWorkdirSnapshot(e)},getHost(e){return g(),c.getHost(e)},[Symbol.asyncDispose](){return y.dispose()}};return y};export{K as createE2BContainer};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{n as e,t}from"./oci-C_S_FKHj.mjs";const n=async n=>{let r=n.binary??`docker`,i=await e(r,n);return t(`docker`,{binary:r,containerName:n.name,workdir:n.workdir,user:n.user,network:n.network,platform:n.platform,env:n.env,ports:n.ports,mounts:n.mounts,extraArgs:n.extraArgs,image:i,builtImage:n.build!==void 0&&!n.build.tag},n)};export{n as createDockerContainer};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{n as e,t}from"./oci-C_S_FKHj.mjs";const n=async n=>{let r=n.binary??`podman`,i=await e(r,n);return t(`podman`,{binary:r,containerName:n.name,workdir:n.workdir,user:n.user,network:n.network,platform:n.platform,env:n.env,ports:n.ports,mounts:n.mounts,extraArgs:n.extraArgs,image:i,builtImage:n.build!==void 0&&!n.build.tag},n)};export{n as createPodmanContainer};
|
package/dist/diff-BCfLDXNN.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{t as e}from"./util-CGg8cK92.mjs";import{n as t,o as n,r}from"./errors-XV0frS3r.mjs";import{execFile as i}from"node:child_process";import{dirname as a,isAbsolute as o,join as s,posix as c,relative as l,sep as u}from"node:path";import{promisify as d}from"node:util";import{createReadStream as f}from"node:fs";import{copyFile as p,lstat as m,mkdir as h,mkdtemp as g,readdir as _,readlink as v,rm as y,stat as b,symlink as x}from"node:fs/promises";import{tmpdir as S}from"node:os";import{createHash as C}from"node:crypto";import{pipeline as w}from"node:stream/promises";const T=e=>e instanceof Error&&`code`in e&&(`stdout`in e||`stderr`in e),E=e=>`'${e.replace(/'/g,`'\\''`)}'`,D=d(i),O=e=>e!==`..`&&!e.startsWith(`..${u}`)&&!o(e),k=(e,t)=>{let n=l(e,t);if(O(n))return n.split(u).join(c.sep)},A=(e,n,r)=>{let i=k(n,e);if(i!==void 0)return i;let a=k(r,e);if(a!==void 0)return a;throw new t(`Git diff produced a path outside the materialized trees: ${e}`)},j=e=>e.sort((e,t)=>e.path===t.path?(e.previousPath??``).localeCompare(t.previousPath??``):e.path.localeCompare(t.path)),M=async e=>{let t=await _(e,{withFileTypes:!0});for(let n of t){let t=s(e,n.name);if(n.name===`.git`){await y(t,{recursive:!0,force:!0});continue}n.isDirectory()&&await M(t)}},N=()=>g(s(S(),`cw-workdir-diff-`)),P=async e=>{e&&await y(e,{recursive:!0,force:!0}).catch(()=>{})},F=(e,t)=>{let n={cwd:e.cwd,createdAt:new Date};return t.set(n,e),n},I=(e,n,r)=>{if(typeof n!=`object`||!n)throw new t(`Invalid workdir snapshot.`);let i=r.get(n);if(!i)throw new t(`Invalid workdir snapshot.`);if(i.owner!==e)throw new t(`Workdir snapshot was created by a different container instance.`);return i},L=(e,n)=>{if(!n.has(e))throw new t(`Workdir snapshot has been released.`)},R=e=>C(`sha256`).update(e).digest(`hex`),z=e=>Buffer.isBuffer(e)?e:Buffer.from(e,`utf8`),B=async e=>{let t=C(`sha256`);return await w(f(e),t),t.digest(`hex`)},V=async(e,n,r)=>{let i=`${e}:${n}`;if(r.has(i))return r.get(i);let a=s(e,...n.split(c.sep));try{let e=await m(a),n,o;if(e.isSymbolicLink()){let e=Buffer.from(await v(a));n=R(e),o=e.byteLength}else if(e.isFile())n=await B(a),o=e.size;else throw new t(`Unsupported filesystem entry in diff metadata: ${a}`);let s={hash:n,size:o};return r.set(i,s),s}catch(e){if(e instanceof Error&&`code`in e&&e.code===`ENOENT`){r.set(i,void 0);return}throw e}},H=(e,n,r)=>{if(e.byteLength===0)return[];let i=e.toString(`utf8`).split(`\0`);i[i.length-1]===``&&i.pop();let a=[];for(let e=0;e<i.length;){let o=i[e++];if(!o)continue;if(o.startsWith(`R`)){let o=i[e++],s=i[e++];if(!o||!s)throw new t(`Failed to parse git rename entry.`);a.push({kind:`renamed`,previousPath:A(o,n,r),path:A(s,n,r)});continue}let s=i[e++];if(!s)throw new t(`Failed to parse git diff entry.`);switch(o){case`A`:a.push({kind:`added`,path:A(s,n,r)});break;case`D`:a.push({kind:`deleted`,path:A(s,n,r)});break;case`M`:a.push({kind:`modified`,path:A(s,n,r)});break;case`T`:a.push({kind:`modified`,path:A(s,n,r)});break;default:throw new t(`Unsupported git diff change kind: ${o}`)}}return a},U=async(n,r)=>{try{return H(z((await D(`git`,[`diff`,`--no-index`,`-z`,`--name-status`,`-M`,`--find-renames=100%`,n,r],{cwd:S(),encoding:`buffer`,maxBuffer:50*1024*1024})).stdout),n,r)}catch(i){if(!T(i))throw new t(`Failed to run git diff: ${e(i)}`);let a=i.code??1,o=Buffer.isBuffer(i.stdout)?i.stdout:Buffer.from(String(i.stdout??``),`utf8`),s=Buffer.isBuffer(i.stderr)?i.stderr:Buffer.from(String(i.stderr??``),`utf8`);if(a===0||a===1)return H(o,n,r);throw new t(`Failed to run git diff: ${s.toString(`utf8`).trim()||o.toString(`utf8`).trim()||`exit code ${a}`}`)}},W=async(e,t,n)=>{let r=new Map;return j(await Promise.all(e.map(async e=>{let i;i=e.kind===`added`?void 0:e.kind===`renamed`?e.previousPath:e.path;let a=e.kind===`deleted`?void 0:e.path,[o,s]=await Promise.all([i===void 0?void 0:V(t,i,r),a===void 0?void 0:V(n,a,r)]);return{path:e.path,previousPath:e.previousPath,kind:e.kind,beforeHash:o?.hash,afterHash:s?.hash,beforeSize:o?.size,afterSize:s?.size}})))},G=e=>{let t=new Set;for(let n of e)t.add(n.path),n.kind===`renamed`&&n.previousPath&&t.add(n.previousPath);return[...t].sort((e,t)=>e.localeCompare(t))},K=(i,a)=>{throw a instanceof t||a instanceof r||a instanceof n?a:new t(`${i}: ${e(a)}`)},q=async(e,n)=>{if(!(await b(e)).isDirectory())throw new t(`Target path is not a directory: ${e}`);await h(n,{recursive:!0});let r=await _(e,{withFileTypes:!0});await Promise.all(r.filter(e=>e.name!==`.git`).map(async r=>{let i=s(e,r.name),o=s(n,r.name);if(r.isDirectory()){await q(i,o);return}if(r.isSymbolicLink()){await h(a(o),{recursive:!0}),await x(await v(i),o);return}if(r.isFile()){await h(a(o),{recursive:!0}),await p(i,o);return}throw new t(`Unsupported filesystem entry in workdir diff: ${i}`)}))},J=e=>{let t=new Set,n=new WeakMap,r=async(r={})=>{let i=r.cwd??e.workdir,a;try{a=await N(),await e.materialize(i,a),await M(a);let r={owner:e.owner,tempDir:a,cwd:i,inFlightDiffs:0,released:!1};return t.add(r),a=void 0,F(r,n)}catch(e){return await P(a),K(`Failed to materialize workdir snapshot`,e)}},i=async r=>{let i=Date.now(),a=I(e.owner,r,n);L(a,t),a.inFlightDiffs++;let o;try{o=await N(),await e.materialize(a.cwd,o),await M(o);let t=await W(await U(a.tempDir,o),a.tempDir,o),n=G(t);return{cwd:a.cwd,changedFiles:n,fileChanges:t,stats:{durationMs:Date.now()-i,filesCompared:n.length}}}catch(e){return K(`Failed to diff workdir snapshot`,e)}finally{a.inFlightDiffs--,a.inFlightDiffs===0&&(a.resolveIdle?.(),a.resolveIdle=void 0),await P(o)}},a=e=>{let n=e;return n.releasePromise?n.releasePromise:(n.released=!0,t.delete(n),n.releasePromise=(async()=>{n.inFlightDiffs>0&&await new Promise(e=>{n.resolveIdle=e}),await P(n.tempDir)})(),n.releasePromise)};return{snapshotWorkdir:r,diffWorkdir:i,releaseWorkdirSnapshot:async t=>{await a(I(e.owner,t,n))},disposeSnapshots:async()=>{await Promise.all(Array.from(t).map(a))}}};export{T as i,J as n,E as r,q as t};
|
package/dist/env-Dkd8Sgjf.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{delimiter as e}from"node:path";const t=e=>Object.keys(e).find(e=>e.toLowerCase()===`path`)??`PATH`,n=(n={})=>{let r=n.propagateEnv===!1?{}:Object.fromEntries(Object.entries(process.env).filter(e=>e[1]!==void 0)),i=n.extraPaths??[];if(i.length>0){let n=t(r),a=r[n]??``;r[n]=[...i,a].filter(Boolean).join(e)}return r};export{n as t};
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import{n as e}from"./types-CwvWHEpy.mjs";import{t}from"./util-CGg8cK92.mjs";import{t as n}from"./env-Dkd8Sgjf.mjs";import{t as r}from"./spawner-BJesLc8I.mjs";import{a as i,i as a,n as o,t as s}from"./classify-error-V6x6jP_R.mjs";import{dirname as c}from"node:path";import{createWriteStream as l,mkdirSync as u}from"node:fs";async function*d(e){let t=new TextDecoder,n=``;for await(let r of e){let e=t.decode(r,{stream:!0});n+=e;let i=n.split(`
|
|
2
|
-
`);n=i.pop()??``;for(let e of i){let t=e.trim();t&&(yield t)}}let r=t.decode();r&&(n+=r);let i=n.trim();i&&(yield i)}const f=e=>e.status===`rejected`?t(e.reason):void 0,p=(e,t)=>{if(e.stopReason)return;let n=f(t.stdoutResult);if(n)return{kind:`process`,message:n};let r=f(t.stderrResult);if(r)return{kind:`process`,message:r};let i=f(t.processResult);if(i)return{kind:`spawn`,message:i};if(!e.status&&!e.error){let t=e.processResult,n=e.stderrLines.join(`
|
|
3
|
-
`);if(t&&t.exitCode!==null&&t.exitCode!==0)return{kind:`process`,message:n||`Process exited with code ${t.exitCode}.`};if(!a(e)&&e.stderrLines.length>0)return{kind:`process`,message:n}}},m=e=>{let t=s(e);return t.kind===`provider`?{kind:`process`,message:t.message}:t};var h=class extends o{spawner;defaults;executionTargetRef;autoStartExecutionTarget;autoStopExecutionTarget;executionTargetStopPromise;logStream;sigkillTimer;constructor(e){super({type:e.type,capabilities:e.capabilities,sessionId:e.defaults?.sessionId,onEvent:e.onEvent}),this.spawner=e.spawner??r,this.defaults=e.defaults??{},this.executionTargetRef=e.executionTarget,this.autoStartExecutionTarget=e.autoStartExecutionTarget??!0,this.autoStopExecutionTarget=e.autoStopExecutionTarget??!1,e.logPath&&this.initLogStream(e.logPath)}onParseError(e,n){this.appendRawLog(`[parse-error] ${t(n)} ${e.slice(0,200)}`)}buildDefaultEnv(e){let t=n({propagateEnv:e});return t.CI=t.CI??`true`,this.defaults.env&&Object.assign(t,this.defaults.env),t}async executeRunCore(e,n){let r=this.setupRunLifecycle(e);try{if(r.abortedBeforeStart)return this.buildResult(e,new Date);try{await this.onBeforeRun(e);let t={...n,...e.normalizedRequest},r=this.buildArgs(t,e),i=this.buildEnv(t,e),a=this.defaults.command?.[0]??`claude`,o=[...this.defaults.command?.slice(1)??[],...r];if(e.stopReason)return this.buildResult(e,new Date);this.emitSessionStart(e),e.process=this.spawner.spawn(a,o,{cwd:e.normalizedRequest.cwd,env:i,stdio:[`pipe`,`pipe`,`pipe`]}),e.process.stdin?.end();let[s,c,l]=await Promise.allSettled([this.watchStdout(e),this.watchStderr(e),e.process.wait()]);l.status===`fulfilled`&&(e.processResult=l.value);let u=p(e,{stdoutResult:s,stderrResult:c,processResult:l});u&&(e.error=u)}catch(t){!e.stopReason&&!e.error&&(e.error=m(t))}return this.buildResult(e,new Date)}finally{r.cleanup(),this.sigkillTimer&&=(clearTimeout(this.sigkillTimer),void 0);try{await this.onRunFinished(e)}catch(e){this.appendRawLog(`[cleanup-error] ${t(e)}`)}}}async watchStdout(e){let t=e.process?.stdout;if(t)for await(let n of d(t))this.appendLog(`stdout`,n),this.processLine(e,n)}async watchStderr(e){let t=e.process?.stderr;if(t)for await(let n of d(t))this.appendLog(`stderr`,n),e.stderrLines.push(n),this.emit(e,i(e.runId,`stderr`,{sessionId:e.sessionId,text:n}))}processLine(e,t){let n;try{n=JSON.parse(t)}catch(e){this.onParseError(t,e);return}let r;try{r=this.mapRawEvent(n,{runId:e.runId,requestedSessionId:e.requestedSessionId,sessionId:e.sessionId,schemaRequested:e.normalizedRequest.schema.kind!==`none`,toolCalls:e.toolCalls})}catch(e){this.onParseError(t,e);return}this.applyBatch(e,r)}get runRequestDefaults(){return this.defaults}onHandlerError(e){this.appendRawLog(`[handler-error] ${t(e)}`)}async onDispose(){let e=this.logStream;this.logStream=void 0,e&&await new Promise(t=>{e.end(t)})}onStopRequested(e){e.process?.kill(),this.sigkillTimer=setTimeout(()=>{e.process?.kill(`SIGKILL`)},5e3),this.sigkillTimer.unref?.()}onBeforeRun(e){return this.ensureExecutionTarget()}async onRunFinished(e){this.autoStopExecutionTarget&&this.executionTargetRef&&this.executionTargetRef.status===`running`&&(this.executionTargetStopPromise=this.executionTargetRef.stop().catch(e=>{this.appendRawLog(`[auto-stop-error] ${t(e)}`)}),await this.executionTargetStopPromise)}appendRawLog(e){if(!this.logStream)return;let t=typeof e==`string`?e:JSON.stringify(e);this.logStream.write(`${t}\n`)}initLogStream(e){try{u(c(e),{recursive:!0}),this.logStream=l(e,{flags:`a`}),this.logStream.write(`\n--- ${new Date().toISOString()} ---\n`)}catch{this.logStream=void 0}}appendLog(e,t){if(!this.logStream||!t)return;let n=e===`stderr`?`STDERR`:`STDOUT`,r=new Date().toISOString();for(let e of t.split(`
|
|
4
|
-
`))e&&this.logStream.write(`[${r}] ${n} ${e}\n`)}async ensureExecutionTarget(){this.executionTargetStopPromise&&=(await this.executionTargetStopPromise,void 0),this.autoStartExecutionTarget&&this.executionTargetRef&&this.executionTargetRef.status!==`running`&&await this.executionTargetRef.start()}};const g=t=>{if(t){if(t.container&&t.sandbox)throw new e(`Pass either "container" or "sandbox", not both.`);return t.container??t.sandbox}},_=e=>{let t=g(e);return!e||!t?{executionTarget:t,options:e}:{executionTarget:t,options:{...e,cwd:e.cwd??t.workdir,spawner:t.spawner}}};export{h as n,_ as t};
|