from typing import Annotated from fastapi import APIRouter, Depends from ..modules import task_type from .agents import auth_agent, Agent router = APIRouter() @router.get("/tasks") async def get_tasks(agent: Annotated[Agent, Depends(auth_agent)]): ships = [] for current_ship in agent.ships.values(): current_ship.load_task() ships.append(current_ship.get_data()) return {"ships": ships} @router.get("/task/{ship_symbol}") async def get_tasks(ship_symbol: str, agent: Annotated[Agent, Depends(auth_agent)]): for current_ship in agent.ships.values(): if current_ship.symbol == ship_symbol: current_ship.load_task() return current_ship.get_data() return {"error": "Unknown ship symbol."} @router.post("/task/{ship_symbol}/set/{task_type}") async def get_tasks(ship_symbol: str, task: str, agent: Annotated[Agent, Depends(auth_agent)]): if task not in task_type.task_types: return {"error": "Invalid task."} for current_ship in agent.ships.values(): if current_ship.symbol == ship_symbol: current_ship.set_task(task) return current_ship.get_data() return {"error": "Unknown ship symbol."}