Skip to content

feat: add 'manual' SSE mode for runtime stream/non-stream decisions#42

Open
CatchMe2 wants to merge 2 commits into
fastify:mainfrom
CatchMe2:feat/manual-sse-mode
Open

feat: add 'manual' SSE mode for runtime stream/non-stream decisions#42
CatchMe2 wants to merge 2 commits into
fastify:mainfrom
CatchMe2:feat/manual-sse-mode

Conversation

@CatchMe2

Copy link
Copy Markdown

What

Adds a new sse: 'manual' route mode (shorthand sse: 'manual' and object form { kind: 'manual' }) that lets a handler decide at runtime whether to stream, without any Accept-header negotiation.

Why

OpenAI-compatible and other LLM APIs decide whether to stream based on the request body ({ "stream": true }) rather than the Accept header — the client sends no Accept: text/event-stream either way.

Behavior

  • 'manual' skips Accept negotiation: reply.sse is always attached.
  • The handler streams (reply.sse.send(...)) or returns a plain value. SSE headers commit lazily on the first send()/stream(), so a non-streaming return falls through to Fastify's normal JSON serialization uncorrupted.
  • Heartbeat start is deferred until headers are committed, so a non-streaming fallback response is never corrupted by a heartbeat write (a correctness improvement that applies to all modes).

Resolves #16

Checklist

@CatchMe2

This comment was marked as spam.

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for dynamic SSE without Accept header

3 participants