feat: 添加动态 Tab 分组支持,优化配置界面 UI 元数据

This commit is contained in:
DrSmoothl
2026-03-07 23:13:04 +08:00
parent d3a4e3f3e7
commit b056ad2c34
5 changed files with 321 additions and 124 deletions

View File

@@ -5,7 +5,7 @@ import types
from dataclasses import dataclass, field
from pathlib import Path
from pydantic import BaseModel, ConfigDict, Field
from typing import Any, Dict, List, Literal, Set, Tuple, Union, cast, get_args, get_origin
from typing import Any, ClassVar, Dict, List, Literal, Set, Tuple, Union, cast, get_args, get_origin
__all__ = ["ConfigBase", "Field", "AttributeData"]
@@ -131,6 +131,11 @@ class ConfigBase(BaseModel, AttrDocBase):
_validate_any: bool = True # 是否验证 Any 类型的使用,默认为 True
suppress_any_warning: bool = False # 是否抑制 Any 类型使用的警告,默认为 False仅仅在_validate_any 为 False 时生效
# UI 分组元数据:子类可覆盖以声明所属 Tab 分组
__ui_parent__: ClassVar[str] = "" # 父配置类在 Config 中的字段名,空表示独立 Tab
__ui_label__: ClassVar[str] = "" # Tab 显示名称(仅做 Tab 主人时使用),空则使用 classDoc
__ui_icon__: ClassVar[str] = "" # Tab 图标名称Lucide 图标名)
@classmethod
def from_dict(cls, attribute_data: AttributeData, data: dict[str, Any]):
"""从字典创建配置对象,并收集缺失和多余的属性信息"""

View File

@@ -19,6 +19,9 @@ class ExampleConfig(ConfigBase):
class BotConfig(ConfigBase):
"""机器人配置类"""
__ui_label__ = "基本信息"
__ui_icon__ = "bot"
platform: str = Field(
default="",
json_schema_extra={
@@ -68,6 +71,9 @@ class BotConfig(ConfigBase):
class PersonalityConfig(ConfigBase):
"""人格配置类"""
__ui_label__ = "人格"
__ui_icon__ = "user-circle"
personality: str = Field(
default="是一个大二在读女大学生,现在正在上网和群友聊天,有时有点攻击性,有时比较温柔",
json_schema_extra={
@@ -160,6 +166,8 @@ class PersonalityConfig(ConfigBase):
class RelationshipConfig(ConfigBase):
"""关系配置类"""
__ui_parent__ = "debug"
enable_relationship: bool = Field(
default=True,
json_schema_extra={
@@ -190,6 +198,9 @@ class TalkRulesItem(ConfigBase):
class ChatConfig(ConfigBase):
"""聊天配置类"""
__ui_label__ = "聊天"
__ui_icon__ = "message-square"
talk_value: float = Field(
default=1,
ge=0,
@@ -293,6 +304,8 @@ class ChatConfig(ConfigBase):
class MessageReceiveConfig(ConfigBase):
"""消息接收配置类"""
__ui_parent__ = "response_post_process"
image_parse_threshold: int = Field(
default=5,
json_schema_extra={
@@ -364,6 +377,8 @@ class TargetItem(ConfigBase):
class MemoryConfig(ConfigBase):
"""记忆配置类"""
__ui_parent__ = "emoji"
max_agent_iterations: int = Field(
default=5,
ge=1,
@@ -551,6 +566,9 @@ class ExpressionGroup(ConfigBase):
class ExpressionConfig(ConfigBase):
"""表达配置类"""
__ui_label__ = "表达"
__ui_icon__ = "pen-tool"
learning_list: list[LearningItem] = Field(
default_factory=lambda: [
LearningItem(
@@ -687,6 +705,8 @@ class ExpressionConfig(ConfigBase):
class ToolConfig(ConfigBase):
"""工具配置类"""
__ui_parent__ = "emoji"
enable_tool: bool = Field(
default=False,
json_schema_extra={
@@ -700,6 +720,8 @@ class ToolConfig(ConfigBase):
class VoiceConfig(ConfigBase):
"""语音识别配置类"""
__ui_parent__ = "emoji"
enable_asr: bool = Field(
default=False,
json_schema_extra={
@@ -713,6 +735,9 @@ class VoiceConfig(ConfigBase):
class EmojiConfig(ConfigBase):
"""表情包配置类"""
__ui_label__ = "功能"
__ui_icon__ = "puzzle"
emoji_chance: float = Field(
default=0.4,
ge=0,
@@ -829,6 +854,8 @@ class KeywordRuleConfig(ConfigBase):
class KeywordReactionConfig(ConfigBase):
"""关键词配置类"""
__ui_parent__ = "response_post_process"
keyword_rules: list[KeywordRuleConfig] = Field(
default_factory=lambda: [],
json_schema_extra={
@@ -858,6 +885,9 @@ class KeywordReactionConfig(ConfigBase):
class ResponsePostProcessConfig(ConfigBase):
"""回复后处理配置类"""
__ui_label__ = "处理"
__ui_icon__ = "settings"
enable_response_post_process: bool = Field(
default=True,
json_schema_extra={
@@ -871,6 +901,8 @@ class ResponsePostProcessConfig(ConfigBase):
class ChineseTypoConfig(ConfigBase):
"""中文错别字配置类"""
__ui_parent__ = "response_post_process"
enable: bool = Field(
default=True,
json_schema_extra={
@@ -929,6 +961,8 @@ class ChineseTypoConfig(ConfigBase):
class ResponseSplitterConfig(ConfigBase):
"""回复分割器配置类"""
__ui_parent__ = "response_post_process"
enable: bool = Field(
default=True,
json_schema_extra={
@@ -978,6 +1012,8 @@ class ResponseSplitterConfig(ConfigBase):
class TelemetryConfig(ConfigBase):
"""遥测配置类"""
__ui_parent__ = "debug"
enable: bool = Field(
default=True,
json_schema_extra={
@@ -991,6 +1027,9 @@ class TelemetryConfig(ConfigBase):
class DebugConfig(ConfigBase):
"""调试配置类"""
__ui_label__ = "其他"
__ui_icon__ = "more-horizontal"
show_prompt: bool = Field(
default=False,
json_schema_extra={
@@ -1101,6 +1140,8 @@ class ExtraPromptItem(ConfigBase):
class ExperimentalConfig(ConfigBase):
"""实验功能配置类"""
__ui_parent__ = "debug"
private_plan_style: str = Field(
default=(
"1.思考**所有**的可用的action中的**每个动作**是否符合当下条件,如果动作使用条件符合聊天内容就使用"
@@ -1136,6 +1177,8 @@ class ExperimentalConfig(ConfigBase):
class MaimMessageConfig(ConfigBase):
"""maim_message配置类"""
__ui_parent__ = "debug"
ws_server_host: str = Field(
default="127.0.0.1",
json_schema_extra={
@@ -1230,6 +1273,9 @@ class MaimMessageConfig(ConfigBase):
class LPMMKnowledgeConfig(ConfigBase):
"""LPMM知识库配置类"""
__ui_label__ = "知识库"
__ui_icon__ = "book-open"
enable: bool = Field(
default=True,
json_schema_extra={
@@ -1397,6 +1443,9 @@ class LPMMKnowledgeConfig(ConfigBase):
class DreamConfig(ConfigBase):
"""Dream配置类"""
__ui_label__ = "做梦"
__ui_icon__ = "moon"
interval_minutes: int = Field(
default=30,
ge=1,
@@ -1467,6 +1516,9 @@ class DreamConfig(ConfigBase):
class WebUIConfig(ConfigBase):
"""WebUI配置类"""
__ui_label__ = "WebUI"
__ui_icon__ = "layout"
enabled: bool = Field(
default=True,
json_schema_extra={
@@ -1543,6 +1595,8 @@ class WebUIConfig(ConfigBase):
class DatabaseConfig(ConfigBase):
"""数据库配置类"""
__ui_parent__ = "debug"
save_binary_data: bool = Field(
default=False,
json_schema_extra={