/* Analyze 页逻辑: SSE 流式分析 (共用 components/sse-client.js). * 与 ai-panel.js 共用 createAnalysisStream, 只负责本页 DOM/Tab 交互. */ import { createAnalysisStream } from "../components/sse-client.js"; import { escapeHtml } from "../utils.js"; export function initAnalyzePage() { let currentStream = null; const scopeSelect = document.getElementById("scopeSelect"); const questionInput = document.getElementById("questionInput"); const startBtn = document.getElementById("startBtn"); const presetBtns = document.querySelectorAll(".preset-btn"); const observationContent = document.getElementById("observationContent"); const promptContent = document.getElementById("promptContent"); const reasoningContent = document.getElementById("reasoningContent"); const conclusionContent = document.getElementById("conclusionContent"); // Programmatic tab switching (Bootstrap tabs) function switchTab(name) { const btn = document.getElementById(name + "-tab"); if (btn) btn.click(); } function startAnalysis(question, preset) { if (currentStream) { currentStream.close(); currentStream = null; } // Reset content observationContent.innerHTML = '
${escapeHtml(content)}`;
}
},
onToken(text, section) {
const pane = section === "conclusion" ? conclusionContent : reasoningContent;
if (pane.querySelector(".text-muted")) pane.innerHTML = "";
pane.innerHTML += escapeHtml(text);
pane.scrollTop = pane.scrollHeight;
},
onSectionStart(section) {
if (section === "reasoning") {
reasoningContent.innerHTML = "";
switchTab("reasoning");
} else {
conclusionContent.innerHTML = "";
switchTab("conclusion");
}
},
onError(msg) {
observationContent.innerHTML = `