computesdk 1.18.1 → 1.19.0
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 +500 -270
- package/dist/index.d.ts +500 -270
- package/dist/index.js +163 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +161 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -37,10 +37,12 @@ __export(index_exports, {
|
|
|
37
37
|
TerminalInstance: () => TerminalInstance,
|
|
38
38
|
autoConfigureCompute: () => autoConfigureCompute,
|
|
39
39
|
buildProviderHeaders: () => buildProviderHeaders,
|
|
40
|
+
buildSetupPayload: () => buildSetupPayload,
|
|
40
41
|
compute: () => compute,
|
|
41
42
|
decodeBinaryMessage: () => decodeBinaryMessage,
|
|
42
43
|
detectProvider: () => detectProvider,
|
|
43
44
|
encodeBinaryMessage: () => encodeBinaryMessage,
|
|
45
|
+
encodeSetupPayload: () => encodeSetupPayload,
|
|
44
46
|
getMissingEnvVars: () => getMissingEnvVars,
|
|
45
47
|
getProviderConfigFromEnv: () => getProviderConfigFromEnv,
|
|
46
48
|
getProviderHeaders: () => getProviderHeaders,
|
|
@@ -1386,6 +1388,7 @@ var Server = class {
|
|
|
1386
1388
|
this.listHandler = handlers.list;
|
|
1387
1389
|
this.retrieveHandler = handlers.retrieve;
|
|
1388
1390
|
this.stopHandler = handlers.stop;
|
|
1391
|
+
this.deleteHandler = handlers.delete;
|
|
1389
1392
|
this.restartHandler = handlers.restart;
|
|
1390
1393
|
this.updateStatusHandler = handlers.updateStatus;
|
|
1391
1394
|
this.logsHandler = handlers.logs;
|
|
@@ -1451,12 +1454,19 @@ var Server = class {
|
|
|
1451
1454
|
return response.data.server;
|
|
1452
1455
|
}
|
|
1453
1456
|
/**
|
|
1454
|
-
* Stop a server by slug
|
|
1457
|
+
* Stop a server by slug (non-destructive)
|
|
1455
1458
|
* @param slug - The server slug
|
|
1456
1459
|
*/
|
|
1457
1460
|
async stop(slug) {
|
|
1458
1461
|
await this.stopHandler(slug);
|
|
1459
1462
|
}
|
|
1463
|
+
/**
|
|
1464
|
+
* Delete a server config by slug (stops + removes persistence)
|
|
1465
|
+
* @param slug - The server slug
|
|
1466
|
+
*/
|
|
1467
|
+
async delete(slug) {
|
|
1468
|
+
await this.deleteHandler(slug);
|
|
1469
|
+
}
|
|
1460
1470
|
/**
|
|
1461
1471
|
* Restart a server by slug
|
|
1462
1472
|
* @param slug - The server slug
|
|
@@ -1926,8 +1936,8 @@ var Child = class {
|
|
|
1926
1936
|
* Create a new child sandbox
|
|
1927
1937
|
* @returns Child sandbox info including URL and subdomain
|
|
1928
1938
|
*/
|
|
1929
|
-
async create() {
|
|
1930
|
-
return this.createHandler();
|
|
1939
|
+
async create(options) {
|
|
1940
|
+
return this.createHandler(options);
|
|
1931
1941
|
}
|
|
1932
1942
|
/**
|
|
1933
1943
|
* List all child sandboxes
|
|
@@ -2098,6 +2108,24 @@ Try increasing maxRetries or check if the source directory is very large.`
|
|
|
2098
2108
|
}
|
|
2099
2109
|
};
|
|
2100
2110
|
|
|
2111
|
+
// src/client/resources/ready.ts
|
|
2112
|
+
var Ready = class {
|
|
2113
|
+
constructor(handlers) {
|
|
2114
|
+
this.getHandler = handlers.get;
|
|
2115
|
+
}
|
|
2116
|
+
/**
|
|
2117
|
+
* Get readiness status for autostarted servers and overlays
|
|
2118
|
+
*/
|
|
2119
|
+
async get() {
|
|
2120
|
+
const response = await this.getHandler();
|
|
2121
|
+
return {
|
|
2122
|
+
ready: response.ready,
|
|
2123
|
+
servers: response.servers ?? [],
|
|
2124
|
+
overlays: response.overlays ?? []
|
|
2125
|
+
};
|
|
2126
|
+
}
|
|
2127
|
+
};
|
|
2128
|
+
|
|
2101
2129
|
// src/client/types.ts
|
|
2102
2130
|
var CommandExitError = class extends Error {
|
|
2103
2131
|
constructor(result) {
|
|
@@ -2249,12 +2277,18 @@ var Sandbox = class {
|
|
|
2249
2277
|
stop: async (slug) => {
|
|
2250
2278
|
await this.stopServer(slug);
|
|
2251
2279
|
},
|
|
2280
|
+
delete: async (slug) => {
|
|
2281
|
+
await this.deleteServer(slug);
|
|
2282
|
+
},
|
|
2252
2283
|
restart: async (slug) => this.restartServer(slug),
|
|
2253
2284
|
updateStatus: async (slug, status) => {
|
|
2254
2285
|
await this.updateServerStatus(slug, status);
|
|
2255
2286
|
},
|
|
2256
2287
|
logs: async (slug, options) => this.getServerLogs(slug, options)
|
|
2257
2288
|
});
|
|
2289
|
+
this.ready = new Ready({
|
|
2290
|
+
get: async () => this.getReady()
|
|
2291
|
+
});
|
|
2258
2292
|
this.watcher = new Watcher({
|
|
2259
2293
|
create: async (path, options) => this.createWatcher(path, options),
|
|
2260
2294
|
list: async () => this.listWatchers(),
|
|
@@ -2301,7 +2335,7 @@ var Sandbox = class {
|
|
|
2301
2335
|
info: async () => this.getAuthInfo()
|
|
2302
2336
|
});
|
|
2303
2337
|
this.child = new Child({
|
|
2304
|
-
create: async () => this.createSandbox(),
|
|
2338
|
+
create: async (options) => this.createSandbox(options),
|
|
2305
2339
|
list: async () => this.listSandboxes(),
|
|
2306
2340
|
retrieve: async (subdomain) => this.getSandbox(subdomain),
|
|
2307
2341
|
destroy: async (subdomain, deleteFiles) => this.deleteSandbox(subdomain, deleteFiles)
|
|
@@ -3164,6 +3198,12 @@ API request failed (${response.status}): ${error}`
|
|
|
3164
3198
|
* @param options.path - Working directory (optional)
|
|
3165
3199
|
* @param options.env_file - Path to .env file relative to path (optional)
|
|
3166
3200
|
* @param options.environment - Inline environment variables (merged with env_file if both provided)
|
|
3201
|
+
* @param options.port - Requested port (preallocated before start)
|
|
3202
|
+
* @param options.strict_port - If true, fail instead of auto-incrementing when port is taken
|
|
3203
|
+
* @param options.autostart - Auto-start on daemon boot (default: true)
|
|
3204
|
+
* @param options.overlay - Inline overlay to create before starting
|
|
3205
|
+
* @param options.overlays - Additional overlays to create before starting
|
|
3206
|
+
* @param options.depends_on - Overlay IDs this server depends on
|
|
3167
3207
|
* @param options.restart_policy - When to automatically restart: 'never' (default), 'on-failure', 'always'
|
|
3168
3208
|
* @param options.max_restarts - Maximum restart attempts, 0 = unlimited (default: 0)
|
|
3169
3209
|
* @param options.restart_delay_ms - Delay between restart attempts in milliseconds (default: 1000)
|
|
@@ -3190,6 +3230,18 @@ API request failed (${response.status}): ${error}`
|
|
|
3190
3230
|
* restart_delay_ms: 2000,
|
|
3191
3231
|
* stop_timeout_ms: 5000,
|
|
3192
3232
|
* });
|
|
3233
|
+
*
|
|
3234
|
+
* // With inline overlay dependencies
|
|
3235
|
+
* await sandbox.startServer({
|
|
3236
|
+
* slug: 'web',
|
|
3237
|
+
* start: 'npm run dev',
|
|
3238
|
+
* path: '/app',
|
|
3239
|
+
* overlay: {
|
|
3240
|
+
* source: '/templates/nextjs',
|
|
3241
|
+
* target: 'app',
|
|
3242
|
+
* strategy: 'smart',
|
|
3243
|
+
* },
|
|
3244
|
+
* });
|
|
3193
3245
|
* ```
|
|
3194
3246
|
*/
|
|
3195
3247
|
async startServer(options) {
|
|
@@ -3206,17 +3258,26 @@ API request failed (${response.status}): ${error}`
|
|
|
3206
3258
|
return this.request(`/servers/${encodeURIComponent(slug)}`);
|
|
3207
3259
|
}
|
|
3208
3260
|
/**
|
|
3209
|
-
* Stop a managed server
|
|
3261
|
+
* Stop a managed server (non-destructive)
|
|
3210
3262
|
* @param slug - Server slug
|
|
3211
3263
|
*/
|
|
3212
3264
|
async stopServer(slug) {
|
|
3213
3265
|
return this.request(
|
|
3214
|
-
`/servers/${encodeURIComponent(slug)}`,
|
|
3266
|
+
`/servers/${encodeURIComponent(slug)}/stop`,
|
|
3215
3267
|
{
|
|
3216
|
-
method: "
|
|
3268
|
+
method: "POST"
|
|
3217
3269
|
}
|
|
3218
3270
|
);
|
|
3219
3271
|
}
|
|
3272
|
+
/**
|
|
3273
|
+
* Delete a managed server configuration
|
|
3274
|
+
* @param slug - Server slug
|
|
3275
|
+
*/
|
|
3276
|
+
async deleteServer(slug) {
|
|
3277
|
+
await this.request(`/servers/${encodeURIComponent(slug)}`, {
|
|
3278
|
+
method: "DELETE"
|
|
3279
|
+
});
|
|
3280
|
+
}
|
|
3220
3281
|
/**
|
|
3221
3282
|
* Restart a managed server
|
|
3222
3283
|
* @param slug - Server slug
|
|
@@ -3259,15 +3320,29 @@ API request failed (${response.status}): ${error}`
|
|
|
3259
3320
|
);
|
|
3260
3321
|
}
|
|
3261
3322
|
// ============================================================================
|
|
3323
|
+
// Ready Management
|
|
3324
|
+
// ============================================================================
|
|
3325
|
+
/**
|
|
3326
|
+
* Get readiness status for autostarted servers and overlays
|
|
3327
|
+
*/
|
|
3328
|
+
async getReady() {
|
|
3329
|
+
const response = await this.request("/ready");
|
|
3330
|
+
return {
|
|
3331
|
+
ready: response.ready,
|
|
3332
|
+
servers: response.servers ?? [],
|
|
3333
|
+
overlays: response.overlays ?? []
|
|
3334
|
+
};
|
|
3335
|
+
}
|
|
3336
|
+
// ============================================================================
|
|
3262
3337
|
// Sandbox Management
|
|
3263
3338
|
// ============================================================================
|
|
3264
3339
|
/**
|
|
3265
3340
|
* Create a new sandbox environment
|
|
3266
3341
|
*/
|
|
3267
|
-
async createSandbox() {
|
|
3342
|
+
async createSandbox(options) {
|
|
3268
3343
|
return this.request("/sandboxes", {
|
|
3269
3344
|
method: "POST",
|
|
3270
|
-
body: JSON.stringify({})
|
|
3345
|
+
body: JSON.stringify(options || {})
|
|
3271
3346
|
});
|
|
3272
3347
|
}
|
|
3273
3348
|
/**
|
|
@@ -3501,6 +3576,42 @@ API request failed (${response.status}): ${error}`
|
|
|
3501
3576
|
}
|
|
3502
3577
|
};
|
|
3503
3578
|
|
|
3579
|
+
// src/setup.ts
|
|
3580
|
+
var encodeBase64 = (value) => {
|
|
3581
|
+
if (typeof Buffer !== "undefined") {
|
|
3582
|
+
return Buffer.from(value, "utf8").toString("base64");
|
|
3583
|
+
}
|
|
3584
|
+
if (typeof btoa !== "undefined" && typeof TextEncoder !== "undefined") {
|
|
3585
|
+
const bytes = new TextEncoder().encode(value);
|
|
3586
|
+
let binary = "";
|
|
3587
|
+
for (const byte of bytes) {
|
|
3588
|
+
binary += String.fromCharCode(byte);
|
|
3589
|
+
}
|
|
3590
|
+
return btoa(binary);
|
|
3591
|
+
}
|
|
3592
|
+
throw new Error("Base64 encoding is not supported in this environment.");
|
|
3593
|
+
};
|
|
3594
|
+
var buildSetupPayload = (options) => {
|
|
3595
|
+
const overlays = options.overlays?.map((overlay) => {
|
|
3596
|
+
const { source, target, ignore, strategy } = overlay;
|
|
3597
|
+
return {
|
|
3598
|
+
source,
|
|
3599
|
+
target,
|
|
3600
|
+
ignore,
|
|
3601
|
+
strategy
|
|
3602
|
+
};
|
|
3603
|
+
});
|
|
3604
|
+
const servers = options.servers;
|
|
3605
|
+
return {
|
|
3606
|
+
overlays: overlays?.length ? overlays : void 0,
|
|
3607
|
+
servers: servers?.length ? servers : void 0
|
|
3608
|
+
};
|
|
3609
|
+
};
|
|
3610
|
+
var encodeSetupPayload = (options) => {
|
|
3611
|
+
const payload = buildSetupPayload(options);
|
|
3612
|
+
return encodeBase64(JSON.stringify(payload));
|
|
3613
|
+
};
|
|
3614
|
+
|
|
3504
3615
|
// src/provider-config.ts
|
|
3505
3616
|
var PROVIDER_AUTH = {
|
|
3506
3617
|
e2b: [["E2B_API_KEY"]],
|
|
@@ -3515,7 +3626,8 @@ var PROVIDER_AUTH = {
|
|
|
3515
3626
|
runloop: [["RUNLOOP_API_KEY"]],
|
|
3516
3627
|
cloudflare: [["CLOUDFLARE_API_TOKEN", "CLOUDFLARE_ACCOUNT_ID"]],
|
|
3517
3628
|
codesandbox: [["CSB_API_KEY"]],
|
|
3518
|
-
blaxel: [["BL_API_KEY", "BL_WORKSPACE"]]
|
|
3629
|
+
blaxel: [["BL_API_KEY", "BL_WORKSPACE"]],
|
|
3630
|
+
namespace: [["NSC_TOKEN"]]
|
|
3519
3631
|
};
|
|
3520
3632
|
var PROVIDER_NAMES = Object.keys(PROVIDER_AUTH);
|
|
3521
3633
|
var PROVIDER_HEADERS = {
|
|
@@ -3557,6 +3669,9 @@ var PROVIDER_HEADERS = {
|
|
|
3557
3669
|
blaxel: {
|
|
3558
3670
|
apiKey: "X-BL-API-Key",
|
|
3559
3671
|
workspace: "X-BL-Workspace"
|
|
3672
|
+
},
|
|
3673
|
+
namespace: {
|
|
3674
|
+
token: "X-Namespace-Token"
|
|
3560
3675
|
}
|
|
3561
3676
|
};
|
|
3562
3677
|
var PROVIDER_ENV_MAP = {
|
|
@@ -3598,6 +3713,9 @@ var PROVIDER_ENV_MAP = {
|
|
|
3598
3713
|
blaxel: {
|
|
3599
3714
|
BL_API_KEY: "apiKey",
|
|
3600
3715
|
BL_WORKSPACE: "workspace"
|
|
3716
|
+
},
|
|
3717
|
+
namespace: {
|
|
3718
|
+
NSC_TOKEN: "token"
|
|
3601
3719
|
}
|
|
3602
3720
|
};
|
|
3603
3721
|
var PROVIDER_DASHBOARD_URLS = {
|
|
@@ -3610,7 +3728,8 @@ var PROVIDER_DASHBOARD_URLS = {
|
|
|
3610
3728
|
runloop: "https://runloop.ai/dashboard",
|
|
3611
3729
|
cloudflare: "https://dash.cloudflare.com/profile/api-tokens",
|
|
3612
3730
|
codesandbox: "https://codesandbox.io/dashboard/settings",
|
|
3613
|
-
blaxel: "https://blaxel.ai/dashboard"
|
|
3731
|
+
blaxel: "https://blaxel.ai/dashboard",
|
|
3732
|
+
namespace: "https://cloud.namespace.so"
|
|
3614
3733
|
};
|
|
3615
3734
|
function isValidProvider(name) {
|
|
3616
3735
|
return name in PROVIDER_AUTH;
|
|
@@ -3678,7 +3797,8 @@ var PROVIDER_PRIORITY = [
|
|
|
3678
3797
|
"vercel",
|
|
3679
3798
|
"cloudflare",
|
|
3680
3799
|
"codesandbox",
|
|
3681
|
-
"blaxel"
|
|
3800
|
+
"blaxel",
|
|
3801
|
+
"namespace"
|
|
3682
3802
|
];
|
|
3683
3803
|
var PROVIDER_ENV_VARS = {
|
|
3684
3804
|
e2b: ["E2B_API_KEY"],
|
|
@@ -3690,7 +3810,8 @@ var PROVIDER_ENV_VARS = {
|
|
|
3690
3810
|
vercel: ["VERCEL_TOKEN", "VERCEL_TEAM_ID", "VERCEL_PROJECT_ID"],
|
|
3691
3811
|
cloudflare: ["CLOUDFLARE_API_TOKEN", "CLOUDFLARE_ACCOUNT_ID"],
|
|
3692
3812
|
codesandbox: ["CSB_API_KEY"],
|
|
3693
|
-
blaxel: ["BL_API_KEY", "BL_WORKSPACE"]
|
|
3813
|
+
blaxel: ["BL_API_KEY", "BL_WORKSPACE"],
|
|
3814
|
+
namespace: ["NSC_TOKEN"]
|
|
3694
3815
|
};
|
|
3695
3816
|
|
|
3696
3817
|
// src/auto-detect.ts
|
|
@@ -3807,6 +3928,11 @@ function getProviderHeaders(provider) {
|
|
|
3807
3928
|
headers["X-Blaxel-Workspace"] = process.env.BL_WORKSPACE;
|
|
3808
3929
|
}
|
|
3809
3930
|
break;
|
|
3931
|
+
case "namespace":
|
|
3932
|
+
if (process.env.NSC_TOKEN) {
|
|
3933
|
+
headers["X-Namespace-Token"] = process.env.NSC_TOKEN;
|
|
3934
|
+
}
|
|
3935
|
+
break;
|
|
3810
3936
|
}
|
|
3811
3937
|
return headers;
|
|
3812
3938
|
}
|
|
@@ -3843,6 +3969,7 @@ To fix this, set one of the following:
|
|
|
3843
3969
|
Cloudflare: export CLOUDFLARE_API_TOKEN=xxx CLOUDFLARE_ACCOUNT_ID=xxx
|
|
3844
3970
|
CodeSandbox: export CSB_API_KEY=xxx
|
|
3845
3971
|
Blaxel: export BL_API_KEY=xxx BL_WORKSPACE=xxx
|
|
3972
|
+
Namespace: export NSC_TOKEN=xxx
|
|
3846
3973
|
|
|
3847
3974
|
Or set COMPUTESDK_PROVIDER to specify explicitly:
|
|
3848
3975
|
export COMPUTESDK_PROVIDER=e2b
|
|
@@ -4079,6 +4206,27 @@ var ComputeManager = class {
|
|
|
4079
4206
|
this.sandbox = {
|
|
4080
4207
|
/**
|
|
4081
4208
|
* Create a new sandbox
|
|
4209
|
+
*
|
|
4210
|
+
* @example
|
|
4211
|
+
* ```typescript
|
|
4212
|
+
* const sandbox = await compute.sandbox.create({
|
|
4213
|
+
* directory: '/custom/path',
|
|
4214
|
+
* overlays: [
|
|
4215
|
+
* {
|
|
4216
|
+
* source: '/templates/nextjs',
|
|
4217
|
+
* target: 'app',
|
|
4218
|
+
* strategy: 'smart',
|
|
4219
|
+
* },
|
|
4220
|
+
* ],
|
|
4221
|
+
* servers: [
|
|
4222
|
+
* {
|
|
4223
|
+
* slug: 'web',
|
|
4224
|
+
* start: 'npm run dev',
|
|
4225
|
+
* path: '/app',
|
|
4226
|
+
* },
|
|
4227
|
+
* ],
|
|
4228
|
+
* });
|
|
4229
|
+
* ```
|
|
4082
4230
|
*/
|
|
4083
4231
|
create: async (options) => {
|
|
4084
4232
|
const config = this.getGatewayConfig();
|
|
@@ -4337,10 +4485,12 @@ var compute = new Proxy(
|
|
|
4337
4485
|
TerminalInstance,
|
|
4338
4486
|
autoConfigureCompute,
|
|
4339
4487
|
buildProviderHeaders,
|
|
4488
|
+
buildSetupPayload,
|
|
4340
4489
|
compute,
|
|
4341
4490
|
decodeBinaryMessage,
|
|
4342
4491
|
detectProvider,
|
|
4343
4492
|
encodeBinaryMessage,
|
|
4493
|
+
encodeSetupPayload,
|
|
4344
4494
|
getMissingEnvVars,
|
|
4345
4495
|
getProviderConfigFromEnv,
|
|
4346
4496
|
getProviderHeaders,
|