some cleanup
This commit is contained in:
@@ -422,9 +422,7 @@ class AIQueryInterface {
|
||||
return Object.values(this.elements).some(el => el !== null);
|
||||
}
|
||||
|
||||
setupEventListeners() {
|
||||
console.log('[AI Interface] Setting up event listeners...');
|
||||
|
||||
setupEventListeners() {
|
||||
this.elements.toggleSwitch?.addEventListener('click', () => this.toggleMode());
|
||||
this.elements.workflowLabel?.addEventListener('click', () => this.setMode('workflow'));
|
||||
this.elements.toolLabel?.addEventListener('click', () => this.setMode('tool'));
|
||||
@@ -438,13 +436,10 @@ class AIQueryInterface {
|
||||
});
|
||||
|
||||
if (this.elements.submitBtn) {
|
||||
console.log('[AI Interface] Attaching click handler to submit button');
|
||||
this.elements.submitBtn.addEventListener('click', () => {
|
||||
console.log('[AI Interface] Submit button clicked!');
|
||||
this.handleSubmit();
|
||||
});
|
||||
} else {
|
||||
console.error('[AI Interface] Submit button not found!');
|
||||
}
|
||||
|
||||
this.elements.dismissSuggestions?.addEventListener('click', () => this.hideSmartPrompting());
|
||||
@@ -654,9 +649,7 @@ class AIQueryInterface {
|
||||
if (this.elements.smartHint) showElement(this.elements.smartHint);
|
||||
}
|
||||
|
||||
async handleSubmit() {
|
||||
console.log('[AI Interface] handleSubmit called');
|
||||
|
||||
async handleSubmit() {
|
||||
const query = this.elements.input.value.trim();
|
||||
|
||||
if (!query) {
|
||||
@@ -1084,7 +1077,6 @@ class AIQueryInterface {
|
||||
if (downloadBtn && !downloadBtn.hasAttribute('data-setup')) {
|
||||
downloadBtn.setAttribute('data-setup', 'true');
|
||||
downloadBtn.addEventListener('click', () => this.downloadResults());
|
||||
console.log('[AI Interface] Download button setup complete');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1119,7 +1111,6 @@ class AIQueryInterface {
|
||||
qualityMetrics: {
|
||||
avgProcessingTime: 0,
|
||||
confidenceDistribution: { high: 0, medium: 0, low: 0 }
|
||||
// Removed aiTransparency
|
||||
},
|
||||
analysisQuality: 'excellent',
|
||||
keyInsights: [
|
||||
@@ -1602,25 +1593,33 @@ class AIQueryInterface {
|
||||
concept_name: bg.concept_name,
|
||||
relevance: bg.relevance
|
||||
})) || [],
|
||||
contextHistory: [], // This would need to be passed from server if needed
|
||||
embeddingsSimilarities: {} // This would need to be passed from server if needed
|
||||
contextHistory: [],
|
||||
embeddingsSimilarities: {}
|
||||
};
|
||||
|
||||
// Enhanced export structure with proper audit trail handling
|
||||
const exportData = {
|
||||
metadata: {
|
||||
timestamp: new Date().toISOString(),
|
||||
version: "1.0",
|
||||
version: "1.1", // Increment version for improved structure
|
||||
toolsDataHash: toolsDataHash,
|
||||
aiModel: aiModel,
|
||||
aiParameters: aiParameters,
|
||||
userQuery: inputValue,
|
||||
mode: this.currentMode,
|
||||
processingStats: processingStats,
|
||||
exportedBy: 'ForensicPathways'
|
||||
exportedBy: 'ForensicPathways',
|
||||
auditTrailVersion: '1.1' // Track audit trail format version
|
||||
},
|
||||
recommendation: this.currentRecommendation,
|
||||
auditTrail: this.currentRecommendation.auditTrail || [],
|
||||
rawContext: rawContext
|
||||
recommendation: {
|
||||
// Export recommendation without auditTrail to avoid duplication
|
||||
...this.currentRecommendation,
|
||||
auditTrail: undefined // Remove from recommendation as it's at top level
|
||||
},
|
||||
auditTrail: this.currentRecommendation.auditTrail || [], // Extract to top level
|
||||
rawContext: rawContext,
|
||||
// Add validation checksum for integrity
|
||||
checksum: this.calculateDataChecksum(this.currentRecommendation)
|
||||
};
|
||||
|
||||
const blob = new Blob([JSON.stringify(exportData, null, 2)], {
|
||||
@@ -1634,17 +1633,46 @@ class AIQueryInterface {
|
||||
a.click();
|
||||
URL.revokeObjectURL(url);
|
||||
|
||||
console.log('[AI Interface] Analysis downloaded with real metadata:', {
|
||||
console.log('[AI Interface] Analysis downloaded with enhanced structure:', {
|
||||
version: '1.1',
|
||||
aiModel,
|
||||
toolsDataHash: toolsDataHash.slice(0, 8) + '...',
|
||||
tokensUsed: aiParameters.totalTokensUsed,
|
||||
auditEntries: exportData.auditTrail.length
|
||||
auditEntries: exportData.auditTrail.length,
|
||||
checksum: exportData.checksum.slice(0, 8) + '...'
|
||||
});
|
||||
}
|
||||
|
||||
calculateDataChecksum(data) {
|
||||
if (!data) return 'empty';
|
||||
|
||||
try {
|
||||
// Simple checksum based on key data properties
|
||||
const keyData = {
|
||||
recommendedToolsCount: data.recommended_tools?.length || 0,
|
||||
backgroundKnowledgeCount: data.background_knowledge?.length || 0,
|
||||
hasScenarioAnalysis: !!(data.scenario_analysis || data.problem_analysis),
|
||||
hasApproach: !!data.investigation_approach,
|
||||
processingTimeMs: data.processingStats?.processingTimeMs || 0
|
||||
};
|
||||
|
||||
const dataString = JSON.stringify(keyData);
|
||||
let hash = 0;
|
||||
for (let i = 0; i < dataString.length; i++) {
|
||||
const char = dataString.charCodeAt(i);
|
||||
hash = ((hash << 5) - hash) + char;
|
||||
hash = hash & hash; // Convert to 32-bit integer
|
||||
}
|
||||
return Math.abs(hash).toString(36);
|
||||
} catch (error) {
|
||||
console.error('[AI Interface] Checksum calculation failed:', error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
validateUploadStructure(data) {
|
||||
try {
|
||||
return !!(
|
||||
const isValid = !!(
|
||||
data &&
|
||||
typeof data === 'object' &&
|
||||
data.metadata &&
|
||||
@@ -1652,8 +1680,32 @@ class AIQueryInterface {
|
||||
typeof data.metadata.timestamp === 'string' &&
|
||||
data.recommendation &&
|
||||
typeof data.recommendation === 'object' &&
|
||||
Array.isArray(data.auditTrail)
|
||||
Array.isArray(data.auditTrail) // Audit trail at top level
|
||||
);
|
||||
|
||||
if (!isValid) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Enhanced validation for audit trail structure
|
||||
if (data.auditTrail.length > 0) {
|
||||
const sampleEntry = data.auditTrail[0];
|
||||
const hasRequiredFields = !!(
|
||||
sampleEntry &&
|
||||
typeof sampleEntry === 'object' &&
|
||||
typeof sampleEntry.timestamp === 'number' &&
|
||||
typeof sampleEntry.phase === 'string' &&
|
||||
typeof sampleEntry.action === 'string' &&
|
||||
typeof sampleEntry.confidence === 'number'
|
||||
);
|
||||
|
||||
if (!hasRequiredFields) {
|
||||
console.warn('[AI Interface] Audit trail entries missing required fields');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('[AI Interface] Structure validation error:', error);
|
||||
return false;
|
||||
@@ -1666,7 +1718,11 @@ class AIQueryInterface {
|
||||
|
||||
this.showUploadedBanner(data.metadata);
|
||||
|
||||
this.currentRecommendation = data.recommendation;
|
||||
// Fix: Ensure audit trail is available in recommendation for restoreAIResults
|
||||
this.currentRecommendation = {
|
||||
...data.recommendation,
|
||||
auditTrail: data.auditTrail // Restore audit trail to recommendation object
|
||||
};
|
||||
|
||||
this.showResults();
|
||||
|
||||
@@ -1757,7 +1813,15 @@ class AIQueryInterface {
|
||||
throw new Error('Ungültiges Analyse-Dateiformat');
|
||||
}
|
||||
|
||||
console.log('[AI Interface] Valid previous analysis file uploaded');
|
||||
// Store audit trail separately for restore function
|
||||
this.uploadedAuditTrail = data.auditTrail;
|
||||
|
||||
console.log('[AI Interface] Valid previous analysis file uploaded:', {
|
||||
version: data.metadata.version || '1.0',
|
||||
auditEntries: data.auditTrail?.length || 0,
|
||||
toolsCount: data.recommendation.recommended_tools?.length || 0,
|
||||
checksum: data.checksum?.slice(0, 8) + '...' || 'none'
|
||||
});
|
||||
|
||||
this.hideResults();
|
||||
this.hideError();
|
||||
@@ -2218,15 +2282,20 @@ class AIQueryInterface {
|
||||
if (this.currentRecommendation && this.elements.results) {
|
||||
this.showResults();
|
||||
|
||||
if (this.currentRecommendation.auditTrail) {
|
||||
// Check both locations for audit trail for backward compatibility
|
||||
const auditTrail = this.currentRecommendation.auditTrail || this.uploadedAuditTrail;
|
||||
|
||||
if (auditTrail && Array.isArray(auditTrail) && auditTrail.length > 0) {
|
||||
setTimeout(() => {
|
||||
try {
|
||||
this.renderAuditTrail(this.currentRecommendation.auditTrail);
|
||||
console.log('[AI Interface] Audit trail restored successfully');
|
||||
this.renderAuditTrail(auditTrail);
|
||||
console.log('[AI Interface] Audit trail restored successfully:', auditTrail.length, 'entries');
|
||||
} catch (error) {
|
||||
console.error('[AI Interface] Audit trail restore failed:', error);
|
||||
}
|
||||
}, 100);
|
||||
} else {
|
||||
console.warn('[AI Interface] No audit trail available for restore');
|
||||
}
|
||||
|
||||
this.hideLoading();
|
||||
|
||||
Reference in New Issue
Block a user