@computesdk/daytona 1.5.7 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -22,7 +22,7 @@ const compute = createCompute({
22
22
  });
23
23
 
24
24
  // Create sandbox
25
- const sandbox = await compute.sandbox.create({});
25
+ const sandbox = await compute.sandbox.create();
26
26
 
27
27
  // Execute code
28
28
  const result = await sandbox.runCode('print("Hello from Daytona!")');
package/dist/index.js CHANGED
@@ -27,6 +27,7 @@ var import_sdk = require("@daytonaio/sdk");
27
27
  var import_computesdk = require("computesdk");
28
28
  var daytona = (0, import_computesdk.createProvider)({
29
29
  name: "daytona",
30
+ defaultMode: "direct",
30
31
  methods: {
31
32
  sandbox: {
32
33
  // Collection operations (compute.sandbox.*)
@@ -128,12 +129,9 @@ var daytona = (0, import_computesdk.createProvider)({
128
129
  }
129
130
  const actualExitCode = hasError ? 1 : response.exitCode || 0;
130
131
  return {
131
- stdout: hasError ? "" : output,
132
- stderr: hasError ? output : "",
132
+ output,
133
133
  exitCode: actualExitCode,
134
- executionTime: Date.now() - startTime,
135
- sandboxId: sandbox.id,
136
- provider: "daytona"
134
+ language: effectiveRuntime
137
135
  };
138
136
  } catch (error) {
139
137
  if (error instanceof Error && error.message.includes("Syntax error")) {
@@ -144,29 +142,22 @@ var daytona = (0, import_computesdk.createProvider)({
144
142
  );
145
143
  }
146
144
  },
147
- runCommand: async (sandbox, command, args = [], options) => {
145
+ runCommand: async (sandbox, command, args = []) => {
148
146
  const startTime = Date.now();
149
147
  try {
150
- const { command: finalCommand, args: finalArgs, isBackground } = (0, import_computesdk.createBackgroundCommand)(command, args, options);
151
- const quotedArgs = finalArgs.map((arg) => {
148
+ const quotedArgs = args.map((arg) => {
152
149
  if (arg.includes(" ") || arg.includes('"') || arg.includes("'") || arg.includes("$") || arg.includes("`")) {
153
150
  return `"${arg.replace(/"/g, '\\"')}"`;
154
151
  }
155
152
  return arg;
156
153
  });
157
- const fullCommand = quotedArgs.length > 0 ? `${finalCommand} ${quotedArgs.join(" ")}` : finalCommand;
154
+ const fullCommand = quotedArgs.length > 0 ? `${command} ${quotedArgs.join(" ")}` : command;
158
155
  const response = await sandbox.process.executeCommand(fullCommand);
159
156
  return {
160
157
  stdout: response.result || "",
161
158
  stderr: "",
162
- // Daytona doesn't separate stderr in the response
163
159
  exitCode: response.exitCode || 0,
164
- executionTime: Date.now() - startTime,
165
- sandboxId: sandbox.id,
166
- provider: "daytona",
167
- isBackground,
168
- // For background commands, we can't get a real PID, but we can indicate it's running
169
- ...isBackground && { pid: -1 }
160
+ durationMs: Date.now() - startTime
170
161
  };
171
162
  } catch (error) {
172
163
  throw new Error(
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * Daytona Provider - Factory-based Implementation\n * \n * Code execution only provider using the factory pattern.\n * Reduces ~300 lines of boilerplate to ~80 lines of core logic.\n */\n\nimport { Daytona, Sandbox as DaytonaSandbox } from '@daytonaio/sdk';\nimport { createProvider, createBackgroundCommand } from 'computesdk';\nimport type { Runtime, ExecutionResult, SandboxInfo, CreateSandboxOptions, FileEntry, RunCommandOptions } from 'computesdk';\n\n/**\n * Daytona-specific configuration options\n */\nexport interface DaytonaConfig {\n /** Daytona API key - if not provided, will fallback to DAYTONA_API_KEY environment variable */\n apiKey?: string;\n /** Default runtime environment */\n runtime?: Runtime;\n /** Execution timeout in milliseconds */\n timeout?: number;\n}\n\n/**\n * Create a Daytona provider instance using the factory pattern\n */\nexport const daytona = createProvider<DaytonaSandbox, DaytonaConfig>({\n name: 'daytona',\n methods: {\n sandbox: {\n // Collection operations (compute.sandbox.*)\n create: async (config: DaytonaConfig, options?: CreateSandboxOptions) => {\n // Validate API key\n const apiKey = config.apiKey || (typeof process !== 'undefined' && process.env?.DAYTONA_API_KEY) || '';\n\n if (!apiKey) {\n throw new Error(\n `Missing Daytona API key. Provide 'apiKey' in config or set DAYTONA_API_KEY environment variable. Get your API key from https://daytona.io/`\n );\n }\n\n const runtime = options?.runtime || config.runtime || 'node';\n\n try {\n // Initialize Daytona client\n const daytona = new Daytona({ apiKey: apiKey });\n\n let session: DaytonaSandbox;\n let sandboxId: string;\n\n if (options?.sandboxId) {\n // Reconnect to existing Daytona sandbox\n session = await daytona.get(options.sandboxId);\n sandboxId = options.sandboxId;\n } else {\n // Create new Daytona sandbox\n session = await daytona.create({\n language: runtime === 'python' ? 'python' : 'javascript',\n });\n sandboxId = session.id;\n }\n\n return {\n sandbox: session,\n sandboxId\n };\n } catch (error) {\n if (error instanceof Error) {\n if (error.message.includes('unauthorized') || error.message.includes('API key')) {\n throw new Error(\n `Daytona authentication failed. Please check your DAYTONA_API_KEY environment variable. Get your API key from https://daytona.io/`\n );\n }\n if (error.message.includes('quota') || error.message.includes('limit')) {\n throw new Error(\n `Daytona quota exceeded. Please check your usage at https://daytona.io/`\n );\n }\n }\n throw new Error(\n `Failed to create Daytona sandbox: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n },\n\n getById: async (config: DaytonaConfig, sandboxId: string) => {\n const apiKey = config.apiKey || process.env.DAYTONA_API_KEY!;\n\n try {\n const daytona = new Daytona({ apiKey: apiKey });\n const session = await daytona.get(sandboxId);\n\n return {\n sandbox: session,\n sandboxId\n };\n } catch (error) {\n // Sandbox doesn't exist or can't be accessed\n return null;\n }\n },\n\n list: async (config: DaytonaConfig) => {\n const apiKey = config.apiKey || process.env.DAYTONA_API_KEY!;\n\n try {\n const daytona = new Daytona({ apiKey: apiKey });\n const sandboxes = await daytona.list();\n\n return sandboxes.map((session: any) => ({\n sandbox: session,\n sandboxId: session.id\n }));\n } catch (error) {\n // Return empty array if listing fails\n return [];\n }\n },\n\n destroy: async (config: DaytonaConfig, sandboxId: string) => {\n const apiKey = config.apiKey || process.env.DAYTONA_API_KEY!;\n\n try {\n const daytona = new Daytona({ apiKey: apiKey });\n // Note: Daytona SDK expects a Sandbox object, but we only have the ID\n // This is a limitation of the current Daytona SDK design\n // For now, we'll skip the delete operation\n const sandbox = await daytona.get(sandboxId);\n await sandbox.delete();\n } catch (error) {\n // Sandbox might already be destroyed or doesn't exist\n // This is acceptable for destroy operations\n }\n },\n\n // Instance operations (sandbox.*)\n runCode: async (sandbox: DaytonaSandbox, code: string, runtime?: Runtime): Promise<ExecutionResult> => {\n const startTime = Date.now();\n\n try {\n // Auto-detect runtime if not specified\n const effectiveRuntime = runtime || (\n // Strong Python indicators\n code.includes('print(') || \n code.includes('import ') ||\n code.includes('def ') ||\n code.includes('sys.') ||\n code.includes('json.') ||\n code.includes('__') ||\n code.includes('f\"') ||\n code.includes(\"f'\") ||\n code.includes('raise ')\n ? 'python'\n // Default to Node.js for all other cases (including ambiguous)\n : 'node'\n );\n \n // Use direct command execution like Vercel for consistency\n let response;\n \n // Use base64 encoding for both runtimes for reliability and consistency\n const encoded = Buffer.from(code).toString('base64');\n \n if (effectiveRuntime === 'python') {\n response = await sandbox.process.executeCommand(`echo \"${encoded}\" | base64 -d | python3`);\n } else {\n response = await sandbox.process.executeCommand(`echo \"${encoded}\" | base64 -d | node`);\n }\n\n // Daytona always returns exitCode: 0, so we need to detect errors from output\n const output = response.result || '';\n const hasError = output.includes('Error:') || \n output.includes('error TS') || \n output.includes('SyntaxError:') ||\n output.includes('TypeError:') ||\n output.includes('ReferenceError:') ||\n output.includes('Traceback (most recent call last)');\n\n // Check for syntax errors and throw them (similar to Vercel behavior)\n if (hasError && (output.includes('SyntaxError:') || \n output.includes('invalid syntax') ||\n output.includes('Unexpected token') ||\n output.includes('Unexpected identifier') ||\n output.includes('error TS1434'))) {\n throw new Error(`Syntax error: ${output.trim()}`);\n }\n\n const actualExitCode = hasError ? 1 : (response.exitCode || 0);\n\n return {\n stdout: hasError ? '' : output,\n stderr: hasError ? output : '',\n exitCode: actualExitCode,\n executionTime: Date.now() - startTime,\n sandboxId: sandbox.id,\n provider: 'daytona'\n };\n } catch (error) {\n // Re-throw syntax errors\n if (error instanceof Error && error.message.includes('Syntax error')) {\n throw error;\n }\n throw new Error(\n `Daytona execution failed: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n },\n\n runCommand: async (sandbox: DaytonaSandbox, command: string, args: string[] = [], options?: RunCommandOptions): Promise<ExecutionResult> => {\n const startTime = Date.now();\n\n try {\n // Handle background command execution\n const { command: finalCommand, args: finalArgs, isBackground } = createBackgroundCommand(command, args, options);\n\n // Construct full command with arguments, properly quoting each arg\n const quotedArgs = finalArgs.map(arg => {\n // Quote arguments that contain spaces or special characters\n if (arg.includes(' ') || arg.includes('\"') || arg.includes(\"'\") || arg.includes('$') || arg.includes('`')) {\n // Escape any double quotes in the argument and wrap in double quotes\n return `\"${arg.replace(/\"/g, '\\\\\"')}\"`;\n }\n return arg;\n });\n const fullCommand = quotedArgs.length > 0 ? `${finalCommand} ${quotedArgs.join(' ')}` : finalCommand;\n\n // Execute command using Daytona's process.executeCommand method\n const response = await sandbox.process.executeCommand(fullCommand);\n\n return {\n stdout: response.result || '',\n stderr: '', // Daytona doesn't separate stderr in the response\n exitCode: response.exitCode || 0,\n executionTime: Date.now() - startTime,\n sandboxId: sandbox.id,\n provider: 'daytona',\n isBackground,\n // For background commands, we can't get a real PID, but we can indicate it's running\n ...(isBackground && { pid: -1 })\n };\n } catch (error) {\n throw new Error(\n `Daytona command execution failed: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n },\n\n getInfo: async (sandbox: DaytonaSandbox): Promise<SandboxInfo> => {\n return {\n id: sandbox.id,\n provider: 'daytona',\n runtime: 'python', // Daytona default\n status: 'running',\n createdAt: new Date(),\n timeout: 300000,\n metadata: {\n daytonaSandboxId: sandbox.id\n }\n };\n },\n\n getUrl: async (sandbox: DaytonaSandbox, options: { port: number; protocol?: string }): Promise<string> => {\n try {\n // Use Daytona's built-in getPreviewLink method\n const previewInfo = await sandbox.getPreviewLink(options.port);\n let url = previewInfo.url;\n \n // If a specific protocol is requested, replace the URL's protocol\n if (options.protocol) {\n const urlObj = new URL(url);\n urlObj.protocol = options.protocol + ':';\n url = urlObj.toString();\n }\n \n return url;\n } catch (error) {\n throw new Error(\n `Failed to get Daytona preview URL for port ${options.port}: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n },\n\n // Filesystem operations via terminal commands\n filesystem: {\n readFile: async (sandbox: DaytonaSandbox, path: string): Promise<string> => {\n try {\n const response = await sandbox.process.executeCommand(`cat \"${path}\"`);\n if (response.exitCode !== 0) {\n throw new Error(`File not found or cannot be read: ${path}`);\n }\n return response.result || '';\n } catch (error) {\n throw new Error(`Failed to read file ${path}: ${error instanceof Error ? error.message : String(error)}`);\n }\n },\n\n writeFile: async (sandbox: DaytonaSandbox, path: string, content: string): Promise<void> => {\n try {\n // Use base64 encoding to safely handle special characters, newlines, and binary content\n const encoded = Buffer.from(content).toString('base64');\n const response = await sandbox.process.executeCommand(`echo \"${encoded}\" | base64 -d > \"${path}\"`);\n if (response.exitCode !== 0) {\n throw new Error(`Failed to write to file: ${path}`);\n }\n } catch (error) {\n throw new Error(`Failed to write file ${path}: ${error instanceof Error ? error.message : String(error)}`);\n }\n },\n\n mkdir: async (sandbox: DaytonaSandbox, path: string): Promise<void> => {\n try {\n const response = await sandbox.process.executeCommand(`mkdir -p \"${path}\"`);\n if (response.exitCode !== 0) {\n throw new Error(`Failed to create directory: ${path}`);\n }\n } catch (error) {\n throw new Error(`Failed to create directory ${path}: ${error instanceof Error ? error.message : String(error)}`);\n }\n },\n\n readdir: async (sandbox: DaytonaSandbox, path: string): Promise<FileEntry[]> => {\n try {\n const response = await sandbox.process.executeCommand(`ls -la \"${path}\"`);\n if (response.exitCode !== 0) {\n throw new Error(`Directory not found or cannot be read: ${path}`);\n }\n\n // Parse ls -la output into FileEntry objects\n const lines = response.result.split('\\n').filter(line => line.trim());\n const entries: FileEntry[] = [];\n\n for (const line of lines) {\n // Skip total line and current/parent directory entries\n if (line.startsWith('total ') || line.endsWith(' .') || line.endsWith(' ..')) {\n continue;\n }\n\n // Parse ls -la format: permissions links owner group size date time name\n const parts = line.trim().split(/\\s+/);\n if (parts.length >= 9) {\n const permissions = parts[0];\n const name = parts.slice(8).join(' '); // Handle filenames with spaces\n const isDirectory = permissions.startsWith('d');\n const size = parseInt(parts[4]) || 0;\n\n entries.push({\n name,\n path: `${path}/${name}`.replace(/\\/+/g, '/'), // Clean up double slashes\n isDirectory,\n size,\n lastModified: new Date() // ls -la date parsing is complex, use current time\n });\n }\n }\n\n return entries;\n } catch (error) {\n throw new Error(`Failed to read directory ${path}: ${error instanceof Error ? error.message : String(error)}`);\n }\n },\n\n exists: async (sandbox: DaytonaSandbox, path: string): Promise<boolean> => {\n try {\n const response = await sandbox.process.executeCommand(`test -e \"${path}\"`);\n return response.exitCode === 0;\n } catch (error) {\n // If command execution fails, assume file doesn't exist\n return false;\n }\n },\n\n remove: async (sandbox: DaytonaSandbox, path: string): Promise<void> => {\n try {\n const response = await sandbox.process.executeCommand(`rm -rf \"${path}\"`);\n if (response.exitCode !== 0) {\n throw new Error(`Failed to remove: ${path}`);\n }\n } catch (error) {\n throw new Error(`Failed to remove ${path}: ${error instanceof Error ? error.message : String(error)}`);\n }\n }\n },\n\n // Provider-specific typed getInstance method\n getInstance: (sandbox: DaytonaSandbox): DaytonaSandbox => {\n return sandbox;\n },\n\n // Terminal operations not implemented - Daytona session API needs verification\n\n }\n }\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,iBAAmD;AACnD,wBAAwD;AAkBjD,IAAM,cAAU,kCAA8C;AAAA,EACnE,MAAM;AAAA,EACN,SAAS;AAAA,IACP,SAAS;AAAA;AAAA,MAEP,QAAQ,OAAO,QAAuB,YAAmC;AAEvE,cAAM,SAAS,OAAO,UAAW,OAAO,YAAY,eAAe,QAAQ,KAAK,mBAAoB;AAEpG,YAAI,CAAC,QAAQ;AACX,gBAAM,IAAI;AAAA,YACR;AAAA,UACF;AAAA,QACF;AAEA,cAAM,UAAU,SAAS,WAAW,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ACF,kBAAM,WAAW,MAAM,QAAQ,QAAQ,eAAe,WAAW,IAAI,GAAG;AACxE,gBAAI,SAAS,aAAa,GAAG;AAC3B,oBAAM,IAAI,MAAM,qBAAqB,IAAI,EAAE;AAAA,YAC7C;AAAA,UACF,SAAS,OAAO;AACd,kBAAM,IAAI,MAAM,oBAAoB,IAAI,KAAK,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC,EAAE;AAAA,UACvG;AAAA,QACF;AAAA,MACF;AAAA;AAAA,MAGA,aAAa,CAAC,YAA4C;AACxD,eAAO;AAAA,MACT;AAAA;AAAA,IAIF;AAAA,EACF;AACF,CAAC;","names":["daytona"]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * Daytona Provider - Factory-based Implementation\n * \n * Code execution only provider using the factory pattern.\n * Reduces ~300 lines of boilerplate to ~80 lines of core logic.\n */\n\nimport { Daytona, Sandbox as DaytonaSandbox } from '@daytonaio/sdk';\nimport { createProvider } from 'computesdk';\nimport type { Runtime, CodeResult, CommandResult, SandboxInfo, CreateSandboxOptions, FileEntry } from 'computesdk';\n\n/**\n * Daytona-specific configuration options\n */\nexport interface DaytonaConfig {\n /** Daytona API key - if not provided, will fallback to DAYTONA_API_KEY environment variable */\n apiKey?: string;\n /** Default runtime environment */\n runtime?: Runtime;\n /** Execution timeout in milliseconds */\n timeout?: number;\n}\n\n/**\n * Create a Daytona provider instance using the factory pattern\n */\nexport const daytona = createProvider<DaytonaSandbox, DaytonaConfig>({\n name: 'daytona',\n defaultMode: 'direct',\n methods: {\n sandbox: {\n // Collection operations (compute.sandbox.*)\n create: async (config: DaytonaConfig, options?: CreateSandboxOptions) => {\n // Validate API key\n const apiKey = config.apiKey || (typeof process !== 'undefined' && process.env?.DAYTONA_API_KEY) || '';\n\n if (!apiKey) {\n throw new Error(\n `Missing Daytona API key. Provide 'apiKey' in config or set DAYTONA_API_KEY environment variable. Get your API key from https://daytona.io/`\n );\n }\n\n const runtime = options?.runtime || config.runtime || 'node';\n\n try {\n // Initialize Daytona client\n const daytona = new Daytona({ apiKey: apiKey });\n\n let session: DaytonaSandbox;\n let sandboxId: string;\n\n if (options?.sandboxId) {\n // Reconnect to existing Daytona sandbox\n session = await daytona.get(options.sandboxId);\n sandboxId = options.sandboxId;\n } else {\n // Create new Daytona sandbox\n session = await daytona.create({\n language: runtime === 'python' ? 'python' : 'javascript',\n });\n sandboxId = session.id;\n }\n\n return {\n sandbox: session,\n sandboxId\n };\n } catch (error) {\n if (error instanceof Error) {\n if (error.message.includes('unauthorized') || error.message.includes('API key')) {\n throw new Error(\n `Daytona authentication failed. Please check your DAYTONA_API_KEY environment variable. Get your API key from https://daytona.io/`\n );\n }\n if (error.message.includes('quota') || error.message.includes('limit')) {\n throw new Error(\n `Daytona quota exceeded. Please check your usage at https://daytona.io/`\n );\n }\n }\n throw new Error(\n `Failed to create Daytona sandbox: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n },\n\n getById: async (config: DaytonaConfig, sandboxId: string) => {\n const apiKey = config.apiKey || process.env.DAYTONA_API_KEY!;\n\n try {\n const daytona = new Daytona({ apiKey: apiKey });\n const session = await daytona.get(sandboxId);\n\n return {\n sandbox: session,\n sandboxId\n };\n } catch (error) {\n // Sandbox doesn't exist or can't be accessed\n return null;\n }\n },\n\n list: async (config: DaytonaConfig) => {\n const apiKey = config.apiKey || process.env.DAYTONA_API_KEY!;\n\n try {\n const daytona = new Daytona({ apiKey: apiKey });\n const sandboxes = await daytona.list();\n\n return sandboxes.map((session: any) => ({\n sandbox: session,\n sandboxId: session.id\n }));\n } catch (error) {\n // Return empty array if listing fails\n return [];\n }\n },\n\n destroy: async (config: DaytonaConfig, sandboxId: string) => {\n const apiKey = config.apiKey || process.env.DAYTONA_API_KEY!;\n\n try {\n const daytona = new Daytona({ apiKey: apiKey });\n // Note: Daytona SDK expects a Sandbox object, but we only have the ID\n // This is a limitation of the current Daytona SDK design\n // For now, we'll skip the delete operation\n const sandbox = await daytona.get(sandboxId);\n await sandbox.delete();\n } catch (error) {\n // Sandbox might already be destroyed or doesn't exist\n // This is acceptable for destroy operations\n }\n },\n\n // Instance operations (sandbox.*)\n runCode: async (sandbox: DaytonaSandbox, code: string, runtime?: Runtime): Promise<CodeResult> => {\n const startTime = Date.now();\n\n try {\n // Auto-detect runtime if not specified\n const effectiveRuntime = runtime || (\n // Strong Python indicators\n code.includes('print(') || \n code.includes('import ') ||\n code.includes('def ') ||\n code.includes('sys.') ||\n code.includes('json.') ||\n code.includes('__') ||\n code.includes('f\"') ||\n code.includes(\"f'\") ||\n code.includes('raise ')\n ? 'python'\n // Default to Node.js for all other cases (including ambiguous)\n : 'node'\n );\n \n // Use direct command execution like Vercel for consistency\n let response;\n \n // Use base64 encoding for both runtimes for reliability and consistency\n const encoded = Buffer.from(code).toString('base64');\n \n if (effectiveRuntime === 'python') {\n response = await sandbox.process.executeCommand(`echo \"${encoded}\" | base64 -d | python3`);\n } else {\n response = await sandbox.process.executeCommand(`echo \"${encoded}\" | base64 -d | node`);\n }\n\n // Daytona always returns exitCode: 0, so we need to detect errors from output\n const output = response.result || '';\n const hasError = output.includes('Error:') || \n output.includes('error TS') || \n output.includes('SyntaxError:') ||\n output.includes('TypeError:') ||\n output.includes('ReferenceError:') ||\n output.includes('Traceback (most recent call last)');\n\n // Check for syntax errors and throw them (similar to Vercel behavior)\n if (hasError && (output.includes('SyntaxError:') || \n output.includes('invalid syntax') ||\n output.includes('Unexpected token') ||\n output.includes('Unexpected identifier') ||\n output.includes('error TS1434'))) {\n throw new Error(`Syntax error: ${output.trim()}`);\n }\n\n const actualExitCode = hasError ? 1 : (response.exitCode || 0);\n\n return {\n output: output,\n exitCode: actualExitCode,\n language: effectiveRuntime\n };\n } catch (error) {\n // Re-throw syntax errors\n if (error instanceof Error && error.message.includes('Syntax error')) {\n throw error;\n }\n throw new Error(\n `Daytona execution failed: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n },\n\n runCommand: async (sandbox: DaytonaSandbox, command: string, args: string[] = []): Promise<CommandResult> => {\n const startTime = Date.now();\n\n try {\n // Construct full command with arguments, properly quoting each arg\n const quotedArgs = args.map((arg: string) => {\n if (arg.includes(' ') || arg.includes('\"') || arg.includes(\"'\") || arg.includes('$') || arg.includes('`')) {\n return `\"${arg.replace(/\"/g, '\\\\\"')}\"`;\n }\n return arg;\n });\n const fullCommand = quotedArgs.length > 0 ? `${command} ${quotedArgs.join(' ')}` : command;\n\n // Execute command using Daytona's process.executeCommand method\n const response = await sandbox.process.executeCommand(fullCommand);\n\n return {\n stdout: response.result || '',\n stderr: '',\n exitCode: response.exitCode || 0,\n durationMs: Date.now() - startTime\n };\n } catch (error) {\n throw new Error(\n `Daytona command execution failed: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n },\n\n getInfo: async (sandbox: DaytonaSandbox): Promise<SandboxInfo> => {\n return {\n id: sandbox.id,\n provider: 'daytona',\n runtime: 'python', // Daytona default\n status: 'running',\n createdAt: new Date(),\n timeout: 300000,\n metadata: {\n daytonaSandboxId: sandbox.id\n }\n };\n },\n\n getUrl: async (sandbox: DaytonaSandbox, options: { port: number; protocol?: string }): Promise<string> => {\n try {\n // Use Daytona's built-in getPreviewLink method\n const previewInfo = await sandbox.getPreviewLink(options.port);\n let url = previewInfo.url;\n \n // If a specific protocol is requested, replace the URL's protocol\n if (options.protocol) {\n const urlObj = new URL(url);\n urlObj.protocol = options.protocol + ':';\n url = urlObj.toString();\n }\n \n return url;\n } catch (error) {\n throw new Error(\n `Failed to get Daytona preview URL for port ${options.port}: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n },\n\n // Filesystem operations via terminal commands\n filesystem: {\n readFile: async (sandbox: DaytonaSandbox, path: string): Promise<string> => {\n try {\n const response = await sandbox.process.executeCommand(`cat \"${path}\"`);\n if (response.exitCode !== 0) {\n throw new Error(`File not found or cannot be read: ${path}`);\n }\n return response.result || '';\n } catch (error) {\n throw new Error(`Failed to read file ${path}: ${error instanceof Error ? error.message : String(error)}`);\n }\n },\n\n writeFile: async (sandbox: DaytonaSandbox, path: string, content: string): Promise<void> => {\n try {\n // Use base64 encoding to safely handle special characters, newlines, and binary content\n const encoded = Buffer.from(content).toString('base64');\n const response = await sandbox.process.executeCommand(`echo \"${encoded}\" | base64 -d > \"${path}\"`);\n if (response.exitCode !== 0) {\n throw new Error(`Failed to write to file: ${path}`);\n }\n } catch (error) {\n throw new Error(`Failed to write file ${path}: ${error instanceof Error ? error.message : String(error)}`);\n }\n },\n\n mkdir: async (sandbox: DaytonaSandbox, path: string): Promise<void> => {\n try {\n const response = await sandbox.process.executeCommand(`mkdir -p \"${path}\"`);\n if (response.exitCode !== 0) {\n throw new Error(`Failed to create directory: ${path}`);\n }\n } catch (error) {\n throw new Error(`Failed to create directory ${path}: ${error instanceof Error ? error.message : String(error)}`);\n }\n },\n\n readdir: async (sandbox: DaytonaSandbox, path: string): Promise<FileEntry[]> => {\n try {\n const response = await sandbox.process.executeCommand(`ls -la \"${path}\"`);\n if (response.exitCode !== 0) {\n throw new Error(`Directory not found or cannot be read: ${path}`);\n }\n\n // Parse ls -la output into FileEntry objects\n const lines = response.result.split('\\n').filter(line => line.trim());\n const entries: FileEntry[] = [];\n\n for (const line of lines) {\n // Skip total line and current/parent directory entries\n if (line.startsWith('total ') || line.endsWith(' .') || line.endsWith(' ..')) {\n continue;\n }\n\n // Parse ls -la format: permissions links owner group size date time name\n const parts = line.trim().split(/\\s+/);\n if (parts.length >= 9) {\n const permissions = parts[0];\n const name = parts.slice(8).join(' '); // Handle filenames with spaces\n const isDirectory = permissions.startsWith('d');\n const size = parseInt(parts[4]) || 0;\n\n entries.push({\n name,\n path: `${path}/${name}`.replace(/\\/+/g, '/'), // Clean up double slashes\n isDirectory,\n size,\n lastModified: new Date() // ls -la date parsing is complex, use current time\n });\n }\n }\n\n return entries;\n } catch (error) {\n throw new Error(`Failed to read directory ${path}: ${error instanceof Error ? error.message : String(error)}`);\n }\n },\n\n exists: async (sandbox: DaytonaSandbox, path: string): Promise<boolean> => {\n try {\n const response = await sandbox.process.executeCommand(`test -e \"${path}\"`);\n return response.exitCode === 0;\n } catch (error) {\n // If command execution fails, assume file doesn't exist\n return false;\n }\n },\n\n remove: async (sandbox: DaytonaSandbox, path: string): Promise<void> => {\n try {\n const response = await sandbox.process.executeCommand(`rm -rf \"${path}\"`);\n if (response.exitCode !== 0) {\n throw new Error(`Failed to remove: ${path}`);\n }\n } catch (error) {\n throw new Error(`Failed to remove ${path}: ${error instanceof Error ? error.message : String(error)}`);\n }\n }\n },\n\n // Provider-specific typed getInstance method\n getInstance: (sandbox: DaytonaSandbox): DaytonaSandbox => {\n return sandbox;\n },\n\n // Terminal operations not implemented - Daytona session API needs verification\n\n }\n }\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,iBAAmD;AACnD,wBAA+B;AAkBxB,IAAM,cAAU,kCAA8C;AAAA,EACnE,MAAM;AAAA,EACN,aAAa;AAAA,EACb,SAAS;AAAA,IACP,SAAS;AAAA;AAAA,MAEP,QAAQ,OAAO,QAAuB,YAAmC;AAEvE,cAAM,SAAS,OAAO,UAAW,OAAO,YAAY,eAAe,QAAQ,KAAK,mBAAoB;AAEpG,YAAI,CAAC,QAAQ;AACX,gBAAM,IAAI;AAAA,YACR;AAAA,UACF;AAAA,QACF;AAEA,cAAM,UAAU,SAAS,WAAW,OAAO,WAAW;AAEtD,YAAI;AAEF,gBAAMA,WAAU,IAAI,mBAAQ,EAAE,OAAe,CAAC;AAE9C,cAAI;AACJ,cAAI;AAEJ,cAAI,SAAS,WAAW;AAEtB,sBAAU,MAAMA,SAAQ,IAAI,QAAQ,SAAS;AAC7C,wBAAY,QAAQ;AAAA,UACtB,OAAO;AAEL,sBAAU,MAAMA,SAAQ,OAAO;AAAA,cAC7B,UAAU,YAAY,WAAW,WAAW;AAAA,YAC9C,CAAC;AACD,wBAAY,QAAQ;AAAA,UACtB;AAEA,iBAAO;AAAA,YACL,SAAS;AAA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AAI,GAAG,QAAQ,QAAQ,GAAG;AAAA;AAAA,kBAC3C;AAAA,kBACA;AAAA,kBACA,cAAc,oBAAI,KAAK;AAAA;AAAA,gBACzB,CAAC;AAAA,cACH;AAAA,YACF;AAEA,mBAAO;AAAA,UACT,SAAS,OAAO;AACd,kBAAM,IAAI,MAAM,4BAA4B,IAAI,KAAK,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC,EAAE;AAAA,UAC/G;AAAA,QACF;AAAA,QAEA,QAAQ,OAAO,SAAyB,SAAmC;AACzE,cAAI;AACF,kBAAM,WAAW,MAAM,QAAQ,QAAQ,eAAe,YAAY,IAAI,GAAG;AACzE,mBAAO,SAAS,aAAa;AAAA,UAC/B,SAAS,OAAO;AAEd,mBAAO;AAAA,UACT;AAAA,QACF;AAAA,QAEA,QAAQ,OAAO,SAAyB,SAAgC;AACtE,cAAI;AACF,kBAAM,WAAW,MAAM,QAAQ,QAAQ,eAAe,WAAW,IAAI,GAAG;AACxE,gBAAI,SAAS,aAAa,GAAG;AAC3B,oBAAM,IAAI,MAAM,qBAAqB,IAAI,EAAE;AAAA,YAC7C;AAAA,UACF,SAAS,OAAO;AACd,kBAAM,IAAI,MAAM,oBAAoB,IAAI,KAAK,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC,EAAE;AAAA,UACvG;AAAA,QACF;AAAA,MACF;AAAA;AAAA,MAGA,aAAa,CAAC,YAA4C;AACxD,eAAO;AAAA,MACT;AAAA;AAAA,IAIF;AAAA,EACF;AACF,CAAC;","names":["daytona"]}
package/dist/index.mjs CHANGED
@@ -1,8 +1,9 @@
1
1
  // src/index.ts
2
2
  import { Daytona } from "@daytonaio/sdk";
3
- import { createProvider, createBackgroundCommand } from "computesdk";
3
+ import { createProvider } from "computesdk";
4
4
  var daytona = createProvider({
5
5
  name: "daytona",
6
+ defaultMode: "direct",
6
7
  methods: {
7
8
  sandbox: {
8
9
  // Collection operations (compute.sandbox.*)
@@ -104,12 +105,9 @@ var daytona = createProvider({
104
105
  }
105
106
  const actualExitCode = hasError ? 1 : response.exitCode || 0;
106
107
  return {
107
- stdout: hasError ? "" : output,
108
- stderr: hasError ? output : "",
108
+ output,
109
109
  exitCode: actualExitCode,
110
- executionTime: Date.now() - startTime,
111
- sandboxId: sandbox.id,
112
- provider: "daytona"
110
+ language: effectiveRuntime
113
111
  };
114
112
  } catch (error) {
115
113
  if (error instanceof Error && error.message.includes("Syntax error")) {
@@ -120,29 +118,22 @@ var daytona = createProvider({
120
118
  );
121
119
  }
122
120
  },
123
- runCommand: async (sandbox, command, args = [], options) => {
121
+ runCommand: async (sandbox, command, args = []) => {
124
122
  const startTime = Date.now();
125
123
  try {
126
- const { command: finalCommand, args: finalArgs, isBackground } = createBackgroundCommand(command, args, options);
127
- const quotedArgs = finalArgs.map((arg) => {
124
+ const quotedArgs = args.map((arg) => {
128
125
  if (arg.includes(" ") || arg.includes('"') || arg.includes("'") || arg.includes("$") || arg.includes("`")) {
129
126
  return `"${arg.replace(/"/g, '\\"')}"`;
130
127
  }
131
128
  return arg;
132
129
  });
133
- const fullCommand = quotedArgs.length > 0 ? `${finalCommand} ${quotedArgs.join(" ")}` : finalCommand;
130
+ const fullCommand = quotedArgs.length > 0 ? `${command} ${quotedArgs.join(" ")}` : command;
134
131
  const response = await sandbox.process.executeCommand(fullCommand);
135
132
  return {
136
133
  stdout: response.result || "",
137
134
  stderr: "",
138
- // Daytona doesn't separate stderr in the response
139
135
  exitCode: response.exitCode || 0,
140
- executionTime: Date.now() - startTime,
141
- sandboxId: sandbox.id,
142
- provider: "daytona",
143
- isBackground,
144
- // For background commands, we can't get a real PID, but we can indicate it's running
145
- ...isBackground && { pid: -1 }
136
+ durationMs: Date.now() - startTime
146
137
  };
147
138
  } catch (error) {
148
139
  throw new Error(
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * Daytona Provider - Factory-based Implementation\n * \n * Code execution only provider using the factory pattern.\n * Reduces ~300 lines of boilerplate to ~80 lines of core logic.\n */\n\nimport { Daytona, Sandbox as DaytonaSandbox } from '@daytonaio/sdk';\nimport { createProvider, createBackgroundCommand } from 'computesdk';\nimport type { Runtime, ExecutionResult, SandboxInfo, CreateSandboxOptions, FileEntry, RunCommandOptions } from 'computesdk';\n\n/**\n * Daytona-specific configuration options\n */\nexport interface DaytonaConfig {\n /** Daytona API key - if not provided, will fallback to DAYTONA_API_KEY environment variable */\n apiKey?: string;\n /** Default runtime environment */\n runtime?: Runtime;\n /** Execution timeout in milliseconds */\n timeout?: number;\n}\n\n/**\n * Create a Daytona provider instance using the factory pattern\n */\nexport const daytona = createProvider<DaytonaSandbox, DaytonaConfig>({\n name: 'daytona',\n methods: {\n sandbox: {\n // Collection operations (compute.sandbox.*)\n create: async (config: DaytonaConfig, options?: CreateSandboxOptions) => {\n // Validate API key\n const apiKey = config.apiKey || (typeof process !== 'undefined' && process.env?.DAYTONA_API_KEY) || '';\n\n if (!apiKey) {\n throw new Error(\n `Missing Daytona API key. Provide 'apiKey' in config or set DAYTONA_API_KEY environment variable. Get your API key from https://daytona.io/`\n );\n }\n\n const runtime = options?.runtime || config.runtime || 'node';\n\n try {\n // Initialize Daytona client\n const daytona = new Daytona({ apiKey: apiKey });\n\n let session: DaytonaSandbox;\n let sandboxId: string;\n\n if (options?.sandboxId) {\n // Reconnect to existing Daytona sandbox\n session = await daytona.get(options.sandboxId);\n sandboxId = options.sandboxId;\n } else {\n // Create new Daytona sandbox\n session = await daytona.create({\n language: runtime === 'python' ? 'python' : 'javascript',\n });\n sandboxId = session.id;\n }\n\n return {\n sandbox: session,\n sandboxId\n };\n } catch (error) {\n if (error instanceof Error) {\n if (error.message.includes('unauthorized') || error.message.includes('API key')) {\n throw new Error(\n `Daytona authentication failed. Please check your DAYTONA_API_KEY environment variable. Get your API key from https://daytona.io/`\n );\n }\n if (error.message.includes('quota') || error.message.includes('limit')) {\n throw new Error(\n `Daytona quota exceeded. Please check your usage at https://daytona.io/`\n );\n }\n }\n throw new Error(\n `Failed to create Daytona sandbox: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n },\n\n getById: async (config: DaytonaConfig, sandboxId: string) => {\n const apiKey = config.apiKey || process.env.DAYTONA_API_KEY!;\n\n try {\n const daytona = new Daytona({ apiKey: apiKey });\n const session = await daytona.get(sandboxId);\n\n return {\n sandbox: session,\n sandboxId\n };\n } catch (error) {\n // Sandbox doesn't exist or can't be accessed\n return null;\n }\n },\n\n list: async (config: DaytonaConfig) => {\n const apiKey = config.apiKey || process.env.DAYTONA_API_KEY!;\n\n try {\n const daytona = new Daytona({ apiKey: apiKey });\n const sandboxes = await daytona.list();\n\n return sandboxes.map((session: any) => ({\n sandbox: session,\n sandboxId: session.id\n }));\n } catch (error) {\n // Return empty array if listing fails\n return [];\n }\n },\n\n destroy: async (config: DaytonaConfig, sandboxId: string) => {\n const apiKey = config.apiKey || process.env.DAYTONA_API_KEY!;\n\n try {\n const daytona = new Daytona({ apiKey: apiKey });\n // Note: Daytona SDK expects a Sandbox object, but we only have the ID\n // This is a limitation of the current Daytona SDK design\n // For now, we'll skip the delete operation\n const sandbox = await daytona.get(sandboxId);\n await sandbox.delete();\n } catch (error) {\n // Sandbox might already be destroyed or doesn't exist\n // This is acceptable for destroy operations\n }\n },\n\n // Instance operations (sandbox.*)\n runCode: async (sandbox: DaytonaSandbox, code: string, runtime?: Runtime): Promise<ExecutionResult> => {\n const startTime = Date.now();\n\n try {\n // Auto-detect runtime if not specified\n const effectiveRuntime = runtime || (\n // Strong Python indicators\n code.includes('print(') || \n code.includes('import ') ||\n code.includes('def ') ||\n code.includes('sys.') ||\n code.includes('json.') ||\n code.includes('__') ||\n code.includes('f\"') ||\n code.includes(\"f'\") ||\n code.includes('raise ')\n ? 'python'\n // Default to Node.js for all other cases (including ambiguous)\n : 'node'\n );\n \n // Use direct command execution like Vercel for consistency\n let response;\n \n // Use base64 encoding for both runtimes for reliability and consistency\n const encoded = Buffer.from(code).toString('base64');\n \n if (effectiveRuntime === 'python') {\n response = await sandbox.process.executeCommand(`echo \"${encoded}\" | base64 -d | python3`);\n } else {\n response = await sandbox.process.executeCommand(`echo \"${encoded}\" | base64 -d | node`);\n }\n\n // Daytona always returns exitCode: 0, so we need to detect errors from output\n const output = response.result || '';\n const hasError = output.includes('Error:') || \n output.includes('error TS') || \n output.includes('SyntaxError:') ||\n output.includes('TypeError:') ||\n output.includes('ReferenceError:') ||\n output.includes('Traceback (most recent call last)');\n\n // Check for syntax errors and throw them (similar to Vercel behavior)\n if (hasError && (output.includes('SyntaxError:') || \n output.includes('invalid syntax') ||\n output.includes('Unexpected token') ||\n output.includes('Unexpected identifier') ||\n output.includes('error TS1434'))) {\n throw new Error(`Syntax error: ${output.trim()}`);\n }\n\n const actualExitCode = hasError ? 1 : (response.exitCode || 0);\n\n return {\n stdout: hasError ? '' : output,\n stderr: hasError ? output : '',\n exitCode: actualExitCode,\n executionTime: Date.now() - startTime,\n sandboxId: sandbox.id,\n provider: 'daytona'\n };\n } catch (error) {\n // Re-throw syntax errors\n if (error instanceof Error && error.message.includes('Syntax error')) {\n throw error;\n }\n throw new Error(\n `Daytona execution failed: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n },\n\n runCommand: async (sandbox: DaytonaSandbox, command: string, args: string[] = [], options?: RunCommandOptions): Promise<ExecutionResult> => {\n const startTime = Date.now();\n\n try {\n // Handle background command execution\n const { command: finalCommand, args: finalArgs, isBackground } = createBackgroundCommand(command, args, options);\n\n // Construct full command with arguments, properly quoting each arg\n const quotedArgs = finalArgs.map(arg => {\n // Quote arguments that contain spaces or special characters\n if (arg.includes(' ') || arg.includes('\"') || arg.includes(\"'\") || arg.includes('$') || arg.includes('`')) {\n // Escape any double quotes in the argument and wrap in double quotes\n return `\"${arg.replace(/\"/g, '\\\\\"')}\"`;\n }\n return arg;\n });\n const fullCommand = quotedArgs.length > 0 ? `${finalCommand} ${quotedArgs.join(' ')}` : finalCommand;\n\n // Execute command using Daytona's process.executeCommand method\n const response = await sandbox.process.executeCommand(fullCommand);\n\n return {\n stdout: response.result || '',\n stderr: '', // Daytona doesn't separate stderr in the response\n exitCode: response.exitCode || 0,\n executionTime: Date.now() - startTime,\n sandboxId: sandbox.id,\n provider: 'daytona',\n isBackground,\n // For background commands, we can't get a real PID, but we can indicate it's running\n ...(isBackground && { pid: -1 })\n };\n } catch (error) {\n throw new Error(\n `Daytona command execution failed: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n },\n\n getInfo: async (sandbox: DaytonaSandbox): Promise<SandboxInfo> => {\n return {\n id: sandbox.id,\n provider: 'daytona',\n runtime: 'python', // Daytona default\n status: 'running',\n createdAt: new Date(),\n timeout: 300000,\n metadata: {\n daytonaSandboxId: sandbox.id\n }\n };\n },\n\n getUrl: async (sandbox: DaytonaSandbox, options: { port: number; protocol?: string }): Promise<string> => {\n try {\n // Use Daytona's built-in getPreviewLink method\n const previewInfo = await sandbox.getPreviewLink(options.port);\n let url = previewInfo.url;\n \n // If a specific protocol is requested, replace the URL's protocol\n if (options.protocol) {\n const urlObj = new URL(url);\n urlObj.protocol = options.protocol + ':';\n url = urlObj.toString();\n }\n \n return url;\n } catch (error) {\n throw new Error(\n `Failed to get Daytona preview URL for port ${options.port}: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n },\n\n // Filesystem operations via terminal commands\n filesystem: {\n readFile: async (sandbox: DaytonaSandbox, path: string): Promise<string> => {\n try {\n const response = await sandbox.process.executeCommand(`cat \"${path}\"`);\n if (response.exitCode !== 0) {\n throw new Error(`File not found or cannot be read: ${path}`);\n }\n return response.result || '';\n } catch (error) {\n throw new Error(`Failed to read file ${path}: ${error instanceof Error ? error.message : String(error)}`);\n }\n },\n\n writeFile: async (sandbox: DaytonaSandbox, path: string, content: string): Promise<void> => {\n try {\n // Use base64 encoding to safely handle special characters, newlines, and binary content\n const encoded = Buffer.from(content).toString('base64');\n const response = await sandbox.process.executeCommand(`echo \"${encoded}\" | base64 -d > \"${path}\"`);\n if (response.exitCode !== 0) {\n throw new Error(`Failed to write to file: ${path}`);\n }\n } catch (error) {\n throw new Error(`Failed to write file ${path}: ${error instanceof Error ? error.message : String(error)}`);\n }\n },\n\n mkdir: async (sandbox: DaytonaSandbox, path: string): Promise<void> => {\n try {\n const response = await sandbox.process.executeCommand(`mkdir -p \"${path}\"`);\n if (response.exitCode !== 0) {\n throw new Error(`Failed to create directory: ${path}`);\n }\n } catch (error) {\n throw new Error(`Failed to create directory ${path}: ${error instanceof Error ? error.message : String(error)}`);\n }\n },\n\n readdir: async (sandbox: DaytonaSandbox, path: string): Promise<FileEntry[]> => {\n try {\n const response = await sandbox.process.executeCommand(`ls -la \"${path}\"`);\n if (response.exitCode !== 0) {\n throw new Error(`Directory not found or cannot be read: ${path}`);\n }\n\n // Parse ls -la output into FileEntry objects\n const lines = response.result.split('\\n').filter(line => line.trim());\n const entries: FileEntry[] = [];\n\n for (const line of lines) {\n // Skip total line and current/parent directory entries\n if (line.startsWith('total ') || line.endsWith(' .') || line.endsWith(' ..')) {\n continue;\n }\n\n // Parse ls -la format: permissions links owner group size date time name\n const parts = line.trim().split(/\\s+/);\n if (parts.length >= 9) {\n const permissions = parts[0];\n const name = parts.slice(8).join(' '); // Handle filenames with spaces\n const isDirectory = permissions.startsWith('d');\n const size = parseInt(parts[4]) || 0;\n\n entries.push({\n name,\n path: `${path}/${name}`.replace(/\\/+/g, '/'), // Clean up double slashes\n isDirectory,\n size,\n lastModified: new Date() // ls -la date parsing is complex, use current time\n });\n }\n }\n\n return entries;\n } catch (error) {\n throw new Error(`Failed to read directory ${path}: ${error instanceof Error ? error.message : String(error)}`);\n }\n },\n\n exists: async (sandbox: DaytonaSandbox, path: string): Promise<boolean> => {\n try {\n const response = await sandbox.process.executeCommand(`test -e \"${path}\"`);\n return response.exitCode === 0;\n } catch (error) {\n // If command execution fails, assume file doesn't exist\n return false;\n }\n },\n\n remove: async (sandbox: DaytonaSandbox, path: string): Promise<void> => {\n try {\n const response = await sandbox.process.executeCommand(`rm -rf \"${path}\"`);\n if (response.exitCode !== 0) {\n throw new Error(`Failed to remove: ${path}`);\n }\n } catch (error) {\n throw new Error(`Failed to remove ${path}: ${error instanceof Error ? error.message : String(error)}`);\n }\n }\n },\n\n // Provider-specific typed getInstance method\n getInstance: (sandbox: DaytonaSandbox): DaytonaSandbox => {\n return sandbox;\n },\n\n // Terminal operations not implemented - Daytona session API needs verification\n\n }\n }\n});\n"],"mappings":";AAOA,SAAS,eAA0C;AACnD,SAAS,gBAAgB,+BAA+B;AAkBjD,IAAM,UAAU,eAA8C;AAAA,EACnE,MAAM;AAAA,EACN,SAAS;AAAA,IACP,SAAS;AAAA;AAAA,MAEP,QAAQ,OAAO,QAAuB,YAAmC;AAEvE,cAAM,SAAS,OAAO,UAAW,OAAO,YAAY,eAAe,QAAQ,KAAK,mBAAoB;AAEpG,YAAI,CAAC,QAAQ;AACX,gBAAM,IAAI;AAAA,YACR;AAAA,UACF;AAAA,QACF;AAEA,cAAM,UAAU,SAAS,WAAW,OAAO,WAAW;AAEtD,YAAI;AAEF,gBAAMA,WAAU,IAAI,QAAQ,EAAE,OAAe,CAAC;AAE9C,cAAI;AACJ,cAAI;AAEJ,cAAI,SAAS,WAAW;AAEtB,sBAAU,MAAMA,SAAQ,IAAI,QAAQ,SAAS;AAC7C,wBAAY,QAAQ;AAAA,UACtB,OAAO;AAEL,sBAAU,MAAMA,SAAQ,OAAO;AAAA,cAC7B,UAAU,YAAY,WAAW,WAAW;AAAA,YAC9C,CAAC;AACD,wBAAY,QAAQ;AAAA,UACtB;AAEA,iBAAO;AAAA,YACL,SAAS;AAAA,YACT;AAAA,UACF;AAAA,QACF,SAAS,OAAO;AACd,cAAI,iBAAiB,OAAO;AAC1B,gBAAI,MAAM,QAAQ,SAAS,cAAc,KAAK,MAAM,QAAQ,SAAS,SAAS,GAAG;AAC/E,oBAAM,IAAI;AAAA,gBACR;AAAA,cACF;AAAA,YACF;AACA,gBAAI,MAAM,QAAQ,SAAS,OAAO,KAAK,MA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BAAQ,KAAK;AAAA,kBACX;AAAA,kBACA,MAAM,GAAG,IAAI,IAAI,IAAI,GAAG,QAAQ,QAAQ,GAAG;AAAA;AAAA,kBAC3C;AAAA,kBACA;AAAA,kBACA,cAAc,oBAAI,KAAK;AAAA;AAAA,gBACzB,CAAC;AAAA,cACH;AAAA,YACF;AAEA,mBAAO;AAAA,UACT,SAAS,OAAO;AACd,kBAAM,IAAI,MAAM,4BAA4B,IAAI,KAAK,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC,EAAE;AAAA,UAC/G;AAAA,QACF;AAAA,QAEA,QAAQ,OAAO,SAAyB,SAAmC;AACzE,cAAI;AACF,kBAAM,WAAW,MAAM,QAAQ,QAAQ,eAAe,YAAY,IAAI,GAAG;AACzE,mBAAO,SAAS,aAAa;AAAA,UAC/B,SAAS,OAAO;AAEd,mBAAO;AAAA,UACT;AAAA,QACF;AAAA,QAEA,QAAQ,OAAO,SAAyB,SAAgC;AACtE,cAAI;AACF,kBAAM,WAAW,MAAM,QAAQ,QAAQ,eAAe,WAAW,IAAI,GAAG;AACxE,gBAAI,SAAS,aAAa,GAAG;AAC3B,oBAAM,IAAI,MAAM,qBAAqB,IAAI,EAAE;AAAA,YAC7C;AAAA,UACF,SAAS,OAAO;AACd,kBAAM,IAAI,MAAM,oBAAoB,IAAI,KAAK,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC,EAAE;AAAA,UACvG;AAAA,QACF;AAAA,MACF;AAAA;AAAA,MAGA,aAAa,CAAC,YAA4C;AACxD,eAAO;AAAA,MACT;AAAA;AAAA,IAIF;AAAA,EACF;AACF,CAAC;","names":["daytona"]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * Daytona Provider - Factory-based Implementation\n * \n * Code execution only provider using the factory pattern.\n * Reduces ~300 lines of boilerplate to ~80 lines of core logic.\n */\n\nimport { Daytona, Sandbox as DaytonaSandbox } from '@daytonaio/sdk';\nimport { createProvider } from 'computesdk';\nimport type { Runtime, CodeResult, CommandResult, SandboxInfo, CreateSandboxOptions, FileEntry } from 'computesdk';\n\n/**\n * Daytona-specific configuration options\n */\nexport interface DaytonaConfig {\n /** Daytona API key - if not provided, will fallback to DAYTONA_API_KEY environment variable */\n apiKey?: string;\n /** Default runtime environment */\n runtime?: Runtime;\n /** Execution timeout in milliseconds */\n timeout?: number;\n}\n\n/**\n * Create a Daytona provider instance using the factory pattern\n */\nexport const daytona = createProvider<DaytonaSandbox, DaytonaConfig>({\n name: 'daytona',\n defaultMode: 'direct',\n methods: {\n sandbox: {\n // Collection operations (compute.sandbox.*)\n create: async (config: DaytonaConfig, options?: CreateSandboxOptions) => {\n // Validate API key\n const apiKey = config.apiKey || (typeof process !== 'undefined' && process.env?.DAYTONA_API_KEY) || '';\n\n if (!apiKey) {\n throw new Error(\n `Missing Daytona API key. Provide 'apiKey' in config or set DAYTONA_API_KEY environment variable. Get your API key from https://daytona.io/`\n );\n }\n\n const runtime = options?.runtime || config.runtime || 'node';\n\n try {\n // Initialize Daytona client\n const daytona = new Daytona({ apiKey: apiKey });\n\n let session: DaytonaSandbox;\n let sandboxId: string;\n\n if (options?.sandboxId) {\n // Reconnect to existing Daytona sandbox\n session = await daytona.get(options.sandboxId);\n sandboxId = options.sandboxId;\n } else {\n // Create new Daytona sandbox\n session = await daytona.create({\n language: runtime === 'python' ? 'python' : 'javascript',\n });\n sandboxId = session.id;\n }\n\n return {\n sandbox: session,\n sandboxId\n };\n } catch (error) {\n if (error instanceof Error) {\n if (error.message.includes('unauthorized') || error.message.includes('API key')) {\n throw new Error(\n `Daytona authentication failed. Please check your DAYTONA_API_KEY environment variable. Get your API key from https://daytona.io/`\n );\n }\n if (error.message.includes('quota') || error.message.includes('limit')) {\n throw new Error(\n `Daytona quota exceeded. Please check your usage at https://daytona.io/`\n );\n }\n }\n throw new Error(\n `Failed to create Daytona sandbox: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n },\n\n getById: async (config: DaytonaConfig, sandboxId: string) => {\n const apiKey = config.apiKey || process.env.DAYTONA_API_KEY!;\n\n try {\n const daytona = new Daytona({ apiKey: apiKey });\n const session = await daytona.get(sandboxId);\n\n return {\n sandbox: session,\n sandboxId\n };\n } catch (error) {\n // Sandbox doesn't exist or can't be accessed\n return null;\n }\n },\n\n list: async (config: DaytonaConfig) => {\n const apiKey = config.apiKey || process.env.DAYTONA_API_KEY!;\n\n try {\n const daytona = new Daytona({ apiKey: apiKey });\n const sandboxes = await daytona.list();\n\n return sandboxes.map((session: any) => ({\n sandbox: session,\n sandboxId: session.id\n }));\n } catch (error) {\n // Return empty array if listing fails\n return [];\n }\n },\n\n destroy: async (config: DaytonaConfig, sandboxId: string) => {\n const apiKey = config.apiKey || process.env.DAYTONA_API_KEY!;\n\n try {\n const daytona = new Daytona({ apiKey: apiKey });\n // Note: Daytona SDK expects a Sandbox object, but we only have the ID\n // This is a limitation of the current Daytona SDK design\n // For now, we'll skip the delete operation\n const sandbox = await daytona.get(sandboxId);\n await sandbox.delete();\n } catch (error) {\n // Sandbox might already be destroyed or doesn't exist\n // This is acceptable for destroy operations\n }\n },\n\n // Instance operations (sandbox.*)\n runCode: async (sandbox: DaytonaSandbox, code: string, runtime?: Runtime): Promise<CodeResult> => {\n const startTime = Date.now();\n\n try {\n // Auto-detect runtime if not specified\n const effectiveRuntime = runtime || (\n // Strong Python indicators\n code.includes('print(') || \n code.includes('import ') ||\n code.includes('def ') ||\n code.includes('sys.') ||\n code.includes('json.') ||\n code.includes('__') ||\n code.includes('f\"') ||\n code.includes(\"f'\") ||\n code.includes('raise ')\n ? 'python'\n // Default to Node.js for all other cases (including ambiguous)\n : 'node'\n );\n \n // Use direct command execution like Vercel for consistency\n let response;\n \n // Use base64 encoding for both runtimes for reliability and consistency\n const encoded = Buffer.from(code).toString('base64');\n \n if (effectiveRuntime === 'python') {\n response = await sandbox.process.executeCommand(`echo \"${encoded}\" | base64 -d | python3`);\n } else {\n response = await sandbox.process.executeCommand(`echo \"${encoded}\" | base64 -d | node`);\n }\n\n // Daytona always returns exitCode: 0, so we need to detect errors from output\n const output = response.result || '';\n const hasError = output.includes('Error:') || \n output.includes('error TS') || \n output.includes('SyntaxError:') ||\n output.includes('TypeError:') ||\n output.includes('ReferenceError:') ||\n output.includes('Traceback (most recent call last)');\n\n // Check for syntax errors and throw them (similar to Vercel behavior)\n if (hasError && (output.includes('SyntaxError:') || \n output.includes('invalid syntax') ||\n output.includes('Unexpected token') ||\n output.includes('Unexpected identifier') ||\n output.includes('error TS1434'))) {\n throw new Error(`Syntax error: ${output.trim()}`);\n }\n\n const actualExitCode = hasError ? 1 : (response.exitCode || 0);\n\n return {\n output: output,\n exitCode: actualExitCode,\n language: effectiveRuntime\n };\n } catch (error) {\n // Re-throw syntax errors\n if (error instanceof Error && error.message.includes('Syntax error')) {\n throw error;\n }\n throw new Error(\n `Daytona execution failed: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n },\n\n runCommand: async (sandbox: DaytonaSandbox, command: string, args: string[] = []): Promise<CommandResult> => {\n const startTime = Date.now();\n\n try {\n // Construct full command with arguments, properly quoting each arg\n const quotedArgs = args.map((arg: string) => {\n if (arg.includes(' ') || arg.includes('\"') || arg.includes(\"'\") || arg.includes('$') || arg.includes('`')) {\n return `\"${arg.replace(/\"/g, '\\\\\"')}\"`;\n }\n return arg;\n });\n const fullCommand = quotedArgs.length > 0 ? `${command} ${quotedArgs.join(' ')}` : command;\n\n // Execute command using Daytona's process.executeCommand method\n const response = await sandbox.process.executeCommand(fullCommand);\n\n return {\n stdout: response.result || '',\n stderr: '',\n exitCode: response.exitCode || 0,\n durationMs: Date.now() - startTime\n };\n } catch (error) {\n throw new Error(\n `Daytona command execution failed: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n },\n\n getInfo: async (sandbox: DaytonaSandbox): Promise<SandboxInfo> => {\n return {\n id: sandbox.id,\n provider: 'daytona',\n runtime: 'python', // Daytona default\n status: 'running',\n createdAt: new Date(),\n timeout: 300000,\n metadata: {\n daytonaSandboxId: sandbox.id\n }\n };\n },\n\n getUrl: async (sandbox: DaytonaSandbox, options: { port: number; protocol?: string }): Promise<string> => {\n try {\n // Use Daytona's built-in getPreviewLink method\n const previewInfo = await sandbox.getPreviewLink(options.port);\n let url = previewInfo.url;\n \n // If a specific protocol is requested, replace the URL's protocol\n if (options.protocol) {\n const urlObj = new URL(url);\n urlObj.protocol = options.protocol + ':';\n url = urlObj.toString();\n }\n \n return url;\n } catch (error) {\n throw new Error(\n `Failed to get Daytona preview URL for port ${options.port}: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n },\n\n // Filesystem operations via terminal commands\n filesystem: {\n readFile: async (sandbox: DaytonaSandbox, path: string): Promise<string> => {\n try {\n const response = await sandbox.process.executeCommand(`cat \"${path}\"`);\n if (response.exitCode !== 0) {\n throw new Error(`File not found or cannot be read: ${path}`);\n }\n return response.result || '';\n } catch (error) {\n throw new Error(`Failed to read file ${path}: ${error instanceof Error ? error.message : String(error)}`);\n }\n },\n\n writeFile: async (sandbox: DaytonaSandbox, path: string, content: string): Promise<void> => {\n try {\n // Use base64 encoding to safely handle special characters, newlines, and binary content\n const encoded = Buffer.from(content).toString('base64');\n const response = await sandbox.process.executeCommand(`echo \"${encoded}\" | base64 -d > \"${path}\"`);\n if (response.exitCode !== 0) {\n throw new Error(`Failed to write to file: ${path}`);\n }\n } catch (error) {\n throw new Error(`Failed to write file ${path}: ${error instanceof Error ? error.message : String(error)}`);\n }\n },\n\n mkdir: async (sandbox: DaytonaSandbox, path: string): Promise<void> => {\n try {\n const response = await sandbox.process.executeCommand(`mkdir -p \"${path}\"`);\n if (response.exitCode !== 0) {\n throw new Error(`Failed to create directory: ${path}`);\n }\n } catch (error) {\n throw new Error(`Failed to create directory ${path}: ${error instanceof Error ? error.message : String(error)}`);\n }\n },\n\n readdir: async (sandbox: DaytonaSandbox, path: string): Promise<FileEntry[]> => {\n try {\n const response = await sandbox.process.executeCommand(`ls -la \"${path}\"`);\n if (response.exitCode !== 0) {\n throw new Error(`Directory not found or cannot be read: ${path}`);\n }\n\n // Parse ls -la output into FileEntry objects\n const lines = response.result.split('\\n').filter(line => line.trim());\n const entries: FileEntry[] = [];\n\n for (const line of lines) {\n // Skip total line and current/parent directory entries\n if (line.startsWith('total ') || line.endsWith(' .') || line.endsWith(' ..')) {\n continue;\n }\n\n // Parse ls -la format: permissions links owner group size date time name\n const parts = line.trim().split(/\\s+/);\n if (parts.length >= 9) {\n const permissions = parts[0];\n const name = parts.slice(8).join(' '); // Handle filenames with spaces\n const isDirectory = permissions.startsWith('d');\n const size = parseInt(parts[4]) || 0;\n\n entries.push({\n name,\n path: `${path}/${name}`.replace(/\\/+/g, '/'), // Clean up double slashes\n isDirectory,\n size,\n lastModified: new Date() // ls -la date parsing is complex, use current time\n });\n }\n }\n\n return entries;\n } catch (error) {\n throw new Error(`Failed to read directory ${path}: ${error instanceof Error ? error.message : String(error)}`);\n }\n },\n\n exists: async (sandbox: DaytonaSandbox, path: string): Promise<boolean> => {\n try {\n const response = await sandbox.process.executeCommand(`test -e \"${path}\"`);\n return response.exitCode === 0;\n } catch (error) {\n // If command execution fails, assume file doesn't exist\n return false;\n }\n },\n\n remove: async (sandbox: DaytonaSandbox, path: string): Promise<void> => {\n try {\n const response = await sandbox.process.executeCommand(`rm -rf \"${path}\"`);\n if (response.exitCode !== 0) {\n throw new Error(`Failed to remove: ${path}`);\n }\n } catch (error) {\n throw new Error(`Failed to remove ${path}: ${error instanceof Error ? error.message : String(error)}`);\n }\n }\n },\n\n // Provider-specific typed getInstance method\n getInstance: (sandbox: DaytonaSandbox): DaytonaSandbox => {\n return sandbox;\n },\n\n // Terminal operations not implemented - Daytona session API needs verification\n\n }\n }\n});\n"],"mappings":";AAOA,SAAS,eAA0C;AACnD,SAAS,sBAAsB;AAkBxB,IAAM,UAAU,eAA8C;AAAA,EACnE,MAAM;AAAA,EACN,aAAa;AAAA,EACb,SAAS;AAAA,IACP,SAAS;AAAA;AAAA,MAEP,QAAQ,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AM,qBAAqB,IAAI,EAAE;AAAA,YAC7C;AAAA,UACF,SAAS,OAAO;AACd,kBAAM,IAAI,MAAM,oBAAoB,IAAI,KAAK,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC,EAAE;AAAA,UACvG;AAAA,QACF;AAAA,MACF;AAAA;AAAA,MAGA,aAAa,CAAC,YAA4C;AACxD,eAAO;AAAA,MACT;AAAA;AAAA,IAIF;AAAA,EACF;AACF,CAAC;","names":["daytona"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@computesdk/daytona",
3
- "version": "1.5.7",
3
+ "version": "1.6.0",
4
4
  "description": "Daytona provider for ComputeSDK",
5
5
  "author": "Garrison",
6
6
  "license": "MIT",
@@ -19,7 +19,7 @@
19
19
  ],
20
20
  "dependencies": {
21
21
  "@daytonaio/sdk": "^0.25.0",
22
- "computesdk": "1.8.7"
22
+ "computesdk": "1.9.0"
23
23
  },
24
24
  "keywords": [
25
25
  "daytona",