""" FastAPI server for the SQL Debug Environment. Hooks into openenv-core's create_fastapi_app() for the standard /ws endpoint, then slaps on a landing page and health check on top. Nothing fancy. """ from __future__ import annotations import logging from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from fastapi.responses import HTMLResponse from openenv.core.env_server import create_fastapi_app from server.environment import SQLDebugEnvironment from sql_debug_env.models import SQLAction, SQLObservation logger = logging.getLogger("sql-debug-env") logging.basicConfig(level=logging.INFO) # ── Wire up the OpenEnv app ──────────────────────────────────────── app: FastAPI = create_fastapi_app( env=SQLDebugEnvironment, action_cls=SQLAction, observation_cls=SQLObservation, ) app.title = "SQL Debug Environment" app.description = ( "OpenEnv-compatible environment for SQL debugging and optimization. " "Agents fix broken queries through iterative execution feedback." ) app.version = "1.0.0" app.contact = {"name": "SQL Debug Env Team"} app.license_info = {"name": "MIT", "url": "https://opensource.org/licenses/MIT"} # Wide open CORS — this is a dev/hackathon tool, not a bank app.add_middleware( CORSMiddleware, allow_origins=["*"], allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) # ── Landing page ──────────────────────────────────────────────────── # # Just a quick info card so you know it's alive when you hit the root URL. # Nothing too wild — dark theme, lists the tasks, links to the docs. LANDING_HTML = """ SQL Debug Environment

🛠️ SQL Debug Environment

Interactive SQL debugging & optimization — powered by OpenEnv

Easy
Fix SQL Syntax Errors
fix_syntax
Medium
Fix Wrong JOIN Logic
fix_join
Hard
Optimize Correlated Subquery
optimize_query

Endpoints

WS /ws — Main interaction (reset / step / state)
GET /health — Health check

📖 Swagger Docs  |  📋 ReDoc

""" @app.get("/", response_class=HTMLResponse) async def root(): """Serve the landing page.""" return LANDING_HTML @app.get("/health") async def health(): """Quick health check — just confirms the server is up.""" return {"status": "ok", "environment": "sql-debug-env"} # ── Entry point ───────────────────────────────────────────────────── def main(): import uvicorn uvicorn.run(app, host="0.0.0.0", port=7860) if __name__ == "__main__": main()