Skip to content

Commit 45a95dd

Browse files
authored
Tweaks to voice assistant hook (#946)
1 parent d35dffd commit 45a95dd

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

packages/react/etc/components-react.api.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1239,7 +1239,7 @@ export interface VoiceAssistant {
12391239
export const VoiceAssistantContext: React_2.Context<VoiceAssistant | undefined>;
12401240

12411241
// @alpha (undocumented)
1242-
export type VoiceAssistantState = 'disconnected' | 'connecting' | 'listening' | 'thinking' | 'speaking';
1242+
export type VoiceAssistantState = 'disconnected' | 'connecting' | 'initializing' | 'listening' | 'thinking' | 'speaking';
12431243

12441244
// @public (undocumented)
12451245
export type WidgetState = {

packages/react/src/hooks/useVoiceAssistant.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { useParticipantAttributes } from './useParticipantAttributes';
1414
export type VoiceAssistantState =
1515
| 'disconnected'
1616
| 'connecting'
17+
| 'initializing'
1718
| 'listening'
1819
| 'thinking'
1920
| 'speaking';
@@ -46,10 +47,14 @@ export function useVoiceAssistant(): VoiceAssistant {
4647
const state: VoiceAssistantState = React.useMemo(() => {
4748
if (connectionState === ConnectionState.Disconnected) {
4849
return 'disconnected';
49-
} else if (connectionState === ConnectionState.Connecting || !agent || !attributes?.state) {
50+
} else if (
51+
connectionState === ConnectionState.Connecting ||
52+
!agent ||
53+
!attributes?.['agent.state']
54+
) {
5055
return 'connecting';
5156
} else {
52-
return attributes.state as VoiceAssistantState;
57+
return attributes['agent.state'] as VoiceAssistantState;
5358
}
5459
}, [attributes, agent, connectionState]);
5560

0 commit comments

Comments
 (0)