disk 0.8.22 → 0.9.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 +85 -0
- package/dist/cli.mjs +3 -2
- package/dist/{disk-DEqV3mtA.d.cts → disk-DseHuBL7.d.cts} +14 -5
- package/dist/{disk-DEqV3mtA.d.mts → disk-DseHuBL7.d.mts} +14 -5
- package/dist/index.cjs +378 -8
- package/dist/index.d.cts +203 -2
- package/dist/index.d.mts +203 -2
- 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-BepELcl6.mjs → src-CR3Ksi_s.mjs} +372 -9
- package/package.json +2 -2
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.
|
|
137
|
+
const VERSION = "0.9.0";
|
|
138
138
|
const USER_AGENT = `archil-js/${VERSION}`;
|
|
139
139
|
//#endregion
|
|
140
140
|
//#region src/client.ts
|
|
@@ -174,6 +174,7 @@ async function unwrapPage(promise) {
|
|
|
174
174
|
*/
|
|
175
175
|
async function unwrapEmpty(promise) {
|
|
176
176
|
const { data: body, error, response } = await promise;
|
|
177
|
+
if (!error && response.status === 204) return;
|
|
177
178
|
if (error || !body) throw new ArchilApiError(error?.error ?? `API request failed with status ${response.status}`, response.status);
|
|
178
179
|
if (!body.success) throw new ArchilApiError(body.error ?? "Unknown API error", response.status);
|
|
179
180
|
}
|
|
@@ -189,6 +190,9 @@ var Disk = class {
|
|
|
189
190
|
createdAt;
|
|
190
191
|
fsHandlerStatus;
|
|
191
192
|
lastAccessed;
|
|
193
|
+
activeDataBytes;
|
|
194
|
+
totalDataBytes;
|
|
195
|
+
/** @deprecated Use {@link activeDataBytes}. */
|
|
192
196
|
dataSize;
|
|
193
197
|
monthlyUsage;
|
|
194
198
|
mounts;
|
|
@@ -215,7 +219,9 @@ var Disk = class {
|
|
|
215
219
|
this.createdAt = data.createdAt;
|
|
216
220
|
this.fsHandlerStatus = data.fsHandlerStatus;
|
|
217
221
|
this.lastAccessed = data.lastAccessed;
|
|
218
|
-
this.
|
|
222
|
+
this.activeDataBytes = data.activeDataBytes;
|
|
223
|
+
this.totalDataBytes = data.totalDataBytes;
|
|
224
|
+
this.dataSize = data.activeDataBytes;
|
|
219
225
|
this.monthlyUsage = data.monthlyUsage;
|
|
220
226
|
this.mounts = data.mounts;
|
|
221
227
|
this.metrics = data.metrics;
|
|
@@ -237,7 +243,8 @@ var Disk = class {
|
|
|
237
243
|
createdAt: this.createdAt,
|
|
238
244
|
fsHandlerStatus: this.fsHandlerStatus,
|
|
239
245
|
lastAccessed: this.lastAccessed,
|
|
240
|
-
|
|
246
|
+
activeDataBytes: this.activeDataBytes,
|
|
247
|
+
totalDataBytes: this.totalDataBytes,
|
|
241
248
|
monthlyUsage: this.monthlyUsage,
|
|
242
249
|
mounts: this.mounts,
|
|
243
250
|
metrics: this.metrics,
|
|
@@ -431,7 +438,10 @@ var Disk = class {
|
|
|
431
438
|
*
|
|
432
439
|
* Optional `mode` / `uid` / `gid` set the POSIX attributes of the published
|
|
433
440
|
* file (e.g. `{ mode: 0o644, uid: 1000, gid: 1000 }` for a non-root agent
|
|
434
|
-
* sandbox).
|
|
441
|
+
* sandbox). Missing parent directories inherit `uid` / `gid` with mode
|
|
442
|
+
* `0755`; existing directories remain unchanged. A key ending in `/` creates
|
|
443
|
+
* an explicit directory marker whose leaf uses the requested attributes.
|
|
444
|
+
* Defaults are `root:root 0644` for files and `root:root 0755` for directories.
|
|
435
445
|
*
|
|
436
446
|
* @param key Path on the disk (e.g. "reports/2026-01/data.json")
|
|
437
447
|
* @param body Contents as a string, Uint8Array/Buffer, or ArrayBuffer
|
|
@@ -503,7 +513,8 @@ var Disk = class {
|
|
|
503
513
|
*
|
|
504
514
|
* When the object does not yet exist, optional `mode` / `uid` / `gid` set the
|
|
505
515
|
* POSIX attributes of the newly created file (same headers as
|
|
506
|
-
* {@link putObject});
|
|
516
|
+
* {@link putObject}); missing parents inherit `uid` / `gid` with mode `0755`.
|
|
517
|
+
* Existing files and directories are unchanged.
|
|
507
518
|
*
|
|
508
519
|
* @param key Path on the disk (e.g. "logs/app.log")
|
|
509
520
|
* @param body Bytes to append (string, Uint8Array/Buffer, or ArrayBuffer)
|
|
@@ -699,7 +710,7 @@ var Disk = class {
|
|
|
699
710
|
({error, response} = await call(path, init));
|
|
700
711
|
} catch (transportError) {
|
|
701
712
|
if (attempt < maxRetries) {
|
|
702
|
-
await sleep(s3RetryDelayMs(attempt));
|
|
713
|
+
await sleep$1(s3RetryDelayMs(attempt));
|
|
703
714
|
continue;
|
|
704
715
|
}
|
|
705
716
|
throw transportError;
|
|
@@ -707,7 +718,7 @@ var Disk = class {
|
|
|
707
718
|
if (!response.ok) {
|
|
708
719
|
if (isTransientS3Status(response.status) && attempt < maxRetries) {
|
|
709
720
|
await response.body?.cancel().catch(() => {});
|
|
710
|
-
await sleep(s3RetryDelayMs(attempt));
|
|
721
|
+
await sleep$1(s3RetryDelayMs(attempt));
|
|
711
722
|
continue;
|
|
712
723
|
}
|
|
713
724
|
const message = typeof error === "string" ? error : error ? JSON.stringify(error) : "";
|
|
@@ -942,7 +953,7 @@ function s3RetryDelayMs(attempt) {
|
|
|
942
953
|
const ceiling = Math.min(S3_RETRY_CAP_MS, S3_RETRY_BASE_MS * 2 ** attempt);
|
|
943
954
|
return Math.random() * ceiling;
|
|
944
955
|
}
|
|
945
|
-
function sleep(ms) {
|
|
956
|
+
function sleep$1(ms) {
|
|
946
957
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
947
958
|
}
|
|
948
959
|
/** S3's minimum size for every multipart part but the last (5 MiB). */
|
|
@@ -1158,6 +1169,347 @@ var Disks = class {
|
|
|
1158
1169
|
}
|
|
1159
1170
|
};
|
|
1160
1171
|
//#endregion
|
|
1172
|
+
//#region src/sandbox.ts
|
|
1173
|
+
const POLL_INTERVAL_MS = 500;
|
|
1174
|
+
function sleep() {
|
|
1175
|
+
return new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL_MS));
|
|
1176
|
+
}
|
|
1177
|
+
var SandboxExec = class {
|
|
1178
|
+
sandboxId;
|
|
1179
|
+
id;
|
|
1180
|
+
command;
|
|
1181
|
+
status;
|
|
1182
|
+
exitCode;
|
|
1183
|
+
stdout;
|
|
1184
|
+
stderr;
|
|
1185
|
+
exitReason;
|
|
1186
|
+
executeTimeMs;
|
|
1187
|
+
startedAt;
|
|
1188
|
+
finishedAt;
|
|
1189
|
+
/** @internal */
|
|
1190
|
+
_client;
|
|
1191
|
+
/** @internal */
|
|
1192
|
+
constructor(data, client) {
|
|
1193
|
+
this._client = client;
|
|
1194
|
+
this._apply(data);
|
|
1195
|
+
}
|
|
1196
|
+
/** @internal Overwrite this exec's fields in place from a fresh wire snapshot. */
|
|
1197
|
+
_apply(data) {
|
|
1198
|
+
this.sandboxId = data.sandbox_id;
|
|
1199
|
+
this.id = data.exec_id;
|
|
1200
|
+
this.command = data.command;
|
|
1201
|
+
this.status = data.status;
|
|
1202
|
+
this.exitCode = data.exit_code;
|
|
1203
|
+
this.stdout = data.stdout;
|
|
1204
|
+
this.stderr = data.stderr;
|
|
1205
|
+
this.exitReason = data.exit_reason;
|
|
1206
|
+
this.executeTimeMs = data.execute_time_ms;
|
|
1207
|
+
this.startedAt = new Date(data.started_at);
|
|
1208
|
+
this.finishedAt = data.finished_at ? new Date(data.finished_at) : void 0;
|
|
1209
|
+
return this;
|
|
1210
|
+
}
|
|
1211
|
+
toJSON() {
|
|
1212
|
+
return {
|
|
1213
|
+
sandboxId: this.sandboxId,
|
|
1214
|
+
id: this.id,
|
|
1215
|
+
command: this.command,
|
|
1216
|
+
status: this.status,
|
|
1217
|
+
exitCode: this.exitCode,
|
|
1218
|
+
stdout: this.stdout,
|
|
1219
|
+
stderr: this.stderr,
|
|
1220
|
+
exitReason: this.exitReason,
|
|
1221
|
+
executeTimeMs: this.executeTimeMs,
|
|
1222
|
+
startedAt: this.startedAt,
|
|
1223
|
+
finishedAt: this.finishedAt
|
|
1224
|
+
};
|
|
1225
|
+
}
|
|
1226
|
+
/** Re-fetch this exec and update it in place, returning the same object. */
|
|
1227
|
+
async refresh() {
|
|
1228
|
+
const data = await unwrap(this._client.GET("/api/sandboxes/{sid}/execs/{eid}", { params: { path: {
|
|
1229
|
+
sid: this.sandboxId,
|
|
1230
|
+
eid: this.id
|
|
1231
|
+
} } }));
|
|
1232
|
+
return this._apply(data);
|
|
1233
|
+
}
|
|
1234
|
+
/** Cancel this exec and update it in place, returning the same object. */
|
|
1235
|
+
async cancel() {
|
|
1236
|
+
const data = await unwrap(this._client.POST("/api/sandboxes/{sid}/execs/{eid}/cancel", { params: { path: {
|
|
1237
|
+
sid: this.sandboxId,
|
|
1238
|
+
eid: this.id
|
|
1239
|
+
} } }));
|
|
1240
|
+
return this._apply(data);
|
|
1241
|
+
}
|
|
1242
|
+
};
|
|
1243
|
+
var SandboxPty = class SandboxPty {
|
|
1244
|
+
_socket;
|
|
1245
|
+
_completion;
|
|
1246
|
+
/** @internal */
|
|
1247
|
+
constructor(socket, onData) {
|
|
1248
|
+
this._socket = socket;
|
|
1249
|
+
this._completion = new Promise((resolve) => {
|
|
1250
|
+
socket.addEventListener("message", (event) => {
|
|
1251
|
+
if (typeof event.data === "string") onData?.(event.data);
|
|
1252
|
+
});
|
|
1253
|
+
socket.addEventListener("close", (event) => {
|
|
1254
|
+
const match = /^process exited with code (-?\d+)$/.exec(event.reason);
|
|
1255
|
+
resolve({ exitCode: match ? Number(match[1]) : void 0 });
|
|
1256
|
+
}, { once: true });
|
|
1257
|
+
});
|
|
1258
|
+
}
|
|
1259
|
+
/** @internal */
|
|
1260
|
+
static connect(url, command, options) {
|
|
1261
|
+
return new Promise((resolve, reject) => {
|
|
1262
|
+
const socket = new WebSocket(url);
|
|
1263
|
+
const handleError = () => reject(/* @__PURE__ */ new Error("Interactive exec connection failed"));
|
|
1264
|
+
socket.addEventListener("error", handleError, { once: true });
|
|
1265
|
+
socket.addEventListener("open", () => {
|
|
1266
|
+
socket.removeEventListener("error", handleError);
|
|
1267
|
+
const pty = new SandboxPty(socket, options.onData);
|
|
1268
|
+
pty._send({
|
|
1269
|
+
type: "resize",
|
|
1270
|
+
cols: options.cols ?? 80,
|
|
1271
|
+
rows: options.rows ?? 24
|
|
1272
|
+
});
|
|
1273
|
+
const quotedCommand = `'${command.replaceAll("'", `'"'"'`)}'`;
|
|
1274
|
+
pty._send({
|
|
1275
|
+
type: "input",
|
|
1276
|
+
data: `eval ${quotedCommand}; exit $?\n`
|
|
1277
|
+
});
|
|
1278
|
+
resolve(pty);
|
|
1279
|
+
}, { once: true });
|
|
1280
|
+
});
|
|
1281
|
+
}
|
|
1282
|
+
async sendInput(data) {
|
|
1283
|
+
this._send({
|
|
1284
|
+
type: "input",
|
|
1285
|
+
data
|
|
1286
|
+
});
|
|
1287
|
+
}
|
|
1288
|
+
async resize(size) {
|
|
1289
|
+
this._send({
|
|
1290
|
+
type: "resize",
|
|
1291
|
+
...size
|
|
1292
|
+
});
|
|
1293
|
+
}
|
|
1294
|
+
wait() {
|
|
1295
|
+
return this._completion;
|
|
1296
|
+
}
|
|
1297
|
+
close() {
|
|
1298
|
+
this._socket.close();
|
|
1299
|
+
}
|
|
1300
|
+
_send(message) {
|
|
1301
|
+
this._socket.send(JSON.stringify(message));
|
|
1302
|
+
}
|
|
1303
|
+
};
|
|
1304
|
+
var Sandbox = class Sandbox {
|
|
1305
|
+
id;
|
|
1306
|
+
name;
|
|
1307
|
+
status;
|
|
1308
|
+
vcpuCount;
|
|
1309
|
+
memSizeMiB;
|
|
1310
|
+
baseImage;
|
|
1311
|
+
platform;
|
|
1312
|
+
maxTtlSeconds;
|
|
1313
|
+
maxConcurrentExecs;
|
|
1314
|
+
endpoints;
|
|
1315
|
+
createdAt;
|
|
1316
|
+
runningAt;
|
|
1317
|
+
finishedAt;
|
|
1318
|
+
lastActiveAt;
|
|
1319
|
+
expiresAt;
|
|
1320
|
+
exitReason;
|
|
1321
|
+
/** @internal */
|
|
1322
|
+
_client;
|
|
1323
|
+
/** @internal */
|
|
1324
|
+
constructor(data, client) {
|
|
1325
|
+
this._client = client;
|
|
1326
|
+
this._apply(data);
|
|
1327
|
+
}
|
|
1328
|
+
/** @internal Overwrite this sandbox's fields in place from a fresh wire snapshot. */
|
|
1329
|
+
_apply(data) {
|
|
1330
|
+
this.id = data.sandbox_id;
|
|
1331
|
+
this.name = data.name;
|
|
1332
|
+
this.status = data.status;
|
|
1333
|
+
this.vcpuCount = data.vcpu_count;
|
|
1334
|
+
this.memSizeMiB = data.mem_size_mib;
|
|
1335
|
+
this.baseImage = data.base_image;
|
|
1336
|
+
this.platform = data.platform;
|
|
1337
|
+
this.maxTtlSeconds = data.max_ttl_seconds;
|
|
1338
|
+
this.maxConcurrentExecs = data.max_concurrent_execs;
|
|
1339
|
+
this.endpoints = data.endpoints?.map((endpoint) => ({ ...endpoint }));
|
|
1340
|
+
this.createdAt = new Date(data.created_at);
|
|
1341
|
+
this.runningAt = data.running_at ? new Date(data.running_at) : void 0;
|
|
1342
|
+
this.finishedAt = data.finished_at ? new Date(data.finished_at) : void 0;
|
|
1343
|
+
this.lastActiveAt = new Date(data.last_active_at);
|
|
1344
|
+
this.expiresAt = data.expires_at ? new Date(data.expires_at) : void 0;
|
|
1345
|
+
this.exitReason = data.exit_reason;
|
|
1346
|
+
return this;
|
|
1347
|
+
}
|
|
1348
|
+
toJSON() {
|
|
1349
|
+
return {
|
|
1350
|
+
id: this.id,
|
|
1351
|
+
name: this.name,
|
|
1352
|
+
status: this.status,
|
|
1353
|
+
vcpuCount: this.vcpuCount,
|
|
1354
|
+
memSizeMiB: this.memSizeMiB,
|
|
1355
|
+
baseImage: this.baseImage,
|
|
1356
|
+
platform: this.platform,
|
|
1357
|
+
maxTtlSeconds: this.maxTtlSeconds,
|
|
1358
|
+
maxConcurrentExecs: this.maxConcurrentExecs,
|
|
1359
|
+
endpoints: this.endpoints?.map((endpoint) => ({ ...endpoint })),
|
|
1360
|
+
createdAt: this.createdAt,
|
|
1361
|
+
runningAt: this.runningAt,
|
|
1362
|
+
finishedAt: this.finishedAt,
|
|
1363
|
+
lastActiveAt: this.lastActiveAt,
|
|
1364
|
+
expiresAt: this.expiresAt,
|
|
1365
|
+
exitReason: this.exitReason
|
|
1366
|
+
};
|
|
1367
|
+
}
|
|
1368
|
+
/** Re-fetch this sandbox. */
|
|
1369
|
+
async refresh() {
|
|
1370
|
+
const data = await unwrap(this._client.GET("/api/sandboxes/{sid}", { params: { path: { sid: this.id } } }));
|
|
1371
|
+
return this._apply(data);
|
|
1372
|
+
}
|
|
1373
|
+
/** Start this sandbox. */
|
|
1374
|
+
async start(options = {}) {
|
|
1375
|
+
const data = await unwrap(this._client.POST("/api/sandboxes/{sid}/start", { params: {
|
|
1376
|
+
path: { sid: this.id },
|
|
1377
|
+
query: { wait: options.wait ?? true }
|
|
1378
|
+
} }));
|
|
1379
|
+
this._apply(data);
|
|
1380
|
+
return options.wait === false ? this : waitForSandboxStart(this);
|
|
1381
|
+
}
|
|
1382
|
+
/** Stop this sandbox. */
|
|
1383
|
+
async stop(options = {}) {
|
|
1384
|
+
const data = await unwrap(this._client.POST("/api/sandboxes/{sid}/stop", { params: { path: { sid: this.id } } }));
|
|
1385
|
+
this._apply(data);
|
|
1386
|
+
return options.wait === false ? this : waitWhileSandboxStatus(this, "stopping");
|
|
1387
|
+
}
|
|
1388
|
+
/** Pause this sandbox, preserving its CPU and memory state. */
|
|
1389
|
+
async pause(options = {}) {
|
|
1390
|
+
const data = await unwrap(this._client.POST("/api/sandboxes/{sid}/pause", { params: { path: { sid: this.id } } }));
|
|
1391
|
+
this._apply(data);
|
|
1392
|
+
return options.wait === false ? this : waitWhileSandboxStatus(this, "pausing");
|
|
1393
|
+
}
|
|
1394
|
+
/** Resume this sandbox from its preserved CPU and memory state. */
|
|
1395
|
+
async resume(options = {}) {
|
|
1396
|
+
const data = await unwrap(this._client.POST("/api/sandboxes/{sid}/resume", { params: {
|
|
1397
|
+
path: { sid: this.id },
|
|
1398
|
+
query: { wait: options.wait ?? true }
|
|
1399
|
+
} }));
|
|
1400
|
+
this._apply(data);
|
|
1401
|
+
return options.wait === false ? this : waitForSandboxStart(this);
|
|
1402
|
+
}
|
|
1403
|
+
/** Create an isolated writable branch from this sandbox's current state. */
|
|
1404
|
+
async fork(options = {}) {
|
|
1405
|
+
const data = await unwrap(this._client.POST("/api/sandboxes/{sid}/fork", {
|
|
1406
|
+
params: {
|
|
1407
|
+
path: { sid: this.id },
|
|
1408
|
+
query: { wait: options.wait ?? true }
|
|
1409
|
+
},
|
|
1410
|
+
body: options.name === void 0 ? void 0 : { name: options.name }
|
|
1411
|
+
}));
|
|
1412
|
+
const fork = new Sandbox(data, this._client);
|
|
1413
|
+
return options.wait === false ? fork : waitForSandboxStart(fork);
|
|
1414
|
+
}
|
|
1415
|
+
/** Create a short-lived signed WebSocket URL for an interactive shell. */
|
|
1416
|
+
async createConnection() {
|
|
1417
|
+
const data = await unwrap(this._client.POST("/api/sandboxes/{sid}/connections", { params: { path: { sid: this.id } } }));
|
|
1418
|
+
return {
|
|
1419
|
+
url: data.url,
|
|
1420
|
+
expiresAt: new Date(data.expires_at)
|
|
1421
|
+
};
|
|
1422
|
+
}
|
|
1423
|
+
/** Delete this sandbox and its backing disk. */
|
|
1424
|
+
async delete() {
|
|
1425
|
+
await unwrapEmpty(this._client.DELETE("/api/sandboxes/{sid}", { params: { path: { sid: this.id } } }));
|
|
1426
|
+
}
|
|
1427
|
+
async exec(command, options = {}) {
|
|
1428
|
+
if ("pty" in options) {
|
|
1429
|
+
const connection = await this.createConnection();
|
|
1430
|
+
return SandboxPty.connect(connection.url, command, options);
|
|
1431
|
+
}
|
|
1432
|
+
const exec = new SandboxExec(await unwrap(this._client.POST("/api/sandboxes/{sid}/execs", {
|
|
1433
|
+
params: {
|
|
1434
|
+
path: { sid: this.id },
|
|
1435
|
+
query: { wait: options.wait ?? true }
|
|
1436
|
+
},
|
|
1437
|
+
body: {
|
|
1438
|
+
command,
|
|
1439
|
+
command_tty: options.commandTty,
|
|
1440
|
+
env: options.env,
|
|
1441
|
+
timeout_seconds: options.timeoutSeconds
|
|
1442
|
+
}
|
|
1443
|
+
})), this._client);
|
|
1444
|
+
if (options.wait === false) return exec;
|
|
1445
|
+
while (exec.status === "running") {
|
|
1446
|
+
await sleep();
|
|
1447
|
+
await exec.refresh();
|
|
1448
|
+
}
|
|
1449
|
+
return exec;
|
|
1450
|
+
}
|
|
1451
|
+
async listExecs() {
|
|
1452
|
+
return ((await unwrap(this._client.GET("/api/sandboxes/{sid}/execs", { params: { path: { sid: this.id } } })))?.execs ?? []).map((exec) => new SandboxExec(exec, this._client));
|
|
1453
|
+
}
|
|
1454
|
+
async getExec(execId) {
|
|
1455
|
+
return new SandboxExec(await unwrap(this._client.GET("/api/sandboxes/{sid}/execs/{eid}", { params: { path: {
|
|
1456
|
+
sid: this.id,
|
|
1457
|
+
eid: execId
|
|
1458
|
+
} } })), this._client);
|
|
1459
|
+
}
|
|
1460
|
+
async cancelExec(execId) {
|
|
1461
|
+
return new SandboxExec(await unwrap(this._client.POST("/api/sandboxes/{sid}/execs/{eid}/cancel", { params: { path: {
|
|
1462
|
+
sid: this.id,
|
|
1463
|
+
eid: execId
|
|
1464
|
+
} } })), this._client);
|
|
1465
|
+
}
|
|
1466
|
+
};
|
|
1467
|
+
/** @internal Continue waiting if the server returned before startup completed. */
|
|
1468
|
+
async function waitForSandboxStart(sandbox) {
|
|
1469
|
+
return waitWhileSandboxStatus(sandbox, "pending");
|
|
1470
|
+
}
|
|
1471
|
+
async function waitWhileSandboxStatus(sandbox, status) {
|
|
1472
|
+
while (sandbox.status === status) {
|
|
1473
|
+
await sleep();
|
|
1474
|
+
await sandbox.refresh();
|
|
1475
|
+
}
|
|
1476
|
+
return sandbox;
|
|
1477
|
+
}
|
|
1478
|
+
//#endregion
|
|
1479
|
+
//#region src/sandboxes.ts
|
|
1480
|
+
var Sandboxes = class {
|
|
1481
|
+
/** @internal */
|
|
1482
|
+
_client;
|
|
1483
|
+
/** @internal */
|
|
1484
|
+
constructor(client) {
|
|
1485
|
+
this._client = client;
|
|
1486
|
+
}
|
|
1487
|
+
/** List the account's sandboxes, oldest first. */
|
|
1488
|
+
async list(options = {}) {
|
|
1489
|
+
const filesystem = typeof options.disk === "string" ? options.disk : options.disk?.id;
|
|
1490
|
+
return ((await unwrap(this._client.GET("/api/sandboxes", { params: { query: { filesystem } } })))?.sandboxes ?? []).map((sandbox) => new Sandbox(sandbox, this._client));
|
|
1491
|
+
}
|
|
1492
|
+
async get(id) {
|
|
1493
|
+
return new Sandbox(await unwrap(this._client.GET("/api/sandboxes/{sid}", { params: { path: { sid: id } } })), this._client);
|
|
1494
|
+
}
|
|
1495
|
+
async create(request = {}, options = {}) {
|
|
1496
|
+
const body = {
|
|
1497
|
+
name: request.name,
|
|
1498
|
+
vcpu_count: request.vcpuCount,
|
|
1499
|
+
mem_size_mib: request.memSizeMiB,
|
|
1500
|
+
base_image: request.baseImage,
|
|
1501
|
+
env: request.env,
|
|
1502
|
+
max_ttl_seconds: request.maxTtlSeconds,
|
|
1503
|
+
max_concurrent_execs: request.maxConcurrentExecs
|
|
1504
|
+
};
|
|
1505
|
+
const sandbox = new Sandbox(await unwrap(this._client.POST("/api/sandboxes", {
|
|
1506
|
+
params: { query: { wait: options.wait ?? true } },
|
|
1507
|
+
body
|
|
1508
|
+
})), this._client);
|
|
1509
|
+
return options.wait === false ? sandbox : waitForSandboxStart(sandbox);
|
|
1510
|
+
}
|
|
1511
|
+
};
|
|
1512
|
+
//#endregion
|
|
1161
1513
|
//#region src/tokens.ts
|
|
1162
1514
|
var Tokens = class {
|
|
1163
1515
|
/** @internal */
|
|
@@ -1439,6 +1791,7 @@ function diskIdFromMount(m) {
|
|
|
1439
1791
|
}
|
|
1440
1792
|
var Archil = class {
|
|
1441
1793
|
disks;
|
|
1794
|
+
sandboxes;
|
|
1442
1795
|
tokens;
|
|
1443
1796
|
/** @internal */
|
|
1444
1797
|
_client;
|
|
@@ -1456,6 +1809,7 @@ var Archil = class {
|
|
|
1456
1809
|
const s3BaseUrl = opts.s3BaseUrl ?? envVar("ARCHIL_S3_BASE_URL") ?? deriveS3BaseUrl(controlBaseUrl);
|
|
1457
1810
|
this._client = client;
|
|
1458
1811
|
this.disks = new Disks(client, region, s3BaseUrl);
|
|
1812
|
+
this.sandboxes = new Sandboxes(client);
|
|
1459
1813
|
this.tokens = new Tokens(client);
|
|
1460
1814
|
}
|
|
1461
1815
|
/**
|
|
@@ -1513,6 +1867,15 @@ function listDisks(opts) {
|
|
|
1513
1867
|
function getDisk(id) {
|
|
1514
1868
|
return archil().disks.get(id);
|
|
1515
1869
|
}
|
|
1870
|
+
function createSandbox(req = {}, opts = {}) {
|
|
1871
|
+
return archil().sandboxes.create(req, opts);
|
|
1872
|
+
}
|
|
1873
|
+
function listSandboxes(opts) {
|
|
1874
|
+
return archil().sandboxes.list(opts);
|
|
1875
|
+
}
|
|
1876
|
+
function getSandbox(id) {
|
|
1877
|
+
return archil().sandboxes.get(id);
|
|
1878
|
+
}
|
|
1516
1879
|
function listApiKeys(opts) {
|
|
1517
1880
|
return archil().tokens.list(opts);
|
|
1518
1881
|
}
|
|
@@ -1545,6 +1908,10 @@ exports.ArchilS3Error = ArchilS3Error;
|
|
|
1545
1908
|
exports.Disk = Disk;
|
|
1546
1909
|
exports.DiskMultipart = DiskMultipart;
|
|
1547
1910
|
exports.Disks = Disks;
|
|
1911
|
+
exports.Sandbox = Sandbox;
|
|
1912
|
+
exports.SandboxExec = SandboxExec;
|
|
1913
|
+
exports.SandboxPty = SandboxPty;
|
|
1914
|
+
exports.Sandboxes = Sandboxes;
|
|
1548
1915
|
exports.Tokens = Tokens;
|
|
1549
1916
|
exports.USER_AGENT = USER_AGENT;
|
|
1550
1917
|
exports.VERSION = VERSION;
|
|
@@ -1552,10 +1919,13 @@ exports.Workspace = Workspace;
|
|
|
1552
1919
|
exports.configure = configure;
|
|
1553
1920
|
exports.createApiKey = createApiKey;
|
|
1554
1921
|
exports.createDisk = createDisk;
|
|
1922
|
+
exports.createSandbox = createSandbox;
|
|
1555
1923
|
exports.deleteApiKey = deleteApiKey;
|
|
1556
1924
|
exports.effectiveUploadPartSize = effectiveUploadPartSize;
|
|
1557
1925
|
exports.exec = exec;
|
|
1558
1926
|
exports.getDisk = getDisk;
|
|
1927
|
+
exports.getSandbox = getSandbox;
|
|
1559
1928
|
exports.listApiKeys = listApiKeys;
|
|
1560
1929
|
exports.listDisks = listDisks;
|
|
1930
|
+
exports.listSandboxes = listSandboxes;
|
|
1561
1931
|
exports.workspace = workspace;
|