agentbox-sdk 0.1.0 → 0.1.3
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 +72 -18
- package/dist/{Sandbox-DTprxRZf.d.ts → Sandbox-CByFJI8X.d.ts} +102 -6
- package/dist/agents/index.d.ts +74 -5
- package/dist/agents/index.js +14 -5
- package/dist/chunk-4MBB6QHD.js +4658 -0
- package/dist/chunk-GOFJNFAD.js +18 -0
- package/dist/{chunk-HMBWQSVN.js → chunk-INMA52FV.js} +83 -23
- package/dist/{chunk-QRQFQTGH.js → chunk-LPKKT6YT.js} +742 -50
- package/dist/chunk-ZOWBRUQR.js +476 -0
- package/dist/cli.js +16 -8
- package/dist/enums.d.ts +25 -0
- package/dist/enums.js +8 -0
- package/dist/events/index.d.ts +86 -2
- package/dist/events/index.js +4 -1
- package/dist/index.d.ts +6 -3
- package/dist/index.js +18 -5
- package/dist/sandboxes/index.d.ts +58 -4
- package/dist/sandboxes/index.js +7 -3
- package/dist/{types-BwcoN0n-.d.ts → types-B3N-Qo2q.d.ts} +147 -6
- package/images/browser-agent.mjs +3 -3
- package/package.json +13 -3
- package/dist/chunk-7FLLQJ6J.js +0 -185
- package/dist/chunk-BW43ESRM.js +0 -4381
- /package/dist/{chunk-JFDP556Q.js → chunk-NSJM57Z4.js} +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
export { A as AISDKEvent, a as AgentApprovalMode, b as
|
|
2
|
-
export { Agent } from './agents/index.js';
|
|
3
|
-
export { A as AsyncCommandHandle, C as CommandEvent, a as CommandOptions, b as CommandResult, D as DaytonaProviderOptions, c as DaytonaSandboxOptions, E as E2bProviderOptions, d as E2bSandboxOptions, G as GitCloneOptions, L as LocalDockerProviderOptions, e as LocalDockerSandboxOptions, M as ModalProviderOptions, f as ModalSandboxOptions, S as Sandbox, g as SandboxDescriptor, h as SandboxListOptions, i as SandboxOptions, j as SandboxOptionsBase, k as SandboxOptionsMap, l as SandboxProviderName, m as SandboxRaw, n as SandboxRawMap, o as SandboxResourceSpec } from './Sandbox-
|
|
1
|
+
export { A as AISDKEvent, a as AgentApprovalMode, b as AgentAttachRequest, c as AgentCommandConfig, d as AgentCostData, e as AgentExecutionRequest, f as AgentLocalMcpConfig, g as AgentMcpConfig, h as AgentOptions, i as AgentOptionsBase, j as AgentOptionsMap, k as AgentPermissionDecision, l as AgentPermissionKind, m as AgentPermissionResponse, n as AgentProviderAdapter, o as AgentProviderName, p as AgentReasoningEffort, q as AgentRemoteMcpConfig, r as AgentResult, s as AgentRun, t as AgentRunConfig, u as AgentRunSink, v as AgentSetupConfig, w as AgentSetupRequest, x as AgentSkillConfig, y as AgentSubAgentConfig, z as AttachedRun, C as ClaudeCodeAgentOptions, B as ClaudeCodeHookConfig, D as ClaudeCodeHookEvent, E as ClaudeCodeHookHandler, F as ClaudeCodeHookMatcherGroup, G as ClaudeCodeHooksConfig, H as ClaudeCodeProviderOptions, I as CodexAgentOptions, J as CodexCommandHook, K as CodexHookEvent, L as CodexHookMatcherGroup, M as CodexHooksConfig, N as CodexProviderOptions, O as DataContent, P as EmbeddedSkillConfig, Q as FilePart, R as ImagePart, S as MessageCompletedEvent, T as MessageInjectedEvent, U as MessageStartedEvent, V as NormalizedAgentEvent, W as NormalizedAgentEventBase, X as NormalizedAgentEventType, Y as OpenCodeAgentOptions, Z as OpenCodePluginConfig, _ as OpenCodePluginEvent, $ as OpenCodePluginHookConfig, a0 as OpenCodeProviderOptions, a1 as PermissionRequestedEvent, a2 as PermissionResolvedEvent, a3 as RawAgentEvent, a4 as ReasoningDeltaEvent, a5 as RepoSkillConfig, a6 as RunCompletedEvent, a7 as RunErrorEvent, a8 as RunStartedEvent, a9 as TextDeltaEvent, aa as TextPart, ab as ToolCallCompletedEvent, ac as ToolCallDeltaEvent, ad as ToolCallStartedEvent, ae as UserContent, af as UserContentPart, ag as createNormalizedEvent, ah as normalizeRawAgentEvent, ai as toAISDKEvent, aj as toAISDKStream } from './types-B3N-Qo2q.js';
|
|
2
|
+
export { AGENT_RESERVED_PORTS, Agent, collectAllAgentReservedPorts } from './agents/index.js';
|
|
3
|
+
export { A as AsyncCommandHandle, C as CommandEvent, a as CommandOptions, b as CommandResult, D as DaytonaProviderOptions, c as DaytonaSandboxOptions, E as E2bProviderOptions, d as E2bSandboxOptions, G as GitCloneOptions, L as LocalDockerProviderOptions, e as LocalDockerSandboxOptions, M as ModalProviderOptions, f as ModalSandboxOptions, S as Sandbox, g as SandboxDescriptor, h as SandboxListOptions, i as SandboxOptions, j as SandboxOptionsBase, k as SandboxOptionsMap, l as SandboxProviderName, m as SandboxRaw, n as SandboxRawMap, o as SandboxResourceSpec, T as TarballEntry, V as VercelGitSource, p as VercelProviderOptions, q as VercelSandboxOptions } from './Sandbox-CByFJI8X.js';
|
|
4
4
|
export { SandboxAdapter, buildGitCloneCommand } from './sandboxes/index.js';
|
|
5
|
+
export { ProviderLogAssembler } from './events/index.js';
|
|
6
|
+
export { AgentProvider, SandboxProvider } from './enums.js';
|
|
5
7
|
import 'e2b';
|
|
8
|
+
import '@vercel/sandbox';
|
|
6
9
|
import '@daytonaio/sdk';
|
|
7
10
|
import 'modal';
|
|
8
11
|
import 'dockerode';
|
package/dist/index.js
CHANGED
|
@@ -1,24 +1,37 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Agent
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-4MBB6QHD.js";
|
|
4
4
|
import {
|
|
5
|
+
ProviderLogAssembler,
|
|
5
6
|
createNormalizedEvent,
|
|
6
7
|
normalizeRawAgentEvent,
|
|
7
8
|
toAISDKEvent,
|
|
8
9
|
toAISDKStream
|
|
9
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-ZOWBRUQR.js";
|
|
10
11
|
import {
|
|
11
12
|
Sandbox,
|
|
12
13
|
SandboxAdapter,
|
|
13
14
|
buildGitCloneCommand
|
|
14
|
-
} from "./chunk-
|
|
15
|
-
import
|
|
16
|
-
|
|
15
|
+
} from "./chunk-LPKKT6YT.js";
|
|
16
|
+
import {
|
|
17
|
+
AGENT_RESERVED_PORTS,
|
|
18
|
+
collectAllAgentReservedPorts
|
|
19
|
+
} from "./chunk-INMA52FV.js";
|
|
20
|
+
import "./chunk-NSJM57Z4.js";
|
|
21
|
+
import {
|
|
22
|
+
AgentProvider,
|
|
23
|
+
SandboxProvider
|
|
24
|
+
} from "./chunk-GOFJNFAD.js";
|
|
17
25
|
export {
|
|
26
|
+
AGENT_RESERVED_PORTS,
|
|
18
27
|
Agent,
|
|
28
|
+
AgentProvider,
|
|
29
|
+
ProviderLogAssembler,
|
|
19
30
|
Sandbox,
|
|
20
31
|
SandboxAdapter,
|
|
32
|
+
SandboxProvider,
|
|
21
33
|
buildGitCloneCommand,
|
|
34
|
+
collectAllAgentReservedPorts,
|
|
22
35
|
createNormalizedEvent,
|
|
23
36
|
normalizeRawAgentEvent,
|
|
24
37
|
toAISDKEvent,
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { l as SandboxProviderName, i as SandboxOptions, a as CommandOptions, b as CommandResult, A as AsyncCommandHandle, h as SandboxListOptions, g as SandboxDescriptor, G as GitCloneOptions } from '../Sandbox-
|
|
2
|
-
export { C as CommandEvent, D as DaytonaProviderOptions, c as DaytonaSandboxOptions, E as E2bProviderOptions, d as E2bSandboxOptions, L as LocalDockerProviderOptions, e as LocalDockerSandboxOptions, M as ModalProviderOptions, f as ModalSandboxOptions, S as Sandbox, j as SandboxOptionsBase, k as SandboxOptionsMap, m as SandboxRaw, n as SandboxRawMap, o as SandboxResourceSpec } from '../Sandbox-
|
|
1
|
+
import { l as SandboxProviderName, i as SandboxOptions, a as CommandOptions, b as CommandResult, A as AsyncCommandHandle, h as SandboxListOptions, g as SandboxDescriptor, T as TarballEntry, G as GitCloneOptions } from '../Sandbox-CByFJI8X.js';
|
|
2
|
+
export { C as CommandEvent, D as DaytonaProviderOptions, c as DaytonaSandboxOptions, E as E2bProviderOptions, d as E2bSandboxOptions, L as LocalDockerProviderOptions, e as LocalDockerSandboxOptions, M as ModalProviderOptions, f as ModalSandboxOptions, S as Sandbox, j as SandboxOptionsBase, k as SandboxOptionsMap, m as SandboxRaw, n as SandboxRawMap, o as SandboxResourceSpec, V as VercelGitSource, p as VercelProviderOptions, q as VercelSandboxOptions } from '../Sandbox-CByFJI8X.js';
|
|
3
|
+
export { SandboxProvider } from '../enums.js';
|
|
3
4
|
import 'e2b';
|
|
5
|
+
import '@vercel/sandbox';
|
|
4
6
|
import '@daytonaio/sdk';
|
|
5
7
|
import 'modal';
|
|
6
8
|
import 'dockerode';
|
|
@@ -11,6 +13,13 @@ declare abstract class SandboxAdapter<TProvider extends SandboxProviderName = Sa
|
|
|
11
13
|
protected readonly baseEnv: Record<string, string>;
|
|
12
14
|
private provisioned;
|
|
13
15
|
private provisioning?;
|
|
16
|
+
/**
|
|
17
|
+
* Whether `provision()` warm-attached to a pre-existing tagged sandbox
|
|
18
|
+
* (true) or had to create a fresh one (false). Set by adapter
|
|
19
|
+
* `provision()` implementations. Stays `false` until `findOrProvision()`
|
|
20
|
+
* has resolved.
|
|
21
|
+
*/
|
|
22
|
+
protected wasFoundFlag: boolean;
|
|
14
23
|
constructor(options: TOptions);
|
|
15
24
|
abstract get provider(): TProvider;
|
|
16
25
|
abstract get raw(): TRaw | undefined;
|
|
@@ -24,9 +33,54 @@ declare abstract class SandboxAdapter<TProvider extends SandboxProviderName = Sa
|
|
|
24
33
|
abstract delete(): Promise<void>;
|
|
25
34
|
abstract openPort(port: number): Promise<void>;
|
|
26
35
|
abstract getPreviewLink(port: number): Promise<string>;
|
|
27
|
-
|
|
36
|
+
uploadFile(_content: Buffer | string, _targetPath: string): Promise<void>;
|
|
37
|
+
downloadFile(_sourcePath: string): Promise<Buffer>;
|
|
38
|
+
/**
|
|
39
|
+
* Upload a tarball of files into the sandbox and execute a command in
|
|
40
|
+
* the same round-trip. Used by setup paths that would otherwise need one
|
|
41
|
+
* sandbox RPC per file plus another to run the install script — Modal-
|
|
42
|
+
* style providers pay ~700ms per RPC, so collapsing N+1 calls into one
|
|
43
|
+
* is the single biggest win on cold setup.
|
|
44
|
+
*
|
|
45
|
+
* Default implementation falls back to `uploadFile` per entry + a final
|
|
46
|
+
* `run`. Providers that support stdin streaming (Modal) override this to
|
|
47
|
+
* do the upload + extract + exec in a single sandbox `exec` call.
|
|
48
|
+
*/
|
|
49
|
+
uploadAndRun(files: TarballEntry[], command: string, options?: CommandOptions): Promise<CommandResult>;
|
|
50
|
+
/**
|
|
51
|
+
* Public hook that callers must invoke before they touch the sandbox
|
|
52
|
+
* (running commands, cloning repos, uploading files, opening preview
|
|
53
|
+
* links, …). It either attaches to an existing tagged sandbox or creates
|
|
54
|
+
* a new one. The result is cached so repeated calls are cheap.
|
|
55
|
+
*
|
|
56
|
+
* Provisioning is no longer triggered implicitly by `run`, `runAsync`,
|
|
57
|
+
* `gitClone`, `uploadAndRun`, etc. Those methods now throw a clear error
|
|
58
|
+
* when the adapter has not been provisioned yet, which makes the
|
|
59
|
+
* lifecycle explicit and gives callers control over when the
|
|
60
|
+
* (potentially slow) sandbox attach / create happens.
|
|
61
|
+
*/
|
|
62
|
+
findOrProvision(): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* Throw a consistent error when a method that needs a provisioned
|
|
65
|
+
* sandbox is called before `findOrProvision()`. Provider adapters call
|
|
66
|
+
* this at the top of `run`, `runAsync`, `uploadFile`, etc.
|
|
67
|
+
*/
|
|
68
|
+
protected requireProvisioned(): void;
|
|
28
69
|
get tags(): Record<string, string>;
|
|
29
70
|
get workingDir(): string;
|
|
71
|
+
/**
|
|
72
|
+
* Whether `findOrProvision()` warm-attached to a pre-existing tagged
|
|
73
|
+
* sandbox (`true`) or created a fresh one (`false`). Useful to skip
|
|
74
|
+
* idempotent setup that the previous run already performed (e.g.
|
|
75
|
+
* `agent.setup()`). Always `false` before `findOrProvision()` resolves.
|
|
76
|
+
*/
|
|
77
|
+
get wasFound(): boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Headers that callers should attach to HTTP / WebSocket requests they make
|
|
80
|
+
* against this sandbox's preview URL. Default is empty; providers like
|
|
81
|
+
* Vercel override this to inject Deployment Protection bypass tokens.
|
|
82
|
+
*/
|
|
83
|
+
get previewHeaders(): Record<string, string>;
|
|
30
84
|
getMergedEnv(extra?: Record<string, string>): Record<string, string>;
|
|
31
85
|
setSecret(name: string, value: string): void;
|
|
32
86
|
setSecrets(values: Record<string, string>): void;
|
|
@@ -35,4 +89,4 @@ declare abstract class SandboxAdapter<TProvider extends SandboxProviderName = Sa
|
|
|
35
89
|
|
|
36
90
|
declare function buildGitCloneCommand(options: GitCloneOptions): string;
|
|
37
91
|
|
|
38
|
-
export { AsyncCommandHandle, CommandOptions, CommandResult, GitCloneOptions, SandboxAdapter, SandboxDescriptor, SandboxListOptions, SandboxOptions, SandboxProviderName, buildGitCloneCommand };
|
|
92
|
+
export { AsyncCommandHandle, CommandOptions, CommandResult, GitCloneOptions, SandboxAdapter, SandboxDescriptor, SandboxListOptions, SandboxOptions, SandboxProviderName, TarballEntry, buildGitCloneCommand };
|
package/dist/sandboxes/index.js
CHANGED
|
@@ -2,11 +2,15 @@ import {
|
|
|
2
2
|
Sandbox,
|
|
3
3
|
SandboxAdapter,
|
|
4
4
|
buildGitCloneCommand
|
|
5
|
-
} from "../chunk-
|
|
6
|
-
import "../chunk-
|
|
7
|
-
import "../chunk-
|
|
5
|
+
} from "../chunk-LPKKT6YT.js";
|
|
6
|
+
import "../chunk-INMA52FV.js";
|
|
7
|
+
import "../chunk-NSJM57Z4.js";
|
|
8
|
+
import {
|
|
9
|
+
SandboxProvider
|
|
10
|
+
} from "../chunk-GOFJNFAD.js";
|
|
8
11
|
export {
|
|
9
12
|
Sandbox,
|
|
10
13
|
SandboxAdapter,
|
|
14
|
+
SandboxProvider,
|
|
11
15
|
buildGitCloneCommand
|
|
12
16
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AgentProvider } from './enums.js';
|
|
2
|
+
import { S as Sandbox } from './Sandbox-CByFJI8X.js';
|
|
2
3
|
|
|
3
4
|
interface RawAgentEvent<TPayload = unknown> {
|
|
4
5
|
provider: string;
|
|
@@ -22,10 +23,24 @@ interface RunStartedEvent extends NormalizedAgentEventBase {
|
|
|
22
23
|
}
|
|
23
24
|
interface MessageStartedEvent extends NormalizedAgentEventBase {
|
|
24
25
|
type: "message.started";
|
|
26
|
+
/**
|
|
27
|
+
* Provider-assigned identifier for the user message that started this turn.
|
|
28
|
+
* Opaque to callers.
|
|
29
|
+
*
|
|
30
|
+
* - claude-code: the user message UUID written to the session JSONL
|
|
31
|
+
* - codex: the turn id from `turn/started`
|
|
32
|
+
* - open-code: the message id from `message.updated` (role=user)
|
|
33
|
+
*/
|
|
34
|
+
messageId?: string;
|
|
25
35
|
}
|
|
26
36
|
interface MessageInjectedEvent extends NormalizedAgentEventBase {
|
|
27
37
|
type: "message.injected";
|
|
28
38
|
content: string;
|
|
39
|
+
/**
|
|
40
|
+
* Provider-assigned identifier for the injected user message. See
|
|
41
|
+
* `MessageStartedEvent.messageId` for provider-specific semantics.
|
|
42
|
+
*/
|
|
43
|
+
messageId?: string;
|
|
29
44
|
}
|
|
30
45
|
interface TextDeltaEvent extends NormalizedAgentEventBase {
|
|
31
46
|
type: "text.delta";
|
|
@@ -71,6 +86,12 @@ interface PermissionResolvedEvent extends NormalizedAgentEventBase {
|
|
|
71
86
|
interface MessageCompletedEvent extends NormalizedAgentEventBase {
|
|
72
87
|
type: "message.completed";
|
|
73
88
|
text?: string;
|
|
89
|
+
/**
|
|
90
|
+
* Provider-assigned identifier for the assistant message that just
|
|
91
|
+
* completed. Format mirrors `MessageStartedEvent.messageId` but identifies
|
|
92
|
+
* the assistant turn rather than the user one.
|
|
93
|
+
*/
|
|
94
|
+
messageId?: string;
|
|
74
95
|
}
|
|
75
96
|
interface RunCompletedEvent extends NormalizedAgentEventBase {
|
|
76
97
|
type: "run.completed";
|
|
@@ -260,7 +281,7 @@ interface AgentCommandConfig {
|
|
|
260
281
|
subtask?: boolean;
|
|
261
282
|
}
|
|
262
283
|
|
|
263
|
-
type AgentProviderName =
|
|
284
|
+
type AgentProviderName = AgentProvider;
|
|
264
285
|
type DataContent = string | URL | Uint8Array | ArrayBuffer | Buffer;
|
|
265
286
|
interface TextPart {
|
|
266
287
|
type: "text";
|
|
@@ -279,12 +300,23 @@ interface FilePart {
|
|
|
279
300
|
}
|
|
280
301
|
type UserContentPart = TextPart | ImagePart | FilePart;
|
|
281
302
|
type UserContent = string | UserContentPart[];
|
|
303
|
+
type AgentReasoningEffort = "low" | "medium" | "high" | "xhigh";
|
|
282
304
|
interface AgentRunConfig {
|
|
283
305
|
input: UserContent;
|
|
306
|
+
runId?: string;
|
|
284
307
|
model?: string;
|
|
285
308
|
systemPrompt?: string;
|
|
286
309
|
resumeSessionId?: string;
|
|
287
|
-
|
|
310
|
+
reasoning?: AgentReasoningEffort;
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Subset of {@link AgentRunConfig} that needs to be committed at
|
|
314
|
+
* `agent.setup()` time so the runtime can pre-bake artifacts that
|
|
315
|
+
* reference it (codex `model_instructions_file`, opencode agent config,
|
|
316
|
+
* etc.). Unlike `AgentRunConfig`, this never carries per-turn input or
|
|
317
|
+
* a resumed session id.
|
|
318
|
+
*/
|
|
319
|
+
type AgentSetupConfig = Pick<AgentRunConfig, "systemPrompt" | "model" | "reasoning">;
|
|
288
320
|
type AgentApprovalMode = "auto" | "interactive";
|
|
289
321
|
type AgentPermissionKind = "bash" | "edit" | "tool" | "network" | "file-change" | "unknown";
|
|
290
322
|
type AgentPermissionDecision = "allow" | "deny";
|
|
@@ -309,6 +341,14 @@ interface CodexProviderOptions {
|
|
|
309
341
|
brokerEndpoint?: string;
|
|
310
342
|
useBroker?: boolean;
|
|
311
343
|
hooks?: CodexHooksConfig;
|
|
344
|
+
/**
|
|
345
|
+
* When `false`, writes `supports_websockets = false` into Codex's
|
|
346
|
+
* config.toml. Useful in environments where outbound WebSocket
|
|
347
|
+
* connections from the Codex CLI aren't available (proxies, network
|
|
348
|
+
* policies). When `true` or omitted, no key is emitted and Codex
|
|
349
|
+
* uses its built-in default.
|
|
350
|
+
*/
|
|
351
|
+
supportsWebsockets?: boolean;
|
|
312
352
|
}
|
|
313
353
|
interface OpenCodeProviderOptions {
|
|
314
354
|
binary?: string;
|
|
@@ -335,10 +375,22 @@ interface ClaudeCodeAgentOptions extends AgentOptionsBase {
|
|
|
335
375
|
}
|
|
336
376
|
type AgentOptionsMap = {
|
|
337
377
|
codex: CodexAgentOptions;
|
|
338
|
-
|
|
378
|
+
"open-code": OpenCodeAgentOptions;
|
|
339
379
|
"claude-code": ClaudeCodeAgentOptions;
|
|
340
380
|
};
|
|
341
381
|
type AgentOptions<P extends AgentProviderName = AgentProviderName> = AgentOptionsMap[P];
|
|
382
|
+
interface AgentCostData {
|
|
383
|
+
total_cost_usd?: number;
|
|
384
|
+
duration_ms?: number;
|
|
385
|
+
duration_api_ms?: number;
|
|
386
|
+
num_turns?: number;
|
|
387
|
+
usage?: {
|
|
388
|
+
input_tokens?: number;
|
|
389
|
+
output_tokens?: number;
|
|
390
|
+
cache_creation_input_tokens?: number;
|
|
391
|
+
cache_read_input_tokens?: number;
|
|
392
|
+
};
|
|
393
|
+
}
|
|
342
394
|
interface AgentResult {
|
|
343
395
|
id: string;
|
|
344
396
|
provider: AgentProviderName;
|
|
@@ -346,6 +398,7 @@ interface AgentResult {
|
|
|
346
398
|
text: string;
|
|
347
399
|
rawEvents: RawAgentEvent[];
|
|
348
400
|
events: NormalizedAgentEvent[];
|
|
401
|
+
costData?: AgentCostData | null;
|
|
349
402
|
}
|
|
350
403
|
interface AgentRun extends AsyncIterable<NormalizedAgentEvent> {
|
|
351
404
|
id: string;
|
|
@@ -367,20 +420,108 @@ interface AgentRunSink {
|
|
|
367
420
|
emitRaw(event: RawAgentEvent): void;
|
|
368
421
|
emitEvent(event: NormalizedAgentEvent): void;
|
|
369
422
|
requestPermission(event: PermissionRequestedEvent): Promise<AgentPermissionResponse>;
|
|
370
|
-
onMessage(handler: (content: UserContent) => Promise<
|
|
423
|
+
onMessage(handler: (content: UserContent) => Promise<{
|
|
424
|
+
messageId?: string;
|
|
425
|
+
} | void>): void;
|
|
371
426
|
complete(result?: {
|
|
372
427
|
text?: string;
|
|
428
|
+
costData?: AgentCostData | null;
|
|
373
429
|
}): void;
|
|
374
430
|
fail(error: unknown): void;
|
|
375
431
|
}
|
|
432
|
+
interface AgentSetupRequest<P extends AgentProviderName = AgentProviderName> {
|
|
433
|
+
provider: P;
|
|
434
|
+
options: AgentOptions<P>;
|
|
435
|
+
config: AgentSetupConfig;
|
|
436
|
+
}
|
|
376
437
|
interface AgentExecutionRequest<P extends AgentProviderName = AgentProviderName> {
|
|
377
438
|
runId: string;
|
|
378
439
|
provider: P;
|
|
379
440
|
options: AgentOptions<P>;
|
|
380
441
|
run: AgentRunConfig;
|
|
381
442
|
}
|
|
443
|
+
/**
|
|
444
|
+
* Stateless attach request used by {@link Agent.attach} to issue control
|
|
445
|
+
* commands (abort, sendMessage) against a run that lives on a different
|
|
446
|
+
* Twill instance.
|
|
447
|
+
*
|
|
448
|
+
* The attach call dials the in-sandbox provider server directly via
|
|
449
|
+
* `sandbox.getPreviewLink(...)` — no shared in-memory state, no broker.
|
|
450
|
+
* The originating instance still owns the run's event stream and reacts
|
|
451
|
+
* naturally to whatever the provider emits as a consequence of the
|
|
452
|
+
* attached command (e.g. `turn/aborted` for codex, message events for
|
|
453
|
+
* claude-code/opencode).
|
|
454
|
+
*/
|
|
455
|
+
interface AgentAttachRequest<P extends AgentProviderName = AgentProviderName> {
|
|
456
|
+
provider: P;
|
|
457
|
+
sandbox: Sandbox;
|
|
458
|
+
/**
|
|
459
|
+
* The {@link AgentRunConfig.runId} the originating instance used in
|
|
460
|
+
* `agent.stream({ runId, ... })`. Required for claude-code (the relay
|
|
461
|
+
* keys channels by runId) and useful as an idempotency / log id for
|
|
462
|
+
* the other providers.
|
|
463
|
+
*/
|
|
464
|
+
runId: string;
|
|
465
|
+
/**
|
|
466
|
+
* Provider-native session id captured from {@link AgentRun.sessionIdReady}.
|
|
467
|
+
*
|
|
468
|
+
* - codex: the threadId
|
|
469
|
+
* - opencode: the sessionId
|
|
470
|
+
* - claude-code: the claude session uuid (optional — runId is the
|
|
471
|
+
* primary key inside the relay)
|
|
472
|
+
*/
|
|
473
|
+
sessionId?: string;
|
|
474
|
+
/**
|
|
475
|
+
* Codex only: the in-flight turn id, captured by the originating
|
|
476
|
+
* caller from the {@link NormalizedAgentEvent} `message.started`
|
|
477
|
+
* event (whose `messageId` is the codex turnId). `attachAbort` uses
|
|
478
|
+
* it for `turn/interrupt`. When omitted the codex attach is a no-op.
|
|
479
|
+
*
|
|
480
|
+
* The SDK does not persist this itself — bookkeeping it across
|
|
481
|
+
* processes is the caller's responsibility (e.g. Redis), since
|
|
482
|
+
* sandbox-side files don't compose well under concurrency.
|
|
483
|
+
*/
|
|
484
|
+
turnId?: string;
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* Thin handle returned by {@link Agent.attach}. Methods are short-lived:
|
|
488
|
+
* each call opens a fresh transport to the in-sandbox server, performs
|
|
489
|
+
* the operation, and tears the transport down. There is no "close" —
|
|
490
|
+
* the handle holds no resources between calls.
|
|
491
|
+
*/
|
|
492
|
+
interface AttachedRun {
|
|
493
|
+
abort(): Promise<void>;
|
|
494
|
+
sendMessage(content: UserContent): Promise<void>;
|
|
495
|
+
}
|
|
382
496
|
interface AgentProviderAdapter<P extends AgentProviderName = AgentProviderName> {
|
|
497
|
+
/**
|
|
498
|
+
* Sandbox-side preparation work that does not depend on per-run input:
|
|
499
|
+
* upload artifacts (skills/commands/mcp/hook config), boot any
|
|
500
|
+
* provider server / relay the run will need.
|
|
501
|
+
*
|
|
502
|
+
* Required before {@link AgentProviderAdapter.execute} for sandbox-backed
|
|
503
|
+
* runs. {@link execute} does not read any setup output and does not
|
|
504
|
+
* re-do this work — it assumes the relay/server is up and dials it
|
|
505
|
+
* directly. If `setup` was never called against a remote sandbox the
|
|
506
|
+
* connect retry inside `execute` fails naturally.
|
|
507
|
+
*
|
|
508
|
+
* Idempotent: `applyDifferentialSetup` short-circuits unchanged
|
|
509
|
+
* artifacts, and the relay/server probes short-circuit when something
|
|
510
|
+
* is already listening.
|
|
511
|
+
*/
|
|
512
|
+
setup(request: AgentSetupRequest<P>): Promise<void>;
|
|
383
513
|
execute(request: AgentExecutionRequest<P>, sink: AgentRunSink): Promise<() => Promise<void> | void>;
|
|
514
|
+
/**
|
|
515
|
+
* Stateless abort. Dial the in-sandbox provider server, issue the
|
|
516
|
+
* provider's "interrupt the in-flight turn" primitive, close.
|
|
517
|
+
*/
|
|
518
|
+
attachAbort(request: AgentAttachRequest<P>): Promise<void>;
|
|
519
|
+
/**
|
|
520
|
+
* Stateless message injection. Dial the in-sandbox provider server,
|
|
521
|
+
* append `content` as a new user turn against the existing session,
|
|
522
|
+
* close.
|
|
523
|
+
*/
|
|
524
|
+
attachSendMessage(request: AgentAttachRequest<P>, content: UserContent): Promise<void>;
|
|
384
525
|
}
|
|
385
526
|
|
|
386
|
-
export { type
|
|
527
|
+
export { type OpenCodePluginHookConfig as $, type AISDKEvent as A, type ClaudeCodeHookConfig as B, type ClaudeCodeAgentOptions as C, type ClaudeCodeHookEvent as D, type ClaudeCodeHookHandler as E, type ClaudeCodeHookMatcherGroup as F, type ClaudeCodeHooksConfig as G, type ClaudeCodeProviderOptions as H, type CodexAgentOptions as I, type CodexCommandHook as J, type CodexHookEvent as K, type CodexHookMatcherGroup as L, type CodexHooksConfig as M, type CodexProviderOptions as N, type DataContent as O, type EmbeddedSkillConfig as P, type FilePart as Q, type ImagePart as R, type MessageCompletedEvent as S, type MessageInjectedEvent as T, type MessageStartedEvent as U, type NormalizedAgentEvent as V, type NormalizedAgentEventBase as W, type NormalizedAgentEventType as X, type OpenCodeAgentOptions as Y, type OpenCodePluginConfig as Z, type OpenCodePluginEvent as _, type AgentApprovalMode as a, type OpenCodeProviderOptions as a0, type PermissionRequestedEvent as a1, type PermissionResolvedEvent as a2, type RawAgentEvent as a3, type ReasoningDeltaEvent as a4, type RepoSkillConfig as a5, type RunCompletedEvent as a6, type RunErrorEvent as a7, type RunStartedEvent as a8, type TextDeltaEvent as a9, type TextPart as aa, type ToolCallCompletedEvent as ab, type ToolCallDeltaEvent as ac, type ToolCallStartedEvent as ad, type UserContent as ae, type UserContentPart as af, createNormalizedEvent as ag, normalizeRawAgentEvent as ah, toAISDKEvent as ai, toAISDKStream as aj, type AgentAttachRequest as b, type AgentCommandConfig as c, type AgentCostData as d, type AgentExecutionRequest as e, type AgentLocalMcpConfig as f, type AgentMcpConfig as g, type AgentOptions as h, type AgentOptionsBase as i, type AgentOptionsMap as j, type AgentPermissionDecision as k, type AgentPermissionKind as l, type AgentPermissionResponse as m, type AgentProviderAdapter as n, type AgentProviderName as o, type AgentReasoningEffort as p, type AgentRemoteMcpConfig as q, type AgentResult as r, type AgentRun as s, type AgentRunConfig as t, type AgentRunSink as u, type AgentSetupConfig as v, type AgentSetupRequest as w, type AgentSkillConfig as x, type AgentSubAgentConfig as y, type AttachedRun as z };
|
package/images/browser-agent.mjs
CHANGED
|
@@ -43,13 +43,13 @@ export default {
|
|
|
43
43
|
run: [
|
|
44
44
|
`apt-get update && apt-get install -y --no-install-recommends ${aptPackages.join(" ")} && rm -rf /var/lib/apt/lists/*`,
|
|
45
45
|
"npm cache clean --force",
|
|
46
|
-
"npm install -g pnpm @anthropic-ai/claude-code @openai/codex opencode-ai agent-browser",
|
|
46
|
+
"npm install -g pnpm @anthropic-ai/claude-code @anthropic-ai/claude-agent-sdk @anthropic-ai/claude-agent-sdk @openai/codex opencode-ai agent-browser",
|
|
47
47
|
"agent-browser set viewport 1980 1080",
|
|
48
48
|
],
|
|
49
49
|
workdir: "/workspace",
|
|
50
50
|
cmd: ["sleep", "infinity"],
|
|
51
51
|
resources: {
|
|
52
|
-
cpu:
|
|
53
|
-
memoryMiB:
|
|
52
|
+
cpu: 1,
|
|
53
|
+
memoryMiB: 1024,
|
|
54
54
|
},
|
|
55
55
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agentbox-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Swappable coding agents and sandbox providers for Bun and TypeScript.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -33,10 +33,15 @@
|
|
|
33
33
|
"./events": {
|
|
34
34
|
"types": "./dist/events/index.d.ts",
|
|
35
35
|
"import": "./dist/events/index.js"
|
|
36
|
+
},
|
|
37
|
+
"./enums": {
|
|
38
|
+
"types": "./dist/enums.d.ts",
|
|
39
|
+
"import": "./dist/enums.js"
|
|
36
40
|
}
|
|
37
41
|
},
|
|
38
42
|
"scripts": {
|
|
39
|
-
"
|
|
43
|
+
"dev": "tsup src/index.ts src/enums.ts src/agents/index.ts src/sandboxes/index.ts src/events/index.ts src/cli.ts --format esm --dts --clean --watch",
|
|
44
|
+
"build": "tsup src/index.ts src/enums.ts src/agents/index.ts src/sandboxes/index.ts src/events/index.ts src/cli.ts --format esm --dts --clean",
|
|
40
45
|
"typecheck": "tsc --noEmit",
|
|
41
46
|
"lint": "eslint . --max-warnings=0",
|
|
42
47
|
"lint:fix": "eslint . --fix",
|
|
@@ -46,14 +51,18 @@
|
|
|
46
51
|
"test:watch": "vitest",
|
|
47
52
|
"check": "npm run typecheck && npm run lint && npm run test",
|
|
48
53
|
"hooks:install": "lefthook install",
|
|
49
|
-
"prepare": "if [ -d .git ]; then lefthook install; else echo 'Skipping lefthook install (
|
|
54
|
+
"prepare": "if [ -n \"$CI\" ] || [ ! -d .git ]; then echo 'Skipping lefthook install (CI or no .git directory)'; else lefthook install || echo 'Skipping lefthook install (binary unavailable)'; fi"
|
|
50
55
|
},
|
|
51
56
|
"engines": {
|
|
52
57
|
"node": ">=20.0.0",
|
|
53
58
|
"bun": ">=1.1.0"
|
|
54
59
|
},
|
|
55
60
|
"dependencies": {
|
|
61
|
+
"@anthropic-ai/claude-agent-sdk": "^0.2.123",
|
|
56
62
|
"@daytonaio/sdk": "^0.161.0",
|
|
63
|
+
"@types/debug": "^4.1.13",
|
|
64
|
+
"@vercel/sandbox": "2.0.0-beta.13",
|
|
65
|
+
"debug": "^4.4.3",
|
|
57
66
|
"dockerode": "^4.0.10",
|
|
58
67
|
"e2b": "^2.19.0",
|
|
59
68
|
"eventsource-parser": "^3.0.6",
|
|
@@ -87,6 +96,7 @@
|
|
|
87
96
|
"modal",
|
|
88
97
|
"daytona",
|
|
89
98
|
"docker",
|
|
99
|
+
"vercel",
|
|
90
100
|
"typescript",
|
|
91
101
|
"bun"
|
|
92
102
|
]
|
package/dist/chunk-7FLLQJ6J.js
DELETED
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
// src/events/normalized.ts
|
|
2
|
-
function createNormalizedEvent(type, base, extra) {
|
|
3
|
-
return {
|
|
4
|
-
type,
|
|
5
|
-
provider: base.provider,
|
|
6
|
-
runId: base.runId,
|
|
7
|
-
timestamp: base.timestamp ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
8
|
-
raw: base.raw,
|
|
9
|
-
meta: base.meta,
|
|
10
|
-
...extra ?? {}
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
function normalizeRawAgentEvent(event) {
|
|
14
|
-
const payload = event.payload;
|
|
15
|
-
const common = {
|
|
16
|
-
provider: event.provider,
|
|
17
|
-
runId: event.runId,
|
|
18
|
-
raw: event,
|
|
19
|
-
timestamp: event.timestamp
|
|
20
|
-
};
|
|
21
|
-
if (event.type === "assistant" && Array.isArray(
|
|
22
|
-
payload?.message?.content
|
|
23
|
-
)) {
|
|
24
|
-
const blocks = (payload?.message).content;
|
|
25
|
-
const text = blocks.filter((block) => block.type === "text").map((block) => String(block.text ?? "")).join("");
|
|
26
|
-
return [
|
|
27
|
-
createNormalizedEvent("message.started", common),
|
|
28
|
-
...text ? [createNormalizedEvent("text.delta", common, { delta: text })] : [],
|
|
29
|
-
createNormalizedEvent("message.completed", common, { text }),
|
|
30
|
-
createNormalizedEvent("run.completed", common, { text })
|
|
31
|
-
];
|
|
32
|
-
}
|
|
33
|
-
if (event.type.includes("delta")) {
|
|
34
|
-
const delta = String(
|
|
35
|
-
payload?.delta ?? payload?.text ?? payload?.["content"] ?? ""
|
|
36
|
-
);
|
|
37
|
-
const normalizedType = event.type.includes("reasoning") ? "reasoning.delta" : "text.delta";
|
|
38
|
-
return [createNormalizedEvent(normalizedType, common, { delta })];
|
|
39
|
-
}
|
|
40
|
-
if (event.type.includes("tool")) {
|
|
41
|
-
const toolName = String(payload?.toolName ?? payload?.tool_name ?? "tool");
|
|
42
|
-
if (event.type.includes("completed") || event.type.includes("summary")) {
|
|
43
|
-
return [
|
|
44
|
-
createNormalizedEvent("tool.call.completed", common, {
|
|
45
|
-
toolName,
|
|
46
|
-
callId: payload?.callId ?? payload?.tool_use_id,
|
|
47
|
-
output: payload?.output ?? payload?.result
|
|
48
|
-
})
|
|
49
|
-
];
|
|
50
|
-
}
|
|
51
|
-
return [
|
|
52
|
-
createNormalizedEvent("tool.call.started", common, {
|
|
53
|
-
toolName,
|
|
54
|
-
callId: payload?.callId ?? payload?.tool_use_id,
|
|
55
|
-
input: payload?.input
|
|
56
|
-
})
|
|
57
|
-
];
|
|
58
|
-
}
|
|
59
|
-
if (event.type === "result") {
|
|
60
|
-
const text = String(payload?.result ?? payload?.text ?? "");
|
|
61
|
-
return [createNormalizedEvent("run.completed", common, { text })];
|
|
62
|
-
}
|
|
63
|
-
if (event.type === "error") {
|
|
64
|
-
return [
|
|
65
|
-
createNormalizedEvent("run.error", common, {
|
|
66
|
-
error: String(
|
|
67
|
-
payload?.message ?? payload?.error ?? "Unknown agent error"
|
|
68
|
-
)
|
|
69
|
-
})
|
|
70
|
-
];
|
|
71
|
-
}
|
|
72
|
-
return [];
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// src/events/ai-sdk.ts
|
|
76
|
-
function toAISDKEvent(event) {
|
|
77
|
-
switch (event.type) {
|
|
78
|
-
case "run.started":
|
|
79
|
-
return {
|
|
80
|
-
type: "response-start",
|
|
81
|
-
id: event.runId,
|
|
82
|
-
provider: event.provider
|
|
83
|
-
};
|
|
84
|
-
case "message.injected":
|
|
85
|
-
return {
|
|
86
|
-
type: "message-injected",
|
|
87
|
-
id: event.runId,
|
|
88
|
-
provider: event.provider,
|
|
89
|
-
content: event.content
|
|
90
|
-
};
|
|
91
|
-
case "text.delta":
|
|
92
|
-
return {
|
|
93
|
-
type: "text-delta",
|
|
94
|
-
id: event.runId,
|
|
95
|
-
provider: event.provider,
|
|
96
|
-
textDelta: event.delta
|
|
97
|
-
};
|
|
98
|
-
case "reasoning.delta":
|
|
99
|
-
return {
|
|
100
|
-
type: "reasoning-delta",
|
|
101
|
-
id: event.runId,
|
|
102
|
-
provider: event.provider,
|
|
103
|
-
textDelta: event.delta
|
|
104
|
-
};
|
|
105
|
-
case "tool.call.started":
|
|
106
|
-
return {
|
|
107
|
-
type: "tool-input-start",
|
|
108
|
-
id: event.runId,
|
|
109
|
-
provider: event.provider,
|
|
110
|
-
toolName: event.toolName,
|
|
111
|
-
callId: event.callId
|
|
112
|
-
};
|
|
113
|
-
case "tool.call.delta":
|
|
114
|
-
return {
|
|
115
|
-
type: "tool-input-delta",
|
|
116
|
-
id: event.runId,
|
|
117
|
-
provider: event.provider,
|
|
118
|
-
toolName: event.toolName,
|
|
119
|
-
callId: event.callId,
|
|
120
|
-
inputTextDelta: event.delta
|
|
121
|
-
};
|
|
122
|
-
case "tool.call.completed":
|
|
123
|
-
return {
|
|
124
|
-
type: "tool-output-available",
|
|
125
|
-
id: event.runId,
|
|
126
|
-
provider: event.provider,
|
|
127
|
-
toolName: event.toolName,
|
|
128
|
-
callId: event.callId,
|
|
129
|
-
output: event.output
|
|
130
|
-
};
|
|
131
|
-
case "permission.requested":
|
|
132
|
-
return {
|
|
133
|
-
type: "permission-requested",
|
|
134
|
-
id: event.runId,
|
|
135
|
-
provider: event.provider,
|
|
136
|
-
requestId: event.requestId,
|
|
137
|
-
kind: event.kind,
|
|
138
|
-
title: event.title,
|
|
139
|
-
message: event.message,
|
|
140
|
-
input: event.input,
|
|
141
|
-
canRemember: event.canRemember
|
|
142
|
-
};
|
|
143
|
-
case "permission.resolved":
|
|
144
|
-
return {
|
|
145
|
-
type: "permission-resolved",
|
|
146
|
-
id: event.runId,
|
|
147
|
-
provider: event.provider,
|
|
148
|
-
requestId: event.requestId,
|
|
149
|
-
decision: event.decision,
|
|
150
|
-
remember: event.remember
|
|
151
|
-
};
|
|
152
|
-
case "message.completed":
|
|
153
|
-
case "run.completed":
|
|
154
|
-
return {
|
|
155
|
-
type: "response-finish",
|
|
156
|
-
id: event.runId,
|
|
157
|
-
provider: event.provider,
|
|
158
|
-
text: event.text
|
|
159
|
-
};
|
|
160
|
-
case "run.error":
|
|
161
|
-
return {
|
|
162
|
-
type: "response-error",
|
|
163
|
-
id: event.runId,
|
|
164
|
-
provider: event.provider,
|
|
165
|
-
error: event.error
|
|
166
|
-
};
|
|
167
|
-
default:
|
|
168
|
-
return null;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
async function* toAISDKStream(events) {
|
|
172
|
-
for await (const event of events) {
|
|
173
|
-
const mapped = toAISDKEvent(event);
|
|
174
|
-
if (mapped) {
|
|
175
|
-
yield mapped;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
export {
|
|
181
|
-
createNormalizedEvent,
|
|
182
|
-
normalizeRawAgentEvent,
|
|
183
|
-
toAISDKEvent,
|
|
184
|
-
toAISDKStream
|
|
185
|
-
};
|