Add model response lifecycle events for UI streams
Closed
YU
10d ago+1319+1319+0123456789012345678901234567890123456789-53-53-01234567890123456789
- Closes #3651
Summary
- add
ModelResponseStartEventandModelResponseEndEventto streamed UI and event-handler flows - expose
AgentStream.iter_events()so lifecycle events wrap streamed responses without changing raw response iteration APIs - emit transient
data-usagechunks in the Vercel AI adapter for AI SDK v6 when a response has non-emptyRequestUsage - document the new
data-usagebehavior and add focused regression coverage for the Vercel AI stream
Why
The streaming pipeline only exposed part-level events. That meant UI adapters had no response boundary to attach per-request usage updates to, so multi-step runs could only surface aggregated usage after the full run completed.
Validation
uv run ruff check ...uv run pyright ...uv run pytest tests/test_streaming.py -k event_stream_handleruv run pytest tests/test_vercel_ai.py -k 'data_usage or usage_chunk'uv run pytest tests/test_vercel_ai.pyuv run pytest tests/test_ui.py -k 'transform_stream or run_stream_text_and_thinking'
Checklist
- Any AI generated code has been reviewed line-by-line by the human PR author, who stands by it.
- No breaking changes in accordance with the version policy.
- PR title is fit for the release changelog.