@mastra/evals 1.10.1 → 1.10.2-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/scorers/code/trajectory/index.d.ts.map +1 -1
- package/dist/scorers/prebuilt/index.cjs +14 -12
- package/dist/scorers/prebuilt/index.cjs.map +1 -1
- package/dist/scorers/prebuilt/index.js +14 -12
- package/dist/scorers/prebuilt/index.js.map +1 -1
- package/package.json +3 -3
package/dist/docs/SKILL.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/scorers/code/trajectory/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,UAAU,EACV,2BAA2B,EAC3B,qBAAqB,EAEtB,MAAM,oBAAoB,CAAC;AAQ5B,OAAO,KAAK,EACV,0BAA0B,EAC1B,0BAA0B,EAC1B,yBAAyB,EACzB,yBAAyB,EAC1B,MAAM,aAAa,CAAC;AAErB,UAAU,mCAAmC;IAC3C;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,UAAU,GAAG,YAAY,EAAE,CAAC;IACjD,kCAAkC;IAClC,iBAAiB,CAAC,EAAE,2BAA2B,CAAC;CACjD;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/scorers/code/trajectory/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,UAAU,EACV,2BAA2B,EAC3B,qBAAqB,EAEtB,MAAM,oBAAoB,CAAC;AAQ5B,OAAO,KAAK,EACV,0BAA0B,EAC1B,0BAA0B,EAC1B,yBAAyB,EACzB,yBAAyB,EAC1B,MAAM,aAAa,CAAC;AAErB,UAAU,mCAAmC;IAC3C;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,UAAU,GAAG,YAAY,EAAE,CAAC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,MAAM,WAAW,2BAA2B;IAC1C;;;OAGG;IACH,QAAQ,CAAC,EAAE,qBAAqB,CAAC;IACjC;;;;OAIG;IACH,OAAO,CAAC,EAAE,sBAAsB,CAAC;CAClC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,GAAE,2BAAgC;;;;;;;6FA0NnF"}
|
|
@@ -4295,7 +4295,6 @@ function trajectoryStepToExpectedStep(step) {
|
|
|
4295
4295
|
* suitable for comparison.
|
|
4296
4296
|
*/
|
|
4297
4297
|
function expectationToExpectedSteps(expectation) {
|
|
4298
|
-
if (!expectation.steps || expectation.steps.length === 0) return void 0;
|
|
4299
4298
|
return expectation.steps;
|
|
4300
4299
|
}
|
|
4301
4300
|
/**
|
|
@@ -4334,7 +4333,7 @@ function expectationToExpectedSteps(expectation) {
|
|
|
4334
4333
|
function createTrajectoryAccuracyScorerCode(options = {}) {
|
|
4335
4334
|
const { expectedTrajectory: staticExpectedTrajectory, comparisonOptions = {} } = options;
|
|
4336
4335
|
const { ordering = "relaxed", allowRepeatedSteps = true } = comparisonOptions;
|
|
4337
|
-
const staticExpectedSteps =
|
|
4336
|
+
const staticExpectedSteps = Array.isArray(staticExpectedTrajectory) ? staticExpectedTrajectory : staticExpectedTrajectory?.steps.map(trajectoryStepToExpectedStep);
|
|
4338
4337
|
const getDescription = () => {
|
|
4339
4338
|
if (staticExpectedSteps) return `Evaluates whether the trajectory matches the expected path: [${staticExpectedSteps.map((s) => s.name).join(" → ")}] (${ordering} ordering)`;
|
|
4340
4339
|
return `Evaluates trajectory accuracy against expected trajectory from dataset items (${ordering} ordering)`;
|
|
@@ -4351,7 +4350,7 @@ function createTrajectoryAccuracyScorerCode(options = {}) {
|
|
|
4351
4350
|
const expectation = run.expectedTrajectory;
|
|
4352
4351
|
resolvedExpectedSteps = expectationToExpectedSteps(expectation);
|
|
4353
4352
|
}
|
|
4354
|
-
if (!resolvedExpectedSteps
|
|
4353
|
+
if (!resolvedExpectedSteps) return {
|
|
4355
4354
|
actualTrajectory,
|
|
4356
4355
|
expectedTrajectory: void 0,
|
|
4357
4356
|
comparison: void 0,
|
|
@@ -4379,6 +4378,9 @@ function createTrajectoryAccuracyScorerCode(options = {}) {
|
|
|
4379
4378
|
return preprocessResult.comparison.score;
|
|
4380
4379
|
});
|
|
4381
4380
|
}
|
|
4381
|
+
function hasBlacklistViolation(results) {
|
|
4382
|
+
return results.some((result) => result.blacklist?.score === 0 || hasBlacklistViolation(result.nested ?? []));
|
|
4383
|
+
}
|
|
4382
4384
|
/**
|
|
4383
4385
|
* Evaluates nested expectations: for each expected step with a `children` config,
|
|
4384
4386
|
* finds the matching actual step and recursively evaluates its children.
|
|
@@ -4396,7 +4398,7 @@ function evaluateNestedExpectations(expectedSteps, actualSteps, weights = {
|
|
|
4396
4398
|
const matchIndex = actualSteps.findIndex((s, i) => !matchedIndices.has(i) && s.name === expectedStep.name && (!expectedStep.stepType || s.stepType === expectedStep.stepType));
|
|
4397
4399
|
const actualStep = matchIndex >= 0 ? actualSteps[matchIndex] : void 0;
|
|
4398
4400
|
if (matchIndex >= 0) matchedIndices.add(matchIndex);
|
|
4399
|
-
if (!actualStep
|
|
4401
|
+
if (!actualStep) {
|
|
4400
4402
|
const expectedStepCount = expectedStep.children.steps?.length ?? 0;
|
|
4401
4403
|
results.push({
|
|
4402
4404
|
stepName: expectedStep.name,
|
|
@@ -4415,12 +4417,12 @@ function evaluateNestedExpectations(expectedSteps, actualSteps, weights = {
|
|
|
4415
4417
|
continue;
|
|
4416
4418
|
}
|
|
4417
4419
|
const childTrajectory = {
|
|
4418
|
-
steps: actualStep.children,
|
|
4420
|
+
steps: actualStep.children ?? [],
|
|
4419
4421
|
totalDurationMs: actualStep.durationMs
|
|
4420
4422
|
};
|
|
4421
4423
|
const childConfig = expectedStep.children;
|
|
4422
4424
|
let accuracy;
|
|
4423
|
-
if (childConfig.steps
|
|
4425
|
+
if (childConfig.steps) accuracy = require_scorers_utils.compareTrajectories(childTrajectory, { steps: childConfig.steps }, {
|
|
4424
4426
|
ordering: childConfig.ordering ?? "relaxed",
|
|
4425
4427
|
allowRepeatedSteps: childConfig.allowRepeatedSteps ?? true
|
|
4426
4428
|
});
|
|
@@ -4435,7 +4437,7 @@ function evaluateNestedExpectations(expectedSteps, actualSteps, weights = {
|
|
|
4435
4437
|
blacklistedSequences: childConfig.blacklistedSequences
|
|
4436
4438
|
}) : void 0;
|
|
4437
4439
|
const toolFailures = require_scorers_utils.analyzeToolFailures(childTrajectory, { maxRetriesPerTool: childConfig.maxRetriesPerTool ?? 2 });
|
|
4438
|
-
const nested = childConfig.steps ? evaluateNestedExpectations(childConfig.steps,
|
|
4440
|
+
const nested = childConfig.steps ? evaluateNestedExpectations(childConfig.steps, childTrajectory.steps, weights) : [];
|
|
4439
4441
|
const scores = [];
|
|
4440
4442
|
if (accuracy) scores.push({
|
|
4441
4443
|
weight: weights.accuracy,
|
|
@@ -4474,7 +4476,7 @@ function evaluateNestedExpectations(expectedSteps, actualSteps, weights = {
|
|
|
4474
4476
|
}
|
|
4475
4477
|
let finalScore = levelScore;
|
|
4476
4478
|
if (nested.length > 0) {
|
|
4477
|
-
if (nested
|
|
4479
|
+
if (hasBlacklistViolation(nested)) {
|
|
4478
4480
|
results.push({
|
|
4479
4481
|
stepName: expectedStep.name,
|
|
4480
4482
|
score: 0,
|
|
@@ -4556,7 +4558,7 @@ function createTrajectoryScorerCode(options = {}) {
|
|
|
4556
4558
|
};
|
|
4557
4559
|
if (itemExpectation.steps !== void 0) config.steps = itemExpectation.steps;
|
|
4558
4560
|
let accuracy;
|
|
4559
|
-
if (config.steps
|
|
4561
|
+
if (config.steps) accuracy = require_scorers_utils.compareTrajectories(actualTrajectory, { steps: config.steps }, {
|
|
4560
4562
|
ordering: config.ordering ?? "relaxed",
|
|
4561
4563
|
allowRepeatedSteps: config.allowRepeatedSteps ?? true
|
|
4562
4564
|
});
|
|
@@ -4607,7 +4609,7 @@ function createTrajectoryScorerCode(options = {}) {
|
|
|
4607
4609
|
levelScore = totalWeight > 0 ? scores.reduce((sum, s) => sum + s.weight / totalWeight * s.value, 0) : 1;
|
|
4608
4610
|
}
|
|
4609
4611
|
if (nested && nested.length > 0) {
|
|
4610
|
-
if (nested
|
|
4612
|
+
if (hasBlacklistViolation(nested)) return 0;
|
|
4611
4613
|
const nestedAvg = nested.reduce((sum, r) => sum + r.score, 0) / nested.length;
|
|
4612
4614
|
levelScore = .7 * levelScore + .3 * nestedAvg;
|
|
4613
4615
|
}
|
|
@@ -4623,8 +4625,8 @@ function createTrajectoryScorerCode(options = {}) {
|
|
|
4623
4625
|
parts.push(`Blacklist violation: ${violations.join(". ")}.`);
|
|
4624
4626
|
return parts.join("\n");
|
|
4625
4627
|
}
|
|
4626
|
-
if (nested && nested
|
|
4627
|
-
const violating = nested.filter((r) => r
|
|
4628
|
+
if (nested && hasBlacklistViolation(nested)) {
|
|
4629
|
+
const violating = nested.filter((r) => hasBlacklistViolation([r])).map((r) => r.stepName);
|
|
4628
4630
|
parts.push(`Nested blacklist violation in: ${violating.join(", ")}.`);
|
|
4629
4631
|
return parts.join("\n");
|
|
4630
4632
|
}
|