@crowandraven/evalkeeper 0.10.0 → 0.11.1
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/README.md +1 -2
- package/dist/ai-sdk/decide.d.ts +35 -0
- package/dist/ai-sdk/decide.js +36 -0
- package/dist/ai-sdk/decide.js.map +1 -0
- package/dist/ai-sdk/hash.d.ts +50 -0
- package/dist/ai-sdk/hash.js +59 -0
- package/dist/ai-sdk/hash.js.map +1 -0
- package/dist/ai-sdk/index.d.ts +15 -0
- package/dist/ai-sdk/index.js +16 -0
- package/dist/ai-sdk/index.js.map +1 -0
- package/dist/ai-sdk/judge.d.ts +69 -0
- package/dist/ai-sdk/judge.js +105 -0
- package/dist/ai-sdk/judge.js.map +1 -0
- package/dist/ai-sdk/usage.d.ts +18 -0
- package/dist/ai-sdk/usage.js +19 -0
- package/dist/ai-sdk/usage.js.map +1 -0
- package/dist/board.d.ts +5 -0
- package/dist/cli/addPages.d.ts +6 -1
- package/dist/cli/addPages.js +14 -8
- package/dist/cli/addPages.js.map +1 -1
- package/dist/cli/main.d.ts +19 -5
- package/dist/cli/main.js +100 -4
- package/dist/cli/main.js.map +1 -1
- package/dist/cli/migration.d.ts +95 -0
- package/dist/cli/migration.js +247 -0
- package/dist/cli/migration.js.map +1 -0
- package/dist/feedback.d.ts +1 -1
- package/dist/glossary.d.ts +8 -1
- package/dist/glossary.js +8 -1
- package/dist/glossary.js.map +1 -1
- package/dist/inInstructions.d.ts +1 -1
- package/dist/inInstructions.js +1 -1
- package/dist/next/RefreshWhile.d.ts +11 -0
- package/dist/next/RefreshWhile.js +28 -0
- package/dist/next/RefreshWhile.js.map +1 -0
- package/dist/next/actions.d.ts +14 -0
- package/dist/next/actions.js +332 -0
- package/dist/next/actions.js.map +1 -0
- package/dist/next/components.d.ts +9 -0
- package/dist/next/components.js +27 -0
- package/dist/next/components.js.map +1 -0
- package/dist/next/cron.d.ts +9 -0
- package/dist/next/cron.js +17 -0
- package/dist/next/cron.js.map +1 -0
- package/dist/next/index.d.ts +15 -0
- package/dist/next/index.js +16 -0
- package/dist/next/index.js.map +1 -0
- package/dist/next/pages.d.ts +70 -0
- package/dist/next/pages.js +77 -0
- package/dist/next/pages.js.map +1 -0
- package/dist/next/route.d.ts +19 -0
- package/dist/next/route.js +31 -0
- package/dist/next/route.js.map +1 -0
- package/dist/next/weekly.d.ts +20 -0
- package/dist/next/weekly.js +55 -0
- package/dist/next/weekly.js.map +1 -0
- package/dist/next/wiring.d.ts +19 -0
- package/dist/next/wiring.js +2 -0
- package/dist/next/wiring.js.map +1 -0
- package/dist/prisma/contracts.d.ts +74 -0
- package/dist/prisma/contracts.js +178 -0
- package/dist/prisma/contracts.js.map +1 -0
- package/dist/prisma/index.d.ts +423 -0
- package/dist/prisma/index.js +622 -0
- package/dist/prisma/index.js.map +1 -0
- package/dist/prisma/mapping.d.ts +63 -0
- package/dist/prisma/mapping.js +111 -0
- package/dist/prisma/mapping.js.map +1 -0
- package/dist/prisma/moveIn.d.ts +106 -0
- package/dist/prisma/moveIn.js +299 -0
- package/dist/prisma/moveIn.js.map +1 -0
- package/dist/prune.d.ts +45 -0
- package/dist/prune.js +32 -0
- package/dist/prune.js.map +1 -1
- package/dist/react/AddCase.d.ts +10 -0
- package/dist/react/AddCase.js +19 -0
- package/dist/react/AddCase.js.map +1 -0
- package/dist/react/AnswerKey.d.ts +22 -0
- package/dist/react/AnswerKey.js +83 -0
- package/dist/react/AnswerKey.js.map +1 -0
- package/dist/react/CaseMenu.d.ts +17 -0
- package/dist/react/CaseMenu.js +41 -0
- package/dist/react/CaseMenu.js.map +1 -0
- package/dist/react/CompareView.d.ts +14 -0
- package/dist/react/CompareView.js +51 -0
- package/dist/react/CompareView.js.map +1 -0
- package/dist/react/ConfirmAnswer.d.ts +13 -0
- package/dist/react/ConfirmAnswer.js +27 -0
- package/dist/react/ConfirmAnswer.js.map +1 -0
- package/dist/react/DisagreementChip.d.ts +10 -0
- package/dist/react/DisagreementChip.js +21 -0
- package/dist/react/DisagreementChip.js.map +1 -0
- package/dist/react/FeedbackView.d.ts +10 -0
- package/dist/react/FeedbackView.js +26 -0
- package/dist/react/FeedbackView.js.map +1 -0
- package/dist/react/Fields.d.ts +32 -0
- package/dist/react/Fields.js +33 -0
- package/dist/react/Fields.js.map +1 -0
- package/dist/react/HubSections.d.ts +78 -0
- package/dist/react/HubSections.js +124 -0
- package/dist/react/HubSections.js.map +1 -0
- package/dist/react/ModelMenu.d.ts +16 -0
- package/dist/react/ModelMenu.js +38 -0
- package/dist/react/ModelMenu.js.map +1 -0
- package/dist/react/RateView.d.ts +18 -0
- package/dist/react/RateView.js +30 -0
- package/dist/react/RateView.js.map +1 -0
- package/dist/react/ReadableOutput.d.ts +3 -0
- package/dist/react/ReadableOutput.js +50 -0
- package/dist/react/ReadableOutput.js.map +1 -0
- package/dist/react/RollBack.d.ts +17 -0
- package/dist/react/RollBack.js +26 -0
- package/dist/react/RollBack.js.map +1 -0
- package/dist/react/RunView.d.ts +9 -0
- package/dist/react/RunView.js +41 -0
- package/dist/react/RunView.js.map +1 -0
- package/dist/react/SettingsHistory.d.ts +33 -0
- package/dist/react/SettingsHistory.js +79 -0
- package/dist/react/SettingsHistory.js.map +1 -0
- package/dist/react/SideBySideView.d.ts +14 -0
- package/dist/react/SideBySideView.js +67 -0
- package/dist/react/SideBySideView.js.map +1 -0
- package/dist/react/SuiteSections.d.ts +111 -0
- package/dist/react/SuiteSections.js +224 -0
- package/dist/react/SuiteSections.js.map +1 -0
- package/dist/react/Tabs.d.ts +15 -0
- package/dist/react/Tabs.js +18 -0
- package/dist/react/Tabs.js.map +1 -0
- package/dist/react/Thumbs.d.ts +13 -0
- package/dist/react/Thumbs.js +54 -0
- package/dist/react/Thumbs.js.map +1 -0
- package/dist/react/WeeklyCheck.d.ts +11 -0
- package/dist/react/WeeklyCheck.js +19 -0
- package/dist/react/WeeklyCheck.js.map +1 -0
- package/dist/react/app.d.ts +118 -0
- package/dist/react/app.js +87 -0
- package/dist/react/app.js.map +1 -0
- package/dist/react/format.d.ts +27 -0
- package/dist/react/format.js +38 -0
- package/dist/react/format.js.map +1 -0
- package/dist/react/index.d.ts +31 -0
- package/dist/react/index.js +32 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/pieces.d.ts +191 -0
- package/dist/react/pieces.js +191 -0
- package/dist/react/pieces.js.map +1 -0
- package/dist/readCheck.d.ts +1 -1
- package/dist/runner.d.ts +62 -2
- package/dist/runner.js +123 -3
- package/dist/runner.js.map +1 -1
- package/dist/settings.d.ts +1 -1
- package/dist/store.d.ts +1 -1
- package/dist/suggest.d.ts +1 -1
- package/dist/suggest.js +7 -7
- package/dist/suggest.js.map +1 -1
- package/dist/suiteContract.d.ts +3 -3
- package/dist/suiteContract.js +20 -16
- package/dist/suiteContract.js.map +1 -1
- package/dist/testing.d.ts +2 -2
- package/dist/testing.js +1 -1
- package/dist/types.js +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +56 -6
- package/schema/evalkeeper.prisma +196 -0
- package/src/ai-sdk/decide.ts +57 -0
- package/src/ai-sdk/hash.ts +74 -0
- package/src/ai-sdk/index.ts +15 -0
- package/src/ai-sdk/judge.ts +163 -0
- package/src/ai-sdk/usage.ts +31 -0
- package/src/board.ts +5 -0
- package/src/cli/addPages.ts +15 -7
- package/src/cli/main.ts +135 -9
- package/src/cli/migration.ts +349 -0
- package/src/feedback.ts +1 -1
- package/src/glossary.ts +16 -2
- package/src/inInstructions.ts +1 -1
- package/{templates/components/evalkeeper → src/next}/RefreshWhile.tsx +2 -2
- package/src/next/actions.ts +389 -0
- package/src/next/components.ts +31 -0
- package/{templates/lib/evalkeeper/cronAuth.ts → src/next/cron.ts} +3 -0
- package/src/next/index.ts +15 -0
- package/src/next/pages.tsx +106 -0
- package/src/next/route.ts +35 -0
- package/src/next/weekly.ts +70 -0
- package/src/next/wiring.ts +18 -0
- package/src/prisma/contracts.ts +249 -0
- package/src/prisma/index.ts +1169 -0
- package/src/prisma/mapping.ts +147 -0
- package/src/prisma/moveIn.ts +502 -0
- package/src/prune.ts +77 -0
- package/{templates/components/evalkeeper → src/react}/AddCase.tsx +6 -6
- package/{templates/components/evalkeeper → src/react}/AnswerKey.tsx +92 -61
- package/{templates/components/evalkeeper → src/react}/CaseMenu.tsx +9 -8
- package/src/react/CompareView.tsx +270 -0
- package/{templates/components/evalkeeper → src/react}/ConfirmAnswer.tsx +6 -3
- package/{templates/components/evalkeeper → src/react}/DisagreementChip.tsx +2 -3
- package/src/react/FeedbackView.tsx +230 -0
- package/{templates/components/evalkeeper → src/react}/Fields.tsx +6 -6
- package/src/react/HubSections.tsx +446 -0
- package/src/react/ModelMenu.tsx +89 -0
- package/src/react/RateView.tsx +143 -0
- package/{templates/components/evalkeeper → src/react}/ReadableOutput.tsx +1 -1
- package/{templates/components/evalkeeper → src/react}/RollBack.tsx +9 -10
- package/src/react/RunView.tsx +151 -0
- package/{templates/components/evalkeeper → src/react}/SettingsHistory.tsx +16 -9
- package/src/react/SideBySideView.tsx +307 -0
- package/src/react/SuiteSections.tsx +925 -0
- package/src/react/Tabs.tsx +61 -0
- package/{templates/components/evalkeeper → src/react}/Thumbs.tsx +7 -6
- package/{templates/components/evalkeeper → src/react}/WeeklyCheck.tsx +31 -20
- package/src/react/app.ts +173 -0
- package/src/react/format.ts +45 -0
- package/src/react/index.ts +31 -0
- package/src/react/pieces.tsx +412 -0
- package/src/readCheck.ts +1 -1
- package/src/runner.ts +167 -3
- package/src/settings.ts +1 -1
- package/src/store.ts +1 -1
- package/src/suggest.ts +7 -7
- package/src/suiteContract.ts +35 -28
- package/src/testing.ts +2 -2
- package/src/types.ts +2 -2
- package/starter/index.ts +22 -8
- package/templates/app/api/cron/evals-weekly/route.ts +5 -15
- package/templates/app/evals/[suite]/compare/page.tsx +6 -383
- package/templates/app/evals/[suite]/page.tsx +7 -685
- package/templates/app/evals/[suite]/rate/page.tsx +6 -151
- package/templates/app/evals/[suite]/runs/[runId]/page.tsx +6 -174
- package/templates/app/evals/[suite]/side-by-side/page.tsx +6 -318
- package/templates/app/evals/feedback/page.tsx +6 -227
- package/templates/app/evals/layout.tsx +10 -0
- package/templates/app/evals/page.tsx +7 -397
- package/templates/lib/evalkeeper/actions.ts +34 -317
- package/templates/lib/evalkeeper/appComponents.tsx +21 -0
- package/templates/lib/evalkeeper/evals.ts +14 -0
- package/templates/lib/evalkeeper/paths.ts +2 -7
- package/templates/components/evalkeeper/Submit.tsx +0 -67
- package/templates/components/evalkeeper/Tip.tsx +0 -98
- package/templates/components/evalkeeper/ui.tsx +0 -105
- package/templates/lib/evalkeeper/time.ts +0 -4
- package/templates/lib/evalkeeper/weekly.ts +0 -74
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helpers for checking a Prisma store on a database that holds real rows:
|
|
3
|
+
* a read check that sees each value before the store fills in defaults,
|
|
4
|
+
* and a cleanup for scoped store contracts that deletes only the rows
|
|
5
|
+
* the scope names.
|
|
6
|
+
*/
|
|
7
|
+
import {
|
|
8
|
+
checkReads,
|
|
9
|
+
type ReadCheckOptions,
|
|
10
|
+
type ReadCheckReport,
|
|
11
|
+
type ReadRow,
|
|
12
|
+
} from "../index.js";
|
|
13
|
+
import type {
|
|
14
|
+
PrismaFeedbackMap,
|
|
15
|
+
PrismaSettingsMap,
|
|
16
|
+
PrismaStoreMap,
|
|
17
|
+
} from "./index.js";
|
|
18
|
+
import { Table, isRow, type Row } from "./mapping.js";
|
|
19
|
+
|
|
20
|
+
/** A model's delete, as any Prisma client has it. */
|
|
21
|
+
type Deleter = {
|
|
22
|
+
findMany(args: object): PromiseLike<unknown>;
|
|
23
|
+
deleteMany(args: object): PromiseLike<unknown>;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
function deleter(db: object, model: string): Deleter | null {
|
|
27
|
+
const d: unknown = Reflect.get(db, model);
|
|
28
|
+
if (typeof d !== "object" || d === null) return null;
|
|
29
|
+
return typeof Reflect.get(d, "findMany") === "function" &&
|
|
30
|
+
typeof Reflect.get(d, "deleteMany") === "function"
|
|
31
|
+
? // Trust boundary: a Prisma delegate, checked for both methods.
|
|
32
|
+
(d as Deleter)
|
|
33
|
+
: null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function counted(result: unknown): number {
|
|
37
|
+
if (!isRow(result)) return 0;
|
|
38
|
+
return typeof result.count === "number" ? result.count : 0;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** How many rows `deleteScopedRows` deleted, by table. */
|
|
42
|
+
export type ScopedRowsDeleted = {
|
|
43
|
+
cases: number;
|
|
44
|
+
answers: number;
|
|
45
|
+
tests: number;
|
|
46
|
+
outputs: number;
|
|
47
|
+
feedback: number;
|
|
48
|
+
versions: number;
|
|
49
|
+
live: number;
|
|
50
|
+
changes: number;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/** The maps for `deleteScopedRows`: the ones you pass the stores. */
|
|
54
|
+
export type ScopedRowsMaps = {
|
|
55
|
+
/** The map you pass `prismaStore`, if any. */
|
|
56
|
+
map?: PrismaStoreMap;
|
|
57
|
+
/** The map you pass `prismaSettingsStore`, if any. */
|
|
58
|
+
settingsMap?: PrismaSettingsMap;
|
|
59
|
+
/** The map you pass `prismaFeedbackStore`, if any. */
|
|
60
|
+
feedbackMap?: PrismaFeedbackMap;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Deletes the rows a scoped store contract wrote, and nothing else: cases
|
|
65
|
+
* and tests whose suite starts with `scope` (with their answers and
|
|
66
|
+
* outputs), and ratings, versions, live pointers, and changes whose
|
|
67
|
+
* feature starts with it. Each row's name is compared exactly in code,
|
|
68
|
+
* not by the database's pattern matching (which may ignore case), so a
|
|
69
|
+
* row whose name only looks like the scope stays. Tables your client
|
|
70
|
+
* doesn't have (feedback, settings) are skipped.
|
|
71
|
+
*
|
|
72
|
+
* @param db - Your Prisma client.
|
|
73
|
+
* @param scope - The prefix the contracts used, such as "contract-".
|
|
74
|
+
* @param maps - The maps you pass the stores, if your tables are your own.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```ts
|
|
78
|
+
* describeStoreContract("our tables", () => prismaStore(prisma, map), {
|
|
79
|
+
* scope: "contract-",
|
|
80
|
+
* cleanup: (scope) => deleteScopedRows(prisma, scope, { map }),
|
|
81
|
+
* });
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
export async function deleteScopedRows(
|
|
85
|
+
db: object,
|
|
86
|
+
scope: string,
|
|
87
|
+
maps: ScopedRowsMaps = {},
|
|
88
|
+
): Promise<ScopedRowsDeleted> {
|
|
89
|
+
if (!scope.trim())
|
|
90
|
+
throw new Error(
|
|
91
|
+
"deleteScopedRows needs a scope with some text in it: an empty one would match every row.",
|
|
92
|
+
);
|
|
93
|
+
const deleted: ScopedRowsDeleted = {
|
|
94
|
+
cases: 0,
|
|
95
|
+
answers: 0,
|
|
96
|
+
tests: 0,
|
|
97
|
+
outputs: 0,
|
|
98
|
+
feedback: 0,
|
|
99
|
+
versions: 0,
|
|
100
|
+
live: 0,
|
|
101
|
+
changes: 0,
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* The ids (by `key`) of a table's rows whose `field` starts with the
|
|
106
|
+
* scope, or null when the client has no such table.
|
|
107
|
+
*/
|
|
108
|
+
const scoped = async (
|
|
109
|
+
t: Table,
|
|
110
|
+
field: string,
|
|
111
|
+
key = "id",
|
|
112
|
+
): Promise<{ d: Deleter; ids: unknown[] } | null> => {
|
|
113
|
+
const d = deleter(db, t.model);
|
|
114
|
+
if (!d) return null;
|
|
115
|
+
const rows = t.ins(
|
|
116
|
+
await d.findMany({
|
|
117
|
+
where: t.out({ [field]: { startsWith: scope } }),
|
|
118
|
+
select: t.out({ [key]: true, [field]: true }),
|
|
119
|
+
}),
|
|
120
|
+
);
|
|
121
|
+
const ids = rows
|
|
122
|
+
.filter((r: Row) => {
|
|
123
|
+
const name = r[field];
|
|
124
|
+
return typeof name === "string" && name.startsWith(scope);
|
|
125
|
+
})
|
|
126
|
+
.map((r) => r[key]);
|
|
127
|
+
return { d, ids };
|
|
128
|
+
};
|
|
129
|
+
const remove = async (t: Table, d: Deleter, field: string, ids: unknown[]) =>
|
|
130
|
+
ids.length
|
|
131
|
+
? counted(await d.deleteMany({ where: t.out({ [field]: { in: ids } }) }))
|
|
132
|
+
: 0;
|
|
133
|
+
|
|
134
|
+
const m = maps.map ?? {};
|
|
135
|
+
const table = (
|
|
136
|
+
name: "evalCase" | "evalCaseLabel" | "evalRun" | "evalOutput",
|
|
137
|
+
) => new Table(name, m.models?.[name] ?? name, m.fields?.[name]);
|
|
138
|
+
const cases = table("evalCase");
|
|
139
|
+
const labels = table("evalCaseLabel");
|
|
140
|
+
const runs = table("evalRun");
|
|
141
|
+
const outputs = table("evalOutput");
|
|
142
|
+
const c = await scoped(cases, "suite");
|
|
143
|
+
const r = await scoped(runs, "suite");
|
|
144
|
+
const o = deleter(db, outputs.model);
|
|
145
|
+
const l = deleter(db, labels.model);
|
|
146
|
+
if (o && r) deleted.outputs += await remove(outputs, o, "runId", r.ids);
|
|
147
|
+
if (o && c) deleted.outputs += await remove(outputs, o, "caseId", c.ids);
|
|
148
|
+
if (l && c) deleted.answers = await remove(labels, l, "caseId", c.ids);
|
|
149
|
+
if (r) deleted.tests = await remove(runs, r.d, "id", r.ids);
|
|
150
|
+
if (c) deleted.cases = await remove(cases, c.d, "id", c.ids);
|
|
151
|
+
|
|
152
|
+
const fm = maps.feedbackMap ?? {};
|
|
153
|
+
const fb = new Table(
|
|
154
|
+
"evalFeedback",
|
|
155
|
+
fm.models?.evalFeedback ?? "evalFeedback",
|
|
156
|
+
fm.fields?.evalFeedback,
|
|
157
|
+
);
|
|
158
|
+
const f = await scoped(fb, "operation");
|
|
159
|
+
if (f) deleted.feedback = await remove(fb, f.d, "id", f.ids);
|
|
160
|
+
|
|
161
|
+
const s = maps.settingsMap ?? {};
|
|
162
|
+
const settings = (
|
|
163
|
+
name: "evalSettingsVersion" | "evalSettingsLive" | "evalSettingsChange",
|
|
164
|
+
) => new Table(name, s.models?.[name] ?? name, s.fields?.[name]);
|
|
165
|
+
const changes = settings("evalSettingsChange");
|
|
166
|
+
const lives = settings("evalSettingsLive");
|
|
167
|
+
const versions = settings("evalSettingsVersion");
|
|
168
|
+
// Changes and live pointers point at versions, so they go first.
|
|
169
|
+
const ch = await scoped(changes, "operation");
|
|
170
|
+
if (ch) deleted.changes = await remove(changes, ch.d, "id", ch.ids);
|
|
171
|
+
const lv = await scoped(lives, "operation", "operation");
|
|
172
|
+
if (lv) deleted.live = await remove(lives, lv.d, "operation", lv.ids);
|
|
173
|
+
const vs = await scoped(versions, "operation");
|
|
174
|
+
if (vs) deleted.versions = await remove(versions, vs.d, "id", vs.ids);
|
|
175
|
+
return deleted;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* A read-only check of your eval tables through a store's map: each
|
|
180
|
+
* suite's cases, answers, tests, and outputs, read as the table holds
|
|
181
|
+
* them, with anything that doesn't parse listed by row (an unknown
|
|
182
|
+
* status, a cost that isn't a number, a missing column), with counts.
|
|
183
|
+
* The store itself reads such a value as a default (an unknown status as
|
|
184
|
+
* a known one), so this is how to see them. With suites (not just keys),
|
|
185
|
+
* each case's input and answer is also checked against the suite's
|
|
186
|
+
* schemas. It only reads.
|
|
187
|
+
*
|
|
188
|
+
* @param db - Your Prisma client.
|
|
189
|
+
* @param map - The map you pass `prismaStore` (`{}` for Evalkeeper's own tables).
|
|
190
|
+
* @param opts - Which suites, and how many tests of each.
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
193
|
+
* ```ts
|
|
194
|
+
* import { prismaReadCheck } from "@crowandraven/evalkeeper/prisma";
|
|
195
|
+
* import { readCheckSummary } from "../index.js";
|
|
196
|
+
*
|
|
197
|
+
* const report = await prismaReadCheck(prisma, map, { suites: SUITES });
|
|
198
|
+
* console.log(readCheckSummary(report).join("\n"));
|
|
199
|
+
* ```
|
|
200
|
+
*/
|
|
201
|
+
export function prismaReadCheck(
|
|
202
|
+
db: object,
|
|
203
|
+
map: PrismaStoreMap,
|
|
204
|
+
opts: ReadCheckOptions,
|
|
205
|
+
): Promise<ReadCheckReport> {
|
|
206
|
+
const table = (
|
|
207
|
+
name: "evalCase" | "evalCaseLabel" | "evalRun" | "evalOutput",
|
|
208
|
+
) => new Table(name, map.models?.[name] ?? name, map.fields?.[name]);
|
|
209
|
+
const cases = table("evalCase");
|
|
210
|
+
const labels = table("evalCaseLabel");
|
|
211
|
+
const runs = table("evalRun");
|
|
212
|
+
const outputs = table("evalOutput");
|
|
213
|
+
const labelsOf = cases.col("labels") ?? "labels";
|
|
214
|
+
return checkReads(
|
|
215
|
+
{
|
|
216
|
+
async cases(suite) {
|
|
217
|
+
const rows = cases.ins(
|
|
218
|
+
await cases.on(db).findMany({
|
|
219
|
+
where: cases.out({ suite }),
|
|
220
|
+
include: { [labelsOf]: true },
|
|
221
|
+
orderBy: cases.out({ createdAt: "asc" }),
|
|
222
|
+
}),
|
|
223
|
+
);
|
|
224
|
+
return rows.map((row): ReadRow =>
|
|
225
|
+
Array.isArray(row.labels)
|
|
226
|
+
? { ...row, labels: labels.ins(row.labels) }
|
|
227
|
+
: row,
|
|
228
|
+
);
|
|
229
|
+
},
|
|
230
|
+
async tests(suite, limit) {
|
|
231
|
+
return runs.ins(
|
|
232
|
+
await runs.on(db).findMany({
|
|
233
|
+
where: runs.out({ suite }),
|
|
234
|
+
orderBy: runs.out({ startedAt: "desc" }),
|
|
235
|
+
...(limit === undefined ? {} : { take: limit }),
|
|
236
|
+
}),
|
|
237
|
+
);
|
|
238
|
+
},
|
|
239
|
+
async outputs(ids) {
|
|
240
|
+
return outputs.ins(
|
|
241
|
+
await outputs.on(db).findMany({
|
|
242
|
+
where: outputs.out({ runId: { in: [...ids] } }),
|
|
243
|
+
}),
|
|
244
|
+
);
|
|
245
|
+
},
|
|
246
|
+
},
|
|
247
|
+
opts,
|
|
248
|
+
);
|
|
249
|
+
}
|