mirror of https://github.com/buster-so/buster.git
add some reasoning trigger
This commit is contained in:
parent
af7b1fe329
commit
f87f67d895
|
@ -8,3 +8,9 @@ export const useDocumentTitle = (title: string | undefined) => {
|
|||
}, 25);
|
||||
}, [title]);
|
||||
};
|
||||
|
||||
export const updateDocumentTitle = (callback: (currentTitle: string) => string) => {
|
||||
const currentTitle = document.title;
|
||||
const newTitle = callback(currentTitle);
|
||||
document.title = newTitle;
|
||||
};
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { useLocation, useNavigate } from '@tanstack/react-router';
|
||||
import { useEffect, useLayoutEffect, useRef } from 'react';
|
||||
import { useNavigate } from '@tanstack/react-router';
|
||||
import { useEffect, useLayoutEffect, useRef, useState } from 'react';
|
||||
import type { BusterChatResponseMessage_file } from '@/api/asset_interfaces/chat';
|
||||
import { useGetChatMessageMemoized } from '@/api/buster_rest/chats';
|
||||
import { useIsVersionChanged } from '@/context/AppVersion/useAppVersion';
|
||||
|
@ -10,6 +10,7 @@ import {
|
|||
useGetChatMessageIsFinishedReasoning,
|
||||
useGetChatMessageLastReasoningMessageId,
|
||||
} from '@/context/Chats/useGetChatMessage';
|
||||
import { useWindowFocus } from '@/hooks/useWindowFocus';
|
||||
import { assetParamsToRoute } from '@/lib/assets/assetParamsToRoute';
|
||||
|
||||
export const useAutoRedirectStreaming = ({
|
||||
|
@ -31,6 +32,7 @@ export const useAutoRedirectStreaming = ({
|
|||
const previousIsCompletedStream = useRef<boolean>(isStreamFinished);
|
||||
const hasLoadedChat = useHasLoadedChat({ chatId: chatId || '' });
|
||||
const hasReasoning = !!lastReasoningMessageId;
|
||||
const [triggerAutoNavigate, setTriggerAutoNavigate] = useState<number>(0);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
previousIsCompletedStream.current = isStreamFinished;
|
||||
|
@ -42,6 +44,8 @@ export const useAutoRedirectStreaming = ({
|
|||
return;
|
||||
}
|
||||
|
||||
console.log('triggerAutoNavigate', triggerAutoNavigate);
|
||||
|
||||
const chatMessage = getChatMessageMemoized(lastMessageId);
|
||||
const firstFileId = chatMessage?.response_message_ids?.find((id) => {
|
||||
const responseMessage = chatMessage?.response_messages[id];
|
||||
|
@ -49,7 +53,11 @@ export const useAutoRedirectStreaming = ({
|
|||
});
|
||||
|
||||
//this will happen if it is streaming and has a file in the response
|
||||
if (!isStreamFinished && firstFileId) {
|
||||
// or if the chat is completed and has a file in the response
|
||||
if (
|
||||
(!isStreamFinished && firstFileId) ||
|
||||
(isStreamFinished && firstFileId && previousIsCompletedStream.current === false)
|
||||
) {
|
||||
const firstFile = chatMessage?.response_messages[firstFileId] as
|
||||
| BusterChatResponseMessage_file
|
||||
| undefined;
|
||||
|
@ -64,6 +72,8 @@ export const useAutoRedirectStreaming = ({
|
|||
|
||||
navigate({ ...linkProps, replace: true, reloadDocument: versionChanged });
|
||||
}
|
||||
|
||||
previousIsCompletedStream.current = true;
|
||||
}
|
||||
|
||||
//this will trigger when the chat is streaming and is has not completed yet (new chat)
|
||||
|
@ -86,8 +96,6 @@ export const useAutoRedirectStreaming = ({
|
|||
previousIsCompletedStream.current === false &&
|
||||
!firstFileId
|
||||
) {
|
||||
//no file is found, so we need to collapse the chat
|
||||
|
||||
navigate({
|
||||
to: '/app/chats/$chatId',
|
||||
params: {
|
||||
|
@ -96,12 +104,27 @@ export const useAutoRedirectStreaming = ({
|
|||
replace: true,
|
||||
reloadDocument: versionChanged,
|
||||
});
|
||||
previousIsCompletedStream.current = true;
|
||||
}
|
||||
}, [isStreamFinished, hasReasoning, hasResponseFile, chatId, lastMessageId, isFinishedReasoning]); //only use these values to trigger the useEffect
|
||||
}, [
|
||||
isStreamFinished,
|
||||
hasReasoning,
|
||||
hasResponseFile,
|
||||
chatId,
|
||||
lastMessageId,
|
||||
isFinishedReasoning,
|
||||
triggerAutoNavigate,
|
||||
]); //only use these values to trigger the useEffect
|
||||
|
||||
useEffect(() => {
|
||||
if (!isStreamFinished && versionChanged) {
|
||||
window.location.reload();
|
||||
}
|
||||
}, [isStreamFinished, versionChanged]);
|
||||
|
||||
useWindowFocus(() => {
|
||||
if (isStreamFinished && previousIsCompletedStream.current === false) {
|
||||
setTriggerAutoNavigate((prev) => prev + 1);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
|
@ -11,6 +11,7 @@ import {
|
|||
import { chatQueryKeys } from '@/api/query_keys/chat';
|
||||
import { metricsQueryKeys } from '@/api/query_keys/metric';
|
||||
import { useBlackboxMessage } from '@/context/BlackBox/useBlackboxMessage';
|
||||
import { updateDocumentTitle, useDocumentTitle } from '@/hooks/useDocumentTitle';
|
||||
import { useMemoizedFn } from '@/hooks/useMemoizedFn';
|
||||
import { useMount } from '@/hooks/useMount';
|
||||
import { updateChatToIChat } from '@/lib/chat';
|
||||
|
@ -135,13 +136,20 @@ export const useChatStreaming = ({
|
|||
});
|
||||
|
||||
useEffect(() => {
|
||||
const REASONING_TITLE = 'Reasoning... | ';
|
||||
if (isStreamingMessage) {
|
||||
const message = getChatMessageMemoized(messageId);
|
||||
if (message) {
|
||||
checkBlackBoxMessage(message);
|
||||
}
|
||||
updateDocumentTitle((currentTitle) => {
|
||||
return `${REASONING_TITLE}${currentTitle}`;
|
||||
});
|
||||
} else {
|
||||
removeBlackBoxMessage(messageId);
|
||||
updateDocumentTitle((currentTitle) => {
|
||||
return currentTitle.replace(REASONING_TITLE, '');
|
||||
});
|
||||
}
|
||||
}, [isStreamingMessage]);
|
||||
|
||||
|
|
Loading…
Reference in New Issue