AI Conversation
hextaui/ai-conversationFreeComponent
Display AI conversation messages with streaming support.
Install it
npx shadcn@latest add https://hextaui.com/r/ai-conversation.jsonSource
1"use client";23import { MessageCircle, Sparkles } from "lucide-react";4import { useCallback, useEffect, useRef, useState } from "react";5import { cn } from "@/lib/utils";6import { Button } from "@/registry/new-york/ui/button";7import AIMessage from "./ai-message";8import AIThinking from "./ai-thinking";910export interface Message {11 id: string;12 role: "user" | "assistant";13 content: string;14 timestamp?: Date;15}1617interface AIConversationProps {18 messages?: Message[];19 isThinking?: boolean;20 isStreaming?: boolean;21 onRegenerate?: (messageId: string) => void;22 onEdit?: (messageId: string) => void;23 onNewMessage?: () => void;24 className?: string;25 maxHeight?: string;26 emptyStateTitle?: string;27 emptyStateDescription?: string;28}2930const SCROLL_THRESHOLD = 100;31const SCROLL_DEBOUNCE_MS = 150;3233function useAutoScroll(34 messages: Message[],35 isThinking: boolean,36 isStreaming: boolean,37 containerRef: React.RefObject<HTMLDivElement | null>38) {39 const shouldScrollRef = useRef(true);40 const scrollTimeoutRef = useRef<NodeJS.Timeout | null>(null);4142 useEffect(() => {43 if (!containerRef.current) return;4445 const container = containerRef.current;46 const isAtBottom =47 container.scrollHeight - container.scrollTop <=48 container.clientHeight + SCROLL_THRESHOLD;4950 shouldScrollRef.current = isAtBottom;51 }, [messages, containerRef]);5253 useEffect(() => {54 if (!(containerRef.current && shouldScrollRef.current)) return;5556 if (scrollTimeoutRef.current) {57 clearTimeout(scrollTimeoutRef.current);58 }5960 scrollTimeoutRef.current = setTimeout(() => {61 if (!containerRef.current) return;6263 if (typeof window !== "undefined") {64 const prefersReducedMotion = window.matchMedia(65 "(prefers-reduced-motion: reduce)"66 ).matches;6768 const scrollBehavior = prefersReducedMotion ? "auto" : "smooth";69 containerRef.current.scrollTo({70 top: containerRef.current.scrollHeight,71 behavior: scrollBehavior,72 });73 } else {74 containerRef.current.scrollTop = containerRef.current.scrollHeight;75 }76 }, SCROLL_DEBOUNCE_MS);7778 return () => {79 if (scrollTimeoutRef.current) {80 clearTimeout(scrollTimeoutRef.current);81 }82 };83 }, [messages, isThinking, isStreaming, containerRef]);84}8586function useKeyboardNavigation(87 messages: Message[],88 containerRef: React.RefObject<HTMLDivElement | null>89) {90// … truncated
What it pulls in
Other registry items
Files it writes
More from HextaUI
All 139 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | HextaUI | Components | Free | 1 dep | |
| AI Chat Historyai-chat-history | HextaUI | Components | Free | no deps | |
| AI Citationsai-citations | HextaUI | Components | Free | no deps | |
| AI Error Handlerai-error-handler | HextaUI | Components | Free | no deps | |
| AI File Uploadai-file-upload | HextaUI | Components | Free | no deps | |
| AI Messageai-message | HextaUI | Components | Free | 4 deps | |
| AI Model Selectorai-model-selector | HextaUI | Components | Free | no deps | |
| AI Prompt Inputai-prompt-input | HextaUI | Components | Free | no deps |
