nonebot-plugin-hermes 0.1.0__py3-none-any.whl

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,42 @@
1
+ """
2
+ NoneBot Plugin Hermes
3
+
4
+ 通过 Hermes Agent API Server 实现多平台 AI 聊天机器人。
5
+ 支持所有 NoneBot adapter(OneBot v11/v12、QQ Official、Kook 等)。
6
+ """
7
+
8
+ from nonebot import require, logger
9
+ from nonebot.plugin import PluginMetadata, inherit_supported_adapters
10
+
11
+ # 确保依赖的插件已加载
12
+ require("nonebot_plugin_alconna")
13
+
14
+ from .config import Config, plugin_config # noqa: E402
15
+
16
+ __version__ = "0.1.0"
17
+
18
+ __plugin_meta__ = PluginMetadata(
19
+ name="Hermes Agent",
20
+ description="通过 Hermes Agent API Server 实现多平台 AI 聊天机器人",
21
+ homepage="https://github.com/NousResearch/hermes-agent",
22
+ usage=(
23
+ "在群聊中 @机器人 发送消息即可与 Hermes Agent 对话。\n"
24
+ "私聊直接发送消息即可。\n\n"
25
+ "命令:\n"
26
+ "/clear - 重置对话\n"
27
+ "/ping - 检查连接状态\n"
28
+ "/help - 显示帮助"
29
+ ),
30
+ type="application",
31
+ config=Config,
32
+ supported_adapters=inherit_supported_adapters("nonebot_plugin_alconna"),
33
+ extra={
34
+ "author": "gsskk",
35
+ "version": __version__,
36
+ },
37
+ )
38
+
39
+ logger.info(f"Hermes Plugin loaded — API: {plugin_config.hermes_api_url}")
40
+
41
+ # 导入 handlers 以注册事件处理器
42
+ from . import handlers # noqa: F401, E402
@@ -0,0 +1,55 @@
1
+ """
2
+ 配置模型
3
+
4
+ 所有配置项通过 NoneBot 的 .env 文件读取,前缀为 HERMES_。
5
+ """
6
+
7
+ from typing import Set
8
+
9
+ from nonebot import get_plugin_config
10
+ from pydantic import BaseModel
11
+
12
+
13
+ class Config(BaseModel):
14
+ # --- Hermes API Server ---
15
+ hermes_api_url: str = "http://127.0.0.1:8642"
16
+ """Hermes API Server 地址"""
17
+
18
+ hermes_api_key: str = ""
19
+ """Hermes API Server 密钥(对应 api_server.extra.key)"""
20
+
21
+ hermes_api_timeout: int = 300
22
+ """API 请求超时时间(秒),Agent 执行可能较慢"""
23
+
24
+ # --- 触发模式 ---
25
+ hermes_group_trigger: str = "at"
26
+ """群聊触发方式: at / all / keyword"""
27
+
28
+ hermes_keywords: Set[str] = {"/ai"}
29
+ """keyword 模式下的触发关键词"""
30
+
31
+ hermes_private_trigger: str = "all"
32
+ """私聊触发方式: all / allowlist"""
33
+
34
+ hermes_allow_users: Set[str] = set()
35
+ """允许私聊的用户 ID(allowlist 模式)"""
36
+
37
+ hermes_allow_groups: Set[str] = set()
38
+ """允许响应的群组 ID(空 = 全部允许)"""
39
+
40
+ # --- 会话 ---
41
+ hermes_session_expire: int = 3600
42
+ """会话过期时间(秒),过期后自动开始新会话"""
43
+
44
+ hermes_session_share_group: bool = False
45
+ """群内是否共享同一个 session(False = 每人独立)"""
46
+
47
+ # --- 消息 ---
48
+ hermes_max_length: int = 4000
49
+ """单条回复最大长度(超出截断,QQ 限制约 4500 字符)"""
50
+
51
+ hermes_ignore_prefix: Set[str] = {"."}
52
+ """以这些字符开头的消息不触发回复"""
53
+
54
+
55
+ plugin_config = get_plugin_config(Config)
@@ -0,0 +1,221 @@
1
+ Metadata-Version: 2.4
2
+ Name: nonebot-plugin-hermes
3
+ Version: 0.1.0
4
+ Summary: NoneBot plugin for Hermes Agent — multi-platform AI chatbot via Hermes API Server
5
+ License: MIT
6
+ Project-URL: Homepage, https://github.com/gsskk/nonebot-plugin-hermes
7
+ Requires-Python: >=3.10
8
+ Description-Content-Type: text/markdown
9
+ Requires-Dist: nonebot2>=2.3.0
10
+ Requires-Dist: nonebot-plugin-alconna>=0.50.2
11
+ Requires-Dist: httpx>=0.27.0
12
+ Requires-Dist: cachetools>=6.2.0
13
+
14
+ # nonebot-plugin-hermes
15
+
16
+ 中文文档 | [English](README_EN.md)
17
+
18
+ [Hermes Agent](https://github.com/NousResearch/hermes-agent) 的 NoneBot2 插件,通过 Hermes API Server 实现多平台 AI 聊天机器人。
19
+
20
+ ## 支持的平台
21
+
22
+ 通过 NoneBot adapter 机制,本插件自动支持:
23
+
24
+ - ✅ OneBot v11(NapCatQQ、LLOneBot、go-cqhttp 等)
25
+ - ✅ OneBot v12
26
+ - ✅ QQ Official Bot
27
+ - ✅ Kook(开黑啦)
28
+ - ✅ Discord
29
+ - ✅ Telegram
30
+ - ✅ 飞书
31
+ - ✅ 其他 `nonebot-plugin-alconna` 支持的平台
32
+
33
+ ## 工作原理
34
+
35
+ ```
36
+ 用户消息 → NoneBot Adapter → nonebot-plugin-hermes
37
+ → POST /v1/chat/completions (Hermes API Server)
38
+ → 解析回复 → UniMessage.send() → NoneBot Adapter → 用户
39
+ ```
40
+
41
+ ## 功能
42
+
43
+ - ✅ 私聊 / 群聊对话
44
+ - ✅ 多轮上下文记忆(基于 Hermes Session)
45
+ - ✅ 群聊 @触发 / 关键词触发 / 全部触发
46
+ - ✅ 图片接收(通过 vision 发给 AI)
47
+ - ✅ 图片发送(解析 AI 回复中的 markdown 图片)
48
+ - ✅ 会话超时自动重置
49
+ - ✅ 白名单(群/用户级别)
50
+ - ✅ 内置命令(`/clear` `/ping` `/help`)
51
+
52
+ ## 快速开始
53
+
54
+ ### 1. 前置条件
55
+
56
+ - 已安装并运行 Hermes Agent,且 API Server 已启用
57
+ - 已安装 NoneBot2 和对应平台的 adapter
58
+
59
+ ### 2. 启用 Hermes API Server
60
+
61
+ 在 `~/.hermes/config.yaml` 中:
62
+
63
+ ```yaml
64
+ platforms:
65
+ api_server:
66
+ enabled: true
67
+ extra:
68
+ port: 8642
69
+ ```
70
+
71
+ 设置 API Key(**必须**,用于会话保持):
72
+
73
+ ```bash
74
+ # 生成密钥
75
+ python -c "import secrets; print(secrets.token_hex(32))"
76
+ # 或 openssl rand -hex 32
77
+
78
+ # 写入 Hermes 环境配置
79
+ echo 'API_SERVER_KEY=your-generated-key' >> ~/.hermes/.env
80
+ ```
81
+
82
+ > **Note**: 不设置 `API_SERVER_KEY` 会导致 Session 续接被拒绝,每次对话无法保持上下文。
83
+
84
+ 启动 Hermes Gateway:
85
+
86
+ ```bash
87
+ hermes gateway
88
+ ```
89
+
90
+ ### 3. 安装插件
91
+
92
+ **方式 A:已有 NoneBot 项目**
93
+
94
+ ```bash
95
+ pip install -e /path/to/nonebot-plugin-hermes
96
+ # 或 uv add /path/to/nonebot-plugin-hermes
97
+ ```
98
+
99
+ 在 `pyproject.toml` 中添加插件:
100
+
101
+ ```toml
102
+ [tool.nonebot]
103
+ plugins = ["nonebot_plugin_hermes"]
104
+ ```
105
+
106
+ **方式 B:新建 NoneBot 项目**
107
+
108
+ ```bash
109
+ pip install nb-cli
110
+ nb create # 创建项目,选择 fastapi 驱动器
111
+ nb plugin install nonebot-adapter-onebot # 安装 OneBot 适配器
112
+ pip install -e /path/to/nonebot-plugin-hermes
113
+ ```
114
+
115
+ ### 4. 配置
116
+
117
+ 复制示例配置:
118
+
119
+ ```bash
120
+ cp .env.example .env
121
+ ```
122
+
123
+ 编辑 `.env`,主要配置:
124
+
125
+ ```env
126
+ # OneBot 正向 WebSocket
127
+ ONEBOT_WS_URLS=["ws://127.0.0.1:3001"]
128
+
129
+ # Hermes API
130
+ HERMES_API_URL=http://127.0.0.1:8642
131
+ HERMES_API_KEY=
132
+
133
+ # 群聊触发
134
+ HERMES_GROUP_TRIGGER=at
135
+ ```
136
+
137
+ ### 5. 运行
138
+
139
+ ```bash
140
+ nb run
141
+ ```
142
+
143
+ ## 可用的 AI 工具
144
+
145
+ 本插件通过 Hermes 的 `api_server` 平台通信,默认使用 `hermes-api-server` 工具集:
146
+
147
+ | 工具类别 | 包含的工具 |
148
+ |---------|-----------|
149
+ | Web 搜索与提取 | `web_search`, `web_extract` |
150
+ | 终端与进程 | `terminal`, `process` |
151
+ | 文件操作 | `read_file`, `write_file`, `patch`, `search_files` |
152
+ | 视觉与图片生成 | `vision_analyze`, `image_generate` |
153
+ | 浏览器自动化 | `browser_navigate`, `browser_snapshot` 等 |
154
+ | 规划与记忆 | `todo`, `memory`, `session_search` |
155
+ | 代码执行与委托 | `execute_code`, `delegate_task` |
156
+ | 定时任务 | `cronjob` |
157
+ | 智能家居 | `ha_list_entities`, `ha_get_state` 等 |
158
+
159
+ ### 🔒 安全最佳实践:限制 API Server 工具集
160
+
161
+ 默认的 `hermes-api-server` 工具集包含 `terminal`、`execute_code` 等可执行服务器命令的工具。**对于面向外部用户的部署,强烈建议限制工具集**。
162
+
163
+ 在 `~/.hermes/config.yaml` 中配置 `platform_toolsets`:
164
+
165
+ ```yaml
166
+ platform_toolsets:
167
+ # 其他平台保持默认
168
+ cli: [hermes-cli]
169
+ telegram: [hermes-telegram]
170
+
171
+ # API Server 使用受限工具集(按需选择)
172
+ api_server: [web, file, vision, image_gen, skills, todo, memory, session_search]
173
+ ```
174
+
175
+ 可选的安全级别:
176
+
177
+ | 级别 | 配置 | 说明 |
178
+ |------|------|------|
179
+ | 🔴 最小权限 | `[safe]` | 仅 web + vision + image_gen,无文件/终端 |
180
+ | 🟡 推荐 | `[web, file, vision, image_gen, skills, todo, memory, session_search]` | 有文件读写但无命令执行 |
181
+ | 🟢 完全信任 | `[hermes-api-server]`(默认) | 包含终端、代码执行等全部工具 |
182
+
183
+ > **Tip**: 运行 `hermes chat --list-toolsets` 查看所有可用工具集。
184
+
185
+
186
+
187
+ ## 命令
188
+
189
+ | 命令 | 说明 |
190
+ |------|------|
191
+ | `/clear` | 重置对话,开始新会话 |
192
+ | `/ping` | 检查 Hermes Agent 连接状态 |
193
+ | `/help` | 显示帮助信息 |
194
+
195
+ ## 配置项
196
+
197
+ 所有配置项通过 `.env` 文件设置,参见 [.env.example](.env.example) 中的详细注释。
198
+
199
+ | 配置项 | 默认值 | 说明 |
200
+ |--------|--------|------|
201
+ | `HERMES_API_URL` | `http://127.0.0.1:8642` | Hermes API Server 地址 |
202
+ | `HERMES_API_KEY` | (空) | API 密钥 |
203
+ | `HERMES_GROUP_TRIGGER` | `at` | 群聊触发: at / all / keyword |
204
+ | `HERMES_PRIVATE_TRIGGER` | `all` | 私聊触发: all / allowlist |
205
+ | `HERMES_SESSION_EXPIRE` | `3600` | 会话超时(秒) |
206
+ | `HERMES_SESSION_SHARE_GROUP` | `false` | 群内共享 session |
207
+
208
+ ## 限制
209
+
210
+ 由于通过 HTTP API 与 Hermes 通信(而非原生 Gateway Adapter),以下功能不可用:
211
+
212
+ - ❌ 追问用户(`clarify` 工具)
213
+ - ❌ 跨平台发消息(`send_message` 工具)
214
+ - ❌ 语音合成发送(`text_to_speech` 工具)
215
+ - ❌ 危险命令审批按钮
216
+ - ❌ Cron 定时主动推送
217
+ - ❌ 中断正在运行的 Agent
218
+
219
+ ## License
220
+
221
+ MIT
@@ -0,0 +1,6 @@
1
+ nonebot_plugin_hermes/__init__.py,sha256=2rEkiPFjVfSTFqjPwharCJ7o1mu2F-mAKNLxGPJzeGE,1277
2
+ nonebot_plugin_hermes/config.py,sha256=iM6_MM56vrY628TV6fSnBbhj7e6t9kTYuEWjp-mnnxo,1555
3
+ nonebot_plugin_hermes-0.1.0.dist-info/METADATA,sha256=7JYn7bLCeKa_ZEsqg3e2ulnFpkfbdI78OdpLGg_V_dY,5927
4
+ nonebot_plugin_hermes-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
5
+ nonebot_plugin_hermes-0.1.0.dist-info/top_level.txt,sha256=8opDU9spxCmiU2okVK23VCfzF4fy5YkXkKjAXVDxJ1Q,22
6
+ nonebot_plugin_hermes-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ nonebot_plugin_hermes