Fix optimistic user message reconciliation

This commit is contained in:
Mohamed Boudra
2026-05-26 11:37:13 +07:00
parent 483790d8c9
commit a3071b46a4
4 changed files with 37 additions and 22 deletions
@@ -295,16 +295,15 @@ function mergeCanonicalUserWithOptimistic(
canonical: UserMessageItem,
optimistic: UserMessageItem,
): UserMessageItem {
const shouldPreserveImages =
(!canonical.images || canonical.images.length === 0) &&
Boolean(optimistic.images && optimistic.images.length > 0);
const shouldPreserveAttachments =
(!canonical.attachments || canonical.attachments.length === 0) &&
Boolean(optimistic.attachments && optimistic.attachments.length > 0);
return {
...canonical,
...(shouldPreserveImages ? { images: optimistic.images } : {}),
...(shouldPreserveAttachments ? { attachments: optimistic.attachments } : {}),
kind: "user_message",
id: canonical.id,
text: optimistic.text,
timestamp: optimistic.timestamp,
...(optimistic.images && optimistic.images.length > 0 ? { images: optimistic.images } : {}),
...(optimistic.attachments && optimistic.attachments.length > 0
? { attachments: optimistic.attachments }
: {}),
};
}