FlagshipAi / Suite /app /main.py
Ali2206's picture
Deploy Flagship AI Space (Docker, clean)
07afba2
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import FileResponse, JSONResponse
import os
import sys
from fastapi.staticfiles import StaticFiles
# Ensure workspace root is on sys.path for sibling packages (AiDesign, AISolutions, AIReadiness, AIArchitecture)
ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
if ROOT_DIR not in sys.path:
sys.path.append(ROOT_DIR)
# Unified FastAPI app that exposes all agents under one server
app = FastAPI(title="Flagship AI Suite", version="0.1.0")
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Serve shared static assets (header partial + js)
static_dir = os.path.join(os.path.dirname(__file__), "static")
app.mount("/static", StaticFiles(directory=static_dir), name="static")
# 1) Include AiDesign's API endpoints (they are already prefixed with /ux)
UX_LOADED = False
try:
from AIDesign.app.main import router as ux_router # type: ignore
app.include_router(ux_router)
UX_LOADED = True
except Exception as e_primary: # pragma: no cover - best effort import
try:
from AiDesign.app.main import router as ux_router # type: ignore
app.include_router(ux_router)
UX_LOADED = True
except Exception as e_alt:
print(f"[Suite] Failed to load AIDesign router: {e_primary}")
print(f"[Suite] Failed to load AiDesign router (alt): {e_alt}")
# 2) Mount AISolutions under /solutions and include AIReadiness routes under /audit
try:
from AISolutions.app.main import app as solutions_app # type: ignore
app.mount("/solutions", solutions_app)
except Exception:
pass
try:
from AIReadiness.app.main import router as audit_router # type: ignore
app.include_router(audit_router)
except Exception:
pass
try:
from AIArchitecture.app.main import router as arch_router # type: ignore
app.include_router(arch_router, prefix="/arch")
except Exception:
pass
try:
from AIHealthcare.app.main import router as triage_router # type: ignore
app.include_router(triage_router, prefix="/triage")
except Exception:
pass
try:
from AICommerce.app.main import router as shop_router # type: ignore
app.include_router(shop_router, prefix="/shop")
except Exception:
pass
try:
from AIAutomation.app.main import router as invoice_router # type: ignore
app.include_router(invoice_router, prefix="/invoice")
except Exception:
pass
try:
from AIIntegration.app.main import router as slack_router # type: ignore
app.include_router(slack_router, prefix="")
except Exception:
pass
try:
from AISaas.app.main import router as saas_router # type: ignore
app.include_router(saas_router)
except Exception:
pass
try:
from AIRoute.app.main import router as route_router # type: ignore
app.include_router(route_router)
except Exception:
pass
try:
from AIQuiz.app.main import router as quiz_router # type: ignore
app.include_router(quiz_router)
except Exception:
pass
try:
from AIDual.app.main import router as dual_router # type: ignore
app.include_router(dual_router)
except Exception:
pass
try:
from AIFit.app.main import router as fit_router # type: ignore
app.include_router(fit_router)
except Exception:
pass
try:
from AIStrategy.app.main import router as strategy_router # type: ignore
app.include_router(strategy_router)
except Exception:
pass
try:
from AIAccessibility.app.main import router as access_router # type: ignore
app.include_router(access_router)
except Exception:
pass
# 3) Convenience landing and static routes
@app.get("/")
def root() -> FileResponse:
base = os.path.join(os.path.dirname(__file__), "static")
return FileResponse(os.path.abspath(os.path.join(base, "index.html")))
@app.get("/ux", response_class=FileResponse)
def ux_index() -> FileResponse:
base = os.path.join(os.path.dirname(__file__), "..", "..", "AIDesign", "app", "static")
return FileResponse(os.path.abspath(os.path.join(base, "index.html")))
@app.get("/audit", response_class=FileResponse)
def audit_index() -> FileResponse:
base = os.path.join(os.path.dirname(__file__), "..", "..", "AIReadiness", "app", "static")
return FileResponse(os.path.abspath(os.path.join(base, "index.html")))
@app.get("/solutions", response_class=FileResponse)
def solutions_index() -> FileResponse:
base = os.path.join(os.path.dirname(__file__), "..", "..", "AISolutions", "app", "static")
return FileResponse(os.path.abspath(os.path.join(base, "index.html")))
@app.get("/arch", response_class=FileResponse)
def arch_index() -> FileResponse:
base = os.path.join(os.path.dirname(__file__), "..", "..", "AIArchitecture", "app", "static")
return FileResponse(os.path.abspath(os.path.join(base, "index.html")))
@app.get("/triage", response_class=FileResponse)
def triage_index() -> FileResponse:
base = os.path.join(os.path.dirname(__file__), "..", "..", "AIHealthcare", "app", "static")
return FileResponse(os.path.abspath(os.path.join(base, "index.html")))
@app.get("/shop", response_class=FileResponse)
def shop_index() -> FileResponse:
base = os.path.join(os.path.dirname(__file__), "..", "..", "AICommerce", "app", "static")
return FileResponse(os.path.abspath(os.path.join(base, "index.html")))
@app.get("/invoice", response_class=FileResponse)
def invoice_index() -> FileResponse:
base = os.path.join(os.path.dirname(__file__), "..", "..", "AIAutomation", "app", "static")
return FileResponse(os.path.abspath(os.path.join(base, "index.html")))
@app.get("/slack", response_class=FileResponse)
def slack_index() -> FileResponse:
base = os.path.join(os.path.dirname(__file__), "..", "..", "AIIntegration", "app", "static")
return FileResponse(os.path.abspath(os.path.join(base, "index.html")))
@app.get("/saas", response_class=FileResponse)
def saas_index() -> FileResponse:
base = os.path.join(os.path.dirname(__file__), "..", "..", "AISaas", "app", "static")
return FileResponse(os.path.abspath(os.path.join(base, "index.html")))
@app.get("/route", response_class=FileResponse)
def route_index() -> FileResponse:
base = os.path.join(os.path.dirname(__file__), "..", "..", "AIRoute", "app", "static")
return FileResponse(os.path.abspath(os.path.join(base, "index.html")))
@app.get("/quiz", response_class=FileResponse)
def quiz_index() -> FileResponse:
base = os.path.join(os.path.dirname(__file__), "..", "..", "AIQuiz", "app", "static")
return FileResponse(os.path.abspath(os.path.join(base, "index.html")))
@app.get("/dual", response_class=FileResponse)
def dual_index() -> FileResponse:
base = os.path.join(os.path.dirname(__file__), "..", "..", "AIDual", "app", "static")
return FileResponse(os.path.abspath(os.path.join(base, "index.html")))
@app.get("/fit", response_class=FileResponse)
def fit_index() -> FileResponse:
base = os.path.join(os.path.dirname(__file__), "..", "..", "AIFit", "app", "static")
return FileResponse(os.path.abspath(os.path.join(base, "index.html")))
@app.get("/strategy", response_class=FileResponse)
def strategy_index() -> FileResponse:
base = os.path.join(os.path.dirname(__file__), "..", "..", "AIStrategy", "app", "static")
return FileResponse(os.path.abspath(os.path.join(base, "index.html")))
@app.get("/access", response_class=FileResponse)
def access_index() -> FileResponse:
base = os.path.join(os.path.dirname(__file__), "..", "..", "AIAccessibility", "app", "static")
return FileResponse(os.path.abspath(os.path.join(base, "index.html")))
@app.get("/status")
def status() -> JSONResponse:
return JSONResponse({
"name": "Flagship AI Suite",
"apps": {
"ux": {"base": "/ux", "loaded": UX_LOADED},
"solutions": {"base": "/solutions"},
"audit": {"base": "/audit"},
"arch": {"base": "/arch"},
"triage": {"base": "/triage"},
"shop": {"base": "/shop"},
"invoice": {"base": "/invoice"},
"slack": {"base": "/slack"},
"saas": {"base": "/saas"},
"route": {"base": "/route"}
,"quiz": {"base": "/quiz"}
,"dual": {"base": "/dual"}
,"fit": {"base": "/fit"}
,"strategy": {"base": "/strategy"}
,"access": {"base": "/access"}
}
})
@app.get("/debug/routes")
def debug_routes() -> JSONResponse:
# Return a compact list of registered routes to diagnose 404 issues
routes = []
for r in app.router.routes:
try:
routes.append({"path": r.path, "methods": sorted(list(getattr(r, "methods", [])))})
except Exception:
pass
return JSONResponse(routes)