import { Text } from '@mantine/core'; import { AGENT_BY_NODE, ENGINE_LABEL, ENGINE_TONE, ENGINE_WORDS, stepName } from '../domain/agents'; import type { NodeState } from '../hooks/useRunStream'; import { Pill } from './common'; // Order of the co-worker graph (coworker/graph/build.py), shown as the vertical "workflow" of step cards. export const LAYOUT: { phase: string; nodes: string[] }[] = [ { phase: 'Research', nodes: ['scout', 'research_module', 'synthesizer'] }, { phase: 'Design', nodes: ['test_generator', 'approval_gate'] }, { phase: 'Data + scripts', nodes: ['data_planner', 'data_executor', 'script_builder'] }, { phase: 'Execute', nodes: ['sign_in_gate', 'executor', 'self_heal'] }, { phase: 'Triage', nodes: ['triage', 'human_review', 'ticket'] }, { phase: 'Report', nodes: ['reporter', 'learner'] }, ]; const STATE_TONE: Record = { pending: 'neutral', running: 'ink', done: 'green', error: 'red', waiting: 'amber', skipped: 'neutral' }; const STATE_LABEL: Record = { pending: 'pending', running: 'running', done: 'done', error: 'failed', waiting: 'waiting for you', skipped: 'skipped' }; type States = Record; /** Vertical workflow: one step card per node, dashed connectors, live state pill. `states` omitted = design view. */ export function GraphView({ states, compact = false, nowFor }: { states?: States; compact?: boolean; nowFor?: (node: string) => { words?: string; connected: boolean } }) { return (
{LAYOUT.flatMap((col) => col.nodes.map((n, i) => ({ n, phase: i === 0 ? col.phase : null }))).map(({ n, phase }) => { const a = AGENT_BY_NODE[n]; const s = states?.[n] ?? { state: 'pending' as NodeState, count: 0, modules: [] }; return (
{phase && !compact && {phase}}
{compact ? stepName(n) : a?.name ?? n} {s.count > 1 && x{s.count}} {states ? {STATE_LABEL[s.state]} : a && (() => { // design view: the pill is the engine the agent is designed for; the tooltip says what serves it now const now = nowFor?.(n); const tip = `Designed for: ${ENGINE_WORDS[a.engine]}.${now?.words ? ` ${now.words}.` : ''} (technical: ${ENGINE_LABEL[a.engine]})`; return {ENGINE_WORDS[a.engine]}; })()}
{!compact && s.modules.length > 0 && workers: {s.modules.join(', ')}}
); })}
); }