Files
memind/wechat/intent/page-continuation.mjs
T
john 7eedda092d
Memind CI / Test, build, and release guards (push) Successful in 2m37s
fix: broaden WeChat session page continuation phrasing
Recognize retry, HTML page, page edits, and poem content edits as session continuations so delivery skips fresh-thumbnail forcing and retains agent context for multi-turn page work.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-28 16:54:42 +08:00

70 lines
3.3 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;
export function isWechatPageRetryText(text) {
const normalized = String(text ?? '').trim();
return Boolean(normalized && PAGE_RETRY_PATTERN.test(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 (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)
);
}