d58dc2a251
Introduce Draft → Confirm → Commit flow for WeChat schedule intents behind feature flags, plus h5_tasks dual-write/read aggregation and rollout scripts so reminders and automations get explicit user confirmation before persisting. Co-authored-by: Cursor <cursoragent@cursor.com>
91 lines
4.2 KiB
JavaScript
91 lines
4.2 KiB
JavaScript
export function formatIntentActionCard({
|
||
title,
|
||
layer,
|
||
actionLevel = 1,
|
||
trigger = null,
|
||
actions = [],
|
||
frequency = null,
|
||
clarify = null,
|
||
} = {}) {
|
||
if (clarify?.length) {
|
||
if (clarify.includes('reminder_title') && !clarify.includes('reminder_time')) {
|
||
return '可以。请告诉我要提醒什么,例如「下午 2 点半项目计划例会」。';
|
||
}
|
||
if (clarify.includes('reminder_time') && !clarify.includes('reminder_title')) {
|
||
return '可以。请告诉我要几点提醒,例如「下午 2 点半」。';
|
||
}
|
||
if (clarify.includes('reminder_time') && clarify.includes('reminder_title')) {
|
||
return '可以。请补充提醒时间和内容,例如「下午 2 点半项目计划例会」。';
|
||
}
|
||
if (clarify.includes('todo_title')) {
|
||
return '可以。请告诉我要记录什么待办,例如「跟进合同」。';
|
||
}
|
||
if (clarify.includes('digest_time')) {
|
||
return '可以。请告诉我想几点收到待办摘要,例如「每天早上 7 点」。';
|
||
}
|
||
if (clarify.includes('threshold')) {
|
||
return '可以。请告诉我余额低于多少元时提醒,例如「余额低于 20 元提醒我」。';
|
||
}
|
||
if (clarify.includes('schedule') && !clarify.includes('task_spec')) {
|
||
return '可以。请告诉我想几点执行,例如「每天 6 点」或「今晚 21:45」。';
|
||
}
|
||
if (clarify.includes('task_spec') && !clarify.includes('schedule')) {
|
||
return '可以。到点需要自动执行什么?例如「搜索并生成今日新闻页面」。';
|
||
}
|
||
if (clarify.includes('task_spec') && clarify.includes('schedule')) {
|
||
return '可以。请告诉我具体执行时间和任务内容,例如「每天 6 点帮我做今日新闻页面」。';
|
||
}
|
||
if (clarify.includes('weekday')) {
|
||
return '可以。这是每周任务,请告诉我是周几、几点执行,例如「每周一 7 点整理待办摘要」。';
|
||
}
|
||
if (clarify.includes('notify_vs_act') || clarify.includes('task_spec')) {
|
||
return [
|
||
'我需要确认一下你的意图:',
|
||
'1️⃣ 到点 **提醒你**(微信通知)',
|
||
'2️⃣ 到点 **自动执行并交付结果**(例如生成页面/日报)',
|
||
'请回复「提醒」或「自动执行」,并补充时间与内容。',
|
||
].join('\n');
|
||
}
|
||
return '可以。请补充具体时间和任务内容。';
|
||
}
|
||
|
||
const lines = ['🤖 我准备执行:', ''];
|
||
if (title) lines.push(`任务:${title}`);
|
||
if (actions.length) {
|
||
lines.push('动作:');
|
||
actions.forEach((step, index) => lines.push(`${index + 1}. ${step}`));
|
||
} else if (layer === 'L1') {
|
||
lines.push('动作:到点通过微信提醒你');
|
||
} else if (layer === 'L2') {
|
||
lines.push('动作:到点自动执行任务并推送结果');
|
||
}
|
||
if (trigger?.at) lines.push(`开始时间:${trigger.at}`);
|
||
else if (trigger?.hour != null) {
|
||
lines.push(`开始时间:${String(trigger.hour).padStart(2, '0')}:${String(trigger.minute ?? 0).padStart(2, '0')}`);
|
||
}
|
||
if (frequency) lines.push(`频率:${frequency}`);
|
||
if (actionLevel >= 3) lines.push('风险:高(涉及外发/第三方)');
|
||
else if (actionLevel >= 2) lines.push('风险:中(重复执行)');
|
||
lines.push('');
|
||
lines.push('回复「确认」执行,「取消」放弃,「修改」重新描述。');
|
||
return lines.join('\n');
|
||
}
|
||
|
||
export function formatDraftCommittedReply({ title, kind }) {
|
||
const label = kind === 'scheduled_task' ? '定时自动任务' : kind === 'timed_reminder' ? '提醒' : '任务';
|
||
return `已设置${label}:${title}。到点我会按约定通知或执行。`;
|
||
}
|
||
|
||
export function formatDraftCancelledReply() {
|
||
return '好的,已取消本次设置,没有写入任何提醒或任务。';
|
||
}
|
||
|
||
export function parseDraftUserReply(text) {
|
||
const compact = String(text ?? '').replace(/\s+/g, '').trim().toLowerCase();
|
||
if (!compact) return null;
|
||
if (/^(确认|确认执行|好的|可以|ok|yes|是|执行)$/.test(compact)) return 'confirm';
|
||
if (/^(取消|不要了|算了|否|no|不设置了)$/.test(compact)) return 'cancel';
|
||
if (/^(修改|改时间|改一下|更改|重新设置)$/.test(compact)) return 'modify';
|
||
return null;
|
||
}
|