@arker-ai/sdk 0.3.0 → 0.5.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/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  # Arker TypeScript SDK
2
2
 
3
- Small TypeScript wrapper for the Arker VM API. The SDK keeps API keys,
4
- region routing, retries, output decoding, and file sync ergonomics in one place.
3
+ A small, typed wrapper around the Arker VM API: fork a machine, run commands, sync files.
5
4
 
6
5
  ## Install
7
6
 
@@ -9,153 +8,69 @@ region routing, retries, output decoding, and file sync ergonomics in one place.
9
8
  npm install @arker-ai/sdk
10
9
  ```
11
10
 
12
- Node 18 or newer is required.
11
+ Node 18+. The client reads your key from `ARKER_API_KEY` — get one in the [console](https://arker.ai/console).
13
12
 
14
13
  ## Quickstart
15
14
 
16
15
  ```ts
17
16
  import { Arker } from "@arker-ai/sdk";
18
17
 
19
- const arker = new Arker({
20
- apiKey: process.env.ARKER_API_KEY,
21
- region: process.env.ARKER_REGION ?? "aws-us-west-2",
22
- });
18
+ const ar = new Arker({ region: "us-west-2" });
23
19
 
24
- const vm = await arker.vm("ubuntu").fork({ name: "hello" });
25
- const result = await vm.run("printf 'hello\\n'");
20
+ // Fork a public golden, run a command, read/write a file.
21
+ const vm = await ar.fork("ubuntu-full"); // public golden — org inferred
26
22
 
27
- if (result.type === "completed") {
28
- console.log(new TextDecoder().decode(result.stdout));
29
- }
23
+ const run = await vm.run("python3 -c 'print(2 + 2)'");
24
+ if (run.type === "completed") console.log(new TextDecoder().decode(run.stdout));
30
25
 
31
- await vm.sync.writeFile("/home/user/data.txt", "hello\n");
32
- const data = await vm.sync.readFile("/home/user/data.txt");
26
+ await vm.sync("/tmp/data.txt", "hello\n"); // write
27
+ const data = await vm.sync("/tmp/data.txt"); // read -> Uint8Array
33
28
 
34
29
  await vm.delete();
35
30
  ```
36
31
 
37
- `region` selects the regional Arker endpoints. The SDK routes `arkuntu` and
38
- burst VM ids to the burst endpoint for that region; other golden names and VM
39
- ids use the normal regional endpoint. There is no cross-region VM replication.
40
-
41
- ```bash
42
- export ARKER_REGION=aws-us-west-2
43
- ```
44
-
45
- For internal or dev targets, pass `baseUrl` directly. If an endpoint mounts the
46
- API under `/api`, include that prefix.
47
-
48
- ## API
32
+ ## Core API
49
33
 
50
34
  ```ts
51
- new Arker({ apiKey?, region?, baseUrl?, burstBaseUrl?, retry? })
52
- .vm(vmId)
53
- .goldens()
54
- .list()
55
- .get(vmId)
56
-
57
- Computer
58
- .fork(request)
59
- .run(command, options)
60
- .runStatus(runId)
61
- .cancelRun(runId)
62
- .delete()
63
- .sync.readFile(path)
64
- .sync.writeFile(path, data)
35
+ const ar = new Arker({ region, apiKey?, baseUrl?, retry? });
36
+
37
+ // VMs
38
+ await ar.fork("ubuntu-full"); // public golden by name (org inferred)
39
+ await ar.fork(vm, { name: "child" }); // an existing VM (uses its id)
40
+ await ar.fork({ sourceVmName, sourceOrgId, name?, durable? });
41
+ await ar.listVms({ state? });
42
+ ar.vm(vmId); // bare handle
43
+ await ar.vm(vmId).run(command, options?);
44
+ await ar.vm(vmId).resize({ vcpu_count, memory_mib });
45
+ await ar.vm(vmId).delete();
46
+
47
+ // Files inside a VM
48
+ await vm.sync(path); // read -> Uint8Array
49
+ await vm.sync(path, data); // write
50
+
51
+ // Filesystems — standalone, persistent volumes
52
+ await ar.createFilesystem({ name });
53
+ await ar.listFilesystems();
54
+ await ar.deleteFilesystem(filesystemId);
55
+
56
+ // Syncs — mount a filesystem into a VM at a path
57
+ await vm.createSync({ filesystemId, path });
58
+ await vm.listSyncs();
59
+ await vm.deleteSync(syncId);
65
60
  ```
66
61
 
67
- `apiKey` falls back to `ARKER_API_KEY` or `AUTH_KEY`.
68
- `region` falls back to `ARKER_REGION`; `baseUrl` falls back to
69
- `ARKER_BASE_URL`. There is no built-in default region.
70
-
71
- Retries are configured on the client:
72
-
73
- ```ts
74
- const arker = new Arker({
75
- apiKey: "ark_live_...",
76
- region: "aws-us-west-2",
77
- retry: { attempts: 4, baseDelayMs: 200, maxDelayMs: 2000 },
78
- });
79
- ```
80
-
81
- Pass `retry: false` to disable SDK retries.
62
+ `apiKey` falls back to `ARKER_API_KEY`; `region` to `ARKER_REGION`. Pass `baseUrl` for dev targets. Configure retries with `retry: { attempts, baseDelayMs, maxDelayMs }`, or `retry: false` to disable.
82
63
 
83
64
  ## Durability
84
65
 
85
- For long-running or non-idempotent work, request a durable VM at fork
86
- time and pass an idempotency key when retrying `run`:
66
+ For long-running or non-idempotent work, fork with `durable: true` and pass an idempotency key when retrying a run:
87
67
 
88
68
  ```ts
89
- const vm = await arker.vm("ubuntu").fork({ name: "job", durable: true });
90
-
91
- const run = await vm.run("python3 train.py", {
92
- background: true,
93
- idempotencyKey: "550e8400-e29b-41d4-a716-446655440000",
94
- });
69
+ const vm = await ar.fork("ubuntu-full", { durable: true });
70
+ await vm.run("python3 train.py", { background: true, idempotencyKey: crypto.randomUUID() });
95
71
  ```
96
72
 
97
- - If the underlying host fails mid-run, the run resumes on a healthy
98
- host with the VM's filesystem state preserved.
99
- - A `run` retried with the same `idempotencyKey` and the same request
100
- returns the original `run_id`. A different request under the same key
101
- returns `ArkerError` code `conflict`.
102
- - `runStatus().retry_count` is the number of automatic retries the run
103
- has gone through — `0` for runs that completed without interruption.
104
-
105
- Forked children default to non-durable. Backends without durability
106
- support return `ArkerError` code `unsupported_operation` when
107
- `durable: true` is requested.
108
-
109
- ## API Contract
110
-
111
- The SDK request and response types are generated from
112
- `../contract/openapi.json`. The client itself is handwritten.
113
-
114
- After updating the vendored contract:
115
-
116
- ```bash
117
- npm run generate:api-types
118
- npm run check:api-types
119
- ```
120
-
121
- ## Routing
122
-
123
- With `region: "aws-us-west-2"`, the SDK uses
124
- `https://aws-us-west-2.arker.ai` for normal VMs and
125
- `https://aws-burst-us-west-2.arker.ai/api` for `arkuntu` and burst VM ids.
126
- The returned `Computer` stays pinned to the endpoint that created it.
127
-
128
- ## Smoke Test
129
-
130
- The conformance smoke test uses raw HTTP and checks the fork/run/sync wire
131
- shape without going through the SDK:
132
-
133
- ```bash
134
- ARKER_API_KEY=ark_live_... \
135
- ARKER_BASE_URL=https://aws-us-west-2.arker.ai \
136
- ARKER_SOURCE_VM=ubuntu \
137
- npm run smoke
138
- ```
139
-
140
- To compare two backends:
141
-
142
- ```bash
143
- ARKER_API_KEY=ark_live_... \
144
- ARKER_SMOKE_TARGETS='[
145
- {"name":"burst","baseUrl":"https://aws-burst-us-west-2.arker.ai/api","source":"01KQH2ADR3DCAJF06N4R453WPJ_uswe"},
146
- {"name":"ubuntu","baseUrl":"https://aws-us-west-2.arker.ai","source":"ubuntu"}
147
- ]' \
148
- npm run smoke
149
- ```
150
-
151
- ## Demo
152
-
153
- ```bash
154
- ARKER_API_KEY=ark_live_... \
155
- ARKER_REGION=aws-us-west-2 \
156
- ARKER_SOURCE_VM=ubuntu \
157
- npm run demo
158
- ```
73
+ If the host fails mid-run, the run resumes on a healthy host with the VM's filesystem state preserved. Backends without durability return `ArkerError` code `unsupported_operation`.
159
74
 
160
75
  ## License
161
76