"use client"; import { ChatMessage } from "@/lib/types"; import React from "react"; import { formatToolCallToString } from "@/lib/format-tool-call"; import { extractTextFromContentPart } from "@/lib/format-message-content"; // Sub-component or helper for the common label + content structure const MessageBlock: React.FC<{ label: string; labelDetail?: string; content: React.ReactNode; }> = ({ label, labelDetail, content }) => { return (

{label} {labelDetail && ( {labelDetail} )}

{content}
); }; interface ToolCallBlockProps { children: React.ReactNode; className?: string; } const ToolCallBlock = ({ children, className }: ToolCallBlockProps) => { // Common styling for both function call arguments and tool output blocks // Let's use slate-50 background as it's good for code-like content. const baseClassName = "p-3 bg-slate-50 border border-slate-200 rounded-md text-sm"; return (
{children}
); }; interface ChatMessageItemProps { message: ChatMessage; } export function ChatMessageItem({ message }: ChatMessageItemProps) { switch (message.role) { case "system": return ( ); case "user": return ( ); case "assistant": if (message.tool_calls && message.tool_calls.length > 0) { return ( <> {message.tool_calls.map((toolCall: any, index: number) => { const formattedToolCall = formatToolCallToString(toolCall); const toolCallContent = ( {formattedToolCall || "Error: Could not display tool call"} ); return ( ); })} ); } else { return ( ); } case "tool": const toolOutputContent = ( {extractTextFromContentPart(message.content)} ); return ( ); } return null; }