fix: plugin name in the marketplace does not match the local plugin#8274
fix: plugin name in the marketplace does not match the local plugin#8274Waterwzy wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The backend now does
plugin.name.replace("_", "-")in multiple places; consider centralizing this into a single normalization helper to keep the transformation consistent and easier to adjust if the naming convention changes again. - On the frontend,
normalizeStris used alongside the backend’s underscore-to-dash conversion; it would be safer to clearly align and document the exact normalization rules in one place (or share a utility) so that backend/ frontend name matching cannot drift over time. - This PR introduces new dashboard dependencies (
@ricky0123/vad-web,onnxruntime-web) that don’t seem directly related to the plugin name matching fix; consider either moving these to a separate PR or clarifying why they are required for this change.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The backend now does `plugin.name.replace("_", "-")` in multiple places; consider centralizing this into a single normalization helper to keep the transformation consistent and easier to adjust if the naming convention changes again.
- On the frontend, `normalizeStr` is used alongside the backend’s underscore-to-dash conversion; it would be safer to clearly align and document the exact normalization rules in one place (or share a utility) so that backend/ frontend name matching cannot drift over time.
- This PR introduces new dashboard dependencies (`@ricky0123/vad-web`, `onnxruntime-web`) that don’t seem directly related to the plugin name matching fix; consider either moving these to a separate PR or clarifying why they are required for this change.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Code Review
This pull request modifies plugin name handling by replacing underscores with hyphens in API responses and updates the frontend matching logic. It also introduces new dependencies and adjusts the timing of update checks. Feedback highlights that hyphenating names in the API is a breaking change for backend operations like uninstallation and updates, as the backend still expects underscores. Furthermore, the frontend matching logic is now considered fragile due to the removal of separator normalization, and the addition of the @ricky0123/vad-web and onnxruntime-web dependencies appears unrelated to the core changes.
| "name": plugin.name.replace( | ||
| "_", "-" | ||
| ), # 统一转换为减号格式,与市场数据保持一致 |
There was a problem hiding this comment.
Changing the name field from underscores to hyphens in the API response is a breaking change for plugin management. This field acts as the unique identifier for plugins in subsequent API calls such as /api/plugin/uninstall, /api/plugin/on/off, and /api/plugin/update. Since the backend lookup logic (e.g., get_registered_star or _get_plugin_metadata_by_name) performs a direct string comparison against the internal plugin name (which still uses underscores), these operations will fail for any plugin containing an underscore.
Furthermore, this will break plugin pages because _serve_plugin_page_content uses this name to look up metadata. It is recommended to keep the original name as the identifier and add a separate field for marketplace matching, or update all backend lookup logic to be separator-insensitive. Additionally, refactor the lookup logic into a shared helper function and ensure this new functionality is accompanied by unit tests.
References
- When implementing similar functionality for different cases (e.g., direct vs. quoted attachments), refactor the logic into a shared helper function to avoid code duplication.
- New functionality, such as handling attachments, should be accompanied by corresponding unit tests.
| }, | ||
| "dependencies": { | ||
| "@guolao/vue-monaco-editor": "^1.5.4", | ||
| "@ricky0123/vad-web": "^0.0.30", |
There was a problem hiding this comment.
| const normalizedName = normalizeStr(plugin.name); | ||
| onlinePluginsNameMap.set(normalizedName, plugin); | ||
| }); | ||
|
|
||
| const data = Array.isArray(extension_data?.data) ? extension_data.data : []; | ||
|
|
||
| data.forEach((extension) => { | ||
| const repoKey = extension.repo?.toLowerCase(); | ||
| const onlinePlugin = repoKey ? onlinePluginsMap.get(repoKey) : null; | ||
| const onlinePluginByName = onlinePluginsNameMap.get(extension.name); | ||
|
|
||
| const normalizedExtensionName = normalizeStr(extension.name); | ||
| const onlinePluginByName = onlinePluginsNameMap.get(normalizedExtensionName); |
There was a problem hiding this comment.
The normalizeStr function only performs lowercasing and trimming; it does not handle the _ vs - difference. While the backend now returns hyphenated names in some responses, this makes the frontend matching logic fragile and dependent on inconsistent backend behavior. To ensure robust matching regardless of the backend's internal representation, it is safer to continue normalizing separators (e.g., .replace(/_/g, '-')) during comparison. Consider refactoring this logic into a shared helper function to avoid code duplication.
References
- When implementing similar functionality for different cases (e.g., direct vs. quoted attachments), refactor the logic into a shared helper function to avoid code duplication.
|
有点问题,我得改一下 |
相关前置PR:#7493
在插件市场获取插件时,获取到的插件分隔符为
-但是本地插件的metadata全部为_会导致插件名称的匹配问题。同时,在检查插件更新时,
checkUpdate()在getExtensions()中被调用时,pluginMarketData(远程插件市场数据)尚未加载完成,导致匹配时 ·pluginMarketData· 为空,无法找到匹配的远程插件。本PR通过修改获取插件市场插件的时机,在后端API接口统一插件名称的方式解决了这些问题。
Modifications / 改动点
astrbot/dashboard/routes/plugin.py)修改了 3 个接口方法,统一在返回数据时转换名称格式:
get_plugins()- 返回本地插件列表get_plugin_detail()- 返回插件详情get_plugin_page_components()- 返回插件页面组件信息dashboard/src/views/extension/useExtensionPage.js)调整
checkUpdate()调用时机 :getExtensions()中移除调用(避免在pluginMarketData加载前执行)finalizeSuccessfulInstall()中添加调用(确保安装后立即检查更新)清理
checkAlreadyInstalled()函数 :移除不再需要的 replace(/_/g, "-") 操作This is NOT a breaking change. / 这不是一个破坏性变更。
Screenshots or Test Results / 运行截图或测试结果
当插件repo不匹配但是名称匹配时:
检查是否安装和是否更新的行为均按预期进行。
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 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
Align plugin naming between local data and the marketplace and adjust update checks to rely on normalized names and correctly loaded market data.
Bug Fixes:
Build: