Skip to content

bug: Implementation of the SSE Specification is incorrect (Typescript SDK) #771

@plettj

Description

@plettj

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: test

This 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 :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions