From b39876d795c9227494bd532cc3b29ca5a61efd1a Mon Sep 17 00:00:00 2001 From: railgun19457 Date: Fri, 26 Dec 2025 03:16:54 +0800 Subject: [PATCH 1/4] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E5=88=97=E8=A1=A8=E9=85=8D=E7=BD=AE=E6=94=AF=E6=8C=81?= =?UTF-8?q?=EF=BC=8C=E5=8C=85=E5=90=AB=E9=AA=8C=E8=AF=81=E5=92=8C=E7=BC=96?= =?UTF-8?q?=E8=BE=91=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- astrbot/core/config/astrbot_config.py | 2 + astrbot/core/config/default.py | 1 + astrbot/dashboard/routes/config.py | 31 + .../src/components/shared/AstrBotConfig.vue | 38 + .../src/components/shared/AstrBotConfigV4.vue | 8 + .../components/shared/TemplateListEditor.vue | 685 ++++++++++++++++++ .../src/i18n/locales/en-US/core/common.json | 7 +- .../src/i18n/locales/zh-CN/core/common.json | 6 + 8 files changed, 777 insertions(+), 1 deletion(-) create mode 100644 dashboard/src/components/shared/TemplateListEditor.vue diff --git a/astrbot/core/config/astrbot_config.py b/astrbot/core/config/astrbot_config.py index 9477eabaa..2208ee766 100644 --- a/astrbot/core/config/astrbot_config.py +++ b/astrbot/core/config/astrbot_config.py @@ -80,6 +80,8 @@ def _parse_schema(schema: dict, conf: dict): if v["type"] == "object": conf[k] = {} _parse_schema(v["items"], conf[k]) + elif v["type"] == "template_list": + conf[k] = default else: conf[k] = default diff --git a/astrbot/core/config/default.py b/astrbot/core/config/default.py index b45917026..4f128b998 100644 --- a/astrbot/core/config/default.py +++ b/astrbot/core/config/default.py @@ -3049,4 +3049,5 @@ class ChatProviderTemplate(TypedDict): "text": "", "list": [], "object": {}, + "template_list": [], } diff --git a/astrbot/dashboard/routes/config.py b/astrbot/dashboard/routes/config.py index f39cccfe6..09dc7b9e0 100644 --- a/astrbot/dashboard/routes/config.py +++ b/astrbot/dashboard/routes/config.py @@ -61,6 +61,37 @@ def validate(data: dict, metadata: dict = schema, path=""): if value is None: data[key] = DEFAULT_VALUE_MAP[meta["type"]] continue + if meta["type"] == "template_list": + if not isinstance(value, list): + errors.append( + f"错误的类型 {path}{key}: 期望是 list, 得到了 {type(value).__name__}", + ) + continue + templates = meta.get("templates", {}) if isinstance(meta.get("templates"), dict) else {} + for idx, item in enumerate(value): + if not isinstance(item, dict): + errors.append( + f"错误的类型 {path}{key}[{idx}]: 期望是 dict, 得到了 {type(item).__name__}", + ) + continue + template_key = item.get("__template_key") or item.get("template") + if not template_key: + errors.append( + f"缺少模板选择 {path}{key}[{idx}]: 需要 __template_key", + ) + continue + template_meta = templates.get(template_key) + if not template_meta: + errors.append( + f"未知模板 {path}{key}[{idx}]: {template_key}", + ) + continue + validate( + item, + template_meta.get("items", {}), + path=f"{path}{key}[{idx}].", + ) + continue if meta["type"] == "list" and not isinstance(value, list): errors.append( f"错误的类型 {path}{key}: 期望是 list, 得到了 {type(value).__name__}", diff --git a/dashboard/src/components/shared/AstrBotConfig.vue b/dashboard/src/components/shared/AstrBotConfig.vue index 045506b63..49cdd101c 100644 --- a/dashboard/src/components/shared/AstrBotConfig.vue +++ b/dashboard/src/components/shared/AstrBotConfig.vue @@ -6,6 +6,7 @@ import ObjectEditor from './ObjectEditor.vue' import ProviderSelector from './ProviderSelector.vue' import PersonaSelector from './PersonaSelector.vue' import KnowledgeBaseSelector from './KnowledgeBaseSelector.vue' +import TemplateListEditor from './TemplateListEditor.vue' import { useI18n } from '@/i18n/composables' import axios from 'axios' import { useToast } from '@/utils/toast' @@ -159,6 +160,30 @@ function hasVisibleItemsAfter(items, currentIndex) { + +
+
+
+ + + {{ metadata[metadataKey].items[key]?.description }} + ({{ key }}) + + {{ key }} + + + ‼️ + {{ metadata[metadataKey].items[key]?.hint }} + +
+ +
+
+