@omnirun/sdk 0.6.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 +18 -0
- package/README.md +245 -73
- package/dist/client.d.ts +41 -2
- package/dist/client.js +151 -80
- package/dist/commands.d.ts +10 -0
- package/dist/commands.js +22 -5
- package/dist/config.d.ts +12 -0
- package/dist/config.js +3 -0
- package/dist/contexts.js +1 -1
- package/dist/errors.d.ts +32 -2
- package/dist/errors.js +28 -4
- package/dist/filesystem.js +5 -3
- package/dist/index.d.ts +4 -2
- package/dist/models.d.ts +40 -2
- package/dist/pty.js +1 -1
- package/dist/sandbox.d.ts +40 -8
- package/dist/sandbox.js +81 -35
- package/dist/webhooks.d.ts +9 -1
- package/dist/webhooks.js +10 -2
- package/package.json +6 -6
package/dist/models.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { RetryOptions } from "./config.js";
|
|
1
2
|
import type { E2EECreateOptions } from "./e2ee.js";
|
|
2
3
|
export interface CommandResult {
|
|
3
4
|
stdout: string;
|
|
@@ -22,6 +23,26 @@ export interface SandboxInfo {
|
|
|
22
23
|
state?: string;
|
|
23
24
|
cpuCount?: number;
|
|
24
25
|
memoryMB?: number;
|
|
26
|
+
/** Region the sandbox runs in (e.g. `"hel1"`). Only set on a service with regions. */
|
|
27
|
+
region?: string;
|
|
28
|
+
}
|
|
29
|
+
/** A region a sandbox can run in, as listed by `GET /regions`. */
|
|
30
|
+
export interface RegionInfo {
|
|
31
|
+
/** Region identifier, the value to pass as `region` on create (e.g. `"hel1"`, `"fsn1"`). */
|
|
32
|
+
id: string;
|
|
33
|
+
/** `true` for the region used when a create names none. */
|
|
34
|
+
default: boolean;
|
|
35
|
+
/** `true` when at least one node of the region accepts new sandboxes. */
|
|
36
|
+
healthy: boolean;
|
|
37
|
+
}
|
|
38
|
+
/** Connection options shared by the static `Sandbox` calls. */
|
|
39
|
+
export interface ConnectOptions {
|
|
40
|
+
apiKey?: string;
|
|
41
|
+
apiUrl?: string;
|
|
42
|
+
/** HTTP request timeout in milliseconds for SDK-to-API calls. */
|
|
43
|
+
requestTimeout?: number;
|
|
44
|
+
/** Bounds for automatic retries, or `false` to switch them off. */
|
|
45
|
+
retry?: RetryOptions | false;
|
|
25
46
|
}
|
|
26
47
|
export interface ProcessInfo {
|
|
27
48
|
pid: number;
|
|
@@ -110,7 +131,13 @@ export interface RefreshExposureOptions {
|
|
|
110
131
|
}
|
|
111
132
|
export interface RunCommandOptions {
|
|
112
133
|
cwd?: string;
|
|
134
|
+
/** Command timeout in seconds. Default `60`; the service caps it at `3600`. */
|
|
113
135
|
timeout?: number;
|
|
136
|
+
/**
|
|
137
|
+
* HTTP request timeout in milliseconds for this call. By default a blocking
|
|
138
|
+
* command waits for its own `timeout` plus a 15-second margin.
|
|
139
|
+
*/
|
|
140
|
+
requestTimeout?: number;
|
|
114
141
|
background?: boolean;
|
|
115
142
|
envs?: Record<string, string>;
|
|
116
143
|
user?: string;
|
|
@@ -126,9 +153,17 @@ export interface CreateSandboxOptions {
|
|
|
126
153
|
apiUrl?: string;
|
|
127
154
|
/** HTTP request timeout in milliseconds for SDK-to-API calls. */
|
|
128
155
|
requestTimeout?: number;
|
|
156
|
+
/** Bounds for automatic retries (`maxAttempts`, `maxTotalWaitMs`), or `false` to switch them off. */
|
|
157
|
+
retry?: RetryOptions | false;
|
|
158
|
+
/**
|
|
159
|
+
* Region to run the sandbox in (e.g. `"hel1"`, `"fsn1"`; see `Sandbox.regions()`).
|
|
160
|
+
* Without it the sandbox runs in the service's default region. An unknown
|
|
161
|
+
* region is refused with `400` and reason `unknown_region`.
|
|
162
|
+
*/
|
|
163
|
+
region?: string;
|
|
129
164
|
/** Enable outbound internet access from the sandbox. Default: `false`. */
|
|
130
165
|
internet?: boolean;
|
|
131
|
-
/** Memory allocation in MB.
|
|
166
|
+
/** Memory allocation in MB. Requires backend support; currently ignored by the server (memory is derived from the template). */
|
|
132
167
|
memory?: number;
|
|
133
168
|
/** Environment variables injected into the sandbox at creation time. */
|
|
134
169
|
envVars?: Record<string, string>;
|
|
@@ -148,12 +183,15 @@ export interface CreateSandboxOptions {
|
|
|
148
183
|
vaultInject?: boolean;
|
|
149
184
|
/** Client-side E2EE bootstrap options (key generation + public key announcement). Pass `true` for defaults. */
|
|
150
185
|
e2ee?: boolean | E2EECreateOptions;
|
|
151
|
-
/** Domain used for sandbox preview URLs (e.g. `"omnirun-preview.dev"`). Falls back to `OMNIRUN_PREVIEW_DOMAIN` env var, then `"
|
|
186
|
+
/** Domain used for sandbox preview URLs (e.g. `"omnirun-preview.dev"`). Falls back to `OMNIRUN_PREVIEW_DOMAIN` env var, then `"omnirun-preview.dev"`. */
|
|
152
187
|
previewDomain?: string;
|
|
153
188
|
}
|
|
154
189
|
export interface ListSandboxOptions {
|
|
155
190
|
apiKey?: string;
|
|
156
191
|
apiUrl?: string;
|
|
192
|
+
requestTimeout?: number;
|
|
193
|
+
/** Bounds for automatic retries, or `false` to switch them off. */
|
|
194
|
+
retry?: RetryOptions | false;
|
|
157
195
|
limit?: number;
|
|
158
196
|
nextToken?: string;
|
|
159
197
|
state?: string;
|
package/dist/pty.js
CHANGED
|
@@ -34,7 +34,7 @@ export class PtySession {
|
|
|
34
34
|
return `/sandboxes/${this.sandboxId}/pty/${this.pid}`;
|
|
35
35
|
}
|
|
36
36
|
async sendStdin(data) {
|
|
37
|
-
await this.client.post(`${this.url}/input`, { data });
|
|
37
|
+
await this.client.post(`${this.url}/input`, { data }, { retry: "never" });
|
|
38
38
|
}
|
|
39
39
|
async resize(cols, rows) {
|
|
40
40
|
await this.client.post(`${this.url}/resize`, { cols, rows });
|
package/dist/sandbox.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { type E2EESessionInfo } from "./e2ee.js";
|
|
|
4
4
|
import { Filesystem } from "./filesystem.js";
|
|
5
5
|
import { Desktop } from "./desktop.js";
|
|
6
6
|
import { Exposures } from "./exposures.js";
|
|
7
|
-
import type { CodeResult, CreateSandboxOptions, CreateExposureOptions, ExposureInfo, FullSandboxInfo, ListSandboxOptions, MetricsSnapshot, NetworkPolicy, SandboxInfo } from "./models.js";
|
|
7
|
+
import type { CodeResult, ConnectOptions, CreateSandboxOptions, CreateExposureOptions, ExposureInfo, FullSandboxInfo, ListSandboxOptions, MetricsSnapshot, NetworkPolicy, RegionInfo, SandboxInfo } from "./models.js";
|
|
8
8
|
import { Production } from "./production.js";
|
|
9
9
|
import { Pty } from "./pty.js";
|
|
10
10
|
import { Webhooks } from "./webhooks.js";
|
|
@@ -26,6 +26,11 @@ export declare class SandboxPaginator {
|
|
|
26
26
|
/** Top-level sandbox abstraction covering lifecycle and nested API namespaces. */
|
|
27
27
|
export declare class Sandbox {
|
|
28
28
|
readonly sandboxId: string;
|
|
29
|
+
/**
|
|
30
|
+
* Region the sandbox runs in (e.g. `"hel1"`), as reported by the service.
|
|
31
|
+
* `undefined` on a service without regions.
|
|
32
|
+
*/
|
|
33
|
+
readonly region?: string;
|
|
29
34
|
readonly commands: Commands;
|
|
30
35
|
readonly files: Filesystem;
|
|
31
36
|
readonly pty: Pty;
|
|
@@ -59,9 +64,21 @@ export declare class Sandbox {
|
|
|
59
64
|
* @param opts.e2ee - E2EE bootstrap options or `true` for defaults.
|
|
60
65
|
* @param opts.vaultInject - Inject vault credentials as env vars via `/tmp/.omnirun-env`.
|
|
61
66
|
* @param opts.requestTimeout - HTTP request timeout in milliseconds.
|
|
67
|
+
* @param opts.region - Region to run in (see {@link Sandbox.regions}). Default: the service's default region.
|
|
68
|
+
* @param opts.retry - Automatic retry bounds, or `false` to switch retries off.
|
|
62
69
|
* @returns A connected {@link Sandbox} instance.
|
|
70
|
+
*
|
|
71
|
+
* The create request is retried automatically only when the service refused
|
|
72
|
+
* it without creating anything (429, and 503 `node_unavailable` /
|
|
73
|
+
* `no_healthy_node`). It is never re-sent after a 504 or a network error.
|
|
74
|
+
*
|
|
75
|
+
* Both call forms are supported: `Sandbox.create("python-3.11", opts)` and
|
|
76
|
+
* `Sandbox.create({ template: "python-3.11", ...opts })`.
|
|
63
77
|
*/
|
|
64
78
|
static create(template?: string, opts?: CreateSandboxOptions): Promise<Sandbox>;
|
|
79
|
+
static create(opts: CreateSandboxOptions & {
|
|
80
|
+
template?: string;
|
|
81
|
+
}): Promise<Sandbox>;
|
|
65
82
|
/**
|
|
66
83
|
* Connect to an existing, already-running sandbox by its ID.
|
|
67
84
|
*
|
|
@@ -73,12 +90,18 @@ export declare class Sandbox {
|
|
|
73
90
|
* @returns A connected {@link Sandbox} instance.
|
|
74
91
|
* @throws {SandboxNotFoundError} If the sandbox does not exist or has been killed.
|
|
75
92
|
*/
|
|
76
|
-
static connect(sandboxId: string, opts?: {
|
|
77
|
-
apiKey?: string;
|
|
78
|
-
apiUrl?: string;
|
|
79
|
-
requestTimeout?: number;
|
|
93
|
+
static connect(sandboxId: string, opts?: ConnectOptions & {
|
|
80
94
|
previewDomain?: string;
|
|
81
95
|
}): Promise<Sandbox>;
|
|
96
|
+
/**
|
|
97
|
+
* List the regions a sandbox can run in (`GET /regions`): which one is the
|
|
98
|
+
* default and whether each currently accepts new sandboxes. The list is
|
|
99
|
+
* empty on a service without regions; a single self-hosted node has no
|
|
100
|
+
* such endpoint and answers 404.
|
|
101
|
+
*
|
|
102
|
+
* @param opts - Connection options (apiKey, apiUrl, requestTimeout, retry).
|
|
103
|
+
*/
|
|
104
|
+
static regions(opts?: ConnectOptions): Promise<RegionInfo[]>;
|
|
82
105
|
/**
|
|
83
106
|
* List sandboxes for the authenticated account.
|
|
84
107
|
*
|
|
@@ -107,8 +130,10 @@ export declare class Sandbox {
|
|
|
107
130
|
*
|
|
108
131
|
* @param timeout - New timeout value in seconds. The sandbox will be killed
|
|
109
132
|
* after this many seconds of wall-clock time unless the timer is reset again.
|
|
133
|
+
* @returns The timeout that took effect, which can be lower than requested
|
|
134
|
+
* (24-hour cap, or the limit of an account that is not yet approved).
|
|
110
135
|
*/
|
|
111
|
-
setTimeout(timeout: number): Promise<
|
|
136
|
+
setTimeout(timeout: number): Promise<number>;
|
|
112
137
|
/**
|
|
113
138
|
* Check whether the sandbox is currently in the `"running"` state.
|
|
114
139
|
*
|
|
@@ -123,8 +148,15 @@ export declare class Sandbox {
|
|
|
123
148
|
* memory, template ID, and timestamps.
|
|
124
149
|
*/
|
|
125
150
|
getInfo(): Promise<FullSandboxInfo>;
|
|
126
|
-
/**
|
|
127
|
-
|
|
151
|
+
/**
|
|
152
|
+
* Execute code via the /code endpoint. Never retried automatically: after a
|
|
153
|
+
* `502 node_connection_lost` the code may have run.
|
|
154
|
+
*
|
|
155
|
+
* @param opts.requestTimeout - HTTP request timeout in milliseconds for this call.
|
|
156
|
+
*/
|
|
157
|
+
runCode(code: string, language?: string, opts?: {
|
|
158
|
+
requestTimeout?: number;
|
|
159
|
+
}): Promise<CodeResult>;
|
|
128
160
|
/** Get public URL for a port exposed inside the sandbox. */
|
|
129
161
|
getHost(port: number): string;
|
|
130
162
|
/** Create a managed preview URL for a sandbox port. */
|
package/dist/sandbox.js
CHANGED
|
@@ -5,11 +5,24 @@ import { Contexts } from "./contexts.js";
|
|
|
5
5
|
import { deriveE2EESharedKey, generateE2EEKeyPair, } from "./e2ee.js";
|
|
6
6
|
import { Filesystem } from "./filesystem.js";
|
|
7
7
|
import { Desktop } from "./desktop.js";
|
|
8
|
+
import { SandboxError, SandboxNotFoundError } from "./errors.js";
|
|
8
9
|
import { Exposures } from "./exposures.js";
|
|
9
10
|
import { parseMetricsSnapshot, Production } from "./production.js";
|
|
10
11
|
import { Pty } from "./pty.js";
|
|
11
12
|
import { makeCommandResult } from "./utils.js";
|
|
12
13
|
import { Webhooks } from "./webhooks.js";
|
|
14
|
+
/** Default domain for sandbox preview URLs when none is configured. */
|
|
15
|
+
const DEFAULT_PREVIEW_DOMAIN = "omnirun-preview.dev";
|
|
16
|
+
/**
|
|
17
|
+
* Rethrow a 404 {@link SandboxError} as a {@link SandboxNotFoundError} so callers
|
|
18
|
+
* can distinguish a missing/killed sandbox from other API failures.
|
|
19
|
+
*/
|
|
20
|
+
function rethrowNotFound(err, sandboxId) {
|
|
21
|
+
if (err instanceof SandboxError && err.status === 404) {
|
|
22
|
+
throw new SandboxNotFoundError(sandboxId);
|
|
23
|
+
}
|
|
24
|
+
throw err;
|
|
25
|
+
}
|
|
13
26
|
function encodeMetadataFilter(metadata) {
|
|
14
27
|
if (!metadata)
|
|
15
28
|
return undefined;
|
|
@@ -29,6 +42,7 @@ function parseSandboxInfo(s) {
|
|
|
29
42
|
state: s.state,
|
|
30
43
|
cpuCount: s.cpuCount,
|
|
31
44
|
memoryMB: s.memoryMB,
|
|
45
|
+
region: s.region || undefined,
|
|
32
46
|
};
|
|
33
47
|
}
|
|
34
48
|
function parseFullSandboxInfo(s) {
|
|
@@ -93,6 +107,11 @@ export class SandboxPaginator {
|
|
|
93
107
|
/** Top-level sandbox abstraction covering lifecycle and nested API namespaces. */
|
|
94
108
|
export class Sandbox {
|
|
95
109
|
sandboxId;
|
|
110
|
+
/**
|
|
111
|
+
* Region the sandbox runs in (e.g. `"hel1"`), as reported by the service.
|
|
112
|
+
* `undefined` on a service without regions.
|
|
113
|
+
*/
|
|
114
|
+
region;
|
|
96
115
|
commands;
|
|
97
116
|
files;
|
|
98
117
|
pty;
|
|
@@ -106,12 +125,13 @@ export class Sandbox {
|
|
|
106
125
|
client;
|
|
107
126
|
previewDomain;
|
|
108
127
|
keepAliveInterval = null;
|
|
109
|
-
constructor(sandboxId, client, previewDomain) {
|
|
128
|
+
constructor(sandboxId, client, previewDomain, region) {
|
|
110
129
|
this.sandboxId = sandboxId;
|
|
130
|
+
this.region = region || undefined;
|
|
111
131
|
this.client = client;
|
|
112
132
|
this.previewDomain = previewDomain
|
|
113
133
|
|| (typeof process !== "undefined" ? process.env.OMNIRUN_PREVIEW_DOMAIN : undefined)
|
|
114
|
-
||
|
|
134
|
+
|| DEFAULT_PREVIEW_DOMAIN;
|
|
115
135
|
this.commands = new Commands(sandboxId, client);
|
|
116
136
|
this.files = new Filesystem(sandboxId, client);
|
|
117
137
|
this.pty = new Pty(sandboxId, client);
|
|
@@ -121,32 +141,16 @@ export class Sandbox {
|
|
|
121
141
|
this.production = new Production(sandboxId, client);
|
|
122
142
|
this.webhooks = new Webhooks(client);
|
|
123
143
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
* @param opts.timeout - Sandbox timeout in seconds. Default `300`. Use `0` for a permanent sandbox.
|
|
130
|
-
* @param opts.apiKey - API key. Falls back to `OMNIRUN_API_KEY` env var.
|
|
131
|
-
* @param opts.apiUrl - API base URL. Falls back to `OMNIRUN_API_URL` env var.
|
|
132
|
-
* @param opts.internet - Enable outbound internet access.
|
|
133
|
-
* @param opts.envVars - Environment variables injected into the sandbox.
|
|
134
|
-
* @param opts.metadata - Arbitrary key-value metadata attached to the sandbox.
|
|
135
|
-
* @param opts.secure - Enable E2E encrypted mode.
|
|
136
|
-
* @param opts.maskRequestHost - Mask the request host header.
|
|
137
|
-
* @param opts.autoPause - Auto-pause the sandbox after inactivity.
|
|
138
|
-
* @param opts.keepAlive - Heartbeat interval in seconds to prevent auto-kill.
|
|
139
|
-
* @param opts.network - Network policy (allow/deny domains and IPs).
|
|
140
|
-
* @param opts.e2ee - E2EE bootstrap options or `true` for defaults.
|
|
141
|
-
* @param opts.vaultInject - Inject vault credentials as env vars via `/tmp/.omnirun-env`.
|
|
142
|
-
* @param opts.requestTimeout - HTTP request timeout in milliseconds.
|
|
143
|
-
* @returns A connected {@link Sandbox} instance.
|
|
144
|
-
*/
|
|
145
|
-
static async create(template = "python-3.11", opts) {
|
|
144
|
+
static async create(templateOrOpts, maybeOpts) {
|
|
145
|
+
const opts = templateOrOpts != null && typeof templateOrOpts === "object" ? templateOrOpts : maybeOpts;
|
|
146
|
+
const template = (templateOrOpts != null && typeof templateOrOpts === "object"
|
|
147
|
+
? templateOrOpts.template
|
|
148
|
+
: templateOrOpts) || "python-3.11";
|
|
146
149
|
const config = resolveConfig({
|
|
147
150
|
apiUrl: opts?.apiUrl,
|
|
148
151
|
apiKey: opts?.apiKey,
|
|
149
152
|
requestTimeout: opts?.requestTimeout,
|
|
153
|
+
retry: opts?.retry,
|
|
150
154
|
});
|
|
151
155
|
const client = new HTTPClient(config);
|
|
152
156
|
const body = {
|
|
@@ -162,8 +166,12 @@ export class Sandbox {
|
|
|
162
166
|
body.e2ee = true;
|
|
163
167
|
body.clientPublicKey = clientPublicKey;
|
|
164
168
|
}
|
|
169
|
+
if (opts?.region)
|
|
170
|
+
body.region = opts.region;
|
|
165
171
|
if (opts?.internet)
|
|
166
172
|
body.internet = true;
|
|
173
|
+
if (opts?.memory != null)
|
|
174
|
+
body.memoryMB = opts.memory;
|
|
167
175
|
if (opts?.envVars)
|
|
168
176
|
body.envVars = opts.envVars;
|
|
169
177
|
if (opts?.metadata)
|
|
@@ -178,8 +186,8 @@ export class Sandbox {
|
|
|
178
186
|
body.maskRequestHost = opts.maskRequestHost;
|
|
179
187
|
if (opts?.vaultInject)
|
|
180
188
|
body.vaultInject = true;
|
|
181
|
-
const data = await client.post("/sandboxes", body);
|
|
182
|
-
const sandbox = new Sandbox(data.sandboxID, client, opts?.previewDomain);
|
|
189
|
+
const data = await client.post("/sandboxes", body, { retry: "refusal" });
|
|
190
|
+
const sandbox = new Sandbox(data.sandboxID, client, opts?.previewDomain, data.region);
|
|
183
191
|
sandbox.trafficAccessToken = data.trafficToken ?? "";
|
|
184
192
|
if (e2eeOpts?.enabled && clientPublicKey) {
|
|
185
193
|
sandbox.e2ee = {
|
|
@@ -221,8 +229,32 @@ export class Sandbox {
|
|
|
221
229
|
static async connect(sandboxId, opts) {
|
|
222
230
|
const config = resolveConfig(opts);
|
|
223
231
|
const client = new HTTPClient(config);
|
|
224
|
-
|
|
225
|
-
|
|
232
|
+
let data;
|
|
233
|
+
try {
|
|
234
|
+
data = await client.get(`/sandboxes/${sandboxId}`);
|
|
235
|
+
}
|
|
236
|
+
catch (err) {
|
|
237
|
+
rethrowNotFound(err, sandboxId);
|
|
238
|
+
}
|
|
239
|
+
return new Sandbox(sandboxId, client, opts?.previewDomain, data?.region);
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* List the regions a sandbox can run in (`GET /regions`): which one is the
|
|
243
|
+
* default and whether each currently accepts new sandboxes. The list is
|
|
244
|
+
* empty on a service without regions; a single self-hosted node has no
|
|
245
|
+
* such endpoint and answers 404.
|
|
246
|
+
*
|
|
247
|
+
* @param opts - Connection options (apiKey, apiUrl, requestTimeout, retry).
|
|
248
|
+
*/
|
|
249
|
+
static async regions(opts) {
|
|
250
|
+
const client = new HTTPClient(resolveConfig(opts));
|
|
251
|
+
const data = await client.get("/regions");
|
|
252
|
+
const regions = Array.isArray(data) ? data : [];
|
|
253
|
+
return regions.map((r) => ({
|
|
254
|
+
id: String(r.id ?? ""),
|
|
255
|
+
default: r.default === true,
|
|
256
|
+
healthy: r.healthy === true,
|
|
257
|
+
}));
|
|
226
258
|
}
|
|
227
259
|
/**
|
|
228
260
|
* List sandboxes for the authenticated account.
|
|
@@ -276,9 +308,12 @@ export class Sandbox {
|
|
|
276
308
|
*
|
|
277
309
|
* @param timeout - New timeout value in seconds. The sandbox will be killed
|
|
278
310
|
* after this many seconds of wall-clock time unless the timer is reset again.
|
|
311
|
+
* @returns The timeout that took effect, which can be lower than requested
|
|
312
|
+
* (24-hour cap, or the limit of an account that is not yet approved).
|
|
279
313
|
*/
|
|
280
314
|
async setTimeout(timeout) {
|
|
281
|
-
await this.client.post(`/sandboxes/${this.sandboxId}/timeout`, { timeout });
|
|
315
|
+
const data = await this.client.post(`/sandboxes/${this.sandboxId}/timeout`, { timeout }, { retry: "idempotent" });
|
|
316
|
+
return typeof data?.timeout === "number" ? data.timeout : timeout;
|
|
282
317
|
}
|
|
283
318
|
/**
|
|
284
319
|
* Check whether the sandbox is currently in the `"running"` state.
|
|
@@ -302,12 +337,23 @@ export class Sandbox {
|
|
|
302
337
|
* memory, template ID, and timestamps.
|
|
303
338
|
*/
|
|
304
339
|
async getInfo() {
|
|
305
|
-
|
|
340
|
+
let data;
|
|
341
|
+
try {
|
|
342
|
+
data = await this.client.get(`/sandboxes/${this.sandboxId}`);
|
|
343
|
+
}
|
|
344
|
+
catch (err) {
|
|
345
|
+
rethrowNotFound(err, this.sandboxId);
|
|
346
|
+
}
|
|
306
347
|
return parseFullSandboxInfo(data);
|
|
307
348
|
}
|
|
308
|
-
/**
|
|
309
|
-
|
|
310
|
-
|
|
349
|
+
/**
|
|
350
|
+
* Execute code via the /code endpoint. Never retried automatically: after a
|
|
351
|
+
* `502 node_connection_lost` the code may have run.
|
|
352
|
+
*
|
|
353
|
+
* @param opts.requestTimeout - HTTP request timeout in milliseconds for this call.
|
|
354
|
+
*/
|
|
355
|
+
async runCode(code, language = "python", opts) {
|
|
356
|
+
const data = await this.client.post(`/sandboxes/${this.sandboxId}/code`, { code, language }, { retry: "never", timeoutMs: opts?.requestTimeout });
|
|
311
357
|
return makeCommandResult(data);
|
|
312
358
|
}
|
|
313
359
|
/** Get public URL for a port exposed inside the sandbox. */
|
|
@@ -320,7 +366,7 @@ export class Sandbox {
|
|
|
320
366
|
}
|
|
321
367
|
/** Get a pre-signed download URL for a file. */
|
|
322
368
|
async downloadUrl(path) {
|
|
323
|
-
const data = await this.client.post(`/sandboxes/${this.sandboxId}/files/download-url`, { path });
|
|
369
|
+
const data = await this.client.post(`/sandboxes/${this.sandboxId}/files/download-url`, { path }, { retry: "idempotent" });
|
|
324
370
|
let url = data.url ?? "";
|
|
325
371
|
if (url && !url.startsWith("http")) {
|
|
326
372
|
url = this.client.baseUrl.replace(/\/$/, "") + url;
|
|
@@ -329,7 +375,7 @@ export class Sandbox {
|
|
|
329
375
|
}
|
|
330
376
|
/** Get a pre-signed upload URL for a file. */
|
|
331
377
|
async uploadUrl(path) {
|
|
332
|
-
const data = await this.client.post(`/sandboxes/${this.sandboxId}/files/upload-url`, { path });
|
|
378
|
+
const data = await this.client.post(`/sandboxes/${this.sandboxId}/files/upload-url`, { path }, { retry: "idempotent" });
|
|
333
379
|
let url = data.url ?? "";
|
|
334
380
|
if (url && !url.startsWith("http")) {
|
|
335
381
|
url = this.client.baseUrl.replace(/\/$/, "") + url;
|
package/dist/webhooks.d.ts
CHANGED
|
@@ -4,7 +4,15 @@ import type { WebhookInfo } from "./models.js";
|
|
|
4
4
|
export declare class Webhooks {
|
|
5
5
|
private client;
|
|
6
6
|
constructor(client: HTTPClient);
|
|
7
|
-
/**
|
|
7
|
+
/** Create a new lifecycle webhook. */
|
|
8
|
+
create(url: string, events: string[]): Promise<{
|
|
9
|
+
id: string;
|
|
10
|
+
}>;
|
|
11
|
+
/**
|
|
12
|
+
* Register a new lifecycle webhook.
|
|
13
|
+
*
|
|
14
|
+
* @deprecated Use {@link create} instead. Retained as an alias for backwards compatibility.
|
|
15
|
+
*/
|
|
8
16
|
register(url: string, events: string[]): Promise<{
|
|
9
17
|
id: string;
|
|
10
18
|
}>;
|
package/dist/webhooks.js
CHANGED
|
@@ -4,10 +4,18 @@ export class Webhooks {
|
|
|
4
4
|
constructor(client) {
|
|
5
5
|
this.client = client;
|
|
6
6
|
}
|
|
7
|
-
/**
|
|
8
|
-
async
|
|
7
|
+
/** Create a new lifecycle webhook. */
|
|
8
|
+
async create(url, events) {
|
|
9
9
|
return this.client.post("/webhooks", { url, events });
|
|
10
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Register a new lifecycle webhook.
|
|
13
|
+
*
|
|
14
|
+
* @deprecated Use {@link create} instead. Retained as an alias for backwards compatibility.
|
|
15
|
+
*/
|
|
16
|
+
async register(url, events) {
|
|
17
|
+
return this.create(url, events);
|
|
18
|
+
}
|
|
11
19
|
/** List all registered webhooks. */
|
|
12
20
|
async list() {
|
|
13
21
|
const data = await this.client.get("/webhooks");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@omnirun/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "TypeScript SDK for OmniRun sandboxes",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
],
|
|
41
41
|
"license": "MIT",
|
|
42
42
|
"engines": {
|
|
43
|
-
"node": ">=
|
|
43
|
+
"node": ">=24.21.0"
|
|
44
44
|
},
|
|
45
45
|
"publishConfig": {
|
|
46
46
|
"access": "public",
|
|
@@ -55,9 +55,9 @@
|
|
|
55
55
|
},
|
|
56
56
|
"homepage": "https://github.com/a14a-org/omnirun-sdk#readme",
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@changesets/cli": "^
|
|
59
|
-
"@types/node": "^
|
|
60
|
-
"typescript": "^
|
|
61
|
-
"vitest": "^
|
|
58
|
+
"@changesets/cli": "^3.0.3",
|
|
59
|
+
"@types/node": "^26.6.11",
|
|
60
|
+
"typescript": "^7.0.2",
|
|
61
|
+
"vitest": "^5.1.2"
|
|
62
62
|
}
|
|
63
63
|
}
|