elements
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chineseassistant-ui Elements
assistant-ui 元素
Always consult assistant-ui.com/llms.txt for the latest API.
Elements are the styled, copy-into-your-project components that sit on top of the unstyled primitives. Every element is a TSX file the CLI copies into , so you own the source and customize it in place. The catalog at assistant-ui.com/elements documents each one with a live demo, a runtime recipe, and a standalone recipe.
components/assistant-ui/elements/请务必查阅assistant-ui.com/llms.txt获取最新API。
元素是基于无样式基础组件(primitives)构建的、可复制到你的项目中的带样式组件。每个元素都是一个TSX文件,由CLI复制到目录下,因此你拥有源码所有权并可在原地自定义。assistant-ui.com/elements上的组件库为每个元素提供了实时演示、运行时使用示例和独立使用示例。
components/assistant-ui/elements/References
参考文档
- ./references/catalog.md -- every element by section with its registry item and installed file
- ./references/aui-elements.md -- the runtime-connected elements (Thread, ThreadList, AssistantModal, AssistantSidebar, ToolFallback, ToolGroup, Reasoning, Sources, Attachment, ModelSelector, Voice, McpConfig, and the renderers)
- ./references/standalone-elements.md -- props-driven elements grouped by section, with the prop shapes that matter
- ./references/catalog.md —— 按分类列出所有元素及其注册表项和安装后的文件
- ./references/aui-elements.md —— 连接运行时的元素(Thread、ThreadList、AssistantModal、AssistantSidebar、ToolFallback、ToolGroup、Reasoning、Sources、Attachment、ModelSelector、Voice、McpConfig以及渲染器)
- ./references/standalone-elements.md —— 按分类分组的基于props的元素,包含关键的props结构
Two kinds of element
两种类型的元素
| Kind | File | Needs a runtime | Registry item |
|---|---|---|---|
| Runtime-connected | | Yes, reads the nearest | short name: |
| Standalone | | No, everything comes in through props | |
| Renderer | | Used from a | |
A few elements exist in both forms. installs the runtime-connected sidebar list and installs the props-driven one; the same split applies to , , , , , , (the orb), (), (), and (). Pick when the data is already in the thread; pick standalone when you render from your own state, a tool result, or a design mock.
thread-listelements-thread-listreasoningsourcestool-groupmodel-selectormessage-timingcontext-displayvoiceattachmentelements-message-attachmentquoteelements-quote-replyfollow-up-suggestionselements-suggestions.aui| 类型 | 文件 | 需要运行时 | 注册表项 |
|---|---|---|---|
| 连接运行时 | | 是,读取最近的 | 短名称: |
| 独立型 | | 否,所有数据通过props传入 | |
| 渲染器 | | 从 | |
部分元素同时存在两种形式。安装的是连接运行时的侧边栏列表,安装的是基于props的版本;同样的区分适用于、、、、、、(悬浮球)、()、()和()。当数据已存在于线程中时,选择版本;当你需要从自有状态、工具结果或设计原型渲染时,选择独立型版本。
thread-listelements-thread-listreasoningsourcestool-groupmodel-selectormessage-timingcontext-displayvoiceattachmentelements-message-attachmentquoteelements-quote-replyfollow-up-suggestionselements-suggestions.auiInstall
安装
bash
npx assistant-ui@latest init # once per project: components.json, style, base elements
npx assistant-ui@latest add thread thread-list
npx assistant-ui@latest add elements-agent-plan elements-code-diffaddnpx shadcn@latest addthreadmarkdown-texttool-fallbacktool-groupreasoningsourcesattachmentimagefilefollow-up-suggestionstooltip-icon-button@assistant-ui/reactlucide-reacttw-shimmerelements-surfacesWithout a the CLI warns and installs the Base UI flavor. To let the shadcn CLI resolve elements directly, register the style-aware URL:
components.jsonjson
{
"registries": {
"@assistant-ui": "https://r.assistant-ui.com/styles/{style}/{name}.json"
}
}Then works too. Styles named receive the Base UI flavor; every other style receives Radix. Most elements compose only primitives and ship one source for both; the ones that touch library-specific surfaces (, , , , , , , , and the shared , , , , ) have a dedicated Base UI variant. The plain URL stays a Radix fallback.
npx shadcn@latest add @assistant-ui/threadbase-*@assistant-ui/reacttooltip-icon-buttonattachmentcontext-displaymessage-timingmcp-configthreadlist-sidebarassistant-modalmodel-selectorselecttabsaccordionbadgedirectionhttps://r.assistant-ui.com/{name}.jsonbash
npx assistant-ui@latest init # 每个项目执行一次:生成components.json、样式文件、基础元素
npx assistant-ui@latest add thread thread-list
npx assistant-ui@latest add elements-agent-plan elements-code-diffaddnpx shadcn@latest addthreadmarkdown-texttool-fallbacktool-groupreasoningsourcesattachmentimagefilefollow-up-suggestionstooltip-icon-button@assistant-ui/reactlucide-reacttw-shimmerelements-surfaces如果没有,CLI会发出警告并安装Base UI风格。要让shadcn CLI直接解析元素,请注册感知样式的URL:
components.jsonjson
{
"registries": {
"@assistant-ui": "https://r.assistant-ui.com/styles/{style}/{name}.json"
}
}之后也可以正常使用。名称为的样式会使用Base UI风格;其他所有样式都使用Radix风格。大多数元素仅基于基础组件构建,并且为两种风格提供同一源码;那些涉及库特定界面的元素(、、、、、、、以及共享的、、、、)有专门的Base UI变体。普通的 URL会作为Radix风格的 fallback。
npx shadcn@latest add @assistant-ui/threadbase-*@assistant-ui/reacttooltip-icon-buttonattachmentcontext-displaymessage-timingmcp-configthreadlist-sidebarassistant-modalmodel-selectorselecttabsaccordionbadgedirectionhttps://r.assistant-ui.com/{name}.jsonUse a runtime-connected element
使用连接运行时的元素
tsx
"use client";
import { AssistantRuntimeProvider } from "@assistant-ui/react";
import { useChatRuntime } from "@assistant-ui/ai-sdk";
import { Thread } from "@/components/assistant-ui/elements/thread.aui";
import { ThreadList } from "@/components/assistant-ui/elements/thread-list.aui";
export default function Chat() {
const runtime = useChatRuntime();
return (
<AssistantRuntimeProvider runtime={runtime}>
<div className="flex h-dvh">
<ThreadList />
<Thread />
</div>
</AssistantRuntimeProvider>
);
}Threadtsx
"use client";
import { AssistantRuntimeProvider } from "@assistant-ui/react";
import { useChatRuntime } from "@assistant-ui/ai-sdk";
import { Thread } from "@/components/assistant-ui/elements/thread.aui";
import { ThreadList } from "@/components/assistant-ui/elements/thread-list.aui";
export default function Chat() {
const runtime = useChatRuntime();
return (
<AssistantRuntimeProvider runtime={runtime}>
<div className="flex h-dvh">
<ThreadList />
<Thread />
</div>
</AssistantRuntimeProvider>
);
}ThreadOverride a slot instead of forking the file
覆盖插槽而非修改文件
tsx
import { Thread, type ThreadComponents } from "@/components/assistant-ui/elements/thread.aui";
const THREAD_COMPONENTS: ThreadComponents = {
Welcome: () => <h1 className="text-2xl">Ask me anything</h1>,
ToolFallback: MyToolFallback,
};
export function Chat() {
return <Thread components={THREAD_COMPONENTS} autoFocus={false} />;
}Slots: , , , , . Define the object at module scope or memoize it, otherwise every parent render remounts the message subtrees. For per-tool UI, register on the toolkit entry (see tools) rather than overriding ; a tool UI registered by name wins over the slot.
AssistantMessageWelcomeToolFallbackToolGroupReasoningGrouprenderToolFallbacktsx
import { Thread, type ThreadComponents } from "@/components/assistant-ui/elements/thread.aui";
const THREAD_COMPONENTS: ThreadComponents = {
Welcome: () => <h1 className="text-2xl">Ask me anything</h1>,
ToolFallback: MyToolFallback,
};
export function Chat() {
return <Thread components={THREAD_COMPONENTS} autoFocus={false} />;
}插槽包括:、、、、。请在模块作用域定义该对象或使用缓存,否则父组件每次渲染都会重新挂载消息子树。如需为特定工具设置UI,请在工具包条目上注册方法(参见tools),而不是覆盖;按名称注册的工具UI优先级高于插槽。
AssistantMessageWelcomeToolFallbackToolGroupReasoningGroupuseMemorenderToolFallbackRestyle
重新样式化
Thread--thread-max-width--composer-bg--composer-radius--composer-paddingThreadPrimitive.Rootthread.aui.tsxThreadThreadPrimitive.Root--thread-max-width--composer-bg--composer-radius--composer-paddingthread.aui.tsxUse a standalone element
使用独立型元素
tsx
import { AgentPlan } from "@/components/assistant-ui/elements/agent-plan";
<AgentPlan
steps={["Read the schema", "Write the migration", "Run the tests"]}
activeIndex={1}
/>;Standalone elements take plain props (here and , plus any props) and never read runtime state, so they work in a tool , in a dashboard, or in Storybook. Each catalog page's "Standalone" tab shows the exact prop shape; the standalone reference summarizes the ones you will reach for most.
steps: readonly string[]activeIndex: numberdivrendertsx
import { AgentPlan } from "@/components/assistant-ui/elements/agent-plan";
<AgentPlan
steps={["Read the schema", "Write the migration", "Run the tests"]}
activeIndex={1}
/>;独立型元素接受普通props(此处为和,以及任何的props),并且从不读取运行时状态,因此它们可以在工具的方法、仪表板或Storybook中使用。每个组件库页面的“Standalone”标签页显示了确切的props结构;独立元素参考文档总结了你最常用的那些props。
steps: readonly string[]activeIndex: numberdivrenderShared surface tokens
共享界面令牌
elements-surfacescomponents/assistant-ui/elements/surfaces.tsxpaperfloatingfieldfieldInteractivepressableghostButtoninkButtonmonoliveiconSwaplabelSwapcollapsePanelcodeScrollcodeSurfaceShimmerLabelSwapLabelcn(...)@/lib/utilslib/utils.tselements-surfacescomponents/assistant-ui/elements/surfaces.tsxpaperfloatingfieldfieldInteractivepressableghostButtoninkButtonmonoliveiconSwaplabelSwapcollapsePanelcodeScrollcodeSurfaceShimmerLabelSwapLabel@/lib/utilscn(...)lib/utils.tsCommon Gotchas
常见问题
Cannot find module '@/components/assistant-ui/thread'- Elements moved under and runtime-connected files carry the
elements/suffix:.aui. Renderers and standalone elements have no suffix.@/components/assistant-ui/elements/thread.aui
Element renders but looks unstyled
- The registry assumes Tailwind v4 and the shadcn theme variables in (
globals.cssplus the@import "tailwindcss",--background,--foregroundfamily).--borderwrites them; in a hand-rolled project copy them from anpx assistant-ui@latest initscaffold.create
CLI installed the wrong flavor
- reads the
addfield ofstyle;components.jsonstyles get Base UI, anything else gets Radix. Fix the style, then re-add withbase-*.--overwrite
Thread re-renders every message on each parent render
- The prop object was created inline. Hoist it to module scope or
components.useMemo
A element throws about a missing provider
.aui- It must be a descendant of (or an
AssistantRuntimeProviderwhose config supplies the scope it reads). Standalone elements have no such requirement.AuiProvider
Registry item not found
- Runtime-connected and renderer items use the short name (,
thread); standalone items are prefixed (markdown-text). The catalog lists the exact item per element.elements-agent-plan
Cannot find module '@/components/assistant-ui/thread'- 元素已移至目录下,连接运行时的文件带有
elements/后缀:.aui。渲染器和独立型元素没有后缀。@/components/assistant-ui/elements/thread.aui
元素已渲染但无样式
- 注册表默认使用Tailwind v4和中的shadcn主题变量(
globals.css加上@import "tailwindcss"、--background、--foreground系列变量)。--border会生成这些内容;如果是手动搭建的项目,请从npx assistant-ui@latest init脚手架中复制这些内容。create
CLI安装了错误的风格
- 命令会读取
add中的components.json字段;style样式会安装Base UI风格,其他样式会安装Radix风格。修改style字段后,使用base-*参数重新添加。--overwrite
Thread在父组件每次渲染时都会重新渲染所有消息
- 属性对象是在内部创建的。请将其提升到模块作用域或使用
components缓存。useMemo
.aui- 它必须是(或提供其读取范围的
AssistantRuntimeProvider)的后代元素。独立型元素没有此要求。AuiProvider
未找到注册表项
- 连接运行时的元素和渲染器使用短名称(、
thread);独立型元素带有前缀(markdown-text)。组件库目录列出了每个元素对应的准确注册表项。elements-agent-plan
Related Skills
相关技能
- primitives -- the unstyled building blocks the elements compose
.aui - setup -- ,
create, and the rest of the CLIinit - tools -- toolkit entries that replace
renderper toolToolFallback - generative-ui -- the renderer and the component vocabulary
generative-ui - markdown -- ,
markdown-text,shiki-highlighter,syntax-highlightermermaid-diagram - thread-list -- ,
thread-list,threadlist-sidebar,thread-searchconversation-map
- primitives —— 元素所基于的无样式基础组件
.aui - setup —— 、
create以及CLI的其他功能init - tools —— 工具包中用于按工具替换的
ToolFallback条目render - generative-ui —— 渲染器和组件词汇表
generative-ui - markdown —— 、
markdown-text、shiki-highlighter、syntax-highlightermermaid-diagram - thread-list —— 、
thread-list、threadlist-sidebar、thread-searchconversation-map