The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(weixin): drop core wiring
Teknium8665b79cf3a4
diff --git a/gateway/run.py b/gateway/run.pyindex 59304603ef0..45980e5f645 100644--- a/gateway/run.py+++ b/gateway/run.py@@ -3319,8 +3319,6 @@ def _builtin_adapter_import(module: str, adapter_name: str, requirement: str):# platform -> (module, adapter class, requirements probe, warning on probe failure)._BUILTIN_ADAPTERS: dict[Platform, tuple[str, str, str, str]] = {- Platform.WEIXIN: ("weixin", "WeixinAdapter", "check_weixin_requirements",- "Weixin: aiohttp/cryptography not installed"),Platform.API_SERVER: ("api_server", "APIServerAdapter", "check_api_server_requirements","API Server: aiohttp not installed"),Platform.WEBHOOK: ("webhook", "WebhookAdapter", "check_webhook_requirements",diff --git a/hermes_cli/gateway.py b/hermes_cli/gateway.pyindex 827ac3a887d..b2d37479e25 100644--- a/hermes_cli/gateway.py+++ b/hermes_cli/gateway.py@@ -4659,9 +4659,6 @@ from hermes_cli.gateway_setup_wizard import (_clean_discord_ids,_prompt_allowlist_var,_setup_standard_platform,- _WEIXIN_DM_POLICIES,- _WEIXIN_GROUP_NOTE,- _setup_weixin,_setup_qqbot,_builtin_setup_fn,_configure_platform,diff --git a/hermes_cli/gateway_setup_wizard.py b/hermes_cli/gateway_setup_wizard.pyindex 9693010c22a..c99648007b1 100644--- a/hermes_cli/gateway_setup_wizard.py+++ b/hermes_cli/gateway_setup_wizard.py@@ -9,8 +9,6 @@ from __future__ import annotationsimport shutilimport subprocessimport sys-from hermes_cli.setup import print_success # def-time binding (table value)-from hermes_cli.setup import print_warning # def-time binding (table value)def _gw():@@ -49,7 +47,6 @@ _PLATFORMS = ["help": "off = flat channel messages, thread = replies nest under your message."},],},- {"key": "weixin", "label": "Weixin / WeChat", "emoji": "π¬", "token_var": "WEIXIN_ACCOUNT_ID"},{"key": "qqbot", "label": "QQ Bot", "emoji": "π§", "token_var": "QQ_APP_ID","setup_instructions": [@@ -140,12 +137,7 @@ def _platform_status(platform: dict) -> str:token_var = platform.get("token_var", "")if not token_var:return "not configured"- # Built-ins needing a second credential to count as fully configured.- second_var = {"weixin": "WEIXIN_TOKEN"}.get(platform.get("key"))- present = [bool(_gw().get_env_value(v)) for v in (token_var, second_var) if v]- if all(present):- return "configured"- return "partially configured" if any(present) else "not configured"+ return "configured" if _gw().get_env_value(token_var) else "not configured"def _set_platform_unauthorized_dm_behavior(platform_key: str, behavior: str) -> None:@@ -362,128 +354,6 @@ def _setup_standard_platform(platform: dict):_gw().print_success(f"{emoji} {label} configured!")-# Weixin DM policy by menu index (index 2 = allowlist is prompted separately).-_WEIXIN_DM_POLICIES = {- 0: ("pairing", "false", print_success, " DM pairing enabled."),- 1: ("open", "true", print_warning, " Open DM access enabled for Weixin."),- 3: ("disabled", "false", print_warning, " Direct messages disabled."),-}---_WEIXIN_GROUP_NOTE = (- " Note: QR login connects an iLink bot identity (e.g. [email protected]), not a",- " scriptable personal WeChat account. Ordinary WeChat groups typically cannot",- " invite an @im.bot identity, and iLink does not deliver ordinary-group events",- " to most bot accounts. The settings below only apply when iLink actually",- " delivers group events for your account type β otherwise DM remains the only",- " working channel regardless of this choice.",-)---def _setup_weixin():- """Interactive setup for Weixin / WeChat personal accounts."""- _print_setup_header("π¬ Weixin / WeChat")- print()- _gw()._print_info_lines(- " 1. Hermes will open Tencent iLink QR login in this terminal.",- " 2. Use WeChat to scan and confirm the QR code.",- " 3. Hermes will store the returned account_id/token in ~/.hermes/.env.",- " 4. This adapter supports native text, image, video, and document delivery.",- )-- if not _confirm_reconfigure("Weixin", "WEIXIN_ACCOUNT_ID", "WEIXIN_TOKEN"):- return-- try:- from gateway.platforms.weixin import check_weixin_requirements, qr_login- except Exception as exc:- _gw().print_error(f" Weixin adapter import failed: {exc}")- _gw().print_info(" Install gateway dependencies first, then retry.")- return-- if not check_weixin_requirements():- _gw().print_error(" Missing dependencies: Weixin needs aiohttp and cryptography.")- _gw().print_info(" Install them, then rerun `hermes gateway setup`.")- return-- print()- if not _gw().prompt_yes_no(" Start QR login now?", True):- _gw().print_info(" Cancelled.")- return-- try:- credentials = _gw().asyncio.run(qr_login(str(_gw().get_hermes_home())))- except KeyboardInterrupt:- print()- _gw().print_warning(" Weixin setup cancelled.")- return- except Exception as exc:- _gw().print_error(f" QR login failed: {exc}")- return-- if not credentials:- _gw().print_warning(" QR login did not complete.")- return-- account_id = credentials.get("account_id", "")- user_id = credentials.get("user_id", "")- _gw().save_env_value("WEIXIN_ACCOUNT_ID", account_id)- _gw().save_env_value("WEIXIN_TOKEN", credentials.get("token", ""))- if credentials.get("base_url", ""):- _gw().save_env_value("WEIXIN_BASE_URL", credentials.get("base_url", ""))- _gw().save_env_value(- "WEIXIN_CDN_BASE_URL", _gw().get_env_value("WEIXIN_CDN_BASE_URL") or "https://novac2c.cdn.weixin.qq.com/c2c"- )-- print()- access_choices = [- "Use DM pairing approval (recommended)", "Allow all direct messages", "Only allow listed user IDs",- "Disable direct messages",- ]- access_idx = _gw().prompt_choice(" How should direct messages be authorized?", access_choices, 0)- if access_idx == 2:- allowlist = _prompt_csv(" Allowed Weixin user IDs (comma-separated)", user_id or "")- _save_env_values(- WEIXIN_DM_POLICY="allowlist", WEIXIN_ALLOW_ALL_USERS="false", WEIXIN_ALLOWED_USERS=allowlist- )- _gw().print_success(" Weixin allowlist saved.")- else:- policy, allow_all, emit, message = _WEIXIN_DM_POLICIES.get(access_idx, _WEIXIN_DM_POLICIES[3])- _save_env_values(WEIXIN_DM_POLICY=policy, WEIXIN_ALLOW_ALL_USERS=allow_all, WEIXIN_ALLOWED_USERS="")- emit(message)- if access_idx == 0:- _gw().print_info(- " Unknown DM users can request access and you approve them with `hermes pairing approve`."- )-- print()- _gw()._print_info_lines(*_WEIXIN_GROUP_NOTE)- group_choices = [- "Disable group chats (recommended)", "Allow all group chats", "Only allow listed group chat IDs",- ]- group_idx = _gw().prompt_choice(" How should group chats be handled?", group_choices, 0)- if group_idx == 0:- _save_env_values(WEIXIN_GROUP_POLICY="disabled", WEIXIN_GROUP_ALLOWED_USERS="")- _gw().print_info(" Group chats disabled.")- elif group_idx == 1:- _save_env_values(WEIXIN_GROUP_POLICY="open", WEIXIN_GROUP_ALLOWED_USERS="")- _gw().print_warning(" All group chats enabled (only takes effect if iLink delivers group events).")- else:- allow_groups = _prompt_csv(" Allowed group chat IDs (comma-separated, not member user IDs)", "")- _save_env_values(WEIXIN_GROUP_POLICY="allowlist", WEIXIN_GROUP_ALLOWED_USERS=allow_groups)- _gw().print_success(" Group allowlist saved (only takes effect if iLink delivers group events).")-- if user_id:- print()- _offer_home_channel("WEIXIN_HOME_CHANNEL", user_id, "your Weixin user ID")-- print()- _gw().print_success("Weixin configured!")- _gw().print_info(f" Account ID: {account_id}")- if user_id:- _gw().print_info(f" User ID: {user_id}")--def _setup_qqbot():"""Interactive setup for QQ Bot β scan-to-configure or manual credentials."""_print_setup_header("π§ QQ Bot")@@ -569,7 +439,6 @@ def _builtin_setup_fn(key: str):return {# telegram/discord/slack/whatsapp/dingtalk/feishu/wecom setup_fns come from their plugins."webhooks": _gw().setup_platforms._setup_webhooks,- "weixin": _setup_weixin,"qqbot": _setup_qqbot,}.get(key)diff --git a/tools/send_message_senders.py b/tools/send_message_senders.pyindex 17306c18e38..71a6d5e9f8e 100644--- a/tools/send_message_senders.py+++ b/tools/send_message_senders.py@@ -472,17 +472,6 @@ def _gateway_platform_module(name, *, unavailable, unmet):return (module, None) if getattr(module, f"check_{name}_requirements")() else (None, {"error": unmet})-async def _send_weixin(pconfig, chat_id, message, media_files=None):- """Send via Weixin iLink using the native adapter helper."""- wx, err = _gateway_platform_module("weixin", unavailable="Weixin adapter not available.",- unmet="Weixin requirements not met. Need aiohttp + cryptography.")- if err:- return err- try:- return await wx.send_weixin_direct(extra=pconfig.extra, token=pconfig.token, chat_id=chat_id,- message=message, media_files=media_files)- except Exception as e:- return _error(f"Weixin send failed: {e}")def _qqbot_media_file_type(media_path: str, is_voice: bool) -> int:diff --git a/tools/send_message_tool.py b/tools/send_message_tool.pyindex 5f900911fc0..3ae1ff53a50 100644--- a/tools/send_message_tool.py+++ b/tools/send_message_tool.py@@ -18,7 +18,7 @@ from tools.send_message_senders import (_AUDIO_EXTS, _DEFAULT_CAPTION_LIMIT, _IMAGE_EXTS, _NO_DELIVERABLE, _VIDEO_EXTS, _VOICE_EXTS,_adapter_media_method, _error, _live_adapter, _media_caption_split, _plugin_standalone_sender,_registry_standalone_send, _resolve_slack_user_target, _sanitize_error_text,- _send_matrix_via_adapter, _send_qqbot, _send_telegram, _send_weixin, _send_yuanbao)+ _send_matrix_via_adapter, _send_qqbot, _send_telegram, _send_yuanbao)from tools.registry import tool_error# NOTE: ``send_message`` is intentionally NOT registered as an agent-callable model tool@@ -619,7 +619,8 @@ def _platform_max_length(platform):_PLUGIN_STANDALONE_MEDIA = {"discord": ("Discord", False, True, [], False), "feishu": ("Feishu", True, False, None, False),"slack": ("Slack", True, True, [], False), "whatsapp": ("WhatsApp", True, True, None, True),# Signal: attachments ride the JSON-RPC param on the final chunk.- "signal": ("Signal", True, False, [], False)}+ "signal": ("Signal", True, False, [], False),+ "weixin": ("Weixin", True, False, None, False)}async def _send_plugin_standalone(platform_name, pconfig, chat_id, message, chunks, media_files, *, thread_id,@@ -684,8 +685,9 @@ async def _send_to_platform(platform, pconfig, chat_id, message, thread_id=None,from gateway.config import Platformplatform_name = platform.value if hasattr(platform, "value") else str(platform)media_files = media_files or []- if platform == Platform.WEIXIN:- return await _send_weixin(pconfig, chat_id, message, media_files=media_files)+ if platform_name == "weixin": # plugin standalone sender only: no other plugin's import can block it+ return await _send_plugin_standalone(platform_name, pconfig, chat_id, message, [message], media_files,+ thread_id=thread_id, max_len=None, force_document=force_document)# Telegram chunks internally on the *formatted* text (escaping inflates length).if platform == Platform.TELEGRAM:return await _send_telegram(