Skip to content

Commit 000f3a3

Browse files
📢 fix: Invalid engineTTS and Conversation State on Navigation (#6904)
* fix: handle invalid engineTTS values and prevent VoiceDropdown render errors * refactor: add verbose developer logging for debugging conversation state issues * refactor: remove unnecessary effect for conversationId changes * chore: imports * fix: include model and entity IDs in conversation query selection * feat: add fetchFreshData function to retrieve conversation data on navigation * fix: remove unnecessary comment in fetchFreshData function * chore: reorder imports in useNavigateToConvo for consistency --------- Co-authored-by: Danny Avila <[email protected]>
1 parent d32f34e commit 000f3a3

File tree

11 files changed

+75
-18
lines changed

11 files changed

+75
-18
lines changed

api/models/Conversation.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,9 @@ module.exports = {
192192

193193
try {
194194
const convos = await Conversation.find(query)
195-
.select('conversationId endpoint title createdAt updatedAt user')
195+
.select(
196+
'conversationId endpoint title createdAt updatedAt user model agent_id assistant_id',
197+
)
196198
.sort({ updatedAt: order === 'asc' ? 1 : -1 })
197199
.limit(limit + 1)
198200
.lean();

client/src/components/Nav/SettingsTabs/Speech/Speech.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,14 @@ function Speech() {
136136
// eslint-disable-next-line react-hooks/exhaustive-deps
137137
}, [data]);
138138

139+
// Reset engineTTS if it is set to a removed/invalid value (e.g., 'edge')
140+
useEffect(() => {
141+
const validEngines = ['browser', 'external'];
142+
if (!validEngines.includes(engineTTS)) {
143+
setEngineTTS('browser');
144+
}
145+
}, [engineTTS, setEngineTTS]);
146+
139147
logger.log({ sttExternal, ttsExternal });
140148

141149
const contentRef = useRef(null);

client/src/components/Nav/SettingsTabs/Speech/TTS/VoiceDropdown.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,9 @@ export default function VoiceDropdown() {
1212
const engineTTS = useRecoilValue<string>(store.engineTTS);
1313
const VoiceDropdownComponent = voiceDropdownComponentsMap[engineTTS];
1414

15+
if (!VoiceDropdownComponent) {
16+
return null;
17+
}
18+
1519
return <VoiceDropdownComponent />;
1620
}

client/src/hooks/Agents/useSelectAgent.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import { EModelEndpoint, isAgentsEndpoint, Constants, QueryKeys } from 'librecha
44
import type { TConversation, TPreset, Agent } from 'librechat-data-provider';
55
import useDefaultConvo from '~/hooks/Conversations/useDefaultConvo';
66
import { useAgentsMapContext } from '~/Providers/AgentsMapContext';
7-
import { useGetAgentByIdQuery } from '~/data-provider';
87
import { useChatContext } from '~/Providers/ChatContext';
8+
import { useGetAgentByIdQuery } from '~/data-provider';
9+
import { logger } from '~/utils';
910

1011
export default function useSelectAgent() {
1112
const queryClient = useQueryClient();
@@ -22,6 +23,7 @@ export default function useSelectAgent() {
2223

2324
const updateConversation = useCallback(
2425
(agent: Partial<Agent>, template: Partial<TPreset | TConversation>) => {
26+
logger.log('conversation', 'Updating conversation with agent', agent);
2527
if (isAgentsEndpoint(conversation?.endpoint)) {
2628
const currentConvo = getDefaultConversation({
2729
conversation: { ...(conversation ?? {}), agent_id: agent.id },

client/src/hooks/Assistants/useSelectAssistant.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { AssistantsEndpoint, TConversation, TPreset } from 'librechat-data-
44
import useDefaultConvo from '~/hooks/Conversations/useDefaultConvo';
55
import { useChatContext } from '~/Providers/ChatContext';
66
import useAssistantListMap from './useAssistantListMap';
7-
import { mapAssistants } from '~/utils';
7+
import { mapAssistants, logger } from '~/utils';
88

99
export default function useSelectAssistant(endpoint: AssistantsEndpoint) {
1010
const getDefaultConversation = useDefaultConvo();
@@ -24,6 +24,7 @@ export default function useSelectAssistant(endpoint: AssistantsEndpoint) {
2424
conversationId: 'new',
2525
};
2626

27+
logger.log('conversation', 'Updating conversation with assistant', assistant);
2728
if (isAssistantsEndpoint(conversation?.endpoint)) {
2829
const currentConvo = getDefaultConversation({
2930
conversation: { ...(conversation ?? {}) },

client/src/hooks/Conversations/useGenerateConvo.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type {
1111
} from 'librechat-data-provider';
1212
import type { SetterOrUpdater } from 'recoil';
1313
import type { AssistantListItem } from '~/common';
14-
import { getEndpointField, buildDefaultConvo, getDefaultEndpoint } from '~/utils';
14+
import { getEndpointField, buildDefaultConvo, getDefaultEndpoint, logger } from '~/utils';
1515
import useAssistantListMap from '~/hooks/Assistants/useAssistantListMap';
1616
import { useGetEndpointsQuery } from '~/data-provider';
1717
import { mainTextareaId } from '~/common';
@@ -44,6 +44,7 @@ const useGenerateConvo = ({
4444
conversationId: rootConvo.conversationId,
4545
} as TConversation;
4646

47+
logger.log('conversation', 'Setting conversation from `useNewConvo`', update);
4748
return update;
4849
});
4950
}

client/src/hooks/Conversations/useNavigateToConvo.tsx

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import { useSetRecoilState } from 'recoil';
22
import { useNavigate } from 'react-router-dom';
33
import { useQueryClient } from '@tanstack/react-query';
4-
import { QueryKeys, EModelEndpoint, LocalStorageKeys, Constants } from 'librechat-data-provider';
4+
import {
5+
QueryKeys,
6+
Constants,
7+
dataService,
8+
EModelEndpoint,
9+
LocalStorageKeys,
10+
} from 'librechat-data-provider';
511
import type { TConversation, TEndpointsConfig, TModelsConfig } from 'librechat-data-provider';
612
import { buildDefaultConvo, getDefaultEndpoint, getEndpointField, logger } from '~/utils';
713
import store from '~/store';
@@ -14,6 +20,21 @@ const useNavigateToConvo = (index = 0) => {
1420
const setSubmission = useSetRecoilState(store.submissionByIndex(index));
1521
const { hasSetConversation, setConversation } = store.useCreateConversationAtom(index);
1622

23+
const fetchFreshData = async (conversationId?: string | null) => {
24+
if (!conversationId) {
25+
return;
26+
}
27+
try {
28+
const data = await queryClient.fetchQuery([QueryKeys.conversation, conversationId], () =>
29+
dataService.getConversationById(conversationId),
30+
);
31+
logger.log('conversation', 'Fetched fresh conversation data', data);
32+
setConversation(data);
33+
} catch (error) {
34+
console.error('Error fetching conversation data on navigation', error);
35+
}
36+
};
37+
1738
const navigateToConvo = (
1839
conversation?: TConversation | null,
1940
_resetLatestMessage = true,
@@ -23,6 +44,7 @@ const useNavigateToConvo = (index = 0) => {
2344
logger.warn('conversation', 'Conversation not provided to `navigateToConvo`');
2445
return;
2546
}
47+
logger.log('conversation', 'Navigating to conversation', conversation);
2648
hasSetConversation.current = true;
2749
setSubmission(null);
2850
if (_resetLatestMessage) {
@@ -60,6 +82,10 @@ const useNavigateToConvo = (index = 0) => {
6082
clearAllConversations(true);
6183
setConversation(convo);
6284
navigate(`/c/${convo.conversationId ?? Constants.NEW_CONVO}`);
85+
if (convo.conversationId !== Constants.NEW_CONVO && convo.conversationId) {
86+
queryClient.invalidateQueries([QueryKeys.conversation, convo.conversationId]);
87+
fetchFreshData(convo.conversationId);
88+
}
6389
};
6490

6591
const navigateWithLastTools = (

client/src/hooks/Input/useQueryParams.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
} from 'librechat-data-provider';
1212
import type { TPreset, TEndpointsConfig, TStartupConfig } from 'librechat-data-provider';
1313
import type { ZodAny } from 'zod';
14-
import { getConvoSwitchLogic, getModelSpecIconURL, removeUnavailableTools } from '~/utils';
14+
import { getConvoSwitchLogic, getModelSpecIconURL, removeUnavailableTools, logger } from '~/utils';
1515
import useDefaultConvo from '~/hooks/Conversations/useDefaultConvo';
1616
import { useChatContext, useChatFormContext } from '~/Providers';
1717
import useSubmitMessage from '~/hooks/Messages/useSubmitMessage';
@@ -159,6 +159,7 @@ export default function useQueryParams({
159159
});
160160

161161
/* We don't reset the latest message, only when changing settings mid-converstion */
162+
logger.log('conversation', 'Switching conversation from query params', currentConvo);
162163
newConversation({
163164
template: currentConvo,
164165
preset: newPreset,

client/src/hooks/Input/useSelectMention.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type {
99
TEndpointsConfig,
1010
} from 'librechat-data-provider';
1111
import type { MentionOption, ConvoGenerator } from '~/common';
12-
import { getConvoSwitchLogic, getModelSpecIconURL, removeUnavailableTools } from '~/utils';
12+
import { getConvoSwitchLogic, getModelSpecIconURL, removeUnavailableTools, logger } from '~/utils';
1313
import { useChatContext } from '~/Providers';
1414
import { useDefaultConvo } from '~/hooks';
1515
import store from '~/store';
@@ -86,6 +86,7 @@ export default function useSelectMention({
8686
});
8787

8888
/* We don't reset the latest message, only when changing settings mid-converstion */
89+
logger.info('conversation', 'Switching conversation to new spec (modular)', conversation);
8990
newConversation({
9091
template: currentConvo,
9192
preset,
@@ -95,6 +96,7 @@ export default function useSelectMention({
9596
return;
9697
}
9798

99+
logger.info('conversation', 'Switching conversation to new spec', conversation);
98100
newConversation({
99101
template: { ...(template as Partial<TConversation>) },
100102
preset,
@@ -172,6 +174,11 @@ export default function useSelectMention({
172174
});
173175

174176
/* We don't reset the latest message, only when changing settings mid-converstion */
177+
logger.info(
178+
'conversation',
179+
'Switching conversation to new endpoint/model (modular)',
180+
currentConvo,
181+
);
175182
newConversation({
176183
template: currentConvo,
177184
preset: currentConvo,
@@ -181,6 +188,7 @@ export default function useSelectMention({
181188
return;
182189
}
183190

191+
logger.info('conversation', 'Switching conversation to new endpoint/model', template);
184192
newConversation({
185193
template: { ...(template as Partial<TConversation>) },
186194
preset: { ...kwargs, spec: null, iconURL: null, modelLabel: null, endpoint: newEndpoint },
@@ -230,6 +238,7 @@ export default function useSelectMention({
230238
});
231239

232240
/* We don't reset the latest message, only when changing settings mid-converstion */
241+
logger.info('conversation', 'Switching conversation to new preset (modular)', currentConvo);
233242
newConversation({
234243
template: currentConvo,
235244
preset: newPreset,
@@ -239,6 +248,7 @@ export default function useSelectMention({
239248
return;
240249
}
241250

251+
logger.info('conversation', 'Switching conversation to new preset', template);
242252
newConversation({ preset: newPreset, keepAddedConvos: isModular });
243253
},
244254
[

client/src/hooks/useNewConvo.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import useAssistantListMap from './Assistants/useAssistantListMap';
3131
import { useResetChatBadges } from './useChatBadges';
3232
import { usePauseGlobalAudio } from './Audio';
3333
import { mainTextareaId } from '~/common';
34+
import { logger } from '~/utils';
3435
import store from '~/store';
3536

3637
const useNewConvo = (index = 0) => {
@@ -151,6 +152,7 @@ const useNewConvo = (index = 0) => {
151152
if (!(keepAddedConvos ?? false)) {
152153
clearAllConversations(true);
153154
}
155+
logger.log('conversation', 'Setting conversation from `useNewConvo`', conversation);
154156
setConversation(conversation);
155157
setSubmission({} as TSubmission);
156158
if (!(keepLatestMessage ?? false)) {

0 commit comments

Comments
 (0)