@agentv/sdk 4.41.5-next.1 → 4.41.6-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -1
- package/dist/index.cjs +94 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +196 -1
- package/dist/index.d.ts +196 -1
- package/dist/index.js +90 -0
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @agentv/sdk
|
|
2
2
|
|
|
3
|
-
Evaluation SDK for AgentV - build custom graders and prompt templates around the canonical AgentV eval model.
|
|
3
|
+
Evaluation SDK for AgentV - build YAML-aligned eval suites, custom graders, and prompt templates around the canonical AgentV eval model.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -41,11 +41,37 @@ export default defineCodeGrader(({ output, traceSummary }) => ({
|
|
|
41
41
|
|
|
42
42
|
Both functions handle stdin/stdout parsing, snake_case conversion, Zod validation, and error handling automatically.
|
|
43
43
|
|
|
44
|
+
### defineEval (YAML-aligned `.eval.ts` authoring)
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
#!/usr/bin/env bun
|
|
48
|
+
import { defineEval } from '@agentv/sdk';
|
|
49
|
+
|
|
50
|
+
export default defineEval({
|
|
51
|
+
name: 'hello-suite',
|
|
52
|
+
execution: {
|
|
53
|
+
targets: ['mock-sdk'],
|
|
54
|
+
},
|
|
55
|
+
tests: [
|
|
56
|
+
{
|
|
57
|
+
id: 'hello',
|
|
58
|
+
input: 'Say hello',
|
|
59
|
+
expectedOutput: 'Hello from the mock target',
|
|
60
|
+
assertions: [{ type: 'contains', value: 'Hello' }],
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
});
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
`defineEval()` keeps TypeScript authoring in camelCase and lowers to the canonical snake_case YAML/runtime contract when AgentV loads the `.eval.ts` file.
|
|
67
|
+
|
|
44
68
|
## Exports
|
|
45
69
|
|
|
46
70
|
- `defineAssertion(handler)` - Define a custom assertion (pass/fail + optional score)
|
|
47
71
|
- `defineCodeGrader(handler)` - Define a code grader grader (full score control)
|
|
48
72
|
- `definePromptTemplate(handler)` - Define a dynamic prompt template
|
|
73
|
+
- `defineEval(definition)` / `evalSuite(definition)` - Define a YAML-aligned `.eval.ts` suite
|
|
74
|
+
- `toEvalYamlObject(definition)` / `serializeEvalYaml(definition)` - Lower or serialize canonical eval YAML
|
|
49
75
|
- `AssertionContext`, `AssertionScore` - Assertion types
|
|
50
76
|
- `CodeGraderInput`, `CodeGraderResult` - Code grader types
|
|
51
77
|
- `TraceSummary`, `Message`, `ToolCall` - Trace data types
|
package/dist/index.cjs
CHANGED
|
@@ -53,7 +53,11 @@ __export(index_exports, {
|
|
|
53
53
|
createTargetClient: () => createTargetClient,
|
|
54
54
|
defineAssertion: () => defineAssertion,
|
|
55
55
|
defineCodeGrader: () => defineCodeGrader,
|
|
56
|
+
defineEval: () => defineEval,
|
|
56
57
|
definePromptTemplate: () => definePromptTemplate,
|
|
58
|
+
evalSuite: () => evalSuite,
|
|
59
|
+
serializeEvalYaml: () => serializeEvalYaml,
|
|
60
|
+
toEvalYamlObject: () => toEvalYamlObject,
|
|
57
61
|
z: () => import_zod2.z
|
|
58
62
|
});
|
|
59
63
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -286,6 +290,92 @@ var CodeGraderResultSchema = import_zod.z.object({
|
|
|
286
290
|
});
|
|
287
291
|
var PromptTemplateInputSchema = CodeGraderInputSchema;
|
|
288
292
|
|
|
293
|
+
// src/eval.ts
|
|
294
|
+
var import_yaml = require("yaml");
|
|
295
|
+
var EVAL_SUITE_SYMBOL = Symbol.for("@agentv/sdk/eval-suite");
|
|
296
|
+
var TO_EVAL_YAML_OBJECT_SYMBOL = Symbol.for("@agentv/sdk/to-eval-yaml-object");
|
|
297
|
+
var KNOWN_SNAKE_CASE_KEYS = {
|
|
298
|
+
afterAll: "after_all",
|
|
299
|
+
afterEach: "after_each",
|
|
300
|
+
argsMatch: "args_match",
|
|
301
|
+
baseCommit: "base_commit",
|
|
302
|
+
beforeAll: "before_all",
|
|
303
|
+
beforeEach: "before_each",
|
|
304
|
+
budgetUsd: "budget_usd",
|
|
305
|
+
conversationId: "conversation_id",
|
|
306
|
+
costLimitUsd: "cost_limit_usd",
|
|
307
|
+
dependsOn: "depends_on",
|
|
308
|
+
expectedOutput: "expected_output",
|
|
309
|
+
explorationTolerance: "exploration_tolerance",
|
|
310
|
+
failOnError: "fail_on_error",
|
|
311
|
+
inputFiles: "input_files",
|
|
312
|
+
keepWorkspaces: "keep_workspaces",
|
|
313
|
+
maxCostUsd: "max_cost_usd",
|
|
314
|
+
maxDurationMs: "max_duration_ms",
|
|
315
|
+
maxInput: "max_input",
|
|
316
|
+
maxLlmCalls: "max_llm_calls",
|
|
317
|
+
maxOutput: "max_output",
|
|
318
|
+
maxTokens: "max_tokens",
|
|
319
|
+
maxToolCalls: "max_tool_calls",
|
|
320
|
+
minScore: "min_score",
|
|
321
|
+
onDependencyFailure: "on_dependency_failure",
|
|
322
|
+
onTurnFailure: "on_turn_failure",
|
|
323
|
+
outputPath: "output_path",
|
|
324
|
+
scoreRanges: "score_ranges",
|
|
325
|
+
skipDefaults: "skip_defaults",
|
|
326
|
+
targetExplorationRatio: "target_exploration_ratio",
|
|
327
|
+
timeoutMs: "timeout_ms",
|
|
328
|
+
useTarget: "use_target",
|
|
329
|
+
windowSize: "window_size"
|
|
330
|
+
};
|
|
331
|
+
function lowerEvalYamlValue(value) {
|
|
332
|
+
if (Array.isArray(value)) {
|
|
333
|
+
return value.map((item) => lowerEvalYamlValue(item));
|
|
334
|
+
}
|
|
335
|
+
if (value && typeof value === "object") {
|
|
336
|
+
const result = {};
|
|
337
|
+
for (const [key, nestedValue] of Object.entries(value)) {
|
|
338
|
+
const loweredKey = KNOWN_SNAKE_CASE_KEYS[key] ?? key;
|
|
339
|
+
result[loweredKey] = lowerEvalYamlValue(nestedValue);
|
|
340
|
+
}
|
|
341
|
+
return result;
|
|
342
|
+
}
|
|
343
|
+
return value;
|
|
344
|
+
}
|
|
345
|
+
function attachEvalSuiteBrand(definition) {
|
|
346
|
+
const branded = definition;
|
|
347
|
+
if (branded[EVAL_SUITE_SYMBOL] === true) {
|
|
348
|
+
return branded;
|
|
349
|
+
}
|
|
350
|
+
Object.defineProperties(branded, {
|
|
351
|
+
[EVAL_SUITE_SYMBOL]: {
|
|
352
|
+
value: true,
|
|
353
|
+
enumerable: false,
|
|
354
|
+
configurable: false,
|
|
355
|
+
writable: false
|
|
356
|
+
},
|
|
357
|
+
[TO_EVAL_YAML_OBJECT_SYMBOL]: {
|
|
358
|
+
value: () => toEvalYamlObject(definition),
|
|
359
|
+
enumerable: false,
|
|
360
|
+
configurable: false,
|
|
361
|
+
writable: false
|
|
362
|
+
}
|
|
363
|
+
});
|
|
364
|
+
return branded;
|
|
365
|
+
}
|
|
366
|
+
function defineEval(definition) {
|
|
367
|
+
return attachEvalSuiteBrand(definition);
|
|
368
|
+
}
|
|
369
|
+
function evalSuite(definition) {
|
|
370
|
+
return defineEval(definition);
|
|
371
|
+
}
|
|
372
|
+
function toEvalYamlObject(definition) {
|
|
373
|
+
return lowerEvalYamlValue(definition);
|
|
374
|
+
}
|
|
375
|
+
function serializeEvalYaml(definition) {
|
|
376
|
+
return (0, import_yaml.stringify)(toEvalYamlObject(definition), { lineWidth: 0 }).trimEnd();
|
|
377
|
+
}
|
|
378
|
+
|
|
289
379
|
// src/target-client.ts
|
|
290
380
|
var TargetNotAvailableError = class extends Error {
|
|
291
381
|
constructor(message) {
|
|
@@ -617,7 +707,11 @@ function defineAssertion(handler) {
|
|
|
617
707
|
createTargetClient,
|
|
618
708
|
defineAssertion,
|
|
619
709
|
defineCodeGrader,
|
|
710
|
+
defineEval,
|
|
620
711
|
definePromptTemplate,
|
|
712
|
+
evalSuite,
|
|
713
|
+
serializeEvalYaml,
|
|
714
|
+
toEvalYamlObject,
|
|
621
715
|
z
|
|
622
716
|
});
|
|
623
717
|
//# sourceMappingURL=index.cjs.map
|
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/deprecation.ts","../src/prompt-template.ts","../src/runtime.ts"],"sourcesContent":["/**\n * AgentV Evaluation SDK\n *\n * Build custom graders 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/sdk';\n *\n * export default defineAssertion(({ output, criteria }) => {\n * const answer = output ?? '';\n * return {\n * pass: answer.includes('hello'),\n * assertions: [{ text: 'Checks greeting', passed: answer.includes('hello') }],\n * };\n * }));\n * ```\n *\n * @example Code grader (full control)\n * ```typescript\n * #!/usr/bin/env bun\n * import { defineCodeGrader } from '@agentv/sdk';\n *\n * export default defineCodeGrader(({ output, traceSummary }) => {\n * return {\n * score: (output ?? '').length > 0 && (traceSummary?.eventCount ?? 0) <= 5 ? 1.0 : 0.5,\n * assertions: [\n * { text: 'Answer is not empty', passed: (output ?? '').length > 0 },\n * { text: 'Efficient tool usage', passed: (traceSummary?.eventCount ?? 0) <= 5 },\n * ],\n * };\n * }));\n * ```\n *\n * @packageDocumentation\n */\n\n// Re-export schemas and types\nexport {\n CodeGraderInputSchema,\n CodeGraderResultSchema,\n TRACE_REDACTION_LEVELS,\n TRACE_SOURCE_KINDS,\n TRACE_EVENT_TYPES,\n TRACE_TOOL_STATUSES,\n TraceSummarySchema,\n TraceSchema,\n TraceArtifactSchema,\n TraceRawEvidenceSchema,\n TraceRedactionStateSchema,\n TraceBranchSchema,\n TraceErrorSchema,\n TraceEventSchema,\n TraceMessageSchema,\n TraceModelSchema,\n TraceSessionSchema,\n TraceSourceRefSchema,\n TraceSourceSchema,\n TraceToolSchema,\n MessageSchema,\n ToolCallSchema,\n TokenUsageSchema,\n PromptTemplateInputSchema,\n ContentTextSchema,\n ContentImageSchema,\n ContentFileSchema,\n ContentSchema,\n type CodeGraderInput,\n type CodeGraderResult,\n type TraceArtifact,\n type TraceRawEvidence,\n type TraceRedactionState,\n type TraceBranch,\n type TraceError,\n type TraceEvent,\n type TraceMessage,\n type TraceModel,\n type TraceSession,\n type TraceSource,\n type TraceSourceRef,\n type TraceTool,\n type TraceSummary,\n type Trace,\n type Message,\n type ToolCall,\n type TokenUsage,\n type PromptTemplateInput,\n type ContentText,\n type ContentImage,\n type ContentFile,\n type Content,\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, runCodeGrader } from './runtime.js';\n\nexport type { CodeGraderHandler };\nexport type { PromptTemplateHandler };\n\n/**\n * Define a code grader 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/sdk';\n *\n * export default defineCodeGrader(({ trace }) => {\n * if (!trace) {\n * return { score: 0.5, assertions: [{ text: 'No trace available', passed: false }] };\n * }\n *\n * const efficient = trace.eventCount <= 10;\n * return {\n * score: efficient ? 1.0 : 0.5,\n * assertions: [{ text: efficient ? 'Efficient execution' : 'Too many tool calls', passed: efficient }],\n * };\n * });\n * ```\n *\n * @example With typed config\n * ```typescript\n * import { defineCodeGrader, z } from '@agentv/sdk';\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/**\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/sdk';\n *\n * export default definePromptTemplate((ctx) => {\n * const question = ctx.input\n * .filter((message) => message.role === 'user')\n * .map((message) => typeof message.content === 'string' ? message.content : '')\n * .join('\\n');\n * const answer = ctx.output ?? '';\n * return `Question: ${question}\\nAnswer: ${answer}`;\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 grader 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/sdk';\n *\n * export default defineAssertion(({ output }) => {\n * const text = output ?? '';\n * return {\n * pass: text.toLowerCase().includes('hello'),\n * assertions: [{ text: 'Checks for greeting', passed: text.toLowerCase().includes('hello') }],\n * };\n * }));\n * ```\n *\n * @example Granular scoring\n * ```typescript\n * import { defineAssertion } from '@agentv/sdk';\n *\n * export default defineAssertion(({ output, traceSummary }) => {\n * const text = output ?? '';\n * const hasContent = text.length > 0 ? 0.5 : 0;\n * const isEfficient = (traceSummary?.eventCount ?? 0) <= 5 ? 0.5 : 0;\n * return {\n * score: hasContent + isEfficient,\n * assertions: [\n * { text: 'Has content', passed: !!hasContent },\n * { text: 'Efficient', passed: !!isEfficient },\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 *\n * ## Content model\n *\n * `Message.content` accepts `string | object[] | object`:\n * - `string` — backward-compatible plain text (most common case)\n * - `object[]` — typed content blocks for multimodal messages, plus AgentV\n * eval input blocks such as `{ type: \"file\", value, path, text }`\n * - `object` — structured YAML/JSON content such as expected outputs\n *\n * Content variants:\n * - `ContentText` — `{ type: 'text', text: string }`\n * - `ContentImage` — `{ type: 'image', media_type: string, path: string }` (file path, not base64)\n * - `ContentFile` — `{ type: 'file', media_type: string, path: string }`\n *\n * To add a new content variant:\n * 1. Define a new Zod schema with a unique `type` literal\n * 2. Add it to `ContentSchema` discriminated union\n * 3. Re-export from `index.ts`\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 reasoning: z.number().optional(),\n});\n\n/**\n * Derived trace summary schema (camelCase for TypeScript ergonomics).\n *\n * This is a compact read model for metric-style graders. Full transcript/tool\n * evidence lives in the canonical `Trace` under `messages` and `events`.\n */\nexport const TraceSummarySchema = z.object({\n eventCount: z.number(),\n toolCalls: 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\nexport const TRACE_SOURCE_KINDS = [\n 'agentv_run',\n 'otlp',\n 'phoenix',\n 'langfuse',\n 'pi_session',\n 'imported_transcript',\n 'compact_transcript',\n] as const;\n\nexport const TRACE_EVENT_TYPES = [\n 'message',\n 'model_turn',\n 'tool_call',\n 'tool_result',\n 'final_response',\n 'error',\n] as const;\n\nexport const TRACE_TOOL_STATUSES = ['ok', 'error', 'timeout', 'cancelled', 'unknown'] as const;\n\nexport const TRACE_REDACTION_LEVELS = ['none', 'partial', 'full'] as const;\n\nconst MetadataSchema = z.record(z.string(), z.unknown());\n\nexport const TraceRedactionStateSchema = z.object({\n level: z.enum(TRACE_REDACTION_LEVELS),\n fields: z.array(z.string()).optional(),\n reason: z.string().optional(),\n});\n\nexport const TraceErrorSchema = z.object({\n message: z.string(),\n name: z.string().optional(),\n code: z.string().optional(),\n stack: z.string().optional(),\n metadata: MetadataSchema.optional(),\n});\n\nexport const TraceSourceSchema = z.object({\n kind: z.enum(TRACE_SOURCE_KINDS),\n path: z.string().optional(),\n url: z.string().optional(),\n provider: z.string().optional(),\n format: z.string().optional(),\n version: z.string().optional(),\n metadata: MetadataSchema.optional(),\n});\n\nexport const TraceSessionSchema = z.object({\n sessionId: z.string().optional(),\n conversationId: z.string().optional(),\n cwd: z.string().optional(),\n startedAt: z.string().optional(),\n endedAt: z.string().optional(),\n metadata: MetadataSchema.optional(),\n});\n\nexport const TraceBranchSchema = z.object({\n selectedLeafId: z.string().optional(),\n selectedPathIds: z.array(z.string()).optional(),\n includedEventIds: z.array(z.string()).optional(),\n omittedEventIds: z.array(z.string()).optional(),\n selectionReason: z.string().optional(),\n});\n\nexport const TraceSourceRefSchema = z.object({\n eventId: z.string().optional(),\n messageId: z.string().optional(),\n spanId: z.string().optional(),\n traceId: z.string().optional(),\n rawKind: z.string().optional(),\n path: z.string().optional(),\n line: z.number().int().nonnegative().optional(),\n metadata: MetadataSchema.optional(),\n});\n\nexport const TraceRawEvidenceSchema = z.object({\n kind: z.string(),\n ref: z.string().optional(),\n mediaType: z.string().optional(),\n content: z.unknown().optional(),\n redacted: z.boolean().optional(),\n metadata: MetadataSchema.optional(),\n});\n\nexport const TraceMessageSchema = z.object({\n role: z.string(),\n name: z.string().optional(),\n content: z.unknown().optional(),\n redaction: TraceRedactionStateSchema.optional(),\n tokenUsage: TokenUsageSchema.optional(),\n metadata: MetadataSchema.optional(),\n});\n\nexport const TraceModelSchema = z.object({\n provider: z.string().optional(),\n name: z.string().optional(),\n invocationId: z.string().optional(),\n tokenUsage: TokenUsageSchema.optional(),\n metadata: MetadataSchema.optional(),\n});\n\nexport const TraceToolSchema = z.object({\n name: z.string(),\n callId: z.string().optional(),\n input: z.unknown().optional(),\n output: z.unknown().optional(),\n status: z.enum(TRACE_TOOL_STATUSES).optional(),\n error: TraceErrorSchema.optional(),\n redaction: TraceRedactionStateSchema.optional(),\n metadata: MetadataSchema.optional(),\n});\n\nexport const TraceEventSchema = z.object({\n eventId: z.string(),\n parentEventId: z.string().optional(),\n ordinal: z.number().int().nonnegative(),\n type: z.enum(TRACE_EVENT_TYPES),\n timestamp: z.string().optional(),\n durationMs: z.number().nonnegative().optional(),\n durationInferred: z.boolean().optional(),\n turnIndex: z.number().int().nonnegative().optional(),\n message: TraceMessageSchema.optional(),\n model: TraceModelSchema.optional(),\n tool: TraceToolSchema.optional(),\n error: TraceErrorSchema.optional(),\n sourceRef: TraceSourceRefSchema.optional(),\n rawEvidence: z.array(TraceRawEvidenceSchema).optional(),\n redaction: TraceRedactionStateSchema.optional(),\n metadata: MetadataSchema.optional(),\n});\n\n/**\n * Derived trace artifact shape used by import/replay helpers.\n *\n * This is not a persisted public trace contract. Grader authors normally\n * receive the result-local `Trace` shape below.\n */\nexport const TraceArtifactSchema = z.object({\n source: TraceSourceSchema,\n session: TraceSessionSchema,\n branch: TraceBranchSchema.optional(),\n events: z.array(TraceEventSchema),\n tokenUsage: TokenUsageSchema.optional(),\n costUsd: z.number().optional(),\n durationMs: z.number().optional(),\n startedAt: z.string().optional(),\n endedAt: z.string().optional(),\n metadata: MetadataSchema.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// Content block schemas (discriminated union on `type`)\n// ---------------------------------------------------------------------------\n\n/** Text content block. */\nexport const ContentTextSchema = z.object({\n type: z.literal('text'),\n text: z.string(),\n});\n\n/**\n * Image content block.\n * `path` is a filesystem path — never inline base64.\n */\nexport const ContentImageSchema = z.object({\n type: z.literal('image'),\n media_type: z.string(),\n path: z.string(),\n});\n\n/** File content block. */\nexport const ContentFileSchema = z.object({\n type: z.literal('file'),\n media_type: z.string(),\n path: z.string(),\n});\n\n/** Discriminated union of all content block types. */\nexport const ContentSchema = z.discriminatedUnion('type', [\n ContentTextSchema,\n ContentImageSchema,\n ContentFileSchema,\n]);\n\nconst MessageContentBlockSchema = z.union([ContentSchema, z.record(z.unknown())]);\n\n/**\n * Unified message schema for input, expected, and output messages.\n *\n * `content` is a plain string, an array of structured blocks, or a\n * structured object from YAML/JSON eval files. Use `getTextContent()` from\n * `@agentv/core` to extract plain text when the content is textual.\n */\nexport const MessageSchema = z.object({\n role: z.enum(['assistant', 'user', 'system', 'tool']),\n content: z\n .union([z.string(), z.array(MessageContentBlockSchema), z.record(z.unknown())])\n .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 * Derived evaluation trace read model exposed to custom graders.\n *\n * Top-level summary fields (`eventCount`, `toolCalls`, `errorCount`) remain\n * available for existing metric graders; full transcript/tool evidence is under\n * `messages` and structured execution events under `events`.\n */\nexport const TraceSchema = TraceSummarySchema.extend({\n messages: z.array(MessageSchema),\n events: z.array(TraceEventSchema),\n tokenUsage: TokenUsageSchema.optional(),\n costUsd: z.number().optional(),\n durationMs: z.number().optional(),\n startTime: z.string().optional(),\n endTime: z.string().optional(),\n metadata: MetadataSchema.optional(),\n});\n\n/**\n * Code grader input schema (camelCase, converted from snake_case wire format).\n *\n * `output` is the final answer/scored result only. Transcript-aware graders\n * should inspect `messages`, `trace.messages`, or `trace.events`.\n */\nexport const CodeGraderInputSchema = z.object({\n criteria: z.string(),\n expectedOutput: z.array(MessageSchema),\n output: z.string().nullable().optional(),\n messages: z.array(MessageSchema).optional().default([]),\n /** Path to a temp file containing the output JSON (used for large payloads). */\n outputPath: z.string().optional(),\n inputFiles: z.array(z.string()),\n input: z.array(MessageSchema),\n metadata: z.record(z.unknown()).nullable().optional(),\n trace: TraceSchema.nullable().optional(),\n traceSummary: 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 assertions: z\n .array(\n z.object({\n text: z.string(),\n passed: z.boolean(),\n evidence: z.string().optional(),\n }),\n )\n .optional()\n .default([]),\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\nexport type TraceSummary = z.infer<typeof TraceSummarySchema>;\nexport type Trace = z.infer<typeof TraceSchema>;\nexport type TraceArtifact = z.infer<typeof TraceArtifactSchema>;\nexport type TraceSource = z.infer<typeof TraceSourceSchema>;\nexport type TraceSession = z.infer<typeof TraceSessionSchema>;\nexport type TraceBranch = z.infer<typeof TraceBranchSchema>;\nexport type TraceEvent = z.infer<typeof TraceEventSchema>;\nexport type TraceMessage = z.infer<typeof TraceMessageSchema>;\nexport type TraceModel = z.infer<typeof TraceModelSchema>;\nexport type TraceTool = z.infer<typeof TraceToolSchema>;\nexport type TraceError = z.infer<typeof TraceErrorSchema>;\nexport type TraceSourceRef = z.infer<typeof TraceSourceRefSchema>;\nexport type TraceRawEvidence = z.infer<typeof TraceRawEvidenceSchema>;\nexport type TraceRedactionState = z.infer<typeof TraceRedactionStateSchema>;\nexport type Message = z.infer<typeof MessageSchema>;\nexport type ToolCall = z.infer<typeof ToolCallSchema>;\nexport type TokenUsage = z.infer<typeof TokenUsageSchema>;\n\nexport type ContentText = z.infer<typeof ContentTextSchema>;\nexport type ContentImage = z.infer<typeof ContentImageSchema>;\nexport type ContentFile = z.infer<typeof ContentFileSchema>;\nexport type Content = z.infer<typeof ContentSchema>;\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` 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/sdk';\n *\n * export default defineCodeGrader(async ({ input, criteria, output }) => {\n * const target = createTargetClient();\n * const question = input\n * .filter((message) => message.role === 'user')\n * .map((message) => typeof message.content === 'string' ? message.content : '')\n * .join('\\n');\n *\n * if (!target) {\n * // Target not available - no target config on this evaluator\n * return { score: 0.5, assertions: [{ text: 'Target not available', passed: false }] };\n * }\n *\n * const response = await target.invoke({\n * question: `Is this answer correct? Question: ${question}, Expected: ${criteria}, Answer: ${output ?? ''}`,\n * systemPrompt: 'You are an expert grader. 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} from './schemas.js';\n\n/**\n * Context provided to assertion handlers.\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 snake_case aliases (still accepted)\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 score\n * ```ts\n * { pass: true, assertions: [{ text: 'Output contains expected keywords', passed: true }] }\n * ```\n *\n * @example Fail with evidence\n * ```ts\n * { pass: false, score: 0.3, assertions: [{ text: 'Missing required header', passed: false }] }\n * ```\n *\n * @example Granular score (0-1)\n * ```ts\n * { score: 0.75, assertions: [\n * { text: 'Format correct', passed: true },\n * { text: 'Content relevant', passed: true },\n * { text: 'Missing citation', passed: false },\n * ] }\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 /** Per-assertion verdicts with optional evidence. */\n readonly assertions?: readonly {\n readonly text: string;\n readonly passed: boolean;\n readonly evidence?: string;\n }[];\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 assertions: result.assertions ? [...result.assertions] : [],\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 — no-op pass-through\n enrichInput(input);\n\n // Run handler\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 assertions: [{ text: `Assertion failed: ${errorMessage}`, passed: false }],\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 * Input enrichment utilities for code grader and assertion runtimes.\n *\n * With the removal of text convenience accessors (`inputText`, `outputText`,\n * `expectedOutputText`) from CodeGraderInput, this module is a no-op pass-through.\n * Kept for backward compatibility — existing runtimes call `enrichInput()` and\n * the call is harmless.\n */\nimport type { CodeGraderInput } from './schemas.js';\n\n/**\n * Enrich a validated CodeGraderInput.\n *\n * Previously populated text convenience accessors; now a no-op pass-through since\n * those fields were removed. Code graders should extract text from `Message.content`\n * using `getTextContent()` from `@agentv/core` instead.\n */\nexport function enrichInput(input: CodeGraderInput): CodeGraderInput {\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 CodeGraderInput, 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: CodeGraderInput) => 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 — no-op pass-through\n enrichInput(input);\n\n // 6. 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, type CodeGraderInput } from '@agentv/sdk';\n *\n * export default definePromptTemplate((ctx: CodeGraderInput) => {\n * const question = ctx.input\n * .filter((message) => message.role === 'user')\n * .map((message) => typeof message.content === 'string' ? message.content : '')\n * .join('\\n');\n * const answer = ctx.output ?? '';\n * return `Question: ${question}\\nAnswer: ${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 { enrichInput } from './deprecation.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. Enrich input — no-op pass-through\n enrichInput(input);\n\n // 7. Run handler\n const rawResult = await handler(input);\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 assertions: [{ text: `Evaluation failed: ${errorMessage}`, passed: false }],\n };\n console.log(JSON.stringify(errorResult, null, 2));\n process.exit(1);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACsBA,iBAAkB;AAKX,IAAM,mBAAmB,aAAE,OAAO;AAAA,EACvC,OAAO,aAAE,OAAO;AAAA,EAChB,QAAQ,aAAE,OAAO;AAAA,EACjB,QAAQ,aAAE,OAAO,EAAE,SAAS;AAAA,EAC5B,WAAW,aAAE,OAAO,EAAE,SAAS;AACjC,CAAC;AAQM,IAAM,qBAAqB,aAAE,OAAO;AAAA,EACzC,YAAY,aAAE,OAAO;AAAA,EACrB,WAAW,aAAE,OAAO,aAAE,OAAO,GAAG,aAAE,OAAO,CAAC;AAAA,EAC1C,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;AAEM,IAAM,qBAAqB;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEO,IAAM,oBAAoB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,E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AK;AAGjB,UAAM,YAAY,MAAM,QAAQ,KAAK;AAGrC,UAAM,SAAS,uBAAuB,MAAM;AAAA,MAC1C,GAAG;AAAA,MACH,OAAOC,YAAW,UAAU,KAAK;AAAA,IACnC,CAAC;AAGD,YAAQ,IAAI,KAAK,UAAU,QAAQ,MAAM,CAAC,CAAC;AAAA,EAC7C,SAAS,OAAO;AAEd,UAAM,eAAeC,aAAY,KAAK;AACtC,UAAM,cAAgC;AAAA,MACpC,OAAO;AAAA,MACP,YAAY,CAAC,EAAE,MAAM,sBAAsB,YAAY,IAAI,QAAQ,MAAM,CAAC;AAAA,IAC5E;AACA,YAAQ,IAAI,KAAK,UAAU,aAAa,MAAM,CAAC,CAAC;AAChD,YAAQ,KAAK,CAAC;AAAA,EAChB;AACF;;;AP2DO,SAAS,iBAAiB,SAAkC;AAEjE,gBAAc,OAAO;AACvB;AA4BO,SAAS,qBAAqB,SAAsC;AAEzE,oBAAkB,OAAO;AAC3B;AAkDO,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/eval.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 graders 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/sdk';\n *\n * export default defineAssertion(({ output, criteria }) => {\n * const answer = output ?? '';\n * return {\n * pass: answer.includes('hello'),\n * assertions: [{ text: 'Checks greeting', passed: answer.includes('hello') }],\n * };\n * }));\n * ```\n *\n * @example Code grader (full control)\n * ```typescript\n * #!/usr/bin/env bun\n * import { defineCodeGrader } from '@agentv/sdk';\n *\n * export default defineCodeGrader(({ output, traceSummary }) => {\n * return {\n * score: (output ?? '').length > 0 && (traceSummary?.eventCount ?? 0) <= 5 ? 1.0 : 0.5,\n * assertions: [\n * { text: 'Answer is not empty', passed: (output ?? '').length > 0 },\n * { text: 'Efficient tool usage', passed: (traceSummary?.eventCount ?? 0) <= 5 },\n * ],\n * };\n * }));\n * ```\n *\n * @packageDocumentation\n */\n\n// Re-export schemas and types\nexport {\n CodeGraderInputSchema,\n CodeGraderResultSchema,\n TRACE_REDACTION_LEVELS,\n TRACE_SOURCE_KINDS,\n TRACE_EVENT_TYPES,\n TRACE_TOOL_STATUSES,\n TraceSummarySchema,\n TraceSchema,\n TraceArtifactSchema,\n TraceRawEvidenceSchema,\n TraceRedactionStateSchema,\n TraceBranchSchema,\n TraceErrorSchema,\n TraceEventSchema,\n TraceMessageSchema,\n TraceModelSchema,\n TraceSessionSchema,\n TraceSourceRefSchema,\n TraceSourceSchema,\n TraceToolSchema,\n MessageSchema,\n ToolCallSchema,\n TokenUsageSchema,\n PromptTemplateInputSchema,\n ContentTextSchema,\n ContentImageSchema,\n ContentFileSchema,\n ContentSchema,\n type CodeGraderInput,\n type CodeGraderResult,\n type TraceArtifact,\n type TraceRawEvidence,\n type TraceRedactionState,\n type TraceBranch,\n type TraceError,\n type TraceEvent,\n type TraceMessage,\n type TraceModel,\n type TraceSession,\n type TraceSource,\n type TraceSourceRef,\n type TraceTool,\n type TraceSummary,\n type Trace,\n type Message,\n type ToolCall,\n type TokenUsage,\n type PromptTemplateInput,\n type ContentText,\n type ContentImage,\n type ContentFile,\n type Content,\n} from './schemas.js';\n\n// Re-export YAML-aligned eval authoring helpers\nexport {\n defineEval,\n evalSuite,\n serializeEvalYaml,\n toEvalYamlObject,\n type DefinedEvalSuite,\n type EvalAssertionConfig,\n type EvalDefinition,\n type EvalDockerWorkspace,\n type EvalExecution,\n type EvalMessage,\n type EvalMessageContent,\n type EvalPreprocessor,\n type EvalRequires,\n type EvalTargetRef,\n type EvalTest,\n type EvalTrials,\n type EvalTurn,\n type EvalWorkspace,\n type EvalWorkspaceHook,\n type EvalWorkspaceHooks,\n type EvalWorkspaceRepo,\n type LowerEvalYamlValue,\n} from './eval.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, runCodeGrader } from './runtime.js';\n\nexport type { CodeGraderHandler };\nexport type { PromptTemplateHandler };\n\n/**\n * Define a code grader 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/sdk';\n *\n * export default defineCodeGrader(({ trace }) => {\n * if (!trace) {\n * return { score: 0.5, assertions: [{ text: 'No trace available', passed: false }] };\n * }\n *\n * const efficient = trace.eventCount <= 10;\n * return {\n * score: efficient ? 1.0 : 0.5,\n * assertions: [{ text: efficient ? 'Efficient execution' : 'Too many tool calls', passed: efficient }],\n * };\n * });\n * ```\n *\n * @example With typed config\n * ```typescript\n * import { defineCodeGrader, z } from '@agentv/sdk';\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/**\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/sdk';\n *\n * export default definePromptTemplate((ctx) => {\n * const question = ctx.input\n * .filter((message) => message.role === 'user')\n * .map((message) => typeof message.content === 'string' ? message.content : '')\n * .join('\\n');\n * const answer = ctx.output ?? '';\n * return `Question: ${question}\\nAnswer: ${answer}`;\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 grader 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/sdk';\n *\n * export default defineAssertion(({ output }) => {\n * const text = output ?? '';\n * return {\n * pass: text.toLowerCase().includes('hello'),\n * assertions: [{ text: 'Checks for greeting', passed: text.toLowerCase().includes('hello') }],\n * };\n * }));\n * ```\n *\n * @example Granular scoring\n * ```typescript\n * import { defineAssertion } from '@agentv/sdk';\n *\n * export default defineAssertion(({ output, traceSummary }) => {\n * const text = output ?? '';\n * const hasContent = text.length > 0 ? 0.5 : 0;\n * const isEfficient = (traceSummary?.eventCount ?? 0) <= 5 ? 0.5 : 0;\n * return {\n * score: hasContent + isEfficient,\n * assertions: [\n * { text: 'Has content', passed: !!hasContent },\n * { text: 'Efficient', passed: !!isEfficient },\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 *\n * ## Content model\n *\n * `Message.content` accepts `string | object[] | object`:\n * - `string` — backward-compatible plain text (most common case)\n * - `object[]` — typed content blocks for multimodal messages, plus AgentV\n * eval input blocks such as `{ type: \"file\", value, path, text }`\n * - `object` — structured YAML/JSON content such as expected outputs\n *\n * Content variants:\n * - `ContentText` — `{ type: 'text', text: string }`\n * - `ContentImage` — `{ type: 'image', media_type: string, path: string }` (file path, not base64)\n * - `ContentFile` — `{ type: 'file', media_type: string, path: string }`\n *\n * To add a new content variant:\n * 1. Define a new Zod schema with a unique `type` literal\n * 2. Add it to `ContentSchema` discriminated union\n * 3. Re-export from `index.ts`\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 reasoning: z.number().optional(),\n});\n\n/**\n * Derived trace summary schema (camelCase for TypeScript ergonomics).\n *\n * This is a compact read model for metric-style graders. Full transcript/tool\n * evidence lives in the canonical `Trace` under `messages` and `events`.\n */\nexport const TraceSummarySchema = z.object({\n eventCount: z.number(),\n toolCalls: 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\nexport const TRACE_SOURCE_KINDS = [\n 'agentv_run',\n 'otlp',\n 'phoenix',\n 'langfuse',\n 'pi_session',\n 'imported_transcript',\n 'compact_transcript',\n] as const;\n\nexport const TRACE_EVENT_TYPES = [\n 'message',\n 'model_turn',\n 'tool_call',\n 'tool_result',\n 'final_response',\n 'error',\n] as const;\n\nexport const TRACE_TOOL_STATUSES = ['ok', 'error', 'timeout', 'cancelled', 'unknown'] as const;\n\nexport const TRACE_REDACTION_LEVELS = ['none', 'partial', 'full'] as const;\n\nconst MetadataSchema = z.record(z.string(), z.unknown());\n\nexport const TraceRedactionStateSchema = z.object({\n level: z.enum(TRACE_REDACTION_LEVELS),\n fields: z.array(z.string()).optional(),\n reason: z.string().optional(),\n});\n\nexport const TraceErrorSchema = z.object({\n message: z.string(),\n name: z.string().optional(),\n code: z.string().optional(),\n stack: z.string().optional(),\n metadata: MetadataSchema.optional(),\n});\n\nexport const TraceSourceSchema = z.object({\n kind: z.enum(TRACE_SOURCE_KINDS),\n path: z.string().optional(),\n url: z.string().optional(),\n provider: z.string().optional(),\n format: z.string().optional(),\n version: z.string().optional(),\n metadata: MetadataSchema.optional(),\n});\n\nexport const TraceSessionSchema = z.object({\n sessionId: z.string().optional(),\n conversationId: z.string().optional(),\n cwd: z.string().optional(),\n startedAt: z.string().optional(),\n endedAt: z.string().optional(),\n metadata: MetadataSchema.optional(),\n});\n\nexport const TraceBranchSchema = z.object({\n selectedLeafId: z.string().optional(),\n selectedPathIds: z.array(z.string()).optional(),\n includedEventIds: z.array(z.string()).optional(),\n omittedEventIds: z.array(z.string()).optional(),\n selectionReason: z.string().optional(),\n});\n\nexport const TraceSourceRefSchema = z.object({\n eventId: z.string().optional(),\n messageId: z.string().optional(),\n spanId: z.string().optional(),\n traceId: z.string().optional(),\n rawKind: z.string().optional(),\n path: z.string().optional(),\n line: z.number().int().nonnegative().optional(),\n metadata: MetadataSchema.optional(),\n});\n\nexport const TraceRawEvidenceSchema = z.object({\n kind: z.string(),\n ref: z.string().optional(),\n mediaType: z.string().optional(),\n content: z.unknown().optional(),\n redacted: z.boolean().optional(),\n metadata: MetadataSchema.optional(),\n});\n\nexport const TraceMessageSchema = z.object({\n role: z.string(),\n name: z.string().optional(),\n content: z.unknown().optional(),\n redaction: TraceRedactionStateSchema.optional(),\n tokenUsage: TokenUsageSchema.optional(),\n metadata: MetadataSchema.optional(),\n});\n\nexport const TraceModelSchema = z.object({\n provider: z.string().optional(),\n name: z.string().optional(),\n invocationId: z.string().optional(),\n tokenUsage: TokenUsageSchema.optional(),\n metadata: MetadataSchema.optional(),\n});\n\nexport const TraceToolSchema = z.object({\n name: z.string(),\n callId: z.string().optional(),\n input: z.unknown().optional(),\n output: z.unknown().optional(),\n status: z.enum(TRACE_TOOL_STATUSES).optional(),\n error: TraceErrorSchema.optional(),\n redaction: TraceRedactionStateSchema.optional(),\n metadata: MetadataSchema.optional(),\n});\n\nexport const TraceEventSchema = z.object({\n eventId: z.string(),\n parentEventId: z.string().optional(),\n ordinal: z.number().int().nonnegative(),\n type: z.enum(TRACE_EVENT_TYPES),\n timestamp: z.string().optional(),\n durationMs: z.number().nonnegative().optional(),\n durationInferred: z.boolean().optional(),\n turnIndex: z.number().int().nonnegative().optional(),\n message: TraceMessageSchema.optional(),\n model: TraceModelSchema.optional(),\n tool: TraceToolSchema.optional(),\n error: TraceErrorSchema.optional(),\n sourceRef: TraceSourceRefSchema.optional(),\n rawEvidence: z.array(TraceRawEvidenceSchema).optional(),\n redaction: TraceRedactionStateSchema.optional(),\n metadata: MetadataSchema.optional(),\n});\n\n/**\n * Derived trace artifact shape used by import/replay helpers.\n *\n * This is not a persisted public trace contract. Grader authors normally\n * receive the result-local `Trace` shape below.\n */\nexport const TraceArtifactSchema = z.object({\n source: TraceSourceSchema,\n session: TraceSessionSchema,\n branch: TraceBranchSchema.optional(),\n events: z.array(TraceEventSchema),\n tokenUsage: TokenUsageSchema.optional(),\n costUsd: z.number().optional(),\n durationMs: z.number().optional(),\n startedAt: z.string().optional(),\n endedAt: z.string().optional(),\n metadata: MetadataSchema.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// Content block schemas (discriminated union on `type`)\n// ---------------------------------------------------------------------------\n\n/** Text content block. */\nexport const ContentTextSchema = z.object({\n type: z.literal('text'),\n text: z.string(),\n});\n\n/**\n * Image content block.\n * `path` is a filesystem path — never inline base64.\n */\nexport const ContentImageSchema = z.object({\n type: z.literal('image'),\n media_type: z.string(),\n path: z.string(),\n});\n\n/** File content block. */\nexport const ContentFileSchema = z.object({\n type: z.literal('file'),\n media_type: z.string(),\n path: z.string(),\n});\n\n/** Discriminated union of all content block types. */\nexport const ContentSchema = z.discriminatedUnion('type', [\n ContentTextSchema,\n ContentImageSchema,\n ContentFileSchema,\n]);\n\nconst MessageContentBlockSchema = z.union([ContentSchema, z.record(z.unknown())]);\n\n/**\n * Unified message schema for input, expected, and output messages.\n *\n * `content` is a plain string, an array of structured blocks, or a\n * structured object from YAML/JSON eval files. Use `getTextContent()` from\n * `@agentv/core` to extract plain text when the content is textual.\n */\nexport const MessageSchema = z.object({\n role: z.enum(['assistant', 'user', 'system', 'tool']),\n content: z\n .union([z.string(), z.array(MessageContentBlockSchema), z.record(z.unknown())])\n .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 * Derived evaluation trace read model exposed to custom graders.\n *\n * Top-level summary fields (`eventCount`, `toolCalls`, `errorCount`) remain\n * available for existing metric graders; full transcript/tool evidence is under\n * `messages` and structured execution events under `events`.\n */\nexport const TraceSchema = TraceSummarySchema.extend({\n messages: z.array(MessageSchema),\n events: z.array(TraceEventSchema),\n tokenUsage: TokenUsageSchema.optional(),\n costUsd: z.number().optional(),\n durationMs: z.number().optional(),\n startTime: z.string().optional(),\n endTime: z.string().optional(),\n metadata: MetadataSchema.optional(),\n});\n\n/**\n * Code grader input schema (camelCase, converted from snake_case wire format).\n *\n * `output` is the final answer/scored result only. Transcript-aware graders\n * should inspect `messages`, `trace.messages`, or `trace.events`.\n */\nexport const CodeGraderInputSchema = z.object({\n criteria: z.string(),\n expectedOutput: z.array(MessageSchema),\n output: z.string().nullable().optional(),\n messages: z.array(MessageSchema).optional().default([]),\n /** Path to a temp file containing the output JSON (used for large payloads). */\n outputPath: z.string().optional(),\n inputFiles: z.array(z.string()),\n input: z.array(MessageSchema),\n metadata: z.record(z.unknown()).nullable().optional(),\n trace: TraceSchema.nullable().optional(),\n traceSummary: 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 assertions: z\n .array(\n z.object({\n text: z.string(),\n passed: z.boolean(),\n evidence: z.string().optional(),\n }),\n )\n .optional()\n .default([]),\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\nexport type TraceSummary = z.infer<typeof TraceSummarySchema>;\nexport type Trace = z.infer<typeof TraceSchema>;\nexport type TraceArtifact = z.infer<typeof TraceArtifactSchema>;\nexport type TraceSource = z.infer<typeof TraceSourceSchema>;\nexport type TraceSession = z.infer<typeof TraceSessionSchema>;\nexport type TraceBranch = z.infer<typeof TraceBranchSchema>;\nexport type TraceEvent = z.infer<typeof TraceEventSchema>;\nexport type TraceMessage = z.infer<typeof TraceMessageSchema>;\nexport type TraceModel = z.infer<typeof TraceModelSchema>;\nexport type TraceTool = z.infer<typeof TraceToolSchema>;\nexport type TraceError = z.infer<typeof TraceErrorSchema>;\nexport type TraceSourceRef = z.infer<typeof TraceSourceRefSchema>;\nexport type TraceRawEvidence = z.infer<typeof TraceRawEvidenceSchema>;\nexport type TraceRedactionState = z.infer<typeof TraceRedactionStateSchema>;\nexport type Message = z.infer<typeof MessageSchema>;\nexport type ToolCall = z.infer<typeof ToolCallSchema>;\nexport type TokenUsage = z.infer<typeof TokenUsageSchema>;\n\nexport type ContentText = z.infer<typeof ContentTextSchema>;\nexport type ContentImage = z.infer<typeof ContentImageSchema>;\nexport type ContentFile = z.infer<typeof ContentFileSchema>;\nexport type Content = z.infer<typeof ContentSchema>;\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","import { stringify as stringifyYaml } from 'yaml';\n\nconst EVAL_SUITE_SYMBOL = Symbol.for('@agentv/sdk/eval-suite');\nconst TO_EVAL_YAML_OBJECT_SYMBOL = Symbol.for('@agentv/sdk/to-eval-yaml-object');\n\nconst KNOWN_SNAKE_CASE_KEYS = {\n afterAll: 'after_all',\n afterEach: 'after_each',\n argsMatch: 'args_match',\n baseCommit: 'base_commit',\n beforeAll: 'before_all',\n beforeEach: 'before_each',\n budgetUsd: 'budget_usd',\n conversationId: 'conversation_id',\n costLimitUsd: 'cost_limit_usd',\n dependsOn: 'depends_on',\n expectedOutput: 'expected_output',\n explorationTolerance: 'exploration_tolerance',\n failOnError: 'fail_on_error',\n inputFiles: 'input_files',\n keepWorkspaces: 'keep_workspaces',\n maxCostUsd: 'max_cost_usd',\n maxDurationMs: 'max_duration_ms',\n maxInput: 'max_input',\n maxLlmCalls: 'max_llm_calls',\n maxOutput: 'max_output',\n maxTokens: 'max_tokens',\n maxToolCalls: 'max_tool_calls',\n minScore: 'min_score',\n onDependencyFailure: 'on_dependency_failure',\n onTurnFailure: 'on_turn_failure',\n outputPath: 'output_path',\n scoreRanges: 'score_ranges',\n skipDefaults: 'skip_defaults',\n targetExplorationRatio: 'target_exploration_ratio',\n timeoutMs: 'timeout_ms',\n useTarget: 'use_target',\n windowSize: 'window_size',\n} as const;\n\ntype KnownSnakeCaseKeyMap = typeof KNOWN_SNAKE_CASE_KEYS;\n\ntype LowerEvalKey<Key extends string> = Key extends keyof KnownSnakeCaseKeyMap\n ? KnownSnakeCaseKeyMap[Key]\n : Key;\n\nexport type LowerEvalYamlValue<Value> = Value extends readonly (infer Item)[]\n ? LowerEvalYamlValue<Item>[]\n : Value extends object\n ? {\n [Key in keyof Value as Key extends string ? LowerEvalKey<Key> : never]: LowerEvalYamlValue<\n Value[Key]\n >;\n }\n : Value;\n\nexport type EvalMessageContent =\n | string\n | Readonly<Record<string, unknown>>\n | readonly (string | Readonly<Record<string, unknown>>)[];\n\nexport interface EvalMessage {\n readonly role: 'system' | 'user' | 'assistant' | 'tool';\n readonly content: EvalMessageContent;\n readonly [key: string]: unknown;\n}\n\nexport interface EvalAssertionConfig {\n readonly type: string;\n readonly [key: string]: unknown;\n}\n\nexport interface EvalPreprocessor {\n readonly type: string;\n readonly command: string | readonly string[];\n readonly [key: string]: unknown;\n}\n\nexport interface EvalWorkspaceHook {\n readonly command?: string | readonly string[];\n readonly script?: string | readonly string[];\n readonly timeoutMs?: number;\n readonly cwd?: string;\n readonly reset?: 'none' | 'fast' | 'strict';\n readonly [key: string]: unknown;\n}\n\nexport interface EvalWorkspaceHooks {\n readonly enabled?: boolean;\n readonly beforeAll?: EvalWorkspaceHook;\n readonly beforeEach?: EvalWorkspaceHook;\n readonly afterEach?: EvalWorkspaceHook;\n readonly afterAll?: EvalWorkspaceHook;\n}\n\nexport interface EvalWorkspaceRepo {\n readonly path?: string;\n readonly repo?: string;\n readonly commit?: string;\n readonly baseCommit?: string;\n readonly ancestor?: number;\n readonly sparse?: readonly string[];\n}\n\nexport interface EvalDockerWorkspace {\n readonly image: string;\n readonly timeout?: number;\n readonly memory?: string;\n readonly cpus?: number;\n}\n\nexport interface EvalWorkspace {\n readonly template?: string;\n readonly isolation?: 'shared' | 'per_test';\n readonly repos?: readonly EvalWorkspaceRepo[];\n readonly hooks?: EvalWorkspaceHooks;\n readonly mode?: 'pooled' | 'temp' | 'static';\n readonly path?: string;\n readonly docker?: EvalDockerWorkspace;\n}\n\nexport interface EvalTargetRef {\n readonly name: string;\n readonly useTarget?: string;\n readonly hooks?: EvalWorkspaceHooks;\n}\n\nexport interface EvalTrials {\n readonly count: number;\n readonly strategy?: 'pass_at_k' | 'mean' | 'confidence_interval';\n readonly costLimitUsd?: number;\n}\n\nexport interface EvalExecution {\n readonly target?: string;\n readonly targets?: readonly (string | EvalTargetRef)[];\n readonly workers?: number;\n readonly assertions?: readonly EvalAssertionConfig[];\n readonly skipDefaults?: boolean;\n readonly cache?: boolean;\n readonly trials?: EvalTrials;\n readonly budgetUsd?: number;\n readonly failOnError?: boolean;\n readonly threshold?: number;\n readonly [key: string]: unknown;\n}\n\nexport interface EvalTurn {\n readonly input: EvalMessageContent;\n readonly expectedOutput?: EvalMessageContent;\n readonly assertions?: readonly (string | EvalAssertionConfig)[];\n}\n\nexport interface EvalTest {\n readonly id: string;\n readonly vars?: Readonly<Record<string, unknown>>;\n readonly criteria?: string;\n readonly input?: string | readonly EvalMessage[];\n readonly inputFiles?: readonly string[];\n readonly expectedOutput?: string | Readonly<Record<string, unknown>> | readonly EvalMessage[];\n readonly assertions?: readonly EvalAssertionConfig[];\n readonly execution?: EvalExecution;\n readonly workspace?: EvalWorkspace;\n readonly metadata?: Readonly<Record<string, unknown>>;\n readonly conversationId?: string;\n readonly suite?: string;\n readonly dependsOn?: readonly string[];\n readonly onDependencyFailure?: 'skip' | 'fail' | 'run';\n readonly mode?: 'conversation';\n readonly turns?: readonly EvalTurn[];\n readonly aggregation?: 'mean' | 'min' | 'max';\n readonly onTurnFailure?: 'continue' | 'stop';\n readonly windowSize?: number;\n}\n\nexport interface EvalRequires {\n readonly agentv?: string;\n readonly [key: string]: unknown;\n}\n\nexport interface EvalDefinition {\n readonly $schema?: string;\n readonly name?: string;\n readonly description?: string;\n readonly category?: string;\n readonly version?: string;\n readonly author?: string;\n readonly tags?: readonly string[];\n readonly license?: string;\n readonly requires?: EvalRequires;\n readonly input?: string | readonly EvalMessage[];\n readonly inputFiles?: readonly string[];\n readonly tests: readonly EvalTest[] | string;\n readonly target?: string;\n readonly execution?: EvalExecution;\n readonly assertions?: readonly EvalAssertionConfig[];\n readonly preprocessors?: readonly EvalPreprocessor[];\n readonly workspace?: EvalWorkspace | string;\n}\n\nexport interface DefinedEvalSuite {\n readonly [EVAL_SUITE_SYMBOL]: true;\n readonly [TO_EVAL_YAML_OBJECT_SYMBOL]: () => Record<string, unknown>;\n}\n\nfunction lowerEvalYamlValue(value: unknown): unknown {\n if (Array.isArray(value)) {\n return value.map((item) => lowerEvalYamlValue(item));\n }\n\n if (value && typeof value === 'object') {\n const result: Record<string, unknown> = {};\n for (const [key, nestedValue] of Object.entries(value)) {\n const loweredKey = KNOWN_SNAKE_CASE_KEYS[key as keyof KnownSnakeCaseKeyMap] ?? key;\n result[loweredKey] = lowerEvalYamlValue(nestedValue);\n }\n return result;\n }\n\n return value;\n}\n\nfunction attachEvalSuiteBrand<T extends EvalDefinition>(definition: T): T & DefinedEvalSuite {\n const branded = definition as T & Partial<DefinedEvalSuite>;\n\n if (branded[EVAL_SUITE_SYMBOL] === true) {\n return branded as T & DefinedEvalSuite;\n }\n\n Object.defineProperties(branded, {\n [EVAL_SUITE_SYMBOL]: {\n value: true,\n enumerable: false,\n configurable: false,\n writable: false,\n },\n [TO_EVAL_YAML_OBJECT_SYMBOL]: {\n value: () => toEvalYamlObject(definition),\n enumerable: false,\n configurable: false,\n writable: false,\n },\n });\n\n return branded as T & DefinedEvalSuite;\n}\n\n/**\n * Define a YAML-aligned eval suite in TypeScript.\n *\n * The returned object preserves the TypeScript authoring shape and carries a\n * non-enumerable lowering hook so AgentV can materialize the canonical\n * snake_case eval contract when the suite is loaded from a `.eval.ts` file.\n */\nexport function defineEval<T extends EvalDefinition>(definition: T): T & DefinedEvalSuite {\n return attachEvalSuiteBrand(definition);\n}\n\n/**\n * Alias for `defineEval()` when a suite reads more clearly as a plain object.\n */\nexport function evalSuite<T extends EvalDefinition>(definition: T): T & DefinedEvalSuite {\n return defineEval(definition);\n}\n\n/**\n * Lower a TypeScript-authored eval suite into the canonical snake_case object\n * contract used by YAML files and the runtime loader.\n *\n * Only known AgentV wire keys are converted. Unknown keys are preserved as-is\n * so opaque assertion, provider, and metadata payloads are not corrupted.\n */\nexport function toEvalYamlObject<T extends EvalDefinition | DefinedEvalSuite>(\n definition: T,\n): LowerEvalYamlValue<T> {\n return lowerEvalYamlValue(definition) as LowerEvalYamlValue<T>;\n}\n\n/**\n * Serialize an eval suite to canonical YAML.\n */\nexport function serializeEvalYaml<T extends EvalDefinition | DefinedEvalSuite>(\n definition: T,\n): string {\n return stringifyYaml(toEvalYamlObject(definition), { lineWidth: 0 }).trimEnd();\n}\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` 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/sdk';\n *\n * export default defineCodeGrader(async ({ input, criteria, output }) => {\n * const target = createTargetClient();\n * const question = input\n * .filter((message) => message.role === 'user')\n * .map((message) => typeof message.content === 'string' ? message.content : '')\n * .join('\\n');\n *\n * if (!target) {\n * // Target not available - no target config on this evaluator\n * return { score: 0.5, assertions: [{ text: 'Target not available', passed: false }] };\n * }\n *\n * const response = await target.invoke({\n * question: `Is this answer correct? Question: ${question}, Expected: ${criteria}, Answer: ${output ?? ''}`,\n * systemPrompt: 'You are an expert grader. 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} from './schemas.js';\n\n/**\n * Context provided to assertion handlers.\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 snake_case aliases (still accepted)\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 score\n * ```ts\n * { pass: true, assertions: [{ text: 'Output contains expected keywords', passed: true }] }\n * ```\n *\n * @example Fail with evidence\n * ```ts\n * { pass: false, score: 0.3, assertions: [{ text: 'Missing required header', passed: false }] }\n * ```\n *\n * @example Granular score (0-1)\n * ```ts\n * { score: 0.75, assertions: [\n * { text: 'Format correct', passed: true },\n * { text: 'Content relevant', passed: true },\n * { text: 'Missing citation', passed: false },\n * ] }\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 /** Per-assertion verdicts with optional evidence. */\n readonly assertions?: readonly {\n readonly text: string;\n readonly passed: boolean;\n readonly evidence?: string;\n }[];\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 assertions: result.assertions ? [...result.assertions] : [],\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 — no-op pass-through\n enrichInput(input);\n\n // Run handler\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 assertions: [{ text: `Assertion failed: ${errorMessage}`, passed: false }],\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 * Input enrichment utilities for code grader and assertion runtimes.\n *\n * With the removal of text convenience accessors (`inputText`, `outputText`,\n * `expectedOutputText`) from CodeGraderInput, this module is a no-op pass-through.\n * Kept for backward compatibility — existing runtimes call `enrichInput()` and\n * the call is harmless.\n */\nimport type { CodeGraderInput } from './schemas.js';\n\n/**\n * Enrich a validated CodeGraderInput.\n *\n * Previously populated text convenience accessors; now a no-op pass-through since\n * those fields were removed. Code graders should extract text from `Message.content`\n * using `getTextContent()` from `@agentv/core` instead.\n */\nexport function enrichInput(input: CodeGraderInput): CodeGraderInput {\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 CodeGraderInput, 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: CodeGraderInput) => 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 — no-op pass-through\n enrichInput(input);\n\n // 6. 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, type CodeGraderInput } from '@agentv/sdk';\n *\n * export default definePromptTemplate((ctx: CodeGraderInput) => {\n * const question = ctx.input\n * .filter((message) => message.role === 'user')\n * .map((message) => typeof message.content === 'string' ? message.content : '')\n * .join('\\n');\n * const answer = ctx.output ?? '';\n * return `Question: ${question}\\nAnswer: ${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 { enrichInput } from './deprecation.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. Enrich input — no-op pass-through\n enrichInput(input);\n\n // 7. Run handler\n const rawResult = await handler(input);\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 assertions: [{ text: `Evaluation failed: ${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