@crowandraven/evalkeeper 0.9.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 (246) 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 +9 -0
  29. package/dist/glossary.js +9 -0
  30. package/dist/glossary.js.map +1 -1
  31. package/dist/health.d.ts +4 -1
  32. package/dist/health.js +4 -2
  33. package/dist/health.js.map +1 -1
  34. package/dist/inInstructions.d.ts +1 -1
  35. package/dist/inInstructions.js +1 -1
  36. package/dist/next/RefreshWhile.d.ts +11 -0
  37. package/dist/next/RefreshWhile.js +28 -0
  38. package/dist/next/RefreshWhile.js.map +1 -0
  39. package/dist/next/actions.d.ts +14 -0
  40. package/dist/next/actions.js +332 -0
  41. package/dist/next/actions.js.map +1 -0
  42. package/dist/next/components.d.ts +9 -0
  43. package/dist/next/components.js +27 -0
  44. package/dist/next/components.js.map +1 -0
  45. package/dist/next/cron.d.ts +9 -0
  46. package/dist/next/cron.js +17 -0
  47. package/dist/next/cron.js.map +1 -0
  48. package/dist/next/index.d.ts +15 -0
  49. package/dist/next/index.js +16 -0
  50. package/dist/next/index.js.map +1 -0
  51. package/dist/next/pages.d.ts +70 -0
  52. package/dist/next/pages.js +77 -0
  53. package/dist/next/pages.js.map +1 -0
  54. package/dist/next/route.d.ts +19 -0
  55. package/dist/next/route.js +31 -0
  56. package/dist/next/route.js.map +1 -0
  57. package/dist/next/weekly.d.ts +20 -0
  58. package/dist/next/weekly.js +55 -0
  59. package/dist/next/weekly.js.map +1 -0
  60. package/dist/next/wiring.d.ts +19 -0
  61. package/dist/next/wiring.js +2 -0
  62. package/dist/next/wiring.js.map +1 -0
  63. package/dist/prisma/contracts.d.ts +74 -0
  64. package/dist/prisma/contracts.js +178 -0
  65. package/dist/prisma/contracts.js.map +1 -0
  66. package/dist/prisma/index.d.ts +423 -0
  67. package/dist/prisma/index.js +622 -0
  68. package/dist/prisma/index.js.map +1 -0
  69. package/dist/prisma/mapping.d.ts +63 -0
  70. package/dist/prisma/mapping.js +111 -0
  71. package/dist/prisma/mapping.js.map +1 -0
  72. package/dist/prisma/moveIn.d.ts +106 -0
  73. package/dist/prisma/moveIn.js +299 -0
  74. package/dist/prisma/moveIn.js.map +1 -0
  75. package/dist/prune.d.ts +45 -0
  76. package/dist/prune.js +32 -0
  77. package/dist/prune.js.map +1 -1
  78. package/dist/react/AddCase.d.ts +10 -0
  79. package/dist/react/AddCase.js +19 -0
  80. package/dist/react/AddCase.js.map +1 -0
  81. package/dist/react/AnswerKey.d.ts +22 -0
  82. package/dist/react/AnswerKey.js +83 -0
  83. package/dist/react/AnswerKey.js.map +1 -0
  84. package/dist/react/CaseMenu.d.ts +17 -0
  85. package/dist/react/CaseMenu.js +41 -0
  86. package/dist/react/CaseMenu.js.map +1 -0
  87. package/dist/react/CompareView.d.ts +14 -0
  88. package/dist/react/CompareView.js +51 -0
  89. package/dist/react/CompareView.js.map +1 -0
  90. package/dist/react/ConfirmAnswer.d.ts +13 -0
  91. package/dist/react/ConfirmAnswer.js +27 -0
  92. package/dist/react/ConfirmAnswer.js.map +1 -0
  93. package/dist/react/DisagreementChip.d.ts +10 -0
  94. package/dist/react/DisagreementChip.js +21 -0
  95. package/dist/react/DisagreementChip.js.map +1 -0
  96. package/dist/react/FeedbackView.d.ts +10 -0
  97. package/dist/react/FeedbackView.js +26 -0
  98. package/dist/react/FeedbackView.js.map +1 -0
  99. package/dist/react/Fields.d.ts +32 -0
  100. package/dist/react/Fields.js +33 -0
  101. package/dist/react/Fields.js.map +1 -0
  102. package/dist/react/HubSections.d.ts +78 -0
  103. package/dist/react/HubSections.js +124 -0
  104. package/dist/react/HubSections.js.map +1 -0
  105. package/dist/react/ModelMenu.d.ts +16 -0
  106. package/dist/react/ModelMenu.js +38 -0
  107. package/dist/react/ModelMenu.js.map +1 -0
  108. package/dist/react/RateView.d.ts +18 -0
  109. package/dist/react/RateView.js +30 -0
  110. package/dist/react/RateView.js.map +1 -0
  111. package/dist/react/ReadableOutput.d.ts +3 -0
  112. package/dist/react/ReadableOutput.js +50 -0
  113. package/dist/react/ReadableOutput.js.map +1 -0
  114. package/dist/react/RollBack.d.ts +17 -0
  115. package/dist/react/RollBack.js +26 -0
  116. package/dist/react/RollBack.js.map +1 -0
  117. package/dist/react/RunView.d.ts +9 -0
  118. package/dist/react/RunView.js +41 -0
  119. package/dist/react/RunView.js.map +1 -0
  120. package/dist/react/SettingsHistory.d.ts +33 -0
  121. package/dist/react/SettingsHistory.js +79 -0
  122. package/dist/react/SettingsHistory.js.map +1 -0
  123. package/dist/react/SideBySideView.d.ts +14 -0
  124. package/dist/react/SideBySideView.js +67 -0
  125. package/dist/react/SideBySideView.js.map +1 -0
  126. package/dist/react/SuiteSections.d.ts +111 -0
  127. package/dist/react/SuiteSections.js +224 -0
  128. package/dist/react/SuiteSections.js.map +1 -0
  129. package/dist/react/Tabs.d.ts +15 -0
  130. package/dist/react/Tabs.js +18 -0
  131. package/dist/react/Tabs.js.map +1 -0
  132. package/dist/react/Thumbs.d.ts +13 -0
  133. package/dist/react/Thumbs.js +54 -0
  134. package/dist/react/Thumbs.js.map +1 -0
  135. package/dist/react/WeeklyCheck.d.ts +11 -0
  136. package/dist/react/WeeklyCheck.js +19 -0
  137. package/dist/react/WeeklyCheck.js.map +1 -0
  138. package/dist/react/app.d.ts +118 -0
  139. package/dist/react/app.js +87 -0
  140. package/dist/react/app.js.map +1 -0
  141. package/dist/react/format.d.ts +27 -0
  142. package/dist/react/format.js +38 -0
  143. package/dist/react/format.js.map +1 -0
  144. package/dist/react/index.d.ts +31 -0
  145. package/dist/react/index.js +32 -0
  146. package/dist/react/index.js.map +1 -0
  147. package/dist/react/pieces.d.ts +191 -0
  148. package/dist/react/pieces.js +191 -0
  149. package/dist/react/pieces.js.map +1 -0
  150. package/dist/readCheck.d.ts +1 -1
  151. package/dist/runner.d.ts +76 -3
  152. package/dist/runner.js +133 -3
  153. package/dist/runner.js.map +1 -1
  154. package/dist/settings.d.ts +1 -1
  155. package/dist/store.d.ts +1 -1
  156. package/dist/suggest.d.ts +52 -2
  157. package/dist/suggest.js +101 -8
  158. package/dist/suggest.js.map +1 -1
  159. package/dist/suiteContract.d.ts +3 -3
  160. package/dist/suiteContract.js +20 -16
  161. package/dist/suiteContract.js.map +1 -1
  162. package/dist/testing.d.ts +2 -2
  163. package/dist/testing.js +1 -1
  164. package/dist/types.d.ts +79 -2
  165. package/dist/types.js +96 -12
  166. package/dist/types.js.map +1 -1
  167. package/package.json +56 -6
  168. package/schema/evalkeeper.prisma +196 -0
  169. package/src/ai-sdk/decide.ts +57 -0
  170. package/src/ai-sdk/hash.ts +74 -0
  171. package/src/ai-sdk/index.ts +15 -0
  172. package/src/ai-sdk/judge.ts +163 -0
  173. package/src/ai-sdk/usage.ts +31 -0
  174. package/src/board.ts +5 -0
  175. package/src/cli/addPages.ts +15 -7
  176. package/src/cli/main.ts +135 -9
  177. package/src/cli/migration.ts +349 -0
  178. package/src/feedback.ts +1 -1
  179. package/src/glossary.ts +18 -0
  180. package/src/health.ts +4 -2
  181. package/src/inInstructions.ts +1 -1
  182. package/{templates/components/evalkeeper → src/next}/RefreshWhile.tsx +2 -2
  183. package/src/next/actions.ts +389 -0
  184. package/src/next/components.ts +31 -0
  185. package/{templates/lib/evalkeeper/cronAuth.ts → src/next/cron.ts} +3 -0
  186. package/src/next/index.ts +15 -0
  187. package/src/next/pages.tsx +106 -0
  188. package/src/next/route.ts +35 -0
  189. package/src/next/weekly.ts +70 -0
  190. package/src/next/wiring.ts +18 -0
  191. package/src/prisma/contracts.ts +249 -0
  192. package/src/prisma/index.ts +1169 -0
  193. package/src/prisma/mapping.ts +147 -0
  194. package/src/prisma/moveIn.ts +502 -0
  195. package/src/prune.ts +77 -0
  196. package/{templates/components/evalkeeper → src/react}/AddCase.tsx +6 -6
  197. package/{templates/components/evalkeeper → src/react}/AnswerKey.tsx +96 -59
  198. package/{templates/components/evalkeeper → src/react}/CaseMenu.tsx +9 -8
  199. package/src/react/CompareView.tsx +270 -0
  200. package/{templates/components/evalkeeper → src/react}/ConfirmAnswer.tsx +6 -3
  201. package/{templates/components/evalkeeper → src/react}/DisagreementChip.tsx +2 -3
  202. package/src/react/FeedbackView.tsx +230 -0
  203. package/{templates/components/evalkeeper → src/react}/Fields.tsx +54 -10
  204. package/src/react/HubSections.tsx +446 -0
  205. package/src/react/ModelMenu.tsx +89 -0
  206. package/src/react/RateView.tsx +143 -0
  207. package/{templates/components/evalkeeper → src/react}/ReadableOutput.tsx +1 -1
  208. package/{templates/components/evalkeeper → src/react}/RollBack.tsx +9 -10
  209. package/src/react/RunView.tsx +151 -0
  210. package/{templates/components/evalkeeper → src/react}/SettingsHistory.tsx +16 -9
  211. package/src/react/SideBySideView.tsx +307 -0
  212. package/src/react/SuiteSections.tsx +925 -0
  213. package/src/react/Tabs.tsx +61 -0
  214. package/{templates/components/evalkeeper → src/react}/Thumbs.tsx +7 -6
  215. package/{templates/components/evalkeeper → src/react}/WeeklyCheck.tsx +31 -20
  216. package/src/react/app.ts +173 -0
  217. package/src/react/format.ts +45 -0
  218. package/src/react/index.ts +31 -0
  219. package/src/react/pieces.tsx +412 -0
  220. package/src/readCheck.ts +1 -1
  221. package/src/runner.ts +182 -4
  222. package/src/settings.ts +1 -1
  223. package/src/store.ts +1 -1
  224. package/src/suggest.ts +145 -13
  225. package/src/suiteContract.ts +35 -28
  226. package/src/testing.ts +2 -2
  227. package/src/types.ts +147 -19
  228. package/starter/index.ts +33 -8
  229. package/templates/app/api/cron/evals-weekly/route.ts +5 -15
  230. package/templates/app/evals/[suite]/compare/page.tsx +6 -383
  231. package/templates/app/evals/[suite]/page.tsx +7 -532
  232. package/templates/app/evals/[suite]/rate/page.tsx +6 -141
  233. package/templates/app/evals/[suite]/runs/[runId]/page.tsx +6 -174
  234. package/templates/app/evals/[suite]/side-by-side/page.tsx +6 -318
  235. package/templates/app/evals/feedback/page.tsx +6 -227
  236. package/templates/app/evals/layout.tsx +10 -0
  237. package/templates/app/evals/page.tsx +7 -365
  238. package/templates/lib/evalkeeper/actions.ts +34 -296
  239. package/templates/lib/evalkeeper/appComponents.tsx +21 -0
  240. package/templates/lib/evalkeeper/evals.ts +14 -0
  241. package/templates/lib/evalkeeper/paths.ts +2 -7
  242. package/templates/components/evalkeeper/Submit.tsx +0 -67
  243. package/templates/components/evalkeeper/Tip.tsx +0 -98
  244. package/templates/components/evalkeeper/ui.tsx +0 -105
  245. package/templates/lib/evalkeeper/time.ts +0 -4
  246. package/templates/lib/evalkeeper/weekly.ts +0 -74
@@ -0,0 +1,270 @@
1
+ import { evalsPath, type EvalAppConfig } from "./app.js";
2
+ import { BackLink, Card, Chip, InfoTip, Link, Tip } from "./pieces.js";
3
+ import { pct, momentOf, LINK } from "./format.js";
4
+ import {
5
+ checkBar,
6
+ perAnswer,
7
+ seconds,
8
+ verdictSentence,
9
+ type Rate,
10
+ type RunRecord,
11
+ type ModelCatalog,
12
+ } from "../index.js";
13
+ import { DisagreementChip } from "./DisagreementChip.js";
14
+
15
+ /** A search parameter as one string, or null when it's missing or repeated. */
16
+ const one = (v: string | string[] | undefined) =>
17
+ typeof v === "string" && v ? v : null;
18
+
19
+ /** A test's name: its model, reasoning setting, set, and when it ran. */
20
+ function testName(models: ModelCatalog, r: RunRecord): string {
21
+ const model = models[r.model]?.label ?? r.model;
22
+ const effort = r.reasoningEffort ? `, ${r.reasoningEffort} reasoning` : "";
23
+ const set = r.set === "ALL" ? "" : `, ${r.set.toLowerCase()} set`;
24
+ return `${model}${effort}${set} · ${momentOf(r.startedAt)}`;
25
+ }
26
+
27
+ /** A pass rate as "80% (8/10)", or a dash when the check never applied. */
28
+ function rateText(r: Rate | undefined): string {
29
+ return r && r.n > 0 ? `${pct(r.passed / r.n)} (${r.passed}/${r.n})` : "—";
30
+ }
31
+
32
+ /**
33
+ * Two finished tests of a suite compared: the verdict in plain words, each
34
+ * check's pass rate side by side, and the cases they graded differently,
35
+ * each linked to its answers side by side. `a` is the test in place (the
36
+ * live model's latest when left out), `b` the challenger.
37
+ */
38
+
39
+ /** Two tests of a suite compared: the verdict, each check, and the cases they graded differently. Null when it doesn't exist. */
40
+ export async function CompareView({
41
+ app,
42
+ suite: key,
43
+ search,
44
+ }: {
45
+ /** Your screens' configuration. */
46
+ app: EvalAppConfig;
47
+ suite: string;
48
+ search: Record<string, string | string[] | undefined>;
49
+ }) {
50
+ const sp = search;
51
+ const suiteDef = app.suiteByKey[key];
52
+ if (!suiteDef) return null;
53
+ // Opened from an "Against live" verdict: the test in place and the
54
+ // challenger, both finished tests of this suite.
55
+ const a = one(sp.a);
56
+ const b = one(sp.b);
57
+ if (!a || !b) return null;
58
+ const result = await app.runner.compare(key, a, b);
59
+ if (!result) return null;
60
+ const titles = new Map(
61
+ (await app.store.listCases(key, { includeRetired: true })).map((c) => [
62
+ c.id,
63
+ suiteDef.title(suiteDef.input.parse(c.input)),
64
+ ]),
65
+ );
66
+ const sideBySide = (caseId: string) =>
67
+ `${evalsPath(app, key, "side-by-side")}?${new URLSearchParams({ a: result.a.id, b: result.b.id, case: caseId })}`;
68
+
69
+ return (
70
+ <div className="space-y-8">
71
+ <div className="space-y-2">
72
+ <BackLink href={evalsPath(app, key)}>{suiteDef.label}</BackLink>
73
+ <h1 className="text-2xl font-semibold">
74
+ {app.models[result.b.model]?.label ?? result.b.model} against{" "}
75
+ {app.models[result.a.model]?.label ?? result.a.model}
76
+ <InfoTip term="comparison" />
77
+ </h1>
78
+ </div>
79
+
80
+ <>
81
+ <Card className="space-y-3">
82
+ <div className="flex flex-wrap items-start justify-between gap-3">
83
+ <h2 className="font-semibold">
84
+ Verdict
85
+ <InfoTip term="verdict" />
86
+ </h2>
87
+ </div>
88
+ <p className="readable text-lg">
89
+ {verdictSentence(
90
+ result.comparison,
91
+ app.models[result.b.model]?.label ?? result.b.model,
92
+ )}
93
+ </p>
94
+ <p className="readable text-sm text-muted">
95
+ <Link
96
+ href={evalsPath(app, key, "runs", result.a.id)}
97
+ className={LINK}
98
+ >
99
+ {testName(app.models, result.a)}
100
+ </Link>{" "}
101
+ (in place) against{" "}
102
+ <Link
103
+ href={evalsPath(app, key, "runs", result.b.id)}
104
+ className={LINK}
105
+ >
106
+ {testName(app.models, result.b)}
107
+ </Link>{" "}
108
+ (challenger), on{" "}
109
+ <Tip term="sharedCases">
110
+ <span>{result.comparison.n} shared cases</span>
111
+ </Tip>
112
+ .
113
+ </p>
114
+ <p className="text-sm text-muted">
115
+ <Tip term="cost" id="cost-compare">
116
+ <span>
117
+ Cost per answer: {perAnswer(result.comparison.cost.champion)} in
118
+ place, {perAnswer(result.comparison.cost.challenger)} challenger
119
+ </span>
120
+ </Tip>
121
+ {" · "}
122
+ <Tip term="time" id="time-compare" align="end">
123
+ <span>
124
+ Time: {seconds(result.comparison.avgMs.champion)} in place,{" "}
125
+ {seconds(result.comparison.avgMs.challenger)} challenger
126
+ </span>
127
+ </Tip>
128
+ </p>
129
+ {result.caveats.length > 0 && (
130
+ <div className="readable rounded-md bg-tint p-3 text-sm">
131
+ <p className="font-medium">
132
+ Measured differently
133
+ <InfoTip term="measuredDifferently" />
134
+ </p>
135
+ <ul className="list-disc pl-5 text-muted">
136
+ {result.caveats.map((c) => (
137
+ <li key={c}>{c}</li>
138
+ ))}
139
+ </ul>
140
+ </div>
141
+ )}
142
+ </Card>
143
+
144
+ <section className="space-y-3">
145
+ <h2 className="text-lg font-semibold">
146
+ Checks
147
+ <InfoTip term="checks" />
148
+ </h2>
149
+ <Card className="overflow-x-auto p-0">
150
+ <table className="w-full text-sm">
151
+ <thead className="text-left text-muted">
152
+ <tr className="border-b border-line">
153
+ <th className="p-3 font-normal">Check</th>
154
+ <th className="p-3 font-normal">
155
+ <Tip term="inPlace" side="bottom" id="inPlace-col">
156
+ In place
157
+ </Tip>
158
+ </th>
159
+ <th className="p-3 font-normal">
160
+ <Tip term="challenger" side="bottom" id="challenger-col">
161
+ Challenger
162
+ </Tip>
163
+ </th>
164
+ <th className="p-3 font-normal">
165
+ <Tip term="bar" side="bottom" align="end">
166
+ Bar
167
+ </Tip>
168
+ </th>
169
+ </tr>
170
+ </thead>
171
+ <tbody>
172
+ {result.suite.checks.map((c) => {
173
+ const r = result.comparison.byCheck[c.key];
174
+ return (
175
+ <tr
176
+ key={c.key}
177
+ className="border-b border-line last:border-0"
178
+ >
179
+ <td className="p-3">
180
+ <span className="flex flex-wrap items-center gap-2">
181
+ {c.label}
182
+ <Tip
183
+ term={c.severity}
184
+ id={`severity-${c.key}`}
185
+ side="bottom"
186
+ >
187
+ <Chip
188
+ tone={
189
+ c.severity === "serious" ? "serious" : "neutral"
190
+ }
191
+ >
192
+ {c.severity}
193
+ </Chip>
194
+ </Tip>
195
+ </span>
196
+ </td>
197
+ <td className="p-3 tabular-nums">
198
+ <Tip term="passRate" id={`a-${c.key}`} side="bottom">
199
+ <span>{rateText(r?.champion)}</span>
200
+ </Tip>
201
+ </td>
202
+ <td className="p-3 tabular-nums">
203
+ <Tip term="passRate" id={`b-${c.key}`} side="bottom">
204
+ <span>{rateText(r?.challenger)}</span>
205
+ </Tip>
206
+ </td>
207
+ <td className="p-3 tabular-nums text-muted">
208
+ {pct(checkBar(c))}
209
+ </td>
210
+ </tr>
211
+ );
212
+ })}
213
+ </tbody>
214
+ </table>
215
+ </Card>
216
+ </section>
217
+
218
+ <section className="space-y-3">
219
+ <div className="flex flex-wrap items-center justify-between gap-3">
220
+ <h2 className="text-lg font-semibold">
221
+ Where they differ ({result.disagreements.length})
222
+ <InfoTip term="disagreements" />
223
+ </h2>
224
+ {result.disagreements[0] && (
225
+ <Link
226
+ href={sideBySide(result.disagreements[0].caseId)}
227
+ className={`text-sm ${LINK}`}
228
+ >
229
+ Read them side by side
230
+ </Link>
231
+ )}
232
+ </div>
233
+ {result.disagreements.length === 0 ? (
234
+ <p className="readable text-muted">
235
+ The two tests graded every shared case alike.
236
+ </p>
237
+ ) : (
238
+ <Card className="space-y-2">
239
+ {result.disagreements.map((d) => (
240
+ <div
241
+ key={d.caseId}
242
+ className="flex flex-wrap items-center justify-between gap-3 rounded-md bg-tint p-3 text-sm"
243
+ >
244
+ <Link
245
+ href={sideBySide(d.caseId)}
246
+ className={`font-medium ${LINK}`}
247
+ >
248
+ {titles.get(d.caseId) ?? "A retired case"}
249
+ </Link>
250
+ <span className="flex items-center gap-3">
251
+ <Tip term="caseScore" id={`score-${d.caseId}`}>
252
+ <span className="text-xs text-muted tabular-nums">
253
+ {pct(d.champion)} → {pct(d.challenger)}
254
+ </span>
255
+ </Tip>
256
+ <DisagreementChip
257
+ kind={d.kind}
258
+ id={`kind-${d.caseId}`}
259
+ align="end"
260
+ />
261
+ </span>
262
+ </div>
263
+ ))}
264
+ </Card>
265
+ )}
266
+ </section>
267
+ </>
268
+ </div>
269
+ );
270
+ }
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
 
3
- import { confirmAnswer } from "@/lib/evalkeeper/actions";
4
- import { Submit } from "./Submit";
3
+ import type { FormAction } from "./app.js";
4
+ import { Submit } from "./pieces.js";
5
5
 
6
6
  /**
7
7
  * Confirms a case's pending answer and moves straight on: this case closes
@@ -12,13 +12,16 @@ import { Submit } from "./Submit";
12
12
  export function ConfirmAnswer({
13
13
  suite,
14
14
  labelId,
15
+ action,
15
16
  }: {
16
17
  suite: string;
17
18
  labelId: string;
19
+ /** Your confirmAnswer action. */
20
+ action: FormAction;
18
21
  }) {
19
22
  return (
20
23
  <form
21
- action={confirmAnswer}
24
+ action={action}
22
25
  onSubmit={(e) => {
23
26
  const here = e.currentTarget.closest("details");
24
27
  if (!here) return;
@@ -1,6 +1,5 @@
1
- import type { DisagreementKind } from "@crowandraven/evalkeeper";
2
- import { Tip } from "./Tip";
3
- import { Chip } from "./ui";
1
+ import type { DisagreementKind } from "../index.js";
2
+ import { Chip, Tip } from "./pieces.js";
4
3
 
5
4
  /** How each kind of disagreement shows: its chip and its glossary entry. */
6
5
  const KIND = {
@@ -0,0 +1,230 @@
1
+ import { daysAgo, type EvalAppConfig } from "./app.js";
2
+ import {
3
+ asText,
4
+ isInjectionSuite,
5
+ thumbsSummary,
6
+ whyNotACase,
7
+ type AnySuite,
8
+ type FeedbackRecord,
9
+ } from "../index.js";
10
+ import { FieldValues } from "./Fields.js";
11
+ import { BackLink, Card, Chip, InfoTip, Submit, Tip } from "./pieces.js";
12
+ import { pct, momentOf } from "./format.js";
13
+ import { ThumbsDown, ThumbsUp } from "lucide-react";
14
+
15
+ /**
16
+ * What people thought of the AI's answers: thumbs per feature this week,
17
+ * and each rating waiting for a look, to make into a case or dismiss.
18
+ */
19
+
20
+ /** Thumbs up and down, and what to do with each. Null when it doesn't exist. */
21
+ export async function FeedbackView({
22
+ app,
23
+ }: {
24
+ /** Your screens' configuration. */
25
+ app: EvalAppConfig;
26
+ }) {
27
+ const all = await app.feedbackStore.listFeedback();
28
+ const summary = thumbsSummary(all, daysAgo(7));
29
+ const open = all
30
+ .filter((f) => f.status === "OPEN")
31
+ .sort((a, b) => Number(b.rating === "DOWN") - Number(a.rating === "DOWN"));
32
+ const suiteFor = (op: string) =>
33
+ app.suites.find((s) => s.operation === op && !isInjectionSuite(s));
34
+ const label = (op: string) => suiteFor(op)?.label ?? op;
35
+
36
+ return (
37
+ <div className="space-y-8">
38
+ <div className="space-y-2">
39
+ <BackLink href={app.basePath}>Evals</BackLink>
40
+ <h1 className="text-2xl font-semibold">Feedback</h1>
41
+ <p className="readable text-muted">
42
+ Thumbs up and down from people using the product. A rating on a kept
43
+ input can become a draft case, so the next model is tested on the
44
+ answer people didn&apos;t like.
45
+ </p>
46
+ </div>
47
+
48
+ <section className="space-y-3">
49
+ <h2 className="text-lg font-semibold">
50
+ This week
51
+ <InfoTip term="thumbs" />
52
+ </h2>
53
+ {summary.length === 0 ? (
54
+ <p className="text-sm text-muted">No ratings this week.</p>
55
+ ) : (
56
+ <Card className="overflow-x-auto p-0 lg:overflow-visible">
57
+ <table className="w-full text-sm">
58
+ <thead className="text-left text-muted">
59
+ <tr className="border-b border-line">
60
+ <th className="p-3 font-normal">Feature</th>
61
+ <th className="p-3 font-normal">Thumbs up</th>
62
+ <th className="p-3 font-normal">Thumbs down</th>
63
+ <th className="p-3 font-normal">Share down</th>
64
+ <th className="p-3 font-normal">Waiting</th>
65
+ </tr>
66
+ </thead>
67
+ <tbody>
68
+ {summary.map((s) => (
69
+ <tr
70
+ key={s.operation}
71
+ className="border-b border-line last:border-0"
72
+ >
73
+ <td className="p-3">
74
+ <span className="mr-2 font-medium">
75
+ {label(s.operation)}
76
+ </span>
77
+ {s.alert && (
78
+ <Tip
79
+ text="At least 5 ratings, and at least 20% of them thumbs down: worth a look."
80
+ id={`alert-${s.operation}`}
81
+ side="bottom"
82
+ >
83
+ <Chip tone="warn">Needs a look</Chip>
84
+ </Tip>
85
+ )}
86
+ </td>
87
+ <td className="p-3 tabular-nums">{s.up}</td>
88
+ <td className="p-3 tabular-nums">{s.down}</td>
89
+ <td className="p-3 tabular-nums">
90
+ {s.downShare === null ? "—" : pct(s.downShare)}
91
+ </td>
92
+ <td className="p-3 tabular-nums">{s.open}</td>
93
+ </tr>
94
+ ))}
95
+ </tbody>
96
+ </table>
97
+ </Card>
98
+ )}
99
+ </section>
100
+
101
+ <section className="space-y-3">
102
+ <h2 className="text-lg font-semibold">
103
+ Waiting for a look ({open.length})
104
+ </h2>
105
+ {open.length === 0 && (
106
+ <p className="text-sm text-muted">
107
+ Nothing waiting. Ratings show up here once an AI feature has a
108
+ thumbs up and down (step 8 of{" "}
109
+ <a
110
+ href="https://seanhudson.github.io/evalkeeper/guides/thumbs/#set-it-up"
111
+ target="_blank"
112
+ rel="noreferrer"
113
+ className="underline"
114
+ >
115
+ the guide
116
+ </a>
117
+ ).
118
+ </p>
119
+ )}
120
+ <div className="space-y-3">
121
+ {open.map((f) => (
122
+ <Rating
123
+ app={app}
124
+ key={f.id}
125
+ fields={suiteFor(f.operation)?.fields}
126
+ f={f}
127
+ feature={label(f.operation)}
128
+ why={whyNotACase(f, suiteFor(f.operation))}
129
+ />
130
+ ))}
131
+ </div>
132
+ </section>
133
+ </div>
134
+ );
135
+ }
136
+
137
+ function Rating({
138
+ app,
139
+ f,
140
+ fields,
141
+ feature,
142
+ why,
143
+ }: {
144
+ app: EvalAppConfig;
145
+ f: FeedbackRecord;
146
+ fields: AnySuite["fields"];
147
+ feature: string;
148
+ why: string | null;
149
+ }) {
150
+ return (
151
+ <article
152
+ aria-label={`Rating: ${feature}${f.reason ? `, ${f.reason}` : ""}`}
153
+ >
154
+ <Card className="space-y-3 text-sm">
155
+ <div className="flex flex-wrap items-center justify-between gap-2">
156
+ <span className="flex items-center gap-2">
157
+ <Chip tone={f.rating === "DOWN" ? "serious" : "live"}>
158
+ {f.rating === "DOWN" ? (
159
+ <>
160
+ <ThumbsDown aria-hidden className="h-3.5 w-3.5" /> Thumbs down
161
+ </>
162
+ ) : (
163
+ <>
164
+ <ThumbsUp aria-hidden className="h-3.5 w-3.5" /> Thumbs up
165
+ </>
166
+ )}
167
+ </Chip>
168
+ <span className="font-medium">{feature}</span>
169
+ </span>
170
+ <span className="text-xs text-muted">{momentOf(f.updatedAt)}</span>
171
+ </div>
172
+ {f.reason && <p className="readable">&ldquo;{f.reason}&rdquo;</p>}
173
+ <div className="grid gap-4 md:grid-cols-2">
174
+ <div className="space-y-1">
175
+ <p className="text-xs font-semibold uppercase tracking-wide text-muted">
176
+ Input
177
+ </p>
178
+ {f.input === null ? (
179
+ <p className="text-muted">Not kept</p>
180
+ ) : fields ? (
181
+ <FieldValues
182
+ fields={fields.input}
183
+ values={f.input}
184
+ prefix={`${f.id}-in-`}
185
+ />
186
+ ) : (
187
+ <p className="whitespace-pre-wrap font-mono text-xs">
188
+ {asText(f.input)}
189
+ </p>
190
+ )}
191
+ </div>
192
+ <div className="space-y-1">
193
+ <p className="text-xs font-semibold uppercase tracking-wide text-muted">
194
+ Answer
195
+ </p>
196
+ {fields && f.output !== null ? (
197
+ <FieldValues
198
+ fields={fields.label}
199
+ values={f.output}
200
+ prefix={`${f.id}-out-`}
201
+ />
202
+ ) : (
203
+ <p className="whitespace-pre-wrap font-mono text-xs">
204
+ {asText(f.output) || f.excerpt || "—"}
205
+ </p>
206
+ )}
207
+ </div>
208
+ </div>
209
+ <div className="flex flex-wrap items-center gap-2">
210
+ {why === null ? (
211
+ <form
212
+ action={app.actions.makeCase}
213
+ className="flex items-center gap-1"
214
+ >
215
+ <input type="hidden" name="feedback" value={f.id} />
216
+ <Submit>Make a case</Submit>
217
+ <InfoTip term="makeCase" id={`make-${f.id}`} />
218
+ </form>
219
+ ) : (
220
+ <p className="readable text-xs text-muted">{why}</p>
221
+ )}
222
+ <form action={app.actions.dismissFeedback}>
223
+ <input type="hidden" name="feedback" value={f.id} />
224
+ <Submit variant="quiet">Dismiss</Submit>
225
+ </form>
226
+ </div>
227
+ </Card>
228
+ </article>
229
+ );
230
+ }
@@ -1,5 +1,11 @@
1
- import { asText, fieldValue, type FormField } from "@crowandraven/evalkeeper";
2
- import { InfoTip } from "./Tip";
1
+ import { InfoTip, Select, TextArea, TextInput } from "./pieces.js";
2
+ import {
3
+ ANSWER_JSON_FIELD,
4
+ asText,
5
+ fieldValue,
6
+ type AnswerEditorProps,
7
+ type FormField,
8
+ } from "../index.js";
3
9
 
4
10
  /**
5
11
  * A suite's form fields, rendered from its field specs: label, input, and
@@ -28,7 +34,7 @@ export function Fields({
28
34
  {f.label}
29
35
  </label>
30
36
  {f.kind === "select" ? (
31
- <select
37
+ <Select
32
38
  id={id}
33
39
  name={f.name}
34
40
  defaultValue={value || f.options?.[0]}
@@ -39,9 +45,9 @@ export function Fields({
39
45
  {o.replace(/_/g, " ")}
40
46
  </option>
41
47
  ))}
42
- </select>
48
+ </Select>
43
49
  ) : f.kind === "text" ? (
44
- <input
50
+ <TextInput
45
51
  id={id}
46
52
  name={f.name}
47
53
  defaultValue={value}
@@ -49,13 +55,14 @@ export function Fields({
49
55
  className={box}
50
56
  />
51
57
  ) : (
52
- <textarea
58
+ <TextArea
53
59
  id={id}
54
60
  name={f.name}
55
61
  defaultValue={value}
56
62
  required={f.required}
57
- rows={f.kind === "lines" ? 4 : 5}
58
- className={box}
63
+ rows={f.kind === "lines" ? 4 : f.kind === "json" ? 8 : 5}
64
+ spellCheck={f.kind !== "json"}
65
+ className={`${box} ${f.kind === "json" ? "font-mono text-xs" : ""}`}
59
66
  />
60
67
  )}
61
68
  <p className="readable text-xs text-muted">{f.help}</p>
@@ -87,8 +94,12 @@ export function FieldValues({
87
94
  {f.label}
88
95
  <InfoTip text={f.help} id={`${prefix}${f.name}-read`} />
89
96
  </dt>
90
- <dd className="readable whitespace-pre-wrap">
91
- {Array.isArray(v) ? (
97
+ <dd className="readable break-words whitespace-pre-wrap">
98
+ {f.kind === "json" && v !== undefined && v !== null ? (
99
+ <pre className="text-xs whitespace-pre-wrap">
100
+ {JSON.stringify(v, null, 2)}
101
+ </pre>
102
+ ) : Array.isArray(v) ? (
92
103
  v.length ? (
93
104
  <ul className="list-disc pl-5">
94
105
  {v.map((x, i) => (
@@ -108,3 +119,36 @@ export function FieldValues({
108
119
  </dl>
109
120
  );
110
121
  }
122
+
123
+ /**
124
+ * A suite's answer, for writing or editing it: the app's own answer editor
125
+ * when it registered one for this suite (`answerEditors` in the wiring
126
+ * module), otherwise the suite's answer fields.
127
+ */
128
+ export function AnswerInput({
129
+ fields,
130
+ editor: Editor,
131
+ input = null,
132
+ values,
133
+ prefix = "",
134
+ }: {
135
+ fields: FormField[];
136
+ /** The app's editor for this suite, if any. */
137
+ editor?: React.ComponentType<AnswerEditorProps> | undefined;
138
+ /** The case's input; null on "Add a case". */
139
+ input?: unknown;
140
+ values?: unknown;
141
+ prefix?: string;
142
+ }) {
143
+ if (Editor)
144
+ return (
145
+ <Editor
146
+ name={ANSWER_JSON_FIELD}
147
+ idPrefix={prefix}
148
+ input={input}
149
+ value={values ?? null}
150
+ fields={fields}
151
+ />
152
+ );
153
+ return <Fields fields={fields} values={values} prefix={prefix} />;
154
+ }