Fix/react headless OpenAI sse decoder#338
Open
boffin-dmytro wants to merge 2 commits intothesysdev:mainfrom
Open
Fix/react headless OpenAI sse decoder#338boffin-dmytro wants to merge 2 commits intothesysdev:mainfrom
boffin-dmytro wants to merge 2 commits intothesysdev:mainfrom
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.
What’s in this PR
This PR makes OpenAI streaming in
@openuidev/react-headlessmore reliable by introducing a small internal SSE decoder and using it in the OpenAI SSE adapters.Previously, the OpenAI adapters parsed streams by splitting each decoded network chunk on
\nand treating eachdata:line as complete JSON. In real-world streaming, chunk boundaries are arbitrary (JSON can be split mid-token), and SSE events are framed by blank lines and can include multi-linedata:fields.Changes
decodeSSE) that:\r\n)data:(joined with\nper SSE spec)openAIAdapter()(Chat Completions SSE)openAIResponsesAdapter()(Responses API SSE)to consume the shared decoder instead of doing ad-hoc line splitting.
Why it matters
This hardens streaming behavior under normal network conditions and reduces duplicated parsing logic across adapters—making streaming output less flaky and easier to maintain.
Scope note
agUIAdapter()is intentionally unchanged in this PR (it already has robust SSE framing); this change focuses on bringing the OpenAI SSE adapters up to the same standard.How to test
corepack pnpm --filter @openuidev/react-headless test