import * as React from "react"; import Markdown from "react-markdown"; import { Prism as SyntaxHighlighter } from "react-syntax-highlighter"; import { oneDark } from "react-syntax-highlighter/dist/esm/styles/prism"; import type { Message, ToolCall } from "../types"; // biome-ignore lint/suspicious/noExplicitAny: react-markdown requires any for component props function CodeBlock({ className, children, ...props }: any) { const match = /language-(\w+)/.exec(className || ""); const isInline = !className; return !isInline && match ? ( {String(children).replace(/\n$/, "")} ) : ( {children} ); } interface MessageItemProps { msg: Message; } function MessageItemInner({ msg }: MessageItemProps) { return (
{msg.role === "user" ? (
{msg.content}
) : msg.role === "tool" ? (
Tool Output {msg.tool_call_id && ` (${msg.tool_call_id})`}
							{msg.content}
						
) : (
{msg.content}
)} {msg.tool_calls && (
{msg.tool_calls.map((tc: ToolCall, i: number) => { let argsSummary = ""; try { const args = JSON.parse(tc.function.arguments); const firstKey = Object.keys(args)[0]; if (firstKey && args[firstKey]) { argsSummary = String(args[firstKey]); if (argsSummary.length > 50) { argsSummary = `${argsSummary.substring(0, 47)}...`; } } } catch (_e) { // ignore } return (
{tc.function.name} {argsSummary && `(${argsSummary})`}
); })}
)}
); } export const MessageItem = React.memo(MessageItemInner);