Back to RecipesYou are on AI Chat.

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 demo · no keyReactNext.jsMotionAI SDKTanStack AIshadcn/ui
01

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.

Scripted in the browser: no provider, no API key and no request.Safe to replay
02

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.

PartWhat it carriesWhat we draw
textThe reply so far, streamed as contentA typed paragraph with a blinking caret and a selectable final text
thinking / reasoningThe model's reasoning while it worksA reasoning line: shimmering Thinking, then Thought with the text
tool-callA name, typed arguments and a stateA tool line, with Deny and Approve when approval is requested
tool-resultThe result matched by the call idThe same line turns from Running to Ran and unfolds its output
status: submittedSent, before the first part existsA 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.

03

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.json
npmthe default on every machine

Shimmering textthe reasoning label

npx shadcn@latest add https://prequeluianimate.terravidhal.me/r/shimmering-text.json
npmthe default on every machine

The 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.

AI SDKTanStack AIThe dependency command for each one sits in its tab below.
04

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.

app/api/chat/route.tsAI SDK
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 SDK
npm install ai @ai-sdk/react @ai-sdk/openai zod
npmthe default on every machine
Only the way each part is read changes. The message list, the reasoning line, the approval card and the result panel stay exactly the same.
05

Without 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.

use-scripted-turn.tsno network
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.

06

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.

Message entranceopacity · 10 px · 4 px blurspring 300 / 30
Typed text13–17 ms per character1 s caret
Reasoningshimmering label · 3 dots1 s · 160 ms stagger
Tool callapproval → run → result950 ms · height 300 / 30
Reduced motionno travel · no loop · no carettext arrives whole
  • 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.
spring 300 / 3013–17 msshimmer 1 sexit 160 msreduced motion

Built by Vidhal. The source is available on GitHub.

MIT licensed