"use client"; import { useState, useRef, useEffect } from "react"; import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { ScrollArea } from "@/components/ui/scroll-area"; import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; import { Badge } from "@/components/ui/badge"; import { Textarea } from "@/components/ui/textarea"; import { Send, Bot, User, Copy, Download, RefreshCw, Loader2, Sparkles, Settings } from "lucide-react"; import { cn } from "@/lib/utils"; interface Message { id: string; role: "user" | "assistant"; content: string; timestamp: Date; isStreaming?: boolean; } export default function AIChatInterface() { const [messages, setMessages] = useState([ { id: "1", role: "assistant", content: "Hello! I'm your AI assistant powered by @hanzo/ui. How can I help you today?", timestamp: new Date(), } ]); const [input, setInput] = useState(""); const [isLoading, setIsLoading] = useState(false); const scrollRef = useRef(null); useEffect(() => { scrollRef.current?.scrollIntoView({ behavior: "smooth" }); }, [messages]); const handleSend = async () => { if (!input.trim() || isLoading) return; const userMessage: Message = { id: Date.now().toString(), role: "user", content: input, timestamp: new Date() }; setMessages(prev => [...prev, userMessage]); setInput(""); setIsLoading(true); // Simulate streaming response const assistantMessage: Message = { id: (Date.now() + 1).toString(), role: "assistant", content: "", timestamp: new Date(), isStreaming: true }; setMessages(prev => [...prev, assistantMessage]); // Simulate streaming text const response = `I understand you're asking about "${input}". Let me help you with that. This response demonstrates the streaming capability of our chat interface built with @hanzo/ui components. The interface features: • Real-time message streaming • Markdown support for rich text formatting • Code syntax highlighting • Responsive design that works on all devices • Dark/light theme support The UI is built entirely with @hanzo/ui primitives like Card, Button, ScrollArea, and Avatar components, ensuring consistency with the Hanzo design system.`; let currentText = ""; const words = response.split(" "); for (let i = 0; i < words.length; i++) { currentText += (i > 0 ? " " : "") + words[i]; await new Promise(resolve => setTimeout(resolve, 30)); setMessages(prev => prev.map(msg => msg.id === assistantMessage.id ? { ...msg, content: currentText } : msg )); } setMessages(prev => prev.map(msg => msg.id === assistantMessage.id ? { ...msg, isStreaming: false } : msg )); setIsLoading(false); }; return (
AI Chat Interface Powered by @hanzo/ui components
GPT-4
{messages.map((message) => (
{message.role === "assistant" && ( )}

{message.content} {message.isStreaming && ( )}

{message.timestamp.toLocaleTimeString()} {message.role === "assistant" && !message.isStreaming && (
)}
{message.role === "user" && ( )}
))}