35 lines
1.1 KiB
Python
35 lines
1.1 KiB
Python
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
from typing import Annotated
|
||
|
|
|
||
|
|
from fastapi import APIRouter, Depends, HTTPException, Query, status
|
||
|
|
from sqlalchemy.orm import Session
|
||
|
|
|
||
|
|
from app.api.deps import get_db
|
||
|
|
from app.schemas.agent_run import AgentRunRead
|
||
|
|
from app.services.agent_runs import AgentRunService
|
||
|
|
|
||
|
|
router = APIRouter(prefix="/agent-runs")
|
||
|
|
DbSession = Annotated[Session, Depends(get_db)]
|
||
|
|
|
||
|
|
|
||
|
|
@router.get("", response_model=list[AgentRunRead])
|
||
|
|
def list_agent_runs(
|
||
|
|
db: DbSession,
|
||
|
|
agent: str | None = Query(default=None),
|
||
|
|
status_value: str | None = Query(default=None, alias="status"),
|
||
|
|
source: str | None = Query(default=None),
|
||
|
|
limit: int = Query(default=20, ge=1, le=100),
|
||
|
|
) -> list[AgentRunRead]:
|
||
|
|
return AgentRunService(db).list_runs(
|
||
|
|
agent=agent, status=status_value, source=source, limit=limit
|
||
|
|
)
|
||
|
|
|
||
|
|
|
||
|
|
@router.get("/{run_id}", response_model=AgentRunRead)
|
||
|
|
def get_agent_run(run_id: str, db: DbSession) -> AgentRunRead:
|
||
|
|
run = AgentRunService(db).get_run(run_id)
|
||
|
|
if run is None:
|
||
|
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Run not found")
|
||
|
|
return run
|