@boxfab/desktop 0.0.1-placeholder.1 → 0.1.0-alpha.2

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.js ADDED
@@ -0,0 +1,557 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let boxfab = require("boxfab");
3
+ let crypto = require("crypto");
4
+ // src/utils.ts
5
+ function generateRandomString(length = 16) {
6
+ const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
7
+ let result = "";
8
+ for (let i = 0; i < length; i++) result += characters[(0, crypto.randomInt)(62)];
9
+ return result;
10
+ }
11
+ // \0@oxc-project+runtime@0.156.0/helpers/esm/typeof.js
12
+ function _typeof(o) {
13
+ "@babel/helpers - typeof";
14
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
15
+ return typeof o;
16
+ } : function(o) {
17
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
18
+ }, _typeof(o);
19
+ }
20
+ // \0@oxc-project+runtime@0.156.0/helpers/esm/toPrimitive.js
21
+ function toPrimitive(t, r) {
22
+ if ("object" != _typeof(t) || !t) return t;
23
+ var e = t[Symbol.toPrimitive];
24
+ if (void 0 !== e) {
25
+ var i = e.call(t, r || "default");
26
+ if ("object" != _typeof(i)) return i;
27
+ throw new TypeError("@@toPrimitive must return a primitive value.");
28
+ }
29
+ return ("string" === r ? String : Number)(t);
30
+ }
31
+ // \0@oxc-project+runtime@0.156.0/helpers/esm/toPropertyKey.js
32
+ function toPropertyKey(t) {
33
+ var i = toPrimitive(t, "string");
34
+ return "symbol" == _typeof(i) ? i : i + "";
35
+ }
36
+ // \0@oxc-project+runtime@0.156.0/helpers/esm/defineProperty.js
37
+ function _defineProperty(e, r, t) {
38
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
39
+ value: t,
40
+ enumerable: !0,
41
+ configurable: !0,
42
+ writable: !0
43
+ }) : e[r] = t, e;
44
+ }
45
+ // \0@oxc-project+runtime@0.156.0/helpers/esm/objectSpread2.js
46
+ function ownKeys(e, r) {
47
+ var t = Object.keys(e);
48
+ if (Object.getOwnPropertySymbols) {
49
+ var o = Object.getOwnPropertySymbols(e);
50
+ r && (o = o.filter(function(r) {
51
+ return Object.getOwnPropertyDescriptor(e, r).enumerable;
52
+ })), t.push.apply(t, o);
53
+ }
54
+ return t;
55
+ }
56
+ function _objectSpread2(e) {
57
+ for (var r = 1; r < arguments.length; r++) {
58
+ var t = null != arguments[r] ? arguments[r] : {};
59
+ r % 2 ? ownKeys(Object(t), !0).forEach(function(r) {
60
+ _defineProperty(e, r, t[r]);
61
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r) {
62
+ Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
63
+ });
64
+ }
65
+ return e;
66
+ }
67
+ // src/sandbox.ts
68
+ const MOUSE_BUTTONS = {
69
+ left: 1,
70
+ right: 3,
71
+ middle: 2
72
+ };
73
+ const KEYS = {
74
+ alt: "Alt_L",
75
+ alt_left: "Alt_L",
76
+ alt_right: "Alt_R",
77
+ backspace: "BackSpace",
78
+ break: "Pause",
79
+ caps_lock: "Caps_Lock",
80
+ cmd: "Super_L",
81
+ command: "Super_L",
82
+ control: "Control_L",
83
+ control_left: "Control_L",
84
+ control_right: "Control_R",
85
+ ctrl: "Control_L",
86
+ del: "Delete",
87
+ delete: "Delete",
88
+ down: "Down",
89
+ end: "End",
90
+ enter: "Return",
91
+ esc: "Escape",
92
+ escape: "Escape",
93
+ f1: "F1",
94
+ f2: "F2",
95
+ f3: "F3",
96
+ f4: "F4",
97
+ f5: "F5",
98
+ f6: "F6",
99
+ f7: "F7",
100
+ f8: "F8",
101
+ f9: "F9",
102
+ f10: "F10",
103
+ f11: "F11",
104
+ f12: "F12",
105
+ home: "Home",
106
+ insert: "Insert",
107
+ left: "Left",
108
+ menu: "Menu",
109
+ meta: "Meta_L",
110
+ num_lock: "Num_Lock",
111
+ page_down: "Page_Down",
112
+ page_up: "Page_Up",
113
+ pause: "Pause",
114
+ print: "Print",
115
+ right: "Right",
116
+ scroll_lock: "Scroll_Lock",
117
+ shift: "Shift_L",
118
+ shift_left: "Shift_L",
119
+ shift_right: "Shift_R",
120
+ space: "space",
121
+ super: "Super_L",
122
+ super_left: "Super_L",
123
+ super_right: "Super_R",
124
+ tab: "Tab",
125
+ up: "Up",
126
+ win: "Super_L",
127
+ windows: "Super_L"
128
+ };
129
+ function mapKey(key) {
130
+ const lowerKey = key.toLowerCase();
131
+ if (lowerKey in KEYS) return KEYS[lowerKey];
132
+ return lowerKey;
133
+ }
134
+ var Sandbox = class extends boxfab.Sandbox {
135
+ /**
136
+ * Use {@link Sandbox.create} to create a new Sandbox instead.
137
+ *
138
+ * @hidden
139
+ * @hide
140
+ * @internal
141
+ * @access protected
142
+ */
143
+ constructor(opts) {
144
+ super(opts);
145
+ _defineProperty(this, "display", ":0");
146
+ _defineProperty(this, "stream", new VNCServer(this));
147
+ _defineProperty(this, "lastXfce4Pid", null);
148
+ }
149
+ static async create(templateOrOpts, opts) {
150
+ const { template, sandboxOpts } = typeof templateOrOpts === "string" ? {
151
+ template: templateOrOpts,
152
+ sandboxOpts: opts
153
+ } : {
154
+ template: this.defaultTemplate,
155
+ sandboxOpts: templateOrOpts
156
+ };
157
+ const display = (opts === null || opts === void 0 ? void 0 : opts.display) || ":0";
158
+ const sandboxOptsWithDisplay = _objectSpread2(_objectSpread2({}, sandboxOpts), {}, { envs: _objectSpread2(_objectSpread2({}, sandboxOpts === null || sandboxOpts === void 0 ? void 0 : sandboxOpts.envs), {}, { DISPLAY: display }) });
159
+ const sbx = await super.create(template, sandboxOptsWithDisplay);
160
+ try {
161
+ await sbx._start(display, sandboxOptsWithDisplay);
162
+ } catch (error) {
163
+ await sbx.kill().catch(() => {});
164
+ throw error;
165
+ }
166
+ return sbx;
167
+ }
168
+ /**
169
+ * Wait for a command to return a specific result.
170
+ * @param cmd - The command to run.
171
+ * @param onResult - The function to check the result of the command.
172
+ * @param timeout - The maximum time to wait for the command to return the result.
173
+ * @param interval - The interval to wait between checks.
174
+ * @returns `true` if the command returned the result within the timeout, otherwise `false`.
175
+ */
176
+ async waitAndVerify(cmd, onResult, timeout = 10, interval = .5) {
177
+ let elapsed = 0;
178
+ while (elapsed < timeout) {
179
+ try {
180
+ if (onResult(await this.commands.run(cmd))) return true;
181
+ } catch (e) {
182
+ if (!(e instanceof boxfab.CommandExitError)) throw e;
183
+ }
184
+ await new Promise((resolve) => setTimeout(resolve, interval * 1e3));
185
+ elapsed += interval;
186
+ }
187
+ return false;
188
+ }
189
+ async screenshot(format = "bytes") {
190
+ const path = `/tmp/screenshot-${generateRandomString()}.png`;
191
+ await this.commands.run(`scrot --pointer ${path}`);
192
+ const file = await this.files.read(path, { format });
193
+ this.files.remove(path).catch(() => {});
194
+ return file;
195
+ }
196
+ /**
197
+ * Left click on the mouse position.
198
+ */
199
+ async leftClick(x, y) {
200
+ if (x && y) await this.moveMouse(x, y);
201
+ await this.commands.run("xdotool click 1");
202
+ }
203
+ /**
204
+ * Double left click on the mouse position.
205
+ */
206
+ async doubleClick(x, y) {
207
+ if (x && y) await this.moveMouse(x, y);
208
+ await this.commands.run("xdotool click --repeat 2 1");
209
+ }
210
+ /**
211
+ * Right click on the mouse position.
212
+ */
213
+ async rightClick(x, y) {
214
+ if (x && y) await this.moveMouse(x, y);
215
+ await this.commands.run("xdotool click 3");
216
+ }
217
+ /**
218
+ * Middle click on the mouse position.
219
+ */
220
+ async middleClick(x, y) {
221
+ if (x && y) await this.moveMouse(x, y);
222
+ await this.commands.run("xdotool click 2");
223
+ }
224
+ /**
225
+ * Scroll the mouse wheel by the given amount.
226
+ * @param direction - The direction to scroll. Can be "up" or "down".
227
+ * @param amount - The amount to scroll.
228
+ */
229
+ async scroll(direction = "down", amount = 1) {
230
+ const button = direction === "up" ? "4" : "5";
231
+ await this.commands.run(`xdotool click --repeat ${amount} ${button}`);
232
+ }
233
+ /**
234
+ * Move the mouse to the given coordinates.
235
+ * @param x - The x coordinate.
236
+ * @param y - The y coordinate.
237
+ */
238
+ async moveMouse(x, y) {
239
+ await this.commands.run(`xdotool mousemove --sync ${x} ${y}`);
240
+ }
241
+ /**
242
+ * Press the mouse button.
243
+ */
244
+ async mousePress(button = "left") {
245
+ await this.commands.run(`xdotool mousedown ${MOUSE_BUTTONS[button]}`);
246
+ }
247
+ /**
248
+ * Release the mouse button.
249
+ */
250
+ async mouseRelease(button = "left") {
251
+ await this.commands.run(`xdotool mouseup ${MOUSE_BUTTONS[button]}`);
252
+ }
253
+ /**
254
+ * Get the current cursor position.
255
+ * @returns A object with the x and y coordinates
256
+ * @throws Error if cursor position cannot be determined
257
+ */
258
+ async getCursorPosition() {
259
+ const result = await this.commands.run("xdotool getmouselocation");
260
+ const match = result.stdout.match(/x:(\d+)\s+y:(\d+)/);
261
+ if (!match) throw new Error(`Failed to parse cursor position from output: ${result.stdout}`);
262
+ const [, x, y] = match;
263
+ if (!x || !y) throw new Error(`Invalid cursor position values: x=${x}, y=${y}`);
264
+ return {
265
+ x: parseInt(x),
266
+ y: parseInt(y)
267
+ };
268
+ }
269
+ /**
270
+ * Get the current screen size.
271
+ * @returns An {@link ScreenSize} object
272
+ * @throws Error if screen size cannot be determined
273
+ */
274
+ async getScreenSize() {
275
+ const result = await this.commands.run("xrandr");
276
+ const match = result.stdout.match(/(\d+x\d+)/);
277
+ if (!match) throw new Error(`Failed to parse screen size from output: ${result.stdout}`);
278
+ try {
279
+ const [width, height] = match[1].split("x").map((val) => parseInt(val));
280
+ return {
281
+ width,
282
+ height
283
+ };
284
+ } catch (error) {
285
+ throw new Error(`Invalid screen size format: ${match[1]}`);
286
+ }
287
+ }
288
+ /**
289
+ * Write the given text at the current cursor position.
290
+ * @param text - The text to write.
291
+ * @param options - An object containing the chunk size and delay between each chunk of text.
292
+ * @param options.chunkSize - The size of each chunk of text to write. Default is 25 characters.
293
+ * @param options.delayInMs - The delay between each chunk of text. Default is 75 ms.
294
+ */
295
+ async write(text, options = {
296
+ chunkSize: 25,
297
+ delayInMs: 75
298
+ }) {
299
+ const chunks = this.breakIntoChunks(text, options.chunkSize);
300
+ for (const chunk of chunks) await this.commands.run(`xdotool type --delay ${options.delayInMs} -- ${this.quoteString(chunk)}`);
301
+ }
302
+ /**
303
+ * Press a key.
304
+ * @param key - The key to press (e.g. "enter", "space", "backspace", etc.). Can be a single key or an array of keys.
305
+ */
306
+ async press(key) {
307
+ if (Array.isArray(key)) key = key.map(mapKey).join("+");
308
+ else key = mapKey(key);
309
+ await this.commands.run(`xdotool key ${key}`);
310
+ }
311
+ /**
312
+ * Drag the mouse from the given position to the given position.
313
+ * @param from - The starting position as `[x, y]`.
314
+ * @param to - The ending position as `[x, y]`.
315
+ */
316
+ async drag(from, to) {
317
+ await this.moveMouse(...from);
318
+ await this.mousePress();
319
+ await this.moveMouse(...to);
320
+ await this.mouseRelease();
321
+ }
322
+ /**
323
+ * Wait for the given amount of time.
324
+ * @param ms - The amount of time to wait in milliseconds.
325
+ */
326
+ async wait(ms) {
327
+ await this.commands.run(`sleep ${ms / 1e3}`);
328
+ }
329
+ /**
330
+ * Open a file or a URL in the default application.
331
+ * @param fileOrUrl - The file or URL to open.
332
+ */
333
+ async open(fileOrUrl) {
334
+ await (await this.commands.run(`xdg-open ${fileOrUrl}`, { background: true })).disconnect();
335
+ }
336
+ /**
337
+ * Get the current window ID.
338
+ * @returns The ID of the current window.
339
+ */
340
+ async getCurrentWindowId() {
341
+ return (await this.commands.run("xdotool getwindowfocus")).stdout.trim();
342
+ }
343
+ /**
344
+ * Get the window ID of the window with the given title.
345
+ * @param title - The title of the window.
346
+ * @returns The ID of the window.
347
+ */
348
+ async getApplicationWindows(application) {
349
+ return (await this.commands.run(`xdotool search --onlyvisible --class ${application}`)).stdout.trim().split("\n");
350
+ }
351
+ /**
352
+ * Get the title of the window with the given ID.
353
+ * @param windowId - The ID of the window.
354
+ * @returns The title of the window.
355
+ */
356
+ async getWindowTitle(windowId) {
357
+ return (await this.commands.run(`xdotool getwindowname ${windowId}`)).stdout.trim();
358
+ }
359
+ /**
360
+ * Launch an application.
361
+ * @param application - The application to launch.
362
+ * @param uri - The URI to open in the application.
363
+ */
364
+ async launch(application, uri) {
365
+ await (await this.commands.run(`gtk-launch ${application} ${uri !== null && uri !== void 0 ? uri : ""}`, {
366
+ background: true,
367
+ timeoutMs: 0
368
+ })).disconnect();
369
+ }
370
+ async _start(display, opts) {
371
+ var _opts$resolution, _opts$dpi;
372
+ this.display = display;
373
+ this.lastXfce4Pid = null;
374
+ this.stream = new VNCServer(this);
375
+ const [width, height] = (_opts$resolution = opts === null || opts === void 0 ? void 0 : opts.resolution) !== null && _opts$resolution !== void 0 ? _opts$resolution : [1024, 768];
376
+ await (await this.commands.run(`Xvfb ${display} -ac -screen 0 ${width}x${height}x24 -retro -dpi ${(_opts$dpi = opts === null || opts === void 0 ? void 0 : opts.dpi) !== null && _opts$dpi !== void 0 ? _opts$dpi : 96} -nolisten tcp -nolisten unix`, {
377
+ background: true,
378
+ timeoutMs: 0
379
+ })).disconnect();
380
+ if (!await this.waitAndVerify(`xdpyinfo -display ${display}`, (r) => r.exitCode === 0)) throw new boxfab.TimeoutError("Could not start Xvfb");
381
+ await this.startXfce4();
382
+ }
383
+ /**
384
+ * Start xfce4 session if logged out or not running.
385
+ */
386
+ async startXfce4() {
387
+ if (this.lastXfce4Pid === null || (await this.commands.run(`ps aux | grep ${this.lastXfce4Pid} | grep -v grep | head -n 1`)).stdout.trim().includes("[xfce4-session] <defunct>")) {
388
+ const result = await this.commands.run("startxfce4", {
389
+ background: true,
390
+ timeoutMs: 0
391
+ });
392
+ this.lastXfce4Pid = result.pid;
393
+ await result.disconnect();
394
+ }
395
+ if (!await this.waitAndVerify("pgrep -x xfce4-session >/dev/null && pgrep -x xfwm4 >/dev/null && pgrep -x xfdesktop >/dev/null", (r) => r.exitCode === 0, 60)) throw new boxfab.TimeoutError("Could not start XFCE");
396
+ }
397
+ *breakIntoChunks(text, n) {
398
+ for (let i = 0; i < text.length; i += n) yield text.slice(i, i + n);
399
+ }
400
+ quoteString(s) {
401
+ if (!s) return "''";
402
+ if (!/[^\w@%+=:,./-]/.test(s)) return s;
403
+ return "'" + s.replace(/'/g, "'\"'\"'") + "'";
404
+ }
405
+ };
406
+ _defineProperty(Sandbox, "defaultTemplate", "desktop");
407
+ var VNCServer = class {
408
+ constructor(desktop) {
409
+ _defineProperty(this, "vncPort", 5900);
410
+ _defineProperty(this, "port", 6080);
411
+ _defineProperty(this, "novncAuthEnabled", false);
412
+ _defineProperty(this, "url", null);
413
+ _defineProperty(this, "novncHandle", null);
414
+ _defineProperty(this, "password", void 0);
415
+ _defineProperty(this, "novncCommand", void 0);
416
+ _defineProperty(this, "desktop", void 0);
417
+ this.desktop = desktop;
418
+ this.novncCommand = `cd /opt/noVNC/utils && ./novnc_proxy --vnc localhost:${this.vncPort} --listen ${this.port} --web /opt/noVNC > /tmp/novnc.log 2>&1`;
419
+ }
420
+ getAuthKey() {
421
+ if (!this.password) throw new Error("Unable to retrieve stream auth key, check if requireAuth is enabled");
422
+ return this.password;
423
+ }
424
+ /**
425
+ * Get the URL to a web page with a stream of the desktop sandbox.
426
+ * @param autoConnect - Whether to automatically connect to the server after opening the URL.
427
+ * @param viewOnly - Whether to prevent user interaction through the client.
428
+ * @param resize - Whether to resize the view when the window resizes.
429
+ * @param authKey - The password to use to connect to the server.
430
+ * @returns The URL to connect to the VNC server.
431
+ */
432
+ getUrl({ autoConnect = true, viewOnly = false, resize = "scale", authKey } = {}) {
433
+ if (this.url === null) throw new Error("Server is not running");
434
+ const url = new URL(this.url);
435
+ if (autoConnect) url.searchParams.set("autoconnect", "true");
436
+ if (viewOnly) url.searchParams.set("view_only", "true");
437
+ if (resize) url.searchParams.set("resize", resize);
438
+ if (authKey) url.searchParams.set("password", authKey);
439
+ return url.toString();
440
+ }
441
+ /**
442
+ * Start the VNC server.
443
+ */
444
+ async start(opts = {}) {
445
+ var _opts$vncPort, _opts$port, _opts$requireAuth;
446
+ if (await this.checkVNCRunning()) throw new Error("Stream is already running");
447
+ this.vncPort = (_opts$vncPort = opts.vncPort) !== null && _opts$vncPort !== void 0 ? _opts$vncPort : this.vncPort;
448
+ this.port = (_opts$port = opts.port) !== null && _opts$port !== void 0 ? _opts$port : this.port;
449
+ this.novncAuthEnabled = (_opts$requireAuth = opts.requireAuth) !== null && _opts$requireAuth !== void 0 ? _opts$requireAuth : this.novncAuthEnabled;
450
+ this.password = this.novncAuthEnabled ? generateRandomString() : void 0;
451
+ this.url = new URL(`https://${this.desktop.getHost(this.port)}/vnc.html`);
452
+ const vncCommand = await this.getVNCCommand(opts.windowId);
453
+ await this.desktop.commands.run(vncCommand);
454
+ this.novncHandle = await this.desktop.commands.run(this.novncCommand, {
455
+ background: true,
456
+ timeoutMs: 0
457
+ });
458
+ if (!await this.waitForPort(this.port)) throw new Error("Could not start noVNC server");
459
+ }
460
+ /**
461
+ * Stop the VNC server.
462
+ */
463
+ async stop() {
464
+ if (await this.checkVNCRunning()) await this.desktop.commands.run("pkill x11vnc");
465
+ if (this.novncHandle) {
466
+ await this.novncHandle.kill();
467
+ this.novncHandle = null;
468
+ }
469
+ }
470
+ /**
471
+ * Set the VNC command to start the VNC server.
472
+ */
473
+ async getVNCCommand(windowId) {
474
+ let pwdFlag = "-nopw";
475
+ if (this.novncAuthEnabled) {
476
+ await this.desktop.commands.run("mkdir -p ~/.vnc");
477
+ await this.desktop.commands.run(`x11vnc -storepasswd ${this.password} ~/.vnc/passwd`);
478
+ pwdFlag = "-usepw";
479
+ }
480
+ return `x11vnc -bg -display ${this.desktop.display} -forever -wait 50 -shared -rfbport ${this.vncPort} ${pwdFlag} 2>/tmp/x11vnc_stderr.log` + (windowId ? ` -id ${windowId}` : "");
481
+ }
482
+ async waitForPort(port) {
483
+ return await this.desktop.waitAndVerify(`netstat -tuln | grep ":${port} "`, (r) => r.stdout.trim() !== "");
484
+ }
485
+ /**
486
+ * Check if the VNC server is running.
487
+ * @returns Whether the VNC server is running.
488
+ */
489
+ async checkVNCRunning() {
490
+ try {
491
+ return (await this.desktop.commands.run("pgrep -x x11vnc")).stdout.trim() !== "";
492
+ } catch (error) {
493
+ return false;
494
+ }
495
+ }
496
+ };
497
+ // src/client.ts
498
+ /**
499
+ * BoxFab client with an explicitly bound connection configuration.
500
+ *
501
+ * The resources exposed by the client ({@link BoxFab.Sandbox},
502
+ * {@link BoxFab.Volume}, {@link BoxFab.Template}, {@link BoxFab.Secret}) behave exactly
503
+ * like the top-level `Sandbox` / `Volume` / `Template` / `Secret` exports,
504
+ * except the options passed to the client are used as the defaults instead of
505
+ * the environment variables.
506
+ * Per-call options still take precedence over the client's options.
507
+ *
508
+ * Multiple clients are fully isolated from each other and from the top-level
509
+ * env-configured exports.
510
+ *
511
+ * @example
512
+ * ```ts
513
+ * import { BoxFab } from '@boxfab/desktop'
514
+ *
515
+ * const client = new BoxFab({ apiKey: 'e2b_...', domain: 'us-west.boxfab.dev' })
516
+ *
517
+ * const desktop = await client.Sandbox.create()
518
+ * await desktop.stream.start()
519
+ * ```
520
+ */
521
+ var BoxFab = class {
522
+ /**
523
+ * Create a new client with the connection options bound to it.
524
+ *
525
+ * @param opts connection options used as the defaults for every call made
526
+ * through this client's resource classes.
527
+ */
528
+ constructor(opts) {
529
+ var _Class;
530
+ _defineProperty(this, "Sandbox", void 0);
531
+ _defineProperty(this, "Volume", void 0);
532
+ _defineProperty(this, "Template", void 0);
533
+ _defineProperty(this, "Secret", void 0);
534
+ const boundOpts = _objectSpread2({}, opts !== null && opts !== void 0 ? opts : {});
535
+ delete boundOpts.signal;
536
+ if (boundOpts.headers) boundOpts.headers = _objectSpread2({}, boundOpts.headers);
537
+ if (boundOpts.apiHeaders) boundOpts.apiHeaders = _objectSpread2({}, boundOpts.apiHeaders);
538
+ this.Sandbox = (_Class = class extends Sandbox {}, _defineProperty(_Class, "boundOpts", boundOpts), _Class);
539
+ const core = new boxfab.BoxFab(boundOpts);
540
+ this.Volume = core.Volume;
541
+ this.Template = core.Template;
542
+ this.Secret = core.Secret;
543
+ }
544
+ };
545
+ exports.BoxFab = BoxFab;
546
+ exports.E2B = BoxFab;
547
+ exports.Sandbox = Sandbox;
548
+ Object.keys(boxfab).forEach(function(k) {
549
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
550
+ enumerable: true,
551
+ get: function() {
552
+ return boxfab[k];
553
+ }
554
+ });
555
+ });
556
+
557
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["randomInt","SandboxBase","CommandExitError","TimeoutError","CoreBoxFab"],"sources":["../src/utils.ts","../src/sandbox.ts","../src/client.ts"],"sourcesContent":["import { randomInt } from 'crypto'\n\nexport function generateRandomString(length: number = 16): string {\n const characters =\n 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'\n let result = ''\n\n for (let i = 0; i < length; i++) {\n result += characters[randomInt(characters.length)]\n }\n\n return result\n}\n","import {\n Sandbox as SandboxBase,\n SandboxOpts as SandboxOptsBase,\n CommandHandle,\n CommandResult,\n CommandExitError,\n TimeoutError,\n} from 'boxfab'\n\nimport { generateRandomString } from './utils'\n\ninterface CursorPosition {\n x: number\n y: number\n}\n\ninterface ScreenSize {\n width: number\n height: number\n}\n\nconst MOUSE_BUTTONS = {\n left: 1,\n right: 3,\n middle: 2,\n}\n\nconst KEYS = {\n alt: 'Alt_L',\n alt_left: 'Alt_L',\n alt_right: 'Alt_R',\n backspace: 'BackSpace',\n break: 'Pause',\n caps_lock: 'Caps_Lock',\n cmd: 'Super_L',\n command: 'Super_L',\n control: 'Control_L',\n control_left: 'Control_L',\n control_right: 'Control_R',\n ctrl: 'Control_L',\n del: 'Delete',\n delete: 'Delete',\n down: 'Down',\n end: 'End',\n enter: 'Return',\n esc: 'Escape',\n escape: 'Escape',\n f1: 'F1',\n f2: 'F2',\n f3: 'F3',\n f4: 'F4',\n f5: 'F5',\n f6: 'F6',\n f7: 'F7',\n f8: 'F8',\n f9: 'F9',\n f10: 'F10',\n f11: 'F11',\n f12: 'F12',\n home: 'Home',\n insert: 'Insert',\n left: 'Left',\n menu: 'Menu',\n meta: 'Meta_L',\n num_lock: 'Num_Lock',\n page_down: 'Page_Down',\n page_up: 'Page_Up',\n pause: 'Pause',\n print: 'Print',\n right: 'Right',\n scroll_lock: 'Scroll_Lock',\n shift: 'Shift_L',\n shift_left: 'Shift_L',\n shift_right: 'Shift_R',\n space: 'space',\n super: 'Super_L',\n super_left: 'Super_L',\n super_right: 'Super_R',\n tab: 'Tab',\n up: 'Up',\n win: 'Super_L',\n windows: 'Super_L',\n}\n\nfunction mapKey(key: string): string {\n const lowerKey = key.toLowerCase()\n if (lowerKey in KEYS) {\n return KEYS[lowerKey as keyof typeof KEYS]\n }\n return lowerKey\n}\n\n/**\n * Configuration options for the Sandbox environment.\n * @interface SandboxOpts\n * @extends {SandboxOptsBase}\n */\nexport interface SandboxOpts extends SandboxOptsBase {\n /**\n * The screen resolution in pixels, specified as [width, height].\n * @type {[number, number]}\n */\n resolution?: [number, number]\n\n /**\n * Dots per inch (DPI) setting for the display.\n * @type {number}\n */\n dpi?: number\n\n /**\n * Display identifier.\n * @type {string}\n */\n display?: string\n}\n\nexport class Sandbox extends SandboxBase {\n protected static override readonly defaultTemplate: string = 'desktop'\n public display: string = ':0'\n public stream: VNCServer = new VNCServer(this)\n private lastXfce4Pid: number | null = null\n\n /**\n * Use {@link Sandbox.create} to create a new Sandbox instead.\n *\n * @hidden\n * @hide\n * @internal\n * @access protected\n */\n constructor(\n opts: Omit<SandboxOpts, 'timeoutMs' | 'metadata'> & {\n sandboxId: string\n envdVersion: string\n }\n ) {\n super(opts)\n }\n\n /**\n * Create a new sandbox from the default `desktop` sandbox template.\n *\n * @param opts connection options.\n *\n * @returns sandbox instance for the new sandbox.\n *\n * @example\n * ```ts\n * const sandbox = await Sandbox.create()\n * ```\n * @constructs Sandbox\n */\n static async create<S extends typeof Sandbox>(\n this: S,\n opts?: SandboxOpts\n ): Promise<InstanceType<S>>\n /**\n * Create a new sandbox from the specified sandbox template.\n *\n * @param template sandbox template name or ID.\n * @param opts connection options.\n *\n * @returns sandbox instance for the new sandbox.\n *\n * @example\n * ```ts\n * const sandbox = await Sandbox.create('<template-name-or-id>')\n * ```\n * @constructs Sandbox\n */\n static async create<S extends typeof Sandbox>(\n this: S,\n template: string,\n opts?: SandboxOpts\n ): Promise<InstanceType<S>>\n static async create<S extends typeof Sandbox>(\n this: S,\n templateOrOpts?: SandboxOpts | string,\n opts?: SandboxOpts\n ): Promise<InstanceType<S>> {\n const { template, sandboxOpts } =\n typeof templateOrOpts === 'string'\n ? { template: templateOrOpts, sandboxOpts: opts }\n : { template: this.defaultTemplate, sandboxOpts: templateOrOpts }\n\n // Add DISPLAY environment variable if not already set\n const display = opts?.display || ':0'\n const sandboxOptsWithDisplay = {\n ...sandboxOpts,\n envs: {\n ...sandboxOpts?.envs,\n DISPLAY: display,\n },\n }\n\n const sbx = (await super.create(\n template,\n sandboxOptsWithDisplay\n )) as InstanceType<S>\n try {\n await sbx._start(display, sandboxOptsWithDisplay)\n } catch (error) {\n await sbx.kill().catch(() => {})\n throw error\n }\n\n return sbx\n }\n\n /**\n * Wait for a command to return a specific result.\n * @param cmd - The command to run.\n * @param onResult - The function to check the result of the command.\n * @param timeout - The maximum time to wait for the command to return the result.\n * @param interval - The interval to wait between checks.\n * @returns `true` if the command returned the result within the timeout, otherwise `false`.\n */\n async waitAndVerify(\n cmd: string,\n onResult: (result: CommandResult) => boolean,\n timeout: number = 10,\n interval: number = 0.5\n ): Promise<boolean> {\n let elapsed = 0\n\n while (elapsed < timeout) {\n try {\n if (onResult(await this.commands.run(cmd))) {\n return true\n }\n } catch (e) {\n if (!(e instanceof CommandExitError)) {\n throw e\n }\n }\n\n await new Promise((resolve) => setTimeout(resolve, interval * 1000))\n elapsed += interval\n }\n\n return false\n }\n\n /**\n * Take a screenshot and save it to the given name.\n * @param format - The format of the screenshot.\n * @returns A Uint8Array bytes representation of the screenshot.\n */\n async screenshot(): Promise<Uint8Array>\n /**\n * Take a screenshot and save it to the given name.\n * @param format - The format of the screenshot.\n * @returns A Uint8Array bytes representation of the screenshot.\n */\n async screenshot(format: 'bytes'): Promise<Uint8Array>\n /**\n * Take a screenshot and save it to the given name.\n * @returns A Blob representation of the screenshot.\n */\n async screenshot(format: 'blob'): Promise<Blob>\n /**\n * Take a screenshot and save it to the given name.\n * @returns A ReadableStream of bytes representation of the screenshot.\n */\n async screenshot(format: 'stream'): Promise<ReadableStream<Uint8Array>>\n async screenshot(format: 'bytes' | 'blob' | 'stream' = 'bytes') {\n const path = `/tmp/screenshot-${generateRandomString()}.png`\n await this.commands.run(`scrot --pointer ${path}`)\n\n // @ts-expect-error\n const file = await this.files.read(path, { format })\n // Cleanup of the temporary file is best-effort: it must not block the\n // returned file (which may be an unconsumed stream) and must not reject\n // if the sandbox is already gone.\n void this.files.remove(path).catch(() => {})\n return file\n }\n\n /**\n * Left click on the mouse position.\n */\n async leftClick(x?: number, y?: number): Promise<void> {\n if (x && y) {\n await this.moveMouse(x, y)\n }\n\n await this.commands.run('xdotool click 1')\n }\n\n /**\n * Double left click on the mouse position.\n */\n async doubleClick(x?: number, y?: number): Promise<void> {\n if (x && y) {\n await this.moveMouse(x, y)\n }\n\n await this.commands.run('xdotool click --repeat 2 1')\n }\n\n /**\n * Right click on the mouse position.\n */\n async rightClick(x?: number, y?: number): Promise<void> {\n if (x && y) {\n await this.moveMouse(x, y)\n }\n\n await this.commands.run('xdotool click 3')\n }\n\n /**\n * Middle click on the mouse position.\n */\n async middleClick(x?: number, y?: number): Promise<void> {\n if (x && y) {\n await this.moveMouse(x, y)\n }\n\n await this.commands.run('xdotool click 2')\n }\n\n /**\n * Scroll the mouse wheel by the given amount.\n * @param direction - The direction to scroll. Can be \"up\" or \"down\".\n * @param amount - The amount to scroll.\n */\n async scroll(\n direction: 'up' | 'down' = 'down',\n amount: number = 1\n ): Promise<void> {\n const button = direction === 'up' ? '4' : '5'\n await this.commands.run(`xdotool click --repeat ${amount} ${button}`)\n }\n\n /**\n * Move the mouse to the given coordinates.\n * @param x - The x coordinate.\n * @param y - The y coordinate.\n */\n async moveMouse(x: number, y: number): Promise<void> {\n await this.commands.run(`xdotool mousemove --sync ${x} ${y}`)\n }\n\n /**\n * Press the mouse button.\n */\n async mousePress(\n button: 'left' | 'right' | 'middle' = 'left'\n ): Promise<void> {\n await this.commands.run(`xdotool mousedown ${MOUSE_BUTTONS[button]}`)\n }\n\n /**\n * Release the mouse button.\n */\n async mouseRelease(\n button: 'left' | 'right' | 'middle' = 'left'\n ): Promise<void> {\n await this.commands.run(`xdotool mouseup ${MOUSE_BUTTONS[button]}`)\n }\n\n /**\n * Get the current cursor position.\n * @returns A object with the x and y coordinates\n * @throws Error if cursor position cannot be determined\n */\n async getCursorPosition(): Promise<CursorPosition> {\n const result = await this.commands.run('xdotool getmouselocation')\n\n const match = result.stdout.match(/x:(\\d+)\\s+y:(\\d+)/)\n if (!match) {\n throw new Error(\n `Failed to parse cursor position from output: ${result.stdout}`\n )\n }\n\n const [, x, y] = match\n if (!x || !y) {\n throw new Error(`Invalid cursor position values: x=${x}, y=${y}`)\n }\n\n return { x: parseInt(x), y: parseInt(y) }\n }\n\n /**\n * Get the current screen size.\n * @returns An {@link ScreenSize} object\n * @throws Error if screen size cannot be determined\n */\n async getScreenSize(): Promise<ScreenSize> {\n const result = await this.commands.run('xrandr')\n\n const match = result.stdout.match(/(\\d+x\\d+)/)\n if (!match) {\n throw new Error(\n `Failed to parse screen size from output: ${result.stdout}`\n )\n }\n\n try {\n const [width, height] = match[1].split('x').map((val) => parseInt(val))\n return { width, height }\n } catch (error) {\n throw new Error(`Invalid screen size format: ${match[1]}`)\n }\n }\n\n /**\n * Write the given text at the current cursor position.\n * @param text - The text to write.\n * @param options - An object containing the chunk size and delay between each chunk of text.\n * @param options.chunkSize - The size of each chunk of text to write. Default is 25 characters.\n * @param options.delayInMs - The delay between each chunk of text. Default is 75 ms.\n */\n async write(\n text: string,\n options: { chunkSize: number; delayInMs: number } = {\n chunkSize: 25,\n delayInMs: 75,\n }\n ): Promise<void> {\n const chunks = this.breakIntoChunks(text, options.chunkSize)\n\n for (const chunk of chunks) {\n await this.commands.run(\n `xdotool type --delay ${options.delayInMs} -- ${this.quoteString(\n chunk\n )}`\n )\n }\n }\n\n /**\n * Press a key.\n * @param key - The key to press (e.g. \"enter\", \"space\", \"backspace\", etc.). Can be a single key or an array of keys.\n */\n async press(key: string | string[]): Promise<void> {\n if (Array.isArray(key)) {\n key = key.map(mapKey).join('+')\n } else {\n key = mapKey(key)\n }\n\n await this.commands.run(`xdotool key ${key}`)\n }\n\n /**\n * Drag the mouse from the given position to the given position.\n * @param from - The starting position as `[x, y]`.\n * @param to - The ending position as `[x, y]`.\n */\n async drag(from: [number, number], to: [number, number]): Promise<void> {\n await this.moveMouse(...from)\n await this.mousePress()\n await this.moveMouse(...to)\n await this.mouseRelease()\n }\n\n /**\n * Wait for the given amount of time.\n * @param ms - The amount of time to wait in milliseconds.\n */\n async wait(ms: number): Promise<void> {\n await this.commands.run(`sleep ${ms / 1000}`)\n }\n\n /**\n * Open a file or a URL in the default application.\n * @param fileOrUrl - The file or URL to open.\n */\n async open(fileOrUrl: string): Promise<void> {\n const handle = await this.commands.run(`xdg-open ${fileOrUrl}`, {\n background: true,\n })\n await handle.disconnect()\n }\n\n /**\n * Get the current window ID.\n * @returns The ID of the current window.\n */\n async getCurrentWindowId(): Promise<string> {\n const result = await this.commands.run('xdotool getwindowfocus')\n return result.stdout.trim()\n }\n\n /**\n * Get the window ID of the window with the given title.\n * @param title - The title of the window.\n * @returns The ID of the window.\n */\n async getApplicationWindows(application: string): Promise<string[]> {\n const result = await this.commands.run(\n `xdotool search --onlyvisible --class ${application}`\n )\n\n return result.stdout.trim().split('\\n')\n }\n\n /**\n * Get the title of the window with the given ID.\n * @param windowId - The ID of the window.\n * @returns The title of the window.\n */\n async getWindowTitle(windowId: string): Promise<string> {\n const result = await this.commands.run(`xdotool getwindowname ${windowId}`)\n\n return result.stdout.trim()\n }\n\n /**\n * Launch an application.\n * @param application - The application to launch.\n * @param uri - The URI to open in the application.\n */\n async launch(application: string, uri?: string): Promise<void> {\n const handle = await this.commands.run(\n `gtk-launch ${application} ${uri ?? ''}`,\n {\n background: true,\n timeoutMs: 0,\n }\n )\n await handle.disconnect()\n }\n\n protected async _start(display: string, opts?: SandboxOpts): Promise<void> {\n this.display = display\n this.lastXfce4Pid = null\n this.stream = new VNCServer(this)\n\n const [width, height] = opts?.resolution ?? [1024, 768]\n const xvfbHandle = await this.commands.run(\n `Xvfb ${display} -ac -screen 0 ${width}x${height}x24 ` +\n `-retro -dpi ${opts?.dpi ?? 96} -nolisten tcp -nolisten unix`,\n { background: true, timeoutMs: 0 }\n )\n await xvfbHandle.disconnect()\n\n const hasStarted = await this.waitAndVerify(\n `xdpyinfo -display ${display}`,\n (r: CommandResult) => r.exitCode === 0\n )\n if (!hasStarted) {\n throw new TimeoutError('Could not start Xvfb')\n }\n\n await this.startXfce4()\n }\n\n /**\n * Start xfce4 session if logged out or not running.\n */\n private async startXfce4(): Promise<void> {\n if (\n this.lastXfce4Pid === null ||\n (\n await this.commands.run(\n `ps aux | grep ${this.lastXfce4Pid} | grep -v grep | head -n 1`\n )\n ).stdout\n .trim()\n .includes('[xfce4-session] <defunct>')\n ) {\n const result = await this.commands.run('startxfce4', {\n background: true,\n timeoutMs: 0,\n })\n this.lastXfce4Pid = result.pid\n await result.disconnect()\n }\n\n const hasStarted = await this.waitAndVerify(\n 'pgrep -x xfce4-session >/dev/null && pgrep -x xfwm4 >/dev/null && pgrep -x xfdesktop >/dev/null',\n (r: CommandResult) => r.exitCode === 0,\n 60\n )\n if (!hasStarted) {\n throw new TimeoutError('Could not start XFCE')\n }\n }\n\n private *breakIntoChunks(text: string, n: number): Generator<string> {\n for (let i = 0; i < text.length; i += n) {\n yield text.slice(i, i + n)\n }\n }\n\n private quoteString(s: string): string {\n if (!s) {\n return \"''\"\n }\n\n if (!/[^\\w@%+=:,./-]/.test(s)) {\n return s\n }\n\n // use single quotes, and put single quotes into double quotes\n // the string $'b is then quoted as '$'\"'\"'b'\n return \"'\" + s.replace(/'/g, \"'\\\"'\\\"'\") + \"'\"\n }\n}\n\ninterface VNCServerOptions {\n vncPort?: number\n port?: number\n requireAuth?: boolean\n windowId?: string\n}\n\ninterface UrlOptions {\n autoConnect?: boolean\n viewOnly?: boolean\n resize?: 'off' | 'scale' | 'remote'\n authKey?: string\n}\n\n// Modified VNCServer class\nclass VNCServer {\n private vncPort: number = 5900\n private port: number = 6080\n private novncAuthEnabled: boolean = false\n private url: URL | null = null\n private novncHandle: CommandHandle | null = null\n private password: string | undefined\n private readonly novncCommand: string\n private readonly desktop: Sandbox\n\n constructor(desktop: Sandbox) {\n this.desktop = desktop\n this.novncCommand =\n `cd /opt/noVNC/utils && ./novnc_proxy --vnc localhost:${this.vncPort} ` +\n `--listen ${this.port} --web /opt/noVNC > /tmp/novnc.log 2>&1`\n }\n\n public getAuthKey(): string {\n if (!this.password) {\n throw new Error(\n 'Unable to retrieve stream auth key, check if requireAuth is enabled'\n )\n }\n\n return this.password\n }\n\n /**\n * Get the URL to a web page with a stream of the desktop sandbox.\n * @param autoConnect - Whether to automatically connect to the server after opening the URL.\n * @param viewOnly - Whether to prevent user interaction through the client.\n * @param resize - Whether to resize the view when the window resizes.\n * @param authKey - The password to use to connect to the server.\n * @returns The URL to connect to the VNC server.\n */\n public getUrl({\n autoConnect = true,\n viewOnly = false,\n resize = 'scale',\n authKey,\n }: UrlOptions = {}): string {\n if (this.url === null) {\n throw new Error('Server is not running')\n }\n\n const url = new URL(this.url)\n if (autoConnect) {\n url.searchParams.set('autoconnect', 'true')\n }\n if (viewOnly) {\n url.searchParams.set('view_only', 'true')\n }\n if (resize) {\n url.searchParams.set('resize', resize)\n }\n if (authKey) {\n url.searchParams.set('password', authKey)\n }\n return url.toString()\n }\n\n /**\n * Start the VNC server.\n */\n public async start(opts: VNCServerOptions = {}): Promise<void> {\n // If stream is already running, throw an error.\n if (await this.checkVNCRunning()) {\n throw new Error('Stream is already running')\n }\n\n this.vncPort = opts.vncPort ?? this.vncPort\n this.port = opts.port ?? this.port\n this.novncAuthEnabled = opts.requireAuth ?? this.novncAuthEnabled\n this.password = this.novncAuthEnabled ? generateRandomString() : undefined\n this.url = new URL(`https://${this.desktop.getHost(this.port)}/vnc.html`)\n\n const vncCommand = await this.getVNCCommand(opts.windowId)\n await this.desktop.commands.run(vncCommand)\n\n this.novncHandle = await this.desktop.commands.run(this.novncCommand, {\n background: true,\n timeoutMs: 0,\n })\n if (!(await this.waitForPort(this.port))) {\n throw new Error('Could not start noVNC server')\n }\n }\n\n /**\n * Stop the VNC server.\n */\n public async stop(): Promise<void> {\n if (await this.checkVNCRunning()) {\n await this.desktop.commands.run('pkill x11vnc')\n }\n\n if (this.novncHandle) {\n await this.novncHandle.kill()\n this.novncHandle = null\n }\n }\n\n /**\n * Set the VNC command to start the VNC server.\n */\n private async getVNCCommand(windowId?: string): Promise<string> {\n let pwdFlag = '-nopw'\n if (this.novncAuthEnabled) {\n // Create .vnc directory if it doesn't exist\n await this.desktop.commands.run('mkdir -p ~/.vnc')\n await this.desktop.commands.run(\n `x11vnc -storepasswd ${this.password} ~/.vnc/passwd`\n )\n pwdFlag = '-usepw'\n }\n\n return (\n `x11vnc -bg -display ${this.desktop.display} -forever -wait 50 -shared ` +\n `-rfbport ${this.vncPort} ${pwdFlag} 2>/tmp/x11vnc_stderr.log` +\n (windowId ? ` -id ${windowId}` : '')\n )\n }\n\n private async waitForPort(port: number): Promise<boolean> {\n return await this.desktop.waitAndVerify(\n `netstat -tuln | grep \":${port} \"`,\n (r: CommandResult) => r.stdout.trim() !== ''\n )\n }\n\n /**\n * Check if the VNC server is running.\n * @returns Whether the VNC server is running.\n */\n private async checkVNCRunning(): Promise<boolean> {\n try {\n const result = await this.desktop.commands.run('pgrep -x x11vnc')\n return result.stdout.trim() !== ''\n } catch (error) {\n return false\n }\n }\n}\n","import {\n ConnectionOpts,\n BoxFabClientOpts,\n BoxFab as CoreBoxFab,\n Secret,\n Template,\n Volume,\n} from 'boxfab'\n\nimport { Sandbox } from './sandbox'\n\nexport type { BoxFabClientOpts }\n\n/**\n * BoxFab client with an explicitly bound connection configuration.\n *\n * The resources exposed by the client ({@link BoxFab.Sandbox},\n * {@link BoxFab.Volume}, {@link BoxFab.Template}, {@link BoxFab.Secret}) behave exactly\n * like the top-level `Sandbox` / `Volume` / `Template` / `Secret` exports,\n * except the options passed to the client are used as the defaults instead of\n * the environment variables.\n * Per-call options still take precedence over the client's options.\n *\n * Multiple clients are fully isolated from each other and from the top-level\n * env-configured exports.\n *\n * @example\n * ```ts\n * import { BoxFab } from '@boxfab/desktop'\n *\n * const client = new BoxFab({ apiKey: 'e2b_...', domain: 'us-west.boxfab.dev' })\n *\n * const desktop = await client.Sandbox.create()\n * await desktop.stream.start()\n * ```\n */\nexport class BoxFab {\n /**\n * Desktop `Sandbox` class bound to this client's connection configuration.\n */\n readonly Sandbox: typeof Sandbox\n\n /**\n * `Volume` class bound to this client's connection configuration.\n */\n readonly Volume: typeof Volume\n\n /**\n * `Template` bound to this client's connection configuration. Both the\n * builder (`client.Template()`) and the statics\n * (`client.Template.build(...)`, `client.Template.exists(...)`, …) work like\n * the top-level `Template`.\n */\n readonly Template: typeof Template\n\n /**\n * `Secret` class bound to this client's connection configuration.\n */\n readonly Secret: typeof Secret\n\n /**\n * Create a new client with the connection options bound to it.\n *\n * @param opts connection options used as the defaults for every call made\n * through this client's resource classes.\n */\n constructor(opts?: BoxFabClientOpts) {\n // Options are copied so later mutations of the caller's object cannot\n // change the bound configuration. `signal` is dropped rather than only\n // typed away, since it cancels a single request and a caller passing a\n // wider-typed object (or plain JS) would otherwise bind it to every call.\n const boundOpts: BoxFabClientOpts = { ...(opts ?? {}) }\n delete (boundOpts as ConnectionOpts).signal\n\n if (boundOpts.headers) {\n boundOpts.headers = { ...boundOpts.headers }\n }\n if (boundOpts.apiHeaders) {\n boundOpts.apiHeaders = { ...boundOpts.apiHeaders }\n }\n\n this.Sandbox = class extends Sandbox {\n protected static override readonly boundOpts = boundOpts\n }\n\n // The resources that are not specific to the Desktop are bound by the core\n // client.\n const core = new CoreBoxFab(boundOpts)\n this.Volume = core.Volume\n this.Template = core.Template\n this.Secret = core.Secret\n }\n}\n"],"mappings":";;;;AAEA,SAAgB,qBAAqB,SAAiB,IAAY;CAChE,MAAM,aACJ;CACF,IAAI,SAAS;CAEb,KAAK,IAAI,IAAI,GAAG,IAAI,QAAQ,KAC1B,UAAU,YAAA,GAAWA,OAAAA,UAAAA,CAAU,EAAiB;CAGlD,OAAO;AACT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACSA,MAAM,gBAAgB;CACpB,MAAM;CACN,OAAO;CACP,QAAQ;AACV;AAEA,MAAM,OAAO;CACX,KAAK;CACL,UAAU;CACV,WAAW;CACX,WAAW;CACX,OAAO;CACP,WAAW;CACX,KAAK;CACL,SAAS;CACT,SAAS;CACT,cAAc;CACd,eAAe;CACf,MAAM;CACN,KAAK;CACL,QAAQ;CACR,MAAM;CACN,KAAK;CACL,OAAO;CACP,KAAK;CACL,QAAQ;CACR,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,KAAK;CACL,KAAK;CACL,KAAK;CACL,MAAM;CACN,QAAQ;CACR,MAAM;CACN,MAAM;CACN,MAAM;CACN,UAAU;CACV,WAAW;CACX,SAAS;CACT,OAAO;CACP,OAAO;CACP,OAAO;CACP,aAAa;CACb,OAAO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