disk 1.4.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/README.md +33 -0
- package/dist/cli.mjs +2 -2
- package/dist/{common-D2ic5Rit.mjs → common-DglyXr-d.mjs} +1 -1
- package/dist/index.cjs +78 -75
- package/dist/index.d.cts +12 -4
- package/dist/index.d.mts +12 -4
- package/dist/index.mjs +2 -2
- package/dist/sandbox-cli.mjs +2 -2
- package/dist/{src-BaAv98od.mjs → src-CxdnwAiv.mjs} +78 -76
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -697,3 +697,36 @@ Archil has two credential types, and the examples above use both:
|
|
|
697
697
|
## Support
|
|
698
698
|
|
|
699
699
|
Questions, feature requests, or issues? Reach us at **support@archil.com**.
|
|
700
|
+
|
|
701
|
+
|
|
702
|
+
To finish selected model requests before pausing, opt in when creating the sandbox:
|
|
703
|
+
|
|
704
|
+
```ts
|
|
705
|
+
const sandbox = await archil.sandboxes.create({
|
|
706
|
+
network: {
|
|
707
|
+
egress: {
|
|
708
|
+
default: "allow",
|
|
709
|
+
drain_on_pause: [
|
|
710
|
+
"*.anthropic.com",
|
|
711
|
+
"api.openai.com",
|
|
712
|
+
"bedrock-runtime.*.amazonaws.com",
|
|
713
|
+
],
|
|
714
|
+
},
|
|
715
|
+
},
|
|
716
|
+
});
|
|
717
|
+
await sandbox.pause();
|
|
718
|
+
```
|
|
719
|
+
|
|
720
|
+
Each entry is a lowercase hostname pattern without a scheme, port, or path.
|
|
721
|
+
`*` works anywhere; `"*"` selects every host. Leading `*.` excludes the apex domain.
|
|
722
|
+
All URL paths on a selected host count. Matching happens before forwarding. Selectors
|
|
723
|
+
do not grant network access. Pausing gates new matches and waits for active HTTP(S)
|
|
724
|
+
responses, including streams, to reach the guest. Requests to other hosts do not delay the drain.
|
|
725
|
+
The drain waits up to ten minutes by default, starting when pause begins. Request errors
|
|
726
|
+
stop counting; expiry proceeds with the snapshot. Requests have no added timeout during
|
|
727
|
+
normal operation.
|
|
728
|
+
HTTP ports 80 and 443 are supported. Clients must trust the sandbox egress CA for HTTPS
|
|
729
|
+
and retry stale connections after resume. Set selectors at creation to cover every
|
|
730
|
+
connection; live network updates cannot intercept existing passthrough connections.
|
|
731
|
+
A snapshot failure leaves the sandbox in `failed` with the failure reason and raises
|
|
732
|
+
`SandboxPauseError` when waiting; `error.latest` contains the resulting sandbox state.
|
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-
|
|
3
|
-
import { a as renderTable, i as resolveProgramCredentials, n as addProfileCommands, r as isProfileCommand, t as addGlobalOptions } from "./common-
|
|
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-
|
|
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
|
@@ -62,6 +62,14 @@ var ArchilApiError = class extends ArchilError {
|
|
|
62
62
|
this.name = "ArchilApiError";
|
|
63
63
|
}
|
|
64
64
|
};
|
|
65
|
+
var SandboxPauseError = class extends ArchilError {
|
|
66
|
+
latest;
|
|
67
|
+
constructor(latest) {
|
|
68
|
+
super(`Sandbox entered ${latest.status} before it paused${latest.exitReason ? `: ${latest.exitReason}` : ""}`, 409, "SANDBOX_PAUSE_FAILED");
|
|
69
|
+
this.latest = latest;
|
|
70
|
+
this.name = "SandboxPauseError";
|
|
71
|
+
}
|
|
72
|
+
};
|
|
65
73
|
var SandboxFileTransferError = class extends ArchilError {
|
|
66
74
|
operation;
|
|
67
75
|
path;
|
|
@@ -145,7 +153,7 @@ function deriveS3BaseUrl(controlBaseUrl) {
|
|
|
145
153
|
}
|
|
146
154
|
//#endregion
|
|
147
155
|
//#region src/version.ts
|
|
148
|
-
const VERSION = "1.
|
|
156
|
+
const VERSION = "1.6.0";
|
|
149
157
|
const USER_AGENT = `archil-js/${VERSION}`;
|
|
150
158
|
//#endregion
|
|
151
159
|
//#region src/client.ts
|
|
@@ -155,7 +163,7 @@ function isNodeRuntime() {
|
|
|
155
163
|
}
|
|
156
164
|
const undiciModule = isNodeRuntime() ? import("undici") : void 0;
|
|
157
165
|
const CONTROL_PLANE_CONNECTIONS = 1;
|
|
158
|
-
const
|
|
166
|
+
const IDLE_SESSION_TIMEOUT_MS = 3e4;
|
|
159
167
|
function isAsyncIterableBody(body) {
|
|
160
168
|
return body != null && typeof body === "object" && Symbol.asyncIterator in body;
|
|
161
169
|
}
|
|
@@ -164,30 +172,12 @@ async function bufferBody(body) {
|
|
|
164
172
|
for await (const chunk of body) chunks.push(typeof chunk === "string" ? Buffer.from(chunk) : chunk);
|
|
165
173
|
return Buffer.concat(chunks);
|
|
166
174
|
}
|
|
167
|
-
const
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
onRequestStart(controller, context) {
|
|
171
|
-
if (requestStarted) {
|
|
172
|
-
controller.abort(/* @__PURE__ */ new Error("Archil control-plane requests are not replayed after a connection failure"));
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
175
|
-
requestStarted = true;
|
|
176
|
-
handler.onRequestStart?.(controller, context);
|
|
177
|
-
},
|
|
178
|
-
onRequestUpgrade: handler.onRequestUpgrade?.bind(handler),
|
|
179
|
-
onResponseStart: handler.onResponseStart?.bind(handler),
|
|
180
|
-
onResponseData: handler.onResponseData?.bind(handler),
|
|
181
|
-
onResponseEnd: handler.onResponseEnd?.bind(handler),
|
|
182
|
-
onResponseError: handler.onResponseError?.bind(handler)
|
|
183
|
-
};
|
|
184
|
-
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({
|
|
185
178
|
...options,
|
|
186
|
-
body
|
|
187
|
-
|
|
188
|
-
}, guardedHandler);
|
|
189
|
-
if (!isAsyncIterableBody(options.body)) return dispatchBody(options.body);
|
|
190
|
-
bufferBody(options.body).then(dispatchBody, (error) => handler.onResponseError?.({
|
|
179
|
+
body
|
|
180
|
+
}, handler), (error) => handler.onResponseError?.({
|
|
191
181
|
aborted: false,
|
|
192
182
|
paused: false,
|
|
193
183
|
reason: null,
|
|
@@ -197,7 +187,7 @@ const multiplexHttp2Requests = (dispatch) => (options, handler) => {
|
|
|
197
187
|
}, error instanceof Error ? error : new Error(String(error))));
|
|
198
188
|
return true;
|
|
199
189
|
};
|
|
200
|
-
const
|
|
190
|
+
const sharedTransports = /* @__PURE__ */ new Map();
|
|
201
191
|
function dispatcherKey(baseUrl, apiKey, ca) {
|
|
202
192
|
return JSON.stringify([
|
|
203
193
|
new URL(baseUrl).origin,
|
|
@@ -205,26 +195,27 @@ function dispatcherKey(baseUrl, apiKey, ca) {
|
|
|
205
195
|
ca?.map((cert) => cert.toString("base64"))
|
|
206
196
|
]);
|
|
207
197
|
}
|
|
208
|
-
function
|
|
209
|
-
const existing =
|
|
198
|
+
function getSharedTransport(key, ca) {
|
|
199
|
+
const existing = sharedTransports.get(key);
|
|
210
200
|
if (existing) return existing;
|
|
211
|
-
const
|
|
201
|
+
const transport = (async () => {
|
|
212
202
|
if (!undiciModule) throw new Error("The pooled control-plane transport requires Node.js");
|
|
213
|
-
const { Agent } = await undiciModule;
|
|
214
|
-
return
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
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
|
+
};
|
|
222
213
|
})();
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
if (
|
|
214
|
+
sharedTransports.set(key, transport);
|
|
215
|
+
transport.catch(() => {
|
|
216
|
+
if (sharedTransports.get(key) === transport) sharedTransports.delete(key);
|
|
226
217
|
});
|
|
227
|
-
return
|
|
218
|
+
return transport;
|
|
228
219
|
}
|
|
229
220
|
function createPooledFetch(baseUrl, apiKey, tls) {
|
|
230
221
|
if (!isNodeRuntime()) {
|
|
@@ -234,8 +225,16 @@ function createPooledFetch(baseUrl, apiKey, tls) {
|
|
|
234
225
|
const ca = tls?.ca === void 0 ? void 0 : (Array.isArray(tls.ca) ? tls.ca : [tls.ca]).map((cert) => Buffer.from(cert));
|
|
235
226
|
const key = dispatcherKey(baseUrl, apiKey, ca);
|
|
236
227
|
return async (request) => {
|
|
237
|
-
const dispatcher = await
|
|
238
|
-
|
|
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
|
+
});
|
|
239
238
|
};
|
|
240
239
|
}
|
|
241
240
|
function createApiClient(opts) {
|
|
@@ -421,28 +420,28 @@ var Disk = class {
|
|
|
421
420
|
};
|
|
422
421
|
}
|
|
423
422
|
async addUser(user) {
|
|
424
|
-
return unwrap(this._client.POST("/api/disks/{id}/users", {
|
|
423
|
+
return unwrap(retryApiRequest(() => this._client.POST("/api/disks/{id}/users", {
|
|
425
424
|
params: { path: { id: this.id } },
|
|
426
425
|
body: user
|
|
427
|
-
}));
|
|
426
|
+
}), "connect"));
|
|
428
427
|
}
|
|
429
428
|
async removeUser(userType, identifier) {
|
|
430
|
-
await unwrapEmpty(this._client.DELETE("/api/disks/{id}/users/{userType}", { params: {
|
|
429
|
+
await unwrapEmpty(retryApiRequest(() => this._client.DELETE("/api/disks/{id}/users/{userType}", { params: {
|
|
431
430
|
path: {
|
|
432
431
|
id: this.id,
|
|
433
432
|
userType
|
|
434
433
|
},
|
|
435
434
|
query: { identifier }
|
|
436
|
-
} }));
|
|
435
|
+
} }), "connect"));
|
|
437
436
|
}
|
|
438
437
|
async createToken(nickname) {
|
|
439
|
-
const user = await unwrap(this._client.POST("/api/disks/{id}/users", {
|
|
438
|
+
const user = await unwrap(retryApiRequest(() => this._client.POST("/api/disks/{id}/users", {
|
|
440
439
|
params: { path: { id: this.id } },
|
|
441
440
|
body: {
|
|
442
441
|
type: "token",
|
|
443
442
|
nickname
|
|
444
443
|
}
|
|
445
|
-
}));
|
|
444
|
+
}), "connect"));
|
|
446
445
|
if (!user.token || !user.identifier) throw new Error("Server did not return a generated token");
|
|
447
446
|
return user;
|
|
448
447
|
}
|
|
@@ -459,7 +458,7 @@ var Disk = class {
|
|
|
459
458
|
* absent.
|
|
460
459
|
*/
|
|
461
460
|
async listDelegations() {
|
|
462
|
-
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;
|
|
463
462
|
}
|
|
464
463
|
/**
|
|
465
464
|
* Forcibly revoke a delegation, reclaiming write access from a client that
|
|
@@ -476,22 +475,22 @@ var Disk = class {
|
|
|
476
475
|
*/
|
|
477
476
|
async revokeDelegation(delegation) {
|
|
478
477
|
const { clientId, inodeId } = delegation;
|
|
479
|
-
await unwrap(this._client.POST("/api/disks/{id}/revoke-delegation", {
|
|
478
|
+
await unwrap(retryApiRequest(() => this._client.POST("/api/disks/{id}/revoke-delegation", {
|
|
480
479
|
params: { path: { id: this.id } },
|
|
481
480
|
body: {
|
|
482
481
|
clientId,
|
|
483
482
|
inodeId
|
|
484
483
|
}
|
|
485
|
-
}));
|
|
484
|
+
}), "connect"));
|
|
486
485
|
}
|
|
487
486
|
async getAllowedIPs() {
|
|
488
|
-
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;
|
|
489
488
|
}
|
|
490
489
|
async setAllowedIPs(allowedIps) {
|
|
491
|
-
return (await unwrap(this._client.PUT("/api/disks/{id}/allowed-ips", {
|
|
490
|
+
return (await unwrap(retryApiRequest(() => this._client.PUT("/api/disks/{id}/allowed-ips", {
|
|
492
491
|
params: { path: { id: this.id } },
|
|
493
492
|
body: { allowedIps }
|
|
494
|
-
}))).allowedIps;
|
|
493
|
+
}), "transient"))).allowedIps;
|
|
495
494
|
}
|
|
496
495
|
async addAllowedIP(ip) {
|
|
497
496
|
const current = await this.getAllowedIPs();
|
|
@@ -503,17 +502,17 @@ var Disk = class {
|
|
|
503
502
|
return this.setAllowedIPs(current.filter((i) => i !== ip));
|
|
504
503
|
}
|
|
505
504
|
async delete() {
|
|
506
|
-
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"));
|
|
507
506
|
}
|
|
508
507
|
/**
|
|
509
508
|
* Execute a command in a container with this disk mounted.
|
|
510
509
|
* Blocks until the command completes and returns stdout, stderr, and exit code.
|
|
511
510
|
*/
|
|
512
511
|
async exec(command) {
|
|
513
|
-
return unwrap(this._client.POST("/api/disks/{id}/exec", {
|
|
512
|
+
return unwrap(retryApiRequest(() => this._client.POST("/api/disks/{id}/exec", {
|
|
514
513
|
params: { path: { id: this.id } },
|
|
515
514
|
body: { command }
|
|
516
|
-
}));
|
|
515
|
+
}), "connect"));
|
|
517
516
|
}
|
|
518
517
|
/**
|
|
519
518
|
* Constant-time parallel grep across files on this disk. Listing and
|
|
@@ -526,7 +525,7 @@ var Disk = class {
|
|
|
526
525
|
* reported first), not the lexicographically first N.
|
|
527
526
|
*/
|
|
528
527
|
async grep(opts) {
|
|
529
|
-
return unwrap(this._client.POST("/api/disks/{id}/grep", {
|
|
528
|
+
return unwrap(retryApiRequest(() => this._client.POST("/api/disks/{id}/grep", {
|
|
530
529
|
params: { path: { id: this.id } },
|
|
531
530
|
body: {
|
|
532
531
|
directory: opts.directory,
|
|
@@ -536,7 +535,7 @@ var Disk = class {
|
|
|
536
535
|
concurrency: opts.concurrency ?? 50,
|
|
537
536
|
maxResults: opts.maxResults ?? 1e3
|
|
538
537
|
}
|
|
539
|
-
}));
|
|
538
|
+
}), "transient"));
|
|
540
539
|
}
|
|
541
540
|
/**
|
|
542
541
|
* Create a signed, time-limited URL that lets anyone download a single file
|
|
@@ -552,7 +551,7 @@ var Disk = class {
|
|
|
552
551
|
const body = { key };
|
|
553
552
|
if (opts.expiresIn !== void 0) body.expiresIn = opts.expiresIn;
|
|
554
553
|
const call = this._client.POST;
|
|
555
|
-
return unwrap(call(`/api/disks/${this.id}/share`, { body }));
|
|
554
|
+
return unwrap(retryApiRequest(() => call(`/api/disks/${this.id}/share`, { body }), "connect"));
|
|
556
555
|
}
|
|
557
556
|
/**
|
|
558
557
|
* Read an object from the disk via the S3-compatible GetObject API and return
|
|
@@ -1280,11 +1279,11 @@ var Disks = class {
|
|
|
1280
1279
|
* listing (it can also be persisted, e.g. across requests of a paginated UI).
|
|
1281
1280
|
*/
|
|
1282
1281
|
async listPage(opts) {
|
|
1283
|
-
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: {
|
|
1284
1283
|
limit: opts?.limit,
|
|
1285
1284
|
cursor: opts?.cursor,
|
|
1286
1285
|
name: opts?.name
|
|
1287
|
-
} } }));
|
|
1286
|
+
} } }), "transient"));
|
|
1288
1287
|
const disks = (data ?? []).map((d) => new Disk(d, this._client, this._region, this._s3BaseUrl));
|
|
1289
1288
|
return nextCursor ? {
|
|
1290
1289
|
disks,
|
|
@@ -1292,7 +1291,7 @@ var Disks = class {
|
|
|
1292
1291
|
} : { disks };
|
|
1293
1292
|
}
|
|
1294
1293
|
async get(id) {
|
|
1295
|
-
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);
|
|
1296
1295
|
}
|
|
1297
1296
|
/**
|
|
1298
1297
|
* Create a new disk with an auto-generated mount token.
|
|
@@ -1306,7 +1305,7 @@ var Disks = class {
|
|
|
1306
1305
|
* Creation-time only.
|
|
1307
1306
|
*/
|
|
1308
1307
|
async create(req) {
|
|
1309
|
-
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"));
|
|
1310
1309
|
if (!resp.diskId) throw new Error("API returned success but no diskId");
|
|
1311
1310
|
const authorizedUsers = resp.authorizedUsers ?? [];
|
|
1312
1311
|
const tokenUser = authorizedUsers.find((u) => u.token);
|
|
@@ -1323,10 +1322,10 @@ var Disks = class {
|
|
|
1323
1322
|
* without fetching the disk first.
|
|
1324
1323
|
*/
|
|
1325
1324
|
async exec(id, command) {
|
|
1326
|
-
return unwrap(this._client.POST("/api/disks/{id}/exec", {
|
|
1325
|
+
return unwrap(retryApiRequest(() => this._client.POST("/api/disks/{id}/exec", {
|
|
1327
1326
|
params: { path: { id } },
|
|
1328
1327
|
body: { command }
|
|
1329
|
-
}));
|
|
1328
|
+
}), "connect"));
|
|
1330
1329
|
}
|
|
1331
1330
|
};
|
|
1332
1331
|
//#endregion
|
|
@@ -1973,7 +1972,10 @@ var Sandbox = class Sandbox {
|
|
|
1973
1972
|
async pause(options = {}) {
|
|
1974
1973
|
const data = await unwrap(retryApiRequest(() => this._client.POST("/api/sandboxes/{sid}/pause", { params: { path: { sid: this.id } } }), "transient"));
|
|
1975
1974
|
this._apply(data);
|
|
1976
|
-
|
|
1975
|
+
if (options.wait === false) return this;
|
|
1976
|
+
await waitWhileSandboxStatus(this, "pausing");
|
|
1977
|
+
if (this.status !== "paused") throw new SandboxPauseError(this);
|
|
1978
|
+
return this;
|
|
1977
1979
|
}
|
|
1978
1980
|
/** Resume this sandbox from its preserved CPU and memory state. */
|
|
1979
1981
|
async resume(options = {}) {
|
|
@@ -2185,16 +2187,16 @@ var Tokens = class {
|
|
|
2185
2187
|
this._client = client;
|
|
2186
2188
|
}
|
|
2187
2189
|
async list(opts) {
|
|
2188
|
-
return (await unwrap(this._client.GET("/api/tokens", { params: { query: {
|
|
2190
|
+
return (await unwrap(retryApiRequest(() => this._client.GET("/api/tokens", { params: { query: {
|
|
2189
2191
|
limit: opts?.limit,
|
|
2190
2192
|
cursor: opts?.cursor
|
|
2191
|
-
} } }))).tokens ?? [];
|
|
2193
|
+
} } }), "transient"))).tokens ?? [];
|
|
2192
2194
|
}
|
|
2193
2195
|
async create(req) {
|
|
2194
|
-
return await unwrap(this._client.POST("/api/tokens", { body: req }));
|
|
2196
|
+
return await unwrap(retryApiRequest(() => this._client.POST("/api/tokens", { body: req }), "connect"));
|
|
2195
2197
|
}
|
|
2196
2198
|
async delete(id) {
|
|
2197
|
-
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"));
|
|
2198
2200
|
}
|
|
2199
2201
|
};
|
|
2200
2202
|
//#endregion
|
|
@@ -2497,10 +2499,10 @@ var Archil = class {
|
|
|
2497
2499
|
if (mount.checkoutPaths !== void 0) entry.checkoutPaths = mount.checkoutPaths;
|
|
2498
2500
|
disks[relPath] = entry;
|
|
2499
2501
|
} else disks[relPath] = diskIdFromMount(mount);
|
|
2500
|
-
return unwrap(this._client.POST("/api/exec", { body: {
|
|
2502
|
+
return unwrap(retryApiRequest(() => this._client.POST("/api/exec", { body: {
|
|
2501
2503
|
disks,
|
|
2502
2504
|
command: opts.command
|
|
2503
|
-
} }));
|
|
2505
|
+
} }), "connect"));
|
|
2504
2506
|
}
|
|
2505
2507
|
/**
|
|
2506
2508
|
* Build an agent filesystem toolset spanning several disks at once. `mounts`
|
|
@@ -2578,6 +2580,7 @@ exports.Disks = Disks;
|
|
|
2578
2580
|
exports.Sandbox = Sandbox;
|
|
2579
2581
|
exports.SandboxFileTransferError = SandboxFileTransferError;
|
|
2580
2582
|
exports.SandboxFiles = SandboxFiles;
|
|
2583
|
+
exports.SandboxPauseError = SandboxPauseError;
|
|
2581
2584
|
exports.SandboxProcess = SandboxProcess;
|
|
2582
2585
|
exports.SandboxProcesses = SandboxProcesses;
|
|
2583
2586
|
exports.Sandboxes = Sandboxes;
|
package/dist/index.d.cts
CHANGED
|
@@ -196,10 +196,14 @@ declare class SandboxFiles {
|
|
|
196
196
|
//#endregion
|
|
197
197
|
//#region src/sandbox.d.ts
|
|
198
198
|
type SandboxNetworkAction = components["schemas"]["SandboxNetworkAction"];
|
|
199
|
-
type SandboxEgressPolicy = components["schemas"]["SandboxEgressPolicy"]
|
|
199
|
+
type SandboxEgressPolicy = components["schemas"]["SandboxEgressPolicy"] & {
|
|
200
|
+
/** Host patterns supporting * anywhere. All paths count; selectors do not grant network access. */drain_on_pause?: string[];
|
|
201
|
+
};
|
|
200
202
|
type SandboxEgressRule = components["schemas"]["SandboxEgressRule"];
|
|
201
203
|
type SandboxEgressTransform = components["schemas"]["SandboxEgressTransform"];
|
|
202
|
-
type SandboxNetwork = components["schemas"]["SandboxNetwork"]
|
|
204
|
+
type SandboxNetwork = Omit<components["schemas"]["SandboxNetwork"], "egress"> & {
|
|
205
|
+
egress?: SandboxEgressPolicy;
|
|
206
|
+
};
|
|
203
207
|
/** @internal */
|
|
204
208
|
type SandboxWire = components["schemas"]["Sandbox"] & {
|
|
205
209
|
idle_ttl_seconds?: number;
|
|
@@ -307,7 +311,7 @@ declare class Sandbox {
|
|
|
307
311
|
/** Stop this sandbox. */
|
|
308
312
|
stop(options?: SandboxWaitOptions): Promise<Sandbox | this>;
|
|
309
313
|
/** Pause this sandbox, preserving its CPU and memory state. */
|
|
310
|
-
pause(options?: SandboxWaitOptions): Promise<
|
|
314
|
+
pause(options?: SandboxWaitOptions): Promise<this>;
|
|
311
315
|
/** Resume this sandbox from its preserved CPU and memory state. */
|
|
312
316
|
resume(options?: SandboxWaitOptions): Promise<Sandbox | this>;
|
|
313
317
|
/**
|
|
@@ -576,6 +580,10 @@ declare class ArchilError extends Error {
|
|
|
576
580
|
declare class ArchilApiError extends ArchilError {
|
|
577
581
|
constructor(message: string, status: number, code?: string);
|
|
578
582
|
}
|
|
583
|
+
declare class SandboxPauseError extends ArchilError {
|
|
584
|
+
readonly latest: Sandbox;
|
|
585
|
+
constructor(latest: Sandbox);
|
|
586
|
+
}
|
|
579
587
|
declare class SandboxFileTransferError extends ArchilError {
|
|
580
588
|
readonly operation: "upload" | "download";
|
|
581
589
|
readonly path: string;
|
|
@@ -632,4 +640,4 @@ declare function exec(opts: ExecOptions): Promise<ExecDiskResult>;
|
|
|
632
640
|
*/
|
|
633
641
|
declare function workspace(mounts: Record<string, ExecMount>): Workspace;
|
|
634
642
|
//#endregion
|
|
635
|
-
export { type ApiTokenResponse, type AppendObjectOptions, Archil, ArchilApiError, ArchilError, type ArchilOptions, ArchilS3Error, type ArchilTlsOptions, type AuthorizedUser, type AwsStsUser, type AzureBlobMount, type CompletedMultipartUpload, type ConnectedClient, type CreateApiTokenRequest, type CreateDiskRequest, type CreateDiskResult, type CreateSandboxPortTokenOptions, type CreateSandboxRequest, type CreatedSandboxPortToken, type Delegation, type DeleteObjectsError, type DeleteObjectsOptions, type DeleteObjectsResult, Disk, type DiskListPage, type DiskMetrics, DiskMultipart, type DiskResponse, type DiskStatus, type DiskUser, Disks, type ExecMount, type ExecMountSpec, type ExecOptions, type ExecRequest, type ExecResult, type FileSystem, type GCSMount, type GrepMatch, type GrepOptions, type GrepResult, type GrepStoppedReason, type ListDisksOptions, type ListMultipartUploadsOptions, type ListObjectsOptions, type ListObjectsResult, type ListPartsOptions, type ListSandboxPortTokensOptions, type ListSandboxesOptions, type ListTokensOptions, type MountConfig, type MountConfigResponse, type MountOptions, type MountResponse, type MultipartUpload, type MultipartUploadListing, type MultipartUploadSummary, type ObjectMetadata, type PartInfo, type PartListing, type PosixCreateAttrs, type PutObjectOptions, type PutObjectResult, type R2Mount, type RootAttrs, type S3CompatibleMount, type S3Mount, type S3Object, Sandbox, type SandboxEgressPolicy, type SandboxEgressRule, type SandboxEgressTransform, type SandboxEndpoint, type SandboxFileSource, SandboxFileTransferError, type SandboxFileUploadOptions, type SandboxFileWriter, SandboxFiles, type SandboxForkOptions, type SandboxNetwork, type SandboxNetworkAction, type SandboxPortToken, type SandboxPortTokenPage, SandboxProcess, type SandboxProcessConnectOptions, type SandboxProcessOutput, type SandboxProcessOutputHandler, type SandboxProcessResult, type SandboxProcessStartOptions, type SandboxProcessStatus, type SandboxProcessStream, SandboxProcesses, type SandboxResponse, type SandboxStatus, type SandboxTerminalOptions, type SandboxTimeoutOptions, type SandboxWaitOptions, Sandboxes, type ShareUrlOptions, type ShareUrlResult, type TokenUser, Tokens, USER_AGENT, type UploadPart, VERSION, Workspace, configure, createApiKey, createDisk, createSandbox, deleteApiKey, effectiveUploadPartSize, exec, getDisk, getSandbox, listApiKeys, listDisks, listSandboxes, workspace };
|
|
643
|
+
export { type ApiTokenResponse, type AppendObjectOptions, Archil, ArchilApiError, ArchilError, type ArchilOptions, ArchilS3Error, type ArchilTlsOptions, type AuthorizedUser, type AwsStsUser, type AzureBlobMount, type CompletedMultipartUpload, type ConnectedClient, type CreateApiTokenRequest, type CreateDiskRequest, type CreateDiskResult, type CreateSandboxPortTokenOptions, type CreateSandboxRequest, type CreatedSandboxPortToken, type Delegation, type DeleteObjectsError, type DeleteObjectsOptions, type DeleteObjectsResult, Disk, type DiskListPage, type DiskMetrics, DiskMultipart, type DiskResponse, type DiskStatus, type DiskUser, Disks, type ExecMount, type ExecMountSpec, type ExecOptions, type ExecRequest, type ExecResult, type FileSystem, type GCSMount, type GrepMatch, type GrepOptions, type GrepResult, type GrepStoppedReason, type ListDisksOptions, type ListMultipartUploadsOptions, type ListObjectsOptions, type ListObjectsResult, type ListPartsOptions, type ListSandboxPortTokensOptions, type ListSandboxesOptions, type ListTokensOptions, type MountConfig, type MountConfigResponse, type MountOptions, type MountResponse, type MultipartUpload, type MultipartUploadListing, type MultipartUploadSummary, type ObjectMetadata, type PartInfo, type PartListing, type PosixCreateAttrs, type PutObjectOptions, type PutObjectResult, type R2Mount, type RootAttrs, type S3CompatibleMount, type S3Mount, type S3Object, Sandbox, type SandboxEgressPolicy, type SandboxEgressRule, type SandboxEgressTransform, type SandboxEndpoint, type SandboxFileSource, SandboxFileTransferError, type SandboxFileUploadOptions, type SandboxFileWriter, SandboxFiles, type SandboxForkOptions, type SandboxNetwork, type SandboxNetworkAction, SandboxPauseError, type SandboxPortToken, type SandboxPortTokenPage, SandboxProcess, type SandboxProcessConnectOptions, type SandboxProcessOutput, type SandboxProcessOutputHandler, type SandboxProcessResult, type SandboxProcessStartOptions, type SandboxProcessStatus, type SandboxProcessStream, SandboxProcesses, type SandboxResponse, type SandboxStatus, type SandboxTerminalOptions, type SandboxTimeoutOptions, type SandboxWaitOptions, Sandboxes, type ShareUrlOptions, type ShareUrlResult, type TokenUser, Tokens, USER_AGENT, type UploadPart, VERSION, Workspace, configure, createApiKey, createDisk, createSandbox, deleteApiKey, effectiveUploadPartSize, exec, getDisk, getSandbox, listApiKeys, listDisks, listSandboxes, workspace };
|
package/dist/index.d.mts
CHANGED
|
@@ -196,10 +196,14 @@ declare class SandboxFiles {
|
|
|
196
196
|
//#endregion
|
|
197
197
|
//#region src/sandbox.d.ts
|
|
198
198
|
type SandboxNetworkAction = components["schemas"]["SandboxNetworkAction"];
|
|
199
|
-
type SandboxEgressPolicy = components["schemas"]["SandboxEgressPolicy"]
|
|
199
|
+
type SandboxEgressPolicy = components["schemas"]["SandboxEgressPolicy"] & {
|
|
200
|
+
/** Host patterns supporting * anywhere. All paths count; selectors do not grant network access. */drain_on_pause?: string[];
|
|
201
|
+
};
|
|
200
202
|
type SandboxEgressRule = components["schemas"]["SandboxEgressRule"];
|
|
201
203
|
type SandboxEgressTransform = components["schemas"]["SandboxEgressTransform"];
|
|
202
|
-
type SandboxNetwork = components["schemas"]["SandboxNetwork"]
|
|
204
|
+
type SandboxNetwork = Omit<components["schemas"]["SandboxNetwork"], "egress"> & {
|
|
205
|
+
egress?: SandboxEgressPolicy;
|
|
206
|
+
};
|
|
203
207
|
/** @internal */
|
|
204
208
|
type SandboxWire = components["schemas"]["Sandbox"] & {
|
|
205
209
|
idle_ttl_seconds?: number;
|
|
@@ -307,7 +311,7 @@ declare class Sandbox {
|
|
|
307
311
|
/** Stop this sandbox. */
|
|
308
312
|
stop(options?: SandboxWaitOptions): Promise<Sandbox | this>;
|
|
309
313
|
/** Pause this sandbox, preserving its CPU and memory state. */
|
|
310
|
-
pause(options?: SandboxWaitOptions): Promise<
|
|
314
|
+
pause(options?: SandboxWaitOptions): Promise<this>;
|
|
311
315
|
/** Resume this sandbox from its preserved CPU and memory state. */
|
|
312
316
|
resume(options?: SandboxWaitOptions): Promise<Sandbox | this>;
|
|
313
317
|
/**
|
|
@@ -576,6 +580,10 @@ declare class ArchilError extends Error {
|
|
|
576
580
|
declare class ArchilApiError extends ArchilError {
|
|
577
581
|
constructor(message: string, status: number, code?: string);
|
|
578
582
|
}
|
|
583
|
+
declare class SandboxPauseError extends ArchilError {
|
|
584
|
+
readonly latest: Sandbox;
|
|
585
|
+
constructor(latest: Sandbox);
|
|
586
|
+
}
|
|
579
587
|
declare class SandboxFileTransferError extends ArchilError {
|
|
580
588
|
readonly operation: "upload" | "download";
|
|
581
589
|
readonly path: string;
|
|
@@ -632,4 +640,4 @@ declare function exec(opts: ExecOptions): Promise<ExecDiskResult>;
|
|
|
632
640
|
*/
|
|
633
641
|
declare function workspace(mounts: Record<string, ExecMount>): Workspace;
|
|
634
642
|
//#endregion
|
|
635
|
-
export { type ApiTokenResponse, type AppendObjectOptions, Archil, ArchilApiError, ArchilError, type ArchilOptions, ArchilS3Error, type ArchilTlsOptions, type AuthorizedUser, type AwsStsUser, type AzureBlobMount, type CompletedMultipartUpload, type ConnectedClient, type CreateApiTokenRequest, type CreateDiskRequest, type CreateDiskResult, type CreateSandboxPortTokenOptions, type CreateSandboxRequest, type CreatedSandboxPortToken, type Delegation, type DeleteObjectsError, type DeleteObjectsOptions, type DeleteObjectsResult, Disk, type DiskListPage, type DiskMetrics, DiskMultipart, type DiskResponse, type DiskStatus, type DiskUser, Disks, type ExecMount, type ExecMountSpec, type ExecOptions, type ExecRequest, type ExecResult, type FileSystem, type GCSMount, type GrepMatch, type GrepOptions, type GrepResult, type GrepStoppedReason, type ListDisksOptions, type ListMultipartUploadsOptions, type ListObjectsOptions, type ListObjectsResult, type ListPartsOptions, type ListSandboxPortTokensOptions, type ListSandboxesOptions, type ListTokensOptions, type MountConfig, type MountConfigResponse, type MountOptions, type MountResponse, type MultipartUpload, type MultipartUploadListing, type MultipartUploadSummary, type ObjectMetadata, type PartInfo, type PartListing, type PosixCreateAttrs, type PutObjectOptions, type PutObjectResult, type R2Mount, type RootAttrs, type S3CompatibleMount, type S3Mount, type S3Object, Sandbox, type SandboxEgressPolicy, type SandboxEgressRule, type SandboxEgressTransform, type SandboxEndpoint, type SandboxFileSource, SandboxFileTransferError, type SandboxFileUploadOptions, type SandboxFileWriter, SandboxFiles, type SandboxForkOptions, type SandboxNetwork, type SandboxNetworkAction, type SandboxPortToken, type SandboxPortTokenPage, SandboxProcess, type SandboxProcessConnectOptions, type SandboxProcessOutput, type SandboxProcessOutputHandler, type SandboxProcessResult, type SandboxProcessStartOptions, type SandboxProcessStatus, type SandboxProcessStream, SandboxProcesses, type SandboxResponse, type SandboxStatus, type SandboxTerminalOptions, type SandboxTimeoutOptions, type SandboxWaitOptions, Sandboxes, type ShareUrlOptions, type ShareUrlResult, type TokenUser, Tokens, USER_AGENT, type UploadPart, VERSION, Workspace, configure, createApiKey, createDisk, createSandbox, deleteApiKey, effectiveUploadPartSize, exec, getDisk, getSandbox, listApiKeys, listDisks, listSandboxes, workspace };
|
|
643
|
+
export { type ApiTokenResponse, type AppendObjectOptions, Archil, ArchilApiError, ArchilError, type ArchilOptions, ArchilS3Error, type ArchilTlsOptions, type AuthorizedUser, type AwsStsUser, type AzureBlobMount, type CompletedMultipartUpload, type ConnectedClient, type CreateApiTokenRequest, type CreateDiskRequest, type CreateDiskResult, type CreateSandboxPortTokenOptions, type CreateSandboxRequest, type CreatedSandboxPortToken, type Delegation, type DeleteObjectsError, type DeleteObjectsOptions, type DeleteObjectsResult, Disk, type DiskListPage, type DiskMetrics, DiskMultipart, type DiskResponse, type DiskStatus, type DiskUser, Disks, type ExecMount, type ExecMountSpec, type ExecOptions, type ExecRequest, type ExecResult, type FileSystem, type GCSMount, type GrepMatch, type GrepOptions, type GrepResult, type GrepStoppedReason, type ListDisksOptions, type ListMultipartUploadsOptions, type ListObjectsOptions, type ListObjectsResult, type ListPartsOptions, type ListSandboxPortTokensOptions, type ListSandboxesOptions, type ListTokensOptions, type MountConfig, type MountConfigResponse, type MountOptions, type MountResponse, type MultipartUpload, type MultipartUploadListing, type MultipartUploadSummary, type ObjectMetadata, type PartInfo, type PartListing, type PosixCreateAttrs, type PutObjectOptions, type PutObjectResult, type R2Mount, type RootAttrs, type S3CompatibleMount, type S3Mount, type S3Object, Sandbox, type SandboxEgressPolicy, type SandboxEgressRule, type SandboxEgressTransform, type SandboxEndpoint, type SandboxFileSource, SandboxFileTransferError, type SandboxFileUploadOptions, type SandboxFileWriter, SandboxFiles, type SandboxForkOptions, type SandboxNetwork, type SandboxNetworkAction, SandboxPauseError, type SandboxPortToken, type SandboxPortTokenPage, SandboxProcess, type SandboxProcessConnectOptions, type SandboxProcessOutput, type SandboxProcessOutputHandler, type SandboxProcessResult, type SandboxProcessStartOptions, type SandboxProcessStatus, type SandboxProcessStream, SandboxProcesses, type SandboxResponse, type SandboxStatus, type SandboxTerminalOptions, type SandboxTimeoutOptions, type SandboxWaitOptions, Sandboxes, type ShareUrlOptions, type ShareUrlResult, type TokenUser, Tokens, USER_AGENT, type UploadPart, VERSION, Workspace, configure, createApiKey, createDisk, createSandbox, deleteApiKey, effectiveUploadPartSize, exec, getDisk, getSandbox, listApiKeys, listDisks, listSandboxes, workspace };
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { A as ArchilS3Error, C as DiskMultipart, E as VERSION, 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-
|
|
2
|
-
export { Archil, ArchilApiError, ArchilError, ArchilS3Error, Disk, DiskMultipart, Disks, Sandbox, SandboxFileTransferError, SandboxFiles, SandboxProcess, SandboxProcesses, Sandboxes, Tokens, USER_AGENT, VERSION, Workspace, configure, createApiKey, createDisk, createSandbox, deleteApiKey, effectiveUploadPartSize, exec, getDisk, getSandbox, listApiKeys, listDisks, listSandboxes, workspace };
|
|
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
|
+
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 };
|
package/dist/sandbox-cli.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { O as ArchilApiError, p as Archil } from "./src-
|
|
3
|
-
import { a as renderTable, i as resolveProgramCredentials, n as addProfileCommands, r as isProfileCommand, t as addGlobalOptions } from "./common-
|
|
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";
|
|
@@ -39,6 +39,14 @@ var ArchilApiError = class extends ArchilError {
|
|
|
39
39
|
this.name = "ArchilApiError";
|
|
40
40
|
}
|
|
41
41
|
};
|
|
42
|
+
var SandboxPauseError = class extends ArchilError {
|
|
43
|
+
latest;
|
|
44
|
+
constructor(latest) {
|
|
45
|
+
super(`Sandbox entered ${latest.status} before it paused${latest.exitReason ? `: ${latest.exitReason}` : ""}`, 409, "SANDBOX_PAUSE_FAILED");
|
|
46
|
+
this.latest = latest;
|
|
47
|
+
this.name = "SandboxPauseError";
|
|
48
|
+
}
|
|
49
|
+
};
|
|
42
50
|
var SandboxFileTransferError = class extends ArchilError {
|
|
43
51
|
operation;
|
|
44
52
|
path;
|
|
@@ -122,7 +130,7 @@ function deriveS3BaseUrl(controlBaseUrl) {
|
|
|
122
130
|
}
|
|
123
131
|
//#endregion
|
|
124
132
|
//#region src/version.ts
|
|
125
|
-
const VERSION = "1.
|
|
133
|
+
const VERSION = "1.6.0";
|
|
126
134
|
const USER_AGENT = `archil-js/${VERSION}`;
|
|
127
135
|
//#endregion
|
|
128
136
|
//#region src/client.ts
|
|
@@ -132,7 +140,7 @@ function isNodeRuntime() {
|
|
|
132
140
|
}
|
|
133
141
|
const undiciModule = isNodeRuntime() ? import("undici") : void 0;
|
|
134
142
|
const CONTROL_PLANE_CONNECTIONS = 1;
|
|
135
|
-
const
|
|
143
|
+
const IDLE_SESSION_TIMEOUT_MS = 3e4;
|
|
136
144
|
function isAsyncIterableBody(body) {
|
|
137
145
|
return body != null && typeof body === "object" && Symbol.asyncIterator in body;
|
|
138
146
|
}
|
|
@@ -141,30 +149,12 @@ async function bufferBody(body) {
|
|
|
141
149
|
for await (const chunk of body) chunks.push(typeof chunk === "string" ? Buffer.from(chunk) : chunk);
|
|
142
150
|
return Buffer.concat(chunks);
|
|
143
151
|
}
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
onRequestStart(controller, context) {
|
|
148
|
-
if (requestStarted) {
|
|
149
|
-
controller.abort(/* @__PURE__ */ new Error("Archil control-plane requests are not replayed after a connection failure"));
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
requestStarted = true;
|
|
153
|
-
handler.onRequestStart?.(controller, context);
|
|
154
|
-
},
|
|
155
|
-
onRequestUpgrade: handler.onRequestUpgrade?.bind(handler),
|
|
156
|
-
onResponseStart: handler.onResponseStart?.bind(handler),
|
|
157
|
-
onResponseData: handler.onResponseData?.bind(handler),
|
|
158
|
-
onResponseEnd: handler.onResponseEnd?.bind(handler),
|
|
159
|
-
onResponseError: handler.onResponseError?.bind(handler)
|
|
160
|
-
};
|
|
161
|
-
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({
|
|
162
155
|
...options,
|
|
163
|
-
body
|
|
164
|
-
|
|
165
|
-
}, guardedHandler);
|
|
166
|
-
if (!isAsyncIterableBody(options.body)) return dispatchBody(options.body);
|
|
167
|
-
bufferBody(options.body).then(dispatchBody, (error) => handler.onResponseError?.({
|
|
156
|
+
body
|
|
157
|
+
}, handler), (error) => handler.onResponseError?.({
|
|
168
158
|
aborted: false,
|
|
169
159
|
paused: false,
|
|
170
160
|
reason: null,
|
|
@@ -174,7 +164,7 @@ const multiplexHttp2Requests = (dispatch) => (options, handler) => {
|
|
|
174
164
|
}, error instanceof Error ? error : new Error(String(error))));
|
|
175
165
|
return true;
|
|
176
166
|
};
|
|
177
|
-
const
|
|
167
|
+
const sharedTransports = /* @__PURE__ */ new Map();
|
|
178
168
|
function dispatcherKey(baseUrl, apiKey, ca) {
|
|
179
169
|
return JSON.stringify([
|
|
180
170
|
new URL(baseUrl).origin,
|
|
@@ -182,26 +172,27 @@ function dispatcherKey(baseUrl, apiKey, ca) {
|
|
|
182
172
|
ca?.map((cert) => cert.toString("base64"))
|
|
183
173
|
]);
|
|
184
174
|
}
|
|
185
|
-
function
|
|
186
|
-
const existing =
|
|
175
|
+
function getSharedTransport(key, ca) {
|
|
176
|
+
const existing = sharedTransports.get(key);
|
|
187
177
|
if (existing) return existing;
|
|
188
|
-
const
|
|
178
|
+
const transport = (async () => {
|
|
189
179
|
if (!undiciModule) throw new Error("The pooled control-plane transport requires Node.js");
|
|
190
|
-
const { Agent } = await undiciModule;
|
|
191
|
-
return
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
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
|
+
};
|
|
199
190
|
})();
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
if (
|
|
191
|
+
sharedTransports.set(key, transport);
|
|
192
|
+
transport.catch(() => {
|
|
193
|
+
if (sharedTransports.get(key) === transport) sharedTransports.delete(key);
|
|
203
194
|
});
|
|
204
|
-
return
|
|
195
|
+
return transport;
|
|
205
196
|
}
|
|
206
197
|
function createPooledFetch(baseUrl, apiKey, tls) {
|
|
207
198
|
if (!isNodeRuntime()) {
|
|
@@ -211,8 +202,16 @@ function createPooledFetch(baseUrl, apiKey, tls) {
|
|
|
211
202
|
const ca = tls?.ca === void 0 ? void 0 : (Array.isArray(tls.ca) ? tls.ca : [tls.ca]).map((cert) => Buffer.from(cert));
|
|
212
203
|
const key = dispatcherKey(baseUrl, apiKey, ca);
|
|
213
204
|
return async (request) => {
|
|
214
|
-
const dispatcher = await
|
|
215
|
-
|
|
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
|
+
});
|
|
216
215
|
};
|
|
217
216
|
}
|
|
218
217
|
function createApiClient(opts) {
|
|
@@ -398,28 +397,28 @@ var Disk = class {
|
|
|
398
397
|
};
|
|
399
398
|
}
|
|
400
399
|
async addUser(user) {
|
|
401
|
-
return unwrap(this._client.POST("/api/disks/{id}/users", {
|
|
400
|
+
return unwrap(retryApiRequest(() => this._client.POST("/api/disks/{id}/users", {
|
|
402
401
|
params: { path: { id: this.id } },
|
|
403
402
|
body: user
|
|
404
|
-
}));
|
|
403
|
+
}), "connect"));
|
|
405
404
|
}
|
|
406
405
|
async removeUser(userType, identifier) {
|
|
407
|
-
await unwrapEmpty(this._client.DELETE("/api/disks/{id}/users/{userType}", { params: {
|
|
406
|
+
await unwrapEmpty(retryApiRequest(() => this._client.DELETE("/api/disks/{id}/users/{userType}", { params: {
|
|
408
407
|
path: {
|
|
409
408
|
id: this.id,
|
|
410
409
|
userType
|
|
411
410
|
},
|
|
412
411
|
query: { identifier }
|
|
413
|
-
} }));
|
|
412
|
+
} }), "connect"));
|
|
414
413
|
}
|
|
415
414
|
async createToken(nickname) {
|
|
416
|
-
const user = await unwrap(this._client.POST("/api/disks/{id}/users", {
|
|
415
|
+
const user = await unwrap(retryApiRequest(() => this._client.POST("/api/disks/{id}/users", {
|
|
417
416
|
params: { path: { id: this.id } },
|
|
418
417
|
body: {
|
|
419
418
|
type: "token",
|
|
420
419
|
nickname
|
|
421
420
|
}
|
|
422
|
-
}));
|
|
421
|
+
}), "connect"));
|
|
423
422
|
if (!user.token || !user.identifier) throw new Error("Server did not return a generated token");
|
|
424
423
|
return user;
|
|
425
424
|
}
|
|
@@ -436,7 +435,7 @@ var Disk = class {
|
|
|
436
435
|
* absent.
|
|
437
436
|
*/
|
|
438
437
|
async listDelegations() {
|
|
439
|
-
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;
|
|
440
439
|
}
|
|
441
440
|
/**
|
|
442
441
|
* Forcibly revoke a delegation, reclaiming write access from a client that
|
|
@@ -453,22 +452,22 @@ var Disk = class {
|
|
|
453
452
|
*/
|
|
454
453
|
async revokeDelegation(delegation) {
|
|
455
454
|
const { clientId, inodeId } = delegation;
|
|
456
|
-
await unwrap(this._client.POST("/api/disks/{id}/revoke-delegation", {
|
|
455
|
+
await unwrap(retryApiRequest(() => this._client.POST("/api/disks/{id}/revoke-delegation", {
|
|
457
456
|
params: { path: { id: this.id } },
|
|
458
457
|
body: {
|
|
459
458
|
clientId,
|
|
460
459
|
inodeId
|
|
461
460
|
}
|
|
462
|
-
}));
|
|
461
|
+
}), "connect"));
|
|
463
462
|
}
|
|
464
463
|
async getAllowedIPs() {
|
|
465
|
-
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;
|
|
466
465
|
}
|
|
467
466
|
async setAllowedIPs(allowedIps) {
|
|
468
|
-
return (await unwrap(this._client.PUT("/api/disks/{id}/allowed-ips", {
|
|
467
|
+
return (await unwrap(retryApiRequest(() => this._client.PUT("/api/disks/{id}/allowed-ips", {
|
|
469
468
|
params: { path: { id: this.id } },
|
|
470
469
|
body: { allowedIps }
|
|
471
|
-
}))).allowedIps;
|
|
470
|
+
}), "transient"))).allowedIps;
|
|
472
471
|
}
|
|
473
472
|
async addAllowedIP(ip) {
|
|
474
473
|
const current = await this.getAllowedIPs();
|
|
@@ -480,17 +479,17 @@ var Disk = class {
|
|
|
480
479
|
return this.setAllowedIPs(current.filter((i) => i !== ip));
|
|
481
480
|
}
|
|
482
481
|
async delete() {
|
|
483
|
-
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"));
|
|
484
483
|
}
|
|
485
484
|
/**
|
|
486
485
|
* Execute a command in a container with this disk mounted.
|
|
487
486
|
* Blocks until the command completes and returns stdout, stderr, and exit code.
|
|
488
487
|
*/
|
|
489
488
|
async exec(command) {
|
|
490
|
-
return unwrap(this._client.POST("/api/disks/{id}/exec", {
|
|
489
|
+
return unwrap(retryApiRequest(() => this._client.POST("/api/disks/{id}/exec", {
|
|
491
490
|
params: { path: { id: this.id } },
|
|
492
491
|
body: { command }
|
|
493
|
-
}));
|
|
492
|
+
}), "connect"));
|
|
494
493
|
}
|
|
495
494
|
/**
|
|
496
495
|
* Constant-time parallel grep across files on this disk. Listing and
|
|
@@ -503,7 +502,7 @@ var Disk = class {
|
|
|
503
502
|
* reported first), not the lexicographically first N.
|
|
504
503
|
*/
|
|
505
504
|
async grep(opts) {
|
|
506
|
-
return unwrap(this._client.POST("/api/disks/{id}/grep", {
|
|
505
|
+
return unwrap(retryApiRequest(() => this._client.POST("/api/disks/{id}/grep", {
|
|
507
506
|
params: { path: { id: this.id } },
|
|
508
507
|
body: {
|
|
509
508
|
directory: opts.directory,
|
|
@@ -513,7 +512,7 @@ var Disk = class {
|
|
|
513
512
|
concurrency: opts.concurrency ?? 50,
|
|
514
513
|
maxResults: opts.maxResults ?? 1e3
|
|
515
514
|
}
|
|
516
|
-
}));
|
|
515
|
+
}), "transient"));
|
|
517
516
|
}
|
|
518
517
|
/**
|
|
519
518
|
* Create a signed, time-limited URL that lets anyone download a single file
|
|
@@ -529,7 +528,7 @@ var Disk = class {
|
|
|
529
528
|
const body = { key };
|
|
530
529
|
if (opts.expiresIn !== void 0) body.expiresIn = opts.expiresIn;
|
|
531
530
|
const call = this._client.POST;
|
|
532
|
-
return unwrap(call(`/api/disks/${this.id}/share`, { body }));
|
|
531
|
+
return unwrap(retryApiRequest(() => call(`/api/disks/${this.id}/share`, { body }), "connect"));
|
|
533
532
|
}
|
|
534
533
|
/**
|
|
535
534
|
* Read an object from the disk via the S3-compatible GetObject API and return
|
|
@@ -1257,11 +1256,11 @@ var Disks = class {
|
|
|
1257
1256
|
* listing (it can also be persisted, e.g. across requests of a paginated UI).
|
|
1258
1257
|
*/
|
|
1259
1258
|
async listPage(opts) {
|
|
1260
|
-
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: {
|
|
1261
1260
|
limit: opts?.limit,
|
|
1262
1261
|
cursor: opts?.cursor,
|
|
1263
1262
|
name: opts?.name
|
|
1264
|
-
} } }));
|
|
1263
|
+
} } }), "transient"));
|
|
1265
1264
|
const disks = (data ?? []).map((d) => new Disk(d, this._client, this._region, this._s3BaseUrl));
|
|
1266
1265
|
return nextCursor ? {
|
|
1267
1266
|
disks,
|
|
@@ -1269,7 +1268,7 @@ var Disks = class {
|
|
|
1269
1268
|
} : { disks };
|
|
1270
1269
|
}
|
|
1271
1270
|
async get(id) {
|
|
1272
|
-
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);
|
|
1273
1272
|
}
|
|
1274
1273
|
/**
|
|
1275
1274
|
* Create a new disk with an auto-generated mount token.
|
|
@@ -1283,7 +1282,7 @@ var Disks = class {
|
|
|
1283
1282
|
* Creation-time only.
|
|
1284
1283
|
*/
|
|
1285
1284
|
async create(req) {
|
|
1286
|
-
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"));
|
|
1287
1286
|
if (!resp.diskId) throw new Error("API returned success but no diskId");
|
|
1288
1287
|
const authorizedUsers = resp.authorizedUsers ?? [];
|
|
1289
1288
|
const tokenUser = authorizedUsers.find((u) => u.token);
|
|
@@ -1300,10 +1299,10 @@ var Disks = class {
|
|
|
1300
1299
|
* without fetching the disk first.
|
|
1301
1300
|
*/
|
|
1302
1301
|
async exec(id, command) {
|
|
1303
|
-
return unwrap(this._client.POST("/api/disks/{id}/exec", {
|
|
1302
|
+
return unwrap(retryApiRequest(() => this._client.POST("/api/disks/{id}/exec", {
|
|
1304
1303
|
params: { path: { id } },
|
|
1305
1304
|
body: { command }
|
|
1306
|
-
}));
|
|
1305
|
+
}), "connect"));
|
|
1307
1306
|
}
|
|
1308
1307
|
};
|
|
1309
1308
|
//#endregion
|
|
@@ -1950,7 +1949,10 @@ var Sandbox = class Sandbox {
|
|
|
1950
1949
|
async pause(options = {}) {
|
|
1951
1950
|
const data = await unwrap(retryApiRequest(() => this._client.POST("/api/sandboxes/{sid}/pause", { params: { path: { sid: this.id } } }), "transient"));
|
|
1952
1951
|
this._apply(data);
|
|
1953
|
-
|
|
1952
|
+
if (options.wait === false) return this;
|
|
1953
|
+
await waitWhileSandboxStatus(this, "pausing");
|
|
1954
|
+
if (this.status !== "paused") throw new SandboxPauseError(this);
|
|
1955
|
+
return this;
|
|
1954
1956
|
}
|
|
1955
1957
|
/** Resume this sandbox from its preserved CPU and memory state. */
|
|
1956
1958
|
async resume(options = {}) {
|
|
@@ -2162,16 +2164,16 @@ var Tokens = class {
|
|
|
2162
2164
|
this._client = client;
|
|
2163
2165
|
}
|
|
2164
2166
|
async list(opts) {
|
|
2165
|
-
return (await unwrap(this._client.GET("/api/tokens", { params: { query: {
|
|
2167
|
+
return (await unwrap(retryApiRequest(() => this._client.GET("/api/tokens", { params: { query: {
|
|
2166
2168
|
limit: opts?.limit,
|
|
2167
2169
|
cursor: opts?.cursor
|
|
2168
|
-
} } }))).tokens ?? [];
|
|
2170
|
+
} } }), "transient"))).tokens ?? [];
|
|
2169
2171
|
}
|
|
2170
2172
|
async create(req) {
|
|
2171
|
-
return await unwrap(this._client.POST("/api/tokens", { body: req }));
|
|
2173
|
+
return await unwrap(retryApiRequest(() => this._client.POST("/api/tokens", { body: req }), "connect"));
|
|
2172
2174
|
}
|
|
2173
2175
|
async delete(id) {
|
|
2174
|
-
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"));
|
|
2175
2177
|
}
|
|
2176
2178
|
};
|
|
2177
2179
|
//#endregion
|
|
@@ -2474,10 +2476,10 @@ var Archil = class {
|
|
|
2474
2476
|
if (mount.checkoutPaths !== void 0) entry.checkoutPaths = mount.checkoutPaths;
|
|
2475
2477
|
disks[relPath] = entry;
|
|
2476
2478
|
} else disks[relPath] = diskIdFromMount(mount);
|
|
2477
|
-
return unwrap(this._client.POST("/api/exec", { body: {
|
|
2479
|
+
return unwrap(retryApiRequest(() => this._client.POST("/api/exec", { body: {
|
|
2478
2480
|
disks,
|
|
2479
2481
|
command: opts.command
|
|
2480
|
-
} }));
|
|
2482
|
+
} }), "connect"));
|
|
2481
2483
|
}
|
|
2482
2484
|
/**
|
|
2483
2485
|
* Build an agent filesystem toolset spanning several disks at once. `mounts`
|
|
@@ -2545,4 +2547,4 @@ function workspace(mounts) {
|
|
|
2545
2547
|
return archil().workspace(mounts);
|
|
2546
2548
|
}
|
|
2547
2549
|
//#endregion
|
|
2548
|
-
export { ArchilS3Error as A, DiskMultipart as C, REGION_URLS as D, VERSION as E, ArchilApiError as O, Disk as S, USER_AGENT as T, Sandbox as _, deleteApiKey as a, SandboxProcesses as b, getSandbox as c, listSandboxes as d, workspace as f, Sandboxes as g, Tokens as h, createSandbox as i, SandboxFileTransferError as j, ArchilError as k, listApiKeys as l, Workspace as m, createApiKey as n, exec as o, Archil as p, createDisk as r, getDisk as s, configure as t, listDisks as u, SandboxFiles as v, effectiveUploadPartSize as w, Disks as x, SandboxProcess as y };
|
|
2550
|
+
export { ArchilS3Error as A, DiskMultipart as C, REGION_URLS as D, VERSION as E, SandboxPauseError as M, ArchilApiError as O, Disk as S, USER_AGENT as T, Sandbox as _, deleteApiKey as a, SandboxProcesses as b, getSandbox as c, listSandboxes as d, workspace as f, Sandboxes as g, Tokens as h, createSandbox as i, SandboxFileTransferError as j, ArchilError as k, listApiKeys as l, Workspace as m, createApiKey as n, exec as o, Archil as p, createDisk as r, getDisk as s, configure as t, listDisks as u, SandboxFiles as v, effectiveUploadPartSize as w, Disks as x, SandboxProcess as y };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "disk",
|
|
3
|
-
"version": "1.
|
|
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": "
|
|
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",
|