@opencoredev/sandbox-sdk 0.2.0 → 1.0.0-beta.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/CHANGELOG.md +32 -11
- package/README.md +350 -25
- package/dist/ai.d.ts +5 -0
- package/dist/ai.js +1 -0
- package/dist/chunk-59t3rqja.js +2 -0
- package/dist/chunk-cwx6cc31.js +2 -0
- package/dist/chunk-exv1kf89.js +60 -0
- package/dist/chunk-gc8zdxyb.js +2 -0
- package/dist/chunk-hjzhc3qg.js +40 -0
- package/dist/chunk-md6fmprc.js +1 -0
- package/dist/chunk-t5vr9nd8.js +8 -0
- package/dist/chunk-v6y7eqxw.js +27 -0
- package/dist/chunk-yed8mvs7.js +2 -0
- package/dist/chunk-yrsb6hws.js +5 -0
- package/dist/chunk-z9rjzn28.js +2 -0
- package/dist/errors.d.ts +60 -0
- package/dist/files.d.ts +57 -0
- package/dist/git.d.ts +28 -0
- package/dist/handle.d.ts +4 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +1 -0
- package/dist/keys.d.ts +5 -0
- package/dist/logs.d.ts +8 -0
- package/dist/mastra.d.ts +43 -0
- package/dist/mastra.js +1 -0
- package/dist/memory.d.ts +34 -0
- package/dist/memory.js +11 -0
- package/dist/openai.d.ts +39 -0
- package/dist/openai.js +1 -0
- package/dist/peer.d.ts +5 -0
- package/dist/processes.d.ts +71 -0
- package/dist/provider.d.ts +138 -0
- package/dist/provider.js +0 -0
- package/dist/providers/agentos/errors.d.ts +4 -0
- package/dist/providers/agentos/index.d.ts +11 -0
- package/dist/providers/agentos/index.js +2 -0
- package/dist/providers/boat/index.d.ts +23 -0
- package/dist/providers/boat/index.js +1 -0
- package/dist/providers/boat-api/errors.d.ts +6 -0
- package/dist/providers/boat-api/exec.d.ts +11 -0
- package/dist/providers/boat-api/index.d.ts +22 -0
- package/dist/providers/boxd/errors.d.ts +3 -0
- package/dist/providers/boxd/execute.d.ts +3 -0
- package/dist/providers/boxd/guest.d.ts +14 -0
- package/dist/providers/boxd/index.d.ts +23 -0
- package/dist/providers/boxd/index.js +85 -0
- package/dist/providers/boxd/transfers.d.ts +19 -0
- package/dist/providers/daytona/buffered.d.ts +3 -0
- package/dist/providers/daytona/errors.d.ts +3 -0
- package/dist/providers/daytona/exec.d.ts +14 -0
- package/dist/providers/daytona/index.d.ts +24 -0
- package/dist/providers/daytona/index.js +88 -0
- package/dist/providers/e2b/errors.d.ts +3 -0
- package/dist/providers/e2b/index.d.ts +15 -0
- package/dist/providers/e2b/index.js +1 -0
- package/dist/providers/freestyle/deadline.d.ts +4 -0
- package/dist/providers/freestyle/errors.d.ts +16 -0
- package/dist/providers/freestyle/execute.d.ts +12 -0
- package/dist/providers/freestyle/index.d.ts +14 -0
- package/dist/providers/freestyle/index.js +133 -0
- package/dist/providers/freestyle/wire.d.ts +10 -0
- package/dist/providers/local/docker.d.ts +32 -0
- package/dist/providers/local/index.d.ts +17 -0
- package/dist/providers/local/index.js +2 -0
- package/dist/providers/railway/errors.d.ts +4 -0
- package/dist/providers/railway/index.d.ts +24 -0
- package/dist/providers/railway/index.js +1 -0
- package/dist/providers/sandboxer/index.d.ts +33 -0
- package/dist/providers/sandboxer/index.js +1 -0
- package/dist/providers/superserve/bootstrap.d.ts +11 -0
- package/dist/providers/superserve/errors.d.ts +3 -0
- package/dist/providers/superserve/execute.d.ts +13 -0
- package/dist/providers/superserve/index.d.ts +23 -0
- package/dist/providers/superserve/index.js +126 -0
- package/dist/providers/tenki/deadline.d.ts +2 -0
- package/dist/providers/tenki/errors.d.ts +10 -0
- package/dist/providers/tenki/exec.d.ts +4 -0
- package/dist/providers/tenki/files.d.ts +3 -0
- package/dist/providers/tenki/index.d.ts +28 -0
- package/dist/providers/tenki/index.js +172 -0
- package/dist/providers/tenki/ready.d.ts +7 -0
- package/dist/providers/tenki/stream.d.ts +3 -0
- package/dist/providers/upstash/buffered.d.ts +3 -0
- package/dist/providers/upstash/errors.d.ts +3 -0
- package/dist/providers/upstash/exec.d.ts +18 -0
- package/dist/providers/upstash/files.d.ts +15 -0
- package/dist/providers/upstash/index.d.ts +38 -0
- package/dist/providers/upstash/index.js +111 -0
- package/dist/providers/vercel/errors.d.ts +3 -0
- package/dist/providers/vercel/index.d.ts +14 -0
- package/dist/providers/vercel/index.js +1 -0
- package/dist/providers/vercel/provider.d.ts +10 -0
- package/dist/providers/vercel/transport.d.ts +40 -0
- package/dist/run.d.ts +41 -0
- package/dist/testing.d.ts +17 -0
- package/dist/testing.js +6 -0
- package/dist/tool-security.d.ts +9 -0
- package/dist/tools.d.ts +117 -0
- package/dist/tools.js +1 -0
- package/dist/types.d.ts +189 -0
- package/package.json +164 -106
- package/dist/agentos-CbrZW7R0.mjs +0 -390
- package/dist/agentos-CbrZW7R0.mjs.map +0 -1
- package/dist/ai/harness.d.mts +0 -16
- package/dist/ai/harness.mjs +0 -69
- package/dist/ai/harness.mjs.map +0 -1
- package/dist/ai/index.d.mts +0 -54
- package/dist/ai/index.mjs +0 -4
- package/dist/ai-DeFa8yPk.mjs +0 -243
- package/dist/ai-DeFa8yPk.mjs.map +0 -1
- package/dist/capabilities-BWvOVFbH.d.mts +0 -15
- package/dist/capabilities-CaSNd6J1.mjs +0 -125
- package/dist/capabilities-CaSNd6J1.mjs.map +0 -1
- package/dist/capabilities-xs9kaHrK.mjs +0 -28
- package/dist/capabilities-xs9kaHrK.mjs.map +0 -1
- package/dist/errors-BuF9bYOQ.mjs +0 -68
- package/dist/errors-BuF9bYOQ.mjs.map +0 -1
- package/dist/eve/index.d.mts +0 -19
- package/dist/eve/index.mjs +0 -155
- package/dist/eve/index.mjs.map +0 -1
- package/dist/index-CkTwqD0X.d.mts +0 -25
- package/dist/index-Dh9xob2s.d.mts +0 -31
- package/dist/index.d.mts +0 -5
- package/dist/index.mjs +0 -40
- package/dist/index.mjs.map +0 -1
- package/dist/managed-provider-BsZGVQ4I.mjs +0 -148
- package/dist/managed-provider-BsZGVQ4I.mjs.map +0 -1
- package/dist/mastra/index.d.mts +0 -118
- package/dist/mastra/index.mjs +0 -662
- package/dist/mastra/index.mjs.map +0 -1
- package/dist/metadata.d.mts +0 -34
- package/dist/metadata.mjs +0 -135
- package/dist/metadata.mjs.map +0 -1
- package/dist/provider-DOBErkBO.d.mts +0 -91
- package/dist/provider-utils-CfB9nvJx.mjs +0 -57
- package/dist/provider-utils-CfB9nvJx.mjs.map +0 -1
- package/dist/providers/agentos/index.d.mts +0 -7
- package/dist/providers/agentos/index.mjs +0 -9
- package/dist/providers/box/index.d.mts +0 -34
- package/dist/providers/box/index.mjs +0 -348
- package/dist/providers/box/index.mjs.map +0 -1
- package/dist/providers/daytona/index.d.mts +0 -21
- package/dist/providers/daytona/index.mjs +0 -206
- package/dist/providers/daytona/index.mjs.map +0 -1
- package/dist/providers/e2b/index.d.mts +0 -17
- package/dist/providers/e2b/index.mjs +0 -169
- package/dist/providers/e2b/index.mjs.map +0 -1
- package/dist/providers/local/index.d.mts +0 -22
- package/dist/providers/local/index.mjs +0 -22
- package/dist/providers/local/index.mjs.map +0 -1
- package/dist/providers/railway/index.d.mts +0 -29
- package/dist/providers/railway/index.mjs +0 -211
- package/dist/providers/railway/index.mjs.map +0 -1
- package/dist/providers/upstash/index.d.mts +0 -17
- package/dist/providers/upstash/index.mjs +0 -211
- package/dist/providers/upstash/index.mjs.map +0 -1
- package/dist/providers/vercel/index.d.mts +0 -28
- package/dist/providers/vercel/index.mjs +0 -186
- package/dist/providers/vercel/index.mjs.map +0 -1
- package/dist/sandbox-DdEqoXJF.d.mts +0 -26
- package/dist/sandbox-DgtY5hvt.mjs +0 -112
- package/dist/sandbox-DgtY5hvt.mjs.map +0 -1
- package/dist/testing/index.d.mts +0 -27
- package/dist/testing/index.mjs +0 -173
- package/dist/testing/index.mjs.map +0 -1
- package/dist/types-Bv6I2U1c.d.mts +0 -103
package/dist/ai-DeFa8yPk.mjs
DELETED
|
@@ -1,243 +0,0 @@
|
|
|
1
|
-
import { n as isSandboxError, r as normalizeError, t as SandboxError } from "./errors-BuF9bYOQ.mjs";
|
|
2
|
-
import { jsonSchema, tool } from "ai";
|
|
3
|
-
|
|
4
|
-
//#region src/ai/index.ts
|
|
5
|
-
/**
|
|
6
|
-
* Adapt a sandbox-sdk sandbox to AI SDK 7's experimental sandbox contract.
|
|
7
|
-
* The caller continues to own the original sandbox and must stop it.
|
|
8
|
-
*/
|
|
9
|
-
function toAISandboxSession(sandbox, options = {}) {
|
|
10
|
-
const read = async (path, abortSignal) => {
|
|
11
|
-
throwIfAborted(abortSignal);
|
|
12
|
-
try {
|
|
13
|
-
const bytes = await sandbox.files.read(path);
|
|
14
|
-
throwIfAborted(abortSignal);
|
|
15
|
-
return bytes;
|
|
16
|
-
} catch (error) {
|
|
17
|
-
if (isSandboxError(error) && error.code === "not_found") return null;
|
|
18
|
-
throw normalizeError(sandbox.provider, "ai.readFile", error);
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
return {
|
|
22
|
-
description: options.description ?? `${sandbox.provider} sandbox ${sandbox.id}; default working directory: ${sandbox.cwd}`,
|
|
23
|
-
async readFile({ path, abortSignal }) {
|
|
24
|
-
const bytes = await read(path, abortSignal);
|
|
25
|
-
return bytes === null ? null : bytesToStream(bytes);
|
|
26
|
-
},
|
|
27
|
-
readBinaryFile: ({ path, abortSignal }) => read(path, abortSignal),
|
|
28
|
-
async readTextFile({ path, encoding = "utf-8", startLine, endLine, abortSignal }) {
|
|
29
|
-
const bytes = await read(path, abortSignal);
|
|
30
|
-
if (bytes === null) return null;
|
|
31
|
-
const content = decode(bytes, encoding);
|
|
32
|
-
if (startLine === void 0 && endLine === void 0) return content;
|
|
33
|
-
validateLineRange(startLine, endLine);
|
|
34
|
-
return content.split("\n").slice((startLine ?? 1) - 1, endLine).join("\n");
|
|
35
|
-
},
|
|
36
|
-
async writeFile({ path, content, abortSignal }) {
|
|
37
|
-
throwIfAborted(abortSignal);
|
|
38
|
-
await sandbox.files.write(path, abortableStream(content, abortSignal));
|
|
39
|
-
throwIfAborted(abortSignal);
|
|
40
|
-
},
|
|
41
|
-
async writeBinaryFile({ path, content, abortSignal }) {
|
|
42
|
-
throwIfAborted(abortSignal);
|
|
43
|
-
await sandbox.files.write(path, content);
|
|
44
|
-
throwIfAborted(abortSignal);
|
|
45
|
-
},
|
|
46
|
-
async writeTextFile({ path, content, encoding = "utf-8", abortSignal }) {
|
|
47
|
-
throwIfAborted(abortSignal);
|
|
48
|
-
await sandbox.files.write(path, encode(content, encoding));
|
|
49
|
-
throwIfAborted(abortSignal);
|
|
50
|
-
},
|
|
51
|
-
async run({ command, workingDirectory, env, abortSignal }) {
|
|
52
|
-
const result = await sandbox.run(command, {
|
|
53
|
-
cwd: workingDirectory,
|
|
54
|
-
env,
|
|
55
|
-
signal: abortSignal
|
|
56
|
-
});
|
|
57
|
-
return {
|
|
58
|
-
exitCode: result.exitCode,
|
|
59
|
-
stdout: result.stdout,
|
|
60
|
-
stderr: result.stderr
|
|
61
|
-
};
|
|
62
|
-
},
|
|
63
|
-
async spawn({ command, workingDirectory, env, abortSignal }) {
|
|
64
|
-
return toAIProcess(await sandbox.processes.start(command, {
|
|
65
|
-
cwd: workingDirectory,
|
|
66
|
-
env,
|
|
67
|
-
signal: abortSignal
|
|
68
|
-
}), abortSignal);
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
/** Ready-made AI SDK tools that execute only through `experimental_sandbox`. */
|
|
73
|
-
function createSandboxTools() {
|
|
74
|
-
return {
|
|
75
|
-
bash: tool({
|
|
76
|
-
description: "Run a shell command in the sandbox.",
|
|
77
|
-
inputSchema: jsonSchema({
|
|
78
|
-
type: "object",
|
|
79
|
-
properties: {
|
|
80
|
-
command: { type: "string" },
|
|
81
|
-
workingDirectory: { type: "string" },
|
|
82
|
-
env: {
|
|
83
|
-
type: "object",
|
|
84
|
-
additionalProperties: { type: "string" }
|
|
85
|
-
}
|
|
86
|
-
},
|
|
87
|
-
required: ["command"],
|
|
88
|
-
additionalProperties: false
|
|
89
|
-
}),
|
|
90
|
-
async execute(input, context) {
|
|
91
|
-
return requireSandbox(context.experimental_sandbox).run({
|
|
92
|
-
command: input.command,
|
|
93
|
-
workingDirectory: input.workingDirectory,
|
|
94
|
-
env: input.env,
|
|
95
|
-
abortSignal: context.abortSignal
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
}),
|
|
99
|
-
read_file: tool({
|
|
100
|
-
description: "Read a text file from the sandbox. Missing files return null.",
|
|
101
|
-
inputSchema: jsonSchema({
|
|
102
|
-
type: "object",
|
|
103
|
-
properties: {
|
|
104
|
-
path: { type: "string" },
|
|
105
|
-
encoding: { type: "string" },
|
|
106
|
-
startLine: {
|
|
107
|
-
type: "integer",
|
|
108
|
-
minimum: 1
|
|
109
|
-
},
|
|
110
|
-
endLine: {
|
|
111
|
-
type: "integer",
|
|
112
|
-
minimum: 1
|
|
113
|
-
}
|
|
114
|
-
},
|
|
115
|
-
required: ["path"],
|
|
116
|
-
additionalProperties: false
|
|
117
|
-
}),
|
|
118
|
-
async execute(input, context) {
|
|
119
|
-
return { content: await requireSandbox(context.experimental_sandbox).readTextFile({
|
|
120
|
-
...input,
|
|
121
|
-
abortSignal: context.abortSignal
|
|
122
|
-
}) };
|
|
123
|
-
}
|
|
124
|
-
}),
|
|
125
|
-
write_file: tool({
|
|
126
|
-
description: "Write a text file in the sandbox, creating parent directories.",
|
|
127
|
-
inputSchema: jsonSchema({
|
|
128
|
-
type: "object",
|
|
129
|
-
properties: {
|
|
130
|
-
path: { type: "string" },
|
|
131
|
-
content: { type: "string" },
|
|
132
|
-
encoding: { type: "string" }
|
|
133
|
-
},
|
|
134
|
-
required: ["path", "content"],
|
|
135
|
-
additionalProperties: false
|
|
136
|
-
}),
|
|
137
|
-
async execute(input, context) {
|
|
138
|
-
await requireSandbox(context.experimental_sandbox).writeTextFile({
|
|
139
|
-
...input,
|
|
140
|
-
abortSignal: context.abortSignal
|
|
141
|
-
});
|
|
142
|
-
return { written: true };
|
|
143
|
-
}
|
|
144
|
-
})
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
/** Create the AI SDK 7 `toolApproval` policy for the ready-made sandbox tools. */
|
|
148
|
-
function createSandboxToolApproval(approval = "mutations") {
|
|
149
|
-
const status = (mutation) => approval === "always" || approval === "mutations" && mutation ? "user-approval" : "not-applicable";
|
|
150
|
-
return {
|
|
151
|
-
bash: status(true),
|
|
152
|
-
read_file: status(false),
|
|
153
|
-
write_file: status(true)
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
function requireSandbox(value) {
|
|
157
|
-
if (!value) throw new SandboxError({
|
|
158
|
-
code: "invalid_input",
|
|
159
|
-
provider: "ai",
|
|
160
|
-
operation: "tool.execute",
|
|
161
|
-
message: "experimental_sandbox is required to execute sandbox tools"
|
|
162
|
-
});
|
|
163
|
-
return value;
|
|
164
|
-
}
|
|
165
|
-
function toAIProcess(process, abortSignal) {
|
|
166
|
-
let stdoutController;
|
|
167
|
-
let stderrController;
|
|
168
|
-
const stdout = new ReadableStream({ start: (controller) => stdoutController = controller });
|
|
169
|
-
const stderr = new ReadableStream({ start: (controller) => stderrController = controller });
|
|
170
|
-
const pump = (async () => {
|
|
171
|
-
try {
|
|
172
|
-
for await (const event of process.output()) {
|
|
173
|
-
const bytes = typeof event.data === "string" ? new TextEncoder().encode(event.data) : event.data;
|
|
174
|
-
(event.stream === "stdout" ? stdoutController : stderrController).enqueue(bytes);
|
|
175
|
-
}
|
|
176
|
-
stdoutController.close();
|
|
177
|
-
stderrController.close();
|
|
178
|
-
} catch (error) {
|
|
179
|
-
stdoutController.error(error);
|
|
180
|
-
stderrController.error(error);
|
|
181
|
-
}
|
|
182
|
-
})();
|
|
183
|
-
const abort = () => void process.kill();
|
|
184
|
-
abortSignal?.addEventListener("abort", abort, { once: true });
|
|
185
|
-
return {
|
|
186
|
-
pid: Number.isFinite(Number(process.id)) ? Number(process.id) : void 0,
|
|
187
|
-
stdout,
|
|
188
|
-
stderr,
|
|
189
|
-
async wait() {
|
|
190
|
-
try {
|
|
191
|
-
const result = await process.wait();
|
|
192
|
-
await pump;
|
|
193
|
-
if (abortSignal?.aborted) throw abortSignal.reason;
|
|
194
|
-
return result;
|
|
195
|
-
} finally {
|
|
196
|
-
abortSignal?.removeEventListener("abort", abort);
|
|
197
|
-
}
|
|
198
|
-
},
|
|
199
|
-
kill: () => process.kill()
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
function bytesToStream(bytes) {
|
|
203
|
-
return new ReadableStream({ start(controller) {
|
|
204
|
-
controller.enqueue(bytes);
|
|
205
|
-
controller.close();
|
|
206
|
-
} });
|
|
207
|
-
}
|
|
208
|
-
function abortableStream(stream, signal) {
|
|
209
|
-
if (!signal) return stream;
|
|
210
|
-
return stream.pipeThrough(new TransformStream({ transform(chunk, controller) {
|
|
211
|
-
throwIfAborted(signal);
|
|
212
|
-
controller.enqueue(chunk);
|
|
213
|
-
} }), { signal });
|
|
214
|
-
}
|
|
215
|
-
function validateLineRange(startLine, endLine) {
|
|
216
|
-
if (startLine !== void 0 && (!Number.isInteger(startLine) || startLine < 1) || endLine !== void 0 && (!Number.isInteger(endLine) || endLine < 1) || startLine !== void 0 && endLine !== void 0 && endLine < startLine) throw new SandboxError({
|
|
217
|
-
code: "invalid_input",
|
|
218
|
-
provider: "ai",
|
|
219
|
-
operation: "readTextFile",
|
|
220
|
-
message: "Line ranges must be positive, 1-based, inclusive, and ordered"
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
function decode(bytes, encoding) {
|
|
224
|
-
try {
|
|
225
|
-
return encoding.toLowerCase() === "utf-8" || encoding.toLowerCase() === "utf8" ? new TextDecoder("utf-8", { fatal: true }).decode(bytes) : Buffer.from(bytes).toString(encoding);
|
|
226
|
-
} catch (error) {
|
|
227
|
-
throw normalizeError("ai", "files.decode", error, "invalid_input");
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
function encode(value, encoding) {
|
|
231
|
-
try {
|
|
232
|
-
return encoding.toLowerCase() === "utf-8" || encoding.toLowerCase() === "utf8" ? new TextEncoder().encode(value) : new Uint8Array(Buffer.from(value, encoding));
|
|
233
|
-
} catch (error) {
|
|
234
|
-
throw normalizeError("ai", "files.encode", error, "invalid_input");
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
function throwIfAborted(signal) {
|
|
238
|
-
if (signal?.aborted) throw signal.reason ?? new DOMException("The operation was aborted", "AbortError");
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
//#endregion
|
|
242
|
-
export { createSandboxTools as n, toAISandboxSession as r, createSandboxToolApproval as t };
|
|
243
|
-
//# sourceMappingURL=ai-DeFa8yPk.mjs.map
|
package/dist/ai-DeFa8yPk.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ai-DeFa8yPk.mjs","names":["stdoutController!: ReadableStreamDefaultController<Uint8Array>","stderrController!: ReadableStreamDefaultController<Uint8Array>"],"sources":["../src/ai/index.ts"],"sourcesContent":["import { jsonSchema, tool } from \"ai\";\nimport type { Experimental_SandboxProcess, Experimental_SandboxSession, Tool, ToolSet } from \"ai\";\nimport { isSandboxError, normalizeError, SandboxError } from \"../core/errors\";\nimport type { Sandbox, SandboxProcess } from \"../core/types\";\n\nexport interface AISandboxSessionOptions {\n description?: string;\n}\n\nexport type SandboxToolApproval = \"mutations\" | \"always\" | \"never\";\n\nexport type SandboxToolApprovalConfiguration = Readonly<{\n bash: \"user-approval\" | \"not-applicable\";\n read_file: \"user-approval\" | \"not-applicable\";\n write_file: \"user-approval\" | \"not-applicable\";\n}>;\n\n/**\n * Adapt a sandbox-sdk sandbox to AI SDK 7's experimental sandbox contract.\n * The caller continues to own the original sandbox and must stop it.\n */\nexport function toAISandboxSession(\n sandbox: Sandbox,\n options: AISandboxSessionOptions = {},\n): Experimental_SandboxSession {\n const read = async (path: string, abortSignal?: AbortSignal): Promise<Uint8Array | null> => {\n throwIfAborted(abortSignal);\n try {\n const bytes = await sandbox.files.read(path);\n throwIfAborted(abortSignal);\n return bytes;\n } catch (error) {\n if (isSandboxError(error) && error.code === \"not_found\") return null;\n throw normalizeError(sandbox.provider, \"ai.readFile\", error);\n }\n };\n\n return {\n description:\n options.description ??\n `${sandbox.provider} sandbox ${sandbox.id}; default working directory: ${sandbox.cwd}`,\n async readFile({ path, abortSignal }) {\n const bytes = await read(path, abortSignal);\n return bytes === null ? null : bytesToStream(bytes);\n },\n readBinaryFile: ({ path, abortSignal }) => read(path, abortSignal),\n async readTextFile({ path, encoding = \"utf-8\", startLine, endLine, abortSignal }) {\n const bytes = await read(path, abortSignal);\n if (bytes === null) return null;\n const content = decode(bytes, encoding);\n if (startLine === undefined && endLine === undefined) return content;\n validateLineRange(startLine, endLine);\n return content\n .split(\"\\n\")\n .slice((startLine ?? 1) - 1, endLine)\n .join(\"\\n\");\n },\n async writeFile({ path, content, abortSignal }) {\n throwIfAborted(abortSignal);\n await sandbox.files.write(path, abortableStream(content, abortSignal));\n throwIfAborted(abortSignal);\n },\n async writeBinaryFile({ path, content, abortSignal }) {\n throwIfAborted(abortSignal);\n await sandbox.files.write(path, content);\n throwIfAborted(abortSignal);\n },\n async writeTextFile({ path, content, encoding = \"utf-8\", abortSignal }) {\n throwIfAborted(abortSignal);\n await sandbox.files.write(path, encode(content, encoding));\n throwIfAborted(abortSignal);\n },\n async run({ command, workingDirectory, env, abortSignal }) {\n const result = await sandbox.run(command, {\n cwd: workingDirectory,\n env,\n signal: abortSignal,\n });\n return { exitCode: result.exitCode, stdout: result.stdout, stderr: result.stderr };\n },\n async spawn({ command, workingDirectory, env, abortSignal }) {\n const process = await sandbox.processes.start(command, {\n cwd: workingDirectory,\n env,\n signal: abortSignal,\n });\n return toAIProcess(process, abortSignal);\n },\n };\n}\n\ntype BashInput = { command: string; workingDirectory?: string; env?: Record<string, string> };\ntype ReadFileInput = { path: string; encoding?: string; startLine?: number; endLine?: number };\ntype WriteFileInput = { path: string; content: string; encoding?: string };\n\nexport type SandboxTools = ToolSet & {\n bash: Tool<BashInput, { exitCode: number; stdout: string; stderr: string }>;\n read_file: Tool<ReadFileInput, { content: string | null }>;\n write_file: Tool<WriteFileInput, { written: true }>;\n};\n\n/** Ready-made AI SDK tools that execute only through `experimental_sandbox`. */\nexport function createSandboxTools(): SandboxTools {\n return {\n bash: tool({\n description: \"Run a shell command in the sandbox.\",\n inputSchema: jsonSchema<BashInput>({\n type: \"object\",\n properties: {\n command: { type: \"string\" },\n workingDirectory: { type: \"string\" },\n env: { type: \"object\", additionalProperties: { type: \"string\" } },\n },\n required: [\"command\"],\n additionalProperties: false,\n }),\n async execute(input, context) {\n const sandbox = requireSandbox(context.experimental_sandbox);\n return sandbox.run({\n command: input.command,\n workingDirectory: input.workingDirectory,\n env: input.env,\n abortSignal: context.abortSignal,\n });\n },\n }),\n read_file: tool({\n description: \"Read a text file from the sandbox. Missing files return null.\",\n inputSchema: jsonSchema<ReadFileInput>({\n type: \"object\",\n properties: {\n path: { type: \"string\" },\n encoding: { type: \"string\" },\n startLine: { type: \"integer\", minimum: 1 },\n endLine: { type: \"integer\", minimum: 1 },\n },\n required: [\"path\"],\n additionalProperties: false,\n }),\n async execute(input, context) {\n const sandbox = requireSandbox(context.experimental_sandbox);\n return {\n content: await sandbox.readTextFile({\n ...input,\n abortSignal: context.abortSignal,\n }),\n };\n },\n }),\n write_file: tool({\n description: \"Write a text file in the sandbox, creating parent directories.\",\n inputSchema: jsonSchema<WriteFileInput>({\n type: \"object\",\n properties: {\n path: { type: \"string\" },\n content: { type: \"string\" },\n encoding: { type: \"string\" },\n },\n required: [\"path\", \"content\"],\n additionalProperties: false,\n }),\n async execute(input, context) {\n const sandbox = requireSandbox(context.experimental_sandbox);\n await sandbox.writeTextFile({ ...input, abortSignal: context.abortSignal });\n return { written: true as const };\n },\n }),\n };\n}\n\n/** Create the AI SDK 7 `toolApproval` policy for the ready-made sandbox tools. */\nexport function createSandboxToolApproval(\n approval: SandboxToolApproval = \"mutations\",\n): SandboxToolApprovalConfiguration {\n const status = (mutation: boolean) =>\n approval === \"always\" || (approval === \"mutations\" && mutation)\n ? (\"user-approval\" as const)\n : (\"not-applicable\" as const);\n\n return {\n bash: status(true),\n read_file: status(false),\n write_file: status(true),\n };\n}\n\nfunction requireSandbox(\n value: Experimental_SandboxSession | undefined,\n): Experimental_SandboxSession {\n if (!value) {\n throw new SandboxError({\n code: \"invalid_input\",\n provider: \"ai\",\n operation: \"tool.execute\",\n message: \"experimental_sandbox is required to execute sandbox tools\",\n });\n }\n return value;\n}\n\nfunction toAIProcess(\n process: SandboxProcess,\n abortSignal?: AbortSignal,\n): Experimental_SandboxProcess {\n let stdoutController!: ReadableStreamDefaultController<Uint8Array>;\n let stderrController!: ReadableStreamDefaultController<Uint8Array>;\n const stdout = new ReadableStream<Uint8Array>({\n start: (controller) => (stdoutController = controller),\n });\n const stderr = new ReadableStream<Uint8Array>({\n start: (controller) => (stderrController = controller),\n });\n const pump = (async () => {\n try {\n for await (const event of process.output()) {\n const bytes =\n typeof event.data === \"string\" ? new TextEncoder().encode(event.data) : event.data;\n (event.stream === \"stdout\" ? stdoutController : stderrController).enqueue(bytes);\n }\n stdoutController.close();\n stderrController.close();\n } catch (error) {\n stdoutController.error(error);\n stderrController.error(error);\n }\n })();\n const abort = () => void process.kill();\n abortSignal?.addEventListener(\"abort\", abort, { once: true });\n return {\n pid: Number.isFinite(Number(process.id)) ? Number(process.id) : undefined,\n stdout,\n stderr,\n async wait() {\n try {\n const result = await process.wait();\n await pump;\n if (abortSignal?.aborted) throw abortSignal.reason;\n return result;\n } finally {\n abortSignal?.removeEventListener(\"abort\", abort);\n }\n },\n kill: () => process.kill(),\n };\n}\n\nfunction bytesToStream(bytes: Uint8Array): ReadableStream<Uint8Array> {\n return new ReadableStream({\n start(controller) {\n controller.enqueue(bytes);\n controller.close();\n },\n });\n}\n\nfunction abortableStream(\n stream: ReadableStream<Uint8Array>,\n signal?: AbortSignal,\n): ReadableStream<Uint8Array> {\n if (!signal) return stream;\n return stream.pipeThrough(\n new TransformStream({\n transform(chunk, controller) {\n throwIfAborted(signal);\n controller.enqueue(chunk);\n },\n }),\n { signal },\n );\n}\n\nfunction validateLineRange(startLine?: number, endLine?: number): void {\n if (\n (startLine !== undefined && (!Number.isInteger(startLine) || startLine < 1)) ||\n (endLine !== undefined && (!Number.isInteger(endLine) || endLine < 1)) ||\n (startLine !== undefined && endLine !== undefined && endLine < startLine)\n ) {\n throw new SandboxError({\n code: \"invalid_input\",\n provider: \"ai\",\n operation: \"readTextFile\",\n message: \"Line ranges must be positive, 1-based, inclusive, and ordered\",\n });\n }\n}\n\nfunction decode(bytes: Uint8Array, encoding: string): string {\n try {\n return encoding.toLowerCase() === \"utf-8\" || encoding.toLowerCase() === \"utf8\"\n ? new TextDecoder(\"utf-8\", { fatal: true }).decode(bytes)\n : Buffer.from(bytes).toString(encoding as BufferEncoding);\n } catch (error) {\n throw normalizeError(\"ai\", \"files.decode\", error, \"invalid_input\");\n }\n}\n\nfunction encode(value: string, encoding: string): Uint8Array {\n try {\n return encoding.toLowerCase() === \"utf-8\" || encoding.toLowerCase() === \"utf8\"\n ? new TextEncoder().encode(value)\n : new Uint8Array(Buffer.from(value, encoding as BufferEncoding));\n } catch (error) {\n throw normalizeError(\"ai\", \"files.encode\", error, \"invalid_input\");\n }\n}\n\nfunction throwIfAborted(signal?: AbortSignal): void {\n if (signal?.aborted)\n throw signal.reason ?? new DOMException(\"The operation was aborted\", \"AbortError\");\n}\n"],"mappings":";;;;;;;;AAqBA,SAAgB,mBACd,SACA,UAAmC,EAAE,EACR;CAC7B,MAAM,OAAO,OAAO,MAAc,gBAA0D;AAC1F,iBAAe,YAAY;AAC3B,MAAI;GACF,MAAM,QAAQ,MAAM,QAAQ,MAAM,KAAK,KAAK;AAC5C,kBAAe,YAAY;AAC3B,UAAO;WACA,OAAO;AACd,OAAI,eAAe,MAAM,IAAI,MAAM,SAAS,YAAa,QAAO;AAChE,SAAM,eAAe,QAAQ,UA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aAAa,KAAK,SACpE,IAAI,aAAa,CAAC,OAAO,MAAM,GAC/B,IAAI,WAAW,OAAO,KAAK,OAAO,SAA2B,CAAC;UAC3D,OAAO;AACd,QAAM,eAAe,MAAM,gBAAgB,OAAO,gBAAgB;;;AAItE,SAAS,eAAe,QAA4B;AAClD,KAAI,QAAQ,QACV,OAAM,OAAO,UAAU,IAAI,aAAa,6BAA6B,aAAa"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { r as CapabilityMode } from "./types-Bv6I2U1c.mjs";
|
|
2
|
-
|
|
3
|
-
//#region src/providers/capabilities.d.ts
|
|
4
|
-
declare const localCapabilities: Readonly<Record<"files.read" | "files.write" | "files.list" | "files.remove" | "process.run" | "process.stream" | "process.background" | "process.stdin" | "process.cancel" | "ports.expose" | "ports.authenticatedRequest" | "snapshot.create" | "snapshot.delete" | "snapshot.restore" | "sandbox.resume" | "filesystem.persistent" | "image.custom" | "network.policy" | "process.pty" | "compute.gpu", false | CapabilityMode>>;
|
|
5
|
-
/** @deprecated AgentOS capabilities are exposed as Local capabilities. */
|
|
6
|
-
declare const agentosCapabilities: Readonly<Record<"files.read" | "files.write" | "files.list" | "files.remove" | "process.run" | "process.stream" | "process.background" | "process.stdin" | "process.cancel" | "ports.expose" | "ports.authenticatedRequest" | "snapshot.create" | "snapshot.delete" | "snapshot.restore" | "sandbox.resume" | "filesystem.persistent" | "image.custom" | "network.policy" | "process.pty" | "compute.gpu", false | CapabilityMode>>;
|
|
7
|
-
declare const e2bCapabilities: Readonly<Record<"files.read" | "files.write" | "files.list" | "files.remove" | "process.run" | "process.stream" | "process.background" | "process.stdin" | "process.cancel" | "ports.expose" | "ports.authenticatedRequest" | "snapshot.create" | "snapshot.delete" | "snapshot.restore" | "sandbox.resume" | "filesystem.persistent" | "image.custom" | "network.policy" | "process.pty" | "compute.gpu", false | CapabilityMode>>;
|
|
8
|
-
declare const daytonaCapabilities: Readonly<Record<"files.read" | "files.write" | "files.list" | "files.remove" | "process.run" | "process.stream" | "process.background" | "process.stdin" | "process.cancel" | "ports.expose" | "ports.authenticatedRequest" | "snapshot.create" | "snapshot.delete" | "snapshot.restore" | "sandbox.resume" | "filesystem.persistent" | "image.custom" | "network.policy" | "process.pty" | "compute.gpu", false | CapabilityMode>>;
|
|
9
|
-
declare const vercelCapabilities: Readonly<Record<"files.read" | "files.write" | "files.list" | "files.remove" | "process.run" | "process.stream" | "process.background" | "process.stdin" | "process.cancel" | "ports.expose" | "ports.authenticatedRequest" | "snapshot.create" | "snapshot.delete" | "snapshot.restore" | "sandbox.resume" | "filesystem.persistent" | "image.custom" | "network.policy" | "process.pty" | "compute.gpu", false | CapabilityMode>>;
|
|
10
|
-
declare const upstashCapabilities: Readonly<Record<"files.read" | "files.write" | "files.list" | "files.remove" | "process.run" | "process.stream" | "process.background" | "process.stdin" | "process.cancel" | "ports.expose" | "ports.authenticatedRequest" | "snapshot.create" | "snapshot.delete" | "snapshot.restore" | "sandbox.resume" | "filesystem.persistent" | "image.custom" | "network.policy" | "process.pty" | "compute.gpu", false | CapabilityMode>>;
|
|
11
|
-
declare const boxCapabilities: Readonly<Record<"files.read" | "files.write" | "files.list" | "files.remove" | "process.run" | "process.stream" | "process.background" | "process.stdin" | "process.cancel" | "ports.expose" | "ports.authenticatedRequest" | "snapshot.create" | "snapshot.delete" | "snapshot.restore" | "sandbox.resume" | "filesystem.persistent" | "image.custom" | "network.policy" | "process.pty" | "compute.gpu", false | CapabilityMode>>;
|
|
12
|
-
declare const railwayCapabilities: Readonly<Record<"files.read" | "files.write" | "files.list" | "files.remove" | "process.run" | "process.stream" | "process.background" | "process.stdin" | "process.cancel" | "ports.expose" | "ports.authenticatedRequest" | "snapshot.create" | "snapshot.delete" | "snapshot.restore" | "sandbox.resume" | "filesystem.persistent" | "image.custom" | "network.policy" | "process.pty" | "compute.gpu", false | CapabilityMode>>;
|
|
13
|
-
//#endregion
|
|
14
|
-
export { localCapabilities as a, vercelCapabilities as c, e2bCapabilities as i, boxCapabilities as n, railwayCapabilities as o, daytonaCapabilities as r, upstashCapabilities as s, agentosCapabilities as t };
|
|
15
|
-
//# sourceMappingURL=capabilities-BWvOVFbH.d.mts.map
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { n as defineCapabilities } from "./capabilities-xs9kaHrK.mjs";
|
|
2
|
-
|
|
3
|
-
//#region src/providers/capabilities.ts
|
|
4
|
-
const localCapabilities = defineCapabilities({
|
|
5
|
-
"files.read": "full",
|
|
6
|
-
"files.write": "full",
|
|
7
|
-
"files.list": "full",
|
|
8
|
-
"files.remove": "full",
|
|
9
|
-
"process.run": "combined-stream",
|
|
10
|
-
"process.stream": "combined-stream",
|
|
11
|
-
"process.background": "full",
|
|
12
|
-
"process.stdin": "full",
|
|
13
|
-
"process.cancel": "full",
|
|
14
|
-
"ports.expose": "in-process",
|
|
15
|
-
"snapshot.create": "filesystem",
|
|
16
|
-
"snapshot.delete": "filesystem",
|
|
17
|
-
"snapshot.restore": "filesystem",
|
|
18
|
-
"sandbox.resume": "memory",
|
|
19
|
-
"filesystem.persistent": "ephemeral",
|
|
20
|
-
"network.policy": "native"
|
|
21
|
-
});
|
|
22
|
-
/** @deprecated AgentOS capabilities are exposed as Local capabilities. */
|
|
23
|
-
const agentosCapabilities = localCapabilities;
|
|
24
|
-
const e2bCapabilities = defineCapabilities({
|
|
25
|
-
"files.read": "full",
|
|
26
|
-
"files.write": "full",
|
|
27
|
-
"files.list": "full",
|
|
28
|
-
"files.remove": "full",
|
|
29
|
-
"process.run": "separate-streams",
|
|
30
|
-
"process.stream": "separate-streams",
|
|
31
|
-
"process.background": "full",
|
|
32
|
-
"process.stdin": "full",
|
|
33
|
-
"process.cancel": "full",
|
|
34
|
-
"process.pty": "native",
|
|
35
|
-
"ports.expose": "authenticated",
|
|
36
|
-
"ports.authenticatedRequest": "authenticated",
|
|
37
|
-
"snapshot.create": "template",
|
|
38
|
-
"snapshot.delete": "template",
|
|
39
|
-
"sandbox.resume": "memory",
|
|
40
|
-
"filesystem.persistent": "ephemeral",
|
|
41
|
-
"image.custom": "template",
|
|
42
|
-
"network.policy": "native"
|
|
43
|
-
});
|
|
44
|
-
const daytonaCapabilities = defineCapabilities({
|
|
45
|
-
"files.read": "full",
|
|
46
|
-
"files.write": "full",
|
|
47
|
-
"files.list": "full",
|
|
48
|
-
"files.remove": "full",
|
|
49
|
-
"process.run": "combined-stream",
|
|
50
|
-
"process.stream": "separate-streams",
|
|
51
|
-
"process.background": "full",
|
|
52
|
-
"process.stdin": "full",
|
|
53
|
-
"process.cancel": "full",
|
|
54
|
-
"process.pty": "native",
|
|
55
|
-
"ports.expose": "authenticated",
|
|
56
|
-
"ports.authenticatedRequest": "authenticated",
|
|
57
|
-
"filesystem.persistent": "persistent",
|
|
58
|
-
"image.custom": "native",
|
|
59
|
-
"network.policy": "native",
|
|
60
|
-
"compute.gpu": "native"
|
|
61
|
-
});
|
|
62
|
-
const vercelCapabilities = defineCapabilities({
|
|
63
|
-
"files.read": "full",
|
|
64
|
-
"files.write": "full",
|
|
65
|
-
"files.list": "full",
|
|
66
|
-
"files.remove": "full",
|
|
67
|
-
"process.run": "separate-streams",
|
|
68
|
-
"process.stream": "separate-streams",
|
|
69
|
-
"process.background": "full",
|
|
70
|
-
"process.cancel": "full",
|
|
71
|
-
"process.pty": "native",
|
|
72
|
-
"ports.expose": "public",
|
|
73
|
-
"snapshot.create": "filesystem",
|
|
74
|
-
"snapshot.delete": "filesystem",
|
|
75
|
-
"sandbox.resume": "persistent",
|
|
76
|
-
"filesystem.persistent": "persistent",
|
|
77
|
-
"network.policy": "native"
|
|
78
|
-
});
|
|
79
|
-
const upstashCapabilities = defineCapabilities({
|
|
80
|
-
"files.read": "full",
|
|
81
|
-
"files.write": "full",
|
|
82
|
-
"files.list": "full",
|
|
83
|
-
"files.remove": "full",
|
|
84
|
-
"process.run": "combined-stream",
|
|
85
|
-
"process.stream": "combined-stream",
|
|
86
|
-
"process.background": "full",
|
|
87
|
-
"ports.expose": "authenticated",
|
|
88
|
-
"ports.authenticatedRequest": "authenticated",
|
|
89
|
-
"snapshot.create": "filesystem",
|
|
90
|
-
"snapshot.delete": "filesystem",
|
|
91
|
-
"sandbox.resume": "persistent",
|
|
92
|
-
"filesystem.persistent": "persistent",
|
|
93
|
-
"image.custom": "native",
|
|
94
|
-
"network.policy": "native"
|
|
95
|
-
});
|
|
96
|
-
const boxCapabilities = defineCapabilities({
|
|
97
|
-
"files.read": "full",
|
|
98
|
-
"files.write": "full",
|
|
99
|
-
"files.list": "full",
|
|
100
|
-
"files.remove": "full",
|
|
101
|
-
"process.run": "separate-streams",
|
|
102
|
-
"ports.expose": "public",
|
|
103
|
-
"ports.authenticatedRequest": "authenticated",
|
|
104
|
-
"sandbox.resume": "persistent",
|
|
105
|
-
"filesystem.persistent": "persistent"
|
|
106
|
-
});
|
|
107
|
-
const railwayCapabilities = defineCapabilities({
|
|
108
|
-
"files.read": "full",
|
|
109
|
-
"files.write": "full",
|
|
110
|
-
"files.list": "full",
|
|
111
|
-
"files.remove": "full",
|
|
112
|
-
"process.run": "separate-streams",
|
|
113
|
-
"process.stream": "separate-streams",
|
|
114
|
-
"process.background": "full",
|
|
115
|
-
"process.cancel": "full",
|
|
116
|
-
"snapshot.create": "filesystem",
|
|
117
|
-
"snapshot.delete": "filesystem",
|
|
118
|
-
"filesystem.persistent": "persistent",
|
|
119
|
-
"image.custom": "template",
|
|
120
|
-
"network.policy": "native"
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
//#endregion
|
|
124
|
-
export { localCapabilities as a, vercelCapabilities as c, e2bCapabilities as i, boxCapabilities as n, railwayCapabilities as o, daytonaCapabilities as r, upstashCapabilities as s, agentosCapabilities as t };
|
|
125
|
-
//# sourceMappingURL=capabilities-CaSNd6J1.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"capabilities-CaSNd6J1.mjs","names":[],"sources":["../src/providers/capabilities.ts"],"sourcesContent":["import { defineCapabilities } from \"../core/capabilities\";\n\nexport const localCapabilities = defineCapabilities({\n \"files.read\": \"full\",\n \"files.write\": \"full\",\n \"files.list\": \"full\",\n \"files.remove\": \"full\",\n \"process.run\": \"combined-stream\",\n \"process.stream\": \"combined-stream\",\n \"process.background\": \"full\",\n \"process.stdin\": \"full\",\n \"process.cancel\": \"full\",\n \"ports.expose\": \"in-process\",\n \"snapshot.create\": \"filesystem\",\n \"snapshot.delete\": \"filesystem\",\n \"snapshot.restore\": \"filesystem\",\n \"sandbox.resume\": \"memory\",\n \"filesystem.persistent\": \"ephemeral\",\n \"network.policy\": \"native\",\n});\n\n/** @deprecated AgentOS capabilities are exposed as Local capabilities. */\nexport const agentosCapabilities = localCapabilities;\n\nexport const e2bCapabilities = defineCapabilities({\n \"files.read\": \"full\",\n \"files.write\": \"full\",\n \"files.list\": \"full\",\n \"files.remove\": \"full\",\n \"process.run\": \"separate-streams\",\n \"process.stream\": \"separate-streams\",\n \"process.background\": \"full\",\n \"process.stdin\": \"full\",\n \"process.cancel\": \"full\",\n \"process.pty\": \"native\",\n \"ports.expose\": \"authenticated\",\n \"ports.authenticatedRequest\": \"authenticated\",\n \"snapshot.create\": \"template\",\n \"snapshot.delete\": \"template\",\n \"sandbox.resume\": \"memory\",\n \"filesystem.persistent\": \"ephemeral\",\n \"image.custom\": \"template\",\n \"network.policy\": \"native\",\n});\n\nexport const daytonaCapabilities = defineCapabilities({\n \"files.read\": \"full\",\n \"files.write\": \"full\",\n \"files.list\": \"full\",\n \"files.remove\": \"full\",\n \"process.run\": \"combined-stream\",\n \"process.stream\": \"separate-streams\",\n \"process.background\": \"full\",\n \"process.stdin\": \"full\",\n \"process.cancel\": \"full\",\n \"process.pty\": \"native\",\n \"ports.expose\": \"authenticated\",\n \"ports.authenticatedRequest\": \"authenticated\",\n \"filesystem.persistent\": \"persistent\",\n \"image.custom\": \"native\",\n \"network.policy\": \"native\",\n \"compute.gpu\": \"native\",\n});\n\nexport const vercelCapabilities = defineCapabilities({\n \"files.read\": \"full\",\n \"files.write\": \"full\",\n \"files.list\": \"full\",\n \"files.remove\": \"full\",\n \"process.run\": \"separate-streams\",\n \"process.stream\": \"separate-streams\",\n \"process.background\": \"full\",\n \"process.cancel\": \"full\",\n \"process.pty\": \"native\",\n \"ports.expose\": \"public\",\n \"snapshot.create\": \"filesystem\",\n \"snapshot.delete\": \"filesystem\",\n \"sandbox.resume\": \"persistent\",\n \"filesystem.persistent\": \"persistent\",\n \"network.policy\": \"native\",\n});\n\nexport const upstashCapabilities = defineCapabilities({\n \"files.read\": \"full\",\n \"files.write\": \"full\",\n \"files.list\": \"full\",\n \"files.remove\": \"full\",\n \"process.run\": \"combined-stream\",\n \"process.stream\": \"combined-stream\",\n \"process.background\": \"full\",\n \"ports.expose\": \"authenticated\",\n \"ports.authenticatedRequest\": \"authenticated\",\n \"snapshot.create\": \"filesystem\",\n \"snapshot.delete\": \"filesystem\",\n \"sandbox.resume\": \"persistent\",\n \"filesystem.persistent\": \"persistent\",\n \"image.custom\": \"native\",\n \"network.policy\": \"native\",\n});\n\nexport const boxCapabilities = defineCapabilities({\n \"files.read\": \"full\",\n \"files.write\": \"full\",\n \"files.list\": \"full\",\n \"files.remove\": \"full\",\n \"process.run\": \"separate-streams\",\n \"ports.expose\": \"public\",\n \"ports.authenticatedRequest\": \"authenticated\",\n \"sandbox.resume\": \"persistent\",\n \"filesystem.persistent\": \"persistent\",\n});\n\nexport const railwayCapabilities = defineCapabilities({\n \"files.read\": \"full\",\n \"files.write\": \"full\",\n \"files.list\": \"full\",\n \"files.remove\": \"full\",\n \"process.run\": \"separate-streams\",\n \"process.stream\": \"separate-streams\",\n \"process.background\": \"full\",\n \"process.cancel\": \"full\",\n \"snapshot.create\": \"filesystem\",\n \"snapshot.delete\": \"filesystem\",\n \"filesystem.persistent\": \"persistent\",\n \"image.custom\": \"template\",\n \"network.policy\": \"native\",\n});\n"],"mappings":";;;AAEA,MAAa,oBAAoB,mBAAmB;CAClD,cAAc;CACd,eAAe;CACf,cAAc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,CAAC;AAEF,MAAa,kBAAkB,mBAAmB;CAChD,cAAc;CACd,eAAe;CACf,cAAc;CACd,gBAAgB;CAChB,eAAe;CACf,gBAAgB;CAChB,8BAA8B;CAC9B,kBAAkB;CAClB,yBAAyB;CAC1B,CAAC;AAEF,MAAa,sBAAsB,mBAAmB;CACpD,cAAc;CACd,eAAe;CACf,cAAc;CACd,gBAAgB;CAChB,eAAe;CACf,kBAAkB;CAClB,sBAAsB;CACtB,kBAAkB;CAClB,mBAAmB;CACnB,mBAAmB;CACnB,yBAAyB;CACzB,gBAAgB;CAChB,kBAAkB;CACnB,CAAC"}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { t as SandboxError } from "./errors-BuF9bYOQ.mjs";
|
|
2
|
-
|
|
3
|
-
//#region src/core/capabilities.ts
|
|
4
|
-
function defineCapabilities(values) {
|
|
5
|
-
return new Proxy(values, { get(target, property) {
|
|
6
|
-
return typeof property === "string" && property in target ? target[property] : false;
|
|
7
|
-
} });
|
|
8
|
-
}
|
|
9
|
-
function supports(sandbox, capability) {
|
|
10
|
-
return sandbox.capabilities[capability] !== false;
|
|
11
|
-
}
|
|
12
|
-
function capabilityMode(sandbox, capability) {
|
|
13
|
-
return sandbox.capabilities[capability];
|
|
14
|
-
}
|
|
15
|
-
function requireCapability(sandbox, capability) {
|
|
16
|
-
const mode = sandbox.capabilities[capability];
|
|
17
|
-
if (mode === false) throw new SandboxError({
|
|
18
|
-
code: "unsupported",
|
|
19
|
-
provider: sandbox.provider,
|
|
20
|
-
operation: capability,
|
|
21
|
-
message: `${sandbox.provider} does not support ${capability}`
|
|
22
|
-
});
|
|
23
|
-
return mode;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
//#endregion
|
|
27
|
-
export { supports as i, defineCapabilities as n, requireCapability as r, capabilityMode as t };
|
|
28
|
-
//# sourceMappingURL=capabilities-xs9kaHrK.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"capabilities-xs9kaHrK.mjs","names":[],"sources":["../src/core/capabilities.ts"],"sourcesContent":["import { SandboxError } from \"./errors\";\nimport type { Capability, CapabilityMap, CapabilityMode, Sandbox } from \"./types\";\n\nexport function defineCapabilities(\n values: Partial<Record<Capability, CapabilityMode>>,\n): CapabilityMap {\n return new Proxy(values, {\n get(target, property) {\n return typeof property === \"string\" && property in target\n ? target[property as Capability]\n : false;\n },\n }) as CapabilityMap;\n}\n\nexport function supports(sandbox: Pick<Sandbox, \"capabilities\">, capability: Capability): boolean {\n return sandbox.capabilities[capability] !== false;\n}\n\nexport function capabilityMode(\n sandbox: Pick<Sandbox, \"capabilities\">,\n capability: Capability,\n): CapabilityMode | false {\n return sandbox.capabilities[capability];\n}\n\nexport function requireCapability(\n sandbox: Pick<Sandbox, \"capabilities\" | \"provider\">,\n capability: Capability,\n): CapabilityMode {\n const mode = sandbox.capabilities[capability];\n if (mode === false) {\n throw new SandboxError({\n code: \"unsupported\",\n provider: sandbox.provider,\n operation: capability,\n message: `${sandbox.provider} does not support ${capability}`,\n });\n }\n return mode;\n}\n"],"mappings":";;;AAGA,SAAgB,mBACd,QACe;AACf,QAAO,IAAI,MAAM,QAAQ,EACvB,IAAI,QAAQ,UAAU;AACpB,SAAO,OAAO,aAAa,YAAY,YAAY,SAC/C,OAAO,YACP;IAEP,CAAC;;AAGJ,SAAgB,SAAS,SAAwC,YAAiC;AAChG,QAAO,QAAQ,aAAa,gBAAgB;;AAG9C,SAAgB,eACd,SACA,YACwB;AACxB,QAAO,QAAQ,aAAa;;AAG9B,SAAgB,kBACd,SACA,YACgB;CAChB,MAAM,OAAO,QAAQ,aAAa;AAClC,KAAI,SAAS,MACX,OAAM,IAAI,aAAa;EACrB,MAAM;EACN,UAAU,QAAQ;EAClB,WAAW;EACX,SAAS,GAAG,QAAQ,SAAS,oBAAoB;EAClD,CAAC;AAEJ,QAAO"}
|
package/dist/errors-BuF9bYOQ.mjs
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
//#region src/core/errors.ts
|
|
2
|
-
const sandboxErrorCodes = [
|
|
3
|
-
"authentication",
|
|
4
|
-
"permission",
|
|
5
|
-
"not_found",
|
|
6
|
-
"timeout",
|
|
7
|
-
"rate_limited",
|
|
8
|
-
"unavailable",
|
|
9
|
-
"unsupported",
|
|
10
|
-
"invalid_input",
|
|
11
|
-
"conflict",
|
|
12
|
-
"terminated",
|
|
13
|
-
"process_failed",
|
|
14
|
-
"internal"
|
|
15
|
-
];
|
|
16
|
-
const sensitive = /((?:token|key|secret|authorization|credential|signature)=?)[^\s&,]+|https?:\/\/[^\s]+(?:token|sig|signature|key)=[^\s&]+/gi;
|
|
17
|
-
function redactSensitive(value) {
|
|
18
|
-
return value.replace(sensitive, "$1[REDACTED]");
|
|
19
|
-
}
|
|
20
|
-
var SandboxError = class extends Error {
|
|
21
|
-
code;
|
|
22
|
-
provider;
|
|
23
|
-
operation;
|
|
24
|
-
retryable;
|
|
25
|
-
cause;
|
|
26
|
-
constructor(options) {
|
|
27
|
-
super(redactSensitive(options.message), { cause: options.cause });
|
|
28
|
-
this.name = "SandboxError";
|
|
29
|
-
this.code = options.code;
|
|
30
|
-
this.provider = options.provider;
|
|
31
|
-
this.operation = options.operation;
|
|
32
|
-
this.retryable = options.retryable ?? [
|
|
33
|
-
"rate_limited",
|
|
34
|
-
"timeout",
|
|
35
|
-
"unavailable"
|
|
36
|
-
].includes(options.code);
|
|
37
|
-
this.cause = options.cause;
|
|
38
|
-
}
|
|
39
|
-
toString() {
|
|
40
|
-
return `${this.name} [${this.code}]: ${this.message}`;
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
function isSandboxError(error) {
|
|
44
|
-
return error instanceof SandboxError;
|
|
45
|
-
}
|
|
46
|
-
function normalizeError(provider, operation, error, fallback = "internal") {
|
|
47
|
-
if (isSandboxError(error)) return error;
|
|
48
|
-
const message = error instanceof Error ? error.message : "Unknown provider error";
|
|
49
|
-
const lower = `${error instanceof Error ? error.name : ""} ${message}`.toLowerCase();
|
|
50
|
-
const status = errorStatus(error);
|
|
51
|
-
return new SandboxError({
|
|
52
|
-
code: status === 401 || lower.includes("unauthorized") || lower.includes("api key") ? "authentication" : status === 403 || lower.includes("forbidden") || lower.includes("permission") ? "permission" : status === 404 || lower.includes("not found") || lower.includes("enoent") ? "not_found" : status === 408 || lower.includes("timeout") || lower.includes("timed out") ? "timeout" : status === 429 || lower.includes("rate limit") || lower.includes("429") ? "rate_limited" : status === 409 || lower.includes("already exists") || lower.includes("conflict") ? "conflict" : fallback,
|
|
53
|
-
provider,
|
|
54
|
-
operation,
|
|
55
|
-
message,
|
|
56
|
-
cause: error
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
function errorStatus(error) {
|
|
60
|
-
if (typeof error !== "object" || error === null) return void 0;
|
|
61
|
-
if ("statusCode" in error && typeof error.statusCode === "number") return error.statusCode;
|
|
62
|
-
if ("status" in error && typeof error.status === "number") return error.status;
|
|
63
|
-
if ("response" in error && typeof error.response === "object" && error.response !== null && "status" in error.response && typeof error.response.status === "number") return error.response.status;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
//#endregion
|
|
67
|
-
export { sandboxErrorCodes as a, redactSensitive as i, isSandboxError as n, normalizeError as r, SandboxError as t };
|
|
68
|
-
//# sourceMappingURL=errors-BuF9bYOQ.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errors-BuF9bYOQ.mjs","names":[],"sources":["../src/core/errors.ts"],"sourcesContent":["export const sandboxErrorCodes = [\n \"authentication\",\n \"permission\",\n \"not_found\",\n \"timeout\",\n \"rate_limited\",\n \"unavailable\",\n \"unsupported\",\n \"invalid_input\",\n \"conflict\",\n \"terminated\",\n \"process_failed\",\n \"internal\",\n] as const;\n\nexport type SandboxErrorCode = (typeof sandboxErrorCodes)[number];\n\nconst sensitive =\n /((?:token|key|secret|authorization|credential|signature)=?)[^\\s&,]+|https?:\\/\\/[^\\s]+(?:token|sig|signature|key)=[^\\s&]+/gi;\n\nexport function redactSensitive(value: string): string {\n return value.replace(sensitive, \"$1[REDACTED]\");\n}\n\nexport class SandboxError extends Error {\n readonly code: SandboxErrorCode;\n readonly provider: string;\n readonly operation?: string;\n readonly retryable: boolean;\n override readonly cause?: unknown;\n\n constructor(options: {\n code: SandboxErrorCode;\n provider: string;\n message: string;\n operation?: string;\n retryable?: boolean;\n cause?: unknown;\n }) {\n super(redactSensitive(options.message), { cause: options.cause });\n this.name = \"SandboxError\";\n this.code = options.code;\n this.provider = options.provider;\n this.operation = options.operation;\n this.retryable =\n options.retryable ?? [\"rate_limited\", \"timeout\", \"unavailable\"].includes(options.code);\n this.cause = options.cause;\n }\n\n override toString(): string {\n return `${this.name} [${this.code}]: ${this.message}`;\n }\n}\n\nexport function isSandboxError(error: unknown): error is SandboxError {\n return error instanceof SandboxError;\n}\n\nexport function normalizeError(\n provider: string,\n operation: string,\n error: unknown,\n fallback: SandboxErrorCode = \"internal\",\n): SandboxError {\n if (isSandboxError(error)) return error;\n const message = error instanceof Error ? error.message : \"Unknown provider error\";\n const lower = `${error instanceof Error ? error.name : \"\"} ${message}`.toLowerCase();\n const status = errorStatus(error);\n const code =\n status === 401 || lower.includes(\"unauthorized\") || lower.includes(\"api key\")\n ? \"authentication\"\n : status === 403 || lower.includes(\"forbidden\") || lower.includes(\"permission\")\n ? \"permission\"\n : status === 404 || lower.includes(\"not found\") || lower.includes(\"enoent\")\n ? \"not_found\"\n : status === 408 || lower.includes(\"timeout\") || lower.includes(\"timed out\")\n ? \"timeout\"\n : status === 429 || lower.includes(\"rate limit\") || lower.includes(\"429\")\n ? \"rate_limited\"\n : status === 409 || lower.includes(\"already exists\") || lower.includes(\"conflict\")\n ? \"conflict\"\n : fallback;\n return new SandboxError({ code, provider, operation, message, cause: error });\n}\n\nfunction errorStatus(error: unknown): number | undefined {\n if (typeof error !== \"object\" || error === null) return undefined;\n if (\"statusCode\" in error && typeof error.statusCode === \"number\") return error.statusCode;\n if (\"status\" in error && typeof error.status === \"number\") return error.status;\n if (\n \"response\" in error &&\n typeof error.response === \"object\" &&\n error.response !== null &&\n \"status\" in error.response &&\n typeof error.response.status === \"number\"\n ) {\n return error.response.status;\n }\n return undefined;\n}\n"],"mappings":";AAAA,MAAa,oBAAoB;CAC/B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AAID,MAAM,YACJ;AAEF,SAAgB,gBAAgB,OAAuB;AACrD,QAAO,MAAM,QAAQ,WAAW,eAAe;;AAGjD,IAAa,eAAb,cAAkC,MAAM;CACtC,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAkB;CAElB,YAAY,SAOT;AACD,QAAM,gBAAgB,QAAQ,QAAQ,EAAE,EAAE,OAAO,QAAQ,OAAO,CAAC;AACjE,OAAK,OAAO;AACZ,OAAK,OAAO,QAAQ;AACpB,OAAK,WAAW,QAAQ;AACxB,OAAK,YAAY,QAAQ;AACzB,OAAK,YACH,QAAQ,aAAa;GAAC;GAAgB;GAAW;GAAc,CAAC,SAAS,QAAQ,KAAK;AACxF,OAAK,QAAQ,QAAQ;;CAGvB,AAAS,WAAmB;AAC1B,SAAO,GAAG,KAAK,KAAK,IAAI,KAAK,KAAK,KAAK,KAAK;;;AAIhD,SAAgB,eAAe,OAAuC;AACpE,QAAO,iBAAiB;;AAG1B,SAAgB,eACd,UACA,WACA,OACA,WAA6B,YACf;AACd,KAAI,eAAe,MAAM,CAAE,QAAO;CAClC,MAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU;CACzD,MAAM,QAAQ,GAAG,iBAAiB,QAAQ,MAAM,OAAO,GAAG,GAAG,UAAU,aAAa;CACpF,MAAM,SAAS,YAAY,MAAM;AAejC,QAAO,IAAI,aAAa;EAAE,MAbxB,WAAW,OAAO,MAAM,SAAS,eAAe,IAAI,MAAM,SAAS,UAAU,GACzE,mBACA,WAAW,OAAO,MAAM,SAAS,YAAY,IAAI,MAAM,SAAS,aAAa,GAC3E,eACA,WAAW,OAAO,MAAM,SAAS,YAAY,IAAI,MAAM,SAAS,SAAS,GACvE,cACA,WAAW,OAAO,MAAM,SAAS,UAAU,IAAI,MAAM,SAAS,YAAY,GACxE,YACA,WAAW,OAAO,MAAM,SAAS,aAAa,IAAI,MAAM,SAAS,MAAM,GACrE,iBACA,WAAW,OAAO,MAAM,SAAS,iBAAiB,IAAI,MAAM,SAAS,WAAW,GAC9E,aACA;EACgB;EAAU;EAAW;EAAS,OAAO;EAAO,CAAC;;AAG/E,SAAS,YAAY,OAAoC;AACvD,KAAI,OAAO,UAAU,YAAY,UAAU,KAAM,QAAO;AACxD,KAAI,gBAAgB,SAAS,OAAO,MAAM,eAAe,SAAU,QAAO,MAAM;AAChF,KAAI,YAAY,SAAS,OAAO,MAAM,WAAW,SAAU,QAAO,MAAM;AACxE,KACE,cAAc,SACd,OAAO,MAAM,aAAa,YAC1B,MAAM,aAAa,QACnB,YAAY,MAAM,YAClB,OAAO,MAAM,SAAS,WAAW,SAEjC,QAAO,MAAM,SAAS"}
|
package/dist/eve/index.d.mts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import "../types-Bv6I2U1c.mjs";
|
|
2
|
-
import { o as SandboxProvider } from "../provider-DOBErkBO.mjs";
|
|
3
|
-
import { SandboxBackend, SandboxBackendHandle, SandboxNetworkPolicy, SandboxSession as EveSandboxSession } from "eve/sandbox";
|
|
4
|
-
|
|
5
|
-
//#region src/eve/index.d.ts
|
|
6
|
-
interface EveSandboxUseOptions {
|
|
7
|
-
networkPolicy?: SandboxNetworkPolicy;
|
|
8
|
-
}
|
|
9
|
-
interface CreateEveSandboxBackendOptions {
|
|
10
|
-
provider: SandboxProvider<unknown>;
|
|
11
|
-
ports?: ReadonlyArray<number>;
|
|
12
|
-
cwd?: string;
|
|
13
|
-
env?: Readonly<Record<string, string>>;
|
|
14
|
-
}
|
|
15
|
-
/** Create an Eve beta SandboxBackend backed by a managed sandbox-sdk provider. */
|
|
16
|
-
declare function createEveSandboxBackend(options: CreateEveSandboxBackendOptions): SandboxBackend<EveSandboxUseOptions, EveSandboxUseOptions>;
|
|
17
|
-
//#endregion
|
|
18
|
-
export { CreateEveSandboxBackendOptions, type EveSandboxSession, EveSandboxUseOptions, type SandboxBackend, type SandboxBackendHandle, createEveSandboxBackend };
|
|
19
|
-
//# sourceMappingURL=index.d.mts.map
|