Skip to content

feat: add palette config types for plugin color selection#4650

Open
bylkuse wants to merge 12 commits intoAstrBotDevs:masterfrom
bylkuse:master
Open

feat: add palette config types for plugin color selection#4650
bylkuse wants to merge 12 commits intoAstrBotDevs:masterfrom
bylkuse:master

Conversation

@bylkuse
Copy link

@bylkuse bylkuse commented Jan 24, 2026

为 'string' 配置项新增了 'widget' 类型 'palette' 并在前端渲染相应的调色板界面,以期解决插件配置中需要保存&管理 HEX、RGB、HSV 等不同格式的颜色时麻烦、不直观的问题

_conf_schema.json中的调用(默认为hex格式如 #FFFFFF ):
"type": "string",
"widget": "palette"

RGB 格式(如 rgb(255, 0, 0) ):
"type": "string",
"widget": "palette",
"widget_props": {
"format": "rgb"
}

HSV 格式(如 hsv(0, 0%, 100%)):
"type": "string",
"widget": "palette",
"widget_props": {
"format": "hsv"
}

Modifications / 改动点

前端 (Vue/TypeScript)
dashboard/src/components/shared/PaletteEditor.vue | 新增 | 调色板核心组件
dashboard/src/components/shared/ConfigItemRenderer.vue | 修改 | 导入并渲染 palette 类型

国际化 (i18n)
dashboard/src/i18n/locales/en-US/core/common.json | 修改 | [调色板] 英文翻译
dashboard/src/i18n/locales/zh-CN/core/common.json | 修改 | [调色板] 中文翻译

  • This is NOT a breaking change. / 这不是一个破坏性变更。

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

image

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.

按照 @Soulter 的建议已改为基于 string 配置项的纯前端实现

@dosubot dosubot bot added the size:XL This PR changes 500-999 lines, ignoring generated files. label Jan 24, 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.

嗨,我在这里给出了一些高层次的反馈:

  • PaletteEditor.vue 中的颜色解析和转换辅助方法(hex/rgb/hsv 的解析和转换)体量比较大,建议抽取到一个共享的工具模块中,这样可以复用、更容易测试,也能让该组件更专注于 UI 逻辑。
  • PaletteEditor.vue 中的剪贴板处理假设 navigator.clipboard 一定可用,并使用了一个硬编码的英文回退消息("Copy failed");更安全的做法是先判断 API 是否可用,并将所有面向用户的文案都通过 i18n 层处理。
  • 当主文本字段通过直接输入(onDirectInput)发生变化时,内部的拾色器/预览状态要等到菜单打开才会同步;建议在输入变更时立刻解析并同步该值,这样预览和校验就能在弹出层之外的用户编辑场景下保持一致。
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The color parsing and conversion helpers (hex/rgb/hsv parsing and transforms) in `PaletteEditor.vue` are quite substantial; consider extracting them into a shared utility module so they can be reused, more easily tested, and keep the component focused on UI logic.
- Clipboard handling in `PaletteEditor.vue` assumes `navigator.clipboard` is available and uses a hard-coded English fallback message (`'Copy failed'`); it would be safer to guard for API availability and route all user-visible text through the i18n layer.
- When the main text field value changes via direct input (`onDirectInput`), the internal picker/preview state is not synchronized until the menu opens; consider parsing and syncing that value immediately so the preview and validation stay consistent with user edits outside the popup.

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

Hey - I've left some high level feedback:

  • The color parsing and conversion helpers (hex/rgb/hsv parsing and transforms) in PaletteEditor.vue are quite substantial; consider extracting them into a shared utility module so they can be reused, more easily tested, and keep the component focused on UI logic.
  • Clipboard handling in PaletteEditor.vue assumes navigator.clipboard is available and uses a hard-coded English fallback message ('Copy failed'); it would be safer to guard for API availability and route all user-visible text through the i18n layer.
  • When the main text field value changes via direct input (onDirectInput), the internal picker/preview state is not synchronized until the menu opens; consider parsing and syncing that value immediately so the preview and validation stay consistent with user edits outside the popup.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The color parsing and conversion helpers (hex/rgb/hsv parsing and transforms) in `PaletteEditor.vue` are quite substantial; consider extracting them into a shared utility module so they can be reused, more easily tested, and keep the component focused on UI logic.
- Clipboard handling in `PaletteEditor.vue` assumes `navigator.clipboard` is available and uses a hard-coded English fallback message (`'Copy failed'`); it would be safer to guard for API availability and route all user-visible text through the i18n layer.
- When the main text field value changes via direct input (`onDirectInput`), the internal picker/preview state is not synchronized until the menu opens; consider parsing and syncing that value immediately so the preview and validation stay consistent with user edits outside the popup.

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.

@dosubot dosubot bot added area:core The bug / feature is about astrbot's core, backend area:webui The bug / feature is about webui(dashboard) of astrbot. labels Jan 24, 2026
@bylkuse
Copy link
Author

bylkuse commented Jan 24, 2026

@sourcery-ai review

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.

Hey - 我在这里给出了一些高层次的反馈:

  • 与调色板相关的三个类型(palettepalette_rgbpalette_hsv)在多个位置被硬编码(后端校验、默认映射、前端渲染器);建议将它们集中到一个共享的常量或枚举中,这样在添加或修改调色板格式时可以避免出现不一致。
  • PaletteEditor.vue 中,任何无效的直接输入仍然会更新 modelValue,并且只展示一个校验提示气泡;如果后端对每种类型都要求严格格式化的值,你可能需要在前端对输入进行规范化或直接拒绝,而不是原样传递无效输入。
给 AI 代理的提示
Please address the comments from this code review:

## Overall Comments
- The three palette-related types ('palette', 'palette_rgb', 'palette_hsv') are hard-coded in several places (backend validation, default maps, front-end renderer); consider centralizing them in a shared constant/enum to avoid divergence when adding or changing palette formats.
- In `PaletteEditor.vue`, any invalid direct input still updates `modelValue` and only shows a validation tooltip; if backend expects strictly formatted values per type, you may want to normalize or reject invalid input instead of propagating it unchanged.

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

Hey - I've left some high level feedback:

  • The three palette-related types ('palette', 'palette_rgb', 'palette_hsv') are hard-coded in several places (backend validation, default maps, front-end renderer); consider centralizing them in a shared constant/enum to avoid divergence when adding or changing palette formats.
  • In PaletteEditor.vue, any invalid direct input still updates modelValue and only shows a validation tooltip; if backend expects strictly formatted values per type, you may want to normalize or reject invalid input instead of propagating it unchanged.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The three palette-related types ('palette', 'palette_rgb', 'palette_hsv') are hard-coded in several places (backend validation, default maps, front-end renderer); consider centralizing them in a shared constant/enum to avoid divergence when adding or changing palette formats.
- In `PaletteEditor.vue`, any invalid direct input still updates `modelValue` and only shows a validation tooltip; if backend expects strictly formatted values per type, you may want to normalize or reject invalid input instead of propagating it unchanged.

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.

@bylkuse
Copy link
Author

bylkuse commented Jan 24, 2026

@sourcery-ai review

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.

Hey - 我在这里给了一些总体反馈:

  • 新的 palettepalette_rgbpalette_hsv 类型标识符在多个地方被重复为字符串字面量(Python 校验、默认映射、Vue 组件);建议在后端和前端分别集中到共享的常量/枚举中,以减少拼写错误的风险并保持行为一致。
  • TemplateListEditordefault.py 中,palette_rgbpalette_hsv 的默认值是空字符串,而 UI 期望的是结构化格式(例如 rgb(...)hsv(...));建议将默认值与期望格式对齐,或者在编辑器中显式处理空值情况,以避免出现不一致的初始状态。
给 AI Agent 的提示词
Please address the comments from this code review:

## Overall Comments
- 新的 `palette``palette_rgb``palette_hsv` 类型标识符在多个地方被重复为字符串字面量(Python 校验、默认映射、Vue 组件);建议在后端和前端分别集中到共享的常量/枚举中,以减少拼写错误的风险并保持行为一致。
-`TemplateListEditor``default.py` 中,`palette_rgb``palette_hsv` 的默认值是空字符串,而 UI 期望的是结构化格式(例如 `rgb(...)``hsv(...)`);建议将默认值与期望格式对齐,或者在编辑器中显式处理空值情况,以避免出现不一致的初始状态。

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

Hey - I've left some high level feedback:

  • The new palette, palette_rgb, and palette_hsv type identifiers are repeated as string literals in multiple places (Python validation, default maps, Vue components); consider centralizing them in a shared constant/enum on both backend and frontend to reduce the risk of typos and keep behavior in sync.
  • In TemplateListEditor and default.py the default values for palette_rgb and palette_hsv are empty strings while the UI expects structured formats (e.g., rgb(...), hsv(...)); consider aligning the defaults with the expected format or handling the empty case explicitly in the editor to avoid inconsistent initial states.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new `palette`, `palette_rgb`, and `palette_hsv` type identifiers are repeated as string literals in multiple places (Python validation, default maps, Vue components); consider centralizing them in a shared constant/enum on both backend and frontend to reduce the risk of typos and keep behavior in sync.
- In `TemplateListEditor` and `default.py` the default values for `palette_rgb` and `palette_hsv` are empty strings while the UI expects structured formats (e.g., `rgb(...)`, `hsv(...)`); consider aligning the defaults with the expected format or handling the empty case explicitly in the editor to avoid inconsistent initial states.

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.

@bylkuse
Copy link
Author

bylkuse commented Jan 24, 2026

@sourcery-ai review

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.

Hey - 我发现了 1 个问题,并给出了一些总体性反馈:

  • 你现在有两个独立的 DEFAULT_VALUE_MAP 定义(一个是新加在 config_types.py 中的,另一个是 PR 描述中提到的现有 core/config/default.py 中的);建议把它们统一整合,这样后端默认配置值就只有一个权威来源。
  • 在前端,ConfigType 和 ColorFormat 被硬编码在 dashboard/src/utils/color.ts,而它们在后端的对应定义位于 astrbot/core/config/config_types.py;为了避免两边逐渐偏离,可能值得引入一个简单的共享 schema 或生成步骤,而不是在前后端分别维护这些字符串枚举。
  • PaletteEditor.vue 在一个基于 TypeScript 的 dashboard 中使用的是纯 JS,并且 props 使用的是字符串类型(例如 format: String);如果把这些收紧为使用 ColorFormatType/PaletteConfigType 类型并启用 lang="ts",会让这个组件更安全,也更符合整个代码库的风格。
给 AI Agent 的提示
请根据这次代码评审中的评论进行修改:

## 整体评论
- 你现在有两个独立的 DEFAULT_VALUE_MAP 定义(一个是新加在 config_types.py 中的,另一个是 PR 描述中提到的现有 core/config/default.py 中的);建议把它们统一整合,这样后端默认配置值就只有一个权威来源。
- 在前端,ConfigType 和 ColorFormat 被硬编码在 dashboard/src/utils/color.ts,而它们在后端的对应定义位于 astrbot/core/config/config_types.py;为了避免两边逐渐偏离,可能值得引入一个简单的共享 schema 或生成步骤,而不是在前后端分别维护这些字符串枚举。
- PaletteEditor.vue 在一个基于 TypeScript 的 dashboard 中使用的是纯 JS,并且 props 使用的是字符串类型(例如 format: String);如果把这些收紧为使用 ColorFormatType/PaletteConfigType 类型并启用 lang="ts",会让这个组件更安全,也更符合整个代码库的风格。

## 单条评论

### 评论 1
<location> `dashboard/src/utils/color.ts:99-100` </location>
<code_context>
+export function hsvToRgb(h: number, s: number, v: number): RgbColor {
</code_context>

<issue_to_address>
**suggestion:** 建议在 `hsvToRgb` 中对 `h``s``v` 做范围限制,以避免超出范围的输入导致意外结果。

目前,`hsvToRgb` 依赖调用方传入已归一化的值,这一点和会在调用前进行截断的 `parseAnyColor` 不同。如果直接用超出范围的输入调用 `hsvToRgb`,可能会产生意外输出。在函数开头添加范围限制(例如对每个参数使用 `Math.max/Math.min`)可以让它对将来的调用方更安全、更不易出错。

```suggestion
export function hsvToRgb(h: number, s: number, v: number): RgbColor {
  h = Math.max(0, Math.min(360, h))
  s = Math.max(0, Math.min(100, s))
  v = Math.max(0, Math.min(100, v))

  h /= 360
  s /= 100
  v /= 100
```
</issue_to_address>

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

Hey - I've found 1 issue, and left some high level feedback:

  • You now have two separate DEFAULT_VALUE_MAP definitions (new one in config_types.py and the existing one in core/config/default.py referenced in the PR description); consider consolidating these so there is a single source of truth for default config values on the backend.
  • On the frontend, ConfigType and ColorFormat are hard-coded in dashboard/src/utils/color.ts while their backend counterparts live in astrbot/core/config/config_types.py; to avoid drift, it may be worth introducing a simple shared schema or generation step rather than maintaining these string enums in parallel.
  • PaletteEditor.vue is written in plain JS in a TypeScript-based dashboard and uses string-typed props (e.g., format: String); tightening these to use the ColorFormatType/PaletteConfigType types and enabling lang="ts" would make the component safer and better aligned with the rest of the codebase.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- You now have two separate DEFAULT_VALUE_MAP definitions (new one in config_types.py and the existing one in core/config/default.py referenced in the PR description); consider consolidating these so there is a single source of truth for default config values on the backend.
- On the frontend, ConfigType and ColorFormat are hard-coded in dashboard/src/utils/color.ts while their backend counterparts live in astrbot/core/config/config_types.py; to avoid drift, it may be worth introducing a simple shared schema or generation step rather than maintaining these string enums in parallel.
- PaletteEditor.vue is written in plain JS in a TypeScript-based dashboard and uses string-typed props (e.g., format: String); tightening these to use the ColorFormatType/PaletteConfigType types and enabling lang="ts" would make the component safer and better aligned with the rest of the codebase.

## Individual Comments

### Comment 1
<location> `dashboard/src/utils/color.ts:99-100` </location>
<code_context>
+export function hsvToRgb(h: number, s: number, v: number): RgbColor {
</code_context>

<issue_to_address>
**suggestion:** Consider clamping `h`, `s`, and `v` in `hsvToRgb` to avoid unexpected results for out-of-range inputs.

Right now, `hsvToRgb` relies on callers to pass normalized values, unlike `parseAnyColor`, which clamps before calling it. If `hsvToRgb` is used directly with out-of-range inputs, it can yield unexpected outputs. Adding clamping at the top of the function (e.g. with `Math.max/Math.min` for each parameter) makes it safer and less error-prone for future callers.

```suggestion
export function hsvToRgb(h: number, s: number, v: number): RgbColor {
  h = Math.max(0, Math.min(360, h))
  s = Math.max(0, Math.min(100, s))
  v = Math.max(0, Math.min(100, v))

  h /= 360
  s /= 100
  v /= 100
```
</issue_to_address>

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.

@bylkuse
Copy link
Author

bylkuse commented Jan 24, 2026

脑袋疼,改不动了,我只是想加个配置项,优化超出我能力范围了。如果确实还有什么需要优化的地方,来个佬捞捞我求求了

Copy link
Member

@Soulter Soulter left a comment

Choose a reason for hiding this comment

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

给出一些建议,如果你是要增加这个配置项类型的话,只修改前端就行。然后如果方便的话可以去 https://github.com/AstrBotDevs/AstrBot-docs 指定的位置提交 PR,描述如何使用这个配置项即可!

这个配置项我理解是不需要改 AstrBot 的 Core 的。我建议就直接只在 type=='string' 的配置项那里加相关字段来表示前端需要渲染一个调色盘。

@bylkuse
Copy link
Author

bylkuse commented Feb 2, 2026

给出一些建议,如果你是要增加这个配置项类型的话,只修改前端就行。然后如果方便的话可以去 AstrBotDevs/AstrBot-docs 指定的位置提交 PR,描述如何使用这个配置项即可!

这个配置项我理解是不需要改 AstrBot 的 Core 的。我建议就直接只在 type=='string' 的配置项那里加相关字段来表示前端需要渲染一个调色盘。

好的,我过后改回去,因为Sourcery一直建议我做后端改进,我自己也越改越觉得不对劲,感谢指导

astrbot-doc-agent bot pushed a commit to AstrBotDevs/AstrBot-docs that referenced this pull request Feb 2, 2026
@astrbot-doc-agent
Copy link

已为该 PR 生成文档更新 PR(待人工审核):
AstrBotDevs/AstrBot-docs#117


AI 改动摘要:

  • 同步更新中英文文档(zh/en/dev/star/guides/plugin-config.md)。
  • 在插件配置指南中新增 palette、palette_rgb 和 palette_hsv 三种颜色选择器类型的说明。
  • 详细描述了各类型的返回格式(HEX、RGB、HSV)并提供了 _conf_schema.json 的定义示例。

astrbot-doc-agent bot pushed a commit to AstrBotDevs/AstrBot-docs that referenced this pull request Feb 2, 2026
@astrbot-doc-agent
Copy link

已为该 PR 生成文档更新 PR(待人工审核):
AstrBotDevs/AstrBot-docs#117


AI 改动摘要:

  • zh/dev/star/guides/plugin-config.mden/dev/star/guides/plugin-config.md 中新增调色板配置项说明。
  • 详细介绍了 palette (HEX)、palette_rgb (RGB) 及 palette_hsv (HSV) 三种颜色选择器类型的定义与返回格式。
  • 提供了在 _conf_schema.json 中定义颜色选择器的示例代码,并标注该功能适用于 v4.15.0 及以上版本。
  • 已同步更新中英文(zh/en)文档内容。

@bylkuse bylkuse requested a review from Soulter February 2, 2026 17:53
@bylkuse
Copy link
Author

bylkuse commented Feb 2, 2026

给出一些建议,如果你是要增加这个配置项类型的话,只修改前端就行。然后如果方便的话可以去 AstrBotDevs/AstrBot-docs 指定的位置提交 PR,描述如何使用这个配置项即可!

这个配置项我理解是不需要改 AstrBot 的 Core 的。我建议就直接只在 type=='string' 的配置项那里加相关字段来表示前端需要渲染一个调色盘。

感谢佬的指导,如果确认这个配置结构没问题的话我再去AstrBot-docs提供文档PR

astrbot-doc-agent bot pushed a commit to AstrBotDevs/AstrBot-docs that referenced this pull request Feb 2, 2026
@astrbot-doc-agent
Copy link

已为该 PR 生成文档更新 PR(待人工审核):
AstrBotDevs/AstrBot-docs#117


AI 改动摘要:

  • 更新了中英文档 zh/dev/star/guides/plugin-config.mden/dev/star/guides/plugin-config.md
  • 在插件配置 type 字段中新增 palettepalette_rgbpalette_hsv 三种类型说明。
  • 新增“调色板类型”章节,详细描述了 HEX、RGB、HSV 格式在 WebUI 中的渲染效果与交互方式。
  • 本次更新已同步完成中英文 (zh/en) 翻译。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core The bug / feature is about astrbot's core, backend area:webui The bug / feature is about webui(dashboard) of astrbot. size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants