Composer
Mirror-textarea AI prompt composer with atomic slash commands and file mentions, attachment progress chips, web search and thinking toggles, a model and effort picker, dictation waveform, character limit ring, and a morphing send/stop control.
import { AIComposer } from '@uthereal/ui/ai-composer'Aicomposer playground
What should we work on?
Overview
AIComposer provides a native-textarea prompt box layered over a synchronized mirror so spellcheck, undo, selection, and IME stay native while /commands and @mentions highlight and delete as atomic tokens. By default (showStage: true), it opens on a centered greeting stage with starter suggestions and transitions into a scrolling thread once a message is sent. Set showStage: false to embed only the composer surface inside your own layout.
| Capability | Behavior |
|---|---|
| Mirror tokens | Typing / at line start or @ opens a keyboard listbox; picked tokens hop on arrows and delete atomically. |
| Attachments | Plus menu (Upload, Drive, GitHub, Screenshot), drag-and-drop, and long pastes render chips with upload rings. |
| Toolbar toggles | Web search and Extended thinking toggle chips with tooltips that fold cleanly to icons below 680px. |
| Model & effort | Portalled menu with brand marks, descriptions, and a five-step effort selector with a gliding thumb. |
| Dictation & limit | Simulated dictation waveform with elapsed timer, plus a character-limit ring at 80%, warning at 95%, block >100%. |
| Send / Stop morph | Accent send arrow morphs into a stop square ringed by live reply progress while streaming. |
Use AIComposer for standalone AI prompt inputs, command-and-mention bars, or lightweight single-thread assistants. Use Chat when you need conversation history, message branching, tool traces, and inline citations.
Usage
'use client'
import { AIComposer, type ComposerMessage } from '@uthereal/ui/ai-composer'
export function AgentPromptBar() {
async function* handleSend(
message: ComposerMessage,
{ signal }: { signal: AbortSignal },
) {
const res = await fetch('/api/complete', {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify(message),
signal,
})
const reader = res.body?.getReader()
const decoder = new TextDecoder()
while (reader) {
const { done, value } = await reader.read()
if (done) break
yield decoder.decode(value, { stream: true })
}
}
return (
<AIComposer
showStage={false}
placeholder="Ask your workspace, / for commands, @ for context"
sendAction="submit_agent_prompt"
onSend={handleSend}
/>
)
}Omit onSend to run the built-in local reply simulator (nothing leaves the browser). When onSend returns an AsyncIterable<string>, AIComposer streams chunks through its reveal clock and aborts signal when the reader presses Stop.
Examples
Use <SchemaPlayground /> above to inspect recipe, motion, theme, and the full greeting stage. The examples below show embedded prompt-bar mode and a custom engineering-triage setup with domain commands and mentions.
Embedded prompt surface (showStage: false)
Set showStage: false to omit the 680px stage container, greeting, and starter suggestions, rendering only the compact composer box ready to dock inside an existing panel or transcript layout.
Custom commands, mentions, and triage starters
Customize models, defaultModel, commands, mentions, and suggestions to tailor the slash-command listbox, @ context picker, and clickable starter prompts to any workflow.
What are we debugging today?
API reference
Serializable schema arguments and defaults come directly from aiComposerConfigSchema.
| Argument | Type / default | Description |
|---|---|---|
greeting | stringDefault: "What should we work on?" | Heading of the empty new-chat state. |
placeholder | stringDefault: "Ask anything, / for commands, @ to add context" | Placeholder of the empty textarea. Defaults to Ask anything, / for commands, @ to add context. |
models | ComposerModel[]Default: [{"id":"claude-opus-5-5","name":"Claude Opus 5.5","short":"Opus 5.5","note":"Flagship for complex work","mark":"claude","defaultEffort":"medium"},{"id":"claude-sonnet-5-5","name":"Claude Sonnet 5.5","short":"Sonnet 5.5","note":"Everyday coding and agents","mark":"claude","defaultEffort":"high"},{"id":"claude-haiku-5-5","name":"Claude Haiku 5.5","short":"Haiku 5.5","note":"Fastest for quick answers","mark":"claude","defaultEffort":"medium"},{"id":"gpt-6-1-sol","name":"GPT-6.1 Sol","short":"GPT-6.1 Sol","note":"OpenAI, released Sep 29","mark":"openai","defaultEffort":"medium"},{"id":"gemini-4-argon","name":"Gemini 4 Argon","short":"Gemini 4","note":"Google, 2M context","mark":"google","defaultEffort":"medium"}] | Models in the model menu; the chip shows short, the menu shows name and note. Defaults to the October 2026 sample lineup. |
defaultModel | string— | Model selected on first render. Defaults to the first model in the list. |
suggestions | ComposerSuggestion[]Default: [{"id":"launch","label":"Summarize the Q4 launch plan","prompt":"/summarize @Q4 launch plan and list the open risks","icon":"summary"},{"id":"reply","label":"Draft a reply to Priya","prompt":"Draft a short reply to Priya about the annual discount on the Team plan","icon":"draft"},{"id":"bug","label":"Explain the checkout retry bug","prompt":"/explain why @checkout.tsx can charge a card twice on a slow network","icon":"bug"}] | Starters under the composer in the empty state; choosing one fills the composer. Defaults to three samples. |
commands | ComposerCommand[]Default: [{"id":"summarize","label":"/summarize","hint":"Condense text or a file into key points"},{"id":"translate","label":"/translate","hint":"Translate into another language"},{"id":"explain","label":"/explain","hint":"Walk through code or an idea step by step"},{"id":"fix","label":"/fix","hint":"Find and fix a bug in the code"}] | Slash commands opened by / at the start of a line. Defaults to /summarize, /translate, /explain and /fix. |
mentions | ComposerMention[]Default: [{"id":"checkout","label":"checkout.tsx","group":"Files","meta":"src/app/checkout","kind":"code"},{"id":"pricing","label":"pricing-q4.csv","group":"Files","meta":"data/finance","kind":"sheet"},{"id":"guidelines","label":"brand-guidelines.pdf","group":"Files","meta":"Design, 4.8 MB","kind":"pdf"},{"id":"launch","label":"Q4 launch plan","group":"Docs","meta":"Notion, edited Oct 18","kind":"notion"},{"id":"retries","label":"Checkout retries","group":"Docs","meta":"Linear, ENG-2481","kind":"linear"},{"id":"flow","label":"Checkout flow v3","group":"Docs","meta":"Figma, edited Oct 16","kind":"figma"}] | Files and docs inserted as atomic @ tokens, grouped by group. Defaults to six samples. |
maxLength | integerDefault: 4000 | Character limit; a ring counter appears at 80 percent, warns at 95 percent and blocks sending above it. |
showStage | booleanDefault: true | Show the full chat stage with greeting, suggestions and streamed turns. False embeds just the composer surface. |
sendAction | string— | Registered host action requested when a message is sent. |
recipe | studio | softDefault: "studio" | Visual treatment. Both recipes preserve interaction behavior. |
theme | AIComposerThemeDefault: {} | Color mode, accent, and typed semantic token overrides. |
motion | none | subtle | expressiveDefault: "subtle" | Animation preset. System reduced-motion preferences take precedence. |
motionOptions | AIComposerMotionOptionsDefault: {} | Menu and listbox popup transition timing overrides in milliseconds. |
dir | ltr | rtl— | Reading direction; inherited from the page when omitted. |
ComposerModelaccepts{ id, name, short, note, mark: 'claude' | 'openai' | 'google', defaultEffort?: 'low' | 'medium' | 'high' | 'xhigh' | 'max' }(unique IDs, 1–20 items).ComposerCommandaccepts{ id, label, hint }(unique IDs, up to 20 items).ComposerMentionaccepts{ id, label, group?, meta, kind: 'code' | 'sheet' | 'pdf' | 'notion' | 'linear' | 'figma' }(unique IDs, up to 50 items).ComposerSuggestionaccepts{ id, label, prompt, icon?: 'summary' | 'draft' | 'bug' }(unique IDs, up to 6 items; up to 3 render in the empty stage).
React integration
| Prop | Purpose |
|---|---|
onSend(message, { signal }) | Called with { text, tokens, attachments }. Return void, Promise<void>, or AsyncIterable<string>. |
onAction(action) | Host action callback fired with sendAction whenever a message is submitted. |
portalContainer | Custom DOM mount target for portalled context/model menus and tooltips. |
preset | Application defaults merged below explicit instance arguments. |
tokens | --ui-* CSS variables applied after the typed theme on the root and portalled menus. |
ref | Forwarded directly to the underlying <textarea> element. |
className, style | Applied to the root <section> element. style takes precedence over theme tokens. |
| Native attributes | id, aria-*, data-*, and remaining <section> props forwarded to the root element. |
Keyboard & accessibility
| Key | Action |
|---|---|
Enter | Picks the highlighted /command or @mention when the listbox is open; otherwise submits. |
Shift+Enter | Inserts a newline and autosizes the textarea cleanly with its mirror. |
ArrowUp / ArrowDown | Moves highlight through the open command/mention listbox or attachment/model menus. |
Tab | Inserts the active command or mention suggestion when the listbox is open. |
Escape | Closes the open command/mention listbox or active popover menu. |
Backspace / Delete | Deletes an adjacent /command or @mention token atomically while preserving native undo. |
ArrowLeft / ArrowRight | Hops cleanly across atomic tokens in visual order (respects RTL). |
- The
<textarea>exposesrole="combobox",aria-autocomplete="list",aria-expanded,aria-controls, andaria-activedescendantwhile the command or mention listbox is open. - Web search, Extended thinking, and Dictate use native
<button>controls witharia-pressed; the model picker announces both model name and selected effort level. - A pre-mounted polite
role="status"live region announces submission, active replies, completion, and stop events. - Container queries fold toolbar chip labels into icon buttons below
680px, hide the effort suffix below560px, and keep every control on one row down to320px. Logical CSS properties anddirforwarding support RTL, andforced-colors: activemaps tokens, pressed chips, and the send control toHighlight/HighlightText.
Motion & theming
The send arrow morphs into a stop square on the morph spring while a progress arc wraps the button, attachment chips scale in on a crisp pop spring, the model chip springs width when switching models, and the effort selector thumb glides via a scoped layoutId (LazyMotion with domMax).
Setting motion="none" or enabling prefers-reduced-motion: reduce disables springs, transitions, progress-ring spin, live waveform frames, and chunk fades, revealing replies immediately.
| 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 |
control | --ui-control-height, --ui-control-padding-x, --ui-control-gap, --ui-icon-size |
popupList | --ui-popup-padding, --ui-popup-min-width, --ui-popup-max-width, --ui-item-height, --ui-item-padding-x, --ui-item-padding-y, --ui-item-gap, --ui-item-radius |
type | --ui-font-mono, --ui-font-display |
include | --ui-shadow-resting, --ui-series-1 |
An application-wide UtherealProvider supplies defaults.
Composition
In an agent composition, AIComposer is a leaf block (group: 'blocks-agents'). Keep IDs unique within models, commands, mentions, and suggestions, set showStage: false when docking inside an existing conversation view, and wire sendAction to a registered host action.
{
"type": "AIComposer",
"props": {
"showStage": false,
"placeholder": "Ask anything, / for commands, @ to add context",
"maxLength": 4000,
"sendAction": "submit_agent_prompt"
},
"children": []
}