computesdk 2.0.2 → 2.1.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
@@ -2309,7 +2309,9 @@ var Sandbox = class {
2309
2309
  terminal.setWaitCommandHandler(async (cmdId, timeout) => {
2310
2310
  const params = timeout ? new URLSearchParams({ timeout: timeout.toString() }) : "";
2311
2311
  const endpoint = `/terminals/${terminalId}/commands/${cmdId}/wait${params ? `?${params}` : ""}`;
2312
- return this.request(endpoint);
2312
+ return this.request(endpoint, {
2313
+ headers: timeout ? { "X-Request-Timeout": timeout.toString() } : void 0
2314
+ });
2313
2315
  });
2314
2316
  terminal.setDestroyHandler(async () => {
2315
2317
  await this.request(`/terminals/${terminalId}`, {
@@ -2325,6 +2327,11 @@ var Sandbox = class {
2325
2327
  async request(endpoint, options = {}) {
2326
2328
  const controller = new AbortController();
2327
2329
  const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
2330
+ if (process.env.COMPUTESDK_DEBUG) {
2331
+ console.log(`[ComputeSDK] Request: ${options.method || "GET"} ${this.config.sandboxUrl}${endpoint}`);
2332
+ console.log(`[ComputeSDK] Sandbox ID: ${this.config.sandboxId}`);
2333
+ console.log(`[ComputeSDK] Token: ${this._token || "(no token)"}`);
2334
+ }
2328
2335
  try {
2329
2336
  const headers = {
2330
2337
  ...this.config.headers
@@ -2367,6 +2374,15 @@ API request failed (${response.status}): ${error}`
2367
2374
  );
2368
2375
  }
2369
2376
  }
2377
+ if (response.status === 403 && process.env.COMPUTESDK_DEBUG) {
2378
+ console.error(`[ComputeSDK] 403 Forbidden Debug Info:`);
2379
+ console.error(` Endpoint: ${endpoint}`);
2380
+ console.error(` Method: ${options.method || "GET"}`);
2381
+ console.error(` Sandbox URL: ${this.config.sandboxUrl}`);
2382
+ console.error(` Sandbox ID: ${this.config.sandboxId}`);
2383
+ console.error(` Token: ${this._token || "(no token)"}`);
2384
+ console.error(` Error: ${error}`);
2385
+ }
2370
2386
  throw new Error(`API request failed (${response.status}): ${error}`);
2371
2387
  }
2372
2388
  return data;
@@ -2886,7 +2902,9 @@ API request failed (${response.status}): ${error}`
2886
2902
  async waitForCommand(terminalId, cmdId, timeout) {
2887
2903
  const params = timeout ? new URLSearchParams({ timeout: timeout.toString() }) : "";
2888
2904
  const endpoint = `/terminals/${terminalId}/commands/${cmdId}/wait${params ? `?${params}` : ""}`;
2889
- return this.request(endpoint);
2905
+ return this.request(endpoint, {
2906
+ headers: timeout ? { "X-Request-Timeout": timeout.toString() } : void 0
2907
+ });
2890
2908
  }
2891
2909
  /**
2892
2910
  * Wait for a background command to complete using long-polling
@@ -3253,6 +3271,7 @@ API request failed (${response.status}): ${error}`
3253
3271
  const response = await this.request("/ready");
3254
3272
  return {
3255
3273
  ready: response.ready,
3274
+ healthy: response.healthy,
3256
3275
  servers: response.servers ?? [],
3257
3276
  overlays: response.overlays ?? []
3258
3277
  };
@@ -3336,6 +3355,7 @@ API request failed (${response.status}): ${error}`
3336
3355
  * @param options.env - Environment variables (server uses cmd.Env)
3337
3356
  * @param options.onStdout - Callback for streaming stdout data
3338
3357
  * @param options.onStderr - Callback for streaming stderr data
3358
+ * @param options.timeout - Timeout in seconds (max 300 for long-running commands)
3339
3359
  * @returns Command execution result
3340
3360
  *
3341
3361
  * @example
@@ -3357,11 +3377,21 @@ API request failed (${response.status}): ${error}`
3357
3377
  * onStdout: (data) => console.log(data),
3358
3378
  * onStderr: (data) => console.error(data),
3359
3379
  * })
3380
+ *
3381
+ * // With timeout for long-running commands
3382
+ * await sandbox.runCommand('npm install', { timeout: 120 })
3360
3383
  * ```
3361
3384
  */
3362
3385
  async runCommand(command, options) {
3363
3386
  const hasStreamingCallbacks = options?.onStdout || options?.onStderr;
3364
3387
  if (!hasStreamingCallbacks) {
3388
+ if (options?.timeout && !options?.background) {
3389
+ return this.run.command(command, {
3390
+ ...options,
3391
+ background: true,
3392
+ waitForCompletion: { timeoutSeconds: options.timeout }
3393
+ });
3394
+ }
3365
3395
  return this.run.command(command, options);
3366
3396
  }
3367
3397
  const ws = await this.ensureWebSocket();
@@ -3419,9 +3449,20 @@ API request failed (${response.status}): ${error}`
3419
3449
  durationMs: 0
3420
3450
  };
3421
3451
  }
3422
- return new Promise((resolve) => {
3452
+ const commandPromise = new Promise((resolve) => {
3423
3453
  resolvePromise = resolve;
3424
3454
  });
3455
+ if (options?.timeout) {
3456
+ const timeoutMs = options.timeout * 1e3;
3457
+ const timeoutPromise = new Promise((_, reject) => {
3458
+ setTimeout(() => {
3459
+ cleanup();
3460
+ reject(new Error(`Command timed out after ${options.timeout} seconds`));
3461
+ }, timeoutMs);
3462
+ });
3463
+ return Promise.race([commandPromise, timeoutPromise]);
3464
+ }
3465
+ return commandPromise;
3425
3466
  }
3426
3467
  /**
3427
3468
  * Get server information
@@ -3551,7 +3592,8 @@ var PROVIDER_AUTH = {
3551
3592
  cloudflare: [["CLOUDFLARE_API_TOKEN", "CLOUDFLARE_ACCOUNT_ID"]],
3552
3593
  codesandbox: [["CSB_API_KEY"]],
3553
3594
  blaxel: [["BL_API_KEY", "BL_WORKSPACE"]],
3554
- namespace: [["NSC_TOKEN"]]
3595
+ namespace: [["NSC_TOKEN"]],
3596
+ hopx: [["HOPX_API_KEY"]]
3555
3597
  };
3556
3598
  var PROVIDER_NAMES = Object.keys(PROVIDER_AUTH);
3557
3599
  var PROVIDER_HEADERS = {
@@ -3588,7 +3630,7 @@ var PROVIDER_HEADERS = {
3588
3630
  accountId: "X-Cloudflare-Account-Id"
3589
3631
  },
3590
3632
  codesandbox: {
3591
- apiKey: "X-CSB-API-Key"
3633
+ apiKey: "X-CODESANDBOX-API-Key"
3592
3634
  },
3593
3635
  blaxel: {
3594
3636
  apiKey: "X-Blaxel-API-Key",
@@ -3596,6 +3638,9 @@ var PROVIDER_HEADERS = {
3596
3638
  },
3597
3639
  namespace: {
3598
3640
  token: "X-Namespace-Token"
3641
+ },
3642
+ hopx: {
3643
+ apiKey: "X-HOPX-API-Key"
3599
3644
  }
3600
3645
  };
3601
3646
  var PROVIDER_ENV_MAP = {
@@ -3640,6 +3685,9 @@ var PROVIDER_ENV_MAP = {
3640
3685
  },
3641
3686
  namespace: {
3642
3687
  NSC_TOKEN: "token"
3688
+ },
3689
+ hopx: {
3690
+ HOPX_API_KEY: "apiKey"
3643
3691
  }
3644
3692
  };
3645
3693
  var PROVIDER_DASHBOARD_URLS = {
@@ -3653,7 +3701,8 @@ var PROVIDER_DASHBOARD_URLS = {
3653
3701
  cloudflare: "https://dash.cloudflare.com/profile/api-tokens",
3654
3702
  codesandbox: "https://codesandbox.io/dashboard/settings",
3655
3703
  blaxel: "https://blaxel.ai/dashboard",
3656
- namespace: "https://cloud.namespace.so"
3704
+ namespace: "https://cloud.namespace.so",
3705
+ hopx: "https://hopx.ai/dashboard"
3657
3706
  };
3658
3707
  function isValidProvider(name) {
3659
3708
  return name in PROVIDER_AUTH;
@@ -3722,7 +3771,8 @@ var PROVIDER_PRIORITY = [
3722
3771
  "cloudflare",
3723
3772
  "codesandbox",
3724
3773
  "blaxel",
3725
- "namespace"
3774
+ "namespace",
3775
+ "hopx"
3726
3776
  ];
3727
3777
  var PROVIDER_ENV_VARS = {
3728
3778
  e2b: ["E2B_API_KEY"],
@@ -3735,7 +3785,8 @@ var PROVIDER_ENV_VARS = {
3735
3785
  cloudflare: ["CLOUDFLARE_API_TOKEN", "CLOUDFLARE_ACCOUNT_ID"],
3736
3786
  codesandbox: ["CSB_API_KEY"],
3737
3787
  blaxel: ["BL_API_KEY", "BL_WORKSPACE"],
3738
- namespace: ["NSC_TOKEN"]
3788
+ namespace: ["NSC_TOKEN"],
3789
+ hopx: ["HOPX_API_KEY"]
3739
3790
  };
3740
3791
 
3741
3792
  // src/auto-detect.ts
@@ -3857,6 +3908,11 @@ function getProviderHeaders(provider) {
3857
3908
  headers["X-Namespace-Token"] = process.env.NSC_TOKEN;
3858
3909
  }
3859
3910
  break;
3911
+ case "hopx":
3912
+ if (process.env.HOPX_API_KEY) {
3913
+ headers["X-HOPX-API-Key"] = process.env.HOPX_API_KEY;
3914
+ }
3915
+ break;
3860
3916
  }
3861
3917
  return headers;
3862
3918
  }
@@ -3894,6 +3950,7 @@ To fix this, set one of the following:
3894
3950
  CodeSandbox: export CSB_API_KEY=xxx
3895
3951
  Blaxel: export BL_API_KEY=xxx BL_WORKSPACE=xxx
3896
3952
  Namespace: export NSC_TOKEN=xxx
3953
+ HopX: export HOPX_API_KEY=xxx
3897
3954
 
3898
3955
  Or set COMPUTESDK_PROVIDER to specify explicitly:
3899
3956
  export COMPUTESDK_PROVIDER=e2b
@@ -4007,7 +4064,7 @@ Get your API key at: https://computesdk.com/dashboard`
4007
4064
  const providerHeaders = buildProviderHeaders2(config);
4008
4065
  return {
4009
4066
  apiKey: computesdkApiKey,
4010
- gatewayUrl: config.gatewayUrl || GATEWAY_URL,
4067
+ gatewayUrl: config.gatewayUrl || process.env.COMPUTESDK_GATEWAY_URL || GATEWAY_URL,
4011
4068
  provider: config.provider,
4012
4069
  providerHeaders,
4013
4070
  requestTimeoutMs: config.requestTimeoutMs,