32 lines
881 B
Python
32 lines
881 B
Python
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
from typing import Any, Protocol
|
||
|
|
|
||
|
|
|
||
|
|
class CodecLike(Protocol):
|
||
|
|
def to_wire(self, event: dict[str, Any]) -> dict[str, Any]: ...
|
||
|
|
|
||
|
|
|
||
|
|
class StoreLike(Protocol):
|
||
|
|
async def persist(self, event: dict[str, Any]) -> None: ...
|
||
|
|
|
||
|
|
|
||
|
|
class BusLike(Protocol):
|
||
|
|
async def publish(self, *, session_id: str, event: dict[str, Any]) -> str: ...
|
||
|
|
|
||
|
|
|
||
|
|
class AgentScopeEventPipeline:
|
||
|
|
_codec: CodecLike
|
||
|
|
_store: StoreLike
|
||
|
|
_bus: BusLike
|
||
|
|
|
||
|
|
def __init__(self, *, codec: CodecLike, store: StoreLike, bus: BusLike) -> None:
|
||
|
|
self._codec = codec
|
||
|
|
self._store = store
|
||
|
|
self._bus = bus
|
||
|
|
|
||
|
|
async def emit(self, *, session_id: str, event: dict[str, Any]) -> str:
|
||
|
|
wire_event = self._codec.to_wire(event)
|
||
|
|
await self._store.persist(wire_event)
|
||
|
|
return await self._bus.publish(session_id=session_id, event=wire_event)
|