"""领域层一炁事件发射(共享绑定)。 领域服务不持有 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, ) )