Skip to content

[POLISH] Stream chat responses (SSE) #9

Description

@hasan-malik

Non-streaming chat feels slow (~6s for tool-using turns). Streaming makes the agent feel alive on stage.

Plan

  1. Switch `/api/chat/route.ts` to return a `ReadableStream` instead of JSON.
  2. Use Anthropic SDK's `client.messages.stream(...)` — yields `content_block_delta`, `tool_use_start`, etc.
  3. Server emits SSE frames: `text`, `tool_call`, `tool_result`, `done`.
  4. `components/chat-widget.tsx` uses `EventSource` or `fetch` + `ReadableStream.getReader()`.
  5. Render text deltas as they arrive; render tool chips on `tool_call` events.

Done when

  • Typing effect appears within ~500ms of pressing send
  • Tool chips slot in as the agent calls them, not all at once at the end

Risk

Mid-stream errors are harder to handle. Add a final `{ done: true }` marker so the client knows when to stop reading.

Metadata

Metadata

Assignees

No one assigned

    Labels

    polishNice to have if time

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions