Spaces:
Sleeping
Sleeping
Ajjack4 commited on
Commit ·
98f33e3
1
Parent(s): 572967a
fix openenv runtime spec: /health=healthy, add /metadata /schema /mcp endpoints
Browse files
api.py
CHANGED
|
@@ -2,9 +2,8 @@
|
|
| 2 |
FastAPI server — exposes OpenEnv standard endpoints + required hackathon endpoints.
|
| 3 |
"""
|
| 4 |
|
| 5 |
-
from fastapi import FastAPI, HTTPException
|
| 6 |
from fastapi.middleware.cors import CORSMiddleware
|
| 7 |
-
from fastapi.responses import HTMLResponse
|
| 8 |
import uvicorn
|
| 9 |
|
| 10 |
from models import Action, Observation
|
|
@@ -136,24 +135,101 @@ def baseline() -> dict:
|
|
| 136 |
|
| 137 |
|
| 138 |
# ---------------------------------------------------------------------------
|
| 139 |
-
#
|
| 140 |
# ---------------------------------------------------------------------------
|
| 141 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
@app.get("/")
|
| 143 |
def root():
|
| 144 |
return {
|
| 145 |
"name": "Dev Environment Debugger",
|
| 146 |
"version": "1.0.0",
|
| 147 |
"description": "OpenEnv environment for AI-powered dev environment debugging.",
|
| 148 |
-
"endpoints": ["/reset", "/step", "/state", "/tasks", "/grader",
|
|
|
|
| 149 |
"openenv": True,
|
| 150 |
}
|
| 151 |
|
| 152 |
|
| 153 |
-
@app.get("/health")
|
| 154 |
-
def health():
|
| 155 |
-
return {"status": "ok"}
|
| 156 |
-
|
| 157 |
-
|
| 158 |
if __name__ == "__main__":
|
| 159 |
uvicorn.run("api:app", host="0.0.0.0", port=7860, reload=False)
|
|
|
|
| 2 |
FastAPI server — exposes OpenEnv standard endpoints + required hackathon endpoints.
|
| 3 |
"""
|
| 4 |
|
| 5 |
+
from fastapi import FastAPI, HTTPException, Request
|
| 6 |
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
| 7 |
import uvicorn
|
| 8 |
|
| 9 |
from models import Action, Observation
|
|
|
|
| 135 |
|
| 136 |
|
| 137 |
# ---------------------------------------------------------------------------
|
| 138 |
+
# OpenEnv runtime spec endpoints
|
| 139 |
# ---------------------------------------------------------------------------
|
| 140 |
|
| 141 |
+
@app.get("/health")
|
| 142 |
+
def health():
|
| 143 |
+
"""OpenEnv spec: must return status=healthy."""
|
| 144 |
+
return {"status": "healthy"}
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
@app.get("/metadata")
|
| 148 |
+
def metadata():
|
| 149 |
+
"""OpenEnv spec: environment name and description."""
|
| 150 |
+
return {
|
| 151 |
+
"name": "Dev Environment Debugger",
|
| 152 |
+
"description": (
|
| 153 |
+
"OpenEnv environment where an AI agent debugs a broken multi-service "
|
| 154 |
+
"dev stack by reading logs, inspecting configs, and fixing env vars."
|
| 155 |
+
),
|
| 156 |
+
"version": "1.0.0",
|
| 157 |
+
"author": "Ajjack4",
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
|
| 161 |
+
@app.get("/schema")
|
| 162 |
+
def schema():
|
| 163 |
+
"""OpenEnv spec: action, observation, and state schemas."""
|
| 164 |
+
return {
|
| 165 |
+
"action": {
|
| 166 |
+
"type": "object",
|
| 167 |
+
"properties": {
|
| 168 |
+
"type": {
|
| 169 |
+
"type": "string",
|
| 170 |
+
"enum": ["read_logs", "inspect_env", "edit_env",
|
| 171 |
+
"restart_service", "run_healthcheck", "submit"],
|
| 172 |
+
},
|
| 173 |
+
"service": {"type": "string", "enum": ["api", "worker", "database", "proxy"]},
|
| 174 |
+
"key": {"type": "string"},
|
| 175 |
+
"value": {"type": "string"},
|
| 176 |
+
},
|
| 177 |
+
"required": ["type"],
|
| 178 |
+
},
|
| 179 |
+
"observation": {
|
| 180 |
+
"type": "object",
|
| 181 |
+
"properties": {
|
| 182 |
+
"step": {"type": "integer"},
|
| 183 |
+
"services": {"type": "object"},
|
| 184 |
+
"last_action_result": {"type": "object"},
|
| 185 |
+
"available_actions": {"type": "array", "items": {"type": "string"}},
|
| 186 |
+
"done": {"type": "boolean"},
|
| 187 |
+
},
|
| 188 |
+
},
|
| 189 |
+
"state": {
|
| 190 |
+
"type": "object",
|
| 191 |
+
"properties": {
|
| 192 |
+
"task_id": {"type": "string"},
|
| 193 |
+
"step": {"type": "integer"},
|
| 194 |
+
"done": {"type": "boolean"},
|
| 195 |
+
"fixed_faults": {"type": "array"},
|
| 196 |
+
"remaining_faults": {"type": "array"},
|
| 197 |
+
"services": {"type": "object"},
|
| 198 |
+
},
|
| 199 |
+
},
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
|
| 203 |
+
@app.post("/mcp")
|
| 204 |
+
async def mcp(request: Request):
|
| 205 |
+
"""OpenEnv spec: minimal MCP / JSON-RPC 2.0 endpoint."""
|
| 206 |
+
try:
|
| 207 |
+
body = await request.json()
|
| 208 |
+
req_id = body.get("id", 1)
|
| 209 |
+
except Exception:
|
| 210 |
+
req_id = 1
|
| 211 |
+
return {
|
| 212 |
+
"jsonrpc": "2.0",
|
| 213 |
+
"id": req_id,
|
| 214 |
+
"result": {
|
| 215 |
+
"name": "Dev Environment Debugger",
|
| 216 |
+
"version": "1.0.0",
|
| 217 |
+
"capabilities": {},
|
| 218 |
+
},
|
| 219 |
+
}
|
| 220 |
+
|
| 221 |
+
|
| 222 |
@app.get("/")
|
| 223 |
def root():
|
| 224 |
return {
|
| 225 |
"name": "Dev Environment Debugger",
|
| 226 |
"version": "1.0.0",
|
| 227 |
"description": "OpenEnv environment for AI-powered dev environment debugging.",
|
| 228 |
+
"endpoints": ["/reset", "/step", "/state", "/tasks", "/grader",
|
| 229 |
+
"/baseline", "/health", "/metadata", "/schema", "/mcp"],
|
| 230 |
"openenv": True,
|
| 231 |
}
|
| 232 |
|
| 233 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 234 |
if __name__ == "__main__":
|
| 235 |
uvicorn.run("api:app", host="0.0.0.0", port=7860, reload=False)
|