Recipe · Chat
A streaming assistant turn, drawn with our primitives.
A message arrives, the reply types itself, the reasoning shines while it runs, a tool asks for approval, then prints its result. The live preview below runs entirely in the browser; the tabs show the same turn wired to the AI SDK or TanStack AI.
Live preview
Press a suggestion, type a message, or answer the tool call yourself. The thread replays a real shape of stream: a user turn, a reasoning part, an approval, the result, then the typed answer.
AI chat recipelive
Prequel Bot
Ready when you are
A streaming turn, start to finish
Pick a suggestion below. The demo streams a message, a reasoning part, a tool call with approval, its result, then the reply.
Demo mode: the turn is scripted in the browser, with no model, API key or network request. Approve or deny the tool call to steer it.
How the parts map
Both libraries describe an assistant turn as an ordered list of parts. We keep that list and give each kind its own visual weight: a paragraph for text, a quiet trace for reasoning, a card for the tool.
| Part | What it carries | What we draw |
|---|---|---|
| text | The reply so far, streamed as content | A typed paragraph with a blinking caret and a selectable final text |
| thinking / reasoning | The model's reasoning while it works | A reasoning line: shimmering Thinking, then Thought with the text |
| tool-call | A name, typed arguments and a state | A tool line, with Deny and Approve when approval is requested |
| tool-result | The result matched by the call id | The same line turns from Running to Ran and unfolds its output |
| status: submitted | Sent, before the first part exists | A Thinking marker with the same shimmer as the reasoning line |
The approval is a question for the person, not a step the model took, so it sits outside the reasoning trace. Denying it stops the tool without discarding the conversation.
Install
The recipe uses two registry items for the visual pieces: the press behaviour of button and the reasoning shimmer of shimmering-text. Add them with the shadcn CLI, then pick the streaming library your route already uses.
Buttonpress spring 550 / 30, scale 0.97
npx shadcn@latest add https://prequeluianimate.terravidhal.me/r/button.jsonShimmering textthe reasoning label
npx shadcn@latest add https://prequeluianimate.terravidhal.me/r/shimmering-text.jsonThe UI layer never imports either streaming library. That is the point of the parts table: the client reads a list, and only the route knows how that list was produced.
Two ways to stream
Both variants send the same conversation and render the same parts. The route owns the model, the tool and the approval policy; the client owns the thread, the field and the motion.
import { openai } from "@ai-sdk/openai";
import { convertToModelMessages, isStepCount, streamText, tool } from "ai";
import { z } from "zod";
import { installFromRegistry } from "@/lib/registry";
export async function POST(request: Request) {
const { messages } = await request.json();
const result = streamText({
model: openai("gpt-5-mini"),
instructions:
"You are a UI assistant. Use the registry tool before you answer, and keep replies short.",
messages: await convertToModelMessages(messages),
tools: {
addComponent: tool({
description: "Install a PrequelUI Animate registry item.",
inputSchema: z.object({ slug: z.string() }),
execute: async ({ slug }) => installFromRegistry(slug),
}),
},
toolApproval: { addComponent: "user-approval" },
stopWhen: isStepCount(8),
});
return result.toUIMessageStreamResponse();
}Install the AI SDK dependencies
AI SDKnpm install ai @ai-sdk/react @ai-sdk/openai zodWithout a model
A live preview should not need a key or a network. The demo above stores a turn as a small script, then reveals one part at a time with the same timings as a streamed response. The tool still waits for a real answer from the reader.
type Part =
| { kind: "thinking"; text: string }
| { kind: "tool-call"; name: string; input: { slug: string } }
| { kind: "tool-result"; output: string }
| { kind: "text"; text: string };
export const scriptedTurn: Part[] = [
{ kind: "thinking", text: "The registry item carries its motion tokens." },
{ kind: "tool-call", name: "addComponent", input: { slug: "dialog" } },
{ kind: "tool-result", output: "Added dialog.tsx and alert-dialog.tsx." },
{ kind: "text", text: "Done. The dialog now opens on a 300 / 30 spring." },
];
export function delayFor(part: Part) {
if (part.kind === "text") return 13;
if (part.kind === "thinking") return 1500;
if (part.kind === "tool-call") return 3400;
return 900;
}Swap the script for streamText or chat() and the components do not change. Keep the fallback turn in tests too: it makes the approval path deterministic, including a Deny.
Motion and access
The motion is quiet on purpose. A chat is read more than it is watched, so each part arrives once, lands quickly and then holds still.
- The thread is a role=log. The full prompt is the accessible name of the user message, so a screen reader never hears a partial word.
- The approval uses real buttons, not an animated overlay. Deny is as easy to reach as Approve.
- Under reduced motion the text arrives whole, the shimmer stops and the demo still reaches the same final state.
- No motion exceeds the content: the caret, the shimmer and the progress line are all decorative and aria-hidden.