mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-23 20:00:15 +01:00
style: minor styling cleanup
This commit is contained in:
parent
d37db43e29
commit
f4833b6b25
5 changed files with 18 additions and 14 deletions
|
|
@ -652,10 +652,12 @@ class OpenAIClient extends BaseClient {
|
||||||
const { headers } = this.options;
|
const { headers } = this.options;
|
||||||
if (headers && typeof headers === 'object' && !Array.isArray(headers)) {
|
if (headers && typeof headers === 'object' && !Array.isArray(headers)) {
|
||||||
configOptions.baseOptions = {
|
configOptions.baseOptions = {
|
||||||
headers: resolveHeaders({ headers: {
|
headers: resolveHeaders({
|
||||||
...headers,
|
headers: {
|
||||||
...configOptions?.baseOptions?.headers,
|
...headers,
|
||||||
} }),
|
...configOptions?.baseOptions?.headers,
|
||||||
|
},
|
||||||
|
}),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,11 @@ const initializeClient = async ({ req, res, endpointOption, optionsOnly, overrid
|
||||||
const CUSTOM_API_KEY = extractEnvVariable(endpointConfig.apiKey);
|
const CUSTOM_API_KEY = extractEnvVariable(endpointConfig.apiKey);
|
||||||
const CUSTOM_BASE_URL = extractEnvVariable(endpointConfig.baseURL);
|
const CUSTOM_BASE_URL = extractEnvVariable(endpointConfig.baseURL);
|
||||||
|
|
||||||
let resolvedHeaders = resolveHeaders({ headers: endpointConfig.headers, user: req.user, body: req.body });
|
let resolvedHeaders = resolveHeaders({
|
||||||
|
headers: endpointConfig.headers,
|
||||||
|
user: req.user,
|
||||||
|
body: req.body,
|
||||||
|
});
|
||||||
|
|
||||||
if (CUSTOM_API_KEY.match(envVarRegex)) {
|
if (CUSTOM_API_KEY.match(envVarRegex)) {
|
||||||
throw new Error(`Missing API Key for ${endpoint}.`);
|
throw new Error(`Missing API Key for ${endpoint}.`);
|
||||||
|
|
|
||||||
|
|
@ -428,7 +428,11 @@ describe('resolveHeaders', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should process LIBRECHAT_BODY placeholders', () => {
|
it('should process LIBRECHAT_BODY placeholders', () => {
|
||||||
const body = { conversationId: 'conv-123', parentMessageId: 'parent-456', messageId: 'msg-789' };
|
const body = {
|
||||||
|
conversationId: 'conv-123',
|
||||||
|
parentMessageId: 'parent-456',
|
||||||
|
messageId: 'msg-789',
|
||||||
|
};
|
||||||
const headers = { 'X-Conversation': '{{LIBRECHAT_BODY_CONVERSATIONID}}' };
|
const headers = { 'X-Conversation': '{{LIBRECHAT_BODY_CONVERSATIONID}}' };
|
||||||
const result = resolveHeaders({ headers, body });
|
const result = resolveHeaders({ headers, body });
|
||||||
expect(result['X-Conversation']).toBe('conv-123');
|
expect(result['X-Conversation']).toBe('conv-123');
|
||||||
|
|
|
||||||
|
|
@ -29,11 +29,7 @@ const ALLOWED_USER_FIELDS = [
|
||||||
* List of allowed request body fields that can be used in header placeholders.
|
* List of allowed request body fields that can be used in header placeholders.
|
||||||
* These are common fields from the request body that are safe to expose in headers.
|
* These are common fields from the request body that are safe to expose in headers.
|
||||||
*/
|
*/
|
||||||
const ALLOWED_BODY_FIELDS = [
|
const ALLOWED_BODY_FIELDS = ['conversationId', 'parentMessageId', 'messageId'] as const;
|
||||||
'conversationId',
|
|
||||||
'parentMessageId',
|
|
||||||
'messageId'
|
|
||||||
] as const;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes a string value to replace user field placeholders
|
* Processes a string value to replace user field placeholders
|
||||||
|
|
@ -81,7 +77,6 @@ function processUserPlaceholders(value: string, user?: TUser): string {
|
||||||
* @returns The processed string with placeholders replaced
|
* @returns The processed string with placeholders replaced
|
||||||
*/
|
*/
|
||||||
function processBodyPlaceholders(value: string, body: RequestBody): string {
|
function processBodyPlaceholders(value: string, body: RequestBody): string {
|
||||||
|
|
||||||
for (const field of ALLOWED_BODY_FIELDS) {
|
for (const field of ALLOWED_BODY_FIELDS) {
|
||||||
const placeholder = `{{LIBRECHAT_BODY_${field.toUpperCase()}}}`;
|
const placeholder = `{{LIBRECHAT_BODY_${field.toUpperCase()}}}`;
|
||||||
if (!value.includes(placeholder)) {
|
if (!value.includes(placeholder)) {
|
||||||
|
|
@ -195,7 +190,7 @@ export function processMCPEnv(
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolves header values by replacing user placeholders, body variables, custom variables, and environment variables.
|
* Resolves header values by replacing user placeholders, body variables, custom variables, and environment variables.
|
||||||
*
|
*
|
||||||
* @param options - Optional configuration object.
|
* @param options - Optional configuration object.
|
||||||
* @param options.headers - The headers object to process.
|
* @param options.headers - The headers object to process.
|
||||||
* @param options.user - Optional user object for replacing user field placeholders (can be partial with just id).
|
* @param options.user - Optional user object for replacing user field placeholders (can be partial with just id).
|
||||||
|
|
|
||||||
|
|
@ -4,4 +4,3 @@ export interface RequestBody {
|
||||||
conversationId?: string;
|
conversationId?: string;
|
||||||
[key: string]: unknown;
|
[key: string]: unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue