Agent: Rename IEventSerializer -> IAgentEventSerializer
This commit is contained in:
parent
ae073de766
commit
0e2b165c15
|
@ -1,5 +1,5 @@
|
||||||
from .consts import EVENT_TYPE_FIELD
|
from .consts import EVENT_TYPE_FIELD
|
||||||
from .i_event_serializer import IEventSerializer, JSONSerializable
|
from .i_event_serializer import IAgentEventSerializer, JSONSerializable
|
||||||
from .event_serializer_registry import EventSerializerRegistry
|
from .event_serializer_registry import EventSerializerRegistry
|
||||||
from .pydantic_event_serializer import PydanticEventSerializer
|
from .pydantic_event_serializer import PydanticEventSerializer
|
||||||
from .register import register_common_agent_event_serializers
|
from .register import register_common_agent_event_serializers
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from typing import Type, Union
|
from typing import Type, Union
|
||||||
|
|
||||||
from common.event_serializers import IEventSerializer
|
from common.event_serializers import IAgentEventSerializer
|
||||||
from common.events import AbstractAgentEvent
|
from common.events import AbstractAgentEvent
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,18 +22,20 @@ class EventSerializerRegistry:
|
||||||
self._registry = {}
|
self._registry = {}
|
||||||
|
|
||||||
def __setitem__(
|
def __setitem__(
|
||||||
self, event_class: Type[AbstractAgentEvent], event_serializer: IEventSerializer
|
self, event_class: Type[AbstractAgentEvent], event_serializer: IAgentEventSerializer
|
||||||
):
|
):
|
||||||
if not issubclass(event_class, AbstractAgentEvent):
|
if not issubclass(event_class, AbstractAgentEvent):
|
||||||
raise TypeError(f"Event class must be of type: {AbstractAgentEvent.__name__}")
|
raise TypeError(f"Event class must be of type: {AbstractAgentEvent.__name__}")
|
||||||
|
|
||||||
if not isinstance(event_serializer, IEventSerializer):
|
if not isinstance(event_serializer, IAgentEventSerializer):
|
||||||
raise TypeError(f"Event serializer must be of type: {IEventSerializer.__name__}")
|
raise TypeError(f"Event serializer must be of type: {IAgentEventSerializer.__name__}")
|
||||||
|
|
||||||
self._registry[event_class] = event_serializer
|
self._registry[event_class] = event_serializer
|
||||||
self._registry[event_class.__name__] = event_serializer
|
self._registry[event_class.__name__] = event_serializer
|
||||||
|
|
||||||
def __getitem__(self, event_class: Union[str, Type[AbstractAgentEvent]]) -> IEventSerializer:
|
def __getitem__(
|
||||||
|
self, event_class: Union[str, Type[AbstractAgentEvent]]
|
||||||
|
) -> IAgentEventSerializer:
|
||||||
if not (isinstance(event_class, str) or issubclass(event_class, AbstractAgentEvent)):
|
if not (isinstance(event_class, str) or issubclass(event_class, AbstractAgentEvent)):
|
||||||
raise TypeError(
|
raise TypeError(
|
||||||
f"Registry get key {event_class} must be of type: {AbstractAgentEvent.__name__} or "
|
f"Registry get key {event_class} must be of type: {AbstractAgentEvent.__name__} or "
|
||||||
|
|
|
@ -14,7 +14,7 @@ JSONSerializable = Union[ # type: ignore[misc]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class IEventSerializer(ABC):
|
class IAgentEventSerializer(ABC):
|
||||||
"""
|
"""
|
||||||
Manages serialization and deserialization of events
|
Manages serialization and deserialization of events
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -4,14 +4,14 @@ from typing import Generic, Type, TypeVar
|
||||||
from common.events import AbstractAgentEvent
|
from common.events import AbstractAgentEvent
|
||||||
from common.utils.code_utils import del_key
|
from common.utils.code_utils import del_key
|
||||||
|
|
||||||
from . import EVENT_TYPE_FIELD, IEventSerializer, JSONSerializable
|
from . import EVENT_TYPE_FIELD, IAgentEventSerializer, JSONSerializable
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
T = TypeVar("T", bound=AbstractAgentEvent)
|
T = TypeVar("T", bound=AbstractAgentEvent)
|
||||||
|
|
||||||
|
|
||||||
class PydanticEventSerializer(IEventSerializer, Generic[T]):
|
class PydanticEventSerializer(IAgentEventSerializer, Generic[T]):
|
||||||
def __init__(self, event_class: Type[T]):
|
def __init__(self, event_class: Type[T]):
|
||||||
self._event_class = event_class
|
self._event_class = event_class
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue