from collections.abc import Mapping
from typing import Any

from backend.utils.artifact_summaries import (
    ARTIFACT_SUMMARIES_KEY,
    build_artifact_summary_parts_for_message,
)


def add_history_artifact_summaries(entry: dict[str, Any], message: Mapping[str, Any]) -> None:
    """Attach artifact summary sidecars to one history entry when the source message produced artifacts."""

    artifact_summary_parts = build_artifact_summary_parts_for_message(message)
    if artifact_summary_parts:
        entry[ARTIFACT_SUMMARIES_KEY] = artifact_summary_parts
