@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,77 @@
|
|
|
1
|
+
import { notFound } from "next/navigation.js";
|
|
2
|
+
import { HubPage } from "../react/HubSections.js";
|
|
3
|
+
import { SuitePage } from "../react/SuiteSections.js";
|
|
4
|
+
import { RunView } from "../react/RunView.js";
|
|
5
|
+
import { CompareView } from "../react/CompareView.js";
|
|
6
|
+
import { SideBySideView } from "../react/SideBySideView.js";
|
|
7
|
+
import { RateView } from "../react/RateView.js";
|
|
8
|
+
import { FeedbackView } from "../react/FeedbackView.js";
|
|
9
|
+
/**
|
|
10
|
+
* Evalkeeper's pages for the Next.js App Router. Each route file `add
|
|
11
|
+
* pages` writes exports one of these as its page and title. Every page
|
|
12
|
+
* calls `requireAdmin` first, and a suite or test that isn't there is a
|
|
13
|
+
* 404.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* // app/evals/[suite]/page.tsx
|
|
18
|
+
* import { pages } from "@/lib/evalkeeper/evals";
|
|
19
|
+
* export const dynamic = "force-dynamic";
|
|
20
|
+
* export const generateMetadata = pages.suite.generateMetadata;
|
|
21
|
+
* export default pages.suite.Page;
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @param app - Your screens' configuration, from `defineEvals`.
|
|
25
|
+
* @param requireAdmin - Who may use the pages; it throws for anyone else.
|
|
26
|
+
*/
|
|
27
|
+
export function evalPages(app, requireAdmin) {
|
|
28
|
+
/** A page of one suite, titled "{what}: {suite}". */
|
|
29
|
+
function suitePage(what, draw) {
|
|
30
|
+
return {
|
|
31
|
+
Page: async ({ params, searchParams }) => {
|
|
32
|
+
const admin = await requireAdmin();
|
|
33
|
+
const view = await draw(await params, await searchParams, admin);
|
|
34
|
+
if (!view)
|
|
35
|
+
notFound();
|
|
36
|
+
return view;
|
|
37
|
+
},
|
|
38
|
+
generateMetadata: async ({ params }) => {
|
|
39
|
+
const label = app.suiteByKey[(await params).suite]?.label ?? "Evals";
|
|
40
|
+
return { title: what ? `${what}: ${label}` : `Evals: ${label}` };
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
/** The hub: where each suite stands and what needs attention. */
|
|
46
|
+
hub: {
|
|
47
|
+
Page: async () => {
|
|
48
|
+
await requireAdmin();
|
|
49
|
+
return HubPage({ app });
|
|
50
|
+
},
|
|
51
|
+
generateMetadata: async () => {
|
|
52
|
+
return { title: "Evals" };
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
/** A suite: its models, suggestion, versions, checks, and answer key. */
|
|
56
|
+
suite: suitePage("", (p) => SuitePage({ app, suite: p.suite })),
|
|
57
|
+
/** One test: every answer, with what each check found. */
|
|
58
|
+
run: suitePage("Test", (p) => RunView({ app, suite: p.suite, runId: p.runId })),
|
|
59
|
+
/** Two tests compared: the verdict, each check, and where they differ. */
|
|
60
|
+
compare: suitePage("Compare", (p, search) => CompareView({ app, suite: p.suite, search })),
|
|
61
|
+
/** Two tests' answers where they differ, side by side. */
|
|
62
|
+
sideBySide: suitePage("Side by side", (p, search) => SideBySideView({ app, suite: p.suite, search })),
|
|
63
|
+
/** Blind rating: one case at a time, by its input only. */
|
|
64
|
+
rate: suitePage("Rate blind", (p, _search, rater) => RateView({ app, suite: p.suite, rater })),
|
|
65
|
+
/** Thumbs up and down, and what to do with each. */
|
|
66
|
+
feedback: {
|
|
67
|
+
Page: async () => {
|
|
68
|
+
await requireAdmin();
|
|
69
|
+
return FeedbackView({ app });
|
|
70
|
+
},
|
|
71
|
+
generateMetadata: async () => {
|
|
72
|
+
return { title: "Feedback: Evals" };
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=pages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pages.js","sourceRoot":"","sources":["../../src/next/pages.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAG9C,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAYxD;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,SAAS,CACvB,GAAkB,EAClB,YAAsC;IAEtC,qDAAqD;IACrD,SAAS,SAAS,CAChB,IAAY,EACZ,IAAoE;QAEpE,OAAO;YACL,IAAI,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,EAAE,EAAE;gBACvC,MAAM,KAAK,GAAG,MAAM,YAAY,EAAE,CAAC;gBACnC,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,MAAM,EAAE,MAAM,YAAY,EAAE,KAAK,CAAC,CAAC;gBACjE,IAAI,CAAC,IAAI;oBAAE,QAAQ,EAAE,CAAC;gBACtB,OAAO,IAAI,CAAC;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AU,EAAE,SAAS,CAAoB,cAAc,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CACrE,cAAc,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC,CAChD;QACD,2DAA2D;QAC3D,IAAI,EAAE,SAAS,CAAoB,YAAY,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,CACrE,QAAQ,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,CAAC,CACzC;QACD,oDAAoD;QACpD,QAAQ,EAAE;YACR,IAAI,EAAE,KAAK,IAAI,EAAE;gBACf,MAAM,YAAY,EAAE,CAAC;gBACrB,OAAO,YAAY,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;YAC/B,CAAC;YACD,gBAAgB,EAAE,KAAK,IAAI,EAAE;gBAC3B,OAAO,EAAE,KAAK,EAAE,iBAAiB,EAAE,CAAC;YACtC,CAAC;SACyB;KAC7B,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { EvalWiring } from "./wiring.js";
|
|
2
|
+
/**
|
|
3
|
+
* The weekly check's cron route: answers at once, then runs each suite's
|
|
4
|
+
* quick set on its live model after the response. Call it with
|
|
5
|
+
* "Authorization: Bearer $CRON_SECRET"; anything else gets a 401.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* // app/api/cron/evals-weekly/route.ts
|
|
10
|
+
* import { weeklyCronRoute } from "@crowandraven/evalkeeper/next";
|
|
11
|
+
* import { wiring } from "@/lib/evalkeeper";
|
|
12
|
+
* export const maxDuration = 300;
|
|
13
|
+
* export const GET = weeklyCronRoute(wiring);
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @param w - Your wiring: its runner, store, and suites.
|
|
17
|
+
* @param secret - The cron secret; `process.env.CRON_SECRET` by default.
|
|
18
|
+
*/
|
|
19
|
+
export declare function weeklyCronRoute(w: Pick<EvalWiring, "runner" | "store" | "suites">, secret?: () => string | undefined): (request: Request) => Promise<Response>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { after } from "next/server.js";
|
|
2
|
+
import { isAuthorizedCron } from "./cron.js";
|
|
3
|
+
import { weeklyCheck } from "./weekly.js";
|
|
4
|
+
/**
|
|
5
|
+
* The weekly check's cron route: answers at once, then runs each suite's
|
|
6
|
+
* quick set on its live model after the response. Call it with
|
|
7
|
+
* "Authorization: Bearer $CRON_SECRET"; anything else gets a 401.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* // app/api/cron/evals-weekly/route.ts
|
|
12
|
+
* import { weeklyCronRoute } from "@crowandraven/evalkeeper/next";
|
|
13
|
+
* import { wiring } from "@/lib/evalkeeper";
|
|
14
|
+
* export const maxDuration = 300;
|
|
15
|
+
* export const GET = weeklyCronRoute(wiring);
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @param w - Your wiring: its runner, store, and suites.
|
|
19
|
+
* @param secret - The cron secret; `process.env.CRON_SECRET` by default.
|
|
20
|
+
*/
|
|
21
|
+
export function weeklyCronRoute(w, secret = () => process.env.CRON_SECRET) {
|
|
22
|
+
const weekly = weeklyCheck(w);
|
|
23
|
+
return async function GET(request) {
|
|
24
|
+
if (!isAuthorizedCron(request.headers.get("authorization"), secret()))
|
|
25
|
+
return Response.json({ error: "Unauthorized" }, { status: 401 });
|
|
26
|
+
const ids = await weekly.start();
|
|
27
|
+
after(() => weekly.run(ids));
|
|
28
|
+
return Response.json({ started: ids.length }, { status: 202 });
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=route.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route.js","sourceRoot":"","sources":["../../src/next/route.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG1C;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,eAAe,CAC7B,CAAkD,EAClD,SAAmC,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW;IAEhE,MAAM,MAAM,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;IAC9B,OAAO,KAAK,UAAU,GAAG,CAAC,OAAgB;QACxC,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;YACnE,OAAO,QAAQ,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,cAAc,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;QACnE,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;QACjC,KAAK,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;QAC7B,OAAO,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;IACjE,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { EvalWiring } from "./wiring.js";
|
|
2
|
+
/** The weekly check, in the two halves a request can split it into. */
|
|
3
|
+
export type WeeklyCheck = {
|
|
4
|
+
/**
|
|
5
|
+
* Brings attack cases up to date with newly confirmed answers, then
|
|
6
|
+
* records each suite's test on its live model, so the hub shows them
|
|
7
|
+
* running. Returns the tests' ids for `run`.
|
|
8
|
+
*/
|
|
9
|
+
start: () => Promise<string[]>;
|
|
10
|
+
/** Drafts cases from the week's activity, then answers the tests. */
|
|
11
|
+
run: (ids: string[]) => Promise<void>;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* The weekly check: each suite's quick set on its live model. On a
|
|
15
|
+
* platform with a request limit, give the runner `requestLimitMs` and
|
|
16
|
+
* `continueRun` so a slow suite carries on in a fresh request.
|
|
17
|
+
*
|
|
18
|
+
* @param w - Your wiring: its runner, store, and suites.
|
|
19
|
+
*/
|
|
20
|
+
export declare function weeklyCheck(w: Pick<EvalWiring, "runner" | "store" | "suites">): WeeklyCheck;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { isInjectionSuite } from "../types.js";
|
|
2
|
+
import { injectionCases } from "../suites/injection.js";
|
|
3
|
+
/**
|
|
4
|
+
* The weekly check: each suite's quick set on its live model. On a
|
|
5
|
+
* platform with a request limit, give the runner `requestLimitMs` and
|
|
6
|
+
* `continueRun` so a slow suite carries on in a fresh request.
|
|
7
|
+
*
|
|
8
|
+
* @param w - Your wiring: its runner, store, and suites.
|
|
9
|
+
*/
|
|
10
|
+
export function weeklyCheck(w) {
|
|
11
|
+
/**
|
|
12
|
+
* New draft cases from the week's activity, for suites that can draft
|
|
13
|
+
* them. One suite failing doesn't stop the rest.
|
|
14
|
+
*/
|
|
15
|
+
async function draft() {
|
|
16
|
+
for (const suite of w.suites) {
|
|
17
|
+
if (!suite.draftFromActivity)
|
|
18
|
+
continue;
|
|
19
|
+
try {
|
|
20
|
+
await w.runner.draftFromActivity(suite.key);
|
|
21
|
+
}
|
|
22
|
+
catch (e) {
|
|
23
|
+
console.error(`Drafting from activity failed for ${suite.key}`, e);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
async start() {
|
|
29
|
+
for (const suite of w.suites)
|
|
30
|
+
if (isInjectionSuite(suite))
|
|
31
|
+
// Trust boundary: isInjectionSuite means injectionSuite made it.
|
|
32
|
+
await injectionCases(w.store, suite);
|
|
33
|
+
const ids = [];
|
|
34
|
+
for (const suite of w.suites) {
|
|
35
|
+
const id = await w.runner.startDriftCheck(suite.key);
|
|
36
|
+
if (id)
|
|
37
|
+
ids.push(id);
|
|
38
|
+
}
|
|
39
|
+
return ids;
|
|
40
|
+
},
|
|
41
|
+
async run(ids) {
|
|
42
|
+
// Drafts nobody reviewed in a month go, so the review queue stays
|
|
43
|
+
// short; the weekly job's other half adds this week's.
|
|
44
|
+
for (const suite of w.suites)
|
|
45
|
+
await w.runner.retireStaleDrafts(suite.key).catch((e) => {
|
|
46
|
+
console.error(`Retiring old drafts failed for ${suite.key}`, e);
|
|
47
|
+
});
|
|
48
|
+
await draft();
|
|
49
|
+
// runEval never throws: a suite that fails says why on its own test.
|
|
50
|
+
for (const id of ids)
|
|
51
|
+
await w.runner.runEval(id, { fresh: true });
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=weekly.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"weekly.js","sourceRoot":"","sources":["../../src/next/weekly.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAexD;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CACzB,CAAkD;IAElD;;;OAGG;IACH,KAAK,UAAU,KAAK;QAClB,KAAK,MAAM,KAAK,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC;YAC7B,IAAI,CAAC,KAAK,CAAC,iBAAiB;gBAAE,SAAS;YACvC,IAAI,CAAC;gBACH,MAAM,CAAC,CAAC,MAAM,CAAC,iBAAiB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAC9C,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,OAAO,CAAC,KAAK,CAAC,qCAAqC,KAAK,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC;YACrE,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO;QACL,KAAK,CAAC,KAAK;YACT,KAAK,MAAM,KAAK,IAAI,CAAC,CAAC,MAAM;gBAC1B,IAAI,gBAAgB,CAAC,KAAK,CAAC;oBACzB,iEAAiE;oBACjE,MAAM,cAAc,CAClB,CAAC,CAAC,KAAK,EACP,KAAwD,CACzD,CAAC;YACN,MAAM,GAAG,GAAa,EAAE,CAAC;YACzB,KAAK,MAAM,KAAK,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC;gBAC7B,MAAM,EAAE,GAAG,MAAM,CAAC,CAAC,MAAM,CAAC,eAAe,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBACrD,IAAI,EAAE;oBAAE,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACvB,CAAC;YACD,OAAO,GAAG,CAAC;QACb,CAAC;QACD,KAAK,CAAC,GAAG,CAAC,GAAG;YACX,kEAAkE;YAClE,uDAAuD;YACvD,KAAK,MAAM,KAAK,IAAI,CAAC,CAAC,MAAM;gBAC1B,MAAM,CAAC,CAAC,MAAM,CAAC,iBAAiB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAU,EAAE,EAAE;oBAC/D,OAAO,CAAC,KAAK,CAAC,kCAAkC,KAAK,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC;gBAClE,CAAC,CAAC,CAAC;YACL,MAAM,KAAK,EAAE,CAAC;YACd,qEAAqE;YACrE,KAAK,MAAM,EAAE,IAAI,GAAG;gBAAE,MAAM,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QACpE,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { EvalApp } from "../react/app.js";
|
|
2
|
+
/** Who's using the eval pages, as your `requireAdmin` returns them. */
|
|
3
|
+
export type EvalAdmin = {
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Your app's Evalkeeper wiring, as the Next.js glue reads it: everything
|
|
9
|
+
* the screens need except their actions (the glue makes those), and who
|
|
10
|
+
* may use the pages.
|
|
11
|
+
*/
|
|
12
|
+
export type EvalWiring = Omit<EvalApp, "actions"> & {
|
|
13
|
+
/**
|
|
14
|
+
* Who may use the eval pages. Every page and action calls it first:
|
|
15
|
+
* throw when the person isn't an admin, and return who they are, which
|
|
16
|
+
* is recorded as who made each change.
|
|
17
|
+
*/
|
|
18
|
+
requireAdmin: () => Promise<EvalAdmin>;
|
|
19
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wiring.js","sourceRoot":"","sources":["../../src/next/wiring.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,74 @@
|
|
|
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 { type ReadCheckOptions, type ReadCheckReport } from "../index.js";
|
|
8
|
+
import type { PrismaFeedbackMap, PrismaSettingsMap, PrismaStoreMap } from "./index.js";
|
|
9
|
+
/** How many rows `deleteScopedRows` deleted, by table. */
|
|
10
|
+
export type ScopedRowsDeleted = {
|
|
11
|
+
cases: number;
|
|
12
|
+
answers: number;
|
|
13
|
+
tests: number;
|
|
14
|
+
outputs: number;
|
|
15
|
+
feedback: number;
|
|
16
|
+
versions: number;
|
|
17
|
+
live: number;
|
|
18
|
+
changes: number;
|
|
19
|
+
};
|
|
20
|
+
/** The maps for `deleteScopedRows`: the ones you pass the stores. */
|
|
21
|
+
export type ScopedRowsMaps = {
|
|
22
|
+
/** The map you pass `prismaStore`, if any. */
|
|
23
|
+
map?: PrismaStoreMap;
|
|
24
|
+
/** The map you pass `prismaSettingsStore`, if any. */
|
|
25
|
+
settingsMap?: PrismaSettingsMap;
|
|
26
|
+
/** The map you pass `prismaFeedbackStore`, if any. */
|
|
27
|
+
feedbackMap?: PrismaFeedbackMap;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Deletes the rows a scoped store contract wrote, and nothing else: cases
|
|
31
|
+
* and tests whose suite starts with `scope` (with their answers and
|
|
32
|
+
* outputs), and ratings, versions, live pointers, and changes whose
|
|
33
|
+
* feature starts with it. Each row's name is compared exactly in code,
|
|
34
|
+
* not by the database's pattern matching (which may ignore case), so a
|
|
35
|
+
* row whose name only looks like the scope stays. Tables your client
|
|
36
|
+
* doesn't have (feedback, settings) are skipped.
|
|
37
|
+
*
|
|
38
|
+
* @param db - Your Prisma client.
|
|
39
|
+
* @param scope - The prefix the contracts used, such as "contract-".
|
|
40
|
+
* @param maps - The maps you pass the stores, if your tables are your own.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* describeStoreContract("our tables", () => prismaStore(prisma, map), {
|
|
45
|
+
* scope: "contract-",
|
|
46
|
+
* cleanup: (scope) => deleteScopedRows(prisma, scope, { map }),
|
|
47
|
+
* });
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export declare function deleteScopedRows(db: object, scope: string, maps?: ScopedRowsMaps): Promise<ScopedRowsDeleted>;
|
|
51
|
+
/**
|
|
52
|
+
* A read-only check of your eval tables through a store's map: each
|
|
53
|
+
* suite's cases, answers, tests, and outputs, read as the table holds
|
|
54
|
+
* them, with anything that doesn't parse listed by row (an unknown
|
|
55
|
+
* status, a cost that isn't a number, a missing column), with counts.
|
|
56
|
+
* The store itself reads such a value as a default (an unknown status as
|
|
57
|
+
* a known one), so this is how to see them. With suites (not just keys),
|
|
58
|
+
* each case's input and answer is also checked against the suite's
|
|
59
|
+
* schemas. It only reads.
|
|
60
|
+
*
|
|
61
|
+
* @param db - Your Prisma client.
|
|
62
|
+
* @param map - The map you pass `prismaStore` (`{}` for Evalkeeper's own tables).
|
|
63
|
+
* @param opts - Which suites, and how many tests of each.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* import { prismaReadCheck } from "@crowandraven/evalkeeper/prisma";
|
|
68
|
+
* import { readCheckSummary } from "../index.js";
|
|
69
|
+
*
|
|
70
|
+
* const report = await prismaReadCheck(prisma, map, { suites: SUITES });
|
|
71
|
+
* console.log(readCheckSummary(report).join("\n"));
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export declare function prismaReadCheck(db: object, map: PrismaStoreMap, opts: ReadCheckOptions): Promise<ReadCheckReport>;
|
|
@@ -0,0 +1,178 @@
|
|
|
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 { checkReads, } from "../index.js";
|
|
8
|
+
import { Table, isRow } from "./mapping.js";
|
|
9
|
+
function deleter(db, model) {
|
|
10
|
+
const d = Reflect.get(db, model);
|
|
11
|
+
if (typeof d !== "object" || d === null)
|
|
12
|
+
return null;
|
|
13
|
+
return typeof Reflect.get(d, "findMany") === "function" &&
|
|
14
|
+
typeof Reflect.get(d, "deleteMany") === "function"
|
|
15
|
+
? // Trust boundary: a Prisma delegate, checked for both methods.
|
|
16
|
+
d
|
|
17
|
+
: null;
|
|
18
|
+
}
|
|
19
|
+
function counted(result) {
|
|
20
|
+
if (!isRow(result))
|
|
21
|
+
return 0;
|
|
22
|
+
return typeof result.count === "number" ? result.count : 0;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Deletes the rows a scoped store contract wrote, and nothing else: cases
|
|
26
|
+
* and tests whose suite starts with `scope` (with their answers and
|
|
27
|
+
* outputs), and ratings, versions, live pointers, and changes whose
|
|
28
|
+
* feature starts with it. Each row's name is compared exactly in code,
|
|
29
|
+
* not by the database's pattern matching (which may ignore case), so a
|
|
30
|
+
* row whose name only looks like the scope stays. Tables your client
|
|
31
|
+
* doesn't have (feedback, settings) are skipped.
|
|
32
|
+
*
|
|
33
|
+
* @param db - Your Prisma client.
|
|
34
|
+
* @param scope - The prefix the contracts used, such as "contract-".
|
|
35
|
+
* @param maps - The maps you pass the stores, if your tables are your own.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* describeStoreContract("our tables", () => prismaStore(prisma, map), {
|
|
40
|
+
* scope: "contract-",
|
|
41
|
+
* cleanup: (scope) => deleteScopedRows(prisma, scope, { map }),
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export async function deleteScopedRows(db, scope, maps = {}) {
|
|
46
|
+
if (!scope.trim())
|
|
47
|
+
throw new Error("deleteScopedRows needs a scope with some text in it: an empty one would match every row.");
|
|
48
|
+
const deleted = {
|
|
49
|
+
cases: 0,
|
|
50
|
+
answers: 0,
|
|
51
|
+
tests: 0,
|
|
52
|
+
outputs: 0,
|
|
53
|
+
feedback: 0,
|
|
54
|
+
versions: 0,
|
|
55
|
+
live: 0,
|
|
56
|
+
changes: 0,
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* The ids (by `key`) of a table's rows whose `field` starts with the
|
|
60
|
+
* scope, or null when the client has no such table.
|
|
61
|
+
*/
|
|
62
|
+
const scoped = async (t, field, key = "id") => {
|
|
63
|
+
const d = deleter(db, t.model);
|
|
64
|
+
if (!d)
|
|
65
|
+
return null;
|
|
66
|
+
const rows = t.ins(await d.findMany({
|
|
67
|
+
where: t.out({ [field]: { startsWith: scope } }),
|
|
68
|
+
select: t.out({ [key]: true, [field]: true }),
|
|
69
|
+
}));
|
|
70
|
+
const ids = rows
|
|
71
|
+
.filter((r) => {
|
|
72
|
+
const name = r[field];
|
|
73
|
+
return typeof name === "string" && name.startsWith(scope);
|
|
74
|
+
})
|
|
75
|
+
.map((r) => r[key]);
|
|
76
|
+
return { d, ids };
|
|
77
|
+
};
|
|
78
|
+
const remove = async (t, d, field, ids) => ids.length
|
|
79
|
+
? counted(await d.deleteMany({ where: t.out({ [field]: { in: ids } }) }))
|
|
80
|
+
: 0;
|
|
81
|
+
const m = maps.map ?? {};
|
|
82
|
+
const table = (name) => new Table(name, m.models?.[name] ?? name, m.fields?.[name]);
|
|
83
|
+
const cases = table("evalCase");
|
|
84
|
+
const labels = table("evalCaseLabel");
|
|
85
|
+
const runs = table("evalRun");
|
|
86
|
+
const outputs = table("evalOutput");
|
|
87
|
+
const c = await scoped(cases, "suite");
|
|
88
|
+
const r = await scoped(runs, "suite");
|
|
89
|
+
const o = deleter(db, outputs.model);
|
|
90
|
+
const l = deleter(db, labels.model);
|
|
91
|
+
if (o && r)
|
|
92
|
+
deleted.outputs += await remove(outputs, o, "runId", r.ids);
|
|
93
|
+
if (o && c)
|
|
94
|
+
deleted.outputs += await remove(outputs, o, "caseId", c.ids);
|
|
95
|
+
if (l && c)
|
|
96
|
+
deleted.answers = await remove(labels, l, "caseId", c.ids);
|
|
97
|
+
if (r)
|
|
98
|
+
deleted.tests = await remove(runs, r.d, "id", r.ids);
|
|
99
|
+
if (c)
|
|
100
|
+
deleted.cases = await remove(cases, c.d, "id", c.ids);
|
|
101
|
+
const fm = maps.feedbackMap ?? {};
|
|
102
|
+
const fb = new Table("evalFeedback", fm.models?.evalFeedback ?? "evalFeedback", fm.fields?.evalFeedback);
|
|
103
|
+
const f = await scoped(fb, "operation");
|
|
104
|
+
if (f)
|
|
105
|
+
deleted.feedback = await remove(fb, f.d, "id", f.ids);
|
|
106
|
+
const s = maps.settingsMap ?? {};
|
|
107
|
+
const settings = (name) => new Table(name, s.models?.[name] ?? name, s.fields?.[name]);
|
|
108
|
+
const changes = settings("evalSettingsChange");
|
|
109
|
+
const lives = settings("evalSettingsLive");
|
|
110
|
+
const versions = settings("evalSettingsVersion");
|
|
111
|
+
// Changes and live pointers point at versions, so they go first.
|
|
112
|
+
const ch = await scoped(changes, "operation");
|
|
113
|
+
if (ch)
|
|
114
|
+
deleted.changes = await remove(changes, ch.d, "id", ch.ids);
|
|
115
|
+
const lv = await scoped(lives, "operation", "operation");
|
|
116
|
+
if (lv)
|
|
117
|
+
deleted.live = await remove(lives, lv.d, "operation", lv.ids);
|
|
118
|
+
const vs = await scoped(versions, "operation");
|
|
119
|
+
if (vs)
|
|
120
|
+
deleted.versions = await remove(versions, vs.d, "id", vs.ids);
|
|
121
|
+
return deleted;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* A read-only check of your eval tables through a store's map: each
|
|
125
|
+
* suite's cases, answers, tests, and outputs, read as the table holds
|
|
126
|
+
* them, with anything that doesn't parse listed by row (an unknown
|
|
127
|
+
* status, a cost that isn't a number, a missing column), with counts.
|
|
128
|
+
* The store itself reads such a value as a default (an unknown status as
|
|
129
|
+
* a known one), so this is how to see them. With suites (not just keys),
|
|
130
|
+
* each case's input and answer is also checked against the suite's
|
|
131
|
+
* schemas. It only reads.
|
|
132
|
+
*
|
|
133
|
+
* @param db - Your Prisma client.
|
|
134
|
+
* @param map - The map you pass `prismaStore` (`{}` for Evalkeeper's own tables).
|
|
135
|
+
* @param opts - Which suites, and how many tests of each.
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```ts
|
|
139
|
+
* import { prismaReadCheck } from "@crowandraven/evalkeeper/prisma";
|
|
140
|
+
* import { readCheckSummary } from "../index.js";
|
|
141
|
+
*
|
|
142
|
+
* const report = await prismaReadCheck(prisma, map, { suites: SUITES });
|
|
143
|
+
* console.log(readCheckSummary(report).join("\n"));
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
export function prismaReadCheck(db, map, opts) {
|
|
147
|
+
const table = (name) => new Table(name, map.models?.[name] ?? name, map.fields?.[name]);
|
|
148
|
+
const cases = table("evalCase");
|
|
149
|
+
const labels = table("evalCaseLabel");
|
|
150
|
+
const runs = table("evalRun");
|
|
151
|
+
const outputs = table("evalOutput");
|
|
152
|
+
const labelsOf = cases.col("labels") ?? "labels";
|
|
153
|
+
return checkReads({
|
|
154
|
+
async cases(suite) {
|
|
155
|
+
const rows = cases.ins(await cases.on(db).findMany({
|
|
156
|
+
where: cases.out({ suite }),
|
|
157
|
+
include: { [labelsOf]: true },
|
|
158
|
+
orderBy: cases.out({ createdAt: "asc" }),
|
|
159
|
+
}));
|
|
160
|
+
return rows.map((row) => Array.isArray(row.labels)
|
|
161
|
+
? { ...row, labels: labels.ins(row.labels) }
|
|
162
|
+
: row);
|
|
163
|
+
},
|
|
164
|
+
async tests(suite, limit) {
|
|
165
|
+
return runs.ins(await runs.on(db).findMany({
|
|
166
|
+
where: runs.out({ suite }),
|
|
167
|
+
orderBy: runs.out({ startedAt: "desc" }),
|
|
168
|
+
...(limit === undefined ? {} : { take: limit }),
|
|
169
|
+
}));
|
|
170
|
+
},
|
|
171
|
+
async outputs(ids) {
|
|
172
|
+
return outputs.ins(await outputs.on(db).findMany({
|
|
173
|
+
where: outputs.out({ runId: { in: [...ids] } }),
|
|
174
|
+
}));
|
|
175
|
+
},
|
|
176
|
+
}, opts);
|
|
177
|
+
}
|
|
178
|
+
//# sourceMappingURL=contracts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contracts.js","sourceRoot":"","sources":["../../src/prisma/contracts.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EACL,UAAU,GAIX,MAAM,aAAa,CAAC;AAMrB,OAAO,EAAE,KAAK,EAAE,KAAK,EAAY,MAAM,cAAc,CAAC;AAQtD,SAAS,OAAO,CAAC,EAAU,EAAE,KAAa;IACxC,MAAM,CAAC,GAAY,OAAO,CAAC,GAAG,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;IAC1C,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IACrD,OAA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