computesdk 1.18.0 → 1.18.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1064,7 +1064,7 @@ declare class Terminal {
1064
1064
  pty?: boolean;
1065
1065
  }) => Promise<TerminalInstance>;
1066
1066
  list: () => Promise<TerminalResponse[]>;
1067
- retrieve: (id: string) => Promise<TerminalResponse>;
1067
+ retrieve: (id: string) => Promise<TerminalInstance>;
1068
1068
  destroy: (id: string) => Promise<void>;
1069
1069
  });
1070
1070
  /**
@@ -1089,9 +1089,9 @@ declare class Terminal {
1089
1089
  /**
1090
1090
  * Retrieve a specific terminal by ID
1091
1091
  * @param id - The terminal ID
1092
- * @returns Terminal response
1092
+ * @returns Terminal instance
1093
1093
  */
1094
- retrieve(id: string): Promise<TerminalResponse>;
1094
+ retrieve(id: string): Promise<TerminalInstance>;
1095
1095
  /**
1096
1096
  * Destroy a terminal by ID
1097
1097
  * @param id - The terminal ID
@@ -2040,6 +2040,12 @@ interface WaitForCompletionOptions {
2040
2040
  /** Backoff multiplier for exponential backoff (default: 1.5) */
2041
2041
  backoffFactor?: number;
2042
2042
  }
2043
+ /**
2044
+ * Strategy for creating an overlay
2045
+ * - 'copy': Full copy of all files (standard behavior)
2046
+ * - 'smart': Use symlinks for immutable packages (e.g. node_modules) for instant creation
2047
+ */
2048
+ type OverlayStrategy = 'copy' | 'smart';
2043
2049
  /**
2044
2050
  * Options for creating an overlay
2045
2051
  */
@@ -2050,6 +2056,8 @@ interface CreateOverlayOptions {
2050
2056
  target: string;
2051
2057
  /** Glob patterns to ignore (e.g., ["node_modules", "*.log"]) */
2052
2058
  ignore?: string[];
2059
+ /** Strategy to use (default: 'smart') */
2060
+ strategy?: OverlayStrategy;
2053
2061
  /** If true, wait for background copy to complete before returning (default: false) */
2054
2062
  waitForCompletion?: boolean | WaitForCompletionOptions;
2055
2063
  }
@@ -2078,6 +2086,8 @@ interface OverlayInfo {
2078
2086
  source: string;
2079
2087
  /** Relative path in sandbox */
2080
2088
  target: string;
2089
+ /** Strategy used for the overlay */
2090
+ strategy: OverlayStrategy;
2081
2091
  /** When the overlay was created */
2082
2092
  createdAt: string;
2083
2093
  /** Statistics about the overlay */
@@ -2094,6 +2104,7 @@ interface OverlayResponse {
2094
2104
  id: string;
2095
2105
  source: string;
2096
2106
  target: string;
2107
+ strategy?: string;
2097
2108
  created_at: string;
2098
2109
  stats: {
2099
2110
  copied_files: number;
@@ -2166,6 +2177,7 @@ declare class Overlay {
2166
2177
  * @param options.source - Absolute path to source directory
2167
2178
  * @param options.target - Relative path in sandbox
2168
2179
  * @param options.ignore - Glob patterns to ignore (e.g., ["node_modules", "*.log"])
2180
+ * @param options.strategy - Strategy to use ('copy' or 'smart')
2169
2181
  * @param options.waitForCompletion - If true or options object, wait for background copy to complete
2170
2182
  * @returns Overlay info with copy status
2171
2183
  */
@@ -2205,6 +2217,10 @@ declare class Overlay {
2205
2217
  * Convert API response to OverlayInfo
2206
2218
  */
2207
2219
  private toOverlayInfo;
2220
+ /**
2221
+ * Validate and return strategy, defaulting to 'copy' for unknown/missing values (legacy support)
2222
+ */
2223
+ private validateStrategy;
2208
2224
  /**
2209
2225
  * Validate and return copy status, defaulting to 'pending' for unknown values
2210
2226
  */
@@ -2925,11 +2941,16 @@ declare class Sandbox {
2925
2941
  private _token;
2926
2942
  private _ws;
2927
2943
  private WebSocketImpl;
2944
+ private _terminals;
2928
2945
  constructor(config: SandboxConfig);
2929
2946
  /**
2930
2947
  * Get or create internal WebSocket manager
2931
2948
  */
2932
2949
  private ensureWebSocket;
2950
+ /**
2951
+ * Create and configure a TerminalInstance from response data
2952
+ */
2953
+ private hydrateTerminal;
2933
2954
  private request;
2934
2955
  /**
2935
2956
  * Check service health
@@ -3231,7 +3252,7 @@ declare class Sandbox {
3231
3252
  /**
3232
3253
  * Get terminal by ID
3233
3254
  */
3234
- getTerminal(id: string): Promise<TerminalResponse>;
3255
+ getTerminal(id: string): Promise<TerminalInstance>;
3235
3256
  /**
3236
3257
  * List all commands executed in a terminal (exec mode only)
3237
3258
  * @param terminalId - The terminal ID
package/dist/index.d.ts CHANGED
@@ -1064,7 +1064,7 @@ declare class Terminal {
1064
1064
  pty?: boolean;
1065
1065
  }) => Promise<TerminalInstance>;
1066
1066
  list: () => Promise<TerminalResponse[]>;
1067
- retrieve: (id: string) => Promise<TerminalResponse>;
1067
+ retrieve: (id: string) => Promise<TerminalInstance>;
1068
1068
  destroy: (id: string) => Promise<void>;
1069
1069
  });
1070
1070
  /**
@@ -1089,9 +1089,9 @@ declare class Terminal {
1089
1089
  /**
1090
1090
  * Retrieve a specific terminal by ID
1091
1091
  * @param id - The terminal ID
1092
- * @returns Terminal response
1092
+ * @returns Terminal instance
1093
1093
  */
1094
- retrieve(id: string): Promise<TerminalResponse>;
1094
+ retrieve(id: string): Promise<TerminalInstance>;
1095
1095
  /**
1096
1096
  * Destroy a terminal by ID
1097
1097
  * @param id - The terminal ID
@@ -2040,6 +2040,12 @@ interface WaitForCompletionOptions {
2040
2040
  /** Backoff multiplier for exponential backoff (default: 1.5) */
2041
2041
  backoffFactor?: number;
2042
2042
  }
2043
+ /**
2044
+ * Strategy for creating an overlay
2045
+ * - 'copy': Full copy of all files (standard behavior)
2046
+ * - 'smart': Use symlinks for immutable packages (e.g. node_modules) for instant creation
2047
+ */
2048
+ type OverlayStrategy = 'copy' | 'smart';
2043
2049
  /**
2044
2050
  * Options for creating an overlay
2045
2051
  */
@@ -2050,6 +2056,8 @@ interface CreateOverlayOptions {
2050
2056
  target: string;
2051
2057
  /** Glob patterns to ignore (e.g., ["node_modules", "*.log"]) */
2052
2058
  ignore?: string[];
2059
+ /** Strategy to use (default: 'smart') */
2060
+ strategy?: OverlayStrategy;
2053
2061
  /** If true, wait for background copy to complete before returning (default: false) */
2054
2062
  waitForCompletion?: boolean | WaitForCompletionOptions;
2055
2063
  }
@@ -2078,6 +2086,8 @@ interface OverlayInfo {
2078
2086
  source: string;
2079
2087
  /** Relative path in sandbox */
2080
2088
  target: string;
2089
+ /** Strategy used for the overlay */
2090
+ strategy: OverlayStrategy;
2081
2091
  /** When the overlay was created */
2082
2092
  createdAt: string;
2083
2093
  /** Statistics about the overlay */
@@ -2094,6 +2104,7 @@ interface OverlayResponse {
2094
2104
  id: string;
2095
2105
  source: string;
2096
2106
  target: string;
2107
+ strategy?: string;
2097
2108
  created_at: string;
2098
2109
  stats: {
2099
2110
  copied_files: number;
@@ -2166,6 +2177,7 @@ declare class Overlay {
2166
2177
  * @param options.source - Absolute path to source directory
2167
2178
  * @param options.target - Relative path in sandbox
2168
2179
  * @param options.ignore - Glob patterns to ignore (e.g., ["node_modules", "*.log"])
2180
+ * @param options.strategy - Strategy to use ('copy' or 'smart')
2169
2181
  * @param options.waitForCompletion - If true or options object, wait for background copy to complete
2170
2182
  * @returns Overlay info with copy status
2171
2183
  */
@@ -2205,6 +2217,10 @@ declare class Overlay {
2205
2217
  * Convert API response to OverlayInfo
2206
2218
  */
2207
2219
  private toOverlayInfo;
2220
+ /**
2221
+ * Validate and return strategy, defaulting to 'copy' for unknown/missing values (legacy support)
2222
+ */
2223
+ private validateStrategy;
2208
2224
  /**
2209
2225
  * Validate and return copy status, defaulting to 'pending' for unknown values
2210
2226
  */
@@ -2925,11 +2941,16 @@ declare class Sandbox {
2925
2941
  private _token;
2926
2942
  private _ws;
2927
2943
  private WebSocketImpl;
2944
+ private _terminals;
2928
2945
  constructor(config: SandboxConfig);
2929
2946
  /**
2930
2947
  * Get or create internal WebSocket manager
2931
2948
  */
2932
2949
  private ensureWebSocket;
2950
+ /**
2951
+ * Create and configure a TerminalInstance from response data
2952
+ */
2953
+ private hydrateTerminal;
2933
2954
  private request;
2934
2955
  /**
2935
2956
  * Check service health
@@ -3231,7 +3252,7 @@ declare class Sandbox {
3231
3252
  /**
3232
3253
  * Get terminal by ID
3233
3254
  */
3234
- getTerminal(id: string): Promise<TerminalResponse>;
3255
+ getTerminal(id: string): Promise<TerminalInstance>;
3235
3256
  /**
3236
3257
  * List all commands executed in a terminal (exec mode only)
3237
3258
  * @param terminalId - The terminal ID
package/dist/index.js CHANGED
@@ -1365,7 +1365,7 @@ var Terminal = class {
1365
1365
  /**
1366
1366
  * Retrieve a specific terminal by ID
1367
1367
  * @param id - The terminal ID
1368
- * @returns Terminal response
1368
+ * @returns Terminal instance
1369
1369
  */
1370
1370
  async retrieve(id) {
1371
1371
  return this.retrieveHandler(id);
@@ -1975,6 +1975,7 @@ var Overlay = class {
1975
1975
  * @param options.source - Absolute path to source directory
1976
1976
  * @param options.target - Relative path in sandbox
1977
1977
  * @param options.ignore - Glob patterns to ignore (e.g., ["node_modules", "*.log"])
1978
+ * @param options.strategy - Strategy to use ('copy' or 'smart')
1978
1979
  * @param options.waitForCompletion - If true or options object, wait for background copy to complete
1979
1980
  * @returns Overlay info with copy status
1980
1981
  */
@@ -2064,6 +2065,7 @@ Try increasing maxRetries or check if the source directory is very large.`
2064
2065
  id: response.id,
2065
2066
  source: response.source,
2066
2067
  target: response.target,
2068
+ strategy: this.validateStrategy(response.strategy),
2067
2069
  createdAt: response.created_at,
2068
2070
  stats: {
2069
2071
  copiedFiles: response.stats.copied_files,
@@ -2074,6 +2076,16 @@ Try increasing maxRetries or check if the source directory is very large.`
2074
2076
  copyError: response.copy_error
2075
2077
  };
2076
2078
  }
2079
+ /**
2080
+ * Validate and return strategy, defaulting to 'copy' for unknown/missing values (legacy support)
2081
+ */
2082
+ validateStrategy(strategy) {
2083
+ const validStrategies = ["copy", "smart"];
2084
+ if (strategy && validStrategies.includes(strategy)) {
2085
+ return strategy;
2086
+ }
2087
+ return "copy";
2088
+ }
2077
2089
  /**
2078
2090
  * Validate and return copy status, defaulting to 'pending' for unknown values
2079
2091
  */
@@ -2104,6 +2116,7 @@ var Sandbox = class {
2104
2116
  constructor(config) {
2105
2117
  this._token = null;
2106
2118
  this._ws = null;
2119
+ this._terminals = /* @__PURE__ */ new Map();
2107
2120
  this.sandboxId = config.sandboxId;
2108
2121
  this.provider = config.provider;
2109
2122
  let sandboxUrlResolved = config.sandboxUrl;
@@ -2310,6 +2323,44 @@ var Sandbox = class {
2310
2323
  }
2311
2324
  return this._ws;
2312
2325
  }
2326
+ /**
2327
+ * Create and configure a TerminalInstance from response data
2328
+ */
2329
+ async hydrateTerminal(data, ws) {
2330
+ const terminal = new TerminalInstance(
2331
+ data.id,
2332
+ data.pty,
2333
+ data.status,
2334
+ data.channel || null,
2335
+ ws || null,
2336
+ data.encoding || "raw"
2337
+ );
2338
+ const terminalId = data.id;
2339
+ terminal.setExecuteHandler(async (command, background) => {
2340
+ return this.request(`/terminals/${terminalId}/execute`, {
2341
+ method: "POST",
2342
+ body: JSON.stringify({ command, background })
2343
+ });
2344
+ });
2345
+ terminal.setListCommandsHandler(async () => {
2346
+ return this.request(`/terminals/${terminalId}/commands`);
2347
+ });
2348
+ terminal.setRetrieveCommandHandler(async (cmdId) => {
2349
+ return this.request(`/terminals/${terminalId}/commands/${cmdId}`);
2350
+ });
2351
+ terminal.setWaitCommandHandler(async (cmdId, timeout) => {
2352
+ const params = timeout ? new URLSearchParams({ timeout: timeout.toString() }) : "";
2353
+ const endpoint = `/terminals/${terminalId}/commands/${cmdId}/wait${params ? `?${params}` : ""}`;
2354
+ return this.request(endpoint);
2355
+ });
2356
+ terminal.setDestroyHandler(async () => {
2357
+ await this.request(`/terminals/${terminalId}`, {
2358
+ method: "DELETE"
2359
+ });
2360
+ this._terminals.delete(terminalId);
2361
+ });
2362
+ return terminal;
2363
+ }
2313
2364
  // ============================================================================
2314
2365
  // Private Helper Methods
2315
2366
  // ============================================================================
@@ -2816,37 +2867,8 @@ API request failed (${response.status}): ${error}`
2816
2867
  }
2817
2868
  });
2818
2869
  }
2819
- const terminal = new TerminalInstance(
2820
- response.data.id,
2821
- response.data.pty,
2822
- response.data.status,
2823
- response.data.channel || null,
2824
- ws,
2825
- response.data.encoding || "raw"
2826
- );
2827
- const terminalId = response.data.id;
2828
- terminal.setExecuteHandler(async (command, background) => {
2829
- return this.request(`/terminals/${terminalId}/execute`, {
2830
- method: "POST",
2831
- body: JSON.stringify({ command, background })
2832
- });
2833
- });
2834
- terminal.setListCommandsHandler(async () => {
2835
- return this.request(`/terminals/${terminalId}/commands`);
2836
- });
2837
- terminal.setRetrieveCommandHandler(async (cmdId) => {
2838
- return this.request(`/terminals/${terminalId}/commands/${cmdId}`);
2839
- });
2840
- terminal.setWaitCommandHandler(async (cmdId, timeout) => {
2841
- const params = timeout ? new URLSearchParams({ timeout: timeout.toString() }) : "";
2842
- const endpoint = `/terminals/${terminalId}/commands/${cmdId}/wait${params ? `?${params}` : ""}`;
2843
- return this.request(endpoint);
2844
- });
2845
- terminal.setDestroyHandler(async () => {
2846
- await this.request(`/terminals/${terminalId}`, {
2847
- method: "DELETE"
2848
- });
2849
- });
2870
+ const terminal = await this.hydrateTerminal(response.data, ws);
2871
+ this._terminals.set(terminal.id, terminal);
2850
2872
  return terminal;
2851
2873
  }
2852
2874
  /**
@@ -2860,7 +2882,18 @@ API request failed (${response.status}): ${error}`
2860
2882
  * Get terminal by ID
2861
2883
  */
2862
2884
  async getTerminal(id) {
2863
- return this.request(`/terminals/${id}`);
2885
+ const cached = this._terminals.get(id);
2886
+ if (cached) {
2887
+ return cached;
2888
+ }
2889
+ const response = await this.request(`/terminals/${id}`);
2890
+ let ws = null;
2891
+ if (response.data.pty) {
2892
+ ws = await this.ensureWebSocket();
2893
+ }
2894
+ const terminal = await this.hydrateTerminal(response.data, ws);
2895
+ this._terminals.set(id, terminal);
2896
+ return terminal;
2864
2897
  }
2865
2898
  // ============================================================================
2866
2899
  // Command Tracking (Exec Mode Terminals)
@@ -3464,6 +3497,7 @@ API request failed (${response.status}): ${error}`
3464
3497
  this._ws.disconnect();
3465
3498
  this._ws = null;
3466
3499
  }
3500
+ this._terminals.clear();
3467
3501
  }
3468
3502
  };
3469
3503