mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-19 01:40:15 +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
221 lines
6.3 KiB
TypeScript
221 lines
6.3 KiB
TypeScript
import { useMemo } from 'react';
|
|
import { useGetModelsQuery } from 'librechat-data-provider/react-query';
|
|
import {
|
|
alternateName,
|
|
EModelEndpoint,
|
|
isAgentsEndpoint,
|
|
getConfigDefaults,
|
|
isAssistantsEndpoint,
|
|
} from 'librechat-data-provider';
|
|
import type { TAssistantsMap, TEndpointsConfig } from 'librechat-data-provider';
|
|
import type { MentionOption } from '~/common';
|
|
import {
|
|
useGetPresetsQuery,
|
|
useGetEndpointsQuery,
|
|
useListAgentsQuery,
|
|
useGetStartupConfig,
|
|
} from '~/data-provider';
|
|
import useAssistantListMap from '~/hooks/Assistants/useAssistantListMap';
|
|
import { mapEndpoints, getPresetTitle } from '~/utils';
|
|
import { EndpointIcon } from '~/components/Endpoints';
|
|
|
|
const defaultInterface = getConfigDefaults().interface;
|
|
|
|
const assistantMapFn =
|
|
({
|
|
endpoint,
|
|
assistantMap,
|
|
endpointsConfig,
|
|
}: {
|
|
endpoint: EModelEndpoint | string;
|
|
assistantMap: TAssistantsMap;
|
|
endpointsConfig: TEndpointsConfig;
|
|
}) =>
|
|
({ id, name, description }) => ({
|
|
type: endpoint,
|
|
label: name ?? '',
|
|
value: id,
|
|
description: description ?? '',
|
|
icon: EndpointIcon({
|
|
conversation: { assistant_id: id, endpoint },
|
|
containerClassName: 'shadow-stroke overflow-hidden rounded-full',
|
|
endpointsConfig: endpointsConfig,
|
|
context: 'menu-item',
|
|
assistantMap,
|
|
size: 20,
|
|
}),
|
|
});
|
|
|
|
export default function useMentions({
|
|
assistantMap,
|
|
includeAssistants,
|
|
}: {
|
|
assistantMap: TAssistantsMap;
|
|
includeAssistants: boolean;
|
|
}) {
|
|
const { data: presets } = useGetPresetsQuery();
|
|
const { data: modelsConfig } = useGetModelsQuery();
|
|
const { data: startupConfig } = useGetStartupConfig();
|
|
const { data: endpointsConfig } = useGetEndpointsQuery();
|
|
const { data: endpoints = [] } = useGetEndpointsQuery({
|
|
select: mapEndpoints,
|
|
});
|
|
const listMap = useAssistantListMap((res) =>
|
|
res.data.map(({ id, name, description }) => ({
|
|
id,
|
|
name,
|
|
description,
|
|
})),
|
|
);
|
|
const { data: agentsList = null } = useListAgentsQuery(undefined, {
|
|
select: (res) => {
|
|
const { data } = res;
|
|
return data.map(({ id, name, avatar }) => ({
|
|
value: id,
|
|
label: name ?? '',
|
|
type: EModelEndpoint.agents,
|
|
icon: EndpointIcon({
|
|
conversation: {
|
|
agent_id: id,
|
|
endpoint: EModelEndpoint.agents,
|
|
iconURL: avatar?.filepath,
|
|
},
|
|
containerClassName: 'shadow-stroke overflow-hidden rounded-full',
|
|
endpointsConfig: endpointsConfig,
|
|
context: 'menu-item',
|
|
size: 20,
|
|
}),
|
|
}));
|
|
},
|
|
});
|
|
const assistantListMap = useMemo(
|
|
() => ({
|
|
[EModelEndpoint.assistants]: listMap[EModelEndpoint.assistants]
|
|
?.map(
|
|
assistantMapFn({
|
|
endpoint: EModelEndpoint.assistants,
|
|
assistantMap,
|
|
endpointsConfig,
|
|
}),
|
|
)
|
|
?.filter(Boolean),
|
|
[EModelEndpoint.azureAssistants]: listMap[EModelEndpoint.azureAssistants]
|
|
?.map(
|
|
assistantMapFn({
|
|
endpoint: EModelEndpoint.azureAssistants,
|
|
assistantMap,
|
|
endpointsConfig,
|
|
}),
|
|
)
|
|
?.filter(Boolean),
|
|
}),
|
|
[listMap, assistantMap, endpointsConfig],
|
|
);
|
|
|
|
const modelSpecs = useMemo(() => startupConfig?.modelSpecs?.list ?? [], [startupConfig]);
|
|
const interfaceConfig = useMemo(
|
|
() => startupConfig?.interface ?? defaultInterface,
|
|
[startupConfig],
|
|
);
|
|
|
|
const options: MentionOption[] = useMemo(() => {
|
|
let validEndpoints = endpoints;
|
|
if (!includeAssistants) {
|
|
validEndpoints = endpoints.filter((endpoint) => !isAssistantsEndpoint(endpoint));
|
|
}
|
|
|
|
const modelOptions = validEndpoints.flatMap((endpoint) => {
|
|
if (isAssistantsEndpoint(endpoint) || isAgentsEndpoint(endpoint)) {
|
|
return [];
|
|
}
|
|
|
|
const models = (modelsConfig?.[endpoint] ?? []).map((model) => ({
|
|
value: endpoint,
|
|
label: model,
|
|
type: 'model' as const,
|
|
icon: EndpointIcon({
|
|
conversation: { endpoint, model },
|
|
endpointsConfig,
|
|
context: 'menu-item',
|
|
size: 20,
|
|
}),
|
|
}));
|
|
return models;
|
|
});
|
|
|
|
const mentions = [
|
|
...(modelSpecs.length > 0 ? modelSpecs : []).map((modelSpec) => ({
|
|
value: modelSpec.name,
|
|
label: modelSpec.label,
|
|
description: modelSpec.description,
|
|
icon: EndpointIcon({
|
|
conversation: {
|
|
...modelSpec.preset,
|
|
iconURL: modelSpec.iconURL,
|
|
},
|
|
endpointsConfig,
|
|
context: 'menu-item',
|
|
size: 20,
|
|
}),
|
|
type: 'modelSpec' as const,
|
|
})),
|
|
...(interfaceConfig.endpointsMenu === true ? validEndpoints : []).map((endpoint) => ({
|
|
value: endpoint,
|
|
label: alternateName[endpoint as string] ?? endpoint ?? '',
|
|
type: 'endpoint' as const,
|
|
icon: EndpointIcon({
|
|
conversation: { endpoint },
|
|
endpointsConfig,
|
|
context: 'menu-item',
|
|
size: 20,
|
|
}),
|
|
})),
|
|
...(agentsList ?? []),
|
|
...(endpointsConfig?.[EModelEndpoint.assistants] && includeAssistants
|
|
? assistantListMap[EModelEndpoint.assistants] || []
|
|
: []),
|
|
...(endpointsConfig?.[EModelEndpoint.azureAssistants] && includeAssistants
|
|
? assistantListMap[EModelEndpoint.azureAssistants] || []
|
|
: []),
|
|
...((interfaceConfig.presets === true ? presets : [])?.map((preset, index) => ({
|
|
value: preset.presetId ?? `preset-${index}`,
|
|
label: preset.title ?? preset.modelLabel ?? preset.chatGptLabel ?? '',
|
|
description: getPresetTitle(preset, true),
|
|
icon: EndpointIcon({
|
|
conversation: preset,
|
|
containerClassName: 'shadow-stroke overflow-hidden rounded-full',
|
|
endpointsConfig: endpointsConfig,
|
|
context: 'menu-item',
|
|
assistantMap,
|
|
size: 20,
|
|
}),
|
|
type: 'preset' as const,
|
|
})) ?? []),
|
|
...modelOptions,
|
|
];
|
|
|
|
return mentions;
|
|
}, [
|
|
presets,
|
|
endpoints,
|
|
modelSpecs,
|
|
agentsList,
|
|
assistantMap,
|
|
modelsConfig,
|
|
endpointsConfig,
|
|
assistantListMap,
|
|
includeAssistants,
|
|
interfaceConfig.presets,
|
|
interfaceConfig.endpointsMenu,
|
|
]);
|
|
|
|
return {
|
|
options,
|
|
presets,
|
|
modelSpecs,
|
|
agentsList,
|
|
modelsConfig,
|
|
endpointsConfig,
|
|
assistantListMap,
|
|
};
|
|
}
|