import React, { Suspense } from 'react'; import { classNames } from '~/utils/classNames'; import WithTooltip from '~/components/ui/Tooltip'; import { getPreviousRepositoryId, type Message } from '~/lib/persistence/message'; import { MessageContents } from './MessageContents'; interface MessagesProps { id?: string; className?: string; hasPendingMessage?: boolean; pendingMessageStatus?: string; messages?: Message[]; onRewind?: (messageId: string) => void; } export const Messages = React.forwardRef((props: MessagesProps, ref) => { const { id, hasPendingMessage = false, pendingMessageStatus = '', messages = [], onRewind } = props; return (
{messages.length > 0 ? messages.map((message, index) => { const { role, id: messageId, repositoryId } = message; const previousRepositoryId = getPreviousRepositoryId(messages, index); const isUserMessage = role === 'user'; const isFirst = index === 0; const isLast = index === messages.length - 1; return (
} > {isUserMessage && (
)}
{previousRepositoryId && repositoryId && onRewind && (
)}
); }) : null} {hasPendingMessage && (
{pendingMessageStatus ? `${pendingMessageStatus}...` : ''}
)} ); });