@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/dist/errors.d.ts
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
|
+
/** Machine-readable details the service sends with an error response. */
|
|
2
|
+
export interface SandboxErrorInfo {
|
|
3
|
+
/** Stable machine-readable reason, e.g. `"no_capacity"` or `"node_unavailable"`. */
|
|
4
|
+
reason?: string;
|
|
5
|
+
/** Extra detail some refusals carry (e.g. the budget behind `no_capacity`). For information only. */
|
|
6
|
+
detail?: string;
|
|
7
|
+
/** Parsed `Retry-After` header in seconds, when the service sent one. */
|
|
8
|
+
retryAfterSeconds?: number;
|
|
9
|
+
/** Whether sending the same request again is safe under the SDK's retry rules. */
|
|
10
|
+
retryable?: boolean;
|
|
11
|
+
}
|
|
1
12
|
export declare class SandboxError extends Error {
|
|
2
|
-
|
|
13
|
+
/** HTTP status code that produced this error, if applicable. */
|
|
14
|
+
status?: number;
|
|
15
|
+
/**
|
|
16
|
+
* Stable machine-readable reason from the service (`no_capacity`,
|
|
17
|
+
* `node_unavailable`, `unknown_region`, `approval_required`, ...).
|
|
18
|
+
* Branch on `status` and `reason`, never on `message`.
|
|
19
|
+
*/
|
|
20
|
+
reason?: string;
|
|
21
|
+
/** Extra detail some refusals carry. For information only; do not branch on it. */
|
|
22
|
+
detail?: string;
|
|
23
|
+
/** Seconds the service asked to wait before retrying (`Retry-After`), or `undefined`. */
|
|
24
|
+
retryAfterSeconds?: number;
|
|
25
|
+
/**
|
|
26
|
+
* `true` when sending the same request again is safe: the service refused it
|
|
27
|
+
* without doing anything (or the call is idempotent). `false` when the
|
|
28
|
+
* request may have taken effect (e.g. `502 node_connection_lost` on a
|
|
29
|
+
* command, `504` on a create) or when retrying cannot help (4xx).
|
|
30
|
+
*/
|
|
31
|
+
retryable: boolean;
|
|
32
|
+
constructor(message: string, status?: number, info?: SandboxErrorInfo);
|
|
3
33
|
}
|
|
4
34
|
export declare class SandboxNotFoundError extends SandboxError {
|
|
5
35
|
constructor(sandboxId: string);
|
|
@@ -11,7 +41,7 @@ export declare class CommandExitException extends SandboxError {
|
|
|
11
41
|
constructor(stdout: string, stderr: string, exitCode: number);
|
|
12
42
|
}
|
|
13
43
|
export declare class StreamError extends SandboxError {
|
|
14
|
-
constructor(message: string);
|
|
44
|
+
constructor(message: string, status?: number, info?: SandboxErrorInfo);
|
|
15
45
|
}
|
|
16
46
|
export declare class TimeoutError extends SandboxError {
|
|
17
47
|
constructor(message: string);
|
package/dist/errors.js
CHANGED
|
@@ -1,12 +1,36 @@
|
|
|
1
1
|
export class SandboxError extends Error {
|
|
2
|
-
|
|
2
|
+
/** HTTP status code that produced this error, if applicable. */
|
|
3
|
+
status;
|
|
4
|
+
/**
|
|
5
|
+
* Stable machine-readable reason from the service (`no_capacity`,
|
|
6
|
+
* `node_unavailable`, `unknown_region`, `approval_required`, ...).
|
|
7
|
+
* Branch on `status` and `reason`, never on `message`.
|
|
8
|
+
*/
|
|
9
|
+
reason;
|
|
10
|
+
/** Extra detail some refusals carry. For information only; do not branch on it. */
|
|
11
|
+
detail;
|
|
12
|
+
/** Seconds the service asked to wait before retrying (`Retry-After`), or `undefined`. */
|
|
13
|
+
retryAfterSeconds;
|
|
14
|
+
/**
|
|
15
|
+
* `true` when sending the same request again is safe: the service refused it
|
|
16
|
+
* without doing anything (or the call is idempotent). `false` when the
|
|
17
|
+
* request may have taken effect (e.g. `502 node_connection_lost` on a
|
|
18
|
+
* command, `504` on a create) or when retrying cannot help (4xx).
|
|
19
|
+
*/
|
|
20
|
+
retryable;
|
|
21
|
+
constructor(message, status, info) {
|
|
3
22
|
super(message);
|
|
4
23
|
this.name = "SandboxError";
|
|
24
|
+
this.status = status;
|
|
25
|
+
this.reason = info?.reason;
|
|
26
|
+
this.detail = info?.detail;
|
|
27
|
+
this.retryAfterSeconds = info?.retryAfterSeconds;
|
|
28
|
+
this.retryable = info?.retryable ?? false;
|
|
5
29
|
}
|
|
6
30
|
}
|
|
7
31
|
export class SandboxNotFoundError extends SandboxError {
|
|
8
32
|
constructor(sandboxId) {
|
|
9
|
-
super(`Sandbox ${sandboxId} not found
|
|
33
|
+
super(`Sandbox ${sandboxId} not found`, 404);
|
|
10
34
|
this.name = "SandboxNotFoundError";
|
|
11
35
|
}
|
|
12
36
|
}
|
|
@@ -23,8 +47,8 @@ export class CommandExitException extends SandboxError {
|
|
|
23
47
|
}
|
|
24
48
|
}
|
|
25
49
|
export class StreamError extends SandboxError {
|
|
26
|
-
constructor(message) {
|
|
27
|
-
super(message);
|
|
50
|
+
constructor(message, status, info) {
|
|
51
|
+
super(message, status, info);
|
|
28
52
|
this.name = "StreamError";
|
|
29
53
|
}
|
|
30
54
|
}
|
package/dist/exposures.d.ts
CHANGED
|
@@ -1,14 +1,65 @@
|
|
|
1
1
|
import type { HTTPClient } from "./client.js";
|
|
2
2
|
import type { CreateExposureOptions, ExposureInfo, RefreshExposureOptions } from "./models.js";
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Preview URL management namespace for a sandbox.
|
|
5
|
+
*
|
|
6
|
+
* An exposure creates a publicly (or privately) accessible URL that proxies
|
|
7
|
+
* traffic to a port inside the sandbox. The lifecycle of an exposure is:
|
|
8
|
+
*
|
|
9
|
+
* `pending` -> `ready` -> `expired` | `revoked` | `sandbox_stopped`
|
|
10
|
+
*
|
|
11
|
+
* - **pending**: The exposure has been requested but the proxy is not yet routing traffic.
|
|
12
|
+
* - **ready**: The URL is live and accepting requests.
|
|
13
|
+
* - **expired**: The TTL elapsed without a refresh.
|
|
14
|
+
* - **revoked**: The exposure was explicitly closed via {@link close}.
|
|
15
|
+
* - **sandbox_stopped**: The parent sandbox was killed or stopped.
|
|
16
|
+
*/
|
|
4
17
|
export declare class Exposures {
|
|
5
18
|
private sandboxId;
|
|
6
19
|
private client;
|
|
7
20
|
constructor(sandboxId: string, client: HTTPClient);
|
|
8
21
|
private get baseUrl();
|
|
22
|
+
/**
|
|
23
|
+
* Create a new exposure for a sandbox port.
|
|
24
|
+
*
|
|
25
|
+
* @param port - The port number inside the sandbox to expose (1-65535).
|
|
26
|
+
* @param opts - Optional configuration.
|
|
27
|
+
* @param opts.visibility - `"public"` (default) or `"private"` (requires auth token).
|
|
28
|
+
* @param opts.ttlSeconds - Time-to-live in seconds before the exposure expires.
|
|
29
|
+
* @param opts.slug - Custom slug for the exposure URL.
|
|
30
|
+
* @param opts.openPath - Path appended to the exposure URL when opened in a browser.
|
|
31
|
+
* @param opts.preserveHost - Whether to preserve the original `Host` header when proxying.
|
|
32
|
+
* @returns The created {@link ExposureInfo}.
|
|
33
|
+
*/
|
|
9
34
|
create(port: number, opts?: CreateExposureOptions): Promise<ExposureInfo>;
|
|
35
|
+
/**
|
|
36
|
+
* List all exposures for this sandbox.
|
|
37
|
+
*
|
|
38
|
+
* @returns An array of {@link ExposureInfo} objects for every exposure
|
|
39
|
+
* (including expired and revoked ones).
|
|
40
|
+
*/
|
|
10
41
|
list(): Promise<ExposureInfo[]>;
|
|
42
|
+
/**
|
|
43
|
+
* Get details for a single exposure.
|
|
44
|
+
*
|
|
45
|
+
* @param exposureId - The unique exposure identifier.
|
|
46
|
+
* @returns The {@link ExposureInfo} for the requested exposure.
|
|
47
|
+
*/
|
|
11
48
|
get(exposureId: string): Promise<ExposureInfo>;
|
|
49
|
+
/**
|
|
50
|
+
* Extend the TTL of an existing exposure, preventing it from expiring.
|
|
51
|
+
*
|
|
52
|
+
* @param exposureId - The unique exposure identifier.
|
|
53
|
+
* @param opts - Optional refresh options.
|
|
54
|
+
* @param opts.ttlSeconds - New TTL in seconds from now. If omitted the server default is used.
|
|
55
|
+
* @returns The updated {@link ExposureInfo} with the new `expiresAt` timestamp.
|
|
56
|
+
*/
|
|
12
57
|
refresh(exposureId: string, opts?: RefreshExposureOptions): Promise<ExposureInfo>;
|
|
58
|
+
/**
|
|
59
|
+
* Permanently close and revoke an exposure. The URL will immediately
|
|
60
|
+
* stop accepting traffic. This action cannot be undone.
|
|
61
|
+
*
|
|
62
|
+
* @param exposureId - The unique exposure identifier.
|
|
63
|
+
*/
|
|
13
64
|
close(exposureId: string): Promise<void>;
|
|
14
65
|
}
|
package/dist/exposures.js
CHANGED
|
@@ -19,7 +19,20 @@ function parseExposureInfo(data) {
|
|
|
19
19
|
createdBy: data.createdBy,
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
|
-
/**
|
|
22
|
+
/**
|
|
23
|
+
* Preview URL management namespace for a sandbox.
|
|
24
|
+
*
|
|
25
|
+
* An exposure creates a publicly (or privately) accessible URL that proxies
|
|
26
|
+
* traffic to a port inside the sandbox. The lifecycle of an exposure is:
|
|
27
|
+
*
|
|
28
|
+
* `pending` -> `ready` -> `expired` | `revoked` | `sandbox_stopped`
|
|
29
|
+
*
|
|
30
|
+
* - **pending**: The exposure has been requested but the proxy is not yet routing traffic.
|
|
31
|
+
* - **ready**: The URL is live and accepting requests.
|
|
32
|
+
* - **expired**: The TTL elapsed without a refresh.
|
|
33
|
+
* - **revoked**: The exposure was explicitly closed via {@link close}.
|
|
34
|
+
* - **sandbox_stopped**: The parent sandbox was killed or stopped.
|
|
35
|
+
*/
|
|
23
36
|
export class Exposures {
|
|
24
37
|
sandboxId;
|
|
25
38
|
client;
|
|
@@ -30,6 +43,18 @@ export class Exposures {
|
|
|
30
43
|
get baseUrl() {
|
|
31
44
|
return `/sandboxes/${this.sandboxId}/exposures`;
|
|
32
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Create a new exposure for a sandbox port.
|
|
48
|
+
*
|
|
49
|
+
* @param port - The port number inside the sandbox to expose (1-65535).
|
|
50
|
+
* @param opts - Optional configuration.
|
|
51
|
+
* @param opts.visibility - `"public"` (default) or `"private"` (requires auth token).
|
|
52
|
+
* @param opts.ttlSeconds - Time-to-live in seconds before the exposure expires.
|
|
53
|
+
* @param opts.slug - Custom slug for the exposure URL.
|
|
54
|
+
* @param opts.openPath - Path appended to the exposure URL when opened in a browser.
|
|
55
|
+
* @param opts.preserveHost - Whether to preserve the original `Host` header when proxying.
|
|
56
|
+
* @returns The created {@link ExposureInfo}.
|
|
57
|
+
*/
|
|
33
58
|
async create(port, opts) {
|
|
34
59
|
const data = await this.client.post(this.baseUrl, {
|
|
35
60
|
port,
|
|
@@ -41,21 +66,47 @@ export class Exposures {
|
|
|
41
66
|
});
|
|
42
67
|
return parseExposureInfo(data);
|
|
43
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* List all exposures for this sandbox.
|
|
71
|
+
*
|
|
72
|
+
* @returns An array of {@link ExposureInfo} objects for every exposure
|
|
73
|
+
* (including expired and revoked ones).
|
|
74
|
+
*/
|
|
44
75
|
async list() {
|
|
45
76
|
const data = await this.client.get(this.baseUrl);
|
|
46
77
|
const items = Array.isArray(data) ? data : [];
|
|
47
78
|
return items.map(parseExposureInfo);
|
|
48
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* Get details for a single exposure.
|
|
82
|
+
*
|
|
83
|
+
* @param exposureId - The unique exposure identifier.
|
|
84
|
+
* @returns The {@link ExposureInfo} for the requested exposure.
|
|
85
|
+
*/
|
|
49
86
|
async get(exposureId) {
|
|
50
87
|
const data = await this.client.get(`${this.baseUrl}/${exposureId}`);
|
|
51
88
|
return parseExposureInfo(data);
|
|
52
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* Extend the TTL of an existing exposure, preventing it from expiring.
|
|
92
|
+
*
|
|
93
|
+
* @param exposureId - The unique exposure identifier.
|
|
94
|
+
* @param opts - Optional refresh options.
|
|
95
|
+
* @param opts.ttlSeconds - New TTL in seconds from now. If omitted the server default is used.
|
|
96
|
+
* @returns The updated {@link ExposureInfo} with the new `expiresAt` timestamp.
|
|
97
|
+
*/
|
|
53
98
|
async refresh(exposureId, opts) {
|
|
54
99
|
const data = await this.client.post(`${this.baseUrl}/${exposureId}/refresh`, {
|
|
55
100
|
requestedTtlSeconds: opts?.ttlSeconds,
|
|
56
101
|
});
|
|
57
102
|
return parseExposureInfo(data);
|
|
58
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* Permanently close and revoke an exposure. The URL will immediately
|
|
106
|
+
* stop accepting traffic. This action cannot be undone.
|
|
107
|
+
*
|
|
108
|
+
* @param exposureId - The unique exposure identifier.
|
|
109
|
+
*/
|
|
59
110
|
async close(exposureId) {
|
|
60
111
|
await this.client.delete(`${this.baseUrl}/${exposureId}`);
|
|
61
112
|
}
|
package/dist/filesystem.js
CHANGED
|
@@ -26,7 +26,9 @@ export class Filesystem {
|
|
|
26
26
|
async write(pathOrEntries, content, opts) {
|
|
27
27
|
// Batch write
|
|
28
28
|
if (Array.isArray(pathOrEntries)) {
|
|
29
|
-
const data = await this.client.post(`${this.baseUrl}/batch`, pathOrEntries
|
|
29
|
+
const data = await this.client.post(`${this.baseUrl}/batch`, pathOrEntries, {
|
|
30
|
+
retry: "idempotent",
|
|
31
|
+
});
|
|
30
32
|
return data.map((r) => ({
|
|
31
33
|
name: r.name ?? "",
|
|
32
34
|
path: r.path ?? "",
|
|
@@ -51,7 +53,7 @@ export class Filesystem {
|
|
|
51
53
|
const body = { path, content: content ?? "" };
|
|
52
54
|
if (writeOpts?.user)
|
|
53
55
|
body.user = writeOpts.user;
|
|
54
|
-
const data = await this.client.post(this.baseUrl, body);
|
|
56
|
+
const data = await this.client.post(this.baseUrl, body, { retry: "idempotent" });
|
|
55
57
|
return {
|
|
56
58
|
name: path.split("/").pop() || "",
|
|
57
59
|
path: data.path ?? path,
|
|
@@ -116,7 +118,7 @@ export class Filesystem {
|
|
|
116
118
|
const body = { path };
|
|
117
119
|
if (opts?.user)
|
|
118
120
|
body.user = opts.user;
|
|
119
|
-
await this.client.post(`${this.baseUrl}/mkdir`, body);
|
|
121
|
+
await this.client.post(`${this.baseUrl}/mkdir`, body, { retry: "idempotent" });
|
|
120
122
|
}
|
|
121
123
|
watchDir(path, opts) {
|
|
122
124
|
return new WatchHandle(this.sandboxId, path, opts?.recursive ?? false, this.client);
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,8 @@ export { CommandHandle } from "./command-handle.js";
|
|
|
5
5
|
export { Filesystem } from "./filesystem.js";
|
|
6
6
|
export { Pty, PtySession } from "./pty.js";
|
|
7
7
|
export { Contexts } from "./contexts.js";
|
|
8
|
+
export { Desktop } from "./desktop.js";
|
|
9
|
+
export type { ScreenInfo, DesktopStreamInfo, MouseOptions, KeyboardOptions, MouseAction, ScrollDirection, KeyboardAction, } from "./desktop.js";
|
|
8
10
|
export { Exposures } from "./exposures.js";
|
|
9
11
|
export { Production } from "./production.js";
|
|
10
12
|
export { Webhooks } from "./webhooks.js";
|
|
@@ -12,11 +14,13 @@ export { LLM } from "./llm.js";
|
|
|
12
14
|
export type { ChatMessage, ChatCompletionRequest, ChatCompletionResponse, ChatCompletionChoice, ChatCompletionUsage, LLMUsage, LLMModel, } from "./llm.js";
|
|
13
15
|
export { WatchHandle } from "./watch-handle.js";
|
|
14
16
|
export { HTTPClient } from "./client.js";
|
|
17
|
+
export type { RetryPolicy, RequestOptions } from "./client.js";
|
|
15
18
|
export { generateE2EEKeyPair, importE2EEPublicKey, deriveE2EESharedKey, encryptE2EEJSON, decryptE2EEJSON, } from "./e2ee.js";
|
|
16
19
|
export { resolveConfig } from "./config.js";
|
|
17
|
-
export type { ConnectionConfig } from "./config.js";
|
|
20
|
+
export type { ConnectionConfig, RetryOptions } from "./config.js";
|
|
18
21
|
export { SandboxError, SandboxNotFoundError, CommandExitException, StreamError, TimeoutError, } from "./errors.js";
|
|
19
|
-
export type {
|
|
22
|
+
export type { SandboxErrorInfo } from "./errors.js";
|
|
23
|
+
export type { CommandResult, EntryInfo, SandboxInfo, FullSandboxInfo, RegionInfo, ConnectOptions, ExposureInfo, ExposureStatus, ExposureVisibility, ProcessInfo, PtyInfo, WriteEntry, FilesystemEvent, StreamEvent, RunCommandOptions, CreateSandboxOptions, CreateExposureOptions, ListSandboxOptions, RefreshExposureOptions, ContextInfo, ResultItem, LogOutput, ExecutionResult, SandboxMetrics, MetricsSnapshot, NetworkPolicy, WebhookInfo, CodeResult, } from "./models.js";
|
|
20
24
|
export type { E2EEAlgorithm, E2EEKeyPairMaterial, E2EECreateOptions, E2EESessionInfo, EncryptedEnvelope, } from "./e2ee.js";
|
|
21
25
|
export type { FileReadOptions, FileWriteOptions, FileListOptions } from "./filesystem.js";
|
|
22
26
|
export type { ExecuteOptions } from "./contexts.js";
|
package/dist/index.js
CHANGED
|
@@ -5,6 +5,7 @@ export { CommandHandle } from "./command-handle.js";
|
|
|
5
5
|
export { Filesystem } from "./filesystem.js";
|
|
6
6
|
export { Pty, PtySession } from "./pty.js";
|
|
7
7
|
export { Contexts } from "./contexts.js";
|
|
8
|
+
export { Desktop } from "./desktop.js";
|
|
8
9
|
export { Exposures } from "./exposures.js";
|
|
9
10
|
export { Production } from "./production.js";
|
|
10
11
|
export { Webhooks } from "./webhooks.js";
|
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;
|
|
@@ -61,23 +82,41 @@ export interface FullSandboxInfo extends SandboxInfo {
|
|
|
61
82
|
}
|
|
62
83
|
export type ExposureVisibility = "public" | "private";
|
|
63
84
|
export type ExposureStatus = "pending" | "ready" | "revoked" | "expired" | "sandbox_stopped" | "error";
|
|
85
|
+
/** Detailed information about a sandbox port exposure (preview URL). */
|
|
64
86
|
export interface ExposureInfo {
|
|
87
|
+
/** Unique exposure identifier. */
|
|
65
88
|
id: string;
|
|
89
|
+
/** ID of the parent sandbox. */
|
|
66
90
|
sandboxId: string;
|
|
91
|
+
/** Account that owns the exposure. */
|
|
67
92
|
accountId?: string;
|
|
93
|
+
/** Sandbox-internal port being exposed. */
|
|
68
94
|
port: number;
|
|
95
|
+
/** Hostname of the exposure proxy. */
|
|
69
96
|
hostname: string;
|
|
97
|
+
/** Full public URL for the exposure. */
|
|
70
98
|
url: string;
|
|
99
|
+
/** URL with embedded access token for private exposures. */
|
|
71
100
|
accessUrl?: string;
|
|
101
|
+
/** Visibility level: `"public"` or `"private"`. */
|
|
72
102
|
visibility: ExposureVisibility;
|
|
103
|
+
/** Current lifecycle status of the exposure. */
|
|
73
104
|
status: ExposureStatus;
|
|
105
|
+
/** ISO-8601 timestamp when the exposure was created. */
|
|
74
106
|
createdAt: string;
|
|
107
|
+
/** ISO-8601 timestamp when the exposure will expire. */
|
|
75
108
|
expiresAt: string;
|
|
109
|
+
/** ISO-8601 timestamp when the exposure was revoked, if applicable. */
|
|
76
110
|
revokedAt?: string;
|
|
111
|
+
/** ISO-8601 timestamp when the parent sandbox stopped, if applicable. */
|
|
77
112
|
sandboxStoppedAt?: string;
|
|
113
|
+
/** ISO-8601 timestamp of the last proxied request. */
|
|
78
114
|
lastAccessedAt?: string;
|
|
115
|
+
/** Default path appended to the URL when opened in a browser. */
|
|
79
116
|
openPath?: string;
|
|
117
|
+
/** Whether the original `Host` header is preserved when proxying. */
|
|
80
118
|
preserveHost: boolean;
|
|
119
|
+
/** Identifier of the user or API key that created the exposure. */
|
|
81
120
|
createdBy?: string;
|
|
82
121
|
}
|
|
83
122
|
export interface CreateExposureOptions {
|
|
@@ -92,7 +131,13 @@ export interface RefreshExposureOptions {
|
|
|
92
131
|
}
|
|
93
132
|
export interface RunCommandOptions {
|
|
94
133
|
cwd?: string;
|
|
134
|
+
/** Command timeout in seconds. Default `60`; the service caps it at `3600`. */
|
|
95
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;
|
|
96
141
|
background?: boolean;
|
|
97
142
|
envs?: Record<string, string>;
|
|
98
143
|
user?: string;
|
|
@@ -100,24 +145,53 @@ export interface RunCommandOptions {
|
|
|
100
145
|
onStderr?: (data: string) => void;
|
|
101
146
|
}
|
|
102
147
|
export interface CreateSandboxOptions {
|
|
148
|
+
/** Sandbox timeout in seconds. Default varies by template (typically 300). Use `0` for a permanent sandbox. */
|
|
103
149
|
timeout?: number;
|
|
150
|
+
/** OmniRun API key. Falls back to `OMNIRUN_API_KEY` environment variable. */
|
|
104
151
|
apiKey?: string;
|
|
152
|
+
/** OmniRun API base URL. Falls back to `OMNIRUN_API_URL` environment variable. */
|
|
105
153
|
apiUrl?: string;
|
|
154
|
+
/** HTTP request timeout in milliseconds for SDK-to-API calls. */
|
|
106
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;
|
|
164
|
+
/** Enable outbound internet access from the sandbox. Default: `false`. */
|
|
107
165
|
internet?: boolean;
|
|
166
|
+
/** Memory allocation in MB. Requires backend support; currently ignored by the server (memory is derived from the template). */
|
|
167
|
+
memory?: number;
|
|
168
|
+
/** Environment variables injected into the sandbox at creation time. */
|
|
108
169
|
envVars?: Record<string, string>;
|
|
170
|
+
/** Arbitrary key-value metadata attached to the sandbox. Queryable via `list()`. */
|
|
109
171
|
metadata?: Record<string, string>;
|
|
172
|
+
/** Heartbeat interval in seconds. The SDK sends periodic `setTimeout` calls to prevent auto-kill. */
|
|
110
173
|
keepAlive?: number;
|
|
174
|
+
/** Auto-pause the sandbox after a period of inactivity instead of killing it. */
|
|
111
175
|
autoPause?: boolean;
|
|
176
|
+
/** Network policy controlling allowed/denied domains and IPs for outbound traffic. */
|
|
112
177
|
network?: NetworkPolicy;
|
|
178
|
+
/** Enable E2E encrypted mode for the sandbox. */
|
|
113
179
|
secure?: boolean;
|
|
180
|
+
/** Mask the request `Host` header seen inside the sandbox with this value. */
|
|
114
181
|
maskRequestHost?: string;
|
|
115
|
-
/**
|
|
182
|
+
/** Inject vault credentials into the sandbox as environment variables via `/tmp/.omnirun-env`. */
|
|
183
|
+
vaultInject?: boolean;
|
|
184
|
+
/** Client-side E2EE bootstrap options (key generation + public key announcement). Pass `true` for defaults. */
|
|
116
185
|
e2ee?: boolean | E2EECreateOptions;
|
|
186
|
+
/** Domain used for sandbox preview URLs (e.g. `"omnirun-preview.dev"`). Falls back to `OMNIRUN_PREVIEW_DOMAIN` env var, then `"omnirun-preview.dev"`. */
|
|
187
|
+
previewDomain?: string;
|
|
117
188
|
}
|
|
118
189
|
export interface ListSandboxOptions {
|
|
119
190
|
apiKey?: string;
|
|
120
191
|
apiUrl?: string;
|
|
192
|
+
requestTimeout?: number;
|
|
193
|
+
/** Bounds for automatic retries, or `false` to switch them off. */
|
|
194
|
+
retry?: RetryOptions | false;
|
|
121
195
|
limit?: number;
|
|
122
196
|
nextToken?: string;
|
|
123
197
|
state?: string;
|
|
@@ -149,19 +223,32 @@ export interface ExecutionResult {
|
|
|
149
223
|
error?: string;
|
|
150
224
|
executionCount?: number;
|
|
151
225
|
}
|
|
226
|
+
/** Aggregated usage metrics for a sandbox. */
|
|
152
227
|
export interface SandboxMetrics {
|
|
228
|
+
/** Total CPU time consumed in milliseconds. */
|
|
153
229
|
cpuTimeMs: number;
|
|
230
|
+
/** Current memory usage in megabytes. */
|
|
154
231
|
memoryUsedMb: number;
|
|
232
|
+
/** Current disk usage in megabytes. */
|
|
155
233
|
diskUsedMb: number;
|
|
234
|
+
/** Network bytes received in kilobytes. */
|
|
156
235
|
networkRxKb: number;
|
|
236
|
+
/** Network bytes transmitted in kilobytes. */
|
|
157
237
|
networkTxKb: number;
|
|
238
|
+
/** Number of commands executed in the sandbox. */
|
|
158
239
|
commandCount: number;
|
|
240
|
+
/** Human-readable uptime string or ISO-8601 timestamp. */
|
|
159
241
|
uptime: string;
|
|
160
242
|
}
|
|
243
|
+
/** Network policy controlling outbound traffic from a sandbox. */
|
|
161
244
|
export interface NetworkPolicy {
|
|
245
|
+
/** Domains the sandbox is allowed to reach. If set, only these domains are permitted. */
|
|
162
246
|
allowDomains?: string[];
|
|
247
|
+
/** Domains the sandbox is explicitly blocked from reaching. */
|
|
163
248
|
denyDomains?: string[];
|
|
249
|
+
/** IP addresses or CIDR ranges the sandbox is allowed to reach. */
|
|
164
250
|
allowIPs?: string[];
|
|
251
|
+
/** IP addresses or CIDR ranges the sandbox is explicitly blocked from reaching. */
|
|
165
252
|
denyIPs?: string[];
|
|
166
253
|
}
|
|
167
254
|
export interface WebhookInfo {
|
|
@@ -174,12 +261,20 @@ export interface CodeResult {
|
|
|
174
261
|
stderr: string;
|
|
175
262
|
exitCode: number;
|
|
176
263
|
}
|
|
264
|
+
/** A single point-in-time metrics snapshot from the sandbox time-series. */
|
|
177
265
|
export interface MetricsSnapshot {
|
|
266
|
+
/** ISO-8601 timestamp of the snapshot. */
|
|
178
267
|
timestamp: string;
|
|
268
|
+
/** CPU utilization as a percentage (0-100). */
|
|
179
269
|
cpuUsedPct: number;
|
|
270
|
+
/** Number of virtual CPUs allocated to the sandbox. */
|
|
180
271
|
cpuCount: number;
|
|
272
|
+
/** Memory currently used in bytes. */
|
|
181
273
|
memUsed: number;
|
|
274
|
+
/** Total memory available in bytes. */
|
|
182
275
|
memTotal: number;
|
|
276
|
+
/** Disk space currently used in bytes. */
|
|
183
277
|
diskUsed: number;
|
|
278
|
+
/** Total disk space available in bytes. */
|
|
184
279
|
diskTotal: number;
|
|
185
280
|
}
|
package/dist/production.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { HTTPClient } from "./client.js";
|
|
2
2
|
import type { MetricsSnapshot, NetworkPolicy, SandboxMetrics } from "./models.js";
|
|
3
|
+
/** Map a raw metrics snapshot from the API (snake_case) to a {@link MetricsSnapshot}. */
|
|
4
|
+
export declare function parseMetricsSnapshot(m: any): MetricsSnapshot;
|
|
3
5
|
/** Production controls for pause/resume/metrics/network policy. */
|
|
4
6
|
export declare class Production {
|
|
5
7
|
private sandboxId;
|
package/dist/production.js
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
/** Map a raw metrics snapshot from the API (snake_case) to a {@link MetricsSnapshot}. */
|
|
2
|
+
export function parseMetricsSnapshot(m) {
|
|
3
|
+
return {
|
|
4
|
+
timestamp: m.timestamp ?? "",
|
|
5
|
+
cpuUsedPct: m.cpu_used_pct ?? 0,
|
|
6
|
+
cpuCount: m.cpu_count ?? 0,
|
|
7
|
+
memUsed: m.mem_used ?? 0,
|
|
8
|
+
memTotal: m.mem_total ?? 0,
|
|
9
|
+
diskUsed: m.disk_used ?? 0,
|
|
10
|
+
diskTotal: m.disk_total ?? 0,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
1
13
|
/** Production controls for pause/resume/metrics/network policy. */
|
|
2
14
|
export class Production {
|
|
3
15
|
sandboxId;
|
|
@@ -48,15 +60,7 @@ export class Production {
|
|
|
48
60
|
const data = await this.client.get(`${this.baseUrl}/metrics`);
|
|
49
61
|
if (!Array.isArray(data))
|
|
50
62
|
return [];
|
|
51
|
-
return data.map(
|
|
52
|
-
timestamp: m.timestamp ?? "",
|
|
53
|
-
cpuUsedPct: m.cpu_used_pct ?? 0,
|
|
54
|
-
cpuCount: m.cpu_count ?? 0,
|
|
55
|
-
memUsed: m.mem_used ?? 0,
|
|
56
|
-
memTotal: m.mem_total ?? 0,
|
|
57
|
-
diskUsed: m.disk_used ?? 0,
|
|
58
|
-
diskTotal: m.disk_total ?? 0,
|
|
59
|
-
}));
|
|
63
|
+
return data.map(parseMetricsSnapshot);
|
|
60
64
|
}
|
|
61
65
|
/** Set network policy for the sandbox. */
|
|
62
66
|
async setNetworkPolicy(policy) {
|
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 });
|