Files

43 lines
1.4 KiB
Python

"""Profile:一次 Run 的插件装配清单与参数包。
层叠顺序(产品 PRD §9.2 / lingtai-runtime.md §4.2):
平台硬边界 → 平台目录 → 用户偏好/BYOK → 人物覆写 → 镜树临时选择。
M0 只有平台目录层;后续里程碑逐层接入。Profile 快照写入事件日志,保证可回放。
"""
from __future__ import annotations
from dataclasses import dataclass, field
from typing import Any
@dataclass(frozen=True)
class ProfileLayer:
"""层叠中的一层:来源标识 + 参数(后者覆盖前者同键)。"""
source: str
params: dict[str, Any] = field(default_factory=dict)
_PLATFORM_LAYER = ProfileLayer(source="platform", params={"slot": "chat"})
@dataclass(frozen=True)
class Profile:
"""解析后的最终装配:插件名列表 + 合并参数。"""
plugins: tuple[str, ...] = ()
params: dict[str, Any] = field(default_factory=dict)
def snapshot(self) -> dict[str, Any]:
"""写入 context.projected 事件的快照视图。"""
return {"plugins": list(self.plugins), "params": dict(self.params)}
def resolve_profile(layers: list[ProfileLayer] | None = None) -> Profile:
"""层叠解析:平台层恒在最底,逐层覆盖参数;M0 无插件装配。"""
merged: dict[str, Any] = {}
for layer in [_PLATFORM_LAYER, *(layers or [])]:
merged.update(layer.params)
return Profile(plugins=(), params=merged)