2023-12-05 09:38:04 -05:00
|
|
|
import { useChatContext } from '~/Providers/ChatContext';
|
2025-02-03 10:53:04 -05:00
|
|
|
import { useGetEndpointsQuery } from '~/data-provider';
|
2024-01-04 10:17:15 -05:00
|
|
|
import { getEndpointField } from '~/utils';
|
2023-12-05 09:38:04 -05:00
|
|
|
import useUserKey from './useUserKey';
|
|
|
|
|
|
|
|
|
|
export default function useRequiresKey() {
|
|
|
|
|
const { conversation } = useChatContext();
|
|
|
|
|
const { data: endpointsConfig } = useGetEndpointsQuery();
|
|
|
|
|
const { endpoint } = conversation || {};
|
2024-01-04 10:17:15 -05:00
|
|
|
const userProvidesKey: boolean | null | undefined = getEndpointField(
|
|
|
|
|
endpointsConfig,
|
|
|
|
|
endpoint,
|
|
|
|
|
'userProvide',
|
|
|
|
|
);
|
2023-12-05 09:38:04 -05:00
|
|
|
const { getExpiry } = useUserKey(endpoint ?? '');
|
|
|
|
|
const expiryTime = getExpiry();
|
|
|
|
|
const requiresKey = !expiryTime && userProvidesKey;
|
|
|
|
|
return { requiresKey };
|
|
|
|
|
}
|