"""Process-local registry mapping agent IDs to their metadata.

Used by the decorator to resolve the *actual* agent name (including nested agents)
when constructing AgentRuntimeError on the consumer side.
"""

from __future__ import annotations

from yera.agents.dataclasses import AgentMetadata

_AGENT_REGISTRY: dict[str, AgentMetadata] = {}


def register_agent(agent_id: str, metadata: AgentMetadata) -> None:
    """Register metadata for a given agent_id in the current process."""
    _AGENT_REGISTRY[agent_id] = metadata


def get_agent_metadata(agent_id: str) -> AgentMetadata | None:
    """Look up metadata for the given agent_id."""
    return _AGENT_REGISTRY.get(agent_id)


def get_agent_name(agent_id: str) -> str | None:
    """Return the display name for the given agent_id, or None if unknown."""
    meta = get_agent_metadata(agent_id)
    return meta.name if meta is not None else None
