Spaces:
Sleeping
Sleeping
Refactor check_approval to hang the connection
Browse files
main.py
CHANGED
|
@@ -912,20 +912,28 @@ APPROVALS = {
|
|
| 912 |
@app.post("/api/agent/approval-request")
|
| 913 |
async def check_approval(req: ApprovalRequest):
|
| 914 |
"""
|
| 915 |
-
Maestro
|
| 916 |
-
|
| 917 |
-
|
| 918 |
"""
|
| 919 |
gate = req.gate.lower()
|
| 920 |
-
is_approved = APPROVALS.get(gate, False)
|
| 921 |
|
| 922 |
-
#
|
| 923 |
-
if
|
| 924 |
-
|
| 925 |
-
|
| 926 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 927 |
|
| 928 |
-
return {"status": "success", "approved":
|
| 929 |
|
| 930 |
|
| 931 |
@app.get("/approve", response_class=HTMLResponse)
|
|
|
|
| 912 |
@app.post("/api/agent/approval-request")
|
| 913 |
async def check_approval(req: ApprovalRequest):
|
| 914 |
"""
|
| 915 |
+
Maestro fires a single HTTP POST here.
|
| 916 |
+
We hang (wait) internally until the human clicks approve in our UI,
|
| 917 |
+
forcing Maestro to pause on this step naturally.
|
| 918 |
"""
|
| 919 |
gate = req.gate.lower()
|
|
|
|
| 920 |
|
| 921 |
+
# Broadcast the pause event to the React dashboard
|
| 922 |
+
agent_idx = 1 if gate == "triage" else 7
|
| 923 |
+
agent_name = "Gate 1: Triage" if gate == "triage" else "Gate 2: BSA Officer"
|
| 924 |
+
await broadcaster.broadcast("agent_pause", {"agent": agent_idx, "name": agent_name})
|
| 925 |
+
|
| 926 |
+
# Loop indefinitely until human approves (up to 120 seconds for safety)
|
| 927 |
+
timeout = 120
|
| 928 |
+
elapsed = 0
|
| 929 |
+
while not APPROVALS.get(gate, False) and elapsed < timeout:
|
| 930 |
+
await asyncio.sleep(2)
|
| 931 |
+
elapsed += 2
|
| 932 |
+
|
| 933 |
+
# Reset for next run
|
| 934 |
+
APPROVALS[gate] = False
|
| 935 |
|
| 936 |
+
return {"status": "success", "approved": True}
|
| 937 |
|
| 938 |
|
| 939 |
@app.get("/approve", response_class=HTMLResponse)
|