mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-30 15:18:50 +01:00
* fix: load all existing conversation settings on refresh * refactor(buildDefaultConvo): use `lastConversationSetup.endpointType` before `conversation.endpointType` * refactor(TMessage/messageSchema): add `endpoint` field to messages to differentiate generation origin * feat(useNewConvo): `keepLatestMessage` param to prevent reseting the `latestMessage` mid-conversation * style(Settings): adjust height styling to allow more space in dialog for additional settings * feat: Modular Chat: experimental setting to Enable switching Endpoints mid-conversation * fix(ChatRoute): fix potential parsing issue with tPresetSchema
80 lines
2.5 KiB
TypeScript
80 lines
2.5 KiB
TypeScript
import { useRecoilValue } from 'recoil';
|
|
import { useEffect, useRef } from 'react';
|
|
import { useParams } from 'react-router-dom';
|
|
import {
|
|
useGetConvoIdQuery,
|
|
useGetModelsQuery,
|
|
useGetEndpointsQuery,
|
|
} from 'librechat-data-provider/react-query';
|
|
import { TPreset } from 'librechat-data-provider';
|
|
import { useNewConvo, useConfigOverride } from '~/hooks';
|
|
import ChatView from '~/components/Chat/ChatView';
|
|
import useAuthRedirect from './useAuthRedirect';
|
|
import { Spinner } from '~/components/svg';
|
|
import store from '~/store';
|
|
|
|
export default function ChatRoute() {
|
|
const index = 0;
|
|
useConfigOverride();
|
|
const { conversationId } = useParams();
|
|
const { conversation } = store.useCreateConversationAtom(index);
|
|
const modelsQueryEnabled = useRecoilValue(store.modelsQueryEnabled);
|
|
const { isAuthenticated } = useAuthRedirect();
|
|
const { newConversation } = useNewConvo();
|
|
const hasSetConversation = useRef(false);
|
|
|
|
const modelsQuery = useGetModelsQuery({ enabled: isAuthenticated && modelsQueryEnabled });
|
|
const initialConvoQuery = useGetConvoIdQuery(conversationId ?? '', {
|
|
enabled: isAuthenticated && conversationId !== 'new',
|
|
});
|
|
const endpointsQuery = useGetEndpointsQuery({ enabled: isAuthenticated && modelsQueryEnabled });
|
|
|
|
useEffect(() => {
|
|
if (
|
|
conversationId === 'new' &&
|
|
endpointsQuery.data &&
|
|
modelsQuery.data &&
|
|
!hasSetConversation.current
|
|
) {
|
|
newConversation({ modelsData: modelsQuery.data });
|
|
hasSetConversation.current = true;
|
|
} else if (
|
|
initialConvoQuery.data &&
|
|
endpointsQuery.data &&
|
|
modelsQuery.data &&
|
|
!hasSetConversation.current
|
|
) {
|
|
newConversation({
|
|
template: initialConvoQuery.data,
|
|
/* this is necessary to load all existing settings */
|
|
preset: initialConvoQuery.data as TPreset,
|
|
modelsData: modelsQuery.data,
|
|
});
|
|
hasSetConversation.current = true;
|
|
}
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, [initialConvoQuery.data, modelsQuery.data, endpointsQuery.data]);
|
|
|
|
if (endpointsQuery.isLoading || modelsQuery.isLoading) {
|
|
return <Spinner className="m-auto dark:text-white" />;
|
|
}
|
|
|
|
if (!isAuthenticated) {
|
|
return null;
|
|
}
|
|
|
|
// if not a conversation
|
|
if (conversation?.conversationId === 'search') {
|
|
return null;
|
|
}
|
|
// if conversationId not match
|
|
if (conversation?.conversationId !== conversationId && !conversation) {
|
|
return null;
|
|
}
|
|
// if conversationId is null
|
|
if (!conversationId) {
|
|
return null;
|
|
}
|
|
|
|
return <ChatView index={index} />;
|
|
}
|