Chris Tate dba70b3919 docs(examples): add READMEs to chat, dashboard, game-engine, and no-ai examples (#277) 2 miesięcy temu
..
app 4bb1151b6c examples (#229) 3 miesięcy temu
components ddae61805e inline mode (#107) 4 miesięcy temu
lib 4bb1151b6c examples (#229) 3 miesięcy temu
.env.example 4bb1151b6c examples (#229) 3 miesięcy temu
CHANGELOG.md 9adcc09204 chore: version packages (#248) 3 miesięcy temu
README.md dba70b3919 docs(examples): add READMEs to chat, dashboard, game-engine, and no-ai examples (#277) 2 miesięcy temu
eslint.config.js 3201854481 external store adapter for state management (#139) 4 miesięcy temu
next.config.ts ddae61805e inline mode (#107) 4 miesięcy temu
package.json 9adcc09204 chore: version packages (#248) 3 miesięcy temu
postcss.config.mjs ddae61805e inline mode (#107) 4 miesięcy temu
tsconfig.json ddae61805e inline mode (#107) 4 miesięcy temu

README.md

Chat Example

An AI-powered data explorer that streams rich, interactive UI directly into a chat interface. The assistant uses tool calls to fetch real data (weather, GitHub, crypto, Hacker News, web search), then generates a json-render spec that renders inline alongside the conversation using shadcn components, Recharts, and React Three Fiber.

What it shows

  • Streaming specs inside chat messages -- pipeJsonRender on the server merges the AI SDK UI stream with json-render spec patches so text, tool-call indicators, and rendered UI all appear in the correct order within a single message bubble.
  • ToolLoopAgent with live data -- the agent loops through tool calls (weather, GitHub repos/PRs, crypto prices, Hacker News, web search) to gather real data before generating UI.
  • Full catalog/registry stack -- a catalog constrains what the model can produce; the registry maps every component to a real React implementation (shadcn, Recharts charts, R3F 3D scenes).
  • State and interactivity -- $state, $bindState, visibility, and actions work inside the streamed spec, so the rendered UI is interactive, not static.

Setup

pnpm install          # from the monorepo root
cd examples/chat
cp .env.example .env.local

Set the required environment variables in .env.local:

Variable Required Description
AI_GATEWAY_API_KEY Yes Vercel AI Gateway key (auto-authenticated on Vercel)
AI_GATEWAY_MODEL No Model identifier, defaults to anthropic/claude-haiku-4.5
KV_REST_API_URL No Upstash Redis URL for rate limiting
KV_REST_API_TOKEN No Upstash Redis token
RATE_LIMIT_PER_MINUTE No Defaults to 10
RATE_LIMIT_PER_DAY No Defaults to 100

Rate limiting is a no-op when the Upstash variables are not set.

Run

pnpm dev
# http://chat-demo.json-render.localhost:1355

Requires global portless. The predev script checks for it automatically.

Files

  • app/page.tsx -- chat UI with useChat, message rendering, and inline spec display
  • app/api/generate/route.ts -- streams the agent through pipeJsonRender with optional Upstash rate limiting
  • lib/agent.ts -- ToolLoopAgent with system prompt from explorerCatalog.prompt() and custom rules for layout, 3D, and interactivity
  • lib/tools/ -- tool definitions for weather, GitHub, crypto, Hacker News, and web search
  • lib/render/catalog.ts -- component catalog (shadcn base + custom metrics, tables, charts, tabs, 3D)
  • lib/render/registry.tsx -- maps catalog types to React components (shadcn, Recharts, R3F)
  • lib/render/renderer.tsx -- ExplorerRenderer wrapping StateProvider, VisibilityProvider, ActionProvider, and Renderer