hivemind-ovos-agent-plugin 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2024 Casimiro Ferreira
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,106 @@
1
+ Metadata-Version: 2.4
2
+ Name: hivemind-ovos-agent-plugin
3
+ Version: 0.1.0
4
+ Summary: OVOS agent protocol plugin for HiveMind-core
5
+ Author-email: jarbasAi <jarbasai@mailfence.com>
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/JarbasHiveMind/hivemind-ovos-agent-plugin
8
+ Project-URL: Issues, https://github.com/JarbasHiveMind/hivemind-ovos-agent-plugin/issues
9
+ Requires-Python: >=3.10
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE.md
12
+ Requires-Dist: ovos-bus-client<2.0.0,>=1.3.1
13
+ Requires-Dist: ovos-config<3.0.0,>=0.0.12
14
+ Requires-Dist: ovos-utils<1.0.0,>=0.8.2
15
+ Requires-Dist: hivemind-bus-client<1.0.0,>=0.7.0a2
16
+ Requires-Dist: hivemind-plugin-manager<1.0.0,>=0.3.0
17
+ Requires-Dist: pyee<13.0.0,>=8.1.0
18
+ Provides-Extra: test
19
+ Requires-Dist: pytest; extra == "test"
20
+ Requires-Dist: pytest-cov; extra == "test"
21
+ Dynamic: license-file
22
+
23
+ # HiveMind OVOS Agent Plugin
24
+
25
+ OVOS agent protocol plugin for [HiveMind-core](https://github.com/JarbasHiveMind/HiveMind-core).
26
+
27
+ Bridges HiveMind client messages to an [OpenVoiceOS](https://github.com/OpenVoiceOS) message bus.
28
+ HiveMind clients connect to a `hivemind-core` listener, and this plugin forwards their
29
+ Mycroft `Message` payloads to a local OVOS bus (and routes OVOS responses back to the
30
+ originating client).
31
+
32
+ ## Installation
33
+
34
+ ```bash
35
+ pip install hivemind-ovos-agent-plugin
36
+ ```
37
+
38
+ Or from source:
39
+
40
+ ```bash
41
+ git clone https://github.com/JarbasHiveMind/hivemind-ovos-agent-plugin
42
+ cd hivemind-ovos-agent-plugin
43
+ pip install -e .
44
+ ```
45
+
46
+ ## Usage
47
+
48
+ The plugin registers itself as a HiveMind agent protocol via the
49
+ `hivemind.agent.protocol` entry point group, with name `hivemind-ovos-agent-plugin`.
50
+
51
+ In your `hivemind-core` configuration:
52
+
53
+ ```json
54
+ {
55
+ "agent_protocol": {
56
+ "hivemind-ovos-agent-plugin": {
57
+ "host": "127.0.0.1",
58
+ "port": 8181
59
+ }
60
+ }
61
+ }
62
+ ```
63
+
64
+ `hivemind-core` will discover the plugin via its entry point and instantiate the
65
+ `OVOSAgentProtocol` class with the supplied config. The plugin connects to the OVOS
66
+ message bus at the given host/port (defaulting to `127.0.0.1:8181`).
67
+
68
+ ### Direct programmatic use
69
+
70
+ ```python
71
+ from hivemind_ovos_agent_plugin import OVOSAgentProtocol
72
+
73
+ agent = OVOSAgentProtocol(config={"host": "127.0.0.1", "port": 8181})
74
+ # pass `agent` to your HiveMindListenerProtocol
75
+ ```
76
+
77
+ ## How it works
78
+
79
+ The plugin owns two callbacks on the OVOS bus:
80
+
81
+ - **`hive.send.downstream`** — emitted by OVOS components that want to push a
82
+ `HiveMessage` to a connected HiveMind client. The plugin wraps the payload in a
83
+ `HiveMessage` and dispatches it to the right peer, or fans it out for
84
+ `PROPAGATE`/`BROADCAST` types.
85
+ - **`message`** (catch-all) — every internal OVOS bus message is inspected. If its
86
+ `context["destination"]` lists a connected HiveMind peer, the plugin forwards it back
87
+ to that peer wrapped as a `HiveMessageType.BUS` message. This is where **client
88
+ isolation** is enforced: a client never sees responses meant for another client.
89
+
90
+ Upstream traffic (client → OVOS bus) is handled by `hivemind-core` itself; this plugin
91
+ only handles the downstream half.
92
+
93
+
94
+ ## Documentation
95
+
96
+ Full developer documentation lives in [`docs/`](docs/):
97
+
98
+ - [`docs/architecture.md`](docs/architecture.md) — how the plugin fits between HiveMind
99
+ and OVOS.
100
+ - [`docs/configuration.md`](docs/configuration.md) — every config knob.
101
+ - [`docs/message_flow.md`](docs/message_flow.md) — end-to-end message lifecycle.
102
+ - [`docs/development.md`](docs/development.md) — running tests, releasing.
103
+
104
+ ## License
105
+
106
+ Apache 2.0. See [LICENSE.md](LICENSE.md).
@@ -0,0 +1,84 @@
1
+ # HiveMind OVOS Agent Plugin
2
+
3
+ OVOS agent protocol plugin for [HiveMind-core](https://github.com/JarbasHiveMind/HiveMind-core).
4
+
5
+ Bridges HiveMind client messages to an [OpenVoiceOS](https://github.com/OpenVoiceOS) message bus.
6
+ HiveMind clients connect to a `hivemind-core` listener, and this plugin forwards their
7
+ Mycroft `Message` payloads to a local OVOS bus (and routes OVOS responses back to the
8
+ originating client).
9
+
10
+ ## Installation
11
+
12
+ ```bash
13
+ pip install hivemind-ovos-agent-plugin
14
+ ```
15
+
16
+ Or from source:
17
+
18
+ ```bash
19
+ git clone https://github.com/JarbasHiveMind/hivemind-ovos-agent-plugin
20
+ cd hivemind-ovos-agent-plugin
21
+ pip install -e .
22
+ ```
23
+
24
+ ## Usage
25
+
26
+ The plugin registers itself as a HiveMind agent protocol via the
27
+ `hivemind.agent.protocol` entry point group, with name `hivemind-ovos-agent-plugin`.
28
+
29
+ In your `hivemind-core` configuration:
30
+
31
+ ```json
32
+ {
33
+ "agent_protocol": {
34
+ "hivemind-ovos-agent-plugin": {
35
+ "host": "127.0.0.1",
36
+ "port": 8181
37
+ }
38
+ }
39
+ }
40
+ ```
41
+
42
+ `hivemind-core` will discover the plugin via its entry point and instantiate the
43
+ `OVOSAgentProtocol` class with the supplied config. The plugin connects to the OVOS
44
+ message bus at the given host/port (defaulting to `127.0.0.1:8181`).
45
+
46
+ ### Direct programmatic use
47
+
48
+ ```python
49
+ from hivemind_ovos_agent_plugin import OVOSAgentProtocol
50
+
51
+ agent = OVOSAgentProtocol(config={"host": "127.0.0.1", "port": 8181})
52
+ # pass `agent` to your HiveMindListenerProtocol
53
+ ```
54
+
55
+ ## How it works
56
+
57
+ The plugin owns two callbacks on the OVOS bus:
58
+
59
+ - **`hive.send.downstream`** — emitted by OVOS components that want to push a
60
+ `HiveMessage` to a connected HiveMind client. The plugin wraps the payload in a
61
+ `HiveMessage` and dispatches it to the right peer, or fans it out for
62
+ `PROPAGATE`/`BROADCAST` types.
63
+ - **`message`** (catch-all) — every internal OVOS bus message is inspected. If its
64
+ `context["destination"]` lists a connected HiveMind peer, the plugin forwards it back
65
+ to that peer wrapped as a `HiveMessageType.BUS` message. This is where **client
66
+ isolation** is enforced: a client never sees responses meant for another client.
67
+
68
+ Upstream traffic (client → OVOS bus) is handled by `hivemind-core` itself; this plugin
69
+ only handles the downstream half.
70
+
71
+
72
+ ## Documentation
73
+
74
+ Full developer documentation lives in [`docs/`](docs/):
75
+
76
+ - [`docs/architecture.md`](docs/architecture.md) — how the plugin fits between HiveMind
77
+ and OVOS.
78
+ - [`docs/configuration.md`](docs/configuration.md) — every config knob.
79
+ - [`docs/message_flow.md`](docs/message_flow.md) — end-to-end message lifecycle.
80
+ - [`docs/development.md`](docs/development.md) — running tests, releasing.
81
+
82
+ ## License
83
+
84
+ Apache 2.0. See [LICENSE.md](LICENSE.md).
@@ -0,0 +1,101 @@
1
+ import dataclasses
2
+ from typing import Dict, Any
3
+
4
+ from ovos_bus_client import MessageBusClient
5
+ from ovos_bus_client.message import Message
6
+ from ovos_config import Configuration
7
+ from ovos_utils.fakebus import FakeBus
8
+ from ovos_utils.log import LOG
9
+ from pyee import EventEmitter
10
+
11
+ from hivemind_bus_client.message import HiveMessage, HiveMessageType
12
+ from hivemind_plugin_manager.protocols import AgentProtocol
13
+
14
+ from hivemind_ovos_agent_plugin.version import __version__
15
+
16
+
17
+ @dataclasses.dataclass()
18
+ class OVOSAgentProtocol(AgentProtocol):
19
+ """HiveMind agent protocol that bridges client messages to an OVOS bus."""
20
+ bus: MessageBusClient = dataclasses.field(default_factory=FakeBus)
21
+ config: Dict[str, Any] = dataclasses.field(default_factory=lambda: Configuration().get("websocket", {}))
22
+
23
+ def __post_init__(self):
24
+ if not self.bus or isinstance(self.bus, FakeBus):
25
+ ovos_bus_address = self.config.get("host") or "127.0.0.1"
26
+ ovos_bus_port = self.config.get("port") or 8181
27
+ self.bus = MessageBusClient(
28
+ host=ovos_bus_address,
29
+ port=ovos_bus_port,
30
+ emitter=EventEmitter(),
31
+ )
32
+ self.bus.run_in_thread()
33
+ self.bus.connected_event.wait()
34
+ self.register_bus_handlers()
35
+
36
+ def register_bus_handlers(self):
37
+ LOG.debug("registering internal OVOS bus handlers")
38
+ self.bus.on("hive.send.downstream", self.handle_send)
39
+ self.bus.on("message", self.handle_internal_mycroft) # catch all
40
+
41
+ # mycroft handlers - from master -> slave
42
+ def handle_send(self, message: Message):
43
+ """ovos wants to send a HiveMessage.
44
+
45
+ A device can be both a master and a slave; downstream messages are handled here.
46
+ HiveMindSlaveInternalProtocol handles requests meant to go upstream.
47
+ """
48
+ payload = message.data.get("payload")
49
+ peer = message.data.get("peer")
50
+ msg_type = message.data["msg_type"]
51
+
52
+ hmessage = HiveMessage(msg_type, payload=payload, target_peers=[peer])
53
+
54
+ if msg_type in [HiveMessageType.PROPAGATE, HiveMessageType.BROADCAST]:
55
+ for peer in self.clients:
56
+ self.clients[peer].send(hmessage)
57
+ elif msg_type == HiveMessageType.ESCALATE:
58
+ # only slaves can escalate, ignore silently
59
+ pass
60
+ elif peer:
61
+ if peer in self.clients:
62
+ client = self.clients[peer]
63
+ client.send(hmessage)
64
+ else:
65
+ LOG.error("That client is not connected")
66
+ self.bus.emit(
67
+ message.forward(
68
+ "hive.client.send.error",
69
+ {"error": "That client is not connected", "peer": peer},
70
+ )
71
+ )
72
+
73
+ def handle_internal_mycroft(self, message: str):
74
+ """Forward internal messages to clients if they are the target.
75
+
76
+ Client isolation happens here: clients only get responses to their own messages.
77
+ """
78
+ message = Message.deserialize(message)
79
+ target_peers = message.context.get("destination") or []
80
+ if not isinstance(target_peers, list):
81
+ target_peers = [target_peers]
82
+
83
+ if target_peers:
84
+ for peer, client in self.clients.items():
85
+ if peer in target_peers:
86
+ LOG.debug(f"{message.msg_type} - destination: {peer}")
87
+ message.context["source"] = "hive"
88
+ msg = HiveMessage(
89
+ HiveMessageType.BUS,
90
+ source_peer=peer,
91
+ target_peers=target_peers,
92
+ payload=message,
93
+ )
94
+ client.send(msg)
95
+
96
+
97
+ # back-compat alias for the old class name shipped from ovos-bus-client
98
+ OVOSProtocol = OVOSAgentProtocol
99
+
100
+
101
+ __all__ = ["OVOSAgentProtocol", "OVOSProtocol", "__version__"]
@@ -0,0 +1,8 @@
1
+ # START_VERSION_BLOCK
2
+ VERSION_MAJOR = 0
3
+ VERSION_MINOR = 1
4
+ VERSION_BUILD = 0
5
+ VERSION_ALPHA = 0
6
+ # END_VERSION_BLOCK
7
+
8
+ __version__ = f"{VERSION_MAJOR}.{VERSION_MINOR}.{VERSION_BUILD}" + (f"a{VERSION_ALPHA}" if VERSION_ALPHA else "")
@@ -0,0 +1,106 @@
1
+ Metadata-Version: 2.4
2
+ Name: hivemind-ovos-agent-plugin
3
+ Version: 0.1.0
4
+ Summary: OVOS agent protocol plugin for HiveMind-core
5
+ Author-email: jarbasAi <jarbasai@mailfence.com>
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/JarbasHiveMind/hivemind-ovos-agent-plugin
8
+ Project-URL: Issues, https://github.com/JarbasHiveMind/hivemind-ovos-agent-plugin/issues
9
+ Requires-Python: >=3.10
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE.md
12
+ Requires-Dist: ovos-bus-client<2.0.0,>=1.3.1
13
+ Requires-Dist: ovos-config<3.0.0,>=0.0.12
14
+ Requires-Dist: ovos-utils<1.0.0,>=0.8.2
15
+ Requires-Dist: hivemind-bus-client<1.0.0,>=0.7.0a2
16
+ Requires-Dist: hivemind-plugin-manager<1.0.0,>=0.3.0
17
+ Requires-Dist: pyee<13.0.0,>=8.1.0
18
+ Provides-Extra: test
19
+ Requires-Dist: pytest; extra == "test"
20
+ Requires-Dist: pytest-cov; extra == "test"
21
+ Dynamic: license-file
22
+
23
+ # HiveMind OVOS Agent Plugin
24
+
25
+ OVOS agent protocol plugin for [HiveMind-core](https://github.com/JarbasHiveMind/HiveMind-core).
26
+
27
+ Bridges HiveMind client messages to an [OpenVoiceOS](https://github.com/OpenVoiceOS) message bus.
28
+ HiveMind clients connect to a `hivemind-core` listener, and this plugin forwards their
29
+ Mycroft `Message` payloads to a local OVOS bus (and routes OVOS responses back to the
30
+ originating client).
31
+
32
+ ## Installation
33
+
34
+ ```bash
35
+ pip install hivemind-ovos-agent-plugin
36
+ ```
37
+
38
+ Or from source:
39
+
40
+ ```bash
41
+ git clone https://github.com/JarbasHiveMind/hivemind-ovos-agent-plugin
42
+ cd hivemind-ovos-agent-plugin
43
+ pip install -e .
44
+ ```
45
+
46
+ ## Usage
47
+
48
+ The plugin registers itself as a HiveMind agent protocol via the
49
+ `hivemind.agent.protocol` entry point group, with name `hivemind-ovos-agent-plugin`.
50
+
51
+ In your `hivemind-core` configuration:
52
+
53
+ ```json
54
+ {
55
+ "agent_protocol": {
56
+ "hivemind-ovos-agent-plugin": {
57
+ "host": "127.0.0.1",
58
+ "port": 8181
59
+ }
60
+ }
61
+ }
62
+ ```
63
+
64
+ `hivemind-core` will discover the plugin via its entry point and instantiate the
65
+ `OVOSAgentProtocol` class with the supplied config. The plugin connects to the OVOS
66
+ message bus at the given host/port (defaulting to `127.0.0.1:8181`).
67
+
68
+ ### Direct programmatic use
69
+
70
+ ```python
71
+ from hivemind_ovos_agent_plugin import OVOSAgentProtocol
72
+
73
+ agent = OVOSAgentProtocol(config={"host": "127.0.0.1", "port": 8181})
74
+ # pass `agent` to your HiveMindListenerProtocol
75
+ ```
76
+
77
+ ## How it works
78
+
79
+ The plugin owns two callbacks on the OVOS bus:
80
+
81
+ - **`hive.send.downstream`** — emitted by OVOS components that want to push a
82
+ `HiveMessage` to a connected HiveMind client. The plugin wraps the payload in a
83
+ `HiveMessage` and dispatches it to the right peer, or fans it out for
84
+ `PROPAGATE`/`BROADCAST` types.
85
+ - **`message`** (catch-all) — every internal OVOS bus message is inspected. If its
86
+ `context["destination"]` lists a connected HiveMind peer, the plugin forwards it back
87
+ to that peer wrapped as a `HiveMessageType.BUS` message. This is where **client
88
+ isolation** is enforced: a client never sees responses meant for another client.
89
+
90
+ Upstream traffic (client → OVOS bus) is handled by `hivemind-core` itself; this plugin
91
+ only handles the downstream half.
92
+
93
+
94
+ ## Documentation
95
+
96
+ Full developer documentation lives in [`docs/`](docs/):
97
+
98
+ - [`docs/architecture.md`](docs/architecture.md) — how the plugin fits between HiveMind
99
+ and OVOS.
100
+ - [`docs/configuration.md`](docs/configuration.md) — every config knob.
101
+ - [`docs/message_flow.md`](docs/message_flow.md) — end-to-end message lifecycle.
102
+ - [`docs/development.md`](docs/development.md) — running tests, releasing.
103
+
104
+ ## License
105
+
106
+ Apache 2.0. See [LICENSE.md](LICENSE.md).
@@ -0,0 +1,15 @@
1
+ LICENSE.md
2
+ README.md
3
+ pyproject.toml
4
+ hivemind_ovos_agent_plugin/__init__.py
5
+ hivemind_ovos_agent_plugin/version.py
6
+ hivemind_ovos_agent_plugin.egg-info/PKG-INFO
7
+ hivemind_ovos_agent_plugin.egg-info/SOURCES.txt
8
+ hivemind_ovos_agent_plugin.egg-info/dependency_links.txt
9
+ hivemind_ovos_agent_plugin.egg-info/entry_points.txt
10
+ hivemind_ovos_agent_plugin.egg-info/requires.txt
11
+ hivemind_ovos_agent_plugin.egg-info/top_level.txt
12
+ tests/test_bus_registration.py
13
+ tests/test_handle_send.py
14
+ tests/test_import.py
15
+ tests/test_isolation.py
@@ -0,0 +1,2 @@
1
+ [hivemind.agent.protocol]
2
+ hivemind-ovos-agent-plugin = hivemind_ovos_agent_plugin:OVOSAgentProtocol
@@ -0,0 +1,10 @@
1
+ ovos-bus-client<2.0.0,>=1.3.1
2
+ ovos-config<3.0.0,>=0.0.12
3
+ ovos-utils<1.0.0,>=0.8.2
4
+ hivemind-bus-client<1.0.0,>=0.7.0a2
5
+ hivemind-plugin-manager<1.0.0,>=0.3.0
6
+ pyee<13.0.0,>=8.1.0
7
+
8
+ [test]
9
+ pytest
10
+ pytest-cov
@@ -0,0 +1 @@
1
+ hivemind_ovos_agent_plugin
@@ -0,0 +1,42 @@
1
+ [build-system]
2
+ requires = ["setuptools>=42", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "hivemind-ovos-agent-plugin"
7
+ dynamic = ["version"]
8
+ description = "OVOS agent protocol plugin for HiveMind-core"
9
+ license = { text = "Apache-2.0" }
10
+ readme = "README.md"
11
+ authors = [
12
+ { name = "jarbasAi", email = "jarbasai@mailfence.com" }
13
+ ]
14
+ requires-python = ">=3.10"
15
+ dependencies = [
16
+ "ovos-bus-client>=1.3.1,<2.0.0",
17
+ "ovos-config>=0.0.12,<3.0.0",
18
+ "ovos-utils>=0.8.2,<1.0.0",
19
+ "hivemind-bus-client>=0.7.0a2,<1.0.0",
20
+ "hivemind-plugin-manager>=0.3.0,<1.0.0",
21
+ "pyee>=8.1.0,<13.0.0",
22
+ ]
23
+
24
+ [project.optional-dependencies]
25
+ test = [
26
+ "pytest",
27
+ "pytest-cov",
28
+ ]
29
+
30
+ [project.urls]
31
+ Homepage = "https://github.com/JarbasHiveMind/hivemind-ovos-agent-plugin"
32
+ Issues = "https://github.com/JarbasHiveMind/hivemind-ovos-agent-plugin/issues"
33
+
34
+ [project.entry-points."hivemind.agent.protocol"]
35
+ "hivemind-ovos-agent-plugin" = "hivemind_ovos_agent_plugin:OVOSAgentProtocol"
36
+
37
+ [tool.setuptools.dynamic]
38
+ version = { attr = "hivemind_ovos_agent_plugin.version.__version__" }
39
+
40
+ [tool.setuptools.packages.find]
41
+ where = ["."]
42
+ include = ["hivemind_ovos_agent_plugin*"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,20 @@
1
+ """Verify the plugin registers the expected handlers on the OVOS bus."""
2
+
3
+ from hivemind_ovos_agent_plugin import OVOSAgentProtocol
4
+
5
+
6
+ class TestBusRegistration:
7
+ def test_registers_hive_send_downstream(self, agent, fake_bus):
8
+ # FakeBus stores listeners on its internal emitter
9
+ listeners = fake_bus.ee.listeners("hive.send.downstream")
10
+ assert any(l.__func__ is OVOSAgentProtocol.handle_send for l in listeners) or \
11
+ any(getattr(l, "__name__", "") == "handle_send" for l in listeners)
12
+
13
+ def test_registers_catch_all_message_listener(self, agent, fake_bus):
14
+ listeners = fake_bus.ee.listeners("message")
15
+ assert any(getattr(l, "__name__", "") == "handle_internal_mycroft" for l in listeners) or \
16
+ any(l.__func__ is OVOSAgentProtocol.handle_internal_mycroft for l in listeners)
17
+
18
+ def test_bus_field_is_kept(self, agent, fake_bus):
19
+ """The bus the plugin operates on is the one we wired in."""
20
+ assert agent.bus is fake_bus
@@ -0,0 +1,80 @@
1
+ """Tests for OVOSAgentProtocol.handle_send (downstream dispatch from OVOS bus)."""
2
+
3
+ from ovos_bus_client.message import Message
4
+ from hivemind_bus_client.message import HiveMessage, HiveMessageType
5
+
6
+
7
+ def _send_msg(msg_type, peer=None, payload=None):
8
+ """Helper to build the ovos Message that triggers handle_send."""
9
+ return Message("hive.send.downstream", {
10
+ "msg_type": msg_type,
11
+ "peer": peer,
12
+ "payload": payload,
13
+ })
14
+
15
+
16
+ class TestHandleSendDirect:
17
+ def test_dispatch_to_connected_peer(self, agent, make_client):
18
+ peer = "ws://1.2.3.4:5678"
19
+ client = make_client(peer)
20
+ agent.hm_protocol.clients = {peer: client}
21
+
22
+ agent.handle_send(_send_msg(HiveMessageType.BUS, peer=peer, payload={"x": 1}))
23
+
24
+ client.send.assert_called_once()
25
+ sent = client.send.call_args[0][0]
26
+ assert isinstance(sent, HiveMessage)
27
+ assert sent.msg_type == HiveMessageType.BUS
28
+
29
+ def test_unknown_peer_emits_error_on_bus(self, agent, make_client, fake_bus):
30
+ seen = []
31
+ fake_bus.on("hive.client.send.error", lambda m: seen.append(m))
32
+
33
+ agent.hm_protocol.clients = {} # nobody connected
34
+ agent.handle_send(_send_msg(HiveMessageType.BUS, peer="ws://missing:1234", payload={}))
35
+
36
+ assert len(seen) == 1
37
+ assert seen[0].data["peer"] == "ws://missing:1234"
38
+ assert "not connected" in seen[0].data["error"].lower()
39
+
40
+ def test_no_peer_no_dispatch(self, agent, make_client):
41
+ c1 = make_client("ws://a")
42
+ c2 = make_client("ws://b")
43
+ agent.hm_protocol.clients = {"ws://a": c1, "ws://b": c2}
44
+
45
+ # msg_type that isn't propagate/broadcast/escalate, with peer=None
46
+ agent.handle_send(_send_msg(HiveMessageType.BUS, peer=None, payload={}))
47
+
48
+ c1.send.assert_not_called()
49
+ c2.send.assert_not_called()
50
+
51
+
52
+ class TestHandleSendFanout:
53
+ def test_propagate_fans_out_to_all(self, agent, make_client):
54
+ peers = [f"ws://{i}" for i in range(3)]
55
+ clients = {p: make_client(p) for p in peers}
56
+ agent.hm_protocol.clients = clients
57
+
58
+ agent.handle_send(_send_msg(HiveMessageType.PROPAGATE, peer=peers[0], payload={}))
59
+
60
+ for c in clients.values():
61
+ c.send.assert_called_once()
62
+
63
+ def test_broadcast_fans_out_to_all(self, agent, make_client):
64
+ peers = [f"ws://{i}" for i in range(3)]
65
+ clients = {p: make_client(p) for p in peers}
66
+ agent.hm_protocol.clients = clients
67
+
68
+ agent.handle_send(_send_msg(HiveMessageType.BROADCAST, peer=peers[0], payload={}))
69
+
70
+ for c in clients.values():
71
+ c.send.assert_called_once()
72
+
73
+ def test_escalate_is_silently_ignored(self, agent, make_client):
74
+ c = make_client("ws://a")
75
+ agent.hm_protocol.clients = {"ws://a": c}
76
+
77
+ agent.handle_send(_send_msg(HiveMessageType.ESCALATE, peer="ws://a", payload={}))
78
+
79
+ # ESCALATE goes upstream, not downstream — no client should be sent to
80
+ c.send.assert_not_called()
@@ -0,0 +1,36 @@
1
+ """Sanity tests: public surface and version."""
2
+
3
+ import hivemind_ovos_agent_plugin as pkg
4
+
5
+
6
+ def test_public_class_exported():
7
+ assert hasattr(pkg, "OVOSAgentProtocol")
8
+
9
+
10
+ def test_backcompat_alias_exists():
11
+ """The old name shipped by ovos-bus-client[hivemind] must still resolve."""
12
+ assert pkg.OVOSProtocol is pkg.OVOSAgentProtocol
13
+
14
+
15
+ def test_version_string():
16
+ assert isinstance(pkg.__version__, str)
17
+ assert pkg.__version__.split(".")[0].isdigit()
18
+
19
+
20
+ def test_is_agent_protocol_subclass():
21
+ from hivemind_plugin_manager.protocols import AgentProtocol
22
+ assert issubclass(pkg.OVOSAgentProtocol, AgentProtocol)
23
+
24
+
25
+ def test_entry_point_registered():
26
+ """The plugin must be discoverable via the hivemind.agent.protocol entry point."""
27
+ try:
28
+ from importlib.metadata import entry_points
29
+ except ImportError: # pragma: no cover
30
+ from importlib_metadata import entry_points # type: ignore
31
+
32
+ eps = entry_points()
33
+ # python 3.10+ select API
34
+ group = eps.select(group="hivemind.agent.protocol") if hasattr(eps, "select") else eps.get("hivemind.agent.protocol", [])
35
+ names = {ep.name for ep in group}
36
+ assert "hivemind-ovos-agent-plugin" in names
@@ -0,0 +1,73 @@
1
+ """Client isolation invariant: a client must only receive messages targeted at it."""
2
+
3
+ from ovos_bus_client.message import Message
4
+ from hivemind_bus_client.message import HiveMessageType
5
+
6
+
7
+ def _ovos_internal(msg_type, destination=None, data=None):
8
+ """Build the serialized JSON that handle_internal_mycroft expects."""
9
+ msg = Message(msg_type, data or {}, {"destination": destination} if destination is not None else {})
10
+ return msg.serialize()
11
+
12
+
13
+ class TestClientIsolation:
14
+ def test_message_addressed_to_one_client_only_reaches_that_client(self, agent, make_client):
15
+ alice = make_client("ws://alice")
16
+ bob = make_client("ws://bob")
17
+ agent.hm_protocol.clients = {"ws://alice": alice, "ws://bob": bob}
18
+
19
+ agent.handle_internal_mycroft(_ovos_internal("speak", destination="ws://alice", data={"utterance": "hi"}))
20
+
21
+ alice.send.assert_called_once()
22
+ bob.send.assert_not_called()
23
+
24
+ def test_destination_can_be_a_list(self, agent, make_client):
25
+ alice = make_client("ws://alice")
26
+ bob = make_client("ws://bob")
27
+ carol = make_client("ws://carol")
28
+ agent.hm_protocol.clients = {"ws://alice": alice, "ws://bob": bob, "ws://carol": carol}
29
+
30
+ agent.handle_internal_mycroft(_ovos_internal("speak", destination=["ws://alice", "ws://bob"]))
31
+
32
+ alice.send.assert_called_once()
33
+ bob.send.assert_called_once()
34
+ carol.send.assert_not_called()
35
+
36
+ def test_message_with_no_destination_is_dropped(self, agent, make_client):
37
+ alice = make_client("ws://alice")
38
+ bob = make_client("ws://bob")
39
+ agent.hm_protocol.clients = {"ws://alice": alice, "ws://bob": bob}
40
+
41
+ agent.handle_internal_mycroft(_ovos_internal("speak", destination=None, data={"utterance": "hi"}))
42
+
43
+ alice.send.assert_not_called()
44
+ bob.send.assert_not_called()
45
+
46
+ def test_message_addressed_to_unknown_peer_is_dropped(self, agent, make_client):
47
+ alice = make_client("ws://alice")
48
+ agent.hm_protocol.clients = {"ws://alice": alice}
49
+
50
+ agent.handle_internal_mycroft(_ovos_internal("speak", destination="ws://stranger"))
51
+
52
+ alice.send.assert_not_called()
53
+
54
+ def test_forwarded_message_is_wrapped_as_bus_hivemessage(self, agent, make_client):
55
+ alice = make_client("ws://alice")
56
+ agent.hm_protocol.clients = {"ws://alice": alice}
57
+
58
+ agent.handle_internal_mycroft(_ovos_internal("speak", destination="ws://alice"))
59
+
60
+ sent = alice.send.call_args[0][0]
61
+ assert sent.msg_type == HiveMessageType.BUS
62
+ # payload is the Mycroft Message
63
+ assert sent.payload.msg_type == "speak"
64
+
65
+ def test_forwarded_message_marks_source_as_hive(self, agent, make_client):
66
+ """Downstream relays must rewrite source so the client sees it came from the hive."""
67
+ alice = make_client("ws://alice")
68
+ agent.hm_protocol.clients = {"ws://alice": alice}
69
+
70
+ agent.handle_internal_mycroft(_ovos_internal("speak", destination="ws://alice"))
71
+
72
+ sent = alice.send.call_args[0][0]
73
+ assert sent.payload.context.get("source") == "hive"