From b1a648004b412827cb36c2a004e90728a5f9742b Mon Sep 17 00:00:00 2001 From: Maplemx Date: Thu, 24 Oct 2024 12:20:29 +0800 Subject: [PATCH] update: automatically use realtime when add "realtime" events --- Agently/plugins/agent_component/EventListener.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Agently/plugins/agent_component/EventListener.py b/Agently/plugins/agent_component/EventListener.py index a7960a5..9a9c560 100644 --- a/Agently/plugins/agent_component/EventListener.py +++ b/Agently/plugins/agent_component/EventListener.py @@ -13,7 +13,10 @@ def __init__(self, agent: object): def add(self, event:str, listener: callable, *, is_await:bool=False, is_agent_event:bool=False): event = event.replace(".", "->") + if event == "realtime": + self.agent.settings.set("use_realtime", True) if event.startswith("realtime:"): + self.agent.settings.set("use_realtime", True) event_data = event.replace(" ", "").split(":") hooks = event_data[1].replace("->", ".").split("&") hook_list = [] @@ -55,8 +58,8 @@ async def realtime_hook_handler(data): await listener(data) else: listener(data) - if event not in (self.listeners.get(trace_back=False) or {}): - self.listeners.update(event, []) + if "realtime" not in (self.listeners.get(trace_back=False) or {}): + self.listeners.update("realtime", []) self.listeners.append("realtime", { "listener": realtime_hook_handler, "is_await": is_await }) else: if is_agent_event: @@ -83,6 +86,7 @@ def on_finally(self, listener: callable, *, is_await:bool=False, is_agent_event: return self.agent def on_realtime(self, listener: callable, *, is_await:bool=False, is_agent_event:bool=False): + self.agent.settings.set("use_realtime", True) self.add("realtime", listener, is_await=is_await, is_agent_event=is_agent_event) return self.agent