Files
memind/wechat/handlers/scheduled-task.mjs
T
john a1a921eba6 fix(wechat): route scheduled task cancel and spec updates through Goose MCP
Pass cancel requests to Goose like create instead of inbound title matching,
and add scheduled_task_update_spec so format or execution constraints update
taskSpec without triggering page delivery guards.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-29 09:47:39 +08:00

48 lines
1.2 KiB
JavaScript

import {
formatScheduledTaskListReply,
isScheduledTaskIntent,
parseScheduledTaskIntent,
} from '../../scheduled-task-intent.mjs';
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 === 'create_scheduled_task'
|| taskIntent.action === 'cancel_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;
}