diff --git a/src/components/Chat.tsx b/src/components/Chat.tsx new file mode 100644 index 0000000..79bcef8 --- /dev/null +++ b/src/components/Chat.tsx @@ -0,0 +1,134 @@ +import { useRef, useState, useEffect } from 'react' +import { type AgentState, type ReceivedMessage, useChat } from '@livekit/components-react' +import { Keyboard, Loader, SendHorizontal } from 'lucide-react' + +import { AgentChatTranscript } from '@/components/agents-ui/agent-chat-transcript' +import { Conversation, ConversationContent, ConversationScrollButton } from '@/components/ai-elements/conversation' +import { Button } from '@/components/ui/button' +import { Bubble, BubbleContent } from '@/components/ui/bubble' +import { Marker, MarkerContent } from '@/components/ui/marker' +import { Drawer, DrawerContent, DrawerHeader, DrawerTitle, DrawerTrigger } from '@/components/ui/drawer' +import chatMessages from '@/mocks/chat.json' +import { formatTime } from '@/utils/datetime' +import { Message, MessageContent, MessageFooter } from './ui/message' + +interface ChatProps { + agentState: AgentState + messages: ReceivedMessage[] +} + +export function Chat({ agentState, messages }: ChatProps) { + // const { send } = useChat({room:session.room}) + const [isChatOpen, setChatOpen] = useState(false) + const [message, setMessage] = useState('') + const [isFormSubmitting, setFormSubmitting] = useState(false) + const inputRef = useRef(null) + + const isDisabled = isFormSubmitting || message.trim().length === 0 + + const handleSend = async () => { + if (isDisabled) return + try { + setFormSubmitting(true) + await send(message.trim()) + setMessage('') + } catch (error) { + console.error(error) + } finally { + setFormSubmitting(false) + } + } + + const handleKeyDown = (e: React.KeyboardEvent) => { + if (e.key === 'Enter' && !e.shiftKey) { + e.preventDefault() + handleSend() + } + } + + useEffect(() => { + if (isChatOpen && inputRef.current) { + inputRef.current.focus() + } + }, [isChatOpen]) + + return ( + + + + + +
+ + Chat + +
+ {messages.length === 0 && chatMessages.length === 0 ? ( +
+ No messages yet. Start a conversation! +
+ ) : ( + + + {chatMessages.length > 0 && + (() => { + return ( + + Conversation started + + ) + })()} + {chatMessages.map((msg) => ( + + + + {msg.content} + + {formatTime(msg.timestamp)} + + + ))} + {messages.length > 0 && ( + + )} + + + + )} +
+
+
+