@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/dist/sandbox.d.ts CHANGED
@@ -2,8 +2,9 @@ import { Commands } from "./commands.js";
2
2
  import { Contexts } from "./contexts.js";
3
3
  import { type E2EESessionInfo } from "./e2ee.js";
4
4
  import { Filesystem } from "./filesystem.js";
5
+ import { Desktop } from "./desktop.js";
5
6
  import { Exposures } from "./exposures.js";
6
- 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";
7
8
  import { Production } from "./production.js";
8
9
  import { Pty } from "./pty.js";
9
10
  import { Webhooks } from "./webhooks.js";
@@ -25,32 +26,137 @@ export declare class SandboxPaginator {
25
26
  /** Top-level sandbox abstraction covering lifecycle and nested API namespaces. */
26
27
  export declare class Sandbox {
27
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;
28
34
  readonly commands: Commands;
29
35
  readonly files: Filesystem;
30
36
  readonly pty: Pty;
31
37
  readonly contexts: Contexts;
38
+ readonly desktop: Desktop;
32
39
  readonly exposures: Exposures;
33
40
  readonly production: Production;
34
41
  readonly webhooks: Webhooks;
35
42
  e2ee: E2EESessionInfo | null;
36
43
  trafficAccessToken: string;
37
44
  private client;
45
+ private previewDomain;
38
46
  private keepAliveInterval;
39
47
  private constructor();
48
+ /**
49
+ * Create a new sandbox from a template.
50
+ *
51
+ * @param template - Template identifier (e.g. `"python-3.11"`, `"node-20"`). Defaults to `"python-3.11"`.
52
+ * @param opts - Creation options.
53
+ * @param opts.timeout - Sandbox timeout in seconds. Default `300`. Use `0` for a permanent sandbox.
54
+ * @param opts.apiKey - API key. Falls back to `OMNIRUN_API_KEY` env var.
55
+ * @param opts.apiUrl - API base URL. Falls back to `OMNIRUN_API_URL` env var.
56
+ * @param opts.internet - Enable outbound internet access.
57
+ * @param opts.envVars - Environment variables injected into the sandbox.
58
+ * @param opts.metadata - Arbitrary key-value metadata attached to the sandbox.
59
+ * @param opts.secure - Enable E2E encrypted mode.
60
+ * @param opts.maskRequestHost - Mask the request host header.
61
+ * @param opts.autoPause - Auto-pause the sandbox after inactivity.
62
+ * @param opts.keepAlive - Heartbeat interval in seconds to prevent auto-kill.
63
+ * @param opts.network - Network policy (allow/deny domains and IPs).
64
+ * @param opts.e2ee - E2EE bootstrap options or `true` for defaults.
65
+ * @param opts.vaultInject - Inject vault credentials as env vars via `/tmp/.omnirun-env`.
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.
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 })`.
77
+ */
40
78
  static create(template?: string, opts?: CreateSandboxOptions): Promise<Sandbox>;
41
- static connect(sandboxId: string, opts?: {
42
- apiKey?: string;
43
- apiUrl?: string;
44
- requestTimeout?: number;
79
+ static create(opts: CreateSandboxOptions & {
80
+ template?: string;
81
+ }): Promise<Sandbox>;
82
+ /**
83
+ * Connect to an existing, already-running sandbox by its ID.
84
+ *
85
+ * Use this instead of {@link create} when you already have a sandbox ID
86
+ * (e.g. from a previous session, webhook payload, or database record).
87
+ *
88
+ * @param sandboxId - The unique sandbox identifier.
89
+ * @param opts - Connection options (apiKey, apiUrl, requestTimeout).
90
+ * @returns A connected {@link Sandbox} instance.
91
+ * @throws {SandboxNotFoundError} If the sandbox does not exist or has been killed.
92
+ */
93
+ static connect(sandboxId: string, opts?: ConnectOptions & {
94
+ previewDomain?: string;
45
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[]>;
105
+ /**
106
+ * List sandboxes for the authenticated account.
107
+ *
108
+ * @param opts - Filter and pagination options (limit, nextToken, state, metadata).
109
+ * @returns An array of {@link SandboxInfo} objects.
110
+ */
46
111
  static list(opts?: ListSandboxOptions): Promise<SandboxInfo[]>;
112
+ /**
113
+ * Return a cursor-based paginator for listing sandboxes.
114
+ *
115
+ * Call {@link SandboxPaginator.nextItems} repeatedly until
116
+ * {@link SandboxPaginator.hasNext} is `false` to iterate through all pages.
117
+ *
118
+ * @param opts - Filter and pagination options.
119
+ * @returns A {@link SandboxPaginator} instance.
120
+ */
47
121
  static paginate(opts?: ListSandboxOptions): SandboxPaginator;
122
+ /**
123
+ * Permanently destroy the sandbox. This is irreversible — the sandbox
124
+ * cannot be resumed or reconnected after being killed.
125
+ * Also clears any active keep-alive heartbeat.
126
+ */
48
127
  kill(): Promise<void>;
49
- setTimeout(timeout: number): Promise<void>;
128
+ /**
129
+ * Reset the sandbox auto-kill timer.
130
+ *
131
+ * @param timeout - New timeout value in seconds. The sandbox will be killed
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).
135
+ */
136
+ setTimeout(timeout: number): Promise<number>;
137
+ /**
138
+ * Check whether the sandbox is currently in the `"running"` state.
139
+ *
140
+ * Makes a GET request to the sandbox info endpoint. Returns `false` if the
141
+ * sandbox does not exist, has been killed, or is in any non-running state.
142
+ */
50
143
  isRunning(): Promise<boolean>;
144
+ /**
145
+ * Retrieve detailed information about the sandbox.
146
+ *
147
+ * @returns A {@link FullSandboxInfo} object containing state, CPU count,
148
+ * memory, template ID, and timestamps.
149
+ */
51
150
  getInfo(): Promise<FullSandboxInfo>;
52
- /** Execute code via the /code endpoint. */
53
- runCode(code: string, language?: string): Promise<CodeResult>;
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>;
54
160
  /** Get public URL for a port exposed inside the sandbox. */
55
161
  getHost(port: number): string;
56
162
  /** Create a managed preview URL for a sandbox port. */
@@ -59,9 +165,18 @@ export declare class Sandbox {
59
165
  downloadUrl(path: string): Promise<string>;
60
166
  /** Get a pre-signed upload URL for a file. */
61
167
  uploadUrl(path: string): Promise<string>;
168
+ /**
169
+ * Pause the sandbox VM. A paused sandbox retains its state on disk and can
170
+ * be resumed later with {@link resume}. Use this for production sandboxes
171
+ * that need to survive periods of inactivity without being killed.
172
+ */
62
173
  pause(): Promise<{
63
174
  status: string;
64
175
  }>;
176
+ /**
177
+ * Resume a previously paused sandbox. The VM is restored from its
178
+ * saved state and continues running where it left off.
179
+ */
65
180
  resume(): Promise<{
66
181
  status: string;
67
182
  }>;
package/dist/sandbox.js CHANGED
@@ -2,21 +2,34 @@ import { HTTPClient } from "./client.js";
2
2
  import { Commands } from "./commands.js";
3
3
  import { resolveConfig } from "./config.js";
4
4
  import { Contexts } from "./contexts.js";
5
- import { generateE2EEKeyPair, } from "./e2ee.js";
5
+ import { deriveE2EESharedKey, generateE2EEKeyPair, } from "./e2ee.js";
6
6
  import { Filesystem } from "./filesystem.js";
7
+ import { Desktop } from "./desktop.js";
8
+ import { SandboxError, SandboxNotFoundError } from "./errors.js";
7
9
  import { Exposures } from "./exposures.js";
8
- import { Production } from "./production.js";
10
+ import { parseMetricsSnapshot, Production } from "./production.js";
9
11
  import { Pty } from "./pty.js";
10
12
  import { makeCommandResult } from "./utils.js";
11
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
+ }
12
26
  function encodeMetadataFilter(metadata) {
13
27
  if (!metadata)
14
28
  return undefined;
15
29
  const entries = Object.entries(metadata);
16
30
  if (entries.length === 0)
17
31
  return undefined;
18
- const [key, value] = entries[0];
19
- return `${key}:${value}`;
32
+ return entries.map(([key, value]) => `${key}:${value}`).join(",");
20
33
  }
21
34
  function parseSandboxInfo(s) {
22
35
  return {
@@ -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,33 +107,50 @@ 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;
99
118
  contexts;
119
+ desktop;
100
120
  exposures;
101
121
  production;
102
122
  webhooks;
103
123
  e2ee = null;
104
124
  trafficAccessToken = "";
105
125
  client;
126
+ previewDomain;
106
127
  keepAliveInterval = null;
107
- constructor(sandboxId, client) {
128
+ constructor(sandboxId, client, previewDomain, region) {
108
129
  this.sandboxId = sandboxId;
130
+ this.region = region || undefined;
109
131
  this.client = client;
132
+ this.previewDomain = previewDomain
133
+ || (typeof process !== "undefined" ? process.env.OMNIRUN_PREVIEW_DOMAIN : undefined)
134
+ || DEFAULT_PREVIEW_DOMAIN;
110
135
  this.commands = new Commands(sandboxId, client);
111
136
  this.files = new Filesystem(sandboxId, client);
112
137
  this.pty = new Pty(sandboxId, client);
113
138
  this.contexts = new Contexts(sandboxId, client);
139
+ this.desktop = new Desktop(sandboxId, client);
114
140
  this.exposures = new Exposures(sandboxId, client);
115
141
  this.production = new Production(sandboxId, client);
116
142
  this.webhooks = new Webhooks(client);
117
143
  }
118
- 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";
119
149
  const config = resolveConfig({
120
150
  apiUrl: opts?.apiUrl,
121
151
  apiKey: opts?.apiKey,
122
152
  requestTimeout: opts?.requestTimeout,
153
+ retry: opts?.retry,
123
154
  });
124
155
  const client = new HTTPClient(config);
125
156
  const body = {
@@ -135,8 +166,12 @@ export class Sandbox {
135
166
  body.e2ee = true;
136
167
  body.clientPublicKey = clientPublicKey;
137
168
  }
169
+ if (opts?.region)
170
+ body.region = opts.region;
138
171
  if (opts?.internet)
139
172
  body.internet = true;
173
+ if (opts?.memory != null)
174
+ body.memoryMB = opts.memory;
140
175
  if (opts?.envVars)
141
176
  body.envVars = opts.envVars;
142
177
  if (opts?.metadata)
@@ -149,8 +184,10 @@ export class Sandbox {
149
184
  body.secure = true;
150
185
  if (opts?.maskRequestHost)
151
186
  body.maskRequestHost = opts.maskRequestHost;
152
- const data = await client.post("/sandboxes", body);
153
- const sandbox = new Sandbox(data.sandboxID, client);
187
+ if (opts?.vaultInject)
188
+ body.vaultInject = true;
189
+ const data = await client.post("/sandboxes", body, { retry: "refusal" });
190
+ const sandbox = new Sandbox(data.sandboxID, client, opts?.previewDomain, data.region);
154
191
  sandbox.trafficAccessToken = data.trafficToken ?? "";
155
192
  if (e2eeOpts?.enabled && clientPublicKey) {
156
193
  sandbox.e2ee = {
@@ -160,6 +197,10 @@ export class Sandbox {
160
197
  serverPublicKey: data.serverPublicKey ?? data.e2ee?.serverPublicKey,
161
198
  };
162
199
  }
200
+ if (sandbox.e2ee?.enabled && sandbox.e2ee.clientKeyPair && sandbox.e2ee.serverPublicKey) {
201
+ const sharedKey = await deriveE2EESharedKey(sandbox.e2ee.clientKeyPair.privateKey, sandbox.e2ee.serverPublicKey);
202
+ client.setE2EEKey(sharedKey);
203
+ }
163
204
  if (opts?.keepAlive != null) {
164
205
  const interval = opts.keepAlive;
165
206
  const timeout = opts.timeout ?? 300;
@@ -174,12 +215,53 @@ export class Sandbox {
174
215
  }
175
216
  return sandbox;
176
217
  }
218
+ /**
219
+ * Connect to an existing, already-running sandbox by its ID.
220
+ *
221
+ * Use this instead of {@link create} when you already have a sandbox ID
222
+ * (e.g. from a previous session, webhook payload, or database record).
223
+ *
224
+ * @param sandboxId - The unique sandbox identifier.
225
+ * @param opts - Connection options (apiKey, apiUrl, requestTimeout).
226
+ * @returns A connected {@link Sandbox} instance.
227
+ * @throws {SandboxNotFoundError} If the sandbox does not exist or has been killed.
228
+ */
177
229
  static async connect(sandboxId, opts) {
178
230
  const config = resolveConfig(opts);
179
231
  const client = new HTTPClient(config);
180
- await client.get(`/sandboxes/${sandboxId}`);
181
- return new Sandbox(sandboxId, client);
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
+ }));
182
258
  }
259
+ /**
260
+ * List sandboxes for the authenticated account.
261
+ *
262
+ * @param opts - Filter and pagination options (limit, nextToken, state, metadata).
263
+ * @returns An array of {@link SandboxInfo} objects.
264
+ */
183
265
  static async list(opts) {
184
266
  const config = resolveConfig(opts);
185
267
  const client = new HTTPClient(config);
@@ -197,9 +279,23 @@ export class Sandbox {
197
279
  const sandboxes = Array.isArray(data) ? data : [];
198
280
  return sandboxes.map(parseSandboxInfo);
199
281
  }
282
+ /**
283
+ * Return a cursor-based paginator for listing sandboxes.
284
+ *
285
+ * Call {@link SandboxPaginator.nextItems} repeatedly until
286
+ * {@link SandboxPaginator.hasNext} is `false` to iterate through all pages.
287
+ *
288
+ * @param opts - Filter and pagination options.
289
+ * @returns A {@link SandboxPaginator} instance.
290
+ */
200
291
  static paginate(opts) {
201
292
  return new SandboxPaginator(opts);
202
293
  }
294
+ /**
295
+ * Permanently destroy the sandbox. This is irreversible — the sandbox
296
+ * cannot be resumed or reconnected after being killed.
297
+ * Also clears any active keep-alive heartbeat.
298
+ */
203
299
  async kill() {
204
300
  if (this.keepAliveInterval) {
205
301
  clearInterval(this.keepAliveInterval);
@@ -207,9 +303,24 @@ export class Sandbox {
207
303
  }
208
304
  await this.client.delete(`/sandboxes/${this.sandboxId}`);
209
305
  }
306
+ /**
307
+ * Reset the sandbox auto-kill timer.
308
+ *
309
+ * @param timeout - New timeout value in seconds. The sandbox will be killed
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).
313
+ */
210
314
  async setTimeout(timeout) {
211
- 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;
212
317
  }
318
+ /**
319
+ * Check whether the sandbox is currently in the `"running"` state.
320
+ *
321
+ * Makes a GET request to the sandbox info endpoint. Returns `false` if the
322
+ * sandbox does not exist, has been killed, or is in any non-running state.
323
+ */
213
324
  async isRunning() {
214
325
  try {
215
326
  const data = await this.client.get(`/sandboxes/${this.sandboxId}`);
@@ -219,18 +330,35 @@ export class Sandbox {
219
330
  return false;
220
331
  }
221
332
  }
333
+ /**
334
+ * Retrieve detailed information about the sandbox.
335
+ *
336
+ * @returns A {@link FullSandboxInfo} object containing state, CPU count,
337
+ * memory, template ID, and timestamps.
338
+ */
222
339
  async getInfo() {
223
- const data = await this.client.get(`/sandboxes/${this.sandboxId}`);
340
+ let data;
341
+ try {
342
+ data = await this.client.get(`/sandboxes/${this.sandboxId}`);
343
+ }
344
+ catch (err) {
345
+ rethrowNotFound(err, this.sandboxId);
346
+ }
224
347
  return parseFullSandboxInfo(data);
225
348
  }
226
- /** Execute code via the /code endpoint. */
227
- async runCode(code, language = "python") {
228
- const data = await this.client.post(`/sandboxes/${this.sandboxId}/code`, { code, language });
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 });
229
357
  return makeCommandResult(data);
230
358
  }
231
359
  /** Get public URL for a port exposed inside the sandbox. */
232
360
  getHost(port) {
233
- return `https://${this.sandboxId}-${port}.claudebox.io`;
361
+ return `https://${this.sandboxId}-${port}.${this.previewDomain}`;
234
362
  }
235
363
  /** Create a managed preview URL for a sandbox port. */
236
364
  async expose(port, opts) {
@@ -238,7 +366,7 @@ export class Sandbox {
238
366
  }
239
367
  /** Get a pre-signed download URL for a file. */
240
368
  async downloadUrl(path) {
241
- 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" });
242
370
  let url = data.url ?? "";
243
371
  if (url && !url.startsWith("http")) {
244
372
  url = this.client.baseUrl.replace(/\/$/, "") + url;
@@ -247,7 +375,7 @@ export class Sandbox {
247
375
  }
248
376
  /** Get a pre-signed upload URL for a file. */
249
377
  async uploadUrl(path) {
250
- 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" });
251
379
  let url = data.url ?? "";
252
380
  if (url && !url.startsWith("http")) {
253
381
  url = this.client.baseUrl.replace(/\/$/, "") + url;
@@ -255,24 +383,25 @@ export class Sandbox {
255
383
  return url;
256
384
  }
257
385
  // Convenience wrappers delegating to production namespace (e2b compat)
386
+ /**
387
+ * Pause the sandbox VM. A paused sandbox retains its state on disk and can
388
+ * be resumed later with {@link resume}. Use this for production sandboxes
389
+ * that need to survive periods of inactivity without being killed.
390
+ */
258
391
  async pause() {
259
392
  return this.production.pause();
260
393
  }
394
+ /**
395
+ * Resume a previously paused sandbox. The VM is restored from its
396
+ * saved state and continues running where it left off.
397
+ */
261
398
  async resume() {
262
399
  return this.production.resume();
263
400
  }
264
401
  async getMetrics() {
265
402
  const data = await this.client.get(`/sandboxes/${this.sandboxId}/metrics`);
266
403
  if (Array.isArray(data)) {
267
- return data.map((m) => ({
268
- timestamp: m.timestamp ?? "",
269
- cpuUsedPct: m.cpu_used_pct ?? 0,
270
- cpuCount: m.cpu_count ?? 0,
271
- memUsed: m.mem_used ?? 0,
272
- memTotal: m.mem_total ?? 0,
273
- diskUsed: m.disk_used ?? 0,
274
- diskTotal: m.disk_total ?? 0,
275
- }));
404
+ return data.map(parseMetricsSnapshot);
276
405
  }
277
406
  return [];
278
407
  }
@@ -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
- /** Register a new lifecycle webhook. */
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
- /** Register a new lifecycle webhook. */
8
- async register(url, events) {
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.5.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": ">=18"
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": "^2.29.7",
59
- "@types/node": "^24.0.0",
60
- "typescript": "^5.9.3",
61
- "vitest": "^3.2.4"
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
  }