import { streamText } from "ai";// Standalone mode is the default (no mode option needed)const systemPrompt = catalog.prompt({ customRules: [ "Use Card as root for forms and small UIs.", "Use Grid for multi-column layouts.", ],});const result = streamText({ model: "anthropic/claude-haiku-4.5", system: systemPrompt, prompt: userPrompt,});
On the client, use useUIStream from @json-render/react or the lower-level createSpecStreamCompiler from @json-render/core to compile the JSONL stream into a spec:
In inline mode, the AI responds conversationally first, then outputs JSONL patches on their own lines. Text-only replies are allowed when no UI is needed (e.g. greetings, clarifying questions).
This is ideal for:
AI chatbots with rich UI responses
Copilot experiences
Educational assistants
Any conversational interface where generated UI is embedded in chat messages
import { streamText } from "ai";import { pipeJsonRender } from "@json-render/core";import { createUIMessageStream, createUIMessageStreamResponse } from "ai";// Enable inline modeconst systemPrompt = catalog.prompt({ mode: "inline" });const result = streamText({ model: yourModel, system: systemPrompt, messages,});// In your API route, pipe the stream through pipeJsonRender// to separate text from JSONL patchesconst stream = createUIMessageStream({ execute: async ({ writer }) => { writer.merge(pipeJsonRender(result.toUIMessageStream())); },});return createUIMessageStreamResponse({ stream });
pipeJsonRender inspects each line of the AI's response. Lines that parse as JSONL patches are emitted as data-spec parts (which the renderer picks up). Everything else is passed through as text.
The AI writes a brief explanation, then JSONL patches on their own lines:
Here's a dashboard showing the latest crypto prices:{"op":"add","path":"/root","value":"dashboard"}{"op":"add","path":"/state/prices","value":[{"name":"Bitcoin","price":98450},{"name":"Ethereum","price":3120}]}{"op":"add","path":"/elements/dashboard","value":{"type":"Grid","props":{"columns":"2"},"children":["btc","eth"]}}{"op":"add","path":"/elements/btc","value":{"type":"Metric","props":{"label":"Bitcoin","value":{"$state":"/prices/0/price"}}}}{"op":"add","path":"/elements/eth","value":{"type":"Metric","props":{"label":"Ethereum","value":{"$state":"/prices/1/price"}}}}
If the user asks a simple question ("what does BTC stand for?"), the AI replies with text only — no JSONL.
Both modes use the same JSONL patch format (RFC 6902) and the same catalog/registry system. The only difference is whether the AI is allowed to include prose alongside the patches.