ai-elements
它能做什么
它指导 AI 把基于 shadcn/ui 的 AI 聊天组件添加到 Next.js 项目中。适用于构建聊天机器人或 AI 助手界面的开发者。
适用场景
- ✓当你想在 Next.js 应用中构建聊天机器人或 AI 助手界面时。
- ✓当你需要聊天消息、工具输出或提示输入的现成组件时。
- ✓当你想把 AI Elements 添加到已使用 shadcn/ui 的项目中时。
技能链接
https://github.com/trycompai/crm/blob/release/.agents/skills/ai-elements/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请帮我在 Next.js 应用中添加一个聊天界面,包含消息气泡和提示输入框。”
每周 5 个新技能,1 分钟读完。
工作原理
AI 会使用与项目匹配的包运行器安装组件,把它们添加到项目中,并接入聊天界面。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
AI Elements
AI Elements is a component library and custom registry built on top of shadcn/ui to help you build AI-native applications faster. It provides pre-built components like conversations, messages and more.
Installing AI Elements is straightforward and can be done in a couple of ways. You can use the dedicated CLI command for the fastest setup, or integrate via the standard shadcn/ui CLI if you've already adopted shadcn's workflow.
IMPORTANT: Run all CLI commands using the project's package runner:
npx ai-elements@latest,pnpm dlx ai-elements@latest, orbunx --bun ai-elements@latest— based on the project'spackageManager. Examples below usenpx ai-elements@latestbut substitute the correct runner for the project.
Prerequisites
Before installing AI Elements, make sure your environment meets the following requirements:
- Node.js, version 18 or later
- A Next.js project with the AI SDK installed.
- shadcn/ui installed in your project. If you don't have it installed, running any install command will automatically install it for you.
- We also highly recommend using the AI Gateway and adding
AI_GATEWAY_API_KEYto yourenv.localso you don't have to use an API key from every provider. AI Gateway also gives $5 in usage per month so you can experiment with models. You can obtain an API key here.
Installing Components
You can install AI Elements components using either the AI Elements CLI or the shadcn/ui CLI. Both achieve the same result: adding the selected component’s code and any needed dependencies to your project.
The CLI will download the component’s code and integrate it into your project’s directory (usually under your components folder). By default, AI Elements components are added to the @/components/ai-elements/ directory (or whatever folder you’ve configured in your shadcn components settings).
After running the command, you should see a confirmation in your terminal that the files were added. You can then proceed to use the component in your code.
Usage
Once an AI Elements component is installed, you can import it and use it in your application like any other React component. The components are added as part of your codebase (not hidden in a library), so the usage feels very natural.
Example
After installing AI Elements components, you can use them in your application like any other React component. For example:
"use client";
import {
Message,
MessageContent,
MessageResponse,
} from "@/components/ai-elements/message";
import { useChat } from "@ai-sdk/react";
const Example = () => {
const { messages } = useChat();
return (
<>
{messages.map(({ role, parts }, index) => (
<Message from={role} key={index}>
<MessageContent>
{parts.map((part, i) => {
switch (part.type) {
case "text":
return (
<MessageResponse key={`${role}-${i}`}>
{part.text}
</MessageResponse>
);
}
})}
</MessageContent>
</Message>
))}
</>
);
};
export default Example;
In the example above, we import the Message component from our AI Elements directory and include it in our JSX. Then, we compose the component with the MessageContent and MessageResponse subcomponents. You can style or configure the component just as you would if you wrote it yourself – since the code lives in your project, you can even open the component file to see how it works or make custom modifications.
Extensibility
All AI Elements components take as many primitive attributes as possible. For example, the Message component extends HTMLAttributes<HTMLDivElement>, so you can pass any props that a div supports. This makes it easy to extend the component with your own styles or functionality.
Customization
After installation, no additional setup is needed. The component’s styles (Tailwind CSS classes) and scripts are already integrated. You can start interacting with the component in your app immediately.
For example, if yo
常见问题
它需要先具备什么?
该技能列出 Node.js 18 或更新版本、带有 AI SDK 的 Next.js 项目,以及 shadcn/ui。
它使用哪个包运行器?
它使用与项目匹配的运行器,例如 npx、pnpm dlx 或 bunx。
它推荐 AI 网关吗?
推荐。它建议使用 AI Gateway,并把其 API 密钥添加到本地环境文件中。
详情
作者的原始描述
Build AI chat interfaces using ai-elements components — conversations, messages, tool displays, prompt inputs, and more. Use when the user wants to build a chatbot, AI assistant UI, or any AI-powered chat interface.
repo: trycompai/crm
热度
- GitHub 星标
- 12k
- 排名
- #11506
- 许可证
- MIT
- 更新时间
- 2026/11/1
评论
- …
同一仓库的更多技能
ai-sdk
12k帮你的智能体使用 Vercel AI SDK 构建 AI 功能,包括文本生成、流式输出、工具调用和智能体。
better-accessibility
12k帮你的智能体让界面可以通过键盘和屏幕阅读器使用,涵盖焦点、标签、ARIA 和表单。
better-auth-best-practices
12k帮你的智能体按照官方文档步骤,在 TypeScript 应用中设置 Better Auth,实现登录、会话、OAuth 和插件。
better-colors
12k帮你的智能体为网页界面转换、选择和检查颜色,包括 OKLCH 调色板、对比度和深色模式。