Add model response lifecycle events for UI streams

Closed
YU
10d ago
+1319-53

Summary

  • add ModelResponseStartEvent and ModelResponseEndEvent to 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-usage chunks in the Vercel AI adapter for AI SDK v6 when a response has non-empty RequestUsage
  • document the new data-usage behavior 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_handler
  • uv run pytest tests/test_vercel_ai.py -k 'data_usage or usage_chunk'
  • uv run pytest tests/test_vercel_ai.py
  • uv 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.