@meistrari/sandbox-sdk 1.5.1 → 1.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -6
- package/dist/index.cjs +17 -6
- package/dist/index.mjs +17 -6
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -213,20 +213,26 @@ const result = await sandbox.runCode(`
|
|
|
213
213
|
await sandbox.kill()
|
|
214
214
|
```
|
|
215
215
|
|
|
216
|
-
### Selecting a
|
|
216
|
+
### Selecting a Backend
|
|
217
217
|
|
|
218
218
|
```typescript
|
|
219
|
-
//
|
|
220
|
-
//
|
|
219
|
+
// `agent-sandbox`, `lambda-microvm` or `e2b`; omitting it uses the
|
|
220
|
+
// deployment's default. Naming one is a promise: the request is served by
|
|
221
|
+
// that backend or it fails.
|
|
221
222
|
const run = await client.createRunAndWait({
|
|
222
223
|
code: 'console.log("Hello")',
|
|
223
224
|
language: 'typescript',
|
|
224
|
-
|
|
225
|
+
provider: 'lambda-microvm',
|
|
225
226
|
})
|
|
226
227
|
|
|
227
|
-
const sandbox = await client.createSandbox({
|
|
228
|
+
const sandbox = await client.createSandbox({ provider: 'lambda-microvm' })
|
|
228
229
|
```
|
|
229
230
|
|
|
231
|
+
`runtime` is the older name for the same setting and still works — it is
|
|
232
|
+
resolved to `provider` before the request goes out. Naming both to different
|
|
233
|
+
backends is refused rather than guessed. Prefer `provider`: it is what the API
|
|
234
|
+
reads, what a run reports back, and what `/health` lists.
|
|
235
|
+
|
|
230
236
|
### Streaming Output
|
|
231
237
|
|
|
232
238
|
```typescript
|
|
@@ -327,7 +333,8 @@ interface CreateRunRequest {
|
|
|
327
333
|
timeoutMs?: number // ms (default: 300000)
|
|
328
334
|
sandboxId?: string // Use existing sandbox
|
|
329
335
|
persistent?: boolean // Keep sandbox after execution
|
|
330
|
-
|
|
336
|
+
provider?: string // Sandbox backend (default: the deployment's)
|
|
337
|
+
runtime?: SandboxRuntime // Older name for `provider`; resolved to it
|
|
331
338
|
}
|
|
332
339
|
|
|
333
340
|
interface RunCodeOptions {
|
package/dist/index.cjs
CHANGED
|
@@ -259,6 +259,19 @@ function assertSupportedRuntime(runtime) {
|
|
|
259
259
|
throw new Error(`Unsupported runtime "${runtime}". Supported runtimes: ${SANDBOX_RUNTIMES.join(", ")}`);
|
|
260
260
|
}
|
|
261
261
|
}
|
|
262
|
+
function withProvider(request) {
|
|
263
|
+
assertSupportedRuntime(request.runtime);
|
|
264
|
+
if (request.runtime === void 0) {
|
|
265
|
+
return request;
|
|
266
|
+
}
|
|
267
|
+
if (request.provider !== void 0 && request.provider !== request.runtime) {
|
|
268
|
+
throw new Error(
|
|
269
|
+
`Conflicting backends: runtime "${request.runtime}" and provider "${request.provider}". They are the same setting; name only one.`
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
const { runtime, ...rest } = request;
|
|
273
|
+
return { ...rest, provider: runtime };
|
|
274
|
+
}
|
|
262
275
|
class SandboxClient {
|
|
263
276
|
constructor(config) {
|
|
264
277
|
__publicField(this, "apiUrl");
|
|
@@ -284,10 +297,9 @@ class SandboxClient {
|
|
|
284
297
|
}
|
|
285
298
|
// === Runs ===
|
|
286
299
|
async createRun(request) {
|
|
287
|
-
assertSupportedRuntime(request.runtime);
|
|
288
300
|
const response = await this.fetch("/api/runs", {
|
|
289
301
|
method: "POST",
|
|
290
|
-
body: JSON.stringify(request)
|
|
302
|
+
body: JSON.stringify(withProvider(request))
|
|
291
303
|
});
|
|
292
304
|
return new SandboxRun(this, response.data);
|
|
293
305
|
}
|
|
@@ -296,7 +308,7 @@ class SandboxClient {
|
|
|
296
308
|
return await run.waitForCompletion();
|
|
297
309
|
}
|
|
298
310
|
async *streamRun(request) {
|
|
299
|
-
|
|
311
|
+
const resolved = withProvider(request);
|
|
300
312
|
const url = `${this.apiUrl}/api/runs/stream`;
|
|
301
313
|
const headers = new Headers();
|
|
302
314
|
const authHeaders = this.auth.getHeaders();
|
|
@@ -307,7 +319,7 @@ class SandboxClient {
|
|
|
307
319
|
const res = await fetch(url, {
|
|
308
320
|
method: "POST",
|
|
309
321
|
headers,
|
|
310
|
-
body: JSON.stringify(
|
|
322
|
+
body: JSON.stringify(resolved)
|
|
311
323
|
});
|
|
312
324
|
if (!res.ok) {
|
|
313
325
|
throw await FetchError.from(url, "POST", res);
|
|
@@ -406,10 +418,9 @@ class SandboxClient {
|
|
|
406
418
|
}
|
|
407
419
|
// === Sandboxes ===
|
|
408
420
|
async createSandbox(request = {}) {
|
|
409
|
-
assertSupportedRuntime(request.runtime);
|
|
410
421
|
const response = await this.fetch("/api/sandboxes", {
|
|
411
422
|
method: "POST",
|
|
412
|
-
body: JSON.stringify(request)
|
|
423
|
+
body: JSON.stringify(withProvider(request))
|
|
413
424
|
});
|
|
414
425
|
return new Sandbox(this, response.data.sandboxId, this.auth, response.data);
|
|
415
426
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -257,6 +257,19 @@ function assertSupportedRuntime(runtime) {
|
|
|
257
257
|
throw new Error(`Unsupported runtime "${runtime}". Supported runtimes: ${SANDBOX_RUNTIMES.join(", ")}`);
|
|
258
258
|
}
|
|
259
259
|
}
|
|
260
|
+
function withProvider(request) {
|
|
261
|
+
assertSupportedRuntime(request.runtime);
|
|
262
|
+
if (request.runtime === void 0) {
|
|
263
|
+
return request;
|
|
264
|
+
}
|
|
265
|
+
if (request.provider !== void 0 && request.provider !== request.runtime) {
|
|
266
|
+
throw new Error(
|
|
267
|
+
`Conflicting backends: runtime "${request.runtime}" and provider "${request.provider}". They are the same setting; name only one.`
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
const { runtime, ...rest } = request;
|
|
271
|
+
return { ...rest, provider: runtime };
|
|
272
|
+
}
|
|
260
273
|
class SandboxClient {
|
|
261
274
|
constructor(config) {
|
|
262
275
|
__publicField(this, "apiUrl");
|
|
@@ -282,10 +295,9 @@ class SandboxClient {
|
|
|
282
295
|
}
|
|
283
296
|
// === Runs ===
|
|
284
297
|
async createRun(request) {
|
|
285
|
-
assertSupportedRuntime(request.runtime);
|
|
286
298
|
const response = await this.fetch("/api/runs", {
|
|
287
299
|
method: "POST",
|
|
288
|
-
body: JSON.stringify(request)
|
|
300
|
+
body: JSON.stringify(withProvider(request))
|
|
289
301
|
});
|
|
290
302
|
return new SandboxRun(this, response.data);
|
|
291
303
|
}
|
|
@@ -294,7 +306,7 @@ class SandboxClient {
|
|
|
294
306
|
return await run.waitForCompletion();
|
|
295
307
|
}
|
|
296
308
|
async *streamRun(request) {
|
|
297
|
-
|
|
309
|
+
const resolved = withProvider(request);
|
|
298
310
|
const url = `${this.apiUrl}/api/runs/stream`;
|
|
299
311
|
const headers = new Headers();
|
|
300
312
|
const authHeaders = this.auth.getHeaders();
|
|
@@ -305,7 +317,7 @@ class SandboxClient {
|
|
|
305
317
|
const res = await fetch(url, {
|
|
306
318
|
method: "POST",
|
|
307
319
|
headers,
|
|
308
|
-
body: JSON.stringify(
|
|
320
|
+
body: JSON.stringify(resolved)
|
|
309
321
|
});
|
|
310
322
|
if (!res.ok) {
|
|
311
323
|
throw await FetchError.from(url, "POST", res);
|
|
@@ -404,10 +416,9 @@ class SandboxClient {
|
|
|
404
416
|
}
|
|
405
417
|
// === Sandboxes ===
|
|
406
418
|
async createSandbox(request = {}) {
|
|
407
|
-
assertSupportedRuntime(request.runtime);
|
|
408
419
|
const response = await this.fetch("/api/sandboxes", {
|
|
409
420
|
method: "POST",
|
|
410
|
-
body: JSON.stringify(request)
|
|
421
|
+
body: JSON.stringify(withProvider(request))
|
|
411
422
|
});
|
|
412
423
|
return new Sandbox(this, response.data.sandboxId, this.auth, response.data);
|
|
413
424
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meistrari/sandbox-sdk",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
],
|
|
17
17
|
"scripts": {
|
|
18
18
|
"build": "unbuild",
|
|
19
|
-
"test": "
|
|
19
|
+
"test": "bun test test",
|
|
20
|
+
"test:manual": "bun run test/manual/integration.ts"
|
|
20
21
|
},
|
|
21
22
|
"dependencies": {
|
|
22
23
|
"eventsource-parser": "^3.0.0"
|