disk 1.5.0 → 1.6.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/cli.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { O as ArchilApiError, a as deleteApiKey, l as listApiKeys, n as createApiKey, r as createDisk, s as getDisk, t as configure, u as listDisks } from "./src-r2oVqVK_.mjs";
3
- import { a as renderTable, i as resolveProgramCredentials, n as addProfileCommands, r as isProfileCommand, t as addGlobalOptions } from "./common-Bi2YnNf6.mjs";
2
+ import { O as ArchilApiError, a as deleteApiKey, l as listApiKeys, n as createApiKey, r as createDisk, s as getDisk, t as configure, u as listDisks } from "./src-CxdnwAiv.mjs";
3
+ import { a as renderTable, i as resolveProgramCredentials, n as addProfileCommands, r as isProfileCommand, t as addGlobalOptions } from "./common-DglyXr-d.mjs";
4
4
  import { createRequire } from "node:module";
5
5
  import { Command } from "commander";
6
6
  //#region bin/cli.ts
@@ -1,4 +1,4 @@
1
- import { D as REGION_URLS, p as Archil } from "./src-r2oVqVK_.mjs";
1
+ import { D as REGION_URLS, p as Archil } from "./src-CxdnwAiv.mjs";
2
2
  import { Option } from "commander";
3
3
  import { isCancel, password, spinner } from "@clack/prompts";
4
4
  import { chmod, mkdir, open, readFile, rename, rm, stat } from "node:fs/promises";
package/dist/index.cjs CHANGED
@@ -153,7 +153,7 @@ function deriveS3BaseUrl(controlBaseUrl) {
153
153
  }
154
154
  //#endregion
155
155
  //#region src/version.ts
156
- const VERSION = "1.5.0";
156
+ const VERSION = "1.6.0";
157
157
  const USER_AGENT = `archil-js/${VERSION}`;
158
158
  //#endregion
159
159
  //#region src/client.ts
@@ -163,7 +163,7 @@ function isNodeRuntime() {
163
163
  }
164
164
  const undiciModule = isNodeRuntime() ? import("undici") : void 0;
165
165
  const CONTROL_PLANE_CONNECTIONS = 1;
166
- const CONTROL_PLANE_CONCURRENT_STREAMS = 100;
166
+ const IDLE_SESSION_TIMEOUT_MS = 3e4;
167
167
  function isAsyncIterableBody(body) {
168
168
  return body != null && typeof body === "object" && Symbol.asyncIterator in body;
169
169
  }
@@ -172,30 +172,12 @@ async function bufferBody(body) {
172
172
  for await (const chunk of body) chunks.push(typeof chunk === "string" ? Buffer.from(chunk) : chunk);
173
173
  return Buffer.concat(chunks);
174
174
  }
175
- const multiplexHttp2Requests = (dispatch) => (options, handler) => {
176
- let requestStarted = false;
177
- const guardedHandler = {
178
- onRequestStart(controller, context) {
179
- if (requestStarted) {
180
- controller.abort(/* @__PURE__ */ new Error("Archil control-plane requests are not replayed after a connection failure"));
181
- return;
182
- }
183
- requestStarted = true;
184
- handler.onRequestStart?.(controller, context);
185
- },
186
- onRequestUpgrade: handler.onRequestUpgrade?.bind(handler),
187
- onResponseStart: handler.onResponseStart?.bind(handler),
188
- onResponseData: handler.onResponseData?.bind(handler),
189
- onResponseEnd: handler.onResponseEnd?.bind(handler),
190
- onResponseError: handler.onResponseError?.bind(handler)
191
- };
192
- const dispatchBody = (body) => dispatch({
175
+ const bufferRequestBodies = (dispatch) => (options, handler) => {
176
+ if (!isAsyncIterableBody(options.body)) return dispatch(options, handler);
177
+ bufferBody(options.body).then((body) => dispatch({
193
178
  ...options,
194
- body,
195
- idempotent: true
196
- }, guardedHandler);
197
- if (!isAsyncIterableBody(options.body)) return dispatchBody(options.body);
198
- bufferBody(options.body).then(dispatchBody, (error) => handler.onResponseError?.({
179
+ body
180
+ }, handler), (error) => handler.onResponseError?.({
199
181
  aborted: false,
200
182
  paused: false,
201
183
  reason: null,
@@ -205,7 +187,7 @@ const multiplexHttp2Requests = (dispatch) => (options, handler) => {
205
187
  }, error instanceof Error ? error : new Error(String(error))));
206
188
  return true;
207
189
  };
208
- const sharedDispatchers = /* @__PURE__ */ new Map();
190
+ const sharedTransports = /* @__PURE__ */ new Map();
209
191
  function dispatcherKey(baseUrl, apiKey, ca) {
210
192
  return JSON.stringify([
211
193
  new URL(baseUrl).origin,
@@ -213,26 +195,27 @@ function dispatcherKey(baseUrl, apiKey, ca) {
213
195
  ca?.map((cert) => cert.toString("base64"))
214
196
  ]);
215
197
  }
216
- function getSharedDispatcher(key, ca) {
217
- const existing = sharedDispatchers.get(key);
198
+ function getSharedTransport(key, ca) {
199
+ const existing = sharedTransports.get(key);
218
200
  if (existing) return existing;
219
- const dispatcher = (async () => {
201
+ const transport = (async () => {
220
202
  if (!undiciModule) throw new Error("The pooled control-plane transport requires Node.js");
221
- const { Agent } = await undiciModule;
222
- return new Agent({
223
- allowH2: true,
224
- connections: CONTROL_PLANE_CONNECTIONS,
225
- pipelining: CONTROL_PLANE_CONCURRENT_STREAMS,
226
- keepAliveTimeout: 6e4,
227
- keepAliveMaxTimeout: 6e5,
228
- ...ca === void 0 ? {} : { connect: { ca } }
229
- }).compose(multiplexHttp2Requests);
203
+ const { Agent, fetch } = await undiciModule;
204
+ return {
205
+ fetch,
206
+ dispatcher: new Agent({
207
+ allowH2: true,
208
+ connections: CONTROL_PLANE_CONNECTIONS,
209
+ keepAliveTimeout: IDLE_SESSION_TIMEOUT_MS,
210
+ ...ca === void 0 ? {} : { connect: { ca } }
211
+ }).compose(bufferRequestBodies)
212
+ };
230
213
  })();
231
- sharedDispatchers.set(key, dispatcher);
232
- dispatcher.catch(() => {
233
- if (sharedDispatchers.get(key) === dispatcher) sharedDispatchers.delete(key);
214
+ sharedTransports.set(key, transport);
215
+ transport.catch(() => {
216
+ if (sharedTransports.get(key) === transport) sharedTransports.delete(key);
234
217
  });
235
- return dispatcher;
218
+ return transport;
236
219
  }
237
220
  function createPooledFetch(baseUrl, apiKey, tls) {
238
221
  if (!isNodeRuntime()) {
@@ -242,8 +225,16 @@ function createPooledFetch(baseUrl, apiKey, tls) {
242
225
  const ca = tls?.ca === void 0 ? void 0 : (Array.isArray(tls.ca) ? tls.ca : [tls.ca]).map((cert) => Buffer.from(cert));
243
226
  const key = dispatcherKey(baseUrl, apiKey, ca);
244
227
  return async (request) => {
245
- const dispatcher = await getSharedDispatcher(key, ca);
246
- return globalThis.fetch(request, { dispatcher });
228
+ const { fetch, dispatcher } = await getSharedTransport(key, ca);
229
+ const body = request.body === null ? null : new Uint8Array(await request.arrayBuffer());
230
+ return await fetch(request.url, {
231
+ method: request.method,
232
+ headers: [...request.headers],
233
+ body,
234
+ redirect: request.redirect,
235
+ signal: request.signal,
236
+ dispatcher
237
+ });
247
238
  };
248
239
  }
249
240
  function createApiClient(opts) {
@@ -429,28 +420,28 @@ var Disk = class {
429
420
  };
430
421
  }
431
422
  async addUser(user) {
432
- return unwrap(this._client.POST("/api/disks/{id}/users", {
423
+ return unwrap(retryApiRequest(() => this._client.POST("/api/disks/{id}/users", {
433
424
  params: { path: { id: this.id } },
434
425
  body: user
435
- }));
426
+ }), "connect"));
436
427
  }
437
428
  async removeUser(userType, identifier) {
438
- await unwrapEmpty(this._client.DELETE("/api/disks/{id}/users/{userType}", { params: {
429
+ await unwrapEmpty(retryApiRequest(() => this._client.DELETE("/api/disks/{id}/users/{userType}", { params: {
439
430
  path: {
440
431
  id: this.id,
441
432
  userType
442
433
  },
443
434
  query: { identifier }
444
- } }));
435
+ } }), "connect"));
445
436
  }
446
437
  async createToken(nickname) {
447
- const user = await unwrap(this._client.POST("/api/disks/{id}/users", {
438
+ const user = await unwrap(retryApiRequest(() => this._client.POST("/api/disks/{id}/users", {
448
439
  params: { path: { id: this.id } },
449
440
  body: {
450
441
  type: "token",
451
442
  nickname
452
443
  }
453
- }));
444
+ }), "connect"));
454
445
  if (!user.token || !user.identifier) throw new Error("Server did not return a generated token");
455
446
  return user;
456
447
  }
@@ -467,7 +458,7 @@ var Disk = class {
467
458
  * absent.
468
459
  */
469
460
  async listDelegations() {
470
- return (await unwrap(this._client.GET("/api/disks/{id}/delegations", { params: { path: { id: this.id } } }))).delegations;
461
+ return (await unwrap(retryApiRequest(() => this._client.GET("/api/disks/{id}/delegations", { params: { path: { id: this.id } } }), "transient"))).delegations;
471
462
  }
472
463
  /**
473
464
  * Forcibly revoke a delegation, reclaiming write access from a client that
@@ -484,22 +475,22 @@ var Disk = class {
484
475
  */
485
476
  async revokeDelegation(delegation) {
486
477
  const { clientId, inodeId } = delegation;
487
- await unwrap(this._client.POST("/api/disks/{id}/revoke-delegation", {
478
+ await unwrap(retryApiRequest(() => this._client.POST("/api/disks/{id}/revoke-delegation", {
488
479
  params: { path: { id: this.id } },
489
480
  body: {
490
481
  clientId,
491
482
  inodeId
492
483
  }
493
- }));
484
+ }), "connect"));
494
485
  }
495
486
  async getAllowedIPs() {
496
- return (await unwrap(this._client.GET("/api/disks/{id}/allowed-ips", { params: { path: { id: this.id } } }))).allowedIps;
487
+ return (await unwrap(retryApiRequest(() => this._client.GET("/api/disks/{id}/allowed-ips", { params: { path: { id: this.id } } }), "transient"))).allowedIps;
497
488
  }
498
489
  async setAllowedIPs(allowedIps) {
499
- return (await unwrap(this._client.PUT("/api/disks/{id}/allowed-ips", {
490
+ return (await unwrap(retryApiRequest(() => this._client.PUT("/api/disks/{id}/allowed-ips", {
500
491
  params: { path: { id: this.id } },
501
492
  body: { allowedIps }
502
- }))).allowedIps;
493
+ }), "transient"))).allowedIps;
503
494
  }
504
495
  async addAllowedIP(ip) {
505
496
  const current = await this.getAllowedIPs();
@@ -511,17 +502,17 @@ var Disk = class {
511
502
  return this.setAllowedIPs(current.filter((i) => i !== ip));
512
503
  }
513
504
  async delete() {
514
- await unwrapEmpty(this._client.DELETE("/api/disks/{id}", { params: { path: { id: this.id } } }));
505
+ await unwrapEmpty(retryApiRequest(() => this._client.DELETE("/api/disks/{id}", { params: { path: { id: this.id } } }), "connect"));
515
506
  }
516
507
  /**
517
508
  * Execute a command in a container with this disk mounted.
518
509
  * Blocks until the command completes and returns stdout, stderr, and exit code.
519
510
  */
520
511
  async exec(command) {
521
- return unwrap(this._client.POST("/api/disks/{id}/exec", {
512
+ return unwrap(retryApiRequest(() => this._client.POST("/api/disks/{id}/exec", {
522
513
  params: { path: { id: this.id } },
523
514
  body: { command }
524
- }));
515
+ }), "connect"));
525
516
  }
526
517
  /**
527
518
  * Constant-time parallel grep across files on this disk. Listing and
@@ -534,7 +525,7 @@ var Disk = class {
534
525
  * reported first), not the lexicographically first N.
535
526
  */
536
527
  async grep(opts) {
537
- return unwrap(this._client.POST("/api/disks/{id}/grep", {
528
+ return unwrap(retryApiRequest(() => this._client.POST("/api/disks/{id}/grep", {
538
529
  params: { path: { id: this.id } },
539
530
  body: {
540
531
  directory: opts.directory,
@@ -544,7 +535,7 @@ var Disk = class {
544
535
  concurrency: opts.concurrency ?? 50,
545
536
  maxResults: opts.maxResults ?? 1e3
546
537
  }
547
- }));
538
+ }), "transient"));
548
539
  }
549
540
  /**
550
541
  * Create a signed, time-limited URL that lets anyone download a single file
@@ -560,7 +551,7 @@ var Disk = class {
560
551
  const body = { key };
561
552
  if (opts.expiresIn !== void 0) body.expiresIn = opts.expiresIn;
562
553
  const call = this._client.POST;
563
- return unwrap(call(`/api/disks/${this.id}/share`, { body }));
554
+ return unwrap(retryApiRequest(() => call(`/api/disks/${this.id}/share`, { body }), "connect"));
564
555
  }
565
556
  /**
566
557
  * Read an object from the disk via the S3-compatible GetObject API and return
@@ -1288,11 +1279,11 @@ var Disks = class {
1288
1279
  * listing (it can also be persisted, e.g. across requests of a paginated UI).
1289
1280
  */
1290
1281
  async listPage(opts) {
1291
- const { data, nextCursor } = await unwrapPage(this._client.GET("/api/disks", { params: { query: {
1282
+ const { data, nextCursor } = await unwrapPage(retryApiRequest(() => this._client.GET("/api/disks", { params: { query: {
1292
1283
  limit: opts?.limit,
1293
1284
  cursor: opts?.cursor,
1294
1285
  name: opts?.name
1295
- } } }));
1286
+ } } }), "transient"));
1296
1287
  const disks = (data ?? []).map((d) => new Disk(d, this._client, this._region, this._s3BaseUrl));
1297
1288
  return nextCursor ? {
1298
1289
  disks,
@@ -1300,7 +1291,7 @@ var Disks = class {
1300
1291
  } : { disks };
1301
1292
  }
1302
1293
  async get(id) {
1303
- return new Disk(await unwrap(this._client.GET("/api/disks/{id}", { params: { path: { id } } })), this._client, this._region, this._s3BaseUrl);
1294
+ return new Disk(await unwrap(retryApiRequest(() => this._client.GET("/api/disks/{id}", { params: { path: { id } } }), "transient")), this._client, this._region, this._s3BaseUrl);
1304
1295
  }
1305
1296
  /**
1306
1297
  * Create a new disk with an auto-generated mount token.
@@ -1314,7 +1305,7 @@ var Disks = class {
1314
1305
  * Creation-time only.
1315
1306
  */
1316
1307
  async create(req) {
1317
- const resp = await unwrap(this._client.POST("/api/disks", { body: req }));
1308
+ const resp = await unwrap(retryApiRequest(() => this._client.POST("/api/disks", { body: req }), "connect"));
1318
1309
  if (!resp.diskId) throw new Error("API returned success but no diskId");
1319
1310
  const authorizedUsers = resp.authorizedUsers ?? [];
1320
1311
  const tokenUser = authorizedUsers.find((u) => u.token);
@@ -1331,10 +1322,10 @@ var Disks = class {
1331
1322
  * without fetching the disk first.
1332
1323
  */
1333
1324
  async exec(id, command) {
1334
- return unwrap(this._client.POST("/api/disks/{id}/exec", {
1325
+ return unwrap(retryApiRequest(() => this._client.POST("/api/disks/{id}/exec", {
1335
1326
  params: { path: { id } },
1336
1327
  body: { command }
1337
- }));
1328
+ }), "connect"));
1338
1329
  }
1339
1330
  };
1340
1331
  //#endregion
@@ -2196,16 +2187,16 @@ var Tokens = class {
2196
2187
  this._client = client;
2197
2188
  }
2198
2189
  async list(opts) {
2199
- return (await unwrap(this._client.GET("/api/tokens", { params: { query: {
2190
+ return (await unwrap(retryApiRequest(() => this._client.GET("/api/tokens", { params: { query: {
2200
2191
  limit: opts?.limit,
2201
2192
  cursor: opts?.cursor
2202
- } } }))).tokens ?? [];
2193
+ } } }), "transient"))).tokens ?? [];
2203
2194
  }
2204
2195
  async create(req) {
2205
- return await unwrap(this._client.POST("/api/tokens", { body: req }));
2196
+ return await unwrap(retryApiRequest(() => this._client.POST("/api/tokens", { body: req }), "connect"));
2206
2197
  }
2207
2198
  async delete(id) {
2208
- await unwrapEmpty(this._client.DELETE("/api/tokens/{tokenId}", { params: { path: { tokenId: id } } }));
2199
+ await unwrapEmpty(retryApiRequest(() => this._client.DELETE("/api/tokens/{tokenId}", { params: { path: { tokenId: id } } }), "connect"));
2209
2200
  }
2210
2201
  };
2211
2202
  //#endregion
@@ -2508,10 +2499,10 @@ var Archil = class {
2508
2499
  if (mount.checkoutPaths !== void 0) entry.checkoutPaths = mount.checkoutPaths;
2509
2500
  disks[relPath] = entry;
2510
2501
  } else disks[relPath] = diskIdFromMount(mount);
2511
- return unwrap(this._client.POST("/api/exec", { body: {
2502
+ return unwrap(retryApiRequest(() => this._client.POST("/api/exec", { body: {
2512
2503
  disks,
2513
2504
  command: opts.command
2514
- } }));
2505
+ } }), "connect"));
2515
2506
  }
2516
2507
  /**
2517
2508
  * Build an agent filesystem toolset spanning several disks at once. `mounts`
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { A as ArchilS3Error, C as DiskMultipart, E as VERSION, M as SandboxPauseError, O as ArchilApiError, S as Disk, T as USER_AGENT, _ as Sandbox, a as deleteApiKey, b as SandboxProcesses, c as getSandbox, d as listSandboxes, f as workspace, g as Sandboxes, h as Tokens, i as createSandbox, j as SandboxFileTransferError, k as ArchilError, l as listApiKeys, m as Workspace, n as createApiKey, o as exec, p as Archil, r as createDisk, s as getDisk, t as configure, u as listDisks, v as SandboxFiles, w as effectiveUploadPartSize, x as Disks, y as SandboxProcess } from "./src-r2oVqVK_.mjs";
1
+ import { A as ArchilS3Error, C as DiskMultipart, E as VERSION, M as SandboxPauseError, O as ArchilApiError, S as Disk, T as USER_AGENT, _ as Sandbox, a as deleteApiKey, b as SandboxProcesses, c as getSandbox, d as listSandboxes, f as workspace, g as Sandboxes, h as Tokens, i as createSandbox, j as SandboxFileTransferError, k as ArchilError, l as listApiKeys, m as Workspace, n as createApiKey, o as exec, p as Archil, r as createDisk, s as getDisk, t as configure, u as listDisks, v as SandboxFiles, w as effectiveUploadPartSize, x as Disks, y as SandboxProcess } from "./src-CxdnwAiv.mjs";
2
2
  export { Archil, ArchilApiError, ArchilError, ArchilS3Error, Disk, DiskMultipart, Disks, Sandbox, SandboxFileTransferError, SandboxFiles, SandboxPauseError, SandboxProcess, SandboxProcesses, Sandboxes, Tokens, USER_AGENT, VERSION, Workspace, configure, createApiKey, createDisk, createSandbox, deleteApiKey, effectiveUploadPartSize, exec, getDisk, getSandbox, listApiKeys, listDisks, listSandboxes, workspace };
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { O as ArchilApiError, p as Archil } from "./src-r2oVqVK_.mjs";
3
- import { a as renderTable, i as resolveProgramCredentials, n as addProfileCommands, r as isProfileCommand, t as addGlobalOptions } from "./common-Bi2YnNf6.mjs";
2
+ import { O as ArchilApiError, p as Archil } from "./src-CxdnwAiv.mjs";
3
+ import { a as renderTable, i as resolveProgramCredentials, n as addProfileCommands, r as isProfileCommand, t as addGlobalOptions } from "./common-DglyXr-d.mjs";
4
4
  import { createRequire } from "node:module";
5
5
  import { Command } from "commander";
6
6
  import { spinner } from "@clack/prompts";
@@ -130,7 +130,7 @@ function deriveS3BaseUrl(controlBaseUrl) {
130
130
  }
131
131
  //#endregion
132
132
  //#region src/version.ts
133
- const VERSION = "1.5.0";
133
+ const VERSION = "1.6.0";
134
134
  const USER_AGENT = `archil-js/${VERSION}`;
135
135
  //#endregion
136
136
  //#region src/client.ts
@@ -140,7 +140,7 @@ function isNodeRuntime() {
140
140
  }
141
141
  const undiciModule = isNodeRuntime() ? import("undici") : void 0;
142
142
  const CONTROL_PLANE_CONNECTIONS = 1;
143
- const CONTROL_PLANE_CONCURRENT_STREAMS = 100;
143
+ const IDLE_SESSION_TIMEOUT_MS = 3e4;
144
144
  function isAsyncIterableBody(body) {
145
145
  return body != null && typeof body === "object" && Symbol.asyncIterator in body;
146
146
  }
@@ -149,30 +149,12 @@ async function bufferBody(body) {
149
149
  for await (const chunk of body) chunks.push(typeof chunk === "string" ? Buffer.from(chunk) : chunk);
150
150
  return Buffer.concat(chunks);
151
151
  }
152
- const multiplexHttp2Requests = (dispatch) => (options, handler) => {
153
- let requestStarted = false;
154
- const guardedHandler = {
155
- onRequestStart(controller, context) {
156
- if (requestStarted) {
157
- controller.abort(/* @__PURE__ */ new Error("Archil control-plane requests are not replayed after a connection failure"));
158
- return;
159
- }
160
- requestStarted = true;
161
- handler.onRequestStart?.(controller, context);
162
- },
163
- onRequestUpgrade: handler.onRequestUpgrade?.bind(handler),
164
- onResponseStart: handler.onResponseStart?.bind(handler),
165
- onResponseData: handler.onResponseData?.bind(handler),
166
- onResponseEnd: handler.onResponseEnd?.bind(handler),
167
- onResponseError: handler.onResponseError?.bind(handler)
168
- };
169
- const dispatchBody = (body) => dispatch({
152
+ const bufferRequestBodies = (dispatch) => (options, handler) => {
153
+ if (!isAsyncIterableBody(options.body)) return dispatch(options, handler);
154
+ bufferBody(options.body).then((body) => dispatch({
170
155
  ...options,
171
- body,
172
- idempotent: true
173
- }, guardedHandler);
174
- if (!isAsyncIterableBody(options.body)) return dispatchBody(options.body);
175
- bufferBody(options.body).then(dispatchBody, (error) => handler.onResponseError?.({
156
+ body
157
+ }, handler), (error) => handler.onResponseError?.({
176
158
  aborted: false,
177
159
  paused: false,
178
160
  reason: null,
@@ -182,7 +164,7 @@ const multiplexHttp2Requests = (dispatch) => (options, handler) => {
182
164
  }, error instanceof Error ? error : new Error(String(error))));
183
165
  return true;
184
166
  };
185
- const sharedDispatchers = /* @__PURE__ */ new Map();
167
+ const sharedTransports = /* @__PURE__ */ new Map();
186
168
  function dispatcherKey(baseUrl, apiKey, ca) {
187
169
  return JSON.stringify([
188
170
  new URL(baseUrl).origin,
@@ -190,26 +172,27 @@ function dispatcherKey(baseUrl, apiKey, ca) {
190
172
  ca?.map((cert) => cert.toString("base64"))
191
173
  ]);
192
174
  }
193
- function getSharedDispatcher(key, ca) {
194
- const existing = sharedDispatchers.get(key);
175
+ function getSharedTransport(key, ca) {
176
+ const existing = sharedTransports.get(key);
195
177
  if (existing) return existing;
196
- const dispatcher = (async () => {
178
+ const transport = (async () => {
197
179
  if (!undiciModule) throw new Error("The pooled control-plane transport requires Node.js");
198
- const { Agent } = await undiciModule;
199
- return new Agent({
200
- allowH2: true,
201
- connections: CONTROL_PLANE_CONNECTIONS,
202
- pipelining: CONTROL_PLANE_CONCURRENT_STREAMS,
203
- keepAliveTimeout: 6e4,
204
- keepAliveMaxTimeout: 6e5,
205
- ...ca === void 0 ? {} : { connect: { ca } }
206
- }).compose(multiplexHttp2Requests);
180
+ const { Agent, fetch } = await undiciModule;
181
+ return {
182
+ fetch,
183
+ dispatcher: new Agent({
184
+ allowH2: true,
185
+ connections: CONTROL_PLANE_CONNECTIONS,
186
+ keepAliveTimeout: IDLE_SESSION_TIMEOUT_MS,
187
+ ...ca === void 0 ? {} : { connect: { ca } }
188
+ }).compose(bufferRequestBodies)
189
+ };
207
190
  })();
208
- sharedDispatchers.set(key, dispatcher);
209
- dispatcher.catch(() => {
210
- if (sharedDispatchers.get(key) === dispatcher) sharedDispatchers.delete(key);
191
+ sharedTransports.set(key, transport);
192
+ transport.catch(() => {
193
+ if (sharedTransports.get(key) === transport) sharedTransports.delete(key);
211
194
  });
212
- return dispatcher;
195
+ return transport;
213
196
  }
214
197
  function createPooledFetch(baseUrl, apiKey, tls) {
215
198
  if (!isNodeRuntime()) {
@@ -219,8 +202,16 @@ function createPooledFetch(baseUrl, apiKey, tls) {
219
202
  const ca = tls?.ca === void 0 ? void 0 : (Array.isArray(tls.ca) ? tls.ca : [tls.ca]).map((cert) => Buffer.from(cert));
220
203
  const key = dispatcherKey(baseUrl, apiKey, ca);
221
204
  return async (request) => {
222
- const dispatcher = await getSharedDispatcher(key, ca);
223
- return globalThis.fetch(request, { dispatcher });
205
+ const { fetch, dispatcher } = await getSharedTransport(key, ca);
206
+ const body = request.body === null ? null : new Uint8Array(await request.arrayBuffer());
207
+ return await fetch(request.url, {
208
+ method: request.method,
209
+ headers: [...request.headers],
210
+ body,
211
+ redirect: request.redirect,
212
+ signal: request.signal,
213
+ dispatcher
214
+ });
224
215
  };
225
216
  }
226
217
  function createApiClient(opts) {
@@ -406,28 +397,28 @@ var Disk = class {
406
397
  };
407
398
  }
408
399
  async addUser(user) {
409
- return unwrap(this._client.POST("/api/disks/{id}/users", {
400
+ return unwrap(retryApiRequest(() => this._client.POST("/api/disks/{id}/users", {
410
401
  params: { path: { id: this.id } },
411
402
  body: user
412
- }));
403
+ }), "connect"));
413
404
  }
414
405
  async removeUser(userType, identifier) {
415
- await unwrapEmpty(this._client.DELETE("/api/disks/{id}/users/{userType}", { params: {
406
+ await unwrapEmpty(retryApiRequest(() => this._client.DELETE("/api/disks/{id}/users/{userType}", { params: {
416
407
  path: {
417
408
  id: this.id,
418
409
  userType
419
410
  },
420
411
  query: { identifier }
421
- } }));
412
+ } }), "connect"));
422
413
  }
423
414
  async createToken(nickname) {
424
- const user = await unwrap(this._client.POST("/api/disks/{id}/users", {
415
+ const user = await unwrap(retryApiRequest(() => this._client.POST("/api/disks/{id}/users", {
425
416
  params: { path: { id: this.id } },
426
417
  body: {
427
418
  type: "token",
428
419
  nickname
429
420
  }
430
- }));
421
+ }), "connect"));
431
422
  if (!user.token || !user.identifier) throw new Error("Server did not return a generated token");
432
423
  return user;
433
424
  }
@@ -444,7 +435,7 @@ var Disk = class {
444
435
  * absent.
445
436
  */
446
437
  async listDelegations() {
447
- return (await unwrap(this._client.GET("/api/disks/{id}/delegations", { params: { path: { id: this.id } } }))).delegations;
438
+ return (await unwrap(retryApiRequest(() => this._client.GET("/api/disks/{id}/delegations", { params: { path: { id: this.id } } }), "transient"))).delegations;
448
439
  }
449
440
  /**
450
441
  * Forcibly revoke a delegation, reclaiming write access from a client that
@@ -461,22 +452,22 @@ var Disk = class {
461
452
  */
462
453
  async revokeDelegation(delegation) {
463
454
  const { clientId, inodeId } = delegation;
464
- await unwrap(this._client.POST("/api/disks/{id}/revoke-delegation", {
455
+ await unwrap(retryApiRequest(() => this._client.POST("/api/disks/{id}/revoke-delegation", {
465
456
  params: { path: { id: this.id } },
466
457
  body: {
467
458
  clientId,
468
459
  inodeId
469
460
  }
470
- }));
461
+ }), "connect"));
471
462
  }
472
463
  async getAllowedIPs() {
473
- return (await unwrap(this._client.GET("/api/disks/{id}/allowed-ips", { params: { path: { id: this.id } } }))).allowedIps;
464
+ return (await unwrap(retryApiRequest(() => this._client.GET("/api/disks/{id}/allowed-ips", { params: { path: { id: this.id } } }), "transient"))).allowedIps;
474
465
  }
475
466
  async setAllowedIPs(allowedIps) {
476
- return (await unwrap(this._client.PUT("/api/disks/{id}/allowed-ips", {
467
+ return (await unwrap(retryApiRequest(() => this._client.PUT("/api/disks/{id}/allowed-ips", {
477
468
  params: { path: { id: this.id } },
478
469
  body: { allowedIps }
479
- }))).allowedIps;
470
+ }), "transient"))).allowedIps;
480
471
  }
481
472
  async addAllowedIP(ip) {
482
473
  const current = await this.getAllowedIPs();
@@ -488,17 +479,17 @@ var Disk = class {
488
479
  return this.setAllowedIPs(current.filter((i) => i !== ip));
489
480
  }
490
481
  async delete() {
491
- await unwrapEmpty(this._client.DELETE("/api/disks/{id}", { params: { path: { id: this.id } } }));
482
+ await unwrapEmpty(retryApiRequest(() => this._client.DELETE("/api/disks/{id}", { params: { path: { id: this.id } } }), "connect"));
492
483
  }
493
484
  /**
494
485
  * Execute a command in a container with this disk mounted.
495
486
  * Blocks until the command completes and returns stdout, stderr, and exit code.
496
487
  */
497
488
  async exec(command) {
498
- return unwrap(this._client.POST("/api/disks/{id}/exec", {
489
+ return unwrap(retryApiRequest(() => this._client.POST("/api/disks/{id}/exec", {
499
490
  params: { path: { id: this.id } },
500
491
  body: { command }
501
- }));
492
+ }), "connect"));
502
493
  }
503
494
  /**
504
495
  * Constant-time parallel grep across files on this disk. Listing and
@@ -511,7 +502,7 @@ var Disk = class {
511
502
  * reported first), not the lexicographically first N.
512
503
  */
513
504
  async grep(opts) {
514
- return unwrap(this._client.POST("/api/disks/{id}/grep", {
505
+ return unwrap(retryApiRequest(() => this._client.POST("/api/disks/{id}/grep", {
515
506
  params: { path: { id: this.id } },
516
507
  body: {
517
508
  directory: opts.directory,
@@ -521,7 +512,7 @@ var Disk = class {
521
512
  concurrency: opts.concurrency ?? 50,
522
513
  maxResults: opts.maxResults ?? 1e3
523
514
  }
524
- }));
515
+ }), "transient"));
525
516
  }
526
517
  /**
527
518
  * Create a signed, time-limited URL that lets anyone download a single file
@@ -537,7 +528,7 @@ var Disk = class {
537
528
  const body = { key };
538
529
  if (opts.expiresIn !== void 0) body.expiresIn = opts.expiresIn;
539
530
  const call = this._client.POST;
540
- return unwrap(call(`/api/disks/${this.id}/share`, { body }));
531
+ return unwrap(retryApiRequest(() => call(`/api/disks/${this.id}/share`, { body }), "connect"));
541
532
  }
542
533
  /**
543
534
  * Read an object from the disk via the S3-compatible GetObject API and return
@@ -1265,11 +1256,11 @@ var Disks = class {
1265
1256
  * listing (it can also be persisted, e.g. across requests of a paginated UI).
1266
1257
  */
1267
1258
  async listPage(opts) {
1268
- const { data, nextCursor } = await unwrapPage(this._client.GET("/api/disks", { params: { query: {
1259
+ const { data, nextCursor } = await unwrapPage(retryApiRequest(() => this._client.GET("/api/disks", { params: { query: {
1269
1260
  limit: opts?.limit,
1270
1261
  cursor: opts?.cursor,
1271
1262
  name: opts?.name
1272
- } } }));
1263
+ } } }), "transient"));
1273
1264
  const disks = (data ?? []).map((d) => new Disk(d, this._client, this._region, this._s3BaseUrl));
1274
1265
  return nextCursor ? {
1275
1266
  disks,
@@ -1277,7 +1268,7 @@ var Disks = class {
1277
1268
  } : { disks };
1278
1269
  }
1279
1270
  async get(id) {
1280
- return new Disk(await unwrap(this._client.GET("/api/disks/{id}", { params: { path: { id } } })), this._client, this._region, this._s3BaseUrl);
1271
+ return new Disk(await unwrap(retryApiRequest(() => this._client.GET("/api/disks/{id}", { params: { path: { id } } }), "transient")), this._client, this._region, this._s3BaseUrl);
1281
1272
  }
1282
1273
  /**
1283
1274
  * Create a new disk with an auto-generated mount token.
@@ -1291,7 +1282,7 @@ var Disks = class {
1291
1282
  * Creation-time only.
1292
1283
  */
1293
1284
  async create(req) {
1294
- const resp = await unwrap(this._client.POST("/api/disks", { body: req }));
1285
+ const resp = await unwrap(retryApiRequest(() => this._client.POST("/api/disks", { body: req }), "connect"));
1295
1286
  if (!resp.diskId) throw new Error("API returned success but no diskId");
1296
1287
  const authorizedUsers = resp.authorizedUsers ?? [];
1297
1288
  const tokenUser = authorizedUsers.find((u) => u.token);
@@ -1308,10 +1299,10 @@ var Disks = class {
1308
1299
  * without fetching the disk first.
1309
1300
  */
1310
1301
  async exec(id, command) {
1311
- return unwrap(this._client.POST("/api/disks/{id}/exec", {
1302
+ return unwrap(retryApiRequest(() => this._client.POST("/api/disks/{id}/exec", {
1312
1303
  params: { path: { id } },
1313
1304
  body: { command }
1314
- }));
1305
+ }), "connect"));
1315
1306
  }
1316
1307
  };
1317
1308
  //#endregion
@@ -2173,16 +2164,16 @@ var Tokens = class {
2173
2164
  this._client = client;
2174
2165
  }
2175
2166
  async list(opts) {
2176
- return (await unwrap(this._client.GET("/api/tokens", { params: { query: {
2167
+ return (await unwrap(retryApiRequest(() => this._client.GET("/api/tokens", { params: { query: {
2177
2168
  limit: opts?.limit,
2178
2169
  cursor: opts?.cursor
2179
- } } }))).tokens ?? [];
2170
+ } } }), "transient"))).tokens ?? [];
2180
2171
  }
2181
2172
  async create(req) {
2182
- return await unwrap(this._client.POST("/api/tokens", { body: req }));
2173
+ return await unwrap(retryApiRequest(() => this._client.POST("/api/tokens", { body: req }), "connect"));
2183
2174
  }
2184
2175
  async delete(id) {
2185
- await unwrapEmpty(this._client.DELETE("/api/tokens/{tokenId}", { params: { path: { tokenId: id } } }));
2176
+ await unwrapEmpty(retryApiRequest(() => this._client.DELETE("/api/tokens/{tokenId}", { params: { path: { tokenId: id } } }), "connect"));
2186
2177
  }
2187
2178
  };
2188
2179
  //#endregion
@@ -2485,10 +2476,10 @@ var Archil = class {
2485
2476
  if (mount.checkoutPaths !== void 0) entry.checkoutPaths = mount.checkoutPaths;
2486
2477
  disks[relPath] = entry;
2487
2478
  } else disks[relPath] = diskIdFromMount(mount);
2488
- return unwrap(this._client.POST("/api/exec", { body: {
2479
+ return unwrap(retryApiRequest(() => this._client.POST("/api/exec", { body: {
2489
2480
  disks,
2490
2481
  command: opts.command
2491
- } }));
2482
+ } }), "connect"));
2492
2483
  }
2493
2484
  /**
2494
2485
  * Build an agent filesystem toolset spanning several disks at once. `mounts`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "disk",
3
- "version": "1.5.0",
3
+ "version": "1.6.0",
4
4
  "description": "Pure-JS client and CLIs for Archil disks and sandboxes",
5
5
  "keywords": [
6
6
  "archil",
@@ -45,7 +45,7 @@
45
45
  "commander": "^14.0.3",
46
46
  "fast-xml-parser": "^5.7.0",
47
47
  "openapi-fetch": "^0.13.5",
48
- "undici": "7.29.0",
48
+ "undici": "8.10.2",
49
49
  "uuid": "^11.1.1",
50
50
  "zod": "^4.4.3"
51
51
  },
@@ -56,7 +56,7 @@
56
56
  "vitest": "^4.1.9"
57
57
  },
58
58
  "engines": {
59
- "node": ">= 22"
59
+ "node": ">= 22.19.0"
60
60
  },
61
61
  "scripts": {
62
62
  "build": "tsdown",