from __future__ import annotations from copy import deepcopy from typing import Any _REVIEW_KEYS = { "id", "eventId", "roundIndex", "branchIds", "branchConclusions", "comparison", "recommendation", "conclusion", "status", "startedAt", "endedAt", "detailRef", "promptRef", "decisionProjection", } def compact_execution_view(view: dict[str, Any]) -> dict[str, Any]: """Return the card-level V8 payload used by the main canvas. Inspector blocks, evaluator bodies and raw runtime previews remain available through the round/activity endpoints. Keeping this boundary here prevents the browser from downloading the same large report once per card. """ compact = deepcopy(view) _strip_decision_details(compact) for round_ in compact.get("rounds") or []: for branch in round_.get("branches") or []: branch["dataDecisions"] = [ { "id": item.get("id"), "node": item.get("node"), } for item in branch.get("dataDecisions") or [] if isinstance(item, dict) ] for batch in round_.get("convergenceBatches") or []: review = batch.get("review") if isinstance(review, dict): batch["review"] = { key: value for key, value in review.items() if key in _REVIEW_KEYS } return compact def _strip_decision_details(value: Any) -> None: if isinstance(value, dict): if value.get("semanticKind") == "decision": value.pop("detail", None) value.pop("inputPreview", None) value.pop("outputPreview", None) value.pop("agentType", None) for child in value.values(): _strip_decision_details(child) return if isinstance(value, list): for child in value: _strip_decision_details(child)