computesdk 1.8.0 → 1.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -60,7 +60,7 @@ async function authorizeApiKey(apiKey) {
|
|
|
60
60
|
throw new Error(`License authorization failed: ${response.statusText}`);
|
|
61
61
|
}
|
|
62
62
|
const data = await response.json();
|
|
63
|
-
if (!data.
|
|
63
|
+
if (!data.access_token) {
|
|
64
64
|
throw new Error("No JWT token received from license server");
|
|
65
65
|
}
|
|
66
66
|
if (!data.sandbox_url) {
|
|
@@ -70,7 +70,7 @@ async function authorizeApiKey(apiKey) {
|
|
|
70
70
|
throw new Error("No preview_url received from license server");
|
|
71
71
|
}
|
|
72
72
|
return {
|
|
73
|
-
jwt: data.
|
|
73
|
+
jwt: data.access_token,
|
|
74
74
|
sandbox_url: data.sandbox_url,
|
|
75
75
|
preview_url: data.preview_url
|
|
76
76
|
};
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/types/sandbox.ts","../src/compute.ts","../src/request-handler.ts","../src/factory.ts"],"sourcesContent":["/**\n * ComputeSDK Core\n * \n * Clean Provider/Sandbox separation architecture with extensible compute.* API\n */\n\n// Export all types\nexport * from './types';\n\n// Export compute singleton - the main API\nexport { compute, createCompute } from './compute';\n\n// Export request handler for web framework integration\nexport { handleComputeRequest } from './request-handler';\n\n// Export compute request/response types\nexport type {\n ComputeRequest,\n ComputeResponse,\n HandleComputeRequestParams\n} from './request-handler';\n\n\n\n// Export provider factory for creating custom providers\nexport { createProvider, createBackgroundCommand } from './factory';\nexport type { ProviderConfig, SandboxMethods, TemplateMethods, SnapshotMethods } from './factory';\n\n// Export error handling utilities (explicitly for clarity)\nexport { CommandExitError, isCommandExitError } from './types/sandbox';\n\n// Test suite is available separately via @computesdk/test-utils package\n","/**\n * Sandbox Types\n * \n * Types related to sandbox execution, filesystem, terminal operations\n */\n\n// Forward declaration to avoid circular dependency\ninterface Provider {\n readonly name: string;\n readonly sandbox: any; // Will be properly typed when imported together\n}\n\n/**\n * Type mapping for provider names to their sandbox types\n * Manually defined for known providers since declaration merging isn't working reliably\n */\nexport interface ProviderSandboxTypeMap {\n e2b: any; // We can't import the E2B type directly, but we'll handle it differently\n vercel: any;\n daytona: any;\n}\n\n/**\n * Utility type to extract the native instance type from a provider\n * Uses provider name and manual type inference\n */\nexport type ExtractSandboxInstanceType<TProvider extends Provider> = \n TProvider extends { readonly name: 'e2b' }\n ? any // For now, let's just try to make the runtime casting work\n : TProvider extends { readonly name: 'vercel' }\n ? any\n : TProvider extends { readonly name: 'daytona' }\n ? any\n : any;\n\n/**\n * Supported runtime environments\n */\nexport type Runtime = 'node' | 'python';\n\n/**\n * Sandbox status types\n */\nexport type SandboxStatus = 'running' | 'stopped' | 'error';\n\n/**\n * Options for running commands\n */\nexport interface RunCommandOptions {\n /** Run command in background (non-blocking) */\n background?: boolean;\n}\n\n/**\n * Result of code execution\n */\nexport interface ExecutionResult {\n /** Standard output from the execution */\n stdout: string;\n /** Standard error from the execution */\n stderr: string;\n /** Exit code from the execution */\n exitCode: number;\n /** Time taken for execution in milliseconds */\n executionTime: number;\n /** ID of the sandbox where the code was executed */\n sandboxId: string;\n /** Provider that executed the code */\n provider: string;\n /** Process ID for background jobs (if applicable) */\n pid?: number;\n /** Whether this command is running in background */\n isBackground?: boolean;\n}\n\n/**\n * Information about a sandbox\n */\nexport interface SandboxInfo {\n /** Unique identifier for the sandbox */\n id: string;\n /** Provider hosting the sandbox */\n provider: string;\n /** Runtime environment in the sandbox */\n runtime: Runtime;\n /** Current status of the sandbox */\n status: SandboxStatus;\n /** When the sandbox was created */\n createdAt: Date;\n /** Execution timeout in milliseconds */\n timeout: number;\n /** Additional provider-specific metadata */\n metadata?: Record<string, any>;\n}\n\n/**\n * Options for creating a sandbox\n */\nexport interface CreateSandboxOptions {\n /** Runtime environment (defaults to 'node' if not specified) */\n runtime?: Runtime;\n /** Execution timeout in milliseconds */\n timeout?: number;\n /** Custom sandbox ID (if supported by provider) */\n sandboxId?: string;\n /** Template ID for sandbox creation (provider-specific) */\n templateId?: string;\n /** Additional metadata for the sandbox */\n metadata?: Record<string, any>;\n /** Domain for sandbox connection (provider-specific) */\n domain?: string;\n /** Environment variables for the sandbox */\n envs?: Record<string, string>;\n}\n\n/**\n * File system entry information\n */\nexport interface FileEntry {\n /** File/directory name */\n name: string;\n /** Full path to the entry */\n path: string;\n /** Whether this is a directory */\n isDirectory: boolean;\n /** File size in bytes (0 for directories) */\n size: number;\n /** Last modified timestamp */\n lastModified: Date;\n}\n\n/**\n * File system interface for sandbox operations\n */\nexport interface SandboxFileSystem {\n /** Read file contents */\n readFile(path: string): Promise<string>;\n /** Write file contents */\n writeFile(path: string, content: string): Promise<void>;\n /** Create directory */\n mkdir(path: string): Promise<void>;\n /** List directory contents */\n readdir(path: string): Promise<FileEntry[]>;\n /** Check if file/directory exists */\n exists(path: string): Promise<boolean>;\n /** Remove file or directory */\n remove(path: string): Promise<void>;\n}\n\n/**\n * Error thrown when a command exits with a non-zero status\n */\nexport class CommandExitError extends Error {\n name = 'CommandExitError';\n constructor(public result: {\n exitCode: number;\n stdout: string;\n stderr: string;\n error: boolean;\n }) {\n super(`Command exited with code ${result.exitCode}`);\n }\n}\n\n/**\n * Type guard to check if an error is a CommandExitError\n */\nexport function isCommandExitError(error: unknown): error is CommandExitError {\n return (\n typeof error === 'object' &&\n error !== null &&\n 'name' in error &&\n error.name === 'CommandExitError' &&\n 'result' in error\n );\n}\n\n\n\n\n\n/**\n * Base sandbox interface - what developers interact with\n */\nexport interface Sandbox<TSandbox = any> {\n /** Unique identifier for the sandbox */\n readonly sandboxId: string;\n /** Provider that created this sandbox */\n readonly provider: string;\n\n /** Execute code in the sandbox */\n runCode(code: string, runtime?: Runtime): Promise<ExecutionResult>;\n /** Execute shell commands */\n runCommand(command: string, args?: string[], options?: RunCommandOptions): Promise<ExecutionResult>;\n /** Get information about the sandbox */\n getInfo(): Promise<SandboxInfo>;\n /** Get URL for accessing the sandbox on a specific port */\n getUrl(options: { port: number; protocol?: string }): Promise<string>;\n /** Get the provider instance that created this sandbox */\n getProvider(): import('./provider').Provider<TSandbox>;\n /** Get the native provider sandbox instance with proper typing */\n getInstance(): TSandbox;\n /** Kill the sandbox */\n kill(): Promise<void>;\n /** Destroy the sandbox and clean up resources */\n destroy(): Promise<void>;\n\n /** File system operations */\n readonly filesystem: SandboxFileSystem;\n}\n\n/**\n * Extract the sandbox type from a provider\n */\ntype ExtractProviderSandboxType<TProvider extends Provider> = TProvider extends { readonly __sandboxType: infer TSandbox } ? TSandbox : any;\n\n/**\n * Typed sandbox interface that preserves the provider's native instance type\n */\nexport interface TypedSandbox<TProvider extends Provider> extends Omit<Sandbox<ExtractProviderSandboxType<TProvider>>, 'getProvider'> {\n /** Get the provider instance that created this sandbox with proper typing */\n getProvider(): TProvider;\n /** Get the native provider sandbox instance with proper typing */\n getInstance(): ExtractProviderSandboxType<TProvider>;\n}","/**\n * Compute Singleton - Main API Orchestrator\n *\n * Provides the unified compute.* API and delegates to specialized managers\n */\n\nimport { ComputeClient } from '@computesdk/client';\nimport type { ComputeAPI, CreateSandboxParams, CreateSandboxParamsWithOptionalProvider, ComputeConfig, Sandbox, Provider, TypedSandbox, TypedComputeAPI } from './types';\n\n/**\n * Authorization response from license server\n */\ninterface AuthorizationResponse {\n jwt: string;\n sandbox_url: string;\n preview_url: string;\n}\n\n/**\n * Authorize license key and get JWT token + URLs from license server\n */\nasync function authorizeApiKey(apiKey: string): Promise<AuthorizationResponse> {\n try {\n const response = await fetch('https://preview.computesdk.com/__api/license/authorize', {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({\n key: apiKey,\n increment_usage: 1\n })\n });\n\n if (!response.ok) {\n throw new Error(`License authorization failed: ${response.statusText}`);\n }\n\n const data = await response.json();\n\n if (!data.jwt) {\n throw new Error('No JWT token received from license server');\n }\n\n if (!data.sandbox_url) {\n throw new Error('No sandbox_url received from license server');\n }\n\n if (!data.preview_url) {\n throw new Error('No preview_url received from license server');\n }\n\n return {\n jwt: data.jwt,\n sandbox_url: data.sandbox_url,\n preview_url: data.preview_url\n };\n } catch (error) {\n throw new Error(`Failed to authorize API key: ${error}`);\n }\n}\n\n/**\n * Install and start compute CLI inside a sandbox\n */\nasync function installComputeInSandbox(\n sandbox: Sandbox,\n config?: { apiKey?: string; jwt?: string }\n): Promise<AuthorizationResponse | null> {\n try {\n console.log('Installing and starting compute CLI in sandbox...');\n\n // Get JWT token and URLs from API key if provided\n let authResponse: AuthorizationResponse | null = null;\n let jwt = config?.jwt;\n\n if (config?.apiKey && !jwt) {\n console.log('Authorizing API key and getting JWT token...');\n authResponse = await authorizeApiKey(config.apiKey);\n jwt = authResponse.jwt;\n }\n\n // Build install command with authentication\n let installCommand = 'curl -fsSL https://computesdk.com/install.sh | sh';\n\n if (jwt) {\n installCommand = `curl -fsSL https://computesdk.com/install.sh | sh -s -- --jwt ${jwt}`;\n }\n\n // Run the install script (it will handle installation and starting compute)\n const result = await sandbox.runCommand('sh', ['-c', installCommand]);\n\n if (result.exitCode !== 0) {\n throw new Error(`Failed to install and start compute CLI: ${result.stderr}`);\n }\n\n console.log('Compute CLI installed and started successfully');\n\n return authResponse;\n } catch (error) {\n throw new Error(`Failed to install compute CLI in sandbox: ${error}`);\n }\n}\n\n/**\n * Compute singleton implementation - orchestrates all compute operations\n */\nclass ComputeManager implements ComputeAPI {\n private config: ComputeConfig | null = null;\n private typedState: {\n isTyped: boolean;\n provider: Provider | null;\n } = { isTyped: false, provider: null };\n private computeAuth: { apiKey?: string; jwt?: string } = {};\n\n /**\n * Set default configuration with generic type preservation\n */\n setConfig<TProvider extends Provider>(config: ComputeConfig<TProvider>): void {\n // Validate that at least one provider is specified\n if (!config.defaultProvider && !config.provider) {\n throw new Error('Either defaultProvider or provider must be specified in setConfig');\n }\n\n // Handle backwards compatibility: if both are provided, defaultProvider takes precedence\n if (config.defaultProvider && config.provider) {\n console.warn('Both defaultProvider and provider specified in setConfig. Using defaultProvider. The provider key is deprecated, please use defaultProvider instead.');\n }\n\n // Normalize config to always have both fields for internal use (backward compatibility)\n const actualProvider = config.defaultProvider || config.provider!;\n this.config = {\n provider: actualProvider,\n defaultProvider: actualProvider,\n apiKey: config.apiKey,\n jwt: config.jwt\n };\n\n // Store compute auth credentials\n this.computeAuth = {\n apiKey: config.apiKey,\n jwt: config.jwt\n };\n\n // Store typed state for type-aware operations\n this.typedState = {\n isTyped: true,\n provider: actualProvider\n };\n }\n\n /**\n * Get current configuration\n */\n getConfig(): ComputeConfig | null {\n return this.config;\n }\n\n /**\n * Clear current configuration\n */\n clearConfig(): void {\n this.config = null;\n }\n\n /**\n * Get the default provider, throwing if not configured\n */\n private getDefaultProvider(): Provider {\n const provider = this.config?.defaultProvider || this.config?.provider;\n if (!provider) {\n throw new Error(\n 'No default provider configured. Either call compute.setConfig({ defaultProvider }) or pass provider explicitly.'\n );\n }\n return provider;\n }\n\n sandbox = {\n /**\n * Create a sandbox from a provider (or default provider if configured)\n * \n * @example\n * ```typescript\n * import { e2b } from '@computesdk/e2b'\n * import { compute } from 'computesdk'\n * \n * // With explicit provider\n * const sandbox = await compute.sandbox.create({\n * provider: e2b({ apiKey: 'your-key' })\n * })\n * \n * // With default provider (both forms work)\n * compute.setConfig({ defaultProvider: e2b({ apiKey: 'your-key' }) })\n * const sandbox1 = await compute.sandbox.create({})\n * const sandbox2 = await compute.sandbox.create()\n * ```\n */\n create: async (params?: CreateSandboxParams | CreateSandboxParamsWithOptionalProvider): Promise<Sandbox> => {\n const provider = params && 'provider' in params && params.provider ? params.provider : this.getDefaultProvider();\n const options = params?.options;\n const sandbox = await provider.sandbox.create(options);\n\n // Install compute CLI in the sandbox with auth credentials if available\n const authResponse = await installComputeInSandbox(sandbox, this.computeAuth);\n\n // If we have authorization info, use ComputeClient instead of provider sandbox\n let finalSandbox: Sandbox = sandbox;\n if (authResponse) {\n finalSandbox = new ComputeClient({\n sandboxUrl: authResponse.sandbox_url,\n sandboxId: sandbox.sandboxId,\n provider: sandbox.provider,\n token: authResponse.jwt\n }) as Sandbox;\n }\n\n // If we have typed state and no explicit provider passed, cast to typed sandbox\n // This enables proper type inference for getInstance() when using default provider\n if (this.typedState.isTyped && (!params || !('provider' in params && params.provider))) {\n return finalSandbox as TypedSandbox<any>;\n }\n\n return finalSandbox;\n },\n\n /**\n * Get an existing sandbox by ID from a provider (or default provider if configured)\n */\n getById: async (providerOrSandboxId: Provider | string, sandboxId?: string): Promise<Sandbox | null> => {\n if (typeof providerOrSandboxId === 'string') {\n // Called with just sandboxId, use default provider\n const provider = this.getDefaultProvider();\n const sandbox = await provider.sandbox.getById(providerOrSandboxId);\n \n // If we have typed state, cast to typed sandbox for proper getInstance() typing\n if (this.typedState.isTyped && sandbox) {\n return sandbox as TypedSandbox<any>;\n }\n \n return sandbox;\n } else {\n // Called with provider and sandboxId\n if (!sandboxId) {\n throw new Error('sandboxId is required when provider is specified');\n }\n return await providerOrSandboxId.sandbox.getById(sandboxId);\n }\n },\n\n /**\n * List all active sandboxes from a provider (or default provider if configured)\n */\n list: async (provider?: Provider): Promise<Sandbox[]> => {\n const actualProvider = provider || this.getDefaultProvider();\n const sandboxes = await actualProvider.sandbox.list();\n \n // If we have typed state and no explicit provider passed, cast to typed sandboxes\n if (this.typedState.isTyped && !provider) {\n return sandboxes as TypedSandbox<any>[];\n }\n \n return sandboxes;\n },\n\n /**\n * Destroy a sandbox via a provider (or default provider if configured)\n */\n destroy: async (providerOrSandboxId: Provider | string, sandboxId?: string): Promise<void> => {\n if (typeof providerOrSandboxId === 'string') {\n // Called with just sandboxId, use default provider\n const provider = this.getDefaultProvider();\n return await provider.sandbox.destroy(providerOrSandboxId);\n } else {\n // Called with provider and sandboxId\n if (!sandboxId) {\n throw new Error('sandboxId is required when provider is specified');\n }\n return await providerOrSandboxId.sandbox.destroy(sandboxId);\n }\n }\n };\n\n // Future: compute.blob.*, compute.database.*, compute.git.* will be added here\n // blob = new BlobManager();\n // database = new DatabaseManager(); \n // git = new GitManager();\n\n\n}\n\n/**\n * Singleton instance - the main API (untyped)\n */\nexport const compute: ComputeAPI = new ComputeManager();\n\n\n\n/**\n * Create a compute instance with proper typing\n * \n * @example\n * ```typescript\n * import { e2b } from '@computesdk/e2b'\n * import { createCompute } from 'computesdk'\n * \n * const compute = createCompute({\n * defaultProvider: e2b({ apiKey: 'your-key' }),\n * });\n * \n * const sandbox = await compute.sandbox.create();\n * const instance = sandbox.getInstance(); // ✅ Properly typed E2B Sandbox!\n * ```\n */\nexport function createCompute<TProvider extends Provider>(config: ComputeConfig<TProvider>): TypedComputeAPI<TProvider> {\n const manager = new ComputeManager();\n\n // Set config directly without calling the public setConfig method\n const actualProvider = config.defaultProvider || config.provider!;\n manager['config'] = {\n provider: actualProvider,\n defaultProvider: actualProvider,\n apiKey: config.apiKey,\n jwt: config.jwt\n };\n manager['typedState'] = {\n isTyped: true,\n provider: actualProvider\n };\n manager['computeAuth'] = {\n apiKey: config.apiKey,\n jwt: config.jwt\n };\n\n return {\n setConfig: <T extends Provider>(cfg: ComputeConfig<T>) => createCompute(cfg),\n getConfig: () => manager.getConfig(),\n clearConfig: () => manager.clearConfig(),\n\n sandbox: {\n create: async (params?: Omit<CreateSandboxParamsWithOptionalProvider, 'provider'>) => {\n const sandbox = await manager.sandbox.create(params);\n // The sandbox should now have the correct getInstance typing from the generic Sandbox<TSandbox>\n return sandbox as TypedSandbox<TProvider>;\n },\n\n getById: async (sandboxId: string) => {\n const sandbox = await manager.sandbox.getById(sandboxId);\n return sandbox ? sandbox as TypedSandbox<TProvider> : null;\n },\n\n list: async () => {\n const sandboxes = await manager.sandbox.list();\n return sandboxes as TypedSandbox<TProvider>[];\n },\n\n destroy: async (sandboxId: string) => {\n return await manager.sandbox.destroy(sandboxId);\n }\n }\n } as TypedComputeAPI<TProvider>;\n}\n\n\n\n","/**\n * Simplified Request Handler for Web Framework Integration\n * \n * Handles JSON requests for sandbox and code execution operations.\n * Terminal support removed - will be re-added with WebSocket VM connections.\n */\n\nimport type { Provider, Runtime } from './types';\nimport { compute } from './compute';\n\n/**\n * Request structure supporting sandbox and code execution capabilities\n */\nexport interface ComputeRequest {\n /** Action in dot notation (e.g., 'compute.sandbox.create') */\n action: string;\n \n /** Parameters for the action */\n sandboxId?: string;\n code?: string;\n command?: string;\n args?: string[];\n runtime?: Runtime;\n path?: string;\n content?: string;\n \n /** Command options (for runCommand action) */\n commandOptions?: {\n background?: boolean;\n };\n \n /** Sandbox creation options */\n options?: {\n runtime?: Runtime;\n timeout?: number;\n sandboxId?: string;\n };\n}\n\n/**\n * Response structure for compute operations\n */\nexport interface ComputeResponse {\n success: boolean;\n error?: string;\n sandboxId: string;\n provider: string;\n [key: string]: any; // Allow any additional response data\n}\n\n/**\n * Execute compute action using targeted handling\n */\nasync function executeAction(body: ComputeRequest, provider: Provider): Promise<ComputeResponse> {\n try {\n const { action, sandboxId } = body;\n \n // Sandbox management operations\n if (action === 'compute.sandbox.create') {\n const sandbox = await compute.sandbox.create({\n provider,\n options: body.options || { runtime: 'python' }\n });\n return {\n success: true,\n sandboxId: sandbox.sandboxId,\n provider: provider.name\n };\n }\n \n if (action === 'compute.sandbox.list') {\n const sandboxes = await compute.sandbox.list(provider);\n return {\n success: true,\n sandboxId: '',\n provider: provider.name,\n sandboxes: sandboxes.map(sb => ({\n sandboxId: sb.sandboxId,\n provider: sb.provider\n }))\n };\n }\n \n if (action === 'compute.sandbox.destroy') {\n if (!sandboxId) {\n throw new Error('sandboxId is required for destroy action');\n }\n await compute.sandbox.destroy(provider, sandboxId);\n return {\n success: true,\n sandboxId,\n provider: provider.name\n };\n }\n \n // For sandbox instance methods, get the sandbox first\n if (!sandboxId) {\n throw new Error('sandboxId is required for this action');\n }\n \n const sandbox = await compute.sandbox.getById(provider, sandboxId);\n if (!sandbox) {\n throw new Error(`Sandbox ${sandboxId} not found`);\n }\n \n // Sandbox info\n if (action === 'compute.sandbox.getInfo') {\n const result = await sandbox.getInfo();\n return {\n success: true,\n sandboxId,\n provider: provider.name,\n info: {\n id: result.id,\n provider: result.provider,\n runtime: result.runtime,\n status: result.status,\n createdAt: result.createdAt.toISOString(),\n timeout: result.timeout,\n metadata: result.metadata\n }\n };\n }\n \n // Code execution\n if (action === 'compute.sandbox.runCode') {\n if (!body.code) throw new Error('code is required');\n const result = await sandbox.runCode(body.code, body.runtime);\n return {\n success: true,\n sandboxId,\n provider: provider.name,\n result: {\n stdout: result.stdout,\n stderr: result.stderr,\n exitCode: result.exitCode,\n executionTime: result.executionTime\n }\n };\n }\n \n if (action === 'compute.sandbox.runCommand') {\n if (!body.command) throw new Error('command is required');\n const result = await sandbox.runCommand(body.command, body.args, body.commandOptions);\n return {\n success: true,\n sandboxId,\n provider: provider.name,\n result: {\n stdout: result.stdout,\n stderr: result.stderr,\n exitCode: result.exitCode,\n executionTime: result.executionTime,\n ...(result.isBackground && { isBackground: result.isBackground }),\n ...(result.pid && { pid: result.pid })\n }\n };\n }\n \n // Filesystem operations\n if (action === 'compute.sandbox.filesystem.readFile') {\n if (!body.path) throw new Error('path is required');\n const result = await sandbox.filesystem.readFile(body.path);\n return {\n success: true,\n sandboxId,\n provider: provider.name,\n fileContent: result\n };\n }\n \n if (action === 'compute.sandbox.filesystem.writeFile') {\n if (!body.path) throw new Error('path is required');\n if (body.content === undefined) throw new Error('content is required');\n await sandbox.filesystem.writeFile(body.path, body.content);\n return { success: true, sandboxId, provider: provider.name };\n }\n \n if (action === 'compute.sandbox.filesystem.mkdir') {\n if (!body.path) throw new Error('path is required');\n await sandbox.filesystem.mkdir(body.path);\n return { success: true, sandboxId, provider: provider.name };\n }\n \n if (action === 'compute.sandbox.filesystem.readdir') {\n if (!body.path) throw new Error('path is required');\n const result = await sandbox.filesystem.readdir(body.path);\n return {\n success: true,\n sandboxId,\n provider: provider.name,\n files: result.map((entry: any) => ({\n name: entry.name,\n path: entry.path,\n isDirectory: entry.isDirectory,\n size: entry.size,\n lastModified: entry.lastModified.toISOString()\n }))\n };\n }\n \n if (action === 'compute.sandbox.filesystem.exists') {\n if (!body.path) throw new Error('path is required');\n const result = await sandbox.filesystem.exists(body.path);\n return {\n success: true,\n sandboxId,\n provider: provider.name,\n exists: result\n };\n }\n \n if (action === 'compute.sandbox.filesystem.remove') {\n if (!body.path) throw new Error('path is required');\n await sandbox.filesystem.remove(body.path);\n return { success: true, sandboxId, provider: provider.name };\n }\n \n throw new Error(`Unknown action: ${action}`);\n \n } catch (error) {\n return {\n success: false,\n error: error instanceof Error ? error.message : 'Unknown error occurred',\n sandboxId: body.sandboxId || '',\n provider: provider.name\n };\n }\n}\n\n/**\n * Main request handler - handles HTTP requests and pre-parsed bodies\n */\nexport async function handleComputeRequest(\n params: HandleComputeRequestParams\n): Promise<ComputeResponse>;\nexport async function handleComputeRequest(\n requestOrBody: Request | ComputeRequest,\n provider: Provider\n): Promise<Response>;\nexport async function handleComputeRequest(\n paramsOrRequestOrBody: HandleComputeRequestParams | Request | ComputeRequest,\n provider?: Provider\n): Promise<ComputeResponse | Response> {\n // Handle object-style API\n if (typeof paramsOrRequestOrBody === 'object' && 'request' in paramsOrRequestOrBody && 'provider' in paramsOrRequestOrBody) {\n const params = paramsOrRequestOrBody as HandleComputeRequestParams;\n return await executeAction(params.request, params.provider);\n }\n \n // Handle original API\n if (!provider) {\n throw new Error('Provider is required when not using object-style API');\n }\n \n const requestOrBody = paramsOrRequestOrBody as Request | ComputeRequest;\n try {\n let body: ComputeRequest;\n \n if (requestOrBody instanceof Request) {\n // Handle HTTP method validation\n if (requestOrBody.method !== 'POST') {\n return Response.json({\n success: false,\n error: 'Only POST requests are supported',\n sandboxId: '',\n provider: provider.name\n }, { status: 405 });\n }\n \n // Parse JSON body with better error handling\n try {\n body = await requestOrBody.json();\n } catch (parseError) {\n return Response.json({\n success: false,\n error: 'Invalid JSON in request body',\n sandboxId: '',\n provider: provider.name\n }, { status: 400 });\n }\n } else {\n body = requestOrBody;\n }\n \n // Execute the action\n const result = await executeAction(body, provider);\n \n return Response.json(result, {\n status: result.success ? 200 : 500\n });\n \n } catch (error) {\n return Response.json({\n success: false,\n error: error instanceof Error ? error.message : 'Request handling failed',\n sandboxId: '',\n provider: provider.name\n }, { status: 500 });\n }\n}\n\n/**\n * Legacy export for backward compatibility\n */\nexport interface HandleComputeRequestParams {\n request: ComputeRequest;\n provider: Provider;\n}\n\nexport { handleComputeRequest as handleHttpComputeRequest };","/**\n * Provider Factory - Creates providers from method definitions\n * \n * Eliminates boilerplate by auto-generating Provider/Sandbox classes\n * from simple method definitions with automatic feature detection.\n */\n\nimport type {\n Provider,\n ProviderSandboxManager,\n ProviderTemplateManager,\n ProviderSnapshotManager,\n Sandbox,\n SandboxFileSystem,\n SandboxInfo,\n ExecutionResult,\n Runtime,\n CreateSandboxOptions,\n FileEntry,\n RunCommandOptions,\n CreateSnapshotOptions,\n ListSnapshotsOptions,\n CreateTemplateOptions,\n ListTemplatesOptions,\n} from './types/index.js';\n\n/**\n * Helper function to handle background command execution\n * Providers can use this to implement background job support\n */\nexport function createBackgroundCommand(command: string, args: string[] = [], options?: RunCommandOptions): { command: string; args: string[]; isBackground: boolean } {\n if (!options?.background) {\n return { command, args, isBackground: false };\n }\n\n // For background execution, we modify the command to run in background\n // Default approach: append & to make it run in background\n const fullCommand = args.length > 0 ? `${command} ${args.join(' ')}` : command;\n \n return {\n command: 'sh',\n args: ['-c', `${fullCommand} &`],\n isBackground: true\n };\n}\n\n/**\n * Flat sandbox method implementations - all operations in one place\n */\nexport interface SandboxMethods<TSandbox = any, TConfig = any> {\n // Collection operations (map to compute.sandbox.*)\n create: (config: TConfig, options?: CreateSandboxOptions) => Promise<{ sandbox: TSandbox; sandboxId: string }>;\n getById: (config: TConfig, sandboxId: string) => Promise<{ sandbox: TSandbox; sandboxId: string } | null>;\n list: (config: TConfig) => Promise<Array<{ sandbox: TSandbox; sandboxId: string }>>;\n destroy: (config: TConfig, sandboxId: string) => Promise<void>;\n \n // Instance operations (map to individual Sandbox methods)\n runCode: (sandbox: TSandbox, code: string, runtime?: Runtime, config?: TConfig) => Promise<ExecutionResult>;\n runCommand: (sandbox: TSandbox, command: string, args?: string[], options?: RunCommandOptions) => Promise<ExecutionResult>;\n getInfo: (sandbox: TSandbox) => Promise<SandboxInfo>;\n getUrl: (sandbox: TSandbox, options: { port: number; protocol?: string }) => Promise<string>;\n \n // Optional provider-specific typed getInstance method\n getInstance?: (sandbox: TSandbox) => TSandbox;\n \n // Optional filesystem methods\n filesystem?: {\n readFile: (sandbox: TSandbox, path: string, runCommand: (sandbox: TSandbox, command: string, args?: string[]) => Promise<ExecutionResult>) => Promise<string>;\n writeFile: (sandbox: TSandbox, path: string, content: string, runCommand: (sandbox: TSandbox, command: string, args?: string[]) => Promise<ExecutionResult>) => Promise<void>;\n mkdir: (sandbox: TSandbox, path: string, runCommand: (sandbox: TSandbox, command: string, args?: string[]) => Promise<ExecutionResult>) => Promise<void>;\n readdir: (sandbox: TSandbox, path: string, runCommand: (sandbox: TSandbox, command: string, args?: string[]) => Promise<ExecutionResult>) => Promise<FileEntry[]>;\n exists: (sandbox: TSandbox, path: string, runCommand: (sandbox: TSandbox, command: string, args?: string[]) => Promise<ExecutionResult>) => Promise<boolean>;\n remove: (sandbox: TSandbox, path: string, runCommand: (sandbox: TSandbox, command: string, args?: string[]) => Promise<ExecutionResult>) => Promise<void>;\n };\n}\n\n/**\n * Template method implementations\n */\nexport interface TemplateMethods<TTemplate = any, TConfig = any> {\n create: (config: TConfig, options: CreateTemplateOptions | any) => Promise<TTemplate>;\n list: (config: TConfig, options?: ListTemplatesOptions) => Promise<TTemplate[]>;\n delete: (config: TConfig, templateId: string) => Promise<void>;\n}\n\n/**\n * Snapshot method implementations \n */\nexport interface SnapshotMethods<TSnapshot = any, TConfig = any> {\n create: (config: TConfig, sandboxId: string, options?: CreateSnapshotOptions) => Promise<TSnapshot>;\n list: (config: TConfig, options?: ListSnapshotsOptions) => Promise<TSnapshot[]>;\n delete: (config: TConfig, snapshotId: string) => Promise<void>;\n}\n\n/**\n * Provider configuration for createProvider()\n */\nexport interface ProviderConfig<TSandbox = any, TConfig = any, TTemplate = any, TSnapshot = any> {\n name: string;\n methods: {\n sandbox: SandboxMethods<TSandbox, TConfig>;\n template?: TemplateMethods<TTemplate, TConfig>;\n snapshot?: SnapshotMethods<TSnapshot, TConfig>;\n };\n}\n\n/**\n * Default filesystem implementations based on shell commands\n * These work for any provider that supports shell command execution\n */\nconst defaultFilesystemMethods = {\n readFile: async (sandbox: any, path: string, runCommand: (sandbox: any, command: string, args?: string[]) => Promise<ExecutionResult>): Promise<string> => {\n const result = await runCommand(sandbox, 'cat', [path]);\n if (result.exitCode !== 0) {\n throw new Error(`Failed to read file ${path}: ${result.stderr}`);\n }\n // Trim trailing newline that cat command adds\n return result.stdout.replace(/\\n$/, '');\n },\n\n writeFile: async (sandbox: any, path: string, content: string, runCommand: (sandbox: any, command: string, args?: string[]) => Promise<ExecutionResult>): Promise<void> => {\n const result = await runCommand(sandbox, 'sh', ['-c', `echo ${JSON.stringify(content)} > ${JSON.stringify(path)}`]);\n if (result.exitCode !== 0) {\n throw new Error(`Failed to write file ${path}: ${result.stderr}`);\n }\n },\n\n mkdir: async (sandbox: any, path: string, runCommand: (sandbox: any, command: string, args?: string[]) => Promise<ExecutionResult>): Promise<void> => {\n const result = await runCommand(sandbox, 'mkdir', ['-p', path]);\n if (result.exitCode !== 0) {\n throw new Error(`Failed to create directory ${path}: ${result.stderr}`);\n }\n },\n\n readdir: async (sandbox: any, path: string, runCommand: (sandbox: any, command: string, args?: string[]) => Promise<ExecutionResult>): Promise<FileEntry[]> => {\n // Try different ls variations for maximum compatibility\n let result = await runCommand(sandbox, 'ls', ['-la', path]);\n let hasDetailedOutput = true;\n \n // Fall back to basic ls if detailed flags not supported\n if (result.exitCode !== 0) {\n result = await runCommand(sandbox, 'ls', ['-l', path]);\n }\n if (result.exitCode !== 0) {\n result = await runCommand(sandbox, 'ls', [path]);\n hasDetailedOutput = false;\n }\n \n if (result.exitCode !== 0) {\n throw new Error(`Failed to list directory ${path}: ${result.stderr}`);\n }\n\n const lines = (result.stdout || '').split('\\n').filter((line: string) => line.trim() && !line.startsWith('total'));\n\n return lines.map((line: string) => {\n if (hasDetailedOutput && line.includes(' ')) {\n // Parse detailed ls output (ls -la or ls -l)\n const parts = line.trim().split(/\\s+/);\n const name = parts[parts.length - 1];\n const isDirectory = line.startsWith('d');\n \n return {\n name,\n path: `${path}/${name}`,\n isDirectory,\n size: parseInt(parts[4]) || 0,\n lastModified: new Date()\n };\n } else {\n // Parse simple ls output (just filenames)\n const name = line.trim();\n return {\n name,\n path: `${path}/${name}`,\n isDirectory: false, // Can't determine from simple ls\n size: 0,\n lastModified: new Date()\n };\n }\n });\n },\n\n exists: async (sandbox: any, path: string, runCommand: (sandbox: any, command: string, args?: string[]) => Promise<ExecutionResult>): Promise<boolean> => {\n const result = await runCommand(sandbox, 'test', ['-e', path]);\n return result.exitCode === 0; // Exit code 0 means file exists\n },\n\n remove: async (sandbox: any, path: string, runCommand: (sandbox: any, command: string, args?: string[]) => Promise<ExecutionResult>): Promise<void> => {\n const result = await runCommand(sandbox, 'rm', ['-rf', path]);\n if (result.exitCode !== 0) {\n throw new Error(`Failed to remove ${path}: ${result.stderr}`);\n }\n }\n};\n\n/**\n * Auto-generated filesystem implementation that throws \"not supported\" errors\n */\nclass UnsupportedFileSystem implements SandboxFileSystem {\n private readonly providerName: string;\n\n constructor(providerName: string) {\n this.providerName = providerName;\n }\n\n async readFile(_path: string): Promise<string> {\n throw new Error(`Filesystem operations are not supported by ${this.providerName}'s sandbox environment. ${this.providerName} sandboxes are designed for code execution only.`);\n }\n\n async writeFile(_path: string, _content: string): Promise<void> {\n throw new Error(`Filesystem operations are not supported by ${this.providerName}'s sandbox environment. ${this.providerName} sandboxes are designed for code execution only.`);\n }\n\n async mkdir(_path: string): Promise<void> {\n throw new Error(`Filesystem operations are not supported by ${this.providerName}'s sandbox environment. ${this.providerName} sandboxes are designed for code execution only.`);\n }\n\n async readdir(_path: string): Promise<FileEntry[]> {\n throw new Error(`Filesystem operations are not supported by ${this.providerName}'s sandbox environment. ${this.providerName} sandboxes are designed for code execution only.`);\n }\n\n async exists(_path: string): Promise<boolean> {\n throw new Error(`Filesystem operations are not supported by ${this.providerName}'s sandbox environment. ${this.providerName} sandboxes are designed for code execution only.`);\n }\n\n async remove(_path: string): Promise<void> {\n throw new Error(`Filesystem operations are not supported by ${this.providerName}'s sandbox environment. ${this.providerName} sandboxes are designed for code execution only.`);\n }\n}\n\n\n\n/**\n * Auto-generated filesystem implementation that wraps provider methods\n */\nclass SupportedFileSystem<TSandbox> implements SandboxFileSystem {\n constructor(\n private sandbox: TSandbox,\n private methods: NonNullable<SandboxMethods<TSandbox>['filesystem']>,\n private allMethods: SandboxMethods<TSandbox>\n ) {}\n\n async readFile(path: string): Promise<string> {\n return this.methods.readFile(this.sandbox, path, this.allMethods.runCommand);\n }\n\n async writeFile(path: string, content: string): Promise<void> {\n return this.methods.writeFile(this.sandbox, path, content, this.allMethods.runCommand);\n }\n\n async mkdir(path: string): Promise<void> {\n return this.methods.mkdir(this.sandbox, path, this.allMethods.runCommand);\n }\n\n async readdir(path: string): Promise<FileEntry[]> {\n return this.methods.readdir(this.sandbox, path, this.allMethods.runCommand);\n }\n\n async exists(path: string): Promise<boolean> {\n return this.methods.exists(this.sandbox, path, this.allMethods.runCommand);\n }\n\n async remove(path: string): Promise<void> {\n return this.methods.remove(this.sandbox, path, this.allMethods.runCommand);\n }\n}\n\n\n\n\n\n/**\n * Generated sandbox class - implements the Sandbox interface\n */\nclass GeneratedSandbox<TSandbox = any> implements Sandbox<TSandbox> {\n readonly sandboxId: string;\n readonly provider: string;\n readonly filesystem: SandboxFileSystem;\n\n constructor(\n private sandbox: TSandbox,\n sandboxId: string,\n providerName: string,\n private methods: SandboxMethods<TSandbox>,\n private config: any,\n private destroyMethod: (config: any, sandboxId: string) => Promise<void>,\n private providerInstance: Provider\n ) {\n this.sandboxId = sandboxId;\n this.provider = providerName;\n\n // Auto-detect filesystem support\n if (methods.filesystem) {\n this.filesystem = new SupportedFileSystem(sandbox, methods.filesystem, methods);\n } else {\n this.filesystem = new UnsupportedFileSystem(providerName);\n }\n }\n\n getInstance(): TSandbox {\n // Use provider-specific typed getInstance if available\n if (this.methods.getInstance) {\n return this.methods.getInstance(this.sandbox);\n }\n // Fallback to returning the sandbox directly\n return this.sandbox;\n }\n\n async runCode(code: string, runtime?: Runtime): Promise<ExecutionResult> {\n return await this.methods.runCode(this.sandbox, code, runtime, this.config);\n }\n\n async runCommand(command: string, args?: string[], options?: RunCommandOptions): Promise<ExecutionResult> {\n return await this.methods.runCommand(this.sandbox, command, args, options);\n }\n\n async getInfo(): Promise<SandboxInfo> {\n return await this.methods.getInfo(this.sandbox);\n }\n\n async getUrl(options: { port: number; protocol?: string }): Promise<string> {\n return await this.methods.getUrl(this.sandbox, options);\n }\n\n getProvider(): Provider<TSandbox> {\n return this.providerInstance;\n }\n\n async kill(): Promise<void> {\n // For backward compatibility, kill() delegates to destroy()\n await this.destroy();\n }\n\n async destroy(): Promise<void> {\n // Destroy via the provider's destroy method using our sandboxId\n await this.destroyMethod(this.config, this.sandboxId);\n }\n}\n\n/**\n * Auto-generated Sandbox Manager implementation\n */\nclass GeneratedSandboxManager<TSandbox, TConfig> implements ProviderSandboxManager<TSandbox> {\n private activeSandboxes: Map<string, GeneratedSandbox<TSandbox>> = new Map();\n\n constructor(\n private config: TConfig,\n private providerName: string,\n private methods: SandboxMethods<TSandbox, TConfig>,\n private providerInstance: Provider\n ) {}\n\n async create(options?: CreateSandboxOptions): Promise<Sandbox<TSandbox>> {\n // Default to 'node' runtime if not specified for consistency across providers\n const optionsWithDefaults = { runtime: 'node' as Runtime, ...options };\n const result = await this.methods.create(this.config, optionsWithDefaults);\n const sandbox = new GeneratedSandbox<TSandbox>(\n result.sandbox,\n result.sandboxId,\n this.providerName,\n this.methods,\n this.config,\n this.methods.destroy,\n this.providerInstance\n );\n \n this.activeSandboxes.set(result.sandboxId, sandbox);\n return sandbox;\n }\n\n async getById(sandboxId: string): Promise<Sandbox<TSandbox> | null> {\n // Check active sandboxes first\n const existing = this.activeSandboxes.get(sandboxId);\n if (existing) {\n return existing;\n }\n\n // Try to reconnect\n const result = await this.methods.getById(this.config, sandboxId);\n if (!result) {\n return null;\n }\n\n const sandbox = new GeneratedSandbox<TSandbox>(\n result.sandbox,\n result.sandboxId,\n this.providerName,\n this.methods,\n this.config,\n this.methods.destroy,\n this.providerInstance\n );\n \n this.activeSandboxes.set(result.sandboxId, sandbox);\n return sandbox;\n }\n\n async list(): Promise<Sandbox<TSandbox>[]> {\n const results = await this.methods.list(this.config);\n const sandboxes: Sandbox[] = [];\n\n for (const result of results) {\n let sandbox = this.activeSandboxes.get(result.sandboxId);\n if (!sandbox) {\n sandbox = new GeneratedSandbox<TSandbox>(\n result.sandbox,\n result.sandboxId,\n this.providerName,\n this.methods,\n this.config,\n this.methods.destroy,\n this.providerInstance\n );\n this.activeSandboxes.set(result.sandboxId, sandbox);\n }\n sandboxes.push(sandbox);\n }\n\n return sandboxes;\n }\n\n async destroy(sandboxId: string): Promise<void> {\n await this.methods.destroy(this.config, sandboxId);\n this.activeSandboxes.delete(sandboxId);\n }\n}\n\n/**\n * Auto-generated Template Manager implementation\n */\nclass GeneratedTemplateManager<TTemplate, TConfig> implements ProviderTemplateManager<TTemplate> {\n constructor(\n private config: TConfig,\n private methods: TemplateMethods<TTemplate, TConfig>\n ) {}\n\n async create(options: CreateTemplateOptions | any): Promise<TTemplate> {\n return await this.methods.create(this.config, options);\n }\n\n async list(options?: ListTemplatesOptions): Promise<TTemplate[]> {\n return await this.methods.list(this.config, options);\n }\n\n async delete(templateId: string): Promise<void> {\n return await this.methods.delete(this.config, templateId);\n }\n}\n\n/**\n * Auto-generated Snapshot Manager implementation\n */\nclass GeneratedSnapshotManager<TSnapshot, TConfig> implements ProviderSnapshotManager<TSnapshot> {\n constructor(\n private config: TConfig,\n private methods: SnapshotMethods<TSnapshot, TConfig>\n ) {}\n\n async create(sandboxId: string, options?: CreateSnapshotOptions): Promise<TSnapshot> {\n return await this.methods.create(this.config, sandboxId, options);\n }\n\n async list(options?: ListSnapshotsOptions): Promise<TSnapshot[]> {\n return await this.methods.list(this.config, options);\n }\n\n async delete(snapshotId: string): Promise<void> {\n return await this.methods.delete(this.config, snapshotId);\n }\n}\n\n/**\n * Auto-generated Provider implementation\n */\nclass GeneratedProvider<TSandbox, TConfig, TTemplate, TSnapshot> implements Provider<TSandbox, TTemplate, TSnapshot> {\n readonly name: string;\n readonly sandbox: ProviderSandboxManager<TSandbox>;\n readonly template?: ProviderTemplateManager<TTemplate>;\n readonly snapshot?: ProviderSnapshotManager<TSnapshot>;\n readonly __sandboxType!: TSandbox; // Phantom type for TypeScript inference\n\n constructor(config: TConfig, providerConfig: ProviderConfig<TSandbox, TConfig, TTemplate, TSnapshot>) {\n this.name = providerConfig.name;\n this.sandbox = new GeneratedSandboxManager(\n config,\n providerConfig.name,\n providerConfig.methods.sandbox,\n this\n );\n\n // Initialize optional managers if methods are provided\n if (providerConfig.methods.template) {\n this.template = new GeneratedTemplateManager(config, providerConfig.methods.template);\n }\n \n if (providerConfig.methods.snapshot) {\n this.snapshot = new GeneratedSnapshotManager(config, providerConfig.methods.snapshot);\n }\n }\n\n getSupportedRuntimes(): Runtime[] {\n // For now, all providers support both node and python\n // In the future, this could be configurable per provider\n return ['node', 'python'];\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 = any, TTemplate = any, TSnapshot = any>(\n providerConfig: ProviderConfig<TSandbox, TConfig, TTemplate, TSnapshot>\n): (config: TConfig) => Provider<TSandbox, TTemplate, TSnapshot> {\n // Auto-inject default filesystem methods if none provided\n if (!providerConfig.methods.sandbox.filesystem) {\n providerConfig.methods.sandbox.filesystem = defaultFilesystemMethods;\n }\n\n return (config: TConfig) => {\n return new GeneratedProvider(config, providerConfig);\n };\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACwJO,IAAM,mBAAN,cAA+B,MAAM;AAAA,EAE1C,YAAmB,QAKhB;AACD,UAAM,4BAA4B,OAAO,QAAQ,EAAE;AANlC;AADnB,gBAAO;AAAA,EAQP;AACF;AAKO,SAAS,mBAAmB,OAA2C;AAC5E,SACE,OAAO,UAAU,YACjB,UAAU,QACV,UAAU,SACV,MAAM,SAAS,sBACf,YAAY;AAEhB;;;ACzKA,oBAA8B;AAe9B,eAAe,gBAAgB,QAAgD;AAC7E,MAAI;AACF,UAAM,WAAW,MAAM,MAAM,0DAA0D;AAAA,MACrF,QAAQ;AAAA,MACR,SAAS;AAAA,QACP,gBAAgB;AAAA,MAClB;AAAA,MACA,MAAM,KAAK,UAAU;AAAA,QACnB,KAAK;AAAA,QACL,iBAAiB;AAAA,MACnB,CAAC;AAAA,IACH,CAAC;AAED,QAAI,CAAC,SAAS,IAAI;AAChB,YAAM,IAAI,MAAM,iCAAiC,SAAS,UAAU,EAAE;AAAA,IACxE;AAEA,UAAM,OAAO,MAAM,SAAS,KAAK;AAEjC,QAAI,CAAC,KAAK,KAAK;AACb,YAAM,IAAI,MAAM,2CAA2C;AAAA,IAC7D;AAEA,QAAI,CAAC,KAAK,aAAa;AACrB,YAAM,IAAI,MAAM,6CAA6C;AAAA,IAC/D;AAEA,QAAI,CAAC,KAAK,aAAa;AACrB,YAAM,IAAI,MAAM,6CAA6C;AAAA,IAC/D;AAEA,WAAO;AAAA,MACL,KAAK,KAAK;AAAA,MACV,aAAa,KAAK;AAAA,MAClB,aAAa,KAAK;AAAA,IAC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D;AACF;AAKA,IAAM,oBAAN,MAAqH;AAAA;AAAA,EAOnH,YAAY,QAAiB,gBAAyE;AACpG,SAAK,OAAO,eAAe;AAC3B,SAAK,UAAU,IAAI;AAAA,MACjB;AAAA,MACA,eAAe;AAAA,MACf,eAAe,QAAQ;AAAA,MACvB;AAAA,IACF;AAGA,QAAI,eAAe,QAAQ,UAAU;AACnC,WAAK,WAAW,IAAI,yBAAyB,QAAQ,eAAe,QAAQ,QAAQ;AAAA,IACtF;AAEA,QAAI,eAAe,QAAQ,UAAU;AACnC,WAAK,WAAW,IAAI,yBAAyB,QAAQ,eAAe,QAAQ,QAAQ;AAAA,IACtF;AAAA,EACF;AAAA,EAEA,uBAAkC;AAGhC,WAAO,CAAC,QAAQ,QAAQ;AAAA,EAC1B;AACF;AAQO,SAAS,eACd,gBAC+D;AAE/D,MAAI,CAAC,eAAe,QAAQ,QAAQ,YAAY;AAC9C,mBAAe,QAAQ,QAAQ,aAAa;AAAA,EAC9C;AAEA,SAAO,CAAC,WAAoB;AAC1B,WAAO,IAAI,kBAAkB,QAAQ,cAAc;AAAA,EACrD;AACF;","names":["sandbox"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/types/sandbox.ts","../src/compute.ts","../src/request-handler.ts","../src/factory.ts"],"sourcesContent":["/**\n * ComputeSDK Core\n * \n * Clean Provider/Sandbox separation architecture with extensible compute.* API\n */\n\n// Export all types\nexport * from './types';\n\n// Export compute singleton - the main API\nexport { compute, createCompute } from './compute';\n\n// Export request handler for web framework integration\nexport { handleComputeRequest } from './request-handler';\n\n// Export compute request/response types\nexport type {\n ComputeRequest,\n ComputeResponse,\n HandleComputeRequestParams\n} from './request-handler';\n\n\n\n// Export provider factory for creating custom providers\nexport { createProvider, createBackgroundCommand } from './factory';\nexport type { ProviderConfig, SandboxMethods, TemplateMethods, SnapshotMethods } from './factory';\n\n// Export error handling utilities (explicitly for clarity)\nexport { CommandExitError, isCommandExitError } from './types/sandbox';\n\n// Test suite is available separately via @computesdk/test-utils package\n","/**\n * Sandbox Types\n * \n * Types related to sandbox execution, filesystem, terminal operations\n */\n\n// Forward declaration to avoid circular dependency\ninterface Provider {\n readonly name: string;\n readonly sandbox: any; // Will be properly typed when imported together\n}\n\n/**\n * Type mapping for provider names to their sandbox types\n * Manually defined for known providers since declaration merging isn't working reliably\n */\nexport interface ProviderSandboxTypeMap {\n e2b: any; // We can't import the E2B type directly, but we'll handle it differently\n vercel: any;\n daytona: any;\n}\n\n/**\n * Utility type to extract the native instance type from a provider\n * Uses provider name and manual type inference\n */\nexport type ExtractSandboxInstanceType<TProvider extends Provider> = \n TProvider extends { readonly name: 'e2b' }\n ? any // For now, let's just try to make the runtime casting work\n : TProvider extends { readonly name: 'vercel' }\n ? any\n : TProvider extends { readonly name: 'daytona' }\n ? any\n : any;\n\n/**\n * Supported runtime environments\n */\nexport type Runtime = 'node' | 'python';\n\n/**\n * Sandbox status types\n */\nexport type SandboxStatus = 'running' | 'stopped' | 'error';\n\n/**\n * Options for running commands\n */\nexport interface RunCommandOptions {\n /** Run command in background (non-blocking) */\n background?: boolean;\n}\n\n/**\n * Result of code execution\n */\nexport interface ExecutionResult {\n /** Standard output from the execution */\n stdout: string;\n /** Standard error from the execution */\n stderr: string;\n /** Exit code from the execution */\n exitCode: number;\n /** Time taken for execution in milliseconds */\n executionTime: number;\n /** ID of the sandbox where the code was executed */\n sandboxId: string;\n /** Provider that executed the code */\n provider: string;\n /** Process ID for background jobs (if applicable) */\n pid?: number;\n /** Whether this command is running in background */\n isBackground?: boolean;\n}\n\n/**\n * Information about a sandbox\n */\nexport interface SandboxInfo {\n /** Unique identifier for the sandbox */\n id: string;\n /** Provider hosting the sandbox */\n provider: string;\n /** Runtime environment in the sandbox */\n runtime: Runtime;\n /** Current status of the sandbox */\n status: SandboxStatus;\n /** When the sandbox was created */\n createdAt: Date;\n /** Execution timeout in milliseconds */\n timeout: number;\n /** Additional provider-specific metadata */\n metadata?: Record<string, any>;\n}\n\n/**\n * Options for creating a sandbox\n */\nexport interface CreateSandboxOptions {\n /** Runtime environment (defaults to 'node' if not specified) */\n runtime?: Runtime;\n /** Execution timeout in milliseconds */\n timeout?: number;\n /** Custom sandbox ID (if supported by provider) */\n sandboxId?: string;\n /** Template ID for sandbox creation (provider-specific) */\n templateId?: string;\n /** Additional metadata for the sandbox */\n metadata?: Record<string, any>;\n /** Domain for sandbox connection (provider-specific) */\n domain?: string;\n /** Environment variables for the sandbox */\n envs?: Record<string, string>;\n}\n\n/**\n * File system entry information\n */\nexport interface FileEntry {\n /** File/directory name */\n name: string;\n /** Full path to the entry */\n path: string;\n /** Whether this is a directory */\n isDirectory: boolean;\n /** File size in bytes (0 for directories) */\n size: number;\n /** Last modified timestamp */\n lastModified: Date;\n}\n\n/**\n * File system interface for sandbox operations\n */\nexport interface SandboxFileSystem {\n /** Read file contents */\n readFile(path: string): Promise<string>;\n /** Write file contents */\n writeFile(path: string, content: string): Promise<void>;\n /** Create directory */\n mkdir(path: string): Promise<void>;\n /** List directory contents */\n readdir(path: string): Promise<FileEntry[]>;\n /** Check if file/directory exists */\n exists(path: string): Promise<boolean>;\n /** Remove file or directory */\n remove(path: string): Promise<void>;\n}\n\n/**\n * Error thrown when a command exits with a non-zero status\n */\nexport class CommandExitError extends Error {\n name = 'CommandExitError';\n constructor(public result: {\n exitCode: number;\n stdout: string;\n stderr: string;\n error: boolean;\n }) {\n super(`Command exited with code ${result.exitCode}`);\n }\n}\n\n/**\n * Type guard to check if an error is a CommandExitError\n */\nexport function isCommandExitError(error: unknown): error is CommandExitError {\n return (\n typeof error === 'object' &&\n error !== null &&\n 'name' in error &&\n error.name === 'CommandExitError' &&\n 'result' in error\n );\n}\n\n\n\n\n\n/**\n * Base sandbox interface - what developers interact with\n */\nexport interface Sandbox<TSandbox = any> {\n /** Unique identifier for the sandbox */\n readonly sandboxId: string;\n /** Provider that created this sandbox */\n readonly provider: string;\n\n /** Execute code in the sandbox */\n runCode(code: string, runtime?: Runtime): Promise<ExecutionResult>;\n /** Execute shell commands */\n runCommand(command: string, args?: string[], options?: RunCommandOptions): Promise<ExecutionResult>;\n /** Get information about the sandbox */\n getInfo(): Promise<SandboxInfo>;\n /** Get URL for accessing the sandbox on a specific port */\n getUrl(options: { port: number; protocol?: string }): Promise<string>;\n /** Get the provider instance that created this sandbox */\n getProvider(): import('./provider').Provider<TSandbox>;\n /** Get the native provider sandbox instance with proper typing */\n getInstance(): TSandbox;\n /** Kill the sandbox */\n kill(): Promise<void>;\n /** Destroy the sandbox and clean up resources */\n destroy(): Promise<void>;\n\n /** File system operations */\n readonly filesystem: SandboxFileSystem;\n}\n\n/**\n * Extract the sandbox type from a provider\n */\ntype ExtractProviderSandboxType<TProvider extends Provider> = TProvider extends { readonly __sandboxType: infer TSandbox } ? TSandbox : any;\n\n/**\n * Typed sandbox interface that preserves the provider's native instance type\n */\nexport interface TypedSandbox<TProvider extends Provider> extends Omit<Sandbox<ExtractProviderSandboxType<TProvider>>, 'getProvider'> {\n /** Get the provider instance that created this sandbox with proper typing */\n getProvider(): TProvider;\n /** Get the native provider sandbox instance with proper typing */\n getInstance(): ExtractProviderSandboxType<TProvider>;\n}","/**\n * Compute Singleton - Main API Orchestrator\n *\n * Provides the unified compute.* API and delegates to specialized managers\n */\n\nimport { ComputeClient } from '@computesdk/client';\nimport type { ComputeAPI, CreateSandboxParams, CreateSandboxParamsWithOptionalProvider, ComputeConfig, Sandbox, Provider, TypedSandbox, TypedComputeAPI } from './types';\n\n/**\n * Authorization response from license server\n */\ninterface AuthorizationResponse {\n jwt: string;\n sandbox_url: string;\n preview_url: string;\n}\n\n/**\n * Authorize license key and get JWT token + URLs from license server\n */\nasync function authorizeApiKey(apiKey: string): Promise<AuthorizationResponse> {\n try {\n const response = await fetch('https://preview.computesdk.com/__api/license/authorize', {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({\n key: apiKey,\n increment_usage: 1\n })\n });\n\n if (!response.ok) {\n throw new Error(`License authorization failed: ${response.statusText}`);\n }\n\n const data = await response.json();\n\n if (!data.access_token) {\n throw new Error('No JWT token received from license server');\n }\n\n if (!data.sandbox_url) {\n throw new Error('No sandbox_url received from license server');\n }\n\n if (!data.preview_url) {\n throw new Error('No preview_url received from license server');\n }\n\n return {\n jwt: data.access_token,\n sandbox_url: data.sandbox_url,\n preview_url: data.preview_url\n };\n } catch (error) {\n throw new Error(`Failed to authorize API key: ${error}`);\n }\n}\n\n/**\n * Install and start compute CLI inside a sandbox\n */\nasync function installComputeInSandbox(\n sandbox: Sandbox,\n config?: { apiKey?: string; jwt?: string }\n): Promise<AuthorizationResponse | null> {\n try {\n console.log('Installing and starting compute CLI in sandbox...');\n\n // Get JWT token and URLs from API key if provided\n let authResponse: AuthorizationResponse | null = null;\n let jwt = config?.jwt;\n\n if (config?.apiKey && !jwt) {\n console.log('Authorizing API key and getting JWT token...');\n authResponse = await authorizeApiKey(config.apiKey);\n jwt = authResponse.jwt;\n }\n\n // Build install command with authentication\n let installCommand = 'curl -fsSL https://computesdk.com/install.sh | sh';\n\n if (jwt) {\n installCommand = `curl -fsSL https://computesdk.com/install.sh | sh -s -- --jwt ${jwt}`;\n }\n\n // Run the install script (it will handle installation and starting compute)\n const result = await sandbox.runCommand('sh', ['-c', installCommand]);\n\n if (result.exitCode !== 0) {\n throw new Error(`Failed to install and start compute CLI: ${result.stderr}`);\n }\n\n console.log('Compute CLI installed and started successfully');\n\n return authResponse;\n } catch (error) {\n throw new Error(`Failed to install compute CLI in sandbox: ${error}`);\n }\n}\n\n/**\n * Compute singleton implementation - orchestrates all compute operations\n */\nclass ComputeManager implements ComputeAPI {\n private config: ComputeConfig | null = null;\n private typedState: {\n isTyped: boolean;\n provider: Provider | null;\n } = { isTyped: false, provider: null };\n private computeAuth: { apiKey?: string; jwt?: string } = {};\n\n /**\n * Set default configuration with generic type preservation\n */\n setConfig<TProvider extends Provider>(config: ComputeConfig<TProvider>): void {\n // Validate that at least one provider is specified\n if (!config.defaultProvider && !config.provider) {\n throw new Error('Either defaultProvider or provider must be specified in setConfig');\n }\n\n // Handle backwards compatibility: if both are provided, defaultProvider takes precedence\n if (config.defaultProvider && config.provider) {\n console.warn('Both defaultProvider and provider specified in setConfig. Using defaultProvider. The provider key is deprecated, please use defaultProvider instead.');\n }\n\n // Normalize config to always have both fields for internal use (backward compatibility)\n const actualProvider = config.defaultProvider || config.provider!;\n this.config = {\n provider: actualProvider,\n defaultProvider: actualProvider,\n apiKey: config.apiKey,\n jwt: config.jwt\n };\n\n // Store compute auth credentials\n this.computeAuth = {\n apiKey: config.apiKey,\n jwt: config.jwt\n };\n\n // Store typed state for type-aware operations\n this.typedState = {\n isTyped: true,\n provider: actualProvider\n };\n }\n\n /**\n * Get current configuration\n */\n getConfig(): ComputeConfig | null {\n return this.config;\n }\n\n /**\n * Clear current configuration\n */\n clearConfig(): void {\n this.config = null;\n }\n\n /**\n * Get the default provider, throwing if not configured\n */\n private getDefaultProvider(): Provider {\n const provider = this.config?.defaultProvider || this.config?.provider;\n if (!provider) {\n throw new Error(\n 'No default provider configured. Either call compute.setConfig({ defaultProvider }) or pass provider explicitly.'\n );\n }\n return provider;\n }\n\n sandbox = {\n /**\n * Create a sandbox from a provider (or default provider if configured)\n * \n * @example\n * ```typescript\n * import { e2b } from '@computesdk/e2b'\n * import { compute } from 'computesdk'\n * \n * // With explicit provider\n * const sandbox = await compute.sandbox.create({\n * provider: e2b({ apiKey: 'your-key' })\n * })\n * \n * // With default provider (both forms work)\n * compute.setConfig({ defaultProvider: e2b({ apiKey: 'your-key' }) })\n * const sandbox1 = await compute.sandbox.create({})\n * const sandbox2 = await compute.sandbox.create()\n * ```\n */\n create: async (params?: CreateSandboxParams | CreateSandboxParamsWithOptionalProvider): Promise<Sandbox> => {\n const provider = params && 'provider' in params && params.provider ? params.provider : this.getDefaultProvider();\n const options = params?.options;\n const sandbox = await provider.sandbox.create(options);\n\n // Install compute CLI in the sandbox with auth credentials if available\n const authResponse = await installComputeInSandbox(sandbox, this.computeAuth);\n\n // If we have authorization info, use ComputeClient instead of provider sandbox\n let finalSandbox: Sandbox = sandbox;\n if (authResponse) {\n finalSandbox = new ComputeClient({\n sandboxUrl: authResponse.sandbox_url,\n sandboxId: sandbox.sandboxId,\n provider: sandbox.provider,\n token: authResponse.jwt\n }) as Sandbox;\n }\n\n // If we have typed state and no explicit provider passed, cast to typed sandbox\n // This enables proper type inference for getInstance() when using default provider\n if (this.typedState.isTyped && (!params || !('provider' in params && params.provider))) {\n return finalSandbox as TypedSandbox<any>;\n }\n\n return finalSandbox;\n },\n\n /**\n * Get an existing sandbox by ID from a provider (or default provider if configured)\n */\n getById: async (providerOrSandboxId: Provider | string, sandboxId?: string): Promise<Sandbox | null> => {\n if (typeof providerOrSandboxId === 'string') {\n // Called with just sandboxId, use default provider\n const provider = this.getDefaultProvider();\n const sandbox = await provider.sandbox.getById(providerOrSandboxId);\n \n // If we have typed state, cast to typed sandbox for proper getInstance() typing\n if (this.typedState.isTyped && sandbox) {\n return sandbox as TypedSandbox<any>;\n }\n \n return sandbox;\n } else {\n // Called with provider and sandboxId\n if (!sandboxId) {\n throw new Error('sandboxId is required when provider is specified');\n }\n return await providerOrSandboxId.sandbox.getById(sandboxId);\n }\n },\n\n /**\n * List all active sandboxes from a provider (or default provider if configured)\n */\n list: async (provider?: Provider): Promise<Sandbox[]> => {\n const actualProvider = provider || this.getDefaultProvider();\n const sandboxes = await actualProvider.sandbox.list();\n \n // If we have typed state and no explicit provider passed, cast to typed sandboxes\n if (this.typedState.isTyped && !provider) {\n return sandboxes as TypedSandbox<any>[];\n }\n \n return sandboxes;\n },\n\n /**\n * Destroy a sandbox via a provider (or default provider if configured)\n */\n destroy: async (providerOrSandboxId: Provider | string, sandboxId?: string): Promise<void> => {\n if (typeof providerOrSandboxId === 'string') {\n // Called with just sandboxId, use default provider\n const provider = this.getDefaultProvider();\n return await provider.sandbox.destroy(providerOrSandboxId);\n } else {\n // Called with provider and sandboxId\n if (!sandboxId) {\n throw new Error('sandboxId is required when provider is specified');\n }\n return await providerOrSandboxId.sandbox.destroy(sandboxId);\n }\n }\n };\n\n // Future: compute.blob.*, compute.database.*, compute.git.* will be added here\n // blob = new BlobManager();\n // database = new DatabaseManager(); \n // git = new GitManager();\n\n\n}\n\n/**\n * Singleton instance - the main API (untyped)\n */\nexport const compute: ComputeAPI = new ComputeManager();\n\n\n\n/**\n * Create a compute instance with proper typing\n * \n * @example\n * ```typescript\n * import { e2b } from '@computesdk/e2b'\n * import { createCompute } from 'computesdk'\n * \n * const compute = createCompute({\n * defaultProvider: e2b({ apiKey: 'your-key' }),\n * });\n * \n * const sandbox = await compute.sandbox.create();\n * const instance = sandbox.getInstance(); // ✅ Properly typed E2B Sandbox!\n * ```\n */\nexport function createCompute<TProvider extends Provider>(config: ComputeConfig<TProvider>): TypedComputeAPI<TProvider> {\n const manager = new ComputeManager();\n\n // Set config directly without calling the public setConfig method\n const actualProvider = config.defaultProvider || config.provider!;\n manager['config'] = {\n provider: actualProvider,\n defaultProvider: actualProvider,\n apiKey: config.apiKey,\n jwt: config.jwt\n };\n manager['typedState'] = {\n isTyped: true,\n provider: actualProvider\n };\n manager['computeAuth'] = {\n apiKey: config.apiKey,\n jwt: config.jwt\n };\n\n return {\n setConfig: <T extends Provider>(cfg: ComputeConfig<T>) => createCompute(cfg),\n getConfig: () => manager.getConfig(),\n clearConfig: () => manager.clearConfig(),\n\n sandbox: {\n create: async (params?: Omit<CreateSandboxParamsWithOptionalProvider, 'provider'>) => {\n const sandbox = await manager.sandbox.create(params);\n // The sandbox should now have the correct getInstance typing from the generic Sandbox<TSandbox>\n return sandbox as TypedSandbox<TProvider>;\n },\n\n getById: async (sandboxId: string) => {\n const sandbox = await manager.sandbox.getById(sandboxId);\n return sandbox ? sandbox as TypedSandbox<TProvider> : null;\n },\n\n list: async () => {\n const sandboxes = await manager.sandbox.list();\n return sandboxes as TypedSandbox<TProvider>[];\n },\n\n destroy: async (sandboxId: string) => {\n return await manager.sandbox.destroy(sandboxId);\n }\n }\n } as TypedComputeAPI<TProvider>;\n}\n\n\n\n","/**\n * Simplified Request Handler for Web Framework Integration\n * \n * Handles JSON requests for sandbox and code execution operations.\n * Terminal support removed - will be re-added with WebSocket VM connections.\n */\n\nimport type { Provider, Runtime } from './types';\nimport { compute } from './compute';\n\n/**\n * Request structure supporting sandbox and code execution capabilities\n */\nexport interface ComputeRequest {\n /** Action in dot notation (e.g., 'compute.sandbox.create') */\n action: string;\n \n /** Parameters for the action */\n sandboxId?: string;\n code?: string;\n command?: string;\n args?: string[];\n runtime?: Runtime;\n path?: string;\n content?: string;\n \n /** Command options (for runCommand action) */\n commandOptions?: {\n background?: boolean;\n };\n \n /** Sandbox creation options */\n options?: {\n runtime?: Runtime;\n timeout?: number;\n sandboxId?: string;\n };\n}\n\n/**\n * Response structure for compute operations\n */\nexport interface ComputeResponse {\n success: boolean;\n error?: string;\n sandboxId: string;\n provider: string;\n [key: string]: any; // Allow any additional response data\n}\n\n/**\n * Execute compute action using targeted handling\n */\nasync function executeAction(body: ComputeRequest, provider: Provider): Promise<ComputeResponse> {\n try {\n const { action, sandboxId } = body;\n \n // Sandbox management operations\n if (action === 'compute.sandbox.create') {\n const sandbox = await compute.sandbox.create({\n provider,\n options: body.options || { runtime: 'python' }\n });\n return {\n success: true,\n sandboxId: sandbox.sandboxId,\n provider: provider.name\n };\n }\n \n if (action === 'compute.sandbox.list') {\n const sandboxes = await compute.sandbox.list(provider);\n return {\n success: true,\n sandboxId: '',\n provider: provider.name,\n sandboxes: sandboxes.map(sb => ({\n sandboxId: sb.sandboxId,\n provider: sb.provider\n }))\n };\n }\n \n if (action === 'compute.sandbox.destroy') {\n if (!sandboxId) {\n throw new Error('sandboxId is required for destroy action');\n }\n await compute.sandbox.destroy(provider, sandboxId);\n return {\n success: true,\n sandboxId,\n provider: provider.name\n };\n }\n \n // For sandbox instance methods, get the sandbox first\n if (!sandboxId) {\n throw new Error('sandboxId is required for this action');\n }\n \n const sandbox = await compute.sandbox.getById(provider, sandboxId);\n if (!sandbox) {\n throw new Error(`Sandbox ${sandboxId} not found`);\n }\n \n // Sandbox info\n if (action === 'compute.sandbox.getInfo') {\n const result = await sandbox.getInfo();\n return {\n success: true,\n sandboxId,\n provider: provider.name,\n info: {\n id: result.id,\n provider: result.provider,\n runtime: result.runtime,\n status: result.status,\n createdAt: result.createdAt.toISOString(),\n timeout: result.timeout,\n metadata: result.metadata\n }\n };\n }\n \n // Code execution\n if (action === 'compute.sandbox.runCode') {\n if (!body.code) throw new Error('code is required');\n const result = await sandbox.runCode(body.code, body.runtime);\n return {\n success: true,\n sandboxId,\n provider: provider.name,\n result: {\n stdout: result.stdout,\n stderr: result.stderr,\n exitCode: result.exitCode,\n executionTime: result.executionTime\n }\n };\n }\n \n if (action === 'compute.sandbox.runCommand') {\n if (!body.command) throw new Error('command is required');\n const result = await sandbox.runCommand(body.command, body.args, body.commandOptions);\n return {\n success: true,\n sandboxId,\n provider: provider.name,\n result: {\n stdout: result.stdout,\n stderr: result.stderr,\n exitCode: result.exitCode,\n executionTime: result.executionTime,\n ...(result.isBackground && { isBackground: result.isBackground }),\n ...(result.pid && { pid: result.pid })\n }\n };\n }\n \n // Filesystem operations\n if (action === 'compute.sandbox.filesystem.readFile') {\n if (!body.path) throw new Error('path is required');\n const result = await sandbox.filesystem.readFile(body.path);\n return {\n success: true,\n sandboxId,\n provider: provider.name,\n fileContent: result\n };\n }\n \n if (action === 'compute.sandbox.filesystem.writeFile') {\n if (!body.path) throw new Error('path is required');\n if (body.content === undefined) throw new Error('content is required');\n await sandbox.filesystem.writeFile(body.path, body.content);\n return { success: true, sandboxId, provider: provider.name };\n }\n \n if (action === 'compute.sandbox.filesystem.mkdir') {\n if (!body.path) throw new Error('path is required');\n await sandbox.filesystem.mkdir(body.path);\n return { success: true, sandboxId, provider: provider.name };\n }\n \n if (action === 'compute.sandbox.filesystem.readdir') {\n if (!body.path) throw new Error('path is required');\n const result = await sandbox.filesystem.readdir(body.path);\n return {\n success: true,\n sandboxId,\n provider: provider.name,\n files: result.map((entry: any) => ({\n name: entry.name,\n path: entry.path,\n isDirectory: entry.isDirectory,\n size: entry.size,\n lastModified: entry.lastModified.toISOString()\n }))\n };\n }\n \n if (action === 'compute.sandbox.filesystem.exists') {\n if (!body.path) throw new Error('path is required');\n const result = await sandbox.filesystem.exists(body.path);\n return {\n success: true,\n sandboxId,\n provider: provider.name,\n exists: result\n };\n }\n \n if (action === 'compute.sandbox.filesystem.remove') {\n if (!body.path) throw new Error('path is required');\n await sandbox.filesystem.remove(body.path);\n return { success: true, sandboxId, provider: provider.name };\n }\n \n throw new Error(`Unknown action: ${action}`);\n \n } catch (error) {\n return {\n success: false,\n error: error instanceof Error ? error.message : 'Unknown error occurred',\n sandboxId: body.sandboxId || '',\n provider: provider.name\n };\n }\n}\n\n/**\n * Main request handler - handles HTTP requests and pre-parsed bodies\n */\nexport async function handleComputeRequest(\n params: HandleComputeRequestParams\n): Promise<ComputeResponse>;\nexport async function handleComputeRequest(\n requestOrBody: Request | ComputeRequest,\n provider: Provider\n): Promise<Response>;\nexport async function handleComputeRequest(\n paramsOrRequestOrBody: HandleComputeRequestParams | Request | ComputeRequest,\n provider?: Provider\n): Promise<ComputeResponse | Response> {\n // Handle object-style API\n if (typeof paramsOrRequestOrBody === 'object' && 'request' in paramsOrRequestOrBody && 'provider' in paramsOrRequestOrBody) {\n const params = paramsOrRequestOrBody as HandleComputeRequestParams;\n return await executeAction(params.request, params.provider);\n }\n \n // Handle original API\n if (!provider) {\n throw new Error('Provider is required when not using object-style API');\n }\n \n const requestOrBody = paramsOrRequestOrBody as Request | ComputeRequest;\n try {\n let body: ComputeRequest;\n \n if (requestOrBody instanceof Request) {\n // Handle HTTP method validation\n if (requestOrBody.method !== 'POST') {\n return Response.json({\n success: false,\n error: 'Only POST requests are supported',\n sandboxId: '',\n provider: provider.name\n }, { status: 405 });\n }\n \n // Parse JSON body with better error handling\n try {\n body = await requestOrBody.json();\n } catch (parseError) {\n return Response.json({\n success: false,\n error: 'Invalid JSON in request body',\n sandboxId: '',\n provider: provider.name\n }, { status: 400 });\n }\n } else {\n body = requestOrBody;\n }\n \n // Execute the action\n const result = await executeAction(body, provider);\n \n return Response.json(result, {\n status: result.success ? 200 : 500\n });\n \n } catch (error) {\n return Response.json({\n success: false,\n error: error instanceof Error ? error.message : 'Request handling failed',\n sandboxId: '',\n provider: provider.name\n }, { status: 500 });\n }\n}\n\n/**\n * Legacy export for backward compatibility\n */\nexport interface HandleComputeRequestParams {\n request: ComputeRequest;\n provider: Provider;\n}\n\nexport { handleComputeRequest as handleHttpComputeRequest };","/**\n * Provider Factory - Creates providers from method definitions\n * \n * Eliminates boilerplate by auto-generating Provider/Sandbox classes\n * from simple method definitions with automatic feature detection.\n */\n\nimport type {\n Provider,\n ProviderSandboxManager,\n ProviderTemplateManager,\n ProviderSnapshotManager,\n Sandbox,\n SandboxFileSystem,\n SandboxInfo,\n ExecutionResult,\n Runtime,\n CreateSandboxOptions,\n FileEntry,\n RunCommandOptions,\n CreateSnapshotOptions,\n ListSnapshotsOptions,\n CreateTemplateOptions,\n ListTemplatesOptions,\n} from './types/index.js';\n\n/**\n * Helper function to handle background command execution\n * Providers can use this to implement background job support\n */\nexport function createBackgroundCommand(command: string, args: string[] = [], options?: RunCommandOptions): { command: string; args: string[]; isBackground: boolean } {\n if (!options?.background) {\n return { command, args, isBackground: false };\n }\n\n // For background execution, we modify the command to run in background\n // Default approach: append & to make it run in background\n const fullCommand = args.length > 0 ? `${command} ${args.join(' ')}` : command;\n \n return {\n command: 'sh',\n args: ['-c', `${fullCommand} &`],\n isBackground: true\n };\n}\n\n/**\n * Flat sandbox method implementations - all operations in one place\n */\nexport interface SandboxMethods<TSandbox = any, TConfig = any> {\n // Collection operations (map to compute.sandbox.*)\n create: (config: TConfig, options?: CreateSandboxOptions) => Promise<{ sandbox: TSandbox; sandboxId: string }>;\n getById: (config: TConfig, sandboxId: string) => Promise<{ sandbox: TSandbox; sandboxId: string } | null>;\n list: (config: TConfig) => Promise<Array<{ sandbox: TSandbox; sandboxId: string }>>;\n destroy: (config: TConfig, sandboxId: string) => Promise<void>;\n \n // Instance operations (map to individual Sandbox methods)\n runCode: (sandbox: TSandbox, code: string, runtime?: Runtime, config?: TConfig) => Promise<ExecutionResult>;\n runCommand: (sandbox: TSandbox, command: string, args?: string[], options?: RunCommandOptions) => Promise<ExecutionResult>;\n getInfo: (sandbox: TSandbox) => Promise<SandboxInfo>;\n getUrl: (sandbox: TSandbox, options: { port: number; protocol?: string }) => Promise<string>;\n \n // Optional provider-specific typed getInstance method\n getInstance?: (sandbox: TSandbox) => TSandbox;\n \n // Optional filesystem methods\n filesystem?: {\n readFile: (sandbox: TSandbox, path: string, runCommand: (sandbox: TSandbox, command: string, args?: string[]) => Promise<ExecutionResult>) => Promise<string>;\n writeFile: (sandbox: TSandbox, path: string, content: string, runCommand: (sandbox: TSandbox, command: string, args?: string[]) => Promise<ExecutionResult>) => Promise<void>;\n mkdir: (sandbox: TSandbox, path: string, runCommand: (sandbox: TSandbox, command: string, args?: string[]) => Promise<ExecutionResult>) => Promise<void>;\n readdir: (sandbox: TSandbox, path: string, runCommand: (sandbox: TSandbox, command: string, args?: string[]) => Promise<ExecutionResult>) => Promise<FileEntry[]>;\n exists: (sandbox: TSandbox, path: string, runCommand: (sandbox: TSandbox, command: string, args?: string[]) => Promise<ExecutionResult>) => Promise<boolean>;\n remove: (sandbox: TSandbox, path: string, runCommand: (sandbox: TSandbox, command: string, args?: string[]) => Promise<ExecutionResult>) => Promise<void>;\n };\n}\n\n/**\n * Template method implementations\n */\nexport interface TemplateMethods<TTemplate = any, TConfig = any> {\n create: (config: TConfig, options: CreateTemplateOptions | any) => Promise<TTemplate>;\n list: (config: TConfig, options?: ListTemplatesOptions) => Promise<TTemplate[]>;\n delete: (config: TConfig, templateId: string) => Promise<void>;\n}\n\n/**\n * Snapshot method implementations \n */\nexport interface SnapshotMethods<TSnapshot = any, TConfig = any> {\n create: (config: TConfig, sandboxId: string, options?: CreateSnapshotOptions) => Promise<TSnapshot>;\n list: (config: TConfig, options?: ListSnapshotsOptions) => Promise<TSnapshot[]>;\n delete: (config: TConfig, snapshotId: string) => Promise<void>;\n}\n\n/**\n * Provider configuration for createProvider()\n */\nexport interface ProviderConfig<TSandbox = any, TConfig = any, TTemplate = any, TSnapshot = any> {\n name: string;\n methods: {\n sandbox: SandboxMethods<TSandbox, TConfig>;\n template?: TemplateMethods<TTemplate, TConfig>;\n snapshot?: SnapshotMethods<TSnapshot, TConfig>;\n };\n}\n\n/**\n * Default filesystem implementations based on shell commands\n * These work for any provider that supports shell command execution\n */\nconst defaultFilesystemMethods = {\n readFile: async (sandbox: any, path: string, runCommand: (sandbox: any, command: string, args?: string[]) => Promise<ExecutionResult>): Promise<string> => {\n const result = await runCommand(sandbox, 'cat', [path]);\n if (result.exitCode !== 0) {\n throw new Error(`Failed to read file ${path}: ${result.stderr}`);\n }\n // Trim trailing newline that cat command adds\n return result.stdout.replace(/\\n$/, '');\n },\n\n writeFile: async (sandbox: any, path: string, content: string, runCommand: (sandbox: any, command: string, args?: string[]) => Promise<ExecutionResult>): Promise<void> => {\n const result = await runCommand(sandbox, 'sh', ['-c', `echo ${JSON.stringify(content)} > ${JSON.stringify(path)}`]);\n if (result.exitCode !== 0) {\n throw new Error(`Failed to write file ${path}: ${result.stderr}`);\n }\n },\n\n mkdir: async (sandbox: any, path: string, runCommand: (sandbox: any, command: string, args?: string[]) => Promise<ExecutionResult>): Promise<void> => {\n const result = await runCommand(sandbox, 'mkdir', ['-p', path]);\n if (result.exitCode !== 0) {\n throw new Error(`Failed to create directory ${path}: ${result.stderr}`);\n }\n },\n\n readdir: async (sandbox: any, path: string, runCommand: (sandbox: any, command: string, args?: string[]) => Promise<ExecutionResult>): Promise<FileEntry[]> => {\n // Try different ls variations for maximum compatibility\n let result = await runCommand(sandbox, 'ls', ['-la', path]);\n let hasDetailedOutput = true;\n \n // Fall back to basic ls if detailed flags not supported\n if (result.exitCode !== 0) {\n result = await runCommand(sandbox, 'ls', ['-l', path]);\n }\n if (result.exitCode !== 0) {\n result = await runCommand(sandbox, 'ls', [path]);\n hasDetailedOutput = false;\n }\n \n if (result.exitCode !== 0) {\n throw new Error(`Failed to list directory ${path}: ${result.stderr}`);\n }\n\n const lines = (result.stdout || '').split('\\n').filter((line: string) => line.trim() && !line.startsWith('total'));\n\n return lines.map((line: string) => {\n if (hasDetailedOutput && line.includes(' ')) {\n // Parse detailed ls output (ls -la or ls -l)\n const parts = line.trim().split(/\\s+/);\n const name = parts[parts.length - 1];\n const isDirectory = line.startsWith('d');\n \n return {\n name,\n path: `${path}/${name}`,\n isDirectory,\n size: parseInt(parts[4]) || 0,\n lastModified: new Date()\n };\n } else {\n // Parse simple ls output (just filenames)\n const name = line.trim();\n return {\n name,\n path: `${path}/${name}`,\n isDirectory: false, // Can't determine from simple ls\n size: 0,\n lastModified: new Date()\n };\n }\n });\n },\n\n exists: async (sandbox: any, path: string, runCommand: (sandbox: any, command: string, args?: string[]) => Promise<ExecutionResult>): Promise<boolean> => {\n const result = await runCommand(sandbox, 'test', ['-e', path]);\n return result.exitCode === 0; // Exit code 0 means file exists\n },\n\n remove: async (sandbox: any, path: string, runCommand: (sandbox: any, command: string, args?: string[]) => Promise<ExecutionResult>): Promise<void> => {\n const result = await runCommand(sandbox, 'rm', ['-rf', path]);\n if (result.exitCode !== 0) {\n throw new Error(`Failed to remove ${path}: ${result.stderr}`);\n }\n }\n};\n\n/**\n * Auto-generated filesystem implementation that throws \"not supported\" errors\n */\nclass UnsupportedFileSystem implements SandboxFileSystem {\n private readonly providerName: string;\n\n constructor(providerName: string) {\n this.providerName = providerName;\n }\n\n async readFile(_path: string): Promise<string> {\n throw new Error(`Filesystem operations are not supported by ${this.providerName}'s sandbox environment. ${this.providerName} sandboxes are designed for code execution only.`);\n }\n\n async writeFile(_path: string, _content: string): Promise<void> {\n throw new Error(`Filesystem operations are not supported by ${this.providerName}'s sandbox environment. ${this.providerName} sandboxes are designed for code execution only.`);\n }\n\n async mkdir(_path: string): Promise<void> {\n throw new Error(`Filesystem operations are not supported by ${this.providerName}'s sandbox environment. ${this.providerName} sandboxes are designed for code execution only.`);\n }\n\n async readdir(_path: string): Promise<FileEntry[]> {\n throw new Error(`Filesystem operations are not supported by ${this.providerName}'s sandbox environment. ${this.providerName} sandboxes are designed for code execution only.`);\n }\n\n async exists(_path: string): Promise<boolean> {\n throw new Error(`Filesystem operations are not supported by ${this.providerName}'s sandbox environment. ${this.providerName} sandboxes are designed for code execution only.`);\n }\n\n async remove(_path: string): Promise<void> {\n throw new Error(`Filesystem operations are not supported by ${this.providerName}'s sandbox environment. ${this.providerName} sandboxes are designed for code execution only.`);\n }\n}\n\n\n\n/**\n * Auto-generated filesystem implementation that wraps provider methods\n */\nclass SupportedFileSystem<TSandbox> implements SandboxFileSystem {\n constructor(\n private sandbox: TSandbox,\n private methods: NonNullable<SandboxMethods<TSandbox>['filesystem']>,\n private allMethods: SandboxMethods<TSandbox>\n ) {}\n\n async readFile(path: string): Promise<string> {\n return this.methods.readFile(this.sandbox, path, this.allMethods.runCommand);\n }\n\n async writeFile(path: string, content: string): Promise<void> {\n return this.methods.writeFile(this.sandbox, path, content, this.allMethods.runCommand);\n }\n\n async mkdir(path: string): Promise<void> {\n return this.methods.mkdir(this.sandbox, path, this.allMethods.runCommand);\n }\n\n async readdir(path: string): Promise<FileEntry[]> {\n return this.methods.readdir(this.sandbox, path, this.allMethods.runCommand);\n }\n\n async exists(path: string): Promise<boolean> {\n return this.methods.exists(this.sandbox, path, this.allMethods.runCommand);\n }\n\n async remove(path: string): Promise<void> {\n return this.methods.remove(this.sandbox, path, this.allMethods.runCommand);\n }\n}\n\n\n\n\n\n/**\n * Generated sandbox class - implements the Sandbox interface\n */\nclass GeneratedSandbox<TSandbox = any> implements Sandbox<TSandbox> {\n readonly sandboxId: string;\n readonly provider: string;\n readonly filesystem: SandboxFileSystem;\n\n constructor(\n private sandbox: TSandbox,\n sandboxId: string,\n providerName: string,\n private methods: SandboxMethods<TSandbox>,\n private config: any,\n private destroyMethod: (config: any, sandboxId: string) => Promise<void>,\n private providerInstance: Provider\n ) {\n this.sandboxId = sandboxId;\n this.provider = providerName;\n\n // Auto-detect filesystem support\n if (methods.filesystem) {\n this.filesystem = new SupportedFileSystem(sandbox, methods.filesystem, methods);\n } else {\n this.filesystem = new UnsupportedFileSystem(providerName);\n }\n }\n\n getInstance(): TSandbox {\n // Use provider-specific typed getInstance if available\n if (this.methods.getInstance) {\n return this.methods.getInstance(this.sandbox);\n }\n // Fallback to returning the sandbox directly\n return this.sandbox;\n }\n\n async runCode(code: string, runtime?: Runtime): Promise<ExecutionResult> {\n return await this.methods.runCode(this.sandbox, code, runtime, this.config);\n }\n\n async runCommand(command: string, args?: string[], options?: RunCommandOptions): Promise<ExecutionResult> {\n return await this.methods.runCommand(this.sandbox, command, args, options);\n }\n\n async getInfo(): Promise<SandboxInfo> {\n return await this.methods.getInfo(this.sandbox);\n }\n\n async getUrl(options: { port: number; protocol?: string }): Promise<string> {\n return await this.methods.getUrl(this.sandbox, options);\n }\n\n getProvider(): Provider<TSandbox> {\n return this.providerInstance;\n }\n\n async kill(): Promise<void> {\n // For backward compatibility, kill() delegates to destroy()\n await this.destroy();\n }\n\n async destroy(): Promise<void> {\n // Destroy via the provider's destroy method using our sandboxId\n await this.destroyMethod(this.config, this.sandboxId);\n }\n}\n\n/**\n * Auto-generated Sandbox Manager implementation\n */\nclass GeneratedSandboxManager<TSandbox, TConfig> implements ProviderSandboxManager<TSandbox> {\n private activeSandboxes: Map<string, GeneratedSandbox<TSandbox>> = new Map();\n\n constructor(\n private config: TConfig,\n private providerName: string,\n private methods: SandboxMethods<TSandbox, TConfig>,\n private providerInstance: Provider\n ) {}\n\n async create(options?: CreateSandboxOptions): Promise<Sandbox<TSandbox>> {\n // Default to 'node' runtime if not specified for consistency across providers\n const optionsWithDefaults = { runtime: 'node' as Runtime, ...options };\n const result = await this.methods.create(this.config, optionsWithDefaults);\n const sandbox = new GeneratedSandbox<TSandbox>(\n result.sandbox,\n result.sandboxId,\n this.providerName,\n this.methods,\n this.config,\n this.methods.destroy,\n this.providerInstance\n );\n \n this.activeSandboxes.set(result.sandboxId, sandbox);\n return sandbox;\n }\n\n async getById(sandboxId: string): Promise<Sandbox<TSandbox> | null> {\n // Check active sandboxes first\n const existing = this.activeSandboxes.get(sandboxId);\n if (existing) {\n return existing;\n }\n\n // Try to reconnect\n const result = await this.methods.getById(this.config, sandboxId);\n if (!result) {\n return null;\n }\n\n const sandbox = new GeneratedSandbox<TSandbox>(\n result.sandbox,\n result.sandboxId,\n this.providerName,\n this.methods,\n this.config,\n this.methods.destroy,\n this.providerInstance\n );\n \n this.activeSandboxes.set(result.sandboxId, sandbox);\n return sandbox;\n }\n\n async list(): Promise<Sandbox<TSandbox>[]> {\n const results = await this.methods.list(this.config);\n const sandboxes: Sandbox[] = [];\n\n for (const result of results) {\n let sandbox = this.activeSandboxes.get(result.sandboxId);\n if (!sandbox) {\n sandbox = new GeneratedSandbox<TSandbox>(\n result.sandbox,\n result.sandboxId,\n this.providerName,\n this.methods,\n this.config,\n this.methods.destroy,\n this.providerInstance\n );\n this.activeSandboxes.set(result.sandboxId, sandbox);\n }\n sandboxes.push(sandbox);\n }\n\n return sandboxes;\n }\n\n async destroy(sandboxId: string): Promise<void> {\n await this.methods.destroy(this.config, sandboxId);\n this.activeSandboxes.delete(sandboxId);\n }\n}\n\n/**\n * Auto-generated Template Manager implementation\n */\nclass GeneratedTemplateManager<TTemplate, TConfig> implements ProviderTemplateManager<TTemplate> {\n constructor(\n private config: TConfig,\n private methods: TemplateMethods<TTemplate, TConfig>\n ) {}\n\n async create(options: CreateTemplateOptions | any): Promise<TTemplate> {\n return await this.methods.create(this.config, options);\n }\n\n async list(options?: ListTemplatesOptions): Promise<TTemplate[]> {\n return await this.methods.list(this.config, options);\n }\n\n async delete(templateId: string): Promise<void> {\n return await this.methods.delete(this.config, templateId);\n }\n}\n\n/**\n * Auto-generated Snapshot Manager implementation\n */\nclass GeneratedSnapshotManager<TSnapshot, TConfig> implements ProviderSnapshotManager<TSnapshot> {\n constructor(\n private config: TConfig,\n private methods: SnapshotMethods<TSnapshot, TConfig>\n ) {}\n\n async create(sandboxId: string, options?: CreateSnapshotOptions): Promise<TSnapshot> {\n return await this.methods.create(this.config, sandboxId, options);\n }\n\n async list(options?: ListSnapshotsOptions): Promise<TSnapshot[]> {\n return await this.methods.list(this.config, options);\n }\n\n async delete(snapshotId: string): Promise<void> {\n return await this.methods.delete(this.config, snapshotId);\n }\n}\n\n/**\n * Auto-generated Provider implementation\n */\nclass GeneratedProvider<TSandbox, TConfig, TTemplate, TSnapshot> implements Provider<TSandbox, TTemplate, TSnapshot> {\n readonly name: string;\n readonly sandbox: ProviderSandboxManager<TSandbox>;\n readonly template?: ProviderTemplateManager<TTemplate>;\n readonly snapshot?: ProviderSnapshotManager<TSnapshot>;\n readonly __sandboxType!: TSandbox; // Phantom type for TypeScript inference\n\n constructor(config: TConfig, providerConfig: ProviderConfig<TSandbox, TConfig, TTemplate, TSnapshot>) {\n this.name = providerConfig.name;\n this.sandbox = new GeneratedSandboxManager(\n config,\n providerConfig.name,\n providerConfig.methods.sandbox,\n this\n );\n\n // Initialize optional managers if methods are provided\n if (providerConfig.methods.template) {\n this.template = new GeneratedTemplateManager(config, providerConfig.methods.template);\n }\n \n if (providerConfig.methods.snapshot) {\n this.snapshot = new GeneratedSnapshotManager(config, providerConfig.methods.snapshot);\n }\n }\n\n getSupportedRuntimes(): Runtime[] {\n // For now, all providers support both node and python\n // In the future, this could be configurable per provider\n return ['node', 'python'];\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 = any, TTemplate = any, TSnapshot = any>(\n providerConfig: ProviderConfig<TSandbox, TConfig, TTemplate, TSnapshot>\n): (config: TConfig) => Provider<TSandbox, TTemplate, TSnapshot> {\n // Auto-inject default filesystem methods if none provided\n if (!providerConfig.methods.sandbox.filesystem) {\n providerConfig.methods.sandbox.filesystem = defaultFilesystemMethods;\n }\n\n return (config: TConfig) => {\n return new GeneratedProvider(config, providerConfig);\n };\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACwJO,IAAM,mBAAN,cAA+B,MAAM;AAAA,EAE1C,YAAmB,QAKhB;AACD,UAAM,4BAA4B,OAAO,QAAQ,EAAE;AANlC;AADnB,gBAAO;AAAA,EAQP;AACF;AAKO,SAAS,mBAAmB,OAA2C;AAC5E,SACE,OAAO,UAAU,YACjB,UAAU,QACV,UAAU,SACV,MAAM,SAAS,sBACf,YAAY;AAEhB;;;ACzKA,oBAA8B;AAe9B,eAAe,gBAAgB,QAAgD;AAC7E,MAAI;AACF,UAAM,WAAW,MAAM,MAAM,0DAA0D;AAAA,MACrF,QAAQ;AAAA,MACR,SAAS;AAAA,QACP,gBAAgB;AAAA,MAClB;AAAA,MACA,MAAM,KAAK,UAAU;AAAA,QACnB,KAAK;AAAA,QACL,iBAAiB;AAAA,MACnB,CAAC;AAAA,IACH,CAAC;AAED,QAAI,CAAC,SAAS,IAAI;AAChB,YAAM,IAAI,MAAM,iCAAiC,SAAS,UAAU,EAAE;AAAA,IACxE;AAEA,UAAM,OAAO,MAAM,SAAS,KAAK;AAEjC,QAAI,CAAC,KAAK,cAAc;AACtB,YAAM,IAAI,MAAM,2CAA2C;AAAA,IAC7D;AAEA,QAAI,CAAC,KAAK,aAAa;AACrB,YAAM,IAAI,MAAM,6CAA6C;AAAA,IAC/D;AAEA,QAAI,CAAC,KAAK,aAAa;AACrB,YAAM,IAAI,MAAM,6CAA6C;AAAA,IAC/D;AAEA,WAAO;AAAA,MACL,KAAK,KAAK;AAAA,MACV,aAAa,KAAK;AAAA,MAClB,aAAa,KAAK;AAAA,IACpB;AAAA,EACF,SAAS,OAAO;AACd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qH;AAAA;AAAA,EAOnH,YAAY,QAAiB,gBAAyE;AACpG,SAAK,OAAO,eAAe;AAC3B,SAAK,UAAU,IAAI;AAAA,MACjB;AAAA,MACA,eAAe;AAAA,MACf,eAAe,QAAQ;AAAA,MACvB;AAAA,IACF;AAGA,QAAI,eAAe,QAAQ,UAAU;AACnC,WAAK,WAAW,IAAI,yBAAyB,QAAQ,eAAe,QAAQ,QAAQ;AAAA,IACtF;AAEA,QAAI,eAAe,QAAQ,UAAU;AACnC,WAAK,WAAW,IAAI,yBAAyB,QAAQ,eAAe,QAAQ,QAAQ;AAAA,IACtF;AAAA,EACF;AAAA,EAEA,uBAAkC;AAGhC,WAAO,CAAC,QAAQ,QAAQ;AAAA,EAC1B;AACF;AAQO,SAAS,eACd,gBAC+D;AAE/D,MAAI,CAAC,eAAe,QAAQ,QAAQ,YAAY;AAC9C,mBAAe,QAAQ,QAAQ,aAAa;AAAA,EAC9C;AAEA,SAAO,CAAC,WAAoB;AAC1B,WAAO,IAAI,kBAAkB,QAAQ,cAAc;AAAA,EACrD;AACF;","names":["sandbox"]}
|
package/dist/index.mjs
CHANGED
|
@@ -28,7 +28,7 @@ async function authorizeApiKey(apiKey) {
|
|
|
28
28
|
throw new Error(`License authorization failed: ${response.statusText}`);
|
|
29
29
|
}
|
|
30
30
|
const data = await response.json();
|
|
31
|
-
if (!data.
|
|
31
|
+
if (!data.access_token) {
|
|
32
32
|
throw new Error("No JWT token received from license server");
|
|
33
33
|
}
|
|
34
34
|
if (!data.sandbox_url) {
|
|
@@ -38,7 +38,7 @@ async function authorizeApiKey(apiKey) {
|
|
|
38
38
|
throw new Error("No preview_url received from license server");
|
|
39
39
|
}
|
|
40
40
|
return {
|
|
41
|
-
jwt: data.
|
|
41
|
+
jwt: data.access_token,
|
|
42
42
|
sandbox_url: data.sandbox_url,
|
|
43
43
|
preview_url: data.preview_url
|
|
44
44
|
};
|
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 * Type mapping for provider names to their sandbox types\n * Manually defined for known providers since declaration merging isn't working reliably\n */\nexport interface ProviderSandboxTypeMap {\n e2b: any; // We can't import the E2B type directly, but we'll handle it differently\n vercel: any;\n daytona: any;\n}\n\n/**\n * Utility type to extract the native instance type from a provider\n * Uses provider name and manual type inference\n */\nexport type ExtractSandboxInstanceType<TProvider extends Provider> = \n TProvider extends { readonly name: 'e2b' }\n ? any // For now, let's just try to make the runtime casting work\n : TProvider extends { readonly name: 'vercel' }\n ? any\n : TProvider extends { readonly name: 'daytona' }\n ? any\n : any;\n\n/**\n * Supported runtime environments\n */\nexport type Runtime = 'node' | 'python';\n\n/**\n * Sandbox status types\n */\nexport type SandboxStatus = 'running' | 'stopped' | 'error';\n\n/**\n * Options for running commands\n */\nexport interface RunCommandOptions {\n /** Run command in background (non-blocking) */\n background?: boolean;\n}\n\n/**\n * Result of code execution\n */\nexport interface ExecutionResult {\n /** Standard output from the execution */\n stdout: string;\n /** Standard error from the execution */\n stderr: string;\n /** Exit code from the execution */\n exitCode: number;\n /** Time taken for execution in milliseconds */\n executionTime: number;\n /** ID of the sandbox where the code was executed */\n sandboxId: string;\n /** Provider that executed the code */\n provider: string;\n /** Process ID for background jobs (if applicable) */\n pid?: number;\n /** Whether this command is running in background */\n isBackground?: boolean;\n}\n\n/**\n * Information about a sandbox\n */\nexport interface SandboxInfo {\n /** Unique identifier for the sandbox */\n id: string;\n /** Provider hosting the sandbox */\n provider: string;\n /** Runtime environment in the sandbox */\n runtime: Runtime;\n /** Current status of the sandbox */\n status: SandboxStatus;\n /** When the sandbox was created */\n createdAt: Date;\n /** Execution timeout in milliseconds */\n timeout: number;\n /** Additional provider-specific metadata */\n metadata?: Record<string, any>;\n}\n\n/**\n * Options for creating a sandbox\n */\nexport interface CreateSandboxOptions {\n /** Runtime environment (defaults to 'node' if not specified) */\n runtime?: Runtime;\n /** Execution timeout in milliseconds */\n timeout?: number;\n /** Custom sandbox ID (if supported by provider) */\n sandboxId?: string;\n /** Template ID for sandbox creation (provider-specific) */\n templateId?: string;\n /** Additional metadata for the sandbox */\n metadata?: Record<string, any>;\n /** Domain for sandbox connection (provider-specific) */\n domain?: string;\n /** Environment variables for the sandbox */\n envs?: Record<string, string>;\n}\n\n/**\n * File system entry information\n */\nexport interface FileEntry {\n /** File/directory name */\n name: string;\n /** Full path to the entry */\n path: string;\n /** Whether this is a directory */\n isDirectory: boolean;\n /** File size in bytes (0 for directories) */\n size: number;\n /** Last modified timestamp */\n lastModified: Date;\n}\n\n/**\n * File system interface for sandbox operations\n */\nexport interface SandboxFileSystem {\n /** Read file contents */\n readFile(path: string): Promise<string>;\n /** Write file contents */\n writeFile(path: string, content: string): Promise<void>;\n /** Create directory */\n mkdir(path: string): Promise<void>;\n /** List directory contents */\n readdir(path: string): Promise<FileEntry[]>;\n /** Check if file/directory exists */\n exists(path: string): Promise<boolean>;\n /** Remove file or directory */\n remove(path: string): Promise<void>;\n}\n\n/**\n * Error thrown when a command exits with a non-zero status\n */\nexport class CommandExitError extends Error {\n name = 'CommandExitError';\n constructor(public result: {\n exitCode: number;\n stdout: string;\n stderr: string;\n error: boolean;\n }) {\n super(`Command exited with code ${result.exitCode}`);\n }\n}\n\n/**\n * Type guard to check if an error is a CommandExitError\n */\nexport function isCommandExitError(error: unknown): error is CommandExitError {\n return (\n typeof error === 'object' &&\n error !== null &&\n 'name' in error &&\n error.name === 'CommandExitError' &&\n 'result' in error\n );\n}\n\n\n\n\n\n/**\n * Base sandbox interface - what developers interact with\n */\nexport interface Sandbox<TSandbox = any> {\n /** Unique identifier for the sandbox */\n readonly sandboxId: string;\n /** Provider that created this sandbox */\n readonly provider: string;\n\n /** Execute code in the sandbox */\n runCode(code: string, runtime?: Runtime): Promise<ExecutionResult>;\n /** Execute shell commands */\n runCommand(command: string, args?: string[], options?: RunCommandOptions): Promise<ExecutionResult>;\n /** Get information about the sandbox */\n getInfo(): Promise<SandboxInfo>;\n /** Get URL for accessing the sandbox on a specific port */\n getUrl(options: { port: number; protocol?: string }): Promise<string>;\n /** Get the provider instance that created this sandbox */\n getProvider(): import('./provider').Provider<TSandbox>;\n /** Get the native provider sandbox instance with proper typing */\n getInstance(): TSandbox;\n /** Kill the sandbox */\n kill(): Promise<void>;\n /** Destroy the sandbox and clean up resources */\n destroy(): Promise<void>;\n\n /** File system operations */\n readonly filesystem: SandboxFileSystem;\n}\n\n/**\n * Extract the sandbox type from a provider\n */\ntype ExtractProviderSandboxType<TProvider extends Provider> = TProvider extends { readonly __sandboxType: infer TSandbox } ? TSandbox : any;\n\n/**\n * Typed sandbox interface that preserves the provider's native instance type\n */\nexport interface TypedSandbox<TProvider extends Provider> extends Omit<Sandbox<ExtractProviderSandboxType<TProvider>>, 'getProvider'> {\n /** Get the provider instance that created this sandbox with proper typing */\n getProvider(): TProvider;\n /** Get the native provider sandbox instance with proper typing */\n getInstance(): ExtractProviderSandboxType<TProvider>;\n}","/**\n * Compute Singleton - Main API Orchestrator\n *\n * Provides the unified compute.* API and delegates to specialized managers\n */\n\nimport { ComputeClient } from '@computesdk/client';\nimport type { ComputeAPI, CreateSandboxParams, CreateSandboxParamsWithOptionalProvider, ComputeConfig, Sandbox, Provider, TypedSandbox, TypedComputeAPI } from './types';\n\n/**\n * Authorization response from license server\n */\ninterface AuthorizationResponse {\n jwt: string;\n sandbox_url: string;\n preview_url: string;\n}\n\n/**\n * Authorize license key and get JWT token + URLs from license server\n */\nasync function authorizeApiKey(apiKey: string): Promise<AuthorizationResponse> {\n try {\n const response = await fetch('https://preview.computesdk.com/__api/license/authorize', {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({\n key: apiKey,\n increment_usage: 1\n })\n });\n\n if (!response.ok) {\n throw new Error(`License authorization failed: ${response.statusText}`);\n }\n\n const data = await response.json();\n\n if (!data.jwt) {\n throw new Error('No JWT token received from license server');\n }\n\n if (!data.sandbox_url) {\n throw new Error('No sandbox_url received from license server');\n }\n\n if (!data.preview_url) {\n throw new Error('No preview_url received from license server');\n }\n\n return {\n jwt: data.jwt,\n sandbox_url: data.sandbox_url,\n preview_url: data.preview_url\n };\n } catch (error) {\n throw new Error(`Failed to authorize API key: ${error}`);\n }\n}\n\n/**\n * Install and start compute CLI inside a sandbox\n */\nasync function installComputeInSandbox(\n sandbox: Sandbox,\n config?: { apiKey?: string; jwt?: string }\n): Promise<AuthorizationResponse | null> {\n try {\n console.log('Installing and starting compute CLI in sandbox...');\n\n // Get JWT token and URLs from API key if provided\n let authResponse: AuthorizationResponse | null = null;\n let jwt = config?.jwt;\n\n if (config?.apiKey && !jwt) {\n console.log('Authorizing API key and getting JWT token...');\n authResponse = await authorizeApiKey(config.apiKey);\n jwt = authResponse.jwt;\n }\n\n // Build install command with authentication\n let installCommand = 'curl -fsSL https://computesdk.com/install.sh | sh';\n\n if (jwt) {\n installCommand = `curl -fsSL https://computesdk.com/install.sh | sh -s -- --jwt ${jwt}`;\n }\n\n // Run the install script (it will handle installation and starting compute)\n const result = await sandbox.runCommand('sh', ['-c', installCommand]);\n\n if (result.exitCode !== 0) {\n throw new Error(`Failed to install and start compute CLI: ${result.stderr}`);\n }\n\n console.log('Compute CLI installed and started successfully');\n\n return authResponse;\n } catch (error) {\n throw new Error(`Failed to install compute CLI in sandbox: ${error}`);\n }\n}\n\n/**\n * Compute singleton implementation - orchestrates all compute operations\n */\nclass ComputeManager implements ComputeAPI {\n private config: ComputeConfig | null = null;\n private typedState: {\n isTyped: boolean;\n provider: Provider | null;\n } = { isTyped: false, provider: null };\n private computeAuth: { apiKey?: string; jwt?: string } = {};\n\n /**\n * Set default configuration with generic type preservation\n */\n setConfig<TProvider extends Provider>(config: ComputeConfig<TProvider>): void {\n // Validate that at least one provider is specified\n if (!config.defaultProvider && !config.provider) {\n throw new Error('Either defaultProvider or provider must be specified in setConfig');\n }\n\n // Handle backwards compatibility: if both are provided, defaultProvider takes precedence\n if (config.defaultProvider && config.provider) {\n console.warn('Both defaultProvider and provider specified in setConfig. Using defaultProvider. The provider key is deprecated, please use defaultProvider instead.');\n }\n\n // Normalize config to always have both fields for internal use (backward compatibility)\n const actualProvider = config.defaultProvider || config.provider!;\n this.config = {\n provider: actualProvider,\n defaultProvider: actualProvider,\n apiKey: config.apiKey,\n jwt: config.jwt\n };\n\n // Store compute auth credentials\n this.computeAuth = {\n apiKey: config.apiKey,\n jwt: config.jwt\n };\n\n // Store typed state for type-aware operations\n this.typedState = {\n isTyped: true,\n provider: actualProvider\n };\n }\n\n /**\n * Get current configuration\n */\n getConfig(): ComputeConfig | null {\n return this.config;\n }\n\n /**\n * Clear current configuration\n */\n clearConfig(): void {\n this.config = null;\n }\n\n /**\n * Get the default provider, throwing if not configured\n */\n private getDefaultProvider(): Provider {\n const provider = this.config?.defaultProvider || this.config?.provider;\n if (!provider) {\n throw new Error(\n 'No default provider configured. Either call compute.setConfig({ defaultProvider }) or pass provider explicitly.'\n );\n }\n return provider;\n }\n\n sandbox = {\n /**\n * Create a sandbox from a provider (or default provider if configured)\n * \n * @example\n * ```typescript\n * import { e2b } from '@computesdk/e2b'\n * import { compute } from 'computesdk'\n * \n * // With explicit provider\n * const sandbox = await compute.sandbox.create({\n * provider: e2b({ apiKey: 'your-key' })\n * })\n * \n * // With default provider (both forms work)\n * compute.setConfig({ defaultProvider: e2b({ apiKey: 'your-key' }) })\n * const sandbox1 = await compute.sandbox.create({})\n * const sandbox2 = await compute.sandbox.create()\n * ```\n */\n create: async (params?: CreateSandboxParams | CreateSandboxParamsWithOptionalProvider): Promise<Sandbox> => {\n const provider = params && 'provider' in params && params.provider ? params.provider : this.getDefaultProvider();\n const options = params?.options;\n const sandbox = await provider.sandbox.create(options);\n\n // Install compute CLI in the sandbox with auth credentials if available\n const authResponse = await installComputeInSandbox(sandbox, this.computeAuth);\n\n // If we have authorization info, use ComputeClient instead of provider sandbox\n let finalSandbox: Sandbox = sandbox;\n if (authResponse) {\n finalSandbox = new ComputeClient({\n sandboxUrl: authResponse.sandbox_url,\n sandboxId: sandbox.sandboxId,\n provider: sandbox.provider,\n token: authResponse.jwt\n }) as Sandbox;\n }\n\n // If we have typed state and no explicit provider passed, cast to typed sandbox\n // This enables proper type inference for getInstance() when using default provider\n if (this.typedState.isTyped && (!params || !('provider' in params && params.provider))) {\n return finalSandbox as TypedSandbox<any>;\n }\n\n return finalSandbox;\n },\n\n /**\n * Get an existing sandbox by ID from a provider (or default provider if configured)\n */\n getById: async (providerOrSandboxId: Provider | string, sandboxId?: string): Promise<Sandbox | null> => {\n if (typeof providerOrSandboxId === 'string') {\n // Called with just sandboxId, use default provider\n const provider = this.getDefaultProvider();\n const sandbox = await provider.sandbox.getById(providerOrSandboxId);\n \n // If we have typed state, cast to typed sandbox for proper getInstance() typing\n if (this.typedState.isTyped && sandbox) {\n return sandbox as TypedSandbox<any>;\n }\n \n return sandbox;\n } else {\n // Called with provider and sandboxId\n if (!sandboxId) {\n throw new Error('sandboxId is required when provider is specified');\n }\n return await providerOrSandboxId.sandbox.getById(sandboxId);\n }\n },\n\n /**\n * List all active sandboxes from a provider (or default provider if configured)\n */\n list: async (provider?: Provider): Promise<Sandbox[]> => {\n const actualProvider = provider || this.getDefaultProvider();\n const sandboxes = await actualProvider.sandbox.list();\n \n // If we have typed state and no explicit provider passed, cast to typed sandboxes\n if (this.typedState.isTyped && !provider) {\n return sandboxes as TypedSandbox<any>[];\n }\n \n return sandboxes;\n },\n\n /**\n * Destroy a sandbox via a provider (or default provider if configured)\n */\n destroy: async (providerOrSandboxId: Provider | string, sandboxId?: string): Promise<void> => {\n if (typeof providerOrSandboxId === 'string') {\n // Called with just sandboxId, use default provider\n const provider = this.getDefaultProvider();\n return await provider.sandbox.destroy(providerOrSandboxId);\n } else {\n // Called with provider and sandboxId\n if (!sandboxId) {\n throw new Error('sandboxId is required when provider is specified');\n }\n return await providerOrSandboxId.sandbox.destroy(sandboxId);\n }\n }\n };\n\n // Future: compute.blob.*, compute.database.*, compute.git.* will be added here\n // blob = new BlobManager();\n // database = new DatabaseManager(); \n // git = new GitManager();\n\n\n}\n\n/**\n * Singleton instance - the main API (untyped)\n */\nexport const compute: ComputeAPI = new ComputeManager();\n\n\n\n/**\n * Create a compute instance with proper typing\n * \n * @example\n * ```typescript\n * import { e2b } from '@computesdk/e2b'\n * import { createCompute } from 'computesdk'\n * \n * const compute = createCompute({\n * defaultProvider: e2b({ apiKey: 'your-key' }),\n * });\n * \n * const sandbox = await compute.sandbox.create();\n * const instance = sandbox.getInstance(); // ✅ Properly typed E2B Sandbox!\n * ```\n */\nexport function createCompute<TProvider extends Provider>(config: ComputeConfig<TProvider>): TypedComputeAPI<TProvider> {\n const manager = new ComputeManager();\n\n // Set config directly without calling the public setConfig method\n const actualProvider = config.defaultProvider || config.provider!;\n manager['config'] = {\n provider: actualProvider,\n defaultProvider: actualProvider,\n apiKey: config.apiKey,\n jwt: config.jwt\n };\n manager['typedState'] = {\n isTyped: true,\n provider: actualProvider\n };\n manager['computeAuth'] = {\n apiKey: config.apiKey,\n jwt: config.jwt\n };\n\n return {\n setConfig: <T extends Provider>(cfg: ComputeConfig<T>) => createCompute(cfg),\n getConfig: () => manager.getConfig(),\n clearConfig: () => manager.clearConfig(),\n\n sandbox: {\n create: async (params?: Omit<CreateSandboxParamsWithOptionalProvider, 'provider'>) => {\n const sandbox = await manager.sandbox.create(params);\n // The sandbox should now have the correct getInstance typing from the generic Sandbox<TSandbox>\n return sandbox as TypedSandbox<TProvider>;\n },\n\n getById: async (sandboxId: string) => {\n const sandbox = await manager.sandbox.getById(sandboxId);\n return sandbox ? sandbox as TypedSandbox<TProvider> : null;\n },\n\n list: async () => {\n const sandboxes = await manager.sandbox.list();\n return sandboxes as TypedSandbox<TProvider>[];\n },\n\n destroy: async (sandboxId: string) => {\n return await manager.sandbox.destroy(sandboxId);\n }\n }\n } as TypedComputeAPI<TProvider>;\n}\n\n\n\n","/**\n * Simplified Request Handler for Web Framework Integration\n * \n * Handles JSON requests for sandbox and code execution operations.\n * Terminal support removed - will be re-added with WebSocket VM connections.\n */\n\nimport type { Provider, Runtime } from './types';\nimport { compute } from './compute';\n\n/**\n * Request structure supporting sandbox and code execution capabilities\n */\nexport interface ComputeRequest {\n /** Action in dot notation (e.g., 'compute.sandbox.create') */\n action: string;\n \n /** Parameters for the action */\n sandboxId?: string;\n code?: string;\n command?: string;\n args?: string[];\n runtime?: Runtime;\n path?: string;\n content?: string;\n \n /** Command options (for runCommand action) */\n commandOptions?: {\n background?: boolean;\n };\n \n /** Sandbox creation options */\n options?: {\n runtime?: Runtime;\n timeout?: number;\n sandboxId?: string;\n };\n}\n\n/**\n * Response structure for compute operations\n */\nexport interface ComputeResponse {\n success: boolean;\n error?: string;\n sandboxId: string;\n provider: string;\n [key: string]: any; // Allow any additional response data\n}\n\n/**\n * Execute compute action using targeted handling\n */\nasync function executeAction(body: ComputeRequest, provider: Provider): Promise<ComputeResponse> {\n try {\n const { action, sandboxId } = body;\n \n // Sandbox management operations\n if (action === 'compute.sandbox.create') {\n const sandbox = await compute.sandbox.create({\n provider,\n options: body.options || { runtime: 'python' }\n });\n return {\n success: true,\n sandboxId: sandbox.sandboxId,\n provider: provider.name\n };\n }\n \n if (action === 'compute.sandbox.list') {\n const sandboxes = await compute.sandbox.list(provider);\n return {\n success: true,\n sandboxId: '',\n provider: provider.name,\n sandboxes: sandboxes.map(sb => ({\n sandboxId: sb.sandboxId,\n provider: sb.provider\n }))\n };\n }\n \n if (action === 'compute.sandbox.destroy') {\n if (!sandboxId) {\n throw new Error('sandboxId is required for destroy action');\n }\n await compute.sandbox.destroy(provider, sandboxId);\n return {\n success: true,\n sandboxId,\n provider: provider.name\n };\n }\n \n // For sandbox instance methods, get the sandbox first\n if (!sandboxId) {\n throw new Error('sandboxId is required for this action');\n }\n \n const sandbox = await compute.sandbox.getById(provider, sandboxId);\n if (!sandbox) {\n throw new Error(`Sandbox ${sandboxId} not found`);\n }\n \n // Sandbox info\n if (action === 'compute.sandbox.getInfo') {\n const result = await sandbox.getInfo();\n return {\n success: true,\n sandboxId,\n provider: provider.name,\n info: {\n id: result.id,\n provider: result.provider,\n runtime: result.runtime,\n status: result.status,\n createdAt: result.createdAt.toISOString(),\n timeout: result.timeout,\n metadata: result.metadata\n }\n };\n }\n \n // Code execution\n if (action === 'compute.sandbox.runCode') {\n if (!body.code) throw new Error('code is required');\n const result = await sandbox.runCode(body.code, body.runtime);\n return {\n success: true,\n sandboxId,\n provider: provider.name,\n result: {\n stdout: result.stdout,\n stderr: result.stderr,\n exitCode: result.exitCode,\n executionTime: result.executionTime\n }\n };\n }\n \n if (action === 'compute.sandbox.runCommand') {\n if (!body.command) throw new Error('command is required');\n const result = await sandbox.runCommand(body.command, body.args, body.commandOptions);\n return {\n success: true,\n sandboxId,\n provider: provider.name,\n result: {\n stdout: result.stdout,\n stderr: result.stderr,\n exitCode: result.exitCode,\n executionTime: result.executionTime,\n ...(result.isBackground && { isBackground: result.isBackground }),\n ...(result.pid && { pid: result.pid })\n }\n };\n }\n \n // Filesystem operations\n if (action === 'compute.sandbox.filesystem.readFile') {\n if (!body.path) throw new Error('path is required');\n const result = await sandbox.filesystem.readFile(body.path);\n return {\n success: true,\n sandboxId,\n provider: provider.name,\n fileContent: result\n };\n }\n \n if (action === 'compute.sandbox.filesystem.writeFile') {\n if (!body.path) throw new Error('path is required');\n if (body.content === undefined) throw new Error('content is required');\n await sandbox.filesystem.writeFile(body.path, body.content);\n return { success: true, sandboxId, provider: provider.name };\n }\n \n if (action === 'compute.sandbox.filesystem.mkdir') {\n if (!body.path) throw new Error('path is required');\n await sandbox.filesystem.mkdir(body.path);\n return { success: true, sandboxId, provider: provider.name };\n }\n \n if (action === 'compute.sandbox.filesystem.readdir') {\n if (!body.path) throw new Error('path is required');\n const result = await sandbox.filesystem.readdir(body.path);\n return {\n success: true,\n sandboxId,\n provider: provider.name,\n files: result.map((entry: any) => ({\n name: entry.name,\n path: entry.path,\n isDirectory: entry.isDirectory,\n size: entry.size,\n lastModified: entry.lastModified.toISOString()\n }))\n };\n }\n \n if (action === 'compute.sandbox.filesystem.exists') {\n if (!body.path) throw new Error('path is required');\n const result = await sandbox.filesystem.exists(body.path);\n return {\n success: true,\n sandboxId,\n provider: provider.name,\n exists: result\n };\n }\n \n if (action === 'compute.sandbox.filesystem.remove') {\n if (!body.path) throw new Error('path is required');\n await sandbox.filesystem.remove(body.path);\n return { success: true, sandboxId, provider: provider.name };\n }\n \n throw new Error(`Unknown action: ${action}`);\n \n } catch (error) {\n return {\n success: false,\n error: error instanceof Error ? error.message : 'Unknown error occurred',\n sandboxId: body.sandboxId || '',\n provider: provider.name\n };\n }\n}\n\n/**\n * Main request handler - handles HTTP requests and pre-parsed bodies\n */\nexport async function handleComputeRequest(\n params: HandleComputeRequestParams\n): Promise<ComputeResponse>;\nexport async function handleComputeRequest(\n requestOrBody: Request | ComputeRequest,\n provider: Provider\n): Promise<Response>;\nexport async function handleComputeRequest(\n paramsOrRequestOrBody: HandleComputeRequestParams | Request | ComputeRequest,\n provider?: Provider\n): Promise<ComputeResponse | Response> {\n // Handle object-style API\n if (typeof paramsOrRequestOrBody === 'object' && 'request' in paramsOrRequestOrBody && 'provider' in paramsOrRequestOrBody) {\n const params = paramsOrRequestOrBody as HandleComputeRequestParams;\n return await executeAction(params.request, params.provider);\n }\n \n // Handle original API\n if (!provider) {\n throw new Error('Provider is required when not using object-style API');\n }\n \n const requestOrBody = paramsOrRequestOrBody as Request | ComputeRequest;\n try {\n let body: ComputeRequest;\n \n if (requestOrBody instanceof Request) {\n // Handle HTTP method validation\n if (requestOrBody.method !== 'POST') {\n return Response.json({\n success: false,\n error: 'Only POST requests are supported',\n sandboxId: '',\n provider: provider.name\n }, { status: 405 });\n }\n \n // Parse JSON body with better error handling\n try {\n body = await requestOrBody.json();\n } catch (parseError) {\n return Response.json({\n success: false,\n error: 'Invalid JSON in request body',\n sandboxId: '',\n provider: provider.name\n }, { status: 400 });\n }\n } else {\n body = requestOrBody;\n }\n \n // Execute the action\n const result = await executeAction(body, provider);\n \n return Response.json(result, {\n status: result.success ? 200 : 500\n });\n \n } catch (error) {\n return Response.json({\n success: false,\n error: error instanceof Error ? error.message : 'Request handling failed',\n sandboxId: '',\n provider: provider.name\n }, { status: 500 });\n }\n}\n\n/**\n * Legacy export for backward compatibility\n */\nexport interface HandleComputeRequestParams {\n request: ComputeRequest;\n provider: Provider;\n}\n\nexport { handleComputeRequest as handleHttpComputeRequest };","/**\n * Provider Factory - Creates providers from method definitions\n * \n * Eliminates boilerplate by auto-generating Provider/Sandbox classes\n * from simple method definitions with automatic feature detection.\n */\n\nimport type {\n Provider,\n ProviderSandboxManager,\n ProviderTemplateManager,\n ProviderSnapshotManager,\n Sandbox,\n SandboxFileSystem,\n SandboxInfo,\n ExecutionResult,\n Runtime,\n CreateSandboxOptions,\n FileEntry,\n RunCommandOptions,\n CreateSnapshotOptions,\n ListSnapshotsOptions,\n CreateTemplateOptions,\n ListTemplatesOptions,\n} from './types/index.js';\n\n/**\n * Helper function to handle background command execution\n * Providers can use this to implement background job support\n */\nexport function createBackgroundCommand(command: string, args: string[] = [], options?: RunCommandOptions): { command: string; args: string[]; isBackground: boolean } {\n if (!options?.background) {\n return { command, args, isBackground: false };\n }\n\n // For background execution, we modify the command to run in background\n // Default approach: append & to make it run in background\n const fullCommand = args.length > 0 ? `${command} ${args.join(' ')}` : command;\n \n return {\n command: 'sh',\n args: ['-c', `${fullCommand} &`],\n isBackground: true\n };\n}\n\n/**\n * Flat sandbox method implementations - all operations in one place\n */\nexport interface SandboxMethods<TSandbox = any, TConfig = any> {\n // Collection operations (map to compute.sandbox.*)\n create: (config: TConfig, options?: CreateSandboxOptions) => Promise<{ sandbox: TSandbox; sandboxId: string }>;\n getById: (config: TConfig, sandboxId: string) => Promise<{ sandbox: TSandbox; sandboxId: string } | null>;\n list: (config: TConfig) => Promise<Array<{ sandbox: TSandbox; sandboxId: string }>>;\n destroy: (config: TConfig, sandboxId: string) => Promise<void>;\n \n // Instance operations (map to individual Sandbox methods)\n runCode: (sandbox: TSandbox, code: string, runtime?: Runtime, config?: TConfig) => Promise<ExecutionResult>;\n runCommand: (sandbox: TSandbox, command: string, args?: string[], options?: RunCommandOptions) => Promise<ExecutionResult>;\n getInfo: (sandbox: TSandbox) => Promise<SandboxInfo>;\n getUrl: (sandbox: TSandbox, options: { port: number; protocol?: string }) => Promise<string>;\n \n // Optional provider-specific typed getInstance method\n getInstance?: (sandbox: TSandbox) => TSandbox;\n \n // Optional filesystem methods\n filesystem?: {\n readFile: (sandbox: TSandbox, path: string, runCommand: (sandbox: TSandbox, command: string, args?: string[]) => Promise<ExecutionResult>) => Promise<string>;\n writeFile: (sandbox: TSandbox, path: string, content: string, runCommand: (sandbox: TSandbox, command: string, args?: string[]) => Promise<ExecutionResult>) => Promise<void>;\n mkdir: (sandbox: TSandbox, path: string, runCommand: (sandbox: TSandbox, command: string, args?: string[]) => Promise<ExecutionResult>) => Promise<void>;\n readdir: (sandbox: TSandbox, path: string, runCommand: (sandbox: TSandbox, command: string, args?: string[]) => Promise<ExecutionResult>) => Promise<FileEntry[]>;\n exists: (sandbox: TSandbox, path: string, runCommand: (sandbox: TSandbox, command: string, args?: string[]) => Promise<ExecutionResult>) => Promise<boolean>;\n remove: (sandbox: TSandbox, path: string, runCommand: (sandbox: TSandbox, command: string, args?: string[]) => Promise<ExecutionResult>) => Promise<void>;\n };\n}\n\n/**\n * Template method implementations\n */\nexport interface TemplateMethods<TTemplate = any, TConfig = any> {\n create: (config: TConfig, options: CreateTemplateOptions | any) => Promise<TTemplate>;\n list: (config: TConfig, options?: ListTemplatesOptions) => Promise<TTemplate[]>;\n delete: (config: TConfig, templateId: string) => Promise<void>;\n}\n\n/**\n * Snapshot method implementations \n */\nexport interface SnapshotMethods<TSnapshot = any, TConfig = any> {\n create: (config: TConfig, sandboxId: string, options?: CreateSnapshotOptions) => Promise<TSnapshot>;\n list: (config: TConfig, options?: ListSnapshotsOptions) => Promise<TSnapshot[]>;\n delete: (config: TConfig, snapshotId: string) => Promise<void>;\n}\n\n/**\n * Provider configuration for createProvider()\n */\nexport interface ProviderConfig<TSandbox = any, TConfig = any, TTemplate = any, TSnapshot = any> {\n name: string;\n methods: {\n sandbox: SandboxMethods<TSandbox, TConfig>;\n template?: TemplateMethods<TTemplate, TConfig>;\n snapshot?: SnapshotMethods<TSnapshot, TConfig>;\n };\n}\n\n/**\n * Default filesystem implementations based on shell commands\n * These work for any provider that supports shell command execution\n */\nconst defaultFilesystemMethods = {\n readFile: async (sandbox: any, path: string, runCommand: (sandbox: any, command: string, args?: string[]) => Promise<ExecutionResult>): Promise<string> => {\n const result = await runCommand(sandbox, 'cat', [path]);\n if (result.exitCode !== 0) {\n throw new Error(`Failed to read file ${path}: ${result.stderr}`);\n }\n // Trim trailing newline that cat command adds\n return result.stdout.replace(/\\n$/, '');\n },\n\n writeFile: async (sandbox: any, path: string, content: string, runCommand: (sandbox: any, command: string, args?: string[]) => Promise<ExecutionResult>): Promise<void> => {\n const result = await runCommand(sandbox, 'sh', ['-c', `echo ${JSON.stringify(content)} > ${JSON.stringify(path)}`]);\n if (result.exitCode !== 0) {\n throw new Error(`Failed to write file ${path}: ${result.stderr}`);\n }\n },\n\n mkdir: async (sandbox: any, path: string, runCommand: (sandbox: any, command: string, args?: string[]) => Promise<ExecutionResult>): Promise<void> => {\n const result = await runCommand(sandbox, 'mkdir', ['-p', path]);\n if (result.exitCode !== 0) {\n throw new Error(`Failed to create directory ${path}: ${result.stderr}`);\n }\n },\n\n readdir: async (sandbox: any, path: string, runCommand: (sandbox: any, command: string, args?: string[]) => Promise<ExecutionResult>): Promise<FileEntry[]> => {\n // Try different ls variations for maximum compatibility\n let result = await runCommand(sandbox, 'ls', ['-la', path]);\n let hasDetailedOutput = true;\n \n // Fall back to basic ls if detailed flags not supported\n if (result.exitCode !== 0) {\n result = await runCommand(sandbox, 'ls', ['-l', path]);\n }\n if (result.exitCode !== 0) {\n result = await runCommand(sandbox, 'ls', [path]);\n hasDetailedOutput = false;\n }\n \n if (result.exitCode !== 0) {\n throw new Error(`Failed to list directory ${path}: ${result.stderr}`);\n }\n\n const lines = (result.stdout || '').split('\\n').filter((line: string) => line.trim() && !line.startsWith('total'));\n\n return lines.map((line: string) => {\n if (hasDetailedOutput && line.includes(' ')) {\n // Parse detailed ls output (ls -la or ls -l)\n const parts = line.trim().split(/\\s+/);\n const name = parts[parts.length - 1];\n const isDirectory = line.startsWith('d');\n \n return {\n name,\n path: `${path}/${name}`,\n isDirectory,\n size: parseInt(parts[4]) || 0,\n lastModified: new Date()\n };\n } else {\n // Parse simple ls output (just filenames)\n const name = line.trim();\n return {\n name,\n path: `${path}/${name}`,\n isDirectory: false, // Can't determine from simple ls\n size: 0,\n lastModified: new Date()\n };\n }\n });\n },\n\n exists: async (sandbox: any, path: string, runCommand: (sandbox: any, command: string, args?: string[]) => Promise<ExecutionResult>): Promise<boolean> => {\n const result = await runCommand(sandbox, 'test', ['-e', path]);\n return result.exitCode === 0; // Exit code 0 means file exists\n },\n\n remove: async (sandbox: any, path: string, runCommand: (sandbox: any, command: string, args?: string[]) => Promise<ExecutionResult>): Promise<void> => {\n const result = await runCommand(sandbox, 'rm', ['-rf', path]);\n if (result.exitCode !== 0) {\n throw new Error(`Failed to remove ${path}: ${result.stderr}`);\n }\n }\n};\n\n/**\n * Auto-generated filesystem implementation that throws \"not supported\" errors\n */\nclass UnsupportedFileSystem implements SandboxFileSystem {\n private readonly providerName: string;\n\n constructor(providerName: string) {\n this.providerName = providerName;\n }\n\n async readFile(_path: string): Promise<string> {\n throw new Error(`Filesystem operations are not supported by ${this.providerName}'s sandbox environment. ${this.providerName} sandboxes are designed for code execution only.`);\n }\n\n async writeFile(_path: string, _content: string): Promise<void> {\n throw new Error(`Filesystem operations are not supported by ${this.providerName}'s sandbox environment. ${this.providerName} sandboxes are designed for code execution only.`);\n }\n\n async mkdir(_path: string): Promise<void> {\n throw new Error(`Filesystem operations are not supported by ${this.providerName}'s sandbox environment. ${this.providerName} sandboxes are designed for code execution only.`);\n }\n\n async readdir(_path: string): Promise<FileEntry[]> {\n throw new Error(`Filesystem operations are not supported by ${this.providerName}'s sandbox environment. ${this.providerName} sandboxes are designed for code execution only.`);\n }\n\n async exists(_path: string): Promise<boolean> {\n throw new Error(`Filesystem operations are not supported by ${this.providerName}'s sandbox environment. ${this.providerName} sandboxes are designed for code execution only.`);\n }\n\n async remove(_path: string): Promise<void> {\n throw new Error(`Filesystem operations are not supported by ${this.providerName}'s sandbox environment. ${this.providerName} sandboxes are designed for code execution only.`);\n }\n}\n\n\n\n/**\n * Auto-generated filesystem implementation that wraps provider methods\n */\nclass SupportedFileSystem<TSandbox> implements SandboxFileSystem {\n constructor(\n private sandbox: TSandbox,\n private methods: NonNullable<SandboxMethods<TSandbox>['filesystem']>,\n private allMethods: SandboxMethods<TSandbox>\n ) {}\n\n async readFile(path: string): Promise<string> {\n return this.methods.readFile(this.sandbox, path, this.allMethods.runCommand);\n }\n\n async writeFile(path: string, content: string): Promise<void> {\n return this.methods.writeFile(this.sandbox, path, content, this.allMethods.runCommand);\n }\n\n async mkdir(path: string): Promise<void> {\n return this.methods.mkdir(this.sandbox, path, this.allMethods.runCommand);\n }\n\n async readdir(path: string): Promise<FileEntry[]> {\n return this.methods.readdir(this.sandbox, path, this.allMethods.runCommand);\n }\n\n async exists(path: string): Promise<boolean> {\n return this.methods.exists(this.sandbox, path, this.allMethods.runCommand);\n }\n\n async remove(path: string): Promise<void> {\n return this.methods.remove(this.sandbox, path, this.allMethods.runCommand);\n }\n}\n\n\n\n\n\n/**\n * Generated sandbox class - implements the Sandbox interface\n */\nclass GeneratedSandbox<TSandbox = any> implements Sandbox<TSandbox> {\n readonly sandboxId: string;\n readonly provider: string;\n readonly filesystem: SandboxFileSystem;\n\n constructor(\n private sandbox: TSandbox,\n sandboxId: string,\n providerName: string,\n private methods: SandboxMethods<TSandbox>,\n private config: any,\n private destroyMethod: (config: any, sandboxId: string) => Promise<void>,\n private providerInstance: Provider\n ) {\n this.sandboxId = sandboxId;\n this.provider = providerName;\n\n // Auto-detect filesystem support\n if (methods.filesystem) {\n this.filesystem = new SupportedFileSystem(sandbox, methods.filesystem, methods);\n } else {\n this.filesystem = new UnsupportedFileSystem(providerName);\n }\n }\n\n getInstance(): TSandbox {\n // Use provider-specific typed getInstance if available\n if (this.methods.getInstance) {\n return this.methods.getInstance(this.sandbox);\n }\n // Fallback to returning the sandbox directly\n return this.sandbox;\n }\n\n async runCode(code: string, runtime?: Runtime): Promise<ExecutionResult> {\n return await this.methods.runCode(this.sandbox, code, runtime, this.config);\n }\n\n async runCommand(command: string, args?: string[], options?: RunCommandOptions): Promise<ExecutionResult> {\n return await this.methods.runCommand(this.sandbox, command, args, options);\n }\n\n async getInfo(): Promise<SandboxInfo> {\n return await this.methods.getInfo(this.sandbox);\n }\n\n async getUrl(options: { port: number; protocol?: string }): Promise<string> {\n return await this.methods.getUrl(this.sandbox, options);\n }\n\n getProvider(): Provider<TSandbox> {\n return this.providerInstance;\n }\n\n async kill(): Promise<void> {\n // For backward compatibility, kill() delegates to destroy()\n await this.destroy();\n }\n\n async destroy(): Promise<void> {\n // Destroy via the provider's destroy method using our sandboxId\n await this.destroyMethod(this.config, this.sandboxId);\n }\n}\n\n/**\n * Auto-generated Sandbox Manager implementation\n */\nclass GeneratedSandboxManager<TSandbox, TConfig> implements ProviderSandboxManager<TSandbox> {\n private activeSandboxes: Map<string, GeneratedSandbox<TSandbox>> = new Map();\n\n constructor(\n private config: TConfig,\n private providerName: string,\n private methods: SandboxMethods<TSandbox, TConfig>,\n private providerInstance: Provider\n ) {}\n\n async create(options?: CreateSandboxOptions): Promise<Sandbox<TSandbox>> {\n // Default to 'node' runtime if not specified for consistency across providers\n const optionsWithDefaults = { runtime: 'node' as Runtime, ...options };\n const result = await this.methods.create(this.config, optionsWithDefaults);\n const sandbox = new GeneratedSandbox<TSandbox>(\n result.sandbox,\n result.sandboxId,\n this.providerName,\n this.methods,\n this.config,\n this.methods.destroy,\n this.providerInstance\n );\n \n this.activeSandboxes.set(result.sandboxId, sandbox);\n return sandbox;\n }\n\n async getById(sandboxId: string): Promise<Sandbox<TSandbox> | null> {\n // Check active sandboxes first\n const existing = this.activeSandboxes.get(sandboxId);\n if (existing) {\n return existing;\n }\n\n // Try to reconnect\n const result = await this.methods.getById(this.config, sandboxId);\n if (!result) {\n return null;\n }\n\n const sandbox = new GeneratedSandbox<TSandbox>(\n result.sandbox,\n result.sandboxId,\n this.providerName,\n this.methods,\n this.config,\n this.methods.destroy,\n this.providerInstance\n );\n \n this.activeSandboxes.set(result.sandboxId, sandbox);\n return sandbox;\n }\n\n async list(): Promise<Sandbox<TSandbox>[]> {\n const results = await this.methods.list(this.config);\n const sandboxes: Sandbox[] = [];\n\n for (const result of results) {\n let sandbox = this.activeSandboxes.get(result.sandboxId);\n if (!sandbox) {\n sandbox = new GeneratedSandbox<TSandbox>(\n result.sandbox,\n result.sandboxId,\n this.providerName,\n this.methods,\n this.config,\n this.methods.destroy,\n this.providerInstance\n );\n this.activeSandboxes.set(result.sandboxId, sandbox);\n }\n sandboxes.push(sandbox);\n }\n\n return sandboxes;\n }\n\n async destroy(sandboxId: string): Promise<void> {\n await this.methods.destroy(this.config, sandboxId);\n this.activeSandboxes.delete(sandboxId);\n }\n}\n\n/**\n * Auto-generated Template Manager implementation\n */\nclass GeneratedTemplateManager<TTemplate, TConfig> implements ProviderTemplateManager<TTemplate> {\n constructor(\n private config: TConfig,\n private methods: TemplateMethods<TTemplate, TConfig>\n ) {}\n\n async create(options: CreateTemplateOptions | any): Promise<TTemplate> {\n return await this.methods.create(this.config, options);\n }\n\n async list(options?: ListTemplatesOptions): Promise<TTemplate[]> {\n return await this.methods.list(this.config, options);\n }\n\n async delete(templateId: string): Promise<void> {\n return await this.methods.delete(this.config, templateId);\n }\n}\n\n/**\n * Auto-generated Snapshot Manager implementation\n */\nclass GeneratedSnapshotManager<TSnapshot, TConfig> implements ProviderSnapshotManager<TSnapshot> {\n constructor(\n private config: TConfig,\n private methods: SnapshotMethods<TSnapshot, TConfig>\n ) {}\n\n async create(sandboxId: string, options?: CreateSnapshotOptions): Promise<TSnapshot> {\n return await this.methods.create(this.config, sandboxId, options);\n }\n\n async list(options?: ListSnapshotsOptions): Promise<TSnapshot[]> {\n return await this.methods.list(this.config, options);\n }\n\n async delete(snapshotId: string): Promise<void> {\n return await this.methods.delete(this.config, snapshotId);\n }\n}\n\n/**\n * Auto-generated Provider implementation\n */\nclass GeneratedProvider<TSandbox, TConfig, TTemplate, TSnapshot> implements Provider<TSandbox, TTemplate, TSnapshot> {\n readonly name: string;\n readonly sandbox: ProviderSandboxManager<TSandbox>;\n readonly template?: ProviderTemplateManager<TTemplate>;\n readonly snapshot?: ProviderSnapshotManager<TSnapshot>;\n readonly __sandboxType!: TSandbox; // Phantom type for TypeScript inference\n\n constructor(config: TConfig, providerConfig: ProviderConfig<TSandbox, TConfig, TTemplate, TSnapshot>) {\n this.name = providerConfig.name;\n this.sandbox = new GeneratedSandboxManager(\n config,\n providerConfig.name,\n providerConfig.methods.sandbox,\n this\n );\n\n // Initialize optional managers if methods are provided\n if (providerConfig.methods.template) {\n this.template = new GeneratedTemplateManager(config, providerConfig.methods.template);\n }\n \n if (providerConfig.methods.snapshot) {\n this.snapshot = new GeneratedSnapshotManager(config, providerConfig.methods.snapshot);\n }\n }\n\n getSupportedRuntimes(): Runtime[] {\n // For now, all providers support both node and python\n // In the future, this could be configurable per provider\n return ['node', 'python'];\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 = any, TTemplate = any, TSnapshot = any>(\n providerConfig: ProviderConfig<TSandbox, TConfig, TTemplate, TSnapshot>\n): (config: TConfig) => Provider<TSandbox, TTemplate, TSnapshot> {\n // Auto-inject default filesystem methods if none provided\n if (!providerConfig.methods.sandbox.filesystem) {\n providerConfig.methods.sandbox.filesystem = defaultFilesystemMethods;\n }\n\n return (config: TConfig) => {\n return new GeneratedProvider(config, providerConfig);\n };\n}"],"mappings":";AAwJO,IAAM,mBAAN,cAA+B,MAAM;AAAA,EAE1C,YAAmB,QAKhB;AACD,UAAM,4BAA4B,OAAO,QAAQ,EAAE;AANlC;AADnB,gBAAO;AAAA,EAQP;AACF;AAKO,SAAS,mBAAmB,OAA2C;AAC5E,SACE,OAAO,UAAU,YACjB,UAAU,QACV,UAAU,SACV,MAAM,SAAS,sBACf,YAAY;AAEhB;;;ACzKA,SAAS,qBAAqB;AAe9B,eAAe,gBAAgB,QAAgD;AAC7E,MAAI;AACF,UAAM,WAAW,MAAM,MAAM,0DAA0D;AAAA,MACrF,QAAQ;AAAA,MACR,SAAS;AAAA,QACP,gBAAgB;AAAA,MAClB;AAAA,MACA,MAAM,KAAK,UAAU;AAAA,QACnB,KAAK;AAAA,QACL,iBAAiB;AAAA,MACnB,CAAC;AAAA,IACH,CAAC;AAED,QAAI,CAAC,SAAS,IAAI;AAChB,YAAM,IAAI,MAAM,iCAAiC,SAAS,UAAU,EAAE;AAAA,IACxE;AAEA,UAAM,OAAO,MAAM,SAAS,KAAK;AAEjC,QAAI,CAAC,KAAK,KAAK;AACb,YAAM,IAAI,MAAM,2CAA2C;AAAA,IAC7D;AAEA,QAAI,CAAC,KAAK,aAAa;AACrB,YAAM,IAAI,MAAM,6CAA6C;AAAA,IAC/D;AAEA,QAAI,CAAC,KAAK,aAAa;AACrB,YAAM,IAAI,MAAM,6CAA6C;AAAA,IAC/D;AAEA,WAAO;AAAA,MACL,KAAK,KAAK;AAAA,MACV,aAAa,KAAK;AAAA,MAClB,aAAa,KAAK;AAAA,IACpB;AAAA,EACF,SAAS,OAAO;AACd,UAAM,IAAI,MAAM,gCAAgC,KA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AiB,gBAAyE;AACpG,SAAK,OAAO,eAAe;AAC3B,SAAK,UAAU,IAAI;AAAA,MACjB;AAAA,MACA,eAAe;AAAA,MACf,eAAe,QAAQ;AAAA,MACvB;AAAA,IACF;AAGA,QAAI,eAAe,QAAQ,UAAU;AACnC,WAAK,WAAW,IAAI,yBAAyB,QAAQ,eAAe,QAAQ,QAAQ;AAAA,IACtF;AAEA,QAAI,eAAe,QAAQ,UAAU;AACnC,WAAK,WAAW,IAAI,yBAAyB,QAAQ,eAAe,QAAQ,QAAQ;AAAA,IACtF;AAAA,EACF;AAAA,EAEA,uBAAkC;AAGhC,WAAO,CAAC,QAAQ,QAAQ;AAAA,EAC1B;AACF;AAQO,SAAS,eACd,gBAC+D;AAE/D,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 * Type mapping for provider names to their sandbox types\n * Manually defined for known providers since declaration merging isn't working reliably\n */\nexport interface ProviderSandboxTypeMap {\n e2b: any; // We can't import the E2B type directly, but we'll handle it differently\n vercel: any;\n daytona: any;\n}\n\n/**\n * Utility type to extract the native instance type from a provider\n * Uses provider name and manual type inference\n */\nexport type ExtractSandboxInstanceType<TProvider extends Provider> = \n TProvider extends { readonly name: 'e2b' }\n ? any // For now, let's just try to make the runtime casting work\n : TProvider extends { readonly name: 'vercel' }\n ? any\n : TProvider extends { readonly name: 'daytona' }\n ? any\n : any;\n\n/**\n * Supported runtime environments\n */\nexport type Runtime = 'node' | 'python';\n\n/**\n * Sandbox status types\n */\nexport type SandboxStatus = 'running' | 'stopped' | 'error';\n\n/**\n * Options for running commands\n */\nexport interface RunCommandOptions {\n /** Run command in background (non-blocking) */\n background?: boolean;\n}\n\n/**\n * Result of code execution\n */\nexport interface ExecutionResult {\n /** Standard output from the execution */\n stdout: string;\n /** Standard error from the execution */\n stderr: string;\n /** Exit code from the execution */\n exitCode: number;\n /** Time taken for execution in milliseconds */\n executionTime: number;\n /** ID of the sandbox where the code was executed */\n sandboxId: string;\n /** Provider that executed the code */\n provider: string;\n /** Process ID for background jobs (if applicable) */\n pid?: number;\n /** Whether this command is running in background */\n isBackground?: boolean;\n}\n\n/**\n * Information about a sandbox\n */\nexport interface SandboxInfo {\n /** Unique identifier for the sandbox */\n id: string;\n /** Provider hosting the sandbox */\n provider: string;\n /** Runtime environment in the sandbox */\n runtime: Runtime;\n /** Current status of the sandbox */\n status: SandboxStatus;\n /** When the sandbox was created */\n createdAt: Date;\n /** Execution timeout in milliseconds */\n timeout: number;\n /** Additional provider-specific metadata */\n metadata?: Record<string, any>;\n}\n\n/**\n * Options for creating a sandbox\n */\nexport interface CreateSandboxOptions {\n /** Runtime environment (defaults to 'node' if not specified) */\n runtime?: Runtime;\n /** Execution timeout in milliseconds */\n timeout?: number;\n /** Custom sandbox ID (if supported by provider) */\n sandboxId?: string;\n /** Template ID for sandbox creation (provider-specific) */\n templateId?: string;\n /** Additional metadata for the sandbox */\n metadata?: Record<string, any>;\n /** Domain for sandbox connection (provider-specific) */\n domain?: string;\n /** Environment variables for the sandbox */\n envs?: Record<string, string>;\n}\n\n/**\n * File system entry information\n */\nexport interface FileEntry {\n /** File/directory name */\n name: string;\n /** Full path to the entry */\n path: string;\n /** Whether this is a directory */\n isDirectory: boolean;\n /** File size in bytes (0 for directories) */\n size: number;\n /** Last modified timestamp */\n lastModified: Date;\n}\n\n/**\n * File system interface for sandbox operations\n */\nexport interface SandboxFileSystem {\n /** Read file contents */\n readFile(path: string): Promise<string>;\n /** Write file contents */\n writeFile(path: string, content: string): Promise<void>;\n /** Create directory */\n mkdir(path: string): Promise<void>;\n /** List directory contents */\n readdir(path: string): Promise<FileEntry[]>;\n /** Check if file/directory exists */\n exists(path: string): Promise<boolean>;\n /** Remove file or directory */\n remove(path: string): Promise<void>;\n}\n\n/**\n * Error thrown when a command exits with a non-zero status\n */\nexport class CommandExitError extends Error {\n name = 'CommandExitError';\n constructor(public result: {\n exitCode: number;\n stdout: string;\n stderr: string;\n error: boolean;\n }) {\n super(`Command exited with code ${result.exitCode}`);\n }\n}\n\n/**\n * Type guard to check if an error is a CommandExitError\n */\nexport function isCommandExitError(error: unknown): error is CommandExitError {\n return (\n typeof error === 'object' &&\n error !== null &&\n 'name' in error &&\n error.name === 'CommandExitError' &&\n 'result' in error\n );\n}\n\n\n\n\n\n/**\n * Base sandbox interface - what developers interact with\n */\nexport interface Sandbox<TSandbox = any> {\n /** Unique identifier for the sandbox */\n readonly sandboxId: string;\n /** Provider that created this sandbox */\n readonly provider: string;\n\n /** Execute code in the sandbox */\n runCode(code: string, runtime?: Runtime): Promise<ExecutionResult>;\n /** Execute shell commands */\n runCommand(command: string, args?: string[], options?: RunCommandOptions): Promise<ExecutionResult>;\n /** Get information about the sandbox */\n getInfo(): Promise<SandboxInfo>;\n /** Get URL for accessing the sandbox on a specific port */\n getUrl(options: { port: number; protocol?: string }): Promise<string>;\n /** Get the provider instance that created this sandbox */\n getProvider(): import('./provider').Provider<TSandbox>;\n /** Get the native provider sandbox instance with proper typing */\n getInstance(): TSandbox;\n /** Kill the sandbox */\n kill(): Promise<void>;\n /** Destroy the sandbox and clean up resources */\n destroy(): Promise<void>;\n\n /** File system operations */\n readonly filesystem: SandboxFileSystem;\n}\n\n/**\n * Extract the sandbox type from a provider\n */\ntype ExtractProviderSandboxType<TProvider extends Provider> = TProvider extends { readonly __sandboxType: infer TSandbox } ? TSandbox : any;\n\n/**\n * Typed sandbox interface that preserves the provider's native instance type\n */\nexport interface TypedSandbox<TProvider extends Provider> extends Omit<Sandbox<ExtractProviderSandboxType<TProvider>>, 'getProvider'> {\n /** Get the provider instance that created this sandbox with proper typing */\n getProvider(): TProvider;\n /** Get the native provider sandbox instance with proper typing */\n getInstance(): ExtractProviderSandboxType<TProvider>;\n}","/**\n * Compute Singleton - Main API Orchestrator\n *\n * Provides the unified compute.* API and delegates to specialized managers\n */\n\nimport { ComputeClient } from '@computesdk/client';\nimport type { ComputeAPI, CreateSandboxParams, CreateSandboxParamsWithOptionalProvider, ComputeConfig, Sandbox, Provider, TypedSandbox, TypedComputeAPI } from './types';\n\n/**\n * Authorization response from license server\n */\ninterface AuthorizationResponse {\n jwt: string;\n sandbox_url: string;\n preview_url: string;\n}\n\n/**\n * Authorize license key and get JWT token + URLs from license server\n */\nasync function authorizeApiKey(apiKey: string): Promise<AuthorizationResponse> {\n try {\n const response = await fetch('https://preview.computesdk.com/__api/license/authorize', {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({\n key: apiKey,\n increment_usage: 1\n })\n });\n\n if (!response.ok) {\n throw new Error(`License authorization failed: ${response.statusText}`);\n }\n\n const data = await response.json();\n\n if (!data.access_token) {\n throw new Error('No JWT token received from license server');\n }\n\n if (!data.sandbox_url) {\n throw new Error('No sandbox_url received from license server');\n }\n\n if (!data.preview_url) {\n throw new Error('No preview_url received from license server');\n }\n\n return {\n jwt: data.access_token,\n sandbox_url: data.sandbox_url,\n preview_url: data.preview_url\n };\n } catch (error) {\n throw new Error(`Failed to authorize API key: ${error}`);\n }\n}\n\n/**\n * Install and start compute CLI inside a sandbox\n */\nasync function installComputeInSandbox(\n sandbox: Sandbox,\n config?: { apiKey?: string; jwt?: string }\n): Promise<AuthorizationResponse | null> {\n try {\n console.log('Installing and starting compute CLI in sandbox...');\n\n // Get JWT token and URLs from API key if provided\n let authResponse: AuthorizationResponse | null = null;\n let jwt = config?.jwt;\n\n if (config?.apiKey && !jwt) {\n console.log('Authorizing API key and getting JWT token...');\n authResponse = await authorizeApiKey(config.apiKey);\n jwt = authResponse.jwt;\n }\n\n // Build install command with authentication\n let installCommand = 'curl -fsSL https://computesdk.com/install.sh | sh';\n\n if (jwt) {\n installCommand = `curl -fsSL https://computesdk.com/install.sh | sh -s -- --jwt ${jwt}`;\n }\n\n // Run the install script (it will handle installation and starting compute)\n const result = await sandbox.runCommand('sh', ['-c', installCommand]);\n\n if (result.exitCode !== 0) {\n throw new Error(`Failed to install and start compute CLI: ${result.stderr}`);\n }\n\n console.log('Compute CLI installed and started successfully');\n\n return authResponse;\n } catch (error) {\n throw new Error(`Failed to install compute CLI in sandbox: ${error}`);\n }\n}\n\n/**\n * Compute singleton implementation - orchestrates all compute operations\n */\nclass ComputeManager implements ComputeAPI {\n private config: ComputeConfig | null = null;\n private typedState: {\n isTyped: boolean;\n provider: Provider | null;\n } = { isTyped: false, provider: null };\n private computeAuth: { apiKey?: string; jwt?: string } = {};\n\n /**\n * Set default configuration with generic type preservation\n */\n setConfig<TProvider extends Provider>(config: ComputeConfig<TProvider>): void {\n // Validate that at least one provider is specified\n if (!config.defaultProvider && !config.provider) {\n throw new Error('Either defaultProvider or provider must be specified in setConfig');\n }\n\n // Handle backwards compatibility: if both are provided, defaultProvider takes precedence\n if (config.defaultProvider && config.provider) {\n console.warn('Both defaultProvider and provider specified in setConfig. Using defaultProvider. The provider key is deprecated, please use defaultProvider instead.');\n }\n\n // Normalize config to always have both fields for internal use (backward compatibility)\n const actualProvider = config.defaultProvider || config.provider!;\n this.config = {\n provider: actualProvider,\n defaultProvider: actualProvider,\n apiKey: config.apiKey,\n jwt: config.jwt\n };\n\n // Store compute auth credentials\n this.computeAuth = {\n apiKey: config.apiKey,\n jwt: config.jwt\n };\n\n // Store typed state for type-aware operations\n this.typedState = {\n isTyped: true,\n provider: actualProvider\n };\n }\n\n /**\n * Get current configuration\n */\n getConfig(): ComputeConfig | null {\n return this.config;\n }\n\n /**\n * Clear current configuration\n */\n clearConfig(): void {\n this.config = null;\n }\n\n /**\n * Get the default provider, throwing if not configured\n */\n private getDefaultProvider(): Provider {\n const provider = this.config?.defaultProvider || this.config?.provider;\n if (!provider) {\n throw new Error(\n 'No default provider configured. Either call compute.setConfig({ defaultProvider }) or pass provider explicitly.'\n );\n }\n return provider;\n }\n\n sandbox = {\n /**\n * Create a sandbox from a provider (or default provider if configured)\n * \n * @example\n * ```typescript\n * import { e2b } from '@computesdk/e2b'\n * import { compute } from 'computesdk'\n * \n * // With explicit provider\n * const sandbox = await compute.sandbox.create({\n * provider: e2b({ apiKey: 'your-key' })\n * })\n * \n * // With default provider (both forms work)\n * compute.setConfig({ defaultProvider: e2b({ apiKey: 'your-key' }) })\n * const sandbox1 = await compute.sandbox.create({})\n * const sandbox2 = await compute.sandbox.create()\n * ```\n */\n create: async (params?: CreateSandboxParams | CreateSandboxParamsWithOptionalProvider): Promise<Sandbox> => {\n const provider = params && 'provider' in params && params.provider ? params.provider : this.getDefaultProvider();\n const options = params?.options;\n const sandbox = await provider.sandbox.create(options);\n\n // Install compute CLI in the sandbox with auth credentials if available\n const authResponse = await installComputeInSandbox(sandbox, this.computeAuth);\n\n // If we have authorization info, use ComputeClient instead of provider sandbox\n let finalSandbox: Sandbox = sandbox;\n if (authResponse) {\n finalSandbox = new ComputeClient({\n sandboxUrl: authResponse.sandbox_url,\n sandboxId: sandbox.sandboxId,\n provider: sandbox.provider,\n token: authResponse.jwt\n }) as Sandbox;\n }\n\n // If we have typed state and no explicit provider passed, cast to typed sandbox\n // This enables proper type inference for getInstance() when using default provider\n if (this.typedState.isTyped && (!params || !('provider' in params && params.provider))) {\n return finalSandbox as TypedSandbox<any>;\n }\n\n return finalSandbox;\n },\n\n /**\n * Get an existing sandbox by ID from a provider (or default provider if configured)\n */\n getById: async (providerOrSandboxId: Provider | string, sandboxId?: string): Promise<Sandbox | null> => {\n if (typeof providerOrSandboxId === 'string') {\n // Called with just sandboxId, use default provider\n const provider = this.getDefaultProvider();\n const sandbox = await provider.sandbox.getById(providerOrSandboxId);\n \n // If we have typed state, cast to typed sandbox for proper getInstance() typing\n if (this.typedState.isTyped && sandbox) {\n return sandbox as TypedSandbox<any>;\n }\n \n return sandbox;\n } else {\n // Called with provider and sandboxId\n if (!sandboxId) {\n throw new Error('sandboxId is required when provider is specified');\n }\n return await providerOrSandboxId.sandbox.getById(sandboxId);\n }\n },\n\n /**\n * List all active sandboxes from a provider (or default provider if configured)\n */\n list: async (provider?: Provider): Promise<Sandbox[]> => {\n const actualProvider = provider || this.getDefaultProvider();\n const sandboxes = await actualProvider.sandbox.list();\n \n // If we have typed state and no explicit provider passed, cast to typed sandboxes\n if (this.typedState.isTyped && !provider) {\n return sandboxes as TypedSandbox<any>[];\n }\n \n return sandboxes;\n },\n\n /**\n * Destroy a sandbox via a provider (or default provider if configured)\n */\n destroy: async (providerOrSandboxId: Provider | string, sandboxId?: string): Promise<void> => {\n if (typeof providerOrSandboxId === 'string') {\n // Called with just sandboxId, use default provider\n const provider = this.getDefaultProvider();\n return await provider.sandbox.destroy(providerOrSandboxId);\n } else {\n // Called with provider and sandboxId\n if (!sandboxId) {\n throw new Error('sandboxId is required when provider is specified');\n }\n return await providerOrSandboxId.sandbox.destroy(sandboxId);\n }\n }\n };\n\n // Future: compute.blob.*, compute.database.*, compute.git.* will be added here\n // blob = new BlobManager();\n // database = new DatabaseManager(); \n // git = new GitManager();\n\n\n}\n\n/**\n * Singleton instance - the main API (untyped)\n */\nexport const compute: ComputeAPI = new ComputeManager();\n\n\n\n/**\n * Create a compute instance with proper typing\n * \n * @example\n * ```typescript\n * import { e2b } from '@computesdk/e2b'\n * import { createCompute } from 'computesdk'\n * \n * const compute = createCompute({\n * defaultProvider: e2b({ apiKey: 'your-key' }),\n * });\n * \n * const sandbox = await compute.sandbox.create();\n * const instance = sandbox.getInstance(); // ✅ Properly typed E2B Sandbox!\n * ```\n */\nexport function createCompute<TProvider extends Provider>(config: ComputeConfig<TProvider>): TypedComputeAPI<TProvider> {\n const manager = new ComputeManager();\n\n // Set config directly without calling the public setConfig method\n const actualProvider = config.defaultProvider || config.provider!;\n manager['config'] = {\n provider: actualProvider,\n defaultProvider: actualProvider,\n apiKey: config.apiKey,\n jwt: config.jwt\n };\n manager['typedState'] = {\n isTyped: true,\n provider: actualProvider\n };\n manager['computeAuth'] = {\n apiKey: config.apiKey,\n jwt: config.jwt\n };\n\n return {\n setConfig: <T extends Provider>(cfg: ComputeConfig<T>) => createCompute(cfg),\n getConfig: () => manager.getConfig(),\n clearConfig: () => manager.clearConfig(),\n\n sandbox: {\n create: async (params?: Omit<CreateSandboxParamsWithOptionalProvider, 'provider'>) => {\n const sandbox = await manager.sandbox.create(params);\n // The sandbox should now have the correct getInstance typing from the generic Sandbox<TSandbox>\n return sandbox as TypedSandbox<TProvider>;\n },\n\n getById: async (sandboxId: string) => {\n const sandbox = await manager.sandbox.getById(sandboxId);\n return sandbox ? sandbox as TypedSandbox<TProvider> : null;\n },\n\n list: async () => {\n const sandboxes = await manager.sandbox.list();\n return sandboxes as TypedSandbox<TProvider>[];\n },\n\n destroy: async (sandboxId: string) => {\n return await manager.sandbox.destroy(sandboxId);\n }\n }\n } as TypedComputeAPI<TProvider>;\n}\n\n\n\n","/**\n * Simplified Request Handler for Web Framework Integration\n * \n * Handles JSON requests for sandbox and code execution operations.\n * Terminal support removed - will be re-added with WebSocket VM connections.\n */\n\nimport type { Provider, Runtime } from './types';\nimport { compute } from './compute';\n\n/**\n * Request structure supporting sandbox and code execution capabilities\n */\nexport interface ComputeRequest {\n /** Action in dot notation (e.g., 'compute.sandbox.create') */\n action: string;\n \n /** Parameters for the action */\n sandboxId?: string;\n code?: string;\n command?: string;\n args?: string[];\n runtime?: Runtime;\n path?: string;\n content?: string;\n \n /** Command options (for runCommand action) */\n commandOptions?: {\n background?: boolean;\n };\n \n /** Sandbox creation options */\n options?: {\n runtime?: Runtime;\n timeout?: number;\n sandboxId?: string;\n };\n}\n\n/**\n * Response structure for compute operations\n */\nexport interface ComputeResponse {\n success: boolean;\n error?: string;\n sandboxId: string;\n provider: string;\n [key: string]: any; // Allow any additional response data\n}\n\n/**\n * Execute compute action using targeted handling\n */\nasync function executeAction(body: ComputeRequest, provider: Provider): Promise<ComputeResponse> {\n try {\n const { action, sandboxId } = body;\n \n // Sandbox management operations\n if (action === 'compute.sandbox.create') {\n const sandbox = await compute.sandbox.create({\n provider,\n options: body.options || { runtime: 'python' }\n });\n return {\n success: true,\n sandboxId: sandbox.sandboxId,\n provider: provider.name\n };\n }\n \n if (action === 'compute.sandbox.list') {\n const sandboxes = await compute.sandbox.list(provider);\n return {\n success: true,\n sandboxId: '',\n provider: provider.name,\n sandboxes: sandboxes.map(sb => ({\n sandboxId: sb.sandboxId,\n provider: sb.provider\n }))\n };\n }\n \n if (action === 'compute.sandbox.destroy') {\n if (!sandboxId) {\n throw new Error('sandboxId is required for destroy action');\n }\n await compute.sandbox.destroy(provider, sandboxId);\n return {\n success: true,\n sandboxId,\n provider: provider.name\n };\n }\n \n // For sandbox instance methods, get the sandbox first\n if (!sandboxId) {\n throw new Error('sandboxId is required for this action');\n }\n \n const sandbox = await compute.sandbox.getById(provider, sandboxId);\n if (!sandbox) {\n throw new Error(`Sandbox ${sandboxId} not found`);\n }\n \n // Sandbox info\n if (action === 'compute.sandbox.getInfo') {\n const result = await sandbox.getInfo();\n return {\n success: true,\n sandboxId,\n provider: provider.name,\n info: {\n id: result.id,\n provider: result.provider,\n runtime: result.runtime,\n status: result.status,\n createdAt: result.createdAt.toISOString(),\n timeout: result.timeout,\n metadata: result.metadata\n }\n };\n }\n \n // Code execution\n if (action === 'compute.sandbox.runCode') {\n if (!body.code) throw new Error('code is required');\n const result = await sandbox.runCode(body.code, body.runtime);\n return {\n success: true,\n sandboxId,\n provider: provider.name,\n result: {\n stdout: result.stdout,\n stderr: result.stderr,\n exitCode: result.exitCode,\n executionTime: result.executionTime\n }\n };\n }\n \n if (action === 'compute.sandbox.runCommand') {\n if (!body.command) throw new Error('command is required');\n const result = await sandbox.runCommand(body.command, body.args, body.commandOptions);\n return {\n success: true,\n sandboxId,\n provider: provider.name,\n result: {\n stdout: result.stdout,\n stderr: result.stderr,\n exitCode: result.exitCode,\n executionTime: result.executionTime,\n ...(result.isBackground && { isBackground: result.isBackground }),\n ...(result.pid && { pid: result.pid })\n }\n };\n }\n \n // Filesystem operations\n if (action === 'compute.sandbox.filesystem.readFile') {\n if (!body.path) throw new Error('path is required');\n const result = await sandbox.filesystem.readFile(body.path);\n return {\n success: true,\n sandboxId,\n provider: provider.name,\n fileContent: result\n };\n }\n \n if (action === 'compute.sandbox.filesystem.writeFile') {\n if (!body.path) throw new Error('path is required');\n if (body.content === undefined) throw new Error('content is required');\n await sandbox.filesystem.writeFile(body.path, body.content);\n return { success: true, sandboxId, provider: provider.name };\n }\n \n if (action === 'compute.sandbox.filesystem.mkdir') {\n if (!body.path) throw new Error('path is required');\n await sandbox.filesystem.mkdir(body.path);\n return { success: true, sandboxId, provider: provider.name };\n }\n \n if (action === 'compute.sandbox.filesystem.readdir') {\n if (!body.path) throw new Error('path is required');\n const result = await sandbox.filesystem.readdir(body.path);\n return {\n success: true,\n sandboxId,\n provider: provider.name,\n files: result.map((entry: any) => ({\n name: entry.name,\n path: entry.path,\n isDirectory: entry.isDirectory,\n size: entry.size,\n lastModified: entry.lastModified.toISOString()\n }))\n };\n }\n \n if (action === 'compute.sandbox.filesystem.exists') {\n if (!body.path) throw new Error('path is required');\n const result = await sandbox.filesystem.exists(body.path);\n return {\n success: true,\n sandboxId,\n provider: provider.name,\n exists: result\n };\n }\n \n if (action === 'compute.sandbox.filesystem.remove') {\n if (!body.path) throw new Error('path is required');\n await sandbox.filesystem.remove(body.path);\n return { success: true, sandboxId, provider: provider.name };\n }\n \n throw new Error(`Unknown action: ${action}`);\n \n } catch (error) {\n return {\n success: false,\n error: error instanceof Error ? error.message : 'Unknown error occurred',\n sandboxId: body.sandboxId || '',\n provider: provider.name\n };\n }\n}\n\n/**\n * Main request handler - handles HTTP requests and pre-parsed bodies\n */\nexport async function handleComputeRequest(\n params: HandleComputeRequestParams\n): Promise<ComputeResponse>;\nexport async function handleComputeRequest(\n requestOrBody: Request | ComputeRequest,\n provider: Provider\n): Promise<Response>;\nexport async function handleComputeRequest(\n paramsOrRequestOrBody: HandleComputeRequestParams | Request | ComputeRequest,\n provider?: Provider\n): Promise<ComputeResponse | Response> {\n // Handle object-style API\n if (typeof paramsOrRequestOrBody === 'object' && 'request' in paramsOrRequestOrBody && 'provider' in paramsOrRequestOrBody) {\n const params = paramsOrRequestOrBody as HandleComputeRequestParams;\n return await executeAction(params.request, params.provider);\n }\n \n // Handle original API\n if (!provider) {\n throw new Error('Provider is required when not using object-style API');\n }\n \n const requestOrBody = paramsOrRequestOrBody as Request | ComputeRequest;\n try {\n let body: ComputeRequest;\n \n if (requestOrBody instanceof Request) {\n // Handle HTTP method validation\n if (requestOrBody.method !== 'POST') {\n return Response.json({\n success: false,\n error: 'Only POST requests are supported',\n sandboxId: '',\n provider: provider.name\n }, { status: 405 });\n }\n \n // Parse JSON body with better error handling\n try {\n body = await requestOrBody.json();\n } catch (parseError) {\n return Response.json({\n success: false,\n error: 'Invalid JSON in request body',\n sandboxId: '',\n provider: provider.name\n }, { status: 400 });\n }\n } else {\n body = requestOrBody;\n }\n \n // Execute the action\n const result = await executeAction(body, provider);\n \n return Response.json(result, {\n status: result.success ? 200 : 500\n });\n \n } catch (error) {\n return Response.json({\n success: false,\n error: error instanceof Error ? error.message : 'Request handling failed',\n sandboxId: '',\n provider: provider.name\n }, { status: 500 });\n }\n}\n\n/**\n * Legacy export for backward compatibility\n */\nexport interface HandleComputeRequestParams {\n request: ComputeRequest;\n provider: Provider;\n}\n\nexport { handleComputeRequest as handleHttpComputeRequest };","/**\n * Provider Factory - Creates providers from method definitions\n * \n * Eliminates boilerplate by auto-generating Provider/Sandbox classes\n * from simple method definitions with automatic feature detection.\n */\n\nimport type {\n Provider,\n ProviderSandboxManager,\n ProviderTemplateManager,\n ProviderSnapshotManager,\n Sandbox,\n SandboxFileSystem,\n SandboxInfo,\n ExecutionResult,\n Runtime,\n CreateSandboxOptions,\n FileEntry,\n RunCommandOptions,\n CreateSnapshotOptions,\n ListSnapshotsOptions,\n CreateTemplateOptions,\n ListTemplatesOptions,\n} from './types/index.js';\n\n/**\n * Helper function to handle background command execution\n * Providers can use this to implement background job support\n */\nexport function createBackgroundCommand(command: string, args: string[] = [], options?: RunCommandOptions): { command: string; args: string[]; isBackground: boolean } {\n if (!options?.background) {\n return { command, args, isBackground: false };\n }\n\n // For background execution, we modify the command to run in background\n // Default approach: append & to make it run in background\n const fullCommand = args.length > 0 ? `${command} ${args.join(' ')}` : command;\n \n return {\n command: 'sh',\n args: ['-c', `${fullCommand} &`],\n isBackground: true\n };\n}\n\n/**\n * Flat sandbox method implementations - all operations in one place\n */\nexport interface SandboxMethods<TSandbox = any, TConfig = any> {\n // Collection operations (map to compute.sandbox.*)\n create: (config: TConfig, options?: CreateSandboxOptions) => Promise<{ sandbox: TSandbox; sandboxId: string }>;\n getById: (config: TConfig, sandboxId: string) => Promise<{ sandbox: TSandbox; sandboxId: string } | null>;\n list: (config: TConfig) => Promise<Array<{ sandbox: TSandbox; sandboxId: string }>>;\n destroy: (config: TConfig, sandboxId: string) => Promise<void>;\n \n // Instance operations (map to individual Sandbox methods)\n runCode: (sandbox: TSandbox, code: string, runtime?: Runtime, config?: TConfig) => Promise<ExecutionResult>;\n runCommand: (sandbox: TSandbox, command: string, args?: string[], options?: RunCommandOptions) => Promise<ExecutionResult>;\n getInfo: (sandbox: TSandbox) => Promise<SandboxInfo>;\n getUrl: (sandbox: TSandbox, options: { port: number; protocol?: string }) => Promise<string>;\n \n // Optional provider-specific typed getInstance method\n getInstance?: (sandbox: TSandbox) => TSandbox;\n \n // Optional filesystem methods\n filesystem?: {\n readFile: (sandbox: TSandbox, path: string, runCommand: (sandbox: TSandbox, command: string, args?: string[]) => Promise<ExecutionResult>) => Promise<string>;\n writeFile: (sandbox: TSandbox, path: string, content: string, runCommand: (sandbox: TSandbox, command: string, args?: string[]) => Promise<ExecutionResult>) => Promise<void>;\n mkdir: (sandbox: TSandbox, path: string, runCommand: (sandbox: TSandbox, command: string, args?: string[]) => Promise<ExecutionResult>) => Promise<void>;\n readdir: (sandbox: TSandbox, path: string, runCommand: (sandbox: TSandbox, command: string, args?: string[]) => Promise<ExecutionResult>) => Promise<FileEntry[]>;\n exists: (sandbox: TSandbox, path: string, runCommand: (sandbox: TSandbox, command: string, args?: string[]) => Promise<ExecutionResult>) => Promise<boolean>;\n remove: (sandbox: TSandbox, path: string, runCommand: (sandbox: TSandbox, command: string, args?: string[]) => Promise<ExecutionResult>) => Promise<void>;\n };\n}\n\n/**\n * Template method implementations\n */\nexport interface TemplateMethods<TTemplate = any, TConfig = any> {\n create: (config: TConfig, options: CreateTemplateOptions | any) => Promise<TTemplate>;\n list: (config: TConfig, options?: ListTemplatesOptions) => Promise<TTemplate[]>;\n delete: (config: TConfig, templateId: string) => Promise<void>;\n}\n\n/**\n * Snapshot method implementations \n */\nexport interface SnapshotMethods<TSnapshot = any, TConfig = any> {\n create: (config: TConfig, sandboxId: string, options?: CreateSnapshotOptions) => Promise<TSnapshot>;\n list: (config: TConfig, options?: ListSnapshotsOptions) => Promise<TSnapshot[]>;\n delete: (config: TConfig, snapshotId: string) => Promise<void>;\n}\n\n/**\n * Provider configuration for createProvider()\n */\nexport interface ProviderConfig<TSandbox = any, TConfig = any, TTemplate = any, TSnapshot = any> {\n name: string;\n methods: {\n sandbox: SandboxMethods<TSandbox, TConfig>;\n template?: TemplateMethods<TTemplate, TConfig>;\n snapshot?: SnapshotMethods<TSnapshot, TConfig>;\n };\n}\n\n/**\n * Default filesystem implementations based on shell commands\n * These work for any provider that supports shell command execution\n */\nconst defaultFilesystemMethods = {\n readFile: async (sandbox: any, path: string, runCommand: (sandbox: any, command: string, args?: string[]) => Promise<ExecutionResult>): Promise<string> => {\n const result = await runCommand(sandbox, 'cat', [path]);\n if (result.exitCode !== 0) {\n throw new Error(`Failed to read file ${path}: ${result.stderr}`);\n }\n // Trim trailing newline that cat command adds\n return result.stdout.replace(/\\n$/, '');\n },\n\n writeFile: async (sandbox: any, path: string, content: string, runCommand: (sandbox: any, command: string, args?: string[]) => Promise<ExecutionResult>): Promise<void> => {\n const result = await runCommand(sandbox, 'sh', ['-c', `echo ${JSON.stringify(content)} > ${JSON.stringify(path)}`]);\n if (result.exitCode !== 0) {\n throw new Error(`Failed to write file ${path}: ${result.stderr}`);\n }\n },\n\n mkdir: async (sandbox: any, path: string, runCommand: (sandbox: any, command: string, args?: string[]) => Promise<ExecutionResult>): Promise<void> => {\n const result = await runCommand(sandbox, 'mkdir', ['-p', path]);\n if (result.exitCode !== 0) {\n throw new Error(`Failed to create directory ${path}: ${result.stderr}`);\n }\n },\n\n readdir: async (sandbox: any, path: string, runCommand: (sandbox: any, command: string, args?: string[]) => Promise<ExecutionResult>): Promise<FileEntry[]> => {\n // Try different ls variations for maximum compatibility\n let result = await runCommand(sandbox, 'ls', ['-la', path]);\n let hasDetailedOutput = true;\n \n // Fall back to basic ls if detailed flags not supported\n if (result.exitCode !== 0) {\n result = await runCommand(sandbox, 'ls', ['-l', path]);\n }\n if (result.exitCode !== 0) {\n result = await runCommand(sandbox, 'ls', [path]);\n hasDetailedOutput = false;\n }\n \n if (result.exitCode !== 0) {\n throw new Error(`Failed to list directory ${path}: ${result.stderr}`);\n }\n\n const lines = (result.stdout || '').split('\\n').filter((line: string) => line.trim() && !line.startsWith('total'));\n\n return lines.map((line: string) => {\n if (hasDetailedOutput && line.includes(' ')) {\n // Parse detailed ls output (ls -la or ls -l)\n const parts = line.trim().split(/\\s+/);\n const name = parts[parts.length - 1];\n const isDirectory = line.startsWith('d');\n \n return {\n name,\n path: `${path}/${name}`,\n isDirectory,\n size: parseInt(parts[4]) || 0,\n lastModified: new Date()\n };\n } else {\n // Parse simple ls output (just filenames)\n const name = line.trim();\n return {\n name,\n path: `${path}/${name}`,\n isDirectory: false, // Can't determine from simple ls\n size: 0,\n lastModified: new Date()\n };\n }\n });\n },\n\n exists: async (sandbox: any, path: string, runCommand: (sandbox: any, command: string, args?: string[]) => Promise<ExecutionResult>): Promise<boolean> => {\n const result = await runCommand(sandbox, 'test', ['-e', path]);\n return result.exitCode === 0; // Exit code 0 means file exists\n },\n\n remove: async (sandbox: any, path: string, runCommand: (sandbox: any, command: string, args?: string[]) => Promise<ExecutionResult>): Promise<void> => {\n const result = await runCommand(sandbox, 'rm', ['-rf', path]);\n if (result.exitCode !== 0) {\n throw new Error(`Failed to remove ${path}: ${result.stderr}`);\n }\n }\n};\n\n/**\n * Auto-generated filesystem implementation that throws \"not supported\" errors\n */\nclass UnsupportedFileSystem implements SandboxFileSystem {\n private readonly providerName: string;\n\n constructor(providerName: string) {\n this.providerName = providerName;\n }\n\n async readFile(_path: string): Promise<string> {\n throw new Error(`Filesystem operations are not supported by ${this.providerName}'s sandbox environment. ${this.providerName} sandboxes are designed for code execution only.`);\n }\n\n async writeFile(_path: string, _content: string): Promise<void> {\n throw new Error(`Filesystem operations are not supported by ${this.providerName}'s sandbox environment. ${this.providerName} sandboxes are designed for code execution only.`);\n }\n\n async mkdir(_path: string): Promise<void> {\n throw new Error(`Filesystem operations are not supported by ${this.providerName}'s sandbox environment. ${this.providerName} sandboxes are designed for code execution only.`);\n }\n\n async readdir(_path: string): Promise<FileEntry[]> {\n throw new Error(`Filesystem operations are not supported by ${this.providerName}'s sandbox environment. ${this.providerName} sandboxes are designed for code execution only.`);\n }\n\n async exists(_path: string): Promise<boolean> {\n throw new Error(`Filesystem operations are not supported by ${this.providerName}'s sandbox environment. ${this.providerName} sandboxes are designed for code execution only.`);\n }\n\n async remove(_path: string): Promise<void> {\n throw new Error(`Filesystem operations are not supported by ${this.providerName}'s sandbox environment. ${this.providerName} sandboxes are designed for code execution only.`);\n }\n}\n\n\n\n/**\n * Auto-generated filesystem implementation that wraps provider methods\n */\nclass SupportedFileSystem<TSandbox> implements SandboxFileSystem {\n constructor(\n private sandbox: TSandbox,\n private methods: NonNullable<SandboxMethods<TSandbox>['filesystem']>,\n private allMethods: SandboxMethods<TSandbox>\n ) {}\n\n async readFile(path: string): Promise<string> {\n return this.methods.readFile(this.sandbox, path, this.allMethods.runCommand);\n }\n\n async writeFile(path: string, content: string): Promise<void> {\n return this.methods.writeFile(this.sandbox, path, content, this.allMethods.runCommand);\n }\n\n async mkdir(path: string): Promise<void> {\n return this.methods.mkdir(this.sandbox, path, this.allMethods.runCommand);\n }\n\n async readdir(path: string): Promise<FileEntry[]> {\n return this.methods.readdir(this.sandbox, path, this.allMethods.runCommand);\n }\n\n async exists(path: string): Promise<boolean> {\n return this.methods.exists(this.sandbox, path, this.allMethods.runCommand);\n }\n\n async remove(path: string): Promise<void> {\n return this.methods.remove(this.sandbox, path, this.allMethods.runCommand);\n }\n}\n\n\n\n\n\n/**\n * Generated sandbox class - implements the Sandbox interface\n */\nclass GeneratedSandbox<TSandbox = any> implements Sandbox<TSandbox> {\n readonly sandboxId: string;\n readonly provider: string;\n readonly filesystem: SandboxFileSystem;\n\n constructor(\n private sandbox: TSandbox,\n sandboxId: string,\n providerName: string,\n private methods: SandboxMethods<TSandbox>,\n private config: any,\n private destroyMethod: (config: any, sandboxId: string) => Promise<void>,\n private providerInstance: Provider\n ) {\n this.sandboxId = sandboxId;\n this.provider = providerName;\n\n // Auto-detect filesystem support\n if (methods.filesystem) {\n this.filesystem = new SupportedFileSystem(sandbox, methods.filesystem, methods);\n } else {\n this.filesystem = new UnsupportedFileSystem(providerName);\n }\n }\n\n getInstance(): TSandbox {\n // Use provider-specific typed getInstance if available\n if (this.methods.getInstance) {\n return this.methods.getInstance(this.sandbox);\n }\n // Fallback to returning the sandbox directly\n return this.sandbox;\n }\n\n async runCode(code: string, runtime?: Runtime): Promise<ExecutionResult> {\n return await this.methods.runCode(this.sandbox, code, runtime, this.config);\n }\n\n async runCommand(command: string, args?: string[], options?: RunCommandOptions): Promise<ExecutionResult> {\n return await this.methods.runCommand(this.sandbox, command, args, options);\n }\n\n async getInfo(): Promise<SandboxInfo> {\n return await this.methods.getInfo(this.sandbox);\n }\n\n async getUrl(options: { port: number; protocol?: string }): Promise<string> {\n return await this.methods.getUrl(this.sandbox, options);\n }\n\n getProvider(): Provider<TSandbox> {\n return this.providerInstance;\n }\n\n async kill(): Promise<void> {\n // For backward compatibility, kill() delegates to destroy()\n await this.destroy();\n }\n\n async destroy(): Promise<void> {\n // Destroy via the provider's destroy method using our sandboxId\n await this.destroyMethod(this.config, this.sandboxId);\n }\n}\n\n/**\n * Auto-generated Sandbox Manager implementation\n */\nclass GeneratedSandboxManager<TSandbox, TConfig> implements ProviderSandboxManager<TSandbox> {\n private activeSandboxes: Map<string, GeneratedSandbox<TSandbox>> = new Map();\n\n constructor(\n private config: TConfig,\n private providerName: string,\n private methods: SandboxMethods<TSandbox, TConfig>,\n private providerInstance: Provider\n ) {}\n\n async create(options?: CreateSandboxOptions): Promise<Sandbox<TSandbox>> {\n // Default to 'node' runtime if not specified for consistency across providers\n const optionsWithDefaults = { runtime: 'node' as Runtime, ...options };\n const result = await this.methods.create(this.config, optionsWithDefaults);\n const sandbox = new GeneratedSandbox<TSandbox>(\n result.sandbox,\n result.sandboxId,\n this.providerName,\n this.methods,\n this.config,\n this.methods.destroy,\n this.providerInstance\n );\n \n this.activeSandboxes.set(result.sandboxId, sandbox);\n return sandbox;\n }\n\n async getById(sandboxId: string): Promise<Sandbox<TSandbox> | null> {\n // Check active sandboxes first\n const existing = this.activeSandboxes.get(sandboxId);\n if (existing) {\n return existing;\n }\n\n // Try to reconnect\n const result = await this.methods.getById(this.config, sandboxId);\n if (!result) {\n return null;\n }\n\n const sandbox = new GeneratedSandbox<TSandbox>(\n result.sandbox,\n result.sandboxId,\n this.providerName,\n this.methods,\n this.config,\n this.methods.destroy,\n this.providerInstance\n );\n \n this.activeSandboxes.set(result.sandboxId, sandbox);\n return sandbox;\n }\n\n async list(): Promise<Sandbox<TSandbox>[]> {\n const results = await this.methods.list(this.config);\n const sandboxes: Sandbox[] = [];\n\n for (const result of results) {\n let sandbox = this.activeSandboxes.get(result.sandboxId);\n if (!sandbox) {\n sandbox = new GeneratedSandbox<TSandbox>(\n result.sandbox,\n result.sandboxId,\n this.providerName,\n this.methods,\n this.config,\n this.methods.destroy,\n this.providerInstance\n );\n this.activeSandboxes.set(result.sandboxId, sandbox);\n }\n sandboxes.push(sandbox);\n }\n\n return sandboxes;\n }\n\n async destroy(sandboxId: string): Promise<void> {\n await this.methods.destroy(this.config, sandboxId);\n this.activeSandboxes.delete(sandboxId);\n }\n}\n\n/**\n * Auto-generated Template Manager implementation\n */\nclass GeneratedTemplateManager<TTemplate, TConfig> implements ProviderTemplateManager<TTemplate> {\n constructor(\n private config: TConfig,\n private methods: TemplateMethods<TTemplate, TConfig>\n ) {}\n\n async create(options: CreateTemplateOptions | any): Promise<TTemplate> {\n return await this.methods.create(this.config, options);\n }\n\n async list(options?: ListTemplatesOptions): Promise<TTemplate[]> {\n return await this.methods.list(this.config, options);\n }\n\n async delete(templateId: string): Promise<void> {\n return await this.methods.delete(this.config, templateId);\n }\n}\n\n/**\n * Auto-generated Snapshot Manager implementation\n */\nclass GeneratedSnapshotManager<TSnapshot, TConfig> implements ProviderSnapshotManager<TSnapshot> {\n constructor(\n private config: TConfig,\n private methods: SnapshotMethods<TSnapshot, TConfig>\n ) {}\n\n async create(sandboxId: string, options?: CreateSnapshotOptions): Promise<TSnapshot> {\n return await this.methods.create(this.config, sandboxId, options);\n }\n\n async list(options?: ListSnapshotsOptions): Promise<TSnapshot[]> {\n return await this.methods.list(this.config, options);\n }\n\n async delete(snapshotId: string): Promise<void> {\n return await this.methods.delete(this.config, snapshotId);\n }\n}\n\n/**\n * Auto-generated Provider implementation\n */\nclass GeneratedProvider<TSandbox, TConfig, TTemplate, TSnapshot> implements Provider<TSandbox, TTemplate, TSnapshot> {\n readonly name: string;\n readonly sandbox: ProviderSandboxManager<TSandbox>;\n readonly template?: ProviderTemplateManager<TTemplate>;\n readonly snapshot?: ProviderSnapshotManager<TSnapshot>;\n readonly __sandboxType!: TSandbox; // Phantom type for TypeScript inference\n\n constructor(config: TConfig, providerConfig: ProviderConfig<TSandbox, TConfig, TTemplate, TSnapshot>) {\n this.name = providerConfig.name;\n this.sandbox = new GeneratedSandboxManager(\n config,\n providerConfig.name,\n providerConfig.methods.sandbox,\n this\n );\n\n // Initialize optional managers if methods are provided\n if (providerConfig.methods.template) {\n this.template = new GeneratedTemplateManager(config, providerConfig.methods.template);\n }\n \n if (providerConfig.methods.snapshot) {\n this.snapshot = new GeneratedSnapshotManager(config, providerConfig.methods.snapshot);\n }\n }\n\n getSupportedRuntimes(): Runtime[] {\n // For now, all providers support both node and python\n // In the future, this could be configurable per provider\n return ['node', 'python'];\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 = any, TTemplate = any, TSnapshot = any>(\n providerConfig: ProviderConfig<TSandbox, TConfig, TTemplate, TSnapshot>\n): (config: TConfig) => Provider<TSandbox, TTemplate, TSnapshot> {\n // Auto-inject default filesystem methods if none provided\n if (!providerConfig.methods.sandbox.filesystem) {\n providerConfig.methods.sandbox.filesystem = defaultFilesystemMethods;\n }\n\n return (config: TConfig) => {\n return new GeneratedProvider(config, providerConfig);\n };\n}"],"mappings":";AAwJO,IAAM,mBAAN,cAA+B,MAAM;AAAA,EAE1C,YAAmB,QAKhB;AACD,UAAM,4BAA4B,OAAO,QAAQ,EAAE;AANlC;AADnB,gBAAO;AAAA,EAQP;AACF;AAKO,SAAS,mBAAmB,OAA2C;AAC5E,SACE,OAAO,UAAU,YACjB,UAAU,QACV,UAAU,SACV,MAAM,SAAS,sBACf,YAAY;AAEhB;;;ACzKA,SAAS,qBAAqB;AAe9B,eAAe,gBAAgB,QAAgD;AAC7E,MAAI;AACF,UAAM,WAAW,MAAM,MAAM,0DAA0D;AAAA,MACrF,QAA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AAC1B,WAAO,IAAI,kBAAkB,QAAQ,cAAc;AAAA,EACrD;AACF;","names":["sandbox"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "computesdk",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.2",
|
|
4
4
|
"description": "A free and open-source toolkit for running other people's code in your applications.",
|
|
5
5
|
"author": "Garrison",
|
|
6
6
|
"license": "MIT",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"zod": "^3.22.0",
|
|
41
41
|
"uuid": "^9.0.0",
|
|
42
|
-
"@computesdk/client": "0.3.
|
|
42
|
+
"@computesdk/client": "0.3.1"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@types/node": "^20.0.0",
|