Repository navigation
Conversation
…replies Models often cite sources with markdown or bare URLs instead of the private <ref>index</ref> format, leaving the webchat citation sidebar empty. Match URLs in the reply against search result URLs as a fallback and order cards by first appearance in text instead of an unordered set. Refs: webchat search citations
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="astrbot/dashboard/services/chat_service.py" line_range="330" />
<code_context>
+ if item.get("url") and item["url"] not in url_to_index:
+ url_to_index[item["url"]] = idx
+ for match in re.findall(
+ r"https?://[^\s<>()\[\]{}\"'\u3000-\u303f\uff00-\uffef]+", accumulated_text
+ ):
+ idx = url_to_index.get(match.rstrip(".,;:!?。))】」"))
</code_context>
<issue_to_address>
**Cited URLs lose their cards**
When a cited URL contains parentheses, is surrounded by punctuation the regex does not exclude, or legitimately ends with punctuation stripped by `rstrip`, the URL regex truncates URLs at parentheses and can include surrounding punctuation, while `rstrip` can remove characters that belong to a valid URL. The resulting string does not match `url_to_index`, so the citation card is missing.
Parse the cited URL without truncating valid parentheses, and remove only surrounding delimiters that are not part of the URL before looking it up.
Also at `astrbot/dashboard/services/live_chat_service.py:338-340`, `astrbot/dashboard/services/chat_service.py:329`, `astrbot/dashboard/services/chat_service.py:331-332`.
</issue_to_address>
### Comment 2
<location path="astrbot/dashboard/services/chat_service.py" line_range="325" />
<code_context>
+ matched_indices.setdefault(idx)
+ # Fallback: models may cite sources with plain or markdown URLs instead
+ # of <ref> tags; recover cards by matching URLs from the search results.
+ url_to_index = {}
+ for idx, item in web_search_results.items():
+ if item.get("url") and item["url"] not in url_to_index:
</code_context>
<issue_to_address>
**Some search providers still lack cards**
When the configured search provider is Exa or AnySearch and the reply cites a result by URL, `web_search_results` remains empty because the extraction allowlist excludes `web_search_exa` and `web_search_anysearch`, so the early return prevents the URL fallback from producing cards for those providers.
Build the extraction allowlist from `WEB_SEARCH_CITATION_TOOL_NAMES` or add the omitted supported tool names to both functions.
Also at `astrbot/dashboard/services/live_chat_service.py:333`.
</issue_to_address>Sourcery assessment
Approval pending. 2 findings to address first.
Blocking findings: astrbot/dashboard/services/chat_service.py:330, astrbot/dashboard/services/chat_service.py:325
| if item.get("url") and item["url"] not in url_to_index: | ||
| url_to_index[item["url"]] = idx | ||
| for match in re.findall( | ||
| r"https?://[^\s<>()\[\]{}\"'\u3000-\u303f\uff00-\uffef]+", accumulated_text |
There was a problem hiding this comment.
🟡 Medium · Cited URLs lose their cards
When a cited URL contains parentheses, is surrounded by punctuation the regex does not exclude, or legitimately ends with punctuation stripped by rstrip, the URL regex truncates URLs at parentheses and can include surrounding punctuation, while rstrip can remove characters that belong to a valid URL. The resulting string does not match url_to_index, so the citation card is missing.
Parse the cited URL without truncating valid parentheses, and remove only surrounding delimiters that are not part of the URL before looking it up.
Also at astrbot/dashboard/services/live_chat_service.py:338-340, astrbot/dashboard/services/chat_service.py:329, astrbot/dashboard/services/chat_service.py:331-332.
Prompt for AI agents
In `astrbot/dashboard/services/chat_service.py` at line 330:
**Cited URLs lose their cards**
When a cited URL contains parentheses, is surrounded by punctuation the regex does not exclude, or legitimately ends with punctuation stripped by `rstrip`, the URL regex truncates URLs at parentheses and can include surrounding punctuation, while `rstrip` can remove characters that belong to a valid URL. The resulting string does not match `url_to_index`, so the citation card is missing.
Parse the cited URL without truncating valid parentheses, and remove only surrounding delimiters that are not part of the URL before looking it up.
Also at `astrbot/dashboard/services/live_chat_service.py:338-340`, `astrbot/dashboard/services/chat_service.py:329`, `astrbot/dashboard/services/chat_service.py:331-332`.| matched_indices.setdefault(idx) | ||
| # Fallback: models may cite sources with plain or markdown URLs instead | ||
| # of <ref> tags; recover cards by matching URLs from the search results. | ||
| url_to_index = {} |
There was a problem hiding this comment.
🟡 Medium · Some search providers still lack cards
When the configured search provider is Exa or AnySearch and the reply cites a result by URL, web_search_results remains empty because the extraction allowlist excludes web_search_exa and web_search_anysearch, so the early return prevents the URL fallback from producing cards for those providers.
Build the extraction allowlist from WEB_SEARCH_CITATION_TOOL_NAMES or add the omitted supported tool names to both functions.
Also at astrbot/dashboard/services/live_chat_service.py:333.
Prompt for AI agents
In `astrbot/dashboard/services/chat_service.py` at line 325:
**Some search providers still lack cards**
When the configured search provider is Exa or AnySearch and the reply cites a result by URL, `web_search_results` remains empty because the extraction allowlist excludes `web_search_exa` and `web_search_anysearch`, so the early return prevents the URL fallback from producing cards for those providers.
Build the extraction allowlist from `WEB_SEARCH_CITATION_TOOL_NAMES` or add the omitted supported tool names to both functions.
Also at `astrbot/dashboard/services/live_chat_service.py:333`.
Webchat renders citation cards by matching the private
<ref>index</ref>tags the chat model is instructed to emit after sentences that rely on web search results. In practice, models often cite sources with plain or markdown URLs instead, soextract_web_search_refsmatched nothing and the citation area stayed empty even though the answer listed real source links.Modifications / 改动点
extract_web_search_refs(chat_service.py,live_chat_service.py): as a fallback, match URLs appearing in the reply text against URLs from web search tool results and emit cards for matches not already covered by<ref>tags. The native<ref>path is unchanged; the fallback only adds cards.Collect native
<ref>citations first, then append URL fallback matches, preserving first-appearance order within each group for stable card ordering.This is NOT a breaking change. / 这不是一个破坏性变更。
Screenshots or Test Results / 运行截图或测试结果
Verified against the real
extract_web_search_refswith mocked tool results:<ref>citations -> behavior unchanged, in text order<ref>+ URL citations -> deduplicated by result index; URL fallback selects the first result for each URL, but different indices sharing a URL may still produce separate cards<ref>indices -> excludedBefore
After
Checklist / 检查清单
😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
/ 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。
👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
/ 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。
📚 I checked the affected WebUI instructions and screenshots in
docs/zhanddocs/enagainst the changed navigation, page structure, and labels, and updated them in this PR (or explained why no documentation update is needed). For renamed, moved, or merged entry points, I included an old entry → new entry mapping in the documentation and changelog./ 我已对照变化后的 WebUI 入口、页面结构和术语,核对并在本 PR 中更新
docs/zh和docs/en的相关操作说明与截图(或说明无需更新文档的原因)。入口改名、移动或合并时,已在文档和 changelog 中补充 旧入口 → 新入口 对照。- No WebUI navigation, page structure, or label changes in this PR; backend-only fix.
🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in
requirements.txtandpyproject.toml./ 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到
requirements.txt和pyproject.toml文件相应位置。😮 My changes do not introduce malicious code.
/ 我的更改没有引入恶意代码。
Summary by Sourcery
Restore web search citation cards from valid URLs in model replies while preserving existing native reference handling.
Bug Fixes:
<ref>tags.Enhancements: