Skip to content

Conversation

@ethanndickson
Copy link
Member

@ethanndickson ethanndickson commented Nov 26, 2025

Emit usage-delta events on AI SDK finish-step, allowing the UI to display live token counts as the AI generates multi-step responses.

demo.mp4

Changes

Backend:

  • Add UsageDeltaEvent type emitted on each finish-step
  • StreamManager emits usage after each tool call step completes
  • Forward events through AIServiceAgentSession → IPC

Frontend:

  • StreamingMessageAggregator stores active stream usage per messageId
  • WorkspaceStore exposes liveUsage in WorkspaceUsageState
  • CostsTab, RightSidebar, ChatMetaSidebar consume liveUsage for real-time context window display

Tests:

  • Unit tests for usage-delta handling in StreamingMessageAggregator
  • Integration test for usage-delta events during multi-step streams

Testing

This feature has been tested with OpenAI, Anthropic & Google.


Generated with mux

Copy link
Member

@ThomasK33 ThomasK33 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems good

Emit usage-delta events on AI SDK finish-step, allowing the UI to
display live token counts as the AI generates multi-step responses.

Backend:
- Add UsageDeltaEvent type emitted on each finish-step
- StreamManager tracks and emits usage after each tool call step
- Forward events through AIService → AgentSession → IPC

Frontend:
- StreamingMessageAggregator stores active stream usage per messageId
- WorkspaceStore exposes liveUsage in WorkspaceUsageState
- CostsTab, RightSidebar, ChatMetaSidebar consume liveUsage for
  real-time context window display

Tests:
- Unit tests for usage-delta handling in StreamingMessageAggregator
- Integration test for usage-delta events during multi-step streams
@ethanndickson ethanndickson force-pushed the mid-stream-token-usage-investigation branch from 7dd36de to 73b0a22 Compare November 26, 2025 23:23
@ethanndickson ethanndickson added this pull request to the merge queue Nov 27, 2025
Merged via the queue into main with commit 80cecf2 Nov 27, 2025
12 of 13 checks passed
@ethanndickson ethanndickson deleted the mid-stream-token-usage-investigation branch November 27, 2025 01:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants