|
1 | 1 | 'use client'; |
2 | 2 |
|
3 | 3 | import { AnimatePresence, type HTMLMotionProps, motion } from 'motion/react'; |
4 | | -import { type ReceivedMessage } from '@livekit/components-react'; |
| 4 | +import { type ReceivedMessage, useVoiceAssistant } from '@livekit/components-react'; |
5 | 5 | import { ChatEntry } from '@/components/livekit/chat-entry'; |
| 6 | +import { ChatIndicator } from '@/components/livekit/chat-indicator'; |
6 | 7 |
|
7 | 8 | const MotionContainer = motion.create('div'); |
8 | 9 | const MotionChatEntry = motion.create(ChatEntry); |
@@ -58,31 +59,35 @@ export function ChatTranscript({ |
58 | 59 | messages = [], |
59 | 60 | ...props |
60 | 61 | }: ChatTranscriptProps & Omit<HTMLMotionProps<'div'>, 'ref'>) { |
| 62 | + const { state: agentState } = useVoiceAssistant(); |
61 | 63 | return ( |
62 | | - <AnimatePresence> |
63 | | - {!hidden && ( |
64 | | - <MotionContainer {...CONTAINER_MOTION_PROPS} {...props}> |
65 | | - {messages.map((receivedMessage) => { |
66 | | - const { id, timestamp, from, message } = receivedMessage; |
67 | | - const locale = navigator?.language ?? 'en-US'; |
68 | | - const messageOrigin = from?.isLocal ? 'local' : 'remote'; |
69 | | - const hasBeenEdited = |
70 | | - receivedMessage.type === 'chatMessage' && !!receivedMessage.editTimestamp; |
| 64 | + <> |
| 65 | + <AnimatePresence> |
| 66 | + {!hidden && ( |
| 67 | + <MotionContainer {...CONTAINER_MOTION_PROPS} {...props}> |
| 68 | + {messages.map((receivedMessage) => { |
| 69 | + const { id, timestamp, from, message } = receivedMessage; |
| 70 | + const locale = navigator?.language ?? 'en-US'; |
| 71 | + const messageOrigin = from?.isLocal ? 'local' : 'remote'; |
| 72 | + const hasBeenEdited = |
| 73 | + receivedMessage.type === 'chatMessage' && !!receivedMessage.editTimestamp; |
71 | 74 |
|
72 | | - return ( |
73 | | - <MotionChatEntry |
74 | | - key={id} |
75 | | - locale={locale} |
76 | | - timestamp={timestamp} |
77 | | - message={message} |
78 | | - messageOrigin={messageOrigin} |
79 | | - hasBeenEdited={hasBeenEdited} |
80 | | - {...MESSAGE_MOTION_PROPS} |
81 | | - /> |
82 | | - ); |
83 | | - })} |
84 | | - </MotionContainer> |
85 | | - )} |
86 | | - </AnimatePresence> |
| 75 | + return ( |
| 76 | + <MotionChatEntry |
| 77 | + key={id} |
| 78 | + locale={locale} |
| 79 | + timestamp={timestamp} |
| 80 | + message={message} |
| 81 | + messageOrigin={messageOrigin} |
| 82 | + hasBeenEdited={hasBeenEdited} |
| 83 | + {...MESSAGE_MOTION_PROPS} |
| 84 | + /> |
| 85 | + ); |
| 86 | + })} |
| 87 | + <ChatIndicator agentState={agentState} /> |
| 88 | + </MotionContainer> |
| 89 | + )} |
| 90 | + </AnimatePresence> |
| 91 | + </> |
87 | 92 | ); |
88 | 93 | } |
0 commit comments