disk 1.15.1 → 1.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -2
- package/dist/{archil-CenIy1WD.d.mts → archil-DiHA0VsS.d.mts} +400 -250
- package/dist/{archil-DHPfg1b9.d.cts → archil-Dte6VwUg.d.cts} +400 -250
- package/dist/archil-cli.mjs +4 -4
- package/dist/cli.mjs +2 -2
- package/dist/{disk-command-CusW9mn8.mjs → disk-command-e1AyXrI4.mjs} +3 -3
- package/dist/index.cjs +2731 -2024
- package/dist/index.d.cts +6 -5
- package/dist/index.d.mts +6 -5
- package/dist/index.mjs +1 -1
- package/dist/internal/tools.d.cts +1 -1
- package/dist/internal/tools.d.mts +1 -1
- package/dist/node/index.cjs +2731 -2024
- package/dist/node/index.mjs +2732 -2025
- package/dist/sandbox-cli.mjs +3 -3
- package/dist/{sandbox-command-BZys6M2u.mjs → sandbox-command-qj_ZlLev.mjs} +1 -1
- package/dist/{sandbox-options-DkEtNyFE.mjs → sandbox-options-Ck_EAl3Z.mjs} +1 -1
- package/dist/{src-BLxQg4dX.mjs → src-B_nMppCu.mjs} +2733 -2026
- package/dist/tunnel.d.cts +1 -1
- package/dist/tunnel.d.mts +1 -1
- package/package.json +4 -3
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MessageInitShape, fromBinary } from "@bufbuild/protobuf";
|
|
2
|
+
import { ClientFrame, ClientFrameSchema, SandboxSchema, ServerFrameSchema } from "@archildata/api-types/process";
|
|
2
3
|
import { ConnectionOptions } from "node:tls";
|
|
3
4
|
import { components, paths } from "@archildata/api-types";
|
|
4
5
|
|
|
@@ -36,6 +37,7 @@ type JsonBodyInit<O> = O extends {
|
|
|
36
37
|
body?: never;
|
|
37
38
|
};
|
|
38
39
|
type RequestOptions<O> = ParamsInit<O> & JsonBodyInit<O>;
|
|
40
|
+
/** What a call to operation O takes: its path, query, and header params and JSON body. */
|
|
39
41
|
type InitArgs<O> = [RequiredKeys<RequestOptions<O>>] extends [never] ? [init?: RequestOptions<O>] : [init: RequestOptions<O>];
|
|
40
42
|
type SuccessStatus = 200 | 201 | 202 | 203 | 204 | 206;
|
|
41
43
|
type ResponseData<O> = O extends {
|
|
@@ -61,6 +63,8 @@ interface ApiClient {
|
|
|
61
63
|
POST: MethodFn<"post">;
|
|
62
64
|
DELETE: MethodFn<"delete">;
|
|
63
65
|
PATCH: MethodFn<"patch">;
|
|
66
|
+
/** Seconds a call that waits for capacity keeps retrying while the region has none. */
|
|
67
|
+
readonly maxThrottleWait: number;
|
|
64
68
|
/**
|
|
65
69
|
* Send an untyped request through the client's transport and default
|
|
66
70
|
* headers, returning the raw response (used for the S3 gateway).
|
|
@@ -81,6 +85,238 @@ interface ArchilTlsOptions {
|
|
|
81
85
|
ca?: ConnectionOptions["ca"];
|
|
82
86
|
}
|
|
83
87
|
//#endregion
|
|
88
|
+
//#region src/process-core.d.ts
|
|
89
|
+
type FrameBody = NonNullable<MessageInitShape<typeof ClientFrameSchema>["body"]>;
|
|
90
|
+
/** An error the transport caused. Python raises these as ConnectionError. */
|
|
91
|
+
type ProcessStatus = "running" | "completed" | "failed" | "cancelled" | "timed_out";
|
|
92
|
+
type ProcessStream = "stdout" | "stderr";
|
|
93
|
+
interface ProcessOutput {
|
|
94
|
+
stream: ProcessStream;
|
|
95
|
+
offset: number;
|
|
96
|
+
data: Uint8Array;
|
|
97
|
+
}
|
|
98
|
+
interface ProcessResult {
|
|
99
|
+
status: Exclude<ProcessStatus, "running">;
|
|
100
|
+
exitCode?: number;
|
|
101
|
+
exitReason?: string;
|
|
102
|
+
stdout: string;
|
|
103
|
+
stderr: string;
|
|
104
|
+
}
|
|
105
|
+
interface StartRequest {
|
|
106
|
+
type: "start";
|
|
107
|
+
command: string;
|
|
108
|
+
cwd?: string;
|
|
109
|
+
env: Record<string, string>;
|
|
110
|
+
terminal?: boolean | {
|
|
111
|
+
rows: number;
|
|
112
|
+
cols: number;
|
|
113
|
+
};
|
|
114
|
+
timeout_seconds?: number;
|
|
115
|
+
}
|
|
116
|
+
/** The VM an exec runs in, as the exec endpoint takes it. */
|
|
117
|
+
type ExecSandbox = MessageInitShape<typeof SandboxSchema>;
|
|
118
|
+
type ProcessRequest = StartRequest | {
|
|
119
|
+
type: "exec";
|
|
120
|
+
start: Omit<StartRequest, "type">;
|
|
121
|
+
sandbox: ExecSandbox;
|
|
122
|
+
} | {
|
|
123
|
+
type: "attach";
|
|
124
|
+
process_id: string;
|
|
125
|
+
offset: number;
|
|
126
|
+
shared?: true;
|
|
127
|
+
};
|
|
128
|
+
type ControlRequest = {
|
|
129
|
+
type: "kill";
|
|
130
|
+
process_id: string;
|
|
131
|
+
} | {
|
|
132
|
+
type: "resize";
|
|
133
|
+
process_id: string;
|
|
134
|
+
rows: number;
|
|
135
|
+
cols: number;
|
|
136
|
+
};
|
|
137
|
+
type ChannelRequest = ProcessRequest | ControlRequest;
|
|
138
|
+
type ChannelEvent = {
|
|
139
|
+
type: "started" | "attached";
|
|
140
|
+
process_id: string;
|
|
141
|
+
} | {
|
|
142
|
+
type: "output";
|
|
143
|
+
stream: ProcessStream;
|
|
144
|
+
offset: number;
|
|
145
|
+
data: Uint8Array;
|
|
146
|
+
cost: number;
|
|
147
|
+
} | {
|
|
148
|
+
type: "exit";
|
|
149
|
+
status: Exclude<ProcessStatus, "running">;
|
|
150
|
+
exit_code?: number;
|
|
151
|
+
exit_reason?: string;
|
|
152
|
+
cursor: number;
|
|
153
|
+
} | {
|
|
154
|
+
type: "error";
|
|
155
|
+
error: string;
|
|
156
|
+
message: string;
|
|
157
|
+
} | {
|
|
158
|
+
type: "killed" | "resized";
|
|
159
|
+
};
|
|
160
|
+
/** What a connection core asks of the socket it runs over. */
|
|
161
|
+
interface ConnectionHost {
|
|
162
|
+
/** Send a frame. May throw if the socket refuses it. */
|
|
163
|
+
send(frame: ClientFrame): void;
|
|
164
|
+
/** Whether the socket can take more writes without exceeding its buffer bound. */
|
|
165
|
+
writable(): boolean;
|
|
166
|
+
/** Whether the socket is open; a peer's close can land before the shell hears of it. */
|
|
167
|
+
socketOpen(): boolean;
|
|
168
|
+
closeSocket(): void;
|
|
169
|
+
startIdleTimer(): void;
|
|
170
|
+
cancelIdleTimer(): void;
|
|
171
|
+
/** The connection closed; open new channels elsewhere. */
|
|
172
|
+
closed(): void;
|
|
173
|
+
}
|
|
174
|
+
/** What a channel tells the process or control request on it. */
|
|
175
|
+
interface ChannelListener {
|
|
176
|
+
event(event: ChannelEvent): void;
|
|
177
|
+
/** Stdin was sent, or a send failed. */
|
|
178
|
+
stdinChanged(): void;
|
|
179
|
+
closed(): void;
|
|
180
|
+
}
|
|
181
|
+
/** One socket's channels. */
|
|
182
|
+
declare class ConnectionCore {
|
|
183
|
+
readonly host: ConnectionHost;
|
|
184
|
+
private readonly maxChannels;
|
|
185
|
+
readonly channels: Map<number, ChannelCore>;
|
|
186
|
+
private next;
|
|
187
|
+
private draining;
|
|
188
|
+
private closedState;
|
|
189
|
+
constructor(host: ConnectionHost, maxChannels?: number);
|
|
190
|
+
get canOpen(): boolean;
|
|
191
|
+
get isClosed(): boolean;
|
|
192
|
+
open(): ChannelCore;
|
|
193
|
+
/** A binary message from the socket. */
|
|
194
|
+
receive(data: Uint8Array): void;
|
|
195
|
+
/** Take no new channels, and close once the last one finishes. */
|
|
196
|
+
drain(): void;
|
|
197
|
+
send(id: number, body: FrameBody): void;
|
|
198
|
+
/** The socket can take writes again; send stdin that was waiting for it. */
|
|
199
|
+
writable(): void;
|
|
200
|
+
remove(id: number): void;
|
|
201
|
+
idleExpired(): void;
|
|
202
|
+
close(reason?: unknown): void;
|
|
203
|
+
}
|
|
204
|
+
type ChannelState = "open" | "closing" | "closed";
|
|
205
|
+
/** One process, or one kill or resize, on a connection. */
|
|
206
|
+
declare class ChannelCore {
|
|
207
|
+
private readonly connection;
|
|
208
|
+
readonly id: number;
|
|
209
|
+
state: ChannelState;
|
|
210
|
+
listener: ChannelListener;
|
|
211
|
+
/** Stdin the runtime will accept. */
|
|
212
|
+
private sendCredit;
|
|
213
|
+
/** Output the runtime may still send. */
|
|
214
|
+
private receiveCredit;
|
|
215
|
+
/** Output consumed since credit was last returned. */
|
|
216
|
+
private consumed;
|
|
217
|
+
/** Stdin chunks waiting for credit or a writable socket. */
|
|
218
|
+
private stdin;
|
|
219
|
+
/** Bytes of stdin queued and sent so far; a write is done once `stdinSent` reaches its end. */
|
|
220
|
+
private stdinQueued;
|
|
221
|
+
private stdinSent;
|
|
222
|
+
/** Failed sends: each failed the writes ending in (from, through]. */
|
|
223
|
+
private stdinFailures;
|
|
224
|
+
private closeStdinQueued;
|
|
225
|
+
private closeStdinSent;
|
|
226
|
+
private closeStdinFailure?;
|
|
227
|
+
constructor(connection: ConnectionCore, id: number);
|
|
228
|
+
request(request: ChannelRequest): void;
|
|
229
|
+
/** Queue stdin; returns the position `stdinSent` reaches once it is all sent. */
|
|
230
|
+
queueStdin(data: Uint8Array): number;
|
|
231
|
+
/** Whether the write ending at `end` was sent, failed, or is still waiting. */
|
|
232
|
+
stdinOutcome(end: number): "sent" | Error | undefined;
|
|
233
|
+
/** Queue EOF after the stdin already queued. */
|
|
234
|
+
closeStdin(): void;
|
|
235
|
+
/** Whether EOF was sent, failed, or is still waiting. */
|
|
236
|
+
get closeStdinOutcome(): "sent" | Error | undefined;
|
|
237
|
+
/** Send queued stdin while the runtime has credit for it and the socket can take it. */
|
|
238
|
+
pump(): void;
|
|
239
|
+
/** Whether stdin is waiting only for the socket to be writable. */
|
|
240
|
+
get waitingToWrite(): boolean;
|
|
241
|
+
/** Return credit for output the application has taken. */
|
|
242
|
+
release(cost: number): void;
|
|
243
|
+
/** Detach from the process, leaving it running. */
|
|
244
|
+
close(): void;
|
|
245
|
+
receive(body: ReturnType<typeof fromBinary<typeof ServerFrameSchema>>["body"]): void;
|
|
246
|
+
/** Fail only this channel, for a message whose value it cannot represent. */
|
|
247
|
+
private fail;
|
|
248
|
+
finish(reason?: unknown): void;
|
|
249
|
+
}
|
|
250
|
+
type Readiness = "pending" | "ready" | Error;
|
|
251
|
+
/** A process handle's state: its output, cursor, consumer, and result. */
|
|
252
|
+
declare class ProcessCore implements ChannelListener {
|
|
253
|
+
private readonly collectOutput;
|
|
254
|
+
/** Called after any change a waiter may be waiting for. */
|
|
255
|
+
private readonly changed;
|
|
256
|
+
id: string;
|
|
257
|
+
/** Next byte after output accepted into the buffer. */
|
|
258
|
+
cursor: number;
|
|
259
|
+
status: ProcessStatus;
|
|
260
|
+
stdout: string;
|
|
261
|
+
stderr: string;
|
|
262
|
+
ready: Readiness;
|
|
263
|
+
error?: Error;
|
|
264
|
+
result?: ProcessResult;
|
|
265
|
+
exit?: Extract<ChannelEvent, {
|
|
266
|
+
type: "exit";
|
|
267
|
+
}>;
|
|
268
|
+
channel?: ChannelCore;
|
|
269
|
+
/** Set once the channel has closed. */
|
|
270
|
+
channelClosed: boolean;
|
|
271
|
+
manual: boolean;
|
|
272
|
+
stdinClosed: boolean;
|
|
273
|
+
iteratorTaken: boolean;
|
|
274
|
+
private deliveredCursor;
|
|
275
|
+
private expected;
|
|
276
|
+
private buffer;
|
|
277
|
+
private readonly stdoutDecoder;
|
|
278
|
+
private readonly stderrDecoder;
|
|
279
|
+
constructor(processId: string, cursor: number, collectOutput: boolean, /** Called after any change a waiter may be waiting for. */
|
|
280
|
+
|
|
281
|
+
changed: () => void);
|
|
282
|
+
get connected(): boolean;
|
|
283
|
+
get done(): boolean;
|
|
284
|
+
connect(channel: ChannelCore, request: ProcessRequest): void;
|
|
285
|
+
event(event: ChannelEvent): void;
|
|
286
|
+
stdinChanged(): void;
|
|
287
|
+
closed(): void;
|
|
288
|
+
/** The channel for a stdin write or EOF, or why there is none. */
|
|
289
|
+
private openChannel;
|
|
290
|
+
/** Queue stdin; returns the `channel.stdinSent` that means it was all sent. */
|
|
291
|
+
sendInput(data: Uint8Array): number;
|
|
292
|
+
/** Queue EOF. Returns false if stdin was already closed. */
|
|
293
|
+
closeStdin(): boolean;
|
|
294
|
+
/** EOF could not be sent; stdin stays open. */
|
|
295
|
+
closeStdinFailed(): void;
|
|
296
|
+
/** Check a resize is allowed before sending it. */
|
|
297
|
+
checkResize(): void;
|
|
298
|
+
/** Whether a kill still has a process to stop. */
|
|
299
|
+
get killable(): boolean;
|
|
300
|
+
/** Start detaching; the shell waits for `channelClosed`, then calls `disconnected`. */
|
|
301
|
+
disconnect(): void;
|
|
302
|
+
disconnected(): void;
|
|
303
|
+
/** Become the output's consumer. Each process has one. */
|
|
304
|
+
beginIterating(): void;
|
|
305
|
+
/**
|
|
306
|
+
* The iterator's next step: an output to yield, "end", or "wait" for a change.
|
|
307
|
+
* Throws the process's error once its output is drained.
|
|
308
|
+
*/
|
|
309
|
+
next(): ProcessOutput | "end" | "wait";
|
|
310
|
+
/** Whether an iterator that stops early must disconnect first. */
|
|
311
|
+
get stopNeedsDisconnect(): boolean;
|
|
312
|
+
/** The iterator stopped; output left behind no longer holds back the result. */
|
|
313
|
+
stoppedIterating(): void;
|
|
314
|
+
fail(error: Error): void;
|
|
315
|
+
private complete;
|
|
316
|
+
private enqueue;
|
|
317
|
+
private appendText;
|
|
318
|
+
}
|
|
319
|
+
//#endregion
|
|
84
320
|
//#region src/sandbox-desktop.d.ts
|
|
85
321
|
/**
|
|
86
322
|
* Sandbox desktops: a Linux desktop (Ubuntu, XFCE, Firefox) served over VNC
|
|
@@ -157,249 +393,6 @@ declare class SandboxDesktop {
|
|
|
157
393
|
private run;
|
|
158
394
|
}
|
|
159
395
|
//#endregion
|
|
160
|
-
//#region src/process-output-buffer.d.ts
|
|
161
|
-
/**
|
|
162
|
-
* Output each process has received but its iterator has not taken yet.
|
|
163
|
-
* Flow control bounds it to one channel window per process, so it never
|
|
164
|
-
* needs to refuse output. Output a handle never reads goes with the handle.
|
|
165
|
-
*/
|
|
166
|
-
declare class ProcessOutputBuffer {
|
|
167
|
-
private readonly queues;
|
|
168
|
-
has(subscription: object): boolean;
|
|
169
|
-
push(subscription: object, output: SandboxProcessOutput): void;
|
|
170
|
-
take(subscription: object): SandboxProcessOutput | undefined;
|
|
171
|
-
discard(subscription: object): void;
|
|
172
|
-
}
|
|
173
|
-
//#endregion
|
|
174
|
-
//#region src/process-connection.d.ts
|
|
175
|
-
type Request$1 = {
|
|
176
|
-
type: "start";
|
|
177
|
-
command: string;
|
|
178
|
-
cwd?: string;
|
|
179
|
-
env: Record<string, string>;
|
|
180
|
-
terminal?: boolean | {
|
|
181
|
-
rows: number;
|
|
182
|
-
cols: number;
|
|
183
|
-
};
|
|
184
|
-
timeout_seconds?: number;
|
|
185
|
-
} | {
|
|
186
|
-
type: "attach";
|
|
187
|
-
process_id: string;
|
|
188
|
-
offset: number;
|
|
189
|
-
shared?: true;
|
|
190
|
-
} | {
|
|
191
|
-
type: "kill";
|
|
192
|
-
process_id: string;
|
|
193
|
-
} | {
|
|
194
|
-
type: "resize";
|
|
195
|
-
process_id: string;
|
|
196
|
-
rows: number;
|
|
197
|
-
cols: number;
|
|
198
|
-
};
|
|
199
|
-
/** Owns only the client connection. A disconnected transport never retries START. */
|
|
200
|
-
declare class BinaryConnection {
|
|
201
|
-
private readonly socket;
|
|
202
|
-
private readonly onClosed;
|
|
203
|
-
readonly channels: Map<number, BinaryChannel>;
|
|
204
|
-
private next;
|
|
205
|
-
private draining;
|
|
206
|
-
private idle?;
|
|
207
|
-
get canOpen(): boolean;
|
|
208
|
-
constructor(socket: WebSocket, onClosed: () => void);
|
|
209
|
-
channel(): BinaryChannel;
|
|
210
|
-
send(id: number, body: ClientFrame["body"]): void;
|
|
211
|
-
writable(): Promise<void>;
|
|
212
|
-
remove(id: number): void;
|
|
213
|
-
close(reason?: unknown): void;
|
|
214
|
-
}
|
|
215
|
-
/** @internal WebSocket-shaped channel; generated protobuf owns all wire encoding. */
|
|
216
|
-
declare class BinaryChannel {
|
|
217
|
-
private readonly connection;
|
|
218
|
-
readonly id: number;
|
|
219
|
-
readyState: number;
|
|
220
|
-
binaryType: string;
|
|
221
|
-
private readonly events;
|
|
222
|
-
readonly addEventListener: WebSocket["addEventListener"];
|
|
223
|
-
private sending;
|
|
224
|
-
/** Stdin the runtime will accept. */
|
|
225
|
-
private sendCredit;
|
|
226
|
-
/** Output the runtime may still send. */
|
|
227
|
-
private receiveCredit;
|
|
228
|
-
/** Output consumed since credit was last returned. */
|
|
229
|
-
private consumed;
|
|
230
|
-
private creditChanged?;
|
|
231
|
-
constructor(connection: BinaryConnection, id: number);
|
|
232
|
-
sendRequest(request: Request$1): void;
|
|
233
|
-
send(bytes: Uint8Array): Promise<void>;
|
|
234
|
-
/** Returns credit for output the application has taken. */
|
|
235
|
-
release(cost: number): void;
|
|
236
|
-
closeStdin(): Promise<void>;
|
|
237
|
-
close(): void;
|
|
238
|
-
receive(frame: ServerFrame): void;
|
|
239
|
-
/** Fails only this channel, for a message whose value it cannot represent. */
|
|
240
|
-
private fail;
|
|
241
|
-
finish(reason?: unknown): void;
|
|
242
|
-
}
|
|
243
|
-
//#endregion
|
|
244
|
-
//#region src/sandbox-process.d.ts
|
|
245
|
-
type SandboxProcessStatus = "running" | "completed" | "failed" | "cancelled" | "timed_out";
|
|
246
|
-
type SandboxProcessStream = "stdout" | "stderr";
|
|
247
|
-
interface SandboxProcessOutput {
|
|
248
|
-
stream: SandboxProcessStream;
|
|
249
|
-
offset: number;
|
|
250
|
-
data: Uint8Array;
|
|
251
|
-
}
|
|
252
|
-
/**
|
|
253
|
-
* Receives each output chunk in order. Returning a promise holds back that
|
|
254
|
-
* process's output until it settles, so a slow handler paces the process's
|
|
255
|
-
* output stream instead of buffering it.
|
|
256
|
-
*
|
|
257
|
-
* @deprecated Iterate the process's `output` instead.
|
|
258
|
-
*/
|
|
259
|
-
type SandboxProcessOutputHandler = (output: SandboxProcessOutput) => void | Promise<void>;
|
|
260
|
-
interface SandboxTerminalOptions {
|
|
261
|
-
cols?: number;
|
|
262
|
-
rows?: number;
|
|
263
|
-
}
|
|
264
|
-
interface SandboxProcessConnectOptions {
|
|
265
|
-
offset?: number;
|
|
266
|
-
/**
|
|
267
|
-
* Watch alongside the connection that owns the process instead of taking it
|
|
268
|
-
* over. By default, attaching takes the process over and the runtime closes
|
|
269
|
-
* the previous connection. A shared connection is closed when the owner's
|
|
270
|
-
* closes.
|
|
271
|
-
*/
|
|
272
|
-
shared?: boolean;
|
|
273
|
-
/**
|
|
274
|
-
* Delivers output to a handler; the handle's `output` iterator is then unavailable.
|
|
275
|
-
*
|
|
276
|
-
* @deprecated Iterate the process's `output` instead.
|
|
277
|
-
*/
|
|
278
|
-
onOutput?: SandboxProcessOutputHandler;
|
|
279
|
-
/** Retain decoded stdout and stderr on the handle and result. Defaults to true. */
|
|
280
|
-
collectOutput?: boolean;
|
|
281
|
-
}
|
|
282
|
-
interface SandboxProcessStartOptions {
|
|
283
|
-
/** Absolute working directory inside the sandbox. */
|
|
284
|
-
cwd?: string;
|
|
285
|
-
/** Enables a PTY. PTY output is merged into stdout and stderr remains empty. */
|
|
286
|
-
terminal?: boolean | SandboxTerminalOptions;
|
|
287
|
-
env?: Record<string, string>;
|
|
288
|
-
timeoutSeconds?: number;
|
|
289
|
-
/**
|
|
290
|
-
* Delivers output to a handler; the handle's `output` iterator is then unavailable.
|
|
291
|
-
*
|
|
292
|
-
* @deprecated Iterate the process's `output` instead.
|
|
293
|
-
*/
|
|
294
|
-
onOutput?: SandboxProcessOutputHandler;
|
|
295
|
-
/** Retain decoded stdout and stderr on the handle and result. Defaults to true. */
|
|
296
|
-
collectOutput?: boolean;
|
|
297
|
-
}
|
|
298
|
-
interface SandboxProcessResult {
|
|
299
|
-
status: Exclude<SandboxProcessStatus, "running">;
|
|
300
|
-
exitCode?: number;
|
|
301
|
-
exitReason?: string;
|
|
302
|
-
stdout: string;
|
|
303
|
-
stderr: string;
|
|
304
|
-
}
|
|
305
|
-
type ProcessConnectionRequest = {
|
|
306
|
-
type: "start";
|
|
307
|
-
command: string;
|
|
308
|
-
cwd?: string;
|
|
309
|
-
terminal?: boolean | {
|
|
310
|
-
cols: number;
|
|
311
|
-
rows: number;
|
|
312
|
-
};
|
|
313
|
-
env: Record<string, string>;
|
|
314
|
-
timeout_seconds?: number;
|
|
315
|
-
} | {
|
|
316
|
-
type: "attach";
|
|
317
|
-
process_id: string;
|
|
318
|
-
offset: number;
|
|
319
|
-
shared?: true;
|
|
320
|
-
};
|
|
321
|
-
type ProcessControlRequest = {
|
|
322
|
-
type: "kill";
|
|
323
|
-
process_id: string;
|
|
324
|
-
} | {
|
|
325
|
-
type: "resize";
|
|
326
|
-
process_id: string;
|
|
327
|
-
cols: number;
|
|
328
|
-
rows: number;
|
|
329
|
-
};
|
|
330
|
-
/** @deprecated Use Sandbox.run() and Sandbox.attach(). Removed in the next version. */
|
|
331
|
-
declare class SandboxProcesses {
|
|
332
|
-
private readonly _sandbox;
|
|
333
|
-
private readonly _disconnect;
|
|
334
|
-
/** @internal */
|
|
335
|
-
constructor(_sandbox: Pick<Sandbox, "run" | "attach">, _disconnect: () => void);
|
|
336
|
-
/** @deprecated Use sandbox.run(). Removed in the next version. */
|
|
337
|
-
start(command: string, options?: SandboxProcessStartOptions): Promise<SandboxProcess>;
|
|
338
|
-
/** @deprecated Use sandbox.attach(). Removed in the next version. */
|
|
339
|
-
connect(processId: string, options?: SandboxProcessConnectOptions): Promise<SandboxProcess>;
|
|
340
|
-
/** Disconnect process transport without terminating guest processes. */
|
|
341
|
-
disconnect(): Promise<void>;
|
|
342
|
-
}
|
|
343
|
-
declare class SandboxProcess {
|
|
344
|
-
private readonly _collectOutput;
|
|
345
|
-
private readonly _buffer;
|
|
346
|
-
private readonly _openConnection;
|
|
347
|
-
private readonly _controlProcess;
|
|
348
|
-
status: SandboxProcessStatus;
|
|
349
|
-
stdout: string;
|
|
350
|
-
stderr: string;
|
|
351
|
-
private _id;
|
|
352
|
-
private _cursor;
|
|
353
|
-
private _deliveredCursor;
|
|
354
|
-
private readonly _stdoutDecoder;
|
|
355
|
-
private readonly _stderrDecoder;
|
|
356
|
-
private _socket?;
|
|
357
|
-
private _closed?;
|
|
358
|
-
private _manual;
|
|
359
|
-
private _stdinClosed;
|
|
360
|
-
private _iteratorTaken;
|
|
361
|
-
/** Settles once onOutput has handled the last chunk. */
|
|
362
|
-
private _delivered?;
|
|
363
|
-
private _wake?;
|
|
364
|
-
private _error?;
|
|
365
|
-
private _exit?;
|
|
366
|
-
private _result?;
|
|
367
|
-
/** Returns each buffered binary output's credit once the iterator takes it. */
|
|
368
|
-
private readonly _releases;
|
|
369
|
-
private _resolveDone;
|
|
370
|
-
private readonly _done;
|
|
371
|
-
/** Pull output from the shared buffer. One iterator may consume each handle. */
|
|
372
|
-
readonly output: AsyncIterable<SandboxProcessOutput>;
|
|
373
|
-
/** @internal */
|
|
374
|
-
constructor(processId: string, cursor: number, _collectOutput: boolean, _buffer: ProcessOutputBuffer, _openConnection: () => Promise<BinaryChannel>, _controlProcess: (request: ProcessControlRequest) => Promise<void>);
|
|
375
|
-
get id(): string;
|
|
376
|
-
/** Next byte after output accepted into the SDK buffer. */
|
|
377
|
-
get cursor(): number;
|
|
378
|
-
get connected(): boolean;
|
|
379
|
-
/** Resolves once the runtime has accepted the input; waits while the process is not reading. */
|
|
380
|
-
sendInput(data: string | Uint8Array): Promise<void>;
|
|
381
|
-
closeStdin(): Promise<void>;
|
|
382
|
-
resize(size: {
|
|
383
|
-
cols: number;
|
|
384
|
-
rows: number;
|
|
385
|
-
}): Promise<void>;
|
|
386
|
-
kill(): Promise<void>;
|
|
387
|
-
disconnect(): Promise<void>;
|
|
388
|
-
wait(): Promise<SandboxProcessResult>;
|
|
389
|
-
/** @internal Feeds `output` to `handler`, waiting for each call to settle. */
|
|
390
|
-
_deliverTo(handler: SandboxProcessOutputHandler): void;
|
|
391
|
-
private _iterateOutput;
|
|
392
|
-
/** @internal */
|
|
393
|
-
_connect(request: ProcessConnectionRequest): Promise<void>;
|
|
394
|
-
private _openSocket;
|
|
395
|
-
private _fail;
|
|
396
|
-
private _complete;
|
|
397
|
-
/** `release` returns the output's flow-control credit once it is consumed. */
|
|
398
|
-
private _enqueueOutput;
|
|
399
|
-
private _appendText;
|
|
400
|
-
private _flushDecoders;
|
|
401
|
-
}
|
|
402
|
-
//#endregion
|
|
403
396
|
//#region src/sandbox-files.d.ts
|
|
404
397
|
type SandboxFileSource = Uint8Array | ArrayBuffer | Blob | AsyncIterable<Uint8Array> | ReadableStream<Uint8Array>;
|
|
405
398
|
type SandboxFileWriter = (chunk: Uint8Array) => void | Promise<void>;
|
|
@@ -569,7 +562,6 @@ declare class Sandbox {
|
|
|
569
562
|
/** @internal */
|
|
570
563
|
private readonly _client;
|
|
571
564
|
private readonly _processConnection;
|
|
572
|
-
private readonly _processOutput;
|
|
573
565
|
/** @internal */
|
|
574
566
|
constructor(data: SandboxWire, client: ApiClient);
|
|
575
567
|
/** @internal Overwrite this sandbox's fields in place from a fresh wire snapshot. */
|
|
@@ -579,6 +571,7 @@ declare class Sandbox {
|
|
|
579
571
|
run(command: string, options?: SandboxProcessStartOptions): Promise<SandboxProcess>;
|
|
580
572
|
/** Reattach to a process, optionally resuming output from a cursor. */
|
|
581
573
|
attach(processId: string, options?: SandboxProcessConnectOptions): Promise<SandboxProcess>;
|
|
574
|
+
private _connectProcess;
|
|
582
575
|
private _connectionEndpoint;
|
|
583
576
|
private _control;
|
|
584
577
|
/** Run a process and wait for it to exit. */
|
|
@@ -629,13 +622,127 @@ declare class Sandbox {
|
|
|
629
622
|
delete(): Promise<void>;
|
|
630
623
|
}
|
|
631
624
|
//#endregion
|
|
625
|
+
//#region src/sandbox-process.d.ts
|
|
626
|
+
type SandboxProcessStatus = "running" | "completed" | "failed" | "cancelled" | "timed_out";
|
|
627
|
+
type SandboxProcessStream = "stdout" | "stderr";
|
|
628
|
+
interface SandboxProcessOutput {
|
|
629
|
+
stream: SandboxProcessStream;
|
|
630
|
+
offset: number;
|
|
631
|
+
data: Uint8Array;
|
|
632
|
+
}
|
|
633
|
+
/**
|
|
634
|
+
* Receives each output chunk in order. Returning a promise holds back that
|
|
635
|
+
* process's output until it settles, so a slow handler paces the process's
|
|
636
|
+
* output stream instead of buffering it.
|
|
637
|
+
*
|
|
638
|
+
* @deprecated Iterate the process's `output` instead.
|
|
639
|
+
*/
|
|
640
|
+
type SandboxProcessOutputHandler = (output: SandboxProcessOutput) => void | Promise<void>;
|
|
641
|
+
interface SandboxTerminalOptions {
|
|
642
|
+
cols?: number;
|
|
643
|
+
rows?: number;
|
|
644
|
+
}
|
|
645
|
+
interface SandboxProcessConnectOptions {
|
|
646
|
+
offset?: number;
|
|
647
|
+
/**
|
|
648
|
+
* Watch alongside the connection that owns the process instead of taking it
|
|
649
|
+
* over. By default, attaching takes the process over and the runtime closes
|
|
650
|
+
* the previous connection. A shared connection is closed when the owner's
|
|
651
|
+
* closes.
|
|
652
|
+
*/
|
|
653
|
+
shared?: boolean;
|
|
654
|
+
/**
|
|
655
|
+
* Delivers output to a handler; the handle's `output` iterator is then unavailable.
|
|
656
|
+
*
|
|
657
|
+
* @deprecated Iterate the process's `output` instead.
|
|
658
|
+
*/
|
|
659
|
+
onOutput?: SandboxProcessOutputHandler;
|
|
660
|
+
/** Retain decoded stdout and stderr on the handle and result. Defaults to true. */
|
|
661
|
+
collectOutput?: boolean;
|
|
662
|
+
}
|
|
663
|
+
interface SandboxProcessStartOptions {
|
|
664
|
+
/** Absolute working directory inside the sandbox. */
|
|
665
|
+
cwd?: string;
|
|
666
|
+
/** Enables a PTY. PTY output is merged into stdout and stderr remains empty. */
|
|
667
|
+
terminal?: boolean | SandboxTerminalOptions;
|
|
668
|
+
env?: Record<string, string>;
|
|
669
|
+
timeoutSeconds?: number;
|
|
670
|
+
/**
|
|
671
|
+
* Delivers output to a handler; the handle's `output` iterator is then unavailable.
|
|
672
|
+
*
|
|
673
|
+
* @deprecated Iterate the process's `output` instead.
|
|
674
|
+
*/
|
|
675
|
+
onOutput?: SandboxProcessOutputHandler;
|
|
676
|
+
/** Retain decoded stdout and stderr on the handle and result. Defaults to true. */
|
|
677
|
+
collectOutput?: boolean;
|
|
678
|
+
}
|
|
679
|
+
interface SandboxProcessResult {
|
|
680
|
+
status: Exclude<SandboxProcessStatus, "running">;
|
|
681
|
+
exitCode?: number;
|
|
682
|
+
exitReason?: string;
|
|
683
|
+
stdout: string;
|
|
684
|
+
stderr: string;
|
|
685
|
+
}
|
|
686
|
+
/** @deprecated Use Sandbox.run() and Sandbox.attach(). Removed in the next version. */
|
|
687
|
+
declare class SandboxProcesses {
|
|
688
|
+
private readonly _sandbox;
|
|
689
|
+
private readonly _disconnect;
|
|
690
|
+
/** @internal */
|
|
691
|
+
constructor(_sandbox: Pick<Sandbox, "run" | "attach">, _disconnect: () => void);
|
|
692
|
+
/** @deprecated Use sandbox.run(). Removed in the next version. */
|
|
693
|
+
start(command: string, options?: SandboxProcessStartOptions): Promise<SandboxProcess>;
|
|
694
|
+
/** @deprecated Use sandbox.attach(). Removed in the next version. */
|
|
695
|
+
connect(processId: string, options?: SandboxProcessConnectOptions): Promise<SandboxProcess>;
|
|
696
|
+
/** Disconnect process transport without terminating guest processes. */
|
|
697
|
+
disconnect(): Promise<void>;
|
|
698
|
+
}
|
|
699
|
+
type ProcessControlRequest = ControlRequest;
|
|
700
|
+
declare class SandboxProcess {
|
|
701
|
+
private readonly _openConnection;
|
|
702
|
+
private readonly _controlProcess;
|
|
703
|
+
/** @internal */
|
|
704
|
+
readonly _core: ProcessCore;
|
|
705
|
+
private readonly _waiters;
|
|
706
|
+
/** Settles once onOutput has handled the last chunk. */
|
|
707
|
+
private _delivered?;
|
|
708
|
+
/** Pull output as it arrives. One iterator, or onOutput, may consume each handle. */
|
|
709
|
+
readonly output: AsyncIterable<SandboxProcessOutput>;
|
|
710
|
+
/** @internal */
|
|
711
|
+
constructor(processId: string, cursor: number, collectOutput: boolean, _openConnection: () => Promise<ChannelCore>, _controlProcess: (request: ProcessControlRequest) => Promise<void>);
|
|
712
|
+
get id(): string;
|
|
713
|
+
/** Next byte after output accepted into the SDK buffer. */
|
|
714
|
+
get cursor(): number;
|
|
715
|
+
get connected(): boolean;
|
|
716
|
+
get status(): SandboxProcessStatus;
|
|
717
|
+
get stdout(): string;
|
|
718
|
+
get stderr(): string;
|
|
719
|
+
/** Resolves once the runtime has accepted the input; waits while the process is not reading. */
|
|
720
|
+
sendInput(data: string | Uint8Array): Promise<void>;
|
|
721
|
+
closeStdin(): Promise<void>;
|
|
722
|
+
resize(size: {
|
|
723
|
+
cols: number;
|
|
724
|
+
rows: number;
|
|
725
|
+
}): Promise<void>;
|
|
726
|
+
kill(): Promise<void>;
|
|
727
|
+
disconnect(): Promise<void>;
|
|
728
|
+
wait(): Promise<SandboxProcessResult>;
|
|
729
|
+
/** @internal Feeds `output` to `handler`, waiting for each call to settle. */
|
|
730
|
+
_deliverTo(handler: SandboxProcessOutputHandler): void;
|
|
731
|
+
private _iterateOutput;
|
|
732
|
+
/** @internal */
|
|
733
|
+
_connect(request: ProcessRequest): Promise<void>;
|
|
734
|
+
/** Resolves on the core's next change. */
|
|
735
|
+
private _change;
|
|
736
|
+
private _until;
|
|
737
|
+
}
|
|
738
|
+
//#endregion
|
|
632
739
|
//#region src/exec-options.d.ts
|
|
633
740
|
/** Network policy for an exec's container, using the sandbox egress rules. */
|
|
634
741
|
type ExecNetwork = Omit<components["schemas"]["ExecNetwork"], "egress"> & {
|
|
635
742
|
egress?: SandboxEgressPolicy;
|
|
636
743
|
};
|
|
637
744
|
/** The image, size, and network of the VM an exec runs in. */
|
|
638
|
-
type ExecVmOptions = Omit<components["schemas"]["ExecDiskRequest"], "command" | "network"> & {
|
|
745
|
+
type ExecVmOptions = Omit<components["schemas"]["ExecDiskRequest"], "command" | "network" | "timeoutSeconds" | "async"> & {
|
|
639
746
|
network?: ExecNetwork;
|
|
640
747
|
};
|
|
641
748
|
//#endregion
|
|
@@ -1061,6 +1168,12 @@ declare class Disk implements FileSystem {
|
|
|
1061
1168
|
readonly region: string;
|
|
1062
1169
|
readonly createdAt: string;
|
|
1063
1170
|
readonly fsHandlerStatus?: string;
|
|
1171
|
+
/**
|
|
1172
|
+
* Latest recorded time a client mounted the disk or refreshed its mount; a
|
|
1173
|
+
* mounted client refreshes every few minutes. Reads and writes do not change it.
|
|
1174
|
+
*/
|
|
1175
|
+
readonly lastMountedAt?: string;
|
|
1176
|
+
/** @deprecated The API no longer returns it; use {@link lastMountedAt}. */
|
|
1064
1177
|
readonly lastAccessed?: string;
|
|
1065
1178
|
readonly activeDataBytes?: number;
|
|
1066
1179
|
readonly totalDataBytes?: number;
|
|
@@ -1731,6 +1844,13 @@ interface ArchilOptions {
|
|
|
1731
1844
|
s3BaseUrl?: string;
|
|
1732
1845
|
/** Per-client TLS trust for control-plane and S3 requests (Node.js only). */
|
|
1733
1846
|
tls?: ArchilTlsOptions;
|
|
1847
|
+
/**
|
|
1848
|
+
* Seconds sandbox create, start, resume, and fork keep retrying while the
|
|
1849
|
+
* region has no capacity, logging a warning, before throwing the 503. Falls
|
|
1850
|
+
* back to ARCHIL_MAX_THROTTLE_WAIT, then 10. `0` throws at once; `Infinity`
|
|
1851
|
+
* waits indefinitely.
|
|
1852
|
+
*/
|
|
1853
|
+
maxThrottleWait?: number;
|
|
1734
1854
|
}
|
|
1735
1855
|
/**
|
|
1736
1856
|
* Options that apply to a single mounted disk in an exec request.
|
|
@@ -1786,12 +1906,21 @@ type ExecMount = Disk | string | ExecMountSpec;
|
|
|
1786
1906
|
interface ExecOptions extends ExecVmOptions {
|
|
1787
1907
|
/**
|
|
1788
1908
|
* Disks to mount, keyed by the relative path under `/mnt/archil` at which
|
|
1789
|
-
* to mount each one.
|
|
1790
|
-
*
|
|
1909
|
+
* to mount each one. Paths must be non-absolute and contain no `.` or `..`
|
|
1910
|
+
* segments. Running without any takes the `workspace:exec` permission.
|
|
1791
1911
|
*/
|
|
1792
|
-
disks
|
|
1912
|
+
disks?: Record<string, ExecMount>;
|
|
1793
1913
|
/** Shell command to run inside the container. */
|
|
1794
1914
|
command: string;
|
|
1915
|
+
/** Set `true` to stream the command's input and output; see {@link ExecStreamOptions}. */
|
|
1916
|
+
stream?: false;
|
|
1917
|
+
}
|
|
1918
|
+
/**
|
|
1919
|
+
* An exec whose input and output stream while it runs. Takes exec's options,
|
|
1920
|
+
* plus the process options `sandbox.run()` takes.
|
|
1921
|
+
*/
|
|
1922
|
+
interface ExecStreamOptions extends Omit<ExecOptions, "stream">, Omit<SandboxProcessStartOptions, "onOutput"> {
|
|
1923
|
+
stream: true;
|
|
1795
1924
|
}
|
|
1796
1925
|
declare class Archil {
|
|
1797
1926
|
readonly disks: Disks;
|
|
@@ -1800,6 +1929,10 @@ declare class Archil {
|
|
|
1800
1929
|
readonly tokens: Tokens;
|
|
1801
1930
|
/** @internal */
|
|
1802
1931
|
private readonly _client;
|
|
1932
|
+
/** @internal Opens control-plane WebSockets for streamed execs. */
|
|
1933
|
+
private readonly _execSocket;
|
|
1934
|
+
/** @internal Created on the first streamed exec. */
|
|
1935
|
+
private _execConnection?;
|
|
1803
1936
|
constructor(opts?: ArchilOptions);
|
|
1804
1937
|
/**
|
|
1805
1938
|
* Run a command in a container with multiple disks mounted simultaneously,
|
|
@@ -1807,6 +1940,23 @@ declare class Archil {
|
|
|
1807
1940
|
* command completes and returns its stdout, stderr, exit code, and timing.
|
|
1808
1941
|
*/
|
|
1809
1942
|
exec(opts: ExecOptions): Promise<ExecDiskResult>;
|
|
1943
|
+
/**
|
|
1944
|
+
* Run a command in a fresh VM and stream its input and output, as
|
|
1945
|
+
* `sandbox.run()` does for a sandbox's processes. Resolves once the command
|
|
1946
|
+
* has started; iterate the handle's `output`, send it input, and `wait()` for
|
|
1947
|
+
* its exit. Concurrent and sequential streamed execs share connections.
|
|
1948
|
+
* `kill()` and `disconnect()` both stop the command and its VM.
|
|
1949
|
+
* Requires Node.js or Bun.
|
|
1950
|
+
*/
|
|
1951
|
+
exec(opts: ExecStreamOptions): Promise<SandboxProcess>;
|
|
1952
|
+
/** @internal */
|
|
1953
|
+
private _execStream;
|
|
1954
|
+
/**
|
|
1955
|
+
* Why the exec endpoint refused a WebSocket, if it did. A refused handshake
|
|
1956
|
+
* reaches the WebSocket as a bare error, so ask with a plain request, which
|
|
1957
|
+
* the endpoint refuses the same way, or answers 426 when nothing refuses it.
|
|
1958
|
+
*/
|
|
1959
|
+
private _execStreamRejection;
|
|
1810
1960
|
/**
|
|
1811
1961
|
* Build an agent filesystem toolset spanning several disks at once. `mounts`
|
|
1812
1962
|
* maps a relative path to a disk (or `ExecMountSpec`), exactly like
|
|
@@ -1817,4 +1967,4 @@ declare class Archil {
|
|
|
1817
1967
|
workspace(mounts: Record<string, ExecMount>): Workspace;
|
|
1818
1968
|
}
|
|
1819
1969
|
//#endregion
|
|
1820
|
-
export {
|
|
1970
|
+
export { effectiveUploadPartSize as $, SandboxNetwork as $t, Disk as A, ExecNetwork as At, MultipartUpload as B, SandboxProcesses as Bt, ListDisksOptions as C, ArchilTlsOptions as Cn, R2Mount as Ct, DeleteObjectsError as D, S3User as Dt, CreateBranchOptions as E, S3Mount as Et, ListMultipartUploadsOptions as F, SandboxProcessOutputHandler as Ft, PartListing as G, Sandbox as Gt, MultipartUploadSummary as H, CreateSandboxPortTokenOptions as Ht, ListObjectsOptions as I, SandboxProcessResult as It, PutObjectResult as J, SandboxEgressTransform as Jt, PosixCreateAttrs as K, SandboxEgressPolicy as Kt, ListObjectsResult as L, SandboxProcessStartOptions as Lt, ExecResult as M, SandboxProcess as Mt, GrepOptions as N, SandboxProcessConnectOptions as Nt, DeleteObjectsOptions as O, TokenUser as Ot, GrepResult as P, SandboxProcessOutput as Pt, UploadPart as Q, SandboxMountSpec as Qt, ListPartsOptions as R, SandboxProcessStatus as Rt, Disks as S, desktopViewerPath as Sn, MountResponse as St, CompletedMultipartUpload as T, S3CompatibleMount as Tt, ObjectMetadata as U, CreatedSandboxPortToken as Ut, MultipartUploadListing as V, SandboxTerminalOptions as Vt, PartInfo as W, ListSandboxPortTokensOptions as Wt, ShareUrlOptions as X, SandboxForkOptions as Xt, S3Object as Y, SandboxEndpoint as Yt, ShareUrlResult as Z, SandboxMount as Zt, ImageStatus as _, DESKTOP_VCPUS as _n, GrepGroupLine as _t, ExecOptions as a, SandboxStatus as an, ConnectedClient as at, CreateDiskResult as b, DesktopScrollDirection as bn, MountConfig as bt, ListTokensOptions as c, SandboxWaitOptions as cn, Delegation as ct, ListSandboxesOptions as d, SandboxFileWriter as dn, DiskStatus as dt, SandboxNetworkAction as en, ApiTokenResponse as et, Sandboxes as f, SandboxFiles as fn, DiskUser as ft, ImageFailureReason as g, DESKTOP_PORT as gn, GrepGroup as gt, Image as h, DESKTOP_MEMORY_MIB as hn, GCSMount as ht, ExecMountSpec as i, SandboxStartOptions as in, Branch as it, DiskMultipart as j, ExecVmOptions as jt, DeleteObjectsResult as k, FileSystem as kt, Tokens as l, SandboxFileSource as ln, DiskMetrics as lt, BuildImageRequest as m, DESKTOP_MAX_TTL_SECONDS as mn, ExecRequest as mt, ArchilOptions as n, SandboxPortTokenPage as nn, AwsStsUser as nt, ExecStreamOptions as o, SandboxTimeoutAction as on, CreateApiTokenRequest as ot, BuildImageOptions as p, DESKTOP_IMAGE as pn, ExecDiskResult as pt, PutObjectOptions as q, SandboxEgressRule as qt, ExecMount as r, SandboxResponse as rn, AzureBlobMount as rt, Workspace as s, SandboxTimeoutOptions as sn, CreateDiskRequest as st, Archil as t, SandboxPortToken as tn, AuthorizedUser as tt, CreateSandboxRequest as u, SandboxFileUploadOptions as un, DiskResponse as ut, Images as v, DesktopMouseButton as vn, GrepMatch as vt, AppendObjectOptions as w, RootAttrs as wt, DiskListPage as x, SandboxDesktop as xn, MountConfigResponse as xt, RegistryAuth as y, DesktopNotInstalledError as yn, GrepStoppedReason as yt, MountOptions as z, SandboxProcessStream as zt };
|