"""Web-UI message renderer registry."""

from __future__ import annotations

from typing import Any, Callable


# Type for message renderer: (message) -> str
MessageRenderer = Callable[[Any], str]

_message_renderers: dict[str, MessageRenderer] = {}


def register_message_renderer(role: str, renderer: MessageRenderer) -> None:
    """Register a custom renderer for a message role."""
    _message_renderers[role] = renderer


def get_message_renderer(role: str) -> MessageRenderer | None:
    """Get the registered renderer for a message role."""
    return _message_renderers.get(role)


def get_all_message_renderers() -> dict[str, MessageRenderer]:
    """Get all registered message renderers."""
    return dict(_message_renderers)
