@mastra/evals 0.12.1 → 0.12.2-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/dist/chunk-5CVZXIFW.js +36 -0
  2. package/dist/chunk-5CVZXIFW.js.map +1 -0
  3. package/dist/chunk-QVZBKGOE.cjs +41 -0
  4. package/dist/chunk-QVZBKGOE.cjs.map +1 -0
  5. package/dist/{dist-BODKWAXM.cjs → dist-JQCAD3AD.cjs} +9 -9
  6. package/dist/{dist-BODKWAXM.cjs.map → dist-JQCAD3AD.cjs.map} +1 -1
  7. package/dist/{dist-JRG62SVA.js → dist-JVIEAZJ6.js} +9 -9
  8. package/dist/{dist-JRG62SVA.js.map → dist-JVIEAZJ6.js.map} +1 -1
  9. package/dist/evaluation.d.ts +1 -1
  10. package/dist/evaluation.d.ts.map +1 -1
  11. package/dist/index.cjs +3 -3
  12. package/dist/index.cjs.map +1 -1
  13. package/dist/index.js +2 -2
  14. package/dist/index.js.map +1 -1
  15. package/dist/scorers/code/index.cjs +85 -0
  16. package/dist/scorers/code/index.cjs.map +1 -1
  17. package/dist/scorers/code/index.d.ts +1 -0
  18. package/dist/scorers/code/index.d.ts.map +1 -1
  19. package/dist/scorers/code/index.js +85 -1
  20. package/dist/scorers/code/index.js.map +1 -1
  21. package/dist/scorers/code/tool-call-accuracy/index.d.ts +18 -0
  22. package/dist/scorers/code/tool-call-accuracy/index.d.ts.map +1 -0
  23. package/dist/scorers/llm/index.cjs +184 -28
  24. package/dist/scorers/llm/index.cjs.map +1 -1
  25. package/dist/scorers/llm/index.d.ts +1 -0
  26. package/dist/scorers/llm/index.d.ts.map +1 -1
  27. package/dist/scorers/llm/index.js +170 -15
  28. package/dist/scorers/llm/index.js.map +1 -1
  29. package/dist/scorers/llm/tool-call-accuracy/index.d.ts +22 -0
  30. package/dist/scorers/llm/tool-call-accuracy/index.d.ts.map +1 -0
  31. package/dist/scorers/llm/tool-call-accuracy/prompts.d.ts +19 -0
  32. package/dist/scorers/llm/tool-call-accuracy/prompts.d.ts.map +1 -0
  33. package/dist/scorers/utils.d.ts +12 -0
  34. package/dist/scorers/utils.d.ts.map +1 -1
  35. package/package.json +10 -9
@@ -1,5 +1,5 @@
1
- import type { Metric } from '@mastra/core';
2
1
  import type { Agent } from '@mastra/core/agent';
2
+ import type { Metric } from '@mastra/core/eval';
3
3
  export declare function evaluate<T extends Agent>(agent: T, input: Parameters<T['generate']>[0], metric: Metric): Promise<import("@mastra/core").EvaluationResult>;
4
4
  export declare const getCurrentTestInfo: () => Promise<{
5
5
  testName: any;
@@ -1 +1 @@
1
- {"version":3,"file":"evaluation.d.ts","sourceRoot":"","sources":["../src/evaluation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAIhD,wBAAsB,QAAQ,CAAC,CAAC,SAAS,KAAK,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,oDAyB5G;AAED,eAAO,MAAM,kBAAkB;;;cAwB9B,CAAC"}
1
+ {"version":3,"file":"evaluation.d.ts","sourceRoot":"","sources":["../src/evaluation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAIhD,wBAAsB,QAAQ,CAAC,CAAC,SAAS,KAAK,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,oDAyB5G;AAED,eAAO,MAAM,kBAAkB;;;cAwB9B,CAAC"}
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var core = require('@mastra/core');
3
+ var _eval = require('@mastra/core/eval');
4
4
  var hooks = require('@mastra/core/hooks');
5
5
  var storage = require('@mastra/core/storage');
6
6
  var utils = require('@mastra/core/utils');
@@ -20,7 +20,7 @@ async function evaluate(agent, input, metric) {
20
20
  globalRunId = process.env[GLOBAL_RUN_ID_ENV_KEY] = crypto.randomUUID();
21
21
  console.warn('Global run id not set, you should run "globalSetup" from "@mastra/evals" before evaluating.');
22
22
  }
23
- const metricResult = await core.evaluate({
23
+ const metricResult = await _eval.evaluate({
24
24
  agentName: agent.name,
25
25
  input,
26
26
  metric,
@@ -41,7 +41,7 @@ var getCurrentTestInfo = async () => {
41
41
  };
42
42
  }
43
43
  try {
44
- const vitest = await import('./dist-BODKWAXM.cjs');
44
+ const vitest = await import('./dist-JQCAD3AD.cjs');
45
45
  if (typeof vitest !== "undefined" && vitest.expect?.getState) {
46
46
  const state = vitest.expect.getState();
47
47
  return {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/constants.ts","../src/evaluation.ts","../src/attachListeners.ts"],"names":["coreEvaluate","registerHook","AvailableHooks","storage","checkEvalStorageFields","TABLE_EVALS"],"mappings":";;;;;;;;AAAO,IAAM,qBAAA,GAAwB,wBAAA;;;ACMrC,eAAsB,QAAA,CAA0B,KAAA,EAAU,KAAA,EAAqC,MAAA,EAAgB;AAC7G,EAAA,MAAM,QAAA,GAAW,MAAM,kBAAA,EAAmB;AAC1C,EAAA,IAAI,WAAA,GAAc,OAAA,CAAQ,GAAA,CAAI,qBAAqB,CAAA;AACnD,EAAA,MAAM,KAAA,GAAQ,OAAO,UAAA,EAAW;AAChC,EAAA,MAAM,WAAA,GAAc,MAAM,KAAA,CAAM,QAAA,CAAS,KAAA,EAAO;AAAA,IAC9C;AAAA,GACD,CAAA;AAED,EAAA,IAAI,CAAC,WAAA,EAAa;AAChB,IAAA,WAAA,GAAc,OAAA,CAAQ,GA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,EAAS;AAEX,MAAA,MAAM,MAAA,GAAS,QAAQ,SAAA,EAAU;AACjC,MAAA,MAAM,cAAA,GAAiBC,4BAAA,CAAuB,WAAA,EAAa,MAAM,CAAA;AACjE,MAAA,IAAI,CAAC,cAAA,EAAgB;AAErB,MAAA,MAAMD,UAAQ,MAAA,CAAO;AAAA,QACnB,SAAA,EAAWE,mBAAA;AAAA,QACX,MAAA,EAAQ;AAAA,UACN,OAAO,WAAA,CAAY,KAAA;AAAA,UACnB,QAAQ,WAAA,CAAY,MAAA;AAAA,UACpB,QAAQ,IAAA,CAAK,SAAA,CAAU,WAAA,CAAY,MAAA,IAAU,EAAE,CAAA;AAAA,UAC/C,YAAY,WAAA,CAAY,SAAA;AAAA,UACxB,aAAa,WAAA,CAAY,UAAA;AAAA,UACzB,cAAc,WAAA,CAAY,YAAA;AAAA,UAC1B,WAAW,WAAA,CAAY,QAAA,GAAW,KAAK,SAAA,CAAU,WAAA,CAAY,QAAQ,CAAA,GAAI,IAAA;AAAA,UACzE,eAAe,WAAA,CAAY,WAAA;AAAA,UAC3B,QAAQ,WAAA,CAAY,KAAA;AAAA,UACpB,UAAA,EAAA,iBAAY,IAAI,IAAA,EAAK,EAAE,WAAA;AAAY;AACrC,OACD,CAAA;AAAA,IACH;AAAA,EACF,CAAC,CAAA;AACH;AAEA,eAAsB,WAAA,GAAc;AAClC,EAAA,IAAI,OAAA,CAAQ,GAAA,CAAI,qBAAqB,CAAA,EAAG;AACtC,IAAA,MAAM,IAAI,MAAM,mEAAmE,CAAA;AAAA,EACrF;AAEA,EAAA,MAAM,WAAA,GAAc,OAAO,UAAA,EAAW;AACtC,EAAA,OAAA,CAAQ,GAAA,CAAI,qBAAqB,CAAA,GAAI,WAAA;AACvC","file":"index.cjs","sourcesContent":["export const GLOBAL_RUN_ID_ENV_KEY = '_MASTRA_GLOBAL_RUN_ID_';\n","import { evaluate as coreEvaluate } from '@mastra/core';\nimport type { Metric } from '@mastra/core';\nimport type { Agent } from '@mastra/core/agent';\n\nimport { GLOBAL_RUN_ID_ENV_KEY } from './constants';\n\nexport async function evaluate<T extends Agent>(agent: T, input: Parameters<T['generate']>[0], metric: Metric) {\n const testInfo = await getCurrentTestInfo();\n let globalRunId = process.env[GLOBAL_RUN_ID_ENV_KEY];\n const runId = crypto.randomUUID();\n const agentOutput = await agent.generate(input, {\n runId,\n });\n\n if (!globalRunId) {\n globalRunId = process.env[GLOBAL_RUN_ID_ENV_KEY] = crypto.randomUUID();\n console.warn('Global run id not set, you should run \"globalSetup\" from \"@mastra/evals\" before evaluating.');\n }\n\n const metricResult = await coreEvaluate({\n agentName: agent.name,\n input,\n metric,\n output: agentOutput.text,\n globalRunId,\n runId,\n testInfo,\n instructions: agent.instructions,\n });\n\n return metricResult;\n}\n\nexport const getCurrentTestInfo = async () => {\n // Jest\n // @ts-ignore\n if (typeof expect !== 'undefined' && expect.getState) {\n // @ts-ignore\n const state = expect.getState();\n return {\n testName: state.currentTestName,\n testPath: state.testPath,\n };\n }\n\n try {\n const vitest = await import('vitest');\n if (typeof vitest !== 'undefined' && vitest.expect?.getState) {\n const state = vitest.expect.getState();\n return {\n testName: state.currentTestName,\n testPath: state.testPath,\n };\n }\n } catch {}\n\n return undefined;\n};\n","import type { Mastra } from '@mastra/core';\nimport { AvailableHooks, registerHook } from '@mastra/core/hooks';\nimport { TABLE_EVALS } from '@mastra/core/storage';\nimport { checkEvalStorageFields } from '@mastra/core/utils';\n\nimport { GLOBAL_RUN_ID_ENV_KEY } from './constants';\n\nexport async function attachListeners(mastra?: Mastra) {\n registerHook(AvailableHooks.ON_EVALUATION, async traceObject => {\n const storage = mastra?.getStorage();\n if (storage) {\n // Check for required fields\n const logger = mastra?.getLogger();\n const areFieldsValid = checkEvalStorageFields(traceObject, logger);\n if (!areFieldsValid) return;\n\n await storage.insert({\n tableName: TABLE_EVALS,\n record: {\n input: traceObject.input,\n output: traceObject.output,\n result: JSON.stringify(traceObject.result || {}),\n agent_name: traceObject.agentName,\n metric_name: traceObject.metricName,\n instructions: traceObject.instructions,\n test_info: traceObject.testInfo ? JSON.stringify(traceObject.testInfo) : null,\n global_run_id: traceObject.globalRunId,\n run_id: traceObject.runId,\n created_at: new Date().toISOString(),\n },\n });\n }\n });\n}\n\nexport async function globalSetup() {\n if (process.env[GLOBAL_RUN_ID_ENV_KEY]) {\n throw new Error('Global run id already set, you should only run \"GlobalSetup\" once');\n }\n\n const globalRunId = crypto.randomUUID();\n process.env[GLOBAL_RUN_ID_ENV_KEY] = globalRunId;\n}\n"]}
1
+ {"version":3,"sources":["../src/constants.ts","../src/evaluation.ts","../src/attachListeners.ts"],"names":["coreEvaluate","registerHook","AvailableHooks","storage","checkEvalStorageFields","TABLE_EVALS"],"mappings":";;;;;;;;AAAO,IAAM,qBAAA,GAAwB,wBAAA;;;ACMrC,eAAsB,QAAA,CAA0B,KAAA,EAAU,KAAA,EAAqC,MAAA,EAAgB;AAC7G,EAAA,MAAM,QAAA,GAAW,MAAM,kBAAA,EAAmB;AAC1C,EAAA,IAAI,WAAA,GAAc,OAAA,CAAQ,GAAA,CAAI,qBAAqB,CAAA;AACnD,EAAA,MAAM,KAAA,GAAQ,OAAO,UAAA,EAAW;AAChC,EAAA,MAAM,WAAA,GAAc,MAAM,KAAA,CAAM,QAAA,CAAS,KAAA,EAAO;AAAA,IAC9C;AAAA,GACD,CAAA;AAED,EAAA,IAAI,CAAC,WAAA,EAAa;AAChB,IAAA,WAAA,GAAc,OAAA,CAAQ,GAAA,CAAI,qBAAqB,CAAA,GAAI,OAAO,UAAA,EAAW;AACrE,IAAA,OAAA,CAAQ,KAAK,6FAA6F,CAAA;AAAA,EAC5G;AAEA,EAAA,MAAM,YAAA,GAAe,MAAMA,cAAA,CAAa;AAAA,IACtC,WAAW,KAAA,CAAM,IAAA;AAAA,IACjB,KAAA;AAAA,IACA,MAAA;AAAA,IACA,QAAQ,WAAA,CAAY,IAAA;AAAA,IACpB,WAAA;AAAA,IACA,KAAA;AAAA,IACA,QAAA;AAA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,CAAY,MAAA;AAAA,UACpB,QAAQ,IAAA,CAAK,SAAA,CAAU,WAAA,CAAY,MAAA,IAAU,EAAE,CAAA;AAAA,UAC/C,YAAY,WAAA,CAAY,SAAA;AAAA,UACxB,aAAa,WAAA,CAAY,UAAA;AAAA,UACzB,cAAc,WAAA,CAAY,YAAA;AAAA,UAC1B,WAAW,WAAA,CAAY,QAAA,GAAW,KAAK,SAAA,CAAU,WAAA,CAAY,QAAQ,CAAA,GAAI,IAAA;AAAA,UACzE,eAAe,WAAA,CAAY,WAAA;AAAA,UAC3B,QAAQ,WAAA,CAAY,KAAA;AAAA,UACpB,UAAA,EAAA,iBAAY,IAAI,IAAA,EAAK,EAAE,WAAA;AAAY;AACrC,OACD,CAAA;AAAA,IACH;AAAA,EACF,CAAC,CAAA;AACH;AAEA,eAAsB,WAAA,GAAc;AAClC,EAAA,IAAI,OAAA,CAAQ,GAAA,CAAI,qBAAqB,CAAA,EAAG;AACtC,IAAA,MAAM,IAAI,MAAM,mEAAmE,CAAA;AAAA,EACrF;AAEA,EAAA,MAAM,WAAA,GAAc,OAAO,UAAA,EAAW;AACtC,EAAA,OAAA,CAAQ,GAAA,CAAI,qBAAqB,CAAA,GAAI,WAAA;AACvC","file":"index.cjs","sourcesContent":["export const GLOBAL_RUN_ID_ENV_KEY = '_MASTRA_GLOBAL_RUN_ID_';\n","import type { Agent } from '@mastra/core/agent';\nimport { evaluate as coreEvaluate } from '@mastra/core/eval';\nimport type { Metric } from '@mastra/core/eval';\n\nimport { GLOBAL_RUN_ID_ENV_KEY } from './constants';\n\nexport async function evaluate<T extends Agent>(agent: T, input: Parameters<T['generate']>[0], metric: Metric) {\n const testInfo = await getCurrentTestInfo();\n let globalRunId = process.env[GLOBAL_RUN_ID_ENV_KEY];\n const runId = crypto.randomUUID();\n const agentOutput = await agent.generate(input, {\n runId,\n });\n\n if (!globalRunId) {\n globalRunId = process.env[GLOBAL_RUN_ID_ENV_KEY] = crypto.randomUUID();\n console.warn('Global run id not set, you should run \"globalSetup\" from \"@mastra/evals\" before evaluating.');\n }\n\n const metricResult = await coreEvaluate({\n agentName: agent.name,\n input,\n metric,\n output: agentOutput.text,\n globalRunId,\n runId,\n testInfo,\n instructions: agent.instructions,\n });\n\n return metricResult;\n}\n\nexport const getCurrentTestInfo = async () => {\n // Jest\n // @ts-ignore\n if (typeof expect !== 'undefined' && expect.getState) {\n // @ts-ignore\n const state = expect.getState();\n return {\n testName: state.currentTestName,\n testPath: state.testPath,\n };\n }\n\n try {\n const vitest = await import('vitest');\n if (typeof vitest !== 'undefined' && vitest.expect?.getState) {\n const state = vitest.expect.getState();\n return {\n testName: state.currentTestName,\n testPath: state.testPath,\n };\n }\n } catch {}\n\n return undefined;\n};\n","import type { Mastra } from '@mastra/core';\nimport { AvailableHooks, registerHook } from '@mastra/core/hooks';\nimport { TABLE_EVALS } from '@mastra/core/storage';\nimport { checkEvalStorageFields } from '@mastra/core/utils';\n\nimport { GLOBAL_RUN_ID_ENV_KEY } from './constants';\n\nexport async function attachListeners(mastra?: Mastra) {\n registerHook(AvailableHooks.ON_EVALUATION, async traceObject => {\n const storage = mastra?.getStorage();\n if (storage) {\n // Check for required fields\n const logger = mastra?.getLogger();\n const areFieldsValid = checkEvalStorageFields(traceObject, logger);\n if (!areFieldsValid) return;\n\n await storage.insert({\n tableName: TABLE_EVALS,\n record: {\n input: traceObject.input,\n output: traceObject.output,\n result: JSON.stringify(traceObject.result || {}),\n agent_name: traceObject.agentName,\n metric_name: traceObject.metricName,\n instructions: traceObject.instructions,\n test_info: traceObject.testInfo ? JSON.stringify(traceObject.testInfo) : null,\n global_run_id: traceObject.globalRunId,\n run_id: traceObject.runId,\n created_at: new Date().toISOString(),\n },\n });\n }\n });\n}\n\nexport async function globalSetup() {\n if (process.env[GLOBAL_RUN_ID_ENV_KEY]) {\n throw new Error('Global run id already set, you should only run \"GlobalSetup\" once');\n }\n\n const globalRunId = crypto.randomUUID();\n process.env[GLOBAL_RUN_ID_ENV_KEY] = globalRunId;\n}\n"]}
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { evaluate as evaluate$1 } from '@mastra/core';
1
+ import { evaluate as evaluate$1 } from '@mastra/core/eval';
2
2
  import { registerHook, AvailableHooks } from '@mastra/core/hooks';
3
3
  import { TABLE_EVALS } from '@mastra/core/storage';
4
4
  import { checkEvalStorageFields } from '@mastra/core/utils';
@@ -39,7 +39,7 @@ var getCurrentTestInfo = async () => {
39
39
  };
40
40
  }
41
41
  try {
42
- const vitest = await import('./dist-JRG62SVA.js');
42
+ const vitest = await import('./dist-JVIEAZJ6.js');
43
43
  if (typeof vitest !== "undefined" && vitest.expect?.getState) {
44
44
  const state = vitest.expect.getState();
45
45
  return {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/constants.ts","../src/evaluation.ts","../src/attachListeners.ts"],"names":["coreEvaluate"],"mappings":";;;;;;AAAO,IAAM,qBAAA,GAAwB,wBAAA;;;ACMrC,eAAsB,QAAA,CAA0B,KAAA,EAAU,KAAA,EAAqC,MAAA,EAAgB;AAC7G,EAAA,MAAM,QAAA,GAAW,MAAM,kBAAA,EAAmB;AAC1C,EAAA,IAAI,WAAA,GAAc,OAAA,CAAQ,GAAA,CAAI,qBAAqB,CAAA;AACnD,EAAA,MAAM,KAAA,GAAQ,OAAO,UAAA,EAAW;AAChC,EAAA,MAAM,WAAA,GAAc,MAAM,KAAA,CAAM,QAAA,CAAS,KAAA,EAAO;AAAA,IAC9C;AAAA,GACD,CAAA;AAED,EAAA,IAAI,CAAC,WAAA,EAAa;AAChB,IAAA,WAAA,GAAc,OAAA,CAAQ,GAAA,CAAI,qBAAqB,CAAA,GAAI,OAAO,UAAA,EAAW;AACrE,IAAA,OAAA,CAAQ,KAAK,6FAA6F,CAAA;AAAA,EAC5G;AAEA,EAAA,MAAM,YAAA,GAAe,MAAMA,UAAA,CAAa;AAAA,IACtC,WAAW,KAAA,CAAM,IAAA;AAAA,IACjB,KAAA;AAAA,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,WAAA;AAAA,QACX,MAAA,EAAQ;AAAA,UACN,OAAO,WAAA,CAAY,KAAA;AAAA,UACnB,QAAQ,WAAA,CAAY,MAAA;AAAA,UACpB,QAAQ,IAAA,CAAK,SAAA,CAAU,WAAA,CAAY,MAAA,IAAU,EAAE,CAAA;AAAA,UAC/C,YAAY,WAAA,CAAY,SAAA;AAAA,UACxB,aAAa,WAAA,CAAY,UAAA;AAAA,UACzB,cAAc,WAAA,CAAY,YAAA;AAAA,UAC1B,WAAW,WAAA,CAAY,QAAA,GAAW,KAAK,SAAA,CAAU,WAAA,CAAY,QAAQ,CAAA,GAAI,IAAA;AAAA,UACzE,eAAe,WAAA,CAAY,WAAA;AAAA,UAC3B,QAAQ,WAAA,CAAY,KAAA;AAAA,UACpB,UAAA,EAAA,iBAAY,IAAI,IAAA,EAAK,EAAE,WAAA;AAAY;AACrC,OACD,CAAA;AAAA,IACH;AAAA,EACF,CAAC,CAAA;AACH;AAEA,eAAsB,WAAA,GAAc;AAClC,EAAA,IAAI,OAAA,CAAQ,GAAA,CAAI,qBAAqB,CAAA,EAAG;AACtC,IAAA,MAAM,IAAI,MAAM,mEAAmE,CAAA;AAAA,EACrF;AAEA,EAAA,MAAM,WAAA,GAAc,OAAO,UAAA,EAAW;AACtC,EAAA,OAAA,CAAQ,GAAA,CAAI,qBAAqB,CAAA,GAAI,WAAA;AACvC","file":"index.js","sourcesContent":["export const GLOBAL_RUN_ID_ENV_KEY = '_MASTRA_GLOBAL_RUN_ID_';\n","import { evaluate as coreEvaluate } from '@mastra/core';\nimport type { Metric } from '@mastra/core';\nimport type { Agent } from '@mastra/core/agent';\n\nimport { GLOBAL_RUN_ID_ENV_KEY } from './constants';\n\nexport async function evaluate<T extends Agent>(agent: T, input: Parameters<T['generate']>[0], metric: Metric) {\n const testInfo = await getCurrentTestInfo();\n let globalRunId = process.env[GLOBAL_RUN_ID_ENV_KEY];\n const runId = crypto.randomUUID();\n const agentOutput = await agent.generate(input, {\n runId,\n });\n\n if (!globalRunId) {\n globalRunId = process.env[GLOBAL_RUN_ID_ENV_KEY] = crypto.randomUUID();\n console.warn('Global run id not set, you should run \"globalSetup\" from \"@mastra/evals\" before evaluating.');\n }\n\n const metricResult = await coreEvaluate({\n agentName: agent.name,\n input,\n metric,\n output: agentOutput.text,\n globalRunId,\n runId,\n testInfo,\n instructions: agent.instructions,\n });\n\n return metricResult;\n}\n\nexport const getCurrentTestInfo = async () => {\n // Jest\n // @ts-ignore\n if (typeof expect !== 'undefined' && expect.getState) {\n // @ts-ignore\n const state = expect.getState();\n return {\n testName: state.currentTestName,\n testPath: state.testPath,\n };\n }\n\n try {\n const vitest = await import('vitest');\n if (typeof vitest !== 'undefined' && vitest.expect?.getState) {\n const state = vitest.expect.getState();\n return {\n testName: state.currentTestName,\n testPath: state.testPath,\n };\n }\n } catch {}\n\n return undefined;\n};\n","import type { Mastra } from '@mastra/core';\nimport { AvailableHooks, registerHook } from '@mastra/core/hooks';\nimport { TABLE_EVALS } from '@mastra/core/storage';\nimport { checkEvalStorageFields } from '@mastra/core/utils';\n\nimport { GLOBAL_RUN_ID_ENV_KEY } from './constants';\n\nexport async function attachListeners(mastra?: Mastra) {\n registerHook(AvailableHooks.ON_EVALUATION, async traceObject => {\n const storage = mastra?.getStorage();\n if (storage) {\n // Check for required fields\n const logger = mastra?.getLogger();\n const areFieldsValid = checkEvalStorageFields(traceObject, logger);\n if (!areFieldsValid) return;\n\n await storage.insert({\n tableName: TABLE_EVALS,\n record: {\n input: traceObject.input,\n output: traceObject.output,\n result: JSON.stringify(traceObject.result || {}),\n agent_name: traceObject.agentName,\n metric_name: traceObject.metricName,\n instructions: traceObject.instructions,\n test_info: traceObject.testInfo ? JSON.stringify(traceObject.testInfo) : null,\n global_run_id: traceObject.globalRunId,\n run_id: traceObject.runId,\n created_at: new Date().toISOString(),\n },\n });\n }\n });\n}\n\nexport async function globalSetup() {\n if (process.env[GLOBAL_RUN_ID_ENV_KEY]) {\n throw new Error('Global run id already set, you should only run \"GlobalSetup\" once');\n }\n\n const globalRunId = crypto.randomUUID();\n process.env[GLOBAL_RUN_ID_ENV_KEY] = globalRunId;\n}\n"]}
1
+ {"version":3,"sources":["../src/constants.ts","../src/evaluation.ts","../src/attachListeners.ts"],"names":["coreEvaluate"],"mappings":";;;;;;AAAO,IAAM,qBAAA,GAAwB,wBAAA;;;ACMrC,eAAsB,QAAA,CAA0B,KAAA,EAAU,KAAA,EAAqC,MAAA,EAAgB;AAC7G,EAAA,MAAM,QAAA,GAAW,MAAM,kBAAA,EAAmB;AAC1C,EAAA,IAAI,WAAA,GAAc,OAAA,CAAQ,GAAA,CAAI,qBAAqB,CAAA;AACnD,EAAA,MAAM,KAAA,GAAQ,OAAO,UAAA,EAAW;AAChC,EAAA,MAAM,WAAA,GAAc,MAAM,KAAA,CAAM,QAAA,CAAS,KAAA,EAAO;AAAA,IAC9C;AAAA,GACD,CAAA;AAED,EAAA,IAAI,CAAC,WAAA,EAAa;AAChB,IAAA,WAAA,GAAc,OAAA,CAAQ,GAAA,CAAI,qBAAqB,CAAA,GAAI,OAAO,UAAA,EAAW;AACrE,IAAA,OAAA,CAAQ,KAAK,6FAA6F,CAAA;AAAA,EAC5G;AAEA,EAAA,MAAM,YAAA,GAAe,MAAMA,UAAA,CAAa;AAAA,IACtC,WAAW,KAAA,CAAM,IAAA;AAAA,IACjB,KAAA;AAAA,IACA,MAAA;AAAA,IACA,QAAQ,WAAA,CAAY,IAAA;AAAA,IACpB,WAAA;AAAA,IACA,KAAA;AAAA,IACA,QAAA;AAAA,IACA,cAAc,KAAA,CAAM;AAAA,GACrB,CAAA;AAED,EAAA,OAAO,YAAA;AACT;AAEO,IAAM,qBAAqB,YAAY;AAG5C,EAAA,IAAI,OAAO,MAAA,KAAW,WAAA,IAAe,MAAA,CAAO,QAAA,EAAU;AAEpD,IAAA,MAAM,KAAA,GAAQ,OAAO,QAAA,EAAS;AAC9B,IAAA,OAAO;AAAA,MACL,UAAU,KAAA,CAAM,eAAA;AA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AAI,IAAA;AAAA,UACzE,eAAe,WAAA,CAAY,WAAA;AAAA,UAC3B,QAAQ,WAAA,CAAY,KAAA;AAAA,UACpB,UAAA,EAAA,iBAAY,IAAI,IAAA,EAAK,EAAE,WAAA;AAAY;AACrC,OACD,CAAA;AAAA,IACH;AAAA,EACF,CAAC,CAAA;AACH;AAEA,eAAsB,WAAA,GAAc;AAClC,EAAA,IAAI,OAAA,CAAQ,GAAA,CAAI,qBAAqB,CAAA,EAAG;AACtC,IAAA,MAAM,IAAI,MAAM,mEAAmE,CAAA;AAAA,EACrF;AAEA,EAAA,MAAM,WAAA,GAAc,OAAO,UAAA,EAAW;AACtC,EAAA,OAAA,CAAQ,GAAA,CAAI,qBAAqB,CAAA,GAAI,WAAA;AACvC","file":"index.js","sourcesContent":["export const GLOBAL_RUN_ID_ENV_KEY = '_MASTRA_GLOBAL_RUN_ID_';\n","import type { Agent } from '@mastra/core/agent';\nimport { evaluate as coreEvaluate } from '@mastra/core/eval';\nimport type { Metric } from '@mastra/core/eval';\n\nimport { GLOBAL_RUN_ID_ENV_KEY } from './constants';\n\nexport async function evaluate<T extends Agent>(agent: T, input: Parameters<T['generate']>[0], metric: Metric) {\n const testInfo = await getCurrentTestInfo();\n let globalRunId = process.env[GLOBAL_RUN_ID_ENV_KEY];\n const runId = crypto.randomUUID();\n const agentOutput = await agent.generate(input, {\n runId,\n });\n\n if (!globalRunId) {\n globalRunId = process.env[GLOBAL_RUN_ID_ENV_KEY] = crypto.randomUUID();\n console.warn('Global run id not set, you should run \"globalSetup\" from \"@mastra/evals\" before evaluating.');\n }\n\n const metricResult = await coreEvaluate({\n agentName: agent.name,\n input,\n metric,\n output: agentOutput.text,\n globalRunId,\n runId,\n testInfo,\n instructions: agent.instructions,\n });\n\n return metricResult;\n}\n\nexport const getCurrentTestInfo = async () => {\n // Jest\n // @ts-ignore\n if (typeof expect !== 'undefined' && expect.getState) {\n // @ts-ignore\n const state = expect.getState();\n return {\n testName: state.currentTestName,\n testPath: state.testPath,\n };\n }\n\n try {\n const vitest = await import('vitest');\n if (typeof vitest !== 'undefined' && vitest.expect?.getState) {\n const state = vitest.expect.getState();\n return {\n testName: state.currentTestName,\n testPath: state.testPath,\n };\n }\n } catch {}\n\n return undefined;\n};\n","import type { Mastra } from '@mastra/core';\nimport { AvailableHooks, registerHook } from '@mastra/core/hooks';\nimport { TABLE_EVALS } from '@mastra/core/storage';\nimport { checkEvalStorageFields } from '@mastra/core/utils';\n\nimport { GLOBAL_RUN_ID_ENV_KEY } from './constants';\n\nexport async function attachListeners(mastra?: Mastra) {\n registerHook(AvailableHooks.ON_EVALUATION, async traceObject => {\n const storage = mastra?.getStorage();\n if (storage) {\n // Check for required fields\n const logger = mastra?.getLogger();\n const areFieldsValid = checkEvalStorageFields(traceObject, logger);\n if (!areFieldsValid) return;\n\n await storage.insert({\n tableName: TABLE_EVALS,\n record: {\n input: traceObject.input,\n output: traceObject.output,\n result: JSON.stringify(traceObject.result || {}),\n agent_name: traceObject.agentName,\n metric_name: traceObject.metricName,\n instructions: traceObject.instructions,\n test_info: traceObject.testInfo ? JSON.stringify(traceObject.testInfo) : null,\n global_run_id: traceObject.globalRunId,\n run_id: traceObject.runId,\n created_at: new Date().toISOString(),\n },\n });\n }\n });\n}\n\nexport async function globalSetup() {\n if (process.env[GLOBAL_RUN_ID_ENV_KEY]) {\n throw new Error('Global run id already set, you should only run \"GlobalSetup\" once');\n }\n\n const globalRunId = crypto.randomUUID();\n process.env[GLOBAL_RUN_ID_ENV_KEY] = globalRunId;\n}\n"]}
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+ var chunkQVZBKGOE_cjs = require('../../chunk-QVZBKGOE.cjs');
3
4
  var scores = require('@mastra/core/scores');
4
5
  var nlp = require('compromise');
5
6
  var difflib = require('difflib');
@@ -228,11 +229,95 @@ function createToneScorer(config = {}) {
228
229
  return results.preprocessStepResult?.score;
229
230
  });
230
231
  }
232
+ function checkToolOrder(actualTools, expectedOrder, strictMode = false) {
233
+ if (strictMode) {
234
+ return JSON.stringify(actualTools) === JSON.stringify(expectedOrder);
235
+ }
236
+ const expectedIndices = [];
237
+ for (const expectedTool of expectedOrder) {
238
+ const index = actualTools.indexOf(expectedTool);
239
+ if (index === -1) {
240
+ return false;
241
+ }
242
+ expectedIndices.push(index);
243
+ }
244
+ for (let i = 1; i < expectedIndices.length; i++) {
245
+ const currentIndex = expectedIndices[i];
246
+ const prevIndex = expectedIndices[i - 1];
247
+ if (currentIndex !== void 0 && prevIndex !== void 0 && currentIndex <= prevIndex) {
248
+ return false;
249
+ }
250
+ }
251
+ return true;
252
+ }
253
+ function calculateAccuracy({
254
+ expectedTool,
255
+ actualTools,
256
+ strictMode = false,
257
+ expectedToolOrder
258
+ }) {
259
+ if (actualTools.length === 0) {
260
+ return 0;
261
+ }
262
+ if (expectedToolOrder && expectedToolOrder.length > 0) {
263
+ return checkToolOrder(actualTools, expectedToolOrder, strictMode) ? 1 : 0;
264
+ }
265
+ if (!expectedTool) {
266
+ return 0;
267
+ }
268
+ if (strictMode) {
269
+ return actualTools.length === 1 && actualTools[0] === expectedTool ? 1 : 0;
270
+ }
271
+ return actualTools.includes(expectedTool) ? 1 : 0;
272
+ }
273
+ function createToolCallAccuracyScorerCode(options) {
274
+ const { expectedTool, strictMode = false, expectedToolOrder } = options;
275
+ if (!expectedTool && !expectedToolOrder) {
276
+ throw new Error("Either expectedTool or expectedToolOrder must be provided");
277
+ }
278
+ const getDescription = () => {
279
+ return expectedToolOrder ? `Evaluates whether the LLM called tools in the correct order: [${expectedToolOrder.join(", ")}]` : `Evaluates whether the LLM selected the correct tool (${expectedTool}) from the available tools`;
280
+ };
281
+ return scores.createScorer({
282
+ name: "Tool Call Accuracy",
283
+ description: getDescription()
284
+ }).preprocess(async ({ run }) => {
285
+ const isInputInvalid = !run.input || !run.input.inputMessages || run.input.inputMessages.length === 0;
286
+ const isOutputInvalid = !run.output || run.output.length === 0;
287
+ if (isInputInvalid || isOutputInvalid) {
288
+ throw new Error("Input and output messages cannot be null or empty");
289
+ }
290
+ const { tools: actualTools, toolCallInfos } = chunkQVZBKGOE_cjs.extractToolCalls(run.output);
291
+ const correctToolCalled = expectedTool ? strictMode ? actualTools.length === 1 && actualTools[0] === expectedTool : actualTools.includes(expectedTool) : false;
292
+ return {
293
+ expectedTool,
294
+ actualTools,
295
+ strictMode,
296
+ expectedToolOrder,
297
+ hasToolCalls: actualTools.length > 0,
298
+ correctToolCalled,
299
+ toolCallInfos,
300
+ correctOrderCalled: expectedToolOrder ? checkToolOrder(actualTools, expectedToolOrder, strictMode) : null
301
+ };
302
+ }).generateScore(({ results }) => {
303
+ const preprocessResult = results.preprocessStepResult;
304
+ if (!preprocessResult) {
305
+ return 0;
306
+ }
307
+ return calculateAccuracy({
308
+ expectedTool: preprocessResult.expectedTool,
309
+ actualTools: preprocessResult.actualTools,
310
+ strictMode: preprocessResult.strictMode,
311
+ expectedToolOrder: preprocessResult.expectedToolOrder
312
+ });
313
+ });
314
+ }
231
315
 
232
316
  exports.createCompletenessScorer = createCompletenessScorer;
233
317
  exports.createContentSimilarityScorer = createContentSimilarityScorer;
234
318
  exports.createKeywordCoverageScorer = createKeywordCoverageScorer;
235
319
  exports.createTextualDifferenceScorer = createTextualDifferenceScorer;
236
320
  exports.createToneScorer = createToneScorer;
321
+ exports.createToolCallAccuracyScorerCode = createToolCallAccuracyScorerCode;
237
322
  //# sourceMappingURL=index.cjs.map
238
323
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/scorers/code/completeness/index.ts","../../../src/scorers/code/textual-difference/index.ts","../../../src/scorers/code/keyword-coverage/index.ts","../../../src/scorers/code/content-similarity/index.ts","../../../src/scorers/code/tone/index.ts"],"names":["createScorer","nlp","SequenceMatcher","keyword_extractor","stringSimilarity","Sentiment"],"mappings":";;;;;;;;;;;;;;;;AAIA,SAAS,gBAAgB,GAAA,EAAqB;AAE5C,EAAA,OAAO,GAAA,CACJ,UAAU,KAA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EAAE,WAAW,CAAA;AACtE,IAAA,MAAM,YAAA,GAAe,UAAA,CAAW,MAAA,CAAO,CAAC,CAAA,EAAG,MAAM,CAAA,GAAI,CAAA,EAAG,CAAC,CAAA,GAAI,UAAA,CAAW,MAAA;AACxE,IAAA,MAAM,QAAA,GAAW,UAAA,CAAW,MAAA,CAAO,CAAC,KAAK,CAAA,KAAM,GAAA,GAAM,IAAA,CAAK,GAAA,CAAI,IAAI,YAAA,EAAc,CAAC,CAAA,EAAG,CAAC,IAAI,UAAA,CAAW,MAAA;AACpG,IAAA,MAAM,SAAA,GAAY,IAAA,CAAK,GAAA,CAAI,CAAA,EAAG,IAAI,QAAQ,CAAA;AAE1C,IAAA,OAAO;AAAA,MACL,KAAA,EAAO,SAAA;AAAA,MACP,YAAA;AAAA,MACA,iBAAA,EAAmB;AAAA,KACrB;AAAA,EACF,CAAC,CAAA,CACA,aAAA,CAAc,CAAC,EAAE,SAAQ,KAAM;AAC9B,IAAA,OAAO,QAAQ,oBAAA,EAAsB,KAAA;AAAA,EACvC,CAAC,CAAA;AACL","file":"index.cjs","sourcesContent":["import { createScorer } from '@mastra/core/scores';\nimport type { ScorerRunInputForAgent, ScorerRunOutputForAgent } from '@mastra/core/scores';\nimport nlp from 'compromise';\n\nfunction normalizeString(str: string): string {\n // Remove diacritics and convert to lowercase\n return str\n .normalize('NFD')\n .replace(/[\\u0300-\\u036f]/g, '')\n .toLowerCase();\n}\n\nfunction extractElements(doc: any): string[] {\n // Get more specific elements and ensure they're arrays\n const nouns = doc.nouns().out('array') || [];\n const verbs = doc.verbs().toInfinitive().out('array') || [];\n const topics = doc.topics().out('array') || [];\n const terms = doc.terms().out('array') || [];\n\n // Helper function to clean and split terms\n const cleanAndSplitTerm = (term: string): string[] => {\n // First normalize the string\n const normalized = normalizeString(term);\n\n // Split on word boundaries and filter out empty strings\n return normalized\n .replace(/([a-z])([A-Z])/g, '$1 $2') // Split camelCase\n .replace(/[^a-z0-9]+/g, ' ') // Replace non-alphanumeric with spaces\n .trim()\n .split(/\\s+/)\n .filter(word => word.length > 0);\n };\n\n // Process all elements\n const processedTerms = [\n ...nouns.flatMap(cleanAndSplitTerm),\n ...verbs.flatMap(cleanAndSplitTerm),\n ...topics.flatMap(cleanAndSplitTerm),\n ...terms.flatMap(cleanAndSplitTerm),\n ];\n\n // Remove duplicates\n return [...new Set(processedTerms)];\n}\n\nfunction calculateCoverage({ original, simplified }: { original: string[]; simplified: string[] }): number {\n if (original.length === 0) {\n return simplified.length === 0 ? 1 : 0;\n }\n\n // Exact matching for short words (3 chars or less), substring matching for longer words\n const covered = original.filter(element =>\n simplified.some(s => {\n const elem = normalizeString(element);\n const simp = normalizeString(s);\n\n // For short words (3 chars or less), require exact match\n if (elem.length <= 3) {\n return elem === simp;\n }\n\n // For longer words, require substantial overlap (more than 60% of the longer word)\n const longer = elem.length > simp.length ? elem : simp;\n const shorter = elem.length > simp.length ? simp : elem;\n\n if (longer.includes(shorter)) {\n return shorter.length / longer.length > 0.6;\n }\n\n return false;\n }),\n );\n return covered.length / original.length;\n}\n\nexport function createCompletenessScorer() {\n return createScorer<ScorerRunInputForAgent, ScorerRunOutputForAgent>({\n name: 'Completeness',\n description:\n 'Leverage the nlp method from \"compromise\" to extract elements from the input and output and calculate the coverage.',\n })\n .preprocess(async ({ run }) => {\n const isInputInvalid =\n !run.input ||\n run.input.inputMessages.some((i: { content: string }) => i.content === null || i.content === undefined);\n\n const isOutputInvalid =\n !run.output || run.output.some((i: { content: string }) => i.content === null || i.content === undefined);\n\n if (isInputInvalid || isOutputInvalid) {\n throw new Error('Inputs cannot be null or undefined');\n }\n\n const input = run.input?.inputMessages.map((i: { content: string }) => i.content).join(', ') || '';\n const output = run.output?.map(({ content }: { content: string }) => content).join(', ') || '';\n\n const inputToProcess = input;\n const outputToProcess = output;\n\n const inputDoc = nlp(inputToProcess.trim());\n const outputDoc = nlp(outputToProcess.trim());\n\n // Extract and log elements\n const inputElements = extractElements(inputDoc);\n const outputElements = extractElements(outputDoc);\n\n return {\n inputElements,\n outputElements,\n missingElements: inputElements.filter(e => !outputElements.includes(e)),\n elementCounts: {\n input: inputElements.length,\n output: outputElements.length,\n },\n };\n })\n .generateScore(({ results }) => {\n const inputElements = results.preprocessStepResult?.inputElements;\n const outputElements = results.preprocessStepResult?.outputElements;\n\n return calculateCoverage({\n original: inputElements,\n simplified: outputElements,\n });\n });\n}\n","import { createScorer } from '@mastra/core/scores';\nimport type { ScorerRunInputForAgent, ScorerRunOutputForAgent } from '@mastra/core/scores';\nimport { SequenceMatcher } from 'difflib';\n\nexport function createTextualDifferenceScorer() {\n return createScorer<ScorerRunInputForAgent, ScorerRunOutputForAgent>({\n name: 'Completeness',\n description:\n 'Leverage the nlp method from \"compromise\" to extract elements from the input and output and calculate the coverage.',\n })\n .preprocess(async ({ run }) => {\n const input = run.input?.inputMessages?.map((i: { content: string }) => i.content).join(', ') || '';\n const output = run.output?.map((i: { content: string }) => i.content).join(', ') || '';\n const matcher = new SequenceMatcher(null, input, output);\n const ratio = matcher.ratio();\n\n // Get detailed operations\n const ops = matcher.getOpcodes();\n const changes = ops.filter(([op]) => op !== 'equal').length;\n\n // Calculate confidence based on text length difference\n const maxLength = Math.max(input.length, output.length);\n const lengthDiff = maxLength > 0 ? Math.abs(input.length - output.length) / maxLength : 0;\n const confidence = 1 - lengthDiff;\n\n return {\n ratio,\n confidence,\n changes,\n lengthDiff,\n };\n })\n .generateScore(({ results }) => {\n return results.preprocessStepResult?.ratio;\n });\n}\n","import { createScorer } from '@mastra/core/scores';\nimport type { ScorerRunInputForAgent, ScorerRunOutputForAgent } from '@mastra/core/scores';\nimport keyword_extractor from 'keyword-extractor';\n\nexport function createKeywordCoverageScorer() {\n return createScorer<ScorerRunInputForAgent, ScorerRunOutputForAgent>({\n name: 'Completeness',\n description:\n 'Leverage the nlp method from \"compromise\" to extract elements from the input and output and calculate the coverage.',\n })\n .preprocess(async ({ run }) => {\n const input = run.input?.inputMessages?.map((i: { content: string }) => i.content).join(', ') || '';\n const output = run.output?.map((i: { content: string }) => i.content).join(', ') || '';\n\n if (!input && !output) {\n return {\n result: {\n referenceKeywords: new Set<string>(),\n responseKeywords: new Set<string>(),\n },\n };\n }\n\n const extractKeywords = (text: string) => {\n return keyword_extractor.extract(text, {\n language: 'english',\n remove_digits: true,\n return_changed_case: true,\n remove_duplicates: true,\n });\n };\n\n const referenceKeywords = new Set(extractKeywords(input));\n const responseKeywords = new Set(extractKeywords(output));\n return {\n referenceKeywords,\n responseKeywords,\n };\n })\n .analyze(async ({ results }) => {\n if (\n !results.preprocessStepResult?.referenceKeywords?.size &&\n !results.preprocessStepResult?.responseKeywords?.size\n ) {\n return {\n totalKeywordsLength: 0,\n matchedKeywordsLength: 0,\n };\n }\n\n const matchedKeywords = [...results.preprocessStepResult?.referenceKeywords].filter(k =>\n results.preprocessStepResult?.responseKeywords?.has(k),\n );\n\n return {\n totalKeywordsLength: Array.from(results.preprocessStepResult?.referenceKeywords).length ?? 0,\n matchedKeywordsLength: matchedKeywords.length ?? 0,\n };\n })\n .generateScore(({ results }) => {\n if (!results.analyzeStepResult?.totalKeywordsLength) {\n return 1;\n }\n\n const totalKeywords = results.analyzeStepResult?.totalKeywordsLength!;\n const matchedKeywords = results.analyzeStepResult?.matchedKeywordsLength!;\n return totalKeywords > 0 ? matchedKeywords / totalKeywords : 0;\n });\n}\n","import { createScorer } from '@mastra/core/scores';\nimport type { ScorerRunInputForAgent, ScorerRunOutputForAgent } from '@mastra/core/scores';\nimport stringSimilarity from 'string-similarity';\n\ninterface ContentSimilarityOptions {\n ignoreCase?: boolean;\n ignoreWhitespace?: boolean;\n}\n\nexport function createContentSimilarityScorer(\n { ignoreCase, ignoreWhitespace }: ContentSimilarityOptions = { ignoreCase: true, ignoreWhitespace: true },\n) {\n return createScorer<ScorerRunInputForAgent, ScorerRunOutputForAgent>({\n name: 'Completeness',\n description:\n 'Leverage the nlp method from \"compromise\" to extract elements from the input and output and calculate the coverage.',\n })\n .preprocess(async ({ run }) => {\n let processedInput = run.input?.inputMessages.map((i: { content: string }) => i.content).join(', ') || '';\n let processedOutput = run.output.map((i: { content: string }) => i.content).join(', ') || '';\n\n if (ignoreCase) {\n processedInput = processedInput.toLowerCase();\n processedOutput = processedOutput.toLowerCase();\n }\n\n if (ignoreWhitespace) {\n processedInput = processedInput.replace(/\\s+/g, ' ').trim();\n processedOutput = processedOutput.replace(/\\s+/g, ' ').trim();\n }\n\n return {\n processedInput,\n processedOutput,\n };\n })\n .generateScore(({ results }) => {\n const similarity = stringSimilarity.compareTwoStrings(\n results.preprocessStepResult?.processedInput,\n results.preprocessStepResult?.processedOutput,\n );\n\n return similarity;\n });\n}\n","import { createScorer } from '@mastra/core/scores';\nimport type { ScorerRunInputForAgent, ScorerRunOutputForAgent } from '@mastra/core/scores';\nimport Sentiment from 'sentiment';\n\ninterface ToneScorerConfig {\n referenceTone?: string;\n}\n\nexport function createToneScorer(config: ToneScorerConfig = {}) {\n const { referenceTone } = config;\n\n return createScorer<ScorerRunInputForAgent, ScorerRunOutputForAgent>({\n name: 'Completeness',\n description:\n 'Leverage the nlp method from \"compromise\" to extract elements from the input and output and calculate the coverage.',\n })\n .preprocess(async ({ run }) => {\n const sentiment = new Sentiment();\n const agentMessage: string = run.output?.map((i: { content: string }) => i.content).join(', ') || '';\n const responseSentiment = sentiment.analyze(agentMessage);\n\n if (referenceTone) {\n // Compare sentiment with reference\n const referenceSentiment = sentiment.analyze(referenceTone);\n const sentimentDiff = Math.abs(responseSentiment.comparative - referenceSentiment.comparative);\n const normalizedScore = Math.max(0, 1 - sentimentDiff);\n\n return {\n score: normalizedScore,\n responseSentiment: responseSentiment.comparative,\n referenceSentiment: referenceSentiment.comparative,\n difference: sentimentDiff,\n };\n }\n\n // Evaluate sentiment stability across response\n const sentences = agentMessage.match(/[^.!?]+[.!?]+/g) || [agentMessage];\n const sentiments = sentences.map(s => sentiment.analyze(s).comparative);\n const avgSentiment = sentiments.reduce((a, b) => a + b, 0) / sentiments.length;\n const variance = sentiments.reduce((sum, s) => sum + Math.pow(s - avgSentiment, 2), 0) / sentiments.length;\n const stability = Math.max(0, 1 - variance);\n\n return {\n score: stability,\n avgSentiment,\n sentimentVariance: variance,\n };\n })\n .generateScore(({ results }) => {\n return results.preprocessStepResult?.score;\n });\n}\n"]}
1
+ {"version":3,"sources":["../../../src/scorers/code/completeness/index.ts","../../../src/scorers/code/textual-difference/index.ts","../../../src/scorers/code/keyword-coverage/index.ts","../../../src/scorers/code/content-similarity/index.ts","../../../src/scorers/code/tone/index.ts","../../../src/scorers/code/tool-call-accuracy/index.ts"],"names":["createScorer","nlp","SequenceMatcher","keyword_extractor","stringSimilarity","Sentiment","extractToolCalls"],"mappings":";;;;;;;;;;;;;;;;;AAIA,SAAS,gBAAgB,GAAA,EAAqB;AAE5C,EAAA,OAAO,GAAA,CACJ,UAAU,KAAK,CAAA,CACf,QAAQ,kBAAA,EAAoB,EAAE,EAC9B,WAAA,EAAY;AACjB;AAEA,SAAS,gBAAgB,GAAA,EAAoB;AAE3C,EAAA,MAAM,QAAQ,GAAA,CAAI,KAAA,GAAQ,GAAA,CAAI,OAAO,KAAK,EAAC;AAC3C,EAAA,MAAM,KAAA,GAAQ,IAAI,KAAA,EAAM,CAAE,cAAa,CAAE,GAAA,CAAI,OAAO,CAAA,IAAK,EAAC;AAC1D,EAAA,MAAM,SAAS,GAAA,CAAI,MAAA,GAAS,GAAA,CAAI,OAAO,KAAK,EAAC;AAC7C,EAAA,MAAM,QAAQ,GAAA,CAAI,KAAA,GAAQ,GAAA,CAAI,OAAO,KAAK,EAAC;AAG3C,EAAA,MAAM,iBAAA,GAAoB,CAAC,IAAA,KAA2B;AAEpD,IAAA,MAAM,UAAA,GAAa,gBAAgB,IAAI,CAAA;AAGvC,IAAA,OAAO,WACJ,OAAA,CAAQ,iBAAA,EAAmB,OAAO,CAAA,CAClC,OAAA,CAAQ,eAAe,GAAG,CAAA,CAC1B,IAAA,EAAK,CACL,MAAM,KAAK,CAAA,CAC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AAIM,kCAAA,CAAiB,IAAI,MAAM,CAAA;AAEzE,IAAA,MAAM,iBAAA,GAAoB,YAAA,GACtB,UAAA,GACE,WAAA,CAAY,MAAA,KAAW,CAAA,IAAK,WAAA,CAAY,CAAC,CAAA,KAAM,YAAA,GAC/C,WAAA,CAAY,QAAA,CAAS,YAAY,CAAA,GACnC,KAAA;AAEJ,IAAA,OAAO;AAAA,MACL,YAAA;AAAA,MACA,WAAA;AAAA,MACA,UAAA;AAAA,MACA,iBAAA;AAAA,MACA,YAAA,EAAc,YAAY,MAAA,GAAS,CAAA;AAAA,MACnC,iBAAA;AAAA,MACA,aAAA;AAAA,MACA,oBAAoB,iBAAA,GAAoB,cAAA,CAAe,WAAA,EAAa,iBAAA,EAAmB,UAAU,CAAA,GAAI;AAAA,KACvG;AAAA,EACF,CAAC,CAAA,CACA,aAAA,CAAc,CAAC,EAAE,SAAQ,KAAM;AAC9B,IAAA,MAAM,mBAAmB,OAAA,CAAQ,oBAAA;AACjC,IAAA,IAAI,CAAC,gBAAA,EAAkB;AACrB,MAAA,OAAO,CAAA;AAAA,IACT;AAEA,IAAA,OAAO,iBAAA,CAAkB;AAAA,MACvB,cAAc,gBAAA,CAAiB,YAAA;AAAA,MAC/B,aAAa,gBAAA,CAAiB,WAAA;AAAA,MAC9B,YAAY,gBAAA,CAAiB,UAAA;AAAA,MAC7B,mBAAmB,gBAAA,CAAiB;AAAA,KACrC,CAAA;AAAA,EACH,CAAC,CAAA;AACL","file":"index.cjs","sourcesContent":["import { createScorer } from '@mastra/core/scores';\nimport type { ScorerRunInputForAgent, ScorerRunOutputForAgent } from '@mastra/core/scores';\nimport nlp from 'compromise';\n\nfunction normalizeString(str: string): string {\n // Remove diacritics and convert to lowercase\n return str\n .normalize('NFD')\n .replace(/[\\u0300-\\u036f]/g, '')\n .toLowerCase();\n}\n\nfunction extractElements(doc: any): string[] {\n // Get more specific elements and ensure they're arrays\n const nouns = doc.nouns().out('array') || [];\n const verbs = doc.verbs().toInfinitive().out('array') || [];\n const topics = doc.topics().out('array') || [];\n const terms = doc.terms().out('array') || [];\n\n // Helper function to clean and split terms\n const cleanAndSplitTerm = (term: string): string[] => {\n // First normalize the string\n const normalized = normalizeString(term);\n\n // Split on word boundaries and filter out empty strings\n return normalized\n .replace(/([a-z])([A-Z])/g, '$1 $2') // Split camelCase\n .replace(/[^a-z0-9]+/g, ' ') // Replace non-alphanumeric with spaces\n .trim()\n .split(/\\s+/)\n .filter(word => word.length > 0);\n };\n\n // Process all elements\n const processedTerms = [\n ...nouns.flatMap(cleanAndSplitTerm),\n ...verbs.flatMap(cleanAndSplitTerm),\n ...topics.flatMap(cleanAndSplitTerm),\n ...terms.flatMap(cleanAndSplitTerm),\n ];\n\n // Remove duplicates\n return [...new Set(processedTerms)];\n}\n\nfunction calculateCoverage({ original, simplified }: { original: string[]; simplified: string[] }): number {\n if (original.length === 0) {\n return simplified.length === 0 ? 1 : 0;\n }\n\n // Exact matching for short words (3 chars or less), substring matching for longer words\n const covered = original.filter(element =>\n simplified.some(s => {\n const elem = normalizeString(element);\n const simp = normalizeString(s);\n\n // For short words (3 chars or less), require exact match\n if (elem.length <= 3) {\n return elem === simp;\n }\n\n // For longer words, require substantial overlap (more than 60% of the longer word)\n const longer = elem.length > simp.length ? elem : simp;\n const shorter = elem.length > simp.length ? simp : elem;\n\n if (longer.includes(shorter)) {\n return shorter.length / longer.length > 0.6;\n }\n\n return false;\n }),\n );\n return covered.length / original.length;\n}\n\nexport function createCompletenessScorer() {\n return createScorer<ScorerRunInputForAgent, ScorerRunOutputForAgent>({\n name: 'Completeness',\n description:\n 'Leverage the nlp method from \"compromise\" to extract elements from the input and output and calculate the coverage.',\n })\n .preprocess(async ({ run }) => {\n const isInputInvalid =\n !run.input ||\n run.input.inputMessages.some((i: { content: string }) => i.content === null || i.content === undefined);\n\n const isOutputInvalid =\n !run.output || run.output.some((i: { content: string }) => i.content === null || i.content === undefined);\n\n if (isInputInvalid || isOutputInvalid) {\n throw new Error('Inputs cannot be null or undefined');\n }\n\n const input = run.input?.inputMessages.map((i: { content: string }) => i.content).join(', ') || '';\n const output = run.output?.map(({ content }: { content: string }) => content).join(', ') || '';\n\n const inputToProcess = input;\n const outputToProcess = output;\n\n const inputDoc = nlp(inputToProcess.trim());\n const outputDoc = nlp(outputToProcess.trim());\n\n // Extract and log elements\n const inputElements = extractElements(inputDoc);\n const outputElements = extractElements(outputDoc);\n\n return {\n inputElements,\n outputElements,\n missingElements: inputElements.filter(e => !outputElements.includes(e)),\n elementCounts: {\n input: inputElements.length,\n output: outputElements.length,\n },\n };\n })\n .generateScore(({ results }) => {\n const inputElements = results.preprocessStepResult?.inputElements;\n const outputElements = results.preprocessStepResult?.outputElements;\n\n return calculateCoverage({\n original: inputElements,\n simplified: outputElements,\n });\n });\n}\n","import { createScorer } from '@mastra/core/scores';\nimport type { ScorerRunInputForAgent, ScorerRunOutputForAgent } from '@mastra/core/scores';\nimport { SequenceMatcher } from 'difflib';\n\nexport function createTextualDifferenceScorer() {\n return createScorer<ScorerRunInputForAgent, ScorerRunOutputForAgent>({\n name: 'Completeness',\n description:\n 'Leverage the nlp method from \"compromise\" to extract elements from the input and output and calculate the coverage.',\n })\n .preprocess(async ({ run }) => {\n const input = run.input?.inputMessages?.map((i: { content: string }) => i.content).join(', ') || '';\n const output = run.output?.map((i: { content: string }) => i.content).join(', ') || '';\n const matcher = new SequenceMatcher(null, input, output);\n const ratio = matcher.ratio();\n\n // Get detailed operations\n const ops = matcher.getOpcodes();\n const changes = ops.filter(([op]) => op !== 'equal').length;\n\n // Calculate confidence based on text length difference\n const maxLength = Math.max(input.length, output.length);\n const lengthDiff = maxLength > 0 ? Math.abs(input.length - output.length) / maxLength : 0;\n const confidence = 1 - lengthDiff;\n\n return {\n ratio,\n confidence,\n changes,\n lengthDiff,\n };\n })\n .generateScore(({ results }) => {\n return results.preprocessStepResult?.ratio;\n });\n}\n","import { createScorer } from '@mastra/core/scores';\nimport type { ScorerRunInputForAgent, ScorerRunOutputForAgent } from '@mastra/core/scores';\nimport keyword_extractor from 'keyword-extractor';\n\nexport function createKeywordCoverageScorer() {\n return createScorer<ScorerRunInputForAgent, ScorerRunOutputForAgent>({\n name: 'Completeness',\n description:\n 'Leverage the nlp method from \"compromise\" to extract elements from the input and output and calculate the coverage.',\n })\n .preprocess(async ({ run }) => {\n const input = run.input?.inputMessages?.map((i: { content: string }) => i.content).join(', ') || '';\n const output = run.output?.map((i: { content: string }) => i.content).join(', ') || '';\n\n if (!input && !output) {\n return {\n result: {\n referenceKeywords: new Set<string>(),\n responseKeywords: new Set<string>(),\n },\n };\n }\n\n const extractKeywords = (text: string) => {\n return keyword_extractor.extract(text, {\n language: 'english',\n remove_digits: true,\n return_changed_case: true,\n remove_duplicates: true,\n });\n };\n\n const referenceKeywords = new Set(extractKeywords(input));\n const responseKeywords = new Set(extractKeywords(output));\n return {\n referenceKeywords,\n responseKeywords,\n };\n })\n .analyze(async ({ results }) => {\n if (\n !results.preprocessStepResult?.referenceKeywords?.size &&\n !results.preprocessStepResult?.responseKeywords?.size\n ) {\n return {\n totalKeywordsLength: 0,\n matchedKeywordsLength: 0,\n };\n }\n\n const matchedKeywords = [...results.preprocessStepResult?.referenceKeywords].filter(k =>\n results.preprocessStepResult?.responseKeywords?.has(k),\n );\n\n return {\n totalKeywordsLength: Array.from(results.preprocessStepResult?.referenceKeywords).length ?? 0,\n matchedKeywordsLength: matchedKeywords.length ?? 0,\n };\n })\n .generateScore(({ results }) => {\n if (!results.analyzeStepResult?.totalKeywordsLength) {\n return 1;\n }\n\n const totalKeywords = results.analyzeStepResult?.totalKeywordsLength!;\n const matchedKeywords = results.analyzeStepResult?.matchedKeywordsLength!;\n return totalKeywords > 0 ? matchedKeywords / totalKeywords : 0;\n });\n}\n","import { createScorer } from '@mastra/core/scores';\nimport type { ScorerRunInputForAgent, ScorerRunOutputForAgent } from '@mastra/core/scores';\nimport stringSimilarity from 'string-similarity';\n\ninterface ContentSimilarityOptions {\n ignoreCase?: boolean;\n ignoreWhitespace?: boolean;\n}\n\nexport function createContentSimilarityScorer(\n { ignoreCase, ignoreWhitespace }: ContentSimilarityOptions = { ignoreCase: true, ignoreWhitespace: true },\n) {\n return createScorer<ScorerRunInputForAgent, ScorerRunOutputForAgent>({\n name: 'Completeness',\n description:\n 'Leverage the nlp method from \"compromise\" to extract elements from the input and output and calculate the coverage.',\n })\n .preprocess(async ({ run }) => {\n let processedInput = run.input?.inputMessages.map((i: { content: string }) => i.content).join(', ') || '';\n let processedOutput = run.output.map((i: { content: string }) => i.content).join(', ') || '';\n\n if (ignoreCase) {\n processedInput = processedInput.toLowerCase();\n processedOutput = processedOutput.toLowerCase();\n }\n\n if (ignoreWhitespace) {\n processedInput = processedInput.replace(/\\s+/g, ' ').trim();\n processedOutput = processedOutput.replace(/\\s+/g, ' ').trim();\n }\n\n return {\n processedInput,\n processedOutput,\n };\n })\n .generateScore(({ results }) => {\n const similarity = stringSimilarity.compareTwoStrings(\n results.preprocessStepResult?.processedInput,\n results.preprocessStepResult?.processedOutput,\n );\n\n return similarity;\n });\n}\n","import { createScorer } from '@mastra/core/scores';\nimport type { ScorerRunInputForAgent, ScorerRunOutputForAgent } from '@mastra/core/scores';\nimport Sentiment from 'sentiment';\n\ninterface ToneScorerConfig {\n referenceTone?: string;\n}\n\nexport function createToneScorer(config: ToneScorerConfig = {}) {\n const { referenceTone } = config;\n\n return createScorer<ScorerRunInputForAgent, ScorerRunOutputForAgent>({\n name: 'Completeness',\n description:\n 'Leverage the nlp method from \"compromise\" to extract elements from the input and output and calculate the coverage.',\n })\n .preprocess(async ({ run }) => {\n const sentiment = new Sentiment();\n const agentMessage: string = run.output?.map((i: { content: string }) => i.content).join(', ') || '';\n const responseSentiment = sentiment.analyze(agentMessage);\n\n if (referenceTone) {\n // Compare sentiment with reference\n const referenceSentiment = sentiment.analyze(referenceTone);\n const sentimentDiff = Math.abs(responseSentiment.comparative - referenceSentiment.comparative);\n const normalizedScore = Math.max(0, 1 - sentimentDiff);\n\n return {\n score: normalizedScore,\n responseSentiment: responseSentiment.comparative,\n referenceSentiment: referenceSentiment.comparative,\n difference: sentimentDiff,\n };\n }\n\n // Evaluate sentiment stability across response\n const sentences = agentMessage.match(/[^.!?]+[.!?]+/g) || [agentMessage];\n const sentiments = sentences.map(s => sentiment.analyze(s).comparative);\n const avgSentiment = sentiments.reduce((a, b) => a + b, 0) / sentiments.length;\n const variance = sentiments.reduce((sum, s) => sum + Math.pow(s - avgSentiment, 2), 0) / sentiments.length;\n const stability = Math.max(0, 1 - variance);\n\n return {\n score: stability,\n avgSentiment,\n sentimentVariance: variance,\n };\n })\n .generateScore(({ results }) => {\n return results.preprocessStepResult?.score;\n });\n}\n","import type { ScorerRunInputForAgent, ScorerRunOutputForAgent } from '@mastra/core/scores';\nimport { createScorer } from '@mastra/core/scores';\nimport { extractToolCalls } from '../../utils';\n\ninterface ToolCallAccuracyOptions {\n expectedTool?: string;\n strictMode?: boolean;\n expectedToolOrder?: string[];\n}\n\nfunction checkToolOrder(actualTools: string[], expectedOrder: string[], strictMode: boolean = false): boolean {\n if (strictMode) {\n return JSON.stringify(actualTools) === JSON.stringify(expectedOrder);\n }\n\n const expectedIndices: number[] = [];\n for (const expectedTool of expectedOrder) {\n const index = actualTools.indexOf(expectedTool);\n if (index === -1) {\n return false;\n }\n expectedIndices.push(index);\n }\n\n for (let i = 1; i < expectedIndices.length; i++) {\n const currentIndex = expectedIndices[i];\n const prevIndex = expectedIndices[i - 1];\n if (currentIndex !== undefined && prevIndex !== undefined && currentIndex <= prevIndex) {\n return false;\n }\n }\n\n return true;\n}\n\nfunction calculateAccuracy({\n expectedTool,\n actualTools,\n strictMode = false,\n expectedToolOrder,\n}: {\n expectedTool?: string;\n actualTools: string[];\n strictMode?: boolean;\n expectedToolOrder?: string[];\n}): number {\n if (actualTools.length === 0) {\n return 0;\n }\n\n if (expectedToolOrder && expectedToolOrder.length > 0) {\n return checkToolOrder(actualTools, expectedToolOrder, strictMode) ? 1 : 0;\n }\n\n if (!expectedTool) {\n return 0;\n }\n\n if (strictMode) {\n return actualTools.length === 1 && actualTools[0] === expectedTool ? 1 : 0;\n }\n\n return actualTools.includes(expectedTool) ? 1 : 0;\n}\n\nexport function createToolCallAccuracyScorerCode(options: ToolCallAccuracyOptions) {\n const { expectedTool, strictMode = false, expectedToolOrder } = options;\n\n if (!expectedTool && !expectedToolOrder) {\n throw new Error('Either expectedTool or expectedToolOrder must be provided');\n }\n\n const getDescription = () => {\n return expectedToolOrder\n ? `Evaluates whether the LLM called tools in the correct order: [${expectedToolOrder.join(', ')}]`\n : `Evaluates whether the LLM selected the correct tool (${expectedTool}) from the available tools`;\n };\n\n return createScorer<ScorerRunInputForAgent, ScorerRunOutputForAgent>({\n name: 'Tool Call Accuracy',\n description: getDescription(),\n })\n .preprocess(async ({ run }) => {\n const isInputInvalid = !run.input || !run.input.inputMessages || run.input.inputMessages.length === 0;\n const isOutputInvalid = !run.output || run.output.length === 0;\n\n if (isInputInvalid || isOutputInvalid) {\n throw new Error('Input and output messages cannot be null or empty');\n }\n\n const { tools: actualTools, toolCallInfos } = extractToolCalls(run.output);\n\n const correctToolCalled = expectedTool\n ? strictMode\n ? actualTools.length === 1 && actualTools[0] === expectedTool\n : actualTools.includes(expectedTool)\n : false;\n\n return {\n expectedTool,\n actualTools,\n strictMode,\n expectedToolOrder,\n hasToolCalls: actualTools.length > 0,\n correctToolCalled,\n toolCallInfos,\n correctOrderCalled: expectedToolOrder ? checkToolOrder(actualTools, expectedToolOrder, strictMode) : null,\n };\n })\n .generateScore(({ results }) => {\n const preprocessResult = results.preprocessStepResult;\n if (!preprocessResult) {\n return 0;\n }\n\n return calculateAccuracy({\n expectedTool: preprocessResult.expectedTool,\n actualTools: preprocessResult.actualTools,\n strictMode: preprocessResult.strictMode,\n expectedToolOrder: preprocessResult.expectedToolOrder,\n });\n });\n}\n"]}
@@ -3,4 +3,5 @@ export * from './textual-difference/index.js';
3
3
  export * from './keyword-coverage/index.js';
4
4
  export * from './content-similarity/index.js';
5
5
  export * from './tone/index.js';
6
+ export * from './tool-call-accuracy/index.js';
6
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/scorers/code/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,QAAQ,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/scorers/code/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,QAAQ,CAAC;AACvB,cAAc,sBAAsB,CAAC"}
@@ -1,3 +1,4 @@
1
+ import { extractToolCalls } from '../../chunk-5CVZXIFW.js';
1
2
  import { createScorer } from '@mastra/core/scores';
2
3
  import nlp from 'compromise';
3
4
  import { SequenceMatcher } from 'difflib';
@@ -219,7 +220,90 @@ function createToneScorer(config = {}) {
219
220
  return results.preprocessStepResult?.score;
220
221
  });
221
222
  }
223
+ function checkToolOrder(actualTools, expectedOrder, strictMode = false) {
224
+ if (strictMode) {
225
+ return JSON.stringify(actualTools) === JSON.stringify(expectedOrder);
226
+ }
227
+ const expectedIndices = [];
228
+ for (const expectedTool of expectedOrder) {
229
+ const index = actualTools.indexOf(expectedTool);
230
+ if (index === -1) {
231
+ return false;
232
+ }
233
+ expectedIndices.push(index);
234
+ }
235
+ for (let i = 1; i < expectedIndices.length; i++) {
236
+ const currentIndex = expectedIndices[i];
237
+ const prevIndex = expectedIndices[i - 1];
238
+ if (currentIndex !== void 0 && prevIndex !== void 0 && currentIndex <= prevIndex) {
239
+ return false;
240
+ }
241
+ }
242
+ return true;
243
+ }
244
+ function calculateAccuracy({
245
+ expectedTool,
246
+ actualTools,
247
+ strictMode = false,
248
+ expectedToolOrder
249
+ }) {
250
+ if (actualTools.length === 0) {
251
+ return 0;
252
+ }
253
+ if (expectedToolOrder && expectedToolOrder.length > 0) {
254
+ return checkToolOrder(actualTools, expectedToolOrder, strictMode) ? 1 : 0;
255
+ }
256
+ if (!expectedTool) {
257
+ return 0;
258
+ }
259
+ if (strictMode) {
260
+ return actualTools.length === 1 && actualTools[0] === expectedTool ? 1 : 0;
261
+ }
262
+ return actualTools.includes(expectedTool) ? 1 : 0;
263
+ }
264
+ function createToolCallAccuracyScorerCode(options) {
265
+ const { expectedTool, strictMode = false, expectedToolOrder } = options;
266
+ if (!expectedTool && !expectedToolOrder) {
267
+ throw new Error("Either expectedTool or expectedToolOrder must be provided");
268
+ }
269
+ const getDescription = () => {
270
+ return expectedToolOrder ? `Evaluates whether the LLM called tools in the correct order: [${expectedToolOrder.join(", ")}]` : `Evaluates whether the LLM selected the correct tool (${expectedTool}) from the available tools`;
271
+ };
272
+ return createScorer({
273
+ name: "Tool Call Accuracy",
274
+ description: getDescription()
275
+ }).preprocess(async ({ run }) => {
276
+ const isInputInvalid = !run.input || !run.input.inputMessages || run.input.inputMessages.length === 0;
277
+ const isOutputInvalid = !run.output || run.output.length === 0;
278
+ if (isInputInvalid || isOutputInvalid) {
279
+ throw new Error("Input and output messages cannot be null or empty");
280
+ }
281
+ const { tools: actualTools, toolCallInfos } = extractToolCalls(run.output);
282
+ const correctToolCalled = expectedTool ? strictMode ? actualTools.length === 1 && actualTools[0] === expectedTool : actualTools.includes(expectedTool) : false;
283
+ return {
284
+ expectedTool,
285
+ actualTools,
286
+ strictMode,
287
+ expectedToolOrder,
288
+ hasToolCalls: actualTools.length > 0,
289
+ correctToolCalled,
290
+ toolCallInfos,
291
+ correctOrderCalled: expectedToolOrder ? checkToolOrder(actualTools, expectedToolOrder, strictMode) : null
292
+ };
293
+ }).generateScore(({ results }) => {
294
+ const preprocessResult = results.preprocessStepResult;
295
+ if (!preprocessResult) {
296
+ return 0;
297
+ }
298
+ return calculateAccuracy({
299
+ expectedTool: preprocessResult.expectedTool,
300
+ actualTools: preprocessResult.actualTools,
301
+ strictMode: preprocessResult.strictMode,
302
+ expectedToolOrder: preprocessResult.expectedToolOrder
303
+ });
304
+ });
305
+ }
222
306
 
223
- export { createCompletenessScorer, createContentSimilarityScorer, createKeywordCoverageScorer, createTextualDifferenceScorer, createToneScorer };
307
+ export { createCompletenessScorer, createContentSimilarityScorer, createKeywordCoverageScorer, createTextualDifferenceScorer, createToneScorer, createToolCallAccuracyScorerCode };
224
308
  //# sourceMappingURL=index.js.map
225
309
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/scorers/code/completeness/index.ts","../../../src/scorers/code/textual-difference/index.ts","../../../src/scorers/code/keyword-coverage/index.ts","../../../src/scorers/code/content-similarity/index.ts","../../../src/scorers/code/tone/index.ts"],"names":["createScorer"],"mappings":";;;;;;;AAIA,SAAS,gBAAgB,GAAA,EAAqB;AAE5C,EAAA,OAAO,GAAA,CACJ,UAAU,KAAK,CAAA,CACf,QAAQ,kBAAA,EAAoB,EAAE,EAC9B,WAAA,EAAY;AACjB;AAEA,SAAS,gBAAgB,GAAA,EAAoB;AAE3C,EAAA,MAAM,QAAQ,GAAA,CAAI,KAAA,GAAQ,GAAA,CAAI,OAAO,KAAK,EAAC;AAC3C,EAAA,MAAM,KAAA,GAAQ,IAAI,KAAA,EAAM,CAAE,cAAa,CAAE,GAAA,CAAI,OAAO,CAAA,IAAK,EAAC;AAC1D,EAAA,MAAM,SAAS,GAAA,CAAI,MAAA,GAAS,GAAA,CAAI,OAAO,KAAK,EAAC;AAC7C,EAAA,MAAM,QAAQ,GAAA,CAAI,KAAA,GAAQ,GAAA,CAAI,OAAO,KAAK,EAAC;AAG3C,EAAA,MAAM,iBAAA,GAAoB,CAAC,IAAA,KAA2B;AAEpD,IAAA,MAAM,UAAA,GAAa,gBAAgB,IAAI,CAAA;AAGvC,IAAA,OAAO,W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9B,IAAA,OAAO,QAAQ,oBAAA,EAAsB,KAAA;AAAA,EACvC,CAAC,CAAA;AACL","file":"index.js","sourcesContent":["import { createScorer } from '@mastra/core/scores';\nimport type { ScorerRunInputForAgent, ScorerRunOutputForAgent } from '@mastra/core/scores';\nimport nlp from 'compromise';\n\nfunction normalizeString(str: string): string {\n // Remove diacritics and convert to lowercase\n return str\n .normalize('NFD')\n .replace(/[\\u0300-\\u036f]/g, '')\n .toLowerCase();\n}\n\nfunction extractElements(doc: any): string[] {\n // Get more specific elements and ensure they're arrays\n const nouns = doc.nouns().out('array') || [];\n const verbs = doc.verbs().toInfinitive().out('array') || [];\n const topics = doc.topics().out('array') || [];\n const terms = doc.terms().out('array') || [];\n\n // Helper function to clean and split terms\n const cleanAndSplitTerm = (term: string): string[] => {\n // First normalize the string\n const normalized = normalizeString(term);\n\n // Split on word boundaries and filter out empty strings\n return normalized\n .replace(/([a-z])([A-Z])/g, '$1 $2') // Split camelCase\n .replace(/[^a-z0-9]+/g, ' ') // Replace non-alphanumeric with spaces\n .trim()\n .split(/\\s+/)\n .filter(word => word.length > 0);\n };\n\n // Process all elements\n const processedTerms = [\n ...nouns.flatMap(cleanAndSplitTerm),\n ...verbs.flatMap(cleanAndSplitTerm),\n ...topics.flatMap(cleanAndSplitTerm),\n ...terms.flatMap(cleanAndSplitTerm),\n ];\n\n // Remove duplicates\n return [...new Set(processedTerms)];\n}\n\nfunction calculateCoverage({ original, simplified }: { original: string[]; simplified: string[] }): number {\n if (original.length === 0) {\n return simplified.length === 0 ? 1 : 0;\n }\n\n // Exact matching for short words (3 chars or less), substring matching for longer words\n const covered = original.filter(element =>\n simplified.some(s => {\n const elem = normalizeString(element);\n const simp = normalizeString(s);\n\n // For short words (3 chars or less), require exact match\n if (elem.length <= 3) {\n return elem === simp;\n }\n\n // For longer words, require substantial overlap (more than 60% of the longer word)\n const longer = elem.length > simp.length ? elem : simp;\n const shorter = elem.length > simp.length ? simp : elem;\n\n if (longer.includes(shorter)) {\n return shorter.length / longer.length > 0.6;\n }\n\n return false;\n }),\n );\n return covered.length / original.length;\n}\n\nexport function createCompletenessScorer() {\n return createScorer<ScorerRunInputForAgent, ScorerRunOutputForAgent>({\n name: 'Completeness',\n description:\n 'Leverage the nlp method from \"compromise\" to extract elements from the input and output and calculate the coverage.',\n })\n .preprocess(async ({ run }) => {\n const isInputInvalid =\n !run.input ||\n run.input.inputMessages.some((i: { content: string }) => i.content === null || i.content === undefined);\n\n const isOutputInvalid =\n !run.output || run.output.some((i: { content: string }) => i.content === null || i.content === undefined);\n\n if (isInputInvalid || isOutputInvalid) {\n throw new Error('Inputs cannot be null or undefined');\n }\n\n const input = run.input?.inputMessages.map((i: { content: string }) => i.content).join(', ') || '';\n const output = run.output?.map(({ content }: { content: string }) => content).join(', ') || '';\n\n const inputToProcess = input;\n const outputToProcess = output;\n\n const inputDoc = nlp(inputToProcess.trim());\n const outputDoc = nlp(outputToProcess.trim());\n\n // Extract and log elements\n const inputElements = extractElements(inputDoc);\n const outputElements = extractElements(outputDoc);\n\n return {\n inputElements,\n outputElements,\n missingElements: inputElements.filter(e => !outputElements.includes(e)),\n elementCounts: {\n input: inputElements.length,\n output: outputElements.length,\n },\n };\n })\n .generateScore(({ results }) => {\n const inputElements = results.preprocessStepResult?.inputElements;\n const outputElements = results.preprocessStepResult?.outputElements;\n\n return calculateCoverage({\n original: inputElements,\n simplified: outputElements,\n });\n });\n}\n","import { createScorer } from '@mastra/core/scores';\nimport type { ScorerRunInputForAgent, ScorerRunOutputForAgent } from '@mastra/core/scores';\nimport { SequenceMatcher } from 'difflib';\n\nexport function createTextualDifferenceScorer() {\n return createScorer<ScorerRunInputForAgent, ScorerRunOutputForAgent>({\n name: 'Completeness',\n description:\n 'Leverage the nlp method from \"compromise\" to extract elements from the input and output and calculate the coverage.',\n })\n .preprocess(async ({ run }) => {\n const input = run.input?.inputMessages?.map((i: { content: string }) => i.content).join(', ') || '';\n const output = run.output?.map((i: { content: string }) => i.content).join(', ') || '';\n const matcher = new SequenceMatcher(null, input, output);\n const ratio = matcher.ratio();\n\n // Get detailed operations\n const ops = matcher.getOpcodes();\n const changes = ops.filter(([op]) => op !== 'equal').length;\n\n // Calculate confidence based on text length difference\n const maxLength = Math.max(input.length, output.length);\n const lengthDiff = maxLength > 0 ? Math.abs(input.length - output.length) / maxLength : 0;\n const confidence = 1 - lengthDiff;\n\n return {\n ratio,\n confidence,\n changes,\n lengthDiff,\n };\n })\n .generateScore(({ results }) => {\n return results.preprocessStepResult?.ratio;\n });\n}\n","import { createScorer } from '@mastra/core/scores';\nimport type { ScorerRunInputForAgent, ScorerRunOutputForAgent } from '@mastra/core/scores';\nimport keyword_extractor from 'keyword-extractor';\n\nexport function createKeywordCoverageScorer() {\n return createScorer<ScorerRunInputForAgent, ScorerRunOutputForAgent>({\n name: 'Completeness',\n description:\n 'Leverage the nlp method from \"compromise\" to extract elements from the input and output and calculate the coverage.',\n })\n .preprocess(async ({ run }) => {\n const input = run.input?.inputMessages?.map((i: { content: string }) => i.content).join(', ') || '';\n const output = run.output?.map((i: { content: string }) => i.content).join(', ') || '';\n\n if (!input && !output) {\n return {\n result: {\n referenceKeywords: new Set<string>(),\n responseKeywords: new Set<string>(),\n },\n };\n }\n\n const extractKeywords = (text: string) => {\n return keyword_extractor.extract(text, {\n language: 'english',\n remove_digits: true,\n return_changed_case: true,\n remove_duplicates: true,\n });\n };\n\n const referenceKeywords = new Set(extractKeywords(input));\n const responseKeywords = new Set(extractKeywords(output));\n return {\n referenceKeywords,\n responseKeywords,\n };\n })\n .analyze(async ({ results }) => {\n if (\n !results.preprocessStepResult?.referenceKeywords?.size &&\n !results.preprocessStepResult?.responseKeywords?.size\n ) {\n return {\n totalKeywordsLength: 0,\n matchedKeywordsLength: 0,\n };\n }\n\n const matchedKeywords = [...results.preprocessStepResult?.referenceKeywords].filter(k =>\n results.preprocessStepResult?.responseKeywords?.has(k),\n );\n\n return {\n totalKeywordsLength: Array.from(results.preprocessStepResult?.referenceKeywords).length ?? 0,\n matchedKeywordsLength: matchedKeywords.length ?? 0,\n };\n })\n .generateScore(({ results }) => {\n if (!results.analyzeStepResult?.totalKeywordsLength) {\n return 1;\n }\n\n const totalKeywords = results.analyzeStepResult?.totalKeywordsLength!;\n const matchedKeywords = results.analyzeStepResult?.matchedKeywordsLength!;\n return totalKeywords > 0 ? matchedKeywords / totalKeywords : 0;\n });\n}\n","import { createScorer } from '@mastra/core/scores';\nimport type { ScorerRunInputForAgent, ScorerRunOutputForAgent } from '@mastra/core/scores';\nimport stringSimilarity from 'string-similarity';\n\ninterface ContentSimilarityOptions {\n ignoreCase?: boolean;\n ignoreWhitespace?: boolean;\n}\n\nexport function createContentSimilarityScorer(\n { ignoreCase, ignoreWhitespace }: ContentSimilarityOptions = { ignoreCase: true, ignoreWhitespace: true },\n) {\n return createScorer<ScorerRunInputForAgent, ScorerRunOutputForAgent>({\n name: 'Completeness',\n description:\n 'Leverage the nlp method from \"compromise\" to extract elements from the input and output and calculate the coverage.',\n })\n .preprocess(async ({ run }) => {\n let processedInput = run.input?.inputMessages.map((i: { content: string }) => i.content).join(', ') || '';\n let processedOutput = run.output.map((i: { content: string }) => i.content).join(', ') || '';\n\n if (ignoreCase) {\n processedInput = processedInput.toLowerCase();\n processedOutput = processedOutput.toLowerCase();\n }\n\n if (ignoreWhitespace) {\n processedInput = processedInput.replace(/\\s+/g, ' ').trim();\n processedOutput = processedOutput.replace(/\\s+/g, ' ').trim();\n }\n\n return {\n processedInput,\n processedOutput,\n };\n })\n .generateScore(({ results }) => {\n const similarity = stringSimilarity.compareTwoStrings(\n results.preprocessStepResult?.processedInput,\n results.preprocessStepResult?.processedOutput,\n );\n\n return similarity;\n });\n}\n","import { createScorer } from '@mastra/core/scores';\nimport type { ScorerRunInputForAgent, ScorerRunOutputForAgent } from '@mastra/core/scores';\nimport Sentiment from 'sentiment';\n\ninterface ToneScorerConfig {\n referenceTone?: string;\n}\n\nexport function createToneScorer(config: ToneScorerConfig = {}) {\n const { referenceTone } = config;\n\n return createScorer<ScorerRunInputForAgent, ScorerRunOutputForAgent>({\n name: 'Completeness',\n description:\n 'Leverage the nlp method from \"compromise\" to extract elements from the input and output and calculate the coverage.',\n })\n .preprocess(async ({ run }) => {\n const sentiment = new Sentiment();\n const agentMessage: string = run.output?.map((i: { content: string }) => i.content).join(', ') || '';\n const responseSentiment = sentiment.analyze(agentMessage);\n\n if (referenceTone) {\n // Compare sentiment with reference\n const referenceSentiment = sentiment.analyze(referenceTone);\n const sentimentDiff = Math.abs(responseSentiment.comparative - referenceSentiment.comparative);\n const normalizedScore = Math.max(0, 1 - sentimentDiff);\n\n return {\n score: normalizedScore,\n responseSentiment: responseSentiment.comparative,\n referenceSentiment: referenceSentiment.comparative,\n difference: sentimentDiff,\n };\n }\n\n // Evaluate sentiment stability across response\n const sentences = agentMessage.match(/[^.!?]+[.!?]+/g) || [agentMessage];\n const sentiments = sentences.map(s => sentiment.analyze(s).comparative);\n const avgSentiment = sentiments.reduce((a, b) => a + b, 0) / sentiments.length;\n const variance = sentiments.reduce((sum, s) => sum + Math.pow(s - avgSentiment, 2), 0) / sentiments.length;\n const stability = Math.max(0, 1 - variance);\n\n return {\n score: stability,\n avgSentiment,\n sentimentVariance: variance,\n };\n })\n .generateScore(({ results }) => {\n return results.preprocessStepResult?.score;\n });\n}\n"]}
1
+ {"version":3,"sources":["../../../src/scorers/code/completeness/index.ts","../../../src/scorers/code/textual-difference/index.ts","../../../src/scorers/code/keyword-coverage/index.ts","../../../src/scorers/code/content-similarity/index.ts","../../../src/scorers/code/tone/index.ts","../../../src/scorers/code/tool-call-accuracy/index.ts"],"names":["createScorer"],"mappings":";;;;;;;;AAIA,SAAS,gBAAgB,GAAA,EAAqB;AAE5C,EAAA,OAAO,GAAA,CACJ,UAAU,KAAK,CAAA,CACf,QAAQ,kBAAA,EAAoB,EAAE,EAC9B,WAAA,EAAY;AACjB;AAEA,SAAS,gBAAgB,GAAA,EAAoB;AAE3C,EAAA,MAAM,QAAQ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;AAEA,IAAA,OAAO,iBAAA,CAAkB;AAAA,MACvB,cAAc,gBAAA,CAAiB,YAAA;AAAA,MAC/B,aAAa,gBAAA,CAAiB,WAAA;AAAA,MAC9B,YAAY,gBAAA,CAAiB,UAAA;AAAA,MAC7B,mBAAmB,gBAAA,CAAiB;AAAA,KACrC,CAAA;AAAA,EACH,CAAC,CAAA;AACL","file":"index.js","sourcesContent":["import { createScorer } from '@mastra/core/scores';\nimport type { ScorerRunInputForAgent, ScorerRunOutputForAgent } from '@mastra/core/scores';\nimport nlp from 'compromise';\n\nfunction normalizeString(str: string): string {\n // Remove diacritics and convert to lowercase\n return str\n .normalize('NFD')\n .replace(/[\\u0300-\\u036f]/g, '')\n .toLowerCase();\n}\n\nfunction extractElements(doc: any): string[] {\n // Get more specific elements and ensure they're arrays\n const nouns = doc.nouns().out('array') || [];\n const verbs = doc.verbs().toInfinitive().out('array') || [];\n const topics = doc.topics().out('array') || [];\n const terms = doc.terms().out('array') || [];\n\n // Helper function to clean and split terms\n const cleanAndSplitTerm = (term: string): string[] => {\n // First normalize the string\n const normalized = normalizeString(term);\n\n // Split on word boundaries and filter out empty strings\n return normalized\n .replace(/([a-z])([A-Z])/g, '$1 $2') // Split camelCase\n .replace(/[^a-z0-9]+/g, ' ') // Replace non-alphanumeric with spaces\n .trim()\n .split(/\\s+/)\n .filter(word => word.length > 0);\n };\n\n // Process all elements\n const processedTerms = [\n ...nouns.flatMap(cleanAndSplitTerm),\n ...verbs.flatMap(cleanAndSplitTerm),\n ...topics.flatMap(cleanAndSplitTerm),\n ...terms.flatMap(cleanAndSplitTerm),\n ];\n\n // Remove duplicates\n return [...new Set(processedTerms)];\n}\n\nfunction calculateCoverage({ original, simplified }: { original: string[]; simplified: string[] }): number {\n if (original.length === 0) {\n return simplified.length === 0 ? 1 : 0;\n }\n\n // Exact matching for short words (3 chars or less), substring matching for longer words\n const covered = original.filter(element =>\n simplified.some(s => {\n const elem = normalizeString(element);\n const simp = normalizeString(s);\n\n // For short words (3 chars or less), require exact match\n if (elem.length <= 3) {\n return elem === simp;\n }\n\n // For longer words, require substantial overlap (more than 60% of the longer word)\n const longer = elem.length > simp.length ? elem : simp;\n const shorter = elem.length > simp.length ? simp : elem;\n\n if (longer.includes(shorter)) {\n return shorter.length / longer.length > 0.6;\n }\n\n return false;\n }),\n );\n return covered.length / original.length;\n}\n\nexport function createCompletenessScorer() {\n return createScorer<ScorerRunInputForAgent, ScorerRunOutputForAgent>({\n name: 'Completeness',\n description:\n 'Leverage the nlp method from \"compromise\" to extract elements from the input and output and calculate the coverage.',\n })\n .preprocess(async ({ run }) => {\n const isInputInvalid =\n !run.input ||\n run.input.inputMessages.some((i: { content: string }) => i.content === null || i.content === undefined);\n\n const isOutputInvalid =\n !run.output || run.output.some((i: { content: string }) => i.content === null || i.content === undefined);\n\n if (isInputInvalid || isOutputInvalid) {\n throw new Error('Inputs cannot be null or undefined');\n }\n\n const input = run.input?.inputMessages.map((i: { content: string }) => i.content).join(', ') || '';\n const output = run.output?.map(({ content }: { content: string }) => content).join(', ') || '';\n\n const inputToProcess = input;\n const outputToProcess = output;\n\n const inputDoc = nlp(inputToProcess.trim());\n const outputDoc = nlp(outputToProcess.trim());\n\n // Extract and log elements\n const inputElements = extractElements(inputDoc);\n const outputElements = extractElements(outputDoc);\n\n return {\n inputElements,\n outputElements,\n missingElements: inputElements.filter(e => !outputElements.includes(e)),\n elementCounts: {\n input: inputElements.length,\n output: outputElements.length,\n },\n };\n })\n .generateScore(({ results }) => {\n const inputElements = results.preprocessStepResult?.inputElements;\n const outputElements = results.preprocessStepResult?.outputElements;\n\n return calculateCoverage({\n original: inputElements,\n simplified: outputElements,\n });\n });\n}\n","import { createScorer } from '@mastra/core/scores';\nimport type { ScorerRunInputForAgent, ScorerRunOutputForAgent } from '@mastra/core/scores';\nimport { SequenceMatcher } from 'difflib';\n\nexport function createTextualDifferenceScorer() {\n return createScorer<ScorerRunInputForAgent, ScorerRunOutputForAgent>({\n name: 'Completeness',\n description:\n 'Leverage the nlp method from \"compromise\" to extract elements from the input and output and calculate the coverage.',\n })\n .preprocess(async ({ run }) => {\n const input = run.input?.inputMessages?.map((i: { content: string }) => i.content).join(', ') || '';\n const output = run.output?.map((i: { content: string }) => i.content).join(', ') || '';\n const matcher = new SequenceMatcher(null, input, output);\n const ratio = matcher.ratio();\n\n // Get detailed operations\n const ops = matcher.getOpcodes();\n const changes = ops.filter(([op]) => op !== 'equal').length;\n\n // Calculate confidence based on text length difference\n const maxLength = Math.max(input.length, output.length);\n const lengthDiff = maxLength > 0 ? Math.abs(input.length - output.length) / maxLength : 0;\n const confidence = 1 - lengthDiff;\n\n return {\n ratio,\n confidence,\n changes,\n lengthDiff,\n };\n })\n .generateScore(({ results }) => {\n return results.preprocessStepResult?.ratio;\n });\n}\n","import { createScorer } from '@mastra/core/scores';\nimport type { ScorerRunInputForAgent, ScorerRunOutputForAgent } from '@mastra/core/scores';\nimport keyword_extractor from 'keyword-extractor';\n\nexport function createKeywordCoverageScorer() {\n return createScorer<ScorerRunInputForAgent, ScorerRunOutputForAgent>({\n name: 'Completeness',\n description:\n 'Leverage the nlp method from \"compromise\" to extract elements from the input and output and calculate the coverage.',\n })\n .preprocess(async ({ run }) => {\n const input = run.input?.inputMessages?.map((i: { content: string }) => i.content).join(', ') || '';\n const output = run.output?.map((i: { content: string }) => i.content).join(', ') || '';\n\n if (!input && !output) {\n return {\n result: {\n referenceKeywords: new Set<string>(),\n responseKeywords: new Set<string>(),\n },\n };\n }\n\n const extractKeywords = (text: string) => {\n return keyword_extractor.extract(text, {\n language: 'english',\n remove_digits: true,\n return_changed_case: true,\n remove_duplicates: true,\n });\n };\n\n const referenceKeywords = new Set(extractKeywords(input));\n const responseKeywords = new Set(extractKeywords(output));\n return {\n referenceKeywords,\n responseKeywords,\n };\n })\n .analyze(async ({ results }) => {\n if (\n !results.preprocessStepResult?.referenceKeywords?.size &&\n !results.preprocessStepResult?.responseKeywords?.size\n ) {\n return {\n totalKeywordsLength: 0,\n matchedKeywordsLength: 0,\n };\n }\n\n const matchedKeywords = [...results.preprocessStepResult?.referenceKeywords].filter(k =>\n results.preprocessStepResult?.responseKeywords?.has(k),\n );\n\n return {\n totalKeywordsLength: Array.from(results.preprocessStepResult?.referenceKeywords).length ?? 0,\n matchedKeywordsLength: matchedKeywords.length ?? 0,\n };\n })\n .generateScore(({ results }) => {\n if (!results.analyzeStepResult?.totalKeywordsLength) {\n return 1;\n }\n\n const totalKeywords = results.analyzeStepResult?.totalKeywordsLength!;\n const matchedKeywords = results.analyzeStepResult?.matchedKeywordsLength!;\n return totalKeywords > 0 ? matchedKeywords / totalKeywords : 0;\n });\n}\n","import { createScorer } from '@mastra/core/scores';\nimport type { ScorerRunInputForAgent, ScorerRunOutputForAgent } from '@mastra/core/scores';\nimport stringSimilarity from 'string-similarity';\n\ninterface ContentSimilarityOptions {\n ignoreCase?: boolean;\n ignoreWhitespace?: boolean;\n}\n\nexport function createContentSimilarityScorer(\n { ignoreCase, ignoreWhitespace }: ContentSimilarityOptions = { ignoreCase: true, ignoreWhitespace: true },\n) {\n return createScorer<ScorerRunInputForAgent, ScorerRunOutputForAgent>({\n name: 'Completeness',\n description:\n 'Leverage the nlp method from \"compromise\" to extract elements from the input and output and calculate the coverage.',\n })\n .preprocess(async ({ run }) => {\n let processedInput = run.input?.inputMessages.map((i: { content: string }) => i.content).join(', ') || '';\n let processedOutput = run.output.map((i: { content: string }) => i.content).join(', ') || '';\n\n if (ignoreCase) {\n processedInput = processedInput.toLowerCase();\n processedOutput = processedOutput.toLowerCase();\n }\n\n if (ignoreWhitespace) {\n processedInput = processedInput.replace(/\\s+/g, ' ').trim();\n processedOutput = processedOutput.replace(/\\s+/g, ' ').trim();\n }\n\n return {\n processedInput,\n processedOutput,\n };\n })\n .generateScore(({ results }) => {\n const similarity = stringSimilarity.compareTwoStrings(\n results.preprocessStepResult?.processedInput,\n results.preprocessStepResult?.processedOutput,\n );\n\n return similarity;\n });\n}\n","import { createScorer } from '@mastra/core/scores';\nimport type { ScorerRunInputForAgent, ScorerRunOutputForAgent } from '@mastra/core/scores';\nimport Sentiment from 'sentiment';\n\ninterface ToneScorerConfig {\n referenceTone?: string;\n}\n\nexport function createToneScorer(config: ToneScorerConfig = {}) {\n const { referenceTone } = config;\n\n return createScorer<ScorerRunInputForAgent, ScorerRunOutputForAgent>({\n name: 'Completeness',\n description:\n 'Leverage the nlp method from \"compromise\" to extract elements from the input and output and calculate the coverage.',\n })\n .preprocess(async ({ run }) => {\n const sentiment = new Sentiment();\n const agentMessage: string = run.output?.map((i: { content: string }) => i.content).join(', ') || '';\n const responseSentiment = sentiment.analyze(agentMessage);\n\n if (referenceTone) {\n // Compare sentiment with reference\n const referenceSentiment = sentiment.analyze(referenceTone);\n const sentimentDiff = Math.abs(responseSentiment.comparative - referenceSentiment.comparative);\n const normalizedScore = Math.max(0, 1 - sentimentDiff);\n\n return {\n score: normalizedScore,\n responseSentiment: responseSentiment.comparative,\n referenceSentiment: referenceSentiment.comparative,\n difference: sentimentDiff,\n };\n }\n\n // Evaluate sentiment stability across response\n const sentences = agentMessage.match(/[^.!?]+[.!?]+/g) || [agentMessage];\n const sentiments = sentences.map(s => sentiment.analyze(s).comparative);\n const avgSentiment = sentiments.reduce((a, b) => a + b, 0) / sentiments.length;\n const variance = sentiments.reduce((sum, s) => sum + Math.pow(s - avgSentiment, 2), 0) / sentiments.length;\n const stability = Math.max(0, 1 - variance);\n\n return {\n score: stability,\n avgSentiment,\n sentimentVariance: variance,\n };\n })\n .generateScore(({ results }) => {\n return results.preprocessStepResult?.score;\n });\n}\n","import type { ScorerRunInputForAgent, ScorerRunOutputForAgent } from '@mastra/core/scores';\nimport { createScorer } from '@mastra/core/scores';\nimport { extractToolCalls } from '../../utils';\n\ninterface ToolCallAccuracyOptions {\n expectedTool?: string;\n strictMode?: boolean;\n expectedToolOrder?: string[];\n}\n\nfunction checkToolOrder(actualTools: string[], expectedOrder: string[], strictMode: boolean = false): boolean {\n if (strictMode) {\n return JSON.stringify(actualTools) === JSON.stringify(expectedOrder);\n }\n\n const expectedIndices: number[] = [];\n for (const expectedTool of expectedOrder) {\n const index = actualTools.indexOf(expectedTool);\n if (index === -1) {\n return false;\n }\n expectedIndices.push(index);\n }\n\n for (let i = 1; i < expectedIndices.length; i++) {\n const currentIndex = expectedIndices[i];\n const prevIndex = expectedIndices[i - 1];\n if (currentIndex !== undefined && prevIndex !== undefined && currentIndex <= prevIndex) {\n return false;\n }\n }\n\n return true;\n}\n\nfunction calculateAccuracy({\n expectedTool,\n actualTools,\n strictMode = false,\n expectedToolOrder,\n}: {\n expectedTool?: string;\n actualTools: string[];\n strictMode?: boolean;\n expectedToolOrder?: string[];\n}): number {\n if (actualTools.length === 0) {\n return 0;\n }\n\n if (expectedToolOrder && expectedToolOrder.length > 0) {\n return checkToolOrder(actualTools, expectedToolOrder, strictMode) ? 1 : 0;\n }\n\n if (!expectedTool) {\n return 0;\n }\n\n if (strictMode) {\n return actualTools.length === 1 && actualTools[0] === expectedTool ? 1 : 0;\n }\n\n return actualTools.includes(expectedTool) ? 1 : 0;\n}\n\nexport function createToolCallAccuracyScorerCode(options: ToolCallAccuracyOptions) {\n const { expectedTool, strictMode = false, expectedToolOrder } = options;\n\n if (!expectedTool && !expectedToolOrder) {\n throw new Error('Either expectedTool or expectedToolOrder must be provided');\n }\n\n const getDescription = () => {\n return expectedToolOrder\n ? `Evaluates whether the LLM called tools in the correct order: [${expectedToolOrder.join(', ')}]`\n : `Evaluates whether the LLM selected the correct tool (${expectedTool}) from the available tools`;\n };\n\n return createScorer<ScorerRunInputForAgent, ScorerRunOutputForAgent>({\n name: 'Tool Call Accuracy',\n description: getDescription(),\n })\n .preprocess(async ({ run }) => {\n const isInputInvalid = !run.input || !run.input.inputMessages || run.input.inputMessages.length === 0;\n const isOutputInvalid = !run.output || run.output.length === 0;\n\n if (isInputInvalid || isOutputInvalid) {\n throw new Error('Input and output messages cannot be null or empty');\n }\n\n const { tools: actualTools, toolCallInfos } = extractToolCalls(run.output);\n\n const correctToolCalled = expectedTool\n ? strictMode\n ? actualTools.length === 1 && actualTools[0] === expectedTool\n : actualTools.includes(expectedTool)\n : false;\n\n return {\n expectedTool,\n actualTools,\n strictMode,\n expectedToolOrder,\n hasToolCalls: actualTools.length > 0,\n correctToolCalled,\n toolCallInfos,\n correctOrderCalled: expectedToolOrder ? checkToolOrder(actualTools, expectedToolOrder, strictMode) : null,\n };\n })\n .generateScore(({ results }) => {\n const preprocessResult = results.preprocessStepResult;\n if (!preprocessResult) {\n return 0;\n }\n\n return calculateAccuracy({\n expectedTool: preprocessResult.expectedTool,\n actualTools: preprocessResult.actualTools,\n strictMode: preprocessResult.strictMode,\n expectedToolOrder: preprocessResult.expectedToolOrder,\n });\n });\n}\n"]}
@@ -0,0 +1,18 @@
1
+ import type { ScorerRunInputForAgent, ScorerRunOutputForAgent } from '@mastra/core/scores';
2
+ interface ToolCallAccuracyOptions {
3
+ expectedTool?: string;
4
+ strictMode?: boolean;
5
+ expectedToolOrder?: string[];
6
+ }
7
+ export declare function createToolCallAccuracyScorerCode(options: ToolCallAccuracyOptions): import("@mastra/core/scores").MastraScorer<string, ScorerRunInputForAgent, ScorerRunOutputForAgent, Record<"preprocessStepResult", {
8
+ expectedTool: string | undefined;
9
+ actualTools: string[];
10
+ strictMode: boolean;
11
+ expectedToolOrder: string[] | undefined;
12
+ hasToolCalls: boolean;
13
+ correctToolCalled: boolean;
14
+ toolCallInfos: import("../../utils").ToolCallInfo[];
15
+ correctOrderCalled: boolean | null;
16
+ }> & Record<"generateScoreStepResult", number>>;
17
+ export {};
18
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/scorers/code/tool-call-accuracy/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAI3F,UAAU,uBAAuB;IAC/B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC9B;AAyDD,wBAAgB,gCAAgC,CAAC,OAAO,EAAE,uBAAuB;;;;;;;;;gDAyDhF"}