|
| 1 | +/** @jsxImportSource @opentui/solid */ |
| 2 | +import { For, Show } from "solid-js" |
| 3 | +import { useTheme } from "@tui/context/theme" |
| 4 | +import { useUIState } from "@tui/context/ui-state" |
| 5 | +import type { AgentStatus, SubAgentState } from "@tui/state/types" |
| 6 | + |
| 7 | +type StatusVisual = { icon: string; color: string } |
| 8 | + |
| 9 | +function getStatusVisual(status: AgentStatus, theme: ReturnType<typeof useTheme>["theme"]): StatusVisual { |
| 10 | + switch (status) { |
| 11 | + case "pending": |
| 12 | + return { icon: "○", color: theme.textMuted.toString() } |
| 13 | + case "running": |
| 14 | + return { icon: "⠋", color: theme.primary.toString() } |
| 15 | + case "completed": |
| 16 | + return { icon: "●", color: theme.success.toString() } |
| 17 | + case "skipped": |
| 18 | + return { icon: "●", color: theme.textMuted.toString() } |
| 19 | + case "retrying": |
| 20 | + return { icon: "⟳", color: theme.warning.toString() } |
| 21 | + case "failed": |
| 22 | + default: |
| 23 | + return { icon: "✗", color: theme.error.toString() } |
| 24 | + } |
| 25 | +} |
| 26 | + |
| 27 | +export function TimelinePanel() { |
| 28 | + const { theme } = useTheme() |
| 29 | + const ui = useUIState() |
| 30 | + const state = ui.state() |
| 31 | + |
| 32 | + const renderSubAgents = (subs: SubAgentState[]) => ( |
| 33 | + <For each={subs}> |
| 34 | + {(sub) => { |
| 35 | + const visual = getStatusVisual(sub.status, theme) |
| 36 | + const isSelected = state.selectedItemType === "sub" && state.selectedSubAgentId === sub.id |
| 37 | + return ( |
| 38 | + <box paddingLeft={2}> |
| 39 | + <text> |
| 40 | + {isSelected ? "> " : " "} |
| 41 | + <span style={{ fg: visual.color }}>{visual.icon}</span>{" "} |
| 42 | + <span style={{ bold: true }}>{sub.name}</span>{" "} |
| 43 | + <span style={{ fg: theme.textMuted }}>{`(${sub.engine})`}</span> |
| 44 | + </text> |
| 45 | + </box> |
| 46 | + ) |
| 47 | + }} |
| 48 | + </For> |
| 49 | + ) |
| 50 | + |
| 51 | + return ( |
| 52 | + <box flexDirection="column" padding={1} border borderColor={theme.borderSubtle} backgroundColor={theme.backgroundPanel} flexGrow={1}> |
| 53 | + <text attributes={1} fg={theme.text}>Timeline</text> |
| 54 | + <Show when={state.agents.length === 0}> |
| 55 | + <text fg={theme.textMuted}>Awaiting agents...</text> |
| 56 | + </Show> |
| 57 | + |
| 58 | + <For each={state.agents}> |
| 59 | + {(agent) => { |
| 60 | + const visual = getStatusVisual(agent.status, theme) |
| 61 | + const isSelected = state.selectedItemType === "main" && state.selectedAgentId === agent.id |
| 62 | + const subAgents = state.subAgents.get(agent.id) || [] |
| 63 | + const isExpanded = state.expandedNodes.has(agent.id) |
| 64 | + const hasSubs = subAgents.length > 0 |
| 65 | + const summarySelected = state.selectedItemType === "summary" && state.selectedAgentId === agent.id |
| 66 | + |
| 67 | + return ( |
| 68 | + <box flexDirection="column" gap={0}> |
| 69 | + <text> |
| 70 | + {isSelected ? "> " : " "} |
| 71 | + <span style={{ fg: visual.color }}>{visual.icon}</span>{" "} |
| 72 | + <span style={{ bold: true }}>{agent.name}</span>{" "} |
| 73 | + <span style={{ fg: theme.textMuted }}>{`(${agent.engine})`}</span> |
| 74 | + {agent.loopRound && agent.loopRound > 0 && ( |
| 75 | + <span style={{ fg: theme.primary }}>{` • Loop ${agent.loopRound}`}</span> |
| 76 | + )} |
| 77 | + </text> |
| 78 | + |
| 79 | + {hasSubs && ( |
| 80 | + <text paddingLeft={1}> |
| 81 | + {summarySelected ? "> " : " "} |
| 82 | + <span style={{ fg: theme.textMuted }}>{isExpanded ? "▼" : "▶"} Sub-agents: {subAgents.length}</span> |
| 83 | + </text> |
| 84 | + )} |
| 85 | + |
| 86 | + {hasSubs && isExpanded && renderSubAgents(subAgents)} |
| 87 | + </box> |
| 88 | + ) |
| 89 | + }} |
| 90 | + </For> |
| 91 | + </box> |
| 92 | + ) |
| 93 | +} |
0 commit comments