execution_view_payload.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. from __future__ import annotations
  2. from copy import deepcopy
  3. from typing import Any
  4. _REVIEW_KEYS = {
  5. "id",
  6. "eventId",
  7. "roundIndex",
  8. "branchIds",
  9. "branchConclusions",
  10. "comparison",
  11. "recommendation",
  12. "conclusion",
  13. "status",
  14. "startedAt",
  15. "endedAt",
  16. "detailRef",
  17. "promptRef",
  18. "decisionProjection",
  19. }
  20. def compact_execution_view(view: dict[str, Any]) -> dict[str, Any]:
  21. """Return the card-level V8 payload used by the main canvas.
  22. Inspector blocks, evaluator bodies and raw runtime previews remain available
  23. through the round/activity endpoints. Keeping this boundary here prevents
  24. the browser from downloading the same large report once per card.
  25. """
  26. compact = deepcopy(view)
  27. _strip_decision_details(compact)
  28. for round_ in compact.get("rounds") or []:
  29. for branch in round_.get("branches") or []:
  30. branch["dataDecisions"] = [
  31. {
  32. "id": item.get("id"),
  33. "node": item.get("node"),
  34. }
  35. for item in branch.get("dataDecisions") or []
  36. if isinstance(item, dict)
  37. ]
  38. for batch in round_.get("convergenceBatches") or []:
  39. review = batch.get("review")
  40. if isinstance(review, dict):
  41. batch["review"] = {
  42. key: value for key, value in review.items() if key in _REVIEW_KEYS
  43. }
  44. return compact
  45. def _strip_decision_details(value: Any) -> None:
  46. if isinstance(value, dict):
  47. if value.get("semanticKind") == "decision":
  48. value.pop("detail", None)
  49. value.pop("inputPreview", None)
  50. value.pop("outputPreview", None)
  51. value.pop("agentType", None)
  52. for child in value.values():
  53. _strip_decision_details(child)
  54. return
  55. if isinstance(value, list):
  56. for child in value:
  57. _strip_decision_details(child)