Skip to main content

Core Responsibilities

Frontend stream handling must:
  • parse SSE frames robustly
  • apply events in order
  • prevent stale stream writes
  • preserve assistant message integrity

Event Application Model

  • meta: captures conversation context for the active stream
  • status: shows lightweight progress text
  • clear: resets provisional text
  • token: appends generated text
  • done: attaches sources/metadata and closes lifecycle
  • error: renders terminal failure text
For new conversations, route transition to /chat/:conversation_id should happen on terminal state (done or error), not on early meta. This prevents unmounting the active stream before assistant output is finalized.

Race-Safety Pattern

  • each stream run gets a monotonic request id
  • starting a new run aborts and invalidates previous one
  • stale frames are ignored if request id mismatch
This prevents cross-stream UI corruption during rapid navigation or retries.

Parser Discipline

Parser should:
  • ignore malformed frames
  • ignore unknown event types safely
  • tolerate additive fields for forward compatibility