diff --git a/wwwroot/js/chat.js b/wwwroot/js/chat.js index 485f418..ac5ce52 100644 --- a/wwwroot/js/chat.js +++ b/wwwroot/js/chat.js @@ -30,6 +30,7 @@ const messages = []; let isStreaming = false; let pendingFiles = []; // [{ name, type, base64 }] let pendingRefs = []; // [{ path, from, to }] - Workspace-Dateireferenzen +let _lastDoneChainData = null; // Chain-Daten vom letzten done-Event async function clearChat() { const archive = await apiArchive(getCurrentSessionId()); @@ -161,12 +162,16 @@ async function sendMessage() { if (data.stopReason === 'max_tokens') { addWarningBubble('⚠️ Antwort wurde abgeschnitten (max_tokens erreicht). Bitte frage nach dem Rest.', true); } + // Chain-Meta als streamed markieren (wird im finally ersetzt) + _lastDoneChainData = null; if (data.model) { - addChainMetaBubble(data, false); + _lastDoneChainData = data; + addChainMetaBubble(data, true); } else if (data.chainId) { - apiGetChain(data.chainId).then(chain => { - if (chain) addChainMetaBubble(chain, false); - }).catch(() => {}); + try { + const chain = await apiGetChain(data.chainId); + if (chain) { _lastDoneChainData = chain; addChainMetaBubble(chain, true); } + } catch (_) {} } setMeta('Bereit'); break; @@ -196,9 +201,13 @@ async function sendMessage() { } endStreamBubble(); - // Erst neue aus DB laden, dann gestreamte Elemente ersetzen - await pollHistory(); + // Gestreamte Elemente entfernen, dann aus DB laden, dann Chain-Meta anhängen removeStreamedElements(); + await pollHistory(); + if (_lastDoneChainData) { + addChainMetaBubble(_lastDoneChainData, false); + _lastDoneChainData = null; + } } } diff --git a/wwwroot/js/history.js b/wwwroot/js/history.js index d8f7c3e..bd5c3b0 100644 --- a/wwwroot/js/history.js +++ b/wwwroot/js/history.js @@ -21,6 +21,7 @@ async function loadHistory() { } scrollDown(); + setMeta('Bereit'); startHistoryPolling(); } catch (e) { console.error('History laden fehlgeschlagen:', e);