import { z } from 'zod/v4'; import type { MastraModelConfig } from '../llm/model/shared.types.js'; import type { Mastra } from '../mastra/index.js'; import { EntityType } from '../observability/index.js'; import type { CorrelationContext, DefinitionSource, ObservabilityContext, ScorerScoreSource, ScorerStepType, ScorerTargetScope } from '../observability/index.js'; import { RequestContext } from '../request-context/index.js'; import type { PublicSchema } from '../schema/index.js'; import type { ScoringSamplingConfig, ScorerRunInputForAgent, ScorerRunOutputForAgent, Trajectory, TrajectoryExpectation } from './types.js'; interface ScorerStepDefinition { name: string; definition: any; isPromptObject: boolean; } type ScorerTypeShortcuts = { agent: { input: ScorerRunInputForAgent; output: ScorerRunOutputForAgent; }; trajectory: { input: ScorerRunInputForAgent; output: Trajectory; }; }; interface ScorerConfig { id: TID; name?: string; description: string; judge?: { model: MastraModelConfig; instructions: string; }; type?: keyof ScorerTypeShortcuts | { input: z.ZodSchema; output: z.ZodSchema; }; } interface ScorerRun { /** Unique ID for this scorer execution. Generated by scorer.run() when omitted. */ runId?: string; /** Primary scorer input. This is often model input/messages, but can be any structured value. */ input?: TInput; /** Primary scorer target output. This is the required value the scorer evaluates. */ output: TOutput; /** Optional expected label/reference value for judged or supervised evaluations. */ groundTruth?: any; /** Expected trajectory config for trajectory scorers. Flows from dataset items or scorer constructor. */ expectedTrajectory?: TrajectoryExpectation; /** Optional request context forwarded to scorers and judge prompts. */ requestContext?: Record | RequestContext; /** What kind of scoring flow produced this score, such as live runs, trace scoring, or experiments. */ scoreSource?: ScorerScoreSource; /** * How the scorer interpreted the target data. * `span` means a single span's input/output was scored. * `trajectory` means a trajectory/path was scored. */ targetScope?: ScorerTargetScope; /** Entity type of the scored target when known. */ targetEntityType?: EntityType; /** Trace anchor for the target being scored when available. */ targetTraceId?: string; /** Optional span anchor for the target being scored. */ targetSpanId?: string; /** Live correlation snapshot for the target span/trace when available. */ targetCorrelationContext?: CorrelationContext; /** Live target metadata to merge into emitted score metadata when available. */ targetMetadata?: Record; } interface PromptObject, TStepName extends string = string, TInput = any, TRunOutput = any> { description: string; /** * Schema defining the expected output structure. * Accepts any schema type supported by Mastra (Zod v4, JSON Schema, AI SDK Schema, or StandardSchema). * Will be converted to StandardSchemaWithJSON at runtime via toStandardSchema(). * * The TOutput generic is inferred from this schema's output type. */ outputSchema: PublicSchema; judge?: { model: MastraModelConfig; instructions: string; }; createPrompt: (context: PromptObjectContext) => string | Promise; } type StepResultKey = `${T}StepResult`; type Awaited = T extends Promise ? U : T; type StepContext, TInput, TRunOutput> = Partial & { run: ScorerRun; results: TAccumulated; }; type AccumulatedResults, K extends string, V> = T & Record, V>; type GenerateReasonContext, TInput, TRunOutput> = StepContext & { score: TAccumulated extends Record<'generateScoreStepResult', infer TScore> ? TScore : never; }; type ScorerRunResult, TInput, TRunOutput> = Promise & { scoreTraceId?: string; score: TAccumulatedResults extends Record<'generateScoreStepResult', infer TScore> ? TScore : never; reason?: TAccumulatedResults extends Record<'generateReasonStepResult', infer TReason> ? TReason : undefined; preprocessPrompt?: string; analyzePrompt?: string; generateScorePrompt?: string; generateReasonPrompt?: string; preprocessStepResult?: TAccumulatedResults extends Record<'preprocessStepResult', infer TPreprocess> ? TPreprocess : undefined; analyzeStepResult?: TAccumulatedResults extends Record<'analyzeStepResult', infer TAnalyze> ? TAnalyze : undefined; } & { runId: string; }>; type PromptObjectContext, TStepName extends string, TInput, TRunOutput> = TStepName extends 'generateReason' ? GenerateReasonContext : StepContext; type FunctionStep, TInput, TRunOutput, TOutput> = ((context: StepContext) => TOutput) | ((context: StepContext) => Promise); type GenerateReasonFunctionStep, TInput, TRunOutput> = ((context: GenerateReasonContext) => any) | ((context: GenerateReasonContext) => Promise); type GenerateScoreFunctionStep, TInput, TRunOutput> = ((context: StepContext) => number) | ((context: StepContext) => Promise); interface GenerateScorePromptObject, TInput, TRunOutput> { description: string; judge?: { model: MastraModelConfig; instructions: string; }; createPrompt: (context: StepContext) => string | Promise; } interface GenerateReasonPromptObject, TInput, TRunOutput> { description: string; judge?: { model: MastraModelConfig; instructions: string; }; createPrompt: (context: GenerateReasonContext) => string | Promise; } type PreprocessStepDef, TStepOutput, TInput, TRunOutput> = FunctionStep | (PromptObject & { outputSchema: PublicSchema; }); type AnalyzeStepDef, TStepOutput, TInput, TRunOutput> = FunctionStep | (PromptObject & { outputSchema: PublicSchema; }); type GenerateScoreStepDef, TInput, TRunOutput> = GenerateScoreFunctionStep | GenerateScorePromptObject; type GenerateReasonStepDef, TInput, TRunOutput> = GenerateReasonFunctionStep | GenerateReasonPromptObject; declare class MastraScorer = {}> { #private; config: ScorerConfig; private steps; private originalPromptObjects; /** * Tracks whether this scorer was defined in code or loaded from storage. * Set by `Mastra.addScorer()` when the `source` option is provided. */ source?: DefinitionSource; constructor(config: ScorerConfig, steps?: Array, originalPromptObjects?: Map | GenerateReasonPromptObject | GenerateScorePromptObject>, mastra?: Mastra); /** * Registers the Mastra instance with the scorer. * This enables access to custom gateways for model resolution. * @internal */ __registerMastra(mastra: Mastra): void; /** * Returns the raw storage configuration this scorer was created from, * or undefined if it was created from code. */ toRawConfig(): Record | undefined; /** * Sets the raw storage configuration for this scorer. * @internal */ __setRawConfig(rawConfig: Record): void; get type(): keyof ScorerTypeShortcuts | { input: z.ZodType>; output: z.ZodType>; } | undefined; get id(): TID; get name(): string; get description(): string; get judge(): { model: MastraModelConfig; instructions: string; } | undefined; preprocess(stepDef: PreprocessStepDef): MastraScorer>>; analyze(stepDef: AnalyzeStepDef): MastraScorer>>; generateScore(stepDef: GenerateScoreStepDef): MastraScorer>>; generateReason(stepDef: GenerateReasonStepDef): MastraScorer>>; private get hasGenerateScore(); private normalizeRunRequestContext; run(input: ScorerRun): ScorerRunResult; private isPromptObject; getSteps(): Array<{ name: string; type: ScorerStepType; description?: string; }>; private toMastraWorkflow; private createScorerContext; private executeFunctionStep; private executePromptStep; private transformToScorerResult; } export declare function createScorer(config: Omit, 'type'> & { type: TType; }): MastraScorer; export declare function createScorer(config: Omit, z.infer>, 'type'> & { type: { input: TInputSchema; output: TOutputSchema; }; }): MastraScorer, z.infer, {}>; export declare function createScorer(config: ScorerConfig): MastraScorer; export type MastraScorerEntry = { scorer: MastraScorer; sampling?: ScoringSamplingConfig; }; export type MastraScorers = Record; export type { ScorerConfig, ScorerRun, PromptObject }; export { MastraScorer }; //# sourceMappingURL=base.d.ts.map