# AI Elements

Patterns for agentic interfaces, built from WebJs UI components.

Source: https://webjs.dev/ui/docs/ai-elements

AI Elements are patterns for building agentic interfaces. Each one is a composition of WebJs UI components that you copy into your project. The code is yours.

A [Chat](https://webjs.dev/ui/docs/ai-elements/chat) is a list of [Message](https://webjs.dev/ui/docs/ai-elements/message) turns inside a [Message Scroller](https://webjs.dev/ui/docs/components/message-scroller). The steps an agent takes inside a turn, like [Reasoning](https://webjs.dev/ui/docs/ai-elements/reasoning), [Tool](https://webjs.dev/ui/docs/ai-elements/tool) and [Plan](https://webjs.dev/ui/docs/ai-elements/plan), are built on [Trace](https://webjs.dev/ui/docs/components/trace), so every step has the same shape.

**Building a chatbot?** Start from the [Chat](https://webjs.dev/ui/docs/ai-elements/chat) pattern. It puts Message Scroller, Message and Prompt Input together, and the [AI SDK](https://webjs.dev/ui/docs/helpers/ai-sdk) page shows how a `'use server'` action streams the reply into it, with tool calls and reasoning as parts.

**Coming from [elements.ai-sdk.dev](https://elements.ai-sdk.dev)?** See Migrating from AI SDK Elements.

## Patterns

- [Chain of Thought A summary that expands into the steps an agent took.](https://webjs.dev/ui/docs/ai-elements/chain-of-thought)
- [Chat The thread. Message Scroller keeps your place while the reply streams.](https://webjs.dev/ui/docs/ai-elements/chat)
- [Checkpoint A point in the conversation you can return to.](https://webjs.dev/ui/docs/ai-elements/checkpoint)
- [Confirmation A prompt to approve or deny a tool before it runs.](https://webjs.dev/ui/docs/ai-elements/confirmation)
- [Context How much of the context window the conversation has used.](https://webjs.dev/ui/docs/ai-elements/context)
- [File Tree The files the agent changed, as a folder tree.](https://webjs.dev/ui/docs/ai-elements/file-tree)
- [Inline Citation A source in the sentence that opens on hover.](https://webjs.dev/ui/docs/ai-elements/inline-citation)
- [Message One turn. The person's message, and the agent's reply with its actions.](https://webjs.dev/ui/docs/ai-elements/message)
- [Model Selector Two menus. One picks the model the agent runs, the other picks how hard it thinks.](https://webjs.dev/ui/docs/ai-elements/model-selector)
- [Plan The steps the agent plans to take, and how far it has got.](https://webjs.dev/ui/docs/ai-elements/plan)
- [Prompt Input A message field with attachments and a send button.](https://webjs.dev/ui/docs/ai-elements/prompt-input)
- [Queue The agent's todo list, split into what is left and what is done.](https://webjs.dev/ui/docs/ai-elements/queue)
- [Reasoning The agent's thinking as it streams.](https://webjs.dev/ui/docs/ai-elements/reasoning)
- [Sources The links the agent used for a reply.](https://webjs.dev/ui/docs/ai-elements/sources)
- [Stack Trace A failed tool call and its stack frames.](https://webjs.dev/ui/docs/ai-elements/stack-trace)
- [Subagent A subagent run, with its tool calls and result.](https://webjs.dev/ui/docs/ai-elements/subagent)
- [Suggestion A short prompt you can send to the agent in one click.](https://webjs.dev/ui/docs/ai-elements/suggestion)
- [Task The steps the agent takes, as it takes them.](https://webjs.dev/ui/docs/ai-elements/task)
- [Terminal A command the agent runs, with its output as it streams.](https://webjs.dev/ui/docs/ai-elements/terminal)
- [Test Results A test run by the agent, with its suites and failures.](https://webjs.dev/ui/docs/ai-elements/test-results)
- [Tool A tool call the agent makes, from input to output.](https://webjs.dev/ui/docs/ai-elements/tool)

## Migrating from AI SDK Elements

If you used AI SDK Elements from [elements.ai-sdk.dev](https://elements.ai-sdk.dev), here is what changes.

### Existing projects

When you installed components from elements.ai-sdk.dev, the code was copied into your project under `components/ai-elements`. In a WebJs app each of them is a pattern built from WebJs UI components, so moving to WebJs means rebuilding each one on those components.

Each pattern page has a **Migrating from AI SDK Elements** section that maps every export of the wrapper in `components/ai-elements` onto the parts of the pattern, so you can rebuild it on Trace, Code Block and the other WebJs UI components one export at a time.

For example, the [Queue](https://webjs.dev/ui/docs/ai-elements/queue#migrating-from-ai-sdk-elements) section rebuilds `queue.tsx` on Trace, and the [Inline Citation](https://webjs.dev/ui/docs/ai-elements/inline-citation#migrating-from-ai-sdk-elements) section rebuilds `inline-citation.tsx` on Hover Card.

### What replaces each element

Each file from AI SDK Elements, and the WebJs UI pattern or component that replaces it.

| AI SDK Elements | WebJs UI |
| --- | --- |
| `agent.tsx` | [Subagent](https://webjs.dev/ui/docs/ai-elements/subagent) |
| `attachments.tsx` | [Attachment](https://webjs.dev/ui/docs/components/attachment) |
| `chain-of-thought.tsx` | [Chain of Thought](https://webjs.dev/ui/docs/ai-elements/chain-of-thought) |
| `checkpoint.tsx` | [Checkpoint](https://webjs.dev/ui/docs/ai-elements/checkpoint) |
| `code-block.tsx` | [Code Block](https://webjs.dev/ui/docs/components/code-block) |
| `commit.tsx` | [Trace](https://webjs.dev/ui/docs/components/trace#commit) |
| `confirmation.tsx` | [Confirmation](https://webjs.dev/ui/docs/ai-elements/confirmation) |
| `context.tsx` | [Context](https://webjs.dev/ui/docs/ai-elements/context) |
| `conversation.tsx` | [Chat](https://webjs.dev/ui/docs/ai-elements/chat) |
| `file-tree.tsx` | [File Tree](https://webjs.dev/ui/docs/ai-elements/file-tree) |
| `inline-citation.tsx` | [Inline Citation](https://webjs.dev/ui/docs/ai-elements/inline-citation) |
| `message.tsx` | [Message](https://webjs.dev/ui/docs/ai-elements/message) |
| `model-selector.tsx` | [Model Selector](https://webjs.dev/ui/docs/ai-elements/model-selector) |
| `plan.tsx` | [Plan](https://webjs.dev/ui/docs/ai-elements/plan) |
| `prompt-input.tsx` | [Prompt Input](https://webjs.dev/ui/docs/ai-elements/prompt-input) |
| `question.tsx` | [Questionnaire](https://webjs.dev/ui/docs/components/questionnaire) |
| `queue.tsx` | [Queue](https://webjs.dev/ui/docs/ai-elements/queue) |
| `reasoning.tsx` | [Reasoning](https://webjs.dev/ui/docs/ai-elements/reasoning) |
| `shimmer.tsx` | [shimmer](https://webjs.dev/ui/docs/utils/shimmer) |
| `sources.tsx` | [Sources](https://webjs.dev/ui/docs/ai-elements/sources) |
| `stack-trace.tsx` | [Stack Trace](https://webjs.dev/ui/docs/ai-elements/stack-trace) |
| `suggestion.tsx` | [Suggestion](https://webjs.dev/ui/docs/ai-elements/suggestion) |
| `task.tsx` | [Task](https://webjs.dev/ui/docs/ai-elements/task) |
| `terminal.tsx` | [Terminal](https://webjs.dev/ui/docs/ai-elements/terminal) |
| `test-results.tsx` | [Test Results](https://webjs.dev/ui/docs/ai-elements/test-results) |
| `tool.tsx` | [Tool](https://webjs.dev/ui/docs/ai-elements/tool) |

### Elements without a replacement

Each of these elements is a small composition you can build from components WebJs UI already has, listed below.

If you need one of these, [open an issue](https://github.com/webjsdev/webjs/issues/new) and we will help you build it.

| AI SDK Elements | Build it with |
| --- | --- |
| `artifact.tsx` | [Card](https://webjs.dev/ui/docs/components/card), [Button](https://webjs.dev/ui/docs/components/button) and [Tooltip](https://webjs.dev/ui/docs/components/tooltip) |
| `audio-player.tsx` | An `audio` element, with [Button Group](https://webjs.dev/ui/docs/components/button-group) and [Slider](https://webjs.dev/ui/docs/components/slider) |
| `canvas.tsx`, `connection.tsx`, `controls.tsx`, `edge.tsx`, `node.tsx`, `panel.tsx` and `toolbar.tsx` | A graph library that renders to the DOM, with [Card](https://webjs.dev/ui/docs/components/card) and [Button Group](https://webjs.dev/ui/docs/components/button-group) |
| `environment-variables.tsx` | [Item](https://webjs.dev/ui/docs/components/item), [Badge](https://webjs.dev/ui/docs/components/badge) and [Switch](https://webjs.dev/ui/docs/components/switch) |
| `image.tsx` | An `img` element |
| `jsx-preview.tsx` | Not needed: WebJs templates are `html` tagged templates, not JSX |
| `mic-selector.tsx` and `voice-selector.tsx` | [Combobox](https://webjs.dev/ui/docs/components/combobox) |
| `open-in-chat.tsx` | [Dropdown Menu](https://webjs.dev/ui/docs/components/dropdown-menu) |
| `package-info.tsx` | [Item](https://webjs.dev/ui/docs/components/item) and [Badge](https://webjs.dev/ui/docs/components/badge) |
| `persona.tsx` | A [Rive](https://rive.app) animation |
| `sandbox.tsx` | [Trace](https://webjs.dev/ui/docs/components/trace), [Tabs](https://webjs.dev/ui/docs/components/tabs) and [Code Block](https://webjs.dev/ui/docs/components/code-block) |
| `schema-display.tsx` | [Collapsible](https://webjs.dev/ui/docs/components/collapsible), [Badge](https://webjs.dev/ui/docs/components/badge) and [Code Block](https://webjs.dev/ui/docs/components/code-block) |
| `snippet.tsx` | [Input Group](https://webjs.dev/ui/docs/components/input-group) |
| `speech-input.tsx` | [Button](https://webjs.dev/ui/docs/components/button) and [Spinner](https://webjs.dev/ui/docs/components/spinner), with the Web Speech API |
| `transcription.tsx` | A [Button](https://webjs.dev/ui/docs/components/button) for each segment, to seek to it |
| `web-preview.tsx` | An `iframe`, with [Input Group](https://webjs.dev/ui/docs/components/input-group) for the address bar |

### New projects

Build from WebJs UI components instead.

### Add the components

```bash
npx @webjsdev/ui add trace code-block
```

### Copy a pattern

Open a pattern above and copy its code into your project. Each page lists any other components it needs.

Or ask your coding agent to do it:

```text title="Prompt"
Add the Reasoning pattern from https://webjs.dev/ui/llm/docs/ai-elements/reasoning to my chat.
```

**Need another element?** [Open an issue](https://github.com/webjsdev/webjs/issues/new) and tell us what you need.
