cleanup
This commit is contained in:
		
							parent
							
								
									15d302031e
								
							
						
					
					
						commit
						5d72549bb7
					
				@ -451,7 +451,6 @@ class AIQueryInterface {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    this.elements.dismissSuggestions?.addEventListener('click', () => this.hideSmartPrompting());
 | 
					    this.elements.dismissSuggestions?.addEventListener('click', () => this.hideSmartPrompting());
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    // CRITICAL: Setup upload for previous analysis (always available)
 | 
					 | 
				
			||||||
    this.setupPreviousAnalysisUpload();
 | 
					    this.setupPreviousAnalysisUpload();
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    console.log('[AI Interface] Event listeners setup complete');
 | 
					    console.log('[AI Interface] Event listeners setup complete');
 | 
				
			||||||
@ -951,7 +950,6 @@ class AIQueryInterface {
 | 
				
			|||||||
    console.log('[AI Interface] Rendering comprehensive audit trail with', rawAuditTrail.length, 'entries');
 | 
					    console.log('[AI Interface] Rendering comprehensive audit trail with', rawAuditTrail.length, 'entries');
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    try {
 | 
					    try {
 | 
				
			||||||
      // Calculate audit statistics
 | 
					 | 
				
			||||||
      const stats = this.calculateAuditStats(rawAuditTrail);
 | 
					      const stats = this.calculateAuditStats(rawAuditTrail);
 | 
				
			||||||
      
 | 
					      
 | 
				
			||||||
      container.innerHTML = `
 | 
					      container.innerHTML = `
 | 
				
			||||||
@ -1060,7 +1058,6 @@ class AIQueryInterface {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  setupUnifiedUploadSystem() {
 | 
					  setupUnifiedUploadSystem() {
 | 
				
			||||||
    // Setup the always-available upload (previous analysis)
 | 
					 | 
				
			||||||
    const previousUploadInput = document.getElementById('upload-previous-analysis');
 | 
					    const previousUploadInput = document.getElementById('upload-previous-analysis');
 | 
				
			||||||
    if (previousUploadInput) {
 | 
					    if (previousUploadInput) {
 | 
				
			||||||
      previousUploadInput.addEventListener('change', (event) => {
 | 
					      previousUploadInput.addEventListener('change', (event) => {
 | 
				
			||||||
@ -1069,12 +1066,11 @@ class AIQueryInterface {
 | 
				
			|||||||
        if (file) {
 | 
					        if (file) {
 | 
				
			||||||
          this.handlePreviousAnalysisUpload(file);
 | 
					          this.handlePreviousAnalysisUpload(file);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        event.target.value = ''; // Reset for reuse
 | 
					        event.target.value = '';
 | 
				
			||||||
      });
 | 
					      });
 | 
				
			||||||
      console.log('[AI Interface] Previous analysis upload setup complete');
 | 
					      console.log('[AI Interface] Previous analysis upload setup complete');
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Setup download buttons automatically when they appear
 | 
					 | 
				
			||||||
    const setupDownloadBtn = () => {
 | 
					    const setupDownloadBtn = () => {
 | 
				
			||||||
      const downloadBtn = document.getElementById('download-results-btn');
 | 
					      const downloadBtn = document.getElementById('download-results-btn');
 | 
				
			||||||
      if (downloadBtn && !downloadBtn.hasAttribute('data-setup')) {
 | 
					      if (downloadBtn && !downloadBtn.hasAttribute('data-setup')) {
 | 
				
			||||||
@ -1084,10 +1080,8 @@ class AIQueryInterface {
 | 
				
			|||||||
      }
 | 
					      }
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Try to setup immediately (if already present)
 | 
					 | 
				
			||||||
    setupDownloadBtn();
 | 
					    setupDownloadBtn();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Watch for dynamically added download buttons
 | 
					 | 
				
			||||||
    const observer = new MutationObserver(() => {
 | 
					    const observer = new MutationObserver(() => {
 | 
				
			||||||
      setupDownloadBtn();
 | 
					      setupDownloadBtn();
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
@ -1097,7 +1091,6 @@ class AIQueryInterface {
 | 
				
			|||||||
      subtree: true 
 | 
					      subtree: true 
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Store observer for cleanup
 | 
					 | 
				
			||||||
    this.uploadObserver = observer;
 | 
					    this.uploadObserver = observer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    console.log('[AI Interface] Unified upload system setup complete');
 | 
					    console.log('[AI Interface] Unified upload system setup complete');
 | 
				
			||||||
@ -1148,7 +1141,6 @@ class AIQueryInterface {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  renderPhaseGroups(auditTrail, stats) {
 | 
					  renderPhaseGroups(auditTrail, stats) {
 | 
				
			||||||
    // Group audit entries by phase
 | 
					 | 
				
			||||||
    const phaseGroups = new Map();
 | 
					    const phaseGroups = new Map();
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    auditTrail.forEach(entry => {
 | 
					    auditTrail.forEach(entry => {
 | 
				
			||||||
@ -1156,7 +1148,6 @@ class AIQueryInterface {
 | 
				
			|||||||
      if (!phaseGroups.has(phase)) {
 | 
					      if (!phaseGroups.has(phase)) {
 | 
				
			||||||
        phaseGroups.set(phase, []);
 | 
					        phaseGroups.set(phase, []);
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      // FIXED: Remove non-null assertion, use proper null checking
 | 
					 | 
				
			||||||
      const phaseEntries = phaseGroups.get(phase);
 | 
					      const phaseEntries = phaseGroups.get(phase);
 | 
				
			||||||
      if (phaseEntries) {
 | 
					      if (phaseEntries) {
 | 
				
			||||||
        phaseEntries.push(entry);
 | 
					        phaseEntries.push(entry);
 | 
				
			||||||
@ -1221,12 +1212,10 @@ class AIQueryInterface {
 | 
				
			|||||||
  renderEntryDetails(entry) {
 | 
					  renderEntryDetails(entry) {
 | 
				
			||||||
    const details = [];
 | 
					    const details = [];
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    // AI-specific details
 | 
					 | 
				
			||||||
    if (entry.action === 'ai-decision' && entry.metadata?.reasoning) {
 | 
					    if (entry.action === 'ai-decision' && entry.metadata?.reasoning) {
 | 
				
			||||||
      details.push(`<div class="detail-item"><strong>Begründung:</strong> ${truncateText(entry.metadata.reasoning, 200)}</div>`);
 | 
					      details.push(`<div class="detail-item"><strong>Begründung:</strong> ${truncateText(entry.metadata.reasoning, 200)}</div>`);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    // Tool selection details
 | 
					 | 
				
			||||||
    if (entry.action === 'selection-decision') {
 | 
					    if (entry.action === 'selection-decision') {
 | 
				
			||||||
      if (entry.metadata?.selectedToolsCount && entry.metadata?.availableToolsCount) {
 | 
					      if (entry.metadata?.selectedToolsCount && entry.metadata?.availableToolsCount) {
 | 
				
			||||||
        details.push(`<div class="detail-item"><strong>Auswahl:</strong> ${entry.metadata.selectedToolsCount} von ${entry.metadata.availableToolsCount} Tools</div>`);
 | 
					        details.push(`<div class="detail-item"><strong>Auswahl:</strong> ${entry.metadata.selectedToolsCount} von ${entry.metadata.availableToolsCount} Tools</div>`);
 | 
				
			||||||
@ -1236,12 +1225,10 @@ class AIQueryInterface {
 | 
				
			|||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    // Embeddings details
 | 
					 | 
				
			||||||
    if (entry.metadata?.embeddingsUsed && entry.metadata?.totalMatches) {
 | 
					    if (entry.metadata?.embeddingsUsed && entry.metadata?.totalMatches) {
 | 
				
			||||||
      details.push(`<div class="detail-item"><strong>Semantische Treffer:</strong> ${entry.metadata.totalMatches}</div>`);
 | 
					      details.push(`<div class="detail-item"><strong>Semantische Treffer:</strong> ${entry.metadata.totalMatches}</div>`);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    // Confidence factors
 | 
					 | 
				
			||||||
    if (entry.metadata?.confidenceFactors?.length > 0) {
 | 
					    if (entry.metadata?.confidenceFactors?.length > 0) {
 | 
				
			||||||
      const factors = entry.metadata.confidenceFactors.slice(0, 2).join(', ');
 | 
					      const factors = entry.metadata.confidenceFactors.slice(0, 2).join(', ');
 | 
				
			||||||
      details.push(`<div class="detail-item"><strong>Faktoren:</strong> ${factors}</div>`);
 | 
					      details.push(`<div class="detail-item"><strong>Faktoren:</strong> ${factors}</div>`);
 | 
				
			||||||
@ -1332,12 +1319,10 @@ class AIQueryInterface {
 | 
				
			|||||||
    
 | 
					    
 | 
				
			||||||
    const inputValue = this.elements.input ? this.elements.input.value : '';
 | 
					    const inputValue = this.elements.input ? this.elements.input.value : '';
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    // Extract real data from the current recommendation and stored response
 | 
					 | 
				
			||||||
    const processingStats = this.currentRecommendation.processingStats || {};
 | 
					    const processingStats = this.currentRecommendation.processingStats || {};
 | 
				
			||||||
    const aiModel = processingStats.aiModel || 'unknown';
 | 
					    const aiModel = processingStats.aiModel || 'unknown';
 | 
				
			||||||
    const toolsDataHash = processingStats.toolsDataHash || 'unknown';
 | 
					    const toolsDataHash = processingStats.toolsDataHash || 'unknown';
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    // Get real AI parameters from the processing stats
 | 
					 | 
				
			||||||
    const aiParameters = {
 | 
					    const aiParameters = {
 | 
				
			||||||
      maxTokens: processingStats.maxTokensUsed || 0,
 | 
					      maxTokens: processingStats.maxTokensUsed || 0,
 | 
				
			||||||
      temperature: processingStats.temperature || 0.3,
 | 
					      temperature: processingStats.temperature || 0.3,
 | 
				
			||||||
@ -1347,7 +1332,6 @@ class AIQueryInterface {
 | 
				
			|||||||
      embeddingsUsed: processingStats.embeddingsUsed || false
 | 
					      embeddingsUsed: processingStats.embeddingsUsed || false
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    // Extract real context data from the recommendation
 | 
					 | 
				
			||||||
    const rawContext = {
 | 
					    const rawContext = {
 | 
				
			||||||
      selectedTools: this.currentRecommendation.recommended_tools?.map(tool => ({
 | 
					      selectedTools: this.currentRecommendation.recommended_tools?.map(tool => ({
 | 
				
			||||||
        name: tool.name,
 | 
					        name: tool.name,
 | 
				
			||||||
@ -1423,23 +1407,18 @@ class AIQueryInterface {
 | 
				
			|||||||
    try {
 | 
					    try {
 | 
				
			||||||
      console.log('[AI Interface] Displaying uploaded results');
 | 
					      console.log('[AI Interface] Displaying uploaded results');
 | 
				
			||||||
      
 | 
					      
 | 
				
			||||||
      // Show upload banner
 | 
					 | 
				
			||||||
      this.showUploadedBanner(data.metadata);
 | 
					      this.showUploadedBanner(data.metadata);
 | 
				
			||||||
      
 | 
					      
 | 
				
			||||||
      // Restore interface state
 | 
					 | 
				
			||||||
      this.currentRecommendation = data.recommendation;
 | 
					      this.currentRecommendation = data.recommendation;
 | 
				
			||||||
      
 | 
					      
 | 
				
			||||||
      // Display the uploaded analysis
 | 
					 | 
				
			||||||
      this.showResults();
 | 
					      this.showResults();
 | 
				
			||||||
      
 | 
					      
 | 
				
			||||||
      // Update the recommendation display based on mode
 | 
					 | 
				
			||||||
      if (data.metadata.mode === 'workflow') {
 | 
					      if (data.metadata.mode === 'workflow') {
 | 
				
			||||||
        this.displayWorkflowResults(data.recommendation, data.metadata.userQuery);
 | 
					        this.displayWorkflowResults(data.recommendation, data.metadata.userQuery);
 | 
				
			||||||
      } else {
 | 
					      } else {
 | 
				
			||||||
        this.displayToolResults(data.recommendation, data.metadata.userQuery);
 | 
					        this.displayToolResults(data.recommendation, data.metadata.userQuery);
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      
 | 
					      
 | 
				
			||||||
      // Render the uploaded audit trail
 | 
					 | 
				
			||||||
      setTimeout(() => {
 | 
					      setTimeout(() => {
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
          this.renderAuditTrail(data.auditTrail);
 | 
					          this.renderAuditTrail(data.auditTrail);
 | 
				
			||||||
@ -1487,7 +1466,6 @@ class AIQueryInterface {
 | 
				
			|||||||
        if (file) {
 | 
					        if (file) {
 | 
				
			||||||
          this.handlePreviousAnalysisUpload(file);
 | 
					          this.handlePreviousAnalysisUpload(file);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        // Reset the input so the same file can be uploaded again
 | 
					 | 
				
			||||||
        event.target.value = '';
 | 
					        event.target.value = '';
 | 
				
			||||||
      });
 | 
					      });
 | 
				
			||||||
      
 | 
					      
 | 
				
			||||||
@ -1501,7 +1479,6 @@ class AIQueryInterface {
 | 
				
			|||||||
    console.log('[AI Interface] Handling previous analysis upload:', file.name);
 | 
					    console.log('[AI Interface] Handling previous analysis upload:', file.name);
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    try {
 | 
					    try {
 | 
				
			||||||
      // Security validation
 | 
					 | 
				
			||||||
      if (file.size > 10 * 1024 * 1024) {
 | 
					      if (file.size > 10 * 1024 * 1024) {
 | 
				
			||||||
        throw new Error('Datei zu groß (max 10MB)');
 | 
					        throw new Error('Datei zu groß (max 10MB)');
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
@ -1525,20 +1502,16 @@ class AIQueryInterface {
 | 
				
			|||||||
      
 | 
					      
 | 
				
			||||||
      console.log('[AI Interface] Valid previous analysis file uploaded');
 | 
					      console.log('[AI Interface] Valid previous analysis file uploaded');
 | 
				
			||||||
      
 | 
					      
 | 
				
			||||||
      // Hide any existing results or errors
 | 
					 | 
				
			||||||
      this.hideResults();
 | 
					      this.hideResults();
 | 
				
			||||||
      this.hideError();
 | 
					      this.hideError();
 | 
				
			||||||
      this.hideLoading();
 | 
					      this.hideLoading();
 | 
				
			||||||
      
 | 
					      
 | 
				
			||||||
      // Display the uploaded analysis
 | 
					 | 
				
			||||||
      this.displayUploadedResults(data);
 | 
					      this.displayUploadedResults(data);
 | 
				
			||||||
      
 | 
					      
 | 
				
			||||||
      // Update mode if different
 | 
					 | 
				
			||||||
      if (data.metadata.mode && data.metadata.mode !== this.currentMode) {
 | 
					      if (data.metadata.mode && data.metadata.mode !== this.currentMode) {
 | 
				
			||||||
        this.setMode(data.metadata.mode);
 | 
					        this.setMode(data.metadata.mode);
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      
 | 
					      
 | 
				
			||||||
      // Optionally restore the query in the input field
 | 
					 | 
				
			||||||
      if (data.metadata.userQuery && this.elements.input) {
 | 
					      if (data.metadata.userQuery && this.elements.input) {
 | 
				
			||||||
        this.elements.input.value = data.metadata.userQuery;
 | 
					        this.elements.input.value = data.metadata.userQuery;
 | 
				
			||||||
        this.updateCharacterCount();
 | 
					        this.updateCharacterCount();
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user