import type { Message } from 'ai'; import React from 'react'; import { classNames } from '~/utils/classNames'; import { AssistantMessage } from './AssistantMessage'; import { UserMessage } from './UserMessage'; interface MessagesProps { id?: string; className?: string; isStreaming?: boolean; messages?: Message[]; avatar?: string; } export const Messages = React.forwardRef((props: MessagesProps, ref) => { const { id, isStreaming = false, messages = [], avatar } = props; return (
{messages.length > 0 ? messages.map((message, index) => { const { role, content } = message; const isUserMessage = role === 'user'; const isFirst = index === 0; const isLast = index === messages.length - 1; return (
{isUserMessage && (
{avatar ? :
}
)}
{isUserMessage ? : }
); }) : null} {isStreaming && (
)}
); });