algunas soluciones

This commit is contained in:
Juan
2026-05-11 17:30:44 +02:00
parent ce629139c2
commit 9377730de4
4 changed files with 72 additions and 8 deletions
+4 -1
View File
@@ -66,6 +66,9 @@ class CoreClient:
def _post(self, path: str, body: dict) -> Any:
r = self._client.post(path, json=body)
if r.status_code in {404, 409, 422}:
return {"error": r.json()}
# Clave deliberadamente distinta de "error": el cuerpo de un AgentExecution
# correcto ya trae error=None, así que las páginas no podrían distinguir
# "ejecución sin error" de "la API rechazó la petición" si reusáramos "error".
return {"api_error": r.json()}
r.raise_for_status()
return r.json()
@@ -53,7 +53,9 @@ if st.button("🚀 Invocar agente", type="primary", disabled=not user_input):
st.session_state["last_execution"] = result
execution = st.session_state.get("last_execution")
if execution and "error" not in execution:
if execution and "api_error" in execution:
st.error(f"Error de la API: {execution['api_error']}")
elif execution:
st.divider()
st.markdown(f"**trace_id:** `{execution['trace_id']}`")
st.markdown(f"**Status:** `{execution['status']}`")
@@ -63,10 +65,10 @@ if execution and "error" not in execution:
"Esta ejecución requiere aprobación humana. "
"Ve a la página **Aprobaciones** para revisar y decidir."
)
if execution.get("error"):
st.error(f"La ejecución terminó con error: `{execution['error']}`")
if execution.get("final_output"):
st.subheader("📦 Output final")
st.json(execution["final_output"])
render_violations(execution.get("violations", []))
render_trace(execution.get("decision_path", []))
elif execution and "error" in execution:
st.error(f"Error de la API: {execution['error']}")
@@ -65,8 +65,8 @@ with col_a:
execution["trace_id"],
{"approved_action_ids": approved_ids, "comment": comment},
)
if "error" in r:
st.error(r["error"])
if "api_error" in r:
st.error(r["api_error"])
else:
st.success(f"Status: {r['status']}")
st.rerun()
@@ -75,8 +75,8 @@ with col_r:
if st.button("❌ Rechazar ejecución", disabled=not reason):
with st.spinner("Aplicando rechazo..."):
r = client.reject(execution["trace_id"], {"reason": reason})
if "error" in r:
st.error(r["error"])
if "api_error" in r:
st.error(r["api_error"])
else:
st.success(f"Status: {r['status']}")
st.rerun()