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[]; } export const Messages = React.forwardRef((props: MessagesProps, ref) => { const { id, isStreaming = false, messages = [] } = props; return (
{messages.length > 0 ? messages.map((message, i) => { const { role, content } = message; const isUser = role === 'user'; const isFirst = i === 0; const isLast = i === messages.length - 1; const isUserMessage = message.role === 'user'; const isAssistantMessage = message.role === 'assistant'; return (
{isUser ? : }
); }) : null} {isStreaming &&
}
); });