The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
chore(platforms): clear the code-health ratchet on the moved adapters
Teknium38b538327003
diff --git a/plugins/platforms/bluebubbles/adapter.py b/plugins/platforms/bluebubbles/adapter.pyindex e1d186d245e..83d6bc689a7 100644--- a/plugins/platforms/bluebubbles/adapter.py+++ b/plugins/platforms/bluebubbles/adapter.py@@ -644,6 +644,7 @@ async def _standalone_send(pconfig, chat_id: str, message: str, *, thread_id: Opreturn send_error(f"BlueBubbles send failed: {result.error}")return {"success": True, "platform": "bluebubbles", "chat_id": chat_id, "message_id": result.message_id}except Exception as e:+ logger.debug("BlueBubbles standalone send failed", exc_info=True)return send_error(f"BlueBubbles send failed: {e}")diff --git a/plugins/platforms/qqbot/send.py b/plugins/platforms/qqbot/send.pyindex 996107e153c..bc8f1fc2c9d 100644--- a/plugins/platforms/qqbot/send.py+++ b/plugins/platforms/qqbot/send.py@@ -4,6 +4,7 @@ Media uploads through C2C then group; guild channels have no native media path.from __future__ import annotations+import asyncioimport loggingimport osimport time@@ -209,7 +210,7 @@ async def send_qqbot(pconfig, chat_id, message, media_files=None, caption=None,# Caption applies to the first bubble only (single-file# caption split already enforced by the caller).media_caption = caption if index == 0 else None- if not os.path.exists(media_path):+ if not await asyncio.to_thread(os.path.exists, media_path):from urllib.parse import urlparse as _urlparseif _urlparse(str(media_path)).scheme not in {"http", "https"}:warnings.append(f"QQBot media file not found, skipping: {media_path}")@@ -244,4 +245,5 @@ async def send_qqbot(pconfig, chat_id, message, media_files=None, caption=None,# --- Text-only path: first 2xx wins (pre-media behavior) ---return await _qqbot_send_text_message(client, headers, chat_id, message or "")except Exception as e:+ logger.debug("QQBot standalone send failed", exc_info=True)return _error(f"QQBot send failed: {e}")diff --git a/plugins/platforms/signal/setup.py b/plugins/platforms/signal/setup.pyindex 03146cc5ea4..544fcb2017d 100644--- a/plugins/platforms/signal/setup.py+++ b/plugins/platforms/signal/setup.py@@ -64,7 +64,7 @@ def interactive_setup() -> None:_gw().print_warning(f" signal-cli responded with status {resp.status_code}.")if not _gw().prompt_yes_no(" Continue anyway?", False):return- except Exception as e:+ except Exception as e: # health: allow BLE001 -- connectivity probe in a wizard: any failure is "unreachable", the user decides_gw().print_warning(f" Could not reach signal-cli at {url}: {e}")if not _gw().prompt_yes_no(" Save this URL anyway? (you can start signal-cli later)", True):returndiff --git a/plugins/platforms/weixin/adapter.py b/plugins/platforms/weixin/adapter.pyindex 01aaa89b624..6d4bfba47e4 100644--- a/plugins/platforms/weixin/adapter.py+++ b/plugins/platforms/weixin/adapter.py@@ -1276,6 +1276,7 @@ async def _standalone_send(pconfig: Any, chat_id: str, message: str, *, thread_ireturn await send_weixin_direct(extra=getattr(pconfig, "extra", None) or {}, token=getattr(pconfig, "token", None),chat_id=chat_id, message=message, media_files=media_files)except Exception as e:+ logger.debug("Weixin standalone send failed", exc_info=True)return send_error(f"Weixin send failed: {e}")@@ -1326,7 +1327,7 @@ def interactive_setup() -> None:print()gw.print_warning(" Weixin setup cancelled.")return- except Exception as exc:+ except Exception as exc: # health: allow BLE001 -- interactive wizard: any QR-login failure is shown and setup stopsgw.print_error(f" QR login failed: {exc}")returnif not credentials:diff --git a/plugins/platforms/yuanbao/__init__.py b/plugins/platforms/yuanbao/__init__.pyindex d3197d8288b..19f7559ca2c 100644--- a/plugins/platforms/yuanbao/__init__.py+++ b/plugins/platforms/yuanbao/__init__.py@@ -2,6 +2,6 @@# ``hermes_plugins.yuanbao_platform``; importing the adapter by its canonical module name keeps# ONE ``YuanbaoAdapter`` class object, so ``YuanbaoAdapter.get_active()`` from tools/yuanbao_tools.py# and the standalone sender see the instance the gateway registry created.-from plugins.platforms.yuanbao.adapter import register+from plugins.platforms.yuanbao.register import register__all__ = ["register"]diff --git a/plugins/platforms/yuanbao/adapter.py b/plugins/platforms/yuanbao/adapter.pyindex 2dcea695453..41eca7254ce 100644--- a/plugins/platforms/yuanbao/adapter.py+++ b/plugins/platforms/yuanbao/adapter.py@@ -49,7 +49,7 @@ from gateway.platforms.base import ()from gateway.platforms.event import MessageEvent, MessageTypefrom gateway.platforms import helpers as _mdchunk-from gateway.platforms._shared import get_scoped_secret as _yb_secret, profile_scoped as _profile_scoped, send_error+from gateway.platforms._shared import get_scoped_secret as _yb_secret, profile_scoped as _profile_scopedfrom gateway.platforms.helpers import MessageDeduplicator, cancel_taskfrom gateway.platforms.access_policy_mixin import OwnAccessPolicyMixinfrom plugins.platforms.yuanbao.yuanbao_media import (@@ -2818,70 +2818,3 @@ class YuanbaoAdapter(BasePlatformAdapter):async def _get_cached_token(self) -> dict:"""Current valid sign token (module-level cache)."""return await SignManager.get_token(self._app_key, self._app_secret, self._api_domain, route_env=self._route_env)---# ----------------------------------------------------------------------------# Plugin registration-# -----------------------------------------------------------------------------_INSTALL_HINT = "Yuanbao: websockets not installed. Run: pip install websockets"--_SETUP_PLATFORM = {- "key": "yuanbao", "label": "Yuanbao", "emoji": "π", "token_var": "YUANBAO_APP_ID",- "setup_instructions": [- "1. Download the Yuanbao app from https://yuanbao.tencent.com/",- "2. In the app, go to PAI β My Bot and create a new bot",- "3. After the bot is created, copy the App ID and App Secret",- "4. Enter them below and Hermes will connect automatically over WebSocket",- ],- "vars": [- {"name": "YUANBAO_APP_ID", "prompt": "App ID", "password": False,- "help": "The App ID from your Yuanbao IM Bot credentials."},- {"name": "YUANBAO_APP_SECRET", "prompt": "App Secret", "password": True,- "help": "The App Secret (used for HMAC signing) from your Yuanbao IM Bot."},- ],-}---def check_yuanbao_requirements() -> bool:- """Runtime deps present (the websockets client)."""- return WEBSOCKETS_AVAILABLE---def interactive_setup() -> None:- """``hermes gateway setup`` flow: the standard App ID / App Secret prompts."""- from hermes_cli import gateway as gateway_mod- gateway_mod._setup_standard_platform(dict(_SETUP_PLATFORM))---def _is_connected(config) -> bool:- """Configured = App ID (or legacy App Key) + App Secret, from config extras or env."""- extra = getattr(config, "extra", {}) or {}- import hermes_cli.gateway as gateway_mod- app_id = (extra.get("app_id") or gateway_mod.get_env_value("YUANBAO_APP_ID")- or gateway_mod.get_env_value("YUANBAO_APP_KEY") or "")- secret = extra.get("app_secret") or gateway_mod.get_env_value("YUANBAO_APP_SECRET") or ""- return bool(str(app_id).strip() and str(secret).strip())---async def _standalone_send(pconfig, chat_id, message, *, thread_id=None, media_files=None, **_kwargs):- """standalone_sender_fn: send via the running adapter's persistent WebSocket (no throwaway- client possible β Yuanbao needs the live signed connection)."""- adapter = YuanbaoAdapter.get_active()- if adapter is None:- return send_error("Yuanbao adapter is not running. Start the gateway with yuanbao platform enabled first.")- try:- return await adapter._outbound.sender.send_direct(chat_id, message, media_files)- except Exception as e:- return send_error(f"Yuanbao send failed: {e}")---def register(ctx) -> None:- """Plugin entry point β called by the Hermes plugin system."""- ctx.register_platform(- name="yuanbao", label="Yuanbao", adapter_factory=YuanbaoAdapter,- check_fn=check_yuanbao_requirements, is_connected=_is_connected,- 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",- standalone_sender_fn=_standalone_send, emoji="π", allow_update_command=False)diff --git a/plugins/platforms/yuanbao/register.py b/plugins/platforms/yuanbao/register.pynew file mode 100644index 00000000000..024bfa827e8--- /dev/null+++ b/plugins/platforms/yuanbao/register.py@@ -0,0 +1,75 @@+"""Yuanbao plugin registration: setup row, configured check, standalone sender, ``register``."""++import logging++from gateway.platforms._shared import send_error++# Absolute import (see __init__.py): one ``YuanbaoAdapter`` class object for the registry,+# tools/yuanbao_tools.py and the standalone sender.+from plugins.platforms.yuanbao.adapter import WEBSOCKETS_AVAILABLE, YuanbaoAdapter++logger = logging.getLogger(__name__)+++_INSTALL_HINT = "Yuanbao: websockets not installed. Run: pip install websockets"++_SETUP_PLATFORM = {+ "key": "yuanbao", "label": "Yuanbao", "emoji": "π", "token_var": "YUANBAO_APP_ID",+ "setup_instructions": [+ "1. Download the Yuanbao app from https://yuanbao.tencent.com/",+ "2. In the app, go to PAI β My Bot and create a new bot",+ "3. After the bot is created, copy the App ID and App Secret",+ "4. Enter them below and Hermes will connect automatically over WebSocket",+ ],+ "vars": [+ {"name": "YUANBAO_APP_ID", "prompt": "App ID", "password": False,+ "help": "The App ID from your Yuanbao IM Bot credentials."},+ {"name": "YUANBAO_APP_SECRET", "prompt": "App Secret", "password": True,+ "help": "The App Secret (used for HMAC signing) from your Yuanbao IM Bot."},+ ],+}+++def check_yuanbao_requirements() -> bool:+ """Runtime deps present (the websockets client)."""+ return WEBSOCKETS_AVAILABLE+++def interactive_setup() -> None:+ """``hermes gateway setup`` flow: the standard App ID / App Secret prompts."""+ from hermes_cli import gateway as gateway_mod+ gateway_mod._setup_standard_platform(dict(_SETUP_PLATFORM))+++def _is_connected(config) -> bool:+ """Configured = App ID (or legacy App Key) + App Secret, from config extras or env."""+ extra = getattr(config, "extra", {}) or {}+ import hermes_cli.gateway as gateway_mod+ app_id = (extra.get("app_id") or gateway_mod.get_env_value("YUANBAO_APP_ID")+ or gateway_mod.get_env_value("YUANBAO_APP_KEY") or "")+ secret = extra.get("app_secret") or gateway_mod.get_env_value("YUANBAO_APP_SECRET") or ""+ return bool(str(app_id).strip() and str(secret).strip())+++async def _standalone_send(pconfig, chat_id, message, *, thread_id=None, media_files=None, **_kwargs):+ """standalone_sender_fn: send via the running adapter's persistent WebSocket (no throwaway+ client possible β Yuanbao needs the live signed connection)."""+ adapter = YuanbaoAdapter.get_active()+ if adapter is None:+ return send_error("Yuanbao adapter is not running. Start the gateway with yuanbao platform enabled first.")+ try:+ return await adapter._outbound.sender.send_direct(chat_id, message, media_files)+ except Exception as e:+ logger.debug("Yuanbao standalone send failed", exc_info=True)+ return send_error(f"Yuanbao send failed: {e}")+++def register(ctx) -> None:+ """Plugin entry point β called by the Hermes plugin system."""+ ctx.register_platform(+ name="yuanbao", label="Yuanbao", adapter_factory=YuanbaoAdapter,+ check_fn=check_yuanbao_requirements, is_connected=_is_connected,+ 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",+ standalone_sender_fn=_standalone_send, emoji="π", allow_update_command=False)diff --git a/tests/gateway/test_yuanbao_plugin_registration.py b/tests/gateway/test_yuanbao_plugin_registration.pyindex e44461527fc..666ddf442d7 100644--- a/tests/gateway/test_yuanbao_plugin_registration.py+++ b/tests/gateway/test_yuanbao_plugin_registration.py@@ -13,7 +13,8 @@ class _Ctx:def test_register_shape_and_core_wiring_removed():from plugins.platforms.yuanbao import register- from plugins.platforms.yuanbao.adapter import YuanbaoAdapter, _standalone_send+ from plugins.platforms.yuanbao.adapter import YuanbaoAdapter+ from plugins.platforms.yuanbao.register import _standalone_sendctx = _Ctx()register(ctx)