Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).

### Added

- **Topology detail panel.** Clicking a session or subagent opens a live side
panel instead of leaving the page: state, branch, title, last active, model,
tokens and cost (own sessions only), its subagents, the last 15 events, and a
link to the full session. The graph stays usable behind it; Esc or a click on
the background closes it.

- **Tell topology sessions and subagents apart.** Session cards show the git
branch (new `sessions.git_branch`, migration 057, from `session.start`; never
stored for `private` sessions) in place of the developer name the parent node
Expand Down
4 changes: 2 additions & 2 deletions packages/dashboard/src/components/flow/AgentNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const EVENT_COLORS: Record<string, string> = {
"teammate.idle": "text-gray-400 bg-gray-500/15",
};

export function AgentNode({ data }: NodeProps & { data: AgentNodeData }) {
export function AgentNode({ data, selected }: NodeProps & { data: AgentNodeData }) {
const { agentId, agentType, description, model, startedAt, latestEvent, isToolRunning, currentToolName } = data;

const debounced = useDebouncedToolState(isToolRunning, currentToolName, latestEvent);
Expand Down Expand Up @@ -70,7 +70,7 @@ export function AgentNode({ data }: NodeProps & { data: AgentNodeData }) {
initial={{ opacity: 0, scale: 0.85 }}
animate={{ opacity: 1, scale: 1, borderColor }}
transition={{ type: "spring", stiffness: 500, damping: 35 }}
className="rounded-xl border bg-gray-900 px-3 py-2 shadow-lg"
className={`rounded-xl border bg-gray-900 px-3 py-2 shadow-lg cursor-pointer hover:brightness-110 ${selected ? "ring-2 ring-blue-400/60" : ""}`}
style={{ width: 240, borderWidth: 1 }}
>
<Handle type="target" position={Position.Top} className="!bg-purple-500" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function AgentSummaryNode({ data }: NodeProps & { data: AgentSummaryNodeD
initial={{ opacity: 0, scale: 0.85 }}
animate={{ opacity: 1, scale: 1 }}
transition={{ type: "spring", stiffness: 500, damping: 35 }}
className="rounded-xl border border-gray-700 bg-gray-900 px-3 py-2 shadow-lg"
className="cursor-pointer rounded-xl border border-gray-700 bg-gray-900 px-3 py-2 shadow-lg hover:brightness-110"
style={{ width: 240 }}
>
<Handle type="target" position={Position.Top} className="!bg-gray-600" />
Expand Down
191 changes: 191 additions & 0 deletions packages/dashboard/src/components/flow/DetailPanel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
import type { ReactNode } from "react";
import type { Node } from "@xyflow/react";
import { Link } from "wouter";
import { GitBranch, X, ExternalLink, Check } from "lucide-react";
import type { FeedEvent } from "@devscope/shared";
import type { SessionNodeData, AgentNodeData, AgentSummaryNodeData } from "./flowTypes";
import { STATE_CONFIG } from "./sessionStates";
import { EVENT_LABELS, getEventSummary } from "@/lib/eventDisplay";
import { formatCost, formatTokenCount, timeAgo } from "@/lib/utils";
import { ProjectLabel } from "@/components/ProjectLabel";

interface DetailPanelProps {
node: Node;
/** All topology nodes, to list a session's subagents. */
nodes: Node[];
onClose: () => void;
}

/** Side panel for the selected topology node; follows its live data. */
export function DetailPanel({ node, nodes, onClose }: DetailPanelProps) {
return (
<aside className="absolute right-0 top-0 z-10 flex h-full w-[380px] max-w-full flex-col border-l border-gray-800 bg-gray-950/95 shadow-2xl backdrop-blur">
<div className="flex justify-end p-2">
<button
onClick={onClose}
className="rounded-md p-1 text-gray-500 hover:bg-gray-800 hover:text-gray-300"
aria-label="Close panel"
>
<X className="h-4 w-4" />
</button>
</div>
<div className="min-h-0 flex-1 overflow-y-auto px-4 pb-4">
{node.type === "session" ? (
<SessionDetails data={node.data as SessionNodeData} nodes={nodes} />
) : (
<AgentDetails data={node.data as AgentNodeData} />
)}
</div>
</aside>
);
}

function SessionDetails({ data, nodes }: { data: SessionNodeData; nodes: Node[] }) {
const { session, activityState, lastActivityAt, recentEvents } = data;
const state = STATE_CONFIG[activityState];
const agents = nodes.filter(
(n) => n.type === "agent" && (n.data as AgentNodeData).sessionId === session.id,
);
const done = nodes.find(
(n) => n.type === "agentSummary" && (n.data as AgentSummaryNodeData).sessionId === session.id,
)?.data as AgentSummaryNodeData | undefined;
// Usage is only returned for the viewer's own sessions.
const hasUsage = session.tokenSource != null;
const totalTokens =
(session.totalInputTokens ?? 0) +
(session.totalOutputTokens ?? 0) +
(session.totalCacheCreationTokens ?? 0) +
(session.totalCacheReadTokens ?? 0);

return (
<div className="space-y-5">
<header className="space-y-1">
<div className="flex items-center justify-between gap-2">
<ProjectLabel name={session.projectName} className="truncate text-base font-semibold text-gray-100" />
<span className={`shrink-0 rounded-full px-2 py-0.5 text-xs font-medium ${state.badgeClass}`}>
{state.label}
</span>
</div>
{session.gitBranch ? (
<div className="flex items-center gap-1 text-xs text-gray-400">
<GitBranch className="h-3 w-3" />
<span className="truncate font-mono">{session.gitBranch}</span>
</div>
) : null}
{session.currentTitle ? (
<p className="text-sm italic text-gray-400">{session.currentTitle}</p>
) : null}
</header>

<dl className="grid grid-cols-2 gap-3 text-sm">
<Fact label="Last active">{timeAgo(lastActivityAt)}</Fact>
<Fact label="Started">{timeAgo(session.startedAt)}</Fact>
{session.model ? <Fact label="Model">{session.model}</Fact> : null}
{hasUsage ? (
<Fact label="Tokens">
{formatTokenCount(totalTokens)} · {formatCost(session.estimatedCostUsd ?? 0)}
</Fact>
) : null}
</dl>

{agents.length > 0 || done ? (
<Section title="Subagents">
<ul className="space-y-2">
{agents.map((n) => {
const agent = n.data as AgentNodeData;
return (
<li key={n.id} className="text-sm">
<span className="font-medium text-purple-200">{agent.agentType}</span>
{agent.model ? <span className="ml-2 font-mono text-xs text-gray-500">{agent.model}</span> : null}
{agent.description ? <div className="truncate text-xs text-gray-400">{agent.description}</div> : null}
</li>
);
})}
{done ? (
<li className="flex items-center gap-1.5 text-xs text-gray-400">
<Check className="h-3 w-3 text-emerald-400" />
{done.total} done: {done.types.map((t) => `${t.agentType} ×${t.count}`).join(", ")}
</li>
) : null}
</ul>
</Section>
) : null}

<RecentActivity events={recentEvents} />

<FullSessionLink sessionId={session.id} />
</div>
);
}

function AgentDetails({ data }: { data: AgentNodeData }) {
return (
<div className="space-y-5">
<header className="space-y-1">
<div className="flex items-center justify-between gap-2">
<span className="text-base font-semibold text-purple-200">{data.agentType}</span>
<span className="rounded-full bg-purple-500/15 px-2 py-0.5 text-xs font-medium text-purple-300">Running</span>
</div>
{data.description ? <p className="text-sm text-gray-300">{data.description}</p> : null}
</header>

<dl className="grid grid-cols-2 gap-3 text-sm">
<Fact label="Started">{timeAgo(data.startedAt)}</Fact>
{data.model ? <Fact label="Model">{data.model}</Fact> : null}
</dl>

<RecentActivity events={data.recentEvents} />

<FullSessionLink sessionId={data.sessionId} />
</div>
);
}

function RecentActivity({ events }: { events: FeedEvent[] }) {
return (
<Section title="Recent activity">
{events.length === 0 ? (
<p className="text-xs text-gray-500">No recent events.</p>
) : (
<ul className="space-y-1.5">
{events.map((event) => (
<li key={event.id} className="flex items-baseline gap-2 text-xs">
<span className="w-24 shrink-0 text-gray-500">{EVENT_LABELS[event.eventType] ?? event.eventType}</span>
<span className="min-w-0 flex-1 truncate text-gray-300">{getEventSummary(event)}</span>
<span className="shrink-0 text-gray-600">{timeAgo(event.timestamp)}</span>
</li>
))}
</ul>
)}
</Section>
);
}

function FullSessionLink({ sessionId }: { sessionId: string }) {
return (
<Link
href={`/dashboard/sessions/${sessionId}`}
className="inline-flex items-center gap-1 text-sm text-blue-400 hover:text-blue-300"
>
Open full session <ExternalLink className="h-3.5 w-3.5" />
</Link>
);
}

function Section({ title, children }: { title: string; children: ReactNode }) {
return (
<section className="space-y-2">
<h3 className="text-xs font-medium uppercase tracking-wide text-gray-500">{title}</h3>
{children}
</section>
);
}

function Fact({ label, children }: { label: string; children: ReactNode }) {
return (
<div>
<dt className="text-xs text-gray-500">{label}</dt>
<dd className="truncate text-gray-200">{children}</dd>
</div>
);
}
39 changes: 36 additions & 3 deletions packages/dashboard/src/components/flow/FlowView.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { Component, useEffect, type ReactNode } from "react";
import { Component, useEffect, useMemo, useState, type ReactNode } from "react";
import {
ReactFlow,
Background,
Controls,
MiniMap,
type Node,
} from "@xyflow/react";
import "@xyflow/react/dist/style.css";
import type { AgentSummaryNodeData } from "./flowTypes";
import { DetailPanel } from "./DetailPanel";
import { nodeTypes } from "./nodeTypes";
import { useFlowLayout } from "./useFlowLayout";
import { useActivityStore } from "@/stores/activityStore";
Expand Down Expand Up @@ -42,17 +45,41 @@ class FlowErrorBoundary extends Component<

const CLEANUP_INTERVAL_MS = 10_000;

/** The node whose details a click opens: sessions and agents; the done card opens its session. */
function selectionFor(node: Node): string | null {
if (node.type === "session" || node.type === "agent") return node.id;
if (node.type === "agentSummary") return `session-${(node.data as AgentSummaryNodeData).sessionId}`;
return null;
}

export function FlowView() {
const { nodes: layoutNodes, edges: layoutEdges } = useFlowLayout();
const connected = useActivityStore((s) => s.connected);
const cleanupStale = useActivityStore((s) => s.cleanupStale);
const [selectedId, setSelectedId] = useState<string | null>(null);

// Periodically remove ended sessions after a grace period, with their finished agents
useEffect(() => {
const id = setInterval(cleanupStale, CLEANUP_INTERVAL_MS);
return () => clearInterval(id);
}, [cleanupStale]);

useEffect(() => {
if (!selectedId) return;
const onKey = (e: KeyboardEvent) => {
if (e.key === "Escape") setSelectedId(null);
};
window.addEventListener("keydown", onKey);
return () => window.removeEventListener("keydown", onKey);
}, [selectedId]);

// The panel follows the node's live data and closes when the node goes away.
const selectedNode = selectedId ? layoutNodes.find((n) => n.id === selectedId) : undefined;
const nodes = useMemo(
() => layoutNodes.map((n) => (n.id === selectedNode?.id ? { ...n, selected: true } : n)),
[layoutNodes, selectedNode?.id],
);

if (layoutNodes.length === 0 && connected) {
return (
<div className="flex h-[calc(100vh-73px)] -m-6 items-center justify-center text-gray-500">
Expand All @@ -71,12 +98,15 @@ export function FlowView() {
}

return (
<div className="h-[calc(100vh-73px)] -m-6">
<div className="relative h-[calc(100vh-73px)] -m-6">
<FlowErrorBoundary>
<ReactFlow
nodes={layoutNodes}
nodes={nodes}
edges={layoutEdges}
nodeTypes={nodeTypes}
onNodeClick={(_, node) => setSelectedId(selectionFor(node))}
onPaneClick={() => setSelectedId(null)}
elementsSelectable={false}
fitView
proOptions={{ hideAttribution: true }}
>
Expand All @@ -95,6 +125,9 @@ export function FlowView() {
maskColor="rgba(0, 0, 0, 0.7)"
/>
</ReactFlow>
{selectedNode ? (
<DetailPanel node={selectedNode} nodes={layoutNodes} onClose={() => setSelectedId(null)} />
) : null}
</FlowErrorBoundary>
</div>
);
Expand Down
Loading