031c6e086a
Extract schedule, greeting/status/connectivity replies, chat-general prompt, and display-name helpers from wechat-mp.mjs. Route sync intents via classifyWechatIntent and add channel isolation CI check. Co-authored-by: Cursor <cursoragent@cursor.com>
38 lines
1.4 KiB
JavaScript
38 lines
1.4 KiB
JavaScript
export function looksLikeScheduleConfirmation(text) {
|
|
const compact = String(text ?? '').replace(/\s+/g, '');
|
|
if (!compact) return false;
|
|
if (/(没有|没能|未能|无法|不能|失败|需要你|请补充|请告诉)/.test(compact)) return false;
|
|
return /(已经|已|现在).{0,12}(设置|安排|记录|加上|添加|创建).{0,12}(待办|提醒|日程|安排|闹钟)|设置好了|已经设置好了|已经加上/.test(
|
|
compact,
|
|
);
|
|
}
|
|
|
|
export async function guardScheduleConfirmationReply({
|
|
replyText,
|
|
scheduleService,
|
|
userId,
|
|
sourceMessageId,
|
|
logger,
|
|
}) {
|
|
if (!scheduleService || !looksLikeScheduleConfirmation(replyText)) return replyText;
|
|
const messageId = String(sourceMessageId ?? '').trim();
|
|
if (!messageId || typeof scheduleService.listItemsBySourceMessage !== 'function') {
|
|
return replyText;
|
|
}
|
|
const items = await scheduleService
|
|
.listItemsBySourceMessage({
|
|
userId,
|
|
sourceMessageId: messageId,
|
|
limit: 5,
|
|
})
|
|
.catch((err) => {
|
|
logger?.warn?.('Schedule confirmation guard failed:', err);
|
|
return [];
|
|
});
|
|
if (items.length > 0) return replyText;
|
|
return [
|
|
'我刚才没有确认到待办/提醒已经写入系统,所以这次不能算设置成功。',
|
|
'请再发一次完整安排,比如“明天早上 6 点跑步,5 点半提醒我”。我会在工具写入成功后再确认。',
|
|
].join('\n');
|
|
}
|