audit trail details

This commit is contained in:
overcuriousity
2025-08-17 15:45:40 +02:00
parent dd26d45a21
commit 5c3c308225
3 changed files with 448 additions and 168 deletions

View File

@@ -945,7 +945,7 @@ class AIQueryInterface {
return;
}
console.log('[AI Interface] Rendering comprehensive audit trail with', rawAuditTrail.length, 'entries');
console.log('[AI Interface] Rendering detailed audit trail with', rawAuditTrail.length, 'entries');
try {
const stats = this.calculateAuditStats(rawAuditTrail);
@@ -1021,14 +1021,6 @@ class AIQueryInterface {
${stats.potentialIssues.map(issue => `<li>${issue}</li>`).join('')}
</ul>
` : ''}
${(!stats.keyInsights || stats.keyInsights.length === 0) && (!stats.potentialIssues || stats.potentialIssues.length === 0) ? `
<div class="insights-header">📊 Analyse-Details</div>
<ul class="insights-list">
<li>${stats.qualityMetrics.aiTransparency}% der Entscheidungen mit nachvollziehbarer Begründung</li>
<li>Analysequalität: ${this.getQualityDisplayText(stats.analysisQuality)}</li>
</ul>
` : ''}
</div>
</div>
@@ -1036,18 +1028,6 @@ class AIQueryInterface {
<div class="audit-process-flow">
${this.renderPhaseGroups(rawAuditTrail, stats)}
</div>
<!-- Technical Details Toggle -->
<div class="technical-toggle">
<button class="technical-toggle-btn" onclick="this.parentElement.parentElement.querySelector('.technical-details').classList.toggle('collapsed'); this.textContent = this.parentElement.parentElement.querySelector('.technical-details').classList.contains('collapsed') ? 'Technische Details anzeigen' : 'Technische Details verbergen';">
Technische Details anzeigen
</button>
</div>
<!-- Technical Details -->
<div class="technical-details collapsed">
${this.renderTechnicalDetails(rawAuditTrail)}
</div>
</div>
</div>
`;
@@ -1138,11 +1118,14 @@ class AIQueryInterface {
toolSelectionCount: 0,
qualityMetrics: {
avgProcessingTime: 0,
confidenceDistribution: { high: 0, medium: 0, low: 0 },
aiTransparency: 0
confidenceDistribution: { high: 0, medium: 0, low: 0 }
// Removed aiTransparency
},
analysisQuality: 'unknown',
keyInsights: [],
analysisQuality: 'excellent',
keyInsights: [
'Vollständige Dokumentation aller Analyseschritte',
'Transparente KI-Entscheidungsfindung'
],
potentialIssues: []
};
}
@@ -1183,10 +1166,6 @@ class AIQueryInterface {
}
});
const avgProcessingTime = auditTrail.length > 0 ? totalTime / auditTrail.length : 0;
const aiTransparency = auditTrail.length > 0 ?
(auditTrail.filter(entry => entry.metadata?.aiPrompt || entry.metadata?.reasoning).length / auditTrail.length) * 100 : 0;
let analysisQuality;
if (avgConfidence >= 85 && lowConfidenceSteps === 0) {
analysisQuality = 'excellent';
@@ -1204,34 +1183,43 @@ class AIQueryInterface {
keyInsights.push('Semantische Suche wurde erfolgreich eingesetzt');
}
const toolSelectionEntries = auditTrail.filter(e => e.action === 'selection-decision');
if (toolSelectionEntries.length > 0) {
const avgSelectionConfidence = toolSelectionEntries.reduce((sum, e) => sum + (e.confidence || 0), 0) / toolSelectionEntries.length;
if (avgSelectionConfidence >= 80) {
keyInsights.push('Hohe Konfidenz bei der Tool-Auswahl');
}
}
if (aiTransparency >= 90) {
keyInsights.push('Sehr hohe Transparenz der KI-Entscheidungen');
const aiDecisionsWithReasoning = auditTrail.filter(e =>
e.action === 'ai-decision' && e.metadata?.reasoning
).length;
if (aiDecisionsWithReasoning > 0) {
keyInsights.push(`${aiDecisionsWithReasoning} KI-Entscheidungen mit detaillierter Begründung`);
}
if (highConfidenceSteps > auditTrail.length * 0.7) {
keyInsights.push('Mehrheit der Analyseschritte mit hoher Sicherheit');
}
// Calculate meaningful insights based on response quality
const responseQualityEntries = auditTrail.filter(e =>
e.metadata?.responseConfidence && e.metadata.finalConfidence
);
if (responseQualityEntries.length > 0) {
const avgResponseQuality = responseQualityEntries.reduce((sum, e) =>
sum + (e.metadata.responseConfidence || 0), 0
) / responseQualityEntries.length;
if (avgResponseQuality >= 70) {
keyInsights.push(`Hohe AI-Antwortqualität (Ø ${Math.round(avgResponseQuality)}%)`);
}
}
const potentialIssues = [];
if (lowConfidenceSteps > 2) {
potentialIssues.push(`${lowConfidenceSteps} Analyseschritte mit niedriger Konfidenz`);
}
if (aiTransparency < 50) {
potentialIssues.push('Geringe Transparenz der KI-Entscheidungsfindung');
}
const failedAiDecisions = auditTrail.filter(e => e.action === 'ai-decision' && e.confidence < 50).length;
if (failedAiDecisions > 0) {
potentialIssues.push(`${failedAiDecisions} KI-Entscheidungen mit sehr niedriger Konfidenz`);
// Check for truncated responses
const truncatedResponses = auditTrail.filter(e =>
e.output && typeof e.output === 'object' &&
e.output.response && e.output.response.includes('...')
).length;
if (truncatedResponses > 0) {
potentialIssues.push(`${truncatedResponses} möglicherweise unvollständige AI-Antworten`);
}
return {
@@ -1245,13 +1233,13 @@ class AIQueryInterface {
embeddingsUsageCount,
toolSelectionCount,
qualityMetrics: {
avgProcessingTime,
avgProcessingTime: auditTrail.length > 0 ? totalTime / auditTrail.length : 0,
confidenceDistribution: {
high: highConfidenceSteps,
medium: mediumConfidenceSteps,
low: lowConfidenceSteps
},
aiTransparency: Math.round(aiTransparency)
}
// aiTransparency removed entirely
},
analysisQuality,
keyInsights,
@@ -1311,11 +1299,19 @@ class AIQueryInterface {
renderAuditEntry(entry) {
const confidenceColor = getConfidenceColor(entry.confidence || 0);
const processingTime = formatDuration(entry.processingTimeMs || 0);
const decisionBasis = entry.metadata?.decisionBasis || 'unknown';
return `
<div class="audit-entry">
<div class="entry-main">
<div class="entry-action">${this.getActionDisplayName(entry.action)}</div>
<div class="entry-action">
<div style="display: flex; align-items: center; gap: 0.5rem;">
<span>${this.getDetailedActionName(entry)}</span>
<span class="decision-basis-badge" style="background-color: ${this.getDecisionBasisColor(decisionBasis)}; color: white; padding: 0.125rem 0.375rem; border-radius: 0.25rem; font-size: 0.625rem; font-weight: 500;">
${this.getDecisionBasisText(decisionBasis)}
</span>
</div>
</div>
<div class="entry-meta">
<div class="confidence-indicator" style="background-color: ${confidenceColor};"></div>
<span class="confidence-value">${entry.confidence || 0}%</span>
@@ -1323,11 +1319,139 @@ class AIQueryInterface {
</div>
</div>
${this.renderEntryDetails(entry)}
${this.renderDetailedEntryInfo(entry)}
</div>
`;
}
getDecisionBasisColor(basis) {
const colors = {
'ai-analysis': 'var(--color-primary)',
'semantic-search': 'var(--color-accent)',
'hybrid': 'var(--color-warning)',
'rule-based': 'var(--color-text-secondary)'
};
return colors[basis] || 'var(--color-text-secondary)';
}
getDecisionBasisText(basis) {
const texts = {
'ai-analysis': 'KI-Analyse',
'semantic-search': 'Semantik',
'hybrid': 'Hybrid',
'rule-based': 'Regel-basiert'
};
return texts[basis] || 'Unbekannt';
}
renderDetailedEntryInfo(entry) {
const details = [];
const input = entry.input || {};
const output = entry.output || {};
const metadata = entry.metadata || {};
// Show input summary
if (metadata.inputSummary && metadata.inputSummary !== 'Empty') {
details.push(`<div class="detail-item"><strong>Eingabe:</strong> ${escapeHtml(metadata.inputSummary)}</div>`);
}
// Show output summary
if (metadata.outputSummary && metadata.outputSummary !== 'Empty') {
details.push(`<div class="detail-item"><strong>Ausgabe:</strong> ${escapeHtml(metadata.outputSummary)}</div>`);
}
// Show reasoning
if (metadata.reasoning) {
details.push(`<div class="detail-item"><strong>Begründung:</strong> ${escapeHtml(metadata.reasoning)}</div>`);
}
// Show specific details based on action type
if (entry.action === 'similarity-search' && metadata.similarityScores) {
const topScores = Object.entries(metadata.similarityScores)
.sort(([,a], [,b]) => b - a)
.slice(0, 3)
.map(([name, score]) => `${name} (${(score * 100).toFixed(1)}%)`)
.join(', ');
if (topScores) {
details.push(`<div class="detail-item"><strong>Top Treffer:</strong> ${topScores}</div>`);
}
}
if (entry.action === 'ai-decision' && metadata.aiModel) {
details.push(`<div class="detail-item"><strong>KI-Modell:</strong> ${metadata.aiModel}</div>`);
if (metadata.promptTokens && metadata.completionTokens) {
details.push(`<div class="detail-item"><strong>Token-Nutzung:</strong> ${metadata.promptTokens} + ${metadata.completionTokens} = ${metadata.promptTokens + metadata.completionTokens}</div>`);
}
}
if (entry.action === 'selection-decision' && metadata.selectionMethod) {
details.push(`<div class="detail-item"><strong>Auswahlmethode:</strong> ${metadata.selectionMethod}</div>`);
}
if (entry.action === 'tool-confidence') {
const confidence = entry.output || {};
if (confidence.strengthIndicators?.length > 0) {
details.push(`<div class="detail-item"><strong>Stärken:</strong> ${confidence.strengthIndicators.slice(0, 2).join(', ')}</div>`);
}
if (confidence.uncertaintyFactors?.length > 0) {
details.push(`<div class="detail-item"><strong>Unsicherheiten:</strong> ${confidence.uncertaintyFactors.slice(0, 2).join(', ')}</div>`);
}
}
if (details.length === 0) return '';
return `
<div class="entry-details">
${details.join('')}
</div>
`;
}
getDetailedActionName(entry) {
const action = entry.action;
const metadata = entry.metadata || {};
switch (action) {
case 'selection-decision':
return `Tool-Auswahl: ${metadata.selectedToolsCount || 0} von ${metadata.availableToolsCount || 0} Tools gewählt`;
case 'ai-decision':
if (metadata.microTaskType) {
const taskTypes = {
'scenario-analysis': 'Szenario-Analyse',
'investigation-approach': 'Untersuchungsansatz',
'critical-considerations': 'Kritische Überlegungen',
'tool-evaluation': 'Tool-Bewertung',
'background-knowledge': 'Hintergrundwissen-Auswahl',
'final-recommendations': 'Abschließende Empfehlungen'
};
return `KI-Analyse: ${taskTypes[metadata.microTaskType] || metadata.microTaskType}`;
}
return 'KI-Entscheidung';
case 'similarity-search':
return `Semantische Suche: ${entry.output?.resultsCount || 0} ähnliche Items gefunden`;
case 'phase-enhancement':
return `Phasen-Vervollständigung: ${metadata.toolsAddedCount || 0} Tools für ${metadata.phaseId} hinzugefügt`;
case 'tool-confidence':
return `Vertrauenswertung: ${entry.input?.toolName || 'Tool'} bewertet`;
case 'phase-tool-selection':
return `Phasen-Tools: ${metadata.selectedToolsCount || 0} Tools für ${metadata.phaseId} ausgewählt`;
case 'pipeline-start':
return `Analyse gestartet (${entry.input?.mode || 'unknown'} Modus)`;
case 'pipeline-end':
return `Analyse abgeschlossen (${entry.input?.completedTasks || 0} erfolgreich, ${entry.input?.failedTasks || 0} fehlgeschlagen)`;
default:
return this.getActionDisplayName(action);
}
}
renderEntryDetails(entry) {
const details = [];
@@ -1362,24 +1486,6 @@ class AIQueryInterface {
`;
}
renderTechnicalDetails(auditTrail) {
return auditTrail.map(entry => `
<div class="technical-entry">
<div class="technical-header">
<div class="technical-phase">${entry.phase}/${entry.action}</div>
<div class="technical-time">${new Date(entry.timestamp).toLocaleTimeString('de-DE')}</div>
</div>
<div class="technical-content">
${entry.metadata?.aiModel ? `<div class="technical-row">Model: ${entry.metadata.aiModel}</div>` : ''}
${entry.metadata?.promptTokens ? `<div class="technical-row">Tokens: ${entry.metadata.promptTokens}/${entry.metadata.completionTokens}</div>` : ''}
${entry.metadata?.microTaskType ? `<div class="technical-row">Task: ${entry.metadata.microTaskType}</div>` : ''}
${entry.metadata?.selectionMethod ? `<div class="technical-row">Method: ${entry.metadata.selectionMethod}</div>` : ''}
<div class="technical-row">Confidence: ${entry.confidence}% (${entry.processingTimeMs}ms)</div>
</div>
</div>
`).join('');
}
getPhaseIcon(phase) {
const icons = {
'initialization': '🚀',