Skip to content
QuireKit Markdown
Developer docs
Preview · unreleased

AI streaming

Render arriving Markdown as one message and handle completion, cancellation and failure.

An AI response usually arrives in several pieces. The application receives network data and accumulates text; QuireMarkdown renders the Markdown received so far. It does not send model requests or determine when they finish.

1. Pass the message to the reader

Keep the component imports from Quick start. message.id is a stable identifier for one response, and message.text is the accumulated source:

vue

Pass the complete received source on each update. Prefix appends reuse a parsing session; replacement, clearing, identity changes and replacing the options object create a fresh session and release old resources. status is receiving, complete, stopped or error. It describes transport state; stopping retains text and neither freezes blocks nor adds synthetic closing delimiters. Late link and footnote definitions can update earlier content. The application cancels its own network request.

2. Try appending and stopping

Choose “Start streaming” and watch headings, links and footnotes arrive. “Stop” retains received text. The application remains responsible for cancelling its network request.

Preparing the example…

Server-rendered first content

SSR produces semantic headings, lists and links by default, with the same parsing strategy on the first client render. Resource loading starts only after client mount. To defer initial parsing, use ssr="source": the server and initial client frame show escaped source, then parse after mounting. An existing snapshot may be passed as state, mutually exclusive with content.

3. Receive a real text response

This reusable function handles HTTP bodies containing raw Markdown text. Pass the application's AbortSignal to both fetch and this function; update message.text in onText. Set receiving on start, complete on success, stopped on user cancellation and error for other failures. Guard callbacks with the request identity so an old request cannot overwrite a different message. The host aborts on unmount.

recipes/response.ts only reads and decodes the response body. readMarkdownResponse(response, signal, onText) supplies accumulated source to onText and returns the complete text when finished. The application owns its message list, request state and error feedback.

recipes/response.tsts

For SSE or JSON events, decode the protocol in the host first and append only text deltas. Do not feed data:, event JSON or binary chunk boundaries directly to Markdown. TextDecoder must preserve decoding state between chunks.

QuireKit Markdown · QuireKitStreaming Markdown · @quirekit/incremark · MIT