@agentv/eval 3.2.5 → 3.3.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.
- package/dist/index.cjs +76 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +94 -19
- package/dist/index.d.ts +94 -19
- package/dist/index.js +76 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -75,10 +75,13 @@ var MessageSchema = import_zod.z.object({
|
|
|
75
75
|
metadata: import_zod.z.record(import_zod.z.unknown()).optional()
|
|
76
76
|
});
|
|
77
77
|
var CodeGraderInputSchema = import_zod.z.object({
|
|
78
|
+
/** @deprecated Use `inputText` instead. First user message content as string. */
|
|
78
79
|
question: import_zod.z.string(),
|
|
79
80
|
criteria: import_zod.z.string(),
|
|
80
81
|
expectedOutput: import_zod.z.array(MessageSchema),
|
|
82
|
+
/** @deprecated Use `expectedOutputText` instead. Expected output content as string. */
|
|
81
83
|
referenceAnswer: import_zod.z.string().optional(),
|
|
84
|
+
/** @deprecated Use `outputText` instead. Last assistant message content as string. */
|
|
82
85
|
answer: import_zod.z.string(),
|
|
83
86
|
output: import_zod.z.array(MessageSchema).nullable().optional(),
|
|
84
87
|
/** Path to a temp file containing the output JSON (used for large payloads). */
|
|
@@ -94,7 +97,13 @@ var CodeGraderInputSchema = import_zod.z.object({
|
|
|
94
97
|
endTime: import_zod.z.string().nullable().optional(),
|
|
95
98
|
fileChanges: import_zod.z.string().nullable().optional(),
|
|
96
99
|
workspacePath: import_zod.z.string().nullable().optional(),
|
|
97
|
-
config: import_zod.z.record(import_zod.z.unknown()).nullable().optional()
|
|
100
|
+
config: import_zod.z.record(import_zod.z.unknown()).nullable().optional(),
|
|
101
|
+
/** First user message content as string. Replaces `question`. */
|
|
102
|
+
inputText: import_zod.z.string().optional(),
|
|
103
|
+
/** Last assistant message content as string. Replaces `answer`. */
|
|
104
|
+
outputText: import_zod.z.string().optional(),
|
|
105
|
+
/** Expected output content as string. Replaces `referenceAnswer`. */
|
|
106
|
+
expectedOutputText: import_zod.z.string().optional()
|
|
98
107
|
});
|
|
99
108
|
var CodeGraderResultSchema = import_zod.z.object({
|
|
100
109
|
score: import_zod.z.number().min(0).max(1),
|
|
@@ -247,6 +256,69 @@ function toCamelCaseDeep(obj) {
|
|
|
247
256
|
return obj;
|
|
248
257
|
}
|
|
249
258
|
|
|
259
|
+
// src/deprecation.ts
|
|
260
|
+
var ANSI_YELLOW = "\x1B[33m";
|
|
261
|
+
var ANSI_RESET = "\x1B[0m";
|
|
262
|
+
var deprecationWarned = /* @__PURE__ */ new Set();
|
|
263
|
+
function warnDeprecation(oldName, newName) {
|
|
264
|
+
if (deprecationWarned.has(oldName)) return;
|
|
265
|
+
deprecationWarned.add(oldName);
|
|
266
|
+
console.warn(
|
|
267
|
+
`${ANSI_YELLOW}Warning: '${oldName}' is deprecated in code graders. Use '${newName}' instead.${ANSI_RESET}`
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
function enrichInput(input) {
|
|
271
|
+
const inputText = input.question;
|
|
272
|
+
const outputText = input.answer;
|
|
273
|
+
const expectedOutputText = input.referenceAnswer ?? "";
|
|
274
|
+
const originalQuestion = input.question;
|
|
275
|
+
const originalAnswer = input.answer;
|
|
276
|
+
const originalReferenceAnswer = input.referenceAnswer;
|
|
277
|
+
Object.defineProperty(input, "inputText", {
|
|
278
|
+
value: inputText,
|
|
279
|
+
writable: false,
|
|
280
|
+
configurable: true,
|
|
281
|
+
enumerable: true
|
|
282
|
+
});
|
|
283
|
+
Object.defineProperty(input, "outputText", {
|
|
284
|
+
value: outputText,
|
|
285
|
+
writable: false,
|
|
286
|
+
configurable: true,
|
|
287
|
+
enumerable: true
|
|
288
|
+
});
|
|
289
|
+
Object.defineProperty(input, "expectedOutputText", {
|
|
290
|
+
value: expectedOutputText,
|
|
291
|
+
writable: false,
|
|
292
|
+
configurable: true,
|
|
293
|
+
enumerable: true
|
|
294
|
+
});
|
|
295
|
+
Object.defineProperty(input, "question", {
|
|
296
|
+
get() {
|
|
297
|
+
warnDeprecation("question", "inputText");
|
|
298
|
+
return originalQuestion;
|
|
299
|
+
},
|
|
300
|
+
configurable: true,
|
|
301
|
+
enumerable: true
|
|
302
|
+
});
|
|
303
|
+
Object.defineProperty(input, "answer", {
|
|
304
|
+
get() {
|
|
305
|
+
warnDeprecation("answer", "outputText");
|
|
306
|
+
return originalAnswer;
|
|
307
|
+
},
|
|
308
|
+
configurable: true,
|
|
309
|
+
enumerable: true
|
|
310
|
+
});
|
|
311
|
+
Object.defineProperty(input, "referenceAnswer", {
|
|
312
|
+
get() {
|
|
313
|
+
warnDeprecation("referenceAnswer", "expectedOutputText");
|
|
314
|
+
return originalReferenceAnswer;
|
|
315
|
+
},
|
|
316
|
+
configurable: true,
|
|
317
|
+
enumerable: true
|
|
318
|
+
});
|
|
319
|
+
return input;
|
|
320
|
+
}
|
|
321
|
+
|
|
250
322
|
// src/assertion.ts
|
|
251
323
|
function readStdin() {
|
|
252
324
|
return (0, import_node_fs.readFileSync)(0, "utf8");
|
|
@@ -300,6 +372,7 @@ async function runAssertion(handler) {
|
|
|
300
372
|
enumerable: true
|
|
301
373
|
});
|
|
302
374
|
}
|
|
375
|
+
enrichInput(input);
|
|
303
376
|
const rawResult = await handler(input);
|
|
304
377
|
const normalized = normalizeScore(rawResult);
|
|
305
378
|
const result = CodeGraderResultSchema.parse(normalized);
|
|
@@ -328,6 +401,7 @@ async function runPromptTemplate(handler) {
|
|
|
328
401
|
const rawInput = JSON.parse(stdin);
|
|
329
402
|
const camelInput = toCamelCaseDeep(rawInput);
|
|
330
403
|
const input = PromptTemplateInputSchema.parse(camelInput);
|
|
404
|
+
enrichInput(input);
|
|
331
405
|
const prompt = await handler(input);
|
|
332
406
|
console.log(prompt);
|
|
333
407
|
} catch (error) {
|
|
@@ -373,6 +447,7 @@ async function runCodeGrader(handler) {
|
|
|
373
447
|
enumerable: true
|
|
374
448
|
});
|
|
375
449
|
}
|
|
450
|
+
enrichInput(input);
|
|
376
451
|
const rawResult = await handler(input);
|
|
377
452
|
const result = CodeGraderResultSchema.parse({
|
|
378
453
|
...rawResult,
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/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 grader (full control)\n * ```typescript\n * #!/usr/bin/env bun\n * import { defineCodeGrader } from '@agentv/eval';\n *\n * export default defineCodeGrader(({ trace, answer }) => ({\n * score: trace?.eventCount <= 5 ? 1.0 : 0.5,\n * hits: ['Efficient tool usage'],\n * misses: [],\n * }));\n * ```\n *\n * @example Code grader with target access (requires `target` config in YAML)\n * ```typescript\n * #!/usr/bin/env bun\n * import { defineCodeGrader, createTargetClient } from '@agentv/eval';\n *\n * export default defineCodeGrader(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 CodeGraderInputSchema,\n CodeGraderResultSchema,\n TraceSummarySchema,\n MessageSchema,\n ToolCallSchema,\n TokenUsageSchema,\n PromptTemplateInputSchema,\n type CodeGraderInput,\n type CodeGraderResult,\n type TraceSummary,\n type Message,\n type ToolCall,\n type TokenUsage,\n type PromptTemplateInput,\n // Backward-compat aliases (deprecated)\n CodeJudgeInputSchema,\n CodeJudgeResultSchema,\n type CodeJudgeInput,\n type CodeJudgeResult,\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 CodeGraderHandler, type CodeJudgeHandler, runCodeGrader } from './runtime.js';\n\nexport type { CodeGraderHandler };\n/** @deprecated Use CodeGraderHandler */\nexport type { CodeJudgeHandler };\nexport type { PromptTemplateHandler };\n\n/**\n * Define a code grader 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 { defineCodeGrader } from '@agentv/eval';\n *\n * export default defineCodeGrader(({ 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 { defineCodeGrader, z } from '@agentv/eval';\n *\n * const ConfigSchema = z.object({\n * maxToolCalls: z.number().default(10),\n * });\n *\n * export default defineCodeGrader(({ trace, config }) => {\n * const { maxToolCalls } = ConfigSchema.parse(config ?? {});\n * // Use maxToolCalls...\n * });\n * ```\n */\nexport function defineCodeGrader(handler: CodeGraderHandler): void {\n // Run immediately when module is loaded\n runCodeGrader(handler);\n}\n\n/** @deprecated Use defineCodeGrader */\nexport const defineCodeJudge = defineCodeGrader;\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 grader 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 toolDurations: z.record(z.string(), z.array(z.number())).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 grader input schema (camelCase, converted from snake_case wire format).\n */\nexport const CodeGraderInputSchema = 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 tokenUsage: TokenUsageSchema.nullable().optional(),\n costUsd: z.number().nullable().optional(),\n durationMs: z.number().nullable().optional(),\n startTime: z.string().nullable().optional(),\n endTime: z.string().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 grader result schema (validated before output).\n */\nexport const CodeGraderResultSchema = 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 CodeGraderInput = z.infer<typeof CodeGraderInputSchema>;\nexport type CodeGraderResult = z.infer<typeof CodeGraderResultSchema>;\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 CodeGraderInput since the orchestrator sends identical payloads.\n */\nexport const PromptTemplateInputSchema = CodeGraderInputSchema;\n\nexport type PromptTemplateInput = CodeGraderInput;\n\n// ── Backward-compat aliases (deprecated) ────────────────────────────────────────\n/** @deprecated Use CodeGraderInputSchema */\nexport const CodeJudgeInputSchema = CodeGraderInputSchema;\n/** @deprecated Use CodeGraderResultSchema */\nexport const CodeJudgeResultSchema = CodeGraderResultSchema;\n/** @deprecated Use CodeGraderInput */\nexport type CodeJudgeInput = CodeGraderInput;\n/** @deprecated Use CodeGraderResult */\nexport type CodeJudgeResult = CodeGraderResult;\n","/**\n * Client for invoking configured targets from code-grader 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\nimport type { TokenUsage } from './schemas.js';\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 readonly tokenUsage?: TokenUsage;\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_grader` (or `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, defineCodeGrader } from '@agentv/eval';\n *\n * export default defineCodeGrader(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 graders 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 CodeGraderInput,\n CodeGraderInputSchema,\n type CodeGraderResult,\n CodeGraderResultSchema,\n} from './schemas.js';\n\n/**\n * Context provided to assertion handlers.\n * Same shape as CodeGraderInput — assertions receive full evaluation context.\n */\nexport type AssertionContext = CodeGraderInput;\n\n/**\n * Known built-in assertion types. Custom types are extensible via string.\n *\n * Use in EVAL.yaml `assertions` blocks:\n * ```yaml\n * assertions:\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 // kebab-case (canonical internal form)\n | 'llm-grader'\n | 'code-grader'\n | 'rubrics'\n | 'composite'\n | 'tool-trajectory'\n | 'field-accuracy'\n | 'latency'\n | 'cost'\n | 'token-usage'\n | 'execution-metrics'\n | 'skill-trigger'\n | 'contains'\n | 'contains-any'\n | 'contains-all'\n | 'icontains'\n | 'icontains-any'\n | 'icontains-all'\n | 'starts-with'\n | 'ends-with'\n | 'equals'\n | 'regex'\n | 'is-json'\n // legacy aliases (still accepted)\n | 'llm-judge'\n | 'code-judge'\n | 'llm_judge'\n | 'code_judge'\n | 'llm_grader'\n | 'code_grader'\n | 'tool_trajectory'\n | 'field_accuracy'\n | 'token_usage'\n | 'execution_metrics'\n | 'contains_any'\n | 'contains_all'\n | 'icontains_any'\n | 'icontains_all'\n | 'starts_with'\n | 'ends_with'\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 CodeGraderResult for wire compatibility.\n */\nfunction normalizeScore(result: AssertionScore): CodeGraderResult {\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 = CodeGraderInputSchema.parse(camelInput);\n\n // Lazy file-backed output loading\n if (input.outputPath && (input.output === null || input.output === undefined)) {\n let cachedOutput: CodeGraderInput['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 = CodeGraderResultSchema.parse(normalized);\n console.log(JSON.stringify(result, null, 2));\n } catch (error) {\n const errorMessage = formatError(error);\n const errorResult: CodeGraderResult = {\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 grader 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 CodeGraderInput,\n CodeGraderInputSchema,\n type CodeGraderResult,\n CodeGraderResultSchema,\n} from './schemas.js';\n\n/**\n * Handler function type for code graders.\n */\nexport type CodeGraderHandler = (\n input: CodeGraderInput,\n) => CodeGraderResult | Promise<CodeGraderResult>;\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 grader handler with full stdin/stdout handling.\n * This is the internal implementation called by defineCodeGrader.\n */\nexport async function runCodeGrader(handler: CodeGraderHandler): 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 = CodeGraderInputSchema.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: CodeGraderInput['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 = CodeGraderResultSchema.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: CodeGraderResult = {\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\n// ── Backward-compat aliases (deprecated) ────────────────────────────────────────\n/** @deprecated Use CodeGraderHandler */\nexport type CodeJudgeHandler = CodeGraderHandler;\n/** @deprecated Use runCodeGrader */\nexport const runCodeJudge = runCodeGrader;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;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,eAAe,aAAE,OAAO,aAAE,OAAO,GAAG,aAAE,MAAM,aAAE,OAAO,CAAC,CAAC,EAAE,SAAS;AAAA,EAClE,cAAc,aAAE,OAAO,EAAE,SAAS;AACpC,CAAC;AAKM,IAAM,iBAAiB,aAAE,OAAO;AAAA,EACrC,MAAM,aAAE,OAAO;AAAA,EACf,OAAO,aAAE,QAAQ,EAAE,SAAS;AA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;AAEd,UAAM,eAAeC,aAAY,KAAK;AACtC,UAAM,cAAgC;AAAA,MACpC,OAAO;AAAA,MACP,MAAM,CAAC;AAAA,MACP,QAAQ,CAAC,YAAY;AAAA,MACrB,WAAW,sBAAsB,YAAY;AAAA,IAC/C;AACA,YAAQ,IAAI,KAAK,UAAU,aAAa,MAAM,CAAC,CAAC;AAChD,YAAQ,KAAK,CAAC;AAAA,EAChB;AACF;;;AN6CO,SAAS,iBAAiB,SAAkC;AAEjE,gBAAc,OAAO;AACvB;AAGO,IAAM,kBAAkB;AAwCxB,SAAS,qBAAqB,SAAsC;AAEzE,oBAAkB,OAAO;AAC3B;AA8CO,SAAS,gBAAgB,SAAiC;AAC/D,eAAa,OAAO;AACtB;","names":["import_zod","import_node_fs","readStdin","import_node_fs","readStdin","clampScore","formatError"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/schemas.ts","../src/target-client.ts","../src/assertion.ts","../src/case-conversion.ts","../src/deprecation.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(({ outputText }) => ({\n * pass: outputText.includes('hello'),\n * reasoning: 'Checks greeting',\n * }));\n * ```\n *\n * @example Code grader (full control)\n * ```typescript\n * #!/usr/bin/env bun\n * import { defineCodeGrader } from '@agentv/eval';\n *\n * export default defineCodeGrader(({ trace, outputText }) => ({\n * score: trace?.eventCount <= 5 ? 1.0 : 0.5,\n * hits: ['Efficient tool usage'],\n * misses: [],\n * }));\n * ```\n *\n * @example Code grader with target access (requires `target` config in YAML)\n * ```typescript\n * #!/usr/bin/env bun\n * import { defineCodeGrader, createTargetClient } from '@agentv/eval';\n *\n * export default defineCodeGrader(async ({ inputText }) => {\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: ${inputText}`,\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 CodeGraderInputSchema,\n CodeGraderResultSchema,\n TraceSummarySchema,\n MessageSchema,\n ToolCallSchema,\n TokenUsageSchema,\n PromptTemplateInputSchema,\n type CodeGraderInput,\n type CodeGraderResult,\n type EnrichedCodeGraderInput,\n type TraceSummary,\n type Message,\n type ToolCall,\n type TokenUsage,\n type PromptTemplateInput,\n // Backward-compat aliases (deprecated)\n CodeJudgeInputSchema,\n CodeJudgeResultSchema,\n type CodeJudgeInput,\n type CodeJudgeResult,\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 CodeGraderHandler, type CodeJudgeHandler, runCodeGrader } from './runtime.js';\n\nexport type { CodeGraderHandler };\n/** @deprecated Use CodeGraderHandler */\nexport type { CodeJudgeHandler };\nexport type { PromptTemplateHandler };\n\n/**\n * Define a code grader 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 { defineCodeGrader } from '@agentv/eval';\n *\n * export default defineCodeGrader(({ 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 { defineCodeGrader, z } from '@agentv/eval';\n *\n * const ConfigSchema = z.object({\n * maxToolCalls: z.number().default(10),\n * });\n *\n * export default defineCodeGrader(({ trace, config }) => {\n * const { maxToolCalls } = ConfigSchema.parse(config ?? {});\n * // Use maxToolCalls...\n * });\n * ```\n */\nexport function defineCodeGrader(handler: CodeGraderHandler): void {\n // Run immediately when module is loaded\n runCodeGrader(handler);\n}\n\n/** @deprecated Use defineCodeGrader */\nexport const defineCodeJudge = defineCodeGrader;\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.inputText}\n * Answer: ${ctx.outputText}\n *\n * ${ctx.expectedOutputText ? `Reference: ${ctx.expectedOutputText}` : ''}\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.inputText}\n * Candidate Answer: ${ctx.outputText}\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(({ outputText }) => ({\n * pass: outputText.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(({ outputText, trace }) => {\n * const hasContent = outputText.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 grader 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 toolDurations: z.record(z.string(), z.array(z.number())).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 grader input schema (camelCase, converted from snake_case wire format).\n *\n * Text convenience accessors (`inputText`, `outputText`, `expectedOutputText`) are always\n * strings. Structured fields (`input`, `output`, `expectedOutput`) are always `Message[]`.\n */\nexport const CodeGraderInputSchema = z.object({\n /** @deprecated Use `inputText` instead. First user message content as string. */\n question: z.string(),\n criteria: z.string(),\n expectedOutput: z.array(MessageSchema),\n /** @deprecated Use `expectedOutputText` instead. Expected output content as string. */\n referenceAnswer: z.string().optional(),\n /** @deprecated Use `outputText` instead. Last assistant message content as string. */\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 tokenUsage: TokenUsageSchema.nullable().optional(),\n costUsd: z.number().nullable().optional(),\n durationMs: z.number().nullable().optional(),\n startTime: z.string().nullable().optional(),\n endTime: z.string().nullable().optional(),\n fileChanges: z.string().nullable().optional(),\n workspacePath: z.string().nullable().optional(),\n config: z.record(z.unknown()).nullable().optional(),\n /** First user message content as string. Replaces `question`. */\n inputText: z.string().optional(),\n /** Last assistant message content as string. Replaces `answer`. */\n outputText: z.string().optional(),\n /** Expected output content as string. Replaces `referenceAnswer`. */\n expectedOutputText: z.string().optional(),\n});\n\n/**\n * Code grader result schema (validated before output).\n */\nexport const CodeGraderResultSchema = 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 CodeGraderInput = z.infer<typeof CodeGraderInputSchema>;\nexport type CodeGraderResult = z.infer<typeof CodeGraderResultSchema>;\n\n/**\n * CodeGraderInput after `enrichInput()` has run.\n *\n * The text convenience accessors (`inputText`, `outputText`, `expectedOutputText`)\n * are always populated by the runtime before the handler is called, so they are\n * guaranteed to be `string` (never `undefined`).\n *\n * Handler function signatures (`CodeGraderHandler`, `AssertionHandler`) use this\n * type so that user code can destructure `{ outputText }` without null-checks.\n */\nexport type EnrichedCodeGraderInput = Omit<\n CodeGraderInput,\n 'inputText' | 'outputText' | 'expectedOutputText'\n> & {\n /** First user message content as string. Replaces `question`. */\n readonly inputText: string;\n /** Last assistant message content as string. Replaces `answer`. */\n readonly outputText: string;\n /** Expected output content as string. Replaces `referenceAnswer`. */\n readonly expectedOutputText: string;\n};\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 CodeGraderInput since the orchestrator sends identical payloads.\n */\nexport const PromptTemplateInputSchema = CodeGraderInputSchema;\n\nexport type PromptTemplateInput = CodeGraderInput;\n\n// ── Backward-compat aliases (deprecated) ────────────────────────────────────────\n/** @deprecated Use CodeGraderInputSchema */\nexport const CodeJudgeInputSchema = CodeGraderInputSchema;\n/** @deprecated Use CodeGraderResultSchema */\nexport const CodeJudgeResultSchema = CodeGraderResultSchema;\n/** @deprecated Use CodeGraderInput */\nexport type CodeJudgeInput = CodeGraderInput;\n/** @deprecated Use CodeGraderResult */\nexport type CodeJudgeResult = CodeGraderResult;\n","/**\n * Client for invoking configured targets from code-grader 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\nimport type { TokenUsage } from './schemas.js';\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 readonly tokenUsage?: TokenUsage;\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_grader` (or `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, defineCodeGrader } from '@agentv/eval';\n *\n * export default defineCodeGrader(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 graders 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 { enrichInput } from './deprecation.js';\nimport {\n type CodeGraderInput,\n CodeGraderInputSchema,\n type CodeGraderResult,\n CodeGraderResultSchema,\n type EnrichedCodeGraderInput,\n} from './schemas.js';\n\n/**\n * Context provided to assertion handlers.\n *\n * Same shape as CodeGraderInput but with `inputText`, `outputText`, and\n * `expectedOutputText` guaranteed to be strings (populated by the runtime\n * before the handler is called).\n */\nexport type AssertionContext = EnrichedCodeGraderInput;\n\n/**\n * Known built-in assertion types. Custom types are extensible via string.\n *\n * Use in EVAL.yaml `assertions` blocks:\n * ```yaml\n * assertions:\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 // kebab-case (canonical internal form)\n | 'llm-grader'\n | 'code-grader'\n | 'rubrics'\n | 'composite'\n | 'tool-trajectory'\n | 'field-accuracy'\n | 'latency'\n | 'cost'\n | 'token-usage'\n | 'execution-metrics'\n | 'skill-trigger'\n | 'contains'\n | 'contains-any'\n | 'contains-all'\n | 'icontains'\n | 'icontains-any'\n | 'icontains-all'\n | 'starts-with'\n | 'ends-with'\n | 'equals'\n | 'regex'\n | 'is-json'\n // legacy aliases (still accepted)\n | 'llm-judge'\n | 'code-judge'\n | 'llm_judge'\n | 'code_judge'\n | 'llm_grader'\n | 'code_grader'\n | 'tool_trajectory'\n | 'field_accuracy'\n | 'token_usage'\n | 'execution_metrics'\n | 'contains_any'\n | 'contains_all'\n | 'icontains_any'\n | 'icontains_all'\n | 'starts_with'\n | 'ends_with'\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 CodeGraderResult for wire compatibility.\n */\nfunction normalizeScore(result: AssertionScore): CodeGraderResult {\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 = CodeGraderInputSchema.parse(camelInput);\n\n // Lazy file-backed output loading\n if (input.outputPath && (input.output === null || input.output === undefined)) {\n let cachedOutput: CodeGraderInput['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 // Enrich input with text accessors and deprecation warnings\n enrichInput(input);\n\n // After enrichment, text accessors are guaranteed to be strings\n const rawResult = await handler(input as EnrichedCodeGraderInput);\n const normalized = normalizeScore(rawResult);\n const result = CodeGraderResultSchema.parse(normalized);\n console.log(JSON.stringify(result, null, 2));\n } catch (error) {\n const errorMessage = formatError(error);\n const errorResult: CodeGraderResult = {\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 * Deprecation warning utilities for code grader and assertion runtimes.\n * Provides text convenience accessors and deprecation warnings on legacy field names.\n */\nimport type { CodeGraderInput } from './schemas.js';\n\nconst ANSI_YELLOW = '\\u001b[33m';\nconst ANSI_RESET = '\\u001b[0m';\n\n/**\n * Emit a deprecation warning to stderr (once per field name per process).\n */\nconst deprecationWarned = new Set<string>();\nfunction warnDeprecation(oldName: string, newName: string): void {\n if (deprecationWarned.has(oldName)) return;\n deprecationWarned.add(oldName);\n console.warn(\n `${ANSI_YELLOW}Warning: '${oldName}' is deprecated in code graders. Use '${newName}' instead.${ANSI_RESET}`,\n );\n}\n\n/**\n * Reset deprecation warning state. Used only in tests.\n */\nexport function resetDeprecationWarnings(): void {\n deprecationWarned.clear();\n}\n\n/**\n * Populate `inputText`, `outputText`, and `expectedOutputText` convenience accessors\n * on the validated input object, and install deprecation warnings on legacy fields.\n *\n * Text accessors are always strings. Structured fields (`input`, `output`, `expectedOutput`)\n * remain `Message[]` always.\n */\nexport function enrichInput(input: CodeGraderInput): CodeGraderInput {\n // Populate text convenience accessors (always strings)\n // inputText = question (first user message content as string)\n const inputText = input.question;\n // outputText = answer (last assistant message content as string)\n const outputText = input.answer;\n // expectedOutputText = referenceAnswer (expected output content as string)\n const expectedOutputText = input.referenceAnswer ?? '';\n\n // Store the original values before redefining properties\n const originalQuestion = input.question;\n const originalAnswer = input.answer;\n const originalReferenceAnswer = input.referenceAnswer;\n\n // Set new text accessor values\n Object.defineProperty(input, 'inputText', {\n value: inputText,\n writable: false,\n configurable: true,\n enumerable: true,\n });\n Object.defineProperty(input, 'outputText', {\n value: outputText,\n writable: false,\n configurable: true,\n enumerable: true,\n });\n Object.defineProperty(input, 'expectedOutputText', {\n value: expectedOutputText,\n writable: false,\n configurable: true,\n enumerable: true,\n });\n\n // Install deprecation warnings on legacy fields via property accessors\n Object.defineProperty(input, 'question', {\n get() {\n warnDeprecation('question', 'inputText');\n return originalQuestion;\n },\n configurable: true,\n enumerable: true,\n });\n\n Object.defineProperty(input, 'answer', {\n get() {\n warnDeprecation('answer', 'outputText');\n return originalAnswer;\n },\n configurable: true,\n enumerable: true,\n });\n\n Object.defineProperty(input, 'referenceAnswer', {\n get() {\n warnDeprecation('referenceAnswer', 'expectedOutputText');\n return originalReferenceAnswer;\n },\n configurable: true,\n enumerable: true,\n });\n\n return input;\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 { enrichInput } from './deprecation.js';\nimport { type EnrichedCodeGraderInput, PromptTemplateInputSchema } from './schemas.js';\n\n/**\n * Handler function type for prompt templates.\n * Returns the prompt string to use for evaluation.\n *\n * The input is enriched at runtime: `inputText`, `outputText`, and\n * `expectedOutputText` are always populated before the handler is called.\n */\nexport type PromptTemplateHandler = (input: EnrichedCodeGraderInput) => 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. Enrich input with text accessors and deprecation warnings\n enrichInput(input);\n\n // 6. Run handler (input is now enriched with guaranteed text accessors)\n const prompt = await handler(input as EnrichedCodeGraderInput);\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.inputText}\n * Answer: ${ctx.outputText}\n *\n * ${ctx.expectedOutputText ? `Reference: ${ctx.expectedOutputText}` : ''}\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.inputText}\n * Candidate Answer: ${ctx.outputText}\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.inputText}\\nAnswer: ${ctx.outputText}`;\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 grader 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 { enrichInput } from './deprecation.js';\nimport {\n type CodeGraderInput,\n CodeGraderInputSchema,\n type CodeGraderResult,\n CodeGraderResultSchema,\n type EnrichedCodeGraderInput,\n} from './schemas.js';\n\n/**\n * Handler function type for code graders.\n *\n * The input is enriched at runtime: `inputText`, `outputText`, and\n * `expectedOutputText` are always populated before the handler is called.\n */\nexport type CodeGraderHandler = (\n input: EnrichedCodeGraderInput,\n) => CodeGraderResult | Promise<CodeGraderResult>;\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 grader handler with full stdin/stdout handling.\n * This is the internal implementation called by defineCodeGrader.\n */\nexport async function runCodeGrader(handler: CodeGraderHandler): 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 = CodeGraderInputSchema.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: CodeGraderInput['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. Enrich input with text accessors and deprecation warnings\n enrichInput(input);\n\n // 7. Run handler (input is now enriched with guaranteed text accessors)\n const rawResult = await handler(input as EnrichedCodeGraderInput);\n\n // 8. Validate and normalize output\n const result = CodeGraderResultSchema.parse({\n ...rawResult,\n score: clampScore(rawResult.score),\n });\n\n // 9. 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: CodeGraderResult = {\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\n// ── Backward-compat aliases (deprecated) ────────────────────────────────────────\n/** @deprecated Use CodeGraderHandler */\nexport type CodeJudgeHandler = CodeGraderHandler;\n/** @deprecated Use runCodeGrader */\nexport const runCodeJudge = runCodeGrader;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA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;AAChD,YAAQ,KAAK,CAAC;AAAA,EAChB;AACF;;;APsCO,SAAS,iBAAiB,SAAkC;AAEjE,gBAAc,OAAO;AACvB;AAGO,IAAM,kBAAkB;AAwCxB,SAAS,qBAAqB,SAAsC;AAEzE,oBAAkB,OAAO;AAC3B;AA8CO,SAAS,gBAAgB,SAAiC;AAC/D,eAAa,OAAO;AACtB;","names":["import_zod","import_node_fs","readStdin","import_node_fs","readStdin","clampScore","formatError"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -148,8 +148,12 @@ declare const MessageSchema: z.ZodObject<{
|
|
|
148
148
|
}>;
|
|
149
149
|
/**
|
|
150
150
|
* Code grader input schema (camelCase, converted from snake_case wire format).
|
|
151
|
+
*
|
|
152
|
+
* Text convenience accessors (`inputText`, `outputText`, `expectedOutputText`) are always
|
|
153
|
+
* strings. Structured fields (`input`, `output`, `expectedOutput`) are always `Message[]`.
|
|
151
154
|
*/
|
|
152
155
|
declare const CodeGraderInputSchema: z.ZodObject<{
|
|
156
|
+
/** @deprecated Use `inputText` instead. First user message content as string. */
|
|
153
157
|
question: z.ZodString;
|
|
154
158
|
criteria: z.ZodString;
|
|
155
159
|
expectedOutput: z.ZodArray<z.ZodObject<{
|
|
@@ -220,7 +224,9 @@ declare const CodeGraderInputSchema: z.ZodObject<{
|
|
|
220
224
|
name?: string | undefined;
|
|
221
225
|
metadata?: Record<string, unknown> | undefined;
|
|
222
226
|
}>, "many">;
|
|
227
|
+
/** @deprecated Use `expectedOutputText` instead. Expected output content as string. */
|
|
223
228
|
referenceAnswer: z.ZodOptional<z.ZodString>;
|
|
229
|
+
/** @deprecated Use `outputText` instead. Last assistant message content as string. */
|
|
224
230
|
answer: z.ZodString;
|
|
225
231
|
output: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{
|
|
226
232
|
role: z.ZodEnum<["assistant", "user", "system", "tool"]>;
|
|
@@ -404,6 +410,12 @@ declare const CodeGraderInputSchema: z.ZodObject<{
|
|
|
404
410
|
fileChanges: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
405
411
|
workspacePath: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
406
412
|
config: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
413
|
+
/** First user message content as string. Replaces `question`. */
|
|
414
|
+
inputText: z.ZodOptional<z.ZodString>;
|
|
415
|
+
/** Last assistant message content as string. Replaces `answer`. */
|
|
416
|
+
outputText: z.ZodOptional<z.ZodString>;
|
|
417
|
+
/** Expected output content as string. Replaces `referenceAnswer`. */
|
|
418
|
+
expectedOutputText: z.ZodOptional<z.ZodString>;
|
|
407
419
|
}, "strip", z.ZodTypeAny, {
|
|
408
420
|
input: {
|
|
409
421
|
role: "tool" | "assistant" | "user" | "system";
|
|
@@ -486,6 +498,9 @@ declare const CodeGraderInputSchema: z.ZodObject<{
|
|
|
486
498
|
fileChanges?: string | null | undefined;
|
|
487
499
|
workspacePath?: string | null | undefined;
|
|
488
500
|
config?: Record<string, unknown> | null | undefined;
|
|
501
|
+
inputText?: string | undefined;
|
|
502
|
+
outputText?: string | undefined;
|
|
503
|
+
expectedOutputText?: string | undefined;
|
|
489
504
|
}, {
|
|
490
505
|
input: {
|
|
491
506
|
role: "tool" | "assistant" | "user" | "system";
|
|
@@ -568,6 +583,9 @@ declare const CodeGraderInputSchema: z.ZodObject<{
|
|
|
568
583
|
fileChanges?: string | null | undefined;
|
|
569
584
|
workspacePath?: string | null | undefined;
|
|
570
585
|
config?: Record<string, unknown> | null | undefined;
|
|
586
|
+
inputText?: string | undefined;
|
|
587
|
+
outputText?: string | undefined;
|
|
588
|
+
expectedOutputText?: string | undefined;
|
|
571
589
|
}>;
|
|
572
590
|
/**
|
|
573
591
|
* Code grader result schema (validated before output).
|
|
@@ -597,6 +615,24 @@ declare const CodeGraderResultSchema: z.ZodObject<{
|
|
|
597
615
|
*/
|
|
598
616
|
type CodeGraderInput = z.infer<typeof CodeGraderInputSchema>;
|
|
599
617
|
type CodeGraderResult = z.infer<typeof CodeGraderResultSchema>;
|
|
618
|
+
/**
|
|
619
|
+
* CodeGraderInput after `enrichInput()` has run.
|
|
620
|
+
*
|
|
621
|
+
* The text convenience accessors (`inputText`, `outputText`, `expectedOutputText`)
|
|
622
|
+
* are always populated by the runtime before the handler is called, so they are
|
|
623
|
+
* guaranteed to be `string` (never `undefined`).
|
|
624
|
+
*
|
|
625
|
+
* Handler function signatures (`CodeGraderHandler`, `AssertionHandler`) use this
|
|
626
|
+
* type so that user code can destructure `{ outputText }` without null-checks.
|
|
627
|
+
*/
|
|
628
|
+
type EnrichedCodeGraderInput = Omit<CodeGraderInput, 'inputText' | 'outputText' | 'expectedOutputText'> & {
|
|
629
|
+
/** First user message content as string. Replaces `question`. */
|
|
630
|
+
readonly inputText: string;
|
|
631
|
+
/** Last assistant message content as string. Replaces `answer`. */
|
|
632
|
+
readonly outputText: string;
|
|
633
|
+
/** Expected output content as string. Replaces `referenceAnswer`. */
|
|
634
|
+
readonly expectedOutputText: string;
|
|
635
|
+
};
|
|
600
636
|
type TraceSummary = z.infer<typeof TraceSummarySchema>;
|
|
601
637
|
type Message = z.infer<typeof MessageSchema>;
|
|
602
638
|
type ToolCall = z.infer<typeof ToolCallSchema>;
|
|
@@ -606,6 +642,7 @@ type TokenUsage = z.infer<typeof TokenUsageSchema>;
|
|
|
606
642
|
* Uses the same schema as CodeGraderInput since the orchestrator sends identical payloads.
|
|
607
643
|
*/
|
|
608
644
|
declare const PromptTemplateInputSchema: z.ZodObject<{
|
|
645
|
+
/** @deprecated Use `inputText` instead. First user message content as string. */
|
|
609
646
|
question: z.ZodString;
|
|
610
647
|
criteria: z.ZodString;
|
|
611
648
|
expectedOutput: z.ZodArray<z.ZodObject<{
|
|
@@ -676,7 +713,9 @@ declare const PromptTemplateInputSchema: z.ZodObject<{
|
|
|
676
713
|
name?: string | undefined;
|
|
677
714
|
metadata?: Record<string, unknown> | undefined;
|
|
678
715
|
}>, "many">;
|
|
716
|
+
/** @deprecated Use `expectedOutputText` instead. Expected output content as string. */
|
|
679
717
|
referenceAnswer: z.ZodOptional<z.ZodString>;
|
|
718
|
+
/** @deprecated Use `outputText` instead. Last assistant message content as string. */
|
|
680
719
|
answer: z.ZodString;
|
|
681
720
|
output: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{
|
|
682
721
|
role: z.ZodEnum<["assistant", "user", "system", "tool"]>;
|
|
@@ -860,6 +899,12 @@ declare const PromptTemplateInputSchema: z.ZodObject<{
|
|
|
860
899
|
fileChanges: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
861
900
|
workspacePath: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
862
901
|
config: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
902
|
+
/** First user message content as string. Replaces `question`. */
|
|
903
|
+
inputText: z.ZodOptional<z.ZodString>;
|
|
904
|
+
/** Last assistant message content as string. Replaces `answer`. */
|
|
905
|
+
outputText: z.ZodOptional<z.ZodString>;
|
|
906
|
+
/** Expected output content as string. Replaces `referenceAnswer`. */
|
|
907
|
+
expectedOutputText: z.ZodOptional<z.ZodString>;
|
|
863
908
|
}, "strip", z.ZodTypeAny, {
|
|
864
909
|
input: {
|
|
865
910
|
role: "tool" | "assistant" | "user" | "system";
|
|
@@ -942,6 +987,9 @@ declare const PromptTemplateInputSchema: z.ZodObject<{
|
|
|
942
987
|
fileChanges?: string | null | undefined;
|
|
943
988
|
workspacePath?: string | null | undefined;
|
|
944
989
|
config?: Record<string, unknown> | null | undefined;
|
|
990
|
+
inputText?: string | undefined;
|
|
991
|
+
outputText?: string | undefined;
|
|
992
|
+
expectedOutputText?: string | undefined;
|
|
945
993
|
}, {
|
|
946
994
|
input: {
|
|
947
995
|
role: "tool" | "assistant" | "user" | "system";
|
|
@@ -1024,10 +1072,14 @@ declare const PromptTemplateInputSchema: z.ZodObject<{
|
|
|
1024
1072
|
fileChanges?: string | null | undefined;
|
|
1025
1073
|
workspacePath?: string | null | undefined;
|
|
1026
1074
|
config?: Record<string, unknown> | null | undefined;
|
|
1075
|
+
inputText?: string | undefined;
|
|
1076
|
+
outputText?: string | undefined;
|
|
1077
|
+
expectedOutputText?: string | undefined;
|
|
1027
1078
|
}>;
|
|
1028
1079
|
type PromptTemplateInput = CodeGraderInput;
|
|
1029
1080
|
/** @deprecated Use CodeGraderInputSchema */
|
|
1030
1081
|
declare const CodeJudgeInputSchema: z.ZodObject<{
|
|
1082
|
+
/** @deprecated Use `inputText` instead. First user message content as string. */
|
|
1031
1083
|
question: z.ZodString;
|
|
1032
1084
|
criteria: z.ZodString;
|
|
1033
1085
|
expectedOutput: z.ZodArray<z.ZodObject<{
|
|
@@ -1098,7 +1150,9 @@ declare const CodeJudgeInputSchema: z.ZodObject<{
|
|
|
1098
1150
|
name?: string | undefined;
|
|
1099
1151
|
metadata?: Record<string, unknown> | undefined;
|
|
1100
1152
|
}>, "many">;
|
|
1153
|
+
/** @deprecated Use `expectedOutputText` instead. Expected output content as string. */
|
|
1101
1154
|
referenceAnswer: z.ZodOptional<z.ZodString>;
|
|
1155
|
+
/** @deprecated Use `outputText` instead. Last assistant message content as string. */
|
|
1102
1156
|
answer: z.ZodString;
|
|
1103
1157
|
output: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{
|
|
1104
1158
|
role: z.ZodEnum<["assistant", "user", "system", "tool"]>;
|
|
@@ -1282,6 +1336,12 @@ declare const CodeJudgeInputSchema: z.ZodObject<{
|
|
|
1282
1336
|
fileChanges: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
1283
1337
|
workspacePath: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
1284
1338
|
config: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
1339
|
+
/** First user message content as string. Replaces `question`. */
|
|
1340
|
+
inputText: z.ZodOptional<z.ZodString>;
|
|
1341
|
+
/** Last assistant message content as string. Replaces `answer`. */
|
|
1342
|
+
outputText: z.ZodOptional<z.ZodString>;
|
|
1343
|
+
/** Expected output content as string. Replaces `referenceAnswer`. */
|
|
1344
|
+
expectedOutputText: z.ZodOptional<z.ZodString>;
|
|
1285
1345
|
}, "strip", z.ZodTypeAny, {
|
|
1286
1346
|
input: {
|
|
1287
1347
|
role: "tool" | "assistant" | "user" | "system";
|
|
@@ -1364,6 +1424,9 @@ declare const CodeJudgeInputSchema: z.ZodObject<{
|
|
|
1364
1424
|
fileChanges?: string | null | undefined;
|
|
1365
1425
|
workspacePath?: string | null | undefined;
|
|
1366
1426
|
config?: Record<string, unknown> | null | undefined;
|
|
1427
|
+
inputText?: string | undefined;
|
|
1428
|
+
outputText?: string | undefined;
|
|
1429
|
+
expectedOutputText?: string | undefined;
|
|
1367
1430
|
}, {
|
|
1368
1431
|
input: {
|
|
1369
1432
|
role: "tool" | "assistant" | "user" | "system";
|
|
@@ -1446,6 +1509,9 @@ declare const CodeJudgeInputSchema: z.ZodObject<{
|
|
|
1446
1509
|
fileChanges?: string | null | undefined;
|
|
1447
1510
|
workspacePath?: string | null | undefined;
|
|
1448
1511
|
config?: Record<string, unknown> | null | undefined;
|
|
1512
|
+
inputText?: string | undefined;
|
|
1513
|
+
outputText?: string | undefined;
|
|
1514
|
+
expectedOutputText?: string | undefined;
|
|
1449
1515
|
}>;
|
|
1450
1516
|
/** @deprecated Use CodeGraderResultSchema */
|
|
1451
1517
|
declare const CodeJudgeResultSchema: z.ZodObject<{
|
|
@@ -1585,9 +1651,12 @@ declare function createTargetClient(): TargetClient | undefined;
|
|
|
1585
1651
|
|
|
1586
1652
|
/**
|
|
1587
1653
|
* Context provided to assertion handlers.
|
|
1588
|
-
*
|
|
1654
|
+
*
|
|
1655
|
+
* Same shape as CodeGraderInput but with `inputText`, `outputText`, and
|
|
1656
|
+
* `expectedOutputText` guaranteed to be strings (populated by the runtime
|
|
1657
|
+
* before the handler is called).
|
|
1589
1658
|
*/
|
|
1590
|
-
type AssertionContext =
|
|
1659
|
+
type AssertionContext = EnrichedCodeGraderInput;
|
|
1591
1660
|
/**
|
|
1592
1661
|
* Known built-in assertion types. Custom types are extensible via string.
|
|
1593
1662
|
*
|
|
@@ -1643,13 +1712,19 @@ type AssertionHandler = (ctx: AssertionContext) => AssertionScore | Promise<Asse
|
|
|
1643
1712
|
/**
|
|
1644
1713
|
* Handler function type for prompt templates.
|
|
1645
1714
|
* Returns the prompt string to use for evaluation.
|
|
1715
|
+
*
|
|
1716
|
+
* The input is enriched at runtime: `inputText`, `outputText`, and
|
|
1717
|
+
* `expectedOutputText` are always populated before the handler is called.
|
|
1646
1718
|
*/
|
|
1647
|
-
type PromptTemplateHandler = (input:
|
|
1719
|
+
type PromptTemplateHandler = (input: EnrichedCodeGraderInput) => string | Promise<string>;
|
|
1648
1720
|
|
|
1649
1721
|
/**
|
|
1650
1722
|
* Handler function type for code graders.
|
|
1723
|
+
*
|
|
1724
|
+
* The input is enriched at runtime: `inputText`, `outputText`, and
|
|
1725
|
+
* `expectedOutputText` are always populated before the handler is called.
|
|
1651
1726
|
*/
|
|
1652
|
-
type CodeGraderHandler = (input:
|
|
1727
|
+
type CodeGraderHandler = (input: EnrichedCodeGraderInput) => CodeGraderResult | Promise<CodeGraderResult>;
|
|
1653
1728
|
/** @deprecated Use CodeGraderHandler */
|
|
1654
1729
|
type CodeJudgeHandler = CodeGraderHandler;
|
|
1655
1730
|
|
|
@@ -1663,8 +1738,8 @@ type CodeJudgeHandler = CodeGraderHandler;
|
|
|
1663
1738
|
* #!/usr/bin/env bun
|
|
1664
1739
|
* import { defineAssertion } from '@agentv/eval';
|
|
1665
1740
|
*
|
|
1666
|
-
* export default defineAssertion(({
|
|
1667
|
-
* pass:
|
|
1741
|
+
* export default defineAssertion(({ outputText }) => ({
|
|
1742
|
+
* pass: outputText.includes('hello'),
|
|
1668
1743
|
* reasoning: 'Checks greeting',
|
|
1669
1744
|
* }));
|
|
1670
1745
|
* ```
|
|
@@ -1674,7 +1749,7 @@ type CodeJudgeHandler = CodeGraderHandler;
|
|
|
1674
1749
|
* #!/usr/bin/env bun
|
|
1675
1750
|
* import { defineCodeGrader } from '@agentv/eval';
|
|
1676
1751
|
*
|
|
1677
|
-
* export default defineCodeGrader(({ trace,
|
|
1752
|
+
* export default defineCodeGrader(({ trace, outputText }) => ({
|
|
1678
1753
|
* score: trace?.eventCount <= 5 ? 1.0 : 0.5,
|
|
1679
1754
|
* hits: ['Efficient tool usage'],
|
|
1680
1755
|
* misses: [],
|
|
@@ -1686,14 +1761,14 @@ type CodeJudgeHandler = CodeGraderHandler;
|
|
|
1686
1761
|
* #!/usr/bin/env bun
|
|
1687
1762
|
* import { defineCodeGrader, createTargetClient } from '@agentv/eval';
|
|
1688
1763
|
*
|
|
1689
|
-
* export default defineCodeGrader(async ({
|
|
1764
|
+
* export default defineCodeGrader(async ({ inputText }) => {
|
|
1690
1765
|
* const target = createTargetClient();
|
|
1691
1766
|
* if (!target) {
|
|
1692
1767
|
* return { score: 0, misses: ['Target not available'] };
|
|
1693
1768
|
* }
|
|
1694
1769
|
*
|
|
1695
1770
|
* const response = await target.invoke({
|
|
1696
|
-
* question: `Evaluate: ${
|
|
1771
|
+
* question: `Evaluate: ${inputText}`,
|
|
1697
1772
|
* systemPrompt: 'Respond with JSON: { "score": 0-1 }'
|
|
1698
1773
|
* });
|
|
1699
1774
|
*
|
|
@@ -1769,10 +1844,10 @@ declare const defineCodeJudge: typeof defineCodeGrader;
|
|
|
1769
1844
|
* import { definePromptTemplate } from '@agentv/eval';
|
|
1770
1845
|
*
|
|
1771
1846
|
* export default definePromptTemplate((ctx) => `
|
|
1772
|
-
* Question: ${ctx.
|
|
1773
|
-
* Answer: ${ctx.
|
|
1847
|
+
* Question: ${ctx.inputText}
|
|
1848
|
+
* Answer: ${ctx.outputText}
|
|
1774
1849
|
*
|
|
1775
|
-
* ${ctx.
|
|
1850
|
+
* ${ctx.expectedOutputText ? `Reference: ${ctx.expectedOutputText}` : ''}
|
|
1776
1851
|
* `);
|
|
1777
1852
|
* ```
|
|
1778
1853
|
*
|
|
@@ -1783,8 +1858,8 @@ declare const defineCodeJudge: typeof defineCodeGrader;
|
|
|
1783
1858
|
* export default definePromptTemplate((ctx) => {
|
|
1784
1859
|
* const rubric = ctx.config?.rubric as string | undefined;
|
|
1785
1860
|
* return `
|
|
1786
|
-
* Question: ${ctx.
|
|
1787
|
-
* Candidate Answer: ${ctx.
|
|
1861
|
+
* Question: ${ctx.inputText}
|
|
1862
|
+
* Candidate Answer: ${ctx.outputText}
|
|
1788
1863
|
* ${rubric ? `\nEvaluation Criteria:\n${rubric}` : ''}
|
|
1789
1864
|
* `;
|
|
1790
1865
|
* });
|
|
@@ -1812,8 +1887,8 @@ declare function definePromptTemplate(handler: PromptTemplateHandler): void;
|
|
|
1812
1887
|
* ```typescript
|
|
1813
1888
|
* import { defineAssertion } from '@agentv/eval';
|
|
1814
1889
|
*
|
|
1815
|
-
* export default defineAssertion(({
|
|
1816
|
-
* pass:
|
|
1890
|
+
* export default defineAssertion(({ outputText }) => ({
|
|
1891
|
+
* pass: outputText.toLowerCase().includes('hello'),
|
|
1817
1892
|
* reasoning: 'Checks for greeting',
|
|
1818
1893
|
* }));
|
|
1819
1894
|
* ```
|
|
@@ -1822,8 +1897,8 @@ declare function definePromptTemplate(handler: PromptTemplateHandler): void;
|
|
|
1822
1897
|
* ```typescript
|
|
1823
1898
|
* import { defineAssertion } from '@agentv/eval';
|
|
1824
1899
|
*
|
|
1825
|
-
* export default defineAssertion(({
|
|
1826
|
-
* const hasContent =
|
|
1900
|
+
* export default defineAssertion(({ outputText, trace }) => {
|
|
1901
|
+
* const hasContent = outputText.length > 0 ? 0.5 : 0;
|
|
1827
1902
|
* const isEfficient = (trace?.eventCount ?? 0) <= 5 ? 0.5 : 0;
|
|
1828
1903
|
* return {
|
|
1829
1904
|
* score: hasContent + isEfficient,
|
|
@@ -1837,4 +1912,4 @@ declare function definePromptTemplate(handler: PromptTemplateHandler): void;
|
|
|
1837
1912
|
*/
|
|
1838
1913
|
declare function defineAssertion(handler: AssertionHandler): void;
|
|
1839
1914
|
|
|
1840
|
-
export { type AssertionContext, type AssertionHandler, type AssertionScore, type AssertionType, type CodeGraderHandler, type CodeGraderInput, CodeGraderInputSchema, type CodeGraderResult, CodeGraderResultSchema, type CodeJudgeHandler, type CodeJudgeInput, CodeJudgeInputSchema, type CodeJudgeResult, CodeJudgeResultSchema, type Message, MessageSchema, type PromptTemplateHandler, type PromptTemplateInput, PromptTemplateInputSchema, type TargetClient, type TargetInfo, TargetInvocationError, type TargetInvokeRequest, type TargetInvokeResponse, TargetNotAvailableError, type TokenUsage, TokenUsageSchema, type ToolCall, ToolCallSchema, type TraceSummary, TraceSummarySchema, createTargetClient, defineAssertion, defineCodeGrader, defineCodeJudge, definePromptTemplate };
|
|
1915
|
+
export { type AssertionContext, type AssertionHandler, type AssertionScore, type AssertionType, type CodeGraderHandler, type CodeGraderInput, CodeGraderInputSchema, type CodeGraderResult, CodeGraderResultSchema, type CodeJudgeHandler, type CodeJudgeInput, CodeJudgeInputSchema, type CodeJudgeResult, CodeJudgeResultSchema, type EnrichedCodeGraderInput, type Message, MessageSchema, type PromptTemplateHandler, type PromptTemplateInput, PromptTemplateInputSchema, type TargetClient, type TargetInfo, TargetInvocationError, type TargetInvokeRequest, type TargetInvokeResponse, TargetNotAvailableError, type TokenUsage, TokenUsageSchema, type ToolCall, ToolCallSchema, type TraceSummary, TraceSummarySchema, createTargetClient, defineAssertion, defineCodeGrader, defineCodeJudge, definePromptTemplate };
|