Skip to content

Commit

Permalink
make chat creation sync to ensure session not created if we have erro…
Browse files Browse the repository at this point in the history
…r with chat (due lack of credits or something else)
  • Loading branch information
dani-did committed Feb 5, 2025
1 parent ec60733 commit 68dee41
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions src/createAgentManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,8 @@ function initializeStreamAndChat(
outerReject(error);
};

let chatPromise;

if (!chat && options.mode !== ChatMode.DirectPlayback) {
chatPromise = newChat(agent.id, agentsApi, analytics, options.mode, options.persistentChat).catch(e => {
reject(e);
});
chat = await newChat(agent.id, agentsApi, analytics, options.mode, options.persistentChat);
}

const streamingManager = await createStreamingManager(
Expand All @@ -141,9 +137,6 @@ function initializeStreamAndChat(
...options.callbacks,
onConnectionStateChange: async state => {
if (state === ConnectionState.Connected) {
if (chatPromise) {
chat = await chatPromise;
}
if (streamingManager) {
options.callbacks.onConnectionStateChange?.(state);
resolve({ chat, streamingManager });
Expand Down Expand Up @@ -390,7 +383,7 @@ export async function createAgentManager(agent: string, options: AgentManagerOpt
items.streamingManager = streamingManager;
items.socketManager = socketManager;
items.chat = chat;

firstConnection = false;

changeMode(chat?.chat_mode ?? options.mode ?? ChatMode.Functional);
Expand Down

0 comments on commit 68dee41

Please sign in to comment.