@omnirun/sdk 0.3.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.
@@ -0,0 +1,23 @@
1
+ import type { HTTPClient } from "./client.js";
2
+ import type { MetricsSnapshot, NetworkPolicy, SandboxMetrics } from "./models.js";
3
+ /** Production controls for pause/resume/metrics/network policy. */
4
+ export declare class Production {
5
+ private sandboxId;
6
+ private client;
7
+ constructor(sandboxId: string, client: HTTPClient);
8
+ private get baseUrl();
9
+ /** Pause the sandbox VM. */
10
+ pause(): Promise<{
11
+ status: string;
12
+ }>;
13
+ /** Resume a paused sandbox VM. */
14
+ resume(): Promise<{
15
+ status: string;
16
+ }>;
17
+ /** Get usage metrics for the sandbox. */
18
+ metrics(): Promise<SandboxMetrics>;
19
+ /** Get raw metrics snapshots if the backend returns time-series data. */
20
+ metricsSnapshots(): Promise<MetricsSnapshot[]>;
21
+ /** Set network policy for the sandbox. */
22
+ setNetworkPolicy(policy: NetworkPolicy): Promise<void>;
23
+ }
@@ -0,0 +1,70 @@
1
+ /** Production controls for pause/resume/metrics/network policy. */
2
+ export class Production {
3
+ sandboxId;
4
+ client;
5
+ constructor(sandboxId, client) {
6
+ this.sandboxId = sandboxId;
7
+ this.client = client;
8
+ }
9
+ get baseUrl() {
10
+ return `/sandboxes/${this.sandboxId}`;
11
+ }
12
+ /** Pause the sandbox VM. */
13
+ async pause() {
14
+ return this.client.post(`${this.baseUrl}/pause`);
15
+ }
16
+ /** Resume a paused sandbox VM. */
17
+ async resume() {
18
+ return this.client.post(`${this.baseUrl}/resume`);
19
+ }
20
+ /** Get usage metrics for the sandbox. */
21
+ async metrics() {
22
+ const data = await this.client.get(`${this.baseUrl}/metrics`);
23
+ // Newer API shape: array of snapshots.
24
+ if (Array.isArray(data)) {
25
+ const last = data[data.length - 1] ?? {};
26
+ return {
27
+ cpuTimeMs: 0,
28
+ memoryUsedMb: Math.round((last.mem_used ?? 0) / (1024 * 1024)),
29
+ diskUsedMb: Math.round((last.disk_used ?? 0) / (1024 * 1024)),
30
+ networkRxKb: 0,
31
+ networkTxKb: 0,
32
+ commandCount: 0,
33
+ uptime: last.timestamp ?? "",
34
+ };
35
+ }
36
+ return {
37
+ cpuTimeMs: data.cpu_time_ms ?? 0,
38
+ memoryUsedMb: data.memory_used_mb ?? 0,
39
+ diskUsedMb: data.disk_used_mb ?? 0,
40
+ networkRxKb: data.network_rx_kb ?? 0,
41
+ networkTxKb: data.network_tx_kb ?? 0,
42
+ commandCount: data.command_count ?? 0,
43
+ uptime: String(data.uptime ?? ""),
44
+ };
45
+ }
46
+ /** Get raw metrics snapshots if the backend returns time-series data. */
47
+ async metricsSnapshots() {
48
+ const data = await this.client.get(`${this.baseUrl}/metrics`);
49
+ if (!Array.isArray(data))
50
+ return [];
51
+ return data.map((m) => ({
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
+ }));
60
+ }
61
+ /** Set network policy for the sandbox. */
62
+ async setNetworkPolicy(policy) {
63
+ await this.client.post(`${this.baseUrl}/network-policy`, {
64
+ allowDomains: policy.allowDomains,
65
+ denyDomains: policy.denyDomains,
66
+ allowIPs: policy.allowIPs,
67
+ denyIPs: policy.denyIPs,
68
+ });
69
+ }
70
+ }
package/dist/pty.d.ts ADDED
@@ -0,0 +1,26 @@
1
+ import type { HTTPClient } from "./client.js";
2
+ import type { PtyInfo } from "./models.js";
3
+ /** PTY namespace for terminal sessions in a sandbox. */
4
+ export declare class Pty {
5
+ private sandboxId;
6
+ private client;
7
+ constructor(sandboxId: string, client: HTTPClient);
8
+ private get baseUrl();
9
+ create(opts?: {
10
+ cols?: number;
11
+ rows?: number;
12
+ }): Promise<PtySession>;
13
+ list(): Promise<PtyInfo[]>;
14
+ }
15
+ /** Handle for a single PTY session. */
16
+ export declare class PtySession {
17
+ readonly pid: number;
18
+ private sandboxId;
19
+ private client;
20
+ constructor(pid: number, sandboxId: string, client: HTTPClient);
21
+ private get url();
22
+ sendStdin(data: string): Promise<void>;
23
+ resize(cols: number, rows: number): Promise<void>;
24
+ read(): Promise<string>;
25
+ kill(): Promise<void>;
26
+ }
package/dist/pty.js ADDED
@@ -0,0 +1,49 @@
1
+ /** PTY namespace for terminal sessions in a sandbox. */
2
+ export class Pty {
3
+ sandboxId;
4
+ client;
5
+ constructor(sandboxId, client) {
6
+ this.sandboxId = sandboxId;
7
+ this.client = client;
8
+ }
9
+ get baseUrl() {
10
+ return `/sandboxes/${this.sandboxId}/pty`;
11
+ }
12
+ async create(opts) {
13
+ const data = await this.client.post(this.baseUrl, {
14
+ cols: opts?.cols ?? 80,
15
+ rows: opts?.rows ?? 24,
16
+ });
17
+ return new PtySession(data.pid, this.sandboxId, this.client);
18
+ }
19
+ async list() {
20
+ return this.client.get(this.baseUrl);
21
+ }
22
+ }
23
+ /** Handle for a single PTY session. */
24
+ export class PtySession {
25
+ pid;
26
+ sandboxId;
27
+ client;
28
+ constructor(pid, sandboxId, client) {
29
+ this.pid = pid;
30
+ this.sandboxId = sandboxId;
31
+ this.client = client;
32
+ }
33
+ get url() {
34
+ return `/sandboxes/${this.sandboxId}/pty/${this.pid}`;
35
+ }
36
+ async sendStdin(data) {
37
+ await this.client.post(`${this.url}/input`, { data });
38
+ }
39
+ async resize(cols, rows) {
40
+ await this.client.post(`${this.url}/resize`, { cols, rows });
41
+ }
42
+ async read() {
43
+ const data = await this.client.get(`${this.url}/read`);
44
+ return data.data ?? "";
45
+ }
46
+ async kill() {
47
+ await this.client.delete(this.url);
48
+ }
49
+ }
@@ -0,0 +1,66 @@
1
+ import { Commands } from "./commands.js";
2
+ import { Contexts } from "./contexts.js";
3
+ import { type E2EESessionInfo } from "./e2ee.js";
4
+ import { Filesystem } from "./filesystem.js";
5
+ import type { CodeResult, CreateSandboxOptions, FullSandboxInfo, ListSandboxOptions, MetricsSnapshot, NetworkPolicy, SandboxInfo } from "./models.js";
6
+ import { Production } from "./production.js";
7
+ import { Pty } from "./pty.js";
8
+ import { Webhooks } from "./webhooks.js";
9
+ /** Cursor paginator for listing sandboxes via `x-next-token`. */
10
+ export declare class SandboxPaginator {
11
+ private client;
12
+ private limit;
13
+ private state?;
14
+ private metadata?;
15
+ private nextToken;
16
+ private _hasNext;
17
+ private firstCall;
18
+ constructor(opts?: ListSandboxOptions & {
19
+ limit?: number;
20
+ });
21
+ get hasNext(): boolean;
22
+ nextItems(): Promise<SandboxInfo[]>;
23
+ }
24
+ /** Top-level sandbox abstraction covering lifecycle and nested API namespaces. */
25
+ export declare class Sandbox {
26
+ readonly sandboxId: string;
27
+ readonly commands: Commands;
28
+ readonly files: Filesystem;
29
+ readonly pty: Pty;
30
+ readonly contexts: Contexts;
31
+ readonly production: Production;
32
+ readonly webhooks: Webhooks;
33
+ e2ee: E2EESessionInfo | null;
34
+ trafficAccessToken: string;
35
+ private client;
36
+ private keepAliveInterval;
37
+ private constructor();
38
+ static create(template?: string, opts?: CreateSandboxOptions): Promise<Sandbox>;
39
+ static connect(sandboxId: string, opts?: {
40
+ apiKey?: string;
41
+ apiUrl?: string;
42
+ requestTimeout?: number;
43
+ }): Promise<Sandbox>;
44
+ static list(opts?: ListSandboxOptions): Promise<SandboxInfo[]>;
45
+ static paginate(opts?: ListSandboxOptions): SandboxPaginator;
46
+ kill(): Promise<void>;
47
+ setTimeout(timeout: number): Promise<void>;
48
+ isRunning(): Promise<boolean>;
49
+ getInfo(): Promise<FullSandboxInfo>;
50
+ /** Execute code via the /code endpoint. */
51
+ runCode(code: string, language?: string): Promise<CodeResult>;
52
+ /** Get public URL for a port exposed inside the sandbox. */
53
+ getHost(port: number): string;
54
+ /** Get a pre-signed download URL for a file. */
55
+ downloadUrl(path: string): Promise<string>;
56
+ /** Get a pre-signed upload URL for a file. */
57
+ uploadUrl(path: string): Promise<string>;
58
+ pause(): Promise<{
59
+ status: string;
60
+ }>;
61
+ resume(): Promise<{
62
+ status: string;
63
+ }>;
64
+ getMetrics(): Promise<MetricsSnapshot[]>;
65
+ setNetworkPolicy(policy: NetworkPolicy): Promise<void>;
66
+ }
@@ -0,0 +1,275 @@
1
+ import { HTTPClient } from "./client.js";
2
+ import { Commands } from "./commands.js";
3
+ import { resolveConfig } from "./config.js";
4
+ import { Contexts } from "./contexts.js";
5
+ import { generateE2EEKeyPair, } from "./e2ee.js";
6
+ import { Filesystem } from "./filesystem.js";
7
+ import { Production } from "./production.js";
8
+ import { Pty } from "./pty.js";
9
+ import { makeCommandResult } from "./utils.js";
10
+ import { Webhooks } from "./webhooks.js";
11
+ function encodeMetadataFilter(metadata) {
12
+ if (!metadata)
13
+ return undefined;
14
+ const entries = Object.entries(metadata);
15
+ if (entries.length === 0)
16
+ return undefined;
17
+ const [key, value] = entries[0];
18
+ return `${key}:${value}`;
19
+ }
20
+ function parseSandboxInfo(s) {
21
+ return {
22
+ sandboxId: s.sandboxID,
23
+ templateId: s.templateID ?? s.templateId ?? "",
24
+ status: s.state ?? "running",
25
+ startedAt: s.startedAt ?? "",
26
+ endAt: s.endAt,
27
+ name: s.name ?? s.metadata?.name,
28
+ state: s.state,
29
+ cpuCount: s.cpuCount,
30
+ memoryMB: s.memoryMB,
31
+ };
32
+ }
33
+ function parseFullSandboxInfo(s) {
34
+ const base = parseSandboxInfo(s);
35
+ return {
36
+ ...base,
37
+ templateId: base.templateId || s.templateID || s.templateId || "",
38
+ state: s.state ?? base.state ?? "unknown",
39
+ cpuCount: s.cpuCount ?? base.cpuCount ?? 0,
40
+ memoryMB: s.memoryMB ?? base.memoryMB ?? 0,
41
+ };
42
+ }
43
+ function normalizeE2EEOptions(e2ee) {
44
+ if (!e2ee)
45
+ return null;
46
+ if (e2ee === true)
47
+ return { enabled: true };
48
+ if (typeof e2ee === "object" && (e2ee.enabled ?? true)) {
49
+ return { enabled: true, keyPair: e2ee.keyPair, clientPublicKey: e2ee.clientPublicKey };
50
+ }
51
+ return null;
52
+ }
53
+ /** Cursor paginator for listing sandboxes via `x-next-token`. */
54
+ export class SandboxPaginator {
55
+ client;
56
+ limit;
57
+ state;
58
+ metadata;
59
+ nextToken = null;
60
+ _hasNext = true;
61
+ firstCall = true;
62
+ constructor(opts) {
63
+ const config = resolveConfig(opts);
64
+ this.client = new HTTPClient(config);
65
+ this.limit = opts?.limit ?? 50;
66
+ this.state = opts?.state;
67
+ this.metadata = opts?.metadata;
68
+ }
69
+ get hasNext() {
70
+ return this._hasNext;
71
+ }
72
+ async nextItems() {
73
+ if (!this._hasNext && !this.firstCall)
74
+ return [];
75
+ this.firstCall = false;
76
+ const params = { limit: String(this.limit) };
77
+ if (this.nextToken)
78
+ params.next_token = this.nextToken;
79
+ if (this.state)
80
+ params.state = this.state;
81
+ const metadataFilter = encodeMetadataFilter(this.metadata);
82
+ if (metadataFilter)
83
+ params.metadata = metadataFilter;
84
+ const { data, headers } = await this.client.getWithHeaders("/sandboxes", params);
85
+ const sandboxes = Array.isArray(data) ? data : [];
86
+ const token = headers.get("x-next-token") || "";
87
+ this.nextToken = token || null;
88
+ this._hasNext = !!this.nextToken;
89
+ return sandboxes.map(parseSandboxInfo);
90
+ }
91
+ }
92
+ /** Top-level sandbox abstraction covering lifecycle and nested API namespaces. */
93
+ export class Sandbox {
94
+ sandboxId;
95
+ commands;
96
+ files;
97
+ pty;
98
+ contexts;
99
+ production;
100
+ webhooks;
101
+ e2ee = null;
102
+ trafficAccessToken = "";
103
+ client;
104
+ keepAliveInterval = null;
105
+ constructor(sandboxId, client) {
106
+ this.sandboxId = sandboxId;
107
+ this.client = client;
108
+ this.commands = new Commands(sandboxId, client);
109
+ this.files = new Filesystem(sandboxId, client);
110
+ this.pty = new Pty(sandboxId, client);
111
+ this.contexts = new Contexts(sandboxId, client);
112
+ this.production = new Production(sandboxId, client);
113
+ this.webhooks = new Webhooks(client);
114
+ }
115
+ static async create(template = "python-3.11", opts) {
116
+ const config = resolveConfig({
117
+ apiUrl: opts?.apiUrl,
118
+ apiKey: opts?.apiKey,
119
+ requestTimeout: opts?.requestTimeout,
120
+ });
121
+ const client = new HTTPClient(config);
122
+ const body = {
123
+ template,
124
+ timeout: opts?.timeout ?? 300,
125
+ };
126
+ const e2eeOpts = normalizeE2EEOptions(opts?.e2ee);
127
+ let e2eeKeyPair;
128
+ let clientPublicKey;
129
+ if (e2eeOpts?.enabled) {
130
+ e2eeKeyPair = e2eeOpts.keyPair ?? (await generateE2EEKeyPair());
131
+ clientPublicKey = e2eeOpts.clientPublicKey ?? e2eeKeyPair.publicKeyBase64;
132
+ body.e2ee = true;
133
+ body.clientPublicKey = clientPublicKey;
134
+ }
135
+ if (opts?.internet)
136
+ body.internet = true;
137
+ if (opts?.envVars)
138
+ body.envVars = opts.envVars;
139
+ if (opts?.metadata)
140
+ body.metadata = opts.metadata;
141
+ if (opts?.autoPause)
142
+ body.autoPause = true;
143
+ if (opts?.network)
144
+ body.network = opts.network;
145
+ if (opts?.secure)
146
+ body.secure = true;
147
+ if (opts?.maskRequestHost)
148
+ body.maskRequestHost = opts.maskRequestHost;
149
+ const data = await client.post("/sandboxes", body);
150
+ const sandbox = new Sandbox(data.sandboxID, client);
151
+ sandbox.trafficAccessToken = data.trafficToken ?? "";
152
+ if (e2eeOpts?.enabled && clientPublicKey) {
153
+ sandbox.e2ee = {
154
+ enabled: true,
155
+ clientPublicKey,
156
+ clientKeyPair: e2eeKeyPair,
157
+ serverPublicKey: data.serverPublicKey ?? data.e2ee?.serverPublicKey,
158
+ };
159
+ }
160
+ if (opts?.keepAlive != null) {
161
+ const interval = opts.keepAlive;
162
+ const timeout = opts.timeout ?? 300;
163
+ sandbox.keepAliveInterval = setInterval(async () => {
164
+ try {
165
+ await sandbox.setTimeout(timeout);
166
+ }
167
+ catch {
168
+ // ignore errors during heartbeat
169
+ }
170
+ }, interval * 1000);
171
+ }
172
+ return sandbox;
173
+ }
174
+ static async connect(sandboxId, opts) {
175
+ const config = resolveConfig(opts);
176
+ const client = new HTTPClient(config);
177
+ await client.get(`/sandboxes/${sandboxId}`);
178
+ return new Sandbox(sandboxId, client);
179
+ }
180
+ static async list(opts) {
181
+ const config = resolveConfig(opts);
182
+ const client = new HTTPClient(config);
183
+ const params = {};
184
+ if (opts?.limit != null)
185
+ params.limit = String(opts.limit);
186
+ if (opts?.nextToken)
187
+ params.next_token = opts.nextToken;
188
+ if (opts?.state)
189
+ params.state = opts.state;
190
+ const metadataFilter = encodeMetadataFilter(opts?.metadata);
191
+ if (metadataFilter)
192
+ params.metadata = metadataFilter;
193
+ const data = await client.get("/sandboxes", Object.keys(params).length > 0 ? params : undefined);
194
+ const sandboxes = Array.isArray(data) ? data : [];
195
+ return sandboxes.map(parseSandboxInfo);
196
+ }
197
+ static paginate(opts) {
198
+ return new SandboxPaginator(opts);
199
+ }
200
+ async kill() {
201
+ if (this.keepAliveInterval) {
202
+ clearInterval(this.keepAliveInterval);
203
+ this.keepAliveInterval = null;
204
+ }
205
+ await this.client.delete(`/sandboxes/${this.sandboxId}`);
206
+ }
207
+ async setTimeout(timeout) {
208
+ await this.client.post(`/sandboxes/${this.sandboxId}/timeout`, { timeout });
209
+ }
210
+ async isRunning() {
211
+ try {
212
+ const data = await this.client.get(`/sandboxes/${this.sandboxId}`);
213
+ return data.state === "running";
214
+ }
215
+ catch {
216
+ return false;
217
+ }
218
+ }
219
+ async getInfo() {
220
+ const data = await this.client.get(`/sandboxes/${this.sandboxId}`);
221
+ return parseFullSandboxInfo(data);
222
+ }
223
+ /** Execute code via the /code endpoint. */
224
+ async runCode(code, language = "python") {
225
+ const data = await this.client.post(`/sandboxes/${this.sandboxId}/code`, { code, language });
226
+ return makeCommandResult(data);
227
+ }
228
+ /** Get public URL for a port exposed inside the sandbox. */
229
+ getHost(port) {
230
+ return `https://${this.sandboxId}-${port}.claudebox.io`;
231
+ }
232
+ /** Get a pre-signed download URL for a file. */
233
+ async downloadUrl(path) {
234
+ const data = await this.client.post(`/sandboxes/${this.sandboxId}/files/download-url`, { path });
235
+ let url = data.url ?? "";
236
+ if (url && !url.startsWith("http")) {
237
+ url = this.client.baseUrl.replace(/\/$/, "") + url;
238
+ }
239
+ return url;
240
+ }
241
+ /** Get a pre-signed upload URL for a file. */
242
+ async uploadUrl(path) {
243
+ const data = await this.client.post(`/sandboxes/${this.sandboxId}/files/upload-url`, { path });
244
+ let url = data.url ?? "";
245
+ if (url && !url.startsWith("http")) {
246
+ url = this.client.baseUrl.replace(/\/$/, "") + url;
247
+ }
248
+ return url;
249
+ }
250
+ // Convenience wrappers delegating to production namespace (e2b compat)
251
+ async pause() {
252
+ return this.production.pause();
253
+ }
254
+ async resume() {
255
+ return this.production.resume();
256
+ }
257
+ async getMetrics() {
258
+ const data = await this.client.get(`/sandboxes/${this.sandboxId}/metrics`);
259
+ if (Array.isArray(data)) {
260
+ return data.map((m) => ({
261
+ timestamp: m.timestamp ?? "",
262
+ cpuUsedPct: m.cpu_used_pct ?? 0,
263
+ cpuCount: m.cpu_count ?? 0,
264
+ memUsed: m.mem_used ?? 0,
265
+ memTotal: m.mem_total ?? 0,
266
+ diskUsed: m.disk_used ?? 0,
267
+ diskTotal: m.disk_total ?? 0,
268
+ }));
269
+ }
270
+ return [];
271
+ }
272
+ async setNetworkPolicy(policy) {
273
+ return this.production.setNetworkPolicy(policy);
274
+ }
275
+ }
@@ -0,0 +1,8 @@
1
+ import type { CommandResult } from "./models.js";
2
+ /** Create a CommandResult with an `output` getter alias for `stdout`. */
3
+ export declare function makeCommandResult(raw: {
4
+ stdout: string;
5
+ stderr: string;
6
+ exit_code?: number;
7
+ exitCode?: number;
8
+ }): CommandResult;
package/dist/utils.js ADDED
@@ -0,0 +1,11 @@
1
+ /** Create a CommandResult with an `output` getter alias for `stdout`. */
2
+ export function makeCommandResult(raw) {
3
+ return {
4
+ stdout: raw.stdout ?? "",
5
+ stderr: raw.stderr ?? "",
6
+ exitCode: raw.exit_code ?? raw.exitCode ?? -1,
7
+ get output() {
8
+ return this.stdout;
9
+ },
10
+ };
11
+ }
@@ -0,0 +1,16 @@
1
+ import type { HTTPClient } from "./client.js";
2
+ import type { FilesystemEvent } from "./models.js";
3
+ /** Pull-based file watch stream handle backed by server-sent events. */
4
+ export declare class WatchHandle {
5
+ private sandboxId;
6
+ private path;
7
+ private recursive;
8
+ private client;
9
+ private events;
10
+ private abortController;
11
+ private running;
12
+ constructor(sandboxId: string, path: string, recursive: boolean, client: HTTPClient);
13
+ private startPolling;
14
+ getNewEvents(): FilesystemEvent[];
15
+ stop(): void;
16
+ }
@@ -0,0 +1,45 @@
1
+ /** Pull-based file watch stream handle backed by server-sent events. */
2
+ export class WatchHandle {
3
+ sandboxId;
4
+ path;
5
+ recursive;
6
+ client;
7
+ events = [];
8
+ abortController;
9
+ running = true;
10
+ constructor(sandboxId, path, recursive, client) {
11
+ this.sandboxId = sandboxId;
12
+ this.path = path;
13
+ this.recursive = recursive;
14
+ this.client = client;
15
+ this.abortController = new AbortController();
16
+ this.startPolling();
17
+ }
18
+ async startPolling() {
19
+ const params = { path: this.path };
20
+ if (this.recursive)
21
+ params.recursive = "true";
22
+ try {
23
+ for await (const event of this.client.streamSSEWithSignal(`/sandboxes/${this.sandboxId}/files/watch`, params, this.abortController.signal)) {
24
+ if (!this.running)
25
+ break;
26
+ const fsEvent = event;
27
+ if (fsEvent.type) {
28
+ this.events.push(fsEvent);
29
+ }
30
+ }
31
+ }
32
+ catch {
33
+ // Stream closed
34
+ }
35
+ }
36
+ getNewEvents() {
37
+ const events = [...this.events];
38
+ this.events = [];
39
+ return events;
40
+ }
41
+ stop() {
42
+ this.running = false;
43
+ this.abortController.abort();
44
+ }
45
+ }
@@ -0,0 +1,15 @@
1
+ import type { HTTPClient } from "./client.js";
2
+ import type { WebhookInfo } from "./models.js";
3
+ /** Webhook management namespace for sandbox lifecycle events. */
4
+ export declare class Webhooks {
5
+ private client;
6
+ constructor(client: HTTPClient);
7
+ /** Register a new lifecycle webhook. */
8
+ register(url: string, events: string[]): Promise<{
9
+ id: string;
10
+ }>;
11
+ /** List all registered webhooks. */
12
+ list(): Promise<WebhookInfo[]>;
13
+ /** Delete a webhook by ID. */
14
+ delete(webhookId: string): Promise<void>;
15
+ }
@@ -0,0 +1,25 @@
1
+ /** Webhook management namespace for sandbox lifecycle events. */
2
+ export class Webhooks {
3
+ client;
4
+ constructor(client) {
5
+ this.client = client;
6
+ }
7
+ /** Register a new lifecycle webhook. */
8
+ async register(url, events) {
9
+ return this.client.post("/webhooks", { url, events });
10
+ }
11
+ /** List all registered webhooks. */
12
+ async list() {
13
+ const data = await this.client.get("/webhooks");
14
+ const webhooks = Array.isArray(data) ? data : [];
15
+ return webhooks.map((w) => ({
16
+ id: w.id ?? "",
17
+ url: w.url ?? "",
18
+ events: Array.isArray(w.events) ? w.events : [],
19
+ }));
20
+ }
21
+ /** Delete a webhook by ID. */
22
+ async delete(webhookId) {
23
+ await this.client.delete(`/webhooks/${webhookId}`);
24
+ }
25
+ }