Skip to content

Commit

Permalink
chore(agents-api): removed upperbound limit for list queries and adde…
Browse files Browse the repository at this point in the history
…d params checks
  • Loading branch information
Vedantsahai18 committed Mar 5, 2025
1 parent ed036c2 commit 478213a
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 17 deletions.
12 changes: 10 additions & 2 deletions agents-api/agents_api/queries/agents/list_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,20 @@ async def list_agents(
Returns:
Tuple of (query, params)
"""
# Validate sort direction
# Validate parameters
if direction.lower() not in ["asc", "desc"]:
raise HTTPException(status_code=400, detail="Invalid sort direction")

# Build metadata filter clause if needed
if sort_by not in ["created_at", "updated_at"]:
raise HTTPException(status_code=400, detail="Invalid sort field")

if limit < 1:
raise HTTPException(status_code=400, detail="Limit must be greater than 0")

if offset < 0:
raise HTTPException(status_code=400, detail="Offset must be non-negative")

# Build metadata filter clause if needed
agent_query = raw_query.format(
metadata_filter_query="AND metadata @> $6::jsonb" if metadata_filter else "",
)
Expand Down
9 changes: 5 additions & 4 deletions agents-api/agents_api/queries/docs/list_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,18 @@ async def list_docs(
Raises:
HTTPException: If invalid parameters are provided.
"""
# Validate parameters
if direction.lower() not in ["asc", "desc"]:
raise HTTPException(status_code=400, detail="Invalid sort direction")

if sort_by not in ["created_at", "updated_at"]:
if sort_by not in ["created_at", "timestamp"]:
raise HTTPException(status_code=400, detail="Invalid sort field")

if limit > 100 or limit < 1:
raise HTTPException(status_code=400, detail="Limit must be between 1 and 100")
if limit < 1:
raise HTTPException(status_code=400, detail="Limit must be greater than 0")

if offset < 0:
raise HTTPException(status_code=400, detail="Offset must be >= 0")
raise HTTPException(status_code=400, detail="Offset must be non-negative")

# Start with the base query
query = base_docs_query
Expand Down
12 changes: 10 additions & 2 deletions agents-api/agents_api/queries/entries/list_entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,16 @@ async def list_entries(
Returns:
tuple[str, list] | tuple[str, list, str]: SQL query and parameters for listing the entries.
"""
if limit < 1 or limit > 1000:
raise HTTPException(status_code=400, detail="Limit must be between 1 and 1000")
# Validate parameters
if direction.lower() not in ["asc", "desc"]:
raise HTTPException(status_code=400, detail="Invalid sort direction")

if sort_by not in ["created_at", "timestamp"]:
raise HTTPException(status_code=400, detail="Invalid sort field")

if limit < 1:
raise HTTPException(status_code=400, detail="Limit must be greater than 0")

if offset < 0:
raise HTTPException(status_code=400, detail="Offset must be non-negative")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,19 @@ async def list_execution_transitions(
Returns:
tuple[str, list]: SQL query and parameters for listing execution transitions.
"""
# Validate parameters
if direction.lower() not in ["asc", "desc"]:
raise HTTPException(status_code=400, detail="Invalid sort direction")

if sort_by not in ["created_at"]:
raise HTTPException(status_code=400, detail="Invalid sort field")

if limit < 1:
raise HTTPException(status_code=400, detail="Limit must be greater than 0")

if offset < 0:
raise HTTPException(status_code=400, detail="Offset must be non-negative")

if transition_id is not None:
return (
get_execution_transition_query,
Expand Down
10 changes: 7 additions & 3 deletions agents-api/agents_api/queries/executions/list_executions.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,18 @@ async def list_executions(
tuple[str, list]: SQL query and parameters for listing executions.
"""

# Validate parameters
if direction.lower() not in ["asc", "desc"]:
raise HTTPException(status_code=400, detail="Invalid sort direction")

if sort_by not in ["created_at", "updated_at"]:
raise HTTPException(status_code=400, detail="Invalid sort field")

if limit > 100 or limit < 1:
raise HTTPException(status_code=400, detail="Limit must be between 1 and 100")
if limit < 1:
raise HTTPException(status_code=400, detail="Limit must be greater than 0")

if offset < 0:
raise HTTPException(status_code=400, detail="Offset must be >= 0")
raise HTTPException(status_code=400, detail="Offset must be non-negative")

return (
list_executions_query,
Expand Down
4 changes: 2 additions & 2 deletions agents-api/agents_api/queries/files/list_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ async def list_files(
if sort_by not in ["created_at", "updated_at"]:
raise HTTPException(status_code=400, detail="Invalid sort field")

if limit > 100 or limit < 1:
raise HTTPException(status_code=400, detail="Limit must be between 1 and 100")
if limit < 1:
raise HTTPException(status_code=400, detail="Limit must be greater than 0")

if offset < 0:
raise HTTPException(status_code=400, detail="Offset must be non-negative")
Expand Down
14 changes: 14 additions & 0 deletions agents-api/agents_api/queries/sessions/list_sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from uuid import UUID

from beartype import beartype
from fastapi import HTTPException

from ...autogen.openapi_model import Session
from ...common.utils.db_exceptions import common_db_exceptions
Expand Down Expand Up @@ -82,6 +83,19 @@ async def list_sessions(
Returns:
tuple[str, list]: SQL query and parameters
"""
# Validate parameters
if direction.lower() not in ["asc", "desc"]:
raise HTTPException(status_code=400, detail="Invalid sort direction")

if sort_by not in ["created_at", "updated_at"]:
raise HTTPException(status_code=400, detail="Invalid sort field")

if limit < 1:
raise HTTPException(status_code=400, detail="Limit must be greater than 0")

if offset < 0:
raise HTTPException(status_code=400, detail="Offset must be non-negative")

return (
session_query,
[
Expand Down
8 changes: 6 additions & 2 deletions agents-api/agents_api/queries/tasks/list_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,19 @@ async def list_tasks(
Raises:
HTTPException: If parameters are invalid or developer/agent doesn't exist
"""
# Validate parameters
if direction.lower() not in ["asc", "desc"]:
raise HTTPException(status_code=400, detail="Invalid sort direction")

if limit > 100 or limit < 1:
raise HTTPException(status_code=400, detail="Limit must be between 1 and 100")
if limit < 1:
raise HTTPException(status_code=400, detail="Limit must be greater than 0")

if offset < 0:
raise HTTPException(status_code=400, detail="Offset must be non-negative")

if sort_by not in ["created_at", "updated_at"]:
raise HTTPException(status_code=400, detail="Invalid sort field")

# Format query with metadata filter if needed
query = list_tasks_query.format(
metadata_filter_query="AND metadata @> $7::jsonb" if metadata_filter else "",
Expand Down
14 changes: 14 additions & 0 deletions agents-api/agents_api/queries/tools/list_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from uuid import UUID

from beartype import beartype
from fastapi import HTTPException

from ...autogen.openapi_model import Tool
from ...common.utils.db_exceptions import common_db_exceptions
Expand Down Expand Up @@ -49,6 +50,19 @@ async def list_tools(
developer_id = str(developer_id)
agent_id = str(agent_id)

# Validate parameters
if direction.lower() not in ["asc", "desc"]:
raise HTTPException(status_code=400, detail="Invalid sort direction")

if sort_by not in ["created_at", "updated_at"]:
raise HTTPException(status_code=400, detail="Invalid sort field")

if limit < 1:
raise HTTPException(status_code=400, detail="Limit must be greater than 0")

if offset < 0:
raise HTTPException(status_code=400, detail="Offset must be non-negative")

return (
tools_query,
[
Expand Down
4 changes: 2 additions & 2 deletions agents-api/agents_api/queries/users/list_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ async def list_users(
Returns:
tuple[str, list]: SQL query and parameters
"""
if limit < 1 or limit > 1000:
raise HTTPException(status_code=400, detail="Limit must be between 1 and 1000")
if limit < 1:
raise HTTPException(status_code=400, detail="Limit must be greater than 0")
if offset < 0:
raise HTTPException(status_code=400, detail="Offset must be non-negative")

Expand Down

0 comments on commit 478213a

Please sign in to comment.