mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-01-26 20:26:13 +01:00
* feat: add filterFilesByEndpointConfig to filter disabled file processing by provider * chore: explicit define of endpointFileConfig for better debugging * refactor: move `normalizeEndpointName` to data-provider as used app-wide * chore: remove overrideEndpoint from useFileHandling * refactor: improve endpoint file config selection * refactor: update filterFilesByEndpointConfig to accept structured parameters and improve endpoint file config handling * refactor: replace defaultFileConfig with getEndpointFileConfig for improved file configuration handling across components * test: add comprehensive unit tests for getEndpointFileConfig to validate endpoint configuration handling * refactor: streamline agent endpoint assignment and improve file filtering logic * feat: add error handling for disabled file uploads in endpoint configuration * refactor: update encodeAndFormat functions to accept structured parameters for provider and endpoint * refactor: streamline requestFiles handling in initializeAgent function * fix: getEndpointFileConfig partial config merging scenarios * refactor: enhance mergeWithDefault function to support document-supported providers with comprehensive MIME types * refactor: user-configured default file config in getEndpointFileConfig * fix: prevent file handling when endpoint is disabled and file is dragged to chat * refactor: move `getEndpointField` to `data-provider` and update usage across components and hooks * fix: prioritize endpointType based on agent.endpoint in file filtering logic * fix: prioritize agent.endpoint in file filtering logic and remove unnecessary endpointType defaulting
74 lines
2.4 KiB
TypeScript
74 lines
2.4 KiB
TypeScript
import { logger } from '@librechat/data-schemas';
|
|
import {
|
|
EModelEndpoint,
|
|
removeNullishValues,
|
|
normalizeEndpointName,
|
|
} from 'librechat-data-provider';
|
|
import type { TCustomConfig, TEndpoint, TTransactionsConfig } from 'librechat-data-provider';
|
|
import type { AppConfig } from '@librechat/data-schemas';
|
|
import { isEnabled } from '~/utils';
|
|
|
|
/**
|
|
* Retrieves the balance configuration object
|
|
* */
|
|
export function getBalanceConfig(appConfig?: AppConfig): Partial<TCustomConfig['balance']> | null {
|
|
const isLegacyEnabled = isEnabled(process.env.CHECK_BALANCE);
|
|
const startBalance = process.env.START_BALANCE;
|
|
/** @type {} */
|
|
const config: Partial<TCustomConfig['balance']> = removeNullishValues({
|
|
enabled: isLegacyEnabled,
|
|
startBalance: startBalance != null && startBalance ? parseInt(startBalance, 10) : undefined,
|
|
});
|
|
if (!appConfig) {
|
|
return config;
|
|
}
|
|
return { ...config, ...(appConfig?.['balance'] ?? {}) };
|
|
}
|
|
|
|
/**
|
|
* Retrieves the transactions configuration object
|
|
* */
|
|
export function getTransactionsConfig(appConfig?: AppConfig): Partial<TTransactionsConfig> {
|
|
const defaultConfig: TTransactionsConfig = { enabled: true };
|
|
|
|
if (!appConfig) {
|
|
return defaultConfig;
|
|
}
|
|
|
|
const transactionsConfig = appConfig?.['transactions'] ?? defaultConfig;
|
|
const balanceConfig = getBalanceConfig(appConfig);
|
|
|
|
// If balance is enabled but transactions are disabled, force transactions to be enabled
|
|
// and log a warning
|
|
if (balanceConfig?.enabled && !transactionsConfig.enabled) {
|
|
logger.warn(
|
|
'Configuration warning: transactions.enabled=false is incompatible with balance.enabled=true. ' +
|
|
'Transactions will be enabled to ensure balance tracking works correctly.',
|
|
);
|
|
return { ...transactionsConfig, enabled: true };
|
|
}
|
|
|
|
return transactionsConfig;
|
|
}
|
|
|
|
export const getCustomEndpointConfig = ({
|
|
endpoint,
|
|
appConfig,
|
|
}: {
|
|
endpoint: string | EModelEndpoint;
|
|
appConfig?: AppConfig;
|
|
}): Partial<TEndpoint> | undefined => {
|
|
if (!appConfig) {
|
|
throw new Error(`Config not found for the ${endpoint} custom endpoint.`);
|
|
}
|
|
|
|
const customEndpoints = appConfig.endpoints?.[EModelEndpoint.custom] ?? [];
|
|
return customEndpoints.find(
|
|
(endpointConfig) => normalizeEndpointName(endpointConfig.name) === endpoint,
|
|
);
|
|
};
|
|
|
|
export function hasCustomUserVars(appConfig?: AppConfig): boolean {
|
|
const mcpServers = appConfig?.mcpConfig;
|
|
return Object.values(mcpServers ?? {}).some((server) => server?.customUserVars);
|
|
}
|