Add Client.EventStream for reconnecting SSE through the pipeline#18
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
Client.EventStream(ctx, req, opts...), a one-call reconnecting Server-Sent Events stream that runs through the client pipeline. Previously a caller had to write their ownsse.ConnectFunc; now the common case — "stream this endpoint through my configured client" — is a single method that returns the sameiter.Seq2[sse.Event, error]shape as the rest of the streaming APIs.Each connection clones the request, sets
Accept: text/event-stream(unless the caller set their own), replays theLast-Event-IDheader after a mid-stream interruption, and sends it throughDo— so auth, logging, tracing, and retry all run per connection. A non-2xx response or a transport failure on connect ends the stream with that error; a mid-stream interruption reconnects transparently. Requests with a body must be replayable (SSE is normally a bodyless GET).Also adds the
header.LastEventIDconstant.Test plan
Last-Event-IDis replayed with the most recent event id on each reconnectAccept: text/event-streamis set on every connectiongofmt -l .clean,go vet ./...clean,go test -race ./...green across all packages🤖 Generated with Claude Code