@@ -134,6 +134,7 @@ export interface MessageProps {
134134 actions ?: UserActions
135135 showAssistantCopyPartID ?: string | null
136136 showReasoningSummaries ?: boolean
137+ onSpeak ?: ( input : { messageID : string ; text : string } ) => void
137138}
138139
139140export type SessionAction = ( input : { sessionID : string ; messageID : string } ) => Promise < void > | void
@@ -150,6 +151,7 @@ export interface MessagePartProps {
150151 defaultOpen ?: boolean
151152 showAssistantCopyPartID ?: string | null
152153 turnDurationMs ?: number
154+ onSpeak ?: ( input : { messageID : string ; text : string } ) => void
153155}
154156
155157export type PartComponent = Component < MessagePartProps >
@@ -748,6 +750,7 @@ export function Message(props: MessageProps) {
748750 parts = { props . parts }
749751 showAssistantCopyPartID = { props . showAssistantCopyPartID }
750752 showReasoningSummaries = { props . showReasoningSummaries }
753+ onSpeak = { props . onSpeak }
751754 />
752755 ) }
753756 </ Match >
@@ -760,6 +763,7 @@ export function AssistantMessageDisplay(props: {
760763 parts : PartType [ ]
761764 showAssistantCopyPartID ?: string | null
762765 showReasoningSummaries ?: boolean
766+ onSpeak ?: ( input : { messageID : string ; text : string } ) => void
763767} ) {
764768 const emptyTools : ToolPart [ ] = [ ]
765769 const part = createMemo ( ( ) => index ( props . parts ) )
@@ -819,6 +823,7 @@ export function AssistantMessageDisplay(props: {
819823 part = { item ( ) ! }
820824 message = { props . message }
821825 showAssistantCopyPartID = { props . showAssistantCopyPartID }
826+ onSpeak = { props . onSpeak }
822827 />
823828 </ Show >
824829 )
@@ -1157,6 +1162,7 @@ export function Part(props: MessagePartProps) {
11571162 defaultOpen = { props . defaultOpen }
11581163 showAssistantCopyPartID = { props . showAssistantCopyPartID }
11591164 turnDurationMs = { props . turnDurationMs }
1165+ onSpeak = { props . onSpeak }
11601166 />
11611167 </ Show >
11621168 )
@@ -1399,6 +1405,7 @@ PART_MAPPING["text"] = function TextPartDisplay(props) {
13991405 if ( typeof props . showAssistantCopyPartID === "string" ) return props . showAssistantCopyPartID === part ( ) . id
14001406 return isLastTextPart ( )
14011407 } )
1408+ const showSpeak = createMemo ( ( ) => props . message . role === "assistant" && isLastTextPart ( ) && ! ! displayText ( ) )
14021409 const [ copied , setCopied ] = createSignal ( false )
14031410
14041411 const handleCopy = async ( ) => {
@@ -1433,6 +1440,18 @@ PART_MAPPING["text"] = function TextPartDisplay(props) {
14331440 aria-label = { copied ( ) ? i18n . t ( "ui.message.copied" ) : i18n . t ( "ui.message.copyResponse" ) }
14341441 />
14351442 </ Tooltip >
1443+ < Show when = { showSpeak ( ) } >
1444+ < Tooltip value = { i18n . t ( "ui.message.speakResponse" ) } placement = "top" gutter = { 4 } >
1445+ < IconButton
1446+ icon = "speaker"
1447+ size = "normal"
1448+ variant = "ghost"
1449+ onMouseDown = { ( e ) => e . preventDefault ( ) }
1450+ onClick = { ( ) => props . onSpeak ?.( { messageID : props . message . id , text : displayText ( ) } ) }
1451+ aria-label = { i18n . t ( "ui.message.speakResponse" ) }
1452+ />
1453+ </ Tooltip >
1454+ </ Show >
14361455 < Show when = { meta ( ) } >
14371456 < span data-slot = "text-part-meta" class = "text-12-regular text-text-weak cursor-default" >
14381457 { meta ( ) }
0 commit comments