@agentv/sdk 4.41.3-next.1 → 4.41.4-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/dist/index.cjs ADDED
@@ -0,0 +1,623 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ CodeGraderInputSchema: () => CodeGraderInputSchema,
24
+ CodeGraderResultSchema: () => CodeGraderResultSchema,
25
+ ContentFileSchema: () => ContentFileSchema,
26
+ ContentImageSchema: () => ContentImageSchema,
27
+ ContentSchema: () => ContentSchema,
28
+ ContentTextSchema: () => ContentTextSchema,
29
+ MessageSchema: () => MessageSchema,
30
+ PromptTemplateInputSchema: () => PromptTemplateInputSchema,
31
+ TRACE_EVENT_TYPES: () => TRACE_EVENT_TYPES,
32
+ TRACE_REDACTION_LEVELS: () => TRACE_REDACTION_LEVELS,
33
+ TRACE_SOURCE_KINDS: () => TRACE_SOURCE_KINDS,
34
+ TRACE_TOOL_STATUSES: () => TRACE_TOOL_STATUSES,
35
+ TargetInvocationError: () => TargetInvocationError,
36
+ TargetNotAvailableError: () => TargetNotAvailableError,
37
+ TokenUsageSchema: () => TokenUsageSchema,
38
+ ToolCallSchema: () => ToolCallSchema,
39
+ TraceArtifactSchema: () => TraceArtifactSchema,
40
+ TraceBranchSchema: () => TraceBranchSchema,
41
+ TraceErrorSchema: () => TraceErrorSchema,
42
+ TraceEventSchema: () => TraceEventSchema,
43
+ TraceMessageSchema: () => TraceMessageSchema,
44
+ TraceModelSchema: () => TraceModelSchema,
45
+ TraceRawEvidenceSchema: () => TraceRawEvidenceSchema,
46
+ TraceRedactionStateSchema: () => TraceRedactionStateSchema,
47
+ TraceSchema: () => TraceSchema,
48
+ TraceSessionSchema: () => TraceSessionSchema,
49
+ TraceSourceRefSchema: () => TraceSourceRefSchema,
50
+ TraceSourceSchema: () => TraceSourceSchema,
51
+ TraceSummarySchema: () => TraceSummarySchema,
52
+ TraceToolSchema: () => TraceToolSchema,
53
+ createTargetClient: () => createTargetClient,
54
+ defineAssertion: () => defineAssertion,
55
+ defineCodeGrader: () => defineCodeGrader,
56
+ definePromptTemplate: () => definePromptTemplate,
57
+ z: () => import_zod2.z
58
+ });
59
+ module.exports = __toCommonJS(index_exports);
60
+
61
+ // src/schemas.ts
62
+ var import_zod = require("zod");
63
+ var TokenUsageSchema = import_zod.z.object({
64
+ input: import_zod.z.number(),
65
+ output: import_zod.z.number(),
66
+ cached: import_zod.z.number().optional(),
67
+ reasoning: import_zod.z.number().optional()
68
+ });
69
+ var TraceSummarySchema = import_zod.z.object({
70
+ eventCount: import_zod.z.number(),
71
+ toolCalls: import_zod.z.record(import_zod.z.string(), import_zod.z.number()),
72
+ errorCount: import_zod.z.number(),
73
+ toolDurations: import_zod.z.record(import_zod.z.string(), import_zod.z.array(import_zod.z.number())).optional(),
74
+ llmCallCount: import_zod.z.number().optional()
75
+ });
76
+ var TRACE_SOURCE_KINDS = [
77
+ "agentv_run",
78
+ "otlp",
79
+ "phoenix",
80
+ "langfuse",
81
+ "pi_session",
82
+ "imported_transcript",
83
+ "compact_transcript"
84
+ ];
85
+ var TRACE_EVENT_TYPES = [
86
+ "message",
87
+ "model_turn",
88
+ "tool_call",
89
+ "tool_result",
90
+ "final_response",
91
+ "error"
92
+ ];
93
+ var TRACE_TOOL_STATUSES = ["ok", "error", "timeout", "cancelled", "unknown"];
94
+ var TRACE_REDACTION_LEVELS = ["none", "partial", "full"];
95
+ var MetadataSchema = import_zod.z.record(import_zod.z.string(), import_zod.z.unknown());
96
+ var TraceRedactionStateSchema = import_zod.z.object({
97
+ level: import_zod.z.enum(TRACE_REDACTION_LEVELS),
98
+ fields: import_zod.z.array(import_zod.z.string()).optional(),
99
+ reason: import_zod.z.string().optional()
100
+ });
101
+ var TraceErrorSchema = import_zod.z.object({
102
+ message: import_zod.z.string(),
103
+ name: import_zod.z.string().optional(),
104
+ code: import_zod.z.string().optional(),
105
+ stack: import_zod.z.string().optional(),
106
+ metadata: MetadataSchema.optional()
107
+ });
108
+ var TraceSourceSchema = import_zod.z.object({
109
+ kind: import_zod.z.enum(TRACE_SOURCE_KINDS),
110
+ path: import_zod.z.string().optional(),
111
+ url: import_zod.z.string().optional(),
112
+ provider: import_zod.z.string().optional(),
113
+ format: import_zod.z.string().optional(),
114
+ version: import_zod.z.string().optional(),
115
+ metadata: MetadataSchema.optional()
116
+ });
117
+ var TraceSessionSchema = import_zod.z.object({
118
+ sessionId: import_zod.z.string().optional(),
119
+ conversationId: import_zod.z.string().optional(),
120
+ cwd: import_zod.z.string().optional(),
121
+ startedAt: import_zod.z.string().optional(),
122
+ endedAt: import_zod.z.string().optional(),
123
+ metadata: MetadataSchema.optional()
124
+ });
125
+ var TraceBranchSchema = import_zod.z.object({
126
+ selectedLeafId: import_zod.z.string().optional(),
127
+ selectedPathIds: import_zod.z.array(import_zod.z.string()).optional(),
128
+ includedEventIds: import_zod.z.array(import_zod.z.string()).optional(),
129
+ omittedEventIds: import_zod.z.array(import_zod.z.string()).optional(),
130
+ selectionReason: import_zod.z.string().optional()
131
+ });
132
+ var TraceSourceRefSchema = import_zod.z.object({
133
+ eventId: import_zod.z.string().optional(),
134
+ messageId: import_zod.z.string().optional(),
135
+ spanId: import_zod.z.string().optional(),
136
+ traceId: import_zod.z.string().optional(),
137
+ rawKind: import_zod.z.string().optional(),
138
+ path: import_zod.z.string().optional(),
139
+ line: import_zod.z.number().int().nonnegative().optional(),
140
+ metadata: MetadataSchema.optional()
141
+ });
142
+ var TraceRawEvidenceSchema = import_zod.z.object({
143
+ kind: import_zod.z.string(),
144
+ ref: import_zod.z.string().optional(),
145
+ mediaType: import_zod.z.string().optional(),
146
+ content: import_zod.z.unknown().optional(),
147
+ redacted: import_zod.z.boolean().optional(),
148
+ metadata: MetadataSchema.optional()
149
+ });
150
+ var TraceMessageSchema = import_zod.z.object({
151
+ role: import_zod.z.string(),
152
+ name: import_zod.z.string().optional(),
153
+ content: import_zod.z.unknown().optional(),
154
+ redaction: TraceRedactionStateSchema.optional(),
155
+ tokenUsage: TokenUsageSchema.optional(),
156
+ metadata: MetadataSchema.optional()
157
+ });
158
+ var TraceModelSchema = import_zod.z.object({
159
+ provider: import_zod.z.string().optional(),
160
+ name: import_zod.z.string().optional(),
161
+ invocationId: import_zod.z.string().optional(),
162
+ tokenUsage: TokenUsageSchema.optional(),
163
+ metadata: MetadataSchema.optional()
164
+ });
165
+ var TraceToolSchema = import_zod.z.object({
166
+ name: import_zod.z.string(),
167
+ callId: import_zod.z.string().optional(),
168
+ input: import_zod.z.unknown().optional(),
169
+ output: import_zod.z.unknown().optional(),
170
+ status: import_zod.z.enum(TRACE_TOOL_STATUSES).optional(),
171
+ error: TraceErrorSchema.optional(),
172
+ redaction: TraceRedactionStateSchema.optional(),
173
+ metadata: MetadataSchema.optional()
174
+ });
175
+ var TraceEventSchema = import_zod.z.object({
176
+ eventId: import_zod.z.string(),
177
+ parentEventId: import_zod.z.string().optional(),
178
+ ordinal: import_zod.z.number().int().nonnegative(),
179
+ type: import_zod.z.enum(TRACE_EVENT_TYPES),
180
+ timestamp: import_zod.z.string().optional(),
181
+ durationMs: import_zod.z.number().nonnegative().optional(),
182
+ durationInferred: import_zod.z.boolean().optional(),
183
+ turnIndex: import_zod.z.number().int().nonnegative().optional(),
184
+ message: TraceMessageSchema.optional(),
185
+ model: TraceModelSchema.optional(),
186
+ tool: TraceToolSchema.optional(),
187
+ error: TraceErrorSchema.optional(),
188
+ sourceRef: TraceSourceRefSchema.optional(),
189
+ rawEvidence: import_zod.z.array(TraceRawEvidenceSchema).optional(),
190
+ redaction: TraceRedactionStateSchema.optional(),
191
+ metadata: MetadataSchema.optional()
192
+ });
193
+ var TraceArtifactSchema = import_zod.z.object({
194
+ source: TraceSourceSchema,
195
+ session: TraceSessionSchema,
196
+ branch: TraceBranchSchema.optional(),
197
+ events: import_zod.z.array(TraceEventSchema),
198
+ tokenUsage: TokenUsageSchema.optional(),
199
+ costUsd: import_zod.z.number().optional(),
200
+ durationMs: import_zod.z.number().optional(),
201
+ startedAt: import_zod.z.string().optional(),
202
+ endedAt: import_zod.z.string().optional(),
203
+ metadata: MetadataSchema.optional()
204
+ });
205
+ var ToolCallSchema = import_zod.z.object({
206
+ tool: import_zod.z.string(),
207
+ input: import_zod.z.unknown().optional(),
208
+ output: import_zod.z.unknown().optional(),
209
+ id: import_zod.z.string().optional(),
210
+ startTime: import_zod.z.string().optional(),
211
+ endTime: import_zod.z.string().optional(),
212
+ durationMs: import_zod.z.number().optional()
213
+ });
214
+ var ContentTextSchema = import_zod.z.object({
215
+ type: import_zod.z.literal("text"),
216
+ text: import_zod.z.string()
217
+ });
218
+ var ContentImageSchema = import_zod.z.object({
219
+ type: import_zod.z.literal("image"),
220
+ media_type: import_zod.z.string(),
221
+ path: import_zod.z.string()
222
+ });
223
+ var ContentFileSchema = import_zod.z.object({
224
+ type: import_zod.z.literal("file"),
225
+ media_type: import_zod.z.string(),
226
+ path: import_zod.z.string()
227
+ });
228
+ var ContentSchema = import_zod.z.discriminatedUnion("type", [
229
+ ContentTextSchema,
230
+ ContentImageSchema,
231
+ ContentFileSchema
232
+ ]);
233
+ var MessageContentBlockSchema = import_zod.z.union([ContentSchema, import_zod.z.record(import_zod.z.unknown())]);
234
+ var MessageSchema = import_zod.z.object({
235
+ role: import_zod.z.enum(["assistant", "user", "system", "tool"]),
236
+ content: import_zod.z.union([import_zod.z.string(), import_zod.z.array(MessageContentBlockSchema), import_zod.z.record(import_zod.z.unknown())]).optional(),
237
+ toolCalls: import_zod.z.array(ToolCallSchema).optional(),
238
+ name: import_zod.z.string().optional(),
239
+ startTime: import_zod.z.string().optional(),
240
+ endTime: import_zod.z.string().optional(),
241
+ durationMs: import_zod.z.number().optional(),
242
+ metadata: import_zod.z.record(import_zod.z.unknown()).optional()
243
+ });
244
+ var TraceSchema = TraceSummarySchema.extend({
245
+ messages: import_zod.z.array(MessageSchema),
246
+ events: import_zod.z.array(TraceEventSchema),
247
+ tokenUsage: TokenUsageSchema.optional(),
248
+ costUsd: import_zod.z.number().optional(),
249
+ durationMs: import_zod.z.number().optional(),
250
+ startTime: import_zod.z.string().optional(),
251
+ endTime: import_zod.z.string().optional(),
252
+ metadata: MetadataSchema.optional()
253
+ });
254
+ var CodeGraderInputSchema = import_zod.z.object({
255
+ criteria: import_zod.z.string(),
256
+ expectedOutput: import_zod.z.array(MessageSchema),
257
+ output: import_zod.z.string().nullable().optional(),
258
+ messages: import_zod.z.array(MessageSchema).optional().default([]),
259
+ /** Path to a temp file containing the output JSON (used for large payloads). */
260
+ outputPath: import_zod.z.string().optional(),
261
+ inputFiles: import_zod.z.array(import_zod.z.string()),
262
+ input: import_zod.z.array(MessageSchema),
263
+ metadata: import_zod.z.record(import_zod.z.unknown()).nullable().optional(),
264
+ trace: TraceSchema.nullable().optional(),
265
+ traceSummary: TraceSummarySchema.nullable().optional(),
266
+ tokenUsage: TokenUsageSchema.nullable().optional(),
267
+ costUsd: import_zod.z.number().nullable().optional(),
268
+ durationMs: import_zod.z.number().nullable().optional(),
269
+ startTime: import_zod.z.string().nullable().optional(),
270
+ endTime: import_zod.z.string().nullable().optional(),
271
+ fileChanges: import_zod.z.string().nullable().optional(),
272
+ workspacePath: import_zod.z.string().nullable().optional(),
273
+ config: import_zod.z.record(import_zod.z.unknown()).nullable().optional()
274
+ });
275
+ var CodeGraderResultSchema = import_zod.z.object({
276
+ score: import_zod.z.number().min(0).max(1),
277
+ assertions: import_zod.z.array(
278
+ import_zod.z.object({
279
+ text: import_zod.z.string(),
280
+ passed: import_zod.z.boolean(),
281
+ evidence: import_zod.z.string().optional()
282
+ })
283
+ ).optional().default([]),
284
+ /** Optional structured details for domain-specific metrics (e.g., TP/TN/FP/FN counts, alignments). */
285
+ details: import_zod.z.record(import_zod.z.unknown()).optional()
286
+ });
287
+ var PromptTemplateInputSchema = CodeGraderInputSchema;
288
+
289
+ // src/target-client.ts
290
+ var TargetNotAvailableError = class extends Error {
291
+ constructor(message) {
292
+ super(message);
293
+ this.name = "TargetNotAvailableError";
294
+ }
295
+ };
296
+ var TargetInvocationError = class extends Error {
297
+ statusCode;
298
+ constructor(message, statusCode) {
299
+ super(message);
300
+ this.name = "TargetInvocationError";
301
+ this.statusCode = statusCode;
302
+ }
303
+ };
304
+ function createTargetClient() {
305
+ const proxyUrl = process.env.AGENTV_TARGET_PROXY_URL;
306
+ const proxyToken = process.env.AGENTV_TARGET_PROXY_TOKEN;
307
+ if (!proxyUrl) {
308
+ return void 0;
309
+ }
310
+ if (!proxyToken) {
311
+ throw new TargetNotAvailableError(
312
+ "AGENTV_TARGET_PROXY_URL is set but AGENTV_TARGET_PROXY_TOKEN is missing"
313
+ );
314
+ }
315
+ return createTargetClientInternal(proxyUrl, proxyToken);
316
+ }
317
+ function createTargetClientInternal(url, token) {
318
+ const headers = {
319
+ "Content-Type": "application/json",
320
+ Authorization: `Bearer ${token}`
321
+ };
322
+ return {
323
+ async invoke(request) {
324
+ const response = await fetch(`${url}/invoke`, {
325
+ method: "POST",
326
+ headers,
327
+ body: JSON.stringify({
328
+ question: request.question,
329
+ systemPrompt: request.systemPrompt,
330
+ evalCaseId: request.evalCaseId,
331
+ attempt: request.attempt,
332
+ target: request.target
333
+ })
334
+ });
335
+ if (!response.ok) {
336
+ const errorBody = await response.text();
337
+ let errorMessage;
338
+ try {
339
+ const errorJson = JSON.parse(errorBody);
340
+ errorMessage = errorJson.error ?? `HTTP ${response.status}`;
341
+ } catch {
342
+ errorMessage = errorBody || `HTTP ${response.status}`;
343
+ }
344
+ throw new TargetInvocationError(errorMessage, response.status);
345
+ }
346
+ return await response.json();
347
+ },
348
+ async invokeBatch(requests) {
349
+ const response = await fetch(`${url}/invokeBatch`, {
350
+ method: "POST",
351
+ headers,
352
+ body: JSON.stringify({
353
+ requests: requests.map((r) => ({
354
+ question: r.question,
355
+ systemPrompt: r.systemPrompt,
356
+ evalCaseId: r.evalCaseId,
357
+ attempt: r.attempt,
358
+ target: r.target
359
+ }))
360
+ })
361
+ });
362
+ if (!response.ok) {
363
+ const errorBody = await response.text();
364
+ let errorMessage;
365
+ try {
366
+ const errorJson = JSON.parse(errorBody);
367
+ errorMessage = errorJson.error ?? `HTTP ${response.status}`;
368
+ } catch {
369
+ errorMessage = errorBody || `HTTP ${response.status}`;
370
+ }
371
+ throw new TargetInvocationError(errorMessage, response.status);
372
+ }
373
+ const result = await response.json();
374
+ return result.responses;
375
+ },
376
+ async getInfo() {
377
+ const response = await fetch(`${url}/info`, {
378
+ method: "GET",
379
+ headers
380
+ });
381
+ if (!response.ok) {
382
+ const errorBody = await response.text();
383
+ let errorMessage;
384
+ try {
385
+ const errorJson = JSON.parse(errorBody);
386
+ errorMessage = errorJson.error ?? `HTTP ${response.status}`;
387
+ } catch {
388
+ errorMessage = errorBody || `HTTP ${response.status}`;
389
+ }
390
+ throw new TargetInvocationError(errorMessage, response.status);
391
+ }
392
+ return await response.json();
393
+ }
394
+ };
395
+ }
396
+
397
+ // src/index.ts
398
+ var import_zod2 = require("zod");
399
+
400
+ // src/assertion.ts
401
+ var import_node_fs = require("fs");
402
+
403
+ // src/case-conversion.ts
404
+ function toCamelCase(str) {
405
+ if (/^[A-Z]/.test(str)) {
406
+ return str;
407
+ }
408
+ return str.replace(/_([a-z0-9])/g, (_, letter) => letter.toUpperCase());
409
+ }
410
+ function toCamelCaseDeep(obj) {
411
+ if (obj === null || obj === void 0) {
412
+ return obj;
413
+ }
414
+ if (Array.isArray(obj)) {
415
+ return obj.map((item) => toCamelCaseDeep(item));
416
+ }
417
+ if (typeof obj === "object") {
418
+ const result = {};
419
+ for (const [key, value] of Object.entries(obj)) {
420
+ const camelKey = toCamelCase(key);
421
+ result[camelKey] = toCamelCaseDeep(value);
422
+ }
423
+ return result;
424
+ }
425
+ return obj;
426
+ }
427
+
428
+ // src/deprecation.ts
429
+ function enrichInput(input) {
430
+ return input;
431
+ }
432
+
433
+ // src/assertion.ts
434
+ function readStdin() {
435
+ return (0, import_node_fs.readFileSync)(0, "utf8");
436
+ }
437
+ function clampScore(value) {
438
+ if (Number.isNaN(value) || !Number.isFinite(value)) {
439
+ return 0;
440
+ }
441
+ return Math.max(0, Math.min(1, value));
442
+ }
443
+ function formatError(error) {
444
+ if (error instanceof Error) {
445
+ return error.message;
446
+ }
447
+ return String(error);
448
+ }
449
+ function normalizeScore(result) {
450
+ let score;
451
+ if (result.score !== void 0) {
452
+ score = clampScore(result.score);
453
+ } else if (result.pass !== void 0) {
454
+ score = result.pass ? 1 : 0;
455
+ } else {
456
+ score = 0;
457
+ }
458
+ return {
459
+ score,
460
+ assertions: result.assertions ? [...result.assertions] : [],
461
+ details: result.details
462
+ };
463
+ }
464
+ async function runAssertion(handler) {
465
+ try {
466
+ const stdin = readStdin();
467
+ const rawInput = JSON.parse(stdin);
468
+ const camelInput = toCamelCaseDeep(rawInput);
469
+ const input = CodeGraderInputSchema.parse(camelInput);
470
+ if (input.outputPath && (input.output === null || input.output === void 0)) {
471
+ let cachedOutput;
472
+ const filePath = input.outputPath;
473
+ Object.defineProperty(input, "output", {
474
+ get() {
475
+ if (cachedOutput === void 0) {
476
+ cachedOutput = JSON.parse((0, import_node_fs.readFileSync)(filePath, "utf8"));
477
+ }
478
+ return cachedOutput;
479
+ },
480
+ configurable: true,
481
+ enumerable: true
482
+ });
483
+ }
484
+ enrichInput(input);
485
+ const rawResult = await handler(input);
486
+ const normalized = normalizeScore(rawResult);
487
+ const result = CodeGraderResultSchema.parse(normalized);
488
+ console.log(JSON.stringify(result, null, 2));
489
+ } catch (error) {
490
+ const errorMessage = formatError(error);
491
+ const errorResult = {
492
+ score: 0,
493
+ assertions: [{ text: `Assertion failed: ${errorMessage}`, passed: false }]
494
+ };
495
+ console.log(JSON.stringify(errorResult, null, 2));
496
+ process.exit(1);
497
+ }
498
+ }
499
+
500
+ // src/prompt-template.ts
501
+ var import_node_fs2 = require("fs");
502
+ function readStdin2() {
503
+ return (0, import_node_fs2.readFileSync)(0, "utf8");
504
+ }
505
+ async function runPromptTemplate(handler) {
506
+ try {
507
+ const stdin = readStdin2();
508
+ const rawInput = JSON.parse(stdin);
509
+ const camelInput = toCamelCaseDeep(rawInput);
510
+ const input = PromptTemplateInputSchema.parse(camelInput);
511
+ enrichInput(input);
512
+ const prompt = await handler(input);
513
+ console.log(prompt);
514
+ } catch (error) {
515
+ console.error(error instanceof Error ? error.message : String(error));
516
+ process.exit(1);
517
+ }
518
+ }
519
+
520
+ // src/runtime.ts
521
+ var import_node_fs3 = require("fs");
522
+ function readStdin3() {
523
+ return (0, import_node_fs3.readFileSync)(0, "utf8");
524
+ }
525
+ function clampScore2(value) {
526
+ if (Number.isNaN(value) || !Number.isFinite(value)) {
527
+ return 0;
528
+ }
529
+ return Math.max(0, Math.min(1, value));
530
+ }
531
+ function formatError2(error) {
532
+ if (error instanceof Error) {
533
+ return error.message;
534
+ }
535
+ return String(error);
536
+ }
537
+ async function runCodeGrader(handler) {
538
+ try {
539
+ const stdin = readStdin3();
540
+ const rawInput = JSON.parse(stdin);
541
+ const camelInput = toCamelCaseDeep(rawInput);
542
+ const input = CodeGraderInputSchema.parse(camelInput);
543
+ if (input.outputPath && (input.output === null || input.output === void 0)) {
544
+ let cachedOutput;
545
+ const filePath = input.outputPath;
546
+ Object.defineProperty(input, "output", {
547
+ get() {
548
+ if (cachedOutput === void 0) {
549
+ cachedOutput = JSON.parse((0, import_node_fs3.readFileSync)(filePath, "utf8"));
550
+ }
551
+ return cachedOutput;
552
+ },
553
+ configurable: true,
554
+ enumerable: true
555
+ });
556
+ }
557
+ enrichInput(input);
558
+ const rawResult = await handler(input);
559
+ const result = CodeGraderResultSchema.parse({
560
+ ...rawResult,
561
+ score: clampScore2(rawResult.score)
562
+ });
563
+ console.log(JSON.stringify(result, null, 2));
564
+ } catch (error) {
565
+ const errorMessage = formatError2(error);
566
+ const errorResult = {
567
+ score: 0,
568
+ assertions: [{ text: `Evaluation failed: ${errorMessage}`, passed: false }]
569
+ };
570
+ console.log(JSON.stringify(errorResult, null, 2));
571
+ process.exit(1);
572
+ }
573
+ }
574
+
575
+ // src/index.ts
576
+ function defineCodeGrader(handler) {
577
+ runCodeGrader(handler);
578
+ }
579
+ function definePromptTemplate(handler) {
580
+ runPromptTemplate(handler);
581
+ }
582
+ function defineAssertion(handler) {
583
+ runAssertion(handler);
584
+ }
585
+ // Annotate the CommonJS export names for ESM import in node:
586
+ 0 && (module.exports = {
587
+ CodeGraderInputSchema,
588
+ CodeGraderResultSchema,
589
+ ContentFileSchema,
590
+ ContentImageSchema,
591
+ ContentSchema,
592
+ ContentTextSchema,
593
+ MessageSchema,
594
+ PromptTemplateInputSchema,
595
+ TRACE_EVENT_TYPES,
596
+ TRACE_REDACTION_LEVELS,
597
+ TRACE_SOURCE_KINDS,
598
+ TRACE_TOOL_STATUSES,
599
+ TargetInvocationError,
600
+ TargetNotAvailableError,
601
+ TokenUsageSchema,
602
+ ToolCallSchema,
603
+ TraceArtifactSchema,
604
+ TraceBranchSchema,
605
+ TraceErrorSchema,
606
+ TraceEventSchema,
607
+ TraceMessageSchema,
608
+ TraceModelSchema,
609
+ TraceRawEvidenceSchema,
610
+ TraceRedactionStateSchema,
611
+ TraceSchema,
612
+ TraceSessionSchema,
613
+ TraceSourceRefSchema,
614
+ TraceSourceSchema,
615
+ TraceSummarySchema,
616
+ TraceToolSchema,
617
+ createTargetClient,
618
+ defineAssertion,
619
+ defineCodeGrader,
620
+ definePromptTemplate,
621
+ z
622
+ });
623
+ //# sourceMappingURL=index.cjs.map