From e7a81f00e7b30655fba02697be609845ec0d9624 Mon Sep 17 00:00:00 2001 From: JOJO <1498581755@qq.com> Date: Tue, 18 Nov 2025 22:19:15 +0800 Subject: [PATCH] feat: auto-scroll and collapse thinking blocks --- static/app.js | 22 ++++++++++++++++------ sub_agent/static/app.js | 10 ++++++++++ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/static/app.js b/static/app.js index fc6ada6..0265e74 100644 --- a/static/app.js +++ b/static/app.js @@ -684,6 +684,9 @@ async function bootstrapApp() { if (status.conversation && status.conversation.current_id) { this.currentConversationId = status.conversation.current_id; } + if (typeof status.thinking_mode !== 'undefined') { + this.thinkingMode = !!status.thinking_mode; + } }); // AI消息开始 @@ -723,7 +726,12 @@ async function bootstrapApp() { msg.actions.push(action); const blockId = `${this.currentMessageIndex}-thinking-${msg.actions.length - 1}`; + action.blockId = blockId; this.expandedBlocks.add(blockId); + // 开始思考时自动锁定滚动到底部 + this.autoScrollEnabled = true; + this.userScrolling = false; + this.scrollToBottom(); this.$forceUpdate(); } }); @@ -752,6 +760,12 @@ async function bootstrapApp() { if (lastAction && lastAction.type === 'thinking') { lastAction.streaming = false; lastAction.content = data.full_content; + if (lastAction.blockId) { + setTimeout(() => { + this.expandedBlocks.delete(lastAction.blockId); + this.$forceUpdate(); + }, 1000); + } } msg.streamingThinking = ''; msg.currentStreamingType = null; @@ -1990,12 +2004,8 @@ async function bootstrapApp() { body: JSON.stringify({ thinking_mode: !this.thinkingMode }) }); const data = await resp.json(); - if (data.success && data.data) { - if (typeof data.data === 'object') { - this.thinkingMode = !!data.data.enabled; - } else { - this.thinkingMode = data.data === '思考模式'; - } + if (data.success) { + this.thinkingMode = !!data.data; } else { throw new Error(data.message || data.error || '切换失败'); } diff --git a/sub_agent/static/app.js b/sub_agent/static/app.js index f3d48ad..8540927 100644 --- a/sub_agent/static/app.js +++ b/sub_agent/static/app.js @@ -1084,7 +1084,11 @@ async function bootstrapApp() { msg.actions.push(action); const blockId = `${this.currentMessageIndex}-thinking-${msg.actions.length - 1}`; + action.blockId = blockId; this.expandedBlocks.add(blockId); + this.autoScrollEnabled = true; + this.userScrolling = false; + this.scrollToBottom(); this.$forceUpdate(); } }); @@ -1113,6 +1117,12 @@ async function bootstrapApp() { if (lastAction && lastAction.type === 'thinking') { lastAction.streaming = false; lastAction.content = data.full_content; + if (lastAction.blockId) { + setTimeout(() => { + this.expandedBlocks.delete(lastAction.blockId); + this.$forceUpdate(); + }, 1000); + } } msg.streamingThinking = ''; msg.currentStreamingType = null;