"""Dispatch HTTP inbox endpoint (D4 / DISPATCH_DELIVERY_MODE=http_inbox). Receives inbound command/event envelopes from dispatch-api and returns a business confirmation. Authenticated as a service participant via X-API-Key. """ from __future__ import annotations from fastapi import APIRouter, Depends from app.api.schemas import DispatchConfirm, DispatchEnvelope from app.api.security import require_service_api_key from app.integrations.dispatch_client import handle_inbox_message router = APIRouter(tags=["dispatch"]) @router.post( "/dispatch/inbox", response_model=DispatchConfirm, dependencies=[Depends(require_service_api_key)], ) def dispatch_inbox(envelope: DispatchEnvelope) -> DispatchConfirm: result = handle_inbox_message(envelope.model_dump()) return DispatchConfirm( status=result.get("status", "confirmed"), event_id=envelope.event_id, handled=result.get("handled"), duplicate=result.get("duplicate"), )