@mastra/evals 1.10.8-alpha.0 → 1.10.8-alpha.2

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,4 +1,4 @@
1
- import { analyzeToolFailures, checkTrajectoryBlacklist, checkTrajectoryEfficiency, compareTrajectories, extractAgentResponseMessages, extractToolCalls, getAssistantMessageFromRunOutput, getCombinedSystemPrompt, getConversationHistoryFromRunInput, getTextContentFromMastraDBMessage, getUserMessageFromRunInput, isScorerRunInputForAgent, isScorerRunOutputForAgent, roundToTwoDecimals } from "../utils.js";
1
+ import { analyzeToolFailures, checkTrajectoryBlacklist, checkTrajectoryEfficiency, compareTrajectories, extractAgentResponseMessages, extractToolCalls, getAssistantMessageFromRunOutput, getCombinedSystemPrompt, getConversationHistoryFromRunInput, getTextContentFromMastraDBMessage, getUserMessageFromRunInput, isScorerRunInputForAgent, isScorerRunOutputForAgent, roundToTwoDecimals, toToolLevelSteps } from "../utils.js";
2
2
  import { a as excludes, c as maxToolCalls, d as toolOrder, f as usedNoTools, i as equals, l as noToolErrors, n as checks, o as includes, r as didNotCall, s as matches, t as calledTool, u as similarity } from "../../checks-DxbqoaYq.js";
3
3
  import { createScorer } from "@mastra/core/evals";
4
4
  import nlp from "compromise";
@@ -3809,14 +3809,13 @@ function formatStepDetails(step) {
3809
3809
  if (step.toolResult !== void 0) parts.push(`result: ${JSON.stringify(step.toolResult)}`);
3810
3810
  return parts.length > 0 ? ` (${parts.join(", ")})` : "";
3811
3811
  }
3812
- case "model_generation": return step.modelId ? ` (model: ${step.modelId})` : "";
3813
3812
  case "workflow_step": return step.output !== void 0 ? ` (output: ${JSON.stringify(step.output)})` : "";
3814
3813
  default: return "";
3815
3814
  }
3816
3815
  }
3817
3816
  function formatTrajectory(trajectory, indent = 0) {
3818
3817
  const prefix = " ".repeat(indent);
3819
- return trajectory.steps.map((step, i) => {
3818
+ return toToolLevelSteps(trajectory.steps).map((step, i) => {
3820
3819
  let line = `${prefix}${i + 1}. [${step.stepType}] ${step.name}${formatStepDetails(step)}`;
3821
3820
  if (step.children && step.children.length > 0) line += `\n${formatTrajectory({ steps: step.children }, indent + 1)}`;
3822
3821
  return line;
@@ -4218,16 +4217,11 @@ function createToneScorer(config = {}) {
4218
4217
  //#region src/scorers/code/tool-call-accuracy/index.ts
4219
4218
  function checkToolOrder(actualTools, expectedOrder, strictMode = false) {
4220
4219
  if (strictMode) return JSON.stringify(actualTools) === JSON.stringify(expectedOrder);
4221
- const expectedIndices = [];
4220
+ let searchFrom = 0;
4222
4221
  for (const expectedTool of expectedOrder) {
4223
- const index = actualTools.indexOf(expectedTool);
4222
+ const index = actualTools.indexOf(expectedTool, searchFrom);
4224
4223
  if (index === -1) return false;
4225
- expectedIndices.push(index);
4226
- }
4227
- for (let i = 1; i < expectedIndices.length; i++) {
4228
- const currentIndex = expectedIndices[i];
4229
- const prevIndex = expectedIndices[i - 1];
4230
- if (currentIndex !== void 0 && prevIndex !== void 0 && currentIndex <= prevIndex) return false;
4224
+ searchFrom = index + 1;
4231
4225
  }
4232
4226
  return true;
4233
4227
  }
@@ -4351,7 +4345,7 @@ function createTrajectoryAccuracyScorerCode(options = {}) {
4351
4345
  actualTrajectory,
4352
4346
  expectedTrajectory: void 0,
4353
4347
  comparison: void 0,
4354
- actualStepNames: actualTrajectory.steps.map((s) => s.name),
4348
+ actualStepNames: toToolLevelSteps(actualTrajectory.steps).map((s) => s.name),
4355
4349
  expectedStepNames: [],
4356
4350
  error: "No expected trajectory provided (pass via options or dataset item expectedTrajectory)"
4357
4351
  };
@@ -4366,7 +4360,7 @@ function createTrajectoryAccuracyScorerCode(options = {}) {
4366
4360
  actualTrajectory,
4367
4361
  expectedTrajectory: { steps: resolvedExpectedSteps },
4368
4362
  comparison,
4369
- actualStepNames: actualTrajectory.steps.map((s) => s.name),
4363
+ actualStepNames: toToolLevelSteps(actualTrajectory.steps).map((s) => s.name),
4370
4364
  expectedStepNames: resolvedExpectedSteps.map((s) => s.name)
4371
4365
  };
4372
4366
  }).generateScore(({ results }) => {
@@ -4389,12 +4383,13 @@ function evaluateNestedExpectations(expectedSteps, actualSteps, weights = {
4389
4383
  blacklist: .1
4390
4384
  }) {
4391
4385
  const results = [];
4392
- const matchedIndices = /* @__PURE__ */ new Set();
4386
+ const matchedSteps = /* @__PURE__ */ new Set();
4387
+ const toolLevelSteps = toToolLevelSteps(actualSteps);
4388
+ const containerNames = new Set(actualSteps.filter((s) => s.stepType === "model_generation" || s.stepType === "processor_run").map((s) => s.name));
4393
4389
  for (const expectedStep of expectedSteps) {
4394
4390
  if (!expectedStep.children) continue;
4395
- const matchIndex = actualSteps.findIndex((s, i) => !matchedIndices.has(i) && s.name === expectedStep.name && (!expectedStep.stepType || s.stepType === expectedStep.stepType));
4396
- const actualStep = matchIndex >= 0 ? actualSteps[matchIndex] : void 0;
4397
- if (matchIndex >= 0) matchedIndices.add(matchIndex);
4391
+ const actualStep = (expectedStep.stepType === "model_generation" || expectedStep.stepType === "processor_run" || !expectedStep.stepType && containerNames.has(expectedStep.name) ? actualSteps : toolLevelSteps).find((s) => !matchedSteps.has(s) && s.name === expectedStep.name && (!expectedStep.stepType || s.stepType === expectedStep.stepType));
4392
+ if (actualStep) matchedSteps.add(actualStep);
4398
4393
  if (!actualStep) {
4399
4394
  const expectedStepCount = expectedStep.children.steps?.length ?? 0;
4400
4395
  results.push({