'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'; 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, chatTurns, sendMessage, rewrite } = useChat(); const parsedMessage = section.parsedAssistantMessage || ''; const speechMessage = section.speechMessage || ''; const thinkingEnded = section.thinkingEnded; const { speechStatus, start, stop } = useSpeech({ text: speechMessage }); const markdownOverrides: MarkdownToJSX.Options = { overrides: { think: { component: ThinkTagProcessor, props: { thinkingEnded: thinkingEnded, }, }, citation: { component: Citation, }, }, }; return (

{section.userMessage.content}

{section.sourceMessage && section.sourceMessage.sources.length > 0 && (

Sources

)}
{section.sourceMessage && (

Answer

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

Related

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