Files
memind/wechat/handlers/scheduled-task.mjs
T
john e13df82021
Memind CI / Test, build, and release guards (push) Failing after 14m19s
fix(wechat): pass inbound messages to goose and gate side effects at MCP tools
Stop ITL regex from intercepting new messages before Agent execution; move
scheduled task and schedule write confirmation to MCP tool calls with draft commit on 确认.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-28 22:16:23 +08:00

61 lines
1.7 KiB
JavaScript

import {
formatScheduledTaskListReply,
isScheduledTaskIntent,
parseScheduledTaskIntent,
} from '../../scheduled-task-intent.mjs';
const WEEKDAY_NAMES = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'];
export async function handleWechatScheduledTaskIntent({
intent,
user,
scheduledTaskService,
env = process.env,
logger = console,
}) {
if (!scheduledTaskService) return null;
const timezone = env.H5_DEFAULT_TIMEZONE || 'Asia/Shanghai';
const taskIntent = parseScheduledTaskIntent(intent.agentText, {
timezone,
});
if (!isScheduledTaskIntent(taskIntent)) return null;
try {
if (taskIntent.action === 'list_scheduled_tasks') {
const tasks = await scheduledTaskService.listTasks({
userId: user.userId,
status: 'active',
limit: 20,
});
return formatScheduledTaskListReply(tasks);
}
if (taskIntent.action === 'cancel_scheduled_task') {
const titleMatch = String(intent.agentText ?? '')
.replace(/(?:取消|停止|关闭|删除|我的|定时|自动|任务)/gu, ' ')
.trim();
if (!titleMatch) {
return '请告诉我要取消哪一条定时任务,或提供任务名称关键词。';
}
const task = await scheduledTaskService.cancelTask({
userId: user.userId,
titleMatch,
});
return `已取消定时任务:${task.title}`;
}
if (taskIntent.action === 'create_scheduled_task') {
return null;
}
} catch (err) {
logger.warn?.(
'[wechat-scheduled-task] preflight failed:',
err instanceof Error ? err.message : err,
);
return `定时任务设置失败:${err instanceof Error ? err.message : String(err)}`;
}
return null;
}