UNPKG

@mastra/core

Version:
66 lines 2.29 kB
import { z } from 'zod/v4'; /** * The predicate Zod schema. We define it via `z.lazy` so the recursive * `and` / `or` / `not` branches can reference the top-level type. */ export declare const predicateSchema: z.ZodType<Predicate>; export type PathOrLiteral = { path: string; } | { literal: string | number | boolean | null; }; export type Predicate = { op: 'eq' | 'ne' | 'lt' | 'lte' | 'gt' | 'gte'; left: PathOrLiteral; right: PathOrLiteral; } | { op: 'in' | 'notIn'; value: PathOrLiteral; set: Array<string | number | boolean | null>; } | { op: 'exists' | 'notExists'; path: string; } | { op: 'truthy' | 'falsy'; value: PathOrLiteral; } | { op: 'and' | 'or'; args: Predicate[]; } | { op: 'not'; arg: Predicate; }; /** * Runtime context a predicate can reference. Exposes the same roots that * mapping templates and `${...}` placeholders see. */ export interface PredicateContext { initData?: unknown; inputData?: unknown; state?: unknown; /** * Pre-materialized step-results map. Predicates prefer this when present. * If absent, `getStepResult` is used to look values up on demand — that * form matches the shape a workflow condition callback exposes at runtime. */ stepResults?: Record<string, unknown>; getStepResult?: (stepId: string) => unknown; } /** * Evaluate a predicate against a context. Never throws for path resolution * failures — missing paths propagate to `false` on comparison/membership ops, * and to `false` / `true` on `exists` / `notExists` respectively. * * Throws only if the predicate shape itself is malformed (which * `predicateSchema.parse` catches at load time). */ export declare function evaluatePredicate(pred: Predicate, ctx: PredicateContext): boolean; /** * Produce a short human-readable label for a predicate, suitable for * rendering as a condition-node label in the workflow graph UI. * Bounded output length; no user-controlled text is passed through * unescaped — every string literal goes through JSON.stringify so a * malicious label can't break out of the surrounding rendering. */ export declare function derivePredicateLabel(pred: Predicate, maxLength?: number): string; //# sourceMappingURL=index.d.ts.map