fix
This commit is contained in:
@@ -217,12 +217,7 @@ const domainAgnosticSoftware = data['domain-agnostic-software'] || [];
|
||||
|
||||
<script type="module" define:vars={{ tools, phases, domainAgnosticSoftware }}>
|
||||
|
||||
// ===================================================================
|
||||
// CONSOLIDATED UTILITIES
|
||||
// ===================================================================
|
||||
|
||||
const Utils = {
|
||||
// Phase configuration for audit trail
|
||||
phaseConfig: {
|
||||
'initialization': { icon: '🚀', displayName: 'Initialisierung' },
|
||||
'retrieval': { icon: '🔍', displayName: 'Datensuche' },
|
||||
@@ -232,7 +227,6 @@ const Utils = {
|
||||
'completion': { icon: '✅', displayName: 'Finalisierung' }
|
||||
},
|
||||
|
||||
// Action translations for display
|
||||
actionTranslations: {
|
||||
'pipeline-start': 'Analyse gestartet',
|
||||
'embeddings-search': 'Ähnliche Tools gesucht',
|
||||
@@ -316,7 +310,6 @@ const Utils = {
|
||||
return String(data);
|
||||
},
|
||||
|
||||
// DOM utilities
|
||||
showElement(element) {
|
||||
if (element) {
|
||||
element.style.display = 'block';
|
||||
@@ -332,10 +325,6 @@ const Utils = {
|
||||
}
|
||||
};
|
||||
|
||||
// ===================================================================
|
||||
// AUDIT TRAIL PROCESSOR
|
||||
// ===================================================================
|
||||
|
||||
class AuditTrailProcessor {
|
||||
static processAuditTrail(rawAuditTrail) {
|
||||
if (!rawAuditTrail || !Array.isArray(rawAuditTrail) || rawAuditTrail.length === 0) {
|
||||
@@ -355,7 +344,6 @@ class AuditTrailProcessor {
|
||||
const highConfidenceSteps = rawAuditTrail.filter(entry => (entry.confidence || 0) >= 80).length;
|
||||
const lowConfidenceSteps = rawAuditTrail.filter(entry => (entry.confidence || 0) < 60).length;
|
||||
|
||||
// Group entries by phase
|
||||
const groupedEntries = rawAuditTrail.reduce((groups, entry) => {
|
||||
const phase = entry.phase || 'unknown';
|
||||
if (!groups[phase]) groups[phase] = [];
|
||||
@@ -363,7 +351,6 @@ class AuditTrailProcessor {
|
||||
return groups;
|
||||
}, {});
|
||||
|
||||
// Process phases
|
||||
const phases = Object.entries(groupedEntries).map(([phase, entries]) => {
|
||||
const phaseConfig = Utils.phaseConfig[phase] || { icon: '📋', displayName: phase };
|
||||
const validEntries = entries.filter(entry => entry && typeof entry === 'object');
|
||||
@@ -463,10 +450,6 @@ class AuditTrailProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
// ===================================================================
|
||||
// AUDIT TRAIL RENDERER
|
||||
// ===================================================================
|
||||
|
||||
class AuditTrailRenderer {
|
||||
constructor(containerId, options = {}) {
|
||||
this.containerId = containerId;
|
||||
@@ -740,7 +723,6 @@ class AuditTrailRenderer {
|
||||
}
|
||||
|
||||
attachEventHandlers() {
|
||||
// Handle collapsible header
|
||||
if (this.options.collapsible) {
|
||||
const header = document.querySelector(`[data-target="${this.componentId}-details"]`);
|
||||
const details = document.getElementById(`${this.componentId}-details`);
|
||||
@@ -755,7 +737,6 @@ class AuditTrailRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
// Handle technical details toggle
|
||||
const technicalBtn = document.querySelector(`[data-target="${this.componentId}-technical"]`);
|
||||
const technicalDetails = document.getElementById(`${this.componentId}-technical`);
|
||||
|
||||
@@ -771,10 +752,6 @@ class AuditTrailRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
// ===================================================================
|
||||
// MAIN AI QUERY INTERFACE
|
||||
// ===================================================================
|
||||
|
||||
class AIQueryInterface {
|
||||
constructor() {
|
||||
this.currentMode = 'workflow';
|
||||
@@ -1251,7 +1228,6 @@ class AIQueryInterface {
|
||||
|
||||
this.showResults();
|
||||
|
||||
// Render audit trail after DOM is ready
|
||||
setTimeout(() => {
|
||||
try {
|
||||
this.renderAuditTrail(recommendation.auditTrail);
|
||||
@@ -1764,7 +1740,6 @@ class AIQueryInterface {
|
||||
return texts[score] || 'GEEIGNET';
|
||||
}
|
||||
|
||||
// Display state management
|
||||
showLoading() {
|
||||
Utils.showElement(this.elements.loading);
|
||||
}
|
||||
@@ -1791,7 +1766,6 @@ class AIQueryInterface {
|
||||
Utils.hideElement(this.elements.error);
|
||||
}
|
||||
|
||||
// Public method for restoring AI results after navigation
|
||||
restoreAIResults() {
|
||||
if (this.currentRecommendation && this.elements.results) {
|
||||
this.showResults();
|
||||
@@ -1813,14 +1787,9 @@ class AIQueryInterface {
|
||||
}
|
||||
}
|
||||
|
||||
// ===================================================================
|
||||
// INITIALIZATION
|
||||
// ===================================================================
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const aiInterface = new AIQueryInterface();
|
||||
|
||||
// Global functions for external access
|
||||
window.restoreAIResults = () => aiInterface.restoreAIResults();
|
||||
window.isToolHosted = window.isToolHosted || isToolHosted;
|
||||
|
||||
|
||||
@@ -354,7 +354,6 @@ const sortedTags = Object.entries(tagFrequency)
|
||||
let semanticSearchAvailable = false;
|
||||
let lastSemanticResults = null;
|
||||
|
||||
// Check embeddings availability
|
||||
async function checkEmbeddingsAvailability() {
|
||||
try {
|
||||
const res = await fetch('/api/ai/embeddings-status');
|
||||
@@ -363,15 +362,13 @@ const sortedTags = Object.entries(tagFrequency)
|
||||
|
||||
if (semanticSearchAvailable) {
|
||||
elements.semanticContainer.classList.remove('hidden');
|
||||
elements.semanticCheckbox.disabled = false; // 👈 re-enable
|
||||
elements.semanticCheckbox.disabled = false;
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('[EMBEDDINGS] Status check failed:', err);
|
||||
// leave the checkbox disabled
|
||||
}
|
||||
}
|
||||
|
||||
// Semantic search function
|
||||
async function performSemanticSearch(query) {
|
||||
if (!semanticSearchAvailable || !query.trim()) {
|
||||
return null;
|
||||
@@ -576,7 +573,6 @@ const sortedTags = Object.entries(tagFrequency)
|
||||
}
|
||||
}
|
||||
|
||||
// FIXED: Consolidated filtering logic with semantic search support
|
||||
async function filterTools() {
|
||||
const searchTerm = elements.searchInput.value.trim().toLowerCase();
|
||||
const selectedDomain = elements.domainSelect.value;
|
||||
@@ -594,7 +590,6 @@ const sortedTags = Object.entries(tagFrequency)
|
||||
let filteredTools = window.toolsData;
|
||||
let semanticResults = null;
|
||||
|
||||
// CONSOLIDATED: Use semantic search if enabled and search term exists
|
||||
if (semanticSearchEnabled && semanticSearchAvailable && searchTerm) {
|
||||
semanticResults = await performSemanticSearch(searchTerm);
|
||||
lastSemanticResults = semanticResults;
|
||||
@@ -605,7 +600,6 @@ const sortedTags = Object.entries(tagFrequency)
|
||||
} else {
|
||||
lastSemanticResults = null;
|
||||
|
||||
// Traditional text-based search
|
||||
if (searchTerm) {
|
||||
filteredTools = window.toolsData.filter(tool =>
|
||||
tool.name.toLowerCase().includes(searchTerm) ||
|
||||
@@ -615,7 +609,6 @@ const sortedTags = Object.entries(tagFrequency)
|
||||
}
|
||||
}
|
||||
|
||||
// Apply additional filters to the results
|
||||
filteredTools = filteredTools.filter(tool => {
|
||||
if (selectedDomain && !(tool.domains || []).includes(selectedDomain)) {
|
||||
return false;
|
||||
@@ -666,9 +659,8 @@ const sortedTags = Object.entries(tagFrequency)
|
||||
);
|
||||
}
|
||||
|
||||
/* existing code continues */
|
||||
const finalResults = semanticSearchEnabled && lastSemanticResults
|
||||
? filteredTools // now properly re-sorted
|
||||
? filteredTools
|
||||
: (searchTerm && window.prioritizeSearchResults
|
||||
? window.prioritizeSearchResults(filteredTools, searchTerm)
|
||||
: filteredTools);
|
||||
@@ -726,7 +718,6 @@ const sortedTags = Object.entries(tagFrequency)
|
||||
filterTagCloud();
|
||||
}
|
||||
|
||||
// Event listeners
|
||||
elements.searchInput.addEventListener('input', (e) => {
|
||||
const hasValue = e.target.value.length > 0;
|
||||
elements.clearSearch.classList.toggle('hidden', !hasValue);
|
||||
@@ -741,7 +732,6 @@ const sortedTags = Object.entries(tagFrequency)
|
||||
filterTools();
|
||||
});
|
||||
|
||||
// Semantic search checkbox handler
|
||||
if (elements.semanticCheckbox) {
|
||||
elements.semanticCheckbox.addEventListener('change', (e) => {
|
||||
semanticSearchEnabled = e.target.checked;
|
||||
@@ -812,7 +802,6 @@ const sortedTags = Object.entries(tagFrequency)
|
||||
window.clearTagFilters = resetTags;
|
||||
window.clearAllFilters = resetAllFilters;
|
||||
|
||||
// Initialize
|
||||
checkEmbeddingsAvailability();
|
||||
initializeCollapsible();
|
||||
initTagCloud();
|
||||
|
||||
@@ -20,7 +20,7 @@ const AI_ANALYZER_API_KEY = getEnv('AI_ANALYZER_API_KEY');
|
||||
const AI_ANALYZER_MODEL = getEnv('AI_ANALYZER_MODEL');
|
||||
|
||||
const rateLimitStore = new Map<string, { count: number; resetTime: number }>();
|
||||
const RATE_LIMIT_WINDOW = 60 * 1000; // 1 minute
|
||||
const RATE_LIMIT_WINDOW = 60 * 1000;
|
||||
const RATE_LIMIT_MAX = 5;
|
||||
|
||||
function sanitizeInput(input: string): string {
|
||||
|
||||
@@ -198,15 +198,12 @@ const phases = data.phases;
|
||||
<script define:vars={{ toolsData: data.tools, phases: data.phases }}>
|
||||
window.toolsData = toolsData;
|
||||
|
||||
// CONSOLIDATED: Approach selection - Pure navigation aid
|
||||
window.selectApproach = function(approach) {
|
||||
console.log(`Selected approach: ${approach}`);
|
||||
|
||||
// Clear any existing AI results
|
||||
const aiResults = document.getElementById('ai-results');
|
||||
if (aiResults) aiResults.style.display = 'none';
|
||||
|
||||
// Update visual selection state
|
||||
document.querySelectorAll('.approach-card').forEach(card => {
|
||||
card.classList.remove('selected');
|
||||
});
|
||||
@@ -214,14 +211,12 @@ const phases = data.phases;
|
||||
const selectedCard = document.querySelector(`.approach-card.${approach}`);
|
||||
if (selectedCard) selectedCard.classList.add('selected');
|
||||
|
||||
// Hide all approach sections first (ensures mutual exclusivity)
|
||||
const methodologySection = document.getElementById('methodology-section');
|
||||
const targetedSection = document.getElementById('targeted-section');
|
||||
|
||||
if (methodologySection) methodologySection.classList.remove('active');
|
||||
if (targetedSection) targetedSection.classList.remove('active');
|
||||
|
||||
// Show the selected approach section (navigation aid only)
|
||||
if (approach === 'methodology') {
|
||||
if (methodologySection) {
|
||||
methodologySection.classList.add('active');
|
||||
@@ -235,11 +230,9 @@ const phases = data.phases;
|
||||
}
|
||||
};
|
||||
|
||||
// CONSOLIDATED: Phase selection - Sets unified filter dropdown
|
||||
window.selectPhase = function(phase) {
|
||||
console.log(`Selected NIST phase: ${phase}`);
|
||||
|
||||
// Update visual selection of phase cards
|
||||
document.querySelectorAll('.phase-card').forEach(card => {
|
||||
card.classList.remove('active');
|
||||
});
|
||||
@@ -249,23 +242,19 @@ const phases = data.phases;
|
||||
selectedCard.classList.add('active');
|
||||
}
|
||||
|
||||
// CONSOLIDATED: Set the unified phase-select dropdown
|
||||
const phaseSelect = document.getElementById('phase-select');
|
||||
if (phaseSelect) {
|
||||
phaseSelect.value = phase;
|
||||
|
||||
// Trigger the change event to activate unified filtering
|
||||
const changeEvent = new Event('change', { bubbles: true });
|
||||
phaseSelect.dispatchEvent(changeEvent);
|
||||
}
|
||||
|
||||
// Switch to grid view to show filtered results
|
||||
const gridToggle = document.querySelector('.view-toggle[data-view="grid"]');
|
||||
if (gridToggle && !gridToggle.classList.contains('active')) {
|
||||
gridToggle.click();
|
||||
}
|
||||
|
||||
// Scroll to filtered results
|
||||
setTimeout(() => {
|
||||
window.scrollToElementById('tools-grid');
|
||||
}, 200);
|
||||
@@ -309,17 +298,14 @@ const phases = data.phases;
|
||||
const filtersSection = document.getElementById('filters-section');
|
||||
const noResults = document.getElementById('no-results');
|
||||
|
||||
// FIXED: Hide approach sections when switching to ANY view mode
|
||||
const methodologySection = document.getElementById('methodology-section');
|
||||
const targetedSection = document.getElementById('targeted-section');
|
||||
|
||||
// Hide all main content areas
|
||||
if (toolsGrid) toolsGrid.style.display = 'none';
|
||||
if (matrixContainer) matrixContainer.style.display = 'none';
|
||||
if (aiInterface) aiInterface.style.display = 'none';
|
||||
if (noResults) noResults.style.display = 'none';
|
||||
|
||||
// FIXED: Hide approach sections when switching to view modes
|
||||
if (methodologySection) methodologySection.classList.remove('active');
|
||||
if (targetedSection) targetedSection.classList.remove('active');
|
||||
|
||||
@@ -335,18 +321,14 @@ const phases = data.phases;
|
||||
case 'ai':
|
||||
if (aiInterface) aiInterface.style.display = 'block';
|
||||
|
||||
// FIXED: Show filters but hide everything except view controls
|
||||
if (filtersSection) {
|
||||
filtersSection.style.display = 'block';
|
||||
|
||||
// Hide all filter sections except the last one (view controls)
|
||||
const filterSections = filtersSection.querySelectorAll('.filter-section');
|
||||
filterSections.forEach((section, index) => {
|
||||
if (index === filterSections.length - 1) {
|
||||
// Keep view controls visible
|
||||
section.style.display = 'block';
|
||||
} else {
|
||||
// Hide other filter sections
|
||||
section.style.display = 'none';
|
||||
}
|
||||
});
|
||||
@@ -354,7 +336,6 @@ const phases = data.phases;
|
||||
break;
|
||||
}
|
||||
|
||||
// FIXED: Reset filter sections visibility when not in AI view
|
||||
if (view !== 'ai' && filtersSection) {
|
||||
const filterSections = filtersSection.querySelectorAll('.filter-section');
|
||||
filterSections.forEach(section => {
|
||||
@@ -363,7 +344,6 @@ const phases = data.phases;
|
||||
}
|
||||
}
|
||||
|
||||
// Navigation functions for AI recommendations (unchanged)
|
||||
window.navigateToGrid = function(toolName) {
|
||||
console.log('Navigating to grid for tool:', toolName);
|
||||
|
||||
@@ -485,8 +465,6 @@ const phases = data.phases;
|
||||
}, 100);
|
||||
}
|
||||
|
||||
// REPLACE the existing toolsFiltered event listener in index.astro with this enhanced version:
|
||||
|
||||
window.addEventListener('toolsFiltered', (event) => {
|
||||
const { tools: filtered, semanticSearch } = event.detail;
|
||||
const currentView = document.querySelector('.view-toggle.active')?.getAttribute('data-view');
|
||||
@@ -504,11 +482,9 @@ const phases = data.phases;
|
||||
if (semanticSearch && filtered.length > 0) {
|
||||
console.log('[SEMANTIC] Reordering tools by semantic similarity');
|
||||
|
||||
// FIXED: Create ordered array of cards based on semantic similarity
|
||||
const orderedCards = [];
|
||||
const remainingCards = [];
|
||||
|
||||
// First pass: collect cards in semantic order
|
||||
filtered.forEach(tool => {
|
||||
const toolName = tool.name.toLowerCase();
|
||||
const matchingCard = Array.from(allToolCards).find(card =>
|
||||
@@ -520,12 +496,10 @@ const phases = data.phases;
|
||||
orderedCards.push(matchingCard);
|
||||
visibleCount++;
|
||||
|
||||
// Add semantic indicators if available
|
||||
if (tool._semanticSimilarity) {
|
||||
matchingCard.setAttribute('data-semantic-similarity', tool._semanticSimilarity.toFixed(3));
|
||||
matchingCard.setAttribute('data-semantic-rank', tool._semanticRank || '');
|
||||
|
||||
// Visual indication of semantic ranking (subtle)
|
||||
const header = matchingCard.querySelector('.tool-card-header h3');
|
||||
if (header && tool._semanticRank <= 3) {
|
||||
const existingIndicator = header.querySelector('.semantic-rank-indicator');
|
||||
@@ -551,7 +525,6 @@ const phases = data.phases;
|
||||
}
|
||||
});
|
||||
|
||||
// Second pass: hide non-matching cards and collect them
|
||||
allToolCards.forEach(card => {
|
||||
const toolName = card.getAttribute('data-tool-name');
|
||||
if (!filteredNames.has(toolName)) {
|
||||
@@ -560,18 +533,15 @@ const phases = data.phases;
|
||||
}
|
||||
});
|
||||
|
||||
// Reorder DOM: semantic results first, then hidden cards
|
||||
const allCards = [...orderedCards, ...remainingCards];
|
||||
allCards.forEach(card => {
|
||||
toolsContainer.appendChild(card);
|
||||
});
|
||||
|
||||
} else {
|
||||
// FIXED: Standard filtering without semantic ordering
|
||||
allToolCards.forEach(card => {
|
||||
const toolName = card.getAttribute('data-tool-name');
|
||||
|
||||
// Clean up any semantic indicators
|
||||
card.removeAttribute('data-semantic-similarity');
|
||||
card.removeAttribute('data-semantic-rank');
|
||||
const semanticIndicator = card.querySelector('.semantic-rank-indicator');
|
||||
@@ -587,10 +557,8 @@ const phases = data.phases;
|
||||
}
|
||||
});
|
||||
|
||||
// Restore original order when not using semantic search
|
||||
if (!semanticSearch) {
|
||||
const originalOrder = Array.from(allToolCards).sort((a, b) => {
|
||||
// Get original indices from data attributes or DOM order
|
||||
const aIndex = Array.from(allToolCards).indexOf(a);
|
||||
const bIndex = Array.from(allToolCards).indexOf(b);
|
||||
return aIndex - bIndex;
|
||||
@@ -602,14 +570,12 @@ const phases = data.phases;
|
||||
}
|
||||
}
|
||||
|
||||
// Show/hide no results message
|
||||
if (visibleCount === 0) {
|
||||
noResults.style.display = 'block';
|
||||
} else {
|
||||
noResults.style.display = 'none';
|
||||
}
|
||||
|
||||
// Log semantic search info
|
||||
if (semanticSearch) {
|
||||
console.log(`[SEMANTIC] Displayed ${visibleCount} tools in semantic order`);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
// src/utils/aiPipeline.ts - Enhanced with Proper Confidence Scoring
|
||||
// src/utils/aiPipeline.ts
|
||||
|
||||
import { getCompressedToolsDataForAI } from './dataService.js';
|
||||
import { embeddingsService, type EmbeddingData, type SimilarityResult } from './embeddings.js';
|
||||
import { AI_PROMPTS, getPrompt } from '../config/prompts.js';
|
||||
import { isToolHosted } from './toolHelpers.js';
|
||||
import { auditService } from './auditService.js'; // Add this import
|
||||
import { auditService } from './auditService.js';
|
||||
|
||||
interface AIConfig {
|
||||
endpoint: string;
|
||||
@@ -188,7 +188,6 @@ class ImprovedMicroTaskAIPipeline {
|
||||
metadata
|
||||
};
|
||||
|
||||
// Add to context audit trail instead of temp storage
|
||||
if (!context.auditTrail) {
|
||||
context.auditTrail = [];
|
||||
}
|
||||
@@ -369,7 +368,6 @@ class ImprovedMicroTaskAIPipeline {
|
||||
|
||||
context.embeddingsSimilarities = new Map<string, number>();
|
||||
|
||||
// Always try to initialize embeddings - let the service decide if it should be enabled
|
||||
try {
|
||||
console.log('[AI PIPELINE] Attempting embeddings initialization...');
|
||||
await embeddingsService.waitForInitialization();
|
||||
@@ -1175,7 +1173,6 @@ ${JSON.stringify(conceptsToSend, null, 2)}`;
|
||||
})) || []
|
||||
};
|
||||
|
||||
// Process audit trail before returning
|
||||
const processedAuditTrail = this.auditConfig.enabled && context.auditTrail
|
||||
? context.auditTrail
|
||||
: [];
|
||||
@@ -1218,7 +1215,7 @@ ${JSON.stringify(conceptsToSend, null, 2)}`;
|
||||
...base,
|
||||
recommended_tools: recommendedToolsWithConfidence,
|
||||
workflow_suggestion: finalContent,
|
||||
auditTrail: processedAuditTrail // Always include audit trail array
|
||||
auditTrail: processedAuditTrail
|
||||
};
|
||||
} else {
|
||||
const recommendedToolsWithConfidence = context.selectedTools?.map(st => {
|
||||
@@ -1260,7 +1257,7 @@ ${JSON.stringify(conceptsToSend, null, 2)}`;
|
||||
...base,
|
||||
recommended_tools: recommendedToolsWithConfidence,
|
||||
additional_considerations: finalContent,
|
||||
auditTrail: processedAuditTrail // Always include audit trail array
|
||||
auditTrail: processedAuditTrail
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
// src/utils/auditService.ts - Centralized Audit Trail Management
|
||||
// src/utils/auditService.ts
|
||||
|
||||
|
||||
function env(key: string, fallback: string | undefined = undefined): string | undefined {
|
||||
// during dev/server-side rendering
|
||||
if (typeof process !== 'undefined' && process.env?.[key] !== undefined) {
|
||||
return process.env[key];
|
||||
}
|
||||
// during client build / browser
|
||||
if (typeof import.meta !== 'undefined' && (import.meta as any).env?.[key] !== undefined) {
|
||||
return (import.meta as any).env[key];
|
||||
}
|
||||
@@ -67,7 +65,6 @@ class AuditService {
|
||||
private config: AuditConfig;
|
||||
private tempEntries: AuditEntry[] = [];
|
||||
|
||||
// Phase configuration with German translations
|
||||
private readonly phaseConfig = {
|
||||
'initialization': { icon: '🚀', displayName: 'Initialisierung' },
|
||||
'retrieval': { icon: '🔍', displayName: 'Datensuche' },
|
||||
@@ -77,7 +74,6 @@ class AuditService {
|
||||
'completion': { icon: '✅', displayName: 'Finalisierung' }
|
||||
};
|
||||
|
||||
// Action translations
|
||||
private readonly actionTranslations = {
|
||||
'pipeline-start': 'Analyse gestartet',
|
||||
'embeddings-search': 'Ähnliche Tools gesucht',
|
||||
@@ -95,7 +91,6 @@ class AuditService {
|
||||
}
|
||||
|
||||
private loadConfig(): AuditConfig {
|
||||
// use the helper if you added it
|
||||
const enabledFlag =
|
||||
(typeof import.meta !== 'undefined' &&
|
||||
(import.meta as any).env?.PUBLIC_FORENSIC_AUDIT_ENABLED) ?? 'false';
|
||||
@@ -172,7 +167,6 @@ class AuditService {
|
||||
try {
|
||||
console.log('[AUDIT] Processing', rawAuditTrail.length, 'audit entries');
|
||||
|
||||
// Calculate summary statistics with safe defaults
|
||||
const totalTime = rawAuditTrail.reduce((sum, entry) => sum + (entry.processingTimeMs || 0), 0);
|
||||
const validConfidenceEntries = rawAuditTrail.filter(entry => typeof entry.confidence === 'number');
|
||||
const avgConfidence = validConfidenceEntries.length > 0
|
||||
@@ -182,7 +176,6 @@ class AuditService {
|
||||
const highConfidenceSteps = rawAuditTrail.filter(entry => (entry.confidence || 0) >= 80).length;
|
||||
const lowConfidenceSteps = rawAuditTrail.filter(entry => (entry.confidence || 0) < 60).length;
|
||||
|
||||
// Group entries by phase with safe handling
|
||||
const groupedEntries = rawAuditTrail.reduce((groups, entry) => {
|
||||
const phase = entry.phase || 'unknown';
|
||||
if (!groups[phase]) groups[phase] = [];
|
||||
@@ -190,7 +183,6 @@ class AuditService {
|
||||
return groups;
|
||||
}, {} as Record<string, AuditEntry[]>);
|
||||
|
||||
// Process phases with error handling
|
||||
const phases = Object.entries(groupedEntries).map(([phase, entries]) => {
|
||||
const phaseConfig = this.phaseConfig[phase] || { icon: '📋', displayName: phase };
|
||||
const validEntries = entries.filter(entry => entry && typeof entry === 'object');
|
||||
@@ -211,9 +203,8 @@ class AuditService {
|
||||
.map(e => this.compressEntry(e))
|
||||
.filter((e): e is CompressedAuditEntry => e !== null)
|
||||
};
|
||||
}).filter(phase => phase.entries.length > 0); // Only include phases with valid entries
|
||||
}).filter(phase => phase.entries.length > 0);
|
||||
|
||||
// Generate analysis summary
|
||||
const summary = this.generateSummary(rawAuditTrail, avgConfidence, lowConfidenceSteps);
|
||||
|
||||
const result: ProcessedAuditTrail = {
|
||||
@@ -261,12 +252,9 @@ class AuditService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compress data based on detail level
|
||||
*/
|
||||
private compressData(data: any): any {
|
||||
if (this.config.detailLevel === 'verbose') {
|
||||
return data; // Keep full data
|
||||
return data;
|
||||
} else if (this.config.detailLevel === 'standard') {
|
||||
return this.summarizeForStorage(data);
|
||||
} else {
|
||||
@@ -274,9 +262,6 @@ class AuditService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Summarize data for display purposes
|
||||
*/
|
||||
private summarizeData(data: any): string {
|
||||
if (data === null || data === undefined) return 'null';
|
||||
if (typeof data === 'string') {
|
||||
@@ -327,15 +312,11 @@ class AuditService {
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate analysis summary
|
||||
*/
|
||||
private generateSummary(entries: AuditEntry[], avgConfidence: number, lowConfidenceSteps: number): {
|
||||
analysisQuality: 'excellent' | 'good' | 'fair' | 'poor';
|
||||
keyInsights: string[];
|
||||
potentialIssues: string[];
|
||||
} {
|
||||
// Determine analysis quality
|
||||
let analysisQuality: 'excellent' | 'good' | 'fair' | 'poor';
|
||||
if (avgConfidence >= 85 && lowConfidenceSteps === 0) {
|
||||
analysisQuality = 'excellent';
|
||||
@@ -347,7 +328,6 @@ class AuditService {
|
||||
analysisQuality = 'poor';
|
||||
}
|
||||
|
||||
// Generate key insights
|
||||
const keyInsights: string[] = [];
|
||||
const embeddingsUsed = entries.some(e => e.action === 'embeddings-search');
|
||||
if (embeddingsUsed) {
|
||||
@@ -362,7 +342,6 @@ class AuditService {
|
||||
}
|
||||
}
|
||||
|
||||
// Identify potential issues
|
||||
const potentialIssues: string[] = [];
|
||||
if (lowConfidenceSteps > 2) {
|
||||
potentialIssues.push(`${lowConfidenceSteps} Analyseschritte mit niedriger Konfidenz`);
|
||||
@@ -380,16 +359,10 @@ class AuditService {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get translated action name
|
||||
*/
|
||||
getActionDisplayName(action: string): string {
|
||||
return this.actionTranslations[action] || action;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format duration for display
|
||||
*/
|
||||
formatDuration(ms: number): string {
|
||||
if (ms < 1000) return '< 1s';
|
||||
if (ms < 60000) return `${Math.ceil(ms / 1000)}s`;
|
||||
@@ -398,30 +371,20 @@ class AuditService {
|
||||
return seconds > 0 ? `${minutes}m ${seconds}s` : `${minutes}m`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get confidence color for UI
|
||||
*/
|
||||
getConfidenceColor(confidence: number): string {
|
||||
if (confidence >= 80) return 'var(--color-accent)';
|
||||
if (confidence >= 60) return 'var(--color-warning)';
|
||||
return 'var(--color-error)';
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if audit is enabled
|
||||
*/
|
||||
isEnabled(): boolean {
|
||||
return this.config.enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current configuration
|
||||
*/
|
||||
getConfig(): AuditConfig {
|
||||
return { ...this.config };
|
||||
}
|
||||
}
|
||||
|
||||
// Export singleton instance
|
||||
export const auditService = new AuditService();
|
||||
export type { ProcessedAuditTrail, CompressedAuditEntry };
|
||||
@@ -37,19 +37,17 @@ class EmbeddingsService {
|
||||
private readonly embeddingsPath = path.join(process.cwd(), 'data', 'embeddings.json');
|
||||
private readonly batchSize: number;
|
||||
private readonly batchDelay: number;
|
||||
private enabled: boolean = false; // Make mutable again
|
||||
private enabled: boolean = false;
|
||||
|
||||
constructor() {
|
||||
this.batchSize = parseInt(process.env.AI_EMBEDDINGS_BATCH_SIZE || '20', 10);
|
||||
this.batchDelay = parseInt(process.env.AI_EMBEDDINGS_BATCH_DELAY_MS || '1000', 10);
|
||||
|
||||
// Don't call async method from constructor - handle in initialize() instead
|
||||
this.enabled = true; // Start optimistically enabled for development
|
||||
this.enabled = true;
|
||||
}
|
||||
|
||||
private async checkEnabledStatus(): Promise<void> {
|
||||
try {
|
||||
// Add debugging to see what's actually in process.env
|
||||
console.log('[EMBEDDINGS] Debug env check:', {
|
||||
AI_EMBEDDINGS_ENABLED: process.env.AI_EMBEDDINGS_ENABLED,
|
||||
envKeys: Object.keys(process.env).filter(k => k.includes('EMBEDDINGS')).length,
|
||||
@@ -59,7 +57,6 @@ class EmbeddingsService {
|
||||
const envEnabled = process.env.AI_EMBEDDINGS_ENABLED;
|
||||
|
||||
if (envEnabled === 'true') {
|
||||
// Check if we have the required API configuration
|
||||
const endpoint = process.env.AI_EMBEDDINGS_ENDPOINT;
|
||||
const model = process.env.AI_EMBEDDINGS_MODEL;
|
||||
|
||||
@@ -74,7 +71,6 @@ class EmbeddingsService {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if embeddings file exists
|
||||
try {
|
||||
await fs.stat(this.embeddingsPath);
|
||||
console.log('[EMBEDDINGS] Existing embeddings file found - enabling');
|
||||
@@ -103,7 +99,6 @@ class EmbeddingsService {
|
||||
}
|
||||
|
||||
private async performInitialization(): Promise<void> {
|
||||
// 1️⃣ Respect the on/off switch that the newer code introduced
|
||||
await this.checkEnabledStatus();
|
||||
if (!this.enabled) {
|
||||
console.log('[EMBEDDINGS] Embeddings disabled, skipping initialization');
|
||||
@@ -114,14 +109,11 @@ class EmbeddingsService {
|
||||
try {
|
||||
console.log('[EMBEDDINGS] Initializing embeddings system…');
|
||||
|
||||
// Make sure the data folder exists
|
||||
await fs.mkdir(path.dirname(this.embeddingsPath), { recursive: true });
|
||||
|
||||
// Load current tools / concepts and generate a hash
|
||||
const toolsData = await getCompressedToolsDataForAI();
|
||||
const currentDataHash = await this.hashToolsFile(); // <- keep the old helper
|
||||
const currentDataHash = await this.hashToolsFile();
|
||||
|
||||
// Try to read an existing file
|
||||
const existing = await this.loadEmbeddings();
|
||||
console.log('[EMBEDDINGS] Current hash:', currentDataHash);
|
||||
console.log('[EMBEDDINGS] Existing file version:', existing?.version);
|
||||
@@ -138,8 +130,7 @@ class EmbeddingsService {
|
||||
this.embeddings = existing.embeddings;
|
||||
} else {
|
||||
console.log('[EMBEDDINGS] Generating new embeddings…');
|
||||
// 2️⃣ Build and persist new vectors
|
||||
await this.generateEmbeddings(toolsData, currentDataHash); // <- old helper
|
||||
await this.generateEmbeddings(toolsData, currentDataHash);
|
||||
}
|
||||
|
||||
this.isInitialized = true;
|
||||
@@ -147,9 +138,8 @@ class EmbeddingsService {
|
||||
} catch (err) {
|
||||
console.error('[EMBEDDINGS] Failed to initialize:', err);
|
||||
this.isInitialized = false;
|
||||
throw err; // Let the caller know – same behaviour as before
|
||||
throw err;
|
||||
} finally {
|
||||
// 3️⃣ Always clear the promise so subsequent calls don't hang
|
||||
this.initializationPromise = null;
|
||||
}
|
||||
}
|
||||
@@ -157,7 +147,7 @@ class EmbeddingsService {
|
||||
private async hashToolsFile(): Promise<string> {
|
||||
const file = path.join(process.cwd(), 'src', 'data', 'tools.yaml');
|
||||
const raw = await fs.readFile(file, 'utf8');
|
||||
return crypto.createHash('sha256').update(raw).digest('hex'); // 64-char hex
|
||||
return crypto.createHash('sha256').update(raw).digest('hex');
|
||||
}
|
||||
|
||||
private async loadEmbeddings(): Promise<EmbeddingsDatabase | null> {
|
||||
@@ -298,7 +288,6 @@ class EmbeddingsService {
|
||||
}
|
||||
|
||||
async waitForInitialization(): Promise<void> {
|
||||
// Always re-check environment status first in case variables loaded after initial check
|
||||
await this.checkEnabledStatus();
|
||||
|
||||
if (!this.enabled || this.isInitialized) {
|
||||
@@ -313,7 +302,6 @@ class EmbeddingsService {
|
||||
return this.initialize();
|
||||
}
|
||||
|
||||
// Force re-check of environment status (useful for development)
|
||||
async forceRecheckEnvironment(): Promise<void> {
|
||||
this.enabled = false;
|
||||
this.isInitialized = false;
|
||||
@@ -342,7 +330,6 @@ class EmbeddingsService {
|
||||
}
|
||||
|
||||
try {
|
||||
// If we have embeddings data, use it
|
||||
if (this.isInitialized && this.embeddings.length > 0) {
|
||||
console.log(`[EMBEDDINGS] Using embeddings data for similarity search: ${query}`);
|
||||
|
||||
@@ -394,7 +381,6 @@ class EmbeddingsService {
|
||||
return results;
|
||||
|
||||
} else {
|
||||
// Fallback: generate mock similarity results from actual tools data
|
||||
console.log(`[EMBEDDINGS] No embeddings data, using fallback text matching: ${query}`);
|
||||
|
||||
const { getToolsData } = await import('./dataService.js');
|
||||
@@ -407,17 +393,14 @@ class EmbeddingsService {
|
||||
.map((tool: any) => {
|
||||
let similarity = 0;
|
||||
|
||||
// Name matching
|
||||
if (tool.name.toLowerCase().includes(queryLower)) {
|
||||
similarity += 0.8;
|
||||
}
|
||||
|
||||
// Description matching
|
||||
if (tool.description && tool.description.toLowerCase().includes(queryLower)) {
|
||||
similarity += 0.6;
|
||||
}
|
||||
|
||||
// Tag matching
|
||||
if (tool.tags && Array.isArray(tool.tags)) {
|
||||
const matchingTags = tool.tags.filter((tag: string) =>
|
||||
tag.toLowerCase().includes(queryLower) || queryLower.includes(tag.toLowerCase())
|
||||
@@ -427,7 +410,6 @@ class EmbeddingsService {
|
||||
}
|
||||
}
|
||||
|
||||
// Word-level matching
|
||||
const toolText = `${tool.name} ${tool.description || ''} ${(tool.tags || []).join(' ')}`.toLowerCase();
|
||||
const matchingWords = queryWords.filter(word => toolText.includes(word));
|
||||
if (queryWords.length > 0) {
|
||||
@@ -439,7 +421,7 @@ class EmbeddingsService {
|
||||
type: 'tool' as const,
|
||||
name: tool.name,
|
||||
content: toolText,
|
||||
embedding: [], // Empty for fallback
|
||||
embedding: [],
|
||||
metadata: {
|
||||
domains: tool.domains || [],
|
||||
phases: tool.phases || [],
|
||||
@@ -465,10 +447,7 @@ class EmbeddingsService {
|
||||
}
|
||||
|
||||
isEnabled(): boolean {
|
||||
// If not enabled and not initialized, try re-checking environment
|
||||
// This handles the case where environment variables loaded after initial check
|
||||
if (!this.enabled && !this.isInitialized) {
|
||||
// Don't await this, just trigger it and return current status
|
||||
this.checkEnabledStatus().catch(console.error);
|
||||
}
|
||||
|
||||
@@ -477,7 +456,7 @@ class EmbeddingsService {
|
||||
|
||||
getStats(): { enabled: boolean; initialized: boolean; count: number } {
|
||||
return {
|
||||
enabled: this.enabled, // Always true during development
|
||||
enabled: this.enabled,
|
||||
initialized: this.isInitialized,
|
||||
count: this.embeddings.length
|
||||
};
|
||||
|
||||
@@ -338,7 +338,7 @@ export class NextcloudUploader {
|
||||
info: {
|
||||
path: remotePath,
|
||||
exists: true,
|
||||
response: text.substring(0, 200) + '...' // Truncated for safety
|
||||
response: text.substring(0, 200) + '...'
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user