@mastra/evals 1.6.0 → 1.7.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.
Files changed (62) hide show
  1. package/CHANGELOG.md +58 -0
  2. package/dist/checks-64AonnEK.js +379 -0
  3. package/dist/checks-64AonnEK.js.map +1 -0
  4. package/dist/checks-DGTgg-nW.cjs +479 -0
  5. package/dist/checks-DGTgg-nW.cjs.map +1 -0
  6. package/dist/checks.cjs +14 -56
  7. package/dist/checks.js +2 -3
  8. package/dist/docs/SKILL.md +2 -1
  9. package/dist/docs/assets/SOURCE_MAP.json +1 -1
  10. package/dist/docs/references/docs-evals-built-in-scorers.md +4 -4
  11. package/dist/docs/references/docs-evals-overview.md +6 -4
  12. package/dist/docs/references/docs-evals-quick-checks.md +2 -2
  13. package/dist/docs/references/reference-evals-answer-relevancy.md +5 -5
  14. package/dist/docs/references/reference-evals-answer-similarity.md +1 -1
  15. package/dist/docs/references/reference-evals-bias.md +4 -4
  16. package/dist/docs/references/reference-evals-checks.md +3 -3
  17. package/dist/docs/references/reference-evals-completeness.md +5 -5
  18. package/dist/docs/references/reference-evals-content-similarity.md +5 -5
  19. package/dist/docs/references/reference-evals-context-precision.md +5 -5
  20. package/dist/docs/references/reference-evals-context-recall.md +11 -11
  21. package/dist/docs/references/reference-evals-context-relevance.md +15 -15
  22. package/dist/docs/references/reference-evals-faithfulness.md +4 -4
  23. package/dist/docs/references/reference-evals-hallucination.md +11 -11
  24. package/dist/docs/references/reference-evals-keyword-coverage.md +6 -6
  25. package/dist/docs/references/reference-evals-noise-sensitivity.md +15 -15
  26. package/dist/docs/references/reference-evals-prompt-alignment.md +20 -20
  27. package/dist/docs/references/reference-evals-rubric.md +2 -2
  28. package/dist/docs/references/reference-evals-scorer-utils.md +4 -4
  29. package/dist/docs/references/reference-evals-summarization.md +203 -0
  30. package/dist/docs/references/reference-evals-textual-difference.md +4 -4
  31. package/dist/docs/references/reference-evals-tool-call-accuracy.md +4 -4
  32. package/dist/docs/references/reference-evals-toxicity.md +5 -5
  33. package/dist/docs/references/reference-evals-trajectory-accuracy.md +10 -10
  34. package/dist/index.cjs +12 -2
  35. package/dist/index.cjs.map +1 -1
  36. package/dist/index.js +13 -1
  37. package/dist/index.js.map +1 -1
  38. package/dist/scorers/llm/index.d.ts +1 -0
  39. package/dist/scorers/llm/index.d.ts.map +1 -1
  40. package/dist/scorers/llm/summarization/index.d.ts +55 -0
  41. package/dist/scorers/llm/summarization/index.d.ts.map +1 -0
  42. package/dist/scorers/llm/summarization/prompts.d.ts +48 -0
  43. package/dist/scorers/llm/summarization/prompts.d.ts.map +1 -0
  44. package/dist/scorers/prebuilt/index.cjs +2753 -2848
  45. package/dist/scorers/prebuilt/index.cjs.map +1 -1
  46. package/dist/scorers/prebuilt/index.js +2735 -2791
  47. package/dist/scorers/prebuilt/index.js.map +1 -1
  48. package/dist/scorers/utils.cjs +966 -101
  49. package/dist/scorers/utils.cjs.map +1 -1
  50. package/dist/scorers/utils.js +939 -2
  51. package/dist/scorers/utils.js.map +1 -1
  52. package/package.json +11 -10
  53. package/dist/checks.cjs.map +0 -1
  54. package/dist/checks.js.map +0 -1
  55. package/dist/chunk-GGHVFNVI.cjs +0 -233
  56. package/dist/chunk-GGHVFNVI.cjs.map +0 -1
  57. package/dist/chunk-IZLA36WC.cjs +0 -654
  58. package/dist/chunk-IZLA36WC.cjs.map +0 -1
  59. package/dist/chunk-UJ4WCQ3F.js +0 -626
  60. package/dist/chunk-UJ4WCQ3F.js.map +0 -1
  61. package/dist/chunk-WEADJCUA.js +0 -216
  62. package/dist/chunk-WEADJCUA.js.map +0 -1
@@ -1,104 +1,969 @@
1
- 'use strict';
2
-
3
- var chunkIZLA36WC_cjs = require('../chunk-IZLA36WC.cjs');
4
-
5
-
6
-
7
- Object.defineProperty(exports, "analyzeToolFailures", {
8
- enumerable: true,
9
- get: function () { return chunkIZLA36WC_cjs.analyzeToolFailures; }
10
- });
11
- Object.defineProperty(exports, "checkTrajectoryBlacklist", {
12
- enumerable: true,
13
- get: function () { return chunkIZLA36WC_cjs.checkTrajectoryBlacklist; }
14
- });
15
- Object.defineProperty(exports, "checkTrajectoryEfficiency", {
16
- enumerable: true,
17
- get: function () { return chunkIZLA36WC_cjs.checkTrajectoryEfficiency; }
18
- });
19
- Object.defineProperty(exports, "compareTrajectories", {
20
- enumerable: true,
21
- get: function () { return chunkIZLA36WC_cjs.compareTrajectories; }
22
- });
23
- Object.defineProperty(exports, "createAgentTestRun", {
24
- enumerable: true,
25
- get: function () { return chunkIZLA36WC_cjs.createAgentTestRun; }
26
- });
27
- Object.defineProperty(exports, "createTestMessage", {
28
- enumerable: true,
29
- get: function () { return chunkIZLA36WC_cjs.createTestMessage; }
30
- });
31
- Object.defineProperty(exports, "createTestRun", {
32
- enumerable: true,
33
- get: function () { return chunkIZLA36WC_cjs.createTestRun; }
34
- });
35
- Object.defineProperty(exports, "createToolInvocation", {
36
- enumerable: true,
37
- get: function () { return chunkIZLA36WC_cjs.createToolInvocation; }
38
- });
39
- Object.defineProperty(exports, "createTrajectoryTestRun", {
40
- enumerable: true,
41
- get: function () { return chunkIZLA36WC_cjs.createTrajectoryTestRun; }
42
- });
43
- Object.defineProperty(exports, "extractAgentResponseMessages", {
44
- enumerable: true,
45
- get: function () { return chunkIZLA36WC_cjs.extractAgentResponseMessages; }
46
- });
47
- Object.defineProperty(exports, "extractInputMessages", {
48
- enumerable: true,
49
- get: function () { return chunkIZLA36WC_cjs.extractInputMessages; }
50
- });
51
- Object.defineProperty(exports, "extractToolCalls", {
52
- enumerable: true,
53
- get: function () { return chunkIZLA36WC_cjs.extractToolCalls; }
54
- });
55
- Object.defineProperty(exports, "extractToolResults", {
56
- enumerable: true,
57
- get: function () { return chunkIZLA36WC_cjs.extractToolResults; }
58
- });
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let _mastra_core_evals = require("@mastra/core/evals");
3
+ let _mastra_core_request_context = require("@mastra/core/request-context");
4
+ //#region src/scorers/utils.ts
5
+ /**
6
+ * Extracts text content from a MastraDBMessage or ModelMessage-like object.
7
+ *
8
+ * @param message - The message to extract text from
9
+ * @returns The extracted text content, or an empty string if no text is found
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * const message: MastraDBMessage = {
14
+ * id: 'msg-1',
15
+ * role: 'assistant',
16
+ * content: { format: 2, parts: [{ type: 'text', text: 'Hello!' }] },
17
+ * createdAt: new Date(),
18
+ * };
19
+ * const text = getTextContentFromMastraDBMessage(message); // 'Hello!'
20
+ * ```
21
+ */
22
+ function getTextContentFromMastraDBMessage(message) {
23
+ const content = message.content;
24
+ if (typeof content === "string") return content;
25
+ if (Array.isArray(content)) {
26
+ const textParts = content.filter((p) => p.type === "text");
27
+ return textParts.length > 0 ? textParts[textParts.length - 1]?.text || "" : "";
28
+ }
29
+ if (typeof content?.content === "string" && content.content !== "") return content.content;
30
+ if (typeof content?.text === "string" && content.text !== "") return content.text;
31
+ if (content?.parts && Array.isArray(content.parts)) {
32
+ const textParts = content.parts.filter((p) => p.type === "text");
33
+ return textParts.length > 0 ? textParts[textParts.length - 1]?.text || "" : "";
34
+ }
35
+ return "";
36
+ }
37
+ const isRecord = (value) => {
38
+ return typeof value === "object" && value !== null;
39
+ };
40
+ const getTextFromValue = (value) => {
41
+ if (typeof value === "string") return value === "" ? void 0 : value;
42
+ if (Array.isArray(value)) {
43
+ const textParts = value.filter((part) => isRecord(part) && part.type === "text" && typeof part.text === "string").map((part) => part.text);
44
+ return textParts.length > 0 ? textParts[textParts.length - 1] : void 0;
45
+ }
46
+ if (!isRecord(value)) return void 0;
47
+ const fromParts = Array.isArray(value.parts) ? getTextFromValue(value.parts) : void 0;
48
+ return getTextFromValue(value.content) ?? (typeof value.text === "string" && value.text !== "" ? value.text : void 0) ?? (typeof value.body === "string" && value.body !== "" ? value.body : void 0) ?? fromParts;
49
+ };
50
+ const isScorerRunInputForAgent = (input) => {
51
+ return isRecord(input) && Array.isArray(input.inputMessages) && Array.isArray(input.rememberedMessages) && Array.isArray(input.systemMessages) && isRecord(input.taggedSystemMessages);
52
+ };
53
+ const isMastraDBMessageLike = (message) => {
54
+ return isRecord(message) && typeof message.id === "string" && typeof message.role === "string" && "content" in message && "createdAt" in message;
55
+ };
56
+ const isScorerRunOutputForAgent = (output) => {
57
+ return Array.isArray(output) && output.every(isMastraDBMessageLike);
58
+ };
59
+ /**
60
+ * Resolves the effective role of a message, accounting for agent signal messages.
61
+ *
62
+ * Messages delivered through the agent subscription / signal API are persisted with
63
+ * `role: 'signal'` and carry their semantic role (e.g. `user`) on `type` and on
64
+ * `content.metadata.signal.{type,tagName}`. Treat those as their underlying role so
65
+ * helpers like `getUserMessageFromRunInput` can find them.
66
+ */
67
+ const getEffectiveMessageRole = (message) => {
68
+ if (message.role !== "signal") return typeof message.role === "string" ? message.role : void 0;
69
+ const signalMeta = isRecord(message.content) && isRecord(message.content.metadata) ? message.content.metadata.signal : void 0;
70
+ const tagName = isRecord(signalMeta) && typeof signalMeta.tagName === "string" ? signalMeta.tagName : void 0;
71
+ const signalType = isRecord(signalMeta) && typeof signalMeta.type === "string" ? signalMeta.type : void 0;
72
+ const topLevelType = typeof message.type === "string" ? message.type : void 0;
73
+ return tagName ?? signalType ?? topLevelType;
74
+ };
75
+ const getTextFromMessages = (messages, role) => {
76
+ if (!Array.isArray(messages)) return void 0;
77
+ const message = messages.find((message) => isRecord(message) && getEffectiveMessageRole(message) === role);
78
+ return message ? getTextFromValue(message) : void 0;
79
+ };
80
+ /**
81
+ * Rounds a number to two decimal places.
82
+ *
83
+ * Uses `Number.EPSILON` to handle floating-point precision issues.
84
+ *
85
+ * @param num - The number to round
86
+ * @returns The number rounded to two decimal places
87
+ *
88
+ * @example
89
+ * ```ts
90
+ * roundToTwoDecimals(0.1 + 0.2); // 0.3
91
+ * roundToTwoDecimals(1.005); // 1.01
92
+ * ```
93
+ */
94
+ const roundToTwoDecimals = (num) => {
95
+ return Math.round((num + Number.EPSILON) * 100) / 100;
96
+ };
97
+ /**
98
+ * Determines if a value is closer to the first target than the second.
99
+ *
100
+ * @param value - The value to compare
101
+ * @param target1 - The first target value
102
+ * @param target2 - The second target value
103
+ * @returns `true` if `value` is closer to `target1` than `target2`
104
+ *
105
+ * @example
106
+ * ```ts
107
+ * isCloserTo(0.6, 1, 0); // true (0.6 is closer to 1)
108
+ * isCloserTo(0.3, 1, 0); // false (0.3 is closer to 0)
109
+ * ```
110
+ */
111
+ function isCloserTo(value, target1, target2) {
112
+ return Math.abs(value - target1) < Math.abs(value - target2);
113
+ }
114
+ /**
115
+ * Creates a scoring input object for testing purposes.
116
+ *
117
+ * @param input - The user input text
118
+ * @param output - The assistant output text
119
+ * @param additionalContext - Optional additional context data
120
+ * @param requestContext - Optional request context data
121
+ * @returns A ScoringInput object ready for use in scorer tests
122
+ *
123
+ * @example
124
+ * ```ts
125
+ * const run = createTestRun(
126
+ * 'What is 2+2?',
127
+ * 'The answer is 4.',
128
+ * { topic: 'math' }
129
+ * );
130
+ * ```
131
+ */
132
+ const createTestRun = (input, output, additionalContext, requestContext) => {
133
+ return {
134
+ input: [{
135
+ role: "user",
136
+ content: input
137
+ }],
138
+ output: {
139
+ role: "assistant",
140
+ text: output
141
+ },
142
+ additionalContext: additionalContext ?? {},
143
+ requestContext: requestContext ?? {}
144
+ };
145
+ };
146
+ /**
147
+ * Extracts the user message text from a scorer run input.
148
+ *
149
+ * Accepts the agent shape (`{ inputMessages }`), `ModelMessage[]`
150
+ * (`{ messages }`), workflow input (`{ prompt }`), and a bare string.
151
+ *
152
+ * @param input - The scorer run input
153
+ * @returns The user message text, or `undefined` if none can be extracted
154
+ *
155
+ * @example
156
+ * ```ts
157
+ * const scorer = createScorer({ ... })
158
+ * .preprocess(({ run }) => {
159
+ * const userText = getUserMessageFromRunInput(run.input);
160
+ * return { userText };
161
+ * });
162
+ * ```
163
+ */
164
+ const getUserMessageFromRunInput = (input) => {
165
+ if (typeof input === "string") return input;
166
+ if (!isRecord(input)) return void 0;
167
+ return getTextFromMessages(input.inputMessages, "user") ?? getTextFromMessages(input.messages, "user") ?? (typeof input.prompt === "string" ? input.prompt : void 0) ?? (typeof input.text === "string" ? input.text : void 0) ?? getTextFromValue(input.content) ?? getTextFromValue(input.input) ?? getTextFromValue(input.user);
168
+ };
169
+ /**
170
+ * Extracts all system messages from a scorer run input.
171
+ *
172
+ * Collects text from both standard system messages and tagged system messages
173
+ * (specialized system prompts like memory instructions).
174
+ *
175
+ * @param input - The scorer run input containing system messages
176
+ * @returns An array of system message strings
177
+ *
178
+ * @example
179
+ * ```ts
180
+ * const scorer = createScorer({ ... })
181
+ * .preprocess(({ run }) => {
182
+ * const systemMessages = getSystemMessagesFromRunInput(run.input);
183
+ * return { systemPrompt: systemMessages.join('\n') };
184
+ * });
185
+ * ```
186
+ */
187
+ const getSystemMessagesFromRunInput = (input) => {
188
+ const systemMessages = [];
189
+ if (!isRecord(input)) return systemMessages;
190
+ if (Array.isArray(input.systemMessages)) systemMessages.push(...input.systemMessages.map((msg) => {
191
+ if (typeof msg.content === "string") return msg.content;
192
+ else if (Array.isArray(msg.content)) return msg.content.filter((part) => part.type === "text").map((part) => part.text || "").join(" ");
193
+ return "";
194
+ }).filter((content) => content));
195
+ const addSystemMessages = (messages) => {
196
+ if (!Array.isArray(messages)) return;
197
+ systemMessages.push(...messages.filter((message) => isRecord(message) && message.role === "system").map((message) => getTextFromValue(message)).filter((content) => Boolean(content)));
198
+ };
199
+ addSystemMessages(input.inputMessages);
200
+ addSystemMessages(input.messages);
201
+ if (isRecord(input.taggedSystemMessages)) Object.values(input.taggedSystemMessages).forEach((messages) => {
202
+ if (!Array.isArray(messages)) return;
203
+ messages.forEach((msg) => {
204
+ const content = getTextFromValue(msg);
205
+ if (content) systemMessages.push(content);
206
+ });
207
+ });
208
+ return systemMessages;
209
+ };
210
+ /**
211
+ * Combines all system messages into a single prompt string.
212
+ *
213
+ * Joins all system messages (standard and tagged) with double newlines.
214
+ *
215
+ * @param input - The scorer run input containing system messages
216
+ * @returns A combined system prompt string
217
+ *
218
+ * @example
219
+ * ```ts
220
+ * const scorer = createScorer({ ... })
221
+ * .preprocess(({ run }) => {
222
+ * const systemPrompt = getCombinedSystemPrompt(run.input);
223
+ * return { systemPrompt };
224
+ * });
225
+ * ```
226
+ */
227
+ const getCombinedSystemPrompt = (input) => {
228
+ return getSystemMessagesFromRunInput(input).join("\n\n");
229
+ };
230
+ /**
231
+ * Extracts the assistant message text from a scorer run output.
232
+ *
233
+ * Accepts the agent shape (`MastraDBMessage[]` / `ModelMessage[]`), workflow
234
+ * output (`{ text }`), task output (`{ content }`), a single assistant message
235
+ * object, and a bare string.
236
+ *
237
+ * @param output - The scorer run output
238
+ * @returns The assistant message text, or `undefined` if none can be extracted
239
+ *
240
+ * @example
241
+ * ```ts
242
+ * const scorer = createScorer({ ... })
243
+ * .preprocess(({ run }) => {
244
+ * const response = getAssistantMessageFromRunOutput(run.output);
245
+ * return { response };
246
+ * });
247
+ * ```
248
+ */
249
+ const getAssistantMessageFromRunOutput = (output) => {
250
+ if (typeof output === "string") return output;
251
+ if (Array.isArray(output)) return getTextFromMessages(output, "assistant");
252
+ if (!isRecord(output)) return void 0;
253
+ const isAssistantOutput = output.role === void 0 || output.role === "assistant";
254
+ if (isAssistantOutput && typeof output.text === "string") return output.text;
255
+ if (isAssistantOutput && typeof output.content === "string") return output.content;
256
+ if (isAssistantOutput && (isRecord(output.content) || Array.isArray(output.content))) return getTextContentFromMastraDBMessage(output) || getTextContentFromMastraDBMessage(output.content) || void 0;
257
+ if (output.role === "assistant") return getTextContentFromMastraDBMessage(output) || void 0;
258
+ };
259
+ /**
260
+ * Extracts reasoning text from a scorer run output.
261
+ *
262
+ * This function extracts reasoning content from assistant messages, which is
263
+ * produced by reasoning models like `deepseek-reasoner`. The reasoning can be
264
+ * stored in two places:
265
+ * 1. `content.reasoning` - a string field on the message content
266
+ * 2. `content.parts` - as parts with `type: 'reasoning'` containing `details`
267
+ *
268
+ * @param output - The scorer run output (array of MastraDBMessage)
269
+ * @returns The reasoning text, or `undefined` if no reasoning is present
270
+ *
271
+ * @example
272
+ * ```ts
273
+ * const reasoningScorer = createScorer({
274
+ * id: 'reasoning-scorer',
275
+ * name: 'Reasoning Quality',
276
+ * description: 'Evaluates the quality of model reasoning',
277
+ * type: 'agent',
278
+ * })
279
+ * .preprocess(({ run }) => {
280
+ * const reasoning = getReasoningFromRunOutput(run.output);
281
+ * const response = getAssistantMessageFromRunOutput(run.output);
282
+ * return { reasoning, response };
283
+ * })
284
+ * .generateScore(({ results }) => {
285
+ * // Score based on reasoning quality
286
+ * return results.preprocessStepResult?.reasoning ? 1 : 0;
287
+ * });
288
+ * ```
289
+ */
290
+ const getReasoningFromRunOutput = (output) => {
291
+ if (!output) return void 0;
292
+ const message = output.find(({ role }) => role === "assistant");
293
+ if (!message) return void 0;
294
+ if (message.content.reasoning) return message.content.reasoning;
295
+ const reasoningParts = message.content.parts?.filter((p) => p.type === "reasoning");
296
+ if (reasoningParts && reasoningParts.length > 0) {
297
+ const reasoningTexts = reasoningParts.map((p) => {
298
+ if (p.details && Array.isArray(p.details)) return p.details.filter((d) => d.type === "text").map((d) => d.text).join("");
299
+ return p.reasoning || "";
300
+ }).filter(Boolean);
301
+ return reasoningTexts.length > 0 ? reasoningTexts.join("\n") : void 0;
302
+ }
303
+ };
304
+ /**
305
+ * Creates a tool invocation object for testing purposes.
306
+ *
307
+ * @param options - The tool invocation configuration
308
+ * @param options.toolCallId - Unique identifier for the tool call
309
+ * @param options.toolName - Name of the tool being called
310
+ * @param options.args - Arguments passed to the tool
311
+ * @param options.result - Result returned by the tool
312
+ * @param options.state - State of the invocation (default: 'result')
313
+ * @returns A tool invocation object
314
+ *
315
+ * @example
316
+ * ```ts
317
+ * const invocation = createToolInvocation({
318
+ * toolCallId: 'call-123',
319
+ * toolName: 'weatherTool',
320
+ * args: { location: 'London' },
321
+ * result: { temperature: 20, condition: 'sunny' },
322
+ * });
323
+ * ```
324
+ */
325
+ const createToolInvocation = ({ toolCallId, toolName, args, result, state = "result" }) => {
326
+ return {
327
+ toolCallId,
328
+ toolName,
329
+ args,
330
+ result,
331
+ state
332
+ };
333
+ };
334
+ /**
335
+ * Creates a MastraDBMessage object for testing purposes.
336
+ *
337
+ * Supports optional tool invocations for testing tool call scenarios.
338
+ *
339
+ * @param options - The message configuration
340
+ * @param options.content - The text content of the message
341
+ * @param options.role - The role of the message sender ('user', 'assistant', or 'system')
342
+ * @param options.id - Optional message ID (default: 'test-message')
343
+ * @param options.toolInvocations - Optional array of tool invocations
344
+ * @returns A MastraDBMessage object
345
+ *
346
+ * @example
347
+ * ```ts
348
+ * const message = createTestMessage({
349
+ * content: 'Hello, how can I help?',
350
+ * role: 'assistant',
351
+ * });
352
+ *
353
+ * // With tool invocations
354
+ * const messageWithTools = createTestMessage({
355
+ * content: 'Let me check the weather.',
356
+ * role: 'assistant',
357
+ * toolInvocations: [{
358
+ * toolCallId: 'call-1',
359
+ * toolName: 'weatherTool',
360
+ * args: { location: 'Paris' },
361
+ * result: { temp: 22 },
362
+ * state: 'result',
363
+ * }],
364
+ * });
365
+ * ```
366
+ */
367
+ function createTestMessage({ content, role, id = "test-message", toolInvocations = [] }) {
368
+ return {
369
+ id,
370
+ role,
371
+ content: {
372
+ format: 2,
373
+ parts: [{
374
+ type: "text",
375
+ text: content
376
+ }],
377
+ content,
378
+ ...toolInvocations.length > 0 && { toolInvocations: toolInvocations.map((ti) => ({
379
+ toolCallId: ti.toolCallId,
380
+ toolName: ti.toolName,
381
+ args: ti.args,
382
+ result: ti.result,
383
+ state: ti.state
384
+ })) }
385
+ },
386
+ createdAt: /* @__PURE__ */ new Date()
387
+ };
388
+ }
389
+ /**
390
+ * Creates a complete agent test run object for testing scorers.
391
+ *
392
+ * Provides a convenient way to construct the full run object that scorers receive,
393
+ * including input messages, output, system messages, and request context.
394
+ *
395
+ * @param options - The test run configuration
396
+ * @param options.inputMessages - Array of input messages (default: [])
397
+ * @param options.output - The output messages (required)
398
+ * @param options.rememberedMessages - Array of remembered messages from memory (default: [])
399
+ * @param options.systemMessages - Array of system messages (default: [])
400
+ * @param options.taggedSystemMessages - Tagged system messages map (default: {})
401
+ * @param options.requestContext - Request context (default: new RequestContext())
402
+ * @param options.runId - Unique run ID (default: random UUID)
403
+ * @returns A complete test run object
404
+ *
405
+ * @example
406
+ * ```ts
407
+ * const testRun = createAgentTestRun({
408
+ * inputMessages: [createTestMessage({ content: 'Hello', role: 'user' })],
409
+ * output: [createTestMessage({ content: 'Hi there!', role: 'assistant' })],
410
+ * });
411
+ *
412
+ * const result = await scorer.run({
413
+ * input: testRun.input,
414
+ * output: testRun.output,
415
+ * });
416
+ * ```
417
+ */
418
+ const createAgentTestRun = ({ inputMessages = [], output, rememberedMessages = [], systemMessages = [], taggedSystemMessages = {}, requestContext = new _mastra_core_request_context.RequestContext(), runId = crypto.randomUUID() }) => {
419
+ return {
420
+ input: {
421
+ inputMessages,
422
+ rememberedMessages,
423
+ systemMessages,
424
+ taggedSystemMessages
425
+ },
426
+ output,
427
+ requestContext,
428
+ runId
429
+ };
430
+ };
431
+ /**
432
+ * Creates a test run for trajectory scorers where `output` is a `Trajectory`
433
+ * (pre-extracted by the `runEvals` pipeline).
434
+ *
435
+ * @example
436
+ * ```ts
437
+ * const testRun = createTrajectoryTestRun({
438
+ * inputMessages: [createTestMessage({ content: 'Do X', role: 'user', id: 'u1' })],
439
+ * trajectory: {
440
+ * steps: [
441
+ * { stepType: 'tool_call', name: 'search', toolArgs: { q: 'test' } },
442
+ * ],
443
+ * },
444
+ * });
445
+ * ```
446
+ */
447
+ const createTrajectoryTestRun = ({ inputMessages = [], trajectory, rememberedMessages = [], systemMessages = [], taggedSystemMessages = {}, requestContext = new _mastra_core_request_context.RequestContext(), runId = crypto.randomUUID(), expectedTrajectory }) => {
448
+ return {
449
+ input: {
450
+ inputMessages,
451
+ rememberedMessages,
452
+ systemMessages,
453
+ taggedSystemMessages
454
+ },
455
+ output: trajectory,
456
+ expectedTrajectory,
457
+ requestContext,
458
+ runId
459
+ };
460
+ };
461
+ /**
462
+ * Extracts all tool calls from a scorer run output.
463
+ *
464
+ * Iterates through all messages and their tool invocations to collect
465
+ * information about tools that were called (with state 'result' or 'call').
466
+ *
467
+ * @param output - The scorer run output (array of MastraDBMessage)
468
+ * @returns An object containing tool names and detailed tool call info
469
+ *
470
+ * @example
471
+ * ```ts
472
+ * const scorer = createScorer({ ... })
473
+ * .preprocess(({ run }) => {
474
+ * const { tools, toolCallInfos } = extractToolCalls(run.output);
475
+ * return {
476
+ * toolsUsed: tools,
477
+ * toolCount: tools.length,
478
+ * };
479
+ * });
480
+ * ```
481
+ */
482
+ function extractToolCalls(output) {
483
+ const toolCalls = [];
484
+ const toolCallInfos = [];
485
+ for (let messageIndex = 0; messageIndex < output.length; messageIndex++) {
486
+ const message = output[messageIndex];
487
+ const legacy = message?.content?.toolInvocations;
488
+ const fromParts = legacy ? void 0 : message?.content?.parts?.filter((p) => p.type === "tool-invocation").map((p) => p.toolInvocation);
489
+ const toolInvocations = legacy ?? fromParts;
490
+ if (!toolInvocations?.length) continue;
491
+ for (let invocationIndex = 0; invocationIndex < toolInvocations.length; invocationIndex++) {
492
+ const invocation = toolInvocations[invocationIndex];
493
+ if (invocation && invocation.toolName && (invocation.state === "result" || invocation.state === "call")) {
494
+ toolCalls.push(invocation.toolName);
495
+ toolCallInfos.push({
496
+ toolName: invocation.toolName,
497
+ toolCallId: invocation.toolCallId || `${messageIndex}-${invocationIndex}`,
498
+ messageIndex,
499
+ invocationIndex
500
+ });
501
+ }
502
+ }
503
+ }
504
+ return {
505
+ tools: toolCalls,
506
+ toolCallInfos
507
+ };
508
+ }
509
+ /**
510
+ * Extracts text content from all input messages.
511
+ *
512
+ * @param runInput - The scorer run input
513
+ * @returns An array of text strings from each input message
514
+ *
515
+ * @example
516
+ * ```ts
517
+ * const scorer = createScorer({ ... })
518
+ * .preprocess(({ run }) => {
519
+ * const messages = extractInputMessages(run.input);
520
+ * return { allUserMessages: messages.join('\n') };
521
+ * });
522
+ * ```
523
+ */
524
+ const extractInputMessages = (runInput) => {
525
+ return runInput?.inputMessages?.map((msg) => getTextContentFromMastraDBMessage(msg)) || [];
526
+ };
527
+ /**
528
+ * Extracts text content from all assistant response messages.
529
+ *
530
+ * Filters for messages with role 'assistant' and extracts their text content.
531
+ *
532
+ * @param runOutput - The scorer run output (array of MastraDBMessage)
533
+ * @returns An array of text strings from each assistant message
534
+ *
535
+ * @example
536
+ * ```ts
537
+ * const scorer = createScorer({ ... })
538
+ * .preprocess(({ run }) => {
539
+ * const responses = extractAgentResponseMessages(run.output);
540
+ * return { allResponses: responses.join('\n') };
541
+ * });
542
+ * ```
543
+ */
544
+ const extractAgentResponseMessages = (runOutput) => {
545
+ return runOutput.filter((msg) => msg.role === "assistant").map((msg) => getTextContentFromMastraDBMessage(msg));
546
+ };
547
+ /**
548
+ * Extracts tool results from a scorer run output.
549
+ *
550
+ * Returns structured objects that can be used with the hallucination scorer's
551
+ * `getContext` hook or for other scorer logic.
552
+ *
553
+ * @param output - The scorer run output (array of MastraDBMessage)
554
+ * @returns An array of ToolResultInfo objects
555
+ *
556
+ * @example
557
+ * ```ts
558
+ * import { extractToolResults } from '@mastra/evals/scorers';
559
+ * import { createHallucinationScorer } from '@mastra/evals/scorers/prebuilt';
560
+ *
561
+ * const scorer = createHallucinationScorer({
562
+ * model: openai('gpt-4o'),
563
+ * options: {
564
+ * getContext: (run) => {
565
+ * const toolResults = extractToolResults(run.output);
566
+ * return toolResults.map(t => JSON.stringify({ tool: t.toolName, result: t.result }));
567
+ * },
568
+ * },
569
+ * });
570
+ * ```
571
+ */
572
+ function extractToolResults(output) {
573
+ const results = [];
574
+ for (const message of output) {
575
+ const legacy = message?.content?.toolInvocations;
576
+ const fromParts = legacy ? void 0 : message?.content?.parts?.filter((p) => p.type === "tool-invocation").map((p) => p.toolInvocation);
577
+ const toolInvocations = legacy ?? fromParts;
578
+ if (!toolInvocations?.length) continue;
579
+ for (const invocation of toolInvocations) if (invocation.state === "result" && invocation.result !== void 0) results.push({
580
+ toolName: invocation.toolName,
581
+ toolCallId: invocation.toolCallId || "",
582
+ args: invocation.args || {},
583
+ result: invocation.result
584
+ });
585
+ }
586
+ return results;
587
+ }
588
+ /**
589
+ * Compares two trajectories and returns detailed comparison results.
590
+ *
591
+ * This is the core comparison logic used by trajectory scorers. It supports
592
+ * strict and non-strict ordering, optional step data comparison, and loop detection.
593
+ *
594
+ * @param actual - The trajectory the agent actually took
595
+ * @param expected - The expected trajectory to compare against
596
+ * @param options - Comparison configuration options
597
+ * @returns Detailed comparison results including match scores and diagnostics
598
+ *
599
+ * @example
600
+ * ```ts
601
+ * const result = compareTrajectories(
602
+ * { steps: [{ stepType: 'tool_call', name: 'search' }, { stepType: 'tool_call', name: 'summarize' }] },
603
+ * { steps: [{ stepType: 'tool_call', name: 'search' }, { stepType: 'tool_call', name: 'summarize' }] },
604
+ * { ordering: 'strict' }
605
+ * );
606
+ * // result.score = 1.0
607
+ * ```
608
+ */
609
+ function compareTrajectories(actual, expected, options = {}) {
610
+ const { allowRepeatedSteps = true, ordering = "relaxed" } = options;
611
+ const normalizedExpected = { steps: expected.steps };
612
+ if (normalizedExpected.steps.length === 0) return {
613
+ score: actual.steps.length === 0 ? 1 : 0,
614
+ matchedSteps: 0,
615
+ totalExpectedSteps: 0,
616
+ totalActualSteps: actual.steps.length,
617
+ missingSteps: [],
618
+ extraSteps: actual.steps.map((s) => s.name),
619
+ outOfOrderSteps: [],
620
+ repeatedSteps: []
621
+ };
622
+ const actualNames = actual.steps.map((s) => s.name);
623
+ const nameCounts = /* @__PURE__ */ new Map();
624
+ for (const name of actualNames) nameCounts.set(name, (nameCounts.get(name) || 0) + 1);
625
+ const repeatedSteps = [...nameCounts.entries()].filter(([_, count]) => count > 1).map(([name]) => name);
626
+ if (ordering === "strict") return compareStrictOrder(actual, normalizedExpected, {
627
+ allowRepeatedSteps,
628
+ repeatedSteps
629
+ });
630
+ if (ordering === "unordered") return compareUnorderedPresence(actual, normalizedExpected, {
631
+ allowRepeatedSteps,
632
+ repeatedSteps
633
+ });
634
+ return compareRelaxedOrder(actual, normalizedExpected, {
635
+ allowRepeatedSteps,
636
+ repeatedSteps
637
+ });
638
+ }
639
+ function compareStrictOrder(actual, expected, opts) {
640
+ const actualNames = actual.steps.map((s) => s.name);
641
+ const expectedNames = expected.steps.map((s) => s.name);
642
+ let matchedSteps = 0;
643
+ const outOfOrderSteps = [];
644
+ const matchedExpectedIndices = /* @__PURE__ */ new Set();
645
+ const maxLen = Math.max(actualNames.length, expectedNames.length);
646
+ for (let i = 0; i < maxLen; i++) {
647
+ const actualName = actualNames[i];
648
+ if (actualName === expectedNames[i]) if (actual.steps[i] && expected.steps[i]) {
649
+ if (expectedStepMatches(actual.steps[i], expected.steps[i])) {
650
+ matchedSteps++;
651
+ matchedExpectedIndices.add(i);
652
+ }
653
+ } else {
654
+ matchedSteps++;
655
+ matchedExpectedIndices.add(i);
656
+ }
657
+ else if (actualName && expectedNames.includes(actualName)) outOfOrderSteps.push(actualName);
658
+ }
659
+ const missingSteps = expectedNames.filter((_, i) => !matchedExpectedIndices.has(i));
660
+ const extraSteps = actualNames.filter((name) => !expectedNames.includes(name));
661
+ let score = matchedSteps / expected.steps.length;
662
+ if (actualNames.length > expectedNames.length) {
663
+ const extraPenalty = (actualNames.length - expectedNames.length) / expectedNames.length;
664
+ score = Math.max(0, score - extraPenalty * .5);
665
+ }
666
+ if (!opts.allowRepeatedSteps && opts.repeatedSteps.length > 0) score = Math.max(0, score - opts.repeatedSteps.length * .1);
667
+ return {
668
+ score: roundToTwoDecimals(Math.max(0, Math.min(1, score))),
669
+ matchedSteps,
670
+ totalExpectedSteps: expected.steps.length,
671
+ totalActualSteps: actual.steps.length,
672
+ missingSteps,
673
+ extraSteps,
674
+ outOfOrderSteps,
675
+ repeatedSteps: opts.repeatedSteps
676
+ };
677
+ }
678
+ function compareRelaxedOrder(actual, expected, opts) {
679
+ const actualNames = actual.steps.map((s) => s.name);
680
+ const expectedNames = expected.steps.map((s) => s.name);
681
+ let matchedSteps = 0;
682
+ let lastMatchedIndex = -1;
683
+ const outOfOrderSteps = [];
684
+ const matchedExpectedIndices = /* @__PURE__ */ new Set();
685
+ for (let i = 0; i < expectedNames.length; i++) {
686
+ const expectedName = expectedNames[i];
687
+ let found = false;
688
+ for (let j = lastMatchedIndex + 1; j < actualNames.length; j++) if (actualNames[j] === expectedName) if (actual.steps[j] && expected.steps[i]) {
689
+ if (expectedStepMatches(actual.steps[j], expected.steps[i])) {
690
+ matchedSteps++;
691
+ lastMatchedIndex = j;
692
+ matchedExpectedIndices.add(i);
693
+ found = true;
694
+ break;
695
+ }
696
+ } else {
697
+ matchedSteps++;
698
+ lastMatchedIndex = j;
699
+ matchedExpectedIndices.add(i);
700
+ found = true;
701
+ break;
702
+ }
703
+ if (!found) {
704
+ if (actualNames.includes(expectedName)) outOfOrderSteps.push(expectedName);
705
+ }
706
+ }
707
+ const missingSteps = expectedNames.filter((_, i) => !matchedExpectedIndices.has(i));
708
+ const expectedSet = new Set(expectedNames);
709
+ const extraSteps = actualNames.filter((name) => !expectedSet.has(name));
710
+ let score = matchedSteps / expected.steps.length;
711
+ if (!opts.allowRepeatedSteps && opts.repeatedSteps.length > 0) score = Math.max(0, score - opts.repeatedSteps.length * .1);
712
+ return {
713
+ score: roundToTwoDecimals(Math.max(0, Math.min(1, score))),
714
+ matchedSteps,
715
+ totalExpectedSteps: expected.steps.length,
716
+ totalActualSteps: actual.steps.length,
717
+ missingSteps,
718
+ extraSteps,
719
+ outOfOrderSteps,
720
+ repeatedSteps: opts.repeatedSteps
721
+ };
722
+ }
723
+ /**
724
+ * Fields on each ExpectedStep variant that are comparable data (not structural).
725
+ * Used by `expectedStepMatches` to know which fields to compare when `compareData` is true.
726
+ */
727
+ const COMPARABLE_FIELDS_BY_TYPE = {
728
+ tool_call: [
729
+ "toolArgs",
730
+ "toolResult",
731
+ "success"
732
+ ],
733
+ mcp_tool_call: [
734
+ "toolArgs",
735
+ "toolResult",
736
+ "mcpServer",
737
+ "success"
738
+ ],
739
+ model_generation: [
740
+ "modelId",
741
+ "promptTokens",
742
+ "completionTokens",
743
+ "finishReason"
744
+ ],
745
+ agent_run: ["agentId"],
746
+ workflow_step: [
747
+ "stepId",
748
+ "status",
749
+ "output"
750
+ ],
751
+ workflow_run: ["workflowId", "status"],
752
+ workflow_conditional: ["conditionCount", "selectedSteps"],
753
+ workflow_parallel: ["branchCount", "parallelSteps"],
754
+ workflow_loop: ["loopType", "totalIterations"],
755
+ workflow_sleep: ["sleepDurationMs", "sleepType"],
756
+ workflow_wait_event: ["eventName", "eventReceived"],
757
+ processor_run: ["processorId"]
758
+ };
759
+ /**
760
+ * Check if an actual TrajectoryStep matches an ExpectedStep.
761
+ * Matches by name, optionally by stepType, and auto-compares any variant-specific
762
+ * fields that are present on the expected step.
763
+ */
764
+ function expectedStepMatches(actual, expected) {
765
+ if (actual.name !== expected.name) return false;
766
+ if (expected.stepType && actual.stepType !== expected.stepType) return false;
767
+ if (expected.stepType) {
768
+ const fields = COMPARABLE_FIELDS_BY_TYPE[expected.stepType] ?? [];
769
+ for (const field of fields) {
770
+ const expectedVal = expected[field];
771
+ if (expectedVal === void 0) continue;
772
+ const actualVal = actual[field];
773
+ if (actualVal === void 0) return false;
774
+ try {
775
+ if (JSON.stringify(actualVal) !== JSON.stringify(expectedVal)) return false;
776
+ } catch {
777
+ return false;
778
+ }
779
+ }
780
+ }
781
+ return true;
782
+ }
783
+ function compareUnorderedPresence(actual, expected, opts) {
784
+ const actualNames = actual.steps.map((s) => s.name);
785
+ const expectedNames = expected.steps.map((s) => s.name);
786
+ let matchedSteps = 0;
787
+ const matchedExpectedIndices = /* @__PURE__ */ new Set();
788
+ const usedIndices = /* @__PURE__ */ new Set();
789
+ for (let i = 0; i < expected.steps.length; i++) {
790
+ const expectedStep = expected.steps[i];
791
+ for (let j = 0; j < actual.steps.length; j++) if (!usedIndices.has(j) && expectedStepMatches(actual.steps[j], expectedStep)) {
792
+ matchedSteps++;
793
+ matchedExpectedIndices.add(i);
794
+ usedIndices.add(j);
795
+ break;
796
+ }
797
+ }
798
+ const missingSteps = expectedNames.filter((_, i) => !matchedExpectedIndices.has(i));
799
+ const expectedSet = new Set(expectedNames);
800
+ const extraSteps = actualNames.filter((name) => !expectedSet.has(name));
801
+ let score = matchedSteps / expected.steps.length;
802
+ if (!opts.allowRepeatedSteps && opts.repeatedSteps.length > 0) score = Math.max(0, score - opts.repeatedSteps.length * .1);
803
+ return {
804
+ score: roundToTwoDecimals(Math.max(0, Math.min(1, score))),
805
+ matchedSteps,
806
+ totalExpectedSteps: expected.steps.length,
807
+ totalActualSteps: actual.steps.length,
808
+ missingSteps,
809
+ extraSteps,
810
+ outOfOrderSteps: [],
811
+ repeatedSteps: opts.repeatedSteps
812
+ };
813
+ }
814
+ /**
815
+ * Evaluate trajectory efficiency against budgets and redundancy checks.
816
+ */
817
+ function checkTrajectoryEfficiency(trajectory, options = {}) {
818
+ const { maxSteps, maxTotalTokens, maxTotalDurationMs, noRedundantCalls = true } = options;
819
+ const totalSteps = trajectory.steps.length;
820
+ let totalTokens = 0;
821
+ for (const step of trajectory.steps) if (step.stepType === "model_generation") totalTokens += (step.promptTokens ?? 0) + (step.completionTokens ?? 0);
822
+ const totalDurationMs = trajectory.totalDurationMs ?? trajectory.steps.reduce((sum, s) => sum + (s.durationMs ?? 0), 0);
823
+ const redundantCalls = [];
824
+ if (noRedundantCalls) for (let i = 1; i < trajectory.steps.length; i++) {
825
+ const prev = trajectory.steps[i - 1];
826
+ const curr = trajectory.steps[i];
827
+ if (prev.name === curr.name && prev.stepType === curr.stepType && (prev.stepType === "tool_call" || prev.stepType === "mcp_tool_call")) {
828
+ const prevArgs = prev.toolArgs;
829
+ const currArgs = curr.toolArgs;
830
+ try {
831
+ if (JSON.stringify(prevArgs) === JSON.stringify(currArgs)) redundantCalls.push({
832
+ name: curr.name,
833
+ index: i
834
+ });
835
+ } catch {}
836
+ }
837
+ }
838
+ const overStepBudget = maxSteps !== void 0 && totalSteps > maxSteps;
839
+ const overTokenBudget = maxTotalTokens !== void 0 && totalTokens > maxTotalTokens;
840
+ const overDurationBudget = maxTotalDurationMs !== void 0 && totalDurationMs > maxTotalDurationMs;
841
+ const dimensions = [];
842
+ if (maxSteps !== void 0) dimensions.push(overStepBudget ? Math.max(0, 1 - (totalSteps - maxSteps) / maxSteps) : 1);
843
+ if (maxTotalTokens !== void 0) dimensions.push(overTokenBudget ? Math.max(0, 1 - (totalTokens - maxTotalTokens) / maxTotalTokens) : 1);
844
+ if (maxTotalDurationMs !== void 0) dimensions.push(overDurationBudget ? Math.max(0, 1 - (totalDurationMs - maxTotalDurationMs) / maxTotalDurationMs) : 1);
845
+ if (noRedundantCalls) dimensions.push(redundantCalls.length === 0 ? 1 : Math.max(0, 1 - redundantCalls.length * .2));
846
+ const score = dimensions.length > 0 ? dimensions.reduce((a, b) => a + b, 0) / dimensions.length : 1;
847
+ return {
848
+ score: roundToTwoDecimals(Math.max(0, Math.min(1, score))),
849
+ totalSteps,
850
+ overStepBudget,
851
+ totalTokens,
852
+ overTokenBudget,
853
+ totalDurationMs,
854
+ overDurationBudget,
855
+ redundantCalls
856
+ };
857
+ }
858
+ /**
859
+ * Check if a trajectory violates any blacklist rules.
860
+ * Returns score 0.0 if any violation is found (hard fail).
861
+ */
862
+ function checkTrajectoryBlacklist(trajectory, options = {}) {
863
+ const { blacklistedTools = [], blacklistedSequences = [] } = options;
864
+ const violatedTools = [];
865
+ const violatedSequences = [];
866
+ const stepNames = trajectory.steps.map((s) => s.name);
867
+ for (const forbidden of blacklistedTools) if (stepNames.includes(forbidden)) violatedTools.push(forbidden);
868
+ for (const sequence of blacklistedSequences) {
869
+ if (sequence.length === 0) continue;
870
+ for (let i = 0; i <= stepNames.length - sequence.length; i++) {
871
+ let match = true;
872
+ for (let j = 0; j < sequence.length; j++) if (stepNames[i + j] !== sequence[j]) {
873
+ match = false;
874
+ break;
875
+ }
876
+ if (match) {
877
+ violatedSequences.push(sequence);
878
+ break;
879
+ }
880
+ }
881
+ }
882
+ return {
883
+ score: violatedTools.length > 0 || violatedSequences.length > 0 ? 0 : 1,
884
+ violatedTools,
885
+ violatedSequences
886
+ };
887
+ }
888
+ /**
889
+ * Analyze tool failure and retry patterns in a trajectory.
890
+ */
891
+ function analyzeToolFailures(trajectory, options = {}) {
892
+ const { maxRetriesPerTool = 2 } = options;
893
+ const patterns = [];
894
+ let totalRetries = 0;
895
+ const toolCallSteps = trajectory.steps.filter((s) => s.stepType === "tool_call" || s.stepType === "mcp_tool_call");
896
+ if (toolCallSteps.length === 0) return {
897
+ score: 1,
898
+ patterns: [],
899
+ totalRetries: 0,
900
+ excessiveRetryTools: []
901
+ };
902
+ let i = 0;
903
+ while (i < toolCallSteps.length) {
904
+ const currentTool = toolCallSteps[i];
905
+ let retryCount = 0;
906
+ let j = i + 1;
907
+ while (j < toolCallSteps.length && toolCallSteps[j].name === currentTool.name) {
908
+ if (toolCallSteps[j - 1].success === false) retryCount++;
909
+ j++;
910
+ }
911
+ if (retryCount > 0) {
912
+ const nextDifferentTool = j < toolCallSteps.length ? toolCallSteps[j] : void 0;
913
+ const lastSuccess = toolCallSteps[j - 1].success !== false;
914
+ patterns.push({
915
+ toolName: currentTool.name,
916
+ retryCount,
917
+ fellBackToAlternative: nextDifferentTool !== void 0 && !lastSuccess,
918
+ alternativeTool: nextDifferentTool !== void 0 && !lastSuccess ? nextDifferentTool.name : void 0,
919
+ eventuallySucceeded: lastSuccess
920
+ });
921
+ totalRetries += retryCount;
922
+ }
923
+ i = j;
924
+ }
925
+ const excessiveRetryTools = patterns.filter((p) => p.retryCount > maxRetriesPerTool).map((p) => p.toolName);
926
+ let score = 1;
927
+ if (toolCallSteps.length > 0) {
928
+ const excessRetries = patterns.reduce((sum, p) => sum + Math.max(0, p.retryCount - maxRetriesPerTool), 0);
929
+ score = Math.max(0, 1 - excessRetries * .2);
930
+ }
931
+ return {
932
+ score: roundToTwoDecimals(Math.max(0, Math.min(1, score))),
933
+ patterns,
934
+ totalRetries,
935
+ excessiveRetryTools
936
+ };
937
+ }
938
+ //#endregion
939
+ exports.analyzeToolFailures = analyzeToolFailures;
940
+ exports.checkTrajectoryBlacklist = checkTrajectoryBlacklist;
941
+ exports.checkTrajectoryEfficiency = checkTrajectoryEfficiency;
942
+ exports.compareTrajectories = compareTrajectories;
943
+ exports.createAgentTestRun = createAgentTestRun;
944
+ exports.createTestMessage = createTestMessage;
945
+ exports.createTestRun = createTestRun;
946
+ exports.createToolInvocation = createToolInvocation;
947
+ exports.createTrajectoryTestRun = createTrajectoryTestRun;
948
+ exports.extractAgentResponseMessages = extractAgentResponseMessages;
949
+ exports.extractInputMessages = extractInputMessages;
950
+ exports.extractToolCalls = extractToolCalls;
951
+ exports.extractToolResults = extractToolResults;
59
952
  Object.defineProperty(exports, "extractTrajectory", {
60
- enumerable: true,
61
- get: function () { return chunkIZLA36WC_cjs.extractTrajectory; }
62
- });
63
- Object.defineProperty(exports, "getAssistantMessageFromRunOutput", {
64
- enumerable: true,
65
- get: function () { return chunkIZLA36WC_cjs.getAssistantMessageFromRunOutput; }
66
- });
67
- Object.defineProperty(exports, "getCombinedSystemPrompt", {
68
- enumerable: true,
69
- get: function () { return chunkIZLA36WC_cjs.getCombinedSystemPrompt; }
70
- });
71
- Object.defineProperty(exports, "getReasoningFromRunOutput", {
72
- enumerable: true,
73
- get: function () { return chunkIZLA36WC_cjs.getReasoningFromRunOutput; }
74
- });
75
- Object.defineProperty(exports, "getSystemMessagesFromRunInput", {
76
- enumerable: true,
77
- get: function () { return chunkIZLA36WC_cjs.getSystemMessagesFromRunInput; }
953
+ enumerable: true,
954
+ get: function() {
955
+ return _mastra_core_evals.extractTrajectory;
956
+ }
78
957
  });
79
- Object.defineProperty(exports, "getTextContentFromMastraDBMessage", {
80
- enumerable: true,
81
- get: function () { return chunkIZLA36WC_cjs.getTextContentFromMastraDBMessage; }
82
- });
83
- Object.defineProperty(exports, "getUserMessageFromRunInput", {
84
- enumerable: true,
85
- get: function () { return chunkIZLA36WC_cjs.getUserMessageFromRunInput; }
86
- });
87
- Object.defineProperty(exports, "isCloserTo", {
88
- enumerable: true,
89
- get: function () { return chunkIZLA36WC_cjs.isCloserTo; }
90
- });
91
- Object.defineProperty(exports, "isScorerRunInputForAgent", {
92
- enumerable: true,
93
- get: function () { return chunkIZLA36WC_cjs.isScorerRunInputForAgent; }
94
- });
95
- Object.defineProperty(exports, "isScorerRunOutputForAgent", {
96
- enumerable: true,
97
- get: function () { return chunkIZLA36WC_cjs.isScorerRunOutputForAgent; }
98
- });
99
- Object.defineProperty(exports, "roundToTwoDecimals", {
100
- enumerable: true,
101
- get: function () { return chunkIZLA36WC_cjs.roundToTwoDecimals; }
102
- });
103
- //# sourceMappingURL=utils.cjs.map
958
+ exports.getAssistantMessageFromRunOutput = getAssistantMessageFromRunOutput;
959
+ exports.getCombinedSystemPrompt = getCombinedSystemPrompt;
960
+ exports.getReasoningFromRunOutput = getReasoningFromRunOutput;
961
+ exports.getSystemMessagesFromRunInput = getSystemMessagesFromRunInput;
962
+ exports.getTextContentFromMastraDBMessage = getTextContentFromMastraDBMessage;
963
+ exports.getUserMessageFromRunInput = getUserMessageFromRunInput;
964
+ exports.isCloserTo = isCloserTo;
965
+ exports.isScorerRunInputForAgent = isScorerRunInputForAgent;
966
+ exports.isScorerRunOutputForAgent = isScorerRunOutputForAgent;
967
+ exports.roundToTwoDecimals = roundToTwoDecimals;
968
+
104
969
  //# sourceMappingURL=utils.cjs.map