/* eslint-disable @next/next/no-img-element */ import React, { MutableRefObject, useEffect, useState } from 'react'; import { Message } from './ChatWindow'; import { cn } from '@/lib/utils'; import { BookCopy, Disc3, FilePen, PlusIcon, Share, ThumbsDown, VideoIcon, } from 'lucide-react'; import Markdown from 'markdown-to-jsx'; import Copy from './MessageActions/Copy'; import Rewrite from './MessageActions/Rewrite'; import MessageSources from './MessageSources'; import SearchImages from './SearchImages'; const MessageBox = ({ message, messageIndex, history, loading, dividerRef, isLast, rewrite, }: { message: Message; messageIndex: number; history: Message[]; loading: boolean; dividerRef?: MutableRefObject; isLast: boolean; rewrite: (messageId: string) => void; }) => { const [parsedMessage, setParsedMessage] = useState(message.content); useEffect(() => { if ( message.role === 'assistant' && message?.sources && message.sources.length > 0 ) { const regex = /\[(\d+)\]/g; return setParsedMessage( message.content.replace( regex, (_, number) => `${number}`, ), ); } setParsedMessage(message.content); }, [message.content, message.sources, message.role]); return (
{message.role === 'user' && (

{message.content}

)} {message.role === 'assistant' && (
{message.sources && message.sources.length > 0 && (

Sources

)}

Answer

{parsedMessage} {!loading && (
)}

Search videos

)}
); }; export default MessageBox;