AI Elements Chat
blocks/ai-05FreeBlock
A ai elements chat block.
Install it
npx shadcn@latest add https://blocks.so/r/ai-05.jsonSource
1'use client';23// Install AI Elements components:4// npx ai-elements@latest add conversation message prompt-input56import {7 IconAdjustmentsHorizontal,8 IconBolt,9 IconMessageCircle,10 IconPaperclip,11 IconRefresh,12 IconSparkles,13} from '@tabler/icons-react';14import type { ChatStatus } from 'ai';15import { useEffect, useRef, useState } from 'react';16import {17 Conversation,18 ConversationContent,19 ConversationScrollButton,20} from '@/components/ai-elements/conversation';21import {22 Message,23 MessageContent,24 MessageResponse,25} from '@/components/ai-elements/message';26import {27 PromptInput,28 PromptInputButton,29 PromptInputFooter,30 PromptInputSubmit,31 PromptInputTextarea,32 PromptInputTools,33} from '@/components/ai-elements/prompt-input';34import { Badge } from '@/components/ui/badge';35import { Button } from '@/components/ui/button';36import { cn } from '@/lib/utils';3738interface DemoMessage {39 id: string;40 role: 'user' | 'assistant';41 content: string;42}4344const INITIAL_MESSAGES: DemoMessage[] = [45 {46 id: 'intro',47 role: 'assistant',48 content:49 '**Welcome back.** I can help you explore this chat block.\n\n- Draft UI copy\n- Summarize docs\n- Turn notes into tasks\n\nAsk me anything and I will respond with a demo reply.',50 },51 {52 id: 'question',53 role: 'user',54 content: 'What makes this chat block reusable?',55 },56 {57 id: 'answer',58 role: 'assistant',59 content:60 'It is built with **AI Elements** for conversation layout and input, plus shadcn/ui for the chrome. That means you can drop it into other screens and wire it up to a real AI backend later.',61 },62];6364const RESPONSES = [65 'Here is a quick outline you can reuse:\n\n1. Swap the mock response with a real API call.\n2. Stream tokens into `MessageResponse`.\n3. Keep the layout exactly as-is for a consistent UI.',66 'If you want multi-model support, add a small model selector next to the status badge and pass the selection to your backend.',67 'You can also inject tools like file upload or voice input by adding buttons to the prompt footer.',68];6970const pickResponse = (index: number) => RESPONSES[index % RESPONSES.length];7172export default function Ai05() {73 const [messages, setMessages] = useState<DemoMessage[]>(INITIAL_MESSAGES);74 const [inputValue, setInputValue] = useState('');75 const [status, setStatus] = useState<ChatStatus>('ready');76 const replyTimeoutRef = useRef<number | null>(null);7778 useEffect(() => {79 return () => {80// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from blocks
All 76 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| AI Chat with Voice Inputai-01 | blocks | Blocks | Free | 1 dep | |
| AI Chat with Model Selectionai-02 | blocks | Blocks | Free | 1 dep | |
| AI Chat Compact Interfaceai-03 | blocks | Blocks | Free | 1 dep | |
| AI Chat with File Attachmentsai-04 | blocks | Blocks | Free | 1 dep | |
| Command Menu with Groupscommand-menu-01 | blocks | Blocks | Free | 1 dep | |
| Command Menu with Keyboard Shortcutscommand-menu-02 | blocks | Blocks | Free | 1 dep | |
| Command Menu with Documentation Searchcommand-menu-03 | blocks | Blocks | Free | 1 dep | |
| Dialog Confirmationdialog-01 | blocks | Blocks | Free | 1 dep |
