The input of an agent: write, attach, pick a model and how much it may do on its own, connect apps - then send.
On this page
Used for
- Prompt box for agents
- Attach files to a prompt
- Pick a model
- Set permission mode
- Dictate a message
Examples
Width
Installation
npx knowns-ui@latest add chat-composerFor Claude Code, Cursor or Codex: installs it and wires the props to your own data.
Paste this into your coding agent (Claude Code, Cursor, Codex). It checks your project, sets up the registry, runs the install and verifies it.
Install prompt
Install Chat composer from Knowns UI into this project. Work step by step, show me each change, and ask before you edit files outside this project.
Context: Knowns UI (https://ui.knowns.dev) is a shadcn registry. Items land in the project as source files. Docs: https://ui.knowns.dev/docs/chat-composer
1. Check the project first. Stop and tell me if any of these is missing:
- React 19 and Tailwind CSS v4.
- A components.json at the project root. If there is none, ask me before running `npx knowns-ui@latest init --no-key` (it runs shadcn init when needed, then adds the registries).
2. Run:
```bash
npx knowns-ui@latest add chat-composer
```
It writes these files:
- lib/knowns/run.ts
- lib/knowns/json.tsx
- lib/knowns/status.ts
- lib/knowns/tone.ts
- lib/knowns/types.ts
- lib/knowns/use-abortable.ts
- lib/knowns/utils.ts
- lib/knowns/icons/actor-icon.tsx
- lib/knowns/icons/model-icons.tsx
- lib/knowns/icons/tool-icons.tsx
- lib/knowns/icons/model-icons.data.ts
- lib/knowns/icons/tool-icons.data.ts
- lib/knowns/icons/LICENSES.md
- lib/knowns/motion.tsx
- lib/knowns/motion-utils.ts
- components/ui/knowns/use-floating.ts
- components/ui/knowns/tooltip.tsx
- components/ui/knowns/tooltip-utils.ts
- components/ui/knowns/avatar.tsx
- components/ui/knowns/spinner.tsx
- components/ui/knowns/button.tsx
- components/ui/knowns/menu.tsx
- components/ui/knowns/chat-composer/chat-composer.tsx
- components/ui/knowns/chat-composer/composer-utils.ts
- components/ui/knowns/chat-composer/use-autosize.ts
and installs these npm packages: clsx@^2.1.1, tailwind-merge@^3.7.0, class-variance-authority@^0.7.1.
3. While it runs:
- It also adds a few @keyframes (all named kn-*) to the global CSS file (globals.css or the file components.json points at). Let it: they only add animations.
- If it asks to overwrite files under lib/knowns/: these are shared by every Knowns UI item. List them, say whether I changed them (check git), and ask me before you answer.
- If it asks to overwrite any other file, show me the diff and ask me.
4. Verify:
- Every file in the list above exists.
- The project type-checks (for example `npx tsc --noEmit`) and the dev build has no new errors.
5. Use it: follow the examples and props on https://ui.knowns.dev/docs/chat-composer, and ask me if anything about my data is unclear.
If the Knowns UI MCP server is connected (https://ui.knowns.dev/docs/ai-and-mcp), use get_component({ name: "chat-composer" }) or search_docs for details.
Finish with a short summary: the files you added or changed, the packages you installed, and anything I still need to do.Props
- onSubmit
(message: ComposerMessage) => void- Enter or the send button. Gets { text, model, mode, attachments, apps, folder }; clears the text and attachments after.
- value / defaultValue / onValueChange
string / string / (v) => void- Default
"" - The text, controlled or not.
- placeholder
string- Default
"Ask anything…" - Shown while empty.
- busy / onStop
boolean / () => void- Default
false - While busy the send button becomes Stop and a light band travels around the card border, fading in and out with the state. Reduced motion shows a still accent ring. Tint it with --kn-accent.
- models
ComposerModel[]- Default
built-in list - { id, name, detail?, icon? }. Without an icon, the provider logo is picked from the name.
- model / defaultModel / onModelChange
string / string / (id) => void- Default
first model - The chosen model.
- mode / defaultMode / onModeChange
"ask"|"auto"|"full"- Default
"ask" - How much the agent may do on its own: Ask before acting, Auto-approve safe actions, Full access.
- attachments / onAttachmentsChange
ComposerAttachment[] / (a) => void- Default
[] - { id, name, kind?, size?, progress? } shown as removable tiles above the text. Tiles land one by one; progress (0 to 1) fills a thin bar until it reaches 1.
- onAttach
(kind: "file" | "image" | "folder" | "link") => void- The + menu: Upload a file, Add an image, Attach a folder, Paste a link. Open your picker and add the result to attachments.
- apps
ComposerApp[]- Default
built-in list - { id, name, icon? } the agent can be connected to. Without an icon, the brand logo is picked from the name. [] hides the apps menu.
- connectedApps / defaultConnectedApps / onConnectedAppsChange
string[] / string[] / (ids) => void- Default
["chat"] - Ids of the apps that are on.
- folders
string[]- Default
built-in list - Working folders offered in the bottom row. [] hides the folder picker.
- folder / defaultFolder / onFolderChange
string|null / string|null / (f) => void- Default
null - The working folder; null is none.
- dictation
{ listening, transcript?, onToggle }- Shows the mic. You run speech recognition; the live transcript is shown while listening.
- footer
ReactNode|false- Replace the bottom row, or false to hide it.
- maxRows
number- Default
8 - The text area grows up to this many rows, then scrolls.
- disabled
boolean- Default
false - Disables the whole composer.
- className
string- On the outer element.
| Prop | Type | Default | Description |
|---|---|---|---|
| onSubmit | (message: ComposerMessage) => void | - | Enter or the send button. Gets { text, model, mode, attachments, apps, folder }; clears the text and attachments after. |
| value / defaultValue / onValueChange | string / string / (v) => void | "" | The text, controlled or not. |
| placeholder | string | "Ask anything…" | Shown while empty. |
| busy / onStop | boolean / () => void | false | While busy the send button becomes Stop and a light band travels around the card border, fading in and out with the state. Reduced motion shows a still accent ring. Tint it with --kn-accent. |
| models | ComposerModel[] | built-in list | { id, name, detail?, icon? }. Without an icon, the provider logo is picked from the name. |
| model / defaultModel / onModelChange | string / string / (id) => void | first model | The chosen model. |
| mode / defaultMode / onModeChange | "ask" | "auto" | "full" | "ask" | How much the agent may do on its own: Ask before acting, Auto-approve safe actions, Full access. |
| attachments / onAttachmentsChange | ComposerAttachment[] / (a) => void | [] | { id, name, kind?, size?, progress? } shown as removable tiles above the text. Tiles land one by one; progress (0 to 1) fills a thin bar until it reaches 1. |
| onAttach | (kind: "file" | "image" | "folder" | "link") => void | - | The + menu: Upload a file, Add an image, Attach a folder, Paste a link. Open your picker and add the result to attachments. |
| apps | ComposerApp[] | built-in list | { id, name, icon? } the agent can be connected to. Without an icon, the brand logo is picked from the name. [] hides the apps menu. |
| connectedApps / defaultConnectedApps / onConnectedAppsChange | string[] / string[] / (ids) => void | ["chat"] | Ids of the apps that are on. |
| folders | string[] | built-in list | Working folders offered in the bottom row. [] hides the folder picker. |
| folder / defaultFolder / onFolderChange | string | null / string | null / (f) => void | null | The working folder; null is none. |
| dictation | { listening, transcript?, onToggle } | - | Shows the mic. You run speech recognition; the live transcript is shown while listening. |
| footer | ReactNode | false | - | Replace the bottom row, or false to hide it. |
| maxRows | number | 8 | The text area grows up to this many rows, then scrolls. |
| disabled | boolean | false | Disables the whole composer. |
| className | string | - | On the outer element. |
Keyboard
| Keys | Where | Does |
|---|---|---|
| Enter | Text | Send. |
| ShiftEnter | Text | New line. |
| ⌘ / CtrlEnter | Text | Send. |
| EnterSpace↓ | Menu button | Open the menu and focus its first item. |
| ↑↓HomeEnd | Open menu | Move between items. |
| Esc | Anywhere | Close the open menu, or stop dictation. |
Accessibility
The text area has a label, and every icon button has a name and a tooltip. The +, mode and apps buttons open menus, the model and folder buttons open single-choice lists; each reports whether it is open. They move focus with the arrow keys and give it back to their button when they close. Attachment chips have a remove button named after the file. While busy, the send button becomes a Stop button with its own name, and the mic button is pressed while listening.
What it handles
- 01Grows the textarea with its text up to maxRows, 8 by default, and then scrolls inside it.
- 02Sends on Enter and breaks the line on Shift+Enter, ignores Enter while an input method is composing, then clears the text and attachments.
- 03Turns the send button into Stop while busy is true and calls onStop, and draws a travelling light around the border while the agent works.
- 04Adds attachment tiles of file, image, folder or link kind with size and an upload bar that fills to 1, and removing one collapses it.
- 05Offers a model picker, an ask, auto or full permission mode, connected apps and a working folder, each as a controlled or uncontrolled value.
- 06Takes dictation from your own state, shows the transcript muted under the text, and stops listening on Escape.
States
- First render
- Nothing. It paints as it is
- none
- Agent starts working
- A light fades in around the card border
- 280ms, ease out
- Agent stops
- The light fades out
- 180ms, ease out
- Attachment added
- The tile rises in, up to 4 steps of 40ms apart
- 180ms, ease out
- Attachment removed
- The tile collapses and fades
- 120ms, ease out
- Upload progress
- The bar along the tile fills
- 280ms, ease out
- Mode or send label changes
- The new label fades in
- 180ms, ease out
- Reduced motion
- Light, tiles and labels change at once
- 0ms
| State | What moves | Timing |
|---|---|---|
| First render | Nothing. It paints as it is | none |
| Agent starts working | A light fades in around the card border | 280ms, ease out |
| Agent stops | The light fades out | 180ms, ease out |
| Attachment added | The tile rises in, up to 4 steps of 40ms apart | 180ms, ease out |
| Attachment removed | The tile collapses and fades | 120ms, ease out |
| Upload progress | The bar along the tile fills | 280ms, ease out |
| Mode or send label changes | The new label fades in | 180ms, ease out |
| Reduced motion | Light, tiles and labels change at once | 0ms |
Works with
When to use
When to use
- The input for an agent: autosizing text, attachments, model and permission menus, dictation, send and stop.
- Any screen where the user writes a prompt that may run for a while and needs a stop button.
When not to use
- A plain single-line search or form field: use Input.
- Picking a model on its own, outside the composer: use Model Picker.
- Saved prompts with blanks to fill in: use Prompt Templates.
Using with AI
Use Copy page for AI above to give your assistant this page, Copy prompt under the install command to have it installed and wired to your data, or connect the Knowns UI MCP server and just ask:
- Add the Knowns UI Chat Composer to my app and wire it to my own data.
- I need the input for an agent: autosizing text, attachments, model and permission menus, dictation, send and stop. Set that up with the Knowns UI Chat Composer.
- Which Chat Composer props do I need for a minimal setup? Show me a short example.
With the server connected, your assistant calls get_component({ name: "chat-composer" }) and search_docs({ query: "chat composer" }).