useVoiceEnabled.ts
hooks/useVoiceEnabled.ts
No strong subsystem tag
26
Lines
1134
Bytes
1
Exports
3
Imports
10
Keywords
What this is
This page documents one file from the repository and includes its full source so you can read it without leaving the docs site.
Beginner explanation
This file is one piece of the larger system. Its name, directory, imports, and exports show where it fits. Start by reading the exports and related files first.
How it is used
Start from the exports list and related files. Those are the easiest clues for where this file fits into the system.
Expert explanation
Architecturally, this file intersects with general runtime concerns. It contains 26 lines, 3 detected imports, and 1 detected exports.
Important relationships
Detected exports
useVoiceEnabled
Keywords
authversionuseappstateauthauthedusememohasvoiceauthisvoicegrowthbookenabledusersettingsvoiceenabled
Detected imports
react../state/AppState.js../voice/voiceModeEnabled.js
Source notes
This page embeds the full file contents. Small or leaf files are still indexed honestly instead of being over-explained.
Full source
import { useMemo } from 'react'
import { useAppState } from '../state/AppState.js'
import {
hasVoiceAuth,
isVoiceGrowthBookEnabled,
} from '../voice/voiceModeEnabled.js'
/**
* Combines user intent (settings.voiceEnabled) with auth + GB kill-switch.
* Only the auth half is memoized on authVersion — it's the expensive one
* (cold getClaudeAIOAuthTokens memoize → sync `security` spawn, ~60ms/call,
* ~180ms total in profile v5 when token refresh cleared the cache mid-session).
* GB is a cheap cached-map lookup and stays outside the memo so a mid-session
* kill-switch flip still takes effect on the next render.
*
* authVersion bumps on /login only. Background token refresh leaves it alone
* (user is still authed), so the auth memo stays correct without re-eval.
*/
export function useVoiceEnabled(): boolean {
const userIntent = useAppState(s => s.settings.voiceEnabled === true)
const authVersion = useAppState(s => s.authVersion)
// eslint-disable-next-line react-hooks/exhaustive-deps
const authed = useMemo(hasVoiceAuth, [authVersion])
return userIntent && authed && isVoiceGrowthBookEnabled()
}