LibreChat/client/src/hooks/Input/useRequiresKey.ts

20 lines
708 B
TypeScript
Raw Normal View History

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 };
}