computesdk 2.5.0 → 2.5.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.d.mts +52 -4
- package/dist/index.d.ts +52 -4
- package/dist/index.js +80 -18
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +79 -17
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -3586,13 +3586,17 @@ var PROVIDER_AUTH = {
|
|
|
3586
3586
|
["VERCEL_TOKEN", "VERCEL_TEAM_ID", "VERCEL_PROJECT_ID"]
|
|
3587
3587
|
],
|
|
3588
3588
|
runloop: [["RUNLOOP_API_KEY"]],
|
|
3589
|
-
cloudflare: [
|
|
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"]],
|
|
3593
3596
|
hopx: [["HOPX_API_KEY"]],
|
|
3594
3597
|
beam: [["BEAM_TOKEN", "BEAM_WORKSPACE_ID"]],
|
|
3595
3598
|
sprites: [["SPRITES_TOKEN"]],
|
|
3599
|
+
freestyle: [["FREESTYLE_API_KEY"]],
|
|
3596
3600
|
"just-bash": [[]]
|
|
3597
3601
|
};
|
|
3598
3602
|
var PROVIDER_NAMES = Object.keys(PROVIDER_AUTH);
|
|
@@ -3626,6 +3630,8 @@ var PROVIDER_HEADERS = {
|
|
|
3626
3630
|
apiKey: "X-Runloop-API-Key"
|
|
3627
3631
|
},
|
|
3628
3632
|
cloudflare: {
|
|
3633
|
+
sandboxUrl: "X-Cloudflare-Sandbox-Url",
|
|
3634
|
+
sandboxSecret: "X-Cloudflare-Sandbox-Secret",
|
|
3629
3635
|
apiToken: "X-Cloudflare-API-Token",
|
|
3630
3636
|
accountId: "X-Cloudflare-Account-Id"
|
|
3631
3637
|
},
|
|
@@ -3649,6 +3655,9 @@ var PROVIDER_HEADERS = {
|
|
|
3649
3655
|
sprites: {
|
|
3650
3656
|
apiKey: "X-Sprites-Token"
|
|
3651
3657
|
},
|
|
3658
|
+
freestyle: {
|
|
3659
|
+
apiKey: "X-Freestyle-API-Key"
|
|
3660
|
+
},
|
|
3652
3661
|
"just-bash": {}
|
|
3653
3662
|
};
|
|
3654
3663
|
var PROVIDER_ENV_MAP = {
|
|
@@ -3681,6 +3690,8 @@ var PROVIDER_ENV_MAP = {
|
|
|
3681
3690
|
RUNLOOP_API_KEY: "apiKey"
|
|
3682
3691
|
},
|
|
3683
3692
|
cloudflare: {
|
|
3693
|
+
CLOUDFLARE_SANDBOX_URL: "sandboxUrl",
|
|
3694
|
+
CLOUDFLARE_SANDBOX_SECRET: "sandboxSecret",
|
|
3684
3695
|
CLOUDFLARE_API_TOKEN: "apiToken",
|
|
3685
3696
|
CLOUDFLARE_ACCOUNT_ID: "accountId"
|
|
3686
3697
|
},
|
|
@@ -3705,6 +3716,9 @@ var PROVIDER_ENV_MAP = {
|
|
|
3705
3716
|
sprites: {
|
|
3706
3717
|
SPRITES_TOKEN: "apiKey"
|
|
3707
3718
|
},
|
|
3719
|
+
freestyle: {
|
|
3720
|
+
FREESTYLE_API_KEY: "apiKey"
|
|
3721
|
+
},
|
|
3708
3722
|
"just-bash": {}
|
|
3709
3723
|
};
|
|
3710
3724
|
var PROVIDER_DASHBOARD_URLS = {
|
|
@@ -3722,6 +3736,7 @@ var PROVIDER_DASHBOARD_URLS = {
|
|
|
3722
3736
|
hopx: "https://hopx.ai/dashboard",
|
|
3723
3737
|
beam: "https://app.beam.cloud",
|
|
3724
3738
|
sprites: "https://sprites.dev",
|
|
3739
|
+
freestyle: "https://dash.freestyle.sh",
|
|
3725
3740
|
"just-bash": "https://github.com/vercel-labs/just-bash"
|
|
3726
3741
|
};
|
|
3727
3742
|
function isValidProvider(name) {
|
|
@@ -3779,7 +3794,7 @@ function getMissingEnvVars(provider) {
|
|
|
3779
3794
|
}
|
|
3780
3795
|
|
|
3781
3796
|
// src/constants.ts
|
|
3782
|
-
var
|
|
3797
|
+
var TRIBUTARY_URL = "https://tributary.edge.computesdk.com";
|
|
3783
3798
|
var PROVIDER_PRIORITY = [
|
|
3784
3799
|
"e2b",
|
|
3785
3800
|
"railway",
|
|
@@ -3794,7 +3809,8 @@ var PROVIDER_PRIORITY = [
|
|
|
3794
3809
|
"namespace",
|
|
3795
3810
|
"hopx",
|
|
3796
3811
|
"beam",
|
|
3797
|
-
"sprites"
|
|
3812
|
+
"sprites",
|
|
3813
|
+
"freestyle"
|
|
3798
3814
|
];
|
|
3799
3815
|
var PROVIDER_ENV_VARS = {
|
|
3800
3816
|
e2b: ["E2B_API_KEY"],
|
|
@@ -3811,6 +3827,7 @@ var PROVIDER_ENV_VARS = {
|
|
|
3811
3827
|
hopx: ["HOPX_API_KEY"],
|
|
3812
3828
|
beam: ["BEAM_TOKEN", "BEAM_WORKSPACE_ID"],
|
|
3813
3829
|
sprites: ["SPRITES_TOKEN"],
|
|
3830
|
+
freestyle: ["FREESTYLE_API_KEY"],
|
|
3814
3831
|
"just-bash": []
|
|
3815
3832
|
};
|
|
3816
3833
|
|
|
@@ -4010,7 +4027,7 @@ Or set COMPUTESDK_PROVIDER to specify explicitly:
|
|
|
4010
4027
|
Docs: https://computesdk.com/docs/quickstart`
|
|
4011
4028
|
);
|
|
4012
4029
|
}
|
|
4013
|
-
const gatewayUrl = process.env.
|
|
4030
|
+
const gatewayUrl = process.env.COMPUTESDK_TRIBUTARY_URL || TRIBUTARY_URL;
|
|
4014
4031
|
const computesdkApiKey = process.env.COMPUTESDK_API_KEY;
|
|
4015
4032
|
const providerHeaders = getProviderHeaders(provider);
|
|
4016
4033
|
try {
|
|
@@ -4020,7 +4037,7 @@ Docs: https://computesdk.com/docs/quickstart`
|
|
|
4020
4037
|
`Invalid gateway URL: "${gatewayUrl}"
|
|
4021
4038
|
|
|
4022
4039
|
The URL must be a valid HTTP/HTTPS URL.
|
|
4023
|
-
Check your
|
|
4040
|
+
Check your COMPUTESDK_TRIBUTARY_URL environment variable.`
|
|
4024
4041
|
);
|
|
4025
4042
|
}
|
|
4026
4043
|
if (process.env.COMPUTESDK_DEBUG) {
|
|
@@ -4116,7 +4133,7 @@ Get your API key at: https://computesdk.com/dashboard`
|
|
|
4116
4133
|
const providerHeaders = buildProviderHeaders2(config);
|
|
4117
4134
|
return {
|
|
4118
4135
|
apiKey: computesdkApiKey,
|
|
4119
|
-
gatewayUrl: config.gatewayUrl || process.env.
|
|
4136
|
+
gatewayUrl: config.gatewayUrl || process.env.COMPUTESDK_TRIBUTARY_URL || TRIBUTARY_URL,
|
|
4120
4137
|
provider: config.provider,
|
|
4121
4138
|
providerHeaders,
|
|
4122
4139
|
requestTimeoutMs: config.requestTimeoutMs,
|
|
@@ -4166,7 +4183,7 @@ Troubleshooting:
|
|
|
4166
4183
|
}
|
|
4167
4184
|
|
|
4168
4185
|
// src/compute.ts
|
|
4169
|
-
async function
|
|
4186
|
+
async function tributaryFetch(url, config, options = {}) {
|
|
4170
4187
|
const timeout = config.requestTimeoutMs ?? 3e4;
|
|
4171
4188
|
const controller = new AbortController();
|
|
4172
4189
|
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
@@ -4213,7 +4230,7 @@ async function waitForSandboxStatus(config, endpoint, body, options = {}) {
|
|
|
4213
4230
|
const startTime = Date.now();
|
|
4214
4231
|
let currentDelay = initialDelayMs;
|
|
4215
4232
|
while (Date.now() - startTime < maxWaitMs) {
|
|
4216
|
-
const result = await
|
|
4233
|
+
const result = await tributaryFetch(endpoint, config, {
|
|
4217
4234
|
method: "POST",
|
|
4218
4235
|
body: JSON.stringify(body)
|
|
4219
4236
|
});
|
|
@@ -4264,7 +4281,7 @@ var ComputeManager = class {
|
|
|
4264
4281
|
*/
|
|
4265
4282
|
create: async (options) => {
|
|
4266
4283
|
const config = this.getGatewayConfig();
|
|
4267
|
-
const result = await
|
|
4284
|
+
const result = await tributaryFetch(`${config.gatewayUrl}/v1/sandboxes`, config, {
|
|
4268
4285
|
method: "POST",
|
|
4269
4286
|
body: JSON.stringify(options || {})
|
|
4270
4287
|
});
|
|
@@ -4286,7 +4303,7 @@ var ComputeManager = class {
|
|
|
4286
4303
|
},
|
|
4287
4304
|
WebSocket: config.WebSocket || globalThis.WebSocket,
|
|
4288
4305
|
destroyHandler: async () => {
|
|
4289
|
-
await
|
|
4306
|
+
await tributaryFetch(`${config.gatewayUrl}/v1/sandboxes/${sandboxId}`, config, {
|
|
4290
4307
|
method: "DELETE"
|
|
4291
4308
|
});
|
|
4292
4309
|
}
|
|
@@ -4299,7 +4316,7 @@ var ComputeManager = class {
|
|
|
4299
4316
|
*/
|
|
4300
4317
|
getById: async (sandboxId) => {
|
|
4301
4318
|
const config = this.getGatewayConfig();
|
|
4302
|
-
const result = await
|
|
4319
|
+
const result = await tributaryFetch(`${config.gatewayUrl}/v1/sandboxes/${sandboxId}`, config);
|
|
4303
4320
|
if (!result.success || !result.data) {
|
|
4304
4321
|
return null;
|
|
4305
4322
|
}
|
|
@@ -4312,7 +4329,7 @@ var ComputeManager = class {
|
|
|
4312
4329
|
metadata,
|
|
4313
4330
|
WebSocket: config.WebSocket || globalThis.WebSocket,
|
|
4314
4331
|
destroyHandler: async () => {
|
|
4315
|
-
await
|
|
4332
|
+
await tributaryFetch(`${config.gatewayUrl}/v1/sandboxes/${sandboxId}`, config, {
|
|
4316
4333
|
method: "DELETE"
|
|
4317
4334
|
});
|
|
4318
4335
|
}
|
|
@@ -4333,7 +4350,7 @@ var ComputeManager = class {
|
|
|
4333
4350
|
*/
|
|
4334
4351
|
destroy: async (sandboxId) => {
|
|
4335
4352
|
const config = this.getGatewayConfig();
|
|
4336
|
-
await
|
|
4353
|
+
await tributaryFetch(`${config.gatewayUrl}/v1/sandboxes/${sandboxId}`, config, {
|
|
4337
4354
|
method: "DELETE"
|
|
4338
4355
|
});
|
|
4339
4356
|
},
|
|
@@ -4368,7 +4385,7 @@ var ComputeManager = class {
|
|
|
4368
4385
|
},
|
|
4369
4386
|
WebSocket: config.WebSocket || globalThis.WebSocket,
|
|
4370
4387
|
destroyHandler: async () => {
|
|
4371
|
-
await
|
|
4388
|
+
await tributaryFetch(`${config.gatewayUrl}/v1/sandboxes/${sandboxId}`, config, {
|
|
4372
4389
|
method: "DELETE"
|
|
4373
4390
|
});
|
|
4374
4391
|
}
|
|
@@ -4405,7 +4422,7 @@ var ComputeManager = class {
|
|
|
4405
4422
|
},
|
|
4406
4423
|
WebSocket: config.WebSocket || globalThis.WebSocket,
|
|
4407
4424
|
destroyHandler: async () => {
|
|
4408
|
-
await
|
|
4425
|
+
await tributaryFetch(`${config.gatewayUrl}/v1/sandboxes/${sandboxId}`, config, {
|
|
4409
4426
|
method: "DELETE"
|
|
4410
4427
|
});
|
|
4411
4428
|
}
|
|
@@ -4419,12 +4436,57 @@ var ComputeManager = class {
|
|
|
4419
4436
|
extendTimeout: async (sandboxId, options) => {
|
|
4420
4437
|
const config = this.getGatewayConfig();
|
|
4421
4438
|
const duration = options?.duration ?? 9e5;
|
|
4422
|
-
await
|
|
4439
|
+
await tributaryFetch(`${config.gatewayUrl}/v1/sandboxes/${sandboxId}/extend`, config, {
|
|
4423
4440
|
method: "POST",
|
|
4424
4441
|
body: JSON.stringify({ duration })
|
|
4425
4442
|
});
|
|
4426
4443
|
}
|
|
4427
4444
|
};
|
|
4445
|
+
this.snapshot = {
|
|
4446
|
+
/**
|
|
4447
|
+
* Create a snapshot from a running sandbox
|
|
4448
|
+
*
|
|
4449
|
+
* @param sandboxId ID of the sandbox to snapshot
|
|
4450
|
+
* @param options Snapshot options (name, metadata)
|
|
4451
|
+
*/
|
|
4452
|
+
create: async (sandboxId, options) => {
|
|
4453
|
+
const config = this.getGatewayConfig();
|
|
4454
|
+
const result = await tributaryFetch(`${config.gatewayUrl}/v1/snapshots`, config, {
|
|
4455
|
+
method: "POST",
|
|
4456
|
+
body: JSON.stringify({ sandboxId, ...options })
|
|
4457
|
+
});
|
|
4458
|
+
if (!result.success || !result.data) {
|
|
4459
|
+
throw new Error(`Gateway returned invalid response`);
|
|
4460
|
+
}
|
|
4461
|
+
return {
|
|
4462
|
+
...result.data,
|
|
4463
|
+
createdAt: new Date(result.data.createdAt)
|
|
4464
|
+
};
|
|
4465
|
+
},
|
|
4466
|
+
/**
|
|
4467
|
+
* List all snapshots
|
|
4468
|
+
*/
|
|
4469
|
+
list: async () => {
|
|
4470
|
+
const config = this.getGatewayConfig();
|
|
4471
|
+
const result = await tributaryFetch(`${config.gatewayUrl}/v1/snapshots`, config);
|
|
4472
|
+
if (!result.success || !result.data) {
|
|
4473
|
+
return [];
|
|
4474
|
+
}
|
|
4475
|
+
return result.data.map((s) => ({
|
|
4476
|
+
...s,
|
|
4477
|
+
createdAt: new Date(s.createdAt)
|
|
4478
|
+
}));
|
|
4479
|
+
},
|
|
4480
|
+
/**
|
|
4481
|
+
* Delete a snapshot
|
|
4482
|
+
*/
|
|
4483
|
+
delete: async (snapshotId) => {
|
|
4484
|
+
const config = this.getGatewayConfig();
|
|
4485
|
+
await tributaryFetch(`${config.gatewayUrl}/v1/snapshots/${snapshotId}`, config, {
|
|
4486
|
+
method: "DELETE"
|
|
4487
|
+
});
|
|
4488
|
+
}
|
|
4489
|
+
};
|
|
4428
4490
|
}
|
|
4429
4491
|
/**
|
|
4430
4492
|
* Lazy auto-configure from environment if not explicitly configured
|
|
@@ -4505,7 +4567,6 @@ var compute = new Proxy(
|
|
|
4505
4567
|
export {
|
|
4506
4568
|
CommandExitError,
|
|
4507
4569
|
FileWatcher,
|
|
4508
|
-
GATEWAY_URL,
|
|
4509
4570
|
Sandbox as GatewaySandbox,
|
|
4510
4571
|
MessageType,
|
|
4511
4572
|
PROVIDER_AUTH,
|
|
@@ -4517,6 +4578,7 @@ export {
|
|
|
4517
4578
|
PROVIDER_PRIORITY,
|
|
4518
4579
|
Sandbox,
|
|
4519
4580
|
SignalService,
|
|
4581
|
+
TRIBUTARY_URL,
|
|
4520
4582
|
TerminalInstance,
|
|
4521
4583
|
autoConfigureCompute,
|
|
4522
4584
|
buildProviderHeaders,
|