From 6a25dd38a48a40941f6583ec03e845490b11dafa Mon Sep 17 00:00:00 2001 From: Danny Avila Date: Fri, 23 Feb 2024 10:20:46 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=97=A8=EF=B8=8F=20fix:=20Prevent=20Resett?= =?UTF-8?q?ing=20Title=20to=20'New=20Chat'=20on=20Follow-Up=20Message=20?= =?UTF-8?q?=20(#1870)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: prevent reseting title to 'New Chat' on follow up message * chore(useSSE): remove empty line --- client/src/hooks/SSE/useSSE.ts | 19 ++++++++++++++++--- client/src/utils/convos.ts | 18 +++++++++++++++++- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/client/src/hooks/SSE/useSSE.ts b/client/src/hooks/SSE/useSSE.ts index 2fd96b460b..0752b8a7d2 100644 --- a/client/src/hooks/SSE/useSSE.ts +++ b/client/src/hooks/SSE/useSSE.ts @@ -24,7 +24,12 @@ import type { TSubmission, ConversationData, } from 'librechat-data-provider'; -import { addConversation, deleteConversation, updateConversation } from '~/utils'; +import { + addConversation, + deleteConversation, + updateConversation, + getConversationById, +} from '~/utils'; import { useGenTitleMutation } from '~/data-provider'; import useContentHandler from './useContentHandler'; import { useAuthContext } from '../AuthContext'; @@ -231,13 +236,21 @@ export default function useSSE(submission: TSubmission | null, index = 0) { ]); } - const { conversationId } = message; + const { conversationId, parentMessageId } = message; let update = {} as TConversation; setConversation((prevState) => { + let title = prevState?.title; + if (parentMessageId !== 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, + title, }) as TConversation; setStorage(update); @@ -248,7 +261,7 @@ export default function useSSE(submission: TSubmission | null, index = 0) { if (!convoData) { return convoData; } - if (message.parentMessageId === Constants.NO_PARENT) { + if (parentMessageId === Constants.NO_PARENT) { return addConversation(convoData, update); } else { return updateConversation(convoData, update); diff --git a/client/src/utils/convos.ts b/client/src/utils/convos.ts index c6f33e6d47..bbfcaea8e8 100644 --- a/client/src/utils/convos.ts +++ b/client/src/utils/convos.ts @@ -3,7 +3,6 @@ import { isToday, isWithinInterval, subDays, - getMonth, getYear, startOfDay, startOfYear, @@ -162,3 +161,20 @@ export const deleteConversation = ( return newData; }; + +export const getConversationById = ( + data: ConversationData | undefined, + conversationId: string | null, +): TConversation | undefined => { + if (!data || !conversationId) { + return undefined; + } + + for (const page of data.pages) { + const conversation = page.conversations.find((c) => c.conversationId === conversationId); + if (conversation) { + return conversation; + } + } + return undefined; +};