🦾 refactor: filter Model Specs based on user access to Agents (#9433)

This commit is contained in:
Danny Avila 2025-09-03 02:59:57 -04:00 committed by GitHub
parent 122ff416ac
commit 45da421e7d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 41 additions and 4 deletions

View file

@ -3,12 +3,12 @@ import { useGetModelsQuery } from 'librechat-data-provider/react-query';
import {
Permissions,
alternateName,
PermissionBits,
EModelEndpoint,
PermissionTypes,
isAgentsEndpoint,
getConfigDefaults,
isAssistantsEndpoint,
PermissionBits,
} from 'librechat-data-provider';
import type { TAssistantsMap, TEndpointsConfig } from 'librechat-data-provider';
import type { MentionOption } from '~/common';
@ -19,6 +19,7 @@ import {
useGetStartupConfig,
} from '~/data-provider';
import useAssistantListMap from '~/hooks/Assistants/useAssistantListMap';
import { useAgentsMapContext } from '~/Providers/AgentsMapContext';
import { mapEndpoints, getPresetTitle } from '~/utils';
import { EndpointIcon } from '~/components/Endpoints';
import useHasAccess from '~/hooks/Roles/useHasAccess';
@ -62,6 +63,7 @@ export default function useMentions({
permission: Permissions.USE,
});
const agentsMap = useAgentsMapContext();
const { data: presets } = useGetPresetsQuery();
const { data: modelsConfig } = useGetModelsQuery();
const { data: startupConfig } = useGetStartupConfig();
@ -129,7 +131,24 @@ export default function useMentions({
[listMap, assistantMap, endpointsConfig],
);
const modelSpecs = useMemo(() => startupConfig?.modelSpecs?.list ?? [], [startupConfig]);
const modelSpecs = useMemo(() => {
const specs = startupConfig?.modelSpecs?.list ?? [];
if (!agentsMap) {
return specs;
}
/**
* Filter modelSpecs to only include agents the user has access to.
* Use agentsMap which already contains permission-filtered agents (consistent with other components).
*/
return specs.filter((spec) => {
if (spec.preset?.endpoint === EModelEndpoint.agents && spec.preset?.agent_id) {
return spec.preset.agent_id in agentsMap;
}
/** Keep non-agent modelSpecs */
return true;
});
}, [startupConfig, agentsMap]);
const options: MentionOption[] = useMemo(() => {
let validEndpoints = endpoints;