fix: broaden WeChat session page continuation phrasing
Memind CI / Test, build, and release guards (push) Successful in 2m37s

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>
This commit is contained in:
john
2026-07-28 16:54:42 +08:00
parent 6307f974cf
commit 7eedda092d
9 changed files with 397 additions and 42 deletions
+30 -36
View File
@@ -31,6 +31,11 @@ import {
isPageDataDevIntent,
isPageDataIntent,
} from './chat-skills.mjs';
import {
isWechatImmediateContextPageCreate,
isWechatSessionPageContinuation,
isWechatContentEditFollowup,
} from './wechat/intent/page-continuation.mjs';
import { resolvePageGenerateOutcome } from './wechat/handlers/page-generate.mjs';
import {
buildWechatImageRunMetadata,
@@ -975,31 +980,12 @@ export function shouldForceNewWechatAgentSession(wechatIntent, resetCandidate) {
);
}
const WECHAT_IMMEDIATE_CONTEXT_PAGE_DECORATORS =
'(?:精美(?:的)?|漂亮(?:的)?|好看(?:的)?|简约(?:的)?|优雅(?:的)?)';
const WECHAT_IMMEDIATE_CONTEXT_PAGE_PATTERN =
new RegExp(
'^'
+ '(?:(?:请|麻烦|可以|能不能)\\s*)?'
+ '(?:(?:帮我|帮忙|给我)\\s*)?'
+ '(?:(?:把\\s*)?(?:这个|刚才(?:的)?(?:诗|文章|内容)?|上面(?:的)?|前面(?:的)?|上一条|它|这首(?:诗)?|这篇(?:文章)?|这段(?:内容)?)\\s*)?'
+ '(?:继续\\s*)?'
+ '(?:做|弄|改|转|写|排版|生成|制作)(?:成|为)?\\s*'
+ '(?:一个|个)?'
+ '(?:(?:\\s*'
+ WECHAT_IMMEDIATE_CONTEXT_PAGE_DECORATORS
+ '){1,3}\\s*(?:h5|html)|(?:\\s*(?:h5|html)))?'
+ '\\s*(?:页面|网页)(?:吧|呀|呢|一下)?[。.!\\s]*'
+ '$',
'iu',
);
export function isWechatImmediateContextFollowup(wechatIntent, text) {
if (wechatIntent?.kind !== 'page.generate') return false;
const normalized = String(text ?? '').trim();
return Boolean(normalized && WECHAT_IMMEDIATE_CONTEXT_PAGE_PATTERN.test(normalized));
return isWechatImmediateContextPageCreate(wechatIntent, text);
}
export { isWechatSessionPageContinuation };
export function shouldRotateUnlinkedWechatRoute({
routeUpdatedAt,
wechatMessageCount,
@@ -1035,10 +1021,12 @@ export function isRecoverableWechatAgentSessionError(message) {
}
export function shouldDeliverWechatHtmlArtifacts(wechatIntent, intent) {
const text = String(intent?.agentText ?? intent?.displayText ?? '').trim();
return (
wechatIntent?.kind === 'page.generate'
|| looksLikeHtmlGenerationIntent(intent?.agentText)
|| isPageDataIntent(intent?.agentText)
|| looksLikeHtmlGenerationIntent(text)
|| isPageDataIntent(text)
|| (wechatIntent?.kind === 'chat.general' && isWechatContentEditFollowup(text))
);
}
@@ -2443,13 +2431,13 @@ export function createWechatMpService({
intent.msgType === 'text' || intent.msgType === 'voice' ? intent.agentText : '';
const isPageDataRequest = isWechatPageDataTask(resetCandidate);
const htmlArtifactDeliveryExpected = shouldDeliverWechatHtmlArtifacts(wechatIntent, intent);
const immediateContextFollowup =
isWechatImmediateContextFollowup(wechatIntent, resetCandidate);
const sessionPageContinuation =
isWechatSessionPageContinuation(wechatIntent, resetCandidate);
const imagePolicy = resolveWechatImageGenerationPolicy({
text: resetCandidate,
isPageGenerate: wechatIntent.kind === 'page.generate',
requireFreshPageThumbnail:
config.requireFreshPageThumbnail && !immediateContextFollowup,
config.requireFreshPageThumbnail && !sessionPageContinuation,
});
// Page Data delivery owns persistent files, datasets and two publication
// policies. Reusing a conversational route here can make a new request
@@ -2460,7 +2448,7 @@ export function createWechatMpService({
openid: inbound.fromUserName,
userContext: user,
forceNew,
retainUnlinkedRoute: immediateContextFollowup,
retainUnlinkedRoute: sessionPageContinuation,
});
let sessionId = route.sessionId;
await ensureSessionProvider(sessionId);
@@ -2501,11 +2489,14 @@ export function createWechatMpService({
? buildPageGenerateAgentPrompt(intent, {
wantsDocx: wechatIntent.wantsDocx,
imagePolicy,
preferImmediateContext: immediateContextFollowup,
preferImmediateContext: sessionPageContinuation,
})
: buildWechatAgentPrompt(intent, { imagePolicy });
: buildWechatAgentPrompt(intent, {
imagePolicy,
preferSessionPageContinuation: sessionPageContinuation,
});
const maxImmediateContextPageAttempts =
wechatIntent.kind === 'page.generate' && immediateContextFollowup ? 2 : 1;
wechatIntent.kind === 'page.generate' && sessionPageContinuation ? 2 : 1;
let reply;
let publishArtifacts = [];
let confirmedArtifacts = [];
@@ -2531,7 +2522,7 @@ export function createWechatMpService({
userId: user.userId,
sessionId,
userMessage,
preserveAgentPrompt: immediateContextFollowup,
preserveAgentPrompt: sessionPageContinuation,
}),
submitReply: submitSessionReply
? ({ requestId: replyRequestId, userMessage }) =>
@@ -2773,7 +2764,7 @@ export function createWechatMpService({
sessionId
&& (isRecoverableWechatAgentSessionError(message) || isWechatAgentApiErrorText(message));
if (mayBeStaleSession) {
if (immediateContextFollowup) {
if (sessionPageContinuation) {
await userAuth.clearWechatAgentRoute(config.appId, inbound.fromUserName).catch((clearErr) => {
logger.warn?.('WeChat MP contextual follow-up route clear failed:', clearErr);
});
@@ -2804,9 +2795,12 @@ export function createWechatMpService({
? buildPageGenerateAgentPrompt(intent, {
wantsDocx: wechatIntent.wantsDocx,
imagePolicy,
preferImmediateContext: immediateContextFollowup,
preferImmediateContext: sessionPageContinuation,
})
: buildWechatAgentPrompt(intent, { imagePolicy });
: buildWechatAgentPrompt(intent, {
imagePolicy,
preferSessionPageContinuation: sessionPageContinuation,
});
const reply = await executeSessionReply(
(pathname, init) => fetchForSession(sessionId, pathname, init),
sessionId,
@@ -2822,7 +2816,7 @@ export function createWechatMpService({
userId: user.userId,
sessionId,
userMessage,
preserveAgentPrompt: immediateContextFollowup,
preserveAgentPrompt: sessionPageContinuation,
}),
submitReply: submitSessionReply
? ({ requestId: replyRequestId, userMessage }) =>