#226
fix(ui): emit safe errors for failed SSE streams
What
A FastAPI route can start streaming an agent response before the upstream provider fails. In that case, to_sse() currently propagates the exception, so AI SDK UI receives a truncated response with no protocol error and no [DONE] marker.
This change:
- emits the existing
UIErrorEventfor ordinary stream failures - masks server details with
An error occurred.by default - adds an
on_errorcallback for logging or a deliberate client-facing message - closes recovered streams with
[DONE] - keeps
to_stream(), cancellation, and generator shutdown behavior unchanged
Why
The existing web_agent example pipes to_sse() directly into FastAPI StreamingResponse. Once the response has started, an in-band AI SDK UI error chunk is the only structured way to report a provider failure to useChat.
This follows the concrete AI SDK UI interoperability direction discussed in #224.
Verification
uv run --frozen pytest -q: 593 passed- Ruff format and lint passed
- mypy and ty passed
- all repository example checks passed
Suggested release label: fix.
@EfeDurmaz16 is attempting to deploy a commit to the Vercel Labs Team on Vercel.
A member of the Team first needs to authorize it.