Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active
TypeScript aianthropicartifactsawsazurechatgptchatgpt-cloneclaudeclonedeepseekgeminigooglegpt-5librechatmcpo1openairesponses-apivisionwebui
import { useMemo } from 'react';
import { useRecoilValue } from 'recoil';
import {
AgentCapabilities,
Permissions,
PermissionTypes,
isTwoFactorPolicyProvider,
} from 'librechat-data-provider';
import type { SettingsContextValue } from './types';
import { useGetStartupConfig, usePullRequestConnectionStatus } from '~/data-provider';
import useProviderKeys from '../SettingsTabs/ProviderKeys/useProviderKeys';
import { useHasAccess, useAuthContext, useGetAgentsConfig } from '~/hooks';
import usePersonalizationAccess from '~/hooks/usePersonalizationAccess';
import { hasAnalyticsGtmId } from '~/store/analytics';
import store from '~/store';
export function useSettingsContext(): SettingsContextValue {
const { user } = useAuthContext();
const { data: startupConfig } = useGetStartupConfig();
const { agentsConfig } = useGetAgentsConfig();
const pullRequestConnection = usePullRequestConnectionStatus();
const { hasAnyPersonalizationFeature, hasMemoryOptOut } = usePersonalizationAccess();
const hasRemoteAgents = useHasAccess({
permissionType: PermissionTypes.REMOTE_AGENTS,
permission: Permissions.USE,
});
const hasMultiConvo = useHasAccess({
permissionType: PermissionTypes.MULTI_CONVO,
permission: Permissions.USE,
});
const hasPrompts = useHasAccess({
permissionType: PermissionTypes.PROMPTS,
permission: Permissions.USE,
});
const balanceEnabled = startupConfig?.balance?.enabled === true;
const langfuseConnectionAccess = startupConfig?.langfuseConnectionAccess === true;
const langfusePromptSyncAccess = startupConfig?.langfusePromptSyncAccess === true;
const adminPanelURL = startupConfig?.adminPanelURL ?? '';
const isLocalProvider = user?.provider === 'local';
const emailEnabled = startupConfig?.emailEnabled === true;
const allowEmailChange = startupConfig?.allowEmailChange === true;
const passkeyLoginEnabled = startupConfig?.passkeyLoginEnabled === true;
/** Also while a stored grant outlives its app, so it can still be disconnected. */
const hasPullRequestConnect =
pullRequestConnection?.connected === true ||
(startupConfig?.pullRequestsConnect != null && pullRequestConnection?.configured !== false);
const twoFactorPolicyProvider = user != null && isTwoFactorPolicyProvider(user.provider);
const twoFactorEnabled = user?.twoFactorEnabled === true;
const allowAccountDeletion = startupConfig?.allowAccountDeletion !== false;
const aboutEnabled = startupConfig?.interface?.buildInfo !== false;
/* Offered only once the deployment has answered, so an operator's opt-out never flashes the row. */
const mascotAllowed = startupConfig != null && startupConfig.interface?.mascot !== false;
/* Offered only once the deployment has answered, matching the capability hook the alerts
read: before then a toggle could store a preference, or raise the browser's permission
prompt, for a capability the operator turns off. */
const replyConfigLoaded = startupConfig != null;
const replyNotificationsConfig = startupConfig?.interface?.replyNotifications;
const replyTabBadgeAllowed = replyConfigLoaded && replyNotificationsConfig?.tabBadge !== false;
const replyNotificationsAllowed =
replyConfigLoaded && replyNotificationsConfig?.desktop !== false;
const replyNotificationSoundAllowed =
replyConfigLoaded && replyNotificationsConfig?.sound !== false;
/* No toggle when the deployment granted consent for everyone: there is no choice to change. */
const analyticsConfigured =
hasAnalyticsGtmId(startupConfig?.analyticsGtmId) &&
startupConfig?.interface?.analyticsConsent !== false;
const hasRemoteAgentsBool = hasRemoteAgents === true;
const hasMultiConvoBool = hasMultiConvo === true;
const hasPromptsBool = hasPrompts === true;
const engineTTS = useRecoilValue<string>(store.engineTTS);
const hasUserProvidedEndpoints = useProviderKeys().length > 0;
const hasStatefulCodeSessions =
agentsConfig?.capabilities.includes(AgentCapabilities.stateful_code_sessions) ?? false;
return useMemo(
() => ({
balanceEnabled,
hasAnyPersonalizationFeature,
hasMemoryOptOut,
hasStatefulCodeSessions,
hasRemoteAgents: hasRemoteAgentsBool,
hasUserProvidedEndpoints,
hasMultiConvo: hasMultiConvoBool,
hasPrompts: hasPromptsBool,
isLocalProvider,
emailEnabled,
allowEmailChange,
passkeyLoginEnabled,
hasPullRequestConnect,
isTwoFactorPolicyProvider: twoFactorPolicyProvider,
twoFactorEnabled,
allowAccountDeletion,
aboutEnabled,
mascotAllowed,
engineTTS,
langfuseConnectionAccess,
langfusePromptSyncAccess,
adminPanelURL,
replyTabBadgeAllowed,
replyNotificationsAllowed,
replyNotificationSoundAllowed,
analyticsConfigured,
}),
[
balanceEnabled,
hasAnyPersonalizationFeature,
hasMemoryOptOut,
hasStatefulCodeSessions,
hasRemoteAgentsBool,
hasUserProvidedEndpoints,
hasMultiConvoBool,
hasPromptsBool,
isLocalProvider,
emailEnabled,
allowEmailChange,
passkeyLoginEnabled,
hasPullRequestConnect,
twoFactorPolicyProvider,
twoFactorEnabled,
allowAccountDeletion,
aboutEnabled,
mascotAllowed,
engineTTS,
langfuseConnectionAccess,
langfusePromptSyncAccess,
adminPanelURL,
replyTabBadgeAllowed,
replyNotificationsAllowed,
replyNotificationSoundAllowed,
analyticsConfigured,
],
);
}