mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-16 16:30:15 +01:00
fix: Refine response message handling in useStepHandler
- Updated logic to determine the appropriate response message based on the last message's origin, ensuring correct message replacement or appending based on user interaction. This change enhances the accuracy of message updates in the chat flow.
This commit is contained in:
parent
f8bb0d955d
commit
5ff66f2d77
1 changed files with 10 additions and 2 deletions
|
|
@ -232,7 +232,12 @@ export default function useStepHandler({
|
|||
let response = messageMap.current.get(responseMessageId);
|
||||
|
||||
if (!response) {
|
||||
const responseMessage = messages[messages.length - 1] as TMessage;
|
||||
// Find the actual response message - check if last message is a response, otherwise use initialResponse
|
||||
const lastMessage = messages[messages.length - 1] as TMessage;
|
||||
const responseMessage =
|
||||
lastMessage && !lastMessage.isCreatedByUser
|
||||
? lastMessage
|
||||
: (submission?.initialResponse as TMessage);
|
||||
|
||||
// Preserve existing content from DB (partial response) and prepend initialContent if provided
|
||||
const existingContent = responseMessage?.content ?? [];
|
||||
|
|
@ -248,7 +253,10 @@ export default function useStepHandler({
|
|||
};
|
||||
|
||||
messageMap.current.set(responseMessageId, response);
|
||||
setMessages([...messages.slice(0, -1), response]);
|
||||
// If last message was user message, append response; otherwise replace last
|
||||
const baseMessages =
|
||||
lastMessage && !lastMessage.isCreatedByUser ? messages.slice(0, -1) : messages;
|
||||
setMessages([...baseMessages, response]);
|
||||
}
|
||||
|
||||
// Store tool call IDs if present
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue