Skip to content

An AI-powered search engine with a generative UI

fix: reload chat after message deletion in regeneration flow

Yoshiki Miuradc1413444f1c
diff --git a/lib/streaming/helpers/prepare-messages.ts b/lib/streaming/helpers/prepare-messages.ts
index 6814f92a..a631252c 100644
--- a/lib/streaming/helpers/prepare-messages.ts
+++ b/lib/streaming/helpers/prepare-messages.ts
@@ -57,7 +57,9 @@ export async function prepareMessages(
const targetMessage = currentChat.messages[messageIndex]
if (targetMessage.role === 'assistant') {
await deleteMessagesFromIndex(chatId, messageId, userId)
- return currentChat.messages.slice(0, messageIndex)
+ // Reload chat to get the updated message list after deletion
+ const updatedChat = await loadChat(chatId, userId)
+ return updatedChat?.messages || currentChat.messages.slice(0, messageIndex)
} else {
// User message edit
if (message && message.id === messageId) {