mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-23 03:40:14 +01:00
* WIP: end session endpoint * refactor: move useGetBannerQuery outside of package * refactor: add queriesEnabled and move useGetEndpointsConfigQuery to data-provider (local) * refactor: move useGetEndpointsQuery import to data-provider * refactor: relocate useGetEndpointsQuery import to improve module organization * refactor: move `useGetStartupConfig` from package to `~/data-provider` * refactor: move useGetUserBalance to data-provider and update imports * refactor: update query enabled conditions to include config check * refactor: remove unused useConfigOverride import from useAppStartup * refactor: integrate queriesEnabled state into file and search queries and move useGetSearchEnabledQuery to data-provider (local) * refactor: move useGetUserQuery to data-provider and update imports * refactor: enhance loginUser mutation with success and error handling as pass in options to hook * refactor: update enabled condition in queries to handle undefined config * refactor: enhance authentication mutations with queriesEnabled state management * refactor: improve conditional rendering for error messages and feature flags in Login component * refactor: remove unused queriesEnabled state from AuthContextProvider * refactor: implement queriesEnabled state management in LoginLayout with timeout handling * refactor: add conditional check for end session endpoint in OpenID strategy * ci: fix tests after changes * refactor: remove endSessionEndpoint from user schema and update logoutController to use OpenID issuer's end_session_endpoint * refactor: update logoutController to use end_session_endpoint from issuer metadata
147 lines
5.3 KiB
TypeScript
147 lines
5.3 KiB
TypeScript
import { useMemo } from 'react';
|
|
import { EModelEndpoint, Constants } from 'librechat-data-provider';
|
|
import type * as t from 'librechat-data-provider';
|
|
import type { ReactNode } from 'react';
|
|
import { useChatContext, useAgentsMapContext, useAssistantsMapContext } from '~/Providers';
|
|
import {
|
|
useGetAssistantDocsQuery,
|
|
useGetEndpointsQuery,
|
|
useGetStartupConfig,
|
|
} from '~/data-provider';
|
|
import ConvoIcon from '~/components/Endpoints/ConvoIcon';
|
|
import { getIconEndpoint, getEntity, cn } from '~/utils';
|
|
import { useLocalize, useSubmitMessage } from '~/hooks';
|
|
import { TooltipAnchor } from '~/components/ui';
|
|
import { BirthdayIcon } from '~/components/svg';
|
|
import ConvoStarter from './ConvoStarter';
|
|
|
|
export default function Landing({ Header }: { Header?: ReactNode }) {
|
|
const { conversation } = useChatContext();
|
|
const agentsMap = useAgentsMapContext();
|
|
const assistantMap = useAssistantsMapContext();
|
|
const { data: startupConfig } = useGetStartupConfig();
|
|
const { data: endpointsConfig } = useGetEndpointsQuery();
|
|
|
|
const localize = useLocalize();
|
|
|
|
let { endpoint = '' } = conversation ?? {};
|
|
|
|
if (
|
|
endpoint === EModelEndpoint.chatGPTBrowser ||
|
|
endpoint === EModelEndpoint.azureOpenAI ||
|
|
endpoint === EModelEndpoint.gptPlugins
|
|
) {
|
|
endpoint = EModelEndpoint.openAI;
|
|
}
|
|
|
|
const iconURL = conversation?.iconURL;
|
|
endpoint = getIconEndpoint({ endpointsConfig, iconURL, endpoint });
|
|
const { data: documentsMap = new Map() } = useGetAssistantDocsQuery(endpoint, {
|
|
select: (data) => new Map(data.map((dbA) => [dbA.assistant_id, dbA])),
|
|
});
|
|
|
|
const { entity, isAgent, isAssistant } = getEntity({
|
|
endpoint,
|
|
agentsMap,
|
|
assistantMap,
|
|
agent_id: conversation?.agent_id,
|
|
assistant_id: conversation?.assistant_id,
|
|
});
|
|
|
|
const name = entity?.name ?? '';
|
|
const description = entity?.description ?? '';
|
|
const avatar = isAgent
|
|
? (entity as t.Agent | undefined)?.avatar?.filepath ?? ''
|
|
: ((entity as t.Assistant | undefined)?.metadata?.avatar as string | undefined) ?? '';
|
|
const conversation_starters = useMemo(() => {
|
|
/* The user made updates, use client-side cache, or they exist in an Agent */
|
|
if (entity && (entity.conversation_starters?.length ?? 0) > 0) {
|
|
return entity.conversation_starters;
|
|
}
|
|
if (isAgent) {
|
|
return entity?.conversation_starters ?? [];
|
|
}
|
|
|
|
/* If none in cache, we use the latest assistant docs */
|
|
const entityDocs = documentsMap.get(entity?.id ?? '');
|
|
return entityDocs?.conversation_starters ?? [];
|
|
}, [documentsMap, isAgent, entity]);
|
|
|
|
const containerClassName =
|
|
'shadow-stroke relative flex h-full items-center justify-center rounded-full bg-white text-black';
|
|
|
|
const { submitMessage } = useSubmitMessage();
|
|
const sendConversationStarter = (text: string) => submitMessage({ text });
|
|
|
|
const getWelcomeMessage = () => {
|
|
const greeting = conversation?.greeting ?? '';
|
|
if (greeting) {
|
|
return greeting;
|
|
}
|
|
|
|
if (isAssistant) {
|
|
return localize('com_nav_welcome_assistant');
|
|
}
|
|
|
|
if (isAgent) {
|
|
return localize('com_nav_welcome_agent');
|
|
}
|
|
|
|
return localize('com_nav_welcome_message');
|
|
};
|
|
|
|
return (
|
|
<div className="relative h-full">
|
|
<div className="absolute left-0 right-0">{Header != null ? Header : null}</div>
|
|
<div className="flex h-full flex-col items-center justify-center">
|
|
<div className={cn('relative h-12 w-12', name && avatar ? 'mb-0' : 'mb-3')}>
|
|
<ConvoIcon
|
|
agentsMap={agentsMap}
|
|
assistantMap={assistantMap}
|
|
conversation={conversation}
|
|
endpointsConfig={endpointsConfig}
|
|
containerClassName={containerClassName}
|
|
context="landing"
|
|
className="h-2/3 w-2/3"
|
|
size={41}
|
|
/>
|
|
{startupConfig?.showBirthdayIcon === true ? (
|
|
<TooltipAnchor
|
|
className="absolute bottom-8 right-2.5"
|
|
description={localize('com_ui_happy_birthday')}
|
|
>
|
|
<BirthdayIcon />
|
|
</TooltipAnchor>
|
|
) : null}
|
|
</div>
|
|
{name ? (
|
|
<div className="flex flex-col items-center gap-0 p-2">
|
|
<div className="text-center text-2xl font-medium dark:text-white">{name}</div>
|
|
<div className="max-w-md text-center text-sm font-normal text-text-primary ">
|
|
{description ? description : localize('com_nav_welcome_message')}
|
|
</div>
|
|
{/* <div className="mt-1 flex items-center gap-1 text-token-text-tertiary">
|
|
<div className="text-sm text-token-text-tertiary">By Daniel Avila</div>
|
|
</div> */}
|
|
</div>
|
|
) : (
|
|
<h2 className="mb-5 max-w-[75vh] px-12 text-center text-lg font-medium dark:text-white md:px-0 md:text-2xl">
|
|
{getWelcomeMessage()}
|
|
</h2>
|
|
)}
|
|
<div className="mt-8 flex flex-wrap justify-center gap-3 px-4">
|
|
{conversation_starters.length > 0 &&
|
|
conversation_starters
|
|
.slice(0, Constants.MAX_CONVO_STARTERS)
|
|
.map((text: string, index: number) => (
|
|
<ConvoStarter
|
|
key={index}
|
|
text={text}
|
|
onClick={() => sendConversationStarter(text)}
|
|
/>
|
|
))}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|