From f49c5263841a121411cbdde4f06513c3dfd1cf52 Mon Sep 17 00:00:00 2001 From: Meleki Date: Mon, 2 Mar 2026 14:29:24 +0100 Subject: [PATCH] Frontend: Aufeinanderfolgende Assistant-Text-Messages gleicher Iteration mergen MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Neue Hilfsfunktion _mergeConsecutiveAssistantTexts() in history.js - Nahtloses Zusammenfügen (Whitespace-Trenner) bei gleicher Iteration - Angewandt in renderMessages(), _renderMessagesIntoFragment() und loadLatestArchive() - Behebt fragmentierte Darstellung bei Web-Search-Antworten --- wwwroot/js/history.js | 26 +++++++++++++++++++++++++- wwwroot/js/pages/dashboard.js | 2 +- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/wwwroot/js/history.js b/wwwroot/js/history.js index 7027c03..df4604d 100644 --- a/wwwroot/js/history.js +++ b/wwwroot/js/history.js @@ -117,7 +117,29 @@ function _findOldestMessageId(entries) { return 0; } +function _mergeConsecutiveAssistantTexts(msgs) { + const result = []; + for (const msg of msgs) { + if (msg.type === 'text' && msg.role === 'assistant') { + const prev = result[result.length - 1]; + if (prev && prev.type === 'text' && prev.role === 'assistant' + && prev.iteration === msg.iteration) { + // Gleiche Iteration: nahtlos zusammenfügen (Web-Search-Fragmente etc.) + prev.content = (prev.content || '') + ' ' + (msg.content || ''); + // IDs/Timestamps: letztes behalten (für Mark-Button etc.) + if (msg.id) prev.id = msg.id; + if (msg.createdAt) prev.createdAt = msg.createdAt; + if (msg.isMarked) prev.isMarked = true; + continue; + } + } + result.push(Object.assign({}, msg)); + } + return result; +} + function _renderMessagesIntoFragment(fragment, msgs) { + msgs = _mergeConsecutiveAssistantTexts(msgs); for (const msg of msgs) { const div = document.createElement('div'); switch (msg.type) { @@ -185,6 +207,7 @@ function _renderMessagesIntoFragment(fragment, msgs) { } function renderMessages(msgs, addToConversation) { + msgs = _mergeConsecutiveAssistantTexts(msgs); for (const msg of msgs) { if (msg.id > lastKnownMessageId) lastKnownMessageId = msg.id; @@ -266,7 +289,8 @@ async function loadLatestArchive() { fragment.appendChild(sep); for (const entry of data) { - for (const msg of entry.messages) { + const mergedMsgs = _mergeConsecutiveAssistantTexts(entry.messages); + for (const msg of mergedMsgs) { const div = document.createElement('div'); switch (msg.type) { case 'text': diff --git a/wwwroot/js/pages/dashboard.js b/wwwroot/js/pages/dashboard.js index 00ee322..044c29a 100644 --- a/wwwroot/js/pages/dashboard.js +++ b/wwwroot/js/pages/dashboard.js @@ -151,7 +151,7 @@ registerPage('dashboard', { if (a.useSoul) badges.push(' Seele'); if (a.useIdentity) badges.push(' Ich'); if (a.useUserInfo) badges.push(' Du'); - if (a.useMemory) badges.push(' Erinnerungen'); + if (a.useMemory) badges.push(' Erinnerungen'); if (a.webSearchVersion) { const wsYear = a.webSearchVersion.includes('2025') ? '2025' : '2026'; badges.push(` Web-Suche`);