function copyToClipboard(element) { if (!element) return; const messageElement = element.closest(".message, .user-message, .assistant-message"); if (!messageElement) return; const rawText = messageElement.getAttribute("data-raw"); if (!rawText) return; navigator.clipboard.writeText(rawText).then(function() { const originalSvg = element.innerHTML; element.innerHTML = ""; setTimeout(() => { element.innerHTML = originalSvg; }, 1000); }).catch(function(err) { console.error("Failed to copy text: ", err); }); } function branchHere(element) { if (!element) return; const messageElement = element.closest(".message, .user-message, .assistant-message"); if (!messageElement) return; const index = messageElement.getAttribute("data-index"); if (!index) return; const branchIndexInput = document.getElementById("Branch-index").querySelector("input"); if (!branchIndexInput) { console.error("Element with ID 'Branch-index' not found."); return; } const branchButton = document.getElementById("Branch"); if (!branchButton) { console.error("Required element 'Branch' not found."); return; } branchIndexInput.value = index; // Trigger any 'change' or 'input' events Gradio might be listening for const event = new Event("input", { bubbles: true }); // 'change' might also work branchIndexInput.dispatchEvent(event); branchButton.click(); // Gradio will now pick up the 'index' } function regenerateClick() { document.getElementById("Regenerate").click(); } function continueClick() { document.getElementById("Continue").click(); } function removeLastClick() { document.getElementById("Remove-last").click(); } // === Version navigation handled in main.js === // function handleMorphdomUpdate(text) { // Track open blocks const openBlocks = new Set(); document.querySelectorAll(".thinking-block").forEach(block => { const blockId = block.getAttribute("data-block-id"); // If block exists and is open, add to open set if (blockId && block.hasAttribute("open")) { openBlocks.add(blockId); } }); // Store scroll positions for any open blocks const scrollPositions = {}; document.querySelectorAll(".thinking-block[open]").forEach(block => { const content = block.querySelector(".thinking-content"); const blockId = block.getAttribute("data-block-id"); if (content && blockId) { const isAtBottom = Math.abs((content.scrollHeight - content.scrollTop) - content.clientHeight) < 5; scrollPositions[blockId] = { position: content.scrollTop, isAtBottom: isAtBottom }; } }); morphdom( document.getElementById("chat").parentNode, "