feat(awooop): surface callback replies on run list
This commit is contained in:
@@ -217,6 +217,9 @@ async def list_runs(
|
||||
"created_at": r.created_at,
|
||||
"timeout_at": r.timeout_at,
|
||||
"remediation_summary": remediation_summaries.get(r.run_id),
|
||||
"callback_reply_summary": _run_callback_reply_summary(
|
||||
outbound_by_run.get(r.run_id, [])
|
||||
),
|
||||
}
|
||||
for r in rows
|
||||
]
|
||||
@@ -382,6 +385,69 @@ def _outbound_timeline_metadata(
|
||||
return metadata
|
||||
|
||||
|
||||
def _run_callback_reply_summary(
|
||||
outbound_messages: list[AwoooPOutboundMessage],
|
||||
) -> dict[str, Any]:
|
||||
"""Summarize Telegram detail/history callback reply delivery for Run List."""
|
||||
callback_rows: list[tuple[AwoooPOutboundMessage, dict[str, Any]]] = []
|
||||
for row in outbound_messages:
|
||||
callback_reply = _outbound_callback_reply(row.source_envelope)
|
||||
if callback_reply:
|
||||
callback_rows.append((row, callback_reply))
|
||||
|
||||
if not callback_rows:
|
||||
return {
|
||||
"schema_version": "awooop_run_callback_reply_summary_v1",
|
||||
"status": "no_callback",
|
||||
"total": 0,
|
||||
"sent": 0,
|
||||
"fallback_sent": 0,
|
||||
"rescue_sent": 0,
|
||||
"failed": 0,
|
||||
"needs_human": False,
|
||||
"latest_status": None,
|
||||
"latest_action": None,
|
||||
"latest_incident_id": None,
|
||||
"latest_at": None,
|
||||
"latest_provider_message_id": None,
|
||||
}
|
||||
|
||||
sorted_rows = sorted(
|
||||
callback_rows,
|
||||
key=lambda item: str(item[0].sent_at or item[0].queued_at or ""),
|
||||
reverse=True,
|
||||
)
|
||||
latest_row, latest_callback = sorted_rows[0]
|
||||
statuses = [
|
||||
str(callback.get("status") or "")
|
||||
for _, callback in sorted_rows
|
||||
]
|
||||
failed = statuses.count("callback_reply_failed")
|
||||
latest_status = str(latest_callback.get("status") or "")
|
||||
summary_status = {
|
||||
"callback_reply_sent": "sent",
|
||||
"callback_reply_fallback_sent": "fallback_sent",
|
||||
"callback_reply_rescue_sent": "rescue_sent",
|
||||
"callback_reply_failed": "failed",
|
||||
}.get(latest_status, "observed")
|
||||
|
||||
return {
|
||||
"schema_version": "awooop_run_callback_reply_summary_v1",
|
||||
"status": summary_status,
|
||||
"total": len(sorted_rows),
|
||||
"sent": statuses.count("callback_reply_sent"),
|
||||
"fallback_sent": statuses.count("callback_reply_fallback_sent"),
|
||||
"rescue_sent": statuses.count("callback_reply_rescue_sent"),
|
||||
"failed": failed,
|
||||
"needs_human": failed > 0 or latest_status == "callback_reply_failed",
|
||||
"latest_status": latest_status or None,
|
||||
"latest_action": latest_callback.get("action"),
|
||||
"latest_incident_id": latest_callback.get("incident_id"),
|
||||
"latest_at": latest_row.sent_at or latest_row.queued_at,
|
||||
"latest_provider_message_id": latest_row.provider_message_id,
|
||||
}
|
||||
|
||||
|
||||
def _mcp_gateway_summary_row(row: AwoooPMcpGatewayAudit) -> dict[str, Any]:
|
||||
"""Convert SQLAlchemy audit rows into the truth-chain summary shape."""
|
||||
return {
|
||||
@@ -441,6 +507,7 @@ def _collect_run_incident_ids(
|
||||
_append_incident_ids_from_text(incident_ids, event.content_redacted)
|
||||
|
||||
for message in outbound_messages:
|
||||
_append_incident_ids_from_source_envelope(incident_ids, message.source_envelope)
|
||||
_append_incident_ids_from_text(incident_ids, message.content_preview)
|
||||
_append_incident_ids_from_text(incident_ids, message.send_error)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user