mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-20 18:30:15 +01:00
* fix(TEndpointsConfig): resolve property access issues with typesafe helper function * fix: undefined or null endpoint edge case * refactor(mapEndpoints -> endpoints): renamed module to be more general for endpoint handling, wrote unit tests, export all helpers
19 lines
708 B
TypeScript
19 lines
708 B
TypeScript
import { useGetEndpointsQuery } from 'librechat-data-provider/react-query';
|
|
import { useChatContext } from '~/Providers/ChatContext';
|
|
import { getEndpointField } from '~/utils';
|
|
import useUserKey from './useUserKey';
|
|
|
|
export default function useRequiresKey() {
|
|
const { conversation } = useChatContext();
|
|
const { data: endpointsConfig } = useGetEndpointsQuery();
|
|
const { endpoint } = conversation || {};
|
|
const userProvidesKey: boolean | null | undefined = getEndpointField(
|
|
endpointsConfig,
|
|
endpoint,
|
|
'userProvide',
|
|
);
|
|
const { getExpiry } = useUserKey(endpoint ?? '');
|
|
const expiryTime = getExpiry();
|
|
const requiresKey = !expiryTime && userProvidesKey;
|
|
return { requiresKey };
|
|
}
|