From ca086b045aa8f947fcfc3309393a20c6cb70b83e Mon Sep 17 00:00:00 2001 From: unraid Date: Sat, 4 Apr 2026 00:09:51 +0800 Subject: [PATCH] fix: resolve Windows Computer Use request_access and screenshot errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two root causes fixed: 1. swiftLoader.ts: require('@ant/computer-use-swift') returns a module with { ComputerUseAPI } class, not an instance. macOS native .node exports a plain object. Fixed by detecting class export and calling new ComputerUseAPI(). 2. executor.ts resolvePrepareCapture: toolCalls.ts expects result to have { hidden: string[], displayId: number } fields. Our ComputerUseAPI returns { base64, width, height } only. Fixed by backfilling missing fields with defaults. Verified: request_access → screenshot → left_click all work on Windows. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/utils/computerUse/executor.ts | 10 +++++++++- src/utils/computerUse/swiftLoader.ts | 11 ++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/utils/computerUse/executor.ts b/src/utils/computerUse/executor.ts index ef8ce1207..2b6c9ade1 100644 --- a/src/utils/computerUse/executor.ts +++ b/src/utils/computerUse/executor.ts @@ -414,7 +414,7 @@ export function createCliExecutor(opts: { d.height, d.scaleFactor, ) - return drainRunLoop(() => + const raw = await drainRunLoop(() => cu.resolvePrepareCapture( withoutTerminal(opts.allowedBundleIds), surrogateHost, @@ -426,6 +426,14 @@ export function createCliExecutor(opts: { opts.doHide, ), ) + // Ensure the result has fields expected by toolCalls.ts (hidden, displayId). + // macOS native returns these from Swift; our cross-platform ComputerUseAPI + // returns {base64, width, height} — fill in the missing fields. + return { + ...raw, + hidden: (raw as any).hidden ?? [], + displayId: (raw as any).displayId ?? opts.preferredDisplayId ?? d.displayId, + } }, /** diff --git a/src/utils/computerUse/swiftLoader.ts b/src/utils/computerUse/swiftLoader.ts index 5a80a83f7..0fcc23fea 100644 --- a/src/utils/computerUse/swiftLoader.ts +++ b/src/utils/computerUse/swiftLoader.ts @@ -13,8 +13,17 @@ let cached: ComputerUseAPI | undefined * these in drainRunLoop(). */ export function requireComputerUseSwift(): ComputerUseAPI { + if (cached) return cached // eslint-disable-next-line @typescript-eslint/no-require-imports - return (cached ??= require('@ant/computer-use-swift') as ComputerUseAPI) + const mod = require('@ant/computer-use-swift') + // macOS native .node exports a plain object with apps/display/screenshot directly. + // Our cross-platform package exports { ComputerUseAPI } class — needs instantiation. + if (mod.ComputerUseAPI && typeof mod.ComputerUseAPI === 'function') { + cached = new mod.ComputerUseAPI() as ComputerUseAPI + } else { + cached = mod as ComputerUseAPI + } + return cached } export type { ComputerUseAPI }