Persist panel member token costs to DB via usage seed

Replace the separate panel_usage SSE event + frontend accumulator with
server-side seeding of the worker's usage object. Both the done-event and
FinalizeChain read from the same usage, so panel (Fusion/MoA) member tokens
now flow into the live badge AND the DB as a single source of truth — the
badge no longer drops to the worker-only value after F5.

- RunPanel takes a TokenUsage usageSink; accumulates member costs after the
  Task.WhenAll barrier (single-threaded, no lock)
- ChatEndpoint passes panelUsage as seedUsage to all three worker paths
- StreamChat / StreamChatViaCli / OpenAI StreamChat fold seedUsage into usage
  at creation time, so every exit path persists it
- OpenAI done-events extended with cacheCreation/cacheRead fields for live
  consistency when seeded by Anthropic members
- chat.js: remove redundant _panelUsage / _addPanelUsage / panel_usage
- TODO.md: mark the live-only v1 boundary closed, note the new mechanism

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
MelekiandClaude Opus 4.8 committed 2026-06-19 08:44:36 +02:00
1 parent 1b203707ec
commit 5c89adb6df
7 files changed
+41 -46

No files matched your search

+4
View File
@@ -38,6 +38,7 @@ public partial class AnthropicService
string unityMcpToken = null,
bool useAutoContext = true,
string effort = null,
TokenUsage seedUsage = null,
CancellationToken workCt = default,
CancellationToken sseCt = default)
{
@@ -50,6 +51,9 @@ public partial class AnthropicService
var sw = System.Diagnostics.Stopwatch.StartNew();
var usage = new TokenUsage();
// Panel-Member-Tokens (Fusion/MoA) vorab in die Chain-Usage falten → erscheinen im
// done-Event (Live-Badge) UND in FinalizeChain (DB, überlebt F5). Null/leer = No-op.
if (seedUsage != null) usage.Add(seedUsage);
var fullText = new StringBuilder();
var tempImagePaths = new List<string>();
string mcpConfigPath = null;