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.

refactor: remove sources panel from results page

LearningCircuit22354a932310
diff --git a/src/local_deep_research/web/static/css/components/sources-slider.css b/src/local_deep_research/web/static/css/components/sources-slider.css
deleted file mode 100644
index 14c1281693..0000000000
--- a/src/local_deep_research/web/static/css/components/sources-slider.css
+++ /dev/null
@@ -1,338 +0,0 @@
-/* Sources Slider Styles */
-.ldr-sources-slider {
- position: fixed !important;
- right: -500px;
- top: 60px;
- width: 500px;
- height: calc(100vh - 60px);
- background: var(--card-bg, #1a1a1a) !important;
- border-left: 1px solid var(--border-color, #333) !important;
- box-shadow: -2px 0 10px rgba(0, 0, 0, 0.3) !important;
- transition: right 0.3s ease;
- z-index: 99998 !important;
- display: flex !important;
- flex-direction: column !important;
- color: var(--text-primary, #e0e0e0) !important;
-}
-
-.ldr-sources-slider.active {
- right: 0;
-}
-
-/* Toggle button */
-.ldr-sources-toggle {
- position: fixed !important;
- right: 0 !important;
- top: 50% !important;
- transform: translateY(-50%) !important;
- background: #007bff !important;
- color: white !important;
- border: none !important;
- border-radius: 8px 0 0 8px !important;
- padding: 15px 10px !important;
- cursor: pointer !important;
- z-index: 99999 !important;
- transition: all 0.3s ease !important;
- writing-mode: vertical-rl !important;
- text-orientation: mixed !important;
- font-size: 14px !important;
- font-weight: 600 !important;
- box-shadow: -2px 0 8px rgba(0, 0, 0, 0.3) !important;
- display: block !important;
- visibility: visible !important;
-}
-
-.ldr-sources-toggle:hover {
- background: var(--primary-hover);
- padding-left: 15px;
-}
-
-.ldr-sources-toggle.active {
- right: 400px;
- border-radius: 4px;
- writing-mode: horizontal-tb;
- padding: 10px 15px;
-}
-
-/* Slider header */
-.ldr-sources-header {
- padding: 20px;
- border-bottom: 1px solid var(--border-color, #333);
- background: var(--bg-color, #0f0f0f);
- color: var(--text-primary, #e0e0e0);
-}
-
-.ldr-sources-header h3 {
- margin: 0 0 10px 0;
- color: var(--text-primary);
- font-size: 18px;
- font-weight: 600;
-}
-
-.ldr-sources-stats {
- display: flex;
- gap: 20px;
- font-size: 14px;
- color: var(--text-secondary);
-}
-
-.ldr-sources-stat {
- display: flex;
- align-items: center;
- gap: 5px;
-}
-
-.ldr-sources-stat i {
- color: var(--primary-color);
-}
-
-/* Sources filter */
-.ldr-sources-filter {
- padding: 15px 20px;
- border-bottom: 1px solid var(--border-color);
- background: var(--bg-color);
-}
-
-.ldr-sources-search {
- width: 100%;
- padding: 8px 12px;
- border: 1px solid var(--border-color);
- border-radius: 4px;
- background: var(--card-bg);
- color: var(--text-primary);
- font-size: 14px;
-}
-
-.ldr-sources-search:focus {
- outline: none;
- border-color: var(--primary-color);
-}
-
-/* Sources list */
-.ldr-sources-list {
- flex: 1;
- overflow-y: auto;
- padding: 20px;
-}
-
-.ldr-source-item {
- background: var(--bg-color, #0f0f0f);
- border: 1px solid var(--border-color, #333);
- border-radius: 8px;
- padding: 20px;
- margin-bottom: 20px;
- transition: all 0.2s ease;
- cursor: pointer;
- color: var(--text-primary, #e0e0e0);
-}
-
-.ldr-source-item:hover {
- border-color: var(--primary-color);
- box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
- transform: translateY(-1px);
-}
-
-.ldr-source-item.downloaded {
- border-left: 3px solid var(--success-color);
-}
-
-.ldr-source-header {
- display: flex;
- justify-content: space-between;
- align-items: start;
- margin-bottom: 12px;
-}
-
-.ldr-source-number {
- background: var(--primary-color);
- color: white;
- padding: 2px 8px;
- border-radius: 12px;
- font-size: 12px;
- font-weight: 600;
- min-width: 24px;
- text-align: center;
-}
-
-.ldr-source-status {
- display: flex;
- align-items: center;
- gap: 8px;
-}
-
-.ldr-source-status i {
- font-size: 16px;
-}
-
-.ldr-source-status .ldr-downloaded-icon {
- color: var(--success-color);
-}
-
-.ldr-source-status .ldr-not-downloaded-icon {
- color: var(--text-secondary);
-}
-
-.ldr-source-title {
- font-weight: 600;
- color: var(--text-primary, #e0e0e0);
- margin-bottom: 10px;
- font-size: 15px;
- line-height: 1.5;
- display: -webkit-box;
- -webkit-line-clamp: 2;
- -webkit-box-orient: vertical;
- overflow: hidden;
-}
-
-.ldr-source-snippet {
- color: var(--text-secondary, #999) !important;
- font-size: 14px !important;
- line-height: 1.6 !important;
- margin: 12px 0 !important;
- padding: 12px !important;
- background: rgba(255, 255, 255, 0.05) !important;
- border-left: 3px solid var(--primary-color, #007bff) !important;
- border-radius: 4px !important;
- font-style: normal !important;
- display: block !important;
-}
-
-.ldr-source-url {
- color: var(--text-secondary);
- font-size: 12px;
- margin-bottom: 8px;
- white-space: nowrap;
- overflow: hidden;
- text-overflow: ellipsis;
-}
-
-.ldr-source-domain {
- display: inline-block;
- background: var(--bg-color);
- border: 1px solid var(--border-color);
- padding: 2px 8px;
- border-radius: 4px;
- font-size: 11px;
- color: var(--text-secondary);
- margin-bottom: 8px;
-}
-
-.ldr-source-actions {
- display: flex;
- gap: 10px;
- margin-top: 10px;
-}
-
-.ldr-source-btn {
- flex: 1;
- padding: 6px 12px;
- border: 1px solid var(--border-color);
- border-radius: 4px;
- background: var(--card-bg);
- color: var(--text-primary);
- font-size: 12px;
- cursor: pointer;
- transition: all 0.2s ease;
- text-decoration: none;
- text-align: center;
- display: flex;
- align-items: center;
- justify-content: center;
- gap: 5px;
-}
-
-.ldr-source-btn:hover {
- background: var(--primary-color);
- color: white;
- border-color: var(--primary-color);
-}
-
-.ldr-source-btn.primary {
- background: var(--primary-color);
- color: white;
- border-color: var(--primary-color);
-}
-
-.ldr-source-btn.primary:hover {
- background: var(--primary-hover);
- border-color: var(--primary-hover);
-}
-
-/* Empty state */
-.ldr-sources-empty {
- text-align: center;
- padding: 40px 20px;
- color: var(--text-secondary);
-}
-
-.ldr-sources-empty i {
- font-size: 48px;
- margin-bottom: 15px;
- opacity: 0.5;
-}
-
-/* Loading state */
-.ldr-sources-loading {
- display: flex;
- justify-content: center;
- align-items: center;
- height: 200px;
- color: var(--text-secondary);
-}
-
-.ldr-sources-loading i {
- font-size: 24px;
- animation: spin 1s linear infinite;
-}
-
-@keyframes spin {
- from { transform: rotate(0deg); }
- to { transform: rotate(360deg); }
-}
-
-/* Responsive adjustments */
-@media (max-width: 768px) {
- .ldr-sources-slider {
- width: 100%;
- right: -100%;
- }
-
- .ldr-sources-toggle.active {
- right: calc(100% - 40px);
- }
-
- .ldr-sources-slider.active {
- right: 0;
- }
-}
-
-/* Dark theme adjustments */
-[data-theme="dark"] .ldr-sources-slider {
- background: #1a1a1a;
- border-left-color: #333;
-}
-
-[data-theme="dark"] .ldr-source-item {
- background: #2a2a2a;
- border-color: #333;
-}
-
-[data-theme="dark"] .ldr-source-item:hover {
- border-color: var(--primary-color);
-}
-
-[data-theme="dark"] .ldr-sources-header,
-[data-theme="dark"] .ldr-sources-filter {
- background: #1a1a1a;
- border-bottom-color: #333;
-}
-
-[data-theme="dark"] .ldr-sources-search {
- background: #2a2a2a;
- border-color: #333;
-}
-
-[data-theme="dark"] .ldr-source-btn {
- background: #2a2a2a;
- border-color: #333;
-}
diff --git a/src/local_deep_research/web/static/js/components/results.js b/src/local_deep_research/web/static/js/components/results.js
index 621430f1a7..4fd4755eda 100644
--- a/src/local_deep_research/web/static/js/components/results.js
+++ b/src/local_deep_research/web/static/js/components/results.js
@@ -43,17 +43,6 @@
// Initialize star rating
initializeStarRating();
- // Initialize sources panel (Bootstrap offcanvas)
- // Add a small delay to ensure the panel script is loaded
- setTimeout(() => {
- if (window.sourcesPanel) {
- console.log('Initializing sources panel...');
- window.sourcesPanel.initialize(researchId);
- } else {
- console.log('Sources panel not available');
- }
- }, 100);
-
// Note: Log panel is now automatically initialized by logpanel.js
// No need to manually initialize it here
}
diff --git a/src/local_deep_research/web/static/js/components/sources-panel.js b/src/local_deep_research/web/static/js/components/sources-panel.js
deleted file mode 100644
index 2c21e2f960..0000000000
--- a/src/local_deep_research/web/static/js/components/sources-panel.js
+++ /dev/null
@@ -1,458 +0,0 @@
-/**
- * Sources Panel Component using Bootstrap Offcanvas
- * A persistent panel that stays open like Mendeley's reference panel
- */
-(function() {
- let sources = [];
- let researchId = null;
- let offcanvas = null;
-
- /**
- * Initialize the sources panel
- */
- function initializeSourcesPanel(research_id) {
- console.log('Initializing sources panel for research:', research_id);
- researchId = research_id;
-
- // Create the offcanvas HTML if it doesn't exist
- if (!document.getElementById('sourcesOffcanvas')) {
- createOffcanvasHTML();
- }
-
- // Initialize Bootstrap offcanvas
- const offcanvasElement = document.getElementById('sourcesOffcanvas');
- offcanvas = new bootstrap.Offcanvas(offcanvasElement, {
- backdrop: false, // No backdrop so user can interact with main content
- keyboard: false, // Don't close on ESC
- scroll: true // Allow scrolling of main content
- });
-
- // Set up toggle button
- setupToggleButton();
-
- // Load sources
- loadSources();
-
- // Restore state from localStorage
- restoreState();
- }
-
- /**
- * Create the offcanvas HTML structure
- */
- function createOffcanvasHTML() {
- const html = `
- <!-- Toggle Button -->
- <button class="btn btn-primary ldr-sources-panel-toggle"
- id="sourcesToggle"
- type="button"
- title="Toggle Sources Panel">
- <i class="fas fa-book"></i>
- <span class="ms-1">Sources</span>
- </button>
-
- <!-- Offcanvas Panel -->
- <div class="offcanvas offcanvas-end ldr-sources-offcanvas"
- tabindex="-1"
- id="sourcesOffcanvas"
- data-bs-backdrop="false"
- data-bs-scroll="true">
- <div class="offcanvas-header">
- <h5 class="offcanvas-title">Research Sources</h5>
- <button type="button"
- class="btn-close"
- data-bs-dismiss="offcanvas"
- aria-label="Close"></button>
- </div>
- <div class="offcanvas-body">
- <!-- Search -->
- <div class="mb-3">
- <input type="text"
- class="form-control"
- id="sourcesSearch"
- placeholder="Search sources...">
- </div>
-
- <!-- Stats -->
- <div class="d-flex justify-content-between mb-3">
- <small class="text-muted">
- <i class="fas fa-file-alt"></i>
- <span id="totalSources">0</span> sources
- </small>
- <small class="text-muted">
- <i class="fas fa-download"></i>
- <span id="downloadedSources">0</span> downloaded
- </small>
- </div>
-
- <!-- Sources List -->
- <div id="sourcesList" class="ldr-sources-list">
- <div class="text-center p-4">
- <div class="spinner-border text-primary" role="status">
- <span class="visually-hidden">Loading...</span>
- </div>
- </div>
- </div>
- </div>
- </div>
- `;
-
- // Add to body
- document.body.insertAdjacentHTML('beforeend', html);
-
- // Add custom styles
- addCustomStyles();
- }
-
- /**
- * Add custom styles for the sources panel
- */
- function addCustomStyles() {
- const style = document.createElement('style');
- style.textContent = `
- .ldr-sources-panel-toggle {
- position: fixed;
- right: 20px;
- bottom: 80px;
- z-index: 1040;
- border-radius: 50px;
- padding: 10px 20px;
- box-shadow: 0 2px 10px rgba(0,0,0,0.2);
- }
-
- .ldr-sources-offcanvas {
- width: 450px !important;
- background: var(--card-bg, #fff);
- border-left: 1px solid var(--border-color, #dee2e6);
- }
-
- .ldr-sources-offcanvas .offcanvas-header {
- background: var(--bg-color, #f8f9fa);
- border-bottom: 1px solid var(--border-color, #dee2e6);
- }
-
- .ldr-source-card {
- background: var(--bg-color, #f8f9fa);
- border: 1px solid var(--border-color, #dee2e6);
- border-radius: 8px;
- padding: 15px;
- margin-bottom: 15px;
- transition: all 0.2s;
- }
-
- .ldr-source-card:hover {
- border-color: var(--primary-color, #0d6efd);
- box-shadow: 0 2px 8px rgba(0,0,0,0.1);
- }
-
- .ldr-source-card.downloaded {
- border-left: 3px solid var(--success-color, #198754);
- }
-
- .ldr-source-number {
- display: inline-block;
- background: var(--primary-color, #0d6efd);
- color: white;
- padding: 2px 8px;
- border-radius: 12px;
- font-size: 12px;
- font-weight: 600;
- margin-right: 8px;
- }
-
- .ldr-source-title {
- font-weight: 600;
- margin-bottom: 8px;
- color: var(--text-primary, #212529);
- }
-
- .ldr-source-snippet {
- font-size: 14px;
- color: var(--text-secondary, #6c757d);
- margin: 10px 0;
- padding: 10px;
- background: rgba(0,0,0,0.03);
- border-left: 3px solid var(--primary-color, #0d6efd);
- border-radius: 4px;
- }
-
- .ldr-source-domain {
- display: inline-block;
- font-size: 12px;
- color: var(--text-secondary, #6c757d);
- background: rgba(0,0,0,0.05);
- padding: 2px 8px;
- border-radius: 4px;
- margin-bottom: 8px;
- }
-
- .ldr-source-url {
- font-size: 12px;
- color: var(--text-secondary, #6c757d);
- white-space: nowrap;
- overflow: hidden;
- text-overflow: ellipsis;
- margin-bottom: 10px;
- }
-
- .ldr-sources-list {
- max-height: calc(100vh - 250px);
- overflow-y: auto;
- }
-
- /* Dark theme adjustments */
- [data-theme="dark"] .ldr-sources-offcanvas {
- background: #1a1a1a;
- color: #e0e0e0;
- }
-
- [data-theme="dark"] .ldr-source-card {
- background: #2a2a2a;
- border-color: #333;
- }
-
- [data-theme="dark"] .ldr-source-snippet {
- background: rgba(255,255,255,0.05);
- }
- `;
- document.head.appendChild(style);
- }
-
- /**
- * Set up toggle button event
- */
- function setupToggleButton() {
- const toggleBtn = document.getElementById('sourcesToggle');
- if (toggleBtn) {
- toggleBtn.addEventListener('click', () => {
- if (offcanvas) {
- offcanvas.toggle();
- // Save state
- const isOpen = document.getElementById('sourcesOffcanvas').classList.contains('show');
- localStorage.setItem('sourcesPanel_open', !isOpen);
- }
- });
- }
-
- // Set up search
- const searchInput = document.getElementById('sourcesSearch');
- if (searchInput) {
- searchInput.addEventListener('input', handleSearch);
- }
- }
-
- /**
- * Load sources from the API
- */
- async function loadSources() {
- try {
- const response = await fetch(`/library/api/get-research-sources/${researchId}`);
-
- if (!response.ok) {
- throw new Error('Failed to fetch sources');
- }
-
- const data = await response.json();
-
- if (data.success && data.sources) {
- sources = data.sources;
- console.log(`Loaded ${sources.length} sources from database`);
- updateStats();
- renderSources(sources);
- }
- } catch (error) {
- console.error('Error loading sources:', error);
- showError('Failed to load sources');
- }
- }
-
- /**
- * Update statistics
- */
- function updateStats() {
- const totalEl = document.getElementById('totalSources');
- const downloadedEl = document.getElementById('downloadedSources');
-
- if (totalEl) totalEl.textContent = sources.length;
- if (downloadedEl) {
- const downloadedCount = sources.filter(s => s.downloaded).length;
- downloadedEl.textContent = downloadedCount;
- }
- }
-
- /**
- * Render sources
- */
- function renderSources(sourcesToRender) {
- const listEl = document.getElementById('sourcesList');
- if (!listEl) return;
-
- if (sourcesToRender.length === 0) {
- listEl.innerHTML = `
- <div class="text-center p-4 text-muted">
- <i class="fas fa-inbox fa-3x mb-3"></i>
- <p>No sources found</p>
- </div>
- `;
- return;
- }
-
- listEl.innerHTML = sourcesToRender.map(source => `
- <div class="ldr-source-card ${source.downloaded ? 'downloaded' : ''}">
- <div class="d-flex justify-content-between align-items-start mb-2">
- <div>
- <span class="ldr-source-number">${source.number}</span>
- ${source.downloaded ?
- '<i class="fas fa-check-circle text-success" title="Downloaded"></i>' :
- '<i class="fas fa-cloud-download-alt text-muted" title="Not downloaded"></i>'
- }
- </div>
- </div>
-
- <div class="ldr-source-title">${escapeHtml(source.title)}</div>
-
- ${source.domain ? `<span class="ldr-source-domain">${escapeHtml(source.domain)}</span>` : ''}
-
- ${source.snippet ? `
- <div class="ldr-source-snippet">
- ${escapeHtml(source.snippet).substring(0, 200)}${source.snippet.length > 200 ? '...' : ''}
- </div>
- ` : ''}
-
- <div class="ldr-source-url" title="${escapeHtml(source.url)}">
- ${escapeHtml(source.url)}
- </div>
-
- <div class="d-flex gap-2">
- ${source.downloaded ? `
- <a href="/library/view/${source.document_id}"
- class="btn btn-sm btn-primary"
- target="_blank">
- <i class="fas fa-book-open"></i> View in Library
- </a>
- ` : `
- <button class="btn btn-sm btn-outline-primary"
- onclick="sourcesPanel.downloadSource('${escapeHtml(source.url)}')">
- <i class="fas fa-download"></i> Download
- </button>
- <button class="btn btn-sm btn-outline-secondary"
- onclick="sourcesPanel.openExternalUrl('${escapeHtml(source.url)}')">
- <i class="fas fa-external-link-alt"></i> Open
- </button>
- `}
- </div>
- </div>
- `).join('');
- }
-
- /**
- * Handle search
- */
- function handleSearch(e) {
- const query = e.target.value.toLowerCase();
-
- if (!query) {
- renderSources(sources);
- } else {
- const filtered = sources.filter(source =>
- (source.title && source.title.toLowerCase().includes(query)) ||
- (source.url && source.url.toLowerCase().includes(query)) ||
- (source.domain && source.domain.toLowerCase().includes(query)) ||
- (source.snippet && source.snippet.toLowerCase().includes(query))
- );
- renderSources(filtered);
- }
- }
-
- /**
- * Download a source
- */
- async function downloadSource(url) {
- try {
- const response = await fetch('/library/api/download-source', {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json'
- },
- body: JSON.stringify({
- research_id: researchId,
- url: url
- })
- });
-
- if (response.ok) {
- // Reload sources to update status
- await loadSources();
- showMessage('Download started');
- } else {
- showError('Failed to start download');
- }
- } catch (error) {
- console.error('Error downloading source:', error);
- showError('Failed to download source');
- }
- }
-
- /**
- * Restore panel state from localStorage
- */
- function restoreState() {
- const isOpen = localStorage.getItem('sourcesPanel_open') === 'true';
- if (isOpen && offcanvas) {
- offcanvas.show();
- }
- }
-
- /**
- * Show error message
- */
- function showError(message) {
- const listEl = document.getElementById('sourcesList');
- if (listEl) {
- listEl.innerHTML = `
- <div class="alert alert-danger" role="alert">
- ${message}
- </div>
- `;
- }
- }
-
- /**
- * Show success message
- */
- function showMessage(message) {
- // You could use a toast notification here
- console.log(message);
- }
-
- /**
- * Escape HTML
- */
- function escapeHtml(text) {
- const div = document.createElement('div');
- div.textContent = text || '';
- return div.innerHTML;
- }
-
- /**
- * Open external URL with validation
- */
- function openExternalUrl(url) {
- if (URLValidator.isSafeUrl(url)) {
- window.open(url, '_blank');
- } else {
- console.error('Unsafe URL blocked:', url);
- alert('This URL cannot be opened for security reasons.');
- }
- }
-
- // Export public methods
- window.sourcesPanel = {
- initialize: initializeSourcesPanel,
- downloadSource: downloadSource,
- openExternalUrl: openExternalUrl,
- reload: loadSources
- };
-
- console.log('Sources panel component loaded');
-})();
diff --git a/src/local_deep_research/web/static/js/components/sources-slider.js b/src/local_deep_research/web/static/js/components/sources-slider.js
deleted file mode 100644
index 607df999bd..0000000000
--- a/src/local_deep_research/web/static/js/components/sources-slider.js
+++ /dev/null
@@ -1,705 +0,0 @@
-/**
- * Sources Slider Component
- * Displays research sources with links to downloaded documents
- */
-
-// URL validation utilities matching Python URLValidator
-const URLValidator = {
- UNSAFE_SCHEMES: ['javascript', 'data', 'vbscript', 'about', 'blob', 'file'],
- SAFE_SCHEMES: ['http', 'https', 'ftp', 'ftps'],
- EMAIL_SCHEME: 'mailto',
-
- isUnsafeScheme: function(url) {
- if (!url) return false;
-
- const normalizedUrl = url.trim().toLowerCase();
-
- for (const scheme of this.UNSAFE_SCHEMES) {
- if (normalizedUrl.startsWith(scheme + ':')) {
- console.warn(`Unsafe URL scheme detected: ${scheme}`);
- return true;
- }
- }
-
- return false;
- },
-
- isSafeUrl: function(url, options = {}) {
- const {
- requireScheme = true,
- allowFragments = true,
- allowMailto = false,
- trustedDomains = []
- } = options;
-
- if (!url || typeof url !== 'string') {
- return false;
- }
-
- // Check for unsafe schemes first
- if (this.isUnsafeScheme(url)) {
- return false;
- }
-
- // Handle fragment-only URLs
- if (url.startsWith('#')) {
- return allowFragments;
- }
-
- // Parse the URL
- try {
- const parsed = new URL(url, window.location.href);
- const scheme = parsed.protocol.slice(0, -1).toLowerCase(); // Remove trailing ':'
-
- // Check if it's a mailto link
- if (scheme === this.EMAIL_SCHEME) {
- return allowMailto;
- }
-
- // Check if it's a safe scheme
- if (!this.SAFE_SCHEMES.includes(scheme)) {
- console.warn(`Unsafe URL scheme: ${scheme}`);
- return false;
- }
-
- // Validate domain if trusted domains are specified
- if (trustedDomains.length > 0 && parsed.hostname) {
- const hostname = parsed.hostname.toLowerCase();
- const isTrusted = trustedDomains.some(domain =>
- hostname === domain.toLowerCase() ||
- hostname.endsWith('.' + domain.toLowerCase())
- );
-
- if (!isTrusted) {
- console.warn(`URL domain not in trusted list: ${parsed.hostname}`);
- return false;
- }
- }
-
- return true;
- } catch (e) {
- console.warn(`Failed to parse URL: ${e.message}`);
- return false;
- }
- },
-
- sanitizeUrl: function(url, defaultScheme = 'https') {
- if (!url) return null;
-
- // Check for unsafe schemes
- if (this.isUnsafeScheme(url)) {
- return null;
- }
-
- // Strip whitespace
- url = url.trim();
-
- // Add scheme if missing
- if (!url.match(/^[a-zA-Z][a-zA-Z\d+\-.]*:/)) {
- url = `${defaultScheme}://${url}`;
- }
-
- // Validate the final URL
- if (this.isSafeUrl(url, { requireScheme: true })) {
- return url;
- }
-
- return null;
- }
-};
-
-(function() {
- let sources = [];
- let filteredSources = [];
- let downloadStatus = {};
- let researchId = null;
- let isOpen = false;
-
- /**
- * Initialize the sources slider
- */
- function initializeSourcesSlider(research_id) {
- console.log('Initializing sources slider for research:', research_id);
- researchId = research_id;
-
- // Create slider HTML if it doesn't exist
- if (!document.getElementById('sources-slider')) {
- console.log('Creating slider HTML');
- createSliderHTML();
- }
-
- // Set up event listeners
- setupEventListeners();
-
- // Load sources
- loadSources();
- }
-
- /**
- * Create the slider HTML structure
- */
- function createSliderHTML() {
- const sliderHTML = `
- <button class="ldr-sources-toggle" id="sources-toggle">
- <span class="ldr-toggle-text">Sources</span>
- </button>
-
- <div class="ldr-sources-slider" id="sources-slider">
- <div class="ldr-sources-header">
- <h3>Research Sources</h3>
- <div class="ldr-sources-stats">
- <div class="ldr-sources-stat">
- <i class="fas fa-file-alt"></i>
- <span id="total-sources">0</span> sources
- </div>
- <div class="ldr-sources-stat">
- <i class="fas fa-download"></i>
- <span id="downloaded-sources">0</span> downloaded
- </div>
- </div>
- </div>
-
- <div class="ldr-sources-filter">
- <input type="text"
- class="ldr-sources-search"
- id="sources-search"
- placeholder="Search sources...">
- </div>
-
- <div class="ldr-sources-list" id="sources-list">
- <div class="ldr-sources-loading">
- <i class="fas fa-spinner fa-spin"></i>
- </div>
- </div>
- </div>
- `;
-
- // Add to body
- document.body.insertAdjacentHTML('beforeend', sliderHTML);
-
- // Verify elements were created
- const toggle = document.getElementById('sources-toggle');
- const slider = document.getElementById('sources-slider');
- console.log('Toggle button created:', !!toggle);
- console.log('Slider panel created:', !!slider);
-
- // Apply inline styles to ensure they work
- if (toggle) {
- toggle.style.position = 'fixed';
- toggle.style.right = '0';
- toggle.style.top = '50%';
- toggle.style.transform = 'translateY(-50%)';
- toggle.style.zIndex = '99999';
- toggle.style.background = '#007bff';
- toggle.style.color = 'white';
- toggle.style.padding = '15px 10px';
- toggle.style.border = 'none';
- toggle.style.borderRadius = '8px 0 0 8px';
- toggle.style.cursor = 'pointer';
- toggle.style.writingMode = 'vertical-rl';
- toggle.style.fontSize = '14px';
- toggle.style.fontWeight = '600';
- toggle.style.boxShadow = '-2px 0 8px rgba(0, 0, 0, 0.3)';
- console.log('Applied inline styles to toggle button');
- }
-
- if (slider) {
- slider.style.position = 'fixed';
- slider.style.right = '-500px';
- slider.style.top = '60px';
- slider.style.width = '500px';
- slider.style.height = 'calc(100vh - 60px)';
- slider.style.background = 'var(--card-bg, #1a1a1a)';
- slider.style.borderLeft = '1px solid var(--border-color, #333)';
- slider.style.boxShadow = '-2px 0 10px rgba(0, 0, 0, 0.3)';
- slider.style.transition = 'right 0.3s ease';
- slider.style.zIndex = '99998';
- slider.style.display = 'flex';
- slider.style.flexDirection = 'column';
- slider.style.overflow = 'hidden';
- console.log('Applied inline styles to slider');
- }
- }
-
- /**
- * Set up event listeners
- */
- function setupEventListeners() {
- // Toggle button
- const toggleBtn = document.getElementById('sources-toggle');
- if (toggleBtn) {
- toggleBtn.addEventListener('click', toggleSlider);
- }
-
- // Search input
- const searchInput = document.getElementById('sources-search');
- if (searchInput) {
- searchInput.addEventListener('input', handleSearch);
- }
-
- // Close on escape key
- document.addEventListener('keydown', (e) => {
- if (e.key === 'Escape' && isOpen) {
- closeSlider();
- }
- });
- }
-
- /**
- * Toggle the slider open/closed
- */
- function toggleSlider() {
- if (isOpen) {
- closeSlider();
- } else {
- openSlider();
- }
- }
-
- /**
- * Open the slider
- */
- function openSlider() {
- const slider = document.getElementById('sources-slider');
- const toggle = document.getElementById('sources-toggle');
-
- if (slider && toggle) {
- slider.classList.add('active');
- toggle.classList.add('active');
- toggle.innerHTML = '<i class="fas fa-times"></i>';
-
- // Also apply inline style to ensure it slides out
- slider.style.right = '0';
-
- isOpen = true;
- console.log('Slider opened');
- }
- }
-
- /**
- * Close the slider
- */
- function closeSlider() {
- const slider = document.getElementById('sources-slider');
- const toggle = document.getElementById('sources-toggle');
-
- if (slider && toggle) {
- slider.classList.remove('active');
- toggle.classList.remove('active');
- toggle.innerHTML = '<span class="ldr-toggle-text">Sources</span>';
-
- // Also apply inline style to ensure it slides back
- slider.style.right = '-500px';
-
- isOpen = false;
- console.log('Slider closed');
- }
- }
-
- /**
- * Load sources from the research report
- */
- async function loadSources() {
- try {
- // Fetch sources from the database
- const response = await fetch(`/library/api/get-research-sources/${researchId}`);
-
- if (!response.ok) {
- throw new Error('Failed to fetch sources');
- }
-
- const data = await response.json();
-
- if (data.success && data.sources) {
- sources = data.sources;
- console.log(`Loaded ${sources.length} sources from database`);
-
- // Update download status is already included in the response
- sources.forEach(source => {
- if (source.downloaded) {
- downloadStatus[source.url] = {
- downloaded: true,
- document_id: source.document_id,
- file_type: source.file_type
- };
- }
- });
-
- // Update stats
- updateStats();
-
- // Render sources
- filteredSources = [...sources];
- renderSources();
- } else {
- // Fallback to extracting from report content
- console.log('No sources from database, extracting from report');
- sources = extractSourcesFromReport();
- await checkDownloadStatus();
- updateStats();
- filteredSources = [...sources];
- renderSources();
- }
-
- } catch (error) {
- console.error('Error loading sources:', error);
- // Fallback to extracting from report content
- sources = extractSourcesFromReport();
- await checkDownloadStatus();
- updateStats();
- filteredSources = [...sources];
- renderSources();
- }
- }
-
- /**
- * Extract sources from the report content
- */
- function extractSourcesFromReport() {
- const extractedSources = [];
- const seenUrls = new Set();
-
- // Look for citation links in the report
- const reportContent = document.getElementById('results-content');
- if (!reportContent) {
- console.log('No results-content element found');
- return extractedSources;
- }
- console.log('Extracting sources from report content');
-
- // Find all links with citation markers [1], [2], etc.
- const citationPattern = /\[(\d+)\]/g;
- const links = reportContent.querySelectorAll('a[href]');
-
- console.log(`Found ${links.length} total links in report`);
-
- links.forEach(link => {
- const url = link.href;
- const text = link.textContent || '';
-
- // Skip internal links, anchors, unsafe schemes, and duplicates
- if (!url ||
- url === '' ||
- url === window.location.href ||
- url.startsWith('#') ||
- URLValidator.isUnsafeScheme(url) ||
- url.startsWith('mailto:') ||
- seenUrls.has(url)) {
- return;
- }
-
- // Check if it's an external link
- try {
- const urlObj = new URL(url);
- // Skip if it's the same domain as the current page
- if (urlObj.hostname === window.location.hostname) {
- return;
- }
- } catch (e) {
- console.log('Invalid URL:', url);
- return;
- }
-
- // Check if this looks like a citation link
- const citationMatch = text.match(/\[(\d+)\]/);
- let sourceNumber = extractedSources.length + 1;
-
- if (citationMatch) {
- sourceNumber = parseInt(citationMatch[1]);
- }
-
- seenUrls.add(url);
-
- // Extract title - could be from link text, title attribute, or nearby text
- let title = link.title || text.replace(/\[\d+\]/, '').trim();
- if (!title || title.length < 3) {
- // Try to get text from parent element
- const parent = link.parentElement;
- if (parent) {
- title = parent.textContent.substring(0, 100).trim();
- }
- }
- if (!title) {
- title = 'Untitled Source';
- }
-
- extractedSources.push({
- number: sourceNumber,
- title: title,
- url: url,
- domain: new URL(url).hostname,
- element: link
- });
-
- console.log(`Added source: ${title} - ${url}`);
- });
-
- // Also look for sources in a sources section if it exists
- const sourcesSection = reportContent.querySelector('.ldr-sources-section, .ldr-references-section, #sources, #references');
- if (sourcesSection) {
- const sourceLinks = sourcesSection.querySelectorAll('a[href]');
- sourceLinks.forEach((link, index) => {
- const url = link.href;
- if (!seenUrls.has(url) && !url.startsWith('#') && !URLValidator.isUnsafeScheme(url)) {
- seenUrls.add(url);
- extractedSources.push({
- number: extractedSources.length + 1,
- title: link.textContent || 'Untitled Source',
- url: url,
- domain: new URL(url).hostname,
- element: link
- });
- }
- });
- }
-
- // Sort by number
- extractedSources.sort((a, b) => a.number - b.number);
-
- console.log(`Found ${extractedSources.length} sources in report`);
- return extractedSources;
- }
-
- /**
- * Check download status for sources
- */
- async function checkDownloadStatus() {
- try {
- const response = await fetch('/library/api/check-downloads', {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json'
- },
- body: JSON.stringify({
- research_id: researchId,
- urls: sources.map(s => s.url)
- })
- });
-
- if (response.ok) {
- const data = await response.json();
- downloadStatus = data.download_status || {};
-
- // Add download info to sources
- sources.forEach(source => {
- const status = downloadStatus[source.url];
- if (status) {
- source.downloaded = status.downloaded;
- source.documentId = status.document_id;
- source.filePath = status.file_path;
- }
- });
- }
- } catch (error) {
- console.error('Error checking download status:', error);
- }
- }
-
- /**
- * Update statistics
- */
- function updateStats() {
- const totalSources = sources.length;
- const downloadedSources = sources.filter(s => s.downloaded).length;
-
- const totalEl = document.getElementById('total-sources');
- const downloadedEl = document.getElementById('downloaded-sources');
-
- if (totalEl) totalEl.textContent = totalSources;
- if (downloadedEl) downloadedEl.textContent = downloadedSources;
- }
-
- /**
- * Render sources list
- */
- function renderSources() {
- const listEl = document.getElementById('sources-list');
- if (!listEl) return;
-
- if (filteredSources.length === 0) {
- listEl.innerHTML = `
- <div class="ldr-sources-empty">
- <i class="fas fa-inbox"></i>
- <p>No sources found</p>
- </div>
- `;
- return;
- }
-
- listEl.innerHTML = filteredSources.map(source => `
- <div class="ldr-source-item ${source.downloaded ? 'downloaded' : ''}"
- data-url="${escapeHtml(source.url)}">
- <div class="ldr-source-header">
- <span class="ldr-source-number">${source.number}</span>
- <div class="ldr-source-status">
- ${source.downloaded ?
- '<i class="fas fa-check-circle ldr-downloaded-icon" title="Downloaded"></i>' :
- '<i class="fas fa-cloud-download-alt ldr-not-downloaded-icon" title="Not downloaded"></i>'
- }
- </div>
- </div>
-
- <div class="ldr-source-title" title="${escapeHtml(source.title)}">
- ${escapeHtml(source.title)}
- </div>
-
- <div class="ldr-source-domain">${escapeHtml(source.domain || '')}</div>
-
- ${source.snippet ? `
- <div class="ldr-source-snippet" style="
- color: #999;
- font-size: 14px;
- line-height: 1.6;
- margin: 12px 0;
- padding: 12px;
- background: rgba(255, 255, 255, 0.05);
- border-left: 3px solid #007bff;
- border-radius: 4px;
- display: block;
- ">
- ${escapeHtml(source.snippet).substring(0, 200)}${source.snippet.length > 200 ? '...' : ''}
- </div>
- ` : ''}
-
- <div class="ldr-source-url" title="${escapeHtml(source.url)}">
- ${escapeHtml(source.url)}
- </div>
-
- <div class="ldr-source-actions">
- ${source.downloaded ? `
- <a href="/library/view/${source.document_id || source.documentId}"
- class="ldr-source-btn primary"
- target="_blank">
- <i class="fas fa-book-open"></i> View in Library
- </a>
- <button class="ldr-source-btn" onclick="sourcesSlider.scrollToSource('${escapeHtml(source.url)}')">
- <i class="fas fa-arrow-right"></i> Go to Citation
- </button>
- ` : `
- <button class="ldr-source-btn" onclick="sourcesSlider.downloadSource('${escapeHtml(source.url)}')">
- <i class="fas fa-download"></i> Download
- </button>
- <a href="${escapeHtml(source.url)}"
- class="ldr-source-btn"
- target="_blank"
- rel="noopener noreferrer">
- <i class="fas fa-external-link-alt"></i> Open Source
- </a>
- `}
- </div>
- </div>
- `).join('');
- }
-
- /**
- * Handle search input
- */
- function handleSearch(e) {
- const query = e.target.value.toLowerCase();
-
- if (!query) {
- filteredSources = [...sources];
- } else {
- filteredSources = sources.filter(source =>
- source.title.toLowerCase().includes(query) ||
- source.url.toLowerCase().includes(query) ||
- source.domain.toLowerCase().includes(query)
- );
- }
-
- renderSources();
- }
-
- /**
- * Scroll to source in the report
- */
- function scrollToSource(url) {
- const source = sources.find(s => s.url === url);
- if (source && source.element) {
- source.element.scrollIntoView({ behavior: 'smooth', block: 'center' });
-
- // Highlight the citation
- source.element.style.backgroundColor = 'yellow';
- setTimeout(() => {
- source.element.style.backgroundColor = '';
- }, 2000);
-
- // Close the slider
- closeSlider();
- }
- }
-
- /**
- * Download a source
- */
- async function downloadSource(url) {
- try {
- const response = await fetch('/library/api/download-source', {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json'
- },
- body: JSON.stringify({
- research_id: researchId,
- url: url
- })
- });
-
- if (response.ok) {
- // Reload sources to update status
- await loadSources();
- showMessage('Download started');
- } else {
- showError('Failed to start download');
- }
- } catch (error) {
- console.error('Error downloading source:', error);
- showError('Failed to download source');
- }
- }
-
- /**
- * Show error message
- */
- function showError(message) {
- // Use existing UI utilities if available
- if (window.ui && window.ui.showError) {
- window.ui.showError(message);
- } else {
- console.error(message);
- }
- }
-
- /**
- * Show success message
- */
- function showMessage(message) {
- // Use existing UI utilities if available
- if (window.ui && window.ui.showMessage) {
- window.ui.showMessage(message);
- } else {
- console.log(message);
- }
- }
-
- /**
- * Escape HTML for safety
- */
- function escapeHtml(text) {
- const div = document.createElement('div');
- div.textContent = text;
- return div.innerHTML;
- }
-
- // Export public methods
- window.sourcesSlider = {
- initialize: initializeSourcesSlider,
- open: openSlider,
- close: closeSlider,
- toggle: toggleSlider,
- scrollToSource: scrollToSource,
- downloadSource: downloadSource,
- reload: loadSources
- };
-
-})();
diff --git a/src/local_deep_research/web/templates/pages/results.html b/src/local_deep_research/web/templates/pages/results.html
index e3d63d0525..cf96c1ed74 100644
--- a/src/local_deep_research/web/templates/pages/results.html
+++ b/src/local_deep_research/web/templates/pages/results.html
@@ -74,9 +74,6 @@
<!-- Results component -->
<script src="/static/js/components/results.js"></script>
-<!-- Sources panel component (Bootstrap Offcanvas) -->
-<script src="/static/js/components/sources-panel.js?v={{ range(1000, 9999) | random }}"></script>
-
<!-- Follow-up Research component -->
<script src="/static/js/followup.js"></script>
{% endblock %}