/** * Cascade Tier Registry for Failure Type Routing * * This module provides a registry for managing cascade tiers in AI failure handling. * Cascade tiers represent the hierarchy of handlers for AI failures: * - code: Automated code-based handlers (retry, fallback values) * - generative: AI/LLM-based handlers (regenerate, rephrase) * - agentic: AI agent handlers (autonomous problem solving) * - human: Human-in-the-loop handlers (manual intervention) */ import type { Priority } from './types.js'; /** * Failure types that can be routed to different tiers */ export type FailureType = string; /** * Failure pattern for matching multiple failure types */ export type FailurePattern = string | RegExp; /** * Result of a tier handler */ export interface TierHandlerResult { /** Whether the failure was handled */ handled: boolean; /** Result of handling (if successful) */ result?: unknown; /** Error message (if failed) */ error?: string; } /** * Failure information passed to tier handlers */ export interface FailureInfo { /** Type of failure */ type: FailureType; /** Error message */ message?: string; /** Original error */ error?: Error; /** Additional context */ context?: Record; } /** * Handler for processing failures within a tier */ export interface TierHandler { /** Check if this handler can handle the failure */ canHandle: (failure: FailureInfo) => boolean; /** Handle the failure */ handle: (failure: FailureInfo) => Promise; } /** * Configuration for a cascade tier */ export interface TierConfig { /** Display name for the tier */ name: string; /** Description of the tier's purpose */ description?: string; /** Priority level (lower = tried first) */ priority: number; /** Handlers for this tier */ handlers?: TierHandler[]; /** Custom availability check function */ availabilityCheck?: () => Promise; /** Additional metadata */ metadata?: Record; } /** * A registered cascade tier */ export interface CascadeTier extends TierConfig { /** Unique identifier for the tier */ id: string; } /** * Metrics for a tier */ export interface TierMetrics { /** Number of times this tier was used */ usageCount: number; /** Number of successful handlings */ successCount: number; /** Number of failed handlings */ failureCount: number; /** Success rate (0-1) */ successRate: number; /** Average duration in milliseconds */ avgDurationMs: number; /** Total duration in milliseconds (internal) */ totalDurationMs: number; } /** * Priority to tier mapping */ export type PriorityMapping = Record; /** * Registry for managing cascade tiers */ export declare class TierRegistry { private tiers; private failureMappings; private fallbackChains; private availability; private metrics; private autoFallbackEnabled; private priorityMapping; /** * Register a new tier or update an existing one */ registerTier(id: string, config: TierConfig): CascadeTier; /** * Get a tier by ID */ getTier(id: string): CascadeTier | undefined; /** * Unregister a tier */ unregisterTier(id: string): boolean; /** * List all registered tiers sorted by priority */ listTiers(): CascadeTier[]; /** * Map a failure type to a tier */ mapFailureToTier(failureType: FailurePattern, tierId: string): void; /** * Route a failure type to the appropriate tier */ routeToTier(failureType: FailureType): string | undefined; /** * Remove a failure type mapping */ unmapFailureType(failureType: FailurePattern): boolean; /** * Get all failure type mappings */ getFailureMappings(): Record; /** * Set the priority to tier mapping */ setPriorityMapping(mapping: Partial): void; /** * Get the tier for a given priority level */ getTierForPriority(priority: Priority): string | undefined; /** * Set the fallback chain for a tier */ setFallbackChain(tierId: string, fallbacks: string[]): void; /** * Get the fallback chain for a tier */ getFallbackChain(tierId: string): string[] | undefined; /** * Enable automatic fallback based on tier priority */ enableAutoFallback(): void; /** * Disable automatic fallback */ disableAutoFallback(): void; /** * Get the next fallback tier */ getNextFallback(tierId: string): string | undefined; /** * Get the full escalation path from a tier */ getEscalationPath(tierId: string): string[]; /** * Check if a tier is available */ isTierAvailable(tierId: string): boolean | undefined; /** * Set tier availability */ setTierAvailability(tierId: string, available: boolean): void; /** * Check tier availability using custom function if defined */ checkTierAvailability(tierId: string): Promise; /** * Get next available fallback tier */ getNextAvailableFallback(tierId: string): string | undefined; /** * Get all available tiers */ getAvailableTiers(): CascadeTier[]; /** * Record tier usage */ recordTierUsage(tierId: string, options?: { durationMs?: number; }): void; /** * Record tier result (success or failure) */ recordTierResult(tierId: string, success: boolean): void; /** * Get metrics for a tier */ getTierMetrics(tierId: string): TierMetrics | undefined; /** * Reset metrics for a tier */ resetTierMetrics(tierId: string): void; /** * Get all tier metrics */ getAllMetrics(): Record; /** * Create empty metrics object */ private createEmptyMetrics; } //# sourceMappingURL=tier-registry.d.ts.map