fix(wechat): isolate stale images and page links
Memind CI / Test, build, and release guards (pull_request) Successful in 2m36s

This commit is contained in:
john
2026-07-22 13:30:44 +08:00
parent aea3c1e83e
commit db225b784e
11 changed files with 416 additions and 37 deletions
+22 -6
View File
@@ -1591,7 +1591,7 @@ export function createTkmindProxy({
async function syncHistoricalImageTurnIsolation(sessionId, activeMessageId) {
const activeId = String(activeMessageId ?? '').trim();
if (!sessionId || !activeId) return;
if (!sessionId || !activeId) return { changed: false, updated: false };
try {
const target = await resolveTarget(sessionId);
const upstream = await apiFetch(
@@ -1599,13 +1599,15 @@ export function createTkmindProxy({
apiSecret,
`/sessions/${encodeURIComponent(sessionId)}`,
);
if (!upstream.ok) return;
if (!upstream.ok) {
return { changed: false, updated: false, status: upstream.status };
}
const session = await upstream.json().catch(() => null);
const { conversation, changed } = scrubConversationHistoricalImageAttachments(
session?.conversation ?? [],
activeId,
);
if (!changed) return;
if (!changed) return { changed: false, updated: false };
const update = await apiFetch(
target,
apiSecret,
@@ -1619,12 +1621,15 @@ export function createTkmindProxy({
console.warn(
`Historical image scrub skipped for session ${sessionId}: upstream ${update.status}`,
);
return { changed: true, updated: false, status: update.status };
}
return { changed: true, updated: true, status: update.status };
} catch (err) {
console.warn(
'Historical image scrub skipped:',
err instanceof Error ? err.message : err,
);
return { changed: false, updated: false, error: err };
}
}
@@ -1633,7 +1638,11 @@ export function createTkmindProxy({
sessionId,
requestId,
userMessage,
{ toolMode = 'chat', forceDeepReasoning = false } = {},
{
toolMode = 'chat',
forceDeepReasoning = false,
requireHistoricalImageIsolation = false,
} = {},
) {
if (!userId || !sessionId) throw new Error('缺少会话信息');
const owns = await sessionStore.validateOwnership(userId, sessionId);
@@ -1655,8 +1664,15 @@ export function createTkmindProxy({
const user = await userAuth.getUserById(userId);
if (!user) throw new Error('用户不存在');
if (messageHasImages(userMessage)) {
await syncHistoricalImageTurnIsolation(sessionId, userMessage?.id);
if (requireHistoricalImageIsolation || messageHasImages(userMessage)) {
const imageIsolation = await syncHistoricalImageTurnIsolation(sessionId, userMessage?.id);
if (requireHistoricalImageIsolation && imageIsolation.changed && !imageIsolation.updated) {
const error = new Error(
`historical_image_session_update_unsupported:${imageIsolation.status ?? 'unknown'}`,
);
error.code = 'HISTORICAL_IMAGE_SESSION_UPDATE_UNSUPPORTED';
throw error;
}
}
let finalUserMessage = userMessage;
if (llmProviderService && messageHasImages(userMessage) && await llmProviderService.hasVisionKey()) {