// Inspired by Chatbot-UI and modified to fit the needs of this project // @see https://github.com/mckaywrigley/chatbot-ui/blob/main/components/Chat/ChatMessage.tsx import remarkGfm from 'remark-gfm'; import remarkMath from 'remark-math'; import rehypeRaw from 'rehype-raw'; import { useMemo, useState } from 'react'; import { cn } from '@/lib/utils'; import { CodeBlock } from '@/components/ui/CodeBlock'; import { MemoizedReactMarkdown } from '@/components/chat/MemoizedReactMarkdown'; import { IconOpenAI, IconUser } from '@/components/ui/Icons'; import { MessageBase } from '../../lib/types'; import { Tooltip, TooltipContent, TooltipTrigger, } from '@/components/ui/Tooltip'; import Img from '../ui/Img'; import { getCleanedUpMessages } from '@/lib/messageUtils'; import Loading from '../ui/Loading'; import { Table, TableCell, TableHead, TableHeader, TableRow, } from '../ui/Table'; import { Button } from '../ui/Button'; import { Dialog, DialogContent } from '../ui/Dialog'; export interface ChatMessageProps { message: MessageBase; isLoading: boolean; } const Markdown: React.FC<{ content: string; setDetails?: (val: string) => void; }> = ({ content, setDetails }) => { return ( <> {children}; }, thead({ children, ...props }) { return {children}; }, th({ children, ...props }) { return {children}; }, tr({ children, ...props }) { return {children}; }, td({ children, ...props }) { return {children}; }, button({ children, ...props }) { if ('data-details' in props && setDetails) { return ( ); } return ; }, p({ children, ...props }) { if ( props.node.children.some( child => child.type === 'element' && child.tagName === 'img', ) ) { return (

{children}

); } return (

{children}

); }, img(props) { if (props.src?.endsWith('.mp4')) { return (
); }; export function ChatMessage({ message, isLoading, ...props }: ChatMessageProps) { const { logs, content } = useMemo(() => { return getCleanedUpMessages({ content: message.content, role: message.role, }); }, [message.content, message.role]); const [details, setDetails] = useState(''); return (
{message.role === 'user' ? : }
{logs && } {/* */} {isLoading && }
!open && setDetails('')}>
); }