Skip to content

Commit b71db38

Browse files
committed
feat: add automatic agent dispatch version of hook
It's unclear if this is needed or not... Let's see what folks say during the review.
1 parent 4bb3f48 commit b71db38

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

packages/react/src/hooks/useConversationWith.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)