Skip to content

Conversation

@Soulter
Copy link
Member

@Soulter Soulter commented Jan 12, 2026

Motivation

  • Prevent platform IDs containing reserved characters : and ! which break UMO routing and session matching.
  • Do not skip loading such platforms; instead sanitize IDs (replace reserved chars with _) and persist the corrected value so the issue does not recur.
  • Provide fast feedback in the web UI to block creation/update of invalid IDs and show a clear localized message.

Description

  • Add _sanitize_platform_id and update load_platform in astrbot/core/platform/manager.py to replace :/! with _, call save_config() when a change is made, and log a warning.
  • Add isPlatformIdValid and validation checks in dashboard/src/components/platform/AddNewPlatform.vue to block saving/updating invalid IDs and display tm('dialog.invalidPlatformId').
  • Add dialog.invalidPlatformId localization entries to dashboard/src/i18n/locales/en-US/features/platform.json and dashboard/src/i18n/locales/zh-CN/features/platform.json.
  • Preserve existing UI validation and adapter loading flow while ensuring sanitized IDs are persisted and used going forward.

Testing

  • No automated tests were run as part of this change.

Codex Task

Summary by Sourcery

在加载平台时清理无效的平台 ID,并在前端强制校验,防止创建或更新包含保留字符的平台 ID。

New Features:

  • 在后端添加对平台 ID 的自动清理:将保留字符替换为安全的替代字符,并持久化修正后的配置。
  • 在控制面板 UI 中引入客户端校验,对无效的平台 ID 进行拦截并显示本地化的错误消息。

Enhancements:

  • 在平台 ID 被清理时记录警告日志,并在平台 ID 缺失或无效时跳过适配器加载。
  • 扩展平台本地化文件,以包含无效平台 ID 错误的相关消息。
Original summary in English

Summary by Sourcery

Sanitize invalid platform IDs during platform loading and enforce front-end validation to prevent creation or update of platforms with reserved characters in their IDs.

New Features:

  • Add automatic sanitization of platform IDs in the backend to replace reserved characters with safe alternatives and persist the corrected configuration.
  • Introduce client-side validation for platform IDs in the dashboard UI to block invalid IDs and display a localized error message.

Enhancements:

  • Log warnings when platform IDs are sanitized and skip loading adapters when IDs are missing or invalid.
  • Extend platform localization files to include messages for invalid platform ID errors.

@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jan 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.

Hey - 我给出了一些整体性的反馈:

  • 现在平台 ID 的校验规则在 Python(_is_valid_platform_id / _sanitize_platform_id)和 Vue 里的 isPlatformIdValid 正则中都各自维护了一份;建议把允许/禁止的字符定义集中到一个地方,这样以后如果有修改,就不会悄悄导致后端和前端行为不一致。
  • AddNewPlatform.vue 中,validateForm 里新增的提前返回校验(if (!this.isPlatformIdValid(this.selectedPlatformConfig?.id)) { return false; })会阻止提交,但不像其他会调用 showError 的校验路径那样向用户展示错误信息,这可能会让人困惑。
  • load_platform 中调用 this.astrbot_config.save_config() 意味着现在在适配器初始化期间就会写配置;可以考虑把这种副作用放到单独的迁移/规范化步骤中,以保证“加载”过程本身是幂等的,并避免在启动时发生意料之外的磁盘写入。
给 AI Agent 的提示词
Please address the comments from this code review:

## Overall Comments
- The platform ID validation rules are now duplicated in Python (`_is_valid_platform_id` / `_sanitize_platform_id`) and in the Vue `isPlatformIdValid` regex; consider centralizing the allowed/forbidden character definition so future changes don’t silently desynchronize backend and frontend behavior.
- In `AddNewPlatform.vue`, the new early-return check in `validateForm` (`if (!this.isPlatformIdValid(this.selectedPlatformConfig?.id)) { return false; }`) prevents submission but doesn’t surface an error message to the user, unlike the other validation paths that call `showError`, which may be confusing.
- Calling `this.astrbot_config.save_config()` from within `load_platform` means config writes now happen during adapter initialization; consider whether this side effect belongs in a separate migration/normalization step to keep loading idempotent and avoid unexpected disk writes during startup.

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

Hey - I've left some high level feedback:

  • The platform ID validation rules are now duplicated in Python (_is_valid_platform_id / _sanitize_platform_id) and in the Vue isPlatformIdValid regex; consider centralizing the allowed/forbidden character definition so future changes don’t silently desynchronize backend and frontend behavior.
  • In AddNewPlatform.vue, the new early-return check in validateForm (if (!this.isPlatformIdValid(this.selectedPlatformConfig?.id)) { return false; }) prevents submission but doesn’t surface an error message to the user, unlike the other validation paths that call showError, which may be confusing.
  • Calling this.astrbot_config.save_config() from within load_platform means config writes now happen during adapter initialization; consider whether this side effect belongs in a separate migration/normalization step to keep loading idempotent and avoid unexpected disk writes during startup.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The platform ID validation rules are now duplicated in Python (`_is_valid_platform_id` / `_sanitize_platform_id`) and in the Vue `isPlatformIdValid` regex; consider centralizing the allowed/forbidden character definition so future changes don’t silently desynchronize backend and frontend behavior.
- In `AddNewPlatform.vue`, the new early-return check in `validateForm` (`if (!this.isPlatformIdValid(this.selectedPlatformConfig?.id)) { return false; }`) prevents submission but doesn’t surface an error message to the user, unlike the other validation paths that call `showError`, which may be confusing.
- Calling `this.astrbot_config.save_config()` from within `load_platform` means config writes now happen during adapter initialization; consider whether this side effect belongs in a separate migration/normalization step to keep loading idempotent and avoid unexpected disk writes during startup.

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:platform The bug / feature is about IM platform adapter, such as QQ, Lark, Telegram, WebChat and so on. area:webui The bug / feature is about webui(dashboard) of astrbot. labels Jan 12, 2026
@Soulter Soulter merged commit 2bbe010 into master Jan 12, 2026
6 checks passed
@Soulter Soulter deleted the codex/implement-issue-4413-with-minimal-changes branch January 12, 2026 11:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:platform The bug / feature is about IM platform adapter, such as QQ, Lark, Telegram, WebChat and so on. area:webui The bug / feature is about webui(dashboard) of astrbot. codex size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants