Coverage for src/symphra_modules/config.py: 100.00%

1"""模块配置和元数据定义."""

2

3 from dataclasses import dataclass, field

4 from datetime import datetime

5 from enum import StrEnum

6 from typing import Any

7

8

9 class ModuleState(StrEnum):

10 """模块状态枚举."""

11

12 NOT_INSTALLED = "not_installed" # 未安装

13 LOADED = "loaded" # 已加载

14 INSTALLED = "installed" # 已安装

15 STARTED = "started" # 已启动

16 STOPPED = "stopped" # 已停止

17 ERROR = "error" # 错误

18

19

20@dataclass

21 class ModuleMetadata:

22 """模块元数据."""

23

24 name: str # 模块名称

25 type: str = "module" # 模块类型

26 category: str | None = None # 模块类别，默认为未分类

27 tags: list[str] = field(default_factory=list) # 标签

28 version: str = "0.0.1" # 版本号

29 description: str = "" # 描述信息

30 author: list[dict[str, str]] = field(default_factory=list) # 作者信息

31 dependencies: list[str] = field(default_factory=list) # 必需依赖

32 optional_dependencies: list[str] = field(default_factory=list) # 可选依赖

33 config_schema: dict[str, Any] | None = None # 配置模式

34

35

36@dataclass

37 class ModuleInfo:

38 """模块信息."""

39

40 metadata: ModuleMetadata # 元数据

41 state: ModuleState = ModuleState.NOT_INSTALLED # 当前状态

42 installed_at: datetime | None = None # 安装时间

43 loaded_at: datetime | None = None # 加载时间

44 started_at: datetime | None = None # 启动时间

45 config: dict[str, Any] = field(default_factory=dict) # 当前配置