mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-02-14 22:48:10 +01:00
42 lines
1.4 KiB
TypeScript
42 lines
1.4 KiB
TypeScript
|
|
import { useRecoilValue } from 'recoil';
|
||
|
|
import { QueryKeys, dataService } from 'librechat-data-provider';
|
||
|
|
import { useQuery } from '@tanstack/react-query';
|
||
|
|
import type { QueryObserverResult, UseQueryOptions } from '@tanstack/react-query';
|
||
|
|
import type t from 'librechat-data-provider';
|
||
|
|
import store from '~/store';
|
||
|
|
|
||
|
|
export const useGetEndpointsQuery = <TData = t.TEndpointsConfig>(
|
||
|
|
config?: UseQueryOptions<t.TEndpointsConfig, unknown, TData>,
|
||
|
|
): QueryObserverResult<TData> => {
|
||
|
|
const queriesEnabled = useRecoilValue<boolean>(store.queriesEnabled);
|
||
|
|
return useQuery<t.TEndpointsConfig, unknown, TData>(
|
||
|
|
[QueryKeys.endpoints],
|
||
|
|
() => dataService.getAIEndpoints(),
|
||
|
|
{
|
||
|
|
staleTime: Infinity,
|
||
|
|
refetchOnWindowFocus: false,
|
||
|
|
refetchOnReconnect: false,
|
||
|
|
refetchOnMount: false,
|
||
|
|
...config,
|
||
|
|
enabled: (config?.enabled ?? true) === true && queriesEnabled,
|
||
|
|
},
|
||
|
|
);
|
||
|
|
};
|
||
|
|
|
||
|
|
export const useGetStartupConfig = (
|
||
|
|
config?: UseQueryOptions<t.TStartupConfig>,
|
||
|
|
): QueryObserverResult<t.TStartupConfig> => {
|
||
|
|
const queriesEnabled = useRecoilValue<boolean>(store.queriesEnabled);
|
||
|
|
return useQuery<t.TStartupConfig>(
|
||
|
|
[QueryKeys.startupConfig],
|
||
|
|
() => dataService.getStartupConfig(),
|
||
|
|
{
|
||
|
|
refetchOnWindowFocus: false,
|
||
|
|
refetchOnReconnect: false,
|
||
|
|
refetchOnMount: false,
|
||
|
|
...config,
|
||
|
|
enabled: (config?.enabled ?? true) === true && queriesEnabled,
|
||
|
|
},
|
||
|
|
);
|
||
|
|
};
|