import * as React from 'react' import { type UseChatHelpers } from 'ai/react' import { shareChat } from '@/app/actions' import { Button } from '@/components/ui/button' import { PromptForm } from '@/components/prompt-form' import { ButtonScrollToBottom } from '@/components/button-scroll-to-bottom' import { IconRefresh, IconShare, IconStop } from '@/components/ui/icons' import { ChatShareDialog } from '@/components/chat-share-dialog' export interface ChatPanelProps extends Pick< UseChatHelpers, | 'append' | 'isLoading' | 'reload' | 'messages' | 'stop' | 'input' | 'setInput' > { id?: string title?: string } export function ChatPanel({ id, title, isLoading, stop, append, reload, input, setInput, messages }: ChatPanelProps) { const [shareDialogOpen, setShareDialogOpen] = React.useState(false) return (
{isLoading ? ( ) : ( messages?.length >= 2 && (
{id && title ? ( <> setShareDialogOpen(false)} shareChat={shareChat} chat={{ id, title, messages }} /> ) : null}
) )}
{ await append({ id, content: value, role: 'user' }) }} input={input} setInput={setInput} isLoading={isLoading} />
) }