From 11a828b0734dc7fb24a04f73a6657d152eec164a Mon Sep 17 00:00:00 2001 From: ItzCrazyKns <95534749+ItzCrazyKns@users.noreply.github.com> Date: Tue, 22 Jul 2025 21:21:09 +0530 Subject: [PATCH] feat(message-box): close think box after thinking process ends --- src/components/MessageBox.tsx | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/components/MessageBox.tsx b/src/components/MessageBox.tsx index a7c46ec..dc43aa2 100644 --- a/src/components/MessageBox.tsx +++ b/src/components/MessageBox.tsx @@ -21,8 +21,16 @@ import SearchVideos from './SearchVideos'; import { useSpeech } from 'react-text-to-speech'; import ThinkBox from './ThinkBox'; -const ThinkTagProcessor = ({ children }: { children: React.ReactNode }) => { - return ; +const ThinkTagProcessor = ({ + children, + thinkingEnded, +}: { + children: React.ReactNode; + thinkingEnded: boolean; +}) => { + return ( + + ); }; const MessageBox = ({ @@ -46,6 +54,7 @@ const MessageBox = ({ }) => { const [parsedMessage, setParsedMessage] = useState(message.content); const [speechMessage, setSpeechMessage] = useState(message.content); + const [thinkingEnded, setThinkingEnded] = useState(false); useEffect(() => { const citationRegex = /\[([^\]]+)\]/g; @@ -61,6 +70,10 @@ const MessageBox = ({ } } + if (message.role === 'assistant' && message.content.includes('')) { + setThinkingEnded(true); + } + if ( message.role === 'assistant' && message?.sources && @@ -88,7 +101,7 @@ const MessageBox = ({ if (url) { return `${numStr}`; } else { - return `[${numStr}]`; + return ``; } }) .join(''); @@ -99,6 +112,14 @@ const MessageBox = ({ ); setSpeechMessage(message.content.replace(regex, '')); return; + } else if ( + message.role === 'assistant' && + message?.sources && + message.sources.length === 0 + ) { + setParsedMessage(processedMessage.replace(regex, '')); + setSpeechMessage(message.content.replace(regex, '')); + return; } setSpeechMessage(message.content.replace(regex, '')); @@ -111,6 +132,9 @@ const MessageBox = ({ overrides: { think: { component: ThinkTagProcessor, + props: { + thinkingEnded: thinkingEnded, + }, }, }, };