From cafbf1509854fa49bac0dbc3f30c50c03028c746 Mon Sep 17 00:00:00 2001 From: JarbasAI <33701864+JarbasAl@users.noreply.github.com> Date: Sun, 29 Dec 2024 02:41:08 +0000 Subject: [PATCH 1/3] feat: add client callbacks (#5) --- hivemind_plugin_manager/protocols.py | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/hivemind_plugin_manager/protocols.py b/hivemind_plugin_manager/protocols.py index 0a3f971..5f3bed4 100644 --- a/hivemind_plugin_manager/protocols.py +++ b/hivemind_plugin_manager/protocols.py @@ -1,7 +1,7 @@ import abc import dataclasses from dataclasses import dataclass -from typing import Dict, Any, Union, Optional +from typing import Dict, Any, Union, Optional, Callable from ovos_bus_client import MessageBusClient from ovos_utils.fakebus import FakeBus @@ -10,11 +10,33 @@ from hivemind_bus_client.identity import NodeIdentity +def on_disconnect(client: 'HiveMindClientConnection'): + LOG.debug(f"callback: client disconnected: {client}") + +def on_connect(client: 'HiveMindClientConnection'): + LOG.debug(f"callback: client connected: {client}") + +def on_invalid_key(client: 'HiveMindClientConnection'): + LOG.debug(f"callback: invalid access key: {client}") + +def on_invalid_protocol(client: 'HiveMindClientConnection'): + LOG.debug(f"callback: protocol requirements failure: {client}") + + +@dataclass +class ClientCallbacks: + on_connect: Callable[['HiveMindClientConnection'], None] = on_connect + on_disconnect: Callable[['HiveMindClientConnection'], None] = on_disconnect + on_invalid_key: Callable[['HiveMindClientConnection'], None] = on_invalid_key + on_invalid_protocol: Callable[['HiveMindClientConnection'], None] = on_invalid_protocol + + @dataclass class _SubProtocol: """base class all protocols derive from""" config: Dict[str, Any] = dataclasses.field(default_factory=dict) hm_protocol: Optional['HiveMindListenerProtocol'] = None + callbacks: ClientCallbacks = dataclasses.field(default_factory=ClientCallbacks) @property def identity(self) -> NodeIdentity: @@ -42,13 +64,14 @@ class AgentProtocol(_SubProtocol): config: Dict[str, Any] = dataclasses.field(default_factory=dict) hm_protocol: Optional['HiveMindListenerProtocol'] = None # usually AgentProtocol is passed as kwarg to hm_protocol # and only then assigned in hm_protocol.__post_init__ - + callbacks: ClientCallbacks = dataclasses.field(default_factory=ClientCallbacks) @dataclass class NetworkProtocol(_SubProtocol): """protocol to transport HiveMessage objects around""" config: Dict[str, Any] = dataclasses.field(default_factory=dict) hm_protocol: Optional['HiveMindListenerProtocol'] = None + callbacks: ClientCallbacks = dataclasses.field(default_factory=ClientCallbacks) @property def agent_protocol(self) -> Optional['AgentProtocol']: @@ -68,6 +91,7 @@ class BinaryDataHandlerProtocol(_SubProtocol): hm_protocol: Optional['HiveMindListenerProtocol'] = None # usually BinaryDataHandlerProtocol is passed as kwarg to hm_protocol # and only then assigned in hm_protocol.__post_init__ agent_protocol: Optional['AgentProtocol'] = None + callbacks: ClientCallbacks = dataclasses.field(default_factory=ClientCallbacks) def __post_init__(self): # NOTE: the most common scenario is having self.agent_protocol but not having self.hm_protocol yet From 498671494e96ab9a358b2cbee9748de5235f1f42 Mon Sep 17 00:00:00 2001 From: JarbasAl Date: Sun, 29 Dec 2024 02:41:22 +0000 Subject: [PATCH 2/3] Increment Version to 0.2.0a1 --- hivemind_plugin_manager/version.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hivemind_plugin_manager/version.py b/hivemind_plugin_manager/version.py index cbb1e3f..d446f48 100644 --- a/hivemind_plugin_manager/version.py +++ b/hivemind_plugin_manager/version.py @@ -1,6 +1,6 @@ # START_VERSION_BLOCK VERSION_MAJOR = 0 -VERSION_MINOR = 1 +VERSION_MINOR = 2 VERSION_BUILD = 0 -VERSION_ALPHA = 0 +VERSION_ALPHA = 1 # END_VERSION_BLOCK From 3a52b3e56aab79a1ef93bc1e1343b8f0e807e1d4 Mon Sep 17 00:00:00 2001 From: JarbasAl Date: Sun, 29 Dec 2024 02:41:45 +0000 Subject: [PATCH 3/3] Update Changelog --- CHANGELOG.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a40f9b..07fbc73 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,12 @@ # Changelog -## [0.1.0a1](https://github.com/JarbasHiveMind/hivemind-plugin-manager/tree/0.1.0a1) (2024-12-29) +## [0.2.0a1](https://github.com/JarbasHiveMind/hivemind-plugin-manager/tree/0.2.0a1) (2024-12-29) -[Full Changelog](https://github.com/JarbasHiveMind/hivemind-plugin-manager/compare/0.0.2...0.1.0a1) +[Full Changelog](https://github.com/JarbasHiveMind/hivemind-plugin-manager/compare/0.1.0...0.2.0a1) **Merged pull requests:** -- feat: add plugin factory classes [\#3](https://github.com/JarbasHiveMind/hivemind-plugin-manager/pull/3) ([JarbasAl](https://github.com/JarbasAl)) +- feat: add client callbacks [\#5](https://github.com/JarbasHiveMind/hivemind-plugin-manager/pull/5) ([JarbasAl](https://github.com/JarbasAl))