fix: 从 QQ 引用消息的 JSON 卡片中提取文本 | extract text from quoted QQ JSON cards - #9680
Open
SweetenedSuzuka wants to merge 3 commits into
Open
fix: 从 QQ 引用消息的 JSON 卡片中提取文本 | extract text from quoted QQ JSON cards#9680SweetenedSuzuka wants to merge 3 commits into
SweetenedSuzuka wants to merge 3 commits into
Conversation
The quoted-message parser dropped generic QQ JSON cards (e.g. mini-program shares) in both extraction paths: _extract_text_from_component_chain had no Json component branch, and _parse_onebot_segments only handled com.tencent.multimsg forward cards. Add _extract_text_from_json_card to read the top-level prompt and meta.*.title/desc/url fields (HTML-unescaped and length-capped), delegating multimsg cards to the existing handler so their behavior is unchanged.
Contributor
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="astrbot/core/utils/quoted_message/chain_parser.py" line_range="324" />
<code_context>
+ if cleaned:
+ _append(f"{label}: {cleaned}")
+
+ _append(_clean_json_card_text(parsed.get("prompt")))
+
+ meta = parsed.get("meta")
</code_context>
<issue_to_address>
**suggestion:** Avoid passing a possible None into `_append` to better align with its signature and intent.
`_append` is annotated to take a `str`, but `_clean_json_card_text` can return `None`. While the current `if value and ...` logic is safe, it breaks the function’s type contract and may confuse readers or type checkers. Consider only calling `_append` when the cleaned prompt is truthy:
```python
prompt = _clean_json_card_text(parsed.get("prompt"))
if prompt:
_append(prompt)
```
```suggestion
prompt = _clean_json_card_text(parsed.get("prompt"))
if prompt:
_append(prompt)
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Only call _append with a truthy prompt to match the str-typed signature (_clean_json_card_text may return None). No behavior change.
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
修复群内引用 QQ JSON 卡片消息(如 QQ 小程序分享卡片)时,机器人无法看到引用内容的问题。
Fixes the bot being unable to see the content of a quoted QQ JSON card message (e.g. QQ mini-program shares).
问题 / Problem
引用消息解析器在两条抽取路径上都会静默丢弃非
com.tencent.multimsg的 JSON 卡片:组件链路径(_extract_text_from_component_chain)没有Json组件分支;onebot 段路径(_parse_onebot_segments)只处理com.tencent.multimsg转发卡片。结果引用 JSON 卡片时 LLM 收到"[Empty Text]"。The quoted-message parser silently dropped generic QQ JSON cards in both extraction paths:
_extract_text_from_component_chainhad noJsoncomponent branch, and_parse_onebot_segmentsonly handledcom.tencent.multimsgforward cards. As a result the LLM received"[Empty Text]"when quoting a JSON card.改动 / Changes
chain_parser.py新增_extract_text_from_json_card:从卡片顶层prompt与meta.*.title/desc/url提取可读文本,逐字段反转义 HTML 实体并设总长度上限。com.tencent.multimsg卡片继续委派给原_extract_text_from_multimsg_json,多转发卡片行为不变。json段)均接入该函数,并补充测试。_extract_text_from_json_cardinchain_parser.pyto extract readable text from a card's top-levelpromptandmeta.*.title/desc/urlfields, HTML-unescaping each field and capping total length.com.tencent.multimsgcards still delegate to the existing_extract_text_from_multimsg_json, so forward-card behavior is unchanged.jsonsegment) and added tests.测试 / Tests
相关测试套件全部通过(
test_quoted_message_parser.py、test_astr_main_agent.py、test_group_chat_context_wiring.py、test_group_message_history.py)。Related test suites pass (
test_quoted_message_parser.py,test_astr_main_agent.py,test_group_chat_context_wiring.py,test_group_message_history.py).范围说明 / Scope
本 PR 只修复引用(reply/quote)消息路径;群聊上下文记忆中引用 JSON 卡片显示为
[Quote(...: [Json])]的既有展示局限不在本 PR 范围。This PR only fixes the quoted(reply/quote) message path; the pre-existing group-context memory display of a quoted JSON card as
[Quote(...: [Json])]is out of scope.Fixes #9565
Summary by Sourcery
Handle text extraction from generic QQ JSON card messages in quoted replies so bots can access their contents instead of returning empty text.
New Features:
Bug Fixes:
Enhancements:
Tests: