@crowandraven/evalkeeper 0.12.0 → 0.13.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 (61) hide show
  1. package/dist/glossary.d.ts +4 -2
  2. package/dist/glossary.js +4 -2
  3. package/dist/glossary.js.map +1 -1
  4. package/dist/health.d.ts +35 -2
  5. package/dist/health.js +29 -5
  6. package/dist/health.js.map +1 -1
  7. package/dist/index.d.ts +1 -0
  8. package/dist/index.js +1 -0
  9. package/dist/index.js.map +1 -1
  10. package/dist/next/actions.js +27 -7
  11. package/dist/next/actions.js.map +1 -1
  12. package/dist/next/wiring.d.ts +6 -0
  13. package/dist/order.d.ts +18 -0
  14. package/dist/order.js +53 -0
  15. package/dist/order.js.map +1 -0
  16. package/dist/prisma/index.d.ts +1 -0
  17. package/dist/prisma/index.js +3 -0
  18. package/dist/prisma/index.js.map +1 -1
  19. package/dist/react/HubSections.js +9 -7
  20. package/dist/react/HubSections.js.map +1 -1
  21. package/dist/react/ModelMenu.d.ts +13 -4
  22. package/dist/react/ModelMenu.js +12 -7
  23. package/dist/react/ModelMenu.js.map +1 -1
  24. package/dist/react/RateView.js +1 -0
  25. package/dist/react/RateView.js.map +1 -1
  26. package/dist/react/SuiteSections.d.ts +2 -0
  27. package/dist/react/SuiteSections.js +66 -29
  28. package/dist/react/SuiteSections.js.map +1 -1
  29. package/dist/react/app.d.ts +2 -0
  30. package/dist/react/app.js.map +1 -1
  31. package/dist/react/pieces.d.ts +10 -1
  32. package/dist/react/pieces.js +50 -0
  33. package/dist/react/pieces.js.map +1 -1
  34. package/dist/settings.d.ts +14 -0
  35. package/dist/settings.js +24 -2
  36. package/dist/settings.js.map +1 -1
  37. package/dist/testing.d.ts +1 -1
  38. package/dist/testing.js +32 -0
  39. package/dist/testing.js.map +1 -1
  40. package/dist/types.d.ts +12 -0
  41. package/dist/types.js +11 -0
  42. package/dist/types.js.map +1 -1
  43. package/package.json +1 -1
  44. package/schema/evalkeeper.prisma +3 -0
  45. package/src/glossary.ts +6 -2
  46. package/src/health.ts +53 -6
  47. package/src/index.ts +1 -0
  48. package/src/next/actions.ts +42 -8
  49. package/src/next/wiring.ts +6 -0
  50. package/src/order.ts +64 -0
  51. package/src/prisma/index.ts +5 -0
  52. package/src/react/HubSections.tsx +9 -7
  53. package/src/react/ModelMenu.tsx +24 -7
  54. package/src/react/RateView.tsx +1 -0
  55. package/src/react/SuiteSections.tsx +337 -178
  56. package/src/react/app.ts +2 -0
  57. package/src/react/pieces.tsx +62 -1
  58. package/src/settings.ts +37 -2
  59. package/src/testing.ts +35 -1
  60. package/src/types.ts +18 -0
  61. package/templates/lib/evalkeeper/actions.ts +4 -0
@@ -16,6 +16,7 @@ import {
16
16
  suggest,
17
17
  useDraftsProvisionally,
18
18
  withoutLeaks,
19
+ priorityOf,
19
20
  type ReasoningEffort,
20
21
  } from "../index.js";
21
22
  import { evalsPath, type EvalActions } from "../react/app.js";
@@ -50,6 +51,10 @@ export function evalActions(w: EvalWiring): Required<EvalActions> {
50
51
  };
51
52
  const weekly = weeklyCheck(w);
52
53
 
54
+ /** Who a settings change records: the admin's name, or their id. */
55
+ const changer = (admin: { id: string; name: string }) =>
56
+ w.changedBy === "id" ? admin.id : admin.name;
57
+
53
58
  const suiteFrom = (form: FormData) =>
54
59
  runner.suiteOrThrow(formText(form, "suite"));
55
60
 
@@ -88,7 +93,7 @@ export function evalActions(w: EvalWiring): Required<EvalActions> {
88
93
  */
89
94
  async function caseToRate(form: FormData, raterId: string) {
90
95
  const suite = suiteFrom(form);
91
- if (suite.caseKind !== "imported")
96
+ if (suite.caseKind !== "imported" || suite.rateBlind === false)
92
97
  throw new Error("This suite isn't rated blind");
93
98
  const c = await knownCase(suite.key, form);
94
99
  if (raterStatus(c, raterId))
@@ -206,7 +211,7 @@ export function evalActions(w: EvalWiring): Required<EvalActions> {
206
211
  ? { model: row.model, reasoningEffort: row.effort }
207
212
  : { model: row.model },
208
213
  {
209
- by: admin.name,
214
+ by: changer(admin),
210
215
  reason: `Made ${row.label} live: ${score.right}/${score.total}, ${VS[row.vsLive ?? ""] ?? "no comparison"}${attacked === null ? "" : `; ${attacked} serious ${attacked === 1 ? "mistake" : "mistakes"} under attack`}`,
211
216
  // The evidence, so the history can show why.
212
217
  evidence: {
@@ -234,7 +239,7 @@ export function evalActions(w: EvalWiring): Required<EvalActions> {
234
239
  suite.operation,
235
240
  { fallbackModel: row.model },
236
241
  {
237
- by: admin.name,
242
+ by: changer(admin),
238
243
  reason: `Made ${row.label} the fallback: ${test ? `${Math.round(test.right)}/${Math.round(test.total)}${failed}` : "not tested"}`,
239
244
  evidence: {
240
245
  runId: test?.runId ?? null,
@@ -254,15 +259,22 @@ export function evalActions(w: EvalWiring): Required<EvalActions> {
254
259
  runner.board(suite.key),
255
260
  attacksOn(suite.key),
256
261
  ]);
257
- const s = suggest(board.rows, suite.checks, suite.priority, w.models, {
258
- attacks,
259
- });
262
+ const { settings: live } = await settings.current(suite.operation);
263
+ const s = suggest(
264
+ board.rows,
265
+ suite.checks,
266
+ priorityOf(suite, live),
267
+ w.models,
268
+ {
269
+ attacks,
270
+ },
271
+ );
260
272
  if (!s || s.same) return;
261
273
  await settings.update(
262
274
  suite.operation,
263
275
  { model: s.live.model, fallbackModel: s.fallback?.model ?? null },
264
276
  {
265
- by: admin.name,
277
+ by: changer(admin),
266
278
  reason: s.reasons.join(" "),
267
279
  evidence: {
268
280
  suggestion: s.reasons,
@@ -281,7 +293,7 @@ export function evalActions(w: EvalWiring): Required<EvalActions> {
281
293
  const reason = formText(form, "reason");
282
294
  if (!reason) throw new Error("Say why you're rolling back");
283
295
  await settings.rollBack(suite.operation, formText(form, "version"), {
284
- by: admin.name,
296
+ by: changer(admin),
285
297
  reason,
286
298
  });
287
299
  everyPage();
@@ -432,6 +444,28 @@ export function evalActions(w: EvalWiring): Required<EvalActions> {
432
444
  revalidatePath(page(suite.key));
433
445
  },
434
446
 
447
+ async setPriority(form) {
448
+ const admin = await w.requireAdmin();
449
+ const suite = choosingSuite(form);
450
+ const favor = formText(form, "favor");
451
+ if (favor !== "quality" && favor !== "speed" && favor !== "cost")
452
+ throw new Error("Pick accuracy, speed, or cost");
453
+ const reason = form.get("reason");
454
+ await settings.update(
455
+ suite.operation,
456
+ // The suite's own priority needs no override.
457
+ { favor: favor === suite.priority.favor ? null : favor },
458
+ {
459
+ by: changer(admin),
460
+ reason:
461
+ typeof reason === "string" && reason.trim()
462
+ ? reason.trim().slice(0, 300)
463
+ : `Favors ${favor === "quality" ? "accuracy" : favor}`,
464
+ },
465
+ );
466
+ everyPage();
467
+ },
468
+
435
469
  async useDraftsProvisionally(form) {
436
470
  await w.requireAdmin();
437
471
  const suite = suiteFrom(form);
@@ -15,4 +15,10 @@ export type EvalWiring = Omit<EvalApp, "actions"> & {
15
15
  * is recorded as who made each change.
16
16
  */
17
17
  requireAdmin: () => Promise<EvalAdmin>;
18
+ /**
19
+ * What the settings history records as who made a change: the admin's
20
+ * `name` (the default) or `id`. Use "id" when your settings store keeps
21
+ * a user id there (a foreign key) and shows names from it.
22
+ */
23
+ changedBy?: "name" | "id";
18
24
  };
package/src/order.ts ADDED
@@ -0,0 +1,64 @@
1
+ import type { BoardRow } from "./board.js";
2
+ import type { CheckDef, SuitePriority } from "./types.js";
3
+ import { seriousMistakes } from "./suggest.js";
4
+
5
+ /**
6
+ * A board's rows in the order the suggestion weighs them: the suggested
7
+ * live model first, then the live one, then models with a current test by
8
+ * fewest serious mistakes, highest accuracy, and the suite's priority
9
+ * (lower cost or time), then the rest. Accuracy is never traded away by
10
+ * this order: cost and speed only break ties. Pure.
11
+ */
12
+ export function orderRows<R extends BoardRow>(
13
+ rows: readonly R[],
14
+ checks: CheckDef[],
15
+ priority: SuitePriority,
16
+ suggested: { live: string | null } = { live: null },
17
+ ): R[] {
18
+ const current = (r: R) => !!r.test && !r.test.stale;
19
+ const accuracy = (r: R) => (r.test?.total ? r.test.right / r.test.total : 0);
20
+ const favored = (r: R) =>
21
+ priority.favor === "cost"
22
+ ? (r.test?.costPerAnswer ?? Infinity)
23
+ : priority.favor === "speed"
24
+ ? (r.test?.avgMs ?? Infinity)
25
+ : 0;
26
+ const rank = (r: R): number[] => [
27
+ r.key === suggested.live ? 0 : 1,
28
+ r.live ? 0 : 1,
29
+ current(r) ? 0 : 1,
30
+ current(r) ? seriousMistakes(r, checks) : 0,
31
+ -accuracy(r),
32
+ favored(r),
33
+ ];
34
+ return [...rows].sort((a, b) => {
35
+ const x = rank(a);
36
+ const y = rank(b);
37
+ for (let i = 0; i < x.length; i++)
38
+ if (x[i] !== y[i]) return (x[i] ?? 0) - (y[i] ?? 0);
39
+ return 0;
40
+ });
41
+ }
42
+
43
+ /**
44
+ * What a model gains on the suite's priority over the live one, when
45
+ * it's about as accurate: "4× cheaper", "2.5× faster". Null under 1.5×,
46
+ * or when the suite favors accuracy. Pure.
47
+ */
48
+ export function priorityGain(
49
+ row: BoardRow,
50
+ live: BoardRow | undefined,
51
+ priority: SuitePriority,
52
+ ): string | null {
53
+ if (!row.test || !live?.test || priority.favor === "quality") return null;
54
+ const [mine, theirs, word] =
55
+ priority.favor === "cost"
56
+ ? [row.test.costPerAnswer, live.test.costPerAnswer, "cheaper"]
57
+ : [row.test.avgMs, live.test.avgMs, "faster"];
58
+ if (mine === null || theirs === null || !(mine > 0) || !(theirs > 0))
59
+ return null;
60
+ const ratio = theirs / mine;
61
+ if (ratio < 1.5) return null;
62
+ const shown = ratio >= 10 ? Math.round(ratio) : Math.round(ratio * 10) / 10;
63
+ return `${shown}× ${word}`;
64
+ }
@@ -863,6 +863,7 @@ export type EvalSettingsVersionRow = {
863
863
  reasoningEffort: string | null;
864
864
  maxOutputTokens: number | null;
865
865
  temperature: number | null;
866
+ favor?: string | null;
866
867
  promptVersion: string | null;
867
868
  createdAt: Date;
868
869
  };
@@ -921,10 +922,14 @@ const version = (v: Row): SettingsVersion => ({
921
922
  reasoningEffort: strOrNull(v.reasoningEffort),
922
923
  maxOutputTokens: numOrNull(v.maxOutputTokens),
923
924
  temperature: numOrNull(v.temperature),
925
+ // An unknown or missing value reads as the suite's own priority.
926
+ favor: FAVORS.find((f) => f === v.favor) ?? null,
924
927
  promptVersion: strOrNull(v.promptVersion),
925
928
  createdAt: date(v.createdAt),
926
929
  });
927
930
 
931
+ const FAVORS = ["speed", "cost", "quality"] as const;
932
+
928
933
  const settingsChange = (c: Row, by: string | null): SettingsChange => ({
929
934
  id: str(c.id),
930
935
  operation: str(c.operation),
@@ -3,6 +3,7 @@ import {
3
3
  attention,
4
4
  isInjectionSuite,
5
5
  perAnswer,
6
+ priorityOf,
6
7
  seconds,
7
8
  suiteHealth,
8
9
  thumbsSummary,
@@ -11,7 +12,7 @@ import {
11
12
  type Settings,
12
13
  type SettingsVersion,
13
14
  } from "../index.js";
14
- import { Link, Card, InfoTip, StatusBadge } from "./pieces.js";
15
+ import { Link, Card, InfoTip, HealthChips } from "./pieces.js";
15
16
  import { pct, dayOf } from "./format.js";
16
17
  import { HistoryEntries } from "./SettingsHistory.js";
17
18
  import {
@@ -134,7 +135,7 @@ export function HubStats({ data }: { data: HubData }) {
134
135
  : "—"
135
136
  }
136
137
  />
137
- <Link href={evalsPath(app, "feedback")}>
138
+ <Link href={evalsPath(app, "feedback")} className="block h-full">
138
139
  <Stat
139
140
  title="Thumbs down this week"
140
141
  term="thumbs"
@@ -165,16 +166,16 @@ export function SuiteList({ data }: { data: HubData }) {
165
166
  <div className="space-y-4">
166
167
  {cards.map(({ b, i }) => {
167
168
  const attacked = attacksOn(b.suite.key);
169
+ const [history, current] = histories[i] ?? [[], null];
168
170
  const h = suiteHealth(
169
171
  b.rows,
170
172
  b.suite.checks,
171
- b.suite.priority,
173
+ priorityOf(b.suite, current?.settings),
172
174
  b.cases,
173
175
  b.provisional,
174
176
  app.models,
175
177
  { attacks: attacksFrom(attacked) },
176
178
  );
177
- const [history, current] = histories[i] ?? [[], null];
178
179
  return (
179
180
  <SuiteCard
180
181
  app={app}
@@ -244,7 +245,8 @@ function Stat({
244
245
  detail: string;
245
246
  }) {
246
247
  return (
247
- <Card className="space-y-1">
248
+ // Full height, so the four cards line up however much each says.
249
+ <Card className="h-full space-y-1">
248
250
  <p className="text-sm text-muted">
249
251
  {title}
250
252
  <InfoTip term={term} />
@@ -308,7 +310,7 @@ function SuiteCard({
308
310
  {b.suite.label}
309
311
  </Link>
310
312
  </h2>
311
- <StatusBadge status={h.status} />
313
+ <HealthChips flags={h.flags} />
312
314
  </div>
313
315
  <p className="readable text-sm text-muted">{b.suite.description}</p>
314
316
  </div>
@@ -351,7 +353,7 @@ function SuiteCard({
351
353
  <p className="text-sm">
352
354
  {t ? (
353
355
  <>
354
- Score{" "}
356
+ Accuracy{" "}
355
357
  <span className={`font-semibold ${scoreTone(t.right / t.total)}`}>
356
358
  {pct(t.right / t.total)}
357
359
  </span>
@@ -6,14 +6,15 @@ import { Button } from "./pieces.js";
6
6
  import type { FormAction } from "./app.js";
7
7
 
8
8
  /**
9
- * A model row's menu: make it live, or make it the fallback, where the
10
- * row allows either. Keeps the model table narrow. Closes on a click
11
- * outside or Escape.
9
+ * A model row's menu: test it (with what that costs now), make it live,
10
+ * or make it the fallback, where the row allows either. Keeps the model
11
+ * table narrow. Closes on a click outside or Escape.
12
12
  */
13
13
  export function ModelMenu({
14
14
  suite,
15
15
  model,
16
16
  label,
17
+ test,
17
18
  makeLive,
18
19
  makeFallback,
19
20
  effort,
@@ -22,6 +23,11 @@ export function ModelMenu({
22
23
  model: string;
23
24
  /** The model's name, for the button's accessible name. */
24
25
  label: string;
26
+ /**
27
+ * Your testModel action, its words ("Test", "Test again"), and what
28
+ * testing costs now ("free, all 34 reused"), when known.
29
+ */
30
+ test?: { action: FormAction; text: string; note: string | null };
25
31
  /** Your makeLive action, when the model can be made live. */
26
32
  makeLive: FormAction | null;
27
33
  /** Your makeFallback action, when it can be the fallback. */
@@ -53,11 +59,20 @@ export function ModelMenu({
53
59
  };
54
60
  }, [open]);
55
61
 
56
- if (!makeLive && !makeFallback) return null;
62
+ if (!test && !makeLive && !makeFallback) return null;
57
63
  const item =
58
64
  "block w-full rounded px-3 py-1.5 text-left text-sm hover:bg-tint";
59
- const choice = (action: FormAction, text: string) => (
60
- <form action={action}>
65
+ const choice = (action: FormAction, text: string, note?: string | null) => (
66
+ // Closes once chosen (after the submit is read), so the open menu
67
+ // doesn't cover the rows below it.
68
+ <form
69
+ action={action}
70
+ onSubmit={() =>
71
+ setTimeout(() => {
72
+ setOpen(false);
73
+ })
74
+ }
75
+ >
61
76
  <input type="hidden" name="suite" value={suite} />
62
77
  <input type="hidden" name="model" value={model} />
63
78
  {effort !== undefined && (
@@ -65,6 +80,7 @@ export function ModelMenu({
65
80
  )}
66
81
  <Button type="submit" role="menuitem" className={item}>
67
82
  {text}
83
+ {note && <span className="block text-xs text-muted">{note}</span>}
68
84
  </Button>
69
85
  </form>
70
86
  );
@@ -87,8 +103,9 @@ export function ModelMenu({
87
103
  {open && (
88
104
  <div
89
105
  role="menu"
90
- className="absolute right-0 z-20 mt-1 w-40 rounded-md border border-line bg-card p-1 shadow-lg"
106
+ className="absolute right-0 z-20 mt-1 w-56 rounded-md border border-line bg-card p-1 shadow-lg"
91
107
  >
108
+ {test && choice(test.action, test.text, test.note)}
92
109
  {makeLive && choice(makeLive, "Make live")}
93
110
  {makeFallback && choice(makeFallback, "Make fallback")}
94
111
  </div>
@@ -30,6 +30,7 @@ export async function RateView({
30
30
  if (
31
31
  !suite ||
32
32
  suite.caseKind !== "imported" ||
33
+ suite.rateBlind === false ||
33
34
  !fields ||
34
35
  !(suite.labelFromForm || app.answerEditors[key])
35
36
  )