Hide voice mode while agents run

This commit is contained in:
Mohamed Boudra
2026-05-19 08:18:56 +07:00
parent 8aa8f7a0cc
commit 501dcf373b
2 changed files with 18 additions and 2 deletions
+2 -1
View File
@@ -756,7 +756,8 @@ function ComposerRightControlsSlot({
...voiceProps ...voiceProps
}: ComposerRightControlsSlotProps) { }: ComposerRightControlsSlotProps) {
const hideVoiceForCompactInput = isCompact && hasSendableContent; const hideVoiceForCompactInput = isCompact && hasSendableContent;
const showVoiceModeButton = !isVoiceModeForAgent && hasAgent && !hideVoiceForCompactInput; const showVoiceModeButton =
!isVoiceModeForAgent && hasAgent && !isAgentRunning && !hideVoiceForCompactInput;
const shouldShowCancelButton = isAgentRunning && !hasSendableContent && !isProcessing; const shouldShowCancelButton = isAgentRunning && !hasSendableContent && !isProcessing;
if (!showVoiceModeButton && !shouldShowCancelButton) return null; if (!showVoiceModeButton && !shouldShowCancelButton) return null;
return ( return (
+16 -1
View File
@@ -799,6 +799,7 @@ interface ToggleRealtimeVoiceContext {
voiceAgentId: string | undefined; voiceAgentId: string | undefined;
isConnected: boolean; isConnected: boolean;
disabled: boolean; disabled: boolean;
isAgentRunning: boolean;
handleStopRealtimeVoice: () => Promise<unknown> | void; handleStopRealtimeVoice: () => Promise<unknown> | void;
toast: { error: (msg: string) => void }; toast: { error: (msg: string) => void };
} }
@@ -812,6 +813,10 @@ function toggleRealtimeVoiceImpl(ctx: ToggleRealtimeVoiceContext): void {
void ctx.handleStopRealtimeVoice(); void ctx.handleStopRealtimeVoice();
return; return;
} }
if (ctx.isAgentRunning) {
ctx.toast.error("Interrupt the agent before starting voice mode");
return;
}
void ctx.voice.startVoice(ctx.voiceServerId, ctx.voiceAgentId).catch((error) => { void ctx.voice.startVoice(ctx.voiceServerId, ctx.voiceAgentId).catch((error) => {
console.error("[MessageInput] Failed to start realtime voice", error); console.error("[MessageInput] Failed to start realtime voice", error);
const message = extractErrorMessage(error); const message = extractErrorMessage(error);
@@ -1450,10 +1455,20 @@ export const MessageInput = forwardRef<MessageInputRef, MessageInputProps>(
voiceAgentId, voiceAgentId,
isConnected, isConnected,
disabled, disabled,
isAgentRunning,
handleStopRealtimeVoice, handleStopRealtimeVoice,
toast, toast,
}); });
}, [disabled, handleStopRealtimeVoice, isConnected, toast, voice, voiceAgentId, voiceServerId]); }, [
disabled,
handleStopRealtimeVoice,
isAgentRunning,
isConnected,
toast,
voice,
voiceAgentId,
voiceServerId,
]);
const minimizeInputHeight = useCallback(() => { const minimizeInputHeight = useCallback(() => {
inputHeightRef.current = MIN_INPUT_HEIGHT; inputHeightRef.current = MIN_INPUT_HEIGHT;