feat(gateway): yuanbao platform#13276
Closed
loongfay wants to merge 2 commits into
Closed
Conversation
11 tasks
Contributor
|
Reviewed and tested locally. Test results: 213 passed, 2 skipped, 0 failed across all 4 test files:
The implementation looks solid:
CI test failure appears to be due to missing dependency registrations in a partial checkout context, not a code issue — all 213 tests pass when the full file set is present. LGTM from a test coverage and architecture perspective. 🚀 |
96ea447 to
971a578
Compare
aee753a to
441cf41
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Adds full Yuanbao (元宝) platform support to Hermes Agent, enabling the bot to connect to Tencent's Yuanbao enterprise messaging platform via WebSocket gateway. This includes real-time message receive/send (C2C and group), media handling (images, files via COS upload), sticker support, access control policies, and a middleware-based inbound message pipeline.
Yuanbao is Tencent's enterprise messaging platform with over 100 million monthly active users, that uses WebSocket for real-time communication with HMAC-based authentication. This PR implements the full adapter lifecycle: authentication (AUTH_BIND), heartbeat, reconnection, message decoding (protobuf-like binary protocol), and outbound message encoding.
Type of Change
Changes Made
Core Platform Adapter
gateway/platforms/yuanbao.py— Main adapter: WebSocket lifecycle, AUTH_BIND, heartbeat, reconnection with close-code classification, inbound pipeline (17 OOP middlewares), outbound queue with fence-aware text buffering, @mention conversion, markdown splitting, DM active messaginggateway/platforms/yuanbao_proto.py— Custom binary protocol codec (protobuf-like): conn/biz layer encode/decode, InboundMessagePush parsing, SendC2C/GroupMessage encoding, auth-bind/ping/push-ackgateway/platforms/yuanbao_media.py— COS upload via temporary credentials (genUploadInfo), TIMImageElem/TIMFileElem message body construction, file downloadgateway/platforms/yuanbao_sticker.py— TIMFaceElem support with built-in sticker catalogue, fuzzy search by keyword/descriptionTools & Skills
tools/yuanbao_tools.py— Toolset (hermes-yuanbao):yb_query_group_info,yb_query_group_members,yb_search_sticker,yb_send_sticker,yb_send_dmskills/yuanbao/SKILL.md— Skill definition for @mention workflow, DM sending, group queriesGateway & CLI Integration
gateway/config.py— Added Yuanbao platform enum, config fields (app_id, app_secret, bot_id, ws_url, api_domain, access policies)gateway/run.py— Integrated Yuanbao adapter startup/shutdowngateway/platforms/__init__.py— Registered Yuanbao platformhermes_cli/gateway.py— Added_setup_yuanbao()interactive wizardhermes_cli/platforms.py— Added Yuanbao to platform listhermes_cli/setup.py— Yuanbao setup integrationhermes_cli/tools_config.py— Registeredhermes-yuanbaotoolsethermes_cli/web_server.py— Yuanbao status endpointtoolsets.py— Yuanbao toolset registrationAgent & Messaging
agent/prompt_builder.py— Yuanbao-specific prompt context (slow-task hints, platform awareness)tools/send_message_tool.py— Extended send_message to support Yuanbao targetsrun_agent.py— Yuanbao adapter integration in agent runnerDocumentation
website/docs/user-guide/messaging/yuanbao.md— Full setup guide (prerequisites, wizard, env vars, features)website/docs/user-guide/messaging/index.md— Added Yuanbao to messaging indexTests (4 new test files, 2400+ lines)
tests/test_yuanbao_proto.py— Protocol codec unit tests (varint, conn/biz layer, MsgContent, InboundPush, outbound encoding, constants)tests/test_yuanbao_pipeline.py— Inbound pipeline middleware tests (17 middlewares, OOP registration, end-to-end flows)tests/test_yuanbao_integration.py— Integration tests (adapter lifecycle, media handling, access control)tests/test_yuanbao_markdown.py— Markdown splitting/enhancement testsHow to Test
pip install websockets httpx aiofileshermes gateway setup→ select Yuanbao → provide APP_ID and APP_SECREThermes gateway run -vvpytest tests/test_yuanbao_proto.py tests/test_yuanbao_pipeline.py tests/test_yuanbao_integration.py tests/test_yuanbao_markdown.py -vChecklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings)cli-config.yaml.exampleif I added/changed config keysScreenshots / Logs
Architecture Overview
graph TD A[Yuanbao WS Gateway] -->|WebSocket| B[YuanbaoAdapter] B --> C[Inbound Pipeline - 17 Middlewares] C --> D[decode → extract-fields → dedup → skip-self] D --> E[chat-routing → access-guard → auto-sethome] E --> F[extract-content → placeholder-filter → owner-command] F --> G[build-source → group-at-guard → group-attribution] G --> H[classify-msg-type → quote-context → media-resolve → dispatch] H --> I[Hermes Agent] I -->|Response| J[OutboundQueue] J -->|Fence-aware splitting| K[WS Send] K --> A