disk 0.8.23 → 0.10.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 +94 -6
- package/dist/cli.mjs +3 -2
- package/dist/{disk-DEqV3mtA.d.cts → disk-DqGdJGsu.d.cts} +18 -6
- package/dist/{disk-DEqV3mtA.d.mts → disk-DqGdJGsu.d.mts} +18 -6
- package/dist/index.cjs +157 -110
- package/dist/index.d.cts +104 -60
- package/dist/index.d.mts +104 -60
- 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-DgL0HTS-.mjs → src-DyVzhbAB.mjs} +157 -109
- package/package.json +2 -2
|
@@ -111,7 +111,7 @@ function deriveS3BaseUrl(controlBaseUrl) {
|
|
|
111
111
|
}
|
|
112
112
|
//#endregion
|
|
113
113
|
//#region src/version.ts
|
|
114
|
-
const VERSION = "0.
|
|
114
|
+
const VERSION = "0.10.0";
|
|
115
115
|
const USER_AGENT = `archil-js/${VERSION}`;
|
|
116
116
|
//#endregion
|
|
117
117
|
//#region src/client.ts
|
|
@@ -151,6 +151,7 @@ async function unwrapPage(promise) {
|
|
|
151
151
|
*/
|
|
152
152
|
async function unwrapEmpty(promise) {
|
|
153
153
|
const { data: body, error, response } = await promise;
|
|
154
|
+
if (!error && response.status === 204) return;
|
|
154
155
|
if (error || !body) throw new ArchilApiError(error?.error ?? `API request failed with status ${response.status}`, response.status);
|
|
155
156
|
if (!body.success) throw new ArchilApiError(body.error ?? "Unknown API error", response.status);
|
|
156
157
|
}
|
|
@@ -166,6 +167,9 @@ var Disk = class {
|
|
|
166
167
|
createdAt;
|
|
167
168
|
fsHandlerStatus;
|
|
168
169
|
lastAccessed;
|
|
170
|
+
activeDataBytes;
|
|
171
|
+
totalDataBytes;
|
|
172
|
+
/** @deprecated Use {@link activeDataBytes}. */
|
|
169
173
|
dataSize;
|
|
170
174
|
monthlyUsage;
|
|
171
175
|
mounts;
|
|
@@ -173,6 +177,8 @@ var Disk = class {
|
|
|
173
177
|
connectedClients;
|
|
174
178
|
authorizedUsers;
|
|
175
179
|
allowedIps;
|
|
180
|
+
/** Root-directory POSIX attributes recorded at creation, if any. */
|
|
181
|
+
rootAttrs;
|
|
176
182
|
/** @internal */
|
|
177
183
|
_client;
|
|
178
184
|
/** @internal */
|
|
@@ -192,13 +198,16 @@ var Disk = class {
|
|
|
192
198
|
this.createdAt = data.createdAt;
|
|
193
199
|
this.fsHandlerStatus = data.fsHandlerStatus;
|
|
194
200
|
this.lastAccessed = data.lastAccessed;
|
|
195
|
-
this.
|
|
201
|
+
this.activeDataBytes = data.activeDataBytes;
|
|
202
|
+
this.totalDataBytes = data.totalDataBytes;
|
|
203
|
+
this.dataSize = data.activeDataBytes;
|
|
196
204
|
this.monthlyUsage = data.monthlyUsage;
|
|
197
205
|
this.mounts = data.mounts;
|
|
198
206
|
this.metrics = data.metrics;
|
|
199
207
|
this.connectedClients = data.connectedClients;
|
|
200
208
|
this.authorizedUsers = data.authorizedUsers;
|
|
201
209
|
this.allowedIps = data.allowedIps;
|
|
210
|
+
this.rootAttrs = data.rootAttrs;
|
|
202
211
|
this._client = client;
|
|
203
212
|
this._archilRegion = archilRegion;
|
|
204
213
|
this._s3BaseUrl = s3BaseUrl ?? "";
|
|
@@ -214,13 +223,15 @@ var Disk = class {
|
|
|
214
223
|
createdAt: this.createdAt,
|
|
215
224
|
fsHandlerStatus: this.fsHandlerStatus,
|
|
216
225
|
lastAccessed: this.lastAccessed,
|
|
217
|
-
|
|
226
|
+
activeDataBytes: this.activeDataBytes,
|
|
227
|
+
totalDataBytes: this.totalDataBytes,
|
|
218
228
|
monthlyUsage: this.monthlyUsage,
|
|
219
229
|
mounts: this.mounts,
|
|
220
230
|
metrics: this.metrics,
|
|
221
231
|
connectedClients: this.connectedClients,
|
|
222
232
|
authorizedUsers: this.authorizedUsers,
|
|
223
|
-
allowedIps: this.allowedIps
|
|
233
|
+
allowedIps: this.allowedIps,
|
|
234
|
+
rootAttrs: this.rootAttrs
|
|
224
235
|
};
|
|
225
236
|
}
|
|
226
237
|
async addUser(user) {
|
|
@@ -408,7 +419,10 @@ var Disk = class {
|
|
|
408
419
|
*
|
|
409
420
|
* Optional `mode` / `uid` / `gid` set the POSIX attributes of the published
|
|
410
421
|
* file (e.g. `{ mode: 0o644, uid: 1000, gid: 1000 }` for a non-root agent
|
|
411
|
-
* sandbox).
|
|
422
|
+
* sandbox). Missing parent directories inherit `uid` / `gid` with mode
|
|
423
|
+
* `0755`; existing directories remain unchanged. A key ending in `/` creates
|
|
424
|
+
* an explicit directory marker whose leaf uses the requested attributes.
|
|
425
|
+
* Defaults are `root:root 0644` for files and `root:root 0755` for directories.
|
|
412
426
|
*
|
|
413
427
|
* @param key Path on the disk (e.g. "reports/2026-01/data.json")
|
|
414
428
|
* @param body Contents as a string, Uint8Array/Buffer, or ArrayBuffer
|
|
@@ -480,7 +494,8 @@ var Disk = class {
|
|
|
480
494
|
*
|
|
481
495
|
* When the object does not yet exist, optional `mode` / `uid` / `gid` set the
|
|
482
496
|
* POSIX attributes of the newly created file (same headers as
|
|
483
|
-
* {@link putObject});
|
|
497
|
+
* {@link putObject}); missing parents inherit `uid` / `gid` with mode `0755`.
|
|
498
|
+
* Existing files and directories are unchanged.
|
|
484
499
|
*
|
|
485
500
|
* @param key Path on the disk (e.g. "logs/app.log")
|
|
486
501
|
* @param body Bytes to append (string, Uint8Array/Buffer, or ArrayBuffer)
|
|
@@ -676,7 +691,7 @@ var Disk = class {
|
|
|
676
691
|
({error, response} = await call(path, init));
|
|
677
692
|
} catch (transportError) {
|
|
678
693
|
if (attempt < maxRetries) {
|
|
679
|
-
await sleep(s3RetryDelayMs(attempt));
|
|
694
|
+
await sleep$1(s3RetryDelayMs(attempt));
|
|
680
695
|
continue;
|
|
681
696
|
}
|
|
682
697
|
throw transportError;
|
|
@@ -684,7 +699,7 @@ var Disk = class {
|
|
|
684
699
|
if (!response.ok) {
|
|
685
700
|
if (isTransientS3Status(response.status) && attempt < maxRetries) {
|
|
686
701
|
await response.body?.cancel().catch(() => {});
|
|
687
|
-
await sleep(s3RetryDelayMs(attempt));
|
|
702
|
+
await sleep$1(s3RetryDelayMs(attempt));
|
|
688
703
|
continue;
|
|
689
704
|
}
|
|
690
705
|
const message = typeof error === "string" ? error : error ? JSON.stringify(error) : "";
|
|
@@ -919,7 +934,7 @@ function s3RetryDelayMs(attempt) {
|
|
|
919
934
|
const ceiling = Math.min(S3_RETRY_CAP_MS, S3_RETRY_BASE_MS * 2 ** attempt);
|
|
920
935
|
return Math.random() * ceiling;
|
|
921
936
|
}
|
|
922
|
-
function sleep(ms) {
|
|
937
|
+
function sleep$1(ms) {
|
|
923
938
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
924
939
|
}
|
|
925
940
|
/** S3's minimum size for every multipart part but the last (5 MiB). */
|
|
@@ -1120,6 +1135,11 @@ var Disks = class {
|
|
|
1120
1135
|
*
|
|
1121
1136
|
* Returns the Disk, the one-time token (save it — it cannot be retrieved
|
|
1122
1137
|
* again), and the token identifier for later management.
|
|
1138
|
+
*
|
|
1139
|
+
* `rootAttrs` sets the POSIX owner and mode of the disk's root directory
|
|
1140
|
+
* (e.g. `{ uid: 1000, gid: 1000, mode: 0o755 }` so an unprivileged process
|
|
1141
|
+
* can create entries under the mount root without a post-mount `chown`).
|
|
1142
|
+
* Creation-time only.
|
|
1123
1143
|
*/
|
|
1124
1144
|
async create(req) {
|
|
1125
1145
|
const resp = await unwrap(this._client.POST("/api/disks", { body: req }));
|
|
@@ -1134,39 +1154,12 @@ var Disks = class {
|
|
|
1134
1154
|
};
|
|
1135
1155
|
}
|
|
1136
1156
|
};
|
|
1157
|
+
//#endregion
|
|
1158
|
+
//#region src/sandbox.ts
|
|
1137
1159
|
const POLL_INTERVAL_MS = 500;
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
if (!Number.isFinite(timeoutMs) || timeoutMs < 0) throw new RangeError("timeoutMs must be a finite, non-negative number");
|
|
1160
|
+
function sleep() {
|
|
1161
|
+
return new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL_MS));
|
|
1141
1162
|
}
|
|
1142
|
-
/**
|
|
1143
|
-
* The requested SDK-side wait expired. The remote sandbox operation continues;
|
|
1144
|
-
* `latest` is the same `Sandbox`/`SandboxExec` the operation was called on,
|
|
1145
|
-
* updated in place to the last state observed before the deadline.
|
|
1146
|
-
*/
|
|
1147
|
-
var SandboxWaitTimeoutError = class extends ArchilError {
|
|
1148
|
-
operation;
|
|
1149
|
-
timeoutMs;
|
|
1150
|
-
latest;
|
|
1151
|
-
constructor(operation, timeoutMs, latest) {
|
|
1152
|
-
const subject = operation === "exec" ? "sandbox exec to complete" : `sandbox to ${operation}`;
|
|
1153
|
-
super(`Timed out after ${timeoutMs}ms waiting for ${subject}`, 408, "SANDBOX_WAIT_TIMEOUT");
|
|
1154
|
-
this.name = "SandboxWaitTimeoutError";
|
|
1155
|
-
this.operation = operation;
|
|
1156
|
-
this.timeoutMs = timeoutMs;
|
|
1157
|
-
this.latest = latest;
|
|
1158
|
-
}
|
|
1159
|
-
};
|
|
1160
|
-
/** The sandbox entered an inactive state before startup completed. */
|
|
1161
|
-
var SandboxStartError = class extends ArchilError {
|
|
1162
|
-
latest;
|
|
1163
|
-
constructor(sandbox) {
|
|
1164
|
-
const detail = sandbox.exitReason ? `: ${sandbox.exitReason}` : "";
|
|
1165
|
-
super(`Sandbox entered ${sandbox.status} before it started${detail}`, 409, "SANDBOX_START_FAILED");
|
|
1166
|
-
this.name = "SandboxStartError";
|
|
1167
|
-
this.latest = sandbox;
|
|
1168
|
-
}
|
|
1169
|
-
};
|
|
1170
1163
|
var SandboxExec = class {
|
|
1171
1164
|
sandboxId;
|
|
1172
1165
|
id;
|
|
@@ -1233,11 +1226,75 @@ var SandboxExec = class {
|
|
|
1233
1226
|
return this._apply(data);
|
|
1234
1227
|
}
|
|
1235
1228
|
};
|
|
1236
|
-
var
|
|
1229
|
+
var SandboxPty = class SandboxPty {
|
|
1230
|
+
_socket;
|
|
1231
|
+
_completion;
|
|
1232
|
+
/** @internal */
|
|
1233
|
+
constructor(socket, onData) {
|
|
1234
|
+
this._socket = socket;
|
|
1235
|
+
this._completion = new Promise((resolve) => {
|
|
1236
|
+
socket.addEventListener("message", (event) => {
|
|
1237
|
+
if (typeof event.data === "string") onData?.(event.data);
|
|
1238
|
+
});
|
|
1239
|
+
socket.addEventListener("close", (event) => {
|
|
1240
|
+
const match = /^process exited with code (-?\d+)$/.exec(event.reason);
|
|
1241
|
+
resolve({ exitCode: match ? Number(match[1]) : void 0 });
|
|
1242
|
+
}, { once: true });
|
|
1243
|
+
});
|
|
1244
|
+
}
|
|
1245
|
+
/** @internal */
|
|
1246
|
+
static connect(url, command, options) {
|
|
1247
|
+
return new Promise((resolve, reject) => {
|
|
1248
|
+
const socket = new WebSocket(url);
|
|
1249
|
+
const handleError = () => reject(/* @__PURE__ */ new Error("Interactive exec connection failed"));
|
|
1250
|
+
socket.addEventListener("error", handleError, { once: true });
|
|
1251
|
+
socket.addEventListener("open", () => {
|
|
1252
|
+
socket.removeEventListener("error", handleError);
|
|
1253
|
+
const pty = new SandboxPty(socket, options.onData);
|
|
1254
|
+
pty._send({
|
|
1255
|
+
type: "resize",
|
|
1256
|
+
cols: options.cols ?? 80,
|
|
1257
|
+
rows: options.rows ?? 24
|
|
1258
|
+
});
|
|
1259
|
+
const quotedCommand = `'${command.replaceAll("'", `'"'"'`)}'`;
|
|
1260
|
+
pty._send({
|
|
1261
|
+
type: "input",
|
|
1262
|
+
data: `eval ${quotedCommand}; exit $?\n`
|
|
1263
|
+
});
|
|
1264
|
+
resolve(pty);
|
|
1265
|
+
}, { once: true });
|
|
1266
|
+
});
|
|
1267
|
+
}
|
|
1268
|
+
async sendInput(data) {
|
|
1269
|
+
this._send({
|
|
1270
|
+
type: "input",
|
|
1271
|
+
data
|
|
1272
|
+
});
|
|
1273
|
+
}
|
|
1274
|
+
async resize(size) {
|
|
1275
|
+
this._send({
|
|
1276
|
+
type: "resize",
|
|
1277
|
+
...size
|
|
1278
|
+
});
|
|
1279
|
+
}
|
|
1280
|
+
wait() {
|
|
1281
|
+
return this._completion;
|
|
1282
|
+
}
|
|
1283
|
+
close() {
|
|
1284
|
+
this._socket.close();
|
|
1285
|
+
}
|
|
1286
|
+
_send(message) {
|
|
1287
|
+
this._socket.send(JSON.stringify(message));
|
|
1288
|
+
}
|
|
1289
|
+
};
|
|
1290
|
+
var Sandbox = class Sandbox {
|
|
1237
1291
|
id;
|
|
1292
|
+
name;
|
|
1238
1293
|
status;
|
|
1239
1294
|
vcpuCount;
|
|
1240
1295
|
memSizeMiB;
|
|
1296
|
+
baseImage;
|
|
1297
|
+
platform;
|
|
1241
1298
|
maxTtlSeconds;
|
|
1242
1299
|
maxConcurrentExecs;
|
|
1243
1300
|
endpoints;
|
|
@@ -1257,9 +1314,12 @@ var Sandbox = class {
|
|
|
1257
1314
|
/** @internal Overwrite this sandbox's fields in place from a fresh wire snapshot. */
|
|
1258
1315
|
_apply(data) {
|
|
1259
1316
|
this.id = data.sandbox_id;
|
|
1317
|
+
this.name = data.name;
|
|
1260
1318
|
this.status = data.status;
|
|
1261
1319
|
this.vcpuCount = data.vcpu_count;
|
|
1262
1320
|
this.memSizeMiB = data.mem_size_mib;
|
|
1321
|
+
this.baseImage = data.base_image;
|
|
1322
|
+
this.platform = data.platform;
|
|
1263
1323
|
this.maxTtlSeconds = data.max_ttl_seconds;
|
|
1264
1324
|
this.maxConcurrentExecs = data.max_concurrent_execs;
|
|
1265
1325
|
this.endpoints = data.endpoints?.map((endpoint) => ({ ...endpoint }));
|
|
@@ -1274,9 +1334,12 @@ var Sandbox = class {
|
|
|
1274
1334
|
toJSON() {
|
|
1275
1335
|
return {
|
|
1276
1336
|
id: this.id,
|
|
1337
|
+
name: this.name,
|
|
1277
1338
|
status: this.status,
|
|
1278
1339
|
vcpuCount: this.vcpuCount,
|
|
1279
1340
|
memSizeMiB: this.memSizeMiB,
|
|
1341
|
+
baseImage: this.baseImage,
|
|
1342
|
+
platform: this.platform,
|
|
1280
1343
|
maxTtlSeconds: this.maxTtlSeconds,
|
|
1281
1344
|
maxConcurrentExecs: this.maxConcurrentExecs,
|
|
1282
1345
|
endpoints: this.endpoints?.map((endpoint) => ({ ...endpoint })),
|
|
@@ -1295,79 +1358,67 @@ var Sandbox = class {
|
|
|
1295
1358
|
}
|
|
1296
1359
|
/** Start this sandbox. */
|
|
1297
1360
|
async start(options = {}) {
|
|
1298
|
-
const timeoutMs = options.timeoutMs ?? 3e4;
|
|
1299
|
-
validateTimeoutMs(timeoutMs);
|
|
1300
|
-
const deadline = Date.now() + timeoutMs;
|
|
1301
1361
|
const data = await unwrap(this._client.POST("/api/sandboxes/{sid}/start", { params: {
|
|
1302
1362
|
path: { sid: this.id },
|
|
1303
|
-
query: { wait:
|
|
1363
|
+
query: { wait: options.wait ?? true }
|
|
1304
1364
|
} }));
|
|
1305
1365
|
this._apply(data);
|
|
1306
|
-
return waitForSandboxStart(this
|
|
1366
|
+
return options.wait === false ? this : waitForSandboxStart(this);
|
|
1307
1367
|
}
|
|
1308
1368
|
/** Stop this sandbox. */
|
|
1309
1369
|
async stop(options = {}) {
|
|
1310
|
-
const timeoutMs = options.timeoutMs ?? 3e4;
|
|
1311
|
-
validateTimeoutMs(timeoutMs);
|
|
1312
|
-
const deadline = Date.now() + timeoutMs;
|
|
1313
1370
|
const data = await unwrap(this._client.POST("/api/sandboxes/{sid}/stop", { params: { path: { sid: this.id } } }));
|
|
1314
1371
|
this._apply(data);
|
|
1315
|
-
|
|
1316
|
-
if ([
|
|
1317
|
-
"stopped",
|
|
1318
|
-
"exited",
|
|
1319
|
-
"failed"
|
|
1320
|
-
].includes(this.status)) return this;
|
|
1321
|
-
if (this.status !== "stopping") throw new ArchilError(`Sandbox entered ${this.status} before it stopped`, 409, "SANDBOX_STOP_FAILED");
|
|
1322
|
-
const remaining = deadline - Date.now();
|
|
1323
|
-
if (remaining <= 0) throw new SandboxWaitTimeoutError("stop", timeoutMs, this);
|
|
1324
|
-
await new Promise((resolve) => setTimeout(resolve, Math.min(POLL_INTERVAL_MS, remaining)));
|
|
1325
|
-
await this.refresh();
|
|
1326
|
-
}
|
|
1372
|
+
return options.wait === false ? this : waitWhileSandboxStatus(this, "stopping");
|
|
1327
1373
|
}
|
|
1328
1374
|
/** Pause this sandbox, preserving its CPU and memory state. */
|
|
1329
1375
|
async pause(options = {}) {
|
|
1330
|
-
const timeoutMs = options.timeoutMs ?? 3e4;
|
|
1331
|
-
validateTimeoutMs(timeoutMs);
|
|
1332
|
-
const deadline = Date.now() + timeoutMs;
|
|
1333
1376
|
const data = await unwrap(this._client.POST("/api/sandboxes/{sid}/pause", { params: { path: { sid: this.id } } }));
|
|
1334
1377
|
this._apply(data);
|
|
1335
|
-
|
|
1336
|
-
if (this.status === "paused") return this;
|
|
1337
|
-
if (this.status !== "pausing") throw new ArchilError(`Sandbox entered ${this.status} before it paused`, 409, "SANDBOX_PAUSE_FAILED");
|
|
1338
|
-
const remaining = deadline - Date.now();
|
|
1339
|
-
if (remaining <= 0) throw new SandboxWaitTimeoutError("pause", timeoutMs, this);
|
|
1340
|
-
await new Promise((resolve) => setTimeout(resolve, Math.min(POLL_INTERVAL_MS, remaining)));
|
|
1341
|
-
await this.refresh();
|
|
1342
|
-
}
|
|
1378
|
+
return options.wait === false ? this : waitWhileSandboxStatus(this, "pausing");
|
|
1343
1379
|
}
|
|
1344
1380
|
/** Resume this sandbox from its preserved CPU and memory state. */
|
|
1345
1381
|
async resume(options = {}) {
|
|
1346
|
-
const timeoutMs = options.timeoutMs ?? 3e4;
|
|
1347
|
-
validateTimeoutMs(timeoutMs);
|
|
1348
|
-
const deadline = Date.now() + timeoutMs;
|
|
1349
1382
|
const data = await unwrap(this._client.POST("/api/sandboxes/{sid}/resume", { params: {
|
|
1350
1383
|
path: { sid: this.id },
|
|
1351
|
-
query: { wait:
|
|
1384
|
+
query: { wait: options.wait ?? true }
|
|
1352
1385
|
} }));
|
|
1353
1386
|
this._apply(data);
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1387
|
+
return options.wait === false ? this : waitForSandboxStart(this);
|
|
1388
|
+
}
|
|
1389
|
+
/** Create an isolated writable branch from this sandbox's current state. */
|
|
1390
|
+
async fork(options = {}) {
|
|
1391
|
+
const data = await unwrap(this._client.POST("/api/sandboxes/{sid}/fork", {
|
|
1392
|
+
params: {
|
|
1393
|
+
path: { sid: this.id },
|
|
1394
|
+
query: { wait: options.wait ?? true }
|
|
1395
|
+
},
|
|
1396
|
+
body: options.name === void 0 ? void 0 : { name: options.name }
|
|
1397
|
+
}));
|
|
1398
|
+
const fork = new Sandbox(data, this._client);
|
|
1399
|
+
return options.wait === false ? fork : waitForSandboxStart(fork);
|
|
1400
|
+
}
|
|
1401
|
+
/** Create a short-lived signed WebSocket URL for an interactive shell. */
|
|
1402
|
+
async createConnection() {
|
|
1403
|
+
const data = await unwrap(this._client.POST("/api/sandboxes/{sid}/connections", { params: { path: { sid: this.id } } }));
|
|
1404
|
+
return {
|
|
1405
|
+
url: data.url,
|
|
1406
|
+
expiresAt: new Date(data.expires_at)
|
|
1407
|
+
};
|
|
1408
|
+
}
|
|
1409
|
+
/** Delete this sandbox and its backing disk. */
|
|
1410
|
+
async delete() {
|
|
1411
|
+
await unwrapEmpty(this._client.DELETE("/api/sandboxes/{sid}", { params: { path: { sid: this.id } } }));
|
|
1362
1412
|
}
|
|
1363
1413
|
async exec(command, options = {}) {
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1414
|
+
if ("pty" in options) {
|
|
1415
|
+
const connection = await this.createConnection();
|
|
1416
|
+
return SandboxPty.connect(connection.url, command, options);
|
|
1417
|
+
}
|
|
1367
1418
|
const exec = new SandboxExec(await unwrap(this._client.POST("/api/sandboxes/{sid}/execs", {
|
|
1368
1419
|
params: {
|
|
1369
1420
|
path: { sid: this.id },
|
|
1370
|
-
query: { wait:
|
|
1421
|
+
query: { wait: options.wait ?? true }
|
|
1371
1422
|
},
|
|
1372
1423
|
body: {
|
|
1373
1424
|
command,
|
|
@@ -1376,14 +1427,12 @@ var Sandbox = class {
|
|
|
1376
1427
|
timeout_seconds: options.timeoutSeconds
|
|
1377
1428
|
}
|
|
1378
1429
|
})), this._client);
|
|
1379
|
-
if (
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
if (remaining <= 0) throw new SandboxWaitTimeoutError("exec", timeoutMs, exec);
|
|
1383
|
-
await new Promise((resolve) => setTimeout(resolve, Math.min(POLL_INTERVAL_MS, remaining)));
|
|
1430
|
+
if (options.wait === false) return exec;
|
|
1431
|
+
while (exec.status === "running") {
|
|
1432
|
+
await sleep();
|
|
1384
1433
|
await exec.refresh();
|
|
1385
|
-
if (exec.status !== "running") return exec;
|
|
1386
1434
|
}
|
|
1435
|
+
return exec;
|
|
1387
1436
|
}
|
|
1388
1437
|
async listExecs() {
|
|
1389
1438
|
return ((await unwrap(this._client.GET("/api/sandboxes/{sid}/execs", { params: { path: { sid: this.id } } })))?.execs ?? []).map((exec) => new SandboxExec(exec, this._client));
|
|
@@ -1401,16 +1450,16 @@ var Sandbox = class {
|
|
|
1401
1450
|
} } })), this._client);
|
|
1402
1451
|
}
|
|
1403
1452
|
};
|
|
1404
|
-
/** @internal
|
|
1405
|
-
async function waitForSandboxStart(sandbox
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
await new Promise((resolve) => setTimeout(resolve, Math.min(POLL_INTERVAL_MS, remaining)));
|
|
1453
|
+
/** @internal Continue waiting if the server returned before startup completed. */
|
|
1454
|
+
async function waitForSandboxStart(sandbox) {
|
|
1455
|
+
return waitWhileSandboxStatus(sandbox, "pending");
|
|
1456
|
+
}
|
|
1457
|
+
async function waitWhileSandboxStatus(sandbox, status) {
|
|
1458
|
+
while (sandbox.status === status) {
|
|
1459
|
+
await sleep();
|
|
1412
1460
|
await sandbox.refresh();
|
|
1413
1461
|
}
|
|
1462
|
+
return sandbox;
|
|
1414
1463
|
}
|
|
1415
1464
|
//#endregion
|
|
1416
1465
|
//#region src/sandboxes.ts
|
|
@@ -1430,10 +1479,8 @@ var Sandboxes = class {
|
|
|
1430
1479
|
return new Sandbox(await unwrap(this._client.GET("/api/sandboxes/{sid}", { params: { path: { sid: id } } })), this._client);
|
|
1431
1480
|
}
|
|
1432
1481
|
async create(request = {}, options = {}) {
|
|
1433
|
-
const timeoutMs = options.timeoutMs ?? 3e4;
|
|
1434
|
-
validateTimeoutMs(timeoutMs);
|
|
1435
|
-
const deadline = Date.now() + timeoutMs;
|
|
1436
1482
|
const body = {
|
|
1483
|
+
name: request.name,
|
|
1437
1484
|
vcpu_count: request.vcpuCount,
|
|
1438
1485
|
mem_size_mib: request.memSizeMiB,
|
|
1439
1486
|
base_image: request.baseImage,
|
|
@@ -1441,10 +1488,11 @@ var Sandboxes = class {
|
|
|
1441
1488
|
max_ttl_seconds: request.maxTtlSeconds,
|
|
1442
1489
|
max_concurrent_execs: request.maxConcurrentExecs
|
|
1443
1490
|
};
|
|
1444
|
-
|
|
1445
|
-
params: { query: { wait:
|
|
1491
|
+
const sandbox = new Sandbox(await unwrap(this._client.POST("/api/sandboxes", {
|
|
1492
|
+
params: { query: { wait: options.wait ?? true } },
|
|
1446
1493
|
body
|
|
1447
|
-
})), this._client)
|
|
1494
|
+
})), this._client);
|
|
1495
|
+
return options.wait === false ? sandbox : waitForSandboxStart(sandbox);
|
|
1448
1496
|
}
|
|
1449
1497
|
};
|
|
1450
1498
|
//#endregion
|
|
@@ -1839,4 +1887,4 @@ function workspace(mounts) {
|
|
|
1839
1887
|
return archil().workspace(mounts);
|
|
1840
1888
|
}
|
|
1841
1889
|
//#endregion
|
|
1842
|
-
export {
|
|
1890
|
+
export { effectiveUploadPartSize as C, ArchilError as D, ArchilApiError as E, ArchilS3Error as O, DiskMultipart as S, VERSION as T, Sandbox as _, deleteApiKey as a, Disks as b, getSandbox as c, listSandboxes as d, workspace as f, Sandboxes as g, Tokens as h, createSandbox as i, 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, SandboxExec as v, USER_AGENT as w, Disk as x, SandboxPty as y };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "disk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Pure-JS client and CLI for Archil disks",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"archil",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"LICENSE"
|
|
39
39
|
],
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@archildata/api-types": "^0.0.
|
|
41
|
+
"@archildata/api-types": "^0.0.18",
|
|
42
42
|
"commander": "^14.0.3",
|
|
43
43
|
"fast-xml-parser": "^5.7.0",
|
|
44
44
|
"openapi-fetch": "^0.13.5",
|