refactor: Token-Tracking mit source=monitor fuer Split-Anzeige

token_usage_monthly hat jetzt UNIQUE(org_id, year_month, source).
Monitor schreibt mit source=monitor, Globe mit source=globe.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Dieser Commit ist enthalten in:
Claude Dev
2026-03-26 20:44:12 +01:00
Ursprung 254a518dd8
Commit 912257ceef

Datei anzeigen

@@ -1321,10 +1321,10 @@ class AgentOrchestrator:
year_month = datetime.now(TIMEZONE).strftime('%Y-%m') year_month = datetime.now(TIMEZONE).strftime('%Y-%m')
await db.execute(""" await db.execute("""
INSERT INTO token_usage_monthly INSERT INTO token_usage_monthly
(organization_id, year_month, input_tokens, output_tokens, (organization_id, year_month, source, input_tokens, output_tokens,
cache_creation_tokens, cache_read_tokens, total_cost_usd, api_calls, refresh_count) cache_creation_tokens, cache_read_tokens, total_cost_usd, api_calls, refresh_count)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, 1) VALUES (?, ?, 'monitor', ?, ?, ?, ?, ?, ?, 1)
ON CONFLICT(organization_id, year_month) DO UPDATE SET ON CONFLICT(organization_id, year_month, source) DO UPDATE SET
input_tokens = input_tokens + excluded.input_tokens, input_tokens = input_tokens + excluded.input_tokens,
output_tokens = output_tokens + excluded.output_tokens, output_tokens = output_tokens + excluded.output_tokens,
cache_creation_tokens = cache_creation_tokens + excluded.cache_creation_tokens, cache_creation_tokens = cache_creation_tokens + excluded.cache_creation_tokens,