UI: Make thinking blocks closed by default

This commit is contained in:
oobabooga 2025-04-30 15:12:46 -07:00
parent cd5c32dc19
commit 195a45c6e1
2 changed files with 13 additions and 11 deletions

View file

@ -31,13 +31,13 @@ function removeLastClick() {
}
function handleMorphdomUpdate(text) {
// Track closed blocks
const closedBlocks = new Set();
// 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 not open, add to closed set
if (blockId && !block.hasAttribute("open")) {
closedBlocks.add(blockId);
// If block exists and is open, add to open set
if (blockId && block.hasAttribute("open")) {
openBlocks.add(blockId);
}
});
@ -72,13 +72,15 @@ function handleMorphdomUpdate(text) {
}
}
// For thinking blocks, respect closed state
// For thinking blocks, assume closed by default
if (fromEl.classList && fromEl.classList.contains("thinking-block") &&
toEl.classList && toEl.classList.contains("thinking-block")) {
toEl.classList && toEl.classList.contains("thinking-block")) {
const blockId = toEl.getAttribute("data-block-id");
// If this block was closed by user, keep it closed
if (blockId && closedBlocks.has(blockId)) {
toEl.removeAttribute("open");
// Remove open attribute by default
toEl.removeAttribute("open");
// If this block was explicitly opened by user, keep it open
if (blockId && openBlocks.has(blockId)) {
toEl.setAttribute("open", "");
}
}

View file

@ -167,7 +167,7 @@ def convert_to_markdown(string, message_id=None):
title_text = "Thinking..." if is_streaming else "Thought"
thinking_block = f'''
<details class="thinking-block" data-block-id="{block_id}" data-streaming="{str(is_streaming).lower()}" open>
<details class="thinking-block" data-block-id="{block_id}" data-streaming="{str(is_streaming).lower()}">
<summary class="thinking-header">
<svg class="thinking-icon" width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M8 1.33334C4.31868 1.33334 1.33334 4.31868 1.33334 8.00001C1.33334 11.6813 4.31868 14.6667 8 14.6667C11.6813 14.6667 14.6667 11.6813 14.6667 8.00001C14.6667 4.31868 11.6813 1.33334 8 1.33334Z" stroke="currentColor" stroke-width="1.33" stroke-linecap="round" stroke-linejoin="round"/>