fix(wecom): add MEDIA file support to send_message tool#37370
Closed
changyinhui wants to merge 5 commits into
Closed
fix(wecom): add MEDIA file support to send_message tool#37370changyinhui wants to merge 5 commits into
changyinhui wants to merge 5 commits into
Conversation
…wn-ext black hole (NousResearch#34517) (NousResearch#34844) MEDIA:<path> tags for .md/.json/.yaml/.xml/.html and other document extensions were silently dropped. extract_media() carried a narrow extension allowlist that omitted them, while extract_local_files() had a broad one. The dispatch sites then ran an unconditional re.sub(r'MEDIA:\\s*\\S+', '') that stripped the tag from the body even when extract_media had not matched it — so extract_local_files (broad list) ran on text where the path was already gone, and the file was delivered by neither path. - Add MEDIA_DELIVERY_EXTS in gateway/platforms/base.py as the single source of truth; extract_media and extract_local_files both derive their extension set from it (no more drift). - Replace the loose MEDIA cleanup at the non-streaming dispatch site (base.py) and the streaming consumer (stream_consumer.py) with the shared, extension-anchored MEDIA_TAG_CLEANUP_RE. A MEDIA: tag with an unknown extension is left in the body so the bare-path detector can still pick it up instead of being black-holed. - Chain cleaned text through extract_media -> extract_images -> extract_local_files in run.py's post-stream media delivery (it was dropping the cleaned text and rescanning raw text with MEDIA: tags). - Regression tests covering both halves: previously-dropped extensions now extract, and unknown-ext paths survive the cleanup. Consolidates the MEDIA extension-allowlist PR cluster. Co-authored-by: Bartok9 <259807879+Bartok9@users.noreply.github.com> Co-authored-by: banditburai <123342691+banditburai@users.noreply.github.com> Co-authored-by: Kyzcreig <9063726+Kyzcreig@users.noreply.github.com>
Three changes to fix WeCom media delivery in send_message: 1. _send_via_adapter(): Add media_files handling with send_document / send_image_file dispatch. Save/restore _last_chat_req_ids so the adapter uses proactive send mode for media instead of consuming the gateway's reply slot. 2. _send_to_platform(): Add Platform.WECOM + media_files branch that routes through _send_via_adapter() — reuses the gateway's live WebSocket connection instead of creating a duplicate connection that would fail with WeCom errcode 846609. 3. _send_wecom(): Add media_files parameter for standalone path (non-live-adapter fallback). Closes NousResearch#37364
Resolved merge conflict in gateway/platforms/base.py — upstream changes (Windows path support, media path masking, _strip_media_directives refactor) are orthogonal to the WeCom send_message MEDIA fix. Our key changes in tools/send_message_tool.py (WeCom media branch at L820, _send_via_adapter reply context handling) are unaffected.
Add TestSendWecomMedia with 4 unit tests: - WeCom + media_files routes to _send_via_adapter - WeCom text-only still uses legacy _send_wecom - Single chunk passes media_files through - Error from _send_via_adapter propagates Closes NousResearch#37364
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.
Summary
Fixes #37364 — WeCom
send_messagesilently drops MEDIA file attachments when the gateway is running.Root Cause
No media branch:
_send_to_platform()had no dedicated WeCom media branch. Files fell through to the "Non-media platforms" catch-all (line 825) and were silently dropped.WebSocket conflict: The standalone
_send_wecom()creates a newWeComAdapterand attempts a fresh WebSocket connection. WeCom enforces single-connection-per-bot (errcode 846609: "aibot websocket not subscribed"), so this fails when the gateway already holds the connection.Changes
_send_via_adapter()— Addmedia_fileshandling withsend_document/send_image_filedispatch. Temporarily clear_last_chat_req_idsso the adapter uses proactive send mode; restore afterwards so the gateway's own response delivery is unaffected._send_to_platform()— AddPlatform.WECOM and media_filesbranch (before the "Non-media platforms" fallback) that routes through_send_via_adapter(), reusing the gateway's live WebSocket connection._send_wecom()— Addmedia_filesparameter and handling for the standalone fallback path.Testing
Verified on live WeCom deployment:
send_message(target="wecom", message="...MEDIA:/tmp/test.md")successfully delivers .md file as native attachment.Closes #37364