computesdk 1.3.1 → 1.4.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 +1 -2
- package/dist/index.d.ts +1 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -146,8 +146,7 @@ interface Sandbox {
|
|
|
146
146
|
/** Get the provider instance that created this sandbox */
|
|
147
147
|
getProvider(): Provider$1;
|
|
148
148
|
/** Get the native provider sandbox instance with proper typing */
|
|
149
|
-
getInstance():
|
|
150
|
-
getInstance<T>(): T;
|
|
149
|
+
getInstance<T = any>(): T;
|
|
151
150
|
/** Kill the sandbox */
|
|
152
151
|
kill(): Promise<void>;
|
|
153
152
|
/** Destroy the sandbox and clean up resources */
|
package/dist/index.d.ts
CHANGED
|
@@ -146,8 +146,7 @@ interface Sandbox {
|
|
|
146
146
|
/** Get the provider instance that created this sandbox */
|
|
147
147
|
getProvider(): Provider$1;
|
|
148
148
|
/** Get the native provider sandbox instance with proper typing */
|
|
149
|
-
getInstance():
|
|
150
|
-
getInstance<T>(): T;
|
|
149
|
+
getInstance<T = any>(): T;
|
|
151
150
|
/** Kill the sandbox */
|
|
152
151
|
kill(): Promise<void>;
|
|
153
152
|
/** Destroy the sandbox and clean up resources */
|
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(): any;\n getInstance<T>(): 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":";;;;;;;;;;;;;;;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IAAI,OAAO,WAAW,OAAO;AAAA,MACpD;AACA,gBAAU,KAAK,OAAO;AAAA,IACxB;AAEA,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,QAAQ,WAAkC;AAC9C,UAAM,KAAK,QAAQ,QAAQ,KAAK,QAAQ,SAAS;AACjD,SAAK,gBAAgB,OAAO,SAAS;AAAA,EACvC;AACF;AAKA,IAAM,oBAAN,MAA+D;AAAA,EAI7D,YAAY,QAAiB,gBAAmD;AAC9E,SAAK,OAAO,eAAe;AAC3B,SAAK,UAAU,IAAI;AAAA,MACjB;AAAA,MACA,eAAe;AAAA,MACf,eAAe,QAAQ;AAAA,MACvB;AAAA,IACF;AAAA,EACF;AACF;AAQO,SAAS,eACd,gBAC+B;AAE/B,MAAI,CAAC,eAAe,QAAQ,QAAQ,YAAY;AAC9C,mBAAe,QAAQ,QAAQ,aAAa;AAAA,EAC9C;AAEA,SAAO,CAAC,WAAoB;AAC1B,WAAO,IAAI,kBAAkB,QAAQ,cAAc;AAAA,EACrD;AACF;","names":["sandbox"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/types/sandbox.ts","../src/compute.ts","../src/request-handler.ts","../src/factory.ts"],"sourcesContent":["/**\n * ComputeSDK Core\n * \n * Clean Provider/Sandbox separation architecture with extensible compute.* API\n */\n\n// Export all types\nexport * from './types';\n\n// Export compute singleton - the main API\nexport { compute } 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,4BAA4B,OAAO,QAAQ,EAAE;AANlC;AADnB,gBAAO;AAAA,EAQP;AACF;AAKO,SAAS,mBAAmB,OAA2C;AAC5E,SACE,OAAO,UA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N,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/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types/sandbox.ts","../src/compute.ts","../src/request-handler.ts","../src/factory.ts"],"sourcesContent":["/**\n * Sandbox Types\n * \n * Types related to sandbox execution, filesystem, terminal operations\n */\n\n// Forward declaration to avoid circular dependency\ninterface Provider {\n readonly name: string;\n readonly sandbox: any; // Will be properly typed when imported together\n}\n\n/**\n * 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(): any;\n getInstance<T>(): 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,eAAO,MAAM,SAAS,QAAQ,OAAO,OAAO;AAAA,MAC9C;AAAA;AAAA;AAAA;AAAA,MAKA,SAAS,OAAO,qBAAwC,cAAgD;AACtG,YAAI,OAAO,wBAAwB,UAAU;AAE3C,gBAAM,WAAW,KAAK,mBAAmB;AACzC,iBAAO,MAAM,SAAS,QAAQ,QAAQ,mBAAmB;AAAA,QAC3D,OAAO;AAEL,cAAI,CAAC,WAAW;AACd,kBAAM,IAAI,MAAM,k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UAAM,YAAuB,CAAC;AAE9B,eAAW,UAAU,SAAS;AAC5B,UAAI,UAAU,KAAK,gBAAgB,IAAI,OAAO,SAAS;AACvD,UAAI,CAAC,SAAS;AACZ,kBAAU,IAAI;AAAA,UACZ,OAAO;AAAA,UACP,OAAO;AAAA,UACP,KAAK;AAAA,UACL,KAAK;AAAA,UACL,KAAK;AAAA,UACL,KAAK,QAAQ;AAAA,UACb,KAAK;AAAA,QACP;AACA,aAAK,gBAAgB,IAAI,OAAO,WAAW,OAAO;AAAA,MACpD;AACA,gBAAU,KAAK,OAAO;AAAA,IACxB;AAEA,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,QAAQ,WAAkC;AAC9C,UAAM,KAAK,QAAQ,QAAQ,KAAK,QAAQ,SAAS;AACjD,SAAK,gBAAgB,OAAO,SAAS;AAAA,EACvC;AACF;AAKA,IAAM,oBAAN,MAA+D;AAAA,EAI7D,YAAY,QAAiB,gBAAmD;AAC9E,SAAK,OAAO,eAAe;AAC3B,SAAK,UAAU,IAAI;AAAA,MACjB;AAAA,MACA,eAAe;AAAA,MACf,eAAe,QAAQ;AAAA,MACvB;AAAA,IACF;AAAA,EACF;AACF;AAQO,SAAS,eACd,gBAC+B;AAE/B,MAAI,CAAC,eAAe,QAAQ,QAAQ,YAAY;AAC9C,mBAAe,QAAQ,QAAQ,aAAa;AAAA,EAC9C;AAEA,SAAO,CAAC,WAAoB;AAC1B,WAAO,IAAI,kBAAkB,QAAQ,cAAc;AAAA,EACrD;AACF;","names":["sandbox"]}
|
|
1
|
+
{"version":3,"sources":["../src/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;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