From 45a95ddcc5f16e033388d073208ffcdc91496b01 Mon Sep 17 00:00:00 2001 From: lukasIO Date: Tue, 20 Aug 2024 16:24:23 +0200 Subject: [PATCH] Tweaks to voice assistant hook (#946) --- packages/react/etc/components-react.api.md | 2 +- packages/react/src/hooks/useVoiceAssistant.ts | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/react/etc/components-react.api.md b/packages/react/etc/components-react.api.md index f0fefc3cd..f1c296de1 100644 --- a/packages/react/etc/components-react.api.md +++ b/packages/react/etc/components-react.api.md @@ -1239,7 +1239,7 @@ export interface VoiceAssistant { export const VoiceAssistantContext: React_2.Context; // @alpha (undocumented) -export type VoiceAssistantState = 'disconnected' | 'connecting' | 'listening' | 'thinking' | 'speaking'; +export type VoiceAssistantState = 'disconnected' | 'connecting' | 'initializing' | 'listening' | 'thinking' | 'speaking'; // @public (undocumented) export type WidgetState = { diff --git a/packages/react/src/hooks/useVoiceAssistant.ts b/packages/react/src/hooks/useVoiceAssistant.ts index 152fa86db..311cac3c7 100644 --- a/packages/react/src/hooks/useVoiceAssistant.ts +++ b/packages/react/src/hooks/useVoiceAssistant.ts @@ -14,6 +14,7 @@ import { useParticipantAttributes } from './useParticipantAttributes'; export type VoiceAssistantState = | 'disconnected' | 'connecting' + | 'initializing' | 'listening' | 'thinking' | 'speaking'; @@ -46,10 +47,14 @@ export function useVoiceAssistant(): VoiceAssistant { const state: VoiceAssistantState = React.useMemo(() => { if (connectionState === ConnectionState.Disconnected) { return 'disconnected'; - } else if (connectionState === ConnectionState.Connecting || !agent || !attributes?.state) { + } else if ( + connectionState === ConnectionState.Connecting || + !agent || + !attributes?.['agent.state'] + ) { return 'connecting'; } else { - return attributes.state as VoiceAssistantState; + return attributes['agent.state'] as VoiceAssistantState; } }, [attributes, agent, connectionState]);