mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-09-21 21:50:49 +02:00
🦾 refactor: filter Model Specs based on user access to Agents (#9433)
This commit is contained in:
parent
122ff416ac
commit
45da421e7d
2 changed files with 41 additions and 4 deletions
|
@ -1,6 +1,6 @@
|
|||
import debounce from 'lodash/debounce';
|
||||
import React, { createContext, useContext, useState, useMemo } from 'react';
|
||||
import { isAgentsEndpoint, isAssistantsEndpoint } from 'librechat-data-provider';
|
||||
import { EModelEndpoint, isAgentsEndpoint, isAssistantsEndpoint } from 'librechat-data-provider';
|
||||
import type * as t from 'librechat-data-provider';
|
||||
import type { Endpoint, SelectedValues } from '~/common';
|
||||
import {
|
||||
|
@ -59,7 +59,25 @@ export function ModelSelectorProvider({ children, startupConfig }: ModelSelector
|
|||
const { data: endpointsConfig } = useGetEndpointsQuery();
|
||||
const { endpoint, model, spec, agent_id, assistant_id, newConversation } =
|
||||
useModelSelectorChatContext();
|
||||
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 permissionLevel = useAgentDefaultPermissionLevel();
|
||||
const { data: agents = null } = useListAgentsQuery(
|
||||
{ requiredPermission: permissionLevel },
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue