@cursor/july 0.1.16 → 0.1.17
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 +9 -4
- package/dist/bin/agent-serve.js +60 -2
- package/dist/channels/slack/api.d.ts.map +1 -1
- package/dist/channels/slack/api.js +13 -3
- package/dist/channels/slack/auth.d.ts +7 -1
- package/dist/channels/slack/auth.d.ts.map +1 -1
- package/dist/channels/slack/auth.js +14 -0
- package/dist/channels/slack/blocks.d.ts +61 -0
- package/dist/channels/slack/blocks.d.ts.map +1 -0
- package/dist/channels/slack/blocks.js +90 -0
- package/dist/channels/slack/defaults.d.ts +2 -0
- package/dist/channels/slack/defaults.d.ts.map +1 -1
- package/dist/channels/slack/defaults.js +29 -3
- package/dist/channels/slack/dispatch.d.ts +3 -17
- package/dist/channels/slack/dispatch.d.ts.map +1 -1
- package/dist/channels/slack/index.d.ts +1 -0
- package/dist/channels/slack/index.d.ts.map +1 -1
- package/dist/channels/slack/index.js +1 -0
- package/dist/channels/slack/interactive.d.ts +39 -3
- package/dist/channels/slack/interactive.d.ts.map +1 -1
- package/dist/channels/slack/interactive.js +152 -7
- package/dist/channels/slack/manifest.d.ts +3 -0
- package/dist/channels/slack/manifest.d.ts.map +1 -1
- package/dist/channels/slack/manifest.js +3 -0
- package/dist/channels/slack/setup.d.ts +4 -1
- package/dist/channels/slack/setup.d.ts.map +1 -1
- package/dist/channels/slack/setup.js +16 -2
- package/dist/channels/slack/slack-channel.d.ts.map +1 -1
- package/dist/channels/slack/slack-channel.js +24 -3
- package/dist/channels/slack/types.d.ts +77 -0
- package/dist/channels/slack/types.d.ts.map +1 -1
- package/dist/connections.d.ts +4 -1
- package/dist/connections.d.ts.map +1 -1
- package/dist/connections.js +4 -1
- package/dist/docs/404.html +2 -2
- package/dist/docs/ab.html +3 -3
- package/dist/docs/assets/{app.DjHC-Ggf.js → app.BbEXr2KO.js} +1 -1
- package/dist/docs/assets/chunks/@localSearchIndexroot.DCBsrfwP.js +1 -0
- package/dist/docs/assets/chunks/{VPLocalSearchBox.DwviwmIq.js → VPLocalSearchBox.DBEi4HDp.js} +1 -1
- package/dist/docs/assets/chunks/{theme.BIpeYSon.js → theme.DGfptcHw.js} +2 -2
- package/dist/docs/assets/{guides_mcp-oauth.md.DqmEOQY1.js → guides_mcp-oauth.md.Dd8EgSem.js} +3 -2
- package/dist/docs/assets/{guides_mcp-oauth.md.DqmEOQY1.lean.js → guides_mcp-oauth.md.Dd8EgSem.lean.js} +1 -1
- package/dist/docs/assets/{guides_slack.md.FWale6Ip.js → guides_slack.md.D_xFKlnF.js} +1 -1
- package/dist/docs/assets/{reference_connections.md.CsSr3rDz.js → reference_connections.md.B9Q3TOve.js} +12 -5
- package/dist/docs/assets/{reference_connections.md.CsSr3rDz.lean.js → reference_connections.md.B9Q3TOve.lean.js} +1 -1
- package/dist/docs/building-with-agents.html +3 -3
- package/dist/docs/concepts.html +3 -3
- package/dist/docs/deployment.html +3 -3
- package/dist/docs/evals.html +3 -3
- package/dist/docs/example-agents/approval-buddy.html +3 -3
- package/dist/docs/example-agents/benny.html +3 -3
- package/dist/docs/example-agents/bugbot.html +3 -3
- package/dist/docs/example-agents/codebase-wiki.html +3 -3
- package/dist/docs/example-agents/codeowners-review.html +3 -3
- package/dist/docs/example-agents/concierge.html +3 -3
- package/dist/docs/example-agents/fsd.html +3 -3
- package/dist/docs/example-agents/index.html +3 -3
- package/dist/docs/example-agents/knowledge-base.html +3 -3
- package/dist/docs/example-agents/oncall.html +3 -3
- package/dist/docs/example-agents/security-reviewer.html +3 -3
- package/dist/docs/example-agents/slack-agent.html +3 -3
- package/dist/docs/example-agents/weather-agent.html +3 -3
- package/dist/docs/guides/agent-to-agent.html +3 -3
- package/dist/docs/guides/cloud-runtime.html +3 -3
- package/dist/docs/guides/github.html +3 -3
- package/dist/docs/guides/human-in-the-loop.html +3 -3
- package/dist/docs/guides/mcp-oauth.html +6 -5
- package/dist/docs/guides/slack.html +5 -5
- package/dist/docs/guides/webhooks.html +3 -3
- package/dist/docs/hashmap.json +1 -1
- package/dist/docs/hillclimbing.html +3 -3
- package/dist/docs/index.html +3 -3
- package/dist/docs/quickstart.html +3 -3
- package/dist/docs/reference/agent-config.html +3 -3
- package/dist/docs/reference/channels.html +3 -3
- package/dist/docs/reference/cli.html +3 -3
- package/dist/docs/reference/connections.html +14 -7
- package/dist/docs/reference/hooks.html +3 -3
- package/dist/docs/reference/http-api.html +3 -3
- package/dist/docs/reference/instructions.html +3 -3
- package/dist/docs/reference/playground.html +3 -3
- package/dist/docs/reference/project-layout.html +3 -3
- package/dist/docs/reference/prompt.html +3 -3
- package/dist/docs/reference/schedules.html +3 -3
- package/dist/docs/reference/sessions.html +3 -3
- package/dist/docs/reference/skills.html +3 -3
- package/dist/docs/reference/subagents.html +3 -3
- package/dist/docs/reference/tools.html +3 -3
- package/dist/docs/scaffolding-agents.html +3 -3
- package/dist/docs/storage.html +3 -3
- package/dist/docs/troubleshooting.html +3 -3
- package/dist/evals/assertions.d.ts +190 -0
- package/dist/evals/assertions.d.ts.map +1 -0
- package/dist/evals/assertions.js +461 -0
- package/dist/evals/expect.d.ts +95 -0
- package/dist/evals/expect.d.ts.map +1 -0
- package/dist/evals/expect.js +194 -0
- package/dist/evals/judge.d.ts +133 -0
- package/dist/evals/judge.d.ts.map +1 -0
- package/dist/evals/judge.js +228 -0
- package/dist/evals/loaders.d.ts +51 -0
- package/dist/evals/loaders.d.ts.map +1 -0
- package/dist/evals/loaders.js +124 -0
- package/dist/evals/matchers.d.ts +95 -0
- package/dist/evals/matchers.d.ts.map +1 -0
- package/dist/evals/matchers.js +145 -0
- package/dist/evals/reporters.d.ts +70 -0
- package/dist/evals/reporters.d.ts.map +1 -0
- package/dist/evals/reporters.js +221 -0
- package/dist/evals/results.d.ts +103 -0
- package/dist/evals/results.d.ts.map +1 -0
- package/dist/evals/results.js +28 -0
- package/dist/evals/run-facts.d.ts +77 -0
- package/dist/evals/run-facts.d.ts.map +1 -0
- package/dist/evals/run-facts.js +187 -0
- package/dist/evals.d.ts +118 -31
- package/dist/evals.d.ts.map +1 -1
- package/dist/evals.js +46 -12
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/internal/cli-ax.d.ts +27 -0
- package/dist/internal/cli-ax.d.ts.map +1 -1
- package/dist/internal/cli-ax.js +90 -12
- package/dist/internal/cli-mcp.d.ts +8 -0
- package/dist/internal/cli-mcp.d.ts.map +1 -1
- package/dist/internal/cli-mcp.js +98 -0
- package/dist/internal/cli-slack.d.ts +29 -1
- package/dist/internal/cli-slack.d.ts.map +1 -1
- package/dist/internal/cli-slack.js +777 -12
- package/dist/internal/deploy-client.d.ts +7 -0
- package/dist/internal/deploy-client.d.ts.map +1 -1
- package/dist/internal/deploy-client.js +9 -0
- package/dist/internal/discovery.d.ts.map +1 -1
- package/dist/internal/discovery.js +29 -9
- package/dist/internal/distribution.d.ts.map +1 -1
- package/dist/internal/distribution.js +2 -0
- package/dist/internal/eval-judge-model.d.ts +59 -0
- package/dist/internal/eval-judge-model.d.ts.map +1 -0
- package/dist/internal/eval-judge-model.js +131 -0
- package/dist/internal/eval-run-store.d.ts.map +1 -1
- package/dist/internal/eval-run-store.js +12 -20
- package/dist/internal/eval-runner.d.ts +31 -25
- package/dist/internal/eval-runner.d.ts.map +1 -1
- package/dist/internal/eval-runner.js +329 -126
- package/dist/internal/evals-client.d.ts.map +1 -1
- package/dist/internal/evals-client.js +4 -1
- package/dist/internal/local-env.d.ts +8 -0
- package/dist/internal/local-env.d.ts.map +1 -0
- package/dist/internal/local-env.js +47 -0
- package/dist/internal/playground/static.d.ts +3 -0
- package/dist/internal/playground/static.d.ts.map +1 -1
- package/dist/internal/playground/static.js +3 -0
- package/dist/internal/run-client.d.ts +15 -0
- package/dist/internal/run-client.d.ts.map +1 -1
- package/dist/internal/run-client.js +3 -2
- package/dist/internal/sdk-runner.d.ts +36 -1
- package/dist/internal/sdk-runner.d.ts.map +1 -1
- package/dist/internal/sdk-runner.js +65 -25
- package/dist/internal/server.d.ts.map +1 -1
- package/dist/internal/server.js +10 -1
- package/dist/internal/session-engine.d.ts +18 -5
- package/dist/internal/session-engine.d.ts.map +1 -1
- package/dist/internal/session-engine.js +72 -19
- package/dist/internal/slack-provision-client.d.ts +130 -0
- package/dist/internal/slack-provision-client.d.ts.map +1 -0
- package/dist/internal/slack-provision-client.js +284 -0
- package/dist/playground/assets/cursor-icons-16-f_W_ogc-.woff2 +0 -0
- package/dist/playground/assets/index-CidizGZv.css +1 -0
- package/dist/playground/assets/index-DNqirsrK.js +85 -0
- package/dist/playground/index.html +2 -2
- package/dist/types.d.ts +70 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +26 -0
- package/docs/guides/mcp-oauth.md +10 -5
- package/docs/guides/slack.md +3 -2
- package/docs/reference/connections.md +28 -18
- package/package.json +20 -2
- package/skills/create-agent/SKILL.md +15 -7
- package/skills/debug/SKILL.md +3 -1
- package/skills/mcp-auth/SKILL.md +1 -1
- package/skills/setup-slack/SKILL.md +173 -11
- package/src/bin/agent-serve.ts +63 -2
- package/src/channels/slack/api.ts +16 -3
- package/src/channels/slack/auth.ts +16 -1
- package/src/channels/slack/blocks.ts +139 -0
- package/src/channels/slack/defaults.ts +32 -4
- package/src/channels/slack/dispatch.ts +3 -18
- package/src/channels/slack/index.ts +1 -0
- package/src/channels/slack/interactive.ts +183 -19
- package/src/channels/slack/manifest.ts +3 -0
- package/src/channels/slack/setup.ts +16 -2
- package/src/channels/slack/slack-channel.ts +37 -6
- package/src/channels/slack/types.ts +89 -0
- package/src/connections.ts +4 -1
- package/src/evals/assertions.ts +704 -0
- package/src/evals/expect.ts +272 -0
- package/src/evals/judge.ts +346 -0
- package/src/evals/loaders.ts +113 -0
- package/src/evals/matchers.ts +246 -0
- package/src/evals/reporters.ts +274 -0
- package/src/evals/results.ts +132 -0
- package/src/evals/run-facts.ts +274 -0
- package/src/evals.ts +205 -42
- package/src/index.ts +2 -0
- package/src/internal/cli-ax.ts +134 -15
- package/src/internal/cli-mcp.ts +118 -5
- package/src/internal/cli-slack.ts +993 -15
- package/src/internal/deploy-client.ts +10 -0
- package/src/internal/discovery.ts +31 -5
- package/src/internal/distribution.ts +2 -0
- package/src/internal/eval-judge-model.ts +148 -0
- package/src/internal/eval-run-store.ts +10 -14
- package/src/internal/eval-runner.ts +460 -214
- package/src/internal/evals-client.ts +5 -0
- package/src/internal/local-env.ts +53 -0
- package/src/internal/playground/static.ts +3 -0
- package/src/internal/run-client.ts +17 -1
- package/src/internal/sdk-runner.ts +103 -22
- package/src/internal/server.ts +10 -0
- package/src/internal/session-engine.ts +89 -21
- package/src/internal/slack-provision-client.ts +438 -0
- package/src/types.ts +92 -4
- package/dist/channels/slack/post-update-delivery.d.ts +0 -85
- package/dist/channels/slack/post-update-delivery.d.ts.map +0 -1
- package/dist/docs/assets/chunks/@localSearchIndexroot.DZtu0ZIc.js +0 -1
- package/dist/internal/json-dir-store.d.ts +0 -32
- package/dist/internal/json-dir-store.d.ts.map +0 -1
- package/dist/internal/persistence-coordinator.d.ts +0 -127
- package/dist/internal/persistence-coordinator.d.ts.map +0 -1
- package/dist/persistence.d.ts +0 -184
- package/dist/persistence.d.ts.map +0 -1
- package/dist/playground/assets/cursor-icons-16-CQ50JpfO.woff2 +0 -0
- package/dist/playground/assets/index-Bwl4Onx4.js +0 -85
- package/dist/playground/assets/index-ByV4nfch.css +0 -1
- /package/dist/docs/assets/{guides_slack.md.FWale6Ip.lean.js → guides_slack.md.D_xFKlnF.lean.js} +0 -0
|
@@ -13,13 +13,44 @@ import { readdir } from "node:fs/promises";
|
|
|
13
13
|
import { join, relative, resolve } from "node:path";
|
|
14
14
|
import { pathToFileURL } from "node:url";
|
|
15
15
|
import type {
|
|
16
|
-
|
|
16
|
+
EvalAssertionHandle,
|
|
17
|
+
EvalAssertions,
|
|
18
|
+
} from "../evals/assertions.js";
|
|
19
|
+
import {
|
|
20
|
+
computeVerdict,
|
|
21
|
+
createAssertions,
|
|
22
|
+
EvalAssertionRecorder,
|
|
23
|
+
EvalRequireFailure,
|
|
24
|
+
EvalSkipSignal,
|
|
25
|
+
} from "../evals/assertions.js";
|
|
26
|
+
import { evaluateExpectation } from "../evals/expect.js";
|
|
27
|
+
import type {
|
|
28
|
+
EvalJudge,
|
|
29
|
+
EvalJudgeCaller,
|
|
30
|
+
EvalJudgeCallOptions,
|
|
31
|
+
EvalJudgeConfig,
|
|
32
|
+
EvalJudgeGrader,
|
|
33
|
+
} from "../evals/judge.js";
|
|
34
|
+
import {
|
|
35
|
+
EVAL_JUDGE_GRADERS,
|
|
36
|
+
EvalJudgeUnavailableError,
|
|
37
|
+
renderSubmission,
|
|
38
|
+
} from "../evals/judge.js";
|
|
39
|
+
import { EVAL_ROOT_ENV } from "../evals/loaders.js";
|
|
40
|
+
import { combineReporters } from "../evals/reporters.js";
|
|
41
|
+
import { summarizeEvalResults } from "../evals/results.js";
|
|
42
|
+
import type {
|
|
17
43
|
EvalCaseDefinition,
|
|
18
44
|
EvalConfigFile,
|
|
19
45
|
EvalDefinition,
|
|
46
|
+
EvalReporter,
|
|
47
|
+
EvalReporterTarget,
|
|
48
|
+
EvalRunResult,
|
|
49
|
+
EvalRunSummary,
|
|
20
50
|
EvalSendOptions,
|
|
21
51
|
EvalTestContext,
|
|
22
52
|
EvalTurnResult,
|
|
53
|
+
EvalVerdict,
|
|
23
54
|
Expectation,
|
|
24
55
|
} from "../evals.js";
|
|
25
56
|
import {
|
|
@@ -30,8 +61,13 @@ import {
|
|
|
30
61
|
matchesEvalIdFilter,
|
|
31
62
|
normalizeEvalMaxConcurrency,
|
|
32
63
|
} from "../evals.js";
|
|
33
|
-
import type { SessionEvent } from "../types.js";
|
|
64
|
+
import type { ModelSetting, SessionEvent } from "../types.js";
|
|
34
65
|
import { isDefinitionOfKind } from "./brand.js";
|
|
66
|
+
import {
|
|
67
|
+
callJudgeModel,
|
|
68
|
+
EVAL_JUDGE_MODEL_ENV,
|
|
69
|
+
resolveJudgeModel,
|
|
70
|
+
} from "./eval-judge-model.js";
|
|
35
71
|
import { mapPool } from "./map-pool.js";
|
|
36
72
|
import { RunSessionTimeoutError, runSession } from "./run-client.js";
|
|
37
73
|
import { buildTrajectory } from "./trajectory.js";
|
|
@@ -45,30 +81,7 @@ export interface DiscoveredEval {
|
|
|
45
81
|
definition: EvalCaseDefinition;
|
|
46
82
|
}
|
|
47
83
|
|
|
48
|
-
export
|
|
49
|
-
id: string;
|
|
50
|
-
path: string;
|
|
51
|
-
description?: string;
|
|
52
|
-
ok: boolean;
|
|
53
|
-
assertions: EvalAssertionResult[];
|
|
54
|
-
sessionId?: string;
|
|
55
|
-
/** Messages passed to `t.send` (eval inputs). */
|
|
56
|
-
inputs: string[];
|
|
57
|
-
finalText?: string;
|
|
58
|
-
tools?: string[];
|
|
59
|
-
/** Tool calls with args/results from the trajectory. */
|
|
60
|
-
toolCalls?: Array<{
|
|
61
|
-
toolName: string;
|
|
62
|
-
args?: unknown;
|
|
63
|
-
output?: unknown;
|
|
64
|
-
isError: boolean;
|
|
65
|
-
}>;
|
|
66
|
-
error?: string;
|
|
67
|
-
logs: string[];
|
|
68
|
-
/** Structured scores from {@link import("../evals.js").EvalTestContext.metric}. */
|
|
69
|
-
metrics: Record<string, string | number>;
|
|
70
|
-
durationMs: number;
|
|
71
|
-
}
|
|
84
|
+
export type { EvalRunResult } from "../evals.js";
|
|
72
85
|
|
|
73
86
|
export interface EvalSelectionOptions {
|
|
74
87
|
filterIds?: string[];
|
|
@@ -79,6 +92,21 @@ export interface RunEvalsOptions extends EvalSelectionOptions {
|
|
|
79
92
|
projectRoot: string;
|
|
80
93
|
baseUrl: string;
|
|
81
94
|
timeoutMs?: number;
|
|
95
|
+
/** Override `evals.config.ts` `maxConcurrency` (CLI `--max-concurrency`). */
|
|
96
|
+
maxConcurrency?: number;
|
|
97
|
+
/**
|
|
98
|
+
* Reporters attached by the caller (CLI `--junit` / `--artifacts`), in
|
|
99
|
+
* addition to the ones declared in `evals.config.ts` and on each eval.
|
|
100
|
+
*/
|
|
101
|
+
reporters?: readonly EvalReporter[];
|
|
102
|
+
/** Ignore reporters declared in config and eval files (`--skip-report`). */
|
|
103
|
+
skipReport?: boolean;
|
|
104
|
+
/** Reported to reporters so a destination can label the run. */
|
|
105
|
+
target?: EvalReporterTarget;
|
|
106
|
+
/** Treat soft threshold misses as failures when summarizing. */
|
|
107
|
+
strict?: boolean;
|
|
108
|
+
/** Injected judge model call; defaults to the Cursor SDK caller. */
|
|
109
|
+
judgeCaller?: EvalJudgeCaller;
|
|
82
110
|
bearerToken?: string;
|
|
83
111
|
/** Extra request headers (e.g. hosted engineAccess). */
|
|
84
112
|
headers?: Record<string, string>;
|
|
@@ -155,6 +183,11 @@ export async function discoverEvals(
|
|
|
155
183
|
const evals: DiscoveredEval[] = [];
|
|
156
184
|
let config: Partial<EvalConfigFile> = {};
|
|
157
185
|
|
|
186
|
+
// Fixture loaders resolve relative paths against the app root, so a dataset
|
|
187
|
+
// path reads the same however deep the eval file sits and whatever cwd the
|
|
188
|
+
// CLI ran from.
|
|
189
|
+
process.env[EVAL_ROOT_ENV] = root;
|
|
190
|
+
|
|
158
191
|
for (const abs of files) {
|
|
159
192
|
const rel = relative(evalsDir, abs).replace(/\\/g, "/");
|
|
160
193
|
if (rel === "evals.config.ts" || rel === "evals.config.js") {
|
|
@@ -168,16 +201,9 @@ export async function discoverEvals(
|
|
|
168
201
|
continue;
|
|
169
202
|
}
|
|
170
203
|
const mod = await importModule(abs);
|
|
171
|
-
const def = mod.default;
|
|
172
|
-
if (!isDefinitionOfKind(def, "eval")) {
|
|
173
|
-
throw new Error(`${rel}: default export must be defineEval({ ... })`);
|
|
174
|
-
}
|
|
175
204
|
const fileId = rel.replace(/\.eval\.(ts|js)$/, "").replace(/\/index$/, "");
|
|
176
205
|
try {
|
|
177
|
-
for (const expanded of
|
|
178
|
-
fileId,
|
|
179
|
-
def as EvalDefinition
|
|
180
|
-
)) {
|
|
206
|
+
for (const expanded of expandEvalModule(fileId, mod.default)) {
|
|
181
207
|
evals.push({
|
|
182
208
|
id: expanded.id,
|
|
183
209
|
fileId,
|
|
@@ -194,6 +220,45 @@ export async function discoverEvals(
|
|
|
194
220
|
return { evals, config };
|
|
195
221
|
}
|
|
196
222
|
|
|
223
|
+
/**
|
|
224
|
+
* Expand one eval module's default export into runnable datapoints.
|
|
225
|
+
*
|
|
226
|
+
* A file normally exports a single `defineEval(...)`. It may instead export an
|
|
227
|
+
* **array** of them to fan out over a dataset, in which case ids come from the
|
|
228
|
+
* file name plus a zero-padded index in array order (`sql/0000`, `sql/0001`, …).
|
|
229
|
+
* Prefer `cases` when the datapoints are hand-written and deserve stable names;
|
|
230
|
+
* the array form is for generated datasets where the index *is* the name.
|
|
231
|
+
*/
|
|
232
|
+
export function expandEvalModule(
|
|
233
|
+
fileId: string,
|
|
234
|
+
defaultExport: unknown
|
|
235
|
+
): Array<{ id: string; definition: EvalCaseDefinition }> {
|
|
236
|
+
if (Array.isArray(defaultExport)) {
|
|
237
|
+
if (defaultExport.length === 0) {
|
|
238
|
+
throw new Error(
|
|
239
|
+
"default export array is empty; export at least one defineEval({ ... })"
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
return defaultExport.flatMap((entry, index) => {
|
|
243
|
+
if (!isDefinitionOfKind(entry, "eval")) {
|
|
244
|
+
throw new Error(
|
|
245
|
+
`default export array entry ${index} must be defineEval({ ... })`
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
return expandEvalDefinition(
|
|
249
|
+
`${fileId}/${String(index).padStart(4, "0")}`,
|
|
250
|
+
entry as EvalDefinition
|
|
251
|
+
);
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
if (!isDefinitionOfKind(defaultExport, "eval")) {
|
|
255
|
+
throw new Error(
|
|
256
|
+
"default export must be defineEval({ ... }) or an array of them"
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
return expandEvalDefinition(fileId, defaultExport as EvalDefinition);
|
|
260
|
+
}
|
|
261
|
+
|
|
197
262
|
/** Apply id/tag filters used by CLI, playground, and `runDiscoveredEvals`. */
|
|
198
263
|
export function filterDiscoveredEvals(
|
|
199
264
|
evals: readonly DiscoveredEval[],
|
|
@@ -239,8 +304,18 @@ export async function runDiscoveredEvals(
|
|
|
239
304
|
return [];
|
|
240
305
|
}
|
|
241
306
|
|
|
242
|
-
const maxConcurrency =
|
|
307
|
+
const maxConcurrency =
|
|
308
|
+
options.maxConcurrency === undefined
|
|
309
|
+
? resolveEvalMaxConcurrency(config)
|
|
310
|
+
: normalizeEvalMaxConcurrency(options.maxConcurrency);
|
|
243
311
|
const defaultTimeoutMs = options.timeoutMs ?? config.timeoutMs ?? 180_000;
|
|
312
|
+
const reporter = buildReporterHub(options, config, selected);
|
|
313
|
+
const startedAt = new Date().toISOString();
|
|
314
|
+
|
|
315
|
+
await reporter?.runStart(
|
|
316
|
+
selected,
|
|
317
|
+
options.target ?? { baseUrl: options.baseUrl, mode: "local" }
|
|
318
|
+
);
|
|
244
319
|
|
|
245
320
|
// Iterations of the same authored datapoint share one concurrency slot and
|
|
246
321
|
// run sequentially. maxConcurrency is therefore the max number of distinct
|
|
@@ -266,19 +341,103 @@ export async function runDiscoveredEvals(
|
|
|
266
341
|
headers: options.headers,
|
|
267
342
|
verbose: Boolean(options.verbose),
|
|
268
343
|
signal: options.signal,
|
|
344
|
+
judge: {
|
|
345
|
+
configModel: config.judge?.model,
|
|
346
|
+
caller: options.judgeCaller ?? callJudgeModel,
|
|
347
|
+
},
|
|
269
348
|
onEvent: (event) => {
|
|
270
349
|
options.onCaseEvent?.(discovered.id, event);
|
|
271
350
|
options.onEvent?.(event);
|
|
272
351
|
},
|
|
273
352
|
});
|
|
274
353
|
options.onCaseDone?.(result);
|
|
354
|
+
await reporter?.caseComplete(discovered, result);
|
|
275
355
|
results.push(result);
|
|
276
356
|
}
|
|
277
357
|
return results;
|
|
278
358
|
},
|
|
279
359
|
{ signal: options.signal }
|
|
280
360
|
);
|
|
281
|
-
|
|
361
|
+
const results = nested.flat();
|
|
362
|
+
|
|
363
|
+
await reporter?.runComplete(
|
|
364
|
+
summarizeEvalResults(results, {
|
|
365
|
+
strict: options.strict === true,
|
|
366
|
+
startedAt,
|
|
367
|
+
finishedAt: new Date().toISOString(),
|
|
368
|
+
})
|
|
369
|
+
);
|
|
370
|
+
return results;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
interface ReporterHub {
|
|
374
|
+
runStart(
|
|
375
|
+
evals: readonly DiscoveredEval[],
|
|
376
|
+
target: EvalReporterTarget
|
|
377
|
+
): Promise<void>;
|
|
378
|
+
caseComplete(
|
|
379
|
+
discovered: DiscoveredEval,
|
|
380
|
+
result: EvalRunResult
|
|
381
|
+
): Promise<void>;
|
|
382
|
+
runComplete(summary: EvalRunSummary): Promise<void>;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* Fan results out to the reporters that observe them.
|
|
387
|
+
*
|
|
388
|
+
* Run-wide reporters (CLI flags plus `evals.config.ts`) see every case; an
|
|
389
|
+
* eval's own `reporters` only see that eval. The run lifecycle hooks fire on
|
|
390
|
+
* every reporter in the run, so a per-eval destination still gets its
|
|
391
|
+
* `onRunStart` / `onRunComplete` pair.
|
|
392
|
+
*/
|
|
393
|
+
function buildReporterHub(
|
|
394
|
+
options: RunEvalsOptions,
|
|
395
|
+
config: Partial<EvalConfigFile>,
|
|
396
|
+
selected: readonly DiscoveredEval[]
|
|
397
|
+
): ReporterHub | undefined {
|
|
398
|
+
const skip = options.skipReport === true;
|
|
399
|
+
const runWide = [
|
|
400
|
+
...(options.reporters ?? []),
|
|
401
|
+
...(skip ? [] : (config.reporters ?? [])),
|
|
402
|
+
];
|
|
403
|
+
const perEval = skip
|
|
404
|
+
? []
|
|
405
|
+
: selected.flatMap((e) => e.definition.reporters ?? []);
|
|
406
|
+
const everyReporter = [...new Set([...runWide, ...perEval])];
|
|
407
|
+
if (everyReporter.length === 0) {
|
|
408
|
+
return undefined;
|
|
409
|
+
}
|
|
410
|
+
const onError = (error: unknown): void => {
|
|
411
|
+
// A broken destination must not fail the eval run itself.
|
|
412
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
413
|
+
process.stderr.write(`eval reporter error: ${detail}\n`);
|
|
414
|
+
};
|
|
415
|
+
const all = combineReporters(everyReporter, onError);
|
|
416
|
+
return {
|
|
417
|
+
async runStart(evals, target) {
|
|
418
|
+
await all.onRunStart?.(
|
|
419
|
+
evals.map((e) => ({
|
|
420
|
+
id: e.id,
|
|
421
|
+
fileId: e.fileId,
|
|
422
|
+
description: e.definition.description,
|
|
423
|
+
tags: e.definition.tags,
|
|
424
|
+
})),
|
|
425
|
+
target
|
|
426
|
+
);
|
|
427
|
+
},
|
|
428
|
+
async caseComplete(discovered, result) {
|
|
429
|
+
const observers = [
|
|
430
|
+
...new Set([
|
|
431
|
+
...runWide,
|
|
432
|
+
...(skip ? [] : (discovered.definition.reporters ?? [])),
|
|
433
|
+
]),
|
|
434
|
+
];
|
|
435
|
+
await combineReporters(observers, onError).onEvalComplete?.(result);
|
|
436
|
+
},
|
|
437
|
+
async runComplete(summary) {
|
|
438
|
+
await all.onRunComplete?.(summary);
|
|
439
|
+
},
|
|
440
|
+
};
|
|
282
441
|
}
|
|
283
442
|
|
|
284
443
|
/**
|
|
@@ -336,6 +495,12 @@ function resolveEvalMaxConcurrency(config: Partial<EvalConfigFile>): number {
|
|
|
336
495
|
return normalizeEvalMaxConcurrency(config.maxConcurrency);
|
|
337
496
|
}
|
|
338
497
|
|
|
498
|
+
interface RunOneEvalJudgeOptions {
|
|
499
|
+
/** Judge model from `evals.config.ts`. */
|
|
500
|
+
configModel?: ModelSetting;
|
|
501
|
+
caller: EvalJudgeCaller;
|
|
502
|
+
}
|
|
503
|
+
|
|
339
504
|
async function runOneEval(
|
|
340
505
|
discovered: DiscoveredEval,
|
|
341
506
|
opts: {
|
|
@@ -344,50 +509,29 @@ async function runOneEval(
|
|
|
344
509
|
bearerToken?: string;
|
|
345
510
|
headers?: Record<string, string>;
|
|
346
511
|
verbose: boolean;
|
|
512
|
+
judge: RunOneEvalJudgeOptions;
|
|
347
513
|
onEvent?: (event: SessionEvent) => void;
|
|
348
514
|
signal?: AbortSignal;
|
|
349
515
|
}
|
|
350
516
|
): Promise<EvalRunResult> {
|
|
351
517
|
const logs: string[] = [];
|
|
352
518
|
const metrics: Record<string, string | number> = {};
|
|
353
|
-
const
|
|
519
|
+
const recorder = new EvalAssertionRecorder();
|
|
354
520
|
const def = discovered.definition;
|
|
355
521
|
const timeoutMs = def.timeoutMs ?? opts.defaultTimeoutMs;
|
|
356
522
|
const startedAt = Date.now();
|
|
357
523
|
|
|
358
524
|
let sessionId: string | undefined;
|
|
359
525
|
let continuationToken: string | undefined;
|
|
526
|
+
// The session stream replays from an index and the client stops at the first
|
|
527
|
+
// terminal event, so each send must resume after the previous turn's last
|
|
528
|
+
// event or it would re-read that turn instead of the new one.
|
|
529
|
+
let nextEventIndex = 0;
|
|
360
530
|
const allEvents: SessionEvent[] = [];
|
|
361
531
|
const inputs: string[] = [];
|
|
532
|
+
const turns: EvalTurnResult[] = [];
|
|
362
533
|
let reply: string | null = null;
|
|
363
534
|
|
|
364
|
-
if (opts.signal?.aborted) {
|
|
365
|
-
return {
|
|
366
|
-
id: discovered.id,
|
|
367
|
-
path: discovered.path,
|
|
368
|
-
...(def.description === undefined
|
|
369
|
-
? {}
|
|
370
|
-
: { description: def.description }),
|
|
371
|
-
ok: false,
|
|
372
|
-
assertions,
|
|
373
|
-
error: "cancelled",
|
|
374
|
-
logs,
|
|
375
|
-
metrics,
|
|
376
|
-
inputs,
|
|
377
|
-
toolCalls: [],
|
|
378
|
-
tools: [],
|
|
379
|
-
durationMs: Date.now() - startedAt,
|
|
380
|
-
};
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
const record = (name: string, passed: boolean, detail?: string): void => {
|
|
384
|
-
assertions.push({
|
|
385
|
-
name,
|
|
386
|
-
passed,
|
|
387
|
-
...(detail === undefined ? {} : { detail }),
|
|
388
|
-
});
|
|
389
|
-
};
|
|
390
|
-
|
|
391
535
|
const toolsUsed = (): string[] =>
|
|
392
536
|
buildTrajectory(allEvents).turns.flatMap((t) =>
|
|
393
537
|
t.toolCalls.map((c) => c.toolName)
|
|
@@ -403,7 +547,69 @@ async function runOneEval(
|
|
|
403
547
|
}))
|
|
404
548
|
);
|
|
405
549
|
|
|
550
|
+
const finish = (extra: {
|
|
551
|
+
verdict: EvalVerdict;
|
|
552
|
+
ok: boolean;
|
|
553
|
+
error?: string;
|
|
554
|
+
skipReason?: string;
|
|
555
|
+
finalText?: string;
|
|
556
|
+
}): EvalRunResult => ({
|
|
557
|
+
id: discovered.id,
|
|
558
|
+
path: discovered.path,
|
|
559
|
+
...(def.description === undefined ? {} : { description: def.description }),
|
|
560
|
+
ok: extra.ok,
|
|
561
|
+
verdict: extra.verdict,
|
|
562
|
+
skipReason: extra.skipReason,
|
|
563
|
+
assertions: recorder.results(),
|
|
564
|
+
error: extra.error,
|
|
565
|
+
logs,
|
|
566
|
+
metrics,
|
|
567
|
+
metadata: def.metadata,
|
|
568
|
+
tags: def.tags,
|
|
569
|
+
inputs,
|
|
570
|
+
toolCalls: toolCallIo(),
|
|
571
|
+
...(sessionId === undefined ? {} : { sessionId }),
|
|
572
|
+
finalText: extra.finalText,
|
|
573
|
+
tools: toolsUsed(),
|
|
574
|
+
durationMs: Date.now() - startedAt,
|
|
575
|
+
});
|
|
576
|
+
|
|
577
|
+
if (opts.signal?.aborted) {
|
|
578
|
+
return finish({ verdict: "failed", ok: false, error: "cancelled" });
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
// A judge that cannot reach a model must not look like a quality regression:
|
|
582
|
+
// the case is skipped visibly instead.
|
|
583
|
+
let judgeUnavailable: string | undefined;
|
|
584
|
+
const timeout = new AbortController();
|
|
585
|
+
const timer = setTimeout(() => timeout.abort(), clampTimerDelay(timeoutMs));
|
|
586
|
+
// A pending case timer must not hold the process open on its own.
|
|
587
|
+
timer.unref?.();
|
|
588
|
+
|
|
589
|
+
const runAssertions: EvalAssertions = createAssertions({
|
|
590
|
+
recorder,
|
|
591
|
+
events: () => allEvents,
|
|
592
|
+
});
|
|
593
|
+
|
|
594
|
+
const judge = createJudgeSurface({
|
|
595
|
+
recorder,
|
|
596
|
+
grader: (name) => EVAL_JUDGE_GRADERS[name],
|
|
597
|
+
resolveModel: (callModel) =>
|
|
598
|
+
resolveJudgeModel({
|
|
599
|
+
call: callModel,
|
|
600
|
+
evalLevel: def.judge?.model,
|
|
601
|
+
config: opts.judge.configModel,
|
|
602
|
+
env: process.env[EVAL_JUDGE_MODEL_ENV],
|
|
603
|
+
}),
|
|
604
|
+
caller: opts.judge.caller,
|
|
605
|
+
defaultValue: () => reply,
|
|
606
|
+
onUnavailable: (message) => {
|
|
607
|
+
judgeUnavailable = judgeUnavailable ?? message;
|
|
608
|
+
},
|
|
609
|
+
});
|
|
610
|
+
|
|
406
611
|
const t: EvalTestContext = {
|
|
612
|
+
...runAssertions,
|
|
407
613
|
get reply() {
|
|
408
614
|
return reply;
|
|
409
615
|
},
|
|
@@ -413,12 +619,19 @@ async function runOneEval(
|
|
|
413
619
|
get events() {
|
|
414
620
|
return allEvents;
|
|
415
621
|
},
|
|
622
|
+
get turns() {
|
|
623
|
+
return turns;
|
|
624
|
+
},
|
|
416
625
|
get iteration() {
|
|
417
626
|
return def.iteration ?? 1;
|
|
418
627
|
},
|
|
419
628
|
get iterations() {
|
|
420
629
|
return def.iterations ?? 1;
|
|
421
630
|
},
|
|
631
|
+
get signal() {
|
|
632
|
+
return timeout.signal;
|
|
633
|
+
},
|
|
634
|
+
judge,
|
|
422
635
|
async send(
|
|
423
636
|
message: string,
|
|
424
637
|
options: EvalSendOptions = {}
|
|
@@ -429,6 +642,7 @@ async function runOneEval(
|
|
|
429
642
|
messages: [message],
|
|
430
643
|
sessionId,
|
|
431
644
|
continuationToken,
|
|
645
|
+
startIndex: nextEventIndex,
|
|
432
646
|
// Keep defineEval traffic out of live defineAB enrollment/metrics.
|
|
433
647
|
purpose: "eval",
|
|
434
648
|
bearerToken: opts.bearerToken,
|
|
@@ -442,57 +656,57 @@ async function runOneEval(
|
|
|
442
656
|
});
|
|
443
657
|
sessionId = result.sessionId;
|
|
444
658
|
continuationToken = result.continuationToken;
|
|
659
|
+
nextEventIndex = result.nextEventIndex ?? nextEventIndex;
|
|
445
660
|
allEvents.push(...result.events);
|
|
446
661
|
if (result.trajectory.finalText !== "") {
|
|
447
662
|
reply = result.trajectory.finalText;
|
|
448
663
|
}
|
|
449
|
-
|
|
664
|
+
const index = turns.length + 1;
|
|
665
|
+
// The turn is immutable, so its assertions read a frozen event slice
|
|
666
|
+
// even after later turns append to the run.
|
|
667
|
+
const turnEvents = [...result.events];
|
|
668
|
+
const turn: EvalTurnResult = {
|
|
669
|
+
...createAssertions({
|
|
670
|
+
recorder,
|
|
671
|
+
events: () => turnEvents,
|
|
672
|
+
scope: `turn[${index}]`,
|
|
673
|
+
}),
|
|
450
674
|
message: result.trajectory.finalText,
|
|
451
675
|
sessionId: result.sessionId,
|
|
452
|
-
events:
|
|
676
|
+
events: turnEvents,
|
|
453
677
|
toolCalls: result.trajectory.turns.flatMap((turn) =>
|
|
454
678
|
turn.toolCalls.map((c) => c.toolName)
|
|
455
679
|
),
|
|
456
680
|
ok: result.ok,
|
|
681
|
+
index,
|
|
682
|
+
expectOk() {
|
|
683
|
+
if (!result.ok) {
|
|
684
|
+
throw new Error(
|
|
685
|
+
`turn[${index}] failed: ${result.trajectory.turns.find((x) => x.failed)?.error ?? "unknown error"}`
|
|
686
|
+
);
|
|
687
|
+
}
|
|
688
|
+
return turn;
|
|
689
|
+
},
|
|
457
690
|
};
|
|
691
|
+
turns.push(turn);
|
|
692
|
+
return turn;
|
|
458
693
|
},
|
|
459
|
-
|
|
460
|
-
const
|
|
461
|
-
record(
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
tools.includes(name) ? undefined : `got [${tools.join(", ")}]`
|
|
473
|
-
);
|
|
474
|
-
},
|
|
475
|
-
notCalledTool(name: string) {
|
|
476
|
-
const tools = toolsUsed();
|
|
477
|
-
record(
|
|
478
|
-
`notCalledTool(${name})`,
|
|
479
|
-
!tools.includes(name),
|
|
480
|
-
tools.includes(name) ? "tool was called" : undefined
|
|
481
|
-
);
|
|
482
|
-
},
|
|
483
|
-
messageIncludes(token: string | RegExp) {
|
|
484
|
-
const text = reply ?? "";
|
|
485
|
-
const passed =
|
|
486
|
-
typeof token === "string" ? text.includes(token) : token.test(text);
|
|
487
|
-
record(
|
|
488
|
-
`messageIncludes(${String(token)})`,
|
|
489
|
-
passed,
|
|
490
|
-
passed ? undefined : `reply=${JSON.stringify(text.slice(0, 120))}`
|
|
491
|
-
);
|
|
694
|
+
async require<T>(value: T, assertion: Expectation): Promise<T> {
|
|
695
|
+
const outcome = evaluateExpectation(value, assertion);
|
|
696
|
+
recorder.record({
|
|
697
|
+
name: `require(${assertion.kind})`,
|
|
698
|
+
passed: outcome.passed,
|
|
699
|
+
detail: outcome.detail,
|
|
700
|
+
score: outcome.score,
|
|
701
|
+
severity: "gate",
|
|
702
|
+
});
|
|
703
|
+
if (!outcome.passed) {
|
|
704
|
+
throw new EvalRequireFailure(`require(${assertion.kind})`);
|
|
705
|
+
}
|
|
706
|
+
return value;
|
|
492
707
|
},
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
record(`check(${assertion.kind})`, passed, detail);
|
|
708
|
+
skip(reason: string): never {
|
|
709
|
+
throw new EvalSkipSignal(reason);
|
|
496
710
|
},
|
|
497
711
|
log(message: string) {
|
|
498
712
|
logs.push(message);
|
|
@@ -515,129 +729,161 @@ async function runOneEval(
|
|
|
515
729
|
try {
|
|
516
730
|
await def.test(t);
|
|
517
731
|
} catch (error) {
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
732
|
+
if (error instanceof EvalSkipSignal) {
|
|
733
|
+
clearTimeout(timer);
|
|
734
|
+
return finish({
|
|
735
|
+
verdict: "skipped",
|
|
736
|
+
ok: true,
|
|
737
|
+
skipReason: error.reason,
|
|
738
|
+
finalText: reply ?? undefined,
|
|
739
|
+
});
|
|
740
|
+
}
|
|
741
|
+
if (!(error instanceof EvalRequireFailure)) {
|
|
742
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
743
|
+
if (error instanceof RunSessionTimeoutError && sessionId === undefined) {
|
|
744
|
+
sessionId = error.sessionId;
|
|
745
|
+
}
|
|
746
|
+
await recorder.waitForPending().catch(() => undefined);
|
|
747
|
+
clearTimeout(timer);
|
|
748
|
+
return finish({
|
|
749
|
+
verdict: "failed",
|
|
750
|
+
ok: false,
|
|
751
|
+
error: message,
|
|
752
|
+
finalText: reply ?? undefined,
|
|
753
|
+
});
|
|
521
754
|
}
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
path: discovered.path,
|
|
525
|
-
...(def.description === undefined
|
|
526
|
-
? {}
|
|
527
|
-
: { description: def.description }),
|
|
528
|
-
ok: false,
|
|
529
|
-
assertions,
|
|
530
|
-
error: message,
|
|
531
|
-
logs,
|
|
532
|
-
metrics,
|
|
533
|
-
inputs,
|
|
534
|
-
toolCalls: toolCallIo(),
|
|
535
|
-
...(sessionId === undefined ? {} : { sessionId }),
|
|
536
|
-
...(reply === null ? {} : { finalText: reply }),
|
|
537
|
-
tools: toolsUsed(),
|
|
538
|
-
durationMs: Date.now() - startedAt,
|
|
539
|
-
};
|
|
755
|
+
// `require` already recorded the failing gate; fall through so the verdict
|
|
756
|
+
// comes from the assertions rather than a duplicate execution error.
|
|
540
757
|
}
|
|
541
758
|
|
|
759
|
+
await recorder.waitForPending();
|
|
760
|
+
clearTimeout(timer);
|
|
761
|
+
|
|
762
|
+
const assertions = recorder.results();
|
|
542
763
|
const traj = buildTrajectory(allEvents);
|
|
543
|
-
|
|
764
|
+
// With no assertions at all, keep the historical fallback: a case that just
|
|
765
|
+
// drives the agent passes when the run itself succeeded.
|
|
766
|
+
const verdict: EvalVerdict =
|
|
544
767
|
assertions.length > 0
|
|
545
|
-
? assertions
|
|
546
|
-
: traj.ok && traj.turns.length > 0
|
|
768
|
+
? computeVerdict(assertions)
|
|
769
|
+
: traj.ok && traj.turns.length > 0
|
|
770
|
+
? "passed"
|
|
771
|
+
: "failed";
|
|
772
|
+
const finalText = reply ?? traj.finalText;
|
|
547
773
|
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
774
|
+
// An unreachable judge means the *judged* signal is unknown, so the case is
|
|
775
|
+
// reported as skipped rather than as a quality regression. It must not also
|
|
776
|
+
// bury a deterministic gate that already failed: skipping a failed case would
|
|
777
|
+
// turn a red eval green on any machine that happens to lack credentials.
|
|
778
|
+
if (judgeUnavailable !== undefined && verdict !== "failed") {
|
|
779
|
+
logs.push(`judge skipped: ${judgeUnavailable}`);
|
|
780
|
+
return finish({
|
|
781
|
+
verdict: "skipped",
|
|
782
|
+
ok: true,
|
|
783
|
+
skipReason: judgeUnavailable,
|
|
784
|
+
finalText,
|
|
785
|
+
});
|
|
786
|
+
}
|
|
787
|
+
if (judgeUnavailable !== undefined) {
|
|
788
|
+
logs.push(
|
|
789
|
+
`judge unavailable (${judgeUnavailable}), but a gate already failed — reporting the failure`
|
|
790
|
+
);
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
return finish({
|
|
794
|
+
verdict,
|
|
795
|
+
ok: verdict !== "failed",
|
|
796
|
+
finalText,
|
|
797
|
+
});
|
|
563
798
|
}
|
|
564
799
|
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
800
|
+
/** Clamp a case timeout to a delay `setTimeout` can represent. */
|
|
801
|
+
function clampTimerDelay(timeoutMs: number): number {
|
|
802
|
+
const MAX_TIMER = 2_147_483_647;
|
|
803
|
+
return Math.min(Math.max(timeoutMs, 0), MAX_TIMER);
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
/**
|
|
807
|
+
* Build `t.judge`. Each grader records its slot immediately and resolves it
|
|
808
|
+
* during finalization, so several judges overlap instead of serializing.
|
|
809
|
+
*/
|
|
810
|
+
function createJudgeSurface(args: {
|
|
811
|
+
recorder: EvalAssertionRecorder;
|
|
812
|
+
grader: (name: keyof typeof EVAL_JUDGE_GRADERS) => EvalJudgeGrader;
|
|
813
|
+
resolveModel: (call?: ModelSetting) => ModelSetting | undefined;
|
|
814
|
+
caller: EvalJudgeCaller;
|
|
815
|
+
defaultValue: () => unknown;
|
|
816
|
+
onUnavailable: (message: string) => void;
|
|
817
|
+
}): EvalJudge {
|
|
818
|
+
const grade = (
|
|
819
|
+
graderName: keyof typeof EVAL_JUDGE_GRADERS,
|
|
820
|
+
reference: string,
|
|
821
|
+
options: EvalJudgeCallOptions | undefined
|
|
822
|
+
): EvalAssertionHandle => {
|
|
823
|
+
const grader = args.grader(graderName);
|
|
824
|
+
const model = args.resolveModel(options?.model);
|
|
825
|
+
const name = `judge.${graderName}(${truncateForName(reference)})`;
|
|
826
|
+
if (model === undefined) {
|
|
827
|
+
// A missing judge model is an authoring error, not a flaky provider.
|
|
828
|
+
return args.recorder.record({
|
|
829
|
+
name,
|
|
830
|
+
passed: false,
|
|
831
|
+
severity: "gate",
|
|
832
|
+
detail:
|
|
833
|
+
"no judge model configured; set judge.model in evals.config.ts, on the eval, or on the call",
|
|
834
|
+
});
|
|
595
835
|
}
|
|
596
|
-
|
|
597
|
-
|
|
836
|
+
const submission = renderSubmission(
|
|
837
|
+
options !== undefined && "on" in options
|
|
838
|
+
? options.on
|
|
839
|
+
: args.defaultValue()
|
|
840
|
+
);
|
|
841
|
+
const settle = (async () => {
|
|
842
|
+
const reply = await args.caller({
|
|
843
|
+
prompt: grader.buildPrompt({ submission, reference }),
|
|
844
|
+
model,
|
|
845
|
+
});
|
|
846
|
+
const result = grader.parse(reply);
|
|
598
847
|
return {
|
|
599
|
-
passed,
|
|
600
|
-
|
|
848
|
+
passed: true,
|
|
849
|
+
score: result.score,
|
|
850
|
+
detail:
|
|
851
|
+
result.rationale === undefined
|
|
852
|
+
? `${result.choice} (${result.score.toFixed(2)})`
|
|
853
|
+
: `${result.choice} (${result.score.toFixed(2)}) — ${result.rationale}`,
|
|
601
854
|
};
|
|
602
|
-
}
|
|
603
|
-
|
|
855
|
+
})().catch((error: unknown) => {
|
|
856
|
+
if (error instanceof EvalJudgeUnavailableError) {
|
|
857
|
+
args.onUnavailable(error.message);
|
|
858
|
+
return { passed: true, detail: `skipped: ${error.message}` };
|
|
859
|
+
}
|
|
860
|
+
throw error;
|
|
861
|
+
});
|
|
862
|
+
// Soft by default: a judge is a tracked score until given a bar.
|
|
863
|
+
return args.recorder.recordAsync(
|
|
864
|
+
{ name, passed: true, severity: "soft", detail: "grading…" },
|
|
865
|
+
settle
|
|
866
|
+
);
|
|
867
|
+
};
|
|
868
|
+
|
|
869
|
+
return {
|
|
870
|
+
async model(prompt, options) {
|
|
871
|
+
const model = args.resolveModel(options?.model);
|
|
872
|
+
if (model === undefined) {
|
|
873
|
+
throw new Error(
|
|
874
|
+
"t.judge.model: no judge model configured; set judge.model in evals.config.ts, on the eval, or on the call"
|
|
875
|
+
);
|
|
876
|
+
}
|
|
877
|
+
return args.caller({ prompt, model });
|
|
878
|
+
},
|
|
879
|
+
factuality: (expected, options) => grade("factuality", expected, options),
|
|
880
|
+
summarizes: (expected, options) => grade("summarizes", expected, options),
|
|
881
|
+
closedQA: (criteria, options) => grade("closedQA", criteria, options),
|
|
882
|
+
sql: (expected, options) => grade("sql", expected, options),
|
|
883
|
+
};
|
|
604
884
|
}
|
|
605
885
|
|
|
606
|
-
function
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
}
|
|
610
|
-
if (
|
|
611
|
-
typeof a !== "object" ||
|
|
612
|
-
typeof b !== "object" ||
|
|
613
|
-
a === null ||
|
|
614
|
-
b === null
|
|
615
|
-
) {
|
|
616
|
-
return false;
|
|
617
|
-
}
|
|
618
|
-
if (Array.isArray(a) !== Array.isArray(b)) {
|
|
619
|
-
return false;
|
|
620
|
-
}
|
|
621
|
-
if (Array.isArray(a) && Array.isArray(b)) {
|
|
622
|
-
if (a.length !== b.length) {
|
|
623
|
-
return false;
|
|
624
|
-
}
|
|
625
|
-
return a.every((item, i) => deepEqual(item, b[i]));
|
|
626
|
-
}
|
|
627
|
-
const aKeys = Object.keys(a as object);
|
|
628
|
-
const bKeys = Object.keys(b as object);
|
|
629
|
-
if (aKeys.length !== bKeys.length) {
|
|
630
|
-
return false;
|
|
631
|
-
}
|
|
632
|
-
for (const key of aKeys) {
|
|
633
|
-
if (
|
|
634
|
-
!deepEqual(
|
|
635
|
-
(a as Record<string, unknown>)[key],
|
|
636
|
-
(b as Record<string, unknown>)[key]
|
|
637
|
-
)
|
|
638
|
-
) {
|
|
639
|
-
return false;
|
|
640
|
-
}
|
|
641
|
-
}
|
|
642
|
-
return true;
|
|
886
|
+
function truncateForName(text: string): string {
|
|
887
|
+
const oneLine = text.replace(/\s+/g, " ").trim();
|
|
888
|
+
return oneLine.length > 60 ? `${oneLine.slice(0, 59)}…` : oneLine;
|
|
643
889
|
}
|