computesdk 1.10.3 → 1.11.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
@@ -40,8 +40,11 @@ For more control, use `setConfig()` to explicitly configure the provider:
40
40
  import { compute } from 'computesdk';
41
41
 
42
42
  compute.setConfig({
43
- provider: 'e2b',
44
- e2b: { apiKey: 'your_api_key' }
43
+ provider: 'your-provider',
44
+ apiKey: process.env.COMPUTESDK_API_KEY,
45
+ 'your-provider': {
46
+ apiKey: process.env.YOUR_PROVIDER_API_KEY
47
+ }
45
48
  });
46
49
 
47
50
  const sandbox = await compute.sandbox.create();
@@ -84,8 +87,11 @@ Configure the gateway with explicit provider settings.
84
87
 
85
88
  ```typescript
86
89
  compute.setConfig({
87
- provider: 'e2b',
88
- e2b: { apiKey: 'your_api_key' }
90
+ provider: 'your-provider',
91
+ apiKey: process.env.COMPUTESDK_API_KEY,
92
+ 'your-provider': {
93
+ apiKey: process.env.YOUR_PROVIDER_API_KEY
94
+ }
89
95
  });
90
96
  ```
91
97
 
@@ -95,6 +101,7 @@ compute.setConfig({
95
101
  // E2B
96
102
  compute.setConfig({
97
103
  provider: 'e2b',
104
+ apiKey: process.env.COMPUTESDK_API_KEY,
98
105
  e2b: {
99
106
  apiKey: 'e2b_xxx',
100
107
  templateId: 'optional_template'
@@ -104,6 +111,7 @@ compute.setConfig({
104
111
  // Modal
105
112
  compute.setConfig({
106
113
  provider: 'modal',
114
+ apiKey: process.env.COMPUTESDK_API_KEY,
107
115
  modal: {
108
116
  tokenId: 'ak-xxx',
109
117
  tokenSecret: 'as-xxx'
@@ -113,6 +121,7 @@ compute.setConfig({
113
121
  // Railway
114
122
  compute.setConfig({
115
123
  provider: 'railway',
124
+ apiKey: process.env.COMPUTESDK_API_KEY,
116
125
  railway: {
117
126
  apiToken: 'your_token',
118
127
  projectId: 'project_id',
@@ -123,12 +132,14 @@ compute.setConfig({
123
132
  // Daytona
124
133
  compute.setConfig({
125
134
  provider: 'daytona',
135
+ apiKey: process.env.COMPUTESDK_API_KEY,
126
136
  daytona: { apiKey: 'your_api_key' }
127
137
  });
128
138
 
129
139
  // Vercel
130
140
  compute.setConfig({
131
141
  provider: 'vercel',
142
+ apiKey: process.env.COMPUTESDK_API_KEY,
132
143
  vercel: {
133
144
  token: 'your_token',
134
145
  teamId: 'team_xxx',
package/dist/index.d.mts CHANGED
@@ -250,6 +250,42 @@ interface TerminalErrorMessage {
250
250
  error: string;
251
251
  };
252
252
  }
253
+ /**
254
+ * Command stdout streaming message (exec mode with stream: true)
255
+ */
256
+ interface CommandStdoutMessage {
257
+ type: 'command:stdout';
258
+ channel: string;
259
+ data: {
260
+ terminal_id: string;
261
+ cmd_id: string;
262
+ output: string;
263
+ };
264
+ }
265
+ /**
266
+ * Command stderr streaming message (exec mode with stream: true)
267
+ */
268
+ interface CommandStderrMessage {
269
+ type: 'command:stderr';
270
+ channel: string;
271
+ data: {
272
+ terminal_id: string;
273
+ cmd_id: string;
274
+ output: string;
275
+ };
276
+ }
277
+ /**
278
+ * Command exit message (exec mode with stream: true)
279
+ */
280
+ interface CommandExitMessage {
281
+ type: 'command:exit';
282
+ channel: string;
283
+ data: {
284
+ terminal_id: string;
285
+ cmd_id: string;
286
+ exit_code: number;
287
+ };
288
+ }
253
289
  /**
254
290
  * File watcher created notification
255
291
  */
@@ -427,6 +463,12 @@ declare class WebSocketManager {
427
463
  * Resize terminal window
428
464
  */
429
465
  resizeTerminal(terminalId: string, cols: number, rows: number): void;
466
+ /**
467
+ * Start a pending streaming command
468
+ * Used in two-phase streaming flow: HTTP request creates pending command,
469
+ * then this signal triggers execution after client has subscribed.
470
+ */
471
+ startCommand(cmdId: string): void;
430
472
  /**
431
473
  * Register event handler
432
474
  */
@@ -438,6 +480,9 @@ declare class WebSocketManager {
438
480
  on(event: 'terminal:output', handler: MessageHandler<TerminalOutputMessage>): void;
439
481
  on(event: 'terminal:destroyed', handler: MessageHandler<TerminalDestroyedMessage>): void;
440
482
  on(event: 'terminal:error', handler: MessageHandler<TerminalErrorMessage>): void;
483
+ on(event: 'command:stdout', handler: MessageHandler<CommandStdoutMessage>): void;
484
+ on(event: 'command:stderr', handler: MessageHandler<CommandStderrMessage>): void;
485
+ on(event: 'command:exit', handler: MessageHandler<CommandExitMessage>): void;
441
486
  on(event: 'watcher:created', handler: MessageHandler<WatcherCreatedMessage>): void;
442
487
  on(event: 'file:changed', handler: MessageHandler<FileChangedMessage>): void;
443
488
  on(event: 'watcher:destroyed', handler: MessageHandler<WatcherDestroyedMessage>): void;
@@ -1957,6 +2002,13 @@ interface SandboxConfig {
1957
2002
  protocol?: 'json' | 'binary';
1958
2003
  /** Optional metadata associated with the sandbox */
1959
2004
  metadata?: Record<string, unknown>;
2005
+ /**
2006
+ * Handler called when destroy() is invoked.
2007
+ * If provided, this is called to destroy the sandbox (e.g., via gateway API).
2008
+ * If not provided, destroy() only disconnects the WebSocket.
2009
+ * @internal
2010
+ */
2011
+ destroyHandler?: () => Promise<void>;
1960
2012
  }
1961
2013
  /**
1962
2014
  * Health check response
@@ -2076,7 +2128,7 @@ interface FileResponse {
2076
2128
  };
2077
2129
  }
2078
2130
  /**
2079
- * Command execution response
2131
+ * Command execution response (used by both /run/command and /terminals/{id}/execute)
2080
2132
  */
2081
2133
  interface CommandExecutionResponse {
2082
2134
  message: string;
@@ -2084,12 +2136,12 @@ interface CommandExecutionResponse {
2084
2136
  terminal_id?: string;
2085
2137
  cmd_id?: string;
2086
2138
  command: string;
2087
- output?: string;
2088
2139
  stdout: string;
2089
2140
  stderr: string;
2090
2141
  exit_code?: number;
2091
2142
  duration_ms?: number;
2092
2143
  status?: 'running' | 'completed' | 'failed';
2144
+ channel?: string;
2093
2145
  pty?: boolean;
2094
2146
  };
2095
2147
  }
@@ -2142,22 +2194,6 @@ interface CodeExecutionResponse {
2142
2194
  language: string;
2143
2195
  };
2144
2196
  }
2145
- /**
2146
- * Run command response (POST /run/command)
2147
- */
2148
- interface RunCommandResponse {
2149
- message: string;
2150
- data: {
2151
- terminal_id?: string;
2152
- cmd_id?: string;
2153
- command: string;
2154
- stdout: string;
2155
- stderr: string;
2156
- exit_code?: number;
2157
- duration_ms?: number;
2158
- status?: 'running' | 'completed' | 'failed';
2159
- };
2160
- }
2161
2197
  /**
2162
2198
  * File watcher information
2163
2199
  */
@@ -2629,9 +2665,10 @@ declare class Sandbox {
2629
2665
  command: string;
2630
2666
  shell?: string;
2631
2667
  background?: boolean;
2668
+ stream?: boolean;
2632
2669
  cwd?: string;
2633
2670
  env?: Record<string, string>;
2634
- }): Promise<RunCommandResponse>;
2671
+ }): Promise<CommandExecutionResponse>;
2635
2672
  /**
2636
2673
  * List files at the specified path
2637
2674
  */
@@ -2644,6 +2681,11 @@ declare class Sandbox {
2644
2681
  * Get file metadata (without content)
2645
2682
  */
2646
2683
  getFile(path: string): Promise<FileResponse>;
2684
+ /**
2685
+ * Encode a file path for use in URLs
2686
+ * Strips leading slash and encodes each segment separately to preserve path structure
2687
+ */
2688
+ private encodeFilePath;
2647
2689
  /**
2648
2690
  * Read file content
2649
2691
  */
@@ -2916,6 +2958,8 @@ declare class Sandbox {
2916
2958
  * @param options.background - Run in background (server uses goroutines)
2917
2959
  * @param options.cwd - Working directory (server uses cmd.Dir)
2918
2960
  * @param options.env - Environment variables (server uses cmd.Env)
2961
+ * @param options.onStdout - Callback for streaming stdout data
2962
+ * @param options.onStderr - Callback for streaming stderr data
2919
2963
  * @returns Command execution result
2920
2964
  *
2921
2965
  * @example
@@ -2931,12 +2975,20 @@ declare class Sandbox {
2931
2975
  * background: true,
2932
2976
  * env: { PORT: '3000' }
2933
2977
  * })
2978
+ *
2979
+ * // With streaming output
2980
+ * await sandbox.runCommand('npm install', {
2981
+ * onStdout: (data) => console.log(data),
2982
+ * onStderr: (data) => console.error(data),
2983
+ * })
2934
2984
  * ```
2935
2985
  */
2936
2986
  runCommand(command: string, options?: {
2937
2987
  background?: boolean;
2938
2988
  cwd?: string;
2939
2989
  env?: Record<string, string>;
2990
+ onStdout?: (data: string) => void;
2991
+ onStderr?: (data: string) => void;
2940
2992
  }): Promise<{
2941
2993
  stdout: string;
2942
2994
  stderr: string;
@@ -2979,6 +3031,9 @@ declare class Sandbox {
2979
3031
  getInstance(): this;
2980
3032
  /**
2981
3033
  * Destroy the sandbox (Sandbox interface method)
3034
+ *
3035
+ * If a destroyHandler was provided (e.g., from gateway), calls it to destroy
3036
+ * the sandbox on the backend. Otherwise, only disconnects the WebSocket.
2982
3037
  */
2983
3038
  destroy(): Promise<void>;
2984
3039
  /**
@@ -3076,8 +3131,13 @@ declare function getMissingEnvVars(provider: ProviderName): string[];
3076
3131
  interface ExplicitComputeConfig {
3077
3132
  /** Provider name to use */
3078
3133
  provider: ProviderName;
3134
+ /**
3135
+ * ComputeSDK API key (required for gateway mode)
3136
+ * @deprecated Use `computesdkApiKey` for clarity
3137
+ */
3138
+ apiKey?: string;
3079
3139
  /** ComputeSDK API key (required for gateway mode) */
3080
- apiKey: string;
3140
+ computesdkApiKey?: string;
3081
3141
  /** Optional gateway URL override */
3082
3142
  gatewayUrl?: string;
3083
3143
  /** Provider-specific configurations */
package/dist/index.d.ts CHANGED
@@ -250,6 +250,42 @@ interface TerminalErrorMessage {
250
250
  error: string;
251
251
  };
252
252
  }
253
+ /**
254
+ * Command stdout streaming message (exec mode with stream: true)
255
+ */
256
+ interface CommandStdoutMessage {
257
+ type: 'command:stdout';
258
+ channel: string;
259
+ data: {
260
+ terminal_id: string;
261
+ cmd_id: string;
262
+ output: string;
263
+ };
264
+ }
265
+ /**
266
+ * Command stderr streaming message (exec mode with stream: true)
267
+ */
268
+ interface CommandStderrMessage {
269
+ type: 'command:stderr';
270
+ channel: string;
271
+ data: {
272
+ terminal_id: string;
273
+ cmd_id: string;
274
+ output: string;
275
+ };
276
+ }
277
+ /**
278
+ * Command exit message (exec mode with stream: true)
279
+ */
280
+ interface CommandExitMessage {
281
+ type: 'command:exit';
282
+ channel: string;
283
+ data: {
284
+ terminal_id: string;
285
+ cmd_id: string;
286
+ exit_code: number;
287
+ };
288
+ }
253
289
  /**
254
290
  * File watcher created notification
255
291
  */
@@ -427,6 +463,12 @@ declare class WebSocketManager {
427
463
  * Resize terminal window
428
464
  */
429
465
  resizeTerminal(terminalId: string, cols: number, rows: number): void;
466
+ /**
467
+ * Start a pending streaming command
468
+ * Used in two-phase streaming flow: HTTP request creates pending command,
469
+ * then this signal triggers execution after client has subscribed.
470
+ */
471
+ startCommand(cmdId: string): void;
430
472
  /**
431
473
  * Register event handler
432
474
  */
@@ -438,6 +480,9 @@ declare class WebSocketManager {
438
480
  on(event: 'terminal:output', handler: MessageHandler<TerminalOutputMessage>): void;
439
481
  on(event: 'terminal:destroyed', handler: MessageHandler<TerminalDestroyedMessage>): void;
440
482
  on(event: 'terminal:error', handler: MessageHandler<TerminalErrorMessage>): void;
483
+ on(event: 'command:stdout', handler: MessageHandler<CommandStdoutMessage>): void;
484
+ on(event: 'command:stderr', handler: MessageHandler<CommandStderrMessage>): void;
485
+ on(event: 'command:exit', handler: MessageHandler<CommandExitMessage>): void;
441
486
  on(event: 'watcher:created', handler: MessageHandler<WatcherCreatedMessage>): void;
442
487
  on(event: 'file:changed', handler: MessageHandler<FileChangedMessage>): void;
443
488
  on(event: 'watcher:destroyed', handler: MessageHandler<WatcherDestroyedMessage>): void;
@@ -1957,6 +2002,13 @@ interface SandboxConfig {
1957
2002
  protocol?: 'json' | 'binary';
1958
2003
  /** Optional metadata associated with the sandbox */
1959
2004
  metadata?: Record<string, unknown>;
2005
+ /**
2006
+ * Handler called when destroy() is invoked.
2007
+ * If provided, this is called to destroy the sandbox (e.g., via gateway API).
2008
+ * If not provided, destroy() only disconnects the WebSocket.
2009
+ * @internal
2010
+ */
2011
+ destroyHandler?: () => Promise<void>;
1960
2012
  }
1961
2013
  /**
1962
2014
  * Health check response
@@ -2076,7 +2128,7 @@ interface FileResponse {
2076
2128
  };
2077
2129
  }
2078
2130
  /**
2079
- * Command execution response
2131
+ * Command execution response (used by both /run/command and /terminals/{id}/execute)
2080
2132
  */
2081
2133
  interface CommandExecutionResponse {
2082
2134
  message: string;
@@ -2084,12 +2136,12 @@ interface CommandExecutionResponse {
2084
2136
  terminal_id?: string;
2085
2137
  cmd_id?: string;
2086
2138
  command: string;
2087
- output?: string;
2088
2139
  stdout: string;
2089
2140
  stderr: string;
2090
2141
  exit_code?: number;
2091
2142
  duration_ms?: number;
2092
2143
  status?: 'running' | 'completed' | 'failed';
2144
+ channel?: string;
2093
2145
  pty?: boolean;
2094
2146
  };
2095
2147
  }
@@ -2142,22 +2194,6 @@ interface CodeExecutionResponse {
2142
2194
  language: string;
2143
2195
  };
2144
2196
  }
2145
- /**
2146
- * Run command response (POST /run/command)
2147
- */
2148
- interface RunCommandResponse {
2149
- message: string;
2150
- data: {
2151
- terminal_id?: string;
2152
- cmd_id?: string;
2153
- command: string;
2154
- stdout: string;
2155
- stderr: string;
2156
- exit_code?: number;
2157
- duration_ms?: number;
2158
- status?: 'running' | 'completed' | 'failed';
2159
- };
2160
- }
2161
2197
  /**
2162
2198
  * File watcher information
2163
2199
  */
@@ -2629,9 +2665,10 @@ declare class Sandbox {
2629
2665
  command: string;
2630
2666
  shell?: string;
2631
2667
  background?: boolean;
2668
+ stream?: boolean;
2632
2669
  cwd?: string;
2633
2670
  env?: Record<string, string>;
2634
- }): Promise<RunCommandResponse>;
2671
+ }): Promise<CommandExecutionResponse>;
2635
2672
  /**
2636
2673
  * List files at the specified path
2637
2674
  */
@@ -2644,6 +2681,11 @@ declare class Sandbox {
2644
2681
  * Get file metadata (without content)
2645
2682
  */
2646
2683
  getFile(path: string): Promise<FileResponse>;
2684
+ /**
2685
+ * Encode a file path for use in URLs
2686
+ * Strips leading slash and encodes each segment separately to preserve path structure
2687
+ */
2688
+ private encodeFilePath;
2647
2689
  /**
2648
2690
  * Read file content
2649
2691
  */
@@ -2916,6 +2958,8 @@ declare class Sandbox {
2916
2958
  * @param options.background - Run in background (server uses goroutines)
2917
2959
  * @param options.cwd - Working directory (server uses cmd.Dir)
2918
2960
  * @param options.env - Environment variables (server uses cmd.Env)
2961
+ * @param options.onStdout - Callback for streaming stdout data
2962
+ * @param options.onStderr - Callback for streaming stderr data
2919
2963
  * @returns Command execution result
2920
2964
  *
2921
2965
  * @example
@@ -2931,12 +2975,20 @@ declare class Sandbox {
2931
2975
  * background: true,
2932
2976
  * env: { PORT: '3000' }
2933
2977
  * })
2978
+ *
2979
+ * // With streaming output
2980
+ * await sandbox.runCommand('npm install', {
2981
+ * onStdout: (data) => console.log(data),
2982
+ * onStderr: (data) => console.error(data),
2983
+ * })
2934
2984
  * ```
2935
2985
  */
2936
2986
  runCommand(command: string, options?: {
2937
2987
  background?: boolean;
2938
2988
  cwd?: string;
2939
2989
  env?: Record<string, string>;
2990
+ onStdout?: (data: string) => void;
2991
+ onStderr?: (data: string) => void;
2940
2992
  }): Promise<{
2941
2993
  stdout: string;
2942
2994
  stderr: string;
@@ -2979,6 +3031,9 @@ declare class Sandbox {
2979
3031
  getInstance(): this;
2980
3032
  /**
2981
3033
  * Destroy the sandbox (Sandbox interface method)
3034
+ *
3035
+ * If a destroyHandler was provided (e.g., from gateway), calls it to destroy
3036
+ * the sandbox on the backend. Otherwise, only disconnects the WebSocket.
2982
3037
  */
2983
3038
  destroy(): Promise<void>;
2984
3039
  /**
@@ -3076,8 +3131,13 @@ declare function getMissingEnvVars(provider: ProviderName): string[];
3076
3131
  interface ExplicitComputeConfig {
3077
3132
  /** Provider name to use */
3078
3133
  provider: ProviderName;
3134
+ /**
3135
+ * ComputeSDK API key (required for gateway mode)
3136
+ * @deprecated Use `computesdkApiKey` for clarity
3137
+ */
3138
+ apiKey?: string;
3079
3139
  /** ComputeSDK API key (required for gateway mode) */
3080
- apiKey: string;
3140
+ computesdkApiKey?: string;
3081
3141
  /** Optional gateway URL override */
3082
3142
  gatewayUrl?: string;
3083
3143
  /** Provider-specific configurations */