from http.server import BaseHTTPRequestHandler

from amc_server.mixins.conversation import ConversationMixin
from amc_server.mixins.control import SessionControlMixin
from amc_server.mixins.discovery import SessionDiscoveryMixin
from amc_server.mixins.http import HttpMixin
from amc_server.mixins.parsing import SessionParsingMixin
from amc_server.mixins.skills import SkillsMixin
from amc_server.mixins.spawn import SpawnMixin
from amc_server.mixins.state import StateMixin


class AMCHandler(
    HttpMixin,
    StateMixin,
    ConversationMixin,
    SessionControlMixin,
    SessionDiscoveryMixin,
    SessionParsingMixin,
    SkillsMixin,
    SpawnMixin,
    BaseHTTPRequestHandler,
):
    """HTTP handler composed from focused mixins."""

    def handle(self):
        """Ignore expected disconnect noise from short-lived HTTP/SSE clients."""
        try:
            super().handle()
        except (ConnectionResetError, BrokenPipeError):
            return
