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 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 | 3x 3x 3x 3x 12x 12x 13x 13x 11x 13x 13x 13x 12x 3x 3x 6x 6x 2x 6x 6x 3x 4x 4x 3x 4x 3x 6x 6x 6x 6x 6x 2x 6x 6x 6x 6x 4x 6x 2x 2x 6x 6x 2x 3x 4x 3x 6x 6x 6x 6x 6x 6x 6x 2x 6x 4x 4x 2x 6x 6x 2x 6x 6x 6x 6x 4x 4x 3x 2x | import {
OriginBadge,
} from "@/components/owner";
import { Resource } from "@/objects/Doc";
import {
CreateButton,
FilterOption,
ResourceCollection,
SegmentedFilter,
collectionSection,
useCollectionFilters,
} from "@/components/collection";
import { BuiltInBadge } from "@/components/badge/BuiltInBadge";
import { isSystemManaged } from "@/objects/Doc";
import {
BatchReportRow,
EvaluationStatus,
TestSuite,
} from "@/objects/Evaluation";
import { QUERY_KEYS, INCLUDE_SYSTEM } from "@/services/query_keys";
import { useApiHandler } from "@/services/useApiHandler";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import type { LucideIcon } from "lucide-react";
import {
ChevronRight,
Columns3,
Loader2,
TestTube,
Trash2,
} from "lucide-react";
import React, { useCallback, useEffect, useMemo, useState } from "react";
import { Link, useNavigate } from "react-router-dom";
import {
ConfirmDialog,
EVALUATION_STATUS,
Modal,
ModalActions,
StatusBadge,
Strong,
} from "@/components/detail";
import { errorDetail } from "@/util/apiError";
import {
ErrorNote,
Field,
PassMark,
ScoreBadge,
datasetHref,
formatScore,
formatTimestamp,
inputCls,
} from "./evaluation/components";
// Compare pulls in the target/scorer pickers and the model and agent lists;
// the other evaluation sections need none of that, so it loads on demand.
const Compare = React.lazy(() => import("./evaluation/Compare"));
const Reports = React.lazy(() => import("./evaluation/Reports"));
// ─── Shared primitives ────────────────────────────────────────────────────────
// Status filter shared by the Evaluations and Datasets lists.
type EvalStatusFilter = "all" | EvaluationStatus;
const EVAL_STATUS_FILTER_OPTIONS: FilterOption<EvalStatusFilter>[] = [
{ value: "all", label: "All" },
{ value: "active", label: "Active" },
{ value: "draft", label: "Draft" },
{ value: "archived", label: "Archived" },
];
// ─── Sections ─────────────────────────────────────────────────────────────────
// Sub-navigation is rendered by the Governance page's subsection links; this
// type is the contract between them and EvaluationContent.
/**
* The evaluation section has three places, not six.
*
* "Labs", "Compare" and "Experiments" were three doors into the same list, and
* "Benchmarking" was a dataset with a target welded onto it. Simulations moved
* next to agents: they produce no score, so sitting beside the things that
* measure quality made the whole section read as incoherent. The old names
* survive as aliases in `Inference.tsx` so links keep working.
*/
export type { EvaluationSection } from "./evaluation/sections";
import type { EvaluationSection } from "./evaluation/sections";
import { parseServerDate } from "@/util/time";
// ─── Create modals ────────────────────────────────────────────────────────────
/**
* New dataset: a name and a description, then straight into its page.
*
* An evaluation's create form is bigger (it picks a dataset and a scorer) and
* lives in its own lazy module; a dataset has nothing to choose, so it stays
* here.
*/
const NewDatasetModal: React.FC<{
onClose: () => void;
onCreate: (name: string, description: string) => void;
loading: boolean;
/** Why the last attempt failed. Shown in the modal so it can stay open
* with the name intact rather than closing on a request that went wrong. */
error?: string | null;
}> = ({ onClose, onCreate, loading, error }) => {
const [name, setName] = useState("");
const [description, setDescription] = useState("");
return (
<Modal
title="New dataset"
icon={TestTube}
size="md"
busy={loading}
onClose={onClose}
description="Questions, and what a good answer to each is. Run experiments on it afterwards — every one of them asks the same questions."
footer={
<ModalActions
onCancel={onClose}
onConfirm={() => onCreate(name.trim(), description.trim())}
confirmLabel="Create"
loadingLabel="Creating…"
loading={loading}
disabled={!name.trim()}
/>
}
>
<div className="space-y-4">
<Field label="Name">
<input
autoFocus
className={inputCls}
placeholder="e.g. Customer support regression cases"
value={name}
onChange={(e) => setName(e.target.value)}
/>
</Field>
<Field label="Description" hint="optional">
<textarea
rows={3}
className={`${inputCls} resize-none`}
placeholder="What does this dataset cover?"
value={description}
onChange={(e) => setDescription(e.target.value)}
/>
</Field>
{error && <ErrorNote message={error} />}
</div>
</Modal>
);
};
// ─── Last result per evaluation / dataset ─────────────────────────────────────
//
// A row used to show name, status and date, and nothing about what the thing
// had *produced* — the score, the run, the reason anyone opens the tab was two
// clicks deep in a viewer. The cross-experiment report already returns every
// completed batch with its owner, score and time in one filterable call; the
// list simply never asked.
/**
* The newest completed run for each evaluation, or for each dataset.
*
* A run belongs to an evaluation and asked a dataset, so the same rows answer
* both lists — keyed by whichever id the list is about.
*/
export function latestByOwner(
rows: BatchReportRow[],
key: "experiment_id" | "dataset_id" = "experiment_id",
): Map<string, BatchReportRow> {
const latest = new Map<string, BatchReportRow>();
for (const row of rows) {
const owner = row[key];
if (!owner) continue;
const when = row.finished_at ?? row.created_at ?? "";
const held = latest.get(owner);
const heldWhen = held ? (held.finished_at ?? held.created_at ?? "") : "";
// ISO timestamps compare as strings; a row with no time never wins.
if (!held || when > heldWhen) latest.set(owner, row);
}
return latest;
}
/** Days of history the list reads its "last result" from. Long enough that a
* dataset run monthly still shows one; short enough to stay one page. */
const RECENT_DAYS = 90;
const RECENT_LIMIT = 200;
function useLatestResults(
key: "experiment_id" | "dataset_id" = "experiment_id",
): Map<string, BatchReportRow> {
const { getApiHandler } = useApiHandler();
const { data } = useQuery<BatchReportRow[]>({
queryKey: [
QUERY_KEYS.GET.BATCH_REPORT,
"recent",
RECENT_DAYS,
RECENT_LIMIT,
],
queryFn: () =>
getApiHandler().evaluation_router.reportBatches({
days: RECENT_DAYS,
limit: RECENT_LIMIT,
}),
staleTime: 60_000,
});
const rows: BatchReportRow[] = data ?? [];
return useMemo(() => latestByOwner(rows, key), [rows, key]);
}
const LastResult: React.FC<{ row?: BatchReportRow }> = ({ row }) => {
Eif (!row) {
return (
<span className="text-xs text-gray-300 dark:text-gray-600 italic whitespace-nowrap shrink-0">
never run
</span>
);
}
return (
<span className="flex items-center gap-2 text-xs text-gray-500 dark:text-gray-400 whitespace-nowrap shrink-0">
<ScoreBadge value={row.mean_score} />
{row.pass_rate !== null && (
<span className="font-mono tabular-nums">
{formatScore(row.pass_rate)} passed
</span>
)}
{row.variants > 1 && <span>· {row.variants} variants</span>}
<span className="text-gray-400 dark:text-gray-500">
· {formatTimestamp(row.finished_at ?? row.created_at)}
</span>
</span>
);
};
// ─── One list for both resources ──────────────────────────────────────────────
//
// An evaluation and a dataset are listed identically — name, status, last
// result — so this is one component with two configurations rather than two
// near-identical tabs each hand-rolling its stats bar, toolbar and search
// state. It renders through `ResourceCollection`, like every other list.
interface Listed extends Resource {
id: string;
name: string;
description: string | null;
status: EvaluationStatus;
created_at: string;
is_system?: boolean;
}
const EvaluationRow = <T extends Listed>({
item,
href,
Icon,
latest,
meta,
onDelete,
}: {
item: T;
href: string;
Icon: LucideIcon;
latest?: BatchReportRow;
/** What else the row says about the item — a dataset's size and pass mark. */
meta?: React.ReactNode;
/** Omitted for what the caller cannot delete — a gold dataset. */
onDelete?: (item: T) => void;
}) => (
<div className="flex items-center gap-3 px-4 py-3 border-b border-gray-100 dark:border-gray-700 last:border-0 hover:bg-gray-50 dark:hover:bg-gray-700/40 transition-colors group">
<div className="p-1.5 rounded-lg bg-gray-100 dark:bg-gray-700 shrink-0">
<Icon className="size-4 text-gray-500 dark:text-gray-400" />
</div>
<Link to={href} className="flex-1 min-w-0">
<div className="flex items-center gap-2 min-w-0">
<span className="text-sm font-medium text-gray-900 dark:text-gray-100 truncate">
{item.name}
</span>
{isSystemManaged(item) && <BuiltInBadge size="sm" />}
<OriginBadge resource={item} />
</div>
{/* Wraps rather than overlapping the status column on a phone: the
result and the dataset's size and pass mark do not truncate. */}
<div className="mt-0.5 flex flex-wrap items-center gap-x-3 gap-y-0.5 min-w-0">
<LastResult row={latest} />
{meta}
{item.description && (
<span className="text-xs text-gray-400 dark:text-gray-500 truncate min-w-0 max-w-full">
{item.description}
</span>
)}
</div>
</Link>
<div className="flex items-center gap-2 shrink-0">
<StatusBadge scale={EVALUATION_STATUS} status={item.status} />
<span className="text-xs text-gray-400 dark:text-gray-500">
{parseServerDate(item.created_at).toLocaleDateString()}
</span>
{onDelete && (
<button
onClick={() => onDelete(item)}
className="opacity-0 group-hover:opacity-100 transition-opacity text-gray-300 dark:text-gray-600 hover:text-red-500 dark:hover:text-red-400"
aria-label={`Delete ${item.name}`}
>
<Trash2 className="size-3.5" />
</button>
)}
<Link to={href}>
<ChevronRight className="size-3.5 text-gray-300 dark:text-gray-600 opacity-0 group-hover:opacity-100 transition-opacity" />
</Link>
</div>
</div>
);
const EvaluationList = <T extends Listed>({
items,
loading,
Icon,
href,
description,
searchPlaceholder,
latest,
noun,
deleteHint,
onDelete,
deleting,
actions,
empty,
builtIn,
meta,
children,
}: {
items: T[];
loading: boolean;
Icon: LucideIcon;
href: (item: T) => string;
description: string;
searchPlaceholder: string;
latest: Map<string, BatchReportRow>;
/** What one of these is called, for the delete confirmation. */
noun: string;
/** What goes with it — its variants and results, its cases and runs. */
deleteHint: string;
onDelete: (id: string) => Promise<unknown>;
deleting: boolean;
actions: React.ReactNode;
empty: { title: string; hint: string; action: React.ReactNode };
/** The platform's own — listed first, under the same search and filters,
* and never deletable. The caller's items then sit under `builtIn.ownLabel`. */
builtIn?: { items: T[]; ownLabel: string; hint?: React.ReactNode };
meta?: (item: T) => React.ReactNode;
children?: React.ReactNode;
}) => {
const collection = useCollectionFilters<{
status: EvalStatusFilter;
}>({
defaults: { status: "all" },
});
const { filters, setFilter, matches } = collection;
// Deleting takes every run, score and version with it, and the row's trash
// icon is one click on hover — so the click asks first, like the viewers do.
const [pendingDelete, setPendingDelete] = useState<T | null>(null);
const [deleteError, setDeleteError] = useState<string | null>(null);
const keep = useCallback(
(item: T) =>
(filters.status === "all" || item.status === filters.status) &&
matches(item.name, item.description),
[filters.status, matches],
);
const filtered = useMemo(() => items.filter(keep), [items, keep]);
const builtInItems = builtIn?.items;
const filteredBuiltIn = useMemo(
() => (builtInItems ?? []).filter(keep),
[builtInItems, keep],
);
const renderRow = (item: T) => (
<EvaluationRow
item={item}
href={href(item)}
Icon={Icon}
latest={latest.get(item.id)}
meta={meta?.(item)}
onDelete={isSystemManaged(item) ? undefined : setPendingDelete}
/>
);
const body = builtIn
? {
sections: [
collectionSection<T>({
label: "Built-in",
items: filteredBuiltIn,
itemKey: (item) => item.id,
renderRow,
loading,
skeletonCount: 3,
hideWhenEmpty: true,
empty: { Icon, title: "Nothing built in matches." },
}),
collectionSection<T>({
label: builtIn.ownLabel,
items: filtered,
itemKey: (item) => item.id,
renderRow,
loading,
skeletonCount: 3,
empty: { Icon, ...empty, dashed: true },
emptyFilteredTitle: "Nothing matches your filters.",
}),
],
}
: {
items: filtered,
itemKey: (item: T) => item.id,
renderRow,
empty: { Icon, ...empty },
emptyFilteredTitle: "Nothing matches your filters.",
};
const ran = items.filter((item) => latest.has(item.id)).length;
return (
<>
{pendingDelete && (
<ConfirmDialog
title={`Delete ${noun}`}
icon={Trash2}
body={
<>
Delete <Strong>{pendingDelete.name}</Strong> and {deleteHint}?
This cannot be undone.
</>
}
loading={deleting}
error={deleteError}
onConfirm={() => {
setDeleteError(null);
onDelete(pendingDelete.id).then(
() => setPendingDelete(null),
(e) =>
setDeleteError(
errorDetail(e, `Could not delete this ${noun}.`),
),
);
}}
onCancel={() => {
setPendingDelete(null);
setDeleteError(null);
}}
/>
)}
<ResourceCollection<T>
description={description}
stats={[
{ label: "Total", value: items.length, loading },
{ label: "With a result", value: ran, loading },
{
label: "Active",
value: items.filter((item) => item.status === "active").length,
loading,
},
]}
shown={filtered.length + filteredBuiltIn.length}
search={{
value: collection.search,
onChange: collection.setSearch,
placeholder: searchPlaceholder,
}}
filters={
<>
<SegmentedFilter
value={filters.status}
onChange={(value) => setFilter("status", value)}
options={EVAL_STATUS_FILTER_OPTIONS}
/>
</>
}
{...collection.toolbarProps}
actions={actions}
{...body}
loading={loading}
skeletonCount={5}
>
{children}
{builtIn?.hint}
</ResourceCollection>
</>
);
};
// ─── Datasets ─────────────────────────────────────────────────────────────────
/** A dataset's size and pass mark, on its row. The pass mark shows only
* where the dataset sets one — or is a gold dataset, where it is part of
* what the benchmark asserts. */
const DatasetMeta: React.FC<{ dataset: TestSuite }> = ({ dataset }) => (
<span className="flex items-center gap-2 text-xs text-gray-400 dark:text-gray-500 shrink-0">
{dataset.case_count != null && (
<span className="tabular-nums">
{dataset.case_count} case{dataset.case_count === 1 ? "" : "s"}
</span>
)}
{(dataset.pass_mark != null || isSystemManaged(dataset)) && (
<span>
· pass <PassMark value={dataset.pass_mark} />
</span>
)}
</span>
);
const DatasetsTab: React.FC = () => {
const { getApiHandler } = useApiHandler();
const queryClient = useQueryClient();
const navigate = useNavigate();
const [showModal, setShowModal] = useState(false);
// Quick try is the fastest way to a result — one prompt, several targets,
// nothing saved — and saving it makes a dataset of that one question with
// an experiment on it, results included. It opens by itself when there is
// nothing else to look at.
const [showCompare, setShowCompare] = useState<boolean | null>(null);
const latest = useLatestResults("dataset_id");
// The caller's datasets and the gold ones in one request; the page lists
// them apart, and counts only the caller's own.
const { data, isLoading } = useQuery<TestSuite[]>({
queryKey: [QUERY_KEYS.GET.TEST_SUITES, INCLUDE_SYSTEM],
queryFn: () =>
getApiHandler().evaluation_router.listTestSuites({ includeSystem: true }),
});
const { suites, builtIn } = useMemo(() => {
const all: TestSuite[] = data ?? [];
return {
suites: all.filter((suite) => !isSystemManaged(suite)),
builtIn: all.filter(isSystemManaged),
};
}, [data]);
useEffect(() => {
if (!isLoading && showCompare === null) {
setShowCompare(suites.length === 0);
}
}, [isLoading, suites.length, showCompare]);
const createMutation = useMutation({
mutationFn: async ({
name,
description,
}: {
name: string;
description: string;
}) => {
// Made in the workspace this page shows (svc-core puts it there).
const created = await getApiHandler().evaluation_router.createTestSuite({
name,
description,
});
if (!created) throw new Error("Could not create the dataset.");
return created;
},
onSuccess: (created) => {
void queryClient.invalidateQueries({
queryKey: [QUERY_KEYS.GET.TEST_SUITES],
});
setShowModal(false);
void navigate(datasetHref(created.id));
},
});
const deleteMutation = useMutation({
mutationFn: (id: string) =>
getApiHandler().evaluation_router.deleteTestSuite(id),
onSuccess: () =>
void queryClient.invalidateQueries({
queryKey: [QUERY_KEYS.GET.TEST_SUITES],
}),
});
const createButton = (
<CreateButton label="New Dataset" onClick={() => setShowModal(true)} />
);
return (
<>
{showModal && (
<NewDatasetModal
onClose={() => setShowModal(false)}
onCreate={(name, description) =>
createMutation.mutate({ name, description })
}
loading={createMutation.isPending}
error={
createMutation.error
? errorDetail(
createMutation.error,
"Could not create the dataset.",
)
: null
}
/>
)}
<EvaluationList<TestSuite>
items={suites}
builtIn={{ items: builtIn, ownLabel: "Your datasets" }}
meta={(dataset) => <DatasetMeta dataset={dataset} />}
loading={isLoading}
Icon={TestTube}
href={(dataset) => datasetHref(dataset.id)}
description="A dataset is a set of questions and what a good answer to each is. Open one to run experiments on it — each grades every answer the same way and compares the models, agents or settings you give it. The built-in datasets are standard benchmarks — hallucination, tool use, political neutrality and more — to run your models and agents against, or copy and make your own."
searchPlaceholder="Search datasets…"
latest={latest}
noun="dataset"
deleteHint="all of its cases and run history"
onDelete={(id) => deleteMutation.mutateAsync(id)}
deleting={deleteMutation.isPending}
actions={
<div className="flex items-center gap-2">
<CreateButton
label={showCompare ? "Hide quick try" : "Try a prompt"}
Icon={Columns3}
variant="secondary"
onClick={() => setShowCompare((open) => !open)}
/>
{createButton}
</div>
}
empty={{
title: "No datasets of your own yet",
hint: "Run a built-in benchmark as it is, or open one and copy it to make it your own. Or try a prompt across a few models — a result you like can be saved as a dataset with an experiment on it in one click — or create a dataset and add or import its cases.",
action: createButton,
}}
>
{showCompare && (
<div className="rounded-xl border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 p-4">
<p className="text-xs text-gray-500 dark:text-gray-400 mb-3">
One prompt against several models or agents. Save a promising
result to keep it — results included.
</p>
<React.Suspense
fallback={
<div className="flex items-center justify-center py-10">
<Loader2 className="size-5 animate-spin text-gray-400 dark:text-gray-500" />
</div>
}
>
<Compare />
</React.Suspense>
</div>
)}
</EvaluationList>
</>
);
};
// ─── Evaluation content (rendered as the Governance → Evaluation tab) ─────────
// Assurance is the tab's entry page and has a module of its own
// (`evaluation/Assurance.tsx`); this renders the two sections it links to.
export const EvaluationContent: React.FC<{
section: Exclude<EvaluationSection, "assurance">;
}> = ({ section }) => {
return (
<div>
{section === "reports" && (
<p className="text-sm text-gray-500 dark:text-gray-400 mb-5">
Every completed run across every experiment and dataset — filtered and
totalled by the backend, so a question can span them rather than go
one at a time.
</p>
)}
{section === "datasets" && <DatasetsTab />}
{section === "reports" && (
<React.Suspense
fallback={
<div className="flex items-center justify-center py-16">
<Loader2 className="size-5 animate-spin text-gray-400 dark:text-gray-500" />
</div>
}
>
<Reports />
</React.Suspense>
)}
</div>
);
};
|