diff --git a/api/server/middleware/abortRun.js b/api/server/middleware/abortRun.js index 2b8a95724c..6db6329d44 100644 --- a/api/server/middleware/abortRun.js +++ b/api/server/middleware/abortRun.js @@ -75,7 +75,6 @@ async function abortRun(req, res) { }); const finalEvent = { - title: 'New Chat', final: true, conversation, runMessages, diff --git a/api/server/routes/assistants/chat.js b/api/server/routes/assistants/chat.js index c47cb8cb14..69be8a7b3e 100644 --- a/api/server/routes/assistants/chat.js +++ b/api/server/routes/assistants/chat.js @@ -247,7 +247,6 @@ router.post('/', validateModel, buildEndpointOption, setHeaders, async (req, res } finalEvent = { - title: 'New Chat', final: true, conversation: await getConvo(req.user.id, conversationId), runMessages, @@ -477,7 +476,6 @@ router.post('/', validateModel, buildEndpointOption, setHeaders, async (req, res conversation = { conversationId, - title: 'New Chat', endpoint: EModelEndpoint.assistants, promptPrefix: promptPrefix, instructions: instructions, @@ -607,7 +605,6 @@ router.post('/', validateModel, buildEndpointOption, setHeaders, async (req, res }; sendMessage(res, { - title: 'New Chat', final: true, conversation, requestMessage: { diff --git a/client/src/data-provider/mutations.ts b/client/src/data-provider/mutations.ts index f81baa2543..a38ff09a33 100644 --- a/client/src/data-provider/mutations.ts +++ b/client/src/data-provider/mutations.ts @@ -68,6 +68,7 @@ export const useGenTitleMutation = (): UseMutationResult< title: response.title, } as TConversation); }); + document.title = response.title; }, }); }; diff --git a/client/src/hooks/SSE/useSSE.ts b/client/src/hooks/SSE/useSSE.ts index 1f586abf99..84c3449123 100644 --- a/client/src/hooks/SSE/useSSE.ts +++ b/client/src/hooks/SSE/useSSE.ts @@ -192,10 +192,19 @@ export default function useSSE(submission: TSubmission | null, index = 0) { let update = {} as TConversation; setConversation((prevState) => { + let title = prevState?.title; + const parentId = requestMessage.parentMessageId; + if (parentId !== Constants.NO_PARENT && title?.toLowerCase()?.includes('new chat')) { + const convos = queryClient.getQueryData([QueryKeys.allConversations]); + const cachedConvo = getConversationById(convos, conversationId); + title = cachedConvo?.title; + } + update = tConvoUpdateSchema.parse({ ...prevState, conversationId, thread_id, + title, messages: [requestMessage.messageId, responseMessage.messageId], }) as TConversation;