File size: 3,852 Bytes
a289b2a
ceab56c
a289b2a
 
 
 
 
 
 
 
 
 
 
 
aa61ac1
a289b2a
 
 
 
 
8f23c37
a289b2a
 
 
 
 
 
 
 
 
 
 
aa61ac1
a289b2a
 
 
2effee4
a289b2a
 
 
8f23c37
 
 
 
 
 
a289b2a
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { Text } from '@mantine/core';
import { AGENT_BY_NODE, ENGINE_LABEL, ENGINE_TONE, ENGINE_WORDS, stepName } from '../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: ['executor', 'self_heal'] },
  { phase: 'Triage', nodes: ['triage', 'human_review', 'ticket'] },
  { phase: 'Report', nodes: ['reporter', 'learner'] },
];
const STATE_TONE: Record<NodeState, string> = { pending: 'neutral', running: 'ink', done: 'green', error: 'red', waiting: 'amber', skipped: 'neutral' };
const STATE_LABEL: Record<NodeState, string> = { pending: 'pending', running: 'running', done: 'done', error: 'failed', waiting: 'waiting for you', skipped: 'skipped' };

type States = Record<string, { state: NodeState; count: number; modules: string[] }>;

/** 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 (
    <div role="list" aria-label="graph nodes">

      {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 (

          <div key={n}>

            {phase && !compact && <Text className="fpt-tree-title" mt={10} mb={4}>{phase}</Text>}

            <div role="listitem" aria-label={`${n} ${s.state}`} data-testid={`node-${n}`} data-state={s.state}

              className={`fpt-card fpt-step${s.state === 'running' ? ' fpt-live' : ''}`}

              style={{ opacity: s.state === 'skipped' ? 0.55 : 1, borderStyle: s.state === 'skipped' ? 'dashed' : 'solid',

                borderColor: s.state === 'waiting' ? 'var(--pill-amber-fg)' : s.state === 'running' ? 'var(--pill-ink-fg)' : undefined }}>

              <div style={{ display: 'flex', alignItems: 'center', gap: 8, justifyContent: 'space-between' }}>

                <span style={{ display: 'flex', alignItems: 'center', gap: 8, minWidth: 0 }}>

                  <span className="fpt-dot" style={{ background: `var(--pill-${a?.tone ?? 'neutral'}-fg)` }} aria-hidden />

                  <Text size="sm" fw={600} truncate title={`graph node: ${n}`}>{compact ? stepName(n) : a?.name ?? n}</Text>

                  {s.count > 1 && <Pill tone="lav">x{s.count}</Pill>}

                </span>

                {states ? <Pill tone={STATE_TONE[s.state]}>{STATE_LABEL[s.state]}</Pill>

                  : 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 <Pill tone={ENGINE_TONE[a.engine]} outline={!!now && !now.connected} title={tip}>{ENGINE_WORDS[a.engine]}</Pill>;

                  })()}

              </div>

              {!compact && s.modules.length > 0 && <Text size="xs" c="dimmed" mt={4}>workers: {s.modules.join(', ')}</Text>}

            </div>

          </div>

        );

      })}

    </div>
  );
}