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 | 2x 2x 2x 1x 1x 2x 1x 1x 2x 1x 1x 2x 1x 1x 2x 1x 1x 2x 9x 2x 2x 2x 85x 85x 85x 85x 85x 85x 85x 85x 39x 85x 38x 85x 35x 85x 38x 85x 85x 85x 85x 1x 1x 1x | import {
EvaluationSection,
evaluationSectionFor,
} from "@/apps/user/pages/evaluation/sections";
import {
SectionTabBar,
SectionTabConfig,
SubsectionBackLink,
SubsectionLinkConfig,
SubsectionLinks,
} from "@/components/nav/SectionNav/SectionNav";
import MainPage from "@/components/page/MainPage/MainPage";
import { GovernanceActivityList } from "@/objects/Governance";
import { Rule } from "@/objects/Rule";
import { ReviewSummary } from "@/objects/Review";
import { QUERY_KEYS } from "@/services/query_keys";
import { useApiHandler } from "@/services/useApiHandler";
import { useQuery } from "@tanstack/react-query";
import {
Activity,
BarChart3,
ChartScatter,
Loader2,
ScrollText,
ShieldCheck,
TestTube,
Wallet,
} from "lucide-react";
import React from "react";
import { useSearchParams } from "react-router-dom";
// Every section is a substantial module with its own query graph, so each is
// loaded when it is first opened rather than pulled into the page's chunk.
const RulesContent = React.lazy(() =>
import("@/apps/user/pages/Rules").then((m) => ({ default: m.RulesContent })),
);
const ReviewsContent = React.lazy(() =>
import("@/apps/user/pages/Reviews").then((m) => ({
default: m.ReviewsContent,
})),
);
const EvaluationContent = React.lazy(() =>
import("@/apps/user/pages/Evaluation").then((m) => ({
default: m.EvaluationContent,
})),
);
const AssuranceContent = React.lazy(() =>
import("@/apps/user/pages/evaluation/Assurance").then((m) => ({
default: m.AssuranceContent,
})),
);
const SpendContent = React.lazy(() =>
import("@/apps/user/pages/spend/Spend").then((m) => ({
default: m.SpendContent,
})),
);
const RuleActivityContent = React.lazy(() =>
import("@/apps/user/pages/RuleActivity").then((m) => ({
default: m.RuleActivityContent,
})),
);
const SectionLoading: React.FC = () => (
<div className="flex items-center justify-center py-16">
<Loader2 className="size-5 animate-spin text-gray-400 dark:text-gray-500" />
</div>
);
// ─── Section types ────────────────────────────────────────────────────────────
// Governance is the control plane's own surface, in three tabs — the two
// kinds of standard a fleet is held to, and what it costs to hold it there:
//
// Rules — the standards every invocation is held to, enforced live
// Evaluation — the standards a model or agent is held to *before and
// between* changes: quality, behaviour, regressions, and
// which version of each agent has evidence behind it
// Spend — what the workspace has spent, the budgets that cap it (each
// a cost-cap rule) and where each is heading
//
// Each tab opens on its standard and reaches what follows from it a link
// away. Rules leads to Activity (what the rules did, invocation by
// invocation) and Reviews (what they asked a person to look at — a regressed
// evaluation run lands in the same queue); Evaluation opens on Assurance,
// with Datasets and Reports behind it. Activity and Reviews were tabs of
// their own, which made the evidence of one standard read as two more
// standards beside it. Their `?section=` values are unchanged, so every link
// into them still lands there.
type GovernanceSection =
| "rules"
| RulesSection
| "evaluation"
| EvaluationSection
| "spend";
type GovernanceTab = "rules" | "evaluation" | "spend";
/** The Rules tab's subsections: what its rules did, and what they asked a
* person to look at. */
type RulesSection = "activity" | "reviews";
const SECTIONS: GovernanceSection[] = [
"rules",
"activity",
"reviews",
"evaluation",
"datasets",
"reports",
"assurance",
"spend",
];
const TAB_FOR_SECTION: Record<GovernanceSection, GovernanceTab> = {
rules: "rules",
activity: "rules",
reviews: "rules",
// The Evaluation tab opens on Assurance (see evaluation/sections.ts).
evaluation: "evaluation",
assurance: "evaluation",
datasets: "evaluation",
reports: "evaluation",
spend: "spend",
};
const Governance: React.FC = () => {
const { getApiHandler } = useApiHandler();
const [searchParams, setSearchParams] = useSearchParams();
const rawSection = searchParams.get("section") as GovernanceSection | null;
const section: GovernanceSection =
rawSection && SECTIONS.includes(rawSection) ? rawSection : "rules";
const activeTab = TAB_FOR_SECTION[section];
const evaluationSection = evaluationSectionFor(section);
const setSection = (s: GovernanceSection) => setSearchParams({ section: s });
// Every count is fetched eagerly so the badges are populated before the
// section is visited — a pending review is the kind of thing a person needs
// to see without first clicking to look for it. Each shares the cache key
// its section uses, so opening one costs no second request.
const { data: rules = [] } = useQuery<Rule[]>({
queryKey: [QUERY_KEYS.GET.RULES],
queryFn: async () => (await getApiHandler().rule_router.list()) ?? [],
});
// A single day's window, and only the summary is read — `limit: 1` keeps
// the badge from paying for a page of rows nobody is looking at yet.
const { data: activity } = useQuery<GovernanceActivityList | null>({
queryKey: [QUERY_KEYS.GET.RULE_ACTIVITY, "badge"],
queryFn: () => getApiHandler().rule_router.activity({ days: 1, limit: 1 }),
staleTime: 30_000,
});
const { data: summary } = useQuery<ReviewSummary | null>({
queryKey: [QUERY_KEYS.GET.REVIEWS_SUMMARY],
queryFn: () => getApiHandler().review_router.summary(),
staleTime: 30_000,
});
// The datasets count shares the Datasets section's cache key.
const { data: datasets = [] } = useQuery<{ id: string }[]>({
queryKey: [QUERY_KEYS.GET.TEST_SUITES],
queryFn: () =>
getApiHandler().evaluation_router.listTestSuites() as Promise<
{ id: string }[]
>,
staleTime: 60_000,
refetchOnWindowFocus: false,
});
const tabs: SectionTabConfig<GovernanceTab>[] = [
{
key: "rules",
label: "Rules",
Icon: ShieldCheck,
count: rules.length,
},
{
key: "evaluation",
label: "Evaluation",
Icon: ChartScatter,
// Datasets: the resource the tab is built from — each holds its own
// experiments, and Assurance is a reading of their runs.
count: datasets.length,
},
{
key: "spend",
label: "Spend",
Icon: Wallet,
},
];
// The entry page is the rules; these are what came of them.
const rulesSubsections: SubsectionLinkConfig<GovernanceSection>[] = [
{
key: "activity",
label: "Activity",
hint: "What each rule did, message by message",
Icon: Activity,
// Evaluations in the last day. A total would climb forever and stop
// meaning anything — the count answers "is my fleet being governed
// right now?", which is the question a count can actually answer.
count: activity?.summary?.total ?? 0,
},
{
key: "reviews",
label: "Reviews",
hint: "Flags and regressions waiting on a person",
Icon: ScrollText,
// Pending, not total. The count answers "is there anything waiting for
// me?" — one that included every resolved flag would grow forever and
// stop meaning anything.
count: summary?.pending ?? 0,
},
];
// The entry page is Assurance; these are what its answer is built from.
const evaluationSubsections: SubsectionLinkConfig<GovernanceSection>[] = [
{
key: "datasets",
label: "Datasets",
hint: "Cases, and the experiments run on them",
Icon: TestTube,
count: datasets.length,
},
{
key: "reports",
label: "Reports",
hint: "Scores across experiments",
Icon: BarChart3,
},
];
return (
<MainPage
title="Governance"
description="Define the standards your fleet is held to, show that it meets them, and decide what needs a person. Rules are enforced on every invocation — policy before the model sees a prompt, audit after it answers — and can be scoped to anything you own. Evaluations test models and agents against your own cases before and between changes, and every result, rule outcome and decision is kept as evidence. Spend shows what it costs, and the budgets that cap it."
>
<SectionTabBar
tabs={tabs}
active={activeTab}
onChange={(t) => setSection(t)}
/>
{activeTab === "rules" &&
(section === "rules" ? (
<SubsectionLinks items={rulesSubsections} onSelect={setSection} />
) : (
<SubsectionBackLink
label="Rules"
onClick={() => setSection("rules")}
/>
))}
{activeTab === "evaluation" &&
(evaluationSection === "assurance" ? (
<SubsectionLinks items={evaluationSubsections} onSelect={setSection} />
) : (
<SubsectionBackLink
label="Evaluation"
onClick={() => setSection("evaluation")}
/>
))}
<React.Suspense fallback={<SectionLoading />}>
{section === "rules" && <RulesContent />}
{section === "activity" && <RuleActivityContent />}
{section === "reviews" && <ReviewsContent />}
{section === "spend" && <SpendContent />}
{activeTab === "evaluation" &&
(evaluationSection === "assurance" ? (
<AssuranceContent />
) : (
<EvaluationContent section={evaluationSection} />
))}
</React.Suspense>
</MainPage>
);
};
export default Governance;
|