mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 17:00:15 +01:00
* Decouple mcp config from start up config * Chore: Work on AI Review and Copilot Comments - setRawConfig is not needed since the private raw config is not needed any more - !!serversLoading bug fixed - added unit tests for route /api/mcp/servers - copilot comments addressed * chore: remove comments * chore: rename data-provider dir for MCP * chore: reorganize mcp specific query hooks * fix: consolidate imports for MCP server manager * chore: add dev-staging branch to frontend review workflow triggers * feat: add GitHub Actions workflow for building and pushing Docker images to GitHub Container Registry and Docker Hub * fix: update label for tag input in BookmarkForm tests to improve clarity --------- Co-authored-by: Atef Bellaaj <slalom.bellaaj@external.daimlertruck.com> Co-authored-by: Danny Avila <danny@librechat.ai>
75 lines
2.1 KiB
TypeScript
75 lines
2.1 KiB
TypeScript
import { useEffect } from 'react';
|
|
import { useRecoilState } from 'recoil';
|
|
import TagManager from 'react-gtm-module';
|
|
import { LocalStorageKeys } from 'librechat-data-provider';
|
|
import type { TStartupConfig, TUser } from 'librechat-data-provider';
|
|
import { cleanupTimestampedStorage } from '~/utils/timestamps';
|
|
import useSpeechSettingsInit from './useSpeechSettingsInit';
|
|
import { useMCPToolsQuery, useMCPServersQuery } from '~/data-provider';
|
|
import store from '~/store';
|
|
|
|
export default function useAppStartup({
|
|
startupConfig,
|
|
user,
|
|
}: {
|
|
startupConfig?: TStartupConfig;
|
|
user?: TUser;
|
|
}) {
|
|
const [defaultPreset, setDefaultPreset] = useRecoilState(store.defaultPreset);
|
|
|
|
useSpeechSettingsInit(!!user);
|
|
const { data: loadedServers, isLoading: serversLoading } = useMCPServersQuery();
|
|
|
|
useMCPToolsQuery({
|
|
enabled: !serversLoading && !!loadedServers && Object.keys(loadedServers).length > 0 && !!user,
|
|
});
|
|
|
|
/** Clean up old localStorage entries on startup */
|
|
useEffect(() => {
|
|
cleanupTimestampedStorage();
|
|
}, []);
|
|
|
|
/** Set the app title */
|
|
useEffect(() => {
|
|
const appTitle = startupConfig?.appTitle ?? '';
|
|
if (!appTitle) {
|
|
return;
|
|
}
|
|
document.title = appTitle;
|
|
localStorage.setItem(LocalStorageKeys.APP_TITLE, appTitle);
|
|
}, [startupConfig]);
|
|
|
|
/** Set the default spec's preset as default */
|
|
useEffect(() => {
|
|
if (defaultPreset && defaultPreset.spec != null) {
|
|
return;
|
|
}
|
|
|
|
const modelSpecs = startupConfig?.modelSpecs?.list;
|
|
|
|
if (!modelSpecs || !modelSpecs.length) {
|
|
return;
|
|
}
|
|
|
|
const defaultSpec = modelSpecs.find((spec) => spec.default);
|
|
|
|
if (!defaultSpec) {
|
|
return;
|
|
}
|
|
|
|
setDefaultPreset({
|
|
...defaultSpec.preset,
|
|
iconURL: defaultSpec.iconURL,
|
|
spec: defaultSpec.name,
|
|
});
|
|
}, [defaultPreset, setDefaultPreset, startupConfig?.modelSpecs?.list]);
|
|
|
|
useEffect(() => {
|
|
if (startupConfig?.analyticsGtmId != null && typeof window.google_tag_manager === 'undefined') {
|
|
const tagManagerArgs = {
|
|
gtmId: startupConfig.analyticsGtmId,
|
|
};
|
|
TagManager.initialize(tagManagerArgs);
|
|
}
|
|
}, [startupConfig?.analyticsGtmId]);
|
|
}
|