@gigadrive/sdk 0.9.4 → 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 +52 -0
- package/dist/index.d.mts +1262 -4
- package/dist/index.d.ts +1262 -4
- package/dist/index.js +1549 -87
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1525 -87
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -131,6 +131,14 @@ declare class HttpClient {
|
|
|
131
131
|
* @internal
|
|
132
132
|
*/
|
|
133
133
|
fetchRaw(url: string, init: RequestInit): Promise<Response>;
|
|
134
|
+
/**
|
|
135
|
+
* Fetch an arbitrary URL without authentication and without throwing on a
|
|
136
|
+
* non-2xx status, using the client's configured `fetch`. Used to probe
|
|
137
|
+
* public URLs such as microVM preview URLs.
|
|
138
|
+
*
|
|
139
|
+
* @internal
|
|
140
|
+
*/
|
|
141
|
+
fetchPublic(url: string, init?: RequestInit): Promise<Response>;
|
|
134
142
|
private request;
|
|
135
143
|
/** Perform the request with auth injection and a single 401 refresh-retry. */
|
|
136
144
|
private fetchWithAuth;
|
|
@@ -150,6 +158,585 @@ declare class BaseResource {
|
|
|
150
158
|
constructor(httpClient: HttpClient);
|
|
151
159
|
}
|
|
152
160
|
|
|
161
|
+
/**
|
|
162
|
+
* A duration in milliseconds, or a string such as `'500ms'`, `'30s'`, `'10m'`
|
|
163
|
+
* or `'2h'`.
|
|
164
|
+
*
|
|
165
|
+
* Unlike queue durations, a bare number here is **milliseconds**, matching the
|
|
166
|
+
* `timeoutMs` fields of the microVM API.
|
|
167
|
+
*/
|
|
168
|
+
type MicroVmDuration = number | `${number}${'ms' | 's' | 'm' | 'h'}`;
|
|
169
|
+
/**
|
|
170
|
+
* Converts a {@link MicroVmDuration} to whole milliseconds, rounding up.
|
|
171
|
+
*
|
|
172
|
+
* @throws {RangeError} When the value is negative, not finite, or not a recognised duration string.
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```ts
|
|
176
|
+
* durationToMs('10m'); // 600000
|
|
177
|
+
* durationToMs(1500); // 1500
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
declare const durationToMs: (value: MicroVmDuration) => number;
|
|
181
|
+
/** The longest lifetime a microVM can have: 24 hours (plans may allow less). */
|
|
182
|
+
declare const MICROVM_MAX_TIMEOUT_MS: number;
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Wire types of the microVM REST API (`/microvms`, `/microvm-images`).
|
|
186
|
+
*
|
|
187
|
+
* These are the JSON shapes the API returns. The ergonomic {@link MicroVM} and
|
|
188
|
+
* {@link Command} classes wrap them; the low-level `client.microvms` resource
|
|
189
|
+
* returns them as is.
|
|
190
|
+
*/
|
|
191
|
+
/**
|
|
192
|
+
* Lifecycle of a microVM.
|
|
193
|
+
*
|
|
194
|
+
* `pending` (accepted, not placed yet) → `starting` (booting) → `running`
|
|
195
|
+
* (commands, files and ports are available) → `stopping` → `stopped`.
|
|
196
|
+
* `failed` can follow any state that is not terminal. `stopped` and `failed`
|
|
197
|
+
* are terminal. `pausing`, `paused` and `resuming` are reserved for pause and
|
|
198
|
+
* resume.
|
|
199
|
+
*/
|
|
200
|
+
type MicroVmStatus = 'pending' | 'starting' | 'running' | 'pausing' | 'paused' | 'resuming' | 'stopping' | 'stopped' | 'failed';
|
|
201
|
+
/** vCPU counts a microVM can be created with. */
|
|
202
|
+
type MicroVmVcpus = 1 | 2 | 4;
|
|
203
|
+
/** Outbound network policy. Private ranges are always blocked, whatever the policy. */
|
|
204
|
+
type MicroVmEgress = 'allow' | 'deny';
|
|
205
|
+
/** Network policy of a microVM. */
|
|
206
|
+
interface MicroVmNetworkPolicy {
|
|
207
|
+
/** `allow` (default) reaches the internet; `deny` blocks all outbound traffic. */
|
|
208
|
+
egress: MicroVmEgress;
|
|
209
|
+
}
|
|
210
|
+
/** A port exposed by a microVM and its public preview URL. */
|
|
211
|
+
interface MicroVmPort {
|
|
212
|
+
/** Port inside the microVM. */
|
|
213
|
+
port: number;
|
|
214
|
+
/** Public HTTPS URL that forwards to the port, e.g. `https://3000-k3j9x2m1q8zt.vm.gigadrive.app`. */
|
|
215
|
+
url: string;
|
|
216
|
+
}
|
|
217
|
+
/** A microVM as the API returns it. */
|
|
218
|
+
interface MicroVmInfo {
|
|
219
|
+
/** Stable UUID. */
|
|
220
|
+
id: string;
|
|
221
|
+
/** Unguessable label used in preview hostnames (`<port>-<slug>.vm.<domain>`). */
|
|
222
|
+
slug: string;
|
|
223
|
+
applicationId: string;
|
|
224
|
+
organizationId: string;
|
|
225
|
+
status: MicroVmStatus;
|
|
226
|
+
/** The image the microVM booted from. */
|
|
227
|
+
image: {
|
|
228
|
+
id: string;
|
|
229
|
+
name: string;
|
|
230
|
+
};
|
|
231
|
+
vcpus: number;
|
|
232
|
+
memoryMb: number;
|
|
233
|
+
diskMb: number;
|
|
234
|
+
region: string;
|
|
235
|
+
/** Exposed ports with their preview URLs. */
|
|
236
|
+
ports: MicroVmPort[];
|
|
237
|
+
network: MicroVmNetworkPolicy;
|
|
238
|
+
/** Metadata given at create. */
|
|
239
|
+
metadata: Record<string, string>;
|
|
240
|
+
/** Lifetime in milliseconds, as set at create or by the last extension. */
|
|
241
|
+
timeoutMs: number;
|
|
242
|
+
/** ISO 8601 time the microVM stops automatically, or `null` before it started. */
|
|
243
|
+
expiresAt: string | null;
|
|
244
|
+
createdAt: string;
|
|
245
|
+
startedAt: string | null;
|
|
246
|
+
stoppedAt: string | null;
|
|
247
|
+
/** Why the microVM stopped, such as `timeout`, `user`, `host_lost` or `maintenance`. */
|
|
248
|
+
stopReason: string | null;
|
|
249
|
+
}
|
|
250
|
+
/** Body of `POST /microvms`. */
|
|
251
|
+
interface CreateMicroVmInput {
|
|
252
|
+
/**
|
|
253
|
+
* Application the microVM belongs to. Optional when the credentials belong to
|
|
254
|
+
* an application or deployment; the SDK also fills it from the client's
|
|
255
|
+
* `applicationId` or `GIGADRIVE_APPLICATION_ID`.
|
|
256
|
+
*/
|
|
257
|
+
applicationId?: string;
|
|
258
|
+
/** Built-in image name (`node22`, `python3.13`, ...), custom image name, or image id. Default `node22`. */
|
|
259
|
+
image?: string;
|
|
260
|
+
/** Default 1. */
|
|
261
|
+
vcpus?: MicroVmVcpus;
|
|
262
|
+
/** Memory in MiB, 512 to 8192. Default 2048. */
|
|
263
|
+
memoryMb?: number;
|
|
264
|
+
/** Writable disk in MiB, 1024 to 51200. Default 10240. */
|
|
265
|
+
diskMb?: number;
|
|
266
|
+
/** Lifetime in milliseconds before the microVM stops automatically. Default 300000 (5 minutes), at most 24 hours and the plan's maximum. */
|
|
267
|
+
timeoutMs?: number;
|
|
268
|
+
/** Up to 8 ports to expose with public preview URLs (10000 and 10001 are reserved). */
|
|
269
|
+
ports?: number[];
|
|
270
|
+
/** Environment variables for every command. Never stored by the platform. */
|
|
271
|
+
env?: Record<string, string>;
|
|
272
|
+
/** String metadata to tag the microVM with. */
|
|
273
|
+
metadata?: Record<string, string>;
|
|
274
|
+
/** Region to place the microVM in. Defaults to the platform's choice. */
|
|
275
|
+
region?: string;
|
|
276
|
+
network?: MicroVmNetworkPolicy;
|
|
277
|
+
}
|
|
278
|
+
/** Query of `GET /microvms`. */
|
|
279
|
+
interface ListMicroVmsQuery {
|
|
280
|
+
applicationId?: string;
|
|
281
|
+
status?: MicroVmStatus;
|
|
282
|
+
cursor?: string;
|
|
283
|
+
limit?: number;
|
|
284
|
+
}
|
|
285
|
+
/** One page of microVMs. */
|
|
286
|
+
interface MicroVmPage {
|
|
287
|
+
items: MicroVmInfo[];
|
|
288
|
+
/** Pass to the next `list` call to continue; absent on the last page. */
|
|
289
|
+
nextCursor?: string;
|
|
290
|
+
/** Whether another page follows. */
|
|
291
|
+
hasMore: boolean;
|
|
292
|
+
}
|
|
293
|
+
/** Signals that can be sent to a command. */
|
|
294
|
+
type CommandSignal = 'SIGTERM' | 'SIGKILL' | 'SIGINT' | 'SIGHUP' | 'SIGQUIT' | 'SIGUSR1' | 'SIGUSR2';
|
|
295
|
+
/** Size of a pseudo-terminal. */
|
|
296
|
+
interface PtySize {
|
|
297
|
+
cols: number;
|
|
298
|
+
rows: number;
|
|
299
|
+
}
|
|
300
|
+
/** A command as the API returns it. */
|
|
301
|
+
interface CommandInfo {
|
|
302
|
+
/** Command id (`cmd_...`). */
|
|
303
|
+
id: string;
|
|
304
|
+
cmd: string;
|
|
305
|
+
args: string[];
|
|
306
|
+
/** Working directory the command runs in. */
|
|
307
|
+
cwd: string | null;
|
|
308
|
+
/** User the command runs as. */
|
|
309
|
+
user?: string;
|
|
310
|
+
status: 'running' | 'exited';
|
|
311
|
+
/** Exit code, or `null` while running or when a signal killed the process. */
|
|
312
|
+
exitCode: number | null;
|
|
313
|
+
/** Signal that killed the process, such as `SIGKILL`. */
|
|
314
|
+
signal: string | null;
|
|
315
|
+
pid: number | null;
|
|
316
|
+
/** Whether the command runs in a pseudo-terminal. */
|
|
317
|
+
pty: boolean;
|
|
318
|
+
/** Whether the command was killed because it ran past its `timeoutMs`. */
|
|
319
|
+
timedOut: boolean;
|
|
320
|
+
/** ISO 8601 start time. */
|
|
321
|
+
startedAt: string | number;
|
|
322
|
+
finishedAt: string | number | null;
|
|
323
|
+
}
|
|
324
|
+
/** Body of `POST /microvms/:id/commands`. */
|
|
325
|
+
interface StartCommandInput {
|
|
326
|
+
/**
|
|
327
|
+
* Executable to run. Without `args`, a `cmd` containing whitespace runs
|
|
328
|
+
* through `/bin/sh -c` (shell form, e.g. `npm install && npm test`).
|
|
329
|
+
*/
|
|
330
|
+
cmd: string;
|
|
331
|
+
/** Arguments; when present `cmd` is executed directly, without a shell. */
|
|
332
|
+
args?: string[];
|
|
333
|
+
/** Working directory. Defaults to the image's working directory. */
|
|
334
|
+
cwd?: string;
|
|
335
|
+
/** Environment merged over the microVM's environment. */
|
|
336
|
+
env?: Record<string, string>;
|
|
337
|
+
/** User name, `root` or a numeric uid. Defaults to the image's user. */
|
|
338
|
+
user?: string;
|
|
339
|
+
/** Keep stdin open for `POST .../stdin`. Implied by `pty`. */
|
|
340
|
+
stdin?: boolean;
|
|
341
|
+
/** Run in a pseudo-terminal of this size (stdout and stderr are merged). */
|
|
342
|
+
pty?: PtySize;
|
|
343
|
+
/** Kill the command with SIGKILL after this many milliseconds. */
|
|
344
|
+
timeoutMs?: number;
|
|
345
|
+
}
|
|
346
|
+
/** Result of a command run with `wait: true`. */
|
|
347
|
+
interface CommandRunResult {
|
|
348
|
+
id: string;
|
|
349
|
+
exitCode: number | null;
|
|
350
|
+
/** Signal that killed the process, if any. */
|
|
351
|
+
signal: string | null;
|
|
352
|
+
/** Whether the command was killed because it ran past its `timeoutMs`. */
|
|
353
|
+
timedOut: boolean;
|
|
354
|
+
/** UTF-8 decoded stdout, at most 1 MiB. */
|
|
355
|
+
stdout: string;
|
|
356
|
+
/** UTF-8 decoded stderr, at most 1 MiB. */
|
|
357
|
+
stderr: string;
|
|
358
|
+
/** Whether output was left out (over 1 MiB, or no longer retained). */
|
|
359
|
+
truncated: boolean;
|
|
360
|
+
durationMs: number;
|
|
361
|
+
}
|
|
362
|
+
/** Query of `GET /microvms/:id/commands/:cmdId/logs`. */
|
|
363
|
+
interface CommandLogsQuery {
|
|
364
|
+
/** Keep the stream open until the command exits. Default `true`. */
|
|
365
|
+
follow?: boolean;
|
|
366
|
+
/** Absolute stdout byte offset to resume from. Default 0. */
|
|
367
|
+
stdoutOffset?: number;
|
|
368
|
+
/** Absolute stderr byte offset to resume from. Default 0. */
|
|
369
|
+
stderrOffset?: number;
|
|
370
|
+
}
|
|
371
|
+
/** Which output stream a chunk belongs to. */
|
|
372
|
+
type CommandStream = 'stdout' | 'stderr';
|
|
373
|
+
/** One event of a command log stream. */
|
|
374
|
+
type CommandLogEvent = {
|
|
375
|
+
type: 'output';
|
|
376
|
+
stream: CommandStream;
|
|
377
|
+
/** The bytes of this chunk. */
|
|
378
|
+
data: Uint8Array;
|
|
379
|
+
/** Absolute byte offset of the first byte of {@link data} in its stream. */
|
|
380
|
+
offset: number;
|
|
381
|
+
} | {
|
|
382
|
+
/** Output before the requested offsets is no longer retained (each stream keeps its last 8 MiB). */
|
|
383
|
+
type: 'truncated';
|
|
384
|
+
} | {
|
|
385
|
+
/** With `follow: false` on a running command: the buffered output was sent; the command keeps running. */
|
|
386
|
+
type: 'end';
|
|
387
|
+
reason: string;
|
|
388
|
+
} | {
|
|
389
|
+
type: 'exit';
|
|
390
|
+
exitCode: number | null;
|
|
391
|
+
signal: string | null;
|
|
392
|
+
/** The command ran past its timeout. Absent from APIs that predate it. */
|
|
393
|
+
timedOut?: boolean;
|
|
394
|
+
/** When the command exited. Absent from APIs that predate it. */
|
|
395
|
+
finishedAt?: string | null;
|
|
396
|
+
};
|
|
397
|
+
/** Type of a file system entry. */
|
|
398
|
+
type FileEntryType = 'file' | 'directory' | 'symlink' | 'other';
|
|
399
|
+
/** A file or directory inside a microVM. */
|
|
400
|
+
interface FileEntry {
|
|
401
|
+
/** Absolute path. */
|
|
402
|
+
path: string;
|
|
403
|
+
/** Last path segment. */
|
|
404
|
+
name: string;
|
|
405
|
+
type: FileEntryType;
|
|
406
|
+
/** Size in bytes. */
|
|
407
|
+
size: number;
|
|
408
|
+
/** Octal permission bits, e.g. `0644`. */
|
|
409
|
+
mode: string;
|
|
410
|
+
/** ISO 8601 modification time. */
|
|
411
|
+
modifiedAt: string | number;
|
|
412
|
+
/** Link target, for symlinks; otherwise `null`. */
|
|
413
|
+
target?: string | null;
|
|
414
|
+
}
|
|
415
|
+
/** A directory listing. */
|
|
416
|
+
interface FileListing {
|
|
417
|
+
entries: FileEntry[];
|
|
418
|
+
/** The listing hit its size limit; list a narrower directory. */
|
|
419
|
+
truncated: boolean;
|
|
420
|
+
}
|
|
421
|
+
/** Result of a file write. */
|
|
422
|
+
interface FileWriteResult {
|
|
423
|
+
path: string;
|
|
424
|
+
/** Bytes written. */
|
|
425
|
+
bytes: number;
|
|
426
|
+
}
|
|
427
|
+
/** Where a custom image comes from. */
|
|
428
|
+
type MicroVmImageSource = {
|
|
429
|
+
type: 'registry';
|
|
430
|
+
ref: string;
|
|
431
|
+
} | {
|
|
432
|
+
type: 'dockerfile';
|
|
433
|
+
dockerfile: string;
|
|
434
|
+
};
|
|
435
|
+
/** Build state of an image. A new image starts `pending`. */
|
|
436
|
+
type MicroVmImageStatus = 'pending' | 'building' | 'ready' | 'failed';
|
|
437
|
+
/** A bootable microVM image. Built-in images have no application. */
|
|
438
|
+
interface MicroVmImage {
|
|
439
|
+
id: string;
|
|
440
|
+
/** Name to pass as `image` when creating a microVM. */
|
|
441
|
+
name: string;
|
|
442
|
+
builtin: boolean;
|
|
443
|
+
status: MicroVmImageStatus;
|
|
444
|
+
applicationId: string | null;
|
|
445
|
+
organizationId: string | null;
|
|
446
|
+
source?: MicroVmImageSource | null;
|
|
447
|
+
/** Registry digest the build resolved. */
|
|
448
|
+
sourceDigest?: string | null;
|
|
449
|
+
/** Size of the unpacked root filesystem. */
|
|
450
|
+
sizeBytes?: number | null;
|
|
451
|
+
/** Why the last build failed. */
|
|
452
|
+
error?: string | null;
|
|
453
|
+
buildStartedAt?: string | null;
|
|
454
|
+
buildFinishedAt?: string | null;
|
|
455
|
+
createdAt?: string;
|
|
456
|
+
updatedAt?: string;
|
|
457
|
+
}
|
|
458
|
+
/** Body of `POST /microvm-images`. */
|
|
459
|
+
interface CreateMicroVmImageInput {
|
|
460
|
+
/** Owning application. Filled from the client's default application when omitted. */
|
|
461
|
+
applicationId?: string;
|
|
462
|
+
/** `^[a-z0-9][a-z0-9._-]{0,62}$`, unique per application. */
|
|
463
|
+
name: string;
|
|
464
|
+
/**
|
|
465
|
+
* The image to build: a public `linux/amd64` registry reference such as
|
|
466
|
+
* `python:3.13` or `ghcr.io/acme/tool:1`, or `{ dockerfile }` with the
|
|
467
|
+
* Dockerfile contents. Shorthand for {@link source}.
|
|
468
|
+
*/
|
|
469
|
+
from?: string | {
|
|
470
|
+
dockerfile: string;
|
|
471
|
+
} | {
|
|
472
|
+
registry: string;
|
|
473
|
+
};
|
|
474
|
+
/** Raw API source. Use this or {@link from}. */
|
|
475
|
+
source?: MicroVmImageSource;
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
/** Options of a resumable command log stream. */
|
|
479
|
+
interface CommandLogStreamOptions {
|
|
480
|
+
/** Keep streaming until the command exits. Default `true`. */
|
|
481
|
+
follow?: boolean;
|
|
482
|
+
/** Absolute stdout offset to start from. Default 0. */
|
|
483
|
+
stdoutOffset?: number;
|
|
484
|
+
/** Absolute stderr offset to start from. Default 0. */
|
|
485
|
+
stderrOffset?: number;
|
|
486
|
+
/**
|
|
487
|
+
* Reconnect after a dropped connection, resuming from the last received
|
|
488
|
+
* offsets. Default `true`. Set to `false` to see exactly one connection.
|
|
489
|
+
*/
|
|
490
|
+
reconnect?: boolean;
|
|
491
|
+
/**
|
|
492
|
+
* How many reconnects in a row may fail to deliver anything before the
|
|
493
|
+
* stream gives up and throws. Default 5.
|
|
494
|
+
*/
|
|
495
|
+
maxReconnectAttempts?: number;
|
|
496
|
+
/** Cancels the stream. */
|
|
497
|
+
signal?: AbortSignal;
|
|
498
|
+
/**
|
|
499
|
+
* Called when a following connection closes without an `exit` event. Return
|
|
500
|
+
* the exit status if the command has exited (the stream then ends with it),
|
|
501
|
+
* or `null` to reconnect.
|
|
502
|
+
*/
|
|
503
|
+
resolveExit?: () => Promise<{
|
|
504
|
+
exitCode: number | null;
|
|
505
|
+
signal: string | null;
|
|
506
|
+
} | null>;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
/** Content accepted by file writes: text (UTF-8), bytes, a `Blob`/`File`, or a web `ReadableStream`. */
|
|
510
|
+
type MicroVmFileContent = string | Uint8Array | ArrayBuffer | Blob | ReadableStream<Uint8Array>;
|
|
511
|
+
/** Per-call request options. */
|
|
512
|
+
interface MicroVmRequestOptions {
|
|
513
|
+
/** Cancels the request. */
|
|
514
|
+
signal?: AbortSignal;
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* Commands inside a microVM: `client.microvms.commands`. Every method maps to
|
|
518
|
+
* one route of `/microvms/:id/commands`. For a friendlier API use
|
|
519
|
+
* {@link MicroVM.run} and {@link MicroVM.spawn}.
|
|
520
|
+
*/
|
|
521
|
+
declare class MicroVmCommandsResource extends BaseResource {
|
|
522
|
+
/**
|
|
523
|
+
* Run a command and wait for it to exit (`POST /microvms/:id/commands`, `wait: true`).
|
|
524
|
+
*
|
|
525
|
+
* @example
|
|
526
|
+
* ```ts
|
|
527
|
+
* const { exitCode, stdout } = await client.microvms.commands.run(id, { cmd: 'node', args: ['-v'] });
|
|
528
|
+
* ```
|
|
529
|
+
*/
|
|
530
|
+
run(microvmId: string, input: StartCommandInput, options?: MicroVmRequestOptions): Promise<CommandRunResult>;
|
|
531
|
+
/**
|
|
532
|
+
* Start a detached command and return at once (`POST /microvms/:id/commands`, `wait: false`).
|
|
533
|
+
* Follow its output with {@link logs}.
|
|
534
|
+
*/
|
|
535
|
+
start(microvmId: string, input: StartCommandInput, options?: MicroVmRequestOptions): Promise<CommandInfo>;
|
|
536
|
+
/** List the microVM's commands, newest first (`GET /microvms/:id/commands`). */
|
|
537
|
+
list(microvmId: string, options?: MicroVmRequestOptions): Promise<CommandInfo[]>;
|
|
538
|
+
/** Get one command (`GET /microvms/:id/commands/:cmdId`). */
|
|
539
|
+
get(microvmId: string, commandId: string, options?: MicroVmRequestOptions): Promise<CommandInfo>;
|
|
540
|
+
/**
|
|
541
|
+
* Stream a command's output (`GET /microvms/:id/commands/:cmdId/logs`, SSE).
|
|
542
|
+
*
|
|
543
|
+
* Yields `output` events with the raw bytes and a final `exit` event. A
|
|
544
|
+
* dropped connection is reopened from the last received offsets, so no byte
|
|
545
|
+
* is lost or repeated; pass `reconnect: false` to disable that.
|
|
546
|
+
*
|
|
547
|
+
* @example
|
|
548
|
+
* ```ts
|
|
549
|
+
* for await (const event of client.microvms.commands.logs(id, commandId)) {
|
|
550
|
+
* if (event.type === 'output') process.stdout.write(event.data);
|
|
551
|
+
* else console.log('exit', event.exitCode);
|
|
552
|
+
* }
|
|
553
|
+
* ```
|
|
554
|
+
*/
|
|
555
|
+
logs(microvmId: string, commandId: string, options?: CommandLogStreamOptions): AsyncGenerator<CommandLogEvent>;
|
|
556
|
+
/**
|
|
557
|
+
* Wait up to `timeoutMs` (at most 60000) for the command to exit
|
|
558
|
+
* (`POST /microvms/:id/commands/:cmdId/wait`). The returned command is still
|
|
559
|
+
* `running` when the wait timed out.
|
|
560
|
+
*/
|
|
561
|
+
wait(microvmId: string, commandId: string, options?: {
|
|
562
|
+
timeoutMs?: number;
|
|
563
|
+
} & MicroVmRequestOptions): Promise<CommandInfo>;
|
|
564
|
+
/**
|
|
565
|
+
* Write to the command's stdin (`POST /microvms/:id/commands/:cmdId/stdin`).
|
|
566
|
+
* The command must have been started with `stdin: true` or a `pty`.
|
|
567
|
+
*
|
|
568
|
+
* @param options.eof - Close stdin after writing.
|
|
569
|
+
*/
|
|
570
|
+
stdin(microvmId: string, commandId: string, data: string | Uint8Array | ArrayBuffer | Blob, options?: {
|
|
571
|
+
eof?: boolean;
|
|
572
|
+
} & MicroVmRequestOptions): Promise<void>;
|
|
573
|
+
/** Send a signal to the command's process group (`POST /microvms/:id/commands/:cmdId/signal`). */
|
|
574
|
+
signal(microvmId: string, commandId: string, signal: CommandSignal, options?: MicroVmRequestOptions): Promise<void>;
|
|
575
|
+
/** Resize a PTY command's terminal (`POST /microvms/:id/commands/:cmdId/resize`). */
|
|
576
|
+
resize(microvmId: string, commandId: string, size: PtySize, options?: MicroVmRequestOptions): Promise<void>;
|
|
577
|
+
}
|
|
578
|
+
/** Options of a file read. */
|
|
579
|
+
interface ReadFileOptions extends MicroVmRequestOptions {
|
|
580
|
+
/** Byte offset to start reading at. */
|
|
581
|
+
offset?: number;
|
|
582
|
+
/** Maximum number of bytes to read. */
|
|
583
|
+
length?: number;
|
|
584
|
+
}
|
|
585
|
+
/** Options of a file write. */
|
|
586
|
+
interface WriteFileOptions extends MicroVmRequestOptions {
|
|
587
|
+
/** Permission bits, as an octal string (`'0755'`) or number (`0o755`). Default `0644`. */
|
|
588
|
+
mode?: string | number;
|
|
589
|
+
/** Create missing parent directories. Default `true`. */
|
|
590
|
+
mkdirs?: boolean;
|
|
591
|
+
}
|
|
592
|
+
/**
|
|
593
|
+
* Files inside a microVM: `client.microvms.files`. Every method maps to one
|
|
594
|
+
* route of `/microvms/:id/files`. `vm.files` on a {@link MicroVM} binds the id.
|
|
595
|
+
* Relative paths resolve against the user's home directory.
|
|
596
|
+
*/
|
|
597
|
+
declare class MicroVmFilesResource extends BaseResource {
|
|
598
|
+
/** Read a file as bytes (`GET /microvms/:id/files/content`). */
|
|
599
|
+
read(microvmId: string, path: string, options?: ReadFileOptions): Promise<Uint8Array>;
|
|
600
|
+
/** Read a file as a stream of bytes, without buffering it (`GET /microvms/:id/files/content`). */
|
|
601
|
+
readStream(microvmId: string, path: string, options?: ReadFileOptions): Promise<ReadableStream<Uint8Array>>;
|
|
602
|
+
/**
|
|
603
|
+
* Write a file, replacing it atomically (`PUT /microvms/:id/files/content`).
|
|
604
|
+
* Missing parent directories are created unless `mkdirs: false`.
|
|
605
|
+
*/
|
|
606
|
+
write(microvmId: string, path: string, content: MicroVmFileContent, options?: WriteFileOptions): Promise<FileWriteResult>;
|
|
607
|
+
/**
|
|
608
|
+
* List a directory (`GET /microvms/:id/files`). `truncated` is set when the
|
|
609
|
+
* listing hit its size limit; list a narrower directory then.
|
|
610
|
+
*/
|
|
611
|
+
list(microvmId: string, path: string, options?: {
|
|
612
|
+
recursive?: boolean;
|
|
613
|
+
depth?: number;
|
|
614
|
+
} & MicroVmRequestOptions): Promise<FileListing>;
|
|
615
|
+
/** Describe a file or directory without following a final symlink (`GET /microvms/:id/files/stat`). */
|
|
616
|
+
stat(microvmId: string, path: string, options?: MicroVmRequestOptions): Promise<FileEntry>;
|
|
617
|
+
/** Create a directory, with its parents unless `parents: false` (`POST /microvms/:id/files/mkdir`). */
|
|
618
|
+
mkdir(microvmId: string, path: string, options?: {
|
|
619
|
+
parents?: boolean;
|
|
620
|
+
} & MicroVmRequestOptions): Promise<FileEntry>;
|
|
621
|
+
/** Move or rename a file or directory (`POST /microvms/:id/files/move`). */
|
|
622
|
+
move(microvmId: string, from: string, to: string, options?: MicroVmRequestOptions): Promise<FileEntry>;
|
|
623
|
+
/** Delete a file, or a directory (non-empty ones need `recursive`) (`DELETE /microvms/:id/files`). */
|
|
624
|
+
remove(microvmId: string, path: string, options?: {
|
|
625
|
+
recursive?: boolean;
|
|
626
|
+
} & MicroVmRequestOptions): Promise<void>;
|
|
627
|
+
private open;
|
|
628
|
+
}
|
|
629
|
+
/** Options of {@link MicroVmImagesResource.waitUntilReady}. */
|
|
630
|
+
interface WaitForImageOptions extends MicroVmRequestOptions {
|
|
631
|
+
/** Give up after this long. Default `'15m'`. */
|
|
632
|
+
timeout?: MicroVmDuration;
|
|
633
|
+
/** Pause between polls. Default `'2s'`. */
|
|
634
|
+
interval?: MicroVmDuration;
|
|
635
|
+
/** Called whenever the polled status changes. */
|
|
636
|
+
onStatus?: (image: MicroVmImage) => void;
|
|
637
|
+
}
|
|
638
|
+
/**
|
|
639
|
+
* microVM images: `client.microvms.images`. Built-in images (`node22`,
|
|
640
|
+
* `node24`, `python3.13`, `python3.12`, `bun1`, `debian12`, `ubuntu24.04`)
|
|
641
|
+
* are always available; custom images are built from a registry reference or
|
|
642
|
+
* a Dockerfile.
|
|
643
|
+
*/
|
|
644
|
+
declare class MicroVmImagesResource extends BaseResource {
|
|
645
|
+
private readonly defaultApplicationId;
|
|
646
|
+
constructor(httpClient: HttpClient, defaultApplicationId?: string);
|
|
647
|
+
/** List the built-in images and the application's custom images (`GET /microvm-images`). */
|
|
648
|
+
list(query?: {
|
|
649
|
+
applicationId?: string;
|
|
650
|
+
}, options?: MicroVmRequestOptions): Promise<MicroVmImage[]>;
|
|
651
|
+
/**
|
|
652
|
+
* Start building a custom image (`POST /microvm-images`). The image is
|
|
653
|
+
* `building` until {@link waitUntilReady} resolves.
|
|
654
|
+
*
|
|
655
|
+
* @example
|
|
656
|
+
* ```ts
|
|
657
|
+
* const image = await client.microvms.images.create({ name: 'py-ml', from: 'python:3.13' });
|
|
658
|
+
* await client.microvms.images.waitUntilReady(image.id);
|
|
659
|
+
* const vm = await MicroVM.create({ image: 'py-ml' });
|
|
660
|
+
* ```
|
|
661
|
+
*/
|
|
662
|
+
create(input: CreateMicroVmImageInput, options?: MicroVmRequestOptions): Promise<MicroVmImage>;
|
|
663
|
+
/** Get one image (`GET /microvm-images/:id`). */
|
|
664
|
+
get(imageId: string, options?: MicroVmRequestOptions): Promise<MicroVmImage>;
|
|
665
|
+
/** Delete a custom image (`DELETE /microvm-images/:id`). */
|
|
666
|
+
delete(imageId: string, options?: MicroVmRequestOptions): Promise<void>;
|
|
667
|
+
/**
|
|
668
|
+
* Poll an image until its build finished.
|
|
669
|
+
*
|
|
670
|
+
* @throws {@link MicroVmImageBuildError} when the build failed.
|
|
671
|
+
* @throws {@link MicroVmTimeoutError} when it is still building after `timeout`.
|
|
672
|
+
*/
|
|
673
|
+
waitUntilReady(imageId: string, options?: WaitForImageOptions): Promise<MicroVmImage>;
|
|
674
|
+
}
|
|
675
|
+
/**
|
|
676
|
+
* The microVM REST API: `client.microvms`. Every method maps to exactly one
|
|
677
|
+
* route; responses are the raw JSON shapes. Most code wants the ergonomic
|
|
678
|
+
* {@link MicroVM} class instead (`MicroVM.create`, `vm.run`, `vm.files`).
|
|
679
|
+
*
|
|
680
|
+
* @example
|
|
681
|
+
* ```ts
|
|
682
|
+
* const client = new GigadriveClient();
|
|
683
|
+
* const vm = await client.microvms.create({ image: 'python3.13', ports: [8000] });
|
|
684
|
+
* const result = await client.microvms.commands.run(vm.id, { cmd: 'python3 --version' });
|
|
685
|
+
* await client.microvms.delete(vm.id);
|
|
686
|
+
* ```
|
|
687
|
+
*/
|
|
688
|
+
declare class MicroVmsResource extends BaseResource {
|
|
689
|
+
/** Commands: run, start, logs, wait, stdin, signal, resize. */
|
|
690
|
+
readonly commands: MicroVmCommandsResource;
|
|
691
|
+
/** Files: read, write, list, stat, mkdir, move, remove. */
|
|
692
|
+
readonly files: MicroVmFilesResource;
|
|
693
|
+
/** Built-in and custom images. */
|
|
694
|
+
readonly images: MicroVmImagesResource;
|
|
695
|
+
private readonly defaultApplicationId;
|
|
696
|
+
constructor(httpClient: HttpClient, defaultApplicationId?: string);
|
|
697
|
+
/**
|
|
698
|
+
* Create a microVM (`POST /microvms`). Resolves once it is `running`; with
|
|
699
|
+
* `wait: false` it resolves at once with a `starting` microVM.
|
|
700
|
+
*
|
|
701
|
+
* `applicationId` defaults to the client's `applicationId` or
|
|
702
|
+
* `GIGADRIVE_APPLICATION_ID`, and may be omitted entirely with application
|
|
703
|
+
* or deployment credentials.
|
|
704
|
+
*/
|
|
705
|
+
create(input?: CreateMicroVmInput, options?: {
|
|
706
|
+
wait?: boolean;
|
|
707
|
+
} & MicroVmRequestOptions): Promise<MicroVmInfo>;
|
|
708
|
+
/** List one page of microVMs, newest first (`GET /microvms`). */
|
|
709
|
+
list(query?: ListMicroVmsQuery, options?: MicroVmRequestOptions): Promise<MicroVmPage>;
|
|
710
|
+
/**
|
|
711
|
+
* Iterate every microVM across all pages.
|
|
712
|
+
*
|
|
713
|
+
* @example
|
|
714
|
+
* ```ts
|
|
715
|
+
* for await (const vm of client.microvms.listAll({ status: 'running' })) console.log(vm.id);
|
|
716
|
+
* ```
|
|
717
|
+
*/
|
|
718
|
+
listAll(query?: Omit<ListMicroVmsQuery, 'cursor'>, options?: MicroVmRequestOptions): AsyncGenerator<MicroVmInfo>;
|
|
719
|
+
/** Get one microVM (`GET /microvms/:id`). */
|
|
720
|
+
get(microvmId: string, options?: MicroVmRequestOptions): Promise<MicroVmInfo>;
|
|
721
|
+
/**
|
|
722
|
+
* Set the remaining lifetime to `timeoutMs` from now (`POST /microvms/:id/timeout`),
|
|
723
|
+
* up to the plan's maximum lifetime.
|
|
724
|
+
*/
|
|
725
|
+
extendTimeout(microvmId: string, timeoutMs: number, options?: MicroVmRequestOptions): Promise<MicroVmInfo>;
|
|
726
|
+
/** Stop a microVM (`POST /microvms/:id/stop`). Its disk and memory are discarded. */
|
|
727
|
+
stop(microvmId: string, options?: MicroVmRequestOptions): Promise<MicroVmInfo>;
|
|
728
|
+
/** Delete a microVM, stopping it first if needed (`DELETE /microvms/:id`). */
|
|
729
|
+
delete(microvmId: string, options?: MicroVmRequestOptions): Promise<void>;
|
|
730
|
+
/**
|
|
731
|
+
* Request a public preview URL with the client's `fetch`, without
|
|
732
|
+
* credentials and without throwing on error statuses. Used by
|
|
733
|
+
* `MicroVM.waitForPort`.
|
|
734
|
+
*
|
|
735
|
+
* @internal
|
|
736
|
+
*/
|
|
737
|
+
fetchPreview(url: string, init?: RequestInit): Promise<Response>;
|
|
738
|
+
}
|
|
739
|
+
|
|
153
740
|
/**
|
|
154
741
|
* Types for the AI Gateway runtime endpoints (`/ai/v1`). The chat/responses
|
|
155
742
|
* shapes are OpenAI-compatible; additional fields are passed through, so request
|
|
@@ -3998,9 +4585,652 @@ declare class GigadriveClient {
|
|
|
3998
4585
|
* handle bound to one queue.
|
|
3999
4586
|
*/
|
|
4000
4587
|
readonly queues: QueuesResource;
|
|
4588
|
+
/**
|
|
4589
|
+
* microVMs: isolated Linux machines to run commands in, move files to and
|
|
4590
|
+
* from, and expose ports from. This is the low-level REST surface; the
|
|
4591
|
+
* {@link MicroVM} class (`MicroVM.create({ client })`) is the friendlier API.
|
|
4592
|
+
*/
|
|
4593
|
+
readonly microvms: MicroVmsResource;
|
|
4001
4594
|
constructor(config?: GigadriveClientConfig);
|
|
4002
4595
|
}
|
|
4003
4596
|
|
|
4597
|
+
/** One chunk of command output. */
|
|
4598
|
+
interface CommandLogChunk {
|
|
4599
|
+
/** `stdout` or `stderr`. PTY commands write everything to `stdout`. */
|
|
4600
|
+
stream: CommandStream;
|
|
4601
|
+
/** The raw bytes. */
|
|
4602
|
+
data: Uint8Array;
|
|
4603
|
+
/**
|
|
4604
|
+
* The bytes decoded as UTF-8. A multi-byte character split across two
|
|
4605
|
+
* chunks is completed in the later chunk, so concatenating `text` is safe.
|
|
4606
|
+
*/
|
|
4607
|
+
text: string;
|
|
4608
|
+
/** Absolute byte offset of the chunk in its stream. */
|
|
4609
|
+
offset: number;
|
|
4610
|
+
}
|
|
4611
|
+
/** Options of {@link Command.logs}. */
|
|
4612
|
+
interface CommandLogsOptions {
|
|
4613
|
+
/** Keep streaming until the command exits. Default `true`; `false` returns what is buffered. */
|
|
4614
|
+
follow?: boolean;
|
|
4615
|
+
/** Start at these absolute offsets instead of the beginning of the retained output. */
|
|
4616
|
+
stdoutOffset?: number;
|
|
4617
|
+
stderrOffset?: number;
|
|
4618
|
+
/** Stops the stream; the iterator then throws the abort reason. */
|
|
4619
|
+
signal?: AbortSignal;
|
|
4620
|
+
}
|
|
4621
|
+
/** Options of {@link Command.wait}. */
|
|
4622
|
+
interface CommandWaitOptions {
|
|
4623
|
+
/** Give up after this long (milliseconds or `'5m'`). Default: wait indefinitely. */
|
|
4624
|
+
timeout?: MicroVmDuration;
|
|
4625
|
+
/** Throw {@link CommandFailedError} when the command exits non-zero or is killed. */
|
|
4626
|
+
throwOnError?: boolean;
|
|
4627
|
+
signal?: AbortSignal;
|
|
4628
|
+
}
|
|
4629
|
+
/** Receives output while a command runs. Returning a promise applies backpressure. */
|
|
4630
|
+
type CommandOutputCallback = (text: string, chunk: CommandLogChunk) => void | Promise<void>;
|
|
4631
|
+
/**
|
|
4632
|
+
* A command running (or finished) inside a microVM. Get one from
|
|
4633
|
+
* {@link MicroVM.spawn} or reattach with `vm.commands.get(id)`.
|
|
4634
|
+
*
|
|
4635
|
+
* Output stays in the microVM (the last 8 MiB of each stream), so any number
|
|
4636
|
+
* of {@link logs} readers can replay it, from any process, and a dropped
|
|
4637
|
+
* connection resumes where it stopped.
|
|
4638
|
+
*
|
|
4639
|
+
* @example
|
|
4640
|
+
* ```ts
|
|
4641
|
+
* const server = await vm.spawn('node', ['server.js']);
|
|
4642
|
+
* for await (const chunk of server.logs()) {
|
|
4643
|
+
* process.stdout.write(chunk.text);
|
|
4644
|
+
* if (chunk.text.includes('listening')) break;
|
|
4645
|
+
* }
|
|
4646
|
+
* await vm.waitForPort(3000);
|
|
4647
|
+
* await server.kill();
|
|
4648
|
+
* ```
|
|
4649
|
+
*/
|
|
4650
|
+
declare class Command {
|
|
4651
|
+
private readonly resource;
|
|
4652
|
+
/** The microVM this command runs in. */
|
|
4653
|
+
readonly microvmId: string;
|
|
4654
|
+
private current;
|
|
4655
|
+
private pump;
|
|
4656
|
+
private pumpError;
|
|
4657
|
+
private skippedOutput;
|
|
4658
|
+
/** @internal Use {@link MicroVM.spawn} or `vm.commands.get(id)`. */
|
|
4659
|
+
constructor(resource: MicroVmCommandsResource,
|
|
4660
|
+
/** The microVM this command runs in. */
|
|
4661
|
+
microvmId: string, info: CommandInfo);
|
|
4662
|
+
/** Command id (`cmd_...`). Pass it to `vm.commands.get(id)` to reattach later. */
|
|
4663
|
+
get id(): string;
|
|
4664
|
+
/** The latest known state. Updated by {@link refresh}, {@link wait} and the end of {@link logs}. */
|
|
4665
|
+
get info(): CommandInfo;
|
|
4666
|
+
get status(): CommandInfo['status'];
|
|
4667
|
+
/** Exit code once exited; `null` while running or when a signal killed it. */
|
|
4668
|
+
get exitCode(): number | null;
|
|
4669
|
+
/** Signal that killed the process, if any. */
|
|
4670
|
+
get signal(): string | null;
|
|
4671
|
+
get pid(): number | null;
|
|
4672
|
+
/** Whether the command was killed because it ran past its `timeout`. */
|
|
4673
|
+
get timedOut(): boolean;
|
|
4674
|
+
/**
|
|
4675
|
+
* Whether a {@link logs} read found older output already dropped (each
|
|
4676
|
+
* stream keeps its last 8 MiB), so what it delivered starts mid-stream.
|
|
4677
|
+
*/
|
|
4678
|
+
get truncated(): boolean;
|
|
4679
|
+
/** Fetch the latest state from the API. */
|
|
4680
|
+
refresh(): Promise<CommandInfo>;
|
|
4681
|
+
/**
|
|
4682
|
+
* Stream the command's output, from the beginning of the retained output by
|
|
4683
|
+
* default, until it exits. With `follow: false` it delivers what is
|
|
4684
|
+
* buffered and ends, even while the command keeps running. Reconnects transparently after a dropped
|
|
4685
|
+
* connection. Breaking out of the loop closes the stream; the command keeps
|
|
4686
|
+
* running.
|
|
4687
|
+
*
|
|
4688
|
+
* @example
|
|
4689
|
+
* ```ts
|
|
4690
|
+
* for await (const { stream, text } of command.logs()) {
|
|
4691
|
+
* (stream === 'stdout' ? process.stdout : process.stderr).write(text);
|
|
4692
|
+
* }
|
|
4693
|
+
* ```
|
|
4694
|
+
*/
|
|
4695
|
+
logs(options?: CommandLogsOptions): AsyncGenerator<CommandLogChunk>;
|
|
4696
|
+
/**
|
|
4697
|
+
* Collect the output from the start until the command exits.
|
|
4698
|
+
*
|
|
4699
|
+
* @example
|
|
4700
|
+
* ```ts
|
|
4701
|
+
* const { stdout } = await (await vm.spawn('ls', ['-la'])).output();
|
|
4702
|
+
* ```
|
|
4703
|
+
*/
|
|
4704
|
+
output(options?: Pick<CommandLogsOptions, 'signal'>): Promise<{
|
|
4705
|
+
stdout: string;
|
|
4706
|
+
stderr: string;
|
|
4707
|
+
}>;
|
|
4708
|
+
/** The complete stdout as text, once the command exited. */
|
|
4709
|
+
stdout(options?: Pick<CommandLogsOptions, 'signal'>): Promise<string>;
|
|
4710
|
+
/** The complete stderr as text, once the command exited. */
|
|
4711
|
+
stderr(options?: Pick<CommandLogsOptions, 'signal'>): Promise<string>;
|
|
4712
|
+
/**
|
|
4713
|
+
* Wait for the command to exit and return its final state. Output callbacks
|
|
4714
|
+
* given to `spawn` have received all output when this resolves.
|
|
4715
|
+
*
|
|
4716
|
+
* @throws {@link MicroVmTimeoutError} when `timeout` elapses first (the command keeps running).
|
|
4717
|
+
* @throws {@link CommandFailedError} with `throwOnError` when it exits non-zero or is killed.
|
|
4718
|
+
*/
|
|
4719
|
+
wait(options?: CommandWaitOptions): Promise<CommandInfo>;
|
|
4720
|
+
/**
|
|
4721
|
+
* Send a signal to the command's process group. Default `SIGTERM`; use
|
|
4722
|
+
* `SIGKILL` to stop it unconditionally.
|
|
4723
|
+
*/
|
|
4724
|
+
kill(signal?: CommandSignal): Promise<void>;
|
|
4725
|
+
/**
|
|
4726
|
+
* Write to stdin. The command must have been spawned with `stdin: true` or a `pty`.
|
|
4727
|
+
*
|
|
4728
|
+
* @example
|
|
4729
|
+
* ```ts
|
|
4730
|
+
* const cat = await vm.spawn('cat', [], { stdin: true });
|
|
4731
|
+
* await cat.write('hello\n');
|
|
4732
|
+
* await cat.end();
|
|
4733
|
+
* console.log(await cat.stdout()); // "hello\n"
|
|
4734
|
+
* ```
|
|
4735
|
+
*/
|
|
4736
|
+
write(data: string | Uint8Array): Promise<void>;
|
|
4737
|
+
/** Close stdin, optionally writing a last piece of data first. */
|
|
4738
|
+
end(data?: string | Uint8Array): Promise<void>;
|
|
4739
|
+
/** Resize the terminal of a PTY command. */
|
|
4740
|
+
resize(cols: number, rows: number): Promise<void>;
|
|
4741
|
+
/** JSON form: the command's latest state. */
|
|
4742
|
+
toJSON(): CommandInfo;
|
|
4743
|
+
/**
|
|
4744
|
+
* Deliver output to callbacks in the background, for `spawn` with
|
|
4745
|
+
* `onStdout`/`onStderr`. {@link wait} waits for it and rethrows its error.
|
|
4746
|
+
*
|
|
4747
|
+
* @internal
|
|
4748
|
+
*/
|
|
4749
|
+
startOutputPump(onStdout: CommandOutputCallback | undefined, onStderr: CommandOutputCallback | undefined): void;
|
|
4750
|
+
}
|
|
4751
|
+
|
|
4752
|
+
/**
|
|
4753
|
+
* The microVM is not `running` (it is still starting, or it stopped or
|
|
4754
|
+
* failed), so commands, files and preview URLs are unavailable. The API
|
|
4755
|
+
* answers `409 microvm_not_running`.
|
|
4756
|
+
*
|
|
4757
|
+
* @example
|
|
4758
|
+
* ```ts
|
|
4759
|
+
* try {
|
|
4760
|
+
* await vm.run('ls');
|
|
4761
|
+
* } catch (err) {
|
|
4762
|
+
* if (err instanceof MicroVmNotRunningError) await vm.refresh();
|
|
4763
|
+
* }
|
|
4764
|
+
* ```
|
|
4765
|
+
*/
|
|
4766
|
+
declare class MicroVmNotRunningError extends ApiError {
|
|
4767
|
+
constructor(message?: string, code?: string, reason?: string);
|
|
4768
|
+
}
|
|
4769
|
+
/** The microVM, command or image does not exist, or the credentials cannot see it (`404`). */
|
|
4770
|
+
declare class MicroVmNotFoundError extends ApiError {
|
|
4771
|
+
constructor(message?: string, code?: string, reason?: string);
|
|
4772
|
+
}
|
|
4773
|
+
/** A file or directory does not exist inside the microVM (`404` from a file route). */
|
|
4774
|
+
declare class MicroVmFileNotFoundError extends MicroVmNotFoundError {
|
|
4775
|
+
/** The path that was not found. */
|
|
4776
|
+
readonly path: string;
|
|
4777
|
+
constructor(path: string, message?: string, code?: string);
|
|
4778
|
+
}
|
|
4779
|
+
/**
|
|
4780
|
+
* The microVM is too busy to take the operation right now (`429`/`503`
|
|
4781
|
+
* `microvm_busy`). Reads and log streams are retried with backoff before this
|
|
4782
|
+
* surfaces; retry later.
|
|
4783
|
+
*/
|
|
4784
|
+
declare class MicroVmBusyError extends ApiError {
|
|
4785
|
+
constructor(message: string, status: number, code?: string, reason?: string);
|
|
4786
|
+
}
|
|
4787
|
+
/** The platform could not reach the microVM (`502 microvm_unreachable`). Usually transient. */
|
|
4788
|
+
declare class MicroVmUnreachableError extends ApiError {
|
|
4789
|
+
constructor(message: string, code?: string, reason?: string);
|
|
4790
|
+
}
|
|
4791
|
+
/** The image is still building or failed to build, so no microVM can boot from it yet (`409 image_not_ready`). */
|
|
4792
|
+
declare class MicroVmImageNotReadyError extends ApiError {
|
|
4793
|
+
constructor(message: string, code?: string, reason?: string);
|
|
4794
|
+
}
|
|
4795
|
+
/**
|
|
4796
|
+
* A plan limit or quota was reached, such as the number of concurrent
|
|
4797
|
+
* microVMs, their size or lifetime (`429 quota_exceeded`, `403 plan_limit_exceeded`).
|
|
4798
|
+
*/
|
|
4799
|
+
declare class MicroVmQuotaExceededError extends ApiError {
|
|
4800
|
+
constructor(message: string, status: number, code?: string, reason?: string);
|
|
4801
|
+
}
|
|
4802
|
+
/** The output a command produced, attached to {@link CommandFailedError}. */
|
|
4803
|
+
interface CommandOutput {
|
|
4804
|
+
commandId: string;
|
|
4805
|
+
exitCode: number | null;
|
|
4806
|
+
signal: string | null;
|
|
4807
|
+
stdout: string;
|
|
4808
|
+
stderr: string;
|
|
4809
|
+
durationMs: number;
|
|
4810
|
+
}
|
|
4811
|
+
/**
|
|
4812
|
+
* A command exited with a non-zero code or was killed by a signal, and the
|
|
4813
|
+
* caller asked for `throwOnError`.
|
|
4814
|
+
*
|
|
4815
|
+
* @example
|
|
4816
|
+
* ```ts
|
|
4817
|
+
* try {
|
|
4818
|
+
* await vm.run('npm', ['test'], { throwOnError: true });
|
|
4819
|
+
* } catch (err) {
|
|
4820
|
+
* if (err instanceof CommandFailedError) console.error(err.exitCode, err.stderr);
|
|
4821
|
+
* }
|
|
4822
|
+
* ```
|
|
4823
|
+
*/
|
|
4824
|
+
declare class CommandFailedError extends GigadriveError {
|
|
4825
|
+
readonly commandId: string;
|
|
4826
|
+
/** Exit code, or `null` when a signal killed the process. */
|
|
4827
|
+
readonly exitCode: number | null;
|
|
4828
|
+
readonly signal: string | null;
|
|
4829
|
+
readonly stdout: string;
|
|
4830
|
+
readonly stderr: string;
|
|
4831
|
+
constructor(output: CommandOutput, label?: string);
|
|
4832
|
+
/** Builds the error from a finished command whose output was not collected. */
|
|
4833
|
+
static fromInfo(info: CommandInfo): CommandFailedError;
|
|
4834
|
+
}
|
|
4835
|
+
/** A wait (`waitForPort`, `waitUntilRunning`, `images.waitUntilReady`, `command.wait`) ran out of time. */
|
|
4836
|
+
declare class MicroVmTimeoutError extends GigadriveError {
|
|
4837
|
+
constructor(message: string);
|
|
4838
|
+
}
|
|
4839
|
+
/** The microVM is not exposing the port, so it has no preview URL. Expose ports with `ports` at create. */
|
|
4840
|
+
declare class MicroVmPortNotExposedError extends GigadriveError {
|
|
4841
|
+
readonly port: number;
|
|
4842
|
+
constructor(port: number, exposed: readonly number[]);
|
|
4843
|
+
}
|
|
4844
|
+
/** The microVM failed while starting, or stopped before it was ready. */
|
|
4845
|
+
declare class MicroVmStartError extends GigadriveError {
|
|
4846
|
+
readonly microvmId: string;
|
|
4847
|
+
readonly status: string;
|
|
4848
|
+
readonly stopReason: string | null;
|
|
4849
|
+
constructor(microvmId: string, status: string, stopReason: string | null);
|
|
4850
|
+
}
|
|
4851
|
+
/**
|
|
4852
|
+
* {@link MicroVM.create} gave up on a microVM and could not delete it either.
|
|
4853
|
+
* The microVM may still boot and bill: delete it by {@link microvmId}.
|
|
4854
|
+
*/
|
|
4855
|
+
declare class MicroVmCleanupError extends GigadriveError {
|
|
4856
|
+
readonly microvmId: string;
|
|
4857
|
+
/** Why deleting the microVM failed. {@link Error.cause} is why creating it failed. */
|
|
4858
|
+
readonly cleanupError: unknown;
|
|
4859
|
+
constructor(microvmId: string, cause: unknown, cleanupError: unknown);
|
|
4860
|
+
}
|
|
4861
|
+
/** A custom image build failed. */
|
|
4862
|
+
declare class MicroVmImageBuildError extends GigadriveError {
|
|
4863
|
+
readonly imageId: string;
|
|
4864
|
+
constructor(imageId: string, message: string | null | undefined);
|
|
4865
|
+
}
|
|
4866
|
+
|
|
4867
|
+
/** How a {@link MicroVM} reaches the API. */
|
|
4868
|
+
interface MicroVmClientOptions {
|
|
4869
|
+
/**
|
|
4870
|
+
* A configured {@link GigadriveClient}, or the configuration to create one.
|
|
4871
|
+
* Default: a shared client configured from the environment
|
|
4872
|
+
* (`GIGADRIVE_CLIENT_ID`/`GIGADRIVE_CLIENT_SECRET`, `GIGADRIVE_BEARER_TOKEN`,
|
|
4873
|
+
* `GIGADRIVE_APPLICATION_ID`), which deployments and Functions receive
|
|
4874
|
+
* automatically.
|
|
4875
|
+
*/
|
|
4876
|
+
client?: GigadriveClient | GigadriveClientConfig;
|
|
4877
|
+
}
|
|
4878
|
+
/** Options of {@link MicroVM.create}. */
|
|
4879
|
+
interface CreateMicroVmOptions extends Omit<CreateMicroVmInput, 'network'>, MicroVmClientOptions {
|
|
4880
|
+
/**
|
|
4881
|
+
* Lifetime before the microVM stops automatically: milliseconds or a string
|
|
4882
|
+
* such as `'10m'`. Default 5 minutes; extend it later with
|
|
4883
|
+
* {@link MicroVM.extendTimeout}. Wins over `timeoutMs`.
|
|
4884
|
+
*/
|
|
4885
|
+
timeout?: MicroVmDuration;
|
|
4886
|
+
/** `'deny'` blocks all outbound traffic. Default `'allow'`. */
|
|
4887
|
+
network?: MicroVmEgress | MicroVmNetworkPolicy;
|
|
4888
|
+
/**
|
|
4889
|
+
* Wait until the microVM is running (polling, up to 10 minutes, which covers
|
|
4890
|
+
* a wait for capacity). Default `true`. With `false` the returned microVM may
|
|
4891
|
+
* still be pending or starting; call {@link MicroVM.waitUntilRunning}.
|
|
4892
|
+
*/
|
|
4893
|
+
wait?: boolean;
|
|
4894
|
+
signal?: AbortSignal;
|
|
4895
|
+
}
|
|
4896
|
+
/** Options of {@link MicroVM.list}. */
|
|
4897
|
+
type ListMicroVmsOptions = Omit<ListMicroVmsQuery, 'cursor'> & MicroVmClientOptions;
|
|
4898
|
+
/** Options shared by {@link MicroVM.run} and {@link MicroVM.spawn}. */
|
|
4899
|
+
interface CommandOptions {
|
|
4900
|
+
/** Working directory. Default: the image's working directory. */
|
|
4901
|
+
cwd?: string;
|
|
4902
|
+
/** Environment variables merged over the microVM's. */
|
|
4903
|
+
env?: Record<string, string>;
|
|
4904
|
+
/** Run as this user (name, `root` or uid). Default: the image's user. */
|
|
4905
|
+
user?: string;
|
|
4906
|
+
/** Run as root. Shorthand for `user: 'root'`. */
|
|
4907
|
+
sudo?: boolean;
|
|
4908
|
+
/** Kill the command (SIGKILL) after this long: milliseconds or `'10m'`. */
|
|
4909
|
+
timeout?: MicroVmDuration;
|
|
4910
|
+
/** Called with stdout text as it arrives. */
|
|
4911
|
+
onStdout?: CommandOutputCallback;
|
|
4912
|
+
/** Called with stderr text as it arrives. */
|
|
4913
|
+
onStderr?: CommandOutputCallback;
|
|
4914
|
+
}
|
|
4915
|
+
/** Options of {@link MicroVM.run}. */
|
|
4916
|
+
interface RunOptions extends CommandOptions {
|
|
4917
|
+
/** Data written to stdin, which is then closed. */
|
|
4918
|
+
stdin?: string | Uint8Array;
|
|
4919
|
+
/** Throw {@link CommandFailedError} when the command exits non-zero or is killed. */
|
|
4920
|
+
throwOnError?: boolean;
|
|
4921
|
+
/** Aborting kills the command (SIGKILL) and rejects with the abort reason. */
|
|
4922
|
+
signal?: AbortSignal;
|
|
4923
|
+
}
|
|
4924
|
+
/** Options of {@link MicroVM.spawn}. */
|
|
4925
|
+
interface SpawnOptions extends CommandOptions {
|
|
4926
|
+
/** Keep stdin open for {@link Command.write}. */
|
|
4927
|
+
stdin?: boolean;
|
|
4928
|
+
/** Run in a pseudo-terminal (`true` is 80x24). Output is merged into stdout. */
|
|
4929
|
+
pty?: boolean | PtySize;
|
|
4930
|
+
}
|
|
4931
|
+
/** What {@link MicroVM.run} returns. */
|
|
4932
|
+
interface CommandResult {
|
|
4933
|
+
commandId: string;
|
|
4934
|
+
/** Exit code; `null` when a signal killed the process. */
|
|
4935
|
+
exitCode: number | null;
|
|
4936
|
+
/** Signal that killed the process, if any. */
|
|
4937
|
+
signal: string | null;
|
|
4938
|
+
/** Whether the command was killed because it ran past its `timeout`. */
|
|
4939
|
+
timedOut: boolean;
|
|
4940
|
+
stdout: string;
|
|
4941
|
+
stderr: string;
|
|
4942
|
+
/**
|
|
4943
|
+
* Whether output was left out: over 1 MiB per stream for a call without
|
|
4944
|
+
* callbacks, or output older than the retained 8 MiB per stream.
|
|
4945
|
+
*/
|
|
4946
|
+
truncated: boolean;
|
|
4947
|
+
durationMs: number;
|
|
4948
|
+
}
|
|
4949
|
+
/** Options of {@link MicroVM.waitForPort}. */
|
|
4950
|
+
interface WaitForPortOptions {
|
|
4951
|
+
/** Give up after this long. Default `'60s'`. */
|
|
4952
|
+
timeout?: MicroVmDuration;
|
|
4953
|
+
/** Pause between probes. Default `'500ms'`. */
|
|
4954
|
+
interval?: MicroVmDuration;
|
|
4955
|
+
/** Path to request. Default `/`. */
|
|
4956
|
+
path?: string;
|
|
4957
|
+
signal?: AbortSignal;
|
|
4958
|
+
}
|
|
4959
|
+
/** Options of {@link MicroVM.waitUntilRunning}. */
|
|
4960
|
+
interface WaitUntilRunningOptions {
|
|
4961
|
+
/** Give up after this long. Default `'2m'`. */
|
|
4962
|
+
timeout?: MicroVmDuration;
|
|
4963
|
+
/** Pause between polls. Default `'500ms'`. */
|
|
4964
|
+
interval?: MicroVmDuration;
|
|
4965
|
+
signal?: AbortSignal;
|
|
4966
|
+
}
|
|
4967
|
+
/** One file of {@link MicroVmFiles.writeMany}. */
|
|
4968
|
+
interface FileToWrite {
|
|
4969
|
+
path: string;
|
|
4970
|
+
content: MicroVmFileContent;
|
|
4971
|
+
/** Permission bits, e.g. `'0755'` or `0o755`. */
|
|
4972
|
+
mode?: string | number;
|
|
4973
|
+
}
|
|
4974
|
+
/**
|
|
4975
|
+
* Files of one microVM: `vm.files`. Paths are absolute or relative to the
|
|
4976
|
+
* user's home directory. All content is binary safe.
|
|
4977
|
+
*/
|
|
4978
|
+
declare class MicroVmFiles {
|
|
4979
|
+
private readonly resource;
|
|
4980
|
+
private readonly microvmId;
|
|
4981
|
+
/** @internal */
|
|
4982
|
+
constructor(resource: MicroVmFilesResource, microvmId: string);
|
|
4983
|
+
/** Read a file as bytes. @throws {@link MicroVmFileNotFoundError} */
|
|
4984
|
+
read(path: string, options?: ReadFileOptions): Promise<Uint8Array>;
|
|
4985
|
+
/** Read a file as UTF-8 text. */
|
|
4986
|
+
readText(path: string, options?: ReadFileOptions): Promise<string>;
|
|
4987
|
+
/** Read a file as a stream, for files too large to buffer. */
|
|
4988
|
+
readStream(path: string, options?: ReadFileOptions): Promise<ReadableStream<Uint8Array>>;
|
|
4989
|
+
/**
|
|
4990
|
+
* Write a file atomically, creating parent directories.
|
|
4991
|
+
*
|
|
4992
|
+
* @example
|
|
4993
|
+
* ```ts
|
|
4994
|
+
* await vm.files.write('/app/index.js', 'console.log("hi")');
|
|
4995
|
+
* await vm.files.write('/app/logo.png', await (await fetch(url)).blob());
|
|
4996
|
+
* ```
|
|
4997
|
+
*/
|
|
4998
|
+
write(path: string, content: MicroVmFileContent, options?: WriteFileOptions): Promise<FileWriteResult>;
|
|
4999
|
+
/**
|
|
5000
|
+
* Write several files, a few at a time. Resolves in input order once all
|
|
5001
|
+
* succeeded; rejects with the first failure.
|
|
5002
|
+
*
|
|
5003
|
+
* @example
|
|
5004
|
+
* ```ts
|
|
5005
|
+
* await vm.files.writeMany([
|
|
5006
|
+
* { path: 'app/package.json', content: JSON.stringify(pkg) },
|
|
5007
|
+
* { path: 'app/run.sh', content: '#!/bin/sh\nnode .', mode: '0755' },
|
|
5008
|
+
* ]);
|
|
5009
|
+
* ```
|
|
5010
|
+
*/
|
|
5011
|
+
writeMany(files: readonly FileToWrite[], options?: {
|
|
5012
|
+
concurrency?: number;
|
|
5013
|
+
signal?: AbortSignal;
|
|
5014
|
+
}): Promise<FileWriteResult[]>;
|
|
5015
|
+
/**
|
|
5016
|
+
* List a directory. `recursive` descends into subdirectories (up to `depth`
|
|
5017
|
+
* levels). Very large listings are cut off; `client.microvms.files.list`
|
|
5018
|
+
* reports that as `truncated`.
|
|
5019
|
+
*/
|
|
5020
|
+
list(path?: string, options?: {
|
|
5021
|
+
recursive?: boolean;
|
|
5022
|
+
depth?: number;
|
|
5023
|
+
}): Promise<FileEntry[]>;
|
|
5024
|
+
/** Describe a file or directory. @throws {@link MicroVmFileNotFoundError} */
|
|
5025
|
+
stat(path: string): Promise<FileEntry>;
|
|
5026
|
+
/** Whether a file or directory exists. */
|
|
5027
|
+
exists(path: string): Promise<boolean>;
|
|
5028
|
+
/** Create a directory and its parents (pass `parents: false` to require the parent). */
|
|
5029
|
+
mkdir(path: string, options?: {
|
|
5030
|
+
parents?: boolean;
|
|
5031
|
+
}): Promise<FileEntry>;
|
|
5032
|
+
/** Delete a file, or a directory with `recursive: true`. */
|
|
5033
|
+
remove(path: string, options?: {
|
|
5034
|
+
recursive?: boolean;
|
|
5035
|
+
}): Promise<void>;
|
|
5036
|
+
/** Move or rename a file or directory. */
|
|
5037
|
+
move(from: string, to: string): Promise<FileEntry>;
|
|
5038
|
+
}
|
|
5039
|
+
/** Commands of one microVM: `vm.commands`, for reattaching to detached commands. */
|
|
5040
|
+
declare class MicroVmCommands {
|
|
5041
|
+
private readonly resource;
|
|
5042
|
+
private readonly microvmId;
|
|
5043
|
+
/** @internal */
|
|
5044
|
+
constructor(resource: MicroVmCommandsResource, microvmId: string);
|
|
5045
|
+
/**
|
|
5046
|
+
* Reattach to a command, for example one spawned by another process.
|
|
5047
|
+
*
|
|
5048
|
+
* @example
|
|
5049
|
+
* ```ts
|
|
5050
|
+
* const command = await vm.commands.get(savedCommandId);
|
|
5051
|
+
* for await (const chunk of command.logs()) process.stdout.write(chunk.data);
|
|
5052
|
+
* ```
|
|
5053
|
+
*/
|
|
5054
|
+
get(commandId: string): Promise<Command>;
|
|
5055
|
+
/** All commands the microVM still remembers, newest first. */
|
|
5056
|
+
list(): Promise<Command[]>;
|
|
5057
|
+
}
|
|
5058
|
+
/**
|
|
5059
|
+
* An isolated Linux machine on Gigadrive Network that you can run commands
|
|
5060
|
+
* in, read and write files on, and expose ports from.
|
|
5061
|
+
*
|
|
5062
|
+
* @example
|
|
5063
|
+
* ```ts
|
|
5064
|
+
* import { MicroVM } from '@gigadrive/sdk';
|
|
5065
|
+
*
|
|
5066
|
+
* await using vm = await MicroVM.create({ image: 'node22', ports: [3000], timeout: '10m' });
|
|
5067
|
+
* await vm.files.write('server.js', 'require("http").createServer((_, r) => r.end("hi")).listen(3000)');
|
|
5068
|
+
* await vm.run('npm init -y');
|
|
5069
|
+
* const server = await vm.spawn('node', ['server.js']);
|
|
5070
|
+
* await vm.waitForPort(3000);
|
|
5071
|
+
* console.log(vm.url(3000));
|
|
5072
|
+
* ```
|
|
5073
|
+
*/
|
|
5074
|
+
declare class MicroVM {
|
|
5075
|
+
private readonly resource;
|
|
5076
|
+
/** Files inside the microVM. */
|
|
5077
|
+
readonly files: MicroVmFiles;
|
|
5078
|
+
/** Reattach to commands by id. */
|
|
5079
|
+
readonly commands: MicroVmCommands;
|
|
5080
|
+
private current;
|
|
5081
|
+
/** @internal Use {@link MicroVM.create} or {@link MicroVM.get}. */
|
|
5082
|
+
constructor(resource: MicroVmsResource, info: MicroVmInfo);
|
|
5083
|
+
/**
|
|
5084
|
+
* Create a microVM and wait until it runs.
|
|
5085
|
+
*
|
|
5086
|
+
* @throws {RangeError} When `timeout` is longer than 24 hours.
|
|
5087
|
+
*
|
|
5088
|
+
* The application is taken from `applicationId`, the client's
|
|
5089
|
+
* `applicationId` or `GIGADRIVE_APPLICATION_ID`; inside a Gigadrive
|
|
5090
|
+
* deployment or Function nothing needs configuring.
|
|
5091
|
+
*
|
|
5092
|
+
* @example
|
|
5093
|
+
* ```ts
|
|
5094
|
+
* const vm = await MicroVM.create({
|
|
5095
|
+
* image: 'python3.13',
|
|
5096
|
+
* vcpus: 2,
|
|
5097
|
+
* memoryMb: 4096,
|
|
5098
|
+
* timeout: '15m',
|
|
5099
|
+
* ports: [8000],
|
|
5100
|
+
* env: { PYTHONUNBUFFERED: '1' },
|
|
5101
|
+
* metadata: { user: 'u_123' },
|
|
5102
|
+
* network: 'deny',
|
|
5103
|
+
* });
|
|
5104
|
+
* ```
|
|
5105
|
+
*/
|
|
5106
|
+
static create(options?: CreateMicroVmOptions): Promise<MicroVM>;
|
|
5107
|
+
/**
|
|
5108
|
+
* Connect to an existing microVM by id.
|
|
5109
|
+
*
|
|
5110
|
+
* @throws {@link MicroVmNotFoundError} when it does not exist.
|
|
5111
|
+
*/
|
|
5112
|
+
static get(microvmId: string, options?: MicroVmClientOptions): Promise<MicroVM>;
|
|
5113
|
+
/** Alias of {@link MicroVM.get}. */
|
|
5114
|
+
static connect(microvmId: string, options?: MicroVmClientOptions): Promise<MicroVM>;
|
|
5115
|
+
/**
|
|
5116
|
+
* Iterate microVMs, newest first, across all pages.
|
|
5117
|
+
*
|
|
5118
|
+
* @example
|
|
5119
|
+
* ```ts
|
|
5120
|
+
* for await (const vm of MicroVM.list({ status: 'running' })) {
|
|
5121
|
+
* console.log(vm.id, vm.metadata);
|
|
5122
|
+
* }
|
|
5123
|
+
* ```
|
|
5124
|
+
*/
|
|
5125
|
+
static list(options?: ListMicroVmsOptions): AsyncGenerator<MicroVM>;
|
|
5126
|
+
/** Stable UUID. */
|
|
5127
|
+
get id(): string;
|
|
5128
|
+
/** Label used in preview URLs. */
|
|
5129
|
+
get slug(): string;
|
|
5130
|
+
get applicationId(): string;
|
|
5131
|
+
/** Status as of the last API response; call {@link refresh} for the current one. */
|
|
5132
|
+
get status(): MicroVmStatus;
|
|
5133
|
+
/** Exposed ports. */
|
|
5134
|
+
get ports(): number[];
|
|
5135
|
+
get metadata(): Record<string, string>;
|
|
5136
|
+
/** When the microVM stops automatically. */
|
|
5137
|
+
get expiresAt(): Date | null;
|
|
5138
|
+
/** The full API object as of the last response. */
|
|
5139
|
+
get info(): MicroVmInfo;
|
|
5140
|
+
/**
|
|
5141
|
+
* The public preview URL of an exposed port.
|
|
5142
|
+
*
|
|
5143
|
+
* @throws {@link MicroVmPortNotExposedError} when the port was not in `ports` at create.
|
|
5144
|
+
*
|
|
5145
|
+
* @example
|
|
5146
|
+
* ```ts
|
|
5147
|
+
* vm.url(3000); // "https://3000-k3j9x2m1q8zt.vm.gigadrive.app"
|
|
5148
|
+
* ```
|
|
5149
|
+
*/
|
|
5150
|
+
url(port: number): string;
|
|
5151
|
+
/** Fetch the latest state. */
|
|
5152
|
+
refresh(options?: {
|
|
5153
|
+
signal?: AbortSignal;
|
|
5154
|
+
}): Promise<MicroVmInfo>;
|
|
5155
|
+
/**
|
|
5156
|
+
* Run a command and wait for it to exit.
|
|
5157
|
+
*
|
|
5158
|
+
* Pass `args` to execute the program directly, or a single string to run it
|
|
5159
|
+
* through `/bin/sh -c` (pipes, `&&`, globbing). Without output callbacks the
|
|
5160
|
+
* call makes one request; with `onStdout`/`onStderr`, `stdin` or `signal` it
|
|
5161
|
+
* starts the command detached and streams its output.
|
|
5162
|
+
*
|
|
5163
|
+
* A non-zero exit code is a normal result; pass `throwOnError: true` to
|
|
5164
|
+
* reject with {@link CommandFailedError} instead.
|
|
5165
|
+
*
|
|
5166
|
+
* @example
|
|
5167
|
+
* ```ts
|
|
5168
|
+
* const { exitCode, stdout } = await vm.run('ls -la /app');
|
|
5169
|
+
* await vm.run('npm', ['install'], { cwd: '/app', onStdout: (text) => process.stdout.write(text) });
|
|
5170
|
+
* await vm.run('pytest -q', { throwOnError: true, timeout: '5m' });
|
|
5171
|
+
* ```
|
|
5172
|
+
*/
|
|
5173
|
+
run(cmd: string, options?: RunOptions): Promise<CommandResult>;
|
|
5174
|
+
run(cmd: string, args: string[], options?: RunOptions): Promise<CommandResult>;
|
|
5175
|
+
/**
|
|
5176
|
+
* Start a command in the background and return a {@link Command} handle at
|
|
5177
|
+
* once. Use it for servers, watchers and interactive programs.
|
|
5178
|
+
*
|
|
5179
|
+
* @example
|
|
5180
|
+
* ```ts
|
|
5181
|
+
* const dev = await vm.spawn('npm', ['run', 'dev'], { cwd: '/app', onStdout: console.log });
|
|
5182
|
+
* await vm.waitForPort(3000);
|
|
5183
|
+
*
|
|
5184
|
+
* const repl = await vm.spawn('python3', [], { pty: { cols: 120, rows: 40 } });
|
|
5185
|
+
* await repl.write('print(1 + 1)\n');
|
|
5186
|
+
* ```
|
|
5187
|
+
*/
|
|
5188
|
+
spawn(cmd: string, options?: SpawnOptions): Promise<Command>;
|
|
5189
|
+
spawn(cmd: string, args: string[], options?: SpawnOptions): Promise<Command>;
|
|
5190
|
+
/**
|
|
5191
|
+
* Set the remaining lifetime to `duration` from now (up to the plan's
|
|
5192
|
+
* maximum lifetime).
|
|
5193
|
+
*
|
|
5194
|
+
* @example
|
|
5195
|
+
* ```ts
|
|
5196
|
+
* await vm.extendTimeout('30m');
|
|
5197
|
+
* ```
|
|
5198
|
+
*/
|
|
5199
|
+
extendTimeout(duration: MicroVmDuration): Promise<MicroVmInfo>;
|
|
5200
|
+
/** Stop the microVM. Its disk, memory and running commands are discarded. */
|
|
5201
|
+
stop(): Promise<MicroVmInfo>;
|
|
5202
|
+
/** Delete the microVM, stopping it first if needed. */
|
|
5203
|
+
delete(): Promise<void>;
|
|
5204
|
+
/**
|
|
5205
|
+
* Poll until the microVM is running, for microVMs created with `wait: false`.
|
|
5206
|
+
*
|
|
5207
|
+
* @throws {@link MicroVmStartError} when it failed or stopped instead.
|
|
5208
|
+
* @throws {@link MicroVmTimeoutError} when it is still starting after `timeout`.
|
|
5209
|
+
*/
|
|
5210
|
+
waitUntilRunning(options?: WaitUntilRunningOptions): Promise<this>;
|
|
5211
|
+
/**
|
|
5212
|
+
* Poll an exposed port's preview URL until a server answers (any status
|
|
5213
|
+
* other than 502, 503 or 504, which the gateway returns while nothing
|
|
5214
|
+
* listens).
|
|
5215
|
+
*
|
|
5216
|
+
* @returns The preview URL.
|
|
5217
|
+
* @throws {@link MicroVmPortNotExposedError} when the port is not exposed.
|
|
5218
|
+
* @throws {@link MicroVmNotRunningError} when the microVM has stopped.
|
|
5219
|
+
* @throws {@link MicroVmTimeoutError} when nothing answers within `timeout`.
|
|
5220
|
+
*
|
|
5221
|
+
* @example
|
|
5222
|
+
* ```ts
|
|
5223
|
+
* await vm.spawn('python3', ['-m', 'http.server', '8000']);
|
|
5224
|
+
* const url = await vm.waitForPort(8000);
|
|
5225
|
+
* ```
|
|
5226
|
+
*/
|
|
5227
|
+
waitForPort(port: number, options?: WaitForPortOptions): Promise<string>;
|
|
5228
|
+
/** Stops the microVM at the end of an `await using` block. Already stopped microVMs are fine. */
|
|
5229
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
5230
|
+
/** JSON form: the API object. */
|
|
5231
|
+
toJSON(): MicroVmInfo;
|
|
5232
|
+
}
|
|
5233
|
+
|
|
4004
5234
|
/**
|
|
4005
5235
|
* Lazily iterate every item across all pages of a cursor-paginated endpoint.
|
|
4006
5236
|
* Pass a function that fetches one page for a given cursor; iteration stops when
|
|
@@ -4216,14 +5446,42 @@ declare function createWorkflowQueue<TMessageId extends string = string>(options
|
|
|
4216
5446
|
|
|
4217
5447
|
/**
|
|
4218
5448
|
* Server-Sent Events (SSE) parsing for streamed API responses (e.g. streamed
|
|
4219
|
-
* chat completions). Works in browsers
|
|
4220
|
-
* a web `ReadableStream`.
|
|
5449
|
+
* chat completions and command logs). Works in browsers, Node.js 18+, Bun,
|
|
5450
|
+
* Deno and edge runtimes, wherever `Response.body` is a web `ReadableStream`.
|
|
4221
5451
|
*
|
|
4222
5452
|
* @internal
|
|
4223
5453
|
*/
|
|
5454
|
+
/** One dispatched Server-Sent Event. */
|
|
5455
|
+
interface ServerSentEvent {
|
|
5456
|
+
/** The `event:` field, or `message` when the server sent none. */
|
|
5457
|
+
event: string;
|
|
5458
|
+
/** The `data:` lines of the event, joined with `\n`. */
|
|
5459
|
+
data: string;
|
|
5460
|
+
/** The `id:` field of this event, when the server sent one. */
|
|
5461
|
+
id: string | undefined;
|
|
5462
|
+
/** The `retry:` reconnection delay in milliseconds, when the server sent one. */
|
|
5463
|
+
retry: number | undefined;
|
|
5464
|
+
}
|
|
5465
|
+
/**
|
|
5466
|
+
* Parse an SSE stream into events, keeping the event name, id and retry
|
|
5467
|
+
* fields. Comment and keep-alive blocks are skipped; iteration ends when the
|
|
5468
|
+
* underlying stream closes. Breaking out of the loop cancels the response body.
|
|
5469
|
+
*
|
|
5470
|
+
* @param response - A streaming `fetch` response.
|
|
5471
|
+
*
|
|
5472
|
+
* @example
|
|
5473
|
+
* ```ts
|
|
5474
|
+
* for await (const event of parseSSEEvents(response)) {
|
|
5475
|
+
* if (event.event === 'exit') break;
|
|
5476
|
+
* console.log(event.event, event.data);
|
|
5477
|
+
* }
|
|
5478
|
+
* ```
|
|
5479
|
+
*/
|
|
5480
|
+
declare function parseSSEEvents(response: Response): AsyncGenerator<ServerSentEvent>;
|
|
4224
5481
|
/**
|
|
4225
5482
|
* Parse an SSE stream, yielding each event's `data` payload parsed as JSON.
|
|
4226
|
-
*
|
|
5483
|
+
* Event names are ignored (use {@link parseSSEEvents} to read them). The
|
|
5484
|
+
* `[DONE]` sentinel and empty keep-alive events are skipped; iteration ends
|
|
4227
5485
|
* when the underlying stream closes.
|
|
4228
5486
|
*
|
|
4229
5487
|
* @typeParam T - The shape of each streamed JSON chunk.
|
|
@@ -4231,4 +5489,4 @@ declare function createWorkflowQueue<TMessageId extends string = string>(options
|
|
|
4231
5489
|
*/
|
|
4232
5490
|
declare function parseSSEStream<T = unknown>(response: Response): AsyncGenerator<T>;
|
|
4233
5491
|
|
|
4234
|
-
export { type AddCustomDomainInput, AiGatewayAudioResource, type AiGatewayBudget, type AiGatewayBudgetInput, AiGatewayBudgetsResource, AiGatewayPoliciesResource, type AiGatewayPolicy, type AiGatewayPolicyInput, type AiGatewayProviderAttempt, type AiGatewayRequestEvent, type AiGatewayRequestsQuery, AiGatewayResource, type AiGatewayUsageBreakdown, type AiGatewayUsageQuery, AiGatewayUsageResource, type AiGatewayUsageSummary, AiGatewayVideosResource, type AiModel, type AiModelCapabilities, type AiModelRoutingProvider, ApiError, type ApiKey, ApiKeysResource, type Application, ApplicationDomainsResource, ApplicationEnvVarsResource, type ApplicationHostnameList, ApplicationRequestsResource, ApplicationStorageResource, ApplicationsResource, AuthenticationError, type ChatCompletionChoice, type ChatCompletionChunk, type ChatCompletionContentPart, type ChatCompletionMessage, type ChatCompletionRequest, type ChatCompletionResponse, type ChatCompletionUsage, ConfigurationError, type CreateApiKeyInput, type CreateApiKeyResult, type CreateDeploymentInput, type CreateEnvVarInput, type CreateOrganizationInput, type CreateStickySessionUrlInput, type CreateStickySessionUrlResult, type CreateStorageBucketInput, type CreateUploadSessionInput, type CreateUploadSessionResponse, type CustomDomain, type CustomDomainState, type CustomDomainTarget, type CustomDomainTargetInput, type Deployment, type DeploymentLog, type DeploymentLogPage, type DeploymentLogType, type DeploymentStatus, DeploymentsResource, DomainNotActiveError, type DomainOwnership, type DomainProblem, type EmptyStorageTrashResult, type EnvVar, type GatewayRequestOptions, type GatewayResult, GigadriveClient, type GigadriveClientConfig, GigadriveError, type Hostname, type HostnameAvailability, type ImageCacheInspection, type ImageCachePurgeResult, ImageOptimizationResource, type ListApiKeysQuery, type ListApplicationsQuery, type ListDeploymentLogsQuery, type ListDeploymentsQuery, type ListQuery, type ListRequestsQuery, type ListStorageBucketsQuery, type ListStorageObjectsQuery, type ListStorageTrashQuery, type ListStorageUploadSessionsQuery, type ManagedImageUrlOptions, type NetworkRequest, type NetworkRequestApplicationRef, type NetworkRequestAssetRef, type NetworkRequestBucketRef, type NetworkRequestDeploymentRef, type NetworkRequestDetails, type NetworkRequestFunctionRef, type NetworkRequestMetrics, type NetworkRequestObjectRef, type NetworkRequestSummary, type NetworkResponseDetails, type NodeReadableLike, NonRetryableError, type Organization, OrganizationAiGatewayResource, OrganizationDomainsResource, OrganizationEnvVarsResource, type OrganizationMember, OrganizationMembersResource, type OrganizationMembershipRole, type OrganizationProductAccess, type OrganizationProductEntitlement, type OrganizationProductEntitlementCheck, type OrganizationProductSubscription, OrganizationProductsResource, OrganizationsResource, type Paginated, type PresignedUrlResult, type ProductAccessMode, type ProductAccessResolutionSource, type ProductDefaultAccessPolicy, type ProductDefinition, type ProductEntitlementStatus, type ProductPlan, type ProductSubscriptionStatus, type ProviderRouting, type PullEnvVarsQuery, type PullEnvVarsResult, QUEUE_DELIVERY_HEADERS, QUEUE_RESPONSE_HEADERS, QUEUE_SIGNATURE_HEADER, QUEUE_SIGNATURE_TOLERANCE_MS, QUEUE_SIGNING_SECRET_ENV, type QueryValue, Queue, type QueueAckResult, type QueueBatchSent, type QueueCodec, type QueueDuration, type QueueInfo, type QueueMessageHandler, type QueueMessageInput, type QueueMessageMeta, type QueueMessageRecord, type QueueNackResult, type QueueOptions, type QueueSchedule, type QueueScheduleInput, type QueueScopeOptions, type QueueSendOptions, type QueueSendResult, type QueueSent, type QueueSettings, type QueueSignatureInput, type QueueStats, QueuesResource, type ReceivedQueueMessage, type RequiredDnsRecord, type ResolvedEnvVar, type ResponsesRequest, type ResponsesResponse, RetryLaterError, type RunUploadOptions, type SetProductionHostnameResult, type SpeechRequest, type StartUploadResult, StickySessionsResource, type StorageBucket, type StorageBucketReference, StorageBucketsResource, type StorageEnvironmentOptions, type StorageObject, type StorageObjectAccess, type StorageObjectAccessOptions, type StorageObjectList, StorageObjectsResource, type StorageTrashList, StorageTrashResource, type StorageUploadSession, StorageUploadSessionsResource, type TranscriptionRequest, type TranscriptionResponse, type TrashedStorageObject, type UpdateCustomDomainInput, type UpdateEnvVarInput, type UploadBatchItemResult, type UploadBatchOptions, type UploadByteSource, type UploadData, UploadError, type UploadFileInput, type UploadFileResult, type UploadPart, UploadSessionExpiredError, type UploadUrlStorage, type VideoGenerationRequest, type VideoGenerationResponse, type VideoModelList, WORKFLOW_CONSUMER_PATH, WORKFLOW_QUEUE_NAME_HEADER, type WaitForCompletionOptions, type WaitUntilActiveOptions, type WorkflowQueue, type WorkflowQueueHandlerMeta, type WorkflowQueueOptions, type WorkflowQueueSendOptions, createManagedImageUrl, createWorkflowQueue, defaultQueueCodec, durationToSeconds, paginate, parseSSEStream, queue, signQueueDelivery, verifyQueueSignature };
|
|
5492
|
+
export { type AddCustomDomainInput, AiGatewayAudioResource, type AiGatewayBudget, type AiGatewayBudgetInput, AiGatewayBudgetsResource, AiGatewayPoliciesResource, type AiGatewayPolicy, type AiGatewayPolicyInput, type AiGatewayProviderAttempt, type AiGatewayRequestEvent, type AiGatewayRequestsQuery, AiGatewayResource, type AiGatewayUsageBreakdown, type AiGatewayUsageQuery, AiGatewayUsageResource, type AiGatewayUsageSummary, AiGatewayVideosResource, type AiModel, type AiModelCapabilities, type AiModelRoutingProvider, ApiError, type ApiKey, ApiKeysResource, type Application, ApplicationDomainsResource, ApplicationEnvVarsResource, type ApplicationHostnameList, ApplicationRequestsResource, ApplicationStorageResource, ApplicationsResource, AuthenticationError, type ChatCompletionChoice, type ChatCompletionChunk, type ChatCompletionContentPart, type ChatCompletionMessage, type ChatCompletionRequest, type ChatCompletionResponse, type ChatCompletionUsage, Command, CommandFailedError, type CommandInfo, type CommandLogChunk, type CommandLogEvent, type CommandLogStreamOptions, type CommandLogsOptions, type CommandLogsQuery, type CommandOptions, type CommandOutput, type CommandOutputCallback, type CommandResult, type CommandRunResult, type CommandSignal, type CommandStream, type CommandWaitOptions, ConfigurationError, type CreateApiKeyInput, type CreateApiKeyResult, type CreateDeploymentInput, type CreateEnvVarInput, type CreateMicroVmImageInput, type CreateMicroVmInput, type CreateMicroVmOptions, type CreateOrganizationInput, type CreateStickySessionUrlInput, type CreateStickySessionUrlResult, type CreateStorageBucketInput, type CreateUploadSessionInput, type CreateUploadSessionResponse, type CustomDomain, type CustomDomainState, type CustomDomainTarget, type CustomDomainTargetInput, type Deployment, type DeploymentLog, type DeploymentLogPage, type DeploymentLogType, type DeploymentStatus, DeploymentsResource, DomainNotActiveError, type DomainOwnership, type DomainProblem, type EmptyStorageTrashResult, type EnvVar, type FileEntry, type FileEntryType, type FileListing, type FileToWrite, type FileWriteResult, type GatewayRequestOptions, type GatewayResult, GigadriveClient, type GigadriveClientConfig, GigadriveError, type Hostname, type HostnameAvailability, type ImageCacheInspection, type ImageCachePurgeResult, ImageOptimizationResource, type ListApiKeysQuery, type ListApplicationsQuery, type ListDeploymentLogsQuery, type ListDeploymentsQuery, type ListMicroVmsOptions, type ListMicroVmsQuery, type ListQuery, type ListRequestsQuery, type ListStorageBucketsQuery, type ListStorageObjectsQuery, type ListStorageTrashQuery, type ListStorageUploadSessionsQuery, MICROVM_MAX_TIMEOUT_MS, type ManagedImageUrlOptions, MicroVM, MicroVmBusyError, MicroVmCleanupError, type MicroVmClientOptions, MicroVmCommands, MicroVmCommandsResource, type MicroVmDuration, type MicroVmEgress, type MicroVmFileContent, MicroVmFileNotFoundError, MicroVmFiles, MicroVmFilesResource, type MicroVmImage, MicroVmImageBuildError, MicroVmImageNotReadyError, type MicroVmImageSource, type MicroVmImageStatus, MicroVmImagesResource, type MicroVmInfo, type MicroVmNetworkPolicy, MicroVmNotFoundError, MicroVmNotRunningError, type MicroVmPage, type MicroVmPort, MicroVmPortNotExposedError, MicroVmQuotaExceededError, type MicroVmRequestOptions, MicroVmStartError, type MicroVmStatus, MicroVmTimeoutError, MicroVmUnreachableError, type MicroVmVcpus, MicroVmsResource, type NetworkRequest, type NetworkRequestApplicationRef, type NetworkRequestAssetRef, type NetworkRequestBucketRef, type NetworkRequestDeploymentRef, type NetworkRequestDetails, type NetworkRequestFunctionRef, type NetworkRequestMetrics, type NetworkRequestObjectRef, type NetworkRequestSummary, type NetworkResponseDetails, type NodeReadableLike, NonRetryableError, type Organization, OrganizationAiGatewayResource, OrganizationDomainsResource, OrganizationEnvVarsResource, type OrganizationMember, OrganizationMembersResource, type OrganizationMembershipRole, type OrganizationProductAccess, type OrganizationProductEntitlement, type OrganizationProductEntitlementCheck, type OrganizationProductSubscription, OrganizationProductsResource, OrganizationsResource, type Paginated, type PresignedUrlResult, type ProductAccessMode, type ProductAccessResolutionSource, type ProductDefaultAccessPolicy, type ProductDefinition, type ProductEntitlementStatus, type ProductPlan, type ProductSubscriptionStatus, type ProviderRouting, type PtySize, type PullEnvVarsQuery, type PullEnvVarsResult, QUEUE_DELIVERY_HEADERS, QUEUE_RESPONSE_HEADERS, QUEUE_SIGNATURE_HEADER, QUEUE_SIGNATURE_TOLERANCE_MS, QUEUE_SIGNING_SECRET_ENV, type QueryValue, Queue, type QueueAckResult, type QueueBatchSent, type QueueCodec, type QueueDuration, type QueueInfo, type QueueMessageHandler, type QueueMessageInput, type QueueMessageMeta, type QueueMessageRecord, type QueueNackResult, type QueueOptions, type QueueSchedule, type QueueScheduleInput, type QueueScopeOptions, type QueueSendOptions, type QueueSendResult, type QueueSent, type QueueSettings, type QueueSignatureInput, type QueueStats, QueuesResource, type ReadFileOptions, type ReceivedQueueMessage, type RequiredDnsRecord, type ResolvedEnvVar, type ResponsesRequest, type ResponsesResponse, RetryLaterError, type RunOptions, type RunUploadOptions, type ServerSentEvent, type SetProductionHostnameResult, type SpawnOptions, type SpeechRequest, type StartCommandInput, type StartUploadResult, StickySessionsResource, type StorageBucket, type StorageBucketReference, StorageBucketsResource, type StorageEnvironmentOptions, type StorageObject, type StorageObjectAccess, type StorageObjectAccessOptions, type StorageObjectList, StorageObjectsResource, type StorageTrashList, StorageTrashResource, type StorageUploadSession, StorageUploadSessionsResource, type TranscriptionRequest, type TranscriptionResponse, type TrashedStorageObject, type UpdateCustomDomainInput, type UpdateEnvVarInput, type UploadBatchItemResult, type UploadBatchOptions, type UploadByteSource, type UploadData, UploadError, type UploadFileInput, type UploadFileResult, type UploadPart, UploadSessionExpiredError, type UploadUrlStorage, type VideoGenerationRequest, type VideoGenerationResponse, type VideoModelList, WORKFLOW_CONSUMER_PATH, WORKFLOW_QUEUE_NAME_HEADER, type WaitForCompletionOptions, type WaitForImageOptions, type WaitForPortOptions, type WaitUntilActiveOptions, type WaitUntilRunningOptions, type WorkflowQueue, type WorkflowQueueHandlerMeta, type WorkflowQueueOptions, type WorkflowQueueSendOptions, type WriteFileOptions, createManagedImageUrl, createWorkflowQueue, defaultQueueCodec, durationToMs, durationToSeconds, paginate, parseSSEEvents, parseSSEStream, queue, signQueueDelivery, verifyQueueSignature };
|