@opencoredev/sandbox-sdk 0.1.1 → 0.2.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 +6 -0
- package/README.md +3 -1
- package/dist/{agentos-DFJ4TFaY.mjs → agentos-CbrZW7R0.mjs} +5 -4
- package/dist/{agentos-DFJ4TFaY.mjs.map → agentos-CbrZW7R0.mjs.map} +1 -1
- package/dist/ai/harness.d.mts +2 -2
- package/dist/ai/harness.mjs +2 -2
- package/dist/ai/index.d.mts +1 -1
- package/dist/ai/index.mjs +2 -2
- package/dist/{ai-DhfwIZdL.mjs → ai-DeFa8yPk.mjs} +2 -2
- package/dist/{ai-DhfwIZdL.mjs.map → ai-DeFa8yPk.mjs.map} +1 -1
- package/dist/{capabilities-DftdOpIu.d.mts → capabilities-BWvOVFbH.d.mts} +5 -3
- package/dist/{capabilities-CEowrzRM.mjs → capabilities-CaSNd6J1.mjs} +29 -3
- package/dist/{capabilities-CEowrzRM.mjs.map → capabilities-CaSNd6J1.mjs.map} +1 -1
- package/dist/{capabilities-COKpwoFH.mjs → capabilities-xs9kaHrK.mjs} +2 -2
- package/dist/{capabilities-COKpwoFH.mjs.map → capabilities-xs9kaHrK.mjs.map} +1 -1
- package/dist/{errors-Ch9PHKTd.mjs → errors-BuF9bYOQ.mjs} +10 -3
- package/dist/errors-BuF9bYOQ.mjs.map +1 -0
- package/dist/eve/index.d.mts +2 -2
- package/dist/eve/index.mjs +2 -2
- package/dist/{index-Bk6GmoEt.d.mts → index-CkTwqD0X.d.mts} +2 -2
- package/dist/{index-BufLdrbp.d.mts → index-Dh9xob2s.d.mts} +2 -2
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +6 -4
- package/dist/index.mjs.map +1 -1
- package/dist/{provider-utils-BjOSWNsh.mjs → managed-provider-BsZGVQ4I.mjs} +4 -57
- package/dist/managed-provider-BsZGVQ4I.mjs.map +1 -0
- package/dist/mastra/index.d.mts +2 -2
- package/dist/mastra/index.mjs +1 -1
- package/dist/metadata.d.mts +1 -1
- package/dist/metadata.mjs +35 -3
- package/dist/metadata.mjs.map +1 -1
- package/dist/{provider-BzzkIVmv.d.mts → provider-DOBErkBO.d.mts} +2 -2
- package/dist/provider-utils-CfB9nvJx.mjs +57 -0
- package/dist/provider-utils-CfB9nvJx.mjs.map +1 -0
- package/dist/providers/agentos/index.d.mts +6 -6
- package/dist/providers/agentos/index.mjs +7 -6
- package/dist/providers/box/index.d.mts +34 -0
- package/dist/providers/box/index.mjs +348 -0
- package/dist/providers/box/index.mjs.map +1 -0
- package/dist/providers/daytona/index.d.mts +5 -5
- package/dist/providers/daytona/index.mjs +6 -5
- package/dist/providers/daytona/index.mjs.map +1 -1
- package/dist/providers/e2b/index.d.mts +5 -5
- package/dist/providers/e2b/index.mjs +6 -5
- package/dist/providers/e2b/index.mjs.map +1 -1
- package/dist/providers/local/index.d.mts +6 -6
- package/dist/providers/local/index.mjs +7 -6
- package/dist/providers/local/index.mjs.map +1 -1
- package/dist/providers/railway/index.d.mts +29 -0
- package/dist/providers/railway/index.mjs +211 -0
- package/dist/providers/railway/index.mjs.map +1 -0
- package/dist/providers/upstash/index.d.mts +5 -5
- package/dist/providers/upstash/index.mjs +6 -5
- package/dist/providers/upstash/index.mjs.map +1 -1
- package/dist/providers/vercel/index.d.mts +5 -5
- package/dist/providers/vercel/index.mjs +6 -5
- package/dist/providers/vercel/index.mjs.map +1 -1
- package/dist/{sandbox-Dco6z9aB.d.mts → sandbox-DdEqoXJF.d.mts} +3 -3
- package/dist/{sandbox-rIOcbhtM.mjs → sandbox-DgtY5hvt.mjs} +2 -2
- package/dist/{sandbox-rIOcbhtM.mjs.map → sandbox-DgtY5hvt.mjs.map} +1 -1
- package/dist/testing/index.d.mts +3 -3
- package/dist/testing/index.mjs +3 -3
- package/dist/{types-DEi_dfRR.d.mts → types-Bv6I2U1c.d.mts} +2 -2
- package/package.json +23 -3
- package/dist/errors-Ch9PHKTd.mjs.map +0 -1
- package/dist/provider-utils-BjOSWNsh.mjs.map +0 -1
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
import { t as SandboxError } from "../../errors-BuF9bYOQ.mjs";
|
|
2
|
+
import "../../capabilities-xs9kaHrK.mjs";
|
|
3
|
+
import "../../sandbox-DgtY5hvt.mjs";
|
|
4
|
+
import { n as boxCapabilities } from "../../capabilities-CaSNd6J1.mjs";
|
|
5
|
+
import { t as withManagedSessions } from "../../managed-provider-BsZGVQ4I.mjs";
|
|
6
|
+
import { a as unsupportedSnapshots, i as unsupported, n as portResult, r as toUint8Array, t as commandString } from "../../provider-utils-CfB9nvJx.mjs";
|
|
7
|
+
import { BoxApi, Configuration } from "@asciidev/box-sdk";
|
|
8
|
+
|
|
9
|
+
//#region src/providers/box/index.ts
|
|
10
|
+
const DEFAULT_BASE_URL = "https://ascii.dev/api/box/v1";
|
|
11
|
+
const MAX_COMMAND_TIMEOUT_MS = 6e4;
|
|
12
|
+
function box(options = {}) {
|
|
13
|
+
const readyTimeoutMs = options.readyTimeout ?? 6e5;
|
|
14
|
+
const publicPorts = options.public ?? true;
|
|
15
|
+
return withManagedSessions({
|
|
16
|
+
id: "box",
|
|
17
|
+
capabilities: boxCapabilities,
|
|
18
|
+
async create(createOptions) {
|
|
19
|
+
const apiKey = options.apiKey ?? process.env.BOX_API_KEY;
|
|
20
|
+
if (!apiKey) throw new SandboxError({
|
|
21
|
+
code: "authentication",
|
|
22
|
+
provider: "box",
|
|
23
|
+
operation: "sandbox.create",
|
|
24
|
+
message: "BOX_API_KEY is required to create an Ascii Box"
|
|
25
|
+
});
|
|
26
|
+
const client = new BoxApi(new Configuration({
|
|
27
|
+
basePath: options.baseUrl ?? process.env.BOX_BASE_URL ?? DEFAULT_BASE_URL,
|
|
28
|
+
accessToken: apiKey
|
|
29
|
+
}));
|
|
30
|
+
assertNotAborted(createOptions.signal);
|
|
31
|
+
const id = (await client.create({ createBoxRequest: {
|
|
32
|
+
ttlSeconds: options.ttlSeconds,
|
|
33
|
+
noEnv: options.noEnv,
|
|
34
|
+
env: { ...createOptions.env }
|
|
35
|
+
} }, { signal: createOptions.signal })).box.id;
|
|
36
|
+
let native;
|
|
37
|
+
try {
|
|
38
|
+
native = {
|
|
39
|
+
client,
|
|
40
|
+
box: await waitUntilBoxReady(client, id, createOptions.signal, createOptions.timeout ?? readyTimeoutMs),
|
|
41
|
+
readyTimeoutMs
|
|
42
|
+
};
|
|
43
|
+
if (options.name) native.box = (await client.update({
|
|
44
|
+
boxId: id,
|
|
45
|
+
updateBoxRequest: { name: options.name }
|
|
46
|
+
})).box;
|
|
47
|
+
assertSucceeded(await execute(client, id, {
|
|
48
|
+
command: commandString({
|
|
49
|
+
command: "mkdir",
|
|
50
|
+
args: [
|
|
51
|
+
"-p",
|
|
52
|
+
"--",
|
|
53
|
+
toRemotePath(createOptions.cwd)
|
|
54
|
+
]
|
|
55
|
+
}),
|
|
56
|
+
timeoutMs: MAX_COMMAND_TIMEOUT_MS,
|
|
57
|
+
signal: createOptions.signal
|
|
58
|
+
}), "sandbox.create.cwd");
|
|
59
|
+
return {
|
|
60
|
+
id,
|
|
61
|
+
raw: native,
|
|
62
|
+
capabilities: boxCapabilities,
|
|
63
|
+
files: {
|
|
64
|
+
async write(path, value) {
|
|
65
|
+
const remotePath = toRemotePath(path);
|
|
66
|
+
assertSucceeded(await execute(client, id, {
|
|
67
|
+
command: commandString({
|
|
68
|
+
command: "mkdir",
|
|
69
|
+
args: [
|
|
70
|
+
"-p",
|
|
71
|
+
"--",
|
|
72
|
+
remotePath.includes("/") ? remotePath.slice(0, remotePath.lastIndexOf("/")) : "."
|
|
73
|
+
]
|
|
74
|
+
}),
|
|
75
|
+
timeoutMs: MAX_COMMAND_TIMEOUT_MS
|
|
76
|
+
}), "files.write.mkdir");
|
|
77
|
+
await client.writeFile({
|
|
78
|
+
boxId: id,
|
|
79
|
+
fileWriteRequest: {
|
|
80
|
+
path: remotePath,
|
|
81
|
+
content: Buffer.from(await toUint8Array(value)).toString("base64"),
|
|
82
|
+
encoding: "base64"
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
},
|
|
86
|
+
async read(path) {
|
|
87
|
+
const response = await client.readFile({
|
|
88
|
+
boxId: id,
|
|
89
|
+
path: toRemotePath(path),
|
|
90
|
+
encoding: "base64"
|
|
91
|
+
});
|
|
92
|
+
return new Uint8Array(Buffer.from(response.content, "base64"));
|
|
93
|
+
},
|
|
94
|
+
async list(path) {
|
|
95
|
+
const result = await execute(client, id, {
|
|
96
|
+
command: commandString({
|
|
97
|
+
command: "python3",
|
|
98
|
+
args: [
|
|
99
|
+
"-c",
|
|
100
|
+
DIRECTORY_LIST_SCRIPT,
|
|
101
|
+
toRemotePath(path)
|
|
102
|
+
]
|
|
103
|
+
}),
|
|
104
|
+
timeoutMs: MAX_COMMAND_TIMEOUT_MS
|
|
105
|
+
});
|
|
106
|
+
assertSucceeded(result, "files.list");
|
|
107
|
+
return JSON.parse(result.stdout).map((entry) => ({
|
|
108
|
+
name: entry.name,
|
|
109
|
+
path: toVirtualPath(entry.path),
|
|
110
|
+
type: entry.type,
|
|
111
|
+
size: entry.type === "file" ? entry.size : void 0
|
|
112
|
+
}));
|
|
113
|
+
},
|
|
114
|
+
async mkdir(path) {
|
|
115
|
+
assertSucceeded(await execute(client, id, {
|
|
116
|
+
command: commandString({
|
|
117
|
+
command: "mkdir",
|
|
118
|
+
args: [
|
|
119
|
+
"-p",
|
|
120
|
+
"--",
|
|
121
|
+
toRemotePath(path)
|
|
122
|
+
]
|
|
123
|
+
}),
|
|
124
|
+
timeoutMs: MAX_COMMAND_TIMEOUT_MS
|
|
125
|
+
}), "files.mkdir");
|
|
126
|
+
},
|
|
127
|
+
async remove(path) {
|
|
128
|
+
assertSucceeded(await execute(client, id, {
|
|
129
|
+
command: commandString({
|
|
130
|
+
command: "rm",
|
|
131
|
+
args: [
|
|
132
|
+
"-rf",
|
|
133
|
+
"--",
|
|
134
|
+
toRemotePath(path)
|
|
135
|
+
]
|
|
136
|
+
}),
|
|
137
|
+
timeoutMs: MAX_COMMAND_TIMEOUT_MS
|
|
138
|
+
}), "files.remove");
|
|
139
|
+
},
|
|
140
|
+
async exists(path) {
|
|
141
|
+
const result = await execute(client, id, {
|
|
142
|
+
command: commandString({
|
|
143
|
+
command: "test",
|
|
144
|
+
args: ["-e", toRemotePath(path)]
|
|
145
|
+
}),
|
|
146
|
+
timeoutMs: MAX_COMMAND_TIMEOUT_MS
|
|
147
|
+
});
|
|
148
|
+
if (result.exitCode === 0) return true;
|
|
149
|
+
if (result.exitCode === 1) return false;
|
|
150
|
+
assertSucceeded(result, "files.exists");
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
async run(command, runOptions) {
|
|
155
|
+
const result = await execute(client, id, {
|
|
156
|
+
command: withEnvironment(command, runOptions.env),
|
|
157
|
+
cwd: toRemotePath(runOptions.cwd),
|
|
158
|
+
timeoutMs: runOptions.timeout,
|
|
159
|
+
signal: runOptions.signal
|
|
160
|
+
});
|
|
161
|
+
if (result.timedOut) throw new SandboxError({
|
|
162
|
+
code: "timeout",
|
|
163
|
+
provider: "box",
|
|
164
|
+
operation: "process.run",
|
|
165
|
+
message: `Command timed out after ${runOptions.timeout ?? 3e4}ms`
|
|
166
|
+
});
|
|
167
|
+
return {
|
|
168
|
+
stdout: result.stdout,
|
|
169
|
+
stderr: result.stderr,
|
|
170
|
+
exitCode: result.exitCode ?? 1,
|
|
171
|
+
success: result.success,
|
|
172
|
+
signal: result.signal ?? void 0,
|
|
173
|
+
durationMs: result.startedAt && result.finishedAt ? result.finishedAt.getTime() - result.startedAt.getTime() : void 0
|
|
174
|
+
};
|
|
175
|
+
},
|
|
176
|
+
async start() {
|
|
177
|
+
unsupported("box", "process.start");
|
|
178
|
+
},
|
|
179
|
+
async expose(port) {
|
|
180
|
+
const hosted = await execute(client, id, {
|
|
181
|
+
command: `host ${port} ${publicPorts ? "--public" : "--private"}`,
|
|
182
|
+
timeoutMs: MAX_COMMAND_TIMEOUT_MS
|
|
183
|
+
});
|
|
184
|
+
assertSucceeded(hosted, "ports.expose");
|
|
185
|
+
const resolved = await execute(client, id, {
|
|
186
|
+
command: `host url ${port}${publicPorts ? " --public" : ""}`,
|
|
187
|
+
timeoutMs: MAX_COMMAND_TIMEOUT_MS
|
|
188
|
+
});
|
|
189
|
+
assertSucceeded(resolved, "ports.expose.url");
|
|
190
|
+
const url = findUrl(`${resolved.stdout}\n${resolved.stderr}`) ?? findUrl(`${hosted.stdout}\n${hosted.stderr}`);
|
|
191
|
+
if (!url) throw new Error(`Box host command did not return a URL for port ${port}`);
|
|
192
|
+
const protectedUrl = new URL(url).searchParams.has("_token");
|
|
193
|
+
return portResult(port, protectedUrl ? withoutProtectedToken(url) : url, !protectedUrl, protectedUrl, protectedUrl ? async (path = "/", init = {}) => fetch(withProtectedPath(url, path), init) : void 0);
|
|
194
|
+
},
|
|
195
|
+
snapshots: unsupportedSnapshots("box"),
|
|
196
|
+
async stop() {
|
|
197
|
+
await destroyBox(client, id, readyTimeoutMs);
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
} catch (error) {
|
|
201
|
+
await destroyBox(client, id, readyTimeoutMs).catch(() => void 0);
|
|
202
|
+
throw error;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}, [], {
|
|
206
|
+
async stop(sandbox) {
|
|
207
|
+
await sandbox.raw.client.stop({ boxId: sandbox.id });
|
|
208
|
+
sandbox.raw.box = await waitForState(sandbox.raw.client, sandbox.id, ["archived"], sandbox.raw.readyTimeoutMs);
|
|
209
|
+
},
|
|
210
|
+
async resume(sandbox) {
|
|
211
|
+
await sandbox.raw.client.resume({ boxId: sandbox.id });
|
|
212
|
+
sandbox.raw.box = await waitUntilBoxReady(sandbox.raw.client, sandbox.id, void 0, sandbox.raw.readyTimeoutMs);
|
|
213
|
+
},
|
|
214
|
+
async destroy(sandbox) {
|
|
215
|
+
await destroyBox(sandbox.raw.client, sandbox.id, sandbox.raw.readyTimeoutMs);
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
const DIRECTORY_LIST_SCRIPT = [
|
|
220
|
+
"import json, os, sys",
|
|
221
|
+
"result = []",
|
|
222
|
+
"for entry in os.scandir(sys.argv[1]):",
|
|
223
|
+
" kind = 'symlink' if entry.is_symlink() else ('directory' if entry.is_dir() else ('file' if entry.is_file() else 'unknown'))",
|
|
224
|
+
" result.append({'name': entry.name, 'path': entry.path, 'type': kind, 'size': entry.stat(follow_symlinks=False).st_size})",
|
|
225
|
+
"print(json.dumps(result))"
|
|
226
|
+
].join("\n");
|
|
227
|
+
async function execute(client, boxId, options) {
|
|
228
|
+
assertNotAborted(options.signal);
|
|
229
|
+
if (options.timeoutMs !== void 0 && options.timeoutMs > MAX_COMMAND_TIMEOUT_MS) throw new SandboxError({
|
|
230
|
+
code: "invalid_input",
|
|
231
|
+
provider: "box",
|
|
232
|
+
operation: "process.run",
|
|
233
|
+
message: "Ascii Box commands support a maximum timeout of 60000ms"
|
|
234
|
+
});
|
|
235
|
+
return client.command({
|
|
236
|
+
boxId,
|
|
237
|
+
commandRequest: {
|
|
238
|
+
command: options.command,
|
|
239
|
+
cwd: options.cwd,
|
|
240
|
+
timeoutSeconds: options.timeoutMs === void 0 ? void 0 : Math.max(1, Math.ceil(options.timeoutMs / 1e3))
|
|
241
|
+
}
|
|
242
|
+
}, { signal: options.signal });
|
|
243
|
+
}
|
|
244
|
+
function withEnvironment(input, environment) {
|
|
245
|
+
const command = commandString(input);
|
|
246
|
+
const entries = Object.entries(environment ?? {});
|
|
247
|
+
if (entries.length === 0) return command;
|
|
248
|
+
return `env ${entries.map(([key, value]) => shellQuote(`${key}=${value}`)).join(" ")} sh -c ${shellQuote(command)}`;
|
|
249
|
+
}
|
|
250
|
+
function toRemotePath(path) {
|
|
251
|
+
return path === "/" ? "." : path.replace(/^\/+/, "");
|
|
252
|
+
}
|
|
253
|
+
function toVirtualPath(path) {
|
|
254
|
+
return `/${path.replace(/^\.\/?/, "")}`.replace(/\/$/, "") || "/";
|
|
255
|
+
}
|
|
256
|
+
function assertSucceeded(result, operation) {
|
|
257
|
+
if (result.exitCode === 0) return;
|
|
258
|
+
throw new Error(`${operation} failed: ${result.stderr || result.stdout || `exit ${result.exitCode}`}`);
|
|
259
|
+
}
|
|
260
|
+
function findUrl(output) {
|
|
261
|
+
return output.match(/https:\/\/[^\s"']+/)?.[0]?.replace(/[),.;]+$/, "");
|
|
262
|
+
}
|
|
263
|
+
function withProtectedPath(base, path) {
|
|
264
|
+
const protectedUrl = new URL(base);
|
|
265
|
+
const target = new URL(path, base);
|
|
266
|
+
if (target.origin !== protectedUrl.origin) throw new SandboxError({
|
|
267
|
+
code: "invalid_input",
|
|
268
|
+
provider: "box",
|
|
269
|
+
operation: "port.request",
|
|
270
|
+
message: "Protected Ascii Box preview requests must stay on the preview origin"
|
|
271
|
+
});
|
|
272
|
+
for (const [key, value] of protectedUrl.searchParams) target.searchParams.set(key, value);
|
|
273
|
+
return target;
|
|
274
|
+
}
|
|
275
|
+
function withoutProtectedToken(url) {
|
|
276
|
+
const exposed = new URL(url);
|
|
277
|
+
exposed.searchParams.delete("_token");
|
|
278
|
+
return exposed.toString();
|
|
279
|
+
}
|
|
280
|
+
async function waitForState(client, boxId, states, timeoutMs) {
|
|
281
|
+
const deadline = Date.now() + timeoutMs;
|
|
282
|
+
for (;;) {
|
|
283
|
+
const current = (await client.get({ boxId })).box;
|
|
284
|
+
if (states.includes(current.state)) return current;
|
|
285
|
+
if (current.state === "error") throw new Error("Box entered terminal state error");
|
|
286
|
+
if (Date.now() >= deadline) throw new Error("Timed out waiting for Box state");
|
|
287
|
+
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
async function destroyBox(client, boxId, timeoutMs) {
|
|
291
|
+
try {
|
|
292
|
+
await client.remove({ boxId });
|
|
293
|
+
return;
|
|
294
|
+
} catch (error) {
|
|
295
|
+
if (!hasResponseStatus(error, 409)) throw error;
|
|
296
|
+
}
|
|
297
|
+
await client.stop({ boxId });
|
|
298
|
+
await waitForState(client, boxId, ["archived"], timeoutMs);
|
|
299
|
+
await client.remove({ boxId });
|
|
300
|
+
}
|
|
301
|
+
function hasResponseStatus(error, status) {
|
|
302
|
+
return typeof error === "object" && error !== null && "response" in error && typeof error.response === "object" && error.response !== null && "status" in error.response && error.response.status === status;
|
|
303
|
+
}
|
|
304
|
+
async function waitUntilBoxReady(client, boxId, signal, timeoutMs = 6e5) {
|
|
305
|
+
const deadline = Date.now() + timeoutMs;
|
|
306
|
+
for (;;) {
|
|
307
|
+
assertNotAborted(signal);
|
|
308
|
+
const current = (await client.get({ boxId }, { signal })).box;
|
|
309
|
+
if ([
|
|
310
|
+
"ready",
|
|
311
|
+
"idle",
|
|
312
|
+
"running"
|
|
313
|
+
].includes(current.state)) return current;
|
|
314
|
+
if ([
|
|
315
|
+
"archived",
|
|
316
|
+
"archiving",
|
|
317
|
+
"error"
|
|
318
|
+
].includes(current.state)) throw new Error(`Box entered terminal state ${current.state}`);
|
|
319
|
+
const remainingMs = deadline - Date.now();
|
|
320
|
+
if (remainingMs <= 0) throw new Error(`Sandbox creation timed out after ${timeoutMs}ms`);
|
|
321
|
+
await abortableDelay(Math.min(1e3, remainingMs), signal);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
function abortableDelay(ms, signal) {
|
|
325
|
+
if (!signal) return new Promise((resolve) => setTimeout(resolve, ms));
|
|
326
|
+
assertNotAborted(signal);
|
|
327
|
+
return new Promise((resolve, reject) => {
|
|
328
|
+
const timer = setTimeout(() => {
|
|
329
|
+
signal.removeEventListener("abort", onAbort);
|
|
330
|
+
resolve();
|
|
331
|
+
}, ms);
|
|
332
|
+
const onAbort = () => {
|
|
333
|
+
clearTimeout(timer);
|
|
334
|
+
reject(signal.reason ?? new DOMException("Aborted", "AbortError"));
|
|
335
|
+
};
|
|
336
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
function assertNotAborted(signal) {
|
|
340
|
+
if (signal?.aborted) throw signal.reason ?? new DOMException("Aborted", "AbortError");
|
|
341
|
+
}
|
|
342
|
+
function shellQuote(value) {
|
|
343
|
+
return `'${value.replaceAll("'", `'"'"'`)}'`;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
//#endregion
|
|
347
|
+
export { box, boxCapabilities };
|
|
348
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["native: AsciiBoxSandbox | undefined"],"sources":["../../../src/providers/box/index.ts"],"sourcesContent":["import { BoxApi, Configuration, type Box as NativeBox } from \"@asciidev/box-sdk\";\nimport { SandboxError } from \"../../core/errors\";\nimport type { SandboxProvider } from \"../../core/provider\";\nimport type { CommandInput } from \"../../core/types\";\nimport { withManagedSessions } from \"../../internal/managed-provider\";\nimport {\n commandString,\n portResult,\n toUint8Array,\n unsupported,\n unsupportedSnapshots,\n} from \"../../internal/provider-utils\";\nimport { boxCapabilities } from \"../capabilities\";\n\nconst DEFAULT_BASE_URL = \"https://ascii.dev/api/box/v1\";\nconst MAX_COMMAND_TIMEOUT_MS = 60_000;\n\nexport interface BoxOptions {\n /** Box API key. Defaults to BOX_API_KEY. */\n apiKey?: string;\n /** Box API base URL. Defaults to BOX_BASE_URL, then the public v1 endpoint. */\n baseUrl?: string;\n /** Seconds before Box automatically archives. The service default is one hour. */\n ttlSeconds?: number | null;\n /** Withhold account-level secrets from the Box. */\n noEnv?: boolean;\n /** Friendly Box name applied after provisioning. */\n name?: string;\n /** Return ungated hosted URLs instead of protected URLs. Defaults to true. */\n public?: boolean;\n /** Maximum time to wait for provisioning, in milliseconds. Defaults to 10 minutes. */\n readyTimeout?: number;\n}\n\nexport interface AsciiBoxSandbox {\n readonly client: BoxApi;\n box: NativeBox;\n readonly readyTimeoutMs: number;\n}\n\nexport { boxCapabilities } from \"../capabilities\";\n\nexport function box(options: BoxOptions = {}): SandboxProvider<AsciiBoxSandbox> {\n const readyTimeoutMs = options.readyTimeout ?? 600_000;\n const publicPorts = options.public ?? true;\n\n const provider: SandboxProvider<AsciiBoxSandbox> = {\n id: \"box\",\n capabilities: boxCapabilities,\n async create(createOptions) {\n const apiKey = options.apiKey ?? process.env.BOX_API_KEY;\n if (!apiKey) {\n throw new SandboxError({\n code: \"authentication\",\n provider: \"box\",\n operation: \"sandbox.create\",\n message: \"BOX_API_KEY is required to create an Ascii Box\",\n });\n }\n const client = new BoxApi(\n new Configuration({\n basePath: options.baseUrl ?? process.env.BOX_BASE_URL ?? DEFAULT_BASE_URL,\n accessToken: apiKey,\n }),\n );\n assertNotAborted(createOptions.signal);\n const created = await client.create(\n {\n createBoxRequest: {\n ttlSeconds: options.ttlSeconds,\n noEnv: options.noEnv,\n env: { ...createOptions.env },\n },\n },\n { signal: createOptions.signal },\n );\n const id = created.box.id;\n let native: AsciiBoxSandbox | undefined;\n try {\n const ready = await waitUntilBoxReady(\n client,\n id,\n createOptions.signal,\n createOptions.timeout ?? readyTimeoutMs,\n );\n native = { client, box: ready, readyTimeoutMs };\n if (options.name) {\n native.box = (\n await client.update({ boxId: id, updateBoxRequest: { name: options.name } })\n ).box;\n }\n\n const remoteRoot = toRemotePath(createOptions.cwd);\n const mkdir = await execute(client, id, {\n command: commandString({ command: \"mkdir\", args: [\"-p\", \"--\", remoteRoot] }),\n timeoutMs: MAX_COMMAND_TIMEOUT_MS,\n signal: createOptions.signal,\n });\n assertSucceeded(mkdir, \"sandbox.create.cwd\");\n return {\n id,\n raw: native,\n capabilities: boxCapabilities,\n files: {\n async write(path, value) {\n const remotePath = toRemotePath(path);\n const parent = remotePath.includes(\"/\")\n ? remotePath.slice(0, remotePath.lastIndexOf(\"/\"))\n : \".\";\n const mkdirResult = await execute(client, id, {\n command: commandString({ command: \"mkdir\", args: [\"-p\", \"--\", parent] }),\n timeoutMs: MAX_COMMAND_TIMEOUT_MS,\n });\n assertSucceeded(mkdirResult, \"files.write.mkdir\");\n await client.writeFile({\n boxId: id,\n fileWriteRequest: {\n path: remotePath,\n content: Buffer.from(await toUint8Array(value)).toString(\"base64\"),\n encoding: \"base64\",\n },\n });\n },\n async read(path) {\n const response = await client.readFile({\n boxId: id,\n path: toRemotePath(path),\n encoding: \"base64\",\n });\n return new Uint8Array(Buffer.from(response.content, \"base64\"));\n },\n async list(path) {\n const result = await execute(client, id, {\n command: commandString({\n command: \"python3\",\n args: [\"-c\", DIRECTORY_LIST_SCRIPT, toRemotePath(path)],\n }),\n timeoutMs: MAX_COMMAND_TIMEOUT_MS,\n });\n assertSucceeded(result, \"files.list\");\n const entries = JSON.parse(result.stdout) as NativeDirectoryEntry[];\n return entries.map((entry) => ({\n name: entry.name,\n path: toVirtualPath(entry.path),\n type: entry.type,\n size: entry.type === \"file\" ? entry.size : undefined,\n }));\n },\n async mkdir(path) {\n const result = await execute(client, id, {\n command: commandString({\n command: \"mkdir\",\n args: [\"-p\", \"--\", toRemotePath(path)],\n }),\n timeoutMs: MAX_COMMAND_TIMEOUT_MS,\n });\n assertSucceeded(result, \"files.mkdir\");\n },\n async remove(path) {\n const result = await execute(client, id, {\n command: commandString({\n command: \"rm\",\n args: [\"-rf\", \"--\", toRemotePath(path)],\n }),\n timeoutMs: MAX_COMMAND_TIMEOUT_MS,\n });\n assertSucceeded(result, \"files.remove\");\n },\n async exists(path) {\n const result = await execute(client, id, {\n command: commandString({\n command: \"test\",\n args: [\"-e\", toRemotePath(path)],\n }),\n timeoutMs: MAX_COMMAND_TIMEOUT_MS,\n });\n if (result.exitCode === 0) return true;\n if (result.exitCode === 1) return false;\n assertSucceeded(result, \"files.exists\");\n return false;\n },\n },\n async run(command, runOptions) {\n const result = await execute(client, id, {\n command: withEnvironment(command, runOptions.env),\n cwd: toRemotePath(runOptions.cwd!),\n timeoutMs: runOptions.timeout,\n signal: runOptions.signal,\n });\n if (result.timedOut) {\n throw new SandboxError({\n code: \"timeout\",\n provider: \"box\",\n operation: \"process.run\",\n message: `Command timed out after ${runOptions.timeout ?? 30_000}ms`,\n });\n }\n return {\n stdout: result.stdout,\n stderr: result.stderr,\n exitCode: result.exitCode ?? 1,\n success: result.success,\n signal: result.signal ?? undefined,\n durationMs:\n result.startedAt && result.finishedAt\n ? result.finishedAt.getTime() - result.startedAt.getTime()\n : undefined,\n };\n },\n async start() {\n unsupported(\"box\", \"process.start\");\n },\n async expose(port) {\n const visibility = publicPorts ? \"--public\" : \"--private\";\n const hosted = await execute(client, id, {\n command: `host ${port} ${visibility}`,\n timeoutMs: MAX_COMMAND_TIMEOUT_MS,\n });\n assertSucceeded(hosted, \"ports.expose\");\n const resolved = await execute(client, id, {\n command: `host url ${port}${publicPorts ? \" --public\" : \"\"}`,\n timeoutMs: MAX_COMMAND_TIMEOUT_MS,\n });\n assertSucceeded(resolved, \"ports.expose.url\");\n const url =\n findUrl(`${resolved.stdout}\\n${resolved.stderr}`) ??\n findUrl(`${hosted.stdout}\\n${hosted.stderr}`);\n if (!url) throw new Error(`Box host command did not return a URL for port ${port}`);\n const protectedUrl = new URL(url).searchParams.has(\"_token\");\n const exposedUrl = protectedUrl ? withoutProtectedToken(url) : url;\n return portResult(\n port,\n exposedUrl,\n !protectedUrl,\n protectedUrl,\n protectedUrl\n ? async (path = \"/\", init = {}) => fetch(withProtectedPath(url, path), init)\n : undefined,\n );\n },\n snapshots: unsupportedSnapshots(\"box\"),\n async stop() {\n await destroyBox(client, id, readyTimeoutMs);\n },\n };\n } catch (error) {\n await destroyBox(client, id, readyTimeoutMs).catch(() => undefined);\n throw error;\n }\n },\n };\n\n return withManagedSessions(provider, [], {\n async stop(sandbox) {\n await sandbox.raw.client.stop({ boxId: sandbox.id });\n sandbox.raw.box = await waitForState(\n sandbox.raw.client,\n sandbox.id,\n [\"archived\"],\n sandbox.raw.readyTimeoutMs,\n );\n },\n async resume(sandbox) {\n await sandbox.raw.client.resume({ boxId: sandbox.id });\n sandbox.raw.box = await waitUntilBoxReady(\n sandbox.raw.client,\n sandbox.id,\n undefined,\n sandbox.raw.readyTimeoutMs,\n );\n },\n async destroy(sandbox) {\n await destroyBox(sandbox.raw.client, sandbox.id, sandbox.raw.readyTimeoutMs);\n },\n });\n}\n\ninterface NativeDirectoryEntry {\n name: string;\n path: string;\n type: \"file\" | \"directory\" | \"symlink\" | \"unknown\";\n size: number;\n}\n\nconst DIRECTORY_LIST_SCRIPT = [\n \"import json, os, sys\",\n \"result = []\",\n \"for entry in os.scandir(sys.argv[1]):\",\n \" kind = 'symlink' if entry.is_symlink() else ('directory' if entry.is_dir() else ('file' if entry.is_file() else 'unknown'))\",\n \" result.append({'name': entry.name, 'path': entry.path, 'type': kind, 'size': entry.stat(follow_symlinks=False).st_size})\",\n \"print(json.dumps(result))\",\n].join(\"\\n\");\n\ntype CommandResponse = Awaited<ReturnType<BoxApi[\"command\"]>>;\n\nasync function execute(\n client: BoxApi,\n boxId: string,\n options: {\n command: string;\n cwd?: string;\n timeoutMs?: number;\n signal?: AbortSignal;\n },\n): Promise<CommandResponse> {\n assertNotAborted(options.signal);\n if (options.timeoutMs !== undefined && options.timeoutMs > MAX_COMMAND_TIMEOUT_MS) {\n throw new SandboxError({\n code: \"invalid_input\",\n provider: \"box\",\n operation: \"process.run\",\n message: \"Ascii Box commands support a maximum timeout of 60000ms\",\n });\n }\n return client.command(\n {\n boxId,\n commandRequest: {\n command: options.command,\n cwd: options.cwd,\n timeoutSeconds:\n options.timeoutMs === undefined\n ? undefined\n : Math.max(1, Math.ceil(options.timeoutMs / 1_000)),\n },\n },\n { signal: options.signal },\n );\n}\n\nfunction withEnvironment(\n input: CommandInput,\n environment: Readonly<Record<string, string>> | undefined,\n): string {\n const command = commandString(input);\n const entries = Object.entries(environment ?? {});\n if (entries.length === 0) return command;\n const assignments = entries.map(([key, value]) => shellQuote(`${key}=${value}`));\n return `env ${assignments.join(\" \")} sh -c ${shellQuote(command)}`;\n}\n\nfunction toRemotePath(path: string): string {\n return path === \"/\" ? \".\" : path.replace(/^\\/+/, \"\");\n}\n\nfunction toVirtualPath(path: string): string {\n return `/${path.replace(/^\\.\\/?/, \"\")}`.replace(/\\/$/, \"\") || \"/\";\n}\n\nfunction assertSucceeded(result: CommandResponse, operation: string): void {\n if (result.exitCode === 0) return;\n throw new Error(\n `${operation} failed: ${result.stderr || result.stdout || `exit ${result.exitCode}`}`,\n );\n}\n\nfunction findUrl(output: string): string | undefined {\n return output.match(/https:\\/\\/[^\\s\"']+/)?.[0]?.replace(/[),.;]+$/, \"\");\n}\n\nfunction withProtectedPath(base: string, path: string): URL {\n const protectedUrl = new URL(base);\n const target = new URL(path, base);\n if (target.origin !== protectedUrl.origin) {\n throw new SandboxError({\n code: \"invalid_input\",\n provider: \"box\",\n operation: \"port.request\",\n message: \"Protected Ascii Box preview requests must stay on the preview origin\",\n });\n }\n for (const [key, value] of protectedUrl.searchParams) target.searchParams.set(key, value);\n return target;\n}\n\nfunction withoutProtectedToken(url: string): string {\n const exposed = new URL(url);\n exposed.searchParams.delete(\"_token\");\n return exposed.toString();\n}\n\nasync function waitForState(\n client: BoxApi,\n boxId: string,\n states: ReadonlyArray<NativeBox[\"state\"]>,\n timeoutMs: number,\n): Promise<NativeBox> {\n const deadline = Date.now() + timeoutMs;\n for (;;) {\n const current = (await client.get({ boxId })).box;\n if (states.includes(current.state)) return current;\n if (current.state === \"error\") throw new Error(\"Box entered terminal state error\");\n if (Date.now() >= deadline) throw new Error(\"Timed out waiting for Box state\");\n await new Promise((resolve) => setTimeout(resolve, 1_000));\n }\n}\n\nasync function destroyBox(client: BoxApi, boxId: string, timeoutMs: number): Promise<void> {\n try {\n await client.remove({ boxId });\n return;\n } catch (error) {\n if (!hasResponseStatus(error, 409)) throw error;\n }\n await client.stop({ boxId });\n await waitForState(client, boxId, [\"archived\"], timeoutMs);\n await client.remove({ boxId });\n}\n\nfunction hasResponseStatus(error: unknown, status: number): boolean {\n return (\n typeof error === \"object\" &&\n error !== null &&\n \"response\" in error &&\n typeof error.response === \"object\" &&\n error.response !== null &&\n \"status\" in error.response &&\n error.response.status === status\n );\n}\n\nasync function waitUntilBoxReady(\n client: BoxApi,\n boxId: string,\n signal?: AbortSignal,\n timeoutMs = 600_000,\n): Promise<NativeBox> {\n const deadline = Date.now() + timeoutMs;\n for (;;) {\n assertNotAborted(signal);\n const current = (await client.get({ boxId }, { signal })).box;\n if ([\"ready\", \"idle\", \"running\"].includes(current.state)) return current;\n if ([\"archived\", \"archiving\", \"error\"].includes(current.state)) {\n throw new Error(`Box entered terminal state ${current.state}`);\n }\n const remainingMs = deadline - Date.now();\n if (remainingMs <= 0) {\n throw new Error(`Sandbox creation timed out after ${timeoutMs}ms`);\n }\n await abortableDelay(Math.min(1_000, remainingMs), signal);\n }\n}\n\nfunction abortableDelay(ms: number, signal?: AbortSignal): Promise<void> {\n if (!signal) return new Promise((resolve) => setTimeout(resolve, ms));\n assertNotAborted(signal);\n return new Promise((resolve, reject) => {\n const timer = setTimeout(() => {\n signal.removeEventListener(\"abort\", onAbort);\n resolve();\n }, ms);\n const onAbort = () => {\n clearTimeout(timer);\n reject(signal.reason ?? new DOMException(\"Aborted\", \"AbortError\"));\n };\n signal.addEventListener(\"abort\", onAbort, { once: true });\n });\n}\n\nfunction assertNotAborted(signal?: AbortSignal): void {\n if (signal?.aborted) throw signal.reason ?? new DOMException(\"Aborted\", \"AbortError\");\n}\n\nfunction shellQuote(value: string): string {\n return `'${value.replaceAll(\"'\", `'\"'\"'`)}'`;\n}\n\nexport type BoxSandbox = AsciiBoxSandbox;\n"],"mappings":";;;;;;;;;AAcA,MAAM,mBAAmB;AACzB,MAAM,yBAAyB;AA2B/B,SAAgB,IAAI,UAAsB,EAAE,EAAoC;CAC9E,MAAM,iBAAiB,QAAQ,gBAAgB;CAC/C,MAAM,cAAc,QAAQ,UAAU;AAgNtC,QAAO,oBA9M4C;EACjD,IAAI;EACJ,cAAc;EACd,MAAM,OAAO,eAAe;GAC1B,MA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,CAAC,SAAS,QAAQ,MAAM,CAC5D,OAAM,IAAI,MAAM,8BAA8B,QAAQ,QAAQ;EAEhE,MAAM,cAAc,WAAW,KAAK,KAAK;AACzC,MAAI,eAAe,EACjB,OAAM,IAAI,MAAM,oCAAoC,UAAU,IAAI;AAEpE,QAAM,eAAe,KAAK,IAAI,KAAO,YAAY,EAAE,OAAO;;;AAI9D,SAAS,eAAe,IAAY,QAAqC;AACvE,KAAI,CAAC,OAAQ,QAAO,IAAI,SAAS,YAAY,WAAW,SAAS,GAAG,CAAC;AACrE,kBAAiB,OAAO;AACxB,QAAO,IAAI,SAAS,SAAS,WAAW;EACtC,MAAM,QAAQ,iBAAiB;AAC7B,UAAO,oBAAoB,SAAS,QAAQ;AAC5C,YAAS;KACR,GAAG;EACN,MAAM,gBAAgB;AACpB,gBAAa,MAAM;AACnB,UAAO,OAAO,UAAU,IAAI,aAAa,WAAW,aAAa,CAAC;;AAEpE,SAAO,iBAAiB,SAAS,SAAS,EAAE,MAAM,MAAM,CAAC;GACzD;;AAGJ,SAAS,iBAAiB,QAA4B;AACpD,KAAI,QAAQ,QAAS,OAAM,OAAO,UAAU,IAAI,aAAa,WAAW,aAAa;;AAGvF,SAAS,WAAW,OAAuB;AACzC,QAAO,IAAI,MAAM,WAAW,KAAK,QAAQ,CAAC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import "../../types-
|
|
2
|
-
import { o as SandboxProvider } from "../../provider-
|
|
3
|
-
import "../../index-
|
|
4
|
-
import "../../sandbox-
|
|
5
|
-
import {
|
|
1
|
+
import "../../types-Bv6I2U1c.mjs";
|
|
2
|
+
import { o as SandboxProvider } from "../../provider-DOBErkBO.mjs";
|
|
3
|
+
import "../../index-Dh9xob2s.mjs";
|
|
4
|
+
import "../../sandbox-DdEqoXJF.mjs";
|
|
5
|
+
import { r as daytonaCapabilities } from "../../capabilities-BWvOVFbH.mjs";
|
|
6
6
|
import { Sandbox as DaytonaSandbox } from "@daytona/sdk";
|
|
7
7
|
|
|
8
8
|
//#region src/providers/daytona/index.d.ts
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { r as normalizeError } from "../../errors-
|
|
2
|
-
import "../../capabilities-
|
|
3
|
-
import "../../sandbox-
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import { r as normalizeError } from "../../errors-BuF9bYOQ.mjs";
|
|
2
|
+
import "../../capabilities-xs9kaHrK.mjs";
|
|
3
|
+
import "../../sandbox-DgtY5hvt.mjs";
|
|
4
|
+
import { r as daytonaCapabilities } from "../../capabilities-CaSNd6J1.mjs";
|
|
5
|
+
import { t as withManagedSessions } from "../../managed-provider-BsZGVQ4I.mjs";
|
|
6
|
+
import { a as unsupportedSnapshots, n as portResult, r as toUint8Array, t as commandString } from "../../provider-utils-CfB9nvJx.mjs";
|
|
6
7
|
import { randomUUID } from "node:crypto";
|
|
7
8
|
import { Daytona } from "@daytona/sdk";
|
|
8
9
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["remoteCwd: string","events: ProcessOutputEvent[]","resolveKilled!: () => void"],"sources":["../../../src/providers/daytona/index.ts"],"sourcesContent":["import { Daytona, type Sandbox as DaytonaSandbox } from \"@daytona/sdk\";\nimport { randomUUID } from \"node:crypto\";\nimport { normalizeError } from \"../../core/errors\";\nimport type { SandboxProvider } from \"../../core/provider\";\nimport type { ProcessOutputEvent, SandboxProcess } from \"../../core/types\";\nimport {\n commandString,\n portResult,\n toUint8Array,\n unsupportedSnapshots,\n} from \"../../internal/provider-utils\";\nimport { daytonaCapabilities } from \"../capabilities\";\nimport { withManagedSessions } from \"../../internal/managed-provider\";\n\nexport interface DaytonaOptions {\n apiKey?: string;\n apiUrl?: string;\n target?: string;\n image?: string;\n language?: string;\n name?: string;\n public?: boolean;\n}\n\nexport { daytonaCapabilities } from \"../capabilities\";\n\nexport function daytona(options: DaytonaOptions = {}): SandboxProvider<DaytonaSandbox> {\n return withManagedSessions(\n {\n id: \"daytona\",\n capabilities: daytonaCapabilities,\n async create(createOptions) {\n const client = new Daytona({\n apiKey: options.apiKey,\n apiUrl: options.apiUrl,\n target: options.target,\n });\n const raw = await client.create(\n {\n ...(options.image ? { image: options.image } : {}),\n language: options.language,\n name: options.name,\n public: options.public,\n envVars: { ...createOptions.env },\n },\n {\n timeout: createOptions.timeout ? Math.ceil(createOptions.timeout / 1_000) : undefined,\n },\n );\n let remoteCwd: string;\n try {\n const nativeWorkDir = (await raw.getWorkDir()) ?? createOptions.cwd;\n remoteCwd = `${nativeWorkDir.replace(/\\/$/, \"\")}/${createOptions.cwd.replace(/^\\/+/, \"\")}`;\n try {\n await raw.fs.getFileDetails(remoteCwd);\n } catch (error) {\n if (!isDaytonaNotFound(error, \"sandbox.create.cwd\")) throw error;\n await raw.fs.createFolder(remoteCwd, \"755\");\n }\n } catch (error) {\n await client.delete(raw);\n throw error;\n }\n const toRemotePath = (path: string) =>\n replacePathPrefix(path, createOptions.cwd, remoteCwd);\n const toVirtualPath = (path: string) =>\n replacePathPrefix(path, remoteCwd, createOptions.cwd);\n return {\n id: raw.id,\n raw,\n capabilities: daytonaCapabilities,\n files: {\n async write(path, value) {\n await raw.fs.uploadFile(Buffer.from(await toUint8Array(value)), toRemotePath(path));\n },\n async read(path) {\n return new Uint8Array(await raw.fs.downloadFile(toRemotePath(path)));\n },\n async list(path) {\n const remotePath = toRemotePath(path);\n return (await raw.fs.listFiles(remotePath)).map((entry) => ({\n name: entry.name,\n path: toVirtualPath(entry.path ?? `${remotePath.replace(/\\/$/, \"\")}/${entry.name}`),\n type: entry.isDir ? (\"directory\" as const) : (\"file\" as const),\n size: entry.size,\n }));\n },\n async mkdir(path) {\n await raw.fs.createFolder(toRemotePath(path), \"755\");\n },\n async remove(path) {\n await raw.fs.deleteFile(toRemotePath(path), true);\n },\n async exists(path) {\n try {\n await raw.fs.getFileDetails(toRemotePath(path));\n return true;\n } catch (error) {\n if (isDaytonaNotFound(error, \"files.exists\")) return false;\n throw error;\n }\n },\n },\n async run(command, runOptions) {\n try {\n const started = performance.now();\n const result = await raw.process.executeCommand(\n commandString(command),\n toRemotePath(runOptions.cwd!),\n { ...runOptions.env },\n runOptions.timeout ? Math.ceil(runOptions.timeout / 1_000) : undefined,\n );\n return {\n stdout: result.result,\n stderr: \"\",\n exitCode: result.exitCode,\n success: result.exitCode === 0,\n durationMs: Math.round(performance.now() - started),\n };\n } catch (error) {\n throw normalizeError(\"daytona\", \"process.run\", error);\n }\n },\n async start(command, runOptions) {\n const sessionId = `sandbox-sdk-${randomUUID()}`;\n await raw.process.createSession(sessionId);\n const response = await raw.process.executeSessionCommand(\n sessionId,\n {\n command: sessionCommand(\n commandString(command),\n toRemotePath(runOptions.cwd!),\n runOptions.env,\n ),\n runAsync: true,\n suppressInputEcho: true,\n },\n runOptions.timeout ? Math.ceil(runOptions.timeout / 1_000) : undefined,\n );\n const commandId = response.cmdId;\n const events: ProcessOutputEvent[] = [];\n const waiters = new Set<() => void>();\n let running = true;\n let killed = false;\n let exitCode = 1;\n let resolveKilled!: () => void;\n const killedPromise = new Promise<void>((resolve) => {\n resolveKilled = resolve;\n });\n const push = (stream: \"stdout\" | \"stderr\", data: string) => {\n events.push({ stream, data, timestamp: new Date() });\n for (const wake of waiters) wake();\n waiters.clear();\n };\n const completed = raw.process\n .getSessionCommandLogs(\n sessionId,\n commandId,\n (data) => push(\"stdout\", data),\n (data) => push(\"stderr\", data),\n )\n .then(async () => {\n const info = await raw.process.getSessionCommand(sessionId, commandId);\n exitCode = info.exitCode ?? 1;\n })\n .catch((error) => {\n if (!killed) throw error;\n })\n .finally(() => {\n running = false;\n for (const wake of waiters) wake();\n waiters.clear();\n });\n const process: SandboxProcess = {\n id: commandId,\n async status() {\n if (killed) return \"killed\";\n if (!running) return \"exited\";\n const commandInfo = await raw.process.getSessionCommand(sessionId, commandId);\n return commandInfo.exitCode == null ? \"running\" : \"exited\";\n },\n async *output() {\n let index = 0;\n while (running || index < events.length) {\n while (index < events.length) yield events[index++]!;\n if (!running) break;\n await new Promise<void>((resolve) => waiters.add(resolve));\n }\n },\n write: (value) =>\n raw.process.sendSessionCommandInput(\n sessionId,\n commandId,\n typeof value === \"string\" ? value : new TextDecoder().decode(value),\n ),\n async wait() {\n await Promise.race([completed, killedPromise]);\n return { exitCode };\n },\n async kill() {\n killed = true;\n try {\n await raw.process.deleteSession(sessionId);\n } catch (error) {\n killed = false;\n throw error;\n }\n exitCode = 137;\n running = false;\n resolveKilled();\n for (const wake of waiters) wake();\n waiters.clear();\n },\n };\n return process;\n },\n async expose(port) {\n const preview = await raw.getPreviewLink(port);\n return portResult(port, preview.url, raw.public, !raw.public, (path = \"/\", init = {}) =>\n fetch(new URL(path, preview.url), {\n ...init,\n headers: {\n ...Object.fromEntries(new Headers(init.headers)),\n ...(preview.token ? { \"x-daytona-preview-token\": preview.token } : {}),\n },\n }),\n );\n },\n snapshots: unsupportedSnapshots(\"daytona\"),\n async stop() {\n await client.delete(raw);\n },\n };\n },\n },\n [],\n {\n stop: (sandbox) => sandbox.raw.stop(),\n resume: (sandbox) => sandbox.raw.start(),\n destroy: (sandbox) => sandbox.raw.delete(),\n },\n );\n}\n\nexport type { DaytonaSandbox };\n\nfunction isDaytonaNotFound(error: unknown, operation: string): boolean {\n if (\n typeof error === \"object\" &&\n error !== null &&\n \"statusCode\" in error &&\n error.statusCode === 404\n ) {\n return true;\n }\n return normalizeError(\"daytona\", operation, error).code === \"not_found\";\n}\n\nfunction replacePathPrefix(path: string, from: string, to: string): string {\n if (path === from) return to;\n const prefix = `${from.replace(/\\/$/, \"\")}/`;\n return path.startsWith(prefix) ? `${to.replace(/\\/$/, \"\")}/${path.slice(prefix.length)}` : path;\n}\n\nfunction sessionCommand(\n command: string,\n cwd: string,\n env: Readonly<Record<string, string>> | undefined,\n): string {\n const assignments = Object.entries(env ?? {}).map(([key, value]) =>\n shellQuote(`${key}=${value}`),\n );\n return `cd ${shellQuote(cwd)} && ${assignments.length ? `env ${assignments.join(\" \")} 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W,MAAM,CAAC,SAAS;;AAG9D,SAAS,kBAAkB,MAAc,MAAc,IAAoB;AACzE,KAAI,SAAS,KAAM,QAAO;CAC1B,MAAM,SAAS,GAAG,KAAK,QAAQ,OAAO,GAAG,CAAC;AAC1C,QAAO,KAAK,WAAW,OAAO,GAAG,GAAG,GAAG,QAAQ,OAAO,GAAG,CAAC,GAAG,KAAK,MAAM,OAAO,OAAO,KAAK;;AAG7F,SAAS,eACP,SACA,KACA,KACQ;CACR,MAAM,cAAc,OAAO,QAAQ,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,KAAK,WACvD,WAAW,GAAG,IAAI,GAAG,QAAQ,CAC9B;AACD,QAAO,MAAM,WAAW,IAAI,CAAC,MAAM,YAAY,SAAS,OAAO,YAAY,KAAK,IAAI,CAAC,KAAK,KAAK;;AAGjG,SAAS,WAAW,OAAuB;AACzC,QAAO,IAAI,MAAM,WAAW,KAAK,QAAQ,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["remoteCwd: string","events: ProcessOutputEvent[]","resolveKilled!: () => void"],"sources":["../../../src/providers/daytona/index.ts"],"sourcesContent":["import { Daytona, type Sandbox as DaytonaSandbox } from \"@daytona/sdk\";\nimport { randomUUID } from \"node:crypto\";\nimport { normalizeError } from \"../../core/errors\";\nimport type { SandboxProvider } from \"../../core/provider\";\nimport type { ProcessOutputEvent, SandboxProcess } from \"../../core/types\";\nimport {\n commandString,\n portResult,\n toUint8Array,\n unsupportedSnapshots,\n} from \"../../internal/provider-utils\";\nimport { daytonaCapabilities } from \"../capabilities\";\nimport { withManagedSessions } from \"../../internal/managed-provider\";\n\nexport interface DaytonaOptions {\n apiKey?: string;\n apiUrl?: string;\n target?: string;\n image?: string;\n language?: string;\n name?: string;\n public?: boolean;\n}\n\nexport { daytonaCapabilities } from \"../capabilities\";\n\nexport function daytona(options: DaytonaOptions = {}): SandboxProvider<DaytonaSandbox> {\n return withManagedSessions(\n {\n id: \"daytona\",\n capabilities: daytonaCapabilities,\n async create(createOptions) {\n const client = new Daytona({\n apiKey: options.apiKey,\n apiUrl: options.apiUrl,\n target: options.target,\n });\n const raw = await client.create(\n {\n ...(options.image ? { image: options.image } : {}),\n language: options.language,\n name: options.name,\n public: options.public,\n envVars: { ...createOptions.env },\n },\n {\n timeout: createOptions.timeout ? Math.ceil(createOptions.timeout / 1_000) : undefined,\n },\n );\n let remoteCwd: string;\n try {\n const nativeWorkDir = (await raw.getWorkDir()) ?? createOptions.cwd;\n remoteCwd = `${nativeWorkDir.replace(/\\/$/, \"\")}/${createOptions.cwd.replace(/^\\/+/, \"\")}`;\n try {\n await raw.fs.getFileDetails(remoteCwd);\n } catch (error) {\n if (!isDaytonaNotFound(error, \"sandbox.create.cwd\")) throw error;\n await raw.fs.createFolder(remoteCwd, \"755\");\n }\n } catch (error) {\n await client.delete(raw);\n throw error;\n }\n const toRemotePath = (path: string) =>\n replacePathPrefix(path, createOptions.cwd, remoteCwd);\n const toVirtualPath = (path: string) =>\n replacePathPrefix(path, remoteCwd, createOptions.cwd);\n return {\n id: raw.id,\n raw,\n capabilities: daytonaCapabilities,\n files: {\n async write(path, value) {\n await raw.fs.uploadFile(Buffer.from(await toUint8Array(value)), toRemotePath(path));\n },\n async read(path) {\n return new Uint8Array(await raw.fs.downloadFile(toRemotePath(path)));\n },\n async list(path) {\n const remotePath = toRemotePath(path);\n return (await raw.fs.listFiles(remotePath)).map((entry) => ({\n name: entry.name,\n path: toVirtualPath(entry.path ?? `${remotePath.replace(/\\/$/, \"\")}/${entry.name}`),\n type: entry.isDir ? (\"directory\" as const) : (\"file\" as const),\n size: entry.size,\n }));\n },\n async mkdir(path) {\n await raw.fs.createFolder(toRemotePath(path), \"755\");\n },\n async remove(path) {\n await raw.fs.deleteFile(toRemotePath(path), true);\n },\n async exists(path) {\n try {\n await raw.fs.getFileDetails(toRemotePath(path));\n return true;\n } catch (error) {\n if (isDaytonaNotFound(error, \"files.exists\")) return false;\n throw error;\n }\n },\n },\n async run(command, runOptions) {\n try {\n const started = performance.now();\n const result = await raw.process.executeCommand(\n commandString(command),\n toRemotePath(runOptions.cwd!),\n { ...runOptions.env },\n runOptions.timeout ? Math.ceil(runOptions.timeout / 1_000) : undefined,\n );\n return {\n stdout: result.result,\n stderr: \"\",\n exitCode: result.exitCode,\n success: result.exitCode === 0,\n durationMs: Math.round(performance.now() - started),\n };\n } catch (error) {\n throw normalizeError(\"daytona\", \"process.run\", error);\n }\n },\n async start(command, runOptions) {\n const sessionId = `sandbox-sdk-${randomUUID()}`;\n await raw.process.createSession(sessionId);\n const response = await raw.process.executeSessionCommand(\n sessionId,\n {\n command: sessionCommand(\n commandString(command),\n toRemotePath(runOptions.cwd!),\n runOptions.env,\n ),\n runAsync: true,\n suppressInputEcho: true,\n },\n runOptions.timeout ? Math.ceil(runOptions.timeout / 1_000) : undefined,\n );\n const commandId = response.cmdId;\n const events: ProcessOutputEvent[] = [];\n const waiters = new Set<() => void>();\n let running = true;\n let killed = false;\n let exitCode = 1;\n let resolveKilled!: () => void;\n const killedPromise = new Promise<void>((resolve) => {\n resolveKilled = resolve;\n });\n const push = (stream: \"stdout\" | \"stderr\", data: string) => {\n events.push({ stream, data, timestamp: new Date() });\n for (const wake of waiters) wake();\n waiters.clear();\n };\n const completed = raw.process\n .getSessionCommandLogs(\n sessionId,\n commandId,\n (data) => push(\"stdout\", data),\n (data) => push(\"stderr\", data),\n )\n .then(async () => {\n const info = await raw.process.getSessionCommand(sessionId, commandId);\n exitCode = info.exitCode ?? 1;\n })\n .catch((error) => {\n if (!killed) throw error;\n })\n .finally(() => {\n running = false;\n for (const wake of waiters) wake();\n waiters.clear();\n });\n const process: SandboxProcess = {\n id: commandId,\n async status() {\n if (killed) return \"killed\";\n if (!running) return \"exited\";\n const commandInfo = await raw.process.getSessionCommand(sessionId, commandId);\n return commandInfo.exitCode == null ? \"running\" : \"exited\";\n },\n async *output() {\n let index = 0;\n while (running || index < events.length) {\n while (index < events.length) yield events[index++]!;\n if (!running) break;\n await new Promise<void>((resolve) => waiters.add(resolve));\n }\n },\n write: (value) =>\n raw.process.sendSessionCommandInput(\n sessionId,\n commandId,\n typeof value === \"string\" ? value : new TextDecoder().decode(value),\n ),\n async wait() {\n await Promise.race([completed, killedPromise]);\n return { exitCode };\n },\n async kill() {\n killed = true;\n try {\n await raw.process.deleteSession(sessionId);\n } catch (error) {\n killed = false;\n throw error;\n }\n exitCode = 137;\n running = false;\n resolveKilled();\n for (const wake of waiters) wake();\n waiters.clear();\n },\n };\n return process;\n },\n async expose(port) {\n const preview = await raw.getPreviewLink(port);\n return portResult(port, preview.url, raw.public, !raw.public, (path = \"/\", init = {}) =>\n fetch(new URL(path, preview.url), {\n ...init,\n headers: {\n ...Object.fromEntries(new Headers(init.headers)),\n ...(preview.token ? { \"x-daytona-preview-token\": preview.token } : {}),\n },\n }),\n );\n },\n snapshots: unsupportedSnapshots(\"daytona\"),\n async stop() {\n await client.delete(raw);\n },\n };\n },\n },\n [],\n {\n stop: (sandbox) => sandbox.raw.stop(),\n resume: (sandbox) => sandbox.raw.start(),\n destroy: (sandbox) => sandbox.raw.delete(),\n },\n );\n}\n\nexport type { DaytonaSandbox };\n\nfunction isDaytonaNotFound(error: unknown, operation: string): boolean {\n if (\n typeof error === \"object\" &&\n error !== null &&\n \"statusCode\" in error &&\n error.statusCode === 404\n ) {\n return true;\n }\n return normalizeError(\"daytona\", operation, error).code === \"not_found\";\n}\n\nfunction replacePathPrefix(path: string, from: string, to: string): string {\n if (path === from) return to;\n const prefix = `${from.replace(/\\/$/, \"\")}/`;\n return path.startsWith(prefix) ? `${to.replace(/\\/$/, \"\")}/${path.slice(prefix.length)}` : path;\n}\n\nfunction sessionCommand(\n command: string,\n cwd: string,\n env: Readonly<Record<string, string>> | undefined,\n): string {\n const assignments = Object.entries(env ?? {}).map(([key, value]) =>\n shellQuote(`${key}=${value}`),\n );\n return `cd ${shellQuote(cwd)} && ${assignments.length ? `env ${assignments.join(\" \")} ` : \"\"}${command}`;\n}\n\nfun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G9D,SAAS,kBAAkB,MAAc,MAAc,IAAoB;AACzE,KAAI,SAAS,KAAM,QAAO;CAC1B,MAAM,SAAS,GAAG,KAAK,QAAQ,OAAO,GAAG,CAAC;AAC1C,QAAO,KAAK,WAAW,OAAO,GAAG,GAAG,GAAG,QAAQ,OAAO,GAAG,CAAC,GAAG,KAAK,MAAM,OAAO,OAAO,KAAK;;AAG7F,SAAS,eACP,SACA,KACA,KACQ;CACR,MAAM,cAAc,OAAO,QAAQ,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,KAAK,WACvD,WAAW,GAAG,IAAI,GAAG,QAAQ,CAC9B;AACD,QAAO,MAAM,WAAW,IAAI,CAAC,MAAM,YAAY,SAAS,OAAO,YAAY,KAAK,IAAI,CAAC,KAAK,KAAK;;AAGjG,SAAS,WAAW,OAAuB;AACzC,QAAO,IAAI,MAAM,WAAW,KAAK,QAAQ,CAAC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import "../../types-
|
|
2
|
-
import { o as SandboxProvider } from "../../provider-
|
|
3
|
-
import "../../index-
|
|
4
|
-
import "../../sandbox-
|
|
5
|
-
import {
|
|
1
|
+
import "../../types-Bv6I2U1c.mjs";
|
|
2
|
+
import { o as SandboxProvider } from "../../provider-DOBErkBO.mjs";
|
|
3
|
+
import "../../index-Dh9xob2s.mjs";
|
|
4
|
+
import "../../sandbox-DdEqoXJF.mjs";
|
|
5
|
+
import { i as e2bCapabilities } from "../../capabilities-BWvOVFbH.mjs";
|
|
6
6
|
import { Sandbox as E2BSandbox } from "e2b";
|
|
7
7
|
|
|
8
8
|
//#region src/providers/e2b/index.d.ts
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { r as normalizeError } from "../../errors-
|
|
2
|
-
import "../../capabilities-
|
|
3
|
-
import "../../sandbox-
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import { r as normalizeError } from "../../errors-BuF9bYOQ.mjs";
|
|
2
|
+
import "../../capabilities-xs9kaHrK.mjs";
|
|
3
|
+
import "../../sandbox-DgtY5hvt.mjs";
|
|
4
|
+
import { i as e2bCapabilities } from "../../capabilities-CaSNd6J1.mjs";
|
|
5
|
+
import { t as withManagedSessions } from "../../managed-provider-BsZGVQ4I.mjs";
|
|
6
|
+
import { i as unsupported, n as portResult, r as toUint8Array, t as commandString } from "../../provider-utils-CfB9nvJx.mjs";
|
|
6
7
|
import { Sandbox } from "e2b";
|
|
7
8
|
|
|
8
9
|
//#region src/providers/e2b/index.ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["E2BSandbox","events: ProcessOutputEvent[]"],"sources":["../../../src/providers/e2b/index.ts"],"sourcesContent":["import { Sandbox as E2BSandbox } from \"e2b\";\nimport { normalizeError } from \"../../core/errors\";\nimport type { SandboxProvider } from \"../../core/provider\";\nimport type { ProcessOutputEvent, SandboxProcess, SandboxSnapshot } from \"../../core/types\";\nimport {\n commandString,\n portResult,\n toUint8Array,\n unsupported,\n} from \"../../internal/provider-utils\";\nimport { e2bCapabilities } from \"../capabilities\";\nimport { withManagedSessions } from \"../../internal/managed-provider\";\n\nexport interface E2BOptions {\n apiKey?: string;\n template?: string;\n timeout?: number;\n}\n\nexport { e2bCapabilities } from \"../capabilities\";\n\nexport function e2b(options: E2BOptions = {}): SandboxProvider<E2BSandbox> {\n return withManagedSessions(\n {\n id: \"e2b\",\n capabilities: e2bCapabilities,\n async create(createOptions) {\n const create = {\n apiKey: options.apiKey,\n timeoutMs: options.timeout ?? createOptions.timeout,\n envs: { ...createOptions.env },\n signal: createOptions.signal,\n };\n const raw = options.template\n ? await E2BSandbox.create(options.template, create)\n : await E2BSandbox.create(create);\n try {\n await raw.files.makeDir(createOptions.cwd);\n } catch (error) {\n await raw.kill().catch(() => undefined);\n throw error;\n }\n return {\n id: raw.sandboxId,\n raw,\n capabilities: e2bCapabilities,\n files: {\n async write(path, value) {\n await raw.files.write(path, Uint8Array.from(await toUint8Array(value)).buffer);\n },\n read: (path) => raw.files.read(path, { format: \"bytes\" }),\n async list(path) {\n return (await raw.files.list(path)).map((entry) => ({\n name: entry.name,\n path: entry.path,\n type:\n entry.type === \"file\"\n ? (\"file\" as const)\n : entry.type === \"dir\"\n ? (\"directory\" as const)\n : (\"unknown\" as const),\n size: entry.size,\n }));\n },\n async mkdir(path) {\n await raw.files.makeDir(path);\n },\n remove: (path) => raw.files.remove(path),\n exists: (path) => raw.files.exists(path),\n },\n async run(command, runOptions) {\n try {\n const started = performance.now();\n const result = await raw.commands.run(commandString(command), {\n cwd: runOptions.cwd,\n envs: { ...runOptions.env },\n timeoutMs: runOptions.timeout,\n signal: runOptions.signal,\n });\n return {\n stdout: result.stdout,\n stderr: result.stderr,\n exitCode: result.exitCode,\n success: result.exitCode === 0,\n durationMs: Math.round(performance.now() - started),\n };\n } catch (error) {\n throw normalizeError(\"e2b\", \"process.run\", error);\n }\n },\n async start(command, runOptions) {\n const events: ProcessOutputEvent[] = [];\n const waiters = new Set<() => void>();\n let running = true;\n const push = (stream: \"stdout\" | \"stderr\", data: string) => {\n events.push({ stream, data, timestamp: new Date() });\n for (const wake of waiters) wake();\n waiters.clear();\n };\n const handle = await raw.commands.run(commandString(command), {\n cwd: runOptions.cwd,\n envs: { ...runOptions.env },\n timeoutMs: runOptions.timeout,\n signal: runOptions.signal,\n background: true,\n stdin: true,\n onStdout: (data) => push(\"stdout\", data),\n onStderr: (data) => push(\"stderr\", data),\n });\n const completed = handle.wait().then((result) => ({ exitCode: result.exitCode }));\n const finish = () => {\n running = false;\n for (const wake of waiters) wake();\n waiters.clear();\n };\n void completed.then(finish, finish);\n const process: SandboxProcess = {\n id: String(handle.pid),\n async status() {\n return running ? \"running\" : \"exited\";\n },\n async *output() {\n let index = 0;\n while (running || index < events.length) {\n while (index < events.length) yield events[index++]!;\n if (!running) break;\n await new Promise<void>((resolve) => waiters.add(resolve));\n }\n },\n write: (value) => handle.sendStdin(value),\n wait: () => completed,\n async kill() {\n await handle.kill();\n running = false;\n },\n };\n return process;\n },\n async expose(port) {\n const host = raw.getHost(port);\n const url = `https://${host}`;\n const token = raw.trafficAccessToken;\n return portResult(\n port,\n url,\n !token,\n Boolean(token),\n token\n ? (path = \"/\", init = {}) =>\n fetch(new URL(path, url), {\n ...init,\n headers: {\n ...Object.fromEntries(new Headers(init.headers)),\n \"x-access-token\": token,\n },\n })\n : undefined,\n );\n },\n snapshots: {\n async create(snapshotOptions) {\n const snapshot = await raw.createSnapshot({ name: snapshotOptions?.name });\n return {\n id: snapshot.snapshotId,\n name: snapshot.names[0],\n mode: \"template\",\n } as SandboxSnapshot;\n },\n async delete(snapshot) {\n await E2BSandbox.deleteSnapshot(\n typeof snapshot === \"string\" ? snapshot : snapshot.id,\n {\n apiKey: options.apiKey,\n },\n );\n },\n async restore() {\n unsupported(\"e2b\", \"snapshot.restore\");\n },\n },\n async stop() {\n await raw.kill();\n },\n };\n },\n },\n [],\n {\n stop: async (sandbox) => {\n await sandbox.raw.pause();\n },\n resume: async (sandbox) => {\n await sandbox.raw.connect();\n },\n destroy: async (sandbox) => {\n await sandbox.raw.kill();\n },\n },\n );\n}\n\nexport type { E2BSandbox };\n"],"mappings":";;;;;;;;AAqBA,SAAgB,IAAI,UAAsB,EAAE,EAA+B;AACzE,QAAO,oBACL;EACE,IAAI;EACJ,cAAc;EACd,MAAM,OAAO,eAAe;GAC1B,MAAM,SAAS;IACb,QAAQ,QAAQ;IAChB,WAAW,QAAQ,WAAW,cAAc;IAC5C,MAAM,EAAE,GAAG,cAAc,KAAK;IAC9B,QAAQ,cAAc;IACvB;GACD,MAAM,MAAM,QAAQ,WAChB,MAAMA,QAAW,OAAO,QAAQ,UAAU,OAAO,GACjD,MAAMA,QAAW,OAAO,OAAO;AACnC,OAAI;AACF,UAAM,IAAI,MAAM,QAAQ,cAAc,IAAI;YACnC,OAAO;AACd,UAAM,IAAI,MAAM,CAAC,YAAY,OAAU;AACvC,UAAM;;AAER,UAAO;IACL,IAAI,IAAI;IACR;IACA,cA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OACL;;IAEH,WAAW;KACT,MAAM,OAAO,iBAAiB;MAC5B,MAAM,WAAW,MAAM,IAAI,eAAe,EAAE,MAAM,iBAAiB,MAAM,CAAC;AAC1E,aAAO;OACL,IAAI,SAAS;OACb,MAAM,SAAS,MAAM;OACrB,MAAM;OACP;;KAEH,MAAM,OAAO,UAAU;AACrB,YAAMD,QAAW,eACf,OAAO,aAAa,WAAW,WAAW,SAAS,IACnD,EACE,QAAQ,QAAQ,QACjB,CACF;;KAEH,MAAM,UAAU;AACd,kBAAY,OAAO,mBAAmB;;KAEzC;IACD,MAAM,OAAO;AACX,WAAM,IAAI,MAAM;;IAEnB;;EAEJ,EACD,EAAE,EACF;EACE,MAAM,OAAO,YAAY;AACvB,SAAM,QAAQ,IAAI,OAAO;;EAE3B,QAAQ,OAAO,YAAY;AACzB,SAAM,QAAQ,IAAI,SAAS;;EAE7B,SAAS,OAAO,YAAY;AAC1B,SAAM,QAAQ,IAAI,MAAM;;EAE3B,CACF"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["E2BSandbox","events: ProcessOutputEvent[]"],"sources":["../../../src/providers/e2b/index.ts"],"sourcesContent":["import { Sandbox as E2BSandbox } from \"e2b\";\nimport { normalizeError } from \"../../core/errors\";\nimport type { SandboxProvider } from \"../../core/provider\";\nimport type { ProcessOutputEvent, SandboxProcess, SandboxSnapshot } from \"../../core/types\";\nimport {\n commandString,\n portResult,\n toUint8Array,\n unsupported,\n} from \"../../internal/provider-utils\";\nimport { e2bCapabilities } from \"../capabilities\";\nimport { withManagedSessions } from \"../../internal/managed-provider\";\n\nexport interface E2BOptions {\n apiKey?: string;\n template?: string;\n timeout?: number;\n}\n\nexport { e2bCapabilities } from \"../capabilities\";\n\nexport function e2b(options: E2BOptions = {}): SandboxProvider<E2BSandbox> {\n return withManagedSessions(\n {\n id: \"e2b\",\n capabilities: e2bCapabilities,\n async create(createOptions) {\n const create = {\n apiKey: options.apiKey,\n timeoutMs: options.timeout ?? createOptions.timeout,\n envs: { ...createOptions.env },\n signal: createOptions.signal,\n };\n const raw = options.template\n ? await E2BSandbox.create(options.template, create)\n : await E2BSandbox.create(create);\n try {\n await raw.files.makeDir(createOptions.cwd);\n } catch (error) {\n await raw.kill().catch(() => undefined);\n throw error;\n }\n return {\n id: raw.sandboxId,\n raw,\n capabilities: e2bCapabilities,\n files: {\n async write(path, value) {\n await raw.files.write(path, Uint8Array.from(await toUint8Array(value)).buffer);\n },\n read: (path) => raw.files.read(path, { format: \"bytes\" }),\n async list(path) {\n return (await raw.files.list(path)).map((entry) => ({\n name: entry.name,\n path: entry.path,\n type:\n entry.type === \"file\"\n ? (\"file\" as const)\n : entry.type === \"dir\"\n ? (\"directory\" as const)\n : (\"unknown\" as const),\n size: entry.size,\n }));\n },\n async mkdir(path) {\n await raw.files.makeDir(path);\n },\n remove: (path) => raw.files.remove(path),\n exists: (path) => raw.files.exists(path),\n },\n async run(command, runOptions) {\n try {\n const started = performance.now();\n const result = await raw.commands.run(commandString(command), {\n cwd: runOptions.cwd,\n envs: { ...runOptions.env },\n timeoutMs: runOptions.timeout,\n signal: runOptions.signal,\n });\n return {\n stdout: result.stdout,\n stderr: result.stderr,\n exitCode: result.exitCode,\n success: result.exitCode === 0,\n durationMs: Math.round(performance.now() - started),\n };\n } catch (error) {\n throw normalizeError(\"e2b\", \"process.run\", error);\n }\n },\n async start(command, runOptions) {\n const events: ProcessOutputEvent[] = [];\n const waiters = new Set<() => void>();\n let running = true;\n const push = (stream: \"stdout\" | \"stderr\", data: string) => {\n events.push({ stream, data, timestamp: new Date() });\n for (const wake of waiters) wake();\n waiters.clear();\n };\n const handle = await raw.commands.run(commandString(command), {\n cwd: runOptions.cwd,\n envs: { ...runOptions.env },\n timeoutMs: runOptions.timeout,\n signal: runOptions.signal,\n background: true,\n stdin: true,\n onStdout: (data) => push(\"stdout\", data),\n onStderr: (data) => push(\"stderr\", data),\n });\n const completed = handle.wait().then((result) => ({ exitCode: result.exitCode }));\n const finish = () => {\n running = false;\n for (const wake of waiters) wake();\n waiters.clear();\n };\n void completed.then(finish, finish);\n const process: SandboxProcess = {\n id: String(handle.pid),\n async status() {\n return running ? \"running\" : \"exited\";\n },\n async *output() {\n let index = 0;\n while (running || index < events.length) {\n while (index < events.length) yield events[index++]!;\n if (!running) break;\n await new Promise<void>((resolve) => waiters.add(resolve));\n }\n },\n write: (value) => handle.sendStdin(value),\n wait: () => completed,\n async kill() {\n await handle.kill();\n running = false;\n },\n };\n return process;\n },\n async expose(port) {\n const host = raw.getHost(port);\n const url = `https://${host}`;\n const token = raw.trafficAccessToken;\n return portResult(\n port,\n url,\n !token,\n Boolean(token),\n token\n ? (path = \"/\", init = {}) =>\n fetch(new URL(path, url), {\n ...init,\n headers: {\n ...Object.fromEntries(new Headers(init.headers)),\n \"x-access-token\": token,\n },\n })\n : undefined,\n );\n },\n snapshots: {\n async create(snapshotOptions) {\n const snapshot = await raw.createSnapshot({ name: snapshotOptions?.name });\n return {\n id: snapshot.snapshotId,\n name: snapshot.names[0],\n mode: \"template\",\n } as SandboxSnapshot;\n },\n async delete(snapshot) {\n await E2BSandbox.deleteSnapshot(\n typeof snapshot === \"string\" ? snapshot : snapshot.id,\n {\n apiKey: options.apiKey,\n },\n );\n },\n async restore() {\n unsupported(\"e2b\", \"snapshot.restore\");\n },\n },\n async stop() {\n await raw.kill();\n },\n };\n },\n },\n [],\n {\n stop: async (sandbox) => {\n await sandbox.raw.pause();\n },\n resume: async (sandbox) => {\n await sandbox.raw.connect();\n },\n destroy: async (sandbox) => {\n await sandbox.raw.kill();\n },\n },\n );\n}\n\nexport type { E2BSandbox };\n"],"mappings":";;;;;;;;;AAqBA,SAAgB,IAAI,UAAsB,EAAE,EAA+B;AACzE,QAAO,oBACL;EACE,IAAI;EACJ,cAAc;EACd,MAAM,OAAO,eAAe;GAC1B,MAAM,SAAS;IACb,QAAQ,QAAQ;IAChB,WAAW,QAAQ,WAAW,cAAc;IAC5C,MAAM,EAAE,GAAG,cAAc,KAAK;IAC9B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AAQ,KAAK;KAE9B,MAAM,QAAQ,IAAI;AAClB,YAAO,WACL,MACA,KACA,CAAC,OACD,QAAQ,MAAM,EACd,SACK,OAAO,KAAK,OAAO,EAAE,KACpB,MAAM,IAAI,IAAI,MAAM,IAAI,EAAE;MACxB,GAAG;MACH,SAAS;OACP,GAAG,OAAO,YAAY,IAAI,QAAQ,KAAK,QAAQ,CAAC;OAChD,kBAAkB;OACnB;MACF,CAAC,GACJ,OACL;;IAEH,WAAW;KACT,MAAM,OAAO,iBAAiB;MAC5B,MAAM,WAAW,MAAM,IAAI,eAAe,EAAE,MAAM,iBAAiB,MAAM,CAAC;AAC1E,aAAO;OACL,IAAI,SAAS;OACb,MAAM,SAAS,MAAM;OACrB,MAAM;OACP;;KAEH,MAAM,OAAO,UAAU;AACrB,YAAMD,QAAW,eACf,OAAO,aAAa,WAAW,WAAW,SAAS,IACnD,EACE,QAAQ,QAAQ,QACjB,CACF;;KAEH,MAAM,UAAU;AACd,kBAAY,OAAO,mBAAmB;;KAEzC;IACD,MAAM,OAAO;AACX,WAAM,IAAI,MAAM;;IAEnB;;EAEJ,EACD,EAAE,EACF;EACE,MAAM,OAAO,YAAY;AACvB,SAAM,QAAQ,IAAI,OAAO;;EAE3B,QAAQ,OAAO,YAAY;AACzB,SAAM,QAAQ,IAAI,SAAS;;EAE7B,SAAS,OAAO,YAAY;AAC1B,SAAM,QAAQ,IAAI,MAAM;;EAE3B,CACF"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import "../../types-
|
|
2
|
-
import { o as SandboxProvider } from "../../provider-
|
|
3
|
-
import "../../index-
|
|
4
|
-
import "../../sandbox-
|
|
5
|
-
import {
|
|
6
|
-
import { n as AgentOsSandbox, t as AgentOsProviderOptions } from "../../index-
|
|
1
|
+
import "../../types-Bv6I2U1c.mjs";
|
|
2
|
+
import { o as SandboxProvider } from "../../provider-DOBErkBO.mjs";
|
|
3
|
+
import "../../index-Dh9xob2s.mjs";
|
|
4
|
+
import "../../sandbox-DdEqoXJF.mjs";
|
|
5
|
+
import { a as localCapabilities } from "../../capabilities-BWvOVFbH.mjs";
|
|
6
|
+
import { n as AgentOsSandbox, t as AgentOsProviderOptions } from "../../index-CkTwqD0X.mjs";
|
|
7
7
|
|
|
8
8
|
//#region src/providers/local/index.d.ts
|
|
9
9
|
/** Options passed to the AgentOS VM that powers the Local provider. */
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import "../../errors-
|
|
2
|
-
import "../../capabilities-
|
|
3
|
-
import "../../sandbox-
|
|
4
|
-
import {
|
|
5
|
-
import "../../provider-
|
|
6
|
-
import
|
|
1
|
+
import "../../errors-BuF9bYOQ.mjs";
|
|
2
|
+
import "../../capabilities-xs9kaHrK.mjs";
|
|
3
|
+
import "../../sandbox-DgtY5hvt.mjs";
|
|
4
|
+
import { a as localCapabilities } from "../../capabilities-CaSNd6J1.mjs";
|
|
5
|
+
import "../../managed-provider-BsZGVQ4I.mjs";
|
|
6
|
+
import "../../provider-utils-CfB9nvJx.mjs";
|
|
7
|
+
import { t as agentos } from "../../agentos-CbrZW7R0.mjs";
|
|
7
8
|
|
|
8
9
|
//#region src/providers/local/index.ts
|
|
9
10
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["createAgentOsRuntime"],"sources":["../../../src/providers/local/index.ts"],"sourcesContent":["import type { SandboxProvider } from \"../../core/provider\";\nimport {\n agentos as createAgentOsRuntime,\n type AgentOsProviderOptions,\n type AgentOsSandbox,\n} from \"../agentos\";\n\n/** Options passed to the AgentOS VM that powers the Local provider. */\nexport interface LocalOptions extends AgentOsProviderOptions {}\n\n/** Native AgentOS access for a Local sandbox. */\nexport type LocalSandbox = AgentOsSandbox;\n\nexport { localCapabilities } from \"../capabilities\";\n\n/**\n * Runs an isolated AgentOS VM inside the current Node.js process.\n *\n * AgentOS is an implementation detail of the Local provider. Outbound networking and host bindings\n * are denied by default; pass native options under `agentOs` to configure the VM explicitly.\n */\nexport function local(options: LocalOptions = {}): SandboxProvider<LocalSandbox> {\n return createAgentOsRuntime(options);\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["createAgentOsRuntime"],"sources":["../../../src/providers/local/index.ts"],"sourcesContent":["import type { SandboxProvider } from \"../../core/provider\";\nimport {\n agentos as createAgentOsRuntime,\n type AgentOsProviderOptions,\n type AgentOsSandbox,\n} from \"../agentos\";\n\n/** Options passed to the AgentOS VM that powers the Local provider. */\nexport interface LocalOptions extends AgentOsProviderOptions {}\n\n/** Native AgentOS access for a Local sandbox. */\nexport type LocalSandbox = AgentOsSandbox;\n\nexport { localCapabilities } from \"../capabilities\";\n\n/**\n * Runs an isolated AgentOS VM inside the current Node.js process.\n *\n * AgentOS is an implementation detail of the Local provider. Outbound networking and host bindings\n * are denied by default; pass native options under `agentOs` to configure the VM explicitly.\n */\nexport function local(options: LocalOptions = {}): SandboxProvider<LocalSandbox> {\n return createAgentOsRuntime(options);\n}\n"],"mappings":";;;;;;;;;;;;;;;AAqBA,SAAgB,MAAM,UAAwB,EAAE,EAAiC;AAC/E,QAAOA,QAAqB,QAAQ"}
|