From e95ad4049b600236afb1016de97017cc38a088bf Mon Sep 17 00:00:00 2001 From: Soulter <37870767+Soulter@users.noreply.github.com> Date: Sun, 17 Aug 2025 23:24:30 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=20WebUI=20=E8=BF=81?= =?UTF-8?q?=E7=A7=BB=E5=8A=A9=E6=89=8B=E4=BB=A5=E5=8F=8A=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E8=BF=81=E7=A7=BB=E6=96=B9=E6=B3=95=20(#2477)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- astrbot/core/core_lifecycle.py | 6 - astrbot/core/db/migration/helper.py | 8 +- astrbot/core/persona_mgr.py | 3 + astrbot/dashboard/routes/stat.py | 4 + astrbot/dashboard/routes/update.py | 17 ++ .../src/components/shared/MigrationDialog.vue | 275 ++++++++++++++++++ dashboard/src/i18n/loader.ts | 1 + .../locales/en-US/features/migration.json | 16 + .../i18n/locales/en-US/features/settings.json | 5 + .../locales/zh-CN/features/migration.json | 16 + .../i18n/locales/zh-CN/features/settings.json | 5 + dashboard/src/i18n/translations.ts | 8 +- dashboard/src/layouts/full/FullLayout.vue | 34 +++ dashboard/src/views/Settings.vue | 45 ++- 14 files changed, 415 insertions(+), 28 deletions(-) create mode 100644 dashboard/src/components/shared/MigrationDialog.vue create mode 100644 dashboard/src/i18n/locales/en-US/features/migration.json create mode 100644 dashboard/src/i18n/locales/zh-CN/features/migration.json diff --git a/astrbot/core/core_lifecycle.py b/astrbot/core/core_lifecycle.py index 71fb772b6..d50955cd1 100644 --- a/astrbot/core/core_lifecycle.py +++ b/astrbot/core/core_lifecycle.py @@ -34,7 +34,6 @@ from astrbot.core.platform_message_history_mgr import PlatformMessageHistoryMana from astrbot.core.astrbot_config_mgr import AstrBotConfigManager from astrbot.core.star.star_handler import star_handlers_registry, EventType from astrbot.core.star.star_handler import star_map -from astrbot.core.db.migration.helper import do_migration_v4 class AstrBotCoreLifecycle: @@ -72,11 +71,6 @@ class AstrBotCoreLifecycle: await self.db.initialize() - try: - await do_migration_v4(self.db, {}, self.astrbot_config) - except Exception as e: - logger.error(f"迁移到 v4.0.0 新版本数据格式失败: {e}") - # 初始化 AstrBot 配置管理器 self.astrbot_config_mgr = AstrBotConfigManager( default_config=self.astrbot_config, sp=sp diff --git a/astrbot/core/db/migration/helper.py b/astrbot/core/db/migration/helper.py index 4eb428153..4ac075a8d 100644 --- a/astrbot/core/db/migration/helper.py +++ b/astrbot/core/db/migration/helper.py @@ -43,14 +43,14 @@ async def do_migration_v4( # 执行会话表迁移 await migration_conversation_table(db_helper, platform_id_map) - # 执行平台统计表迁移 - await migration_platform_table(db_helper, platform_id_map) + # 执行人格数据迁移 + await migration_persona_data(db_helper, astrbot_config) # 执行 WebChat 数据迁移 await migration_webchat_data(db_helper, platform_id_map) - # 执行人格数据迁移 - await migration_persona_data(db_helper, astrbot_config) + # 执行平台统计表迁移 + await migration_platform_table(db_helper, platform_id_map) # 标记迁移完成 await db_helper.insert_preference_or_update("migration_done_v4", "true") diff --git a/astrbot/core/persona_mgr.py b/astrbot/core/persona_mgr.py index 81e1f9f34..a01106607 100644 --- a/astrbot/core/persona_mgr.py +++ b/astrbot/core/persona_mgr.py @@ -7,8 +7,11 @@ from astrbot import logger DEFAULT_PERSONALITY = Personality( prompt="You are a helpful and friendly assistant.", name="default", + begin_dialogs=[], + mood_imitation_dialogs=[], tools=None, _begin_dialogs_processed=[], + _mood_imitation_dialogs_processed="", ) diff --git a/astrbot/dashboard/routes/stat.py b/astrbot/dashboard/routes/stat.py index 1890002c7..d13eb802c 100644 --- a/astrbot/dashboard/routes/stat.py +++ b/astrbot/dashboard/routes/stat.py @@ -11,6 +11,7 @@ from astrbot.core.db import BaseDatabase from astrbot.core.config import VERSION from astrbot.core.utils.io import get_dashboard_version from astrbot.core import DEMO_MODE +from astrbot.core.db.migration.helper import check_migration_needed_v4 class StatRoute(Route): @@ -59,6 +60,8 @@ class StatRoute(Route): ) async def get_version(self): + need_migration = await check_migration_needed_v4(self.core_lifecycle.db) + return ( Response() .ok( @@ -66,6 +69,7 @@ class StatRoute(Route): "version": VERSION, "dashboard_version": await get_dashboard_version(), "change_pwd_hint": self.is_default_cred(), + "need_migration": need_migration, } ) .__dict__ diff --git a/astrbot/dashboard/routes/update.py b/astrbot/dashboard/routes/update.py index f88e9a208..595a79037 100644 --- a/astrbot/dashboard/routes/update.py +++ b/astrbot/dashboard/routes/update.py @@ -7,6 +7,7 @@ from astrbot.core import logger, pip_installer from astrbot.core.utils.io import download_dashboard, get_dashboard_version from astrbot.core.config.default import VERSION from astrbot.core import DEMO_MODE +from astrbot.core.db.migration.helper import do_migration_v4, check_migration_needed_v4 class UpdateRoute(Route): @@ -23,11 +24,27 @@ class UpdateRoute(Route): "/update/do": ("POST", self.update_project), "/update/dashboard": ("POST", self.update_dashboard), "/update/pip-install": ("POST", self.install_pip_package), + "/update/migration": ("POST", self.do_migration), } self.astrbot_updator = astrbot_updator self.core_lifecycle = core_lifecycle self.register_routes() + async def do_migration(self): + need_migration = await check_migration_needed_v4(self.core_lifecycle.db) + if not need_migration: + return Response().ok(None, "不需要进行迁移。").__dict__ + try: + data = await request.json + pim = data.get("platform_id_map", {}) + await do_migration_v4( + self.core_lifecycle.db, pim, self.core_lifecycle.astrbot_config + ) + return Response().ok(None, "迁移成功。").__dict__ + except Exception as e: + logger.error(f"迁移失败: {traceback.format_exc()}") + return Response().error(f"迁移失败: {str(e)}").__dict__ + async def check_update(self): type_ = request.args.get("type", None) diff --git a/dashboard/src/components/shared/MigrationDialog.vue b/dashboard/src/components/shared/MigrationDialog.vue new file mode 100644 index 000000000..6bbf7b362 --- /dev/null +++ b/dashboard/src/components/shared/MigrationDialog.vue @@ -0,0 +1,275 @@ + + + + + {{ t('features.migration.dialog.title') }} + + + + {{ t('features.migration.dialog.warning') }} + + + + mdi-check-circle + {{ t('features.migration.dialog.completed') }} + {{ migrationResult?.message || t('features.migration.dialog.success') }} + + + + + + {{ t('features.migration.dialog.migrating') }} + {{ t('features.migration.dialog.migratingSubtitle') }} + + + + + + + + + {{ t('features.migration.dialog.loading') }} + + + + + + mdi-alert + + {{ error }} + + + {{ t('features.migration.dialog.retry') }} + + + + + + + + mdi-information + + {{ t('features.migration.dialog.noPlatforms') }} + + + + + + + + {{ group.type }} + + + + + + 请选择该平台类型下您主要使用的平台适配器。 + + + + + + + + + + + + + + + {{ t('core.common.confirm') }} + + + + + {{ t('core.common.cancel') }} + + + {{ t('features.migration.dialog.startMigration') }} + + + + + + + + + + diff --git a/dashboard/src/i18n/loader.ts b/dashboard/src/i18n/loader.ts index ec76b2c0c..4ea2ce4d9 100644 --- a/dashboard/src/i18n/loader.ts +++ b/dashboard/src/i18n/loader.ts @@ -53,6 +53,7 @@ export class I18nLoader { { name: 'features/alkaid/knowledge-base', path: 'features/alkaid/knowledge-base.json' }, { name: 'features/alkaid/memory', path: 'features/alkaid/memory.json' }, { name: 'features/persona', path: 'features/persona.json' }, + { name: 'features/migration', path: 'features/migration.json' }, // 消息模块 { name: 'messages/errors', path: 'messages/errors.json' }, diff --git a/dashboard/src/i18n/locales/en-US/features/migration.json b/dashboard/src/i18n/locales/en-US/features/migration.json new file mode 100644 index 000000000..c87b770b3 --- /dev/null +++ b/dashboard/src/i18n/locales/en-US/features/migration.json @@ -0,0 +1,16 @@ +{ + "dialog": { + "title": "Database Migration Assistant", + "warning": "A database migration is required.", + "loading": "Loading platform list...", + "loadError": "Failed to load platform list, please retry", + "noPlatforms": "No available platform configurations found", + "retry": "Retry", + "startMigration": "Start Migration", + "migrating": "Migrating...", + "migratingSubtitle": "Please wait patiently, do not close this window during migration", + "migrationError": "Migration failed", + "success": "Migration completed successfully!", + "completed": "Migration Completed" + } +} diff --git a/dashboard/src/i18n/locales/en-US/features/settings.json b/dashboard/src/i18n/locales/en-US/features/settings.json index 584c7d0cf..e8ae3cbf2 100644 --- a/dashboard/src/i18n/locales/en-US/features/settings.json +++ b/dashboard/src/i18n/locales/en-US/features/settings.json @@ -13,6 +13,11 @@ "title": "Restart", "subtitle": "Restart AstrBot", "button": "Restart" + }, + "migration": { + "title": "Data Migration to v4.0.0", + "subtitle": "If you encounter data compatibility issues, you can manually start the database migration assistant", + "button": "Start Migration Assistant" } } } \ No newline at end of file diff --git a/dashboard/src/i18n/locales/zh-CN/features/migration.json b/dashboard/src/i18n/locales/zh-CN/features/migration.json new file mode 100644 index 000000000..a34af8475 --- /dev/null +++ b/dashboard/src/i18n/locales/zh-CN/features/migration.json @@ -0,0 +1,16 @@ +{ + "dialog": { + "title": "数据迁移助手", + "warning": "👋 欢迎升级到 v4.0.0。我们在新版本对数据格式进行了优化,检测到需要进行数据库迁移。", + "loading": "正在加载平台列表...", + "loadError": "加载平台列表失败,请重试", + "noPlatforms": "未找到可用的平台配置", + "retry": "重试", + "startMigration": "开始迁移", + "migrating": "正在迁移中...", + "migratingSubtitle": "请耐心等待,迁移过程中请勿关闭此窗口", + "migrationError": "迁移失败", + "success": "迁移成功完成!", + "completed": "迁移已完成" + } +} diff --git a/dashboard/src/i18n/locales/zh-CN/features/settings.json b/dashboard/src/i18n/locales/zh-CN/features/settings.json index e925a02db..f8ea8520b 100644 --- a/dashboard/src/i18n/locales/zh-CN/features/settings.json +++ b/dashboard/src/i18n/locales/zh-CN/features/settings.json @@ -13,6 +13,11 @@ "title": "重启", "subtitle": "重启 AstrBot", "button": "重启" + }, + "migration": { + "title": "数据迁移到 v4.0.0 格式", + "subtitle": "如果您遇到数据兼容性问题,可以手动启动数据库迁移助手", + "button": "启动迁移助手" } } } \ No newline at end of file diff --git a/dashboard/src/i18n/translations.ts b/dashboard/src/i18n/translations.ts index f5ea8c97e..168edd5e5 100644 --- a/dashboard/src/i18n/translations.ts +++ b/dashboard/src/i18n/translations.ts @@ -26,6 +26,7 @@ import zhCNAlkaidIndex from './locales/zh-CN/features/alkaid/index.json'; import zhCNAlkaidKnowledgeBase from './locales/zh-CN/features/alkaid/knowledge-base.json'; import zhCNAlkaidMemory from './locales/zh-CN/features/alkaid/memory.json'; import zhCNPersona from './locales/zh-CN/features/persona.json'; +import zhCNMigration from './locales/zh-CN/features/migration.json'; import zhCNErrors from './locales/zh-CN/messages/errors.json'; import zhCNSuccess from './locales/zh-CN/messages/success.json'; @@ -56,6 +57,7 @@ import enUSAlkaidIndex from './locales/en-US/features/alkaid/index.json'; import enUSAlkaidKnowledgeBase from './locales/en-US/features/alkaid/knowledge-base.json'; import enUSAlkaidMemory from './locales/en-US/features/alkaid/memory.json'; import enUSPersona from './locales/en-US/features/persona.json'; +import enUSMigration from './locales/en-US/features/migration.json'; import enUSErrors from './locales/en-US/messages/errors.json'; import enUSSuccess from './locales/en-US/messages/success.json'; @@ -91,7 +93,8 @@ export const translations = { 'knowledge-base': zhCNAlkaidKnowledgeBase, memory: zhCNAlkaidMemory }, - persona: zhCNPersona + persona: zhCNPersona, + migration: zhCNMigration }, messages: { errors: zhCNErrors, @@ -127,7 +130,8 @@ export const translations = { 'knowledge-base': enUSAlkaidKnowledgeBase, memory: enUSAlkaidMemory }, - persona: enUSPersona + persona: enUSPersona, + migration: enUSMigration }, messages: { errors: enUSErrors, diff --git a/dashboard/src/layouts/full/FullLayout.vue b/dashboard/src/layouts/full/FullLayout.vue index a0754cafd..e12098588 100644 --- a/dashboard/src/layouts/full/FullLayout.vue +++ b/dashboard/src/layouts/full/FullLayout.vue @@ -1,9 +1,40 @@ @@ -20,6 +51,9 @@ const customizer = useCustomizerStore(); + + + diff --git a/dashboard/src/views/Settings.vue b/dashboard/src/views/Settings.vue index 77ad4ea1f..6cbdf93a4 100644 --- a/dashboard/src/views/Settings.vue +++ b/dashboard/src/views/Settings.vue @@ -14,35 +14,48 @@ {{ tm('system.restart.button') }} + + + {{ tm('system.migration.button') }} + + - \ No newline at end of file
{{ t('features.migration.dialog.warning') }}
{{ t('features.migration.dialog.migratingSubtitle') }}
{{ t('features.migration.dialog.loading') }}