| | const { CacheKeys } = require('librechat-data-provider'); |
| | const { logger, AppService } = require('@librechat/data-schemas'); |
| | const { loadAndFormatTools } = require('~/server/services/start/tools'); |
| | const loadCustomConfig = require('./loadCustomConfig'); |
| | const { setCachedTools } = require('./getCachedTools'); |
| | const getLogStores = require('~/cache/getLogStores'); |
| | const paths = require('~/config/paths'); |
| |
|
| | const BASE_CONFIG_KEY = '_BASE_'; |
| |
|
| | const loadBaseConfig = async () => { |
| | |
| | const config = (await loadCustomConfig()) ?? {}; |
| | |
| | const systemTools = loadAndFormatTools({ |
| | adminFilter: config.filteredTools, |
| | adminIncluded: config.includedTools, |
| | directory: paths.structuredTools, |
| | }); |
| | return AppService({ config, paths, systemTools }); |
| | }; |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | async function getAppConfig(options = {}) { |
| | const { role, refresh } = options; |
| |
|
| | const cache = getLogStores(CacheKeys.APP_CONFIG); |
| | const cacheKey = role ? role : BASE_CONFIG_KEY; |
| |
|
| | if (!refresh) { |
| | const cached = await cache.get(cacheKey); |
| | if (cached) { |
| | return cached; |
| | } |
| | } |
| |
|
| | let baseConfig = await cache.get(BASE_CONFIG_KEY); |
| | if (!baseConfig) { |
| | logger.info('[getAppConfig] App configuration not initialized. Initializing AppService...'); |
| | baseConfig = await loadBaseConfig(); |
| |
|
| | if (!baseConfig) { |
| | throw new Error('Failed to initialize app configuration through AppService.'); |
| | } |
| |
|
| | if (baseConfig.availableTools) { |
| | await setCachedTools(baseConfig.availableTools); |
| | } |
| |
|
| | await cache.set(BASE_CONFIG_KEY, baseConfig); |
| | } |
| |
|
| | |
| | |
| | if (role) { |
| | |
| | |
| | |
| | |
| | } |
| |
|
| | return baseConfig; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | async function clearAppConfigCache() { |
| | const cache = getLogStores(CacheKeys.CONFIG_STORE); |
| | const cacheKey = CacheKeys.APP_CONFIG; |
| | return await cache.delete(cacheKey); |
| | } |
| |
|
| | module.exports = { |
| | getAppConfig, |
| | clearAppConfigCache, |
| | }; |
| |
|