Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions cdp_use/generator/registry_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def generate_registry(self, domains: List[Dict[str, Any]]) -> str:
content += ' logger.debug(f"Unregistering handler for {method}")\n'
content += " self._handlers.pop(method, None)\n\n"

content += " def handle_event(\n"
content += " async def handle_event(\n"
content += " self,\n"
content += " method: str,\n"
content += " params: Any,\n"
Expand All @@ -75,7 +75,15 @@ def generate_registry(self, domains: List[Dict[str, Any]]) -> str:
content += ' """\n'
content += " if method in self._handlers:\n"
content += " try:\n"
content += " self._handlers[method](params, session_id)\n"
content += " import inspect\n"
content += " handler = self._handlers[method]\n\n"
content += " # Check if handler is async\n"
content += " if inspect.iscoroutinefunction(handler):\n"
content += " # Await async handlers\n"
content += " await handler(params, session_id)\n"
content += " else:\n"
content += " # Call sync handlers directly\n"
content += " handler(params, session_id)\n"
content += " return True\n"
content += " except Exception as e:\n"
content += ' logger.error(f"Error in event handler for {method}: {e}")\n'
Expand Down