disk 1.11.0 → 1.12.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 +8 -0
- package/dist/{disk-BmBSYT8h.d.cts → archil-CLQrudfP.d.cts} +789 -5
- package/dist/{disk-BmBSYT8h.d.mts → archil-CLQrudfP.d.mts} +789 -5
- package/dist/cli.mjs +2 -3
- package/dist/index.cjs +240 -73
- package/dist/index.d.cts +2 -695
- package/dist/index.d.mts +2 -695
- package/dist/index.mjs +1 -1
- package/dist/internal/tools.d.cts +1 -1
- package/dist/internal/tools.d.mts +1 -1
- package/dist/sandbox-cli.mjs +5 -10
- package/dist/{sandbox-options-VBQ-AsOP.mjs → sandbox-options-Cz_oVr-y.mjs} +375 -21
- package/dist/{src-BbjR-spO.mjs → src-V9HdQW-c.mjs} +240 -51
- package/package.json +12 -9
|
@@ -1,17 +1,164 @@
|
|
|
1
1
|
import { t as toSegments } from "./paths-Br9snUhy.mjs";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
//#region src/api-fetch.ts
|
|
3
|
+
function buildPath(template, params = {}) {
|
|
4
|
+
return template.replace(/\{([^}]+)\}/g, (_, name) => {
|
|
5
|
+
const value = params[name];
|
|
6
|
+
if (value === void 0) throw new Error(`Missing path parameter '${name}' for ${template}`);
|
|
7
|
+
return encodeURIComponent(String(value));
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
/** Serialize a query object; undefined/null values are omitted and arrays repeat the key. */
|
|
11
|
+
function buildQuery(query = {}) {
|
|
12
|
+
const parts = [];
|
|
13
|
+
for (const [name, value] of Object.entries(query)) for (const item of Array.isArray(value) ? value : [value]) {
|
|
14
|
+
if (item === void 0 || item === null) continue;
|
|
15
|
+
parts.push(`${encodeURIComponent(name)}=${encodeURIComponent(String(item))}`);
|
|
16
|
+
}
|
|
17
|
+
return parts.length > 0 ? `?${parts.join("&")}` : "";
|
|
18
|
+
}
|
|
19
|
+
function createClient(config) {
|
|
20
|
+
const baseUrl = config.baseUrl.replace(/\/+$/, "");
|
|
21
|
+
const send = (request) => (config.fetch ?? globalThis.fetch)(request);
|
|
22
|
+
const headersFor = (extra = {}) => {
|
|
23
|
+
const headers = new Headers(config.headers);
|
|
24
|
+
for (const [name, value] of Object.entries(extra)) if (value !== void 0) headers.set(name, value);
|
|
25
|
+
return headers;
|
|
26
|
+
};
|
|
27
|
+
const call = async (method, path, init = {}) => {
|
|
28
|
+
const url = baseUrl + buildPath(path, init.params?.path) + buildQuery(init.params?.query);
|
|
29
|
+
const headers = headersFor(init.params?.header);
|
|
30
|
+
let body;
|
|
31
|
+
if (init.body !== void 0) {
|
|
32
|
+
body = JSON.stringify(init.body);
|
|
33
|
+
if (!headers.has("Content-Type")) headers.set("Content-Type", "application/json");
|
|
34
|
+
}
|
|
35
|
+
const response = await send(new Request(url, {
|
|
36
|
+
method,
|
|
37
|
+
headers,
|
|
38
|
+
body
|
|
39
|
+
}));
|
|
40
|
+
if (response.status === 204 || response.headers.get("Content-Length") === "0") {
|
|
41
|
+
await response.body?.cancel().catch(() => {});
|
|
42
|
+
return response.ok ? {
|
|
43
|
+
data: void 0,
|
|
44
|
+
response
|
|
45
|
+
} : {
|
|
46
|
+
error: void 0,
|
|
47
|
+
response
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
if (response.ok) return {
|
|
51
|
+
data: await response.json(),
|
|
52
|
+
response
|
|
53
|
+
};
|
|
54
|
+
const text = await response.text();
|
|
55
|
+
let error = text;
|
|
56
|
+
try {
|
|
57
|
+
error = JSON.parse(text);
|
|
58
|
+
} catch {}
|
|
59
|
+
return {
|
|
60
|
+
error,
|
|
61
|
+
response
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
const method = (name) => ((path, init) => call(name, path, init));
|
|
65
|
+
return {
|
|
66
|
+
GET: method("GET"),
|
|
67
|
+
PUT: method("PUT"),
|
|
68
|
+
POST: method("POST"),
|
|
69
|
+
DELETE: method("DELETE"),
|
|
70
|
+
PATCH: method("PATCH"),
|
|
71
|
+
raw: (methodName, url, init = {}) => send(new Request(url, {
|
|
72
|
+
method: methodName,
|
|
73
|
+
headers: headersFor(init.headers),
|
|
74
|
+
body: init.body
|
|
75
|
+
}))
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
//#endregion
|
|
4
79
|
//#region src/s3xml.ts
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
80
|
+
const ALWAYS_ARRAY = /* @__PURE__ */ new Set(["Contents", "CommonPrefixes"]);
|
|
81
|
+
const NAMED_ENTITIES = {
|
|
82
|
+
amp: "&",
|
|
83
|
+
lt: "<",
|
|
84
|
+
gt: ">",
|
|
85
|
+
quot: "\"",
|
|
86
|
+
apos: "'"
|
|
87
|
+
};
|
|
88
|
+
function decodeEntities(text) {
|
|
89
|
+
if (!text.includes("&")) return text;
|
|
90
|
+
return text.replace(/&(#x[0-9a-fA-F]+|#[0-9]+|[a-zA-Z]+);/g, (match, ref) => {
|
|
91
|
+
if (ref[0] === "#") {
|
|
92
|
+
const code = ref[1] === "x" || ref[1] === "X" ? parseInt(ref.slice(2), 16) : parseInt(ref.slice(1), 10);
|
|
93
|
+
return code > 1114111 ? match : String.fromCodePoint(code);
|
|
94
|
+
}
|
|
95
|
+
return Object.hasOwn(NAMED_ENTITIES, ref) ? NAMED_ENTITIES[ref] : match;
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
function setOwn(target, name, value) {
|
|
99
|
+
Object.defineProperty(target, name, {
|
|
100
|
+
value,
|
|
101
|
+
enumerable: true,
|
|
102
|
+
writable: true,
|
|
103
|
+
configurable: true
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
function addChild(parent, name, value) {
|
|
107
|
+
parent.hasChildren = true;
|
|
108
|
+
const existing = Object.hasOwn(parent.children, name) ? parent.children[name] : void 0;
|
|
109
|
+
if (existing === void 0) setOwn(parent.children, name, ALWAYS_ARRAY.has(name) ? [value] : value);
|
|
110
|
+
else if (Array.isArray(existing)) existing.push(value);
|
|
111
|
+
else setOwn(parent.children, name, [existing, value]);
|
|
112
|
+
}
|
|
113
|
+
/** Index just past `terminator`, searching from `from`; throws if it never appears. */
|
|
114
|
+
function skipPast(xml, terminator, from) {
|
|
115
|
+
const end = xml.indexOf(terminator, from);
|
|
116
|
+
if (end === -1) throw new Error(`Malformed XML: missing '${terminator}'`);
|
|
117
|
+
return end + terminator.length;
|
|
118
|
+
}
|
|
11
119
|
/** Parse an XML document into a plain object. Returns {} for empty/blank input. */
|
|
12
120
|
function parseXml(xml) {
|
|
13
|
-
|
|
14
|
-
|
|
121
|
+
const root = {
|
|
122
|
+
name: "",
|
|
123
|
+
children: {},
|
|
124
|
+
hasChildren: false,
|
|
125
|
+
text: ""
|
|
126
|
+
};
|
|
127
|
+
const stack = [root];
|
|
128
|
+
let position = 0;
|
|
129
|
+
while (position < xml.length) {
|
|
130
|
+
const current = stack[stack.length - 1];
|
|
131
|
+
const open = xml.indexOf("<", position);
|
|
132
|
+
current.text += decodeEntities(xml.slice(position, open === -1 ? xml.length : open));
|
|
133
|
+
if (open === -1) break;
|
|
134
|
+
if (xml.startsWith("<!--", open)) position = skipPast(xml, "-->", open + 4);
|
|
135
|
+
else if (xml.startsWith("<![CDATA[", open)) {
|
|
136
|
+
position = skipPast(xml, "]]>", open + 9);
|
|
137
|
+
current.text += xml.slice(open + 9, position - 3);
|
|
138
|
+
} else if (xml.startsWith("<?", open)) position = skipPast(xml, "?>", open + 2);
|
|
139
|
+
else if (xml.startsWith("<!", open)) throw new Error("Malformed XML: DOCTYPE and other declarations are not supported");
|
|
140
|
+
else {
|
|
141
|
+
position = skipPast(xml, ">", open + 1);
|
|
142
|
+
const tag = xml.slice(open + 1, position - 1);
|
|
143
|
+
const closing = tag.startsWith("/");
|
|
144
|
+
const selfClosing = !closing && tag.endsWith("/");
|
|
145
|
+
const name = /^[^\s/]+/.exec(closing ? tag.slice(1) : tag)?.[0];
|
|
146
|
+
if (!name) throw new Error(`Malformed XML: invalid tag <${tag}>`);
|
|
147
|
+
if (closing) {
|
|
148
|
+
if (current.name !== name || stack.length === 1) throw new Error(`Malformed XML: unexpected </${name}>`);
|
|
149
|
+
stack.pop();
|
|
150
|
+
addChild(stack[stack.length - 1], name, current.hasChildren ? current.children : current.text);
|
|
151
|
+
} else if (selfClosing) addChild(current, name, "");
|
|
152
|
+
else stack.push({
|
|
153
|
+
name,
|
|
154
|
+
children: {},
|
|
155
|
+
hasChildren: false,
|
|
156
|
+
text: ""
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (stack.length !== 1) throw new Error(`Malformed XML: unclosed <${stack[stack.length - 1].name}>`);
|
|
161
|
+
return root.children;
|
|
15
162
|
}
|
|
16
163
|
//#endregion
|
|
17
164
|
//#region src/errors.ts
|
|
@@ -140,11 +287,10 @@ function deriveS3BaseUrl(controlBaseUrl) {
|
|
|
140
287
|
}
|
|
141
288
|
//#endregion
|
|
142
289
|
//#region src/version.ts
|
|
143
|
-
const VERSION = "1.
|
|
290
|
+
const VERSION = "1.12.0";
|
|
144
291
|
const USER_AGENT = `archil-js/${VERSION}`;
|
|
145
292
|
//#endregion
|
|
146
293
|
//#region src/client.ts
|
|
147
|
-
const createClient = typeof createClientDefault === "function" ? createClientDefault : createClientDefault.default;
|
|
148
294
|
function isNodeRuntime() {
|
|
149
295
|
return typeof process !== "undefined" && typeof process.versions?.node === "string";
|
|
150
296
|
}
|
|
@@ -175,10 +321,10 @@ const bufferRequestBodies = (dispatch) => (options, handler) => {
|
|
|
175
321
|
return true;
|
|
176
322
|
};
|
|
177
323
|
const sharedTransports = /* @__PURE__ */ new Map();
|
|
178
|
-
function dispatcherKey(baseUrl,
|
|
324
|
+
function dispatcherKey(baseUrl, authorization, ca) {
|
|
179
325
|
return JSON.stringify([
|
|
180
326
|
new URL(baseUrl).origin,
|
|
181
|
-
|
|
327
|
+
authorization,
|
|
182
328
|
ca?.map((cert) => cert.toString("base64"))
|
|
183
329
|
]);
|
|
184
330
|
}
|
|
@@ -204,13 +350,13 @@ function getSharedTransport(key, ca) {
|
|
|
204
350
|
});
|
|
205
351
|
return transport;
|
|
206
352
|
}
|
|
207
|
-
function createPooledFetch(baseUrl,
|
|
353
|
+
function createPooledFetch(baseUrl, authorization, tls) {
|
|
208
354
|
if (!isNodeRuntime()) {
|
|
209
355
|
if (tls?.ca !== void 0) throw new Error("Custom TLS CAs require Node.js");
|
|
210
356
|
return;
|
|
211
357
|
}
|
|
212
358
|
const ca = tls?.ca === void 0 ? void 0 : (Array.isArray(tls.ca) ? tls.ca : [tls.ca]).map((cert) => Buffer.from(cert));
|
|
213
|
-
const key = dispatcherKey(baseUrl,
|
|
359
|
+
const key = dispatcherKey(baseUrl, authorization, ca);
|
|
214
360
|
return async (request) => {
|
|
215
361
|
const { fetch, dispatcher } = await getSharedTransport(key, ca);
|
|
216
362
|
const body = request.body === null ? null : new Uint8Array(await request.arrayBuffer());
|
|
@@ -224,14 +370,23 @@ function createPooledFetch(baseUrl, apiKey, tls) {
|
|
|
224
370
|
});
|
|
225
371
|
};
|
|
226
372
|
}
|
|
373
|
+
/**
|
|
374
|
+
* The `Authorization` value for an API key: the key exactly as given, as a
|
|
375
|
+
* bearer token. Credential-injecting proxies substitute a placeholder only when
|
|
376
|
+
* it is the whole token, so the SDK must not add a prefix to it. The control
|
|
377
|
+
* plane accepts the key with or without its `key-` prefix after `Bearer`.
|
|
378
|
+
*/
|
|
379
|
+
function apiKeyAuthorization(apiKey) {
|
|
380
|
+
return `Bearer ${apiKey}`;
|
|
381
|
+
}
|
|
227
382
|
function createApiClient(opts) {
|
|
228
383
|
const baseUrl = opts.baseUrl ?? resolveBaseUrl(opts.region);
|
|
229
|
-
const
|
|
384
|
+
const authorization = apiKeyAuthorization(opts.apiKey);
|
|
230
385
|
return createClient({
|
|
231
386
|
baseUrl,
|
|
232
|
-
fetch: createPooledFetch(baseUrl,
|
|
387
|
+
fetch: createPooledFetch(baseUrl, authorization, opts.tls),
|
|
233
388
|
headers: {
|
|
234
|
-
Authorization:
|
|
389
|
+
Authorization: authorization,
|
|
235
390
|
"User-Agent": USER_AGENT
|
|
236
391
|
}
|
|
237
392
|
});
|
|
@@ -271,6 +426,22 @@ async function unwrapEmpty(promise) {
|
|
|
271
426
|
}
|
|
272
427
|
if (!body.success) throw new ArchilApiError(body.error ?? "Unknown API error", response.status, body.code);
|
|
273
428
|
}
|
|
429
|
+
//#endregion
|
|
430
|
+
//#region src/exec-options.ts
|
|
431
|
+
/**
|
|
432
|
+
* @internal Copies only the known option keys into a request body. Every key
|
|
433
|
+
* is required here, so an option added to the API fails to compile until it is
|
|
434
|
+
* copied.
|
|
435
|
+
*/
|
|
436
|
+
function execVmBody(options) {
|
|
437
|
+
return {
|
|
438
|
+
baseImage: options?.baseImage,
|
|
439
|
+
imageId: options?.imageId,
|
|
440
|
+
vcpuCount: options?.vcpuCount,
|
|
441
|
+
memSizeMib: options?.memSizeMib,
|
|
442
|
+
network: options?.network
|
|
443
|
+
};
|
|
444
|
+
}
|
|
274
445
|
const RETRY_BASE_MS = 100;
|
|
275
446
|
const RETRY_CAP_MS = 2e3;
|
|
276
447
|
const TRANSIENT_STATUSES = /* @__PURE__ */ new Set([
|
|
@@ -550,10 +721,13 @@ var Disk = class {
|
|
|
550
721
|
* Execute a command in a container with this disk mounted.
|
|
551
722
|
* Blocks until the command completes and returns stdout, stderr, and exit code.
|
|
552
723
|
*/
|
|
553
|
-
async exec(command) {
|
|
724
|
+
async exec(command, options) {
|
|
554
725
|
return unwrap(retryApiRequest(() => this._client.POST("/api/disks/{id}/exec", {
|
|
555
726
|
params: { path: { id: this.id } },
|
|
556
|
-
body: {
|
|
727
|
+
body: {
|
|
728
|
+
...execVmBody(options),
|
|
729
|
+
command
|
|
730
|
+
}
|
|
557
731
|
}), "connect"));
|
|
558
732
|
}
|
|
559
733
|
/**
|
|
@@ -900,29 +1074,22 @@ var Disk = class {
|
|
|
900
1074
|
*/
|
|
901
1075
|
async _s3Request(method, key, opts = {}) {
|
|
902
1076
|
if (!this._s3BaseUrl) throw new Error("S3 base URL not configured. Pass s3BaseUrl to new Archil({...}) or set ARCHIL_S3_BASE_URL.");
|
|
903
|
-
const call = this._client[method];
|
|
904
1077
|
const encodedKey = key.replace(/^\//, "").split("/").map(encodeURIComponent).join("/");
|
|
905
1078
|
const path = encodedKey ? `/${this.id}/${encodedKey}` : `/${this.id}`;
|
|
1079
|
+
const url = `${this._s3BaseUrl.replace(/\/+$/, "")}${path}${buildQuery(opts.query)}`;
|
|
906
1080
|
const init = {
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
...opts.query ? { params: { query: opts.query } } : {},
|
|
910
|
-
...opts.body !== void 0 ? {
|
|
911
|
-
body: opts.body,
|
|
912
|
-
bodySerializer: (b) => b
|
|
913
|
-
} : {},
|
|
914
|
-
...opts.contentType || opts.extraHeaders ? { headers: {
|
|
1081
|
+
body: opts.body,
|
|
1082
|
+
headers: {
|
|
915
1083
|
...opts.contentType ? { "Content-Type": opts.contentType } : {},
|
|
916
1084
|
...opts.extraHeaders
|
|
917
|
-
}
|
|
1085
|
+
}
|
|
918
1086
|
};
|
|
919
1087
|
const hasBody = method === "GET" || method === "POST";
|
|
920
1088
|
const maxRetries = opts.retry === false ? 0 : 3;
|
|
921
1089
|
for (let attempt = 0;; attempt++) {
|
|
922
|
-
let error;
|
|
923
1090
|
let response;
|
|
924
1091
|
try {
|
|
925
|
-
|
|
1092
|
+
response = await this._client.raw(method, url, init);
|
|
926
1093
|
} catch (transportError) {
|
|
927
1094
|
if (attempt < maxRetries) {
|
|
928
1095
|
await retrySleep(attempt);
|
|
@@ -936,15 +1103,15 @@ var Disk = class {
|
|
|
936
1103
|
await retrySleep(attempt);
|
|
937
1104
|
continue;
|
|
938
1105
|
}
|
|
939
|
-
const message = typeof error === "string" ? error : error ? JSON.stringify(error) : "";
|
|
940
1106
|
return {
|
|
941
1107
|
ok: false,
|
|
942
1108
|
status: response.status,
|
|
943
1109
|
statusText: response.statusText,
|
|
944
1110
|
headers: response.headers,
|
|
945
|
-
body: new
|
|
1111
|
+
body: new Uint8Array(await response.arrayBuffer())
|
|
946
1112
|
};
|
|
947
1113
|
}
|
|
1114
|
+
if (!hasBody) await response.body?.cancel().catch(() => {});
|
|
948
1115
|
const bytes = hasBody ? new Uint8Array(await response.arrayBuffer()) : /* @__PURE__ */ new Uint8Array(0);
|
|
949
1116
|
return {
|
|
950
1117
|
ok: true,
|
|
@@ -1370,10 +1537,13 @@ var Disks = class {
|
|
|
1370
1537
|
* disk ID directly so callers that do not need its metadata can execute
|
|
1371
1538
|
* without fetching the disk first.
|
|
1372
1539
|
*/
|
|
1373
|
-
async exec(id, command) {
|
|
1540
|
+
async exec(id, command, options) {
|
|
1374
1541
|
return unwrap(retryApiRequest(() => this._client.POST("/api/disks/{id}/exec", {
|
|
1375
1542
|
params: { path: { id } },
|
|
1376
|
-
body: {
|
|
1543
|
+
body: {
|
|
1544
|
+
...execVmBody(options),
|
|
1545
|
+
command
|
|
1546
|
+
}
|
|
1377
1547
|
}), "connect"));
|
|
1378
1548
|
}
|
|
1379
1549
|
};
|
|
@@ -1451,6 +1621,15 @@ var Images = class {
|
|
|
1451
1621
|
//#endregion
|
|
1452
1622
|
//#region src/sandbox-process.ts
|
|
1453
1623
|
const PROCESS_STDIN_CHUNK_BYTES = 1024 * 1024;
|
|
1624
|
+
/** Close codes the runtime uses when it ends a connection to a running process. */
|
|
1625
|
+
const CLOSE_REASONS = {
|
|
1626
|
+
4001: "Process was taken over by another connection",
|
|
1627
|
+
4003: "Process owner disconnected"
|
|
1628
|
+
};
|
|
1629
|
+
/** The subprotocol the runtime selects for a process connection. */
|
|
1630
|
+
const CONNECT_SUBPROTOCOL = "archil.connect.v1";
|
|
1631
|
+
/** Prefix of the subprotocol that carries a connection token. */
|
|
1632
|
+
const TOKEN_SUBPROTOCOL_PREFIX = "archil.token.";
|
|
1454
1633
|
async function waitForSocketOpen(socket) {
|
|
1455
1634
|
if (socket.readyState === WebSocket.OPEN) return;
|
|
1456
1635
|
await new Promise((resolve, reject) => {
|
|
@@ -1476,12 +1655,13 @@ async function waitForSocketOpen(socket) {
|
|
|
1476
1655
|
socket.addEventListener("close", closed, { once: true });
|
|
1477
1656
|
});
|
|
1478
1657
|
}
|
|
1479
|
-
async function openProcessSocket(
|
|
1658
|
+
async function openProcessSocket(connectionEndpoint) {
|
|
1480
1659
|
for (let attempt = 0;; attempt++) {
|
|
1481
|
-
const
|
|
1660
|
+
const target = await connectionEndpoint();
|
|
1661
|
+
const endpoint = typeof target === "string" ? { url: target } : target;
|
|
1482
1662
|
let socket;
|
|
1483
1663
|
try {
|
|
1484
|
-
socket = new WebSocket(url);
|
|
1664
|
+
socket = endpoint.protocols ? new WebSocket(endpoint.url, endpoint.protocols) : new WebSocket(endpoint.url);
|
|
1485
1665
|
await waitForSocketOpen(socket);
|
|
1486
1666
|
return socket;
|
|
1487
1667
|
} catch (error) {
|
|
@@ -1517,7 +1697,7 @@ var SandboxProcess = class {
|
|
|
1517
1697
|
_cursor;
|
|
1518
1698
|
_onOutput;
|
|
1519
1699
|
_collectOutput;
|
|
1520
|
-
|
|
1700
|
+
_connectionEndpoint;
|
|
1521
1701
|
_controlProcess;
|
|
1522
1702
|
_stdoutDecoder = new TextDecoder();
|
|
1523
1703
|
_stderrDecoder = new TextDecoder();
|
|
@@ -1529,12 +1709,12 @@ var SandboxProcess = class {
|
|
|
1529
1709
|
_connectionError;
|
|
1530
1710
|
_stdinClosed = false;
|
|
1531
1711
|
/** @internal */
|
|
1532
|
-
constructor(processId, cursor, onOutput, collectOutput,
|
|
1712
|
+
constructor(processId, cursor, onOutput, collectOutput, connectionEndpoint, controlProcess) {
|
|
1533
1713
|
this._id = processId;
|
|
1534
1714
|
this._cursor = cursor;
|
|
1535
1715
|
this._onOutput = onOutput;
|
|
1536
1716
|
this._collectOutput = collectOutput;
|
|
1537
|
-
this.
|
|
1717
|
+
this._connectionEndpoint = connectionEndpoint;
|
|
1538
1718
|
this._controlProcess = controlProcess;
|
|
1539
1719
|
this._terminal = new Promise((resolve) => {
|
|
1540
1720
|
this._resolveTerminal = resolve;
|
|
@@ -1595,7 +1775,7 @@ var SandboxProcess = class {
|
|
|
1595
1775
|
}
|
|
1596
1776
|
/** @internal */
|
|
1597
1777
|
async _connect(request) {
|
|
1598
|
-
const socket = await openProcessSocket(this.
|
|
1778
|
+
const socket = await openProcessSocket(this._connectionEndpoint);
|
|
1599
1779
|
socket.binaryType = "arraybuffer";
|
|
1600
1780
|
this._socket = socket;
|
|
1601
1781
|
let resolveClosed;
|
|
@@ -1637,7 +1817,9 @@ var SandboxProcess = class {
|
|
|
1637
1817
|
this._connectionError = error;
|
|
1638
1818
|
fail(error);
|
|
1639
1819
|
});
|
|
1640
|
-
socket.addEventListener("close", () => {
|
|
1820
|
+
socket.addEventListener("close", (event) => {
|
|
1821
|
+
const reason = CLOSE_REASONS[event.code];
|
|
1822
|
+
if (reason && !this._result) this._connectionError = new Error(reason);
|
|
1641
1823
|
if (this._socket === socket) this._socket = void 0;
|
|
1642
1824
|
if (!readySettled) rejectReady(/* @__PURE__ */ new Error("Process connection closed before ready"));
|
|
1643
1825
|
resolveClosed();
|
|
@@ -2054,7 +2236,7 @@ var Sandbox = class Sandbox {
|
|
|
2054
2236
|
}
|
|
2055
2237
|
/** Start a process and return its handle without waiting for exit. */
|
|
2056
2238
|
async run(command, options = {}) {
|
|
2057
|
-
const process = new SandboxProcess("", 0, options.onOutput, options.collectOutput ?? true, () => this.
|
|
2239
|
+
const process = new SandboxProcess("", 0, options.onOutput, options.collectOutput ?? true, () => this._connectionEndpoint(), (request) => this._control(request));
|
|
2058
2240
|
const terminal = typeof options.terminal === "object" ? {
|
|
2059
2241
|
cols: options.terminal.cols ?? 80,
|
|
2060
2242
|
rows: options.terminal.rows ?? 24
|
|
@@ -2072,19 +2254,25 @@ var Sandbox = class Sandbox {
|
|
|
2072
2254
|
/** Reattach to a process, optionally resuming output from a cursor. */
|
|
2073
2255
|
async attach(processId, options = {}) {
|
|
2074
2256
|
const offset = options.offset ?? 0;
|
|
2075
|
-
const process = new SandboxProcess(processId, offset, options.onOutput, options.collectOutput ?? true, () => this.
|
|
2257
|
+
const process = new SandboxProcess(processId, offset, options.onOutput, options.collectOutput ?? true, () => this._connectionEndpoint(), (request) => this._control(request));
|
|
2076
2258
|
await process._connect({
|
|
2077
2259
|
type: "attach",
|
|
2078
2260
|
process_id: processId,
|
|
2079
|
-
offset
|
|
2261
|
+
offset,
|
|
2262
|
+
...options.shared ? { shared: true } : {}
|
|
2080
2263
|
});
|
|
2081
2264
|
return process;
|
|
2082
2265
|
}
|
|
2083
|
-
async
|
|
2084
|
-
|
|
2266
|
+
async _connectionEndpoint() {
|
|
2267
|
+
const data = await unwrap(retryApiRequest(() => this._client.POST("/api/sandboxes/{sid}/connections", { params: { path: { sid: this.id } } }), "transient"));
|
|
2268
|
+
if (data.endpoint && data.token) return {
|
|
2269
|
+
url: data.endpoint,
|
|
2270
|
+
protocols: [CONNECT_SUBPROTOCOL, `${TOKEN_SUBPROTOCOL_PREFIX}${data.token}`]
|
|
2271
|
+
};
|
|
2272
|
+
return { url: data.url };
|
|
2085
2273
|
}
|
|
2086
2274
|
async _control(request) {
|
|
2087
|
-
const socket = await openProcessSocket(() => this.
|
|
2275
|
+
const socket = await openProcessSocket(() => this._connectionEndpoint());
|
|
2088
2276
|
const expected = request.type === "kill" ? "killed" : "resized";
|
|
2089
2277
|
await new Promise((resolve, reject) => {
|
|
2090
2278
|
socket.addEventListener("message", (message) => {
|
|
@@ -2761,6 +2949,7 @@ var Archil = class {
|
|
|
2761
2949
|
disks[relPath] = entry;
|
|
2762
2950
|
} else disks[relPath] = diskIdFromMount(mount);
|
|
2763
2951
|
return unwrap(retryApiRequest(() => this._client.POST("/api/exec", { body: {
|
|
2952
|
+
...execVmBody(opts),
|
|
2764
2953
|
disks,
|
|
2765
2954
|
command: opts.command
|
|
2766
2955
|
} }), "connect"));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "disk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.0",
|
|
4
4
|
"description": "Pure-JS client and CLIs for Archil disks and sandboxes",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"archil",
|
|
@@ -40,20 +40,23 @@
|
|
|
40
40
|
"LICENSE"
|
|
41
41
|
],
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@archildata/api-types": "^0.0.
|
|
44
|
-
"
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
"openapi-fetch": "^0.13.5",
|
|
48
|
-
"undici": "8.10.2",
|
|
49
|
-
"uuid": "^11.1.1",
|
|
43
|
+
"@archildata/api-types": "^0.0.81",
|
|
44
|
+
"undici": "^8.12.3"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
50
47
|
"zod": "^4.4.3"
|
|
51
48
|
},
|
|
49
|
+
"peerDependenciesMeta": {
|
|
50
|
+
"zod": {
|
|
51
|
+
"optional": true
|
|
52
|
+
}
|
|
53
|
+
},
|
|
52
54
|
"devDependencies": {
|
|
53
55
|
"@types/node": "^26.0.1",
|
|
54
56
|
"tsdown": "^0.22.3",
|
|
55
57
|
"typescript": "^6.0.3",
|
|
56
|
-
"vitest": "^4.1.9"
|
|
58
|
+
"vitest": "^4.1.9",
|
|
59
|
+
"zod": "^4.4.3"
|
|
57
60
|
},
|
|
58
61
|
"engines": {
|
|
59
62
|
"node": ">= 22.19.0"
|