Update useChatStreamMessage.ts

This commit is contained in:
Nate Kelley 2025-03-05 22:55:01 -07:00
parent 74167c27a9
commit 0db64cd4a4
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
1 changed files with 24 additions and 12 deletions

View File

@ -157,19 +157,9 @@ export const useChatStreamMessage = () => {
if (!response_message?.id) return; if (!response_message?.id) return;
const responseMessageId = response_message.id; const responseMessageId = response_message.id;
const foundResponseMessage: BusterChatMessageResponse | undefined = const existingMessage =
chatRef.current[chat_id]?.messages?.[message_id]?.response_messages?.[responseMessageId]; chatRef.current[chat_id]?.messages?.[message_id]?.response_messages?.[responseMessageId];
const isNewMessage = !foundResponseMessage; const isNewMessage = !existingMessage;
if (response_message.type === 'text') {
const existingMessage =
(foundResponseMessage as BusterChatResponseMessage_text)?.message || '';
const isStreaming =
response_message.message_chunk !== undefined || response_message.message_chunk !== null;
if (isStreaming) {
response_message.message = existingMessage + response_message.message_chunk;
}
}
if (isNewMessage) { if (isNewMessage) {
initializeOrUpdateMessage(chat_id, message_id, (draft) => { initializeOrUpdateMessage(chat_id, message_id, (draft) => {
@ -182,6 +172,28 @@ export const useChatStreamMessage = () => {
}); });
} }
if (response_message.type === 'text') {
const existingResponseMessageText = existingMessage as BusterChatResponseMessage_text;
const isStreaming =
response_message.message_chunk !== undefined || response_message.message_chunk !== null;
initializeOrUpdateMessage(chat_id, message_id, (draft) => {
const responseMessage =
draft[chat_id]?.messages?.[message_id]?.response_messages?.[responseMessageId];
if (!responseMessage) return;
const messageText = responseMessage as BusterChatMessageReasoning_text;
Object.assign(messageText, {
...existingResponseMessageText,
...response_message,
message: isStreaming
? (existingResponseMessageText?.message || '') +
(response_message.message_chunk || '')
: response_message.message
});
});
}
const response_messages = chatRef.current[chat_id]?.messages?.[message_id]?.response_messages; const response_messages = chatRef.current[chat_id]?.messages?.[message_id]?.response_messages;
const response_message_ids = const response_message_ids =
chatRef.current[chat_id]?.messages?.[message_id]?.response_message_ids; chatRef.current[chat_id]?.messages?.[message_id]?.response_message_ids;