@arker-ai/sdk 0.2.1 → 0.5.1

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/index.d.cts CHANGED
@@ -1,120 +1,797 @@
1
+ interface components {
2
+ schemas: {
3
+ /**
4
+ * @description Stable machine-readable error code. `unsupported_operation` means the backend doesn't implement the requested optional feature.
5
+ * @enum {string}
6
+ */
7
+ ErrorCode: "unsupported_operation" | "bad_request" | "unauthorized" | "forbidden" | "not_found" | "conflict" | "payload_too_large" | "not_implemented" | "resource_pressure" | "internal" | "unavailable" | "network_error";
8
+ ErrorResponse: {
9
+ code: components["schemas"]["ErrorCode"];
10
+ message: string;
11
+ };
12
+ /**
13
+ * @description Unified lifecycle state for a VM or a Session. `idle` means no command is currently executing; `running` means a command is in flight.
14
+ * @enum {string}
15
+ */
16
+ VmState: "idle" | "running";
17
+ SessionState: components["schemas"]["VmState"];
18
+ /**
19
+ * @description Lifecycle state for a Run. `running` = command in flight. `completed` = ran to completion; `exit_code` conveys success (0) or a non-zero program exit (still `completed`). `failed` = the platform could not run/finish the command (worker died, evicted mid-run); `fail_reason` explains why, distinct from the program's `stderr`. `cancelled` = cancelled by the client.
20
+ * @enum {string}
21
+ */
22
+ RunState: "running" | "completed" | "failed" | "cancelled";
23
+ /**
24
+ * @description `starting` = backend is allocating the tunnel; `open` = accepting
25
+ * connections; `closed` = torn down or never came up.
26
+ * @enum {string}
27
+ */
28
+ TunnelState: "starting" | "open" | "closed";
29
+ /** @enum {string} */
30
+ ResourceKind: "cpu" | "memory" | "disk";
31
+ NetworkPolicy: components["schemas"]["NetworkPolicyOpen"] | components["schemas"]["NetworkPolicyBlocked"] | components["schemas"]["NetworkPolicyAllow"] | components["schemas"]["NetworkPolicyBlock"];
32
+ NetworkPolicyOpen: {
33
+ /** @constant */
34
+ type: "open";
35
+ };
36
+ NetworkPolicyBlocked: {
37
+ /** @constant */
38
+ type: "blocked";
39
+ };
40
+ NetworkPolicyAllow: {
41
+ /** @constant */
42
+ type: "allow";
43
+ allow: string[];
44
+ };
45
+ NetworkPolicyBlock: {
46
+ /** @constant */
47
+ type: "block";
48
+ block: string[];
49
+ };
50
+ NetworkPolicyInput: boolean | string | components["schemas"]["NetworkPolicy"];
51
+ ForkRequest: {
52
+ /** @description Global VM identifier. Org is inferred from the row. */
53
+ source_vm_id?: string | null;
54
+ /** @description VM name within an org. Defaults `source_org_id` to the caller's org. A different org must be either the Arker org (for the public goldens `arkuntu` / `ubuntu`) or one with a `public: true` VM by that name. */
55
+ source_vm_name?: string | null;
56
+ /** @description Optional explicit org context for `source_vm_name`. SDK auto-fills the Arker org when forking the public goldens. */
57
+ source_org_id?: string | null;
58
+ /** @description Optional name for the new VM, scoped to the caller's org. */
59
+ name?: string | null;
60
+ /** @description Make the new VM publicly forkable from other orgs. */
61
+ public?: boolean | null;
62
+ network?: components["schemas"]["NetworkPolicyInput"] | null;
63
+ /** @default true */
64
+ disk?: boolean;
65
+ vcpu_count?: number | null;
66
+ memory_mib?: number | null;
67
+ max_memory_mib?: number | null;
68
+ disk_mib?: number | null;
69
+ durable?: boolean | null;
70
+ };
71
+ Session: {
72
+ session_id: string;
73
+ /** @default 0 */
74
+ session_idx?: number;
75
+ state: components["schemas"]["SessionState"];
76
+ cwd: string;
77
+ /** @description Optional environment-variable overrides for this session. */
78
+ env?: {
79
+ [key: string]: string;
80
+ } | null;
81
+ started_at?: string | null;
82
+ vm_id?: string | null;
83
+ vm_name?: string | null;
84
+ source_org_id?: string | null;
85
+ region?: string | null;
86
+ /** @enum {string|null} */
87
+ provider?: "aws" | "aws-burst" | null;
88
+ };
89
+ ListSessionsResponse: {
90
+ sessions: components["schemas"]["Session"][];
91
+ next_cursor?: string | null;
92
+ };
93
+ Vm: {
94
+ vm_id: string;
95
+ /** @description Org that owns this VM. */
96
+ owner_org_id: string;
97
+ created_at: string;
98
+ /** @description VM name, scoped to `owner_org_id`. */
99
+ name?: string | null;
100
+ /** @description When `true`, other orgs can fork this VM (but cannot run on it). */
101
+ public: boolean;
102
+ /** @description ID of the root (deepest-ancestor) source VM, if this VM was created by a chain of forks. None for VMs forked directly from an image. */
103
+ root_source_vm_id?: string | null;
104
+ /** @description Name of the root source VM. Populated together with `root_source_vm_id`. */
105
+ root_source_vm_name?: string | null;
106
+ state: components["schemas"]["VmState"];
107
+ region?: string | null;
108
+ /** @enum {string|null} */
109
+ provider?: "aws" | "aws-burst" | null;
110
+ started_at?: string | null;
111
+ vcpu_count?: number | null;
112
+ memory_mib?: number | null;
113
+ disk_mib?: number | null;
114
+ /** @description Worker host that owns this VM. Used by routers to populate caches without a fresh PlanetScale lookup. */
115
+ worker_id?: string | null;
116
+ sessions: components["schemas"]["Session"][];
117
+ tunnels?: components["schemas"]["Tunnel"][];
118
+ };
119
+ ListVmsResponse: {
120
+ vms: components["schemas"]["Vm"][];
121
+ next_cursor?: string | null;
122
+ };
123
+ DeleteVmResponse: {
124
+ deleted: boolean;
125
+ };
126
+ DeleteSessionResponse: {
127
+ deleted: boolean;
128
+ };
129
+ RunRequest: {
130
+ session_id?: string | null;
131
+ session_idx?: number | null;
132
+ command: string;
133
+ /** @default false */
134
+ background?: boolean;
135
+ timeout?: number | null;
136
+ /** @default auto */
137
+ end_symbol?: string | null;
138
+ vcpu_count?: number | null;
139
+ memory_mib?: number | null;
140
+ disk_mib?: number | null;
141
+ network?: components["schemas"]["NetworkRequest"] | null;
142
+ /**
143
+ * @description Comma-separated list of resources to ensure are
144
+ * pre-allocated (warm) before the run starts. Values: `cpu`,
145
+ * `memory`, `disk`. Example: `"cpu,memory"`.
146
+ */
147
+ acquire?: string | null;
148
+ /**
149
+ * @description Comma-separated list of resources to release after the run
150
+ * finishes. Values: `cpu`, `memory`, `disk`. `"cpu"` frees
151
+ * vCPU but keeps memory hot for the next run on this VM;
152
+ * `"cpu,memory,disk"` is a full release (closest to a
153
+ * suspend).
154
+ */
155
+ release?: string | null;
156
+ signal?: string | null;
157
+ };
158
+ NetworkRequest: {
159
+ inbound?: components["schemas"]["InboundRequest"] | null;
160
+ };
161
+ InboundRequest: {
162
+ /** @default {} */
163
+ ports?: {
164
+ [key: string]: components["schemas"]["InboundPortRequest"];
165
+ };
166
+ };
167
+ InboundPortRequest: {
168
+ /** @default private */
169
+ visibility?: string;
170
+ /** @default http */
171
+ protocol?: string;
172
+ };
173
+ RunResponse: components["schemas"]["CompletedRunResponse"] | components["schemas"]["BackgroundRunResponse"];
174
+ CompletedRunResponse: {
175
+ stdout: string;
176
+ /**
177
+ * @description TODO(encoding-normalize): goal is to always emit utf-8 from
178
+ * every source so this field becomes unnecessary. Until then
179
+ * the SDK uses it to decode.
180
+ */
181
+ stdout_encoding: string;
182
+ stderr: string;
183
+ stderr_encoding: string;
184
+ exit_code: number;
185
+ dispatch?: string | null;
186
+ };
187
+ BackgroundRunResponse: {
188
+ run_id: string;
189
+ /** @default [] */
190
+ tunnels?: components["schemas"]["Tunnel"][];
191
+ };
192
+ Run: {
193
+ run_id: string;
194
+ session_id?: string | null;
195
+ command?: string | null;
196
+ state: components["schemas"]["RunState"];
197
+ started_at: string;
198
+ completed_at?: string | null;
199
+ exit_code: number | null;
200
+ /** @description System failure explanation when `state` is `failed` (e.g. "worker died: <id>"). Distinct from `stderr`, which is the program's own output. */
201
+ fail_reason?: string | null;
202
+ stdout: string;
203
+ stdout_encoding: string;
204
+ stderr: string;
205
+ stderr_encoding: string;
206
+ tunnels: components["schemas"]["Tunnel"][];
207
+ /** @default 0 */
208
+ retry_count?: number;
209
+ vm_id?: string | null;
210
+ vm_name?: string | null;
211
+ source_org_id?: string | null;
212
+ region?: string | null;
213
+ /** @enum {string|null} */
214
+ provider?: "aws" | "aws-burst" | null;
215
+ };
216
+ RunSummary: {
217
+ run_id: string;
218
+ session_id?: string | null;
219
+ command?: string | null;
220
+ state: components["schemas"]["RunState"];
221
+ started_at: string;
222
+ completed_at?: string | null;
223
+ exit_code: number | null;
224
+ /** @description System failure explanation when `state` is `failed` (e.g. "worker died: <id>"). Distinct from `stderr`, which is the program's own output. */
225
+ fail_reason?: string | null;
226
+ vm_id?: string | null;
227
+ vm_name?: string | null;
228
+ source_org_id?: string | null;
229
+ region?: string | null;
230
+ /** @enum {string|null} */
231
+ provider?: "aws" | "aws-burst" | null;
232
+ };
233
+ ListRunsResponse: {
234
+ runs: components["schemas"]["RunSummary"][];
235
+ next_cursor?: string | null;
236
+ };
237
+ NetworkStatus: {
238
+ inbound: components["schemas"]["InboundStatus"];
239
+ };
240
+ InboundStatus: {
241
+ ports: {
242
+ [key: string]: components["schemas"]["InboundPortStatus"];
243
+ };
244
+ };
245
+ InboundPortStatus: {
246
+ requested: string;
247
+ observed: string;
248
+ effective: string;
249
+ protocol: string;
250
+ url?: string | null;
251
+ };
252
+ Tunnel: {
253
+ /** @description The VM this tunnel belongs to. Always populated, including when embedded in `Run.tunnels`. */
254
+ vm_id: string;
255
+ /** @description Unique-per-VM identifier. */
256
+ port: number;
257
+ /** @description The Run that opened this tunnel, if any. Tunnels allocated at fork time have `run_id: null`. */
258
+ run_id?: string | null;
259
+ visibility: string;
260
+ protocol: string;
261
+ url?: string | null;
262
+ state: components["schemas"]["TunnelState"];
263
+ message?: string | null;
264
+ started_at?: string | null;
265
+ vm_name?: string | null;
266
+ source_org_id?: string | null;
267
+ region?: string | null;
268
+ /** @enum {string|null} */
269
+ provider?: "aws" | "aws-burst" | null;
270
+ };
271
+ ListTunnelsResponse: {
272
+ tunnels: components["schemas"]["Tunnel"][];
273
+ next_cursor?: string | null;
274
+ };
275
+ DeleteTunnelResponse: {
276
+ deleted: boolean;
277
+ };
278
+ CancelRunResponse: {
279
+ cancelled: boolean;
280
+ };
281
+ CreateSessionRequest: {
282
+ env?: {
283
+ [key: string]: string;
284
+ } | null;
285
+ cwd?: string | null;
286
+ };
287
+ ResizeRequest: {
288
+ vcpu_count?: number | null;
289
+ memory_mib?: number | null;
290
+ disk_mib?: number | null;
291
+ };
292
+ ResizeResponse: {
293
+ resized: boolean;
294
+ };
295
+ Sync: {
296
+ sync_id: string;
297
+ vm_id: string;
298
+ filesystem_id: string;
299
+ /** @description VM-side path where the filesystem is mounted. Same field name as used by `SyncReadRequest.path`. */
300
+ path: string;
301
+ created_at: string;
302
+ vm_name?: string | null;
303
+ filesystem_name?: string | null;
304
+ source_org_id?: string | null;
305
+ region?: string | null;
306
+ /** @enum {string|null} */
307
+ provider?: "aws" | "aws-burst" | null;
308
+ live?: boolean;
309
+ live_error?: string;
310
+ idempotent?: boolean;
311
+ };
312
+ ListSyncsResponse: {
313
+ syncs: components["schemas"]["Sync"][];
314
+ next_cursor?: string | null;
315
+ };
316
+ DeleteSyncResponse: {
317
+ deleted: boolean;
318
+ };
319
+ SyncCreateRequest: {
320
+ filesystem_id: string;
321
+ /** @description VM-side path. Returns `ErrorResponse` code `conflict` if a sync already exists at this path. */
322
+ path?: string;
323
+ };
324
+ SyncReadRequest: {
325
+ /** @constant */
326
+ op: "read";
327
+ path: string;
328
+ };
329
+ SyncWriteRequest: {
330
+ /** @constant */
331
+ op: "write";
332
+ writes: components["schemas"]["SyncWriteEntry"][];
333
+ };
334
+ SyncWriteEntry: components["schemas"]["SyncChunkWrite"] | components["schemas"]["SyncPresignedWriteRequest"] | components["schemas"]["SyncPresignedWriteCommit"];
335
+ SyncChunkWrite: {
336
+ path: string;
337
+ size: number;
338
+ upload_id: string;
339
+ content: string;
340
+ start: number;
341
+ end: number;
342
+ sha256?: string | null;
343
+ /** @default false */
344
+ is_secret?: boolean;
345
+ };
346
+ SyncPresignedWriteRequest: {
347
+ path: string;
348
+ size: number;
349
+ presigned: boolean;
350
+ /** @default false */
351
+ is_secret?: boolean;
352
+ };
353
+ SyncPresignedWriteCommit: {
354
+ path: string;
355
+ size: number;
356
+ upload_id: string;
357
+ sha256?: string | null;
358
+ };
359
+ SyncReadResponse: components["schemas"]["SyncReadInlineResponse"] | components["schemas"]["SyncReadPresignedResponse"];
360
+ SyncReadInlineResponse: {
361
+ path: string;
362
+ size: number;
363
+ content: string;
364
+ encoding: string;
365
+ };
366
+ SyncReadPresignedResponse: {
367
+ path: string;
368
+ size: number;
369
+ presigned_url: string;
370
+ expires_in: number;
371
+ method: string;
372
+ };
373
+ SyncWriteResponse: {
374
+ results: components["schemas"]["SyncWriteResult"][];
375
+ };
376
+ SyncWriteResult: components["schemas"]["SyncChunkWriteResult"] | components["schemas"]["SyncPresignedWriteRequestResult"] | components["schemas"]["SyncCommitWriteResult"];
377
+ SyncChunkWriteResult: {
378
+ path: string;
379
+ size: number;
380
+ received_bytes: number;
381
+ ranges: components["schemas"]["SyncByteRange"][];
382
+ complete: boolean;
383
+ written: boolean;
384
+ error?: components["schemas"]["SyncEntryError"] | null;
385
+ };
386
+ SyncPresignedWriteRequestResult: {
387
+ path: string;
388
+ size: number;
389
+ presigned_url: string;
390
+ upload_id: string;
391
+ expires_in: number;
392
+ method: string;
393
+ complete: boolean;
394
+ written: boolean;
395
+ error?: components["schemas"]["SyncEntryError"] | null;
396
+ };
397
+ SyncCommitWriteResult: {
398
+ path: string;
399
+ size: number;
400
+ complete: boolean;
401
+ written: boolean;
402
+ error?: components["schemas"]["SyncEntryError"] | null;
403
+ };
404
+ SyncByteRange: {
405
+ start: number;
406
+ end: number;
407
+ };
408
+ SyncEntryError: {
409
+ code: string;
410
+ message: string;
411
+ };
412
+ Filesystem: {
413
+ filesystem_id: string;
414
+ name: string;
415
+ owner_org_id: string;
416
+ created_at: string;
417
+ size_bytes?: number | null;
418
+ /** @default us-west-2 */
419
+ region?: string | null;
420
+ /**
421
+ * @default aws
422
+ * @enum {string|null}
423
+ */
424
+ provider?: "aws" | "aws-burst" | null;
425
+ };
426
+ ListFilesystemsResponse: {
427
+ filesystems: components["schemas"]["Filesystem"][];
428
+ next_cursor?: string | null;
429
+ };
430
+ DeleteFilesystemResponse: {
431
+ deleted: boolean;
432
+ };
433
+ FilesystemCreateRequest: {
434
+ name: string;
435
+ };
436
+ };
437
+ responses: {
438
+ /** @description API error. */
439
+ Error: {
440
+ headers: {
441
+ [name: string]: unknown;
442
+ };
443
+ content: {
444
+ "application/json": components["schemas"]["ErrorResponse"];
445
+ };
446
+ };
447
+ /** @description The request is valid, but this backend does not support the requested operation or option. */
448
+ UnsupportedOperation: {
449
+ headers: {
450
+ [name: string]: unknown;
451
+ };
452
+ content: {
453
+ "application/json": components["schemas"]["ErrorResponse"];
454
+ };
455
+ };
456
+ };
457
+ parameters: {
458
+ VmId: string;
459
+ RunId: string;
460
+ SessionId: string;
461
+ SyncId: string;
462
+ TunnelPort: number;
463
+ FilesystemId: string;
464
+ /** @description Opaque pagination cursor returned by the previous page's `next_cursor`. */
465
+ Cursor: string | null;
466
+ /** @description Max items per page. Backend caps may apply. */
467
+ Limit: number;
468
+ };
469
+ requestBodies: never;
470
+ headers: never;
471
+ pathItems: never;
472
+ }
473
+
1
474
  /**
2
- * Arker SDK — TypeScript client.
3
- *
4
- * Quickstart:
5
- *
6
- * import { Arker } from "@arker-ai/sdk";
7
- * const arker = new Arker({ apiKey: "ark_live_..." });
8
- * const vm = await arker.vm("arkuntu").fork({ name: "hello" });
9
- *
10
- * const result = await vm.run("echo hi");
11
- * console.log(new TextDecoder().decode(result.stdout)); // → "hi\n"
12
- *
13
- * await vm.sync.writeFile("/home/user/data.bin", new Uint8Array([1, 2, 3]));
14
- * const blob = await vm.sync.readFile("/home/user/data.bin");
15
- *
16
- * const child = await vm.fork({ name: "branch" });
17
- * await child.delete();
18
- * await vm.delete();
19
- *
20
- * // List your VMs (paginated):
21
- * const page = await arker.list({ limit: 10 });
22
- * for (const summary of page.items) {
23
- * console.log(summary.vm_id, summary.name, summary.created_at);
24
- * }
475
+ * Arker TypeScript SDK.
25
476
  *
26
- * Errors are thrown as `ArkerError(code, message, status)`.
477
+ * A small wrapper around the VM API. Configure a region for the standard
478
+ * Arker endpoints, or pass baseUrl directly for internal/dev targets.
27
479
  */
28
- declare const DEFAULT_BASE_URL = "https://aws-burst-us-west-2.arker.ai";
29
- /** `list` is served from a different host than the rest; used regardless of the client's baseUrl. */
30
- declare const LIST_BASE_URL = "https://arker.ai";
31
- /** 1000 pre-forked public VMs (snapshots of `arkuntu`). The SDK picks one
32
- * at random per `vm("arkuntu").fork()` call so concurrent fork bursts
33
- * fan out across distinct source state.log keys, avoiding per-key
34
- * throttling under load. */
35
- declare const ARKUNTU_POOL: readonly string[];
36
- /** Source-VM aliases. `arkuntu` resolves to the 1000-VM pool above. */
37
- declare const SOURCE_ALIASES: Record<string, readonly string[] | string>;
38
- /** Files above this size go through a direct upload path. */
480
+
481
+ type ApiSchema<Name extends keyof components["schemas"]> = components["schemas"][Name];
39
482
  declare const CHUNK_SIZE: number;
40
- interface ArkerOptions {
41
- apiKey: string;
42
- baseUrl?: string;
483
+ /**
484
+ * Org id for the "Arker" org — the org that owns the public golden VMs
485
+ * (`arkuntu`, `ubuntu`, `ubuntu-full`, `ubuntu-py-repl`, …). Pass it as
486
+ * `sourceOrgId` to fork a public golden:
487
+ *
488
+ * arker.fork({ sourceVmName: "ubuntu-full", sourceOrgId: ARKER_ORG_ID })
489
+ */
490
+ declare const ARKER_ORG_ID = "ArkerHQ";
491
+ type FetchLike = typeof fetch;
492
+ type HttpMethod = "GET" | "POST" | "DELETE";
493
+ interface RetryOptions {
494
+ attempts?: number;
495
+ baseDelayMs?: number;
496
+ maxDelayMs?: number;
497
+ jitterMs?: number;
43
498
  }
44
- interface ForkOptions {
45
- name?: string;
46
- isPublic?: boolean;
499
+ interface ArkerOptions {
500
+ apiKey?: string;
501
+ /** Region (e.g. `"us-west-2"`). Combined with `provider` to build the
502
+ * compute endpoint. Back-compat: accepts the legacy combined form
503
+ * `"aws-us-west-2"`. */
47
504
  region?: string;
505
+ /** Provider for compute calls. Defaults to `"aws"` (arkerd-managed
506
+ * VMs). Use `"aws-burst"` to target the Lambda burst backend
507
+ * directly. Has no effect on the burst-classified routing — a fork
508
+ * of `arkuntu` in the Arker org still goes to burst regardless. */
509
+ provider?: "aws" | "aws-burst";
510
+ /** Override the compute base URL (e.g. for internal / dev targets).
511
+ * If set, `provider` + `region` are ignored for compute. */
512
+ baseUrl?: string;
513
+ /** Override the burst compute base URL. */
514
+ burstBaseUrl?: string;
515
+ /** Override the control-plane URL — the CF Worker that owns
516
+ * administrative endpoints like `GET /v1/vms` (cross-provider list)
517
+ * and `/v1/filesystems`. Default `https://arker.ai/api`. */
518
+ controlBaseUrl?: string;
519
+ fetch?: FetchLike;
520
+ retry?: RetryOptions | false;
48
521
  }
49
- interface RunOptions {
50
- sessionId?: string | number;
51
- timeout?: number;
52
- }
53
- interface RunResult {
522
+ type VmState = ApiSchema<"VmState">;
523
+ type SessionState = ApiSchema<"SessionState">;
524
+ type RunState = ApiSchema<"RunState">;
525
+ type TunnelState = ApiSchema<"TunnelState">;
526
+ type ResourceKind = ApiSchema<"ResourceKind">;
527
+ type ErrorCode = ApiSchema<"ErrorCode">;
528
+ type NetworkPolicy = ApiSchema<"NetworkPolicy">;
529
+ type NetworkPolicyInput = ApiSchema<"NetworkPolicyInput">;
530
+ type ForkRequest = ApiSchema<"ForkRequest">;
531
+ type ForkOptions = ForkRequest;
532
+ type Session = ApiSchema<"Session">;
533
+ type Vm = ApiSchema<"Vm">;
534
+ type ListVmsResponse = ApiSchema<"ListVmsResponse">;
535
+ type ListSessionsResponse = ApiSchema<"ListSessionsResponse">;
536
+ type DeleteVmResponse = ApiSchema<"DeleteVmResponse">;
537
+ type DeleteSessionResponse = ApiSchema<"DeleteSessionResponse">;
538
+ type Filesystem = ApiSchema<"Filesystem">;
539
+ type ListFilesystemsResponse = ApiSchema<"ListFilesystemsResponse">;
540
+ type DeleteFilesystemResponse = ApiSchema<"DeleteFilesystemResponse">;
541
+ type FilesystemCreateRequest = ApiSchema<"FilesystemCreateRequest">;
542
+ type Sync = ApiSchema<"Sync">;
543
+ type ListSyncsResponse = ApiSchema<"ListSyncsResponse">;
544
+ type DeleteSyncResponse = ApiSchema<"DeleteSyncResponse">;
545
+ type SyncCreateRequest = ApiSchema<"SyncCreateRequest">;
546
+ type SyncReadRequest = ApiSchema<"SyncReadRequest">;
547
+ type SyncWriteRequest = ApiSchema<"SyncWriteRequest">;
548
+ type SyncReadResponse = ApiSchema<"SyncReadResponse">;
549
+ type SyncReadInlineResponse = ApiSchema<"SyncReadInlineResponse">;
550
+ type SyncReadPresignedResponse = ApiSchema<"SyncReadPresignedResponse">;
551
+ type SyncWriteResponse = ApiSchema<"SyncWriteResponse">;
552
+ type SyncWriteResult = ApiSchema<"SyncWriteResult">;
553
+ type SyncChunkWriteResult = ApiSchema<"SyncChunkWriteResult">;
554
+ type SyncPresignedWriteRequestResult = ApiSchema<"SyncPresignedWriteRequestResult">;
555
+ type SyncCommitWriteResult = ApiSchema<"SyncCommitWriteResult">;
556
+ type SyncByteRange = ApiSchema<"SyncByteRange">;
557
+ type RunRequest = ApiSchema<"RunRequest">;
558
+ type RunOptions = Partial<Omit<RunRequest, "command">> & {
559
+ /**
560
+ * Optional idempotency key for retrying the run. Sent as the
561
+ * `Idempotency-Key` HTTP header.
562
+ */
563
+ idempotencyKey?: string;
564
+ };
565
+ type InboundPortRequest = ApiSchema<"InboundPortRequest">;
566
+ type NetworkRequest = ApiSchema<"NetworkRequest">;
567
+ type Tunnel = ApiSchema<"Tunnel">;
568
+ type ListTunnelsResponse = ApiSchema<"ListTunnelsResponse">;
569
+ type DeleteTunnelResponse = ApiSchema<"DeleteTunnelResponse">;
570
+ type NetworkStatus = ApiSchema<"NetworkStatus">;
571
+ type RunResponse = ApiSchema<"RunResponse">;
572
+ type CompletedRunResponse = ApiSchema<"CompletedRunResponse">;
573
+ type BackgroundRunResponse = ApiSchema<"BackgroundRunResponse">;
574
+ type Run = ApiSchema<"Run">;
575
+ type RunSummary = ApiSchema<"RunSummary">;
576
+ type ListRunsResponse = ApiSchema<"ListRunsResponse">;
577
+ type CancelRunResponse = ApiSchema<"CancelRunResponse">;
578
+ type CreateSessionRequest = ApiSchema<"CreateSessionRequest">;
579
+ type ResizeRequest = ApiSchema<"ResizeRequest">;
580
+ type ResizeResponse = ApiSchema<"ResizeResponse">;
581
+ type ErrorResponse = ApiSchema<"ErrorResponse">;
582
+ /** @deprecated Use `Session`. */
583
+ type SessionInfo = Session;
584
+ /** @deprecated Use `Run`. */
585
+ type RunStatusResponse = Run;
586
+ /** @deprecated Use `NetworkRequest`. */
587
+ type RunNetworkRequest = NetworkRequest;
588
+ /** @deprecated Use `NetworkStatus`. */
589
+ type RunNetworkStatus = NetworkStatus;
590
+ /** @deprecated Use `InboundPortRequest`. */
591
+ type RunInboundPortRequest = InboundPortRequest;
592
+ /** @deprecated Use `Tunnel`. */
593
+ type RunTunnelStatus = Tunnel;
594
+ interface CompletedRunResult {
595
+ type: "completed";
596
+ /** The run's own id. Present for executed runs; absent for operation acks. */
597
+ runId?: string;
598
+ /** Lifecycle state — "completed" or "failed". Mirrors the run-status (`Run`) shape. */
599
+ state: string;
54
600
  stdout: Uint8Array;
601
+ stdoutEncoding: string;
55
602
  stderr: Uint8Array;
603
+ stderrEncoding: string;
56
604
  exitCode: number;
57
- durationMs: number;
58
- sessionId: string;
59
- cwd: string;
60
- }
61
- interface VmSummary {
62
- vm_id: string;
63
- name: string | null;
64
- base_image: string;
65
- region: string;
66
- /** ISO 8601 UTC. */
67
- created_at: string;
68
- }
69
- interface VmList {
70
- items: VmSummary[];
71
- /** Total matching the query, ignoring limit/offset. */
72
- total: number;
605
+ /** System failure explanation when `state` is "failed". Distinct from
606
+ * `stderr` (the program's own error output); null otherwise. */
607
+ failReason?: string | null;
73
608
  }
74
- interface ListOptions {
75
- limit?: number;
76
- offset?: number;
77
- q?: string;
78
- /** `created_at` | `-created_at` | `region` | `-region`. Default `-created_at`. */
79
- sort?: string;
609
+ interface BackgroundRunResult {
610
+ type: "background";
611
+ runId: string;
612
+ /** Lifecycle state — "running". */
613
+ state: string;
614
+ tunnels: Tunnel[];
80
615
  }
616
+ type RunResult = CompletedRunResult | BackgroundRunResult;
81
617
  declare class ArkerError extends Error {
82
618
  readonly code: string;
83
619
  readonly status: number;
84
620
  constructor(code: string, message: string, status: number);
85
621
  }
622
+ /** Source for `Arker.fork()`. Exactly one of `sourceVmId` or
623
+ * `sourceVmName` must be set. When `sourceVmName` is set,
624
+ * `sourceOrgId` selects which org to look the name up in (defaults
625
+ * server-side to the caller's org; pass `ARKER_ORG_ID` to fork the
626
+ * public goldens like `"arkuntu"` / `"ubuntu"`).
627
+ *
628
+ * Distinct from the new VM's `name`, which is the *destination* name. */
629
+ interface ForkSource {
630
+ sourceVmId?: string;
631
+ sourceVmName?: string;
632
+ sourceOrgId?: string;
633
+ }
86
634
  declare class Arker {
635
+ /** Compute base URL for `provider` + `region` — used for fork/run/
636
+ * per-VM ops. SDK calls go straight to this host, skipping the CF
637
+ * Worker control plane. */
638
+ readonly baseUrl: string;
639
+ /** Compute base URL for the burst provider in this region. */
640
+ readonly burstBaseUrl?: string;
641
+ /** CF Worker control-plane URL — used for cross-cutting admin calls
642
+ * like list-VMs and filesystems. */
643
+ readonly controlBaseUrl: string;
644
+ readonly region?: string;
645
+ readonly provider: "aws" | "aws-burst";
87
646
  private readonly apiKey;
88
- private readonly baseUrl;
89
- constructor(opts: ArkerOptions);
647
+ private readonly fetchImpl;
648
+ private readonly retry;
649
+ constructor(opts?: ArkerOptions);
650
+ /**
651
+ * Address an existing VM. Doesn't make any network calls; returns a
652
+ * lightweight handle.
653
+ */
654
+ vm(vmId: string): VM;
655
+ /**
656
+ * Create a new VM by forking from a source.
657
+ *
658
+ * fork("ubuntu-full") // public golden by name
659
+ * fork("base") // a VM by name in your org
660
+ * fork(vm) // an existing VM (uses its id)
661
+ * fork({ sourceVmId: "vm_abc..." })
662
+ * fork({ sourceVmName: "base", sourceOrgId: "org_..." })
663
+ *
664
+ * The source can be a name string, a `VM` handle, or a `ForkSource`
665
+ * object. `sourceOrgId` defaults to the Arker org when `sourceVmName`
666
+ * is a known public golden, otherwise to your own org; an explicit
667
+ * value always wins, and it's irrelevant when forking by id. Forking a
668
+ * VM in another org requires that VM to be `public: true`. The new VM's
669
+ * name (in your org) is passed as `name`. When the source is a name or
670
+ * `VM`, extra fork options go in the second `opts` argument.
671
+ */
672
+ fork(source: string | VM | (ForkSource & Partial<Omit<ForkRequest, "source_vm_id" | "source_vm_name" | "source_org_id">>), opts?: Partial<Omit<ForkRequest, "source_vm_id" | "source_vm_name" | "source_org_id">>): Promise<VM>;
673
+ /**
674
+ * List VMs visible to the authenticated caller. **Admin call** —
675
+ * goes through the control plane (`controlBaseUrl`) so it can
676
+ * aggregate across providers and regions. Pass `?provider=` /
677
+ * `?region=` to narrow.
678
+ */
679
+ listVms(opts?: ListOpts & {
680
+ region?: string;
681
+ provider?: "aws" | "aws-burst";
682
+ state?: VmState;
683
+ sourceOrgId?: string;
684
+ startedAfter?: string;
685
+ startedBefore?: string;
686
+ }): Promise<{
687
+ vms: VM[];
688
+ nextCursor: string | null;
689
+ }>;
690
+ /** Compute call — goes direct to the backend hosting this VM (no
691
+ * control-plane hop). Returns a fully-populated VM handle. */
692
+ getVm(vmId: string): Promise<VM>;
693
+ listFilesystems(opts?: ListOpts & {
694
+ namePrefix?: string;
695
+ }): Promise<ListFilesystemsResponse>;
696
+ createFilesystem(request: {
697
+ name: string;
698
+ }): Promise<Filesystem>;
699
+ getFilesystem(filesystemId: string): Promise<Filesystem>;
700
+ deleteFilesystem(filesystemId: string): Promise<DeleteFilesystemResponse>;
701
+ /** @internal */
702
+ _request<T>(method: HttpMethod, path: string, body?: unknown, baseUrl?: string, extraHeaders?: Record<string, string | undefined>): Promise<T>;
90
703
  /** @internal */
91
- _request<T = any>(method: string, path: string, body?: unknown, overrideBaseUrl?: string): Promise<T>;
92
- /** Open a handle to a VM by ULID *or* template name. No network call. */
93
- vm(vmId: string): Computer;
94
- /** List VMs in the caller's organization. Always hits `https://arker.ai`. */
95
- list(opts?: ListOptions): Promise<VmList>;
704
+ _fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
705
+ /** @internal */
706
+ _retryAttempts(): number;
707
+ /** @internal */
708
+ _retryDelay(attempt: number): number;
709
+ /** @internal */
710
+ _baseUrlFor(ref: string): string;
96
711
  }
97
- declare class Computer {
712
+ interface ListOpts {
713
+ cursor?: string;
714
+ limit?: number;
715
+ }
716
+ declare class VM {
98
717
  readonly id: string;
99
- readonly sync: Sync;
718
+ readonly baseUrl: string;
100
719
  /** @internal */
101
720
  readonly _client: Arker;
102
- constructor(client: Arker, vmId: string);
103
- delete(): Promise<void>;
104
- /** Fork this VM. Aliases like `"arkuntu"` resolve client-side. */
105
- fork(opts?: ForkOptions): Promise<Computer>;
106
- run(command: string, opts?: RunOptions): Promise<RunResult>;
107
- }
108
- declare class Sync {
109
- /** @internal */
110
- readonly _vm: Computer;
111
- constructor(vm: Computer);
112
- private path;
113
- readFile(path: string): Promise<Uint8Array>;
114
- writeFile(path: string, data: Uint8Array | string): Promise<void>;
115
- private fastPath;
116
- private presignedPath;
721
+ readonly vm_id?: string;
722
+ readonly name?: string | null;
723
+ readonly state?: VmState;
724
+ readonly owner_org_id?: string;
725
+ readonly created_at?: string;
726
+ readonly public?: boolean;
727
+ readonly region?: string | null;
728
+ readonly provider?: string | null;
729
+ readonly vcpu_count?: number | null;
730
+ readonly memory_mib?: number | null;
731
+ readonly disk_mib?: number | null;
732
+ readonly started_at?: string | null;
733
+ readonly root_source_vm_id?: string | null;
734
+ readonly root_source_vm_name?: string | null;
735
+ readonly worker_id?: string | null;
736
+ readonly sessions?: Session[];
737
+ readonly tunnels?: Tunnel[];
738
+ constructor(client: Arker, vmId: string, baseUrl?: string, data?: Vm);
739
+ /** Re-fetch this VM and return a fresh, fully-populated handle. */
740
+ refresh(): Promise<VM>;
741
+ /**
742
+ * @deprecated Use `Arker.fork({ sourceVmId: this.id, ... })`.
743
+ * Kept for back-compat with older user code that called `.fork()` on
744
+ * a VM instance.
745
+ */
746
+ fork(request?: Partial<ForkRequest>): Promise<VM>;
747
+ run(command: string, options?: RunOptions): Promise<RunResult>;
748
+ /**
749
+ * Read or write a file in this VM over `POST /v1/vms/{id}/sync`.
750
+ * Omit `data` to read; pass `data` (string or bytes) to write. The
751
+ * client picks inline transfer for small files and presigned uploads
752
+ * for large ones automatically.
753
+ *
754
+ * const bytes = await vm.sync("/home/user/out.txt"); // read
755
+ * await vm.sync("/home/user/in.txt", "hello\n"); // write
756
+ *
757
+ * To mount a standalone filesystem into the VM, use `vm.syncs.create`.
758
+ */
759
+ sync(path: string): Promise<Uint8Array>;
760
+ sync(path: string, data: Uint8Array | string): Promise<void>;
761
+ private syncRead;
762
+ private syncWriteInline;
763
+ private syncWritePresigned;
764
+ private putPresigned;
117
765
  private sendOneWrite;
766
+ resize(request: ResizeRequest): Promise<ResizeResponse>;
767
+ delete(): Promise<DeleteVmResponse>;
768
+ listSyncs(opts?: ListOpts & {
769
+ filesystemId?: string;
770
+ }): Promise<ListSyncsResponse>;
771
+ createSync(request: {
772
+ filesystemId: string;
773
+ path?: string;
774
+ }): Promise<Sync>;
775
+ deleteSync(syncId: string): Promise<DeleteSyncResponse>;
776
+ listRuns(opts?: ListOpts & {
777
+ state?: RunState;
778
+ startedAfter?: string;
779
+ startedBefore?: string;
780
+ completedAfter?: string;
781
+ }): Promise<ListRunsResponse>;
782
+ getRun(runId: string): Promise<Run>;
783
+ cancelRun(runId: string): Promise<CancelRunResponse>;
784
+ listSessions(opts?: ListOpts & {
785
+ state?: SessionState;
786
+ }): Promise<ListSessionsResponse>;
787
+ createSession(request?: CreateSessionRequest): Promise<Session>;
788
+ getSession(sessionId: string): Promise<Session>;
789
+ deleteSession(sessionId: string): Promise<DeleteSessionResponse>;
790
+ listTunnels(opts?: ListOpts & {
791
+ state?: TunnelState;
792
+ }): Promise<ListTunnelsResponse>;
793
+ getTunnel(port: number): Promise<Tunnel>;
794
+ deleteTunnel(port: number): Promise<DeleteTunnelResponse>;
118
795
  }
119
796
 
120
- export { ARKUNTU_POOL, Arker, ArkerError, type ArkerOptions, CHUNK_SIZE, Computer, DEFAULT_BASE_URL, type ForkOptions, LIST_BASE_URL, type ListOptions, type RunOptions, type RunResult, SOURCE_ALIASES, Sync, type VmList, type VmSummary };
797
+ export { ARKER_ORG_ID, Arker, ArkerError, type ArkerOptions, type BackgroundRunResponse, type BackgroundRunResult, CHUNK_SIZE, type CancelRunResponse, type CompletedRunResponse, type CompletedRunResult, type CreateSessionRequest, type DeleteFilesystemResponse, type DeleteSessionResponse, type DeleteSyncResponse, type DeleteTunnelResponse, type DeleteVmResponse, type ErrorCode, type ErrorResponse, type Filesystem, type FilesystemCreateRequest, type ForkOptions, type ForkRequest, type ForkSource, type InboundPortRequest, type ListFilesystemsResponse, type ListOpts, type ListRunsResponse, type ListSessionsResponse, type ListSyncsResponse, type ListTunnelsResponse, type ListVmsResponse, type NetworkPolicy, type NetworkPolicyInput, type NetworkRequest, type NetworkStatus, type ResizeRequest, type ResizeResponse, type ResourceKind, type RetryOptions, type Run, type RunInboundPortRequest, type RunNetworkRequest, type RunNetworkStatus, type RunOptions, type RunRequest, type RunResponse, type RunResult, type RunState, type RunStatusResponse, type RunSummary, type RunTunnelStatus, type Session, type SessionInfo, type SessionState, type Sync, type SyncByteRange, type SyncChunkWriteResult, type SyncCommitWriteResult, type SyncCreateRequest, type SyncPresignedWriteRequestResult, type SyncReadInlineResponse, type SyncReadPresignedResponse, type SyncReadRequest, type SyncReadResponse, type SyncWriteRequest, type SyncWriteResponse, type SyncWriteResult, type Tunnel, type TunnelState, VM, type Vm, type VmState };