computesdk 1.18.0 → 1.18.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1312,7 +1312,7 @@ var Terminal = class {
1312
1312
  /**
1313
1313
  * Retrieve a specific terminal by ID
1314
1314
  * @param id - The terminal ID
1315
- * @returns Terminal response
1315
+ * @returns Terminal instance
1316
1316
  */
1317
1317
  async retrieve(id) {
1318
1318
  return this.retrieveHandler(id);
@@ -1922,6 +1922,7 @@ var Overlay = class {
1922
1922
  * @param options.source - Absolute path to source directory
1923
1923
  * @param options.target - Relative path in sandbox
1924
1924
  * @param options.ignore - Glob patterns to ignore (e.g., ["node_modules", "*.log"])
1925
+ * @param options.strategy - Strategy to use ('copy' or 'smart')
1925
1926
  * @param options.waitForCompletion - If true or options object, wait for background copy to complete
1926
1927
  * @returns Overlay info with copy status
1927
1928
  */
@@ -2011,6 +2012,7 @@ Try increasing maxRetries or check if the source directory is very large.`
2011
2012
  id: response.id,
2012
2013
  source: response.source,
2013
2014
  target: response.target,
2015
+ strategy: this.validateStrategy(response.strategy),
2014
2016
  createdAt: response.created_at,
2015
2017
  stats: {
2016
2018
  copiedFiles: response.stats.copied_files,
@@ -2021,6 +2023,16 @@ Try increasing maxRetries or check if the source directory is very large.`
2021
2023
  copyError: response.copy_error
2022
2024
  };
2023
2025
  }
2026
+ /**
2027
+ * Validate and return strategy, defaulting to 'copy' for unknown/missing values (legacy support)
2028
+ */
2029
+ validateStrategy(strategy) {
2030
+ const validStrategies = ["copy", "smart"];
2031
+ if (strategy && validStrategies.includes(strategy)) {
2032
+ return strategy;
2033
+ }
2034
+ return "copy";
2035
+ }
2024
2036
  /**
2025
2037
  * Validate and return copy status, defaulting to 'pending' for unknown values
2026
2038
  */
@@ -2051,6 +2063,7 @@ var Sandbox = class {
2051
2063
  constructor(config) {
2052
2064
  this._token = null;
2053
2065
  this._ws = null;
2066
+ this._terminals = /* @__PURE__ */ new Map();
2054
2067
  this.sandboxId = config.sandboxId;
2055
2068
  this.provider = config.provider;
2056
2069
  let sandboxUrlResolved = config.sandboxUrl;
@@ -2257,6 +2270,44 @@ var Sandbox = class {
2257
2270
  }
2258
2271
  return this._ws;
2259
2272
  }
2273
+ /**
2274
+ * Create and configure a TerminalInstance from response data
2275
+ */
2276
+ async hydrateTerminal(data, ws) {
2277
+ const terminal = new TerminalInstance(
2278
+ data.id,
2279
+ data.pty,
2280
+ data.status,
2281
+ data.channel || null,
2282
+ ws || null,
2283
+ data.encoding || "raw"
2284
+ );
2285
+ const terminalId = data.id;
2286
+ terminal.setExecuteHandler(async (command, background) => {
2287
+ return this.request(`/terminals/${terminalId}/execute`, {
2288
+ method: "POST",
2289
+ body: JSON.stringify({ command, background })
2290
+ });
2291
+ });
2292
+ terminal.setListCommandsHandler(async () => {
2293
+ return this.request(`/terminals/${terminalId}/commands`);
2294
+ });
2295
+ terminal.setRetrieveCommandHandler(async (cmdId) => {
2296
+ return this.request(`/terminals/${terminalId}/commands/${cmdId}`);
2297
+ });
2298
+ terminal.setWaitCommandHandler(async (cmdId, timeout) => {
2299
+ const params = timeout ? new URLSearchParams({ timeout: timeout.toString() }) : "";
2300
+ const endpoint = `/terminals/${terminalId}/commands/${cmdId}/wait${params ? `?${params}` : ""}`;
2301
+ return this.request(endpoint);
2302
+ });
2303
+ terminal.setDestroyHandler(async () => {
2304
+ await this.request(`/terminals/${terminalId}`, {
2305
+ method: "DELETE"
2306
+ });
2307
+ this._terminals.delete(terminalId);
2308
+ });
2309
+ return terminal;
2310
+ }
2260
2311
  // ============================================================================
2261
2312
  // Private Helper Methods
2262
2313
  // ============================================================================
@@ -2763,37 +2814,8 @@ API request failed (${response.status}): ${error}`
2763
2814
  }
2764
2815
  });
2765
2816
  }
2766
- const terminal = new TerminalInstance(
2767
- response.data.id,
2768
- response.data.pty,
2769
- response.data.status,
2770
- response.data.channel || null,
2771
- ws,
2772
- response.data.encoding || "raw"
2773
- );
2774
- const terminalId = response.data.id;
2775
- terminal.setExecuteHandler(async (command, background) => {
2776
- return this.request(`/terminals/${terminalId}/execute`, {
2777
- method: "POST",
2778
- body: JSON.stringify({ command, background })
2779
- });
2780
- });
2781
- terminal.setListCommandsHandler(async () => {
2782
- return this.request(`/terminals/${terminalId}/commands`);
2783
- });
2784
- terminal.setRetrieveCommandHandler(async (cmdId) => {
2785
- return this.request(`/terminals/${terminalId}/commands/${cmdId}`);
2786
- });
2787
- terminal.setWaitCommandHandler(async (cmdId, timeout) => {
2788
- const params = timeout ? new URLSearchParams({ timeout: timeout.toString() }) : "";
2789
- const endpoint = `/terminals/${terminalId}/commands/${cmdId}/wait${params ? `?${params}` : ""}`;
2790
- return this.request(endpoint);
2791
- });
2792
- terminal.setDestroyHandler(async () => {
2793
- await this.request(`/terminals/${terminalId}`, {
2794
- method: "DELETE"
2795
- });
2796
- });
2817
+ const terminal = await this.hydrateTerminal(response.data, ws);
2818
+ this._terminals.set(terminal.id, terminal);
2797
2819
  return terminal;
2798
2820
  }
2799
2821
  /**
@@ -2807,7 +2829,18 @@ API request failed (${response.status}): ${error}`
2807
2829
  * Get terminal by ID
2808
2830
  */
2809
2831
  async getTerminal(id) {
2810
- return this.request(`/terminals/${id}`);
2832
+ const cached = this._terminals.get(id);
2833
+ if (cached) {
2834
+ return cached;
2835
+ }
2836
+ const response = await this.request(`/terminals/${id}`);
2837
+ let ws = null;
2838
+ if (response.data.pty) {
2839
+ ws = await this.ensureWebSocket();
2840
+ }
2841
+ const terminal = await this.hydrateTerminal(response.data, ws);
2842
+ this._terminals.set(id, terminal);
2843
+ return terminal;
2811
2844
  }
2812
2845
  // ============================================================================
2813
2846
  // Command Tracking (Exec Mode Terminals)
@@ -3411,6 +3444,7 @@ API request failed (${response.status}): ${error}`
3411
3444
  this._ws.disconnect();
3412
3445
  this._ws = null;
3413
3446
  }
3447
+ this._terminals.clear();
3414
3448
  }
3415
3449
  };
3416
3450
 
@@ -3428,7 +3462,8 @@ var PROVIDER_AUTH = {
3428
3462
  runloop: [["RUNLOOP_API_KEY"]],
3429
3463
  cloudflare: [["CLOUDFLARE_API_TOKEN", "CLOUDFLARE_ACCOUNT_ID"]],
3430
3464
  codesandbox: [["CSB_API_KEY"]],
3431
- blaxel: [["BL_API_KEY", "BL_WORKSPACE"]]
3465
+ blaxel: [["BL_API_KEY", "BL_WORKSPACE"]],
3466
+ namespace: [["NSC_TOKEN"]]
3432
3467
  };
3433
3468
  var PROVIDER_NAMES = Object.keys(PROVIDER_AUTH);
3434
3469
  var PROVIDER_HEADERS = {
@@ -3470,6 +3505,9 @@ var PROVIDER_HEADERS = {
3470
3505
  blaxel: {
3471
3506
  apiKey: "X-BL-API-Key",
3472
3507
  workspace: "X-BL-Workspace"
3508
+ },
3509
+ namespace: {
3510
+ token: "X-Namespace-Token"
3473
3511
  }
3474
3512
  };
3475
3513
  var PROVIDER_ENV_MAP = {
@@ -3511,6 +3549,9 @@ var PROVIDER_ENV_MAP = {
3511
3549
  blaxel: {
3512
3550
  BL_API_KEY: "apiKey",
3513
3551
  BL_WORKSPACE: "workspace"
3552
+ },
3553
+ namespace: {
3554
+ NSC_TOKEN: "token"
3514
3555
  }
3515
3556
  };
3516
3557
  var PROVIDER_DASHBOARD_URLS = {
@@ -3523,7 +3564,8 @@ var PROVIDER_DASHBOARD_URLS = {
3523
3564
  runloop: "https://runloop.ai/dashboard",
3524
3565
  cloudflare: "https://dash.cloudflare.com/profile/api-tokens",
3525
3566
  codesandbox: "https://codesandbox.io/dashboard/settings",
3526
- blaxel: "https://blaxel.ai/dashboard"
3567
+ blaxel: "https://blaxel.ai/dashboard",
3568
+ namespace: "https://cloud.namespace.so"
3527
3569
  };
3528
3570
  function isValidProvider(name) {
3529
3571
  return name in PROVIDER_AUTH;
@@ -3591,7 +3633,8 @@ var PROVIDER_PRIORITY = [
3591
3633
  "vercel",
3592
3634
  "cloudflare",
3593
3635
  "codesandbox",
3594
- "blaxel"
3636
+ "blaxel",
3637
+ "namespace"
3595
3638
  ];
3596
3639
  var PROVIDER_ENV_VARS = {
3597
3640
  e2b: ["E2B_API_KEY"],
@@ -3603,7 +3646,8 @@ var PROVIDER_ENV_VARS = {
3603
3646
  vercel: ["VERCEL_TOKEN", "VERCEL_TEAM_ID", "VERCEL_PROJECT_ID"],
3604
3647
  cloudflare: ["CLOUDFLARE_API_TOKEN", "CLOUDFLARE_ACCOUNT_ID"],
3605
3648
  codesandbox: ["CSB_API_KEY"],
3606
- blaxel: ["BL_API_KEY", "BL_WORKSPACE"]
3649
+ blaxel: ["BL_API_KEY", "BL_WORKSPACE"],
3650
+ namespace: ["NSC_TOKEN"]
3607
3651
  };
3608
3652
 
3609
3653
  // src/auto-detect.ts
@@ -3720,6 +3764,11 @@ function getProviderHeaders(provider) {
3720
3764
  headers["X-Blaxel-Workspace"] = process.env.BL_WORKSPACE;
3721
3765
  }
3722
3766
  break;
3767
+ case "namespace":
3768
+ if (process.env.NSC_TOKEN) {
3769
+ headers["X-Namespace-Token"] = process.env.NSC_TOKEN;
3770
+ }
3771
+ break;
3723
3772
  }
3724
3773
  return headers;
3725
3774
  }
@@ -3756,6 +3805,7 @@ To fix this, set one of the following:
3756
3805
  Cloudflare: export CLOUDFLARE_API_TOKEN=xxx CLOUDFLARE_ACCOUNT_ID=xxx
3757
3806
  CodeSandbox: export CSB_API_KEY=xxx
3758
3807
  Blaxel: export BL_API_KEY=xxx BL_WORKSPACE=xxx
3808
+ Namespace: export NSC_TOKEN=xxx
3759
3809
 
3760
3810
  Or set COMPUTESDK_PROVIDER to specify explicitly:
3761
3811
  export COMPUTESDK_PROVIDER=e2b