/** * Types for Human-in-the-Loop Pattern */ import { AsyncFunction, Logger } from "./common"; /** * Escalation reasons */ export declare enum EscalationReason { /** * AI confidence is too low */ LOW_CONFIDENCE = "LOW_CONFIDENCE", /** * Operation timed out */ TIMEOUT = "TIMEOUT", /** * Operation encountered an error */ ERROR = "ERROR", /** * Sensitive content detected */ SENSITIVE_CONTENT = "SENSITIVE_CONTENT", /** * Keyword detected in input/output */ KEYWORD_DETECTED = "KEYWORD_DETECTED", /** * Manual escalation requested */ MANUAL_REQUEST = "MANUAL_REQUEST", /** * Custom escalation reason */ CUSTOM = "CUSTOM" } /** * Review status */ export declare enum ReviewStatus { /** * Review is pending */ PENDING = "PENDING", /** * Review approved */ APPROVED = "APPROVED", /** * Review rejected */ REJECTED = "REJECTED", /** * Review modified */ MODIFIED = "MODIFIED" } /** * Timeout fallback behavior */ export declare enum TimeoutFallback { /** * Use AI output on timeout */ USE_AI = "USE_AI", /** * Throw error on timeout */ THROW = "THROW", /** * Retry escalation on timeout */ RETRY = "RETRY" } /** * Escalation rule */ export interface EscalationRule { /** * Rule name */ name: string; /** * Function to determine if escalation is needed */ shouldEscalate: (input: TInput, output?: TOutput, error?: Error) => boolean | Promise; /** * Escalation reason */ reason: EscalationReason; /** * Priority (higher = more important) */ priority?: number; } /** * Human review request */ export interface HumanReview { /** * Unique review ID */ id: string; /** * Original input */ input: TInput; /** * AI output (if available) */ aiOutput?: TOutput; /** * Escalation reason */ reason: EscalationReason; /** * Additional metadata */ metadata?: Record; /** * Creation timestamp */ createdAt: number; /** * Review status */ status: ReviewStatus; /** * Final output (after human review) */ humanOutput?: TOutput; /** * Human notes */ notes?: string; /** * Resolution timestamp */ resolvedAt?: number; } /** * Options for human-in-the-loop */ export interface HumanInTheLoopOptions { /** * AI function to execute */ execute: AsyncFunction; /** * Input for tracking purposes (optional, for metadata) */ input?: TInput; /** * Escalation rules */ escalationRules?: EscalationRule[]; /** * Timeout for human review (ms) * @default 300000 (5 minutes) */ reviewTimeout?: number; /** * Function to request human review * Must return the review result */ requestHumanReview: (review: HumanReview) => Promise; /** * Callback on escalation */ onEscalate?: (review: HumanReview) => void; /** * Callback after review complete */ onReviewComplete?: (review: HumanReview) => void; /** * Logger */ logger?: Logger; /** * Fallback mode on review timeout * @default TimeoutFallback.THROW */ timeoutFallback?: TimeoutFallback; } /** * Result from human-in-the-loop pattern */ export interface HumanInTheLoopResult { /** * The final output value */ value: TOutput; /** * Whether escalation occurred */ escalated: boolean; /** * Escalation reason (if escalated) */ escalationReason?: EscalationReason; } /** * Common escalation rules for typical scenarios */ export declare const CommonEscalationRules: { /** * Escalate if confidence is low */ lowConfidence: (threshold?: number) => EscalationRule; /** * Escalate if sensitive keywords detected in input or output */ sensitiveKeywords: (keywords: string[]) => EscalationRule; /** * Escalate on error */ onError: () => EscalationRule; /** * Custom escalation rule */ custom: (name: string, fn: (input: TInput, output?: TOutput) => boolean | Promise, priority?: number) => EscalationRule; }; //# sourceMappingURL=human-in-the-loop.d.ts.map