import { useConversation } from '../context/ConversationContext';
import { getChildren } from '../utils/tree';
export default function MessageBubble({ node, onBranch }) {
const { state } = useConversation();
const conv = state.conversations[state.activeConversationId];
const childCount = conv ? getChildren(conv.nodes, node.id).length : 0;
return (
<>
{/* User message */}
{node.userMessage}
{childCount > 1 && (
⑂ {childCount}
)}
U
{/* Assistant message */}
AI
{node.status === 'generating' && !node.assistantMessage && (
Generating…
)}
{node.status === 'error' && (
❌ Error generating response
)}
{node.assistantMessage && (
)}
>
);
}
/**
* Very lightweight markdown-ish formatting.
* Converts **bold**, *italic*, `code`, and newlines.
*/
function formatMessage(text) {
return text
.replace(/&/g, '&')
.replace(//g, '>')
.replace(/\*\*(.+?)\*\*/g, '$1')
.replace(/\*(.+?)\*/g, '$1')
.replace(/`([^`]+)`/g, '$1')
.replace(/\n/g, '
');
}