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 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 | 15x 15x 15x 8x 8x 8x 8x 8x 8x 8x 15x 24x 24x 24x 2x 22x 7x 7x 7x 7x 7x 7x 7x 15x 1x 1x 14x 14x 1x 1x 13x 1x 1x 12x 8x 8x 8x 8x 8x 4x 4x 4x 4x 5x 5x | import {
LaneFunnel,
MixNote,
PackingTable,
PlanLanes,
} from "@/components/chat/ExecutionPipeline/KnowledgeLanes";
import RuleEvaluationList from "@/components/chat/ExecutionPipeline/RuleEvaluationList";
import {
SYSTEM_NODE_CONFIG,
sysBlock,
sysLbl,
} from "@/components/chat/ExecutionPipeline/nodeMeta";
import {
KnowledgeInventoryNote,
RetrievalReportNotes,
TriageChoiceNote,
} from "@/components/chat/ExecutionPipeline/TraceNotes";
import { isRuleNodeId } from "@/util/ruleTrace";
import {
recallBasisLabel,
recalledMemory,
recalledMemoryLabel,
} from "@/util/agentMemory";
import {
KNOWLEDGE_PLAN_NODE_ID,
RETRIEVAL_JOIN_NODE_ID,
laneKind,
} from "@/objects/systemNodes";
import {
knowledgePlanResult,
lanePacking,
laneSearchResult,
retrievalReport,
triageChoice,
} from "@/util/systemNodeTrace";
import React from "react";
/**
* Structured renderers for each system node's result payload — the expanded
* body of a stage card (gate routing, the execution plan, retrieval context,
* evaluator scores, governance rule actions, …).
*/
/** Renders the input context (prompt) passed to a system node's LLM call. */
const NodeInputSection: React.FC<{ input: Record<string, unknown> }> = ({ input }) => {
const query = input.input ? String(input.input) : null;
const extras = Object.entries(input).filter(([k]) => k !== "input");
if (!query && extras.length === 0) return null;
return (
<div className="space-y-1.5 border-b border-blue-100 dark:border-blue-900/40 pb-2 mb-2">
<p className="text-[10px] font-semibold uppercase tracking-wide text-gray-400 dark:text-gray-500">
Node Input
</p>
{query && (
<p className={sysBlock}>{query}</p>
)}
{extras.map(([k, v]) => (
<div key={k} className="flex gap-1.5 text-[10px] font-mono">
<span className="text-blue-500 dark:text-blue-400 shrink-0">{k}:</span>
<span className="text-gray-500 dark:text-gray-400 truncate">
{typeof v === "boolean" ? String(v) : Array.isArray(v) ? (v as unknown[]).join(", ") || "—" : String(v ?? "—")}
</span>
</div>
))}
</div>
);
};
/** What triage's scope check found, as a person reads it. */
const SCOPE_CHECK: Record<string, string> = {
clear: "clear — nothing to ask",
ambiguous: "unclear — asked first",
unavailable: "could not run",
};
/**
* The task's shape: how complex it is, whether the skill graph runs, the
* tools it is likely to need, and the scope check. Decided by triage in the
* same call as the route (the gate's result); stored traces from before
* October 2026 carry it on a separate `__recon__` stage.
*/
const TaskShape: React.FC<{ r: Record<string, unknown> }> = ({ r }) => {
const complexity = r.complexity ? String(r.complexity) : "";
const useSkillGraph = r.use_skill_graph as boolean | undefined;
const tools = (r.relevant_tools as string[] | undefined) ?? [];
const notes = r.resource_notes ? String(r.resource_notes) : "";
const scope = r.scope_check ? String(r.scope_check) : "";
const reason = r.ambiguity_reason ? String(r.ambiguity_reason) : "";
return (
<>
{complexity && (
<div className="flex gap-3 text-[11px] font-mono">
<span className="text-gray-400 dark:text-gray-500">complexity:</span>
<span className="font-semibold text-blue-600 dark:text-blue-400">{complexity}</span>
<span className="text-gray-400 dark:text-gray-500">skill graph:</span>
<span className={`font-semibold ${useSkillGraph ? "text-emerald-600 dark:text-emerald-400" : "text-amber-600 dark:text-amber-400"}`}>
{useSkillGraph ? "yes" : "no"}
</span>
</div>
)}
{scope && (
<p className="text-[11px] text-gray-500 dark:text-gray-400">
{`Scope check: ${SCOPE_CHECK[scope] ?? scope}`}
{reason && (
<span className="block text-gray-400 dark:text-gray-500">{reason}</span>
)}
</p>
)}
{tools.length > 0 && (
<div>
<p className={sysLbl}>Suggested Tools</p>
<p className="font-mono text-[11px] text-gray-500 dark:text-gray-400">{tools.join(", ")}</p>
</div>
)}
{notes && (
<div>
<p className={sysLbl}>Strategy Notes</p>
<p className="text-[11px] text-gray-600 dark:text-gray-300 leading-relaxed">{notes}</p>
</div>
)}
</>
);
};
/** Render structured result data for a completed system node's expanded view. */
const SystemNodeResultView: React.FC<{
nodeId: string;
result: unknown;
input?: Record<string, unknown>;
}> = ({ nodeId, result, input }) => {
Iif (!result || typeof result !== "object") {
if (input && Object.keys(input).length > 0) {
return <NodeInputSection input={input} />;
}
return null;
}
const r = result as Record<string, unknown>;
if (isRuleNodeId(nodeId)) {
return <RuleEvaluationList nodeId={nodeId} result={r} />;
}
if (nodeId === "__gate__") {
const route = r.route ? String(r.route) : "";
// Meaningful only for a retrieve route: svc-ai fills it for every route,
// and "direct · internal" read as an internal search that never ran.
const rtype =
route === "retrieve" && r.retrieval_type ? String(r.retrieval_type) : "";
const trivialOutput = r.trivial_output ? String(r.trivial_output) : "";
// Both absent on traces stored before svc-ai sent them.
const triage = triageChoice(r.triage);
const inventoryIncomplete = r.kb_inventory_complete === false;
const ROUTE_DESC: Record<string, string> = {
direct: "Answered directly — no planning or retrieval.",
plan: "Complex task — planning runs before skill nodes.",
retrieve: "Retrieval before skill nodes, no planning.",
plan_retrieve: "Full pipeline — planning + retrieval.",
trivial: "Trivial input — answered without LLM.",
};
return (
<div className="space-y-1.5">
{input && Object.keys(input).length > 0 && <NodeInputSection input={input} />}
{trivialOutput ? (
<p className={sysBlock}>{trivialOutput}</p>
) : (
<p className="text-[11px] text-blue-600 dark:text-blue-400 font-medium">
{route ? `Route: ${route}${rtype ? ` · ${rtype}` : ""}` : "Routing performed"}
{route && ROUTE_DESC[route] && (
<span className="block text-gray-400 dark:text-gray-500 font-normal mt-0.5">
{ROUTE_DESC[route]}
</span>
)}
</p>
)}
{!trivialOutput && triage && <TriageChoiceNote triage={triage} />}
{!trivialOutput && <TaskShape r={r} />}
{inventoryIncomplete && <KnowledgeInventoryNote />}
</div>
);
}
// Stored traces from before triage decided the task's shape itself.
if (nodeId === "__recon__") {
const reconCtx = r.recon_context ? String(r.recon_context) : "";
return (
<div className="space-y-1.5">
{input && Object.keys(input).length > 0 && <NodeInputSection input={input} />}
<TaskShape r={r} />
{reconCtx && (
<div>
<p className={sysLbl}>Recon Context</p>
<p className={sysBlock}>{reconCtx}</p>
</div>
)}
</div>
);
}
Iif (nodeId === "__planning__") {
const plans = r.node_plans as
| { node_id: string; goal: string; expected_output?: string }[]
| undefined;
const overallGoal = r.overall_goal ? String(r.overall_goal) : "";
const retrievalFocus = r.retrieval_focus ? String(r.retrieval_focus) : "";
// The planner may plan for a node without dispatching it — the dispatch
// list is what actually determines which skill stages run.
const dispatched = Array.isArray(r.active_node_ids)
? (r.active_node_ids as unknown[]).map(String)
: null;
return (
<div className="space-y-2">
{input && Object.keys(input).length > 0 && <NodeInputSection input={input} />}
{dispatched && (
<div>
<p className={sysLbl}>Dispatched Nodes</p>
{dispatched.length === 0 ? (
<p className="text-gray-500 dark:text-gray-400 italic">
Skill graph bypassed — synthesis answers from retrieved context.
</p>
) : (
<div className="flex flex-wrap gap-1">
{dispatched.map((nodeId) => (
<span
key={nodeId}
className="px-1.5 py-0.5 rounded font-mono text-[10px] font-semibold bg-blue-100 dark:bg-blue-900/50 text-blue-700 dark:text-blue-300"
>
{nodeId}
</span>
))}
</div>
)}
</div>
)}
{overallGoal && (
<div>
<p className={sysLbl}>Overall Goal</p>
<p className="text-gray-600 dark:text-gray-300 leading-relaxed">{overallGoal}</p>
</div>
)}
{retrievalFocus && (
<div>
<p className={sysLbl}>Retrieval Focus</p>
<p className="text-gray-600 dark:text-gray-300 leading-relaxed">{retrievalFocus}</p>
</div>
)}
{plans && plans.length > 0 && (
<div>
<p className={sysLbl}>Node Plans</p>
<div className="space-y-1">
{plans.map((p) => (
<div
key={p.node_id}
className="px-2 py-1.5 rounded bg-blue-50 dark:bg-blue-950/30 border border-blue-100 dark:border-blue-900/50"
>
<span className="font-mono font-semibold text-blue-700 dark:text-blue-300">
{SYSTEM_NODE_CONFIG[p.node_id]?.label ?? p.node_id}
</span>
<p className="text-gray-500 dark:text-gray-400 mt-0.5 leading-relaxed">{p.goal}</p>
</div>
))}
</div>
</div>
)}
</div>
);
}
if (nodeId === KNOWLEDGE_PLAN_NODE_ID) {
const plan = knowledgePlanResult(r);
return (
<div className="space-y-1.5">
{input && Object.keys(input).length > 0 && <NodeInputSection input={input} />}
{plan?.mix && <MixNote mix={plan.mix} />}
{plan && <PlanLanes plan={plan} />}
{plan?.error && (
<p className="text-[11px] text-red-600 dark:text-red-400">{`Planning failed: ${plan.error}`}</p>
)}
</div>
);
}
if (laneKind(nodeId)) {
const lane = laneSearchResult(r);
return (
<div className="space-y-1.5">
{input && Object.keys(input).length > 0 && <NodeInputSection input={input} />}
{lane ? (
<>
<p className="text-[11px] text-gray-500 dark:text-gray-400">
{`${lane.role || "Lane"} · ${lane.kb_ids.length} knowledge base${lane.kb_ids.length === 1 ? "" : "s"}`}
</p>
<LaneFunnel lane={lane} />
</>
) : null}
</div>
);
}
if (
nodeId === "__retrieval__" ||
nodeId === "__internal_retrieval__" ||
nodeId === RETRIEVAL_JOIN_NODE_ID ||
nodeId === "__external_retrieval__" ||
nodeId === "__tool_retrieval__"
) {
const ctx = r.retrieval_context ? String(r.retrieval_context) : "";
// The frameworks found in reasoning knowledge, handed on apart from the
// evidence; absent with none.
const frameworks = r.frameworks_context ? String(r.frameworks_context) : "";
// Absent on traces stored before svc-ai sent it, and when nothing is set.
const report = retrievalReport(r.report);
// The join's: how each lane fared in packing.
const packed = lanePacking(r.lanes);
return (
<div className="space-y-1.5">
{input && Object.keys(input).length > 0 && <NodeInputSection input={input} />}
{report && <RetrievalReportNotes report={report} />}
<PackingTable lanes={packed} />
{frameworks && <p className={sysBlock}>{frameworks}</p>}
{ctx ? (
<p className={sysBlock}>{ctx}</p>
) : (
!frameworks && (
<p className="text-gray-400 dark:text-gray-500 italic">No context retrieved.</p>
)
)}
</div>
);
}
Iif (nodeId === "__synthesis__") {
const out = r.output ? String(r.output) : "";
return (
<div className="space-y-1.5">
{input && Object.keys(input).length > 0 && <NodeInputSection input={input} />}
{out ? (
<p className="leading-relaxed text-gray-600 dark:text-gray-300 line-clamp-6 bg-blue-50 dark:bg-blue-950/20 rounded px-2 py-1.5">
{out}
</p>
) : null}
</div>
);
}
Eif (nodeId === "__memory_read__") {
const memories = Array.isArray(r.memories) ? r.memories.map(recalledMemory) : [];
return (
<div className="space-y-1.5">
{input && Object.keys(input).length > 0 && <NodeInputSection input={input} />}
{memories.length === 0 ? (
<p className="text-gray-400 dark:text-gray-500 italic">No prior memories found.</p>
) : (
<>
<p className={sysLbl}>{memories.length} memor{memories.length === 1 ? "y" : "ies"} recalled</p>
{memories.map((m, i) => {
const basis = recallBasisLabel(m);
return (
<div key={i} className={sysBlock}>
<p className="text-[10px] font-semibold uppercase tracking-wide text-violet-600 dark:text-violet-400">
{recalledMemoryLabel(m)}
</p>
<p className="line-clamp-3">{m.text}</p>
{basis && (
<p
className="mt-0.5 text-[10px] text-gray-400 dark:text-gray-500"
title="Why recall chose it. Words: how much of the request's wording it covers (0–1). Meaning: how close its embedding is to the request's."
>
{basis}
</p>
)}
</div>
);
})}
</>
)}
</div>
);
}
if (nodeId === "__memory_write__") {
const { stored, content } = r as { stored?: boolean; content?: string };
return (
<div className="space-y-1.5">
{input && Object.keys(input).length > 0 && <NodeInputSection input={input} />}
{stored ? (
<>
<p className={sysLbl}>Memory stored</p>
<p className={`${sysBlock} line-clamp-4`}>{String(content ?? "")}</p>
</>
) : (
<p className="text-gray-400 dark:text-gray-500 italic">Nothing stored.</p>
)}
</div>
);
}
if (nodeId === "__evaluator__") {
const passed = r.passed as boolean | undefined;
const score = r.score as number | undefined;
const gaps = (r.gaps as string[] | undefined) ?? [];
const critique = r.critique ? String(r.critique) : "";
const finalOut = r.final_output ? String(r.final_output) : "";
return (
<div className="space-y-1.5">
{input && Object.keys(input).length > 0 && <NodeInputSection input={input} />}
<div className="flex items-center gap-3 text-[11px] font-mono">
{score !== undefined && (
<span className={`font-semibold ${score >= 80 ? "text-emerald-600 dark:text-emerald-400" : score >= 50 ? "text-amber-600 dark:text-amber-400" : "text-red-600 dark:text-red-400"}`}>
{score}/100
</span>
)}
{passed !== undefined && (
<span className={`font-semibold ${passed ? "text-emerald-600 dark:text-emerald-400" : "text-amber-600 dark:text-amber-400"}`}>
{passed ? "passed" : "sent back to the agent"}
</span>
)}
</div>
{critique && <p className="text-[11px] text-gray-500 dark:text-gray-400 italic">{critique}</p>}
{gaps.length > 0 && (
<div>
<p className={sysLbl}>Gaps filled</p>
<div className="space-y-0.5">
{gaps.map((g, i) => (
<p key={i} className="text-[11px] text-amber-700 dark:text-amber-300 font-mono bg-amber-50 dark:bg-amber-950/20 rounded px-2 py-0.5">↳ {g}</p>
))}
</div>
</div>
)}
{finalOut && (
<div>
<p className={sysLbl}>Final Output</p>
<p className={sysBlock}>{finalOut}</p>
</div>
)}
</div>
);
}
// Fallback: render input + raw JSON
return (
<div className="space-y-1.5">
{input && Object.keys(input).length > 0 && <NodeInputSection input={input} />}
{Object.keys(r).length > 0 && (
<p className={sysBlock}>{JSON.stringify(r, null, 2)}</p>
)}
</div>
);
};
export default SystemNodeResultView;
|