54 lines
1.4 KiB
Python
54 lines
1.4 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
main.py — Cloud Run entrypoint for OSVauco OPAX agent.
|
|
Exposes a minimal Flask 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 flask import Flask, request, jsonify
|
|
from agent import run # agents/core-logic/agent.py
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
|
@app.route("/health", methods=["GET"])
|
|
def health():
|
|
return jsonify({"status": "ok"})
|
|
|
|
|
|
@app.route("/run", methods=["POST"])
|
|
def run_agent():
|
|
body = request.get_json(force=True, silent=True) or {}
|
|
message = body.get("message", "")
|
|
user_id = body.get("user_id", "opax")
|
|
session_id = body.get("session_id", "default")
|
|
mode = body.get("mode", "A")
|
|
|
|
if not message:
|
|
return jsonify({"error": "'message' field required"}), 400
|
|
|
|
try:
|
|
response = run(
|
|
message=message,
|
|
user_id=user_id,
|
|
session_id=session_id,
|
|
mode=mode,
|
|
)
|
|
return jsonify({"response": response})
|
|
except PermissionError as e:
|
|
return jsonify({"error": str(e)}), 403
|
|
except ValueError as e:
|
|
return jsonify({"error": str(e)}), 400
|
|
except Exception as e:
|
|
return jsonify({"error": str(e)}), 500
|
|
|
|
|
|
if __name__ == "__main__":
|
|
port = int(os.environ.get("PORT", 8080))
|
|
app.run(host="0.0.0.0", port=port)
|