54 lines
1.3 KiB
Python
54 lines
1.3 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
main.py — Cloud Run entrypoint for OSVauco OPAX agent.
|
|
Exposes a FastAPI HTTP API that wraps agent.run().
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
|
|
# Ensure agents/core-logic is on the path
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "agents", "core-logic"))
|
|
|
|
from fastapi import FastAPI, HTTPException
|
|
from pydantic import BaseModel
|
|
from agent import run # agents/core-logic/agent.py
|
|
|
|
app = FastAPI(title="OSVauco OPAX Agent")
|
|
|
|
|
|
class RunRequest(BaseModel):
|
|
message: str
|
|
user_id: str = "opax"
|
|
session_id: str = "default"
|
|
mode: str = "A"
|
|
|
|
|
|
@app.get("/health")
|
|
def health():
|
|
return {"status": "ok"}
|
|
|
|
|
|
@app.post("/run")
|
|
def run_agent(req: RunRequest):
|
|
try:
|
|
response = run(
|
|
message=req.message,
|
|
user_id=req.user_id,
|
|
session_id=req.session_id,
|
|
mode=req.mode,
|
|
)
|
|
return {"response": response}
|
|
except PermissionError as e:
|
|
raise HTTPException(status_code=403, detail=str(e))
|
|
except ValueError as e:
|
|
raise HTTPException(status_code=400, detail=str(e))
|
|
except Exception as e:
|
|
raise HTTPException(status_code=500, detail=str(e))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
import uvicorn
|
|
port = int(os.environ.get("PORT", 8080))
|
|
uvicorn.run(app, host="0.0.0.0", port=port)
|