@@ -7,7 +7,7 @@ import { ParticipantAgentAttributes, TrackReference } from '@livekit/components-
7
7
8
8
import { useParticipantTracks } from './useParticipantTracks' ;
9
9
import { useRemoteParticipants } from './useRemoteParticipants' ;
10
- import { ConversationInstance } from './useConversationWith' ;
10
+ import { UseConversationReturn } from './useConversationWith' ;
11
11
12
12
// FIXME: make this 10 seconds once room dispatch booting info is discoverable
13
13
const DEFAULT_AGENT_CONNECT_TIMEOUT_MILLISECONDS = 20_000 ;
@@ -46,9 +46,7 @@ export type AgentCallbacks = {
46
46
[ AgentEvent . StateChanged ] : ( newAgentState : AgentState ) => void ;
47
47
} ;
48
48
49
- type AgentInstanceCommon = {
50
- [ Symbol . toStringTag ] : "AgentInstance" ;
51
-
49
+ type AgentStateCommon = {
52
50
// FIXME: maybe add some sort of schema to this?
53
51
attributes : Record < string , string > ;
54
52
@@ -60,7 +58,7 @@ type AgentInstanceCommon = {
60
58
} ;
61
59
} ;
62
60
63
- type AgentStateAvailable = AgentInstanceCommon & {
61
+ type AgentStateAvailable = AgentStateCommon & {
64
62
state : "thinking" | "speaking" ;
65
63
failureReasons : null ;
66
64
@@ -74,7 +72,7 @@ type AgentStateAvailable = AgentInstanceCommon & {
74
72
microphoneTrack : TrackReference | null ;
75
73
} ;
76
74
77
- type AgentStateAvailableListening = AgentInstanceCommon & {
75
+ type AgentStateAvailableListening = AgentStateCommon & {
78
76
state : "listening" ;
79
77
failureReasons : null ;
80
78
@@ -88,7 +86,7 @@ type AgentStateAvailableListening = AgentInstanceCommon & {
88
86
microphoneTrack : TrackReference | null ;
89
87
} ;
90
88
91
- type AgentStateUnAvailable = AgentInstanceCommon & {
89
+ type AgentStateUnAvailable = AgentStateCommon & {
92
90
state : "initializing" | "idle" ;
93
91
failureReasons : null ;
94
92
@@ -102,7 +100,7 @@ type AgentStateUnAvailable = AgentInstanceCommon & {
102
100
microphoneTrack : TrackReference | null ;
103
101
} ;
104
102
105
- type AgentStateConnecting = AgentInstanceCommon & {
103
+ type AgentStateConnecting = AgentStateCommon & {
106
104
state : "disconnected" | "connecting" ;
107
105
failureReasons : null ;
108
106
@@ -116,7 +114,7 @@ type AgentStateConnecting = AgentInstanceCommon & {
116
114
microphoneTrack : null ;
117
115
} ;
118
116
119
- type AgentStateFailed = AgentInstanceCommon & {
117
+ type AgentStateFailed = AgentStateCommon & {
120
118
state : "failed" ;
121
119
failureReasons : Array < string > ;
122
120
@@ -142,7 +140,7 @@ type AgentActions = {
142
140
} ;
143
141
144
142
type AgentStateCases = AgentStateConnecting | AgentStateAvailable | AgentStateAvailableListening | AgentStateUnAvailable | AgentStateFailed ;
145
- export type AgentInstance = AgentStateCases & AgentActions ;
143
+ export type UseAgentReturn = AgentStateCases & AgentActions ;
146
144
147
145
const generateDerivedStateValues = < State extends AgentState > ( state : State ) => ( {
148
146
isAvailable : (
@@ -235,12 +233,12 @@ const useAgentTimeoutIdStore = create<{
235
233
} ;
236
234
} ) ;
237
235
238
- type ConversationStub = Pick < ConversationInstance , 'connectionState' | 'subtle' > ;
236
+ type ConversationStub = Pick < UseConversationReturn , 'connectionState' | 'subtle' > ;
239
237
240
238
/**
241
239
* useAgent encapculates all agent state, normalizing some quirks around how LiveKit Agents work.
242
240
*/
243
- export function useAgent ( conversation : ConversationStub , _name ?: string ) : AgentInstance {
241
+ export function useAgent ( conversation : ConversationStub , _name ?: string ) : UseAgentReturn {
244
242
const { room } = conversation . subtle ;
245
243
246
244
const emitter = useMemo ( ( ) => new EventEmitter ( ) as TypedEventEmitter < AgentCallbacks > , [ ] ) ;
@@ -268,7 +266,7 @@ export function useAgent(conversation: ConversationStub, _name?: string): AgentI
268
266
return ;
269
267
}
270
268
271
- const handleAttributesChanged = ( attributes : AgentInstance [ "attributes" ] ) => {
269
+ const handleAttributesChanged = ( attributes : UseAgentReturn [ "attributes" ] ) => {
272
270
setAgentParticipantAttributes ( attributes ) ;
273
271
emitter . emit ( AgentEvent . AttributesChanged , attributes ) ;
274
272
} ;
@@ -397,9 +395,7 @@ export function useAgent(conversation: ConversationStub, _name?: string): AgentI
397
395
} , [ isConversationDisconnected , conversation . subtle . agentConnectTimeoutMilliseconds ] ) ;
398
396
399
397
const agentState : AgentStateCases = useMemo ( ( ) => {
400
- const common : AgentInstanceCommon = {
401
- [ Symbol . toStringTag ] : "AgentInstance" ,
402
-
398
+ const common : AgentStateCommon = {
403
399
attributes : agentParticipantAttributes ,
404
400
405
401
subtle : {
@@ -508,7 +504,7 @@ export function useAgent(conversation: ConversationStub, _name?: string): AgentI
508
504
} ;
509
505
const abortHandler = ( ) => {
510
506
cleanup ( ) ;
511
- reject ( new Error ( 'AgentInstance .waitUntilAvailable - signal aborted' ) ) ;
507
+ reject ( new Error ( 'useAgent .waitUntilAvailable - signal aborted' ) ) ;
512
508
} ;
513
509
514
510
const cleanup = ( ) => {
@@ -532,7 +528,7 @@ export function useAgent(conversation: ConversationStub, _name?: string): AgentI
532
528
} ;
533
529
const abortHandler = ( ) => {
534
530
cleanup ( ) ;
535
- reject ( new Error ( 'AgentInstance .waitUntilCamera - signal aborted' ) ) ;
531
+ reject ( new Error ( 'useAgent .waitUntilCamera - signal aborted' ) ) ;
536
532
} ;
537
533
538
534
const cleanup = ( ) => {
@@ -556,7 +552,7 @@ export function useAgent(conversation: ConversationStub, _name?: string): AgentI
556
552
} ;
557
553
const abortHandler = ( ) => {
558
554
cleanup ( ) ;
559
- reject ( new Error ( 'AgentInstance .waitUntilMicrophone - signal aborted' ) ) ;
555
+ reject ( new Error ( 'useAgent .waitUntilMicrophone - signal aborted' ) ) ;
560
556
} ;
561
557
562
558
const cleanup = ( ) => {
0 commit comments