import { macosBackend } from "./macos/backend.ts"; import { isBrowserApp, isChromeFamilyApp, openBrowserLocationWithAppleScript } from "./macos/browser.ts"; import { ensureMacosReady } from "./macos/permissions.ts"; import type { ComputerUsePlatformBackend, PlatformName } from "./types.ts"; import { linuxBackend } from "./linux/backend.ts"; import { windowsBackend } from "./windows/backend.ts"; const macosPlatformBackend: ComputerUsePlatformBackend = { name: "macos", shutdown: macosBackend.shutdown, setActivity: macosBackend.setActivity, ensureReady: ensureMacosReady, listApps: macosBackend.listApps, listRoots: macosBackend.listRoots, getFrontmost: macosBackend.getFrontmost, focusWindow: macosBackend.focusWindow, observe: macosBackend.observe, act: macosBackend.act, actBatch: macosBackend.actBatch, readText: macosBackend.readText, waitFor: macosBackend.waitFor, isBrowserApp, isChromeFamilyApp, openBrowserLocation: openBrowserLocationWithAppleScript, }; class UnsupportedPlatformBackend implements ComputerUsePlatformBackend { readonly name: PlatformName; private readonly platform: NodeJS.Platform; constructor(platform: NodeJS.Platform) { this.platform = platform; this.name = platform === "win32" ? "windows" : "linux"; } private unsupported(): never { throw new Error(`pi-computer-use does not support platform '${this.platform}' yet.`); } async ensureReady(): Promise { this.unsupported(); } async listApps(): Promise { this.unsupported(); } async listRoots(): Promise { this.unsupported(); } async getFrontmost(): Promise { this.unsupported(); } async focusWindow(): Promise { this.unsupported(); } async observe(): Promise { this.unsupported(); } async act(): Promise { this.unsupported(); } async readText(): Promise { this.unsupported(); } async waitFor(): Promise { this.unsupported(); } isBrowserApp(): never { this.unsupported(); } isChromeFamilyApp(): never { this.unsupported(); } async openBrowserLocation(): Promise { this.unsupported(); } } export function platformBackendForRuntime(platform: NodeJS.Platform = process.platform): ComputerUsePlatformBackend { if (platform === "darwin") return macosPlatformBackend; if (platform === "win32") return windowsBackend; if (platform === "linux") return linuxBackend; return new UnsupportedPlatformBackend(platform); } export const currentPlatformBackend = platformBackendForRuntime();