mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-09-22 08:12:00 +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>>;
|
setActivePanel: React.Dispatch<React.SetStateAction<Panel>>;
|
||||||
setCurrentAgentId: React.Dispatch<React.SetStateAction<string | undefined>>;
|
setCurrentAgentId: React.Dispatch<React.SetStateAction<string | undefined>>;
|
||||||
agent_id?: string;
|
agent_id?: string;
|
||||||
|
agentsConfig?: t.TAgentsEndpoint;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type AgentModelPanelProps = {
|
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 { Agent, AgentCreateParams } from 'librechat-data-provider';
|
||||||
import type { TAgentCapabilities, AgentForm } from '~/common';
|
import type { TAgentCapabilities, AgentForm } from '~/common';
|
||||||
import { cn, createProviderOption, processAgentOption, getDefaultAgentFormValues } from '~/utils';
|
import { cn, createProviderOption, processAgentOption, getDefaultAgentFormValues } from '~/utils';
|
||||||
import {
|
import { useGetStartupConfig, useListAgentsQuery } from '~/data-provider';
|
||||||
useAgentListingDefaultPermissionLevel,
|
import { useLocalize, useAgentDefaultPermissionLevel } from '~/hooks';
|
||||||
useGetStartupConfig,
|
|
||||||
useListAgentsQuery,
|
|
||||||
} from '~/data-provider';
|
|
||||||
import { useLocalize } from '~/hooks';
|
|
||||||
|
|
||||||
const keys = new Set(Object.keys(defaultAgentFormValues));
|
const keys = new Set(Object.keys(defaultAgentFormValues));
|
||||||
|
|
||||||
|
@ -32,7 +28,7 @@ export default function AgentSelect({
|
||||||
const { control, reset } = useFormContext();
|
const { control, reset } = useFormContext();
|
||||||
|
|
||||||
const { data: startupConfig } = useGetStartupConfig();
|
const { data: startupConfig } = useGetStartupConfig();
|
||||||
const permissionLevel = useAgentListingDefaultPermissionLevel();
|
const permissionLevel = useAgentDefaultPermissionLevel();
|
||||||
|
|
||||||
const { data: agents = null } = useListAgentsQuery(
|
const { data: agents = null } = useListAgentsQuery(
|
||||||
{ requiredPermission: permissionLevel },
|
{ 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 { useQuery, useInfiniteQuery, useQueryClient } from '@tanstack/react-query';
|
||||||
|
import { QueryKeys, dataService, EModelEndpoint, PermissionBits } from 'librechat-data-provider';
|
||||||
import type {
|
import type {
|
||||||
QueryObserverResult,
|
QueryObserverResult,
|
||||||
UseQueryOptions,
|
UseQueryOptions,
|
||||||
UseInfiniteQueryOptions,
|
UseInfiniteQueryOptions,
|
||||||
} from '@tanstack/react-query';
|
} from '@tanstack/react-query';
|
||||||
import type t from 'librechat-data-provider';
|
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
|
* AGENTS
|
||||||
|
|
|
@ -4,3 +4,4 @@ export { default as useAgentCategories } from './useAgentCategories';
|
||||||
export type { ProcessedAgentCategory } from './useAgentCategories';
|
export type { ProcessedAgentCategory } from './useAgentCategories';
|
||||||
export { default as useAgentCapabilities } from './useAgentCapabilities';
|
export { default as useAgentCapabilities } from './useAgentCapabilities';
|
||||||
export { default as useGetAgentsConfig } from './useGetAgentsConfig';
|
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 { 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';
|
import { mapAgents } from '~/utils';
|
||||||
|
|
||||||
export default function useAgentsMap({
|
export default function useAgentsMap({
|
||||||
|
@ -8,10 +9,8 @@ export default function useAgentsMap({
|
||||||
}: {
|
}: {
|
||||||
isAuthenticated: boolean;
|
isAuthenticated: boolean;
|
||||||
}): TAgentsMap | undefined {
|
}): TAgentsMap | undefined {
|
||||||
const permissionLevel = useAgentListingDefaultPermissionLevel();
|
|
||||||
|
|
||||||
const { data: agentsList = null } = useListAgentsQuery(
|
const { data: agentsList = null } = useListAgentsQuery(
|
||||||
{ requiredPermission: permissionLevel },
|
{ requiredPermission: PermissionBits.VIEW },
|
||||||
{
|
{
|
||||||
select: (res) => mapAgents(res.data),
|
select: (res) => mapAgents(res.data),
|
||||||
enabled: isAuthenticated,
|
enabled: isAuthenticated,
|
||||||
|
|
|
@ -60,6 +60,10 @@ jest.mock('~/hooks/Agents/useAgentsMap', () => ({
|
||||||
__esModule: true,
|
__esModule: true,
|
||||||
default: jest.fn(() => ({})),
|
default: jest.fn(() => ({})),
|
||||||
}));
|
}));
|
||||||
|
jest.mock('~/hooks/Agents/useAgentDefaultPermissionLevel', () => ({
|
||||||
|
__esModule: true,
|
||||||
|
default: jest.fn(() => ({})),
|
||||||
|
}));
|
||||||
|
|
||||||
jest.mock('~/utils', () => ({
|
jest.mock('~/utils', () => ({
|
||||||
getConvoSwitchLogic: jest.fn(() => ({
|
getConvoSwitchLogic: jest.fn(() => ({
|
||||||
|
@ -101,7 +105,6 @@ jest.mock('~/data-provider', () => ({
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
error: null,
|
error: null,
|
||||||
})),
|
})),
|
||||||
useAgentListingDefaultPermissionLevel: jest.fn(() => 'view'),
|
|
||||||
useListAgentsQuery: jest.fn(() => ({
|
useListAgentsQuery: jest.fn(() => ({
|
||||||
data: null,
|
data: null,
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue