@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,229 +1,8 @@
1
- import type { Metadata } from "next";
2
- import {
3
- asText,
4
- isInjectionSuite,
5
- thumbsSummary,
6
- whyNotACase,
7
- type AnySuite,
8
- type FeedbackRecord,
9
- } from "@crowandraven/evalkeeper";
10
- import { FieldValues } from "@/components/evalkeeper/Fields";
11
- import { Submit } from "@/components/evalkeeper/Submit";
12
- import { InfoTip, Tip } from "@/components/evalkeeper/Tip";
13
- import { BackLink, Card, Chip, pct } from "@/components/evalkeeper/ui";
14
- import { ThumbsDown, ThumbsUp } from "lucide-react";
15
- import { feedbackStore, requireAdmin, SUITES } from "@/lib/evalkeeper";
16
- import { daysAgo } from "@/lib/evalkeeper/time";
17
- import { dismissFeedback, makeCase } from "@/lib/evalkeeper/actions";
18
- import { EVALS_BASE } from "@/lib/evalkeeper/paths";
1
+ import { pages } from "@/lib/evalkeeper/evals";
19
2
 
20
- export const dynamic = "force-dynamic";
21
-
22
- export const metadata: Metadata = { title: "Feedback: Evals" };
23
-
24
- /**
25
- * What people thought of the AI's answers: thumbs per feature this week,
26
- * and each rating waiting for a look, to make into a case or dismiss.
27
- */
28
- export default async function FeedbackPage() {
29
- await requireAdmin();
30
- const all = await feedbackStore.listFeedback();
31
- const summary = thumbsSummary(all, daysAgo(7));
32
- const open = all
33
- .filter((f) => f.status === "OPEN")
34
- .sort((a, b) => Number(b.rating === "DOWN") - Number(a.rating === "DOWN"));
35
- const suiteFor = (op: string) =>
36
- SUITES.find((s) => s.operation === op && !isInjectionSuite(s));
37
- const label = (op: string) => suiteFor(op)?.label ?? op;
38
-
39
- return (
40
- <div className="space-y-8">
41
- <div className="space-y-2">
42
- <BackLink href={EVALS_BASE}>Evals</BackLink>
43
- <h1 className="text-2xl font-semibold">Feedback</h1>
44
- <p className="readable text-muted">
45
- Thumbs up and down from people using the product. A rating on a kept
46
- input can become a draft case, so the next model is tested on the
47
- answer people didn&apos;t like.
48
- </p>
49
- </div>
3
+ // Written by `npx @crowandraven/evalkeeper add pages`: don't edit it.
4
+ // Thumbs up and down, and what to do with each.
50
5
 
51
- <section className="space-y-3">
52
- <h2 className="text-lg font-semibold">
53
- This week
54
- <InfoTip term="thumbs" />
55
- </h2>
56
- {summary.length === 0 ? (
57
- <p className="text-sm text-muted">No ratings this week.</p>
58
- ) : (
59
- <Card className="overflow-x-auto p-0 lg:overflow-visible">
60
- <table className="w-full text-sm">
61
- <thead className="text-left text-muted">
62
- <tr className="border-b border-line">
63
- <th className="p-3 font-normal">Feature</th>
64
- <th className="p-3 font-normal">Thumbs up</th>
65
- <th className="p-3 font-normal">Thumbs down</th>
66
- <th className="p-3 font-normal">Share down</th>
67
- <th className="p-3 font-normal">Waiting</th>
68
- </tr>
69
- </thead>
70
- <tbody>
71
- {summary.map((s) => (
72
- <tr
73
- key={s.operation}
74
- className="border-b border-line last:border-0"
75
- >
76
- <td className="p-3">
77
- <span className="mr-2 font-medium">
78
- {label(s.operation)}
79
- </span>
80
- {s.alert && (
81
- <Tip
82
- text="At least 5 ratings, and at least 20% of them thumbs down: worth a look."
83
- id={`alert-${s.operation}`}
84
- side="bottom"
85
- >
86
- <Chip tone="warn">Needs a look</Chip>
87
- </Tip>
88
- )}
89
- </td>
90
- <td className="p-3 tabular-nums">{s.up}</td>
91
- <td className="p-3 tabular-nums">{s.down}</td>
92
- <td className="p-3 tabular-nums">
93
- {s.downShare === null ? "—" : pct(s.downShare)}
94
- </td>
95
- <td className="p-3 tabular-nums">{s.open}</td>
96
- </tr>
97
- ))}
98
- </tbody>
99
- </table>
100
- </Card>
101
- )}
102
- </section>
103
-
104
- <section className="space-y-3">
105
- <h2 className="text-lg font-semibold">
106
- Waiting for a look ({open.length})
107
- </h2>
108
- {open.length === 0 && (
109
- <p className="text-sm text-muted">
110
- Nothing waiting. Ratings show up here once an AI feature has a
111
- thumbs up and down (step 8 of{" "}
112
- <a
113
- href="https://github.com/seanhudson/evalkeeper/blob/main/docs/adding-to-your-app.md#8-add-thumbs-to-your-ai-answers-optional"
114
- target="_blank"
115
- rel="noreferrer"
116
- className="underline"
117
- >
118
- the guide
119
- </a>
120
- ).
121
- </p>
122
- )}
123
- <div className="space-y-3">
124
- {open.map((f) => (
125
- <Rating
126
- key={f.id}
127
- fields={suiteFor(f.operation)?.fields}
128
- f={f}
129
- feature={label(f.operation)}
130
- why={whyNotACase(f, suiteFor(f.operation))}
131
- />
132
- ))}
133
- </div>
134
- </section>
135
- </div>
136
- );
137
- }
138
-
139
- function Rating({
140
- f,
141
- fields,
142
- feature,
143
- why,
144
- }: {
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">
171
- {f.updatedAt.toLocaleString()}
172
- </span>
173
- </div>
174
- {f.reason && <p className="readable">&ldquo;{f.reason}&rdquo;</p>}
175
- <div className="grid gap-4 md:grid-cols-2">
176
- <div className="space-y-1">
177
- <p className="text-xs font-semibold uppercase tracking-wide text-muted">
178
- Input
179
- </p>
180
- {f.input === null ? (
181
- <p className="text-muted">Not kept</p>
182
- ) : fields ? (
183
- <FieldValues
184
- fields={fields.input}
185
- values={f.input}
186
- prefix={`${f.id}-in-`}
187
- />
188
- ) : (
189
- <p className="whitespace-pre-wrap font-mono text-xs">
190
- {asText(f.input)}
191
- </p>
192
- )}
193
- </div>
194
- <div className="space-y-1">
195
- <p className="text-xs font-semibold uppercase tracking-wide text-muted">
196
- Answer
197
- </p>
198
- {fields && f.output !== null ? (
199
- <FieldValues
200
- fields={fields.label}
201
- values={f.output}
202
- prefix={`${f.id}-out-`}
203
- />
204
- ) : (
205
- <p className="whitespace-pre-wrap font-mono text-xs">
206
- {asText(f.output) || f.excerpt || "—"}
207
- </p>
208
- )}
209
- </div>
210
- </div>
211
- <div className="flex flex-wrap items-center gap-2">
212
- {why === null ? (
213
- <form action={makeCase} className="flex items-center gap-1">
214
- <input type="hidden" name="feedback" value={f.id} />
215
- <Submit>Make a case</Submit>
216
- <InfoTip term="makeCase" id={`make-${f.id}`} />
217
- </form>
218
- ) : (
219
- <p className="readable text-xs text-muted">{why}</p>
220
- )}
221
- <form action={dismissFeedback}>
222
- <input type="hidden" name="feedback" value={f.id} />
223
- <Submit variant="quiet">Dismiss</Submit>
224
- </form>
225
- </div>
226
- </Card>
227
- </article>
228
- );
229
- }
6
+ export const dynamic = "force-dynamic";
7
+ export const generateMetadata = pages.feedback.generateMetadata;
8
+ export default pages.feedback.Page;
@@ -0,0 +1,10 @@
1
+ import { AppComponents } from "@/lib/evalkeeper/appComponents";
2
+
3
+ /** Every eval page, drawn with the app's own components. */
4
+ export default function EvalsLayout({
5
+ children,
6
+ }: {
7
+ children: React.ReactNode;
8
+ }) {
9
+ return <AppComponents>{children}</AppComponents>;
10
+ }
@@ -1,399 +1,9 @@
1
- import type { Metadata } from "next";
2
- import Link from "next/link";
3
- import {
4
- attackMistakes,
5
- attacksFrom,
6
- attention,
7
- isInjectionSuite,
8
- perAnswer,
9
- seconds,
10
- suiteHealth,
11
- thumbsSummary,
12
- type GlossaryTerm,
13
- type HistoryEntry,
14
- type Settings,
15
- type SettingsVersion,
16
- } from "@crowandraven/evalkeeper";
17
- import { Card, StatusBadge, pct } from "@/components/evalkeeper/ui";
18
- import {
19
- feedbackStore,
20
- MODELS,
21
- requireAdmin,
22
- runner,
23
- settings,
24
- SUITES,
25
- } from "@/lib/evalkeeper";
26
- import { daysAgo } from "@/lib/evalkeeper/time";
27
- import { loadWeekly } from "@/lib/evalkeeper/weekly";
28
- import { WeeklyCheck } from "@/components/evalkeeper/WeeklyCheck";
29
- import { InfoTip } from "@/components/evalkeeper/Tip";
30
- import { evalsPath } from "@/lib/evalkeeper/paths";
31
- import { HistoryEntries } from "@/components/evalkeeper/SettingsHistory";
32
- import { ChevronDown } from "lucide-react";
1
+ import { pages } from "@/lib/evalkeeper/evals";
33
2
 
34
- export const dynamic = "force-dynamic";
35
-
36
- export const metadata: Metadata = { title: "Evals" };
37
-
38
- /** The evals hub: where each suite stands, and what needs attention. */
39
- export default async function EvalsHub() {
40
- await requireAdmin();
41
- const [boards, weekly] = await Promise.all([
42
- Promise.all(SUITES.map((s) => runner.board(s.key))),
43
- loadWeekly(),
44
- ]);
45
- const histories = await Promise.all(
46
- SUITES.map((s) =>
47
- Promise.all([
48
- settings.history(s.operation),
49
- settings.current(s.operation),
50
- ]),
51
- ),
52
- );
53
- const thumbs = thumbsSummary(await feedbackStore.listFeedback(), daysAgo(7));
54
- const down = thumbs.reduce((t, s) => t + s.down, 0);
55
- const waiting = thumbs.reduce((t, s) => t + s.open, 0);
56
- const flagged = thumbs.filter((s) => s.alert).length;
57
- // An injection suite shows on its base suite's card, not its own.
58
- const attacksOn = (key: string) =>
59
- boards.filter((x) => isInjectionSuite(x.suite) && x.suite.base.key === key);
60
- const cards = boards
61
- .map((b, i) => ({ b, i }))
62
- .filter(({ b }) => !isInjectionSuite(b.suite));
63
- const needs = attention(
64
- cards.map(({ b }) => ({
65
- key: b.suite.key,
66
- label: b.suite.label,
67
- rows: b.rows,
68
- toReview: b.provisional,
69
- })),
70
- );
71
- return (
72
- <div className="space-y-8">
73
- <div className="readable space-y-2">
74
- <h1 className="text-2xl font-semibold">Evals</h1>
75
- <p className="text-muted">
76
- Each suite tests one AI feature against answers people confirmed. Test
77
- models on it, then pick the live one on evidence.
78
- </p>
79
- </div>
80
-
81
- <div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-4">
82
- <Stat
83
- title="Most room to improve"
84
- term="improve"
85
- value={needs.improve ? pct(needs.improve.best) : "—"}
86
- detail={
87
- !needs.improve
88
- ? "Test a suite to see"
89
- : needs.improve.best >= 1
90
- ? "Every suite has a model scoring 100%"
91
- : `${needs.improve.label}, best on ${needs.improve.model}`
92
- }
93
- />
94
- <Stat
95
- title="Slowest live model"
96
- term="slowest"
97
- value={needs.slowest ? seconds(needs.slowest.ms) : "—"}
98
- detail={
99
- needs.slowest
100
- ? `${needs.slowest.label} on ${needs.slowest.model}`
101
- : "—"
102
- }
103
- />
104
- <Stat
105
- title="Costliest live model"
106
- term="costliest"
107
- value={needs.costliest ? perAnswer(needs.costliest.usd) : "—"}
108
- detail={
109
- needs.costliest
110
- ? `${needs.costliest.label} on ${needs.costliest.model}`
111
- : "—"
112
- }
113
- />
114
- <Link href={evalsPath("feedback")}>
115
- <Stat
116
- title="Thumbs down this week"
117
- term="thumbs"
118
- value={String(down)}
119
- detail={
120
- flagged
121
- ? `${flagged} feature${flagged === 1 ? "" : "s"} need a look · ${waiting} waiting`
122
- : `${waiting} waiting for a look`
123
- }
124
- />
125
- </Link>
126
- </div>
127
-
128
- <WeeklyCheck weekly={weekly} />
129
-
130
- <section aria-labelledby="suites" className="space-y-3">
131
- <h2 id="suites" className="text-lg font-semibold">
132
- Suites
133
- <InfoTip term="suites" />
134
- </h2>
135
- {cards.length === 0 && <NoSuites />}
136
- <div className="space-y-4">
137
- {cards.map(({ b, i }) => {
138
- const attacked = attacksOn(b.suite.key);
139
- const h = suiteHealth(
140
- b.rows,
141
- b.suite.checks,
142
- b.suite.priority,
143
- b.cases,
144
- b.provisional,
145
- MODELS,
146
- { attacks: attacksFrom(attacked) },
147
- );
148
- const [history, current] = histories[i] ?? [[], null];
149
- return (
150
- <SuiteCard
151
- key={b.suite.key}
152
- board={b}
153
- attacked={attacked}
154
- health={h}
155
- history={history}
156
- current={current}
157
- />
158
- );
159
- })}
160
- </div>
161
- </section>
162
- </div>
163
- );
164
- }
165
-
166
- /** Before the first suite: what a suite is, and how to add one. */
167
- function NoSuites() {
168
- return (
169
- <Card className="readable space-y-3 text-sm">
170
- <p className="font-semibold">No suites yet</p>
171
- <p className="text-muted">
172
- A suite tests one AI feature: its cases, the answers a person confirms,
173
- and the checks that grade any model against them. To add one:
174
- </p>
175
- <ol className="list-decimal space-y-2 pl-4">
176
- <li>
177
- Write it: the input and answer shapes with zod, two or three checks,{" "}
178
- <code>run</code>, and <code>grade</code>.
179
- </li>
180
- <li>
181
- Add it to <code>SUITES</code> in <code>lib/evalkeeper/index.ts</code>,
182
- with its instructions hash.
183
- </li>
184
- <li>
185
- Add cases (here, or with <code>importCases</code> from files you
186
- have), confirm their answers, and test models.
187
- </li>
188
- </ol>
189
- <p className="text-muted">
190
- Step by step:{" "}
191
- <a
192
- href="https://github.com/seanhudson/evalkeeper/blob/main/docs/adding-to-your-app.md#5-write-your-first-suite"
193
- target="_blank"
194
- rel="noreferrer"
195
- className="underline"
196
- >
197
- Write your first suite
198
- </a>
199
- .
200
- </p>
201
- </Card>
202
- );
203
- }
204
-
205
- function Stat({
206
- title,
207
- term,
208
- value,
209
- detail,
210
- }: {
211
- title: string;
212
- term: GlossaryTerm;
213
- value: string;
214
- detail: string;
215
- }) {
216
- return (
217
- <Card className="space-y-1">
218
- <p className="text-sm text-muted">
219
- {title}
220
- <InfoTip term={term} />
221
- </p>
222
- <p className="text-2xl font-semibold tabular-nums">{value}</p>
223
- <p className="text-sm text-muted">{detail}</p>
224
- </Card>
225
- );
226
- }
3
+ // Written by `npx @crowandraven/evalkeeper add pages`. To arrange
4
+ // the hub your own way, replace this file with the sections ("Arrange
5
+ // your own page" in the guide).
227
6
 
228
- type Board = Awaited<ReturnType<typeof runner.board>>;
229
-
230
- const label = (model: string) => MODELS[model]?.label ?? model;
231
- const day = (d: Date) => d.toLocaleDateString();
232
- /** Green at 95% and up, amber from 80%, red below. */
233
- const scoreTone = (rate: number) =>
234
- rate >= 0.95 ? "text-good" : rate >= 0.8 ? "text-warn" : "text-bad";
235
-
236
- /**
237
- * One feature on the hub: its live version and models, what the live
238
- * model costs and how fast it is, its latest test, how it does under
239
- * attack, what needs a look, and its settings history.
240
- */
241
- function SuiteCard({
242
- board: b,
243
- attacked,
244
- health: h,
245
- history,
246
- current,
247
- }: {
248
- board: Board;
249
- /** The injection suites that attack this feature. */
250
- attacked: Board[];
251
- health: ReturnType<typeof suiteHealth>;
252
- history: HistoryEntry[];
253
- current: { settings: Settings; version: SettingsVersion | null } | null;
254
- }) {
255
- const live = b.rows.find((r) => r.live && !r.variant);
256
- const t = live?.test;
257
- const version = current?.version ?? null;
258
- const since = version
259
- ? (history.find((e) => e.to.id === version.id)?.createdAt ??
260
- version.createdAt)
261
- : null;
262
- const s = current?.settings;
263
- const price = s ? MODELS[s.model] : undefined;
264
- const versions = Math.max(1, ...history.map((e) => e.to.number));
265
- return (
266
- <Card className="relative space-y-4 transition-colors hover:border-muted">
267
- <div className="flex flex-wrap items-start justify-between gap-4">
268
- <div className="min-w-0 space-y-2">
269
- <div className="flex flex-wrap items-center gap-2">
270
- <h2 className="font-semibold">
271
- {/* Covers the whole card; the versions toggle sits above it. */}
272
- <Link
273
- href={evalsPath(b.suite.key)}
274
- className="after:absolute after:inset-0 after:rounded-lg"
275
- >
276
- {b.suite.label}
277
- </Link>
278
- </h2>
279
- <StatusBadge status={h.status} />
280
- </div>
281
- <p className="readable text-sm text-muted">{b.suite.description}</p>
282
- </div>
283
- {t && (
284
- <div className="shrink-0 space-y-0.5 text-right text-sm">
285
- <p className="font-semibold tabular-nums">
286
- {perAnswer(t.costPerAnswer)} / answer
287
- </p>
288
- <p className="text-xs text-muted">{seconds(t.avgMs)} avg</p>
289
- {price?.inputPer1M !== undefined &&
290
- price.outputPer1M !== undefined && (
291
- <p className="text-xs text-muted">
292
- ${price.inputPer1M} / ${price.outputPer1M} per 1M
293
- </p>
294
- )}
295
- </div>
296
- )}
297
- </div>
298
-
299
- {s && (
300
- <p className="text-sm text-muted">
301
- <span className="font-semibold text-ink">{label(s.model)}</span>
302
- {s.fallbackModel ? (
303
- <>
304
- {" "}
305
- · fallback{" "}
306
- <span className="font-semibold text-ink">
307
- {label(s.fallbackModel)}
308
- </span>
309
- </>
310
- ) : (
311
- " · no fallback"
312
- )}
313
- {s.reasoningEffort ? ` · reasoning ${s.reasoningEffort}` : ""}
314
- </p>
315
- )}
316
-
317
- <p className="text-sm">
318
- {t ? (
319
- <>
320
- Score{" "}
321
- <span className={`font-semibold ${scoreTone(t.right / t.total)}`}>
322
- {pct(t.right / t.total)}
323
- </span>
324
- </>
325
- ) : (
326
- "Live model not tested yet"
327
- )}{" "}
328
- · {b.cases} cases · {h.testedModels} models tested ·{" "}
329
- <Link
330
- href={evalsPath(b.suite.key)}
331
- className="relative text-accent hover:underline"
332
- >
333
- Compare models
334
- </Link>
335
- </p>
336
-
337
- {h.details.length > 0 && (
338
- <ul className="readable list-disc space-y-1 pl-5 text-sm text-muted">
339
- {h.details.slice(0, 3).map((d) => (
340
- <li key={d}>{d}</li>
341
- ))}
342
- </ul>
343
- )}
344
-
345
- {attacked.map((a) => {
346
- const n = live ? attackMistakes(live.key, attacksFrom([a])) : null;
347
- return (
348
- <p key={a.suite.key} className="relative text-sm">
349
- Under attack
350
- <InfoTip term="underAttack" />:{" "}
351
- {n === null ? (
352
- <span className="text-muted">live model not tested</span>
353
- ) : (
354
- <span className={n ? "font-semibold text-bad" : "text-good"}>
355
- {n} serious {n === 1 ? "mistake" : "mistakes"}
356
- </span>
357
- )}{" "}
358
- · {a.cases} attack cases ·{" "}
359
- <Link
360
- href={evalsPath(a.suite.key)}
361
- className="text-accent hover:underline"
362
- >
363
- {a.suite.label}
364
- </Link>
365
- </p>
366
- );
367
- })}
368
-
369
- {s && (
370
- <details className="group/history relative rounded-md bg-tint">
371
- <summary className="flex list-none items-center justify-between gap-2 p-3 text-sm font-medium">
372
- Versions
373
- <span className="flex items-center gap-1 text-xs font-normal text-muted">
374
- <span className="font-medium text-ink">
375
- v{version?.number ?? 1}
376
- </span>{" "}
377
- {since ? `live since ${day(since)}` : "defaults from code"} ·{" "}
378
- {versions} version{versions === 1 ? "" : "s"}
379
- <ChevronDown
380
- aria-hidden
381
- className="h-4 w-4 transition-transform group-open/history:rotate-180"
382
- />
383
- </span>
384
- </summary>
385
- <div className="px-3 pb-3">
386
- <HistoryEntries
387
- suite={b.suite.key}
388
- entries={history}
389
- liveId={version?.id ?? null}
390
- label={label}
391
- defaults={s}
392
- plain
393
- />
394
- </div>
395
- </details>
396
- )}
397
- </Card>
398
- );
399
- }
7
+ export const dynamic = "force-dynamic";
8
+ export const generateMetadata = pages.hub.generateMetadata;
9
+ export default pages.hub.Page;