@agentv/eval 2.6.0 → 2.7.1-next.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -8
- package/dist/index.cjs +121 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +487 -149
- package/dist/index.d.ts +487 -149
- package/dist/index.js +120 -20
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @agentv/eval
|
|
2
2
|
|
|
3
|
-
Evaluation SDK for AgentV - build custom
|
|
3
|
+
Evaluation SDK for AgentV - build custom evaluators with zero boilerplate.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -10,23 +10,43 @@ npm install @agentv/eval
|
|
|
10
10
|
|
|
11
11
|
## Quick Start
|
|
12
12
|
|
|
13
|
+
### defineAssertion (simplest way)
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
#!/usr/bin/env bun
|
|
17
|
+
import { defineAssertion } from '@agentv/eval';
|
|
18
|
+
|
|
19
|
+
export default defineAssertion(({ answer }) => ({
|
|
20
|
+
pass: answer.toLowerCase().includes('hello'),
|
|
21
|
+
reasoning: 'Checks for greeting',
|
|
22
|
+
}));
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Assertions support `pass: boolean` for simple checks and `score: number` (0-1) for granular scoring.
|
|
26
|
+
|
|
27
|
+
### defineCodeJudge (full control)
|
|
28
|
+
|
|
13
29
|
```typescript
|
|
14
30
|
#!/usr/bin/env bun
|
|
15
31
|
import { defineCodeJudge } from '@agentv/eval';
|
|
16
32
|
|
|
17
|
-
export default defineCodeJudge(({
|
|
18
|
-
score:
|
|
33
|
+
export default defineCodeJudge(({ answer, trace }) => ({
|
|
34
|
+
score: answer.length > 0 ? 1.0 : 0.0,
|
|
19
35
|
hits: ['Output received'],
|
|
20
36
|
}));
|
|
21
37
|
```
|
|
22
38
|
|
|
23
|
-
|
|
39
|
+
Both functions handle stdin/stdout parsing, snake_case conversion, Zod validation, and error handling automatically.
|
|
24
40
|
|
|
25
41
|
## Exports
|
|
26
42
|
|
|
27
|
-
- `
|
|
28
|
-
- `
|
|
29
|
-
- `
|
|
43
|
+
- `defineAssertion(handler)` - Define a custom assertion (pass/fail + optional score)
|
|
44
|
+
- `defineCodeJudge(handler)` - Define a code judge evaluator (full score control)
|
|
45
|
+
- `definePromptTemplate(handler)` - Define a dynamic prompt template
|
|
46
|
+
- `AssertionContext`, `AssertionScore` - Assertion types
|
|
47
|
+
- `CodeJudgeInput`, `CodeJudgeResult` - Code judge types
|
|
48
|
+
- `TraceSummary`, `Message`, `ToolCall` - Trace data types
|
|
49
|
+
- `createTargetClient()` - LLM target proxy for evaluators
|
|
30
50
|
- `z` - Re-exported Zod for custom config schemas
|
|
31
51
|
|
|
32
52
|
## Documentation
|
|
@@ -37,7 +57,7 @@ For complete documentation including:
|
|
|
37
57
|
- Execution metrics usage
|
|
38
58
|
- Best practices
|
|
39
59
|
|
|
40
|
-
See the [Custom Evaluators Guide](
|
|
60
|
+
See the [Custom Evaluators Guide](../../plugins/agentv-dev/skills/agentv-eval-builder/references/custom-evaluators.md) or run AgentV's `/agentv-eval-builder` skill.
|
|
41
61
|
|
|
42
62
|
## Repository
|
|
43
63
|
|
package/dist/index.cjs
CHANGED
|
@@ -30,6 +30,7 @@ __export(index_exports, {
|
|
|
30
30
|
ToolCallSchema: () => ToolCallSchema,
|
|
31
31
|
TraceSummarySchema: () => TraceSummarySchema,
|
|
32
32
|
createTargetClient: () => createTargetClient,
|
|
33
|
+
defineAssertion: () => defineAssertion,
|
|
33
34
|
defineCodeJudge: () => defineCodeJudge,
|
|
34
35
|
definePromptTemplate: () => definePromptTemplate,
|
|
35
36
|
z: () => import_zod2.z
|
|
@@ -51,34 +52,45 @@ var TraceSummarySchema = import_zod.z.object({
|
|
|
51
52
|
tokenUsage: TokenUsageSchema.optional(),
|
|
52
53
|
costUsd: import_zod.z.number().optional(),
|
|
53
54
|
durationMs: import_zod.z.number().optional(),
|
|
54
|
-
toolDurations: import_zod.z.record(import_zod.z.string(), import_zod.z.array(import_zod.z.number())).optional()
|
|
55
|
+
toolDurations: import_zod.z.record(import_zod.z.string(), import_zod.z.array(import_zod.z.number())).optional(),
|
|
56
|
+
startTime: import_zod.z.string().optional(),
|
|
57
|
+
endTime: import_zod.z.string().optional(),
|
|
58
|
+
llmCallCount: import_zod.z.number().optional()
|
|
55
59
|
});
|
|
56
60
|
var ToolCallSchema = import_zod.z.object({
|
|
57
61
|
tool: import_zod.z.string(),
|
|
58
62
|
input: import_zod.z.unknown().optional(),
|
|
59
63
|
output: import_zod.z.unknown().optional(),
|
|
60
64
|
id: import_zod.z.string().optional(),
|
|
61
|
-
|
|
65
|
+
startTime: import_zod.z.string().optional(),
|
|
66
|
+
endTime: import_zod.z.string().optional(),
|
|
67
|
+
durationMs: import_zod.z.number().optional()
|
|
62
68
|
});
|
|
63
69
|
var MessageSchema = import_zod.z.object({
|
|
64
70
|
role: import_zod.z.enum(["assistant", "user", "system", "tool"]),
|
|
65
71
|
content: import_zod.z.union([import_zod.z.string(), import_zod.z.record(import_zod.z.unknown()), import_zod.z.array(import_zod.z.record(import_zod.z.unknown()))]).optional(),
|
|
66
72
|
toolCalls: import_zod.z.array(ToolCallSchema).optional(),
|
|
67
73
|
name: import_zod.z.string().optional(),
|
|
68
|
-
|
|
74
|
+
startTime: import_zod.z.string().optional(),
|
|
75
|
+
endTime: import_zod.z.string().optional(),
|
|
76
|
+
durationMs: import_zod.z.number().optional(),
|
|
69
77
|
metadata: import_zod.z.record(import_zod.z.unknown()).optional()
|
|
70
78
|
});
|
|
71
79
|
var CodeJudgeInputSchema = import_zod.z.object({
|
|
72
80
|
question: import_zod.z.string(),
|
|
73
|
-
|
|
74
|
-
|
|
81
|
+
criteria: import_zod.z.string(),
|
|
82
|
+
expectedOutput: import_zod.z.array(MessageSchema),
|
|
75
83
|
referenceAnswer: import_zod.z.string().optional(),
|
|
76
|
-
|
|
77
|
-
|
|
84
|
+
answer: import_zod.z.string(),
|
|
85
|
+
output: import_zod.z.array(MessageSchema).nullable().optional(),
|
|
86
|
+
/** Path to a temp file containing the output JSON (used for large payloads). */
|
|
87
|
+
outputPath: import_zod.z.string().optional(),
|
|
78
88
|
guidelineFiles: import_zod.z.array(import_zod.z.string()),
|
|
79
89
|
inputFiles: import_zod.z.array(import_zod.z.string()),
|
|
80
|
-
|
|
81
|
-
|
|
90
|
+
input: import_zod.z.array(MessageSchema),
|
|
91
|
+
trace: TraceSummarySchema.nullable().optional(),
|
|
92
|
+
fileChanges: import_zod.z.string().nullable().optional(),
|
|
93
|
+
workspacePath: import_zod.z.string().nullable().optional(),
|
|
82
94
|
config: import_zod.z.record(import_zod.z.unknown()).nullable().optional()
|
|
83
95
|
});
|
|
84
96
|
var CodeJudgeResultSchema = import_zod.z.object({
|
|
@@ -202,7 +214,7 @@ function createTargetClientInternal(url, token) {
|
|
|
202
214
|
// src/index.ts
|
|
203
215
|
var import_zod2 = require("zod");
|
|
204
216
|
|
|
205
|
-
// src/
|
|
217
|
+
// src/assertion.ts
|
|
206
218
|
var import_node_fs = require("fs");
|
|
207
219
|
|
|
208
220
|
// src/case-conversion.ts
|
|
@@ -230,15 +242,86 @@ function toCamelCaseDeep(obj) {
|
|
|
230
242
|
return obj;
|
|
231
243
|
}
|
|
232
244
|
|
|
233
|
-
// src/
|
|
245
|
+
// src/assertion.ts
|
|
234
246
|
function readStdin() {
|
|
235
247
|
return (0, import_node_fs.readFileSync)(0, "utf8");
|
|
236
248
|
}
|
|
237
|
-
|
|
249
|
+
function clampScore(value) {
|
|
250
|
+
if (Number.isNaN(value) || !Number.isFinite(value)) {
|
|
251
|
+
return 0;
|
|
252
|
+
}
|
|
253
|
+
return Math.max(0, Math.min(1, value));
|
|
254
|
+
}
|
|
255
|
+
function formatError(error) {
|
|
256
|
+
if (error instanceof Error) {
|
|
257
|
+
return error.message;
|
|
258
|
+
}
|
|
259
|
+
return String(error);
|
|
260
|
+
}
|
|
261
|
+
function normalizeScore(result) {
|
|
262
|
+
let score;
|
|
263
|
+
if (result.score !== void 0) {
|
|
264
|
+
score = clampScore(result.score);
|
|
265
|
+
} else if (result.pass !== void 0) {
|
|
266
|
+
score = result.pass ? 1 : 0;
|
|
267
|
+
} else {
|
|
268
|
+
score = 0;
|
|
269
|
+
}
|
|
270
|
+
return {
|
|
271
|
+
score,
|
|
272
|
+
hits: result.hits ? [...result.hits] : [],
|
|
273
|
+
misses: result.misses ? [...result.misses] : [],
|
|
274
|
+
reasoning: result.reasoning,
|
|
275
|
+
details: result.details
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
async function runAssertion(handler) {
|
|
238
279
|
try {
|
|
239
280
|
const stdin = readStdin();
|
|
240
281
|
const rawInput = JSON.parse(stdin);
|
|
241
282
|
const camelInput = toCamelCaseDeep(rawInput);
|
|
283
|
+
const input = CodeJudgeInputSchema.parse(camelInput);
|
|
284
|
+
if (input.outputPath && (input.output === null || input.output === void 0)) {
|
|
285
|
+
let cachedOutput;
|
|
286
|
+
const filePath = input.outputPath;
|
|
287
|
+
Object.defineProperty(input, "output", {
|
|
288
|
+
get() {
|
|
289
|
+
if (cachedOutput === void 0) {
|
|
290
|
+
cachedOutput = JSON.parse((0, import_node_fs.readFileSync)(filePath, "utf8"));
|
|
291
|
+
}
|
|
292
|
+
return cachedOutput;
|
|
293
|
+
},
|
|
294
|
+
configurable: true,
|
|
295
|
+
enumerable: true
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
const rawResult = await handler(input);
|
|
299
|
+
const normalized = normalizeScore(rawResult);
|
|
300
|
+
const result = CodeJudgeResultSchema.parse(normalized);
|
|
301
|
+
console.log(JSON.stringify(result, null, 2));
|
|
302
|
+
} catch (error) {
|
|
303
|
+
const errorMessage = formatError(error);
|
|
304
|
+
const errorResult = {
|
|
305
|
+
score: 0,
|
|
306
|
+
hits: [],
|
|
307
|
+
misses: [errorMessage],
|
|
308
|
+
reasoning: `Assertion failed: ${errorMessage}`
|
|
309
|
+
};
|
|
310
|
+
console.log(JSON.stringify(errorResult, null, 2));
|
|
311
|
+
process.exit(1);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// src/prompt-template.ts
|
|
316
|
+
var import_node_fs2 = require("fs");
|
|
317
|
+
function readStdin2() {
|
|
318
|
+
return (0, import_node_fs2.readFileSync)(0, "utf8");
|
|
319
|
+
}
|
|
320
|
+
async function runPromptTemplate(handler) {
|
|
321
|
+
try {
|
|
322
|
+
const stdin = readStdin2();
|
|
323
|
+
const rawInput = JSON.parse(stdin);
|
|
324
|
+
const camelInput = toCamelCaseDeep(rawInput);
|
|
242
325
|
const input = PromptTemplateInputSchema.parse(camelInput);
|
|
243
326
|
const prompt = await handler(input);
|
|
244
327
|
console.log(prompt);
|
|
@@ -249,17 +332,17 @@ async function runPromptTemplate(handler) {
|
|
|
249
332
|
}
|
|
250
333
|
|
|
251
334
|
// src/runtime.ts
|
|
252
|
-
var
|
|
253
|
-
function
|
|
254
|
-
return (0,
|
|
335
|
+
var import_node_fs3 = require("fs");
|
|
336
|
+
function readStdin3() {
|
|
337
|
+
return (0, import_node_fs3.readFileSync)(0, "utf8");
|
|
255
338
|
}
|
|
256
|
-
function
|
|
339
|
+
function clampScore2(value) {
|
|
257
340
|
if (Number.isNaN(value) || !Number.isFinite(value)) {
|
|
258
341
|
return 0;
|
|
259
342
|
}
|
|
260
343
|
return Math.max(0, Math.min(1, value));
|
|
261
344
|
}
|
|
262
|
-
function
|
|
345
|
+
function formatError2(error) {
|
|
263
346
|
if (error instanceof Error) {
|
|
264
347
|
return error.message;
|
|
265
348
|
}
|
|
@@ -267,18 +350,32 @@ function formatError(error) {
|
|
|
267
350
|
}
|
|
268
351
|
async function runCodeJudge(handler) {
|
|
269
352
|
try {
|
|
270
|
-
const stdin =
|
|
353
|
+
const stdin = readStdin3();
|
|
271
354
|
const rawInput = JSON.parse(stdin);
|
|
272
355
|
const camelInput = toCamelCaseDeep(rawInput);
|
|
273
356
|
const input = CodeJudgeInputSchema.parse(camelInput);
|
|
357
|
+
if (input.outputPath && (input.output === null || input.output === void 0)) {
|
|
358
|
+
let cachedOutput;
|
|
359
|
+
const filePath = input.outputPath;
|
|
360
|
+
Object.defineProperty(input, "output", {
|
|
361
|
+
get() {
|
|
362
|
+
if (cachedOutput === void 0) {
|
|
363
|
+
cachedOutput = JSON.parse((0, import_node_fs3.readFileSync)(filePath, "utf8"));
|
|
364
|
+
}
|
|
365
|
+
return cachedOutput;
|
|
366
|
+
},
|
|
367
|
+
configurable: true,
|
|
368
|
+
enumerable: true
|
|
369
|
+
});
|
|
370
|
+
}
|
|
274
371
|
const rawResult = await handler(input);
|
|
275
372
|
const result = CodeJudgeResultSchema.parse({
|
|
276
373
|
...rawResult,
|
|
277
|
-
score:
|
|
374
|
+
score: clampScore2(rawResult.score)
|
|
278
375
|
});
|
|
279
376
|
console.log(JSON.stringify(result, null, 2));
|
|
280
377
|
} catch (error) {
|
|
281
|
-
const errorMessage =
|
|
378
|
+
const errorMessage = formatError2(error);
|
|
282
379
|
const errorResult = {
|
|
283
380
|
score: 0,
|
|
284
381
|
hits: [],
|
|
@@ -297,6 +394,9 @@ function defineCodeJudge(handler) {
|
|
|
297
394
|
function definePromptTemplate(handler) {
|
|
298
395
|
runPromptTemplate(handler);
|
|
299
396
|
}
|
|
397
|
+
function defineAssertion(handler) {
|
|
398
|
+
runAssertion(handler);
|
|
399
|
+
}
|
|
300
400
|
// Annotate the CommonJS export names for ESM import in node:
|
|
301
401
|
0 && (module.exports = {
|
|
302
402
|
CodeJudgeInputSchema,
|
|
@@ -309,6 +409,7 @@ function definePromptTemplate(handler) {
|
|
|
309
409
|
ToolCallSchema,
|
|
310
410
|
TraceSummarySchema,
|
|
311
411
|
createTargetClient,
|
|
412
|
+
defineAssertion,
|
|
312
413
|
defineCodeJudge,
|
|
313
414
|
definePromptTemplate,
|
|
314
415
|
z
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/schemas.ts","../src/target-client.ts","../src/prompt-template.ts","../src/case-conversion.ts","../src/runtime.ts"],"sourcesContent":["/**\n * AgentV Evaluation SDK\n *\n * Build custom code judges for evaluating AI agent outputs.\n *\n * @example Basic code judge\n * ```typescript\n * #!/usr/bin/env bun\n * import { defineCodeJudge } from '@agentv/eval';\n *\n * export default defineCodeJudge(({ traceSummary, candidateAnswer }) => ({\n * score: traceSummary?.eventCount <= 5 ? 1.0 : 0.5,\n * hits: ['Efficient tool usage'],\n * misses: [],\n * }));\n * ```\n *\n * @example Code judge with target access (requires `target` config in YAML)\n * ```typescript\n * #!/usr/bin/env bun\n * import { defineCodeJudge, createTargetClient } from '@agentv/eval';\n *\n * export default defineCodeJudge(async ({ question }) => {\n * const target = createTargetClient();\n * if (!target) {\n * return { score: 0, misses: ['Target not available'] };\n * }\n *\n * const response = await target.invoke({\n * question: `Evaluate: ${question}`,\n * systemPrompt: 'Respond with JSON: { \"score\": 0-1 }'\n * });\n *\n * const result = JSON.parse(response.rawText ?? '{}');\n * return { score: result.score ?? 0 };\n * });\n * ```\n *\n * @packageDocumentation\n */\n\n// Re-export schemas and types\nexport {\n CodeJudgeInputSchema,\n CodeJudgeResultSchema,\n TraceSummarySchema,\n MessageSchema,\n ToolCallSchema,\n TokenUsageSchema,\n PromptTemplateInputSchema,\n type CodeJudgeInput,\n type CodeJudgeResult,\n type TraceSummary,\n type Message,\n type ToolCall,\n type TokenUsage,\n type PromptTemplateInput,\n} from './schemas.js';\n\n// Re-export target client\nexport {\n createTargetClient,\n TargetNotAvailableError,\n TargetInvocationError,\n type TargetClient,\n type TargetInfo,\n type TargetInvokeRequest,\n type TargetInvokeResponse,\n} from './target-client.js';\n\n// Re-export Zod for typed config support\nexport { z } from 'zod';\n\nimport { type PromptTemplateHandler, runPromptTemplate } from './prompt-template.js';\n// Import runtime\nimport { type CodeJudgeHandler, runCodeJudge } from './runtime.js';\n\nexport type { CodeJudgeHandler };\nexport type { PromptTemplateHandler };\n\n/**\n * Define a code judge evaluator with automatic stdin/stdout handling.\n *\n * This function:\n * 1. Reads JSON from stdin (snake_case format)\n * 2. Converts to camelCase and validates with Zod\n * 3. Calls your handler with typed input\n * 4. Validates the result and outputs JSON to stdout\n * 5. Handles errors gracefully with proper exit codes\n *\n * @param handler - Function that evaluates the input and returns a result\n *\n * @example\n * ```typescript\n * import { defineCodeJudge } from '@agentv/eval';\n *\n * export default defineCodeJudge(({ traceSummary }) => {\n * if (!traceSummary) {\n * return { score: 0.5, reasoning: 'No trace available' };\n * }\n *\n * const efficient = traceSummary.eventCount <= 10;\n * return {\n * score: efficient ? 1.0 : 0.5,\n * hits: efficient ? ['Efficient execution'] : [],\n * misses: efficient ? [] : ['Too many tool calls'],\n * };\n * });\n * ```\n *\n * @example With typed config\n * ```typescript\n * import { defineCodeJudge, z } from '@agentv/eval';\n *\n * const ConfigSchema = z.object({\n * maxToolCalls: z.number().default(10),\n * });\n *\n * export default defineCodeJudge(({ traceSummary, config }) => {\n * const { maxToolCalls } = ConfigSchema.parse(config ?? {});\n * // Use maxToolCalls...\n * });\n * ```\n */\nexport function defineCodeJudge(handler: CodeJudgeHandler): void {\n // Run immediately when module is loaded\n runCodeJudge(handler);\n}\n\n/**\n * Define a prompt template with automatic stdin/stdout handling.\n *\n * This function:\n * 1. Reads JSON from stdin (snake_case format)\n * 2. Converts to camelCase and validates with Zod\n * 3. Calls your handler with typed input\n * 4. Outputs the generated prompt string to stdout\n * 5. Handles errors gracefully with proper exit codes\n *\n * @param handler - Function that generates the prompt string from input\n *\n * @example\n * ```typescript\n * import { definePromptTemplate } from '@agentv/eval';\n *\n * export default definePromptTemplate((ctx) => `\n * Question: ${ctx.question}\n * Answer: ${ctx.candidateAnswer}\n *\n * ${ctx.referenceAnswer ? `Reference: ${ctx.referenceAnswer}` : ''}\n * `);\n * ```\n *\n * @example With conditional logic\n * ```typescript\n * import { definePromptTemplate } from '@agentv/eval';\n *\n * export default definePromptTemplate((ctx) => {\n * const rubric = ctx.config?.rubric as string | undefined;\n * return `\n * Question: ${ctx.question}\n * Candidate Answer: ${ctx.candidateAnswer}\n * ${rubric ? `\\nEvaluation Criteria:\\n${rubric}` : ''}\n * `;\n * });\n * ```\n */\nexport function definePromptTemplate(handler: PromptTemplateHandler): void {\n // Run immediately when module is loaded\n runPromptTemplate(handler);\n}\n","/**\n * Zod schemas for code judge input/output validation.\n * Provides both compile-time types and runtime validation.\n */\nimport { z } from 'zod';\n\n/**\n * Token usage metrics schema.\n */\nexport const TokenUsageSchema = z.object({\n input: z.number(),\n output: z.number(),\n cached: z.number().optional(),\n});\n\n/**\n * Trace summary schema (camelCase for TypeScript ergonomics).\n */\nexport const TraceSummarySchema = z.object({\n eventCount: z.number(),\n toolNames: z.array(z.string()),\n toolCallsByName: z.record(z.string(), z.number()),\n errorCount: z.number(),\n tokenUsage: TokenUsageSchema.optional(),\n costUsd: z.number().optional(),\n durationMs: z.number().optional(),\n toolDurations: z.record(z.string(), z.array(z.number())).optional(),\n});\n\n/**\n * Tool call schema.\n */\nexport const ToolCallSchema = z.object({\n tool: z.string(),\n input: z.unknown().optional(),\n output: z.unknown().optional(),\n id: z.string().optional(),\n timestamp: z.string().optional(),\n});\n\n/**\n * Unified message schema for input, expected, and output messages.\n */\nexport const MessageSchema = z.object({\n role: z.enum(['assistant', 'user', 'system', 'tool']),\n content: z.union([z.string(), z.record(z.unknown()), z.array(z.record(z.unknown()))]).optional(),\n toolCalls: z.array(ToolCallSchema).optional(),\n name: z.string().optional(),\n timestamp: z.string().optional(),\n metadata: z.record(z.unknown()).optional(),\n});\n\n/**\n * Code judge input schema (camelCase, converted from snake_case wire format).\n */\nexport const CodeJudgeInputSchema = z.object({\n question: z.string(),\n expectedOutcome: z.string(),\n expectedMessages: z.array(MessageSchema),\n referenceAnswer: z.string().optional(),\n candidateAnswer: z.string(),\n outputMessages: z.array(MessageSchema).nullable().optional(),\n guidelineFiles: z.array(z.string()),\n inputFiles: z.array(z.string()),\n inputMessages: z.array(MessageSchema),\n traceSummary: TraceSummarySchema.nullable().optional(),\n config: z.record(z.unknown()).nullable().optional(),\n});\n\n/**\n * Code judge result schema (validated before output).\n */\nexport const CodeJudgeResultSchema = z.object({\n score: z.number().min(0).max(1),\n hits: z.array(z.string()).optional().default([]),\n misses: z.array(z.string()).optional().default([]),\n reasoning: z.string().optional(),\n /** Optional structured details for domain-specific metrics (e.g., TP/TN/FP/FN counts, alignments). */\n details: z.record(z.unknown()).optional(),\n});\n\n/**\n * Inferred types from schemas.\n */\nexport type CodeJudgeInput = z.infer<typeof CodeJudgeInputSchema>;\nexport type CodeJudgeResult = z.infer<typeof CodeJudgeResultSchema>;\nexport type TraceSummary = z.infer<typeof TraceSummarySchema>;\nexport type Message = z.infer<typeof MessageSchema>;\nexport type ToolCall = z.infer<typeof ToolCallSchema>;\nexport type TokenUsage = z.infer<typeof TokenUsageSchema>;\n\n/**\n * Prompt template input schema (camelCase, converted from snake_case wire format).\n * Uses the same schema as CodeJudgeInput since the orchestrator sends identical payloads.\n */\nexport const PromptTemplateInputSchema = CodeJudgeInputSchema;\n\nexport type PromptTemplateInput = CodeJudgeInput;\n","/**\n * Client for invoking configured targets from code_judge scripts.\n *\n * Environment variables (set automatically by AgentV when `target` config is present):\n * - AGENTV_TARGET_PROXY_URL: The URL of the local proxy server\n * - AGENTV_TARGET_PROXY_TOKEN: Bearer token for authentication\n */\n\n/**\n * Request to invoke the target\n */\nexport interface TargetInvokeRequest {\n readonly question: string;\n readonly systemPrompt?: string;\n readonly evalCaseId?: string;\n readonly attempt?: number;\n /** Optional target override - use a different target for this invocation */\n readonly target?: string;\n}\n\n/**\n * Response from a target invocation\n */\nexport interface TargetInvokeResponse {\n readonly outputMessages: readonly unknown[];\n readonly rawText?: string;\n}\n\n/**\n * Information about the target proxy configuration\n */\nexport interface TargetInfo {\n /** Name of the default target being used */\n readonly targetName: string;\n /** Maximum number of calls allowed */\n readonly maxCalls: number;\n /** Current number of calls made */\n readonly callCount: number;\n /** List of all available target names */\n readonly availableTargets: readonly string[];\n}\n\n/**\n * Target client for making target invocations\n */\nexport interface TargetClient {\n /**\n * Invoke the configured target with a prompt.\n * @param request - The question and optional system prompt\n * @returns The target's response with output messages and optional raw text\n */\n invoke(request: TargetInvokeRequest): Promise<TargetInvokeResponse>;\n\n /**\n * Invoke the target with multiple requests in sequence.\n * Each request counts toward the max_calls limit.\n * @param requests - Array of target requests\n * @returns Array of target responses\n */\n invokeBatch(requests: readonly TargetInvokeRequest[]): Promise<readonly TargetInvokeResponse[]>;\n\n /**\n * Get information about the target proxy configuration.\n * Returns the default target name, max calls, current call count, and available targets.\n */\n getInfo(): Promise<TargetInfo>;\n}\n\n/**\n * Error thrown when target proxy is not available\n */\nexport class TargetNotAvailableError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'TargetNotAvailableError';\n }\n}\n\n/**\n * Error thrown when target invocation fails\n */\nexport class TargetInvocationError extends Error {\n readonly statusCode?: number;\n\n constructor(message: string, statusCode?: number) {\n super(message);\n this.name = 'TargetInvocationError';\n this.statusCode = statusCode;\n }\n}\n\n/**\n * Create a target client from environment variables.\n *\n * This function reads the proxy URL and token from environment variables\n * that are automatically set by AgentV when a `target` config block is present\n * on a `code_judge` evaluator.\n *\n * @returns A target client if environment variables are set, otherwise undefined\n * @throws TargetNotAvailableError if token is missing when URL is present\n *\n * @example\n * ```typescript\n * import { createTargetClient, defineCodeJudge } from '@agentv/eval';\n *\n * export default defineCodeJudge(async ({ question, expectedOutcome }) => {\n * const target = createTargetClient();\n *\n * if (!target) {\n * // Target not available - no target config on this evaluator\n * return { score: 0.5, reasoning: 'Target not available' };\n * }\n *\n * const response = await target.invoke({\n * question: `Is this answer correct? Question: ${question}, Expected: ${expectedOutcome}`,\n * systemPrompt: 'You are an expert evaluator. Respond with JSON: { \"correct\": true/false }'\n * });\n *\n * const result = JSON.parse(response.rawText ?? '{}');\n * return { score: result.correct ? 1.0 : 0.0 };\n * });\n * ```\n */\nexport function createTargetClient(): TargetClient | undefined {\n const proxyUrl = process.env.AGENTV_TARGET_PROXY_URL;\n const proxyToken = process.env.AGENTV_TARGET_PROXY_TOKEN;\n\n if (!proxyUrl) {\n return undefined;\n }\n\n if (!proxyToken) {\n throw new TargetNotAvailableError(\n 'AGENTV_TARGET_PROXY_URL is set but AGENTV_TARGET_PROXY_TOKEN is missing',\n );\n }\n\n return createTargetClientInternal(proxyUrl, proxyToken);\n}\n\n/**\n * Internal: Create a target client with explicit URL and token.\n * Exported for testing only - use createTargetClient() in production.\n */\nexport function createTargetClientInternal(url: string, token: string): TargetClient {\n const headers = {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${token}`,\n };\n\n return {\n async invoke(request: TargetInvokeRequest): Promise<TargetInvokeResponse> {\n const response = await fetch(`${url}/invoke`, {\n method: 'POST',\n headers,\n body: JSON.stringify({\n question: request.question,\n systemPrompt: request.systemPrompt,\n evalCaseId: request.evalCaseId,\n attempt: request.attempt,\n target: request.target,\n }),\n });\n\n if (!response.ok) {\n const errorBody = await response.text();\n let errorMessage: string;\n try {\n const errorJson = JSON.parse(errorBody) as { error?: string };\n errorMessage = errorJson.error ?? `HTTP ${response.status}`;\n } catch {\n errorMessage = errorBody || `HTTP ${response.status}`;\n }\n throw new TargetInvocationError(errorMessage, response.status);\n }\n\n return (await response.json()) as TargetInvokeResponse;\n },\n\n async invokeBatch(\n requests: readonly TargetInvokeRequest[],\n ): Promise<readonly TargetInvokeResponse[]> {\n const response = await fetch(`${url}/invokeBatch`, {\n method: 'POST',\n headers,\n body: JSON.stringify({\n requests: requests.map((r) => ({\n question: r.question,\n systemPrompt: r.systemPrompt,\n evalCaseId: r.evalCaseId,\n attempt: r.attempt,\n target: r.target,\n })),\n }),\n });\n\n if (!response.ok) {\n const errorBody = await response.text();\n let errorMessage: string;\n try {\n const errorJson = JSON.parse(errorBody) as { error?: string };\n errorMessage = errorJson.error ?? `HTTP ${response.status}`;\n } catch {\n errorMessage = errorBody || `HTTP ${response.status}`;\n }\n throw new TargetInvocationError(errorMessage, response.status);\n }\n\n const result = (await response.json()) as { responses: TargetInvokeResponse[] };\n return result.responses;\n },\n\n async getInfo(): Promise<TargetInfo> {\n const response = await fetch(`${url}/info`, {\n method: 'GET',\n headers,\n });\n\n if (!response.ok) {\n const errorBody = await response.text();\n let errorMessage: string;\n try {\n const errorJson = JSON.parse(errorBody) as { error?: string };\n errorMessage = errorJson.error ?? `HTTP ${response.status}`;\n } catch {\n errorMessage = errorBody || `HTTP ${response.status}`;\n }\n throw new TargetInvocationError(errorMessage, response.status);\n }\n\n return (await response.json()) as TargetInfo;\n },\n };\n}\n","/**\n * Runtime for prompt template evaluators.\n * Handles stdin parsing, validation, error handling, and string output.\n */\nimport { readFileSync } from 'node:fs';\n\nimport { toCamelCaseDeep } from './case-conversion.js';\nimport { type PromptTemplateInput, PromptTemplateInputSchema } from './schemas.js';\n\n/**\n * Handler function type for prompt templates.\n * Returns the prompt string to use for evaluation.\n */\nexport type PromptTemplateHandler = (input: PromptTemplateInput) => string | Promise<string>;\n\n/**\n * Read stdin synchronously (works in both Node.js and Bun).\n */\nfunction readStdin(): string {\n return readFileSync(0, 'utf8');\n}\n\n/**\n * Run a prompt template handler with full stdin/stdout handling.\n * This is the internal implementation called by definePromptTemplate.\n */\nexport async function runPromptTemplate(handler: PromptTemplateHandler): Promise<void> {\n try {\n // 1. Read stdin\n const stdin = readStdin();\n\n // 2. Parse JSON\n const rawInput = JSON.parse(stdin) as Record<string, unknown>;\n\n // 3. Convert snake_case to camelCase\n const camelInput = toCamelCaseDeep(rawInput);\n\n // 4. Validate input with Zod\n const input = PromptTemplateInputSchema.parse(camelInput);\n\n // 5. Run handler\n const prompt = await handler(input);\n\n // 6. Output raw string (not JSON) - the prompt itself\n console.log(prompt);\n } catch (error) {\n // Output error to stderr and exit with non-zero code\n console.error(error instanceof Error ? error.message : String(error));\n process.exit(1);\n }\n}\n\n/**\n * Define a prompt template with automatic stdin/stdout handling.\n *\n * This function:\n * 1. Reads JSON from stdin (snake_case format)\n * 2. Converts to camelCase and validates with Zod\n * 3. Calls your handler with typed input\n * 4. Outputs the generated prompt string to stdout\n * 5. Handles errors gracefully with proper exit codes\n *\n * @param handler - Function that generates the prompt string from input\n *\n * @example\n * ```typescript\n * import { definePromptTemplate } from '@agentv/eval';\n *\n * export default definePromptTemplate((ctx) => `\n * Question: ${ctx.question}\n * Answer: ${ctx.candidateAnswer}\n *\n * ${ctx.referenceAnswer ? `Reference: ${ctx.referenceAnswer}` : ''}\n * `);\n * ```\n *\n * @example With conditional logic\n * ```typescript\n * import { definePromptTemplate } from '@agentv/eval';\n *\n * export default definePromptTemplate((ctx) => {\n * const rubric = ctx.config?.rubric as string | undefined;\n * return `\n * Question: ${ctx.question}\n * Candidate Answer: ${ctx.candidateAnswer}\n * ${rubric ? `\\nEvaluation Criteria:\\n${rubric}` : ''}\n * `;\n * });\n * ```\n *\n * @example Async handler\n * ```typescript\n * import { definePromptTemplate } from '@agentv/eval';\n *\n * export default definePromptTemplate(async (ctx) => {\n * // Async operations are supported\n * return `Question: ${ctx.question}\\nAnswer: ${ctx.candidateAnswer}`;\n * });\n * ```\n */\nexport function definePromptTemplate(handler: PromptTemplateHandler): void {\n // Run immediately when module is loaded\n runPromptTemplate(handler);\n}\n","/**\n * Case conversion utilities for JSON payloads.\n * Converts between snake_case (wire format) and camelCase (TypeScript).\n */\n\nfunction toCamelCase(str: string): string {\n // Don't convert keys that start with uppercase (proper nouns/tool names)\n if (/^[A-Z]/.test(str)) {\n return str;\n }\n return str.replace(/_([a-z0-9])/g, (_, letter) => letter.toUpperCase());\n}\n\n/**\n * Recursively converts all keys in an object from snake_case to camelCase.\n * Used to map wire payloads into TypeScript-friendly shapes.\n *\n * @param obj - The object to convert (can be any JSON-serializable value)\n * @returns A new object with all keys converted to camelCase\n */\nexport function toCamelCaseDeep(obj: unknown): unknown {\n if (obj === null || obj === undefined) {\n return obj;\n }\n\n if (Array.isArray(obj)) {\n return obj.map((item) => toCamelCaseDeep(item));\n }\n\n if (typeof obj === 'object') {\n const result: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(obj)) {\n const camelKey = toCamelCase(key);\n result[camelKey] = toCamelCaseDeep(value);\n }\n return result;\n }\n\n return obj;\n}\n","/**\n * Runtime for code judge evaluators.\n * Handles stdin parsing, validation, error handling, and output formatting.\n */\nimport { readFileSync } from 'node:fs';\n\nimport { toCamelCaseDeep } from './case-conversion.js';\nimport {\n type CodeJudgeInput,\n CodeJudgeInputSchema,\n type CodeJudgeResult,\n CodeJudgeResultSchema,\n} from './schemas.js';\n\n/**\n * Handler function type for code judges.\n */\nexport type CodeJudgeHandler = (\n input: CodeJudgeInput,\n) => CodeJudgeResult | Promise<CodeJudgeResult>;\n\n/**\n * Read stdin synchronously (works in both Node.js and Bun).\n */\nfunction readStdin(): string {\n return readFileSync(0, 'utf8');\n}\n\n/**\n * Clamp a value to the range [0, 1].\n */\nfunction clampScore(value: number): number {\n if (Number.isNaN(value) || !Number.isFinite(value)) {\n return 0;\n }\n return Math.max(0, Math.min(1, value));\n}\n\n/**\n * Format an error for output.\n */\nfunction formatError(error: unknown): string {\n if (error instanceof Error) {\n return error.message;\n }\n return String(error);\n}\n\n/**\n * Run a code judge handler with full stdin/stdout handling.\n * This is the internal implementation called by defineCodeJudge.\n */\nexport async function runCodeJudge(handler: CodeJudgeHandler): Promise<void> {\n try {\n // 1. Read stdin\n const stdin = readStdin();\n\n // 2. Parse JSON\n const rawInput = JSON.parse(stdin) as Record<string, unknown>;\n\n // 3. Convert snake_case to camelCase\n const camelInput = toCamelCaseDeep(rawInput);\n\n // 4. Validate input with Zod\n const input = CodeJudgeInputSchema.parse(camelInput);\n\n // 5. Run handler\n const rawResult = await handler(input);\n\n // 6. Validate and normalize output\n const result = CodeJudgeResultSchema.parse({\n ...rawResult,\n score: clampScore(rawResult.score),\n });\n\n // 7. Output JSON\n console.log(JSON.stringify(result, null, 2));\n } catch (error) {\n // Output failure result\n const errorMessage = formatError(error);\n const errorResult: CodeJudgeResult = {\n score: 0,\n hits: [],\n misses: [errorMessage],\n reasoning: `Evaluation failed: ${errorMessage}`,\n };\n console.log(JSON.stringify(errorResult, null, 2));\n process.exit(1);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACIA,iBAAkB;AAKX,IAAM,mBAAmB,aAAE,OAAO;AAAA,EACvC,OAAO,aAAE,OAAO;AAAA,EAChB,QAAQ,aAAE,OAAO;AAAA,EACjB,QAAQ,aAAE,OAAO,EAAE,SAAS;AAC9B,CAAC;AAKM,IAAM,qBAAqB,aAAE,OAAO;AAAA,EACzC,YAAY,aAAE,OAAO;AAAA,EACrB,WAAW,aAAE,MAAM,aAAE,OAAO,CAAC;AAAA,EAC7B,iBAAiB,aAAE,OAAO,aAAE,OAAO,GAAG,aAAE,OAAO,CAAC;AAAA,EAChD,YAAY,aAAE,OAAO;AAAA,EACrB,YAAY,iBAAiB,SAAS;AAAA,EACtC,SAAS,aAAE,OAAO,EAAE,SAAS;AAAA,EAC7B,YAAY,aAAE,OAAO,EAAE,SAAS;AAAA,EAChC,eAAe,aAAE,OAAO,aAAE,OAAO,GAAG,aAAE,MAAM,aAAE,OAAO,CAAC,CAAC,EAAE,SAAS;AACpE,CAAC;AAKM,IAAM,iBAAiB,aAAE,OAAO;AAAA,EACrC,MAAM,aAAE,OAAO;AAAA,EACf,OAAO,aAAE,QAAQ,EAAE,SAAS;AAAA,EAC5B,QAAQ,aAAE,QAAQ,EAAE,SAAS;AAAA,EAC7B,IAAI,aAAE,OAAO,EAAE,SAAS;AAAA,EACxB,WAAW,aAAE,OAAO,EAAE,SAAS;AACjC,CAAC;AAKM,IAAM,gBAAgB,aAAE,OAAO;AAAA,EACpC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/index.ts","../src/schemas.ts","../src/target-client.ts","../src/assertion.ts","../src/case-conversion.ts","../src/prompt-template.ts","../src/runtime.ts"],"sourcesContent":["/**\n * AgentV Evaluation SDK\n *\n * Build custom evaluators for AI agent outputs.\n *\n * @example Custom assertion (simplest way to add evaluation logic)\n * ```typescript\n * #!/usr/bin/env bun\n * import { defineAssertion } from '@agentv/eval';\n *\n * export default defineAssertion(({ answer }) => ({\n * pass: answer.includes('hello'),\n * reasoning: 'Checks greeting',\n * }));\n * ```\n *\n * @example Code judge (full control)\n * ```typescript\n * #!/usr/bin/env bun\n * import { defineCodeJudge } from '@agentv/eval';\n *\n * export default defineCodeJudge(({ trace, answer }) => ({\n * score: trace?.eventCount <= 5 ? 1.0 : 0.5,\n * hits: ['Efficient tool usage'],\n * misses: [],\n * }));\n * ```\n *\n * @example Code judge with target access (requires `target` config in YAML)\n * ```typescript\n * #!/usr/bin/env bun\n * import { defineCodeJudge, createTargetClient } from '@agentv/eval';\n *\n * export default defineCodeJudge(async ({ question }) => {\n * const target = createTargetClient();\n * if (!target) {\n * return { score: 0, misses: ['Target not available'] };\n * }\n *\n * const response = await target.invoke({\n * question: `Evaluate: ${question}`,\n * systemPrompt: 'Respond with JSON: { \"score\": 0-1 }'\n * });\n *\n * const result = JSON.parse(response.rawText ?? '{}');\n * return { score: result.score ?? 0 };\n * });\n * ```\n *\n * @packageDocumentation\n */\n\n// Re-export schemas and types\nexport {\n CodeJudgeInputSchema,\n CodeJudgeResultSchema,\n TraceSummarySchema,\n MessageSchema,\n ToolCallSchema,\n TokenUsageSchema,\n PromptTemplateInputSchema,\n type CodeJudgeInput,\n type CodeJudgeResult,\n type TraceSummary,\n type Message,\n type ToolCall,\n type TokenUsage,\n type PromptTemplateInput,\n} from './schemas.js';\n\n// Re-export target client\nexport {\n createTargetClient,\n TargetNotAvailableError,\n TargetInvocationError,\n type TargetClient,\n type TargetInfo,\n type TargetInvokeRequest,\n type TargetInvokeResponse,\n} from './target-client.js';\n\n// Re-export Zod for typed config support\nexport { z } from 'zod';\n\n// Re-export assertion types\nexport type {\n AssertionContext,\n AssertionHandler,\n AssertionScore,\n AssertionType,\n} from './assertion.js';\n\nimport { type AssertionHandler, runAssertion } from './assertion.js';\nimport { type PromptTemplateHandler, runPromptTemplate } from './prompt-template.js';\nimport { type CodeJudgeHandler, runCodeJudge } from './runtime.js';\n\nexport type { CodeJudgeHandler };\nexport type { PromptTemplateHandler };\n\n/**\n * Define a code judge evaluator with automatic stdin/stdout handling.\n *\n * This function:\n * 1. Reads JSON from stdin (snake_case format)\n * 2. Converts to camelCase and validates with Zod\n * 3. Calls your handler with typed input\n * 4. Validates the result and outputs JSON to stdout\n * 5. Handles errors gracefully with proper exit codes\n *\n * @param handler - Function that evaluates the input and returns a result\n *\n * @example\n * ```typescript\n * import { defineCodeJudge } from '@agentv/eval';\n *\n * export default defineCodeJudge(({ trace }) => {\n * if (!trace) {\n * return { score: 0.5, reasoning: 'No trace available' };\n * }\n *\n * const efficient = trace.eventCount <= 10;\n * return {\n * score: efficient ? 1.0 : 0.5,\n * hits: efficient ? ['Efficient execution'] : [],\n * misses: efficient ? [] : ['Too many tool calls'],\n * };\n * });\n * ```\n *\n * @example With typed config\n * ```typescript\n * import { defineCodeJudge, z } from '@agentv/eval';\n *\n * const ConfigSchema = z.object({\n * maxToolCalls: z.number().default(10),\n * });\n *\n * export default defineCodeJudge(({ trace, config }) => {\n * const { maxToolCalls } = ConfigSchema.parse(config ?? {});\n * // Use maxToolCalls...\n * });\n * ```\n */\nexport function defineCodeJudge(handler: CodeJudgeHandler): void {\n // Run immediately when module is loaded\n runCodeJudge(handler);\n}\n\n/**\n * Define a prompt template with automatic stdin/stdout handling.\n *\n * This function:\n * 1. Reads JSON from stdin (snake_case format)\n * 2. Converts to camelCase and validates with Zod\n * 3. Calls your handler with typed input\n * 4. Outputs the generated prompt string to stdout\n * 5. Handles errors gracefully with proper exit codes\n *\n * @param handler - Function that generates the prompt string from input\n *\n * @example\n * ```typescript\n * import { definePromptTemplate } from '@agentv/eval';\n *\n * export default definePromptTemplate((ctx) => `\n * Question: ${ctx.question}\n * Answer: ${ctx.answer}\n *\n * ${ctx.referenceAnswer ? `Reference: ${ctx.referenceAnswer}` : ''}\n * `);\n * ```\n *\n * @example With conditional logic\n * ```typescript\n * import { definePromptTemplate } from '@agentv/eval';\n *\n * export default definePromptTemplate((ctx) => {\n * const rubric = ctx.config?.rubric as string | undefined;\n * return `\n * Question: ${ctx.question}\n * Candidate Answer: ${ctx.answer}\n * ${rubric ? `\\nEvaluation Criteria:\\n${rubric}` : ''}\n * `;\n * });\n * ```\n */\nexport function definePromptTemplate(handler: PromptTemplateHandler): void {\n // Run immediately when module is loaded\n runPromptTemplate(handler);\n}\n\n/**\n * Define a custom assertion evaluator with automatic stdin/stdout handling.\n *\n * Assertions are the simplest way to add custom evaluation logic. They receive\n * the full evaluation context and return a pass/fail result with optional\n * granular scoring.\n *\n * This function:\n * 1. Reads JSON from stdin (snake_case format)\n * 2. Converts to camelCase and validates with Zod\n * 3. Calls your handler with typed context\n * 4. Normalizes the result (pass→score, clamp, etc.)\n * 5. Outputs JSON to stdout\n * 6. Handles errors gracefully with proper exit codes\n *\n * @param handler - Function that evaluates the context and returns a result\n *\n * @example Simple pass/fail\n * ```typescript\n * import { defineAssertion } from '@agentv/eval';\n *\n * export default defineAssertion(({ answer }) => ({\n * pass: answer.toLowerCase().includes('hello'),\n * reasoning: 'Checks for greeting',\n * }));\n * ```\n *\n * @example Granular scoring\n * ```typescript\n * import { defineAssertion } from '@agentv/eval';\n *\n * export default defineAssertion(({ answer, trace }) => {\n * const hasContent = answer.length > 0 ? 0.5 : 0;\n * const isEfficient = (trace?.eventCount ?? 0) <= 5 ? 0.5 : 0;\n * return {\n * score: hasContent + isEfficient,\n * hits: [\n * ...(hasContent ? ['Has content'] : []),\n * ...(isEfficient ? ['Efficient'] : []),\n * ],\n * };\n * });\n * ```\n */\nexport function defineAssertion(handler: AssertionHandler): void {\n runAssertion(handler);\n}\n","/**\n * Zod schemas for code judge input/output validation.\n * Provides both compile-time types and runtime validation.\n */\nimport { z } from 'zod';\n\n/**\n * Token usage metrics schema.\n */\nexport const TokenUsageSchema = z.object({\n input: z.number(),\n output: z.number(),\n cached: z.number().optional(),\n});\n\n/**\n * Trace summary schema (camelCase for TypeScript ergonomics).\n */\nexport const TraceSummarySchema = z.object({\n eventCount: z.number(),\n toolNames: z.array(z.string()),\n toolCallsByName: z.record(z.string(), z.number()),\n errorCount: z.number(),\n tokenUsage: TokenUsageSchema.optional(),\n costUsd: z.number().optional(),\n durationMs: z.number().optional(),\n toolDurations: z.record(z.string(), z.array(z.number())).optional(),\n startTime: z.string().optional(),\n endTime: z.string().optional(),\n llmCallCount: z.number().optional(),\n});\n\n/**\n * Tool call schema.\n */\nexport const ToolCallSchema = z.object({\n tool: z.string(),\n input: z.unknown().optional(),\n output: z.unknown().optional(),\n id: z.string().optional(),\n startTime: z.string().optional(),\n endTime: z.string().optional(),\n durationMs: z.number().optional(),\n});\n\n/**\n * Unified message schema for input, expected, and output messages.\n */\nexport const MessageSchema = z.object({\n role: z.enum(['assistant', 'user', 'system', 'tool']),\n content: z.union([z.string(), z.record(z.unknown()), z.array(z.record(z.unknown()))]).optional(),\n toolCalls: z.array(ToolCallSchema).optional(),\n name: z.string().optional(),\n startTime: z.string().optional(),\n endTime: z.string().optional(),\n durationMs: z.number().optional(),\n metadata: z.record(z.unknown()).optional(),\n});\n\n/**\n * Code judge input schema (camelCase, converted from snake_case wire format).\n */\nexport const CodeJudgeInputSchema = z.object({\n question: z.string(),\n criteria: z.string(),\n expectedOutput: z.array(MessageSchema),\n referenceAnswer: z.string().optional(),\n answer: z.string(),\n output: z.array(MessageSchema).nullable().optional(),\n /** Path to a temp file containing the output JSON (used for large payloads). */\n outputPath: z.string().optional(),\n guidelineFiles: z.array(z.string()),\n inputFiles: z.array(z.string()),\n input: z.array(MessageSchema),\n trace: TraceSummarySchema.nullable().optional(),\n fileChanges: z.string().nullable().optional(),\n workspacePath: z.string().nullable().optional(),\n config: z.record(z.unknown()).nullable().optional(),\n});\n\n/**\n * Code judge result schema (validated before output).\n */\nexport const CodeJudgeResultSchema = z.object({\n score: z.number().min(0).max(1),\n hits: z.array(z.string()).optional().default([]),\n misses: z.array(z.string()).optional().default([]),\n reasoning: z.string().optional(),\n /** Optional structured details for domain-specific metrics (e.g., TP/TN/FP/FN counts, alignments). */\n details: z.record(z.unknown()).optional(),\n});\n\n/**\n * Inferred types from schemas.\n */\nexport type CodeJudgeInput = z.infer<typeof CodeJudgeInputSchema>;\nexport type CodeJudgeResult = z.infer<typeof CodeJudgeResultSchema>;\nexport type TraceSummary = z.infer<typeof TraceSummarySchema>;\nexport type Message = z.infer<typeof MessageSchema>;\nexport type ToolCall = z.infer<typeof ToolCallSchema>;\nexport type TokenUsage = z.infer<typeof TokenUsageSchema>;\n\n/**\n * Prompt template input schema (camelCase, converted from snake_case wire format).\n * Uses the same schema as CodeJudgeInput since the orchestrator sends identical payloads.\n */\nexport const PromptTemplateInputSchema = CodeJudgeInputSchema;\n\nexport type PromptTemplateInput = CodeJudgeInput;\n","/**\n * Client for invoking configured targets from code_judge scripts.\n *\n * Environment variables (set automatically by AgentV when `target` config is present):\n * - AGENTV_TARGET_PROXY_URL: The URL of the local proxy server\n * - AGENTV_TARGET_PROXY_TOKEN: Bearer token for authentication\n */\n\n/**\n * Request to invoke the target\n */\nexport interface TargetInvokeRequest {\n readonly question: string;\n readonly systemPrompt?: string;\n readonly evalCaseId?: string;\n readonly attempt?: number;\n /** Optional target override - use a different target for this invocation */\n readonly target?: string;\n}\n\n/**\n * Response from a target invocation\n */\nexport interface TargetInvokeResponse {\n readonly output: readonly unknown[];\n readonly rawText?: string;\n}\n\n/**\n * Information about the target proxy configuration\n */\nexport interface TargetInfo {\n /** Name of the default target being used */\n readonly targetName: string;\n /** Maximum number of calls allowed */\n readonly maxCalls: number;\n /** Current number of calls made */\n readonly callCount: number;\n /** List of all available target names */\n readonly availableTargets: readonly string[];\n}\n\n/**\n * Target client for making target invocations\n */\nexport interface TargetClient {\n /**\n * Invoke the configured target with a prompt.\n * @param request - The question and optional system prompt\n * @returns The target's response with output messages and optional raw text\n */\n invoke(request: TargetInvokeRequest): Promise<TargetInvokeResponse>;\n\n /**\n * Invoke the target with multiple requests in sequence.\n * Each request counts toward the max_calls limit.\n * @param requests - Array of target requests\n * @returns Array of target responses\n */\n invokeBatch(requests: readonly TargetInvokeRequest[]): Promise<readonly TargetInvokeResponse[]>;\n\n /**\n * Get information about the target proxy configuration.\n * Returns the default target name, max calls, current call count, and available targets.\n */\n getInfo(): Promise<TargetInfo>;\n}\n\n/**\n * Error thrown when target proxy is not available\n */\nexport class TargetNotAvailableError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'TargetNotAvailableError';\n }\n}\n\n/**\n * Error thrown when target invocation fails\n */\nexport class TargetInvocationError extends Error {\n readonly statusCode?: number;\n\n constructor(message: string, statusCode?: number) {\n super(message);\n this.name = 'TargetInvocationError';\n this.statusCode = statusCode;\n }\n}\n\n/**\n * Create a target client from environment variables.\n *\n * This function reads the proxy URL and token from environment variables\n * that are automatically set by AgentV when a `target` config block is present\n * on a `code_judge` evaluator.\n *\n * @returns A target client if environment variables are set, otherwise undefined\n * @throws TargetNotAvailableError if token is missing when URL is present\n *\n * @example\n * ```typescript\n * import { createTargetClient, defineCodeJudge } from '@agentv/eval';\n *\n * export default defineCodeJudge(async ({ question, criteria }) => {\n * const target = createTargetClient();\n *\n * if (!target) {\n * // Target not available - no target config on this evaluator\n * return { score: 0.5, reasoning: 'Target not available' };\n * }\n *\n * const response = await target.invoke({\n * question: `Is this answer correct? Question: ${question}, Expected: ${criteria}`,\n * systemPrompt: 'You are an expert evaluator. Respond with JSON: { \"correct\": true/false }'\n * });\n *\n * const result = JSON.parse(response.rawText ?? '{}');\n * return { score: result.correct ? 1.0 : 0.0 };\n * });\n * ```\n */\nexport function createTargetClient(): TargetClient | undefined {\n const proxyUrl = process.env.AGENTV_TARGET_PROXY_URL;\n const proxyToken = process.env.AGENTV_TARGET_PROXY_TOKEN;\n\n if (!proxyUrl) {\n return undefined;\n }\n\n if (!proxyToken) {\n throw new TargetNotAvailableError(\n 'AGENTV_TARGET_PROXY_URL is set but AGENTV_TARGET_PROXY_TOKEN is missing',\n );\n }\n\n return createTargetClientInternal(proxyUrl, proxyToken);\n}\n\n/**\n * Internal: Create a target client with explicit URL and token.\n * Exported for testing only - use createTargetClient() in production.\n */\nexport function createTargetClientInternal(url: string, token: string): TargetClient {\n const headers = {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${token}`,\n };\n\n return {\n async invoke(request: TargetInvokeRequest): Promise<TargetInvokeResponse> {\n const response = await fetch(`${url}/invoke`, {\n method: 'POST',\n headers,\n body: JSON.stringify({\n question: request.question,\n systemPrompt: request.systemPrompt,\n evalCaseId: request.evalCaseId,\n attempt: request.attempt,\n target: request.target,\n }),\n });\n\n if (!response.ok) {\n const errorBody = await response.text();\n let errorMessage: string;\n try {\n const errorJson = JSON.parse(errorBody) as { error?: string };\n errorMessage = errorJson.error ?? `HTTP ${response.status}`;\n } catch {\n errorMessage = errorBody || `HTTP ${response.status}`;\n }\n throw new TargetInvocationError(errorMessage, response.status);\n }\n\n return (await response.json()) as TargetInvokeResponse;\n },\n\n async invokeBatch(\n requests: readonly TargetInvokeRequest[],\n ): Promise<readonly TargetInvokeResponse[]> {\n const response = await fetch(`${url}/invokeBatch`, {\n method: 'POST',\n headers,\n body: JSON.stringify({\n requests: requests.map((r) => ({\n question: r.question,\n systemPrompt: r.systemPrompt,\n evalCaseId: r.evalCaseId,\n attempt: r.attempt,\n target: r.target,\n })),\n }),\n });\n\n if (!response.ok) {\n const errorBody = await response.text();\n let errorMessage: string;\n try {\n const errorJson = JSON.parse(errorBody) as { error?: string };\n errorMessage = errorJson.error ?? `HTTP ${response.status}`;\n } catch {\n errorMessage = errorBody || `HTTP ${response.status}`;\n }\n throw new TargetInvocationError(errorMessage, response.status);\n }\n\n const result = (await response.json()) as { responses: TargetInvokeResponse[] };\n return result.responses;\n },\n\n async getInfo(): Promise<TargetInfo> {\n const response = await fetch(`${url}/info`, {\n method: 'GET',\n headers,\n });\n\n if (!response.ok) {\n const errorBody = await response.text();\n let errorMessage: string;\n try {\n const errorJson = JSON.parse(errorBody) as { error?: string };\n errorMessage = errorJson.error ?? `HTTP ${response.status}`;\n } catch {\n errorMessage = errorBody || `HTTP ${response.status}`;\n }\n throw new TargetInvocationError(errorMessage, response.status);\n }\n\n return (await response.json()) as TargetInfo;\n },\n };\n}\n","/**\n * Runtime for custom assertion evaluators.\n * Handles stdin parsing, validation, error handling, and output formatting.\n *\n * Assertions receive the same input as code judges but use a simplified result\n * contract focused on pass/fail with optional score granularity.\n */\nimport { readFileSync } from 'node:fs';\n\nimport { toCamelCaseDeep } from './case-conversion.js';\nimport {\n type CodeJudgeInput,\n CodeJudgeInputSchema,\n type CodeJudgeResult,\n CodeJudgeResultSchema,\n} from './schemas.js';\n\n/**\n * Context provided to assertion handlers.\n * Same shape as CodeJudgeInput — assertions receive full evaluation context.\n */\nexport type AssertionContext = CodeJudgeInput;\n\n/**\n * Known built-in assertion types. Custom types are extensible via string.\n *\n * Use in EVAL.yaml `assert` blocks:\n * ```yaml\n * assert:\n * - type: contains\n * value: \"Paris\"\n * ```\n *\n * Custom types registered via `.agentv/assertions/` or `defineAssertion()`\n * are also valid — the `string & {}` escape hatch provides autocomplete\n * for known types while accepting any string.\n */\nexport type AssertionType =\n | 'llm_judge'\n | 'code_judge'\n | 'rubrics'\n | 'composite'\n | 'tool_trajectory'\n | 'field_accuracy'\n | 'latency'\n | 'cost'\n | 'token_usage'\n | 'execution_metrics'\n | 'agent_judge'\n | 'contains'\n | 'equals'\n | 'regex'\n | 'is_json'\n | (string & {});\n\n/**\n * Result returned from an assertion handler.\n *\n * @example Pass with reasoning\n * ```ts\n * { pass: true, reasoning: 'Output contains expected keywords' }\n * ```\n *\n * @example Fail with misses\n * ```ts\n * { pass: false, misses: ['Missing required header'], score: 0.3 }\n * ```\n *\n * @example Granular score (0-1)\n * ```ts\n * { score: 0.75, hits: ['Format correct', 'Content relevant'], misses: ['Missing citation'] }\n * ```\n */\nexport interface AssertionScore {\n /** Explicit pass/fail. If omitted, derived from score (>= 0.5 = pass). */\n readonly pass?: boolean;\n /** Numeric score between 0 and 1. Defaults to 1 if pass=true, 0 if pass=false. */\n readonly score?: number;\n /** Aspects that passed. */\n readonly hits?: readonly string[];\n /** Aspects that failed. */\n readonly misses?: readonly string[];\n /** Human-readable explanation. */\n readonly reasoning?: string;\n /** Optional structured details for domain-specific metrics. */\n readonly details?: Record<string, unknown>;\n}\n\n/**\n * Handler function type for assertions.\n */\nexport type AssertionHandler = (ctx: AssertionContext) => AssertionScore | Promise<AssertionScore>;\n\n/**\n * Read stdin synchronously.\n */\nfunction readStdin(): string {\n return readFileSync(0, 'utf8');\n}\n\n/**\n * Clamp a value to the range [0, 1].\n */\nfunction clampScore(value: number): number {\n if (Number.isNaN(value) || !Number.isFinite(value)) {\n return 0;\n }\n return Math.max(0, Math.min(1, value));\n}\n\nfunction formatError(error: unknown): string {\n if (error instanceof Error) {\n return error.message;\n }\n return String(error);\n}\n\n/**\n * Normalize an AssertionScore to a CodeJudgeResult for wire compatibility.\n */\nfunction normalizeScore(result: AssertionScore): CodeJudgeResult {\n let score: number;\n if (result.score !== undefined) {\n score = clampScore(result.score);\n } else if (result.pass !== undefined) {\n score = result.pass ? 1 : 0;\n } else {\n score = 0;\n }\n\n return {\n score,\n hits: result.hits ? [...result.hits] : [],\n misses: result.misses ? [...result.misses] : [],\n reasoning: result.reasoning,\n details: result.details,\n };\n}\n\n/**\n * Run an assertion handler with full stdin/stdout handling.\n * This is the internal implementation called by defineAssertion.\n */\nexport async function runAssertion(handler: AssertionHandler): Promise<void> {\n try {\n const stdin = readStdin();\n const rawInput = JSON.parse(stdin) as Record<string, unknown>;\n const camelInput = toCamelCaseDeep(rawInput);\n const input = CodeJudgeInputSchema.parse(camelInput);\n\n // Lazy file-backed output loading\n if (input.outputPath && (input.output === null || input.output === undefined)) {\n let cachedOutput: CodeJudgeInput['output'] | undefined;\n const filePath = input.outputPath;\n Object.defineProperty(input, 'output', {\n get() {\n if (cachedOutput === undefined) {\n cachedOutput = JSON.parse(readFileSync(filePath, 'utf8'));\n }\n return cachedOutput;\n },\n configurable: true,\n enumerable: true,\n });\n }\n\n const rawResult = await handler(input);\n const normalized = normalizeScore(rawResult);\n const result = CodeJudgeResultSchema.parse(normalized);\n console.log(JSON.stringify(result, null, 2));\n } catch (error) {\n const errorMessage = formatError(error);\n const errorResult: CodeJudgeResult = {\n score: 0,\n hits: [],\n misses: [errorMessage],\n reasoning: `Assertion failed: ${errorMessage}`,\n };\n console.log(JSON.stringify(errorResult, null, 2));\n process.exit(1);\n }\n}\n","/**\n * Case conversion utilities for JSON payloads.\n * Converts between snake_case (wire format) and camelCase (TypeScript).\n */\n\nfunction toCamelCase(str: string): string {\n // Don't convert keys that start with uppercase (proper nouns/tool names)\n if (/^[A-Z]/.test(str)) {\n return str;\n }\n return str.replace(/_([a-z0-9])/g, (_, letter) => letter.toUpperCase());\n}\n\n/**\n * Recursively converts all keys in an object from snake_case to camelCase.\n * Used to map wire payloads into TypeScript-friendly shapes.\n *\n * @param obj - The object to convert (can be any JSON-serializable value)\n * @returns A new object with all keys converted to camelCase\n */\nexport function toCamelCaseDeep(obj: unknown): unknown {\n if (obj === null || obj === undefined) {\n return obj;\n }\n\n if (Array.isArray(obj)) {\n return obj.map((item) => toCamelCaseDeep(item));\n }\n\n if (typeof obj === 'object') {\n const result: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(obj)) {\n const camelKey = toCamelCase(key);\n result[camelKey] = toCamelCaseDeep(value);\n }\n return result;\n }\n\n return obj;\n}\n","/**\n * Runtime for prompt template evaluators.\n * Handles stdin parsing, validation, error handling, and string output.\n */\nimport { readFileSync } from 'node:fs';\n\nimport { toCamelCaseDeep } from './case-conversion.js';\nimport { type PromptTemplateInput, PromptTemplateInputSchema } from './schemas.js';\n\n/**\n * Handler function type for prompt templates.\n * Returns the prompt string to use for evaluation.\n */\nexport type PromptTemplateHandler = (input: PromptTemplateInput) => string | Promise<string>;\n\n/**\n * Read stdin synchronously (works in both Node.js and Bun).\n */\nfunction readStdin(): string {\n return readFileSync(0, 'utf8');\n}\n\n/**\n * Run a prompt template handler with full stdin/stdout handling.\n * This is the internal implementation called by definePromptTemplate.\n */\nexport async function runPromptTemplate(handler: PromptTemplateHandler): Promise<void> {\n try {\n // 1. Read stdin\n const stdin = readStdin();\n\n // 2. Parse JSON\n const rawInput = JSON.parse(stdin) as Record<string, unknown>;\n\n // 3. Convert snake_case to camelCase\n const camelInput = toCamelCaseDeep(rawInput);\n\n // 4. Validate input with Zod\n const input = PromptTemplateInputSchema.parse(camelInput);\n\n // 5. Run handler\n const prompt = await handler(input);\n\n // 6. Output raw string (not JSON) - the prompt itself\n console.log(prompt);\n } catch (error) {\n // Output error to stderr and exit with non-zero code\n console.error(error instanceof Error ? error.message : String(error));\n process.exit(1);\n }\n}\n\n/**\n * Define a prompt template with automatic stdin/stdout handling.\n *\n * This function:\n * 1. Reads JSON from stdin (snake_case format)\n * 2. Converts to camelCase and validates with Zod\n * 3. Calls your handler with typed input\n * 4. Outputs the generated prompt string to stdout\n * 5. Handles errors gracefully with proper exit codes\n *\n * @param handler - Function that generates the prompt string from input\n *\n * @example\n * ```typescript\n * import { definePromptTemplate } from '@agentv/eval';\n *\n * export default definePromptTemplate((ctx) => `\n * Question: ${ctx.question}\n * Answer: ${ctx.answer}\n *\n * ${ctx.referenceAnswer ? `Reference: ${ctx.referenceAnswer}` : ''}\n * `);\n * ```\n *\n * @example With conditional logic\n * ```typescript\n * import { definePromptTemplate } from '@agentv/eval';\n *\n * export default definePromptTemplate((ctx) => {\n * const rubric = ctx.config?.rubric as string | undefined;\n * return `\n * Question: ${ctx.question}\n * Candidate Answer: ${ctx.answer}\n * ${rubric ? `\\nEvaluation Criteria:\\n${rubric}` : ''}\n * `;\n * });\n * ```\n *\n * @example Async handler\n * ```typescript\n * import { definePromptTemplate } from '@agentv/eval';\n *\n * export default definePromptTemplate(async (ctx) => {\n * // Async operations are supported\n * return `Question: ${ctx.question}\\nAnswer: ${ctx.answer}`;\n * });\n * ```\n */\nexport function definePromptTemplate(handler: PromptTemplateHandler): void {\n // Run immediately when module is loaded\n runPromptTemplate(handler);\n}\n","/**\n * Runtime for code judge evaluators.\n * Handles stdin parsing, validation, error handling, and output formatting.\n */\nimport { readFileSync } from 'node:fs';\n\nimport { toCamelCaseDeep } from './case-conversion.js';\nimport {\n type CodeJudgeInput,\n CodeJudgeInputSchema,\n type CodeJudgeResult,\n CodeJudgeResultSchema,\n} from './schemas.js';\n\n/**\n * Handler function type for code judges.\n */\nexport type CodeJudgeHandler = (\n input: CodeJudgeInput,\n) => CodeJudgeResult | Promise<CodeJudgeResult>;\n\n/**\n * Read stdin synchronously (works in both Node.js and Bun).\n */\nfunction readStdin(): string {\n return readFileSync(0, 'utf8');\n}\n\n/**\n * Clamp a value to the range [0, 1].\n */\nfunction clampScore(value: number): number {\n if (Number.isNaN(value) || !Number.isFinite(value)) {\n return 0;\n }\n return Math.max(0, Math.min(1, value));\n}\n\n/**\n * Format an error for output.\n */\nfunction formatError(error: unknown): string {\n if (error instanceof Error) {\n return error.message;\n }\n return String(error);\n}\n\n/**\n * Run a code judge handler with full stdin/stdout handling.\n * This is the internal implementation called by defineCodeJudge.\n */\nexport async function runCodeJudge(handler: CodeJudgeHandler): Promise<void> {\n try {\n // 1. Read stdin\n const stdin = readStdin();\n\n // 2. Parse JSON\n const rawInput = JSON.parse(stdin) as Record<string, unknown>;\n\n // 3. Convert snake_case to camelCase\n const camelInput = toCamelCaseDeep(rawInput);\n\n // 4. Validate input with Zod\n const input = CodeJudgeInputSchema.parse(camelInput);\n\n // 5. Set up lazy file-backed output loading if applicable\n if (input.outputPath && (input.output === null || input.output === undefined)) {\n let cachedOutput: CodeJudgeInput['output'] | undefined;\n const filePath = input.outputPath;\n Object.defineProperty(input, 'output', {\n get() {\n if (cachedOutput === undefined) {\n cachedOutput = JSON.parse(readFileSync(filePath, 'utf8'));\n }\n return cachedOutput;\n },\n configurable: true,\n enumerable: true,\n });\n }\n\n // 6. Run handler\n const rawResult = await handler(input);\n\n // 7. Validate and normalize output\n const result = CodeJudgeResultSchema.parse({\n ...rawResult,\n score: clampScore(rawResult.score),\n });\n\n // 8. Output JSON\n console.log(JSON.stringify(result, null, 2));\n } catch (error) {\n // Output failure result\n const errorMessage = formatError(error);\n const errorResult: CodeJudgeResult = {\n score: 0,\n hits: [],\n misses: [errorMessage],\n reasoning: `Evaluation failed: ${errorMessage}`,\n };\n console.log(JSON.stringify(errorResult, null, 2));\n process.exit(1);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACIA,iBAAkB;AAKX,IAAM,mBAAmB,aAAE,OAAO;AAAA,EACvC,OAAO,aAAE,OAAO;AAAA,EAChB,QAAQ,aAAE,OAAO;AAAA,EACjB,QAAQ,aAAE,OAAO,EAAE,SAAS;AAC9B,CAAC;AAKM,IAAM,qBAAqB,aAAE,OAAO;AAAA,EACzC,YAAY,aAAE,OAAO;AAAA,EACrB,WAAW,aAAE,MAAM,aAAE,OAAO,CAAC;AAAA,EAC7B,iBAAiB,aAAE,OAAO,aAAE,OAAO,GAAG,aAAE,OAAO,CAAC;AAAA,EAChD,YAAY,aAAE,OAAO;AAAA,EACrB,YAAY,iBAAiB,SAAS;AAAA,EACtC,SAAS,aAAE,OAAO,EAAE,SAAS;AAAA,EAC7B,YAAY,aAAE,OAAO,EAAE,SAAS;AAAA,EAChC,eAAe,aAAE,OAAO,aAAE,OAAO,GAAG,aAAE,MAAM,aAAE,OAAO,CAAC,CAAC,EAAE,SAAS;AAAA,EAClE,WAAW,a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