Skip to content

Conversation

@IGCrystal-A
Copy link
Contributor

@IGCrystal-A IGCrystal-A commented Jan 19, 2026

This PR brings several improvements to the Template Editor preview:

  • Dynamic Versioning: Replaced hardcoded v4.0.0 with real-time version fetching from /api/stat/version.

Modifications / 改动点

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

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


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.

Summary by Sourcery

通过使用动态数据来替代硬编码的值,为 T2I 模板编辑器预览提供版本号和预览文本,从而改进预览效果。

新功能:

  • /api/stat/version 接口获取模板预览版本,并在预览中动态显示该版本信息。
  • 使用 i18n 翻译键对预览示例文本进行本地化,而不是使用硬编码字符串。

改进:

  • 在刷新预览或打开编辑器对话框时触发版本同步,以确保预览内容保持最新。
Original summary in English

Summary by Sourcery

Improve the T2I template editor preview by using dynamic data for version and preview text instead of hardcoded values.

New Features:

  • Fetch the template preview version from the /api/stat/version endpoint and display it dynamically in the preview.
  • Localize the preview sample text using the i18n translation key rather than a hardcoded string.

Enhancements:

  • Trigger version synchronization whenever the preview is refreshed or the editor dialog is opened to keep the preview up to date.

@auto-assign auto-assign bot requested review from Raven95676 and anka-afk January 19, 2026 15:06
@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Jan 19, 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 - 我发现了 1 个问题,并留下了一些高层次的反馈:

  • 建议在对话框打开时只获取一次版本并进行缓存/复用,而不是在 dialog 打开和每次 refreshPreview 时都调用 syncPreviewVersion(),以避免重复的网络请求。
  • 如果其他组件也需要应用版本信息,获取版本的逻辑(syncPreviewVersion)可能更适合抽取到一个共享的 composable 或 service 中,这样之后就不用在多个地方重复处理 /api/stat/version 了。
  • 建议不要在 syncPreviewVersion 中直接使用 console.warn,可以考虑通过现有的 UI 通知或日志上报机制来处理错误,这样失败信息就能更一致地展示给用户或监控系统。
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider fetching the version once on dialog open and caching/reusing it rather than calling `syncPreviewVersion()` both on `dialog` open and every `refreshPreview`, to avoid redundant network requests.
- The version-fetching logic (`syncPreviewVersion`) might be better extracted into a shared composable or service if other components also need the app version, so you don't duplicate the `/api/stat/version` handling in multiple places later.
- Instead of using `console.warn` directly in `syncPreviewVersion`, consider routing errors through your existing UI notification or logging mechanism so failures are surfaced consistently to users or monitoring.

## Individual Comments

### Comment 1
<location> `dashboard/src/components/shared/T2ITemplateEditor.vue:299-302` </location>
<code_context>
 }
+
+const previewData = computed(() => ({
+  text: tm('t2iTemplateEditor.previewText') || '这是一个示例文本,用于预览模板效果。\n\n这里可以包含多行文本,支持换行和各种格式。',
+  version: previewVersion.value 
+}))
</code_context>

<issue_to_address>
**suggestion:** Using `||` means an intentionally empty translated string will fall back to the default text.

If `tm('t2iTemplateEditor.previewText')` returns an intentionally empty string, `||` will treat it as falsy and incorrectly fall back to the default Chinese text. To only fall back when the translation is missing (undefined/null), use nullish coalescing or an explicit check, e.g.:

```ts
const t = tm('t2iTemplateEditor.previewText')
text: t ?? defaultText
// or
text: t !== undefined ? t : defaultText
```

```suggestion
const previewData = computed(() => {
  const t = tm('t2iTemplateEditor.previewText')
  return {
    text: t ?? '这是一个示例文本,用于预览模板效果。\n\n这里可以包含多行文本,支持换行和各种格式。',
    version: previewVersion.value
  }
})
```
</issue_to_address>

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

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

  • Consider fetching the version once on dialog open and caching/reusing it rather than calling syncPreviewVersion() both on dialog open and every refreshPreview, to avoid redundant network requests.
  • The version-fetching logic (syncPreviewVersion) might be better extracted into a shared composable or service if other components also need the app version, so you don't duplicate the /api/stat/version handling in multiple places later.
  • Instead of using console.warn directly in syncPreviewVersion, consider routing errors through your existing UI notification or logging mechanism so failures are surfaced consistently to users or monitoring.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider fetching the version once on dialog open and caching/reusing it rather than calling `syncPreviewVersion()` both on `dialog` open and every `refreshPreview`, to avoid redundant network requests.
- The version-fetching logic (`syncPreviewVersion`) might be better extracted into a shared composable or service if other components also need the app version, so you don't duplicate the `/api/stat/version` handling in multiple places later.
- Instead of using `console.warn` directly in `syncPreviewVersion`, consider routing errors through your existing UI notification or logging mechanism so failures are surfaced consistently to users or monitoring.

## Individual Comments

### Comment 1
<location> `dashboard/src/components/shared/T2ITemplateEditor.vue:299-302` </location>
<code_context>
 }
+
+const previewData = computed(() => ({
+  text: tm('t2iTemplateEditor.previewText') || '这是一个示例文本,用于预览模板效果。\n\n这里可以包含多行文本,支持换行和各种格式。',
+  version: previewVersion.value 
+}))
</code_context>

<issue_to_address>
**suggestion:** Using `||` means an intentionally empty translated string will fall back to the default text.

If `tm('t2iTemplateEditor.previewText')` returns an intentionally empty string, `||` will treat it as falsy and incorrectly fall back to the default Chinese text. To only fall back when the translation is missing (undefined/null), use nullish coalescing or an explicit check, e.g.:

```ts
const t = tm('t2iTemplateEditor.previewText')
text: t ?? defaultText
// or
text: t !== undefined ? t : defaultText
```

```suggestion
const previewData = computed(() => {
  const t = tm('t2iTemplateEditor.previewText')
  return {
    text: t ?? '这是一个示例文本,用于预览模板效果。\n\n这里可以包含多行文本,支持换行和各种格式。',
    version: previewVersion.value
  }
})
```
</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.

Comment on lines +299 to +302
const previewData = computed(() => ({
text: tm('t2iTemplateEditor.previewText') || '这是一个示例文本,用于预览模板效果。\n\n这里可以包含多行文本,支持换行和各种格式。',
version: previewVersion.value
}))
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: 使用 || 会导致有意配置为空字符串的翻译也回退到默认文案。

如果 tm('t2iTemplateEditor.previewText') 返回的是一个有意设置的空字符串,|| 会把它当作 falsy,从而错误地回退到默认的中文文案。为了只在翻译缺失(undefined/null)时回退,建议使用空值合并运算符或显式判断,例如:

const t = tm('t2iTemplateEditor.previewText')
text: t ?? defaultText
// or
text: t !== undefined ? t : defaultText
Suggested change
const previewData = computed(() => ({
text: tm('t2iTemplateEditor.previewText') || '这是一个示例文本,用于预览模板效果。\n\n这里可以包含多行文本,支持换行和各种格式。',
version: previewVersion.value
}))
const previewData = computed(() => {
const t = tm('t2iTemplateEditor.previewText')
return {
text: t ?? '这是一个示例文本,用于预览模板效果。\n\n这里可以包含多行文本,支持换行和各种格式。',
version: previewVersion.value
}
})
Original comment in English

suggestion: Using || means an intentionally empty translated string will fall back to the default text.

If tm('t2iTemplateEditor.previewText') returns an intentionally empty string, || will treat it as falsy and incorrectly fall back to the default Chinese text. To only fall back when the translation is missing (undefined/null), use nullish coalescing or an explicit check, e.g.:

const t = tm('t2iTemplateEditor.previewText')
text: t ?? defaultText
// or
text: t !== undefined ? t : defaultText
Suggested change
const previewData = computed(() => ({
text: tm('t2iTemplateEditor.previewText') || '这是一个示例文本,用于预览模板效果。\n\n这里可以包含多行文本,支持换行和各种格式。',
version: previewVersion.value
}))
const previewData = computed(() => {
const t = tm('t2iTemplateEditor.previewText')
return {
text: t ?? '这是一个示例文本,用于预览模板效果。\n\n这里可以包含多行文本,支持换行和各种格式。',
version: previewVersion.value
}
})

@dosubot dosubot bot added the area:webui The bug / feature is about webui(dashboard) of astrbot. label Jan 19, 2026
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jan 20, 2026
@Soulter Soulter merged commit 978d9cb into AstrBotDevs:master Jan 20, 2026
6 checks passed
Soulter pushed a commit that referenced this pull request Jan 21, 2026
Soulter added a commit that referenced this pull request Jan 22, 2026
* feat: astr live

* chore: remove

* feat: metrics

* feat: enhance audio processing and metrics display in live mode

* feat: genie tts

* feat: enhance live mode audio processing and text handling

* feat: add metrics

* feat: eyes

* feat: nervous

* chore: update readme

Added '自动压缩对话' feature and updated features list.

* feat: skip saving head system messages in history (#4538)

* feat: skip saving the first system message in history

* fix: rename variable for clarity in system message handling

* fix: update logic to skip all system messages until the first non-system message

* fix: clarify logic for skipping initial system messages in conversation

* chore: bump version to 4.12.2

* docs: update 4.12.2 changelog

* refactor: update event types for LLM tool usage and response

* chore: bump version to 4.12.3

* fix: ensure embedding dimensions are returned as integers in providers (#4547)

* fix: ensure embedding dimensions are returned as integers in providers

* chore: ruff format

* perf: T2I template editor preview (#4574)

* feat: add file drag upload feature for ChatUI (#4583)

* feat(chat): add drag-drop upload and fix batch file upload

* style(chat): adjust drop overlay to only cover input container

* fix: streaming response for DingTalk (#4590)

closes: #4384

* #4384 钉钉消息回复卡片模板

* chore: ruff format

* chore: ruff format

---------

Co-authored-by: ManJiang <man.jiang@jg-robust.com>
Co-authored-by: Soulter <905617992@qq.com>

* feat: implement persona folder for advanced persona management (#4443)

* feat(db): add persona folder management for hierarchical organization

Implement hierarchical folder structure for organizing personas:
- Add PersonaFolder model with recursive parent-child relationships
- Add folder_id and sort_order fields to Persona model
- Implement CRUD operations for persona folders in database layer
- Add migration support for existing databases
- Extend PersonaManager with folder management methods
- Add dashboard API routes for folder operations

* feat(persona): add batch sort order update endpoint for personas and folders

Add new API endpoint POST /persona/reorder to batch update sort_order
for both personas and folders. This enables drag-and-drop reordering
in the dashboard UI.

Changes:
- Add abstract batch_update_sort_order method to BaseDatabase
- Implement batch_update_sort_order in SQLiteDatabase
- Add batch_update_sort_order to PersonaManager with cache refresh
- Add reorder_items route handler with input validation

* feat(persona): add folder_id and sort_order params to persona creation

Extend persona creation flow to support folder placement and ordering:
- Add folder_id and sort_order parameters to insert_persona in db layer
- Update PersonaManager.create_persona to accept and pass folder params
- Add get_folder_detail API endpoint for retrieving folder information
- Include folder_id and sort_order in persona creation response
- Add session flush/refresh to return complete persona object

* feat(dashboard): implement persona folder management UI

- Add folder management system with tree view and breadcrumbs
- Implement create, rename, delete, and move operations for folders
- Add drag-and-drop support for organizing personas and folders
- Create new PersonaManager component and Pinia store for state management
- Refactor PersonaPage to support hierarchical structure
- Update locale files with folder-related translations
- Handle empty parent_id correctly in backend route

* feat(dashboard): centralize folder expansion state in persona store

Move folder expansion logic from local component state to global Pinia
store to persist expansion state.
- Add `expandedFolderIds` state and toggle actions to `personaStore`
- Update `FolderTreeNode` to use store state instead of local data
- Automatically navigate to target folder after moving a persona

* feat(dashboard): add reusable folder management component library

Extract folder management UI into reusable base components and create
persona-specific wrapper components that integrate with personaStore.

- Add base folder components (tree, breadcrumb, card, dialogs) with
  customizable labels for i18n support
- Create useFolderManager composable for folder state management
- Implement drag-and-drop support for moving personas between folders
- Add persona-specific wrapper components connecting to personaStore
- Reorganize PersonaManager into views/persona directory structure
- Include comprehensive README documentation for component usage

* refactor(dashboard): remove legacy persona folder management components

Remove deprecated persona folder management Vue components that have been
superseded by the new reusable folder management component library.

Deleted components:
- CreateFolderDialog.vue
- FolderBreadcrumb.vue
- FolderCard.vue
- FolderTree.vue
- FolderTreeNode.vue
- MoveTargetNode.vue
- MoveToFolderDialog.vue
- PersonaCard.vue
- PersonaManager.vue

These components are replaced by the centralized folder management
implementation introduced in commit 3fbb3db.

* fix(dashboard): add delayed skeleton loading to prevent UI flicker

Implement a 150ms delay before showing the skeleton loader in
PersonaManager to prevent visual flicker during fast loading operations.

- Add showSkeleton state with timer-based delay mechanism
- Use v-fade-transition for smooth skeleton visibility transitions
- Clean up timer on component unmount to prevent memory leaks
- Only display skeleton when loading exceeds threshold duration

* feat(dashboard): add generic folder item selector component for persona selection

Introduce BaseFolderItemSelector.vue as a reusable component for selecting
items within folder hierarchies. Refactor PersonaSelector to use this new
base component instead of its previous flat list implementation.

Changes:
- Add BaseFolderItemSelector with folder tree navigation and item selection
- Extend folder types with SelectableItem and FolderItemSelectorLabels
- Refactor PersonaSelector to leverage the new base component
- Add i18n translations for rootFolder and emptyFolder labels

* feat(persona): add tree-view display for persona list command

Add hierarchical folder tree output for the persona list command,
showing personas organized by folders with visual tree connectors.

- Add _build_tree_output method for recursive tree structure rendering
- Display folders with 📁 icon and personas with 👤 icon
- Show root-level personas separately from folder contents
- Include total persona count in output

* refactor(persona): simplify tree-view output with shorter indentation lines

Replace complex tree connector logic with simpler depth-based indentation
using "│ " prefix. Remove unnecessary parameters (prefix, is_last) and
computed variables (has_content, total_items, item_idx) in favor of a
cleaner depth-based approach.

* feat(dashboard): add duplicate persona ID validation in create form

Add frontend validation to prevent creating personas with duplicate IDs.
Load existing persona IDs when opening the create form and validate
against them in real-time.

- Add existingPersonaIds array and loadExistingPersonaIds method
- Add validation rule to check for duplicate persona IDs
- Add i18n messages for duplicate ID error (en-US and zh-CN)
- Fix minLength validation to require at least 1 character

* i18n(persona): add createButton translation key for folder dialog

Move create button label to folder-specific translation path
instead of using generic buttons.create key.

* feat(persona): show target folder name in persona creation dialog

Add visual feedback showing which folder a new persona will be created in.

- Add info alert in PersonaForm displaying the target folder name
- Pass currentFolderName prop from PersonaManager and PersonaSelector
- Add recursive findFolderName helper to resolve folder ID to name
- Add i18n translations for createInFolder and rootFolder labels

* style:format code

* fix: remove 'persistent' attribute from dialog components

---------

Co-authored-by: Soulter <905617992@qq.com>

* perf: live mode entry

* chore: remove japanese prompt

---------

Co-authored-by: Anima-IGCenter <cacheigcrystal2@gmail.com>
Co-authored-by: Clhikari <Clhikari@qq.com>
Co-authored-by: jiangman202506 <jiangman202506@163.com>
Co-authored-by: ManJiang <man.jiang@jg-robust.com>
Co-authored-by: Ruochen Pan <67079377+RC-CHN@users.noreply.github.com>
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. lgtm This PR has been approved by a maintainer size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants