@@ -126,22 +126,23 @@ export type ConversationInstance = (ConversationStateConnecting | ConversationSt
126126 * AgentSession represents a connection to a LiveKit Agent, providing abstractions to make 1:1
127127 * agent/participant rooms easier to work with.
128128 */
129- export function useConversationWith ( agentToDispatch : string | RoomAgentDispatch , options : ConversationOptions ) : ConversationInstance {
129+ export function useConversationWith ( agentToDispatch : string | RoomAgentDispatch | null , options : ConversationOptions ) : ConversationInstance {
130130 const roomFromContext = useMaybeRoomContext ( ) ;
131131 const room = useMemo ( ( ) => roomFromContext ?? options . room ?? new Room ( ) , [ roomFromContext , options . room ] ) ;
132132
133133 const emitter = useMemo ( ( ) => new EventEmitter ( ) as TypedEventEmitter < ConversationCallbacks > , [ ] ) ;
134134
135- const agentName = typeof agentToDispatch === 'string' ? agentToDispatch : agentToDispatch . agentName ;
135+ const agentName = typeof agentToDispatch === 'string' ? agentToDispatch : agentToDispatch ? .agentName ;
136136 useEffect ( ( ) => {
137- const agentDispatch = typeof agentToDispatch === 'string' ? (
137+ const roomAgentDispatch = typeof agentToDispatch === 'string' ? (
138138 new RoomAgentDispatch ( { agentName : agentToDispatch , metadata : '' } )
139139 ) : agentToDispatch ;
140- options . credentials . setRequest ( {
141- roomConfig : new RoomConfiguration ( {
142- agents : [ agentDispatch ] ,
143- } ) ,
144- } ) ;
140+ const roomConfig = roomAgentDispatch ? (
141+ new RoomConfiguration ( {
142+ agents : [ roomAgentDispatch ] ,
143+ } )
144+ ) : undefined ;
145+ options . credentials . setRequest ( { roomConfig } ) ;
145146
146147 return ( ) => {
147148 options . credentials . clearRequest ( ) ;
@@ -372,3 +373,7 @@ export function useConversationWith(agentToDispatch: string | RoomAgentDispatch,
372373 end ,
373374 ] ) ;
374375}
376+
377+ export function useConversation ( options : ConversationOptions ) : ConversationInstance {
378+ return useConversationWith ( null , options ) ;
379+ }
0 commit comments