9dfafb99ca
Memind CI / Test, build, and release guards (push) Successful in 3m43s
Expand ASR normalization and colloquial reminder parsing so simple timed reminders route to L1 confirm cards instead of the agent, and disable schedule-guard false failures when ITL is enabled. Co-authored-by: Cursor <cursoragent@cursor.com>
50 lines
1.9 KiB
JavaScript
50 lines
1.9 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 function rewriteScheduleConfirmationWhenItlEnabled(replyText, { enabled = false } = {}) {
|
|
if (!enabled || !looksLikeScheduleConfirmation(replyText)) return replyText;
|
|
return [
|
|
'这类提醒需要你先确认卡片后才会写入。',
|
|
'请直接发完整安排(例如「每天18点提醒打卡」),我会先发确认卡片;回复「确认」后再生效。',
|
|
].join('\n');
|
|
}
|
|
|
|
export async function guardScheduleConfirmationReply({
|
|
replyText,
|
|
scheduleService,
|
|
userId,
|
|
sourceMessageId,
|
|
logger,
|
|
intentTransactionEnabled = false,
|
|
}) {
|
|
if (intentTransactionEnabled) {
|
|
return rewriteScheduleConfirmationWhenItlEnabled(replyText, { enabled: true });
|
|
}
|
|
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');
|
|
}
|