computesdk 1.6.0 → 1.7.1
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 +46 -6
- package/dist/index.d.mts +128 -27
- package/dist/index.d.ts +128 -27
- package/dist/index.js +128 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +128 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -19,10 +19,10 @@
|
|
|
19
19
|
|
|
20
20
|
## What is ComputeSDK?
|
|
21
21
|
|
|
22
|
-
ComputeSDK is a free and open-source toolkit for running other people's code in your applications. Think of it as the "AI SDK for compute" - providing a consistent TypeScript interface whether you're using E2B, Vercel, or Daytona.
|
|
22
|
+
ComputeSDK is a free and open-source toolkit for running other people's code in your applications. Think of it as the "AI SDK for compute" - providing a consistent TypeScript interface whether you're using Blaxel, E2B, Vercel, or Daytona.
|
|
23
23
|
|
|
24
24
|
**Why ComputeSDK?**
|
|
25
|
-
- 🔄 **Provider-agnostic** - Switch between E2B, Vercel, Daytona and more (coming soon) without code changes
|
|
25
|
+
- 🔄 **Provider-agnostic** - Switch between Blaxel, E2B, Vercel, Daytona and more (coming soon) without code changes
|
|
26
26
|
- 🛡️ **Security-first** - Isolated sandboxes protect your infrastructure
|
|
27
27
|
- ⚡ **Developer experience** - Simple, TypeScript-native API
|
|
28
28
|
- 🌍 **Production-ready** - Used by teams building the next generation of developer tools
|
|
@@ -36,7 +36,7 @@ ComputeSDK is a free and open-source toolkit for running other people's code in
|
|
|
36
36
|
|
|
37
37
|
## Features
|
|
38
38
|
|
|
39
|
-
- 🚀 **Multi-provider support** - E2B, Vercel, Daytona
|
|
39
|
+
- 🚀 **Multi-provider support** - Blaxel, E2B, Vercel, Daytona
|
|
40
40
|
- 📁 **Filesystem operations** - Read, write, create directories across providers
|
|
41
41
|
- 🖥️ **Terminal support** - Interactive PTY terminals (E2B)
|
|
42
42
|
- ⚡ **Command execution** - Run shell commands directly
|
|
@@ -53,6 +53,7 @@ ComputeSDK is a free and open-source toolkit for running other people's code in
|
|
|
53
53
|
npm install computesdk
|
|
54
54
|
|
|
55
55
|
# Add your preferred provider
|
|
56
|
+
npm install @computesdk/blaxel # For AI-powered code execution
|
|
56
57
|
npm install @computesdk/e2b # For data science and Python
|
|
57
58
|
npm install @computesdk/vercel # For web-scale Node.js/Python
|
|
58
59
|
npm install @computesdk/daytona # For development workspaces
|
|
@@ -64,7 +65,9 @@ npm install @computesdk/ui # React hooks and utilities
|
|
|
64
65
|
Set your environment variables and you're ready to go:
|
|
65
66
|
|
|
66
67
|
```bash
|
|
67
|
-
export
|
|
68
|
+
export BLAXEL_API_KEY=your_api_key
|
|
69
|
+
export BLAXEL_WORKSPACE=your_workspace
|
|
70
|
+
# or E2B_API_KEY=your_api_key
|
|
68
71
|
# or VERCEL_TOKEN=your_token
|
|
69
72
|
# or DAYTONA_API_KEY=your_key
|
|
70
73
|
```
|
|
@@ -73,11 +76,14 @@ export E2B_API_KEY=your_api_key
|
|
|
73
76
|
|
|
74
77
|
```typescript
|
|
75
78
|
import { compute } from 'computesdk';
|
|
76
|
-
import {
|
|
79
|
+
import { blaxel } from '@computesdk/blaxel';
|
|
77
80
|
|
|
78
81
|
// Set default provider
|
|
79
82
|
compute.setConfig({
|
|
80
|
-
provider:
|
|
83
|
+
provider: blaxel({
|
|
84
|
+
apiKey: process.env.BLAXEL_API_KEY,
|
|
85
|
+
workspace: process.env.BLAXEL_WORKSPACE
|
|
86
|
+
})
|
|
81
87
|
});
|
|
82
88
|
|
|
83
89
|
// Create a sandbox
|
|
@@ -93,6 +99,40 @@ await compute.sandbox.destroy(sandbox.sandboxId);
|
|
|
93
99
|
|
|
94
100
|
## Provider Setup
|
|
95
101
|
|
|
102
|
+
### Blaxel - AI-Powered Code Execution
|
|
103
|
+
|
|
104
|
+
Blaxel provides intelligent code execution with AI assistance:
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
export BLAXEL_API_KEY=your_blaxel_api_key_here
|
|
108
|
+
export BLAXEL_WORKSPACE=your_workspace_here
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
import { compute } from 'computesdk';
|
|
113
|
+
import { blaxel } from '@computesdk/blaxel';
|
|
114
|
+
|
|
115
|
+
compute.setConfig({
|
|
116
|
+
provider: blaxel({
|
|
117
|
+
apiKey: process.env.BLAXEL_API_KEY,
|
|
118
|
+
workspace: process.env.BLAXEL_WORKSPACE
|
|
119
|
+
})
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
const sandbox = await compute.sandbox.create({});
|
|
123
|
+
|
|
124
|
+
// Execute code with AI assistance
|
|
125
|
+
const result = await sandbox.runCode(`
|
|
126
|
+
print("Hello from Blaxel!")
|
|
127
|
+
# Your code can leverage AI capabilities
|
|
128
|
+
import json
|
|
129
|
+
data = {"message": "AI-powered execution"}
|
|
130
|
+
print(json.dumps(data, indent=2))
|
|
131
|
+
`);
|
|
132
|
+
|
|
133
|
+
console.log(result.stdout);
|
|
134
|
+
```
|
|
135
|
+
|
|
96
136
|
### E2B - Full Development Environment
|
|
97
137
|
|
|
98
138
|
E2B provides full filesystem and terminal support:
|
package/dist/index.d.mts
CHANGED
|
@@ -7,17 +7,26 @@ interface Provider$1 {
|
|
|
7
7
|
readonly name: string;
|
|
8
8
|
readonly sandbox: any;
|
|
9
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* Type mapping for provider names to their sandbox types
|
|
12
|
+
* Manually defined for known providers since declaration merging isn't working reliably
|
|
13
|
+
*/
|
|
14
|
+
interface ProviderSandboxTypeMap {
|
|
15
|
+
e2b: any;
|
|
16
|
+
vercel: any;
|
|
17
|
+
daytona: any;
|
|
18
|
+
}
|
|
10
19
|
/**
|
|
11
20
|
* Utility type to extract the native instance type from a provider
|
|
12
|
-
*
|
|
21
|
+
* Uses provider name and manual type inference
|
|
13
22
|
*/
|
|
14
|
-
type ExtractSandboxInstanceType<TProvider extends Provider$1> = TProvider extends
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
} ?
|
|
19
|
-
|
|
20
|
-
} ?
|
|
23
|
+
type ExtractSandboxInstanceType<TProvider extends Provider$1> = TProvider extends {
|
|
24
|
+
readonly name: 'e2b';
|
|
25
|
+
} ? any : TProvider extends {
|
|
26
|
+
readonly name: 'vercel';
|
|
27
|
+
} ? any : TProvider extends {
|
|
28
|
+
readonly name: 'daytona';
|
|
29
|
+
} ? any : any;
|
|
21
30
|
/**
|
|
22
31
|
* Supported runtime environments
|
|
23
32
|
*/
|
|
@@ -77,7 +86,7 @@ interface SandboxInfo {
|
|
|
77
86
|
* Options for creating a sandbox
|
|
78
87
|
*/
|
|
79
88
|
interface CreateSandboxOptions {
|
|
80
|
-
/** Runtime environment */
|
|
89
|
+
/** Runtime environment (defaults to 'node' if not specified) */
|
|
81
90
|
runtime?: Runtime;
|
|
82
91
|
/** Execution timeout in milliseconds */
|
|
83
92
|
timeout?: number;
|
|
@@ -149,7 +158,7 @@ declare function isCommandExitError(error: unknown): error is CommandExitError;
|
|
|
149
158
|
/**
|
|
150
159
|
* Base sandbox interface - what developers interact with
|
|
151
160
|
*/
|
|
152
|
-
interface Sandbox {
|
|
161
|
+
interface Sandbox<TSandbox = any> {
|
|
153
162
|
/** Unique identifier for the sandbox */
|
|
154
163
|
readonly sandboxId: string;
|
|
155
164
|
/** Provider that created this sandbox */
|
|
@@ -166,9 +175,9 @@ interface Sandbox {
|
|
|
166
175
|
protocol?: string;
|
|
167
176
|
}): Promise<string>;
|
|
168
177
|
/** Get the provider instance that created this sandbox */
|
|
169
|
-
getProvider(): Provider
|
|
178
|
+
getProvider(): Provider<TSandbox>;
|
|
170
179
|
/** Get the native provider sandbox instance with proper typing */
|
|
171
|
-
getInstance
|
|
180
|
+
getInstance(): TSandbox;
|
|
172
181
|
/** Kill the sandbox */
|
|
173
182
|
kill(): Promise<void>;
|
|
174
183
|
/** Destroy the sandbox and clean up resources */
|
|
@@ -176,38 +185,109 @@ interface Sandbox {
|
|
|
176
185
|
/** File system operations */
|
|
177
186
|
readonly filesystem: SandboxFileSystem;
|
|
178
187
|
}
|
|
188
|
+
/**
|
|
189
|
+
* Extract the sandbox type from a provider
|
|
190
|
+
*/
|
|
191
|
+
type ExtractProviderSandboxType<TProvider extends Provider$1> = TProvider extends {
|
|
192
|
+
readonly __sandboxType: infer TSandbox;
|
|
193
|
+
} ? TSandbox : any;
|
|
179
194
|
/**
|
|
180
195
|
* Typed sandbox interface that preserves the provider's native instance type
|
|
181
196
|
*/
|
|
182
|
-
interface TypedSandbox<TProvider extends Provider$1> extends Sandbox {
|
|
197
|
+
interface TypedSandbox<TProvider extends Provider$1> extends Omit<Sandbox<ExtractProviderSandboxType<TProvider>>, 'getProvider'> {
|
|
183
198
|
/** Get the provider instance that created this sandbox with proper typing */
|
|
184
199
|
getProvider(): TProvider;
|
|
185
200
|
/** Get the native provider sandbox instance with proper typing */
|
|
186
|
-
getInstance():
|
|
187
|
-
getInstance<T>(): T;
|
|
201
|
+
getInstance(): ExtractProviderSandboxType<TProvider>;
|
|
188
202
|
}
|
|
189
203
|
|
|
190
204
|
/**
|
|
191
|
-
*
|
|
205
|
+
* Common options for creating snapshots
|
|
192
206
|
*/
|
|
193
|
-
interface
|
|
207
|
+
interface CreateSnapshotOptions {
|
|
208
|
+
/** Optional name for the snapshot */
|
|
209
|
+
name?: string;
|
|
210
|
+
/** Optional metadata for the snapshot */
|
|
211
|
+
metadata?: Record<string, string>;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Common options for listing snapshots
|
|
215
|
+
*/
|
|
216
|
+
interface ListSnapshotsOptions {
|
|
217
|
+
/** Filter by sandbox ID */
|
|
218
|
+
sandboxId?: string;
|
|
219
|
+
/** Limit the number of results */
|
|
220
|
+
limit?: number;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Common options for creating templates/blueprints
|
|
224
|
+
*/
|
|
225
|
+
interface CreateTemplateOptions {
|
|
226
|
+
/** Name of the template */
|
|
227
|
+
name: string;
|
|
228
|
+
/** Optional description */
|
|
229
|
+
description?: string;
|
|
230
|
+
/** Optional metadata for the template */
|
|
231
|
+
metadata?: Record<string, string>;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Common options for listing templates
|
|
235
|
+
*/
|
|
236
|
+
interface ListTemplatesOptions {
|
|
237
|
+
/** Limit the number of results */
|
|
238
|
+
limit?: number;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Provider sandbox manager interface - handles sandbox lifecycle
|
|
242
|
+
*/
|
|
243
|
+
interface ProviderSandboxManager<TSandbox = any> {
|
|
194
244
|
/** Create a new sandbox */
|
|
195
|
-
create(options?: CreateSandboxOptions): Promise<Sandbox
|
|
245
|
+
create(options?: CreateSandboxOptions): Promise<Sandbox<TSandbox>>;
|
|
196
246
|
/** Get an existing sandbox by ID */
|
|
197
|
-
getById(sandboxId: string): Promise<Sandbox | null>;
|
|
247
|
+
getById(sandboxId: string): Promise<Sandbox<TSandbox> | null>;
|
|
198
248
|
/** List all active sandboxes */
|
|
199
|
-
list(): Promise<Sandbox[]>;
|
|
249
|
+
list(): Promise<Sandbox<TSandbox>[]>;
|
|
200
250
|
/** Destroy a sandbox */
|
|
201
251
|
destroy(sandboxId: string): Promise<void>;
|
|
202
252
|
}
|
|
253
|
+
/**
|
|
254
|
+
* Provider template manager interface - handles template/blueprint lifecycle
|
|
255
|
+
*/
|
|
256
|
+
interface ProviderTemplateManager<TTemplate = any> {
|
|
257
|
+
/** Create a new template */
|
|
258
|
+
create(options: CreateTemplateOptions | any): Promise<TTemplate>;
|
|
259
|
+
/** List all available templates */
|
|
260
|
+
list(options?: ListTemplatesOptions): Promise<TTemplate[]>;
|
|
261
|
+
/** Delete a template */
|
|
262
|
+
delete(templateId: string): Promise<void>;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Provider snapshot manager interface - handles snapshot lifecycle
|
|
266
|
+
*/
|
|
267
|
+
interface ProviderSnapshotManager<TSnapshot = any> {
|
|
268
|
+
/** Create a snapshot from a sandbox */
|
|
269
|
+
create(sandboxId: string, options?: CreateSnapshotOptions): Promise<TSnapshot>;
|
|
270
|
+
/** List all snapshots */
|
|
271
|
+
list(options?: ListSnapshotsOptions): Promise<TSnapshot[]>;
|
|
272
|
+
/** Delete a snapshot */
|
|
273
|
+
delete(snapshotId: string): Promise<void>;
|
|
274
|
+
}
|
|
203
275
|
/**
|
|
204
276
|
* Provider interface - creates and manages resources
|
|
205
277
|
*/
|
|
206
|
-
interface Provider {
|
|
278
|
+
interface Provider<TSandbox = any, TTemplate = any, TSnapshot = any> {
|
|
207
279
|
/** Provider name/type */
|
|
208
280
|
readonly name: string;
|
|
209
281
|
/** Sandbox management operations */
|
|
210
|
-
readonly sandbox: ProviderSandboxManager
|
|
282
|
+
readonly sandbox: ProviderSandboxManager<TSandbox>;
|
|
283
|
+
/** Optional template management operations */
|
|
284
|
+
readonly template?: ProviderTemplateManager<TTemplate>;
|
|
285
|
+
/** Optional snapshot management operations */
|
|
286
|
+
readonly snapshot?: ProviderSnapshotManager<TSnapshot>;
|
|
287
|
+
/** Get the list of supported runtime environments */
|
|
288
|
+
getSupportedRuntimes(): Runtime[];
|
|
289
|
+
/** Phantom type property for TypeScript inference - not used at runtime */
|
|
290
|
+
readonly __sandboxType: TSandbox;
|
|
211
291
|
}
|
|
212
292
|
/**
|
|
213
293
|
* Configuration for the compute singleton
|
|
@@ -217,6 +297,10 @@ interface ComputeConfig<TProvider extends Provider = Provider> {
|
|
|
217
297
|
defaultProvider?: TProvider;
|
|
218
298
|
/** @deprecated Use defaultProvider instead. Kept for backwards compatibility */
|
|
219
299
|
provider?: TProvider;
|
|
300
|
+
/** API key for compute CLI authentication */
|
|
301
|
+
apiKey?: string;
|
|
302
|
+
/** JWT token for compute CLI authentication */
|
|
303
|
+
jwt?: string;
|
|
220
304
|
}
|
|
221
305
|
/**
|
|
222
306
|
* Parameters for compute.sandbox.create()
|
|
@@ -285,7 +369,6 @@ interface TypedComputeAPI<TProvider extends Provider> extends Omit<ComputeAPI, '
|
|
|
285
369
|
declare const compute: ComputeAPI;
|
|
286
370
|
/**
|
|
287
371
|
* Create a compute instance with proper typing
|
|
288
|
-
* This enables proper type inference for getInstance() calls
|
|
289
372
|
*
|
|
290
373
|
* @example
|
|
291
374
|
* ```typescript
|
|
@@ -297,7 +380,7 @@ declare const compute: ComputeAPI;
|
|
|
297
380
|
* });
|
|
298
381
|
*
|
|
299
382
|
* const sandbox = await compute.sandbox.create();
|
|
300
|
-
* const instance = sandbox.getInstance(); // ✅ Properly typed!
|
|
383
|
+
* const instance = sandbox.getInstance(); // ✅ Properly typed E2B Sandbox!
|
|
301
384
|
* ```
|
|
302
385
|
*/
|
|
303
386
|
declare function createCompute<TProvider extends Provider>(config: ComputeConfig<TProvider>): TypedComputeAPI<TProvider>;
|
|
@@ -407,13 +490,31 @@ interface SandboxMethods<TSandbox = any, TConfig = any> {
|
|
|
407
490
|
remove: (sandbox: TSandbox, path: string, runCommand: (sandbox: TSandbox, command: string, args?: string[]) => Promise<ExecutionResult>) => Promise<void>;
|
|
408
491
|
};
|
|
409
492
|
}
|
|
493
|
+
/**
|
|
494
|
+
* Template method implementations
|
|
495
|
+
*/
|
|
496
|
+
interface TemplateMethods<TTemplate = any, TConfig = any> {
|
|
497
|
+
create: (config: TConfig, options: CreateTemplateOptions | any) => Promise<TTemplate>;
|
|
498
|
+
list: (config: TConfig, options?: ListTemplatesOptions) => Promise<TTemplate[]>;
|
|
499
|
+
delete: (config: TConfig, templateId: string) => Promise<void>;
|
|
500
|
+
}
|
|
501
|
+
/**
|
|
502
|
+
* Snapshot method implementations
|
|
503
|
+
*/
|
|
504
|
+
interface SnapshotMethods<TSnapshot = any, TConfig = any> {
|
|
505
|
+
create: (config: TConfig, sandboxId: string, options?: CreateSnapshotOptions) => Promise<TSnapshot>;
|
|
506
|
+
list: (config: TConfig, options?: ListSnapshotsOptions) => Promise<TSnapshot[]>;
|
|
507
|
+
delete: (config: TConfig, snapshotId: string) => Promise<void>;
|
|
508
|
+
}
|
|
410
509
|
/**
|
|
411
510
|
* Provider configuration for createProvider()
|
|
412
511
|
*/
|
|
413
|
-
interface ProviderConfig<TSandbox = any, TConfig = any> {
|
|
512
|
+
interface ProviderConfig<TSandbox = any, TConfig = any, TTemplate = any, TSnapshot = any> {
|
|
414
513
|
name: string;
|
|
415
514
|
methods: {
|
|
416
515
|
sandbox: SandboxMethods<TSandbox, TConfig>;
|
|
516
|
+
template?: TemplateMethods<TTemplate, TConfig>;
|
|
517
|
+
snapshot?: SnapshotMethods<TSnapshot, TConfig>;
|
|
417
518
|
};
|
|
418
519
|
}
|
|
419
520
|
/**
|
|
@@ -422,6 +523,6 @@ interface ProviderConfig<TSandbox = any, TConfig = any> {
|
|
|
422
523
|
* Auto-generates all boilerplate classes and provides feature detection
|
|
423
524
|
* based on which methods are implemented.
|
|
424
525
|
*/
|
|
425
|
-
declare function createProvider<TSandbox, TConfig>(providerConfig: ProviderConfig<TSandbox, TConfig>): (config: TConfig) => Provider
|
|
526
|
+
declare function createProvider<TSandbox, TConfig = any, TTemplate = any, TSnapshot = any>(providerConfig: ProviderConfig<TSandbox, TConfig, TTemplate, TSnapshot>): (config: TConfig) => Provider<TSandbox, TTemplate, TSnapshot>;
|
|
426
527
|
|
|
427
|
-
export { CommandExitError, type ComputeAPI, type ComputeConfig, type ComputeRequest, type ComputeResponse, type CreateSandboxOptions, type CreateSandboxParams, type CreateSandboxParamsWithOptionalProvider, type ExecutionResult, type ExtractSandboxInstanceType, type FileEntry, type HandleComputeRequestParams, type Provider, type ProviderConfig, type ProviderSandboxManager, type RunCommandOptions, type Runtime, type Sandbox, type SandboxFileSystem, type SandboxInfo, type SandboxMethods, type SandboxStatus, type TypedComputeAPI, type TypedSandbox, compute, createBackgroundCommand, createCompute, createProvider, handleComputeRequest, isCommandExitError };
|
|
528
|
+
export { CommandExitError, type ComputeAPI, type ComputeConfig, type ComputeRequest, type ComputeResponse, type CreateSandboxOptions, type CreateSandboxParams, type CreateSandboxParamsWithOptionalProvider, type CreateSnapshotOptions, type CreateTemplateOptions, type ExecutionResult, type ExtractSandboxInstanceType, type FileEntry, type HandleComputeRequestParams, type ListSnapshotsOptions, type ListTemplatesOptions, type Provider, type ProviderConfig, type ProviderSandboxManager, type ProviderSandboxTypeMap, type ProviderSnapshotManager, type ProviderTemplateManager, type RunCommandOptions, type Runtime, type Sandbox, type SandboxFileSystem, type SandboxInfo, type SandboxMethods, type SandboxStatus, type SnapshotMethods, type TemplateMethods, type TypedComputeAPI, type TypedSandbox, compute, createBackgroundCommand, createCompute, createProvider, handleComputeRequest, isCommandExitError };
|
package/dist/index.d.ts
CHANGED
|
@@ -7,17 +7,26 @@ interface Provider$1 {
|
|
|
7
7
|
readonly name: string;
|
|
8
8
|
readonly sandbox: any;
|
|
9
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* Type mapping for provider names to their sandbox types
|
|
12
|
+
* Manually defined for known providers since declaration merging isn't working reliably
|
|
13
|
+
*/
|
|
14
|
+
interface ProviderSandboxTypeMap {
|
|
15
|
+
e2b: any;
|
|
16
|
+
vercel: any;
|
|
17
|
+
daytona: any;
|
|
18
|
+
}
|
|
10
19
|
/**
|
|
11
20
|
* Utility type to extract the native instance type from a provider
|
|
12
|
-
*
|
|
21
|
+
* Uses provider name and manual type inference
|
|
13
22
|
*/
|
|
14
|
-
type ExtractSandboxInstanceType<TProvider extends Provider$1> = TProvider extends
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
} ?
|
|
19
|
-
|
|
20
|
-
} ?
|
|
23
|
+
type ExtractSandboxInstanceType<TProvider extends Provider$1> = TProvider extends {
|
|
24
|
+
readonly name: 'e2b';
|
|
25
|
+
} ? any : TProvider extends {
|
|
26
|
+
readonly name: 'vercel';
|
|
27
|
+
} ? any : TProvider extends {
|
|
28
|
+
readonly name: 'daytona';
|
|
29
|
+
} ? any : any;
|
|
21
30
|
/**
|
|
22
31
|
* Supported runtime environments
|
|
23
32
|
*/
|
|
@@ -77,7 +86,7 @@ interface SandboxInfo {
|
|
|
77
86
|
* Options for creating a sandbox
|
|
78
87
|
*/
|
|
79
88
|
interface CreateSandboxOptions {
|
|
80
|
-
/** Runtime environment */
|
|
89
|
+
/** Runtime environment (defaults to 'node' if not specified) */
|
|
81
90
|
runtime?: Runtime;
|
|
82
91
|
/** Execution timeout in milliseconds */
|
|
83
92
|
timeout?: number;
|
|
@@ -149,7 +158,7 @@ declare function isCommandExitError(error: unknown): error is CommandExitError;
|
|
|
149
158
|
/**
|
|
150
159
|
* Base sandbox interface - what developers interact with
|
|
151
160
|
*/
|
|
152
|
-
interface Sandbox {
|
|
161
|
+
interface Sandbox<TSandbox = any> {
|
|
153
162
|
/** Unique identifier for the sandbox */
|
|
154
163
|
readonly sandboxId: string;
|
|
155
164
|
/** Provider that created this sandbox */
|
|
@@ -166,9 +175,9 @@ interface Sandbox {
|
|
|
166
175
|
protocol?: string;
|
|
167
176
|
}): Promise<string>;
|
|
168
177
|
/** Get the provider instance that created this sandbox */
|
|
169
|
-
getProvider(): Provider
|
|
178
|
+
getProvider(): Provider<TSandbox>;
|
|
170
179
|
/** Get the native provider sandbox instance with proper typing */
|
|
171
|
-
getInstance
|
|
180
|
+
getInstance(): TSandbox;
|
|
172
181
|
/** Kill the sandbox */
|
|
173
182
|
kill(): Promise<void>;
|
|
174
183
|
/** Destroy the sandbox and clean up resources */
|
|
@@ -176,38 +185,109 @@ interface Sandbox {
|
|
|
176
185
|
/** File system operations */
|
|
177
186
|
readonly filesystem: SandboxFileSystem;
|
|
178
187
|
}
|
|
188
|
+
/**
|
|
189
|
+
* Extract the sandbox type from a provider
|
|
190
|
+
*/
|
|
191
|
+
type ExtractProviderSandboxType<TProvider extends Provider$1> = TProvider extends {
|
|
192
|
+
readonly __sandboxType: infer TSandbox;
|
|
193
|
+
} ? TSandbox : any;
|
|
179
194
|
/**
|
|
180
195
|
* Typed sandbox interface that preserves the provider's native instance type
|
|
181
196
|
*/
|
|
182
|
-
interface TypedSandbox<TProvider extends Provider$1> extends Sandbox {
|
|
197
|
+
interface TypedSandbox<TProvider extends Provider$1> extends Omit<Sandbox<ExtractProviderSandboxType<TProvider>>, 'getProvider'> {
|
|
183
198
|
/** Get the provider instance that created this sandbox with proper typing */
|
|
184
199
|
getProvider(): TProvider;
|
|
185
200
|
/** Get the native provider sandbox instance with proper typing */
|
|
186
|
-
getInstance():
|
|
187
|
-
getInstance<T>(): T;
|
|
201
|
+
getInstance(): ExtractProviderSandboxType<TProvider>;
|
|
188
202
|
}
|
|
189
203
|
|
|
190
204
|
/**
|
|
191
|
-
*
|
|
205
|
+
* Common options for creating snapshots
|
|
192
206
|
*/
|
|
193
|
-
interface
|
|
207
|
+
interface CreateSnapshotOptions {
|
|
208
|
+
/** Optional name for the snapshot */
|
|
209
|
+
name?: string;
|
|
210
|
+
/** Optional metadata for the snapshot */
|
|
211
|
+
metadata?: Record<string, string>;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Common options for listing snapshots
|
|
215
|
+
*/
|
|
216
|
+
interface ListSnapshotsOptions {
|
|
217
|
+
/** Filter by sandbox ID */
|
|
218
|
+
sandboxId?: string;
|
|
219
|
+
/** Limit the number of results */
|
|
220
|
+
limit?: number;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Common options for creating templates/blueprints
|
|
224
|
+
*/
|
|
225
|
+
interface CreateTemplateOptions {
|
|
226
|
+
/** Name of the template */
|
|
227
|
+
name: string;
|
|
228
|
+
/** Optional description */
|
|
229
|
+
description?: string;
|
|
230
|
+
/** Optional metadata for the template */
|
|
231
|
+
metadata?: Record<string, string>;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Common options for listing templates
|
|
235
|
+
*/
|
|
236
|
+
interface ListTemplatesOptions {
|
|
237
|
+
/** Limit the number of results */
|
|
238
|
+
limit?: number;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Provider sandbox manager interface - handles sandbox lifecycle
|
|
242
|
+
*/
|
|
243
|
+
interface ProviderSandboxManager<TSandbox = any> {
|
|
194
244
|
/** Create a new sandbox */
|
|
195
|
-
create(options?: CreateSandboxOptions): Promise<Sandbox
|
|
245
|
+
create(options?: CreateSandboxOptions): Promise<Sandbox<TSandbox>>;
|
|
196
246
|
/** Get an existing sandbox by ID */
|
|
197
|
-
getById(sandboxId: string): Promise<Sandbox | null>;
|
|
247
|
+
getById(sandboxId: string): Promise<Sandbox<TSandbox> | null>;
|
|
198
248
|
/** List all active sandboxes */
|
|
199
|
-
list(): Promise<Sandbox[]>;
|
|
249
|
+
list(): Promise<Sandbox<TSandbox>[]>;
|
|
200
250
|
/** Destroy a sandbox */
|
|
201
251
|
destroy(sandboxId: string): Promise<void>;
|
|
202
252
|
}
|
|
253
|
+
/**
|
|
254
|
+
* Provider template manager interface - handles template/blueprint lifecycle
|
|
255
|
+
*/
|
|
256
|
+
interface ProviderTemplateManager<TTemplate = any> {
|
|
257
|
+
/** Create a new template */
|
|
258
|
+
create(options: CreateTemplateOptions | any): Promise<TTemplate>;
|
|
259
|
+
/** List all available templates */
|
|
260
|
+
list(options?: ListTemplatesOptions): Promise<TTemplate[]>;
|
|
261
|
+
/** Delete a template */
|
|
262
|
+
delete(templateId: string): Promise<void>;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Provider snapshot manager interface - handles snapshot lifecycle
|
|
266
|
+
*/
|
|
267
|
+
interface ProviderSnapshotManager<TSnapshot = any> {
|
|
268
|
+
/** Create a snapshot from a sandbox */
|
|
269
|
+
create(sandboxId: string, options?: CreateSnapshotOptions): Promise<TSnapshot>;
|
|
270
|
+
/** List all snapshots */
|
|
271
|
+
list(options?: ListSnapshotsOptions): Promise<TSnapshot[]>;
|
|
272
|
+
/** Delete a snapshot */
|
|
273
|
+
delete(snapshotId: string): Promise<void>;
|
|
274
|
+
}
|
|
203
275
|
/**
|
|
204
276
|
* Provider interface - creates and manages resources
|
|
205
277
|
*/
|
|
206
|
-
interface Provider {
|
|
278
|
+
interface Provider<TSandbox = any, TTemplate = any, TSnapshot = any> {
|
|
207
279
|
/** Provider name/type */
|
|
208
280
|
readonly name: string;
|
|
209
281
|
/** Sandbox management operations */
|
|
210
|
-
readonly sandbox: ProviderSandboxManager
|
|
282
|
+
readonly sandbox: ProviderSandboxManager<TSandbox>;
|
|
283
|
+
/** Optional template management operations */
|
|
284
|
+
readonly template?: ProviderTemplateManager<TTemplate>;
|
|
285
|
+
/** Optional snapshot management operations */
|
|
286
|
+
readonly snapshot?: ProviderSnapshotManager<TSnapshot>;
|
|
287
|
+
/** Get the list of supported runtime environments */
|
|
288
|
+
getSupportedRuntimes(): Runtime[];
|
|
289
|
+
/** Phantom type property for TypeScript inference - not used at runtime */
|
|
290
|
+
readonly __sandboxType: TSandbox;
|
|
211
291
|
}
|
|
212
292
|
/**
|
|
213
293
|
* Configuration for the compute singleton
|
|
@@ -217,6 +297,10 @@ interface ComputeConfig<TProvider extends Provider = Provider> {
|
|
|
217
297
|
defaultProvider?: TProvider;
|
|
218
298
|
/** @deprecated Use defaultProvider instead. Kept for backwards compatibility */
|
|
219
299
|
provider?: TProvider;
|
|
300
|
+
/** API key for compute CLI authentication */
|
|
301
|
+
apiKey?: string;
|
|
302
|
+
/** JWT token for compute CLI authentication */
|
|
303
|
+
jwt?: string;
|
|
220
304
|
}
|
|
221
305
|
/**
|
|
222
306
|
* Parameters for compute.sandbox.create()
|
|
@@ -285,7 +369,6 @@ interface TypedComputeAPI<TProvider extends Provider> extends Omit<ComputeAPI, '
|
|
|
285
369
|
declare const compute: ComputeAPI;
|
|
286
370
|
/**
|
|
287
371
|
* Create a compute instance with proper typing
|
|
288
|
-
* This enables proper type inference for getInstance() calls
|
|
289
372
|
*
|
|
290
373
|
* @example
|
|
291
374
|
* ```typescript
|
|
@@ -297,7 +380,7 @@ declare const compute: ComputeAPI;
|
|
|
297
380
|
* });
|
|
298
381
|
*
|
|
299
382
|
* const sandbox = await compute.sandbox.create();
|
|
300
|
-
* const instance = sandbox.getInstance(); // ✅ Properly typed!
|
|
383
|
+
* const instance = sandbox.getInstance(); // ✅ Properly typed E2B Sandbox!
|
|
301
384
|
* ```
|
|
302
385
|
*/
|
|
303
386
|
declare function createCompute<TProvider extends Provider>(config: ComputeConfig<TProvider>): TypedComputeAPI<TProvider>;
|
|
@@ -407,13 +490,31 @@ interface SandboxMethods<TSandbox = any, TConfig = any> {
|
|
|
407
490
|
remove: (sandbox: TSandbox, path: string, runCommand: (sandbox: TSandbox, command: string, args?: string[]) => Promise<ExecutionResult>) => Promise<void>;
|
|
408
491
|
};
|
|
409
492
|
}
|
|
493
|
+
/**
|
|
494
|
+
* Template method implementations
|
|
495
|
+
*/
|
|
496
|
+
interface TemplateMethods<TTemplate = any, TConfig = any> {
|
|
497
|
+
create: (config: TConfig, options: CreateTemplateOptions | any) => Promise<TTemplate>;
|
|
498
|
+
list: (config: TConfig, options?: ListTemplatesOptions) => Promise<TTemplate[]>;
|
|
499
|
+
delete: (config: TConfig, templateId: string) => Promise<void>;
|
|
500
|
+
}
|
|
501
|
+
/**
|
|
502
|
+
* Snapshot method implementations
|
|
503
|
+
*/
|
|
504
|
+
interface SnapshotMethods<TSnapshot = any, TConfig = any> {
|
|
505
|
+
create: (config: TConfig, sandboxId: string, options?: CreateSnapshotOptions) => Promise<TSnapshot>;
|
|
506
|
+
list: (config: TConfig, options?: ListSnapshotsOptions) => Promise<TSnapshot[]>;
|
|
507
|
+
delete: (config: TConfig, snapshotId: string) => Promise<void>;
|
|
508
|
+
}
|
|
410
509
|
/**
|
|
411
510
|
* Provider configuration for createProvider()
|
|
412
511
|
*/
|
|
413
|
-
interface ProviderConfig<TSandbox = any, TConfig = any> {
|
|
512
|
+
interface ProviderConfig<TSandbox = any, TConfig = any, TTemplate = any, TSnapshot = any> {
|
|
414
513
|
name: string;
|
|
415
514
|
methods: {
|
|
416
515
|
sandbox: SandboxMethods<TSandbox, TConfig>;
|
|
516
|
+
template?: TemplateMethods<TTemplate, TConfig>;
|
|
517
|
+
snapshot?: SnapshotMethods<TSnapshot, TConfig>;
|
|
417
518
|
};
|
|
418
519
|
}
|
|
419
520
|
/**
|
|
@@ -422,6 +523,6 @@ interface ProviderConfig<TSandbox = any, TConfig = any> {
|
|
|
422
523
|
* Auto-generates all boilerplate classes and provides feature detection
|
|
423
524
|
* based on which methods are implemented.
|
|
424
525
|
*/
|
|
425
|
-
declare function createProvider<TSandbox, TConfig>(providerConfig: ProviderConfig<TSandbox, TConfig>): (config: TConfig) => Provider
|
|
526
|
+
declare function createProvider<TSandbox, TConfig = any, TTemplate = any, TSnapshot = any>(providerConfig: ProviderConfig<TSandbox, TConfig, TTemplate, TSnapshot>): (config: TConfig) => Provider<TSandbox, TTemplate, TSnapshot>;
|
|
426
527
|
|
|
427
|
-
export { CommandExitError, type ComputeAPI, type ComputeConfig, type ComputeRequest, type ComputeResponse, type CreateSandboxOptions, type CreateSandboxParams, type CreateSandboxParamsWithOptionalProvider, type ExecutionResult, type ExtractSandboxInstanceType, type FileEntry, type HandleComputeRequestParams, type Provider, type ProviderConfig, type ProviderSandboxManager, type RunCommandOptions, type Runtime, type Sandbox, type SandboxFileSystem, type SandboxInfo, type SandboxMethods, type SandboxStatus, type TypedComputeAPI, type TypedSandbox, compute, createBackgroundCommand, createCompute, createProvider, handleComputeRequest, isCommandExitError };
|
|
528
|
+
export { CommandExitError, type ComputeAPI, type ComputeConfig, type ComputeRequest, type ComputeResponse, type CreateSandboxOptions, type CreateSandboxParams, type CreateSandboxParamsWithOptionalProvider, type CreateSnapshotOptions, type CreateTemplateOptions, type ExecutionResult, type ExtractSandboxInstanceType, type FileEntry, type HandleComputeRequestParams, type ListSnapshotsOptions, type ListTemplatesOptions, type Provider, type ProviderConfig, type ProviderSandboxManager, type ProviderSandboxTypeMap, type ProviderSnapshotManager, type ProviderTemplateManager, type RunCommandOptions, type Runtime, type Sandbox, type SandboxFileSystem, type SandboxInfo, type SandboxMethods, type SandboxStatus, type SnapshotMethods, type TemplateMethods, type TypedComputeAPI, type TypedSandbox, compute, createBackgroundCommand, createCompute, createProvider, handleComputeRequest, isCommandExitError };
|