Files
memind/wechat/intent/page-continuation.mjs
T
john b9f5720ce0
Memind CI / Test, build, and release guards (push) Failing after 4s
fix(wechat): recognize news page intents and harden scheduled task delivery
Expand page.generate rules for post-page verbs and link-missing retries,
recover HTML artifacts when shadow LLM agrees, and stop marking scheduled
tasks failed when WeChat notification hits rate limits.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-02 06:46:37 +08:00

82 lines
3.7 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.
/** WeChat short follow-ups that continue an in-session page or poem without a full new topic. */
const PAGE_DECORATORS =
'(?:精美(?:的)?|漂亮(?:的)?|好看(?:的)?|简约(?:的)?|优雅(?:的)?)';
export const PAGE_RETRY_PATTERN =
/^(?:(?:请|麻烦|可以|能不能)\s*)?(?:(?:帮我|帮忙|给我)\s*)?重试(?:上次|上一个)?页面[。.!\s]*$/iu;
export const PAGE_EDIT_PATTERN =
/^(?:(?:请|麻烦|可以|能不能)\s*)?(?:(?:帮我|帮忙|给我)\s*)?(?:(?:把|将)\s*)?(?:(?:这个|刚才(?:的)?|上面(?:的)?|前面(?:的)?|上一条|它|刚才(?:生成|做|弄)(?:的)?|上面(?:生成|做|弄)(?:的)?)\s*)?(?:的)?\s*(?:页面|网页|html)?\s*(?:的)?\s*(?:内容|标题|背景|样式|排版|封面|页脚|字体|颜色)?\s*(?:改|修改|调整|更新|换|优化|美化)/iu;
export const PAGE_IMMEDIATE_CREATE_PATTERN =
new RegExp(
'^'
+ '(?:(?:请|麻烦|可以|能不能)\\s*)?'
+ '(?:(?:帮我|帮忙|给我)\\s*)?'
+ '(?:(?:把\\s*)?(?:这个|刚才(?:的)?(?:诗|文章|内容)?|上面(?:的)?|前面(?:的)?|上一条|它|这首(?:诗)?|这篇(?:文章)?|这段(?:内容)?)\\s*)?'
+ '(?:继续\\s*)?'
+ '(?:做|弄|改|转|写|排版|生成|制作)(?:成|为)?\\s*'
+ '(?:一个|个)?'
+ '(?:(?:\\s*'
+ PAGE_DECORATORS
+ '){1,3}\\s*(?:h5|html)|(?:\\s*(?:h5|html)))?'
+ '\\s*(?:页面|网页)(?:吧|呀|呢|一下)?[。.!\\s]*'
+ '$',
'iu',
);
export const PAGE_CONTENT_EDIT_PATTERN =
/^(?:(?:请|麻烦|可以|能不能)\s*)?(?:(?:帮我|帮忙|给我)\s*)?(?:(?:把|将)\s*)?(?:(?:这个|刚才(?:的)?|上面(?:的)?|前面(?:的)?|它|这首(?:诗)?|这篇(?:文章)?|这段(?:内容)?|诗(?:里|中)?)\s*)?(?:的)?\s*(?:[\p{L}\p{N}]{0,12}\s*)?(?:改|修改|调整|更新|换|加长|缩短|润色)/iu;
const PAGE_LINK_MISSING_RETRY_PATTERN =
/(?:页面|链接|新闻页|新闻页面|html).{0,16}(?:没有生成|没生成|未生成|没发|未发)/iu;
export function isWechatPageLinkRetryText(text) {
const normalized = String(text ?? '').trim();
return Boolean(normalized && PAGE_LINK_MISSING_RETRY_PATTERN.test(normalized));
}
export function isWechatPageRetryText(text) {
const normalized = String(text ?? '').trim();
return Boolean(
normalized
&& (PAGE_RETRY_PATTERN.test(normalized) || isWechatPageLinkRetryText(normalized)),
);
}
export function isWechatPageEditText(text) {
const normalized = String(text ?? '').trim();
return Boolean(normalized && PAGE_EDIT_PATTERN.test(normalized));
}
export function isWechatContentEditFollowup(text) {
const normalized = String(text ?? '').trim();
return Boolean(normalized && PAGE_CONTENT_EDIT_PATTERN.test(normalized));
}
export function isWechatImmediateContextPageCreate(wechatIntent, text) {
if (wechatIntent?.kind !== 'page.generate') return false;
const normalized = String(text ?? '').trim();
return Boolean(normalized && PAGE_IMMEDIATE_CREATE_PATTERN.test(normalized));
}
export function isWechatSessionPageContinuation(wechatIntent, text) {
const normalized = String(text ?? '').trim();
if (!normalized) return false;
if (isWechatPageLinkRetryText(normalized)) return true;
if (isWechatPageRetryText(normalized)) return true;
if (isWechatImmediateContextPageCreate(wechatIntent, normalized)) return true;
if (wechatIntent?.kind === 'page.generate' && isWechatPageEditText(normalized)) return true;
if (wechatIntent?.kind === 'chat.general' && isWechatContentEditFollowup(normalized)) return true;
return false;
}
export function expectsWechatHtmlArtifactDelivery(wechatIntent, text) {
const normalized = String(text ?? '').trim();
return (
wechatIntent?.kind === 'page.generate'
|| isWechatSessionPageContinuation(wechatIntent, normalized)
);
}