blob: 243442247e6b32c74d744d0820bf7f2ce451df14 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
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)")
cursor.execute(
"CREATE TABLE IF NOT EXISTS ships(primary_key INTEGER PRIMARY KEY, symbol TEXT NOT NULL UNIQUE, task TEXT NOT NULL, params TEXT)")
conn.commit()
agents.load_agents_from_database()
yield
app = FastAPI(lifespan=lifespan)
app.include_router(agents.router)
@app.get("/tasks")
async def get_tasks(agent: Annotated[agents.Agent, Depends(agents.auth_agent)]):
return {"callsign": agent.agent_symbol}
|