mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-01-25 19:56:13 +01:00
cleanup: code formatting and improve readability across multiple components
This commit is contained in:
parent
4808c5be48
commit
a06e999dd6
144 changed files with 608 additions and 648 deletions
|
|
@ -275,8 +275,7 @@ describe('ActionRequest', () => {
|
|||
expect(config?.headers).toEqual({
|
||||
'some-header': 'header-var',
|
||||
});
|
||||
expect(config?.params).toEqual({
|
||||
});
|
||||
expect(config?.params).toEqual({});
|
||||
expect(response.data.success).toBe(true);
|
||||
});
|
||||
|
||||
|
|
@ -285,13 +284,13 @@ describe('ActionRequest', () => {
|
|||
|
||||
const data: Record<string, unknown> = {
|
||||
'api-version': '2025-01-01',
|
||||
'message': 'a body parameter',
|
||||
message: 'a body parameter',
|
||||
'some-header': 'header-var',
|
||||
};
|
||||
|
||||
const loc: Record<string, 'query' | 'path' | 'header' | 'body'> = {
|
||||
'api-version': 'query',
|
||||
'message': 'body',
|
||||
message: 'body',
|
||||
'some-header': 'header',
|
||||
};
|
||||
|
||||
|
|
@ -326,13 +325,13 @@ describe('ActionRequest', () => {
|
|||
|
||||
const data: Record<string, unknown> = {
|
||||
'api-version': '2025-01-01',
|
||||
'message': 'a body parameter',
|
||||
message: 'a body parameter',
|
||||
'some-header': 'header-var',
|
||||
};
|
||||
|
||||
const loc: Record<string, 'query' | 'path' | 'header' | 'body'> = {
|
||||
'api-version': 'query',
|
||||
'message': 'body',
|
||||
message: 'body',
|
||||
'some-header': 'header',
|
||||
};
|
||||
|
||||
|
|
@ -367,13 +366,13 @@ describe('ActionRequest', () => {
|
|||
|
||||
const data: Record<string, unknown> = {
|
||||
'api-version': '2025-01-01',
|
||||
'message': 'a body parameter',
|
||||
message: 'a body parameter',
|
||||
'some-header': 'header-var',
|
||||
};
|
||||
|
||||
const loc: Record<string, 'query' | 'path' | 'header' | 'body'> = {
|
||||
'api-version': 'query',
|
||||
'message': 'body',
|
||||
message: 'body',
|
||||
'some-header': 'header',
|
||||
};
|
||||
|
||||
|
|
@ -443,7 +442,6 @@ describe('ActionRequest', () => {
|
|||
});
|
||||
expect(response.data.success).toBe(true);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
it('throws an error for unsupported HTTP method', async () => {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
/* eslint-disable jest/no-conditional-expect */
|
||||
import { ZodError, z } from 'zod';
|
||||
import { generateDynamicSchema, validateSettingDefinitions, OptionTypes } from '../src/generate';
|
||||
import type { SettingsConfiguration } from '../src/generate';
|
||||
|
|
@ -515,7 +514,7 @@ const settingsConfiguration: SettingsConfiguration = [
|
|||
{
|
||||
key: 'presence_penalty',
|
||||
description:
|
||||
'Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model\'s likelihood to talk about new topics.',
|
||||
"Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.",
|
||||
type: 'number',
|
||||
default: 0,
|
||||
range: {
|
||||
|
|
@ -529,7 +528,7 @@ const settingsConfiguration: SettingsConfiguration = [
|
|||
{
|
||||
key: 'frequency_penalty',
|
||||
description:
|
||||
'Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model\'s likelihood to repeat the same line verbatim.',
|
||||
"Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.",
|
||||
type: 'number',
|
||||
default: 0,
|
||||
range: {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,9 @@
|
|||
import { StdioOptionsSchema, StreamableHTTPOptionsSchema, processMCPEnv, MCPOptions } from '../src/mcp';
|
||||
import {
|
||||
StdioOptionsSchema,
|
||||
StreamableHTTPOptionsSchema,
|
||||
processMCPEnv,
|
||||
MCPOptions,
|
||||
} from '../src/mcp';
|
||||
|
||||
describe('Environment Variable Extraction (MCP)', () => {
|
||||
const originalEnv = process.env;
|
||||
|
|
@ -91,13 +96,13 @@ describe('Environment Variable Extraction (MCP)', () => {
|
|||
|
||||
// Type is now required, so parsing should fail
|
||||
expect(() => StreamableHTTPOptionsSchema.parse(options)).toThrow();
|
||||
|
||||
|
||||
// With type provided, it should pass
|
||||
const validOptions = {
|
||||
type: 'streamable-http' as const,
|
||||
url: 'https://example.com/api',
|
||||
};
|
||||
|
||||
|
||||
const result = StreamableHTTPOptionsSchema.parse(validOptions);
|
||||
expect(result.type).toBe('streamable-http');
|
||||
});
|
||||
|
|
@ -113,7 +118,7 @@ describe('Environment Variable Extraction (MCP)', () => {
|
|||
};
|
||||
|
||||
const result = StreamableHTTPOptionsSchema.parse(options);
|
||||
|
||||
|
||||
expect(result.headers).toEqual(options.headers);
|
||||
});
|
||||
});
|
||||
|
|
@ -262,7 +267,7 @@ describe('Environment Variable Extraction (MCP)', () => {
|
|||
'Content-Type': 'application/json',
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('should maintain streamable-http type in processed options', () => {
|
||||
const obj: MCPOptions = {
|
||||
type: 'streamable-http',
|
||||
|
|
|
|||
|
|
@ -303,7 +303,8 @@ class RequestExecutor {
|
|||
if (this.config.parameterLocations && this.params) {
|
||||
for (const key of Object.keys(this.params)) {
|
||||
// Determine parameter placement; default to "query" for GET and "body" for others.
|
||||
const loc: 'query' | 'path' | 'header' | 'body' = this.config.parameterLocations[key] || (method === 'get' ? 'query' : 'body');
|
||||
const loc: 'query' | 'path' | 'header' | 'body' =
|
||||
this.config.parameterLocations[key] || (method === 'get' ? 'query' : 'body');
|
||||
|
||||
const val = this.params[key];
|
||||
if (loc === 'query') {
|
||||
|
|
@ -351,7 +352,15 @@ export class ActionRequest {
|
|||
contentType: string,
|
||||
parameterLocations?: Record<string, 'query' | 'path' | 'header' | 'body'>,
|
||||
) {
|
||||
this.config = new RequestConfig(domain, path, method, operation, isConsequential, contentType, parameterLocations);
|
||||
this.config = new RequestConfig(
|
||||
domain,
|
||||
path,
|
||||
method,
|
||||
operation,
|
||||
isConsequential,
|
||||
contentType,
|
||||
parameterLocations,
|
||||
);
|
||||
}
|
||||
|
||||
// Add getters to maintain backward compatibility
|
||||
|
|
@ -486,12 +495,12 @@ export function openapiToFunction(
|
|||
}
|
||||
// Record the parameter location from the OpenAPI "in" field.
|
||||
paramLocations[paramName] =
|
||||
(resolvedParam.in === 'query' ||
|
||||
resolvedParam.in === 'path' ||
|
||||
resolvedParam.in === 'header' ||
|
||||
resolvedParam.in === 'body')
|
||||
? resolvedParam.in
|
||||
: 'query';
|
||||
resolvedParam.in === 'query' ||
|
||||
resolvedParam.in === 'path' ||
|
||||
resolvedParam.in === 'header' ||
|
||||
resolvedParam.in === 'body'
|
||||
? resolvedParam.in
|
||||
: 'query';
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -239,13 +239,13 @@ export function mapModelToAzureConfig({
|
|||
const { deploymentName = '', version = '' } =
|
||||
typeof modelDetails === 'object'
|
||||
? {
|
||||
deploymentName: modelDetails.deploymentName ?? groupConfig.deploymentName,
|
||||
version: modelDetails.version ?? groupConfig.version,
|
||||
}
|
||||
deploymentName: modelDetails.deploymentName ?? groupConfig.deploymentName,
|
||||
version: modelDetails.version ?? groupConfig.version,
|
||||
}
|
||||
: {
|
||||
deploymentName: groupConfig.deploymentName,
|
||||
version: groupConfig.version,
|
||||
};
|
||||
deploymentName: groupConfig.deploymentName,
|
||||
version: groupConfig.version,
|
||||
};
|
||||
|
||||
if (!deploymentName || !version) {
|
||||
throw new Error(
|
||||
|
|
@ -335,13 +335,13 @@ export function mapGroupToAzureConfig({
|
|||
const { deploymentName = '', version = '' } =
|
||||
typeof modelDetails === 'object'
|
||||
? {
|
||||
deploymentName: modelDetails.deploymentName ?? groupConfig.deploymentName,
|
||||
version: modelDetails.version ?? groupConfig.version,
|
||||
}
|
||||
deploymentName: modelDetails.deploymentName ?? groupConfig.deploymentName,
|
||||
version: modelDetails.version ?? groupConfig.version,
|
||||
}
|
||||
: {
|
||||
deploymentName: groupConfig.deploymentName,
|
||||
version: groupConfig.version,
|
||||
};
|
||||
deploymentName: groupConfig.deploymentName,
|
||||
version: groupConfig.version,
|
||||
};
|
||||
|
||||
if (!deploymentName || !version) {
|
||||
throw new Error(
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
/* eslint-disable max-len */
|
||||
import { z } from 'zod';
|
||||
import { EModelEndpoint } from './schemas';
|
||||
import type { FileConfig, EndpointFileConfig } from './types/files';
|
||||
|
|
|
|||
|
|
@ -467,7 +467,11 @@ export function validateSettingDefinitions(settings: SettingsConfiguration): voi
|
|||
}
|
||||
|
||||
/* Default value checks */
|
||||
if (setting.type === SettingTypes.Number && isNaN(setting.default as number) && setting.default != null) {
|
||||
if (
|
||||
setting.type === SettingTypes.Number &&
|
||||
isNaN(setting.default as number) &&
|
||||
setting.default != null
|
||||
) {
|
||||
errors.push({
|
||||
code: ZodIssueCode.custom,
|
||||
message: `Invalid default value for setting ${setting.key}. Must be a number.`,
|
||||
|
|
@ -475,7 +479,11 @@ export function validateSettingDefinitions(settings: SettingsConfiguration): voi
|
|||
});
|
||||
}
|
||||
|
||||
if (setting.type === SettingTypes.Boolean && typeof setting.default !== 'boolean' && setting.default != null) {
|
||||
if (
|
||||
setting.type === SettingTypes.Boolean &&
|
||||
typeof setting.default !== 'boolean' &&
|
||||
setting.default != null
|
||||
) {
|
||||
errors.push({
|
||||
code: ZodIssueCode.custom,
|
||||
message: `Invalid default value for setting ${setting.key}. Must be a boolean.`,
|
||||
|
|
@ -485,7 +493,8 @@ export function validateSettingDefinitions(settings: SettingsConfiguration): voi
|
|||
|
||||
if (
|
||||
(setting.type === SettingTypes.String || setting.type === SettingTypes.Enum) &&
|
||||
typeof setting.default !== 'string' && setting.default != null
|
||||
typeof setting.default !== 'string' &&
|
||||
setting.default != null
|
||||
) {
|
||||
errors.push({
|
||||
code: ZodIssueCode.custom,
|
||||
|
|
|
|||
|
|
@ -264,19 +264,19 @@ describe('convertJsonSchemaToZod', () => {
|
|||
properties: {
|
||||
name: {
|
||||
type: 'string',
|
||||
description: 'The user\'s name',
|
||||
description: "The user's name",
|
||||
},
|
||||
age: {
|
||||
type: 'number',
|
||||
description: 'The user\'s age',
|
||||
description: "The user's age",
|
||||
},
|
||||
},
|
||||
};
|
||||
const zodSchema = convertJsonSchemaToZod(schema);
|
||||
|
||||
const shape = (zodSchema as z.ZodObject<any>).shape;
|
||||
expect(shape.name.description).toBe('The user\'s name');
|
||||
expect(shape.age.description).toBe('The user\'s age');
|
||||
expect(shape.name.description).toBe("The user's name");
|
||||
expect(shape.age.description).toBe("The user's age");
|
||||
});
|
||||
|
||||
it('should preserve descriptions in nested objects', () => {
|
||||
|
|
@ -290,7 +290,7 @@ describe('convertJsonSchemaToZod', () => {
|
|||
properties: {
|
||||
name: {
|
||||
type: 'string',
|
||||
description: 'The user\'s name',
|
||||
description: "The user's name",
|
||||
},
|
||||
settings: {
|
||||
type: 'object',
|
||||
|
|
@ -318,7 +318,7 @@ describe('convertJsonSchemaToZod', () => {
|
|||
|
||||
const userShape = shape.user instanceof z.ZodObject ? shape.user.shape : {};
|
||||
if ('name' in userShape && 'settings' in userShape) {
|
||||
expect(userShape.name.description).toBe('The user\'s name');
|
||||
expect(userShape.name.description).toBe("The user's name");
|
||||
expect(userShape.settings.description).toBe('User preferences');
|
||||
|
||||
const settingsShape =
|
||||
|
|
@ -682,10 +682,7 @@ describe('convertJsonSchemaToZod', () => {
|
|||
name: { type: 'string' },
|
||||
age: { type: 'number' },
|
||||
},
|
||||
anyOf: [
|
||||
{ required: ['name'] },
|
||||
{ required: ['age'] },
|
||||
],
|
||||
anyOf: [{ required: ['name'] }, { required: ['age'] }],
|
||||
oneOf: [
|
||||
{ properties: { role: { type: 'string', enum: ['admin'] } } },
|
||||
{ properties: { role: { type: 'string', enum: ['user'] } } },
|
||||
|
|
@ -708,7 +705,7 @@ describe('convertJsonSchemaToZod', () => {
|
|||
it('should drop fields from nested schemas', () => {
|
||||
// Create a schema with nested fields that should be dropped
|
||||
const schema: JsonSchemaType & {
|
||||
properties?: Record<string, JsonSchemaType & { anyOf?: any; oneOf?: any }>
|
||||
properties?: Record<string, JsonSchemaType & { anyOf?: any; oneOf?: any }>;
|
||||
} = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
|
|
@ -718,10 +715,7 @@ describe('convertJsonSchemaToZod', () => {
|
|||
name: { type: 'string' },
|
||||
role: { type: 'string' },
|
||||
},
|
||||
anyOf: [
|
||||
{ required: ['name'] },
|
||||
{ required: ['role'] },
|
||||
],
|
||||
anyOf: [{ required: ['name'] }, { required: ['role'] }],
|
||||
},
|
||||
settings: {
|
||||
type: 'object',
|
||||
|
|
@ -742,20 +736,24 @@ describe('convertJsonSchemaToZod', () => {
|
|||
});
|
||||
|
||||
// The schema should still validate normal properties
|
||||
expect(zodSchema?.parse({
|
||||
user: { name: 'John', role: 'admin' },
|
||||
settings: { theme: 'custom' }, // This would fail if oneOf was still present
|
||||
})).toEqual({
|
||||
expect(
|
||||
zodSchema?.parse({
|
||||
user: { name: 'John', role: 'admin' },
|
||||
settings: { theme: 'custom' }, // This would fail if oneOf was still present
|
||||
}),
|
||||
).toEqual({
|
||||
user: { name: 'John', role: 'admin' },
|
||||
settings: { theme: 'custom' },
|
||||
});
|
||||
|
||||
// But the anyOf constraint should be gone from user
|
||||
// (If it was present, this would fail because neither name nor role is required)
|
||||
expect(zodSchema?.parse({
|
||||
user: {},
|
||||
settings: { theme: 'light' },
|
||||
})).toEqual({
|
||||
expect(
|
||||
zodSchema?.parse({
|
||||
user: {},
|
||||
settings: { theme: 'light' },
|
||||
}),
|
||||
).toEqual({
|
||||
user: {},
|
||||
settings: { theme: 'light' },
|
||||
});
|
||||
|
|
@ -803,10 +801,7 @@ describe('convertJsonSchemaToZod', () => {
|
|||
anyOf: [{ minItems: 1 }],
|
||||
},
|
||||
},
|
||||
oneOf: [
|
||||
{ required: ['name', 'permissions'] },
|
||||
{ required: ['name'] },
|
||||
],
|
||||
oneOf: [{ required: ['name', 'permissions'] }, { required: ['name'] }],
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -871,10 +866,7 @@ describe('convertJsonSchemaToZod', () => {
|
|||
const schema = {
|
||||
type: 'object', // Add a type to satisfy JsonSchemaType
|
||||
properties: {}, // Empty properties
|
||||
oneOf: [
|
||||
{ type: 'string' },
|
||||
{ type: 'number' },
|
||||
],
|
||||
oneOf: [{ type: 'string' }, { type: 'number' }],
|
||||
} as JsonSchemaType & { oneOf?: any };
|
||||
|
||||
// Convert with transformOneOfAnyOf option
|
||||
|
|
@ -893,10 +885,7 @@ describe('convertJsonSchemaToZod', () => {
|
|||
const schema = {
|
||||
type: 'object', // Add a type to satisfy JsonSchemaType
|
||||
properties: {}, // Empty properties
|
||||
anyOf: [
|
||||
{ type: 'string' },
|
||||
{ type: 'number' },
|
||||
],
|
||||
anyOf: [{ type: 'string' }, { type: 'number' }],
|
||||
} as JsonSchemaType & { anyOf?: any };
|
||||
|
||||
// Convert with transformOneOfAnyOf option
|
||||
|
|
@ -956,10 +945,7 @@ describe('convertJsonSchemaToZod', () => {
|
|||
properties: {
|
||||
value: { type: 'string' },
|
||||
},
|
||||
oneOf: [
|
||||
{ required: ['value'] },
|
||||
{ properties: { optional: { type: 'boolean' } } },
|
||||
],
|
||||
oneOf: [{ required: ['value'] }, { properties: { optional: { type: 'boolean' } } }],
|
||||
} as JsonSchemaType & { oneOf?: any };
|
||||
|
||||
// Convert with transformOneOfAnyOf option
|
||||
|
|
@ -1013,9 +999,12 @@ describe('convertJsonSchemaToZod', () => {
|
|||
},
|
||||
},
|
||||
} as JsonSchemaType & {
|
||||
properties?: Record<string, JsonSchemaType & {
|
||||
properties?: Record<string, JsonSchemaType & { oneOf?: any }>
|
||||
}>
|
||||
properties?: Record<
|
||||
string,
|
||||
JsonSchemaType & {
|
||||
properties?: Record<string, JsonSchemaType & { oneOf?: any }>;
|
||||
}
|
||||
>;
|
||||
};
|
||||
|
||||
// Convert with transformOneOfAnyOf option
|
||||
|
|
@ -1024,14 +1013,16 @@ describe('convertJsonSchemaToZod', () => {
|
|||
});
|
||||
|
||||
// The schema should validate nested unions
|
||||
expect(zodSchema?.parse({
|
||||
user: {
|
||||
contact: {
|
||||
type: 'email',
|
||||
email: 'test@example.com',
|
||||
expect(
|
||||
zodSchema?.parse({
|
||||
user: {
|
||||
contact: {
|
||||
type: 'email',
|
||||
email: 'test@example.com',
|
||||
},
|
||||
},
|
||||
},
|
||||
})).toEqual({
|
||||
}),
|
||||
).toEqual({
|
||||
user: {
|
||||
contact: {
|
||||
type: 'email',
|
||||
|
|
@ -1040,14 +1031,16 @@ describe('convertJsonSchemaToZod', () => {
|
|||
},
|
||||
});
|
||||
|
||||
expect(zodSchema?.parse({
|
||||
user: {
|
||||
contact: {
|
||||
type: 'phone',
|
||||
phone: '123-456-7890',
|
||||
expect(
|
||||
zodSchema?.parse({
|
||||
user: {
|
||||
contact: {
|
||||
type: 'phone',
|
||||
phone: '123-456-7890',
|
||||
},
|
||||
},
|
||||
},
|
||||
})).toEqual({
|
||||
}),
|
||||
).toEqual({
|
||||
user: {
|
||||
contact: {
|
||||
type: 'phone',
|
||||
|
|
@ -1057,14 +1050,16 @@ describe('convertJsonSchemaToZod', () => {
|
|||
});
|
||||
|
||||
// Should reject invalid contact types
|
||||
expect(() => zodSchema?.parse({
|
||||
user: {
|
||||
contact: {
|
||||
type: 'email',
|
||||
phone: '123-456-7890', // Missing email, has phone instead
|
||||
expect(() =>
|
||||
zodSchema?.parse({
|
||||
user: {
|
||||
contact: {
|
||||
type: 'email',
|
||||
phone: '123-456-7890', // Missing email, has phone instead
|
||||
},
|
||||
},
|
||||
},
|
||||
})).toThrow();
|
||||
}),
|
||||
).toThrow();
|
||||
});
|
||||
|
||||
it('should work with dropFields option', () => {
|
||||
|
|
@ -1072,10 +1067,7 @@ describe('convertJsonSchemaToZod', () => {
|
|||
const schema = {
|
||||
type: 'object', // Add a type to satisfy JsonSchemaType
|
||||
properties: {}, // Empty properties
|
||||
oneOf: [
|
||||
{ type: 'string' },
|
||||
{ type: 'number' },
|
||||
],
|
||||
oneOf: [{ type: 'string' }, { type: 'number' }],
|
||||
deprecated: true, // Field to drop
|
||||
} as JsonSchemaType & { oneOf?: any; deprecated?: boolean };
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue