fix: Enable real-time analytics tracking for chat messages#40
Merged
0xGingi merged 1 commit intonanogpt-community:mainfrom Jan 13, 2026
Merged
fix: Enable real-time analytics tracking for chat messages#400xGingi merged 1 commit intonanogpt-community:mainfrom
0xGingi merged 1 commit intonanogpt-community:mainfrom
Conversation
This commit fixes the broken analytics feature that was not tracking model usage statistics for chat messages in real-time. **Problem:** - Message generation was storing analytics data (tokenCount, costUsd, responseTimeMs) in individual messages, but the aggregated model_performance_stats table was never updated - Stats were only recalculated when users visited the analytics page or manually clicked "recalculate", making the feature appear broken **Solution:** - Added asynchronous analytics tracking after each message generation - Implemented incremental updates (similar to TTS/STT) to efficiently update stats without full recalculation - Updates include: totalMessages, totalCost, avgTokens, avgResponseTime **Implementation details:** - Runs asynchronously in background after message completion - Only processes when valid analytics data is available - Creates new stat entries or updates existing ones - Uses proper running average calculation for avgTokens and avgResponseTime **Related:** - TTS endpoint already implements this pattern (tts/+server.ts:120-150) - Fixes inconsistency between chat and audio analytics tracking 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This commit fixes the broken analytics feature that was not tracking model usage statistics for chat messages in real-time.
Problem
tokenCount,costUsd,responseTimeMs) in individual messages, but the aggregatedmodel_performance_statstable was never updatedSolution
totalMessages,totalCost,avgTokens,avgResponseTimeImplementation Details
avgTokensandavgResponseTimeRelated
src/routes/api/tts/+server.ts:120-150)