@pablofdezr/microvm 0.1.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.
@@ -0,0 +1,178 @@
1
+ /**
2
+ * Wire types for the microvm API.
3
+ *
4
+ * These mirror the server's public types exactly. They are hand-written rather
5
+ * than generated so the names read naturally in TypeScript, and so a field
6
+ * added server-side is a deliberate change here rather than a silent one.
7
+ */
8
+ /** How a sandbox or exec ended. */
9
+ export type SandboxState = "running" | "stopped";
10
+ /**
11
+ * Why a sandbox stopped.
12
+ *
13
+ * The distinctions are the point: `expired` and `idle` are our doing, `failed`
14
+ * means the VM died on its own, and `stopped` means you asked.
15
+ */
16
+ export type StopReason = "stopped" | "expired" | "idle" | "failed";
17
+ /**
18
+ * How an exec ended.
19
+ *
20
+ * `exited` is your code's own verdict. `vanished` means we took the VM away
21
+ * mid-run — a TTL, an OOM — and is not your code failing. `failed` means the
22
+ * command could never start at all, usually a missing binary.
23
+ */
24
+ export type ExecStatus = "running" | "exited" | "timed_out" | "aborted" | "vanished" | "failed";
25
+ /** Where a queued task is in its life. */
26
+ export type TaskStatus = "pending" | "leased" | "done" | "failed";
27
+ /** What a sandbox has consumed. */
28
+ export interface Stats {
29
+ /**
30
+ * CPU actually burned, in milliseconds. This is the billable number: a
31
+ * sandbox blocked on the network contributes nothing to it.
32
+ */
33
+ active_cpu_ms: number;
34
+ /** How long the sandbox has existed. */
35
+ wall_ms: number;
36
+ /** Wall minus active CPU: existing but doing nothing. */
37
+ idle_ms: number;
38
+ memory_current_bytes: number;
39
+ memory_peak_bytes: number;
40
+ }
41
+ /** A sandbox's state. */
42
+ export interface SandboxInfo {
43
+ id: string;
44
+ image: string;
45
+ state: SandboxState;
46
+ reason?: StopReason;
47
+ created_at: string;
48
+ expires_at: string;
49
+ stopped_at?: string;
50
+ stats: Stats;
51
+ }
52
+ /** Options for creating a sandbox. */
53
+ export interface SandboxOptions {
54
+ vcpus?: number;
55
+ memMiB?: number;
56
+ /** May be fractional, e.g. 0.5. */
57
+ cpuCores?: number;
58
+ diskMiB?: number;
59
+ /**
60
+ * Enable filtered egress: the public internet is reachable, every private
61
+ * range is not. Package installs work; reaching the host's LAN does not.
62
+ */
63
+ network?: boolean;
64
+ /** Maximum lifetime in milliseconds. The sandbox is killed when it elapses. */
65
+ ttlMs?: number;
66
+ /**
67
+ * Reclaim the sandbox after this long with nothing running. Negative disables
68
+ * it, which only makes sense if you will definitely destroy it yourself.
69
+ */
70
+ idleTimeoutMs?: number;
71
+ }
72
+ /** Options for running a command. */
73
+ export interface ExecOptions {
74
+ args?: string[];
75
+ env?: Record<string, string>;
76
+ cwd?: string;
77
+ /** Written to the process, then closed. */
78
+ stdin?: Uint8Array | string;
79
+ /** Kills the process group when exceeded. */
80
+ timeoutMs?: number;
81
+ /** Makes the exec addressable before it finishes. Generated when absent. */
82
+ id?: string;
83
+ /** Aborts the process inside the guest when triggered. */
84
+ signal?: AbortSignal;
85
+ }
86
+ /** A finished command. */
87
+ export interface ExecResult {
88
+ id: string;
89
+ status: ExecStatus;
90
+ exit_code?: number;
91
+ signal?: string;
92
+ /** Why the command could never start. */
93
+ error?: string;
94
+ stdout: string;
95
+ stderr: string;
96
+ /** Output exceeded the retention cap and the oldest bytes were dropped. */
97
+ stdout_truncated?: boolean;
98
+ stderr_truncated?: boolean;
99
+ started_at: string;
100
+ finished_at?: string;
101
+ duration_ms: number;
102
+ }
103
+ /** One event in a streamed exec. */
104
+ export interface Frame {
105
+ type: "started" | "stdout" | "stderr" | "exit" | "error";
106
+ /** Base64 on the wire; decoded to bytes by the client. */
107
+ data?: Uint8Array;
108
+ pid?: number;
109
+ exit_code?: number;
110
+ signal?: string;
111
+ timed_out?: boolean;
112
+ message?: string;
113
+ }
114
+ /** Options for queueing a task. */
115
+ export interface TaskOptions {
116
+ /** Written into the sandbox before the command runs, keyed by path. */
117
+ files?: Record<string, Uint8Array | string>;
118
+ args?: string[];
119
+ env?: Record<string, string>;
120
+ timeoutMs?: number;
121
+ network?: boolean;
122
+ vcpus?: number;
123
+ memMiB?: number;
124
+ cpuCores?: number;
125
+ /** Higher runs first. Equal priorities are strictly FIFO. */
126
+ priority?: number;
127
+ /**
128
+ * Bounds retries. Retries exist for nodes dying, not for code failing: a task
129
+ * whose process exits non-zero is finished, never retried.
130
+ */
131
+ maxAttempts?: number;
132
+ /** Makes submission idempotent: the same ID twice is rejected, not re-run. */
133
+ id?: string;
134
+ }
135
+ /** A queued task. */
136
+ export interface Task {
137
+ id: string;
138
+ status: TaskStatus;
139
+ }
140
+ /** A finished task's outcome. */
141
+ export interface TaskResult {
142
+ task_id: string;
143
+ status: TaskStatus;
144
+ exit_code?: number;
145
+ stdout: string;
146
+ stderr: string;
147
+ /**
148
+ * An infrastructure failure — no sandbox, the VM died. Distinct from a
149
+ * non-zero exit, which is your code's own verdict.
150
+ */
151
+ error?: string;
152
+ attempts: number;
153
+ started_at?: string;
154
+ finished_at?: string;
155
+ active_cpu_ms: number;
156
+ memory_peak_bytes: number;
157
+ }
158
+ /** The queue's depth and a node's slots. */
159
+ export interface QueueStats {
160
+ pending: number;
161
+ leased: number;
162
+ done: number;
163
+ failed: number;
164
+ /**
165
+ * How long the head of the queue has waited. The number that says whether the
166
+ * fleet is big enough: rising means work arrives faster than it finishes.
167
+ */
168
+ oldest_pending_ms: number;
169
+ /** This node's slots, not the fleet's. */
170
+ slots: number;
171
+ busy: number;
172
+ }
173
+ /** The daemon's status. */
174
+ export interface Health {
175
+ ok: boolean;
176
+ version: string;
177
+ images: string[];
178
+ }