def _stack_service(request: Request,
                   default_environment: Text) -> StackService:
    settings_service = SettingsService(request[REQUEST_DB_SESSION_KEY])

    environment = rasa_x_utils.deployment_environment_from_request(
        request, default_environment)
    service = settings_service.get_stack_service(environment)
    if not service:
        raise ValueError(
            f"Service for requested environment '{environment}' not found")

    return service
    async def minimum_compatible_version(self) -> Optional[Text]:
        from rasax.community.services.settings_service import SettingsService

        if config.LOCAL_MODE:
            # In local mode Rasa X and Rasa are in the same environment
            from rasa.constants import MINIMUM_COMPATIBLE_VERSION

            return MINIMUM_COMPATIBLE_VERSION

        settings_service = SettingsService(self.session)
        stack_service = settings_service.get_stack_service(self.environment)
        info = await stack_service.version()
        if info:
            return info.get("minimum_compatible_version")
        else:
            logger.debug("Couldn't get a minimum compatible model version.")
            return None