mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 17:00:15 +01:00
👤 fix: Missing User Placeholder Fields for MCP Services (#9824)
This commit is contained in:
parent
57f8b333bc
commit
4f3683fd9a
6 changed files with 388 additions and 38 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import { extractEnvVariable } from 'librechat-data-provider';
|
||||
import type { TUser, MCPOptions } from 'librechat-data-provider';
|
||||
import type { IUser } from '@librechat/data-schemas';
|
||||
import type { RequestBody } from '~/types';
|
||||
|
||||
/**
|
||||
|
|
@ -26,6 +27,31 @@ const ALLOWED_USER_FIELDS = [
|
|||
'termsAccepted',
|
||||
] as const;
|
||||
|
||||
type AllowedUserField = (typeof ALLOWED_USER_FIELDS)[number];
|
||||
type SafeUser = Pick<IUser, AllowedUserField>;
|
||||
|
||||
/**
|
||||
* Creates a safe user object containing only allowed fields.
|
||||
* Optimized for performance while maintaining type safety.
|
||||
*
|
||||
* @param user - The user object to extract safe fields from
|
||||
* @returns A new object containing only allowed fields
|
||||
*/
|
||||
export function createSafeUser(user: IUser | null | undefined): Partial<SafeUser> {
|
||||
if (!user) {
|
||||
return {};
|
||||
}
|
||||
|
||||
const safeUser: Partial<SafeUser> = {};
|
||||
for (const field of ALLOWED_USER_FIELDS) {
|
||||
if (field in user) {
|
||||
safeUser[field] = user[field];
|
||||
}
|
||||
}
|
||||
|
||||
return safeUser;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue