from contextlib import asynccontextmanager from typing import Annotated from fastapi import FastAPI, Depends from .apirouters import agents, tasks, customize_ship from .apirouters import tasks, customize_ship 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)") cursor.execute( "CREATE TABLE IF NOT EXISTS ships(primary_key INTEGER PRIMARY KEY, symbol TEXT NOT NULL UNIQUE, task TEXT NOT NULL, params TEXT, name TEXT)") conn.commit() agents.load_agents_from_database() yield app = FastAPI(lifespan=lifespan) app.include_router(agents.router) app.include_router(tasks.router) app.include_router(customize_ship.router)