fix audit trail
This commit is contained in:
@@ -1184,6 +1184,37 @@ class AIPipeline {
|
||||
try {
|
||||
const response = await aiService.callMicroTaskAI(contextPrompt);
|
||||
|
||||
// FIX: Ensure ALL AI calls generate audit entries
|
||||
const toolsDataHash = getDataVersion?.() || 'unknown';
|
||||
const aiConfig = aiService.getConfig();
|
||||
|
||||
// Calculate response confidence for audit trail
|
||||
const responseConfidence = auditService.calculateAIResponseConfidence(
|
||||
response.content,
|
||||
this.getExpectedLengthForTaskType(taskType),
|
||||
taskType
|
||||
);
|
||||
|
||||
// FIX: Always add AI decision audit entry for micro-tasks
|
||||
auditService.addAIDecision(
|
||||
this.getPhaseForTaskType(taskType),
|
||||
prompt, // Store original prompt without context
|
||||
response.content,
|
||||
responseConfidence,
|
||||
this.getReasoningForTaskType(taskType, response.content),
|
||||
startTime,
|
||||
{
|
||||
toolsDataHash: toolsDataHash,
|
||||
microTaskType: taskType,
|
||||
aiModel: aiConfig.model,
|
||||
contextLength: contextPrompt.length,
|
||||
originalPromptLength: prompt.length,
|
||||
contextHistoryUsed: context.contextHistory.length > 0,
|
||||
decisionBasis: 'ai-analysis',
|
||||
...response.usage
|
||||
}
|
||||
);
|
||||
|
||||
return {
|
||||
taskType,
|
||||
content: response.content,
|
||||
@@ -1193,6 +1224,29 @@ class AIPipeline {
|
||||
};
|
||||
|
||||
} catch (error) {
|
||||
// FIX: Also audit failed AI calls for completeness
|
||||
auditService.addEntry(
|
||||
this.getPhaseForTaskType(taskType),
|
||||
'ai-decision-failed',
|
||||
{
|
||||
prompt: prompt.slice(0, 200) + '...',
|
||||
taskType: taskType,
|
||||
error: error.message
|
||||
},
|
||||
{
|
||||
error: error.message,
|
||||
success: false
|
||||
},
|
||||
0, // Zero confidence for failed calls
|
||||
startTime,
|
||||
{
|
||||
toolsDataHash: getDataVersion?.() || 'unknown',
|
||||
microTaskType: taskType,
|
||||
failed: true,
|
||||
decisionBasis: 'ai-analysis'
|
||||
}
|
||||
);
|
||||
|
||||
return {
|
||||
taskType,
|
||||
content: '',
|
||||
@@ -1203,6 +1257,51 @@ class AIPipeline {
|
||||
}
|
||||
}
|
||||
|
||||
private getPhaseForTaskType(taskType: string): string {
|
||||
const phaseMap: Record<string, string> = {
|
||||
'scenario-analysis': 'contextual-analysis',
|
||||
'investigation-approach': 'contextual-analysis',
|
||||
'critical-considerations': 'contextual-analysis',
|
||||
'tool-evaluation': 'tool-evaluation',
|
||||
'background-knowledge': 'knowledge-synthesis',
|
||||
'final-recommendations': 'synthesis',
|
||||
'phase-completion-selection': 'phase-completion',
|
||||
'phase-completion-reasoning': 'phase-completion'
|
||||
};
|
||||
return phaseMap[taskType] || 'contextual-analysis';
|
||||
}
|
||||
|
||||
private getExpectedLengthForTaskType(taskType: string): { min: number; max: number } {
|
||||
const lengthMap: Record<string, { min: number; max: number }> = {
|
||||
'scenario-analysis': { min: 100, max: 500 },
|
||||
'investigation-approach': { min: 100, max: 400 },
|
||||
'critical-considerations': { min: 80, max: 300 },
|
||||
'tool-evaluation': { min: 200, max: 800 },
|
||||
'background-knowledge': { min: 50, max: 300 },
|
||||
'final-recommendations': { min: 150, max: 600 },
|
||||
'phase-completion-selection': { min: 50, max: 200 },
|
||||
'phase-completion-reasoning': { min: 100, max: 300 }
|
||||
};
|
||||
return lengthMap[taskType] || { min: 50, max: 300 };
|
||||
}
|
||||
|
||||
private getReasoningForTaskType(taskType: string, response: string): string {
|
||||
const responseLength = response.length;
|
||||
const taskNames: Record<string, string> = {
|
||||
'scenario-analysis': 'Szenario-Analyse',
|
||||
'investigation-approach': 'Untersuchungsansatz',
|
||||
'critical-considerations': 'Kritische Überlegungen',
|
||||
'tool-evaluation': 'Tool-Bewertung',
|
||||
'background-knowledge': 'Hintergrundwissen-Auswahl',
|
||||
'final-recommendations': 'Abschließende Empfehlungen',
|
||||
'phase-completion-selection': 'Phasen-Vervollständigung',
|
||||
'phase-completion-reasoning': 'Phasen-Begründung'
|
||||
};
|
||||
|
||||
const taskName = taskNames[taskType] || taskType;
|
||||
return `KI generierte ${taskName} (${responseLength} Zeichen) - forensisch fundierte Analyse mit methodischer Begründung`;
|
||||
}
|
||||
|
||||
private addToContextHistory(context: PipelineContext, newEntry: string): void {
|
||||
const entryTokens = aiService.estimateTokens(newEntry);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user