* feat: Add File Upload with PromptAttachments and PromptForm Components (#76) * feat: Add PromptInputActionMenu for granular action dropdowns * feat: Implement PromptForm and PromptAttachments components for file attachment handling * refactor: Integrate PromptForm with PromptInput for enhanced submission handling and attachment support * docs: Update README files to include new components PromptForm and PromptInputAttachments * refactor: Refactor useAttachment hook for better DX * feat: Add Chat context visualization component (#75) * feat: add context component to visualise model context usage * chore: update README and package.json to include context component in documentation and description * feat: integrate context component into example files for enhanced token visualization * fix: update title for ContextIcon to improve accessibility * refactor: remove title element from ContextIcon for cleaner code * fix: add className prop to button in Context for improved styling flexibility * fix: apply minHeight and maxHeight props in PromptInputTextarea (#40) * fix: apply minHeight and maxHeight props in PromptInputTextarea * style: revert unintended quote changes * Switch to pure CSS --------- Co-authored-by: Hayden Bleasel <hello@haydenbleasel.com> * feat: add MessageContent variants (#37) * feat: add variants for message content * chore: remove unneded join * Bump deps * Ignore shadcn/ui * Run formatter * Update biome.jsonc * Resolves #77 * Resolves #69 * Resolves #60 * Remove logo.dev from examples * Update context.tsx * Propagate fixes from ai-studio * Resolves #74 * Resolves #59 * Resolves #67 * Run Ultracite * Resolves #73 * Resolves #71 * Update prompt-input.tsx * Start merging prompt input files * Continue working * STILL working * Finish cleaning up prompt input * Update prompt-input.tsx * Remove context * Update prompt-input.tsx * Update prompt-input.tsx * Update message.tsx * Fix trigger consistency * Fade reasoning text * Resolves #38 * Create artifact.tsx * Misc fixes * Port Context from ChatSDK (WIP) * Rebuild context component * Update context.tsx * Misc fixes * Port updates from ai-studio * Update suggestion-input.tsx * Update v0-clone.tsx --------- Co-authored-by: Nicklas Scharpff <64584979+xn1cklas@users.noreply.github.com> Co-authored-by: huygbui <160628415+huygbui@users.noreply.github.com> Co-authored-by: Damiano Carradori <damiano.carradori@gmail.com>
▲ AI Elements
AI Elements is a component library built on top of shadcn/ui to help you build AI-native applications faster.
Overview
AI Elements provides pre-built, customizable React components specifically designed for AI applications, including conversations, messages, code blocks, reasoning displays, and more. The CLI makes it easy to add these components to your Next.js project.
Installation
You can use the AI Elements CLI directly with npx, or install it globally:
# Use directly (recommended)
npx ai-elements@latest
# Or using shadcn cli
npx shadcn@latest add https://registry.ai-sdk.dev/registry.json
Prerequisites
Before using AI Elements, ensure your project meets these requirements:
- Node.js 18 or later
- Next.js project with AI SDK installed
- shadcn/ui initialized in your project (
npx shadcn@latest init) - Tailwind CSS configured (AI Elements supports CSS Variables mode only)
Usage
Install All Components
Install all available AI Elements components at once:
npx ai-elements@latest
This command will:
- Set up shadcn/ui if not already configured
- Install all AI Elements components to your configured components directory
- Add necessary dependencies to your project
Install Specific Components
Install individual components using the add command:
npx ai-elements@latest add <component-name>
Examples:
# Install the message component
npx ai-elements@latest add message
# Install the conversation component
npx ai-elements@latest add conversation
# Install the code-block component
npx ai-elements@latest add code-block
Alternative: Use with shadcn CLI
You can also install components using the standard shadcn/ui CLI:
# Install all components
npx shadcn@latest add https://registry.ai-sdk.dev/registry.json
# Install a specific component
npx shadcn@latest add https://registry.ai-sdk.dev/message.json
Available Components
AI Elements includes the following components:
| Component | Description |
|---|---|
actions |
Interactive action buttons for AI responses |
branch |
Branch visualization for conversation flows |
code-block |
Syntax-highlighted code display with copy functionality |
context |
Display Context consumption |
conversation |
Container for chat conversations |
image |
AI-generated image display component |
inline-citation |
Inline source citations |
loader |
Loading states for AI operations |
message |
Individual chat messages with avatars |
prompt-form |
Controlled form wrapper for prompt submission |
prompt-input |
Advanced input component with model selection |
prompt-input-attachments |
Opt-in file/image attachments for prompt input |
reasoning |
Display AI reasoning and thought processes |
response |
Formatted AI response display |
source |
Source attribution component |
suggestion |
Quick action suggestions |
task |
Task completion tracking |
tool |
Tool usage visualization |
web-preview |
Embedded web page previews |
Quick Start Example
After installing components, you can use them in your React application:
'use client';
import { useChat } from '@ai-sdk/react';
import {
Conversation,
ConversationContent,
} from '@/components/ai-elements/conversation';
import {
Message,
MessageContent,
} from '@/components/ai-elements/message';
import { Response } from '@/components/ai-elements/response';
export default function Chat() {
const { messages } = useChat();
return (
<Conversation>
<ConversationContent>
{messages.map((message, index) => (
<Message key={index} from={message.role}>
<MessageContent>
<Response>{message.content}</Response>
</MessageContent>
</Message>
))}
</ConversationContent>
</Conversation>
);
}
How It Works
The AI Elements CLI:
- Detects your package manager (npm, pnpm, yarn, or bun) automatically
- Fetches component registry from
https://registry.ai-sdk.dev/registry.json - Installs components using the shadcn/ui CLI under the hood
- Adds dependencies and integrates with your existing shadcn/ui setup
Components are installed to your configured shadcn/ui components directory (typically @/components/ai-elements/) and become part of your codebase, allowing for full customization.
Configuration
AI Elements uses your existing shadcn/ui configuration. Components will be installed to the directory specified in your components.json file.
Recommended Setup
For the best experience, we recommend:
- AI Gateway: Set up Vercel AI Gateway and add
AI_GATEWAY_API_KEYto your.env.local - CSS Variables: Use shadcn/ui's CSS Variables mode for theming
- TypeScript: Enable TypeScript for better development experience
Contributing
If you'd like to contribute to AI Elements, please follow these steps:
- Fork the repository
- Create a new branch
- Make your changes to the components in
packages/elements. - Open a PR to the
mainbranch.
Made with ❤️ by Vercel