@@ -2992,6 +2992,16 @@ def _json_safe(value):
29922992 return value
29932993
29942994
2995+ def _agent_status_response (status ):
2996+ try :
2997+ status_code = int (status )
2998+ except (TypeError , ValueError ):
2999+ status_code = 502
3000+ if status_code < 100 or status_code > 599 :
3001+ status_code = 502
3002+ return jsonify ({"ok" : 200 <= status_code < 300 , "status_code" : status_code }), status_code
3003+
3004+
29953005# ---------------------------------------------------------------------------
29963006# Agent mode endpoints (proxy to agent service)
29973007# ---------------------------------------------------------------------------
@@ -3021,8 +3031,8 @@ def agent_get_task(task_id):
30213031 if task_id is None :
30223032 return jsonify ({"error" : "invalid task id" }), 400
30233033 try :
3024- data , status = _agent_request ("GET" , _agent_task_path (task_id ))
3025- return jsonify ( _json_safe ( data )), status
3034+ _ , status = _agent_request ("GET" , _agent_task_path (task_id ))
3035+ return _agent_status_response ( status )
30263036 except Exception :
30273037 log .exception ("agent service unavailable" )
30283038 return jsonify ({"error" : "agent service unavailable" }), 503
@@ -3036,10 +3046,10 @@ def agent_approve_steps(task_id):
30363046 return jsonify ({"error" : "invalid task id" }), 400
30373047 body = request .get_json (silent = True ) or {}
30383048 try :
3039- data , status = _agent_request ("POST" , _agent_task_path (task_id , "/approve" ), json_body = body )
3049+ _ , status = _agent_request ("POST" , _agent_task_path (task_id , "/approve" ), json_body = body )
30403050 event = "agent_steps_approved" if 200 <= status < 300 else "agent_steps_approve_failed"
30413051 _ui_audit .append (event , {"task_id" : task_id , "status_code" : status })
3042- return jsonify ( _json_safe ( data )), status
3052+ return _agent_status_response ( status )
30433053 except Exception :
30443054 log .exception ("agent service unavailable" )
30453055 return jsonify ({"error" : "agent service unavailable" }), 503
@@ -3053,10 +3063,10 @@ def agent_deny_steps(task_id):
30533063 return jsonify ({"error" : "invalid task id" }), 400
30543064 body = request .get_json (silent = True ) or {}
30553065 try :
3056- data , status = _agent_request ("POST" , _agent_task_path (task_id , "/deny" ), json_body = body )
3066+ _ , status = _agent_request ("POST" , _agent_task_path (task_id , "/deny" ), json_body = body )
30573067 event = "agent_steps_denied" if 200 <= status < 300 else "agent_steps_deny_failed"
30583068 _ui_audit .append (event , {"task_id" : task_id , "status_code" : status })
3059- return jsonify ( _json_safe ( data )), status
3069+ return _agent_status_response ( status )
30603070 except Exception :
30613071 log .exception ("agent service unavailable" )
30623072 return jsonify ({"error" : "agent service unavailable" }), 503
@@ -3069,10 +3079,10 @@ def agent_cancel_task(task_id):
30693079 if task_id is None :
30703080 return jsonify ({"error" : "invalid task id" }), 400
30713081 try :
3072- data , status = _agent_request ("POST" , _agent_task_path (task_id , "/cancel" ), json_body = {})
3082+ _ , status = _agent_request ("POST" , _agent_task_path (task_id , "/cancel" ), json_body = {})
30733083 event = "agent_task_cancelled" if 200 <= status < 300 else "agent_task_cancel_failed"
30743084 _ui_audit .append (event , {"task_id" : task_id , "status_code" : status })
3075- return jsonify ( _json_safe ( data )), status
3085+ return _agent_status_response ( status )
30763086 except Exception :
30773087 log .exception ("agent service unavailable" )
30783088 return jsonify ({"error" : "agent service unavailable" }), 503
0 commit comments