-
Notifications
You must be signed in to change notification settings - Fork 942
Description
The Typescript SDK, specifically the @ag-ui/client package, currently ignores any event text that doesn't start with data: , while the SSE spec says it should be checking only for data:, ignoring the space.
Problem
AG-UI's Implementation: The Typescript SDK's HttpAgent uses processSSEEvent which scans for data: (with a space) here, ignoring any blocks like data:{} without the space:
if (line.startsWith("data: ")) {
// Extract data content (remove 'data: ' prefix)
dataLines.push(line.slice(6));
}SSE Specification: The official SSE spec from WHATWG states that the space after the colon should always be ignored. From the docs:
The following stream fires two identical events:
data:test data: testThis is because the space after the colon is ignored if present.
Solution
Implement the official SSE specification by not requiring a space after the colon, and ignoring exactly one space if it does exist.
Concerns
My only concern with implementing the spec more precisely is backward compatibility.
There's one failure case: if an application's backend happens to send both data: and data: in their streams, and the frontend that uses @ag-ui/client relies on not receiving the data: events.
If you're curious why this bug is important, well, my team is using Gin on our backend which uses manucorporat/sse for SSE... which doesn't add a space after its colons. That's an 85K+ starred project which relies on an implementation that was last edited 10 years ago. Truly the pinnacle of software engineering :)