@@ -47,7 +47,7 @@ class MyPlugin:
4747 def __init__ (self ):
4848 # EventManager is automatically available
4949 self .events = EventManager()
50-
50+
5151 # Register your custom events
5252 self .events.register_events_from_module(events)
5353```
@@ -121,7 +121,7 @@ class MyValidatedEvent(PluginBaseEvent):
121121 type : str = field(default = ' plugin.myplugin.validated' , init = False )
122122 text: str = " "
123123 confidence: float = 0.0
124-
124+
125125 def __post_init__ (self ):
126126 if not self .text:
127127 raise ValueError (" Text cannot be empty" )
@@ -160,17 +160,17 @@ class MyPlugin:
160160 message = " Processing started" ,
161161 data = data
162162 ))
163-
163+
164164 # Do processing
165165 result = await self ._process(data)
166-
166+
167167 # Emit success event
168168 self .events.send(MyPluginEvent(
169169 plugin_name = " myplugin" ,
170170 message = " Processing completed" ,
171171 data = result
172172 ))
173-
173+
174174 except Exception as e:
175175 # Emit error event
176176 self .events.send(MyPluginErrorEvent(
@@ -205,21 +205,21 @@ class MyPlugin:
205205 super ().__init__ ()
206206 self .events.register_events_from_module(events)
207207 self ._setup_event_handlers()
208-
208+
209209 def _setup_event_handlers (self ):
210210 """ Set up event handlers for the plugin."""
211-
211+
212212 @self.events.subscribe
213213 async def handle_stt_transcript (event : STTTranscriptEvent):
214214 """ Handle speech-to-text transcripts."""
215215 if event.is_final:
216216 await self ._process_transcript(event.text)
217-
217+
218218 @self.events.subscribe
219219 async def handle_llm_response (event : LLMResponseEvent):
220220 """ Handle LLM responses."""
221221 await self ._process_llm_response(event.text)
222-
222+
223223 @self.events.subscribe
224224 async def handle_error_events (event : MyPluginErrorEvent | STTErrorEvent):
225225 """ Handle error events."""
@@ -268,16 +268,16 @@ class MyPlugin(PluginBase):
268268 super ().__init__ ()
269269 # Register custom events
270270 self .events.register_events_from_module(events)
271-
271+
272272 async def process (self , data ):
273273 # Send custom events
274274 self .events.send(events.MyPluginStartEvent(
275275 plugin_name = " myplugin" ,
276276 config = self .config
277277 ))
278-
278+
279279 result = await self ._process_data(data)
280-
280+
281281 self .events.send(events.MyPluginDataEvent(
282282 plugin_name = " myplugin" ,
283283 data = result,
@@ -296,21 +296,21 @@ class SimpleSTT(STT):
296296 def __init__ (self ):
297297 super ().__init__ ()
298298 # No need to register custom events - use base class events
299-
299+
300300 async def transcribe (self , audio_data : bytes ) -> str :
301301 try :
302302 result = await self ._call_api(audio_data)
303-
303+
304304 # Send base class event
305305 self .events.send(STTTranscriptEvent(
306306 plugin_name = " simple_stt" ,
307307 text = result.text,
308308 confidence = result.confidence,
309309 is_final = True
310310 ))
311-
311+
312312 return result.text
313-
313+
314314 except Exception as e:
315315 # Send error event
316316 self .events.send(STTErrorEvent(
@@ -332,32 +332,32 @@ class MyAgent(Agent):
332332 def __init__ (self , ** kwargs ):
333333 super ().__init__ (** kwargs)
334334 self ._setup_agent_handlers()
335-
335+
336336 def _setup_agent_handlers (self ):
337337 @self.events.subscribe
338338 async def handle_agent_say (event : AgentSayEvent):
339339 """ Handle when agent wants to say something."""
340340 print (f " Agent wants to say: { event.text} " )
341-
341+
342342 # Process the speech request
343343 await self ._process_speech_request(event)
344-
344+
345345 # Three ways to send events:
346-
346+
347347 # Method 1: Direct event sending
348348 def send_custom_event (self , data ):
349349 self .events.send(MyCustomEvent(
350350 plugin_name = " agent" ,
351351 data = data
352352 ))
353-
353+
354354 # Method 2: Convenience method
355355 def send_event_convenience (self , data ):
356356 self .send(MyCustomEvent(
357357 plugin_name = " agent" ,
358358 data = data
359359 ))
360-
360+
361361 # Method 3: High-level speech
362362 async def make_agent_speak (self , text ):
363363 await self .say(text, metadata = {" source" : " custom_handler" })
@@ -423,7 +423,7 @@ class ValidatedEvent(PluginBaseEvent):
423423 type : str = field(default = ' plugin.myplugin.validated' , init = False )
424424 text: str = " "
425425 confidence: float = 0.0
426-
426+
427427 def __post_init__ (self ):
428428 if not self .text.strip():
429429 raise ValueError (" Text cannot be empty" )
@@ -440,20 +440,20 @@ from my_plugin import MyPlugin
440440@pytest.mark.asyncio
441441async def test_plugin_events ():
442442 plugin = MyPlugin()
443-
443+
444444 # Track events
445445 events_received = []
446-
446+
447447 @plugin.events.subscribe
448448 async def track_events (event ):
449449 events_received.append(event)
450-
450+
451451 # Trigger event
452452 await plugin.process_data(" test" )
453-
453+
454454 # Wait for events
455455 await plugin.events.wait()
456-
456+
457457 # Verify events
458458 assert len (events_received) > 0
459459 assert any (isinstance (e, MyPluginEvent) for e in events_received)
@@ -483,15 +483,15 @@ class OpenAILLM(LLM):
483483 super ().__init__ ()
484484 self .events.register_events_from_module(events)
485485 self .model = model
486-
486+
487487 def _standardize_and_emit_event (self , event : ResponseStreamEvent):
488488 # Send raw OpenAI event
489489 self .events.send(events.OpenAIStreamEvent(
490490 plugin_name = " openai" ,
491491 event_type = event.type,
492492 event_data = event
493493 ))
494-
494+
495495 if event.type == " response.error" :
496496 self .events.send(events.LLMErrorEvent(
497497 plugin_name = " openai" ,
@@ -519,10 +519,10 @@ class Realtime(realtime.Realtime):
519519 def __init__ (self , ** kwargs ):
520520 super ().__init__ (** kwargs)
521521 self .events.register_events_from_module(events)
522-
522+
523523 async def connect (self ):
524524 # ... connection logic ...
525-
525+
526526 # Emit connection event
527527 self .events.send(events.GeminiConnectedEvent(
528528 plugin_name = " gemini" ,
0 commit comments