anyclaude-sdk 0.1.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/LICENSE +21 -0
- package/README.md +295 -0
- package/dist/agent.d.ts +110 -0
- package/dist/agent.js +897 -0
- package/dist/background/index.d.ts +3 -0
- package/dist/background/index.js +9 -0
- package/dist/background/manager.d.ts +32 -0
- package/dist/background/manager.js +108 -0
- package/dist/background/tools.d.ts +5 -0
- package/dist/background/tools.js +98 -0
- package/dist/background/worker.d.ts +19 -0
- package/dist/background/worker.js +30 -0
- package/dist/commands/builtins.d.ts +2 -0
- package/dist/commands/builtins.js +306 -0
- package/dist/commands/index.d.ts +21 -0
- package/dist/commands/index.js +56 -0
- package/dist/commands/types.d.ts +110 -0
- package/dist/commands/types.js +5 -0
- package/dist/compact.d.ts +22 -0
- package/dist/compact.js +67 -0
- package/dist/fs/dexie.d.ts +57 -0
- package/dist/fs/dexie.js +243 -0
- package/dist/fs/index.d.ts +4 -0
- package/dist/fs/index.js +13 -0
- package/dist/fs/linuxTree.d.ts +11 -0
- package/dist/fs/linuxTree.js +43 -0
- package/dist/fs/opfs.d.ts +23 -0
- package/dist/fs/opfs.js +112 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +29 -0
- package/dist/llm/anthropic.d.ts +24 -0
- package/dist/llm/anthropic.js +280 -0
- package/dist/llm/index.d.ts +3 -0
- package/dist/llm/index.js +3 -0
- package/dist/llm/inlineTools.d.ts +11 -0
- package/dist/llm/inlineTools.js +72 -0
- package/dist/llm/openai.d.ts +29 -0
- package/dist/llm/openai.js +224 -0
- package/dist/llm/responses.d.ts +18 -0
- package/dist/llm/responses.js +256 -0
- package/dist/mcp/client.d.ts +20 -0
- package/dist/mcp/client.js +156 -0
- package/dist/mcp/index.d.ts +24 -0
- package/dist/mcp/index.js +157 -0
- package/dist/mcp/proxy.d.ts +3 -0
- package/dist/mcp/proxy.js +25 -0
- package/dist/mcp/sdkServer.d.ts +21 -0
- package/dist/mcp/sdkServer.js +28 -0
- package/dist/mcp/types.d.ts +92 -0
- package/dist/mcp/types.js +5 -0
- package/dist/memory/index.d.ts +4 -0
- package/dist/memory/index.js +5 -0
- package/dist/memory/render.d.ts +7 -0
- package/dist/memory/render.js +46 -0
- package/dist/memory/store.d.ts +20 -0
- package/dist/memory/store.js +79 -0
- package/dist/memory/tools.d.ts +5 -0
- package/dist/memory/tools.js +95 -0
- package/dist/memory/types.d.ts +15 -0
- package/dist/memory/types.js +4 -0
- package/dist/permissions/dangerous.d.ts +4 -0
- package/dist/permissions/dangerous.js +24 -0
- package/dist/permissions/gate.d.ts +21 -0
- package/dist/permissions/gate.js +66 -0
- package/dist/permissions/index.d.ts +5 -0
- package/dist/permissions/index.js +6 -0
- package/dist/permissions/match.d.ts +19 -0
- package/dist/permissions/match.js +104 -0
- package/dist/permissions/planMode.d.ts +3 -0
- package/dist/permissions/planMode.js +33 -0
- package/dist/permissions/types.d.ts +19 -0
- package/dist/permissions/types.js +2 -0
- package/dist/persist.d.ts +15 -0
- package/dist/persist.js +58 -0
- package/dist/prompt.d.ts +6 -0
- package/dist/prompt.js +34 -0
- package/dist/query.d.ts +105 -0
- package/dist/query.js +115 -0
- package/dist/queue.d.ts +23 -0
- package/dist/queue.js +43 -0
- package/dist/sandbox/cloudflare.d.ts +48 -0
- package/dist/sandbox/cloudflare.js +124 -0
- package/dist/sandbox/daytona.d.ts +48 -0
- package/dist/sandbox/daytona.js +79 -0
- package/dist/sandbox/e2b.d.ts +54 -0
- package/dist/sandbox/e2b.js +87 -0
- package/dist/sandbox/index.d.ts +8 -0
- package/dist/sandbox/index.js +19 -0
- package/dist/sandbox/local.d.ts +51 -0
- package/dist/sandbox/local.js +155 -0
- package/dist/sandbox/types.d.ts +18 -0
- package/dist/sandbox/types.js +27 -0
- package/dist/sandbox/util.d.ts +15 -0
- package/dist/sandbox/util.js +100 -0
- package/dist/sandbox/vercel.d.ts +48 -0
- package/dist/sandbox/vercel.js +130 -0
- package/dist/session/index.d.ts +2 -0
- package/dist/session/index.js +6 -0
- package/dist/session/store.d.ts +28 -0
- package/dist/session/store.js +122 -0
- package/dist/session/types.d.ts +22 -0
- package/dist/session/types.js +2 -0
- package/dist/settings/index.d.ts +3 -0
- package/dist/settings/index.js +3 -0
- package/dist/settings/load.d.ts +20 -0
- package/dist/settings/load.js +36 -0
- package/dist/settings/merge.d.ts +13 -0
- package/dist/settings/merge.js +65 -0
- package/dist/settings/types.d.ts +17 -0
- package/dist/settings/types.js +3 -0
- package/dist/skills/index.d.ts +4 -0
- package/dist/skills/index.js +5 -0
- package/dist/skills/load.d.ts +23 -0
- package/dist/skills/load.js +54 -0
- package/dist/skills/parse.d.ts +7 -0
- package/dist/skills/parse.js +40 -0
- package/dist/skills/tool.d.ts +2 -0
- package/dist/skills/tool.js +39 -0
- package/dist/skills/types.d.ts +10 -0
- package/dist/skills/types.js +4 -0
- package/dist/team/dispatch.d.ts +2 -0
- package/dist/team/dispatch.js +41 -0
- package/dist/team/index.d.ts +9 -0
- package/dist/team/index.js +11 -0
- package/dist/team/mailbox.d.ts +24 -0
- package/dist/team/mailbox.js +33 -0
- package/dist/team/prompt.d.ts +1 -0
- package/dist/team/prompt.js +12 -0
- package/dist/team/runner.d.ts +20 -0
- package/dist/team/runner.js +45 -0
- package/dist/team/taskBoard.d.ts +41 -0
- package/dist/team/taskBoard.js +73 -0
- package/dist/team/tools.d.ts +7 -0
- package/dist/team/tools.js +190 -0
- package/dist/tools/bash.d.ts +2 -0
- package/dist/tools/bash.js +45 -0
- package/dist/tools/config.d.ts +2 -0
- package/dist/tools/config.js +44 -0
- package/dist/tools/define.d.ts +18 -0
- package/dist/tools/define.js +21 -0
- package/dist/tools/delete_file.d.ts +2 -0
- package/dist/tools/delete_file.js +33 -0
- package/dist/tools/edit_file.d.ts +2 -0
- package/dist/tools/edit_file.js +93 -0
- package/dist/tools/fileTypes.d.ts +32 -0
- package/dist/tools/fileTypes.js +166 -0
- package/dist/tools/glob.d.ts +2 -0
- package/dist/tools/glob.js +53 -0
- package/dist/tools/grep.d.ts +2 -0
- package/dist/tools/grep.js +110 -0
- package/dist/tools/imageProcessor.d.ts +15 -0
- package/dist/tools/imageProcessor.js +83 -0
- package/dist/tools/index.d.ts +28 -0
- package/dist/tools/index.js +45 -0
- package/dist/tools/list_files.d.ts +2 -0
- package/dist/tools/list_files.js +42 -0
- package/dist/tools/multi_edit.d.ts +2 -0
- package/dist/tools/multi_edit.js +112 -0
- package/dist/tools/notebook_edit.d.ts +2 -0
- package/dist/tools/notebook_edit.js +118 -0
- package/dist/tools/plan_mode.d.ts +4 -0
- package/dist/tools/plan_mode.js +44 -0
- package/dist/tools/read_file.d.ts +2 -0
- package/dist/tools/read_file.js +193 -0
- package/dist/tools/task.d.ts +2 -0
- package/dist/tools/task.js +77 -0
- package/dist/tools/todo_write.d.ts +2 -0
- package/dist/tools/todo_write.js +104 -0
- package/dist/tools/tool_search.d.ts +2 -0
- package/dist/tools/tool_search.js +49 -0
- package/dist/tools/types.d.ts +82 -0
- package/dist/tools/types.js +1 -0
- package/dist/tools/walk.d.ts +29 -0
- package/dist/tools/walk.js +82 -0
- package/dist/tools/web_fetch.d.ts +2 -0
- package/dist/tools/web_fetch.js +76 -0
- package/dist/tools/web_search.d.ts +22 -0
- package/dist/tools/web_search.js +195 -0
- package/dist/tools/write_file.d.ts +2 -0
- package/dist/tools/write_file.js +39 -0
- package/dist/types/index.d.ts +363 -0
- package/dist/types/index.js +9 -0
- package/dist/util/ids.d.ts +3 -0
- package/dist/util/ids.js +22 -0
- package/dist/util/paths.d.ts +16 -0
- package/dist/util/paths.js +72 -0
- package/dist/util/pricing.d.ts +15 -0
- package/dist/util/pricing.js +81 -0
- package/dist/workspace/index.d.ts +2 -0
- package/dist/workspace/index.js +2 -0
- package/dist/workspace/memory.d.ts +28 -0
- package/dist/workspace/memory.js +97 -0
- package/dist/workspace/webcontainer.d.ts +65 -0
- package/dist/workspace/webcontainer.js +156 -0
- package/package.json +78 -0
package/dist/queue.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ContentBlockParam } from './types/index.js';
|
|
2
|
+
export type QueuedContent = string | ContentBlockParam[];
|
|
3
|
+
export interface QueuedMessage {
|
|
4
|
+
content: QueuedContent;
|
|
5
|
+
/** Epoch ms when enqueued. */
|
|
6
|
+
at: number;
|
|
7
|
+
}
|
|
8
|
+
export declare class MessageQueue {
|
|
9
|
+
private items;
|
|
10
|
+
private listeners;
|
|
11
|
+
/** Enqueue a user message to be delivered at the next turn boundary. */
|
|
12
|
+
push(content: QueuedContent): void;
|
|
13
|
+
/** Remove and return the oldest queued message (FIFO), or undefined if empty. */
|
|
14
|
+
shift(): QueuedMessage | undefined;
|
|
15
|
+
peek(): QueuedMessage | undefined;
|
|
16
|
+
get size(): number;
|
|
17
|
+
/** Snapshot of pending messages (does not drain). */
|
|
18
|
+
list(): readonly QueuedMessage[];
|
|
19
|
+
clear(): void;
|
|
20
|
+
/** Subscribe to size changes (push/shift/clear). Returns an unsubscribe fn. */
|
|
21
|
+
onChange(fn: (size: number) => void): () => void;
|
|
22
|
+
private emit;
|
|
23
|
+
}
|
package/dist/queue.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export class MessageQueue {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.items = [];
|
|
4
|
+
this.listeners = new Set();
|
|
5
|
+
}
|
|
6
|
+
/** Enqueue a user message to be delivered at the next turn boundary. */
|
|
7
|
+
push(content) {
|
|
8
|
+
this.items.push({ content, at: Date.now() });
|
|
9
|
+
this.emit();
|
|
10
|
+
}
|
|
11
|
+
/** Remove and return the oldest queued message (FIFO), or undefined if empty. */
|
|
12
|
+
shift() {
|
|
13
|
+
const m = this.items.shift();
|
|
14
|
+
if (m)
|
|
15
|
+
this.emit();
|
|
16
|
+
return m;
|
|
17
|
+
}
|
|
18
|
+
peek() {
|
|
19
|
+
return this.items[0];
|
|
20
|
+
}
|
|
21
|
+
get size() {
|
|
22
|
+
return this.items.length;
|
|
23
|
+
}
|
|
24
|
+
/** Snapshot of pending messages (does not drain). */
|
|
25
|
+
list() {
|
|
26
|
+
return this.items.slice();
|
|
27
|
+
}
|
|
28
|
+
clear() {
|
|
29
|
+
if (!this.items.length)
|
|
30
|
+
return;
|
|
31
|
+
this.items = [];
|
|
32
|
+
this.emit();
|
|
33
|
+
}
|
|
34
|
+
/** Subscribe to size changes (push/shift/clear). Returns an unsubscribe fn. */
|
|
35
|
+
onChange(fn) {
|
|
36
|
+
this.listeners.add(fn);
|
|
37
|
+
return () => this.listeners.delete(fn);
|
|
38
|
+
}
|
|
39
|
+
emit() {
|
|
40
|
+
for (const fn of this.listeners)
|
|
41
|
+
fn(this.items.length);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { CommandExecutor, FileSystem } from '../types/index.js';
|
|
2
|
+
import type { Sandbox } from './types.js';
|
|
3
|
+
interface CfExecResult {
|
|
4
|
+
stdout?: string;
|
|
5
|
+
stderr?: string;
|
|
6
|
+
exitCode?: number;
|
|
7
|
+
}
|
|
8
|
+
interface CfFileEntry {
|
|
9
|
+
name: string;
|
|
10
|
+
isDir?: boolean;
|
|
11
|
+
type?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface CloudflareClientLike {
|
|
14
|
+
exec(command: string, opts?: {
|
|
15
|
+
cwd?: string;
|
|
16
|
+
}): Promise<CfExecResult>;
|
|
17
|
+
readFile?(path: string): Promise<string | {
|
|
18
|
+
content?: string;
|
|
19
|
+
}>;
|
|
20
|
+
writeFile?(path: string, content: string): Promise<unknown>;
|
|
21
|
+
mkdir?(path: string, opts?: {
|
|
22
|
+
recursive?: boolean;
|
|
23
|
+
}): Promise<unknown>;
|
|
24
|
+
deleteFile?(path: string): Promise<unknown>;
|
|
25
|
+
listFiles?(path: string): Promise<CfFileEntry[]>;
|
|
26
|
+
}
|
|
27
|
+
export declare class CloudflareSandbox implements Sandbox, FileSystem, CommandExecutor {
|
|
28
|
+
private readonly client;
|
|
29
|
+
readonly cwd: string;
|
|
30
|
+
constructor(client: CloudflareClientLike, cwd?: string);
|
|
31
|
+
private r;
|
|
32
|
+
readFile(path: string): Promise<string | null>;
|
|
33
|
+
readBinary(path: string): Promise<Uint8Array | null>;
|
|
34
|
+
writeFile(path: string, contents: string): Promise<void>;
|
|
35
|
+
writeBinary(path: string, data: Uint8Array): Promise<void>;
|
|
36
|
+
deleteFile(path: string): Promise<void>;
|
|
37
|
+
readdir(path: string): Promise<Array<{
|
|
38
|
+
name: string;
|
|
39
|
+
isDir: boolean;
|
|
40
|
+
}> | null>;
|
|
41
|
+
mkdir(path: string): Promise<void>;
|
|
42
|
+
exec(command: string, _timeoutMs?: number, _env?: Record<string, string>): Promise<{
|
|
43
|
+
output: string;
|
|
44
|
+
exitCode: number;
|
|
45
|
+
}>;
|
|
46
|
+
}
|
|
47
|
+
export declare function createCloudflareSandbox(client: CloudflareClientLike, cwd?: string): CloudflareSandbox;
|
|
48
|
+
export {};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
// Cloudflare Sandbox adapter.
|
|
2
|
+
//
|
|
3
|
+
// Wrap a `@cloudflare/sandbox` instance (Cloudflare Containers):
|
|
4
|
+
//
|
|
5
|
+
// import { getSandbox } from '@cloudflare/sandbox'
|
|
6
|
+
// const sbx = getSandbox(env.Sandbox, 'my-session')
|
|
7
|
+
// const workspace = new CloudflareSandbox(sbx)
|
|
8
|
+
//
|
|
9
|
+
// Methods used:
|
|
10
|
+
// sbx.exec(command) -> { stdout, stderr, exitCode }
|
|
11
|
+
// sbx.readFile(path) -> string | { content: string }
|
|
12
|
+
// sbx.writeFile(path, content)
|
|
13
|
+
// sbx.mkdir(path, { recursive })
|
|
14
|
+
// sbx.deleteFile(path)
|
|
15
|
+
// sbx.listFiles(path) (optional; falls back to `ls -1Ap` via exec)
|
|
16
|
+
import { resolvePath } from '../util/paths.js';
|
|
17
|
+
import { base64ToBytes, bytesToBase64, shellQuote } from './util.js';
|
|
18
|
+
const encoder = new TextEncoder();
|
|
19
|
+
export class CloudflareSandbox {
|
|
20
|
+
constructor(client, cwd = '/workspace') {
|
|
21
|
+
this.client = client;
|
|
22
|
+
this.cwd = cwd;
|
|
23
|
+
}
|
|
24
|
+
r(p) {
|
|
25
|
+
return resolvePath(this.cwd, p);
|
|
26
|
+
}
|
|
27
|
+
async readFile(path) {
|
|
28
|
+
const abs = this.r(path);
|
|
29
|
+
if (this.client.readFile) {
|
|
30
|
+
try {
|
|
31
|
+
const res = await this.client.readFile(abs);
|
|
32
|
+
if (typeof res === 'string')
|
|
33
|
+
return res;
|
|
34
|
+
return res?.content ?? null;
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const res = await this.client.exec(`cat ${shellQuote(abs)}`);
|
|
41
|
+
return (res.exitCode ?? 0) === 0 ? (res.stdout ?? '') : null;
|
|
42
|
+
}
|
|
43
|
+
async readBinary(path) {
|
|
44
|
+
// No portable native binary read; round-trip through base64 over exec.
|
|
45
|
+
const abs = this.r(path);
|
|
46
|
+
const res = await this.client.exec(`base64 ${shellQuote(abs)} | tr -d '\\n'`);
|
|
47
|
+
if ((res.exitCode ?? 0) !== 0) {
|
|
48
|
+
// Fall back to a text read if base64 is unavailable.
|
|
49
|
+
const text = await this.readFile(path);
|
|
50
|
+
return text === null ? null : encoder.encode(text);
|
|
51
|
+
}
|
|
52
|
+
try {
|
|
53
|
+
return base64ToBytes((res.stdout ?? '').trim());
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
async writeFile(path, contents) {
|
|
60
|
+
const abs = this.r(path);
|
|
61
|
+
if (this.client.writeFile) {
|
|
62
|
+
await this.client.writeFile(abs, contents);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
await this.client.exec(`mkdir -p ${shellQuote(dir(abs))} && cat > ${shellQuote(abs)} <<'BCS_EOF'\n${contents}\nBCS_EOF`);
|
|
66
|
+
}
|
|
67
|
+
async writeBinary(path, data) {
|
|
68
|
+
const abs = this.r(path);
|
|
69
|
+
// base64-decode through the shell so arbitrary bytes survive.
|
|
70
|
+
const b64 = bytesToBase64(data);
|
|
71
|
+
const res = await this.client.exec(`mkdir -p ${shellQuote(dir(abs))} && printf %s ${shellQuote(b64)} | base64 -d > ${shellQuote(abs)}`);
|
|
72
|
+
if ((res.exitCode ?? 0) !== 0) {
|
|
73
|
+
throw new Error(`writeBinary failed: ${res.stderr ?? res.stdout ?? ''}`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
async deleteFile(path) {
|
|
77
|
+
const abs = this.r(path);
|
|
78
|
+
if (this.client.deleteFile) {
|
|
79
|
+
await this.client.deleteFile(abs);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
await this.client.exec(`rm -rf ${shellQuote(abs)}`);
|
|
83
|
+
}
|
|
84
|
+
async readdir(path) {
|
|
85
|
+
const abs = this.r(path);
|
|
86
|
+
if (this.client.listFiles) {
|
|
87
|
+
try {
|
|
88
|
+
const entries = await this.client.listFiles(abs);
|
|
89
|
+
return entries.map((e) => ({ name: e.name, isDir: e.isDir ?? e.type === 'dir' }));
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
const res = await this.client.exec(`ls -1Ap ${shellQuote(abs)}`);
|
|
96
|
+
if ((res.exitCode ?? 0) !== 0)
|
|
97
|
+
return null;
|
|
98
|
+
return (res.stdout ?? '')
|
|
99
|
+
.split('\n')
|
|
100
|
+
.map((l) => l.trim())
|
|
101
|
+
.filter(Boolean)
|
|
102
|
+
.map((name) => name.endsWith('/') ? { name: name.slice(0, -1), isDir: true } : { name, isDir: false });
|
|
103
|
+
}
|
|
104
|
+
async mkdir(path) {
|
|
105
|
+
const abs = this.r(path);
|
|
106
|
+
if (this.client.mkdir) {
|
|
107
|
+
await this.client.mkdir(abs, { recursive: true });
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
await this.client.exec(`mkdir -p ${shellQuote(abs)}`);
|
|
111
|
+
}
|
|
112
|
+
async exec(command, _timeoutMs, _env) {
|
|
113
|
+
const res = await this.client.exec(command, { cwd: this.cwd });
|
|
114
|
+
const out = (res.stdout ?? '') + (res.stderr ? '\n' + res.stderr : '');
|
|
115
|
+
return { output: out.trimEnd(), exitCode: res.exitCode ?? 0 };
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function dir(p) {
|
|
119
|
+
const i = p.lastIndexOf('/');
|
|
120
|
+
return i <= 0 ? '/' : p.slice(0, i);
|
|
121
|
+
}
|
|
122
|
+
export function createCloudflareSandbox(client, cwd) {
|
|
123
|
+
return new CloudflareSandbox(client, cwd);
|
|
124
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { CommandExecutor, FileSystem } from '../types/index.js';
|
|
2
|
+
import type { Sandbox } from './types.js';
|
|
3
|
+
interface DaytonaFileInfo {
|
|
4
|
+
name: string;
|
|
5
|
+
isDir?: boolean;
|
|
6
|
+
isDirectory?: boolean;
|
|
7
|
+
}
|
|
8
|
+
interface DaytonaExecResult {
|
|
9
|
+
exitCode?: number;
|
|
10
|
+
result?: string;
|
|
11
|
+
artifacts?: {
|
|
12
|
+
stdout?: string;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export interface DaytonaClientLike {
|
|
16
|
+
fs: {
|
|
17
|
+
uploadFile(content: Uint8Array, destPath: string): Promise<unknown>;
|
|
18
|
+
downloadFile(path: string): Promise<Uint8Array | ArrayBuffer | string>;
|
|
19
|
+
listFiles(path: string): Promise<DaytonaFileInfo[]>;
|
|
20
|
+
deleteFile(path: string): Promise<unknown>;
|
|
21
|
+
createFolder(path: string, mode?: string): Promise<unknown>;
|
|
22
|
+
};
|
|
23
|
+
process: {
|
|
24
|
+
executeCommand(command: string, cwd?: string, env?: Record<string, string>, timeout?: number): Promise<DaytonaExecResult>;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export declare class DaytonaSandbox implements Sandbox, FileSystem, CommandExecutor {
|
|
28
|
+
private readonly client;
|
|
29
|
+
readonly cwd: string;
|
|
30
|
+
constructor(client: DaytonaClientLike, cwd?: string);
|
|
31
|
+
private r;
|
|
32
|
+
readBinary(path: string): Promise<Uint8Array | null>;
|
|
33
|
+
readFile(path: string): Promise<string | null>;
|
|
34
|
+
writeBinary(path: string, data: Uint8Array): Promise<void>;
|
|
35
|
+
writeFile(path: string, contents: string): Promise<void>;
|
|
36
|
+
deleteFile(path: string): Promise<void>;
|
|
37
|
+
readdir(path: string): Promise<Array<{
|
|
38
|
+
name: string;
|
|
39
|
+
isDir: boolean;
|
|
40
|
+
}> | null>;
|
|
41
|
+
mkdir(path: string): Promise<void>;
|
|
42
|
+
exec(command: string, timeoutMs?: number, env?: Record<string, string>): Promise<{
|
|
43
|
+
output: string;
|
|
44
|
+
exitCode: number;
|
|
45
|
+
}>;
|
|
46
|
+
}
|
|
47
|
+
export declare function createDaytonaSandbox(client: DaytonaClientLike, cwd?: string): DaytonaSandbox;
|
|
48
|
+
export {};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// Daytona sandbox adapter.
|
|
2
|
+
//
|
|
3
|
+
// Wrap a Daytona `Sandbox` (from `@daytonaio/sdk`):
|
|
4
|
+
//
|
|
5
|
+
// import { Daytona } from '@daytonaio/sdk'
|
|
6
|
+
// const daytona = new Daytona()
|
|
7
|
+
// const sbx = await daytona.create()
|
|
8
|
+
// const workspace = new DaytonaSandbox(sbx)
|
|
9
|
+
//
|
|
10
|
+
// Methods used:
|
|
11
|
+
// sbx.fs.uploadFile(content: Uint8Array, destPath) // some SDK versions: (destPath, content)
|
|
12
|
+
// sbx.fs.downloadFile(path) -> Uint8Array
|
|
13
|
+
// sbx.fs.listFiles(path) -> FileInfo[] { name, isDir }
|
|
14
|
+
// sbx.fs.deleteFile(path)
|
|
15
|
+
// sbx.fs.createFolder(path, mode?)
|
|
16
|
+
// sbx.process.executeCommand(command, cwd?, env?, timeout?) -> { exitCode, result | artifacts.stdout }
|
|
17
|
+
import { resolvePath } from '../util/paths.js';
|
|
18
|
+
const decoder = new TextDecoder();
|
|
19
|
+
const encoder = new TextEncoder();
|
|
20
|
+
export class DaytonaSandbox {
|
|
21
|
+
constructor(client, cwd = '/home/daytona') {
|
|
22
|
+
this.client = client;
|
|
23
|
+
this.cwd = cwd;
|
|
24
|
+
}
|
|
25
|
+
r(p) {
|
|
26
|
+
return resolvePath(this.cwd, p);
|
|
27
|
+
}
|
|
28
|
+
async readBinary(path) {
|
|
29
|
+
try {
|
|
30
|
+
const data = await this.client.fs.downloadFile(this.r(path));
|
|
31
|
+
if (data instanceof Uint8Array)
|
|
32
|
+
return data;
|
|
33
|
+
if (data instanceof ArrayBuffer)
|
|
34
|
+
return new Uint8Array(data);
|
|
35
|
+
if (typeof data === 'string')
|
|
36
|
+
return encoder.encode(data);
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
async readFile(path) {
|
|
44
|
+
const bytes = await this.readBinary(path);
|
|
45
|
+
return bytes === null ? null : decoder.decode(bytes);
|
|
46
|
+
}
|
|
47
|
+
async writeBinary(path, data) {
|
|
48
|
+
await this.client.fs.uploadFile(data, this.r(path));
|
|
49
|
+
}
|
|
50
|
+
async writeFile(path, contents) {
|
|
51
|
+
await this.writeBinary(path, encoder.encode(contents));
|
|
52
|
+
}
|
|
53
|
+
async deleteFile(path) {
|
|
54
|
+
await this.client.fs.deleteFile(this.r(path));
|
|
55
|
+
}
|
|
56
|
+
async readdir(path) {
|
|
57
|
+
try {
|
|
58
|
+
const entries = await this.client.fs.listFiles(this.r(path));
|
|
59
|
+
return entries.map((e) => ({
|
|
60
|
+
name: e.name,
|
|
61
|
+
isDir: e.isDir ?? e.isDirectory ?? false,
|
|
62
|
+
}));
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
async mkdir(path) {
|
|
69
|
+
await this.client.fs.createFolder(this.r(path), '755');
|
|
70
|
+
}
|
|
71
|
+
async exec(command, timeoutMs, env) {
|
|
72
|
+
const res = await this.client.process.executeCommand(command, this.cwd, env, timeoutMs != null ? Math.ceil(timeoutMs / 1000) : undefined);
|
|
73
|
+
const out = res.result ?? res.artifacts?.stdout ?? '';
|
|
74
|
+
return { output: out.trimEnd(), exitCode: res.exitCode ?? 0 };
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
export function createDaytonaSandbox(client, cwd) {
|
|
78
|
+
return new DaytonaSandbox(client, cwd);
|
|
79
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { CommandExecutor, FileSystem } from '../types/index.js';
|
|
2
|
+
import type { Sandbox } from './types.js';
|
|
3
|
+
interface E2BEntry {
|
|
4
|
+
name: string;
|
|
5
|
+
type?: 'file' | 'dir';
|
|
6
|
+
isDir?: boolean;
|
|
7
|
+
}
|
|
8
|
+
interface E2BCommandResult {
|
|
9
|
+
stdout?: string;
|
|
10
|
+
stderr?: string;
|
|
11
|
+
exitCode?: number;
|
|
12
|
+
}
|
|
13
|
+
export interface E2BClientLike {
|
|
14
|
+
files: {
|
|
15
|
+
read(path: string, opts?: {
|
|
16
|
+
format?: 'text' | 'bytes' | 'blob' | 'stream';
|
|
17
|
+
}): Promise<unknown>;
|
|
18
|
+
write(path: string, data: string | Uint8Array): Promise<unknown>;
|
|
19
|
+
list(path: string): Promise<E2BEntry[]>;
|
|
20
|
+
remove(path: string): Promise<unknown>;
|
|
21
|
+
makeDir(path: string): Promise<unknown>;
|
|
22
|
+
};
|
|
23
|
+
commands: {
|
|
24
|
+
run(cmd: string, opts?: {
|
|
25
|
+
timeoutMs?: number;
|
|
26
|
+
envs?: Record<string, string>;
|
|
27
|
+
cwd?: string;
|
|
28
|
+
background?: false;
|
|
29
|
+
}): Promise<E2BCommandResult>;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export declare class E2BSandbox implements Sandbox, FileSystem, CommandExecutor {
|
|
33
|
+
private readonly client;
|
|
34
|
+
readonly cwd: string;
|
|
35
|
+
constructor(client: E2BClientLike, cwd?: string);
|
|
36
|
+
private r;
|
|
37
|
+
readFile(path: string): Promise<string | null>;
|
|
38
|
+
readBinary(path: string): Promise<Uint8Array | null>;
|
|
39
|
+
writeFile(path: string, contents: string): Promise<void>;
|
|
40
|
+
writeBinary(path: string, data: Uint8Array): Promise<void>;
|
|
41
|
+
deleteFile(path: string): Promise<void>;
|
|
42
|
+
readdir(path: string): Promise<Array<{
|
|
43
|
+
name: string;
|
|
44
|
+
isDir: boolean;
|
|
45
|
+
}> | null>;
|
|
46
|
+
mkdir(path: string): Promise<void>;
|
|
47
|
+
exec(command: string, timeoutMs?: number, env?: Record<string, string>): Promise<{
|
|
48
|
+
output: string;
|
|
49
|
+
exitCode: number;
|
|
50
|
+
}>;
|
|
51
|
+
}
|
|
52
|
+
/** Convenience factory mirroring `new E2BSandbox(client, cwd)`. */
|
|
53
|
+
export declare function createE2BSandbox(client: E2BClientLike, cwd?: string): E2BSandbox;
|
|
54
|
+
export {};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// E2B sandbox adapter.
|
|
2
|
+
//
|
|
3
|
+
// Wrap an E2B `Sandbox` (from the `e2b` or `@e2b/code-interpreter` package):
|
|
4
|
+
//
|
|
5
|
+
// import { Sandbox } from 'e2b'
|
|
6
|
+
// const sbx = await Sandbox.create()
|
|
7
|
+
// const workspace = new E2BSandbox(sbx)
|
|
8
|
+
//
|
|
9
|
+
// Methods used (E2B JS SDK):
|
|
10
|
+
// sbx.files.read(path, { format }) // 'text' -> string, 'bytes' -> Uint8Array
|
|
11
|
+
// sbx.files.write(path, data)
|
|
12
|
+
// sbx.files.list(path) // EntryInfo[] { name, type: 'file'|'dir' }
|
|
13
|
+
// sbx.files.remove(path)
|
|
14
|
+
// sbx.files.makeDir(path)
|
|
15
|
+
// sbx.commands.run(cmd, { timeoutMs, envs, cwd }) // { stdout, stderr, exitCode }
|
|
16
|
+
import { resolvePath } from '../util/paths.js';
|
|
17
|
+
const decoder = new TextDecoder();
|
|
18
|
+
export class E2BSandbox {
|
|
19
|
+
constructor(client, cwd = '/home/user') {
|
|
20
|
+
this.client = client;
|
|
21
|
+
this.cwd = cwd;
|
|
22
|
+
}
|
|
23
|
+
r(p) {
|
|
24
|
+
return resolvePath(this.cwd, p);
|
|
25
|
+
}
|
|
26
|
+
async readFile(path) {
|
|
27
|
+
try {
|
|
28
|
+
const data = await this.client.files.read(this.r(path), { format: 'text' });
|
|
29
|
+
return typeof data === 'string' ? data : decoder.decode(data);
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async readBinary(path) {
|
|
36
|
+
try {
|
|
37
|
+
const data = await this.client.files.read(this.r(path), { format: 'bytes' });
|
|
38
|
+
if (data instanceof Uint8Array)
|
|
39
|
+
return data;
|
|
40
|
+
if (data instanceof ArrayBuffer)
|
|
41
|
+
return new Uint8Array(data);
|
|
42
|
+
if (typeof data === 'string')
|
|
43
|
+
return new TextEncoder().encode(data);
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
async writeFile(path, contents) {
|
|
51
|
+
await this.client.files.write(this.r(path), contents);
|
|
52
|
+
}
|
|
53
|
+
async writeBinary(path, data) {
|
|
54
|
+
await this.client.files.write(this.r(path), data);
|
|
55
|
+
}
|
|
56
|
+
async deleteFile(path) {
|
|
57
|
+
await this.client.files.remove(this.r(path));
|
|
58
|
+
}
|
|
59
|
+
async readdir(path) {
|
|
60
|
+
try {
|
|
61
|
+
const entries = await this.client.files.list(this.r(path));
|
|
62
|
+
return entries.map((e) => ({
|
|
63
|
+
name: e.name,
|
|
64
|
+
isDir: e.isDir ?? e.type === 'dir',
|
|
65
|
+
}));
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
async mkdir(path) {
|
|
72
|
+
await this.client.files.makeDir(this.r(path));
|
|
73
|
+
}
|
|
74
|
+
async exec(command, timeoutMs = 120_000, env) {
|
|
75
|
+
const res = await this.client.commands.run(command, {
|
|
76
|
+
timeoutMs,
|
|
77
|
+
envs: env,
|
|
78
|
+
cwd: this.cwd,
|
|
79
|
+
});
|
|
80
|
+
const out = (res.stdout ?? '') + (res.stderr ? '\n' + res.stderr : '');
|
|
81
|
+
return { output: out.trimEnd(), exitCode: res.exitCode ?? 0 };
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/** Convenience factory mirroring `new E2BSandbox(client, cwd)`. */
|
|
85
|
+
export function createE2BSandbox(client, cwd) {
|
|
86
|
+
return new E2BSandbox(client, cwd);
|
|
87
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './types.js';
|
|
2
|
+
export { LocalSandbox, createLocalSandbox, detectPlatform, type Platform, type LocalSandboxOptions, } from './local.js';
|
|
3
|
+
export { E2BSandbox, createE2BSandbox, type E2BClientLike } from './e2b.js';
|
|
4
|
+
export { VercelSandbox, createVercelSandbox, type VercelClientLike } from './vercel.js';
|
|
5
|
+
export { DaytonaSandbox, createDaytonaSandbox, type DaytonaClientLike } from './daytona.js';
|
|
6
|
+
export { CloudflareSandbox, createCloudflareSandbox, type CloudflareClientLike, } from './cloudflare.js';
|
|
7
|
+
export { WebContainerWorkspace, type WebContainerLike } from '../workspace/webcontainer.js';
|
|
8
|
+
export { NoopCommandExecutor } from '../workspace/memory.js';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Sandbox providers — pluggable backends implementing the `Sandbox`
|
|
2
|
+
// (FileSystem + CommandExecutor) interface.
|
|
3
|
+
//
|
|
4
|
+
// Supported: WebContainer, E2B, Vercel Sandbox, Daytona, Cloudflare Sandbox.
|
|
5
|
+
// Each adapter wraps the provider's client structurally (no hard SDK dependency
|
|
6
|
+
// — install only the provider you use). `composeWorkspace` mixes any FileSystem
|
|
7
|
+
// with any CommandExecutor.
|
|
8
|
+
export * from './types.js';
|
|
9
|
+
export { LocalSandbox, createLocalSandbox, detectPlatform, } from './local.js';
|
|
10
|
+
export { E2BSandbox, createE2BSandbox } from './e2b.js';
|
|
11
|
+
export { VercelSandbox, createVercelSandbox } from './vercel.js';
|
|
12
|
+
export { DaytonaSandbox, createDaytonaSandbox } from './daytona.js';
|
|
13
|
+
export { CloudflareSandbox, createCloudflareSandbox, } from './cloudflare.js';
|
|
14
|
+
// WebContainer lives in workspace/ but is re-exported here so every sandbox
|
|
15
|
+
// provider is reachable from a single import.
|
|
16
|
+
export { WebContainerWorkspace } from '../workspace/webcontainer.js';
|
|
17
|
+
// NoopCommandExecutor (a CommandExecutor that refuses to run anything) pairs
|
|
18
|
+
// with composeWorkspace for file-only agents.
|
|
19
|
+
export { NoopCommandExecutor } from '../workspace/memory.js';
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { Sandbox } from './types.js';
|
|
2
|
+
export type Platform = 'windows' | 'mac' | 'linux' | 'unknown';
|
|
3
|
+
/** Detect the host platform from process.platform. */
|
|
4
|
+
export declare function detectPlatform(): Platform;
|
|
5
|
+
export interface LocalSandboxOptions {
|
|
6
|
+
/** Working directory. Defaults to process.cwd(). */
|
|
7
|
+
cwd?: string;
|
|
8
|
+
/** Override the shell binary (default: cmd.exe on Windows, $SHELL or /bin/sh elsewhere). */
|
|
9
|
+
shell?: string;
|
|
10
|
+
/** Override shell args; the command string is appended as the final arg. */
|
|
11
|
+
shellArgs?: string[];
|
|
12
|
+
/** Extra environment variables merged over process.env. */
|
|
13
|
+
env?: Record<string, string>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* A Sandbox backed by the local OS filesystem and shell. Pair with an Anthropic/
|
|
17
|
+
* OpenAI client and pass to `query()` to run the agent on real files:
|
|
18
|
+
*
|
|
19
|
+
* const workspace = new LocalSandbox({ cwd: '/path/to/project' })
|
|
20
|
+
* query({ prompt, workspace, llm })
|
|
21
|
+
*/
|
|
22
|
+
export declare class LocalSandbox implements Sandbox {
|
|
23
|
+
readonly cwd: string;
|
|
24
|
+
readonly platform: Platform;
|
|
25
|
+
private opts;
|
|
26
|
+
private _fs?;
|
|
27
|
+
private _path?;
|
|
28
|
+
private _cp?;
|
|
29
|
+
constructor(options?: LocalSandboxOptions);
|
|
30
|
+
private fs;
|
|
31
|
+
private path;
|
|
32
|
+
private cp;
|
|
33
|
+
private resolve;
|
|
34
|
+
readFile(p: string): Promise<string | null>;
|
|
35
|
+
readBinary(p: string): Promise<Uint8Array | null>;
|
|
36
|
+
writeFile(p: string, contents: string): Promise<void>;
|
|
37
|
+
writeBinary(p: string, data: Uint8Array): Promise<void>;
|
|
38
|
+
deleteFile(p: string): Promise<void>;
|
|
39
|
+
readdir(p: string): Promise<Array<{
|
|
40
|
+
name: string;
|
|
41
|
+
isDir: boolean;
|
|
42
|
+
}> | null>;
|
|
43
|
+
mkdir(p: string): Promise<void>;
|
|
44
|
+
exec(command: string, timeoutMs?: number, env?: Record<string, string>): Promise<{
|
|
45
|
+
output: string;
|
|
46
|
+
exitCode: number;
|
|
47
|
+
}>;
|
|
48
|
+
/** Pick the shell + args for the detected platform (overridable via options). */
|
|
49
|
+
private shellFor;
|
|
50
|
+
}
|
|
51
|
+
export declare function createLocalSandbox(options?: LocalSandboxOptions): LocalSandbox;
|