fix: add GET / route serving opax.html from static/
This commit is contained in:
parent
40788c35d4
commit
950220166f
|
|
@ -5,9 +5,10 @@ import os
|
||||||
import sys
|
import sys
|
||||||
import logging
|
import logging
|
||||||
from contextlib import asynccontextmanager
|
from contextlib import asynccontextmanager
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
from fastapi import FastAPI, HTTPException, Request
|
from fastapi import FastAPI, HTTPException, Request
|
||||||
from fastapi.responses import JSONResponse
|
from fastapi.responses import JSONResponse, FileResponse
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
logging.basicConfig(level=logging.INFO)
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
|
@ -31,12 +32,16 @@ PROJECT_ID = os.environ.get("GOOGLE_CLOUD_PROJECT", "propane-will-491900
|
||||||
BQ_BILLING_DATASET = os.environ.get("BQ_BILLING_DATASET", "billing_data")
|
BQ_BILLING_DATASET = os.environ.get("BQ_BILLING_DATASET", "billing_data")
|
||||||
CLOUD_BUILD_TRIGGER_ID = os.environ.get("CLOUD_BUILD_TRIGGER_ID", "")
|
CLOUD_BUILD_TRIGGER_ID = os.environ.get("CLOUD_BUILD_TRIGGER_ID", "")
|
||||||
|
|
||||||
|
# Static folder: /app/static/ (two levels up from agents/core-logic)
|
||||||
|
STATIC_DIR = Path(__file__).parent.parent.parent / "static"
|
||||||
|
|
||||||
_budget_store: dict = {}
|
_budget_store: dict = {}
|
||||||
|
|
||||||
|
|
||||||
@asynccontextmanager
|
@asynccontextmanager
|
||||||
async def lifespan(app: FastAPI):
|
async def lifespan(app: FastAPI):
|
||||||
logger.info(f"OSVauco agent '{APP_NAME}' starting up")
|
logger.info(f"OSVauco agent '{APP_NAME}' starting up")
|
||||||
|
logger.info(f"Static dir: {STATIC_DIR} (exists={STATIC_DIR.exists()})")
|
||||||
yield
|
yield
|
||||||
logger.info(f"OSVauco agent '{APP_NAME}' shutting down")
|
logger.info(f"OSVauco agent '{APP_NAME}' shutting down")
|
||||||
|
|
||||||
|
|
@ -80,6 +85,25 @@ async def _ensure_session(user_id: str, session_id: str):
|
||||||
return session
|
return session
|
||||||
|
|
||||||
|
|
||||||
|
# ── root — serve opax.html ────────────────────────────────────────────────────
|
||||||
|
@app.get("/")
|
||||||
|
async def root():
|
||||||
|
index = STATIC_DIR / "opax.html"
|
||||||
|
if not index.exists():
|
||||||
|
logger.error(f"opax.html not found at {index}")
|
||||||
|
raise HTTPException(status_code=404, detail=f"opax.html not found at {index}")
|
||||||
|
return FileResponse(str(index), media_type="text/html")
|
||||||
|
|
||||||
|
|
||||||
|
# ── static files ──────────────────────────────────────────────────────────────
|
||||||
|
@app.get("/static/{filename}")
|
||||||
|
async def static_file(filename: str):
|
||||||
|
filepath = STATIC_DIR / filename
|
||||||
|
if not filepath.exists():
|
||||||
|
raise HTTPException(status_code=404, detail=f"{filename} not found")
|
||||||
|
return FileResponse(str(filepath))
|
||||||
|
|
||||||
|
|
||||||
# ── helse ────────────────────────────────────────────────────────────────────
|
# ── helse ────────────────────────────────────────────────────────────────────
|
||||||
@app.get("/health")
|
@app.get("/health")
|
||||||
async def health():
|
async def health():
|
||||||
|
|
@ -225,7 +249,6 @@ async def tokens_estimate(complexity: str = "medium"):
|
||||||
return JSONResponse({"complexity": complexity, "factor": factor, "estimated_usd": None, "warning": "Ingen data ennå (OQ-15)"})
|
return JSONResponse({"complexity": complexity, "factor": factor, "estimated_usd": None, "warning": "Ingen data ennå (OQ-15)"})
|
||||||
row = result[0]
|
row = result[0]
|
||||||
avg_cost = float(row.avg_cost_per_call or 0)
|
avg_cost = float(row.avg_cost_per_call or 0)
|
||||||
# Estimat: 1 oppdrag = 20 kall snitt × faktor
|
|
||||||
CALLS_PER_TASK = 20
|
CALLS_PER_TASK = 20
|
||||||
estimated = round(avg_cost * CALLS_PER_TASK * factor, 4)
|
estimated = round(avg_cost * CALLS_PER_TASK * factor, 4)
|
||||||
return JSONResponse({
|
return JSONResponse({
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user