From d3bd4c2fe6115b16d4e3d697cbe16a78c03efd6f Mon Sep 17 00:00:00 2001 From: JianFeeeee <109188060+JianFeeeee@users.noreply.github.com> Date: Fri, 14 Aug 2026 00:58:41 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20output=5Fsend=20=E6=B0=94=E6=B3=A1?= =?UTF-8?q?=E6=97=B6=E5=BA=8F(chatFinalIdx=20=E6=8F=92=E5=85=A5)=E4=B8=8E?= =?UTF-8?q?=20channel=5Foutput=20=E5=90=8E=E6=B5=81=E5=BC=8F=E4=B8=A2?= =?UTF-8?q?=E5=A4=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 8 ++++++++ cmd/gui/renderer/app.js | 13 +++++++++++-- internal/plugins/webui/dashboard.html | 23 ++++++++++++++++++++--- 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 39fd9ef..78833ea 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,11 @@ third_party/homeagent-sdk/example/ # codegraph 本地索引配置(含嵌套 SDK 仓放行,仅本地生效) codegraph.json + +# 运行时产物(不提交) +adapters/ +knowledge/ +memory/ +scripts/ +terminal_locked_log.txt + diff --git a/cmd/gui/renderer/app.js b/cmd/gui/renderer/app.js index d471b35..0d9b371 100644 --- a/cmd/gui/renderer/app.js +++ b/cmd/gui/renderer/app.js @@ -22,6 +22,7 @@ let state = { chatStick: true, pendingTools: [], eventSource: null, + chatFinalIdx: -1, lang: localStorage.getItem('ha-lang') || 'zh', connections: [], currentConn: null, @@ -828,6 +829,7 @@ async function sendChat() { var text = inp.value.trim(); if (!text || state.chatLoading) return; state.chatStick = true; + state.chatFinalIdx = -1; state.messages.push({ role: 'user', content: text }); inp.value = ''; rerenderChat(); @@ -858,6 +860,7 @@ async function sendChat() { _grow: true }); } + state.chatFinalIdx = state.messages.length - 1; rerenderChat(); } catch(e) { state.messages.push({ role: 'assistant', content: __('错误: ','Error: ') + e.message, _final: true }); @@ -1947,7 +1950,13 @@ async function connectFetchSSE(url) { if (type === 'agent_output') { state.chatStage = __('AI 回复中...','AI replying...'); if (p.kind === 'channel_output') { - state.messages.push({ role: 'assistant', content: p.content || '', source: p.channel || '', _final: true, _grow: true }); + var cm = { role: 'assistant', content: p.content || '', source: p.channel || '', _final: true, _grow: true }; + if (state.chatFinalIdx >= 0 && state.chatFinalIdx < state.messages.length) { + state.messages.splice(state.chatFinalIdx, 0, cm); + state.chatFinalIdx++; + } else { + state.messages.push(cm); + } rerenderChatIfActive(); return; } var last = state.messages.length > 0 ? state.messages[state.messages.length - 1] : null; @@ -1956,7 +1965,7 @@ async function connectFetchSSE(url) { last.content += (p.content || ''); rerenderChatIfActive(); return; } - if (last && last.role === 'assistant' && last._final) { return; } + if (last && last.role === 'assistant' && last._final && !last.source) { return; } state.messages.push({ role: 'assistant', content: p.content || '', _streaming: true, _grow: true }); rerenderChatIfActive(); } else if (type === 'reasoning') { diff --git a/internal/plugins/webui/dashboard.html b/internal/plugins/webui/dashboard.html index 7e4a7d2..4d61f85 100644 --- a/internal/plugins/webui/dashboard.html +++ b/internal/plugins/webui/dashboard.html @@ -1980,6 +1980,7 @@ chatStick: true, pendingTools: [], eventSource: null, + chatFinalIdx: -1, lang: localStorage.getItem("ha-lang") || "zh", }; @@ -3296,6 +3297,7 @@ var text = inp.value.trim(); if (!text || state.chatLoading) return; state.chatStick = true; + state.chatFinalIdx = -1; state.messages.push({ role: "user", content: text }); inp.value = ""; rerenderChat(); @@ -3348,6 +3350,7 @@ _grow: true, }); } + state.chatFinalIdx = state.messages.length - 1; rerenderChat(); } catch (e) { state.messages.push({ @@ -3739,13 +3742,22 @@ if (!p.content) return; state.chatStage = __("AI 回复中...", "AI replying..."); if (p.kind === "channel_output") { - state.messages.push({ + var cm = { role: "assistant", content: p.content, source: p.channel || "", _final: true, _grow: true, - }); + }; + if ( + state.chatFinalIdx >= 0 && + state.chatFinalIdx < state.messages.length + ) { + state.messages.splice(state.chatFinalIdx, 0, cm); + state.chatFinalIdx++; + } else { + state.messages.push(cm); + } rerenderChat(); return; } @@ -3762,7 +3774,12 @@ rerenderChat(); return; } - if (lastM2 && lastM2.role === "assistant" && lastM2._final) { + if ( + lastM2 && + lastM2.role === "assistant" && + lastM2._final && + !lastM2.source + ) { return; } state.messages.push({