@crowandraven/evalkeeper 0.18.0 → 0.19.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.
- package/dist/decisions.js +1 -1
- package/dist/decisions.js.map +1 -1
- package/dist/drafts.d.ts +2 -0
- package/dist/drafts.js +1 -1
- package/dist/drafts.js.map +1 -1
- package/dist/glossary.d.ts +25 -14
- package/dist/glossary.js +25 -14
- package/dist/glossary.js.map +1 -1
- package/dist/health.js +2 -2
- package/dist/health.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/memoryStore.d.ts +2 -1
- package/dist/memoryStore.js +9 -0
- package/dist/memoryStore.js.map +1 -1
- package/dist/next/actions.js +58 -3
- package/dist/next/actions.js.map +1 -1
- package/dist/prisma/contracts.d.ts +5 -2
- package/dist/prisma/contracts.js +7 -1
- package/dist/prisma/contracts.js.map +1 -1
- package/dist/prisma/index.d.ts +40 -1
- package/dist/prisma/index.js +37 -1
- package/dist/prisma/index.js.map +1 -1
- package/dist/prune.d.ts +5 -2
- package/dist/prune.js +7 -4
- package/dist/prune.js.map +1 -1
- package/dist/react/AddCase.js +11 -5
- package/dist/react/AddCase.js.map +1 -1
- package/dist/react/AnswerKey.js +7 -4
- package/dist/react/AnswerKey.js.map +1 -1
- package/dist/react/CaseMenu.d.ts +2 -2
- package/dist/react/CaseMenu.js +10 -31
- package/dist/react/CaseMenu.js.map +1 -1
- package/dist/react/CompareView.js +3 -3
- package/dist/react/CompareView.js.map +1 -1
- package/dist/react/ConfirmAnswer.js +1 -1
- package/dist/react/ConfirmAnswer.js.map +1 -1
- package/dist/react/Drawer.d.ts +32 -0
- package/dist/react/Drawer.js +60 -0
- package/dist/react/Drawer.js.map +1 -0
- package/dist/react/HubSections.d.ts +31 -18
- package/dist/react/HubSections.js +104 -103
- package/dist/react/HubSections.js.map +1 -1
- package/dist/react/Menu.d.ts +37 -0
- package/dist/react/Menu.js +51 -0
- package/dist/react/Menu.js.map +1 -0
- package/dist/react/ModelMenu.d.ts +1 -1
- package/dist/react/ModelMenu.js +8 -32
- package/dist/react/ModelMenu.js.map +1 -1
- package/dist/react/RunView.js +24 -4
- package/dist/react/RunView.js.map +1 -1
- package/dist/react/Spending.d.ts +25 -0
- package/dist/react/Spending.js +51 -0
- package/dist/react/Spending.js.map +1 -0
- package/dist/react/SuiteSections.d.ts +25 -6
- package/dist/react/SuiteSections.js +233 -75
- package/dist/react/SuiteSections.js.map +1 -1
- package/dist/react/app.d.ts +18 -0
- package/dist/react/app.js.map +1 -1
- package/dist/react/format.d.ts +13 -0
- package/dist/react/format.js +13 -0
- package/dist/react/format.js.map +1 -1
- package/dist/react/index.d.ts +3 -0
- package/dist/react/index.js +3 -0
- package/dist/react/index.js.map +1 -1
- package/dist/react/pieces.d.ts +21 -8
- package/dist/react/pieces.js +44 -14
- package/dist/react/pieces.js.map +1 -1
- package/dist/runner.d.ts +15 -1
- package/dist/runner.js +89 -13
- package/dist/runner.js.map +1 -1
- package/dist/settings.d.ts +12 -0
- package/dist/settings.js +18 -0
- package/dist/settings.js.map +1 -1
- package/dist/spending.d.ts +100 -0
- package/dist/spending.js +133 -0
- package/dist/spending.js.map +1 -0
- package/dist/stats.d.ts +3 -1
- package/dist/stats.js +6 -2
- package/dist/stats.js.map +1 -1
- package/dist/store.d.ts +5 -0
- package/dist/suggest.js +17 -12
- package/dist/suggest.js.map +1 -1
- package/dist/suiteSettings.d.ts +78 -0
- package/dist/suiteSettings.js +142 -0
- package/dist/suiteSettings.js.map +1 -0
- package/dist/suites/crisisRisk.js +3 -3
- package/dist/suites/crisisRisk.js.map +1 -1
- package/dist/suites/hopelessness.js +6 -6
- package/dist/suites/hopelessness.js.map +1 -1
- package/dist/suites/injection.js +2 -2
- package/dist/suites/injection.js.map +1 -1
- package/dist/summary.d.ts +41 -4
- package/dist/summary.js +46 -8
- package/dist/summary.js.map +1 -1
- package/dist/testing.d.ts +19 -0
- package/dist/testing.js +61 -0
- package/dist/testing.js.map +1 -1
- package/dist/todo.d.ts +146 -0
- package/dist/todo.js +198 -0
- package/dist/todo.js.map +1 -0
- package/dist/types.d.ts +40 -7
- package/dist/types.js +28 -4
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
- package/schema/evalkeeper.prisma +13 -0
- package/src/decisions.ts +1 -1
- package/src/drafts.ts +3 -1
- package/src/glossary.ts +35 -14
- package/src/health.ts +3 -2
- package/src/index.ts +3 -0
- package/src/memoryStore.ts +15 -1
- package/src/next/actions.ts +67 -2
- package/src/prisma/contracts.ts +16 -1
- package/src/prisma/index.ts +68 -1
- package/src/prune.ts +7 -2
- package/src/react/AddCase.tsx +13 -11
- package/src/react/AnswerKey.tsx +17 -5
- package/src/react/CaseMenu.tsx +23 -77
- package/src/react/CompareView.tsx +4 -10
- package/src/react/ConfirmAnswer.tsx +1 -1
- package/src/react/Drawer.tsx +130 -0
- package/src/react/HubSections.tsx +180 -414
- package/src/react/Menu.tsx +155 -0
- package/src/react/ModelMenu.tsx +23 -74
- package/src/react/RunView.tsx +46 -3
- package/src/react/Spending.tsx +200 -0
- package/src/react/SuiteSections.tsx +579 -175
- package/src/react/app.ts +18 -0
- package/src/react/format.ts +15 -0
- package/src/react/index.ts +3 -0
- package/src/react/pieces.tsx +57 -18
- package/src/runner.ts +122 -12
- package/src/settings.ts +20 -0
- package/src/spending.ts +209 -0
- package/src/stats.ts +8 -2
- package/src/store.ts +5 -0
- package/src/suggest.ts +21 -14
- package/src/suiteSettings.ts +201 -0
- package/src/suites/crisisRisk.ts +3 -3
- package/src/suites/hopelessness.ts +6 -6
- package/src/suites/injection.ts +2 -2
- package/src/summary.ts +59 -8
- package/src/testing.ts +77 -0
- package/src/todo.ts +318 -0
- package/src/types.ts +57 -9
- package/starter/index.ts +7 -0
- package/templates/lib/evalkeeper/actions.ts +20 -0
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
createContext,
|
|
5
|
+
useContext,
|
|
6
|
+
useRef,
|
|
7
|
+
useState,
|
|
8
|
+
type ReactNode,
|
|
9
|
+
} from "react";
|
|
10
|
+
import { EllipsisVertical } from "lucide-react";
|
|
11
|
+
import { Button } from "./pieces.js";
|
|
12
|
+
import { useDismiss } from "./InfoPopover.js";
|
|
13
|
+
import type { FormAction } from "./app.js";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The one menu on the eval pages: a vertical-dots button that opens a list
|
|
17
|
+
* of items. A model row's menu, a case's menu, and the page title's menu
|
|
18
|
+
* are all this, so every menu looks and behaves the same. Closes on a
|
|
19
|
+
* click outside, Escape, or once an item is chosen.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
const Close = createContext<() => void>(() => {});
|
|
23
|
+
|
|
24
|
+
/** A menu item's look, shared by buttons and forms. */
|
|
25
|
+
const ITEM = "block w-full rounded px-3 py-1.5 text-left text-sm hover:bg-tint";
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* A vertical-dots button and its menu.
|
|
29
|
+
*/
|
|
30
|
+
export function Menu({
|
|
31
|
+
label,
|
|
32
|
+
children,
|
|
33
|
+
width = "w-56",
|
|
34
|
+
className = "relative",
|
|
35
|
+
}: {
|
|
36
|
+
/** The button's accessible name: "Choose GPT-6 Luna". */
|
|
37
|
+
label: string;
|
|
38
|
+
children: ReactNode;
|
|
39
|
+
/** The menu's width class; `w-56` by default. */
|
|
40
|
+
width?: string;
|
|
41
|
+
/** Classes for the wrapper (to place it). */
|
|
42
|
+
className?: string;
|
|
43
|
+
}) {
|
|
44
|
+
const [open, setOpen] = useState(false);
|
|
45
|
+
const ref = useRef<HTMLDivElement>(null);
|
|
46
|
+
useDismiss(open, setOpen, ref);
|
|
47
|
+
return (
|
|
48
|
+
<div ref={ref} className={className}>
|
|
49
|
+
<Button
|
|
50
|
+
type="button"
|
|
51
|
+
aria-label={label}
|
|
52
|
+
title={label}
|
|
53
|
+
aria-haspopup="menu"
|
|
54
|
+
aria-expanded={open}
|
|
55
|
+
onClick={() => {
|
|
56
|
+
setOpen(!open);
|
|
57
|
+
}}
|
|
58
|
+
className="inline-flex h-8 w-8 items-center justify-center rounded-md text-muted hover:bg-tint hover:text-ink"
|
|
59
|
+
>
|
|
60
|
+
<EllipsisVertical aria-hidden className="h-4 w-4" />
|
|
61
|
+
</Button>
|
|
62
|
+
{open && (
|
|
63
|
+
<div
|
|
64
|
+
role="menu"
|
|
65
|
+
aria-label={label}
|
|
66
|
+
className={`absolute right-0 z-20 mt-1 ${width} rounded-md border border-line bg-card p-1 shadow-lg`}
|
|
67
|
+
>
|
|
68
|
+
<Close.Provider
|
|
69
|
+
value={() => {
|
|
70
|
+
setOpen(false);
|
|
71
|
+
}}
|
|
72
|
+
>
|
|
73
|
+
{children}
|
|
74
|
+
</Close.Provider>
|
|
75
|
+
</div>
|
|
76
|
+
)}
|
|
77
|
+
</div>
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* A menu item that does something in the browser (opens a form or a
|
|
83
|
+
* drawer), then closes the menu.
|
|
84
|
+
*/
|
|
85
|
+
export function MenuButton({
|
|
86
|
+
onSelect,
|
|
87
|
+
children,
|
|
88
|
+
danger = false,
|
|
89
|
+
}: {
|
|
90
|
+
onSelect: () => void;
|
|
91
|
+
children: ReactNode;
|
|
92
|
+
/** Shown in the bad color, for retiring and the like. */
|
|
93
|
+
danger?: boolean;
|
|
94
|
+
}) {
|
|
95
|
+
const close = useContext(Close);
|
|
96
|
+
return (
|
|
97
|
+
<Button
|
|
98
|
+
type="button"
|
|
99
|
+
role="menuitem"
|
|
100
|
+
className={`${ITEM}${danger ? " text-bad" : ""}`}
|
|
101
|
+
onClick={() => {
|
|
102
|
+
onSelect();
|
|
103
|
+
close();
|
|
104
|
+
}}
|
|
105
|
+
>
|
|
106
|
+
{children}
|
|
107
|
+
</Button>
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* A menu item that submits a server action with hidden fields, with an
|
|
113
|
+
* optional note under its words ("free, all 34 reused"). The menu closes
|
|
114
|
+
* once the form is read, so it doesn't cover the rows below.
|
|
115
|
+
*/
|
|
116
|
+
export function MenuForm({
|
|
117
|
+
action,
|
|
118
|
+
fields,
|
|
119
|
+
children,
|
|
120
|
+
note,
|
|
121
|
+
danger = false,
|
|
122
|
+
}: {
|
|
123
|
+
action: FormAction;
|
|
124
|
+
/** Hidden fields, by name; undefined ones are left out. */
|
|
125
|
+
fields: Readonly<Record<string, string | undefined>>;
|
|
126
|
+
children: ReactNode;
|
|
127
|
+
note?: string | null;
|
|
128
|
+
danger?: boolean;
|
|
129
|
+
}) {
|
|
130
|
+
const close = useContext(Close);
|
|
131
|
+
return (
|
|
132
|
+
<form
|
|
133
|
+
action={action}
|
|
134
|
+
onSubmit={() =>
|
|
135
|
+
setTimeout(() => {
|
|
136
|
+
close();
|
|
137
|
+
})
|
|
138
|
+
}
|
|
139
|
+
>
|
|
140
|
+
{Object.entries(fields).map(([name, value]) =>
|
|
141
|
+
value === undefined ? null : (
|
|
142
|
+
<input key={name} type="hidden" name={name} value={value} />
|
|
143
|
+
),
|
|
144
|
+
)}
|
|
145
|
+
<Button
|
|
146
|
+
type="submit"
|
|
147
|
+
role="menuitem"
|
|
148
|
+
className={`${ITEM}${danger ? " text-bad" : ""}`}
|
|
149
|
+
>
|
|
150
|
+
{children}
|
|
151
|
+
{note && <span className="block text-xs text-muted">{note}</span>}
|
|
152
|
+
</Button>
|
|
153
|
+
</form>
|
|
154
|
+
);
|
|
155
|
+
}
|
package/src/react/ModelMenu.tsx
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import { EllipsisVertical } from "lucide-react";
|
|
5
|
-
import { Button } from "./pieces.js";
|
|
3
|
+
import { Menu, MenuForm } from "./Menu.js";
|
|
6
4
|
import type { FormAction } from "./app.js";
|
|
7
5
|
|
|
8
6
|
/**
|
|
9
7
|
* A model row's menu: test it (with what that costs now), make it live,
|
|
10
8
|
* or make it the fallback, where the row allows either. Keeps the model
|
|
11
|
-
* table narrow.
|
|
9
|
+
* table narrow. The eval pages' one `Menu`.
|
|
12
10
|
*/
|
|
13
11
|
export function ModelMenu({
|
|
14
12
|
suite,
|
|
@@ -38,78 +36,29 @@ export function ModelMenu({
|
|
|
38
36
|
*/
|
|
39
37
|
effort?: string | null | undefined;
|
|
40
38
|
}) {
|
|
41
|
-
const [open, setOpen] = useState(false);
|
|
42
|
-
const ref = useRef<HTMLDivElement>(null);
|
|
43
|
-
|
|
44
|
-
useEffect(() => {
|
|
45
|
-
if (!open) return;
|
|
46
|
-
const close = (e: MouseEvent | KeyboardEvent) => {
|
|
47
|
-
if (
|
|
48
|
-
e instanceof KeyboardEvent
|
|
49
|
-
? e.key === "Escape"
|
|
50
|
-
: !ref.current?.contains(e.target as Node)
|
|
51
|
-
)
|
|
52
|
-
setOpen(false);
|
|
53
|
-
};
|
|
54
|
-
document.addEventListener("mousedown", close);
|
|
55
|
-
document.addEventListener("keydown", close);
|
|
56
|
-
return () => {
|
|
57
|
-
document.removeEventListener("mousedown", close);
|
|
58
|
-
document.removeEventListener("keydown", close);
|
|
59
|
-
};
|
|
60
|
-
}, [open]);
|
|
61
|
-
|
|
62
39
|
if (!test && !makeLive && !makeFallback) return null;
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
<form
|
|
69
|
-
action={action}
|
|
70
|
-
onSubmit={() =>
|
|
71
|
-
setTimeout(() => {
|
|
72
|
-
setOpen(false);
|
|
73
|
-
})
|
|
74
|
-
}
|
|
75
|
-
>
|
|
76
|
-
<input type="hidden" name="suite" value={suite} />
|
|
77
|
-
<input type="hidden" name="model" value={model} />
|
|
78
|
-
{effort !== undefined && (
|
|
79
|
-
<input type="hidden" name="effort" value={effort ?? "default"} />
|
|
80
|
-
)}
|
|
81
|
-
<Button type="submit" role="menuitem" className={item}>
|
|
82
|
-
{text}
|
|
83
|
-
{note && <span className="block text-xs text-muted">{note}</span>}
|
|
84
|
-
</Button>
|
|
85
|
-
</form>
|
|
86
|
-
);
|
|
87
|
-
|
|
40
|
+
const fields = {
|
|
41
|
+
suite,
|
|
42
|
+
model,
|
|
43
|
+
effort: effort === undefined ? undefined : (effort ?? "default"),
|
|
44
|
+
};
|
|
88
45
|
return (
|
|
89
|
-
<
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
<
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
<div
|
|
105
|
-
role="menu"
|
|
106
|
-
className="absolute right-0 z-20 mt-1 w-56 rounded-md border border-line bg-card p-1 shadow-lg"
|
|
107
|
-
>
|
|
108
|
-
{test && choice(test.action, test.text, test.note)}
|
|
109
|
-
{makeLive && choice(makeLive, "Make live")}
|
|
110
|
-
{makeFallback && choice(makeFallback, "Make fallback")}
|
|
111
|
-
</div>
|
|
46
|
+
<Menu label={`Choose ${label}`}>
|
|
47
|
+
{test && (
|
|
48
|
+
<MenuForm action={test.action} fields={fields} note={test.note}>
|
|
49
|
+
{test.text}
|
|
50
|
+
</MenuForm>
|
|
51
|
+
)}
|
|
52
|
+
{makeLive && (
|
|
53
|
+
<MenuForm action={makeLive} fields={fields}>
|
|
54
|
+
Make live
|
|
55
|
+
</MenuForm>
|
|
56
|
+
)}
|
|
57
|
+
{makeFallback && (
|
|
58
|
+
<MenuForm action={makeFallback} fields={fields}>
|
|
59
|
+
Make fallback
|
|
60
|
+
</MenuForm>
|
|
112
61
|
)}
|
|
113
|
-
</
|
|
62
|
+
</Menu>
|
|
114
63
|
);
|
|
115
64
|
}
|
package/src/react/RunView.tsx
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { evalsPath, type EvalAppConfig } from "./app.js";
|
|
2
|
-
import { Link, LocalDate } from "./pieces.js";
|
|
3
|
-
import {
|
|
2
|
+
import { InfoTip, Link, LocalDate } from "./pieces.js";
|
|
3
|
+
import {
|
|
4
|
+
SEVERITY_LABEL,
|
|
5
|
+
SEVERITY_ORDER,
|
|
6
|
+
allPassed,
|
|
7
|
+
failureHints,
|
|
8
|
+
money,
|
|
9
|
+
summarize,
|
|
10
|
+
} from "../index.js";
|
|
4
11
|
import { FieldValues } from "./Fields.js";
|
|
5
12
|
import { ReadableOutput } from "./ReadableOutput.js";
|
|
6
13
|
import { BackLink, Card } from "./pieces.js";
|
|
@@ -38,6 +45,12 @@ export async function RunView({
|
|
|
38
45
|
o.error ? 0 : allPassed(o.scores ?? null) ? 2 : 1;
|
|
39
46
|
const ordered = [...outputs].sort((a, b) => rank(a) - rank(b));
|
|
40
47
|
const failed = outputs.filter((o) => o.error);
|
|
48
|
+
// The first answer that missed each check, which a to-do item's "See the
|
|
49
|
+
// cases" links to (#check-<key>).
|
|
50
|
+
const firstMiss = new Map<string, string>();
|
|
51
|
+
for (const o of ordered)
|
|
52
|
+
for (const c of o.scores ?? [])
|
|
53
|
+
if (c.pass === false && !firstMiss.has(c.key)) firstMiss.set(c.key, o.id);
|
|
41
54
|
// Why they failed, counted: "timed out after 60s (3)".
|
|
42
55
|
const reasons = [
|
|
43
56
|
...failed
|
|
@@ -77,6 +90,25 @@ export async function RunView({
|
|
|
77
90
|
{pct(summary.total ? summary.right / summary.total : 0)})
|
|
78
91
|
</p>
|
|
79
92
|
<p className="readable text-sm text-muted">{summary.trust}</p>
|
|
93
|
+
{metrics?.levels && (
|
|
94
|
+
// The levels it was graded at: a nice-to-have miss didn't fail
|
|
95
|
+
// an answer. Saving other levels rescores it.
|
|
96
|
+
<p className="readable text-sm text-muted">
|
|
97
|
+
Graded with{" "}
|
|
98
|
+
{SEVERITY_ORDER.flatMap((level) => {
|
|
99
|
+
const names = suite.checks
|
|
100
|
+
.filter((c) => metrics.levels?.[c.key] === level)
|
|
101
|
+
.map((c) => c.label);
|
|
102
|
+
return names.length
|
|
103
|
+
? [
|
|
104
|
+
`${SEVERITY_LABEL[level].toLowerCase()}: ${names.join(", ")}`,
|
|
105
|
+
]
|
|
106
|
+
: [];
|
|
107
|
+
}).join("; ")}
|
|
108
|
+
.
|
|
109
|
+
<InfoTip term="checkLevels" id="run-levels" />
|
|
110
|
+
</p>
|
|
111
|
+
)}
|
|
80
112
|
{failed.length > 0 && (
|
|
81
113
|
<p className="readable text-sm text-bad">
|
|
82
114
|
{failed.length} {failed.length === 1 ? "answer" : "answers"}{" "}
|
|
@@ -96,7 +128,14 @@ export async function RunView({
|
|
|
96
128
|
<ul className="readable list-disc pl-5 text-sm">
|
|
97
129
|
{summary.problems.map((p) => (
|
|
98
130
|
<li key={p.key}>
|
|
99
|
-
{
|
|
131
|
+
{firstMiss.has(p.key) ? (
|
|
132
|
+
<a href={`#check-${p.key}`} className={LINK}>
|
|
133
|
+
{p.label}
|
|
134
|
+
</a>
|
|
135
|
+
) : (
|
|
136
|
+
p.label
|
|
137
|
+
)}
|
|
138
|
+
: failed {p.failed} of {p.of}
|
|
100
139
|
</li>
|
|
101
140
|
))}
|
|
102
141
|
</ul>
|
|
@@ -107,6 +146,7 @@ export async function RunView({
|
|
|
107
146
|
{ordered.map((o, i) => {
|
|
108
147
|
const checks = (o.scores as Check[] | null) ?? null;
|
|
109
148
|
const ok = allPassed(checks);
|
|
149
|
+
const anchors = [...firstMiss].filter(([, id]) => id === o.id);
|
|
110
150
|
return (
|
|
111
151
|
<div
|
|
112
152
|
key={o.id}
|
|
@@ -114,6 +154,9 @@ export async function RunView({
|
|
|
114
154
|
id={o.error && i === 0 ? "failed" : undefined}
|
|
115
155
|
className="scroll-mt-4 rounded-md bg-tint p-3 text-sm"
|
|
116
156
|
>
|
|
157
|
+
{anchors.map(([k]) => (
|
|
158
|
+
<span key={k} id={`check-${k}`} className="block scroll-mt-4" />
|
|
159
|
+
))}
|
|
117
160
|
<div className="flex justify-between gap-4">
|
|
118
161
|
<span className="font-medium">{titleOf(o.caseId)}</span>
|
|
119
162
|
<span
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MAX_LIMIT_USD,
|
|
3
|
+
spendingHalt,
|
|
4
|
+
spendingNeedsRoom,
|
|
5
|
+
usd,
|
|
6
|
+
type SpendingReading,
|
|
7
|
+
} from "../spending.js";
|
|
8
|
+
import type { EvalAppConfig } from "./app.js";
|
|
9
|
+
import { InfoTip, Submit, TextInput } from "./pieces.js";
|
|
10
|
+
import { WARN_PANEL } from "./format.js";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* What tests spent, and the stop, when it matters: over a limit, stopped,
|
|
14
|
+
* or a test running (so Stop is in reach). Otherwise it renders nothing,
|
|
15
|
+
* and spending lives in the page's menu. Needs your app's `spending`.
|
|
16
|
+
*/
|
|
17
|
+
export function SpendingAlert({
|
|
18
|
+
app,
|
|
19
|
+
reading,
|
|
20
|
+
}: {
|
|
21
|
+
app: EvalAppConfig;
|
|
22
|
+
/** The reading the page loaded; null: none to show. */
|
|
23
|
+
reading: SpendingReading | null;
|
|
24
|
+
}) {
|
|
25
|
+
if (!reading || !spendingNeedsRoom(reading)) return null;
|
|
26
|
+
const halt = spendingHalt(reading);
|
|
27
|
+
const stopped =
|
|
28
|
+
reading.stoppedUntil !== null && reading.stoppedUntil > new Date();
|
|
29
|
+
const { stopTests, allowTests } = app.actions;
|
|
30
|
+
const canStop = app.spending?.stopAll && stopTests;
|
|
31
|
+
const canAllow = app.spending?.allow && allowTests;
|
|
32
|
+
return (
|
|
33
|
+
<section
|
|
34
|
+
aria-label="Eval spending"
|
|
35
|
+
className={`flex flex-wrap items-start justify-between gap-3 rounded-lg p-4 text-sm ${WARN_PANEL}`}
|
|
36
|
+
>
|
|
37
|
+
<div className="readable space-y-1">
|
|
38
|
+
<p className="font-medium">
|
|
39
|
+
{halt
|
|
40
|
+
? stopped
|
|
41
|
+
? "Tests are stopped"
|
|
42
|
+
: "Tests are over a daily limit"
|
|
43
|
+
: `${reading.running} ${reading.running === 1 ? "test is" : "tests are"} running`}
|
|
44
|
+
<InfoTip term="spending" id="spending-alert" />
|
|
45
|
+
</p>
|
|
46
|
+
<p>
|
|
47
|
+
{halt ??
|
|
48
|
+
`${usd(reading.spentUsd)} spent in the last 24 hours, of a ${usd(reading.limitUsd)} daily limit. Stop them if they cost more than you meant.`}
|
|
49
|
+
</p>
|
|
50
|
+
</div>
|
|
51
|
+
{stopped
|
|
52
|
+
? canAllow && (
|
|
53
|
+
<form action={allowTests}>
|
|
54
|
+
<Submit variant="quiet">Allow tests</Submit>
|
|
55
|
+
</form>
|
|
56
|
+
)
|
|
57
|
+
: reading.running > 0 &&
|
|
58
|
+
canStop && (
|
|
59
|
+
<form action={stopTests}>
|
|
60
|
+
<Submit variant="quiet">Stop all tests</Submit>
|
|
61
|
+
</form>
|
|
62
|
+
)}
|
|
63
|
+
</section>
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* The Spending and daily limits drawer: the last 24 hours' spending, then
|
|
69
|
+
* one form for both limits with one Save. On a suite's page the reading
|
|
70
|
+
* has its feature; an empty feature limit means its default.
|
|
71
|
+
*/
|
|
72
|
+
export function SpendingForm({
|
|
73
|
+
app,
|
|
74
|
+
reading,
|
|
75
|
+
suite,
|
|
76
|
+
label,
|
|
77
|
+
}: {
|
|
78
|
+
app: EvalAppConfig;
|
|
79
|
+
reading: SpendingReading;
|
|
80
|
+
/** The suite whose page this is, for its feature's limit. */
|
|
81
|
+
suite?: string;
|
|
82
|
+
/** That feature's name, as the page shows it. */
|
|
83
|
+
label?: string;
|
|
84
|
+
}) {
|
|
85
|
+
const f = reading.feature;
|
|
86
|
+
const name = label ?? "This feature";
|
|
87
|
+
const action = app.actions.saveLimits;
|
|
88
|
+
return (
|
|
89
|
+
<div className="space-y-5">
|
|
90
|
+
<dl className="space-y-2">
|
|
91
|
+
<div className="flex justify-between gap-4">
|
|
92
|
+
<dt className="text-muted">All tests, last 24 hours</dt>
|
|
93
|
+
<dd className="font-medium tabular-nums">
|
|
94
|
+
{usd(reading.spentUsd)} of {usd(reading.limitUsd)}
|
|
95
|
+
</dd>
|
|
96
|
+
</div>
|
|
97
|
+
{f && (
|
|
98
|
+
<div className="flex justify-between gap-4">
|
|
99
|
+
<dt className="text-muted">{name}, last 24 hours</dt>
|
|
100
|
+
<dd className="font-medium tabular-nums">
|
|
101
|
+
{usd(f.spentUsd)}
|
|
102
|
+
{f.limitUsd === null
|
|
103
|
+
? ", no limit of its own"
|
|
104
|
+
: ` of ${usd(f.limitUsd)}`}
|
|
105
|
+
</dd>
|
|
106
|
+
</div>
|
|
107
|
+
)}
|
|
108
|
+
<div className="flex justify-between gap-4">
|
|
109
|
+
<dt className="text-muted">Running now</dt>
|
|
110
|
+
<dd className="tabular-nums">{reading.running}</dd>
|
|
111
|
+
</div>
|
|
112
|
+
</dl>
|
|
113
|
+
{action && (
|
|
114
|
+
// Keyed by the saved values, so the fields show them after a save.
|
|
115
|
+
<form
|
|
116
|
+
key={`${reading.limitUsd}-${f?.limitUsd ?? "none"}`}
|
|
117
|
+
action={action}
|
|
118
|
+
className="space-y-4"
|
|
119
|
+
>
|
|
120
|
+
{suite && f && (
|
|
121
|
+
<>
|
|
122
|
+
<input type="hidden" name="suite" value={suite} />
|
|
123
|
+
<input type="hidden" name="operation" value={f.operation} />
|
|
124
|
+
</>
|
|
125
|
+
)}
|
|
126
|
+
<MoneyField
|
|
127
|
+
id="limit-all"
|
|
128
|
+
name="allUsd"
|
|
129
|
+
label="Daily limit for all tests"
|
|
130
|
+
help="Every feature's tests together stop at this, over any 24 hours."
|
|
131
|
+
value={reading.limitUsd}
|
|
132
|
+
required
|
|
133
|
+
/>
|
|
134
|
+
{suite && f && (
|
|
135
|
+
<MoneyField
|
|
136
|
+
id="limit-feature"
|
|
137
|
+
name="featureUsd"
|
|
138
|
+
label={`Daily limit for ${name}`}
|
|
139
|
+
help={
|
|
140
|
+
f.defaultUsd === null
|
|
141
|
+
? "Leave it empty for none of its own: only the limit for all tests applies."
|
|
142
|
+
: `Leave it empty for its default, ${usd(f.defaultUsd)}.`
|
|
143
|
+
}
|
|
144
|
+
value={
|
|
145
|
+
f.limitUsd !== null && f.limitUsd !== f.defaultUsd
|
|
146
|
+
? f.limitUsd
|
|
147
|
+
: null
|
|
148
|
+
}
|
|
149
|
+
/>
|
|
150
|
+
)}
|
|
151
|
+
<Submit>Save limits</Submit>
|
|
152
|
+
</form>
|
|
153
|
+
)}
|
|
154
|
+
</div>
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** A dollar field: a $ before it, and the saved value to the cent. */
|
|
159
|
+
function MoneyField({
|
|
160
|
+
id,
|
|
161
|
+
name,
|
|
162
|
+
label,
|
|
163
|
+
help,
|
|
164
|
+
value,
|
|
165
|
+
required = false,
|
|
166
|
+
}: {
|
|
167
|
+
id: string;
|
|
168
|
+
name: string;
|
|
169
|
+
label: string;
|
|
170
|
+
help: string;
|
|
171
|
+
value: number | null;
|
|
172
|
+
required?: boolean;
|
|
173
|
+
}) {
|
|
174
|
+
return (
|
|
175
|
+
<div className="space-y-1">
|
|
176
|
+
<label htmlFor={id} className="block font-medium">
|
|
177
|
+
{label}
|
|
178
|
+
</label>
|
|
179
|
+
<div className="flex items-center rounded-md border border-line bg-card focus-within:border-accent">
|
|
180
|
+
<span aria-hidden className="pl-3 text-muted">
|
|
181
|
+
$
|
|
182
|
+
</span>
|
|
183
|
+
<TextInput
|
|
184
|
+
id={id}
|
|
185
|
+
name={name}
|
|
186
|
+
inputMode="decimal"
|
|
187
|
+
required={required}
|
|
188
|
+
defaultValue={value === null ? "" : value.toFixed(2)}
|
|
189
|
+
aria-describedby={`${id}-help`}
|
|
190
|
+
pattern="\$?[0-9,]*(\.[0-9]{0,2})?"
|
|
191
|
+
title={`Dollars, up to ${usd(MAX_LIMIT_USD)}`}
|
|
192
|
+
className="w-full rounded-md bg-transparent px-2 py-2 tabular-nums focus:outline-none"
|
|
193
|
+
/>
|
|
194
|
+
</div>
|
|
195
|
+
<p id={`${id}-help`} className="text-xs text-muted">
|
|
196
|
+
{help}
|
|
197
|
+
</p>
|
|
198
|
+
</div>
|
|
199
|
+
);
|
|
200
|
+
}
|