48 lines
1.3 KiB
Python
48 lines
1.3 KiB
Python
"""Client-facing projection helpers for model-only compaction carriers."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any, Dict, Optional
|
|
|
|
from agent.context_compressor import (
|
|
ContextCompressor,
|
|
is_compaction_summary_message,
|
|
)
|
|
|
|
|
|
_COMPACTION_INTERNAL_FIELDS = (
|
|
"tool_calls",
|
|
"finish_reason",
|
|
"reasoning",
|
|
"reasoning_content",
|
|
"reasoning_details",
|
|
"codex_reasoning_items",
|
|
"codex_message_items",
|
|
)
|
|
|
|
|
|
def project_compaction_message_for_display(
|
|
message: Dict[str, Any],
|
|
) -> Optional[Dict[str, Any]]:
|
|
"""Return authentic transcript content, or ``None`` for a pure handoff.
|
|
|
|
Model-facing recovery history retains the complete carrier. Display
|
|
projections instead remove the handoff, inherited tool state, and internal
|
|
reasoning while preserving any real prior-tail content or live user ask
|
|
embedded in the carrier.
|
|
"""
|
|
if not isinstance(message, dict):
|
|
return None
|
|
if not is_compaction_summary_message(message):
|
|
return message.copy()
|
|
|
|
projected = ContextCompressor._strip_context_summary_handoff_message(message)
|
|
if projected is None:
|
|
return None
|
|
|
|
projected = projected.copy()
|
|
for key in _COMPACTION_INTERNAL_FIELDS:
|
|
projected.pop(key, None)
|
|
projected.pop("display_kind", None)
|
|
return projected
|