diff --git a/agents-api/agents_api/dependencies/query_filter.py b/agents-api/agents_api/dependencies/query_filter.py index 766a5b7c3..da9a76528 100644 --- a/agents-api/agents_api/dependencies/query_filter.py +++ b/agents-api/agents_api/dependencies/query_filter.py @@ -32,6 +32,9 @@ def create_filter_extractor(prefix: str = "filter") -> Callable[[Request], Filte Callable[[Request], FilterModel]: The dependency function. """ + # Add a dot to the prefix to allow for nested filters + prefix += "." + def extract_filters(request: Request) -> FilterModel: """ Extracts query parameters that start with the specified prefix and returns them as a dictionary. @@ -42,10 +45,9 @@ def extract_filters(request: Request) -> FilterModel: Returns: FilterModel: A FilterModel instance containing the filter parameters. """ - nonlocal prefix - prefix += "." filters: dict[str, Any] = {} + for key, value in request.query_params.items(): if key.startswith(prefix): filter_key = key[len(prefix) :] diff --git a/agents-api/agents_api/models/docs/list_docs.py b/agents-api/agents_api/models/docs/list_docs.py index 3c095c2db..4dad7ec06 100644 --- a/agents-api/agents_api/models/docs/list_docs.py +++ b/agents-api/agents_api/models/docs/list_docs.py @@ -90,7 +90,8 @@ def list_docs( created_at, metadata, }}, - snippets[id, snippet_data] + snippets[id, snippet_data], + {metadata_filter_str} :limit $limit :offset $offset @@ -112,6 +113,5 @@ def list_docs( "owner_type": owner_type, "limit": limit, "offset": offset, - "metadata_filter": metadata_filter_str, }, ) diff --git a/agents-api/agents_api/routers/agents/list_agents.py b/agents-api/agents_api/routers/agents/list_agents.py index a24f0667c..0e14be261 100644 --- a/agents-api/agents_api/routers/agents/list_agents.py +++ b/agents-api/agents_api/routers/agents/list_agents.py @@ -17,7 +17,7 @@ async def list_agents( # Example: # > ?metadata_filter.name=John&metadata_filter.age=30 metadata_filter: Annotated[ - FilterModel | None, Depends(create_filter_extractor("metadata_filter")) + FilterModel, Depends(create_filter_extractor("metadata_filter")) ], limit: int = 100, offset: int = 0, diff --git a/agents-api/agents_api/routers/docs/list_docs.py b/agents-api/agents_api/routers/docs/list_docs.py index f342f4b4b..f56de7c84 100644 --- a/agents-api/agents_api/routers/docs/list_docs.py +++ b/agents-api/agents_api/routers/docs/list_docs.py @@ -1,9 +1,7 @@ -import json -from json import JSONDecodeError from typing import Annotated, Literal from uuid import UUID -from fastapi import Depends, HTTPException, status +from fastapi import Depends from ...autogen.openapi_model import Doc, ListResponse from ...dependencies.developer_id import get_developer_id @@ -15,10 +13,10 @@ @router.get("/users/{user_id}/docs", tags=["docs"]) async def list_user_docs( x_developer_id: Annotated[UUID, Depends(get_developer_id)], - user_id: UUID, metadata_filter: Annotated[ - FilterModel | None, Depends(create_filter_extractor("metadata_filter")) + FilterModel, Depends(create_filter_extractor("metadata_filter")) ], + user_id: UUID, limit: int = 100, offset: int = 0, sort_by: Literal["created_at", "updated_at"] = "created_at", @@ -43,10 +41,10 @@ async def list_user_docs( @router.get("/agents/{agent_id}/docs", tags=["docs"]) async def list_agent_docs( x_developer_id: Annotated[UUID, Depends(get_developer_id)], - agent_id: UUID, metadata_filter: Annotated[ - FilterModel | None, Depends(create_filter_extractor("metadata_filter")) + FilterModel, Depends(create_filter_extractor("metadata_filter")) ], + agent_id: UUID, limit: int = 100, offset: int = 0, sort_by: Literal["created_at", "updated_at"] = "created_at",