@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
@@ -0,0 +1,61 @@
1
+ "use client";
2
+
3
+ import { useState, type ReactNode } from "react";
4
+ import { Button } from "./pieces.js";
5
+
6
+ /**
7
+ * Tabs over panels drawn on the server: every panel is on the page, and
8
+ * the tabs show one at a time. For a section with a few views of the same
9
+ * thing (a feature's cases, and its attack cases).
10
+ */
11
+ export function Tabs({
12
+ label,
13
+ tabs,
14
+ }: {
15
+ /** What the tabs choose between, for screen readers. */
16
+ label: string;
17
+ tabs: { id: string; title: string; panel: ReactNode }[];
18
+ }) {
19
+ const [shown, setShown] = useState(tabs[0]?.id ?? "");
20
+ return (
21
+ <div className="space-y-4">
22
+ <div
23
+ role="tablist"
24
+ aria-label={label}
25
+ className="flex gap-1 border-b border-line"
26
+ >
27
+ {tabs.map((t) => (
28
+ <Button
29
+ key={t.id}
30
+ type="button"
31
+ role="tab"
32
+ id={`tab-${t.id}`}
33
+ aria-selected={shown === t.id}
34
+ aria-controls={`panel-${t.id}`}
35
+ onClick={() => {
36
+ setShown(t.id);
37
+ }}
38
+ className={`-mb-px border-b px-3 py-2 text-sm ${
39
+ shown === t.id
40
+ ? "border-accent font-medium text-ink"
41
+ : "border-transparent text-muted hover:text-ink"
42
+ }`}
43
+ >
44
+ {t.title}
45
+ </Button>
46
+ ))}
47
+ </div>
48
+ {tabs.map((t) => (
49
+ <div
50
+ key={t.id}
51
+ role="tabpanel"
52
+ id={`panel-${t.id}`}
53
+ aria-labelledby={`tab-${t.id}`}
54
+ hidden={shown !== t.id}
55
+ >
56
+ {t.panel}
57
+ </div>
58
+ ))}
59
+ </div>
60
+ );
61
+ }
@@ -1,8 +1,9 @@
1
1
  "use client";
2
2
 
3
+ import { Button, TextInput } from "./pieces.js";
3
4
  import { useState, useTransition } from "react";
4
5
  import { ThumbsDown, ThumbsUp } from "lucide-react";
5
- import { formText } from "@crowandraven/evalkeeper";
6
+ import { formText } from "../index.js";
6
7
 
7
8
  type Rating = "UP" | "DOWN";
8
9
 
@@ -44,7 +45,7 @@ export function Thumbs({
44
45
  ? "Good answer"
45
46
  : "Not a good answer";
46
47
  return (
47
- <button
48
+ <Button
48
49
  type="button"
49
50
  aria-label={label}
50
51
  title={label}
@@ -68,7 +69,7 @@ export function Thumbs({
68
69
  ) : (
69
70
  <ThumbsDown aria-hidden className="h-4 w-4" />
70
71
  )}
71
- </button>
72
+ </Button>
72
73
  );
73
74
  };
74
75
 
@@ -96,20 +97,20 @@ export function Thumbs({
96
97
  <label htmlFor={`why-${targetId}`} className="sr-only">
97
98
  What was wrong?
98
99
  </label>
99
- <input
100
+ <TextInput
100
101
  id={`why-${targetId}`}
101
102
  name="reason"
102
103
  maxLength={1000}
103
104
  placeholder="What was wrong? (optional)"
104
105
  className="min-w-0 flex-1 rounded-md border border-line bg-card px-3 py-1.5 text-sm focus:border-accent focus:outline-none"
105
106
  />
106
- <button
107
+ <Button
107
108
  type="submit"
108
109
  disabled={pending}
109
110
  className="rounded-md border border-line bg-card px-3 py-1.5 text-sm hover:bg-tint disabled:opacity-60"
110
111
  >
111
112
  Send
112
- </button>
113
+ </Button>
113
114
  </form>
114
115
  )}
115
116
  </div>
@@ -1,17 +1,28 @@
1
- import Link from "next/link";
2
- import { money, type WeeklySummary } from "@crowandraven/evalkeeper";
3
- import { runWeeklyNow } from "@/lib/evalkeeper/actions";
4
- import { RefreshWhile } from "./RefreshWhile";
5
- import { Submit } from "./Submit";
6
- import { InfoTip, Tip } from "./Tip";
7
- import { Card, Chip, pct } from "./ui";
8
- import { evalsPath } from "@/lib/evalkeeper/paths";
1
+ import { money, type WeeklySummary } from "../index.js";
2
+ import {
3
+ Card,
4
+ Chip,
5
+ InfoTip,
6
+ Link,
7
+ RefreshWhile,
8
+ Submit,
9
+ Tip,
10
+ } from "./pieces.js";
11
+ import { pct, dayOf, LINK } from "./format.js";
12
+ import { evalsPath, type EvalAppConfig } from "./app.js";
9
13
 
10
14
  /**
11
15
  * The weekly check on the evals hub: when it last ran, what it found, and
12
16
  * a button to run it now. It only reports; a person decides what to change.
13
17
  */
14
- export function WeeklyCheck({ weekly }: { weekly: WeeklySummary }) {
18
+ export function WeeklyCheck({
19
+ app,
20
+ weekly,
21
+ }: {
22
+ /** Your screens' configuration. */
23
+ app: EvalAppConfig;
24
+ weekly: WeeklySummary;
25
+ }) {
15
26
  return (
16
27
  <section aria-labelledby="weekly" className="space-y-3">
17
28
  <RefreshWhile active={weekly.running > 0} />
@@ -20,7 +31,7 @@ export function WeeklyCheck({ weekly }: { weekly: WeeklySummary }) {
20
31
  Weekly check
21
32
  <InfoTip term="weeklyCheck" />
22
33
  </h2>
23
- <form action={runWeeklyNow}>
34
+ <form action={app.actions.runWeeklyNow}>
24
35
  <Submit variant="quiet">Run it now</Submit>
25
36
  </form>
26
37
  </div>
@@ -29,7 +40,7 @@ export function WeeklyCheck({ weekly }: { weekly: WeeklySummary }) {
29
40
  {weekly.running > 0
30
41
  ? `Running now: ${weekly.running} quick set${weekly.running === 1 ? "" : "s"} left. `
31
42
  : weekly.lastAt
32
- ? `Last run ${weekly.lastAt.toLocaleDateString("en-US", { month: "long", day: "numeric" })}, ${money(weekly.costUsd)}. `
43
+ ? `Last run ${dayOf(weekly.lastAt)}, ${money(weekly.costUsd)}. `
33
44
  : "Not run yet. "}
34
45
  Every Monday, each live model answers its suite&apos;s quick set
35
46
  again, so a quiet change by its provider shows up here. It also flags
@@ -54,8 +65,8 @@ export function WeeklyCheck({ weekly }: { weekly: WeeklySummary }) {
54
65
  <Chip tone="serious">Drift</Chip>
55
66
  <span>
56
67
  <Link
57
- href={evalsPath(d.suite)}
58
- className="font-medium underline"
68
+ href={evalsPath(app, d.suite)}
69
+ className={`font-medium ${LINK}`}
59
70
  >
60
71
  {d.label}
61
72
  </Link>{" "}
@@ -73,8 +84,8 @@ export function WeeklyCheck({ weekly }: { weekly: WeeklySummary }) {
73
84
  <Chip tone="serious">Didn&apos;t finish</Chip>
74
85
  <span>
75
86
  <Link
76
- href={evalsPath(f.suite)}
77
- className="font-medium underline"
87
+ href={evalsPath(app, f.suite)}
88
+ className={`font-medium ${LINK}`}
78
89
  >
79
90
  {f.label}
80
91
  </Link>
@@ -91,8 +102,8 @@ export function WeeklyCheck({ weekly }: { weekly: WeeklySummary }) {
91
102
  <span>
92
103
  {r.model}, the {r.role} model for{" "}
93
104
  <Link
94
- href={evalsPath(r.suite)}
95
- className="font-medium underline"
105
+ href={evalsPath(app, r.suite)}
106
+ className={`font-medium ${LINK}`}
96
107
  >
97
108
  {r.label}
98
109
  </Link>
@@ -110,7 +121,7 @@ export function WeeklyCheck({ weekly }: { weekly: WeeklySummary }) {
110
121
  <Chip tone="warn">Thumbs down</Chip>
111
122
  <span>
112
123
  {t.operation}: {t.down} of {t.up + t.down} ratings this week.{" "}
113
- <Link href={evalsPath("feedback")} className="underline">
124
+ <Link href={evalsPath(app, "feedback")} className={LINK}>
114
125
  Read the reasons
115
126
  </Link>
116
127
  .
@@ -138,8 +149,8 @@ export function WeeklyCheck({ weekly }: { weekly: WeeklySummary }) {
138
149
  : `${d.waiting} waiting for review. `}
139
150
  {d.waiting > 0 && (
140
151
  <Link
141
- href={`${evalsPath(d.suite)}#answer-key`}
142
- className="underline"
152
+ href={`${evalsPath(app, d.suite)}#answer-key`}
153
+ className={LINK}
143
154
  >
144
155
  Review them
145
156
  </Link>
@@ -0,0 +1,173 @@
1
+ import type { ComponentType } from "react";
2
+ import type { EvalStore } from "../store.js";
3
+ import type { FeedbackStore } from "../feedback.js";
4
+ import { thumbsSummary } from "../feedback.js";
5
+ import type { ModelCatalog } from "../models.js";
6
+ import type { Route, Runner } from "../runner.js";
7
+ import type { BoardRow } from "../board.js";
8
+ import type { VersionedSettings } from "../settings.js";
9
+ import type { AnswerEditorProps, AnySuite } from "../types.js";
10
+ import { weeklySummary, type WeeklySummary } from "../weekly.js";
11
+
12
+ /** A form action: a server action the screens' forms submit to. */
13
+ export type FormAction = (form: FormData) => Promise<void>;
14
+
15
+ /**
16
+ * The server actions the screens' forms submit to. On Next.js, a
17
+ * `"use server"` module of your app makes them (`evalActions` does it in
18
+ * one line); the screens never import your modules themselves.
19
+ */
20
+ export type EvalActions = {
21
+ testModel: FormAction;
22
+ testAll: FormAction;
23
+ makeLive: FormAction;
24
+ makeFallback: FormAction;
25
+ useSuggestion: FormAction;
26
+ rescore: FormAction;
27
+ rollBackSettings: FormAction;
28
+ confirmAnswer: FormAction;
29
+ addCase: FormAction;
30
+ editAnswer: FormAction;
31
+ retireCase: FormAction;
32
+ /** Retiring easy cases beyond the floor; the health panel's button. */
33
+ retireEasy?: FormAction;
34
+ /** Retiring drafts nobody reviewed; the health panel's button. */
35
+ retireStaleDrafts?: FormAction;
36
+ runWeeklyNow: () => Promise<void>;
37
+ /** Blind rating; only for an app with the rate page. */
38
+ rateBlind?: FormAction;
39
+ /** Skipping a case in blind rating; only with the rate page. */
40
+ skipCase?: FormAction;
41
+ /** Turning a rating into a draft case; only with the feedback page. */
42
+ makeCase?: FormAction;
43
+ /** Setting a rating aside; only with the feedback page. */
44
+ dismissFeedback?: FormAction;
45
+ };
46
+
47
+ /**
48
+ * Everything Evalkeeper's screens need from your app, in one object: your
49
+ * runner, settings, and stores, your models and suites, where the pages
50
+ * live, your answer editors, and the actions their forms submit to. Make
51
+ * it once in your wiring module with `defineEvals`, and pass it to the
52
+ * screens.
53
+ */
54
+ export type EvalApp = {
55
+ runner: Runner;
56
+ settings: VersionedSettings;
57
+ store: EvalStore;
58
+ feedbackStore: FeedbackStore;
59
+ /** Your model catalog: labels, providers, prices, and retirements. */
60
+ models: ModelCatalog;
61
+ suites: AnySuite[];
62
+ /** What's live for an operation, as your router sees it. */
63
+ routeFor: (operation: string) => Promise<Route>;
64
+ /** Your own editors for answers plain fields edit badly, by suite. */
65
+ answerEditors: Partial<Record<string, ComponentType<AnswerEditorProps>>>;
66
+ actions: EvalActions;
67
+ /** Where the eval pages live, as a URL path: "/evals", "/admin/evals". */
68
+ basePath: string;
69
+ };
70
+
71
+ /** An `EvalApp` with its suites by key, as the screens read it. */
72
+ export type EvalAppConfig = EvalApp & {
73
+ /** Each suite by its key. */
74
+ suiteByKey: Readonly<Record<string, AnySuite>>;
75
+ };
76
+
77
+ /** A path without its trailing slashes, in one pass (no regex to backtrack). */
78
+ function withoutTrailingSlashes(path: string): string {
79
+ let end = path.length;
80
+ while (end > 0 && path[end - 1] === "/") end--;
81
+ return path.slice(0, end);
82
+ }
83
+
84
+ /**
85
+ * Makes the object the screens read everything from. Call it once in your
86
+ * wiring module and pass the result to the pages.
87
+ *
88
+ * @example
89
+ * ```ts
90
+ * export const evals = defineEvals({
91
+ * runner, settings, store, feedbackStore, models: MODELS, suites: SUITES,
92
+ * routeFor, answerEditors: {}, actions, basePath: "/admin/evals",
93
+ * });
94
+ * ```
95
+ *
96
+ * @param app - Your runner, stores, models, suites, editors, actions, and
97
+ * where the pages live.
98
+ */
99
+ export function defineEvals(app: EvalApp): EvalAppConfig {
100
+ return {
101
+ ...app,
102
+ basePath: withoutTrailingSlashes(app.basePath) || "/",
103
+ suiteByKey: Object.fromEntries(app.suites.map((s) => [s.key, s])),
104
+ };
105
+ }
106
+
107
+ /**
108
+ * A link to an eval page: the base path, then each part, escaped.
109
+ *
110
+ * @param app - Your screens' configuration (for the base path).
111
+ * @param parts - The path below it: a suite's key, "runs", a test's id.
112
+ */
113
+ export function evalsPath(app: { basePath: string }, ...parts: string[]) {
114
+ return [app.basePath, ...parts.map(encodeURIComponent)].join("/");
115
+ }
116
+
117
+ /** The moment `days` days before now. */
118
+ export const daysAgo = (days: number) => new Date(Date.now() - days * 864e5);
119
+
120
+ /**
121
+ * Where the weekly check stands, for the hub: the last week's tests,
122
+ * what's live, thumbs, and drafts.
123
+ *
124
+ * @param app - Your screens' configuration.
125
+ */
126
+ export async function loadWeekly(app: EvalApp): Promise<WeeklySummary> {
127
+ const [runs, routes, feedback, cases] = await Promise.all([
128
+ Promise.all(
129
+ app.suites.map((s) => app.store.listRuns(s.key, { limit: 50 })),
130
+ ).then((r) => r.flat()),
131
+ Promise.all(
132
+ app.suites.map(
133
+ async (s) => [s.operation, await app.routeFor(s.operation)] as const,
134
+ ),
135
+ ).then((r) => Object.fromEntries(r)),
136
+ app.feedbackStore.listFeedback({ since: daysAgo(7) }),
137
+ Promise.all(app.suites.map((s) => app.store.listCases(s.key))).then((c) =>
138
+ c.flat(),
139
+ ),
140
+ ]);
141
+ return weeklySummary({
142
+ runs,
143
+ suites: app.suites,
144
+ routes,
145
+ models: app.models,
146
+ thumbs: thumbsSummary(feedback, daysAgo(7)),
147
+ cases,
148
+ });
149
+ }
150
+
151
+ /**
152
+ * A model's attacks resisted: of the answers to a feature's attack cases,
153
+ * how many had no serious mistake, across its injection suites. Null
154
+ * until each has a current, complete test of the model.
155
+ *
156
+ * @param key - The model's row key (model and reasoning setting).
157
+ * @param boards - The feature's injection suites' boards.
158
+ */
159
+ export function attacksResisted(
160
+ key: string,
161
+ boards: readonly { rows: readonly BoardRow[] }[],
162
+ ): { resisted: number; of: number } | null {
163
+ if (!boards.length) return null;
164
+ let resisted = 0;
165
+ let of = 0;
166
+ for (const b of boards) {
167
+ const t = b.rows.find((r) => r.key === key)?.test;
168
+ if (!t || t.stale || t.failedAnswers) return null;
169
+ resisted += t.answersNoSerious;
170
+ of += t.answers;
171
+ }
172
+ return of ? { resisted, of } : null;
173
+ }
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Helpers the screens share on the server and in the browser. They live
3
+ * outside the client components' module because Next.js makes every
4
+ * export of a `"use client"` module a client reference, which server code
5
+ * can't call.
6
+ */
7
+
8
+ /** A share as a whole percent: 0.874 is "87%". */
9
+ export const pct = (x: number): string => `${Math.round(x * 100)}%`;
10
+
11
+ /**
12
+ * A button that isn't the page's main action: the app's accent as an
13
+ * outline, so it still reads as a button in the app's colors (set
14
+ * `--accent` in evalkeeper.css).
15
+ */
16
+ export const QUIET_BUTTON =
17
+ "border border-accent/40 bg-card text-accent hover:bg-accent/10";
18
+
19
+ /**
20
+ * A day, with the month as a word so no reader mistakes it:
21
+ * "Oct 28, 2026" (10/28 is the 10th of the 28th month in most of the world).
22
+ */
23
+ export const dayOf = (d: Date): string =>
24
+ d.toLocaleDateString("en-US", {
25
+ month: "short",
26
+ day: "numeric",
27
+ year: "numeric",
28
+ });
29
+
30
+ /** A day and time, the same way: "Oct 28, 2026, 3:04 PM". */
31
+ export const momentOf = (d: Date): string =>
32
+ d.toLocaleString("en-US", {
33
+ month: "short",
34
+ day: "numeric",
35
+ year: "numeric",
36
+ hour: "numeric",
37
+ minute: "2-digit",
38
+ });
39
+
40
+ /**
41
+ * Every link that reads as words: the app's accent, underlined on hover.
42
+ * Numbers that link (a score, a count) keep their own color, and links
43
+ * styled as buttons, card titles, and the back link have their own look.
44
+ */
45
+ export const LINK = "text-accent hover:underline";
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Evalkeeper's screens for React apps. Import from
3
+ * `@crowandraven/evalkeeper/react`; it needs React and `lucide-react`.
4
+ * Draw the screens with your app's own components through
5
+ * `EvalComponentsProvider`.
6
+ *
7
+ * @module evalkeeper/react
8
+ */
9
+ export * from "./pieces.js";
10
+ export * from "./format.js";
11
+ export * from "./app.js";
12
+ export * from "./SuiteSections.js";
13
+ export * from "./HubSections.js";
14
+ export * from "./AnswerKey.js";
15
+ export * from "./SettingsHistory.js";
16
+ export * from "./WeeklyCheck.js";
17
+ export * from "./Fields.js";
18
+ export * from "./ReadableOutput.js";
19
+ export * from "./DisagreementChip.js";
20
+ export * from "./AddCase.js";
21
+ export * from "./CaseMenu.js";
22
+ export * from "./ConfirmAnswer.js";
23
+ export * from "./RollBack.js";
24
+ export * from "./Thumbs.js";
25
+ export * from "./RunView.js";
26
+ export * from "./CompareView.js";
27
+ export * from "./SideBySideView.js";
28
+ export * from "./RateView.js";
29
+ export * from "./FeedbackView.js";
30
+ export * from "./ModelMenu.js";
31
+ export * from "./Tabs.js";