disk 0.8.21 → 0.8.23
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 +50 -0
- package/dist/cli.mjs +1 -1
- package/dist/{disk-BhRejJas.d.cts → disk-DEqV3mtA.d.cts} +26 -1
- package/dist/{disk-BhRejJas.d.mts → disk-DEqV3mtA.d.mts} +26 -1
- package/dist/index.cjs +368 -1
- package/dist/index.d.cts +203 -41
- package/dist/index.d.mts +203 -41
- package/dist/index.mjs +2 -2
- package/dist/internal/tools.d.cts +1 -1
- package/dist/internal/tools.d.mts +1 -1
- package/dist/{src-CrK7pSLW.mjs → src-DgL0HTS-.mjs} +361 -2
- package/package.json +13 -9
package/README.md
CHANGED
|
@@ -74,6 +74,33 @@ await d.removeUser("token", user.identifier!);
|
|
|
74
74
|
await d.delete();
|
|
75
75
|
```
|
|
76
76
|
|
|
77
|
+
### Sandboxes
|
|
78
|
+
|
|
79
|
+
Use `Archil.sandboxes` to manage persistent VMs:
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
const client = new archil.Archil({
|
|
83
|
+
apiKey: process.env.ARCHIL_API_KEY,
|
|
84
|
+
region: "aws-us-east-1",
|
|
85
|
+
});
|
|
86
|
+
const sandbox = await client.sandboxes.create({ vcpuCount: 2, memSizeMiB: 4096 });
|
|
87
|
+
|
|
88
|
+
const result = await sandbox.exec("uname -a");
|
|
89
|
+
console.log(result.stdout);
|
|
90
|
+
|
|
91
|
+
await sandbox.stop();
|
|
92
|
+
await sandbox.start();
|
|
93
|
+
await sandbox.pause();
|
|
94
|
+
await sandbox.resume();
|
|
95
|
+
|
|
96
|
+
const all = await client.sandboxes.list();
|
|
97
|
+
const usingDisk = await client.sandboxes.list({ disk: "dsk-abc123" });
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
`create`, `start`, `stop`, `pause`, `resume`, and `exec` wait up to 30 seconds by default.
|
|
101
|
+
Set `timeoutMs` to change the limit. A `SandboxWaitTimeoutError` includes the latest
|
|
102
|
+
resource state.
|
|
103
|
+
|
|
77
104
|
API keys live at the account level, so those helpers are top-level:
|
|
78
105
|
|
|
79
106
|
```ts
|
|
@@ -271,6 +298,29 @@ const workspace = archil.workspace({
|
|
|
271
298
|
When `queueMs` is set without `checkoutPaths`, the mount root is acquired
|
|
272
299
|
during mount setup instead.
|
|
273
300
|
|
|
301
|
+
## Delegations
|
|
302
|
+
|
|
303
|
+
A delegation grants a client exclusive write access to an inode on a shared
|
|
304
|
+
disk. List the delegations currently held on a disk and forcibly revoke one —
|
|
305
|
+
useful for reclaiming write access from a client that crashed or lost
|
|
306
|
+
connectivity without checking its delegations in:
|
|
307
|
+
|
|
308
|
+
```ts
|
|
309
|
+
const disk = await archil.disks.get("dsk-0123456789abcdef");
|
|
310
|
+
|
|
311
|
+
for (const d of await disk.listDelegations()) {
|
|
312
|
+
// { clientId, inodeId, path?, isPending, isOrphaned }
|
|
313
|
+
if (d.isOrphaned) {
|
|
314
|
+
await disk.revokeDelegation(d);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
A delegation has no ID of its own — it is identified by the
|
|
320
|
+
`(clientId, inodeId)` pair. `isOrphaned` entries are held by clients no longer
|
|
321
|
+
connected to the disk. `path` is resolved best-effort by the server and may be
|
|
322
|
+
absent.
|
|
323
|
+
|
|
274
324
|
A `Workspace` is a full filesystem in its own right — it has the same object API
|
|
275
325
|
a `Disk` does (`getObject` / `putObject` / `deleteObject` / `listObjects` /
|
|
276
326
|
`grep` / `exec`; both implement the `FileSystem` interface), so you can use it
|
package/dist/cli.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
2
|
+
import { D 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-DgL0HTS-.mjs";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import { Command, Option } from "commander";
|
|
5
5
|
//#region bin/cli.ts
|
|
@@ -50,6 +50,7 @@ type GCSMount = components["schemas"]["GCSMount"];
|
|
|
50
50
|
type R2Mount = components["schemas"]["R2Mount"];
|
|
51
51
|
type S3CompatibleMount = components["schemas"]["S3CompatibleMount"];
|
|
52
52
|
type AzureBlobMount = components["schemas"]["AzureBlobMount"];
|
|
53
|
+
type Delegation = components["schemas"]["DelegationEntry"];
|
|
53
54
|
type DiskUser = components["schemas"]["DiskUser"];
|
|
54
55
|
type TokenUser = components["schemas"]["TokenUser"];
|
|
55
56
|
type AwsStsUser = components["schemas"]["AwsStsUser"];
|
|
@@ -396,6 +397,30 @@ declare class Disk implements FileSystem {
|
|
|
396
397
|
identifier: string;
|
|
397
398
|
}>;
|
|
398
399
|
removeTokenUser(identifier: string): Promise<void>;
|
|
400
|
+
/**
|
|
401
|
+
* List all delegations currently held on this disk. A delegation grants a
|
|
402
|
+
* client exclusive write access to an inode; it has no ID of its own and is
|
|
403
|
+
* identified by the (clientId, inodeId) pair — pass those to
|
|
404
|
+
* `revokeDelegation` to release one. Entries with `isOrphaned: true` are
|
|
405
|
+
* held by clients no longer connected to the disk (disconnected without
|
|
406
|
+
* checking in). `path` is resolved best-effort by the server and may be
|
|
407
|
+
* absent.
|
|
408
|
+
*/
|
|
409
|
+
listDelegations(): Promise<Delegation[]>;
|
|
410
|
+
/**
|
|
411
|
+
* Forcibly revoke a delegation, reclaiming write access from a client that
|
|
412
|
+
* is unreachable or crashed without checking its delegations in.
|
|
413
|
+
*
|
|
414
|
+
* Takes the `(clientId, inodeId)` pair identifying the delegation — pass an
|
|
415
|
+
* entry from `listDelegations` directly:
|
|
416
|
+
*
|
|
417
|
+
* ```ts
|
|
418
|
+
* for (const d of await disk.listDelegations()) {
|
|
419
|
+
* if (d.isOrphaned) await disk.revokeDelegation(d);
|
|
420
|
+
* }
|
|
421
|
+
* ```
|
|
422
|
+
*/
|
|
423
|
+
revokeDelegation(delegation: Pick<Delegation, "clientId" | "inodeId">): Promise<void>;
|
|
399
424
|
getAllowedIPs(): Promise<string[]>;
|
|
400
425
|
setAllowedIPs(allowedIps: string[]): Promise<string[]>;
|
|
401
426
|
addAllowedIP(ip: string): Promise<string[]>;
|
|
@@ -672,4 +697,4 @@ declare class DiskMultipart {
|
|
|
672
697
|
*/
|
|
673
698
|
declare function effectiveUploadPartSize(totalBytes: number, requestedPartSize: number): number;
|
|
674
699
|
//#endregion
|
|
675
|
-
export {
|
|
700
|
+
export { TokenUser as $, ApiTokenResponse as A, DiskStatus as B, PutObjectOptions as C, ShareUrlResult as D, ShareUrlOptions as E, CreateApiTokenRequest as F, GrepMatch as G, ExecDiskResult as H, CreateDiskRequest as I, MountConfigResponse as J, GrepStoppedReason as K, Delegation as L, AwsStsUser as M, AzureBlobMount as N, UploadPart as O, ConnectedClient as P, S3Mount as Q, DiskMetrics as R, PosixCreateAttrs as S, S3Object as T, ExecRequest as U, DiskUser as V, GCSMount as W, R2Mount as X, MountResponse as Y, S3CompatibleMount as Z, MultipartUploadListing as _, DeleteObjectsResult as a, PartInfo as b, ExecResult as c, ListMultipartUploadsOptions as d, FileSystem as et, ListObjectsOptions as f, MultipartUpload as g, MountOptions as h, DeleteObjectsOptions as i, AuthorizedUser as j, effectiveUploadPartSize as k, GrepOptions as l, ListPartsOptions as m, CompletedMultipartUpload as n, Disk as o, ListObjectsResult as p, MountConfig as q, DeleteObjectsError as r, DiskMultipart as s, AppendObjectOptions as t, ApiClient as tt, GrepResult as u, MultipartUploadSummary as v, PutObjectResult as w, PartListing as x, ObjectMetadata as y, DiskResponse as z };
|
|
@@ -50,6 +50,7 @@ type GCSMount = components["schemas"]["GCSMount"];
|
|
|
50
50
|
type R2Mount = components["schemas"]["R2Mount"];
|
|
51
51
|
type S3CompatibleMount = components["schemas"]["S3CompatibleMount"];
|
|
52
52
|
type AzureBlobMount = components["schemas"]["AzureBlobMount"];
|
|
53
|
+
type Delegation = components["schemas"]["DelegationEntry"];
|
|
53
54
|
type DiskUser = components["schemas"]["DiskUser"];
|
|
54
55
|
type TokenUser = components["schemas"]["TokenUser"];
|
|
55
56
|
type AwsStsUser = components["schemas"]["AwsStsUser"];
|
|
@@ -396,6 +397,30 @@ declare class Disk implements FileSystem {
|
|
|
396
397
|
identifier: string;
|
|
397
398
|
}>;
|
|
398
399
|
removeTokenUser(identifier: string): Promise<void>;
|
|
400
|
+
/**
|
|
401
|
+
* List all delegations currently held on this disk. A delegation grants a
|
|
402
|
+
* client exclusive write access to an inode; it has no ID of its own and is
|
|
403
|
+
* identified by the (clientId, inodeId) pair — pass those to
|
|
404
|
+
* `revokeDelegation` to release one. Entries with `isOrphaned: true` are
|
|
405
|
+
* held by clients no longer connected to the disk (disconnected without
|
|
406
|
+
* checking in). `path` is resolved best-effort by the server and may be
|
|
407
|
+
* absent.
|
|
408
|
+
*/
|
|
409
|
+
listDelegations(): Promise<Delegation[]>;
|
|
410
|
+
/**
|
|
411
|
+
* Forcibly revoke a delegation, reclaiming write access from a client that
|
|
412
|
+
* is unreachable or crashed without checking its delegations in.
|
|
413
|
+
*
|
|
414
|
+
* Takes the `(clientId, inodeId)` pair identifying the delegation — pass an
|
|
415
|
+
* entry from `listDelegations` directly:
|
|
416
|
+
*
|
|
417
|
+
* ```ts
|
|
418
|
+
* for (const d of await disk.listDelegations()) {
|
|
419
|
+
* if (d.isOrphaned) await disk.revokeDelegation(d);
|
|
420
|
+
* }
|
|
421
|
+
* ```
|
|
422
|
+
*/
|
|
423
|
+
revokeDelegation(delegation: Pick<Delegation, "clientId" | "inodeId">): Promise<void>;
|
|
399
424
|
getAllowedIPs(): Promise<string[]>;
|
|
400
425
|
setAllowedIPs(allowedIps: string[]): Promise<string[]>;
|
|
401
426
|
addAllowedIP(ip: string): Promise<string[]>;
|
|
@@ -672,4 +697,4 @@ declare class DiskMultipart {
|
|
|
672
697
|
*/
|
|
673
698
|
declare function effectiveUploadPartSize(totalBytes: number, requestedPartSize: number): number;
|
|
674
699
|
//#endregion
|
|
675
|
-
export {
|
|
700
|
+
export { TokenUser as $, ApiTokenResponse as A, DiskStatus as B, PutObjectOptions as C, ShareUrlResult as D, ShareUrlOptions as E, CreateApiTokenRequest as F, GrepMatch as G, ExecDiskResult as H, CreateDiskRequest as I, MountConfigResponse as J, GrepStoppedReason as K, Delegation as L, AwsStsUser as M, AzureBlobMount as N, UploadPart as O, ConnectedClient as P, S3Mount as Q, DiskMetrics as R, PosixCreateAttrs as S, S3Object as T, ExecRequest as U, DiskUser as V, GCSMount as W, R2Mount as X, MountResponse as Y, S3CompatibleMount as Z, MultipartUploadListing as _, DeleteObjectsResult as a, PartInfo as b, ExecResult as c, ListMultipartUploadsOptions as d, FileSystem as et, ListObjectsOptions as f, MultipartUpload as g, MountOptions as h, DeleteObjectsOptions as i, AuthorizedUser as j, effectiveUploadPartSize as k, GrepOptions as l, ListPartsOptions as m, CompletedMultipartUpload as n, Disk as o, ListObjectsResult as p, MountConfig as q, DeleteObjectsError as r, DiskMultipart as s, AppendObjectOptions as t, ApiClient as tt, GrepResult as u, MultipartUploadSummary as v, PutObjectResult as w, PartListing as x, ObjectMetadata as y, DiskResponse as z };
|
package/dist/index.cjs
CHANGED
|
@@ -134,7 +134,7 @@ function deriveS3BaseUrl(controlBaseUrl) {
|
|
|
134
134
|
}
|
|
135
135
|
//#endregion
|
|
136
136
|
//#region src/version.ts
|
|
137
|
-
const VERSION = "0.8.
|
|
137
|
+
const VERSION = "0.8.23";
|
|
138
138
|
const USER_AGENT = `archil-js/${VERSION}`;
|
|
139
139
|
//#endregion
|
|
140
140
|
//#region src/client.ts
|
|
@@ -275,6 +275,41 @@ var Disk = class {
|
|
|
275
275
|
async removeTokenUser(identifier) {
|
|
276
276
|
await this.removeUser("token", identifier);
|
|
277
277
|
}
|
|
278
|
+
/**
|
|
279
|
+
* List all delegations currently held on this disk. A delegation grants a
|
|
280
|
+
* client exclusive write access to an inode; it has no ID of its own and is
|
|
281
|
+
* identified by the (clientId, inodeId) pair — pass those to
|
|
282
|
+
* `revokeDelegation` to release one. Entries with `isOrphaned: true` are
|
|
283
|
+
* held by clients no longer connected to the disk (disconnected without
|
|
284
|
+
* checking in). `path` is resolved best-effort by the server and may be
|
|
285
|
+
* absent.
|
|
286
|
+
*/
|
|
287
|
+
async listDelegations() {
|
|
288
|
+
return (await unwrap(this._client.GET("/api/disks/{id}/delegations", { params: { path: { id: this.id } } }))).delegations;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Forcibly revoke a delegation, reclaiming write access from a client that
|
|
292
|
+
* is unreachable or crashed without checking its delegations in.
|
|
293
|
+
*
|
|
294
|
+
* Takes the `(clientId, inodeId)` pair identifying the delegation — pass an
|
|
295
|
+
* entry from `listDelegations` directly:
|
|
296
|
+
*
|
|
297
|
+
* ```ts
|
|
298
|
+
* for (const d of await disk.listDelegations()) {
|
|
299
|
+
* if (d.isOrphaned) await disk.revokeDelegation(d);
|
|
300
|
+
* }
|
|
301
|
+
* ```
|
|
302
|
+
*/
|
|
303
|
+
async revokeDelegation(delegation) {
|
|
304
|
+
const { clientId, inodeId } = delegation;
|
|
305
|
+
await unwrap(this._client.POST("/api/disks/{id}/revoke-delegation", {
|
|
306
|
+
params: { path: { id: this.id } },
|
|
307
|
+
body: {
|
|
308
|
+
clientId,
|
|
309
|
+
inodeId
|
|
310
|
+
}
|
|
311
|
+
}));
|
|
312
|
+
}
|
|
278
313
|
async getAllowedIPs() {
|
|
279
314
|
return (await unwrap(this._client.GET("/api/disks/{id}/allowed-ips", { params: { path: { id: this.id } } }))).allowedIps;
|
|
280
315
|
}
|
|
@@ -1122,6 +1157,319 @@ var Disks = class {
|
|
|
1122
1157
|
};
|
|
1123
1158
|
}
|
|
1124
1159
|
};
|
|
1160
|
+
const POLL_INTERVAL_MS = 500;
|
|
1161
|
+
/** @internal */
|
|
1162
|
+
function validateTimeoutMs(timeoutMs) {
|
|
1163
|
+
if (!Number.isFinite(timeoutMs) || timeoutMs < 0) throw new RangeError("timeoutMs must be a finite, non-negative number");
|
|
1164
|
+
}
|
|
1165
|
+
/**
|
|
1166
|
+
* The requested SDK-side wait expired. The remote sandbox operation continues;
|
|
1167
|
+
* `latest` is the same `Sandbox`/`SandboxExec` the operation was called on,
|
|
1168
|
+
* updated in place to the last state observed before the deadline.
|
|
1169
|
+
*/
|
|
1170
|
+
var SandboxWaitTimeoutError = class extends ArchilError {
|
|
1171
|
+
operation;
|
|
1172
|
+
timeoutMs;
|
|
1173
|
+
latest;
|
|
1174
|
+
constructor(operation, timeoutMs, latest) {
|
|
1175
|
+
const subject = operation === "exec" ? "sandbox exec to complete" : `sandbox to ${operation}`;
|
|
1176
|
+
super(`Timed out after ${timeoutMs}ms waiting for ${subject}`, 408, "SANDBOX_WAIT_TIMEOUT");
|
|
1177
|
+
this.name = "SandboxWaitTimeoutError";
|
|
1178
|
+
this.operation = operation;
|
|
1179
|
+
this.timeoutMs = timeoutMs;
|
|
1180
|
+
this.latest = latest;
|
|
1181
|
+
}
|
|
1182
|
+
};
|
|
1183
|
+
/** The sandbox entered an inactive state before startup completed. */
|
|
1184
|
+
var SandboxStartError = class extends ArchilError {
|
|
1185
|
+
latest;
|
|
1186
|
+
constructor(sandbox) {
|
|
1187
|
+
const detail = sandbox.exitReason ? `: ${sandbox.exitReason}` : "";
|
|
1188
|
+
super(`Sandbox entered ${sandbox.status} before it started${detail}`, 409, "SANDBOX_START_FAILED");
|
|
1189
|
+
this.name = "SandboxStartError";
|
|
1190
|
+
this.latest = sandbox;
|
|
1191
|
+
}
|
|
1192
|
+
};
|
|
1193
|
+
var SandboxExec = class {
|
|
1194
|
+
sandboxId;
|
|
1195
|
+
id;
|
|
1196
|
+
command;
|
|
1197
|
+
status;
|
|
1198
|
+
exitCode;
|
|
1199
|
+
stdout;
|
|
1200
|
+
stderr;
|
|
1201
|
+
exitReason;
|
|
1202
|
+
executeTimeMs;
|
|
1203
|
+
startedAt;
|
|
1204
|
+
finishedAt;
|
|
1205
|
+
/** @internal */
|
|
1206
|
+
_client;
|
|
1207
|
+
/** @internal */
|
|
1208
|
+
constructor(data, client) {
|
|
1209
|
+
this._client = client;
|
|
1210
|
+
this._apply(data);
|
|
1211
|
+
}
|
|
1212
|
+
/** @internal Overwrite this exec's fields in place from a fresh wire snapshot. */
|
|
1213
|
+
_apply(data) {
|
|
1214
|
+
this.sandboxId = data.sandbox_id;
|
|
1215
|
+
this.id = data.exec_id;
|
|
1216
|
+
this.command = data.command;
|
|
1217
|
+
this.status = data.status;
|
|
1218
|
+
this.exitCode = data.exit_code;
|
|
1219
|
+
this.stdout = data.stdout;
|
|
1220
|
+
this.stderr = data.stderr;
|
|
1221
|
+
this.exitReason = data.exit_reason;
|
|
1222
|
+
this.executeTimeMs = data.execute_time_ms;
|
|
1223
|
+
this.startedAt = new Date(data.started_at);
|
|
1224
|
+
this.finishedAt = data.finished_at ? new Date(data.finished_at) : void 0;
|
|
1225
|
+
return this;
|
|
1226
|
+
}
|
|
1227
|
+
toJSON() {
|
|
1228
|
+
return {
|
|
1229
|
+
sandboxId: this.sandboxId,
|
|
1230
|
+
id: this.id,
|
|
1231
|
+
command: this.command,
|
|
1232
|
+
status: this.status,
|
|
1233
|
+
exitCode: this.exitCode,
|
|
1234
|
+
stdout: this.stdout,
|
|
1235
|
+
stderr: this.stderr,
|
|
1236
|
+
exitReason: this.exitReason,
|
|
1237
|
+
executeTimeMs: this.executeTimeMs,
|
|
1238
|
+
startedAt: this.startedAt,
|
|
1239
|
+
finishedAt: this.finishedAt
|
|
1240
|
+
};
|
|
1241
|
+
}
|
|
1242
|
+
/** Re-fetch this exec and update it in place, returning the same object. */
|
|
1243
|
+
async refresh() {
|
|
1244
|
+
const data = await unwrap(this._client.GET("/api/sandboxes/{sid}/execs/{eid}", { params: { path: {
|
|
1245
|
+
sid: this.sandboxId,
|
|
1246
|
+
eid: this.id
|
|
1247
|
+
} } }));
|
|
1248
|
+
return this._apply(data);
|
|
1249
|
+
}
|
|
1250
|
+
/** Cancel this exec and update it in place, returning the same object. */
|
|
1251
|
+
async cancel() {
|
|
1252
|
+
const data = await unwrap(this._client.POST("/api/sandboxes/{sid}/execs/{eid}/cancel", { params: { path: {
|
|
1253
|
+
sid: this.sandboxId,
|
|
1254
|
+
eid: this.id
|
|
1255
|
+
} } }));
|
|
1256
|
+
return this._apply(data);
|
|
1257
|
+
}
|
|
1258
|
+
};
|
|
1259
|
+
var Sandbox = class {
|
|
1260
|
+
id;
|
|
1261
|
+
status;
|
|
1262
|
+
vcpuCount;
|
|
1263
|
+
memSizeMiB;
|
|
1264
|
+
maxTtlSeconds;
|
|
1265
|
+
maxConcurrentExecs;
|
|
1266
|
+
endpoints;
|
|
1267
|
+
createdAt;
|
|
1268
|
+
runningAt;
|
|
1269
|
+
finishedAt;
|
|
1270
|
+
lastActiveAt;
|
|
1271
|
+
expiresAt;
|
|
1272
|
+
exitReason;
|
|
1273
|
+
/** @internal */
|
|
1274
|
+
_client;
|
|
1275
|
+
/** @internal */
|
|
1276
|
+
constructor(data, client) {
|
|
1277
|
+
this._client = client;
|
|
1278
|
+
this._apply(data);
|
|
1279
|
+
}
|
|
1280
|
+
/** @internal Overwrite this sandbox's fields in place from a fresh wire snapshot. */
|
|
1281
|
+
_apply(data) {
|
|
1282
|
+
this.id = data.sandbox_id;
|
|
1283
|
+
this.status = data.status;
|
|
1284
|
+
this.vcpuCount = data.vcpu_count;
|
|
1285
|
+
this.memSizeMiB = data.mem_size_mib;
|
|
1286
|
+
this.maxTtlSeconds = data.max_ttl_seconds;
|
|
1287
|
+
this.maxConcurrentExecs = data.max_concurrent_execs;
|
|
1288
|
+
this.endpoints = data.endpoints?.map((endpoint) => ({ ...endpoint }));
|
|
1289
|
+
this.createdAt = new Date(data.created_at);
|
|
1290
|
+
this.runningAt = data.running_at ? new Date(data.running_at) : void 0;
|
|
1291
|
+
this.finishedAt = data.finished_at ? new Date(data.finished_at) : void 0;
|
|
1292
|
+
this.lastActiveAt = new Date(data.last_active_at);
|
|
1293
|
+
this.expiresAt = data.expires_at ? new Date(data.expires_at) : void 0;
|
|
1294
|
+
this.exitReason = data.exit_reason;
|
|
1295
|
+
return this;
|
|
1296
|
+
}
|
|
1297
|
+
toJSON() {
|
|
1298
|
+
return {
|
|
1299
|
+
id: this.id,
|
|
1300
|
+
status: this.status,
|
|
1301
|
+
vcpuCount: this.vcpuCount,
|
|
1302
|
+
memSizeMiB: this.memSizeMiB,
|
|
1303
|
+
maxTtlSeconds: this.maxTtlSeconds,
|
|
1304
|
+
maxConcurrentExecs: this.maxConcurrentExecs,
|
|
1305
|
+
endpoints: this.endpoints?.map((endpoint) => ({ ...endpoint })),
|
|
1306
|
+
createdAt: this.createdAt,
|
|
1307
|
+
runningAt: this.runningAt,
|
|
1308
|
+
finishedAt: this.finishedAt,
|
|
1309
|
+
lastActiveAt: this.lastActiveAt,
|
|
1310
|
+
expiresAt: this.expiresAt,
|
|
1311
|
+
exitReason: this.exitReason
|
|
1312
|
+
};
|
|
1313
|
+
}
|
|
1314
|
+
/** Re-fetch this sandbox. */
|
|
1315
|
+
async refresh() {
|
|
1316
|
+
const data = await unwrap(this._client.GET("/api/sandboxes/{sid}", { params: { path: { sid: this.id } } }));
|
|
1317
|
+
return this._apply(data);
|
|
1318
|
+
}
|
|
1319
|
+
/** Start this sandbox. */
|
|
1320
|
+
async start(options = {}) {
|
|
1321
|
+
const timeoutMs = options.timeoutMs ?? 3e4;
|
|
1322
|
+
validateTimeoutMs(timeoutMs);
|
|
1323
|
+
const deadline = Date.now() + timeoutMs;
|
|
1324
|
+
const data = await unwrap(this._client.POST("/api/sandboxes/{sid}/start", { params: {
|
|
1325
|
+
path: { sid: this.id },
|
|
1326
|
+
query: { wait: false }
|
|
1327
|
+
} }));
|
|
1328
|
+
this._apply(data);
|
|
1329
|
+
return waitForSandboxStart(this, deadline, timeoutMs);
|
|
1330
|
+
}
|
|
1331
|
+
/** Stop this sandbox. */
|
|
1332
|
+
async stop(options = {}) {
|
|
1333
|
+
const timeoutMs = options.timeoutMs ?? 3e4;
|
|
1334
|
+
validateTimeoutMs(timeoutMs);
|
|
1335
|
+
const deadline = Date.now() + timeoutMs;
|
|
1336
|
+
const data = await unwrap(this._client.POST("/api/sandboxes/{sid}/stop", { params: { path: { sid: this.id } } }));
|
|
1337
|
+
this._apply(data);
|
|
1338
|
+
for (;;) {
|
|
1339
|
+
if ([
|
|
1340
|
+
"stopped",
|
|
1341
|
+
"exited",
|
|
1342
|
+
"failed"
|
|
1343
|
+
].includes(this.status)) return this;
|
|
1344
|
+
if (this.status !== "stopping") throw new ArchilError(`Sandbox entered ${this.status} before it stopped`, 409, "SANDBOX_STOP_FAILED");
|
|
1345
|
+
const remaining = deadline - Date.now();
|
|
1346
|
+
if (remaining <= 0) throw new SandboxWaitTimeoutError("stop", timeoutMs, this);
|
|
1347
|
+
await new Promise((resolve) => setTimeout(resolve, Math.min(POLL_INTERVAL_MS, remaining)));
|
|
1348
|
+
await this.refresh();
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1351
|
+
/** Pause this sandbox, preserving its CPU and memory state. */
|
|
1352
|
+
async pause(options = {}) {
|
|
1353
|
+
const timeoutMs = options.timeoutMs ?? 3e4;
|
|
1354
|
+
validateTimeoutMs(timeoutMs);
|
|
1355
|
+
const deadline = Date.now() + timeoutMs;
|
|
1356
|
+
const data = await unwrap(this._client.POST("/api/sandboxes/{sid}/pause", { params: { path: { sid: this.id } } }));
|
|
1357
|
+
this._apply(data);
|
|
1358
|
+
for (;;) {
|
|
1359
|
+
if (this.status === "paused") return this;
|
|
1360
|
+
if (this.status !== "pausing") throw new ArchilError(`Sandbox entered ${this.status} before it paused`, 409, "SANDBOX_PAUSE_FAILED");
|
|
1361
|
+
const remaining = deadline - Date.now();
|
|
1362
|
+
if (remaining <= 0) throw new SandboxWaitTimeoutError("pause", timeoutMs, this);
|
|
1363
|
+
await new Promise((resolve) => setTimeout(resolve, Math.min(POLL_INTERVAL_MS, remaining)));
|
|
1364
|
+
await this.refresh();
|
|
1365
|
+
}
|
|
1366
|
+
}
|
|
1367
|
+
/** Resume this sandbox from its preserved CPU and memory state. */
|
|
1368
|
+
async resume(options = {}) {
|
|
1369
|
+
const timeoutMs = options.timeoutMs ?? 3e4;
|
|
1370
|
+
validateTimeoutMs(timeoutMs);
|
|
1371
|
+
const deadline = Date.now() + timeoutMs;
|
|
1372
|
+
const data = await unwrap(this._client.POST("/api/sandboxes/{sid}/resume", { params: {
|
|
1373
|
+
path: { sid: this.id },
|
|
1374
|
+
query: { wait: false }
|
|
1375
|
+
} }));
|
|
1376
|
+
this._apply(data);
|
|
1377
|
+
for (;;) {
|
|
1378
|
+
if (this.status === "running") return this;
|
|
1379
|
+
if (this.status !== "pending") throw new ArchilError(`Sandbox entered ${this.status} before it resumed`, 409, "SANDBOX_RESUME_FAILED");
|
|
1380
|
+
const remaining = deadline - Date.now();
|
|
1381
|
+
if (remaining <= 0) throw new SandboxWaitTimeoutError("resume", timeoutMs, this);
|
|
1382
|
+
await new Promise((resolve) => setTimeout(resolve, Math.min(POLL_INTERVAL_MS, remaining)));
|
|
1383
|
+
await this.refresh();
|
|
1384
|
+
}
|
|
1385
|
+
}
|
|
1386
|
+
async exec(command, options = {}) {
|
|
1387
|
+
const timeoutMs = options.timeoutMs ?? 3e4;
|
|
1388
|
+
validateTimeoutMs(timeoutMs);
|
|
1389
|
+
const deadline = Date.now() + timeoutMs;
|
|
1390
|
+
const exec = new SandboxExec(await unwrap(this._client.POST("/api/sandboxes/{sid}/execs", {
|
|
1391
|
+
params: {
|
|
1392
|
+
path: { sid: this.id },
|
|
1393
|
+
query: { wait: false }
|
|
1394
|
+
},
|
|
1395
|
+
body: {
|
|
1396
|
+
command,
|
|
1397
|
+
command_tty: options.commandTty,
|
|
1398
|
+
env: options.env,
|
|
1399
|
+
timeout_seconds: options.timeoutSeconds
|
|
1400
|
+
}
|
|
1401
|
+
})), this._client);
|
|
1402
|
+
if (exec.status !== "running") return exec;
|
|
1403
|
+
for (;;) {
|
|
1404
|
+
const remaining = deadline - Date.now();
|
|
1405
|
+
if (remaining <= 0) throw new SandboxWaitTimeoutError("exec", timeoutMs, exec);
|
|
1406
|
+
await new Promise((resolve) => setTimeout(resolve, Math.min(POLL_INTERVAL_MS, remaining)));
|
|
1407
|
+
await exec.refresh();
|
|
1408
|
+
if (exec.status !== "running") return exec;
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1411
|
+
async listExecs() {
|
|
1412
|
+
return ((await unwrap(this._client.GET("/api/sandboxes/{sid}/execs", { params: { path: { sid: this.id } } })))?.execs ?? []).map((exec) => new SandboxExec(exec, this._client));
|
|
1413
|
+
}
|
|
1414
|
+
async getExec(execId) {
|
|
1415
|
+
return new SandboxExec(await unwrap(this._client.GET("/api/sandboxes/{sid}/execs/{eid}", { params: { path: {
|
|
1416
|
+
sid: this.id,
|
|
1417
|
+
eid: execId
|
|
1418
|
+
} } })), this._client);
|
|
1419
|
+
}
|
|
1420
|
+
async cancelExec(execId) {
|
|
1421
|
+
return new SandboxExec(await unwrap(this._client.POST("/api/sandboxes/{sid}/execs/{eid}/cancel", { params: { path: {
|
|
1422
|
+
sid: this.id,
|
|
1423
|
+
eid: execId
|
|
1424
|
+
} } })), this._client);
|
|
1425
|
+
}
|
|
1426
|
+
};
|
|
1427
|
+
/** @internal Poll `sandbox` in place until it is running (or the deadline passes). */
|
|
1428
|
+
async function waitForSandboxStart(sandbox, deadline, timeoutMs) {
|
|
1429
|
+
for (;;) {
|
|
1430
|
+
if (sandbox.status === "running") return sandbox;
|
|
1431
|
+
if (sandbox.status !== "pending") throw new SandboxStartError(sandbox);
|
|
1432
|
+
const remaining = deadline - Date.now();
|
|
1433
|
+
if (remaining <= 0) throw new SandboxWaitTimeoutError("start", timeoutMs, sandbox);
|
|
1434
|
+
await new Promise((resolve) => setTimeout(resolve, Math.min(POLL_INTERVAL_MS, remaining)));
|
|
1435
|
+
await sandbox.refresh();
|
|
1436
|
+
}
|
|
1437
|
+
}
|
|
1438
|
+
//#endregion
|
|
1439
|
+
//#region src/sandboxes.ts
|
|
1440
|
+
var Sandboxes = class {
|
|
1441
|
+
/** @internal */
|
|
1442
|
+
_client;
|
|
1443
|
+
/** @internal */
|
|
1444
|
+
constructor(client) {
|
|
1445
|
+
this._client = client;
|
|
1446
|
+
}
|
|
1447
|
+
/** List the account's sandboxes, oldest first. */
|
|
1448
|
+
async list(options = {}) {
|
|
1449
|
+
const filesystem = typeof options.disk === "string" ? options.disk : options.disk?.id;
|
|
1450
|
+
return ((await unwrap(this._client.GET("/api/sandboxes", { params: { query: { filesystem } } })))?.sandboxes ?? []).map((sandbox) => new Sandbox(sandbox, this._client));
|
|
1451
|
+
}
|
|
1452
|
+
async get(id) {
|
|
1453
|
+
return new Sandbox(await unwrap(this._client.GET("/api/sandboxes/{sid}", { params: { path: { sid: id } } })), this._client);
|
|
1454
|
+
}
|
|
1455
|
+
async create(request = {}, options = {}) {
|
|
1456
|
+
const timeoutMs = options.timeoutMs ?? 3e4;
|
|
1457
|
+
validateTimeoutMs(timeoutMs);
|
|
1458
|
+
const deadline = Date.now() + timeoutMs;
|
|
1459
|
+
const body = {
|
|
1460
|
+
vcpu_count: request.vcpuCount,
|
|
1461
|
+
mem_size_mib: request.memSizeMiB,
|
|
1462
|
+
base_image: request.baseImage,
|
|
1463
|
+
env: request.env,
|
|
1464
|
+
max_ttl_seconds: request.maxTtlSeconds,
|
|
1465
|
+
max_concurrent_execs: request.maxConcurrentExecs
|
|
1466
|
+
};
|
|
1467
|
+
return waitForSandboxStart(new Sandbox(await unwrap(this._client.POST("/api/sandboxes", {
|
|
1468
|
+
params: { query: { wait: false } },
|
|
1469
|
+
body
|
|
1470
|
+
})), this._client), deadline, timeoutMs);
|
|
1471
|
+
}
|
|
1472
|
+
};
|
|
1125
1473
|
//#endregion
|
|
1126
1474
|
//#region src/tokens.ts
|
|
1127
1475
|
var Tokens = class {
|
|
@@ -1404,6 +1752,7 @@ function diskIdFromMount(m) {
|
|
|
1404
1752
|
}
|
|
1405
1753
|
var Archil = class {
|
|
1406
1754
|
disks;
|
|
1755
|
+
sandboxes;
|
|
1407
1756
|
tokens;
|
|
1408
1757
|
/** @internal */
|
|
1409
1758
|
_client;
|
|
@@ -1421,6 +1770,7 @@ var Archil = class {
|
|
|
1421
1770
|
const s3BaseUrl = opts.s3BaseUrl ?? envVar("ARCHIL_S3_BASE_URL") ?? deriveS3BaseUrl(controlBaseUrl);
|
|
1422
1771
|
this._client = client;
|
|
1423
1772
|
this.disks = new Disks(client, region, s3BaseUrl);
|
|
1773
|
+
this.sandboxes = new Sandboxes(client);
|
|
1424
1774
|
this.tokens = new Tokens(client);
|
|
1425
1775
|
}
|
|
1426
1776
|
/**
|
|
@@ -1478,6 +1828,15 @@ function listDisks(opts) {
|
|
|
1478
1828
|
function getDisk(id) {
|
|
1479
1829
|
return archil().disks.get(id);
|
|
1480
1830
|
}
|
|
1831
|
+
function createSandbox(req = {}, opts = {}) {
|
|
1832
|
+
return archil().sandboxes.create(req, opts);
|
|
1833
|
+
}
|
|
1834
|
+
function listSandboxes(opts) {
|
|
1835
|
+
return archil().sandboxes.list(opts);
|
|
1836
|
+
}
|
|
1837
|
+
function getSandbox(id) {
|
|
1838
|
+
return archil().sandboxes.get(id);
|
|
1839
|
+
}
|
|
1481
1840
|
function listApiKeys(opts) {
|
|
1482
1841
|
return archil().tokens.list(opts);
|
|
1483
1842
|
}
|
|
@@ -1510,6 +1869,11 @@ exports.ArchilS3Error = ArchilS3Error;
|
|
|
1510
1869
|
exports.Disk = Disk;
|
|
1511
1870
|
exports.DiskMultipart = DiskMultipart;
|
|
1512
1871
|
exports.Disks = Disks;
|
|
1872
|
+
exports.Sandbox = Sandbox;
|
|
1873
|
+
exports.SandboxExec = SandboxExec;
|
|
1874
|
+
exports.SandboxStartError = SandboxStartError;
|
|
1875
|
+
exports.SandboxWaitTimeoutError = SandboxWaitTimeoutError;
|
|
1876
|
+
exports.Sandboxes = Sandboxes;
|
|
1513
1877
|
exports.Tokens = Tokens;
|
|
1514
1878
|
exports.USER_AGENT = USER_AGENT;
|
|
1515
1879
|
exports.VERSION = VERSION;
|
|
@@ -1517,10 +1881,13 @@ exports.Workspace = Workspace;
|
|
|
1517
1881
|
exports.configure = configure;
|
|
1518
1882
|
exports.createApiKey = createApiKey;
|
|
1519
1883
|
exports.createDisk = createDisk;
|
|
1884
|
+
exports.createSandbox = createSandbox;
|
|
1520
1885
|
exports.deleteApiKey = deleteApiKey;
|
|
1521
1886
|
exports.effectiveUploadPartSize = effectiveUploadPartSize;
|
|
1522
1887
|
exports.exec = exec;
|
|
1523
1888
|
exports.getDisk = getDisk;
|
|
1889
|
+
exports.getSandbox = getSandbox;
|
|
1524
1890
|
exports.listApiKeys = listApiKeys;
|
|
1525
1891
|
exports.listDisks = listDisks;
|
|
1892
|
+
exports.listSandboxes = listSandboxes;
|
|
1526
1893
|
exports.workspace = workspace;
|