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.mjs CHANGED
@@ -1333,6 +1333,7 @@ var Server = class {
1333
1333
  this.listHandler = handlers.list;
1334
1334
  this.retrieveHandler = handlers.retrieve;
1335
1335
  this.stopHandler = handlers.stop;
1336
+ this.deleteHandler = handlers.delete;
1336
1337
  this.restartHandler = handlers.restart;
1337
1338
  this.updateStatusHandler = handlers.updateStatus;
1338
1339
  this.logsHandler = handlers.logs;
@@ -1398,12 +1399,19 @@ var Server = class {
1398
1399
  return response.data.server;
1399
1400
  }
1400
1401
  /**
1401
- * Stop a server by slug
1402
+ * Stop a server by slug (non-destructive)
1402
1403
  * @param slug - The server slug
1403
1404
  */
1404
1405
  async stop(slug) {
1405
1406
  await this.stopHandler(slug);
1406
1407
  }
1408
+ /**
1409
+ * Delete a server config by slug (stops + removes persistence)
1410
+ * @param slug - The server slug
1411
+ */
1412
+ async delete(slug) {
1413
+ await this.deleteHandler(slug);
1414
+ }
1407
1415
  /**
1408
1416
  * Restart a server by slug
1409
1417
  * @param slug - The server slug
@@ -1873,8 +1881,8 @@ var Child = class {
1873
1881
  * Create a new child sandbox
1874
1882
  * @returns Child sandbox info including URL and subdomain
1875
1883
  */
1876
- async create() {
1877
- return this.createHandler();
1884
+ async create(options) {
1885
+ return this.createHandler(options);
1878
1886
  }
1879
1887
  /**
1880
1888
  * List all child sandboxes
@@ -2045,6 +2053,24 @@ Try increasing maxRetries or check if the source directory is very large.`
2045
2053
  }
2046
2054
  };
2047
2055
 
2056
+ // src/client/resources/ready.ts
2057
+ var Ready = class {
2058
+ constructor(handlers) {
2059
+ this.getHandler = handlers.get;
2060
+ }
2061
+ /**
2062
+ * Get readiness status for autostarted servers and overlays
2063
+ */
2064
+ async get() {
2065
+ const response = await this.getHandler();
2066
+ return {
2067
+ ready: response.ready,
2068
+ servers: response.servers ?? [],
2069
+ overlays: response.overlays ?? []
2070
+ };
2071
+ }
2072
+ };
2073
+
2048
2074
  // src/client/types.ts
2049
2075
  var CommandExitError = class extends Error {
2050
2076
  constructor(result) {
@@ -2196,12 +2222,18 @@ var Sandbox = class {
2196
2222
  stop: async (slug) => {
2197
2223
  await this.stopServer(slug);
2198
2224
  },
2225
+ delete: async (slug) => {
2226
+ await this.deleteServer(slug);
2227
+ },
2199
2228
  restart: async (slug) => this.restartServer(slug),
2200
2229
  updateStatus: async (slug, status) => {
2201
2230
  await this.updateServerStatus(slug, status);
2202
2231
  },
2203
2232
  logs: async (slug, options) => this.getServerLogs(slug, options)
2204
2233
  });
2234
+ this.ready = new Ready({
2235
+ get: async () => this.getReady()
2236
+ });
2205
2237
  this.watcher = new Watcher({
2206
2238
  create: async (path, options) => this.createWatcher(path, options),
2207
2239
  list: async () => this.listWatchers(),
@@ -2248,7 +2280,7 @@ var Sandbox = class {
2248
2280
  info: async () => this.getAuthInfo()
2249
2281
  });
2250
2282
  this.child = new Child({
2251
- create: async () => this.createSandbox(),
2283
+ create: async (options) => this.createSandbox(options),
2252
2284
  list: async () => this.listSandboxes(),
2253
2285
  retrieve: async (subdomain) => this.getSandbox(subdomain),
2254
2286
  destroy: async (subdomain, deleteFiles) => this.deleteSandbox(subdomain, deleteFiles)
@@ -3111,6 +3143,12 @@ API request failed (${response.status}): ${error}`
3111
3143
  * @param options.path - Working directory (optional)
3112
3144
  * @param options.env_file - Path to .env file relative to path (optional)
3113
3145
  * @param options.environment - Inline environment variables (merged with env_file if both provided)
3146
+ * @param options.port - Requested port (preallocated before start)
3147
+ * @param options.strict_port - If true, fail instead of auto-incrementing when port is taken
3148
+ * @param options.autostart - Auto-start on daemon boot (default: true)
3149
+ * @param options.overlay - Inline overlay to create before starting
3150
+ * @param options.overlays - Additional overlays to create before starting
3151
+ * @param options.depends_on - Overlay IDs this server depends on
3114
3152
  * @param options.restart_policy - When to automatically restart: 'never' (default), 'on-failure', 'always'
3115
3153
  * @param options.max_restarts - Maximum restart attempts, 0 = unlimited (default: 0)
3116
3154
  * @param options.restart_delay_ms - Delay between restart attempts in milliseconds (default: 1000)
@@ -3137,6 +3175,18 @@ API request failed (${response.status}): ${error}`
3137
3175
  * restart_delay_ms: 2000,
3138
3176
  * stop_timeout_ms: 5000,
3139
3177
  * });
3178
+ *
3179
+ * // With inline overlay dependencies
3180
+ * await sandbox.startServer({
3181
+ * slug: 'web',
3182
+ * start: 'npm run dev',
3183
+ * path: '/app',
3184
+ * overlay: {
3185
+ * source: '/templates/nextjs',
3186
+ * target: 'app',
3187
+ * strategy: 'smart',
3188
+ * },
3189
+ * });
3140
3190
  * ```
3141
3191
  */
3142
3192
  async startServer(options) {
@@ -3153,17 +3203,26 @@ API request failed (${response.status}): ${error}`
3153
3203
  return this.request(`/servers/${encodeURIComponent(slug)}`);
3154
3204
  }
3155
3205
  /**
3156
- * Stop a managed server
3206
+ * Stop a managed server (non-destructive)
3157
3207
  * @param slug - Server slug
3158
3208
  */
3159
3209
  async stopServer(slug) {
3160
3210
  return this.request(
3161
- `/servers/${encodeURIComponent(slug)}`,
3211
+ `/servers/${encodeURIComponent(slug)}/stop`,
3162
3212
  {
3163
- method: "DELETE"
3213
+ method: "POST"
3164
3214
  }
3165
3215
  );
3166
3216
  }
3217
+ /**
3218
+ * Delete a managed server configuration
3219
+ * @param slug - Server slug
3220
+ */
3221
+ async deleteServer(slug) {
3222
+ await this.request(`/servers/${encodeURIComponent(slug)}`, {
3223
+ method: "DELETE"
3224
+ });
3225
+ }
3167
3226
  /**
3168
3227
  * Restart a managed server
3169
3228
  * @param slug - Server slug
@@ -3206,15 +3265,29 @@ API request failed (${response.status}): ${error}`
3206
3265
  );
3207
3266
  }
3208
3267
  // ============================================================================
3268
+ // Ready Management
3269
+ // ============================================================================
3270
+ /**
3271
+ * Get readiness status for autostarted servers and overlays
3272
+ */
3273
+ async getReady() {
3274
+ const response = await this.request("/ready");
3275
+ return {
3276
+ ready: response.ready,
3277
+ servers: response.servers ?? [],
3278
+ overlays: response.overlays ?? []
3279
+ };
3280
+ }
3281
+ // ============================================================================
3209
3282
  // Sandbox Management
3210
3283
  // ============================================================================
3211
3284
  /**
3212
3285
  * Create a new sandbox environment
3213
3286
  */
3214
- async createSandbox() {
3287
+ async createSandbox(options) {
3215
3288
  return this.request("/sandboxes", {
3216
3289
  method: "POST",
3217
- body: JSON.stringify({})
3290
+ body: JSON.stringify(options || {})
3218
3291
  });
3219
3292
  }
3220
3293
  /**
@@ -3448,6 +3521,42 @@ API request failed (${response.status}): ${error}`
3448
3521
  }
3449
3522
  };
3450
3523
 
3524
+ // src/setup.ts
3525
+ var encodeBase64 = (value) => {
3526
+ if (typeof Buffer !== "undefined") {
3527
+ return Buffer.from(value, "utf8").toString("base64");
3528
+ }
3529
+ if (typeof btoa !== "undefined" && typeof TextEncoder !== "undefined") {
3530
+ const bytes = new TextEncoder().encode(value);
3531
+ let binary = "";
3532
+ for (const byte of bytes) {
3533
+ binary += String.fromCharCode(byte);
3534
+ }
3535
+ return btoa(binary);
3536
+ }
3537
+ throw new Error("Base64 encoding is not supported in this environment.");
3538
+ };
3539
+ var buildSetupPayload = (options) => {
3540
+ const overlays = options.overlays?.map((overlay) => {
3541
+ const { source, target, ignore, strategy } = overlay;
3542
+ return {
3543
+ source,
3544
+ target,
3545
+ ignore,
3546
+ strategy
3547
+ };
3548
+ });
3549
+ const servers = options.servers;
3550
+ return {
3551
+ overlays: overlays?.length ? overlays : void 0,
3552
+ servers: servers?.length ? servers : void 0
3553
+ };
3554
+ };
3555
+ var encodeSetupPayload = (options) => {
3556
+ const payload = buildSetupPayload(options);
3557
+ return encodeBase64(JSON.stringify(payload));
3558
+ };
3559
+
3451
3560
  // src/provider-config.ts
3452
3561
  var PROVIDER_AUTH = {
3453
3562
  e2b: [["E2B_API_KEY"]],
@@ -4042,6 +4151,27 @@ var ComputeManager = class {
4042
4151
  this.sandbox = {
4043
4152
  /**
4044
4153
  * Create a new sandbox
4154
+ *
4155
+ * @example
4156
+ * ```typescript
4157
+ * const sandbox = await compute.sandbox.create({
4158
+ * directory: '/custom/path',
4159
+ * overlays: [
4160
+ * {
4161
+ * source: '/templates/nextjs',
4162
+ * target: 'app',
4163
+ * strategy: 'smart',
4164
+ * },
4165
+ * ],
4166
+ * servers: [
4167
+ * {
4168
+ * slug: 'web',
4169
+ * start: 'npm run dev',
4170
+ * path: '/app',
4171
+ * },
4172
+ * ],
4173
+ * });
4174
+ * ```
4045
4175
  */
4046
4176
  create: async (options) => {
4047
4177
  const config = this.getGatewayConfig();
@@ -4299,10 +4429,12 @@ export {
4299
4429
  TerminalInstance,
4300
4430
  autoConfigureCompute,
4301
4431
  buildProviderHeaders,
4432
+ buildSetupPayload,
4302
4433
  compute,
4303
4434
  decodeBinaryMessage,
4304
4435
  detectProvider,
4305
4436
  encodeBinaryMessage,
4437
+ encodeSetupPayload,
4306
4438
  getMissingEnvVars,
4307
4439
  getProviderConfigFromEnv,
4308
4440
  getProviderHeaders,