@crowandraven/evalkeeper 0.10.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (241) hide show
  1. package/README.md +1 -2
  2. package/dist/ai-sdk/decide.d.ts +35 -0
  3. package/dist/ai-sdk/decide.js +36 -0
  4. package/dist/ai-sdk/decide.js.map +1 -0
  5. package/dist/ai-sdk/hash.d.ts +50 -0
  6. package/dist/ai-sdk/hash.js +59 -0
  7. package/dist/ai-sdk/hash.js.map +1 -0
  8. package/dist/ai-sdk/index.d.ts +15 -0
  9. package/dist/ai-sdk/index.js +16 -0
  10. package/dist/ai-sdk/index.js.map +1 -0
  11. package/dist/ai-sdk/judge.d.ts +69 -0
  12. package/dist/ai-sdk/judge.js +105 -0
  13. package/dist/ai-sdk/judge.js.map +1 -0
  14. package/dist/ai-sdk/usage.d.ts +18 -0
  15. package/dist/ai-sdk/usage.js +19 -0
  16. package/dist/ai-sdk/usage.js.map +1 -0
  17. package/dist/board.d.ts +5 -0
  18. package/dist/cli/addPages.d.ts +6 -1
  19. package/dist/cli/addPages.js +14 -8
  20. package/dist/cli/addPages.js.map +1 -1
  21. package/dist/cli/main.d.ts +19 -5
  22. package/dist/cli/main.js +100 -4
  23. package/dist/cli/main.js.map +1 -1
  24. package/dist/cli/migration.d.ts +95 -0
  25. package/dist/cli/migration.js +247 -0
  26. package/dist/cli/migration.js.map +1 -0
  27. package/dist/feedback.d.ts +1 -1
  28. package/dist/glossary.d.ts +8 -1
  29. package/dist/glossary.js +8 -1
  30. package/dist/glossary.js.map +1 -1
  31. package/dist/inInstructions.d.ts +1 -1
  32. package/dist/inInstructions.js +1 -1
  33. package/dist/next/RefreshWhile.d.ts +11 -0
  34. package/dist/next/RefreshWhile.js +28 -0
  35. package/dist/next/RefreshWhile.js.map +1 -0
  36. package/dist/next/actions.d.ts +14 -0
  37. package/dist/next/actions.js +332 -0
  38. package/dist/next/actions.js.map +1 -0
  39. package/dist/next/components.d.ts +9 -0
  40. package/dist/next/components.js +27 -0
  41. package/dist/next/components.js.map +1 -0
  42. package/dist/next/cron.d.ts +9 -0
  43. package/dist/next/cron.js +17 -0
  44. package/dist/next/cron.js.map +1 -0
  45. package/dist/next/index.d.ts +15 -0
  46. package/dist/next/index.js +16 -0
  47. package/dist/next/index.js.map +1 -0
  48. package/dist/next/pages.d.ts +70 -0
  49. package/dist/next/pages.js +77 -0
  50. package/dist/next/pages.js.map +1 -0
  51. package/dist/next/route.d.ts +19 -0
  52. package/dist/next/route.js +31 -0
  53. package/dist/next/route.js.map +1 -0
  54. package/dist/next/weekly.d.ts +20 -0
  55. package/dist/next/weekly.js +55 -0
  56. package/dist/next/weekly.js.map +1 -0
  57. package/dist/next/wiring.d.ts +19 -0
  58. package/dist/next/wiring.js +2 -0
  59. package/dist/next/wiring.js.map +1 -0
  60. package/dist/prisma/contracts.d.ts +74 -0
  61. package/dist/prisma/contracts.js +178 -0
  62. package/dist/prisma/contracts.js.map +1 -0
  63. package/dist/prisma/index.d.ts +423 -0
  64. package/dist/prisma/index.js +622 -0
  65. package/dist/prisma/index.js.map +1 -0
  66. package/dist/prisma/mapping.d.ts +63 -0
  67. package/dist/prisma/mapping.js +111 -0
  68. package/dist/prisma/mapping.js.map +1 -0
  69. package/dist/prisma/moveIn.d.ts +106 -0
  70. package/dist/prisma/moveIn.js +299 -0
  71. package/dist/prisma/moveIn.js.map +1 -0
  72. package/dist/prune.d.ts +45 -0
  73. package/dist/prune.js +32 -0
  74. package/dist/prune.js.map +1 -1
  75. package/dist/react/AddCase.d.ts +10 -0
  76. package/dist/react/AddCase.js +19 -0
  77. package/dist/react/AddCase.js.map +1 -0
  78. package/dist/react/AnswerKey.d.ts +22 -0
  79. package/dist/react/AnswerKey.js +83 -0
  80. package/dist/react/AnswerKey.js.map +1 -0
  81. package/dist/react/CaseMenu.d.ts +17 -0
  82. package/dist/react/CaseMenu.js +41 -0
  83. package/dist/react/CaseMenu.js.map +1 -0
  84. package/dist/react/CompareView.d.ts +14 -0
  85. package/dist/react/CompareView.js +51 -0
  86. package/dist/react/CompareView.js.map +1 -0
  87. package/dist/react/ConfirmAnswer.d.ts +13 -0
  88. package/dist/react/ConfirmAnswer.js +27 -0
  89. package/dist/react/ConfirmAnswer.js.map +1 -0
  90. package/dist/react/DisagreementChip.d.ts +10 -0
  91. package/dist/react/DisagreementChip.js +21 -0
  92. package/dist/react/DisagreementChip.js.map +1 -0
  93. package/dist/react/FeedbackView.d.ts +10 -0
  94. package/dist/react/FeedbackView.js +26 -0
  95. package/dist/react/FeedbackView.js.map +1 -0
  96. package/dist/react/Fields.d.ts +32 -0
  97. package/dist/react/Fields.js +33 -0
  98. package/dist/react/Fields.js.map +1 -0
  99. package/dist/react/HubSections.d.ts +78 -0
  100. package/dist/react/HubSections.js +124 -0
  101. package/dist/react/HubSections.js.map +1 -0
  102. package/dist/react/ModelMenu.d.ts +16 -0
  103. package/dist/react/ModelMenu.js +38 -0
  104. package/dist/react/ModelMenu.js.map +1 -0
  105. package/dist/react/RateView.d.ts +18 -0
  106. package/dist/react/RateView.js +30 -0
  107. package/dist/react/RateView.js.map +1 -0
  108. package/dist/react/ReadableOutput.d.ts +3 -0
  109. package/dist/react/ReadableOutput.js +50 -0
  110. package/dist/react/ReadableOutput.js.map +1 -0
  111. package/dist/react/RollBack.d.ts +17 -0
  112. package/dist/react/RollBack.js +26 -0
  113. package/dist/react/RollBack.js.map +1 -0
  114. package/dist/react/RunView.d.ts +9 -0
  115. package/dist/react/RunView.js +41 -0
  116. package/dist/react/RunView.js.map +1 -0
  117. package/dist/react/SettingsHistory.d.ts +33 -0
  118. package/dist/react/SettingsHistory.js +79 -0
  119. package/dist/react/SettingsHistory.js.map +1 -0
  120. package/dist/react/SideBySideView.d.ts +14 -0
  121. package/dist/react/SideBySideView.js +67 -0
  122. package/dist/react/SideBySideView.js.map +1 -0
  123. package/dist/react/SuiteSections.d.ts +111 -0
  124. package/dist/react/SuiteSections.js +224 -0
  125. package/dist/react/SuiteSections.js.map +1 -0
  126. package/dist/react/Tabs.d.ts +15 -0
  127. package/dist/react/Tabs.js +18 -0
  128. package/dist/react/Tabs.js.map +1 -0
  129. package/dist/react/Thumbs.d.ts +13 -0
  130. package/dist/react/Thumbs.js +54 -0
  131. package/dist/react/Thumbs.js.map +1 -0
  132. package/dist/react/WeeklyCheck.d.ts +11 -0
  133. package/dist/react/WeeklyCheck.js +19 -0
  134. package/dist/react/WeeklyCheck.js.map +1 -0
  135. package/dist/react/app.d.ts +118 -0
  136. package/dist/react/app.js +87 -0
  137. package/dist/react/app.js.map +1 -0
  138. package/dist/react/format.d.ts +27 -0
  139. package/dist/react/format.js +38 -0
  140. package/dist/react/format.js.map +1 -0
  141. package/dist/react/index.d.ts +31 -0
  142. package/dist/react/index.js +32 -0
  143. package/dist/react/index.js.map +1 -0
  144. package/dist/react/pieces.d.ts +191 -0
  145. package/dist/react/pieces.js +191 -0
  146. package/dist/react/pieces.js.map +1 -0
  147. package/dist/readCheck.d.ts +1 -1
  148. package/dist/runner.d.ts +62 -2
  149. package/dist/runner.js +123 -3
  150. package/dist/runner.js.map +1 -1
  151. package/dist/settings.d.ts +1 -1
  152. package/dist/store.d.ts +1 -1
  153. package/dist/suggest.d.ts +1 -1
  154. package/dist/suggest.js +7 -7
  155. package/dist/suggest.js.map +1 -1
  156. package/dist/suiteContract.d.ts +3 -3
  157. package/dist/suiteContract.js +20 -16
  158. package/dist/suiteContract.js.map +1 -1
  159. package/dist/testing.d.ts +2 -2
  160. package/dist/testing.js +1 -1
  161. package/dist/types.js +1 -1
  162. package/dist/types.js.map +1 -1
  163. package/package.json +56 -6
  164. package/schema/evalkeeper.prisma +196 -0
  165. package/src/ai-sdk/decide.ts +57 -0
  166. package/src/ai-sdk/hash.ts +74 -0
  167. package/src/ai-sdk/index.ts +15 -0
  168. package/src/ai-sdk/judge.ts +163 -0
  169. package/src/ai-sdk/usage.ts +31 -0
  170. package/src/board.ts +5 -0
  171. package/src/cli/addPages.ts +15 -7
  172. package/src/cli/main.ts +135 -9
  173. package/src/cli/migration.ts +349 -0
  174. package/src/feedback.ts +1 -1
  175. package/src/glossary.ts +16 -2
  176. package/src/inInstructions.ts +1 -1
  177. package/{templates/components/evalkeeper → src/next}/RefreshWhile.tsx +2 -2
  178. package/src/next/actions.ts +389 -0
  179. package/src/next/components.ts +31 -0
  180. package/{templates/lib/evalkeeper/cronAuth.ts → src/next/cron.ts} +3 -0
  181. package/src/next/index.ts +15 -0
  182. package/src/next/pages.tsx +106 -0
  183. package/src/next/route.ts +35 -0
  184. package/src/next/weekly.ts +70 -0
  185. package/src/next/wiring.ts +18 -0
  186. package/src/prisma/contracts.ts +249 -0
  187. package/src/prisma/index.ts +1169 -0
  188. package/src/prisma/mapping.ts +147 -0
  189. package/src/prisma/moveIn.ts +502 -0
  190. package/src/prune.ts +77 -0
  191. package/{templates/components/evalkeeper → src/react}/AddCase.tsx +6 -6
  192. package/{templates/components/evalkeeper → src/react}/AnswerKey.tsx +92 -61
  193. package/{templates/components/evalkeeper → src/react}/CaseMenu.tsx +9 -8
  194. package/src/react/CompareView.tsx +270 -0
  195. package/{templates/components/evalkeeper → src/react}/ConfirmAnswer.tsx +6 -3
  196. package/{templates/components/evalkeeper → src/react}/DisagreementChip.tsx +2 -3
  197. package/src/react/FeedbackView.tsx +230 -0
  198. package/{templates/components/evalkeeper → src/react}/Fields.tsx +6 -6
  199. package/src/react/HubSections.tsx +446 -0
  200. package/src/react/ModelMenu.tsx +89 -0
  201. package/src/react/RateView.tsx +143 -0
  202. package/{templates/components/evalkeeper → src/react}/ReadableOutput.tsx +1 -1
  203. package/{templates/components/evalkeeper → src/react}/RollBack.tsx +9 -10
  204. package/src/react/RunView.tsx +151 -0
  205. package/{templates/components/evalkeeper → src/react}/SettingsHistory.tsx +16 -9
  206. package/src/react/SideBySideView.tsx +307 -0
  207. package/src/react/SuiteSections.tsx +925 -0
  208. package/src/react/Tabs.tsx +61 -0
  209. package/{templates/components/evalkeeper → src/react}/Thumbs.tsx +7 -6
  210. package/{templates/components/evalkeeper → src/react}/WeeklyCheck.tsx +31 -20
  211. package/src/react/app.ts +173 -0
  212. package/src/react/format.ts +45 -0
  213. package/src/react/index.ts +31 -0
  214. package/src/react/pieces.tsx +412 -0
  215. package/src/readCheck.ts +1 -1
  216. package/src/runner.ts +167 -3
  217. package/src/settings.ts +1 -1
  218. package/src/store.ts +1 -1
  219. package/src/suggest.ts +7 -7
  220. package/src/suiteContract.ts +35 -28
  221. package/src/testing.ts +2 -2
  222. package/src/types.ts +2 -2
  223. package/starter/index.ts +22 -8
  224. package/templates/app/api/cron/evals-weekly/route.ts +5 -15
  225. package/templates/app/evals/[suite]/compare/page.tsx +6 -383
  226. package/templates/app/evals/[suite]/page.tsx +7 -685
  227. package/templates/app/evals/[suite]/rate/page.tsx +6 -151
  228. package/templates/app/evals/[suite]/runs/[runId]/page.tsx +6 -174
  229. package/templates/app/evals/[suite]/side-by-side/page.tsx +6 -318
  230. package/templates/app/evals/feedback/page.tsx +6 -227
  231. package/templates/app/evals/layout.tsx +10 -0
  232. package/templates/app/evals/page.tsx +7 -397
  233. package/templates/lib/evalkeeper/actions.ts +34 -317
  234. package/templates/lib/evalkeeper/appComponents.tsx +21 -0
  235. package/templates/lib/evalkeeper/evals.ts +14 -0
  236. package/templates/lib/evalkeeper/paths.ts +2 -7
  237. package/templates/components/evalkeeper/Submit.tsx +0 -67
  238. package/templates/components/evalkeeper/Tip.tsx +0 -98
  239. package/templates/components/evalkeeper/ui.tsx +0 -105
  240. package/templates/lib/evalkeeper/time.ts +0 -4
  241. package/templates/lib/evalkeeper/weekly.ts +0 -74
@@ -1,10 +1,9 @@
1
1
  "use client";
2
2
 
3
+ import { Submit, TextInput, Tip } from "./pieces.js";
3
4
  import { useState } from "react";
4
- import type { ChangeKind } from "@crowandraven/evalkeeper";
5
- import { rollBackSettings } from "@/lib/evalkeeper/actions";
6
- import { Submit } from "./Submit";
7
- import { Tip } from "./Tip";
5
+ import type { ChangeKind } from "../index.js";
6
+ import type { FormAction } from "./app.js";
8
7
 
9
8
  /**
10
9
  * Rolls a feature back to an earlier version. The button stays off until
@@ -17,7 +16,10 @@ export function RollBack({
17
16
  versionId,
18
17
  number,
19
18
  kind,
19
+ action,
20
20
  }: {
21
+ /** Your rollBackSettings action. */
22
+ action: FormAction;
21
23
  suite: string;
22
24
  versionId: string;
23
25
  number: number;
@@ -33,16 +35,13 @@ export function RollBack({
33
35
  </Submit>
34
36
  );
35
37
  return (
36
- <form
37
- action={rollBackSettings}
38
- className="flex flex-wrap items-center gap-2"
39
- >
38
+ <form action={action} className="flex flex-wrap items-center gap-2">
40
39
  <input type="hidden" name="suite" value={suite} />
41
40
  <input type="hidden" name="version" value={versionId} />
42
41
  <label htmlFor={`why-${versionId}`} className="sr-only">
43
42
  Why roll back to v{number}?
44
43
  </label>
45
- <input
44
+ <TextInput
46
45
  id={`why-${versionId}`}
47
46
  name="reason"
48
47
  required
@@ -51,7 +50,7 @@ export function RollBack({
51
50
  setReason(e.target.value);
52
51
  }}
53
52
  placeholder="Why roll back?"
54
- className="rounded-md border border-line bg-card px-2 py-1 text-xs focus:border-accent focus:outline-none"
53
+ className="rounded-md border border-line bg-card px-3 py-1.5 text-sm focus:border-accent focus:outline-none"
55
54
  />
56
55
  {missing ? (
57
56
  <Tip
@@ -0,0 +1,151 @@
1
+ import { evalsPath, type EvalAppConfig } from "./app.js";
2
+ import { Link } from "./pieces.js";
3
+ import { allPassed, money, summarize } from "../index.js";
4
+ import { FieldValues } from "./Fields.js";
5
+ import { ReadableOutput } from "./ReadableOutput.js";
6
+ import { BackLink, Card } from "./pieces.js";
7
+ import { pct, momentOf, LINK } from "./format.js";
8
+
9
+ /** One test: every answer, with what each check found. */
10
+
11
+ /** One test: every answer, with what each check found. Null when it doesn't exist. */
12
+ export async function RunView({
13
+ app,
14
+ suite: key,
15
+ runId,
16
+ }: {
17
+ /** Your screens' configuration. */
18
+ app: EvalAppConfig;
19
+ suite: string;
20
+ runId: string;
21
+ }) {
22
+ const run = await app.store.getRun(runId);
23
+ if (!run || run.suite !== key) return null;
24
+ const suite = app.runner.suiteOrThrow(key);
25
+ const [outputs, cases] = await Promise.all([
26
+ app.store.listOutputs(runId),
27
+ app.store.listCases(key).then((cs) => new Map(cs.map((c) => [c.id, c]))),
28
+ ]);
29
+ const titleOf = (caseId: string) => {
30
+ const c = cases.get(caseId);
31
+ return c ? suite.title(suite.input.parse(c.input)) : "A retired case";
32
+ };
33
+ const metrics = run.metrics;
34
+ const summary = metrics ? summarize(metrics, suite.checks) : null;
35
+ const label = (k: string) =>
36
+ suite.checks.find((c) => c.key === k)?.label ?? k;
37
+ type Check = {
38
+ key: string;
39
+ pass: boolean | null;
40
+ note?: string;
41
+ given?: string;
42
+ matches?: { expected: string; actual: string; why: string }[];
43
+ };
44
+
45
+ return (
46
+ <div className="space-y-6">
47
+ <BackLink href={evalsPath(app, key)}>{suite.label}</BackLink>
48
+ <div className="space-y-1">
49
+ <h1 className="text-2xl font-semibold">
50
+ {app.models[run.model]?.label ?? run.model} on {suite.label}
51
+ </h1>
52
+ <p className="text-sm text-muted">
53
+ {momentOf(run.startedAt)} · {run.status.toLowerCase()}
54
+ {metrics && ` · spent ${money(metrics.costUsd)}`}
55
+ </p>
56
+ {run.error && <p className="readable text-bad">{run.error}</p>}
57
+ </div>
58
+ {summary && (
59
+ <Card className="space-y-2">
60
+ <p className="text-lg">
61
+ {summary.right} of {summary.total} answers fully right (
62
+ {pct(summary.total ? summary.right / summary.total : 0)})
63
+ </p>
64
+ <p className="readable text-sm text-muted">{summary.trust}</p>
65
+ {summary.problems.length > 0 && (
66
+ <ul className="readable list-disc pl-5 text-sm">
67
+ {summary.problems.map((p) => (
68
+ <li key={p.key}>
69
+ {p.label}: failed {p.failed} of {p.of}
70
+ </li>
71
+ ))}
72
+ </ul>
73
+ )}
74
+ </Card>
75
+ )}
76
+ <Card className="space-y-3">
77
+ {outputs.map((o) => {
78
+ const checks = (o.scores as Check[] | null) ?? null;
79
+ const ok = allPassed(checks);
80
+ return (
81
+ <div key={o.id} className="rounded-md bg-tint p-3 text-sm">
82
+ <div className="flex justify-between gap-4">
83
+ <span className="font-medium">{titleOf(o.caseId)}</span>
84
+ <span
85
+ className={
86
+ o.error ? "text-bad" : ok ? "text-good" : "text-warn"
87
+ }
88
+ >
89
+ {o.error ? "No answer" : ok ? "Right" : "Wrong"}
90
+ </span>
91
+ </div>
92
+ {o.error && <p className="text-bad">{o.error}</p>}
93
+ {!o.error && o.output !== null && (
94
+ <div className="mt-2">
95
+ {suite.fields && suite.labelFromOutput ? (
96
+ <FieldValues
97
+ fields={suite.fields.label}
98
+ values={suite.labelFromOutput(o.output)}
99
+ prefix={`${o.id}-`}
100
+ />
101
+ ) : (
102
+ <ReadableOutput value={o.output} />
103
+ )}
104
+ </div>
105
+ )}
106
+ {suite.decisions &&
107
+ checks?.some((c) => c.given !== undefined) && (
108
+ <ul className="mt-2 space-y-0.5 text-xs">
109
+ {checks
110
+ .filter((c) => c.given !== undefined)
111
+ .map((c) => (
112
+ <li key={c.key}>
113
+ <span className="text-muted">{label(c.key)}:</span>{" "}
114
+ {c.given}{" "}
115
+ <span className={c.pass ? "text-good" : "text-warn"}>
116
+ {c.pass ? "right" : "wrong"}
117
+ </span>
118
+ </li>
119
+ ))}
120
+ </ul>
121
+ )}
122
+ {checks
123
+ ?.filter((c) => c.pass === false)
124
+ .map((c) => (
125
+ <p key={c.key} className="readable mt-2 text-muted">
126
+ {label(c.key)}: {c.note ?? "failed"}
127
+ </p>
128
+ ))}
129
+ {checks
130
+ ?.flatMap((c) => c.matches ?? [])
131
+ .slice(0, 20)
132
+ .map((m, i) => (
133
+ <p key={i} className="readable mt-1 text-xs text-muted">
134
+ Matched “{m.expected}” with “{m.actual}”: {m.why}
135
+ </p>
136
+ ))}
137
+ {cases.has(o.caseId) && (
138
+ <Link
139
+ href={`${evalsPath(app, key)}#case-${o.caseId}`}
140
+ className={`mt-2 inline-block text-xs ${LINK}`}
141
+ >
142
+ Find the case in the answer key
143
+ </Link>
144
+ )}
145
+ </div>
146
+ );
147
+ })}
148
+ </Card>
149
+ </div>
150
+ );
151
+ }
@@ -1,15 +1,14 @@
1
- import Link from "next/link";
1
+ import { momentOf, LINK } from "./format.js";
2
2
  import {
3
3
  GLOSSARY,
4
4
  describeChange,
5
5
  type ChangeKind,
6
6
  type HistoryEntry,
7
7
  type Settings,
8
- } from "@crowandraven/evalkeeper";
9
- import { RollBack } from "./RollBack";
10
- import { InfoTip, Tip } from "./Tip";
11
- import { Chip } from "./ui";
12
- import { evalsPath } from "@/lib/evalkeeper/paths";
8
+ } from "../index.js";
9
+ import { RollBack } from "./RollBack.js";
10
+ import { Link, Chip, InfoTip, Tip } from "./pieces.js";
11
+ import { evalsPath, type EvalAppConfig } from "./app.js";
13
12
 
14
13
  const KIND: Record<
15
14
  ChangeKind,
@@ -55,12 +54,15 @@ type Evidence = { runId?: string | null; live?: string | null };
55
54
  * live again, with a reason.
56
55
  */
57
56
  export function SettingsHistory({
57
+ app,
58
58
  suite,
59
59
  entries,
60
60
  liveId,
61
61
  label,
62
62
  defaults,
63
63
  }: {
64
+ /** Your screens' configuration. */
65
+ app: EvalAppConfig;
64
66
  suite: string;
65
67
  entries: HistoryEntry[];
66
68
  liveId: string | null;
@@ -75,6 +77,7 @@ export function SettingsHistory({
75
77
  <InfoTip term="versions" />
76
78
  </h2>
77
79
  <HistoryEntries
80
+ app={app}
78
81
  suite={suite}
79
82
  entries={entries}
80
83
  liveId={liveId}
@@ -90,6 +93,7 @@ export function SettingsHistory({
90
93
  * unless it's live. For a page's history section or a card's history toggle.
91
94
  */
92
95
  export function HistoryEntries({
96
+ app,
93
97
  suite,
94
98
  entries,
95
99
  liveId,
@@ -97,6 +101,8 @@ export function HistoryEntries({
97
101
  defaults,
98
102
  plain = false,
99
103
  }: {
104
+ /** Your screens' configuration. */
105
+ app: EvalAppConfig;
100
106
  suite: string;
101
107
  entries: HistoryEntry[];
102
108
  liveId: string | null;
@@ -156,7 +162,7 @@ export function HistoryEntries({
156
162
  (e.kind === "OUTSIDE"
157
163
  ? "Found by the system"
158
164
  : "System")}{" "}
159
- · {e.createdAt.toLocaleString()}
165
+ · {momentOf(e.createdAt)}
160
166
  </span>
161
167
  </div>
162
168
  <ul className="readable list-disc pl-5">
@@ -178,14 +184,15 @@ export function HistoryEntries({
178
184
  <div className="flex flex-wrap items-center gap-3">
179
185
  {testId && (
180
186
  <Link
181
- href={evalsPath(suite, "runs", testId)}
182
- className="text-xs underline"
187
+ href={evalsPath(app, suite, "runs", testId)}
188
+ className={`text-xs ${LINK}`}
183
189
  >
184
190
  The test behind it
185
191
  </Link>
186
192
  )}
187
193
  {!isLive && (
188
194
  <RollBack
195
+ action={app.actions.rollBackSettings}
189
196
  suite={suite}
190
197
  versionId={e.to.id}
191
198
  number={e.to.number}
@@ -0,0 +1,307 @@
1
+ import { evalsPath, type EvalAppConfig } from "./app.js";
2
+ import { Link } from "./pieces.js";
3
+ import { ArrowLeft, ArrowRight, Check, Minus, X } from "lucide-react";
4
+ import {
5
+ aroundCase,
6
+ type AnySuite,
7
+ type CheckResult,
8
+ type OutputRecord,
9
+ type RunRecord,
10
+ } from "../index.js";
11
+ import { DisagreementChip } from "./DisagreementChip.js";
12
+ import { FieldValues } from "./Fields.js";
13
+ import { ReadableOutput } from "./ReadableOutput.js";
14
+ import { BackLink, Card, InfoTip, Tip } from "./pieces.js";
15
+ import { pct } from "./format.js";
16
+
17
+ /** A search parameter as one string, or null when it's missing or repeated. */
18
+ const one = (v: string | string[] | undefined) =>
19
+ typeof v === "string" && v ? v : null;
20
+
21
+ /**
22
+ * Two tests' answers to one case, side by side with the expected answer
23
+ * and what each check found, and previous and next through the cases the
24
+ * two graded differently. `a` is the test in place, `b` the challenger,
25
+ * and `case` the case (the first disagreement when left out).
26
+ */
27
+
28
+ /** Two tests' answers to the cases they graded differently, side by side. Null when it doesn't exist. */
29
+ export async function SideBySideView({
30
+ app,
31
+ suite: key,
32
+ search,
33
+ }: {
34
+ /** Your screens' configuration. */
35
+ app: EvalAppConfig;
36
+ suite: string;
37
+ search: Record<string, string | string[] | undefined>;
38
+ }) {
39
+ const sp = search;
40
+ const a = one(sp.a);
41
+ const b = one(sp.b);
42
+ if (!a || !b) return null;
43
+ const result = await app.runner.compare(key, a, b);
44
+ if (!result) return null;
45
+ const { suite, disagreements } = result;
46
+ const caseId = one(sp.case) ?? disagreements[0]?.caseId ?? null;
47
+ const compareHref = `${evalsPath(app, key, "compare")}?${new URLSearchParams({ a, b })}`;
48
+ const back = <BackLink href={compareHref}>Compare</BackLink>;
49
+ if (!caseId)
50
+ return (
51
+ <div className="space-y-4">
52
+ {back}
53
+ <h1 className="text-2xl font-semibold">Side by side</h1>
54
+ <p className="readable text-muted">
55
+ The two tests graded every shared case alike: there&apos;s nothing to
56
+ read side by side.
57
+ </p>
58
+ </div>
59
+ );
60
+
61
+ const [cases, outA, outB] = await Promise.all([
62
+ app.store.listCases(key, { includeRetired: true }),
63
+ app.store.listOutputs(a),
64
+ app.store.listOutputs(b),
65
+ ]);
66
+ const c = cases.find((x) => x.id === caseId);
67
+ if (!c) return null;
68
+ const input = suite.input.parse(c.input);
69
+ const expected =
70
+ c.labels.find((l) => l.status === "CONFIRMED") ??
71
+ c.labels.find((l) => l.status === "PROVISIONAL");
72
+ const here = aroundCase(disagreements, caseId);
73
+ const d = disagreements[here.index];
74
+ const to = (id: string) =>
75
+ `${evalsPath(app, key, "side-by-side")}?${new URLSearchParams({ a, b, case: id })}`;
76
+ const byRepeat = (os: OutputRecord[]) =>
77
+ os.filter((o) => o.caseId === caseId).sort((x, y) => x.repeat - y.repeat);
78
+
79
+ return (
80
+ <div className="space-y-6">
81
+ {back}
82
+ <div className="space-y-2">
83
+ <p className="text-sm text-muted">
84
+ Side by side
85
+ <InfoTip term="sideBySide" />
86
+ {" · "}
87
+ {suite.label}
88
+ </p>
89
+ <h1 className="text-2xl font-semibold">{suite.title(input)}</h1>
90
+ <div className="flex flex-wrap items-center justify-between gap-3">
91
+ <span className="flex items-center gap-2 text-sm text-muted">
92
+ {d ? (
93
+ <>
94
+ <DisagreementChip kind={d.kind} id="kind" />
95
+ <Tip term="disagreements" id="position">
96
+ <span>
97
+ {here.index + 1} of {disagreements.length} where they differ
98
+ </span>
99
+ </Tip>
100
+ </>
101
+ ) : (
102
+ <span>Both tests graded this case alike.</span>
103
+ )}
104
+ </span>
105
+ <nav aria-label="Cases where they differ" className="flex gap-2">
106
+ {here.previous ? (
107
+ <StepLink href={to(here.previous)} dir="previous" />
108
+ ) : (
109
+ <StepLink dir="previous" />
110
+ )}
111
+ {here.next ? (
112
+ <StepLink href={to(here.next)} dir="next" />
113
+ ) : (
114
+ <StepLink dir="next" />
115
+ )}
116
+ </nav>
117
+ </div>
118
+ </div>
119
+
120
+ <Card className="grid gap-5 text-sm md:grid-cols-2">
121
+ <section className="min-w-0 space-y-2">
122
+ <h2 className="text-xs font-semibold uppercase tracking-wide text-muted">
123
+ Input
124
+ </h2>
125
+ {/* A suite's own readable input (describe) reads best. */}
126
+ {suite.describe ? (
127
+ <pre className="readable text-xs whitespace-pre-wrap">
128
+ {suite.describe(input)}
129
+ </pre>
130
+ ) : suite.fields ? (
131
+ <FieldValues
132
+ fields={suite.fields.input}
133
+ values={c.input}
134
+ prefix="in-"
135
+ />
136
+ ) : (
137
+ <pre className="readable text-xs whitespace-pre-wrap">
138
+ {JSON.stringify(c.input, null, 2)}
139
+ </pre>
140
+ )}
141
+ </section>
142
+ <section className="min-w-0 space-y-2">
143
+ <h2 className="text-xs font-semibold uppercase tracking-wide text-muted">
144
+ Expected answer
145
+ <InfoTip term="expectedAnswer" />
146
+ </h2>
147
+ {!expected ? (
148
+ <p className="readable text-muted">No answer in use.</p>
149
+ ) : suite.fields ? (
150
+ <FieldValues
151
+ fields={suite.fields.label}
152
+ values={expected.value}
153
+ prefix="expected-"
154
+ />
155
+ ) : (
156
+ <pre className="readable whitespace-pre-wrap text-xs">
157
+ {JSON.stringify(expected.value, null, 2)}
158
+ </pre>
159
+ )}
160
+ </section>
161
+ </Card>
162
+
163
+ <div className="grid gap-4 md:grid-cols-2">
164
+ <Side
165
+ app={app}
166
+ side="inPlace"
167
+ run={result.a}
168
+ outputs={byRepeat(outA)}
169
+ suite={suite}
170
+ score={d?.champion ?? null}
171
+ runHref={evalsPath(app, key, "runs", a)}
172
+ />
173
+ <Side
174
+ app={app}
175
+ side="challenger"
176
+ run={result.b}
177
+ outputs={byRepeat(outB)}
178
+ suite={suite}
179
+ score={d?.challenger ?? null}
180
+ runHref={evalsPath(app, key, "runs", b)}
181
+ />
182
+ </div>
183
+ </div>
184
+ );
185
+ }
186
+
187
+ /** A link to the previous or next disagreement, or a dimmed one at either end. */
188
+ function StepLink({ href, dir }: { href?: string; dir: "previous" | "next" }) {
189
+ const label = dir === "previous" ? "Previous" : "Next";
190
+ const body =
191
+ dir === "previous" ? (
192
+ <>
193
+ <ArrowLeft aria-hidden className="h-4 w-4" />
194
+ {label}
195
+ </>
196
+ ) : (
197
+ <>
198
+ {label}
199
+ <ArrowRight aria-hidden className="h-4 w-4" />
200
+ </>
201
+ );
202
+ const cls =
203
+ "inline-flex items-center gap-1 rounded-md border border-line px-3 py-1.5 text-sm";
204
+ return href ? (
205
+ <Link href={href} className={`${cls} hover:bg-tint`}>
206
+ {body}
207
+ </Link>
208
+ ) : (
209
+ <span aria-disabled="true" className={`${cls} text-muted opacity-60`}>
210
+ {body}
211
+ </span>
212
+ );
213
+ }
214
+
215
+ /** One test's answers to the case, with what each check found. */
216
+ function Side({
217
+ app,
218
+ side,
219
+ run,
220
+ outputs,
221
+ suite,
222
+ score,
223
+ runHref,
224
+ }: {
225
+ app: EvalAppConfig;
226
+ side: "inPlace" | "challenger";
227
+ run: RunRecord;
228
+ outputs: OutputRecord[];
229
+ suite: AnySuite;
230
+ score: number | null;
231
+ runHref: string;
232
+ }) {
233
+ const label = (k: string) =>
234
+ suite.checks.find((x) => x.key === k)?.label ?? k;
235
+ return (
236
+ <Card className="space-y-4 text-sm">
237
+ <div className="space-y-1">
238
+ <p className="text-xs font-semibold uppercase tracking-wide text-muted">
239
+ {side === "inPlace" ? "In place" : "Challenger"}
240
+ <InfoTip term={side} id={`${side}-side`} />
241
+ </p>
242
+ <h2 className="text-lg font-semibold">
243
+ <Link href={runHref} className="hover:underline">
244
+ {app.models[run.model]?.label ?? run.model}
245
+ </Link>
246
+ </h2>
247
+ {score !== null && (
248
+ <Tip term="caseScore" id={`${side}-score`}>
249
+ <span className="text-muted">Scored {pct(score)} on this case</span>
250
+ </Tip>
251
+ )}
252
+ </div>
253
+ {outputs.length === 0 && (
254
+ <p className="readable text-muted">This test has no answer here.</p>
255
+ )}
256
+ {outputs.map((o) => {
257
+ const checks: CheckResult[] = o.scores ?? [];
258
+ return (
259
+ <section key={o.id} className="space-y-3 rounded-md bg-tint p-3">
260
+ {outputs.length > 1 && (
261
+ <p className="text-xs text-muted">Repeat {o.repeat + 1}</p>
262
+ )}
263
+ {o.error ? (
264
+ <p className="readable text-bad">No answer: {o.error}</p>
265
+ ) : suite.fields && suite.labelFromOutput ? (
266
+ <FieldValues
267
+ fields={suite.fields.label}
268
+ values={suite.labelFromOutput(o.output)}
269
+ prefix={`${side}-${o.repeat}-`}
270
+ />
271
+ ) : (
272
+ <ReadableOutput value={o.output} />
273
+ )}
274
+ {checks.length > 0 && (
275
+ <ul className="space-y-1">
276
+ {checks.map((x) => (
277
+ <li key={x.key} className="flex items-start gap-1.5">
278
+ {x.pass === null ? (
279
+ <Minus
280
+ aria-label="Doesn't apply"
281
+ className="mt-0.5 h-4 w-4 shrink-0 text-muted"
282
+ />
283
+ ) : x.pass ? (
284
+ <Check
285
+ aria-label="Passed"
286
+ className="mt-0.5 h-4 w-4 shrink-0 text-good"
287
+ />
288
+ ) : (
289
+ <X
290
+ aria-label="Failed"
291
+ className="mt-0.5 h-4 w-4 shrink-0 text-warn"
292
+ />
293
+ )}
294
+ <span className="readable">
295
+ {label(x.key)}
296
+ {x.note && <span className="text-muted">: {x.note}</span>}
297
+ </span>
298
+ </li>
299
+ ))}
300
+ </ul>
301
+ )}
302
+ </section>
303
+ );
304
+ })}
305
+ </Card>
306
+ );
307
+ }