Use json-render with the Vercel AI SDK for seamless streaming. json-render supports two modes: Standalone (standalone UI) and Inline (UI embedded in conversation). See Generation Modes for a detailed comparison.
In standalone mode, the AI outputs only JSONL patches. The entire response is a UI spec with no prose. This is the default mode and is ideal for playgrounds, builders, and dashboard generators.
In inline mode, the AI responds conversationally and includes JSONL patches inline. Text-only replies are allowed when no UI is needed. This is ideal for chatbots, copilots, and educational assistants.
The example above is a message-level layout: text joins all text parts, and spec combines all spec data parts into one cumulative spec. It renders the joined text followed by the UI, not the original part order.
For mixed inline layouts, iterate message.parts instead. Render the latest merged spec once at the firstSPEC_DATA_PART_TYPE position and skip subsequent spec parts. Individual spec parts may be patches, not standalone UI blocks. Later patches update that same UI in place, even when text or tools occur between them; this does not create a separate UI snapshot at each patch position.
Here, registry is your component registry and renderPart is your application's renderer for tool, reasoning, source, and other parts (return null for parts you do not display). For text → tool → text → spec patch → text → spec patch, the layout is text → tool → text → merged UI → text. Do not also render the hook's aggregated text, or the text will appear twice.
During streaming, hasSpec can be false while the initial patches have not added any elements yet. The UI appears at the first spec-part position once hasSpec is true; text-only messages render without a UI block. See the chat example's ordered segments for a complete implementation that also groups adjacent text and tool parts.
In inline mode, the prompt instructs the AI to respond conversationally first, then include JSONL patches on their own lines when UI is needed. Text-only replies are allowed.