Spaces:
Paused
Paused
Add proxy server
Browse files
server.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Simple proxy server to OpenHands Cloud API"""
|
| 2 |
+
import os
|
| 3 |
+
from fastapi import FastAPI, HTTPException
|
| 4 |
+
from fastapi.middleware.cors import CORSMiddleware
|
| 5 |
+
import httpx
|
| 6 |
+
|
| 7 |
+
app = FastAPI(title="OpenHands Backend Proxy", version="1.0.0")
|
| 8 |
+
|
| 9 |
+
app.add_middleware(
|
| 10 |
+
CORSMiddleware,
|
| 11 |
+
allow_origins=["*"],
|
| 12 |
+
allow_credentials=True,
|
| 13 |
+
allow_methods=["*"],
|
| 14 |
+
allow_headers=["*"],
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
OPENHANDS_API_KEY = os.getenv("OPENHANDS_API_KEY", "")
|
| 18 |
+
OPENHANDS_BASE_URL = os.getenv("OPENHANDS_BASE_URL", "https://app.all-hands.dev")
|
| 19 |
+
|
| 20 |
+
@app.get("/health")
|
| 21 |
+
async def health():
|
| 22 |
+
return {"status": "ok", "backend": "proxy", "version": "1.0.0"}
|
| 23 |
+
|
| 24 |
+
@app.get("/ready")
|
| 25 |
+
async def ready():
|
| 26 |
+
return {"status": "ready", "service": "openhands-proxy"}
|
| 27 |
+
|
| 28 |
+
@app.get("/api/conversations")
|
| 29 |
+
async def list_conversations():
|
| 30 |
+
if not OPENHANDS_API_KEY:
|
| 31 |
+
raise HTTPException(status_code=503, detail="OPENHANDS_API_KEY not configured")
|
| 32 |
+
async with httpx.AsyncClient() as client:
|
| 33 |
+
resp = await client.get(
|
| 34 |
+
f"{OPENHANDS_BASE_URL}/api/conversations",
|
| 35 |
+
headers={"Authorization": f"Bearer {OPENHANDS_API_KEY}"}
|
| 36 |
+
)
|
| 37 |
+
resp.raise_for_status()
|
| 38 |
+
return resp.json()
|
| 39 |
+
|
| 40 |
+
@app.post("/api/conversations")
|
| 41 |
+
async def create_conversation(data: dict):
|
| 42 |
+
if not OPENHANDS_API_KEY:
|
| 43 |
+
raise HTTPException(status_code=503, detail="OPENHANDS_API_KEY not configured")
|
| 44 |
+
async with httpx.AsyncClient() as client:
|
| 45 |
+
resp = await client.post(
|
| 46 |
+
f"{OPENHANDS_BASE_URL}/api/conversations",
|
| 47 |
+
headers={"Authorization": f"Bearer {OPENHANDS_API_KEY}"},
|
| 48 |
+
json=data
|
| 49 |
+
)
|
| 50 |
+
resp.raise_for_status()
|
| 51 |
+
return resp.json()
|