admin / Apex
publicBid Management and Orchestration Tool with AI Capability
Apex / Synapse-Apexv2 / backend / app / main.py
2291 B · main
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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | import logging from fastapi import Depends, FastAPI from fastapi.middleware.cors import CORSMiddleware from app.core.config import settings from app.core.database import Base, SessionLocal, engine, get_db from app.core.deps import get_current_user from app.core.seed import run_seed from app.routers import ( admin, assistant, auth, bids, capabilities, commercial, exports, library, resources, ) logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(name)s %(message)s") log = logging.getLogger("apex") app = FastAPI(title="Synapse-Apex API", version="2.0.0") app.add_middleware( CORSMiddleware, allow_origins=settings.cors_list, allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) @app.on_event("startup") def on_startup() -> None: # v1: create tables on boot + seed. (Alembic migrations are the documented # follow-up — see DECISIONS.md.) Base.metadata.create_all(bind=engine) db = SessionLocal() try: run_seed(db) log.info("Seed complete. AI enabled=%s model=%s", settings.ai_enabled, settings.anthropic_model) finally: db.close() @app.get("/api/health") def health() -> dict: return {"status": "ok", "ai_enabled": settings.ai_enabled} @app.get("/api/config") def client_config(user=Depends(get_current_user), db=Depends(get_db)) -> dict: from app.models import SystemSetting row = db.get(SystemSetting, "ai_assistant") assistant_admin_on = bool(row and row.value.get("enabled")) return { "ai_enabled": settings.ai_enabled, "assistant_admin_enabled": assistant_admin_on, "currency": settings.default_currency, } @app.get("/api/ai/status") def ai_status(force: bool = False, user=Depends(get_current_user)) -> dict: """Live check that the AI is connected and working (cached ~60s).""" from app.services import ai return ai.check_status(force=force) app.include_router(auth.router) app.include_router(admin.router) app.include_router(resources.router) app.include_router(capabilities.router) app.include_router(bids.router) app.include_router(commercial.router) app.include_router(exports.router) app.include_router(assistant.router) app.include_router(library.router) |