fix(yuanbao): resolve quoted file/image media via transcript lookup - #26216
Merged
Merged
Conversation
…ispatchMiddleware
…ote desc lacks ybres When a user quotes a file message (type=3) and @bot, the quote's desc field only contains the filename without a ybres:// resource reference. The existing QuoteContextMiddleware only extracted media refs from desc using the ybres regex, which always returned empty for file quotes. Fix: add a transcript lookup fallback in QuoteContextMiddleware.handle() — when quote_media_refs is empty but reply_to_message_id is set, search the session transcript for the quoted message_id and extract ybres anchors from its content. Also fix message_type classification: when quote media resolves non-image files, override message_type to DOCUMENT so gateway/run.py's document injection logic properly prepends the file path and content for the agent.
…dleware, tighten conditions
23 tasks
Contributor
🔎 Lint report:
|
| Rule | Count |
|---|---|
invalid-argument-type |
1 |
First entries
gateway/platforms/yuanbao.py:2621: [invalid-argument-type] invalid-argument-type: Argument is incorrect: Expected `MessageType`, found `Literal[MessageType.DOCUMENT] | Any | None`
✅ Fixed issues (1):
| Rule | Count |
|---|---|
invalid-argument-type |
1 |
First entries
gateway/platforms/yuanbao.py:2509: [invalid-argument-type] invalid-argument-type: Argument is incorrect: Expected `MessageType`, found `Any | None`
Unchanged: 4310 pre-existing issues carried over.
Diagnostics are surfaced as warnings — this check never fails the build.
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.
Salvage of #22742 by @libo1106 onto current main.
Summary
Yuanbao bot can now read quoted file/image messages in group chats. Previously, quoting a file/image and @-mentioning the bot returned "file not found" because the quote's
cloud_custom_datadoesn't carry theresourceIdneeded for download (especially for file quotes,type=3).Mechanism
_extract_text+ new_parse_resource_idstore[file:name|ybres:rid]/[image|ybres:rid]anchors onTIMFileElem/TIMImageElem/TIMSoundElem/TIMVideoFileElemobservation so the resourceId is recoverable later.QuoteContextMiddleware._extract_quote_contextnow returns a 3-tuple includingquote_media_refsextracted from the quote desc via_YB_RES_REF_RE.DispatchMiddleware._dispatch_inbound_eventfalls back to a reversed transcript lookup bymessage_idwhen the quote desc lacks ybres anchors (file quotes only carry filename in desc), resolves quote refs exclusively (skipping unrelated history backfill), and overridesmessage_type→DOCUMENTwhen resolved media includesapplication/*ortext/*sogateway/run.py's file injection feeds content to the agent._RESOLVABLE_MEDIA_KINDS = frozenset({"image", "file"})replaces 4 duplicated inline set literals.Salvage
_collect_observed_mediaresolved in favor of the contributor's_RESOLVABLE_MEDIA_KINDSconstant (current main had migrated the literal to a set via PR chore: ruff auto-fix PLR6201 — tuple → set in membership tests #23937 ruff PLR6201 — same intent, contributor's version is cleaner).Validation
py_compile gateway/platforms/yuanbao.py— OKscripts/run_tests.sh tests/test_yuanbao_*.py— 215/215 passCloses #22742.