mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-01-12 21:48:51 +01:00
* 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 <danny@librechat.ai>
50 lines
1.7 KiB
TypeScript
50 lines
1.7 KiB
TypeScript
import { useCallback } from 'react';
|
|
import { isAssistantsEndpoint } from 'librechat-data-provider';
|
|
import type { AssistantsEndpoint, TConversation, TPreset } from 'librechat-data-provider';
|
|
import useDefaultConvo from '~/hooks/Conversations/useDefaultConvo';
|
|
import { useChatContext } from '~/Providers/ChatContext';
|
|
import useAssistantListMap from './useAssistantListMap';
|
|
import { mapAssistants, logger } from '~/utils';
|
|
|
|
export default function useSelectAssistant(endpoint: AssistantsEndpoint) {
|
|
const getDefaultConversation = useDefaultConvo();
|
|
const { conversation, newConversation } = useChatContext();
|
|
const assistantMap = useAssistantListMap((res) => mapAssistants(res.data));
|
|
|
|
const onSelect = useCallback(
|
|
(value: string) => {
|
|
const assistant = assistantMap[endpoint]?.[value];
|
|
if (!assistant) {
|
|
return;
|
|
}
|
|
const template: Partial<TPreset | TConversation> = {
|
|
endpoint,
|
|
assistant_id: assistant.id,
|
|
model: assistant.model,
|
|
conversationId: 'new',
|
|
};
|
|
|
|
logger.log('conversation', 'Updating conversation with assistant', assistant);
|
|
if (isAssistantsEndpoint(conversation?.endpoint)) {
|
|
const currentConvo = getDefaultConversation({
|
|
conversation: { ...(conversation ?? {}) },
|
|
preset: template,
|
|
});
|
|
newConversation({
|
|
template: currentConvo,
|
|
preset: template as Partial<TPreset>,
|
|
keepLatestMessage: true,
|
|
});
|
|
return;
|
|
}
|
|
|
|
newConversation({
|
|
template: { ...(template as Partial<TConversation>) },
|
|
preset: template as Partial<TPreset>,
|
|
});
|
|
},
|
|
[endpoint, assistantMap, conversation, getDefaultConversation, newConversation],
|
|
);
|
|
|
|
return { onSelect };
|
|
}
|