@declaw/sdk 1.1.2 → 1.1.4

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/CHANGELOG.md CHANGED
@@ -5,6 +5,26 @@ All notable changes to the Declaw TypeScript / JavaScript SDK are documented in
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.1.4]
9
+
10
+ ### Changed
11
+
12
+ - Enable HTTP/2 multiplexing on the Node dispatcher (`allowH2: true`).
13
+
14
+ ## [1.1.3]
15
+
16
+ ### Changed
17
+
18
+ - **Higher-concurrency HTTP dispatcher on Node.** The SDK now installs a
19
+ module-level `undici.Agent` (128 connections per origin, keep-alive
20
+ tuned) on first use under Node, so callers fanning out many concurrent
21
+ requests are no longer capped by undici's default 10 connections per
22
+ origin. On runtimes that don't ship `undici` (browsers, Cloudflare
23
+ Workers, Deno) the dynamic import silently no-ops and the platform's
24
+ native `fetch` is used unchanged. Opt out with
25
+ `DECLAW_SDK_DISABLE_DISPATCHER=1` if you bring your own dispatcher.
26
+ `undici` is declared as an `optionalDependency`.
27
+
8
28
  ## [1.1.2]
9
29
 
10
30
  ### Fixed
package/dist/index.cjs CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
 
20
30
  // src/index.ts
@@ -223,6 +233,37 @@ var CommandExitError = class extends SandboxError {
223
233
  };
224
234
 
225
235
  // src/api/client.ts
236
+ var _dispatcherPromise;
237
+ function getDispatcher() {
238
+ if (_dispatcherPromise) return _dispatcherPromise;
239
+ _dispatcherPromise = (async () => {
240
+ try {
241
+ if (typeof process === "undefined" || !process.versions?.node) {
242
+ return void 0;
243
+ }
244
+ if (process.env.DECLAW_SDK_DISABLE_DISPATCHER) {
245
+ return void 0;
246
+ }
247
+ const origEmit = process.emitWarning;
248
+ process.emitWarning = ((warning, ...rest) => {
249
+ if (rest[0] === "UNDICI-H2") return;
250
+ return origEmit.call(process, warning, ...rest);
251
+ });
252
+ const undici = await import("undici");
253
+ return new undici.Agent({
254
+ connections: 10,
255
+ keepAliveTimeout: 3e4,
256
+ keepAliveMaxTimeout: 6e4,
257
+ pipelining: 1,
258
+ allowH2: true,
259
+ connect: { keepAlive: true, keepAliveInitialDelay: 5e3 }
260
+ });
261
+ } catch {
262
+ return void 0;
263
+ }
264
+ })();
265
+ return _dispatcherPromise;
266
+ }
226
267
  var STATUS_ERROR_MAP = {
227
268
  401: AuthenticationError,
228
269
  403: AuthenticationError,
@@ -333,12 +374,15 @@ var ApiClient = class {
333
374
  signals.push(AbortSignal.timeout(timeoutMs));
334
375
  }
335
376
  const signal = signals.length === 1 ? signals[0] : AbortSignal.any(signals);
336
- const response = await fetch(url, {
377
+ const dispatcher = await getDispatcher();
378
+ const fetchOpts = {
337
379
  method,
338
380
  headers,
339
381
  body: fetchBody,
340
382
  signal
341
- });
383
+ };
384
+ if (dispatcher) fetchOpts.dispatcher = dispatcher;
385
+ const response = await fetch(url, fetchOpts);
342
386
  if (response.status >= 500 && attempt < this.maxRetries - 1) {
343
387
  await this.delay(attempt);
344
388
  continue;
@@ -2226,6 +2270,27 @@ var Sandbox = class _Sandbox {
2226
2270
  const raw = data.snapshots ?? [];
2227
2271
  return raw.map((s) => parseSnapshot(s));
2228
2272
  }
2273
+ /**
2274
+ * Delete a single snapshot of this sandbox by ID.
2275
+ *
2276
+ * The snapshot's PG row and S3 blobs (mem / vmstate / overlay) are
2277
+ * removed. Idempotent: deleting an already-deleted snapshot resolves to
2278
+ * true without throwing.
2279
+ *
2280
+ * The pause snapshot of a currently-paused sandbox is protected — the
2281
+ * server returns 409 because deletion would break Resume. Resume or
2282
+ * kill the sandbox first.
2283
+ *
2284
+ * @param snapshotId - The snapshot to delete.
2285
+ * @param requestTimeout - Optional per-request timeout in milliseconds.
2286
+ * @returns True on success.
2287
+ */
2288
+ async deleteSnapshot(snapshotId, requestTimeout) {
2289
+ await this._client.delete(`/sandboxes/${this._sandboxId}/snapshots/${snapshotId}`, {
2290
+ timeout: requestTimeout
2291
+ });
2292
+ return true;
2293
+ }
2229
2294
  /**
2230
2295
  * Restore a sandbox from a snapshot. The restored instance may run on a
2231
2296
  * different worker node than the original sandbox.
@@ -2410,11 +2475,30 @@ var TemplateBase = class {
2410
2475
  _envs = {};
2411
2476
  _aptPackages = [];
2412
2477
  _startCmd;
2478
+ /**
2479
+ * When set, the server uses this Dockerfile verbatim and ignores the
2480
+ * structured fields. Use for multi-stage builds, ARG, ONBUILD, etc.
2481
+ */
2482
+ _dockerfile;
2413
2483
  /** Set the base image for the template. */
2414
2484
  fromBaseImage(image) {
2415
2485
  this._baseImage = image ?? "ubuntu:22.04";
2416
2486
  return this;
2417
2487
  }
2488
+ /**
2489
+ * Use a raw Dockerfile string instead of the structured helpers.
2490
+ *
2491
+ * When set, all other ``aptInstall`` / ``runCmd`` / ``setEnvs`` /
2492
+ * ``copy`` / ``setStartCmd`` / ``fromBaseImage`` calls on this spec
2493
+ * are ignored — the Dockerfile is sent to the build worker verbatim.
2494
+ *
2495
+ * @param content Full Dockerfile contents. Must contain a ``FROM``
2496
+ * instruction. Capped server-side at 64 KiB.
2497
+ */
2498
+ fromDockerfile(content) {
2499
+ this._dockerfile = content;
2500
+ return this;
2501
+ }
2418
2502
  /** Add a run command (as array of command + args). */
2419
2503
  runCmd(cmds) {
2420
2504
  this._runCmds.push(cmds);
@@ -2442,11 +2526,14 @@ var TemplateBase = class {
2442
2526
  }
2443
2527
  /** Serialize the template to a JSON-friendly object. */
2444
2528
  toJSON() {
2529
+ if (this._dockerfile !== void 0) {
2530
+ return { dockerfile: this._dockerfile };
2531
+ }
2445
2532
  const result = {
2446
2533
  base_image: this._baseImage
2447
2534
  };
2448
2535
  if (this._runCmds.length > 0) {
2449
- result.run_cmds = this._runCmds;
2536
+ result.run_cmds = this._runCmds.map((c) => c.join(" "));
2450
2537
  }
2451
2538
  if (this._copies.length > 0) {
2452
2539
  result.copies = this._copies;