Skip to content

The agent that grows with you

refactor(platforms): read connected checks, allowlist env, cron home vars and status labels from the plugin registry

Teknium0663bdf98c1b
diff --git a/cron/scheduler_delivery.py b/cron/scheduler_delivery.py
index 9a36f425286..5eb7dd3c7c5 100644
--- a/cron/scheduler_delivery.py
+++ b/cron/scheduler_delivery.py
@@ -24,35 +24,24 @@ logger = logging.getLogger("cron.scheduler")
# Validates user-supplied delivery platform names, preventing env-var enumeration via crafted names.
-_KNOWN_DELIVERY_PLATFORMS = frozenset({
- "telegram", "discord", "slack", "whatsapp", "signal",
- "matrix", "mattermost", "dingtalk", "feishu",
- "wecom", "wecom_callback", "weixin", "sms", "email", "webhook", "bluebubbles",
- "qqbot", "yuanbao"})
+# Plugin platforms are known through ``PlatformEntry.cron_deliver_env_var``; these rows have none:
+# ``webhook`` is core-only and ``wecom_callback`` (a ``wecom`` plugin sibling) delivers only to its
+# config.yaml ``home_channel``.
+_KNOWN_DELIVERY_PLATFORMS = frozenset({"webhook", "wecom_callback"})
# Gateway platforms whose adapter declares ``supports_async_delivery = False`` (request/response
# only, ``send()`` is a stub) — a cron report can never reach them, so they are never a
# deliver=origin destination.
_NON_PUSH_ORIGIN_PLATFORMS = frozenset({"api_server"})
-# Platforms supporting a cron/notification home target -> env var used by gateway config.
-_HOME_TARGET_ENV_VARS = {
- "matrix": "MATRIX_HOME_ROOM",
- "telegram": "TELEGRAM_HOME_CHANNEL",
- "discord": "DISCORD_HOME_CHANNEL",
- "slack": "SLACK_HOME_CHANNEL",
- "signal": "SIGNAL_HOME_CHANNEL",
- "mattermost": "MATTERMOST_HOME_CHANNEL",
- "sms": "SMS_HOME_CHANNEL",
- "email": "EMAIL_HOME_ADDRESS",
- "dingtalk": "DINGTALK_HOME_CHANNEL",
- "feishu": "FEISHU_HOME_CHANNEL",
- "wecom": "WECOM_HOME_CHANNEL",
- "weixin": "WEIXIN_HOME_CHANNEL",
- "bluebubbles": "BLUEBUBBLES_HOME_CHANNEL",
- "qqbot": "QQBOT_HOME_CHANNEL",
- "whatsapp": "WHATSAPP_HOME_CHANNEL",
- "whatsapp_cloud": "WHATSAPP_CLOUD_HOME_CHANNEL"}
+# Home-target platforms tried first, in this order, by ``deliver=origin`` with no origin (first
+# platform with a home chat wins) and ``deliver=all``; their env var is the plugin's
+# ``cron_deliver_env_var``. Other plugin platforms follow by name (a fresh process loads deferred
+# entries in name order, so this is the order they had when they trailed a static table).
+_HOME_TARGET_PRIORITY = (
+ "matrix", "telegram", "discord", "slack", "signal", "mattermost", "sms", "email", "dingtalk",
+ "feishu", "wecom", "weixin", "bluebubbles", "qqbot", "whatsapp", "whatsapp_cloud",
+)
# Back-compat: primary env var -> previous name, consulted when the primary is unset.
_LEGACY_HOME_TARGET_ENV_VARS = {"QQBOT_HOME_CHANNEL": "QQ_HOME_CHANNEL"}
@@ -421,9 +410,8 @@ def _is_known_delivery_platform(platform_name: str) -> bool:
def _resolve_home_env_var(platform_name: str) -> str:
- """Env var name for a platform's cron home channel (built-in table, then plugin registry)."""
- name = platform_name.lower()
- return _HOME_TARGET_ENV_VARS.get(name) or _plugin_cron_env_var(name)
+ """Env var name for a platform's cron home channel (``PlatformEntry.cron_deliver_env_var``)."""
+ return _plugin_cron_env_var(platform_name.lower())
def _get_config_home_channel(platform_name: str):
@@ -512,15 +500,14 @@ def _get_home_target_thread_id(platform_name: str) -> Optional[str]:
def _iter_home_target_platforms():
- """Iterate built-in + plugin platform names that expose a home channel."""
- yield from _HOME_TARGET_ENV_VARS
+ """Iterate plugin platform names that expose a home channel, ``_HOME_TARGET_PRIORITY`` first."""
with contextlib.suppress(Exception):
from hermes_cli.plugins import discover_plugins
discover_plugins() # idempotent
from gateway.platform_registry import platform_registry
- for entry in platform_registry.plugin_entries():
- if entry.cron_deliver_env_var and entry.name not in _HOME_TARGET_ENV_VARS:
- yield entry.name
+ named = {e.name for e in platform_registry.plugin_entries() if e.cron_deliver_env_var}
+ yield from (n for n in _HOME_TARGET_PRIORITY if n in named)
+ yield from sorted(named - set(_HOME_TARGET_PRIORITY))
def _relay_fronted_delivery_platforms(connected: set) -> set:
diff --git a/gateway/authz_mixin.py b/gateway/authz_mixin.py
index c87b3ac2c80..501d72de6ec 100644
--- a/gateway/authz_mixin.py
+++ b/gateway/authz_mixin.py
@@ -16,7 +16,6 @@ from typing import Optional
from gateway.bot_loop_guard import BotLoopGuard
from gateway.config import Platform
-from gateway.pairing import _PLATFORM_ALLOWLIST_ENV
from gateway.session import SessionSource
from gateway.whatsapp_identity import (
expand_whatsapp_aliases as _expand_whatsapp_auth_aliases,
@@ -29,10 +28,17 @@ _TRUTHY = frozenset({"true", "1", "yes"})
_BOT_LOOP_GUARD_INIT_LOCK = threading.Lock()
logger = logging.getLogger(__name__)
-# Platform -> ``<PLATFORM>_ALLOWED_USERS`` / ``<PLATFORM>_ALLOW_ALL_USERS``. Shared with the pairing
-# store's allowlist mirror (single source of truth); plugin platforms are added per-call from the registry.
-_ALLOWED_USERS_ENV = {Platform(k): v for k, v in _PLATFORM_ALLOWLIST_ENV.items()}
-_ALLOW_ALL_ENV = {p: v.replace("_ALLOWED_USERS", "_ALLOW_ALL_USERS") for p, v in _ALLOWED_USERS_ENV.items()}
+# ``<PLATFORM>_ALLOWED_USERS`` / ``<PLATFORM>_ALLOW_ALL_USERS`` come from each platform's
+# ``PlatformEntry.allowed_users_env`` / ``allow_all_env`` (shared with the pairing allowlist mirror).
+# Platforms whose env allowlist turns the unauthorized-DM default from "pair" into "ignore". Names
+# only (the env var is still the plugin's): this is the historical set the allowlist-aware default
+# covered, so adding a platform here is a behaviour change (Yuanbao was never in it).
+_ALLOWLIST_SUPPRESSES_PAIRING = frozenset({
+ Platform.TELEGRAM, Platform.DISCORD, Platform.WHATSAPP, Platform.WHATSAPP_CLOUD, Platform.SLACK,
+ Platform.SIGNAL, Platform.EMAIL, Platform.SMS, Platform.MATTERMOST, Platform.MATRIX, Platform.DINGTALK,
+ Platform.FEISHU, Platform.WECOM, Platform.WECOM_CALLBACK, Platform.WEIXIN, Platform.BLUEBUBBLES,
+ Platform.QQBOT,
+})
_GROUP_USER_ENV = {Platform.TELEGRAM: "TELEGRAM_GROUP_ALLOWED_USERS"}
_GROUP_CHAT_ENV = {Platform.TELEGRAM: "TELEGRAM_GROUP_ALLOWED_CHATS", Platform.QQBOT: "QQ_GROUP_ALLOWED_USERS"}
_ALLOW_BOTS_ENV = {
@@ -58,9 +64,13 @@ def _env_truthy(name: str) -> bool:
def _registry_entry(platform):
- """Platform-registry entry for a (plugin) platform, or None."""
+ """Platform-registry entry for a (plugin) platform, or None. Discovers first (idempotent): the
+ allowlist env names live only on the entry, so an undiscovered process must not read "no list"."""
if platform is None:
return None
+ with contextlib.suppress(Exception):
+ from hermes_cli.plugins import discover_plugins
+ discover_plugins()
with contextlib.suppress(Exception):
from gateway.platform_registry import platform_registry
@@ -652,13 +662,9 @@ class GatewayAuthorizationMixin:
if not user_id:
return False
- platform_allow_env = _ALLOWED_USERS_ENV.get(source.platform, "")
- platform_allow_all_var = _ALLOW_ALL_ENV.get(source.platform, "")
- if source.platform not in _ALLOWED_USERS_ENV:
- entry = _registry_entry(source.platform)
- with contextlib.suppress(Exception):
- platform_allow_env = getattr(entry, "allowed_users_env", "") or platform_allow_env
- platform_allow_all_var = getattr(entry, "allow_all_env", "") or platform_allow_all_var
+ entry = _registry_entry(source.platform)
+ platform_allow_env = getattr(entry, "allowed_users_env", "") or ""
+ platform_allow_all_var = getattr(entry, "allow_all_env", "") or ""
if platform_allow_all_var and _env_truthy(platform_allow_all_var):
return True
# Adapter-verified role auth (Discord DISCORD_ALLOWED_ROLES). ``is True``: no MagicMock pass.
@@ -740,8 +746,8 @@ class GatewayAuthorizationMixin:
return "pair"
if dm_policy in {"allowlist", "disabled"}:
return "ignore"
- # Historical: Yuanbao is absent from this allowlist-aware default.
- env_key = "" if platform == Platform.YUANBAO else _ALLOWED_USERS_ENV.get(platform, "")
+ env_key = (getattr(_registry_entry(platform), "allowed_users_env", "") or ""
+ if platform in _ALLOWLIST_SUPPRESSES_PAIRING else "")
allowlist_keys = [env_key, _GROUP_USER_ENV.get(platform), _GROUP_CHAT_ENV.get(platform), *allowlist_keys]
if any(key and _auth_env(key).strip() for key in allowlist_keys):
return "ignore"
diff --git a/gateway/config.py b/gateway/config.py
index 61a24aacae9..8f97b5bd260 100644
--- a/gateway/config.py
+++ b/gateway/config.py
@@ -553,27 +553,34 @@ def _has_usable_api_server_key(key: object) -> bool:
return len(str(key).strip()) >= 16
-def _needs_extra(*keys: str) -> Callable[[PlatformConfig], bool]:
- return lambda cfg: all(cfg.extra.get(k) for k in keys)
-
-
-# Built-in "sufficiently configured?" checks; platforms covered by the generic
-# ``token or api_key`` check (Telegram, Discord, Slack, Matrix, ...) need no entry.
+# Core-only "sufficiently configured?" checks (no plugin entry). Plugin platforms declare theirs as
+# ``PlatformEntry.config_connected_fn`` (or rely on the generic ``token or api_key`` check).
_PLATFORM_CONNECTED_CHECKERS: dict[Platform, Callable[[PlatformConfig], bool]] = {
- Platform.WEIXIN: lambda cfg: bool(cfg.extra.get("account_id") and (cfg.token or cfg.extra.get("token"))),
- Platform.WHATSAPP_CLOUD: _needs_extra("phone_number_id", "access_token"),
- Platform.SIGNAL: _needs_extra("http_url"),
Platform.API_SERVER: lambda cfg: _has_usable_api_server_key(cfg.extra.get("key") if cfg else None),
Platform.WEBHOOK: lambda cfg: True,
Platform.MSGRAPH_WEBHOOK: lambda cfg: bool(str(cfg.extra.get("client_state") or "").strip()),
- Platform.BLUEBUBBLES: _needs_extra("server_url", "password"),
- Platform.QQBOT: _needs_extra("app_id", "client_secret"),
- Platform.YUANBAO: _needs_extra("app_id", "app_secret"),
# Relay dials OUT: "connected" once an endpoint URL is configured. EXPERIMENTAL.
Platform.RELAY: lambda cfg: bool(cfg.extra.get("relay_url") or cfg.extra.get("url")),
}
+def _discovered_registry_entry(platform: Platform):
+ """Registry entry for *platform* after (idempotent) plugin discovery, so a directly-constructed
+ config sees plugin platforms; None when absent or the registry is not initialised yet (early import).
+
+ Enablement gate (#31116): a plugin's ``is_connected`` ("has the user actually configured
+ credentials for this?") is consulted before treating it as connected; ``check_fn`` alone — a
+ passive "is the SDK importable?" probe — must never make a platform the user never opted into
+ look connected (``_platform_status`` was fixed for the same bug class in commit 7849a3d73)."""
+ with contextlib.suppress(Exception):
+ from hermes_cli.plugins import discover_plugins
+ discover_plugins()
+ with contextlib.suppress(Exception): # registry not initialised yet during early import
+ from gateway.platform_registry import platform_registry
+ return platform_registry.get(platform.value)
+ return None
+
+
# Top-level bool-ish keys read verbatim (no nested ``gateway.`` fallback) with their defaults.
_TOPLEVEL_BOOL_DEFAULTS = {
"write_sessions_json": True, "always_log_local": True, "filter_silence_narration": True,
@@ -664,42 +671,21 @@ class GatewayConfig:
def _is_platform_connected(self, platform: Platform, config: PlatformConfig) -> bool:
checker = _PLATFORM_CONNECTED_CHECKERS.get(platform)
- # Weixin needs token AND account_id, so it must bypass the generic token branch.
- if platform == Platform.WEIXIN:
- return checker(config)
+ if checker is not None:
+ return bool(config.token or config.api_key) or checker(config)
+ entry = _discovered_registry_entry(platform)
+ # ``config_connected_fn`` owns the token shortcut (Weixin needs token AND account_id).
+ if entry is not None and entry.config_connected_fn is not None:
+ return entry.config_connected_fn(config)
if config.token or config.api_key:
return True
- if checker is not None:
- return checker(config)
-
- # Plugin platforms; force (idempotent) discovery for directly-constructed configs.
+ if entry is None:
+ return False
+ check = entry.is_connected if entry.is_connected is not None else entry.validate_config
try:
- from gateway.platform_registry import platform_registry
- with contextlib.suppress(Exception):
- # Iterate built-in platforms plus any registered plugin platforms so plugin authors get the
- # same shared-key bridging (#24836).
- # Registry-driven enable for plugin platforms. Built-ins have explicit blocks above. A
- # plugin platform is enabled when its credentials are configured (``is_connected``) and its
- # dependencies are either present (passive ``check_fn``) or installable on demand
- # (``ensure_deps_fn``, run later by ``create_adapter()`` — never here). Plugins that need to
- # seed ``PlatformConfig.extra`` from env vars (e.g. Google Chat's project_id /
- # subscription_name) can supply ``env_enablement_fn`` on their PlatformEntry — called here
- # BEFORE adapter construction. Enablement gate (#31116): when a plugin registers
- # ``is_connected`` (the "has the user actually configured credentials for this?" check), we
- # MUST consult it before flipping ``enabled = True``. Otherwise ``check_fn`` alone — a
- # passive "is the SDK importable?" probe — silently enables platforms the user never opted
- # into, and the gateway then tries to connect to Discord / Teams / Google Chat with no token
- # and emits noisy retry-forever errors. ``_platform_status`` was already fixed for the same
- # bug class in commit 7849a3d73; this is the runtime counterpart.
- from hermes_cli.plugins import discover_plugins
- discover_plugins()
- entry = platform_registry.get(platform.value)
- if entry:
- check = entry.is_connected if entry.is_connected is not None else entry.validate_config
- return True if check is None else check(config)
+ return True if check is None else check(config)
except Exception:
- pass # Registry not yet initialised during early import
- return False
+ return False
def get_home_channel(self, platform: Platform) -> Optional[HomeChannel]:
return self.platforms[platform].home_channel if self.platforms.get(platform) else None
diff --git a/gateway/pairing.py b/gateway/pairing.py
index 0e49e256112..d2721678045 100644
--- a/gateway/pairing.py
+++ b/gateway/pairing.py
@@ -59,29 +59,18 @@ def _default_pairing_dir() -> Path:
return PAIRING_DIR if PAIRING_DIR is not None else get_hermes_dir("platforms/pairing", "pairing")
-# Platform value -> allowlist env var. Approving a code also writes the user into
-# an already-configured allowlist (revoke removes them) so the operator's list stays
-# the visible source of truth. Platforms absent here (or with no allowlist
-# configured) keep the pairing store as the sole grant record (authz union).
-# See #23778.
-_PLATFORM_ALLOWLIST_ENV = {
- "telegram": "TELEGRAM_ALLOWED_USERS", "discord": "DISCORD_ALLOWED_USERS",
- "whatsapp": "WHATSAPP_ALLOWED_USERS", "whatsapp_cloud": "WHATSAPP_CLOUD_ALLOWED_USERS",
- "slack": "SLACK_ALLOWED_USERS", "signal": "SIGNAL_ALLOWED_USERS",
- "email": "EMAIL_ALLOWED_USERS", "sms": "SMS_ALLOWED_USERS",
- "mattermost": "MATTERMOST_ALLOWED_USERS", "matrix": "MATRIX_ALLOWED_USERS",
- "dingtalk": "DINGTALK_ALLOWED_USERS", "feishu": "FEISHU_ALLOWED_USERS",
- "wecom": "WECOM_ALLOWED_USERS", "wecom_callback": "WECOM_CALLBACK_ALLOWED_USERS",
- "weixin": "WEIXIN_ALLOWED_USERS", "bluebubbles": "BLUEBUBBLES_ALLOWED_USERS",
- "qqbot": "QQ_ALLOWED_USERS", "yuanbao": "YUANBAO_ALLOWED_USERS",
-}
-
-
def _allowlist_env_for_platform(platform: str) -> Optional[str]:
- """Allowlist env var name for ``platform`` (plugin registry fallback), or None."""
+ """Allowlist env var name for ``platform`` (its ``PlatformEntry.allowed_users_env``), or None.
+
+ Approving a code also writes the user into an already-configured allowlist (revoke removes
+ them) so the operator's list stays the visible source of truth. Platforms without one (or with
+ no allowlist configured) keep the pairing store as the sole grant record (authz union). See
+ #23778. Discovers plugins first: ``hermes pairing approve`` runs in a CLI process that may not
+ have loaded them yet."""
platform = (platform or "").lower().strip()
- if env_var := _PLATFORM_ALLOWLIST_ENV.get(platform):
- return env_var
+ with contextlib.suppress(Exception):
+ from hermes_cli.plugins import discover_plugins
+ discover_plugins() # idempotent
with contextlib.suppress(Exception):
from gateway.platform_registry import platform_registry
return platform_registry.get(platform).allowed_users_env or None
diff --git a/gateway/platform_registry.py b/gateway/platform_registry.py
index 2ec5558541d..4aa97be9588 100644
--- a/gateway/platform_registry.py
+++ b/gateway/platform_registry.py
@@ -118,6 +118,14 @@ class PlatformEntry:
# Env prefixes shared with a non-channel capability (the same plugin's tools): profile clones
# strip keys under them only when the source profile runs the adapter (profile_channels.py).
shared_env_prefixes: tuple = ()
+ # --- config ---
+ # Gateway "sufficiently configured?" verdict from the PlatformConfig ALONE (yaml + env seeding
+ # already merged into it), for ``GatewayConfig.get_connected_platforms``. Unlike ``is_connected``
+ # it never falls back to the env / ``.env`` (the gateway runs from the merged config, setup UIs
+ # read the env), and it owns the ``token``/``api_key`` shortcut so a platform that needs more
+ # than a token (Weixin: token AND account_id) can refuse it. None = ``token or api_key``, then
+ # ``is_connected`` / ``validate_config``.
+ config_connected_fn: Optional[Callable[[Any], bool]] = None
def core_ships_platform(name: str) -> bool:
diff --git a/gateway/platforms/_shared.py b/gateway/platforms/_shared.py
index cf220e0c414..92ccc2b4377 100644
--- a/gateway/platforms/_shared.py
+++ b/gateway/platforms/_shared.py
@@ -242,6 +242,16 @@ def env_is_connected(*names: str) -> Callable[[Any], bool]:
return is_connected
+def config_connected_extra(*keys: str) -> Callable[[Any], bool]:
+ """``PlatformEntry.config_connected_fn``: connected when the merged PlatformConfig carries a
+ token/api_key or every ``extra`` key (no env fallback; that is ``is_connected``'s job)."""
+
+ def config_connected(config: Any) -> bool:
+ return bool(config.token or config.api_key) or all(config.extra.get(k) for k in keys)
+
+ return config_connected
+
+
def coerce_port(value: Any, default: int) -> int:
"""``int(value)`` or ``default`` when unparseable (incl. non-finite YAML like ``.inf``)."""
try:
diff --git a/gateway/run.py b/gateway/run.py
index acda4ddea70..955cda5080b 100644
--- a/gateway/run.py
+++ b/gateway/run.py
@@ -1542,7 +1542,7 @@ def _collect_history_media_paths(agent_history: list[dict[str, Any]]) -> set:
return paths
def _home_target_env_var(platform_name: str) -> str:
- """Home-target env var: built-in ``_HOME_TARGET_ENV_VARS``, plugin registry, then
+ """Home-target env var: the plugin's ``cron_deliver_env_var``, then
``<PLATFORM>_HOME_CHANNEL``."""
from cron.scheduler_delivery import _resolve_home_env_var
return _resolve_home_env_var(platform_name) or f"{platform_name.upper()}_HOME_CHANNEL"
diff --git a/hermes_cli/status.py b/hermes_cli/status.py
index 6804726a7c5..6b071e306ac 100644
--- a/hermes_cli/status.py
+++ b/hermes_cli/status.py
@@ -112,12 +112,6 @@ _TERMINAL_ENV_ROWS = {
"daytona": (("Daytona Image:", "TERMINAL_DAYTONA_IMAGE", DEFAULT_SANDBOX_IMAGE, False),),
}
-# Labels for built-in adapters without a platform-registry entry; registry entries bring their own.
-_PLATFORM_LABELS = {"telegram": "Telegram", "discord": "Discord", "whatsapp": "WhatsApp", "signal": "Signal",
- "slack": "Slack", "email": "Email", "sms": "SMS", "dingtalk": "DingTalk", "feishu": "Feishu",
- "wecom": "WeCom", "wecom_callback": "WeCom Callback", "weixin": "Weixin",
- "bluebubbles": "BlueBubbles", "qqbot": "QQBot", "yuanbao": "Yuanbao"}
-
# Gateway manager label when the runtime snapshot is unavailable, keyed by platform.
_GATEWAY_FALLBACK = {"termux": ("unknown", "Termux / manual process"), "linux": ("unknown", "systemd/manual"),
"darwin": ("unknown", "launchd")}
@@ -202,12 +196,14 @@ def _render_platforms(ctx):
try:
from gateway.config import load_gateway_config
from gateway.platform_registry import platform_registry
+ from hermes_cli.plugins import discover_plugins
+ discover_plugins() # labels come from the plugin entries
cfg = load_gateway_config()
except Exception:
return
connected = {p.value for p in cfg.get_connected_platforms()}
homes = {p.value: pc.home_channel for p, pc in cfg.platforms.items() if pc.home_channel}
- labels = {**_PLATFORM_LABELS, **{e.name: e.label for e in platform_registry.plugin_entries()}}
+ labels = {e.name: e.label for e in platform_registry.plugin_entries()}
for value, label in sorted(labels.items(), key=lambda kv: kv[1].lower()):
home = homes.get(value)
_row(label, value in connected,
diff --git a/hermes_cli/web_routers/messaging.py b/hermes_cli/web_routers/messaging.py
index f146f692045..a7c4a8dd91c 100644
--- a/hermes_cli/web_routers/messaging.py
+++ b/hermes_cli/web_routers/messaging.py
@@ -956,20 +956,16 @@ def _platform_authz_env_names(platform_id: str) -> tuple[str, str]:
"""``(allowed_users_env, allow_all_env)`` for a platform, honoring plugin registry
entries. Empty strings mean "this platform has no per-user authorization surface"
(webhook-style trusted inbound or unknown), so no posture is computed for it."""
- from gateway.pairing import _PLATFORM_ALLOWLIST_ENV
-
- allowed = _PLATFORM_ALLOWLIST_ENV.get(platform_id, "")
- allow_all = allowed.replace("_ALLOWED_USERS", "_ALLOW_ALL_USERS")
- if not allowed:
- with contextlib.suppress(Exception):
- from gateway.platform_registry import platform_registry
-
- entry = platform_registry.get(platform_id)
- if entry is not None:
- if getattr(entry, "trusted_inbound", False) is True:
- return "", ""
- allowed = getattr(entry, "allowed_users_env", "") or ""
- allow_all = getattr(entry, "allow_all_env", "") or ""
+ allowed = allow_all = ""
+ with contextlib.suppress(Exception):
+ from gateway.platform_registry import platform_registry
+
+ entry = platform_registry.get(platform_id)
+ if entry is not None:
+ if getattr(entry, "trusted_inbound", False) is True:
+ return "", ""
+ allowed = getattr(entry, "allowed_users_env", "") or ""
+ allow_all = getattr(entry, "allow_all_env", "") or ""
return allowed, allow_all
diff --git a/plugins/platforms/bluebubbles/adapter.py b/plugins/platforms/bluebubbles/adapter.py
index 83d6bc689a7..e76766dc467 100644
--- a/plugins/platforms/bluebubbles/adapter.py
+++ b/plugins/platforms/bluebubbles/adapter.py
@@ -18,6 +18,7 @@ import httpx
from gateway.config import Platform, PlatformConfig
from gateway.platforms._shared import extra_or_secret as _extra_or_secret, get_scoped_secret as _get_scoped_secret
+from gateway.platforms._shared import config_connected_extra
from gateway.platforms.base import (
BasePlatformAdapter, SendResult,
cache_image_from_bytes_async, cache_audio_from_bytes_async, cache_document_from_bytes_async,
@@ -689,6 +690,7 @@ def register(ctx) -> None:
ctx.register_platform(
name="bluebubbles", label="BlueBubbles (iMessage)", adapter_factory=BlueBubblesAdapter,
check_fn=check_bluebubbles_requirements, is_connected=_is_connected,
+ config_connected_fn=config_connected_extra("server_url", "password"),
required_env=["BLUEBUBBLES_SERVER_URL", "BLUEBUBBLES_PASSWORD"], install_hint=_INSTALL_HINT,
setup_fn=interactive_setup,
allowed_users_env="BLUEBUBBLES_ALLOWED_USERS", allow_all_env="BLUEBUBBLES_ALLOW_ALL_USERS",
diff --git a/plugins/platforms/qqbot/register.py b/plugins/platforms/qqbot/register.py
index 819f0dbdce2..26f58d12ab2 100644
--- a/plugins/platforms/qqbot/register.py
+++ b/plugins/platforms/qqbot/register.py
@@ -8,6 +8,7 @@ connection.
from __future__ import annotations
from gateway.platforms._shared import env_is_connected
+from gateway.platforms._shared import config_connected_extra
from .adapter import QQAdapter, check_qq_requirements
@@ -128,6 +129,7 @@ def register(ctx) -> None:
adapter_factory=QQAdapter,
check_fn=check_qq_requirements,
is_connected=is_connected,
+ config_connected_fn=config_connected_extra("app_id", "client_secret"),
required_env=["QQ_APP_ID", "QQ_CLIENT_SECRET"],
install_hint="QQBot: aiohttp/httpx missing or QQ_APP_ID/QQ_CLIENT_SECRET not configured",
setup_fn=setup_qqbot,
diff --git a/plugins/platforms/signal/register.py b/plugins/platforms/signal/register.py
index 37f27b3a481..241993aee24 100644
--- a/plugins/platforms/signal/register.py
+++ b/plugins/platforms/signal/register.py
@@ -4,6 +4,7 @@ import logging
from gateway.config import PlatformConfig
from gateway.platforms._shared import env_is_connected
+from gateway.platforms._shared import config_connected_extra
# Absolute imports (see __init__.py): one canonical module per file.
from plugins.platforms.signal.adapter import (
@@ -37,6 +38,7 @@ def register(ctx) -> None:
name="signal", label="Signal", adapter_factory=SignalAdapter,
check_fn=check_signal_requirements, validate_config=_validate_config,
is_connected=_is_connected, required_env=["SIGNAL_HTTP_URL", "SIGNAL_ACCOUNT"],
+ config_connected_fn=config_connected_extra("http_url"),
install_hint="Signal: runtime requirements not met", setup_fn=interactive_setup,
allowed_users_env="SIGNAL_ALLOWED_USERS", allow_all_env="SIGNAL_ALLOW_ALL_USERS",
cron_deliver_env_var="SIGNAL_HOME_CHANNEL",
diff --git a/plugins/platforms/weixin/adapter.py b/plugins/platforms/weixin/adapter.py
index 6d4bfba47e4..aa1ce02019d 100644
--- a/plugins/platforms/weixin/adapter.py
+++ b/plugins/platforms/weixin/adapter.py
@@ -1254,6 +1254,12 @@ _INSTALL_HINT = "Weixin: aiohttp/cryptography not installed"
_env_configured = env_is_connected("WEIXIN_ACCOUNT_ID", "WEIXIN_TOKEN")
+def _config_connected(config: Any) -> bool:
+ """``config_connected_fn``: account_id AND token in the merged PlatformConfig; a token alone is
+ not enough, so this platform opts out of the generic ``token or api_key`` shortcut."""
+ return bool(config.extra.get("account_id") and (config.token or config.extra.get("token")))
+
+
def _is_connected(config: Any) -> bool:
"""Account ID AND token, from ``config`` or the scoped ``WEIXIN_*`` env (``gateway/config.py``'s
Weixin connected check reads the same pair), else ``.env``, which a plain CLI process never loads
@@ -1389,6 +1395,7 @@ def register(ctx) -> None:
ctx.register_platform(
name="weixin", label="Weixin / WeChat", adapter_factory=WeixinAdapter, check_fn=check_weixin_requirements,
is_connected=_is_connected, required_env=["WEIXIN_ACCOUNT_ID", "WEIXIN_TOKEN"], install_hint=_INSTALL_HINT,
+ config_connected_fn=_config_connected,
setup_fn=interactive_setup, allowed_users_env="WEIXIN_ALLOWED_USERS", allow_all_env="WEIXIN_ALLOW_ALL_USERS",
cron_deliver_env_var="WEIXIN_HOME_CHANNEL",
# Out-of-process send_message/cron; the adapter's own send() chunks (MAX_MESSAGE_LENGTH), so
diff --git a/plugins/platforms/whatsapp_cloud/adapter.py b/plugins/platforms/whatsapp_cloud/adapter.py
index b9e31cdc833..973f2d20128 100644
--- a/plugins/platforms/whatsapp_cloud/adapter.py
+++ b/plugins/platforms/whatsapp_cloud/adapter.py
@@ -40,6 +40,7 @@ except ImportError:
httpx = None # type: ignore[assignment]
from gateway.config import Platform, PlatformConfig
+from gateway.platforms._shared import config_connected_extra
from agent.i18n import t
from gateway.platforms.base import BasePlatformAdapter, ExecApprovalPrompt, SendResult, transcode_to_ogg_opus
from gateway.platforms.base_exec_approval import ea_header_text
@@ -1095,6 +1096,7 @@ def register(ctx) -> None:
ctx.register_platform(
name="whatsapp_cloud", label="WhatsApp Business (Cloud)", adapter_factory=WhatsAppCloudAdapter,
check_fn=check_whatsapp_cloud_requirements, is_connected=_is_connected,
+ config_connected_fn=config_connected_extra("phone_number_id", "access_token"),
required_env=["WHATSAPP_CLOUD_PHONE_NUMBER_ID", "WHATSAPP_CLOUD_ACCESS_TOKEN"],
install_hint="aiohttp/httpx missing — reinstall hermes-agent", setup_fn=_interactive_setup,
allowed_users_env="WHATSAPP_CLOUD_ALLOWED_USERS", allow_all_env="WHATSAPP_CLOUD_ALLOW_ALL_USERS",
diff --git a/plugins/platforms/yuanbao/register.py b/plugins/platforms/yuanbao/register.py
index 024bfa827e8..bcc12ece7a9 100644
--- a/plugins/platforms/yuanbao/register.py
+++ b/plugins/platforms/yuanbao/register.py
@@ -3,6 +3,7 @@
import logging
from gateway.platforms._shared import send_error
+from gateway.platforms._shared import config_connected_extra
# Absolute import (see __init__.py): one ``YuanbaoAdapter`` class object for the registry,
# tools/yuanbao_tools.py and the standalone sender.
@@ -69,6 +70,7 @@ def register(ctx) -> None:
ctx.register_platform(
name="yuanbao", label="Yuanbao", adapter_factory=YuanbaoAdapter,
check_fn=check_yuanbao_requirements, is_connected=_is_connected,
+ config_connected_fn=config_connected_extra("app_id", "app_secret"),
required_env=["YUANBAO_APP_ID", "YUANBAO_APP_SECRET"], install_hint=_INSTALL_HINT,
setup_fn=interactive_setup, allowed_users_env="YUANBAO_ALLOWED_USERS",
allow_all_env="YUANBAO_ALLOW_ALL_USERS", cron_deliver_env_var="YUANBAO_HOME_CHANNEL",