from contextlib import asynccontextmanager from typing import Annotated from fastapi import FastAPI, Depends from .apirouters import agents from .modules.database import cursor, conn @asynccontextmanager async def lifespan(app: FastAPI): cursor.execute( "CREATE TABLE IF NOT EXISTS agents(primary_key INTEGER PRIMARY KEY, callsign TEXT NOT NULL UNIQUE, token TEXT NOT NULL)") conn.commit() agents.load_agents_from_database() yield app = FastAPI(lifespan=lifespan) app.include_router(agents.router) @app.get("/{callsign}/tasks") async def get_tasks(callsign: str, token: Annotated[str, Depends(agents.oauth2_scheme)]): return f'{{"callsign": "{callsign}", "token": "{token}"}}'