computesdk 1.4.0 → 1.5.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 CHANGED
@@ -7,6 +7,17 @@ interface Provider$1 {
7
7
  readonly name: string;
8
8
  readonly sandbox: any;
9
9
  }
10
+ /**
11
+ * Utility type to extract the native instance type from a provider
12
+ * This enables proper typing for getInstance() calls by looking at the provider's internal types
13
+ */
14
+ type ExtractSandboxInstanceType<TProvider extends Provider$1> = TProvider extends Provider$1 ? TProvider extends {
15
+ sandbox: {
16
+ create(): Promise<infer TSandbox>;
17
+ };
18
+ } ? (TSandbox extends {
19
+ getInstance(): infer TInstance;
20
+ } ? TInstance : any) : any : any;
10
21
  /**
11
22
  * Supported runtime environments
12
23
  */
@@ -15,6 +26,13 @@ type Runtime = 'node' | 'python';
15
26
  * Sandbox status types
16
27
  */
17
28
  type SandboxStatus = 'running' | 'stopped' | 'error';
29
+ /**
30
+ * Options for running commands
31
+ */
32
+ interface RunCommandOptions {
33
+ /** Run command in background (non-blocking) */
34
+ background?: boolean;
35
+ }
18
36
  /**
19
37
  * Result of code execution
20
38
  */
@@ -31,6 +49,10 @@ interface ExecutionResult {
31
49
  sandboxId: string;
32
50
  /** Provider that executed the code */
33
51
  provider: string;
52
+ /** Process ID for background jobs (if applicable) */
53
+ pid?: number;
54
+ /** Whether this command is running in background */
55
+ isBackground?: boolean;
34
56
  }
35
57
  /**
36
58
  * Information about a sandbox
@@ -135,7 +157,7 @@ interface Sandbox {
135
157
  /** Execute code in the sandbox */
136
158
  runCode(code: string, runtime?: Runtime): Promise<ExecutionResult>;
137
159
  /** Execute shell commands */
138
- runCommand(command: string, args?: string[]): Promise<ExecutionResult>;
160
+ runCommand(command: string, args?: string[], options?: RunCommandOptions): Promise<ExecutionResult>;
139
161
  /** Get information about the sandbox */
140
162
  getInfo(): Promise<SandboxInfo>;
141
163
  /** Get URL for accessing the sandbox on a specific port */
@@ -154,6 +176,16 @@ interface Sandbox {
154
176
  /** File system operations */
155
177
  readonly filesystem: SandboxFileSystem;
156
178
  }
179
+ /**
180
+ * Typed sandbox interface that preserves the provider's native instance type
181
+ */
182
+ interface TypedSandbox<TProvider extends Provider$1> extends Sandbox {
183
+ /** Get the provider instance that created this sandbox with proper typing */
184
+ getProvider(): TProvider;
185
+ /** Get the native provider sandbox instance with proper typing */
186
+ getInstance(): ExtractSandboxInstanceType<TProvider>;
187
+ getInstance<T>(): T;
188
+ }
157
189
 
158
190
  /**
159
191
  * Provider Types
@@ -186,11 +218,11 @@ interface Provider {
186
218
  /**
187
219
  * Configuration for the compute singleton
188
220
  */
189
- interface ComputeConfig {
221
+ interface ComputeConfig<TProvider extends Provider = Provider> {
190
222
  /** Default provider to use when none is specified */
191
- defaultProvider?: Provider;
223
+ defaultProvider?: TProvider;
192
224
  /** @deprecated Use defaultProvider instead. Kept for backwards compatibility */
193
- provider?: Provider;
225
+ provider?: TProvider;
194
226
  }
195
227
  /**
196
228
  * Parameters for compute.sandbox.create()
@@ -211,11 +243,11 @@ interface CreateSandboxParamsWithOptionalProvider {
211
243
  options?: CreateSandboxOptions;
212
244
  }
213
245
  /**
214
- * Compute singleton interface
246
+ * Base Compute API interface (non-generic)
215
247
  */
216
248
  interface ComputeAPI {
217
249
  /** Configuration management */
218
- setConfig(config: ComputeConfig): void;
250
+ setConfig<TProvider extends Provider>(config: ComputeConfig<TProvider>): void;
219
251
  getConfig(): ComputeConfig | null;
220
252
  clearConfig(): void;
221
253
  sandbox: {
@@ -262,6 +294,10 @@ interface ComputeRequest {
262
294
  runtime?: Runtime;
263
295
  path?: string;
264
296
  content?: string;
297
+ /** Command options (for runCommand action) */
298
+ commandOptions?: {
299
+ background?: boolean;
300
+ };
265
301
  /** Sandbox creation options */
266
302
  options?: {
267
303
  runtime?: Runtime;
@@ -299,6 +335,15 @@ interface HandleComputeRequestParams {
299
335
  * from simple method definitions with automatic feature detection.
300
336
  */
301
337
 
338
+ /**
339
+ * Helper function to handle background command execution
340
+ * Providers can use this to implement background job support
341
+ */
342
+ declare function createBackgroundCommand(command: string, args?: string[], options?: RunCommandOptions): {
343
+ command: string;
344
+ args: string[];
345
+ isBackground: boolean;
346
+ };
302
347
  /**
303
348
  * Flat sandbox method implementations - all operations in one place
304
349
  */
@@ -317,7 +362,7 @@ interface SandboxMethods<TSandbox = any, TConfig = any> {
317
362
  }>>;
318
363
  destroy: (config: TConfig, sandboxId: string) => Promise<void>;
319
364
  runCode: (sandbox: TSandbox, code: string, runtime?: Runtime, config?: TConfig) => Promise<ExecutionResult>;
320
- runCommand: (sandbox: TSandbox, command: string, args?: string[]) => Promise<ExecutionResult>;
365
+ runCommand: (sandbox: TSandbox, command: string, args?: string[], options?: RunCommandOptions) => Promise<ExecutionResult>;
321
366
  getInfo: (sandbox: TSandbox) => Promise<SandboxInfo>;
322
367
  getUrl: (sandbox: TSandbox, options: {
323
368
  port: number;
@@ -350,4 +395,4 @@ interface ProviderConfig<TSandbox = any, TConfig = any> {
350
395
  */
351
396
  declare function createProvider<TSandbox, TConfig>(providerConfig: ProviderConfig<TSandbox, TConfig>): (config: TConfig) => Provider;
352
397
 
353
- export { CommandExitError, type ComputeAPI, type ComputeConfig, type ComputeRequest, type ComputeResponse, type CreateSandboxOptions, type CreateSandboxParams, type CreateSandboxParamsWithOptionalProvider, type ExecutionResult, type FileEntry, type HandleComputeRequestParams, type Provider, type ProviderConfig, type ProviderSandboxManager, type Runtime, type Sandbox, type SandboxFileSystem, type SandboxInfo, type SandboxMethods, type SandboxStatus, compute, createProvider, handleComputeRequest, isCommandExitError };
398
+ 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 TypedSandbox, compute, createBackgroundCommand, createProvider, handleComputeRequest, isCommandExitError };
package/dist/index.d.ts CHANGED
@@ -7,6 +7,17 @@ interface Provider$1 {
7
7
  readonly name: string;
8
8
  readonly sandbox: any;
9
9
  }
10
+ /**
11
+ * Utility type to extract the native instance type from a provider
12
+ * This enables proper typing for getInstance() calls by looking at the provider's internal types
13
+ */
14
+ type ExtractSandboxInstanceType<TProvider extends Provider$1> = TProvider extends Provider$1 ? TProvider extends {
15
+ sandbox: {
16
+ create(): Promise<infer TSandbox>;
17
+ };
18
+ } ? (TSandbox extends {
19
+ getInstance(): infer TInstance;
20
+ } ? TInstance : any) : any : any;
10
21
  /**
11
22
  * Supported runtime environments
12
23
  */
@@ -15,6 +26,13 @@ type Runtime = 'node' | 'python';
15
26
  * Sandbox status types
16
27
  */
17
28
  type SandboxStatus = 'running' | 'stopped' | 'error';
29
+ /**
30
+ * Options for running commands
31
+ */
32
+ interface RunCommandOptions {
33
+ /** Run command in background (non-blocking) */
34
+ background?: boolean;
35
+ }
18
36
  /**
19
37
  * Result of code execution
20
38
  */
@@ -31,6 +49,10 @@ interface ExecutionResult {
31
49
  sandboxId: string;
32
50
  /** Provider that executed the code */
33
51
  provider: string;
52
+ /** Process ID for background jobs (if applicable) */
53
+ pid?: number;
54
+ /** Whether this command is running in background */
55
+ isBackground?: boolean;
34
56
  }
35
57
  /**
36
58
  * Information about a sandbox
@@ -135,7 +157,7 @@ interface Sandbox {
135
157
  /** Execute code in the sandbox */
136
158
  runCode(code: string, runtime?: Runtime): Promise<ExecutionResult>;
137
159
  /** Execute shell commands */
138
- runCommand(command: string, args?: string[]): Promise<ExecutionResult>;
160
+ runCommand(command: string, args?: string[], options?: RunCommandOptions): Promise<ExecutionResult>;
139
161
  /** Get information about the sandbox */
140
162
  getInfo(): Promise<SandboxInfo>;
141
163
  /** Get URL for accessing the sandbox on a specific port */
@@ -154,6 +176,16 @@ interface Sandbox {
154
176
  /** File system operations */
155
177
  readonly filesystem: SandboxFileSystem;
156
178
  }
179
+ /**
180
+ * Typed sandbox interface that preserves the provider's native instance type
181
+ */
182
+ interface TypedSandbox<TProvider extends Provider$1> extends Sandbox {
183
+ /** Get the provider instance that created this sandbox with proper typing */
184
+ getProvider(): TProvider;
185
+ /** Get the native provider sandbox instance with proper typing */
186
+ getInstance(): ExtractSandboxInstanceType<TProvider>;
187
+ getInstance<T>(): T;
188
+ }
157
189
 
158
190
  /**
159
191
  * Provider Types
@@ -186,11 +218,11 @@ interface Provider {
186
218
  /**
187
219
  * Configuration for the compute singleton
188
220
  */
189
- interface ComputeConfig {
221
+ interface ComputeConfig<TProvider extends Provider = Provider> {
190
222
  /** Default provider to use when none is specified */
191
- defaultProvider?: Provider;
223
+ defaultProvider?: TProvider;
192
224
  /** @deprecated Use defaultProvider instead. Kept for backwards compatibility */
193
- provider?: Provider;
225
+ provider?: TProvider;
194
226
  }
195
227
  /**
196
228
  * Parameters for compute.sandbox.create()
@@ -211,11 +243,11 @@ interface CreateSandboxParamsWithOptionalProvider {
211
243
  options?: CreateSandboxOptions;
212
244
  }
213
245
  /**
214
- * Compute singleton interface
246
+ * Base Compute API interface (non-generic)
215
247
  */
216
248
  interface ComputeAPI {
217
249
  /** Configuration management */
218
- setConfig(config: ComputeConfig): void;
250
+ setConfig<TProvider extends Provider>(config: ComputeConfig<TProvider>): void;
219
251
  getConfig(): ComputeConfig | null;
220
252
  clearConfig(): void;
221
253
  sandbox: {
@@ -262,6 +294,10 @@ interface ComputeRequest {
262
294
  runtime?: Runtime;
263
295
  path?: string;
264
296
  content?: string;
297
+ /** Command options (for runCommand action) */
298
+ commandOptions?: {
299
+ background?: boolean;
300
+ };
265
301
  /** Sandbox creation options */
266
302
  options?: {
267
303
  runtime?: Runtime;
@@ -299,6 +335,15 @@ interface HandleComputeRequestParams {
299
335
  * from simple method definitions with automatic feature detection.
300
336
  */
301
337
 
338
+ /**
339
+ * Helper function to handle background command execution
340
+ * Providers can use this to implement background job support
341
+ */
342
+ declare function createBackgroundCommand(command: string, args?: string[], options?: RunCommandOptions): {
343
+ command: string;
344
+ args: string[];
345
+ isBackground: boolean;
346
+ };
302
347
  /**
303
348
  * Flat sandbox method implementations - all operations in one place
304
349
  */
@@ -317,7 +362,7 @@ interface SandboxMethods<TSandbox = any, TConfig = any> {
317
362
  }>>;
318
363
  destroy: (config: TConfig, sandboxId: string) => Promise<void>;
319
364
  runCode: (sandbox: TSandbox, code: string, runtime?: Runtime, config?: TConfig) => Promise<ExecutionResult>;
320
- runCommand: (sandbox: TSandbox, command: string, args?: string[]) => Promise<ExecutionResult>;
365
+ runCommand: (sandbox: TSandbox, command: string, args?: string[], options?: RunCommandOptions) => Promise<ExecutionResult>;
321
366
  getInfo: (sandbox: TSandbox) => Promise<SandboxInfo>;
322
367
  getUrl: (sandbox: TSandbox, options: {
323
368
  port: number;
@@ -350,4 +395,4 @@ interface ProviderConfig<TSandbox = any, TConfig = any> {
350
395
  */
351
396
  declare function createProvider<TSandbox, TConfig>(providerConfig: ProviderConfig<TSandbox, TConfig>): (config: TConfig) => Provider;
352
397
 
353
- export { CommandExitError, type ComputeAPI, type ComputeConfig, type ComputeRequest, type ComputeResponse, type CreateSandboxOptions, type CreateSandboxParams, type CreateSandboxParamsWithOptionalProvider, type ExecutionResult, type FileEntry, type HandleComputeRequestParams, type Provider, type ProviderConfig, type ProviderSandboxManager, type Runtime, type Sandbox, type SandboxFileSystem, type SandboxInfo, type SandboxMethods, type SandboxStatus, compute, createProvider, handleComputeRequest, isCommandExitError };
398
+ 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 TypedSandbox, compute, createBackgroundCommand, createProvider, handleComputeRequest, isCommandExitError };
package/dist/index.js CHANGED
@@ -22,6 +22,7 @@ var index_exports = {};
22
22
  __export(index_exports, {
23
23
  CommandExitError: () => CommandExitError,
24
24
  compute: () => compute,
25
+ createBackgroundCommand: () => createBackgroundCommand,
25
26
  createProvider: () => createProvider,
26
27
  handleComputeRequest: () => handleComputeRequest,
27
28
  isCommandExitError: () => isCommandExitError
@@ -44,6 +45,7 @@ function isCommandExitError(error) {
44
45
  var ComputeManager = class {
45
46
  constructor() {
46
47
  this.config = null;
48
+ this.typedState = { isTyped: false, provider: null };
47
49
  this.sandbox = {
48
50
  /**
49
51
  * Create a sandbox from a provider (or default provider if configured)
@@ -67,7 +69,11 @@ var ComputeManager = class {
67
69
  create: async (params) => {
68
70
  const provider = params && "provider" in params && params.provider ? params.provider : this.getDefaultProvider();
69
71
  const options = params?.options;
70
- return await provider.sandbox.create(options);
72
+ const sandbox = await provider.sandbox.create(options);
73
+ if (this.typedState.isTyped && (!params || !("provider" in params && params.provider))) {
74
+ return sandbox;
75
+ }
76
+ return sandbox;
71
77
  },
72
78
  /**
73
79
  * Get an existing sandbox by ID from a provider (or default provider if configured)
@@ -75,7 +81,11 @@ var ComputeManager = class {
75
81
  getById: async (providerOrSandboxId, sandboxId) => {
76
82
  if (typeof providerOrSandboxId === "string") {
77
83
  const provider = this.getDefaultProvider();
78
- return await provider.sandbox.getById(providerOrSandboxId);
84
+ const sandbox = await provider.sandbox.getById(providerOrSandboxId);
85
+ if (this.typedState.isTyped && sandbox) {
86
+ return sandbox;
87
+ }
88
+ return sandbox;
79
89
  } else {
80
90
  if (!sandboxId) {
81
91
  throw new Error("sandboxId is required when provider is specified");
@@ -88,7 +98,11 @@ var ComputeManager = class {
88
98
  */
89
99
  list: async (provider) => {
90
100
  const actualProvider = provider || this.getDefaultProvider();
91
- return await actualProvider.sandbox.list();
101
+ const sandboxes = await actualProvider.sandbox.list();
102
+ if (this.typedState.isTyped && !provider) {
103
+ return sandboxes;
104
+ }
105
+ return sandboxes;
92
106
  },
93
107
  /**
94
108
  * Destroy a sandbox via a provider (or default provider if configured)
@@ -107,7 +121,7 @@ var ComputeManager = class {
107
121
  };
108
122
  }
109
123
  /**
110
- * Set default configuration
124
+ * Set default configuration with generic type preservation
111
125
  */
112
126
  setConfig(config) {
113
127
  if (!config.defaultProvider && !config.provider) {
@@ -121,6 +135,10 @@ var ComputeManager = class {
121
135
  provider: actualProvider,
122
136
  defaultProvider: actualProvider
123
137
  };
138
+ this.typedState = {
139
+ isTyped: true,
140
+ provider: actualProvider
141
+ };
124
142
  }
125
143
  /**
126
144
  * Get current configuration
@@ -138,12 +156,13 @@ var ComputeManager = class {
138
156
  * Get the default provider, throwing if not configured
139
157
  */
140
158
  getDefaultProvider() {
141
- if (!this.config?.provider) {
159
+ const provider = this.config?.defaultProvider || this.config?.provider;
160
+ if (!provider) {
142
161
  throw new Error(
143
162
  "No default provider configured. Either call compute.setConfig({ defaultProvider }) or pass provider explicitly."
144
163
  );
145
164
  }
146
- return this.config.provider;
165
+ return provider;
147
166
  }
148
167
  // Future: compute.blob.*, compute.database.*, compute.git.* will be added here
149
168
  // blob = new BlobManager();
@@ -231,7 +250,7 @@ async function executeAction(body, provider) {
231
250
  }
232
251
  if (action === "compute.sandbox.runCommand") {
233
252
  if (!body.command) throw new Error("command is required");
234
- const result = await sandbox.runCommand(body.command, body.args);
253
+ const result = await sandbox.runCommand(body.command, body.args, body.commandOptions);
235
254
  return {
236
255
  success: true,
237
256
  sandboxId,
@@ -240,7 +259,9 @@ async function executeAction(body, provider) {
240
259
  stdout: result.stdout,
241
260
  stderr: result.stderr,
242
261
  exitCode: result.exitCode,
243
- executionTime: result.executionTime
262
+ executionTime: result.executionTime,
263
+ ...result.isBackground && { isBackground: result.isBackground },
264
+ ...result.pid && { pid: result.pid }
244
265
  }
245
266
  };
246
267
  }
@@ -354,6 +375,17 @@ async function handleComputeRequest(paramsOrRequestOrBody, provider) {
354
375
  }
355
376
 
356
377
  // src/factory.ts
378
+ function createBackgroundCommand(command, args = [], options) {
379
+ if (!options?.background) {
380
+ return { command, args, isBackground: false };
381
+ }
382
+ const fullCommand = args.length > 0 ? `${command} ${args.join(" ")}` : command;
383
+ return {
384
+ command: "sh",
385
+ args: ["-c", `${fullCommand} &`],
386
+ isBackground: true
387
+ };
388
+ }
357
389
  var defaultFilesystemMethods = {
358
390
  readFile: async (sandbox, path, runCommand) => {
359
391
  const result = await runCommand(sandbox, "cat", [path]);
@@ -496,8 +528,8 @@ var GeneratedSandbox = class {
496
528
  async runCode(code, runtime) {
497
529
  return await this.methods.runCode(this.sandbox, code, runtime, this.config);
498
530
  }
499
- async runCommand(command, args) {
500
- return await this.methods.runCommand(this.sandbox, command, args);
531
+ async runCommand(command, args, options) {
532
+ return await this.methods.runCommand(this.sandbox, command, args, options);
501
533
  }
502
534
  async getInfo() {
503
535
  return await this.methods.getInfo(this.sandbox);
@@ -607,6 +639,7 @@ function createProvider(providerConfig) {
607
639
  0 && (module.exports = {
608
640
  CommandExitError,
609
641
  compute,
642
+ createBackgroundCommand,
610
643
  createProvider,
611
644
  handleComputeRequest,
612
645
  isCommandExitError
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 } 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 } 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 * 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 * 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}\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[]): 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 * 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 } from './types';\n\n/**\n * Compute singleton implementation - orchestrates all compute operations\n */\nclass ComputeManager implements ComputeAPI {\n private config: ComputeConfig | null = null;\n\n /**\n * Set default configuration\n */\n setConfig(config: ComputeConfig): 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 provider for internal use (for backwards compatibility)\n const actualProvider = config.defaultProvider || config.provider!;\n this.config = {\n provider: actualProvider,\n defaultProvider: 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 if (!this.config?.provider) {\n throw new Error(\n 'No default provider configured. Either call compute.setConfig({ defaultProvider }) or pass provider explicitly.'\n );\n }\n return this.config.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 return await provider.sandbox.create(options);\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 return await provider.sandbox.getById(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.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 return await actualProvider.sandbox.list();\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\n */\nexport const compute: ComputeAPI = new ComputeManager();\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 /** 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);\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 // 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} from './types/index.js';\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[]) => 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[]): Promise<ExecutionResult> {\n return await this.methods.runCommand(this.sandbox, command, args);\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;;;ACqHO,IAAM,mBAAN,cAA+B,MAAM;AAAA,EAE1C,YAAmB,QAKhB;AACD,UAAM,4B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AM,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 } 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 } 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\n */\nexport const compute: ComputeAPI = new ComputeManager();\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;A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ACf,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"]}
package/dist/index.mjs CHANGED
@@ -14,6 +14,7 @@ function isCommandExitError(error) {
14
14
  var ComputeManager = class {
15
15
  constructor() {
16
16
  this.config = null;
17
+ this.typedState = { isTyped: false, provider: null };
17
18
  this.sandbox = {
18
19
  /**
19
20
  * Create a sandbox from a provider (or default provider if configured)
@@ -37,7 +38,11 @@ var ComputeManager = class {
37
38
  create: async (params) => {
38
39
  const provider = params && "provider" in params && params.provider ? params.provider : this.getDefaultProvider();
39
40
  const options = params?.options;
40
- return await provider.sandbox.create(options);
41
+ const sandbox = await provider.sandbox.create(options);
42
+ if (this.typedState.isTyped && (!params || !("provider" in params && params.provider))) {
43
+ return sandbox;
44
+ }
45
+ return sandbox;
41
46
  },
42
47
  /**
43
48
  * Get an existing sandbox by ID from a provider (or default provider if configured)
@@ -45,7 +50,11 @@ var ComputeManager = class {
45
50
  getById: async (providerOrSandboxId, sandboxId) => {
46
51
  if (typeof providerOrSandboxId === "string") {
47
52
  const provider = this.getDefaultProvider();
48
- return await provider.sandbox.getById(providerOrSandboxId);
53
+ const sandbox = await provider.sandbox.getById(providerOrSandboxId);
54
+ if (this.typedState.isTyped && sandbox) {
55
+ return sandbox;
56
+ }
57
+ return sandbox;
49
58
  } else {
50
59
  if (!sandboxId) {
51
60
  throw new Error("sandboxId is required when provider is specified");
@@ -58,7 +67,11 @@ var ComputeManager = class {
58
67
  */
59
68
  list: async (provider) => {
60
69
  const actualProvider = provider || this.getDefaultProvider();
61
- return await actualProvider.sandbox.list();
70
+ const sandboxes = await actualProvider.sandbox.list();
71
+ if (this.typedState.isTyped && !provider) {
72
+ return sandboxes;
73
+ }
74
+ return sandboxes;
62
75
  },
63
76
  /**
64
77
  * Destroy a sandbox via a provider (or default provider if configured)
@@ -77,7 +90,7 @@ var ComputeManager = class {
77
90
  };
78
91
  }
79
92
  /**
80
- * Set default configuration
93
+ * Set default configuration with generic type preservation
81
94
  */
82
95
  setConfig(config) {
83
96
  if (!config.defaultProvider && !config.provider) {
@@ -91,6 +104,10 @@ var ComputeManager = class {
91
104
  provider: actualProvider,
92
105
  defaultProvider: actualProvider
93
106
  };
107
+ this.typedState = {
108
+ isTyped: true,
109
+ provider: actualProvider
110
+ };
94
111
  }
95
112
  /**
96
113
  * Get current configuration
@@ -108,12 +125,13 @@ var ComputeManager = class {
108
125
  * Get the default provider, throwing if not configured
109
126
  */
110
127
  getDefaultProvider() {
111
- if (!this.config?.provider) {
128
+ const provider = this.config?.defaultProvider || this.config?.provider;
129
+ if (!provider) {
112
130
  throw new Error(
113
131
  "No default provider configured. Either call compute.setConfig({ defaultProvider }) or pass provider explicitly."
114
132
  );
115
133
  }
116
- return this.config.provider;
134
+ return provider;
117
135
  }
118
136
  // Future: compute.blob.*, compute.database.*, compute.git.* will be added here
119
137
  // blob = new BlobManager();
@@ -201,7 +219,7 @@ async function executeAction(body, provider) {
201
219
  }
202
220
  if (action === "compute.sandbox.runCommand") {
203
221
  if (!body.command) throw new Error("command is required");
204
- const result = await sandbox.runCommand(body.command, body.args);
222
+ const result = await sandbox.runCommand(body.command, body.args, body.commandOptions);
205
223
  return {
206
224
  success: true,
207
225
  sandboxId,
@@ -210,7 +228,9 @@ async function executeAction(body, provider) {
210
228
  stdout: result.stdout,
211
229
  stderr: result.stderr,
212
230
  exitCode: result.exitCode,
213
- executionTime: result.executionTime
231
+ executionTime: result.executionTime,
232
+ ...result.isBackground && { isBackground: result.isBackground },
233
+ ...result.pid && { pid: result.pid }
214
234
  }
215
235
  };
216
236
  }
@@ -324,6 +344,17 @@ async function handleComputeRequest(paramsOrRequestOrBody, provider) {
324
344
  }
325
345
 
326
346
  // src/factory.ts
347
+ function createBackgroundCommand(command, args = [], options) {
348
+ if (!options?.background) {
349
+ return { command, args, isBackground: false };
350
+ }
351
+ const fullCommand = args.length > 0 ? `${command} ${args.join(" ")}` : command;
352
+ return {
353
+ command: "sh",
354
+ args: ["-c", `${fullCommand} &`],
355
+ isBackground: true
356
+ };
357
+ }
327
358
  var defaultFilesystemMethods = {
328
359
  readFile: async (sandbox, path, runCommand) => {
329
360
  const result = await runCommand(sandbox, "cat", [path]);
@@ -466,8 +497,8 @@ var GeneratedSandbox = class {
466
497
  async runCode(code, runtime) {
467
498
  return await this.methods.runCode(this.sandbox, code, runtime, this.config);
468
499
  }
469
- async runCommand(command, args) {
470
- return await this.methods.runCommand(this.sandbox, command, args);
500
+ async runCommand(command, args, options) {
501
+ return await this.methods.runCommand(this.sandbox, command, args, options);
471
502
  }
472
503
  async getInfo() {
473
504
  return await this.methods.getInfo(this.sandbox);
@@ -576,6 +607,7 @@ function createProvider(providerConfig) {
576
607
  export {
577
608
  CommandExitError,
578
609
  compute,
610
+ createBackgroundCommand,
579
611
  createProvider,
580
612
  handleComputeRequest,
581
613
  isCommandExitError
@@ -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 * 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 * 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}\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[]): 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 * 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 } from './types';\n\n/**\n * Compute singleton implementation - orchestrates all compute operations\n */\nclass ComputeManager implements ComputeAPI {\n private config: ComputeConfig | null = null;\n\n /**\n * Set default configuration\n */\n setConfig(config: ComputeConfig): 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 provider for internal use (for backwards compatibility)\n const actualProvider = config.defaultProvider || config.provider!;\n this.config = {\n provider: actualProvider,\n defaultProvider: 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 if (!this.config?.provider) {\n throw new Error(\n 'No default provider configured. Either call compute.setConfig({ defaultProvider }) or pass provider explicitly.'\n );\n }\n return this.config.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 return await provider.sandbox.create(options);\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 return await provider.sandbox.getById(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.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 return await actualProvider.sandbox.list();\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\n */\nexport const compute: ComputeAPI = new ComputeManager();\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 /** 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);\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 // 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} from './types/index.js';\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[]) => 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[]): Promise<ExecutionResult> {\n return await this.methods.runCommand(this.sandbox, command, args);\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":";AAqHO,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;;;ACjIA,IAAM,iBAAN,MAA2C;AAAA,EAA3C;AACE,SAAQ,SAA+B;AAkDvC,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,eA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]}
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 } 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\n */\nexport const compute: ComputeAPI = new ComputeManager();\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,UAAU,MAAM,SAAS,QAAQ,QAAQ,mBAAmB;AAGlE,cAAI,KAAK,WAAW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AQ,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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "computesdk",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
4
4
  "description": "A free and open-source toolkit for running other people's code in your applications.",
5
5
  "author": "Garrison",
6
6
  "license": "MIT",