/**
 * AI Audit Trail
 * Comprehensive logging and compliance reporting for AI operations
 * Vorion Security Platform
 */
import { EventEmitter } from 'events';
import { AIAuditLogEntry, AIAuditAction, QueryAuditData, ResponseAuditData, TokenUsage, AuditMetadata, AuditLevel, ComplianceReport } from './types';
/**
 * Audit configuration
 */
export interface AuditConfig {
    enabled: boolean;
    defaultAuditLevel: AuditLevel;
    logQueries: boolean;
    logResponses: boolean;
    hashSensitiveData: boolean;
    retentionDays: number;
    maxEntriesInMemory: number;
    costPerInputToken: number;
    costPerOutputToken: number;
    currency: string;
    complianceFrameworks: string[];
    alertOnAnomalies: boolean;
    anomalyThresholds: AnomalyThresholds;
}
/**
 * Anomaly detection thresholds
 */
export interface AnomalyThresholds {
    maxQueriesPerMinute: number;
    maxTokensPerQuery: number;
    maxCostPerQuery: number;
    injectionRateThreshold: number;
}
/**
 * Audit query options
 */
export interface AuditQueryOptions {
    startDate?: Date;
    endDate?: Date;
    userId?: string;
    modelId?: string;
    action?: AIAuditAction | AIAuditAction[];
    sessionId?: string;
    limit?: number;
    offset?: number;
    sortBy?: 'timestamp' | 'cost' | 'tokens';
    sortOrder?: 'asc' | 'desc';
}
/**
 * Audit storage interface
 */
export interface AuditStorage {
    save(entry: AIAuditLogEntry): Promise<void>;
    get(id: string): Promise<AIAuditLogEntry | null>;
    query(options: AuditQueryOptions): Promise<AIAuditLogEntry[]>;
    count(options: AuditQueryOptions): Promise<number>;
    delete(id: string): Promise<void>;
    deleteOlderThan(date: Date): Promise<number>;
    getAggregatedStats(startDate: Date, endDate: Date): Promise<{
        totalQueries: number;
        totalTokens: number;
        totalCost: number;
        uniqueUsers: number;
        actionCounts: Record<string, number>;
    }>;
}
/**
 * In-memory audit storage implementation
 */
export declare class InMemoryAuditStorage implements AuditStorage {
    private entries;
    private maxEntries;
    constructor(maxEntries?: number);
    save(entry: AIAuditLogEntry): Promise<void>;
    get(id: string): Promise<AIAuditLogEntry | null>;
    query(options: AuditQueryOptions): Promise<AIAuditLogEntry[]>;
    count(options: AuditQueryOptions): Promise<number>;
    delete(id: string): Promise<void>;
    deleteOlderThan(date: Date): Promise<number>;
    getAggregatedStats(startDate: Date, endDate: Date): Promise<{
        totalQueries: number;
        totalTokens: number;
        totalCost: number;
        uniqueUsers: number;
        actionCounts: Record<string, number>;
    }>;
}
/**
 * AI Audit Trail Manager
 * Manages comprehensive audit logging for AI operations
 */
export declare class AuditTrail extends EventEmitter {
    private config;
    private storage;
    private recentQueries;
    constructor(config?: Partial<AuditConfig>, storage?: AuditStorage);
    /**
     * Generate a unique audit entry ID
     */
    private generateId;
    /**
     * Log a query
     */
    logQuery(params: {
        modelId: string;
        userId: string;
        sessionId: string;
        query: QueryAuditData;
        tokenUsage: TokenUsage;
        auditLevel?: AuditLevel;
        metadata?: Partial<AuditMetadata>;
        ipAddress?: string;
        userAgent?: string;
    }): Promise<AIAuditLogEntry>;
    /**
     * Log a response
     */
    logResponse(params: {
        modelId: string;
        userId: string;
        sessionId: string;
        response: ResponseAuditData;
        tokenUsage: TokenUsage;
        auditLevel?: AuditLevel;
        metadata?: Partial<AuditMetadata>;
    }): Promise<AIAuditLogEntry>;
    /**
     * Log a policy violation
     */
    logPolicyViolation(params: {
        modelId: string;
        userId: string;
        sessionId: string;
        violation: string;
        policyField: string;
        metadata?: Partial<AuditMetadata>;
        ipAddress?: string;
    }): Promise<AIAuditLogEntry>;
    /**
     * Log rate limit exceeded
     */
    logRateLimitExceeded(params: {
        modelId: string;
        userId: string;
        sessionId: string;
        limitType: string;
        currentUsage: number;
        limit: number;
        metadata?: Partial<AuditMetadata>;
    }): Promise<AIAuditLogEntry>;
    /**
     * Query audit logs
     */
    queryLogs(options: AuditQueryOptions): Promise<AIAuditLogEntry[]>;
    /**
     * Get audit entry by ID
     */
    getEntry(id: string): Promise<AIAuditLogEntry | null>;
    /**
     * Count audit entries
     */
    countEntries(options: AuditQueryOptions): Promise<number>;
    /**
     * Generate compliance report
     */
    generateComplianceReport(modelId: string, reportType: ComplianceReport['reportType'], period: {
        start: Date;
        end: Date;
    }): Promise<ComplianceReport>;
    /**
     * Clean up old audit entries
     */
    cleanup(): Promise<number>;
    /**
     * Calculate cost from token usage
     */
    private calculateCost;
    /**
     * Process query data based on audit level
     */
    private processQueryData;
    /**
     * Process response data based on audit level
     */
    private processResponseData;
    /**
     * Check for anomalies in request patterns
     */
    private checkForAnomalies;
    /**
     * Create a placeholder entry when audit is disabled
     */
    private createDisabledEntry;
    /**
     * Calculate access control compliance score
     */
    private calculateAccessControlCompliance;
    /**
     * Calculate data protection compliance score
     */
    private calculateDataProtectionCompliance;
    /**
     * Calculate auditing compliance score
     */
    private calculateAuditingCompliance;
    /**
     * Calculate bias monitoring compliance score
     */
    private calculateBiasMonitoringCompliance;
    /**
     * Get violation severity
     */
    private getViolationSeverity;
    /**
     * Generate compliance recommendations
     */
    private generateComplianceRecommendations;
    /**
     * Update configuration
     */
    updateConfig(updates: Partial<AuditConfig>): void;
    /**
     * Get current configuration
     */
    getConfig(): AuditConfig;
    /**
     * Get usage statistics for a user
     */
    getUserStats(userId: string, period: {
        start: Date;
        end: Date;
    }): Promise<{
        totalQueries: number;
        totalTokens: number;
        totalCost: number;
        averageTokensPerQuery: number;
    }>;
}
export default AuditTrail;
//# sourceMappingURL=audit-trail.d.ts.map