feat(app): handle new architecture

This commit is contained in:
ItzCrazyKns
2025-11-23 19:58:46 +05:30
parent e0ba476ca4
commit 956a768a86
14 changed files with 945 additions and 508 deletions

View File

@@ -22,6 +22,9 @@ import { useSpeech } from 'react-text-to-speech';
import ThinkBox from './ThinkBox';
import { useChat, Section } from '@/lib/hooks/useChat';
import Citation from './Citation';
import AssistantSteps from './AssistantSteps';
import { ResearchBlock } from '@/lib/types';
import Renderer from './Widgets/Renderer';
const ThinkTagProcessor = ({
children,
@@ -46,12 +49,21 @@ const MessageBox = ({
dividerRef?: MutableRefObject<HTMLDivElement | null>;
isLast: boolean;
}) => {
const { loading, chatTurns, sendMessage, rewrite } = useChat();
const { loading, sendMessage, rewrite, messages, researchEnded } = useChat();
const parsedMessage = section.parsedAssistantMessage || '';
const parsedMessage = section.parsedTextBlocks.join('\n\n');
const speechMessage = section.speechMessage || '';
const thinkingEnded = section.thinkingEnded;
const sourceBlocks = section.message.responseBlocks.filter(
(block): block is typeof block & { type: 'source' } =>
block.type === 'source',
);
const sources = sourceBlocks.flatMap((block) => block.data);
const hasContent = section.parsedTextBlocks.length > 0;
const { speechStatus, start, stop } = useSpeech({ text: speechMessage });
const markdownOverrides: MarkdownToJSX.Options = {
@@ -72,7 +84,7 @@ const MessageBox = ({
<div className="space-y-6">
<div className={'w-full pt-8 break-words'}>
<h2 className="text-black dark:text-white font-medium text-3xl lg:w-9/12">
{section.userMessage.content}
{section.message.query}
</h2>
</div>
@@ -81,21 +93,50 @@ const MessageBox = ({
ref={dividerRef}
className="flex flex-col space-y-6 w-full lg:w-9/12"
>
{section.sourceMessage &&
section.sourceMessage.sources.length > 0 && (
<div className="flex flex-col space-y-2">
<div className="flex flex-row items-center space-x-2">
<BookCopy className="text-black dark:text-white" size={20} />
<h3 className="text-black dark:text-white font-medium text-xl">
Sources
</h3>
</div>
<MessageSources sources={section.sourceMessage.sources} />
{sources.length > 0 && (
<div className="flex flex-col space-y-2">
<div className="flex flex-row items-center space-x-2">
<BookCopy className="text-black dark:text-white" size={20} />
<h3 className="text-black dark:text-white font-medium text-xl">
Sources
</h3>
</div>
<MessageSources sources={sources} />
</div>
)}
{section.message.responseBlocks
.filter(
(block): block is ResearchBlock =>
block.type === 'research' && block.data.subSteps.length > 0,
)
.map((researchBlock) => (
<div key={researchBlock.id} className="flex flex-col space-y-2">
<AssistantSteps
block={researchBlock}
status={section.message.status}
/>
</div>
))}
{section.widgets.length > 0 && <Renderer widgets={section.widgets} />}
{isLast &&
loading &&
!researchEnded &&
!section.message.responseBlocks.some(
(b) => b.type === 'research' && b.data.subSteps.length > 0,
) && (
<div className="flex items-center gap-2 p-3 rounded-lg bg-light-secondary dark:bg-dark-secondary border border-light-200 dark:border-dark-200">
<Disc3 className="w-4 h-4 text-black dark:text-white animate-spin" />
<span className="text-sm text-black/70 dark:text-white/70">
Brainstorming...
</span>
</div>
)}
<div className="flex flex-col space-y-2">
{section.sourceMessage && (
{sources.length > 0 && (
<div className="flex flex-row items-center space-x-2">
<Disc3
className={cn(
@@ -110,7 +151,7 @@ const MessageBox = ({
</div>
)}
{section.assistantMessage && (
{hasContent && (
<>
<Markdown
className={cn(
@@ -127,14 +168,11 @@ const MessageBox = ({
<div className="flex flex-row items-center -ml-2">
<Rewrite
rewrite={rewrite}
messageId={section.assistantMessage.messageId}
messageId={section.message.messageId}
/>
</div>
<div className="flex flex-row items-center -mr-2">
<Copy
initialMessage={section.assistantMessage.content}
section={section}
/>
<Copy initialMessage={parsedMessage} section={section} />
<button
onClick={() => {
if (speechStatus === 'started') {
@@ -158,7 +196,7 @@ const MessageBox = ({
{isLast &&
section.suggestions &&
section.suggestions.length > 0 &&
section.assistantMessage &&
hasContent &&
!loading && (
<div className="mt-6">
<div className="flex flex-row items-center space-x-2 mb-4">
@@ -206,17 +244,17 @@ const MessageBox = ({
</div>
</div>
{section.assistantMessage && (
{hasContent && (
<div className="lg:sticky lg:top-20 flex flex-col items-center space-y-3 w-full lg:w-3/12 z-30 h-full pb-4">
<SearchImages
query={section.userMessage.content}
chatHistory={chatTurns}
messageId={section.assistantMessage.messageId}
query={section.message.query}
chatHistory={messages}
messageId={section.message.messageId}
/>
<SearchVideos
chatHistory={chatTurns}
query={section.userMessage.content}
messageId={section.assistantMessage.messageId}
chatHistory={messages}
query={section.message.query}
messageId={section.message.messageId}
/>
</div>
)}