You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(ai): forward token usage on the structured-output fallback path
`fallbackStructuredOutputStream` — used by `chat({ outputSchema, stream: true })`
whenever an adapter resolves the schema through the non-streaming
`structuredOutput()` rather than a native streaming or combined path (Ollama,
plus Anthropic and Gemini models that predate combined tools+schema support) —
wrapped `structuredOutput()` but dropped the `usage` from its result. Consumers
reading `RUN_FINISHED.usage` saw `undefined`, and the engine's `runOnUsage`
middleware hook (gated on `chunk.usage`) never fired, so cost-tracking and
observability layers reported zero token counts on that path.
The synthesized `RUN_FINISHED` now carries the adapter-reported `usage`,
matching the native streaming path. Adapters that don't report usage are
unaffected — the conditional spread omits the key entirely.
Adds unit coverage in chat-structured-output-stream.test.ts (usage forwarded;
omitted when absent) and an e2e regression (anthropic-structured-usage) that
drives the Anthropic adapter through the fallback against an aimock mount and
asserts usage reaches RUN_FINISHED.usage.
0 commit comments