@insforge/instabox-sdk 0.2.2 → 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.
package/dist/index.d.ts CHANGED
@@ -339,7 +339,8 @@ declare class Files {
339
339
  format?: 'text';
340
340
  }): Promise<string>;
341
341
  read(path: string, opts: {
342
- format: 'bytes';
342
+ format: 'bytes'; /** @internal */
343
+ maxBytes?: number;
343
344
  }): Promise<Uint8Array>;
344
345
  /**
345
346
  * Writes a file, creating parent directories. Replaces the file atomically (temp file + rename).
@@ -354,6 +355,92 @@ declare class Files {
354
355
  exists(path: string): Promise<boolean>;
355
356
  }
356
357
 
358
+ type MouseButton = 'left' | 'right' | 'middle';
359
+ type ScrollDirection = 'up' | 'down' | 'left' | 'right';
360
+ interface DesktopStatus {
361
+ /** The desktop's packages are installed (templates other than `agent-browser` install them on first `start`). */
362
+ installed: boolean;
363
+ /** Its VNC server runs: the desktop can be seen, screenshotted and controlled. */
364
+ running: boolean;
365
+ /** Screen size in pixels while running. */
366
+ width?: number;
367
+ height?: number;
368
+ }
369
+ interface DesktopStream {
370
+ /** A page that shows the desktop full-screen; open it or embed it in an iframe. No sign-in needed. */
371
+ url: string;
372
+ expiresAt: Date;
373
+ }
374
+ /** X display the sandbox's desktop runs on. */
375
+ declare const DESKTOP_DISPLAY = ":1";
376
+ declare class Desktop {
377
+ private readonly http;
378
+ private readonly sandboxId;
379
+ private readonly commands;
380
+ private readonly files;
381
+ /** @internal */
382
+ constructor(http: HttpClient, sandboxId: string, commands: Commands, files: Files);
383
+ /**
384
+ * Starts the desktop and resolves once it runs; a running desktop is left as it is (its size too).
385
+ * On a template without the desktop it is installed first (about half a minute, once). `width` and
386
+ * `height` size the screen: 800-2560 x 600-1600, default 1280 x 800.
387
+ */
388
+ start(opts?: {
389
+ width?: number;
390
+ height?: number;
391
+ }): Promise<DesktopStatus>;
392
+ /** Whether the desktop runs, and its screen size. */
393
+ status(): Promise<DesktopStatus>;
394
+ /** A PNG of the whole screen. */
395
+ screenshot(): Promise<Uint8Array>;
396
+ /** Clicks at (x, y): the left button by default; `double` clicks twice. */
397
+ click(x: number, y: number, opts?: {
398
+ button?: MouseButton;
399
+ double?: boolean;
400
+ }): Promise<void>;
401
+ /** Moves the pointer to (x, y). */
402
+ move(x: number, y: number): Promise<void>;
403
+ /** Drags with the left button from `from` to `to`, each `[x, y]`. */
404
+ drag(from: [number, number], to: [number, number]): Promise<void>;
405
+ /** Scrolls the wheel at the pointer, `amount` notches (default 3). */
406
+ scroll(opts: {
407
+ direction: ScrollDirection;
408
+ amount?: number;
409
+ }): Promise<void>;
410
+ /** Types `text` as is (quotes, newlines and Unicode included) into the focused window. */
411
+ type(text: string, opts?: {
412
+ delayMs?: number;
413
+ }): Promise<void>;
414
+ /** Presses a key (`'Enter'`, `'a'`, `'F5'`) or a chord (`['ctrl', 'l']`). */
415
+ press(keys: string | string[]): Promise<void>;
416
+ /** Opens `url` (http or https) in the desktop's browser. */
417
+ open(url: string): Promise<void>;
418
+ /** Where the pointer is. */
419
+ cursorPosition(): Promise<{
420
+ x: number;
421
+ y: number;
422
+ }>;
423
+ /**
424
+ * A link that shows the desktop full-screen in a browser, for people without an instabox account:
425
+ * open it or embed it in an iframe. View-only by default (the server drops the viewer's input).
426
+ * `ttlSeconds`: 60 to 86 400, default 3 600. The expiry stops new connections only; a viewer already
427
+ * watching stays until they leave or `revokeStreamUrls()` is called.
428
+ */
429
+ streamUrl(opts?: {
430
+ viewOnly?: boolean;
431
+ ttlSeconds?: number;
432
+ }): Promise<DesktopStream>;
433
+ /**
434
+ * Revokes every link `streamUrl()` made for this sandbox: they stop working and open viewers are
435
+ * disconnected within a few seconds. Links made afterwards work.
436
+ */
437
+ revokeStreamUrls(): Promise<void>;
438
+ private call;
439
+ /** Runs `xdotool <args>` on the desktop's display. */
440
+ private xdo;
441
+ private run;
442
+ }
443
+
357
444
  declare const DEFAULT_TEMPLATE = "agent-browser";
358
445
  /** The default when a server does not offer `DEFAULT_TEMPLATE` (an older or self-hosted one). */
359
446
  declare const FALLBACK_TEMPLATE = "universal";
@@ -480,6 +567,8 @@ declare class Sandbox {
480
567
  readonly commands: Commands;
481
568
  /** Read and write files. Needs a instabox server with the exec endpoint. */
482
569
  readonly files: Files;
570
+ /** See and control the sandbox's graphical desktop (screenshots, mouse, keyboard, a link to watch it). */
571
+ readonly desktop: Desktop;
483
572
  private machine;
484
573
  private constructor();
485
574
  /**
@@ -581,4 +670,4 @@ declare class Sandbox {
581
670
  private mutate;
582
671
  }
583
672
 
584
- export { type ApiError, CommandExitError, type CommandHandle, type CommandOptions, type CommandResult, Commands, type Connection, type ConnectionOptions, type CreateSnapshotOpts, DEFAULT_API_URL, DEFAULT_TEMPLATE, type EntryInfo, type ExecResponse, FALLBACK_TEMPLATE, Files, type ForkOpts, type HostTrust, InstaboxAuthError, InstaboxError, type InstaboxErrorInit, InstaboxQuotaError, InstaboxTimeoutError, MAX_FILE_BYTES, MAX_STDIN_BYTES, type Machine, type MachineList, type MachineSpec, type MachineState, type MachineVault, type MachineVaultItem, type OnTimeout, type Operation, Sandbox, type SandboxConnectOpts, type SandboxInfo, type SandboxListOpts, type SandboxOpts, type Snapshot, type SnapshotList, type SshCredentials, type Template, type TemplateRef, type VaultApplied, type VaultFile, type VaultKept, type WriteInfo };
673
+ export { type ApiError, CommandExitError, type CommandHandle, type CommandOptions, type CommandResult, Commands, type Connection, type ConnectionOptions, type CreateSnapshotOpts, DEFAULT_API_URL, DEFAULT_TEMPLATE, DESKTOP_DISPLAY, Desktop, type DesktopStatus, type DesktopStream, type EntryInfo, type ExecResponse, FALLBACK_TEMPLATE, Files, type ForkOpts, type HostTrust, InstaboxAuthError, InstaboxError, type InstaboxErrorInit, InstaboxQuotaError, InstaboxTimeoutError, MAX_FILE_BYTES, MAX_STDIN_BYTES, type Machine, type MachineList, type MachineSpec, type MachineState, type MachineVault, type MachineVaultItem, type MouseButton, type OnTimeout, type Operation, Sandbox, type SandboxConnectOpts, type SandboxInfo, type SandboxListOpts, type SandboxOpts, type ScrollDirection, type Snapshot, type SnapshotList, type SshCredentials, type Template, type TemplateRef, type VaultApplied, type VaultFile, type VaultKept, type WriteInfo };
package/dist/index.js CHANGED
@@ -173,6 +173,261 @@ var Commands = class {
173
173
  }
174
174
  };
175
175
 
176
+ // src/desktop.ts
177
+ var DESKTOP_DISPLAY = ":1";
178
+ var BUTTONS = { left: 1, middle: 2, right: 3 };
179
+ var WHEEL = { up: 4, down: 5, left: 6, right: 7 };
180
+ var KEYS = {
181
+ enter: "Return",
182
+ return: "Return",
183
+ esc: "Escape",
184
+ escape: "Escape",
185
+ tab: "Tab",
186
+ space: "space",
187
+ backspace: "BackSpace",
188
+ delete: "Delete",
189
+ del: "Delete",
190
+ insert: "Insert",
191
+ home: "Home",
192
+ end: "End",
193
+ pageup: "Prior",
194
+ pagedown: "Next",
195
+ up: "Up",
196
+ down: "Down",
197
+ left: "Left",
198
+ right: "Right",
199
+ ctrl: "ctrl",
200
+ control: "ctrl",
201
+ alt: "alt",
202
+ shift: "shift",
203
+ meta: "super",
204
+ cmd: "super",
205
+ command: "super",
206
+ super: "super",
207
+ win: "super",
208
+ "+": "plus"
209
+ };
210
+ var enc = encodeURIComponent;
211
+ function keysym(key) {
212
+ if (typeof key !== "string" || !key || /\s/.test(key)) {
213
+ throw new InstaboxError(`invalid key ${JSON.stringify(key)}`, { code: "bad_request" });
214
+ }
215
+ const lower = key.toLowerCase();
216
+ if (KEYS[lower]) return KEYS[lower];
217
+ if (/^f([1-9]|1[0-9]|2[0-4])$/.test(lower)) return lower.toUpperCase();
218
+ return key;
219
+ }
220
+ function coord(name, v) {
221
+ if (!Number.isInteger(v) || v < 0 || v > 16384) {
222
+ throw new InstaboxError(`${name} must be a whole number of pixels from 0; got ${v}`, { code: "bad_request" });
223
+ }
224
+ return v;
225
+ }
226
+ var SCREENSHOT_MAX_BYTES = 32 * 1024 * 1024;
227
+ var Desktop = class {
228
+ /** @internal */
229
+ constructor(http, sandboxId, commands, files) {
230
+ this.http = http;
231
+ this.sandboxId = sandboxId;
232
+ this.commands = commands;
233
+ this.files = files;
234
+ }
235
+ http;
236
+ sandboxId;
237
+ commands;
238
+ files;
239
+ /**
240
+ * Starts the desktop and resolves once it runs; a running desktop is left as it is (its size too).
241
+ * On a template without the desktop it is installed first (about half a minute, once). `width` and
242
+ * `height` size the screen: 800-2560 x 600-1600, default 1280 x 800.
243
+ */
244
+ async start(opts = {}) {
245
+ const size = {};
246
+ for (const [k, lo, hi] of [
247
+ ["width", 800, 2560],
248
+ ["height", 600, 1600]
249
+ ]) {
250
+ const v = opts[k];
251
+ if (v === void 0) continue;
252
+ if (!Number.isInteger(v) || v < lo || v > hi) {
253
+ throw new InstaboxError(`${k} must be a whole number from ${lo} to ${hi}; got ${v}`, { code: "bad_request" });
254
+ }
255
+ size[k] = v;
256
+ }
257
+ let s = await this.call({ action: "start", ...size });
258
+ if (!s.installed) {
259
+ if (!s.installing) s = await this.call({ action: "install" });
260
+ const deadline = Date.now() + this.http.operationTimeoutMs;
261
+ while (!s.installed) {
262
+ if (s.failed) {
263
+ throw new InstaboxError(
264
+ `the desktop could not be installed: ${s.log ?? "see /tmp/instabox-desktop-install.log"}`,
265
+ {
266
+ code: "desktop_install_failed"
267
+ }
268
+ );
269
+ }
270
+ if (Date.now() > deadline) {
271
+ throw new InstaboxTimeoutError(`the desktop was not installed within ${this.http.operationTimeoutMs} ms`, {
272
+ code: "operation_timeout"
273
+ });
274
+ }
275
+ await sleep(this.http.pollIntervalMs * 8);
276
+ s = await this.call({ action: "status" });
277
+ }
278
+ s = await this.call({ action: "start", ...size });
279
+ }
280
+ if (!s.running) throw new InstaboxError("the desktop did not start", { code: "desktop_not_running" });
281
+ return this.status();
282
+ }
283
+ /** Whether the desktop runs, and its screen size. */
284
+ async status() {
285
+ const s = await this.call({ action: "status" });
286
+ const out = { installed: s.installed, running: s.running };
287
+ if (s.running) {
288
+ const [w, h] = (await this.xdo("getdisplaygeometry")).stdout.trim().split(/\s+/).map(Number);
289
+ if (Number.isInteger(w) && Number.isInteger(h)) Object.assign(out, { width: w, height: h });
290
+ }
291
+ return out;
292
+ }
293
+ /** A PNG of the whole screen. */
294
+ async screenshot() {
295
+ const path = `/tmp/instabox-screenshot-${randomSuffix()}.png`;
296
+ const p = shellQuote(path);
297
+ try {
298
+ await this.run(
299
+ `if command -v scrot >/dev/null; then scrot -o ${p}; elif command -v import >/dev/null; then import -window root png:${p}; else echo 'no screenshot tool in the sandbox (scrot or ImageMagick import)' >&2; exit 127; fi`
300
+ );
301
+ return await this.files.read(path, { format: "bytes", maxBytes: SCREENSHOT_MAX_BYTES });
302
+ } finally {
303
+ await this.commands.exec(`rm -f ${p}`).catch(() => {
304
+ });
305
+ }
306
+ }
307
+ /** Clicks at (x, y): the left button by default; `double` clicks twice. */
308
+ async click(x, y, opts = {}) {
309
+ const button = BUTTONS[opts.button ?? "left"];
310
+ if (!button)
311
+ throw new InstaboxError(`button must be left, right or middle; got ${opts.button}`, { code: "bad_request" });
312
+ const repeat = opts.double ? " --repeat 2 --delay 80" : "";
313
+ await this.xdo(`mousemove ${coord("x", x)} ${coord("y", y)} click${repeat} ${button}`);
314
+ }
315
+ /** Moves the pointer to (x, y). */
316
+ async move(x, y) {
317
+ await this.xdo(`mousemove ${coord("x", x)} ${coord("y", y)}`);
318
+ }
319
+ /** Drags with the left button from `from` to `to`, each `[x, y]`. */
320
+ async drag(from, to) {
321
+ await this.xdo(
322
+ `mousemove ${coord("x", from[0])} ${coord("y", from[1])} mousedown 1 sleep 0.1 mousemove ${coord("x", to[0])} ${coord("y", to[1])} sleep 0.1 mouseup 1`
323
+ );
324
+ }
325
+ /** Scrolls the wheel at the pointer, `amount` notches (default 3). */
326
+ async scroll(opts) {
327
+ const wheel = WHEEL[opts.direction];
328
+ const n = opts.amount ?? 3;
329
+ if (!wheel)
330
+ throw new InstaboxError(`direction must be up, down, left or right; got ${opts.direction}`, {
331
+ code: "bad_request"
332
+ });
333
+ if (!Number.isInteger(n) || n < 1 || n > 100) {
334
+ throw new InstaboxError(`amount must be a whole number from 1 to 100; got ${n}`, { code: "bad_request" });
335
+ }
336
+ await this.xdo(`click --repeat ${n} --delay 30 ${wheel}`);
337
+ }
338
+ /** Types `text` as is (quotes, newlines and Unicode included) into the focused window. */
339
+ async type(text, opts = {}) {
340
+ if (typeof text !== "string") throw new InstaboxError("text must be a string", { code: "bad_request" });
341
+ if (!text) return;
342
+ const delay = opts.delayMs ?? 12;
343
+ if (!Number.isInteger(delay) || delay < 0 || delay > 1e3) {
344
+ throw new InstaboxError(`delayMs must be a whole number from 0 to 1000; got ${delay}`, { code: "bad_request" });
345
+ }
346
+ await this.xdo(`type --delay ${delay} --file -`, text);
347
+ }
348
+ /** Presses a key (`'Enter'`, `'a'`, `'F5'`) or a chord (`['ctrl', 'l']`). */
349
+ async press(keys) {
350
+ const list = Array.isArray(keys) ? keys : [keys];
351
+ if (!list.length) throw new InstaboxError("press needs a key", { code: "bad_request" });
352
+ await this.xdo(`key -- ${shellQuote(list.map(keysym).join("+"))}`);
353
+ }
354
+ /** Opens `url` (http or https) in the desktop's browser. */
355
+ async open(url) {
356
+ let u;
357
+ try {
358
+ u = new URL(url);
359
+ } catch {
360
+ throw new InstaboxError(`invalid URL: ${url}`, { code: "bad_request" });
361
+ }
362
+ if (u.protocol !== "http:" && u.protocol !== "https:") {
363
+ throw new InstaboxError(`only http and https URLs open in the browser; got ${u.protocol}`, {
364
+ code: "bad_request"
365
+ });
366
+ }
367
+ await this.run(
368
+ `b=$(command -v chromium || command -v chromium-browser || command -v google-chrome) || { echo 'no browser in the sandbox' >&2; exit 127; }; setsid nohup "$b" --no-first-run --no-default-browser-check --password-store=basic ${shellQuote(u.href)} >/dev/null 2>&1 </dev/null &`
369
+ );
370
+ }
371
+ /** Where the pointer is. */
372
+ async cursorPosition() {
373
+ const out = (await this.xdo("getmouselocation --shell")).stdout;
374
+ const x = Number(/^X=(\d+)/m.exec(out)?.[1]);
375
+ const y = Number(/^Y=(\d+)/m.exec(out)?.[1]);
376
+ if (!Number.isInteger(x) || !Number.isInteger(y)) {
377
+ throw new InstaboxError("could not read the pointer position", { code: "invalid_response" });
378
+ }
379
+ return { x, y };
380
+ }
381
+ /**
382
+ * A link that shows the desktop full-screen in a browser, for people without an instabox account:
383
+ * open it or embed it in an iframe. View-only by default (the server drops the viewer's input).
384
+ * `ttlSeconds`: 60 to 86 400, default 3 600. The expiry stops new connections only; a viewer already
385
+ * watching stays until they leave or `revokeStreamUrls()` is called.
386
+ */
387
+ async streamUrl(opts = {}) {
388
+ const body = { viewOnly: opts.viewOnly ?? true };
389
+ if (opts.ttlSeconds !== void 0) {
390
+ if (!Number.isInteger(opts.ttlSeconds) || opts.ttlSeconds < 60 || opts.ttlSeconds > 86400) {
391
+ throw new InstaboxError(`ttlSeconds must be a whole number from 60 to 86 400; got ${opts.ttlSeconds}`, {
392
+ code: "bad_request"
393
+ });
394
+ }
395
+ body.ttlSeconds = opts.ttlSeconds;
396
+ }
397
+ const r = await this.http.request(
398
+ "POST",
399
+ `/v1/machines/${enc(this.sandboxId)}/desktop/stream`,
400
+ { body }
401
+ );
402
+ return { url: r.url, expiresAt: new Date(r.expiresAt) };
403
+ }
404
+ /**
405
+ * Revokes every link `streamUrl()` made for this sandbox: they stop working and open viewers are
406
+ * disconnected within a few seconds. Links made afterwards work.
407
+ */
408
+ async revokeStreamUrls() {
409
+ await this.http.request("DELETE", `/v1/machines/${enc(this.sandboxId)}/desktop/stream`);
410
+ }
411
+ call(body) {
412
+ return this.http.request("POST", `/v1/machines/${enc(this.sandboxId)}/desktop`, {
413
+ body,
414
+ timeoutMs: 9e4
415
+ });
416
+ }
417
+ /** Runs `xdotool <args>` on the desktop's display. */
418
+ xdo(args, stdin) {
419
+ return this.run(`xdotool ${args}`, stdin);
420
+ }
421
+ async run(cmd, stdin) {
422
+ const r = await this.commands.exec(
423
+ `export DISPLAY=${DESKTOP_DISPLAY}; ${cmd}`,
424
+ stdin === void 0 ? {} : { stdin }
425
+ );
426
+ if (r.exitCode !== 0) throw new CommandExitError(r);
427
+ return r;
428
+ }
429
+ };
430
+
176
431
  // src/files.ts
177
432
  var MAX_FILE_BYTES = 10 * 1024 * 1024;
178
433
  var WRITE_CHUNK_B64 = 48 * 1024;
@@ -185,18 +440,19 @@ var Files = class {
185
440
  commands;
186
441
  async read(path, opts = {}) {
187
442
  const p = arg(path);
443
+ const limit = opts.maxBytes ?? MAX_FILE_BYTES;
188
444
  const r = await this.commands.exec(
189
- `[ -f ${p} ] || { echo "no such file: "${p} >&2; exit 3; }; s=$(wc -c < ${p}) || exit 1; [ "$s" -le ${MAX_FILE_BYTES} ] || { echo "file too large: $s bytes" >&2; exit 4; }; printf '%s' "$s"`
445
+ `[ -f ${p} ] || { echo "no such file: "${p} >&2; exit 3; }; s=$(wc -c < ${p}) || exit 1; [ "$s" -le ${limit} ] || { echo "file too large: $s bytes" >&2; exit 4; }; printf '%s' "$s"`
190
446
  );
191
447
  if (r.exitCode === 3) throw new InstaboxError(`file not found: ${path}`, { status: 404, code: "not_found" });
192
448
  if (r.exitCode === 4) {
193
- throw new InstaboxError(`${path} is larger than the ${MAX_FILE_BYTES}-byte limit of files.read`, {
449
+ throw new InstaboxError(`${path} is larger than the ${limit}-byte limit of files.read`, {
194
450
  code: "file_too_large"
195
451
  });
196
452
  }
197
453
  ensureComplete(r);
198
454
  const size = Number(r.stdout.trim());
199
- if (!Number.isSafeInteger(size) || size < 0 || size > MAX_FILE_BYTES) {
455
+ if (!Number.isSafeInteger(size) || size < 0 || size > limit) {
200
456
  throw new InstaboxError("invalid file size returned by exec", { code: "invalid_response" });
201
457
  }
202
458
  const bytes = new Uint8Array(size);
@@ -465,7 +721,7 @@ function toSeconds(ms, field = "timeoutMs") {
465
721
  return s;
466
722
  }
467
723
  var METADATA_KEY = /^[A-Za-z0-9_.-]{1,64}$/;
468
- var enc = encodeURIComponent;
724
+ var enc2 = encodeURIComponent;
469
725
  var Sandbox = class _Sandbox {
470
726
  constructor(http, machine, opts = {}) {
471
727
  this.http = http;
@@ -473,6 +729,7 @@ var Sandbox = class _Sandbox {
473
729
  this.machine = machine;
474
730
  this.commands = new Commands(http, machine.id, { ...opts.envs });
475
731
  this.files = new Files(this.commands);
732
+ this.desktop = new Desktop(http, machine.id, this.commands, this.files);
476
733
  }
477
734
  http;
478
735
  /** The machine ID (`m_...`). */
@@ -481,6 +738,8 @@ var Sandbox = class _Sandbox {
481
738
  commands;
482
739
  /** Read and write files. Needs a instabox server with the exec endpoint. */
483
740
  files;
741
+ /** See and control the sandbox's graphical desktop (screenshots, mouse, keyboard, a link to watch it). */
742
+ desktop;
484
743
  machine;
485
744
  static async create(a, b) {
486
745
  const opts = (typeof a === "string" ? b : a) ?? {};
@@ -541,12 +800,12 @@ var Sandbox = class _Sandbox {
541
800
  }
542
801
  /** Fetches a snapshot by ID. Requires images:read. */
543
802
  static async getSnapshot(snapshotId, opts = {}) {
544
- return new HttpClient(opts).request("GET", `/v1/snapshots/${enc(snapshotId)}`);
803
+ return new HttpClient(opts).request("GET", `/v1/snapshots/${enc2(snapshotId)}`);
545
804
  }
546
805
  /** Deletes a snapshot. Returns false if absent. Requires images:delete. */
547
806
  static async deleteSnapshot(snapshotId, opts = {}) {
548
807
  try {
549
- await new HttpClient(opts).request("DELETE", `/v1/snapshots/${enc(snapshotId)}`);
808
+ await new HttpClient(opts).request("DELETE", `/v1/snapshots/${enc2(snapshotId)}`);
550
809
  return true;
551
810
  } catch (err) {
552
811
  if (err instanceof InstaboxError && err.status === 404 && err.code === "not_found") return false;
@@ -561,7 +820,7 @@ var Sandbox = class _Sandbox {
561
820
  async createSnapshot(opts) {
562
821
  await this.settle();
563
822
  await this.untilSynced();
564
- return this.http.request("POST", `/v1/machines/${enc(this.sandboxId)}/snapshots`, { body: opts });
823
+ return this.http.request("POST", `/v1/machines/${enc2(this.sandboxId)}/snapshots`, { body: opts });
565
824
  }
566
825
  /** Fetches the current state of the sandbox. */
567
826
  async getInfo() {
@@ -575,20 +834,20 @@ var Sandbox = class _Sandbox {
575
834
  async setTimeout(timeoutMs, opts = {}) {
576
835
  const body = { timeoutSeconds: timeoutMs === 0 ? 0 : toSeconds(timeoutMs) };
577
836
  if (opts.onTimeout) body.onTimeout = opts.onTimeout;
578
- this.machine = await this.http.request("PATCH", `/v1/machines/${enc(this.sandboxId)}`, { body });
837
+ this.machine = await this.http.request("PATCH", `/v1/machines/${enc2(this.sandboxId)}`, { body });
579
838
  }
580
839
  /**
581
840
  * Pauses the sandbox once it has been idle `idleMs` (whole seconds, 2 min to 24 h); 0 turns the idle
582
841
  * pause off. Unlike a timeout the setting stays across pause and resume.
583
842
  */
584
843
  async setAutoSuspend(idleMs) {
585
- this.machine = await this.http.request("PATCH", `/v1/machines/${enc(this.sandboxId)}`, {
844
+ this.machine = await this.http.request("PATCH", `/v1/machines/${enc2(this.sandboxId)}`, {
586
845
  body: { autoSuspendAfterSeconds: toIdleSeconds(idleMs) }
587
846
  });
588
847
  }
589
848
  /** Replaces the sandbox's metadata (`{}` clears it). */
590
849
  async setMetadata(metadata) {
591
- this.machine = await this.http.request("PATCH", `/v1/machines/${enc(this.sandboxId)}`, {
850
+ this.machine = await this.http.request("PATCH", `/v1/machines/${enc2(this.sandboxId)}`, {
592
851
  body: { metadata }
593
852
  });
594
853
  }
@@ -598,21 +857,21 @@ var Sandbox = class _Sandbox {
598
857
  * Throws `not_found` on a server without the Vault.
599
858
  */
600
859
  async vault() {
601
- return this.http.request("GET", `/v1/machines/${enc(this.sandboxId)}/vault`);
860
+ return this.http.request("GET", `/v1/machines/${enc2(this.sandboxId)}/vault`);
602
861
  }
603
862
  /**
604
863
  * Writes the account's current Vault items into the running sandbox now, the same write as after a boot,
605
864
  * and returns its record (`error` set when the guest refused it). Requires machines:write.
606
865
  */
607
866
  async pushVault() {
608
- return this.http.request("POST", `/v1/machines/${enc(this.sandboxId)}/vault`);
867
+ return this.http.request("POST", `/v1/machines/${enc2(this.sandboxId)}/vault`);
609
868
  }
610
869
  /**
611
870
  * Turns the Vault off for this sandbox, for good, in any state: its next boot, resume or push removes
612
871
  * what the Vault wrote and nothing is written again. Requires machines:write.
613
872
  */
614
873
  async disableVault() {
615
- this.machine = await this.http.request("PATCH", `/v1/machines/${enc(this.sandboxId)}`, {
874
+ this.machine = await this.http.request("PATCH", `/v1/machines/${enc2(this.sandboxId)}`, {
616
875
  body: { vault: false }
617
876
  });
618
877
  }
@@ -664,7 +923,7 @@ var Sandbox = class _Sandbox {
664
923
  if (opts.autoSuspendMs !== void 0) body.autoSuspendAfterSeconds = toIdleSeconds(opts.autoSuspendMs);
665
924
  if (opts.metadata) body.metadata = opts.metadata;
666
925
  if (opts.vault === false) body.vault = false;
667
- const op = await this.http.request("POST", `/v1/machines/${enc(this.sandboxId)}/fork`, { body });
926
+ const op = await this.http.request("POST", `/v1/machines/${enc2(this.sandboxId)}/fork`, { body });
668
927
  const done = await this.http.waitForOperation(op);
669
928
  return new _Sandbox(this.http, await getMachine(this.http, done.machineId));
670
929
  }
@@ -687,7 +946,7 @@ var Sandbox = class _Sandbox {
687
946
  }
688
947
  body.ttlSeconds = opts.ttlSeconds;
689
948
  }
690
- const c = await this.http.request("POST", `/v1/machines/${enc(this.sandboxId)}/connections`, { body });
949
+ const c = await this.http.request("POST", `/v1/machines/${enc2(this.sandboxId)}/connections`, { body });
691
950
  return {
692
951
  host: c.host,
693
952
  port: c.port,
@@ -706,7 +965,7 @@ var Sandbox = class _Sandbox {
706
965
  async settle(refresh = true) {
707
966
  if (refresh) this.machine = await getMachine(this.http, this.sandboxId);
708
967
  if (this.machine.operationId) {
709
- const op = await this.http.request("GET", `/v1/operations/${enc(this.machine.operationId)}`);
968
+ const op = await this.http.request("GET", `/v1/operations/${enc2(this.machine.operationId)}`);
710
969
  await this.http.waitForOperation(op).catch(() => {
711
970
  });
712
971
  this.machine = await getMachine(this.http, this.sandboxId);
@@ -734,17 +993,17 @@ var Sandbox = class _Sandbox {
734
993
  }
735
994
  }
736
995
  async mutate(method, action) {
737
- const op = await this.http.request(method, `/v1/machines/${enc(this.sandboxId)}/${action}`);
996
+ const op = await this.http.request(method, `/v1/machines/${enc2(this.sandboxId)}/${action}`);
738
997
  await this.http.waitForOperation(op);
739
998
  this.machine = await getMachine(this.http, this.sandboxId);
740
999
  }
741
1000
  };
742
1001
  async function getMachine(http, id) {
743
- return http.request("GET", `/v1/machines/${enc(id)}`);
1002
+ return http.request("GET", `/v1/machines/${enc2(id)}`);
744
1003
  }
745
1004
  async function killMachine(http, id) {
746
1005
  try {
747
- const op = await http.request("DELETE", `/v1/machines/${enc(id)}`);
1006
+ const op = await http.request("DELETE", `/v1/machines/${enc2(id)}`);
748
1007
  await http.waitForOperation(op);
749
1008
  return true;
750
1009
  } catch (err) {
@@ -793,6 +1052,8 @@ export {
793
1052
  Commands,
794
1053
  DEFAULT_API_URL,
795
1054
  DEFAULT_TEMPLATE,
1055
+ DESKTOP_DISPLAY,
1056
+ Desktop,
796
1057
  FALLBACK_TEMPLATE,
797
1058
  Files,
798
1059
  InstaboxAuthError,