Chat AppPRO
A complete assistant screen: history sidebar, model switcher, the thread and a composer, wired to a real model.
Code
24 files · 3,730 lines of TypeScriptPRO
Chat App is part of Pro
Get its source, the one-paste agent prompt and all 113 components, for a one-time $99.
Motion notes
- Runs on `useChat`: by default it POSTs `{ messages, model }` to `/api/chat` and reads the Claude stream with `anthropicAdapter`, so reasoning, tool calls and Markdown arrive as Thinking, ToolCall and StreamingMarkdown with no glue code. Pass `transport` for another provider, or `chat` to own the state yourself.
- The docked sidebar springs its width open while its content keeps a fixed width, so the history never reflows mid-animation. Under 900px of its own width it becomes a slide-over with a scrim; Esc or a tap outside closes it.
- The composer lifts a couple of pixels and gains depth while focused, attachments collapse in above it, and the footer hint swaps to “Esc to stop” while a reply streams. Enter sends, Shift+Enter adds a line, Esc stops.
- The empty state rises in order (orb, headline, detail, suggestions) and fades out as the thread fades in. With reduced motion, panels and states switch with short fades and nothing travels.
Usage
Example
// app/chat/page.tsx
"use client";
import { ChatApp } from "@/components/thinking-ui/chat-app";
export default function Page() {
return (
<div className="h-dvh">
<ChatApp suggestions={["Summarize a PDF", "Write a SQL query"]} />
</div>
);
}
// The block POSTs { messages, model } to /api/chat and expects the Claude
// Messages API stream back unchanged. A minimal app/api/chat/route.ts:
// read the body, allowlist `model`, then call
// client.messages.create({ model, max_tokens: 64000, stream: true,
// thinking: { type: "adaptive", display: "summarized" },
// messages: toAnthropicMessages(messages) }).asResponse()
// with @anthropic-ai/sdk and return its body as text/event-stream.
// `display: "summarized"` is what makes reasoning stream into Thinking.
// Using OpenAI or the AI SDK instead? Pass
// transport={httpTransport({ adapter: openaiAdapter })}Props
| Prop | Type | Default | Description |
|---|---|---|---|
| transport | ChatTransport | — | Where messages go. Defaults to httpTransport({ api, body: { model } }). |
| api | string | "/api/chat" | Route for the default transport. |
| chat | ReturnType<typeof useChat> | — | Your own useChat() result. The block renders it instead of creating one. |
| initialMessages | ChatMessage[] | — | Starting messages for the built-in useChat. |
| title | string | "Thinking UI" | Product name at the top of the sidebar. |
| welcome | ReactNode | "What can I help with?" | Headline before the first message. |
| welcomeDetail | ReactNode | — | Line under the headline. |
| suggestions | Suggestion[] | — | Starter prompts in the empty state. Selecting one sends it. |
| placeholder | string | "Message the assistant…" | Composer placeholder. |
| models | ModelOption[] | — | Options for the model switcher. Values are sent as `model` in the request body. |
| model / defaultModel / onModelChange | string / string / (model) => void | — | Controlled or uncontrolled model choice. |
| initialChats | ChatAppConversation[] | — | Seeds the built-in history. Each item may carry `messages` to load on select. |
| chats | ChatHistoryItem[] | — | Controlled history. Load messages yourself with chat.setMessages in onSelectChat. |
| activeChatId | string | — | Controlled active conversation. |
| onSelectChat / onNewChat | (id) => void / () => void | — | Replace the built-in conversation switching. |
| onRenameChat / onDeleteChat | (id, title) => void / (id) => void | — | Replace the built-in rename and delete. |
| now | number | — | Reference time for grouping the history. Pass it for deterministic SSR. |
| attachments | ChatAppAttachment[] | — | Controlled chips above the composer ({ id, name, size?, progress?, status }). |
| onAttach | (files: File[]) => void | — | Files picked with the paperclip. Upload them and feed progress back through `attachments`. |
| onRemoveAttachment | (id) => void | — | A chip's remove button was pressed. |
| input / onInputChange | string / (value) => void | — | Controlled composer text. |
| sidebarOpen / defaultSidebarOpen / onSidebarOpenChange | boolean / boolean / (open) => void | — / true / — | Sidebar visibility (docked or slide-over). |
| user | { name: string; detail?: string } | — | Shown at the foot of the sidebar. |
| onShare / onSettings | () => void | — | Top bar icon buttons. |
| className | string | — | Classes for the root. Give it a height: it fills its parent. |