computesdk 1.18.2 → 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.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: "DELETE"
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"]],
@@ -4095,6 +4206,27 @@ var ComputeManager = class {
4095
4206
  this.sandbox = {
4096
4207
  /**
4097
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
+ * ```
4098
4230
  */
4099
4231
  create: async (options) => {
4100
4232
  const config = this.getGatewayConfig();
@@ -4353,10 +4485,12 @@ var compute = new Proxy(
4353
4485
  TerminalInstance,
4354
4486
  autoConfigureCompute,
4355
4487
  buildProviderHeaders,
4488
+ buildSetupPayload,
4356
4489
  compute,
4357
4490
  decodeBinaryMessage,
4358
4491
  detectProvider,
4359
4492
  encodeBinaryMessage,
4493
+ encodeSetupPayload,
4360
4494
  getMissingEnvVars,
4361
4495
  getProviderConfigFromEnv,
4362
4496
  getProviderHeaders,