@kibotos/sdk 0.1.0 → 0.2.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.
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Official zero-dependency TypeScript and JavaScript SDK for the **Kibotos** v1 API.
4
4
 
5
- Built exclusively on standard Web APIs (`fetch`, `URL`, `URLSearchParams`, `AbortController`, `AbortSignal.timeout`, `crypto.randomUUID`), `@kibotos/sdk` runs seamlessly in **Node 20+**, **Bun**, **Deno**, and **Cloudflare Workers**.
5
+ The HTTP client uses built-in Web APIs including `fetch`, `ReadableStream`, and `AbortController` on **Node 20+**, **Bun**, **Deno**, and **Cloudflare Workers**.
6
6
 
7
7
  ## Installation
8
8
 
@@ -73,13 +73,68 @@ In edge runtimes without `process.env` (such as Cloudflare Workers), pass `apiKe
73
73
  | --- | --- |
74
74
  | `client.zones` | `list`, `iterate` |
75
75
  | `client.templates` | `list`, `iterate`, `get`, `listRevisions`, `getRevision` |
76
- | `client.workspaces` | `create`, `list`, `iterate`, `get`, `update`, `delete`, `start`, `stop`, `setTimeout`, `setNetwork`, `attachVolume`, `detachVolume`, `wait` |
76
+ | `client.workspaces` | `create`, `list`, `iterate`, `get`, `update`, `delete`, `start`, `stop`, `setTimeout`, `setNetwork`, `setVolumes`, `setPacks`, `getMetrics`, `attachVolume`, `detachVolume`, `wait` |
77
+ | `client.workspaces` (data plane) | `exec`, `execStream`, `listFiles`, `statFile`, `readFile`, `writeFile`, `makeDir`, `moveFile`, `deleteFile`, `connectWS`, `connectTunnel`, `connectDesktop`, `connectProxy`, `wsUrl`, `tunnelWSUrl`, `desktopVNCUrl`, `proxyUrl`, `proxyWSUrl`, `wsHeaders` |
77
78
  | `client.volumes` | `create`, `list`, `iterate`, `get`, `update`, `resize`, `delete`, `wait` |
78
79
  | `client.exposures` | `create`, `list`, `iterate`, `get`, `revoke` |
80
+ | `client.packs` | `list`, `get`, `getRevision` |
81
+ | `client.egresses`, `client.resolvers` | `create`, `list`, `get`, `replace` (configuration), `update` (name and labels), `delete` |
82
+
83
+ Workspace creation accepts `volumes`, Pack IDs in `packs`, and a `network` policy with `allow`, `deny`, `egresses`, and `resolvers`. Use `update(id, { resources: { vcpus, memory_mib, disk_mib } })` to resize a stopped or failed workspace. The root disk can only grow. `setVolumes` and `setPacks` take the complete list, and an empty list clears it. A workspace binds up to four Packs, and Pack changes take effect on the next start. The legacy `volume` field and single-volume methods remain available. `attachVolume` leaves only the given volume attached and `detachVolume` removes every attachment, so use `setVolumes` on multi-volume workspaces.
84
+
85
+ `setNetwork` replaces the whole policy and also accepts `drain_seconds`. The response's `network.applied` is `null` while the workspace is not running. `getMetrics(id, { start, end })` accepts RFC 3339 strings or `Date` values and returns host and guest time series.
86
+
87
+ ## Commands and Files
88
+
89
+ ```ts
90
+ const ws = client.workspaces;
91
+ const result = await ws.exec(workspaceId, { argv: ['python3', '--version'] });
92
+ console.log(result.exit_code, result.stdout);
93
+
94
+ for await (const { event, data } of ws.execStream(workspaceId, { argv: ['ls', '-l'] })) {
95
+ console.log(event, data);
96
+ }
97
+
98
+ await ws.makeDir(workspaceId, { path: '/tmp/example', mode: '0750' });
99
+ await ws.writeFile(workspaceId, '/tmp/example/hello.txt', 'hello', {
100
+ mode: '0640', createOnly: true,
101
+ });
102
+ const response = await ws.readFile(workspaceId, '/tmp/example/hello.txt', {
103
+ range: 'bytes=0-2',
104
+ });
105
+ console.log(response.status, response.headers.get('Content-Range'), await response.text());
106
+ ```
107
+
108
+ `execStream` yields `started`, `stdout`, `stderr`, `heartbeat`, `exited`, and `error` events. It decodes JSON event data when present. `exec` defaults to the command's `timeout_seconds` (30 seconds if omitted) plus 15 seconds. `execStream`, `readFile`, and `writeFile` have no default client deadline. Pass `timeoutMs` to set a per-request deadline or `signal` to cancel a request.
109
+
110
+ `readFile` returns a `Response` by default. Pass `as: 'bytes'` for a `Uint8Array` or `as: 'stream'` for its readable body. Use the response form to check `206` and `Content-Range`, or `304` when using `ifNoneMatch`. `writeFile` also accepts a `Uint8Array`, `Blob`, or `ReadableStream<Uint8Array>`. The directory and metadata methods are `listFiles`, `statFile`, `makeDir`, `moveFile`, and `deleteFile`. All seven file methods accept a workspace user override.
111
+
112
+ ## WebSocket Connections
113
+
114
+ ```ts
115
+ import { WorkspaceChannel } from '@kibotos/sdk';
116
+
117
+ const connection = client.workspaces.connectWS(workspaceId);
118
+ connection.onFrame((message) => {
119
+ if (message.type === 'binary' && message.frame.channel === WorkspaceChannel.stdout) {
120
+ console.log(message.frame.stream_id, message.frame.payload);
121
+ }
122
+ if (message.type === 'control') console.log(message.frame);
123
+ });
124
+ connection.socket.addEventListener('open', () => {
125
+ connection.open(1, 'process', { action: 'start', mode: 'pipe', argv: ['printf', 'hello'] });
126
+ });
127
+ ```
128
+
129
+ `WorkspaceSocket` supports `process`, `fs.watch`, and `tunnel` streams on one connection. Use `sendControl` for JSON controls and `sendBinary` for stream payloads. The exported `encodeBinaryFrame` and `decodeBinaryFrame` use a version byte (`0x01`), a big-endian 32-bit stream ID, and a channel byte (`0` stdin, `1` stdout, `2` stderr, `3` PTY, `4` tunnel).
130
+
131
+ `connectTunnel`, `connectDesktop`, and `connectProxy` return raw WebSockets. Use `tunnelWSUrl`, `desktopVNCUrl`, `proxyWSUrl`, `wsUrl`, and `wsHeaders` to build an upgrade for your own transport. `proxyUrl` builds the HTTP(S) URL.
132
+
133
+ Authenticated native upgrades use Node's global `WebSocket` with handshake headers. Node 20 exposes the global from 20.10 with `--experimental-websocket`. For a runtime whose global lacks handshake header support, pass a `factory` that accepts the URL, headers, and requested subprotocols.
79
134
 
80
135
  ## Auto-Pagination & Label Filtering
81
136
 
82
- Every listable resource exposes an `iterate(...)` method returning an `AsyncIterable<T>`:
137
+ Resources with an `iterate(...)` method return an `AsyncIterable<T>`. For Packs, egresses, and resolvers, pass `next_page_token` from the previous list response as `page_token`.
83
138
 
84
139
  ```ts
85
140
  for await (const ws of client.workspaces.iterate({
@@ -93,9 +148,10 @@ for await (const ws of client.workspaces.iterate({
93
148
 
94
149
  ## Retries, Idempotency & Cancellation
95
150
 
96
- - **Automatic idempotency**: `POST` mutations automatically generate a UUID v4 `Idempotency-Key` header if omitted and reuse the exact same key across retries. You may also pass `idempotencyKey` in `RequestOptions`.
151
+ - **Automatic idempotency**: Control-plane `POST` mutations automatically generate a UUID v4 `Idempotency-Key` header if omitted and reuse the same key across retries. You may also pass `idempotencyKey` in `RequestOptions`. `exec`, `makeDir`, and `moveFile` never send one.
97
152
  - **Retries**: Exponential backoff with jitter for `retryable: true` API errors, HTTP `429` (honoring `Retry-After` seconds or HTTP-date), `500`/`502`/`503`/`504`, and transient network failures.
98
- - **Cancellation**: Pass an `AbortSignal` via `{ signal }` on any method to cancel in-flight requests, retry delays, and `wait()` loops.
153
+ - **One-shot data-plane requests**: `exec`, `execStream`, `writeFile`, `makeDir`, `moveFile`, and `deleteFile` make a single attempt.
154
+ - **Cancellation**: Pass an `AbortSignal` via `{ signal }` to HTTP methods to cancel in-flight requests, retry delays, and `wait()` loops.
99
155
 
100
156
  ## Error Handling
101
157
 
@@ -133,6 +189,10 @@ try {
133
189
  }
134
190
  ```
135
191
 
192
+ ## Documentation
193
+
194
+ Reference guides live in [`docs/`](./docs) and are published at [docs.kibo.to](https://docs.kibo.to): workspaces, volumes, exposures, exec / files / tunnels, Packs and networking, templates and zones, and errors and retries.
195
+
136
196
  ## License
137
197
 
138
198
  MIT