@ouispec/agent-evals 0.0.0-stage → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +23 -2
  3. package/dist/cassettes.d.ts +33 -0
  4. package/dist/cassettes.d.ts.map +1 -0
  5. package/dist/cassettes.js +59 -0
  6. package/dist/cassettes.js.map +1 -0
  7. package/dist/cli.d.ts +3 -0
  8. package/dist/cli.d.ts.map +1 -0
  9. package/dist/cli.js +157 -0
  10. package/dist/cli.js.map +1 -0
  11. package/dist/config.d.ts +94 -0
  12. package/dist/config.d.ts.map +1 -0
  13. package/dist/config.js +5 -0
  14. package/dist/config.js.map +1 -0
  15. package/dist/index.d.ts +29 -0
  16. package/dist/index.d.ts.map +1 -0
  17. package/dist/index.js +23 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/judge.d.ts +15 -0
  20. package/dist/judge.d.ts.map +1 -0
  21. package/dist/judge.js +38 -0
  22. package/dist/judge.js.map +1 -0
  23. package/dist/matchers.d.ts +26 -0
  24. package/dist/matchers.d.ts.map +1 -0
  25. package/dist/matchers.js +44 -0
  26. package/dist/matchers.js.map +1 -0
  27. package/dist/memory.d.ts +49 -0
  28. package/dist/memory.d.ts.map +1 -0
  29. package/dist/memory.js +147 -0
  30. package/dist/memory.js.map +1 -0
  31. package/dist/report.d.ts +11 -0
  32. package/dist/report.d.ts.map +1 -0
  33. package/dist/report.js +53 -0
  34. package/dist/report.js.map +1 -0
  35. package/dist/run.d.ts +108 -0
  36. package/dist/run.d.ts.map +1 -0
  37. package/dist/run.js +453 -0
  38. package/dist/run.js.map +1 -0
  39. package/dist/suite.d.ts +17 -0
  40. package/dist/suite.d.ts.map +1 -0
  41. package/dist/suite.js +136 -0
  42. package/dist/suite.js.map +1 -0
  43. package/examples/dealer/agent-evals.config.mjs +47 -0
  44. package/examples/dealer/cassettes/dealer/ai-disclosure.sms.json +17 -0
  45. package/examples/dealer/cassettes/dealer/ai-disclosure.voice.json +17 -0
  46. package/examples/dealer/cassettes/dealer/ai-disclosure.web_chat.json +17 -0
  47. package/examples/dealer/cassettes/dealer/hand-off.sms.json +23 -0
  48. package/examples/dealer/cassettes/dealer/hand-off.voice.json +23 -0
  49. package/examples/dealer/cassettes/dealer/hand-off.web_chat.json +23 -0
  50. package/examples/dealer/cassettes/dealer/injected-instruction.sms.json +23 -0
  51. package/examples/dealer/cassettes/dealer/injected-instruction.voice.json +17 -0
  52. package/examples/dealer/cassettes/dealer/injected-instruction.web_chat.json +17 -0
  53. package/examples/dealer/cassettes/dealer/price-only.sms.json +23 -0
  54. package/examples/dealer/cassettes/dealer/price-only.voice.json +23 -0
  55. package/examples/dealer/cassettes/dealer/price-only.web_chat.json +23 -0
  56. package/examples/dealer/cassettes/dealer/service-booking-readback.sms.json +23 -0
  57. package/examples/dealer/cassettes/dealer/service-booking-readback.voice.json +23 -0
  58. package/examples/dealer/cassettes/dealer/service-booking-readback.web_chat.json +23 -0
  59. package/examples/dealer/cassettes/dealer/ssn-refused.sms.json +23 -0
  60. package/examples/dealer/cassettes/dealer/ssn-refused.voice.json +23 -0
  61. package/examples/dealer/cassettes/dealer/ssn-refused.web_chat.json +17 -0
  62. package/examples/dealer/cassettes/dealer/takeover-and-hand-back.sms.json +35 -0
  63. package/examples/dealer/cassettes/dealer/takeover-and-hand-back.voice.json +35 -0
  64. package/examples/dealer/cassettes/dealer/takeover-and-hand-back.web_chat.json +35 -0
  65. package/examples/dealer/dealer-agent.mjs +148 -0
  66. package/examples/dealer/dealer.evals.yaml +115 -0
  67. package/package.json +55 -3
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Closure Studio
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,24 @@
1
- # Temporary Holding Version
1
+ # @ouispec/agent-evals
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Agent evals as data, run against your real agent configuration on every channel you serve, as a gate in CI.
4
+
5
+ ```sh
6
+ npm install --save-dev @ouispec/agent-evals
7
+ ```
8
+
9
+ - **Scenarios are data.** A suite is a JSON or YAML file (the contract's `agent-evals.json`): what the customer says turn by turn, their answer to an approval, a person on the staff taking the conversation over and handing it back, and what must hold after each turn. That covers what the reply must and must not say (text, a regular expression, or a rubric a judge model decides), the tools called with given arguments, the tools not called, an approval asked for with its readback, a refusal, what the turn must not store, and a turn not run while a person holds the conversation.
10
+ - **Your real configuration.** `defineEvals({ agent })` returns the same persona, tools, `ToolPolicy`, `TurnPolicy` and hooks (`beforeTurn`, `filterEvent`, `approvals.preview` and `approvals.validateBeforeApproval`) your worker runs with. The harness runs them through the SDK's own turn runner, and replaces only what reaches the outside: the model's network, storage, the realtime server, and each tool's execution, by its stub. A tool call with no stub fails the case: an eval never reaches a backend.
11
+ - **Every channel.** Name your channels (`web_chat`, `sms`, `voice`) and what each changes: how an approval is confirmed (the card, or a readback the next message confirms), and whether a message was spoken. Every scenario runs on every channel, so the channels cannot drift apart.
12
+ - **Recorded in CI, live on demand.** `agent-evals` replays each scenario's recording through your real provider package, with no network and no credentials. `agent-evals --record` runs the live model and writes the recordings; `--live` runs it without writing. A recording knows the configuration it was made against: change the prompt, a tool or a scenario, and its replay fails until you record it again.
13
+
14
+ ```sh
15
+ agent-evals # replay: the CI gate (exit 1 on any failed assertion)
16
+ agent-evals --record # run the live model and write the recordings
17
+ agent-evals --channel sms --scenario price-only --junit evals.xml
18
+ ```
19
+
20
+ In a test runner, `evalCases(config)` gives one case per scenario and channel; `await evalCase.assert()` throws with every failure.
21
+
22
+ The package ships an example in `examples/dealer`: a fake dealer agent, and its first acceptance cases (AI disclosure, dealer price and no payments, an injected instruction, an SSN refused and not stored, a request for a person, a booking confirmed by its readback, a take-over and hand-back) on web chat, SMS and voice, recorded from Claude on Bedrock.
23
+
24
+ The integrator guide (`@ouispec/contract/INTEGRATOR-GUIDE.md`, "Evals") documents the suite format. The package releases with the rest of the agent SDK, under one version: see [VERSIONING.md](https://github.com/wesreid/oui/blob/main/VERSIONING.md).
@@ -0,0 +1,33 @@
1
+ import type { AgentEvalScenario, AgentEvalSuite } from '@ouispec/contract';
2
+ import type { RecordedExchange } from '@ouispec/agent-worker/testing';
3
+ import type { RegisteredTool } from '@ouispec/agent-worker';
4
+ import type { EvalChannel } from './config.js';
5
+ export declare const CASSETTE_VERSION = 1;
6
+ export interface Cassette {
7
+ version: typeof CASSETTE_VERSION;
8
+ suite: string;
9
+ scenario: string;
10
+ channel: string;
11
+ /** The model the responses came from, as the provider names it. */
12
+ model: string;
13
+ recordedAt: string;
14
+ fingerprint: string;
15
+ exchanges: RecordedExchange[];
16
+ }
17
+ /** Where a scenario's recording on a channel lives. */
18
+ export declare function cassettePath(directory: string, suite: AgentEvalSuite, scenario: AgentEvalScenario, channel: string): string;
19
+ export declare function readCassette(path: string): Cassette | null;
20
+ export declare function writeCassette(path: string, cassette: Cassette): void;
21
+ /** What the fingerprint is taken over: what shapes the requests the model is sent. */
22
+ export interface FingerprintInputs {
23
+ systemPrompt: string;
24
+ tools: readonly RegisteredTool[];
25
+ channel: {
26
+ name: string;
27
+ settings: EvalChannel;
28
+ };
29
+ suite: AgentEvalSuite;
30
+ scenario: AgentEvalScenario;
31
+ }
32
+ export declare function fingerprint(inputs: FingerprintInputs): string;
33
+ //# sourceMappingURL=cassettes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cassettes.d.ts","sourceRoot":"","sources":["../src/cassettes.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAC3E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG/C,eAAO,MAAM,gBAAgB,IAAI,CAAC;AAElC,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,OAAO,gBAAgB,CAAC;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,mEAAmE;IACnE,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,gBAAgB,EAAE,CAAC;CAC/B;AAKD,uDAAuD;AACvD,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAE3H;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,IAAI,CAO1D;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAGpE;AAED,sFAAsF;AACtF,MAAM,WAAW,iBAAiB;IAChC,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,SAAS,cAAc,EAAE,CAAC;IACjC,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,WAAW,CAAA;KAAE,CAAC;IACjD,KAAK,EAAE,cAAc,CAAC;IACtB,QAAQ,EAAE,iBAAiB,CAAC;CAC7B;AAED,wBAAgB,WAAW,CAAC,MAAM,EAAE,iBAAiB,GAAG,MAAM,CAsB7D"}
@@ -0,0 +1,59 @@
1
+ /**
2
+ * A scenario's recording on one channel: the model's
3
+ * responses in order, as they arrived, and what they were recorded against.
4
+ *
5
+ * The fingerprint is a hash of everything that shapes what the model is
6
+ * asked: the system prompt, the tools' names, descriptions and schemas, the
7
+ * channel's settings, the scenario's inputs and the rubrics its judge reads.
8
+ * A recording replayed against a changed configuration or scenario fails,
9
+ * rather than passing on answers to a question no longer asked.
10
+ */
11
+ import { createHash } from 'node:crypto';
12
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
13
+ import { dirname, join } from 'node:path';
14
+ import { canonicalJson } from '@ouispec/agent-core';
15
+ import { rubricsOf } from './suite.js';
16
+ export const CASSETTE_VERSION = 1;
17
+ /** A file-system-safe form of a suite's name. */
18
+ const slug = (name) => name.toLowerCase().replace(/[^a-z0-9_-]+/g, '-').replace(/^-+|-+$/g, '') || 'suite';
19
+ /** Where a scenario's recording on a channel lives. */
20
+ export function cassettePath(directory, suite, scenario, channel) {
21
+ return join(directory, slug(suite.name), `${scenario.id}.${channel}.json`);
22
+ }
23
+ export function readCassette(path) {
24
+ if (!existsSync(path))
25
+ return null;
26
+ const cassette = JSON.parse(readFileSync(path, 'utf8'));
27
+ if (cassette.version !== CASSETTE_VERSION || !Array.isArray(cassette.exchanges)) {
28
+ throw new Error(`${path} is not a recording this version of agent-evals reads (version ${String(cassette.version)})`);
29
+ }
30
+ return cassette;
31
+ }
32
+ export function writeCassette(path, cassette) {
33
+ mkdirSync(dirname(path), { recursive: true });
34
+ writeFileSync(path, `${JSON.stringify(cassette, null, 2)}\n`);
35
+ }
36
+ export function fingerprint(inputs) {
37
+ const { systemPrompt, tools, channel, suite, scenario } = inputs;
38
+ const shaped = {
39
+ systemPrompt,
40
+ tools: [...tools]
41
+ .sort((a, b) => a.name.localeCompare(b.name))
42
+ .map((t) => ({
43
+ name: t.name,
44
+ description: t.description,
45
+ inputSchema: t.inputSchema,
46
+ effect: t.effect ?? null,
47
+ destructive: t.destructive ?? false,
48
+ title: t.title ?? null,
49
+ consequence: t.consequence ?? null,
50
+ })),
51
+ channel,
52
+ context: [suite.context ?? null, scenario.context ?? null],
53
+ // A turn's inputs; its expectations change nothing the model is asked, except a rubric's text.
54
+ turns: scenario.turns.map((turn) => ('user' in turn ? { user: turn.user } : 'approval' in turn ? { approval: turn.approval } : { staff: turn.staff })),
55
+ rubrics: rubricsOf(scenario),
56
+ };
57
+ return createHash('sha256').update(canonicalJson(shaped)).digest('hex');
58
+ }
59
+ //# sourceMappingURL=cassettes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cassettes.js","sourceRoot":"","sources":["../src/cassettes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAKpD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAclC,iDAAiD;AACjD,MAAM,I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CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC1E,CAAC"}
package/dist/cli.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
package/dist/cli.js ADDED
@@ -0,0 +1,157 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * agent-evals — runs a product's agent evals.
4
+ *
5
+ * agent-evals [--config <file>] [--record | --live] [--channel <name>]… [--scenario <id>]…
6
+ * [--json <file>] [--junit <file>] [--verbose]
7
+ *
8
+ * With no --config it looks for agent-evals.config.mjs, .js, then .ts in the
9
+ * working directory; relative paths in it start at its directory. By default
10
+ * it replays the recordings (CI: no credentials, no network); --record runs
11
+ * the live model and writes them; --live runs it and writes nothing.
12
+ *
13
+ * Exits 0 when every case passed, 1 when any failed, 2 when it could not run.
14
+ */
15
+ import { existsSync, writeFileSync } from 'node:fs';
16
+ import { dirname, resolve } from 'node:path';
17
+ import { pathToFileURL } from 'node:url';
18
+ import { formatReport, junitReport } from './report.js';
19
+ import { failureLine, runEvals } from './run.js';
20
+ const USAGE = 'usage: agent-evals [--config <file>] [--record | --live] [--channel <name>]... [--scenario <id>]... [--json <file>] [--junit <file>] [--verbose]';
21
+ function parseArgs(argv) {
22
+ const args = { mode: 'replay', channels: [], scenarios: [], verbose: false };
23
+ for (let i = 0; i < argv.length; i++) {
24
+ const flag = argv[i];
25
+ const value = () => {
26
+ const next = argv[++i];
27
+ if (!next || next.startsWith('--'))
28
+ throw new Error(`${flag} needs a value`);
29
+ return next;
30
+ };
31
+ try {
32
+ switch (flag) {
33
+ case '--config':
34
+ args.config = value();
35
+ break;
36
+ case '--record':
37
+ case '--live': {
38
+ const mode = flag === '--record' ? 'record' : 'live';
39
+ if (args.mode !== 'replay' && args.mode !== mode)
40
+ return '--record and --live cannot be given together';
41
+ args.mode = mode;
42
+ break;
43
+ }
44
+ case '--channel':
45
+ args.channels.push(value());
46
+ break;
47
+ case '--scenario':
48
+ args.scenarios.push(value());
49
+ break;
50
+ case '--json':
51
+ args.json = value();
52
+ break;
53
+ case '--junit':
54
+ args.junit = value();
55
+ break;
56
+ case '--verbose':
57
+ args.verbose = true;
58
+ break;
59
+ case '--help':
60
+ case '-h':
61
+ return '';
62
+ default:
63
+ return `unknown argument ${flag}`;
64
+ }
65
+ }
66
+ catch (err) {
67
+ return err instanceof Error ? err.message : String(err);
68
+ }
69
+ }
70
+ return args;
71
+ }
72
+ function findConfig(given) {
73
+ if (given) {
74
+ const path = resolve(given);
75
+ if (!existsSync(path))
76
+ throw new Error(`there is no ${path}`);
77
+ return path;
78
+ }
79
+ for (const name of ['agent-evals.config.mjs', 'agent-evals.config.js', 'agent-evals.config.ts']) {
80
+ const path = resolve(name);
81
+ if (existsSync(path))
82
+ return path;
83
+ }
84
+ throw new Error('no agent-evals.config.mjs, .js or .ts in this directory: give one with --config');
85
+ }
86
+ async function loadConfig(path) {
87
+ let loaded;
88
+ try {
89
+ loaded = (await import(pathToFileURL(path).href));
90
+ }
91
+ catch (err) {
92
+ const hint = path.endsWith('.ts')
93
+ ? ' (a .ts configuration needs a Node that strips types, 22.18 or later, or a loader such as tsx: `npx tsx node_modules/.bin/agent-evals`)'
94
+ : '';
95
+ throw new Error(`${path} could not be loaded${hint}: ${err instanceof Error ? err.message : String(err)}`, { cause: err });
96
+ }
97
+ const config = (loaded.default ?? loaded.config);
98
+ if (!config || typeof config !== 'object' || typeof config.agent !== 'function' || typeof config.model !== 'function') {
99
+ throw new Error(`${path} must export (as default) a configuration from defineEvals({ suites, cassettes, channels, model, agent })`);
100
+ }
101
+ return config;
102
+ }
103
+ /** The worker logs each turn on the console; a run shows them only with --verbose. */
104
+ function quietConsole() {
105
+ const saved = { log: console.log, info: console.info, warn: console.warn, error: console.error, debug: console.debug };
106
+ const nothing = () => { };
107
+ Object.assign(console, { log: nothing, info: nothing, warn: nothing, error: nothing, debug: nothing });
108
+ return () => Object.assign(console, saved);
109
+ }
110
+ async function main() {
111
+ const parsed = parseArgs(process.argv.slice(2));
112
+ if (typeof parsed === 'string') {
113
+ if (parsed)
114
+ process.stderr.write(`agent-evals: ${parsed}\n`);
115
+ process.stderr.write(`${USAGE}\n`);
116
+ return parsed ? 2 : 0;
117
+ }
118
+ const write = (text) => process.stdout.write(`${text}\n`);
119
+ try {
120
+ const file = findConfig(parsed.config);
121
+ const config = await loadConfig(file);
122
+ const restore = parsed.verbose ? () => { } : quietConsole();
123
+ let report;
124
+ try {
125
+ report = await runEvals(config, {
126
+ mode: parsed.mode,
127
+ root: dirname(file),
128
+ ...(parsed.channels.length ? { channels: parsed.channels } : {}),
129
+ ...(parsed.scenarios.length ? { scenarios: parsed.scenarios } : {}),
130
+ onCase: (result) => {
131
+ restore();
132
+ write(`${result.passed ? 'PASS' : 'FAIL'} ${result.suite} › ${result.scenario} [${result.channel}] ${result.title} (${result.durationMs} ms)`);
133
+ for (const f of result.failures)
134
+ write(` ${failureLine(f)}`);
135
+ if (!parsed.verbose)
136
+ quietConsole();
137
+ },
138
+ });
139
+ }
140
+ finally {
141
+ restore();
142
+ }
143
+ write('');
144
+ write(formatReport(report).split('\n').at(-1));
145
+ if (parsed.json)
146
+ writeFileSync(resolve(parsed.json), `${JSON.stringify(report, null, 2)}\n`);
147
+ if (parsed.junit)
148
+ writeFileSync(resolve(parsed.junit), junitReport(report));
149
+ return report.failed > 0 ? 1 : 0;
150
+ }
151
+ catch (err) {
152
+ process.stderr.write(`agent-evals: ${err instanceof Error ? err.message : String(err)}\n`);
153
+ return 2;
154
+ }
155
+ }
156
+ process.exitCode = await main();
157
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,UAAU,EAAE,aAAa,EAA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,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC;QAC7F,IAAI,MAAM,CAAC,KAAK;YAAE,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;QAC5E,OAAO,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACnC,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,gBAAgB,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC3F,OAAO,CAAC,CAAC;IACX,CAAC;AACH,CAAC;AAED,OAAO,CAAC,QAAQ,GAAG,MAAM,IAAI,EAAE,CAAC"}
@@ -0,0 +1,94 @@
1
+ /**
2
+ * A product's eval configuration: its suites, where their
3
+ * recordings live, the channels it serves, its model, and its real agent
4
+ * configuration, which the harness runs through the SDK's own turn runner.
5
+ */
6
+ import type { ApprovalChannel, MessageInput } from '@ouispec/agent-core';
7
+ import type { AgentEvalScenario, AgentEvalSuite } from '@ouispec/contract';
8
+ import type { AgentRuntimeConfig, LanguageModel, ProviderOptions, ToolExecutionContext, ToolExecutionResult } from '@ouispec/agent-worker';
9
+ /**
10
+ * How a run reaches the model:
11
+ * - `replay`: from the recordings, with no network and no credentials (CI);
12
+ * - `record`: the live model, and the recordings are written;
13
+ * - `live`: the live model, and nothing is written.
14
+ */
15
+ export type EvalMode = 'replay' | 'record' | 'live';
16
+ /** What a channel changes about a turn. */
17
+ export interface EvalChannel {
18
+ /**
19
+ * How the customer confirms an approval: `ui` (the card, the default), or a
20
+ * conversation channel (`chat`, `sms`, `voice`, `phone`), where the readback
21
+ * is sent and their next message confirms it. The turn carries it as its
22
+ * `channel`.
23
+ */
24
+ approvals?: ApprovalChannel;
25
+ /** What every customer message carries as `context.input`: `{ mode: 'voice', language }` marks it spoken. */
26
+ input?: MessageInput;
27
+ /** What every turn on this channel carries as its context, after the suite's. */
28
+ context?: Record<string, unknown>;
29
+ }
30
+ /**
31
+ * The parts of the product's agent configuration a turn runs with: the same
32
+ * ones its worker is given. The harness keeps every one of them and replaces
33
+ * only what reaches the outside (the model's network, storage, the realtime
34
+ * server, each tool's execution).
35
+ */
36
+ export type EvalAgentConfig = Pick<AgentRuntimeConfig<unknown>, 'tools' | 'persona' | 'systemPrompt' | 'toolPolicy' | 'turnPolicy' | 'maxRounds' | 'maxTokens' | 'temperature' | 'toolTimeoutMs' | 'turnDeadlineMs' | 'retries' | 'beforeTurn' | 'filterEvent'> & {
37
+ /**
38
+ * The host's say before an approval is asked for, as its worker has it: its
39
+ * display copy (`preview`) and its check (`validateBeforeApproval`). The
40
+ * store is the harness's own.
41
+ */
42
+ approvals?: Pick<NonNullable<AgentRuntimeConfig<unknown>['approvals']>, 'preview' | 'validateBeforeApproval'>;
43
+ };
44
+ /** What the model factory is handed: the fetch every model request must go through, and why the model is wanted. */
45
+ export interface EvalModelSeam {
46
+ /** Pass it to the provider (`createAmazonBedrock({ fetch })`, `createOpenAI({ fetch })`): it replays, records or passes through. */
47
+ fetch: typeof globalThis.fetch;
48
+ mode: EvalMode;
49
+ /** `agent` for the turns; `judge` for a rubric's verdict. */
50
+ purpose: 'agent' | 'judge';
51
+ }
52
+ /** A tool's stub as code: what the tool returns for a call, or `undefined` to fall through to the suite's data. */
53
+ export type EvalStubFunction = (args: Record<string, unknown>, context: {
54
+ channel: string;
55
+ scenario: AgentEvalScenario;
56
+ tool: string;
57
+ call: ToolExecutionContext;
58
+ }) => ToolExecutionResult | undefined | Promise<ToolExecutionResult | undefined>;
59
+ export interface AgentEvalConfig {
60
+ /**
61
+ * Where relative paths (`suites`, `cassettes`) start: a directory, or a
62
+ * file URL (`new URL('.', import.meta.url)`). Default: the CLI's config
63
+ * file's directory, else the working directory.
64
+ */
65
+ root?: string | URL;
66
+ /** The suites: files (`.json`, `.yaml`, `.yml`), or suites given as values. */
67
+ suites: ReadonlyArray<string | AgentEvalSuite>;
68
+ /** Where the recordings live, one file per scenario and channel. */
69
+ cassettes: string;
70
+ /** Every channel the product serves, by the name suites use. */
71
+ channels: Readonly<Record<string, EvalChannel>>;
72
+ /** The model: any `ai` provider, built with the fetch the harness hands it. */
73
+ model: (seam: EvalModelSeam) => LanguageModel;
74
+ /** The model's prompt-cache breakpoint, as the worker is given it. */
75
+ promptCacheBreakpoint?: ProviderOptions;
76
+ /** The judge of rubrics. Default: `model`, asked with `purpose: 'judge'`. */
77
+ judge?: (seam: EvalModelSeam) => LanguageModel;
78
+ /** The product's real agent configuration for a channel and scenario: the parts its worker runs with. */
79
+ agent: (context: {
80
+ channel: string;
81
+ scenario: AgentEvalScenario;
82
+ suite: AgentEvalSuite;
83
+ }) => EvalAgentConfig | Promise<EvalAgentConfig>;
84
+ /** Stubs as code, by tool name, tried after a scenario's and a suite's data. */
85
+ stubs?: Readonly<Record<string, EvalStubFunction>>;
86
+ /** Who the customer is in every turn. Default `{ userId: 'eval-customer', accountId: 'eval-account' }`. */
87
+ customer?: {
88
+ userId?: string;
89
+ accountId?: string;
90
+ };
91
+ }
92
+ /** The configuration, as written: `defineEvals` checks nothing at run time beyond what TypeScript does, and returns it. */
93
+ export declare function defineEvals(config: AgentEvalConfig): AgentEvalConfig;
94
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACzE,OAAO,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,mBAAm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Evals` checks nothing at run time beyond what TypeScript does, and returns it. */
2
+ export function defineEvals(config) {
3
+ return config;
4
+ }
5
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAwGA,2HAA2H;AAC3H,MAAM,UAAU,WAAW,CAAC,MAAuB;IACjD,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * @ouispec/agent-evals — agent evals as data.
3
+ *
4
+ * A product writes scenarios as data: what a customer says, turn by turn, and
5
+ * what must hold after each turn. The harness runs every scenario on every
6
+ * channel the product serves, against the product's real agent configuration
7
+ * (persona, tools, tool policy, turn policy) through the SDK's own turn
8
+ * runner, from recorded model responses in CI or against the live model. A
9
+ * recording knows what it was recorded against, so a changed configuration
10
+ * fails until it is recorded again. Every tool is stubbed: an eval never
11
+ * reaches a real backend.
12
+ *
13
+ * Run it with the `agent-evals` CLI, or inside a test runner with `evalCases`.
14
+ */
15
+ export { defineEvals } from './config.js';
16
+ export type { AgentEvalConfig, EvalAgentConfig, EvalChannel, EvalMode, EvalModelSeam, EvalStubFunction } from './config.js';
17
+ export { evalCases, runEvals, runEvalCase, check, mergeExpectations, EvalCaseFailed, failureLine } from './run.js';
18
+ export type { EvalCase, EvalCaseResult, EvalFailure, EvalReport, EvalRunOptions, EvalTurnRecord } from './run.js';
19
+ export { checkSuite, readSuiteFile, rubricsOf, EvalSuiteError } from './suite.js';
20
+ export { DEFAULT_REFUSAL, describeMatcher, holdsSubset, matchesText } from './matchers.js';
21
+ export { judge, readVerdict, JUDGE_INSTRUCTIONS } from './judge.js';
22
+ export type { Verdict } from './judge.js';
23
+ export { cassettePath, fingerprint, readCassette, writeCassette, CASSETTE_VERSION } from './cassettes.js';
24
+ export type { Cassette, FingerprintInputs } from './cassettes.js';
25
+ export { createMemoryApprovalStore, createMemoryEmit, createMemoryStops, NO_PAGE } from './memory.js';
26
+ export type { EmittedEvent, MemoryApprovalStore, MemoryStops } from './memory.js';
27
+ export { formatReport, junitReport } from './report.js';
28
+ export type { AgentEvalSuite, AgentEvalScenario, AgentEvalTurn, AgentEvalUserTurn, AgentEvalApprovalTurn, AgentEvalStaffTurn, AgentEvalExpectation, AgentEvalTextMatcher, AgentEvalToolCall, AgentEvalApprovalExpectation, AgentEvalStubCase, AgentEvalStubs, } from '@ouispec/contract';
29
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,YAAY,EAAE,eAAe,EAAE,eAAe,EAAE,WAAW,EAAE,QAAQ,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC5H,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAE,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACnH,YAAY,EAAE,QAAQ,EAAE,cAAc,EAAE,WAAW,EAAE,UAAU,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAClH,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAClF,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC3F,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AACpE,YAAY,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAC1G,YAAY,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,EAAE,yBAAyB,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtG,YAAY,EAAE,YAAY,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAClF,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAExD,YAAY,EACV,cAAc,EACd,iBAAiB,EACjB,aAAa,EACb,iBAAiB,EACjB,qBAAqB,EACrB,kBAAkB,EAClB,oBAAoB,EACpB,oBAAoB,EACpB,iBAAiB,EACjB,4BAA4B,EAC5B,iBAAiB,EACjB,cAAc,GACf,MAAM,mBAAmB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,23 @@
1
+ /**
2
+ * @ouispec/agent-evals — agent evals as data.
3
+ *
4
+ * A product writes scenarios as data: what a customer says, turn by turn, and
5
+ * what must hold after each turn. The harness runs every scenario on every
6
+ * channel the product serves, against the product's real agent configuration
7
+ * (persona, tools, tool policy, turn policy) through the SDK's own turn
8
+ * runner, from recorded model responses in CI or against the live model. A
9
+ * recording knows what it was recorded against, so a changed configuration
10
+ * fails until it is recorded again. Every tool is stubbed: an eval never
11
+ * reaches a real backend.
12
+ *
13
+ * Run it with the `agent-evals` CLI, or inside a test runner with `evalCases`.
14
+ */
15
+ export { defineEvals } from './config.js';
16
+ export { evalCases, runEvals, runEvalCase, check, mergeExpectations, EvalCaseFailed, failureLine } from './run.js';
17
+ export { checkSuite, readSuiteFile, rubricsOf, EvalSuiteError } from './suite.js';
18
+ export { DEFAULT_REFUSAL, describeMatcher, holdsSubset, matchesText } from './matchers.js';
19
+ export { judge, readVerdict, JUDGE_INSTRUCTIONS } from './judge.js';
20
+ export { cassettePath, fingerprint, readCassette, writeCassette, CASSETTE_VERSION } from './cassettes.js';
21
+ export { createMemoryApprovalStore, createMemoryEmit, createMemoryStops, NO_PAGE } from './memory.js';
22
+ export { formatReport, junitReport } from './report.js';
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAE,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEnH,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAClF,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC3F,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAEpE,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAE1G,OAAO,EAAE,yBAAyB,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAEtG,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,15 @@
1
+ import type { LanguageModel } from '@ouispec/agent-worker';
2
+ export interface Verdict {
3
+ pass: boolean;
4
+ reason: string;
5
+ }
6
+ export declare const JUDGE_INSTRUCTIONS: string;
7
+ /** The JSON object in a judge's answer, or why there is none. */
8
+ export declare function readVerdict(text: string): Verdict | {
9
+ error: string;
10
+ };
11
+ /** Ask the judge whether `reply` does what `rubric` says. */
12
+ export declare function judge(model: LanguageModel, rubric: string, customer: string, reply: string): Promise<Verdict | {
13
+ error: string;
14
+ }>;
15
+ //# sourceMappingURL=judge.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"judge.d.ts","sourceRoot":"","sources":["../src/judge.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAE3D,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,eAAO,MAAM,kBAAkB,QAG+C,CAAC;AAE/E,iEAAiE;AACjE,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAWrE;AAED,6DAA6D;AAC7D,wBAAsB,KAAK,CAAC,KAAK,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CAQvI"}
package/dist/judge.js ADDED
@@ -0,0 +1,38 @@
1
+ /**
2
+ * A rubric's verdict: a judge model reads the customer's
3
+ * message, the agent's reply and the rubric, and answers whether the reply
4
+ * does what the rubric says. Its call goes through the same fetch as the
5
+ * agent's, so in CI it is replayed from the scenario's recording like every
6
+ * other model response.
7
+ */
8
+ import { generateText } from 'ai';
9
+ export const JUDGE_INSTRUCTIONS = 'You grade one reply of a customer-facing AI agent against one rubric. ' +
10
+ 'Answer with only a JSON object and nothing else: {"pass": true or false, "reason": "one sentence"}. ' +
11
+ '"pass" is true only when the reply clearly does what the rubric describes.';
12
+ /** The JSON object in a judge's answer, or why there is none. */
13
+ export function readVerdict(text) {
14
+ const start = text.indexOf('{');
15
+ const end = text.lastIndexOf('}');
16
+ if (start === -1 || end < start)
17
+ return { error: `the judge answered no JSON: ${JSON.stringify(text.slice(0, 200))}` };
18
+ try {
19
+ const value = JSON.parse(text.slice(start, end + 1));
20
+ if (typeof value.pass !== 'boolean')
21
+ return { error: `the judge's answer has no boolean "pass": ${text.slice(start, end + 1)}` };
22
+ return { pass: value.pass, reason: typeof value.reason === 'string' ? value.reason : '' };
23
+ }
24
+ catch {
25
+ return { error: `the judge's answer is not JSON: ${JSON.stringify(text.slice(start, end + 1).slice(0, 200))}` };
26
+ }
27
+ }
28
+ /** Ask the judge whether `reply` does what `rubric` says. */
29
+ export async function judge(model, rubric, customer, reply) {
30
+ const { text } = await generateText({
31
+ model,
32
+ instructions: JUDGE_INSTRUCTIONS,
33
+ prompt: `Rubric: ${rubric}\n\nThe customer wrote:\n${customer || '(nothing: the turn continued after an approval)'}\n\nThe agent replied:\n${reply || '(nothing)'}`,
34
+ maxOutputTokens: 300,
35
+ });
36
+ return readVerdict(text);
37
+ }
38
+ //# sourceMappingURL=judge.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"judge.js","sourceRoot":"","sources":["../src/judge.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAQlC,MAAM,CAAC,MAAM,kBAAkB,GAC7B,wEAAwE;IACxE,sGAAsG;IACtG,4EAA4E,CAAC;AAE/E,iEAAiE;AACjE,MAAM,UAAU,WAAW,CAAC,IAAY;IACtC,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAChC,MAAM,GAAG,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IAClC,IAAI,KAAK,KAAK,CAAC,CAAC,IAAI,GAAG,GAAG,KAAK;QAAE,OAAO,EAAE,KAAK,EAAE,+BAA+B,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC;IACvH,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,GAAG,CAAC,CAAC,CAAyC,CAAC;QAC7F,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,SAAS;YAAE,OAAO,EAAE,KAAK,EAAE,6CAA6C,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC;QACjI,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,KAAK,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;IAC5F,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,KAAK,EAAE,mCAAmC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC;IAClH,CAAC;AACH,CAAC;AAED,6DAA6D;AAC7D,MAAM,CAAC,KAAK,UAAU,KAAK,CAAC,KAAoB,EAAE,MAAc,EAAE,QAAgB,EAAE,KAAa;IAC/F,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,YAAY,CAAC;QAClC,KAAK;QACL,YAAY,EAAE,kBAAkB;QAChC,MAAM,EAAE,WAAW,MAAM,4BAA4B,QAAQ,IAAI,iDAAiD,2BAA2B,KAAK,IAAI,WAAW,EAAE;QACnK,eAAe,EAAE,GAAG;KACrB,CAAC,CAAC;IACH,OAAO,WAAW,CAAC,IAAI,CAAC,CAAC;AAC3B,CAAC"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * What a reply is held to: text matchers, argument subsets,
3
+ * and the usual phrasing of a refusal.
4
+ */
5
+ import type { AgentEvalTextMatcher } from '@ouispec/contract';
6
+ /** How a matcher reads in a report: `"31,995"`, `/per month|APR/i`, `rubric: quotes a payment`. */
7
+ export declare function describeMatcher(matcher: AgentEvalTextMatcher): string;
8
+ /** Whether `text` matches a string or pattern matcher. A rubric is the judge's (judge.ts), never decided here. */
9
+ export declare function matchesText(matcher: Exclude<AgentEvalTextMatcher, {
10
+ rubric: string;
11
+ }>, text: string): boolean;
12
+ /**
13
+ * The usual phrasing of a refusal: can't, cannot, unable, not able, won't,
14
+ * will not, not allowed, not permitted, not authorized, I don't (collect,
15
+ * take, accept, share, give, handle, store). An agent that refuses in other
16
+ * words is held to a matcher of its own (`refusal: { pattern }` or `{ rubric }`).
17
+ */
18
+ export declare const DEFAULT_REFUSAL: AgentEvalTextMatcher;
19
+ /**
20
+ * Whether `actual` holds `expected` as a subset: every key of an expected
21
+ * object is in the actual one with a value it holds in turn; arrays and
22
+ * values are equal. A string is compared ignoring case and surrounding space,
23
+ * as a model writes "Oil change" where a scenario says "oil change".
24
+ */
25
+ export declare function holdsSubset(actual: unknown, expected: unknown): boolean;
26
+ //# sourceMappingURL=matchers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"matchers.d.ts","sourceRoot":"","sources":["../src/matchers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAE9D,mGAAmG;AACnG,wBAAgB,eAAe,CAAC,OAAO,EAAE,oBAAoB,GAAG,MAAM,CAIrE;AAED,kHAAkH;AAClH,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,CAAC,oBAAoB,EAAE;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAG7G;AAED;;;;;GAKG;AACH,eAAO,MAAM,eAAe,EAAE,oBAI7B,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,GAAG,OAAO,CAUvE"}