Meta-Bar: Token-Anzeige auch bei abgebrochenem Stream; Cache-Tokens anzeigen

This commit is contained in:
Meleki committed 2026-02-28 16:49:18 +01:00
1 parent b84dff6d8c
commit 6b707d7d74
3 files changed
+25 -17

No files matched your search

+3 -3
View File
@@ -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);
}
}
+20 -5
View File
@@ -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;
+2 -9
View File
@@ -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');
}