release: per-message cost/usage metadata + ai SDK upgrade (#592)
Merged
SW
5mo ago+648+648+012345678901234567890123456789-177-177-012345678901234567890123456789
Summary
- Adds
messageMetadatacallback torunAgentStepโ emitsmessage-metadatachunks per assistantfinish-stepwith{modelId, lastStepUsage, totalMessageUsage, lastStepCost, totalMessageCost, stepFinishReasons} - Wire format byte-compatible with
sandbox.recoupable.com's existing UI consumption (verified via Chrome DevTools MCP capture against open-agents production) - Upgrades
ai@6.0.0-beta.122โ^6.0.190(+@ai-sdk/anthropic/gateway/google/openai/mcpto latest stable) so api'sLanguageModelUsagematches open-agents' flat shape natively - SRP cleanups:
addTokenCounts,hasGatewayShape,GatewayProviderMetadata,AgentStepFinishMetadataeach in their own file - Deletes
normalizeUsage(-82 LOC) โ no longer needed after SDK upgrade
Test plan
- 29 new unit tests across 7 helper files
- Full suite 3106/3106 pass
- E2E on preview verified: 2
message-metadatachunks emitted, totals accumulate correctly across steps, cost extraction from gateway providerMetadata works ($0.006191 + $0.010118 = $0.016309) - Cross-validated wire format against open-agents production โ byte-for-byte compatible
๐ค Generated with Claude Code
Summary by cubic
Adds per-message cost and token-usage metadata to assistant turns and upgrades the ai SDK so usage data matches the open-agents wire format used by sandbox.recoupable.com.
-
New Features
- Emit
message-metadatachunks fromrunAgentStepon eachfinish-stepvia amessageMetadatacallback with{ modelId, lastStepUsage, totalMessageUsage, lastStepCost, totalMessageCost, stepFinishReasons }. - Accumulates totals across steps and parses step cost from Vercel AI Gateway
providerMetadata. - Extracted focused helpers (
addLanguageModelUsage,addTokenCounts,extractGatewayCost,hasGatewayShape) and types; deletednormalizeUsage. - Updated
runAgentStepandsetupChatRequesttoawaitconvertToModelMessages.
- Emit
-
Dependencies
- Upgraded
aito6.0.190and@ai-sdk/anthropic,@ai-sdk/gateway,@ai-sdk/google,@ai-sdk/openai,@ai-sdk/mcpto latest stable, adopting the flatLanguageModelUsageshape for byte-compatible UI payloads.
- Upgraded