from __future__ import annotations from app.modules.agent_api.infrastructure.logging.request_trace_logger import RequestTraceLogger from app.modules.agent_api.infrastructure.streaming.sse_event_channel import SseEventChannel from app.modules.orchestration.messaging.status_message_factory import StatusMessageFactory from app.modules.orchestration.messaging.user_message_factory import UserMessageFactory class ClientMessagePublisher: def __init__(self, channel: SseEventChannel, trace_logger: RequestTraceLogger) -> None: self._channel = channel self._trace_logger = trace_logger self._status = StatusMessageFactory() self._user = UserMessageFactory() async def publish_status(self, request_id: str, source: str, text: str, payload: dict | None = None) -> None: event = self._status.create(request_id, source, text, payload) self._trace_logger.log_event(event) await self._channel.publish(event) async def publish_user(self, request_id: str, source: str, text: str, payload: dict | None = None) -> None: event = self._user.create(request_id, source, text, payload) self._trace_logger.log_event(event) await self._channel.publish(event)