import { UIMessage as VercelMessage } from '@ai-sdk/react' import { memo, type PropsWithChildren } from 'react' import { cn } from 'ui' import { useMessageInfoContext } from './Message.Context' import { MessagePartSwitcher } from './Message.Parts' import { MessageMarkdown } from './MessageMarkdown' import { ProfileImage as ProfileImageDisplay } from '@/components/ui/ProfileImage' import { useProfileNameAndPicture } from '@/lib/profile' function MessageDisplayProfileImage() { const { username, avatarUrl } = useProfileNameAndPicture() return ( ) } function MessageDisplayContainer({ children, onClick, className, }: PropsWithChildren<{ onClick?: () => void; className?: string }>) { return (
{children}
) } function MessageDisplayMainArea({ children, className, }: PropsWithChildren<{ className?: string }>) { return
{children}
} const MessageDisplayContent = memo(function MessageDisplayContent({ message, }: { message: VercelMessage }) { const { id, isLoading, readOnly } = useMessageInfoContext() const messageParts = message.parts const content = ('content' in message && typeof message.content === 'string' && message.content.trim()) || undefined return (
{messageParts?.length > 0 ? messageParts.map((part: NonNullable, idx) => { // The SDK exposes its mutable object on the first write, then publishes clones. // Capture state/text now so later mutations cannot change memo's previous props. return }) : content && (
{content}
)}
) }) function MessageDisplayTextMessage({ id, isLoading, readOnly, children, }: PropsWithChildren<{ id: string; isLoading: boolean; readOnly?: boolean }>) { return ( {children} ) } export const MessageDisplay = { Container: MessageDisplayContainer, Content: MessageDisplayContent, MainArea: MessageDisplayMainArea, ProfileImage: MessageDisplayProfileImage, }