import dayjs from 'dayjs' import { noop } from 'lodash' import Image from 'next/image' import { PropsWithChildren, memo, useMemo } from 'react' import ReactMarkdown from 'react-markdown' import remarkGfm from 'remark-gfm' import { AiIconAnimation, Badge, cn, markdownComponents } from 'ui' import { useProfile } from 'lib/profile' import { DiffType } from '../SQLEditor.types' import { AiMessagePre } from './AiMessagePre' interface MessageProps { name?: string role: 'function' | 'system' | 'user' | 'assistant' | 'data' | 'tool' content?: string createdAt?: number isDebug?: boolean isSelected?: boolean onDiff?: (type: DiffType, s: string) => void action?: React.ReactNode } const Message = memo(function Message({ name, role, content, createdAt, isDebug, isSelected = false, onDiff = noop, children, action = <>, }: PropsWithChildren) { const { profile } = useProfile() const icon = useMemo(() => { return role === 'assistant' ? ( ) : (
avatar
) }, [content, profile?.username, role]) if (!content) return null return (
{icon} {role === 'assistant' ? 'Assistant' : name ? name : 'You'} {createdAt && ( {dayjs(createdAt).fromNow()} )} {isDebug && Debug request}
{' '} {action}
{ return ( div>pre]:!border-stronger [&>div>pre]:!bg-surface-200' : '' )} > {props.children[0].props.children} ) }, }} > {content} {children}
) }) export default Message