computesdk 2.4.0 → 2.5.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.mjs CHANGED
@@ -3586,7 +3586,10 @@ var PROVIDER_AUTH = {
3586
3586
  ["VERCEL_TOKEN", "VERCEL_TEAM_ID", "VERCEL_PROJECT_ID"]
3587
3587
  ],
3588
3588
  runloop: [["RUNLOOP_API_KEY"]],
3589
- cloudflare: [["CLOUDFLARE_API_TOKEN", "CLOUDFLARE_ACCOUNT_ID"]],
3589
+ cloudflare: [
3590
+ ["CLOUDFLARE_SANDBOX_URL", "CLOUDFLARE_SANDBOX_SECRET"],
3591
+ ["CLOUDFLARE_API_TOKEN", "CLOUDFLARE_ACCOUNT_ID"]
3592
+ ],
3590
3593
  codesandbox: [["CSB_API_KEY"]],
3591
3594
  blaxel: [["BL_API_KEY", "BL_WORKSPACE"]],
3592
3595
  namespace: [["NSC_TOKEN"], ["NSC_TOKEN_FILE"]],
@@ -3626,6 +3629,8 @@ var PROVIDER_HEADERS = {
3626
3629
  apiKey: "X-Runloop-API-Key"
3627
3630
  },
3628
3631
  cloudflare: {
3632
+ sandboxUrl: "X-Cloudflare-Sandbox-Url",
3633
+ sandboxSecret: "X-Cloudflare-Sandbox-Secret",
3629
3634
  apiToken: "X-Cloudflare-API-Token",
3630
3635
  accountId: "X-Cloudflare-Account-Id"
3631
3636
  },
@@ -3681,6 +3686,8 @@ var PROVIDER_ENV_MAP = {
3681
3686
  RUNLOOP_API_KEY: "apiKey"
3682
3687
  },
3683
3688
  cloudflare: {
3689
+ CLOUDFLARE_SANDBOX_URL: "sandboxUrl",
3690
+ CLOUDFLARE_SANDBOX_SECRET: "sandboxSecret",
3684
3691
  CLOUDFLARE_API_TOKEN: "apiToken",
3685
3692
  CLOUDFLARE_ACCOUNT_ID: "accountId"
3686
3693
  },
@@ -3779,7 +3786,7 @@ function getMissingEnvVars(provider) {
3779
3786
  }
3780
3787
 
3781
3788
  // src/constants.ts
3782
- var GATEWAY_URL = "https://gateway.computesdk.com";
3789
+ var TRIBUTARY_URL = "https://tributary.edge.computesdk.com";
3783
3790
  var PROVIDER_PRIORITY = [
3784
3791
  "e2b",
3785
3792
  "railway",
@@ -4010,7 +4017,7 @@ Or set COMPUTESDK_PROVIDER to specify explicitly:
4010
4017
  Docs: https://computesdk.com/docs/quickstart`
4011
4018
  );
4012
4019
  }
4013
- const gatewayUrl = process.env.COMPUTESDK_GATEWAY_URL || GATEWAY_URL;
4020
+ const gatewayUrl = process.env.COMPUTESDK_TRIBUTARY_URL || TRIBUTARY_URL;
4014
4021
  const computesdkApiKey = process.env.COMPUTESDK_API_KEY;
4015
4022
  const providerHeaders = getProviderHeaders(provider);
4016
4023
  try {
@@ -4020,7 +4027,7 @@ Docs: https://computesdk.com/docs/quickstart`
4020
4027
  `Invalid gateway URL: "${gatewayUrl}"
4021
4028
 
4022
4029
  The URL must be a valid HTTP/HTTPS URL.
4023
- Check your COMPUTESDK_GATEWAY_URL environment variable.`
4030
+ Check your COMPUTESDK_TRIBUTARY_URL environment variable.`
4024
4031
  );
4025
4032
  }
4026
4033
  if (process.env.COMPUTESDK_DEBUG) {
@@ -4116,7 +4123,7 @@ Get your API key at: https://computesdk.com/dashboard`
4116
4123
  const providerHeaders = buildProviderHeaders2(config);
4117
4124
  return {
4118
4125
  apiKey: computesdkApiKey,
4119
- gatewayUrl: config.gatewayUrl || process.env.COMPUTESDK_GATEWAY_URL || GATEWAY_URL,
4126
+ gatewayUrl: config.gatewayUrl || process.env.COMPUTESDK_TRIBUTARY_URL || TRIBUTARY_URL,
4120
4127
  provider: config.provider,
4121
4128
  providerHeaders,
4122
4129
  requestTimeoutMs: config.requestTimeoutMs,
@@ -4166,7 +4173,7 @@ Troubleshooting:
4166
4173
  }
4167
4174
 
4168
4175
  // src/compute.ts
4169
- async function gatewayFetch(url, config, options = {}) {
4176
+ async function tributaryFetch(url, config, options = {}) {
4170
4177
  const timeout = config.requestTimeoutMs ?? 3e4;
4171
4178
  const controller = new AbortController();
4172
4179
  const timeoutId = setTimeout(() => controller.abort(), timeout);
@@ -4213,7 +4220,7 @@ async function waitForSandboxStatus(config, endpoint, body, options = {}) {
4213
4220
  const startTime = Date.now();
4214
4221
  let currentDelay = initialDelayMs;
4215
4222
  while (Date.now() - startTime < maxWaitMs) {
4216
- const result = await gatewayFetch(endpoint, config, {
4223
+ const result = await tributaryFetch(endpoint, config, {
4217
4224
  method: "POST",
4218
4225
  body: JSON.stringify(body)
4219
4226
  });
@@ -4264,7 +4271,7 @@ var ComputeManager = class {
4264
4271
  */
4265
4272
  create: async (options) => {
4266
4273
  const config = this.getGatewayConfig();
4267
- const result = await gatewayFetch(`${config.gatewayUrl}/v1/sandboxes`, config, {
4274
+ const result = await tributaryFetch(`${config.gatewayUrl}/v1/sandboxes`, config, {
4268
4275
  method: "POST",
4269
4276
  body: JSON.stringify(options || {})
4270
4277
  });
@@ -4286,7 +4293,7 @@ var ComputeManager = class {
4286
4293
  },
4287
4294
  WebSocket: config.WebSocket || globalThis.WebSocket,
4288
4295
  destroyHandler: async () => {
4289
- await gatewayFetch(`${config.gatewayUrl}/v1/sandboxes/${sandboxId}`, config, {
4296
+ await tributaryFetch(`${config.gatewayUrl}/v1/sandboxes/${sandboxId}`, config, {
4290
4297
  method: "DELETE"
4291
4298
  });
4292
4299
  }
@@ -4299,7 +4306,7 @@ var ComputeManager = class {
4299
4306
  */
4300
4307
  getById: async (sandboxId) => {
4301
4308
  const config = this.getGatewayConfig();
4302
- const result = await gatewayFetch(`${config.gatewayUrl}/v1/sandboxes/${sandboxId}`, config);
4309
+ const result = await tributaryFetch(`${config.gatewayUrl}/v1/sandboxes/${sandboxId}`, config);
4303
4310
  if (!result.success || !result.data) {
4304
4311
  return null;
4305
4312
  }
@@ -4312,7 +4319,7 @@ var ComputeManager = class {
4312
4319
  metadata,
4313
4320
  WebSocket: config.WebSocket || globalThis.WebSocket,
4314
4321
  destroyHandler: async () => {
4315
- await gatewayFetch(`${config.gatewayUrl}/v1/sandboxes/${sandboxId}`, config, {
4322
+ await tributaryFetch(`${config.gatewayUrl}/v1/sandboxes/${sandboxId}`, config, {
4316
4323
  method: "DELETE"
4317
4324
  });
4318
4325
  }
@@ -4333,7 +4340,7 @@ var ComputeManager = class {
4333
4340
  */
4334
4341
  destroy: async (sandboxId) => {
4335
4342
  const config = this.getGatewayConfig();
4336
- await gatewayFetch(`${config.gatewayUrl}/v1/sandboxes/${sandboxId}`, config, {
4343
+ await tributaryFetch(`${config.gatewayUrl}/v1/sandboxes/${sandboxId}`, config, {
4337
4344
  method: "DELETE"
4338
4345
  });
4339
4346
  },
@@ -4368,7 +4375,7 @@ var ComputeManager = class {
4368
4375
  },
4369
4376
  WebSocket: config.WebSocket || globalThis.WebSocket,
4370
4377
  destroyHandler: async () => {
4371
- await gatewayFetch(`${config.gatewayUrl}/v1/sandboxes/${sandboxId}`, config, {
4378
+ await tributaryFetch(`${config.gatewayUrl}/v1/sandboxes/${sandboxId}`, config, {
4372
4379
  method: "DELETE"
4373
4380
  });
4374
4381
  }
@@ -4405,7 +4412,7 @@ var ComputeManager = class {
4405
4412
  },
4406
4413
  WebSocket: config.WebSocket || globalThis.WebSocket,
4407
4414
  destroyHandler: async () => {
4408
- await gatewayFetch(`${config.gatewayUrl}/v1/sandboxes/${sandboxId}`, config, {
4415
+ await tributaryFetch(`${config.gatewayUrl}/v1/sandboxes/${sandboxId}`, config, {
4409
4416
  method: "DELETE"
4410
4417
  });
4411
4418
  }
@@ -4419,12 +4426,57 @@ var ComputeManager = class {
4419
4426
  extendTimeout: async (sandboxId, options) => {
4420
4427
  const config = this.getGatewayConfig();
4421
4428
  const duration = options?.duration ?? 9e5;
4422
- await gatewayFetch(`${config.gatewayUrl}/v1/sandboxes/${sandboxId}/extend`, config, {
4429
+ await tributaryFetch(`${config.gatewayUrl}/v1/sandboxes/${sandboxId}/extend`, config, {
4423
4430
  method: "POST",
4424
4431
  body: JSON.stringify({ duration })
4425
4432
  });
4426
4433
  }
4427
4434
  };
4435
+ this.snapshot = {
4436
+ /**
4437
+ * Create a snapshot from a running sandbox
4438
+ *
4439
+ * @param sandboxId ID of the sandbox to snapshot
4440
+ * @param options Snapshot options (name, metadata)
4441
+ */
4442
+ create: async (sandboxId, options) => {
4443
+ const config = this.getGatewayConfig();
4444
+ const result = await tributaryFetch(`${config.gatewayUrl}/v1/snapshots`, config, {
4445
+ method: "POST",
4446
+ body: JSON.stringify({ sandboxId, ...options })
4447
+ });
4448
+ if (!result.success || !result.data) {
4449
+ throw new Error(`Gateway returned invalid response`);
4450
+ }
4451
+ return {
4452
+ ...result.data,
4453
+ createdAt: new Date(result.data.createdAt)
4454
+ };
4455
+ },
4456
+ /**
4457
+ * List all snapshots
4458
+ */
4459
+ list: async () => {
4460
+ const config = this.getGatewayConfig();
4461
+ const result = await tributaryFetch(`${config.gatewayUrl}/v1/snapshots`, config);
4462
+ if (!result.success || !result.data) {
4463
+ return [];
4464
+ }
4465
+ return result.data.map((s) => ({
4466
+ ...s,
4467
+ createdAt: new Date(s.createdAt)
4468
+ }));
4469
+ },
4470
+ /**
4471
+ * Delete a snapshot
4472
+ */
4473
+ delete: async (snapshotId) => {
4474
+ const config = this.getGatewayConfig();
4475
+ await tributaryFetch(`${config.gatewayUrl}/v1/snapshots/${snapshotId}`, config, {
4476
+ method: "DELETE"
4477
+ });
4478
+ }
4479
+ };
4428
4480
  }
4429
4481
  /**
4430
4482
  * Lazy auto-configure from environment if not explicitly configured
@@ -4505,7 +4557,6 @@ var compute = new Proxy(
4505
4557
  export {
4506
4558
  CommandExitError,
4507
4559
  FileWatcher,
4508
- GATEWAY_URL,
4509
4560
  Sandbox as GatewaySandbox,
4510
4561
  MessageType,
4511
4562
  PROVIDER_AUTH,
@@ -4517,6 +4568,7 @@ export {
4517
4568
  PROVIDER_PRIORITY,
4518
4569
  Sandbox,
4519
4570
  SignalService,
4571
+ TRIBUTARY_URL,
4520
4572
  TerminalInstance,
4521
4573
  autoConfigureCompute,
4522
4574
  buildProviderHeaders,