@zhin.js/adapter-napcat 1.0.1 → 1.1.0

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.
Files changed (159) hide show
  1. package/CHANGELOG.md +661 -0
  2. package/README.md +60 -95
  3. package/adapters/napcat.js +47 -0
  4. package/adapters/napcat.ts +64 -0
  5. package/{skills/napcat → agent}/PERMITS.md +3 -3
  6. package/{skills/napcat/SKILL.md → agent/skills/napcat.md} +2 -2
  7. package/agent/tools/ai_tts.ts +19 -0
  8. package/agent/tools/del_group_notice.ts +20 -0
  9. package/agent/tools/delete_essence_msg.ts +19 -0
  10. package/agent/tools/delete_friend.ts +18 -0
  11. package/agent/tools/download_file.ts +17 -0
  12. package/agent/tools/forward_single_msg.ts +28 -0
  13. package/agent/tools/get_ai_characters.ts +17 -0
  14. package/agent/tools/get_essence_list.ts +17 -0
  15. package/agent/tools/get_friend_msg_history.ts +18 -0
  16. package/agent/tools/get_group_file_url.ts +19 -0
  17. package/agent/tools/get_group_info_ex.ts +17 -0
  18. package/agent/tools/get_group_msg_history.ts +19 -0
  19. package/agent/tools/get_group_notice.ts +17 -0
  20. package/agent/tools/get_group_root_files.ts +17 -0
  21. package/agent/tools/get_group_shut_list.ts +17 -0
  22. package/agent/tools/get_mini_app_ark.ts +20 -0
  23. package/agent/tools/get_user_status.ts +16 -0
  24. package/agent/tools/group_sign.ts +18 -0
  25. package/agent/tools/mark_msg_as_read.ts +17 -0
  26. package/agent/tools/ocr_image.ts +16 -0
  27. package/agent/tools/send_forward_msg.ts +27 -0
  28. package/agent/tools/send_group_notice.ts +21 -0
  29. package/agent/tools/send_like.ts +18 -0
  30. package/agent/tools/send_poke.ts +18 -0
  31. package/agent/tools/set_avatar.ts +17 -0
  32. package/agent/tools/set_emoji_reaction.ts +18 -0
  33. package/agent/tools/set_essence_msg.ts +19 -0
  34. package/agent/tools/set_group_portrait.ts +20 -0
  35. package/agent/tools/set_online_status.ts +18 -0
  36. package/agent/tools/set_profile.ts +21 -0
  37. package/agent/tools/set_signature.ts +17 -0
  38. package/agent/tools/set_title.ts +21 -0
  39. package/agent/tools/translate.ts +16 -0
  40. package/agent/tools/upload_group_file.ts +21 -0
  41. package/commands/endpoint/add/[id].js +3 -0
  42. package/commands/endpoint/add/[id].ts +3 -0
  43. package/commands/endpoint/list.js +3 -0
  44. package/commands/endpoint/list.ts +3 -0
  45. package/commands/endpoint/remove/[id].js +3 -0
  46. package/commands/endpoint/remove/[id].ts +3 -0
  47. package/lib/client.d.ts +52 -0
  48. package/lib/client.js +62 -0
  49. package/lib/endpoint-management.d.ts +15 -0
  50. package/lib/endpoint-management.js +47 -0
  51. package/lib/http-endpoint.d.ts +27 -0
  52. package/lib/http-endpoint.js +177 -0
  53. package/lib/index.d.ts +11 -22
  54. package/lib/index.js +10 -59
  55. package/lib/napcat-endpoint-commands.d.ts +1 -0
  56. package/lib/napcat-endpoint-commands.js +28 -0
  57. package/lib/napcat-inbound.d.ts +12 -5
  58. package/lib/napcat-inbound.js +28 -13
  59. package/lib/napcat-runtime-state.d.ts +1 -0
  60. package/lib/napcat-runtime-state.js +6 -0
  61. package/lib/onebot-get-msg.d.ts +16 -3
  62. package/lib/onebot-get-msg.js +53 -1
  63. package/lib/protocol.d.ts +165 -0
  64. package/lib/protocol.js +305 -0
  65. package/lib/side-event-dispatch.d.ts +7 -0
  66. package/lib/side-event-dispatch.js +36 -0
  67. package/lib/webhook.d.ts +2 -0
  68. package/lib/webhook.js +14 -0
  69. package/lib/ws-endpoint.d.ts +27 -0
  70. package/lib/ws-endpoint.js +241 -0
  71. package/lib/ws-transport.d.ts +13 -0
  72. package/lib/ws-transport.js +75 -0
  73. package/lib/ws-types.d.ts +17 -0
  74. package/lib/ws-types.js +1 -0
  75. package/lib/wss-auth.d.ts +2 -0
  76. package/lib/wss-auth.js +16 -0
  77. package/lib/wss-endpoint.d.ts +26 -0
  78. package/lib/wss-endpoint.js +187 -0
  79. package/package.json +62 -32
  80. package/plugin.js +18 -0
  81. package/schema.json +110 -0
  82. package/src/client.ts +79 -0
  83. package/src/endpoint-management.ts +72 -0
  84. package/src/http-endpoint.ts +234 -0
  85. package/src/index.ts +63 -87
  86. package/src/napcat-endpoint-commands.ts +26 -0
  87. package/src/napcat-inbound.ts +34 -10
  88. package/src/napcat-runtime-state.ts +7 -0
  89. package/src/onebot-get-msg.ts +69 -5
  90. package/src/protocol.ts +468 -0
  91. package/src/side-event-dispatch.ts +48 -0
  92. package/src/webhook.ts +16 -0
  93. package/src/ws-endpoint.ts +301 -0
  94. package/src/ws-transport.ts +105 -0
  95. package/src/ws-types.ts +20 -0
  96. package/src/wss-auth.ts +17 -0
  97. package/src/wss-endpoint.ts +242 -0
  98. package/client/NapCatManagement.tsx +0 -113
  99. package/client/index.tsx +0 -11
  100. package/client/tsconfig.json +0 -7
  101. package/client/utils/api.ts +0 -30
  102. package/dist/index.js +0 -27
  103. package/lib/adapter.d.ts +0 -28
  104. package/lib/adapter.d.ts.map +0 -1
  105. package/lib/adapter.js +0 -94
  106. package/lib/adapter.js.map +0 -1
  107. package/lib/agent-prompt.d.ts +0 -3
  108. package/lib/agent-prompt.d.ts.map +0 -1
  109. package/lib/agent-prompt.js +0 -105
  110. package/lib/agent-prompt.js.map +0 -1
  111. package/lib/endpoint-base.d.ts +0 -143
  112. package/lib/endpoint-base.d.ts.map +0 -1
  113. package/lib/endpoint-base.js +0 -334
  114. package/lib/endpoint-base.js.map +0 -1
  115. package/lib/endpoint-http.d.ts +0 -18
  116. package/lib/endpoint-http.d.ts.map +0 -1
  117. package/lib/endpoint-http.js +0 -119
  118. package/lib/endpoint-http.js.map +0 -1
  119. package/lib/endpoint-ws-client.d.ts +0 -21
  120. package/lib/endpoint-ws-client.d.ts.map +0 -1
  121. package/lib/endpoint-ws-client.js +0 -165
  122. package/lib/endpoint-ws-client.js.map +0 -1
  123. package/lib/endpoint-ws-server.d.ts +0 -21
  124. package/lib/endpoint-ws-server.d.ts.map +0 -1
  125. package/lib/endpoint-ws-server.js +0 -150
  126. package/lib/endpoint-ws-server.js.map +0 -1
  127. package/lib/index.d.ts.map +0 -1
  128. package/lib/index.js.map +0 -1
  129. package/lib/napcat-inbound.d.ts.map +0 -1
  130. package/lib/napcat-inbound.js.map +0 -1
  131. package/lib/onebot-get-msg.d.ts.map +0 -1
  132. package/lib/onebot-get-msg.js.map +0 -1
  133. package/lib/routes.d.ts +0 -4
  134. package/lib/routes.d.ts.map +0 -1
  135. package/lib/routes.js +0 -61
  136. package/lib/routes.js.map +0 -1
  137. package/lib/tools.d.ts +0 -8
  138. package/lib/tools.d.ts.map +0 -1
  139. package/lib/tools.js +0 -605
  140. package/lib/tools.js.map +0 -1
  141. package/lib/types.d.ts +0 -293
  142. package/lib/types.d.ts.map +0 -1
  143. package/lib/types.js +0 -6
  144. package/lib/types.js.map +0 -1
  145. package/lib/typing-indicator.d.ts +0 -45
  146. package/lib/typing-indicator.d.ts.map +0 -1
  147. package/lib/typing-indicator.js +0 -132
  148. package/lib/typing-indicator.js.map +0 -1
  149. package/plugin.yml +0 -3
  150. package/src/adapter.ts +0 -101
  151. package/src/agent-prompt.ts +0 -114
  152. package/src/endpoint-base.ts +0 -376
  153. package/src/endpoint-http.ts +0 -109
  154. package/src/endpoint-ws-client.ts +0 -164
  155. package/src/endpoint-ws-server.ts +0 -150
  156. package/src/routes.ts +0 -61
  157. package/src/tools.ts +0 -632
  158. package/src/types.ts +0 -279
  159. package/src/typing-indicator.ts +0 -184
package/README.md CHANGED
@@ -1,131 +1,96 @@
1
1
  # @zhin.js/adapter-napcat
2
2
 
3
- Zhin.js NapCatQQ 适配器,支持 OneBot11 标准 + go-cqhttp 扩展 + NapCat 独有 API。
3
+ Zhin.js [NapCatQQ](https://github.com/NapNeko/NapCatQQ) 适配器(Plugin Runtime,OneBot 11 + NapCat 扩展)。默认 **正向 WebSocket 客户端**(`connection: ws`);亦支持 **反向 WS** 与 **HTTP POST 上报**(经 `httpHostToken`)。
4
4
 
5
5
  ## 功能特性
6
6
 
7
- - 完整 OneBot v11 协议兼容 + go-cqhttp 扩展 + NapCat 独有 API(92+ 接口)
8
- - **单一适配器**:`context: napcat`,通过 `connection` 选择连接方式
9
- - **正向 WebSocket**(`connection: ws`):应用连 NapCat 的 WS
10
- - **反向 WebSocket**(`connection: wss`):应用开 WS 服务端,NapCat 连上来
11
- - **HTTP API + POST 上报**(`connection: http`):出站 HTTP 调用,入站 webhook
12
- - Access Token 认证支持(Bearer / HMAC 签名)
13
- - 自动重连机制(WS)与心跳检测
14
- - 群聊和私聊消息处理
15
- - 入站消息去重与 bot 自发消息过滤
16
- - Typing Indicator(处理中提示:群聊表情回应 / 私聊输入状态)
17
- - 41 个 AI 工具(群管、戳一戳、表情回应、精华消息、群公告、AI 语音等)
18
- - Console 管理页面(`/console/napcat`)
19
- - Agent Prompt 贡献器(deferred 任务自动优选 napcat 工具)
7
+ - OneBot 11 + go-cqhttp 扩展 + NapCat 独有 API
8
+ - 约定式 `defineAdapter` / `definePlugin`(无需 `usePlugin`)
9
+ - **正向 WebSocket**(`connection: ws`):应用连 NapCat WS
10
+ - `access_token` 鉴权(Bearer + query)
11
+ - 入站经 `Endpoint.emit(...)`(去重 + 自发过滤);出站 `send({ conversation, payload })`
12
+ - 41 个 AI 工具(`agent/tools/`)
20
13
 
21
14
  ## 安装
22
15
 
23
16
  ```bash
24
- pnpm add @zhin.js/adapter-napcat ws
17
+ pnpm add @zhin.js/adapter-napcat
25
18
  ```
26
19
 
27
- 反向 WS / HTTP 模式需同时启用 `@zhin.js/host-router`。
20
+ ## Plugin Runtime
28
21
 
29
- ## 配置
22
+ - `@zhin.js/adapter` — 约定式 `adapters/napcat.ts`(`defineAdapter`)
23
+ - `@zhin.js/core` — `Endpoint.emit(...)` 入站、`outboundMessageToken` 出站
24
+ - `zhin.js` — `plugin.ts`(`definePlugin`)
25
+ - 配置经插件 `schema.json` 落到 `plugins.<instanceKey>`
30
26
 
31
- 所有 Endpoint 使用 **同一 context:`napcat`**,通过 **`connection`** 区分连接方式。
27
+ 入站:`gateway.receive({ conversation, message: { conversation, id }, content, sender, metadata })`(`conversation` 为 ConversationRef:私聊 `kind: 'private'`、群聊 `kind: 'group'`,临时会话群容器进 `parent`)
28
+ 出站:`send({ conversation, payload })` → WS `send_private_msg` / `send_group_msg`
32
29
 
33
- ### 正向 WebSocket(connection: ws)
30
+ ## 前置条件
31
+
32
+ 1. 安装并登录 NapCatQQ,启用一个与 Zhin 配置匹配的 OneBot 11 连接。
33
+ 2. 正向 WS 需 Zhin 可达 NapCat;反向 WS/HTTP 上报需 NapCat 可达 Zhin HTTP Host。
34
+ 3. 两端配置相同的 `access_token`,不要把未鉴权端口暴露到公网。
35
+
36
+ ## 最小配置
34
37
 
35
38
  ```yaml
39
+ # zhin.config.yml(Plugin Runtime)
36
40
  plugins:
37
- - "@zhin.js/adapter-napcat"
38
-
39
- endpoints:
40
- - context: napcat
41
+ napcat:
41
42
  connection: ws
42
- name: my-bot
43
- url: "ws://127.0.0.1:3001"
44
- access_token: "${NAPCAT_TOKEN}"
45
43
  reconnect_interval: 5000
46
44
  heartbeat_interval: 30000
45
+ endpoints:
46
+ - name: my-bot
47
+ url: "ws://127.0.0.1:3001"
48
+ access_token: "${NAPCAT_TOKEN}"
47
49
  ```
48
50
 
49
- ### 反向 WebSocket(connection: wss)
51
+ 根插件 `zhin.plugins`(或项目图)需引用 `@zhin.js/adapter-napcat`(`instanceKey: napcat`)。
50
52
 
51
- ```yaml
52
- plugins:
53
- - "@zhin.js/host-router"
54
- - "@zhin.js/adapter-napcat"
55
-
56
- endpoints:
57
- - context: napcat
58
- connection: wss
59
- name: my-bot
60
- path: "/napcat/ws"
61
- access_token: "${NAPCAT_TOKEN}"
62
- heartbeat_interval: 30000
63
- ```
53
+ ## 连接方式
64
54
 
65
- ### HTTP API + POST 上报(connection: http)
55
+ | connection | 状态 |
56
+ |------------|------|
57
+ | `ws` | 已实现(推荐) |
58
+ | `wss` | 已实现:反向 WS(httpHostToken) |
59
+ | `http` | 已实现:POST 入站 + `http_url/{action}` 出站 |
66
60
 
67
- ```yaml
68
- plugins:
69
- - "@zhin.js/host-router"
70
- - "@zhin.js/adapter-napcat"
71
-
72
- endpoints:
73
- - context: napcat
74
- connection: http
75
- name: my-bot
76
- http_url: "http://127.0.0.1:3000"
77
- post_path: "/napcat/post"
78
- access_token: "${NAPCAT_TOKEN}"
79
- poll_interval: 30000
80
- ```
61
+ ## 鉴权
81
62
 
82
- ### Typing Indicator(处理中提示)
63
+ - **Bearer**:`Authorization: Bearer <access_token>`
64
+ - 正向 WS 在 Upgrade 时附带请求头,并在 URL query 写入 `access_token`
83
65
 
84
- ```yaml
85
- endpoints:
86
- - context: napcat
87
- connection: ws
88
- name: my-bot
89
- url: "ws://127.0.0.1:3001"
90
- typingIndicator:
91
- enabled: true
92
- defaultEmoji: "128516"
93
- privateConfig:
94
- type: "message"
95
- message: "正在思考中..."
96
- groupConfig:
97
- type: "reaction"
98
- emoji: "128516"
99
- ```
66
+ ## AI 工具
100
67
 
101
- ## NapCat 独有能力
68
+ | 类别 | 路径 |
69
+ |------|------|
70
+ | Permit 词汇 | `agent/PERMITS.md` |
71
+ | 平台工具 | `agent/tools/*.ts` |
72
+ | 技能说明 | `agent/skills/napcat.md` |
102
73
 
103
- 相比标准 OneBot11 适配器,NapCat 额外支持:
74
+ ## 迁移说明(Plugin Runtime)
104
75
 
105
- - 戳一戳(群聊 / 私聊)
106
- - 表情回应(贴表情)
107
- - 合并 / 单条消息转发
108
- - 精华消息管理
109
- - 群公告管理
110
- - 群文件管理
111
- - AI 语音 TTS
112
- - 图片 OCR 文字识别
113
- - 小程序卡片签名
114
- - 个人资料 / 头像 / 签名修改
115
- - 在线状态设置
116
- - 消息历史查询
117
- - 英译中翻译
76
+ - **notice / request / meta 侧事件**:经 the unified `Endpoint.emit(...)` ingress 归一后分发到 `handlers`(`notice.receive` / `request.receive` / `system.receive`),请求带 `$approve` / `$reject`。消息仍走 `outboundMessageToken`。
77
+ - **群管工具暂未迁移**:旧 Adapter 经 `createSceneManagementTools` 注册踢人 / 禁言 / 群名片等成套 agent 工具;迁移后 `agent/tools/` 仅覆盖 NapCat 扩展 API,其余群管能力可通过 `callApi`(如 `set_group_kick`、`set_group_ban`)作为逃生舱调用。
78
+ - **平台权限门禁**:`plugin.ts` setup 已注册 `registerDefaultScenePlatformPermitChecker('napcat')`,`scene_admin` / `scene_owner` 依据入站 metadata 中的 sender `role`(owner / admin)判定。
118
79
 
119
- ## AI 工具
80
+ ## 文档链接
120
81
 
121
- 适配器自动注册 41 个 AI 工具(7 个群管理标准工具 + 34 个 NapCat 扩展工具),详见 `skills/napcat/SKILL.md`。
82
+ - [NapCatQQ](https://github.com/NapNeko/NapCatQQ)
83
+ - [适配器概览](https://zhin.js.org/essentials/adapters)
122
84
 
123
- ## full-bot L4 参考
85
+ ## 故障排查
124
86
 
125
- [`examples/full-bot`](../../../examples/full-bot/) 默认加载本适配器(`endpoints` 段需自行填写 `ONEBOT11_*` 后取消注释)。
87
+ | 现象 | 排查 |
88
+ | --- | --- |
89
+ | WS 连接被拒绝 | 检查 NapCat URL、端口与连接方向 |
90
+ | 401 或握手失败 | 确认两端 token 一致,反向代理保留 Authorization |
91
+ | 重复或自身消息触发 | 检查是否同时启用了多条上报连接 |
92
+ | 请求/通知缺失 | 确认 NapCat 上报 notice/request/meta,并查看 Endpoint 对应分类 |
126
93
 
127
- - 入站 → `ZhinAgent` → 出站走 `Adapter.sendMessage` 统一链路
128
- - 契约测试:`plugins/adapters/napcat/tests/l4-contract.test.ts` + `integration.test.ts`(adapter-harness)
129
- - CI:`L4_SKIP_PLATFORM=1` 跳过实机;本地验证不设该变量并可配置 `ONEBOT11_WS_URL`
94
+ ## 许可证
130
95
 
131
- 详见 [full-bot ACCEPTANCE.md](../../../examples/full-bot/ACCEPTANCE.md)。
96
+ MIT License
@@ -0,0 +1,47 @@
1
+ // Generated by build-plugin-runtime-entries.mjs. Do not edit.
2
+ /**
3
+ * Convention entry: discover `adapters/napcat.ts` → defineAdapter.
4
+ */
5
+ import { defineAdapter } from 'zhin.js/adapter';
6
+ import { httpHostToken } from '@zhin.js/host-http';
7
+ import { NapCatHttpEndpoint } from "../lib/http-endpoint.js";
8
+ import { resolveNapCatConfig } from "../lib/protocol.js";
9
+ import { NapCatWsEndpoint } from "../lib/ws-endpoint.js";
10
+ import { NapCatWssEndpoint } from "../lib/wss-endpoint.js";
11
+ import { napcatRuntimeStateToken } from "../lib/napcat-runtime-state.js";
12
+ export { NapCatHttpEndpoint, } from "../lib/http-endpoint.js";
13
+ export { NapCatWsEndpoint, } from "../lib/ws-endpoint.js";
14
+ export { NapCatWssEndpoint, } from "../lib/wss-endpoint.js";
15
+ export default defineAdapter({
16
+ capabilities: ['inbound', 'outbound'],
17
+ operations: ['recall'],
18
+ // OneBot file 参数原生消费 url / base64:// 媒体,file:// 本地路径由 NapCat 侧读盘;
19
+ // 无卡片交互面,交互段降级纯文本。
20
+ segments: {
21
+ outboundMedia: ['url', 'base64', 'path'],
22
+ interactive: 'text',
23
+ },
24
+ create(context) {
25
+ const config = resolveNapCatConfig(context.config);
26
+ // 注册到插件运行时状态(napcat.endpoint list 的"运行中"数据源)
27
+ context.use(napcatRuntimeStateToken).endpoints.set(config.id, {
28
+ id: config.id,
29
+ mode: config.connection,
30
+ });
31
+ if (config.connection === 'wss') {
32
+ return new NapCatWssEndpoint({
33
+ id: context.id,
34
+ http: context.use(httpHostToken),
35
+ config,
36
+ });
37
+ }
38
+ if (config.connection === 'http') {
39
+ return new NapCatHttpEndpoint({
40
+ id: context.id,
41
+ http: context.use(httpHostToken),
42
+ config,
43
+ });
44
+ }
45
+ return new NapCatWsEndpoint({ id: context.id, config });
46
+ },
47
+ });
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Convention entry: discover `adapters/napcat.ts` → defineAdapter.
3
+ */
4
+ import { defineAdapter } from 'zhin.js/adapter';
5
+ import { httpHostToken } from '@zhin.js/host-http';
6
+ import { NapCatHttpEndpoint } from '../src/http-endpoint.js';
7
+ import { resolveNapCatConfig, type NapCatAdapterConfig } from '../src/protocol.js';
8
+ import { NapCatWsEndpoint } from '../src/ws-endpoint.js';
9
+ import { NapCatWssEndpoint } from '../src/wss-endpoint.js';
10
+ import { napcatRuntimeStateToken } from '../src/napcat-runtime-state.js';
11
+
12
+ export {
13
+ NapCatHttpEndpoint,
14
+ type NapCatHttpEndpointOptions,
15
+ } from '../src/http-endpoint.js';
16
+ export {
17
+ NapCatWsEndpoint,
18
+ type NapCatWsEndpointOptions,
19
+ } from '../src/ws-endpoint.js';
20
+ export {
21
+ NapCatWssEndpoint,
22
+ type NapCatWssEndpointOptions,
23
+ } from '../src/wss-endpoint.js';
24
+ export type { NapCatWsSocket, NapCatWsCreateOptions } from '../src/ws-types.js';
25
+
26
+ declare module '@zhin.js/core' {
27
+ interface AdapterEndpoints {
28
+ napcat: import('../src/ws-endpoint.js').NapCatWsEndpoint;
29
+ }
30
+ }
31
+
32
+ export default defineAdapter<NapCatAdapterConfig>({
33
+ capabilities: ['inbound', 'outbound'],
34
+ operations: ['recall'],
35
+ // OneBot file 参数原生消费 url / base64:// 媒体,file:// 本地路径由 NapCat 侧读盘;
36
+ // 无卡片交互面,交互段降级纯文本。
37
+ segments: {
38
+ outboundMedia: ['url', 'base64', 'path'],
39
+ interactive: 'text',
40
+ },
41
+ create(context) {
42
+ const config = resolveNapCatConfig(context.config);
43
+ // 注册到插件运行时状态(napcat.endpoint list 的"运行中"数据源)
44
+ context.use(napcatRuntimeStateToken).endpoints.set(config.id, {
45
+ id: config.id,
46
+ mode: config.connection,
47
+ });
48
+ if (config.connection === 'wss') {
49
+ return new NapCatWssEndpoint({
50
+ id: context.id,
51
+ http: context.use(httpHostToken),
52
+ config,
53
+ });
54
+ }
55
+ if (config.connection === 'http') {
56
+ return new NapCatHttpEndpoint({
57
+ id: context.id,
58
+ http: context.use(httpHostToken),
59
+ config,
60
+ });
61
+ }
62
+ return new NapCatWsEndpoint({ id: context.id, config });
63
+ },
64
+ });
@@ -13,7 +13,7 @@ OneBot `sender.role` 透传:`owner` · `admin` · `member`。
13
13
 
14
14
  | `platform(napcat,…)` | 含义 |
15
15
  |----------------------|------|
16
- | `group_owner` | 群主 |
17
- | `group_admin` | 群管理员(含群主) |
16
+ | `scene_owner` | 群主 |
17
+ | `scene_admin` | 群管理员(含群主) |
18
18
 
19
- 使用 core 默认 `createGroupRolePlatformChecker`。
19
+ 使用 core 默认 `createSceneRolePlatformChecker`。
@@ -110,8 +110,8 @@ NapCat 是 OneBot11 协议的超集实现,提供标准群管理之外大量 QQ
110
110
  工具分三个权限层级,调用前先判断 Endpoint 在群里的身份:
111
111
 
112
112
  - **user** — 普通成员即可,如查询、点赞、戳一戳
113
- - **group_admin** — 需要管理员权限,如踢人、禁言、设精华、发公告
114
- - **group_owner** — 需要群主权限,如设管理员、设专属头衔
113
+ - **scene_admin** — 需要管理员权限,如踢人、禁言、设精华、发公告
114
+ - **scene_owner** — 需要群主权限,如设管理员、设专属头衔
115
115
 
116
116
  如果 Endpoint 权限不足,API 会返回错误。遇到权限不足时,向用户说明需要什么权限,而不是重试。
117
117
 
@@ -0,0 +1,19 @@
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
+ import { z } from 'zod';
3
+
4
+ export default defineAgentTool<{ group_id: number; character: string; text: string }>({
5
+ description: 'AI 文字转语音,在群聊中发送 AI 语音消息。',
6
+ inputSchema: z.object({
7
+ group_id: z.number().describe('群号'),
8
+ character: z.string().describe('AI 语音角色 ID(可先用 napcat_get_ai_characters 查询)'),
9
+ text: z.string().describe('要转为语音的文字'),
10
+ }),
11
+ adapter: 'napcat',
12
+ tags: ['napcat', 'qq'],
13
+ keywords: ['AI语音', 'TTS', '文字转语音', 'ai record'],
14
+ scopes: ['group'],
15
+ async execute({ group_id, character, text }: { group_id: number; character: string; text: string }, context) {
16
+ const endpoint = context.$client;
17
+ return endpoint.sendGroupAiRecord(group_id, character, text);
18
+ },
19
+ });
@@ -0,0 +1,20 @@
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
+ import { z } from 'zod';
3
+
4
+ export default defineAgentTool<{ group_id: number; notice_id: string }>({
5
+ description: '删除群公告。',
6
+ inputSchema: z.object({
7
+ group_id: z.number().describe('群号'),
8
+ notice_id: z.string().describe('公告 ID'),
9
+ }),
10
+ adapter: 'napcat',
11
+ tags: ['napcat', 'qq'],
12
+ keywords: ['删除公告', 'delete notice'],
13
+ permissions: ['platform(napcat,scene_admin)'],
14
+ scopes: ['group'],
15
+ async execute({ group_id, notice_id }: { group_id: number; notice_id: string }, context) {
16
+ const endpoint = context.$client;
17
+ await endpoint.deleteGroupNotice(group_id, notice_id);
18
+ return { success: true };
19
+ },
20
+ });
@@ -0,0 +1,19 @@
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
+ import { z } from 'zod';
3
+
4
+ export default defineAgentTool<{ message_id: number }>({
5
+ description: '移除群精华消息。',
6
+ inputSchema: z.object({
7
+ message_id: z.number().describe('消息 ID'),
8
+ }),
9
+ adapter: 'napcat',
10
+ tags: ['napcat', 'qq'],
11
+ keywords: ['取消精华', '移除精华', 'delete essence'],
12
+ permissions: ['platform(napcat,scene_admin)'],
13
+ scopes: ['group'],
14
+ async execute({ message_id }: { message_id: number }, context) {
15
+ const endpoint = context.$client;
16
+ await endpoint.deleteEssenceMsg(message_id);
17
+ return { success: true };
18
+ },
19
+ });
@@ -0,0 +1,18 @@
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
+ import { z } from 'zod';
3
+
4
+ export default defineAgentTool<{ user_id: number }>({
5
+ description: '删除好友。',
6
+ inputSchema: z.object({
7
+ user_id: z.number().describe('好友 QQ 号'),
8
+ }),
9
+ adapter: 'napcat',
10
+ tags: ['napcat', 'qq'],
11
+ keywords: ['删除好友', 'delete friend', '删好友'],
12
+ permissions: ['platform(napcat,scene_admin)'],
13
+ async execute({ user_id }: { user_id: number }, context) {
14
+ const endpoint = context.$client;
15
+ await endpoint.deleteFriend(user_id);
16
+ return { success: true };
17
+ },
18
+ });
@@ -0,0 +1,17 @@
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
+ import { z } from 'zod';
3
+
4
+ export default defineAgentTool<{ url: string; thread_count?: number }>({
5
+ description: '下载文件到 NapCat 缓存目录,返回本地路径。',
6
+ inputSchema: z.object({
7
+ url: z.string().describe('文件 URL'),
8
+ thread_count: z.number().optional().describe('下载线程数(可选,默认 1)'),
9
+ }),
10
+ adapter: 'napcat',
11
+ tags: ['napcat', 'qq'],
12
+ keywords: ['下载', 'download', '下载文件'],
13
+ async execute({ url, thread_count }: { url: string; thread_count?: number }, context) {
14
+ const endpoint = context.$client;
15
+ return endpoint.downloadFile(url, thread_count || 1);
16
+ },
17
+ });
@@ -0,0 +1,28 @@
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
+ import { z } from 'zod';
3
+
4
+ export default defineAgentTool<{
5
+ target_type: 'friend' | 'group';
6
+ target_id: number;
7
+ message_id: number;
8
+ }>({
9
+ description: '转发单条消息到指定好友或群。',
10
+ inputSchema: z.object({
11
+ target_type: z.enum(['friend', 'group']).describe('friend 或 group'),
12
+ target_id: z.number().describe('目标好友 QQ 号或群号'),
13
+ message_id: z.number().describe('要转发的消息 ID'),
14
+ }),
15
+ adapter: 'napcat',
16
+ tags: ['napcat', 'qq'],
17
+ keywords: ['转发', 'forward', '单条转发'],
18
+ async execute({ target_type, target_id, message_id }: {
19
+ target_type: 'friend' | 'group';
20
+ target_id: number;
21
+ message_id: number;
22
+ }, context) {
23
+ const endpoint = context.$client;
24
+ if (target_type === 'friend') await endpoint.forwardFriendSingleMsg(target_id, message_id);
25
+ else await endpoint.forwardGroupSingleMsg(target_id, message_id);
26
+ return { success: true };
27
+ },
28
+ });
@@ -0,0 +1,17 @@
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
+ import { z } from 'zod';
3
+
4
+ export default defineAgentTool<{ group_id: number }>({
5
+ description: '获取 AI 语音角色列表,用于 napcat_ai_tts 的 character 参数。',
6
+ inputSchema: z.object({
7
+ group_id: z.number().describe('群号'),
8
+ }),
9
+ adapter: 'napcat',
10
+ tags: ['napcat', 'qq'],
11
+ keywords: ['AI角色', 'ai characters', '语音角色'],
12
+ scopes: ['group'],
13
+ async execute({ group_id }: { group_id: number }, context) {
14
+ const endpoint = context.$client;
15
+ return endpoint.getAiCharacters(group_id);
16
+ },
17
+ });
@@ -0,0 +1,17 @@
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
+ import { z } from 'zod';
3
+
4
+ export default defineAgentTool<{ group_id: number }>({
5
+ description: '获取群精华消息列表。',
6
+ inputSchema: z.object({
7
+ group_id: z.number().describe('群号'),
8
+ }),
9
+ adapter: 'napcat',
10
+ tags: ['napcat', 'qq'],
11
+ keywords: ['精华列表', 'essence list'],
12
+ scopes: ['group'],
13
+ async execute({ group_id }: { group_id: number }, context) {
14
+ const endpoint = context.$client;
15
+ return endpoint.getEssenceMsgList(group_id);
16
+ },
17
+ });
@@ -0,0 +1,18 @@
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
+ import { z } from 'zod';
3
+
4
+ export default defineAgentTool<{ user_id: number; message_seq?: number; count?: number }>({
5
+ description: '获取私聊消息历史记录。',
6
+ inputSchema: z.object({
7
+ user_id: z.number().describe('QQ 号'),
8
+ message_seq: z.number().optional().describe('起始消息序号(可选)'),
9
+ count: z.number().optional().describe('获取条数(可选)'),
10
+ }),
11
+ adapter: 'napcat',
12
+ tags: ['napcat', 'qq'],
13
+ keywords: ['私聊记录', '好友聊天记录', 'friend history'],
14
+ async execute({ user_id, message_seq, count }: { user_id: number; message_seq?: number; count?: number }, context) {
15
+ const endpoint = context.$client;
16
+ return endpoint.getFriendMsgHistory(user_id, message_seq, count);
17
+ },
18
+ });
@@ -0,0 +1,19 @@
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
+ import { z } from 'zod';
3
+
4
+ export default defineAgentTool<{ group_id: number; file_id: string; busid: number }>({
5
+ description: '获取群文件下载链接。',
6
+ inputSchema: z.object({
7
+ group_id: z.number().describe('群号'),
8
+ file_id: z.string().describe('文件 ID'),
9
+ busid: z.number().describe('文件类型 ID'),
10
+ }),
11
+ adapter: 'napcat',
12
+ tags: ['napcat', 'qq'],
13
+ keywords: ['文件链接', 'file url', '下载文件'],
14
+ scopes: ['group'],
15
+ async execute({ group_id, file_id, busid }: { group_id: number; file_id: string; busid: number }, context) {
16
+ const endpoint = context.$client;
17
+ return endpoint.getGroupFileUrl(group_id, file_id, busid);
18
+ },
19
+ });
@@ -0,0 +1,17 @@
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
+ import { z } from 'zod';
3
+
4
+ export default defineAgentTool<{ group_id: number }>({
5
+ description: '获取群组额外详细信息。',
6
+ inputSchema: z.object({
7
+ group_id: z.number().describe('群号'),
8
+ }),
9
+ adapter: 'napcat',
10
+ tags: ['napcat', 'qq'],
11
+ keywords: ['群详情', '群额外信息', 'group info ex'],
12
+ scopes: ['group'],
13
+ async execute({ group_id }: { group_id: number }, context) {
14
+ const endpoint = context.$client;
15
+ return endpoint.getGroupInfoEx(group_id);
16
+ },
17
+ });
@@ -0,0 +1,19 @@
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
+ import { z } from 'zod';
3
+
4
+ export default defineAgentTool<{ group_id: number; message_seq?: number; count?: number }>({
5
+ description: '获取群消息历史记录。',
6
+ inputSchema: z.object({
7
+ group_id: z.number().describe('群号'),
8
+ message_seq: z.number().optional().describe('起始消息序号(可选,不传从最新开始)'),
9
+ count: z.number().optional().describe('获取条数(可选)'),
10
+ }),
11
+ adapter: 'napcat',
12
+ tags: ['napcat', 'qq'],
13
+ keywords: ['群消息历史', '聊天记录', 'message history'],
14
+ scopes: ['group'],
15
+ async execute({ group_id, message_seq, count }: { group_id: number; message_seq?: number; count?: number }, context) {
16
+ const endpoint = context.$client;
17
+ return endpoint.getGroupMsgHistory(group_id, message_seq, count);
18
+ },
19
+ });
@@ -0,0 +1,17 @@
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
+ import { z } from 'zod';
3
+
4
+ export default defineAgentTool<{ group_id: number }>({
5
+ description: '获取群公告列表。',
6
+ inputSchema: z.object({
7
+ group_id: z.number().describe('群号'),
8
+ }),
9
+ adapter: 'napcat',
10
+ tags: ['napcat', 'qq'],
11
+ keywords: ['群公告', '获取公告', 'get notice'],
12
+ scopes: ['group'],
13
+ async execute({ group_id }: { group_id: number }, context) {
14
+ const endpoint = context.$client;
15
+ return endpoint.getGroupNotice(group_id);
16
+ },
17
+ });
@@ -0,0 +1,17 @@
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
+ import { z } from 'zod';
3
+
4
+ export default defineAgentTool<{ group_id: number }>({
5
+ description: '获取群根目录文件列表。',
6
+ inputSchema: z.object({
7
+ group_id: z.number().describe('群号'),
8
+ }),
9
+ adapter: 'napcat',
10
+ tags: ['napcat', 'qq'],
11
+ keywords: ['群文件列表', 'group files'],
12
+ scopes: ['group'],
13
+ async execute({ group_id }: { group_id: number }, context) {
14
+ const endpoint = context.$client;
15
+ return endpoint.getGroupRootFiles(group_id);
16
+ },
17
+ });
@@ -0,0 +1,17 @@
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
+ import { z } from 'zod';
3
+
4
+ export default defineAgentTool<{ group_id: number }>({
5
+ description: '获取群禁言列表。',
6
+ inputSchema: z.object({
7
+ group_id: z.number().describe('群号'),
8
+ }),
9
+ adapter: 'napcat',
10
+ tags: ['napcat', 'qq'],
11
+ keywords: ['禁言列表', 'shut list', '被禁言'],
12
+ scopes: ['group'],
13
+ async execute({ group_id }: { group_id: number }, context) {
14
+ const endpoint = context.$client;
15
+ return endpoint.getGroupShutList(group_id);
16
+ },
17
+ });
@@ -0,0 +1,20 @@
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
+ import { z } from 'zod';
3
+
4
+ export default defineAgentTool<{ type: string; title: string; desc: string; pic_url: string; jump_url: string }>({
5
+ description: '签名小程序卡片(如 B 站分享卡片等)。',
6
+ inputSchema: z.object({
7
+ type: z.string().describe('卡片类型'),
8
+ title: z.string().describe('标题'),
9
+ desc: z.string().describe('描述'),
10
+ pic_url: z.string().describe('图片 URL'),
11
+ jump_url: z.string().describe('跳转 URL'),
12
+ }),
13
+ adapter: 'napcat',
14
+ tags: ['napcat', 'qq'],
15
+ keywords: ['小程序', 'mini app', '卡片', 'ark'],
16
+ async execute({ type, title, desc, pic_url, jump_url }: { type: string; title: string; desc: string; pic_url: string; jump_url: string }, context) {
17
+ const endpoint = context.$client;
18
+ return endpoint.getMiniAppArk(type, title, desc, pic_url, jump_url);
19
+ },
20
+ });