bashkit 0.2.1 → 0.2.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/dist/index.js +24 -6
- package/dist/sandbox/e2b.d.ts +2 -0
- package/dist/sandbox/interface.d.ts +7 -0
- package/dist/sandbox/vercel.d.ts +2 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -53,16 +53,22 @@ var anthropicPromptCacheMiddleware = {
|
|
|
53
53
|
import { Sandbox as E2BSandboxSDK } from "@e2b/code-interpreter";
|
|
54
54
|
function createE2BSandbox(config = {}) {
|
|
55
55
|
let sandbox = null;
|
|
56
|
+
let sandboxId = config.sandboxId;
|
|
56
57
|
const workingDirectory = config.cwd || "/home/user";
|
|
57
58
|
const timeout = config.timeout ?? 300000;
|
|
58
59
|
const ensureSandbox = async () => {
|
|
59
60
|
if (sandbox)
|
|
60
61
|
return sandbox;
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
62
|
+
if (config.sandboxId) {
|
|
63
|
+
sandbox = await E2BSandboxSDK.connect(config.sandboxId);
|
|
64
|
+
} else {
|
|
65
|
+
sandbox = await E2BSandboxSDK.create({
|
|
66
|
+
apiKey: config.apiKey,
|
|
67
|
+
timeoutMs: timeout,
|
|
68
|
+
metadata: config.metadata
|
|
69
|
+
});
|
|
70
|
+
sandboxId = sandbox.sandboxId;
|
|
71
|
+
}
|
|
66
72
|
return sandbox;
|
|
67
73
|
};
|
|
68
74
|
const exec = async (command, options) => {
|
|
@@ -108,6 +114,9 @@ function createE2BSandbox(config = {}) {
|
|
|
108
114
|
};
|
|
109
115
|
return {
|
|
110
116
|
exec,
|
|
117
|
+
get id() {
|
|
118
|
+
return sandboxId;
|
|
119
|
+
},
|
|
111
120
|
async readFile(path) {
|
|
112
121
|
const result = await exec(`cat "${path}"`);
|
|
113
122
|
if (result.exitCode !== 0) {
|
|
@@ -227,6 +236,7 @@ function createLocalSandbox(config = {}) {
|
|
|
227
236
|
import { Sandbox as VercelSandboxSDK } from "@vercel/sandbox";
|
|
228
237
|
function createVercelSandbox(config = {}) {
|
|
229
238
|
let sandbox = null;
|
|
239
|
+
let sandboxId = config.sandboxId;
|
|
230
240
|
const workingDirectory = config.cwd || "/vercel/sandbox";
|
|
231
241
|
const resolvedConfig = {
|
|
232
242
|
runtime: config.runtime ?? "node22",
|
|
@@ -247,7 +257,12 @@ function createVercelSandbox(config = {}) {
|
|
|
247
257
|
token: config.token
|
|
248
258
|
});
|
|
249
259
|
}
|
|
250
|
-
|
|
260
|
+
if (config.sandboxId) {
|
|
261
|
+
sandbox = await VercelSandboxSDK.get({ sandboxId: config.sandboxId });
|
|
262
|
+
} else {
|
|
263
|
+
sandbox = await VercelSandboxSDK.create(createOptions);
|
|
264
|
+
}
|
|
265
|
+
sandboxId = sandbox.sandboxId;
|
|
251
266
|
return sandbox;
|
|
252
267
|
};
|
|
253
268
|
const exec = async (command, options) => {
|
|
@@ -301,6 +316,9 @@ function createVercelSandbox(config = {}) {
|
|
|
301
316
|
};
|
|
302
317
|
return {
|
|
303
318
|
exec,
|
|
319
|
+
get id() {
|
|
320
|
+
return sandboxId;
|
|
321
|
+
},
|
|
304
322
|
async readFile(path) {
|
|
305
323
|
const sbx = await ensureSandbox();
|
|
306
324
|
const stream = await sbx.readFile({ path });
|
package/dist/sandbox/e2b.d.ts
CHANGED
|
@@ -18,4 +18,11 @@ export interface Sandbox {
|
|
|
18
18
|
fileExists(path: string): Promise<boolean>;
|
|
19
19
|
isDirectory(path: string): Promise<boolean>;
|
|
20
20
|
destroy(): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Sandbox ID for reconnection (cloud providers only).
|
|
23
|
+
* - For new sandboxes: available after first operation
|
|
24
|
+
* - For reconnected sandboxes: available immediately
|
|
25
|
+
* - For local sandboxes: always undefined
|
|
26
|
+
*/
|
|
27
|
+
readonly id?: string;
|
|
21
28
|
}
|
package/dist/sandbox/vercel.d.ts
CHANGED