cleanup
This commit is contained in:
@@ -11,7 +11,8 @@ function env(key: string, fallback: string | undefined = undefined): string | un
|
||||
return fallback;
|
||||
}
|
||||
|
||||
interface AuditEntry {
|
||||
// CONSOLIDATED AUDIT INTERFACES - Single source of truth
|
||||
export interface AuditEntry {
|
||||
timestamp: number;
|
||||
phase: string;
|
||||
action: string;
|
||||
@@ -40,7 +41,7 @@ interface CompressedAuditEntry {
|
||||
metadata: Record<string, any>;
|
||||
}
|
||||
|
||||
interface ProcessedAuditTrail {
|
||||
export interface ProcessedAuditTrail {
|
||||
totalTime: number;
|
||||
avgConfidence: number;
|
||||
stepCount: number;
|
||||
@@ -63,7 +64,7 @@ interface ProcessedAuditTrail {
|
||||
|
||||
class AuditService {
|
||||
private config: AuditConfig;
|
||||
private tempEntries: AuditEntry[] = [];
|
||||
private activeAuditTrail: AuditEntry[] = [];
|
||||
|
||||
private readonly phaseConfig = {
|
||||
'initialization': { icon: '🚀', displayName: 'Initialisierung' },
|
||||
@@ -83,11 +84,16 @@ class AuditService {
|
||||
'tool-evaluation': 'Tool-Bewertung erstellt',
|
||||
'background-knowledge-selection': 'Hintergrundwissen ausgewählt',
|
||||
'confidence-scoring': 'Vertrauenswertung berechnet',
|
||||
'phase-completion': 'Phasenergänzung durchgeführt',
|
||||
'pipeline-end': 'Analyse abgeschlossen'
|
||||
};
|
||||
|
||||
constructor() {
|
||||
this.config = this.loadConfig();
|
||||
console.log('[AUDIT-SERVICE] Initialized:', {
|
||||
enabled: this.config.enabled,
|
||||
detailLevel: this.config.detailLevel
|
||||
});
|
||||
}
|
||||
|
||||
private loadConfig(): AuditConfig {
|
||||
@@ -96,14 +102,6 @@ class AuditService {
|
||||
const retentionHours = parseInt(env('FORENSIC_AUDIT_RETENTION_HOURS', '72') || '72', 10);
|
||||
const maxEntries = parseInt(env('FORENSIC_AUDIT_MAX_ENTRIES', '50') || '50', 10);
|
||||
|
||||
console.log('[AUDIT SERVICE] Configuration loaded:', {
|
||||
enabled: enabledFlag === 'true',
|
||||
detailLevel,
|
||||
retentionHours,
|
||||
maxEntries,
|
||||
context: typeof process !== 'undefined' ? 'server' : 'client'
|
||||
});
|
||||
|
||||
return {
|
||||
enabled: enabledFlag === 'true',
|
||||
detailLevel,
|
||||
@@ -112,6 +110,7 @@ class AuditService {
|
||||
};
|
||||
}
|
||||
|
||||
// CONSOLIDATED AUDIT ENTRY CREATION - Single method for all audit operations
|
||||
addEntry(
|
||||
phase: string,
|
||||
action: string,
|
||||
@@ -134,35 +133,44 @@ class AuditService {
|
||||
metadata
|
||||
};
|
||||
|
||||
this.tempEntries.push(entry);
|
||||
console.log(`[AUDIT] ${phase}/${action}: ${confidence}% confidence, ${entry.processingTimeMs}ms`);
|
||||
this.activeAuditTrail.push(entry);
|
||||
console.log(`[AUDIT-SERVICE] ${phase}/${action}: ${confidence}% confidence, ${entry.processingTimeMs}ms`);
|
||||
}
|
||||
|
||||
|
||||
mergeAndClear(auditTrail: AuditEntry[]): void {
|
||||
if (!this.config.enabled || this.tempEntries.length === 0) return;
|
||||
|
||||
auditTrail.unshift(...this.tempEntries);
|
||||
const entryCount = this.tempEntries.length;
|
||||
this.tempEntries = [];
|
||||
|
||||
console.log(`[AUDIT] Merged ${entryCount} entries into audit trail`);
|
||||
// GET CURRENT AUDIT TRAIL - For integration with AI pipeline
|
||||
getCurrentAuditTrail(): AuditEntry[] {
|
||||
return [...this.activeAuditTrail];
|
||||
}
|
||||
|
||||
// CLEAR AUDIT TRAIL - Start fresh for new analysis
|
||||
clearAuditTrail(): void {
|
||||
if (this.activeAuditTrail.length > 0) {
|
||||
console.log(`[AUDIT-SERVICE] Cleared ${this.activeAuditTrail.length} audit entries`);
|
||||
this.activeAuditTrail = [];
|
||||
}
|
||||
}
|
||||
|
||||
// FINALIZE AUDIT TRAIL - Complete analysis and return final trail
|
||||
finalizeAuditTrail(): AuditEntry[] {
|
||||
const finalTrail = [...this.activeAuditTrail];
|
||||
console.log(`[AUDIT-SERVICE] Finalized audit trail with ${finalTrail.length} entries`);
|
||||
this.clearAuditTrail();
|
||||
return finalTrail;
|
||||
}
|
||||
|
||||
processAuditTrail(rawAuditTrail: AuditEntry[]): ProcessedAuditTrail | null {
|
||||
if (!this.config.enabled) {
|
||||
console.log('[AUDIT] Service disabled, returning null');
|
||||
console.log('[AUDIT-SERVICE] Processing disabled');
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!rawAuditTrail || !Array.isArray(rawAuditTrail) || rawAuditTrail.length === 0) {
|
||||
console.log('[AUDIT] No audit trail data provided');
|
||||
console.log('[AUDIT-SERVICE] No audit trail data to process');
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
console.log('[AUDIT] Processing', rawAuditTrail.length, 'audit entries');
|
||||
console.log(`[AUDIT-SERVICE] Processing ${rawAuditTrail.length} audit entries`);
|
||||
|
||||
const totalTime = rawAuditTrail.reduce((sum, entry) => sum + (entry.processingTimeMs || 0), 0);
|
||||
const validConfidenceEntries = rawAuditTrail.filter(entry => typeof entry.confidence === 'number');
|
||||
@@ -197,8 +205,8 @@ class AuditService {
|
||||
avgConfidence: phaseAvgConfidence,
|
||||
totalTime: phaseTotalTime,
|
||||
entries: validEntries
|
||||
.map(e => this.compressEntry(e))
|
||||
.filter((e): e is CompressedAuditEntry => e !== null)
|
||||
.map(e => this.compressEntry(e))
|
||||
.filter((e): e is CompressedAuditEntry => e !== null)
|
||||
};
|
||||
}).filter(phase => phase.entries.length > 0);
|
||||
|
||||
@@ -214,18 +222,18 @@ class AuditService {
|
||||
summary
|
||||
};
|
||||
|
||||
console.log('[AUDIT] Successfully processed audit trail:', result);
|
||||
console.log(`[AUDIT-SERVICE] Successfully processed audit trail: ${result.phases.length} phases, ${result.avgConfidence}% avg confidence`);
|
||||
return result;
|
||||
|
||||
} catch (error) {
|
||||
console.error('[AUDIT] Error processing audit trail:', error);
|
||||
console.error('[AUDIT-SERVICE] Error processing audit trail:', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private compressEntry(entry: AuditEntry): CompressedAuditEntry | null {
|
||||
if (!entry || typeof entry !== 'object') {
|
||||
console.warn('[AUDIT] Invalid audit entry:', entry);
|
||||
console.warn('[AUDIT-SERVICE] Invalid audit entry skipped');
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -241,7 +249,7 @@ class AuditService {
|
||||
metadata: entry.metadata || {}
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('[AUDIT] Error compressing entry:', error);
|
||||
console.error('[AUDIT-SERVICE] Error compressing entry:', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -375,4 +383,4 @@ class AuditService {
|
||||
}
|
||||
|
||||
export const auditService = new AuditService();
|
||||
export type { ProcessedAuditTrail, CompressedAuditEntry };
|
||||
export type { CompressedAuditEntry };
|
||||
Reference in New Issue
Block a user