@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
package/src/store.ts CHANGED
@@ -3,7 +3,7 @@ import type { SuiteMetrics } from "./stats.js";
3
3
 
4
4
  /**
5
5
  * Where Evalkeeper keeps cases, answers, tests, and outputs. The runner
6
- * talks only to this interface: `@crowandraven/evalkeeper-prisma` implements it on your
6
+ * talks only to this interface: `@crowandraven/evalkeeper/prisma` implements it on your
7
7
  * database, and `memoryStore()` keeps everything in memory for tests and
8
8
  * demos. Every method is a plain read or write; the rules live in the
9
9
  * runner.
package/src/suggest.ts CHANGED
@@ -116,7 +116,7 @@ export function attacksFrom(
116
116
  }
117
117
 
118
118
  /**
119
- * A model's serious mistakes under attack: its serious mistakes on every
119
+ * A model's serious mistakes on the attacks: its serious mistakes on every
120
120
  * injection suite, added up. Null when any of them has no current,
121
121
  * complete test of it, so it can't be compared yet; also null with no
122
122
  * injection suites.
@@ -261,12 +261,12 @@ export function suggest<R extends SuggestRow>(
261
261
  `No model has an up-to-date test against the attacks: test ${next.label} on them before relying on it.`,
262
262
  );
263
263
  } else {
264
- // At least two fewer serious mistakes under attack, as accurate or more.
264
+ // At least two fewer serious mistakes on the attacks, as accurate or more.
265
265
  const attackReason = (r: R): string | null => {
266
266
  const ra = underAttack(r);
267
267
  const la = underAttack(live);
268
268
  return ra !== null && la !== null && ra <= la - 2 && rate(r) >= rate(live)
269
- ? `${r.label} makes fewer serious mistakes under attack than ${live.label} (${ra} against ${la}), and scores at least as well (${pct(rate(r))} against ${pct(rate(live))}).`
269
+ ? `${r.label} makes fewer serious mistakes on the attacks than ${live.label} (${ra} against ${la}), and scores at least as well (${pct(rate(r))} against ${pct(rate(live))}).`
270
270
  : null;
271
271
  };
272
272
  const why = (r: R): string | null => {
@@ -336,8 +336,8 @@ export function suggest<R extends SuggestRow>(
336
336
  if (a !== null && reason !== attackReason(next))
337
337
  reasons.push(
338
338
  liveAttack === null
339
- ? `Under attack, ${next.label} makes ${mistakes(a)}. ${live.label} has no up-to-date test against the attacks to compare with.`
340
- : `Under attack, ${next.label} makes ${mistakes(a)}, against ${liveAttack} for ${live.label}.`,
339
+ ? `On the attacks, ${next.label} makes ${mistakes(a)}. ${live.label} has no up-to-date test against the attacks to compare with.`
340
+ : `On the attacks, ${next.label} makes ${mistakes(a)}, against ${liveAttack} for ${live.label}.`,
341
341
  );
342
342
  } else {
343
343
  next = live;
@@ -351,7 +351,7 @@ export function suggest<R extends SuggestRow>(
351
351
  reasons.push(
352
352
  a === null
353
353
  ? `${held.label} would otherwise qualify, but it has no up-to-date test against the attacks. Test it on ${at(attacks, 0).label}.`
354
- : `${held.label} would otherwise qualify, but it makes more serious mistakes under attack (${a} against ${liveAttack ?? 0}).`,
354
+ : `${held.label} would otherwise qualify, but it makes more serious mistakes on the attacks (${a} against ${liveAttack ?? 0}).`,
355
355
  );
356
356
  }
357
357
  // The one to watch: scored higher, but not by enough to tell.
@@ -389,7 +389,7 @@ export function suggest<R extends SuggestRow>(
389
389
  ? ""
390
390
  : a === null
391
391
  ? "; not tested against the attacks"
392
- : `; ${mistakes(a)} under attack`;
392
+ : `; ${mistakes(a)} on the attacks`;
393
393
  reasons.push(
394
394
  `Fallback: ${fallback.label} is the most accurate from another provider (${pct(rate(fallback))}, ${mistakes(serious(fallback))}${attacked}).`,
395
395
  );
@@ -5,19 +5,33 @@ import type { AnySuite, FormField } from "./types.js";
5
5
  /** A field help shorter than this says nothing a label doesn't. */
6
6
  const MIN_HELP = 10;
7
7
 
8
- /** A zod schema's definition, read by name so any copy of zod works. */
8
+ /** A zod schema's definition, read by name so any copy of zod 4 works. */
9
9
  type Def = {
10
- typeName?: string;
11
- shape?: () => Record<string, unknown>;
12
- schema?: z.ZodTypeAny;
13
- innerType?: z.ZodTypeAny;
10
+ type?: string;
11
+ shape?: Record<string, unknown>;
12
+ /** What a wrapper (optional, nullable, default, …) wraps. */
13
+ innerType?: z.ZodType;
14
+ /** A pipe's two ends: a transform's schema is `in`, a preprocess's `out`. */
15
+ in?: z.ZodType;
16
+ out?: z.ZodType;
14
17
  /** A union's options (a plain union's, or a discriminated one's). */
15
- options?: readonly z.ZodTypeAny[];
18
+ options?: readonly z.ZodType[];
16
19
  };
17
20
 
21
+ /** Wrappers whose keys are their inner schema's. */
22
+ const WRAPPERS = new Set([
23
+ "optional",
24
+ "nullable",
25
+ "default",
26
+ "prefault",
27
+ "catch",
28
+ "readonly",
29
+ "nonoptional",
30
+ ]);
31
+
18
32
  /**
19
- * The top-level keys of an object schema, through refinements, optional,
20
- * nullable, and default wrappers. For a union (`z.union` or
33
+ * The top-level keys of an object schema, through refinements,
34
+ * transforms, and optional, nullable, and default wrappers. For a union (`z.union` or
21
35
  * `z.discriminatedUnion`), every key that appears in any of its object
22
36
  * options, in the order they first appear, so one `fields` list covers
23
37
  * them all. Null for any other shape (a string, a list, a union with no
@@ -25,41 +39,34 @@ type Def = {
25
39
  *
26
40
  * @param schema - A suite's input or answer schema.
27
41
  */
28
- export function schemaKeys(schema: z.ZodTypeAny): string[] | null {
42
+ export function schemaKeys(schema: z.ZodType): string[] | null {
29
43
  return keysOf(schema, 0);
30
44
  }
31
45
 
32
46
  /** Wrappers and unions deeper than this are read as an unknown shape. */
33
47
  const MAX_DEPTH = 10;
34
48
 
35
- function keysOf(schema: z.ZodTypeAny, depth: number): string[] | null {
36
- let s: z.ZodTypeAny | undefined = schema;
49
+ function keysOf(schema: z.ZodType, depth: number): string[] | null {
50
+ let s: z.ZodType | undefined = schema;
37
51
  for (let i = depth; s && i < MAX_DEPTH; i++) {
38
52
  // Trust boundary: zod's own definition object, read by its names.
39
- const def = s._def as Def;
40
- if (def.typeName === "ZodObject" && def.shape)
41
- return Object.keys(def.shape());
42
- if (
43
- (def.typeName === "ZodUnion" ||
44
- def.typeName === "ZodDiscriminatedUnion") &&
45
- def.options
46
- )
53
+ const def = s._zod.def as Def;
54
+ if (def.type === "object" && def.shape) return Object.keys(def.shape);
55
+ if (def.type === "union" && def.options)
47
56
  return unionKeys(def.options, i + 1);
48
- s =
49
- def.typeName === "ZodEffects"
50
- ? def.schema
51
- : def.typeName === "ZodOptional" ||
52
- def.typeName === "ZodNullable" ||
53
- def.typeName === "ZodDefault"
54
- ? def.innerType
55
- : undefined;
57
+ if (def.type === "pipe")
58
+ return (
59
+ keysOf(def.in as z.ZodType, i + 1) ??
60
+ keysOf(def.out as z.ZodType, i + 1)
61
+ );
62
+ s = def.type && WRAPPERS.has(def.type) ? def.innerType : undefined;
56
63
  }
57
64
  return null;
58
65
  }
59
66
 
60
67
  /** Every key of a union's object options; null when none is an object. */
61
68
  function unionKeys(
62
- options: readonly z.ZodTypeAny[],
69
+ options: readonly z.ZodType[],
63
70
  depth: number,
64
71
  ): string[] | null {
65
72
  const keys = new Set<string>();
package/src/testing.ts CHANGED
@@ -99,7 +99,7 @@ export type ScopedContractOptions = ContractOptions & {
99
99
  * after the contract's tests (and so also any left by an earlier run
100
100
  * that stopped early). Needs `scope`, and `afterAll` among the test
101
101
  * functions. For Prisma, `deleteScopedRows` from
102
- * `@crowandraven/evalkeeper-prisma`.
102
+ * `@crowandraven/evalkeeper/prisma`.
103
103
  */
104
104
  cleanup?: (scope: string) => Promise<unknown>;
105
105
  };
@@ -1035,7 +1035,7 @@ export function describeSuiteContract(
1035
1035
  * @example
1036
1036
  * ```ts
1037
1037
  * import { describeMappedReadCheck } from "@crowandraven/evalkeeper/testing";
1038
- * import { prismaReadCheck } from "@crowandraven/evalkeeper-prisma";
1038
+ * import { prismaReadCheck } from "@crowandraven/evalkeeper/prisma";
1039
1039
  *
1040
1040
  * describeMappedReadCheck(
1041
1041
  * "our answer key",
package/src/types.ts CHANGED
@@ -371,9 +371,9 @@ export function injectionSuitesOf(
371
371
  }
372
372
 
373
373
  /** Where a zod issue sits, in plain words: "facts, item 2, name". */
374
- function issuePath(path: readonly (string | number)[]): string {
374
+ function issuePath(path: readonly PropertyKey[]): string {
375
375
  return path
376
- .map((p) => (typeof p === "number" ? `item ${p + 1}` : p))
376
+ .map((p) => (typeof p === "number" ? `item ${p + 1}` : String(p)))
377
377
  .join(", ");
378
378
  }
379
379
 
package/starter/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- // Your app's Evalkeeper wiring: the one file the copied eval pages import.
1
+ // Your app's Evalkeeper wiring: the one file the eval pages read from.
2
2
  // Written by `npx @crowandraven/evalkeeper add pages`; it's yours now. Fill in each TODO.
3
3
  import "server-only";
4
4
  import {
@@ -10,13 +10,14 @@ import {
10
10
  } from "@crowandraven/evalkeeper";
11
11
  import type { ComponentType } from "react";
12
12
  import { createRunner, type Route } from "@crowandraven/evalkeeper/runner";
13
+ import type { EvalWiring } from "@crowandraven/evalkeeper/next";
13
14
  import {
14
15
  prismaFeedbackStore,
15
16
  prismaSettingsStore,
16
17
  prismaStore,
17
- } from "@crowandraven/evalkeeper-prisma";
18
+ } from "@crowandraven/evalkeeper/prisma";
18
19
  // TODO: your app's Prisma client, with Evalkeeper's models added to the
19
- // schema (node_modules/@crowandraven/evalkeeper-prisma/schema/evalkeeper.prisma).
20
+ // schema (node_modules/@crowandraven/evalkeeper/schema/evalkeeper.prisma).
20
21
  import { prisma } from "@/lib/prisma";
21
22
 
22
23
  /** TODO: the models your app can use, with prices and retirement dates. */
@@ -37,9 +38,6 @@ export function modelsFor(_operation: string): string[] {
37
38
 
38
39
  /** TODO: one suite per AI feature (see the README's "Write a suite"). */
39
40
  export const SUITES: AnySuite[] = [];
40
- export const SUITE_BY_KEY: Record<string, AnySuite> = Object.fromEntries(
41
- SUITES.map((s) => [s.key, s]),
42
- );
43
41
 
44
42
  /**
45
43
  * Your own editors for answers plain fields can't edit well, keyed by
@@ -52,13 +50,13 @@ export const answerEditors: Partial<
52
50
 
53
51
  /**
54
52
  * TODO: each feature's instructions hash (instructionsHash from
55
- * @crowandraven/evalkeeper-ai-sdk), so editing a prompt marks older tests out of date.
53
+ * @crowandraven/evalkeeper/ai-sdk), so editing a prompt marks older tests out of date.
56
54
  */
57
55
  const PROMPT_VERSIONS: Record<string, string> = {};
58
56
 
59
57
  /**
60
58
  * TODO: each feature's instructions as text (instructionParts from
61
- * @crowandraven/evalkeeper-ai-sdk, on the parts you hash), so the suite
59
+ * @crowandraven/evalkeeper/ai-sdk, on the parts you hash), so the suite
62
60
  * page warns when a case was copied into them.
63
61
  */
64
62
  const INSTRUCTION_TEXTS: Record<string, string[]> = {};
@@ -103,3 +101,19 @@ export async function requireAdmin(): Promise<{ id: string; name: string }> {
103
101
  "Evalkeeper: write requireAdmin in lib/evalkeeper/index.ts so only admins can use the eval pages.",
104
102
  );
105
103
  }
104
+
105
+ /**
106
+ * Everything Evalkeeper's pages, actions, and weekly check need from your
107
+ * app, in one object. Where the pages live is in `./paths`.
108
+ */
109
+ export const wiring = {
110
+ runner,
111
+ settings,
112
+ store,
113
+ feedbackStore,
114
+ models: MODELS,
115
+ suites: SUITES,
116
+ routeFor,
117
+ answerEditors,
118
+ requireAdmin,
119
+ } satisfies Omit<EvalWiring, "basePath">;
@@ -1,6 +1,7 @@
1
- import { after, type NextRequest, NextResponse } from "next/server";
2
- import { isAuthorizedCron } from "@/lib/evalkeeper/cronAuth";
3
- import { runWeeklyCheck, startWeeklyCheck } from "@/lib/evalkeeper/weekly";
1
+ import { weeklyCronRoute } from "@crowandraven/evalkeeper/next";
2
+ import { wiring } from "@/lib/evalkeeper";
3
+
4
+ // Written by `npx @crowandraven/evalkeeper add pages`: don't edit it.
4
5
 
5
6
  /** The checks run after the response, within this function's time limit. */
6
7
  export const maxDuration = 300;
@@ -10,15 +11,4 @@ export const maxDuration = 300;
10
11
  * runs each suite's quick set on its live model. Results show on the
11
12
  * evals hub. Call it with "Authorization: Bearer $CRON_SECRET".
12
13
  */
13
- export async function GET(request: NextRequest) {
14
- if (
15
- !isAuthorizedCron(
16
- request.headers.get("authorization"),
17
- process.env.CRON_SECRET,
18
- )
19
- )
20
- return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
21
- const ids = await startWeeklyCheck();
22
- after(() => runWeeklyCheck(ids));
23
- return NextResponse.json({ started: ids.length }, { status: 202 });
24
- }
14
+ export const GET = weeklyCronRoute(wiring);
@@ -1,385 +1,8 @@
1
- import type { Metadata } from "next";
2
- import Link from "next/link";
3
- import { notFound } from "next/navigation";
4
- import {
5
- checkBar,
6
- perAnswer,
7
- seconds,
8
- verdictSentence,
9
- type Rate,
10
- type RunRecord,
11
- } from "@crowandraven/evalkeeper";
12
- import { DisagreementChip } from "@/components/evalkeeper/DisagreementChip";
13
- import { Submit } from "@/components/evalkeeper/Submit";
14
- import { InfoTip, Tip } from "@/components/evalkeeper/Tip";
15
- import { BackLink, Card, Chip, pct } from "@/components/evalkeeper/ui";
16
- import {
17
- MODELS,
18
- SUITE_BY_KEY,
19
- requireAdmin,
20
- routeFor,
21
- runner,
22
- store,
23
- } from "@/lib/evalkeeper";
24
- import { evalsPath } from "@/lib/evalkeeper/paths";
1
+ import { pages } from "@/lib/evalkeeper/evals";
25
2
 
26
- export const dynamic = "force-dynamic";
27
-
28
- export async function generateMetadata({
29
- params,
30
- }: {
31
- params: Promise<{ suite: string }>;
32
- }): Promise<Metadata> {
33
- const { suite } = await params;
34
- return { title: `Compare: ${SUITE_BY_KEY[suite]?.label ?? "Evals"}` };
35
- }
36
-
37
- /** A search parameter as one string, or null when it's missing or repeated. */
38
- const one = (v: string | string[] | undefined) =>
39
- typeof v === "string" && v ? v : null;
40
-
41
- /** A test's name: its model, reasoning setting, set, and when it ran. */
42
- function testName(r: RunRecord): string {
43
- const model = MODELS[r.model]?.label ?? r.model;
44
- const effort = r.reasoningEffort ? `, ${r.reasoningEffort} reasoning` : "";
45
- const set = r.set === "ALL" ? "" : `, ${r.set.toLowerCase()} set`;
46
- return `${model}${effort}${set} · ${r.startedAt.toLocaleString()}`;
47
- }
48
-
49
- /** A pass rate as "80% (8/10)", or a dash when the check never applied. */
50
- function rateText(r: Rate | undefined): string {
51
- return r && r.n > 0 ? `${pct(r.passed / r.n)} (${r.passed}/${r.n})` : "—";
52
- }
53
-
54
- /**
55
- * Two finished tests of a suite compared: the verdict in plain words, each
56
- * check's pass rate side by side, and the cases they graded differently,
57
- * each linked to its answers side by side. `a` is the test in place (the
58
- * live model's latest when left out), `b` the challenger.
59
- */
60
- export default async function ComparePage({
61
- params,
62
- searchParams,
63
- }: {
64
- params: Promise<{ suite: string }>;
65
- searchParams: Promise<Record<string, string | string[] | undefined>>;
66
- }) {
67
- await requireAdmin();
68
- const { suite: key } = await params;
69
- const sp = await searchParams;
70
- const suiteDef = SUITE_BY_KEY[key];
71
- if (!suiteDef) notFound();
72
- const runs = await store.listRuns(key, { status: "SUCCEEDED" });
73
- const b = one(sp.b);
74
- // Without a test in place, the live model's latest finished test.
75
- let a = one(sp.a);
76
- if (!a) {
77
- // A feature with no settings yet has no live model to start from.
78
- const live = await routeFor(suiteDef.operation).then(
79
- (r) => r.model,
80
- () => null,
81
- );
82
- a = runs.find((r) => r.model === live && r.id !== b)?.id ?? null;
83
- }
84
- const result = a && b ? await runner.compare(key, a, b) : null;
85
- const titles = new Map(
86
- (await store.listCases(key, { includeRetired: true })).map((c) => [
87
- c.id,
88
- suiteDef.title(suiteDef.input.parse(c.input)),
89
- ]),
90
- );
91
- const sideBySide = (caseId: string) =>
92
- result
93
- ? `${evalsPath(key, "side-by-side")}?${new URLSearchParams({ a: result.a.id, b: result.b.id, case: caseId })}`
94
- : "";
95
-
96
- return (
97
- <div className="space-y-8">
98
- <div className="space-y-2">
99
- <BackLink href={evalsPath(key)}>{suiteDef.label}</BackLink>
100
- <h1 className="text-2xl font-semibold">
101
- Compare two tests
102
- <InfoTip term="comparison" />
103
- </h1>
104
- <p className="readable text-muted">
105
- Pick the test in place and a challenger. Only finished tests of{" "}
106
- {suiteDef.label} can be compared.
107
- </p>
108
- </div>
3
+ // Written by `npx @crowandraven/evalkeeper add pages`: don't edit it.
4
+ // Two tests compared: the verdict, each check, and where they differ.
109
5
 
110
- <Card>
111
- {/* Keyed by the tests, so the pickers show them after a swap. */}
112
- <form
113
- key={`${a ?? ""}-${b ?? ""}`}
114
- action={evalsPath(key, "compare")}
115
- className="grid items-end gap-4 md:grid-cols-[1fr_1fr_auto]"
116
- >
117
- <TestPicker
118
- name="a"
119
- label="In place"
120
- term="inPlace"
121
- runs={runs}
122
- value={a}
123
- />
124
- <TestPicker
125
- name="b"
126
- label="Challenger"
127
- term="challenger"
128
- runs={runs}
129
- value={b}
130
- />
131
- <div className="pb-1">
132
- <Submit>Compare</Submit>
133
- </div>
134
- </form>
135
- </Card>
136
-
137
- {a && b && !result && (
138
- <p className="readable text-warn">
139
- These can&apos;t be compared: pick two different finished tests of
140
- this suite.
141
- </p>
142
- )}
143
- {runs.length < 2 && (
144
- <p className="readable text-muted">
145
- This suite needs two finished tests to compare. Test another model on
146
- the suite page first.
147
- </p>
148
- )}
149
-
150
- {result && (
151
- <>
152
- <Card className="space-y-3">
153
- <div className="flex flex-wrap items-start justify-between gap-3">
154
- <h2 className="font-semibold">
155
- Verdict
156
- <InfoTip term="verdict" />
157
- </h2>
158
- <Link
159
- href={`${evalsPath(key, "compare")}?${new URLSearchParams({ a: result.b.id, b: result.a.id })}`}
160
- className="text-sm text-muted hover:text-ink"
161
- >
162
- Swap them
163
- </Link>
164
- </div>
165
- <p className="readable text-lg">
166
- {verdictSentence(
167
- result.comparison,
168
- MODELS[result.b.model]?.label ?? result.b.model,
169
- )}
170
- </p>
171
- <p className="readable text-sm text-muted">
172
- <Link href={evalsPath(key, "runs", result.a.id)}>
173
- {testName(result.a)}
174
- </Link>{" "}
175
- (in place) against{" "}
176
- <Link href={evalsPath(key, "runs", result.b.id)}>
177
- {testName(result.b)}
178
- </Link>{" "}
179
- (challenger), on{" "}
180
- <Tip term="sharedCases">
181
- <span>{result.comparison.n} shared cases</span>
182
- </Tip>
183
- .
184
- </p>
185
- <p className="text-sm text-muted">
186
- <Tip term="cost" id="cost-compare">
187
- <span>
188
- Cost per answer: {perAnswer(result.comparison.cost.champion)}{" "}
189
- in place, {perAnswer(result.comparison.cost.challenger)}{" "}
190
- challenger
191
- </span>
192
- </Tip>
193
- {" · "}
194
- <Tip term="time" id="time-compare" align="end">
195
- <span>
196
- Time: {seconds(result.comparison.avgMs.champion)} in place,{" "}
197
- {seconds(result.comparison.avgMs.challenger)} challenger
198
- </span>
199
- </Tip>
200
- </p>
201
- {result.caveats.length > 0 && (
202
- <div className="readable rounded-md bg-tint p-3 text-sm">
203
- <p className="font-medium">
204
- Measured differently
205
- <InfoTip term="measuredDifferently" />
206
- </p>
207
- <ul className="list-disc pl-5 text-muted">
208
- {result.caveats.map((c) => (
209
- <li key={c}>{c}</li>
210
- ))}
211
- </ul>
212
- </div>
213
- )}
214
- </Card>
215
-
216
- <section className="space-y-3">
217
- <h2 className="text-lg font-semibold">
218
- Checks
219
- <InfoTip term="checks" />
220
- </h2>
221
- <Card className="overflow-x-auto p-0">
222
- <table className="w-full text-sm">
223
- <thead className="text-left text-muted">
224
- <tr className="border-b border-line">
225
- <th className="p-3 font-normal">Check</th>
226
- <th className="p-3 font-normal">
227
- <Tip term="inPlace" side="bottom" id="inPlace-col">
228
- In place
229
- </Tip>
230
- </th>
231
- <th className="p-3 font-normal">
232
- <Tip term="challenger" side="bottom" id="challenger-col">
233
- Challenger
234
- </Tip>
235
- </th>
236
- <th className="p-3 font-normal">
237
- <Tip term="bar" side="bottom" align="end">
238
- Bar
239
- </Tip>
240
- </th>
241
- </tr>
242
- </thead>
243
- <tbody>
244
- {result.suite.checks.map((c) => {
245
- const r = result.comparison.byCheck[c.key];
246
- return (
247
- <tr
248
- key={c.key}
249
- className="border-b border-line last:border-0"
250
- >
251
- <td className="p-3">
252
- <span className="flex flex-wrap items-center gap-2">
253
- {c.label}
254
- <Tip
255
- term={c.severity}
256
- id={`severity-${c.key}`}
257
- side="bottom"
258
- >
259
- <Chip
260
- tone={
261
- c.severity === "serious"
262
- ? "serious"
263
- : "neutral"
264
- }
265
- >
266
- {c.severity}
267
- </Chip>
268
- </Tip>
269
- </span>
270
- </td>
271
- <td className="p-3 tabular-nums">
272
- <Tip term="passRate" id={`a-${c.key}`} side="bottom">
273
- <span>{rateText(r?.champion)}</span>
274
- </Tip>
275
- </td>
276
- <td className="p-3 tabular-nums">
277
- <Tip term="passRate" id={`b-${c.key}`} side="bottom">
278
- <span>{rateText(r?.challenger)}</span>
279
- </Tip>
280
- </td>
281
- <td className="p-3 tabular-nums text-muted">
282
- {pct(checkBar(c))}
283
- </td>
284
- </tr>
285
- );
286
- })}
287
- </tbody>
288
- </table>
289
- </Card>
290
- </section>
291
-
292
- <section className="space-y-3">
293
- <div className="flex flex-wrap items-center justify-between gap-3">
294
- <h2 className="text-lg font-semibold">
295
- Where they differ ({result.disagreements.length})
296
- <InfoTip term="disagreements" />
297
- </h2>
298
- {result.disagreements[0] && (
299
- <Link
300
- href={sideBySide(result.disagreements[0].caseId)}
301
- className="text-sm text-accent"
302
- >
303
- Read them side by side
304
- </Link>
305
- )}
306
- </div>
307
- {result.disagreements.length === 0 ? (
308
- <p className="readable text-muted">
309
- The two tests graded every shared case alike.
310
- </p>
311
- ) : (
312
- <Card className="space-y-2">
313
- {result.disagreements.map((d) => (
314
- <div
315
- key={d.caseId}
316
- className="flex flex-wrap items-center justify-between gap-3 rounded-md bg-tint p-3 text-sm"
317
- >
318
- <Link
319
- href={sideBySide(d.caseId)}
320
- className="font-medium hover:underline"
321
- >
322
- {titles.get(d.caseId) ?? "A retired case"}
323
- </Link>
324
- <span className="flex items-center gap-3">
325
- <Tip term="caseScore" id={`score-${d.caseId}`}>
326
- <span className="text-xs text-muted tabular-nums">
327
- {pct(d.champion)} → {pct(d.challenger)}
328
- </span>
329
- </Tip>
330
- <DisagreementChip
331
- kind={d.kind}
332
- id={`kind-${d.caseId}`}
333
- align="end"
334
- />
335
- </span>
336
- </div>
337
- ))}
338
- </Card>
339
- )}
340
- </section>
341
- </>
342
- )}
343
- </div>
344
- );
345
- }
346
-
347
- /** One of the two tests to compare, chosen from the suite's finished tests. */
348
- function TestPicker({
349
- name,
350
- label,
351
- term,
352
- runs,
353
- value,
354
- }: {
355
- name: string;
356
- label: string;
357
- term: "inPlace" | "challenger";
358
- runs: RunRecord[];
359
- value: string | null;
360
- }) {
361
- return (
362
- <div className="space-y-1">
363
- <label htmlFor={`pick-${name}`} className="block text-sm font-medium">
364
- {label}
365
- <InfoTip term={term} id={`${term}-pick`} />
366
- </label>
367
- <select
368
- id={`pick-${name}`}
369
- name={name}
370
- defaultValue={value ?? ""}
371
- required
372
- className="w-full rounded-md border border-line bg-card px-3 py-2 text-sm focus:border-accent focus:outline-none"
373
- >
374
- <option value="" disabled>
375
- Pick a test
376
- </option>
377
- {runs.map((r) => (
378
- <option key={r.id} value={r.id}>
379
- {testName(r)}
380
- </option>
381
- ))}
382
- </select>
383
- </div>
384
- );
385
- }
6
+ export const dynamic = "force-dynamic";
7
+ export const generateMetadata = pages.compare.generateMetadata;
8
+ export default pages.compare.Page;