Bladeren bron

Remove the YAML -> env config bridge

@DeprecationWarning as a decorator replaced the function with an
exception instance, which register() then passed to Hermes as
apply_yaml_config_fn — calling it would have raised TypeError.

The hook only mutated process-wide environment variables; config.yaml
already reaches the adapter through PlatformConfig.extra, which
ChattoConfiguration reads directly. Drop it along with
EXTRA_ENV_MAPPING, so ConfigField.env_name is the single source of truth
for env var names.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Paul-Dieter Klumpp 1 week geleden
bovenliggende
commit
51e407d60b
2 gewijzigde bestanden met toevoegingen van 2 en 53 verwijderingen
  1. 0 44
      adapter.py
  2. 2 9
      platform_config.py

+ 0 - 44
adapter.py

@@ -1298,49 +1298,6 @@ def hermes_is_connected(config: PlatformConfig) -> bool:
 
 
 
-# ---------------------------------------------------------------------------
-# YAML → env config bridge
-# ---------------------------------------------------------------------------
-
-@DeprecationWarning
-def hermes_apply_yaml_config_fn(yaml_dict: dict, platform_dict: dict) -> Optional[dict]:
-    """Translate config.yaml chatto.extra keys into CHATTO_* env vars.
-    I don't actually get why Hermes wants us to modify OS environment variables.
-    Bad behavior in my book.
-    
-    Also .. I don't think we need this"""
-
-    if not isinstance(platform_dict, dict):
-        platform_dict = {}
-    extra = platform_dict.get("extra", {}) or {}
-    if not isinstance(extra, dict):
-        extra = {}
-
-    for yaml_key, env_key in ChattoConstants.EXTRA_ENV_MAPPING.items():
-        val = extra.get(yaml_key)
-        if val is not None and not os.getenv(env_key):
-            if isinstance(val, bool):
-                env_val = str(val).lower()
-            elif isinstance(val, list):
-                env_val = ",".join(str(v) for v in val)
-            else:
-                env_val = str(val)
-            os.environ[env_key] = env_val
-
-    channels = extra.get(ChattoConfiguration.channels.field_name)
-    if isinstance(channels, list) and not os.getenv(ChattoConfiguration.channels.env_name):
-        os.environ[ChattoConfiguration.channels.env_name] = ",".join(str(c) for c in channels)
-
-    allowed = extra.get(ChattoConfiguration.allowed_users.field_name)
-    if isinstance(allowed, list) and not os.getenv(ChattoConfiguration.allowed_users.env_name):
-        os.environ[ChattoConfiguration.allowed_users.env_name] = ",".join(str(u) for u in allowed)
-
-    if ChattoConfiguration.allow_all_users.field_name in extra and not os.getenv(ChattoConfiguration.allow_all_users.env_name):
-        os.environ[ChattoConfiguration.allow_all_users.env_name] = str(extra[ChattoConfiguration.allow_all_users.field_name]).lower()
-
-    return None
-
-
 def hermes_setup_fn() -> None:
     """Interactive setup wizard for Chatto. Is called by and only works in Hermes CLI context.
     Function name should be the same as register argument name with "hermes_" prefix, so we
@@ -1442,7 +1399,6 @@ def register(ctx) -> None:
         install_hint=ChattoConstants.INSTALL_HINT,
         env_enablement_fn=hermes_env_enablement_fn,
         setup_fn=hermes_setup_fn,
-        apply_yaml_config_fn=hermes_apply_yaml_config_fn,
         cron_deliver_env_var=ChattoConfiguration.home_channel.env_name,
         standalone_sender_fn=hermes_standalone_sender_fn,
         allowed_users_env=ChattoConfiguration.allowed_users.env_name,

+ 2 - 9
platform_config.py

@@ -47,15 +47,8 @@ class ChattoConstants:
 
     INSTALL_HINT = "Requires a Chatto server. See https://docs.chatto.run"
 
-    EXTRA_ENV_MAPPING = {
-        "base_url": "CHATTO_BASE_URL",
-        "home_channel": "CHATTO_HOME_CHANNEL",
-        "require_mention": "CHATTO_REQUIRE_MENTION",
-        "free_response_channels": "CHATTO_FREE_RESPONSE_CHANNELS",
-        "auto_thread": "CHATTO_AUTO_THREAD",
-        "allow_all_users": "CHATTO_ALLOW_ALL_USERS",
-        "allowed_users": "CHATTO_ALLOWED_USERS",
-    }
+    # NOTE: env var names live on the ConfigFields below (ConfigField.env_name),
+    # so there is exactly one source of truth for them.
 
     MAX_MESSAGE_LENGTH = 10000
     SEEN_CAP = 500