Skip to content

~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.

Fix progress component and enhance log panel functionality

hashedviking36407b6fa10d
diff --git a/src/local_deep_research/web/routes/history_routes.py b/src/local_deep_research/web/routes/history_routes.py
index 066ab164c9..aa55c9994d 100644
--- a/src/local_deep_research/web/routes/history_routes.py
+++ b/src/local_deep_research/web/routes/history_routes.py
@@ -285,6 +285,17 @@ def get_research_logs(research_id):
# Retrieve logs from the database
logs = get_logs_for_research(research_id)
+
+ # Format logs correctly if needed
+ formatted_logs = []
+ for log in logs:
+ # Ensure each log has time, message, and type fields
+ log_entry = {
+ "time": log.get("time", ""),
+ "message": log.get("message", "No message"),
+ "type": log.get("type", "info")
+ }
+ formatted_logs.append(log_entry)
# Import globals from research routes
from .research_routes import get_globals
@@ -296,17 +307,19 @@ def get_research_logs(research_id):
# Use the logs from memory temporarily until they're saved to the database
memory_logs = active_research[research_id]["log"]
- # Filter out logs that are already in the database
- # We'll compare timestamps to avoid duplicates
- db_timestamps = {log["time"] for log in logs}
- unique_memory_logs = [
- log for log in memory_logs if log["time"] not in db_timestamps
- ]
-
- # Add unique memory logs to our return list
- logs.extend(unique_memory_logs)
+ # Format memory logs too
+ for log in memory_logs:
+ log_entry = {
+ "time": log.get("time", ""),
+ "message": log.get("message", "No message"),
+ "type": log.get("type", "info")
+ }
+
+ # Check if this log is already in our formatted logs by timestamp
+ if not any(flog["time"] == log_entry["time"] for flog in formatted_logs):
+ formatted_logs.append(log_entry)
# Sort logs by timestamp
- logs.sort(key=lambda x: x["time"])
+ formatted_logs.sort(key=lambda x: x["time"])
- return jsonify({"status": "success", "logs": logs})
\ No newline at end of file
+ return jsonify({"status": "success", "logs": formatted_logs})
\ No newline at end of file
diff --git a/src/local_deep_research/web/static/js/components/fallback/ui.js b/src/local_deep_research/web/static/js/components/fallback/ui.js
index b650cfc8aa..48590bb71e 100644
--- a/src/local_deep_research/web/static/js/components/fallback/ui.js
+++ b/src/local_deep_research/web/static/js/components/fallback/ui.js
@@ -166,12 +166,50 @@
return html;
}
+ /**
+ * Update favicon to indicate status
+ * @param {string} status - Status to indicate (active, complete, error)
+ */
+ function updateFavicon(status) {
+ try {
+ const faviconLink = document.querySelector('link[rel="icon"]') ||
+ document.querySelector('link[rel="shortcut icon"]');
+
+ if (!faviconLink) {
+ console.warn('Favicon link not found');
+ return;
+ }
+
+ let iconPath;
+ switch (status) {
+ case 'active':
+ iconPath = '/research/static/img/favicon-active.ico';
+ break;
+ case 'complete':
+ iconPath = '/research/static/img/favicon-complete.ico';
+ break;
+ case 'error':
+ iconPath = '/research/static/img/favicon-error.ico';
+ break;
+ default:
+ iconPath = '/research/static/img/favicon.ico';
+ }
+
+ // Add cache busting parameter to force reload
+ faviconLink.href = iconPath + '?v=' + new Date().getTime();
+ console.log('Updated favicon to:', status);
+ } catch (error) {
+ console.error('Failed to update favicon:', error);
+ }
+ }
+
// Export utilities to window.ui
window.ui = {
showSpinner,
hideSpinner,
showError,
showMessage,
- renderMarkdown
+ renderMarkdown,
+ updateFavicon
};
})();
\ No newline at end of file
diff --git a/src/local_deep_research/web/static/js/components/progress.js b/src/local_deep_research/web/static/js/components/progress.js
index e3ba501461..adff1ef4e3 100644
--- a/src/local_deep_research/web/static/js/components/progress.js
+++ b/src/local_deep_research/web/static/js/components/progress.js
@@ -10,6 +10,7 @@
// DOM Elements
let progressBar = null;
+ let progressPercentage = null;
let statusText = null;
let currentTaskText = null;
let cancelButton = null;
@@ -24,7 +25,7 @@
if (!currentResearchId) {
console.error('No research ID found');
- window.ui.showError('No active research found. Please start a new research.');
+ if (window.ui) window.ui.showError('No active research found. Please start a new research.');
setTimeout(() => {
window.location.href = '/';
}, 3000);
@@ -33,14 +34,32 @@
// Get DOM elements
progressBar = document.getElementById('progress-bar');
+ progressPercentage = document.getElementById('progress-percentage');
statusText = document.getElementById('status-text');
currentTaskText = document.getElementById('current-task');
cancelButton = document.getElementById('cancel-research-btn');
viewResultsButton = document.getElementById('view-results-btn');
- if (!progressBar || !statusText || !currentTaskText) {
- console.error('Required DOM elements not found for progress component');
- return;
+ // Log available elements for debugging
+ console.log('Progress DOM elements:', {
+ progressBar: !!progressBar,
+ progressPercentage: !!progressPercentage,
+ statusText: !!statusText,
+ currentTaskText: !!currentTaskText,
+ cancelButton: !!cancelButton,
+ viewResultsButton: !!viewResultsButton
+ });
+
+ // Check for required elements
+ const missingElements = [];
+ if (!progressBar) missingElements.push('progress-bar');
+ if (!statusText) missingElements.push('status-text');
+ if (!currentTaskText) missingElements.push('current-task');
+
+ if (missingElements.length > 0) {
+ console.error('Required DOM elements not found for progress component:', missingElements.join(', '));
+ // Try to create fallback elements if not found
+ createFallbackElements(missingElements);
}
// Set up event listeners
@@ -48,8 +67,14 @@
cancelButton.addEventListener('click', handleCancelResearch);
}
- // Initialize socket connection
- initializeSocket();
+ // Initialize socket connection if available
+ if (window.socket) {
+ initializeSocket();
+ } else {
+ console.warn('Socket service not available, falling back to polling');
+ // Set up polling as fallback
+ pollInterval = setInterval(checkProgress, 3000);
+ }
// Initial progress check
checkProgress();
@@ -57,6 +82,54 @@
console.log('Progress component initialized for research ID:', currentResearchId);
}
+ /**
+ * Create fallback elements if they're missing
+ * @param {Array} missingElements - Array of missing element IDs
+ */
+ function createFallbackElements(missingElements) {
+ const progressContainer = document.querySelector('.progress-container');
+ const statusContainer = document.querySelector('.status-container');
+ const taskContainer = document.querySelector('.task-container');
+
+ if (missingElements.includes('progress-bar') && progressContainer) {
+ console.log('Creating fallback progress bar');
+ const progressBarContainer = document.createElement('div');
+ progressBarContainer.className = 'progress-bar';
+ progressBarContainer.innerHTML = '<div id="progress-bar" class="progress-fill" style="width: 0%"></div>';
+ progressContainer.prepend(progressBarContainer);
+ progressBar = document.getElementById('progress-bar');
+
+ if (!progressPercentage) {
+ const percentEl = document.createElement('div');
+ percentEl.id = 'progress-percentage';
+ percentEl.className = 'progress-percentage';
+ percentEl.textContent = '0%';
+ progressContainer.appendChild(percentEl);
+ progressPercentage = percentEl;
+ }
+ }
+
+ if (missingElements.includes('status-text') && statusContainer) {
+ console.log('Creating fallback status text');
+ const statusEl = document.createElement('div');
+ statusEl.id = 'status-text';
+ statusEl.className = 'status-indicator';
+ statusEl.textContent = 'Initializing';
+ statusContainer.appendChild(statusEl);
+ statusText = statusEl;
+ }
+
+ if (missingElements.includes('current-task') && taskContainer) {
+ console.log('Creating fallback task text');
+ const taskEl = document.createElement('div');
+ taskEl.id = 'current-task';
+ taskEl.className = 'task-text';
+ taskEl.textContent = 'Starting research...';
+ taskContainer.appendChild(taskEl);
+ currentTaskText = taskEl;
+ }
+ }
+
/**
* Extract research ID from URL
* @returns {string|null} The research ID or null if not found
@@ -76,14 +149,22 @@
* Initialize Socket.IO connection and listeners
*/
function initializeSocket() {
- // Subscribe to research events
- window.socket.subscribeToResearch(currentResearchId, handleProgressUpdate);
-
- // Handle socket reconnection
- window.socket.onReconnect(() => {
- console.log('Socket reconnected, resubscribing to research events');
+ try {
+ // Subscribe to research events
window.socket.subscribeToResearch(currentResearchId, handleProgressUpdate);
- });
+
+ // Handle socket reconnection
+ window.socket.onReconnect(() => {
+ console.log('Socket reconnected, resubscribing to research events');
+ window.socket.subscribeToResearch(currentResearchId, handleProgressUpdate);
+ });
+ } catch (error) {
+ console.error('Error initializing socket:', error);
+ // Fall back to polling
+ if (!pollInterval) {
+ pollInterval = setInterval(checkProgress, 3000);
+ }
+ }
}
/**
@@ -109,6 +190,11 @@
*/
async function checkProgress() {
try {
+ if (!window.api || !window.api.getResearchStatus) {
+ console.error('API service not available');
+ return;
+ }
+
const data = await window.api.getResearchStatus(currentResearchId);
if (data) {
@@ -127,7 +213,29 @@
}
} catch (error) {
console.error('Error checking research progress:', error);
- statusText.textContent = 'Error checking research status';
+ if (statusText) {
+ statusText.textContent = 'Error checking research status';
+ }
+ }
+ }
+
+ /**
+ * Update progress bar
+ * @param {HTMLElement} progressBar - The progress bar element
+ * @param {number} progress - Progress percentage (0-100)
+ */
+ function updateProgressBar(progressBar, progress) {
+ if (!progressBar) return;
+
+ // Ensure progress is between 0-100
+ const percentage = Math.max(0, Math.min(100, Math.floor(progress)));
+
+ // Update progress bar width
+ progressBar.style.width = `${percentage}%`;
+
+ // Update percentage text if available
+ if (progressPercentage) {
+ progressPercentage.textContent = `${percentage}%`;
}
}
@@ -137,13 +245,20 @@
*/
function updateProgressUI(data) {
// Update progress bar
- if (data.progress !== undefined) {
- window.ui.updateProgressBar(progressBar, data.progress);
+ if (data.progress !== undefined && progressBar) {
+ // Try to use UI service if available, otherwise use local function
+ if (window.ui && typeof window.ui.updateProgressBar === 'function') {
+ window.ui.updateProgressBar(progressBar, data.progress);
+ } else {
+ updateProgressBar(progressBar, data.progress);
+ }
}
// Update status text
- if (data.status) {
- statusText.textContent = window.formatting.formatStatus(data.status);
+ if (data.status && statusText) {
+ statusText.textContent = window.formatting ?
+ window.formatting.formatStatus(data.status) :
+ data.status.charAt(0).toUpperCase() + data.status.slice(1);
// Add status class for styling
document.querySelectorAll('.status-indicator').forEach(el => {
@@ -153,7 +268,7 @@
}
// Update current task
- if (data.current_task) {
+ if (data.current_task && currentTaskText) {
currentTaskText.textContent = data.current_task;
}
@@ -163,7 +278,9 @@
}
// Update favicon based on status
- window.ui.updateFavicon(data.status);
+ if (window.ui && typeof window.ui.updateFavicon === 'function') {
+ window.ui.updateFavicon(data.status);
+ }
// Show notification if enabled
if (data.status === 'completed' && localStorage.getItem('notificationsEnabled') === 'true') {
@@ -199,7 +316,11 @@
}
} else if (data.status === 'failed' || data.status === 'cancelled') {
// Show error message
- window.ui.showError(data.error || 'Research was unsuccessful');
+ if (window.ui) {
+ window.ui.showError(data.error || 'Research was unsuccessful');
+ } else {
+ console.error('Research failed:', data.error || 'Unknown error');
+ }
// Update button to go back to home
if (viewResultsButton) {
@@ -230,16 +351,24 @@
}
try {
+ if (!window.api || !window.api.cancelResearch) {
+ throw new Error('API service not available');
+ }
+
await window.api.cancelResearch(currentResearchId);
// Update status manually (in case socket fails)
- statusText.textContent = 'Cancelled';
- document.querySelectorAll('.status-indicator').forEach(el => {
- el.className = 'status-indicator status-cancelled';
- });
+ if (statusText) {
+ statusText.textContent = 'Cancelled';
+ document.querySelectorAll('.status-indicator').forEach(el => {
+ el.className = 'status-indicator status-cancelled';
+ });
+ }
// Show message
- window.ui.showMessage('Research has been cancelled.');
+ if (window.ui) {
+ window.ui.showMessage('Research has been cancelled.');
+ }
// Update cancel button
if (cancelButton) {
@@ -252,14 +381,19 @@
viewResultsButton.href = '/';
viewResultsButton.style.display = 'inline-block';
}
+
} catch (error) {
console.error('Error cancelling research:', error);
- window.ui.showError('Error cancelling research: ' + error.message);
// Re-enable cancel button
if (cancelButton) {
cancelButton.disabled = false;
- cancelButton.innerHTML = '<i class="fas fa-times"></i> Cancel Research';
+ cancelButton.innerHTML = '<i class="fas fa-stop-circle"></i> Cancel Research';
+ }
+
+ // Show error message
+ if (window.ui) {
+ window.ui.showError('Failed to cancel research. Please try again.');
}
}
}
@@ -267,29 +401,31 @@
/**
* Show browser notification
* @param {string} title - Notification title
- * @param {string} body - Notification body
+ * @param {string} message - Notification message
*/
- function showNotification(title, body) {
- if (!("Notification" in window)) {
- console.log("Browser does not support notifications");
- return;
- }
+ function showNotification(title, message) {
+ if (!('Notification' in window)) return;
- if (Notification.permission === "granted") {
- new Notification(title, { body, icon: '/static/favicon.ico' });
- } else if (Notification.permission !== "denied") {
+ // Check if permission is already granted
+ if (Notification.permission === 'granted') {
+ new Notification(title, { body: message });
+ }
+ // Otherwise, request permission
+ else if (Notification.permission !== 'denied') {
Notification.requestPermission().then(permission => {
- if (permission === "granted") {
- new Notification(title, { body, icon: '/static/favicon.ico' });
+ if (permission === 'granted') {
+ new Notification(title, { body: message });
}
});
}
}
- // Initialize on DOM content loaded
- if (document.readyState === 'loading') {
- document.addEventListener('DOMContentLoaded', initializeProgress);
- } else {
- initializeProgress();
- }
+ // Initialize on page load
+ document.addEventListener('DOMContentLoaded', initializeProgress);
+
+ // Public API
+ window.progressComponent = {
+ checkProgress,
+ handleCancelResearch
+ };
})();
\ No newline at end of file
diff --git a/src/local_deep_research/web/static/js/services/socket.js b/src/local_deep_research/web/static/js/services/socket.js
index 73d0c30855..0b3c0e2a40 100644
--- a/src/local_deep_research/web/static/js/services/socket.js
+++ b/src/local_deep_research/web/static/js/services/socket.js
@@ -3,175 +3,262 @@
* Manages WebSocket communication using Socket.IO
*/
-// Socket.IO instance
-let socket = null;
-
-// Map of event handlers for each research ID
-const researchEventHandlers = new Map();
-
-/**
- * Initialize the Socket.IO connection
- * @returns {Object} The socket instance
- */
-function initializeSocket() {
- // Check if Socket.IO library is available
- if (typeof io === 'undefined') {
- console.error('Socket.IO library not loaded');
- return null;
- }
+window.socket = (function() {
+ let socket = null;
+ let researchEventHandlers = {};
+ let reconnectCallback = null;
- // Initialize Socket.IO with the research namespace
- try {
- socket = io({
- path: '/research/socket.io'
- });
+ // Keep track of the research we're currently subscribed to
+ let currentResearchId = null;
+
+ /**
+ * Initialize the Socket.IO connection
+ */
+ function initializeSocket() {
+ if (socket) {
+ // Already initialized
+ return socket;
+ }
- // Setup core socket event handlers
- setupSocketEvents();
+ // Get the base URL from the current page
+ const baseUrl = window.location.protocol + '//' + window.location.host;
+
+ // Create a new socket instance
+ try {
+ socket = io(baseUrl, {
+ path: '/research/socket.io',
+ reconnection: true,
+ reconnectionDelay: 1000,
+ reconnectionAttempts: 5
+ });
+
+ setupSocketEvents();
+ console.log('Socket.IO initialized');
+ } catch (error) {
+ console.error('Error initializing Socket.IO:', error);
+ }
- console.log('Socket.IO initialized');
return socket;
- } catch (err) {
- console.error('Error initializing Socket.IO:', err);
- return null;
}
-}
-
-/**
- * Setup core Socket.IO event handlers
- */
-function setupSocketEvents() {
- if (!socket) return;
- socket.on('connect', () => {
- console.log('Socket connected, ID:', socket.id);
+ /**
+ * Set up the socket event handlers
+ */
+ function setupSocketEvents() {
+ socket.on('connect', () => {
+ console.log('Socket connected');
+
+ // Re-subscribe to current research if any
+ if (currentResearchId) {
+ subscribeToResearch(currentResearchId);
+ }
+
+ // Call reconnect callback if exists
+ if (reconnectCallback) {
+ reconnectCallback();
+ }
+ });
- // Reconnect any active research subscriptions
- researchEventHandlers.forEach((handlers, researchId) => {
- subscribeToResearch(researchId);
+ socket.on('disconnect', (reason) => {
+ console.log('Socket disconnected:', reason);
+ });
+
+ socket.on('reconnect', (attemptNumber) => {
+ console.log('Socket reconnected after', attemptNumber, 'attempts');
+ });
+
+ socket.on('reconnect_attempt', (attemptNumber) => {
+ console.log('Socket reconnection attempt:', attemptNumber);
+ });
+
+ socket.on('error', (error) => {
+ console.error('Socket error:', error);
});
- });
-
- socket.on('disconnect', (reason) => {
- console.log('Socket disconnected:', reason);
- });
-
- socket.on('error', (error) => {
- console.error('Socket error:', error);
- });
-
- socket.on('connect_error', (error) => {
- console.error('Socket connection error:', error);
- });
-}
-
-/**
- * Subscribe to events for a specific research ID
- * @param {number} researchId - The research ID to subscribe to
- */
-function subscribeToResearch(researchId) {
- if (!socket) {
- initializeSocket();
}
- if (!socket || !researchId) return;
-
- // Create a unique event name for this research
- const eventName = `research_progress_${researchId}`;
-
- // Subscribe to this research on the server
- socket.emit('subscribe_to_research', { research_id: researchId });
-
- console.log(`Subscribed to research ${researchId}`);
-}
-
-/**
- * Add an event handler for a specific research
- * @param {number} researchId - The research ID
- * @param {Function} callback - The event handler function
- */
-function addResearchEventHandler(researchId, callback) {
- if (!socket) {
- initializeSocket();
+ /**
+ * Subscribe to research events
+ * @param {string} researchId - The research ID to subscribe to
+ */
+ function subscribeToResearch(researchId) {
+ if (!socket) {
+ console.warn('Socket not initialized, initializing now');
+ initializeSocket();
+ }
+
+ if (!researchId) {
+ console.error('No research ID provided');
+ return;
+ }
+
+ console.log('Subscribing to research:', researchId);
+
+ // Remember the current research ID
+ currentResearchId = researchId;
+
+ // Join the research room
+ socket.emit('join', { research_id: researchId });
+
+ // Setup direct event handler for progress updates
+ socket.on(`progress_${researchId}`, (data) => {
+ console.log('Progress update:', data);
+
+ // Call all registered handlers for this research
+ if (researchEventHandlers[researchId]) {
+ researchEventHandlers[researchId].forEach(callback => {
+ try {
+ callback(data);
+ } catch (error) {
+ console.error('Error in research event handler:', error);
+ }
+ });
+ }
+
+ // If the event contains log data, add it to the console
+ if (data.log && window.addConsoleLog) {
+ window.addConsoleLog(data.log.message, data.log.type || 'info');
+ }
+ });
}
- if (!socket || !researchId || !callback) return;
-
- // Create a unique event name for this research
- const eventName = `research_progress_${researchId}`;
-
- // Remove any existing handler
- removeResearchEventHandler(researchId);
+ /**
+ * Unsubscribe from research events
+ * @param {string} researchId - The research ID to unsubscribe from
+ */
+ function unsubscribeFromResearch(researchId) {
+ if (!socket) return;
+
+ console.log('Unsubscribing from research:', researchId);
+
+ // Leave the research room
+ socket.emit('leave', { research_id: researchId });
+
+ // Remove the event handler
+ socket.off(`progress_${researchId}`);
+
+ // Clear handlers
+ if (researchId === currentResearchId) {
+ currentResearchId = null;
+ researchEventHandlers[researchId] = [];
+ }
+ }
- // Add the handler
- socket.on(eventName, callback);
+ /**
+ * Add a research event handler
+ * @param {string} researchId - The research ID to handle events for
+ * @param {function} callback - The function to call when an event occurs
+ */
+ function addResearchEventHandler(researchId, callback) {
+ if (!researchId || typeof callback !== 'function') {
+ console.error('Invalid research event handler');
+ return;
+ }
+
+ // Initialize the handlers array if needed
+ if (!researchEventHandlers[researchId]) {
+ researchEventHandlers[researchId] = [];
+ }
+
+ // Add the handler
+ researchEventHandlers[researchId].push(callback);
+ }
- // Store the handler reference
- if (!researchEventHandlers.has(researchId)) {
- researchEventHandlers.set(researchId, new Set());
+ /**
+ * Remove a research event handler
+ * @param {string} researchId - The research ID to remove handler for
+ * @param {function} callback - The function to remove
+ */
+ function removeResearchEventHandler(researchId, callback) {
+ if (!researchId || !researchEventHandlers[researchId]) return;
+
+ // Find the handler index
+ const index = researchEventHandlers[researchId].indexOf(callback);
+
+ // Remove if found
+ if (index !== -1) {
+ researchEventHandlers[researchId].splice(index, 1);
+ }
}
- researchEventHandlers.get(researchId).add(callback);
- // Subscribe to the research
- subscribeToResearch(researchId);
-}
-
-/**
- * Remove an event handler for a specific research
- * @param {number} researchId - The research ID
- * @param {Function} callback - Optional specific callback to remove
- */
-function removeResearchEventHandler(researchId, callback) {
- if (!socket || !researchId) return;
+ /**
+ * Set a callback for socket reconnection
+ * @param {function} callback - The function to call on reconnection
+ */
+ function setReconnectCallback(callback) {
+ reconnectCallback = callback;
+ }
- // Create a unique event name for this research
- const eventName = `research_progress_${researchId}`;
+ /**
+ * Disconnect the socket
+ */
+ function disconnectSocket() {
+ if (socket) {
+ socket.disconnect();
+ socket = null;
+ researchEventHandlers = {};
+ reconnectCallback = null;
+ currentResearchId = null;
+ }
+ }
- if (callback) {
- // Remove specific callback
- socket.off(eventName, callback);
-
- // Remove from our registry
- const handlers = researchEventHandlers.get(researchId);
- if (handlers) {
- handlers.delete(callback);
- if (handlers.size === 0) {
- researchEventHandlers.delete(researchId);
+ /**
+ * Filter log messages by type
+ * @param {string} type - The log type to filter by ('all', 'info', 'error', 'milestone')
+ */
+ function filterLogsByType(type) {
+ console.log('Filtering logs by type:', type);
+
+ // Update button UI
+ const buttons = document.querySelectorAll('.filter-buttons .small-btn');
+ buttons.forEach(button => {
+ button.classList.remove('selected');
+ if (button.textContent.toLowerCase() === type ||
+ (type === 'all' && button.textContent.toLowerCase() === 'all')) {
+ button.classList.add('selected');
}
- }
- } else {
- // Remove all callbacks for this research
- socket.off(eventName);
+ });
+
+ // Get all log entries
+ const logEntries = document.querySelectorAll('.console-log-entry');
- // Remove from our registry
- researchEventHandlers.delete(researchId);
+ logEntries.forEach(entry => {
+ const badge = entry.querySelector('.log-badge');
+ const logType = badge ? badge.textContent.toLowerCase() : 'info';
+
+ if (type === 'all' || logType === type) {
+ entry.style.display = '';
+ } else {
+ entry.style.display = 'none';
+ }
+ });
+
+ // Update empty state message if needed
+ const logContainer = document.getElementById('console-log-container');
+ if (logContainer) {
+ const visibleEntries = logContainer.querySelectorAll('.console-log-entry[style="display: ;"], .console-log-entry:not([style])');
+ const emptyMessage = logContainer.querySelector('.empty-log-message');
+
+ if (visibleEntries.length === 0 && !emptyMessage) {
+ logContainer.innerHTML = `<div class="empty-log-message">No ${type === 'all' ? '' : type + ' '}logs available.</div>` + logContainer.innerHTML;
+ } else if (visibleEntries.length > 0 && emptyMessage) {
+ emptyMessage.remove();
+ }
+ }
}
-}
-
-/**
- * Disconnect and cleanup all socket events
- */
-function disconnectSocket() {
- if (!socket) return;
- // Remove all event handlers
- researchEventHandlers.forEach((handlers, researchId) => {
- removeResearchEventHandler(researchId);
- });
+ // Initialize socket on load
+ initializeSocket();
- // Disconnect the socket
- socket.disconnect();
- socket = null;
+ // Expose the log filtering function globally
+ window.filterLogsByType = filterLogsByType;
- console.log('Socket disconnected and cleaned up');
-}
-
-// Export the socket service functions
-window.socketService = {
- initializeSocket,
- subscribeToResearch,
- addResearchEventHandler,
- removeResearchEventHandler,
- disconnectSocket,
- getSocket: () => socket
-};
\ No newline at end of file
+ // Public API
+ return {
+ init: initializeSocket,
+ subscribeToResearch,
+ unsubscribeFromResearch,
+ onReconnect: setReconnectCallback,
+ disconnect: disconnectSocket,
+ getSocketInstance: () => socket
+ };
+})();
\ No newline at end of file
diff --git a/src/local_deep_research/web/static/js/services/ui.js b/src/local_deep_research/web/static/js/services/ui.js
index 1818df99b6..6588c29510 100644
--- a/src/local_deep_research/web/static/js/services/ui.js
+++ b/src/local_deep_research/web/static/js/services/ui.js
@@ -213,6 +213,50 @@ function createDynamicFavicon(emoji = '⚡') {
link.href = dataUrl;
}
+/**
+ * Update favicon to indicate status
+ * @param {string} status - Status to indicate (active, complete, error)
+ */
+function updateFavicon(status) {
+ try {
+ const faviconLink = document.querySelector('link[rel="icon"]') ||
+ document.querySelector('link[rel="shortcut icon"]');
+
+ if (!faviconLink) {
+ console.warn('Favicon link not found');
+ return;
+ }
+
+ let iconPath;
+ switch (status) {
+ case 'active':
+ case 'in_progress':
+ iconPath = '/research/static/img/favicon-active.ico';
+ break;
+ case 'completed':
+ case 'complete':
+ iconPath = '/research/static/img/favicon-complete.ico';
+ break;
+ case 'failed':
+ case 'error':
+ iconPath = '/research/static/img/favicon-error.ico';
+ break;
+ case 'cancelled':
+ case 'cancel':
+ iconPath = '/research/static/img/favicon-cancel.ico';
+ break;
+ default:
+ iconPath = '/research/static/img/favicon.ico';
+ }
+
+ // Add cache busting parameter to force reload
+ faviconLink.href = iconPath + '?v=' + new Date().getTime();
+ console.log('Updated favicon to:', status);
+ } catch (error) {
+ console.error('Failed to update favicon:', error);
+ }
+}
+
// Add CSS for toast messages
function addToastStyles() {
if (document.getElementById('toast-styles')) return;
@@ -302,5 +346,6 @@ window.ui = {
showError,
showMessage,
renderMarkdown,
- createDynamicFavicon
+ createDynamicFavicon,
+ updateFavicon
};
\ No newline at end of file
diff --git a/src/local_deep_research/web/templates/pages/progress.html b/src/local_deep_research/web/templates/pages/progress.html
index 0eb4f4281c..9309eab229 100644
--- a/src/local_deep_research/web/templates/pages/progress.html
+++ b/src/local_deep_research/web/templates/pages/progress.html
@@ -16,44 +16,41 @@
</div>
<div class="progress-container">
<div class="progress-bar">
- <div id="progress-fill" class="progress-fill"></div>
+ <div id="progress-bar" class="progress-fill"></div>
</div>
<div id="progress-percentage" class="progress-percentage">0%</div>
</div>
- <div id="progress-status" class="progress-status">Initializing research process...</div>
+ <div class="status-container">
+ <div class="status-label">Status:</div>
+ <div id="status-text" class="status-indicator">Initializing</div>
+ </div>
+ <div class="task-container">
+ <div class="task-label">Current Task:</div>
+ <div id="current-task" class="task-text">Starting research...</div>
+ </div>
<div class="progress-actions">
- <button id="terminate-research-btn" class="btn btn-outline terminate-btn" style="display: none;">
- <i class="fas fa-stop-circle"></i> Terminate Research
- </button>
- <div id="error-message" class="error-message" style="display: none;"></div>
- <button id="try-again-btn" class="btn btn-primary" style="display: none; margin-top: 15px;">
- <i class="fas fa-redo"></i> Try Again
+ <button id="cancel-research-btn" class="btn btn-outline terminate-btn">
+ <i class="fas fa-stop-circle"></i> Cancel Research
</button>
+ <a id="view-results-btn" class="btn btn-primary" style="display: none;">
+ <i class="fas fa-eye"></i> View Results
+ </a>
</div>
</div>
</div>
</div>
+
+ {% include "components/log_panel.html" %}
</div>
{% endblock %}
{% block page_scripts %}
+<!-- Load required services first -->
+<script src="{{ url_for('research.serve_static', path='js/services/ui.js') }}"></script>
+<script src="{{ url_for('research.serve_static', path='js/services/formatting.js') }}"></script>
+<script src="{{ url_for('research.serve_static', path='js/services/api.js') }}"></script>
+<script src="{{ url_for('research.serve_static', path='js/services/socket.js') }}"></script>
+
+<!-- Then load the component -->
<script src="{{ url_for('research.serve_static', path='js/components/progress.js') }}"></script>
-<script>
- document.addEventListener('DOMContentLoaded', function() {
- // Initialize the terminate button event listener
- const terminateBtn = document.getElementById('terminate-research-btn');
- if (terminateBtn) {
- terminateBtn.addEventListener('click', function() {
- // Get the current research ID from the page
- const currentResearchId = window.currentResearchId;
- if (currentResearchId) {
- window.terminateResearch(currentResearchId);
- } else {
- console.error('No active research ID found');
- alert('No active research found to terminate');
- }
- });
- }
- });
-</script>
{% endblock %}
\ No newline at end of file