fix(automation): reorder routes — static paths before dynamic {id} to prevent 400 errors

This commit is contained in:
Agent Zero
2026-07-24 10:42:08 +02:00
parent 7dd4865638
commit 992d4b79d4
2 changed files with 186 additions and 186 deletions
+58 -58
View File
@@ -139,6 +139,64 @@ async def create_agent(
return _agent_to_response(agent)
@router.get(
"/tools",
dependencies=[Depends(require_permission("agents:read"))],
)
async def list_tools(
current_user: dict[str, Any] = Depends(get_current_user),
):
"""List available tools from the tool registry."""
try:
from app.plugins.builtins.ai_assistant.tool_registry import (
get_tool_registry,
)
registry = get_tool_registry()
tools = registry.list_tools()
return {
"items": [
{
"id": t.get("id", t.get("name", "")),
"name": t.get("name", ""),
"description": t.get("description", ""),
"plugin": t.get("plugin", ""),
}
for t in tools
],
"total": len(tools),
}
except ImportError:
return {"items": [], "total": 0, "note": "Tool registry not available"}
except Exception as e:
logger.exception("Failed to list tools")
return {"items": [], "total": 0, "error": str(e)}
# ─── Recent Runs ───
@router.get(
"/runs/recent",
dependencies=[Depends(require_permission("agents:read"))],
response_model=AgentRunListResponse,
)
async def list_recent_agent_runs(
limit: int = Query(20, ge=1, le=100),
status: str | None = Query(None),
current_user: dict[str, Any] = Depends(get_current_user),
db: AsyncSession = Depends(get_db),
):
"""List recent agent runs across all agents (for dashboard)."""
tenant_id = uuid.UUID(current_user["tenant_id"])
items, total = await RunLogService.list_agent_runs(
db, tenant_id, agent_id=None, status=status, limit=limit, offset=0
)
return AgentRunListResponse(
items=[_agent_run_to_response(r) for r in items],
total=total,
)
@router.get(
"/{agent_id}",
dependencies=[Depends(require_permission("agents:read"))],
@@ -419,61 +477,3 @@ async def send_agent_message_endpoint(
)
return result
@router.get(
"/tools",
dependencies=[Depends(require_permission("agents:read"))],
)
async def list_tools(
current_user: dict[str, Any] = Depends(get_current_user),
):
"""List available tools from the tool registry."""
try:
from app.plugins.builtins.ai_assistant.tool_registry import (
get_tool_registry,
)
registry = get_tool_registry()
tools = registry.list_tools()
return {
"items": [
{
"id": t.get("id", t.get("name", "")),
"name": t.get("name", ""),
"description": t.get("description", ""),
"plugin": t.get("plugin", ""),
}
for t in tools
],
"total": len(tools),
}
except ImportError:
return {"items": [], "total": 0, "note": "Tool registry not available"}
except Exception as e:
logger.exception("Failed to list tools")
return {"items": [], "total": 0, "error": str(e)}
# ─── Recent Runs ───
@router.get(
"/runs/recent",
dependencies=[Depends(require_permission("agents:read"))],
response_model=AgentRunListResponse,
)
async def list_recent_agent_runs(
limit: int = Query(20, ge=1, le=100),
status: str | None = Query(None),
current_user: dict[str, Any] = Depends(get_current_user),
db: AsyncSession = Depends(get_db),
):
"""List recent agent runs across all agents (for dashboard)."""
tenant_id = uuid.UUID(current_user["tenant_id"])
items, total = await RunLogService.list_agent_runs(
db, tenant_id, agent_id=None, status=status, limit=limit, offset=0
)
return AgentRunListResponse(
items=[_agent_run_to_response(r) for r in items],
total=total,
)