refactor(api): reuse _COMPACTION_INTERNAL_FIELDS from compaction_display

The 7-key internal-fields tuple was inlined twice (agent/compaction_display.py
and _project_client_message); a drift between the copies would silently leak
one internal field class through the API projection. Surfaced during review
of PR #85442.
This commit is contained in:
kshitijk4poor
2026-08-21 18:26:23 +05:30
committed by kshitij
parent a2a23a8f7e
commit b2c4f1f376
+5 -10
View File
@@ -441,20 +441,15 @@ def _project_client_message(message: Dict[str, Any]) -> Dict[str, Any]:
summary delimiter. Tool calls are dropped from both shapes because a
carrier's inherited calls are historical context, not live client output.
"""
from agent.compaction_display import project_compaction_message_for_display
from agent.compaction_display import (
_COMPACTION_INTERNAL_FIELDS,
project_compaction_message_for_display,
)
projected = project_compaction_message_for_display(message)
if projected is None:
projected = message.copy()
for internal_key in (
"tool_calls",
"finish_reason",
"reasoning",
"reasoning_content",
"reasoning_details",
"codex_reasoning_items",
"codex_message_items",
):
for internal_key in _COMPACTION_INTERNAL_FIELDS:
projected.pop(internal_key, None)
projected["content"] = ""
projected["display_kind"] = "hidden"