Now add the `loadDeepAnalysis()` JS function. I'll add it near the other deep analysis code:


3345:        // Submit to AI

3345:        // Submit to AI


  3338→            } finally {
  3339→                document.getElementById('loading-overlay').classList.remove('active');
  3340→                document.getElementById('submit-ai-btn').disabled = false;
  3341→                document.getElementById('deep-analysis-btn').disabled = false;
  3342→            }
  3343→        }
  3344→
  3345→        // Submit to AI
  3346→        async function submitToAI() {
  3347→            var selectedProvidersList = getSelectedProviders();

            } finally {
                document.getElementById('loading-overlay').classList.remove('active');
                document.getElementById('submit-ai-btn').disabled = false;
                document.getElementById('deep-analysis-btn').disabled = false;
            }
        }

        // Submit to AI
        async function submitToAI() {
            var selectedProvidersList = getSelectedProviders();


Edit

        // Submit to AI
        async function submitToAI() {

// Load saved Deep Analysis from MongoDB
        async function loadDeepAnalysis() {
            var daContainer = document.getElementById('deep-analysis-container');
            var daResults = document.getElementById('deep-analysis-results');
            var daProgress = document.getElementById('deep-analysis-progress');

            daContainer.style.display = 'block';
            daResults.innerHTML = '
Loading deep analysis...
';
            daProgress.textContent = 'Loading...';
            daContainer.scrollIntoView({ behavior: 'smooth' });

            try {
                var resp = await fetch('api.php?action=load_deep_analysis&thread_id=' + encodeURIComponent(currentThreadId));
                var data = await resp.json();

                if (!data.success || !data.passes || data.passes.length === 0) {
                    daResults.innerHTML = '
No deep analysis found for this thread.
';
                    daProgress.textContent = '';
                    return;
                }

                daResults.innerHTML = '';
                daProgress.textContent = data.passes.length + ' passes loaded';

                data.passes.forEach(function(pass) {
                    var passAgent = AI_AGENTS[pass.agent] || { name: pass.agent, icon: '' };

                    var passSection = document.createElement('div');
                    passSection.style.cssText = 'margin-bottom:20px;border:1px solid #e5e7eb;border-radius:8px;overflow:hidden;';

                    var passHtml = '
' +
                        'Pass ' + pass.pass + ': ' + escapeHtml(pass.name) + '' +
                        'Agent: ' + escapeHtml(passAgent.icon + ' ' + passAgent.name) + '' +
                        '

';

                    pass.responses.forEach(function(r) {
                        passHtml += '
';
                        passHtml += '
';
                        passHtml += '' + escapeHtml(r.provider) + '';
                        passHtml += '' + escapeHtml(r.model) + ' | ' + (r.request_time ? parseFloat(r.request_time).toFixed(1) + 's' : '') + ' | $' + (r.cost ? parseFloat(r.cost).toFixed(4) : '0') + '';
                        passHtml += '
';
                        passHtml += '
' + escapeHtml(r.response) + '
';
                        passHtml += '
';
                    });

                    passHtml += '
';
                    passSection.innerHTML = passHtml;
                    daResults.appendChild(passSection);
                });

                // Add info footer
                var footer = document.createElement('div');
                footer.style.cssText = 'margin-top:15px;padding:15px;background:linear-gradient(135deg,#f0fdf4,#ecfeff);border-radius:8px;border:1px solid #86efac;';
                footer.innerHTML = 'Deep Analysis Loaded
' +
                    '' + data.total_responses + ' saved responses across ' + data.passes.length + ' passes.';
                daResults.appendChild(footer);

            } catch (err) {
                daResults.innerHTML = '
Error loading deep analysis: ' + escapeHtml(err.message) + '
';
                daProgress.textContent = 'Error';
            }
        }

        // Submit to AI
        async function submitToAI() {