/** * Adaptive Compliance Scoring Engine * * Computes and manages entity risk scores based on compliance history, * violations, and contextual factors (Enhancement #13). */ import type { EntityRiskScore as BaseEntityRiskScore, RiskFactor as BaseRiskFactor, RiskBand } from '@arka-protocol/types'; /** * Extended risk band with scoring metadata */ export interface RiskBandConfig { /** Band name matching RiskBand type */ name: RiskBand; /** Minimum score for this band */ minScore: number; /** Maximum score for this band */ maxScore: number; /** Display color */ color: string; /** Human-readable description */ description: string; } /** * Extended risk factor for internal computation */ export interface ComputedRiskFactor extends BaseRiskFactor { /** Factor identifier */ id: string; /** Factor category */ category: 'HISTORICAL' | 'BEHAVIORAL' | 'STRUCTURAL' | 'CONTEXTUAL' | 'EXTERNAL'; } /** * Extended entity risk score with additional metadata */ export interface EntityRiskScore extends Omit { /** Computed risk factors with extended info */ factors: ComputedRiskFactor[]; /** Confidence level in the score (0-1) */ confidence?: number; /** ISO timestamp of calculation */ calculatedAt: string; } /** * Risk factor definition */ export interface RiskFactorDefinition { /** Factor identifier */ id: string; /** Factor name */ name: string; /** Factor category */ category: 'HISTORICAL' | 'BEHAVIORAL' | 'STRUCTURAL' | 'CONTEXTUAL' | 'EXTERNAL'; /** Weight in overall score (0-1) */ weight: number; /** Function to compute factor value */ compute: (context: RiskComputeContext) => Promise; /** Whether this factor is enabled */ enabled: boolean; } /** * Context for computing risk factors */ export interface RiskComputeContext { /** Entity ID */ entityId: string; /** Entity type */ entityType: string; /** Entity data */ entityData: Record; /** Historical decisions */ decisions: DecisionHistory[]; /** Current timestamp */ timestamp: string; /** Jurisdiction */ jurisdiction?: string; /** Additional context */ additionalContext?: Record; } /** * Historical decision for risk calculation */ export interface DecisionHistory { /** Decision ID */ id: string; /** Rule ID */ ruleId: string; /** Decision type */ decision: 'ALLOW' | 'DENY' | 'FLAG'; /** Severity */ severity: string; /** Timestamp */ timestamp: string; /** Whether it was a violation */ isViolation: boolean; } /** * Scoring model configuration */ export interface ScoringModelConfig { /** Model name */ name: string; /** Risk bands */ bands: RiskBandConfig[]; /** Decay rate for historical factors (per day) */ historicalDecayRate: number; /** Maximum lookback period in days */ maxLookbackDays: number; /** Minimum decisions required for stable score */ minDecisionsForStableScore: number; /** Default score for new entities */ defaultScore: number; } /** * Score change event */ export interface ScoreChangeEvent { /** Entity ID */ entityId: string; /** Previous score */ previousScore: number; /** New score */ newScore: number; /** Previous band */ previousBand: string; /** New band */ newBand: string; /** Factors that contributed to change */ contributingFactors: Array<{ factorId: string; contribution: number; }>; /** Timestamp */ timestamp: string; } /** * Score listener */ export type ScoreChangeListener = (event: ScoreChangeEvent) => void; /** * Default risk bands */ export declare const DEFAULT_RISK_BANDS: RiskBandConfig[]; /** * Default scoring model */ export declare const DEFAULT_SCORING_MODEL: ScoringModelConfig; /** * Risk Scoring Engine */ export declare class RiskScoringEngine { private factors; private scores; private model; private listeners; constructor(model?: ScoringModelConfig); /** * Register a risk factor */ registerFactor(factor: RiskFactorDefinition): void; /** * Compute risk score for an entity */ computeScore(context: RiskComputeContext): Promise; /** * Get current score for an entity */ getScore(entityId: string): EntityRiskScore | undefined; /** * Get all scores */ getAllScores(): EntityRiskScore[]; /** * Get scores by band */ getScoresByBand(bandName: string): EntityRiskScore[]; /** * Get high-risk entities */ getHighRiskEntities(threshold?: number): EntityRiskScore[]; /** * Add score change listener */ onScoreChange(listener: ScoreChangeListener): void; /** * Remove score change listener */ offScoreChange(listener: ScoreChangeListener): void; /** * Update scoring model */ updateModel(model: Partial): void; /** * Get current model */ getModel(): ScoringModelConfig; /** * Get all registered factors */ getFactors(): RiskFactorDefinition[]; /** * Enable/disable a factor */ setFactorEnabled(factorId: string, enabled: boolean): void; /** * Batch compute scores for multiple entities */ computeBatchScores(contexts: RiskComputeContext[]): Promise>; private registerDefaultFactors; private getBandForScore; private calculateConfidence; private calculateTrend; private applyDecay; private getDaysSince; private emitScoreChange; } /** * Create a risk scoring engine */ export declare function createRiskScoringEngine(model?: ScoringModelConfig): RiskScoringEngine; //# sourceMappingURL=riskScoringEngine.d.ts.map