mirror of https://github.com/buster-so/buster.git
update some of the query keys
This commit is contained in:
parent
8e456e9056
commit
ca7e0ef188
|
@ -12,7 +12,7 @@ export const useChatIndividual = (chatId: string) => {
|
|||
payload: { id: chatId }
|
||||
},
|
||||
responseEvent: '/chats/get:getChat',
|
||||
options: queryKeys['chatsGetChat'](chatId),
|
||||
options: queryKeys.chatsGetChat(chatId),
|
||||
callback: (_currentData, newData) => {
|
||||
const { iChat, iChatMessages } = updateChatToIChat(newData, false);
|
||||
for (const message of iChatMessages) {
|
||||
|
|
|
@ -7,7 +7,7 @@ export const useChatSelectors = () => {
|
|||
const queryClient = useQueryClient();
|
||||
|
||||
const getChatMemoized = useMemoizedFn((chatId: string): IBusterChat | undefined => {
|
||||
const options = queryKeys['chatsGetChat'](chatId);
|
||||
const options = queryKeys.chatsGetChat(chatId);
|
||||
const queryKey = options.queryKey;
|
||||
return queryClient.getQueryData<IBusterChat>(queryKey);
|
||||
});
|
||||
|
|
|
@ -16,7 +16,7 @@ export const useChatUpdate = () => {
|
|||
|
||||
const onUpdateChat = useMemoizedFn(
|
||||
async (newChatConfig: Partial<IBusterChat> & { id: string }, saveToServer: boolean = false) => {
|
||||
const options = queryKeys['chatsGetChat'](newChatConfig.id);
|
||||
const options = queryKeys.chatsGetChat(newChatConfig.id);
|
||||
const queryKey = options.queryKey;
|
||||
const currentData = queryClient.getQueryData<IBusterChat>(queryKey);
|
||||
const iChat: IBusterChat = {
|
||||
|
|
|
@ -3,7 +3,10 @@ import { useBusterChatContextSelector } from '../ChatProvider';
|
|||
import {
|
||||
BusterChat,
|
||||
BusterChatMessage_text,
|
||||
BusterChatMessageReasoning
|
||||
BusterChatMessageReasoning,
|
||||
BusterChatMessageReasoning_files,
|
||||
BusterChatMessageReasoning_text,
|
||||
BusterChatMessageReasoning_Pills
|
||||
} from '@/api/asset_interfaces';
|
||||
import {
|
||||
ChatEvent_GeneratingReasoningMessage,
|
||||
|
@ -91,8 +94,6 @@ export const useChatStreamMessage = () => {
|
|||
|
||||
const initializeNewChatCallback = useMemoizedFn((d: BusterChat) => {
|
||||
const { iChat, iChatMessages } = updateChatToIChat(d, true);
|
||||
console.log('iChatMessages', iChatMessages);
|
||||
console.log('iChat', iChat);
|
||||
normalizeChatMessage(iChatMessages);
|
||||
onUpdateChat(iChat);
|
||||
onChangePage({
|
||||
|
@ -182,9 +183,9 @@ export const useChatStreamMessage = () => {
|
|||
(_: null, d: ChatEvent_GeneratingReasoningMessage) => {
|
||||
const { message_id, reasoning, chat_id } = d;
|
||||
const reasoningMessageId = reasoning.id;
|
||||
const foundReasoningMessage: undefined | ChatMessageReasoning =
|
||||
let messageToUse: undefined | ChatMessageReasoning =
|
||||
chatMessageReasoningMessageRef.current[message_id]?.[reasoningMessageId];
|
||||
const isNewMessage = !foundReasoningMessage;
|
||||
const isNewMessage = !messageToUse;
|
||||
const currentReasoning = chatMessagesRef.current[message_id]?.reasoning ?? [];
|
||||
|
||||
if (isNewMessage) {
|
||||
|
@ -195,21 +196,86 @@ export const useChatStreamMessage = () => {
|
|||
index: currentReasoning.length
|
||||
}
|
||||
};
|
||||
messageToUse = chatMessageReasoningMessageRef.current[message_id]?.[reasoningMessageId]!;
|
||||
}
|
||||
|
||||
const messageToUse =
|
||||
chatMessageReasoningMessageRef.current[message_id]?.[reasoningMessageId]!;
|
||||
switch (reasoning.type) {
|
||||
case 'text':
|
||||
const existingReasoningMessageText = messageToUse as BusterChatMessageReasoning_text;
|
||||
const isStreaming = reasoning.message_chunk !== null;
|
||||
if (isStreaming) {
|
||||
existingReasoningMessageText.message =
|
||||
(existingReasoningMessageText.message || '') + reasoning.message_chunk!;
|
||||
}
|
||||
|
||||
console.log(existingReasoningMessageText.message?.length);
|
||||
|
||||
break;
|
||||
case 'files':
|
||||
const existingReasoningMessageFiles = messageToUse as BusterChatMessageReasoning_files;
|
||||
|
||||
const updatedFiles = reasoning.files.reduce(
|
||||
(acc, newFile) => {
|
||||
const existingFile = acc.find((f) => f.file_name === newFile.file_name);
|
||||
if (existingFile) {
|
||||
// Update existing file with new content
|
||||
if (existingFile.file && newFile.file) {
|
||||
existingFile.file =
|
||||
Array.isArray(existingFile.file) && Array.isArray(newFile.file)
|
||||
? [...existingFile.file, ...newFile.file]
|
||||
: existingFile.file;
|
||||
}
|
||||
} else {
|
||||
// Add new file
|
||||
acc.push(newFile);
|
||||
}
|
||||
return acc;
|
||||
},
|
||||
[...existingReasoningMessageFiles.files]
|
||||
);
|
||||
|
||||
reasoning.files = updatedFiles;
|
||||
break;
|
||||
case 'pills':
|
||||
const existingReasoningMessagePills = messageToUse as BusterChatMessageReasoning_Pills;
|
||||
|
||||
// Handle pill containers
|
||||
if (reasoning.pill_containers) {
|
||||
const updatedContainers = reasoning.pill_containers.reduce(
|
||||
(acc, newContainer) => {
|
||||
const existingContainer = acc.find((c) => c.title === newContainer.title);
|
||||
|
||||
if (existingContainer) {
|
||||
// Update existing container by merging pills
|
||||
existingContainer.pills = [...existingContainer.pills, ...newContainer.pills];
|
||||
} else {
|
||||
// Add new container
|
||||
acc.push(newContainer);
|
||||
}
|
||||
|
||||
return acc;
|
||||
},
|
||||
[...(existingReasoningMessagePills.pill_containers || [])]
|
||||
);
|
||||
|
||||
reasoning.pill_containers = updatedContainers;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
const type: never = reasoning;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!messageToUse) return;
|
||||
|
||||
const updatedReasoning: BusterChatMessageReasoning[] = isNewMessage
|
||||
? [...currentReasoning, messageToUse]
|
||||
: [
|
||||
...currentReasoning.slice(0, foundReasoningMessage.index),
|
||||
reasoning,
|
||||
...currentReasoning.slice(foundReasoningMessage.index + 1)
|
||||
...currentReasoning.slice(0, messageToUse.index),
|
||||
messageToUse,
|
||||
...currentReasoning.slice(messageToUse.index + 1)
|
||||
];
|
||||
|
||||
console.log(updatedReasoning.length);
|
||||
|
||||
onUpdateChatMessageTransition({
|
||||
id: message_id,
|
||||
reasoning: autoAppendThought(updatedReasoning, chat_id),
|
||||
|
|
|
@ -4,6 +4,7 @@ import React from 'react';
|
|||
import { useChatIndividualContextSelector } from '@chatLayout/ChatContext';
|
||||
import { ReasoningMessageContainer } from './ReasoningMessageContainer';
|
||||
import { useMessageIndividual } from '@/context/Chats';
|
||||
import { useMount } from 'ahooks';
|
||||
|
||||
interface ReasoningControllerProps {
|
||||
chatId: string;
|
||||
|
@ -14,9 +15,9 @@ export const ReasoningController: React.FC<ReasoningControllerProps> = ({ chatId
|
|||
const hasChat = useChatIndividualContextSelector((state) => state.hasChat);
|
||||
const message = useMessageIndividual(messageId);
|
||||
|
||||
console.log(hasChat, message);
|
||||
console.log('mounted', hasChat, message?.id);
|
||||
|
||||
if (!hasChat || !message) return null;
|
||||
if (!hasChat || !message) return <div className="h-full w-full bg-red-500">NUTS</div>;
|
||||
|
||||
const reasoningMessages = message.reasoning;
|
||||
const isCompletedStream = message.isCompletedStream;
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
import React from 'react';
|
||||
import type {
|
||||
BusterChatMessageReasoning,
|
||||
BusterChatMessageReasoning_text
|
||||
} from '@/api/asset_interfaces';
|
||||
import { StreamingMessage_Text } from '@/components/ui/streaming/StreamingMessage_Text';
|
||||
import type { BusterChatMessageReasoning } from '@/api/asset_interfaces';
|
||||
import { ReasoningMessage_PillsContainer } from './ReasoningMessage_PillContainers';
|
||||
import { ReasoningMessage_Files } from './ReasoningMessage_Files';
|
||||
import { ReasoningMessage_Text } from './ReasoningMessage_Text';
|
||||
|
@ -38,6 +34,7 @@ export const ReasoningMessageSelector: React.FC<ReasoningMessageSelectorProps> =
|
|||
chatId
|
||||
}) => {
|
||||
const ReasoningMessage = ReasoningMessageRecord[reasoningMessage.type];
|
||||
console.log(reasoningMessage.type);
|
||||
return (
|
||||
<ReasoningMessage
|
||||
reasoningMessage={reasoningMessage}
|
||||
|
|
|
@ -8,6 +8,8 @@ export const ReasoningMessage_Text: React.FC<ReasoningMessageProps> = React.memo
|
|||
({ reasoningMessage, chatId, isCompletedStream, isLastMessageItem }) => {
|
||||
const { message, status, id, type, title, secondary_title } =
|
||||
reasoningMessage as BusterChatMessageReasoning_text;
|
||||
|
||||
console.log('here', message?.length);
|
||||
return (
|
||||
<BarContainer
|
||||
showBar={true}
|
||||
|
|
Loading…
Reference in New Issue