~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.
Python academiaanthropicarxivbravedeep-researchencryptionhome-automationhomeserverlocallocal-deep-researchlocal-llmmistralollamaopenaipubmedresearchresearch-toolretrieval-augmented-generationsearxngself-hosted
initial log panel
hashedviking9aa27c66324e
diff --git a/static/css/styles.css b/static/css/styles.cssindex 77a4acbbf0..9e16c92cb3 100644--- a/static/css/styles.css+++ b/static/css/styles.css@@ -132,6 +132,12 @@ a:hover {width: calc(100% - 240px);}+/* Add padding to bottom of main content when log panel is visible */+.page#research-progress.active ~ .main-content,+.page#research-results.active ~ .main-content {+ padding-bottom: 42vh; /* Log panel max height + some extra */+}+.page {display: none;}@@ -927,10 +933,15 @@ textarea:focus, input[type="text"]:focus {}.main-content {- padding: 1rem;- padding-bottom: 70px; /* Add padding for the tab bar */margin-left: 0;width: 100%;+ padding-bottom: 70px; /* Account for mobile tab bar */+ }++ /* Adjust padding for mobile when log panel is visible */+ .page#research-progress.active ~ .main-content,+ .page#research-results.active ~ .main-content {+ padding-bottom: calc(42vh + 60px); /* Log panel + mobile tab bar */}.sidebar {@@ -1005,4 +1016,183 @@ textarea:focus, input[type="text"]:focus {#try-again-btn i {margin-right: 5px;+}++/* Collapsible Log Panel */+.collapsible-log-panel {+ position: fixed;+ bottom: 0;+ left: 240px; /* Same as sidebar width */+ right: 0;+ z-index: 100;+ border: 1px solid var(--border-color);+ border-radius: 8px 8px 0 0;+ background-color: var(--bg-tertiary);+ display: flex;+ flex-direction: column;+ max-height: 40vh; /* Maximum height of 40% of viewport */+ box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.2);+ padding: 0;+ margin: 0;+ /* Hide by default, only show on research-progress and research-results pages */+ display: none;+}++/* Only show log panel on research-progress and relevant pages */+.page#research-progress.active ~ .collapsible-log-panel,+.page#research-results.active ~ .collapsible-log-panel {+ display: flex;+}++/* Adjust for smaller screens */+@media (max-width: 991px) {+ .collapsible-log-panel {+ left: 60px; /* Adjust for collapsed sidebar */+ }+}++@media (max-width: 767px) {+ .collapsible-log-panel {+ left: 0; /* Full width on mobile */+ bottom: 60px; /* Account for mobile tab bar */+ }+}++.log-panel-header {+ display: flex;+ align-items: center;+ padding: 0.75rem 1rem;+ background: var(--gradient-bg);+ cursor: pointer;+ user-select: none;+ transition: background-color 0.2s;+ z-index: 101;+ border-radius: 8px 8px 0 0;+}++.log-panel-header:hover {+ background-color: var(--bg-secondary);+}++.log-panel-header .toggle-icon {+ margin-right: 0.75rem;+ transition: transform 0.3s ease;+}++.log-panel-header.collapsed .toggle-icon {+ transform: rotate(-90deg);+}++.log-indicator {+ margin-left: auto;+ background-color: var(--accent-primary);+ color: white;+ border-radius: 12px;+ padding: 0.1rem 0.5rem;+ font-size: 0.75rem;+ min-width: 1.5rem;+ text-align: center;+}++.log-panel-content {+ display: flex;+ flex-direction: column;+ overflow: hidden;+ height: calc(40vh - 40px); /* Viewport height minus header */+ transition: height 0.3s ease;+}++.log-panel-content.collapsed {+ height: 0 !important;+ overflow: hidden;+ display: none;+}++.log-controls {+ display: flex;+ justify-content: space-between;+ align-items: center;+ padding: 0.5rem 1rem;+ border-bottom: 1px solid var(--border-color);+ background-color: rgba(0, 0, 0, 0.2);+}++.log-filter {+ display: flex;+ align-items: center;+ gap: 0.5rem;+}++.log-filter select {+ background-color: var(--bg-secondary);+ color: var(--text-primary);+ border: 1px solid var(--border-color);+ padding: 0.25rem 0.5rem;+ border-radius: 4px;+}++.console-log {+ padding: 0.5rem 1rem;+ font-family: 'Consolas', 'Monaco', monospace;+ font-size: 0.85rem;+ line-height: 1.4;+ overflow-y: auto;+ height: 100%;+}++.console-log-entry {+ padding: 0.5rem 1rem;+ display: flex;+ align-items: flex-start;+ border-bottom: 1px solid rgba(255, 255, 255, 0.05);+}++.console-log-entry:hover {+ background-color: rgba(0, 0, 0, 0.2);+}++.console-log-entry .log-timestamp {+ color: var(--text-muted);+ min-width: 4.5rem;+ margin-right: 0.5rem;+ font-size: 0.75rem;+}++.console-log-entry .log-badge {+ display: inline-block;+ padding: 0 0.4rem;+ margin-right: 0.5rem;+ border-radius: 3px;+ font-size: 0.7rem;+ text-transform: uppercase;+ font-weight: bold;+ line-height: 1.4;+}++.console-log-entry .log-message {+ flex: 1;+ word-break: break-word;+ padding-right: 1rem;+}++.console-log-entry.log-milestone .log-badge {+ background-color: var(--accent-primary);+ color: white;+}++.console-log-entry.log-error .log-badge {+ background-color: var(--error-color);+ color: white;+}++.console-log-entry.log-info .log-badge {+ background-color: var(--accent-tertiary);+ color: white;+}++.empty-log-message {+ color: var(--text-muted);+ padding: 1rem;+ text-align: center;+ font-style: italic;}\ No newline at end of filediff --git a/static/js/app.js b/static/js/app.jsindex 99ed3a3858..743930d014 100644--- a/static/js/app.js+++ b/static/js/app.js@@ -198,137 +198,230 @@ document.addEventListener('DOMContentLoaded', () => {}};- // Helper function to connect to research updates+ // Connect to the research socket for real-time updateswindow.connectToResearchSocket = function(researchId) {- try {- // Check if the research ID is valid- if (!researchId) {- console.error('Invalid research ID for socket connection');- return false;+ if (socket) {+ if (!socketConnected) {+ // Try to reconnect+ socket.connect();}- // First disconnect any existing socket to avoid duplicates- window.disconnectSocket();+ // Subscribe to this research+ socket.emit('subscribe_to_research', { research_id: researchId });- // Initialize socket if needed- socket = initializeSocket();+ // Add socket event handlers for this research+ const eventName = `research_progress_${researchId}`;- if (!socket) {- console.error('Failed to initialize socket for research updates');- return false;- }+ // Remove any existing listeners to avoid duplicates+ socket.off(eventName);- // Subscribe to research updates- socket.emit('subscribe_to_research', { research_id: researchId });+ // Add a new listener+ socket.on(eventName, function(data) {+ // Pass the data to our event handler+ window.handleResearchProgressEvent(data);+ });- // Set up event listener for research progress- const progressEventName = `research_progress_${researchId}`;+ console.log(`Connected to socket for research ${researchId}`);+ } else {+ console.error('Socket not initialized');+ initializeSocket();+ // Try again after initialization+ setTimeout(() => {+ window.connectToResearchSocket(researchId);+ }, 1000);+ }+ };++ // Format the research status for display+ function formatStatus(status) {+ if (!status) return 'Unknown';++ // Handle in_progress specially+ if (status === 'in_progress') return 'In Progress';++ // Capitalize first letter for other statuses+ return status.charAt(0).toUpperCase() + status.slice(1).toLowerCase();+ }++ // Format the research mode for display+ function formatMode(mode) {+ if (!mode) return 'Unknown';++ return mode === 'detailed' ? 'Detailed Report' : 'Quick Summary';+ }++ // Format a date for display+ function formatDate(date) {+ // Handle null/undefined gracefully+ if (!date) return 'Unknown';- // Remove existing listeners to prevent duplicates+ // Check if we have a date string instead of a Date object+ if (typeof date === 'string') {try {- socket.off(progressEventName);+ // Handle ISO string with microseconds (which causes problems)+ if (date.includes('.') && date.includes('T')) {+ // Extract only up to milliseconds (3 digits after dot) or remove microseconds entirely+ const parts = date.split('.');+ if (parts.length > 1) {+ // If there's a Z or + or - after microseconds, preserve it+ let timezone = '';+ const microsecondPart = parts[1];+ const tzIndex = microsecondPart.search(/[Z+-]/);++ if (tzIndex !== -1) {+ timezone = microsecondPart.substring(tzIndex);+ }++ // Use only milliseconds (first 3 digits after dot) or none if format issues+ const milliseconds = microsecondPart.substring(0, Math.min(3, tzIndex !== -1 ? tzIndex : microsecondPart.length));++ // Reconstruct with controlled precision+ const cleanedDateStr = parts[0] + (milliseconds.length > 0 ? '.' + milliseconds : '') + timezone;+ date = new Date(cleanedDateStr);+ } else {+ date = new Date(date);+ }+ } else {+ date = new Date(date);+ }} catch (e) {- console.warn(`Error removing existing listeners for ${progressEventName}`, e);+ console.warn('Error parsing date string:', e);+ return 'Invalid date'; // Return error message if we can't parse}+ }++ // Ensure we're handling the date properly+ if (!(date instanceof Date) || isNaN(date.getTime())) {+ console.warn('Invalid date provided to formatDate:', date);+ return 'Invalid date';+ }++ // Get current year to compare with date year+ const currentYear = new Date().getFullYear();+ const dateYear = date.getFullYear();++ // Get month name, day, and time+ const month = date.toLocaleString('en-US', { month: 'short' });+ const day = date.getDate();+ const hours = date.getHours().toString().padStart(2, '0');+ const minutes = date.getMinutes().toString().padStart(2, '0');++ // Format like "Feb 25, 08:09" or "Feb 25, 2022, 08:09" if not current year+ if (dateYear === currentYear) {+ return `${month} ${day}, ${hours}:${minutes}`;+ } else {+ return `${month} ${day}, ${dateYear}, ${hours}:${minutes}`;+ }+ }++ // Update the socket event handler to prevent duplicate log messages+ window.handleResearchProgressEvent = function(data) {+ console.log('Research progress update:', data);++ // Track processed messages to prevent duplicates+ window.processedMessages = window.processedMessages || new Set();++ // Add to console log if there's a message+ if (data.message) {+ let logType = 'info';++ // Create a unique identifier for this message (message + timestamp if available)+ const messageId = data.message + (data.log_entry?.time || '');- // Add new listener- socket.on(progressEventName, (data) => {- console.log('Received research progress update:', data);+ // Check if we've already processed this message+ if (!window.processedMessages.has(messageId)) {+ window.processedMessages.add(messageId);- // Handle different message types- if (data.status === 'in_progress') {- // Update progress- updateProgressUI(data.progress, data.status, data.message);- } else if (data.status === 'completed') {- // Research completed- console.log('Socket received research complete notification');-- // Clear polling interval- if (pollingInterval) {- console.log('Clearing polling interval from socket event');- clearInterval(pollingInterval);- pollingInterval = null;- }-- // Load the results- loadResearch(researchId);-- // Play notification sound- console.log('Playing success notification sound from socket event');- playNotificationSound('success');-- // Clean up resources- window.cleanupResearchResources();-- // Update navigation and research status display- updateNavigationBasedOnResearchStatus();-- // Update history item status if on history page- updateHistoryItemStatus(researchId, 'completed');-- // Dispatch event for any other components that need to know about completion- document.dispatchEvent(new CustomEvent('research_completed', { detail: data }));- } else if (data.status === 'failed' || data.status === 'suspended') {- // Research failed or was suspended- console.log(`Socket received research final state: ${data.status}`);-- // Clear polling interval- if (pollingInterval) {- console.log('Clearing polling interval from socket event');- clearInterval(pollingInterval);- pollingInterval = null;- }-- // Get the error message from the socket response- const errorText = data.error || data.message || (data.status === 'failed' ? 'Research failed' : 'Research was suspended');- console.log(`Error message from socket: ${errorText}`);-- // Show error message- console.log(`Showing error message for status: ${data.status} from socket event`);- const errorMessage = document.getElementById('error-message');- if (errorMessage) {- errorMessage.style.display = 'block';- errorMessage.textContent = errorText;- }-- // Update UI with status- updateProgressUI(- 0,- data.status,- errorText- );-- // Update history item status if on history page- updateHistoryItemStatus(researchId, data.status, errorText);-- // Update navigation- updateNavigationBasedOnResearchStatus();-- if (data.status === 'failed') {- console.log('Playing error notification sound from socket event');- playNotificationSound('error');- }-- // Clean up resources- window.cleanupResearchResources();-- // Update navigation and research status display- updateNavigationBasedOnResearchStatus();-- // Dispatch event for any other components that need to know about completion- document.dispatchEvent(new CustomEvent('research_completed', { detail: data }));+ // Determine log type based on status or message content+ if (data.status === 'failed' || data.status === 'suspended') {+ logType = 'error';+ } else if (isMilestoneLog(data.message, data.log_entry?.metadata)) {+ logType = 'milestone';+ }++ addConsoleLog(data.message, logType);+ }+ }++ // Add error messages to log+ if (data.error && !window.processedMessages.has('error:' + data.error)) {+ window.processedMessages.add('error:' + data.error);+ addConsoleLog(data.error, 'error');+ }++ // Update progress UI if progress is provided+ if (data.progress !== undefined) {+ updateProgressUI(data.progress, data.status, data.message);+ }++ // Update detail log if log_entry is provided+ if (data.log_entry) {+ updateDetailLogEntry(data.log_entry);+ }++ // Handle completion states+ if (data.status === 'completed' || data.status === 'failed' || data.status === 'suspended') {+ const researchId = getActiveResearchId();+ if (!researchId) return;++ // Clear polling interval+ if (pollingInterval) {+ console.log('Clearing polling interval from socket event');+ clearInterval(pollingInterval);+ pollingInterval = null;+ }++ if (data.status === 'completed') {+ // Success sound and notification+ playNotificationSound('success');++ // Store the completed research ID for navigation+ const completedResearchId = researchId;++ // Reset current research ID+ currentResearchId = null;+ window.currentResearchId = null;++ // Update navigation state+ isResearchInProgress = false;+ updateNavigationBasedOnResearchStatus();++ // Navigate to results page with a slight delay to ensure all updates are processed+ setTimeout(() => {+ // Load the research results+ loadResearch(completedResearchId);+ }, 800);+ } else {+ // Error sound and notification+ playNotificationSound('error');++ // Show error message and Try Again button for errors and terminations+ const errorMessage = document.getElementById('error-message');+ const tryAgainBtn = document.getElementById('try-again-btn');++ if (errorMessage) {+ errorMessage.textContent = data.error || 'Research was terminated';+ errorMessage.style.display = 'block';}- // Update the detailed log if on details page- if (data.log_entry && document.getElementById('research-log')) {- updateDetailLogEntry(data.log_entry);+ if (tryAgainBtn) {+ tryAgainBtn.style.display = 'block';}- });++ // Update navigation - important for correctly showing/hiding various elements+ // based on the current research state+ isResearchInProgress = false;+ updateNavigationBasedOnResearchStatus();++ // Reset current research ID+ currentResearchId = null;+ window.currentResearchId = null;+ }- return true;- } catch (e) {- console.error('Error connecting to research socket:', e);- return false;+ // Refresh the history list to show the completed research+ if (document.getElementById('history').classList.contains('active')) {+ loadResearchHistory();+ }}};@@ -412,223 +505,262 @@ document.addEventListener('DOMContentLoaded', () => {// Function to start researchasync function startResearch(query, mode) {- // Reset potentially stale state- if (isResearchInProgress) {- // Force a fresh check of active research status- try {- const response = await fetch(getApiUrl('/api/history'));- const history = await response.json();-- // Find any in-progress research- const activeResearch = history.find(item => item.status === 'in_progress');-- // If no active research is found, reset the state- if (!activeResearch) {- console.log('Resetting stale research state - no active research found in history');- window.cleanupResearchResources();- } else {- alert('Another research is already in progress. Please wait for it to complete or check its status in the history tab.');- return;- }- } catch (error) {- console.error('Error checking for active research:', error);- }- }-- // Get the start button- const startResearchBtn = document.getElementById('start-research-btn');- if (!startResearchBtn) return;-- // Disable the start button while we attempt to start the research- startResearchBtn.disabled = true;- startResearchBtn.innerHTML = '<i class="fas fa-spinner fa-spin"></i> Starting...';-try {- // Set the favicon based on research mode+ // Reset any previous research states+ window.cleanupResearchResources();+ clearPollingInterval();++ // Clear logs when starting new research+ clearConsoleLogs();++ // Add initial log entry+ addConsoleLog(`Starting research: ${query}`, 'milestone');++ // Set favicon based on research modesetFavicon(mode);+ // Show loading state+ const startBtn = document.getElementById('start-research-btn');+ if (startBtn) {+ startBtn.innerHTML = '<div class="spinner-small"></div> Starting...';+ startBtn.disabled = true;+ }++ // Setup the form data+ const data = {+ query: query,+ mode: mode+ };++ // Make the API requestconst response = await fetch(getApiUrl('/api/start_research'), {method: 'POST',headers: {'Content-Type': 'application/json'},- body: JSON.stringify({- query: query,- mode: mode- })+ body: JSON.stringify(data)});- const data = await response.json();+ const result = await response.json();- if (data.status === 'success') {- isResearchInProgress = true;- currentResearchId = data.research_id;-- // Also update the window object- window.currentResearchId = data.research_id;-- // Update the navigation to show Research in Progress- updateNavigationBasedOnResearchStatus();+ if (result.status === 'success') {+ // Store the research ID for progress tracking+ window.currentResearchId = result.research_id;- // Update progress page- document.getElementById('current-query').textContent = query;- document.getElementById('progress-fill').style.width = '0%';- document.getElementById('progress-percentage').textContent = '0%';- document.getElementById('progress-status').textContent = 'Initializing research process...';+ // Add a log entry+ addConsoleLog(`Research started with ID: ${result.research_id}`, 'info');// Navigate to progress pageswitchPage('research-progress');- // Connect to socket for this research- window.connectToResearchSocket(data.research_id);+ // Update the current query display+ const currentQueryEl = document.getElementById('current-query');+ if (currentQueryEl) {+ currentQueryEl.textContent = query;+ }- // Start polling for status- pollResearchStatus(data.research_id);+ // Set up progress polling+ pollResearchStatus(result.research_id);++ // Also try to subscribe via socket for real-time updates+ if (socket && socket.connected) {+ socket.emit('subscribe_to_research', { research_id: result.research_id });+ addConsoleLog('Connected to real-time updates', 'info');+ }// Show the terminate buttonconst terminateBtn = document.getElementById('terminate-research-btn');if (terminateBtn) {- terminateBtn.style.display = 'inline-flex';- terminateBtn.disabled = false;+ terminateBtn.style.display = 'block';+ }++ // Hide any previous error message+ const errorMessage = document.getElementById('error-message');+ if (errorMessage) {+ errorMessage.style.display = 'none';+ }++ // Hide any previous try again button+ const tryAgainBtn = document.getElementById('try-again-btn');+ if (tryAgainBtn) {+ tryAgainBtn.style.display = 'none';}++ // Reset progress UI+ updateProgressUI(0, 'in_progress', 'Initializing research process...');++ // Update navigation+ updateNavigationBasedOnResearchStatus();} else {- // Reset favicon to default on error- createDynamicFavicon('⚡');+ // Handle error+ const errorMessage = result.message || 'Failed to start research';+ console.error('Research start error:', errorMessage);++ // Add error to log+ addConsoleLog(`Error: ${errorMessage}`, 'error');++ alert(errorMessage);- alert('Error starting research: ' + (data.message || 'Unknown error'));- startResearchBtn.disabled = false;- startResearchBtn.innerHTML = '<i class="fas fa-rocket"></i> Start Research';+ // Reset the favicon+ setFavicon('default');++ // Reset button state+ if (startBtn) {+ startBtn.innerHTML = '<i class="fas fa-rocket"></i> Start Research';+ startBtn.disabled = false;+ }}} catch (error) {- // Reset favicon to default on error- createDynamicFavicon('⚡');+ console.error('Error starting research:', error);++ // Add error to log+ addConsoleLog(`Error: ${error.message}`, 'error');++ // Reset the favicon+ setFavicon('default');++ // Reset button state+ const startBtn = document.getElementById('start-research-btn');+ if (startBtn) {+ startBtn.innerHTML = '<i class="fas fa-rocket"></i> Start Research';+ startBtn.disabled = false;+ }- console.error('Error:', error);alert('An error occurred while starting the research. Please try again.');- startResearchBtn.disabled = false;- startResearchBtn.innerHTML = '<i class="fas fa-rocket"></i> Start Research';}}- // Function to poll research status (as a backup to socket.io)+ // Function to clear any existing polling interval+ function clearPollingInterval() {+ if (pollingInterval) {+ console.log('Clearing existing polling interval');+ clearInterval(pollingInterval);+ pollingInterval = null;+ }+ }++ // Update the polling function to use a more robust approachfunction pollResearchStatus(researchId) {- console.log(`Polling research status for ID: ${researchId}`);- fetch(getApiUrl(`/api/research/${researchId}`))- .then(response => {- if (!response.ok) {- throw new Error(`Server returned ${response.status}`);- }- return response.json();- })- .then(data => {- console.log('Research status response:', data);-- // Get the latest progress and log data- const progress = data.progress || 0;- const status = data.status || 'in_progress';-- // Get the latest message from the log if available- let latestMessage = "Processing research...";- if (data.log && Array.isArray(data.log) && data.log.length > 0) {- const latestLog = data.log[data.log.length - 1];- if (latestLog && latestLog.message) {- latestMessage = latestLog.message;- }- }-- // Update the UI with the current progress - always- updateProgressUI(progress, status, latestMessage);-- // If research is complete, show the completion buttons- if (status === 'completed' || status === 'failed' || status === 'suspended') {- console.log(`Research is in final state: ${status}`);- // Clear the polling interval- if (pollingInterval) {- console.log('Clearing polling interval');- clearInterval(pollingInterval);- pollingInterval = null;- }-- // Update UI for completion- if (status === 'completed') {- console.log('Research completed, loading results automatically');- // Hide the terminate button- const terminateBtn = document.getElementById('terminate-research-btn');- if (terminateBtn) {- terminateBtn.style.display = 'none';- }-- // Update history item status- updateHistoryItemStatus(researchId, 'completed');-- // Auto-load the results instead of showing a button- loadResearch(researchId);- } else if (status === 'failed' || status === 'suspended') {- console.log(`Showing error message for status: ${status}`);+ if (!researchId) {+ console.error('No research ID provided for polling');+ return;+ }++ // Reset message deduplication when starting a new poll+ window.processedMessages = new Set();++ // Update UI to show loading+ document.getElementById('current-query').textContent = 'Loading research...';++ console.log(`Starting polling for research ${researchId}`);++ // Ensure we have a socket connection+ if (typeof window.connectToResearchSocket === 'function') {+ window.connectToResearchSocket(researchId);+ }++ // Set polling interval for updates+ if (pollingInterval) {+ clearInterval(pollingInterval);+ }++ // Make an immediate request+ checkResearchStatus(researchId);++ // Then set up polling+ pollingInterval = setInterval(() => {+ checkResearchStatus(researchId);+ }, 2000); // Poll every 2 seconds++ // Function to check research status+ function checkResearchStatus(researchId) {+ fetch(getApiUrl(`/api/research/${researchId}`))+ .then(response => response.json())+ .then(data => {+ // Process status update+ if (data) {+ // Update UI with progress+ const progress = data.progress || 0;+ const status = data.status || 'in_progress';- // Get error message from metadata if available or use latest message- let errorText = latestMessage;- if (data.metadata && typeof data.metadata === 'string') {- try {- const metadataObj = JSON.parse(data.metadata);- if (metadataObj.error) {- errorText = metadataObj.error;+ // Get most recent message+ let message = '';+ if (data.log && data.log.length > 0) {+ // Get the latest unique log entry+ for (let i = data.log.length - 1; i >= 0; i--) {+ const latestLog = data.log[i];+ const messageId = latestLog.message + (latestLog.time || '');++ if (!window.processedMessages.has(messageId)) {+ window.processedMessages.add(messageId);+ message = latestLog.message || '';++ // Add to console logs+ if (message) {+ let logType = 'info';+ if (isMilestoneLog(message, latestLog.metadata)) {+ logType = 'milestone';+ }+ addConsoleLog(message, logType);+ }++ break; // Only process one message per poll}- } catch (e) {- console.log('Error parsing metadata:', e);}}- // Show error message in UI- const errorMessage = document.getElementById('error-message');- if (errorMessage) {- errorMessage.style.display = 'block';- errorMessage.textContent = errorText;- console.log('Set error message to:', errorText);+ // Update progress UI+ updateProgressUI(progress, status, message || 'Processing research...');++ // Update the UI based on research status+ if (status === 'completed' || status === 'failed' || status === 'suspended') {+ // Clear polling interval+ if (pollingInterval) {+ console.log('Clearing polling interval due to status change');+ clearInterval(pollingInterval);+ pollingInterval = null;+ }++ // Handle completion or failure+ if (status === 'completed') {+ addConsoleLog('Research completed successfully', 'milestone');+ playNotificationSound('success');+ } else {+ addConsoleLog(`Research ${status}`, 'error');+ playNotificationSound('error');++ // Show error message and Try Again button+ const errorMessage = document.getElementById('error-message');+ const tryAgainBtn = document.getElementById('try-again-btn');++ if (errorMessage) {+ errorMessage.textContent = data.error || `Research was ${status}`;+ errorMessage.style.display = 'block';+ }++ if (tryAgainBtn) {+ tryAgainBtn.style.display = 'block';+ }+ }++ // Update navigation+ isResearchInProgress = false;+ currentResearchId = null;+ window.currentResearchId = null;+ updateNavigationBasedOnResearchStatus();} else {- console.error('error-message element not found');+ // Research is still in progress+ isResearchInProgress = true;+ currentResearchId = researchId;+ window.currentResearchId = researchId;}-- // Update progress display with error- updateProgressUI(0, status, errorText);-- // Update history item status- updateHistoryItemStatus(researchId, status, errorText);- }-- // Play notification sound based on status- if (status === 'completed') {- console.log('Playing success notification sound');- playNotificationSound('success');- } else if (status === 'failed') {- console.log('Playing error notification sound');- playNotificationSound('error');- }-- // Update the navigation- console.log('Updating navigation based on research status');- updateNavigationBasedOnResearchStatus();-- // Force the UI to update with a manual trigger- document.dispatchEvent(new CustomEvent('research_completed', { detail: data }));-- return;- }-- // Continue polling if still in progress- if (status === 'in_progress') {- console.log('Research is still in progress, continuing polling');- if (!pollingInterval) {- console.log('Setting up polling interval');- pollingInterval = setInterval(() => {- pollResearchStatus(researchId);- }, 10000);}- }- })- .catch(error => {- console.error('Error polling research status:', error);- });+ })+ .catch(error => {+ console.error('Error polling research status:', error);+ // Don't clear the interval on error - just keep trying+ });+ }}// Main initialization function@@ -738,44 +870,34 @@ document.addEventListener('DOMContentLoaded', () => {// Function to switch between pagesfunction switchPage(pageId) {- // Get elements directly from the DOM+ // First hide all pagesconst pages = document.querySelectorAll('.page');- const navItems = document.querySelectorAll('.sidebar-nav li');- const mobileNavItems = document.querySelectorAll('.mobile-tab-bar li');-- // Remove active class from all pages- pages.forEach(page => {- page.classList.remove('active');- });+ pages.forEach(page => page.classList.remove('active'));- // Add active class to target page- const targetPage = document.getElementById(pageId);- if (targetPage) {- targetPage.classList.add('active');+ // Then activate the selected page+ const selectedPage = document.getElementById(pageId);+ if (selectedPage) {+ selectedPage.classList.add('active');}- // Update sidebar navigation active states- navItems.forEach(item => {- if (item.getAttribute('data-page') === pageId) {- item.classList.add('active');- } else {- item.classList.remove('active');- }- });+ // Update the URL hash+ window.location.hash = '#' + pageId;- // Update mobile tab bar active states- mobileNavItems.forEach(item => {- if (item.getAttribute('data-page') === pageId) {- item.classList.add('active');- } else {- item.classList.remove('active');- }- });+ // Update the navigation UI to highlight the active page+ updateNavigationUI(pageId);// Special handling for history pageif (pageId === 'history') {loadResearchHistory();}++ // Reset scroll position for the newly activated page+ window.scrollTo(0, 0);++ console.log(`Switched to page: ${pageId}`);++ // Update the log panel visibility+ updateLogPanelVisibility(pageId);}// Track termination status@@ -1244,165 +1366,155 @@ document.addEventListener('DOMContentLoaded', () => {}}- // Function to load research+ // Function to load research data and display resultsasync function loadResearch(researchId) {try {+ console.log(`Loading research results for ID: ${researchId}`);++ // Show loading indicators+ const resultsContent = document.getElementById('results-content');+ if (resultsContent) {+ resultsContent.innerHTML = '<div class="loading-spinner centered"><div class="spinner"></div></div>';+ }++ // Fetch the research dataconst response = await fetch(getApiUrl(`/api/research/${researchId}`));if (!response.ok) {- throw new Error('Failed to load research');+ throw new Error(`Server returned ${response.status}`);}const data = await response.json();+ console.log('Research data:', data);- if (data.status === 'completed' && data.report_path) {- // Set the favicon based on the research mode- setFavicon(data.mode || 'quick');-- // Get report content- const reportResponse = await fetch(getApiUrl(`/api/report/${researchId}`));- if (!reportResponse.ok) {- throw new Error('Failed to load report');- }+ // Check if the report path exists+ if (!data.report_path && !data.metadata?.report_path) {+ console.error('No report path found in research data');+ throw new Error('Research report not found');+ }++ // Get report content+ const reportResponse = await fetch(getApiUrl(`/api/report/${researchId}`));+ if (!reportResponse.ok) {+ throw new Error(`Server returned ${reportResponse.status} when fetching report`);+ }++ const reportData = await reportResponse.json();+ console.log('Report data status:', reportData.status);++ if (reportData.status === 'success' && reportData.content) {+ // Update metadata display+ const queryEl = document.getElementById('result-query');+ const dateEl = document.getElementById('result-date');+ const modeEl = document.getElementById('result-mode');- const reportData = await reportResponse.json();+ if (queryEl) queryEl.textContent = data.query || data.metadata?.query || 'Unknown query';+ if (dateEl) dateEl.textContent = formatDate(data.completed_at || data.metadata?.completed_at || data.metadata?.generated_at);+ if (modeEl) modeEl.textContent = formatMode(data.mode || data.metadata?.mode);- if (reportData.status === 'success') {- // Update UI with report content- document.getElementById('result-query').textContent = data.query || 'Unknown query';- document.getElementById('result-mode').textContent = data.mode === 'detailed' ? 'Detailed Report' : 'Quick Summary';-- // Format date- const reportDate = data.completed_at ? formatDate(new Date(data.completed_at)) : 'Unknown';- document.getElementById('result-date').textContent = reportDate;-- // Render markdown content- const resultsContent = document.getElementById('results-content');- if (resultsContent) {- resultsContent.innerHTML = '';- resultsContent.classList.add('markdown-body');-- // Enable syntax highlighting- const renderedContent = marked.parse(reportData.content);- resultsContent.innerHTML = renderedContent;-- // Apply syntax highlighting- document.querySelectorAll('pre code').forEach((block) => {- hljs.highlightElement(block);- });+ // Update duration if available+ if (data.metadata) {+ const metadata = data.metadata;+ // For duration, use created_at and completed_at+ if (!metadata.started_at && data.created_at) {+ metadata.started_at = data.created_at;+ }+ if (!metadata.completed_at && data.completed_at) {+ metadata.completed_at = data.completed_at;}+ updateResearchDuration(metadata);+ }++ // Render the report content+ if (resultsContent) {+ resultsContent.innerHTML = marked.parse(reportData.content);- // Switch to results page- switchPage('research-results');- } else {- throw new Error(reportData.message || 'Failed to load report content');+ // Apply syntax highlighting+ document.querySelectorAll('pre code').forEach((block) => {+ try {+ hljs.highlightBlock(block);+ } catch (e) {+ console.error('Error applying syntax highlighting:', e);+ }+ });+ }++ // Enable the PDF download button+ const pdfBtn = document.getElementById('download-pdf-btn');+ if (pdfBtn) {+ pdfBtn.disabled = false;+ pdfBtn.onclick = function() {+ generatePdf(researchId, data.query || data.metadata?.query);+ };}- } else if (data.status === 'in_progress') {- // Set favicon based on the research mode- setFavicon(data.mode || 'quick');- // Redirect to progress page- navigateToResearchProgress(data);+ // Switch to the results page+ switchPage('research-results');+ console.log('Switched to results page successfully');} else {- // Show research details for failed or suspended research- loadResearchDetails(researchId);+ throw new Error(reportData.message || 'Failed to load report content');}} catch (error) {console.error('Error loading research:', error);- alert('Error loading research: ' + error.message);- // Reset favicon to default on error- createDynamicFavicon('⚡');+ alert(`Failed to load research: ${error.message}`);}}// Function to load research detailsasync function loadResearchDetails(researchId) {try {- // Navigate to details page- switchPage('research-details');-- const researchLog = document.getElementById('research-log');- researchLog.innerHTML = '<div class="loading-spinner centered"><div class="spinner"></div></div>';-- const response = await fetch(getApiUrl(`/api/research/${researchId}/details`));- if (!response.ok) {- throw new Error('Failed to load research details');- }+ // Show loading indicators+ document.getElementById('research-log').innerHTML = '<div class="loading-spinner centered"><div class="spinner"></div></div>';+ // Fetch the research data+ const response = await fetch(getApiUrl(`/api/research/${researchId}`));const data = await response.json();- // Set the favicon based on the research mode- setFavicon(data.mode || 'quick');-- // Update UI with research details- document.getElementById('detail-query').textContent = data.query || 'Unknown query';- document.getElementById('detail-status').textContent = capitalizeFirstLetter(data.status || 'unknown');- document.getElementById('detail-mode').textContent = data.mode === 'detailed' ? 'Detailed Report' : 'Quick Summary';-- // Update progress indicator- const progress = data.progress || 0;- document.getElementById('detail-progress-fill').style.width = `${progress}%`;- document.getElementById('detail-progress-percentage').textContent = `${progress}%`;-- // Add status classes- document.getElementById('detail-status').className = 'metadata-value status-' + (data.status || 'unknown');-- // Clear existing log entries- researchLog.innerHTML = '';-- // Render log entries- if (data.log && Array.isArray(data.log)) {- renderLogEntries(data.log);+ if (data.status === 'success') {+ // Update the metadata display+ document.getElementById('detail-query').textContent = data.metadata.query || 'Unknown query';+ document.getElementById('detail-status').textContent = formatStatus(data.metadata.status);+ document.getElementById('detail-mode').textContent = formatMode(data.metadata.mode);++ // Update progress percentage+ const progressFill = document.getElementById('detail-progress-fill');+ const progressPercentage = document.getElementById('detail-progress-percentage');++ if (progressFill && progressPercentage) {+ const progress = data.metadata.progress || 0;+ progressFill.style.width = `${progress}%`;+ progressPercentage.textContent = `${progress}%`;+ }++ // Update duration if available+ updateResearchDuration(data.metadata);++ // Fetch the research log+ const logResponse = await fetch(getApiUrl(`/api/research/${researchId}/log`));+ const logData = await logResponse.json();++ if (logData.status === 'success') {+ // Render the log entries+ renderResearchLog(logData.log);+ } else {+ document.getElementById('research-log').innerHTML = '<div class="empty-state">No log entries available</div>';+ }++ // Update detail actions based on research status+ updateDetailActions(data.metadata);++ // Switch to the details page+ switchPage('research-details');} else {- researchLog.innerHTML = '<div class="empty-message">No log entries available</div>';- }-- // Update actions based on status- const actionsContainer = document.getElementById('detail-actions');- actionsContainer.innerHTML = '';-- if (data.status === 'completed' && data.report_path) {- // Add button to view results- const viewResultsBtn = document.createElement('button');- viewResultsBtn.className = 'btn btn-primary';- viewResultsBtn.innerHTML = '<i class="fas fa-eye"></i> View Results';- viewResultsBtn.addEventListener('click', () => loadResearch(researchId));- actionsContainer.appendChild(viewResultsBtn);- } else if (data.status === 'in_progress') {- // Add button to view progress- const viewProgressBtn = document.createElement('button');- viewProgressBtn.className = 'btn btn-primary';- viewProgressBtn.innerHTML = '<i class="fas fa-spinner"></i> View Progress';- viewProgressBtn.addEventListener('click', () => navigateToResearchProgress(data));- actionsContainer.appendChild(viewProgressBtn);-- // Add button to terminate research- const terminateBtn = document.createElement('button');- terminateBtn.className = 'btn btn-outline terminate-btn';- terminateBtn.innerHTML = '<i class="fas fa-stop-circle"></i> Terminate Research';- terminateBtn.addEventListener('click', () => terminateResearch(researchId));- actionsContainer.appendChild(terminateBtn);+ alert('Failed to load research details: ' + (data.message || 'Unknown error'));}-- // Add delete button for all research items- const deleteBtn = document.createElement('button');- deleteBtn.className = 'btn btn-outline delete-btn';- deleteBtn.innerHTML = '<i class="fas fa-trash"></i> Delete Research';- deleteBtn.addEventListener('click', () => {- if (confirm('Are you sure you want to delete this research? This action cannot be undone.')) {- deleteResearch(researchId);- }- });- actionsContainer.appendChild(deleteBtn);} catch (error) {console.error('Error loading research details:', error);- document.getElementById('research-log').innerHTML = '<div class="error-message">Error loading research details. Please try again later.</div>';- // Reset favicon to default on error- createDynamicFavicon('⚡');+ alert('An error occurred while loading the research details');}}// Function to render log entries- function renderLogEntries(logEntries) {+ function renderResearchLog(logEntries) {const researchLog = document.getElementById('research-log');researchLog.innerHTML = '';@@ -1540,31 +1652,6 @@ document.addEventListener('DOMContentLoaded', () => {return string.charAt(0).toUpperCase() + string.slice(1);}- function formatDate(date) {- // Ensure we're handling the date properly- if (!(date instanceof Date) || isNaN(date)) {- console.warn('Invalid date provided to formatDate:', date);- return 'Invalid date';- }-- // Get current year to compare with date year- const currentYear = new Date().getFullYear();- const dateYear = date.getFullYear();-- // Get month name, day, and time- const month = date.toLocaleString('en-US', { month: 'short' });- const day = date.getDate();- const hours = date.getHours().toString().padStart(2, '0');- const minutes = date.getMinutes().toString().padStart(2, '0');-- // Format like "Feb 25, 08:09" or "Feb 25, 2022, 08:09" if not current year- if (dateYear === currentYear) {- return `${month} ${day}, ${hours}:${minutes}`;- } else {- return `${month} ${day}, ${dateYear}, ${hours}:${minutes}`;- }- }-// Function to update progress UI from current researchfunction updateProgressFromCurrentResearch() {if (!isResearchInProgress || !currentResearchId) return;@@ -1587,120 +1674,52 @@ document.addEventListener('DOMContentLoaded', () => {// Function to update the sidebar navigation based on research statusfunction updateNavigationBasedOnResearchStatus() {- console.log("Updating navigation based on research status");- console.log("isResearchInProgress:", isResearchInProgress);- console.log("currentResearchId:", currentResearchId);+ const isResearchPage = document.getElementById('research-progress').classList.contains('active');+ const isAnyResearchInProgress = window.currentResearchId !== null && isResearchInProgress;- // Get nav items for each update to ensure we have fresh references- const navItems = document.querySelectorAll('.sidebar-nav li');- const mobileNavItems = document.querySelectorAll('.mobile-tab-bar li');- // Get all pages- const pages = document.querySelectorAll('.page');+ // Get the sidebar nav items and mobile tab items+ const sidebarNewResearchItem = document.querySelector('.sidebar-nav li[data-page="new-research"]');+ const sidebarHistoryItem = document.querySelector('.sidebar-nav li[data-page="history"]');+ const mobileNewResearchItem = document.querySelector('.mobile-tab-bar li[data-page="new-research"]');+ const mobileHistoryItem = document.querySelector('.mobile-tab-bar li[data-page="history"]');- const newResearchNav = Array.from(navItems).find(item =>- item.getAttribute('data-page') === 'new-research' ||- (item.getAttribute('data-original-page') === 'new-research' &&- item.getAttribute('data-page') === 'research-progress')- );+ // Control elements+ const terminateBtn = document.getElementById('terminate-research-btn');+ const errorMessage = document.getElementById('error-message');+ const tryAgainBtn = document.getElementById('try-again-btn');- if (newResearchNav) {- if (isResearchInProgress) {- console.log("Research is in progress, updating navigation");- // Change text to "Research in Progress"- newResearchNav.innerHTML = '<i class="fas fa-spinner fa-spin"></i> Research in Progress';-- // Also update the listener to navigate to progress page- if (newResearchNav.getAttribute('data-page') !== 'research-progress') {- newResearchNav.setAttribute('data-original-page', 'new-research');- newResearchNav.setAttribute('data-page', 'research-progress');- }-- // If on new-research page, redirect to research-progress- if (document.getElementById('new-research').classList.contains('active')) {- pages.forEach(page => page.classList.remove('active'));- document.getElementById('research-progress').classList.add('active');-- // Update the research progress page- updateProgressFromCurrentResearch();- }- } else {- console.log("Research is not in progress, resetting navigation");- // Reset to "New Research" if there's no active research- newResearchNav.innerHTML = '<i class="fas fa-search"></i> New Research';-- // Reset the listener- if (newResearchNav.hasAttribute('data-original-page')) {- newResearchNav.setAttribute('data-page', newResearchNav.getAttribute('data-original-page'));- newResearchNav.removeAttribute('data-original-page');- }-- // Reset progress UI elements- const progressFill = document.getElementById('progress-fill');- const progressPercentage = document.getElementById('progress-percentage');- const progressStatus = document.getElementById('progress-status');-- if (progressFill) progressFill.style.width = '0%';- if (progressPercentage) progressPercentage.textContent = '0%';- if (progressStatus) {- const errorMessage = document.getElementById('error-message');- if (errorMessage && errorMessage.style.display === 'block') {- // If there's an error message displayed, show a more informative status- progressStatus.textContent = 'Research process encountered an error. Please check the error message above and try again.';- progressStatus.classList.add('status-failed');- } else {- progressStatus.textContent = 'Start a new research query when you\'re ready...';- progressStatus.classList.remove('status-failed');- }- }-- // If the terminate button is visible, hide it- const terminateBtn = document.getElementById('terminate-research-btn');- if (terminateBtn) {- terminateBtn.style.display = 'none';- terminateBtn.disabled = false;- terminateBtn.innerHTML = '<i class="fas fa-stop-circle"></i> Terminate Research';- }-- // Also hide error message if visible- const errorMessage = document.getElementById('error-message');- if (errorMessage) {- errorMessage.style.display = 'none';- errorMessage.textContent = '';- }-- // Reset research form submit button- const startResearchBtn = document.getElementById('start-research-btn');- if (startResearchBtn) {- startResearchBtn.disabled = false;- startResearchBtn.innerHTML = '<i class="fas fa-rocket"></i> Start Research';- }+ // Log panel should only be visible on research-progress and research-results pages+ const logPanel = document.querySelector('.collapsible-log-panel');++ // If research is in progress+ if (isAnyResearchInProgress) {+ // Disable new research and history navigation while research is in progress+ if (sidebarNewResearchItem) sidebarNewResearchItem.classList.add('disabled');+ if (sidebarHistoryItem) sidebarHistoryItem.classList.add('disabled');+ if (mobileNewResearchItem) mobileNewResearchItem.classList.add('disabled');+ if (mobileHistoryItem) mobileHistoryItem.classList.add('disabled');++ // If user is not already on the research progress page, switch to it+ if (!isResearchPage) {+ switchPage('research-progress');}- // Make sure the navigation highlights the correct item- navItems.forEach(item => {- if (item === newResearchNav) {- if (isResearchInProgress) {- if (document.getElementById('research-progress').classList.contains('active')) {- item.classList.add('active');- }- } else if (document.getElementById('new-research').classList.contains('active')) {- item.classList.add('active');- }- }- });- }-- // Connect to socket for updates only if research is in progress- if (isResearchInProgress && currentResearchId) {- window.connectToResearchSocket(currentResearchId);+ // Show terminate button and hide error message and try again button+ if (terminateBtn) terminateBtn.style.display = 'block';+ if (errorMessage) errorMessage.style.display = 'none';+ if (tryAgainBtn) tryAgainBtn.style.display = 'none';} else {- // Disconnect socket if no active research- window.disconnectSocket();-- // Also reset the current research ID- currentResearchId = null;- window.currentResearchId = null;+ // Enable navigation when no research is in progress+ if (sidebarNewResearchItem) sidebarNewResearchItem.classList.remove('disabled');+ if (sidebarHistoryItem) sidebarHistoryItem.classList.remove('disabled');+ if (mobileNewResearchItem) mobileNewResearchItem.classList.remove('disabled');+ if (mobileHistoryItem) mobileHistoryItem.classList.remove('disabled');++ // Hide terminate button when no research is in progress+ if (terminateBtn) terminateBtn.style.display = 'none';}++ console.log('Updated navigation based on research status. In progress:', isAnyResearchInProgress);}// Function to update the research progress page from nav click@@ -2371,11 +2390,12 @@ document.addEventListener('DOMContentLoaded', () => {// Initialize the terminate button event listenerconst terminateBtn = document.getElementById('terminate-research-btn');if (terminateBtn) {- terminateBtn.addEventListener('click', () => {- if (confirm('Are you sure you want to terminate this research? This action cannot be undone.')) {- if (currentResearchId) {- terminateResearch(currentResearchId);- }+ terminateBtn.addEventListener('click', function() {+ if (currentResearchId) {+ terminateResearch(currentResearchId);+ } else {+ console.error('No active research ID found for termination');+ alert('No active research ID found. Please try again.');}});}@@ -2518,4 +2538,522 @@ document.addEventListener('DOMContentLoaded', () => {const emoji = mode === 'detailed' ? '🔬' : '⚡';return createDynamicFavicon(emoji);}++ // Global log tracking variables+ let consoleLogEntries = [];+ let logCount = 0;+ let lastLogMessage = null; // Track the last log message to prevent duplicates+ let lastLogTimestamp = null; // Track the last log timestamp++ // Function to filter console logs by type+ function filterConsoleLogs(filterType = 'all') {+ console.log(`Filtering logs by type: ${filterType}`);++ // Make sure the filter type is lowercase for consistency+ filterType = filterType.toLowerCase();++ // Get all log entries from the DOM+ const logEntries = document.querySelectorAll('.console-log-entry');+ console.log(`Found ${logEntries.length} log entries to filter`);++ // If no entries found, exit early+ if (logEntries.length === 0) {+ console.log('No log entries found to filter');+ return;+ }++ let visibleCount = 0;++ // Apply filters+ logEntries.forEach(entry => {+ // Check for log type classes+ const isInfo = entry.classList.contains('log-info');+ const isMilestone = entry.classList.contains('log-milestone');+ const isError = entry.classList.contains('log-error');++ // Determine visibility based on filter type+ let shouldShow = false;++ switch (filterType) {+ case 'all':+ shouldShow = true;+ break;+ case 'info':+ shouldShow = isInfo;+ break;+ case 'milestone':+ case 'milestones': // Handle plural form too+ shouldShow = isMilestone;+ break;+ case 'error':+ case 'errors': // Handle plural form too+ shouldShow = isError;+ break;+ default:+ shouldShow = true; // Default to showing everything+ console.warn(`Unknown filter type: ${filterType}, showing all logs`);+ }++ // Set display style based on filter result+ entry.style.display = shouldShow ? '' : 'none';++ if (shouldShow) {+ visibleCount++;+ }+ });++ console.log(`Filtering complete. Showing ${visibleCount} of ${logEntries.length} logs with filter: ${filterType}`);++ // Highlight the active filter in the UI+ const filterSelect = document.getElementById('log-level-filter');+ if (filterSelect) {+ // Ensure the filter select matches the applied filter+ for (let i = 0; i < filterSelect.options.length; i++) {+ if (filterSelect.options[i].value.toLowerCase() === filterType) {+ filterSelect.selectedIndex = i;+ break;+ }+ }+ }++ // Show 'no logs' message if all logs are filtered out+ const consoleContainer = document.getElementById('console-log-container');+ if (consoleContainer) {+ // Remove any existing empty message+ const existingEmptyMessage = consoleContainer.querySelector('.empty-log-message');+ if (existingEmptyMessage) {+ existingEmptyMessage.remove();+ }++ // Add empty message if needed+ if (visibleCount === 0 && logEntries.length > 0) {+ const newEmptyMessage = document.createElement('div');+ newEmptyMessage.className = 'empty-log-message';+ newEmptyMessage.textContent = `No ${filterType} logs to display.`;+ consoleContainer.appendChild(newEmptyMessage);+ }++ // Scroll to the bottom to ensure newly visible logs are seen+ consoleContainer.scrollTop = consoleContainer.scrollHeight;+ }+ }++ // Function to initialize the log panel with direct DOM methods+ function initializeLogPanel() {+ console.log('Initializing log panel');++ const logPanelToggle = document.getElementById('log-panel-toggle');+ const logPanelContent = document.getElementById('log-panel-content');+ const clearLogsBtn = document.getElementById('clear-logs-btn');+ const logLevelFilter = document.getElementById('log-level-filter');++ // Check if elements exist+ if (!logPanelToggle) {+ console.error('Log panel toggle element not found');+ return;+ }++ if (!logPanelContent) {+ console.error('Log panel content element not found');+ return;+ }++ // Set initial collapsed state+ logPanelContent.classList.add('collapsed');+ logPanelToggle.classList.add('collapsed');++ // Direct DOM manipulation for better toggle performance+ logPanelToggle.onclick = function() {+ console.log('Toggle button clicked');+ if (logPanelContent.classList.contains('collapsed')) {+ logPanelContent.classList.remove('collapsed');+ logPanelToggle.classList.remove('collapsed');++ // Scroll to bottom when expanded+ const consoleContainer = document.getElementById('console-log-container');+ if (consoleContainer) {+ setTimeout(() => {+ consoleContainer.scrollTop = consoleContainer.scrollHeight;+ }, 10);+ }+ } else {+ logPanelContent.classList.add('collapsed');+ logPanelToggle.classList.add('collapsed');+ }++ return false; // Prevent default+ };++ // Direct DOM manipulation for clear logs button+ if (clearLogsBtn) {+ clearLogsBtn.onclick = function() {+ console.log('Clear logs button clicked');+ clearConsoleLogs();+ return false; // Prevent default+ };+ }++ // Direct DOM manipulation for filter dropdown+ if (logLevelFilter) {+ // Set default to "all"+ logLevelFilter.value = 'all';++ // Apply initial filtering+ setTimeout(() => filterConsoleLogs('all'), 100);++ logLevelFilter.onchange = function() {+ const filterValue = this.value;+ console.log('Log filter changed to:', filterValue);+ filterConsoleLogs(filterValue);+ };+ }++ console.log('Log panel initialization completed');+ }++ // Function to clear all console logs+ function clearConsoleLogs() {+ const consoleContainer = document.getElementById('console-log-container');+ if (!consoleContainer) return;++ console.log('Clearing console logs');++ // Reset the processed messages set to allow new logs after clearing+ window.processedMessages = new Set();++ // Clear the container+ consoleContainer.innerHTML = '<div class="empty-log-message">No logs yet. Research logs will appear here as they occur.</div>';++ // Reset the log entries array+ consoleLogEntries = [];++ // Reset the log count+ logCount = 0;+ updateLogIndicator();++ // Reset last message tracking+ lastLogMessage = null;+ lastLogTimestamp = null;++ console.log('Console logs cleared');+ }++ // Function to determine if a log message is a milestone+ function isMilestoneLog(message, metadata) {+ if (!message) return false;++ // Critical milestones - main research flow points+ const criticalMilestones = [+ // Research start/end+ /^Research (started|complete)/i,+ /^Starting research/i,++ // Iteration markers+ /^Starting iteration \d+/i,+ /^Iteration \d+ complete/i,++ // Final completion+ /^Research completed successfully/i,+ /^Report generation complete/i,+ /^Writing research report to file/i+ ];++ // Check for critical milestones first+ const isCriticalMilestone = criticalMilestones.some(pattern => pattern.test(message));+ if (isCriticalMilestone) return true;++ // Check metadata phase for critical phases only+ const isCriticalPhase = metadata && (+ metadata.phase === 'init' ||+ metadata.phase === 'iteration_start' ||+ metadata.phase === 'iteration_complete' ||+ metadata.phase === 'complete' ||+ metadata.phase === 'report_generation' ||+ metadata.phase === 'report_complete'+ );++ return isCriticalPhase;+ }++ // Initialize the log panel when the application starts+ function initializeAppWithLogs() {+ // Original initializeApp function+ const originalInitializeApp = window.initializeApp || initializeApp;+ window.initializeApp = function() {+ // Call the original initialization+ originalInitializeApp();++ // Ensure global log variables are initialized+ window.consoleLogEntries = [];+ window.logCount = 0;+ window.lastLogMessage = null;+ window.lastLogTimestamp = null;++ // Initialize the log panel with a delay to ensure DOM is ready+ setTimeout(() => {+ initializeLogPanel();++ // Add an initial welcome log entry+ addConsoleLog('Research system initialized and ready', 'milestone');++ console.log('Log panel initialization completed');+ }, 100);+ };+ }++ // Call the initialization function immediately+ initializeAppWithLogs();++ // Function to get active research ID+ function getActiveResearchId() {+ return window.currentResearchId || currentResearchId;+ }++ // Function to update research duration on results display+ function updateResearchDuration(metadata) {+ if (!metadata || !metadata.started_at || !metadata.completed_at) return;++ try {+ // Parse ISO dates+ const startDate = new Date(metadata.started_at);+ const endDate = new Date(metadata.completed_at);++ // Calculate duration in seconds+ const durationMs = endDate - startDate;+ const durationSec = Math.floor(durationMs / 1000);++ // Format as minutes and seconds+ const minutes = Math.floor(durationSec / 60);+ const seconds = durationSec % 60;+ const formattedDuration = `${minutes}m ${seconds}s`;++ // Add to results metadata+ const resultsMetadata = document.querySelector('.results-metadata');+ if (resultsMetadata) {+ // Check if duration element already exists+ let durationEl = resultsMetadata.querySelector('.metadata-item.duration');++ if (!durationEl) {+ // Create new duration element+ durationEl = document.createElement('div');+ durationEl.className = 'metadata-item duration';++ const labelEl = document.createElement('span');+ labelEl.className = 'metadata-label';+ labelEl.textContent = 'Duration:';++ const valueEl = document.createElement('span');+ valueEl.className = 'metadata-value';+ valueEl.id = 'result-duration';++ durationEl.appendChild(labelEl);+ durationEl.appendChild(valueEl);++ // Insert after "Generated" metadata+ const generatedEl = resultsMetadata.querySelector('.metadata-item:nth-child(2)');+ if (generatedEl) {+ resultsMetadata.insertBefore(durationEl, generatedEl.nextSibling);+ } else {+ resultsMetadata.appendChild(durationEl);+ }+ }++ // Update duration value+ const durationValueEl = resultsMetadata.querySelector('#result-duration');+ if (durationValueEl) {+ durationValueEl.textContent = formattedDuration;+ }+ }++ // Also add to research details metadata+ const detailsMetadata = document.querySelector('.research-metadata');+ if (detailsMetadata) {+ // Check if duration element already exists+ let durationEl = null;++ // Use querySelectorAll and iterate to find the element with "Duration" label+ const metadataItems = detailsMetadata.querySelectorAll('.metadata-item');+ for (let i = 0; i < metadataItems.length; i++) {+ const labelEl = metadataItems[i].querySelector('.metadata-label');+ if (labelEl && labelEl.textContent.includes('Duration')) {+ durationEl = metadataItems[i];+ break;+ }+ }++ if (!durationEl) {+ // Create new duration element+ durationEl = document.createElement('div');+ durationEl.className = 'metadata-item';++ const labelEl = document.createElement('span');+ labelEl.className = 'metadata-label';+ labelEl.textContent = 'Duration:';++ const valueEl = document.createElement('span');+ valueEl.className = 'metadata-value';+ valueEl.id = 'detail-duration';++ durationEl.appendChild(labelEl);+ durationEl.appendChild(valueEl);++ // Insert after mode metadata+ const modeEl = detailsMetadata.querySelector('.metadata-item:nth-child(3)');+ if (modeEl) {+ detailsMetadata.insertBefore(durationEl, modeEl.nextSibling);+ } else {+ detailsMetadata.appendChild(durationEl);+ }+ }++ // Update duration value+ const durationValueEl = durationEl.querySelector('.metadata-value');+ if (durationValueEl) {+ durationValueEl.textContent = formattedDuration;+ }+ }++ console.log(`Research duration: ${formattedDuration}`);+ } catch (error) {+ console.error('Error calculating research duration:', error);+ }+ }++ // Function to add a log entry to the console with reduced deduplication time window+ function addConsoleLog(message, type = 'info') {+ // Skip if identical to the last message to prevent duplication+ const currentTime = new Date().getTime();+ if (message === lastLogMessage && lastLogTimestamp && currentTime - lastLogTimestamp < 300) {+ // Skip duplicate message if it's within 300ms of the last one (reduced from 2000ms)+ return null;+ }++ // Update tracking variables+ lastLogMessage = message;+ lastLogTimestamp = currentTime;++ // Get DOM elements+ const consoleContainer = document.getElementById('console-log-container');+ const template = document.getElementById('console-log-entry-template');++ if (!consoleContainer || !template) {+ console.error('Console log container or template not found');+ return null;+ }++ // Clear the empty message if it's the first log+ const emptyMessage = consoleContainer.querySelector('.empty-log-message');+ if (emptyMessage) {+ consoleContainer.removeChild(emptyMessage);+ }++ // Create a new log entry from the template+ const clone = document.importNode(template.content, true);+ const logEntry = clone.querySelector('.console-log-entry');++ // Make sure type is valid and standardized+ let validType = 'info';+ if (['info', 'milestone', 'error'].includes(type.toLowerCase())) {+ validType = type.toLowerCase();+ }++ // Add appropriate class based on type+ logEntry.classList.add(`log-${validType}`);++ // Set the timestamp+ const timestamp = new Date().toLocaleTimeString();+ const timestampEl = logEntry.querySelector('.log-timestamp');+ if (timestampEl) timestampEl.textContent = timestamp;++ // Set the badge text based on type+ const badgeEl = logEntry.querySelector('.log-badge');+ if (badgeEl) {+ badgeEl.textContent = validType.toUpperCase();+ }++ // Set the message+ const messageEl = logEntry.querySelector('.log-message');+ if (messageEl) messageEl.textContent = message;++ // Add the log entry to the container+ consoleContainer.appendChild(logEntry);++ // Store the log entry for filtering+ consoleLogEntries.push({+ element: logEntry,+ type: validType,+ message: message,+ timestamp: timestamp+ });++ // Update log count+ logCount++;+ updateLogIndicator();++ // Ensure the log panel is visible if it's the first log+ if (logCount === 1) {+ const logPanelContent = document.getElementById('log-panel-content');+ const logPanelToggle = document.getElementById('log-panel-toggle');++ if (logPanelContent && logPanelContent.classList.contains('collapsed')) {+ logPanelContent.classList.remove('collapsed');+ if (logPanelToggle) logPanelToggle.classList.remove('collapsed');+ }+ }++ // Use setTimeout to ensure DOM updates before scrolling+ setTimeout(() => {+ // Scroll to the bottom+ consoleContainer.scrollTop = consoleContainer.scrollHeight;+ }, 0);++ console.log(`Added console log (${validType}): ${message}`);++ return logEntry;+ }++ // Function to update the log indicator count+ function updateLogIndicator() {+ const indicator = document.getElementById('log-indicator');+ if (indicator) {+ indicator.textContent = logCount;+ }+ }++ // New function to update log panel visibility based on current page+ function updateLogPanelVisibility(pageId) {+ console.log('Updating log panel visibility for page:', pageId);++ // Only show log panel on research progress and results pages+ if (pageId === 'research-progress' || pageId === 'research-results') {+ console.log('Showing log panel');+ // Let CSS handle the display+ } else {+ console.log('Hiding log panel');+ // Let CSS handle the display+ }+ }++ // Function to update the navigation UI based on active page+ function updateNavigationUI(pageId) {+ // Update sidebar navigation+ const sidebarNavItems = document.querySelectorAll('.sidebar-nav li');+ sidebarNavItems.forEach(item => {+ if (item.getAttribute('data-page') === pageId) {+ item.classList.add('active');+ } else {+ item.classList.remove('active');+ }+ });++ // Update mobile tab bar+ const mobileNavItems = document.querySelectorAll('.mobile-tab-bar li');+ mobileNavItems.forEach(item => {+ if (item.getAttribute('data-page') === pageId) {+ item.classList.add('active');+ } else {+ item.classList.remove('active');+ }+ });+ }});\ No newline at end of filediff --git a/templates/index.html b/templates/index.htmlindex a758a29c65..2fb972225a 100644--- a/templates/index.html+++ b/templates/index.html@@ -215,6 +215,35 @@</div></div></div>++ <!-- Collapsible Log Panel -->+ <div class="collapsible-log-panel">+ <div class="log-panel-header" id="log-panel-toggle">+ <i class="fas fa-chevron-down toggle-icon"></i>+ <span>Research Logs</span>+ <span class="log-indicator" id="log-indicator">0</span>+ </div>+ <div class="log-panel-content" id="log-panel-content">+ <div class="log-controls">+ <button class="btn btn-sm btn-outline" id="clear-logs-btn">+ <i class="fas fa-trash-alt"></i> Clear+ </button>+ <div class="log-filter">+ <label>Show:</label>+ <select id="log-level-filter">+ <option value="all" selected>All</option>+ <option value="milestone">Milestones</option>+ <option value="info">Info</option>+ <option value="error">Errors</option>+ </select>+ </div>+ </div>+ <div class="console-log" id="console-log-container">+ <!-- Logs will be added here dynamically -->+ <div class="empty-log-message">No logs yet. Research logs will appear here as they occur.</div>+ </div>+ </div>+ </div></main></div>@@ -303,5 +332,14 @@window.html2canvas_noSandbox = true;}</script>++ <!-- Add a template for console log entries -->+ <template id="console-log-entry-template">+ <div class="console-log-entry">+ <span class="log-timestamp"></span>+ <span class="log-badge"></span>+ <span class="log-message"></span>+ </div>+ </template></body></html>\ No newline at end of file