"""Modal deployment for Interviewer. Build frontend first: bun run build Serve locally on Modal: modal serve modal_app.py Deploy: modal deploy modal_app.py """ from pathlib import Path import modal APP_NAME = "sensemaker-interviewer" ROOT = Path(__file__).parent DIST = ROOT / "dist" app = modal.App(APP_NAME) image = ( modal.Image.debian_slim(python_version="3.12") .uv_pip_install("fastapi[standard]==0.115.4") .add_local_dir(DIST, remote_path="/assets") ) @app.function(image=image) @modal.concurrent(max_inputs=100) @modal.asgi_app() def web(): from fastapi import FastAPI, Request, Response from fastapi.responses import JSONResponse from fastapi.staticfiles import StaticFiles web_app = FastAPI(title="Interviewer") def origin_from_request(request: Request) -> str: forwarded_proto = request.headers.get("x-forwarded-proto") forwarded_host = request.headers.get("x-forwarded-host") if forwarded_proto and forwarded_host: return f"{forwarded_proto}://{forwarded_host}" return str(request.base_url).rstrip("/") @web_app.get("/health") async def health(): return {"ok": True, "app": APP_NAME} @web_app.get("/api/config") async def config(request: Request): origin = origin_from_request(request) return { "app": APP_NAME, "oauth": { "enabled": False, "clientMetadataUrl": f"{origin}/oauth/client-metadata.json", "callbackUrl": f"{origin}/oauth/callback", "reason": "OAuth metadata is published; PKCE/DPoP callback/session exchange is not implemented yet.", }, } @web_app.get("/oauth/client-metadata.json") async def oauth_client_metadata(request: Request): origin = origin_from_request(request) metadata_url = f"{origin}/oauth/client-metadata.json" return JSONResponse( { "client_id": metadata_url, "client_name": "Interviewer", "client_uri": origin, "logo_uri": f"{origin}/logo.svg", "redirect_uris": [f"{origin}/oauth/callback"], "application_type": "web", "grant_types": ["authorization_code", "refresh_token"], "response_types": ["code"], "scope": "atproto", "dpop_bound_access_tokens": True, "token_endpoint_auth_method": "none", } ) @web_app.get("/oauth/callback") async def oauth_callback(): return Response( "OAuth callback placeholder. Implement PKCE/DPoP token exchange before enabling sign-in.", media_type="text/plain", ) web_app.mount("/", StaticFiles(directory="/assets", html=True), name="static") return web_app