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 }
|
payload: { id: chatId }
|
||||||
},
|
},
|
||||||
responseEvent: '/chats/get:getChat',
|
responseEvent: '/chats/get:getChat',
|
||||||
options: queryKeys['chatsGetChat'](chatId),
|
options: queryKeys.chatsGetChat(chatId),
|
||||||
callback: (_currentData, newData) => {
|
callback: (_currentData, newData) => {
|
||||||
const { iChat, iChatMessages } = updateChatToIChat(newData, false);
|
const { iChat, iChatMessages } = updateChatToIChat(newData, false);
|
||||||
for (const message of iChatMessages) {
|
for (const message of iChatMessages) {
|
||||||
|
|
|
@ -7,7 +7,7 @@ export const useChatSelectors = () => {
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
const getChatMemoized = useMemoizedFn((chatId: string): IBusterChat | undefined => {
|
const getChatMemoized = useMemoizedFn((chatId: string): IBusterChat | undefined => {
|
||||||
const options = queryKeys['chatsGetChat'](chatId);
|
const options = queryKeys.chatsGetChat(chatId);
|
||||||
const queryKey = options.queryKey;
|
const queryKey = options.queryKey;
|
||||||
return queryClient.getQueryData<IBusterChat>(queryKey);
|
return queryClient.getQueryData<IBusterChat>(queryKey);
|
||||||
});
|
});
|
||||||
|
|
|
@ -16,7 +16,7 @@ export const useChatUpdate = () => {
|
||||||
|
|
||||||
const onUpdateChat = useMemoizedFn(
|
const onUpdateChat = useMemoizedFn(
|
||||||
async (newChatConfig: Partial<IBusterChat> & { id: string }, saveToServer: boolean = false) => {
|
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 queryKey = options.queryKey;
|
||||||
const currentData = queryClient.getQueryData<IBusterChat>(queryKey);
|
const currentData = queryClient.getQueryData<IBusterChat>(queryKey);
|
||||||
const iChat: IBusterChat = {
|
const iChat: IBusterChat = {
|
||||||
|
|
|
@ -3,7 +3,10 @@ import { useBusterChatContextSelector } from '../ChatProvider';
|
||||||
import {
|
import {
|
||||||
BusterChat,
|
BusterChat,
|
||||||
BusterChatMessage_text,
|
BusterChatMessage_text,
|
||||||
BusterChatMessageReasoning
|
BusterChatMessageReasoning,
|
||||||
|
BusterChatMessageReasoning_files,
|
||||||
|
BusterChatMessageReasoning_text,
|
||||||
|
BusterChatMessageReasoning_Pills
|
||||||
} from '@/api/asset_interfaces';
|
} from '@/api/asset_interfaces';
|
||||||
import {
|
import {
|
||||||
ChatEvent_GeneratingReasoningMessage,
|
ChatEvent_GeneratingReasoningMessage,
|
||||||
|
@ -91,8 +94,6 @@ export const useChatStreamMessage = () => {
|
||||||
|
|
||||||
const initializeNewChatCallback = useMemoizedFn((d: BusterChat) => {
|
const initializeNewChatCallback = useMemoizedFn((d: BusterChat) => {
|
||||||
const { iChat, iChatMessages } = updateChatToIChat(d, true);
|
const { iChat, iChatMessages } = updateChatToIChat(d, true);
|
||||||
console.log('iChatMessages', iChatMessages);
|
|
||||||
console.log('iChat', iChat);
|
|
||||||
normalizeChatMessage(iChatMessages);
|
normalizeChatMessage(iChatMessages);
|
||||||
onUpdateChat(iChat);
|
onUpdateChat(iChat);
|
||||||
onChangePage({
|
onChangePage({
|
||||||
|
@ -182,9 +183,9 @@ export const useChatStreamMessage = () => {
|
||||||
(_: null, d: ChatEvent_GeneratingReasoningMessage) => {
|
(_: null, d: ChatEvent_GeneratingReasoningMessage) => {
|
||||||
const { message_id, reasoning, chat_id } = d;
|
const { message_id, reasoning, chat_id } = d;
|
||||||
const reasoningMessageId = reasoning.id;
|
const reasoningMessageId = reasoning.id;
|
||||||
const foundReasoningMessage: undefined | ChatMessageReasoning =
|
let messageToUse: undefined | ChatMessageReasoning =
|
||||||
chatMessageReasoningMessageRef.current[message_id]?.[reasoningMessageId];
|
chatMessageReasoningMessageRef.current[message_id]?.[reasoningMessageId];
|
||||||
const isNewMessage = !foundReasoningMessage;
|
const isNewMessage = !messageToUse;
|
||||||
const currentReasoning = chatMessagesRef.current[message_id]?.reasoning ?? [];
|
const currentReasoning = chatMessagesRef.current[message_id]?.reasoning ?? [];
|
||||||
|
|
||||||
if (isNewMessage) {
|
if (isNewMessage) {
|
||||||
|
@ -195,21 +196,86 @@ export const useChatStreamMessage = () => {
|
||||||
index: currentReasoning.length
|
index: currentReasoning.length
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
messageToUse = chatMessageReasoningMessageRef.current[message_id]?.[reasoningMessageId]!;
|
||||||
}
|
}
|
||||||
|
|
||||||
const messageToUse =
|
switch (reasoning.type) {
|
||||||
chatMessageReasoningMessageRef.current[message_id]?.[reasoningMessageId]!;
|
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
|
const updatedReasoning: BusterChatMessageReasoning[] = isNewMessage
|
||||||
? [...currentReasoning, messageToUse]
|
? [...currentReasoning, messageToUse]
|
||||||
: [
|
: [
|
||||||
...currentReasoning.slice(0, foundReasoningMessage.index),
|
...currentReasoning.slice(0, messageToUse.index),
|
||||||
reasoning,
|
messageToUse,
|
||||||
...currentReasoning.slice(foundReasoningMessage.index + 1)
|
...currentReasoning.slice(messageToUse.index + 1)
|
||||||
];
|
];
|
||||||
|
|
||||||
console.log(updatedReasoning.length);
|
|
||||||
|
|
||||||
onUpdateChatMessageTransition({
|
onUpdateChatMessageTransition({
|
||||||
id: message_id,
|
id: message_id,
|
||||||
reasoning: autoAppendThought(updatedReasoning, chat_id),
|
reasoning: autoAppendThought(updatedReasoning, chat_id),
|
||||||
|
|
|
@ -4,6 +4,7 @@ import React from 'react';
|
||||||
import { useChatIndividualContextSelector } from '@chatLayout/ChatContext';
|
import { useChatIndividualContextSelector } from '@chatLayout/ChatContext';
|
||||||
import { ReasoningMessageContainer } from './ReasoningMessageContainer';
|
import { ReasoningMessageContainer } from './ReasoningMessageContainer';
|
||||||
import { useMessageIndividual } from '@/context/Chats';
|
import { useMessageIndividual } from '@/context/Chats';
|
||||||
|
import { useMount } from 'ahooks';
|
||||||
|
|
||||||
interface ReasoningControllerProps {
|
interface ReasoningControllerProps {
|
||||||
chatId: string;
|
chatId: string;
|
||||||
|
@ -14,9 +15,9 @@ export const ReasoningController: React.FC<ReasoningControllerProps> = ({ chatId
|
||||||
const hasChat = useChatIndividualContextSelector((state) => state.hasChat);
|
const hasChat = useChatIndividualContextSelector((state) => state.hasChat);
|
||||||
const message = useMessageIndividual(messageId);
|
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 reasoningMessages = message.reasoning;
|
||||||
const isCompletedStream = message.isCompletedStream;
|
const isCompletedStream = message.isCompletedStream;
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import type {
|
import type { BusterChatMessageReasoning } from '@/api/asset_interfaces';
|
||||||
BusterChatMessageReasoning,
|
|
||||||
BusterChatMessageReasoning_text
|
|
||||||
} from '@/api/asset_interfaces';
|
|
||||||
import { StreamingMessage_Text } from '@/components/ui/streaming/StreamingMessage_Text';
|
|
||||||
import { ReasoningMessage_PillsContainer } from './ReasoningMessage_PillContainers';
|
import { ReasoningMessage_PillsContainer } from './ReasoningMessage_PillContainers';
|
||||||
import { ReasoningMessage_Files } from './ReasoningMessage_Files';
|
import { ReasoningMessage_Files } from './ReasoningMessage_Files';
|
||||||
import { ReasoningMessage_Text } from './ReasoningMessage_Text';
|
import { ReasoningMessage_Text } from './ReasoningMessage_Text';
|
||||||
|
@ -38,6 +34,7 @@ export const ReasoningMessageSelector: React.FC<ReasoningMessageSelectorProps> =
|
||||||
chatId
|
chatId
|
||||||
}) => {
|
}) => {
|
||||||
const ReasoningMessage = ReasoningMessageRecord[reasoningMessage.type];
|
const ReasoningMessage = ReasoningMessageRecord[reasoningMessage.type];
|
||||||
|
console.log(reasoningMessage.type);
|
||||||
return (
|
return (
|
||||||
<ReasoningMessage
|
<ReasoningMessage
|
||||||
reasoningMessage={reasoningMessage}
|
reasoningMessage={reasoningMessage}
|
||||||
|
|
|
@ -8,6 +8,8 @@ export const ReasoningMessage_Text: React.FC<ReasoningMessageProps> = React.memo
|
||||||
({ reasoningMessage, chatId, isCompletedStream, isLastMessageItem }) => {
|
({ reasoningMessage, chatId, isCompletedStream, isLastMessageItem }) => {
|
||||||
const { message, status, id, type, title, secondary_title } =
|
const { message, status, id, type, title, secondary_title } =
|
||||||
reasoningMessage as BusterChatMessageReasoning_text;
|
reasoningMessage as BusterChatMessageReasoning_text;
|
||||||
|
|
||||||
|
console.log('here', message?.length);
|
||||||
return (
|
return (
|
||||||
<BarContainer
|
<BarContainer
|
||||||
showBar={true}
|
showBar={true}
|
||||||
|
|
Loading…
Reference in New Issue