aicomputer 0.1.13 → 0.1.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,655 @@
1
+ import {
2
+ ensureHandleDirectories,
3
+ ensureMountDirectories,
4
+ getMountHandlePaths,
5
+ readMountStatusSnapshot,
6
+ removeMountHandleState,
7
+ writeMountHandleMeta,
8
+ writeMountStatusSnapshot
9
+ } from "./chunk-5JVJROSI.js";
10
+
11
+ // src/lib/mount-reconcile.ts
12
+ import { readdir, mkdir, rename, rm } from "fs/promises";
13
+ import { join as join3 } from "path";
14
+
15
+ // src/lib/config.ts
16
+ import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "fs";
17
+ import { homedir } from "os";
18
+ import { join } from "path";
19
+ var CONFIG_DIR = join(homedir(), ".computer");
20
+ var CONFIG_FILE = join(CONFIG_DIR, "config.json");
21
+ function ensureConfigDir() {
22
+ if (!existsSync(CONFIG_DIR)) {
23
+ mkdirSync(CONFIG_DIR, { recursive: true, mode: 448 });
24
+ }
25
+ }
26
+ function readConfig() {
27
+ ensureConfigDir();
28
+ if (!existsSync(CONFIG_FILE)) {
29
+ return {};
30
+ }
31
+ try {
32
+ return JSON.parse(readFileSync(CONFIG_FILE, "utf8"));
33
+ } catch {
34
+ return {};
35
+ }
36
+ }
37
+ function writeConfig(config) {
38
+ ensureConfigDir();
39
+ const tempFile = `${CONFIG_FILE}.${process.pid}.tmp`;
40
+ writeFileSync(tempFile, JSON.stringify(config, null, 2), { mode: 384 });
41
+ renameSync(tempFile, CONFIG_FILE);
42
+ }
43
+ function getAPIKey() {
44
+ const envValue = process.env.COMPUTER_API_KEY ?? process.env.AGENTCOMPUTER_API_KEY;
45
+ if (envValue) {
46
+ return envValue.trim();
47
+ }
48
+ return getStoredAPIKey();
49
+ }
50
+ function getStoredAPIKey() {
51
+ return readConfig().auth?.apiKey?.trim() || null;
52
+ }
53
+ function hasEnvAPIKey() {
54
+ return Boolean(process.env.COMPUTER_API_KEY ?? process.env.AGENTCOMPUTER_API_KEY);
55
+ }
56
+ function setAPIKey(apiKey) {
57
+ const config = readConfig();
58
+ config.auth = { apiKey: apiKey.trim() };
59
+ writeConfig(config);
60
+ }
61
+ function clearAPIKey() {
62
+ const config = readConfig();
63
+ delete config.auth;
64
+ writeConfig(config);
65
+ }
66
+
67
+ // src/lib/api.ts
68
+ var BASE_URL = process.env.COMPUTER_API_URL ?? process.env.AGENTCOMPUTER_API_URL ?? "https://api.computer.agentcomputer.ai";
69
+ var WEB_URL = process.env.COMPUTER_WEB_URL ?? process.env.AGENTCOMPUTER_WEB_URL ?? resolveDefaultWebURL(BASE_URL);
70
+ var ApiError = class extends Error {
71
+ constructor(status, message) {
72
+ super(message);
73
+ this.status = status;
74
+ this.name = "ApiError";
75
+ }
76
+ };
77
+ function getBaseURL() {
78
+ return BASE_URL;
79
+ }
80
+ function getWebURL() {
81
+ return WEB_URL;
82
+ }
83
+ async function api(path, options = {}) {
84
+ const apiKey = getAPIKey();
85
+ if (!apiKey) {
86
+ throw new ApiError(401, "not logged in; run 'computer login' first");
87
+ }
88
+ return requestWithKey(apiKey, path, options);
89
+ }
90
+ function resolveDefaultWebURL(apiURL) {
91
+ try {
92
+ const parsed = new URL(apiURL);
93
+ if (parsed.hostname === "api.computer.agentcomputer.ai") {
94
+ return "https://agentcomputer.ai";
95
+ }
96
+ if (parsed.hostname === "localhost" || parsed.hostname === "127.0.0.1") {
97
+ return `${parsed.protocol}//${parsed.hostname}:3000`;
98
+ }
99
+ } catch {
100
+ return "https://agentcomputer.ai";
101
+ }
102
+ return "https://agentcomputer.ai";
103
+ }
104
+ async function apiWithKey(apiKey, path, options = {}) {
105
+ return requestWithKey(apiKey, path, options);
106
+ }
107
+ async function requestWithKey(apiKey, path, options) {
108
+ const headers = {
109
+ Accept: "application/json",
110
+ ...options.headers ?? {}
111
+ };
112
+ if (options.body !== void 0) {
113
+ headers["Content-Type"] = "application/json";
114
+ }
115
+ if (apiKey) {
116
+ headers.Authorization = `Bearer ${apiKey}`;
117
+ }
118
+ const response = await fetch(`${BASE_URL}${path}`, {
119
+ ...options,
120
+ headers
121
+ });
122
+ if (!response.ok) {
123
+ throw new ApiError(response.status, await readErrorMessage(response));
124
+ }
125
+ if (response.status === 204) {
126
+ return void 0;
127
+ }
128
+ return await response.json();
129
+ }
130
+ async function readErrorMessage(response) {
131
+ const contentType = response.headers.get("content-type") ?? "";
132
+ if (contentType.includes("application/json")) {
133
+ try {
134
+ const payload = await response.json();
135
+ if (payload.error) {
136
+ return payload.error;
137
+ }
138
+ return JSON.stringify(payload);
139
+ } catch {
140
+ return response.statusText || "request failed";
141
+ }
142
+ }
143
+ const body = await response.text();
144
+ return body || response.statusText || "request failed";
145
+ }
146
+
147
+ // src/lib/computers.ts
148
+ async function listComputers() {
149
+ const response = await api("/v1/computers");
150
+ return response.computers;
151
+ }
152
+ async function getComputerByID(id) {
153
+ return api(`/v1/computers/${id}`);
154
+ }
155
+ async function createComputer(input) {
156
+ return api("/v1/computers", {
157
+ method: "POST",
158
+ body: JSON.stringify(input)
159
+ });
160
+ }
161
+ async function deleteComputer(computerID) {
162
+ return api(`/v1/computers/${computerID}`, {
163
+ method: "DELETE"
164
+ });
165
+ }
166
+ async function getFilesystemSettings() {
167
+ return api("/v1/me/filesystem");
168
+ }
169
+ async function getConnectionInfo(computerID) {
170
+ return api(`/v1/computers/${computerID}/connection`);
171
+ }
172
+ async function createBrowserAccess(computerID) {
173
+ return api(`/v1/computers/${computerID}/access/browser`, {
174
+ method: "POST"
175
+ });
176
+ }
177
+ async function listPublishedPorts(computerID) {
178
+ const response = await api(`/v1/computers/${computerID}/ports`);
179
+ return response.ports;
180
+ }
181
+ async function publishPort(computerID, input) {
182
+ return api(`/v1/computers/${computerID}/ports`, {
183
+ method: "POST",
184
+ body: JSON.stringify(input)
185
+ });
186
+ }
187
+ async function deletePublishedPort(computerID, targetPort) {
188
+ return api(`/v1/computers/${computerID}/ports/${targetPort}`, {
189
+ method: "DELETE"
190
+ });
191
+ }
192
+ async function resolveComputer(identifier) {
193
+ try {
194
+ return await getComputerByID(identifier);
195
+ } catch (error) {
196
+ if (!(error instanceof Error) || !("status" in error)) {
197
+ throw error;
198
+ }
199
+ const status = Reflect.get(error, "status");
200
+ if (status !== 404) {
201
+ throw error;
202
+ }
203
+ }
204
+ const computers = await listComputers();
205
+ const exact = computers.find(
206
+ (computer) => computer.handle === identifier || computer.id === identifier
207
+ );
208
+ if (exact) {
209
+ return exact;
210
+ }
211
+ throw new Error(`computer '${identifier}' not found`);
212
+ }
213
+ function webURL(computer) {
214
+ return `https://${computer.primary_web_host}${normalizePrimaryPath(computer.primary_path)}`;
215
+ }
216
+ function vncURL(computer) {
217
+ if (!computer.vnc_enabled) {
218
+ return null;
219
+ }
220
+ const domain = computer.primary_web_host.replace(/^[^.]+\./, "");
221
+ return `https://6080--${computer.handle}.${domain}`;
222
+ }
223
+ function normalizePrimaryPath(primaryPath) {
224
+ const trimmed = primaryPath?.trim();
225
+ if (!trimmed) {
226
+ return "/";
227
+ }
228
+ return trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
229
+ }
230
+
231
+ // src/lib/computer-picker.ts
232
+ import { select } from "@inquirer/prompts";
233
+ import chalk2 from "chalk";
234
+
235
+ // src/lib/format.ts
236
+ import chalk from "chalk";
237
+ function padEnd(str, len) {
238
+ const visible = str.replace(/\u001b\[[0-9;]*m/g, "");
239
+ return str + " ".repeat(Math.max(0, len - visible.length));
240
+ }
241
+ function timeAgo(dateStr) {
242
+ const seconds = Math.floor((Date.now() - new Date(dateStr).getTime()) / 1e3);
243
+ if (seconds < 60) return `${seconds}s ago`;
244
+ const minutes = Math.floor(seconds / 60);
245
+ if (minutes < 60) return `${minutes}m ago`;
246
+ const hours = Math.floor(minutes / 60);
247
+ if (hours < 24) return `${hours}h ago`;
248
+ const days = Math.floor(hours / 24);
249
+ return `${days}d ago`;
250
+ }
251
+ function minuteSecondAgo(dateStr) {
252
+ const timestamp = new Date(dateStr).getTime();
253
+ if (!Number.isFinite(timestamp)) {
254
+ return "unknown";
255
+ }
256
+ const totalSeconds = Math.max(0, Math.floor((Date.now() - timestamp) / 1e3));
257
+ const totalMinutes = Math.floor(totalSeconds / 60);
258
+ const seconds = totalSeconds % 60;
259
+ return `${totalMinutes}:${String(seconds).padStart(2, "0")} ago`;
260
+ }
261
+ function formatStatus(status) {
262
+ switch (status) {
263
+ case "running":
264
+ return chalk.green(status);
265
+ case "pending":
266
+ case "provisioning":
267
+ case "starting":
268
+ return chalk.yellow(status);
269
+ case "stopping":
270
+ case "stopped":
271
+ case "deleted":
272
+ return chalk.gray(status);
273
+ case "error":
274
+ return chalk.red(status);
275
+ default:
276
+ return status;
277
+ }
278
+ }
279
+
280
+ // src/lib/computer-picker.ts
281
+ async function promptForSSHComputer(computers, message) {
282
+ if (!process.stdin.isTTY || !process.stdout.isTTY) {
283
+ throw new Error("computer id or handle is required when not running interactively");
284
+ }
285
+ const available = computers.filter(isSSHSelectable);
286
+ if (available.length === 0) {
287
+ if (computers.length === 0) {
288
+ throw new Error("no computers found");
289
+ }
290
+ throw new Error("no running computers with SSH enabled");
291
+ }
292
+ const handleWidth = Math.max(6, ...available.map((computer) => computer.handle.length));
293
+ const selectedID = await select({
294
+ message,
295
+ pageSize: Math.min(available.length, 10),
296
+ choices: available.map((computer) => ({
297
+ name: `${padEnd(chalk2.white(computer.handle), handleWidth + 2)}${padEnd(formatStatus(computer.status), 12)}${chalk2.dim(describeSSHChoice(computer))}`,
298
+ value: computer.id
299
+ }))
300
+ });
301
+ return available.find((computer) => computer.id === selectedID) ?? available[0];
302
+ }
303
+ function isSSHSelectable(computer) {
304
+ return computer.ssh_enabled && computer.status === "running";
305
+ }
306
+ function describeSSHChoice(computer) {
307
+ const displayName = computer.display_name.trim();
308
+ if (displayName && displayName !== computer.handle) {
309
+ return `${displayName} ${timeAgo(computer.updated_at)}`;
310
+ }
311
+ return `${computer.runtime_family} ${timeAgo(computer.updated_at)}`;
312
+ }
313
+
314
+ // src/lib/mount-mutagen.ts
315
+ import { chmodSync, existsSync as existsSync2, readFileSync as readFileSync2, symlinkSync, unlinkSync, writeFileSync as writeFileSync2 } from "fs";
316
+ import { spawnSync } from "child_process";
317
+ import { basename, join as join2 } from "path";
318
+ function ensureMutagenSshEnvironment(config, paths) {
319
+ ensureMountDirectories(paths);
320
+ const sshPath = resolveCommandPath("ssh");
321
+ const scpPath = resolveCommandPath("scp");
322
+ writeExecutableLink(paths.sshToolsDir, "ssh", sshPath);
323
+ writeExecutableLink(paths.sshToolsDir, "scp", scpPath);
324
+ writeExecutableLink(paths.sshToolsDir, basename(sshPath), sshPath);
325
+ writeExecutableLink(paths.sshToolsDir, basename(scpPath), scpPath);
326
+ }
327
+ function writeHandleProjectFile(handle, config, paths) {
328
+ const handlePaths = ensureHandleDirectories(handle, config.rootPath);
329
+ const content = [
330
+ "sync:",
331
+ " defaults:",
332
+ " flushOnCreate: true",
333
+ " mirror:",
334
+ ` alpha: ${yamlString(join2(paths.rootPath, handle))}`,
335
+ ` beta: ${yamlString(`${handle}@${config.alias}:/home/node`)}`,
336
+ ""
337
+ ].join("\n");
338
+ writeFileSync2(handlePaths.projectFilePath, content, { mode: 384 });
339
+ return handlePaths.projectFilePath;
340
+ }
341
+ function startHandleProject(handle, config, paths) {
342
+ const handlePaths = getMountHandlePaths(handle, config.rootPath);
343
+ runMutagen(["project", "start", "-f", handlePaths.projectFilePath], config, paths, handle);
344
+ runMutagen(["project", "flush", "-f", handlePaths.projectFilePath], config, paths, handle);
345
+ }
346
+ function terminateHandleProject(handle, config, paths) {
347
+ const handlePaths = getMountHandlePaths(handle, config.rootPath);
348
+ if (!existsSync2(handlePaths.projectFilePath)) {
349
+ return;
350
+ }
351
+ runMutagen(["project", "terminate", "-f", handlePaths.projectFilePath], config, paths, handle, true);
352
+ }
353
+ function inspectHandleProject(handle, config, paths) {
354
+ const handlePaths = getMountHandlePaths(handle, config.rootPath);
355
+ if (!existsSync2(handlePaths.projectFilePath)) {
356
+ return {
357
+ ok: false,
358
+ stdout: "",
359
+ stderr: "project file missing"
360
+ };
361
+ }
362
+ return runMutagen(["project", "list", "-f", handlePaths.projectFilePath], config, paths, handle, true);
363
+ }
364
+ function cleanupKnownHandleProjects(config, paths, handles) {
365
+ for (const handle of handles) {
366
+ terminateHandleProject(handle, config, paths);
367
+ }
368
+ }
369
+ function runMutagen(args, config, paths, handle, ignoreFailure = false) {
370
+ const result = spawnSync("mutagen", args, {
371
+ encoding: "utf8",
372
+ env: {
373
+ ...process.env,
374
+ MUTAGEN_SSH_PATH: paths.sshToolsDir,
375
+ MUTAGEN_SSH_CONNECT_TIMEOUT: String(config.connectTimeoutSeconds)
376
+ }
377
+ });
378
+ const stdout = result.stdout?.trim() ?? "";
379
+ const stderr = result.stderr?.trim() ?? "";
380
+ if (result.status !== 0 && !ignoreFailure) {
381
+ throw new Error(stderr || stdout || `mutagen failed for ${handle}`);
382
+ }
383
+ return {
384
+ ok: result.status === 0,
385
+ stdout,
386
+ stderr
387
+ };
388
+ }
389
+ function resolveCommandPath(command) {
390
+ const result = spawnSync("which", [command], { encoding: "utf8" });
391
+ if (result.status !== 0) {
392
+ throw new Error(`failed to resolve ${command}`);
393
+ }
394
+ return result.stdout.trim();
395
+ }
396
+ function writeExecutableLink(directory, name, target) {
397
+ const linkPath = join2(directory, name);
398
+ try {
399
+ unlinkSync(linkPath);
400
+ } catch {
401
+ }
402
+ try {
403
+ symlinkSync(target, linkPath);
404
+ } catch {
405
+ const script = `#!/bin/sh
406
+ exec "${escapeShell(target)}" "$@"
407
+ `;
408
+ writeFileSync2(linkPath, script, { mode: 493 });
409
+ chmodSync(linkPath, 493);
410
+ return;
411
+ }
412
+ try {
413
+ const stat = readFileSync2(linkPath);
414
+ if (!stat) {
415
+ throw new Error("empty");
416
+ }
417
+ } catch {
418
+ const script = `#!/bin/sh
419
+ exec "${escapeShell(target)}" "$@"
420
+ `;
421
+ writeFileSync2(linkPath, script, { mode: 493 });
422
+ chmodSync(linkPath, 493);
423
+ }
424
+ }
425
+ function yamlString(value) {
426
+ return JSON.stringify(value);
427
+ }
428
+ function escapeShell(value) {
429
+ return value.replaceAll("\\", "\\\\").replaceAll("`", "\\`").replaceAll("$", "\\$").replaceAll('"', '\\"');
430
+ }
431
+
432
+ // src/lib/mount-reconcile.ts
433
+ function computeMountPlan(input) {
434
+ const previousByHandle = new Map(
435
+ (input.previousSnapshot?.mounts ?? []).map((mount) => [mount.handle, mount])
436
+ );
437
+ const desiredHandles = new Set(
438
+ [...input.desired, ...input.pending].map((entry) => entry.handle)
439
+ );
440
+ const toStart = [];
441
+ const toCheck = [];
442
+ for (const entry of input.desired) {
443
+ const previous = previousByHandle.get(entry.handle);
444
+ if (previous?.state === "mounted") {
445
+ toCheck.push(entry);
446
+ } else {
447
+ toStart.push(entry);
448
+ }
449
+ }
450
+ const toStop = /* @__PURE__ */ new Set();
451
+ for (const mount of input.previousSnapshot?.mounts ?? []) {
452
+ if (!desiredHandles.has(mount.handle)) {
453
+ toStop.add(mount.handle);
454
+ }
455
+ }
456
+ for (const entry of input.rootEntries) {
457
+ if (!desiredHandles.has(entry)) {
458
+ toStop.add(entry);
459
+ }
460
+ }
461
+ return {
462
+ toStart,
463
+ toCheck,
464
+ toStop: Array.from(toStop).sort(),
465
+ pending: input.pending
466
+ };
467
+ }
468
+ async function planMountReconcile(config, paths) {
469
+ const computers = await listComputers();
470
+ const desired = [];
471
+ const pending = [];
472
+ for (const computer of computers.filter(isSSHSelectable)) {
473
+ const mountPath = join3(paths.rootPath, computer.handle);
474
+ try {
475
+ const info = await getConnectionInfo(computer.id);
476
+ if (!info.connection.ssh_available) {
477
+ pending.push({
478
+ handle: computer.handle,
479
+ mountPath,
480
+ ready: false,
481
+ message: "SSH is not ready yet"
482
+ });
483
+ continue;
484
+ }
485
+ } catch (error) {
486
+ pending.push({
487
+ handle: computer.handle,
488
+ mountPath,
489
+ ready: false,
490
+ message: error instanceof Error ? error.message : "Failed to confirm SSH readiness"
491
+ });
492
+ continue;
493
+ }
494
+ desired.push({
495
+ handle: computer.handle,
496
+ mountPath,
497
+ ready: true
498
+ });
499
+ }
500
+ const previousSnapshot = readMountStatusSnapshot(config.rootPath);
501
+ const rootEntries = await listRootHandleDirectories(paths.rootPath);
502
+ return computeMountPlan({
503
+ desired,
504
+ pending,
505
+ previousSnapshot,
506
+ rootEntries
507
+ });
508
+ }
509
+ async function reconcileMounts(config, paths, controllerPid = process.pid) {
510
+ ensureMutagenSshEnvironment(config, paths);
511
+ const plan = await planMountReconcile(config, paths);
512
+ const mounts = [];
513
+ const errors = [];
514
+ for (const handle of plan.toStop) {
515
+ try {
516
+ terminateHandleProject(handle, config, paths);
517
+ await moveHandleOutOfRoot(handle, paths);
518
+ removeMountHandleState(handle, config.rootPath);
519
+ } catch (error) {
520
+ errors.push(
521
+ error instanceof Error ? `${handle}: ${error.message}` : `${handle}: teardown failed`
522
+ );
523
+ }
524
+ }
525
+ for (const entry of plan.toCheck) {
526
+ try {
527
+ const inspection = inspectHandleProject(entry.handle, config, paths);
528
+ if (!inspection.ok) {
529
+ await ensureMountedHandle(entry, config, paths);
530
+ }
531
+ mounts.push(snapshotEntry(entry.handle, entry.mountPath, "mounted"));
532
+ } catch (error) {
533
+ const message = error instanceof Error ? error.message : "sync check failed";
534
+ mounts.push(snapshotEntry(entry.handle, entry.mountPath, "error", message));
535
+ errors.push(`${entry.handle}: ${message}`);
536
+ }
537
+ }
538
+ for (const entry of plan.toStart) {
539
+ try {
540
+ await ensureMountedHandle(entry, config, paths);
541
+ mounts.push(snapshotEntry(entry.handle, entry.mountPath, "mounted"));
542
+ } catch (error) {
543
+ const message = error instanceof Error ? error.message : "sync start failed";
544
+ mounts.push(snapshotEntry(entry.handle, entry.mountPath, "error", message));
545
+ errors.push(`${entry.handle}: ${message}`);
546
+ }
547
+ }
548
+ for (const entry of plan.pending) {
549
+ mounts.push(snapshotEntry(entry.handle, entry.mountPath, "pending", entry.message));
550
+ }
551
+ const now = (/* @__PURE__ */ new Date()).toISOString();
552
+ const previousSnapshot = readMountStatusSnapshot(config.rootPath);
553
+ const snapshot = {
554
+ updatedAt: now,
555
+ controllerPid,
556
+ running: true,
557
+ lastSuccessfulSyncAt: errors.length === 0 ? now : previousSnapshot?.lastSuccessfulSyncAt,
558
+ lastError: errors[0],
559
+ mounts: sortSnapshots(mounts)
560
+ };
561
+ writeMountStatusSnapshot(snapshot, config.rootPath);
562
+ return snapshot;
563
+ }
564
+ async function teardownManagedSessions(config, paths) {
565
+ const handles = await listKnownHandleStates(paths);
566
+ cleanupKnownHandleProjects(config, paths, handles);
567
+ for (const handle of handles) {
568
+ removeMountHandleState(handle, config.rootPath);
569
+ }
570
+ }
571
+ async function ensureMountedHandle(entry, config, paths) {
572
+ await mkdir(entry.mountPath, { recursive: true });
573
+ ensureHandleDirectories(entry.handle, config.rootPath);
574
+ writeHandleProjectFile(entry.handle, config, paths);
575
+ startHandleProject(entry.handle, config, paths);
576
+ writeMountHandleMeta(
577
+ entry.handle,
578
+ {
579
+ handle: entry.handle,
580
+ startedAt: (/* @__PURE__ */ new Date()).toISOString(),
581
+ lastStartedAt: (/* @__PURE__ */ new Date()).toISOString()
582
+ },
583
+ config.rootPath
584
+ );
585
+ }
586
+ async function moveHandleOutOfRoot(handle, paths) {
587
+ const sourcePath = join3(paths.rootPath, handle);
588
+ const stalePath = join3(paths.staleDir, `${handle}-${Date.now()}`);
589
+ try {
590
+ await rename(sourcePath, stalePath);
591
+ } catch {
592
+ await rm(sourcePath, { recursive: true, force: true });
593
+ }
594
+ }
595
+ function snapshotEntry(handle, mountPath, state, message) {
596
+ return {
597
+ handle,
598
+ mountPath,
599
+ state,
600
+ message,
601
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString()
602
+ };
603
+ }
604
+ function sortSnapshots(mounts) {
605
+ return mounts.slice().sort((left, right) => left.handle.localeCompare(right.handle));
606
+ }
607
+ async function listRootHandleDirectories(rootPath) {
608
+ try {
609
+ return (await readdir(rootPath, { withFileTypes: true })).filter((entry) => entry.isDirectory()).map((entry) => entry.name).sort();
610
+ } catch {
611
+ return [];
612
+ }
613
+ }
614
+ async function listKnownHandleStates(paths) {
615
+ try {
616
+ return (await readdir(paths.handlesDir, { withFileTypes: true })).filter((entry) => entry.isDirectory()).map((entry) => entry.name).sort();
617
+ } catch {
618
+ return [];
619
+ }
620
+ }
621
+
622
+ export {
623
+ getAPIKey,
624
+ getStoredAPIKey,
625
+ hasEnvAPIKey,
626
+ setAPIKey,
627
+ clearAPIKey,
628
+ ApiError,
629
+ getBaseURL,
630
+ getWebURL,
631
+ api,
632
+ apiWithKey,
633
+ listComputers,
634
+ getComputerByID,
635
+ createComputer,
636
+ deleteComputer,
637
+ getFilesystemSettings,
638
+ getConnectionInfo,
639
+ createBrowserAccess,
640
+ listPublishedPorts,
641
+ publishPort,
642
+ deletePublishedPort,
643
+ resolveComputer,
644
+ webURL,
645
+ vncURL,
646
+ padEnd,
647
+ timeAgo,
648
+ minuteSecondAgo,
649
+ formatStatus,
650
+ promptForSSHComputer,
651
+ computeMountPlan,
652
+ planMountReconcile,
653
+ reconcileMounts,
654
+ teardownManagedSessions
655
+ };