/** * Fallback Resolution Patterns for Human Decisions * * This module provides primitives for: * - Decision logging with full context and audit trail * - Feedback loops for AI model improvement * - Fallback chains for human escalation * - Decision analytics and pattern detection */ import type { HumanStore } from './types.js'; /** * Context for a decision */ export interface DecisionContext { /** The original request ID */ requestId: string; /** Type of request (approval, review, decision, etc.) */ requestType: string; /** AI's suggested decision (if any) */ aiSuggestion?: string; /** AI's confidence in its suggestion (0-1) */ aiConfidence?: number; /** Original input data for the decision */ inputData: unknown; /** Timestamp of the original request */ timestamp: Date; } /** * A logged decision with full context */ export interface DecisionLog { /** Unique decision ID */ id: string; /** Who made the decision */ decisionMaker: string; /** The decision made */ decision: string; /** Context of the decision */ context: DecisionContext; /** Human reasoning for the decision */ reasoning?: string; /** Additional metadata */ metadata?: Record; /** When the decision was made */ timestamp: Date; /** Version number for tracking updates */ version: number; /** Previous versions of this decision */ previousVersions?: Array<{ decision: string; reasoning?: string; timestamp: Date; }>; /** Whether this decision overrides AI suggestion */ isOverride: boolean; /** Override details if applicable */ overrideDetails?: { aiRecommendation: string; humanDecision: string; aiConfidence: number; }; } /** * Input for logging a decision */ export interface LogDecisionInput { decisionMaker: string; decision: string; context: DecisionContext; reasoning?: string; metadata?: Record; } /** * Compliance report filters */ export interface ComplianceReportFilters { overridesOnly?: boolean; decisionMaker?: string; startDate?: Date; endDate?: Date; } /** * Compliance report */ export interface ComplianceReport { totalDecisions: number; overrides: number; overrideRate: number; overrideDecisions: DecisionLog[]; } /** * Decision Logger for audit trail */ export declare class DecisionLogger { private decisions; private decisionsByRequest; private idCounter; /** * Generate a unique decision ID */ private generateId; /** * Check if decision is an override of AI suggestion */ private isOverrideDecision; /** * Normalize decision string for comparison */ private normalizeDecision; /** * Log a human decision with full context */ logDecision(input: LogDecisionInput): DecisionLog; /** * Update an existing decision (creates new version) */ updateDecision(id: string, updates: { decision: string; reasoning?: string; }): DecisionLog; /** * Get decision history for a request */ getDecisionHistory(requestId: string): DecisionLog[]; /** * Query decisions by date range */ queryByDateRange(startDate: Date, endDate: Date): DecisionLog[]; /** * Get compliance report */ getComplianceReport(filters?: ComplianceReportFilters): ComplianceReport; /** * Get all decisions (for analytics) */ getAllDecisions(): DecisionLog[]; /** * Get decision by ID */ getDecision(id: string): DecisionLog | undefined; /** * Clear all decisions (for testing) */ clear(): void; } /** * Feedback signal for AI model improvement */ export interface FeedbackSignal { /** Unique signal ID */ id: string; /** Type of signal */ type: 'reinforcement' | 'correction'; /** The correct label from human decision */ label: string; /** Weight of this signal for training */ weight: number; /** Training data */ trainingData: { input: unknown; output?: unknown; correction?: string; }; /** When the signal was generated */ timestamp: Date; } /** * Input for generating a feedback signal */ export interface GenerateSignalInput { decisionId: string; requestId: string; inputData: unknown; aiPrediction: string; aiConfidence?: number; humanDecision: string; outcome: 'correct' | 'override' | 'unknown'; reasoning?: string; } /** * Training batch */ export interface TrainingBatch { signals: FeedbackSignal[]; stats: { totalSignals: number; corrections: number; reinforcements: number; }; } /** * Accuracy metrics */ export interface AccuracyMetrics { overallAccuracy: number; totalDecisions: number; correctPredictions: number; } /** * Feedback Loop for AI model improvement */ export declare class FeedbackLoop { private signals; private idCounter; /** * Generate a unique signal ID */ private generateId; /** * Generate a training signal from a human decision */ generateSignal(input: GenerateSignalInput): FeedbackSignal; /** * Get training batch */ getTrainingBatch(options?: { minSize?: number; }): TrainingBatch; /** * Export signals in standard ML format */ exportForTraining(format?: 'jsonl' | 'json'): string; /** * Get accuracy metrics */ getAccuracyMetrics(): AccuracyMetrics; /** * Clear all signals (for testing) */ clear(): void; } /** * Fallback handler definition */ export interface FallbackHandler { /** Handler ID */ id: string; /** Handler name */ name?: string; /** Who handles requests at this level */ assignee: string; /** Function to determine if handler can handle the context */ canHandle: (context: Record) => boolean; /** Timeout in milliseconds before escalating */ timeout: number; /** Priority (lower = higher priority) */ priority: number; } /** * Escalation record */ export interface EscalationRecord { from: string; to: string; reason: string; timestamp: Date; } /** * Escalation audit */ export interface EscalationAudit { requestId: string; escalations: EscalationRecord[]; finalHandler?: string; completed: boolean; } /** * Execute with fallback result */ export interface ExecuteWithFallbackResult { handlerUsed: string; escalated: boolean; escalationPath: string[]; response?: unknown; } /** * Fallback Chain for human escalation */ export declare class FallbackChain { private handlers; private store?; private escalationAudits; /** * Set the store for request management */ setStore(store: HumanStore): void; /** * Add a handler to the chain */ addHandler(handler: FallbackHandler): void; /** * Get all handlers */ getHandlers(): FallbackHandler[]; /** * Find the appropriate handler for a context */ findHandler(context: Record): FallbackHandler | undefined; /** * Execute request with fallback chain */ executeWithFallback(options: { requestId: string; context: Record; simulateTimeout?: boolean; maxEscalations?: number; }): Promise; /** * Get escalation audit for a request */ getEscalationAudit(requestId: string): EscalationAudit; /** * Clear all handlers (for testing) */ clear(): void; } /** * Decision pattern */ export interface DecisionPattern { type: string; description: string; confidence: number; occurrences: number; examples?: string[]; } /** * Time-based patterns */ export interface TimePatterns { peakApprovalDay: string; approvalsByDay: Record; } /** * Dashboard data */ export interface DashboardData { totalDecisions: number; approvalRate: number; overrideRate: number; averageResponseTime: number; topDecisionMakers: Array<{ name: string; count: number; }>; } /** * Decision Analytics for pattern detection */ export declare class DecisionAnalytics { private logger; constructor(logger: DecisionLogger); /** * Detect decision patterns for a decision maker */ detectPatterns(options: { decisionMaker?: string; minOccurrences?: number; }): DecisionPattern[]; /** * Detect time-based patterns */ detectTimePatterns(decisionMaker: string): TimePatterns; /** * Get consistency score for a decision maker */ getConsistencyScore(decisionMaker: string): number; /** * Get dashboard data */ getDashboardData(): DashboardData; /** * Export decision data for training */ exportForTraining(options: { format?: 'jsonl' | 'json'; includeContext?: boolean; }): string; } //# sourceMappingURL=fallback-resolution.d.ts.map