Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | 38x 197x 83x 83x 19x 19x 19x 38x 38x 38x 38x 38x 267x 220x 220x 220x 142x 117x 117x 34x 38x 38x 144x 31x 31x | import {
LANE_NODE_IDS,
SYSTEM_NODES,
SystemNodeMeta,
} from "@/objects/systemNodes";
import type { StageState } from "@/util/pipelineUtils";
import {
AlertTriangle,
CheckCircle2,
CircleDashed,
CircleSlash,
Database,
Hand,
Settings2,
Users,
XCircle,
} from "lucide-react";
import React from "react";
/**
* Presentation metadata for execution-graph nodes and pipeline stage states —
* the single source of truth for how a node or stage is named and coloured,
* shared by the stage rail, the stage cards and the persisted-trace view.
*/
// ─── System node identity ─────────────────────────────────────────────────────
/** Every system node's name and icon (`objects/systemNodes.ts`). */
export const SYSTEM_NODE_CONFIG: Record<string, SystemNodeMeta> = SYSTEM_NODES;
export function systemNodeLabel(nodeId: string): string {
return SYSTEM_NODE_CONFIG[nodeId]?.label ?? nodeId;
}
/** A system node's icon at ``className``'s size (the pipeline's by default). */
export function systemNodeIcon(
nodeId: string,
className = "w-3.5 h-3.5 shrink-0",
): React.ReactNode {
const Icon = SYSTEM_NODE_CONFIG[nodeId]?.Icon ?? Settings2;
return <Icon className={className} />;
}
/** A kind of knowledge as its lane is named: "Domain", "Temporal". */
export function kindLabel(category: string): string {
const nodeId = LANE_NODE_IDS[category as keyof typeof LANE_NODE_IDS];
return nodeId ? systemNodeLabel(nodeId).replace(/ Retrieval$/, "") : category;
}
/** A parallel stage's branch, short, for the rail: a lane's kind, "External",
* "Tool". */
export function branchLabel(nodeId: string): string {
return systemNodeLabel(nodeId).replace(/ Retrieval$/, "");
}
/** What each input profile of a turn's knowledge mix means: svc-ai's
* `knowledge.mix.PROFILES`, word for word (pinned by `KnowledgeLanes.test.tsx`). */
export const PROFILE_LABELS: Record<string, string> = {
triage_failed: "Triage could not read the request: every kind it holds",
current_web: "About what is current, and sent to the web: dated knowledge only",
analysis_current: "A worked problem about what is current",
current: "About what is current",
analysis: "A worked problem: analysis or a decision",
lookup: "A lookup",
};
export const sysLbl = "text-[10px] font-semibold uppercase tracking-wide text-blue-500 dark:text-blue-400 mb-0.5";
export const sysBlock = "font-mono text-[11px] leading-relaxed text-gray-500 dark:text-gray-400 bg-blue-50 dark:bg-blue-950/20 rounded px-2 py-1.5 line-clamp-6";
// ─── Stage identity ───────────────────────────────────────────────────────────
/**
* Labels for stages that cover several nodes, where no single node name fits.
* Keyed by the stage id svc-ai announces in its `graph_plan` frame.
*/
const STAGE_LABELS: Record<string, string> = {
retrieval: "Retrieval",
};
const STAGE_ICONS: Record<string, React.ReactNode> = {
retrieval: <Database className="w-3.5 h-3.5 shrink-0" />,
};
/** Display name for a stage: its own label, else its single node's label. */
export function stageLabel(stage: {
id: string;
node_ids: string[];
is_system_stage: boolean;
}): string {
if (STAGE_LABELS[stage.id]) return STAGE_LABELS[stage.id];
const [first] = stage.node_ids;
Iif (!first) return stage.id;
return stage.is_system_stage ? systemNodeLabel(first) : first;
}
export function stageIcon(stage: {
id: string;
node_ids: string[];
is_system_stage: boolean;
}): React.ReactNode {
if (STAGE_ICONS[stage.id]) return STAGE_ICONS[stage.id];
const [first] = stage.node_ids;
if (stage.is_system_stage && first) return systemNodeIcon(first);
return <Users className="w-3.5 h-3.5 shrink-0" />;
}
// ─── Stage state presentation ─────────────────────────────────────────────────
export type StageStateStyle = {
/** Short uppercase status word for the chip tooltip and card badge. */
label: string;
/** Chip container classes (border + background + text). */
chip: string;
/** Text/icon accent. */
accent: string;
/** Connector segment leading out of this stage. */
connector: string;
/** Status glyph shown on the chip and the card row. */
icon: React.ReactNode;
};
const glyph = "w-3.5 h-3.5 shrink-0";
export const STAGE_STATE_STYLES: Record<StageState, StageStateStyle> = {
pending: {
label: "Pending",
chip: "border-dashed border-gray-200 dark:border-gray-700 bg-gray-50/60 dark:bg-gray-900/40 text-gray-400 dark:text-gray-600",
accent: "text-gray-300 dark:text-gray-600",
connector: "bg-gray-200 dark:bg-gray-700",
icon: <CircleDashed className={glyph} />,
},
running: {
label: "Running",
chip: "border-violet-300 dark:border-violet-700 bg-violet-50 dark:bg-violet-950/40 text-violet-700 dark:text-violet-300 ring-2 ring-violet-200/70 dark:ring-violet-800/40",
accent: "text-violet-500 dark:text-violet-400",
connector: "bg-violet-300 dark:bg-violet-700",
icon: (
<span className="relative flex w-3.5 h-3.5 items-center justify-center shrink-0">
<span className="absolute w-3.5 h-3.5 rounded-full bg-violet-400/40 animate-ping" />
<span className="w-2 h-2 rounded-full bg-violet-500 dark:bg-violet-400" />
</span>
),
},
awaiting: {
label: "Waiting for you",
chip: "border-amber-400 dark:border-amber-600 bg-amber-50 dark:bg-amber-950/40 text-amber-800 dark:text-amber-200 ring-2 ring-amber-200/80 dark:ring-amber-800/50",
accent: "text-amber-600 dark:text-amber-400",
connector: "bg-amber-300 dark:bg-amber-700",
icon: <Hand className={`${glyph} animate-pulse`} />,
},
done: {
label: "Complete",
chip: "border-emerald-200 dark:border-emerald-800/70 bg-emerald-50 dark:bg-emerald-950/30 text-emerald-700 dark:text-emerald-300",
accent: "text-emerald-500 dark:text-emerald-400",
connector: "bg-emerald-300 dark:bg-emerald-700",
icon: <CheckCircle2 className={glyph} />,
},
skipped: {
label: "Skipped",
chip: "border-dashed border-gray-200 dark:border-gray-800 bg-transparent text-gray-400 dark:text-gray-600",
accent: "text-gray-300 dark:text-gray-600",
connector: "bg-gray-200 dark:bg-gray-800",
icon: <CircleSlash className={glyph} />,
},
// Some branches of a parallel stage failed and the rest went on: the
// stage handed on less, not nothing.
degraded: {
label: "Partial",
chip: "border-amber-300 dark:border-amber-800 bg-amber-50 dark:bg-amber-950/30 text-amber-800 dark:text-amber-200",
accent: "text-amber-500 dark:text-amber-400",
connector: "bg-amber-300 dark:bg-amber-700",
icon: <AlertTriangle className={glyph} />,
},
failed: {
label: "Failed",
chip: "border-red-300 dark:border-red-800 bg-red-50 dark:bg-red-950/30 text-red-700 dark:text-red-300",
accent: "text-red-500 dark:text-red-400",
connector: "bg-red-300 dark:bg-red-800",
icon: <XCircle className={glyph} />,
},
};
// ─── Formatting ───────────────────────────────────────────────────────────────
export function formatDuration(ms: number): string {
if (ms <= 0) return "";
Iif (ms < 1000) return `${ms}ms`;
Eif (ms < 60_000) return `${(ms / 1000).toFixed(1)}s`;
return `${Math.floor(ms / 60_000)}m ${Math.round((ms % 60_000) / 1000)}s`;
}
export function formatTokens(count: number): string {
if (count < 1000) return `${count}`;
return `${(count / 1000).toFixed(count < 10_000 ? 1 : 0)}k`;
}
|