mirror of https://github.com/kortix-ai/suna.git
Merge pull request #1784 from escapade-mckv/fix-templates-api
fix: remove pagination for kortix templates
This commit is contained in:
commit
809e6ab34b
|
@ -370,6 +370,56 @@ class MarketplaceTemplatesResponse(BaseModel):
|
||||||
templates: List[TemplateResponse]
|
templates: List[TemplateResponse]
|
||||||
pagination: MarketplacePaginationInfo
|
pagination: MarketplacePaginationInfo
|
||||||
|
|
||||||
|
@router.get("/kortix-all", response_model=MarketplaceTemplatesResponse)
|
||||||
|
async def get_all_kortix_templates(
|
||||||
|
request: Request = None
|
||||||
|
):
|
||||||
|
try:
|
||||||
|
from core.templates.services.marketplace_service import MarketplaceService, MarketplaceFilters
|
||||||
|
|
||||||
|
pagination_params = PaginationParams(
|
||||||
|
page=1,
|
||||||
|
page_size=1000
|
||||||
|
)
|
||||||
|
|
||||||
|
filters = MarketplaceFilters(
|
||||||
|
is_kortix_team=True,
|
||||||
|
sort_by="download_count",
|
||||||
|
sort_order="desc"
|
||||||
|
)
|
||||||
|
|
||||||
|
client = await db.client
|
||||||
|
marketplace_service = MarketplaceService(client)
|
||||||
|
paginated_result = await marketplace_service.get_marketplace_templates_paginated(
|
||||||
|
pagination_params=pagination_params,
|
||||||
|
filters=filters
|
||||||
|
)
|
||||||
|
|
||||||
|
template_responses = []
|
||||||
|
for template_data in paginated_result.data:
|
||||||
|
template_response = TemplateResponse(**template_data)
|
||||||
|
template_responses.append(template_response)
|
||||||
|
|
||||||
|
return MarketplaceTemplatesResponse(
|
||||||
|
templates=template_responses,
|
||||||
|
pagination=MarketplacePaginationInfo(
|
||||||
|
current_page=1,
|
||||||
|
page_size=len(template_responses),
|
||||||
|
total_items=len(template_responses),
|
||||||
|
total_pages=1,
|
||||||
|
has_next=False,
|
||||||
|
has_previous=False
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
try:
|
||||||
|
error_str = str(e)
|
||||||
|
except Exception:
|
||||||
|
error_str = f"Error of type {type(e).__name__}"
|
||||||
|
logger.error(f"Error getting all Kortix templates: {error_str}")
|
||||||
|
raise HTTPException(status_code=500, detail="Internal server error")
|
||||||
|
|
||||||
@router.get("/marketplace", response_model=MarketplaceTemplatesResponse)
|
@router.get("/marketplace", response_model=MarketplaceTemplatesResponse)
|
||||||
async def get_marketplace_templates(
|
async def get_marketplace_templates(
|
||||||
page: Optional[int] = Query(1, ge=1, description="Page number (1-based)"),
|
page: Optional[int] = Query(1, ge=1, description="Page number (1-based)"),
|
||||||
|
|
|
@ -485,9 +485,29 @@ export function useDeleteTemplate() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useKortixTeamTemplates() {
|
export function useKortixTeamTemplates() {
|
||||||
return useMarketplaceTemplates({
|
return useQuery({
|
||||||
is_kortix_team: true,
|
queryKey: ['secure-mcp', 'kortix-templates-all'],
|
||||||
limit: 10
|
queryFn: async (): Promise<MarketplaceTemplatesResponse> => {
|
||||||
|
const supabase = createClient();
|
||||||
|
const { data: { session } } = await supabase.auth.getSession();
|
||||||
|
|
||||||
|
if (!session) {
|
||||||
|
throw new Error('You must be logged in to view Kortix templates');
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await fetch(`${API_URL}/templates/kortix-all`, {
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${session.access_token}`,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
const errorData = await response.json().catch(() => ({ message: 'Unknown error' }));
|
||||||
|
throw new Error(errorData.message || `HTTP ${response.status}: ${response.statusText}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response.json();
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -519,7 +539,6 @@ export function useInstallTemplate() {
|
||||||
|
|
||||||
if (isAgentLimitError) {
|
if (isAgentLimitError) {
|
||||||
const { AgentCountLimitError } = await import('@/lib/api');
|
const { AgentCountLimitError } = await import('@/lib/api');
|
||||||
// Use the nested detail if it exists, otherwise use the errorData directly
|
|
||||||
const errorDetail = errorData.detail || errorData;
|
const errorDetail = errorData.detail || errorData;
|
||||||
throw new AgentCountLimitError(response.status, errorDetail);
|
throw new AgentCountLimitError(response.status, errorDetail);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue