File tree Expand file tree Collapse file tree 3 files changed +10
-8
lines changed
agents-core/vision_agents/core Expand file tree Collapse file tree 3 files changed +10
-8
lines changed Original file line number Diff line number Diff line change 33import logging
44import time
55import uuid
6- from collections .abc import Awaitable , Callable
76from contextlib import asynccontextmanager , contextmanager
87from pathlib import Path
98from typing import (
3332)
3433from ..edge .types import Connection , Participant , TrackType , User
3534from ..events import AgentConnectionEvent , EdgeCustomEventOutboundAdapter
36- from ..events .bus import EventBus , InMemoryEventBus
35+ from ..events .bus import EventBus , EventHandler , InMemoryEventBus
3736from ..events .manager import EventManager
3837from ..instructions import Instructions
3938from ..llm import events as llm_events
@@ -1541,7 +1540,7 @@ def _register_default_outbound_adapter_if_needed(self) -> None:
15411540
15421541 def _resolve_adapter_deliver (
15431542 self , adapter : OutboundEventAdapter
1544- ) -> Callable [[ AgentConnectionEvent ], Awaitable [ None ] ]:
1543+ ) -> EventHandler [ AgentConnectionEvent ]:
15451544 deliver = getattr (adapter , "deliver" , None )
15461545 if deliver is None :
15471546 raise ValueError (
Original file line number Diff line number Diff line change 77 VideoProcessorDetectionEvent ,
88)
99from .adapters import EdgeCustomEventOutboundAdapter
10- from .bus import EventBus , InMemoryEventBus
10+ from .bus import EventBus , EventHandler , InMemoryEventBus
1111from .manager import EventManager
1212
1313__all__ = [
1717 "ConnectionState" ,
1818 "EdgeCustomEventOutboundAdapter" ,
1919 "EventBus" ,
20+ "EventHandler" ,
2021 "EventManager" ,
2122 "InMemoryEventBus" ,
2223 "PluginBaseEvent" ,
Original file line number Diff line number Diff line change 11import asyncio
2+ import inspect
23from collections .abc import Awaitable , Callable
34from typing import Generic , Protocol , TypeVar
45
56T = TypeVar ("T" )
7+ EventHandler = Callable [[T ], Awaitable [None ]]
68
79
810class EventBus (Protocol [T ]):
9- def subscribe (self , handler : Callable [[ T ], Awaitable [ None ] ]) -> None : ...
11+ def subscribe (self , handler : EventHandler [ T ]) -> None : ...
1012
1113 async def publish (self , event : T ) -> None : ...
1214
1315
1416class InMemoryEventBus (Generic [T ]):
1517 def __init__ (self ) -> None :
16- self ._handlers : list [Callable [[ T ], Awaitable [ None ] ]] = []
18+ self ._handlers : list [EventHandler [ T ]] = []
1719
18- def subscribe (self , handler : Callable [[ T ], Awaitable [ None ] ]) -> None :
19- if not asyncio .iscoroutinefunction (handler ):
20+ def subscribe (self , handler : EventHandler [ T ]) -> None :
21+ if not inspect .iscoroutinefunction (handler ):
2022 raise RuntimeError (
2123 "Handlers must be coroutines. Use async def handler(event):"
2224 )
You can’t perform that action at this time.
0 commit comments