fix(router): route casual chat to DeepSeek and reserve Cursor for page tasks
Default unmatched conversation to direct_chat, stop blanket Agent session continuation and generic Agent→Cursor promotion; fix WeChat page retry userPublishDir scope and simplify ChatPanel controls. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+112
-29
@@ -6,6 +6,12 @@ import { mergeMessageContent } from './message-stream.mjs';
|
||||
import { reconcileAgentSession } from './session-reconcile.mjs';
|
||||
import { resolveSessionAccess } from './session-broker.mjs';
|
||||
import { loadWechatMpConfig } from './wechat-mp-config.mjs';
|
||||
import { executeWechatCursorAgentRun } from './wechat-cursor-agent-run.mjs';
|
||||
import { resolveWechatCursorExecutorEligible } from './wechat-cursor-executor-policy.mjs';
|
||||
import {
|
||||
isWechatCursorChannelReply,
|
||||
prepareWechatCursorPageDelivery,
|
||||
} from './wechat-cursor-page-delivery.mjs';
|
||||
import {
|
||||
downloadTemporaryMedia,
|
||||
persistWechatAttachment,
|
||||
@@ -532,6 +538,7 @@ function hasAnyToolRequest(messages = []) {
|
||||
}
|
||||
|
||||
function isSuspiciousBareCompletionReply(reply, intent) {
|
||||
if (isWechatCursorChannelReply(reply)) return false;
|
||||
if (!looksLikeHtmlGenerationIntent(intent?.agentText)) return false;
|
||||
if (!isBareCompletionText(reply?.text)) return false;
|
||||
if (extractHtmlWriteTargets(replyRequestMessages(reply)).length > 0) return false;
|
||||
@@ -575,6 +582,7 @@ async function isSuspiciousHtmlPublishClaimReply(reply, intent, { linkExists = d
|
||||
}
|
||||
|
||||
function isMissingRequiredPublishSkill(reply, intent) {
|
||||
if (isWechatCursorChannelReply(reply)) return false;
|
||||
if (!looksLikeHtmlGenerationIntent(intent?.agentText)) return false;
|
||||
const wroteHtml = extractHtmlWriteTargets(replyRequestMessages(reply)).length > 0;
|
||||
if (!wroteHtml) return false;
|
||||
@@ -1022,6 +1030,11 @@ export function shouldRetryHtmlGenerationReply({
|
||||
confirmedArtifacts = [],
|
||||
hasValidLinkInReply = false,
|
||||
}) {
|
||||
if (isWechatCursorChannelReply(reply)) {
|
||||
return nonStubHtmlArtifacts(confirmedArtifacts).length === 0
|
||||
&& !hasAnyPublicHtmlLinkInReply(reply);
|
||||
}
|
||||
|
||||
if (nonStubHtmlArtifacts(confirmedArtifacts).length > 0) return false;
|
||||
|
||||
const replyHasPublicLinks = hasAnyPublicHtmlLinkInReply(reply);
|
||||
@@ -1615,6 +1628,8 @@ export function createWechatMpService({
|
||||
htmlDeliveryAuthority = null,
|
||||
pageDataFinishGuard = null,
|
||||
pageDataDeliveryReviewer = null,
|
||||
wechatCursorExecutorPolicyService = null,
|
||||
agentRunGateway = null,
|
||||
wechatFetch = undiciFetch,
|
||||
linkExists = defaultPublicHtmlLinkExists,
|
||||
h5Root = '',
|
||||
@@ -2874,8 +2889,10 @@ export function createWechatMpService({
|
||||
logger,
|
||||
intentTransactionEnabled: isIntentTransactionEnabled(),
|
||||
});
|
||||
let userPublishDir = null;
|
||||
try {
|
||||
const requestStartedAt = Date.now();
|
||||
userPublishDir = await userAuth.resolveWorkingDir(user.userId);
|
||||
const agentPrompt =
|
||||
wechatIntent.kind === 'page.generate'
|
||||
? buildPageGenerateAgentPrompt(intent, {
|
||||
@@ -2900,36 +2917,97 @@ export function createWechatMpService({
|
||||
const activeAgentPrompt =
|
||||
pageAttempt === 1 ? agentPrompt : buildImmediateContextPageRepairPrompt(intent);
|
||||
const activeRequestId = pageAttempt === 1 ? requestId : crypto.randomUUID();
|
||||
reply = await executeSessionReply(
|
||||
(pathname, init) => fetchForSession(sessionId, pathname, init),
|
||||
sessionId,
|
||||
activeRequestId,
|
||||
activeAgentPrompt,
|
||||
buildIntentMetadata(intent, {
|
||||
mediaAnalysisEnabled,
|
||||
imagePolicy,
|
||||
pgRequired: isPageDataRequest,
|
||||
}),
|
||||
{
|
||||
prepareUserMessage: (userMessage) => prepareWechatAgentUserMessage({
|
||||
reply = null;
|
||||
let wechatCursorPolicy = null;
|
||||
if (
|
||||
pageAttempt === 1
|
||||
&& wechatCursorExecutorPolicyService?.getEffectivePolicy
|
||||
&& agentRunGateway
|
||||
) {
|
||||
try {
|
||||
wechatCursorPolicy = await wechatCursorExecutorPolicyService.getEffectivePolicy(
|
||||
user.userId,
|
||||
user,
|
||||
);
|
||||
} catch (policyErr) {
|
||||
logger.warn?.('WeChat MP cursor policy lookup failed:', policyErr);
|
||||
}
|
||||
}
|
||||
const useWechatCursorChannel = resolveWechatCursorExecutorEligible({
|
||||
user,
|
||||
intentKind: wechatIntent.kind,
|
||||
policy: wechatCursorPolicy,
|
||||
});
|
||||
if (useWechatCursorChannel) {
|
||||
try {
|
||||
reply = await executeWechatCursorAgentRun({
|
||||
agentRunGateway,
|
||||
userId: user.userId,
|
||||
sessionId,
|
||||
userMessage,
|
||||
preserveAgentPrompt: sessionPageContinuation,
|
||||
requestId: activeRequestId,
|
||||
displayText: String(intent?.displayText ?? intent?.agentText ?? '').trim(),
|
||||
agentPrompt: activeAgentPrompt,
|
||||
intentKind: wechatIntent.kind,
|
||||
timeoutMs: agentReplyTimeoutMs,
|
||||
logger,
|
||||
});
|
||||
const buildCanonicalUrl = (relativePath) => {
|
||||
const base = String(config.publicBaseUrl ?? '').replace(/\/+$/, '');
|
||||
const normalized = String(relativePath ?? '')
|
||||
.replace(/^\/+/, '')
|
||||
.split('/')
|
||||
.map(encodeURIComponent)
|
||||
.join('/');
|
||||
return `${base}/MindSpace/${encodeURIComponent(user.userId)}/${normalized}`;
|
||||
};
|
||||
reply = prepareWechatCursorPageDelivery({
|
||||
reply,
|
||||
intent,
|
||||
publishDir: userPublishDir,
|
||||
requestStartedAt,
|
||||
buildCanonicalUrl,
|
||||
topic: wechatIntent?.topic ?? intent?.agentText ?? '',
|
||||
});
|
||||
} catch (cursorErr) {
|
||||
logger.warn?.('WeChat MP cursor channel failed:', cursorErr);
|
||||
if (wechatCursorPolicy?.fallbackToDeepseek === false) {
|
||||
throw cursorErr;
|
||||
}
|
||||
reply = null;
|
||||
}
|
||||
}
|
||||
if (!reply) {
|
||||
reply = await executeSessionReply(
|
||||
(pathname, init) => fetchForSession(sessionId, pathname, init),
|
||||
sessionId,
|
||||
activeRequestId,
|
||||
activeAgentPrompt,
|
||||
buildIntentMetadata(intent, {
|
||||
mediaAnalysisEnabled,
|
||||
imagePolicy,
|
||||
pgRequired: isPageDataRequest,
|
||||
}),
|
||||
submitReply: submitSessionReply
|
||||
? ({ requestId: replyRequestId, userMessage }) =>
|
||||
submitSessionReply({
|
||||
userId: user.userId,
|
||||
sessionId,
|
||||
requestId: replyRequestId,
|
||||
userMessage,
|
||||
options: { requireHistoricalImageIsolation: true },
|
||||
})
|
||||
: null,
|
||||
timeoutMs: agentReplyTimeoutMs,
|
||||
},
|
||||
);
|
||||
{
|
||||
prepareUserMessage: (userMessage) => prepareWechatAgentUserMessage({
|
||||
userId: user.userId,
|
||||
sessionId,
|
||||
userMessage,
|
||||
preserveAgentPrompt: sessionPageContinuation,
|
||||
}),
|
||||
submitReply: submitSessionReply
|
||||
? ({ requestId: replyRequestId, userMessage }) =>
|
||||
submitSessionReply({
|
||||
userId: user.userId,
|
||||
sessionId,
|
||||
requestId: replyRequestId,
|
||||
userMessage,
|
||||
options: { requireHistoricalImageIsolation: true },
|
||||
})
|
||||
: null,
|
||||
timeoutMs: agentReplyTimeoutMs,
|
||||
},
|
||||
);
|
||||
}
|
||||
generatedImages = collectWechatGeneratedImages(replyRequestMessages(reply));
|
||||
if (imagePolicy.standaloneImageMode === 'required' && generatedImages.length === 0) {
|
||||
const error = new Error('图片生成没有获得本轮新的有效位图,请稍后重试');
|
||||
@@ -3003,8 +3081,9 @@ export function createWechatMpService({
|
||||
replyHasPublicLinks,
|
||||
topic: wechatIntent?.topic ?? intent?.agentText ?? '',
|
||||
repairContext: {
|
||||
publishDir: resolveUserPublishDir(user.userId),
|
||||
publishDir: userPublishDir,
|
||||
},
|
||||
wechatCursorChannel: isWechatCursorChannelReply(reply),
|
||||
});
|
||||
if (pageOutcome.action === 'session_retry') {
|
||||
if (sessionPageContinuation && pageAttempt < maxImmediateContextPageAttempts) {
|
||||
@@ -3293,6 +3372,9 @@ export function createWechatMpService({
|
||||
}
|
||||
const retryId = crypto.randomUUID();
|
||||
const retryStartedAt = Date.now();
|
||||
if (!userPublishDir) {
|
||||
userPublishDir = await userAuth.resolveWorkingDir(user.userId);
|
||||
}
|
||||
const retryPageContinuation = sessionPageContinuation && !historicalImageError;
|
||||
const retryPrompt =
|
||||
wechatIntent.kind === 'page.generate'
|
||||
@@ -3407,8 +3489,9 @@ export function createWechatMpService({
|
||||
replyHasPublicLinks,
|
||||
topic: wechatIntent?.topic ?? intent?.agentText ?? '',
|
||||
repairContext: {
|
||||
publishDir: resolveUserPublishDir(user.userId),
|
||||
publishDir: userPublishDir,
|
||||
},
|
||||
wechatCursorChannel: isWechatCursorChannelReply(reply),
|
||||
});
|
||||
if (pageOutcome.action === 'session_retry' || pageOutcome.action === 'fail') {
|
||||
const text = pageOutcome.failureText ?? buildPagePublishFailureText();
|
||||
|
||||
Reference in New Issue
Block a user