Skip to content

refactor(gateway): migrate Weixin adapter to bundled plugin - #41101

Closed
kshitijk4poor wants to merge 2 commits into
NousResearch:mainfrom
kshitijk4poor:feat/weixin-platform-plugin
Closed

refactor(gateway): migrate Weixin adapter to bundled plugin#41101
kshitijk4poor wants to merge 2 commits into
NousResearch:mainfrom
kshitijk4poor:feat/weixin-platform-plugin

Conversation

@kshitijk4poor

Copy link
Copy Markdown
Collaborator

What this does

Moves the Weixin (微信 / WeChat) adapter from gateway/platforms/weixin.py
into a self-contained bundled plugin under plugins/platforms/weixin/,
following the Discord / Mattermost / Home Assistant / Yuanbao / Signal / QQBot
migration shape.

How

register() supplies the hooks that were per-platform wiring in core:
adapter_factory, check_fn, is_connected, setup_fn (iLink QR login + DM/group
policy), standalone_sender_fn, cron_deliver_env_var. The one-shot
send_weixin_direct helper stays in the adapter; _standalone_send wraps it
for out-of-process cron / send_message delivery.

Connection-check reorder (the one non-mechanical bit)

Weixin requires BOTH account_id and a token, and it sets config.token
during env-enablement — so the generic token-only branch in
_is_platform_connected would wrongly pass it without an account_id. Instead
of a per-platform special-case, the registry is_connected hook is now
consulted BEFORE the generic token branch (a platform's own check is the
authoritative signal). Verified no cross-platform regression — full gateway
connection-check suite green, all platforms detect correctly.

Out of scope (stays generic, same as every other platform)

Platform.WEIXIN enum literal, the _apply_env_overrides WEIXIN_* env block,
the WEIXIN_TOKEN entry in _token_env_names, the _is_user_authorized
allowlist maps. No load_gateway_config YAML block, so no apply_yaml_config_fn.

Tests

Rename R089 (adapter). 254 focused tests pass. Updated the connection-checker
guard test to exclude bundled-plugin platforms; repointed the bare-submodule
test import. No new failures vs main (pre-existing matrix/telegram xdist flakes
excluded).

Move the Weixin (微信 / WeChat) adapter from gateway/platforms/weixin.py into
a self-contained bundled plugin under plugins/platforms/weixin/, following the
Discord/Mattermost/Home Assistant/Yuanbao/Signal/QQBot migration shape.

register() supplies the hooks that previously lived as per-platform wiring
in core:
  - adapter_factory      -> the elif in gateway/run.py::_create_adapter()
  - check_fn             -> check_weixin_requirements guard there
  - is_connected         -> the Platform.WEIXIN branch in _is_platform_connected
                            + the _PLATFORM_CONNECTED_CHECKERS lambda
  - setup_fn             -> _setup_weixin (iLink QR login + DM/group policy)
                            + its _PLATFORMS entry + _builtin_setup_fn mapping
  - standalone_sender_fn -> _send_weixin in tools/send_message_tool.py
  - cron_deliver_env_var -> WEIXIN_HOME_CHANNEL

The one-shot send_weixin_direct helper stays in the adapter; _standalone_send
wraps it for cron/send_message delivery. Weixin is HTTP (iLink API), so this
works out-of-process.

Connection-check reorder: weixin requires BOTH account_id and token, and it
sets config.token during env-enablement, so the generic token-only branch in
_is_platform_connected would wrongly pass it without account_id. Rather than
keep a per-platform special-case, the registry is_connected hook is now
consulted BEFORE the generic token branch — a platform's own check is the
authoritative signal. Verified no cross-platform regression (full gateway
connection-check suite green).

Deliberately left generic in core: the Platform.WEIXIN enum literal, the
_apply_env_overrides WEIXIN_* env block, the WEIXIN_TOKEN entry in the
_token_env_names map, and the _is_user_authorized allowlist maps. Weixin has
no load_gateway_config YAML block, so no apply_yaml_config_fn.

Updated the connection-checker guard test to exclude bundled-plugin platforms;
repointed the bare-submodule test import to the plugin adapter module.
@alt-glitch alt-glitch added type/refactor Code restructuring, no behavior change P3 Low — cosmetic, nice to have comp/gateway Gateway runner, session dispatch, delivery comp/plugins Plugin system and bundled plugins labels Jun 7, 2026
weixin is now a bundled plugin; its PlatformEntry already permits /update via
allow_update_command (defaults True), honored by the registry fallback in
_handle_update_command. The hardcoded Platform.WEIXIN entry in
_UPDATE_ALLOWED_PLATFORMS is therefore redundant. Same cleanup as NousResearch#32525
did for Discord/Mattermost.
@kshitijk4poor

Copy link
Copy Markdown
Collaborator Author

Follow-up to #32525: now that the migrated-platform /update allowlist cleanup landed, this PR drops Platform.WEIXIN from _UPDATE_ALLOWED_PLATFORMS. As a bundled plugin, weixin's PlatformEntry.allow_update_command (default True) is already honored by the registry fallback in _handle_update_command, so the hardcoded frozenset entry is redundant. No behavior change — /update from a weixin chat still works; test_update_command.py passes (35/35).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery comp/plugins Plugin system and bundled plugins P3 Low — cosmetic, nice to have type/refactor Code restructuring, no behavior change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants