Skip to content

Commit

Permalink
always use bot client
Browse files Browse the repository at this point in the history
  • Loading branch information
popestr committed Jul 9, 2024
1 parent 20dc668 commit b361376
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 25 deletions.
14 changes: 3 additions & 11 deletions packages/chat-headless/src/ChatHeadlessImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import { isChatEventClient } from "./models/clients/ChatEventClient";
export class ChatHeadlessImpl implements ChatHeadless {
private config: HeadlessConfig;
private chatClient: ChatClient;
private botClient: ChatClient;
private clients: ChatClient[];
private stateManager: ReduxStateManager;
private chatAnalyticsService: ChatAnalyticsService;
Expand Down Expand Up @@ -71,6 +72,7 @@ export class ChatHeadlessImpl implements ChatHeadless {
// bot client is the default client.
// If agent client is provided, it will be used as the second client on handoff
this.chatClient = botClient ?? provideChatCore(this.config);
this.botClient = this.chatClient;
this.clients = [this.chatClient];
if (agentClient) {
this.clients.push(agentClient);
Expand Down Expand Up @@ -266,17 +268,7 @@ export class ChatHeadlessImpl implements ChatHeadless {
restartConversation() {
if (isChatEventClient(this.chatClient)) {
this.chatClient.resetSession();
let nextClient: ChatClient | undefined = undefined;
for (const client of this.clients) {
if (this.chatClient !== client) {
nextClient = client;
}
}
if (!nextClient) {
console.warn("No next client available during conversation reset.");
return;
}
this.chatClient = nextClient;
this.chatClient = this.botClient;
}

this.setConversationId(undefined);
Expand Down
15 changes: 1 addition & 14 deletions packages/chat-headless/tests/chatheadless.clients.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ it("update state on events from event client", async () => {
expect(headless.state.conversation.isLoading).toBeFalsy();
});

it("resets session and uses next client on reset", async () => {
it("resets session and uses bot client on reset", async () => {
const botClient = createMockHttpClient([
{ message: createMessage("message 1"), notes: {}, integrationDetails: {} }, //trigger handoff
{ message: createMessage("message 2"), notes: {} },
Expand Down Expand Up @@ -156,19 +156,6 @@ it("resets session and uses next client on reset", async () => {
expect(botClient.getNextMessage).toHaveBeenCalledTimes(2);
});

it("logs warning when only one client exists and agent session is reset", async () => {
const agentClient = createMockEventClient();
const headless = provideChatHeadless(config, { bot: agentClient });

// reset session, but no agent client exists
const consoleWarnSpy = jest.spyOn(console, "warn").mockImplementation();
headless.restartConversation();
expect(consoleWarnSpy).toBeCalledTimes(1);
expect(consoleWarnSpy).toBeCalledWith(
"No next client available during conversation reset."
);
});

function createMessage(text: string): Message {
return {
text,
Expand Down

0 comments on commit b361376

Please sign in to comment.