refactor: unify agent marketplace to single endpoint with cursor pagination

- Replace multiple marketplace routes with unified /marketplace endpoint
  - Add query string controls: category, search, limit, cursor, promoted, requiredPermission
  - Implement cursor-based pagination replacing page-based system
  - Integrate ACL permissions for proper access control
  - Fix ObjectId constructor error in Agent model
  - Update React components to use unified useGetMarketplaceAgentsQuery hook
  - Enhance type safety and remove deprecated useDynamicAgentQuery
  - Update tests for new marketplace architecture
  -Known issues:
  see more button after category switching + Unit tests
This commit is contained in:
Danny Avila 2025-06-23 11:42:24 -04:00
parent be7476d530
commit 2eef94d58d
No known key found for this signature in database
GPG key ID: BF31EEB2C5CA0956
22 changed files with 458 additions and 1128 deletions

View file

@ -12,6 +12,7 @@ import * as q from '../types/queries';
import { QueryKeys } from '../keys';
import * as s from '../schemas';
import * as t from '../types';
import * as a from '../types/assistants';
import * as permissions from '../accessPermissions';
export { hasPermissions } from '../accessPermissions';
@ -450,3 +451,52 @@ export const useGetEffectivePermissionsQuery = (
...config,
});
};
/* Marketplace */
/**
* Get agent categories with counts 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,
},
);
};
/**
* Unified marketplace agents query with query string controls
*/
export const useGetMarketplaceAgentsQuery = (
params: {
requiredPermission: number;
category?: string;
search?: string;
limit?: number;
cursor?: string;
promoted?: 0 | 1;
},
config?: UseQueryOptions<a.AgentListResponse>,
): QueryObserverResult<a.AgentListResponse> => {
return useQuery<a.AgentListResponse>(
[QueryKeys.marketplaceAgents, params],
() => dataService.getMarketplaceAgents(params),
{
enabled: !!params.requiredPermission,
refetchOnWindowFocus: false,
refetchOnReconnect: false,
refetchOnMount: false,
staleTime: 2 * 60 * 1000, // Cache for 2 minutes
...config,
},
);
};