mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-01-10 04:28:50 +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
85 lines
3.2 KiB
TypeScript
85 lines
3.2 KiB
TypeScript
import { EModelEndpoint, getEndpointField } from 'librechat-data-provider';
|
|
import type { TEndpointsConfig, TConfig } from 'librechat-data-provider';
|
|
import { getAvailableEndpoints, getEndpointsFilter, mapEndpoints } from './endpoints';
|
|
|
|
const mockEndpointsConfig: TEndpointsConfig = {
|
|
[EModelEndpoint.openAI]: { type: undefined, iconURL: 'openAI_icon.png', order: 0 },
|
|
[EModelEndpoint.google]: { type: undefined, iconURL: 'google_icon.png', order: 1 },
|
|
Mistral: { type: EModelEndpoint.custom, iconURL: 'custom_icon.png', order: 2 },
|
|
};
|
|
|
|
describe('getEndpointField', () => {
|
|
it('returns undefined if endpointsConfig is undefined', () => {
|
|
expect(getEndpointField(undefined, EModelEndpoint.openAI, 'type')).toBeUndefined();
|
|
});
|
|
|
|
it('returns undefined if endpoint is null', () => {
|
|
expect(getEndpointField(mockEndpointsConfig, null, 'type')).toBeUndefined();
|
|
});
|
|
|
|
it('returns undefined if endpoint is undefined', () => {
|
|
expect(getEndpointField(mockEndpointsConfig, undefined, 'type')).toBeUndefined();
|
|
});
|
|
|
|
it('returns the correct value for a valid endpoint and property', () => {
|
|
expect(getEndpointField(mockEndpointsConfig, EModelEndpoint.openAI, 'order')).toEqual(0);
|
|
expect(getEndpointField(mockEndpointsConfig, EModelEndpoint.google, 'iconURL')).toEqual(
|
|
'google_icon.png',
|
|
);
|
|
});
|
|
|
|
it('returns undefined for a valid endpoint but an invalid property', () => {
|
|
/* Type assertion as 'nonexistentProperty' is intentionally not a valid property of TConfig */
|
|
expect(
|
|
getEndpointField(
|
|
mockEndpointsConfig,
|
|
EModelEndpoint.openAI,
|
|
'nonexistentProperty' as keyof TConfig,
|
|
),
|
|
).toBeUndefined();
|
|
});
|
|
|
|
it('returns the correct value for a non-enum endpoint and valid property', () => {
|
|
expect(getEndpointField(mockEndpointsConfig, 'Mistral', 'type')).toEqual(EModelEndpoint.custom);
|
|
});
|
|
|
|
it('returns undefined for a non-enum endpoint with an invalid property', () => {
|
|
expect(
|
|
getEndpointField(mockEndpointsConfig, 'Mistral', 'nonexistentProperty' as keyof TConfig),
|
|
).toBeUndefined();
|
|
});
|
|
});
|
|
|
|
describe('getEndpointsFilter', () => {
|
|
it('returns an empty object if endpointsConfig is undefined', () => {
|
|
expect(getEndpointsFilter(undefined)).toEqual({});
|
|
});
|
|
|
|
it('returns a filter object based on endpointsConfig', () => {
|
|
const expectedFilter = {
|
|
[EModelEndpoint.openAI]: true,
|
|
[EModelEndpoint.google]: true,
|
|
Mistral: true,
|
|
};
|
|
expect(getEndpointsFilter(mockEndpointsConfig)).toEqual(expectedFilter);
|
|
});
|
|
});
|
|
|
|
describe('getAvailableEndpoints', () => {
|
|
it('returns available endpoints based on filter and config', () => {
|
|
const filter = {
|
|
[EModelEndpoint.openAI]: true,
|
|
[EModelEndpoint.google]: false,
|
|
Mistral: true,
|
|
};
|
|
const expectedEndpoints = [EModelEndpoint.openAI, 'Mistral'];
|
|
expect(getAvailableEndpoints(filter, mockEndpointsConfig)).toEqual(expectedEndpoints);
|
|
});
|
|
});
|
|
|
|
describe('mapEndpoints', () => {
|
|
it('returns sorted available endpoints', () => {
|
|
const expectedOrder = [EModelEndpoint.openAI, EModelEndpoint.google, 'Mistral'];
|
|
expect(mapEndpoints(mockEndpointsConfig)).toEqual(expectedOrder);
|
|
});
|
|
});
|