A streamed answer that shows its work: what the assistant searched, the sources it read, numbered citations that preview their source, and copy, regenerate, feedback and follow-ups.
On this page
Used for
- Streamed answer card
- Cited search reply
- Answer with sources
- Collect thumbs feedback
- Offer follow-up questions
Examples
Installation
npx knowns-ui@latest add ai-answerFor 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 AI answer 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/ai-answer
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 ai-answer
```
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
- components/ui/knowns/spinner.tsx
- components/ui/knowns/button.tsx
- 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/ai-answer/ai-answer.tsx
- components/ui/knowns/ai-answer/ai-answer-utils.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/ai-answer, 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: "ai-answer" }) 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.Answer text
- Paragraphs
blank line- A blank line starts a new paragraph.
- Lists
"- " at line start- Consecutive lines become one list.
- Bold, code
**bold** · `code`- Unclosed markers while streaming are fine - they run to the end.
- Citations
[1] · [1, 3]- 1-based indexes into sources. A citation still being typed is hidden until it closes.
| Prop | Type | Default | Description |
|---|---|---|---|
| Paragraphs | blank line | - | A blank line starts a new paragraph. |
| Lists | "- " at line start | - | Consecutive lines become one list. |
| Bold, code | **bold** · `code` | - | Unclosed markers while streaming are fine - they run to the end. |
| Citations | [1] · [1, 3] | - | 1-based indexes into sources. A citation still being typed is hidden until it closes. |
Props
- text
string- The answer. May grow while streaming; a text that no longer continues the old one starts over.
- status
"thinking"|"streaming"|"done"|"stopped"|"error"- Default
"done" - Thinking shows placeholders and “Reading N sources”; streaming keeps the caret going.
- sources
AnswerSource[]- Default
[] - { title, site, url?, icon?, excerpt? }. Three fit the row, the rest fold into “+N more”.
- steps
AnswerStep[]- { label, state } - what the assistant did. Collapsed to one line, expandable.
- question
string- Title above everything.
- suggestions / onSuggestion
string[] / (q) => void- Follow-up questions shown once the answer is complete.
- onRegenerate / onStop / onCopy
callbacks- Regenerate and copy after the answer; Stop while it is thinking or streaming.
- onFeedback
(rating, reason?) => void- Good, or bad with one of feedbackReasons.
- reveal / wordsPerSecond
boolean / number- Default
true / 42 - Smooth word-by-word reveal; off under reduced motion.
- card
boolean- Default
true - On its own card, or blended into the surrounding thread.
- meta
ReactNode- Small text at the end of the action row, e.g. “Answered in 3.4s”.
| Prop | Type | Default | Description |
|---|---|---|---|
| text | string | - | The answer. May grow while streaming; a text that no longer continues the old one starts over. |
| status | "thinking" | "streaming" | "done" | "stopped" | "error" | "done" | Thinking shows placeholders and “Reading N sources”; streaming keeps the caret going. |
| sources | AnswerSource[] | [] | { title, site, url?, icon?, excerpt? }. Three fit the row, the rest fold into “+N more”. |
| steps | AnswerStep[] | - | { label, state } - what the assistant did. Collapsed to one line, expandable. |
| question | string | - | Title above everything. |
| suggestions / onSuggestion | string[] / (q) => void | - | Follow-up questions shown once the answer is complete. |
| onRegenerate / onStop / onCopy | callbacks | - | Regenerate and copy after the answer; Stop while it is thinking or streaming. |
| onFeedback | (rating, reason?) => void | - | Good, or bad with one of feedbackReasons. |
| reveal / wordsPerSecond | boolean / number | true / 42 | Smooth word-by-word reveal; off under reduced motion. |
| card | boolean | true | On its own card, or blended into the surrounding thread. |
| meta | ReactNode | - | Small text at the end of the action row, e.g. “Answered in 3.4s”. |
Accessibility
The answer is marked
aria-busy while it streams, so screen readers read it once. Citations are buttons named after their source; their preview is a tooltip that also opens on focus and closes with Escape. Copy and feedback are announced in a polite live region. With reduced motion the text appears at once.What it handles
- 01Renders the text prop as paragraphs, dash lists, bold, inline code and numbered citations like [1] or [1, 3] that point at your sources.
- 02Reveals words at wordsPerSecond, 42 by default, and copes with half-streamed text by hiding an unfinished citation and closing an open bold or code span.
- 03Shows a preview card with the title, site and snippet when you hover or focus a citation, and Escape closes it.
- 04Moves through thinking, streaming, done, stopped and error through status, with a skeleton while thinking and a Stop button when you pass onStop.
- 05Lists what the assistant did as a collapsible steps list, and shows source pills before the text.
- 06Ends with Copy, Regenerate and thumbs, where a thumbs down asks "What was wrong?" with your feedbackReasons, and then follow-up suggestions.
States
- First render
- Nothing. A finished answer paints whole
- none
- Each new word
- It fades in as it streams
- 280ms, ease out
- Actions and reasons appear
- The row rises into place
- 180ms, ease out
- Citation preview opens
- The card rises under the citation
- 120ms, ease out
- Steps fold
- The chevron turns a quarter turn
- 180ms, ease out
- Skeleton and cursor
- They pulse while the answer waits
- none
- Reduced motion
- Text appears whole, with no word fade
- 0ms
| State | What moves | Timing |
|---|---|---|
| First render | Nothing. A finished answer paints whole | none |
| Each new word | It fades in as it streams | 280ms, ease out |
| Actions and reasons appear | The row rises into place | 180ms, ease out |
| Citation preview opens | The card rises under the citation | 120ms, ease out |
| Steps fold | The chevron turns a quarter turn | 180ms, ease out |
| Skeleton and cursor | They pulse while the answer waits | none |
| Reduced motion | Text appears whole, with no word fade | 0ms |
Works with
- SpinnerInstalled with it. Shows while a Regenerate or thinking step is pending.
- TooltipInstalled with it. Labels the Copy, Regenerate and thumbs buttons.
- Thinking statePairs with it: show the thinking steps above, then stream the answer here.
- Message actionsPairs with it: use it when the action row lives outside the answer card.
When to use
When to use
- Rendering a model's reply with sources, numbered citations that preview their source, and copy, regenerate and feedback actions.
- Search-style answers where users need to check where a claim came from.
When not to use
- The agent's steps before it answers: use Thinking State.
- A whole chat screen with sidebar and composer: use Chat App.
- Short system messages or errors: a plain message or a toast reads better: use Toast.
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 AI Answer to my app and wire it to my own data.
- I need rendering a model's reply with sources, numbered citations that preview their source, and copy, regenerate and feedback actions. Set that up with the Knowns UI AI Answer.
- Which AI Answer props do I need for a minimal setup? Show me a short example.
With the server connected, your assistant calls get_component({ name: "ai-answer" }) and search_docs({ query: "ai answer" }).