feat: 升级 @ant/computer-use-mcp — 类型安全 stub + sentinel apps

- types.ts: 替换所有 any 为真实类型 (CoordinateMode, CuSubGates,
  Logger, GrantFlags, CuPermissionRequest/Response, ComputerUseHostAdapter)
- index.ts: 所有导出类型化 (DisplayGeometry, FrontmostApp, InstalledApp,
  RunningApp, ScreenshotResult, CuCallToolResult 等);
  targetImageSize() 实现真实缩放逻辑;
  bindSessionContext() 返回类型正确的空调度器
- sentinelApps.ts: 添加 10 个 macOS 敏感应用 (Terminal, iTerm2,
  Finder, System Preferences 等) 及其分类

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
claude-code-best
2026-04-01 08:36:12 +08:00
parent 975b4876cc
commit b51b2d7675
4 changed files with 255 additions and 33 deletions

View File

@@ -1,30 +1,163 @@
export const API_RESIZE_PARAMS: any = {}
/**
* @ant/computer-use-mcp — Stub 实现
*
* 提供类型安全的 stub所有函数返回合理的默认值。
* 在 feature('CHICAGO_MCP') = false 时不会被实际调用,
* 但确保 import 不报错且类型正确。
*/
export class ComputerExecutor {}
import type {
ComputerUseHostAdapter,
CoordinateMode,
GrantFlags,
Logger,
} from './types'
export type ComputerUseSessionContext = any
export type CuCallToolResult = any
export type CuPermissionRequest = any
export type CuPermissionResponse = any
export const DEFAULT_GRANT_FLAGS: any = {}
export type DisplayGeometry = any
export type FrontmostApp = any
export type InstalledApp = any
export type ResolvePrepareCaptureResult = any
export type RunningApp = any
export type ScreenshotDims = any
export type ScreenshotResult = any
// Re-export types from types.ts
export type { CoordinateMode, Logger } from './types'
export type {
ComputerUseConfig,
ComputerUseHostAdapter,
CuPermissionRequest,
CuPermissionResponse,
CuSubGates,
} from './types'
export { DEFAULT_GRANT_FLAGS } from './types'
export function bindSessionContext(..._args: any[]): any {
return null
// ---------------------------------------------------------------------------
// Types (defined here for callers that import from the main entry)
// ---------------------------------------------------------------------------
export interface DisplayGeometry {
width: number
height: number
displayId?: number
originX?: number
originY?: number
}
export function buildComputerUseTools(..._args: any[]): any[] {
export interface FrontmostApp {
bundleId: string
displayName: string
}
export interface InstalledApp {
bundleId: string
displayName: string
path: string
}
export interface RunningApp {
bundleId: string
displayName: string
}
export interface ScreenshotResult {
base64: string
width: number
height: number
}
export type ResolvePrepareCaptureResult = ScreenshotResult
export interface ScreenshotDims {
width: number
height: number
displayWidth: number
displayHeight: number
displayId: number
originX: number
originY: number
}
export interface CuCallToolResultContent {
type: 'image' | 'text'
data?: string
mimeType?: string
text?: string
}
export interface CuCallToolResult {
content: CuCallToolResultContent[]
telemetry: {
error_kind?: string
[key: string]: unknown
}
}
export type ComputerUseSessionContext = Record<string, unknown>
// ---------------------------------------------------------------------------
// API_RESIZE_PARAMS — 默认的截图缩放参数
// ---------------------------------------------------------------------------
export const API_RESIZE_PARAMS = {
maxWidth: 1280,
maxHeight: 800,
maxPixels: 1280 * 800,
}
// ---------------------------------------------------------------------------
// ComputerExecutor — stub class
// ---------------------------------------------------------------------------
export class ComputerExecutor {
capabilities: Record<string, boolean> = {}
}
// ---------------------------------------------------------------------------
// Functions — 返回合理默认值的 stub
// ---------------------------------------------------------------------------
/**
* 计算目标截图尺寸。
* 在物理宽高和 API 限制之间取最优尺寸。
*/
export function targetImageSize(
physW: number,
physH: number,
_params?: typeof API_RESIZE_PARAMS,
): [number, number] {
const maxW = _params?.maxWidth ?? 1280
const maxH = _params?.maxHeight ?? 800
const scale = Math.min(1, maxW / physW, maxH / physH)
return [Math.round(physW * scale), Math.round(physH * scale)]
}
/**
* 绑定会话上下文,返回工具调度函数。
* Stub 返回一个始终返回空结果的调度器。
*/
export function bindSessionContext(
_adapter: ComputerUseHostAdapter,
_coordinateMode: CoordinateMode,
_ctx: ComputerUseSessionContext,
): (name: string, args: unknown) => Promise<CuCallToolResult> {
return async (_name: string, _args: unknown) => ({
content: [],
telemetry: {},
})
}
/**
* 构建 Computer Use 工具定义列表。
* Stub 返回空数组(无工具)。
*/
export function buildComputerUseTools(
_capabilities?: Record<string, boolean>,
_coordinateMode?: CoordinateMode,
_installedAppNames?: string[],
): Array<{ name: string; description: string; inputSchema: Record<string, unknown> }> {
return []
}
export function createComputerUseMcpServer(..._args: any[]): any {
/**
* 创建 Computer Use MCP server。
* Stub 返回 null服务未启用
*/
export function createComputerUseMcpServer(
_adapter?: ComputerUseHostAdapter,
_coordinateMode?: CoordinateMode,
): null {
return null
}
export const targetImageSize: any = null