import React, { Suspense } from 'react'; import { classNames } from '~/utils/classNames'; import WithTooltip from '~/components/ui/Tooltip'; import { getPreviousRepositoryId } from '~/lib/persistence/useChatHistory'; import type { Message } from '~/lib/persistence/message'; import { MessageContents } from './MessageContents'; interface MessagesProps { id?: string; className?: string; isStreaming?: boolean; messages?: Message[]; onRewind?: (messageId: string) => void; } export const Messages = React.forwardRef((props: MessagesProps, ref) => { const { id, isStreaming = false, 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} {isStreaming && (
)} ); });