From 15b45c7653893cbeeacd721a94f65e1198ad3947 Mon Sep 17 00:00:00 2001 From: JianFeeeee <109188060+JianFeeeee@users.noreply.github.com> Date: Sat, 15 Aug 2026 09:03:07 +0800 Subject: [PATCH] =?UTF-8?q?gui:=20renderChat=20=E5=A2=9E=E5=8A=A0=E9=98=B2?= =?UTF-8?q?=E6=8A=A4=E4=B8=8E=E6=97=A5=E5=BF=97;=20log:r=20=E6=94=B9=20inv?= =?UTF-8?q?oke;=20=E4=BF=AE=20SSE=20=E6=B5=81=E5=BC=8F=E4=B8=A2=E5=A4=B1?= =?UTF-8?q?=E6=B0=94=E6=B3=A1;=20chat=20=E5=B8=83=E5=B1=80=20overflow=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/gui/main.js | 1 + cmd/gui/preload.js | 4 ++-- cmd/gui/renderer/app.js | 17 ++++++++++++++--- cmd/gui/renderer/style.css | 6 +++--- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/cmd/gui/main.js b/cmd/gui/main.js index abcb3fc..19ea320 100644 --- a/cmd/gui/main.js +++ b/cmd/gui/main.js @@ -364,6 +364,7 @@ function doWebuiLogin(baseUrl, username, password, extraCookie) { } ipcMain.on('log:r', (_e, m) => { log('[r] ' + m); }); +ipcMain.handle('log:r', (_e, m) => { log('[r] ' + m); return true; }); ipcMain.handle('webui:setAuth', async (_, { url, cookie, headers, username, password }) => { const resp = { ok: true, error: '' }; diff --git a/cmd/gui/preload.js b/cmd/gui/preload.js index 73350f6..2262e1b 100644 --- a/cmd/gui/preload.js +++ b/cmd/gui/preload.js @@ -20,7 +20,7 @@ contextBridge.exposeInMainWorld('homeagent', { setAuth: (url, cookie, headers, username, password) => ipcRenderer.invoke('webui:setAuth', { url, cookie, headers, username, password }), openLogin: (url, username, password) => ipcRenderer.invoke('webui:openLogin', { url, username, password }), onLoginResult: (cb) => ipcRenderer.on('webui:login-result', (_e, d) => cb(d)), - cacheBg: (src) => ipcRenderer.invoke('bg:cache', { src }), - log: (m) => ipcRenderer.send('log:r', m), }, + cacheBg: (src) => ipcRenderer.invoke('bg:cache', { src }), + log: (m) => ipcRenderer.invoke('log:r', m), }); diff --git a/cmd/gui/renderer/app.js b/cmd/gui/renderer/app.js index 6ece334..bf14d1b 100644 --- a/cmd/gui/renderer/app.js +++ b/cmd/gui/renderer/app.js @@ -664,6 +664,18 @@ function renderChat() { msgsEl.innerHTML = html; if (state.chatStick !== false) { try { msgsEl.scrollTo({ top: msgsEl.scrollHeight, behavior: 'smooth' }) } catch(e) { msgsEl.scrollTop = msgsEl.scrollHeight } } updateChatBadge(); + if (window.homeagent && window.homeagent.log) { + window.homeagent.log('render: msgs=' + msgs.length + ' sig=' + sig.slice(0, 60) + + ' last=' + (lastM ? lastM.role + '/C=' + String(lastM.content || '').length + '/T=' + ((lastM.tool_calls || []).length) : 'none') + + ' roles=' + msgs.map(function(m){ return m.role + (m.content ? '#' + String(m.content).length : '') + (m.source ? '@' + m.source : '') + (m.tool_calls && m.tool_calls.length ? 'T' + m.tool_calls.length : '') }).join(',')); + } +} + +function guardedRenderChat() { + try { renderChat() } catch (e) { + if (window.homeagent && window.homeagent.log) window.homeagent.log('renderChat ERROR: ' + e.message + ' stack=' + (e.stack || '').split('\n').slice(0, 2).join(';')); + console.error('renderChat error', e); + } } function updateChatBadge() { @@ -673,7 +685,7 @@ function updateChatBadge() { badge.style.display = 'none'; } -function rerenderChat() { renderChat(); renderChatStarmap(); renderTerminals(); renderCmdHistory() } +function rerenderChat() { guardedRenderChat(); renderChatStarmap(); renderTerminals(); renderCmdHistory() } function toggleToolCall(el) { var d = el.querySelector('.tc-detail'); @@ -1104,7 +1116,7 @@ function switchChatPanel(tab, el) { } async function loadChatHistory() { - try { var data = await api('/chat/history'); if (data && data.messages) state.messages = data.messages } catch(e) {} + try { var data = await api('/chat/history'); if (data && data.messages) { state.messages = data.messages; if (window.homeagent && window.homeagent.log) window.homeagent.log('history: loaded ' + data.messages.length); } else if (window.homeagent && window.homeagent.log) { window.homeagent.log('history: no messages field'); } } catch(e) { if (window.homeagent && window.homeagent.log) window.homeagent.log('history: error ' + e.message) } } async function loadTerminals() { @@ -2311,7 +2323,6 @@ async function connectFetchSSE(url) { last.content += (p.content || ''); rerenderChatIfActive(); 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/cmd/gui/renderer/style.css b/cmd/gui/renderer/style.css index 7d57a69..dc43e97 100644 --- a/cmd/gui/renderer/style.css +++ b/cmd/gui/renderer/style.css @@ -497,15 +497,15 @@ code { font-family: var(--font-mono); font-size: 12px; color: var(--pre-color) } .empty-state p { font-size: 14px; margin-bottom: 8px } /* ===== Chat (对话主页) ===== */ -.chat-layout { display: flex; flex-direction: column; gap: 12px; height: 100%; min-height: 60vh } +.chat-layout { display: flex; flex-direction: column; gap: 12px; height: 100%; min-height: 0 } .chat-tabs { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 1px solid var(--border-color); padding-bottom: 10px } .chat-tabs span { padding: 6px 14px; font-size: 13px; cursor: pointer; color: var(--text-muted); border-radius: var(--radius-pill); border: 1px solid transparent; transition: all .15s } .chat-tabs span:hover { color: var(--text-primary); background: var(--bg-hover) } .chat-tabs span.active { color: var(--accent); background: var(--accent-bg); border-color: color-mix(in srgb, var(--accent) 35%, transparent) } -.chat-panel { display: none; flex: 1; min-height: 0; flex-direction: column } +.chat-panel { display: none; flex: 1; min-height: 0; flex-direction: column; overflow: hidden } .chat-panel.active { display: flex } .chat-main { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column } -.chat-main .card { flex: 1; display: flex; flex-direction: column; margin-bottom: 0; min-height: 0; background: transparent; border: none; box-shadow: none; backdrop-filter: none; padding: 0 } +.chat-main .card { flex: 1; display: flex; flex-direction: column; margin-bottom: 0; min-height: 0; background: transparent; border: none; box-shadow: none; backdrop-filter: none; padding: 0; overflow: hidden } .chat-main .card h2 { flex-shrink: 0 } .chat-messages { flex: 1; overflow-y: auto; padding: 18px 18px 26px; margin-bottom: 0; display: flex; flex-direction: column; gap: 6px; min-height: 0 } .msg { display: flex; gap: 8px; margin-bottom: 2px; align-items: flex-start; max-width: 100% }