File size: 1,822 Bytes
12832d8
b10856a
 
12832d8
b10856a
 
e627b57
6fdf170
 
b10856a
12832d8
6fdf170
 
 
 
 
29f5dfb
fb62834
 
 
6fdf170
12832d8
 
 
 
6fdf170
 
12832d8
b10856a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12832d8
6fdf170
b10856a
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
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from fastapi.responses import FileResponse
import uvicorn
import os
from pathlib import Path

from utils import log
from chat_handler import router as chat_router  # ← start_session & chat
from admin_routes import router as admin_router  # ← Admin API endpoints

app = FastAPI(
    title="Flare Orchestration Service",
    version="0.1.0",
    description="LLM-driven intent & API flow engine (bootstrap)",
)

from spark_startup import run_in_thread
run_in_thread()

# ---------------- Health probe (HF Spaces watchdog) -----------------
@app.get("/")
def health_check():
    return {"status": "ok"}

# ---------------- Core chat/session routes --------------------------
app.include_router(chat_router)

# ---------------- Admin API routes ----------------------------------
app.include_router(admin_router)

# ---------------- Serve Angular UI if exists ------------------------
static_path = Path("static")
if static_path.exists() and static_path.is_dir():
    # Serve static files (Angular assets)
    app.mount("/assets", StaticFiles(directory="static/assets"), name="assets")
    
    # Catch-all route for Angular routing (must be last!)
    @app.get("/{full_path:path}")
    async def serve_angular(full_path: str):
        # Don't catch API routes
        if full_path.startswith("api/") or full_path in ["start_session", "chat"]:
            return {"error": "Not found"}, 404
        
        # Return Angular index.html for all other routes
        index_path = static_path / "index.html"
        if index_path.exists():
            return FileResponse(str(index_path))
        return {"error": "UI not found"}, 404

if __name__ == "__main__":
    log("🌐 Starting Flare backend …")
    uvicorn.run(app, host="0.0.0.0", port=7860)