UNPKG

@mastra/core

Version:
45 lines • 2.23 kB
import type { Predicate } from '../predicate/index.js'; /** * Scoring target for the shared predicate DSL (`core/src/predicate`). * * A scorer binding can declare a `filter` predicate that decides whether a * given run qualifies for scoring. Filters are evaluated before sampling, so * the sampling rate applies to qualifying traffic only (filter → sample). * * Deliberately excluded roots: `input` and `output`. Output-dependent * predicates can't be evaluated against stored records at query time, which * would break rule preview / backfill before it exists. */ export declare const SCORING_PREDICATE_ROOTS: readonly ['requestContext', 'entity', 'entityType', 'source', 'threadId', 'resourceId', 'projectId']; /** A scoring eligibility filter — a predicate over `ScoringPredicateContext`. */ export type ScoringFilter = Predicate; /** Context a scoring filter predicate can reference. */ export interface ScoringPredicateContext { /** * The flattened request context (primitive values keyed by dot-joined flat * keys, e.g. `"user.tier"`), matching what is persisted on score rows. * Nested objects are also supported for callers that haven't flattened. */ requestContext?: Record<string, unknown>; entity?: Record<string, unknown>; entityType?: string; source?: string; threadId?: string; resourceId?: string; projectId?: string; } /** * Evaluate a scoring filter against a scoring context. Never throws for path * resolution failures — missing paths propagate to `false` on comparison ops * and `in` (fail closed: an unresolvable filter does not score), but to * `true` on the negated ops `notIn` and `notExists` (a missing value is * trivially "not in" any set), and to `false` on `exists`. */ export declare const evaluateScoringPredicate: (pred: Predicate, ctx: ScoringPredicateContext) => boolean; /** * Validate a scoring filter at definition time. Throws if any referenced path * doesn't start with a known scoring root, so typos fail loud when the * binding is registered instead of silently skipping all scoring at runtime. */ export declare function validateScoringPredicate(pred: Predicate): void; //# sourceMappingURL=predicate.d.ts.map