初始化提交

This commit is contained in:
chenxin committed 2026-08-21 16:00:13 +08:00
commit 887c1f449e
963 files changed
+166869

No files matched your search

@@ -0,0 +1,43 @@
"""沙箱事件桥接:把 SandboxEvent 转写为一炁 Event 落入 EventStore。
实现 sandbox EventSink Protocol,使 SandboxClient 发出的 tool.started / tool.completed /
tool.failed 事件自动进入一炁事件存储,无需改动客户端。
"""
from __future__ import annotations
import uuid
from app.integrations.sandbox.events import SandboxEvent
from app.modules.runtime.events import Event, EventStore
class EventStoreSink:
"""将沙箱事件适配为一炁事件并写入 EventStore。"""
def __init__(
self,
store: EventStore,
*,
run_id: str | None = None,
character_id: str | None = None,
) -> None:
self._store = store
self._run_id = run_id
self._character_id = character_id
async def emit(self, event: SandboxEvent) -> None:
await self._store.append(
Event(
id=f"event_{uuid.uuid4().hex}",
type=event.type,
source=event.source,
payload=dict(event.payload),
visibility="public",
sensitivity=event.sensitivity, # type: ignore[arg-type]
run_id=self._run_id,
character_id=self._character_id,
trace_id=event.trace_id,
created_at=event.created_at,
)
)