From 351ce77147ac7e84ca3a266e71019d758b03e0d5 Mon Sep 17 00:00:00 2001 From: Sjshi763 Date: Mon, 2 Feb 2026 14:53:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E6=A0=BC=E5=BC=8F=E5=AF=BC=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../i18n/locales/en-US/features/persona.json | 3 +- .../i18n/locales/zh-CN/features/persona.json | 3 +- .../src/views/persona/PersonaManager.vue | 29 ++++++++++++++----- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/dashboard/src/i18n/locales/en-US/features/persona.json b/dashboard/src/i18n/locales/en-US/features/persona.json index 6ff936883..44736f449 100644 --- a/dashboard/src/i18n/locales/en-US/features/persona.json +++ b/dashboard/src/i18n/locales/en-US/features/persona.json @@ -93,7 +93,8 @@ "messages": { "moveSuccess": "Persona moved successfully", "moveError": "Failed to move persona", - "exportSuccess": "Exported successfully(excluding skills and tools)" + "exportSuccess": "Exported successfully(excluding skills and tools)", + "importSuccess": "Imported successfully" } }, "folder": { diff --git a/dashboard/src/i18n/locales/zh-CN/features/persona.json b/dashboard/src/i18n/locales/zh-CN/features/persona.json index b0dfa4079..652aff833 100644 --- a/dashboard/src/i18n/locales/zh-CN/features/persona.json +++ b/dashboard/src/i18n/locales/zh-CN/features/persona.json @@ -93,7 +93,8 @@ "messages": { "moveSuccess": "人格移动成功", "moveError": "移动人格失败", - "exportSuccess": "导出成功(不包含 Skills 和工具)" + "exportSuccess": "导出成功(不包含 Skills 和工具)", + "importSuccess": "导入成功" } }, "folder": { diff --git a/dashboard/src/views/persona/PersonaManager.vue b/dashboard/src/views/persona/PersonaManager.vue index 63d4c9889..29d83e633 100644 --- a/dashboard/src/views/persona/PersonaManager.vue +++ b/dashboard/src/views/persona/PersonaManager.vue @@ -541,23 +541,36 @@ export default defineComponent({ const text = await file.text(); const data = JSON.parse(text); - // 白名单过滤 - const whitelist = ['persona_id', 'system_prompt', 'begin_dialogs', 'tools', 'skills', 'folder_id']; - const filteredData: any = {}; + let importData: any = {}; - for (const key of whitelist) { - if (key in data) { - filteredData[key] = data[key]; + if (data.version && data.persona && Array.isArray(data.persona)) { + const firstPersona = data.persona[0]; + importData = { + persona_id: firstPersona.name, + system_prompt: firstPersona.prompt, + begin_dialogs: [] + }; + + // 转换对话对 + if (firstPersona.begin_dialogs && Array.isArray(firstPersona.begin_dialogs)) { + for (const dialog of firstPersona.begin_dialogs) { + if (dialog.user) { + importData.begin_dialogs.push(dialog.user); + } + if (dialog.assistant) { + importData.begin_dialogs.push(dialog.assistant); + } + } } } // 验证必需字段 - if (!filteredData.persona_id || !filteredData.system_prompt) { + if (!importData.persona_id || !importData.system_prompt) { throw new Error(this.tm('persona.messages.importMissingFields')); } // 执行导入 - await this.importPersona(filteredData); + await this.importPersona(importData); this.showSuccess(this.tm('persona.messages.importSuccess')); } catch (error: any) { console.error(this.tm('persona.messages.importFailed'), error);