@zhin.js/adapter-napcat 3.0.1 → 4.0.1

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 (140) hide show
  1. package/CHANGELOG.md +58 -0
  2. package/README.md +43 -96
  3. package/adapters/napcat.ts +39 -0
  4. package/agent/tools/ai_tts.ts +21 -0
  5. package/agent/tools/del_group_notice.ts +22 -0
  6. package/agent/tools/delete_essence_msg.ts +21 -0
  7. package/agent/tools/delete_friend.ts +20 -0
  8. package/agent/tools/download_file.ts +19 -0
  9. package/agent/tools/forward_single_msg.ts +32 -0
  10. package/agent/tools/get_ai_characters.ts +19 -0
  11. package/agent/tools/get_essence_list.ts +19 -0
  12. package/agent/tools/get_friend_msg_history.ts +20 -0
  13. package/agent/tools/get_group_file_url.ts +21 -0
  14. package/agent/tools/get_group_info_ex.ts +19 -0
  15. package/agent/tools/get_group_msg_history.ts +21 -0
  16. package/agent/tools/get_group_notice.ts +19 -0
  17. package/agent/tools/get_group_root_files.ts +19 -0
  18. package/agent/tools/get_group_shut_list.ts +19 -0
  19. package/agent/tools/get_mini_app_ark.ts +22 -0
  20. package/agent/tools/get_user_status.ts +18 -0
  21. package/agent/tools/group_sign.ts +20 -0
  22. package/agent/tools/mark_msg_as_read.ts +19 -0
  23. package/agent/tools/ocr_image.ts +18 -0
  24. package/agent/tools/send_forward_msg.ts +31 -0
  25. package/agent/tools/send_group_notice.ts +23 -0
  26. package/agent/tools/send_like.ts +20 -0
  27. package/agent/tools/send_poke.ts +20 -0
  28. package/agent/tools/set_avatar.ts +19 -0
  29. package/agent/tools/set_emoji_reaction.ts +20 -0
  30. package/agent/tools/set_essence_msg.ts +21 -0
  31. package/agent/tools/set_group_portrait.ts +22 -0
  32. package/agent/tools/set_online_status.ts +20 -0
  33. package/agent/tools/set_profile.ts +23 -0
  34. package/agent/tools/set_signature.ts +19 -0
  35. package/agent/tools/set_title.ts +23 -0
  36. package/agent/tools/translate.ts +18 -0
  37. package/agent/tools/upload_group_file.ts +23 -0
  38. package/lib/http-endpoint.d.ts +26 -0
  39. package/lib/http-endpoint.js +147 -0
  40. package/lib/index.d.ts +11 -21
  41. package/lib/index.js +10 -59
  42. package/lib/napcat-agent-deps.d.ts +51 -0
  43. package/lib/napcat-agent-deps.js +33 -0
  44. package/lib/napcat-inbound.d.ts +12 -5
  45. package/lib/napcat-inbound.js +28 -13
  46. package/lib/onebot-get-msg.d.ts +13 -2
  47. package/lib/onebot-get-msg.js +0 -1
  48. package/lib/protocol.d.ts +151 -0
  49. package/lib/protocol.js +217 -0
  50. package/lib/webhook.d.ts +2 -0
  51. package/lib/webhook.js +14 -0
  52. package/lib/ws-endpoint.d.ts +61 -0
  53. package/lib/ws-endpoint.js +357 -0
  54. package/lib/ws-transport.d.ts +13 -0
  55. package/lib/ws-transport.js +75 -0
  56. package/lib/ws-types.d.ts +17 -0
  57. package/lib/ws-types.js +1 -0
  58. package/lib/wss-auth.d.ts +2 -0
  59. package/lib/wss-auth.js +16 -0
  60. package/lib/wss-endpoint.d.ts +25 -0
  61. package/lib/wss-endpoint.js +157 -0
  62. package/package.json +48 -32
  63. package/plugin.ts +13 -0
  64. package/schema.json +48 -0
  65. package/src/http-endpoint.ts +197 -0
  66. package/src/index.ts +66 -82
  67. package/src/napcat-agent-deps.ts +95 -0
  68. package/src/napcat-inbound.ts +34 -10
  69. package/src/onebot-get-msg.ts +8 -2
  70. package/src/protocol.ts +373 -0
  71. package/src/webhook.ts +16 -0
  72. package/src/ws-endpoint.ts +452 -0
  73. package/src/ws-transport.ts +105 -0
  74. package/src/ws-types.ts +20 -0
  75. package/src/wss-auth.ts +17 -0
  76. package/src/wss-endpoint.ts +205 -0
  77. package/client/NapCatManagement.tsx +0 -113
  78. package/client/index.tsx +0 -11
  79. package/client/tsconfig.json +0 -7
  80. package/client/utils/api.ts +0 -30
  81. package/dist/index.js +0 -27
  82. package/lib/adapter.d.ts +0 -36
  83. package/lib/adapter.d.ts.map +0 -1
  84. package/lib/adapter.js +0 -102
  85. package/lib/adapter.js.map +0 -1
  86. package/lib/agent-prompt.d.ts +0 -3
  87. package/lib/agent-prompt.d.ts.map +0 -1
  88. package/lib/agent-prompt.js +0 -106
  89. package/lib/agent-prompt.js.map +0 -1
  90. package/lib/endpoint-base.d.ts +0 -144
  91. package/lib/endpoint-base.d.ts.map +0 -1
  92. package/lib/endpoint-base.js +0 -341
  93. package/lib/endpoint-base.js.map +0 -1
  94. package/lib/endpoint-http.d.ts +0 -17
  95. package/lib/endpoint-http.d.ts.map +0 -1
  96. package/lib/endpoint-http.js +0 -106
  97. package/lib/endpoint-http.js.map +0 -1
  98. package/lib/endpoint-ws-client.d.ts +0 -20
  99. package/lib/endpoint-ws-client.d.ts.map +0 -1
  100. package/lib/endpoint-ws-client.js +0 -139
  101. package/lib/endpoint-ws-client.js.map +0 -1
  102. package/lib/endpoint-ws-server.d.ts +0 -20
  103. package/lib/endpoint-ws-server.d.ts.map +0 -1
  104. package/lib/endpoint-ws-server.js +0 -137
  105. package/lib/endpoint-ws-server.js.map +0 -1
  106. package/lib/index.d.ts.map +0 -1
  107. package/lib/index.js.map +0 -1
  108. package/lib/napcat-inbound.d.ts.map +0 -1
  109. package/lib/napcat-inbound.js.map +0 -1
  110. package/lib/onebot-get-msg.d.ts.map +0 -1
  111. package/lib/onebot-get-msg.js.map +0 -1
  112. package/lib/routes.d.ts +0 -4
  113. package/lib/routes.d.ts.map +0 -1
  114. package/lib/routes.js +0 -61
  115. package/lib/routes.js.map +0 -1
  116. package/lib/segment-mapper.d.ts +0 -2
  117. package/lib/segment-mapper.d.ts.map +0 -1
  118. package/lib/segment-mapper.js +0 -2
  119. package/lib/segment-mapper.js.map +0 -1
  120. package/lib/tools.d.ts +0 -8
  121. package/lib/tools.d.ts.map +0 -1
  122. package/lib/tools.js +0 -605
  123. package/lib/tools.js.map +0 -1
  124. package/lib/types.d.ts +0 -275
  125. package/lib/types.d.ts.map +0 -1
  126. package/lib/types.js +0 -6
  127. package/lib/types.js.map +0 -1
  128. package/plugin.yml +0 -3
  129. package/src/adapter.ts +0 -109
  130. package/src/agent-prompt.ts +0 -116
  131. package/src/endpoint-base.ts +0 -386
  132. package/src/endpoint-http.ts +0 -95
  133. package/src/endpoint-ws-client.ts +0 -137
  134. package/src/endpoint-ws-server.ts +0 -136
  135. package/src/routes.ts +0 -61
  136. package/src/segment-mapper.ts +0 -1
  137. package/src/tools.ts +0 -632
  138. package/src/types.ts +0 -266
  139. /package/{skills/napcat → agent}/PERMITS.md +0 -0
  140. /package/{skills/napcat/SKILL.md → agent/skills/napcat.md} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,63 @@
1
1
  # @zhin.js/adapter-napcat
2
2
 
3
+ ## 4.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - cc5c94d: 约定式插件运行时迁移(breaking):插件与适配器由 `usePlugin()` / `extends Adapter` 迁移为 `definePlugin` / `defineAdapter` + `plugin.ts` + 约定目录(`adapters/`、`commands/`、`components/`、`tools/` 等)。
8
+
9
+ - 新增约定式运行时包:`@zhin.js/plugin-runtime`、`@zhin.js/adapter`、`@zhin.js/runtime`、`@zhin.js/host-http`(首版 1.0.0 走 init-publish,不在本 changeset 内 bump)。
10
+ - 全部 20 个平台适配器改为约定式 `defineAdapter`,旧 `usePlugin` / `extends Adapter` / `segment-mapper` 生产入口已删除;onebot11 反向 WSS、onebot12 webhook/wss、milky sse/webhook/wss、satori webhook、kook webhook、qq webhook/middleware 等 slice 1 推迟的连接模式已补齐。
11
+ - 游戏 / 工具 / 服务插件同步迁移到约定目录结构。
12
+ - CLI 增加 plugin-runtime host installer(http/database/outbound/schedule/console 等)。
13
+
14
+ 后续加固(同批):
15
+
16
+ - CLI:`zhin runtime start --daemon`(pidfile/崩溃拉起/风暴保护),orphan watchdog 防僵尸进程;legacy `zhin dev` / `zhin start` 已移除(含 `zhin restart`),`zhin stop` 兼容新 daemon。
17
+ - 安全:builtin 工具统一走 `security/policy-facade.ts` 的 `runToolPolicies`(声明式策略表,deny 优先);审计日志 close flush + 背压队列;`splitCompoundCommand` 引号感知、`extractCommandName` 去引号堵绕过。
18
+ - 日志:Logger 双堆栈修复、本地时区、`getLogger` 挂树(`setLevel` 递归生效)、第三方库(log4js/discord)桥接、启动人读总结。
19
+ - 结构:`plugins/games/shared` 迁为 `packages/game-kit`(`@zhin.js/game-kit`);死目录 `plugins/adapters/common` 删除。
20
+ - 脚手架:`create-zhin-app` / `zhin new` / scaffold-wizard 生成物改为 Plugin Runtime 形态(minimal-bot 同构,新配置格式)。
21
+ - Console:endpoint.list 真实名称与 phase、schema:get-all 按 instanceKey 映射、db:\* 接 DatabaseHost。
22
+
23
+ 注:按仓库发布惯例(见 1bb345dd2),本次 breaking 迁移统一使用 patch,避免 zhin.js 5.0 级联。
24
+
25
+ - 447f3e2: 迁移缺口修复(legacy 功能对齐):
26
+
27
+ - html 段出站规范化:经 `@zhin.js/html-renderer` 渲染为 image 段(sandbox 豁免、无渲染器时降级文本),修复真实平台 `[object Object]`。
28
+ - 群聊 @ 触发 AI:适配器入站标注 `metadata.mentioned`(icqq/qq/slack/onebot11/onebot12/napcat/milky/discord/telegram/kook/dingtalk/satori),`matchAiTrigger` 补齐 ignorePrefixes/respondToAt/respondToPrivate/keywords(默认值与 legacy 对齐)。
29
+ - im_transcripts 全量流水恢复写入(chat_history 工具可用);群聊旁听上下文回迁。
30
+ - `ai.trigger.timeout/thinkingMessage/errorTemplate` 生效;masters/trusted 角色解析对齐 legacy。
31
+ - `Message.sender` 统一为用户 ID(onebot11/12、napcat、milky 原误传显示名);quote_id 经 metadata 接入 AI 引用上下文。
32
+
33
+ - Updated dependencies [16ec4e8]
34
+ - Updated dependencies [cc5c94d]
35
+ - Updated dependencies [447f3e2]
36
+ - @zhin.js/core@1.3.5
37
+ - @zhin.js/agent@1.0.4
38
+ - @zhin.js/host-http@1.0.1
39
+ - zhin.js@4.1.3
40
+ - @zhin.js/logger@1.0.75
41
+ - @zhin.js/plugin-runtime@1.0.1
42
+ - @zhin.js/adapter@1.0.1
43
+
44
+ ## 3.0.2
45
+
46
+ ### Patch Changes
47
+
48
+ - 872c583: Slack 适配器 Phase 1/2:mrkdwn 出站、长消息切分、斜杠/按钮 ephemeral 反馈、入站 mrkdwn→Markdown、editMessage 对齐 core。
49
+
50
+ Logger 表格日志与 string-width 列宽;Agent AI Handler 框线表格与 introspection/MCP 导出;Core side-event 归一化;Schedule 时区规划;多适配器 side-event 与 API surface 更新。
51
+
52
+ - 872c583: fix: 代码格式优化
53
+ - Updated dependencies [872c583]
54
+ - Updated dependencies [872c583]
55
+ - @zhin.js/agent@1.0.3
56
+ - @zhin.js/contract@1.0.3
57
+ - @zhin.js/host-api@2.0.5
58
+ - @zhin.js/host-router@2.0.3
59
+ - zhin.js@4.1.2
60
+
3
61
  ## 3.0.1
4
62
 
5
63
  ### Patch Changes
package/README.md CHANGED
@@ -1,45 +1,38 @@
1
1
  # @zhin.js/adapter-napcat
2
2
 
3
- > **QQ 群助手 + 可选 @AI** — 先在 [demo.zhin.dev](https://demo.zhin.dev) 或 Sandbox 调试,再接 NapCat。启用 AI:`npx zhin setup --ai`。接入本适配器:`npx zhin setup --adapters`。
4
-
5
- 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`)。
6
4
 
7
5
  ## 功能特性
8
6
 
9
- - 完整 OneBot v11 协议兼容 + go-cqhttp 扩展 + NapCat 独有 API(92+ 接口)
10
- - **单一适配器**:`context: napcat`,通过 `connection` 选择连接方式
11
- - **正向 WebSocket**(`connection: ws`):应用连 NapCat 的 WS
12
- - **反向 WebSocket**(`connection: wss`):应用开 WS 服务端,NapCat 连上来
13
- - **HTTP API + POST 上报**(`connection: http`):出站 HTTP 调用,入站 webhook
14
- - Access Token 认证支持(Bearer / HMAC 签名)
15
- - 自动重连机制(WS)与心跳检测
16
- - 群聊和私聊消息处理
17
- - 入站消息去重与 bot 自发消息过滤
18
- - Typing Indicator(处理中提示:群聊表情回应 / 私聊输入状态)
19
- - 41 个 AI 工具(群管、戳一戳、表情回应、精华消息、群公告、AI 语音等)
20
- - Console 管理页面(`/console/napcat`)
21
- - 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
+ - 入站经 `messageGatewayToken`(去重 + 自发过滤);出站 `send({ target, payload })`
12
+ - 41 个 AI 工具(`agent/tools/`)
22
13
 
23
14
  ## 安装
24
15
 
25
16
  ```bash
26
- pnpm add @zhin.js/adapter-napcat ws
17
+ pnpm add @zhin.js/adapter-napcat
27
18
  ```
28
19
 
29
- 反向 WS / HTTP 模式需同时启用 `@zhin.js/host-router`。
20
+ ## Plugin Runtime
30
21
 
31
- ## 配置
22
+ - `@zhin.js/adapter` — 约定式 `adapters/napcat.ts`(`defineAdapter`)
23
+ - `@zhin.js/core` — `messageGatewayToken` 入站/出站
24
+ - `@zhin.js/plugin-runtime` — `plugin.ts`(`definePlugin`)
25
+ - 配置经插件 `schema.json` 落到 `plugins.<instanceKey>`
32
26
 
33
- 所有 Endpoint 使用 **同一 context:`napcat`**,通过 **`connection`** 区分连接方式。
27
+ 入站:`gateway.receive({ adapter, target: "private:uid"|"group:gid", content, sender, metadata })`
28
+ 出站:`send({ target, payload })` → WS `send_private_msg` / `send_group_msg`
34
29
 
35
- ### 正向 WebSocket(connection: ws)
30
+ ## 最小配置
36
31
 
37
32
  ```yaml
33
+ # zhin.config.yml(Plugin Runtime)
38
34
  plugins:
39
- - "@zhin.js/adapter-napcat"
40
-
41
- endpoints:
42
- - context: napcat
35
+ napcat:
43
36
  connection: ws
44
37
  name: my-bot
45
38
  url: "ws://127.0.0.1:3001"
@@ -48,86 +41,40 @@ endpoints:
48
41
  heartbeat_interval: 30000
49
42
  ```
50
43
 
51
- ### 反向 WebSocket(connection: wss)
52
-
53
- ```yaml
54
- plugins:
55
- - "@zhin.js/host-router"
56
- - "@zhin.js/adapter-napcat"
57
-
58
- endpoints:
59
- - context: napcat
60
- connection: wss
61
- name: my-bot
62
- path: "/napcat/ws"
63
- access_token: "${NAPCAT_TOKEN}"
64
- heartbeat_interval: 30000
65
- ```
66
-
67
- ### HTTP API + POST 上报(connection: http)
68
-
69
- ```yaml
70
- plugins:
71
- - "@zhin.js/host-router"
72
- - "@zhin.js/adapter-napcat"
44
+ 根插件 `zhin.plugins`(或项目图)需引用 `@zhin.js/adapter-napcat`(`instanceKey: napcat`)。
73
45
 
74
- endpoints:
75
- - context: napcat
76
- connection: http
77
- name: my-bot
78
- http_url: "http://127.0.0.1:3000"
79
- post_path: "/napcat/post"
80
- access_token: "${NAPCAT_TOKEN}"
81
- poll_interval: 30000
82
- ```
46
+ ## 连接方式
83
47
 
84
- ### Typing Indicator(处理中提示)
48
+ | connection | 状态 |
49
+ |------------|------|
50
+ | `ws` | 已实现(推荐) |
51
+ | `wss` | 已实现:反向 WS(httpHostToken) |
52
+ | `http` | 已实现:POST 入站 + `http_url/{action}` 出站 |
85
53
 
86
- ```yaml
87
- endpoints:
88
- - context: napcat
89
- connection: ws
90
- name: my-bot
91
- url: "ws://127.0.0.1:3001"
92
- typingIndicator:
93
- enabled: true
94
- defaultEmoji: "128516"
95
- privateConfig:
96
- type: "message"
97
- message: "正在思考中..."
98
- groupConfig:
99
- type: "reaction"
100
- emoji: "128516"
101
- ```
54
+ ## 鉴权
102
55
 
103
- ## NapCat 独有能力
56
+ - **Bearer**:`Authorization: Bearer <access_token>`
57
+ - 正向 WS 在 Upgrade 时附带请求头,并在 URL query 写入 `access_token`
104
58
 
105
- 相比标准 OneBot11 适配器,NapCat 额外支持:
59
+ ## AI 工具
106
60
 
107
- - 戳一戳(群聊 / 私聊)
108
- - 表情回应(贴表情)
109
- - 合并 / 单条消息转发
110
- - 精华消息管理
111
- - 群公告管理
112
- - 群文件管理
113
- - AI 语音 TTS
114
- - 图片 OCR 文字识别
115
- - 小程序卡片签名
116
- - 个人资料 / 头像 / 签名修改
117
- - 在线状态设置
118
- - 消息历史查询
119
- - 英译中翻译
61
+ | 类别 | 路径 |
62
+ |------|------|
63
+ | Permit 词汇 | `agent/PERMITS.md` |
64
+ | 平台工具 | `agent/tools/*.ts` |
65
+ | 技能说明 | `agent/skills/napcat.md` |
120
66
 
121
- ## AI 工具
67
+ ## 迁移说明(Plugin Runtime)
122
68
 
123
- 适配器自动注册 41 个 AI 工具(7 个群管理标准工具 + 34 个 NapCat 扩展工具),详见 `skills/napcat/SKILL.md`。
69
+ - **notice / request 侧事件已移除**:旧 Adapter 对 `post_type: notice|request` 构建 `notice.receive` / `request.receive` 事件(含 `$approve` / `$reject`);新 Plugin Runtime(`messageGatewayToken`)暂无侧事件总线,入站仅处理 `post_type: message`,notice / request 事件静默丢弃。加好友 / 加群请求审批可改用 `callApi('set_friend_add_request' | 'set_group_add_request')`。
70
+ - **群管工具暂未迁移**:旧 Adapter 经 `createSceneManagementTools` 注册踢人 / 禁言 / 群名片等成套 agent 工具;迁移后 `agent/tools/` 仅覆盖 NapCat 扩展 API,其余群管能力可通过 `callApi`(如 `set_group_kick`、`set_group_ban`)作为逃生舱调用。
71
+ - **平台权限门禁**:`plugin.ts` setup 已注册 `registerDefaultScenePlatformPermitChecker('napcat')`,`scene_admin` / `scene_owner` 依据入站 metadata 中的 sender `role`(owner / admin)判定。
124
72
 
125
- ## full-bot L4 参考
73
+ ## 文档链接
126
74
 
127
- [`examples/full-bot`](../../../examples/full-bot/) 默认加载本适配器(`endpoints` 段需自行填写 `ONEBOT11_*` 后取消注释)。
75
+ - [NapCatQQ](https://github.com/NapNeko/NapCatQQ)
76
+ - [适配器概览](https://zhin.js.org/essentials/adapters)
128
77
 
129
- - 入站 → `ZhinAgent` → 出站走 `Adapter.sendMessage` 统一链路
130
- - 契约测试:`plugins/adapters/napcat/tests/l4-contract.test.ts` + `integration.test.ts`(adapter-harness)
131
- - CI:`L4_SKIP_PLATFORM=1` 跳过实机;本地验证不设该变量并可配置 `ONEBOT11_WS_URL`
78
+ ## 许可证
132
79
 
133
- 详见 [full-bot ACCEPTANCE.md](../../../examples/full-bot/ACCEPTANCE.md)。
80
+ MIT License
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Convention entry: discover `adapters/napcat.ts` → defineAdapter.
3
+ */
4
+ import { defineAdapter } from '@zhin.js/adapter';
5
+ import { messageGatewayToken } from '@zhin.js/core/runtime';
6
+ import { httpHostToken } from '@zhin.js/host-http';
7
+ import { NapCatHttpEndpoint } from '../src/http-endpoint.js';
8
+ import { resolveNapCatConfig, type NapCatAdapterConfig } from '../src/protocol.js';
9
+ import { NapCatWsEndpoint } from '../src/ws-endpoint.js';
10
+ import { NapCatWssEndpoint } from '../src/wss-endpoint.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
+ export default defineAdapter<NapCatAdapterConfig>({
27
+ capabilities: ['inbound', 'outbound'],
28
+ create(context) {
29
+ const config = resolveNapCatConfig(context.config);
30
+ const gateway = context.use(messageGatewayToken);
31
+ if (config.connection === 'wss') {
32
+ return new NapCatWssEndpoint({ id: context.id, gateway, http: context.use(httpHostToken), config });
33
+ }
34
+ if (config.connection === 'http') {
35
+ return new NapCatHttpEndpoint({ id: context.id, gateway, http: context.use(httpHostToken), config });
36
+ }
37
+ return new NapCatWsEndpoint({ id: context.id, gateway, config });
38
+ },
39
+ });
@@ -0,0 +1,21 @@
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
+ import { z } from 'zod';
3
+ import { getEndpoint } from '../../src/napcat-agent-deps.js';
4
+
5
+ export default defineAgentTool<{ endpoint_id: string; group_id: number; character: string; text: string }>({
6
+ description: 'AI 文字转语音,在群聊中发送 AI 语音消息。',
7
+ inputSchema: z.object({
8
+ endpoint_id: z.string().describe('Endpoint 名称'),
9
+ group_id: z.number().describe('群号'),
10
+ character: z.string().describe('AI 语音角色 ID(可先用 napcat_get_ai_characters 查询)'),
11
+ text: z.string().describe('要转为语音的文字'),
12
+ }),
13
+ platforms: ['napcat'],
14
+ tags: ['napcat', 'qq'],
15
+ keywords: ['AI语音', 'TTS', '文字转语音', 'ai record'],
16
+ scopes: ['group'],
17
+ async execute({ endpoint_id, group_id, character, text }: { endpoint_id: string; group_id: number; character: string; text: string }) {
18
+ const endpoint = getEndpoint(endpoint_id);
19
+ return endpoint.sendGroupAiRecord(group_id, character, text);
20
+ },
21
+ });
@@ -0,0 +1,22 @@
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
+ import { z } from 'zod';
3
+ import { getEndpoint } from '../../src/napcat-agent-deps.js';
4
+
5
+ export default defineAgentTool<{ endpoint_id: string; group_id: number; notice_id: string }>({
6
+ description: '删除群公告。',
7
+ inputSchema: z.object({
8
+ endpoint_id: z.string().describe('Endpoint 名称'),
9
+ group_id: z.number().describe('群号'),
10
+ notice_id: z.string().describe('公告 ID'),
11
+ }),
12
+ platforms: ['napcat'],
13
+ tags: ['napcat', 'qq'],
14
+ keywords: ['删除公告', 'delete notice'],
15
+ permissions: ['platform(napcat,scene_admin)'],
16
+ scopes: ['group'],
17
+ async execute({ endpoint_id, group_id, notice_id }: { endpoint_id: string; group_id: number; notice_id: string }) {
18
+ const endpoint = getEndpoint(endpoint_id);
19
+ await endpoint.deleteGroupNotice(group_id, notice_id);
20
+ return { success: true };
21
+ },
22
+ });
@@ -0,0 +1,21 @@
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
+ import { z } from 'zod';
3
+ import { getEndpoint } from '../../src/napcat-agent-deps.js';
4
+
5
+ export default defineAgentTool<{ endpoint_id: string; message_id: number }>({
6
+ description: '移除群精华消息。',
7
+ inputSchema: z.object({
8
+ endpoint_id: z.string().describe('Endpoint 名称'),
9
+ message_id: z.number().describe('消息 ID'),
10
+ }),
11
+ platforms: ['napcat'],
12
+ tags: ['napcat', 'qq'],
13
+ keywords: ['取消精华', '移除精华', 'delete essence'],
14
+ permissions: ['platform(napcat,scene_admin)'],
15
+ scopes: ['group'],
16
+ async execute({ endpoint_id, message_id }: { endpoint_id: string; message_id: number }) {
17
+ const endpoint = getEndpoint(endpoint_id);
18
+ await endpoint.deleteEssenceMsg(message_id);
19
+ return { success: true };
20
+ },
21
+ });
@@ -0,0 +1,20 @@
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
+ import { z } from 'zod';
3
+ import { getEndpoint } from '../../src/napcat-agent-deps.js';
4
+
5
+ export default defineAgentTool<{ endpoint_id: string; user_id: number }>({
6
+ description: '删除好友。',
7
+ inputSchema: z.object({
8
+ endpoint_id: z.string().describe('Endpoint 名称'),
9
+ user_id: z.number().describe('好友 QQ 号'),
10
+ }),
11
+ platforms: ['napcat'],
12
+ tags: ['napcat', 'qq'],
13
+ keywords: ['删除好友', 'delete friend', '删好友'],
14
+ permissions: ['platform(napcat,scene_admin)'],
15
+ async execute({ endpoint_id, user_id }: { endpoint_id: string; user_id: number }) {
16
+ const endpoint = getEndpoint(endpoint_id);
17
+ await endpoint.deleteFriend(user_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
+ import { getEndpoint } from '../../src/napcat-agent-deps.js';
4
+
5
+ export default defineAgentTool<{ endpoint_id: string; url: string; thread_count?: number }>({
6
+ description: '下载文件到 NapCat 缓存目录,返回本地路径。',
7
+ inputSchema: z.object({
8
+ endpoint_id: z.string().describe('Endpoint 名称'),
9
+ url: z.string().describe('文件 URL'),
10
+ thread_count: z.number().optional().describe('下载线程数(可选,默认 1)'),
11
+ }),
12
+ platforms: ['napcat'],
13
+ tags: ['napcat', 'qq'],
14
+ keywords: ['下载', 'download', '下载文件'],
15
+ async execute({ endpoint_id, url, thread_count }: { endpoint_id: string; url: string; thread_count?: number }) {
16
+ const endpoint = getEndpoint(endpoint_id);
17
+ return endpoint.downloadFile(url, thread_count || 1);
18
+ },
19
+ });
@@ -0,0 +1,32 @@
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
+ import { z } from 'zod';
3
+ import { getEndpoint } from '../../src/napcat-agent-deps.js';
4
+
5
+ export default defineAgentTool<{
6
+ endpoint_id: string;
7
+ target_type: 'friend' | 'group';
8
+ target_id: number;
9
+ message_id: number;
10
+ }>({
11
+ description: '转发单条消息到指定好友或群。',
12
+ inputSchema: z.object({
13
+ endpoint_id: z.string().describe('Endpoint 名称'),
14
+ target_type: z.enum(['friend', 'group']).describe('friend 或 group'),
15
+ target_id: z.number().describe('目标好友 QQ 号或群号'),
16
+ message_id: z.number().describe('要转发的消息 ID'),
17
+ }),
18
+ platforms: ['napcat'],
19
+ tags: ['napcat', 'qq'],
20
+ keywords: ['转发', 'forward', '单条转发'],
21
+ async execute({ endpoint_id, target_type, target_id, message_id }: {
22
+ endpoint_id: string;
23
+ target_type: 'friend' | 'group';
24
+ target_id: number;
25
+ message_id: number;
26
+ }) {
27
+ const endpoint = getEndpoint(endpoint_id);
28
+ if (target_type === 'friend') await endpoint.forwardFriendSingleMsg(target_id, message_id);
29
+ else await endpoint.forwardGroupSingleMsg(target_id, message_id);
30
+ return { success: true };
31
+ },
32
+ });
@@ -0,0 +1,19 @@
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
+ import { z } from 'zod';
3
+ import { getEndpoint } from '../../src/napcat-agent-deps.js';
4
+
5
+ export default defineAgentTool<{ endpoint_id: string; group_id: number }>({
6
+ description: '获取 AI 语音角色列表,用于 napcat_ai_tts 的 character 参数。',
7
+ inputSchema: z.object({
8
+ endpoint_id: z.string().describe('Endpoint 名称'),
9
+ group_id: z.number().describe('群号'),
10
+ }),
11
+ platforms: ['napcat'],
12
+ tags: ['napcat', 'qq'],
13
+ keywords: ['AI角色', 'ai characters', '语音角色'],
14
+ scopes: ['group'],
15
+ async execute({ endpoint_id, group_id }: { endpoint_id: string; group_id: number }) {
16
+ const endpoint = getEndpoint(endpoint_id);
17
+ return endpoint.getAiCharacters(group_id);
18
+ },
19
+ });
@@ -0,0 +1,19 @@
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
+ import { z } from 'zod';
3
+ import { getEndpoint } from '../../src/napcat-agent-deps.js';
4
+
5
+ export default defineAgentTool<{ endpoint_id: string; group_id: number }>({
6
+ description: '获取群精华消息列表。',
7
+ inputSchema: z.object({
8
+ endpoint_id: z.string().describe('Endpoint 名称'),
9
+ group_id: z.number().describe('群号'),
10
+ }),
11
+ platforms: ['napcat'],
12
+ tags: ['napcat', 'qq'],
13
+ keywords: ['精华列表', 'essence list'],
14
+ scopes: ['group'],
15
+ async execute({ endpoint_id, group_id }: { endpoint_id: string; group_id: number }) {
16
+ const endpoint = getEndpoint(endpoint_id);
17
+ return endpoint.getEssenceMsgList(group_id);
18
+ },
19
+ });
@@ -0,0 +1,20 @@
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
+ import { z } from 'zod';
3
+ import { getEndpoint } from '../../src/napcat-agent-deps.js';
4
+
5
+ export default defineAgentTool<{ endpoint_id: string; user_id: number; message_seq?: number; count?: number }>({
6
+ description: '获取私聊消息历史记录。',
7
+ inputSchema: z.object({
8
+ endpoint_id: z.string().describe('Endpoint 名称'),
9
+ user_id: z.number().describe('QQ 号'),
10
+ message_seq: z.number().optional().describe('起始消息序号(可选)'),
11
+ count: z.number().optional().describe('获取条数(可选)'),
12
+ }),
13
+ platforms: ['napcat'],
14
+ tags: ['napcat', 'qq'],
15
+ keywords: ['私聊记录', '好友聊天记录', 'friend history'],
16
+ async execute({ endpoint_id, user_id, message_seq, count }: { endpoint_id: string; user_id: number; message_seq?: number; count?: number }) {
17
+ const endpoint = getEndpoint(endpoint_id);
18
+ return endpoint.getFriendMsgHistory(user_id, message_seq, count);
19
+ },
20
+ });
@@ -0,0 +1,21 @@
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
+ import { z } from 'zod';
3
+ import { getEndpoint } from '../../src/napcat-agent-deps.js';
4
+
5
+ export default defineAgentTool<{ endpoint_id: string; group_id: number; file_id: string; busid: number }>({
6
+ description: '获取群文件下载链接。',
7
+ inputSchema: z.object({
8
+ endpoint_id: z.string().describe('Endpoint 名称'),
9
+ group_id: z.number().describe('群号'),
10
+ file_id: z.string().describe('文件 ID'),
11
+ busid: z.number().describe('文件类型 ID'),
12
+ }),
13
+ platforms: ['napcat'],
14
+ tags: ['napcat', 'qq'],
15
+ keywords: ['文件链接', 'file url', '下载文件'],
16
+ scopes: ['group'],
17
+ async execute({ endpoint_id, group_id, file_id, busid }: { endpoint_id: string; group_id: number; file_id: string; busid: number }) {
18
+ const endpoint = getEndpoint(endpoint_id);
19
+ return endpoint.getGroupFileUrl(group_id, file_id, busid);
20
+ },
21
+ });
@@ -0,0 +1,19 @@
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
+ import { z } from 'zod';
3
+ import { getEndpoint } from '../../src/napcat-agent-deps.js';
4
+
5
+ export default defineAgentTool<{ endpoint_id: string; group_id: number }>({
6
+ description: '获取群组额外详细信息。',
7
+ inputSchema: z.object({
8
+ endpoint_id: z.string().describe('Endpoint 名称'),
9
+ group_id: z.number().describe('群号'),
10
+ }),
11
+ platforms: ['napcat'],
12
+ tags: ['napcat', 'qq'],
13
+ keywords: ['群详情', '群额外信息', 'group info ex'],
14
+ scopes: ['group'],
15
+ async execute({ endpoint_id, group_id }: { endpoint_id: string; group_id: number }) {
16
+ const endpoint = getEndpoint(endpoint_id);
17
+ return endpoint.getGroupInfoEx(group_id);
18
+ },
19
+ });
@@ -0,0 +1,21 @@
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
+ import { z } from 'zod';
3
+ import { getEndpoint } from '../../src/napcat-agent-deps.js';
4
+
5
+ export default defineAgentTool<{ endpoint_id: string; group_id: number; message_seq?: number; count?: number }>({
6
+ description: '获取群消息历史记录。',
7
+ inputSchema: z.object({
8
+ endpoint_id: z.string().describe('Endpoint 名称'),
9
+ group_id: z.number().describe('群号'),
10
+ message_seq: z.number().optional().describe('起始消息序号(可选,不传从最新开始)'),
11
+ count: z.number().optional().describe('获取条数(可选)'),
12
+ }),
13
+ platforms: ['napcat'],
14
+ tags: ['napcat', 'qq'],
15
+ keywords: ['群消息历史', '聊天记录', 'message history'],
16
+ scopes: ['group'],
17
+ async execute({ endpoint_id, group_id, message_seq, count }: { endpoint_id: string; group_id: number; message_seq?: number; count?: number }) {
18
+ const endpoint = getEndpoint(endpoint_id);
19
+ return endpoint.getGroupMsgHistory(group_id, message_seq, count);
20
+ },
21
+ });
@@ -0,0 +1,19 @@
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
+ import { z } from 'zod';
3
+ import { getEndpoint } from '../../src/napcat-agent-deps.js';
4
+
5
+ export default defineAgentTool<{ endpoint_id: string; group_id: number }>({
6
+ description: '获取群公告列表。',
7
+ inputSchema: z.object({
8
+ endpoint_id: z.string().describe('Endpoint 名称'),
9
+ group_id: z.number().describe('群号'),
10
+ }),
11
+ platforms: ['napcat'],
12
+ tags: ['napcat', 'qq'],
13
+ keywords: ['群公告', '获取公告', 'get notice'],
14
+ scopes: ['group'],
15
+ async execute({ endpoint_id, group_id }: { endpoint_id: string; group_id: number }) {
16
+ const endpoint = getEndpoint(endpoint_id);
17
+ return endpoint.getGroupNotice(group_id);
18
+ },
19
+ });
@@ -0,0 +1,19 @@
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
+ import { z } from 'zod';
3
+ import { getEndpoint } from '../../src/napcat-agent-deps.js';
4
+
5
+ export default defineAgentTool<{ endpoint_id: string; group_id: number }>({
6
+ description: '获取群根目录文件列表。',
7
+ inputSchema: z.object({
8
+ endpoint_id: z.string().describe('Endpoint 名称'),
9
+ group_id: z.number().describe('群号'),
10
+ }),
11
+ platforms: ['napcat'],
12
+ tags: ['napcat', 'qq'],
13
+ keywords: ['群文件列表', 'group files'],
14
+ scopes: ['group'],
15
+ async execute({ endpoint_id, group_id }: { endpoint_id: string; group_id: number }) {
16
+ const endpoint = getEndpoint(endpoint_id);
17
+ return endpoint.getGroupRootFiles(group_id);
18
+ },
19
+ });
@@ -0,0 +1,19 @@
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
+ import { z } from 'zod';
3
+ import { getEndpoint } from '../../src/napcat-agent-deps.js';
4
+
5
+ export default defineAgentTool<{ endpoint_id: string; group_id: number }>({
6
+ description: '获取群禁言列表。',
7
+ inputSchema: z.object({
8
+ endpoint_id: z.string().describe('Endpoint 名称'),
9
+ group_id: z.number().describe('群号'),
10
+ }),
11
+ platforms: ['napcat'],
12
+ tags: ['napcat', 'qq'],
13
+ keywords: ['禁言列表', 'shut list', '被禁言'],
14
+ scopes: ['group'],
15
+ async execute({ endpoint_id, group_id }: { endpoint_id: string; group_id: number }) {
16
+ const endpoint = getEndpoint(endpoint_id);
17
+ return endpoint.getGroupShutList(group_id);
18
+ },
19
+ });
@@ -0,0 +1,22 @@
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
+ import { z } from 'zod';
3
+ import { getEndpoint } from '../../src/napcat-agent-deps.js';
4
+
5
+ export default defineAgentTool<{ endpoint_id: string; type: string; title: string; desc: string; pic_url: string; jump_url: string }>({
6
+ description: '签名小程序卡片(如 B 站分享卡片等)。',
7
+ inputSchema: z.object({
8
+ endpoint_id: z.string().describe('Endpoint 名称'),
9
+ type: z.string().describe('卡片类型'),
10
+ title: z.string().describe('标题'),
11
+ desc: z.string().describe('描述'),
12
+ pic_url: z.string().describe('图片 URL'),
13
+ jump_url: z.string().describe('跳转 URL'),
14
+ }),
15
+ platforms: ['napcat'],
16
+ tags: ['napcat', 'qq'],
17
+ keywords: ['小程序', 'mini app', '卡片', 'ark'],
18
+ async execute({ endpoint_id, type, title, desc, pic_url, jump_url }: { endpoint_id: string; type: string; title: string; desc: string; pic_url: string; jump_url: string }) {
19
+ const endpoint = getEndpoint(endpoint_id);
20
+ return endpoint.getMiniAppArk(type, title, desc, pic_url, jump_url);
21
+ },
22
+ });