vitest-evals 0.9.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/README.md +112 -66
  2. package/dist/harness.d.mts +12 -1
  3. package/dist/harness.d.ts +12 -1
  4. package/dist/harness.js +8 -0
  5. package/dist/harness.js.map +1 -1
  6. package/dist/harness.mjs +7 -0
  7. package/dist/harness.mjs.map +1 -1
  8. package/dist/index.d.mts +48 -20
  9. package/dist/index.d.ts +48 -20
  10. package/dist/index.js +308 -21
  11. package/dist/index.js.map +1 -1
  12. package/dist/index.mjs +304 -21
  13. package/dist/index.mjs.map +1 -1
  14. package/dist/internal/scoring.d.mts +3 -3
  15. package/dist/internal/scoring.d.ts +3 -3
  16. package/dist/internal/scoring.js.map +1 -1
  17. package/dist/internal/toolCallScorer.js +42 -2
  18. package/dist/internal/toolCallScorer.js.map +1 -1
  19. package/dist/internal/toolCallScorer.mjs +42 -2
  20. package/dist/internal/toolCallScorer.mjs.map +1 -1
  21. package/dist/judges/factualityJudge.d.mts +151 -0
  22. package/dist/judges/factualityJudge.d.ts +151 -0
  23. package/dist/judges/factualityJudge.js +235 -0
  24. package/dist/judges/factualityJudge.js.map +1 -0
  25. package/dist/judges/factualityJudge.mjs +208 -0
  26. package/dist/judges/factualityJudge.mjs.map +1 -0
  27. package/dist/judges/index.d.mts +3 -1
  28. package/dist/judges/index.d.ts +3 -1
  29. package/dist/judges/index.js +447 -7
  30. package/dist/judges/index.js.map +1 -1
  31. package/dist/judges/index.mjs +443 -6
  32. package/dist/judges/index.mjs.map +1 -1
  33. package/dist/judges/judgeHarness.d.mts +122 -0
  34. package/dist/judges/judgeHarness.d.ts +122 -0
  35. package/dist/judges/judgeHarness.js +303 -0
  36. package/dist/judges/judgeHarness.js.map +1 -0
  37. package/dist/judges/judgeHarness.mjs +274 -0
  38. package/dist/judges/judgeHarness.mjs.map +1 -0
  39. package/dist/judges/structuredOutputJudge.d.mts +1 -0
  40. package/dist/judges/structuredOutputJudge.d.ts +1 -0
  41. package/dist/judges/toolCallJudge.d.mts +1 -0
  42. package/dist/judges/toolCallJudge.d.ts +1 -0
  43. package/dist/judges/toolCallJudge.js +42 -2
  44. package/dist/judges/toolCallJudge.js.map +1 -1
  45. package/dist/judges/toolCallJudge.mjs +42 -2
  46. package/dist/judges/toolCallJudge.mjs.map +1 -1
  47. package/dist/judges/types.d.mts +33 -6
  48. package/dist/judges/types.d.ts +33 -6
  49. package/dist/judges/types.js.map +1 -1
  50. package/dist/legacy/scorers/index.js +42 -2
  51. package/dist/legacy/scorers/index.js.map +1 -1
  52. package/dist/legacy/scorers/index.mjs +42 -2
  53. package/dist/legacy/scorers/index.mjs.map +1 -1
  54. package/dist/legacy/scorers/toolCallScorer.js +42 -2
  55. package/dist/legacy/scorers/toolCallScorer.js.map +1 -1
  56. package/dist/legacy/scorers/toolCallScorer.mjs +42 -2
  57. package/dist/legacy/scorers/toolCallScorer.mjs.map +1 -1
  58. package/dist/legacy.js +56 -3
  59. package/dist/legacy.js.map +1 -1
  60. package/dist/legacy.mjs +56 -3
  61. package/dist/legacy.mjs.map +1 -1
  62. package/dist/replay.js +1 -1
  63. package/dist/replay.js.map +1 -1
  64. package/dist/replay.mjs +1 -1
  65. package/dist/replay.mjs.map +1 -1
  66. package/dist/reporter.js.map +1 -1
  67. package/dist/reporter.mjs.map +1 -1
  68. package/package.json +1 -1
@@ -0,0 +1,151 @@
1
+ import { JsonValue, HarnessMetadata, Harness } from '../harness.mjs';
2
+ import { JudgeHarness } from './judgeHarness.mjs';
3
+ import { Judge, JudgeContext } from './types.mjs';
4
+
5
+ /**
6
+ * Rubric choice returned by a factuality judge model call.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * import type { FactualityJudgeChoice } from "vitest-evals";
11
+ *
12
+ * const choice: FactualityJudgeChoice = "C";
13
+ * ```
14
+ */
15
+ type FactualityJudgeChoice = "A" | "B" | "C" | "D" | "E";
16
+ /**
17
+ * Prompt payload sent to the configured judge harness.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * import type { FactualityJudgePrompt } from "vitest-evals";
22
+ *
23
+ * const payload: FactualityJudgePrompt = {
24
+ * system: "Grade factual consistency.",
25
+ * prompt: "Compare these answers.",
26
+ * };
27
+ * ```
28
+ */
29
+ type FactualityJudgePrompt = {
30
+ /** System prompt for the judge model. */
31
+ system: string;
32
+ /** User prompt containing the question, expert answer, submitted answer, and rubric. */
33
+ prompt: string;
34
+ };
35
+ /**
36
+ * Parsed verdict returned by a factuality judge model call.
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * import type { FactualityJudgeVerdict } from "vitest-evals";
41
+ *
42
+ * const verdict: FactualityJudgeVerdict = {
43
+ * choice: "C",
44
+ * rationale: "The submitted answer matches the expert answer.",
45
+ * };
46
+ * ```
47
+ */
48
+ type FactualityJudgeVerdict = {
49
+ /** Rubric choice selected by the judge model. */
50
+ choice: FactualityJudgeChoice;
51
+ /** Human-readable explanation for the selected choice. */
52
+ rationale: string;
53
+ };
54
+ /**
55
+ * Expert answer or reference facts accepted by `FactualityJudge()`.
56
+ *
57
+ * @example
58
+ * ```ts
59
+ * import type { FactualityJudgeExpected } from "vitest-evals";
60
+ *
61
+ * const expected: FactualityJudgeExpected =
62
+ * "Paris is the capital of France.";
63
+ * ```
64
+ */
65
+ type FactualityJudgeExpected = JsonValue;
66
+ /**
67
+ * Configuration for the factuality judge.
68
+ *
69
+ * The judge harness can be supplied here, by `describeEval({ judgeHarness })`,
70
+ * or by `expect(...).toSatisfyJudge(..., { judgeHarness })`. Passing it here
71
+ * keeps the judge self-contained while preserving provider neutrality.
72
+ *
73
+ * @example
74
+ * ```ts
75
+ * import { FactualityJudge, type JudgeHarness } from "vitest-evals";
76
+ *
77
+ * declare const judgeHarness: JudgeHarness;
78
+ *
79
+ * const judge = FactualityJudge({ name: "FactJudge", judgeHarness });
80
+ * ```
81
+ */
82
+ type FactualityJudgeConfig = {
83
+ /** Stable judge name used in assertion messages and reports. */
84
+ name?: string;
85
+ /** Default judge-side harness used when matcher options do not provide one. */
86
+ judgeHarness?: JudgeHarness;
87
+ };
88
+ /**
89
+ * Matcher context accepted by `FactualityJudge()`.
90
+ *
91
+ * @example
92
+ * ```ts
93
+ * import { aiSdkJudgeHarness } from "@vitest-evals/harness-ai-sdk";
94
+ * import { openai } from "@ai-sdk/openai";
95
+ * import { expect } from "vitest";
96
+ * import { FactualityJudge } from "vitest-evals";
97
+ *
98
+ * const judgeHarness = aiSdkJudgeHarness({
99
+ * model: openai("gpt-4.1-mini"),
100
+ * });
101
+ *
102
+ * await expect(result).toSatisfyJudge(FactualityJudge(), {
103
+ * expected: "Paris is the capital of France.",
104
+ * judgeHarness,
105
+ * });
106
+ * ```
107
+ */
108
+ type FactualityJudgeOptions<TInput = any, TOutput extends JsonValue | undefined = JsonValue | undefined, TMetadata extends HarnessMetadata = HarnessMetadata, THarness extends Harness<TInput, TOutput, TMetadata> | undefined = Harness<TInput, TOutput, TMetadata> | undefined> = JudgeContext<TInput, TOutput, TMetadata, THarness> & {
109
+ /** Expert answer or reference facts. Defaults to `metadata.expected`. */
110
+ expected?: FactualityJudgeExpected;
111
+ };
112
+ /**
113
+ * Creates a factuality judge over normalized harness output.
114
+ *
115
+ * `FactualityJudge()` compares `input`, `output`, and `expected` from the
116
+ * current `JudgeContext`, so the same judge can run against any application
117
+ * harness. Configure the LLM used for grading with `judgeHarness` on the
118
+ * judge, suite, or matcher options.
119
+ *
120
+ * @param config - Optional judge name and reusable judge harness default.
121
+ *
122
+ * @example
123
+ * ```ts
124
+ * import { anthropic } from "@ai-sdk/anthropic";
125
+ * import { aiSdkJudgeHarness } from "@vitest-evals/harness-ai-sdk";
126
+ * import { describeEval, FactualityJudge } from "vitest-evals";
127
+ * import { qaHarness } from "./qaHarness";
128
+ *
129
+ * const judgeHarness = aiSdkJudgeHarness({
130
+ * model: anthropic("claude-sonnet-4-5"),
131
+ * temperature: 0,
132
+ * });
133
+ * const factualityJudge = FactualityJudge({ judgeHarness });
134
+ *
135
+ * describeEval("qa agent", {
136
+ * harness: qaHarness,
137
+ * judges: [factualityJudge],
138
+ * }, (it) => {
139
+ * it("answers a geography question", async ({ run }) => {
140
+ * await run("What is the capital of France?", {
141
+ * metadata: {
142
+ * expected: "Paris is the capital of France.",
143
+ * },
144
+ * });
145
+ * });
146
+ * });
147
+ * ```
148
+ */
149
+ declare function FactualityJudge(config?: FactualityJudgeConfig): Judge<FactualityJudgeOptions>;
150
+
151
+ export { FactualityJudge, type FactualityJudgeChoice, type FactualityJudgeConfig, type FactualityJudgeExpected, type FactualityJudgeOptions, type FactualityJudgePrompt, type FactualityJudgeVerdict };
@@ -0,0 +1,151 @@
1
+ import { JsonValue, HarnessMetadata, Harness } from '../harness.js';
2
+ import { JudgeHarness } from './judgeHarness.js';
3
+ import { Judge, JudgeContext } from './types.js';
4
+
5
+ /**
6
+ * Rubric choice returned by a factuality judge model call.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * import type { FactualityJudgeChoice } from "vitest-evals";
11
+ *
12
+ * const choice: FactualityJudgeChoice = "C";
13
+ * ```
14
+ */
15
+ type FactualityJudgeChoice = "A" | "B" | "C" | "D" | "E";
16
+ /**
17
+ * Prompt payload sent to the configured judge harness.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * import type { FactualityJudgePrompt } from "vitest-evals";
22
+ *
23
+ * const payload: FactualityJudgePrompt = {
24
+ * system: "Grade factual consistency.",
25
+ * prompt: "Compare these answers.",
26
+ * };
27
+ * ```
28
+ */
29
+ type FactualityJudgePrompt = {
30
+ /** System prompt for the judge model. */
31
+ system: string;
32
+ /** User prompt containing the question, expert answer, submitted answer, and rubric. */
33
+ prompt: string;
34
+ };
35
+ /**
36
+ * Parsed verdict returned by a factuality judge model call.
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * import type { FactualityJudgeVerdict } from "vitest-evals";
41
+ *
42
+ * const verdict: FactualityJudgeVerdict = {
43
+ * choice: "C",
44
+ * rationale: "The submitted answer matches the expert answer.",
45
+ * };
46
+ * ```
47
+ */
48
+ type FactualityJudgeVerdict = {
49
+ /** Rubric choice selected by the judge model. */
50
+ choice: FactualityJudgeChoice;
51
+ /** Human-readable explanation for the selected choice. */
52
+ rationale: string;
53
+ };
54
+ /**
55
+ * Expert answer or reference facts accepted by `FactualityJudge()`.
56
+ *
57
+ * @example
58
+ * ```ts
59
+ * import type { FactualityJudgeExpected } from "vitest-evals";
60
+ *
61
+ * const expected: FactualityJudgeExpected =
62
+ * "Paris is the capital of France.";
63
+ * ```
64
+ */
65
+ type FactualityJudgeExpected = JsonValue;
66
+ /**
67
+ * Configuration for the factuality judge.
68
+ *
69
+ * The judge harness can be supplied here, by `describeEval({ judgeHarness })`,
70
+ * or by `expect(...).toSatisfyJudge(..., { judgeHarness })`. Passing it here
71
+ * keeps the judge self-contained while preserving provider neutrality.
72
+ *
73
+ * @example
74
+ * ```ts
75
+ * import { FactualityJudge, type JudgeHarness } from "vitest-evals";
76
+ *
77
+ * declare const judgeHarness: JudgeHarness;
78
+ *
79
+ * const judge = FactualityJudge({ name: "FactJudge", judgeHarness });
80
+ * ```
81
+ */
82
+ type FactualityJudgeConfig = {
83
+ /** Stable judge name used in assertion messages and reports. */
84
+ name?: string;
85
+ /** Default judge-side harness used when matcher options do not provide one. */
86
+ judgeHarness?: JudgeHarness;
87
+ };
88
+ /**
89
+ * Matcher context accepted by `FactualityJudge()`.
90
+ *
91
+ * @example
92
+ * ```ts
93
+ * import { aiSdkJudgeHarness } from "@vitest-evals/harness-ai-sdk";
94
+ * import { openai } from "@ai-sdk/openai";
95
+ * import { expect } from "vitest";
96
+ * import { FactualityJudge } from "vitest-evals";
97
+ *
98
+ * const judgeHarness = aiSdkJudgeHarness({
99
+ * model: openai("gpt-4.1-mini"),
100
+ * });
101
+ *
102
+ * await expect(result).toSatisfyJudge(FactualityJudge(), {
103
+ * expected: "Paris is the capital of France.",
104
+ * judgeHarness,
105
+ * });
106
+ * ```
107
+ */
108
+ type FactualityJudgeOptions<TInput = any, TOutput extends JsonValue | undefined = JsonValue | undefined, TMetadata extends HarnessMetadata = HarnessMetadata, THarness extends Harness<TInput, TOutput, TMetadata> | undefined = Harness<TInput, TOutput, TMetadata> | undefined> = JudgeContext<TInput, TOutput, TMetadata, THarness> & {
109
+ /** Expert answer or reference facts. Defaults to `metadata.expected`. */
110
+ expected?: FactualityJudgeExpected;
111
+ };
112
+ /**
113
+ * Creates a factuality judge over normalized harness output.
114
+ *
115
+ * `FactualityJudge()` compares `input`, `output`, and `expected` from the
116
+ * current `JudgeContext`, so the same judge can run against any application
117
+ * harness. Configure the LLM used for grading with `judgeHarness` on the
118
+ * judge, suite, or matcher options.
119
+ *
120
+ * @param config - Optional judge name and reusable judge harness default.
121
+ *
122
+ * @example
123
+ * ```ts
124
+ * import { anthropic } from "@ai-sdk/anthropic";
125
+ * import { aiSdkJudgeHarness } from "@vitest-evals/harness-ai-sdk";
126
+ * import { describeEval, FactualityJudge } from "vitest-evals";
127
+ * import { qaHarness } from "./qaHarness";
128
+ *
129
+ * const judgeHarness = aiSdkJudgeHarness({
130
+ * model: anthropic("claude-sonnet-4-5"),
131
+ * temperature: 0,
132
+ * });
133
+ * const factualityJudge = FactualityJudge({ judgeHarness });
134
+ *
135
+ * describeEval("qa agent", {
136
+ * harness: qaHarness,
137
+ * judges: [factualityJudge],
138
+ * }, (it) => {
139
+ * it("answers a geography question", async ({ run }) => {
140
+ * await run("What is the capital of France?", {
141
+ * metadata: {
142
+ * expected: "Paris is the capital of France.",
143
+ * },
144
+ * });
145
+ * });
146
+ * });
147
+ * ```
148
+ */
149
+ declare function FactualityJudge(config?: FactualityJudgeConfig): Judge<FactualityJudgeOptions>;
150
+
151
+ export { FactualityJudge, type FactualityJudgeChoice, type FactualityJudgeConfig, type FactualityJudgeExpected, type FactualityJudgeOptions, type FactualityJudgePrompt, type FactualityJudgeVerdict };
@@ -0,0 +1,235 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/judges/factualityJudge.ts
21
+ var factualityJudge_exports = {};
22
+ __export(factualityJudge_exports, {
23
+ FactualityJudge: () => FactualityJudge
24
+ });
25
+ module.exports = __toCommonJS(factualityJudge_exports);
26
+
27
+ // src/harness.ts
28
+ function messagesByRole(session, role) {
29
+ return session.messages.filter((message) => message.role === role);
30
+ }
31
+ function hasNonEmptyMessageContent(message) {
32
+ return message.content !== void 0 && (typeof message.content !== "string" || message.content.trim().length > 0);
33
+ }
34
+ function assistantMessages(session) {
35
+ return messagesByRole(session, "assistant");
36
+ }
37
+ function latestAssistantMessageContent(session) {
38
+ return [...assistantMessages(session)].reverse().find(hasNonEmptyMessageContent)?.content;
39
+ }
40
+
41
+ // src/judges/judgeHarness.ts
42
+ async function runJudgeHarness(judgeHarness, input, options = {}) {
43
+ const artifacts = {};
44
+ const run = await judgeHarness.run(input, {
45
+ metadata: options.metadata ?? {},
46
+ signal: options.signal,
47
+ artifacts,
48
+ setArtifact: (name, value) => {
49
+ artifacts[name] = value;
50
+ }
51
+ });
52
+ return run.output !== void 0 ? run.output : resolveJudgeHarnessAssistantOutput(run);
53
+ }
54
+ function createRunJudge(judgeHarness, signal) {
55
+ if (!judgeHarness) {
56
+ return void 0;
57
+ }
58
+ return (input, options) => runJudgeHarness(judgeHarness, input, {
59
+ metadata: options?.metadata,
60
+ signal
61
+ });
62
+ }
63
+ function resolveJudgeHarnessAssistantOutput(run) {
64
+ return latestAssistantMessageContent(run.session) ?? "";
65
+ }
66
+
67
+ // src/judges/factualityJudge.ts
68
+ var FACTUALITY_CHOICE_SCORES = {
69
+ A: 0.4,
70
+ B: 0.6,
71
+ C: 1,
72
+ D: 0,
73
+ E: 1
74
+ };
75
+ var FACTUALITY_SYSTEM = "You are comparing factual content. Ignore differences in style, grammar, punctuation, and formatting.";
76
+ var FACTUALITY_RESPONSE_SCHEMA = {
77
+ type: "object",
78
+ additionalProperties: false,
79
+ required: ["choice", "rationale"],
80
+ properties: {
81
+ choice: {
82
+ enum: ["A", "B", "C", "D", "E"]
83
+ },
84
+ rationale: {
85
+ type: "string"
86
+ }
87
+ }
88
+ };
89
+ function FactualityJudge(config = {}) {
90
+ const judgeHarness = config.judgeHarness;
91
+ return {
92
+ name: config.name ?? "FactualityJudge",
93
+ judgeHarness,
94
+ assess: (opts) => assessFactuality(opts, judgeHarness)
95
+ };
96
+ }
97
+ async function assessFactuality(opts, configuredJudgeHarness) {
98
+ const metadata = opts.metadata;
99
+ const expected = opts.expected === void 0 ? metadata.expected : opts.expected;
100
+ if (isMissingExpectedAnswer(expected)) {
101
+ return {
102
+ score: 0,
103
+ metadata: {
104
+ rationale: "FactualityJudge requires a non-empty expert answer in `expected` or `metadata.expected`."
105
+ }
106
+ };
107
+ }
108
+ const runJudge = opts.runJudge ?? createRunJudge(
109
+ configuredJudgeHarness,
110
+ opts.signal
111
+ );
112
+ if (!runJudge) {
113
+ throw new Error(
114
+ "FactualityJudge requires a judgeHarness in FactualityJudge(...) config, describeEval(...) options, toSatisfyJudge(...) options, or JudgeContext.runJudge."
115
+ );
116
+ }
117
+ const verdict = await runJudge({
118
+ system: FACTUALITY_SYSTEM,
119
+ prompt: formatFactualityPrompt({
120
+ input: opts.input,
121
+ expected,
122
+ output: resolveJudgeOutput(opts)
123
+ }),
124
+ responseFormat: {
125
+ type: "json",
126
+ schema: FACTUALITY_RESPONSE_SCHEMA
127
+ }
128
+ });
129
+ return formatJudgeResult(parseFactualityJudgeVerdict(verdict));
130
+ }
131
+ function isMissingExpectedAnswer(value) {
132
+ return value == null || typeof value === "string" && value.trim().length === 0;
133
+ }
134
+ function resolveJudgeOutput(opts) {
135
+ if (opts.output !== void 0) {
136
+ return opts.output;
137
+ }
138
+ return latestAssistantMessageContent(opts.session) ?? "";
139
+ }
140
+ function parseFactualityJudgeVerdict(value) {
141
+ const parsed = typeof value === "string" ? parseJsonObject(value) : value;
142
+ if (!parsed || typeof parsed !== "object") {
143
+ throw new Error(
144
+ "FactualityJudge judgeHarness must return an object with `choice` and `rationale`."
145
+ );
146
+ }
147
+ const verdict = parsed;
148
+ if (!isFactualityChoice(verdict.choice)) {
149
+ throw new Error(
150
+ "FactualityJudge judgeHarness must return choice A, B, C, D, or E."
151
+ );
152
+ }
153
+ if (typeof verdict.rationale !== "string") {
154
+ throw new Error(
155
+ "FactualityJudge judgeHarness must return a string `rationale`."
156
+ );
157
+ }
158
+ return {
159
+ choice: verdict.choice,
160
+ rationale: verdict.rationale
161
+ };
162
+ }
163
+ function parseJsonObject(value) {
164
+ try {
165
+ return JSON.parse(value);
166
+ } catch {
167
+ const fencedJson = value.match(/```(?:json)?\s*([\s\S]*?)\s*```/i);
168
+ if (!fencedJson) {
169
+ throw new Error(
170
+ "FactualityJudge judgeHarness must return JSON with `choice` and `rationale`."
171
+ );
172
+ }
173
+ return JSON.parse(fencedJson[1]);
174
+ }
175
+ }
176
+ function isFactualityChoice(value) {
177
+ return value === "A" || value === "B" || value === "C" || value === "D" || value === "E";
178
+ }
179
+ function formatFactualityPrompt({
180
+ input,
181
+ expected,
182
+ output
183
+ }) {
184
+ const comparison = formatJudgeValue({
185
+ question: input ?? "",
186
+ expert_answer: expected,
187
+ submitted_answer: output ?? ""
188
+ });
189
+ return `Compare the submitted answer with the expert answer.
190
+
191
+ Comparison payload:
192
+ ${comparison}
193
+
194
+ Select exactly one option:
195
+ A: The submission is a fully consistent subset of the expert answer.
196
+ B: The submission is a fully consistent superset of the expert answer.
197
+ C: The submission contains the same factual details as the expert answer.
198
+ D: The submission disagrees with the expert answer.
199
+ E: The answers differ only in ways that do not affect factuality.
200
+
201
+ Return JSON with exactly these fields:
202
+ {
203
+ "choice": "C",
204
+ "rationale": "Brief explanation for the selected choice"
205
+ }
206
+
207
+ The choice value must be one of A, B, C, D, or E.`;
208
+ }
209
+ function formatJudgeValue(value) {
210
+ if (typeof value === "string") {
211
+ return value;
212
+ }
213
+ if (value === void 0) {
214
+ return "";
215
+ }
216
+ try {
217
+ return JSON.stringify(value, null, 2) ?? String(value);
218
+ } catch {
219
+ return String(value);
220
+ }
221
+ }
222
+ function formatJudgeResult(object) {
223
+ return {
224
+ score: FACTUALITY_CHOICE_SCORES[object.choice],
225
+ metadata: {
226
+ rationale: object.rationale,
227
+ choice: object.choice
228
+ }
229
+ };
230
+ }
231
+ // Annotate the CommonJS export names for ESM import in node:
232
+ 0 && (module.exports = {
233
+ FactualityJudge
234
+ });
235
+ //# sourceMappingURL=factualityJudge.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/judges/factualityJudge.ts","../../src/harness.ts","../../src/judges/judgeHarness.ts"],"sourcesContent":["import {\n type Harness,\n type HarnessMetadata,\n latestAssistantMessageContent,\n} from \"../harness\";\nimport type { JsonValue } from \"../harness\";\nimport { createRunJudge } from \"./judgeHarness\";\nimport type { JudgeHarness } from \"./judgeHarness\";\nimport type { Judge, JudgeContext, JudgeResult } from \"./types\";\n\n/**\n * Rubric choice returned by a factuality judge model call.\n *\n * @example\n * ```ts\n * import type { FactualityJudgeChoice } from \"vitest-evals\";\n *\n * const choice: FactualityJudgeChoice = \"C\";\n * ```\n */\nexport type FactualityJudgeChoice = \"A\" | \"B\" | \"C\" | \"D\" | \"E\";\n\n/**\n * Prompt payload sent to the configured judge harness.\n *\n * @example\n * ```ts\n * import type { FactualityJudgePrompt } from \"vitest-evals\";\n *\n * const payload: FactualityJudgePrompt = {\n * system: \"Grade factual consistency.\",\n * prompt: \"Compare these answers.\",\n * };\n * ```\n */\nexport type FactualityJudgePrompt = {\n /** System prompt for the judge model. */\n system: string;\n /** User prompt containing the question, expert answer, submitted answer, and rubric. */\n prompt: string;\n};\n\n/**\n * Parsed verdict returned by a factuality judge model call.\n *\n * @example\n * ```ts\n * import type { FactualityJudgeVerdict } from \"vitest-evals\";\n *\n * const verdict: FactualityJudgeVerdict = {\n * choice: \"C\",\n * rationale: \"The submitted answer matches the expert answer.\",\n * };\n * ```\n */\nexport type FactualityJudgeVerdict = {\n /** Rubric choice selected by the judge model. */\n choice: FactualityJudgeChoice;\n /** Human-readable explanation for the selected choice. */\n rationale: string;\n};\n\nconst FACTUALITY_CHOICE_SCORES: Record<FactualityJudgeChoice, number> = {\n A: 0.4,\n B: 0.6,\n C: 1,\n D: 0,\n E: 1,\n};\n\nconst FACTUALITY_SYSTEM =\n \"You are comparing factual content. Ignore differences in style, grammar, punctuation, and formatting.\";\n\nconst FACTUALITY_RESPONSE_SCHEMA = {\n type: \"object\",\n additionalProperties: false,\n required: [\"choice\", \"rationale\"],\n properties: {\n choice: {\n enum: [\"A\", \"B\", \"C\", \"D\", \"E\"],\n },\n rationale: {\n type: \"string\",\n },\n },\n} as const satisfies JsonValue;\n\n/**\n * Expert answer or reference facts accepted by `FactualityJudge()`.\n *\n * @example\n * ```ts\n * import type { FactualityJudgeExpected } from \"vitest-evals\";\n *\n * const expected: FactualityJudgeExpected =\n * \"Paris is the capital of France.\";\n * ```\n */\nexport type FactualityJudgeExpected = JsonValue;\n\n/**\n * Configuration for the factuality judge.\n *\n * The judge harness can be supplied here, by `describeEval({ judgeHarness })`,\n * or by `expect(...).toSatisfyJudge(..., { judgeHarness })`. Passing it here\n * keeps the judge self-contained while preserving provider neutrality.\n *\n * @example\n * ```ts\n * import { FactualityJudge, type JudgeHarness } from \"vitest-evals\";\n *\n * declare const judgeHarness: JudgeHarness;\n *\n * const judge = FactualityJudge({ name: \"FactJudge\", judgeHarness });\n * ```\n */\nexport type FactualityJudgeConfig = {\n /** Stable judge name used in assertion messages and reports. */\n name?: string;\n /** Default judge-side harness used when matcher options do not provide one. */\n judgeHarness?: JudgeHarness;\n};\n\ntype FactualityJudgeMetadata = HarnessMetadata & {\n expected?: FactualityJudgeExpected;\n};\n\n/**\n * Matcher context accepted by `FactualityJudge()`.\n *\n * @example\n * ```ts\n * import { aiSdkJudgeHarness } from \"@vitest-evals/harness-ai-sdk\";\n * import { openai } from \"@ai-sdk/openai\";\n * import { expect } from \"vitest\";\n * import { FactualityJudge } from \"vitest-evals\";\n *\n * const judgeHarness = aiSdkJudgeHarness({\n * model: openai(\"gpt-4.1-mini\"),\n * });\n *\n * await expect(result).toSatisfyJudge(FactualityJudge(), {\n * expected: \"Paris is the capital of France.\",\n * judgeHarness,\n * });\n * ```\n */\nexport type FactualityJudgeOptions<\n TInput = any,\n TOutput extends JsonValue | undefined = JsonValue | undefined,\n TMetadata extends HarnessMetadata = HarnessMetadata,\n THarness extends Harness<TInput, TOutput, TMetadata> | undefined =\n | Harness<TInput, TOutput, TMetadata>\n | undefined,\n> = JudgeContext<TInput, TOutput, TMetadata, THarness> & {\n /** Expert answer or reference facts. Defaults to `metadata.expected`. */\n expected?: FactualityJudgeExpected;\n};\n\n/**\n * Creates a factuality judge over normalized harness output.\n *\n * `FactualityJudge()` compares `input`, `output`, and `expected` from the\n * current `JudgeContext`, so the same judge can run against any application\n * harness. Configure the LLM used for grading with `judgeHarness` on the\n * judge, suite, or matcher options.\n *\n * @param config - Optional judge name and reusable judge harness default.\n *\n * @example\n * ```ts\n * import { anthropic } from \"@ai-sdk/anthropic\";\n * import { aiSdkJudgeHarness } from \"@vitest-evals/harness-ai-sdk\";\n * import { describeEval, FactualityJudge } from \"vitest-evals\";\n * import { qaHarness } from \"./qaHarness\";\n *\n * const judgeHarness = aiSdkJudgeHarness({\n * model: anthropic(\"claude-sonnet-4-5\"),\n * temperature: 0,\n * });\n * const factualityJudge = FactualityJudge({ judgeHarness });\n *\n * describeEval(\"qa agent\", {\n * harness: qaHarness,\n * judges: [factualityJudge],\n * }, (it) => {\n * it(\"answers a geography question\", async ({ run }) => {\n * await run(\"What is the capital of France?\", {\n * metadata: {\n * expected: \"Paris is the capital of France.\",\n * },\n * });\n * });\n * });\n * ```\n */\nexport function FactualityJudge(\n config: FactualityJudgeConfig = {},\n): Judge<FactualityJudgeOptions> {\n const judgeHarness = config.judgeHarness;\n\n return {\n name: config.name ?? \"FactualityJudge\",\n judgeHarness,\n assess: (opts) => assessFactuality(opts, judgeHarness),\n };\n}\n\nasync function assessFactuality(\n opts: FactualityJudgeOptions,\n configuredJudgeHarness: JudgeHarness | undefined,\n) {\n const metadata = opts.metadata as FactualityJudgeMetadata;\n const expected =\n opts.expected === undefined ? metadata.expected : opts.expected;\n\n if (isMissingExpectedAnswer(expected)) {\n return {\n score: 0,\n metadata: {\n rationale:\n \"FactualityJudge requires a non-empty expert answer in `expected` or `metadata.expected`.\",\n },\n };\n }\n\n const runJudge =\n opts.runJudge ??\n createRunJudge(\n configuredJudgeHarness,\n (opts as { signal?: AbortSignal }).signal,\n );\n\n if (!runJudge) {\n throw new Error(\n \"FactualityJudge requires a judgeHarness in FactualityJudge(...) config, describeEval(...) options, toSatisfyJudge(...) options, or JudgeContext.runJudge.\",\n );\n }\n\n const verdict = await runJudge({\n system: FACTUALITY_SYSTEM,\n prompt: formatFactualityPrompt({\n input: opts.input,\n expected,\n output: resolveJudgeOutput(opts),\n }),\n responseFormat: {\n type: \"json\",\n schema: FACTUALITY_RESPONSE_SCHEMA,\n },\n });\n\n return formatJudgeResult(parseFactualityJudgeVerdict(verdict));\n}\n\nfunction isMissingExpectedAnswer(value: FactualityJudgeExpected | undefined) {\n return (\n value == null || (typeof value === \"string\" && value.trim().length === 0)\n );\n}\n\nfunction resolveJudgeOutput(opts: FactualityJudgeOptions) {\n if (opts.output !== undefined) {\n return opts.output;\n }\n\n return latestAssistantMessageContent(opts.session) ?? \"\";\n}\n\nfunction parseFactualityJudgeVerdict(value: unknown): FactualityJudgeVerdict {\n const parsed = typeof value === \"string\" ? parseJsonObject(value) : value;\n\n if (!parsed || typeof parsed !== \"object\") {\n throw new Error(\n \"FactualityJudge judgeHarness must return an object with `choice` and `rationale`.\",\n );\n }\n\n const verdict = parsed as Record<string, unknown>;\n if (!isFactualityChoice(verdict.choice)) {\n throw new Error(\n \"FactualityJudge judgeHarness must return choice A, B, C, D, or E.\",\n );\n }\n\n if (typeof verdict.rationale !== \"string\") {\n throw new Error(\n \"FactualityJudge judgeHarness must return a string `rationale`.\",\n );\n }\n\n return {\n choice: verdict.choice,\n rationale: verdict.rationale,\n };\n}\n\nfunction parseJsonObject(value: string) {\n try {\n return JSON.parse(value);\n } catch {\n const fencedJson = value.match(/```(?:json)?\\s*([\\s\\S]*?)\\s*```/i);\n if (!fencedJson) {\n throw new Error(\n \"FactualityJudge judgeHarness must return JSON with `choice` and `rationale`.\",\n );\n }\n\n return JSON.parse(fencedJson[1]);\n }\n}\n\nfunction isFactualityChoice(value: unknown): value is FactualityJudgeChoice {\n return (\n value === \"A\" ||\n value === \"B\" ||\n value === \"C\" ||\n value === \"D\" ||\n value === \"E\"\n );\n}\n\nfunction formatFactualityPrompt({\n input,\n expected,\n output,\n}: {\n input: unknown;\n expected: unknown;\n output: unknown;\n}) {\n const comparison = formatJudgeValue({\n question: input ?? \"\",\n expert_answer: expected,\n submitted_answer: output ?? \"\",\n });\n\n return `Compare the submitted answer with the expert answer.\n\nComparison payload:\n${comparison}\n\nSelect exactly one option:\nA: The submission is a fully consistent subset of the expert answer.\nB: The submission is a fully consistent superset of the expert answer.\nC: The submission contains the same factual details as the expert answer.\nD: The submission disagrees with the expert answer.\nE: The answers differ only in ways that do not affect factuality.\n\nReturn JSON with exactly these fields:\n{\n \"choice\": \"C\",\n \"rationale\": \"Brief explanation for the selected choice\"\n}\n\nThe choice value must be one of A, B, C, D, or E.`;\n}\n\nfunction formatJudgeValue(value: unknown) {\n if (typeof value === \"string\") {\n return value;\n }\n\n if (value === undefined) {\n return \"\";\n }\n\n try {\n return JSON.stringify(value, null, 2) ?? String(value);\n } catch {\n return String(value);\n }\n}\n\nfunction formatJudgeResult(object: FactualityJudgeVerdict): JudgeResult {\n return {\n score: FACTUALITY_CHOICE_SCORES[object.choice],\n metadata: {\n rationale: object.rationale,\n choice: object.choice,\n },\n };\n}\n","/** Primitive scalar values allowed in normalized JSON-safe eval data. */\nexport type JsonPrimitive = string | number | boolean | null;\n\n/** JSON-safe value shape used by normalized sessions, artifacts, and errors. */\nexport type JsonValue =\n | JsonPrimitive\n | JsonValue[]\n | { [key: string]: JsonValue };\n\n/**\n * Normalized record for one tool call observed during a harness run.\n *\n * @example\n * ```ts\n * const call: ToolCallRecord = {\n * name: \"lookupInvoice\",\n * arguments: { invoiceId: \"inv_123\" },\n * result: { refundable: true },\n * };\n * ```\n */\nexport type ToolCallRecord = {\n /** Provider or runtime tool-call id when one is available. */\n id?: string;\n /** Tool name as exposed to the agent or application runtime. */\n name: string;\n /** JSON-safe tool arguments after provider/runtime normalization. */\n arguments?: Record<string, JsonValue>;\n /** JSON-safe tool result returned by the application tool. */\n result?: JsonValue;\n /** Normalized tool error when execution failed. */\n error?: {\n message: string;\n type?: string;\n [key: string]: JsonValue | undefined;\n };\n /** ISO timestamp for the start of tool execution. */\n startedAt?: string;\n /** ISO timestamp for the end of tool execution. */\n finishedAt?: string;\n /** Tool execution duration in milliseconds. */\n durationMs?: number;\n /** Extra JSON-safe tool metadata for reporters and custom judges. */\n metadata?: Record<string, JsonValue>;\n};\n\n/**\n * Normalized message recorded in a harness session transcript.\n *\n * @example\n * ```ts\n * const message: NormalizedMessage = {\n * role: \"assistant\",\n * content: { status: \"approved\" },\n * toolCalls: [{ name: \"lookupInvoice\" }],\n * };\n * ```\n */\nexport type NormalizedMessage = {\n /** Transcript role for the normalized message. */\n role: \"system\" | \"user\" | \"assistant\" | \"tool\";\n /** JSON-safe message content. */\n content?: JsonValue;\n /** Tool calls associated with this message. */\n toolCalls?: ToolCallRecord[];\n /** Extra JSON-safe message metadata. */\n metadata?: Record<string, JsonValue>;\n};\n\n/**\n * Provider usage summary attached to a normalized harness run.\n *\n * @example\n * ```ts\n * const usage: UsageSummary = {\n * provider: \"openai\",\n * model: \"gpt-4o-mini\",\n * inputTokens: 212,\n * outputTokens: 48,\n * totalTokens: 260,\n * };\n * ```\n */\nexport type UsageSummary = {\n /** Provider that served the application run. */\n provider?: string;\n /** Model used for the application run. */\n model?: string;\n /** Input, prompt, or request tokens consumed by the run. */\n inputTokens?: number;\n /** Output or completion tokens produced by the run. */\n outputTokens?: number;\n /** Reasoning tokens reported by providers that expose them. */\n reasoningTokens?: number;\n /** Total token count reported by the provider or adapter. */\n totalTokens?: number;\n /** Count of tool calls observed during the run. */\n toolCalls?: number;\n /** Retry count observed during the run. */\n retries?: number;\n /** Provider-specific JSON-safe usage details. Cost estimates belong here. */\n metadata?: Record<string, JsonValue>;\n};\n\n/** Timing summary attached to a normalized harness run. */\nexport type TimingSummary = {\n /** End-to-end run duration in milliseconds. */\n totalMs?: number;\n /** Extra JSON-safe timing metadata. */\n metadata?: Record<string, JsonValue>;\n};\n\n/**\n * JSON-serializable transcript produced by the system under test.\n *\n * @example\n * ```ts\n * const session: NormalizedSession = {\n * provider: \"openai\",\n * model: \"gpt-4o-mini\",\n * messages: [\n * { role: \"user\", content: \"Refund invoice inv_123\" },\n * { role: \"assistant\", content: { status: \"approved\" } },\n * ],\n * };\n * ```\n */\nexport type NormalizedSession = {\n /** Ordered normalized transcript messages. */\n messages: NormalizedMessage[];\n /** Provider that produced the session when known. */\n provider?: string;\n /** Model that produced the session when known. */\n model?: string;\n /** Extra JSON-safe session metadata. */\n metadata?: Record<string, JsonValue>;\n};\n\ntype OutputField<TOutput extends JsonValue | undefined> =\n undefined extends TOutput ? { output?: TOutput } : { output: TOutput };\n\n/**\n * Normalized result returned by every harness execution.\n *\n * @example\n * ```ts\n * const run: HarnessRun<{ status: \"approved\" }> = {\n * output: { status: \"approved\" },\n * session: {\n * messages: [\n * { role: \"user\", content: \"Refund invoice inv_123\" },\n * { role: \"assistant\", content: { status: \"approved\" } },\n * ],\n * },\n * usage: { totalTokens: 260 },\n * errors: [],\n * };\n * ```\n */\nexport type HarnessRun<\n TOutput extends JsonValue | undefined = JsonValue | undefined,\n> = OutputField<TOutput> & {\n /** Normalized transcript and provider/session metadata. */\n session: NormalizedSession;\n /** Stable provider usage units such as tokens, tools, and retries. */\n usage: UsageSummary;\n /** Optional timing summary for the run. */\n timings?: TimingSummary;\n /** JSON-safe run artifacts captured by the harness or test context. */\n artifacts?: Record<string, JsonValue>;\n /** Normalized errors captured during execution. */\n errors: Array<Record<string, JsonValue>>;\n};\n\n/** Error value with an attached partial or complete normalized harness run. */\nexport type HarnessRunError = Error & {\n /** Attached normalized harness run recovered by `getHarnessRunFromError(...)`. */\n vitestEvalsRun: HarnessRun;\n};\n\n/** Per-run metadata shape accepted by harnesses and eval tests. */\nexport type HarnessMetadata = Record<string, unknown>;\n\n/**\n * Runtime context passed from the eval fixture into a harness run.\n *\n * @example\n * ```ts\n * const harness: Harness<string> = {\n * name: \"refund-agent\",\n * async run(input, context) {\n * context.setArtifact(\"inputLength\", input.length);\n *\n * return {\n * output: undefined,\n * session: { messages: [{ role: \"user\", content: input }] },\n * usage: {},\n * errors: [],\n * };\n * },\n * };\n * ```\n */\nexport type HarnessContext<\n TMetadata extends HarnessMetadata = HarnessMetadata,\n> = {\n /** Per-run metadata passed through `run(input, { metadata })`. */\n metadata: Readonly<TMetadata>;\n /** Abort signal from Vitest when available. */\n signal?: AbortSignal;\n /** Mutable JSON-safe artifact bag shared with the harness. */\n artifacts: Record<string, JsonValue>;\n /** Stores one JSON-safe artifact on the current run. */\n setArtifact: (name: string, value: JsonValue) => void;\n};\n\n/**\n * Adapter that executes the system under test and returns a normalized run.\n *\n * @example\n * ```ts\n * const harness: Harness<string, { status: \"approved\" | \"denied\" }> = {\n * name: \"refund-agent\",\n * async run(input, context) {\n * return normalizeHarnessRun(input, await runRefundFlow(input), context);\n * },\n * };\n * ```\n */\nexport type Harness<\n TInput = unknown,\n TOutput extends JsonValue | undefined = JsonValue | undefined,\n TMetadata extends HarnessMetadata = HarnessMetadata,\n> = {\n /** Stable harness name used in reports. */\n name: string;\n /** Executes the system under test and returns a normalized run. */\n run: (\n input: TInput,\n context: HarnessContext<TMetadata>,\n ) => Promise<HarnessRun<TOutput>>;\n};\n\n/** Value or promise accepted by lightweight harness callbacks. */\nexport type MaybePromise<T> = T | Promise<T>;\n\n/** Lightweight tool-call record accepted by `createHarness(...)` results. */\nexport type SimpleToolCallRecord = Omit<\n ToolCallRecord,\n \"arguments\" | \"result\" | \"error\" | \"metadata\"\n> & {\n /** Raw tool arguments accepted by `createHarness(...)` before normalization. */\n arguments?: unknown;\n /** Raw tool result accepted by `createHarness(...)` before normalization. */\n result?: unknown;\n /** Raw tool error accepted by `createHarness(...)` before normalization. */\n error?: unknown;\n /** Raw tool metadata accepted by `createHarness(...)` before normalization. */\n metadata?: Record<string, unknown>;\n};\n\n/**\n * Lightweight result shape normalized by `createHarness(...)`.\n *\n * @example\n * ```ts\n * const result: SimpleHarnessResult<{ status: \"approved\" }> = {\n * output: { status: \"approved\" },\n * toolCalls: [{ name: \"lookupInvoice\", arguments: { invoiceId: \"inv_123\" } }],\n * usage: { totalTokens: 260 },\n * };\n * ```\n */\nexport type SimpleHarnessResult<\n TOutput extends JsonValue | undefined = JsonValue | undefined,\n> = OutputField<TOutput> & {\n /** Pre-normalized transcript messages. When omitted, a default user/assistant transcript is created. */\n messages?: NormalizedMessage[];\n /** Lightweight tool-call records to normalize into the session. */\n toolCalls?: SimpleToolCallRecord[];\n /** Usage summary to attach to the run. */\n usage?: UsageSummary;\n /** Timing summary to attach to the run. */\n timings?: TimingSummary;\n /** Raw artifact values to normalize and merge into the run. */\n artifacts?: Record<string, unknown>;\n /** Raw session metadata to normalize into the session. */\n metadata?: Record<string, unknown>;\n /** Raw errors to normalize into the run. */\n errors?: unknown[];\n};\n\n/** Either a complete normalized run or a lightweight result to normalize. */\nexport type HarnessResultLike<\n TOutput extends JsonValue | undefined = JsonValue | undefined,\n> = HarnessRun<TOutput> | SimpleHarnessResult<TOutput>;\n\n/** Arguments passed to the `createHarness(...)` convenience callback. */\nexport type CreateHarnessRunArgs<TInput, TMetadata extends HarnessMetadata> = {\n /** Original input passed to `run(input)`. */\n input: TInput;\n /** Read-only metadata passed to `run(input, { metadata })`. */\n metadata: Readonly<TMetadata>;\n /** Abort signal from Vitest when available. */\n signal?: AbortSignal;\n /** Mutable run artifact bag. */\n artifacts: HarnessContext<TMetadata>[\"artifacts\"];\n /** Stores one JSON-safe artifact on the current run. */\n setArtifact: HarnessContext<TMetadata>[\"setArtifact\"];\n};\n\n/**\n * Options for creating a lightweight custom application harness.\n *\n * @example\n * ```ts\n * const options: CreateHarnessOptions<string, { status: \"approved\" }> = {\n * name: \"refund-agent\",\n * run: async ({ input }) => ({\n * output: await classifyRefund(input),\n * }),\n * };\n * ```\n */\nexport type CreateHarnessOptions<\n TInput = unknown,\n TOutput extends JsonValue | undefined = JsonValue | undefined,\n TMetadata extends HarnessMetadata = HarnessMetadata,\n> = {\n /** Stable harness name used in reports. */\n name: string;\n /** Executes application code and returns either a lightweight result or full `HarnessRun`. */\n run: (\n args: CreateHarnessRunArgs<TInput, TMetadata>,\n ) => MaybePromise<HarnessResultLike<TOutput>>;\n};\n\nfunction isJsonPrimitive(value: unknown): value is JsonPrimitive {\n return (\n value === null ||\n typeof value === \"string\" ||\n typeof value === \"number\" ||\n typeof value === \"boolean\"\n );\n}\n\nfunction isJsonRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction normalizeJsonArray(value: unknown[]): JsonValue[] {\n return value.map((item) => {\n const normalized = toJsonValue(item);\n return normalized === undefined ? null : normalized;\n });\n}\n\nfunction normalizeJsonObject(\n value: Record<string, unknown>,\n): Record<string, JsonValue> {\n const normalized: Record<string, JsonValue> = {};\n\n for (const [key, entryValue] of Object.entries(value)) {\n const entry = toJsonValue(entryValue);\n if (entry !== undefined) {\n normalized[key] = entry;\n }\n }\n\n return normalized;\n}\n\n/** Returns true when a value exposes a callable method with the given name. */\nexport function hasCallableMethod(value: unknown, methodName: string) {\n return (\n value !== null &&\n (typeof value === \"object\" || typeof value === \"function\") &&\n methodName in value &&\n typeof (value as Record<string, unknown>)[methodName] === \"function\"\n );\n}\n\n/** Normalizes an unknown value into the JSON-safe shape used by harness runs. */\nexport function toJsonValue(value: unknown): JsonValue | undefined {\n if (isJsonPrimitive(value)) {\n return value;\n }\n\n if (Array.isArray(value)) {\n return normalizeJsonArray(value);\n }\n\n if (isJsonRecord(value)) {\n return normalizeJsonObject(value);\n }\n\n return undefined;\n}\n\n/** Drops non-JSON properties from a record while preserving valid values. */\nexport function normalizeRecord(\n value: Record<string, unknown>,\n): Record<string, JsonValue> {\n return normalizeJsonObject(value);\n}\n\n/** Normalizes metadata and omits the field entirely when nothing survives. */\nexport function normalizeMetadata(\n value: Record<string, unknown>,\n): Record<string, JsonValue> | undefined {\n const normalized = normalizeRecord(value);\n return Object.keys(normalized).length > 0 ? normalized : undefined;\n}\n\n/** Converts arbitrary content into the JSON-safe message content shape. */\nexport function normalizeContent(value: unknown): JsonValue {\n const normalized = toJsonValue(value);\n return normalized !== undefined ? normalized : String(value);\n}\n\n/**\n * Creates a harness from the common \"run app code and return output\" shape.\n *\n * @param options - Harness name plus the callback that executes app code.\n *\n * @example\n * ```ts\n * import { createHarness } from \"vitest-evals\";\n *\n * export const refundHarness = createHarness<\n * string,\n * { status: \"approved\" | \"denied\" },\n * { expected: { status: \"approved\" | \"denied\" } }\n * >({\n * name: \"refund-agent\",\n * run: async ({ input, metadata, setArtifact }) => {\n * const result = await runRefundFlow(input, metadata);\n * const output = { status: result.status };\n *\n * setArtifact(\"case\", { expected: metadata.expected.status });\n *\n * return {\n * output,\n * toolCalls: result.toolCalls,\n * usage: { provider: \"openai\", model: \"gpt-4o-mini\" },\n * };\n * },\n * });\n * ```\n */\nexport function createHarness<\n TInput = unknown,\n TOutput extends JsonValue | undefined = JsonValue | undefined,\n TMetadata extends HarnessMetadata = HarnessMetadata,\n>(\n options: CreateHarnessOptions<TInput, TOutput, TMetadata>,\n): Harness<TInput, TOutput, TMetadata>;\nexport function createHarness<\n TInput = unknown,\n TOutput extends JsonValue | undefined = JsonValue | undefined,\n TMetadata extends HarnessMetadata = HarnessMetadata,\n>(\n options: CreateHarnessOptions<TInput, TOutput, TMetadata>,\n): Harness<TInput, TOutput, TMetadata> {\n const harness: Harness<TInput, TOutput, TMetadata> = {\n name: options.name,\n run: async (input, context) => {\n const result = await options.run({\n input,\n metadata: context.metadata,\n signal: context.signal,\n artifacts: context.artifacts,\n setArtifact: context.setArtifact,\n });\n\n return normalizeHarnessRun(input, result, context);\n },\n };\n\n return harness;\n}\n\n/**\n * Normalizes a lightweight harness result into the reporter-facing run shape.\n *\n * @param input - Original input passed to the harness.\n * @param result - Lightweight result or pre-normalized harness run.\n * @param context - Optional per-run context used to merge artifacts.\n *\n * @example\n * ```ts\n * const run = normalizeHarnessRun(\"Refund invoice inv_123\", {\n * output: { status: \"approved\" },\n * toolCalls: [{ name: \"lookupInvoice\", arguments: { invoiceId: \"inv_123\" } }],\n * usage: { provider: \"openai\", model: \"gpt-4o-mini\" },\n * });\n *\n * expect(toolCalls(run.session)).toHaveLength(1);\n * ```\n */\nexport function normalizeHarnessRun<\n TInput = unknown,\n TMetadata extends HarnessMetadata = HarnessMetadata,\n TOutput extends JsonValue | undefined = JsonValue | undefined,\n>(\n input: TInput,\n result: HarnessResultLike<TOutput>,\n context?: HarnessContext<TMetadata>,\n): HarnessRun<TOutput> {\n if (isHarnessRun(result)) {\n if (\n context &&\n Object.keys(context.artifacts).length > 0 &&\n !result.artifacts\n ) {\n return {\n ...result,\n artifacts: context.artifacts,\n };\n }\n\n return result;\n }\n\n const output = result.output;\n const toolCalls = normalizeSimpleToolCalls(result.toolCalls);\n const usage = result.usage ?? {};\n const messages =\n result.messages ??\n createDefaultSessionMessages({\n input,\n output,\n toolCalls,\n });\n const metadata = result.metadata\n ? normalizeMetadata(result.metadata)\n : undefined;\n const artifacts = normalizeMergedArtifacts(\n context?.artifacts,\n result.artifacts,\n );\n\n return {\n session: {\n messages,\n ...(usage.provider ? { provider: usage.provider } : {}),\n ...(usage.model ? { model: usage.model } : {}),\n ...(metadata ? { metadata } : {}),\n },\n ...(output !== undefined ? { output } : {}),\n usage,\n ...(result.timings ? { timings: result.timings } : {}),\n ...(artifacts ? { artifacts } : {}),\n errors: normalizeSimpleErrors(result.errors),\n } as HarnessRun<TOutput>;\n}\n\nfunction createDefaultSessionMessages<TInput>({\n input,\n output,\n toolCalls: normalizedToolCalls,\n}: {\n input: TInput;\n output: JsonValue | undefined;\n toolCalls: ToolCallRecord[];\n}): NormalizedMessage[] {\n const messages: NormalizedMessage[] = [\n {\n role: \"user\",\n content: normalizeContent(input),\n },\n ];\n\n if (output !== undefined || normalizedToolCalls.length > 0) {\n messages.push({\n role: \"assistant\",\n ...(output !== undefined ? { content: normalizeContent(output) } : {}),\n ...(normalizedToolCalls.length > 0\n ? { toolCalls: normalizedToolCalls }\n : {}),\n });\n }\n\n return messages;\n}\n\nfunction normalizeSimpleToolCalls(\n calls: SimpleToolCallRecord[] | undefined,\n): ToolCallRecord[] {\n return (calls ?? []).map((call) => {\n const {\n arguments: rawArguments,\n result: rawResult,\n error: rawError,\n metadata: rawMetadata,\n ...toolCall\n } = call;\n const args = normalizeToolCallArguments(rawArguments);\n const result = toJsonValue(rawResult);\n const error = normalizeToolCallError(rawError);\n const metadata = rawMetadata ? normalizeMetadata(rawMetadata) : undefined;\n\n return {\n ...toolCall,\n ...(args ? { arguments: args } : {}),\n ...(result !== undefined ? { result } : {}),\n ...(error ? { error } : {}),\n ...(metadata ? { metadata } : {}),\n };\n });\n}\n\nfunction normalizeToolCallArguments(\n value: unknown,\n): Record<string, JsonValue> | undefined {\n if (value === undefined) {\n return undefined;\n }\n\n const normalized = toJsonValue(value);\n return normalized &&\n typeof normalized === \"object\" &&\n !Array.isArray(normalized)\n ? normalized\n : undefined;\n}\n\nfunction normalizeToolCallError(\n value: unknown,\n): ToolCallRecord[\"error\"] | undefined {\n if (value === undefined) {\n return undefined;\n }\n\n const serialized = serializeError(value);\n const { message, type, ...details } = serialized;\n\n return {\n ...details,\n message: typeof message === \"string\" ? message : String(message),\n ...(typeof type === \"string\" ? { type } : {}),\n };\n}\n\nfunction normalizeMergedArtifacts(\n contextArtifacts: Record<string, JsonValue> | undefined,\n resultArtifacts: Record<string, unknown> | undefined,\n) {\n const artifacts = {\n ...(contextArtifacts ?? {}),\n ...(resultArtifacts ? normalizeRecord(resultArtifacts) : {}),\n };\n\n return Object.keys(artifacts).length > 0 ? artifacts : undefined;\n}\n\nfunction normalizeSimpleErrors(\n errors: unknown[] | undefined,\n): Array<Record<string, JsonValue>> {\n return (errors ?? []).map((error) => {\n const normalized = toJsonValue(error);\n\n if (\n normalized &&\n typeof normalized === \"object\" &&\n !Array.isArray(normalized) &&\n Object.keys(normalized).length > 0\n ) {\n return normalized;\n }\n\n return serializeError(error);\n });\n}\n\n/**\n * Flattens every recorded tool call from a normalized session.\n *\n * @param session - Normalized session produced by a harness run.\n *\n * @example\n * ```ts\n * const names = toolCalls(result.session).map((call) => call.name);\n *\n * expect(names).toEqual([\"lookupInvoice\", \"createRefund\"]);\n * ```\n */\nexport function toolCalls(session: NormalizedSession): ToolCallRecord[] {\n return session.messages.flatMap((message) => message.toolCalls ?? []);\n}\n\n/**\n * Filters normalized session messages by role.\n *\n * @param session - Normalized session produced by a harness run.\n * @param role - Message role to keep.\n *\n * @example\n * ```ts\n * const assistantText = messagesByRole(result.session, \"assistant\")\n * .map((message) => message.content)\n * .join(\"\\n\");\n * ```\n */\nexport function messagesByRole(\n session: NormalizedSession,\n role: NormalizedMessage[\"role\"],\n): NormalizedMessage[] {\n return session.messages.filter((message) => message.role === role);\n}\n\nfunction hasNonEmptyMessageContent(message: NormalizedMessage) {\n return (\n message.content !== undefined &&\n (typeof message.content !== \"string\" || message.content.trim().length > 0)\n );\n}\n\n/**\n * Returns every normalized system message from a session.\n *\n * @param session - Normalized session produced by a harness run.\n *\n * @example\n * ```ts\n * const systemPrompts = systemMessages(result.session);\n * ```\n */\nexport function systemMessages(session: NormalizedSession) {\n return messagesByRole(session, \"system\");\n}\n\n/**\n * Returns every normalized user message from a session.\n *\n * @param session - Normalized session produced by a harness run.\n *\n * @example\n * ```ts\n * const firstPrompt = userMessages(result.session)[0]?.content;\n * ```\n */\nexport function userMessages(session: NormalizedSession) {\n return messagesByRole(session, \"user\");\n}\n\n/**\n * Returns every normalized assistant message from a session.\n *\n * @param session - Normalized session produced by a harness run.\n *\n * @example\n * ```ts\n * const finalAnswer = assistantMessages(result.session).at(-1)?.content;\n * ```\n */\nexport function assistantMessages(session: NormalizedSession) {\n return messagesByRole(session, \"assistant\");\n}\n\n/**\n * Returns the latest assistant message content, ignoring empty text messages.\n *\n * @param session - Normalized session produced by a harness run.\n *\n * @example\n * ```ts\n * const finalAnswer = latestAssistantMessageContent(result.session);\n * ```\n */\nexport function latestAssistantMessageContent(session: NormalizedSession) {\n return [...assistantMessages(session)]\n .reverse()\n .find(hasNonEmptyMessageContent)?.content;\n}\n\n/**\n * Returns every normalized tool message from a session.\n *\n * @param session - Normalized session produced by a harness run.\n *\n * @example\n * ```ts\n * const toolOutputs = toolMessages(result.session).map((message) => message.content);\n * ```\n */\nexport function toolMessages(session: NormalizedSession) {\n return messagesByRole(session, \"tool\");\n}\n\n/**\n * Attaches a partial or complete harness run to an arbitrary thrown error.\n *\n * @param error - Thrown value to wrap.\n * @param run - Partial or complete normalized harness run to preserve.\n *\n * @example\n * ```ts\n * try {\n * return await runAgent(input);\n * } catch (error) {\n * throw attachHarnessRunToError(error, partialRun);\n * }\n * ```\n */\nexport function attachHarnessRunToError(\n error: unknown,\n run: HarnessRun,\n): HarnessRunError {\n const baseError =\n error instanceof Error\n ? error\n : new Error(String(error ?? \"Unknown error\"));\n return Object.assign(baseError, {\n vitestEvalsRun: run,\n });\n}\n\n/**\n * Reads an attached harness run back off a previously wrapped error value.\n *\n * @param error - Unknown thrown value that may contain a harness run.\n *\n * @example\n * ```ts\n * const partialRun = getHarnessRunFromError(error);\n *\n * if (partialRun) {\n * console.log(toolCalls(partialRun.session));\n * }\n * ```\n */\nexport function getHarnessRunFromError(error: unknown): HarnessRun | undefined {\n if (\n error &&\n typeof error === \"object\" &&\n \"vitestEvalsRun\" in error &&\n isHarnessRun((error as { vitestEvalsRun?: unknown }).vitestEvalsRun)\n ) {\n return (error as { vitestEvalsRun: HarnessRun }).vitestEvalsRun;\n }\n\n return undefined;\n}\n\n/** Returns true when a value matches the normalized `HarnessRun` contract. */\nexport function isHarnessRun(value: unknown): value is HarnessRun {\n if (!value || typeof value !== \"object\") {\n return false;\n }\n\n const candidate = value as {\n session?: unknown;\n usage?: unknown;\n errors?: unknown;\n };\n\n return (\n isNormalizedSession(candidate.session) &&\n Boolean(candidate.usage) &&\n typeof candidate.usage === \"object\" &&\n !Array.isArray(candidate.usage) &&\n Array.isArray(candidate.errors)\n );\n}\n\n/** Returns true when a value matches the normalized session contract. */\nexport function isNormalizedSession(\n value: unknown,\n): value is NormalizedSession {\n return (\n Boolean(value) &&\n typeof value === \"object\" &&\n value !== null &&\n \"messages\" in value &&\n Array.isArray((value as { messages?: unknown }).messages)\n );\n}\n\n/** Reuses pre-normalized harness errors when a runtime already returns them. */\nexport function resolveHarnessRunErrors(\n result: unknown,\n): Array<Record<string, JsonValue>> {\n if (\n result &&\n typeof result === \"object\" &&\n Array.isArray((result as Record<string, unknown>).errors)\n ) {\n return (result as { errors: Array<Record<string, JsonValue>> }).errors;\n }\n\n return [];\n}\n\n/** Serializes an arbitrary thrown value into the normalized error shape. */\nexport function serializeError(error: unknown): Record<string, JsonValue> {\n if (error instanceof Error) {\n return {\n type: error.name,\n message: error.message,\n };\n }\n\n return {\n type: \"Error\",\n message: String(error),\n };\n}\n","import {\n createHarness,\n type Harness,\n type HarnessContext,\n type HarnessMetadata,\n type HarnessResultLike,\n type HarnessRun,\n isHarnessRun,\n latestAssistantMessageContent,\n type JsonValue,\n type MaybePromise,\n normalizeContent,\n} from \"../harness\";\n\n/**\n * Provider-neutral prompt request issued by an LLM-backed judge.\n *\n * @example\n * ```ts\n * const input: JudgeHarnessInput = {\n * system: \"Grade factual consistency.\",\n * prompt: \"Compare the submitted answer with the reference answer.\",\n * responseFormat: {\n * type: \"json\",\n * },\n * };\n * ```\n */\nexport type JudgeHarnessInput = {\n /** Optional system prompt for the judge model. */\n system?: string;\n /** User prompt or instruction payload for the judge model. */\n prompt: string;\n /** Optional response-format hint for adapters that support structured output. */\n responseFormat?: {\n /** Requests a JSON-compatible response. */\n type: \"json\";\n /** Optional JSON Schema passed through to provider-specific adapters. */\n schema?: JsonValue;\n };\n};\n\n/** JSON-safe output returned by a judge harness. */\nexport type JudgeHarnessOutput = JsonValue | undefined;\n\n/**\n * Harness used by LLM-backed judges to issue judge-side prompts.\n *\n * This is separate from the application harness under test.\n *\n * @example\n * ```ts\n * const judgeHarness: JudgeHarness = createJudgeHarness({\n * name: \"judge-model\",\n * run: async ({ prompt }, { signal }) => {\n * return callJudgeModel({ prompt, signal });\n * },\n * });\n * ```\n */\nexport type JudgeHarness = Harness<\n JudgeHarnessInput,\n JudgeHarnessOutput,\n HarnessMetadata\n>;\n\n/** Runtime options supplied when a judge calls `runJudge(...)`. */\nexport type RunJudgeOptions = {\n /** Optional metadata forwarded to the judge harness run. */\n metadata?: HarnessMetadata;\n};\n\n/**\n * Curried judge-harness runner available inside `JudgeContext`.\n *\n * @example\n * ```ts\n * const verdict = await ctx.runJudge?.({\n * prompt: \"Return a JSON verdict.\",\n * responseFormat: { type: \"json\" },\n * });\n * ```\n */\nexport type RunJudge = (\n input: JudgeHarnessInput,\n options?: RunJudgeOptions,\n) => Promise<JudgeHarnessOutput>;\n\n/** Runtime options passed to `createJudgeHarness(...)` callbacks. */\nexport type CreateJudgeHarnessRunOptions = {\n /** Abort signal from the current eval run when available. */\n signal?: AbortSignal;\n /** Metadata for this judge-harness run. */\n metadata: Readonly<HarnessMetadata>;\n};\n\n/**\n * Configuration for `createJudgeHarness(...)`.\n *\n * @example\n * ```ts\n * const judgeHarness = createJudgeHarness({\n * name: \"custom-judge\",\n * run: async ({ system, prompt }, { signal }) => {\n * return callProvider({ system, prompt, signal });\n * },\n * });\n * ```\n */\nexport type CreateJudgeHarnessOptions = {\n /** Stable harness name used in diagnostics. */\n name?: string;\n /**\n * Runs one provider-specific judge prompt.\n *\n * Return a JSON-safe value, a raw provider value to normalize, a lightweight\n * `{ output }` result, or a full normalized `HarnessRun`.\n */\n run: (\n input: JudgeHarnessInput,\n options: CreateJudgeHarnessRunOptions,\n ) => MaybePromise<unknown>;\n};\n\n/**\n * Creates a judge harness from a provider-specific prompt callback.\n *\n * @param options - Harness name plus the callback that issues the judge prompt.\n *\n * @example\n * ```ts\n * const judgeHarness = createJudgeHarness({\n * run: async ({ prompt }) => callJudgeModel(prompt),\n * });\n * ```\n */\nexport function createJudgeHarness(\n options: CreateJudgeHarnessOptions,\n): JudgeHarness {\n return createHarness({\n name: options.name ?? \"judge-harness\",\n run: async ({ input, signal, metadata }) => {\n return normalizeJudgeHarnessResult(\n await options.run(input, { signal, metadata }),\n );\n },\n });\n}\n\n/**\n * Runs a judge harness with eval-scoped context already supplied.\n *\n * @param judgeHarness - Judge-side harness configured on the matcher, judge, or suite.\n * @param input - Provider-neutral judge prompt request.\n * @param options - Run-scoped metadata and abort signal.\n */\nexport async function runJudgeHarness(\n judgeHarness: JudgeHarness,\n input: JudgeHarnessInput,\n options: RunJudgeOptions & { signal?: AbortSignal } = {},\n): Promise<JudgeHarnessOutput> {\n const artifacts: HarnessContext[\"artifacts\"] = {};\n const run = await judgeHarness.run(input, {\n metadata: options.metadata ?? {},\n signal: options.signal,\n artifacts,\n setArtifact: (name, value) => {\n artifacts[name] = value;\n },\n });\n\n return run.output !== undefined\n ? run.output\n : resolveJudgeHarnessAssistantOutput(run);\n}\n\n/** Binds a judge harness to the current eval run context. */\nexport function createRunJudge(\n judgeHarness: JudgeHarness | undefined,\n signal?: AbortSignal,\n): RunJudge | undefined {\n if (!judgeHarness) {\n return undefined;\n }\n\n return (input, options) =>\n runJudgeHarness(judgeHarness, input, {\n metadata: options?.metadata,\n signal,\n });\n}\n\nfunction normalizeJudgeHarnessResult(\n result: Awaited<ReturnType<CreateJudgeHarnessOptions[\"run\"]>>,\n): HarnessResultLike<JudgeHarnessOutput> {\n if (isHarnessRun(result)) {\n return result as HarnessRun<JudgeHarnessOutput>;\n }\n\n if (hasOutputField(result)) {\n return {\n output: normalizeJudgeHarnessOutput(result.output),\n };\n }\n\n return {\n output: normalizeJudgeHarnessOutput(result),\n };\n}\n\nfunction hasOutputField(value: unknown): value is { output?: unknown } {\n return (\n value !== null &&\n typeof value === \"object\" &&\n !Array.isArray(value) &&\n Object.keys(value).length === 1 &&\n \"output\" in value\n );\n}\n\nfunction normalizeJudgeHarnessOutput(value: unknown): JudgeHarnessOutput {\n if (value === undefined) {\n return undefined;\n }\n\n return normalizeContent(value);\n}\n\nfunction resolveJudgeHarnessAssistantOutput(\n run: HarnessRun<JudgeHarnessOutput>,\n): JudgeHarnessOutput {\n return latestAssistantMessageContent(run.session) ?? \"\";\n}\n"],"mappings":"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","names":[]}