Skip to content

feat: typed SSE client primitive (port from Teller, .ts) #22

@constk

Description

@constk

Problem

Streaming-LLM apps need an SSE client. Hand-written SSE parsing is a known footgun (RFC 6455-style event:/data:/blank-line state machine). Shipping a tested, typed primitive saves users that footgun.

Proposed solution

Port frontend/src/lib/api/client.js from Teller into frontend/src/lib/api/client.ts. Type the event shapes with discriminated unions. Keep the parser pure (no DOM dependency). Add a vitest unit test for the parser using a fake ReadableStream.

Acceptance criteria

  • client.ts exports a typed consumeSSE function returning an AsyncIterable of typed events.
  • Vitest unit test covers: event:/data: parsing, multi-line data:, blank-line dispatch, partial-chunk reassembly.
  • Strict TS passes; eslint zero warnings.

Priority rationale

High: this is one of the most copy-pasted-incorrectly primitives in LLM-frontend code. Shipping it correctly is a portfolio differentiator.

Depends on

#21

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestfrontendReact + Vite frontend scaffold

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions