@omnirun/sdk 0.5.0 → 0.7.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/CHANGELOG.md +24 -0
- package/README.md +266 -61
- package/dist/client.d.ts +44 -2
- package/dist/client.js +174 -81
- package/dist/commands.d.ts +10 -0
- package/dist/commands.js +39 -7
- package/dist/config.d.ts +12 -0
- package/dist/config.js +3 -0
- package/dist/contexts.js +1 -1
- package/dist/desktop.d.ts +72 -0
- package/dist/desktop.js +86 -0
- package/dist/errors.d.ts +32 -2
- package/dist/errors.js +28 -4
- package/dist/exposures.d.ts +52 -1
- package/dist/exposures.js +52 -1
- package/dist/filesystem.js +5 -3
- package/dist/index.d.ts +6 -2
- package/dist/index.js +1 -0
- package/dist/models.d.ts +96 -1
- package/dist/production.d.ts +2 -0
- package/dist/production.js +13 -9
- package/dist/pty.js +1 -1
- package/dist/sandbox.d.ts +123 -8
- package/dist/sandbox.js +156 -27
- package/dist/webhooks.d.ts +9 -1
- package/dist/webhooks.js +10 -2
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.7.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 2132c88: Add regions, richer errors and safe automatic retries.
|
|
8
|
+
|
|
9
|
+
- **Regions:** `Sandbox.create(template, { region })` chooses the region (`hel1`, `fsn1`); `sandbox.region` reports it (also after `Sandbox.connect`), `region` is part of `getInfo()` and `Sandbox.list()` entries, and `Sandbox.regions()` lists the regions with their health. `Sandbox.create` also accepts a single options object: `Sandbox.create({ template, region, ... })`.
|
|
10
|
+
- **Errors:** `SandboxError` (and `StreamError`) now carry `reason`, `detail`, `retryAfterSeconds` and `retryable` next to `status`. Class names and `instanceof` are unchanged. Download errors now carry `status` too.
|
|
11
|
+
- **Retries (behaviour change):** the SDK used to re-send any request once after 500/502/503/504, including sandbox creates and commands. Now `GET`/`DELETE`/idempotent calls are retried on network errors and 429/502/503/504; `Sandbox.create` only on 429 and on 503 `node_unavailable`/`no_healthy_node` (never after a 504 or a network error, when a sandbox may exist); command and code execution are never re-sent. `Retry-After` is honoured, within 3 attempts and 30 s of waiting by default. Configure with `retry: { maxAttempts, maxTotalWaitMs }` or switch off with `retry: false`. A 500 is no longer retried.
|
|
12
|
+
- **Commands:** a blocking `commands.run()` now waits for the command's own `timeout` (up to 3600 s) plus a 15-second margin instead of the general 60-second `requestTimeout`; `requestTimeout` in the run options overrides it. `runCode` accepts `{ requestTimeout }`.
|
|
13
|
+
- `sandbox.setTimeout()` returns the timeout that took effect.
|
|
14
|
+
|
|
15
|
+
## 0.6.1
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- 53095fc: Change the default preview domain from `claudebox.io` to `omnirun-preview.dev`. `sandbox.getHost(port)` now returns `https://<sandboxId>-<port>.omnirun-preview.dev` unless you pass `previewDomain` to `Sandbox.create`/`Sandbox.connect` or set `OMNIRUN_PREVIEW_DOMAIN`. The old default pointed at a domain we do not control.
|
|
20
|
+
|
|
21
|
+
## 0.6.0
|
|
22
|
+
|
|
23
|
+
### Minor Changes
|
|
24
|
+
|
|
25
|
+
- Add Desktop class for GUI sandbox control (screenshot, mouse, keyboard, screen). Implement full E2EE payload encryption with AES-256-GCM. Add HTTP transport security warnings.
|
|
26
|
+
|
|
3
27
|
## 0.5.0
|
|
4
28
|
|
|
5
29
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -1,63 +1,235 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://omnirun.io">
|
|
3
|
+
<h1 align="center">@omnirun/sdk</h1>
|
|
4
|
+
</a>
|
|
5
|
+
</p>
|
|
2
6
|
|
|
3
|
-
|
|
7
|
+
<p align="center">
|
|
8
|
+
<strong>TypeScript SDK for OmniRun cloud sandboxes.</strong>
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
<p align="center">
|
|
12
|
+
<a href="https://www.npmjs.com/package/@omnirun/sdk"><img src="https://img.shields.io/npm/v/@omnirun/sdk" alt="npm"></a>
|
|
13
|
+
<a href="https://omnirun.io/docs"><img src="https://img.shields.io/badge/docs-omnirun.io-blue" alt="Documentation"></a>
|
|
14
|
+
<a href="./LICENSE"><img src="https://img.shields.io/badge/license-MIT-green" alt="License"></a>
|
|
15
|
+
</p>
|
|
16
|
+
|
|
17
|
+
---
|
|
4
18
|
|
|
5
19
|
## Install
|
|
6
20
|
|
|
7
21
|
```bash
|
|
8
22
|
npm install @omnirun/sdk
|
|
9
|
-
pnpm add @omnirun/sdk
|
|
10
|
-
bun add @omnirun/sdk
|
|
11
23
|
```
|
|
12
24
|
|
|
13
|
-
##
|
|
25
|
+
## Quick Start
|
|
14
26
|
|
|
15
|
-
|
|
27
|
+
```ts
|
|
28
|
+
import { Sandbox } from "@omnirun/sdk";
|
|
16
29
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
30
|
+
// Create a sandbox (Firecracker microVM)
|
|
31
|
+
const sbx = await Sandbox.create("python-3.11", {
|
|
32
|
+
apiKey: process.env.OMNIRUN_API_KEY,
|
|
33
|
+
});
|
|
20
34
|
|
|
21
|
-
|
|
35
|
+
// Run a command
|
|
36
|
+
const result = await sbx.commands.run("python3 -c \"print('hello from sandbox')\"");
|
|
37
|
+
console.log(result.stdout); // "hello from sandbox\n"
|
|
38
|
+
|
|
39
|
+
// Clean up
|
|
40
|
+
await sbx.kill();
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Desktop Sandbox
|
|
44
|
+
|
|
45
|
+
Control a full Linux desktop environment with mouse, keyboard, and screenshots.
|
|
22
46
|
|
|
23
47
|
```ts
|
|
24
|
-
|
|
48
|
+
const sbx = await Sandbox.create("desktop", {
|
|
49
|
+
apiKey: process.env.OMNIRUN_API_KEY,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
// Take a screenshot
|
|
53
|
+
const png = await sbx.desktop.screenshot();
|
|
54
|
+
|
|
55
|
+
// Click and type
|
|
56
|
+
await sbx.desktop.leftClick(100, 200);
|
|
57
|
+
await sbx.desktop.type("Hello world");
|
|
58
|
+
await sbx.desktop.press("Enter");
|
|
25
59
|
|
|
60
|
+
// Get screen dimensions
|
|
61
|
+
const screen = await sbx.desktop.getScreen();
|
|
62
|
+
console.log(`${screen.width}x${screen.height}`);
|
|
63
|
+
|
|
64
|
+
await sbx.kill();
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Encrypted Transport to the Sandbox
|
|
68
|
+
|
|
69
|
+
Bootstrap a client keypair and encrypt payloads in transit to the sandbox.
|
|
70
|
+
|
|
71
|
+
> **Confidentiality scope:** payloads are encrypted in transit and the worker
|
|
72
|
+
> decrypts them in order to execute commands and code. Confidentiality therefore
|
|
73
|
+
> terminates at the worker — this is encrypted transport, not zero-knowledge
|
|
74
|
+
> end-to-end encryption. The operator running the sandbox can observe decrypted
|
|
75
|
+
> payloads.
|
|
76
|
+
|
|
77
|
+
```ts
|
|
26
78
|
const sbx = await Sandbox.create("python-3.11", {
|
|
27
79
|
apiKey: process.env.OMNIRUN_API_KEY,
|
|
28
|
-
|
|
29
|
-
timeout: 300,
|
|
80
|
+
e2ee: true,
|
|
30
81
|
});
|
|
31
82
|
|
|
32
|
-
|
|
33
|
-
console.log(
|
|
83
|
+
console.log(sbx.e2ee?.clientPublicKey);
|
|
84
|
+
console.log(sbx.e2ee?.serverPublicKey);
|
|
85
|
+
```
|
|
34
86
|
|
|
35
|
-
|
|
87
|
+
See `docs/E2EE-PROTOCOL-SCAFFOLD.md` for protocol details.
|
|
88
|
+
|
|
89
|
+
## Regions
|
|
90
|
+
|
|
91
|
+
A sandbox runs in one region. Pass `region` on create; without it the service
|
|
92
|
+
uses its default region (`hel1`). `Sandbox.regions()` lists the regions.
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
const regions = await Sandbox.regions();
|
|
96
|
+
// [{ id: "fsn1", default: false, healthy: true }, { id: "hel1", default: true, healthy: true }]
|
|
97
|
+
|
|
98
|
+
const sbx = await Sandbox.create("python-3.11", { region: "fsn1" });
|
|
99
|
+
console.log(sbx.region); // "fsn1"
|
|
100
|
+
|
|
101
|
+
// The single-object form works too:
|
|
102
|
+
const other = await Sandbox.create({ template: "node-20", region: "hel1" });
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
`sbx.region` is also set by `Sandbox.connect()`, and `region` is part of
|
|
106
|
+
`sbx.getInfo()` and of every entry of `Sandbox.list()`. It is `undefined` on a
|
|
107
|
+
self-hosted service without regions. There is no fallback to another region: a
|
|
108
|
+
full region answers `429 no_capacity`, a region without a healthy node
|
|
109
|
+
`503 no_healthy_node`, and an unknown name `400 unknown_region`.
|
|
110
|
+
|
|
111
|
+
## Commands
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
const result = await sbx.commands.run("make test", { timeout: 1800 });
|
|
115
|
+
console.log(result.exitCode, result.stdout, result.stderr);
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
- `exitCode` is the one documented property for the exit code, on command,
|
|
119
|
+
code and process results. (The service sends it as both `exit_code` and
|
|
120
|
+
`exitCode`; the SDK reads either.) A non-zero exit of `commands.run()` throws
|
|
121
|
+
`CommandExitException`, which carries `exitCode`, `stdout` and `stderr`.
|
|
122
|
+
- `timeout` is in seconds (default 60, at most 3600). A blocking
|
|
123
|
+
`commands.run()` waits for the command for that long plus a 15-second
|
|
124
|
+
margin, whatever the general `requestTimeout` is. Pass `requestTimeout`
|
|
125
|
+
(milliseconds) in the run options to set the HTTP timeout of one call
|
|
126
|
+
yourself. `sbx.runCode(code, language, { requestTimeout })` takes the same
|
|
127
|
+
option; without it, code runs use the general `requestTimeout` (60 s).
|
|
128
|
+
|
|
129
|
+
## Errors
|
|
130
|
+
|
|
131
|
+
API errors are thrown as `SandboxError` (or a subclass: `SandboxNotFoundError`,
|
|
132
|
+
`StreamError`). Branch on `status` and `reason`, never on `message`.
|
|
133
|
+
|
|
134
|
+
| Property | Meaning |
|
|
135
|
+
|----------|---------|
|
|
136
|
+
| `status` | HTTP status code |
|
|
137
|
+
| `reason` | Stable machine-readable reason, when the service sends one |
|
|
138
|
+
| `detail` | Extra information on some refusals (for example the budget behind `no_capacity`); do not branch on it |
|
|
139
|
+
| `retryAfterSeconds` | The `Retry-After` header as a number of seconds, or `undefined` |
|
|
140
|
+
| `retryable` | `true` when sending the same request again is safe (see [Retries](#retries)) |
|
|
141
|
+
|
|
142
|
+
```ts
|
|
143
|
+
import { Sandbox, SandboxError } from "@omnirun/sdk";
|
|
144
|
+
|
|
145
|
+
try {
|
|
146
|
+
await Sandbox.create("python-3.11", { region: "fsn1" });
|
|
147
|
+
} catch (err) {
|
|
148
|
+
if (err instanceof SandboxError && err.reason === "no_capacity") {
|
|
149
|
+
console.log(`region is full, try again in ${err.retryAfterSeconds}s`);
|
|
150
|
+
} else {
|
|
151
|
+
throw err;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
36
154
|
```
|
|
37
155
|
|
|
156
|
+
Reasons you can expect:
|
|
157
|
+
|
|
158
|
+
| Status | `reason` | Meaning |
|
|
159
|
+
|--------|----------|---------|
|
|
160
|
+
| 400 | `unknown_region` | The `region` does not exist |
|
|
161
|
+
| 402 | none | The account's credit limit is used up |
|
|
162
|
+
| 403 | `approval_required`, `account_suspended` | The request needs an approved account; the account is suspended |
|
|
163
|
+
| 429 | `no_capacity` | The region cannot take the sandbox right now |
|
|
164
|
+
| 429 | `per_user_sandbox_limit`, `per_user_ram_limit` | Your own sandboxes use your limit: end one first |
|
|
165
|
+
| 429 | `rate_limited`, `create_rate_limited` | Slow down |
|
|
166
|
+
| 502 | `node_connection_lost` | The connection broke while a command or code was running. It may have run: check before running it again |
|
|
167
|
+
| 503 | `node_unavailable`, `no_healthy_node` | The node is restarting or unreachable. Nothing was done; an existing sandbox is not gone, keep its id |
|
|
168
|
+
| 504 | `node_timeout` | The node did not answer in time |
|
|
169
|
+
|
|
170
|
+
Network failures and request timeouts are not wrapped: they surface as the
|
|
171
|
+
error `fetch` throws (`TypeError`, or a `TimeoutError` `DOMException`).
|
|
172
|
+
|
|
173
|
+
## Retries
|
|
174
|
+
|
|
175
|
+
The SDK retries a failed request only when sending it again cannot do
|
|
176
|
+
something twice.
|
|
177
|
+
|
|
178
|
+
| Request | Retried automatically on | Never retried on |
|
|
179
|
+
|---------|--------------------------|------------------|
|
|
180
|
+
| `GET`, `DELETE` and idempotent POSTs (`setTimeout`, text/batch/binary file writes, `makeDir`, signed URLs) | network errors, 429, 502, 503, 504 | other statuses (400, 401, 403, 404, 500, ...), request timeouts |
|
|
181
|
+
| `Sandbox.create()` (`POST /sandboxes`) | 429 (`no_capacity`, rate limits), 503 `node_unavailable`, 503 `no_healthy_node`: nothing was created | 504 `node_timeout`, 502, 500, a 503 without one of those reasons, network errors, request timeouts: a sandbox may exist |
|
|
182
|
+
| Command and code execution (`commands.run()`, `runCode()`, `contexts.execute()`), `sendStdin()`, PTY input | never | everything, including 502 `node_connection_lost`: the command may have run |
|
|
183
|
+
| Other POSTs (pause, resume, exposures, webhooks, PTY create, rename, ...) | 429, 503 `node_unavailable`, 503 `no_healthy_node` | 502, 504, network errors |
|
|
184
|
+
| Streams (command output, file watch, streamed downloads) | never | everything |
|
|
185
|
+
|
|
186
|
+
- The wait before a retry is the service's `Retry-After`; without one it is
|
|
187
|
+
250 ms, doubling per attempt.
|
|
188
|
+
- Bounds: at most 3 attempts per request and at most 30 seconds of waiting in
|
|
189
|
+
total. A retry whose wait would pass the total is not made; the error is
|
|
190
|
+
thrown at once.
|
|
191
|
+
- A 429 for your own limit (`per_user_sandbox_limit`, `per_user_ram_limit`) is
|
|
192
|
+
not retried automatically, because waiting does not help until one of your
|
|
193
|
+
sandboxes ends. Its `retryable` is still `true`.
|
|
194
|
+
- `error.retryable` follows the same table, so it tells you whether your own
|
|
195
|
+
retry is safe. After a `504` or a network error on `Sandbox.create()`, look
|
|
196
|
+
at `Sandbox.list()` before creating again.
|
|
197
|
+
|
|
198
|
+
Configure or switch off retries per call site:
|
|
199
|
+
|
|
200
|
+
```ts
|
|
201
|
+
// More patience
|
|
202
|
+
await Sandbox.create("python-3.11", { retry: { maxAttempts: 5, maxTotalWaitMs: 120_000 } });
|
|
203
|
+
|
|
204
|
+
// No automatic retries at all
|
|
205
|
+
const sbx = await Sandbox.create("python-3.11", { retry: false });
|
|
206
|
+
await Sandbox.connect(sbx.sandboxId, { retry: false });
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
The setting given to `Sandbox.create()` / `Sandbox.connect()` applies to every
|
|
210
|
+
call made through that sandbox object. `Sandbox.list()`, `Sandbox.regions()`
|
|
211
|
+
and `new LLM({ ... })` take the same `retry` option.
|
|
212
|
+
|
|
38
213
|
## Files
|
|
39
214
|
|
|
40
215
|
```ts
|
|
216
|
+
// Write and read files
|
|
41
217
|
await sbx.files.write("/tmp/input.txt", "hello");
|
|
42
218
|
const content = await sbx.files.read("/tmp/input.txt");
|
|
43
219
|
const bytes = await sbx.files.read("/tmp/input.txt", "bytes");
|
|
44
|
-
```
|
|
45
220
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
```ts
|
|
221
|
+
// Signed URLs for moving artifacts across the sandbox boundary
|
|
49
222
|
const uploadUrl = await sbx.uploadUrl("/tmp/report.json");
|
|
50
223
|
const downloadUrl = await sbx.downloadUrl("/tmp/report.json");
|
|
51
224
|
```
|
|
52
225
|
|
|
53
|
-
Use `uploadUrl` with multipart form-data when you need to move artifacts across the sandbox boundary.
|
|
54
|
-
|
|
55
226
|
## Streaming
|
|
56
227
|
|
|
57
228
|
```ts
|
|
58
|
-
const command = await sbx.commands.run(
|
|
59
|
-
|
|
60
|
-
}
|
|
229
|
+
const command = await sbx.commands.run(
|
|
230
|
+
"for i in 1 2 3; do echo $i; sleep 1; done",
|
|
231
|
+
{ background: true },
|
|
232
|
+
);
|
|
61
233
|
|
|
62
234
|
for await (const event of command) {
|
|
63
235
|
if (event.type === "stdout") {
|
|
@@ -66,63 +238,96 @@ for await (const event of command) {
|
|
|
66
238
|
}
|
|
67
239
|
```
|
|
68
240
|
|
|
69
|
-
## Production
|
|
241
|
+
## Production Controls
|
|
70
242
|
|
|
71
243
|
```ts
|
|
244
|
+
// Network policy
|
|
72
245
|
await sbx.production.setNetworkPolicy({
|
|
73
246
|
allowDomains: ["api.openai.com"],
|
|
74
247
|
});
|
|
75
248
|
|
|
249
|
+
// Metrics
|
|
76
250
|
const metrics = await sbx.production.metrics();
|
|
77
251
|
const snapshots = await sbx.production.metricsSnapshots();
|
|
78
252
|
```
|
|
79
253
|
|
|
80
|
-
##
|
|
254
|
+
## LLM Proxy
|
|
81
255
|
|
|
82
|
-
|
|
256
|
+
OpenAI-compatible LLM proxy with per-user spend tracking.
|
|
83
257
|
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
OMNIRUN_API_KEY=<key> \
|
|
87
|
-
RUN_OMNIRUN_INTEGRATION=1 \
|
|
88
|
-
npm run test:integration
|
|
89
|
-
```
|
|
258
|
+
```ts
|
|
259
|
+
import { LLM } from "@omnirun/sdk";
|
|
90
260
|
|
|
91
|
-
|
|
261
|
+
const llm = new LLM({ apiKey: process.env.OMNIRUN_API_KEY });
|
|
92
262
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
263
|
+
// Chat completion
|
|
264
|
+
const response = await llm.chatCompletion({
|
|
265
|
+
model: "gpt-4o",
|
|
266
|
+
messages: [{ role: "user", content: "Hello!" }],
|
|
267
|
+
});
|
|
268
|
+
console.log(response.choices[0].message.content);
|
|
269
|
+
|
|
270
|
+
// Streaming
|
|
271
|
+
for await (const chunk of llm.streamChatCompletion({
|
|
272
|
+
model: "gpt-4o",
|
|
273
|
+
messages: [{ role: "user", content: "Tell me a joke" }],
|
|
274
|
+
})) {
|
|
275
|
+
process.stdout.write(chunk);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// Usage tracking
|
|
279
|
+
const usage = await llm.getUsage();
|
|
280
|
+
console.log(`Remaining: ${usage.remainingCents / 100} USD`);
|
|
97
281
|
```
|
|
98
282
|
|
|
99
|
-
|
|
283
|
+
## API Overview
|
|
284
|
+
|
|
285
|
+
### Sandbox
|
|
286
|
+
|
|
287
|
+
| Method | Description |
|
|
288
|
+
|--------|-------------|
|
|
289
|
+
| `Sandbox.create(template, opts)` | Create a new sandbox |
|
|
290
|
+
| `Sandbox.connect(sandboxId, opts)` | Connect to an existing sandbox |
|
|
291
|
+
| `Sandbox.list(opts)` | List all sandboxes |
|
|
292
|
+
| `Sandbox.regions(opts)` | List the regions and their health |
|
|
293
|
+
| `sbx.region` | Region the sandbox runs in |
|
|
294
|
+
| `sbx.setTimeout(seconds)` | Move the sandbox's end; returns the timeout that took effect |
|
|
295
|
+
| `sbx.pause()` / `sbx.resume()` | Pause and resume the VM |
|
|
296
|
+
| `sbx.kill()` | Destroy the sandbox |
|
|
297
|
+
|
|
298
|
+
### Namespaces
|
|
299
|
+
|
|
300
|
+
| Namespace | Key Methods | Description |
|
|
301
|
+
|-----------|-------------|-------------|
|
|
302
|
+
| `sbx.commands` | `run()`, `list()` | Run shell commands, stream output |
|
|
303
|
+
| `sbx.files` | `read()`, `write()`, `list()`, `remove()` | Read, write, and manage files |
|
|
304
|
+
| `sbx.pty` | `create()`, `resize()`, `write()` | Interactive terminal (PTY) sessions |
|
|
305
|
+
| `sbx.contexts` | `create()`, `execute()` | Persistent interpreter contexts (REPL) |
|
|
306
|
+
| `sbx.desktop` | `screenshot()`, `leftClick()`, `type()`, `press()` | Desktop GUI interaction |
|
|
307
|
+
| `sbx.exposures` | `create()`, `list()`, `close()` | Port exposure and preview URLs |
|
|
308
|
+
| `sbx.production` | `setNetworkPolicy()`, `metrics()` | Network policies and monitoring |
|
|
309
|
+
| `sbx.webhooks` | `create()`, `list()`, `delete()` | Webhook registration |
|
|
310
|
+
| `LLM` | `chatCompletion()`, `streamChatCompletion()`, `listModels()` | LLM inference gateway |
|
|
100
311
|
|
|
101
|
-
##
|
|
312
|
+
## Configuration
|
|
102
313
|
|
|
103
|
-
The SDK
|
|
314
|
+
The SDK resolves configuration in this order:
|
|
104
315
|
|
|
105
|
-
|
|
106
|
-
|
|
316
|
+
1. Explicit options passed to SDK methods
|
|
317
|
+
2. Environment variables: `OMNIRUN_API_URL`, `OMNIRUN_API_KEY`
|
|
318
|
+
3. Default API URL: `https://api.omnirun.io`
|
|
107
319
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
e2ee: true,
|
|
112
|
-
});
|
|
320
|
+
Options: `apiKey`, `apiUrl`, `requestTimeout` (milliseconds, default 60000)
|
|
321
|
+
and `retry` (`{ maxAttempts, maxTotalWaitMs }` or `false`, see
|
|
322
|
+
[Retries](#retries)).
|
|
113
323
|
|
|
114
|
-
|
|
115
|
-
console.log(sbx.e2ee?.serverPublicKey); // available when backend returns it
|
|
116
|
-
```
|
|
324
|
+
## Related
|
|
117
325
|
|
|
118
|
-
|
|
326
|
+
- Python SDK -- not published yet. Do not install the PyPI package `omnirun`: it belongs to an unrelated project.
|
|
327
|
+
- [Examples](https://github.com/a14a-org/omnirun-examples) -- 11 practical examples
|
|
328
|
+
- [CLI](https://www.npmjs.com/package/@omnirun/cli) -- `npm install -g @omnirun/cli`
|
|
329
|
+
- [Documentation](https://omnirun.io/docs)
|
|
119
330
|
|
|
120
|
-
##
|
|
331
|
+
## License
|
|
121
332
|
|
|
122
|
-
|
|
123
|
-
- `Commands` / `CommandHandle`
|
|
124
|
-
- `Filesystem`
|
|
125
|
-
- `Pty` / `PtySession`
|
|
126
|
-
- `Contexts`
|
|
127
|
-
- `Production`
|
|
128
|
-
- `Webhooks`
|
|
333
|
+
MIT
|
package/dist/client.d.ts
CHANGED
|
@@ -1,14 +1,51 @@
|
|
|
1
1
|
import type { ConnectionConfig } from "./config.js";
|
|
2
2
|
import type { StreamEvent } from "./models.js";
|
|
3
|
+
/**
|
|
4
|
+
* When a failed request may be sent again automatically.
|
|
5
|
+
*
|
|
6
|
+
* - `"idempotent"`: sending it twice is harmless (GET, DELETE, idempotent
|
|
7
|
+
* POSTs). Retried on network errors and on 429/502/503/504.
|
|
8
|
+
* - `"refusal"`: not idempotent (e.g. `POST /sandboxes`). Retried only when the
|
|
9
|
+
* service refused the request without acting on it: 429, and 503 with reason
|
|
10
|
+
* `node_unavailable` or `no_healthy_node`. Never on 502/504 or a network
|
|
11
|
+
* error, after which the request may have taken effect.
|
|
12
|
+
* - `"never"`: never retried (command and code execution).
|
|
13
|
+
*/
|
|
14
|
+
export type RetryPolicy = "idempotent" | "refusal" | "never";
|
|
15
|
+
/** Per-request options for {@link HTTPClient} calls. */
|
|
16
|
+
export interface RequestOptions {
|
|
17
|
+
/** Retry policy for this request. */
|
|
18
|
+
retry?: RetryPolicy;
|
|
19
|
+
/** Request timeout in milliseconds for this request, instead of the configured `requestTimeout`. */
|
|
20
|
+
timeoutMs?: number;
|
|
21
|
+
}
|
|
22
|
+
/** Parse a `Retry-After` header (delta seconds or HTTP date) into seconds. */
|
|
23
|
+
export declare function parseRetryAfter(value: string | null): number | undefined;
|
|
3
24
|
/** Low-level HTTP transport for OmniRun API requests. */
|
|
4
25
|
export declare class HTTPClient {
|
|
5
26
|
private config;
|
|
27
|
+
private e2eeKey;
|
|
6
28
|
constructor(config: ConnectionConfig);
|
|
29
|
+
setE2EEKey(key: CryptoKey): void;
|
|
7
30
|
get baseUrl(): string;
|
|
8
31
|
private get authHeaders();
|
|
9
32
|
private get jsonHeaders();
|
|
33
|
+
private get maxAttempts();
|
|
34
|
+
private get maxTotalWaitMs();
|
|
35
|
+
/**
|
|
36
|
+
* Send a request, retrying it as far as `policy` and the configured bounds
|
|
37
|
+
* allow. Returns the first successful response; throws a {@link SandboxError}
|
|
38
|
+
* for the last error response, or the network error itself.
|
|
39
|
+
*/
|
|
40
|
+
private request;
|
|
10
41
|
get<T = any>(path: string, params?: Record<string, string>): Promise<T>;
|
|
11
|
-
|
|
42
|
+
/**
|
|
43
|
+
* POST a JSON body. By default the request is retried only when the service
|
|
44
|
+
* refused it without acting on it (`"refusal"`); pass `retry: "idempotent"`
|
|
45
|
+
* for calls that are safe to repeat and `retry: "never"` for calls that must
|
|
46
|
+
* not be sent twice.
|
|
47
|
+
*/
|
|
48
|
+
post<T = any>(path: string, body?: any, opts?: RequestOptions): Promise<T>;
|
|
12
49
|
delete(path: string, params?: Record<string, string>): Promise<void>;
|
|
13
50
|
download(path: string, params?: Record<string, string>): Promise<Uint8Array>;
|
|
14
51
|
streamDownload(path: string, params?: Record<string, string>): Promise<ReadableStream<Uint8Array>>;
|
|
@@ -16,12 +53,17 @@ export declare class HTTPClient {
|
|
|
16
53
|
data: T;
|
|
17
54
|
headers: Headers;
|
|
18
55
|
}>;
|
|
56
|
+
/** Upload a file (multipart). Writing the same file twice is harmless, so this is retried as idempotent. */
|
|
19
57
|
upload(path: string, filePath: string, content: Uint8Array, filename: string): Promise<any>;
|
|
20
58
|
streamSSE(path: string, params?: Record<string, string>): AsyncGenerator<StreamEvent>;
|
|
21
59
|
streamSSEPost(path: string, body?: unknown, signal?: AbortSignal): AsyncGenerator<StreamEvent>;
|
|
22
60
|
streamSSEWithSignal(path: string, params?: Record<string, string>, signal?: AbortSignal): AsyncGenerator<StreamEvent>;
|
|
23
61
|
private buildUrl;
|
|
24
62
|
private handle;
|
|
63
|
+
private handleWithDecrypt;
|
|
25
64
|
private parseSSE;
|
|
26
|
-
|
|
65
|
+
/** Build the {@link SandboxError} for an error response. */
|
|
66
|
+
private toError;
|
|
67
|
+
/** Read the message, `reason`, `detail` and `Retry-After` of an error response. */
|
|
68
|
+
private errorInfo;
|
|
27
69
|
}
|