enhancement 1: audit trail
This commit is contained in:
126
src/config/forensic.config.ts
Normal file
126
src/config/forensic.config.ts
Normal file
@@ -0,0 +1,126 @@
|
||||
// src/config/forensic.config.ts
|
||||
// Centralized configuration for forensic RAG enhancements
|
||||
|
||||
export const FORENSIC_CONFIG = {
|
||||
audit: {
|
||||
enabled: process.env.FORENSIC_AUDIT_ENABLED === 'true',
|
||||
detailLevel: (process.env.FORENSIC_AUDIT_DETAIL_LEVEL as 'minimal' | 'standard' | 'verbose') || 'standard',
|
||||
retentionHours: parseInt(process.env.FORENSIC_AUDIT_RETENTION_HOURS || '72', 10),
|
||||
maxEntriesPerRequest: parseInt(process.env.FORENSIC_AUDIT_MAX_ENTRIES || '50', 10)
|
||||
},
|
||||
confidence: {
|
||||
embeddingsWeight: parseFloat(process.env.CONFIDENCE_EMBEDDINGS_WEIGHT || '0.3'),
|
||||
consensusWeight: parseFloat(process.env.CONFIDENCE_CONSENSUS_WEIGHT || '0.25'),
|
||||
domainMatchWeight: parseFloat(process.env.CONFIDENCE_DOMAIN_MATCH_WEIGHT || '0.25'),
|
||||
freshnessWeight: parseFloat(process.env.CONFIDENCE_FRESHNESS_WEIGHT || '0.2'),
|
||||
minimumThreshold: parseInt(process.env.CONFIDENCE_MINIMUM_THRESHOLD || '40', 10),
|
||||
highThreshold: parseInt(process.env.CONFIDENCE_HIGH_THRESHOLD || '80', 10),
|
||||
mediumThreshold: parseInt(process.env.CONFIDENCE_MEDIUM_THRESHOLD || '60', 10)
|
||||
},
|
||||
bias: {
|
||||
enabled: process.env.BIAS_DETECTION_ENABLED === 'true',
|
||||
popularityThreshold: parseFloat(process.env.BIAS_POPULARITY_THRESHOLD || '0.7'),
|
||||
diversityMinimum: parseFloat(process.env.BIAS_DIVERSITY_MINIMUM || '0.6'),
|
||||
domainMismatchThreshold: parseFloat(process.env.BIAS_DOMAIN_MISMATCH_THRESHOLD || '0.3'),
|
||||
warningThreshold: parseInt(process.env.BIAS_WARNING_THRESHOLD || '3', 10),
|
||||
celebrityTools: (process.env.BIAS_CELEBRITY_TOOLS || 'Volatility 3,Wireshark,Autopsy,Maltego').split(',').map(t => t.trim())
|
||||
},
|
||||
// Quality thresholds for various metrics
|
||||
quality: {
|
||||
minResponseLength: parseInt(process.env.QUALITY_MIN_RESPONSE_LENGTH || '50', 10),
|
||||
minSelectionCount: parseInt(process.env.QUALITY_MIN_SELECTION_COUNT || '1', 10),
|
||||
maxProcessingTime: parseInt(process.env.QUALITY_MAX_PROCESSING_TIME_MS || '30000', 10)
|
||||
},
|
||||
// Display preferences
|
||||
ui: {
|
||||
showAuditTrailByDefault: process.env.UI_SHOW_AUDIT_TRAIL_DEFAULT === 'true',
|
||||
showConfidenceScores: process.env.UI_SHOW_CONFIDENCE_SCORES !== 'false',
|
||||
showBiasWarnings: process.env.UI_SHOW_BIAS_WARNINGS !== 'false',
|
||||
auditTrailCollapsible: process.env.UI_AUDIT_TRAIL_COLLAPSIBLE !== 'false'
|
||||
}
|
||||
};
|
||||
|
||||
// Validation function to ensure configuration is valid
|
||||
export function validateForensicConfig(): { valid: boolean; errors: string[] } {
|
||||
const errors: string[] = [];
|
||||
|
||||
// Validate audit configuration
|
||||
if (FORENSIC_CONFIG.audit.retentionHours < 1 || FORENSIC_CONFIG.audit.retentionHours > 168) {
|
||||
errors.push('FORENSIC_AUDIT_RETENTION_HOURS must be between 1 and 168 (1 week)');
|
||||
}
|
||||
|
||||
if (!['minimal', 'standard', 'verbose'].includes(FORENSIC_CONFIG.audit.detailLevel)) {
|
||||
errors.push('FORENSIC_AUDIT_DETAIL_LEVEL must be one of: minimal, standard, verbose');
|
||||
}
|
||||
|
||||
// Validate confidence weights sum to approximately 1.0
|
||||
const weightSum = FORENSIC_CONFIG.confidence.embeddingsWeight +
|
||||
FORENSIC_CONFIG.confidence.consensusWeight +
|
||||
FORENSIC_CONFIG.confidence.domainMatchWeight +
|
||||
FORENSIC_CONFIG.confidence.freshnessWeight;
|
||||
|
||||
if (Math.abs(weightSum - 1.0) > 0.05) {
|
||||
errors.push(`Confidence weights must sum to 1.0 (currently ${weightSum.toFixed(3)})`);
|
||||
}
|
||||
|
||||
// Validate threshold ranges
|
||||
if (FORENSIC_CONFIG.confidence.minimumThreshold < 0 || FORENSIC_CONFIG.confidence.minimumThreshold > 100) {
|
||||
errors.push('CONFIDENCE_MINIMUM_THRESHOLD must be between 0 and 100');
|
||||
}
|
||||
|
||||
if (FORENSIC_CONFIG.confidence.highThreshold <= FORENSIC_CONFIG.confidence.mediumThreshold) {
|
||||
errors.push('CONFIDENCE_HIGH_THRESHOLD must be greater than CONFIDENCE_MEDIUM_THRESHOLD');
|
||||
}
|
||||
|
||||
// Validate bias thresholds
|
||||
if (FORENSIC_CONFIG.bias.popularityThreshold < 0 || FORENSIC_CONFIG.bias.popularityThreshold > 1) {
|
||||
errors.push('BIAS_POPULARITY_THRESHOLD must be between 0 and 1');
|
||||
}
|
||||
|
||||
if (FORENSIC_CONFIG.bias.diversityMinimum < 0 || FORENSIC_CONFIG.bias.diversityMinimum > 1) {
|
||||
errors.push('BIAS_DIVERSITY_MINIMUM must be between 0 and 1');
|
||||
}
|
||||
|
||||
return {
|
||||
valid: errors.length === 0,
|
||||
errors
|
||||
};
|
||||
}
|
||||
|
||||
// Helper functions for configuration access
|
||||
export function isAuditEnabled(): boolean {
|
||||
return FORENSIC_CONFIG.audit.enabled;
|
||||
}
|
||||
|
||||
export function getAuditDetailLevel(): 'minimal' | 'standard' | 'verbose' {
|
||||
return FORENSIC_CONFIG.audit.detailLevel;
|
||||
}
|
||||
|
||||
export function getConfidenceThresholds() {
|
||||
return {
|
||||
minimum: FORENSIC_CONFIG.confidence.minimumThreshold,
|
||||
medium: FORENSIC_CONFIG.confidence.mediumThreshold,
|
||||
high: FORENSIC_CONFIG.confidence.highThreshold
|
||||
};
|
||||
}
|
||||
|
||||
export function isBiasDetectionEnabled(): boolean {
|
||||
return FORENSIC_CONFIG.bias.enabled;
|
||||
}
|
||||
|
||||
// Initialize and validate configuration on module load
|
||||
const configValidation = validateForensicConfig();
|
||||
if (!configValidation.valid) {
|
||||
console.warn('[FORENSIC CONFIG] Configuration validation failed:', configValidation.errors);
|
||||
// In development, we might want to throw an error
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
throw new Error(`Forensic configuration invalid: ${configValidation.errors.join(', ')}`);
|
||||
}
|
||||
}
|
||||
|
||||
console.log('[FORENSIC CONFIG] Configuration loaded:', {
|
||||
auditEnabled: FORENSIC_CONFIG.audit.enabled,
|
||||
confidenceEnabled: true, // Always enabled
|
||||
biasDetectionEnabled: FORENSIC_CONFIG.bias.enabled,
|
||||
detailLevel: FORENSIC_CONFIG.audit.detailLevel
|
||||
});
|
||||
Reference in New Issue
Block a user