import { Check, Copy } from "lucide-react"; import { Message } from "ai"; import { Fragment } from "react"; import { Button } from "../../button"; import { useCopyToClipboard } from "../hooks/use-copy-to-clipboard"; import { ChatHandler, DocumentFileData, EventData, ImageData, MessageAnnotation, MessageAnnotationType, SourceData, SuggestedQuestionsData, ToolData, getAnnotationData, } from "../index"; import ChatAvatar from "./chat-avatar"; import { ChatEvents } from "./chat-events"; import { ChatFiles } from "./chat-files"; import { ChatImage } from "./chat-image"; import { ChatSources } from "./chat-sources"; import { SuggestedQuestions } from "./chat-suggestedQuestions"; import ChatTools from "./chat-tools"; import Markdown from "./markdown"; type ContentDisplayConfig = { order: number; component: JSX.Element | null; }; function ChatMessageContent({ message, isLoading, append, }: { message: Message; isLoading: boolean; append: Pick["append"]; }) { const annotations = message.annotations as MessageAnnotation[] | undefined; if (!annotations?.length) return ; const imageData = getAnnotationData( annotations, MessageAnnotationType.IMAGE, ); const contentFileData = getAnnotationData( annotations, MessageAnnotationType.DOCUMENT_FILE, ); const eventData = getAnnotationData( annotations, MessageAnnotationType.EVENTS, ); const sourceData = getAnnotationData( annotations, MessageAnnotationType.SOURCES, ); const toolData = getAnnotationData( annotations, MessageAnnotationType.TOOLS, ); const suggestedQuestionsData = getAnnotationData( annotations, MessageAnnotationType.SUGGESTED_QUESTIONS, ); const contents: ContentDisplayConfig[] = [ { order: 1, component: imageData[0] ? : null, }, { order: -3, component: eventData.length > 0 ? ( ) : null, }, { order: 2, component: contentFileData[0] ? ( ) : null, }, { order: -1, component: toolData[0] ? : null, }, { order: 0, component: , }, { order: 3, component: sourceData[0] ? : null, }, { order: 4, component: suggestedQuestionsData[0] ? ( ) : null, }, ]; return (
{contents .sort((a, b) => a.order - b.order) .map((content, index) => ( {content.component} ))}
); } export default function ChatMessage({ chatMessage, isLoading, append, }: { chatMessage: Message; isLoading: boolean; append: Pick["append"]; }) { const { isCopied, copyToClipboard } = useCopyToClipboard({ timeout: 2000 }); return (
); }