@aerol-ai/aerolvm-sdk 0.8.0 → 0.8.2

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/dist/MicroVM.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { type APIVersion, type RetryConfig } from "./internal/client.js";
2
2
  import { Sandbox } from "./Sandbox.js";
3
3
  import { Image } from "./Image.js";
4
- import type { APITokenList, BuildImageOptions, BuildImageResult, CloneGeneration, CreateAPITokenOptions, CreatedAPIToken, CreateOptions, CreateSessionOptions, CreateTemplateOptions, CreateWasmModuleOptions, PushWasmModuleOptions, PushWasmModuleResult, ExecStreamHandle, ExecStreamOptions, HealthStatus, EgressProfile, EgressProfileList, EgressProfileOptions, ListEgressProfilesOptions, NetworkPolicyCheckOptions, NetworkPolicyCheckResult, IngressTarget, Lifecycle, GetOptions, ListOptions, MountSpecRedacted, RegisterSnapshotOptions, ListSnapshotsOptions, SnapshotList, ResizeOptions, SandboxSnapshot, Session, SessionAttachHandle, SessionAttachOptions, Template, WasmModule, WhoAmI } from "./types.js";
4
+ import type { APITokenList, CallOptions, DestroyAllOptions, BuildImageOptions, BuildImageResult, CloneGeneration, CreateAPITokenOptions, CreatedAPIToken, CreateOptions, CreateSessionOptions, CreateTemplateOptions, CreateWasmModuleOptions, PushWasmModuleOptions, PushWasmModuleResult, ExecStreamHandle, ExecStreamOptions, FileEvent, FileWatchHandle, HealthStatus, EgressProfile, EgressProfileList, EgressProfileOptions, IdentityRole, IdentityRoleList, IdentityRoleOptions, ListEgressProfilesOptions, TeamQuota, TeamQuotaOptions, WarmPool, WarmPoolOptions, ListIdentityRolesOptions, NetworkPolicyCheckOptions, NetworkPolicyCheckResult, IngressTarget, Lifecycle, GetOptions, ListOptions, MountSpecRedacted, RevokeSandboxTokensResult, CreateSnapshotOptions, RegisterSnapshotOptions, ListSnapshotsOptions, SnapshotList, ResizeOptions, SandboxSnapshot, Session, SessionAttachHandle, SessionAttachOptions, Template, WasmModule, WatchFilesOptions, WhoAmI } from "./types.js";
5
5
  type FetchLike = typeof fetch;
6
6
  /** Scoped API token calls, reached as `microvm.tokens`. */
7
7
  export interface Tokens {
@@ -11,11 +11,17 @@ export interface Tokens {
11
11
  * earlier attempt whose reply was lost; that secret cannot be recovered,
12
12
  * so revoke the token and create it again.
13
13
  */
14
- create(options: CreateAPITokenOptions): Promise<CreatedAPIToken>;
14
+ create(options: CreateAPITokenOptions, call?: CallOptions): Promise<CreatedAPIToken>;
15
15
  /** List every token (auditor or admin); expired ones stay listed for 30 days. */
16
- list(): Promise<APITokenList>;
16
+ list(call?: CallOptions): Promise<APITokenList>;
17
17
  /** Revoke a token by id (admin only). Revoking one already gone succeeds. */
18
- revoke(id: string): Promise<void>;
18
+ revoke(id: string, call?: CallOptions): Promise<void>;
19
+ }
20
+ /** What {@link MicroVM.getOrCreate} found or made. */
21
+ export interface GetOrCreateResult {
22
+ sandbox: Sandbox;
23
+ /** True only when this call created the sandbox. */
24
+ created: boolean;
19
25
  }
20
26
  export interface MicroVMConfig {
21
27
  /**
@@ -58,7 +64,9 @@ export interface MicroVMConfig {
58
64
  * Cancels the client's HTTP requests: aborting it ends the request in
59
65
  * flight and any retry wait, so a call never sits out a long
60
66
  * `Retry-After` once aborted. Pass `AbortSignal.timeout(ms)` to bound
61
- * how long the client may run. WebSocket streams are not affected.
67
+ * how long the client may run. WebSocket streams are not affected. To
68
+ * cancel or time-limit one call, pass `{ signal }` as that call's last
69
+ * argument ({@link CallOptions}).
62
70
  */
63
71
  signal?: AbortSignal;
64
72
  }
@@ -69,76 +77,148 @@ export declare class MicroVM {
69
77
  readonly team: string;
70
78
  private readonly client;
71
79
  constructor(config?: MicroVMConfig);
72
- create(options: CreateOptions): Promise<Sandbox>;
73
- list(options?: ListOptions): Promise<Sandbox[]>;
80
+ create(options: CreateOptions, call?: CallOptions): Promise<Sandbox>;
81
+ list(options?: ListOptions, call?: CallOptions): Promise<Sandbox[]>;
74
82
  /**
75
83
  * Iterates one server page at a time. Use this for large fleet inventories so
76
84
  * the SDK does not retain every sandbox in memory.
77
85
  */
78
- listPages(options?: ListOptions): AsyncGenerator<Sandbox[]>;
79
- get(id: string, options?: GetOptions): Promise<Sandbox>;
86
+ listPages(options?: ListOptions, call?: CallOptions): AsyncGenerator<Sandbox[]>;
87
+ get(id: string, options?: GetOptions, call?: CallOptions): Promise<Sandbox>;
80
88
  /**
81
89
  * Returns the caller's sandbox with this name, or `null` when there is none.
82
90
  * Names are unique per owner. Throws when the server predates name lookup
83
91
  * (it ignores `?name=`), rather than guessing from an unfiltered list.
84
92
  */
85
- getByName(name: string, options?: GetOptions): Promise<Sandbox | null>;
86
- start(id: string): Promise<Sandbox>;
87
- stop(id: string): Promise<Sandbox>;
88
- createSnapshot(id: string, name: string): Promise<SandboxSnapshot>;
89
- registerSnapshot(options: RegisterSnapshotOptions): Promise<SandboxSnapshot>;
90
- registerSnapshotFromImage(name: string, image: Image, options?: Omit<RegisterSnapshotOptions, "name" | "image" | "dockerfileContent">): Promise<SandboxSnapshot>;
93
+ getByName(name: string, options?: GetOptions, call?: CallOptions): Promise<Sandbox | null>;
94
+ /**
95
+ * Returns the caller's sandbox called `name`, creating it from `options`
96
+ * when there is none. `created` is true only when this call made the
97
+ * sandbox. Safe to retry and to run at the same time from many processes:
98
+ * names are unique per owner, so when two callers race to create the same
99
+ * name, one gets a 409 and reads the winner's sandbox instead. An existing
100
+ * sandbox is returned as it is; its image and settings are not compared
101
+ * with `options`.
102
+ */
103
+ getOrCreate(name: string, options: CreateOptions, call?: CallOptions): Promise<GetOrCreateResult>;
104
+ start(id: string, call?: CallOptions): Promise<Sandbox>;
105
+ stop(id: string, call?: CallOptions): Promise<Sandbox>;
106
+ createSnapshot(id: string, name: string, options?: CreateSnapshotOptions, call?: CallOptions): Promise<SandboxSnapshot>;
107
+ registerSnapshot(options: RegisterSnapshotOptions, call?: CallOptions): Promise<SandboxSnapshot>;
108
+ registerSnapshotFromImage(name: string, image: Image, options?: Omit<RegisterSnapshotOptions, "name" | "image" | "dockerfileContent">, call?: CallOptions): Promise<SandboxSnapshot>;
91
109
  /** Look a snapshot up by name. In a cluster the request is routed to the node holding the image. */
92
- getSnapshot(name: string): Promise<SandboxSnapshot>;
110
+ getSnapshot(name: string, call?: CallOptions): Promise<SandboxSnapshot>;
93
111
  /** List the caller's snapshots, one name-ordered page at a time. */
94
- listSnapshots(options?: ListSnapshotsOptions): Promise<SnapshotList>;
112
+ listSnapshots(options?: ListSnapshotsOptions, call?: CallOptions): Promise<SnapshotList>;
95
113
  /** Delete a snapshot by name (idempotent 404 if it does not exist). */
96
- deleteSnapshot(name: string): Promise<void>;
97
- destroy(id: string): Promise<void>;
98
- resize(id: string, options: ResizeOptions): Promise<Sandbox>;
99
- updateLifecycle(id: string, lifecycle: Lifecycle): Promise<Sandbox>;
100
- reconcile(): Promise<void>;
114
+ deleteSnapshot(name: string, call?: CallOptions): Promise<void>;
115
+ destroy(id: string, call?: CallOptions): Promise<void>;
116
+ /**
117
+ * Deletes every sandbox of yours that carries all of `options.tags` and
118
+ * returns the IDs of the ones now gone. It lists every page first, then
119
+ * deletes them one at a time. A sandbox that is already gone (404) counts
120
+ * as deleted, so a second call, or two calls at once, is safe. Any other
121
+ * failed delete stops the call and is thrown; the sandboxes already
122
+ * deleted stay deleted, and calling it again finishes the job. `tags`
123
+ * must not be empty.
124
+ */
125
+ destroyAll(options: DestroyAllOptions, call?: CallOptions): Promise<string[]>;
126
+ resize(id: string, options: ResizeOptions, call?: CallOptions): Promise<Sandbox>;
127
+ updateLifecycle(id: string, lifecycle: Lifecycle, call?: CallOptions): Promise<Sandbox>;
128
+ reconcile(call?: CallOptions): Promise<void>;
101
129
  /**
102
130
  * Build an {@link Image} on the daemon and optionally push the result to a
103
131
  * remote registry. Push credentials are forwarded per request and never
104
132
  * persisted by the daemon. Returns the local content-addressed tag and,
105
133
  * when push was requested, the pushed reference.
106
134
  */
107
- buildImage(image: Image, options?: BuildImageOptions): Promise<BuildImageResult>;
108
- health(): Promise<HealthStatus>;
135
+ buildImage(image: Image, options?: BuildImageOptions, call?: CallOptions): Promise<BuildImageResult>;
136
+ health(call?: CallOptions): Promise<HealthStatus>;
109
137
  /**
110
138
  * Asks whether a sandbox created with these egress fields would reach a
111
139
  * destination, using the same matcher the filter enforces. No sandbox is
112
140
  * needed.
113
141
  */
114
- checkNetworkPolicy(options: NetworkPolicyCheckOptions): Promise<NetworkPolicyCheckResult>;
142
+ checkNetworkPolicy(options: NetworkPolicyCheckOptions, call?: CallOptions): Promise<NetworkPolicyCheckResult>;
115
143
  /**
116
144
  * Creates or replaces a named egress profile (a full replace: the same body
117
145
  * twice is a no-op). Sandboxes reference it through `egressProfiles`, and a
118
146
  * change reaches every one of them.
119
147
  */
120
- putEgressProfile(name: string, options: EgressProfileOptions): Promise<EgressProfile>;
121
- getEgressProfile(name: string): Promise<EgressProfile>;
122
- listEgressProfiles(options?: ListEgressProfilesOptions): Promise<EgressProfileList>;
148
+ putEgressProfile(name: string, options: EgressProfileOptions, call?: CallOptions): Promise<EgressProfile>;
149
+ getEgressProfile(name: string, call?: CallOptions): Promise<EgressProfile>;
150
+ listEgressProfiles(options?: ListEgressProfilesOptions, call?: CallOptions): Promise<EgressProfileList>;
123
151
  /** Deletes a profile; one that sandboxes still reference is refused (409). */
124
- deleteEgressProfile(name: string): Promise<void>;
125
- mounts(sandboxID: string): Promise<MountSpecRedacted[]>;
152
+ deleteEgressProfile(name: string, call?: CallOptions): Promise<void>;
153
+ /**
154
+ * Sets how many ready sandboxes every server with a warm pool keeps for an
155
+ * image (a full replace: the same call twice is a no-op). A create that names
156
+ * the image then starts from a warm sandbox. Admin only.
157
+ */
158
+ putWarmPool(image: string, options: WarmPoolOptions, call?: CallOptions): Promise<WarmPool>;
159
+ /** Returns an image's warm-pool entry with its status (ready and target, per server). */
160
+ getWarmPool(image: string, call?: CallOptions): Promise<WarmPool>;
161
+ /** Returns every warm-pool entry, by image, with its status. */
162
+ listWarmPools(call?: CallOptions): Promise<WarmPool[]>;
163
+ /** Deletes an image's warm-pool entry; its warm sandboxes are removed. Deleting a missing entry succeeds. */
164
+ deleteWarmPool(image: string, call?: CallOptions): Promise<void>;
165
+ /**
166
+ * Puts a role tag on a team's cloud identity allow list, or changes its
167
+ * minimum caller role (`"runner"` or `"admin"`). Admin only. The same call
168
+ * twice changes nothing, so it is safe to retry.
169
+ */
170
+ putIdentityRole(tag: string, options: IdentityRoleOptions, call?: CallOptions): Promise<IdentityRole>;
171
+ /** Lists a team's cloud identity allow list, one page at a time. Admin only. */
172
+ listIdentityRoles(options?: ListIdentityRolesOptions, call?: CallOptions): Promise<IdentityRoleList>;
173
+ /**
174
+ * Takes a role tag off a team's allow list. Admin only. Sandboxes that use
175
+ * it keep their current token (at most one hour) and get no new one.
176
+ * Deleting a tag that is already gone succeeds.
177
+ */
178
+ deleteIdentityRole(tag: string, options?: {
179
+ team?: string;
180
+ }, call?: CallOptions): Promise<void>;
181
+ /**
182
+ * Sets a team's quota: the most sandboxes, CPU and memory its sandboxes
183
+ * may hold. Admin only. The same limits twice change nothing. A create,
184
+ * resize or start past the quota fails with 429 `team_quota_exceeded`.
185
+ */
186
+ putTeamQuota(team: string, options: TeamQuotaOptions, call?: CallOptions): Promise<TeamQuota>;
187
+ /** Reads a team's quota and what the team holds now. 404 if it has none. */
188
+ getTeamQuota(team: string, call?: CallOptions): Promise<TeamQuota>;
189
+ /** Removes a team's quota. Removing one that is already gone succeeds. */
190
+ deleteTeamQuota(team: string, call?: CallOptions): Promise<void>;
191
+ mounts(sandboxID: string, call?: CallOptions): Promise<MountSpecRedacted[]>;
192
+ /**
193
+ * Make every token issued for a sandbox so far stop working (see
194
+ * `sandbox.revokeTokens()`). A token made after the call works.
195
+ */
196
+ revokeSandboxTokens(sandboxID: string, call?: CallOptions): Promise<RevokeSandboxTokensResult>;
126
197
  /**
127
198
  * Read a sandbox's clone-generation token. The token changes whenever the
128
199
  * sandbox is resumed from a snapshot, so a change signals "this is a clone."
129
200
  * Read-only — the SDK cannot reseed a process inside the guest; see the
130
201
  * "Randomness in cloned sandboxes" docs page for the in-guest reseed pattern.
131
202
  */
132
- cloneGeneration(sandboxID: string): Promise<CloneGeneration>;
203
+ cloneGeneration(sandboxID: string, call?: CallOptions): Promise<CloneGeneration>;
133
204
  execStream(sandboxID: string, options: ExecStreamOptions): ExecStreamHandle;
134
- createSession(sandboxID: string, options: CreateSessionOptions): Promise<Session>;
135
- listSessions(sandboxID: string): Promise<Session[]>;
136
- getSession(sandboxID: string, sessionID: string): Promise<Session>;
137
- deleteSession(sandboxID: string, sessionID: string): Promise<void>;
138
- signalSession(sandboxID: string, sessionID: string, signal: string): Promise<void>;
139
- resizeSession(sandboxID: string, sessionID: string, cols: number, rows: number): Promise<void>;
140
- sessionLog(sandboxID: string, sessionID: string): Promise<Uint8Array>;
141
- sessionRecording(sandboxID: string, sessionID: string): Promise<Uint8Array>;
205
+ /**
206
+ * Watch a folder in a sandbox for changes: `onEvent` gets each create,
207
+ * write, remove, rename and chmod, in batches every 250 ms. Resolves once
208
+ * the watch is in place. gVisor and Firecracker sandboxes only; Docker,
209
+ * containerd, WASM and isolate sandboxes reject with a 501
210
+ * `MicroVMApiError`. A sandbox whose agent predates file watching rejects
211
+ * with `MicroVMUnsupportedFeatureError`.
212
+ */
213
+ watchFiles(sandboxID: string, path: string, onEvent: (event: FileEvent) => void, options?: WatchFilesOptions): Promise<FileWatchHandle>;
214
+ createSession(sandboxID: string, options: CreateSessionOptions, call?: CallOptions): Promise<Session>;
215
+ listSessions(sandboxID: string, call?: CallOptions): Promise<Session[]>;
216
+ getSession(sandboxID: string, sessionID: string, call?: CallOptions): Promise<Session>;
217
+ deleteSession(sandboxID: string, sessionID: string, call?: CallOptions): Promise<void>;
218
+ signalSession(sandboxID: string, sessionID: string, signal: string, call?: CallOptions): Promise<void>;
219
+ resizeSession(sandboxID: string, sessionID: string, cols: number, rows: number, call?: CallOptions): Promise<void>;
220
+ sessionLog(sandboxID: string, sessionID: string, call?: CallOptions): Promise<Uint8Array>;
221
+ sessionRecording(sandboxID: string, sessionID: string, call?: CallOptions): Promise<Uint8Array>;
142
222
  attachSession(sandboxID: string, sessionID: string, options?: SessionAttachOptions): SessionAttachHandle;
143
223
  /**
144
224
  * Register a Firecracker rootfs template. Returns immediately with a
@@ -150,25 +230,25 @@ export declare class MicroVM {
150
230
  * duplicate ID returns 409 so a retried CI step does not create two
151
231
  * rows for the same logical template.
152
232
  */
153
- createTemplate(options: CreateTemplateOptions): Promise<Template>;
154
- listTemplates(): Promise<Template[]>;
155
- getTemplate(id: string): Promise<Template>;
156
- deleteTemplate(id: string): Promise<void>;
233
+ createTemplate(options: CreateTemplateOptions, call?: CallOptions): Promise<Template>;
234
+ listTemplates(call?: CallOptions): Promise<Template[]>;
235
+ getTemplate(id: string, call?: CallOptions): Promise<Template>;
236
+ deleteTemplate(id: string, call?: CallOptions): Promise<void>;
157
237
  /**
158
238
  * Register a WASM module in the host catalogue. Resolution is synchronous —
159
239
  * the returned row is typically already `ready`. Use the row's `id` or
160
240
  * `moduleRef` on subsequent `create` calls with `runtime: "wasm"`.
161
241
  */
162
- createWasmModule(options: CreateWasmModuleOptions): Promise<WasmModule>;
163
- listWasmModules(): Promise<WasmModule[]>;
164
- getWasmModule(id: string): Promise<WasmModule>;
165
- deleteWasmModule(id: string): Promise<void>;
242
+ createWasmModule(options: CreateWasmModuleOptions, call?: CallOptions): Promise<WasmModule>;
243
+ listWasmModules(call?: CallOptions): Promise<WasmModule[]>;
244
+ getWasmModule(id: string, call?: CallOptions): Promise<WasmModule>;
245
+ deleteWasmModule(id: string, call?: CallOptions): Promise<void>;
166
246
  /**
167
247
  * Upload a compiled core-wasip1 module to the registry under your own
168
248
  * credentials and get back the `oci://` ref to use as `moduleRef` on create.
169
249
  * The daemon validates and forwards the bytes; it never stores them.
170
250
  */
171
- pushWasmModule(options: PushWasmModuleOptions): Promise<PushWasmModuleResult>;
251
+ pushWasmModule(options: PushWasmModuleOptions, call?: CallOptions): Promise<PushWasmModuleResult>;
172
252
  /**
173
253
  * Re-run the snapshot phase against an existing template. Idempotent
174
254
  * under concurrent retry: the daemon's CAS collapses N parallel calls
@@ -180,7 +260,7 @@ export declare class MicroVM {
180
260
  * where rebuild is not safe (build in flight) or not supported
181
261
  * (`ready_no_snapshot` / `failed` — those need delete+recreate today).
182
262
  */
183
- rebuildTemplate(id: string): Promise<Template>;
263
+ rebuildTemplate(id: string, call?: CallOptions): Promise<Template>;
184
264
  /**
185
265
  * Cluster-level DNS helpers. Exposed as a namespaced accessor (rather
186
266
  * than a flat `ingressDNS()` method) so call sites read like
@@ -189,19 +269,21 @@ export declare class MicroVM {
189
269
  * see the current client even if MicroVM is later extended.
190
270
  */
191
271
  get dns(): {
192
- target(): Promise<IngressTarget>;
272
+ target(call?: CallOptions): Promise<IngressTarget>;
193
273
  };
194
274
  /**
195
275
  * Who the server says the caller is: principal, role, team and when the
196
276
  * credential expires. Every valid credential may ask.
197
277
  */
198
- whoami(): Promise<WhoAmI>;
278
+ whoami(call?: CallOptions): Promise<WhoAmI>;
199
279
  /**
200
280
  * Scoped API tokens (`avm_…`) for services and CI, as
201
281
  * `microvm.tokens.create/list/revoke`. Same namespaced shape as
202
282
  * {@link MicroVM.dns}.
203
283
  */
204
284
  get tokens(): Tokens;
285
+ /** The client for one call: the real one, or a view carrying the call's signal. */
286
+ private clientFor;
205
287
  private wrap;
206
288
  }
207
289
  export {};