Skip to content

feat(plugin): 增加加载失败插件重装按钮#6092

Open
catDforD wants to merge 3 commits intoAstrBotDevs:masterfrom
catDforD:feat/6021
Open

feat(plugin): 增加加载失败插件重装按钮#6092
catDforD wants to merge 3 commits intoAstrBotDevs:masterfrom
catDforD:feat/6021

Conversation

@catDforD
Copy link
Contributor

@catDforD catDforD commented Mar 12, 2026

Closes #6021

本次改动为失败插件列表补充“重新安装”能力,并完善重装过程中的前端提示反馈,解决失败插件只能“重载 / 卸载”、且重装过程中缺少状态提示的问题。

Modifications / 改动点

  • 为失败插件列表新增“重新安装”按钮和对应的后端接口。
  • 重装逻辑基于失败插件记录中的 repo 重新拉取插件源码并重新安装。
  • 修复重装失败时失败记录被提前删除的问题,确保失败插件不会从列表中消失。
  • 为“重新安装”操作补充即时提示、按钮 loading 态和禁用态。
  • 补充重装相关单元测试,并同步更新中英文文案。

文件变更统计:

  • 新增文件:0 个
  • 修改文件:7 个
  • 删除文件:0 个

详细变更:

文件 变更类型 说明
astrbot/core/star/star_manager.py 修改 新增失败插件重装逻辑,并在重装失败时恢复失败记录
astrbot/dashboard/routes/plugin.py 修改 新增失败插件重装接口
dashboard/src/views/extension/useExtensionPage.js 修改 接入失败插件重装请求、toast 提示和按钮状态管理
dashboard/src/views/extension/InstalledPluginsTab.vue 修改 为失败插件区域增加重装按钮及 loading/禁用态
dashboard/src/i18n/locales/zh-CN/features/extension.json 修改 新增中文重装提示文案
dashboard/src/i18n/locales/en-US/features/extension.json 修改 新增英文重装提示文案
tests/test_plugin_manager.py 修改 补充重装成功、缺少 repo、失败恢复记录等测试
  • This is NOT a breaking change. / 这不是一个破坏性变更。

Screenshots or Test Results / 运行截图或测试结果

验证步骤:

  1. 构造加载失败插件并进入 /extension#installed 的失败插件列表页面。
  2. 验证失败插件区域新增“重新安装”按钮。
  3. 点击“重新安装”后,确认页面立即显示“正在重新安装”提示,且按钮进入 loading 态。
  4. 使用真实插件 astrbot_plugin_self_code 验证重新安装成功。
  5. 验证当重装过程失败时,失败插件仍保留在失败列表中,不会消失。

测试结果:

uv run pytest tests/test_plugin_manager.py -k 'reinstall_failed_plugin'
# 4 passed, 14 deselected

ruff check astrbot/core/star/star_manager.py tests/test_plugin_manager.py
# All checks passed!

cd dashboard && pnpm build
# ✓ built in 24.52s

运行视频:

test.mp4

Checklist / 检查清单

  • 😊 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。/ If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
  • 👀 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。/ My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
  • 🤓 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到了 requirements.txtpyproject.toml 文件相应位置。/ 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.txt and pyproject.toml.
  • 😮 我的更改没有引入恶意代码。/ My changes do not introduce malicious code.

Sourcery 总结

添加对使用插件原始仓库源重新安装失败插件的支持,并通过仪表板 UI 和 API 暴露这一流程。

新功能:

  • 允许在插件管理器中复用已记录的仓库 URL 来重新安装失败的插件。
  • 暴露一个后端 API 端点,用于从仪表板触发对失败插件的重新安装。
  • 在扩展页面为失败插件添加重新安装操作以及有状态的 UI 反馈。

错误修复:

  • 确保在重新安装尝试失败或缺少仓库信息时,失败插件记录能够被保留或正确恢复。

测试:

  • 添加单元测试,覆盖失败插件成功重新安装、缺失仓库信息的处理以及在重新安装出错时恢复失败记录等场景。
Original summary in English

Summary by Sourcery

Add support for reinstalling failed plugins using their original repository source and expose this flow through the dashboard UI and API.

New Features:

  • Allow reinstalling failed plugins by reusing the recorded repository URL in the plugin manager.
  • Expose a backend API endpoint to trigger reinstall of a failed plugin from the dashboard.
  • Add a reinstall action and stateful UI feedback for failed plugins in the extensions page.

Bug Fixes:

  • Ensure failed plugin records are preserved or correctly restored when reinstall attempts fail or are missing repository information.

Tests:

  • Add unit tests covering successful failed-plugin reinstall, missing repo handling, and restoration of failed records on reinstall errors.

@gemini-code-assist
Copy link
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. feature:plugin The bug / feature is about AstrBot plugin system. labels Mar 12, 2026
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

你好——我在这里给了一些整体性的反馈:

  • StarManager.reinstall_failed_plugin 中,缺少仓库地址时使用了硬编码的中文错误信息("失败插件缺少仓库地址,无法重新安装。"),绕过了 format_plugin_error,导致和其他错误文案以及 i18n 机制不一致;建议新增一个专门的错误 key,并通过 format_plugin_error 来生成错误信息。
  • PluginRoute.reinstall_failed_plugin 处理器直接从后端返回了一条中文成功消息("重新安装成功。"),而前端已经有本地化的 toast 文案;建议要么前端不要依赖后端返回的消息、复用已有的本地化文案,要么在后端对这类响应信息进行标准化,使其符合现有的 i18n 方式。
面向 AI 代理的提示词
Please address the comments from this code review:

## Overall Comments
- In `StarManager.reinstall_failed_plugin`, the hard-coded Chinese error message for missing repo (`"失败插件缺少仓库地址,无法重新安装。"`) bypasses `format_plugin_error` and breaks consistency with other error strings and i18n; consider adding a dedicated error key and using `format_plugin_error` instead.
- The `PluginRoute.reinstall_failed_plugin` handler returns a Chinese success message (`"重新安装成功。"`) directly from the backend while the frontend already has localized toast texts; either reuse the localized frontend strings by not relying on backend messages, or standardize this response message to match the existing i18n approach.

Sourcery 对开源项目是免费的——如果你觉得我们的代码审查有帮助,欢迎分享给更多人 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续的代码审查。
Original comment in English

Hey - I've left some high level feedback:

  • In StarManager.reinstall_failed_plugin, the hard-coded Chinese error message for missing repo ("失败插件缺少仓库地址,无法重新安装。") bypasses format_plugin_error and breaks consistency with other error strings and i18n; consider adding a dedicated error key and using format_plugin_error instead.
  • The PluginRoute.reinstall_failed_plugin handler returns a Chinese success message ("重新安装成功。") directly from the backend while the frontend already has localized toast texts; either reuse the localized frontend strings by not relying on backend messages, or standardize this response message to match the existing i18n approach.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `StarManager.reinstall_failed_plugin`, the hard-coded Chinese error message for missing repo (`"失败插件缺少仓库地址,无法重新安装。"`) bypasses `format_plugin_error` and breaks consistency with other error strings and i18n; consider adding a dedicated error key and using `format_plugin_error` instead.
- The `PluginRoute.reinstall_failed_plugin` handler returns a Chinese success message (`"重新安装成功。"`) directly from the backend while the frontend already has localized toast texts; either reuse the localized frontend strings by not relying on backend messages, or standardize this response message to match the existing i18n approach.

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.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6f806d7ef9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +1378 to +1382
if dir_name not in self.failed_plugin_dict:
restored_info = failed_info_snapshot
if isinstance(restored_info, dict):
restored_info["error"] = str(e)
restored_info["traceback"] = traceback.format_exc()

Choose a reason for hiding this comment

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

P2 Badge Avoid restoring stale failed entry after reinstall cleanup

When reinstall_failed_plugin catches an exception, this block restores failed_plugin_dict[dir_name] from the snapshot without verifying the plugin directory still exists. In the failure path where remove_dir(plugin_path) has already run and install_plugin fails before creating a new checkout (for example, a network failure in updator.install), the manager now advertises a failed plugin that has no on-disk directory; a later reload_failed_plugin call will report success and drop the record even though nothing was reinstalled. This leaves plugin state inconsistent and gives a false-success recovery flow.

Useful? React with 👍 / 👎.

# Conflicts:
#	astrbot/core/star/star_manager.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature:plugin The bug / feature is about AstrBot plugin system. size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]增加失败插件重装按钮

1 participant