fix(wechat): avoid image_url session poison on report follow-ups
Store image-only WeChat messages without running Agent, scrub assistant image_url history, and retry historical-image failures with text-only prompts. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+14
-10
@@ -122,11 +122,10 @@ export function detachCurrentTurnImagesForTextProvider(message, canonicalImageUr
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove image attachments from a persisted user message so later turns cannot reuse them.
|
||||
* UI displayText / previewImageUrls are preserved for chat history rendering.
|
||||
* Remove image attachments from a persisted message so later turns cannot reuse them.
|
||||
*/
|
||||
export function scrubUserMessageImageAttachments(message) {
|
||||
if (!message || message.role !== 'user') return { message, changed: false };
|
||||
function scrubPersistedImageAttachments(message) {
|
||||
if (!message) return { message, changed: false };
|
||||
|
||||
const metadata =
|
||||
message.metadata && typeof message.metadata === 'object' && !Array.isArray(message.metadata)
|
||||
@@ -153,15 +152,13 @@ export function scrubUserMessageImageAttachments(message) {
|
||||
return null;
|
||||
}
|
||||
if (item?.type !== 'text' || typeof item.text !== 'string') return item;
|
||||
const nextText = stripAgentImageText(item.text);
|
||||
const nextText = message.role === 'user' ? stripAgentImageText(item.text) : item.text;
|
||||
if (nextText === item.text) return item;
|
||||
contentChanged = true;
|
||||
return nextText ? { ...item, text: nextText } : null;
|
||||
}).filter(Boolean)
|
||||
: message.content;
|
||||
|
||||
const displayText =
|
||||
typeof metadata.displayText === 'string' ? metadata.displayText : null;
|
||||
const changed = hadImageMetadata || contentChanged;
|
||||
if (!changed) return { message, changed: false };
|
||||
|
||||
@@ -170,12 +167,20 @@ export function scrubUserMessageImageAttachments(message) {
|
||||
...message,
|
||||
content,
|
||||
metadata,
|
||||
...(displayText != null ? {} : {}),
|
||||
},
|
||||
changed: true,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove image attachments from a persisted user message so later turns cannot reuse them.
|
||||
* UI displayText / previewImageUrls are preserved for chat history rendering.
|
||||
*/
|
||||
export function scrubUserMessageImageAttachments(message) {
|
||||
if (!message || message.role !== 'user') return { message, changed: false };
|
||||
return scrubPersistedImageAttachments(message);
|
||||
}
|
||||
|
||||
export function messageContentHasImageUrl(content) {
|
||||
if (!Array.isArray(content)) return false;
|
||||
return content.some((item) => item?.type === 'image_url' && item?.image_url?.url);
|
||||
@@ -203,9 +208,8 @@ export function scrubConversationHistoricalImageAttachments(conversation, active
|
||||
|
||||
let changed = false;
|
||||
const nextConversation = conversation.map((message) => {
|
||||
if (message?.role !== 'user') return message;
|
||||
if (String(message?.id ?? '').trim() === activeId) return message;
|
||||
const scrubbed = scrubUserMessageImageAttachments(message);
|
||||
const scrubbed = scrubPersistedImageAttachments(message);
|
||||
if (scrubbed.changed) changed = true;
|
||||
return scrubbed.message;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user