fix: computer use

This commit is contained in:
oboard
2026-03-31 19:56:09 +08:00
parent 73b53870f6
commit 2c185b8470
4 changed files with 388 additions and 17 deletions

View File

@@ -5,6 +5,17 @@ import type {
let cached: ComputerUseInputAPI | undefined
function unwrapDefaultExport<T>(mod: T | { default: T }): T {
return (
typeof mod === 'object' &&
mod !== null &&
'default' in mod &&
mod.default !== undefined
? mod.default
: mod
) as T
}
/**
* Package's js/index.js reads COMPUTER_USE_INPUT_NODE_PATH (baked by
* build-with-plugins.ts on darwin targets, unset otherwise — falls through to
@@ -22,7 +33,11 @@ let cached: ComputerUseInputAPI | undefined
export function requireComputerUseInput(): ComputerUseInputAPI {
if (cached) return cached
// eslint-disable-next-line @typescript-eslint/no-require-imports
const input = require('@ant/computer-use-input') as ComputerUseInput
const input = unwrapDefaultExport(
require('@ant/computer-use-input') as ComputerUseInput | {
default: ComputerUseInput
},
)
if (!input.isSupported) {
throw new Error('@ant/computer-use-input is not supported on this platform')
}

View File

@@ -2,6 +2,17 @@ import type { ComputerUseAPI } from '@ant/computer-use-swift'
let cached: ComputerUseAPI | undefined
function unwrapDefaultExport<T>(mod: T | { default: T }): T {
return (
typeof mod === 'object' &&
mod !== null &&
'default' in mod &&
mod.default !== undefined
? mod.default
: mod
) as T
}
/**
* Package's js/index.js reads COMPUTER_USE_SWIFT_NODE_PATH (baked by
* build-with-plugins.ts on darwin targets, unset otherwise — falls through to
@@ -17,7 +28,12 @@ export function requireComputerUseSwift(): ComputerUseAPI {
throw new Error('@ant/computer-use-swift is macOS-only')
}
// eslint-disable-next-line @typescript-eslint/no-require-imports
return (cached ??= require('@ant/computer-use-swift') as ComputerUseAPI)
return (cached ??=
unwrapDefaultExport(
require('@ant/computer-use-swift') as ComputerUseAPI | {
default: ComputerUseAPI
},
))
}
export type { ComputerUseAPI }