mirror of https://github.com/buster-so/buster.git
Update useChatStreamMessage.ts
This commit is contained in:
parent
d7430f1594
commit
21c320e739
|
@ -24,6 +24,7 @@ import { IBusterChat, IBusterChatMessage } from '../interfaces';
|
||||||
import { queryKeys } from '@/api/query_keys';
|
import { queryKeys } from '@/api/query_keys';
|
||||||
import { useQueryClient } from '@tanstack/react-query';
|
import { useQueryClient } from '@tanstack/react-query';
|
||||||
import { create } from 'mutative';
|
import { create } from 'mutative';
|
||||||
|
import files from '@/components/ui/icons/NucleoIconOutlined/files';
|
||||||
|
|
||||||
export const useChatStreamMessage = () => {
|
export const useChatStreamMessage = () => {
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
@ -41,9 +42,6 @@ export const useChatStreamMessage = () => {
|
||||||
Object.assign(draft || {}, chatMessage);
|
Object.assign(draft || {}, chatMessage);
|
||||||
})!;
|
})!;
|
||||||
|
|
||||||
const firstReasoningMessage = iChatMessage.reasoning_message_ids[0];
|
|
||||||
console.log(iChatMessage.reasoning_messages[firstReasoningMessage]);
|
|
||||||
|
|
||||||
onUpdateChatMessage(iChatMessage!);
|
onUpdateChatMessage(iChatMessage!);
|
||||||
|
|
||||||
startTransition(() => {
|
startTransition(() => {
|
||||||
|
@ -241,36 +239,53 @@ export const useChatStreamMessage = () => {
|
||||||
initializeOrUpdateMessage(chat_id, message_id, (draft) => {
|
initializeOrUpdateMessage(chat_id, message_id, (draft) => {
|
||||||
const chat = draft[chat_id];
|
const chat = draft[chat_id];
|
||||||
if (!chat?.messages?.[message_id]?.reasoning_messages?.[reasoningMessageId]) return;
|
if (!chat?.messages?.[message_id]?.reasoning_messages?.[reasoningMessageId]) return;
|
||||||
const messageFiles = chat.messages[message_id].reasoning_messages[
|
|
||||||
reasoningMessageId
|
|
||||||
] as BusterChatMessageReasoning_files;
|
|
||||||
messageFiles.file_ids = existingReasoningMessageFiles?.file_ids || [];
|
|
||||||
|
|
||||||
for (const fileId of reasoning.file_ids) {
|
const messageFiles = create(
|
||||||
if (!messageFiles.files[fileId]) {
|
chat.messages[message_id].reasoning_messages[
|
||||||
messageFiles.files[fileId] = {} as BusterChatMessageReasoning_file;
|
reasoningMessageId
|
||||||
messageFiles.file_ids.push(fileId);
|
] as BusterChatMessageReasoning_files,
|
||||||
|
(draft) => {
|
||||||
|
draft.file_ids = existingReasoningMessageFiles?.file_ids || [];
|
||||||
|
|
||||||
|
if (reasoning.status) draft.status = reasoning.status;
|
||||||
|
if (reasoning.title) draft.title = reasoning.title;
|
||||||
|
if (reasoning.secondary_title) draft.secondary_title = reasoning.secondary_title;
|
||||||
|
|
||||||
|
for (const fileId of reasoning.file_ids) {
|
||||||
|
if (!draft.files[fileId]) {
|
||||||
|
draft.files[fileId] = {} as BusterChatMessageReasoning_file;
|
||||||
|
draft.file_ids.push(fileId);
|
||||||
|
}
|
||||||
|
|
||||||
|
const existingFile = existingReasoningMessageFiles?.files[fileId];
|
||||||
|
const newFile = reasoning.files[fileId];
|
||||||
|
|
||||||
|
if (existingFile) {
|
||||||
|
draft.files[fileId] = create(draft.files[fileId], (fileDraft) => {
|
||||||
|
Object.assign(fileDraft, existingFile);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (existingFile?.file && newFile.file) {
|
||||||
|
draft.files[fileId].file = create(draft.files[fileId].file, (fileDraft) => {
|
||||||
|
Object.assign(fileDraft, existingFile.file);
|
||||||
|
fileDraft.text = newFile.file.text_chunk
|
||||||
|
? (existingFile.file.text || '') + newFile.file.text_chunk
|
||||||
|
: (newFile.file.text ?? existingFile.file.text);
|
||||||
|
fileDraft.modified = newFile.file.modified ?? existingFile.file.modified;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
console.log('newFile', newFile);
|
||||||
|
draft.files[fileId] = create(draft.files[fileId], (fileDraft) => {
|
||||||
|
fileDraft.file.text = newFile.file.text_chunk;
|
||||||
|
Object.assign(fileDraft, newFile);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
);
|
||||||
|
|
||||||
const existingFile = existingReasoningMessageFiles?.files[fileId];
|
chat.messages[message_id].reasoning_messages[reasoningMessageId] = messageFiles;
|
||||||
const newFile = reasoning.files[fileId];
|
|
||||||
|
|
||||||
if (existingFile) {
|
|
||||||
Object.assign(messageFiles.files[fileId], existingFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (existingFile?.file && newFile.file) {
|
|
||||||
messageFiles.files[fileId].file = {
|
|
||||||
...existingFile.file,
|
|
||||||
text: newFile.file.text_chunk
|
|
||||||
? (existingFile.file.text || '') + newFile.file.text_chunk
|
|
||||||
: (newFile.file.text ?? existingFile.file.text),
|
|
||||||
modified: newFile.file.modified ?? existingFile.file.modified
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
Object.assign(messageFiles.files[fileId], newFile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue