Skip to content

fix: support rst and adoc knowledge uploads#8255

Merged
RC-CHN merged 1 commit into
AstrBotDevs:masterfrom
he-yufeng:fix/kb-rst-adoc-upload
May 20, 2026
Merged

fix: support rst and adoc knowledge uploads#8255
RC-CHN merged 1 commit into
AstrBotDevs:masterfrom
he-yufeng:fix/kb-rst-adoc-upload

Conversation

@he-yufeng

@he-yufeng he-yufeng commented May 20, 2026

Copy link
Copy Markdown
Contributor

Summary

  • allow the knowledge-base parser selector to route .rst and .adoc files through the existing MarkItDown parser
  • include those formats in the dashboard file picker and supported-format copy
  • add parser selection coverage for both extensions

Fixes #8213.

To verify

  • python -m pytest tests/test_epub_parser.py -q
  • python -m ruff check astrbot/core/knowledge_base/parsers/util.py tests/test_epub_parser.py
  • python -m py_compile astrbot/core/knowledge_base/parsers/util.py tests/test_epub_parser.py
  • pnpm install --frozen-lockfile in dashboard/
  • pnpm typecheck in dashboard/

Note: direct pnpm exec eslint src/views/knowledge-base/components/DocumentsTab.vue could not find an ESLint config in this checkout, so I did not run the repo's lint --fix script.

Summary by Sourcery

Extend knowledge base text parsing and dashboard upload support to handle additional markup formats.

New Features:

  • Support .rst and .adoc files in the knowledge base by routing them through the existing Markitdown-based text parser.
  • Allow uploading .rst and .adoc files from the dashboard file picker with appropriate icons and colors in the document list.

Documentation:

  • Update knowledge base UI copy to list .rst and .adoc among supported upload formats.

Tests:

  • Add parser selection tests to ensure .rst and .adoc extensions are correctly mapped to the Markitdown parser.

@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. area:webui The bug / feature is about webui(dashboard) of astrbot. feature:knowledge-base The bug / feature is about knowledge base labels May 20, 2026

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • The set of Markitdown-backed extensions is now duplicated across select_parser, the file input accept attribute, and the icon/color helpers; consider centralizing these extensions in a shared constant or config to keep frontend and backend behavior in sync and avoid drift when formats change.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The set of Markitdown-backed extensions is now duplicated across `select_parser`, the file input `accept` attribute, and the icon/color helpers; consider centralizing these extensions in a shared constant or config to keep frontend and backend behavior in sync and avoid drift when formats change.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds support for .rst and .adoc file formats to the knowledge base by updating the backend parser selection, frontend file upload filters, and UI components. Feedback suggests replacing .includes() with exact string equality when determining file icons and colors in the frontend to prevent incorrect matches with other file extensions.

const type = fileType?.toLowerCase() || ''
if (type.includes('pdf')) return 'mdi-file-pdf-box'
if (type.includes('epub')) return 'mdi-book-open-page-variant'
if (type.includes('rst') || type.includes('adoc')) return 'mdi-file-document-outline'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using .includes() for file extension checks is unreliable because it can match substrings in unrelated extensions. For example, a file with a .first extension would incorrectly match the rst check. Since type is the lowercased extension string, exact equality is safer and more predictable.

  if (type === 'rst' || type === 'adoc') return 'mdi-file-document-outline'

const type = fileType?.toLowerCase() || ''
if (type.includes('pdf')) return 'error'
if (type.includes('epub')) return 'warning'
if (type.includes('rst') || type.includes('adoc')) return 'success'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similar to the icon selection logic, using .includes() here is prone to false positives with extensions that happen to contain these substrings (e.g., .first matching rst). Exact string comparison should be used to ensure the correct color is applied.

  if (type === 'rst' || type === 'adoc') return 'success'

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds support for .rst and .adoc file formats to the knowledge base by updating the parser selection logic, UI localization files, and file upload components. Feedback suggests consolidating the icon and color mapping logic in DocumentsTab.vue for these new formats and .txt files to improve maintainability and reduce redundancy.

Comment on lines +712 to 714
if (type.includes('rst') || type.includes('adoc')) return 'mdi-file-document-outline'
if (type.includes('md') || type.includes('markdown')) return 'mdi-language-markdown'
if (type.includes('txt')) return 'mdi-file-document-outline'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The icon mapping for .rst, .adoc, and .txt files can be consolidated since they all use the same icon (mdi-file-document-outline). This improves maintainability and reduces redundancy in the icon selection logic.

  if (type.includes('md') || type.includes('markdown')) return 'mdi-language-markdown'
  if (type.includes('rst') || type.includes('adoc') || type.includes('txt')) return 'mdi-file-document-outline'

Comment on lines +723 to 725
if (type.includes('rst') || type.includes('adoc')) return 'success'
if (type.includes('md')) return 'info'
if (type.includes('txt')) return 'success'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The color mapping for .rst, .adoc, and .txt files can be merged as they all share the 'success' color status. This keeps the mapping logic concise and easier to update in the future.

  if (type.includes('md')) return 'info'
  if (type.includes('rst') || type.includes('adoc') || type.includes('txt')) return 'success'

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label May 20, 2026
@RC-CHN RC-CHN merged commit c4693fa into AstrBotDevs:master May 20, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:webui The bug / feature is about webui(dashboard) of astrbot. feature:knowledge-base The bug / feature is about knowledge base lgtm This PR has been approved by a maintainer size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] 知识库无法上传 rst 格式(reStructuredText)文本文件

2 participants