@mastra/evals 1.2.0-alpha.0 → 1.2.0-alpha.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/CHANGELOG.md CHANGED
@@ -1,5 +1,33 @@
1
1
  # @mastra/evals
2
2
 
3
+ ## 1.2.0-alpha.1
4
+
5
+ ### Patch Changes
6
+
7
+ - **Configurable weights**: Add `weights` option to `createTrajectoryScorerCode` for controlling how dimension scores are combined. Defaults to `{ accuracy: 0.4, efficiency: 0.3, toolFailures: 0.2, blacklist: 0.1 }`. ([#14740](https://github.com/mastra-ai/mastra/pull/14740))
8
+
9
+ ```ts
10
+ const scorer = createTrajectoryScorerCode({
11
+ defaults: { steps: [{ name: 'search' }], maxSteps: 5 },
12
+ weights: { accuracy: 0.6, efficiency: 0.2, toolFailures: 0.1, blacklist: 0.1 },
13
+ });
14
+ ```
15
+
16
+ **ExpectedStep redesign**: `ExpectedStep` is now a discriminated union mirroring `TrajectoryStep`. When you specify a `stepType`, you get autocomplete for that variant's fields (e.g., `toolArgs` for `tool_call`, `modelId` for `model_generation`). The old `data: Record<string, unknown>` field is replaced by direct variant fields.
17
+
18
+ ```ts
19
+ // Before: { name: 'search', stepType: 'tool_call', data: { input: { query: 'weather' } } }
20
+ // After:
21
+ { name: 'search', stepType: 'tool_call', toolArgs: { query: 'weather' } }
22
+ ```
23
+
24
+ **Remove `compareStepData`**: The `compareStepData` option is removed from `compareTrajectories`, `TrajectoryExpectation`, and all scorers. Data fields are now auto-compared when present on expected steps — if you specify `toolArgs` on an `ExpectedStep`, it will be compared against the actual step. If you omit it, only name and stepType are matched.
25
+
26
+ Also fixes documentation inaccuracies in `trajectory-accuracy.mdx` and `scorer-utils.mdx`.
27
+
28
+ - Updated dependencies [[`e333b77`](https://github.com/mastra-ai/mastra/commit/e333b77e2d76ba57ccec1818e08cebc1993469ff), [`60a224d`](https://github.com/mastra-ai/mastra/commit/60a224dd497240e83698cfa5bfd02e3d1d854844), [`949b7bf`](https://github.com/mastra-ai/mastra/commit/949b7bfd4e40f2b2cba7fef5eb3f108a02cfe938), [`d084b66`](https://github.com/mastra-ai/mastra/commit/d084b6692396057e83c086b954c1857d20b58a14), [`79c699a`](https://github.com/mastra-ai/mastra/commit/79c699acf3cd8a77e11c55530431f48eb48456e9), [`62757b6`](https://github.com/mastra-ai/mastra/commit/62757b6db6e8bb86569d23ad0b514178f57053f8), [`3d70b0b`](https://github.com/mastra-ai/mastra/commit/3d70b0b3524d817173ad870768f259c06d61bd23), [`3b45a13`](https://github.com/mastra-ai/mastra/commit/3b45a138d09d040779c0aba1edbbfc1b57442d23), [`8127d96`](https://github.com/mastra-ai/mastra/commit/8127d96280492e335d49b244501088dfdd59a8f1)]:
29
+ - @mastra/core@1.18.0-alpha.3
30
+
3
31
  ## 1.2.0-alpha.0
4
32
 
5
33
  ### Minor Changes
@@ -216,42 +216,10 @@ function extractToolResults(output) {
216
216
  return results;
217
217
  }
218
218
  function compareTrajectories(actual, expected, options = {}) {
219
- const { compareStepData = false, allowRepeatedSteps = true } = options;
220
- const trajectoryStepKeys = [
221
- "toolArgs",
222
- "toolResult",
223
- "agentId",
224
- "modelId",
225
- "durationMs",
226
- "success",
227
- "promptTokens",
228
- "completionTokens"
229
- ];
230
- const hasTrajectorySteps = expected.steps.length > 0 && expected.steps.some((s) => trajectoryStepKeys.some((k) => k in s));
231
- let normalizedExpected;
232
- if (hasTrajectorySteps) {
233
- normalizedExpected = {
234
- steps: expected.steps.map((s) => {
235
- const stepData = getStepData(s);
236
- const data = {};
237
- if (stepData.input !== void 0) data.input = stepData.input;
238
- if (stepData.output !== void 0) data.output = stepData.output;
239
- return {
240
- name: s.name,
241
- stepType: s.stepType,
242
- ...Object.keys(data).length > 0 ? { data } : {}
243
- };
244
- })
245
- };
246
- } else {
247
- normalizedExpected = expected;
248
- }
249
- let ordering = "relaxed";
250
- if (options.ordering) {
251
- ordering = options.ordering;
252
- } else if (options.strictOrder) {
253
- ordering = "strict";
254
- }
219
+ const { allowRepeatedSteps = true, ordering = "relaxed" } = options;
220
+ const normalizedExpected = {
221
+ steps: expected.steps
222
+ };
255
223
  if (normalizedExpected.steps.length === 0) {
256
224
  return {
257
225
  score: actual.steps.length === 0 ? 1 : 0,
@@ -271,16 +239,12 @@ function compareTrajectories(actual, expected, options = {}) {
271
239
  }
272
240
  const repeatedSteps = [...nameCounts.entries()].filter(([_, count]) => count > 1).map(([name]) => name);
273
241
  if (ordering === "strict") {
274
- return compareStrictOrder(actual, normalizedExpected, { compareStepData, allowRepeatedSteps, repeatedSteps });
242
+ return compareStrictOrder(actual, normalizedExpected, { allowRepeatedSteps, repeatedSteps });
275
243
  }
276
244
  if (ordering === "unordered") {
277
- return compareUnorderedPresence(actual, normalizedExpected, {
278
- compareStepData,
279
- allowRepeatedSteps,
280
- repeatedSteps
281
- });
245
+ return compareUnorderedPresence(actual, normalizedExpected, { allowRepeatedSteps, repeatedSteps });
282
246
  }
283
- return compareRelaxedOrder(actual, normalizedExpected, { compareStepData, allowRepeatedSteps, repeatedSteps });
247
+ return compareRelaxedOrder(actual, normalizedExpected, { allowRepeatedSteps, repeatedSteps });
284
248
  }
285
249
  function compareStrictOrder(actual, expected, opts) {
286
250
  const actualNames = actual.steps.map((s) => s.name);
@@ -293,13 +257,8 @@ function compareStrictOrder(actual, expected, opts) {
293
257
  const actualName = actualNames[i];
294
258
  const expectedName = expectedNames[i];
295
259
  if (actualName === expectedName) {
296
- if (opts.compareStepData && actual.steps[i] && expected.steps[i]) {
297
- if (expectedStepMatches(actual.steps[i], expected.steps[i], true)) {
298
- matchedSteps++;
299
- matchedExpectedIndices.add(i);
300
- }
301
- } else if (actual.steps[i] && expected.steps[i]) {
302
- if (expectedStepMatches(actual.steps[i], expected.steps[i], false)) {
260
+ if (actual.steps[i] && expected.steps[i]) {
261
+ if (expectedStepMatches(actual.steps[i], expected.steps[i])) {
303
262
  matchedSteps++;
304
263
  matchedExpectedIndices.add(i);
305
264
  }
@@ -345,7 +304,7 @@ function compareRelaxedOrder(actual, expected, opts) {
345
304
  for (let j = lastMatchedIndex + 1; j < actualNames.length; j++) {
346
305
  if (actualNames[j] === expectedName) {
347
306
  if (actual.steps[j] && expected.steps[i]) {
348
- if (expectedStepMatches(actual.steps[j], expected.steps[i], opts.compareStepData)) {
307
+ if (expectedStepMatches(actual.steps[j], expected.steps[i])) {
349
308
  matchedSteps++;
350
309
  lastMatchedIndex = j;
351
310
  matchedExpectedIndices.add(i);
@@ -385,27 +344,32 @@ function compareRelaxedOrder(actual, expected, opts) {
385
344
  repeatedSteps: opts.repeatedSteps
386
345
  };
387
346
  }
388
- function getStepData(step) {
389
- switch (step.stepType) {
390
- case "tool_call":
391
- case "mcp_tool_call":
392
- return { input: step.toolArgs, output: step.toolResult };
393
- case "workflow_step":
394
- return { output: step.output };
395
- default:
396
- return {};
397
- }
398
- }
399
- function expectedStepMatches(actual, expected, compareData) {
347
+ var COMPARABLE_FIELDS_BY_TYPE = {
348
+ tool_call: ["toolArgs", "toolResult", "success"],
349
+ mcp_tool_call: ["toolArgs", "toolResult", "mcpServer", "success"],
350
+ model_generation: ["modelId", "promptTokens", "completionTokens", "finishReason"],
351
+ agent_run: ["agentId"],
352
+ workflow_step: ["stepId", "status", "output"],
353
+ workflow_run: ["workflowId", "status"],
354
+ workflow_conditional: ["conditionCount", "selectedSteps"],
355
+ workflow_parallel: ["branchCount", "parallelSteps"],
356
+ workflow_loop: ["loopType", "totalIterations"],
357
+ workflow_sleep: ["sleepDurationMs", "sleepType"],
358
+ workflow_wait_event: ["eventName", "eventReceived"],
359
+ processor_run: ["processorId"]
360
+ };
361
+ function expectedStepMatches(actual, expected) {
400
362
  if (actual.name !== expected.name) return false;
401
363
  if (expected.stepType && actual.stepType !== expected.stepType) return false;
402
- if (compareData && expected.data) {
403
- const actualData = getStepData(actual);
404
- for (const [key, value] of Object.entries(expected.data)) {
405
- const actualField = key === "input" ? actualData.input : key === "output" ? actualData.output : void 0;
406
- if (actualField === void 0) return false;
364
+ if (expected.stepType) {
365
+ const fields = COMPARABLE_FIELDS_BY_TYPE[expected.stepType] ?? [];
366
+ for (const field of fields) {
367
+ const expectedVal = expected[field];
368
+ if (expectedVal === void 0) continue;
369
+ const actualVal = actual[field];
370
+ if (actualVal === void 0) return false;
407
371
  try {
408
- if (JSON.stringify(actualField) !== JSON.stringify(value)) return false;
372
+ if (JSON.stringify(actualVal) !== JSON.stringify(expectedVal)) return false;
409
373
  } catch {
410
374
  return false;
411
375
  }
@@ -418,30 +382,15 @@ function compareUnorderedPresence(actual, expected, opts) {
418
382
  const expectedNames = expected.steps.map((s) => s.name);
419
383
  let matchedSteps = 0;
420
384
  const matchedExpectedIndices = /* @__PURE__ */ new Set();
421
- if (opts.compareStepData) {
422
- const usedIndices = /* @__PURE__ */ new Set();
423
- for (let i = 0; i < expected.steps.length; i++) {
424
- const expectedStep = expected.steps[i];
425
- for (let j = 0; j < actual.steps.length; j++) {
426
- if (!usedIndices.has(j) && expectedStepMatches(actual.steps[j], expectedStep, true)) {
427
- matchedSteps++;
428
- matchedExpectedIndices.add(i);
429
- usedIndices.add(j);
430
- break;
431
- }
432
- }
433
- }
434
- } else {
435
- const usedIndices = /* @__PURE__ */ new Set();
436
- for (let i = 0; i < expected.steps.length; i++) {
437
- const expectedStep = expected.steps[i];
438
- for (let j = 0; j < actual.steps.length; j++) {
439
- if (!usedIndices.has(j) && expectedStepMatches(actual.steps[j], expectedStep, false)) {
440
- matchedSteps++;
441
- matchedExpectedIndices.add(i);
442
- usedIndices.add(j);
443
- break;
444
- }
385
+ const usedIndices = /* @__PURE__ */ new Set();
386
+ for (let i = 0; i < expected.steps.length; i++) {
387
+ const expectedStep = expected.steps[i];
388
+ for (let j = 0; j < actual.steps.length; j++) {
389
+ if (!usedIndices.has(j) && expectedStepMatches(actual.steps[j], expectedStep)) {
390
+ matchedSteps++;
391
+ matchedExpectedIndices.add(i);
392
+ usedIndices.add(j);
393
+ break;
445
394
  }
446
395
  }
447
396
  }
@@ -628,5 +577,5 @@ exports.getTextContentFromMastraDBMessage = getTextContentFromMastraDBMessage;
628
577
  exports.getUserMessageFromRunInput = getUserMessageFromRunInput;
629
578
  exports.isCloserTo = isCloserTo;
630
579
  exports.roundToTwoDecimals = roundToTwoDecimals;
631
- //# sourceMappingURL=chunk-XRUR5PBK.cjs.map
632
- //# sourceMappingURL=chunk-XRUR5PBK.cjs.map
580
+ //# sourceMappingURL=chunk-AY4K3J4R.cjs.map
581
+ //# sourceMappingURL=chunk-AY4K3J4R.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/scorers/utils.ts"],"names":["requestContext","RequestContext"],"mappings":";;;;;;AAiCO,SAAS,kCAAkC,OAAA,EAAkC;AAClF,EAAA,IAAI,OAAO,QAAQ,OAAA,CAAQ,OAAA,KAAY,YAAY,OAAA,CAAQ,OAAA,CAAQ,YAAY,EAAA,EAAI;AACjF,IAAA,OAAO,QAAQ,OAAA,CAAQ,OAAA;AAAA,EACzB;AACA,EAAA,IAAI,OAAA,CAAQ,QAAQ,KAAA,IAAS,KAAA,CAAM,QAAQ,OAAA,CAAQ,OAAA,CAAQ,KAAK,CAAA,EAAG;AAEjE,IAAA,MAAM,SAAA,GAAY,QAAQ,OAAA,CAAQ,KAAA,CAAM,OAAO,CAAA,CAAA,KAAK,CAAA,CAAE,SAAS,MAAM,CAAA;AACrE,IAAA,OAAO,SAAA,CAAU,SAAS,CAAA,GAAI,SAAA,CAAU,UAAU,MAAA,GAAS,CAAC,CAAA,EAAG,IAAA,IAAQ,EAAA,GAAK,EAAA;AAAA,EAC9E;AACA,EAAA,OAAO,EAAA;AACT;AAgBO,IAAM,kBAAA,GAAqB,CAAC,GAAA,KAAgB;AACjD,EAAA,OAAO,KAAK,KAAA,CAAA,CAAO,GAAA,GAAM,MAAA,CAAO,OAAA,IAAW,GAAG,CAAA,GAAI,GAAA;AACpD;AAgBO,SAAS,UAAA,CAAW,KAAA,EAAe,OAAA,EAAiB,OAAA,EAA0B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AA,GAAQ,IAAA,CAAK,GAAA,CAAI,CAAA,EAAG,CAAA,GAAI,gBAAgB,GAAG,CAAA;AAAA,EAC7C;AAEA,EAAA,OAAO;AAAA,IACL,KAAA,EAAO,kBAAA,CAAmB,IAAA,CAAK,GAAA,CAAI,CAAA,EAAG,KAAK,GAAA,CAAI,CAAA,EAAG,KAAK,CAAC,CAAC,CAAA;AAAA,IACzD,QAAA;AAAA,IACA,YAAA;AAAA,IACA;AAAA,GACF;AACF","file":"chunk-AY4K3J4R.cjs","sourcesContent":["import type { MastraDBMessage } from '@mastra/core/agent';\nimport type {\n ExpectedStep,\n ScorerRunInputForAgent,\n ScorerRunOutputForAgent,\n ScoringInput,\n TrajectoryExpectation,\n TrajectoryStep,\n Trajectory,\n} from '@mastra/core/evals';\nimport { RequestContext } from '@mastra/core/request-context';\n\n/**\n * Extracts text content from a MastraDBMessage.\n *\n * This function matches the logic used in `MessageList.mastraDBMessageToAIV4UIMessage`.\n * It first checks for a string `content.content` field, then falls back to extracting\n * text from the `parts` array (returning only the last text part, like AI SDK does).\n *\n * @param message - The MastraDBMessage to extract text from\n * @returns The extracted text content, or an empty string if no text is found\n *\n * @example\n * ```ts\n * const message: MastraDBMessage = {\n * id: 'msg-1',\n * role: 'assistant',\n * content: { format: 2, parts: [{ type: 'text', text: 'Hello!' }] },\n * createdAt: new Date(),\n * };\n * const text = getTextContentFromMastraDBMessage(message); // 'Hello!'\n * ```\n */\nexport function getTextContentFromMastraDBMessage(message: MastraDBMessage): string {\n if (typeof message.content.content === 'string' && message.content.content !== '') {\n return message.content.content;\n }\n if (message.content.parts && Array.isArray(message.content.parts)) {\n // Return only the last text part like AI SDK does\n const textParts = message.content.parts.filter(p => p.type === 'text');\n return textParts.length > 0 ? textParts[textParts.length - 1]?.text || '' : '';\n }\n return '';\n}\n\n/**\n * Rounds a number to two decimal places.\n *\n * Uses `Number.EPSILON` to handle floating-point precision issues.\n *\n * @param num - The number to round\n * @returns The number rounded to two decimal places\n *\n * @example\n * ```ts\n * roundToTwoDecimals(0.1 + 0.2); // 0.3\n * roundToTwoDecimals(1.005); // 1.01\n * ```\n */\nexport const roundToTwoDecimals = (num: number) => {\n return Math.round((num + Number.EPSILON) * 100) / 100;\n};\n\n/**\n * Determines if a value is closer to the first target than the second.\n *\n * @param value - The value to compare\n * @param target1 - The first target value\n * @param target2 - The second target value\n * @returns `true` if `value` is closer to `target1` than `target2`\n *\n * @example\n * ```ts\n * isCloserTo(0.6, 1, 0); // true (0.6 is closer to 1)\n * isCloserTo(0.3, 1, 0); // false (0.3 is closer to 0)\n * ```\n */\nexport function isCloserTo(value: number, target1: number, target2: number): boolean {\n return Math.abs(value - target1) < Math.abs(value - target2);\n}\n\n/**\n * Represents a test case for scorer evaluation.\n */\nexport type TestCase = {\n /** The input text to evaluate */\n input: string;\n /** The output text to evaluate */\n output: string;\n /** The expected result of the evaluation */\n expectedResult: {\n /** The expected score */\n score: number;\n /** The optional expected reason */\n reason?: string;\n };\n};\n\n/**\n * Represents a test case with additional context for scorer evaluation.\n */\nexport type TestCaseWithContext = TestCase & {\n /** Additional context strings for the evaluation */\n context: string[];\n};\n\n/**\n * Creates a scoring input object for testing purposes.\n *\n * @param input - The user input text\n * @param output - The assistant output text\n * @param additionalContext - Optional additional context data\n * @param requestContext - Optional request context data\n * @returns A ScoringInput object ready for use in scorer tests\n *\n * @example\n * ```ts\n * const run = createTestRun(\n * 'What is 2+2?',\n * 'The answer is 4.',\n * { topic: 'math' }\n * );\n * ```\n */\nexport const createTestRun = (\n input: string,\n output: string,\n additionalContext?: Record<string, any>,\n requestContext?: Record<string, any>,\n): ScoringInput => {\n return {\n input: [{ role: 'user', content: input }],\n output: { role: 'assistant', text: output },\n additionalContext: additionalContext ?? {},\n requestContext: requestContext ?? {},\n };\n};\n\n/**\n * Extracts the user message text from a scorer run input.\n *\n * Finds the first message with role 'user' and extracts its text content.\n *\n * @param input - The scorer run input containing input messages\n * @returns The user message text, or `undefined` if no user message is found\n *\n * @example\n * ```ts\n * const scorer = createScorer({ ... })\n * .preprocess(({ run }) => {\n * const userText = getUserMessageFromRunInput(run.input);\n * return { userText };\n * });\n * ```\n */\nexport const getUserMessageFromRunInput = (input?: ScorerRunInputForAgent): string | undefined => {\n const message = input?.inputMessages.find(({ role }) => role === 'user');\n return message ? getTextContentFromMastraDBMessage(message) : undefined;\n};\n\n/**\n * Extracts all system messages from a scorer run input.\n *\n * Collects text from both standard system messages and tagged system messages\n * (specialized system prompts like memory instructions).\n *\n * @param input - The scorer run input containing system messages\n * @returns An array of system message strings\n *\n * @example\n * ```ts\n * const scorer = createScorer({ ... })\n * .preprocess(({ run }) => {\n * const systemMessages = getSystemMessagesFromRunInput(run.input);\n * return { systemPrompt: systemMessages.join('\\n') };\n * });\n * ```\n */\nexport const getSystemMessagesFromRunInput = (input?: ScorerRunInputForAgent): string[] => {\n const systemMessages: string[] = [];\n\n // Add standard system messages\n if (input?.systemMessages) {\n systemMessages.push(\n ...input.systemMessages\n .map(msg => {\n // Handle different content types - extract text if it's an array of parts\n if (typeof msg.content === 'string') {\n return msg.content;\n } else if (Array.isArray(msg.content)) {\n // Extract text from parts array\n return msg.content\n .filter((part: any) => part.type === 'text')\n .map((part: any) => part.text || '')\n .join(' ');\n }\n return '';\n })\n .filter(content => content),\n );\n }\n\n // Add tagged system messages (these are specialized system prompts)\n if (input?.taggedSystemMessages) {\n Object.values(input.taggedSystemMessages).forEach(messages => {\n messages.forEach(msg => {\n if (typeof msg.content === 'string') {\n systemMessages.push(msg.content);\n }\n });\n });\n }\n\n return systemMessages;\n};\n\n/**\n * Combines all system messages into a single prompt string.\n *\n * Joins all system messages (standard and tagged) with double newlines.\n *\n * @param input - The scorer run input containing system messages\n * @returns A combined system prompt string\n *\n * @example\n * ```ts\n * const scorer = createScorer({ ... })\n * .preprocess(({ run }) => {\n * const systemPrompt = getCombinedSystemPrompt(run.input);\n * return { systemPrompt };\n * });\n * ```\n */\nexport const getCombinedSystemPrompt = (input?: ScorerRunInputForAgent): string => {\n const systemMessages = getSystemMessagesFromRunInput(input);\n return systemMessages.join('\\n\\n');\n};\n\n/**\n * Extracts the assistant message text from a scorer run output.\n *\n * Finds the first message with role 'assistant' and extracts its text content.\n *\n * @param output - The scorer run output (array of MastraDBMessage)\n * @returns The assistant message text, or `undefined` if no assistant message is found\n *\n * @example\n * ```ts\n * const scorer = createScorer({ ... })\n * .preprocess(({ run }) => {\n * const response = getAssistantMessageFromRunOutput(run.output);\n * return { response };\n * });\n * ```\n */\nexport const getAssistantMessageFromRunOutput = (output?: ScorerRunOutputForAgent) => {\n const message = output?.find(({ role }) => role === 'assistant');\n return message ? getTextContentFromMastraDBMessage(message) : undefined;\n};\n\n/**\n * Extracts reasoning text from a scorer run output.\n *\n * This function extracts reasoning content from assistant messages, which is\n * produced by reasoning models like `deepseek-reasoner`. The reasoning can be\n * stored in two places:\n * 1. `content.reasoning` - a string field on the message content\n * 2. `content.parts` - as parts with `type: 'reasoning'` containing `details`\n *\n * @param output - The scorer run output (array of MastraDBMessage)\n * @returns The reasoning text, or `undefined` if no reasoning is present\n *\n * @example\n * ```ts\n * const reasoningScorer = createScorer({\n * id: 'reasoning-scorer',\n * name: 'Reasoning Quality',\n * description: 'Evaluates the quality of model reasoning',\n * type: 'agent',\n * })\n * .preprocess(({ run }) => {\n * const reasoning = getReasoningFromRunOutput(run.output);\n * const response = getAssistantMessageFromRunOutput(run.output);\n * return { reasoning, response };\n * })\n * .generateScore(({ results }) => {\n * // Score based on reasoning quality\n * return results.preprocessStepResult?.reasoning ? 1 : 0;\n * });\n * ```\n */\nexport const getReasoningFromRunOutput = (output?: ScorerRunOutputForAgent): string | undefined => {\n if (!output) return undefined;\n\n const message = output.find(({ role }) => role === 'assistant');\n if (!message) return undefined;\n\n // Check for reasoning in content.reasoning (string format)\n if (message.content.reasoning) {\n return message.content.reasoning;\n }\n\n // Check for reasoning in parts with type 'reasoning'\n // Reasoning models store reasoning in parts as { type: 'reasoning', details: [{ type: 'text', text: '...' }] }\n const reasoningParts = message.content.parts?.filter((p: any) => p.type === 'reasoning');\n if (reasoningParts && reasoningParts.length > 0) {\n const reasoningTexts = reasoningParts\n .map((p: any) => {\n // The reasoning text can be in p.reasoning or in p.details[].text\n if (p.details && Array.isArray(p.details)) {\n return p.details\n .filter((d: any) => d.type === 'text')\n .map((d: any) => d.text)\n .join('');\n }\n return p.reasoning || '';\n })\n .filter(Boolean);\n\n return reasoningTexts.length > 0 ? reasoningTexts.join('\\n') : undefined;\n }\n\n return undefined;\n};\n\n/**\n * Creates a tool invocation object for testing purposes.\n *\n * @param options - The tool invocation configuration\n * @param options.toolCallId - Unique identifier for the tool call\n * @param options.toolName - Name of the tool being called\n * @param options.args - Arguments passed to the tool\n * @param options.result - Result returned by the tool\n * @param options.state - State of the invocation (default: 'result')\n * @returns A tool invocation object\n *\n * @example\n * ```ts\n * const invocation = createToolInvocation({\n * toolCallId: 'call-123',\n * toolName: 'weatherTool',\n * args: { location: 'London' },\n * result: { temperature: 20, condition: 'sunny' },\n * });\n * ```\n */\nexport const createToolInvocation = ({\n toolCallId,\n toolName,\n args,\n result,\n state = 'result',\n}: {\n toolCallId: string;\n toolName: string;\n args: Record<string, any>;\n result: Record<string, any>;\n state?: 'call' | 'partial-call' | 'result';\n}): { toolCallId: string; toolName: string; args: Record<string, any>; result: Record<string, any>; state: string } => {\n return {\n toolCallId,\n toolName,\n args,\n result,\n state,\n };\n};\n\n/**\n * Creates a MastraDBMessage object for testing purposes.\n *\n * Supports optional tool invocations for testing tool call scenarios.\n *\n * @param options - The message configuration\n * @param options.content - The text content of the message\n * @param options.role - The role of the message sender ('user', 'assistant', or 'system')\n * @param options.id - Optional message ID (default: 'test-message')\n * @param options.toolInvocations - Optional array of tool invocations\n * @returns A MastraDBMessage object\n *\n * @example\n * ```ts\n * const message = createTestMessage({\n * content: 'Hello, how can I help?',\n * role: 'assistant',\n * });\n *\n * // With tool invocations\n * const messageWithTools = createTestMessage({\n * content: 'Let me check the weather.',\n * role: 'assistant',\n * toolInvocations: [{\n * toolCallId: 'call-1',\n * toolName: 'weatherTool',\n * args: { location: 'Paris' },\n * result: { temp: 22 },\n * state: 'result',\n * }],\n * });\n * ```\n */\nexport function createTestMessage({\n content,\n role,\n id = 'test-message',\n toolInvocations = [],\n}: {\n content: string;\n role: 'user' | 'assistant' | 'system';\n id?: string;\n toolInvocations?: Array<{\n toolCallId: string;\n toolName: string;\n args: Record<string, any>;\n result: Record<string, any>;\n state: any;\n }>;\n}): MastraDBMessage {\n return {\n id,\n role,\n content: {\n format: 2,\n parts: [{ type: 'text', text: content }],\n content,\n ...(toolInvocations.length > 0 && {\n toolInvocations: toolInvocations.map(ti => ({\n toolCallId: ti.toolCallId,\n toolName: ti.toolName,\n args: ti.args,\n result: ti.result,\n state: ti.state,\n })),\n }),\n },\n createdAt: new Date(),\n };\n}\n\n/**\n * Creates a complete agent test run object for testing scorers.\n *\n * Provides a convenient way to construct the full run object that scorers receive,\n * including input messages, output, system messages, and request context.\n *\n * @param options - The test run configuration\n * @param options.inputMessages - Array of input messages (default: [])\n * @param options.output - The output messages (required)\n * @param options.rememberedMessages - Array of remembered messages from memory (default: [])\n * @param options.systemMessages - Array of system messages (default: [])\n * @param options.taggedSystemMessages - Tagged system messages map (default: {})\n * @param options.requestContext - Request context (default: new RequestContext())\n * @param options.runId - Unique run ID (default: random UUID)\n * @returns A complete test run object\n *\n * @example\n * ```ts\n * const testRun = createAgentTestRun({\n * inputMessages: [createTestMessage({ content: 'Hello', role: 'user' })],\n * output: [createTestMessage({ content: 'Hi there!', role: 'assistant' })],\n * });\n *\n * const result = await scorer.run({\n * input: testRun.input,\n * output: testRun.output,\n * });\n * ```\n */\nexport const createAgentTestRun = ({\n inputMessages = [],\n output,\n rememberedMessages = [],\n systemMessages = [],\n taggedSystemMessages = {},\n requestContext = new RequestContext(),\n runId = crypto.randomUUID(),\n}: {\n inputMessages?: ScorerRunInputForAgent['inputMessages'];\n output: ScorerRunOutputForAgent;\n rememberedMessages?: ScorerRunInputForAgent['rememberedMessages'];\n systemMessages?: ScorerRunInputForAgent['systemMessages'];\n taggedSystemMessages?: ScorerRunInputForAgent['taggedSystemMessages'];\n requestContext?: RequestContext;\n runId?: string;\n}): {\n input: ScorerRunInputForAgent;\n output: ScorerRunOutputForAgent;\n requestContext: RequestContext;\n runId: string;\n} => {\n return {\n input: {\n inputMessages,\n rememberedMessages,\n systemMessages,\n taggedSystemMessages,\n },\n output,\n requestContext,\n runId,\n };\n};\n\n/**\n * Creates a test run for trajectory scorers where `output` is a `Trajectory`\n * (pre-extracted by the `runEvals` pipeline).\n *\n * @example\n * ```ts\n * const testRun = createTrajectoryTestRun({\n * inputMessages: [createTestMessage({ content: 'Do X', role: 'user', id: 'u1' })],\n * trajectory: {\n * steps: [\n * { stepType: 'tool_call', name: 'search', toolArgs: { q: 'test' } },\n * ],\n * },\n * });\n * ```\n */\nexport const createTrajectoryTestRun = ({\n inputMessages = [],\n trajectory,\n rememberedMessages = [],\n systemMessages = [],\n taggedSystemMessages = {},\n requestContext = new RequestContext(),\n runId = crypto.randomUUID(),\n expectedTrajectory,\n}: {\n inputMessages?: ScorerRunInputForAgent['inputMessages'];\n trajectory: Trajectory;\n rememberedMessages?: ScorerRunInputForAgent['rememberedMessages'];\n systemMessages?: ScorerRunInputForAgent['systemMessages'];\n taggedSystemMessages?: ScorerRunInputForAgent['taggedSystemMessages'];\n requestContext?: RequestContext;\n runId?: string;\n expectedTrajectory?: TrajectoryExpectation;\n}): {\n input: ScorerRunInputForAgent;\n output: Trajectory;\n requestContext: RequestContext;\n runId: string;\n expectedTrajectory?: TrajectoryExpectation;\n} => {\n return {\n input: {\n inputMessages,\n rememberedMessages,\n systemMessages,\n taggedSystemMessages,\n },\n output: trajectory,\n expectedTrajectory,\n requestContext,\n runId,\n };\n};\n\n/**\n * Information about a tool call extracted from scorer output.\n */\nexport type ToolCallInfo = {\n /** Name of the tool that was called */\n toolName: string;\n /** Unique identifier for the tool call */\n toolCallId: string;\n /** Index of the message containing this tool call */\n messageIndex: number;\n /** Index of the invocation within the message's tool invocations */\n invocationIndex: number;\n};\n\n/**\n * Extracts all tool calls from a scorer run output.\n *\n * Iterates through all messages and their tool invocations to collect\n * information about tools that were called (with state 'result' or 'call').\n *\n * @param output - The scorer run output (array of MastraDBMessage)\n * @returns An object containing tool names and detailed tool call info\n *\n * @example\n * ```ts\n * const scorer = createScorer({ ... })\n * .preprocess(({ run }) => {\n * const { tools, toolCallInfos } = extractToolCalls(run.output);\n * return {\n * toolsUsed: tools,\n * toolCount: tools.length,\n * };\n * });\n * ```\n */\nexport function extractToolCalls(output: ScorerRunOutputForAgent): { tools: string[]; toolCallInfos: ToolCallInfo[] } {\n const toolCalls: string[] = [];\n const toolCallInfos: ToolCallInfo[] = [];\n\n for (let messageIndex = 0; messageIndex < output.length; messageIndex++) {\n const message = output[messageIndex];\n // Tool invocations are now nested under content\n if (message?.content?.toolInvocations) {\n for (let invocationIndex = 0; invocationIndex < message.content.toolInvocations.length; invocationIndex++) {\n const invocation = message.content.toolInvocations[invocationIndex];\n if (invocation && invocation.toolName && (invocation.state === 'result' || invocation.state === 'call')) {\n toolCalls.push(invocation.toolName);\n toolCallInfos.push({\n toolName: invocation.toolName,\n toolCallId: invocation.toolCallId || `${messageIndex}-${invocationIndex}`,\n messageIndex,\n invocationIndex,\n });\n }\n }\n }\n }\n\n return { tools: toolCalls, toolCallInfos };\n}\n\n/**\n * Extracts text content from all input messages.\n *\n * @param runInput - The scorer run input\n * @returns An array of text strings from each input message\n *\n * @example\n * ```ts\n * const scorer = createScorer({ ... })\n * .preprocess(({ run }) => {\n * const messages = extractInputMessages(run.input);\n * return { allUserMessages: messages.join('\\n') };\n * });\n * ```\n */\nexport const extractInputMessages = (runInput: ScorerRunInputForAgent | undefined): string[] => {\n return runInput?.inputMessages?.map(msg => getTextContentFromMastraDBMessage(msg)) || [];\n};\n\n/**\n * Extracts text content from all assistant response messages.\n *\n * Filters for messages with role 'assistant' and extracts their text content.\n *\n * @param runOutput - The scorer run output (array of MastraDBMessage)\n * @returns An array of text strings from each assistant message\n *\n * @example\n * ```ts\n * const scorer = createScorer({ ... })\n * .preprocess(({ run }) => {\n * const responses = extractAgentResponseMessages(run.output);\n * return { allResponses: responses.join('\\n') };\n * });\n * ```\n */\nexport const extractAgentResponseMessages = (runOutput: ScorerRunOutputForAgent): string[] => {\n return runOutput.filter(msg => msg.role === 'assistant').map(msg => getTextContentFromMastraDBMessage(msg));\n};\n\n/**\n * Information about a tool result extracted from scorer output.\n */\nexport type ToolResultInfo = {\n /** Name of the tool that was called */\n toolName: string;\n /** Unique identifier for the tool call */\n toolCallId: string;\n /** Arguments passed to the tool */\n args: Record<string, any>;\n /** Result returned by the tool */\n result: any;\n};\n\n/**\n * Extracts tool results from a scorer run output.\n *\n * Returns structured objects that can be used with the hallucination scorer's\n * `getContext` hook or for other scorer logic.\n *\n * @param output - The scorer run output (array of MastraDBMessage)\n * @returns An array of ToolResultInfo objects\n *\n * @example\n * ```ts\n * import { extractToolResults } from '@mastra/evals/scorers';\n * import { createHallucinationScorer } from '@mastra/evals/scorers/prebuilt';\n *\n * const scorer = createHallucinationScorer({\n * model: openai('gpt-4o'),\n * options: {\n * getContext: (run) => {\n * const toolResults = extractToolResults(run.output);\n * return toolResults.map(t => JSON.stringify({ tool: t.toolName, result: t.result }));\n * },\n * },\n * });\n * ```\n */\nexport function extractToolResults(output: ScorerRunOutputForAgent): ToolResultInfo[] {\n const results: ToolResultInfo[] = [];\n\n for (const message of output) {\n const toolInvocations = message?.content?.toolInvocations;\n if (!toolInvocations) continue;\n\n for (const invocation of toolInvocations) {\n if (invocation.state === 'result' && invocation.result !== undefined) {\n results.push({\n toolName: invocation.toolName,\n toolCallId: invocation.toolCallId || '',\n args: invocation.args || {},\n result: invocation.result,\n });\n }\n }\n }\n\n return results;\n}\n\n// Re-export extractTrajectory from core — it's called automatically by runEvals\n// for trajectory scorers, but users may still want it for custom use cases.\nexport { extractTrajectory } from '@mastra/core/evals';\n\n/**\n * Compares two trajectories and returns detailed comparison results.\n *\n * This is the core comparison logic used by trajectory scorers. It supports\n * strict and non-strict ordering, optional step data comparison, and loop detection.\n *\n * @param actual - The trajectory the agent actually took\n * @param expected - The expected trajectory to compare against\n * @param options - Comparison configuration options\n * @returns Detailed comparison results including match scores and diagnostics\n *\n * @example\n * ```ts\n * const result = compareTrajectories(\n * { steps: [{ stepType: 'tool_call', name: 'search' }, { stepType: 'tool_call', name: 'summarize' }] },\n * { steps: [{ stepType: 'tool_call', name: 'search' }, { stepType: 'tool_call', name: 'summarize' }] },\n * { ordering: 'strict' }\n * );\n * // result.score = 1.0\n * ```\n */\nexport function compareTrajectories(\n actual: Trajectory,\n expected: Trajectory | { steps: ExpectedStep[] },\n options: {\n ordering?: 'strict' | 'relaxed' | 'unordered';\n allowRepeatedSteps?: boolean;\n } = {},\n): TrajectoryComparisonResult {\n const { allowRepeatedSteps = true, ordering = 'relaxed' } = options;\n\n // Normalize expected to ExpectedStep[]. TrajectoryStep and ExpectedStep share\n // the same field names, so TrajectoryStep[] can be used directly as ExpectedStep[].\n // The only structural difference is `children` (TrajectoryStep[] vs TrajectoryExpectation),\n // but compareTrajectories doesn't recurse into children.\n const normalizedExpected: { steps: ExpectedStep[] } = {\n steps: expected.steps as ExpectedStep[],\n };\n\n if (normalizedExpected.steps.length === 0) {\n return {\n score: actual.steps.length === 0 ? 1 : 0,\n matchedSteps: 0,\n totalExpectedSteps: 0,\n totalActualSteps: actual.steps.length,\n missingSteps: [],\n extraSteps: actual.steps.map((s: TrajectoryStep) => s.name),\n outOfOrderSteps: [],\n repeatedSteps: [],\n };\n }\n\n const actualNames = actual.steps.map((s: TrajectoryStep) => s.name);\n\n // Detect repeated steps\n const nameCounts = new Map<string, number>();\n for (const name of actualNames) {\n nameCounts.set(name, (nameCounts.get(name) || 0) + 1);\n }\n const repeatedSteps = [...nameCounts.entries()]\n .filter(([_, count]: [string, number]) => count > 1)\n .map(([name]: [string, number]) => name);\n\n if (ordering === 'strict') {\n return compareStrictOrder(actual, normalizedExpected, { allowRepeatedSteps, repeatedSteps });\n }\n\n if (ordering === 'unordered') {\n return compareUnorderedPresence(actual, normalizedExpected, { allowRepeatedSteps, repeatedSteps });\n }\n\n return compareRelaxedOrder(actual, normalizedExpected, { allowRepeatedSteps, repeatedSteps });\n}\n\n/**\n * Result of comparing two trajectories.\n */\nexport type TrajectoryComparisonResult = {\n /** Overall match score from 0 to 1 */\n score: number;\n /** Number of expected steps that were matched */\n matchedSteps: number;\n /** Total number of expected steps */\n totalExpectedSteps: number;\n /** Total number of actual steps taken */\n totalActualSteps: number;\n /** Expected steps that were not found in the actual trajectory */\n missingSteps: string[];\n /** Actual steps that were not in the expected trajectory */\n extraSteps: string[];\n /** Steps that appear but not in the expected position */\n outOfOrderSteps: string[];\n /** Steps that were repeated (appeared more than once) */\n repeatedSteps: string[];\n};\n\nfunction compareStrictOrder(\n actual: Trajectory,\n expected: { steps: ExpectedStep[] },\n opts: { allowRepeatedSteps: boolean; repeatedSteps: string[] },\n): TrajectoryComparisonResult {\n const actualNames: string[] = actual.steps.map((s: TrajectoryStep) => s.name);\n const expectedNames: string[] = expected.steps.map((s: ExpectedStep) => s.name);\n\n // Strict: exact same sequence\n let matchedSteps = 0;\n const outOfOrderSteps: string[] = [];\n const matchedExpectedIndices = new Set<number>();\n const maxLen = Math.max(actualNames.length, expectedNames.length);\n\n for (let i = 0; i < maxLen; i++) {\n const actualName = actualNames[i];\n const expectedName = expectedNames[i];\n if (actualName === expectedName) {\n if (actual.steps[i] && expected.steps[i]) {\n if (expectedStepMatches(actual.steps[i]!, expected.steps[i]!)) {\n matchedSteps++;\n matchedExpectedIndices.add(i);\n }\n } else {\n matchedSteps++;\n matchedExpectedIndices.add(i);\n }\n } else if (actualName && expectedNames.includes(actualName)) {\n outOfOrderSteps.push(actualName);\n }\n }\n\n // Missing steps = expected steps that were not matched (accounts for stepType/data mismatches)\n const missingSteps: string[] = expectedNames.filter((_: string, i: number) => !matchedExpectedIndices.has(i));\n const extraSteps: string[] = actualNames.filter((name: string) => !expectedNames.includes(name));\n\n let score = matchedSteps / expected.steps.length;\n\n // Penalize extra steps in strict mode\n if (actualNames.length > expectedNames.length) {\n const extraPenalty = (actualNames.length - expectedNames.length) / expectedNames.length;\n score = Math.max(0, score - extraPenalty * 0.5);\n }\n\n // Penalize repeated steps if not allowed\n if (!opts.allowRepeatedSteps && opts.repeatedSteps.length > 0) {\n score = Math.max(0, score - opts.repeatedSteps.length * 0.1);\n }\n\n return {\n score: roundToTwoDecimals(Math.max(0, Math.min(1, score))),\n matchedSteps,\n totalExpectedSteps: expected.steps.length,\n totalActualSteps: actual.steps.length,\n missingSteps,\n extraSteps,\n outOfOrderSteps,\n repeatedSteps: opts.repeatedSteps,\n };\n}\n\nfunction compareRelaxedOrder(\n actual: Trajectory,\n expected: { steps: ExpectedStep[] },\n opts: { allowRepeatedSteps: boolean; repeatedSteps: string[] },\n): TrajectoryComparisonResult {\n const actualNames: string[] = actual.steps.map((s: TrajectoryStep) => s.name);\n const expectedNames: string[] = expected.steps.map((s: ExpectedStep) => s.name);\n\n // Relaxed: expected steps must appear in order but extra steps are allowed\n let matchedSteps = 0;\n let lastMatchedIndex = -1;\n const outOfOrderSteps: string[] = [];\n const matchedExpectedIndices = new Set<number>();\n\n for (let i = 0; i < expectedNames.length; i++) {\n const expectedName = expectedNames[i];\n let found = false;\n\n for (let j = lastMatchedIndex + 1; j < actualNames.length; j++) {\n if (actualNames[j] === expectedName) {\n if (actual.steps[j] && expected.steps[i]) {\n if (expectedStepMatches(actual.steps[j]!, expected.steps[i]!)) {\n matchedSteps++;\n lastMatchedIndex = j;\n matchedExpectedIndices.add(i);\n found = true;\n break;\n }\n } else {\n matchedSteps++;\n lastMatchedIndex = j;\n matchedExpectedIndices.add(i);\n found = true;\n break;\n }\n }\n }\n\n if (!found) {\n // Check if the step exists but is out of order\n if (actualNames.includes(expectedName!)) {\n outOfOrderSteps.push(expectedName!);\n }\n }\n }\n\n // Missing steps = expected steps that were not matched (by name + stepType + data, not just name)\n const missingSteps = expectedNames.filter((_, i) => !matchedExpectedIndices.has(i));\n const expectedSet = new Set(expectedNames);\n const extraSteps = actualNames.filter(name => !expectedSet.has(name));\n\n let score = matchedSteps / expected.steps.length;\n\n // Penalize repeated steps if not allowed\n if (!opts.allowRepeatedSteps && opts.repeatedSteps.length > 0) {\n score = Math.max(0, score - opts.repeatedSteps.length * 0.1);\n }\n\n return {\n score: roundToTwoDecimals(Math.max(0, Math.min(1, score))),\n matchedSteps,\n totalExpectedSteps: expected.steps.length,\n totalActualSteps: actual.steps.length,\n missingSteps,\n extraSteps,\n outOfOrderSteps,\n repeatedSteps: opts.repeatedSteps,\n };\n}\n\n/**\n * Fields on each ExpectedStep variant that are comparable data (not structural).\n * Used by `expectedStepMatches` to know which fields to compare when `compareData` is true.\n */\nconst COMPARABLE_FIELDS_BY_TYPE: Record<string, string[]> = {\n tool_call: ['toolArgs', 'toolResult', 'success'],\n mcp_tool_call: ['toolArgs', 'toolResult', 'mcpServer', 'success'],\n model_generation: ['modelId', 'promptTokens', 'completionTokens', 'finishReason'],\n agent_run: ['agentId'],\n workflow_step: ['stepId', 'status', 'output'],\n workflow_run: ['workflowId', 'status'],\n workflow_conditional: ['conditionCount', 'selectedSteps'],\n workflow_parallel: ['branchCount', 'parallelSteps'],\n workflow_loop: ['loopType', 'totalIterations'],\n workflow_sleep: ['sleepDurationMs', 'sleepType'],\n workflow_wait_event: ['eventName', 'eventReceived'],\n processor_run: ['processorId'],\n};\n\n/**\n * Check if an actual TrajectoryStep matches an ExpectedStep.\n * Matches by name, optionally by stepType, and auto-compares any variant-specific\n * fields that are present on the expected step.\n */\nfunction expectedStepMatches(actual: TrajectoryStep, expected: ExpectedStep): boolean {\n if (actual.name !== expected.name) return false;\n if (expected.stepType && actual.stepType !== expected.stepType) return false;\n\n if (expected.stepType) {\n const fields = COMPARABLE_FIELDS_BY_TYPE[expected.stepType] ?? [];\n for (const field of fields) {\n const expectedVal = (expected as any)[field];\n if (expectedVal === undefined) continue; // field not specified in expectation, skip\n const actualVal = (actual as any)[field];\n if (actualVal === undefined) return false;\n try {\n if (JSON.stringify(actualVal) !== JSON.stringify(expectedVal)) return false;\n } catch {\n return false;\n }\n }\n }\n\n return true;\n}\n\nfunction compareUnorderedPresence(\n actual: Trajectory,\n expected: { steps: ExpectedStep[] },\n opts: { allowRepeatedSteps: boolean; repeatedSteps: string[] },\n): TrajectoryComparisonResult {\n const actualNames: string[] = actual.steps.map((s: TrajectoryStep) => s.name);\n const expectedNames: string[] = expected.steps.map((s: ExpectedStep) => s.name);\n\n let matchedSteps = 0;\n const matchedExpectedIndices = new Set<number>();\n const usedIndices = new Set<number>();\n for (let i = 0; i < expected.steps.length; i++) {\n const expectedStep = expected.steps[i]!;\n for (let j = 0; j < actual.steps.length; j++) {\n if (!usedIndices.has(j) && expectedStepMatches(actual.steps[j]!, expectedStep)) {\n matchedSteps++;\n matchedExpectedIndices.add(i);\n usedIndices.add(j);\n break;\n }\n }\n }\n\n // Missing steps = expected steps that were not matched (accounts for stepType/data mismatches)\n const missingSteps = expectedNames.filter((_, i) => !matchedExpectedIndices.has(i));\n const expectedSet = new Set(expectedNames);\n const extraSteps = actualNames.filter(name => !expectedSet.has(name));\n\n let score = matchedSteps / expected.steps.length;\n\n // Penalize repeated steps if not allowed\n if (!opts.allowRepeatedSteps && opts.repeatedSteps.length > 0) {\n score = Math.max(0, score - opts.repeatedSteps.length * 0.1);\n }\n\n return {\n score: roundToTwoDecimals(Math.max(0, Math.min(1, score))),\n matchedSteps,\n totalExpectedSteps: expected.steps.length,\n totalActualSteps: actual.steps.length,\n missingSteps,\n extraSteps,\n outOfOrderSteps: [], // ordering not checked in unordered mode\n repeatedSteps: opts.repeatedSteps,\n };\n}\n\n// ─── Efficiency evaluation ───\n\n/**\n * Result of checking trajectory efficiency.\n */\nexport type TrajectoryEfficiencyResult = {\n /** Overall efficiency score from 0 to 1 */\n score: number;\n /** Total number of steps taken */\n totalSteps: number;\n /** Whether the step budget was exceeded */\n overStepBudget: boolean;\n /** Total tokens used across model_generation steps */\n totalTokens: number;\n /** Whether the token budget was exceeded */\n overTokenBudget: boolean;\n /** Total duration in milliseconds */\n totalDurationMs: number;\n /** Whether the duration budget was exceeded */\n overDurationBudget: boolean;\n /** Redundant calls detected (same tool + same args consecutively) */\n redundantCalls: Array<{ name: string; index: number }>;\n};\n\n/**\n * Evaluate trajectory efficiency against budgets and redundancy checks.\n */\nexport function checkTrajectoryEfficiency(\n trajectory: Trajectory,\n options: {\n maxSteps?: number;\n maxTotalTokens?: number;\n maxTotalDurationMs?: number;\n noRedundantCalls?: boolean;\n } = {},\n): TrajectoryEfficiencyResult {\n const { maxSteps, maxTotalTokens, maxTotalDurationMs, noRedundantCalls = true } = options;\n\n const totalSteps = trajectory.steps.length;\n\n // Calculate total tokens from model_generation steps\n let totalTokens = 0;\n for (const step of trajectory.steps) {\n if (step.stepType === 'model_generation') {\n totalTokens += (step.promptTokens ?? 0) + (step.completionTokens ?? 0);\n }\n }\n\n // Calculate total duration\n const totalDurationMs =\n trajectory.totalDurationMs ?? trajectory.steps.reduce((sum, s) => sum + (s.durationMs ?? 0), 0);\n\n // Detect redundant calls (same tool name + same args in consecutive calls)\n const redundantCalls: Array<{ name: string; index: number }> = [];\n if (noRedundantCalls) {\n for (let i = 1; i < trajectory.steps.length; i++) {\n const prev = trajectory.steps[i - 1]!;\n const curr = trajectory.steps[i]!;\n if (\n prev.name === curr.name &&\n prev.stepType === curr.stepType &&\n (prev.stepType === 'tool_call' || prev.stepType === 'mcp_tool_call')\n ) {\n const prevArgs = (prev as TrajectoryStep & { toolArgs?: Record<string, unknown> }).toolArgs;\n const currArgs = (curr as TrajectoryStep & { toolArgs?: Record<string, unknown> }).toolArgs;\n try {\n if (JSON.stringify(prevArgs) === JSON.stringify(currArgs)) {\n redundantCalls.push({ name: curr.name, index: i });\n }\n } catch {\n // If serialization fails, don't flag as redundant\n }\n }\n }\n }\n\n const overStepBudget = maxSteps !== undefined && totalSteps > maxSteps;\n const overTokenBudget = maxTotalTokens !== undefined && totalTokens > maxTotalTokens;\n const overDurationBudget = maxTotalDurationMs !== undefined && totalDurationMs > maxTotalDurationMs;\n\n // Calculate score: each dimension contributes equally\n const dimensions: number[] = [];\n\n if (maxSteps !== undefined) {\n dimensions.push(overStepBudget ? Math.max(0, 1 - (totalSteps - maxSteps) / maxSteps) : 1);\n }\n if (maxTotalTokens !== undefined) {\n dimensions.push(overTokenBudget ? Math.max(0, 1 - (totalTokens - maxTotalTokens) / maxTotalTokens) : 1);\n }\n if (maxTotalDurationMs !== undefined) {\n dimensions.push(\n overDurationBudget ? Math.max(0, 1 - (totalDurationMs - maxTotalDurationMs) / maxTotalDurationMs) : 1,\n );\n }\n if (noRedundantCalls) {\n dimensions.push(redundantCalls.length === 0 ? 1 : Math.max(0, 1 - redundantCalls.length * 0.2));\n }\n\n const score = dimensions.length > 0 ? dimensions.reduce((a, b) => a + b, 0) / dimensions.length : 1;\n\n return {\n score: roundToTwoDecimals(Math.max(0, Math.min(1, score))),\n totalSteps,\n overStepBudget,\n totalTokens,\n overTokenBudget,\n totalDurationMs,\n overDurationBudget,\n redundantCalls,\n };\n}\n\n// ─── Blacklist evaluation ───\n\n/**\n * Result of checking trajectory against a blacklist.\n */\nexport type TrajectoryBlacklistResult = {\n /** Score: 1.0 if clean, 0.0 if any violation found */\n score: number;\n /** Individual blacklisted tools that were found */\n violatedTools: string[];\n /** Blacklisted sequences that were found */\n violatedSequences: string[][];\n};\n\n/**\n * Check if a trajectory violates any blacklist rules.\n * Returns score 0.0 if any violation is found (hard fail).\n */\nexport function checkTrajectoryBlacklist(\n trajectory: Trajectory,\n options: {\n blacklistedTools?: string[];\n blacklistedSequences?: string[][];\n } = {},\n): TrajectoryBlacklistResult {\n const { blacklistedTools = [], blacklistedSequences = [] } = options;\n const violatedTools: string[] = [];\n const violatedSequences: string[][] = [];\n\n const stepNames = trajectory.steps.map(s => s.name);\n\n // Check blacklisted tools\n for (const forbidden of blacklistedTools) {\n if (stepNames.includes(forbidden)) {\n violatedTools.push(forbidden);\n }\n }\n\n // Check blacklisted sequences (contiguous subsequences)\n for (const sequence of blacklistedSequences) {\n if (sequence.length === 0) continue;\n for (let i = 0; i <= stepNames.length - sequence.length; i++) {\n let match = true;\n for (let j = 0; j < sequence.length; j++) {\n if (stepNames[i + j] !== sequence[j]) {\n match = false;\n break;\n }\n }\n if (match) {\n violatedSequences.push(sequence);\n break; // Only report each sequence once\n }\n }\n }\n\n const hasViolations = violatedTools.length > 0 || violatedSequences.length > 0;\n\n return {\n score: hasViolations ? 0 : 1,\n violatedTools,\n violatedSequences,\n };\n}\n\n// ─── Tool failure analysis ───\n\n/**\n * A detected tool failure pattern in the trajectory.\n */\nexport type ToolFailurePattern = {\n /** The tool name that experienced failure */\n toolName: string;\n /** Number of consecutive retries (same tool, same or similar args) */\n retryCount: number;\n /** Whether the agent fell back to a different tool after failures */\n fellBackToAlternative: boolean;\n /** The alternative tool used, if any */\n alternativeTool?: string;\n /** Whether any retry eventually succeeded */\n eventuallySucceeded: boolean;\n};\n\n/**\n * Result of analyzing tool failure patterns in a trajectory.\n */\nexport type ToolFailureAnalysisResult = {\n /** Score from 0 to 1 (lower = more failures/retries) */\n score: number;\n /** Tool failure patterns detected */\n patterns: ToolFailurePattern[];\n /** Total number of retries across all tools */\n totalRetries: number;\n /** Tools that exceeded the retry threshold */\n excessiveRetryTools: string[];\n};\n\n/**\n * Analyze tool failure and retry patterns in a trajectory.\n */\nexport function analyzeToolFailures(\n trajectory: Trajectory,\n options: {\n maxRetriesPerTool?: number;\n } = {},\n): ToolFailureAnalysisResult {\n const { maxRetriesPerTool = 2 } = options;\n const patterns: ToolFailurePattern[] = [];\n let totalRetries = 0;\n\n const toolCallSteps = trajectory.steps.filter(s => s.stepType === 'tool_call' || s.stepType === 'mcp_tool_call');\n\n if (toolCallSteps.length === 0) {\n return { score: 1, patterns: [], totalRetries: 0, excessiveRetryTools: [] };\n }\n\n // Group consecutive calls to the same tool as potential retry sequences\n let i = 0;\n while (i < toolCallSteps.length) {\n const currentTool = toolCallSteps[i]!;\n let retryCount = 0;\n let j = i + 1;\n\n // Count consecutive calls to the same tool\n // (toolCallSteps is pre-filtered to tool_call/mcp_tool_call, so no stepType checks needed)\n while (j < toolCallSteps.length && toolCallSteps[j]!.name === currentTool.name) {\n const prevStep = toolCallSteps[j - 1]! as TrajectoryStep & { success?: boolean };\n if (prevStep.success === false) {\n retryCount++;\n }\n j++;\n }\n\n if (retryCount > 0) {\n // Check if agent fell back to a different tool after retries\n const nextDifferentTool = j < toolCallSteps.length ? toolCallSteps[j] : undefined;\n const lastRetry = toolCallSteps[j - 1]! as TrajectoryStep & { success?: boolean };\n const lastSuccess = lastRetry.success !== false;\n\n patterns.push({\n toolName: currentTool.name,\n retryCount,\n fellBackToAlternative: nextDifferentTool !== undefined && !lastSuccess,\n alternativeTool: nextDifferentTool !== undefined && !lastSuccess ? nextDifferentTool.name : undefined,\n eventuallySucceeded: lastSuccess,\n });\n\n totalRetries += retryCount;\n }\n\n i = j;\n }\n\n // Score: penalize excessive retries\n const excessiveRetryTools = patterns.filter(p => p.retryCount > maxRetriesPerTool).map(p => p.toolName);\n\n let score = 1;\n if (toolCallSteps.length > 0) {\n // Each retry beyond the threshold costs more\n const excessRetries = patterns.reduce((sum, p) => sum + Math.max(0, p.retryCount - maxRetriesPerTool), 0);\n score = Math.max(0, 1 - excessRetries * 0.2);\n }\n\n return {\n score: roundToTwoDecimals(Math.max(0, Math.min(1, score))),\n patterns,\n totalRetries,\n excessiveRetryTools,\n };\n}\n"]}
@@ -214,42 +214,10 @@ function extractToolResults(output) {
214
214
  return results;
215
215
  }
216
216
  function compareTrajectories(actual, expected, options = {}) {
217
- const { compareStepData = false, allowRepeatedSteps = true } = options;
218
- const trajectoryStepKeys = [
219
- "toolArgs",
220
- "toolResult",
221
- "agentId",
222
- "modelId",
223
- "durationMs",
224
- "success",
225
- "promptTokens",
226
- "completionTokens"
227
- ];
228
- const hasTrajectorySteps = expected.steps.length > 0 && expected.steps.some((s) => trajectoryStepKeys.some((k) => k in s));
229
- let normalizedExpected;
230
- if (hasTrajectorySteps) {
231
- normalizedExpected = {
232
- steps: expected.steps.map((s) => {
233
- const stepData = getStepData(s);
234
- const data = {};
235
- if (stepData.input !== void 0) data.input = stepData.input;
236
- if (stepData.output !== void 0) data.output = stepData.output;
237
- return {
238
- name: s.name,
239
- stepType: s.stepType,
240
- ...Object.keys(data).length > 0 ? { data } : {}
241
- };
242
- })
243
- };
244
- } else {
245
- normalizedExpected = expected;
246
- }
247
- let ordering = "relaxed";
248
- if (options.ordering) {
249
- ordering = options.ordering;
250
- } else if (options.strictOrder) {
251
- ordering = "strict";
252
- }
217
+ const { allowRepeatedSteps = true, ordering = "relaxed" } = options;
218
+ const normalizedExpected = {
219
+ steps: expected.steps
220
+ };
253
221
  if (normalizedExpected.steps.length === 0) {
254
222
  return {
255
223
  score: actual.steps.length === 0 ? 1 : 0,
@@ -269,16 +237,12 @@ function compareTrajectories(actual, expected, options = {}) {
269
237
  }
270
238
  const repeatedSteps = [...nameCounts.entries()].filter(([_, count]) => count > 1).map(([name]) => name);
271
239
  if (ordering === "strict") {
272
- return compareStrictOrder(actual, normalizedExpected, { compareStepData, allowRepeatedSteps, repeatedSteps });
240
+ return compareStrictOrder(actual, normalizedExpected, { allowRepeatedSteps, repeatedSteps });
273
241
  }
274
242
  if (ordering === "unordered") {
275
- return compareUnorderedPresence(actual, normalizedExpected, {
276
- compareStepData,
277
- allowRepeatedSteps,
278
- repeatedSteps
279
- });
243
+ return compareUnorderedPresence(actual, normalizedExpected, { allowRepeatedSteps, repeatedSteps });
280
244
  }
281
- return compareRelaxedOrder(actual, normalizedExpected, { compareStepData, allowRepeatedSteps, repeatedSteps });
245
+ return compareRelaxedOrder(actual, normalizedExpected, { allowRepeatedSteps, repeatedSteps });
282
246
  }
283
247
  function compareStrictOrder(actual, expected, opts) {
284
248
  const actualNames = actual.steps.map((s) => s.name);
@@ -291,13 +255,8 @@ function compareStrictOrder(actual, expected, opts) {
291
255
  const actualName = actualNames[i];
292
256
  const expectedName = expectedNames[i];
293
257
  if (actualName === expectedName) {
294
- if (opts.compareStepData && actual.steps[i] && expected.steps[i]) {
295
- if (expectedStepMatches(actual.steps[i], expected.steps[i], true)) {
296
- matchedSteps++;
297
- matchedExpectedIndices.add(i);
298
- }
299
- } else if (actual.steps[i] && expected.steps[i]) {
300
- if (expectedStepMatches(actual.steps[i], expected.steps[i], false)) {
258
+ if (actual.steps[i] && expected.steps[i]) {
259
+ if (expectedStepMatches(actual.steps[i], expected.steps[i])) {
301
260
  matchedSteps++;
302
261
  matchedExpectedIndices.add(i);
303
262
  }
@@ -343,7 +302,7 @@ function compareRelaxedOrder(actual, expected, opts) {
343
302
  for (let j = lastMatchedIndex + 1; j < actualNames.length; j++) {
344
303
  if (actualNames[j] === expectedName) {
345
304
  if (actual.steps[j] && expected.steps[i]) {
346
- if (expectedStepMatches(actual.steps[j], expected.steps[i], opts.compareStepData)) {
305
+ if (expectedStepMatches(actual.steps[j], expected.steps[i])) {
347
306
  matchedSteps++;
348
307
  lastMatchedIndex = j;
349
308
  matchedExpectedIndices.add(i);
@@ -383,27 +342,32 @@ function compareRelaxedOrder(actual, expected, opts) {
383
342
  repeatedSteps: opts.repeatedSteps
384
343
  };
385
344
  }
386
- function getStepData(step) {
387
- switch (step.stepType) {
388
- case "tool_call":
389
- case "mcp_tool_call":
390
- return { input: step.toolArgs, output: step.toolResult };
391
- case "workflow_step":
392
- return { output: step.output };
393
- default:
394
- return {};
395
- }
396
- }
397
- function expectedStepMatches(actual, expected, compareData) {
345
+ var COMPARABLE_FIELDS_BY_TYPE = {
346
+ tool_call: ["toolArgs", "toolResult", "success"],
347
+ mcp_tool_call: ["toolArgs", "toolResult", "mcpServer", "success"],
348
+ model_generation: ["modelId", "promptTokens", "completionTokens", "finishReason"],
349
+ agent_run: ["agentId"],
350
+ workflow_step: ["stepId", "status", "output"],
351
+ workflow_run: ["workflowId", "status"],
352
+ workflow_conditional: ["conditionCount", "selectedSteps"],
353
+ workflow_parallel: ["branchCount", "parallelSteps"],
354
+ workflow_loop: ["loopType", "totalIterations"],
355
+ workflow_sleep: ["sleepDurationMs", "sleepType"],
356
+ workflow_wait_event: ["eventName", "eventReceived"],
357
+ processor_run: ["processorId"]
358
+ };
359
+ function expectedStepMatches(actual, expected) {
398
360
  if (actual.name !== expected.name) return false;
399
361
  if (expected.stepType && actual.stepType !== expected.stepType) return false;
400
- if (compareData && expected.data) {
401
- const actualData = getStepData(actual);
402
- for (const [key, value] of Object.entries(expected.data)) {
403
- const actualField = key === "input" ? actualData.input : key === "output" ? actualData.output : void 0;
404
- if (actualField === void 0) return false;
362
+ if (expected.stepType) {
363
+ const fields = COMPARABLE_FIELDS_BY_TYPE[expected.stepType] ?? [];
364
+ for (const field of fields) {
365
+ const expectedVal = expected[field];
366
+ if (expectedVal === void 0) continue;
367
+ const actualVal = actual[field];
368
+ if (actualVal === void 0) return false;
405
369
  try {
406
- if (JSON.stringify(actualField) !== JSON.stringify(value)) return false;
370
+ if (JSON.stringify(actualVal) !== JSON.stringify(expectedVal)) return false;
407
371
  } catch {
408
372
  return false;
409
373
  }
@@ -416,30 +380,15 @@ function compareUnorderedPresence(actual, expected, opts) {
416
380
  const expectedNames = expected.steps.map((s) => s.name);
417
381
  let matchedSteps = 0;
418
382
  const matchedExpectedIndices = /* @__PURE__ */ new Set();
419
- if (opts.compareStepData) {
420
- const usedIndices = /* @__PURE__ */ new Set();
421
- for (let i = 0; i < expected.steps.length; i++) {
422
- const expectedStep = expected.steps[i];
423
- for (let j = 0; j < actual.steps.length; j++) {
424
- if (!usedIndices.has(j) && expectedStepMatches(actual.steps[j], expectedStep, true)) {
425
- matchedSteps++;
426
- matchedExpectedIndices.add(i);
427
- usedIndices.add(j);
428
- break;
429
- }
430
- }
431
- }
432
- } else {
433
- const usedIndices = /* @__PURE__ */ new Set();
434
- for (let i = 0; i < expected.steps.length; i++) {
435
- const expectedStep = expected.steps[i];
436
- for (let j = 0; j < actual.steps.length; j++) {
437
- if (!usedIndices.has(j) && expectedStepMatches(actual.steps[j], expectedStep, false)) {
438
- matchedSteps++;
439
- matchedExpectedIndices.add(i);
440
- usedIndices.add(j);
441
- break;
442
- }
383
+ const usedIndices = /* @__PURE__ */ new Set();
384
+ for (let i = 0; i < expected.steps.length; i++) {
385
+ const expectedStep = expected.steps[i];
386
+ for (let j = 0; j < actual.steps.length; j++) {
387
+ if (!usedIndices.has(j) && expectedStepMatches(actual.steps[j], expectedStep)) {
388
+ matchedSteps++;
389
+ matchedExpectedIndices.add(i);
390
+ usedIndices.add(j);
391
+ break;
443
392
  }
444
393
  }
445
394
  }
@@ -602,5 +551,5 @@ function analyzeToolFailures(trajectory, options = {}) {
602
551
  }
603
552
 
604
553
  export { analyzeToolFailures, checkTrajectoryBlacklist, checkTrajectoryEfficiency, compareTrajectories, createAgentTestRun, createTestMessage, createTestRun, createToolInvocation, createTrajectoryTestRun, extractAgentResponseMessages, extractInputMessages, extractToolCalls, extractToolResults, getAssistantMessageFromRunOutput, getCombinedSystemPrompt, getReasoningFromRunOutput, getSystemMessagesFromRunInput, getTextContentFromMastraDBMessage, getUserMessageFromRunInput, isCloserTo, roundToTwoDecimals };
605
- //# sourceMappingURL=chunk-EVBNIL5M.js.map
606
- //# sourceMappingURL=chunk-EVBNIL5M.js.map
554
+ //# sourceMappingURL=chunk-X4MKZ735.js.map
555
+ //# sourceMappingURL=chunk-X4MKZ735.js.map