From 7f5fdef445dd0c81c5bf4a819888247c245f90ea Mon Sep 17 00:00:00 2001 From: overcuriousity Date: Thu, 7 Aug 2025 08:55:29 +0200 Subject: [PATCH 1/3] fixes & consolidation --- src/components/AIQueryInterface.astro | 1361 ++++++++++++++++--------- src/utils/aiPipeline.ts | 19 - 2 files changed, 854 insertions(+), 526 deletions(-) diff --git a/src/components/AIQueryInterface.astro b/src/components/AIQueryInterface.astro index b8b3969..88dae7e 100644 --- a/src/components/AIQueryInterface.astro +++ b/src/components/AIQueryInterface.astro @@ -3,7 +3,6 @@ import { getToolsData } from '../utils/dataService.js'; import { isToolHosted } from '../utils/toolHelpers.js'; -import { AuditTrailRenderer } from '../js/auditTrailRenderer.js'; const data = await getToolsData(); const tools = data.tools; @@ -211,21 +210,575 @@ const domainAgnosticSoftware = data['domain-agnostic-software'] || []; \ No newline at end of file + + console.log('[AI Interface] Initialized successfully'); +}); \ No newline at end of file diff --git a/src/utils/aiPipeline.ts b/src/utils/aiPipeline.ts index 79d5a39..0d1ba3b 100644 --- a/src/utils/aiPipeline.ts +++ b/src/utils/aiPipeline.ts @@ -209,25 +209,6 @@ class ImprovedMicroTaskAIPipeline { console.log('[AUDIT] Merged temporary entries into context'); } -/** - private summarizeForAudit(data: any): any { - if (this.auditConfig.detailLevel === 'minimal') { - if (typeof data === 'string' && data.length > 100) { - return data.slice(0, 100) + '...[truncated]'; - } - if (Array.isArray(data) && data.length > 3) { - return [...data.slice(0, 3), `...[${data.length - 3} more items]`]; - } - } else if (this.auditConfig.detailLevel === 'standard') { - if (typeof data === 'string' && data.length > 500) { - return data.slice(0, 500) + '...[truncated]'; - } - if (Array.isArray(data) && data.length > 10) { - return [...data.slice(0, 10), `...[${data.length - 10} more items]`]; - } - } - return data; - }**/ private calculateSelectionConfidence(result: any, candidateCount: number): number { if (!result || !result.selectedTools) return 30; -- 2.39.5 From 5d05c62a555c3ac6ee6777aef36d7fb336ad6990 Mon Sep 17 00:00:00 2001 From: overcuriousity Date: Thu, 7 Aug 2025 09:13:04 +0200 Subject: [PATCH 2/3] fix --- public/js/auditTrailRenderer.js | 389 -------------------------- src/components/AIQueryInterface.astro | 31 -- src/components/ToolFilters.astro | 15 +- src/pages/api/ai/enhance-input.ts | 2 +- src/pages/index.astro | 34 --- src/utils/aiPipeline.ts | 11 +- src/utils/auditService.ts | 43 +-- src/utils/embeddings.ts | 37 +-- src/utils/nextcloud.ts | 2 +- 9 files changed, 19 insertions(+), 545 deletions(-) delete mode 100644 public/js/auditTrailRenderer.js diff --git a/public/js/auditTrailRenderer.js b/public/js/auditTrailRenderer.js deleted file mode 100644 index 9aed45a..0000000 --- a/public/js/auditTrailRenderer.js +++ /dev/null @@ -1,389 +0,0 @@ -// src/js/auditTrailRenderer.js - -import { auditService } from '../../src/utils/auditService.js'; - -export class AuditTrailRenderer { - constructor(containerId, options = {}) { - this.containerId = containerId; - this.options = { - title: options.title || 'KI-Entscheidungspfad', - collapsible: options.collapsible !== false, - defaultExpanded: options.defaultExpanded || false, - ...options - }; - this.componentId = `audit-trail-${Date.now()}-${Math.random().toString(36).substr(2, 6)}`; - } - - /** - * Render audit trail from raw audit data - * FIXED: Proper Promise handling - */ - render(rawAuditTrail) { - const container = document.getElementById(this.containerId); - if (!container) { - console.error(`[AUDIT RENDERER] Container ${this.containerId} not found`); - return; - } - - if (!rawAuditTrail || !Array.isArray(rawAuditTrail) || rawAuditTrail.length === 0) { - this.renderEmpty(); - return; - } - - try { - console.log('[AUDIT RENDERER] Processing audit trail...', rawAuditTrail.length, 'entries'); - - // Process audit trail using the centralized service (synchronous) - const processedAudit = auditService.processAuditTrail(rawAuditTrail); - - console.log('[AUDIT RENDERER] Processed audit:', processedAudit); - - if (processedAudit && processedAudit.phases && processedAudit.phases.length > 0) { - this.renderProcessed(processedAudit); - // Attach event handlers after DOM is updated - setTimeout(() => this.attachEventHandlers(), 0); - } else { - console.warn('[AUDIT RENDERER] No processed audit data'); - this.renderEmpty(); - } - } catch (error) { - console.error('[AUDIT RENDERER] Failed to render audit trail:', error); - this.renderError(error); - } - } - /** - * Render processed audit trail - */ - renderProcessed(processedAudit) { - const container = document.getElementById(this.containerId); - if (!container) return; - - const detailsId = `${this.componentId}-details`; - - console.log('[AUDIT RENDERER] Rendering processed audit with', processedAudit.phases.length, 'phases'); - - container.innerHTML = ` -
-
-
-
-
-

${this.options.title}

-
- -
-
-
- ${auditService.formatDuration(processedAudit.totalTime)} -
-
-
- ${processedAudit.avgConfidence}% Vertrauen -
-
- ${processedAudit.stepCount} Schritte -
-
-
- - ${this.options.collapsible ? ` -
- - - -
- ` : ''} -
- -
- ${this.renderSummary(processedAudit)} - ${this.renderProcessFlow(processedAudit)} - ${this.renderTechnicalDetails(processedAudit)} -
-
- `; - - console.log('[AUDIT RENDERER] HTML rendered successfully'); - } - - /** - * Render audit summary section - */ - renderSummary(audit) { - return ` -
-
📊 Analyse-Qualität
-
-
-
${audit.highConfidenceSteps}
-
Hohe Sicherheit
-
-
-
- ${audit.lowConfidenceSteps} -
-
Unsichere Schritte
-
-
-
${auditService.formatDuration(audit.totalTime)}
-
Verarbeitungszeit
-
-
- - ${audit.summary.keyInsights && audit.summary.keyInsights.length > 0 ? ` -
-
✓ Erkenntnisse:
-
    - ${audit.summary.keyInsights.map(insight => `
  • ${this.escapeHtml(insight)}
  • `).join('')} -
-
- ` : ''} - - ${audit.summary.potentialIssues && audit.summary.potentialIssues.length > 0 ? ` -
-
⚠ Hinweise:
-
    - ${audit.summary.potentialIssues.map(issue => `
  • ${this.escapeHtml(issue)}
  • `).join('')} -
-
- ` : ''} -
- `; - } - - /** - * Render process flow section - */ - renderProcessFlow(audit) { - if (!audit.phases || audit.phases.length === 0) { - return '

Keine Phasen verfügbar

'; - } - - return ` -
- ${audit.phases.map((phase, index) => ` -
-
-
- ${phase.icon || '📋'} - ${phase.displayName || phase.name} -
-
-
-
-
-
-
- ${phase.avgConfidence || 0}% -
-
- -
- ${(phase.entries || []).map(entry => ` -
-
- ${auditService.getActionDisplayName(entry.action)} - -
- - ${(entry.inputSummary && entry.inputSummary !== 'null') || (entry.outputSummary && entry.outputSummary !== 'null') ? ` -
- ${entry.inputSummary && entry.inputSummary !== 'null' ? ` -
Input: ${this.escapeHtml(entry.inputSummary)}
- ` : ''} - ${entry.outputSummary && entry.outputSummary !== 'null' ? ` -
Output: ${this.escapeHtml(entry.outputSummary)}
- ` : ''} -
- ` : ''} -
- `).join('')} -
-
- `).join('')} -
- `; - } - - /** - * Render technical details section - */ - renderTechnicalDetails(audit) { - const technicalId = `${this.componentId}-technical`; - - return ` -
- - -
- `; - } - - /** - * Attach event handlers for interactions - */ - attachEventHandlers() { - console.log('[AUDIT RENDERER] Attaching event handlers...'); - - // Handle collapsible header - if (this.options.collapsible) { - const header = document.querySelector(`[data-target="${this.componentId}-details"]`); - const details = document.getElementById(`${this.componentId}-details`); - const toggleIcon = header?.querySelector('.toggle-icon svg'); - - if (header && details && toggleIcon) { - // Remove existing listeners - header.replaceWith(header.cloneNode(true)); - const newHeader = document.querySelector(`[data-target="${this.componentId}-details"]`); - const newToggleIcon = newHeader?.querySelector('.toggle-icon svg'); - - if (newHeader && newToggleIcon) { - newHeader.addEventListener('click', () => { - const isCollapsed = details.classList.contains('collapsed'); - - if (isCollapsed) { - details.classList.remove('collapsed'); - newToggleIcon.style.transform = 'rotate(180deg)'; - } else { - details.classList.add('collapsed'); - newToggleIcon.style.transform = 'rotate(0deg)'; - } - }); - console.log('[AUDIT RENDERER] Collapsible header handler attached'); - } - } - } - - // Handle technical details toggle - const technicalBtn = document.querySelector(`[data-target="${this.componentId}-technical"]`); - const technicalDetails = document.getElementById(`${this.componentId}-technical`); - - if (technicalBtn && technicalDetails) { - // Remove existing listener - technicalBtn.replaceWith(technicalBtn.cloneNode(true)); - const newTechnicalBtn = document.querySelector(`[data-target="${this.componentId}-technical"]`); - - if (newTechnicalBtn) { - newTechnicalBtn.addEventListener('click', () => { - const isCollapsed = technicalDetails.classList.contains('collapsed'); - - if (isCollapsed) { - technicalDetails.classList.remove('collapsed'); - newTechnicalBtn.textContent = '🔧 Technische Details ausblenden'; - } else { - technicalDetails.classList.add('collapsed'); - newTechnicalBtn.textContent = '🔧 Technische Details anzeigen'; - } - }); - console.log('[AUDIT RENDERER] Technical details handler attached'); - } - } - } - - /** - * Render empty state - */ - renderEmpty() { - const container = document.getElementById(this.containerId); - if (container) { - container.innerHTML = ` -
-
-
-
-

Kein Audit-Trail verfügbar

-
-
-
- `; - } - } - - /** - * Render error state - */ - renderError(error) { - const container = document.getElementById(this.containerId); - if (container) { - container.innerHTML = ` -
-
-
-
-

Audit-Trail Fehler

-
-
-
-

- Fehler beim Laden der Audit-Informationen: ${this.escapeHtml(error.message)} -

-
-
- `; - } - } - - /** - * Utility method to escape HTML - */ - escapeHtml(text) { - if (typeof text !== 'string') return String(text); - const div = document.createElement('div'); - div.textContent = text; - return div.innerHTML; - } - - /** - * Clear the audit trail display - */ - clear() { - const container = document.getElementById(this.containerId); - if (container) { - container.innerHTML = ''; - } - } - - /** - * Get container element - */ - getContainer() { - return document.getElementById(this.containerId); - } -} \ No newline at end of file diff --git a/src/components/AIQueryInterface.astro b/src/components/AIQueryInterface.astro index 88dae7e..b95e93b 100644 --- a/src/components/AIQueryInterface.astro +++ b/src/components/AIQueryInterface.astro @@ -217,12 +217,7 @@ const domainAgnosticSoftware = data['domain-agnostic-software'] || [];