mirror of https://github.com/Mai-with-u/MaiBot.git
更新插件系统文档和配置类型定义
parent
dccdc7eaff
commit
0b87b32480
|
|
@ -11,6 +11,9 @@ from .base import (
|
|||
BaseCommand,
|
||||
BaseTool,
|
||||
ConfigField,
|
||||
ConfigSection,
|
||||
ConfigLayout,
|
||||
ConfigTab,
|
||||
ComponentType,
|
||||
ActionActivationType,
|
||||
ChatMode,
|
||||
|
|
@ -116,6 +119,9 @@ __all__ = [
|
|||
# 装饰器
|
||||
"register_plugin",
|
||||
"ConfigField",
|
||||
"ConfigSection",
|
||||
"ConfigLayout",
|
||||
"ConfigTab",
|
||||
# 工具函数
|
||||
"ManifestValidator",
|
||||
"get_logger",
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ from .component_types import (
|
|||
ForwardNode,
|
||||
ReplySetModel,
|
||||
)
|
||||
from .config_types import ConfigField
|
||||
from .config_types import ConfigField, ConfigSection, ConfigLayout, ConfigTab
|
||||
|
||||
__all__ = [
|
||||
"BasePlugin",
|
||||
|
|
@ -46,6 +46,9 @@ __all__ = [
|
|||
"PluginInfo",
|
||||
"PythonDependency",
|
||||
"ConfigField",
|
||||
"ConfigSection",
|
||||
"ConfigLayout",
|
||||
"ConfigTab",
|
||||
"EventHandlerInfo",
|
||||
"EventType",
|
||||
"BaseEventHandler",
|
||||
|
|
|
|||
|
|
@ -70,6 +70,12 @@ class ConfigField:
|
|||
depends_on: Optional[str] = None # 依赖的字段路径,如 "section.field"
|
||||
depends_value: Any = None # 依赖字段需要的值(当依赖字段等于此值时显示)
|
||||
|
||||
# === 列表类型专用 ===
|
||||
item_type: Optional[str] = None # 数组元素类型: "string", "number", "object"
|
||||
item_fields: Optional[Dict[str, Any]] = None # 当 item_type="object" 时,定义对象的字段结构
|
||||
min_items: Optional[int] = None # 数组最小元素数量
|
||||
max_items: Optional[int] = None # 数组最大元素数量
|
||||
|
||||
def get_ui_type(self) -> str:
|
||||
"""
|
||||
获取 UI 控件类型
|
||||
|
|
@ -132,6 +138,10 @@ class ConfigField:
|
|||
"group": self.group,
|
||||
"depends_on": self.depends_on,
|
||||
"depends_value": self.depends_value,
|
||||
"item_type": self.item_type,
|
||||
"item_fields": self.item_fields,
|
||||
"min_items": self.min_items,
|
||||
"max_items": self.max_items,
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1401,12 +1401,34 @@ async def get_plugin_config_schema(
|
|||
# 推断字段类型
|
||||
field_type = type(field_value).__name__
|
||||
ui_type = "text"
|
||||
item_type = None
|
||||
item_fields = None
|
||||
|
||||
if isinstance(field_value, bool):
|
||||
ui_type = "switch"
|
||||
elif isinstance(field_value, (int, float)):
|
||||
ui_type = "number"
|
||||
elif isinstance(field_value, list):
|
||||
ui_type = "list"
|
||||
# 推断数组元素类型
|
||||
if field_value:
|
||||
first_item = field_value[0]
|
||||
if isinstance(first_item, dict):
|
||||
item_type = "object"
|
||||
# 从第一个元素推断字段结构
|
||||
item_fields = {}
|
||||
for k, v in first_item.items():
|
||||
item_fields[k] = {
|
||||
"type": "number" if isinstance(v, (int, float)) else "string",
|
||||
"label": k,
|
||||
"default": "" if isinstance(v, str) else 0,
|
||||
}
|
||||
elif isinstance(first_item, (int, float)):
|
||||
item_type = "number"
|
||||
else:
|
||||
item_type = "string"
|
||||
else:
|
||||
item_type = "string"
|
||||
elif isinstance(field_value, dict):
|
||||
ui_type = "json"
|
||||
|
||||
|
|
@ -1421,6 +1443,26 @@ async def get_plugin_config_schema(
|
|||
"hidden": False,
|
||||
"disabled": False,
|
||||
"order": 0,
|
||||
"item_type": item_type,
|
||||
"item_fields": item_fields,
|
||||
"min_items": None,
|
||||
"max_items": None,
|
||||
# 补充缺失的字段
|
||||
"placeholder": None,
|
||||
"hint": None,
|
||||
"icon": None,
|
||||
"example": None,
|
||||
"choices": None,
|
||||
"min": None,
|
||||
"max": None,
|
||||
"step": None,
|
||||
"pattern": None,
|
||||
"max_length": None,
|
||||
"input_type": None,
|
||||
"rows": 3,
|
||||
"group": None,
|
||||
"depends_on": None,
|
||||
"depends_value": None,
|
||||
}
|
||||
|
||||
return {"success": True, "schema": schema}
|
||||
|
|
|
|||
Loading…
Reference in New Issue