From aeb0326d953bece44e3790646056248738c07ab2 Mon Sep 17 00:00:00 2001 From: yi7503 Date: Mon, 6 Apr 2026 08:53:20 +0800 Subject: [PATCH] feat: enable Computer Use on Windows and Linux MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove macOS-only guards so Computer Use works cross-platform: - main.tsx: allow CHICAGO_MCP on any known platform (not just macos) - swiftLoader.ts: remove darwin-only throw, let the backend handle it - computer-use-input: dispatch to darwin/win32/linux backends - computer-use-swift: rename loadDarwin→loadBackend, dispatch all platforms Co-Authored-By: Claude Opus 4.6 (1M context) --- packages/@ant/computer-use-input/src/index.ts | 10 ++++++++-- packages/@ant/computer-use-swift/src/index.ts | 20 ++++++++++++------- src/main.tsx | 2 +- src/utils/computerUse/swiftLoader.ts | 3 --- 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/packages/@ant/computer-use-input/src/index.ts b/packages/@ant/computer-use-input/src/index.ts index 171ef6005..22cb9bf96 100644 --- a/packages/@ant/computer-use-input/src/index.ts +++ b/packages/@ant/computer-use-input/src/index.ts @@ -22,12 +22,18 @@ export interface InputBackend { } function loadBackend(): InputBackend | null { - if (process.platform !== 'darwin') return null try { - return require('./backends/darwin.js') as InputBackend + if (process.platform === 'darwin') { + return require('./backends/darwin.js') as InputBackend + } else if (process.platform === 'win32') { + return require('./backends/win32.js') as InputBackend + } else if (process.platform === 'linux') { + return require('./backends/linux.js') as InputBackend + } } catch { return null } + return null } const backend = loadBackend() diff --git a/packages/@ant/computer-use-swift/src/index.ts b/packages/@ant/computer-use-swift/src/index.ts index b179966f0..28a1780cd 100644 --- a/packages/@ant/computer-use-swift/src/index.ts +++ b/packages/@ant/computer-use-swift/src/index.ts @@ -18,19 +18,25 @@ export type { import type { ResolvePrepareCaptureResult } from './backends/darwin.js' -function loadDarwin() { - if (process.platform !== 'darwin') return null +function loadBackend() { try { - return require('./backends/darwin.js') + if (process.platform === 'darwin') { + return require('./backends/darwin.js') + } else if (process.platform === 'win32') { + return require('./backends/win32.js') + } else if (process.platform === 'linux') { + return require('./backends/linux.js') + } } catch { return null } + return null } -const darwin = loadDarwin() +const backend = loadBackend() export class ComputerUseAPI { - apps = darwin?.apps ?? { + apps = backend?.apps ?? { async prepareDisplay() { return { activated: '', hidden: [] } }, async previewHideSet() { return [] }, async findWindowDisplays(ids: string[]) { return ids.map((b: string) => ({ bundleId: b, displayIds: [] as number[] })) }, @@ -42,12 +48,12 @@ export class ComputerUseAPI { async unhide() {}, } - display = darwin?.display ?? { + display = backend?.display ?? { getSize() { throw new Error('@ant/computer-use-swift: macOS only') }, listAll() { throw new Error('@ant/computer-use-swift: macOS only') }, } - screenshot = darwin?.screenshot ?? { + screenshot = backend?.screenshot ?? { async captureExcluding() { throw new Error('@ant/computer-use-swift: macOS only') }, async captureRegion() { throw new Error('@ant/computer-use-swift: macOS only') }, } diff --git a/src/main.tsx b/src/main.tsx index b382aee15..5ceb6405d 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -2434,7 +2434,7 @@ async function run(): Promise { // shipped without incident; chicago places itself correctly. if ( feature('CHICAGO_MCP') && - getPlatform() === 'macos' && + getPlatform() !== 'unknown' && !getIsNonInteractiveSession() ) { try { diff --git a/src/utils/computerUse/swiftLoader.ts b/src/utils/computerUse/swiftLoader.ts index 95e5ead7e..0d8d7908a 100644 --- a/src/utils/computerUse/swiftLoader.ts +++ b/src/utils/computerUse/swiftLoader.ts @@ -7,9 +7,6 @@ let cached: ComputerUseAPI | undefined * Non-darwin platforms should use src/utils/computerUse/platforms/ instead. */ export function requireComputerUseSwift(): ComputerUseAPI { - if (process.platform !== 'darwin') { - throw new Error('@ant/computer-use-swift is macOS-only. Use platforms/ for cross-platform.') - } if (cached) return cached // eslint-disable-next-line @typescript-eslint/no-require-imports const mod = require('@ant/computer-use-swift')