File size: 2,441 Bytes
a753e74
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
84
85
86
"""FastAPI application for ResearchLink AI."""

from __future__ import annotations

from pathlib import Path

from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import HTMLResponse
from fastapi.staticfiles import StaticFiles

from researchlink import __product__, __version__
from researchlink.api.routes.ingest import router as ingest_router
from researchlink.api.routes.providers import router as providers_router
from researchlink.api.routes.review import router as review_router
from researchlink.api.routes.settings import router as settings_router
from researchlink.api.routes.system import router as system_router

app = FastAPI(
    title=__product__,
    version=__version__,
    description="Multi-agent research digest platform API",
)

app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_methods=["*"],
    allow_headers=["*"],
)

app.include_router(system_router)
app.include_router(providers_router)
app.include_router(ingest_router)
app.include_router(settings_router)
app.include_router(review_router)

# Serve static files
_static_dir = Path(__file__).parent.parent / "web" / "static"
if _static_dir.exists():
    app.mount("/static", StaticFiles(directory=str(_static_dir)), name="static")

_templates_dir = Path(__file__).parent.parent / "web" / "templates"


def _read_template(name: str) -> str:
    p = _templates_dir / name
    return p.read_text(encoding="utf-8") if p.exists() else f"<h1>{name} not found</h1>"


@app.get("/", response_class=HTMLResponse)
async def index():
    # The new dashboard is the default entry point.
    return _read_template("dashboard.html")


@app.get("/dashboard", response_class=HTMLResponse)
async def dashboard_page():
    return _read_template("dashboard.html")


@app.get("/legacy", response_class=HTMLResponse)
async def legacy_index():
    # The previous single-page app, preserved.
    return _read_template("index.html")


@app.get("/settings", response_class=HTMLResponse)
async def settings_page():
    return _read_template("settings.html")


@app.get("/results", response_class=HTMLResponse)
async def results_page():
    return _read_template("results.html")


@app.get("/history", response_class=HTMLResponse)
async def history_page():
    return _read_template("history.html")


@app.get("/health")
async def health():
    return {"status": "ok", "product": __product__, "version": __version__}