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 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 | 8x 8x 8x 2x 8x 5x 8x 5x 8x 8x 3x 8x 3x 3x 2x 8x 12x 6x 6x 6x 6x 5x 8x 9x 3x 9x 8x 6x 6x 2x 2x 2x 2x 6x 6x 6x 8x 2x 2x 1x 1x 1x 1x 8x 2x 2x 2x 4x 4x 2x 4x 8x 2x 2x 2x 8x 9x 6x 6x 3x 3x 8x 2x 2x 1x 2x 3x 6x 8x 9x 4x 4x 4x 3x 4x 8x 4x 2x 4x 4x 8x 1x 1x 8x 2x 2x 2x 1x 1x 2x 2x 8x 8x 2x 8x 8x 4x 4x 2x 4x 2x 4x 2x 2x 1x 7x 1x 3x 1x 3x 3x 3x 2x 8x 8x 8x 13x 8x 5x 8x 8x 8x | /**
* The assurance tile: evaluation evidence on a board (`data_kind: platform`).
*
* Five views of two queries. Four read the platform benchmark
* (`GET /evaluations/benchmark`) — CHAINR Bot and each maker's strongest model on the
* gold datasets, the same for every user. One reads the viewer's own agents
* (`GET /evaluations/assurance`), in the board's workspace. Every view shares
* its query with the page it summarises, so a board and the Assurance page
* never disagree, and nothing here re-derives a figure svc-core computed.
*
* `VIEWS` is held equal to svc-core's `AssuranceWidget.VIEWS` by a test there.
*/
import {
ASSURANCE_STATUS,
STATUS_TONE_CLASSES,
StatusBadge,
StatusTone,
encodeResourceId,
} from "@/components/detail";
import {
AgentAssurance,
BenchmarkDataset,
BenchmarkResult,
BenchmarkTarget,
FleetAssurance,
PlatformBenchmark,
} from "@/objects/Evaluation";
import { Sparkline as KitSparkline } from "@/components/charts";
import { AssuranceConfig, AssuranceView } from "@/objects/Dashboard";
import { APP_ROUTES, ROUTE_PARAMS } from "@/routes/const";
import { QUERY_KEYS } from "@/services/query_keys";
import { useApiHandler } from "@/services/useApiHandler";
import { useQuery } from "@tanstack/react-query";
import { Loader2 } from "lucide-react";
import React from "react";
import { Link } from "react-router-dom";
import {
STATUS_LABEL,
STATUS_ORDER,
needsAttention,
} from "@/apps/user/pages/evaluation/assuranceStatus";
import {
BOT_KEY,
benchmarkJudge,
notRunYet,
usePlatformBenchmark,
} from "@/apps/user/pages/evaluation/Benchmark";
import {
ScoreBadge,
datasetHref,
formatScore,
formatSpread,
} from "@/apps/user/pages/evaluation/components";
import {
QualitySummary,
botStanding,
riskPoints,
} from "@/apps/user/pages/evaluation/RiskReturn";
import RiskReturnChart from "@/apps/user/pages/evaluation/RiskReturnChart";
import { WidgetBodyProps } from "./types";
// ─── Shared pieces ────────────────────────────────────────────────────────────
const Spinner = () => (
<div className="h-full flex items-center justify-center text-gray-300 dark:text-gray-600">
<Loader2 className="w-4 h-4 animate-spin" />
</div>
);
const Note: React.FC<{ children: React.ReactNode }> = ({ children }) => (
<p className="text-xs text-gray-400 dark:text-gray-500 italic">{children}</p>
);
const Caption: React.FC<{ children: React.ReactNode }> = ({ children }) => (
<p className="mb-2 text-[11px] leading-snug text-gray-500 dark:text-gray-400">
{children}
</p>
);
/** A pass or a miss in words as well as colour. */
const Mark: React.FC<{ passed: boolean }> = ({ passed }) => (
<span
aria-label={passed ? "Reaches the pass mark" : "Below the pass mark"}
className={
passed
? "text-green-600 dark:text-green-400"
: "text-red-500 dark:text-red-400"
}
>
{passed ? "✓" : "✗"}
</span>
);
/** Within this much of its pass mark, a miss reads as close rather than far. */
const NEAR_MISS = 0.1;
/** How a score sits against its pass mark — the tone of a heatmap cell. */
export const scoreTone = (result: BenchmarkResult | null): StatusTone =>
!result || typeof result.score !== "number"
? "neutral"
: result.passed
? "success"
: "danger";
const toneOf = (result: BenchmarkResult | null, passMark: number): StatusTone => {
const tone = scoreTone(result);
if (tone !== "danger" || !result || typeof result.score !== "number") return tone;
// Below the mark but close, and not a regression: a caution, not a failure.
return result.regression_verdict !== "regressed" &&
result.score >= passMark - NEAR_MISS
? "warning"
: "danger";
};
/** The benchmark's state in one line, for the views that need it. */
const BenchmarkState: React.FC<{
query: ReturnType<typeof usePlatformBenchmark>;
children: (data: PlatformBenchmark) => React.ReactNode;
}> = ({ query, children }) => {
if (query.isLoading) return <Spinner />;
const data = query.data as PlatformBenchmark | null | undefined;
Iif (!data) return <Note>Could not load the platform benchmark.</Note>;
const anyResult = data.datasets.some((d) => d.rows.some((r) => r.latest));
if (!anyResult) return <Note>{notRunYet(data)}</Note>;
return <>{children(data)}</>;
};
// ─── Leaderboard ──────────────────────────────────────────────────────────────
/** Targets with an average, ranked as svc-core ranks them: complete coverage
* first, best average first. Those still missing a dataset are listed after,
* unranked, because an average over fewer capabilities is not comparable. */
export const leaderboardRows = (targets: BenchmarkTarget[]) => {
const scored = targets.filter((t) => t.quality);
let rank = 0;
return scored.map((t) => ({
target: t,
rank: t.datasets_covered === t.datasets_total ? ++rank : null,
}));
};
const Leaderboard: React.FC = () => {
const query = usePlatformBenchmark();
return (
<BenchmarkState query={query}>
{(data) => {
const rows = leaderboardRows(data.targets);
const judge = benchmarkJudge(data.datasets);
Iif (!rows.length)
return <Note>No model has a result on every gold dataset yet.</Note>;
return (
<div>
<Caption>
Average score across {data.datasets.length} gold datasets, each
counted equally; risk is how far a typical answer lands from it.
{judge ? ` Graded by ${judge}.` : ""}
</Caption>
<ol className="space-y-1.5" data-testid="assurance-leaderboard">
{rows.map(({ target, rank }) => {
const q = target.quality!;
const isBot = target.target_key === BOT_KEY;
return (
// Wraps rather than overflows: on a narrow tile the
// average and risk drop under the bar.
<li
key={target.target_key}
className="flex flex-wrap items-center gap-x-2 gap-y-1 text-xs"
>
<span className="w-5 shrink-0 text-right tabular-nums text-gray-400 dark:text-gray-500">
{rank ?? "–"}
</span>
<span className="w-28 sm:w-44 shrink-0 truncate" title={target.name}>
<span
className={
isBot
? "font-semibold text-gray-900 dark:text-gray-100"
: "text-gray-700 dark:text-gray-300"
}
>
{target.name}
</span>
</span>
<span className="relative h-2 flex-1 min-w-[4rem] rounded-full bg-gray-100 dark:bg-gray-800">
<span
className={`absolute inset-y-0 left-0 rounded-full ${
isBot ? "bg-indigo-500" : "bg-slate-400 dark:bg-slate-500"
}`}
style={{ width: `${Math.round(q.mean * 100)}%` }}
/>
</span>
<QualitySummary quality={q} className="shrink-0" />
{target.efficient && (
<span
className="shrink-0 text-[10px] text-indigo-600 dark:text-indigo-400"
title="On the efficient frontier: nothing has as good an average for no more risk."
>
frontier
</span>
)}
{rank === null && (
<span className="shrink-0 text-[10px] text-gray-400 dark:text-gray-500">
{target.datasets_covered}/{target.datasets_total} datasets
</span>
)}
</li>
);
})}
</ol>
</div>
);
}}
</BenchmarkState>
);
};
// ─── Average against risk ─────────────────────────────────────────────────────
const RiskReturn: React.FC = () => {
const query = usePlatformBenchmark();
return (
<BenchmarkState query={query}>
{(data) => {
const points = riskPoints(data.targets, BOT_KEY);
Iif (points.length < 2)
return (
<Note>
The chart appears once two models have a result on every gold
dataset.
</Note>
);
const standing = botStanding(data.targets, BOT_KEY);
return (
<div>
<RiskReturnChart points={points} />
{standing && (
<p className="mt-1 text-[11px] text-gray-500 dark:text-gray-400">
{standing}
</p>
)}
</div>
);
}}
</BenchmarkState>
);
};
// ─── Scores by gold dataset ───────────────────────────────────────────────────
/** Every target, in leaderboard order, then any that have no average yet. */
export const heatmapTargets = (data: PlatformBenchmark): { key: string; name: string }[] => {
const seen = new Set<string>();
const out: { key: string; name: string }[] = [];
for (const t of data.targets) {
seen.add(t.target_key);
out.push({ key: t.target_key, name: t.name });
}
for (const d of data.datasets)
for (const r of d.rows)
if (!seen.has(r.target_key)) {
seen.add(r.target_key);
out.push({ key: r.target_key, name: r.name });
}
return out;
};
const Cell: React.FC<{ dataset: BenchmarkDataset; targetKey: string }> = ({
dataset,
targetKey,
}) => {
const row = dataset.rows.find((r) => r.target_key === targetKey);
const latest = row?.latest ?? null;
if (!row || !latest || typeof latest.score !== "number")
return (
<td className="px-1 py-1 text-center text-gray-300 dark:text-gray-600">
<span title={row?.status === "running" ? "Running now" : "Not yet run"}>
{row?.status === "running" ? "…" : "—"}
</span>
</td>
);
return (
<td className="px-1 py-1">
<span
className={`flex items-center justify-center gap-1 rounded border px-1.5 py-1 font-mono tabular-nums ${
STATUS_TONE_CLASSES[toneOf(latest, dataset.pass_mark)]
}`}
title={`${row.name} on ${dataset.dataset_name}: ${formatScore(latest.score)} against a pass mark of ${formatScore(dataset.pass_mark)}${
latest.regression_verdict === "regressed" ? " — regressed on its last run" : ""
}`}
>
{formatScore(latest.score)} <Mark passed={latest.passed} />
</span>
</td>
);
};
const Scores: React.FC = () => {
const query = usePlatformBenchmark();
return (
<BenchmarkState query={query}>
{(data) => (
<div>
<Caption>
Each cell is the newest score on the dataset as it stands. ✓
reaches the dataset's pass mark, ✗ falls short; amber is within
ten points of it.
</Caption>
<div className="overflow-x-auto">
<table className="w-full text-xs" data-testid="assurance-scores">
<thead>
<tr>
<th className="sticky left-0 z-10 bg-white dark:bg-gray-800 py-1 pr-2 text-left text-[10px] font-medium uppercase tracking-wide text-gray-400 dark:text-gray-500">
Model or agent
</th>
{data.datasets.map((d) => (
<th
key={d.dataset_id}
className="px-1 py-1 align-bottom text-center text-[10px] font-medium text-gray-500 dark:text-gray-400 min-w-[5.5rem]"
>
<Link to={datasetHref(d.dataset_id)} className="hover:underline">
{d.dataset_name}
</Link>
<div className="font-normal text-gray-400 dark:text-gray-500">
pass {formatScore(d.pass_mark)}
</div>
</th>
))}
</tr>
</thead>
<tbody>
{heatmapTargets(data).map((t) => (
<tr key={t.key}>
<th
scope="row"
className={`sticky left-0 z-10 bg-white dark:bg-gray-800 py-1 pr-2 text-left font-normal whitespace-nowrap ${
t.key === BOT_KEY
? "font-semibold text-gray-900 dark:text-gray-100"
: "text-gray-700 dark:text-gray-300"
}`}
>
{t.name}
</th>
{data.datasets.map((d) => (
<Cell key={d.dataset_id} dataset={d} targetKey={t.key} />
))}
</tr>
))}
</tbody>
</table>
</div>
</div>
)}
</BenchmarkState>
);
};
// ─── CHAINR Bot, release by release ───────────────────────────────────────────
/** The newest result, and how far it moved from the run before it on the same
* dataset version — runs on different versions asked different questions. */
export const latestMove = (
history: BenchmarkResult[],
): { latest: BenchmarkResult; change: number | null } | null => {
const scored = history.filter((h) => typeof h.score === "number");
const latest = scored[scored.length - 1];
Iif (!latest) return null;
const previous = scored
.slice(0, -1)
.reverse()
.find((h) => h.dataset_version === latest.dataset_version);
return {
latest,
change:
previous && typeof previous.score === "number"
? (latest.score as number) - previous.score
: null,
};
};
/** A small line of the bot's scores, oldest left, with the pass mark dashed
* and a break wherever the dataset's version changed (the kit's
* `Sparkline`, on the score scale). */
export const Sparkline: React.FC<{
history: BenchmarkResult[];
passMark: number;
}> = ({ history, passMark }) => {
const scored = history.filter((h) => typeof h.score === "number");
return (
<KitSparkline
values={scored.map((h) => h.score as number)}
label="Scores"
domain={[0, 1]}
reference={passMark}
format={formatScore}
breaks={scored.flatMap((h, i) =>
i > 0 && h.dataset_version !== scored[i - 1].dataset_version
? [
{
index: i,
title:
"New dataset version: runs either side asked different questions",
},
]
: [],
)}
/>
);
};
const formatChange = (change: number) => {
const points = Math.round(change * 100);
return points === 0 ? "no change" : `${points > 0 ? "+" : "−"}${Math.abs(points)} pts`;
};
const BotTrend: React.FC = () => {
const query = usePlatformBenchmark();
return (
<BenchmarkState query={query}>
{(data) => {
const datasets = data.datasets.filter((d) => d.bot_history.length);
Iif (!datasets.length) return <Note>{notRunYet(data)}</Note>;
return (
<div>
<Caption>
Each run of CHAINR Bot, oldest left; the dashed line is the pass
mark. The change is against its previous run on the same version
of the dataset.
</Caption>
<ul className="divide-y divide-gray-100 dark:divide-gray-700" data-testid="assurance-bot-trend">
{datasets.map((d) => {
const move = latestMove(d.bot_history);
return (
<li key={d.dataset_id} className="flex items-center gap-2 py-1.5 text-xs">
<span className="min-w-0 flex-1">
<Link
to={datasetHref(d.dataset_id)}
className="block leading-snug text-gray-800 dark:text-gray-200 hover:underline"
>
{d.dataset_name}
</Link>
{move?.latest.agent_version != null && (
<span className="text-[10px] text-gray-400 dark:text-gray-500">
release v{move.latest.agent_version}
</span>
)}
</span>
<Sparkline history={d.bot_history} passMark={d.pass_mark} />
<span className="flex w-28 shrink-0 items-center justify-end gap-1.5">
{move && (
<>
{move.change !== null && (
<span
className={`text-[10px] tabular-nums ${
move.change < 0
? "text-red-500 dark:text-red-400"
: "text-gray-400 dark:text-gray-500"
}`}
>
{formatChange(move.change)}
</span>
)}
<ScoreBadge value={move.latest.score} />
<Mark passed={move.latest.passed} />
</>
)}
</span>
</li>
);
})}
</ul>
</div>
);
}}
</BenchmarkState>
);
};
// ─── Your agents ──────────────────────────────────────────────────────────────
/** A solid bar per tone: the badge classes are too pale to read as a bar.
* Keyed by tone, so a status's colour still comes from its scale. */
const BAR_TONE: Record<StatusTone, string> = {
neutral: "bg-gray-300 dark:bg-gray-600",
muted: "bg-gray-200 dark:bg-gray-700",
progress: "bg-blue-400 dark:bg-blue-500",
success: "bg-green-500 dark:bg-green-500",
done: "bg-violet-400 dark:bg-violet-500",
warning: "bg-amber-400 dark:bg-amber-500",
danger: "bg-red-500 dark:bg-red-500",
};
const agentHref = (id: string) =>
APP_ROUTES.USER.INFERENCE.AGENTS.id.replace(
ROUTE_PARAMS.AGENT.id,
encodeResourceId(id),
);
/** How many agents to list by name before pointing at the Assurance page. */
const ATTENTION_SHOWN = 5;
const Fleet: React.FC = () => {
const { getApiHandler } = useApiHandler();
const { data, isLoading } = useQuery<FleetAssurance | null>({
queryKey: [QUERY_KEYS.GET.EVALUATION_ASSURANCE],
queryFn: () => getApiHandler().evaluation_router.assurance(),
});
if (isLoading) return <Spinner />;
const fleet = (data as FleetAssurance | null | undefined) ?? null;
Iif (!fleet) return <Note>Could not load your agents' evidence.</Note>;
const total = fleet.summary.total;
if (!total)
return (
<Note>
No agents here yet. Create one, then press Evaluate on it — its evidence
shows here.
</Note>
);
const counts = STATUS_ORDER.filter((s) => fleet.summary[s] > 0).map((s) => ({
status: s,
count: fleet.summary[s],
}));
const attention: AgentAssurance[] = fleet.agents.filter((a) =>
needsAttention(a.status),
);
return (
<div>
<Caption>
{fleet.summary.current} of {total} agent{total === 1 ? "" : "s"} have
passing evidence for the version in force.
</Caption>
<div
className="flex h-3 w-full overflow-hidden rounded-full bg-gray-100 dark:bg-gray-800"
role="img"
aria-label={counts.map((c) => `${STATUS_LABEL[c.status]}: ${c.count}`).join(", ")}
>
{counts.map((c) => (
<span
key={c.status}
className={BAR_TONE[ASSURANCE_STATUS[c.status] ?? "neutral"]}
style={{ width: `${(c.count / total) * 100}%` }}
/>
))}
</div>
<div className="mt-2 flex flex-wrap gap-1.5">
{counts.map((c) => (
<StatusBadge
key={c.status}
status={c.status}
scale={ASSURANCE_STATUS}
label={`${STATUS_LABEL[c.status]} · ${c.count}`}
/>
))}
</div>
{attention.length > 0 && (
<ul className="mt-3 divide-y divide-gray-100 dark:divide-gray-700" data-testid="assurance-fleet">
{attention.slice(0, ATTENTION_SHOWN).map((a) => (
<li key={a.agent_id} className="flex items-center gap-2 py-1.5 text-xs">
<Link
to={agentHref(a.agent_id)}
className="min-w-0 flex-1 truncate text-gray-800 dark:text-gray-200 hover:underline"
>
{a.agent_name}
</Link>
{a.quality && (
<span className="hidden sm:inline text-[10px] tabular-nums text-gray-400 dark:text-gray-500">
{formatScore(a.quality.mean)} {formatSpread(a.quality.sd)}
</span>
)}
<StatusBadge
status={a.status}
scale={ASSURANCE_STATUS}
label={STATUS_LABEL[a.status]}
/>
</li>
))}
</ul>
)}
<Link
to={APP_ROUTES.USER.GOVERNANCE.EVALUATION.assurance}
className="mt-2 inline-block text-[11px] text-blue-600 dark:text-blue-400 hover:underline"
>
{attention.length > ATTENTION_SHOWN
? `${attention.length - ATTENTION_SHOWN} more on Assurance`
: "Open Assurance"}
</Link>
</div>
);
};
// ─── The registry ─────────────────────────────────────────────────────────────
/** Where a benchmark view's figures come from. They are CHAIN-R's
* measurements, the same for every viewer, so the tile must not carry the
* "Your data" marker a platform tile otherwise gets. */
export const BENCHMARK_SOURCE = "CHAIN-R benchmark";
/** Every view this app draws: the label the tile editor offers, and the
* named source a tile shows in place of "Your data" (null: the viewer's
* own). */
export const VIEWS: Record<
AssuranceView,
{ label: string; source: string | null; body: React.FC }
> = {
leaderboard: { label: "Leaderboard — models and CHAINR Bot by average", source: BENCHMARK_SOURCE, body: Leaderboard },
risk_return: { label: "Average against risk — with the efficient frontier", source: BENCHMARK_SOURCE, body: RiskReturn },
scores: { label: "Scores by gold dataset — against each pass mark", source: BENCHMARK_SOURCE, body: Scores },
bot_trend: { label: "CHAINR Bot, release by release", source: BENCHMARK_SOURCE, body: BotTrend },
fleet: { label: "Your agents — evidence for the version in force", source: null, body: Fleet },
};
const viewOf = (widget: { config: unknown }) =>
VIEWS[(widget.config as AssuranceConfig | null)?.view] ?? VIEWS.leaderboard;
/** The provenance a tile names (`DashboardCanvas`'s `sourceNameOf`). */
export const assuranceSource = (widget: { config: unknown }): string | null =>
viewOf(widget).source;
export const AssuranceWidgetBody: React.FC<WidgetBodyProps> = ({ widget }) => {
const Body = viewOf(widget).body;
return <Body />;
};
|