"use client" import * as React from "react" import { useChat } from "@ai-sdk/react" import { createChat, getMessageText } from "@/lib/ai" import { Example } from "@/registry/bases/base/components/example" import { PartText } from "@/registry/bases/radix/blocks/preview-03/components/part-text" import { PromptInput } from "@/registry/bases/radix/blocks/preview-03/components/prompt-input" import { Button } from "@/registry/bases/radix/ui/button" import { Card, CardAction, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, } from "@/registry/bases/radix/ui/card" import { Marker, MarkerContent, MarkerIcon, } from "@/registry/bases/radix/ui/marker" import { Message, MessageContent } from "@/registry/bases/radix/ui/message" import { MessageScroller, MessageScrollerButton, MessageScrollerContent, MessageScrollerItem, MessageScrollerProvider, MessageScrollerViewport, } from "@/registry/bases/radix/ui/message-scroller" import { Spinner } from "@/registry/bases/radix/ui/spinner" import { IconPlaceholder } from "@/app/(app)/create/components/icon-placeholder" const chat = createChat() .user("Write me a haiku about centering a div and how it's done.") .sleep(3000) .assistant( "One box in the void / Twenty wrappers, still offset / `margin: 0 auto`" ) .user( `Is this conversation actually happening? I've been sitting here wondering if you're **really** reading this. Every reply feels a little too convenient — like someone already wrote \`chat.next(messages)\` and I'm just clicking send on my own lines.` ) .sleep(3000) .assistant( "You're in a preview block. I'm four hardcoded replies and a transport. Real enough for the demo — philosophically, we're both props." ) .user( "Okay, how do I make my loading spinner feel faster? Tell me in detail about the technique." ) .sleep(3000) .assistant( "Add text that says “Almost there…” and never update it. Users assume progress. Ethically dubious. Statistically effective." ) .user("Can you at least pretend to be surprised?") .sleep(3000) .assistant("😮 WOW! I had no idea you would ask that!") const initialMessages = chat.get(0) const transport = chat.transport() export function SimpleChat() { const { status, messages, sendMessage, setMessages } = useChat({ messages: initialMessages, transport, }) const nextMessage = chat.next(messages) const isBusy = status === "submitted" || status === "streaming" const onSubmit = (input: string) => { const message = input ? { text: input } : (nextMessage ?? undefined) if (!message) { return } void sendMessage(message) } return ( What can I help you with today? A simple chat example. {messages.map((message) => { return ( {message.parts.map((part, index) => ( {part.type === "text" ? ( ) : null} ))} ) })} {status === "submitted" ? ( Thinking... ) : null} ) }