mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-25 00:51:20 +00:00
fix(gateway/weixin): split poll/send sessions, reuse live adapter for cron & send_message
- gateway/platforms/weixin.py: - Split aiohttp.ClientSession into _poll_session and _send_session - Add _LIVE_ADAPTERS registry so send_weixin_direct() reuses the connected gateway adapter instead of creating a competing session - Fixes silent message loss when gateway is running (iLink token contention) - cron/scheduler.py: - Support comma-separated deliver values (e.g. 'feishu,weixin') for multi-target delivery - Delay pconfig/enabled check until standalone fallback so live adapters work even when platform is not in gateway config - tools/send_message_tool.py: - Synthesize PlatformConfig from WEIXIN_* env vars when gateway config lacks a weixin entry - Fall back to WEIXIN_HOME_CHANNEL env var for home channel resolution - tests/gateway/test_weixin.py: - Update mocks to include _send_session
This commit is contained in:
parent
c60b6dc317
commit
5ca52bae5b
4 changed files with 235 additions and 134 deletions
|
|
@ -215,7 +215,27 @@ def _handle_send(args):
|
|||
|
||||
pconfig = config.platforms.get(platform)
|
||||
if not pconfig or not pconfig.enabled:
|
||||
return tool_error(f"Platform '{platform_name}' is not configured. Set up credentials in ~/.hermes/config.yaml or environment variables.")
|
||||
# Weixin can be configured purely via .env; synthesize a pconfig so
|
||||
# send_message and cron delivery work without a gateway.yaml entry.
|
||||
if platform_name == "weixin":
|
||||
import os
|
||||
wx_token = os.getenv("WEIXIN_TOKEN", "").strip()
|
||||
wx_account = os.getenv("WEIXIN_ACCOUNT_ID", "").strip()
|
||||
if wx_token and wx_account:
|
||||
from gateway.config import PlatformConfig
|
||||
pconfig = PlatformConfig(
|
||||
enabled=True,
|
||||
token=wx_token,
|
||||
extra={
|
||||
"account_id": wx_account,
|
||||
"base_url": os.getenv("WEIXIN_BASE_URL", "").strip(),
|
||||
"cdn_base_url": os.getenv("WEIXIN_CDN_BASE_URL", "").strip(),
|
||||
},
|
||||
)
|
||||
else:
|
||||
return tool_error(f"Platform '{platform_name}' is not configured. Set up credentials in ~/.hermes/config.yaml or environment variables.")
|
||||
else:
|
||||
return tool_error(f"Platform '{platform_name}' is not configured. Set up credentials in ~/.hermes/config.yaml or environment variables.")
|
||||
|
||||
from gateway.platforms.base import BasePlatformAdapter
|
||||
|
||||
|
|
@ -225,6 +245,12 @@ def _handle_send(args):
|
|||
used_home_channel = False
|
||||
if not chat_id:
|
||||
home = config.get_home_channel(platform)
|
||||
if not home and platform_name == "weixin":
|
||||
import os
|
||||
wx_home = os.getenv("WEIXIN_HOME_CHANNEL", "").strip()
|
||||
if wx_home:
|
||||
from gateway.config import HomeChannel
|
||||
home = HomeChannel(platform=platform, chat_id=wx_home, name="Weixin Home")
|
||||
if home:
|
||||
chat_id = home.chat_id
|
||||
used_home_channel = True
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue