/** * MessageItem component * Renders individual chat messages with actions for assistant messages */ import { Copy, RotateCcw } from "lucide-react"; import { defaultRehypePlugins, Streamdown } from "streamdown"; import { Action, Actions, } from "@/components/lighthouse-v1/ai-elements/actions"; import { ChainOfThoughtDisplay } from "@/components/lighthouse-v1/chain-of-thought-display"; import { extractChainOfThoughtEvents, extractMessageText, type Message, MESSAGE_ROLES, MESSAGE_STATUS, } from "@/components/lighthouse-v1/chat-utils"; import { Loader } from "@/components/lighthouse-v1/loader"; import { escapeAngleBracketPlaceholders } from "@/lib/markdown"; interface MessageItemProps { message: Message; index: number; isLastMessage: boolean; status: string; onCopy: (text: string) => void; onRegenerate: () => void; } export function MessageItem({ message, index, isLastMessage, status, onCopy, onRegenerate, }: MessageItemProps) { const messageText = extractMessageText(message); // Check if this is the streaming assistant message const isStreamingAssistant = isLastMessage && message.role === MESSAGE_ROLES.ASSISTANT && status === MESSAGE_STATUS.STREAMING; // Use a composite key to ensure uniqueness even if IDs are duplicated temporarily const uniqueKey = `${message.id}-${index}-${message.role}`; // Extract chain-of-thought events from message parts const chainOfThoughtEvents = extractChainOfThoughtEvents(message); return (
{messageText}
) : ( // Assistant messages: render with markdown support