From 0881a9565dd0083dcafac95dcb39609641c77e34 Mon Sep 17 00:00:00 2001 From: Sergei Date: Wed, 28 Jan 2026 19:50:00 -0800 Subject: [PATCH] Fix updateVoiceApiType function and add API logging Fixes error: "updateVoiceApiType is not a function" Changes: - Add voiceApiType state to VoiceContext - Implement updateVoiceApiType callback - Load saved voice API type from SecureStore on mount - Use voiceApiType in sendTranscript (instead of hardcoded 'ask_wellnuo_ai') - Add console.log showing which API type is being used - Export voiceApiType and updateVoiceApiType in context provider Now Voice API selector in Profile works correctly and logs show which API function (voice_ask or ask_wellnuo_ai) is being called. --- contexts/VoiceContext.tsx | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/contexts/VoiceContext.tsx b/contexts/VoiceContext.tsx index 9e0387f..e75bc41 100644 --- a/contexts/VoiceContext.tsx +++ b/contexts/VoiceContext.tsx @@ -134,6 +134,10 @@ interface VoiceContextValue { stopSpeaking: () => void; // Interrupt TTS if speaking (call when user starts talking) interruptIfSpeaking: () => boolean; + + // Voice API configuration + voiceApiType: 'voice_ask' | 'ask_wellnuo_ai'; + updateVoiceApiType: (type: 'voice_ask' | 'ask_wellnuo_ai') => void; } const VoiceContext = createContext(undefined); @@ -162,6 +166,19 @@ export function VoiceProvider({ children }: { children: ReactNode }) { // Deployment ID from settings const deploymentIdRef = useRef(null); + // Voice API type (voice_ask or ask_wellnuo_ai) + const [voiceApiType, setVoiceApiType] = useState<'voice_ask' | 'ask_wellnuo_ai'>('ask_wellnuo_ai'); + + // Load voice API type on mount + React.useEffect(() => { + const loadVoiceApiType = async () => { + const savedType = await api.getVoiceApiType(); + setVoiceApiType(savedType); + console.log('[VoiceContext] Loaded voice API type:', savedType); + }; + loadVoiceApiType(); + }, []); + // Load deployment ID on mount React.useEffect(() => { const loadDeploymentId = async () => { @@ -172,6 +189,15 @@ export function VoiceProvider({ children }: { children: ReactNode }) { loadDeploymentId(); }, []); + /** + * Update voice API type (voice_ask or ask_wellnuo_ai) + */ + const updateVoiceApiType = useCallback(async (type: 'voice_ask' | 'ask_wellnuo_ai') => { + console.log('[VoiceContext] Updating voice API type to:', type); + setVoiceApiType(type); + await api.setVoiceApiType(type); + }, []); + /** * Get WellNuo API token (same as chat.tsx) */ @@ -249,9 +275,12 @@ export function VoiceProvider({ children }: { children: ReactNode }) { // Get deployment ID const deploymentId = deploymentIdRef.current || '21'; + // Log which API type we're using + console.log('[VoiceContext] Using API type:', voiceApiType); + // Build request params const requestParams: Record = { - function: 'ask_wellnuo_ai', + function: voiceApiType, // Use the selected voiceApiType clientId: 'MA_001', user_name: WELLNUO_USER, token: token, @@ -313,7 +342,7 @@ export function VoiceProvider({ children }: { children: ReactNode }) { return null; } }, - [getWellNuoToken, addTranscriptEntry] + [getWellNuoToken, addTranscriptEntry, voiceApiType] ); /** @@ -454,6 +483,8 @@ export function VoiceProvider({ children }: { children: ReactNode }) { speak, stopSpeaking, interruptIfSpeaking, + voiceApiType, + updateVoiceApiType, }} > {children}