A chat assistant that streams back real, interactive React components instead of plain text — ask about revenue and get a live animated chart, ask to compare plans and get a real comparison table, ask to book a demo and get a working confirmation card. Built on the Vercel AI SDK's tool-calling + useChat pattern.
Most "AI chatbot" demos are a text box that returns markdown. The pattern that's actually valuable to build for clients — dashboards, booking flows, product configurators driven by natural language — is the model calling a typed tool server-side and the client rendering the result as a real UI component, not a wall of text describing it. This project implements that pattern end to end, with three working examples.
src/
lib/
tools.ts Three typed tools (Zod schemas + execute functions): showRevenueChart,
comparePlans, scheduleDemo
scriptedModel.ts A deterministic LanguageModelV1 implementation (see below)
app/
api/chat/route.ts POST handler: streamText with the tools, real OpenAI or the scripted
model depending on whether OPENAI_API_KEY is set
page.tsx
components/
ChatWindow.tsx useChat-driven chat UI, suggestion chips for discoverability
ChatMessage.tsx Renders message.parts — dispatches tool-invocation results to:
tool-ui/
RevenueChart.tsx Animated bar chart (inline SVG-free CSS, no chart library)
ComparisonTable.tsx Side-by-side plan comparison
BookingCard.tsx Confirmation card with a generated confirmation ID
The interesting piece is scriptedModel.ts. Rather than hand-rolling a fake version of the chat UI for a zero-cost public demo (the approach in my other RAG projects), this implements the AI SDK's actual LanguageModelV1 interface directly — using MockLanguageModelV1 and simulateReadableStream from ai/test — so the exact same streamText → tool-execution → useChat → component-rendering pipeline that a real OpenAI-backed deployment uses is what's running in the public demo. The only thing swapped is which "model" answers doStream(): a keyword-matched, deterministic sequence of stream parts instead of a real API call. Nothing in the frontend or the route handler knows or cares which one it's talking to.
npm install
npm run dev # runs in demo mode — no API key needed, same UITo use a real model:
cp .env.example .env.local
# set OPENAI_API_KEY=sk-...
npm run devTry: "How is the Pro Plan performing this quarter?", "Compare the Pro and Enterprise plans", "Book a demo for next Tuesday at 2pm".
npm test12 tests covering the scripted model's stream output (correct tool selection per keyword, correct AI SDK stream-part shape, the follow-up-text-only path once a tool result is present, and the no-match fallback) and each tool's execute function (deterministic output, sane fallbacks for unrecognized input).