@anvia/core 0.26.0 → 1.0.0-rc.10
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 +400 -94
- package/dist/agent/index.d.ts +67 -71
- package/dist/agent/index.js +36 -18
- package/dist/agent/interactions/index.d.ts +122 -0
- package/dist/agent/interactions/index.js +20 -0
- package/dist/agent-DWzW9SoH.d.ts +150 -0
- package/dist/chunk-3RM57ZT2.js +31 -0
- package/dist/chunk-3RM57ZT2.js.map +1 -0
- package/dist/chunk-3RWESPUG.js +331 -0
- package/dist/chunk-3RWESPUG.js.map +1 -0
- package/dist/{chunk-NCPN4SJR.js → chunk-3SKZ2BKP.js} +15 -13
- package/dist/chunk-3SKZ2BKP.js.map +1 -0
- package/dist/chunk-3XQGVDU5.js +69 -0
- package/dist/chunk-3XQGVDU5.js.map +1 -0
- package/dist/{chunk-MRQLEK2B.js → chunk-5C6B6ZRH.js} +69 -51
- package/dist/chunk-5C6B6ZRH.js.map +1 -0
- package/dist/chunk-6BBOCFHV.js +323 -0
- package/dist/chunk-6BBOCFHV.js.map +1 -0
- package/dist/chunk-7JLAIN6E.js +15 -0
- package/dist/chunk-7JLAIN6E.js.map +1 -0
- package/dist/chunk-7PHMK7W4.js +1516 -0
- package/dist/chunk-7PHMK7W4.js.map +1 -0
- package/dist/{chunk-CWUJUSOS.js → chunk-AZB6N7P4.js} +94 -65
- package/dist/chunk-AZB6N7P4.js.map +1 -0
- package/dist/chunk-D4PACGPA.js +37 -0
- package/dist/chunk-D4PACGPA.js.map +1 -0
- package/dist/chunk-EFLT7XZD.js +51 -0
- package/dist/chunk-EFLT7XZD.js.map +1 -0
- package/dist/chunk-EMZKPRE6.js +667 -0
- package/dist/chunk-EMZKPRE6.js.map +1 -0
- package/dist/chunk-I3Q7XSBB.js +59 -0
- package/dist/chunk-I3Q7XSBB.js.map +1 -0
- package/dist/chunk-J6LVLV6P.js +13 -0
- package/dist/chunk-J6LVLV6P.js.map +1 -0
- package/dist/chunk-LTXABCOO.js +127 -0
- package/dist/chunk-LTXABCOO.js.map +1 -0
- package/dist/chunk-OJBFDBLG.js +164 -0
- package/dist/chunk-OJBFDBLG.js.map +1 -0
- package/dist/chunk-QGX73TSQ.js +177 -0
- package/dist/chunk-QGX73TSQ.js.map +1 -0
- package/dist/chunk-QOUPWOGW.js +29 -0
- package/dist/chunk-QOUPWOGW.js.map +1 -0
- package/dist/chunk-SJMSS5SI.js +171 -0
- package/dist/chunk-SJMSS5SI.js.map +1 -0
- package/dist/chunk-T2C3CGDQ.js +56 -0
- package/dist/chunk-T2C3CGDQ.js.map +1 -0
- package/dist/chunk-VX3HS6PE.js +4569 -0
- package/dist/chunk-VX3HS6PE.js.map +1 -0
- package/dist/chunk-X4LK4ODN.js +86 -0
- package/dist/chunk-X4LK4ODN.js.map +1 -0
- package/dist/chunk-ZA564323.js +331 -0
- package/dist/chunk-ZA564323.js.map +1 -0
- package/dist/completion/index.d.ts +6 -36
- package/dist/completion/index.js +34 -29
- package/dist/documents/index.d.ts +34 -0
- package/dist/documents/index.js +340 -0
- package/dist/documents/index.js.map +1 -0
- package/dist/dynamic-tools-aIZlg5x1.d.ts +45 -0
- package/dist/embeddings/index.d.ts +11 -9
- package/dist/embeddings/index.js +3 -4
- package/dist/evals/index.d.ts +57 -21
- package/dist/evals/index.js +209 -104
- package/dist/evals/index.js.map +1 -1
- package/dist/extractor/index.d.ts +27 -42
- package/dist/extractor/index.js +9 -22
- package/dist/guardrails/index.d.ts +7 -129
- package/dist/guardrails/index.js +1 -1
- package/dist/image-generation/index.d.ts +23 -23
- package/dist/image-generation/index.js +7 -39
- package/dist/image-generation/index.js.map +1 -1
- package/dist/index.d.ts +24 -22
- package/dist/index.js +85 -68
- package/dist/internal/agent.d.ts +156 -10
- package/dist/internal/agent.js +58 -18
- package/dist/internal/agent.js.map +1 -1
- package/dist/mcp/index.d.ts +7 -15
- package/dist/mcp/index.js +3 -348
- package/dist/mcp/index.js.map +1 -1
- package/dist/memory/index.d.ts +20 -6
- package/dist/memory/index.js +11 -10
- package/dist/middleware-kcF8AusP.d.ts +59 -0
- package/dist/model-call-options-CZkSw_xN.d.ts +6 -0
- package/dist/model-listing/index.d.ts +3 -1
- package/dist/observability/index.d.ts +23 -4
- package/dist/observability/index.js +10 -5
- package/dist/observability/index.js.map +1 -1
- package/dist/pipeline/index.d.ts +111 -73
- package/dist/pipeline/index.js +471 -286
- package/dist/pipeline/index.js.map +1 -1
- package/dist/provider-output-error-BEwDgVv3.d.ts +99 -0
- package/dist/retry-CjvSlKGW.d.ts +16 -0
- package/dist/skills/index.d.ts +5 -4
- package/dist/skills/index.js +8 -8
- package/dist/speech-generation/index.d.ts +37 -0
- package/dist/speech-generation/index.js +10 -0
- package/dist/streaming/index.js +37 -3
- package/dist/streaming/index.js.map +1 -1
- package/dist/text-ZLECpQE7.d.ts +32 -0
- package/dist/think-tool-BwCsJ365.d.ts +40 -0
- package/dist/tool/index.d.ts +11 -6
- package/dist/tool/index.js +21 -21
- package/dist/tool-BpqpoRSE.d.ts +58 -0
- package/dist/transcription/index.d.ts +29 -22
- package/dist/transcription/index.js +7 -57
- package/dist/transcription/index.js.map +1 -1
- package/dist/type-utils-CtHVDRn_.d.ts +6 -0
- package/dist/types-CXNE592e.d.ts +130 -0
- package/dist/types-Cr4uiYo5.d.ts +99 -0
- package/dist/{types-04LqWrmy.d.ts → types-DC1U1XwW.d.ts} +1 -1
- package/dist/types-DKOXVTcq.d.ts +155 -0
- package/dist/types-DgvozfPc.d.ts +349 -0
- package/dist/types-DhkodEft.d.ts +105 -0
- package/dist/types-DjqRHeAi.d.ts +31 -0
- package/dist/types-Sue2hb_L.d.ts +403 -0
- package/dist/vector-store/index.d.ts +34 -34
- package/dist/vector-store/index.js +10 -6
- package/package.json +22 -24
- package/dist/agent-x3YTyv5i.d.ts +0 -222
- package/dist/audio-generation/index.d.ts +0 -33
- package/dist/audio-generation/index.js +0 -42
- package/dist/audio-generation/index.js.map +0 -1
- package/dist/chunk-2ODTMRHP.js +0 -54
- package/dist/chunk-2ODTMRHP.js.map +0 -1
- package/dist/chunk-ADH7NNCS.js +0 -512
- package/dist/chunk-ADH7NNCS.js.map +0 -1
- package/dist/chunk-BALBBVI3.js +0 -2732
- package/dist/chunk-BALBBVI3.js.map +0 -1
- package/dist/chunk-CQNNSZPG.js +0 -9
- package/dist/chunk-CQNNSZPG.js.map +0 -1
- package/dist/chunk-CWUJUSOS.js.map +0 -1
- package/dist/chunk-DALYP4PX.js +0 -225
- package/dist/chunk-DALYP4PX.js.map +0 -1
- package/dist/chunk-HYUYZEAJ.js +0 -223
- package/dist/chunk-HYUYZEAJ.js.map +0 -1
- package/dist/chunk-I6XOQ4LK.js +0 -466
- package/dist/chunk-I6XOQ4LK.js.map +0 -1
- package/dist/chunk-JI5YZWNT.js +0 -220
- package/dist/chunk-JI5YZWNT.js.map +0 -1
- package/dist/chunk-MC3CCKEB.js +0 -221
- package/dist/chunk-MC3CCKEB.js.map +0 -1
- package/dist/chunk-MELYDKWQ.js +0 -337
- package/dist/chunk-MELYDKWQ.js.map +0 -1
- package/dist/chunk-MNWK2USR.js +0 -243
- package/dist/chunk-MNWK2USR.js.map +0 -1
- package/dist/chunk-MRQLEK2B.js.map +0 -1
- package/dist/chunk-NCPN4SJR.js.map +0 -1
- package/dist/chunk-OIMLU4SF.js +0 -20
- package/dist/chunk-OIMLU4SF.js.map +0 -1
- package/dist/chunk-Q25IWLBT.js +0 -138
- package/dist/chunk-Q25IWLBT.js.map +0 -1
- package/dist/chunk-UQX6EXWG.js +0 -33
- package/dist/chunk-UQX6EXWG.js.map +0 -1
- package/dist/chunk-WQKHFADH.js +0 -12
- package/dist/chunk-WQKHFADH.js.map +0 -1
- package/dist/chunk-XUUY2L2D.js +0 -42
- package/dist/chunk-XUUY2L2D.js.map +0 -1
- package/dist/chunk-XWUC7CIT.js +0 -1
- package/dist/chunk-XWUC7CIT.js.map +0 -1
- package/dist/chunk-YLMDBQO4.js +0 -141
- package/dist/chunk-YLMDBQO4.js.map +0 -1
- package/dist/errors-2moLDuuN.d.ts +0 -17
- package/dist/hooks/index.d.ts +0 -12
- package/dist/hooks/index.js +0 -17
- package/dist/index-BxSbmOMr.d.ts +0 -257
- package/dist/json-BVPssigK.d.ts +0 -39
- package/dist/loaders/index.d.ts +0 -91
- package/dist/loaders/index.js +0 -299
- package/dist/loaders/index.js.map +0 -1
- package/dist/middleware-Dp3d_pxi.d.ts +0 -90
- package/dist/request/index.d.ts +0 -28
- package/dist/request/index.js +0 -25
- package/dist/think-tool-DfCMuO8e.d.ts +0 -26
- package/dist/tool-Cohdv5GC.d.ts +0 -65
- package/dist/types-BCTRUGex.d.ts +0 -47
- package/dist/types-BrLbKnEz.d.ts +0 -119
- package/dist/types-D9JpeAPF.d.ts +0 -114
- package/dist/types-G12i56s2.d.ts +0 -354
- package/dist/types-JJCxRnaZ.d.ts +0 -70
- package/dist/types-O-abTIin.d.ts +0 -79
- package/dist/ui/index.d.ts +0 -107
- package/dist/ui/index.js +0 -10
- package/dist/ui/index.js.map +0 -1
- /package/dist/{hooks → agent/interactions}/index.js.map +0 -0
- /package/dist/{request → speech-generation}/index.js.map +0 -0
package/dist/evals/index.js
CHANGED
|
@@ -1,37 +1,33 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
} from "../chunk-
|
|
4
|
-
import "../chunk-JI5YZWNT.js";
|
|
5
|
-
import "../chunk-DALYP4PX.js";
|
|
6
|
-
import "../chunk-BALBBVI3.js";
|
|
7
|
-
import "../chunk-YK4WAAS4.js";
|
|
8
|
-
import "../chunk-XUUY2L2D.js";
|
|
9
|
-
import "../chunk-HYUYZEAJ.js";
|
|
10
|
-
import "../chunk-MELYDKWQ.js";
|
|
11
|
-
import "../chunk-2ODTMRHP.js";
|
|
12
|
-
import "../chunk-UQX6EXWG.js";
|
|
13
|
-
import "../chunk-MRQLEK2B.js";
|
|
2
|
+
AgentRunBlockedError
|
|
3
|
+
} from "../chunk-X4LK4ODN.js";
|
|
14
4
|
import {
|
|
15
5
|
cosineSimilarity,
|
|
16
6
|
embedText
|
|
17
|
-
} from "../chunk-
|
|
7
|
+
} from "../chunk-ZA564323.js";
|
|
18
8
|
import {
|
|
19
9
|
mapWithConcurrency
|
|
20
|
-
} from "../chunk-
|
|
21
|
-
import
|
|
22
|
-
|
|
10
|
+
} from "../chunk-3RM57ZT2.js";
|
|
11
|
+
import {
|
|
12
|
+
extract
|
|
13
|
+
} from "../chunk-LTXABCOO.js";
|
|
14
|
+
import "../chunk-D4PACGPA.js";
|
|
23
15
|
import {
|
|
24
16
|
Usage
|
|
25
|
-
} from "../chunk-
|
|
26
|
-
import "../chunk-
|
|
27
|
-
import "../chunk-
|
|
17
|
+
} from "../chunk-7PHMK7W4.js";
|
|
18
|
+
import "../chunk-7JLAIN6E.js";
|
|
19
|
+
import "../chunk-QGX73TSQ.js";
|
|
20
|
+
import {
|
|
21
|
+
isJsonValue
|
|
22
|
+
} from "../chunk-3XQGVDU5.js";
|
|
23
|
+
import "../chunk-3RWESPUG.js";
|
|
28
24
|
|
|
29
25
|
// src/evals/advanced-metrics.ts
|
|
30
26
|
import { z } from "zod";
|
|
31
27
|
|
|
32
28
|
// src/evals/format.ts
|
|
33
29
|
function defaultOutputValue(output) {
|
|
34
|
-
if (typeof output === "object" && output !== null && "output" in output
|
|
30
|
+
if (typeof output === "object" && output !== null && "output" in output) {
|
|
35
31
|
return output.output;
|
|
36
32
|
}
|
|
37
33
|
return output;
|
|
@@ -58,8 +54,15 @@ function errorMessage(error) {
|
|
|
58
54
|
|
|
59
55
|
// src/evals/judge.ts
|
|
60
56
|
async function runJudge(args) {
|
|
61
|
-
const result = await
|
|
62
|
-
|
|
57
|
+
const result = await extract({
|
|
58
|
+
model: args.model,
|
|
59
|
+
outputSchema: args.schema,
|
|
60
|
+
instructions: args.instructions,
|
|
61
|
+
text: args.prompt,
|
|
62
|
+
temperature: 0,
|
|
63
|
+
retries: args.retries <= 0 ? void 0 : { maxAttempts: Math.trunc(args.retries) + 1 }
|
|
64
|
+
});
|
|
65
|
+
return { data: result.output, usage: result.usage };
|
|
63
66
|
}
|
|
64
67
|
function addUsage(...values) {
|
|
65
68
|
return values.reduce((total, usage) => Usage.add(total, usage), Usage.empty());
|
|
@@ -238,13 +241,14 @@ ${actual}`,
|
|
|
238
241
|
usage = addUsage(usage, verdictResult.usage);
|
|
239
242
|
}
|
|
240
243
|
const score = verdicts.length === 0 ? 1 : verdicts.filter((verdict) => verdict.verdict !== "no").length / verdicts.length;
|
|
244
|
+
const serializedVerdicts = serializeVerdicts(verdicts);
|
|
241
245
|
const reasonResult = await maybeReason({
|
|
242
246
|
model: options.model,
|
|
243
247
|
includeReason: config.includeReason,
|
|
244
248
|
retries: config.retries,
|
|
245
249
|
metric: "answer relevancy",
|
|
246
250
|
score,
|
|
247
|
-
evidence: { input, verdicts }
|
|
251
|
+
evidence: { input, verdicts: serializedVerdicts }
|
|
248
252
|
});
|
|
249
253
|
usage = addUsage(usage, reasonResult.usage);
|
|
250
254
|
return higherOutcome({
|
|
@@ -252,7 +256,7 @@ ${actual}`,
|
|
|
252
256
|
threshold: config.threshold,
|
|
253
257
|
strictMode: config.strictMode,
|
|
254
258
|
comment: reasonResult.reason,
|
|
255
|
-
details: { statements, verdicts },
|
|
259
|
+
details: { statements, verdicts: serializedVerdicts },
|
|
256
260
|
usage
|
|
257
261
|
});
|
|
258
262
|
} catch (error) {
|
|
@@ -320,6 +324,9 @@ function jsonCorrectness(options) {
|
|
|
320
324
|
let validationError;
|
|
321
325
|
try {
|
|
322
326
|
parsed = JSON.parse(actual);
|
|
327
|
+
if (!isJsonValue(parsed)) {
|
|
328
|
+
throw new TypeError("Generated output is not a JSON value.");
|
|
329
|
+
}
|
|
323
330
|
const result = options.schema.safeParse(parsed);
|
|
324
331
|
if (!result.success) {
|
|
325
332
|
validationError = z.prettifyError(result.error);
|
|
@@ -452,13 +459,14 @@ ${actual}`,
|
|
|
452
459
|
(verdict) => verdict.verdict === "yes" || verdict.verdict === "idk" && !penalizeAmbiguousClaims
|
|
453
460
|
).length;
|
|
454
461
|
const score = verdicts.length === 0 ? 1 : supported / verdicts.length;
|
|
462
|
+
const serializedVerdicts = serializeVerdicts(verdicts);
|
|
455
463
|
const reasonResult = await maybeReason({
|
|
456
464
|
model: options.model,
|
|
457
465
|
includeReason: config.includeReason,
|
|
458
466
|
retries: config.retries,
|
|
459
467
|
metric: "faithfulness",
|
|
460
468
|
score,
|
|
461
|
-
evidence: { verdicts, penalizeAmbiguousClaims }
|
|
469
|
+
evidence: { verdicts: serializedVerdicts, penalizeAmbiguousClaims }
|
|
462
470
|
});
|
|
463
471
|
usage = addUsage(usage, reasonResult.usage);
|
|
464
472
|
return higherOutcome({
|
|
@@ -466,7 +474,7 @@ ${actual}`,
|
|
|
466
474
|
threshold: config.threshold,
|
|
467
475
|
strictMode: config.strictMode,
|
|
468
476
|
comment: reasonResult.reason,
|
|
469
|
-
details: { truths, claims, verdicts, penalizeAmbiguousClaims },
|
|
477
|
+
details: { truths, claims, verdicts: serializedVerdicts, penalizeAmbiguousClaims },
|
|
470
478
|
usage
|
|
471
479
|
});
|
|
472
480
|
} catch (error) {
|
|
@@ -630,13 +638,19 @@ ${actual}`,
|
|
|
630
638
|
});
|
|
631
639
|
const coverageScore = coverageTotal === 0 ? 0 : coverageMatched / coverageTotal;
|
|
632
640
|
const score = Math.min(alignmentScore, coverageScore);
|
|
641
|
+
const serializedAlignmentVerdicts = serializeVerdicts(alignmentVerdicts);
|
|
633
642
|
const reasonResult = await maybeReason({
|
|
634
643
|
model: options.model,
|
|
635
644
|
includeReason: config.includeReason,
|
|
636
645
|
retries: config.retries,
|
|
637
646
|
metric: "summarization",
|
|
638
647
|
score,
|
|
639
|
-
evidence: {
|
|
648
|
+
evidence: {
|
|
649
|
+
alignmentVerdicts: serializedAlignmentVerdicts,
|
|
650
|
+
coverageVerdicts,
|
|
651
|
+
alignmentScore,
|
|
652
|
+
coverageScore
|
|
653
|
+
}
|
|
640
654
|
});
|
|
641
655
|
const usage = addUsage(
|
|
642
656
|
truthResult.usage,
|
|
@@ -656,7 +670,7 @@ ${actual}`,
|
|
|
656
670
|
truths,
|
|
657
671
|
claims,
|
|
658
672
|
assessmentQuestions: questions,
|
|
659
|
-
alignmentVerdicts,
|
|
673
|
+
alignmentVerdicts: serializedAlignmentVerdicts,
|
|
660
674
|
coverageVerdicts,
|
|
661
675
|
scoreBreakdown: { alignment: alignmentScore, coverage: coverageScore }
|
|
662
676
|
},
|
|
@@ -1042,15 +1056,33 @@ function assertSameLength(label, inputs, outputs) {
|
|
|
1042
1056
|
throw new Error(`${label} count ${outputs.length} did not match input count ${inputs.length}.`);
|
|
1043
1057
|
}
|
|
1044
1058
|
}
|
|
1059
|
+
function serializeVerdicts(verdicts) {
|
|
1060
|
+
return verdicts.map((verdict) => {
|
|
1061
|
+
const serialized = { verdict: verdict.verdict };
|
|
1062
|
+
if (verdict.reason !== void 0) serialized.reason = verdict.reason;
|
|
1063
|
+
return serialized;
|
|
1064
|
+
});
|
|
1065
|
+
}
|
|
1045
1066
|
function jsonPrompt(value) {
|
|
1046
1067
|
return JSON.stringify(value, null, 2);
|
|
1047
1068
|
}
|
|
1048
1069
|
function toJsonValue(value) {
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
}
|
|
1052
|
-
|
|
1053
|
-
|
|
1070
|
+
if (!isJsonValue(value)) {
|
|
1071
|
+
throw new TypeError("G-Eval expectedOutput must be a JSON value.");
|
|
1072
|
+
}
|
|
1073
|
+
return cloneJsonValue(value);
|
|
1074
|
+
}
|
|
1075
|
+
function cloneJsonValue(value) {
|
|
1076
|
+
if (value === null || typeof value !== "object") return value;
|
|
1077
|
+
if (Array.isArray(value)) return value.map(cloneJsonValue);
|
|
1078
|
+
return Object.fromEntries(
|
|
1079
|
+
Object.entries(value).map(([key, item]) => {
|
|
1080
|
+
if (item === void 0) {
|
|
1081
|
+
throw new TypeError("G-Eval expectedOutput must be a JSON value.");
|
|
1082
|
+
}
|
|
1083
|
+
return [key, cloneJsonValue(item)];
|
|
1084
|
+
})
|
|
1085
|
+
);
|
|
1054
1086
|
}
|
|
1055
1087
|
function normalizeEvalTurns(value) {
|
|
1056
1088
|
const source = conversationArray(value);
|
|
@@ -1116,13 +1148,61 @@ function contentText(content) {
|
|
|
1116
1148
|
}
|
|
1117
1149
|
|
|
1118
1150
|
// src/evals/agent-target.ts
|
|
1119
|
-
|
|
1151
|
+
var AgentEvalSuspensionError = class extends Error {
|
|
1152
|
+
constructor(result, message = "Agent eval target suspended without an interaction responder.") {
|
|
1153
|
+
super(message);
|
|
1154
|
+
this.result = result;
|
|
1155
|
+
this.name = "AgentEvalSuspensionError";
|
|
1156
|
+
}
|
|
1157
|
+
result;
|
|
1158
|
+
};
|
|
1159
|
+
function agentEvalTarget(options) {
|
|
1120
1160
|
return async (input, testCase) => {
|
|
1121
|
-
const
|
|
1122
|
-
|
|
1123
|
-
|
|
1161
|
+
const maxResponses = options.interactions?.maxResponses ?? 10;
|
|
1162
|
+
if (!Number.isSafeInteger(maxResponses) || maxResponses < 1) {
|
|
1163
|
+
throw new TypeError("Agent eval interactions.maxResponses must be a positive integer.");
|
|
1164
|
+
}
|
|
1165
|
+
const request = await options.request({ input, testCase });
|
|
1166
|
+
const runSettings = agentRunSettings(request);
|
|
1167
|
+
let response = await options.agent.generate(request);
|
|
1168
|
+
let phase = 0;
|
|
1169
|
+
while (response.status === "suspended") {
|
|
1170
|
+
if (options.interactions === void 0) {
|
|
1171
|
+
throw new AgentEvalSuspensionError(response);
|
|
1172
|
+
}
|
|
1173
|
+
if (phase >= maxResponses) {
|
|
1174
|
+
throw new AgentEvalSuspensionError(
|
|
1175
|
+
response,
|
|
1176
|
+
`Agent eval target exceeded the interaction response limit of ${maxResponses}.`
|
|
1177
|
+
);
|
|
1178
|
+
}
|
|
1179
|
+
phase += 1;
|
|
1180
|
+
const interactionResponse = await options.interactions.respond({
|
|
1181
|
+
interaction: response.interaction,
|
|
1182
|
+
testCase,
|
|
1183
|
+
phase
|
|
1184
|
+
});
|
|
1185
|
+
response = await options.agent.generate({
|
|
1186
|
+
continuation: response.continuation,
|
|
1187
|
+
response: interactionResponse,
|
|
1188
|
+
...runSettings
|
|
1189
|
+
});
|
|
1190
|
+
}
|
|
1191
|
+
if (response.status === "blocked") throw new AgentRunBlockedError(response);
|
|
1192
|
+
return options.output === void 0 ? response : await options.output({ response, testCase });
|
|
1124
1193
|
};
|
|
1125
1194
|
}
|
|
1195
|
+
function agentRunSettings(request) {
|
|
1196
|
+
const {
|
|
1197
|
+
prompt: _prompt,
|
|
1198
|
+
messages: _messages,
|
|
1199
|
+
session: _session,
|
|
1200
|
+
continuation: _continuation,
|
|
1201
|
+
response: _response,
|
|
1202
|
+
...settings
|
|
1203
|
+
} = request;
|
|
1204
|
+
return settings;
|
|
1205
|
+
}
|
|
1126
1206
|
|
|
1127
1207
|
// src/evals/reporting.ts
|
|
1128
1208
|
function projectEvalOutcome(outcome, dataType, projectScore) {
|
|
@@ -1185,6 +1265,7 @@ function traceFromCarrier(value) {
|
|
|
1185
1265
|
function traceFromMetadata(metadata) {
|
|
1186
1266
|
if (metadata === void 0) return void 0;
|
|
1187
1267
|
return readTraceRef({
|
|
1268
|
+
observer: metadata.traceObserver,
|
|
1188
1269
|
traceId: metadata.traceId,
|
|
1189
1270
|
observationId: metadata.observationId,
|
|
1190
1271
|
responseId: metadata.responseId
|
|
@@ -1194,9 +1275,11 @@ function readTraceRef(value) {
|
|
|
1194
1275
|
if (typeof value !== "object" || value === null) return void 0;
|
|
1195
1276
|
const traceId = value.traceId;
|
|
1196
1277
|
if (typeof traceId !== "string" || traceId.length === 0) return void 0;
|
|
1278
|
+
const observer = value.observer;
|
|
1197
1279
|
const observationId = value.observationId;
|
|
1198
1280
|
const responseId = value.responseId;
|
|
1199
1281
|
const trace = { traceId };
|
|
1282
|
+
if (typeof observer === "string" && observer.length > 0) trace.observer = observer;
|
|
1200
1283
|
if (typeof observationId === "string" && observationId.length > 0) {
|
|
1201
1284
|
trace.observationId = observationId;
|
|
1202
1285
|
}
|
|
@@ -1205,6 +1288,14 @@ function readTraceRef(value) {
|
|
|
1205
1288
|
}
|
|
1206
1289
|
|
|
1207
1290
|
// src/evals/runner.ts
|
|
1291
|
+
var EvalReporterDispatchError = class extends AggregateError {
|
|
1292
|
+
phase;
|
|
1293
|
+
constructor(phase, errors) {
|
|
1294
|
+
super(errors, `Evaluation reporter ${phase} failed ${errors.length} time(s).`);
|
|
1295
|
+
this.name = "EvalReporterDispatchError";
|
|
1296
|
+
this.phase = phase;
|
|
1297
|
+
}
|
|
1298
|
+
};
|
|
1208
1299
|
async function runEvalSuite(options) {
|
|
1209
1300
|
validateSuiteOptions(options);
|
|
1210
1301
|
const startedAtMs = Date.now();
|
|
@@ -1221,7 +1312,7 @@ async function runEvalSuite(options) {
|
|
|
1221
1312
|
reporterErrors = await notifyRunStart(
|
|
1222
1313
|
reporters,
|
|
1223
1314
|
lifecycle,
|
|
1224
|
-
options.
|
|
1315
|
+
options.reporterErrorPolicy ?? "collect"
|
|
1225
1316
|
);
|
|
1226
1317
|
} catch (error) {
|
|
1227
1318
|
await notifyRunEnd(reporters, {
|
|
@@ -1256,25 +1347,26 @@ async function runEvalSuite(options) {
|
|
|
1256
1347
|
metrics: aggregates.metrics,
|
|
1257
1348
|
cases: aggregates.cases,
|
|
1258
1349
|
usage: aggregates.usage,
|
|
1259
|
-
...aggregates.cost === void 0 ? {} : { cost: aggregates.cost },
|
|
1260
1350
|
durationMs: Date.now() - startedAtMs,
|
|
1261
1351
|
reporterErrors
|
|
1262
1352
|
};
|
|
1353
|
+
if (aggregates.cost !== void 0) {
|
|
1354
|
+
result.cost = aggregates.cost;
|
|
1355
|
+
}
|
|
1356
|
+
const runEndArgs = {
|
|
1357
|
+
...lifecycle,
|
|
1358
|
+
status: "completed",
|
|
1359
|
+
completedAt,
|
|
1360
|
+
durationMs: result.durationMs,
|
|
1361
|
+
metrics: result.metrics,
|
|
1362
|
+
cases: result.cases,
|
|
1363
|
+
usage: result.usage
|
|
1364
|
+
};
|
|
1365
|
+
if (result.cost !== void 0) {
|
|
1366
|
+
runEndArgs.cost = result.cost;
|
|
1367
|
+
}
|
|
1263
1368
|
result.reporterErrors.push(
|
|
1264
|
-
...await notifyRunEnd(
|
|
1265
|
-
reporters,
|
|
1266
|
-
{
|
|
1267
|
-
...lifecycle,
|
|
1268
|
-
status: "completed",
|
|
1269
|
-
completedAt,
|
|
1270
|
-
durationMs: result.durationMs,
|
|
1271
|
-
metrics: result.metrics,
|
|
1272
|
-
cases: result.cases,
|
|
1273
|
-
usage: result.usage,
|
|
1274
|
-
...result.cost === void 0 ? {} : { cost: result.cost }
|
|
1275
|
-
},
|
|
1276
|
-
options.failOnReporterError === true
|
|
1277
|
-
)
|
|
1369
|
+
...await notifyRunEnd(reporters, runEndArgs, options.reporterErrorPolicy ?? "collect")
|
|
1278
1370
|
);
|
|
1279
1371
|
return result;
|
|
1280
1372
|
}
|
|
@@ -1327,7 +1419,7 @@ async function runEvalCase(options, testCase, run) {
|
|
|
1327
1419
|
trace: traceResult.trace,
|
|
1328
1420
|
traceError: traceResult.error,
|
|
1329
1421
|
reporters: options.reporters ?? [],
|
|
1330
|
-
|
|
1422
|
+
reporterErrorPolicy: options.reporterErrorPolicy ?? "collect"
|
|
1331
1423
|
});
|
|
1332
1424
|
const metricResult = {
|
|
1333
1425
|
metricName: metric.name,
|
|
@@ -1380,9 +1472,7 @@ async function safeEvaluate(suiteName, testCase, output, metric) {
|
|
|
1380
1472
|
async function reportOutcome(args) {
|
|
1381
1473
|
const errors = [];
|
|
1382
1474
|
if (args.traceError !== void 0) {
|
|
1383
|
-
if (args.failOnReporterError) throw args.traceError;
|
|
1384
1475
|
errors.push(args.traceError);
|
|
1385
|
-
return errors;
|
|
1386
1476
|
}
|
|
1387
1477
|
for (const reporter of args.reporters) {
|
|
1388
1478
|
try {
|
|
@@ -1397,12 +1487,10 @@ async function reportOutcome(args) {
|
|
|
1397
1487
|
outcome: args.outcome
|
|
1398
1488
|
});
|
|
1399
1489
|
} catch (error) {
|
|
1400
|
-
if (args.failOnReporterError) {
|
|
1401
|
-
throw error;
|
|
1402
|
-
}
|
|
1403
1490
|
errors.push(error);
|
|
1404
1491
|
}
|
|
1405
1492
|
}
|
|
1493
|
+
throwReporterErrors("report", errors, args.reporterErrorPolicy);
|
|
1406
1494
|
return errors;
|
|
1407
1495
|
}
|
|
1408
1496
|
function resolveRun(options, startedAtMs) {
|
|
@@ -1418,40 +1506,46 @@ function resolveRun(options, startedAtMs) {
|
|
|
1418
1506
|
throw new TypeError(`Evaluation run ${label} must contain 1 to 256 characters`);
|
|
1419
1507
|
}
|
|
1420
1508
|
}
|
|
1421
|
-
|
|
1509
|
+
const run = {
|
|
1422
1510
|
id,
|
|
1423
|
-
startedAt: new Date(startedAtMs).toISOString()
|
|
1424
|
-
...options.run?.datasetName === void 0 ? {} : { datasetName: options.run.datasetName },
|
|
1425
|
-
...options.run?.datasetVersion === void 0 ? {} : { datasetVersion: options.run.datasetVersion },
|
|
1426
|
-
...options.run?.metadata === void 0 ? {} : { metadata: options.run.metadata }
|
|
1511
|
+
startedAt: new Date(startedAtMs).toISOString()
|
|
1427
1512
|
};
|
|
1513
|
+
if (options.run?.datasetName !== void 0) run.datasetName = options.run.datasetName;
|
|
1514
|
+
if (options.run?.datasetVersion !== void 0) run.datasetVersion = options.run.datasetVersion;
|
|
1515
|
+
if (options.run?.metadata !== void 0) run.metadata = options.run.metadata;
|
|
1516
|
+
return run;
|
|
1428
1517
|
}
|
|
1429
|
-
async function notifyRunStart(reporters, args,
|
|
1518
|
+
async function notifyRunStart(reporters, args, errorPolicy) {
|
|
1430
1519
|
const errors = [];
|
|
1431
1520
|
for (const reporter of reporters) {
|
|
1432
1521
|
if (reporter.onRunStart === void 0) continue;
|
|
1433
1522
|
try {
|
|
1434
1523
|
await reporter.onRunStart(args);
|
|
1435
1524
|
} catch (error) {
|
|
1436
|
-
if (failOnReporterError) throw error;
|
|
1437
1525
|
errors.push(error);
|
|
1438
1526
|
}
|
|
1439
1527
|
}
|
|
1528
|
+
throwReporterErrors("onRunStart", errors, errorPolicy);
|
|
1440
1529
|
return errors;
|
|
1441
1530
|
}
|
|
1442
|
-
async function notifyRunEnd(reporters, args,
|
|
1531
|
+
async function notifyRunEnd(reporters, args, errorPolicy = "collect") {
|
|
1443
1532
|
const errors = [];
|
|
1444
1533
|
for (const reporter of reporters) {
|
|
1445
1534
|
if (reporter.onRunEnd === void 0) continue;
|
|
1446
1535
|
try {
|
|
1447
1536
|
await reporter.onRunEnd(args);
|
|
1448
1537
|
} catch (error) {
|
|
1449
|
-
if (failOnReporterError) throw error;
|
|
1450
1538
|
errors.push(error);
|
|
1451
1539
|
}
|
|
1452
1540
|
}
|
|
1541
|
+
throwReporterErrors("onRunEnd", errors, errorPolicy);
|
|
1453
1542
|
return errors;
|
|
1454
1543
|
}
|
|
1544
|
+
function throwReporterErrors(phase, errors, errorPolicy) {
|
|
1545
|
+
if (errorPolicy === "throw" && errors.length > 0) {
|
|
1546
|
+
throw new EvalReporterDispatchError(phase, errors);
|
|
1547
|
+
}
|
|
1548
|
+
}
|
|
1455
1549
|
function countMetricOutcomes(results) {
|
|
1456
1550
|
const totals = emptyTotals();
|
|
1457
1551
|
for (const result of results) {
|
|
@@ -1706,18 +1800,21 @@ function jsonResult(result) {
|
|
|
1706
1800
|
}
|
|
1707
1801
|
function expectationMismatches(result, expectations) {
|
|
1708
1802
|
if (expectations === void 0) return [];
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1803
|
+
const mismatches = [];
|
|
1804
|
+
if (expectations.totals !== void 0) {
|
|
1805
|
+
mismatches.push(...totalMismatches(result, expectations.totals));
|
|
1806
|
+
}
|
|
1807
|
+
if (expectations.outcomes !== void 0) {
|
|
1808
|
+
mismatches.push(...outcomeMismatches(result, expectations.outcomes));
|
|
1809
|
+
}
|
|
1810
|
+
return mismatches;
|
|
1713
1811
|
}
|
|
1714
1812
|
function totalMismatches(result, expected) {
|
|
1715
|
-
const directMetrics = {
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
};
|
|
1813
|
+
const directMetrics = {};
|
|
1814
|
+
if (expected.total !== void 0) directMetrics.total = expected.total;
|
|
1815
|
+
if (expected.passed !== void 0) directMetrics.passed = expected.passed;
|
|
1816
|
+
if (expected.failed !== void 0) directMetrics.failed = expected.failed;
|
|
1817
|
+
if (expected.invalid !== void 0) directMetrics.invalid = expected.invalid;
|
|
1721
1818
|
return [
|
|
1722
1819
|
...totalsGroupMismatches("metrics", result.metrics, {
|
|
1723
1820
|
...directMetrics,
|
|
@@ -1996,9 +2093,9 @@ function semanticSimilarity(options) {
|
|
|
1996
2093
|
if (typeof expected !== "string") {
|
|
1997
2094
|
return EvalOutcome.invalid("Semantic similarity expected value must be a string.");
|
|
1998
2095
|
}
|
|
1999
|
-
const [actualEmbedding, expectedEmbedding] = await Promise.all([
|
|
2000
|
-
embedText(options.model, actual),
|
|
2001
|
-
embedText(options.model, expected)
|
|
2096
|
+
const [{ embedding: actualEmbedding }, { embedding: expectedEmbedding }] = await Promise.all([
|
|
2097
|
+
embedText({ model: options.model, text: actual }),
|
|
2098
|
+
embedText({ model: options.model, text: expected })
|
|
2002
2099
|
]);
|
|
2003
2100
|
const score = cosineSimilarity(actualEmbedding.vector, expectedEmbedding.vector);
|
|
2004
2101
|
return score >= options.threshold ? EvalOutcome.pass(score) : EvalOutcome.fail(score, { comment: `Similarity below threshold ${options.threshold}.` });
|
|
@@ -2006,18 +2103,19 @@ function semanticSimilarity(options) {
|
|
|
2006
2103
|
};
|
|
2007
2104
|
}
|
|
2008
2105
|
function llmJudge(options) {
|
|
2009
|
-
const extractor = new ExtractorBuilder(options.model, options.schema).instructions(
|
|
2010
|
-
options.instructions ?? "Judge the eval case by the requested schema. Submit the judgment using the schema."
|
|
2011
|
-
).retries(options.retries ?? 0).build();
|
|
2012
2106
|
return {
|
|
2013
2107
|
name: options.name ?? "llm_judge",
|
|
2014
2108
|
required: options.required ?? true,
|
|
2015
2109
|
async evaluate(args) {
|
|
2016
2110
|
try {
|
|
2017
|
-
const result = await
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2111
|
+
const result = await extract({
|
|
2112
|
+
model: options.model,
|
|
2113
|
+
outputSchema: options.schema,
|
|
2114
|
+
instructions: options.instructions ?? "Judge the eval case by the requested schema. Submit the judgment using the schema.",
|
|
2115
|
+
text: await resolveJudgePrompt(options.prompt, args),
|
|
2116
|
+
retries: evalExtractionRetries(options.retries)
|
|
2117
|
+
});
|
|
2118
|
+
return options.passes(result.output) ? EvalOutcome.pass(result.output, { usage: result.usage }) : EvalOutcome.fail(result.output, { usage: result.usage });
|
|
2021
2119
|
} catch (error) {
|
|
2022
2120
|
return EvalOutcome.invalid(errorMessage(error));
|
|
2023
2121
|
}
|
|
@@ -2026,18 +2124,6 @@ function llmJudge(options) {
|
|
|
2026
2124
|
}
|
|
2027
2125
|
function llmScore(options) {
|
|
2028
2126
|
const criteria = Array.isArray(options.criteria) ? options.criteria.join("\n") : options.criteria;
|
|
2029
|
-
const extractor = new ExtractorBuilder(
|
|
2030
|
-
options.model,
|
|
2031
|
-
z2.object({
|
|
2032
|
-
score: z2.number(),
|
|
2033
|
-
feedback: z2.string()
|
|
2034
|
-
})
|
|
2035
|
-
).instructions(
|
|
2036
|
-
options.instructions ?? `Score the eval case against these criteria:
|
|
2037
|
-
${criteria}
|
|
2038
|
-
|
|
2039
|
-
Return a score between 0 and 1 and brief feedback.`
|
|
2040
|
-
).retries(options.retries ?? 0).build();
|
|
2041
2127
|
return {
|
|
2042
2128
|
name: options.name ?? "llm_score",
|
|
2043
2129
|
required: options.required ?? true,
|
|
@@ -2047,10 +2133,20 @@ Return a score between 0 and 1 and brief feedback.`
|
|
|
2047
2133
|
threshold: options.threshold,
|
|
2048
2134
|
async evaluate(args) {
|
|
2049
2135
|
try {
|
|
2050
|
-
const result = await
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2136
|
+
const result = await extract({
|
|
2137
|
+
model: options.model,
|
|
2138
|
+
outputSchema: z2.object({
|
|
2139
|
+
score: z2.number(),
|
|
2140
|
+
feedback: z2.string()
|
|
2141
|
+
}),
|
|
2142
|
+
instructions: options.instructions ?? `Score the eval case against these criteria:
|
|
2143
|
+
${criteria}
|
|
2144
|
+
|
|
2145
|
+
Return a score between 0 and 1 and brief feedback.`,
|
|
2146
|
+
text: await resolveJudgePrompt(options.prompt, args),
|
|
2147
|
+
retries: evalExtractionRetries(options.retries)
|
|
2148
|
+
});
|
|
2149
|
+
const score = result.output;
|
|
2054
2150
|
if (score.score < 0 || score.score > 1) {
|
|
2055
2151
|
return EvalOutcome.invalid(`Score ${score.score} outside valid range [0, 1].`, {
|
|
2056
2152
|
score,
|
|
@@ -2064,6 +2160,13 @@ Return a score between 0 and 1 and brief feedback.`
|
|
|
2064
2160
|
}
|
|
2065
2161
|
};
|
|
2066
2162
|
}
|
|
2163
|
+
function evalExtractionRetries(retries) {
|
|
2164
|
+
const retryCount = Math.max(0, Math.trunc(retries ?? 0));
|
|
2165
|
+
if (retryCount === 0) {
|
|
2166
|
+
return void 0;
|
|
2167
|
+
}
|
|
2168
|
+
return { maxAttempts: retryCount + 1 };
|
|
2169
|
+
}
|
|
2067
2170
|
|
|
2068
2171
|
// src/evals/suite.ts
|
|
2069
2172
|
function defineEvalCases(cases) {
|
|
@@ -2078,8 +2181,10 @@ function defineEvalSuite(options) {
|
|
|
2078
2181
|
};
|
|
2079
2182
|
}
|
|
2080
2183
|
export {
|
|
2184
|
+
AgentEvalSuspensionError,
|
|
2081
2185
|
EvalAssertionError,
|
|
2082
2186
|
EvalOutcome,
|
|
2187
|
+
EvalReporterDispatchError,
|
|
2083
2188
|
abstention,
|
|
2084
2189
|
agentEvalTarget,
|
|
2085
2190
|
answerRelevancy,
|