mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-09-21 21:50:49 +02:00
👁️🗨️ refactor: use PermissionBits.VIEW
in useAgentsMap
for requiredPermission
This commit is contained in:
parent
803ade8601
commit
b742c8c7f9
7 changed files with 32 additions and 36 deletions
|
@ -225,6 +225,7 @@ export type AgentPanelContextType = {
|
|||
setActivePanel: React.Dispatch<React.SetStateAction<Panel>>;
|
||||
setCurrentAgentId: React.Dispatch<React.SetStateAction<string | undefined>>;
|
||||
agent_id?: string;
|
||||
agentsConfig?: t.TAgentsEndpoint;
|
||||
};
|
||||
|
||||
export type AgentModelPanelProps = {
|
||||
|
|
|
@ -7,12 +7,8 @@ import type { UseMutationResult, QueryObserverResult } from '@tanstack/react-que
|
|||
import type { Agent, AgentCreateParams } from 'librechat-data-provider';
|
||||
import type { TAgentCapabilities, AgentForm } from '~/common';
|
||||
import { cn, createProviderOption, processAgentOption, getDefaultAgentFormValues } from '~/utils';
|
||||
import {
|
||||
useAgentListingDefaultPermissionLevel,
|
||||
useGetStartupConfig,
|
||||
useListAgentsQuery,
|
||||
} from '~/data-provider';
|
||||
import { useLocalize } from '~/hooks';
|
||||
import { useGetStartupConfig, useListAgentsQuery } from '~/data-provider';
|
||||
import { useLocalize, useAgentDefaultPermissionLevel } from '~/hooks';
|
||||
|
||||
const keys = new Set(Object.keys(defaultAgentFormValues));
|
||||
|
||||
|
@ -32,7 +28,7 @@ export default function AgentSelect({
|
|||
const { control, reset } = useFormContext();
|
||||
|
||||
const { data: startupConfig } = useGetStartupConfig();
|
||||
const permissionLevel = useAgentListingDefaultPermissionLevel();
|
||||
const permissionLevel = useAgentDefaultPermissionLevel();
|
||||
|
||||
const { data: agents = null } = useListAgentsQuery(
|
||||
{ requiredPermission: permissionLevel },
|
||||
|
|
|
@ -1,33 +1,11 @@
|
|||
import {
|
||||
QueryKeys,
|
||||
dataService,
|
||||
Permissions,
|
||||
EModelEndpoint,
|
||||
PermissionBits,
|
||||
PermissionTypes,
|
||||
} from 'librechat-data-provider';
|
||||
import { useQuery, useInfiniteQuery, useQueryClient } from '@tanstack/react-query';
|
||||
import { QueryKeys, dataService, EModelEndpoint, PermissionBits } from 'librechat-data-provider';
|
||||
import type {
|
||||
QueryObserverResult,
|
||||
UseQueryOptions,
|
||||
UseInfiniteQueryOptions,
|
||||
} from '@tanstack/react-query';
|
||||
import type t from 'librechat-data-provider';
|
||||
import { useHasAccess } from '~/hooks';
|
||||
|
||||
/**
|
||||
* Hook to determine the appropriate permission level for agent queries based on marketplace configuration
|
||||
*/
|
||||
export const useAgentListingDefaultPermissionLevel = () => {
|
||||
const hasMarketplaceAccess = useHasAccess({
|
||||
permissionType: PermissionTypes.MARKETPLACE,
|
||||
permission: Permissions.USE,
|
||||
});
|
||||
|
||||
// When marketplace is active: EDIT permissions (builder mode)
|
||||
// When marketplace is not active: VIEW permissions (browse mode)
|
||||
return hasMarketplaceAccess ? PermissionBits.EDIT : PermissionBits.VIEW;
|
||||
};
|
||||
|
||||
/**
|
||||
* AGENTS
|
||||
|
|
|
@ -4,3 +4,4 @@ export { default as useAgentCategories } from './useAgentCategories';
|
|||
export type { ProcessedAgentCategory } from './useAgentCategories';
|
||||
export { default as useAgentCapabilities } from './useAgentCapabilities';
|
||||
export { default as useGetAgentsConfig } from './useGetAgentsConfig';
|
||||
export { default as useAgentDefaultPermissionLevel } from './useAgentDefaultPermissionLevel';
|
||||
|
|
18
client/src/hooks/Agents/useAgentDefaultPermissionLevel.ts
Normal file
18
client/src/hooks/Agents/useAgentDefaultPermissionLevel.ts
Normal file
|
@ -0,0 +1,18 @@
|
|||
import { Permissions, PermissionBits, PermissionTypes } from 'librechat-data-provider';
|
||||
import { useHasAccess } from '~/hooks/Roles';
|
||||
|
||||
/**
|
||||
* Hook to determine the appropriate permission level for agent queries based on marketplace configuration
|
||||
*/
|
||||
const useAgentDefaultPermissionLevel = () => {
|
||||
const hasMarketplaceAccess = useHasAccess({
|
||||
permissionType: PermissionTypes.MARKETPLACE,
|
||||
permission: Permissions.USE,
|
||||
});
|
||||
|
||||
// When marketplace is active: EDIT permissions (builder mode)
|
||||
// When marketplace is not active: VIEW permissions (browse mode)
|
||||
return hasMarketplaceAccess ? PermissionBits.EDIT : PermissionBits.VIEW;
|
||||
};
|
||||
|
||||
export default useAgentDefaultPermissionLevel;
|
|
@ -1,6 +1,7 @@
|
|||
import { TAgentsMap } from 'librechat-data-provider';
|
||||
import { useMemo } from 'react';
|
||||
import { useListAgentsQuery, useAgentListingDefaultPermissionLevel } from '~/data-provider';
|
||||
import { PermissionBits } from 'librechat-data-provider';
|
||||
import type { TAgentsMap } from 'librechat-data-provider';
|
||||
import { useListAgentsQuery } from '~/data-provider';
|
||||
import { mapAgents } from '~/utils';
|
||||
|
||||
export default function useAgentsMap({
|
||||
|
@ -8,10 +9,8 @@ export default function useAgentsMap({
|
|||
}: {
|
||||
isAuthenticated: boolean;
|
||||
}): TAgentsMap | undefined {
|
||||
const permissionLevel = useAgentListingDefaultPermissionLevel();
|
||||
|
||||
const { data: agentsList = null } = useListAgentsQuery(
|
||||
{ requiredPermission: permissionLevel },
|
||||
{ requiredPermission: PermissionBits.VIEW },
|
||||
{
|
||||
select: (res) => mapAgents(res.data),
|
||||
enabled: isAuthenticated,
|
||||
|
|
|
@ -60,6 +60,10 @@ jest.mock('~/hooks/Agents/useAgentsMap', () => ({
|
|||
__esModule: true,
|
||||
default: jest.fn(() => ({})),
|
||||
}));
|
||||
jest.mock('~/hooks/Agents/useAgentDefaultPermissionLevel', () => ({
|
||||
__esModule: true,
|
||||
default: jest.fn(() => ({})),
|
||||
}));
|
||||
|
||||
jest.mock('~/utils', () => ({
|
||||
getConvoSwitchLogic: jest.fn(() => ({
|
||||
|
@ -101,7 +105,6 @@ jest.mock('~/data-provider', () => ({
|
|||
isLoading: false,
|
||||
error: null,
|
||||
})),
|
||||
useAgentListingDefaultPermissionLevel: jest.fn(() => 'view'),
|
||||
useListAgentsQuery: jest.fn(() => ({
|
||||
data: null,
|
||||
isLoading: false,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue