function normalizeText(text) { return String(text ?? '').replace(/\s+/g, '').trim(); } const EXECUTE_VERBS = /(?:做|生成|制作|创建|写|执行|跑|更新|整理|汇总|推送)/u; const SCHEDULE_MARKERS = /(?:定时(?:自动)?任务|scheduled\s*task|scheduled\s*automation|cron\s*job|recurring\s*task)/iu; const RECURRENCE_MARKERS = /(?:每天|每日|每周|定时|到点|届时|自动)/u; function wantsScheduledTaskAutomation(compact) { if (SCHEDULE_MARKERS.test(compact)) return true; if (!RECURRENCE_MARKERS.test(compact)) return false; if (!EXECUTE_VERBS.test(compact)) return false; // Pure reminders/digests stay on schedule-assistant or wechat schedule handler. if (/(?:提醒我|闹钟|待办记录|待办列表|待办清单|当天待办|一天的待办)/u.test(compact)) return false; if (/(?:待办|代办|带办|代拜).{0,8}(?:记录|列表|清单|摘要|汇总)/u.test(compact)) return false; return true; } export function shouldUseScheduledTaskAutomation(text) { const compact = normalizeText(text); if (!compact) return false; return wantsScheduledTaskAutomation(compact); } export function parseScheduledTaskIntent(text) { const compact = normalizeText(text); if (!compact) return { action: 'none' }; if (!wantsScheduledTaskAutomation(compact)) { return { action: 'none' }; } const wantsCancel = /(?:取消|停止|关闭|删除).{0,12}(?:定时|自动)/u.test(compact) || /(?:cancel|stop|disable).{0,12}(?:scheduled|automation|task)/iu.test(compact); if (wantsCancel) { return { action: 'cancel_scheduled_task' }; } const wantsList = /(?:查看|看看|列出|我的).{0,12}(?:定时|自动).{0,12}(?:任务|自动化)/u.test(compact) || /(?:list|show).{0,12}(?:scheduled|automation).{0,12}tasks/iu.test(compact); if (wantsList) { return { action: 'list_scheduled_tasks' }; } const recurrence = /(?:一次|单次|仅一次|once)/iu.test(compact) ? 'once' : /(?:每周|weekly)/iu.test(compact) ? 'weekly' : /(?:每天|每日|daily)/u.test(compact) ? 'daily' : null; const hasTaskSpec = EXECUTE_VERBS.test(compact) && !/^(?:帮我)?(?:设|设置|创建|添加)(?:一个|个)?定时(?:自动)?任务/u.test(String(text ?? '').trim()); const needsClarification = []; if (!recurrence && !/(?:明天|后天|今天|今晚|\d{1,2}[点::]|[零一二两三四五六七八九十]{1,3}点)/u.test(compact)) { needsClarification.push('schedule'); } if (!hasTaskSpec) { needsClarification.push('task_spec'); } if (needsClarification.length > 0) { return { action: 'create_scheduled_task', needsClarification, recurrence: recurrence ?? 'daily', }; } return { action: 'create_scheduled_task', recurrence: recurrence ?? 'daily', }; } export function isScheduledTaskIntent(intent) { return intent?.action && intent.action !== 'none'; }