@@ -113,6 +113,9 @@ import {
113113} from "../voice-input/ComposerDictationControl" ;
114114import { useVoiceInputController } from "../voice-input/useVoiceInputController" ;
115115import { resolveVoiceComposerPresentation } from "../voice-input/voiceInputPresentation" ;
116+ import { ComposerVoiceModeButton , ComposerVoiceStrip } from "../voice-mode/ComposerVoiceMode" ;
117+ import { useVoiceModePhase , useVoiceModeThreadLifecycle } from "../voice-mode/useVoiceMode" ;
118+ import { voiceMode , voiceModeSupported } from "../voice-mode/voiceMode" ;
116119import {
117120 rememberModelOptions ,
118121 withRememberedModelOptions ,
@@ -480,15 +483,40 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps
480483 onUsageLimits :
481484 usageLimitsOffered && draftAttachments . length === 0 ? openUsageLimits : undefined ,
482485 } ) ;
486+ const voiceTarget = useMemo (
487+ ( ) => ( { environmentId : props . environmentId , threadId : props . selectedThread . id } ) ,
488+ [ props . environmentId , props . selectedThread . id ] ,
489+ ) ;
490+ const voicePhase = useVoiceModePhase ( voiceTarget ) ;
491+ useVoiceModeThreadLifecycle ( voiceTarget ) ;
492+ // Dictation and a voice conversation both need the microphone.
493+ const voiceConversationLive = voicePhase !== "idle" ;
483494 const voiceInput = useVoiceInputController ( {
484495 ownerKey : composerDraftKey ,
485496 label : props . selectedThread . title || "Untitled thread" ,
486497 readDraftMessage : ( ) => getComposerDraftSnapshot ( composerDraftKey ) . text ,
487498 subscribeToDraftChanges : ( onChange ) => appAtomRegistry . subscribe ( composerDraftsAtom , onChange ) ,
488499 selection : composerMenu . selection ,
500+ disabled : voiceConversationLive ,
489501 onChangeDraftMessage : ( text ) => setComposerDraftText ( composerDraftKey , text ) ,
490502 onChangeSelection : composerMenu . onSelectionChange ,
491503 } ) ;
504+ const offersVoiceConversation =
505+ voiceModeSupported && selectedProviderStatus ?. supportsVoice === true ;
506+ // The server attaches voice to the thread's provider session, which the first message creates.
507+ const canToggleVoiceConversation =
508+ voiceConversationLive ||
509+ ( props . connectionState === "connected" &&
510+ props . selectedThread . latestUserMessageAt !== null &&
511+ ! voiceInput . isBusy ) ;
512+ const toggleVoiceConversation = useCallback ( ( ) => voiceMode . toggle ( voiceTarget ) , [ voiceTarget ] ) ;
513+ const voiceModeButton = offersVoiceConversation ? (
514+ < ComposerVoiceModeButton
515+ phase = { voicePhase }
516+ disabled = { ! canToggleVoiceConversation }
517+ onPress = { toggleVoiceConversation }
518+ />
519+ ) : null ;
492520 const voicePresentation = resolveVoiceComposerPresentation (
493521 voiceInput . state ,
494522 voiceInput . elapsedSeconds ,
@@ -736,6 +764,9 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps
736764 { selectedProviderStatus . compatibilityAdvisory . message }
737765 </ Text >
738766 ) : null }
767+
768+ { voiceConversationLive ? < ComposerVoiceStrip /> : null }
769+
739770 { modelUnavailable ? (
740771 < Button
741772 label = "Model unavailable. Open model settings."
@@ -977,9 +1008,11 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps
9771008 ) : null }
9781009 { ! isExpanded ? (
9791010 < View className = "flex-row items-center" >
1011+ { voiceModeButton }
9801012 < ComposerDictationStartAction
9811013 state = { voiceInput . state }
9821014 isAvailable = { voiceInput . isAvailable }
1015+ disabled = { voiceConversationLive }
9831016 onStart = { voiceInput . start }
9841017 onCancel = { voiceInput . cancel }
9851018 />
@@ -1077,10 +1110,12 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps
10771110 </ View >
10781111 ) }
10791112 < View className = "shrink-0 flex-row items-center" >
1113+ { isVoiceInputPresented ? null : voiceModeButton }
10801114 < ComposerDictationPrimaryAction
10811115 state = { voiceInput . state }
10821116 presentation = { voicePresentation }
10831117 isAvailable = { voiceInput . isAvailable }
1118+ disabled = { voiceConversationLive }
10841119 onStart = { voiceInput . start }
10851120 onConfirm = { voiceInput . stop }
10861121 onCancel = { voiceInput . cancel }
0 commit comments