@@ -4,6 +4,7 @@ import { Marked } from '@ts-stack/markdown';
44import { FeedbackRatingType , sendFeedbackQuery , sendFileDownloadQuery , updateFeedbackQuery } from '@/queries/sendMessageQuery' ;
55import { FileUpload , IAction , MessageType } from '../Bot' ;
66import { CopyToClipboardButton , ThumbsDownButton , ThumbsUpButton } from '../buttons/FeedbackButtons' ;
7+ import { TTSButton } from '../buttons/TTSButton' ;
78import FeedbackContentDialog from '../FeedbackContentDialog' ;
89import { AgentReasoningBubble } from './AgentReasoningBubble' ;
910import { TickIcon , XIcon } from '../icons' ;
@@ -32,6 +33,12 @@ type Props = {
3233 renderHTML ?: boolean ;
3334 handleActionClick : ( elem : any , action : IAction | undefined | null ) => void ;
3435 handleSourceDocumentsClick : ( src : any ) => void ;
36+ // TTS props
37+ isTTSEnabled ?: boolean ;
38+ isTTSLoading ?: Record < string , boolean > ;
39+ isTTSPlaying ?: Record < string , boolean > ;
40+ handleTTSClick ?: ( messageId : string , messageText : string ) => void ;
41+ handleTTSStop ?: ( messageId : string ) => void ;
3542} ;
3643
3744const defaultBackgroundColor = '#f7f8ff' ;
@@ -481,7 +488,7 @@ export const BotBubble = (props: Props) => {
481488 { action . label }
482489 </ button >
483490 ) : (
484- < button > { action . label } </ button >
491+ < button type = "button" > { action . label } </ button >
485492 ) }
486493 </ >
487494 ) ;
@@ -521,9 +528,25 @@ export const BotBubble = (props: Props) => {
521528 ) }
522529 </ div >
523530 < div >
524- { props . chatFeedbackStatus && props . message . messageId && (
525- < >
526- < div class = { `flex items-center px-2 pb-2 ${ props . showAvatar ? 'ml-10' : '' } ` } >
531+ < div class = { `flex items-center px-2 pb-2 ${ props . showAvatar ? 'ml-10' : '' } ` } >
532+ < Show when = { props . isTTSEnabled } >
533+ < TTSButton
534+ feedbackColor = { props . feedbackColor }
535+ isLoading = { props . isTTSLoading ?. [ props . message . id || '' ] || false }
536+ isPlaying = { props . isTTSPlaying ?. [ props . message . id || '' ] || false }
537+ onClick = { ( ) => {
538+ const messageId = props . message . id || '' ;
539+ const messageText = props . message . message || '' ;
540+ if ( props . isTTSPlaying ?. [ messageId ] ) {
541+ props . handleTTSStop ?.( messageId ) ;
542+ } else {
543+ props . handleTTSClick ?.( messageId , messageText ) ;
544+ }
545+ } }
546+ />
547+ </ Show >
548+ { props . chatFeedbackStatus && props . message . messageId && (
549+ < >
527550 < CopyToClipboardButton feedbackColor = { props . feedbackColor } onClick = { ( ) => copyMessageToClipboard ( ) } />
528551 < Show when = { copiedMessage ( ) } >
529552 < div class = "copied-message" style = { { color : props . feedbackColor ?? defaultFeedbackColor } } >
@@ -546,18 +569,18 @@ export const BotBubble = (props: Props) => {
546569 { formatDateTime ( props . message . dateTime , props ?. dateTimeToggle ?. date , props ?. dateTimeToggle ?. time ) }
547570 </ div >
548571 </ Show >
549- </ div >
550- < Show when = { showFeedbackContentDialog ( ) } >
551- < FeedbackContentDialog
552- isOpen = { showFeedbackContentDialog ( ) }
553- onClose = { ( ) => setShowFeedbackContentModal ( false ) }
554- onSubmit = { submitFeedbackContent }
555- backgroundColor = { props . backgroundColor }
556- textColor = { props . textColor }
557- />
558- </ Show >
559- < />
560- ) }
572+ </ >
573+ ) }
574+ </ div >
575+ < Show when = { showFeedbackContentDialog ( ) } >
576+ < FeedbackContentDialog
577+ isOpen = { showFeedbackContentDialog ( ) }
578+ onClose = { ( ) => setShowFeedbackContentModal ( false ) }
579+ onSubmit = { submitFeedbackContent }
580+ backgroundColor = { props . backgroundColor }
581+ textColor = { props . textColor }
582+ />
583+ </ Show >
561584 </ div >
562585 </ div >
563586 ) ;
0 commit comments