@mastra/evals 0.13.2 → 0.13.3-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2333 -0
- package/dist/{chunk-5CVZXIFW.js → chunk-4LRZVFXR.js} +32 -3
- package/dist/chunk-4LRZVFXR.js.map +1 -0
- package/dist/{chunk-QVZBKGOE.cjs → chunk-EKSPLMYP.cjs} +32 -2
- package/dist/chunk-EKSPLMYP.cjs.map +1 -0
- package/dist/{dist-JVIEAZJ6.js → dist-CI72CYZJ.js} +10 -10
- package/dist/{dist-JVIEAZJ6.js.map → dist-CI72CYZJ.js.map} +1 -1
- package/dist/{dist-JQCAD3AD.cjs → dist-IKJJ2AX4.cjs} +10 -10
- package/dist/{dist-JQCAD3AD.cjs.map → dist-IKJJ2AX4.cjs.map} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/{magic-string.es-NBXOXRCK.cjs → magic-string.es-VZN2EYER.cjs} +3 -3
- package/dist/{magic-string.es-NBXOXRCK.cjs.map → magic-string.es-VZN2EYER.cjs.map} +1 -1
- package/dist/{magic-string.es-6JSI7KY4.js → magic-string.es-WQRLTQPQ.js} +3 -3
- package/dist/{magic-string.es-6JSI7KY4.js.map → magic-string.es-WQRLTQPQ.js.map} +1 -1
- package/dist/scorers/code/index.cjs +2 -2
- package/dist/scorers/code/index.js +1 -1
- package/dist/scorers/llm/context-precision/index.d.ts +18 -0
- package/dist/scorers/llm/context-precision/index.d.ts.map +1 -0
- package/dist/scorers/llm/context-precision/prompts.d.ts +19 -0
- package/dist/scorers/llm/context-precision/prompts.d.ts.map +1 -0
- package/dist/scorers/llm/context-relevance/index.d.ts +27 -0
- package/dist/scorers/llm/context-relevance/index.d.ts.map +1 -0
- package/dist/scorers/llm/context-relevance/prompts.d.ts +20 -0
- package/dist/scorers/llm/context-relevance/prompts.d.ts.map +1 -0
- package/dist/scorers/llm/index.cjs +1163 -25
- package/dist/scorers/llm/index.cjs.map +1 -1
- package/dist/scorers/llm/index.d.ts +4 -0
- package/dist/scorers/llm/index.d.ts.map +1 -1
- package/dist/scorers/llm/index.js +1137 -3
- package/dist/scorers/llm/index.js.map +1 -1
- package/dist/scorers/llm/noise-sensitivity/index.d.ts +36 -0
- package/dist/scorers/llm/noise-sensitivity/index.d.ts.map +1 -0
- package/dist/scorers/llm/noise-sensitivity/prompts.d.ts +21 -0
- package/dist/scorers/llm/noise-sensitivity/prompts.d.ts.map +1 -0
- package/dist/scorers/llm/prompt-alignment/index.d.ts +38 -0
- package/dist/scorers/llm/prompt-alignment/index.d.ts.map +1 -0
- package/dist/scorers/llm/prompt-alignment/prompts.d.ts +44 -0
- package/dist/scorers/llm/prompt-alignment/prompts.d.ts.map +1 -0
- package/dist/scorers/llm/tool-call-accuracy/index.d.ts +2 -4
- package/dist/scorers/llm/tool-call-accuracy/index.d.ts.map +1 -1
- package/dist/scorers/utils.d.ts +2 -0
- package/dist/scorers/utils.d.ts.map +1 -1
- package/package.json +15 -5
- package/dist/chunk-5CVZXIFW.js.map +0 -1
- package/dist/chunk-QVZBKGOE.cjs.map +0 -1
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { MastraLanguageModel } from '@mastra/core/agent';
|
|
2
|
+
import type { ScorerRunInputForAgent, ScorerRunOutputForAgent } from '@mastra/core/scores';
|
|
3
|
+
export interface NoiseSensitivityOptions {
|
|
4
|
+
baselineResponse: string;
|
|
5
|
+
noisyQuery: string;
|
|
6
|
+
noiseType?: string;
|
|
7
|
+
scoring?: {
|
|
8
|
+
impactWeights?: {
|
|
9
|
+
none?: number;
|
|
10
|
+
minimal?: number;
|
|
11
|
+
moderate?: number;
|
|
12
|
+
significant?: number;
|
|
13
|
+
severe?: number;
|
|
14
|
+
};
|
|
15
|
+
penalties?: {
|
|
16
|
+
majorIssuePerItem?: number;
|
|
17
|
+
maxMajorIssuePenalty?: number;
|
|
18
|
+
};
|
|
19
|
+
discrepancyThreshold?: number;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export declare function createNoiseSensitivityScorerLLM({ model, options, }: {
|
|
23
|
+
model: MastraLanguageModel;
|
|
24
|
+
options: NoiseSensitivityOptions;
|
|
25
|
+
}): import("@mastra/core/scores").MastraScorer<string, ScorerRunInputForAgent, ScorerRunOutputForAgent, Record<"analyzeStepResult", {
|
|
26
|
+
overallAssessment: string;
|
|
27
|
+
dimensions: {
|
|
28
|
+
dimension: string;
|
|
29
|
+
impactLevel: "none" | "minimal" | "moderate" | "significant" | "severe";
|
|
30
|
+
specificChanges: string;
|
|
31
|
+
noiseInfluence: string;
|
|
32
|
+
}[];
|
|
33
|
+
robustnessScore: number;
|
|
34
|
+
majorIssues?: string[] | undefined;
|
|
35
|
+
}> & Record<"generateScoreStepResult", number> & Record<"generateReasonStepResult", string>>;
|
|
36
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/scorers/llm/noise-sensitivity/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,KAAK,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAM3F,MAAM,WAAW,uBAAuB;IACtC,gBAAgB,EAAE,MAAM,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE;QACR,aAAa,CAAC,EAAE;YACd,IAAI,CAAC,EAAE,MAAM,CAAC;YACd,OAAO,CAAC,EAAE,MAAM,CAAC;YACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;YAClB,WAAW,CAAC,EAAE,MAAM,CAAC;YACrB,MAAM,CAAC,EAAE,MAAM,CAAC;SACjB,CAAC;QACF,SAAS,CAAC,EAAE;YACV,iBAAiB,CAAC,EAAE,MAAM,CAAC;YAC3B,oBAAoB,CAAC,EAAE,MAAM,CAAC;SAC/B,CAAC;QACF,oBAAoB,CAAC,EAAE,MAAM,CAAC;KAC/B,CAAC;CACH;AA+BD,wBAAgB,+BAA+B,CAAC,EAC9C,KAAK,EACL,OAAO,GACR,EAAE;IACD,KAAK,EAAE,mBAAmB,CAAC;IAC3B,OAAO,EAAE,uBAAuB,CAAC;CAClC;;;;;;;;;;6FAoHA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare const NOISE_SENSITIVITY_INSTRUCTIONS = "You are an expert noise sensitivity evaluator. Your job is to analyze how much irrelevant, distracting, or misleading information (noise) affected the agent's response quality and accuracy.\n\nKey Evaluation Criteria:\n1. **Response Consistency**: How similar are the baseline and noisy responses in content and correctness?\n2. **Information Integrity**: Did the agent maintain accuracy despite noise, or was it misled?\n3. **Focus Preservation**: Did the agent stay on topic or get distracted by irrelevant information?\n4. **Hallucination Resistance**: Did noise cause the agent to generate false or fabricated information?\n5. **Completeness**: Did noise cause the agent to miss important parts of the original query?\n\nNoise Impact Assessment:\n- **No Impact (1.0)**: Response is virtually identical in quality, accuracy, and completeness\n- **Minimal Impact (0.8-0.9)**: Slight changes in phrasing but maintains correctness and completeness \n- **Moderate Impact (0.5-0.7)**: Noticeable changes that affect quality but core information remains correct\n- **Significant Impact (0.2-0.4)**: Major degradation in quality, accuracy, or completeness\n- **Severe Impact (0.0-0.1)**: Response is substantially worse, incorrect, or completely derailed\n\nBe thorough in comparing both responses and identifying specific ways the noise affected the agent's performance.";
|
|
2
|
+
export declare function createAnalyzePrompt({ userQuery, baselineResponse, noisyQuery, noisyResponse, noiseType, }: {
|
|
3
|
+
userQuery: string;
|
|
4
|
+
baselineResponse: string;
|
|
5
|
+
noisyQuery: string;
|
|
6
|
+
noisyResponse: string;
|
|
7
|
+
noiseType?: string;
|
|
8
|
+
}): string;
|
|
9
|
+
export declare function createReasonPrompt({ userQuery, score, dimensions, majorIssues, overallAssessment, }: {
|
|
10
|
+
userQuery: string;
|
|
11
|
+
score: number;
|
|
12
|
+
dimensions: Array<{
|
|
13
|
+
dimension: string;
|
|
14
|
+
impactLevel: string;
|
|
15
|
+
specificChanges: string;
|
|
16
|
+
noiseInfluence: string;
|
|
17
|
+
}>;
|
|
18
|
+
majorIssues: string[];
|
|
19
|
+
overallAssessment: string;
|
|
20
|
+
}): string;
|
|
21
|
+
//# sourceMappingURL=prompts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../../../../src/scorers/llm/noise-sensitivity/prompts.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,8BAA8B,61CAgBuE,CAAC;AAEnH,wBAAgB,mBAAmB,CAAC,EAClC,SAAS,EACT,gBAAgB,EAChB,UAAU,EACV,aAAa,EACb,SAAS,GACV,EAAE;IACD,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,EAAE,MAAM,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,UAgHA;AAED,wBAAgB,kBAAkB,CAAC,EACjC,SAAS,EACT,KAAK,EACL,UAAU,EACV,WAAW,EACX,iBAAiB,GAClB,EAAE;IACD,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,KAAK,CAAC;QAChB,SAAS,EAAE,MAAM,CAAC;QAClB,WAAW,EAAE,MAAM,CAAC;QACpB,eAAe,EAAE,MAAM,CAAC;QACxB,cAAc,EAAE,MAAM,CAAC;KACxB,CAAC,CAAC;IACH,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,iBAAiB,EAAE,MAAM,CAAC;CAC3B,UA6CA"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { MastraLanguageModel } from '@mastra/core/agent';
|
|
2
|
+
import type { ScorerRunInputForAgent, ScorerRunOutputForAgent } from '@mastra/core/scores';
|
|
3
|
+
export interface PromptAlignmentOptions {
|
|
4
|
+
scale?: number;
|
|
5
|
+
evaluationMode?: 'user' | 'system' | 'both';
|
|
6
|
+
}
|
|
7
|
+
export declare function createPromptAlignmentScorerLLM({ model, options, }: {
|
|
8
|
+
model: MastraLanguageModel;
|
|
9
|
+
options?: PromptAlignmentOptions;
|
|
10
|
+
}): import("@mastra/core/scores").MastraScorer<string, ScorerRunInputForAgent, ScorerRunOutputForAgent, Record<"analyzeStepResult", {
|
|
11
|
+
overallAssessment: string;
|
|
12
|
+
intentAlignment: {
|
|
13
|
+
reasoning: string;
|
|
14
|
+
score: number;
|
|
15
|
+
primaryIntent: string;
|
|
16
|
+
isAddressed: boolean;
|
|
17
|
+
};
|
|
18
|
+
requirementsFulfillment: {
|
|
19
|
+
requirements: {
|
|
20
|
+
reasoning: string;
|
|
21
|
+
requirement: string;
|
|
22
|
+
isFulfilled: boolean;
|
|
23
|
+
}[];
|
|
24
|
+
overallScore: number;
|
|
25
|
+
};
|
|
26
|
+
completeness: {
|
|
27
|
+
reasoning: string;
|
|
28
|
+
score: number;
|
|
29
|
+
missingElements: string[];
|
|
30
|
+
};
|
|
31
|
+
responseAppropriateness: {
|
|
32
|
+
reasoning: string;
|
|
33
|
+
score: number;
|
|
34
|
+
formatAlignment: boolean;
|
|
35
|
+
toneAlignment: boolean;
|
|
36
|
+
};
|
|
37
|
+
}> & Record<"generateScoreStepResult", number> & Record<"generateReasonStepResult", string>>;
|
|
38
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/scorers/llm/prompt-alignment/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,KAAK,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAW3F,MAAM,WAAW,sBAAsB;IACrC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,cAAc,CAAC,EAAE,MAAM,GAAG,QAAQ,GAAG,MAAM,CAAC;CAC7C;AAsDD,wBAAgB,8BAA8B,CAAC,EAC7C,KAAK,EACL,OAAO,GACR,EAAE;IACD,KAAK,EAAE,mBAAmB,CAAC;IAC3B,OAAO,CAAC,EAAE,sBAAsB,CAAC;CAClC;;;;;;;;;;;;;;;;;;;;;;;;;;;6FAoHA"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export declare const PROMPT_ALIGNMENT_INSTRUCTIONS = "You are an expert prompt-response alignment evaluator. Your job is to analyze how well an agent's response aligns with the user's prompt in terms of intent, requirements, completeness, and appropriateness.\n\nKey Evaluation Dimensions:\n1. **Intent Alignment**: Does the response address the core purpose of the prompt?\n2. **Requirements Fulfillment**: Are all explicit and implicit requirements met?\n3. **Completeness**: Is the response comprehensive and thorough?\n4. **Response Appropriateness**: Does the format, tone, and style match expectations?\n\nEvaluation Guidelines:\n- Identify the primary intent and any secondary intents in the prompt\n- Extract all explicit requirements (specific tasks, constraints, formats)\n- Consider implicit requirements based on context and standard expectations\n- Assess whether the response fully addresses the prompt or leaves gaps\n- Evaluate if the response format and tone are appropriate for the request\n- Be objective and focus on alignment rather than response quality\n\nScore each dimension from 0.0 (completely misaligned) to 1.0 (perfectly aligned).";
|
|
2
|
+
export declare function createAnalyzePrompt({ userPrompt, systemPrompt, agentResponse, evaluationMode, }: {
|
|
3
|
+
userPrompt: string;
|
|
4
|
+
systemPrompt?: string;
|
|
5
|
+
agentResponse: string;
|
|
6
|
+
evaluationMode: 'user' | 'system' | 'both';
|
|
7
|
+
}): string;
|
|
8
|
+
export type AnalysisResult = {
|
|
9
|
+
intentAlignment: {
|
|
10
|
+
score: number;
|
|
11
|
+
primaryIntent: string;
|
|
12
|
+
isAddressed: boolean;
|
|
13
|
+
reasoning: string;
|
|
14
|
+
};
|
|
15
|
+
requirementsFulfillment: {
|
|
16
|
+
requirements: Array<{
|
|
17
|
+
requirement: string;
|
|
18
|
+
isFulfilled: boolean;
|
|
19
|
+
reasoning: string;
|
|
20
|
+
}>;
|
|
21
|
+
overallScore: number;
|
|
22
|
+
};
|
|
23
|
+
completeness: {
|
|
24
|
+
score: number;
|
|
25
|
+
missingElements: string[];
|
|
26
|
+
reasoning: string;
|
|
27
|
+
};
|
|
28
|
+
responseAppropriateness: {
|
|
29
|
+
score: number;
|
|
30
|
+
formatAlignment: boolean;
|
|
31
|
+
toneAlignment: boolean;
|
|
32
|
+
reasoning: string;
|
|
33
|
+
};
|
|
34
|
+
overallAssessment: string;
|
|
35
|
+
};
|
|
36
|
+
export declare function createReasonPrompt({ userPrompt, systemPrompt, score, scale, analysis, evaluationMode, }: {
|
|
37
|
+
userPrompt: string;
|
|
38
|
+
systemPrompt?: string;
|
|
39
|
+
score: number;
|
|
40
|
+
scale: number;
|
|
41
|
+
analysis: AnalysisResult;
|
|
42
|
+
evaluationMode: 'user' | 'system' | 'both';
|
|
43
|
+
}): string;
|
|
44
|
+
//# sourceMappingURL=prompts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../../../../src/scorers/llm/prompt-alignment/prompts.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,6BAA6B,ulCAgBwC,CAAC;AAEnF,wBAAgB,mBAAmB,CAAC,EAClC,UAAU,EACV,YAAY,EACZ,aAAa,EACb,cAAc,GACf,EAAE;IACD,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,GAAG,QAAQ,GAAG,MAAM,CAAC;CAC5C,UA6KA;AAED,MAAM,MAAM,cAAc,GAAG;IAC3B,eAAe,EAAE;QACf,KAAK,EAAE,MAAM,CAAC;QACd,aAAa,EAAE,MAAM,CAAC;QACtB,WAAW,EAAE,OAAO,CAAC;QACrB,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;IACF,uBAAuB,EAAE;QACvB,YAAY,EAAE,KAAK,CAAC;YAClB,WAAW,EAAE,MAAM,CAAC;YACpB,WAAW,EAAE,OAAO,CAAC;YACrB,SAAS,EAAE,MAAM,CAAC;SACnB,CAAC,CAAC;QACH,YAAY,EAAE,MAAM,CAAC;KACtB,CAAC;IACF,YAAY,EAAE;QACZ,KAAK,EAAE,MAAM,CAAC;QACd,eAAe,EAAE,MAAM,EAAE,CAAC;QAC1B,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;IACF,uBAAuB,EAAE;QACvB,KAAK,EAAE,MAAM,CAAC;QACd,eAAe,EAAE,OAAO,CAAC;QACzB,aAAa,EAAE,OAAO,CAAC;QACvB,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;IACF,iBAAiB,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF,wBAAgB,kBAAkB,CAAC,EACjC,UAAU,EACV,YAAY,EACZ,KAAK,EACL,KAAK,EACL,QAAQ,EACR,cAAc,GACf,EAAE;IACD,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,cAAc,CAAC;IACzB,cAAc,EAAE,MAAM,GAAG,QAAQ,GAAG,MAAM,CAAC;CAC5C,UAkEA"}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
+
import type { Tool } from '@mastra/core';
|
|
1
2
|
import type { MastraLanguageModel } from '@mastra/core/agent';
|
|
2
3
|
import type { ScorerRunInputForAgent, ScorerRunOutputForAgent } from '@mastra/core/scores';
|
|
3
4
|
export interface ToolCallAccuracyOptions {
|
|
4
5
|
model: MastraLanguageModel;
|
|
5
|
-
availableTools:
|
|
6
|
-
name: string;
|
|
7
|
-
description: string;
|
|
8
|
-
}>;
|
|
6
|
+
availableTools: Tool[];
|
|
9
7
|
}
|
|
10
8
|
export declare function createToolCallAccuracyScorerLLM({ model, availableTools }: ToolCallAccuracyOptions): import("@mastra/core/scores").MastraScorer<string, ScorerRunInputForAgent, ScorerRunOutputForAgent, Record<"preprocessStepResult", {
|
|
11
9
|
actualTools: string[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/scorers/llm/tool-call-accuracy/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,KAAK,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAW3F,MAAM,WAAW,uBAAuB;IACtC,KAAK,EAAE,mBAAmB,CAAC;IAC3B,cAAc,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/scorers/llm/tool-call-accuracy/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,KAAK,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAW3F,MAAM,WAAW,uBAAuB;IACtC,KAAK,EAAE,mBAAmB,CAAC;IAC3B,cAAc,EAAE,IAAI,EAAE,CAAC;CACxB;AAaD,wBAAgB,+BAA+B,CAAC,EAAE,KAAK,EAAE,cAAc,EAAE,EAAE,uBAAuB;;;;;;;;;;;6FA0EjG"}
|
package/dist/scorers/utils.d.ts
CHANGED
|
@@ -16,6 +16,8 @@ export type TestCaseWithContext = TestCase & {
|
|
|
16
16
|
};
|
|
17
17
|
export declare const createTestRun: (input: string, output: string, context?: string[]) => ScoringInput;
|
|
18
18
|
export declare const getUserMessageFromRunInput: (input?: ScorerRunInputForAgent) => string | undefined;
|
|
19
|
+
export declare const getSystemMessagesFromRunInput: (input?: ScorerRunInputForAgent) => string[];
|
|
20
|
+
export declare const getCombinedSystemPrompt: (input?: ScorerRunInputForAgent) => string;
|
|
19
21
|
export declare const getAssistantMessageFromRunOutput: (output?: ScorerRunOutputForAgent) => string | undefined;
|
|
20
22
|
export declare const createToolInvocation: ({ toolCallId, toolName, args, result, state, }: {
|
|
21
23
|
toolCallId: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/scorers/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,KAAK,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACzG,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAEpD,eAAO,MAAM,kBAAkB,GAAI,KAAK,MAAM,WAE7C,CAAC;AAEF,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAEnF;AAED,MAAM,MAAM,QAAQ,GAAG;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE;QACd,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG,QAAQ,GAAG;IAC3C,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,OAAO,MAAM,EAAE,QAAQ,MAAM,EAAE,UAAU,MAAM,EAAE,KAAG,YAOjF,CAAC;AAEF,eAAO,MAAM,0BAA0B,GAAI,QAAQ,sBAAsB,uBAExE,CAAC;AAEF,eAAO,MAAM,gCAAgC,GAAI,SAAS,uBAAuB,uBAEhF,CAAC;AAEF,eAAO,MAAM,o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C;AAEF,eAAO,MAAM,4BAA4B,GAAI,WAAW,uBAAuB,KAAG,MAAM,EAEvF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/evals",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.3-alpha.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
7
|
-
"dist"
|
|
7
|
+
"dist",
|
|
8
|
+
"CHANGELOG.md"
|
|
8
9
|
],
|
|
10
|
+
"homepage": "https://mastra.ai",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/mastra-ai/mastra.git",
|
|
14
|
+
"directory": "packages/evals"
|
|
15
|
+
},
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/mastra-ai/mastra/issues"
|
|
18
|
+
},
|
|
9
19
|
"main": "dist/index.js",
|
|
10
20
|
"types": "dist/index.d.ts",
|
|
11
21
|
"exports": {
|
|
@@ -100,10 +110,10 @@
|
|
|
100
110
|
"tsup": "^8.5.0",
|
|
101
111
|
"typescript": "^5.8.3",
|
|
102
112
|
"vitest": "^3.2.4",
|
|
103
|
-
"zod": "^3.25.
|
|
104
|
-
"@
|
|
113
|
+
"zod": "^3.25.76",
|
|
114
|
+
"@internal/lint": "0.0.34",
|
|
105
115
|
"@internal/types-builder": "0.0.9",
|
|
106
|
-
"@
|
|
116
|
+
"@mastra/core": "0.15.3-alpha.5"
|
|
107
117
|
},
|
|
108
118
|
"scripts": {
|
|
109
119
|
"check": "tsc --noEmit",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/scorers/utils.ts"],"names":[],"mappings":";AAIO,IAAM,kBAAA,GAAqB,CAAC,GAAA,KAAgB;AACjD,EAAA,OAAO,KAAK,KAAA,CAAA,CAAO,GAAA,GAAM,MAAA,CAAO,OAAA,IAAW,GAAG,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AAA,OAAO,EAAE,KAAA,EAAO,SAAA,EAAW,aAAA,EAAc;AAC3C","file":"chunk-5CVZXIFW.js","sourcesContent":["import { RuntimeContext } from '@mastra/core/runtime-context';\nimport type { ScorerRunInputForAgent, ScorerRunOutputForAgent, ScoringInput } from '@mastra/core/scores';\nimport type { ToolInvocation, UIMessage } from 'ai';\n\nexport const roundToTwoDecimals = (num: number) => {\n return Math.round((num + Number.EPSILON) * 100) / 100;\n};\n\nexport function isCloserTo(value: number, target1: number, target2: number): boolean {\n return Math.abs(value - target1) < Math.abs(value - target2);\n}\n\nexport type TestCase = {\n input: string;\n output: string;\n expectedResult: {\n score: number;\n reason?: string;\n };\n};\n\nexport type TestCaseWithContext = TestCase & {\n context: string[];\n};\n\nexport const createTestRun = (input: string, output: string, context?: string[]): ScoringInput => {\n return {\n input: [{ role: 'user', content: input }],\n output: { role: 'assistant', text: output },\n additionalContext: { context },\n runtimeContext: {},\n };\n};\n\nexport const getUserMessageFromRunInput = (input?: ScorerRunInputForAgent) => {\n return input?.inputMessages.find(({ role }) => role === 'user')?.content;\n};\n\nexport const getAssistantMessageFromRunOutput = (output?: ScorerRunOutputForAgent) => {\n return output?.find(({ role }) => role === 'assistant')?.content;\n};\n\nexport const createToolInvocation = ({\n toolCallId,\n toolName,\n args,\n result,\n state = 'result',\n}: {\n toolCallId: string;\n toolName: string;\n args: Record<string, any>;\n result: Record<string, any>;\n state?: ToolInvocation['state'];\n}): { toolCallId: string; toolName: string; args: Record<string, any>; result: Record<string, any>; state: string } => {\n return {\n toolCallId,\n toolName,\n args,\n result,\n state,\n };\n};\n\nexport const createUIMessage = ({\n content,\n role,\n id = 'test-message',\n toolInvocations = [],\n}: {\n id: string;\n role: 'user' | 'assistant' | 'system';\n content: string;\n toolInvocations?: Array<{\n toolCallId: string;\n toolName: string;\n args: Record<string, any>;\n result: Record<string, any>;\n state: any;\n }>;\n}): UIMessage => {\n return {\n id,\n role,\n content,\n parts: [{ type: 'text', text: content }],\n toolInvocations,\n };\n};\n\nexport const createAgentTestRun = ({\n inputMessages = [],\n output,\n rememberedMessages = [],\n systemMessages = [],\n taggedSystemMessages = {},\n runtimeContext = new RuntimeContext(),\n runId = crypto.randomUUID(),\n}: {\n inputMessages?: ScorerRunInputForAgent['inputMessages'];\n output: ScorerRunOutputForAgent;\n rememberedMessages?: ScorerRunInputForAgent['rememberedMessages'];\n systemMessages?: ScorerRunInputForAgent['systemMessages'];\n taggedSystemMessages?: ScorerRunInputForAgent['taggedSystemMessages'];\n runtimeContext?: RuntimeContext;\n runId?: string;\n}): {\n input: ScorerRunInputForAgent;\n output: ScorerRunOutputForAgent;\n runtimeContext: RuntimeContext;\n runId: string;\n} => {\n return {\n input: {\n inputMessages,\n rememberedMessages,\n systemMessages,\n taggedSystemMessages,\n },\n output,\n runtimeContext,\n runId,\n };\n};\n\nexport type ToolCallInfo = {\n toolName: string;\n toolCallId: string;\n messageIndex: number;\n invocationIndex: number;\n};\n\nexport function extractToolCalls(output: ScorerRunOutputForAgent): { tools: string[]; toolCallInfos: ToolCallInfo[] } {\n const toolCalls: string[] = [];\n const toolCallInfos: ToolCallInfo[] = [];\n\n for (let messageIndex = 0; messageIndex < output.length; messageIndex++) {\n const message = output[messageIndex];\n if (message?.toolInvocations) {\n for (let invocationIndex = 0; invocationIndex < message.toolInvocations.length; invocationIndex++) {\n const invocation = message.toolInvocations[invocationIndex];\n if (invocation && invocation.toolName && (invocation.state === 'result' || invocation.state === 'call')) {\n toolCalls.push(invocation.toolName);\n toolCallInfos.push({\n toolName: invocation.toolName,\n toolCallId: invocation.toolCallId || `${messageIndex}-${invocationIndex}`,\n messageIndex,\n invocationIndex,\n });\n }\n }\n }\n }\n\n return { tools: toolCalls, toolCallInfos };\n}\n\nexport const extractInputMessages = (runInput: ScorerRunInputForAgent | undefined): string[] => {\n return runInput?.inputMessages?.map(msg => msg.content) || [];\n};\n\nexport const extractAgentResponseMessages = (runOutput: ScorerRunOutputForAgent): string[] => {\n return runOutput.filter(msg =>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,UAAA,aAAA,CAAc,IAAA,CAAK;AAAA,YACjB,UAAU,UAAA,CAAW,QAAA;AAAA,YACrB,YAAY,UAAA,CAAW,UAAA,IAAc,CAAA,EAAG,YAAY,IAAI,eAAe,CAAA,CAAA;AAAA,YACvE,YAAA;AAAA,YACA;AAAA,WACD,CAAA;AAAA,QACH;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,EAAA,OAAO,EAAE,KAAA,EAAO,SAAA,EAAW,aAAA,EAAc;AAC3C","file":"chunk-QVZBKGOE.cjs","sourcesContent":["import { RuntimeContext } from '@mastra/core/runtime-context';\nimport type { ScorerRunInputForAgent, ScorerRunOutputForAgent, ScoringInput } from '@mastra/core/scores';\nimport type { ToolInvocation, UIMessage } from 'ai';\n\nexport const roundToTwoDecimals = (num: number) => {\n return Math.round((num + Number.EPSILON) * 100) / 100;\n};\n\nexport function isCloserTo(value: number, target1: number, target2: number): boolean {\n return Math.abs(value - target1) < Math.abs(value - target2);\n}\n\nexport type TestCase = {\n input: string;\n output: string;\n expectedResult: {\n score: number;\n reason?: string;\n };\n};\n\nexport type TestCaseWithContext = TestCase & {\n context: string[];\n};\n\nexport const createTestRun = (input: string, output: string, context?: string[]): ScoringInput => {\n return {\n input: [{ role: 'user', content: input }],\n output: { role: 'assistant', text: output },\n additionalContext: { context },\n runtimeContext: {},\n };\n};\n\nexport const getUserMessageFromRunInput = (input?: ScorerRunInputForAgent) => {\n return input?.inputMessages.find(({ role }) => role === 'user')?.content;\n};\n\nexport const getAssistantMessageFromRunOutput = (output?: ScorerRunOutputForAgent) => {\n return output?.find(({ role }) => role === 'assistant')?.content;\n};\n\nexport const createToolInvocation = ({\n toolCallId,\n toolName,\n args,\n result,\n state = 'result',\n}: {\n toolCallId: string;\n toolName: string;\n args: Record<string, any>;\n result: Record<string, any>;\n state?: ToolInvocation['state'];\n}): { toolCallId: string; toolName: string; args: Record<string, any>; result: Record<string, any>; state: string } => {\n return {\n toolCallId,\n toolName,\n args,\n result,\n state,\n };\n};\n\nexport const createUIMessage = ({\n content,\n role,\n id = 'test-message',\n toolInvocations = [],\n}: {\n id: string;\n role: 'user' | 'assistant' | 'system';\n content: string;\n toolInvocations?: Array<{\n toolCallId: string;\n toolName: string;\n args: Record<string, any>;\n result: Record<string, any>;\n state: any;\n }>;\n}): UIMessage => {\n return {\n id,\n role,\n content,\n parts: [{ type: 'text', text: content }],\n toolInvocations,\n };\n};\n\nexport const createAgentTestRun = ({\n inputMessages = [],\n output,\n rememberedMessages = [],\n systemMessages = [],\n taggedSystemMessages = {},\n runtimeContext = new RuntimeContext(),\n runId = crypto.randomUUID(),\n}: {\n inputMessages?: ScorerRunInputForAgent['inputMessages'];\n output: ScorerRunOutputForAgent;\n rememberedMessages?: ScorerRunInputForAgent['rememberedMessages'];\n systemMessages?: ScorerRunInputForAgent['systemMessages'];\n taggedSystemMessages?: ScorerRunInputForAgent['taggedSystemMessages'];\n runtimeContext?: RuntimeContext;\n runId?: string;\n}): {\n input: ScorerRunInputForAgent;\n output: ScorerRunOutputForAgent;\n runtimeContext: RuntimeContext;\n runId: string;\n} => {\n return {\n input: {\n inputMessages,\n rememberedMessages,\n systemMessages,\n taggedSystemMessages,\n },\n output,\n runtimeContext,\n runId,\n };\n};\n\nexport type ToolCallInfo = {\n toolName: string;\n toolCallId: string;\n messageIndex: number;\n invocationIndex: number;\n};\n\nexport function extractToolCalls(output: ScorerRunOutputForAgent): { tools: string[]; toolCallInfos: ToolCallInfo[] } {\n const toolCalls: string[] = [];\n const toolCallInfos: ToolCallInfo[] = [];\n\n for (let messageIndex = 0; messageIndex < output.length; messageIndex++) {\n const message = output[messageIndex];\n if (message?.toolInvocations) {\n for (let invocationIndex = 0; invocationIndex < message.toolInvocations.length; invocationIndex++) {\n const invocation = message.toolInvocations[invocationIndex];\n if (invocation && invocation.toolName && (invocation.state === 'result' || invocation.state === 'call')) {\n toolCalls.push(invocation.toolName);\n toolCallInfos.push({\n toolName: invocation.toolName,\n toolCallId: invocation.toolCallId || `${messageIndex}-${invocationIndex}`,\n messageIndex,\n invocationIndex,\n });\n }\n }\n }\n }\n\n return { tools: toolCalls, toolCallInfos };\n}\n\nexport const extractInputMessages = (runInput: ScorerRunInputForAgent | undefined): string[] => {\n return runInput?.inputMessages?.map(msg => msg.content) || [];\n};\n\nexport const extractAgentResponseMessages = (runOutput: ScorerRunOutputForAgent): string[] => {\n return runOutput.filter(msg => msg.role === 'assistant').map(msg => msg.content);\n};\n"]}
|