Open History to see the last commit
1import { useGT } from "gt-react";
2import { useVoiceTranscriptionDestination } from "../../speech/useEnvironmentSpeechInput";
3import {
4 useRetainedVoiceInputSession,
5 useVoiceInputSessionActivity,
6 useVoiceInputSessionSnapshot,
7 useVoiceOwnerPresented,
8} from "../../speech/voiceInputSession";
9import { Button } from "../ui/button";
10import { ComposerSpeechRecordingPill } from "./ComposerSpeechButton";
11
12/**
13 * Keeps the chosen destination's dictation alive across navigation and, while the draft it
14 * records into is off screen, shows it so it can be finished, cancelled, or returned to.
15 */
16export function GlobalVoiceInputIndicator({ hidden = false }: { hidden?: boolean }) {
17 const gt = useGT();
18 const { prepared, grantId, cloudProvider, cloudModel } = useVoiceTranscriptionDestination();
19 const session = useRetainedVoiceInputSession({ prepared, grantId, cloudProvider, cloudModel });
20 const { state, target, recordingStartedAt } = useVoiceInputSessionSnapshot(session);
21 const presented = useVoiceOwnerPresented(target?.ownerKey ?? null);
22 const { level } = useVoiceInputSessionActivity(
23 hidden || presented ? null : session,
24 target?.ownerKey ?? null,
25 );
26 if (hidden || !session || !target || state.phase === "idle" || presented) return null;
27
28 return (
29 <div className="pointer-events-none fixed inset-x-0 top-3 z-100 flex justify-center px-4">
30 <div className="pointer-events-auto flex max-w-full items-center gap-1 rounded-full bg-popover p-0.5 shadow-lg/5 [-webkit-app-region:no-drag]">
31 <Button
32 type="button"
33 size="sm-pill"
34 variant="ghost"
35 disabled={!target.open}
36 onClick={() => target.open?.()}
37 className="min-w-0 shrink"
38 >
39 <span className="truncate">{target.label ?? gt("Untitled thread")}</span>
40 </Button>
41 <ComposerSpeechRecordingPill
42 state={state}
43 progress={null}
44 level={level}
45 recordingStartedAt={recordingStartedAt}
46 onStart={() => void session.start(target)}
47 onStop={() => void session.stop()}
48 onCancel={() => session.cancel()}
49 onSkipPostProcessing={() => session.skipPostProcessing()}
50 />
51 </div>
52 </div>
53 );
54}