@kibotos/sdk 0.0.0-stage → 0.1.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 +137 -2
- package/dist/index.cjs +1026 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +650 -0
- package/dist/index.d.ts +650 -0
- package/dist/index.js +1005 -0
- package/dist/index.js.map +1 -0
- package/package.json +54 -4
package/README.md
CHANGED
|
@@ -1,3 +1,138 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@kibotos/sdk`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Official zero-dependency TypeScript and JavaScript SDK for the **Kibotos** v1 API.
|
|
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**.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @kibotos/sdk
|
|
11
|
+
# or
|
|
12
|
+
pnpm add @kibotos/sdk
|
|
13
|
+
# or
|
|
14
|
+
bun add @kibotos/sdk
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Quick Start
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { Kibotos } from '@kibotos/sdk';
|
|
21
|
+
|
|
22
|
+
// Reads KIBOTOS_API_KEY and KIBOTOS_API_URL (default: https://api.kibo.to/v1)
|
|
23
|
+
const client = new Kibotos();
|
|
24
|
+
|
|
25
|
+
// 1. Create a workspace
|
|
26
|
+
const created = await client.workspaces.create({
|
|
27
|
+
name: 'agent-runner',
|
|
28
|
+
template: { id: 'python-3.12' },
|
|
29
|
+
resources: { vcpus: 2, memory_mib: 4096 },
|
|
30
|
+
timeout: { seconds: 3600, action: 'stop' },
|
|
31
|
+
labels: { env: 'dev' },
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// 2. Wait until available (supports timeouts > 60s via automatic chunking)
|
|
35
|
+
const workspace = await client.workspaces.wait(created.id, {
|
|
36
|
+
status: ['available', 'failed'],
|
|
37
|
+
timeoutSeconds: 120,
|
|
38
|
+
});
|
|
39
|
+
console.log('Workspace ready:', workspace.id, workspace.status);
|
|
40
|
+
|
|
41
|
+
// 3. Expose a port over HTTPS
|
|
42
|
+
const exposure = await client.exposures.create(workspace.id, {
|
|
43
|
+
port: 8080,
|
|
44
|
+
ttl_seconds: 3600,
|
|
45
|
+
});
|
|
46
|
+
console.log('Public URL:', exposure.url);
|
|
47
|
+
|
|
48
|
+
// 4. Clean up
|
|
49
|
+
await client.exposures.revoke(workspace.id, exposure.id);
|
|
50
|
+
await client.workspaces.delete(workspace.id);
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Configuration
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
import { Kibotos } from '@kibotos/sdk';
|
|
57
|
+
|
|
58
|
+
const client = new Kibotos({
|
|
59
|
+
apiKey: 'kb_...', // Defaults to process.env.KIBOTOS_API_KEY
|
|
60
|
+
baseUrl: 'https://api.kibo.to/v1', // Defaults to process.env.KIBOTOS_API_URL ?? 'https://api.kibo.to/v1'
|
|
61
|
+
maxRetries: 3, // Defaults to 3
|
|
62
|
+
timeoutMs: 30_000, // Defaults to 30000 (30s)
|
|
63
|
+
defaultHeaders: { 'X-App': 'my-service' },
|
|
64
|
+
fetch: customFetch, // Optional fetch override
|
|
65
|
+
});
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
In edge runtimes without `process.env` (such as Cloudflare Workers), pass `apiKey` explicitly from your environment bindings.
|
|
69
|
+
|
|
70
|
+
## Resources
|
|
71
|
+
|
|
72
|
+
| Namespace | Methods |
|
|
73
|
+
| --- | --- |
|
|
74
|
+
| `client.zones` | `list`, `iterate` |
|
|
75
|
+
| `client.templates` | `list`, `iterate`, `get`, `listRevisions`, `getRevision` |
|
|
76
|
+
| `client.workspaces` | `create`, `list`, `iterate`, `get`, `update`, `delete`, `start`, `stop`, `setTimeout`, `setNetwork`, `attachVolume`, `detachVolume`, `wait` |
|
|
77
|
+
| `client.volumes` | `create`, `list`, `iterate`, `get`, `update`, `resize`, `delete`, `wait` |
|
|
78
|
+
| `client.exposures` | `create`, `list`, `iterate`, `get`, `revoke` |
|
|
79
|
+
|
|
80
|
+
## Auto-Pagination & Label Filtering
|
|
81
|
+
|
|
82
|
+
Every listable resource exposes an `iterate(...)` method returning an `AsyncIterable<T>`:
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
for await (const ws of client.workspaces.iterate({
|
|
86
|
+
status: 'available',
|
|
87
|
+
labels: { team: 'ml', env: 'prod' }, // Serialized as label.team=ml&label.env=prod
|
|
88
|
+
limit: 50,
|
|
89
|
+
})) {
|
|
90
|
+
console.log(ws.id, ws.name);
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Retries, Idempotency & Cancellation
|
|
95
|
+
|
|
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`.
|
|
97
|
+
- **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.
|
|
99
|
+
|
|
100
|
+
## Error Handling
|
|
101
|
+
|
|
102
|
+
All SDK errors inherit from `KibotosError`:
|
|
103
|
+
|
|
104
|
+
```ts
|
|
105
|
+
import {
|
|
106
|
+
APIConnectionError,
|
|
107
|
+
AuthenticationError,
|
|
108
|
+
ConflictError,
|
|
109
|
+
KibotosAPIError,
|
|
110
|
+
NotFoundError,
|
|
111
|
+
PermissionDeniedError,
|
|
112
|
+
RateLimitError,
|
|
113
|
+
UnexpectedStatusError,
|
|
114
|
+
WaitTimeoutError,
|
|
115
|
+
} from '@kibotos/sdk';
|
|
116
|
+
|
|
117
|
+
try {
|
|
118
|
+
await client.workspaces.get('wks_missing');
|
|
119
|
+
} catch (err) {
|
|
120
|
+
if (err instanceof NotFoundError) {
|
|
121
|
+
console.error('Not found:', err.code, err.requestId);
|
|
122
|
+
} else if (err instanceof RateLimitError) {
|
|
123
|
+
console.error('Rate limited; retry after ms:', err.retryAfterMs);
|
|
124
|
+
} else if (err instanceof UnexpectedStatusError) {
|
|
125
|
+
console.error('Wait stopped on unexpected status:', err.details);
|
|
126
|
+
} else if (err instanceof WaitTimeoutError) {
|
|
127
|
+
console.error('Wait timed out:', err.details);
|
|
128
|
+
} else if (err instanceof KibotosAPIError) {
|
|
129
|
+
console.error('API error:', err.status, err.code, err.message);
|
|
130
|
+
} else if (err instanceof APIConnectionError) {
|
|
131
|
+
console.error('Connection error:', err.message);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## License
|
|
137
|
+
|
|
138
|
+
MIT
|