Files
memind/schedule-intent.mjs
T
john 229805a070 Improve WeChat MP replies and ship MindSpace/H5 production updates.
Add WeChat service account routing with sync acks, connectivity tests, and context isolation; document deploy runbooks; and bundle related MindSpace, voice, Plaza, and server gateway changes for production rollout.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-19 23:06:43 +08:00

76 lines
2.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
function normalizeText(text) {
return String(text ?? '').replace(/\s+/g, '').trim();
}
function chineseHourToNumber(value) {
const raw = String(value ?? '').trim();
if (/^\d{1,2}$/.test(raw)) return Number(raw);
const map = {
: 0,
: 1,
: 2,
: 2,
: 3,
: 4,
: 5,
: 6,
: 7,
: 8,
: 9,
: 10,
};
if (raw === '十') return 10;
if (raw.startsWith('十')) return 10 + (map[raw.slice(1)] ?? 0);
if (raw.endsWith('十')) return (map[raw[0]] ?? 0) * 10;
if (raw.includes('十')) {
const [tens, ones] = raw.split('十');
return (map[tens] ?? 1) * 10 + (map[ones] ?? 0);
}
return map[raw] ?? null;
}
function parseHourMinute(text) {
const match = text.match(/(?:早上|上午|清晨|每天早上|每天上午)?([0-9]{1,2}|[零一二两三四五六七八九十]{1,3})(?:点|:|)(半|[0-9]{1,2}分?)?/);
if (!match) return null;
const hour = chineseHourToNumber(match[1]);
if (hour === null || hour < 0 || hour > 23) return null;
let minute = 0;
if (match[2] === '半') minute = 30;
else if (match[2]) minute = Number(String(match[2]).replace('分', ''));
if (!Number.isFinite(minute) || minute < 0 || minute > 59) return null;
return { hour, minute };
}
export function parseScheduleIntent(text) {
const compact = normalizeText(text);
if (!compact) return { action: 'none' };
const wantsDaily = /每天|每日|天天/.test(compact);
const wantsTodoDigest = /(待办|todo|任务).*(记录|列表|清单|安排|摘要)|一天的待办/.test(compact);
const wantsSend = /发|发送|推送|提醒|通知|给我/.test(compact);
if (wantsDaily && wantsTodoDigest && wantsSend) {
const time = parseHourMinute(compact);
if (!time) {
return {
action: 'create_daily_todo_digest',
needsClarification: ['digest_time'],
};
}
return {
action: 'create_daily_todo_digest',
hour: time.hour,
minute: time.minute,
};
}
if (/看看|查看|看下|列出/.test(compact) && /(待办|日程|行程|计划|任务)/.test(compact)) {
return { action: 'query_schedule' };
}
return { action: 'none' };
}
export function isScheduleIntent(intent) {
return intent?.action && intent.action !== 'none';
}