import { ReactNode } from 'react'; import type { AgentDelegation } from '@/services/agents/delegation'; interface MiniRAHPanelProps { delegation: AgentDelegation; onNodeClick?: (nodeId: number) => void; } const statusPalette: Record = { queued: { border: '#1f3a5f', badge: '#5c9aff' }, in_progress: { border: '#3b5f2a', badge: '#8bd450' }, completed: { border: '#2a2a2a', badge: '#6b6b6b' }, failed: { border: '#5f2a2a', badge: '#ff6b6b' }, }; const NODE_LINK_REGEX = /\[NODE:(\d+):"([^"]+)"\]/g; function formatStatus(status: string) { switch (status) { case 'queued': return 'Queued'; case 'in_progress': return 'Working'; case 'completed': return 'Completed'; case 'failed': return 'Failed'; default: return status; } } function renderNodeAwareLine(text: string, onNodeClick?: (nodeId: number) => void): ReactNode { const parts: ReactNode[] = []; let lastIndex = 0; text.replace(NODE_LINK_REGEX, (match, id, title, offset) => { if (offset > lastIndex) { parts.push({text.slice(lastIndex, offset)}); } const nodeId = Number(id); const handleClick = () => { if (onNodeClick) onNodeClick(nodeId); }; parts.push( ); lastIndex = offset + match.length; return match; }); if (lastIndex < text.length) { parts.push({text.slice(lastIndex)}); } return <>{parts}; } export default function MiniRAHPanel({ delegation, onNodeClick }: MiniRAHPanelProps) { const palette = statusPalette[delegation.status] ?? statusPalette.queued; const summaryLines = delegation.summary ? delegation.summary.split('\n').filter(Boolean) : []; return (
MINI RA-H ยท {formatStatus(delegation.status)} {new Date(delegation.updatedAt).toLocaleTimeString()}

Task

{delegation.task}

{delegation.context.length > 0 && (

Context

    {delegation.context.map((item, idx) => (
  • {renderNodeAwareLine(item, onNodeClick)}
  • ))}
)} {summaryLines.length > 0 && (

Summary

{summaryLines.map((line, idx) => (

{renderNodeAwareLine(line, onNodeClick)}

))}
)}
); }