@@ -7,7 +7,7 @@ import { ParticipantAgentAttributes, TrackReference } from '@livekit/components-
77
88import { useParticipantTracks } from './useParticipantTracks' ;
99import { useRemoteParticipants } from './useRemoteParticipants' ;
10- import { ConversationInstance } from './useConversationWith' ;
10+ import { UseConversationReturn } from './useConversationWith' ;
1111
1212// FIXME: make this 10 seconds once room dispatch booting info is discoverable
1313const DEFAULT_AGENT_CONNECT_TIMEOUT_MILLISECONDS = 20_000 ;
@@ -46,9 +46,7 @@ export type AgentCallbacks = {
4646 [ AgentEvent . StateChanged ] : ( newAgentState : AgentState ) => void ;
4747} ;
4848
49- type AgentInstanceCommon = {
50- [ Symbol . toStringTag ] : "AgentInstance" ;
51-
49+ type AgentStateCommon = {
5250 // FIXME: maybe add some sort of schema to this?
5351 attributes : Record < string , string > ;
5452
@@ -60,7 +58,7 @@ type AgentInstanceCommon = {
6058 } ;
6159} ;
6260
63- type AgentStateAvailable = AgentInstanceCommon & {
61+ type AgentStateAvailable = AgentStateCommon & {
6462 state : "thinking" | "speaking" ;
6563 failureReasons : null ;
6664
@@ -74,7 +72,7 @@ type AgentStateAvailable = AgentInstanceCommon & {
7472 microphoneTrack : TrackReference | null ;
7573} ;
7674
77- type AgentStateAvailableListening = AgentInstanceCommon & {
75+ type AgentStateAvailableListening = AgentStateCommon & {
7876 state : "listening" ;
7977 failureReasons : null ;
8078
@@ -88,7 +86,7 @@ type AgentStateAvailableListening = AgentInstanceCommon & {
8886 microphoneTrack : TrackReference | null ;
8987} ;
9088
91- type AgentStateUnAvailable = AgentInstanceCommon & {
89+ type AgentStateUnAvailable = AgentStateCommon & {
9290 state : "initializing" | "idle" ;
9391 failureReasons : null ;
9492
@@ -102,7 +100,7 @@ type AgentStateUnAvailable = AgentInstanceCommon & {
102100 microphoneTrack : TrackReference | null ;
103101} ;
104102
105- type AgentStateConnecting = AgentInstanceCommon & {
103+ type AgentStateConnecting = AgentStateCommon & {
106104 state : "disconnected" | "connecting" ;
107105 failureReasons : null ;
108106
@@ -116,7 +114,7 @@ type AgentStateConnecting = AgentInstanceCommon & {
116114 microphoneTrack : null ;
117115} ;
118116
119- type AgentStateFailed = AgentInstanceCommon & {
117+ type AgentStateFailed = AgentStateCommon & {
120118 state : "failed" ;
121119 failureReasons : Array < string > ;
122120
@@ -142,7 +140,7 @@ type AgentActions = {
142140} ;
143141
144142type AgentStateCases = AgentStateConnecting | AgentStateAvailable | AgentStateAvailableListening | AgentStateUnAvailable | AgentStateFailed ;
145- export type AgentInstance = AgentStateCases & AgentActions ;
143+ export type UseAgentReturn = AgentStateCases & AgentActions ;
146144
147145const generateDerivedStateValues = < State extends AgentState > ( state : State ) => ( {
148146 isAvailable : (
@@ -235,12 +233,12 @@ const useAgentTimeoutIdStore = create<{
235233 } ;
236234} ) ;
237235
238- type ConversationStub = Pick < ConversationInstance , 'connectionState' | 'subtle' > ;
236+ type ConversationStub = Pick < UseConversationReturn , 'connectionState' | 'subtle' > ;
239237
240238/**
241239 * useAgent encapculates all agent state, normalizing some quirks around how LiveKit Agents work.
242240 */
243- export function useAgent ( conversation : ConversationStub , _name ?: string ) : AgentInstance {
241+ export function useAgent ( conversation : ConversationStub , _name ?: string ) : UseAgentReturn {
244242 const { room } = conversation . subtle ;
245243
246244 const emitter = useMemo ( ( ) => new EventEmitter ( ) as TypedEventEmitter < AgentCallbacks > , [ ] ) ;
@@ -268,7 +266,7 @@ export function useAgent(conversation: ConversationStub, _name?: string): AgentI
268266 return ;
269267 }
270268
271- const handleAttributesChanged = ( attributes : AgentInstance [ "attributes" ] ) => {
269+ const handleAttributesChanged = ( attributes : UseAgentReturn [ "attributes" ] ) => {
272270 setAgentParticipantAttributes ( attributes ) ;
273271 emitter . emit ( AgentEvent . AttributesChanged , attributes ) ;
274272 } ;
@@ -397,9 +395,7 @@ export function useAgent(conversation: ConversationStub, _name?: string): AgentI
397395 } , [ isConversationDisconnected , conversation . subtle . agentConnectTimeoutMilliseconds ] ) ;
398396
399397 const agentState : AgentStateCases = useMemo ( ( ) => {
400- const common : AgentInstanceCommon = {
401- [ Symbol . toStringTag ] : "AgentInstance" ,
402-
398+ const common : AgentStateCommon = {
403399 attributes : agentParticipantAttributes ,
404400
405401 subtle : {
@@ -508,7 +504,7 @@ export function useAgent(conversation: ConversationStub, _name?: string): AgentI
508504 } ;
509505 const abortHandler = ( ) => {
510506 cleanup ( ) ;
511- reject ( new Error ( 'AgentInstance .waitUntilAvailable - signal aborted' ) ) ;
507+ reject ( new Error ( 'useAgent .waitUntilAvailable - signal aborted' ) ) ;
512508 } ;
513509
514510 const cleanup = ( ) => {
@@ -532,7 +528,7 @@ export function useAgent(conversation: ConversationStub, _name?: string): AgentI
532528 } ;
533529 const abortHandler = ( ) => {
534530 cleanup ( ) ;
535- reject ( new Error ( 'AgentInstance .waitUntilCamera - signal aborted' ) ) ;
531+ reject ( new Error ( 'useAgent .waitUntilCamera - signal aborted' ) ) ;
536532 } ;
537533
538534 const cleanup = ( ) => {
@@ -556,7 +552,7 @@ export function useAgent(conversation: ConversationStub, _name?: string): AgentI
556552 } ;
557553 const abortHandler = ( ) => {
558554 cleanup ( ) ;
559- reject ( new Error ( 'AgentInstance .waitUntilMicrophone - signal aborted' ) ) ;
555+ reject ( new Error ( 'useAgent .waitUntilMicrophone - signal aborted' ) ) ;
560556 } ;
561557
562558 const cleanup = ( ) => {
0 commit comments