@@ -23,10 +23,29 @@ export type AgentState =
2323 * @beta
2424 */
2525export interface VoiceAssistant {
26+ /**
27+ * The agent participant.
28+ */
2629 agent : RemoteParticipant | undefined ;
30+ /**
31+ * The current state of the agent.
32+ */
2733 state : AgentState ;
34+ /**
35+ * The microphone track published by the agent or associated avatar worker (if any).
36+ */
2837 audioTrack : TrackReference | undefined ;
38+ /**
39+ * The camera track published by the agent or associated avatar worker (if any).
40+ */
41+ videoTrack : TrackReference | undefined ;
42+ /**
43+ * The transcriptions of the agent's microphone track (if any).
44+ */
2945 agentTranscriptions : ReceivedTranscriptionSegment [ ] ;
46+ /**
47+ * The agent's participant attributes.
48+ */
3049 agentAttributes : RemoteParticipant [ 'attributes' ] | undefined ;
3150}
3251
@@ -42,8 +61,28 @@ const state_attribute = 'lk.agent.state';
4261 * @beta
4362 */
4463export function useVoiceAssistant ( ) : VoiceAssistant {
45- const agent = useRemoteParticipants ( ) . find ( ( p ) => p . kind === ParticipantKind . AGENT ) ;
46- const audioTrack = useParticipantTracks ( [ Track . Source . Microphone ] , agent ?. identity ) [ 0 ] ;
64+ const remoteParticipants = useRemoteParticipants ( ) ;
65+ const agent = remoteParticipants . find (
66+ ( p ) => p . kind === ParticipantKind . AGENT && ! ( 'lk.publish_on_behalf' in p . attributes ) ,
67+ ) ;
68+ const worker = remoteParticipants . find (
69+ ( p ) =>
70+ p . kind === ParticipantKind . AGENT && p . attributes [ 'lk.publish_on_behalf' ] === agent ?. identity ,
71+ ) ;
72+ const agentTracks = useParticipantTracks (
73+ [ Track . Source . Microphone , Track . Source . Camera ] ,
74+ agent ?. identity ,
75+ ) ;
76+ const workerTracks = useParticipantTracks (
77+ [ Track . Source . Microphone , Track . Source . Camera ] ,
78+ worker ?. identity ,
79+ ) ;
80+ const audioTrack =
81+ agentTracks . find ( ( t ) => t . source === Track . Source . Microphone ) ??
82+ workerTracks . find ( ( t ) => t . source === Track . Source . Microphone ) ;
83+ const videoTrack =
84+ agentTracks . find ( ( t ) => t . source === Track . Source . Camera ) ??
85+ workerTracks . find ( ( t ) => t . source === Track . Source . Camera ) ;
4786 const { segments : agentTranscriptions } = useTrackTranscription ( audioTrack ) ;
4887 const connectionState = useConnectionState ( ) ;
4988 const { attributes } = useParticipantAttributes ( { participant : agent } ) ;
@@ -66,6 +105,7 @@ export function useVoiceAssistant(): VoiceAssistant {
66105 agent,
67106 state,
68107 audioTrack,
108+ videoTrack,
69109 agentTranscriptions,
70110 agentAttributes : attributes ,
71111 } ;
0 commit comments