M2a:镜树域后端核心——树/节点/引文/归真/移栽全量 API 与 Kernel 完成回调(芽体固化/残答封存),8 用例钉死 PRD 场景 1/2/3/5/6/7/8

This commit is contained in:
chenxin committed 2026-08-21 23:00:07 +08:00
1 parent 1cd0069d65
commit e6a3b7121f
16 files changed
+2002 -74

No files matched your search

+42
View File
@@ -0,0 +1,42 @@
"""领域层一炁事件发射(共享绑定)。
领域服务不持有 Run 上下文时(灵胚创建、采用、归真等)经此写入事件日志;
lifespan 装配时 ``bind_event_store`` 注入进程级 EventStore。事件类型取值以
契约词典 §8.3 为准,新增先登记后使用。
"""
from __future__ import annotations
from app.services.event_store import DbEventStore
_store: DbEventStore | None = None
def bind_event_store(store: DbEventStore) -> None:
global _store
_store = store
async def emit(
event_type: str,
*,
character_id: str | None,
payload: dict,
visibility: str = "public",
run_id: str | None = None,
source: str,
) -> None:
from app.modules.runtime.events import Event
if _store is None:
return
await _store.append(
Event(
type=event_type,
source=source,
payload=payload,
visibility=visibility, # type: ignore[arg-type]
run_id=run_id,
character_id=character_id,
)
)