export type ComputerAutomationIntent = | { needed: true; source: 'explicit-current' | 'continuation'; reason: string } | { needed: false; source: 'none'; reason: string }; export interface ComputerAutomationContinuationState { lastUsedAt: number; } const CONTINUATION_WINDOW_MS = 30 * 60_000; const CONTINUATION_ONLY = /^(?:请)?(?:继续|接着(?:做|操作)?|重试|再试一次|往下做|恢复操作)[。!!\s]*$/i; const DIRECT_DESKTOP = /(?:操作(?:电脑|桌面|屏幕|窗口|系统|本机)|电脑自动化|桌面自动化|查看(?:当前)?(?:桌面|屏幕|前台窗口)|截(?:取)?(?:当前)?屏|系统设置|控制面板|任务管理器|资源管理器|访达|Finder)/i; const GUI_ACTION = /(?:点击|双击|右键|拖拽|滚动|输入|粘贴|按(?:键|快捷键)|切换|激活|关闭|移动|调整窗口|发送|发消息|发给|发布|上传)/i; const APP_TARGET = /(?:在|用|打开|切换到|进入)[^,。\n]{0,28}(?:应用|软件|客户端|微信|WeChat|钉钉|飞书|Slack|QQ|邮件|Outlook|Word|Excel|PowerPoint|设置|窗口)(?:里|中|上|内|给|向|并|,|。|\s|$)/i; const DISCUSSION_ONLY = /(?:解释|介绍|讨论|分析|评审|代码|源码|实现|设计|为什么|是什么|如何实现|测试.*ComputerUse|ComputerUse.*测试)/i; const DIRECT_TOOL_TASK = /(?:读取|分析|查看|理解).{0,12}(?:图片|照片|截图文件|PDF|文件|附件)|(?:搜索|修改|编写|重构|构建|运行测试|查找).{0,12}(?:代码|文件|网页)|(?:搜索网页|打开网址|访问网站|网页中)/i; /** * Conservative, deterministic exposure classifier. It only consumes the * current human input and a short-lived record of a real prior ComputerUse * call; model output, page content, and tool arguments can never enable it. */ export function classifyComputerAutomationIntent( input: string, continuation?: ComputerAutomationContinuationState, now = Date.now(), ): ComputerAutomationIntent { const text = input.trim(); if ( continuation && now - continuation.lastUsedAt <= CONTINUATION_WINDOW_MS && CONTINUATION_ONLY.test(text) ) { return { needed: true, source: 'continuation', reason: '继续最近一次桌面自动化任务' }; } if (!text) return { needed: false, source: 'none', reason: '没有桌面操作请求' }; if (DIRECT_TOOL_TASK.test(text) && !DIRECT_DESKTOP.test(text)) { return { needed: false, source: 'none', reason: '专用文件、图片或 Web 工具可直接完成' }; } if (DISCUSSION_ONLY.test(text) && !DIRECT_DESKTOP.test(text) && !GUI_ACTION.test(text)) { return { needed: false, source: 'none', reason: '仅讨论桌面能力,没有要求实际操作' }; } if (DIRECT_DESKTOP.test(text) || (GUI_ACTION.test(text) && APP_TARGET.test(text))) { return { needed: true, source: 'explicit-current', reason: '用户明确要求操作原生桌面界面' }; } return { needed: false, source: 'none', reason: '未发现明确的原生桌面操作意图' }; }