fix(app): keep dictation running when agent tab loses focus
Previously, dictation was cancelled the moment the user switched away from the active agent tab, losing any in-progress recording. Drop the auto-stop-on-blur behavior so users can start dictating, switch tabs, and come back to finalize.
This commit is contained in:
@@ -1328,7 +1328,6 @@ export const MessageInput = forwardRef<MessageInputRef, MessageInputProps>(
|
|||||||
onError: handleDictationError,
|
onError: handleDictationError,
|
||||||
canStart: canStartDictation,
|
canStart: canStartDictation,
|
||||||
canConfirm: canConfirmDictation,
|
canConfirm: canConfirmDictation,
|
||||||
autoStopWhenHidden: { isVisible: isPaneFocused },
|
|
||||||
enableDuration: true,
|
enableDuration: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ export interface UseDictationOptions {
|
|||||||
onPermanentFailure?: (error: Error, context: { requestId: string }) => void;
|
onPermanentFailure?: (error: Error, context: { requestId: string }) => void;
|
||||||
canStart?: () => boolean;
|
canStart?: () => boolean;
|
||||||
canConfirm?: () => boolean;
|
canConfirm?: () => boolean;
|
||||||
autoStopWhenHidden?: { isVisible: boolean };
|
|
||||||
enableDuration?: boolean;
|
enableDuration?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ export function useDictation(options: UseDictationOptions): UseDictationResult {
|
|||||||
onPermanentFailure,
|
onPermanentFailure,
|
||||||
canStart,
|
canStart,
|
||||||
canConfirm,
|
canConfirm,
|
||||||
autoStopWhenHidden,
|
|
||||||
enableDuration = false,
|
enableDuration = false,
|
||||||
} = options;
|
} = options;
|
||||||
|
|
||||||
@@ -425,46 +424,6 @@ export function useDictation(options: UseDictationOptions): UseDictationResult {
|
|||||||
clearStreamingState();
|
clearStreamingState();
|
||||||
}, [clearStreamingState, stopDurationTracking]);
|
}, [clearStreamingState, stopDurationTracking]);
|
||||||
|
|
||||||
const cancelRef = useRef<(() => void) | null>(null);
|
|
||||||
useEffect(() => {
|
|
||||||
cancelRef.current = () => {
|
|
||||||
void cancelDictation();
|
|
||||||
};
|
|
||||||
}, [cancelDictation]);
|
|
||||||
|
|
||||||
const visibilityRef = useRef<boolean | null>(
|
|
||||||
typeof autoStopWhenHidden?.isVisible === "boolean" ? autoStopWhenHidden.isVisible : null,
|
|
||||||
);
|
|
||||||
useEffect(() => {
|
|
||||||
const nextVisible =
|
|
||||||
typeof autoStopWhenHidden?.isVisible === "boolean" ? autoStopWhenHidden.isVisible : null;
|
|
||||||
const prevVisible = visibilityRef.current;
|
|
||||||
visibilityRef.current = nextVisible;
|
|
||||||
|
|
||||||
if (prevVisible === true && nextVisible === false) {
|
|
||||||
attemptGuardRef.current.cancel();
|
|
||||||
|
|
||||||
if (isRecordingRef.current) {
|
|
||||||
cancelRef.current?.();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isProcessingRef.current) {
|
|
||||||
stopDurationTracking();
|
|
||||||
setDuration(0);
|
|
||||||
setIsProcessing(false);
|
|
||||||
isProcessingRef.current = false;
|
|
||||||
setError(null);
|
|
||||||
if (senderRef.current?.hasSegments()) {
|
|
||||||
setStatus("failed");
|
|
||||||
} else {
|
|
||||||
setStatus("idle");
|
|
||||||
clearStreamingState();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, [autoStopWhenHidden?.isVisible, clearStreamingState, stopDurationTracking]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const attemptGuard = attemptGuardRef.current;
|
const attemptGuard = attemptGuardRef.current;
|
||||||
const audioStop = audioStopRef;
|
const audioStop = audioStopRef;
|
||||||
|
|||||||
Reference in New Issue
Block a user