'use client'; /* eslint-disable @next/next/no-img-element */ import React, { MutableRefObject } from 'react'; import { cn } from '@/lib/utils'; import { BookCopy, Disc3, Volume2, StopCircle, Layers3, Plus, CornerDownRight, } from 'lucide-react'; import Markdown, { MarkdownToJSX } from 'markdown-to-jsx'; import Copy from './MessageActions/Copy'; import Rewrite from './MessageActions/Rewrite'; import MessageSources from './MessageSources'; import SearchImages from './SearchImages'; import SearchVideos from './SearchVideos'; 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, thinkingEnded, }: { children: React.ReactNode; thinkingEnded: boolean; }) => { return ( ); }; const MessageBox = ({ section, sectionIndex, dividerRef, isLast, }: { section: Section; sectionIndex: number; dividerRef?: MutableRefObject; isLast: boolean; }) => { const { loading, sendMessage, rewrite, messages, researchEnded } = useChat(); 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 = { overrides: { think: { component: ThinkTagProcessor, props: { thinkingEnded: thinkingEnded, }, }, citation: { component: Citation, }, }, }; return (

{section.message.query}

{sources.length > 0 && (

Sources

)} {section.message.responseBlocks .filter( (block): block is ResearchBlock => block.type === 'research' && block.data.subSteps.length > 0, ) .map((researchBlock) => (
))} {section.widgets.length > 0 && } {isLast && loading && !researchEnded && !section.message.responseBlocks.some( (b) => b.type === 'research' && b.data.subSteps.length > 0, ) && (
Brainstorming...
)}
{sources.length > 0 && (

Answer

)} {hasContent && ( <> {parsedMessage} {loading && isLast ? null : (
)} {isLast && section.suggestions && section.suggestions.length > 0 && hasContent && !loading && (

Related

{section.suggestions.map( (suggestion: string, i: number) => (
), )}
)} )}
{hasContent && (
)}
); }; export default MessageBox;