diff --git a/Services/AnthropicService.cs b/Services/AnthropicService.cs index 2203001..0d39db0 100644 --- a/Services/AnthropicService.cs +++ b/Services/AnthropicService.cs @@ -90,7 +90,7 @@ public class AnthropicService }); await TryWriteSse(response, "error", new { error = errMsg }, cancellationToken); await FinalizeChain(chain, usage, iterations, "error", sw); - await TryWriteSse(response, "done", new { }, cancellationToken); + await TryWriteSse(response, "done", new { chainId = chain.ChainId }, cancellationToken); return; } @@ -186,7 +186,7 @@ public class AnthropicService await FinalizeChain(chain, usage, iterations, "max_iterations", sw); await TryWriteSse(response, "error", new { error = "Max iterations erreicht" }, cancellationToken); - await TryWriteSse(response, "done", new { }, cancellationToken); + await TryWriteSse(response, "done", new { chainId = chain.ChainId }, cancellationToken); } catch (OperationCanceledException) { @@ -205,7 +205,7 @@ public class AnthropicService }); await FinalizeChain(chain, usage, iterations, "error", sw); await TryWriteSse(response, "error", new { error = errMsg }, cancellationToken); - await TryWriteSse(response, "done", new { }, cancellationToken); + await TryWriteSse(response, "done", new { chainId = chain.ChainId }, cancellationToken); } } diff --git a/wwwroot/js/chat.js b/wwwroot/js/chat.js index 1d5e81d..b0f0486 100644 --- a/wwwroot/js/chat.js +++ b/wwwroot/js/chat.js @@ -1,3 +1,15 @@ +// ── Helpers ── + +function buildMetaString(d) { + let meta = `Model: ${d.model || '?'} | In: ${d.inputTokens || 0} | Out: ${d.outputTokens || 0}`; + if (d.cacheCreationTokens > 0) meta += ` | Cache-Write: ${d.cacheCreationTokens}`; + if (d.cacheReadTokens > 0) meta += ` | Cache-Read: ${d.cacheReadTokens}`; + if ((d.iterations || 0) > 1) meta += ` | Iterations: ${d.iterations}`; + if (d.durationMs) meta += ` | ${(d.durationMs / 1000).toFixed(1)}s`; + if (d.stopReason && d.stopReason !== 'end_turn' && d.stopReason !== 'tool_use') meta += ` | Stop: ${d.stopReason}`; + return meta; +} + // ── Chat State ── const messages = []; @@ -135,11 +147,14 @@ async function sendMessage() { if (data.stopReason === 'max_tokens') { addWarningBubble('⚠️ Antwort wurde abgeschnitten (max_tokens erreicht). Bitte frage nach dem Rest.', true); } - let meta = `Model: ${data.model || '?'} | In: ${data.inputTokens || 0} | Out: ${data.outputTokens || 0}`; - if (data.iterations > 1) meta += ` | Iterations: ${data.iterations}`; - if (data.durationMs) meta += ` | ${(data.durationMs / 1000).toFixed(1)}s`; - if (data.stopReason && data.stopReason !== 'end_turn' && data.stopReason !== 'tool_use') meta += ` | Stop: ${data.stopReason}`; - setMeta(meta); + if (data.model) { + setMeta(buildMetaString(data)); + } else if (data.chainId) { + // Leeres done (z.B. nach error/max_iterations) – Chain-Daten nachladen + apiGetChain(data.chainId).then(chain => { + if (chain) setMeta(buildMetaString(chain)); + }).catch(() => {}); + } break; } eventType = null; diff --git a/wwwroot/js/pages/chat-page.js b/wwwroot/js/pages/chat-page.js index c25a878..6236640 100644 --- a/wwwroot/js/pages/chat-page.js +++ b/wwwroot/js/pages/chat-page.js @@ -25,15 +25,8 @@ function startStreamingPoll(sessionId, sendBtn, chainId) { const cid = _recoveryChainId || status.chainId; if (cid) { const chain = await apiGetChain(cid); - if (chain) { - let meta = `Model: ${chain.model || '?'} | In: ${chain.inputTokens || 0} | Out: ${chain.outputTokens || 0}`; - if (chain.iterations > 1) meta += ` | Iterations: ${chain.iterations}`; - if (chain.durationMs) meta += ` | ${(chain.durationMs / 1000).toFixed(1)}s`; - if (chain.stopReason && chain.stopReason !== 'end_turn' && chain.stopReason !== 'tool_use') meta += ` | Stop: ${chain.stopReason}`; - setMeta(meta); - } else { - setMeta('Bereit'); - } + if (chain) setMeta(buildMetaString(chain)); + else setMeta('Bereit'); } else { setMeta('Bereit'); }