import * as React from '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 { IconShare } from '@/components/ui/icons' import { FooterText } from '@/components/footer' import { ChatShareDialog } from '@/components/chat-share-dialog' import { useAIState, useActions, useUIState } from 'ai/rsc' import type { AI } from '@/lib/chat/actions' import { nanoid } from 'nanoid' import { UserMessage } from './stocks/message' export interface ChatPanelProps { id?: string title?: string input: string setInput: (value: string) => void } export function ChatPanel({ id, title, input, setInput }: ChatPanelProps) { const [aiState] = useAIState() const [messages, setMessages] = useUIState() const { submitUserMessage } = useActions() const [shareDialogOpen, setShareDialogOpen] = React.useState(false) const exampleMessages = [ { heading: 'Explain the concept', subheading: 'of a serverless function', message: `Explain the concept of a serverless function` }, { heading: 'What are the benefits', subheading: 'of using turborepo in my codebase?', message: 'What are the benefits of using turborepo in my codebase?' }, { heading: 'List differences between', subheading: 'pages and app router in Next.js', message: `List differences between pages and app router in Next.js` }, { heading: 'What is the price', subheading: `of VRCL in the stock market?`, message: `What is the price of VRCL in the stock market?` } ] return (
{messages.length === 0 && exampleMessages.map((example, index) => (
1 && 'hidden md:block' }`} onClick={async () => { setMessages(currentMessages => [ ...currentMessages, { id: nanoid(), display: {example.message} } ]) const responseMessage = await submitUserMessage( example.message ) setMessages(currentMessages => [ ...currentMessages, responseMessage ]) }} >
{example.heading}
{example.subheading}
))}
{messages?.length >= 2 ? (
{id && title ? ( <> setShareDialogOpen(false)} shareChat={shareChat} chat={{ id, title, messages: aiState.messages }} /> ) : null}
) : null}
) }