hermes-actra-platform 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 [yyyy] [name of copyright owner]
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,321 @@
1
+ Metadata-Version: 2.4
2
+ Name: hermes-actra-platform
3
+ Version: 0.1.0
4
+ Summary: Custom actra platform adapter for Hermes Agent
5
+ Author: Dong Shuaijie
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/stavecho/hermes-actra-platform
8
+ Project-URL: Repository, https://github.com/stavecho/hermes-actra-platform
9
+ Project-URL: Issues, https://github.com/stavecho/hermes-actra-platform/issues
10
+ Keywords: hermes-agent,actra,websocket,plugin
11
+ Requires-Python: <3.14,>=3.11
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Requires-Dist: hermes-agent<0.18,>=0.17.0
15
+ Requires-Dist: websockets>=12.0
16
+ Dynamic: license-file
17
+
18
+ # hermes-actra-platform
19
+
20
+ Hermes Agent 的 Actra message platform 插件。插件通过 WebSocket 接收 Actra 消息事件,把它们转换成 Hermes `MessageEvent`,并把 Hermes 回复、工具调用状态和中断状态转换回 Actra 事件。
21
+
22
+ ## 功能
23
+
24
+ - WebSocket 长连接接入 Actra 服务。
25
+ - 入站 `messages` 事件转换为 Hermes 文本消息。
26
+ - 出站回复按 `start -> messages/tools -> end` 事件序列返回。
27
+ - Hermes 工具调用通过 `pre_tool_call` / `post_tool_call` hook 转成 `tools` 事件。
28
+ - 支持 `break: true` 中断当前 Hermes session,并返回被打断的 `message_ids`。
29
+ - 支持 `PING` 保活和回显。
30
+
31
+ ## 安装
32
+
33
+ 需要 Python 3.11–3.13、Hermes Agent 0.17.x,以及可访问的 Actra WebSocket 服务。请在运行 Hermes 的同一个 Python 环境中安装插件。
34
+
35
+ PyPI 首次发布完成后,可使用:
36
+
37
+ ```bash
38
+ python -m pip install hermes-actra-platform
39
+ ```
40
+
41
+ 首次发布前,或需要安装 GitHub 上的版本时:
42
+
43
+ ```bash
44
+ python -m pip install "git+https://github.com/stavecho/hermes-actra-platform.git"
45
+ ```
46
+
47
+ 插件通过 `hermes_agent.plugins` entry point 加载,不需要软链到 `~/.hermes/plugins`。在 Hermes 的 `~/.hermes/config.yaml` 中合并以下配置(保留已有插件和平台配置):
48
+
49
+ ```yaml
50
+ plugins:
51
+ enabled:
52
+ - actra
53
+
54
+ platforms:
55
+ actra:
56
+ enabled: true
57
+ ```
58
+
59
+ 配置下方必需的环境变量后,启动或重启 Hermes gateway:
60
+
61
+ ```bash
62
+ hermes gateway
63
+ ```
64
+
65
+ ## 环境变量
66
+
67
+ 必需:
68
+
69
+ ```bash
70
+ export ACTRA_WS_URL='wss://example.com/ws'
71
+ export ACTRA_WS_TOKEN='token'
72
+ ```
73
+
74
+ 可选:
75
+
76
+ ```bash
77
+ export ACTRA_WS_HOME_CHANNEL='actra-default'
78
+ export ACTRA_APPROVE='false'
79
+ export ACTRA_END_IDLE_SECONDS='1'
80
+ ```
81
+
82
+ 如果 `ACTRA_WS_URL` 没有 query string,插件会自动拼接:
83
+
84
+ ```text
85
+ ?service_type=service&token=<ACTRA_WS_TOKEN>
86
+ ```
87
+
88
+ 如果 URL 已经包含 `?`,插件会原样使用,不再追加 token。
89
+
90
+ 也可以通过 Hermes `config.yaml` 的 `platforms.actra.extra` 配置:
91
+
92
+ ```yaml
93
+ plugins:
94
+ enabled:
95
+ - actra
96
+
97
+ platforms:
98
+ actra:
99
+ enabled: true
100
+ extra:
101
+ ws_url: wss://example.com/ws
102
+ token: your-token
103
+ approve: false
104
+ end_idle_seconds: 1
105
+ ```
106
+
107
+ `approve: true` 只对 Actra 平台生效。它不会修改 Hermes 全局 `approvals.mode`,而是在 Actra 收到危险命令审批请求时自动按 `/approve always` 处理。如果不设置,则按 Hermes 全局审批配置继续运行。
108
+
109
+ `end_idle_seconds` 是最终 `messages` 后发送 `end` 的等待时间,默认 1 秒。Hermes 的最终回复会通过 `metadata.notify=true` 标记;工具结果本身不会触发 `end`,所以 `tools` 和最终 `messages` 会落在同一个 `start/end` 中。
110
+
111
+ ## 入站事件
112
+
113
+ Actra 服务端发给 Hermes 插件:
114
+
115
+ ```json
116
+ {
117
+ "event": "messages",
118
+ "data": "你好",
119
+ "message_id": "msg-001",
120
+ "chat_id": "chat-001",
121
+ "account_id": "default",
122
+ "user_id": "client",
123
+ "user_name": "client"
124
+ }
125
+ ```
126
+
127
+ 字段说明:
128
+
129
+ - `event`: 必须是 `messages`。
130
+ - `data`: 用户文本。
131
+ - `message_id`: 可选,优先使用;兼容 `messageId`。
132
+ - `chat_id`: 可选。缺省时使用 `actra-<account_id>`,`account_id` 缺省为 `default`。
133
+ - `break`: 可选,`true` 时中断当前 session。
134
+
135
+ ## 出站回复事件
136
+
137
+ Hermes 回复会按同一个 `message_id` 返回:
138
+
139
+ ```json
140
+ {
141
+ "event": "start",
142
+ "from": "service",
143
+ "message_id": "msg-001",
144
+ "messageId": "msg-001",
145
+ "query": "你好"
146
+ }
147
+ ```
148
+
149
+ ```json
150
+ {
151
+ "event": "messages",
152
+ "from": "service",
153
+ "data": "你好,我是 Hermes。",
154
+ "query": "你好",
155
+ "message_id": "msg-001",
156
+ "messageId": "msg-001"
157
+ }
158
+ ```
159
+
160
+ ```json
161
+ {
162
+ "event": "end",
163
+ "from": "service",
164
+ "query": "你好",
165
+ "message_id": "msg-001",
166
+ "messageId": "msg-001"
167
+ }
168
+ ```
169
+
170
+ `tools` 事件会出现在 `start` 和 `end` 之间。
171
+
172
+ ## 工具事件
173
+
174
+ 工具开始:
175
+
176
+ ```json
177
+ {
178
+ "event": "tools",
179
+ "from": "service",
180
+ "message_id": "msg-001",
181
+ "messageId": "msg-001",
182
+ "query": "读一下 README",
183
+ "type": "call",
184
+ "role": "assistant",
185
+ "title": "tool read_file",
186
+ "phase": "start",
187
+ "name": "read_file",
188
+ "toolCallId": "tool-001",
189
+ "isError": false
190
+ }
191
+ ```
192
+
193
+ 工具结果:
194
+
195
+ ```json
196
+ {
197
+ "event": "tools",
198
+ "from": "service",
199
+ "message_id": "msg-001",
200
+ "messageId": "msg-001",
201
+ "query": "读一下 README",
202
+ "type": "output",
203
+ "role": "tool",
204
+ "title": "Tool output read_file",
205
+ "phase": "result",
206
+ "name": "read_file",
207
+ "toolCallId": "tool-001",
208
+ "isError": false
209
+ }
210
+ ```
211
+
212
+ 错误、阻断和取消会把 `isError` 设置为 `true`。
213
+
214
+ ## 中断事件
215
+
216
+ 发送 break-only:
217
+
218
+ ```json
219
+ {
220
+ "event": "messages",
221
+ "break": true
222
+ }
223
+ ```
224
+
225
+ 插件会取消当前 session,并返回被打断的消息 ID:
226
+
227
+ ```json
228
+ {
229
+ "event": "break",
230
+ "data": {
231
+ "message_ids": ["msg-001", "msg-002"]
232
+ }
233
+ }
234
+ ```
235
+
236
+ 如果 `break: true` 同时带了新的 `data`,插件会先返回 `break` 事件,再把新文本作为新一轮消息处理。
237
+
238
+ ## PING
239
+
240
+ 插件每 30 秒主动发送:
241
+
242
+ ```json
243
+ {
244
+ "event": "PING",
245
+ "data": 0
246
+ }
247
+ ```
248
+
249
+ 收到 Actra 服务端的 `PING` 时会回显:
250
+
251
+ ```json
252
+ {
253
+ "event": "PING",
254
+ "data": "原始 data"
255
+ }
256
+ ```
257
+
258
+ ## 代码结构
259
+
260
+ - `actra/adapter.py`: Hermes platform adapter,负责 WebSocket 连接和 Hermes message 转换。
261
+ - `actra/protocol.py`: Actra 事件协议构造和解析。
262
+ - `actra/hooks.py`: Hermes tool lifecycle hooks,负责把工具调用转换成 `tools` 事件。
263
+ - `actra/plugin.yaml`: Hermes plugin manifest。
264
+
265
+ ## 开发检查
266
+
267
+ 从源码安装:
268
+
269
+ ```bash
270
+ git clone https://github.com/stavecho/hermes-actra-platform.git
271
+ cd hermes-actra-platform
272
+ python -m pip install -e .
273
+ ```
274
+
275
+ 在 Hermes 所在的 Python 环境中检查:
276
+
277
+ ```bash
278
+ python -m compileall -q actra
279
+ python scripts/check_install.py
280
+ ```
281
+
282
+ `check_install.py` 验证安装的分发包、插件资源、pip entry point、Hermes 平台注册和 adapter 初始化;不连接 Actra 服务。
283
+
284
+ ## 发布
285
+
286
+ 构建和检查:
287
+
288
+ ```bash
289
+ python3 -m venv .venv
290
+ source .venv/bin/activate
291
+ python -m pip install --upgrade build twine
292
+ python -m build
293
+ python -m twine check dist/*
294
+ ```
295
+
296
+ 建议使用单独的构建环境,避免构建工具与 Hermes 的固定版本依赖发生冲突。GitHub Actions 在 push 和 pull request 时构建分发包,并在另一个虚拟环境中验证 wheel 安装。
297
+
298
+ 自动发布使用 PyPI Trusted Publishing,不需要在仓库中保存 API Token。首次发布前:
299
+
300
+ 1. 注册并验证 [PyPI](https://pypi.org/account/register/) 账号,启用双因素认证。
301
+ 2. 在仓库 **Settings → Environments** 创建 `pypi` environment,并配置发布审批人。
302
+ 3. 在 [PyPI Publishing](https://pypi.org/manage/account/publishing/) 添加 Pending Publisher,填写:
303
+
304
+ | 字段 | 值 |
305
+ | --- | --- |
306
+ | PyPI Project Name | `hermes-actra-platform` |
307
+ | GitHub Owner | `stavecho` |
308
+ | GitHub Repository | `hermes-actra-platform` |
309
+ | Workflow filename | `publish.yml` |
310
+ | Environment name | `pypi` |
311
+
312
+ 4. 创建指向准备发布的提交的 GitHub Release,例如 `v0.1.0`。标签去掉 `v` 后必须与 `pyproject.toml` 的版本一致。
313
+ 5. 发布 Release 后,`Publish to PyPI` 工作流会检查版本、构建、验证 wheel 安装,然后上传 PyPI;若 environment 配置了审批,需要先批准发布。
314
+
315
+ 后续发布时,同时更新 `pyproject.toml` 和 `actra/plugin.yaml` 的版本,并使用新的 Release 标签。每次手动构建前清理旧的 `dist/` 产物,避免混入旧版本。
316
+
317
+ 参考:[PyPA GitHub Actions 发布指南](https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/)。
318
+
319
+ ## 许可证
320
+
321
+ 本项目使用 [Apache License 2.0](LICENSE)。