import React from "react"; import { Box, Text } from "ink"; import { highlight } from "cli-highlight"; import type { Message } from "../hooks/useChat.js"; import { useSettings } from "../context/SettingsContext.js"; type MessageViewProps = { message: Message; }; export const MessageView: React.FC = ({ message }) => { const isUser = message.role === "user"; const isSystem = message.role === "system"; const { showThinking } = useSettings(); return ( {isUser ? "You" : isSystem ? "System" : "Assistant"} {message.thinking && ( {showThinking ? "▼ Thinking" : "▶ Thinking (hidden)"} {showThinking && ( {message.thinking} )} )} {renderContent(message.content)} {message.tools && message.tools.length > 0 && ( {message.tools.map((tool) => ( Tool: {tool.name} Args: {JSON.stringify(tool.args)} {tool.isStreaming && Running...} {tool.result && ( Result:{" "} {typeof tool.result === "string" ? tool.result : JSON.stringify(tool.result)} )} ))} )} ); }; function renderContent(content: string) { const parts = content.split(/(```[\s\S]*?```)/g); return parts.map((part, i) => { if (part.startsWith("```")) { const match = part.match(/```(\w*)\n([\s\S]*?)```/); if (match) { const lang = match[1] || "text"; const code = match[2]; try { return ( {highlight(code, { language: lang })} ); } catch { return ( {code} ); } } } return {part}; }); }