Chat
Full-height AI conversation block with a conversation switcher, model picker, inline user message edits, collapsible reasoning, expandable tool chips, inline citation hover cards, syntax-tinted code, version paging, and an autosizing composer.
import { AIChat } from '@uthereal/ui/ai-chat'Aichat playground
What are we working on?
Overview
AIChat renders a complete single-column AI assistant surface with a slim header, an internally pinned message thread, and a docked composer. Set height to a pixel value (320–1200, default 640) or 'full' when the parent reserves a fixed-height column.
| Capability | Behavior |
|---|---|
| Header controls | Conversation history menu grouped by period, model switcher with brand marks, and a New chat button. |
| Streaming & reveal | Streams reasoning, tool calls, sources, and text deltas through a steady chunked word-fade clock. |
| Reasoning & tools | Collapsible Thought for Ns disclosure and expandable tool chips for search queries, SQL, and sources. |
| Markdown & code | Headings, lists, inline code, syntax-tinted fenced code blocks with copy, and [n] hover citations. |
| Edits & versioning | Editing a prompt or retrying a reply branches the turn with < 2 / 2 > version paging. |
| Empty state & input | Centered greeting, starter suggestion cards, file attachment chips (up to 4), and Send/Stop toggle. |
Use AIChat for a full conversation workspace with history, branching turns, and tool traces. Use Composer when you need an inline /command and @mention prompt bar with an optional lightweight stage, or Model arena to compare two models side by side.
Usage
'use client'
import { AIChat, type AiChatRespond } from '@uthereal/ui/ai-chat'
const respond: AiChatRespond = async function* (messages, { signal, model }) {
const res = await fetch('/api/chat', {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ model: model.id, messages }),
signal,
})
const reader = res.body?.getReader()
const decoder = new TextDecoder()
while (reader) {
const { done, value } = await reader.read()
if (done) break
yield { type: 'text', delta: decoder.decode(value, { stream: true }) }
}
}
export function AssistantWorkspace() {
return (
<AIChat
greeting="What are we working on?"
respond={respond}
height={640}
onFeedback={(message, rating) => {
console.log('Feedback', message.id, rating)
}}
onModelChange={(model) => {
console.log('Selected model', model.id)
}}
/>
)
}Omit respond to run the built-in local simulator (nothing leaves the browser; scripted answers include reasoning, tool calls, sources, and a simulated timeout that recovers on Retry). Passing respond disables sample history and suggestions unless you supply history or suggestions explicitly.
Examples
Use <SchemaPlayground /> above to inspect recipe, motion, theme, height, and the default empty greeting state. The examples below cover seeded multi-turn transcripts and compact workspace configurations.
Seeded thread with reasoning, tools, and citations
Pass initialMessages with reasoning, thoughtFor, tools, sources, and inline [1]/[2] citations to open directly on a settled conversation. Assistant messages can also carry status: 'error' and error to surface an inline Retry action.
- invoices-schema.sql
How do I add a NOT NULL column to a 40M-row Postgres table without blocking writes?
Split the migration into a metadata-only constraint followed by an online validation 1:
ALTER TABLE invoices
ADD COLUMN currency text DEFAULT 'USD';
ALTER TABLE invoices
ADD CONSTRAINT invoices_currency_not_null
CHECK (currency IS NOT NULL) NOT VALID;
ALTER TABLE invoices
VALIDATE CONSTRAINT invoices_currency_not_null;Once validated, PostgreSQL 12+ can promote SET NOT NULL without re-scanning the 40M rows 2.
Generate a rollback script and lock timeout guard for the deploy pipeline.
Reply failed. Upstream model timed out after 30s. Select Retry to resume from the last turn.
Compact workspace without sample history
Pass history: [], a focused models lineup, custom suggestions, and a smaller height to embed AIChat in a side panel or product assistant drawer with host actions wired.
Ask the billing copilot
API reference
Serializable schema arguments and defaults come directly from aiChatConfigSchema.
| Argument | Type / default | Description |
|---|---|---|
title | string— | Conversation title shown in the header; auto-titled from the first message when omitted. |
greeting | stringDefault: "What are we working on?" | Heading shown in the empty state before any message; pairs with suggestions. |
placeholder | stringDefault: "Ask anything" | Hint text inside the composer textarea when the draft is empty. |
models | AiChatModel[]Default: [{"id":"claude-opus-5-5","name":"Claude Opus 5.5","brand":"claude","note":"Anthropic","color":"#D97757"},{"id":"claude-sonnet-5-5","name":"Claude Sonnet 5.5","brand":"claude","note":"Anthropic","color":"#D97757"},{"id":"gpt-6-1-sol","name":"GPT-6.1 Sol","brand":"openai","note":"OpenAI"},{"id":"gemini-4-argon","name":"Gemini 4 Argon","brand":"google","note":"Google"},{"id":"mistral-large-4","name":"Mistral Large 4","brand":"mistral","note":"Mistral AI"}] | Chat models offered by the header picker; the first is the default when defaultModel is unset. |
defaultModel | string— | ID of the initially selected model; must match a models entry. |
initialMessages | AiChatMessage[]— | Flat seed conversation; a trailing user message opens a pending assistant reply. |
history | AiChatHistoryItem[]— | Past conversations listed in the header menu, grouped by their group field; newest chat first. |
suggestions | AiChatSuggestion[]— | Starter prompt cards under the greeting in the empty state; up to three show. |
autoPlay | booleanDefault: false | Run the built-in sample responder when the host supplies no respond function. |
height | integer | stringDefault: 640 | Block height in px (320–1200) or full to fill the parent; drives the internal scroll area. |
sendAction | string— | Registered host action requested when a message is sent. |
feedbackAction | string— | Registered host action requested when thumbs up or down is toggled. |
newChatAction | string— | Registered host action requested when the New chat button is pressed. |
recipe | studio | softDefault: "studio" | Visual treatment. Both recipes preserve interaction behavior. |
theme | AiChatThemeDefault: {} | Color mode, accent, and typed semantic token overrides. |
motion | none | subtle | expressiveDefault: "subtle" | Animation preset. System reduced-motion preferences take precedence. |
motionOptions | AiChatMotionOptionsDefault: {} | Swap, fold, streaming chunk fade, and thread crossfade timing overrides in milliseconds. |
dir | ltr | rtl— | Reading direction; inherited from the page when omitted. |
locale | string— | BCP 47 locale for attachment size and duration formatting; inherited when omitted. |
AiChatModelaccepts{ id, name, brand?, note?, color?, icon? }. Model IDs must be unique.AiChatMessageaccepts{ id?, role: 'user' | 'assistant', content, model?, reasoning?, thoughtFor?, tools?, sources?, attachments?, status?, error? }.AiChatHistoryItemaccepts{ id, title, group?, messages }with at least one message per conversation.AiChatSuggestionaccepts{ label, prompt?, icon?: 'database' | 'timer' | 'activity' | 'search' }.
React integration
| Prop | Purpose |
|---|---|
respond(messages, opts) | Async iterable returning AiChatStreamEvent (reasoning, reasoning-end, tool, sources, text, error). |
onFeedback(message, value) | Called when a reply is rated 'up', 'down', or cleared (null). |
onModelChange(model) | Called when the reader picks a different model in the header menu; subsequent replies use it. |
onNewChat() | Called when the reader clicks the New chat button or chooses New chat in the conversation menu. |
onAction(action) | Host action callback fired for sendAction, feedbackAction, and newChatAction. |
renderModelMark(mark) | Replaces the default provider SVG or monogram mark. Keep returned elements decorative. |
portalContainer | Custom DOM mount target for portalled chat/model menus, tooltips, and citation hover cards. |
preset | Application defaults merged below explicit instance arguments. |
tokens | --ui-* CSS variables applied after the typed theme on the root and portalled menus. |
ref, className, style | Forwarded to the root <section> element. style takes precedence over motion and theme tokens. |
| Native attributes | id, aria-*, data-*, and remaining <section> props forwarded to the root element. |
Keyboard & accessibility
| Key | Action |
|---|---|
Enter (composer / editor) | Submits the message or edited prompt; ignored during IME composition. |
Shift+Enter | Inserts a newline and grows the autosizing composer up to seven lines. |
Escape | Stops an active streaming reply from the composer, cancels an inline edit, or closes open menus. |
ArrowUp / ArrowDown | Moves focus across conversations or models in the open header menu (wraps cleanly). |
Tab | Moves across header controls, turn disclosures, citations, turn actions, and the composer. |
- A pre-mounted polite
role="status"live region announces reply start, completion, stop, errors, version switches ("Version 2 of 2"), model selection, attachments, feedback, and clipboard copy outcomes. - Collapsible reasoning and tool detail buttons wire
aria-expandedandaria-controls; non-expandable headers disable activation and omit disclosure chevrons. - Version controls render inside a
role="group"labeled"Version N of M"; feedback thumbs exposearia-pressed; citation links carry full labels naming source number, title, and domain. - Hover-only turn actions remain visible on keyboard
:focus-withinand on touch devices (@media (hover: none)). - Layout geometry uses logical CSS properties (
padding-inline,border-inline-start,margin-inline-start), forwardsdirto<section>and all portals, and adapts at480pxand360pxcontainer widths. Underforced-colors: active, borders, surfaces, send button, and open citations map to system colors.
Motion & theming
Reasoning panels, tool details, and attachment trays fold on the zero-bounce smooth spring while turn edits and version switches glide height on the snappy spring. Header labels crossfade with measured width springs, streamed chunks fade in on a 34ms word clock, and pinned scroll follows new lines with a soft lerp.
Setting motion="none" makes all springs, CSS transitions, chunk fades, and spinners immediate (0ms). Under prefers-reduced-motion: reduce, springs, travel, chunk fades, and smooth scrolling turn off while preserving 120ms opacity crossfades.
| Token group | CSS custom properties |
|---|---|
core | --ui-surface, --ui-surface-raised, --ui-text, --ui-text-secondary, --ui-muted, --ui-border, --ui-highlight, --ui-accent, --ui-accent-foreground, --ui-danger, --ui-focus-ring, --ui-radius, --ui-border-width, --ui-shadow, --ui-disabled-opacity, --ui-font, --ui-font-size, --ui-font-weight |
extended | --ui-surface-sunken, --ui-border-strong, --ui-border-subtle, --ui-track, --ui-info, --ui-success, --ui-warning, --ui-tone-foreground, --ui-overlay, --ui-tint-strength |
shape | --ui-radius-sm, --ui-popup-radius, --ui-surface-radius |
accentTones | --ui-accent-strong, --ui-accent-subtle |
type | --ui-font-mono, --ui-font-display |
include | --ui-series-1, --ui-series-3, --ui-series-4 (SQL syntax keyword, number, and string tints) |
An application-wide UtherealProvider supplies defaults.
Composition
In an agent composition, AIChat is a leaf block (group: 'blocks-agents'). Keep models non-empty with unique IDs, align 1-indexed [n] citations with sources, leave autoPlay false unless requesting a demo, and register sendAction, feedbackAction, and newChatAction on the host.
{
"type": "AIChat",
"props": {
"title": "Database migration",
"greeting": "How can I help with your schema?",
"height": 560,
"sendAction": "send_ai_chat_message",
"feedbackAction": "rate_ai_chat_reply",
"newChatAction": "start_ai_chat"
},
"children": []
}