Skip to content

fix: explicitly merge usage fields in Accumulate using JSON presence checks#6

Draft
ibetitsmike wants to merge 5 commits intocoder_2_33from
mike/fix-usage-accumulator-2.33
Draft

fix: explicitly merge usage fields in Accumulate using JSON presence checks#6
ibetitsmike wants to merge 5 commits intocoder_2_33from
mike/fix-usage-accumulator-2.33

Conversation

@ibetitsmike
Copy link
Copy Markdown

This PR was authored by Mux on behalf of Mike.

Cherry-pick of mike/fix-usage-accumulator onto coder_2_33.

When a MessageDeltaEvent arrives during streaming, Accumulate() previously only assigned OutputTokens. For non-server-tool conversations, Anthropic's message_delta only includes output_tokens in the JSON, omitting input_tokens and cache fields.

This uses Raw() != respjson.Omitted to check actual JSON field presence before updating each usage field. Omitted fields preserve their values from the initial message_start event.

The examples go.mod was using github.com/anthropics/anthropic-sdk-go
in its replace directive and require block, but the root module and all
example Go files use github.com/charmbracelet/anthropic-sdk-go. This
mismatch caused build failures.
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.

3 participants