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 streamstatus: shows lightweight progress textclear: resets provisional texttoken: appends generated textdone: attaches sources/metadata and closes lifecycleerror: renders terminal failure text
/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
Parser Discipline
Parser should:- ignore malformed frames
- ignore unknown event types safely
- tolerate additive fields for forward compatibility