|
| 1 | +from fastapi.responses import HTMLResponse, FileResponse |
| 2 | +from fastapi.templating import Jinja2Templates |
| 3 | +from fastapi.staticfiles import StaticFiles |
| 4 | +from fastapi import FastAPI, Request |
| 5 | +from chainlit.utils import mount_chainlit |
| 6 | +from pathlib import Path |
| 7 | +import os |
| 8 | + |
| 9 | +ROOT_PATH = os.getenv("API_ROOT_PATH", "./") |
| 10 | +app = FastAPI(title="AgentTide", description="Precision-Driven Software Engineering Agent") |
| 11 | + |
| 12 | +# Mount static files directory for assets (logo, CSS, JS, etc.) |
| 13 | +app.mount("/static", StaticFiles(directory=F"{ROOT_PATH}/public"), name="static") |
| 14 | + |
| 15 | +templates = Jinja2Templates(directory=F"{ROOT_PATH}/static") |
| 16 | + |
| 17 | +@app.get("/", response_class=HTMLResponse) |
| 18 | +async def landing_page(request: Request): |
| 19 | + """Serve the AgentTide landing page""" |
| 20 | + return templates.TemplateResponse("landing_page.html", {"request": request}) |
| 21 | + |
| 22 | +@app.get("/health") |
| 23 | +async def health_check(): |
| 24 | + """Health check endpoint""" |
| 25 | + return {"status": "healthy", "service": "AgentTide"} |
| 26 | + |
| 27 | +@app.get("/favicon.ico", include_in_schema=False) |
| 28 | +async def favicon(): |
| 29 | + """Serve favicon""" |
| 30 | + favicon_path = Path(F"{ROOT_PATH}/public/favicon.ico") |
| 31 | + if favicon_path.exists(): |
| 32 | + return FileResponse(favicon_path) |
| 33 | + else: |
| 34 | + # Return 204 No Content if favicon doesn't exist |
| 35 | + return HTMLResponse(status_code=204) |
| 36 | + |
| 37 | +@app.get("/logo_dark.png", include_in_schema=False) |
| 38 | +async def logo_dark(): |
| 39 | + """Serve favicon""" |
| 40 | + favicon_path = Path(F"{ROOT_PATH}/public/logo_dark.png") |
| 41 | + if favicon_path.exists(): |
| 42 | + return FileResponse(favicon_path) |
| 43 | + else: |
| 44 | + # Return 204 No Content if favicon doesn't exist |
| 45 | + return HTMLResponse(status_code=204) |
| 46 | + |
| 47 | +mount_chainlit(app=app, target=F"{ROOT_PATH}/app.py", path="/tide") |
| 48 | + |
| 49 | +if __name__ == "__main__": |
| 50 | + from dotenv import load_dotenv |
| 51 | + import uvicorn |
| 52 | + |
| 53 | + load_dotenv() |
| 54 | + uvicorn.run(app, host="0.0.0.0", port=7860) |
0 commit comments