computesdk 1.6.0 → 1.7.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/dist/index.d.mts +40 -25
- package/dist/index.d.ts +40 -25
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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
|
*/
|
|
@@ -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,45 @@ 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
|
-
* Provider sandbox
|
|
205
|
+
* Provider sandbox manager interface - handles sandbox lifecycle
|
|
192
206
|
*/
|
|
193
|
-
interface ProviderSandboxManager {
|
|
207
|
+
interface ProviderSandboxManager<TSandbox = any> {
|
|
194
208
|
/** Create a new sandbox */
|
|
195
|
-
create(options?: CreateSandboxOptions): Promise<Sandbox
|
|
209
|
+
create(options?: CreateSandboxOptions): Promise<Sandbox<TSandbox>>;
|
|
196
210
|
/** Get an existing sandbox by ID */
|
|
197
|
-
getById(sandboxId: string): Promise<Sandbox | null>;
|
|
211
|
+
getById(sandboxId: string): Promise<Sandbox<TSandbox> | null>;
|
|
198
212
|
/** List all active sandboxes */
|
|
199
|
-
list(): Promise<Sandbox[]>;
|
|
213
|
+
list(): Promise<Sandbox<TSandbox>[]>;
|
|
200
214
|
/** Destroy a sandbox */
|
|
201
215
|
destroy(sandboxId: string): Promise<void>;
|
|
202
216
|
}
|
|
203
217
|
/**
|
|
204
218
|
* Provider interface - creates and manages resources
|
|
205
219
|
*/
|
|
206
|
-
interface Provider {
|
|
220
|
+
interface Provider<TSandbox = any> {
|
|
207
221
|
/** Provider name/type */
|
|
208
222
|
readonly name: string;
|
|
209
223
|
/** Sandbox management operations */
|
|
210
|
-
readonly sandbox: ProviderSandboxManager
|
|
224
|
+
readonly sandbox: ProviderSandboxManager<TSandbox>;
|
|
225
|
+
/** Phantom type property for TypeScript inference - not used at runtime */
|
|
226
|
+
readonly __sandboxType: TSandbox;
|
|
211
227
|
}
|
|
212
228
|
/**
|
|
213
229
|
* Configuration for the compute singleton
|
|
@@ -285,7 +301,6 @@ interface TypedComputeAPI<TProvider extends Provider> extends Omit<ComputeAPI, '
|
|
|
285
301
|
declare const compute: ComputeAPI;
|
|
286
302
|
/**
|
|
287
303
|
* Create a compute instance with proper typing
|
|
288
|
-
* This enables proper type inference for getInstance() calls
|
|
289
304
|
*
|
|
290
305
|
* @example
|
|
291
306
|
* ```typescript
|
|
@@ -297,7 +312,7 @@ declare const compute: ComputeAPI;
|
|
|
297
312
|
* });
|
|
298
313
|
*
|
|
299
314
|
* const sandbox = await compute.sandbox.create();
|
|
300
|
-
* const instance = sandbox.getInstance(); // ✅ Properly typed!
|
|
315
|
+
* const instance = sandbox.getInstance(); // ✅ Properly typed E2B Sandbox!
|
|
301
316
|
* ```
|
|
302
317
|
*/
|
|
303
318
|
declare function createCompute<TProvider extends Provider>(config: ComputeConfig<TProvider>): TypedComputeAPI<TProvider>;
|
|
@@ -422,6 +437,6 @@ interface ProviderConfig<TSandbox = any, TConfig = any> {
|
|
|
422
437
|
* Auto-generates all boilerplate classes and provides feature detection
|
|
423
438
|
* based on which methods are implemented.
|
|
424
439
|
*/
|
|
425
|
-
declare function createProvider<TSandbox, TConfig>(providerConfig: ProviderConfig<TSandbox, TConfig>): (config: TConfig) => Provider
|
|
440
|
+
declare function createProvider<TSandbox, TConfig>(providerConfig: ProviderConfig<TSandbox, TConfig>): (config: TConfig) => Provider<TSandbox>;
|
|
426
441
|
|
|
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 };
|
|
442
|
+
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 ProviderSandboxTypeMap, type RunCommandOptions, type Runtime, type Sandbox, type SandboxFileSystem, type SandboxInfo, type SandboxMethods, type SandboxStatus, 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
|
*/
|
|
@@ -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,45 @@ 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
|
-
* Provider sandbox
|
|
205
|
+
* Provider sandbox manager interface - handles sandbox lifecycle
|
|
192
206
|
*/
|
|
193
|
-
interface ProviderSandboxManager {
|
|
207
|
+
interface ProviderSandboxManager<TSandbox = any> {
|
|
194
208
|
/** Create a new sandbox */
|
|
195
|
-
create(options?: CreateSandboxOptions): Promise<Sandbox
|
|
209
|
+
create(options?: CreateSandboxOptions): Promise<Sandbox<TSandbox>>;
|
|
196
210
|
/** Get an existing sandbox by ID */
|
|
197
|
-
getById(sandboxId: string): Promise<Sandbox | null>;
|
|
211
|
+
getById(sandboxId: string): Promise<Sandbox<TSandbox> | null>;
|
|
198
212
|
/** List all active sandboxes */
|
|
199
|
-
list(): Promise<Sandbox[]>;
|
|
213
|
+
list(): Promise<Sandbox<TSandbox>[]>;
|
|
200
214
|
/** Destroy a sandbox */
|
|
201
215
|
destroy(sandboxId: string): Promise<void>;
|
|
202
216
|
}
|
|
203
217
|
/**
|
|
204
218
|
* Provider interface - creates and manages resources
|
|
205
219
|
*/
|
|
206
|
-
interface Provider {
|
|
220
|
+
interface Provider<TSandbox = any> {
|
|
207
221
|
/** Provider name/type */
|
|
208
222
|
readonly name: string;
|
|
209
223
|
/** Sandbox management operations */
|
|
210
|
-
readonly sandbox: ProviderSandboxManager
|
|
224
|
+
readonly sandbox: ProviderSandboxManager<TSandbox>;
|
|
225
|
+
/** Phantom type property for TypeScript inference - not used at runtime */
|
|
226
|
+
readonly __sandboxType: TSandbox;
|
|
211
227
|
}
|
|
212
228
|
/**
|
|
213
229
|
* Configuration for the compute singleton
|
|
@@ -285,7 +301,6 @@ interface TypedComputeAPI<TProvider extends Provider> extends Omit<ComputeAPI, '
|
|
|
285
301
|
declare const compute: ComputeAPI;
|
|
286
302
|
/**
|
|
287
303
|
* Create a compute instance with proper typing
|
|
288
|
-
* This enables proper type inference for getInstance() calls
|
|
289
304
|
*
|
|
290
305
|
* @example
|
|
291
306
|
* ```typescript
|
|
@@ -297,7 +312,7 @@ declare const compute: ComputeAPI;
|
|
|
297
312
|
* });
|
|
298
313
|
*
|
|
299
314
|
* const sandbox = await compute.sandbox.create();
|
|
300
|
-
* const instance = sandbox.getInstance(); // ✅ Properly typed!
|
|
315
|
+
* const instance = sandbox.getInstance(); // ✅ Properly typed E2B Sandbox!
|
|
301
316
|
* ```
|
|
302
317
|
*/
|
|
303
318
|
declare function createCompute<TProvider extends Provider>(config: ComputeConfig<TProvider>): TypedComputeAPI<TProvider>;
|
|
@@ -422,6 +437,6 @@ interface ProviderConfig<TSandbox = any, TConfig = any> {
|
|
|
422
437
|
* Auto-generates all boilerplate classes and provides feature detection
|
|
423
438
|
* based on which methods are implemented.
|
|
424
439
|
*/
|
|
425
|
-
declare function createProvider<TSandbox, TConfig>(providerConfig: ProviderConfig<TSandbox, TConfig>): (config: TConfig) => Provider
|
|
440
|
+
declare function createProvider<TSandbox, TConfig>(providerConfig: ProviderConfig<TSandbox, TConfig>): (config: TConfig) => Provider<TSandbox>;
|
|
426
441
|
|
|
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 };
|
|
442
|
+
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 ProviderSandboxTypeMap, type RunCommandOptions, type Runtime, type Sandbox, type SandboxFileSystem, type SandboxInfo, type SandboxMethods, type SandboxStatus, type TypedComputeAPI, type TypedSandbox, compute, createBackgroundCommand, createCompute, createProvider, handleComputeRequest, isCommandExitError };
|
package/dist/index.js
CHANGED
|
@@ -652,6 +652,7 @@ var GeneratedSandboxManager = class {
|
|
|
652
652
|
}
|
|
653
653
|
};
|
|
654
654
|
var GeneratedProvider = class {
|
|
655
|
+
// Phantom type for TypeScript inference
|
|
655
656
|
constructor(config, providerConfig) {
|
|
656
657
|
this.name = providerConfig.name;
|
|
657
658
|
this.sandbox = new GeneratedSandboxManager(
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/types/sandbox.ts","../src/compute.ts","../src/request-handler.ts","../src/factory.ts"],"sourcesContent":["/**\n * ComputeSDK Core\n * \n * Clean Provider/Sandbox separation architecture with extensible compute.* API\n */\n\n// Export all types\nexport * from './types';\n\n// Export compute singleton - the main API\nexport { compute, createCompute } from './compute';\n\n// Export request handler for web framework integration\nexport { handleComputeRequest } from './request-handler';\n\n// Export compute request/response types\nexport type {\n ComputeRequest,\n ComputeResponse,\n HandleComputeRequestParams\n} from './request-handler';\n\n\n\n// Export provider factory for creating custom providers\nexport { createProvider, createBackgroundCommand } from './factory';\nexport type { ProviderConfig, SandboxMethods } from './factory';\n\n// Export error handling utilities (explicitly for clarity)\nexport { CommandExitError, isCommandExitError } from './types/sandbox';\n\n// Test suite is available separately via @computesdk/test-utils package\n","/**\n * Sandbox Types\n * \n * Types related to sandbox execution, filesystem, terminal operations\n */\n\n// Forward declaration to avoid circular dependency\ninterface Provider {\n readonly name: string;\n readonly sandbox: any; // Will be properly typed when imported together\n}\n\n/**\n * Utility type to extract the native instance type from a provider\n * This enables proper typing for getInstance() calls by looking at the provider's internal types\n */\nexport type ExtractSandboxInstanceType<TProvider extends Provider> = TProvider extends Provider ? \n TProvider extends { \n sandbox: { \n create(): Promise<infer TSandbox> \n } \n } ? (\n TSandbox extends { getInstance(): infer TInstance } \n ? TInstance \n : any\n ) : any : any;\n\n/**\n * Supported runtime environments\n */\nexport type Runtime = 'node' | 'python';\n\n/**\n * Sandbox status types\n */\nexport type SandboxStatus = 'running' | 'stopped' | 'error';\n\n/**\n * Options for running commands\n */\nexport interface RunCommandOptions {\n /** Run command in background (non-blocking) */\n background?: boolean;\n}\n\n/**\n * Result of code execution\n */\nexport interface ExecutionResult {\n /** Standard output from the execution */\n stdout: string;\n /** Standard error from the execution */\n stderr: string;\n /** Exit code from the execution */\n exitCode: number;\n /** Time taken for execution in milliseconds */\n executionTime: number;\n /** ID of the sandbox where the code was executed */\n sandboxId: string;\n /** Provider that executed the code */\n provider: string;\n /** Process ID for background jobs (if applicable) */\n pid?: number;\n /** Whether this command is running in background */\n isBackground?: boolean;\n}\n\n/**\n * Information about a sandbox\n */\nexport interface SandboxInfo {\n /** Unique identifier for the sandbox */\n id: string;\n /** Provider hosting the sandbox */\n provider: string;\n /** Runtime environment in the sandbox */\n runtime: Runtime;\n /** Current status of the sandbox */\n status: SandboxStatus;\n /** When the sandbox was created */\n createdAt: Date;\n /** Execution timeout in milliseconds */\n timeout: number;\n /** Additional provider-specific metadata */\n metadata?: Record<string, any>;\n}\n\n/**\n * Options for creating a sandbox\n */\nexport interface CreateSandboxOptions {\n /** Runtime environment */\n runtime?: Runtime;\n /** Execution timeout in milliseconds */\n timeout?: number;\n /** Custom sandbox ID (if supported by provider) */\n sandboxId?: string;\n /** Template ID for sandbox creation (provider-specific) */\n templateId?: string;\n /** Additional metadata for the sandbox */\n metadata?: Record<string, any>;\n /** Domain for sandbox connection (provider-specific) */\n domain?: string;\n /** Environment variables for the sandbox */\n envs?: Record<string, string>;\n}\n\n/**\n * File system entry information\n */\nexport interface FileEntry {\n /** File/directory name */\n name: string;\n /** Full path to the entry */\n path: string;\n /** Whether this is a directory */\n isDirectory: boolean;\n /** File size in bytes (0 for directories) */\n size: number;\n /** Last modified timestamp */\n lastModified: Date;\n}\n\n/**\n * File system interface for sandbox operations\n */\nexport interface SandboxFileSystem {\n /** Read file contents */\n readFile(path: string): Promise<string>;\n /** Write file contents */\n writeFile(path: string, content: string): Promise<void>;\n /** Create directory */\n mkdir(path: string): Promise<void>;\n /** List directory contents */\n readdir(path: string): Promise<FileEntry[]>;\n /** Check if file/directory exists */\n exists(path: string): Promise<boolean>;\n /** Remove file or directory */\n remove(path: string): Promise<void>;\n}\n\n/**\n * Error thrown when a command exits with a non-zero status\n */\nexport class CommandExitError extends Error {\n name = 'CommandExitError';\n constructor(public result: {\n exitCode: number;\n stdout: string;\n stderr: string;\n error: boolean;\n }) {\n super(`Command exited with code ${result.exitCode}`);\n }\n}\n\n/**\n * Type guard to check if an error is a CommandExitError\n */\nexport function isCommandExitError(error: unknown): error is CommandExitError {\n return (\n typeof error === 'object' &&\n error !== null &&\n 'name' in error &&\n error.name === 'CommandExitError' &&\n 'result' in error\n );\n}\n\n\n\n\n\n/**\n * Base sandbox interface - what developers interact with\n */\nexport interface Sandbox {\n /** Unique identifier for the sandbox */\n readonly sandboxId: string;\n /** Provider that created this sandbox */\n readonly provider: string;\n\n /** Execute code in the sandbox */\n runCode(code: string, runtime?: Runtime): Promise<ExecutionResult>;\n /** Execute shell commands */\n runCommand(command: string, args?: string[], options?: RunCommandOptions): Promise<ExecutionResult>;\n /** Get information about the sandbox */\n getInfo(): Promise<SandboxInfo>;\n /** Get URL for accessing the sandbox on a specific port */\n getUrl(options: { port: number; protocol?: string }): Promise<string>;\n /** Get the provider instance that created this sandbox */\n getProvider(): Provider;\n /** Get the native provider sandbox instance with proper typing */\n getInstance<T = any>(): T;\n /** Kill the sandbox */\n kill(): Promise<void>;\n /** Destroy the sandbox and clean up resources */\n destroy(): Promise<void>;\n\n /** File system operations */\n readonly filesystem: SandboxFileSystem;\n}\n\n/**\n * Typed sandbox interface that preserves the provider's native instance type\n */\nexport interface TypedSandbox<TProvider extends Provider> extends Sandbox {\n /** Get the provider instance that created this sandbox with proper typing */\n getProvider(): TProvider;\n /** Get the native provider sandbox instance with proper typing */\n getInstance(): ExtractSandboxInstanceType<TProvider>;\n getInstance<T>(): T;\n}","/**\n * Compute Singleton - Main API Orchestrator\n * \n * Provides the unified compute.* API and delegates to specialized managers\n */\n\nimport type { ComputeAPI, CreateSandboxParams, CreateSandboxParamsWithOptionalProvider, ComputeConfig, Sandbox, Provider, TypedSandbox, TypedComputeAPI } from './types';\n\n/**\n * Compute singleton implementation - orchestrates all compute operations\n */\nclass ComputeManager implements ComputeAPI {\n private config: ComputeConfig | null = null;\n private typedState: { \n isTyped: boolean; \n provider: Provider | null; \n } = { isTyped: false, provider: null };\n\n /**\n * Set default configuration with generic type preservation\n */\n setConfig<TProvider extends Provider>(config: ComputeConfig<TProvider>): void {\n // Validate that at least one provider is specified\n if (!config.defaultProvider && !config.provider) {\n throw new Error('Either defaultProvider or provider must be specified in setConfig');\n }\n \n // Handle backwards compatibility: if both are provided, defaultProvider takes precedence\n if (config.defaultProvider && config.provider) {\n console.warn('Both defaultProvider and provider specified in setConfig. Using defaultProvider. The provider key is deprecated, please use defaultProvider instead.');\n }\n \n // Normalize config to always have both fields for internal use (backward compatibility)\n const actualProvider = config.defaultProvider || config.provider!;\n this.config = {\n provider: actualProvider,\n defaultProvider: actualProvider\n };\n\n // Store typed state for type-aware operations\n this.typedState = {\n isTyped: true,\n provider: actualProvider\n };\n }\n\n /**\n * Get current configuration\n */\n getConfig(): ComputeConfig | null {\n return this.config;\n }\n\n /**\n * Clear current configuration\n */\n clearConfig(): void {\n this.config = null;\n }\n\n /**\n * Get the default provider, throwing if not configured\n */\n private getDefaultProvider(): Provider {\n const provider = this.config?.defaultProvider || this.config?.provider;\n if (!provider) {\n throw new Error(\n 'No default provider configured. Either call compute.setConfig({ defaultProvider }) or pass provider explicitly.'\n );\n }\n return provider;\n }\n\n sandbox = {\n /**\n * Create a sandbox from a provider (or default provider if configured)\n * \n * @example\n * ```typescript\n * import { e2b } from '@computesdk/e2b'\n * import { compute } from 'computesdk'\n * \n * // With explicit provider\n * const sandbox = await compute.sandbox.create({\n * provider: e2b({ apiKey: 'your-key' })\n * })\n * \n * // With default provider (both forms work)\n * compute.setConfig({ defaultProvider: e2b({ apiKey: 'your-key' }) })\n * const sandbox1 = await compute.sandbox.create({})\n * const sandbox2 = await compute.sandbox.create()\n * ```\n */\n create: async (params?: CreateSandboxParams | CreateSandboxParamsWithOptionalProvider): Promise<Sandbox> => {\n const provider = params && 'provider' in params && params.provider ? params.provider : this.getDefaultProvider();\n const options = params?.options;\n const sandbox = await provider.sandbox.create(options);\n \n // If we have typed state and no explicit provider passed, cast to typed sandbox\n // This enables proper type inference for getInstance() when using default provider\n if (this.typedState.isTyped && (!params || !('provider' in params && params.provider))) {\n return sandbox as TypedSandbox<any>;\n }\n \n return sandbox;\n },\n\n /**\n * Get an existing sandbox by ID from a provider (or default provider if configured)\n */\n getById: async (providerOrSandboxId: Provider | string, sandboxId?: string): Promise<Sandbox | null> => {\n if (typeof providerOrSandboxId === 'string') {\n // Called with just sandboxId, use default provider\n const provider = this.getDefaultProvider();\n const sandbox = await provider.sandbox.getById(providerOrSandboxId);\n \n // If we have typed state, cast to typed sandbox for proper getInstance() typing\n if (this.typedState.isTyped && sandbox) {\n return sandbox as TypedSandbox<any>;\n }\n \n return sandbox;\n } else {\n // Called with provider and sandboxId\n if (!sandboxId) {\n throw new Error('sandboxId is required when provider is specified');\n }\n return await providerOrSandboxId.sandbox.getById(sandboxId);\n }\n },\n\n /**\n * List all active sandboxes from a provider (or default provider if configured)\n */\n list: async (provider?: Provider): Promise<Sandbox[]> => {\n const actualProvider = provider || this.getDefaultProvider();\n const sandboxes = await actualProvider.sandbox.list();\n \n // If we have typed state and no explicit provider passed, cast to typed sandboxes\n if (this.typedState.isTyped && !provider) {\n return sandboxes as TypedSandbox<any>[];\n }\n \n return sandboxes;\n },\n\n /**\n * Destroy a sandbox via a provider (or default provider if configured)\n */\n destroy: async (providerOrSandboxId: Provider | string, sandboxId?: string): Promise<void> => {\n if (typeof providerOrSandboxId === 'string') {\n // Called with just sandboxId, use default provider\n const provider = this.getDefaultProvider();\n return await provider.sandbox.destroy(providerOrSandboxId);\n } else {\n // Called with provider and sandboxId\n if (!sandboxId) {\n throw new Error('sandboxId is required when provider is specified');\n }\n return await providerOrSandboxId.sandbox.destroy(sandboxId);\n }\n }\n };\n\n // Future: compute.blob.*, compute.database.*, compute.git.* will be added here\n // blob = new BlobManager();\n // database = new DatabaseManager(); \n // git = new GitManager();\n\n\n}\n\n/**\n * Singleton instance - the main API (untyped)\n */\nexport const compute: ComputeAPI = new ComputeManager();\n\n/**\n * Create a compute instance with proper typing\n * This enables proper type inference for getInstance() calls\n * \n * @example\n * ```typescript\n * import { e2b } from '@computesdk/e2b'\n * import { createCompute } from 'computesdk'\n * \n * const compute = createCompute({\n * defaultProvider: e2b({ apiKey: 'your-key' }),\n * });\n * \n * const sandbox = await compute.sandbox.create();\n * const instance = sandbox.getInstance(); // ✅ Properly typed!\n * ```\n */\nexport function createCompute<TProvider extends Provider>(config: ComputeConfig<TProvider>): TypedComputeAPI<TProvider> {\n const manager = new ComputeManager();\n \n // Set config directly without calling the public setConfig method\n const actualProvider = config.defaultProvider || config.provider!;\n manager['config'] = {\n provider: actualProvider,\n defaultProvider: actualProvider\n };\n manager['typedState'] = {\n isTyped: true,\n provider: actualProvider\n };\n \n return {\n setConfig: <T extends Provider>(cfg: ComputeConfig<T>) => createCompute(cfg),\n getConfig: () => manager.getConfig(),\n clearConfig: () => manager.clearConfig(),\n \n sandbox: {\n create: async (params?: Omit<CreateSandboxParamsWithOptionalProvider, 'provider'>) => {\n const sandbox = await manager.sandbox.create(params);\n return sandbox as TypedSandbox<TProvider>;\n },\n \n getById: async (sandboxId: string) => {\n const sandbox = await manager.sandbox.getById(sandboxId);\n return sandbox ? sandbox as TypedSandbox<TProvider> : null;\n },\n \n list: async () => {\n const sandboxes = await manager.sandbox.list();\n return sandboxes as TypedSandbox<TProvider>[];\n },\n \n destroy: async (sandboxId: string) => {\n return await manager.sandbox.destroy(sandboxId);\n }\n }\n } as TypedComputeAPI<TProvider>;\n}\n\n\n\n","/**\n * Simplified Request Handler for Web Framework Integration\n * \n * Handles JSON requests for sandbox and code execution operations.\n * Terminal support removed - will be re-added with WebSocket VM connections.\n */\n\nimport type { Provider, Runtime } from './types';\nimport { compute } from './compute';\n\n/**\n * Request structure supporting sandbox and code execution capabilities\n */\nexport interface ComputeRequest {\n /** Action in dot notation (e.g., 'compute.sandbox.create') */\n action: string;\n \n /** Parameters for the action */\n sandboxId?: string;\n code?: string;\n command?: string;\n args?: string[];\n runtime?: Runtime;\n path?: string;\n content?: string;\n \n /** Command options (for runCommand action) */\n commandOptions?: {\n background?: boolean;\n };\n \n /** Sandbox creation options */\n options?: {\n runtime?: Runtime;\n timeout?: number;\n sandboxId?: string;\n };\n}\n\n/**\n * Response structure for compute operations\n */\nexport interface ComputeResponse {\n success: boolean;\n error?: string;\n sandboxId: string;\n provider: string;\n [key: string]: any; // Allow any additional response data\n}\n\n/**\n * Execute compute action using targeted handling\n */\nasync function executeAction(body: ComputeRequest, provider: Provider): Promise<ComputeResponse> {\n try {\n const { action, sandboxId } = body;\n \n // Sandbox management operations\n if (action === 'compute.sandbox.create') {\n const sandbox = await compute.sandbox.create({\n provider,\n options: body.options || { runtime: 'python' }\n });\n return {\n success: true,\n sandboxId: sandbox.sandboxId,\n provider: provider.name\n };\n }\n \n if (action === 'compute.sandbox.list') {\n const sandboxes = await compute.sandbox.list(provider);\n return {\n success: true,\n sandboxId: '',\n provider: provider.name,\n sandboxes: sandboxes.map(sb => ({\n sandboxId: sb.sandboxId,\n provider: sb.provider\n }))\n };\n }\n \n if (action === 'compute.sandbox.destroy') {\n if (!sandboxId) {\n throw new Error('sandboxId is required for destroy action');\n }\n await compute.sandbox.destroy(provider, sandboxId);\n return {\n success: true,\n sandboxId,\n provider: provider.name\n };\n }\n \n // For sandbox instance methods, get the sandbox first\n if (!sandboxId) {\n throw new Error('sandboxId is required for this action');\n }\n \n const sandbox = await compute.sandbox.getById(provider, sandboxId);\n if (!sandbox) {\n throw new Error(`Sandbox ${sandboxId} not found`);\n }\n \n // Sandbox info\n if (action === 'compute.sandbox.getInfo') {\n const result = await sandbox.getInfo();\n return {\n success: true,\n sandboxId,\n provider: provider.name,\n info: {\n id: result.id,\n provider: result.provider,\n runtime: result.runtime,\n status: result.status,\n createdAt: result.createdAt.toISOString(),\n timeout: result.timeout,\n metadata: result.metadata\n }\n };\n }\n \n // Code execution\n if (action === 'compute.sandbox.runCode') {\n if (!body.code) throw new Error('code is required');\n const result = await sandbox.runCode(body.code, body.runtime);\n return {\n success: true,\n sandboxId,\n provider: provider.name,\n result: {\n stdout: result.stdout,\n stderr: result.stderr,\n exitCode: result.exitCode,\n executionTime: result.executionTime\n }\n };\n }\n \n if (action === 'compute.sandbox.runCommand') {\n if (!body.command) throw new Error('command is required');\n const result = await sandbox.runCommand(body.command, body.args, body.commandOptions);\n return {\n success: true,\n sandboxId,\n provider: provider.name,\n result: {\n stdout: result.stdout,\n stderr: result.stderr,\n exitCode: result.exitCode,\n executionTime: result.executionTime,\n ...(result.isBackground && { isBackground: result.isBackground }),\n ...(result.pid && { pid: result.pid })\n }\n };\n }\n \n // Filesystem operations\n if (action === 'compute.sandbox.filesystem.readFile') {\n if (!body.path) throw new Error('path is required');\n const result = await sandbox.filesystem.readFile(body.path);\n return {\n success: true,\n sandboxId,\n provider: provider.name,\n fileContent: result\n };\n }\n \n if (action === 'compute.sandbox.filesystem.writeFile') {\n if (!body.path) throw new Error('path is required');\n if (body.content === undefined) throw new Error('content is required');\n await sandbox.filesystem.writeFile(body.path, body.content);\n return { success: true, sandboxId, provider: provider.name };\n }\n \n if (action === 'compute.sandbox.filesystem.mkdir') {\n if (!body.path) throw new Error('path is required');\n await sandbox.filesystem.mkdir(body.path);\n return { success: true, sandboxId, provider: provider.name };\n }\n \n if (action === 'compute.sandbox.filesystem.readdir') {\n if (!body.path) throw new Error('path is required');\n const result = await sandbox.filesystem.readdir(body.path);\n return {\n success: true,\n sandboxId,\n provider: provider.name,\n files: result.map((entry: any) => ({\n name: entry.name,\n path: entry.path,\n isDirectory: entry.isDirectory,\n size: entry.size,\n lastModified: entry.lastModified.toISOString()\n }))\n };\n }\n \n if (action === 'compute.sandbox.filesystem.exists') {\n if (!body.path) throw new Error('path is required');\n const result = await sandbox.filesystem.exists(body.path);\n return {\n success: true,\n sandboxId,\n provider: provider.name,\n exists: result\n };\n }\n \n if (action === 'compute.sandbox.filesystem.remove') {\n if (!body.path) throw new Error('path is required');\n await sandbox.filesystem.remove(body.path);\n return { success: true, sandboxId, provider: provider.name };\n }\n \n throw new Error(`Unknown action: ${action}`);\n \n } catch (error) {\n return {\n success: false,\n error: error instanceof Error ? error.message : 'Unknown error occurred',\n sandboxId: body.sandboxId || '',\n provider: provider.name\n };\n }\n}\n\n/**\n * Main request handler - handles HTTP requests and pre-parsed bodies\n */\nexport async function handleComputeRequest(\n params: HandleComputeRequestParams\n): Promise<ComputeResponse>;\nexport async function handleComputeRequest(\n requestOrBody: Request | ComputeRequest,\n provider: Provider\n): Promise<Response>;\nexport async function handleComputeRequest(\n paramsOrRequestOrBody: HandleComputeRequestParams | Request | ComputeRequest,\n provider?: Provider\n): Promise<ComputeResponse | Response> {\n // Handle object-style API\n if (typeof paramsOrRequestOrBody === 'object' && 'request' in paramsOrRequestOrBody && 'provider' in paramsOrRequestOrBody) {\n const params = paramsOrRequestOrBody as HandleComputeRequestParams;\n return await executeAction(params.request, params.provider);\n }\n \n // Handle original API\n if (!provider) {\n throw new Error('Provider is required when not using object-style API');\n }\n \n const requestOrBody = paramsOrRequestOrBody as Request | ComputeRequest;\n try {\n let body: ComputeRequest;\n \n if (requestOrBody instanceof Request) {\n // Handle HTTP method validation\n if (requestOrBody.method !== 'POST') {\n return Response.json({\n success: false,\n error: 'Only POST requests are supported',\n sandboxId: '',\n provider: provider.name\n }, { status: 405 });\n }\n \n // Parse JSON body with better error handling\n try {\n body = await requestOrBody.json();\n } catch (parseError) {\n return Response.json({\n success: false,\n error: 'Invalid JSON in request body',\n sandboxId: '',\n provider: provider.name\n }, { status: 400 });\n }\n } else {\n body = requestOrBody;\n }\n \n // Execute the action\n const result = await executeAction(body, provider);\n \n return Response.json(result, {\n status: result.success ? 200 : 500\n });\n \n } catch (error) {\n return Response.json({\n success: false,\n error: error instanceof Error ? error.message : 'Request handling failed',\n sandboxId: '',\n provider: provider.name\n }, { status: 500 });\n }\n}\n\n/**\n * Legacy export for backward compatibility\n */\nexport interface HandleComputeRequestParams {\n request: ComputeRequest;\n provider: Provider;\n}\n\nexport { handleComputeRequest as handleHttpComputeRequest };","/**\n * Provider Factory - Creates providers from method definitions\n * \n * Eliminates boilerplate by auto-generating Provider/Sandbox classes\n * from simple method definitions with automatic feature detection.\n */\n\nimport type {\n Provider,\n ProviderSandboxManager,\n Sandbox,\n SandboxFileSystem,\n SandboxInfo,\n ExecutionResult,\n Runtime,\n CreateSandboxOptions,\n FileEntry,\n RunCommandOptions,\n} from './types/index.js';\n\n/**\n * Helper function to handle background command execution\n * Providers can use this to implement background job support\n */\nexport function createBackgroundCommand(command: string, args: string[] = [], options?: RunCommandOptions): { command: string; args: string[]; isBackground: boolean } {\n if (!options?.background) {\n return { command, args, isBackground: false };\n }\n\n // For background execution, we modify the command to run in background\n // Default approach: append & to make it run in background\n const fullCommand = args.length > 0 ? `${command} ${args.join(' ')}` : command;\n \n return {\n command: 'sh',\n args: ['-c', `${fullCommand} &`],\n isBackground: true\n };\n}\n\n/**\n * Flat sandbox method implementations - all operations in one place\n */\nexport interface SandboxMethods<TSandbox = any, TConfig = any> {\n // Collection operations (map to compute.sandbox.*)\n create: (config: TConfig, options?: CreateSandboxOptions) => Promise<{ sandbox: TSandbox; sandboxId: string }>;\n getById: (config: TConfig, sandboxId: string) => Promise<{ sandbox: TSandbox; sandboxId: string } | null>;\n list: (config: TConfig) => Promise<Array<{ sandbox: TSandbox; sandboxId: string }>>;\n destroy: (config: TConfig, sandboxId: string) => Promise<void>;\n \n // Instance operations (map to individual Sandbox methods)\n runCode: (sandbox: TSandbox, code: string, runtime?: Runtime, config?: TConfig) => Promise<ExecutionResult>;\n runCommand: (sandbox: TSandbox, command: string, args?: string[], options?: RunCommandOptions) => Promise<ExecutionResult>;\n getInfo: (sandbox: TSandbox) => Promise<SandboxInfo>;\n getUrl: (sandbox: TSandbox, options: { port: number; protocol?: string }) => Promise<string>;\n \n // Optional provider-specific typed getInstance method\n getInstance?: (sandbox: TSandbox) => TSandbox;\n \n // Optional filesystem methods\n filesystem?: {\n readFile: (sandbox: TSandbox, path: string, runCommand: (sandbox: TSandbox, command: string, args?: string[]) => Promise<ExecutionResult>) => Promise<string>;\n writeFile: (sandbox: TSandbox, path: string, content: string, runCommand: (sandbox: TSandbox, command: string, args?: string[]) => Promise<ExecutionResult>) => Promise<void>;\n mkdir: (sandbox: TSandbox, path: string, runCommand: (sandbox: TSandbox, command: string, args?: string[]) => Promise<ExecutionResult>) => Promise<void>;\n readdir: (sandbox: TSandbox, path: string, runCommand: (sandbox: TSandbox, command: string, args?: string[]) => Promise<ExecutionResult>) => Promise<FileEntry[]>;\n exists: (sandbox: TSandbox, path: string, runCommand: (sandbox: TSandbox, command: string, args?: string[]) => Promise<ExecutionResult>) => Promise<boolean>;\n remove: (sandbox: TSandbox, path: string, runCommand: (sandbox: TSandbox, command: string, args?: string[]) => Promise<ExecutionResult>) => Promise<void>;\n };\n \n\n}\n\n/**\n * Provider configuration for createProvider()\n */\nexport interface ProviderConfig<TSandbox = any, TConfig = any> {\n name: string;\n methods: {\n sandbox: SandboxMethods<TSandbox, TConfig>;\n };\n}\n\n/**\n * Default filesystem implementations based on shell commands\n * These work for any provider that supports shell command execution\n */\nconst defaultFilesystemMethods = {\n readFile: async (sandbox: any, path: string, runCommand: (sandbox: any, command: string, args?: string[]) => Promise<ExecutionResult>): Promise<string> => {\n const result = await runCommand(sandbox, 'cat', [path]);\n if (result.exitCode !== 0) {\n throw new Error(`Failed to read file ${path}: ${result.stderr}`);\n }\n // Trim trailing newline that cat command adds\n return result.stdout.replace(/\\n$/, '');\n },\n\n writeFile: async (sandbox: any, path: string, content: string, runCommand: (sandbox: any, command: string, args?: string[]) => Promise<ExecutionResult>): Promise<void> => {\n const result = await runCommand(sandbox, 'sh', ['-c', `echo ${JSON.stringify(content)} > ${JSON.stringify(path)}`]);\n if (result.exitCode !== 0) {\n throw new Error(`Failed to write file ${path}: ${result.stderr}`);\n }\n },\n\n mkdir: async (sandbox: any, path: string, runCommand: (sandbox: any, command: string, args?: string[]) => Promise<ExecutionResult>): Promise<void> => {\n const result = await runCommand(sandbox, 'mkdir', ['-p', path]);\n if (result.exitCode !== 0) {\n throw new Error(`Failed to create directory ${path}: ${result.stderr}`);\n }\n },\n\n readdir: async (sandbox: any, path: string, runCommand: (sandbox: any, command: string, args?: string[]) => Promise<ExecutionResult>): Promise<FileEntry[]> => {\n // Try different ls variations for maximum compatibility\n let result = await runCommand(sandbox, 'ls', ['-la', path]);\n let hasDetailedOutput = true;\n \n // Fall back to basic ls if detailed flags not supported\n if (result.exitCode !== 0) {\n result = await runCommand(sandbox, 'ls', ['-l', path]);\n }\n if (result.exitCode !== 0) {\n result = await runCommand(sandbox, 'ls', [path]);\n hasDetailedOutput = false;\n }\n \n if (result.exitCode !== 0) {\n throw new Error(`Failed to list directory ${path}: ${result.stderr}`);\n }\n\n const lines = (result.stdout || '').split('\\n').filter((line: string) => line.trim() && !line.startsWith('total'));\n\n return lines.map((line: string) => {\n if (hasDetailedOutput && line.includes(' ')) {\n // Parse detailed ls output (ls -la or ls -l)\n const parts = line.trim().split(/\\s+/);\n const name = parts[parts.length - 1];\n const isDirectory = line.startsWith('d');\n \n return {\n name,\n path: `${path}/${name}`,\n isDirectory,\n size: parseInt(parts[4]) || 0,\n lastModified: new Date()\n };\n } else {\n // Parse simple ls output (just filenames)\n const name = line.trim();\n return {\n name,\n path: `${path}/${name}`,\n isDirectory: false, // Can't determine from simple ls\n size: 0,\n lastModified: new Date()\n };\n }\n });\n },\n\n exists: async (sandbox: any, path: string, runCommand: (sandbox: any, command: string, args?: string[]) => Promise<ExecutionResult>): Promise<boolean> => {\n const result = await runCommand(sandbox, 'test', ['-e', path]);\n return result.exitCode === 0; // Exit code 0 means file exists\n },\n\n remove: async (sandbox: any, path: string, runCommand: (sandbox: any, command: string, args?: string[]) => Promise<ExecutionResult>): Promise<void> => {\n const result = await runCommand(sandbox, 'rm', ['-rf', path]);\n if (result.exitCode !== 0) {\n throw new Error(`Failed to remove ${path}: ${result.stderr}`);\n }\n }\n};\n\n/**\n * Auto-generated filesystem implementation that throws \"not supported\" errors\n */\nclass UnsupportedFileSystem implements SandboxFileSystem {\n private readonly providerName: string;\n\n constructor(providerName: string) {\n this.providerName = providerName;\n }\n\n async readFile(_path: string): Promise<string> {\n throw new Error(`Filesystem operations are not supported by ${this.providerName}'s sandbox environment. ${this.providerName} sandboxes are designed for code execution only.`);\n }\n\n async writeFile(_path: string, _content: string): Promise<void> {\n throw new Error(`Filesystem operations are not supported by ${this.providerName}'s sandbox environment. ${this.providerName} sandboxes are designed for code execution only.`);\n }\n\n async mkdir(_path: string): Promise<void> {\n throw new Error(`Filesystem operations are not supported by ${this.providerName}'s sandbox environment. ${this.providerName} sandboxes are designed for code execution only.`);\n }\n\n async readdir(_path: string): Promise<FileEntry[]> {\n throw new Error(`Filesystem operations are not supported by ${this.providerName}'s sandbox environment. ${this.providerName} sandboxes are designed for code execution only.`);\n }\n\n async exists(_path: string): Promise<boolean> {\n throw new Error(`Filesystem operations are not supported by ${this.providerName}'s sandbox environment. ${this.providerName} sandboxes are designed for code execution only.`);\n }\n\n async remove(_path: string): Promise<void> {\n throw new Error(`Filesystem operations are not supported by ${this.providerName}'s sandbox environment. ${this.providerName} sandboxes are designed for code execution only.`);\n }\n}\n\n\n\n/**\n * Auto-generated filesystem implementation that wraps provider methods\n */\nclass SupportedFileSystem<TSandbox> implements SandboxFileSystem {\n constructor(\n private sandbox: TSandbox,\n private methods: NonNullable<SandboxMethods<TSandbox>['filesystem']>,\n private allMethods: SandboxMethods<TSandbox>\n ) {}\n\n async readFile(path: string): Promise<string> {\n return this.methods.readFile(this.sandbox, path, this.allMethods.runCommand);\n }\n\n async writeFile(path: string, content: string): Promise<void> {\n return this.methods.writeFile(this.sandbox, path, content, this.allMethods.runCommand);\n }\n\n async mkdir(path: string): Promise<void> {\n return this.methods.mkdir(this.sandbox, path, this.allMethods.runCommand);\n }\n\n async readdir(path: string): Promise<FileEntry[]> {\n return this.methods.readdir(this.sandbox, path, this.allMethods.runCommand);\n }\n\n async exists(path: string): Promise<boolean> {\n return this.methods.exists(this.sandbox, path, this.allMethods.runCommand);\n }\n\n async remove(path: string): Promise<void> {\n return this.methods.remove(this.sandbox, path, this.allMethods.runCommand);\n }\n}\n\n\n\n\n\n/**\n * Generated sandbox class - implements the Sandbox interface\n */\nclass GeneratedSandbox<TSandbox = any> implements Sandbox {\n readonly sandboxId: string;\n readonly provider: string;\n readonly filesystem: SandboxFileSystem;\n\n constructor(\n private sandbox: TSandbox,\n sandboxId: string,\n providerName: string,\n private methods: SandboxMethods<TSandbox>,\n private config: any,\n private destroyMethod: (config: any, sandboxId: string) => Promise<void>,\n private providerInstance: Provider\n ) {\n this.sandboxId = sandboxId;\n this.provider = providerName;\n\n // Auto-detect filesystem support\n if (methods.filesystem) {\n this.filesystem = new SupportedFileSystem(sandbox, methods.filesystem, methods);\n } else {\n this.filesystem = new UnsupportedFileSystem(providerName);\n }\n }\n\n getInstance(): TSandbox;\n getInstance<T extends TSandbox>(): T;\n getInstance<T extends TSandbox = TSandbox>(): T {\n // Use provider-specific typed getInstance if available\n if (this.methods.getInstance) {\n return this.methods.getInstance(this.sandbox) as T;\n }\n // Fallback to generic casting\n return this.sandbox as T;\n }\n\n async runCode(code: string, runtime?: Runtime): Promise<ExecutionResult> {\n return await this.methods.runCode(this.sandbox, code, runtime, this.config);\n }\n\n async runCommand(command: string, args?: string[], options?: RunCommandOptions): Promise<ExecutionResult> {\n return await this.methods.runCommand(this.sandbox, command, args, options);\n }\n\n async getInfo(): Promise<SandboxInfo> {\n return await this.methods.getInfo(this.sandbox);\n }\n\n async getUrl(options: { port: number; protocol?: string }): Promise<string> {\n return await this.methods.getUrl(this.sandbox, options);\n }\n\n getProvider(): Provider {\n return this.providerInstance;\n }\n\n async kill(): Promise<void> {\n // For backward compatibility, kill() delegates to destroy()\n await this.destroy();\n }\n\n async destroy(): Promise<void> {\n // Destroy via the provider's destroy method using our sandboxId\n await this.destroyMethod(this.config, this.sandboxId);\n }\n}\n\n/**\n * Auto-generated Sandbox Manager implementation\n */\nclass GeneratedSandboxManager<TSandbox, TConfig> implements ProviderSandboxManager {\n private activeSandboxes: Map<string, GeneratedSandbox<TSandbox>> = new Map();\n\n constructor(\n private config: TConfig,\n private providerName: string,\n private methods: SandboxMethods<TSandbox, TConfig>,\n private providerInstance: Provider\n ) {}\n\n async create(options?: CreateSandboxOptions): Promise<Sandbox> {\n const result = await this.methods.create(this.config, options);\n const sandbox = new GeneratedSandbox(\n result.sandbox,\n result.sandboxId,\n this.providerName,\n this.methods,\n this.config,\n this.methods.destroy,\n this.providerInstance\n );\n \n this.activeSandboxes.set(result.sandboxId, sandbox);\n return sandbox;\n }\n\n async getById(sandboxId: string): Promise<Sandbox | null> {\n // Check active sandboxes first\n const existing = this.activeSandboxes.get(sandboxId);\n if (existing) {\n return existing;\n }\n\n // Try to reconnect\n const result = await this.methods.getById(this.config, sandboxId);\n if (!result) {\n return null;\n }\n\n const sandbox = new GeneratedSandbox(\n result.sandbox,\n result.sandboxId,\n this.providerName,\n this.methods,\n this.config,\n this.methods.destroy,\n this.providerInstance\n );\n \n this.activeSandboxes.set(result.sandboxId, sandbox);\n return sandbox;\n }\n\n async list(): Promise<Sandbox[]> {\n const results = await this.methods.list(this.config);\n const sandboxes: Sandbox[] = [];\n\n for (const result of results) {\n let sandbox = this.activeSandboxes.get(result.sandboxId);\n if (!sandbox) {\n sandbox = new GeneratedSandbox(\n result.sandbox,\n result.sandboxId,\n this.providerName,\n this.methods,\n this.config,\n this.methods.destroy,\n this.providerInstance\n );\n this.activeSandboxes.set(result.sandboxId, sandbox);\n }\n sandboxes.push(sandbox);\n }\n\n return sandboxes;\n }\n\n async destroy(sandboxId: string): Promise<void> {\n await this.methods.destroy(this.config, sandboxId);\n this.activeSandboxes.delete(sandboxId);\n }\n}\n\n/**\n * Auto-generated Provider implementation\n */\nclass GeneratedProvider<TSandbox, TConfig> implements Provider {\n readonly name: string;\n readonly sandbox: ProviderSandboxManager;\n\n constructor(config: TConfig, providerConfig: ProviderConfig<TSandbox, TConfig>) {\n this.name = providerConfig.name;\n this.sandbox = new GeneratedSandboxManager(\n config,\n providerConfig.name,\n providerConfig.methods.sandbox,\n this\n );\n }\n}\n\n/**\n * Create a provider from method definitions\n * \n * Auto-generates all boilerplate classes and provides feature detection\n * based on which methods are implemented.\n */\nexport function createProvider<TSandbox, TConfig>(\n providerConfig: ProviderConfig<TSandbox, TConfig>\n): (config: TConfig) => Provider {\n // Auto-inject default filesystem methods if none provided\n if (!providerConfig.methods.sandbox.filesystem) {\n providerConfig.methods.sandbox.filesystem = defaultFilesystemMethods;\n }\n\n return (config: TConfig) => {\n return new GeneratedProvider(config, providerConfig);\n };\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACgJO,IAAM,mBAAN,cAA+B,MAAM;AAAA,EAE1C,YAAmB,QAKhB;AACD,UAAM,4BAA4B,OAAO,QAAQ,EAAE;AANlC;AADnB,gBAAO;AAAA,EAQP;AACF;AAKO,SAAS,mBAAmB,OAA2C;AAC5E,SACE,OAAO,UAAU,YACjB,UAAU,QACV,UAAU,SACV,MAAM,SAAS,sBACf,YAAY;AAEhB;;;AC5JA,IAAM,iBAAN,MAA2C;AAAA,EAA3C;AACE,SAAQ,SAA+B;AACvC,SAAQ,aAGJ,EAAE,SAAS,OAAO,UAAU,KAAK;AAyDrC,mBAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAoBR,QAAQ,OAAO,WAA6F;AAC1G,cAAM,WAAW,UAAU,cAAc,UAAU,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,UAAM,KAAK,QAAQ,QAAQ,KAAK,QAAQ,SAAS;AACjD,SAAK,gBAAgB,OAAO,SAAS;AAAA,EACvC;AACF;AAKA,IAAM,oBAAN,MAA+D;AAAA,EAI7D,YAAY,QAAiB,gBAAmD;AAC9E,SAAK,OAAO,eAAe;AAC3B,SAAK,UAAU,IAAI;AAAA,MACjB;AAAA,MACA,eAAe;AAAA,MACf,eAAe,QAAQ;AAAA,MACvB;AAAA,IACF;AAAA,EACF;AACF;AAQO,SAAS,eACd,gBAC+B;AAE/B,MAAI,CAAC,eAAe,QAAQ,QAAQ,YAAY;AAC9C,mBAAe,QAAQ,QAAQ,aAAa;AAAA,EAC9C;AAEA,SAAO,CAAC,WAAoB;AAC1B,WAAO,IAAI,kBAAkB,QAAQ,cAAc;AAAA,EACrD;AACF;","names":["sandbox"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/types/sandbox.ts","../src/compute.ts","../src/request-handler.ts","../src/factory.ts"],"sourcesContent":["/**\n * ComputeSDK Core\n * \n * Clean Provider/Sandbox separation architecture with extensible compute.* API\n */\n\n// Export all types\nexport * from './types';\n\n// Export compute singleton - the main API\nexport { compute, createCompute } from './compute';\n\n// Export request handler for web framework integration\nexport { handleComputeRequest } from './request-handler';\n\n// Export compute request/response types\nexport type {\n ComputeRequest,\n ComputeResponse,\n HandleComputeRequestParams\n} from './request-handler';\n\n\n\n// Export provider factory for creating custom providers\nexport { createProvider, createBackgroundCommand } from './factory';\nexport type { ProviderConfig, SandboxMethods } from './factory';\n\n// Export error handling utilities (explicitly for clarity)\nexport { CommandExitError, isCommandExitError } from './types/sandbox';\n\n// Test suite is available separately via @computesdk/test-utils package\n","/**\n * Sandbox Types\n * \n * Types related to sandbox execution, filesystem, terminal operations\n */\n\n// Forward declaration to avoid circular dependency\ninterface Provider {\n readonly name: string;\n readonly sandbox: any; // Will be properly typed when imported together\n}\n\n/**\n * Type mapping for provider names to their sandbox types\n * Manually defined for known providers since declaration merging isn't working reliably\n */\nexport interface ProviderSandboxTypeMap {\n e2b: any; // We can't import the E2B type directly, but we'll handle it differently\n vercel: any;\n daytona: any;\n}\n\n/**\n * Utility type to extract the native instance type from a provider\n * Uses provider name and manual type inference\n */\nexport type ExtractSandboxInstanceType<TProvider extends Provider> = \n TProvider extends { readonly name: 'e2b' }\n ? any // For now, let's just try to make the runtime casting work\n : TProvider extends { readonly name: 'vercel' }\n ? any\n : TProvider extends { readonly name: 'daytona' }\n ? any\n : any;\n\n/**\n * Supported runtime environments\n */\nexport type Runtime = 'node' | 'python';\n\n/**\n * Sandbox status types\n */\nexport type SandboxStatus = 'running' | 'stopped' | 'error';\n\n/**\n * Options for running commands\n */\nexport interface RunCommandOptions {\n /** Run command in background (non-blocking) */\n background?: boolean;\n}\n\n/**\n * Result of code execution\n */\nexport interface ExecutionResult {\n /** Standard output from the execution */\n stdout: string;\n /** Standard error from the execution */\n stderr: string;\n /** Exit code from the execution */\n exitCode: number;\n /** Time taken for execution in milliseconds */\n executionTime: number;\n /** ID of the sandbox where the code was executed */\n sandboxId: string;\n /** Provider that executed the code */\n provider: string;\n /** Process ID for background jobs (if applicable) */\n pid?: number;\n /** Whether this command is running in background */\n isBackground?: boolean;\n}\n\n/**\n * Information about a sandbox\n */\nexport interface SandboxInfo {\n /** Unique identifier for the sandbox */\n id: string;\n /** Provider hosting the sandbox */\n provider: string;\n /** Runtime environment in the sandbox */\n runtime: Runtime;\n /** Current status of the sandbox */\n status: SandboxStatus;\n /** When the sandbox was created */\n createdAt: Date;\n /** Execution timeout in milliseconds */\n timeout: number;\n /** Additional provider-specific metadata */\n metadata?: Record<string, any>;\n}\n\n/**\n * Options for creating a sandbox\n */\nexport interface CreateSandboxOptions {\n /** Runtime environment */\n runtime?: Runtime;\n /** Execution timeout in milliseconds */\n timeout?: number;\n /** Custom sandbox ID (if supported by provider) */\n sandboxId?: string;\n /** Template ID for sandbox creation (provider-specific) */\n templateId?: string;\n /** Additional metadata for the sandbox */\n metadata?: Record<string, any>;\n /** Domain for sandbox connection (provider-specific) */\n domain?: string;\n /** Environment variables for the sandbox */\n envs?: Record<string, string>;\n}\n\n/**\n * File system entry information\n */\nexport interface FileEntry {\n /** File/directory name */\n name: string;\n /** Full path to the entry */\n path: string;\n /** Whether this is a directory */\n isDirectory: boolean;\n /** File size in bytes (0 for directories) */\n size: number;\n /** Last modified timestamp */\n lastModified: Date;\n}\n\n/**\n * File system interface for sandbox operations\n */\nexport interface SandboxFileSystem {\n /** Read file contents */\n readFile(path: string): Promise<string>;\n /** Write file contents */\n writeFile(path: string, content: string): Promise<void>;\n /** Create directory */\n mkdir(path: string): Promise<void>;\n /** List directory contents */\n readdir(path: string): Promise<FileEntry[]>;\n /** Check if file/directory exists */\n exists(path: string): Promise<boolean>;\n /** Remove file or directory */\n remove(path: string): Promise<void>;\n}\n\n/**\n * Error thrown when a command exits with a non-zero status\n */\nexport class CommandExitError extends Error {\n name = 'CommandExitError';\n constructor(public result: {\n exitCode: number;\n stdout: string;\n stderr: string;\n error: boolean;\n }) {\n super(`Command exited with code ${result.exitCode}`);\n }\n}\n\n/**\n * Type guard to check if an error is a CommandExitError\n */\nexport function isCommandExitError(error: unknown): error is CommandExitError {\n return (\n typeof error === 'object' &&\n error !== null &&\n 'name' in error &&\n error.name === 'CommandExitError' &&\n 'result' in error\n );\n}\n\n\n\n\n\n/**\n * Base sandbox interface - what developers interact with\n */\nexport interface Sandbox<TSandbox = any> {\n /** Unique identifier for the sandbox */\n readonly sandboxId: string;\n /** Provider that created this sandbox */\n readonly provider: string;\n\n /** Execute code in the sandbox */\n runCode(code: string, runtime?: Runtime): Promise<ExecutionResult>;\n /** Execute shell commands */\n runCommand(command: string, args?: string[], options?: RunCommandOptions): Promise<ExecutionResult>;\n /** Get information about the sandbox */\n getInfo(): Promise<SandboxInfo>;\n /** Get URL for accessing the sandbox on a specific port */\n getUrl(options: { port: number; protocol?: string }): Promise<string>;\n /** Get the provider instance that created this sandbox */\n getProvider(): import('./provider').Provider<TSandbox>;\n /** Get the native provider sandbox instance with proper typing */\n getInstance(): TSandbox;\n /** Kill the sandbox */\n kill(): Promise<void>;\n /** Destroy the sandbox and clean up resources */\n destroy(): Promise<void>;\n\n /** File system operations */\n readonly filesystem: SandboxFileSystem;\n}\n\n/**\n * Extract the sandbox type from a provider\n */\ntype ExtractProviderSandboxType<TProvider extends Provider> = TProvider extends { readonly __sandboxType: infer TSandbox } ? TSandbox : any;\n\n/**\n * Typed sandbox interface that preserves the provider's native instance type\n */\nexport interface TypedSandbox<TProvider extends Provider> extends Omit<Sandbox<ExtractProviderSandboxType<TProvider>>, 'getProvider'> {\n /** Get the provider instance that created this sandbox with proper typing */\n getProvider(): TProvider;\n /** Get the native provider sandbox instance with proper typing */\n getInstance(): ExtractProviderSandboxType<TProvider>;\n}","/**\n * Compute Singleton - Main API Orchestrator\n * \n * Provides the unified compute.* API and delegates to specialized managers\n */\n\nimport type { ComputeAPI, CreateSandboxParams, CreateSandboxParamsWithOptionalProvider, ComputeConfig, Sandbox, Provider, TypedSandbox, TypedComputeAPI, ExtractSandboxInstanceType } from './types';\n\n/**\n * Compute singleton implementation - orchestrates all compute operations\n */\nclass ComputeManager implements ComputeAPI {\n private config: ComputeConfig | null = null;\n private typedState: { \n isTyped: boolean; \n provider: Provider | null; \n } = { isTyped: false, provider: null };\n\n /**\n * Set default configuration with generic type preservation\n */\n setConfig<TProvider extends Provider>(config: ComputeConfig<TProvider>): void {\n // Validate that at least one provider is specified\n if (!config.defaultProvider && !config.provider) {\n throw new Error('Either defaultProvider or provider must be specified in setConfig');\n }\n \n // Handle backwards compatibility: if both are provided, defaultProvider takes precedence\n if (config.defaultProvider && config.provider) {\n console.warn('Both defaultProvider and provider specified in setConfig. Using defaultProvider. The provider key is deprecated, please use defaultProvider instead.');\n }\n \n // Normalize config to always have both fields for internal use (backward compatibility)\n const actualProvider = config.defaultProvider || config.provider!;\n this.config = {\n provider: actualProvider,\n defaultProvider: actualProvider\n };\n\n // Store typed state for type-aware operations\n this.typedState = {\n isTyped: true,\n provider: actualProvider\n };\n }\n\n /**\n * Get current configuration\n */\n getConfig(): ComputeConfig | null {\n return this.config;\n }\n\n /**\n * Clear current configuration\n */\n clearConfig(): void {\n this.config = null;\n }\n\n /**\n * Get the default provider, throwing if not configured\n */\n private getDefaultProvider(): Provider {\n const provider = this.config?.defaultProvider || this.config?.provider;\n if (!provider) {\n throw new Error(\n 'No default provider configured. Either call compute.setConfig({ defaultProvider }) or pass provider explicitly.'\n );\n }\n return provider;\n }\n\n sandbox = {\n /**\n * Create a sandbox from a provider (or default provider if configured)\n * \n * @example\n * ```typescript\n * import { e2b } from '@computesdk/e2b'\n * import { compute } from 'computesdk'\n * \n * // With explicit provider\n * const sandbox = await compute.sandbox.create({\n * provider: e2b({ apiKey: 'your-key' })\n * })\n * \n * // With default provider (both forms work)\n * compute.setConfig({ defaultProvider: e2b({ apiKey: 'your-key' }) })\n * const sandbox1 = await compute.sandbox.create({})\n * const sandbox2 = await compute.sandbox.create()\n * ```\n */\n create: async (params?: CreateSandboxParams | CreateSandboxParamsWithOptionalProvider): Promise<Sandbox> => {\n const provider = params && 'provider' in params && params.provider ? params.provider : this.getDefaultProvider();\n const options = params?.options;\n const sandbox = await provider.sandbox.create(options);\n \n // If we have typed state and no explicit provider passed, cast to typed sandbox\n // This enables proper type inference for getInstance() when using default provider\n if (this.typedState.isTyped && (!params || !('provider' in params && params.provider))) {\n return sandbox as TypedSandbox<any>;\n }\n \n return sandbox;\n },\n\n /**\n * Get an existing sandbox by ID from a provider (or default provider if configured)\n */\n getById: async (providerOrSandboxId: Provider | string, sandboxId?: string): Promise<Sandbox | null> => {\n if (typeof providerOrSandboxId === 'string') {\n // Called with just sandboxId, use default provider\n const provider = this.getDefaultProvider();\n const sandbox = await provider.sandbox.getById(providerOrSandboxId);\n \n // If we have typed state, cast to typed sandbox for proper getInstance() typing\n if (this.typedState.isTyped && sandbox) {\n return sandbox as TypedSandbox<any>;\n }\n \n return sandbox;\n } else {\n // Called with provider and sandboxId\n if (!sandboxId) {\n throw new Error('sandboxId is required when provider is specified');\n }\n return await providerOrSandboxId.sandbox.getById(sandboxId);\n }\n },\n\n /**\n * List all active sandboxes from a provider (or default provider if configured)\n */\n list: async (provider?: Provider): Promise<Sandbox[]> => {\n const actualProvider = provider || this.getDefaultProvider();\n const sandboxes = await actualProvider.sandbox.list();\n \n // If we have typed state and no explicit provider passed, cast to typed sandboxes\n if (this.typedState.isTyped && !provider) {\n return sandboxes as TypedSandbox<any>[];\n }\n \n return sandboxes;\n },\n\n /**\n * Destroy a sandbox via a provider (or default provider if configured)\n */\n destroy: async (providerOrSandboxId: Provider | string, sandboxId?: string): Promise<void> => {\n if (typeof providerOrSandboxId === 'string') {\n // Called with just sandboxId, use default provider\n const provider = this.getDefaultProvider();\n return await provider.sandbox.destroy(providerOrSandboxId);\n } else {\n // Called with provider and sandboxId\n if (!sandboxId) {\n throw new Error('sandboxId is required when provider is specified');\n }\n return await providerOrSandboxId.sandbox.destroy(sandboxId);\n }\n }\n };\n\n // Future: compute.blob.*, compute.database.*, compute.git.* will be added here\n // blob = new BlobManager();\n // database = new DatabaseManager(); \n // git = new GitManager();\n\n\n}\n\n/**\n * Singleton instance - the main API (untyped)\n */\nexport const compute: ComputeAPI = new ComputeManager();\n\n\n\n/**\n * Create a compute instance with proper typing\n * \n * @example\n * ```typescript\n * import { e2b } from '@computesdk/e2b'\n * import { createCompute } from 'computesdk'\n * \n * const compute = createCompute({\n * defaultProvider: e2b({ apiKey: 'your-key' }),\n * });\n * \n * const sandbox = await compute.sandbox.create();\n * const instance = sandbox.getInstance(); // ✅ Properly typed E2B Sandbox!\n * ```\n */\nexport function createCompute<TProvider extends Provider>(config: ComputeConfig<TProvider>): TypedComputeAPI<TProvider> {\n const manager = new ComputeManager();\n \n // Set config directly without calling the public setConfig method\n const actualProvider = config.defaultProvider || config.provider!;\n manager['config'] = {\n provider: actualProvider,\n defaultProvider: actualProvider\n };\n manager['typedState'] = {\n isTyped: true,\n provider: actualProvider\n };\n \n return {\n setConfig: <T extends Provider>(cfg: ComputeConfig<T>) => createCompute(cfg),\n getConfig: () => manager.getConfig(),\n clearConfig: () => manager.clearConfig(),\n \n sandbox: {\n create: async (params?: Omit<CreateSandboxParamsWithOptionalProvider, 'provider'>) => {\n const sandbox = await manager.sandbox.create(params);\n // The sandbox should now have the correct getInstance typing from the generic Sandbox<TSandbox>\n return sandbox as TypedSandbox<TProvider>;\n },\n \n getById: async (sandboxId: string) => {\n const sandbox = await manager.sandbox.getById(sandboxId);\n return sandbox ? sandbox as TypedSandbox<TProvider> : null;\n },\n \n list: async () => {\n const sandboxes = await manager.sandbox.list();\n return sandboxes as TypedSandbox<TProvider>[];\n },\n \n destroy: async (sandboxId: string) => {\n return await manager.sandbox.destroy(sandboxId);\n }\n }\n } as TypedComputeAPI<TProvider>;\n}\n\n\n\n","/**\n * Simplified Request Handler for Web Framework Integration\n * \n * Handles JSON requests for sandbox and code execution operations.\n * Terminal support removed - will be re-added with WebSocket VM connections.\n */\n\nimport type { Provider, Runtime } from './types';\nimport { compute } from './compute';\n\n/**\n * Request structure supporting sandbox and code execution capabilities\n */\nexport interface ComputeRequest {\n /** Action in dot notation (e.g., 'compute.sandbox.create') */\n action: string;\n \n /** Parameters for the action */\n sandboxId?: string;\n code?: string;\n command?: string;\n args?: string[];\n runtime?: Runtime;\n path?: string;\n content?: string;\n \n /** Command options (for runCommand action) */\n commandOptions?: {\n background?: boolean;\n };\n \n /** Sandbox creation options */\n options?: {\n runtime?: Runtime;\n timeout?: number;\n sandboxId?: string;\n };\n}\n\n/**\n * Response structure for compute operations\n */\nexport interface ComputeResponse {\n success: boolean;\n error?: string;\n sandboxId: string;\n provider: string;\n [key: string]: any; // Allow any additional response data\n}\n\n/**\n * Execute compute action using targeted handling\n */\nasync function executeAction(body: ComputeRequest, provider: Provider): Promise<ComputeResponse> {\n try {\n const { action, sandboxId } = body;\n \n // Sandbox management operations\n if (action === 'compute.sandbox.create') {\n const sandbox = await compute.sandbox.create({\n provider,\n options: body.options || { runtime: 'python' }\n });\n return {\n success: true,\n sandboxId: sandbox.sandboxId,\n provider: provider.name\n };\n }\n \n if (action === 'compute.sandbox.list') {\n const sandboxes = await compute.sandbox.list(provider);\n return {\n success: true,\n sandboxId: '',\n provider: provider.name,\n sandboxes: sandboxes.map(sb => ({\n sandboxId: sb.sandboxId,\n provider: sb.provider\n }))\n };\n }\n \n if (action === 'compute.sandbox.destroy') {\n if (!sandboxId) {\n throw new Error('sandboxId is required for destroy action');\n }\n await compute.sandbox.destroy(provider, sandboxId);\n return {\n success: true,\n sandboxId,\n provider: provider.name\n };\n }\n \n // For sandbox instance methods, get the sandbox first\n if (!sandboxId) {\n throw new Error('sandboxId is required for this action');\n }\n \n const sandbox = await compute.sandbox.getById(provider, sandboxId);\n if (!sandbox) {\n throw new Error(`Sandbox ${sandboxId} not found`);\n }\n \n // Sandbox info\n if (action === 'compute.sandbox.getInfo') {\n const result = await sandbox.getInfo();\n return {\n success: true,\n sandboxId,\n provider: provider.name,\n info: {\n id: result.id,\n provider: result.provider,\n runtime: result.runtime,\n status: result.status,\n createdAt: result.createdAt.toISOString(),\n timeout: result.timeout,\n metadata: result.metadata\n }\n };\n }\n \n // Code execution\n if (action === 'compute.sandbox.runCode') {\n if (!body.code) throw new Error('code is required');\n const result = await sandbox.runCode(body.code, body.runtime);\n return {\n success: true,\n sandboxId,\n provider: provider.name,\n result: {\n stdout: result.stdout,\n stderr: result.stderr,\n exitCode: result.exitCode,\n executionTime: result.executionTime\n }\n };\n }\n \n if (action === 'compute.sandbox.runCommand') {\n if (!body.command) throw new Error('command is required');\n const result = await sandbox.runCommand(body.command, body.args, body.commandOptions);\n return {\n success: true,\n sandboxId,\n provider: provider.name,\n result: {\n stdout: result.stdout,\n stderr: result.stderr,\n exitCode: result.exitCode,\n executionTime: result.executionTime,\n ...(result.isBackground && { isBackground: result.isBackground }),\n ...(result.pid && { pid: result.pid })\n }\n };\n }\n \n // Filesystem operations\n if (action === 'compute.sandbox.filesystem.readFile') {\n if (!body.path) throw new Error('path is required');\n const result = await sandbox.filesystem.readFile(body.path);\n return {\n success: true,\n sandboxId,\n provider: provider.name,\n fileContent: result\n };\n }\n \n if (action === 'compute.sandbox.filesystem.writeFile') {\n if (!body.path) throw new Error('path is required');\n if (body.content === undefined) throw new Error('content is required');\n await sandbox.filesystem.writeFile(body.path, body.content);\n return { success: true, sandboxId, provider: provider.name };\n }\n \n if (action === 'compute.sandbox.filesystem.mkdir') {\n if (!body.path) throw new Error('path is required');\n await sandbox.filesystem.mkdir(body.path);\n return { success: true, sandboxId, provider: provider.name };\n }\n \n if (action === 'compute.sandbox.filesystem.readdir') {\n if (!body.path) throw new Error('path is required');\n const result = await sandbox.filesystem.readdir(body.path);\n return {\n success: true,\n sandboxId,\n provider: provider.name,\n files: result.map((entry: any) => ({\n name: entry.name,\n path: entry.path,\n isDirectory: entry.isDirectory,\n size: entry.size,\n lastModified: entry.lastModified.toISOString()\n }))\n };\n }\n \n if (action === 'compute.sandbox.filesystem.exists') {\n if (!body.path) throw new Error('path is required');\n const result = await sandbox.filesystem.exists(body.path);\n return {\n success: true,\n sandboxId,\n provider: provider.name,\n exists: result\n };\n }\n \n if (action === 'compute.sandbox.filesystem.remove') {\n if (!body.path) throw new Error('path is required');\n await sandbox.filesystem.remove(body.path);\n return { success: true, sandboxId, provider: provider.name };\n }\n \n throw new Error(`Unknown action: ${action}`);\n \n } catch (error) {\n return {\n success: false,\n error: error instanceof Error ? error.message : 'Unknown error occurred',\n sandboxId: body.sandboxId || '',\n provider: provider.name\n };\n }\n}\n\n/**\n * Main request handler - handles HTTP requests and pre-parsed bodies\n */\nexport async function handleComputeRequest(\n params: HandleComputeRequestParams\n): Promise<ComputeResponse>;\nexport async function handleComputeRequest(\n requestOrBody: Request | ComputeRequest,\n provider: Provider\n): Promise<Response>;\nexport async function handleComputeRequest(\n paramsOrRequestOrBody: HandleComputeRequestParams | Request | ComputeRequest,\n provider?: Provider\n): Promise<ComputeResponse | Response> {\n // Handle object-style API\n if (typeof paramsOrRequestOrBody === 'object' && 'request' in paramsOrRequestOrBody && 'provider' in paramsOrRequestOrBody) {\n const params = paramsOrRequestOrBody as HandleComputeRequestParams;\n return await executeAction(params.request, params.provider);\n }\n \n // Handle original API\n if (!provider) {\n throw new Error('Provider is required when not using object-style API');\n }\n \n const requestOrBody = paramsOrRequestOrBody as Request | ComputeRequest;\n try {\n let body: ComputeRequest;\n \n if (requestOrBody instanceof Request) {\n // Handle HTTP method validation\n if (requestOrBody.method !== 'POST') {\n return Response.json({\n success: false,\n error: 'Only POST requests are supported',\n sandboxId: '',\n provider: provider.name\n }, { status: 405 });\n }\n \n // Parse JSON body with better error handling\n try {\n body = await requestOrBody.json();\n } catch (parseError) {\n return Response.json({\n success: false,\n error: 'Invalid JSON in request body',\n sandboxId: '',\n provider: provider.name\n }, { status: 400 });\n }\n } else {\n body = requestOrBody;\n }\n \n // Execute the action\n const result = await executeAction(body, provider);\n \n return Response.json(result, {\n status: result.success ? 200 : 500\n });\n \n } catch (error) {\n return Response.json({\n success: false,\n error: error instanceof Error ? error.message : 'Request handling failed',\n sandboxId: '',\n provider: provider.name\n }, { status: 500 });\n }\n}\n\n/**\n * Legacy export for backward compatibility\n */\nexport interface HandleComputeRequestParams {\n request: ComputeRequest;\n provider: Provider;\n}\n\nexport { handleComputeRequest as handleHttpComputeRequest };","/**\n * Provider Factory - Creates providers from method definitions\n * \n * Eliminates boilerplate by auto-generating Provider/Sandbox classes\n * from simple method definitions with automatic feature detection.\n */\n\nimport type {\n Provider,\n ProviderSandboxManager,\n Sandbox,\n SandboxFileSystem,\n SandboxInfo,\n ExecutionResult,\n Runtime,\n CreateSandboxOptions,\n FileEntry,\n RunCommandOptions,\n} from './types/index.js';\n\n/**\n * Helper function to handle background command execution\n * Providers can use this to implement background job support\n */\nexport function createBackgroundCommand(command: string, args: string[] = [], options?: RunCommandOptions): { command: string; args: string[]; isBackground: boolean } {\n if (!options?.background) {\n return { command, args, isBackground: false };\n }\n\n // For background execution, we modify the command to run in background\n // Default approach: append & to make it run in background\n const fullCommand = args.length > 0 ? `${command} ${args.join(' ')}` : command;\n \n return {\n command: 'sh',\n args: ['-c', `${fullCommand} &`],\n isBackground: true\n };\n}\n\n/**\n * Flat sandbox method implementations - all operations in one place\n */\nexport interface SandboxMethods<TSandbox = any, TConfig = any> {\n // Collection operations (map to compute.sandbox.*)\n create: (config: TConfig, options?: CreateSandboxOptions) => Promise<{ sandbox: TSandbox; sandboxId: string }>;\n getById: (config: TConfig, sandboxId: string) => Promise<{ sandbox: TSandbox; sandboxId: string } | null>;\n list: (config: TConfig) => Promise<Array<{ sandbox: TSandbox; sandboxId: string }>>;\n destroy: (config: TConfig, sandboxId: string) => Promise<void>;\n \n // Instance operations (map to individual Sandbox methods)\n runCode: (sandbox: TSandbox, code: string, runtime?: Runtime, config?: TConfig) => Promise<ExecutionResult>;\n runCommand: (sandbox: TSandbox, command: string, args?: string[], options?: RunCommandOptions) => Promise<ExecutionResult>;\n getInfo: (sandbox: TSandbox) => Promise<SandboxInfo>;\n getUrl: (sandbox: TSandbox, options: { port: number; protocol?: string }) => Promise<string>;\n \n // Optional provider-specific typed getInstance method\n getInstance?: (sandbox: TSandbox) => TSandbox;\n \n // Optional filesystem methods\n filesystem?: {\n readFile: (sandbox: TSandbox, path: string, runCommand: (sandbox: TSandbox, command: string, args?: string[]) => Promise<ExecutionResult>) => Promise<string>;\n writeFile: (sandbox: TSandbox, path: string, content: string, runCommand: (sandbox: TSandbox, command: string, args?: string[]) => Promise<ExecutionResult>) => Promise<void>;\n mkdir: (sandbox: TSandbox, path: string, runCommand: (sandbox: TSandbox, command: string, args?: string[]) => Promise<ExecutionResult>) => Promise<void>;\n readdir: (sandbox: TSandbox, path: string, runCommand: (sandbox: TSandbox, command: string, args?: string[]) => Promise<ExecutionResult>) => Promise<FileEntry[]>;\n exists: (sandbox: TSandbox, path: string, runCommand: (sandbox: TSandbox, command: string, args?: string[]) => Promise<ExecutionResult>) => Promise<boolean>;\n remove: (sandbox: TSandbox, path: string, runCommand: (sandbox: TSandbox, command: string, args?: string[]) => Promise<ExecutionResult>) => Promise<void>;\n };\n \n\n}\n\n/**\n * Provider configuration for createProvider()\n */\nexport interface ProviderConfig<TSandbox = any, TConfig = any> {\n name: string;\n methods: {\n sandbox: SandboxMethods<TSandbox, TConfig>;\n };\n}\n\n/**\n * Default filesystem implementations based on shell commands\n * These work for any provider that supports shell command execution\n */\nconst defaultFilesystemMethods = {\n readFile: async (sandbox: any, path: string, runCommand: (sandbox: any, command: string, args?: string[]) => Promise<ExecutionResult>): Promise<string> => {\n const result = await runCommand(sandbox, 'cat', [path]);\n if (result.exitCode !== 0) {\n throw new Error(`Failed to read file ${path}: ${result.stderr}`);\n }\n // Trim trailing newline that cat command adds\n return result.stdout.replace(/\\n$/, '');\n },\n\n writeFile: async (sandbox: any, path: string, content: string, runCommand: (sandbox: any, command: string, args?: string[]) => Promise<ExecutionResult>): Promise<void> => {\n const result = await runCommand(sandbox, 'sh', ['-c', `echo ${JSON.stringify(content)} > ${JSON.stringify(path)}`]);\n if (result.exitCode !== 0) {\n throw new Error(`Failed to write file ${path}: ${result.stderr}`);\n }\n },\n\n mkdir: async (sandbox: any, path: string, runCommand: (sandbox: any, command: string, args?: string[]) => Promise<ExecutionResult>): Promise<void> => {\n const result = await runCommand(sandbox, 'mkdir', ['-p', path]);\n if (result.exitCode !== 0) {\n throw new Error(`Failed to create directory ${path}: ${result.stderr}`);\n }\n },\n\n readdir: async (sandbox: any, path: string, runCommand: (sandbox: any, command: string, args?: string[]) => Promise<ExecutionResult>): Promise<FileEntry[]> => {\n // Try different ls variations for maximum compatibility\n let result = await runCommand(sandbox, 'ls', ['-la', path]);\n let hasDetailedOutput = true;\n \n // Fall back to basic ls if detailed flags not supported\n if (result.exitCode !== 0) {\n result = await runCommand(sandbox, 'ls', ['-l', path]);\n }\n if (result.exitCode !== 0) {\n result = await runCommand(sandbox, 'ls', [path]);\n hasDetailedOutput = false;\n }\n \n if (result.exitCode !== 0) {\n throw new Error(`Failed to list directory ${path}: ${result.stderr}`);\n }\n\n const lines = (result.stdout || '').split('\\n').filter((line: string) => line.trim() && !line.startsWith('total'));\n\n return lines.map((line: string) => {\n if (hasDetailedOutput && line.includes(' ')) {\n // Parse detailed ls output (ls -la or ls -l)\n const parts = line.trim().split(/\\s+/);\n const name = parts[parts.length - 1];\n const isDirectory = line.startsWith('d');\n \n return {\n name,\n path: `${path}/${name}`,\n isDirectory,\n size: parseInt(parts[4]) || 0,\n lastModified: new Date()\n };\n } else {\n // Parse simple ls output (just filenames)\n const name = line.trim();\n return {\n name,\n path: `${path}/${name}`,\n isDirectory: false, // Can't determine from simple ls\n size: 0,\n lastModified: new Date()\n };\n }\n });\n },\n\n exists: async (sandbox: any, path: string, runCommand: (sandbox: any, command: string, args?: string[]) => Promise<ExecutionResult>): Promise<boolean> => {\n const result = await runCommand(sandbox, 'test', ['-e', path]);\n return result.exitCode === 0; // Exit code 0 means file exists\n },\n\n remove: async (sandbox: any, path: string, runCommand: (sandbox: any, command: string, args?: string[]) => Promise<ExecutionResult>): Promise<void> => {\n const result = await runCommand(sandbox, 'rm', ['-rf', path]);\n if (result.exitCode !== 0) {\n throw new Error(`Failed to remove ${path}: ${result.stderr}`);\n }\n }\n};\n\n/**\n * Auto-generated filesystem implementation that throws \"not supported\" errors\n */\nclass UnsupportedFileSystem implements SandboxFileSystem {\n private readonly providerName: string;\n\n constructor(providerName: string) {\n this.providerName = providerName;\n }\n\n async readFile(_path: string): Promise<string> {\n throw new Error(`Filesystem operations are not supported by ${this.providerName}'s sandbox environment. ${this.providerName} sandboxes are designed for code execution only.`);\n }\n\n async writeFile(_path: string, _content: string): Promise<void> {\n throw new Error(`Filesystem operations are not supported by ${this.providerName}'s sandbox environment. ${this.providerName} sandboxes are designed for code execution only.`);\n }\n\n async mkdir(_path: string): Promise<void> {\n throw new Error(`Filesystem operations are not supported by ${this.providerName}'s sandbox environment. ${this.providerName} sandboxes are designed for code execution only.`);\n }\n\n async readdir(_path: string): Promise<FileEntry[]> {\n throw new Error(`Filesystem operations are not supported by ${this.providerName}'s sandbox environment. ${this.providerName} sandboxes are designed for code execution only.`);\n }\n\n async exists(_path: string): Promise<boolean> {\n throw new Error(`Filesystem operations are not supported by ${this.providerName}'s sandbox environment. ${this.providerName} sandboxes are designed for code execution only.`);\n }\n\n async remove(_path: string): Promise<void> {\n throw new Error(`Filesystem operations are not supported by ${this.providerName}'s sandbox environment. ${this.providerName} sandboxes are designed for code execution only.`);\n }\n}\n\n\n\n/**\n * Auto-generated filesystem implementation that wraps provider methods\n */\nclass SupportedFileSystem<TSandbox> implements SandboxFileSystem {\n constructor(\n private sandbox: TSandbox,\n private methods: NonNullable<SandboxMethods<TSandbox>['filesystem']>,\n private allMethods: SandboxMethods<TSandbox>\n ) {}\n\n async readFile(path: string): Promise<string> {\n return this.methods.readFile(this.sandbox, path, this.allMethods.runCommand);\n }\n\n async writeFile(path: string, content: string): Promise<void> {\n return this.methods.writeFile(this.sandbox, path, content, this.allMethods.runCommand);\n }\n\n async mkdir(path: string): Promise<void> {\n return this.methods.mkdir(this.sandbox, path, this.allMethods.runCommand);\n }\n\n async readdir(path: string): Promise<FileEntry[]> {\n return this.methods.readdir(this.sandbox, path, this.allMethods.runCommand);\n }\n\n async exists(path: string): Promise<boolean> {\n return this.methods.exists(this.sandbox, path, this.allMethods.runCommand);\n }\n\n async remove(path: string): Promise<void> {\n return this.methods.remove(this.sandbox, path, this.allMethods.runCommand);\n }\n}\n\n\n\n\n\n/**\n * Generated sandbox class - implements the Sandbox interface\n */\nclass GeneratedSandbox<TSandbox = any> implements Sandbox<TSandbox> {\n readonly sandboxId: string;\n readonly provider: string;\n readonly filesystem: SandboxFileSystem;\n\n constructor(\n private sandbox: TSandbox,\n sandboxId: string,\n providerName: string,\n private methods: SandboxMethods<TSandbox>,\n private config: any,\n private destroyMethod: (config: any, sandboxId: string) => Promise<void>,\n private providerInstance: Provider\n ) {\n this.sandboxId = sandboxId;\n this.provider = providerName;\n\n // Auto-detect filesystem support\n if (methods.filesystem) {\n this.filesystem = new SupportedFileSystem(sandbox, methods.filesystem, methods);\n } else {\n this.filesystem = new UnsupportedFileSystem(providerName);\n }\n }\n\n getInstance(): TSandbox {\n // Use provider-specific typed getInstance if available\n if (this.methods.getInstance) {\n return this.methods.getInstance(this.sandbox);\n }\n // Fallback to returning the sandbox directly\n return this.sandbox;\n }\n\n async runCode(code: string, runtime?: Runtime): Promise<ExecutionResult> {\n return await this.methods.runCode(this.sandbox, code, runtime, this.config);\n }\n\n async runCommand(command: string, args?: string[], options?: RunCommandOptions): Promise<ExecutionResult> {\n return await this.methods.runCommand(this.sandbox, command, args, options);\n }\n\n async getInfo(): Promise<SandboxInfo> {\n return await this.methods.getInfo(this.sandbox);\n }\n\n async getUrl(options: { port: number; protocol?: string }): Promise<string> {\n return await this.methods.getUrl(this.sandbox, options);\n }\n\n getProvider(): Provider<TSandbox> {\n return this.providerInstance;\n }\n\n async kill(): Promise<void> {\n // For backward compatibility, kill() delegates to destroy()\n await this.destroy();\n }\n\n async destroy(): Promise<void> {\n // Destroy via the provider's destroy method using our sandboxId\n await this.destroyMethod(this.config, this.sandboxId);\n }\n}\n\n/**\n * Auto-generated Sandbox Manager implementation\n */\nclass GeneratedSandboxManager<TSandbox, TConfig> implements ProviderSandboxManager<TSandbox> {\n private activeSandboxes: Map<string, GeneratedSandbox<TSandbox>> = new Map();\n\n constructor(\n private config: TConfig,\n private providerName: string,\n private methods: SandboxMethods<TSandbox, TConfig>,\n private providerInstance: Provider\n ) {}\n\n async create(options?: CreateSandboxOptions): Promise<Sandbox<TSandbox>> {\n const result = await this.methods.create(this.config, options);\n const sandbox = new GeneratedSandbox<TSandbox>(\n result.sandbox,\n result.sandboxId,\n this.providerName,\n this.methods,\n this.config,\n this.methods.destroy,\n this.providerInstance\n );\n \n this.activeSandboxes.set(result.sandboxId, sandbox);\n return sandbox;\n }\n\n async getById(sandboxId: string): Promise<Sandbox<TSandbox> | null> {\n // Check active sandboxes first\n const existing = this.activeSandboxes.get(sandboxId);\n if (existing) {\n return existing;\n }\n\n // Try to reconnect\n const result = await this.methods.getById(this.config, sandboxId);\n if (!result) {\n return null;\n }\n\n const sandbox = new GeneratedSandbox<TSandbox>(\n result.sandbox,\n result.sandboxId,\n this.providerName,\n this.methods,\n this.config,\n this.methods.destroy,\n this.providerInstance\n );\n \n this.activeSandboxes.set(result.sandboxId, sandbox);\n return sandbox;\n }\n\n async list(): Promise<Sandbox<TSandbox>[]> {\n const results = await this.methods.list(this.config);\n const sandboxes: Sandbox[] = [];\n\n for (const result of results) {\n let sandbox = this.activeSandboxes.get(result.sandboxId);\n if (!sandbox) {\n sandbox = new GeneratedSandbox<TSandbox>(\n result.sandbox,\n result.sandboxId,\n this.providerName,\n this.methods,\n this.config,\n this.methods.destroy,\n this.providerInstance\n );\n this.activeSandboxes.set(result.sandboxId, sandbox);\n }\n sandboxes.push(sandbox);\n }\n\n return sandboxes;\n }\n\n async destroy(sandboxId: string): Promise<void> {\n await this.methods.destroy(this.config, sandboxId);\n this.activeSandboxes.delete(sandboxId);\n }\n}\n\n/**\n * Auto-generated Provider implementation\n */\nclass GeneratedProvider<TSandbox, TConfig> implements Provider<TSandbox> {\n readonly name: string;\n readonly sandbox: ProviderSandboxManager<TSandbox>;\n readonly __sandboxType!: TSandbox; // Phantom type for TypeScript inference\n\n constructor(config: TConfig, providerConfig: ProviderConfig<TSandbox, TConfig>) {\n this.name = providerConfig.name;\n this.sandbox = new GeneratedSandboxManager(\n config,\n providerConfig.name,\n providerConfig.methods.sandbox,\n this\n );\n }\n}\n\n/**\n * Create a provider from method definitions\n * \n * Auto-generates all boilerplate classes and provides feature detection\n * based on which methods are implemented.\n */\nexport function createProvider<TSandbox, TConfig>(\n providerConfig: ProviderConfig<TSandbox, TConfig>\n): (config: TConfig) => Provider<TSandbox> {\n // Auto-inject default filesystem methods if none provided\n if (!providerConfig.methods.sandbox.filesystem) {\n providerConfig.methods.sandbox.filesystem = defaultFilesystemMethods;\n }\n\n return (config: TConfig) => {\n return new GeneratedProvider(config, providerConfig);\n };\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACwJO,IAAM,mBAAN,cAA+B,MAAM;AAAA,EAE1C,YAAmB,QAKhB;AACD,UAAM,4BAA4B,OAAO,QAAQ,EAAE;AANlC;AADnB,gBAAO;AAAA,EAQP;AACF;AAKO,SAAS,mBAAmB,OAA2C;AAC5E,SACE,OAAO,UAAU,YACjB,UAAU,QACV,UAAU,SACV,MAAM,SAAS,sBACf,YAAY;AAEhB;;;ACpKA,IAAM,iBAAN,MAA2C;AAAA,EAA3C;AACE,SAAQ,SAA+B;AACvC,SAAQ,aAGJ,EAAE,SAAS,OAAO,UAAU,KAAK;AAyDrC,mBAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAoBR,QAAQ,OAAO,WAA6F;AAC1G,cAAM,WAAW,UAAU,cAAc,UAAU,OAAO,WAAW,OAAO,WAAW,KAAK,mBAAmB;AAC/G,cAAM,UAAU,QAAQ;AACxB,cAAM,UAAU,MAAM,SAAS,QAAQ,OAAO,OAAO;AAIrD,YAAI,KAAK,WAAW,YAAY,CAAC,UAAU,EAAE,cAAc,UAAU,OAAO,YAAY;AACtF,iBAAO;AAAA,QACT;AAEA,eAAO;AAAA,MACT;AAAA;AAAA;AAAA;AAAA,MAKA,SAAS,OAAO,qBAAwC,cAAgD;AACtG,YAAI,OAAO,wBAAwB,UAAU;AAE3C,gBAAM,WAAW,KAAK,mBAAmB;AACzC,gBAAM,UAAU,MAAM,SAAS,QAAQ,QAAQ,mBAAmB;AAGlE,cAAI,KAAK,WAAW,WAAW,SAAS;AACtC,mBAAO;AAAA,UACT;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QAAQ,cAAc;AAAA,EACrD;AACF;","names":["sandbox"]}
|
package/dist/index.mjs
CHANGED
|
@@ -620,6 +620,7 @@ var GeneratedSandboxManager = class {
|
|
|
620
620
|
}
|
|
621
621
|
};
|
|
622
622
|
var GeneratedProvider = class {
|
|
623
|
+
// Phantom type for TypeScript inference
|
|
623
624
|
constructor(config, providerConfig) {
|
|
624
625
|
this.name = providerConfig.name;
|
|
625
626
|
this.sandbox = new GeneratedSandboxManager(
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types/sandbox.ts","../src/compute.ts","../src/request-handler.ts","../src/factory.ts"],"sourcesContent":["/**\n * Sandbox Types\n * \n * Types related to sandbox execution, filesystem, terminal operations\n */\n\n// Forward declaration to avoid circular dependency\ninterface Provider {\n readonly name: string;\n readonly sandbox: any; // Will be properly typed when imported together\n}\n\n/**\n * Utility type to extract the native instance type from a provider\n * This enables proper typing for getInstance() calls by looking at the provider's internal types\n */\nexport type ExtractSandboxInstanceType<TProvider extends Provider> = TProvider extends Provider ? \n TProvider extends { \n sandbox: { \n create(): Promise<infer TSandbox> \n } \n } ? (\n TSandbox extends { getInstance(): infer TInstance } \n ? TInstance \n : any\n ) : any : any;\n\n/**\n * Supported runtime environments\n */\nexport type Runtime = 'node' | 'python';\n\n/**\n * Sandbox status types\n */\nexport type SandboxStatus = 'running' | 'stopped' | 'error';\n\n/**\n * Options for running commands\n */\nexport interface RunCommandOptions {\n /** Run command in background (non-blocking) */\n background?: boolean;\n}\n\n/**\n * Result of code execution\n */\nexport interface ExecutionResult {\n /** Standard output from the execution */\n stdout: string;\n /** Standard error from the execution */\n stderr: string;\n /** Exit code from the execution */\n exitCode: number;\n /** Time taken for execution in milliseconds */\n executionTime: number;\n /** ID of the sandbox where the code was executed */\n sandboxId: string;\n /** Provider that executed the code */\n provider: string;\n /** Process ID for background jobs (if applicable) */\n pid?: number;\n /** Whether this command is running in background */\n isBackground?: boolean;\n}\n\n/**\n * Information about a sandbox\n */\nexport interface SandboxInfo {\n /** Unique identifier for the sandbox */\n id: string;\n /** Provider hosting the sandbox */\n provider: string;\n /** Runtime environment in the sandbox */\n runtime: Runtime;\n /** Current status of the sandbox */\n status: SandboxStatus;\n /** When the sandbox was created */\n createdAt: Date;\n /** Execution timeout in milliseconds */\n timeout: number;\n /** Additional provider-specific metadata */\n metadata?: Record<string, any>;\n}\n\n/**\n * Options for creating a sandbox\n */\nexport interface CreateSandboxOptions {\n /** Runtime environment */\n runtime?: Runtime;\n /** Execution timeout in milliseconds */\n timeout?: number;\n /** Custom sandbox ID (if supported by provider) */\n sandboxId?: string;\n /** Template ID for sandbox creation (provider-specific) */\n templateId?: string;\n /** Additional metadata for the sandbox */\n metadata?: Record<string, any>;\n /** Domain for sandbox connection (provider-specific) */\n domain?: string;\n /** Environment variables for the sandbox */\n envs?: Record<string, string>;\n}\n\n/**\n * File system entry information\n */\nexport interface FileEntry {\n /** File/directory name */\n name: string;\n /** Full path to the entry */\n path: string;\n /** Whether this is a directory */\n isDirectory: boolean;\n /** File size in bytes (0 for directories) */\n size: number;\n /** Last modified timestamp */\n lastModified: Date;\n}\n\n/**\n * File system interface for sandbox operations\n */\nexport interface SandboxFileSystem {\n /** Read file contents */\n readFile(path: string): Promise<string>;\n /** Write file contents */\n writeFile(path: string, content: string): Promise<void>;\n /** Create directory */\n mkdir(path: string): Promise<void>;\n /** List directory contents */\n readdir(path: string): Promise<FileEntry[]>;\n /** Check if file/directory exists */\n exists(path: string): Promise<boolean>;\n /** Remove file or directory */\n remove(path: string): Promise<void>;\n}\n\n/**\n * Error thrown when a command exits with a non-zero status\n */\nexport class CommandExitError extends Error {\n name = 'CommandExitError';\n constructor(public result: {\n exitCode: number;\n stdout: string;\n stderr: string;\n error: boolean;\n }) {\n super(`Command exited with code ${result.exitCode}`);\n }\n}\n\n/**\n * Type guard to check if an error is a CommandExitError\n */\nexport function isCommandExitError(error: unknown): error is CommandExitError {\n return (\n typeof error === 'object' &&\n error !== null &&\n 'name' in error &&\n error.name === 'CommandExitError' &&\n 'result' in error\n );\n}\n\n\n\n\n\n/**\n * Base sandbox interface - what developers interact with\n */\nexport interface Sandbox {\n /** Unique identifier for the sandbox */\n readonly sandboxId: string;\n /** Provider that created this sandbox */\n readonly provider: string;\n\n /** Execute code in the sandbox */\n runCode(code: string, runtime?: Runtime): Promise<ExecutionResult>;\n /** Execute shell commands */\n runCommand(command: string, args?: string[], options?: RunCommandOptions): Promise<ExecutionResult>;\n /** Get information about the sandbox */\n getInfo(): Promise<SandboxInfo>;\n /** Get URL for accessing the sandbox on a specific port */\n getUrl(options: { port: number; protocol?: string }): Promise<string>;\n /** Get the provider instance that created this sandbox */\n getProvider(): Provider;\n /** Get the native provider sandbox instance with proper typing */\n getInstance<T = any>(): T;\n /** Kill the sandbox */\n kill(): Promise<void>;\n /** Destroy the sandbox and clean up resources */\n destroy(): Promise<void>;\n\n /** File system operations */\n readonly filesystem: SandboxFileSystem;\n}\n\n/**\n * Typed sandbox interface that preserves the provider's native instance type\n */\nexport interface TypedSandbox<TProvider extends Provider> extends Sandbox {\n /** Get the provider instance that created this sandbox with proper typing */\n getProvider(): TProvider;\n /** Get the native provider sandbox instance with proper typing */\n getInstance(): ExtractSandboxInstanceType<TProvider>;\n getInstance<T>(): T;\n}","/**\n * Compute Singleton - Main API Orchestrator\n * \n * Provides the unified compute.* API and delegates to specialized managers\n */\n\nimport type { ComputeAPI, CreateSandboxParams, CreateSandboxParamsWithOptionalProvider, ComputeConfig, Sandbox, Provider, TypedSandbox, TypedComputeAPI } from './types';\n\n/**\n * Compute singleton implementation - orchestrates all compute operations\n */\nclass ComputeManager implements ComputeAPI {\n private config: ComputeConfig | null = null;\n private typedState: { \n isTyped: boolean; \n provider: Provider | null; \n } = { isTyped: false, provider: null };\n\n /**\n * Set default configuration with generic type preservation\n */\n setConfig<TProvider extends Provider>(config: ComputeConfig<TProvider>): void {\n // Validate that at least one provider is specified\n if (!config.defaultProvider && !config.provider) {\n throw new Error('Either defaultProvider or provider must be specified in setConfig');\n }\n \n // Handle backwards compatibility: if both are provided, defaultProvider takes precedence\n if (config.defaultProvider && config.provider) {\n console.warn('Both defaultProvider and provider specified in setConfig. Using defaultProvider. The provider key is deprecated, please use defaultProvider instead.');\n }\n \n // Normalize config to always have both fields for internal use (backward compatibility)\n const actualProvider = config.defaultProvider || config.provider!;\n this.config = {\n provider: actualProvider,\n defaultProvider: actualProvider\n };\n\n // Store typed state for type-aware operations\n this.typedState = {\n isTyped: true,\n provider: actualProvider\n };\n }\n\n /**\n * Get current configuration\n */\n getConfig(): ComputeConfig | null {\n return this.config;\n }\n\n /**\n * Clear current configuration\n */\n clearConfig(): void {\n this.config = null;\n }\n\n /**\n * Get the default provider, throwing if not configured\n */\n private getDefaultProvider(): Provider {\n const provider = this.config?.defaultProvider || this.config?.provider;\n if (!provider) {\n throw new Error(\n 'No default provider configured. Either call compute.setConfig({ defaultProvider }) or pass provider explicitly.'\n );\n }\n return provider;\n }\n\n sandbox = {\n /**\n * Create a sandbox from a provider (or default provider if configured)\n * \n * @example\n * ```typescript\n * import { e2b } from '@computesdk/e2b'\n * import { compute } from 'computesdk'\n * \n * // With explicit provider\n * const sandbox = await compute.sandbox.create({\n * provider: e2b({ apiKey: 'your-key' })\n * })\n * \n * // With default provider (both forms work)\n * compute.setConfig({ defaultProvider: e2b({ apiKey: 'your-key' }) })\n * const sandbox1 = await compute.sandbox.create({})\n * const sandbox2 = await compute.sandbox.create()\n * ```\n */\n create: async (params?: CreateSandboxParams | CreateSandboxParamsWithOptionalProvider): Promise<Sandbox> => {\n const provider = params && 'provider' in params && params.provider ? params.provider : this.getDefaultProvider();\n const options = params?.options;\n const sandbox = await provider.sandbox.create(options);\n \n // If we have typed state and no explicit provider passed, cast to typed sandbox\n // This enables proper type inference for getInstance() when using default provider\n if (this.typedState.isTyped && (!params || !('provider' in params && params.provider))) {\n return sandbox as TypedSandbox<any>;\n }\n \n return sandbox;\n },\n\n /**\n * Get an existing sandbox by ID from a provider (or default provider if configured)\n */\n getById: async (providerOrSandboxId: Provider | string, sandboxId?: string): Promise<Sandbox | null> => {\n if (typeof providerOrSandboxId === 'string') {\n // Called with just sandboxId, use default provider\n const provider = this.getDefaultProvider();\n const sandbox = await provider.sandbox.getById(providerOrSandboxId);\n \n // If we have typed state, cast to typed sandbox for proper getInstance() typing\n if (this.typedState.isTyped && sandbox) {\n return sandbox as TypedSandbox<any>;\n }\n \n return sandbox;\n } else {\n // Called with provider and sandboxId\n if (!sandboxId) {\n throw new Error('sandboxId is required when provider is specified');\n }\n return await providerOrSandboxId.sandbox.getById(sandboxId);\n }\n },\n\n /**\n * List all active sandboxes from a provider (or default provider if configured)\n */\n list: async (provider?: Provider): Promise<Sandbox[]> => {\n const actualProvider = provider || this.getDefaultProvider();\n const sandboxes = await actualProvider.sandbox.list();\n \n // If we have typed state and no explicit provider passed, cast to typed sandboxes\n if (this.typedState.isTyped && !provider) {\n return sandboxes as TypedSandbox<any>[];\n }\n \n return sandboxes;\n },\n\n /**\n * Destroy a sandbox via a provider (or default provider if configured)\n */\n destroy: async (providerOrSandboxId: Provider | string, sandboxId?: string): Promise<void> => {\n if (typeof providerOrSandboxId === 'string') {\n // Called with just sandboxId, use default provider\n const provider = this.getDefaultProvider();\n return await provider.sandbox.destroy(providerOrSandboxId);\n } else {\n // Called with provider and sandboxId\n if (!sandboxId) {\n throw new Error('sandboxId is required when provider is specified');\n }\n return await providerOrSandboxId.sandbox.destroy(sandboxId);\n }\n }\n };\n\n // Future: compute.blob.*, compute.database.*, compute.git.* will be added here\n // blob = new BlobManager();\n // database = new DatabaseManager(); \n // git = new GitManager();\n\n\n}\n\n/**\n * Singleton instance - the main API (untyped)\n */\nexport const compute: ComputeAPI = new ComputeManager();\n\n/**\n * Create a compute instance with proper typing\n * This enables proper type inference for getInstance() calls\n * \n * @example\n * ```typescript\n * import { e2b } from '@computesdk/e2b'\n * import { createCompute } from 'computesdk'\n * \n * const compute = createCompute({\n * defaultProvider: e2b({ apiKey: 'your-key' }),\n * });\n * \n * const sandbox = await compute.sandbox.create();\n * const instance = sandbox.getInstance(); // ✅ Properly typed!\n * ```\n */\nexport function createCompute<TProvider extends Provider>(config: ComputeConfig<TProvider>): TypedComputeAPI<TProvider> {\n const manager = new ComputeManager();\n \n // Set config directly without calling the public setConfig method\n const actualProvider = config.defaultProvider || config.provider!;\n manager['config'] = {\n provider: actualProvider,\n defaultProvider: actualProvider\n };\n manager['typedState'] = {\n isTyped: true,\n provider: actualProvider\n };\n \n return {\n setConfig: <T extends Provider>(cfg: ComputeConfig<T>) => createCompute(cfg),\n getConfig: () => manager.getConfig(),\n clearConfig: () => manager.clearConfig(),\n \n sandbox: {\n create: async (params?: Omit<CreateSandboxParamsWithOptionalProvider, 'provider'>) => {\n const sandbox = await manager.sandbox.create(params);\n return sandbox as TypedSandbox<TProvider>;\n },\n \n getById: async (sandboxId: string) => {\n const sandbox = await manager.sandbox.getById(sandboxId);\n return sandbox ? sandbox as TypedSandbox<TProvider> : null;\n },\n \n list: async () => {\n const sandboxes = await manager.sandbox.list();\n return sandboxes as TypedSandbox<TProvider>[];\n },\n \n destroy: async (sandboxId: string) => {\n return await manager.sandbox.destroy(sandboxId);\n }\n }\n } as TypedComputeAPI<TProvider>;\n}\n\n\n\n","/**\n * Simplified Request Handler for Web Framework Integration\n * \n * Handles JSON requests for sandbox and code execution operations.\n * Terminal support removed - will be re-added with WebSocket VM connections.\n */\n\nimport type { Provider, Runtime } from './types';\nimport { compute } from './compute';\n\n/**\n * Request structure supporting sandbox and code execution capabilities\n */\nexport interface ComputeRequest {\n /** Action in dot notation (e.g., 'compute.sandbox.create') */\n action: string;\n \n /** Parameters for the action */\n sandboxId?: string;\n code?: string;\n command?: string;\n args?: string[];\n runtime?: Runtime;\n path?: string;\n content?: string;\n \n /** Command options (for runCommand action) */\n commandOptions?: {\n background?: boolean;\n };\n \n /** Sandbox creation options */\n options?: {\n runtime?: Runtime;\n timeout?: number;\n sandboxId?: string;\n };\n}\n\n/**\n * Response structure for compute operations\n */\nexport interface ComputeResponse {\n success: boolean;\n error?: string;\n sandboxId: string;\n provider: string;\n [key: string]: any; // Allow any additional response data\n}\n\n/**\n * Execute compute action using targeted handling\n */\nasync function executeAction(body: ComputeRequest, provider: Provider): Promise<ComputeResponse> {\n try {\n const { action, sandboxId } = body;\n \n // Sandbox management operations\n if (action === 'compute.sandbox.create') {\n const sandbox = await compute.sandbox.create({\n provider,\n options: body.options || { runtime: 'python' }\n });\n return {\n success: true,\n sandboxId: sandbox.sandboxId,\n provider: provider.name\n };\n }\n \n if (action === 'compute.sandbox.list') {\n const sandboxes = await compute.sandbox.list(provider);\n return {\n success: true,\n sandboxId: '',\n provider: provider.name,\n sandboxes: sandboxes.map(sb => ({\n sandboxId: sb.sandboxId,\n provider: sb.provider\n }))\n };\n }\n \n if (action === 'compute.sandbox.destroy') {\n if (!sandboxId) {\n throw new Error('sandboxId is required for destroy action');\n }\n await compute.sandbox.destroy(provider, sandboxId);\n return {\n success: true,\n sandboxId,\n provider: provider.name\n };\n }\n \n // For sandbox instance methods, get the sandbox first\n if (!sandboxId) {\n throw new Error('sandboxId is required for this action');\n }\n \n const sandbox = await compute.sandbox.getById(provider, sandboxId);\n if (!sandbox) {\n throw new Error(`Sandbox ${sandboxId} not found`);\n }\n \n // Sandbox info\n if (action === 'compute.sandbox.getInfo') {\n const result = await sandbox.getInfo();\n return {\n success: true,\n sandboxId,\n provider: provider.name,\n info: {\n id: result.id,\n provider: result.provider,\n runtime: result.runtime,\n status: result.status,\n createdAt: result.createdAt.toISOString(),\n timeout: result.timeout,\n metadata: result.metadata\n }\n };\n }\n \n // Code execution\n if (action === 'compute.sandbox.runCode') {\n if (!body.code) throw new Error('code is required');\n const result = await sandbox.runCode(body.code, body.runtime);\n return {\n success: true,\n sandboxId,\n provider: provider.name,\n result: {\n stdout: result.stdout,\n stderr: result.stderr,\n exitCode: result.exitCode,\n executionTime: result.executionTime\n }\n };\n }\n \n if (action === 'compute.sandbox.runCommand') {\n if (!body.command) throw new Error('command is required');\n const result = await sandbox.runCommand(body.command, body.args, body.commandOptions);\n return {\n success: true,\n sandboxId,\n provider: provider.name,\n result: {\n stdout: result.stdout,\n stderr: result.stderr,\n exitCode: result.exitCode,\n executionTime: result.executionTime,\n ...(result.isBackground && { isBackground: result.isBackground }),\n ...(result.pid && { pid: result.pid })\n }\n };\n }\n \n // Filesystem operations\n if (action === 'compute.sandbox.filesystem.readFile') {\n if (!body.path) throw new Error('path is required');\n const result = await sandbox.filesystem.readFile(body.path);\n return {\n success: true,\n sandboxId,\n provider: provider.name,\n fileContent: result\n };\n }\n \n if (action === 'compute.sandbox.filesystem.writeFile') {\n if (!body.path) throw new Error('path is required');\n if (body.content === undefined) throw new Error('content is required');\n await sandbox.filesystem.writeFile(body.path, body.content);\n return { success: true, sandboxId, provider: provider.name };\n }\n \n if (action === 'compute.sandbox.filesystem.mkdir') {\n if (!body.path) throw new Error('path is required');\n await sandbox.filesystem.mkdir(body.path);\n return { success: true, sandboxId, provider: provider.name };\n }\n \n if (action === 'compute.sandbox.filesystem.readdir') {\n if (!body.path) throw new Error('path is required');\n const result = await sandbox.filesystem.readdir(body.path);\n return {\n success: true,\n sandboxId,\n provider: provider.name,\n files: result.map((entry: any) => ({\n name: entry.name,\n path: entry.path,\n isDirectory: entry.isDirectory,\n size: entry.size,\n lastModified: entry.lastModified.toISOString()\n }))\n };\n }\n \n if (action === 'compute.sandbox.filesystem.exists') {\n if (!body.path) throw new Error('path is required');\n const result = await sandbox.filesystem.exists(body.path);\n return {\n success: true,\n sandboxId,\n provider: provider.name,\n exists: result\n };\n }\n \n if (action === 'compute.sandbox.filesystem.remove') {\n if (!body.path) throw new Error('path is required');\n await sandbox.filesystem.remove(body.path);\n return { success: true, sandboxId, provider: provider.name };\n }\n \n throw new Error(`Unknown action: ${action}`);\n \n } catch (error) {\n return {\n success: false,\n error: error instanceof Error ? error.message : 'Unknown error occurred',\n sandboxId: body.sandboxId || '',\n provider: provider.name\n };\n }\n}\n\n/**\n * Main request handler - handles HTTP requests and pre-parsed bodies\n */\nexport async function handleComputeRequest(\n params: HandleComputeRequestParams\n): Promise<ComputeResponse>;\nexport async function handleComputeRequest(\n requestOrBody: Request | ComputeRequest,\n provider: Provider\n): Promise<Response>;\nexport async function handleComputeRequest(\n paramsOrRequestOrBody: HandleComputeRequestParams | Request | ComputeRequest,\n provider?: Provider\n): Promise<ComputeResponse | Response> {\n // Handle object-style API\n if (typeof paramsOrRequestOrBody === 'object' && 'request' in paramsOrRequestOrBody && 'provider' in paramsOrRequestOrBody) {\n const params = paramsOrRequestOrBody as HandleComputeRequestParams;\n return await executeAction(params.request, params.provider);\n }\n \n // Handle original API\n if (!provider) {\n throw new Error('Provider is required when not using object-style API');\n }\n \n const requestOrBody = paramsOrRequestOrBody as Request | ComputeRequest;\n try {\n let body: ComputeRequest;\n \n if (requestOrBody instanceof Request) {\n // Handle HTTP method validation\n if (requestOrBody.method !== 'POST') {\n return Response.json({\n success: false,\n error: 'Only POST requests are supported',\n sandboxId: '',\n provider: provider.name\n }, { status: 405 });\n }\n \n // Parse JSON body with better error handling\n try {\n body = await requestOrBody.json();\n } catch (parseError) {\n return Response.json({\n success: false,\n error: 'Invalid JSON in request body',\n sandboxId: '',\n provider: provider.name\n }, { status: 400 });\n }\n } else {\n body = requestOrBody;\n }\n \n // Execute the action\n const result = await executeAction(body, provider);\n \n return Response.json(result, {\n status: result.success ? 200 : 500\n });\n \n } catch (error) {\n return Response.json({\n success: false,\n error: error instanceof Error ? error.message : 'Request handling failed',\n sandboxId: '',\n provider: provider.name\n }, { status: 500 });\n }\n}\n\n/**\n * Legacy export for backward compatibility\n */\nexport interface HandleComputeRequestParams {\n request: ComputeRequest;\n provider: Provider;\n}\n\nexport { handleComputeRequest as handleHttpComputeRequest };","/**\n * Provider Factory - Creates providers from method definitions\n * \n * Eliminates boilerplate by auto-generating Provider/Sandbox classes\n * from simple method definitions with automatic feature detection.\n */\n\nimport type {\n Provider,\n ProviderSandboxManager,\n Sandbox,\n SandboxFileSystem,\n SandboxInfo,\n ExecutionResult,\n Runtime,\n CreateSandboxOptions,\n FileEntry,\n RunCommandOptions,\n} from './types/index.js';\n\n/**\n * Helper function to handle background command execution\n * Providers can use this to implement background job support\n */\nexport function createBackgroundCommand(command: string, args: string[] = [], options?: RunCommandOptions): { command: string; args: string[]; isBackground: boolean } {\n if (!options?.background) {\n return { command, args, isBackground: false };\n }\n\n // For background execution, we modify the command to run in background\n // Default approach: append & to make it run in background\n const fullCommand = args.length > 0 ? `${command} ${args.join(' ')}` : command;\n \n return {\n command: 'sh',\n args: ['-c', `${fullCommand} &`],\n isBackground: true\n };\n}\n\n/**\n * Flat sandbox method implementations - all operations in one place\n */\nexport interface SandboxMethods<TSandbox = any, TConfig = any> {\n // Collection operations (map to compute.sandbox.*)\n create: (config: TConfig, options?: CreateSandboxOptions) => Promise<{ sandbox: TSandbox; sandboxId: string }>;\n getById: (config: TConfig, sandboxId: string) => Promise<{ sandbox: TSandbox; sandboxId: string } | null>;\n list: (config: TConfig) => Promise<Array<{ sandbox: TSandbox; sandboxId: string }>>;\n destroy: (config: TConfig, sandboxId: string) => Promise<void>;\n \n // Instance operations (map to individual Sandbox methods)\n runCode: (sandbox: TSandbox, code: string, runtime?: Runtime, config?: TConfig) => Promise<ExecutionResult>;\n runCommand: (sandbox: TSandbox, command: string, args?: string[], options?: RunCommandOptions) => Promise<ExecutionResult>;\n getInfo: (sandbox: TSandbox) => Promise<SandboxInfo>;\n getUrl: (sandbox: TSandbox, options: { port: number; protocol?: string }) => Promise<string>;\n \n // Optional provider-specific typed getInstance method\n getInstance?: (sandbox: TSandbox) => TSandbox;\n \n // Optional filesystem methods\n filesystem?: {\n readFile: (sandbox: TSandbox, path: string, runCommand: (sandbox: TSandbox, command: string, args?: string[]) => Promise<ExecutionResult>) => Promise<string>;\n writeFile: (sandbox: TSandbox, path: string, content: string, runCommand: (sandbox: TSandbox, command: string, args?: string[]) => Promise<ExecutionResult>) => Promise<void>;\n mkdir: (sandbox: TSandbox, path: string, runCommand: (sandbox: TSandbox, command: string, args?: string[]) => Promise<ExecutionResult>) => Promise<void>;\n readdir: (sandbox: TSandbox, path: string, runCommand: (sandbox: TSandbox, command: string, args?: string[]) => Promise<ExecutionResult>) => Promise<FileEntry[]>;\n exists: (sandbox: TSandbox, path: string, runCommand: (sandbox: TSandbox, command: string, args?: string[]) => Promise<ExecutionResult>) => Promise<boolean>;\n remove: (sandbox: TSandbox, path: string, runCommand: (sandbox: TSandbox, command: string, args?: string[]) => Promise<ExecutionResult>) => Promise<void>;\n };\n \n\n}\n\n/**\n * Provider configuration for createProvider()\n */\nexport interface ProviderConfig<TSandbox = any, TConfig = any> {\n name: string;\n methods: {\n sandbox: SandboxMethods<TSandbox, TConfig>;\n };\n}\n\n/**\n * Default filesystem implementations based on shell commands\n * These work for any provider that supports shell command execution\n */\nconst defaultFilesystemMethods = {\n readFile: async (sandbox: any, path: string, runCommand: (sandbox: any, command: string, args?: string[]) => Promise<ExecutionResult>): Promise<string> => {\n const result = await runCommand(sandbox, 'cat', [path]);\n if (result.exitCode !== 0) {\n throw new Error(`Failed to read file ${path}: ${result.stderr}`);\n }\n // Trim trailing newline that cat command adds\n return result.stdout.replace(/\\n$/, '');\n },\n\n writeFile: async (sandbox: any, path: string, content: string, runCommand: (sandbox: any, command: string, args?: string[]) => Promise<ExecutionResult>): Promise<void> => {\n const result = await runCommand(sandbox, 'sh', ['-c', `echo ${JSON.stringify(content)} > ${JSON.stringify(path)}`]);\n if (result.exitCode !== 0) {\n throw new Error(`Failed to write file ${path}: ${result.stderr}`);\n }\n },\n\n mkdir: async (sandbox: any, path: string, runCommand: (sandbox: any, command: string, args?: string[]) => Promise<ExecutionResult>): Promise<void> => {\n const result = await runCommand(sandbox, 'mkdir', ['-p', path]);\n if (result.exitCode !== 0) {\n throw new Error(`Failed to create directory ${path}: ${result.stderr}`);\n }\n },\n\n readdir: async (sandbox: any, path: string, runCommand: (sandbox: any, command: string, args?: string[]) => Promise<ExecutionResult>): Promise<FileEntry[]> => {\n // Try different ls variations for maximum compatibility\n let result = await runCommand(sandbox, 'ls', ['-la', path]);\n let hasDetailedOutput = true;\n \n // Fall back to basic ls if detailed flags not supported\n if (result.exitCode !== 0) {\n result = await runCommand(sandbox, 'ls', ['-l', path]);\n }\n if (result.exitCode !== 0) {\n result = await runCommand(sandbox, 'ls', [path]);\n hasDetailedOutput = false;\n }\n \n if (result.exitCode !== 0) {\n throw new Error(`Failed to list directory ${path}: ${result.stderr}`);\n }\n\n const lines = (result.stdout || '').split('\\n').filter((line: string) => line.trim() && !line.startsWith('total'));\n\n return lines.map((line: string) => {\n if (hasDetailedOutput && line.includes(' ')) {\n // Parse detailed ls output (ls -la or ls -l)\n const parts = line.trim().split(/\\s+/);\n const name = parts[parts.length - 1];\n const isDirectory = line.startsWith('d');\n \n return {\n name,\n path: `${path}/${name}`,\n isDirectory,\n size: parseInt(parts[4]) || 0,\n lastModified: new Date()\n };\n } else {\n // Parse simple ls output (just filenames)\n const name = line.trim();\n return {\n name,\n path: `${path}/${name}`,\n isDirectory: false, // Can't determine from simple ls\n size: 0,\n lastModified: new Date()\n };\n }\n });\n },\n\n exists: async (sandbox: any, path: string, runCommand: (sandbox: any, command: string, args?: string[]) => Promise<ExecutionResult>): Promise<boolean> => {\n const result = await runCommand(sandbox, 'test', ['-e', path]);\n return result.exitCode === 0; // Exit code 0 means file exists\n },\n\n remove: async (sandbox: any, path: string, runCommand: (sandbox: any, command: string, args?: string[]) => Promise<ExecutionResult>): Promise<void> => {\n const result = await runCommand(sandbox, 'rm', ['-rf', path]);\n if (result.exitCode !== 0) {\n throw new Error(`Failed to remove ${path}: ${result.stderr}`);\n }\n }\n};\n\n/**\n * Auto-generated filesystem implementation that throws \"not supported\" errors\n */\nclass UnsupportedFileSystem implements SandboxFileSystem {\n private readonly providerName: string;\n\n constructor(providerName: string) {\n this.providerName = providerName;\n }\n\n async readFile(_path: string): Promise<string> {\n throw new Error(`Filesystem operations are not supported by ${this.providerName}'s sandbox environment. ${this.providerName} sandboxes are designed for code execution only.`);\n }\n\n async writeFile(_path: string, _content: string): Promise<void> {\n throw new Error(`Filesystem operations are not supported by ${this.providerName}'s sandbox environment. ${this.providerName} sandboxes are designed for code execution only.`);\n }\n\n async mkdir(_path: string): Promise<void> {\n throw new Error(`Filesystem operations are not supported by ${this.providerName}'s sandbox environment. ${this.providerName} sandboxes are designed for code execution only.`);\n }\n\n async readdir(_path: string): Promise<FileEntry[]> {\n throw new Error(`Filesystem operations are not supported by ${this.providerName}'s sandbox environment. ${this.providerName} sandboxes are designed for code execution only.`);\n }\n\n async exists(_path: string): Promise<boolean> {\n throw new Error(`Filesystem operations are not supported by ${this.providerName}'s sandbox environment. ${this.providerName} sandboxes are designed for code execution only.`);\n }\n\n async remove(_path: string): Promise<void> {\n throw new Error(`Filesystem operations are not supported by ${this.providerName}'s sandbox environment. ${this.providerName} sandboxes are designed for code execution only.`);\n }\n}\n\n\n\n/**\n * Auto-generated filesystem implementation that wraps provider methods\n */\nclass SupportedFileSystem<TSandbox> implements SandboxFileSystem {\n constructor(\n private sandbox: TSandbox,\n private methods: NonNullable<SandboxMethods<TSandbox>['filesystem']>,\n private allMethods: SandboxMethods<TSandbox>\n ) {}\n\n async readFile(path: string): Promise<string> {\n return this.methods.readFile(this.sandbox, path, this.allMethods.runCommand);\n }\n\n async writeFile(path: string, content: string): Promise<void> {\n return this.methods.writeFile(this.sandbox, path, content, this.allMethods.runCommand);\n }\n\n async mkdir(path: string): Promise<void> {\n return this.methods.mkdir(this.sandbox, path, this.allMethods.runCommand);\n }\n\n async readdir(path: string): Promise<FileEntry[]> {\n return this.methods.readdir(this.sandbox, path, this.allMethods.runCommand);\n }\n\n async exists(path: string): Promise<boolean> {\n return this.methods.exists(this.sandbox, path, this.allMethods.runCommand);\n }\n\n async remove(path: string): Promise<void> {\n return this.methods.remove(this.sandbox, path, this.allMethods.runCommand);\n }\n}\n\n\n\n\n\n/**\n * Generated sandbox class - implements the Sandbox interface\n */\nclass GeneratedSandbox<TSandbox = any> implements Sandbox {\n readonly sandboxId: string;\n readonly provider: string;\n readonly filesystem: SandboxFileSystem;\n\n constructor(\n private sandbox: TSandbox,\n sandboxId: string,\n providerName: string,\n private methods: SandboxMethods<TSandbox>,\n private config: any,\n private destroyMethod: (config: any, sandboxId: string) => Promise<void>,\n private providerInstance: Provider\n ) {\n this.sandboxId = sandboxId;\n this.provider = providerName;\n\n // Auto-detect filesystem support\n if (methods.filesystem) {\n this.filesystem = new SupportedFileSystem(sandbox, methods.filesystem, methods);\n } else {\n this.filesystem = new UnsupportedFileSystem(providerName);\n }\n }\n\n getInstance(): TSandbox;\n getInstance<T extends TSandbox>(): T;\n getInstance<T extends TSandbox = TSandbox>(): T {\n // Use provider-specific typed getInstance if available\n if (this.methods.getInstance) {\n return this.methods.getInstance(this.sandbox) as T;\n }\n // Fallback to generic casting\n return this.sandbox as T;\n }\n\n async runCode(code: string, runtime?: Runtime): Promise<ExecutionResult> {\n return await this.methods.runCode(this.sandbox, code, runtime, this.config);\n }\n\n async runCommand(command: string, args?: string[], options?: RunCommandOptions): Promise<ExecutionResult> {\n return await this.methods.runCommand(this.sandbox, command, args, options);\n }\n\n async getInfo(): Promise<SandboxInfo> {\n return await this.methods.getInfo(this.sandbox);\n }\n\n async getUrl(options: { port: number; protocol?: string }): Promise<string> {\n return await this.methods.getUrl(this.sandbox, options);\n }\n\n getProvider(): Provider {\n return this.providerInstance;\n }\n\n async kill(): Promise<void> {\n // For backward compatibility, kill() delegates to destroy()\n await this.destroy();\n }\n\n async destroy(): Promise<void> {\n // Destroy via the provider's destroy method using our sandboxId\n await this.destroyMethod(this.config, this.sandboxId);\n }\n}\n\n/**\n * Auto-generated Sandbox Manager implementation\n */\nclass GeneratedSandboxManager<TSandbox, TConfig> implements ProviderSandboxManager {\n private activeSandboxes: Map<string, GeneratedSandbox<TSandbox>> = new Map();\n\n constructor(\n private config: TConfig,\n private providerName: string,\n private methods: SandboxMethods<TSandbox, TConfig>,\n private providerInstance: Provider\n ) {}\n\n async create(options?: CreateSandboxOptions): Promise<Sandbox> {\n const result = await this.methods.create(this.config, options);\n const sandbox = new GeneratedSandbox(\n result.sandbox,\n result.sandboxId,\n this.providerName,\n this.methods,\n this.config,\n this.methods.destroy,\n this.providerInstance\n );\n \n this.activeSandboxes.set(result.sandboxId, sandbox);\n return sandbox;\n }\n\n async getById(sandboxId: string): Promise<Sandbox | null> {\n // Check active sandboxes first\n const existing = this.activeSandboxes.get(sandboxId);\n if (existing) {\n return existing;\n }\n\n // Try to reconnect\n const result = await this.methods.getById(this.config, sandboxId);\n if (!result) {\n return null;\n }\n\n const sandbox = new GeneratedSandbox(\n result.sandbox,\n result.sandboxId,\n this.providerName,\n this.methods,\n this.config,\n this.methods.destroy,\n this.providerInstance\n );\n \n this.activeSandboxes.set(result.sandboxId, sandbox);\n return sandbox;\n }\n\n async list(): Promise<Sandbox[]> {\n const results = await this.methods.list(this.config);\n const sandboxes: Sandbox[] = [];\n\n for (const result of results) {\n let sandbox = this.activeSandboxes.get(result.sandboxId);\n if (!sandbox) {\n sandbox = new GeneratedSandbox(\n result.sandbox,\n result.sandboxId,\n this.providerName,\n this.methods,\n this.config,\n this.methods.destroy,\n this.providerInstance\n );\n this.activeSandboxes.set(result.sandboxId, sandbox);\n }\n sandboxes.push(sandbox);\n }\n\n return sandboxes;\n }\n\n async destroy(sandboxId: string): Promise<void> {\n await this.methods.destroy(this.config, sandboxId);\n this.activeSandboxes.delete(sandboxId);\n }\n}\n\n/**\n * Auto-generated Provider implementation\n */\nclass GeneratedProvider<TSandbox, TConfig> implements Provider {\n readonly name: string;\n readonly sandbox: ProviderSandboxManager;\n\n constructor(config: TConfig, providerConfig: ProviderConfig<TSandbox, TConfig>) {\n this.name = providerConfig.name;\n this.sandbox = new GeneratedSandboxManager(\n config,\n providerConfig.name,\n providerConfig.methods.sandbox,\n this\n );\n }\n}\n\n/**\n * Create a provider from method definitions\n * \n * Auto-generates all boilerplate classes and provides feature detection\n * based on which methods are implemented.\n */\nexport function createProvider<TSandbox, TConfig>(\n providerConfig: ProviderConfig<TSandbox, TConfig>\n): (config: TConfig) => Provider {\n // Auto-inject default filesystem methods if none provided\n if (!providerConfig.methods.sandbox.filesystem) {\n providerConfig.methods.sandbox.filesystem = defaultFilesystemMethods;\n }\n\n return (config: TConfig) => {\n return new GeneratedProvider(config, providerConfig);\n };\n}"],"mappings":";AAgJO,IAAM,mBAAN,cAA+B,MAAM;AAAA,EAE1C,YAAmB,QAKhB;AACD,UAAM,4BAA4B,OAAO,QAAQ,EAAE;AANlC;AADnB,gBAAO;AAAA,EAQP;AACF;AAKO,SAAS,mBAAmB,OAA2C;AAC5E,SACE,OAAO,UAAU,YACjB,UAAU,QACV,UAAU,SACV,MAAM,SAAS,sBACf,YAAY;AAEhB;;;AC5JA,IAAM,iBAAN,MAA2C;AAAA,EAA3C;AACE,SAAQ,SAA+B;AACvC,SAAQ,aAGJ,EAAE,SAAS,OAAO,UAAU,KAAK;AAyDrC,mBAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAoBR,QAAQ,OAAO,WAA6F;AAC1G,cAAM,WAAW,UAAU,cAAc,UAAU,OAAO,WAAW,OAAO,WAAW,KAAK,mBAAmB;AAC/G,cAAM,UAAU,QAAQ;AACxB,cAAM,UAAU,MAAM,SAAS,QAAQ,OAAO,OAAO;AAIrD,YAAI,KAAK,WAAW,YAAY,CAAC,UAAU,EAAE,cAAc,UAAU,OAAO,YAAY;AACtF,iBAAO;AAAA,QACT;AAEA,eAAO;AAAA,MACT;AAAA;AAAA;AAAA;AAAA,MAKA,SAAS,OAAO,qBAAwC,cAAgD;AACtG,YAAI,OAAO,wBAAwB,UAAU;AAE3C,gBAAM,WAAW,KAAK,mBAAmB;AACzC,gBAAM,UAA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,mBAAe,QAAQ,QAAQ,aAAa;AAAA,EAC9C;AAEA,SAAO,CAAC,WAAoB;AAC1B,WAAO,IAAI,kBAAkB,QAAQ,cAAc;AAAA,EACrD;AACF;","names":["sandbox"]}
|
|
1
|
+
{"version":3,"sources":["../src/types/sandbox.ts","../src/compute.ts","../src/request-handler.ts","../src/factory.ts"],"sourcesContent":["/**\n * Sandbox Types\n * \n * Types related to sandbox execution, filesystem, terminal operations\n */\n\n// Forward declaration to avoid circular dependency\ninterface Provider {\n readonly name: string;\n readonly sandbox: any; // Will be properly typed when imported together\n}\n\n/**\n * Type mapping for provider names to their sandbox types\n * Manually defined for known providers since declaration merging isn't working reliably\n */\nexport interface ProviderSandboxTypeMap {\n e2b: any; // We can't import the E2B type directly, but we'll handle it differently\n vercel: any;\n daytona: any;\n}\n\n/**\n * Utility type to extract the native instance type from a provider\n * Uses provider name and manual type inference\n */\nexport type ExtractSandboxInstanceType<TProvider extends Provider> = \n TProvider extends { readonly name: 'e2b' }\n ? any // For now, let's just try to make the runtime casting work\n : TProvider extends { readonly name: 'vercel' }\n ? any\n : TProvider extends { readonly name: 'daytona' }\n ? any\n : any;\n\n/**\n * Supported runtime environments\n */\nexport type Runtime = 'node' | 'python';\n\n/**\n * Sandbox status types\n */\nexport type SandboxStatus = 'running' | 'stopped' | 'error';\n\n/**\n * Options for running commands\n */\nexport interface RunCommandOptions {\n /** Run command in background (non-blocking) */\n background?: boolean;\n}\n\n/**\n * Result of code execution\n */\nexport interface ExecutionResult {\n /** Standard output from the execution */\n stdout: string;\n /** Standard error from the execution */\n stderr: string;\n /** Exit code from the execution */\n exitCode: number;\n /** Time taken for execution in milliseconds */\n executionTime: number;\n /** ID of the sandbox where the code was executed */\n sandboxId: string;\n /** Provider that executed the code */\n provider: string;\n /** Process ID for background jobs (if applicable) */\n pid?: number;\n /** Whether this command is running in background */\n isBackground?: boolean;\n}\n\n/**\n * Information about a sandbox\n */\nexport interface SandboxInfo {\n /** Unique identifier for the sandbox */\n id: string;\n /** Provider hosting the sandbox */\n provider: string;\n /** Runtime environment in the sandbox */\n runtime: Runtime;\n /** Current status of the sandbox */\n status: SandboxStatus;\n /** When the sandbox was created */\n createdAt: Date;\n /** Execution timeout in milliseconds */\n timeout: number;\n /** Additional provider-specific metadata */\n metadata?: Record<string, any>;\n}\n\n/**\n * Options for creating a sandbox\n */\nexport interface CreateSandboxOptions {\n /** Runtime environment */\n runtime?: Runtime;\n /** Execution timeout in milliseconds */\n timeout?: number;\n /** Custom sandbox ID (if supported by provider) */\n sandboxId?: string;\n /** Template ID for sandbox creation (provider-specific) */\n templateId?: string;\n /** Additional metadata for the sandbox */\n metadata?: Record<string, any>;\n /** Domain for sandbox connection (provider-specific) */\n domain?: string;\n /** Environment variables for the sandbox */\n envs?: Record<string, string>;\n}\n\n/**\n * File system entry information\n */\nexport interface FileEntry {\n /** File/directory name */\n name: string;\n /** Full path to the entry */\n path: string;\n /** Whether this is a directory */\n isDirectory: boolean;\n /** File size in bytes (0 for directories) */\n size: number;\n /** Last modified timestamp */\n lastModified: Date;\n}\n\n/**\n * File system interface for sandbox operations\n */\nexport interface SandboxFileSystem {\n /** Read file contents */\n readFile(path: string): Promise<string>;\n /** Write file contents */\n writeFile(path: string, content: string): Promise<void>;\n /** Create directory */\n mkdir(path: string): Promise<void>;\n /** List directory contents */\n readdir(path: string): Promise<FileEntry[]>;\n /** Check if file/directory exists */\n exists(path: string): Promise<boolean>;\n /** Remove file or directory */\n remove(path: string): Promise<void>;\n}\n\n/**\n * Error thrown when a command exits with a non-zero status\n */\nexport class CommandExitError extends Error {\n name = 'CommandExitError';\n constructor(public result: {\n exitCode: number;\n stdout: string;\n stderr: string;\n error: boolean;\n }) {\n super(`Command exited with code ${result.exitCode}`);\n }\n}\n\n/**\n * Type guard to check if an error is a CommandExitError\n */\nexport function isCommandExitError(error: unknown): error is CommandExitError {\n return (\n typeof error === 'object' &&\n error !== null &&\n 'name' in error &&\n error.name === 'CommandExitError' &&\n 'result' in error\n );\n}\n\n\n\n\n\n/**\n * Base sandbox interface - what developers interact with\n */\nexport interface Sandbox<TSandbox = any> {\n /** Unique identifier for the sandbox */\n readonly sandboxId: string;\n /** Provider that created this sandbox */\n readonly provider: string;\n\n /** Execute code in the sandbox */\n runCode(code: string, runtime?: Runtime): Promise<ExecutionResult>;\n /** Execute shell commands */\n runCommand(command: string, args?: string[], options?: RunCommandOptions): Promise<ExecutionResult>;\n /** Get information about the sandbox */\n getInfo(): Promise<SandboxInfo>;\n /** Get URL for accessing the sandbox on a specific port */\n getUrl(options: { port: number; protocol?: string }): Promise<string>;\n /** Get the provider instance that created this sandbox */\n getProvider(): import('./provider').Provider<TSandbox>;\n /** Get the native provider sandbox instance with proper typing */\n getInstance(): TSandbox;\n /** Kill the sandbox */\n kill(): Promise<void>;\n /** Destroy the sandbox and clean up resources */\n destroy(): Promise<void>;\n\n /** File system operations */\n readonly filesystem: SandboxFileSystem;\n}\n\n/**\n * Extract the sandbox type from a provider\n */\ntype ExtractProviderSandboxType<TProvider extends Provider> = TProvider extends { readonly __sandboxType: infer TSandbox } ? TSandbox : any;\n\n/**\n * Typed sandbox interface that preserves the provider's native instance type\n */\nexport interface TypedSandbox<TProvider extends Provider> extends Omit<Sandbox<ExtractProviderSandboxType<TProvider>>, 'getProvider'> {\n /** Get the provider instance that created this sandbox with proper typing */\n getProvider(): TProvider;\n /** Get the native provider sandbox instance with proper typing */\n getInstance(): ExtractProviderSandboxType<TProvider>;\n}","/**\n * Compute Singleton - Main API Orchestrator\n * \n * Provides the unified compute.* API and delegates to specialized managers\n */\n\nimport type { ComputeAPI, CreateSandboxParams, CreateSandboxParamsWithOptionalProvider, ComputeConfig, Sandbox, Provider, TypedSandbox, TypedComputeAPI, ExtractSandboxInstanceType } from './types';\n\n/**\n * Compute singleton implementation - orchestrates all compute operations\n */\nclass ComputeManager implements ComputeAPI {\n private config: ComputeConfig | null = null;\n private typedState: { \n isTyped: boolean; \n provider: Provider | null; \n } = { isTyped: false, provider: null };\n\n /**\n * Set default configuration with generic type preservation\n */\n setConfig<TProvider extends Provider>(config: ComputeConfig<TProvider>): void {\n // Validate that at least one provider is specified\n if (!config.defaultProvider && !config.provider) {\n throw new Error('Either defaultProvider or provider must be specified in setConfig');\n }\n \n // Handle backwards compatibility: if both are provided, defaultProvider takes precedence\n if (config.defaultProvider && config.provider) {\n console.warn('Both defaultProvider and provider specified in setConfig. Using defaultProvider. The provider key is deprecated, please use defaultProvider instead.');\n }\n \n // Normalize config to always have both fields for internal use (backward compatibility)\n const actualProvider = config.defaultProvider || config.provider!;\n this.config = {\n provider: actualProvider,\n defaultProvider: actualProvider\n };\n\n // Store typed state for type-aware operations\n this.typedState = {\n isTyped: true,\n provider: actualProvider\n };\n }\n\n /**\n * Get current configuration\n */\n getConfig(): ComputeConfig | null {\n return this.config;\n }\n\n /**\n * Clear current configuration\n */\n clearConfig(): void {\n this.config = null;\n }\n\n /**\n * Get the default provider, throwing if not configured\n */\n private getDefaultProvider(): Provider {\n const provider = this.config?.defaultProvider || this.config?.provider;\n if (!provider) {\n throw new Error(\n 'No default provider configured. Either call compute.setConfig({ defaultProvider }) or pass provider explicitly.'\n );\n }\n return provider;\n }\n\n sandbox = {\n /**\n * Create a sandbox from a provider (or default provider if configured)\n * \n * @example\n * ```typescript\n * import { e2b } from '@computesdk/e2b'\n * import { compute } from 'computesdk'\n * \n * // With explicit provider\n * const sandbox = await compute.sandbox.create({\n * provider: e2b({ apiKey: 'your-key' })\n * })\n * \n * // With default provider (both forms work)\n * compute.setConfig({ defaultProvider: e2b({ apiKey: 'your-key' }) })\n * const sandbox1 = await compute.sandbox.create({})\n * const sandbox2 = await compute.sandbox.create()\n * ```\n */\n create: async (params?: CreateSandboxParams | CreateSandboxParamsWithOptionalProvider): Promise<Sandbox> => {\n const provider = params && 'provider' in params && params.provider ? params.provider : this.getDefaultProvider();\n const options = params?.options;\n const sandbox = await provider.sandbox.create(options);\n \n // If we have typed state and no explicit provider passed, cast to typed sandbox\n // This enables proper type inference for getInstance() when using default provider\n if (this.typedState.isTyped && (!params || !('provider' in params && params.provider))) {\n return sandbox as TypedSandbox<any>;\n }\n \n return sandbox;\n },\n\n /**\n * Get an existing sandbox by ID from a provider (or default provider if configured)\n */\n getById: async (providerOrSandboxId: Provider | string, sandboxId?: string): Promise<Sandbox | null> => {\n if (typeof providerOrSandboxId === 'string') {\n // Called with just sandboxId, use default provider\n const provider = this.getDefaultProvider();\n const sandbox = await provider.sandbox.getById(providerOrSandboxId);\n \n // If we have typed state, cast to typed sandbox for proper getInstance() typing\n if (this.typedState.isTyped && sandbox) {\n return sandbox as TypedSandbox<any>;\n }\n \n return sandbox;\n } else {\n // Called with provider and sandboxId\n if (!sandboxId) {\n throw new Error('sandboxId is required when provider is specified');\n }\n return await providerOrSandboxId.sandbox.getById(sandboxId);\n }\n },\n\n /**\n * List all active sandboxes from a provider (or default provider if configured)\n */\n list: async (provider?: Provider): Promise<Sandbox[]> => {\n const actualProvider = provider || this.getDefaultProvider();\n const sandboxes = await actualProvider.sandbox.list();\n \n // If we have typed state and no explicit provider passed, cast to typed sandboxes\n if (this.typedState.isTyped && !provider) {\n return sandboxes as TypedSandbox<any>[];\n }\n \n return sandboxes;\n },\n\n /**\n * Destroy a sandbox via a provider (or default provider if configured)\n */\n destroy: async (providerOrSandboxId: Provider | string, sandboxId?: string): Promise<void> => {\n if (typeof providerOrSandboxId === 'string') {\n // Called with just sandboxId, use default provider\n const provider = this.getDefaultProvider();\n return await provider.sandbox.destroy(providerOrSandboxId);\n } else {\n // Called with provider and sandboxId\n if (!sandboxId) {\n throw new Error('sandboxId is required when provider is specified');\n }\n return await providerOrSandboxId.sandbox.destroy(sandboxId);\n }\n }\n };\n\n // Future: compute.blob.*, compute.database.*, compute.git.* will be added here\n // blob = new BlobManager();\n // database = new DatabaseManager(); \n // git = new GitManager();\n\n\n}\n\n/**\n * Singleton instance - the main API (untyped)\n */\nexport const compute: ComputeAPI = new ComputeManager();\n\n\n\n/**\n * Create a compute instance with proper typing\n * \n * @example\n * ```typescript\n * import { e2b } from '@computesdk/e2b'\n * import { createCompute } from 'computesdk'\n * \n * const compute = createCompute({\n * defaultProvider: e2b({ apiKey: 'your-key' }),\n * });\n * \n * const sandbox = await compute.sandbox.create();\n * const instance = sandbox.getInstance(); // ✅ Properly typed E2B Sandbox!\n * ```\n */\nexport function createCompute<TProvider extends Provider>(config: ComputeConfig<TProvider>): TypedComputeAPI<TProvider> {\n const manager = new ComputeManager();\n \n // Set config directly without calling the public setConfig method\n const actualProvider = config.defaultProvider || config.provider!;\n manager['config'] = {\n provider: actualProvider,\n defaultProvider: actualProvider\n };\n manager['typedState'] = {\n isTyped: true,\n provider: actualProvider\n };\n \n return {\n setConfig: <T extends Provider>(cfg: ComputeConfig<T>) => createCompute(cfg),\n getConfig: () => manager.getConfig(),\n clearConfig: () => manager.clearConfig(),\n \n sandbox: {\n create: async (params?: Omit<CreateSandboxParamsWithOptionalProvider, 'provider'>) => {\n const sandbox = await manager.sandbox.create(params);\n // The sandbox should now have the correct getInstance typing from the generic Sandbox<TSandbox>\n return sandbox as TypedSandbox<TProvider>;\n },\n \n getById: async (sandboxId: string) => {\n const sandbox = await manager.sandbox.getById(sandboxId);\n return sandbox ? sandbox as TypedSandbox<TProvider> : null;\n },\n \n list: async () => {\n const sandboxes = await manager.sandbox.list();\n return sandboxes as TypedSandbox<TProvider>[];\n },\n \n destroy: async (sandboxId: string) => {\n return await manager.sandbox.destroy(sandboxId);\n }\n }\n } as TypedComputeAPI<TProvider>;\n}\n\n\n\n","/**\n * Simplified Request Handler for Web Framework Integration\n * \n * Handles JSON requests for sandbox and code execution operations.\n * Terminal support removed - will be re-added with WebSocket VM connections.\n */\n\nimport type { Provider, Runtime } from './types';\nimport { compute } from './compute';\n\n/**\n * Request structure supporting sandbox and code execution capabilities\n */\nexport interface ComputeRequest {\n /** Action in dot notation (e.g., 'compute.sandbox.create') */\n action: string;\n \n /** Parameters for the action */\n sandboxId?: string;\n code?: string;\n command?: string;\n args?: string[];\n runtime?: Runtime;\n path?: string;\n content?: string;\n \n /** Command options (for runCommand action) */\n commandOptions?: {\n background?: boolean;\n };\n \n /** Sandbox creation options */\n options?: {\n runtime?: Runtime;\n timeout?: number;\n sandboxId?: string;\n };\n}\n\n/**\n * Response structure for compute operations\n */\nexport interface ComputeResponse {\n success: boolean;\n error?: string;\n sandboxId: string;\n provider: string;\n [key: string]: any; // Allow any additional response data\n}\n\n/**\n * Execute compute action using targeted handling\n */\nasync function executeAction(body: ComputeRequest, provider: Provider): Promise<ComputeResponse> {\n try {\n const { action, sandboxId } = body;\n \n // Sandbox management operations\n if (action === 'compute.sandbox.create') {\n const sandbox = await compute.sandbox.create({\n provider,\n options: body.options || { runtime: 'python' }\n });\n return {\n success: true,\n sandboxId: sandbox.sandboxId,\n provider: provider.name\n };\n }\n \n if (action === 'compute.sandbox.list') {\n const sandboxes = await compute.sandbox.list(provider);\n return {\n success: true,\n sandboxId: '',\n provider: provider.name,\n sandboxes: sandboxes.map(sb => ({\n sandboxId: sb.sandboxId,\n provider: sb.provider\n }))\n };\n }\n \n if (action === 'compute.sandbox.destroy') {\n if (!sandboxId) {\n throw new Error('sandboxId is required for destroy action');\n }\n await compute.sandbox.destroy(provider, sandboxId);\n return {\n success: true,\n sandboxId,\n provider: provider.name\n };\n }\n \n // For sandbox instance methods, get the sandbox first\n if (!sandboxId) {\n throw new Error('sandboxId is required for this action');\n }\n \n const sandbox = await compute.sandbox.getById(provider, sandboxId);\n if (!sandbox) {\n throw new Error(`Sandbox ${sandboxId} not found`);\n }\n \n // Sandbox info\n if (action === 'compute.sandbox.getInfo') {\n const result = await sandbox.getInfo();\n return {\n success: true,\n sandboxId,\n provider: provider.name,\n info: {\n id: result.id,\n provider: result.provider,\n runtime: result.runtime,\n status: result.status,\n createdAt: result.createdAt.toISOString(),\n timeout: result.timeout,\n metadata: result.metadata\n }\n };\n }\n \n // Code execution\n if (action === 'compute.sandbox.runCode') {\n if (!body.code) throw new Error('code is required');\n const result = await sandbox.runCode(body.code, body.runtime);\n return {\n success: true,\n sandboxId,\n provider: provider.name,\n result: {\n stdout: result.stdout,\n stderr: result.stderr,\n exitCode: result.exitCode,\n executionTime: result.executionTime\n }\n };\n }\n \n if (action === 'compute.sandbox.runCommand') {\n if (!body.command) throw new Error('command is required');\n const result = await sandbox.runCommand(body.command, body.args, body.commandOptions);\n return {\n success: true,\n sandboxId,\n provider: provider.name,\n result: {\n stdout: result.stdout,\n stderr: result.stderr,\n exitCode: result.exitCode,\n executionTime: result.executionTime,\n ...(result.isBackground && { isBackground: result.isBackground }),\n ...(result.pid && { pid: result.pid })\n }\n };\n }\n \n // Filesystem operations\n if (action === 'compute.sandbox.filesystem.readFile') {\n if (!body.path) throw new Error('path is required');\n const result = await sandbox.filesystem.readFile(body.path);\n return {\n success: true,\n sandboxId,\n provider: provider.name,\n fileContent: result\n };\n }\n \n if (action === 'compute.sandbox.filesystem.writeFile') {\n if (!body.path) throw new Error('path is required');\n if (body.content === undefined) throw new Error('content is required');\n await sandbox.filesystem.writeFile(body.path, body.content);\n return { success: true, sandboxId, provider: provider.name };\n }\n \n if (action === 'compute.sandbox.filesystem.mkdir') {\n if (!body.path) throw new Error('path is required');\n await sandbox.filesystem.mkdir(body.path);\n return { success: true, sandboxId, provider: provider.name };\n }\n \n if (action === 'compute.sandbox.filesystem.readdir') {\n if (!body.path) throw new Error('path is required');\n const result = await sandbox.filesystem.readdir(body.path);\n return {\n success: true,\n sandboxId,\n provider: provider.name,\n files: result.map((entry: any) => ({\n name: entry.name,\n path: entry.path,\n isDirectory: entry.isDirectory,\n size: entry.size,\n lastModified: entry.lastModified.toISOString()\n }))\n };\n }\n \n if (action === 'compute.sandbox.filesystem.exists') {\n if (!body.path) throw new Error('path is required');\n const result = await sandbox.filesystem.exists(body.path);\n return {\n success: true,\n sandboxId,\n provider: provider.name,\n exists: result\n };\n }\n \n if (action === 'compute.sandbox.filesystem.remove') {\n if (!body.path) throw new Error('path is required');\n await sandbox.filesystem.remove(body.path);\n return { success: true, sandboxId, provider: provider.name };\n }\n \n throw new Error(`Unknown action: ${action}`);\n \n } catch (error) {\n return {\n success: false,\n error: error instanceof Error ? error.message : 'Unknown error occurred',\n sandboxId: body.sandboxId || '',\n provider: provider.name\n };\n }\n}\n\n/**\n * Main request handler - handles HTTP requests and pre-parsed bodies\n */\nexport async function handleComputeRequest(\n params: HandleComputeRequestParams\n): Promise<ComputeResponse>;\nexport async function handleComputeRequest(\n requestOrBody: Request | ComputeRequest,\n provider: Provider\n): Promise<Response>;\nexport async function handleComputeRequest(\n paramsOrRequestOrBody: HandleComputeRequestParams | Request | ComputeRequest,\n provider?: Provider\n): Promise<ComputeResponse | Response> {\n // Handle object-style API\n if (typeof paramsOrRequestOrBody === 'object' && 'request' in paramsOrRequestOrBody && 'provider' in paramsOrRequestOrBody) {\n const params = paramsOrRequestOrBody as HandleComputeRequestParams;\n return await executeAction(params.request, params.provider);\n }\n \n // Handle original API\n if (!provider) {\n throw new Error('Provider is required when not using object-style API');\n }\n \n const requestOrBody = paramsOrRequestOrBody as Request | ComputeRequest;\n try {\n let body: ComputeRequest;\n \n if (requestOrBody instanceof Request) {\n // Handle HTTP method validation\n if (requestOrBody.method !== 'POST') {\n return Response.json({\n success: false,\n error: 'Only POST requests are supported',\n sandboxId: '',\n provider: provider.name\n }, { status: 405 });\n }\n \n // Parse JSON body with better error handling\n try {\n body = await requestOrBody.json();\n } catch (parseError) {\n return Response.json({\n success: false,\n error: 'Invalid JSON in request body',\n sandboxId: '',\n provider: provider.name\n }, { status: 400 });\n }\n } else {\n body = requestOrBody;\n }\n \n // Execute the action\n const result = await executeAction(body, provider);\n \n return Response.json(result, {\n status: result.success ? 200 : 500\n });\n \n } catch (error) {\n return Response.json({\n success: false,\n error: error instanceof Error ? error.message : 'Request handling failed',\n sandboxId: '',\n provider: provider.name\n }, { status: 500 });\n }\n}\n\n/**\n * Legacy export for backward compatibility\n */\nexport interface HandleComputeRequestParams {\n request: ComputeRequest;\n provider: Provider;\n}\n\nexport { handleComputeRequest as handleHttpComputeRequest };","/**\n * Provider Factory - Creates providers from method definitions\n * \n * Eliminates boilerplate by auto-generating Provider/Sandbox classes\n * from simple method definitions with automatic feature detection.\n */\n\nimport type {\n Provider,\n ProviderSandboxManager,\n Sandbox,\n SandboxFileSystem,\n SandboxInfo,\n ExecutionResult,\n Runtime,\n CreateSandboxOptions,\n FileEntry,\n RunCommandOptions,\n} from './types/index.js';\n\n/**\n * Helper function to handle background command execution\n * Providers can use this to implement background job support\n */\nexport function createBackgroundCommand(command: string, args: string[] = [], options?: RunCommandOptions): { command: string; args: string[]; isBackground: boolean } {\n if (!options?.background) {\n return { command, args, isBackground: false };\n }\n\n // For background execution, we modify the command to run in background\n // Default approach: append & to make it run in background\n const fullCommand = args.length > 0 ? `${command} ${args.join(' ')}` : command;\n \n return {\n command: 'sh',\n args: ['-c', `${fullCommand} &`],\n isBackground: true\n };\n}\n\n/**\n * Flat sandbox method implementations - all operations in one place\n */\nexport interface SandboxMethods<TSandbox = any, TConfig = any> {\n // Collection operations (map to compute.sandbox.*)\n create: (config: TConfig, options?: CreateSandboxOptions) => Promise<{ sandbox: TSandbox; sandboxId: string }>;\n getById: (config: TConfig, sandboxId: string) => Promise<{ sandbox: TSandbox; sandboxId: string } | null>;\n list: (config: TConfig) => Promise<Array<{ sandbox: TSandbox; sandboxId: string }>>;\n destroy: (config: TConfig, sandboxId: string) => Promise<void>;\n \n // Instance operations (map to individual Sandbox methods)\n runCode: (sandbox: TSandbox, code: string, runtime?: Runtime, config?: TConfig) => Promise<ExecutionResult>;\n runCommand: (sandbox: TSandbox, command: string, args?: string[], options?: RunCommandOptions) => Promise<ExecutionResult>;\n getInfo: (sandbox: TSandbox) => Promise<SandboxInfo>;\n getUrl: (sandbox: TSandbox, options: { port: number; protocol?: string }) => Promise<string>;\n \n // Optional provider-specific typed getInstance method\n getInstance?: (sandbox: TSandbox) => TSandbox;\n \n // Optional filesystem methods\n filesystem?: {\n readFile: (sandbox: TSandbox, path: string, runCommand: (sandbox: TSandbox, command: string, args?: string[]) => Promise<ExecutionResult>) => Promise<string>;\n writeFile: (sandbox: TSandbox, path: string, content: string, runCommand: (sandbox: TSandbox, command: string, args?: string[]) => Promise<ExecutionResult>) => Promise<void>;\n mkdir: (sandbox: TSandbox, path: string, runCommand: (sandbox: TSandbox, command: string, args?: string[]) => Promise<ExecutionResult>) => Promise<void>;\n readdir: (sandbox: TSandbox, path: string, runCommand: (sandbox: TSandbox, command: string, args?: string[]) => Promise<ExecutionResult>) => Promise<FileEntry[]>;\n exists: (sandbox: TSandbox, path: string, runCommand: (sandbox: TSandbox, command: string, args?: string[]) => Promise<ExecutionResult>) => Promise<boolean>;\n remove: (sandbox: TSandbox, path: string, runCommand: (sandbox: TSandbox, command: string, args?: string[]) => Promise<ExecutionResult>) => Promise<void>;\n };\n \n\n}\n\n/**\n * Provider configuration for createProvider()\n */\nexport interface ProviderConfig<TSandbox = any, TConfig = any> {\n name: string;\n methods: {\n sandbox: SandboxMethods<TSandbox, TConfig>;\n };\n}\n\n/**\n * Default filesystem implementations based on shell commands\n * These work for any provider that supports shell command execution\n */\nconst defaultFilesystemMethods = {\n readFile: async (sandbox: any, path: string, runCommand: (sandbox: any, command: string, args?: string[]) => Promise<ExecutionResult>): Promise<string> => {\n const result = await runCommand(sandbox, 'cat', [path]);\n if (result.exitCode !== 0) {\n throw new Error(`Failed to read file ${path}: ${result.stderr}`);\n }\n // Trim trailing newline that cat command adds\n return result.stdout.replace(/\\n$/, '');\n },\n\n writeFile: async (sandbox: any, path: string, content: string, runCommand: (sandbox: any, command: string, args?: string[]) => Promise<ExecutionResult>): Promise<void> => {\n const result = await runCommand(sandbox, 'sh', ['-c', `echo ${JSON.stringify(content)} > ${JSON.stringify(path)}`]);\n if (result.exitCode !== 0) {\n throw new Error(`Failed to write file ${path}: ${result.stderr}`);\n }\n },\n\n mkdir: async (sandbox: any, path: string, runCommand: (sandbox: any, command: string, args?: string[]) => Promise<ExecutionResult>): Promise<void> => {\n const result = await runCommand(sandbox, 'mkdir', ['-p', path]);\n if (result.exitCode !== 0) {\n throw new Error(`Failed to create directory ${path}: ${result.stderr}`);\n }\n },\n\n readdir: async (sandbox: any, path: string, runCommand: (sandbox: any, command: string, args?: string[]) => Promise<ExecutionResult>): Promise<FileEntry[]> => {\n // Try different ls variations for maximum compatibility\n let result = await runCommand(sandbox, 'ls', ['-la', path]);\n let hasDetailedOutput = true;\n \n // Fall back to basic ls if detailed flags not supported\n if (result.exitCode !== 0) {\n result = await runCommand(sandbox, 'ls', ['-l', path]);\n }\n if (result.exitCode !== 0) {\n result = await runCommand(sandbox, 'ls', [path]);\n hasDetailedOutput = false;\n }\n \n if (result.exitCode !== 0) {\n throw new Error(`Failed to list directory ${path}: ${result.stderr}`);\n }\n\n const lines = (result.stdout || '').split('\\n').filter((line: string) => line.trim() && !line.startsWith('total'));\n\n return lines.map((line: string) => {\n if (hasDetailedOutput && line.includes(' ')) {\n // Parse detailed ls output (ls -la or ls -l)\n const parts = line.trim().split(/\\s+/);\n const name = parts[parts.length - 1];\n const isDirectory = line.startsWith('d');\n \n return {\n name,\n path: `${path}/${name}`,\n isDirectory,\n size: parseInt(parts[4]) || 0,\n lastModified: new Date()\n };\n } else {\n // Parse simple ls output (just filenames)\n const name = line.trim();\n return {\n name,\n path: `${path}/${name}`,\n isDirectory: false, // Can't determine from simple ls\n size: 0,\n lastModified: new Date()\n };\n }\n });\n },\n\n exists: async (sandbox: any, path: string, runCommand: (sandbox: any, command: string, args?: string[]) => Promise<ExecutionResult>): Promise<boolean> => {\n const result = await runCommand(sandbox, 'test', ['-e', path]);\n return result.exitCode === 0; // Exit code 0 means file exists\n },\n\n remove: async (sandbox: any, path: string, runCommand: (sandbox: any, command: string, args?: string[]) => Promise<ExecutionResult>): Promise<void> => {\n const result = await runCommand(sandbox, 'rm', ['-rf', path]);\n if (result.exitCode !== 0) {\n throw new Error(`Failed to remove ${path}: ${result.stderr}`);\n }\n }\n};\n\n/**\n * Auto-generated filesystem implementation that throws \"not supported\" errors\n */\nclass UnsupportedFileSystem implements SandboxFileSystem {\n private readonly providerName: string;\n\n constructor(providerName: string) {\n this.providerName = providerName;\n }\n\n async readFile(_path: string): Promise<string> {\n throw new Error(`Filesystem operations are not supported by ${this.providerName}'s sandbox environment. ${this.providerName} sandboxes are designed for code execution only.`);\n }\n\n async writeFile(_path: string, _content: string): Promise<void> {\n throw new Error(`Filesystem operations are not supported by ${this.providerName}'s sandbox environment. ${this.providerName} sandboxes are designed for code execution only.`);\n }\n\n async mkdir(_path: string): Promise<void> {\n throw new Error(`Filesystem operations are not supported by ${this.providerName}'s sandbox environment. ${this.providerName} sandboxes are designed for code execution only.`);\n }\n\n async readdir(_path: string): Promise<FileEntry[]> {\n throw new Error(`Filesystem operations are not supported by ${this.providerName}'s sandbox environment. ${this.providerName} sandboxes are designed for code execution only.`);\n }\n\n async exists(_path: string): Promise<boolean> {\n throw new Error(`Filesystem operations are not supported by ${this.providerName}'s sandbox environment. ${this.providerName} sandboxes are designed for code execution only.`);\n }\n\n async remove(_path: string): Promise<void> {\n throw new Error(`Filesystem operations are not supported by ${this.providerName}'s sandbox environment. ${this.providerName} sandboxes are designed for code execution only.`);\n }\n}\n\n\n\n/**\n * Auto-generated filesystem implementation that wraps provider methods\n */\nclass SupportedFileSystem<TSandbox> implements SandboxFileSystem {\n constructor(\n private sandbox: TSandbox,\n private methods: NonNullable<SandboxMethods<TSandbox>['filesystem']>,\n private allMethods: SandboxMethods<TSandbox>\n ) {}\n\n async readFile(path: string): Promise<string> {\n return this.methods.readFile(this.sandbox, path, this.allMethods.runCommand);\n }\n\n async writeFile(path: string, content: string): Promise<void> {\n return this.methods.writeFile(this.sandbox, path, content, this.allMethods.runCommand);\n }\n\n async mkdir(path: string): Promise<void> {\n return this.methods.mkdir(this.sandbox, path, this.allMethods.runCommand);\n }\n\n async readdir(path: string): Promise<FileEntry[]> {\n return this.methods.readdir(this.sandbox, path, this.allMethods.runCommand);\n }\n\n async exists(path: string): Promise<boolean> {\n return this.methods.exists(this.sandbox, path, this.allMethods.runCommand);\n }\n\n async remove(path: string): Promise<void> {\n return this.methods.remove(this.sandbox, path, this.allMethods.runCommand);\n }\n}\n\n\n\n\n\n/**\n * Generated sandbox class - implements the Sandbox interface\n */\nclass GeneratedSandbox<TSandbox = any> implements Sandbox<TSandbox> {\n readonly sandboxId: string;\n readonly provider: string;\n readonly filesystem: SandboxFileSystem;\n\n constructor(\n private sandbox: TSandbox,\n sandboxId: string,\n providerName: string,\n private methods: SandboxMethods<TSandbox>,\n private config: any,\n private destroyMethod: (config: any, sandboxId: string) => Promise<void>,\n private providerInstance: Provider\n ) {\n this.sandboxId = sandboxId;\n this.provider = providerName;\n\n // Auto-detect filesystem support\n if (methods.filesystem) {\n this.filesystem = new SupportedFileSystem(sandbox, methods.filesystem, methods);\n } else {\n this.filesystem = new UnsupportedFileSystem(providerName);\n }\n }\n\n getInstance(): TSandbox {\n // Use provider-specific typed getInstance if available\n if (this.methods.getInstance) {\n return this.methods.getInstance(this.sandbox);\n }\n // Fallback to returning the sandbox directly\n return this.sandbox;\n }\n\n async runCode(code: string, runtime?: Runtime): Promise<ExecutionResult> {\n return await this.methods.runCode(this.sandbox, code, runtime, this.config);\n }\n\n async runCommand(command: string, args?: string[], options?: RunCommandOptions): Promise<ExecutionResult> {\n return await this.methods.runCommand(this.sandbox, command, args, options);\n }\n\n async getInfo(): Promise<SandboxInfo> {\n return await this.methods.getInfo(this.sandbox);\n }\n\n async getUrl(options: { port: number; protocol?: string }): Promise<string> {\n return await this.methods.getUrl(this.sandbox, options);\n }\n\n getProvider(): Provider<TSandbox> {\n return this.providerInstance;\n }\n\n async kill(): Promise<void> {\n // For backward compatibility, kill() delegates to destroy()\n await this.destroy();\n }\n\n async destroy(): Promise<void> {\n // Destroy via the provider's destroy method using our sandboxId\n await this.destroyMethod(this.config, this.sandboxId);\n }\n}\n\n/**\n * Auto-generated Sandbox Manager implementation\n */\nclass GeneratedSandboxManager<TSandbox, TConfig> implements ProviderSandboxManager<TSandbox> {\n private activeSandboxes: Map<string, GeneratedSandbox<TSandbox>> = new Map();\n\n constructor(\n private config: TConfig,\n private providerName: string,\n private methods: SandboxMethods<TSandbox, TConfig>,\n private providerInstance: Provider\n ) {}\n\n async create(options?: CreateSandboxOptions): Promise<Sandbox<TSandbox>> {\n const result = await this.methods.create(this.config, options);\n const sandbox = new GeneratedSandbox<TSandbox>(\n result.sandbox,\n result.sandboxId,\n this.providerName,\n this.methods,\n this.config,\n this.methods.destroy,\n this.providerInstance\n );\n \n this.activeSandboxes.set(result.sandboxId, sandbox);\n return sandbox;\n }\n\n async getById(sandboxId: string): Promise<Sandbox<TSandbox> | null> {\n // Check active sandboxes first\n const existing = this.activeSandboxes.get(sandboxId);\n if (existing) {\n return existing;\n }\n\n // Try to reconnect\n const result = await this.methods.getById(this.config, sandboxId);\n if (!result) {\n return null;\n }\n\n const sandbox = new GeneratedSandbox<TSandbox>(\n result.sandbox,\n result.sandboxId,\n this.providerName,\n this.methods,\n this.config,\n this.methods.destroy,\n this.providerInstance\n );\n \n this.activeSandboxes.set(result.sandboxId, sandbox);\n return sandbox;\n }\n\n async list(): Promise<Sandbox<TSandbox>[]> {\n const results = await this.methods.list(this.config);\n const sandboxes: Sandbox[] = [];\n\n for (const result of results) {\n let sandbox = this.activeSandboxes.get(result.sandboxId);\n if (!sandbox) {\n sandbox = new GeneratedSandbox<TSandbox>(\n result.sandbox,\n result.sandboxId,\n this.providerName,\n this.methods,\n this.config,\n this.methods.destroy,\n this.providerInstance\n );\n this.activeSandboxes.set(result.sandboxId, sandbox);\n }\n sandboxes.push(sandbox);\n }\n\n return sandboxes;\n }\n\n async destroy(sandboxId: string): Promise<void> {\n await this.methods.destroy(this.config, sandboxId);\n this.activeSandboxes.delete(sandboxId);\n }\n}\n\n/**\n * Auto-generated Provider implementation\n */\nclass GeneratedProvider<TSandbox, TConfig> implements Provider<TSandbox> {\n readonly name: string;\n readonly sandbox: ProviderSandboxManager<TSandbox>;\n readonly __sandboxType!: TSandbox; // Phantom type for TypeScript inference\n\n constructor(config: TConfig, providerConfig: ProviderConfig<TSandbox, TConfig>) {\n this.name = providerConfig.name;\n this.sandbox = new GeneratedSandboxManager(\n config,\n providerConfig.name,\n providerConfig.methods.sandbox,\n this\n );\n }\n}\n\n/**\n * Create a provider from method definitions\n * \n * Auto-generates all boilerplate classes and provides feature detection\n * based on which methods are implemented.\n */\nexport function createProvider<TSandbox, TConfig>(\n providerConfig: ProviderConfig<TSandbox, TConfig>\n): (config: TConfig) => Provider<TSandbox> {\n // Auto-inject default filesystem methods if none provided\n if (!providerConfig.methods.sandbox.filesystem) {\n providerConfig.methods.sandbox.filesystem = defaultFilesystemMethods;\n }\n\n return (config: TConfig) => {\n return new GeneratedProvider(config, providerConfig);\n };\n}"],"mappings":";AAwJO,IAAM,mBAAN,cAA+B,MAAM;AAAA,EAE1C,YAAmB,QAKhB;AACD,UAAM,4BAA4B,OAAO,QAAQ,EAAE;AANlC;AADnB,gBAAO;AAAA,EAQP;AACF;AAKO,SAAS,mBAAmB,OAA2C;AAC5E,SACE,OAAO,UAAU,YACjB,UAAU,QACV,UAAU,SACV,MAAM,SAAS,sBACf,YAAY;AAEhB;;;ACpKA,IAAM,iBAAN,MAA2C;AAAA,EAA3C;AACE,SAAQ,SAA+B;AACvC,SAAQ,aAGJ,EAAE,SAAS,OAAO,UAAU,KAAK;AAyDrC,mBAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAoBR,QAAQ,OAAO,WAA6F;AAC1G,cAAM,WAAW,UAAU,cAAc,UAAU,OAAO,WAAW,OAAO,WAAW,KAAK,mBAAmB;AAC/G,cAAM,UAAU,QAAQ;AACxB,cAAM,UAAU,MAAM,SAAS,QAAQ,OAAO,OAAO;AAIrD,YAAI,KAAK,WAAW,YAAY,C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