Skip to content
This repository was archived by the owner on Sep 29, 2025. It is now read-only.

Commit 052f373

Browse files
authored
(EAI-571) [UI] Support creating conversation on first message (#603)
1 parent 2e42cf4 commit 052f373

File tree

8 files changed

+331
-138
lines changed

8 files changed

+331
-138
lines changed

packages/mongodb-chatbot-ui/src/InputBarTrigger.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,6 @@ export function InputBarTrigger({
125125
if (conversation.messages.length > 0) {
126126
openChat();
127127
}
128-
if (!conversation.conversationId) {
129-
await conversation.createConversation();
130-
}
131128
}}
132129
onFocus={() => {
133130
setFocused(true);

packages/mongodb-chatbot-ui/src/conversationStore.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
import { combine } from "zustand/middleware";
77
import createMessage, { CreateMessageArgs } from "./createMessage";
88
import { References } from "./references";
9-
import { removeArrayElementAt } from "./utils";
9+
import { nonProd, removeArrayElementAt } from "./utils";
1010

1111
export type ConversationState = {
1212
conversationId?: string;
@@ -49,12 +49,32 @@ export type ConversationStore = ReturnType<typeof makeConversationStore>;
4949

5050
export const makeConversationStore = (name = "default") => {
5151
return createStore(
52-
combine(initialConversationState, (set) => ({
52+
combine(initialConversationState, (set, get) => ({
5353
name,
5454
api: {
5555
initialize: (initialState: ConversationState) => {
5656
set(initialState);
5757
},
58+
setConversationId: (conversationId: string) => {
59+
if (conversationId === "") {
60+
nonProd(() => {
61+
console.warn("Attempted to set an empty conversation ID");
62+
});
63+
return;
64+
}
65+
if (get().conversationId) {
66+
nonProd(() => {
67+
console.warn(
68+
"Attempted to set a conversation ID when one is already set"
69+
);
70+
});
71+
return;
72+
}
73+
set((prevState) => ({
74+
...prevState,
75+
conversationId,
76+
}));
77+
},
5878
setConversationError: (errorMessage: string) => {
5979
set((prevState) => ({
6080
...prevState,

0 commit comments

Comments
 (0)