@arker-ai/sdk 0.3.0 → 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/README.md +40 -125
- package/dist/chunk-PI3H3TGC.js +697 -0
- package/dist/cli.cjs +1316 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +606 -0
- package/dist/index.cjs +321 -103
- package/dist/index.d.cts +470 -206
- package/dist/index.d.ts +470 -206
- package/dist/index.js +9 -473
- package/package.json +17 -4
package/README.md
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
# Arker TypeScript SDK
|
|
2
2
|
|
|
3
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
25
|
-
const
|
|
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
|
-
|
|
28
|
-
|
|
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
|
|
32
|
-
const data = await vm.sync
|
|
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
|
-
|
|
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?,
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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 `
|
|
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,
|
|
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
|
|
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
|
-
|
|
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
|
|