mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-21 02:40:14 +01:00
- Add useMarketplaceAgentsInfiniteQuery and useGetAgentCategoriesQuery to client/src/data-provider/Agents/
- Replace manual pagination in AgentGrid with infinite query pattern - Update imports to use local data provider instead of librechat-data-provider - Add proper permission handling with PERMISSION_BITS.VIEW/EDIT constants - Improve agent access control by adding requiredPermission validation in backend - Remove manual cursor/state management in favor of infinite query built-ins - Maintain existing search and category filtering functionality
This commit is contained in:
parent
6ebcfdf3e2
commit
3f6d7ab7c7
9 changed files with 143 additions and 128 deletions
|
|
@ -1,6 +1,11 @@
|
|||
import { QueryKeys, dataService, EModelEndpoint, defaultOrderQuery } from 'librechat-data-provider';
|
||||
import { useQuery, useQueryClient } from '@tanstack/react-query';
|
||||
import type { QueryObserverResult, UseQueryOptions } from '@tanstack/react-query';
|
||||
import { useQuery, useInfiniteQuery, useQueryClient } from '@tanstack/react-query';
|
||||
import type {
|
||||
QueryObserverResult,
|
||||
UseQueryOptions,
|
||||
UseInfiniteQueryOptions,
|
||||
InfiniteData,
|
||||
} from '@tanstack/react-query';
|
||||
import type t from 'librechat-data-provider';
|
||||
|
||||
/**
|
||||
|
|
@ -98,3 +103,60 @@ export const useGetExpandedAgentByIdQuery = (
|
|||
},
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* MARKETPLACE
|
||||
*/
|
||||
/**
|
||||
* Hook for getting agent categories for marketplace tabs
|
||||
*/
|
||||
export const useGetAgentCategoriesQuery = (
|
||||
config?: UseQueryOptions<t.TMarketplaceCategory[]>,
|
||||
): QueryObserverResult<t.TMarketplaceCategory[]> => {
|
||||
return useQuery<t.TMarketplaceCategory[]>(
|
||||
[QueryKeys.agentCategories],
|
||||
() => dataService.getAgentCategories(),
|
||||
{
|
||||
refetchOnWindowFocus: false,
|
||||
refetchOnReconnect: false,
|
||||
refetchOnMount: false,
|
||||
staleTime: 5 * 60 * 1000, // Cache for 5 minutes
|
||||
...config,
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Hook for infinite loading of marketplace agents with cursor-based pagination
|
||||
*/
|
||||
export const useMarketplaceAgentsInfiniteQuery = (
|
||||
params: {
|
||||
requiredPermission: number;
|
||||
category?: string;
|
||||
search?: string;
|
||||
limit?: number;
|
||||
promoted?: 0 | 1;
|
||||
cursor?: string; // For pagination
|
||||
},
|
||||
config?: UseInfiniteQueryOptions<t.AgentListResponse, unknown>,
|
||||
) => {
|
||||
return useInfiniteQuery<t.AgentListResponse>({
|
||||
queryKey: [QueryKeys.marketplaceAgents, params],
|
||||
queryFn: ({ pageParam }) => {
|
||||
const queryParams = { ...params };
|
||||
if (pageParam) {
|
||||
queryParams.cursor = pageParam.toString();
|
||||
}
|
||||
return dataService.getMarketplaceAgents(queryParams);
|
||||
},
|
||||
getNextPageParam: (lastPage) => lastPage?.after ?? undefined,
|
||||
enabled: !!params.requiredPermission,
|
||||
keepPreviousData: true,
|
||||
staleTime: 2 * 60 * 1000, // 2 minutes
|
||||
cacheTime: 10 * 60 * 1000, // 10 minutes
|
||||
refetchOnWindowFocus: false,
|
||||
refetchOnReconnect: false,
|
||||
refetchOnMount: false,
|
||||
...config,
|
||||
});
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue