@anvia/core 0.24.0 → 0.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  import { Z as ZodSchema } from '../zod-schema-C7F4clpm.js';
2
- import { l as JsonValue, C as CompletionModel, M as Message } from '../types-G12i56s2.js';
2
+ import { U as Usage, l as JsonValue, C as CompletionModel, M as Message } from '../types-G12i56s2.js';
3
3
  import { A as Agent } from '../agent-x3YTyv5i.js';
4
4
  import { P as PromptResponse } from '../index-BxSbmOMr.js';
5
5
  import { E as EmbeddingModel } from '../types-BCTRUGex.js';
@@ -16,31 +16,37 @@ type EvalOutcome<Score = unknown> = {
16
16
  score?: Score | undefined;
17
17
  comment?: string | undefined;
18
18
  metadata?: EvalMetadata | undefined;
19
+ usage?: Usage | undefined;
19
20
  } | {
20
21
  outcome: "fail";
21
22
  score?: Score | undefined;
22
23
  comment?: string | undefined;
23
24
  metadata?: EvalMetadata | undefined;
25
+ usage?: Usage | undefined;
24
26
  } | {
25
27
  outcome: "invalid";
26
28
  reason: string;
27
29
  score?: Score | undefined;
28
30
  comment?: string | undefined;
29
31
  metadata?: EvalMetadata | undefined;
32
+ usage?: Usage | undefined;
30
33
  };
31
34
  declare const EvalOutcome: {
32
35
  pass<Score>(score?: Score, options?: {
33
36
  comment?: string | undefined;
34
37
  metadata?: EvalMetadata | undefined;
38
+ usage?: Usage | undefined;
35
39
  }): EvalOutcome<Score>;
36
40
  fail<Score>(score?: Score, options?: {
37
41
  comment?: string | undefined;
38
42
  metadata?: EvalMetadata | undefined;
43
+ usage?: Usage | undefined;
39
44
  }): EvalOutcome<Score>;
40
45
  invalid<Score = never>(reason: string, options?: {
41
46
  score?: Score | undefined;
42
47
  comment?: string | undefined;
43
48
  metadata?: EvalMetadata | undefined;
49
+ usage?: Usage | undefined;
44
50
  }): EvalOutcome<Score>;
45
51
  };
46
52
 
@@ -78,6 +84,36 @@ type EvalTraceRef = {
78
84
  };
79
85
  type EvalTarget<Input, Output, Expected = unknown> = (input: Input, testCase: EvalCase<Input, Expected>) => Output | Promise<Output>;
80
86
  type EvalOutcomeStatus = "pass" | "fail" | "invalid";
87
+ type EvalScoreDirection = "higher_is_better" | "lower_is_better";
88
+ type EvalDataType = "NUMERIC" | "CATEGORICAL" | "BOOLEAN";
89
+ type EvalTraceCarrier = {
90
+ trace: EvalTraceRef;
91
+ };
92
+ type DefaultEvalActual<Output> = Output extends {
93
+ output: infer Text extends string;
94
+ } ? Text : Output;
95
+ type EvalCaseRequirements = {
96
+ expected?: unknown;
97
+ context?: string[];
98
+ retrievalContext?: string[];
99
+ };
100
+ type EvalTotals = {
101
+ total: number;
102
+ passed: number;
103
+ failed: number;
104
+ invalid: number;
105
+ };
106
+ type EvalUsageSummary = {
107
+ target: Usage;
108
+ evaluation: Usage;
109
+ total: Usage;
110
+ };
111
+ type EvalCostSummary = {
112
+ currency: string;
113
+ target: number;
114
+ evaluation: number;
115
+ total: number;
116
+ };
81
117
  type EvalScoreProjection = {
82
118
  outcome: EvalOutcomeStatus;
83
119
  value: number | string;
@@ -91,37 +127,61 @@ type EvalMetricArgs<Input, Output, Expected = unknown> = {
91
127
  case: EvalCase<Input, Expected>;
92
128
  output: Output;
93
129
  };
94
- type EvalMetric<Input, Output, Score = unknown, Expected = unknown> = {
95
- name: string;
96
- dataType?: "NUMERIC" | "CATEGORICAL" | "BOOLEAN" | undefined;
130
+ type EvalMetric<Input, Output, Score = unknown, Expected = unknown, Name extends string = string, Requirements extends EvalCaseRequirements = Record<never, never>> = {
131
+ name: Name;
132
+ required?: boolean | undefined;
133
+ direction?: EvalScoreDirection | undefined;
134
+ threshold?: number | undefined;
135
+ dataType?: EvalDataType | undefined;
136
+ projectScore?(score: Score): number | string | boolean;
97
137
  scoreConfigId?: string | undefined;
98
138
  configId?: string | undefined;
99
139
  metadata?: EvalMetadata | undefined;
140
+ readonly caseRequirements?: Requirements | undefined;
100
141
  evaluate(args: EvalMetricArgs<Input, Output, Expected>): EvalOutcome<Score> | Promise<EvalOutcome<Score>>;
101
142
  };
102
- type EvalMetricResult<Score = unknown> = {
103
- metricName: string;
143
+ type EvalMetricResult<Score = unknown, Name extends string = string> = {
144
+ metricName: Name;
145
+ required: boolean;
146
+ direction?: EvalScoreDirection | undefined;
147
+ threshold?: number | undefined;
104
148
  outcome: EvalOutcome<Score>;
105
149
  reporterErrors: unknown[];
106
150
  };
107
- type EvalCaseResult<Input, Output, Expected = unknown> = {
151
+ type AnyEvalMetric = EvalMetric<never, never, unknown, never, string>;
152
+ type EvalMetricScore<Metric> = Metric extends {
153
+ evaluate(...args: never[]): infer Result;
154
+ } ? Awaited<Result> extends EvalOutcome<infer Score> ? Score : never : never;
155
+ type EvalMetricResultFor<Metric> = Metric extends {
156
+ name: infer Name extends string;
157
+ } ? EvalMetricResult<EvalMetricScore<Metric>, Name> : never;
158
+ type EvalScoreMap<Metrics extends readonly AnyEvalMetric[]> = {
159
+ [Metric in Metrics[number] as Metric["name"]]: EvalOutcome<EvalMetricScore<Metric>>;
160
+ };
161
+ type EvalCaseResult<Input, Output, Expected = unknown, Metrics extends readonly AnyEvalMetric[] = readonly AnyEvalMetric[]> = {
108
162
  case: EvalCase<Input, Expected>;
163
+ outcome: EvalOutcomeStatus;
109
164
  output?: Output | undefined;
110
165
  targetError?: unknown;
111
- metrics: EvalMetricResult[];
166
+ metrics: Array<EvalMetricResultFor<Metrics[number]>>;
167
+ scores: EvalScoreMap<Metrics>;
112
168
  };
113
- type EvalSuiteResult<Input, Output, Expected = unknown> = {
169
+ type EvalSuiteResult<Input, Output, Expected = unknown, Metrics extends readonly AnyEvalMetric[] = readonly AnyEvalMetric[]> = {
114
170
  name: string;
115
171
  run: EvalRunContext & {
116
172
  completedAt: string;
117
173
  };
118
- results: Array<EvalCaseResult<Input, Output, Expected>>;
119
- passed: number;
120
- failed: number;
121
- invalid: number;
174
+ results: Array<EvalCaseResult<Input, Output, Expected, Metrics>>;
175
+ metrics: EvalTotals;
176
+ cases: EvalTotals;
177
+ usage: EvalUsageSummary;
178
+ cost?: EvalCostSummary | undefined;
122
179
  durationMs: number;
123
180
  reporterErrors: unknown[];
124
181
  };
182
+ type EvalMetricDescriptor<Score = unknown, Name extends string = string> = Omit<EvalMetric<never, never, Score, never, Name>, "evaluate"> & {
183
+ evaluate?: EvalMetric<never, never, Score, never, Name>["evaluate"];
184
+ };
125
185
  type EvalReportArgs<Input, Output, Score = unknown, Expected = unknown> = {
126
186
  run?: EvalRunContext | undefined;
127
187
  suiteName: string;
@@ -129,7 +189,7 @@ type EvalReportArgs<Input, Output, Score = unknown, Expected = unknown> = {
129
189
  output?: Output | undefined;
130
190
  targetError?: unknown;
131
191
  trace?: EvalTraceRef | undefined;
132
- metric: EvalMetric<Input, Output, Score, Expected>;
192
+ metric: EvalMetricDescriptor<Score>;
133
193
  outcome: EvalOutcome<Score>;
134
194
  };
135
195
  type EvalRunStartArgs = {
@@ -142,9 +202,10 @@ type EvalRunEndArgs = EvalRunStartArgs & {
142
202
  status: "completed" | "failed";
143
203
  completedAt: string;
144
204
  durationMs: number;
145
- passed?: number | undefined;
146
- failed?: number | undefined;
147
- invalid?: number | undefined;
205
+ metrics?: EvalTotals | undefined;
206
+ cases?: EvalTotals | undefined;
207
+ usage?: EvalUsageSummary | undefined;
208
+ cost?: EvalCostSummary | undefined;
148
209
  error?: unknown;
149
210
  };
150
211
  type EvalTraceSelectorArgs<Input, Output, Expected = unknown> = {
@@ -154,27 +215,49 @@ type EvalTraceSelectorArgs<Input, Output, Expected = unknown> = {
154
215
  targetError?: unknown;
155
216
  };
156
217
  type EvalTraceSelector<Input, Output, Expected = unknown> = (args: EvalTraceSelectorArgs<Input, Output, Expected>) => EvalTraceRef | undefined | Promise<EvalTraceRef | undefined>;
157
- type EvalReporter<Input = unknown, Output = unknown, Expected = unknown> = {
218
+ type EvalReporter<in Input = unknown, in Output = unknown, in Expected = unknown> = {
158
219
  onRunStart?(args: EvalRunStartArgs): void | Promise<void>;
159
220
  report(args: EvalReportArgs<Input, Output, unknown, Expected>): void | Promise<void>;
160
221
  onRunEnd?(args: EvalRunEndArgs): void | Promise<void>;
161
222
  };
162
- type RunEvalSuiteOptions<Input, Output, Expected = unknown> = {
223
+ type EvalTargetUsageSelector<Input, Output, Expected = unknown> = (args: EvalMetricArgs<Input, Output, Expected>) => Usage | undefined | Promise<Usage | undefined>;
224
+ type EvalCostCalculatorArgs<Input, Output, Expected = unknown> = {
225
+ kind: "target";
226
+ suiteName: string;
227
+ case: EvalCase<Input, Expected>;
228
+ output: Output;
229
+ usage: Usage;
230
+ } | {
231
+ kind: "evaluation";
232
+ suiteName: string;
233
+ case: EvalCase<Input, Expected>;
234
+ output: Output;
235
+ metric: EvalMetric<Input, Output, unknown, Expected>;
236
+ usage: Usage;
237
+ };
238
+ type EvalCostOptions<Input, Output, Expected = unknown> = {
239
+ currency: string;
240
+ calculate(args: EvalCostCalculatorArgs<Input, Output, Expected>): number | Promise<number>;
241
+ };
242
+ type RunEvalSuiteOptions<Input, Output, Expected = unknown, Metrics extends readonly EvalMetric<NoInfer<Input>, NoInfer<Output>, unknown, NoInfer<Expected>, string>[] = readonly EvalMetric<NoInfer<Input>, NoInfer<Output>, unknown, NoInfer<Expected>, string>[]> = {
163
243
  name: string;
164
244
  run?: EvalRunOptions | undefined;
165
- cases: Array<EvalCase<Input, Expected>>;
245
+ cases: readonly EvalCase<Input, Expected>[];
166
246
  target: EvalTarget<Input, Output, Expected>;
167
- metrics: Array<EvalMetric<NoInfer<Input>, NoInfer<Output>, unknown, NoInfer<Expected>>>;
247
+ metrics: Metrics;
168
248
  concurrency?: number | undefined;
169
249
  trace?: EvalTraceSelector<NoInfer<Input>, NoInfer<Output>, NoInfer<Expected>> | undefined;
170
- reporters?: Array<EvalReporter<NoInfer<Input>, NoInfer<Output>, NoInfer<Expected>>> | undefined;
250
+ reporters?: readonly EvalReporter<NoInfer<Input>, NoInfer<Output>, NoInfer<Expected>>[] | undefined;
171
251
  failOnReporterError?: boolean | undefined;
252
+ targetUsage?: EvalTargetUsageSelector<NoInfer<Input>, NoInfer<Output>, NoInfer<Expected>> | undefined;
253
+ cost?: EvalCostOptions<NoInfer<Input>, NoInfer<Output>, NoInfer<Expected>> | undefined;
172
254
  };
173
255
  type ValueSelector<Input, Output, Expected, Value> = (args: EvalMetricArgs<Input, Output, Expected>) => Value | Promise<Value>;
174
256
  type SelectorOrValue<Input, Output, Expected, Value> = Value | ValueSelector<Input, Output, Expected, Value>;
175
257
 
176
258
  type LlmEvalOptions<Input, Output, Expected = unknown> = {
177
259
  name?: string | undefined;
260
+ required?: boolean | undefined;
178
261
  model: CompletionModel;
179
262
  threshold?: number | undefined;
180
263
  strictMode?: boolean | undefined;
@@ -184,13 +267,18 @@ type LlmEvalOptions<Input, Output, Expected = unknown> = {
184
267
  actual?: ValueSelector<Input, Output, Expected, string> | undefined;
185
268
  };
186
269
  type AnswerRelevancyOptions<Input, Output, Expected = unknown> = LlmEvalOptions<Input, Output, Expected>;
187
- declare function answerRelevancy<Input, Output, Expected = unknown>(options: AnswerRelevancyOptions<Input, Output, Expected>): EvalMetric<Input, Output, number, Expected>;
270
+ declare function answerRelevancy<Input, Output, Expected = unknown, const Name extends string = string>(options: AnswerRelevancyOptions<Input, Output, Expected> & {
271
+ name?: Name | undefined;
272
+ }): EvalMetric<Input, Output, number, Expected, Name>;
188
273
  type PromptAlignmentOptions<Input, Output, Expected = unknown> = LlmEvalOptions<Input, Output, Expected> & {
189
274
  promptInstructions: string[];
190
275
  };
191
- declare function promptAlignment<Input, Output, Expected = unknown>(options: PromptAlignmentOptions<Input, Output, Expected>): EvalMetric<Input, Output, number, Expected>;
276
+ declare function promptAlignment<Input, Output, Expected = unknown, const Name extends string = string>(options: PromptAlignmentOptions<Input, Output, Expected> & {
277
+ name?: Name | undefined;
278
+ }): EvalMetric<Input, Output, number, Expected, Name>;
192
279
  type JsonCorrectnessOptions<Input, Output, SchemaOutput, Expected = unknown> = {
193
280
  name?: string | undefined;
281
+ required?: boolean | undefined;
194
282
  schema: ZodSchema<SchemaOutput>;
195
283
  model?: CompletionModel | undefined;
196
284
  threshold?: number | undefined;
@@ -199,23 +287,59 @@ type JsonCorrectnessOptions<Input, Output, SchemaOutput, Expected = unknown> = {
199
287
  retries?: number | undefined;
200
288
  actual?: ValueSelector<Input, Output, Expected, string> | undefined;
201
289
  };
202
- declare function jsonCorrectness<Input, Output, SchemaOutput, Expected = unknown>(options: JsonCorrectnessOptions<Input, Output, SchemaOutput, Expected>): EvalMetric<Input, Output, number, Expected>;
290
+ declare function jsonCorrectness<Input, Output, SchemaOutput, Expected = unknown, const Name extends string = string>(options: JsonCorrectnessOptions<Input, Output, SchemaOutput, Expected> & {
291
+ name?: Name | undefined;
292
+ }): EvalMetric<Input, Output, number, Expected, Name>;
203
293
  type HallucinationOptions<Input, Output, Expected = unknown> = LlmEvalOptions<Input, Output, Expected> & {
204
294
  context?: SelectorOrValue<Input, Output, Expected, string[]> | undefined;
205
295
  };
206
- declare function hallucination<Input, Output, Expected = unknown>(options: HallucinationOptions<Input, Output, Expected>): EvalMetric<Input, Output, number, Expected>;
296
+ declare function hallucination<Input, Output, Expected = unknown, const Name extends string = string>(options: HallucinationOptions<Input, Output, Expected> & {
297
+ context: Exclude<HallucinationOptions<Input, Output, Expected>["context"], undefined>;
298
+ name?: Name | undefined;
299
+ }): EvalMetric<Input, Output, number, Expected, Name>;
300
+ declare function hallucination<Input, Output, Expected = unknown, const Name extends string = string>(options: Omit<HallucinationOptions<Input, Output, Expected>, "context"> & {
301
+ context?: undefined;
302
+ name?: Name | undefined;
303
+ }): EvalMetric<Input, Output, number, Expected, Name, {
304
+ context: string[];
305
+ }>;
207
306
  type FaithfulnessOptions<Input, Output, Expected = unknown> = LlmEvalOptions<Input, Output, Expected> & {
208
307
  retrievalContext?: SelectorOrValue<Input, Output, Expected, string[]> | undefined;
209
308
  truthsExtractionLimit?: number | undefined;
210
309
  penalizeAmbiguousClaims?: boolean | undefined;
211
310
  };
212
- declare function faithfulness<Input, Output, Expected = unknown>(options: FaithfulnessOptions<Input, Output, Expected>): EvalMetric<Input, Output, number, Expected>;
311
+ declare function faithfulness<Input, Output, Expected = unknown, const Name extends string = string>(options: FaithfulnessOptions<Input, Output, Expected> & {
312
+ name?: Name | undefined;
313
+ retrievalContext: Exclude<FaithfulnessOptions<Input, Output, Expected>["retrievalContext"], undefined>;
314
+ }): EvalMetric<Input, Output, number, Expected, Name>;
315
+ declare function faithfulness<Input, Output, Expected = unknown, const Name extends string = string>(options: Omit<FaithfulnessOptions<Input, Output, Expected>, "retrievalContext"> & {
316
+ name?: Name | undefined;
317
+ retrievalContext?: undefined;
318
+ }): EvalMetric<Input, Output, number, Expected, Name, {
319
+ retrievalContext: string[];
320
+ }>;
321
+ type AbstentionCategory = "correct_abstention" | "unnecessary_abstention" | "unsupported_confident_answer" | "correct_grounded_answer";
322
+ type AbstentionOptions<Input, Output, Expected = unknown> = {
323
+ name?: string | undefined;
324
+ required?: boolean | undefined;
325
+ model: CompletionModel;
326
+ shouldAbstain: SelectorOrValue<Input, Output, Expected, boolean>;
327
+ context?: SelectorOrValue<Input, Output, Expected, string[]> | undefined;
328
+ actual?: ValueSelector<Input, Output, Expected, string> | undefined;
329
+ includeReason?: boolean | undefined;
330
+ retries?: number | undefined;
331
+ };
332
+ declare function abstention<Input, Output, Expected = unknown, const Name extends string = string>(options: AbstentionOptions<Input, Output, Expected> & {
333
+ name?: Name | undefined;
334
+ }): EvalMetric<Input, Output, AbstentionCategory, Expected, Name>;
213
335
  type SummarizationOptions<Input, Output, Expected = unknown> = LlmEvalOptions<Input, Output, Expected> & {
214
336
  assessmentQuestions?: string[] | undefined;
215
337
  questionCount?: number | undefined;
216
338
  truthsExtractionLimit?: number | undefined;
217
339
  };
218
- declare function summarization<Input, Output, Expected = unknown>(options: SummarizationOptions<Input, Output, Expected>): EvalMetric<Input, Output, number, Expected>;
340
+ declare function summarization<Input, Output, Expected = unknown, const Name extends string = string>(options: SummarizationOptions<Input, Output, Expected> & {
341
+ name?: Name | undefined;
342
+ }): EvalMetric<Input, Output, number, Expected, Name>;
219
343
  type GEvalParameter = "input" | "actualOutput" | "expectedOutput" | "context" | "retrievalContext" | "metadata";
220
344
  type GEvalRubric = {
221
345
  scoreRange: readonly [number, number];
@@ -231,9 +355,12 @@ type GEvalOptions<Input, Output, Expected = unknown> = Omit<LlmEvalOptions<Input
231
355
  context?: SelectorOrValue<Input, Output, Expected, string[]> | undefined;
232
356
  retrievalContext?: SelectorOrValue<Input, Output, Expected, string[]> | undefined;
233
357
  };
234
- declare function gEval<Input, Output, Expected = unknown>(options: GEvalOptions<Input, Output, Expected>): EvalMetric<Input, Output, number, Expected>;
358
+ declare function gEval<Input, Output, Expected = unknown, const Name extends string = string>(options: GEvalOptions<Input, Output, Expected> & {
359
+ name: Name;
360
+ }): EvalMetric<Input, Output, number, Expected, Name>;
235
361
  type ConversationEvalOptions<Input, Output, Expected = unknown> = {
236
362
  name?: string | undefined;
363
+ required?: boolean | undefined;
237
364
  model: CompletionModel;
238
365
  threshold?: number | undefined;
239
366
  strictMode?: boolean | undefined;
@@ -245,42 +372,160 @@ type ConversationEvalOptions<Input, Output, Expected = unknown> = {
245
372
  type TurnRelevancyOptions<Input, Output, Expected = unknown> = ConversationEvalOptions<Input, Output, Expected> & {
246
373
  windowSize?: number | undefined;
247
374
  };
248
- declare function turnRelevancy<Input, Output, Expected = unknown>(options: TurnRelevancyOptions<Input, Output, Expected>): EvalMetric<Input, Output, number, Expected>;
375
+ declare function turnRelevancy<Input, Output, Expected = unknown, const Name extends string = string>(options: TurnRelevancyOptions<Input, Output, Expected> & {
376
+ name?: Name | undefined;
377
+ }): EvalMetric<Input, Output, number, Expected, Name>;
249
378
  type KnowledgeRetentionOptions<Input, Output, Expected = unknown> = ConversationEvalOptions<Input, Output, Expected>;
250
- declare function knowledgeRetention<Input, Output, Expected = unknown>(options: KnowledgeRetentionOptions<Input, Output, Expected>): EvalMetric<Input, Output, number, Expected>;
379
+ declare function knowledgeRetention<Input, Output, Expected = unknown, const Name extends string = string>(options: KnowledgeRetentionOptions<Input, Output, Expected> & {
380
+ name?: Name | undefined;
381
+ }): EvalMetric<Input, Output, number, Expected, Name>;
251
382
  type ConversationSource = EvalTurn[] | Message[];
252
383
 
253
- type AgentEvalTargetOptions<Input, Output = PromptResponse> = {
254
- prompt?: ((input: Input, testCase: EvalCase<Input>) => string | Message) | undefined;
255
- output?: ((response: PromptResponse, testCase: EvalCase<Input>) => Output) | undefined;
384
+ type AgentEvalTargetOptions<Input, Output = PromptResponse, Expected = unknown> = {
385
+ prompt?: ((input: Input, testCase: EvalCase<Input, Expected>) => string | Message) | undefined;
386
+ output?: ((response: PromptResponse, testCase: EvalCase<Input, Expected>) => Output) | undefined;
256
387
  };
257
- declare function agentEvalTarget<Input>(agent: Agent, options?: AgentEvalTargetOptions<Input, PromptResponse>): EvalTarget<Input, PromptResponse>;
258
- declare function agentEvalTarget<Input, Output>(agent: Agent, options: AgentEvalTargetOptions<Input, Output>): EvalTarget<Input, Output>;
388
+ declare function agentEvalTarget<Input, Expected = unknown>(agent: Agent, options?: AgentEvalTargetOptions<Input, PromptResponse, Expected>): EvalTarget<Input, PromptResponse, Expected>;
389
+ declare function agentEvalTarget<Input, Output, Expected = unknown>(agent: Agent, options: AgentEvalTargetOptions<Input, Output, Expected>): EvalTarget<Input, Output, Expected>;
390
+
391
+ type EvalOutputFormat = "pretty" | "json" | "quiet";
392
+ type EvalExpectedTotals = Partial<EvalTotals> & {
393
+ metrics?: Partial<EvalTotals> | undefined;
394
+ cases?: Partial<EvalTotals> | undefined;
395
+ };
396
+ type EvalExpectedOutcomes = Record<string, Record<string, EvalOutcomeStatus>>;
397
+ type EvalExpectations = {
398
+ totals?: EvalExpectedTotals | undefined;
399
+ outcomes?: EvalExpectedOutcomes | undefined;
400
+ };
401
+ type EvalOutputWriters = {
402
+ stdout?(text: string): void;
403
+ stderr?(text: string): void;
404
+ };
405
+ type PrintEvalResultOptions = {
406
+ format?: EvalOutputFormat | undefined;
407
+ output?: EvalOutputWriters | undefined;
408
+ };
409
+ type RunEvalCliOptions<Input, Output, Expected = unknown, Metrics extends readonly EvalMetric<NoInfer<Input>, NoInfer<Output>, unknown, NoInfer<Expected>, string>[] = readonly EvalMetric<NoInfer<Input>, NoInfer<Output>, unknown, NoInfer<Expected>, string>[]> = RunEvalSuiteOptions<Input, Output, Expected, Metrics> & {
410
+ format?: EvalOutputFormat | undefined;
411
+ exitCode?: boolean | undefined;
412
+ expectations?: EvalExpectations | undefined;
413
+ output?: EvalOutputWriters | undefined;
414
+ };
415
+ declare class EvalAssertionError extends Error {
416
+ readonly mismatches: string[];
417
+ constructor(message: string, mismatches: string[]);
418
+ }
419
+ declare function printEvalResult(result: EvalSuiteResult<unknown, unknown, unknown>, options?: PrintEvalResultOptions): void;
420
+ declare function evalExitCode(result: EvalSuiteResult<unknown, unknown, unknown>, expectations?: EvalExpectations): 0 | 1 | 2;
421
+ declare function assertEvalTotals(result: EvalSuiteResult<unknown, unknown, unknown>, expected: EvalExpectedTotals): void;
422
+ declare function assertEvalOutcomes(result: EvalSuiteResult<unknown, unknown, unknown>, expected: EvalExpectedOutcomes): void;
423
+ declare function runEvalCli<Input, Output, Expected = unknown, const Metrics extends readonly EvalMetric<NoInfer<Input>, NoInfer<Output>, unknown, NoInfer<Expected>, string>[] = readonly EvalMetric<NoInfer<Input>, NoInfer<Output>, unknown, NoInfer<Expected>, string>[]>(options: RunEvalCliOptions<Input, Output, Expected, Metrics>): Promise<EvalSuiteResult<Input, Output, Expected, Metrics>>;
259
424
 
260
- declare function defineMetric<Input, Output, Score, Expected>(metric: EvalMetric<Input, Output, Score, Expected>): EvalMetric<Input, Output, Score, Expected>;
425
+ declare function defineMetric<Input, Output, Score, Expected, const Name extends string = string>(metric: EvalMetric<Input, Output, Score, Expected, Name>): EvalMetric<Input, Output, Score, Expected, Name>;
261
426
 
262
427
  type ExactMatchOptions<Input, Output, Expected = unknown> = {
263
428
  name?: string | undefined;
429
+ required?: boolean | undefined;
264
430
  actual?: ValueSelector<Input, Output, Expected, unknown> | undefined;
265
431
  expected?: SelectorOrValue<Input, Output, Expected, unknown> | undefined;
266
432
  };
267
- declare function exactMatch<Input, Output, Expected = unknown>(options?: ExactMatchOptions<Input, Output, Expected>): EvalMetric<Input, Output, boolean, Expected>;
433
+ declare function exactMatch<Input, Output, Expected = unknown, const Name extends string = string>(options: ExactMatchOptions<Input, Output, Expected> & {
434
+ expected: Exclude<ExactMatchOptions<Input, Output, Expected>["expected"], undefined>;
435
+ name?: Name | undefined;
436
+ }): EvalMetric<Input, Output, boolean, Expected, Name>;
437
+ declare function exactMatch<Input, Output, Expected = unknown, const Name extends string = string>(options?: Omit<ExactMatchOptions<Input, Output, Expected>, "expected"> & {
438
+ expected?: undefined;
439
+ name?: Name | undefined;
440
+ }): EvalMetric<Input, Output, boolean, Expected, Name, {
441
+ expected: unknown;
442
+ }>;
268
443
  type ContainsOptions<Input, Output, Expected = unknown> = {
269
444
  name?: string | undefined;
445
+ required?: boolean | undefined;
270
446
  actual?: ValueSelector<Input, Output, Expected, string> | undefined;
271
447
  expected?: SelectorOrValue<Input, Output, Expected, string | RegExp> | undefined;
272
448
  };
273
- declare function contains<Input, Output, Expected = unknown>(options?: ContainsOptions<Input, Output, Expected>): EvalMetric<Input, Output, boolean, Expected>;
449
+ declare function contains<Input, Output, Expected = unknown, const Name extends string = string>(options: ContainsOptions<Input, Output, Expected> & {
450
+ expected: Exclude<ContainsOptions<Input, Output, Expected>["expected"], undefined>;
451
+ name?: Name | undefined;
452
+ }): EvalMetric<Input, Output, boolean, Expected, Name>;
453
+ declare function contains<Input, Output, Expected = unknown, const Name extends string = string>(options?: Omit<ContainsOptions<Input, Output, Expected>, "expected"> & {
454
+ expected?: undefined;
455
+ name?: Name | undefined;
456
+ }): EvalMetric<Input, Output, boolean, Expected, Name, {
457
+ expected: string | RegExp;
458
+ }>;
459
+ type NotContainsOptions<Input, Output, Expected = unknown> = ContainsOptions<Input, Output, Expected>;
460
+ declare function notContains<Input, Output, Expected = unknown, const Name extends string = string>(options?: NotContainsOptions<Input, Output, Expected> & {
461
+ name?: Name | undefined;
462
+ }): EvalMetric<Input, Output, boolean, Expected, Name>;
463
+ type ContainsListOptions<Input, Output, Expected = unknown> = {
464
+ name?: string | undefined;
465
+ required?: boolean | undefined;
466
+ actual?: ValueSelector<Input, Output, Expected, string> | undefined;
467
+ expected?: SelectorOrValue<Input, Output, Expected, ReadonlyArray<string | RegExp>> | undefined;
468
+ };
469
+ type ContainsAllOptions<Input, Output, Expected = unknown> = ContainsListOptions<Input, Output, Expected>;
470
+ declare function containsAll<Input, Output, Expected = unknown, const Name extends string = string>(options: ContainsAllOptions<Input, Output, Expected> & {
471
+ name?: Name | undefined;
472
+ }): EvalMetric<Input, Output, boolean, Expected, Name>;
473
+ type ContainsAnyOptions<Input, Output, Expected = unknown> = ContainsListOptions<Input, Output, Expected>;
474
+ declare function containsAny<Input, Output, Expected = unknown, const Name extends string = string>(options: ContainsAnyOptions<Input, Output, Expected> & {
475
+ name?: Name | undefined;
476
+ }): EvalMetric<Input, Output, boolean, Expected, Name>;
477
+ type MatchesOptions<Input, Output, Expected = unknown> = {
478
+ name?: string | undefined;
479
+ required?: boolean | undefined;
480
+ actual?: ValueSelector<Input, Output, Expected, string> | undefined;
481
+ expected?: SelectorOrValue<Input, Output, Expected, RegExp> | undefined;
482
+ };
483
+ declare function matches<Input, Output, Expected = unknown, const Name extends string = string>(options: MatchesOptions<Input, Output, Expected> & {
484
+ name?: Name | undefined;
485
+ }): EvalMetric<Input, Output, boolean, Expected, Name>;
486
+ type DoesNotMatchOptions<Input, Output, Expected = unknown> = MatchesOptions<Input, Output, Expected>;
487
+ declare function doesNotMatch<Input, Output, Expected = unknown, const Name extends string = string>(options: DoesNotMatchOptions<Input, Output, Expected> & {
488
+ name?: Name | undefined;
489
+ }): EvalMetric<Input, Output, boolean, Expected, Name>;
490
+ type MaxLengthOptions<Input, Output, Expected = unknown> = {
491
+ name?: string | undefined;
492
+ required?: boolean | undefined;
493
+ actual?: ValueSelector<Input, Output, Expected, string> | undefined;
494
+ max: SelectorOrValue<Input, Output, Expected, number>;
495
+ };
496
+ declare function maxLength<Input, Output, Expected = unknown, const Name extends string = string>(options: MaxLengthOptions<Input, Output, Expected> & {
497
+ name?: Name | undefined;
498
+ }): EvalMetric<Input, Output, boolean, Expected, Name>;
499
+ type RequiredFieldsOptions<Input, Output, Expected = unknown> = {
500
+ name?: string | undefined;
501
+ required?: boolean | undefined;
502
+ actual?: ValueSelector<Input, Output, Expected, unknown> | undefined;
503
+ expected: SelectorOrValue<Input, Output, Expected, readonly string[]>;
504
+ };
505
+ declare function requiredFields<Input, Output, Expected = unknown, const Name extends string = string>(options: RequiredFieldsOptions<Input, Output, Expected> & {
506
+ name?: Name | undefined;
507
+ }): EvalMetric<Input, Output, boolean, Expected, Name>;
274
508
  type SemanticSimilarityOptions<Input, Output, Expected = unknown> = {
275
509
  name?: string | undefined;
510
+ required?: boolean | undefined;
276
511
  model: EmbeddingModel;
277
512
  threshold: number;
278
513
  actual?: ValueSelector<Input, Output, Expected, string> | undefined;
279
514
  expected?: SelectorOrValue<Input, Output, Expected, string> | undefined;
280
515
  };
281
- declare function semanticSimilarity<Input, Output, Expected = unknown>(options: SemanticSimilarityOptions<Input, Output, Expected>): EvalMetric<Input, Output, number, Expected>;
516
+ declare function semanticSimilarity<Input, Output, Expected = unknown, const Name extends string = string>(options: SemanticSimilarityOptions<Input, Output, Expected> & {
517
+ expected: Exclude<SemanticSimilarityOptions<Input, Output, Expected>["expected"], undefined>;
518
+ name?: Name | undefined;
519
+ }): EvalMetric<Input, Output, number, Expected, Name>;
520
+ declare function semanticSimilarity<Input, Output, Expected = unknown, const Name extends string = string>(options: Omit<SemanticSimilarityOptions<Input, Output, Expected>, "expected"> & {
521
+ expected?: undefined;
522
+ name?: Name | undefined;
523
+ }): EvalMetric<Input, Output, number, Expected, Name, {
524
+ expected: string;
525
+ }>;
282
526
  type LlmJudgeOptions<Input, Output, SchemaOutput, Expected = unknown> = {
283
527
  name?: string | undefined;
528
+ required?: boolean | undefined;
284
529
  model: CompletionModel;
285
530
  schema: ZodSchema<SchemaOutput>;
286
531
  passes(value: SchemaOutput): boolean;
@@ -288,13 +533,16 @@ type LlmJudgeOptions<Input, Output, SchemaOutput, Expected = unknown> = {
288
533
  retries?: number | undefined;
289
534
  prompt?: ValueSelector<Input, Output, Expected, string> | undefined;
290
535
  };
291
- declare function llmJudge<Input, Output, SchemaOutput, Expected = unknown>(options: LlmJudgeOptions<Input, Output, SchemaOutput, Expected>): EvalMetric<Input, Output, SchemaOutput, Expected>;
536
+ declare function llmJudge<Input, Output, SchemaOutput, Expected = unknown, const Name extends string = string>(options: LlmJudgeOptions<Input, Output, SchemaOutput, Expected> & {
537
+ name?: Name | undefined;
538
+ }): EvalMetric<Input, Output, SchemaOutput, Expected, Name>;
292
539
  type LlmScoreMetricScore = {
293
540
  score: number;
294
541
  feedback: string;
295
542
  };
296
543
  type LlmScoreOptions<Input, Output, Expected = unknown> = {
297
544
  name?: string | undefined;
545
+ required?: boolean | undefined;
298
546
  model: CompletionModel;
299
547
  threshold: number;
300
548
  criteria: string | string[];
@@ -302,9 +550,11 @@ type LlmScoreOptions<Input, Output, Expected = unknown> = {
302
550
  retries?: number | undefined;
303
551
  prompt?: ValueSelector<Input, Output, Expected, string> | undefined;
304
552
  };
305
- declare function llmScore<Input, Output, Expected = unknown>(options: LlmScoreOptions<Input, Output, Expected>): EvalMetric<Input, Output, LlmScoreMetricScore, Expected>;
553
+ declare function llmScore<Input, Output, Expected = unknown, const Name extends string = string>(options: LlmScoreOptions<Input, Output, Expected> & {
554
+ name?: Name | undefined;
555
+ }): EvalMetric<Input, Output, LlmScoreMetricScore, Expected, Name>;
306
556
 
307
- declare function projectEvalOutcome(outcome: EvalOutcome, dataType: EvalMetric<unknown, unknown>["dataType"]): EvalScoreProjection;
557
+ declare function projectEvalOutcome<Score>(outcome: EvalOutcome<Score>, dataType: EvalMetric<unknown, unknown>["dataType"], projectScore?: ((score: Score) => number | string | boolean) | undefined): EvalScoreProjection;
308
558
  declare function resolveEvalTraceRef(args: {
309
559
  output?: unknown;
310
560
  input?: unknown;
@@ -312,6 +562,75 @@ declare function resolveEvalTraceRef(args: {
312
562
  }): EvalTraceRef | undefined;
313
563
  declare function defaultEvalTraceSelector<Input, Output, Expected>(args: EvalTraceSelectorArgs<Input, Output, Expected>): EvalTraceRef | undefined;
314
564
 
315
- declare function runEvalSuite<Input, Output, Expected = unknown>(options: RunEvalSuiteOptions<Input, Output, Expected>): Promise<EvalSuiteResult<Input, Output, Expected>>;
565
+ declare function runEvalSuite<Input, Output, Expected = unknown, const Metrics extends readonly EvalMetric<NoInfer<Input>, NoInfer<Output>, unknown, NoInfer<Expected>, string>[] = readonly EvalMetric<NoInfer<Input>, NoInfer<Output>, unknown, NoInfer<Expected>, string>[]>(options: RunEvalSuiteOptions<Input, Output, Expected, Metrics>): Promise<EvalSuiteResult<Input, Output, Expected, Metrics>>;
566
+
567
+ declare function selectPromptOutput(args: EvalMetricArgs<unknown, unknown, unknown>): string;
568
+
569
+ type EvalCaseLike = EvalCase<unknown, unknown>;
570
+ type EvalCasesInput<Cases extends readonly EvalCaseLike[]> = Cases[number]["input"];
571
+ type EvalCaseExpected<Case> = Case extends {
572
+ expected: infer Expected;
573
+ } ? Expected : unknown;
574
+ type EvalCasesExpected<Cases extends readonly EvalCaseLike[]> = EvalCaseExpected<Cases[number]>;
575
+ type EvalMetricRequirements<Metric> = Metric extends EvalMetric<infer _Input, infer _Output, infer _Score, infer _Expected, infer _Name, infer Requirements> ? Requirements : Record<never, never>;
576
+ type RequiredExpected<Metrics extends readonly EvalMetric<never, never>[]> = Extract<EvalMetricRequirements<Metrics[number]>, {
577
+ expected: unknown;
578
+ }>;
579
+ type RequiredContext<Metrics extends readonly EvalMetric<never, never>[]> = Extract<EvalMetricRequirements<Metrics[number]>, {
580
+ context: string[];
581
+ }>;
582
+ type RequiredRetrievalContext<Metrics extends readonly EvalMetric<never, never>[]> = Extract<EvalMetricRequirements<Metrics[number]>, {
583
+ retrievalContext: string[];
584
+ }>;
585
+ type EvalCaseFieldsForMetrics<Metrics extends readonly EvalMetric<never, never>[]> = ([
586
+ RequiredExpected<Metrics>
587
+ ] extends [never] ? Record<never, never> : {
588
+ expected: RequiredExpected<Metrics>["expected"];
589
+ }) & ([RequiredContext<Metrics>] extends [never] ? Record<never, never> : {
590
+ context: string[];
591
+ }) & ([RequiredRetrievalContext<Metrics>] extends [never] ? Record<never, never> : {
592
+ retrievalContext: string[];
593
+ });
594
+ type EvalCasesForMetrics<Cases extends readonly EvalCaseLike[], Metrics extends readonly EvalMetric<never, never>[]> = {
595
+ readonly [Index in keyof Cases]: Cases[Index] & EvalCaseFieldsForMetrics<Metrics>;
596
+ };
597
+ type DefinedEvalSuite<Cases extends readonly EvalCaseLike[], Output, Metrics extends readonly EvalMetric<EvalCasesInput<Cases>, Output, unknown, EvalCasesExpected<Cases>, string>[]> = Omit<RunEvalSuiteOptions<EvalCasesInput<Cases>, Output, EvalCasesExpected<Cases>, Metrics>, "cases" | "target" | "metrics"> & {
598
+ cases: Cases & EvalCasesForMetrics<NoInfer<Cases>, NoInfer<Metrics>>;
599
+ target: EvalTarget<EvalCasesInput<Cases>, Output, EvalCasesExpected<Cases>>;
600
+ metrics: Metrics;
601
+ };
602
+ type EvalSuiteTypeBuilder<Input, Output, Expected = unknown> = {
603
+ defineMetric<const Name extends string = string>(metric: EvalMetric<Input, Output, boolean, Expected, Name> & {
604
+ dataType: "BOOLEAN";
605
+ }): EvalMetric<Input, Output, boolean, Expected, Name>;
606
+ defineMetric<const Name extends string = string>(metric: EvalMetric<Input, Output, number, Expected, Name> & {
607
+ dataType: "NUMERIC";
608
+ }): EvalMetric<Input, Output, number, Expected, Name>;
609
+ defineMetric<const Name extends string = string>(metric: EvalMetric<Input, Output, string, Expected, Name> & {
610
+ dataType: "CATEGORICAL";
611
+ }): EvalMetric<Input, Output, string, Expected, Name>;
612
+ defineMetric<Score, const Name extends string = string>(metric: EvalMetric<Input, Output, Score, Expected, Name> & {
613
+ dataType: "BOOLEAN";
614
+ projectScore(score: Score): boolean;
615
+ }): EvalMetric<Input, Output, Score, Expected, Name>;
616
+ defineMetric<Score, const Name extends string = string>(metric: EvalMetric<Input, Output, Score, Expected, Name> & {
617
+ dataType: "NUMERIC";
618
+ projectScore(score: Score): number;
619
+ }): EvalMetric<Input, Output, Score, Expected, Name>;
620
+ defineMetric<Score, const Name extends string = string>(metric: EvalMetric<Input, Output, Score, Expected, Name> & {
621
+ dataType: "CATEGORICAL";
622
+ projectScore(score: Score): string;
623
+ }): EvalMetric<Input, Output, Score, Expected, Name>;
624
+ defineMetric<Score, const Name extends string = string>(metric: EvalMetric<Input, Output, Score, Expected, Name> & {
625
+ dataType?: undefined;
626
+ }): EvalMetric<Input, Output, Score, Expected, Name>;
627
+ };
628
+ declare function defineEvalCases<const Cases extends readonly EvalCaseLike[]>(cases: Cases): Cases;
629
+ declare function defineEvalSuite<Input, Output, Expected = unknown>(): EvalSuiteTypeBuilder<Input, Output, Expected>;
630
+ declare function defineEvalSuite<const Cases extends readonly EvalCaseLike[], const Target extends (input: EvalCasesInput<Cases>, testCase: EvalCase<EvalCasesInput<Cases>, EvalCasesExpected<Cases>>) => unknown, const Metrics extends readonly EvalMetric<EvalCasesInput<Cases>, Awaited<ReturnType<Target>>, unknown, EvalCasesExpected<Cases>, string>[]>(options: DefinedEvalSuite<Cases, Awaited<ReturnType<Target>>, Metrics> & {
631
+ target: Target;
632
+ }): DefinedEvalSuite<Cases, Awaited<ReturnType<Target>>, Metrics> & {
633
+ target: Target;
634
+ };
316
635
 
317
- export { type AgentEvalTargetOptions, type AnswerRelevancyOptions, type ContainsOptions, type EvalCase, type EvalCaseResult, type EvalMetadata, type EvalMetric, type EvalMetricArgs, type EvalMetricResult, EvalOutcome, type EvalOutcomeStatus, type EvalReportArgs, type EvalReporter, type EvalRunContext, type EvalRunEndArgs, type EvalRunOptions, type EvalRunStartArgs, type EvalScoreProjection, type EvalSuiteResult, type EvalTarget, type EvalTraceRef, type EvalTraceSelector, type EvalTraceSelectorArgs, type EvalTurn, type ExactMatchOptions, type FaithfulnessOptions, type GEvalOptions, type GEvalParameter, type GEvalRubric, type HallucinationOptions, type JsonCorrectnessOptions, type KnowledgeRetentionOptions, type LlmJudgeOptions, type LlmScoreMetricScore, type LlmScoreOptions, type PromptAlignmentOptions, type RunEvalSuiteOptions, type SelectorOrValue, type SemanticSimilarityOptions, type SummarizationOptions, type TurnRelevancyOptions, type ValueSelector, agentEvalTarget, answerRelevancy, contains, defaultEvalTraceSelector, defineMetric, exactMatch, faithfulness, gEval, hallucination, jsonCorrectness, knowledgeRetention, llmJudge, llmScore, projectEvalOutcome, promptAlignment, resolveEvalTraceRef, runEvalSuite, semanticSimilarity, summarization, turnRelevancy };
636
+ export { type AbstentionCategory, type AbstentionOptions, type AgentEvalTargetOptions, type AnswerRelevancyOptions, type AnyEvalMetric, type ContainsAllOptions, type ContainsAnyOptions, type ContainsListOptions, type ContainsOptions, type DefaultEvalActual, type DefinedEvalSuite, type DoesNotMatchOptions, EvalAssertionError, type EvalCase, type EvalCaseRequirements, type EvalCaseResult, type EvalCasesExpected, type EvalCasesForMetrics, type EvalCasesInput, type EvalCostCalculatorArgs, type EvalCostOptions, type EvalCostSummary, type EvalDataType, type EvalExpectations, type EvalExpectedOutcomes, type EvalExpectedTotals, type EvalMetadata, type EvalMetric, type EvalMetricArgs, type EvalMetricDescriptor, type EvalMetricResult, type EvalMetricResultFor, type EvalMetricScore, EvalOutcome, type EvalOutcomeStatus, type EvalOutputFormat, type EvalOutputWriters, type EvalReportArgs, type EvalReporter, type EvalRunContext, type EvalRunEndArgs, type EvalRunOptions, type EvalRunStartArgs, type EvalScoreDirection, type EvalScoreMap, type EvalScoreProjection, type EvalSuiteResult, type EvalSuiteTypeBuilder, type EvalTarget, type EvalTargetUsageSelector, type EvalTotals, type EvalTraceCarrier, type EvalTraceRef, type EvalTraceSelector, type EvalTraceSelectorArgs, type EvalTurn, type EvalUsageSummary, type ExactMatchOptions, type FaithfulnessOptions, type GEvalOptions, type GEvalParameter, type GEvalRubric, type HallucinationOptions, type JsonCorrectnessOptions, type KnowledgeRetentionOptions, type LlmJudgeOptions, type LlmScoreMetricScore, type LlmScoreOptions, type MatchesOptions, type MaxLengthOptions, type NotContainsOptions, type PrintEvalResultOptions, type PromptAlignmentOptions, type RequiredFieldsOptions, type RunEvalCliOptions, type RunEvalSuiteOptions, type SelectorOrValue, type SemanticSimilarityOptions, type SummarizationOptions, type TurnRelevancyOptions, type ValueSelector, abstention, agentEvalTarget, answerRelevancy, assertEvalOutcomes, assertEvalTotals, contains, containsAll, containsAny, defaultEvalTraceSelector, defineEvalCases, defineEvalSuite, defineMetric, doesNotMatch, evalExitCode, exactMatch, faithfulness, gEval, hallucination, jsonCorrectness, knowledgeRetention, llmJudge, llmScore, matches, maxLength, notContains, printEvalResult, projectEvalOutcome, promptAlignment, requiredFields, resolveEvalTraceRef, runEvalCli, runEvalSuite, selectPromptOutput, semanticSimilarity, summarization, turnRelevancy };