/** * Runtime execution helpers for guardrails. * * This module provides the bridge between configuration and runtime execution for * guardrail validation. */ import type { GuardrailSpec } from './spec'; import type { GuardrailResult, TContext, TextInput, TIn } from './types'; /** * Configuration for a single guardrail instance. */ export interface GuardrailConfig { /** The registry name used to look up the guardrail spec. */ name: string; /** Configuration object for this guardrail instance. */ config: Record; } /** * A guardrail bundle containing multiple guardrails. */ export interface GuardrailBundle { /** Version of the bundle format. */ version?: number; /** Name of the stage this bundle applies to. */ stageName?: string; /** Array of guardrail configurations. */ guardrails: GuardrailConfig[]; } /** * Pipeline configuration structure. */ export interface PipelineConfig { version?: number; pre_flight?: GuardrailBundle; input?: GuardrailBundle; output?: GuardrailBundle; } /** * A configured, executable guardrail. * * This class binds a `GuardrailSpec` definition to a validated configuration * object. The resulting instance is used to run guardrail logic in production * pipelines. It supports both sync and async check functions. */ export declare class ConfiguredGuardrail { readonly definition: GuardrailSpec; readonly config: TCfg; constructor(definition: GuardrailSpec, config: TCfg); /** * Ensure a guardrail function is executed asynchronously. * * If the function is sync, runs it in a Promise.resolve for compatibility with async flows. * If already async, simply awaits it. Used internally to normalize execution style. * * @param fn Guardrail check function (sync or async). * @param args Arguments for the check function. * @returns Promise resolving to the result of the check function. */ private ensureAsync; /** * Run the guardrail's check function with the provided context and data. * * Main entry point for executing guardrails. Supports both sync and async * functions, ensuring results are always awaited. * * @param ctx Runtime context for the guardrail. * @param data Input value to be checked. * @returns Promise resolving to the outcome of the guardrail logic. */ run(ctx: TContext, data: TIn): Promise; } /** * Run a single guardrail bundle on plain text input. * * This is a high-level convenience function that loads a bundle configuration * and runs all guardrails in parallel, throwing an exception if any tripwire * is triggered. * * @param text Input text to validate. * @param bundle Guardrail bundle configuration. * @param context Optional context object for the guardrails. * @throws {Error} If any guardrail tripwire is triggered. */ export declare function checkPlainText(text: string, bundle: GuardrailBundle, context?: TContext): Promise; /** * Run multiple guardrails in parallel and return all results. * * This function orchestrates the execution of multiple guardrails, * running them concurrently for better performance. * * @param data Input data to validate. * @param bundle Guardrail bundle configuration. * @param context Optional context object for the guardrails. * @param raiseGuardrailErrors If true, raise exceptions when guardrails fail to execute. * @returns Array of guardrail results. */ export declare function runGuardrails(data: TIn, bundle: GuardrailBundle, context?: TContext, raiseGuardrailErrors?: boolean): Promise; /** * Instantiate guardrails from a bundle configuration. * * Creates configured guardrail instances from a bundle specification, * validating configurations against their schemas. * * @param bundle Guardrail bundle configuration. * @returns Array of configured guardrail instances. */ export declare function instantiateGuardrails(bundle: GuardrailBundle): Promise; /** * Load a guardrail bundle configuration from a JSON string. * * @param jsonString JSON string containing bundle configuration. * @returns Parsed guardrail bundle. */ export declare function loadConfigBundle(jsonString: string): GuardrailBundle; /** * Load a guardrail bundle configuration from a file. * * Note: This function requires Node.js fs module and will only work in Node.js environments. * * @param filePath Path to the JSON configuration file. * @returns Parsed guardrail bundle. */ export declare function loadConfigBundleFromFile(filePath: string): Promise; /** * Load pipeline configuration from string or object. * * @param config Pipeline configuration as string or object * @returns Parsed pipeline configuration */ export declare function loadPipelineBundles(config: string | PipelineConfig): Promise; //# sourceMappingURL=runtime.d.ts.map