@zhin.js/core 1.1.34 → 1.1.37

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 (326) hide show
  1. package/README.md +84 -142
  2. package/lib/built/ai-access.d.ts +36 -0
  3. package/lib/built/ai-access.js +46 -0
  4. package/lib/built/ai-outbound/extensions/onebot-keyboard.d.ts +2 -0
  5. package/lib/built/ai-outbound/extensions/onebot-keyboard.js +67 -0
  6. package/lib/built/ai-outbound/extensions/qq-message.d.ts +3 -0
  7. package/lib/built/ai-outbound/extensions/qq-message.js +23 -0
  8. package/lib/built/ai-outbound/index.d.ts +8 -0
  9. package/lib/built/ai-outbound/index.js +8 -0
  10. package/lib/built/ai-outbound/parse.d.ts +13 -0
  11. package/lib/built/ai-outbound/parse.js +104 -0
  12. package/lib/built/ai-outbound/plain-mention-rewrite.d.ts +6 -0
  13. package/lib/built/ai-outbound/plain-mention-rewrite.js +37 -0
  14. package/lib/built/ai-outbound/prompt.d.ts +11 -0
  15. package/lib/built/ai-outbound/prompt.js +44 -0
  16. package/lib/built/ai-outbound/resolve.d.ts +4 -0
  17. package/lib/built/ai-outbound/resolve.js +64 -0
  18. package/lib/built/ai-outbound/structured-detect.d.ts +3 -0
  19. package/lib/built/ai-outbound/structured-detect.js +6 -0
  20. package/lib/built/ai-outbound/types.d.ts +49 -0
  21. package/lib/built/ai-outbound/types.js +5 -0
  22. package/lib/built/ai-trigger.d.ts +12 -17
  23. package/lib/built/ai-trigger.js +39 -70
  24. package/lib/built/common-adapter-tools.d.ts +33 -29
  25. package/lib/built/common-adapter-tools.js +79 -67
  26. package/lib/built/generated-qrcode.d.ts +24 -0
  27. package/lib/built/generated-qrcode.js +45 -0
  28. package/lib/built/generic-segment-mapper.d.ts +4 -0
  29. package/lib/built/generic-segment-mapper.js +190 -0
  30. package/lib/built/html-segment-fallback.d.ts +2 -5
  31. package/lib/built/html-segment-fallback.js +0 -16
  32. package/lib/built/html-to-text.d.ts +0 -1
  33. package/lib/built/html-to-text.js +15 -15
  34. package/lib/built/interactive-segments/action.d.ts +17 -0
  35. package/lib/built/interactive-segments/action.js +69 -0
  36. package/lib/built/interactive-segments/button-spec.d.ts +10 -0
  37. package/lib/built/interactive-segments/button-spec.js +21 -0
  38. package/lib/built/interactive-segments/index.d.ts +6 -0
  39. package/lib/built/interactive-segments/index.js +6 -0
  40. package/lib/built/interactive-segments/keyboard-segment.d.ts +10 -0
  41. package/lib/built/interactive-segments/keyboard-segment.js +11 -0
  42. package/lib/built/interactive-segments/onebot-keyboard.d.ts +6 -0
  43. package/lib/built/interactive-segments/onebot-keyboard.js +49 -0
  44. package/lib/built/interactive-segments/resolve.d.ts +14 -0
  45. package/lib/built/interactive-segments/resolve.js +109 -0
  46. package/lib/built/interactive-segments/types.d.ts +45 -0
  47. package/lib/built/interactive-segments/types.js +9 -0
  48. package/lib/built/login-assist.d.ts +43 -16
  49. package/lib/built/login-assist.js +113 -11
  50. package/lib/built/message-enrich.d.ts +32 -0
  51. package/lib/built/message-enrich.js +67 -0
  52. package/lib/built/outbound-media-utils.d.ts +9 -0
  53. package/lib/built/outbound-media-utils.js +62 -0
  54. package/lib/built/queue-im-field-contract.d.ts +7 -2
  55. package/lib/built/queue-im-field-contract.js +13 -4
  56. package/lib/built/rich-segments/markdown-to-text.d.ts +3 -0
  57. package/lib/built/rich-segments/markdown-to-text.js +27 -0
  58. package/lib/built/roles.d.ts +4 -5
  59. package/lib/built/roles.js +4 -5
  60. package/lib/built/segment-contract/assert.d.ts +7 -0
  61. package/lib/built/segment-contract/assert.js +39 -0
  62. package/lib/built/segment-contract/delivery.d.ts +5 -0
  63. package/lib/built/segment-contract/delivery.js +40 -0
  64. package/lib/built/segment-contract/image.d.ts +5 -0
  65. package/lib/built/segment-contract/image.js +10 -0
  66. package/lib/built/segment-contract/index.d.ts +10 -0
  67. package/lib/built/segment-contract/index.js +9 -0
  68. package/lib/built/segment-contract/json-schema.d.ts +28 -0
  69. package/lib/built/segment-contract/json-schema.js +128 -0
  70. package/lib/built/segment-contract/media.d.ts +12 -0
  71. package/lib/built/segment-contract/media.js +22 -0
  72. package/lib/built/segment-contract/mention.d.ts +10 -0
  73. package/lib/built/segment-contract/mention.js +26 -0
  74. package/lib/built/segment-contract/preview.d.ts +3 -0
  75. package/lib/built/segment-contract/preview.js +159 -0
  76. package/lib/built/segment-contract/text.d.ts +7 -0
  77. package/lib/built/segment-contract/text.js +34 -0
  78. package/lib/built/segment-contract/types.d.ts +58 -0
  79. package/lib/built/segment-contract/types.js +1 -0
  80. package/lib/built/segment-contract/validate.d.ts +229 -0
  81. package/lib/built/segment-contract/validate.js +172 -0
  82. package/lib/built/tool-access.d.ts +5 -0
  83. package/lib/built/tool-access.js +17 -0
  84. package/lib/built/user-interaction.d.ts +30 -0
  85. package/lib/built/user-interaction.js +244 -0
  86. package/lib/component.d.ts +0 -1
  87. package/lib/component.js +30 -14
  88. package/lib/errors.d.ts +2 -3
  89. package/lib/errors.js +4 -5
  90. package/lib/feature/adapter.d.ts +2 -0
  91. package/lib/feature/adapter.js +2 -0
  92. package/lib/feature/command.d.ts +2 -0
  93. package/lib/feature/command.js +2 -0
  94. package/lib/feature/component.d.ts +2 -0
  95. package/lib/feature/component.js +2 -0
  96. package/lib/feature/handler.d.ts +48 -0
  97. package/lib/feature/handler.js +26 -0
  98. package/lib/feature/middleware.d.ts +2 -0
  99. package/lib/feature/middleware.js +2 -0
  100. package/lib/im-scene.d.ts +29 -0
  101. package/lib/im-scene.js +75 -0
  102. package/lib/im-session-id.d.ts +39 -0
  103. package/lib/im-session-id.js +47 -0
  104. package/lib/index.d.ts +29 -36
  105. package/lib/index.js +27 -41
  106. package/lib/jsx-dev-runtime.d.ts +0 -1
  107. package/lib/jsx-dev-runtime.js +0 -1
  108. package/lib/jsx-runtime.d.ts +1 -1
  109. package/lib/jsx-runtime.js +0 -1
  110. package/lib/jsx.d.ts +19 -22
  111. package/lib/jsx.js +0 -1
  112. package/lib/message.d.ts +17 -12
  113. package/lib/message.js +16 -13
  114. package/lib/models/system-log.d.ts +0 -3
  115. package/lib/models/system-log.js +1 -9
  116. package/lib/models/user.d.ts +0 -3
  117. package/lib/models/user.js +1 -8
  118. package/lib/notice.d.ts +16 -60
  119. package/lib/notice.js +1 -4
  120. package/lib/plugin-runtime/im/contracts.d.ts +191 -0
  121. package/lib/plugin-runtime/im/contracts.js +169 -0
  122. package/lib/plugin-runtime/im/conversation-runtime.d.ts +19 -0
  123. package/lib/plugin-runtime/im/conversation-runtime.js +312 -0
  124. package/lib/plugin-runtime/im/endpoint-runtime.d.ts +79 -0
  125. package/lib/plugin-runtime/im/endpoint-runtime.js +162 -0
  126. package/lib/plugin-runtime/im/im-runtime.d.ts +84 -0
  127. package/lib/plugin-runtime/im/im-runtime.js +201 -0
  128. package/lib/plugin-runtime/im/inbound-runtime.d.ts +31 -0
  129. package/lib/plugin-runtime/im/inbound-runtime.js +252 -0
  130. package/lib/plugin-runtime/im/index.d.ts +11 -0
  131. package/lib/plugin-runtime/im/index.js +9 -0
  132. package/lib/plugin-runtime/im/ingress-route.d.ts +10 -0
  133. package/lib/plugin-runtime/im/ingress-route.js +10 -0
  134. package/lib/plugin-runtime/im/interaction-runtime.d.ts +23 -0
  135. package/lib/plugin-runtime/im/interaction-runtime.js +181 -0
  136. package/lib/plugin-runtime/im/interactive-router.d.ts +17 -0
  137. package/lib/plugin-runtime/im/interactive-router.js +98 -0
  138. package/lib/plugin-runtime/im/login-assist-host.d.ts +6 -0
  139. package/lib/plugin-runtime/im/login-assist-host.js +6 -0
  140. package/lib/plugin-runtime/im/message-bus.d.ts +38 -0
  141. package/lib/plugin-runtime/im/message-bus.js +40 -0
  142. package/lib/plugin-runtime/im/message-dispatcher.d.ts +18 -0
  143. package/lib/plugin-runtime/im/message-dispatcher.js +107 -0
  144. package/lib/plugin-runtime/im/message-events.d.ts +26 -0
  145. package/lib/plugin-runtime/im/message-events.js +61 -0
  146. package/lib/plugin-runtime/im/outbound-delivery-runtime.d.ts +19 -0
  147. package/lib/plugin-runtime/im/outbound-delivery-runtime.js +165 -0
  148. package/lib/plugin-runtime/im/outbound-renderer.d.ts +7 -0
  149. package/lib/plugin-runtime/im/outbound-renderer.js +70 -0
  150. package/lib/plugin-runtime/im/outbound-segments.d.ts +71 -0
  151. package/lib/plugin-runtime/im/outbound-segments.js +219 -0
  152. package/lib/plugin-runtime/im/public-api.d.ts +6 -0
  153. package/lib/plugin-runtime/im/public-api.js +6 -0
  154. package/lib/plugin-runtime/im/runtime-middleware.d.ts +3 -0
  155. package/lib/plugin-runtime/im/runtime-middleware.js +13 -0
  156. package/lib/request.d.ts +17 -62
  157. package/lib/request.js +0 -4
  158. package/lib/side-event/base.d.ts +51 -0
  159. package/lib/side-event/base.js +30 -0
  160. package/lib/side-event/dispatch.d.ts +15 -0
  161. package/lib/side-event/dispatch.js +140 -0
  162. package/lib/side-event/index.d.ts +4 -0
  163. package/lib/side-event/index.js +4 -0
  164. package/lib/side-event/normalize.d.ts +38 -0
  165. package/lib/side-event/normalize.js +111 -0
  166. package/lib/side-event/types.d.ts +23 -0
  167. package/lib/side-event/types.js +55 -0
  168. package/lib/system-event.d.ts +14 -0
  169. package/lib/system-event.js +7 -0
  170. package/lib/types.d.ts +35 -193
  171. package/lib/types.js +0 -1
  172. package/lib/utils.d.ts +81 -6
  173. package/lib/utils.js +54 -25
  174. package/package.json +94 -16
  175. package/lib/adapter.d.ts +0 -96
  176. package/lib/adapter.d.ts.map +0 -1
  177. package/lib/adapter.js +0 -217
  178. package/lib/adapter.js.map +0 -1
  179. package/lib/agent-prompt.d.ts +0 -37
  180. package/lib/agent-prompt.d.ts.map +0 -1
  181. package/lib/agent-prompt.js +0 -2
  182. package/lib/agent-prompt.js.map +0 -1
  183. package/lib/bot.d.ts +0 -38
  184. package/lib/bot.d.ts.map +0 -1
  185. package/lib/bot.js +0 -2
  186. package/lib/bot.js.map +0 -1
  187. package/lib/built/adapter-process.d.ts +0 -43
  188. package/lib/built/adapter-process.d.ts.map +0 -1
  189. package/lib/built/adapter-process.js +0 -81
  190. package/lib/built/adapter-process.js.map +0 -1
  191. package/lib/built/agent-preset.d.ts +0 -65
  192. package/lib/built/agent-preset.d.ts.map +0 -1
  193. package/lib/built/agent-preset.js +0 -80
  194. package/lib/built/agent-preset.js.map +0 -1
  195. package/lib/built/ai-trigger.d.ts.map +0 -1
  196. package/lib/built/ai-trigger.js.map +0 -1
  197. package/lib/built/command.d.ts +0 -68
  198. package/lib/built/command.d.ts.map +0 -1
  199. package/lib/built/command.js +0 -92
  200. package/lib/built/command.js.map +0 -1
  201. package/lib/built/common-adapter-tools.d.ts.map +0 -1
  202. package/lib/built/common-adapter-tools.js.map +0 -1
  203. package/lib/built/component.d.ts +0 -69
  204. package/lib/built/component.d.ts.map +0 -1
  205. package/lib/built/component.js +0 -99
  206. package/lib/built/component.js.map +0 -1
  207. package/lib/built/config.d.ts +0 -99
  208. package/lib/built/config.d.ts.map +0 -1
  209. package/lib/built/config.js +0 -355
  210. package/lib/built/config.js.map +0 -1
  211. package/lib/built/cron.d.ts +0 -75
  212. package/lib/built/cron.d.ts.map +0 -1
  213. package/lib/built/cron.js +0 -122
  214. package/lib/built/cron.js.map +0 -1
  215. package/lib/built/database.d.ts +0 -66
  216. package/lib/built/database.d.ts.map +0 -1
  217. package/lib/built/database.js +0 -100
  218. package/lib/built/database.js.map +0 -1
  219. package/lib/built/dispatcher.d.ts +0 -139
  220. package/lib/built/dispatcher.d.ts.map +0 -1
  221. package/lib/built/dispatcher.js +0 -361
  222. package/lib/built/dispatcher.js.map +0 -1
  223. package/lib/built/html-segment-fallback.d.ts.map +0 -1
  224. package/lib/built/html-segment-fallback.js.map +0 -1
  225. package/lib/built/html-to-text.d.ts.map +0 -1
  226. package/lib/built/html-to-text.js.map +0 -1
  227. package/lib/built/inbound-runner.d.ts +0 -23
  228. package/lib/built/inbound-runner.d.ts.map +0 -1
  229. package/lib/built/inbound-runner.js +0 -37
  230. package/lib/built/inbound-runner.js.map +0 -1
  231. package/lib/built/login-assist.d.ts.map +0 -1
  232. package/lib/built/login-assist.js.map +0 -1
  233. package/lib/built/mcp-mesh-registrar.d.ts +0 -9
  234. package/lib/built/mcp-mesh-registrar.d.ts.map +0 -1
  235. package/lib/built/mcp-mesh-registrar.js +0 -17
  236. package/lib/built/mcp-mesh-registrar.js.map +0 -1
  237. package/lib/built/message-filter.d.ts +0 -177
  238. package/lib/built/message-filter.d.ts.map +0 -1
  239. package/lib/built/message-filter.js +0 -241
  240. package/lib/built/message-filter.js.map +0 -1
  241. package/lib/built/permission.d.ts +0 -55
  242. package/lib/built/permission.d.ts.map +0 -1
  243. package/lib/built/permission.js +0 -112
  244. package/lib/built/permission.js.map +0 -1
  245. package/lib/built/prepend-quote-context.d.ts +0 -35
  246. package/lib/built/prepend-quote-context.d.ts.map +0 -1
  247. package/lib/built/prepend-quote-context.js +0 -131
  248. package/lib/built/prepend-quote-context.js.map +0 -1
  249. package/lib/built/queue-im-field-contract.d.ts.map +0 -1
  250. package/lib/built/queue-im-field-contract.js.map +0 -1
  251. package/lib/built/roles.d.ts.map +0 -1
  252. package/lib/built/roles.js.map +0 -1
  253. package/lib/built/runtime-io.d.ts +0 -10
  254. package/lib/built/runtime-io.d.ts.map +0 -1
  255. package/lib/built/runtime-io.js +0 -68
  256. package/lib/built/runtime-io.js.map +0 -1
  257. package/lib/built/schema-feature.d.ts +0 -78
  258. package/lib/built/schema-feature.d.ts.map +0 -1
  259. package/lib/built/schema-feature.js +0 -132
  260. package/lib/built/schema-feature.js.map +0 -1
  261. package/lib/built/skill.d.ts +0 -121
  262. package/lib/built/skill.d.ts.map +0 -1
  263. package/lib/built/skill.js +0 -152
  264. package/lib/built/skill.js.map +0 -1
  265. package/lib/built/tool.d.ts +0 -150
  266. package/lib/built/tool.d.ts.map +0 -1
  267. package/lib/built/tool.js +0 -383
  268. package/lib/built/tool.js.map +0 -1
  269. package/lib/command.d.ts +0 -42
  270. package/lib/command.d.ts.map +0 -1
  271. package/lib/command.js +0 -75
  272. package/lib/command.js.map +0 -1
  273. package/lib/component.d.ts.map +0 -1
  274. package/lib/component.js.map +0 -1
  275. package/lib/errors.d.ts.map +0 -1
  276. package/lib/errors.js.map +0 -1
  277. package/lib/index.d.ts.map +0 -1
  278. package/lib/index.js.map +0 -1
  279. package/lib/jsx-dev-runtime.d.ts.map +0 -1
  280. package/lib/jsx-dev-runtime.js.map +0 -1
  281. package/lib/jsx-runtime.d.ts.map +0 -1
  282. package/lib/jsx-runtime.js.map +0 -1
  283. package/lib/jsx.d.ts.map +0 -1
  284. package/lib/jsx.js.map +0 -1
  285. package/lib/message-quote.d.ts +0 -11
  286. package/lib/message-quote.d.ts.map +0 -1
  287. package/lib/message-quote.js +0 -91
  288. package/lib/message-quote.js.map +0 -1
  289. package/lib/message.d.ts.map +0 -1
  290. package/lib/message.js.map +0 -1
  291. package/lib/models/system-log.d.ts.map +0 -1
  292. package/lib/models/system-log.js.map +0 -1
  293. package/lib/models/user.d.ts.map +0 -1
  294. package/lib/models/user.js.map +0 -1
  295. package/lib/notice.d.ts.map +0 -1
  296. package/lib/notice.js.map +0 -1
  297. package/lib/plugin.d.ts +0 -258
  298. package/lib/plugin.d.ts.map +0 -1
  299. package/lib/plugin.js +0 -688
  300. package/lib/plugin.js.map +0 -1
  301. package/lib/prompt.d.ts +0 -118
  302. package/lib/prompt.d.ts.map +0 -1
  303. package/lib/prompt.js +0 -244
  304. package/lib/prompt.js.map +0 -1
  305. package/lib/request.d.ts.map +0 -1
  306. package/lib/request.js.map +0 -1
  307. package/lib/scheduler/scheduler.d.ts +0 -49
  308. package/lib/scheduler/scheduler.d.ts.map +0 -1
  309. package/lib/scheduler/scheduler.js +0 -352
  310. package/lib/scheduler/scheduler.js.map +0 -1
  311. package/lib/scheduler/types.d.ts +0 -71
  312. package/lib/scheduler/types.d.ts.map +0 -1
  313. package/lib/scheduler/types.js +0 -8
  314. package/lib/scheduler/types.js.map +0 -1
  315. package/lib/tool-zod.d.ts +0 -28
  316. package/lib/tool-zod.d.ts.map +0 -1
  317. package/lib/tool-zod.js +0 -98
  318. package/lib/tool-zod.js.map +0 -1
  319. package/lib/types-generator.d.ts +0 -6
  320. package/lib/types-generator.d.ts.map +0 -1
  321. package/lib/types-generator.js +0 -72
  322. package/lib/types-generator.js.map +0 -1
  323. package/lib/types.d.ts.map +0 -1
  324. package/lib/types.js.map +0 -1
  325. package/lib/utils.d.ts.map +0 -1
  326. package/lib/utils.js.map +0 -1
@@ -1,24 +1,24 @@
1
1
  /**
2
- * Group Management — 方法规范与 Tool 工厂
2
+ * Scene Management — 方法规范与 Tool 工厂
3
3
  *
4
4
  * 设计理念:
5
- * 各 IM 平台在适配器内自行实现群管方法(kickMember、muteMember 等),
5
+ * 各 IM 平台在适配器内自行实现场景治理方法(removeMember、muteMember 等),
6
6
  * 并自行注册 Tool;平台说明使用包内 `skills/<adapter>/SKILL.md`。
7
7
  *
8
8
  * 使用方式(在各适配器 start 或注册方法中):
9
9
  *
10
- * import { createGroupManagementTools, GROUP_MANAGEMENT_SKILL_KEYWORDS, GROUP_MANAGEMENT_SKILL_TAGS } from 'zhin.js';
11
- * const tools = createGroupManagementTools(this, this.name);
10
+ * import { createSceneManagementTools, SCENE_MANAGEMENT_SKILL_KEYWORDS, SCENE_MANAGEMENT_SKILL_TAGS } from 'zhin.js';
11
+ * const tools = createSceneManagementTools(this, this.name);
12
12
  * tools.forEach(t => this.addTool(t));
13
13
  * // 另:包内 skills/<name>/SKILL.md 供 Agent 发现
14
14
  */
15
- export const GROUP_METHOD_SPECS = [
15
+ export const SCENE_MANAGEMENT_METHOD_SPECS = [
16
16
  {
17
- method: 'kickMember',
18
- toolSuffix: 'kick_member',
19
- description: '将成员踢出群/服务器。适用于严重违规、广告号等需要移除的场景。踢出后该成员将无法再进入群聊(部分平台可重新邀请)。如果只需要用户名而没有 user_id,请先调用 list_members 查询',
17
+ method: 'removeMember',
18
+ toolSuffix: 'remove_member',
19
+ description: '将成员移出当前 IM 场景。适用于严重违规、广告号等需要移除的场景。如果只需要用户名而没有 user_id,请先调用 list_members 查询',
20
20
  keywords: ['踢', 'kick', '移除', '踢出'],
21
- requiredAnyRole: ['group_admin'],
21
+ permit: 'scene_admin',
22
22
  extraParams: {
23
23
  user_id: { type: 'string', description: '目标用户 ID(如果只有昵称,先用 list_members 查询获取)' },
24
24
  },
@@ -29,7 +29,7 @@ export const GROUP_METHOD_SPECS = [
29
29
  toolSuffix: 'mute_member',
30
30
  description: '禁言或解除禁言群成员。适用于违规发言、刷屏、骚扰他人等需要临时限制发言的场景。duration 单位为秒,传 0 表示解除禁言。默认禁言 10 分钟(600秒)。如果只有昵称而没有 user_id,请先调用 list_members 查询',
31
31
  keywords: ['禁言', 'mute', '静音', '解除禁言', '解禁', '闭嘴'],
32
- requiredAnyRole: ['group_admin'],
32
+ permit: 'scene_admin',
33
33
  extraParams: {
34
34
  user_id: { type: 'string', description: '目标用户 ID(如果只有昵称,先用 list_members 查询获取)' },
35
35
  duration: { type: 'number', description: '禁言时长(秒),0=解除禁言,默认600(10分钟)。常用值:60=1分钟, 600=10分钟, 3600=1小时, 86400=1天', default: 600 },
@@ -41,7 +41,7 @@ export const GROUP_METHOD_SPECS = [
41
41
  toolSuffix: 'set_nickname',
42
42
  description: '设置群成员的群昵称/名片。仅修改群内显示名称,不影响用户的全局昵称。如果只有昵称而没有 user_id,请先调用 list_members 查询',
43
43
  keywords: ['昵称', '名片', 'nickname', 'card', '改名片'],
44
- requiredAnyRole: ['group_admin'],
44
+ permit: 'scene_admin',
45
45
  extraParams: {
46
46
  user_id: { type: 'string', description: '目标用户 ID(如果只有昵称,先用 list_members 查询获取)' },
47
47
  nickname: { type: 'string', description: '新的群昵称/名片' },
@@ -49,11 +49,11 @@ export const GROUP_METHOD_SPECS = [
49
49
  extraRequired: ['user_id', 'nickname'],
50
50
  },
51
51
  {
52
- method: 'setAdmin',
53
- toolSuffix: 'set_admin',
54
- description: '设置或取消群管理员。注意:此操作需要群主权限,普通管理员无法执行。enable=true 为设置管理员,enable=false 为取消管理员。如果只有昵称而没有 user_id,请先调用 list_members 查询',
52
+ method: 'setModerator',
53
+ toolSuffix: 'set_moderator',
54
+ description: '设置或取消场景管理员。注意:此操作通常需要场景所有者权限。enable=true 为设置管理员,enable=false 为取消管理员。如果只有昵称而没有 user_id,请先调用 list_members 查询',
55
55
  keywords: ['管理员', 'admin', '设置管理', '取消管理', '提升管理', '撤销管理'],
56
- requiredAnyRole: ['group_owner'],
56
+ permit: 'scene_owner',
57
57
  extraParams: {
58
58
  user_id: { type: 'string', description: '目标用户 ID(如果只有昵称,先用 list_members 查询获取)' },
59
59
  enable: { type: 'boolean', description: 'true=设置为管理员,false=取消管理员身份', default: true },
@@ -73,7 +73,7 @@ export const GROUP_METHOD_SPECS = [
73
73
  toolSuffix: 'ban_member',
74
74
  description: '永久封禁成员(拉入黑名单)。与踢人(kick)不同,封禁后该成员无法再加入群聊。适用于恶意用户、严重违规等需要永久禁止的场景。如果只有昵称而没有 user_id,请先调用 list_members 查询',
75
75
  keywords: ['封禁', 'ban', '拉黑', '黑名单'],
76
- requiredAnyRole: ['group_admin'],
76
+ permit: 'scene_admin',
77
77
  extraParams: {
78
78
  user_id: { type: 'string', description: '目标用户 ID(如果只有昵称,先用 list_members 查询获取)' },
79
79
  reason: { type: 'string', description: '封禁原因(将记录在封禁日志中)' },
@@ -85,37 +85,37 @@ export const GROUP_METHOD_SPECS = [
85
85
  toolSuffix: 'unban_member',
86
86
  description: '解除封禁,将成员从黑名单中移除。解除后该成员可以重新加入群聊。如果只有昵称而没有 user_id,请先调用 list_members 查询',
87
87
  keywords: ['解封', 'unban', '解除封禁', '移出黑名单'],
88
- requiredAnyRole: ['group_admin'],
88
+ permit: 'scene_admin',
89
89
  extraParams: {
90
90
  user_id: { type: 'string', description: '目标用户 ID(如果只有昵称,先用 list_members 查询获取)' },
91
91
  },
92
92
  extraRequired: ['user_id'],
93
93
  },
94
94
  {
95
- method: 'setGroupName',
96
- toolSuffix: 'set_group_name',
97
- description: '修改群/服务器名称。修改后所有成员立即可见新群名',
95
+ method: 'renameScene',
96
+ toolSuffix: 'rename_scene',
97
+ description: '修改 IM 场景名称。修改后所有成员立即可见新名称',
98
98
  keywords: ['群名', '改名', 'group name', '修改群名'],
99
- requiredAnyRole: ['group_admin'],
99
+ permit: 'scene_admin',
100
100
  extraParams: {
101
101
  name: { type: 'string', description: '新群名称' },
102
102
  },
103
103
  extraRequired: ['name'],
104
104
  },
105
105
  {
106
- method: 'muteAll',
107
- toolSuffix: 'mute_all',
108
- description: '开启或关闭全员禁言。开启后除管理员外所有成员都无法发言。适用于紧急维护、重要通知、聊天秩序混乱等场景。enable=true 开启,enable=false 解除',
106
+ method: 'setSceneMuted',
107
+ toolSuffix: 'set_scene_muted',
108
+ description: '开启或关闭场景全员禁言。开启后除管理员外所有成员都无法发言。适用于紧急维护、重要通知、聊天秩序混乱等场景。enable=true 开启,enable=false 解除',
109
109
  keywords: ['全员禁言', 'mute all', '全体禁言', '全体解禁'],
110
- requiredAnyRole: ['group_admin'],
110
+ permit: 'scene_admin',
111
111
  extraParams: {
112
112
  enable: { type: 'boolean', description: 'true=开启全员禁言,false=解除全员禁言', default: true },
113
113
  },
114
114
  },
115
115
  {
116
- method: 'getGroupInfo',
117
- toolSuffix: 'get_group_info',
118
- description: '获取群/服务器基本信息,包括群名、群主、成员数量、创建时间等。用于了解群聊概况',
116
+ method: 'getSceneInfo',
117
+ toolSuffix: 'get_scene_info',
118
+ description: '获取 IM 场景基本信息,包括名称、所有者、成员数量、创建时间等。用于了解场景概况',
119
119
  keywords: ['群信息', 'group info', '群资料', '群详情'],
120
120
  extraParams: {},
121
121
  preExecutable: true,
@@ -124,42 +124,55 @@ export const GROUP_METHOD_SPECS = [
124
124
  // ============================================================================
125
125
  // Skill 常量(群管相关 SKILL.md 与文档可复用 keywords/tags)
126
126
  // ============================================================================
127
- export const GROUP_MANAGEMENT_SKILL_TAGS = ['group', 'management', 'im', 'admin'];
128
- export const GROUP_MANAGEMENT_SKILL_KEYWORDS = [
129
- '群管理', '踢人', '禁言', '封禁', '管理员', '群名',
127
+ export const SCENE_MANAGEMENT_SKILL_TAGS = ['scene', 'management', 'im', 'admin'];
128
+ export const SCENE_MANAGEMENT_SKILL_KEYWORDS = [
129
+ '场景治理', '群管理', '踢人', '禁言', '封禁', '管理员', '群名',
130
130
  '成员', 'kick', 'mute', 'ban', 'admin', 'members',
131
131
  ];
132
- export function createGroupManagementTools(adapter, prefix) {
133
- return createGroupManagementToolsRaw(adapter, prefix, (spec, prefix, execute) => ({
134
- name: `${prefix}_${spec.toolSuffix}`,
135
- description: `${spec.description} (${prefix})`,
136
- parameters: {
137
- type: 'object',
138
- properties: {
139
- bot_id: { type: 'string', description: 'Bot ID', contextKey: 'botId' },
140
- scene_id: { type: 'string', description: '群/服务器 ID', contextKey: 'sceneId' },
141
- ...Object.fromEntries(Object.entries(spec.extraParams)),
132
+ export function defaultScenePermitResolver(adapterPrefix) {
133
+ return (logicalPerm) => `platform(${adapterPrefix},${logicalPerm})`;
134
+ }
135
+ function resolveSpecPermit(specPerm, prefix, permitResolver) {
136
+ if (!specPerm)
137
+ return undefined;
138
+ const resolved = permitResolver(specPerm);
139
+ return resolved ? [resolved] : undefined;
140
+ }
141
+ export function createSceneManagementTools(adapter, prefix, options = {}) {
142
+ const permitResolver = options.permitResolver ?? defaultScenePermitResolver(prefix);
143
+ return createSceneManagementToolsRaw(adapter, prefix, (spec, prefix, execute) => {
144
+ const specPermissions = resolveSpecPermit(spec.permit, prefix, permitResolver);
145
+ return {
146
+ name: `${prefix}_${spec.toolSuffix}`,
147
+ description: `${spec.description} (${prefix})`,
148
+ parameters: {
149
+ type: 'object',
150
+ properties: {
151
+ endpoint_id: { type: 'string', description: 'Endpoint ID', contextKey: 'endpointKey' },
152
+ scene_id: { type: 'string', description: 'IM 场景 ID', contextKey: 'sceneId' },
153
+ ...Object.fromEntries(Object.entries(spec.extraParams)),
154
+ },
155
+ required: ['endpoint_id', 'scene_id', ...(spec.extraRequired ?? [])],
142
156
  },
143
- required: ['bot_id', 'scene_id', ...(spec.extraRequired ?? [])],
144
- },
145
- execute,
146
- tags: ['group', 'management', prefix],
147
- keywords: spec.keywords,
148
- ...(spec.requiredAnyRole?.length ? { requiredAnyRole: spec.requiredAnyRole } : {}),
149
- scopes: ['group', 'channel'],
150
- preExecutable: spec.preExecutable,
151
- }));
157
+ execute,
158
+ tags: ['scene', 'management', prefix],
159
+ keywords: spec.keywords,
160
+ ...(specPermissions ? { permissions: specPermissions } : {}),
161
+ scopes: ['group', 'channel'],
162
+ preExecutable: spec.preExecutable,
163
+ };
164
+ });
152
165
  }
153
- export function createGroupManagementToolsRaw(adapter, prefix, factory) {
166
+ export function createSceneManagementToolsRaw(adapter, prefix, factory) {
154
167
  const tools = [];
155
- for (const spec of GROUP_METHOD_SPECS) {
168
+ for (const spec of SCENE_MANAGEMENT_METHOD_SPECS) {
156
169
  const fn = adapter[spec.method];
157
170
  if (typeof fn !== 'function')
158
171
  continue;
159
172
  const boundFn = fn.bind(adapter);
160
173
  const execute = async (args) => {
161
- const { bot_id, scene_id, ...rest } = args;
162
- const methodArgs = buildMethodArgs(spec.method, bot_id, scene_id, rest);
174
+ const { endpoint_id, scene_id, ...rest } = args;
175
+ const methodArgs = buildSceneMethodArgs(spec.method, endpoint_id, scene_id, rest);
163
176
  return boundFn.apply(adapter, methodArgs);
164
177
  };
165
178
  tools.push(factory(spec, prefix, execute));
@@ -169,19 +182,18 @@ export function createGroupManagementToolsRaw(adapter, prefix, factory) {
169
182
  // ============================================================================
170
183
  // 参数映射(method → 有序参数列表)
171
184
  // ============================================================================
172
- export function buildMethodArgs(method, botId, sceneId, rest) {
185
+ export function buildSceneMethodArgs(method, endpointKey, sceneId, rest) {
173
186
  switch (method) {
174
- case 'kickMember': return [botId, sceneId, rest.user_id];
175
- case 'muteMember': return [botId, sceneId, rest.user_id, rest.duration ?? 600];
176
- case 'setMemberNickname': return [botId, sceneId, rest.user_id, rest.nickname];
177
- case 'setAdmin': return [botId, sceneId, rest.user_id, rest.enable ?? true];
178
- case 'listMembers': return [botId, sceneId];
179
- case 'banMember': return [botId, sceneId, rest.user_id, rest.reason];
180
- case 'unbanMember': return [botId, sceneId, rest.user_id];
181
- case 'setGroupName': return [botId, sceneId, rest.name];
182
- case 'muteAll': return [botId, sceneId, rest.enable ?? true];
183
- case 'getGroupInfo': return [botId, sceneId];
184
- default: return [botId, sceneId, ...Object.values(rest)];
187
+ case 'removeMember': return [endpointKey, sceneId, rest.user_id];
188
+ case 'muteMember': return [endpointKey, sceneId, rest.user_id, rest.duration ?? 600];
189
+ case 'setMemberNickname': return [endpointKey, sceneId, rest.user_id, rest.nickname];
190
+ case 'setModerator': return [endpointKey, sceneId, rest.user_id, rest.enable ?? true];
191
+ case 'listMembers': return [endpointKey, sceneId];
192
+ case 'banMember': return [endpointKey, sceneId, rest.user_id, rest.reason];
193
+ case 'unbanMember': return [endpointKey, sceneId, rest.user_id];
194
+ case 'renameScene': return [endpointKey, sceneId, rest.name];
195
+ case 'setSceneMuted': return [endpointKey, sceneId, rest.enable ?? true];
196
+ case 'getSceneInfo': return [endpointKey, sceneId];
197
+ default: return [endpointKey, sceneId, ...Object.values(rest)];
185
198
  }
186
199
  }
187
- //# sourceMappingURL=common-adapter-tools.js.map
@@ -0,0 +1,24 @@
1
+ export interface GenerateQrCodeOptions {
2
+ width?: number;
3
+ margin?: number;
4
+ errorCorrectionLevel?: 'L' | 'M' | 'Q' | 'H';
5
+ }
6
+ export interface PrintQrCodeTerminalOptions {
7
+ small?: boolean;
8
+ }
9
+ /** 二维码实例:一次 generate,多种输出 */
10
+ export declare class GeneratedQrCode {
11
+ #private;
12
+ private constructor();
13
+ static generate(text: string, options?: GenerateQrCodeOptions): Promise<GeneratedQrCode>;
14
+ /** data URL,含 `data:image/png;base64,...` 前缀 */
15
+ toDataUrl(): string;
16
+ /**
17
+ * encoding === 'base64' → 纯 base64 载荷(无 data: 前缀)
18
+ */
19
+ toString(encoding: 'base64'): string;
20
+ /** 输出 ASCII 二维码到 process.stdout */
21
+ printToTerminal(options?: PrintQrCodeTerminalOptions): Promise<void>;
22
+ }
23
+ /** 便捷别名 */
24
+ export declare const generateQrCode: typeof GeneratedQrCode.generate;
@@ -0,0 +1,45 @@
1
+ import QRCode from 'qrcode';
2
+ /** 二维码实例:一次 generate,多种输出 */
3
+ export class GeneratedQrCode {
4
+ #text;
5
+ #dataUrl;
6
+ constructor(text, dataUrl) {
7
+ this.#text = text;
8
+ this.#dataUrl = dataUrl;
9
+ }
10
+ static async generate(text, options = {}) {
11
+ const dataUrl = await QRCode.toDataURL(text, {
12
+ width: options.width ?? 280,
13
+ margin: options.margin ?? 2,
14
+ errorCorrectionLevel: options.errorCorrectionLevel ?? 'M',
15
+ });
16
+ return new GeneratedQrCode(text, dataUrl);
17
+ }
18
+ /** data URL,含 `data:image/png;base64,...` 前缀 */
19
+ toDataUrl() {
20
+ return this.#dataUrl;
21
+ }
22
+ /**
23
+ * encoding === 'base64' → 纯 base64 载荷(无 data: 前缀)
24
+ */
25
+ toString(encoding) {
26
+ if (encoding !== 'base64') {
27
+ throw new Error(`GeneratedQrCode.toString: unsupported encoding "${encoding}"`);
28
+ }
29
+ const prefix = 'data:image/png;base64,';
30
+ if (!this.#dataUrl.startsWith(prefix)) {
31
+ throw new Error('GeneratedQrCode.toString: unexpected data URL format');
32
+ }
33
+ return this.#dataUrl.slice(prefix.length);
34
+ }
35
+ /** 输出 ASCII 二维码到 process.stdout */
36
+ async printToTerminal(options = {}) {
37
+ const terminalText = await QRCode.toString(this.#text, {
38
+ type: 'terminal',
39
+ small: options.small ?? true,
40
+ });
41
+ process.stdout.write(`${terminalText}\n`);
42
+ }
43
+ }
44
+ /** 便捷别名 */
45
+ export const generateQrCode = GeneratedQrCode.generate.bind(GeneratedQrCode);
@@ -0,0 +1,4 @@
1
+ import type { MessageElement } from '../types.js';
2
+ import type { Segment } from './segment-contract/types.js';
3
+ /** wire 段数组 → canonical Segment[](包括所有媒体的 `data.media` 归一)。 */
4
+ export declare function toCanonicalSegments(content: readonly MessageElement[] | readonly unknown[]): Segment[];
@@ -0,0 +1,190 @@
1
+ import { isMediaRef, readMentionTarget, } from './segment-contract/index.js';
2
+ function isRecord(value) {
3
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
4
+ }
5
+ function readPlatform(seg) {
6
+ const platform = seg.platform;
7
+ return platform && typeof platform === 'object' ? platform : undefined;
8
+ }
9
+ function normalizeMention(seg) {
10
+ const data = seg.data;
11
+ const target = readMentionTarget(data);
12
+ const name = typeof data.name === 'string' && data.name ? data.name : undefined;
13
+ const platform = readPlatform(seg);
14
+ return {
15
+ type: 'mention',
16
+ data: name ? { target, name } : { target },
17
+ ...(platform ? { platform } : {}),
18
+ };
19
+ }
20
+ const MEDIA_SEGMENT_TYPES = new Set(['image', 'audio', 'video', 'file']);
21
+ function nonEmptyString(value) {
22
+ return typeof value === 'string' && value.trim() ? value : undefined;
23
+ }
24
+ function legacyMediaRef(data) {
25
+ if (isMediaRef(data.media))
26
+ return data.media;
27
+ const url = nonEmptyString(data.url) ?? nonEmptyString(data.href) ?? nonEmptyString(data.src);
28
+ const path = nonEmptyString(data.path) ?? nonEmptyString(data.file_path);
29
+ const base64 = nonEmptyString(data.base64);
30
+ const file = nonEmptyString(data.file) ?? nonEmptyString(data.file_id);
31
+ const value = url ?? path ?? base64 ?? file;
32
+ if (!value)
33
+ return undefined;
34
+ const kind = url ? 'url'
35
+ : path ? 'path'
36
+ : base64 ? 'base64'
37
+ : /^(?:[a-z][a-z0-9+.-]*:)?\/\//iu.test(value) ? 'url'
38
+ : /^(?:\.{1,2}\/|\/|~\/)/u.test(value) ? 'path'
39
+ : 'file';
40
+ const mimeType = nonEmptyString(data.mime_type) ?? nonEmptyString(data.mimeType);
41
+ // Legacy top-level fileName names the rendered file segment. Keep source
42
+ // metadata reserved for an explicit media object instead of duplicating it.
43
+ const fileName = nonEmptyString(data.media_file_name);
44
+ const size = typeof data.size === 'number' && Number.isFinite(data.size) ? data.size : undefined;
45
+ return {
46
+ kind,
47
+ value,
48
+ ...(mimeType ? { mime_type: mimeType } : {}),
49
+ ...(fileName ? { file_name: fileName } : {}),
50
+ ...(size === undefined ? {} : { size }),
51
+ };
52
+ }
53
+ /**
54
+ * The sole ingress compatibility boundary for media. Adapters may emit their
55
+ * native `url`/`path`/`file` fields, but every consumer receives `data.media`.
56
+ */
57
+ function normalizeMedia(seg) {
58
+ const data = seg.data;
59
+ const platform = readPlatform(seg);
60
+ const media = legacyMediaRef(data);
61
+ if (!media)
62
+ return seg;
63
+ const attributes = seg.type === 'image'
64
+ ? { ...(typeof data.alt === 'string' ? { alt: data.alt } : {}) }
65
+ : seg.type === 'audio'
66
+ ? { ...(typeof data.duration === 'number' ? { duration: data.duration } : {}) }
67
+ : seg.type === 'video'
68
+ ? {
69
+ ...(typeof data.duration === 'number' ? { duration: data.duration } : {}),
70
+ ...(typeof data.alt === 'string' ? { alt: data.alt } : {}),
71
+ }
72
+ : {
73
+ ...(nonEmptyString(data.name) ?? nonEmptyString(data.file_name) ?? nonEmptyString(data.fileName)
74
+ ? { name: nonEmptyString(data.name) ?? nonEmptyString(data.file_name) ?? nonEmptyString(data.fileName) }
75
+ : {}),
76
+ };
77
+ return {
78
+ type: seg.type,
79
+ data: { media, ...attributes },
80
+ ...(platform ? { platform } : {}),
81
+ };
82
+ }
83
+ function normalizeReply(seg) {
84
+ const data = seg.data;
85
+ const messageId = String(data.message_id ?? data.id ?? '').trim();
86
+ if (!messageId)
87
+ return seg;
88
+ return { type: 'reply', data: { message_id: messageId } };
89
+ }
90
+ function normalizeLink(seg) {
91
+ const data = seg.data;
92
+ const url = String(data.url ?? data.href ?? '').trim();
93
+ if (!url)
94
+ return seg;
95
+ const text = typeof data.text === 'string' && data.text ? data.text : undefined;
96
+ const platform = readPlatform(seg);
97
+ return {
98
+ type: 'link',
99
+ data: text ? { url, text } : { url },
100
+ ...(platform ? { platform } : {}),
101
+ };
102
+ }
103
+ function normalizeForward(seg) {
104
+ const data = seg.data;
105
+ const forwardId = String(data.forward_id ?? data.id ?? data.resid ?? '').trim();
106
+ if (!forwardId)
107
+ return seg;
108
+ const title = typeof data.title === 'string' ? data.title : undefined;
109
+ const messages = Array.isArray(data.messages) ? data.messages : undefined;
110
+ const platform = { ...(readPlatform(seg) ?? {}) };
111
+ if (data.resid != null)
112
+ platform.resid = String(data.resid);
113
+ return {
114
+ type: 'forward',
115
+ data: {
116
+ forward_id: forwardId,
117
+ ...(title ? { title } : {}),
118
+ ...(messages ? { messages: messages } : {}),
119
+ },
120
+ ...(Object.keys(platform).length ? { platform } : {}),
121
+ };
122
+ }
123
+ function isPlatformSticker(seg) {
124
+ if (seg.type !== 'sticker')
125
+ return false;
126
+ const data = seg.data;
127
+ return data.package_id != null
128
+ || data.sticker_id != null
129
+ || data.packageId != null
130
+ || data.stickerId != null;
131
+ }
132
+ function normalizeFace(seg) {
133
+ if (isPlatformSticker(seg))
134
+ return seg;
135
+ const data = seg.data;
136
+ const rawId = data.id ?? data.face_id;
137
+ const name = typeof data.name === 'string'
138
+ ? data.name
139
+ : typeof data.text === 'string'
140
+ ? data.text
141
+ : undefined;
142
+ const platform = readPlatform(seg);
143
+ return {
144
+ type: 'face',
145
+ data: {
146
+ ...(rawId != null ? { id: rawId } : {}),
147
+ ...(name ? { name } : {}),
148
+ },
149
+ ...(platform ? { platform } : {}),
150
+ };
151
+ }
152
+ function normalizeMarkdown(seg) {
153
+ const data = seg.data;
154
+ const content = typeof data.content === 'string'
155
+ ? data.content
156
+ : typeof data.text === 'string'
157
+ ? data.text
158
+ : '';
159
+ return { type: 'markdown', data: { content } };
160
+ }
161
+ function normalizeSegment(seg) {
162
+ if (seg.type === 'at' || seg.type === 'mention')
163
+ return normalizeMention(seg);
164
+ if (MEDIA_SEGMENT_TYPES.has(seg.type))
165
+ return normalizeMedia(seg);
166
+ if (seg.type === 'reply')
167
+ return normalizeReply(seg);
168
+ if (seg.type === 'forward')
169
+ return normalizeForward(seg);
170
+ if (seg.type === 'sticker' && isPlatformSticker(seg))
171
+ return seg;
172
+ if (seg.type === 'face' || seg.type === 'sticker' || seg.type === 'emoji')
173
+ return normalizeFace(seg);
174
+ if (seg.type === 'link')
175
+ return normalizeLink(seg);
176
+ if (seg.type === 'markdown')
177
+ return normalizeMarkdown(seg);
178
+ return seg;
179
+ }
180
+ function asMessageSegments(content) {
181
+ return content.map((item) => {
182
+ if (typeof item === 'string')
183
+ return { type: 'text', data: { text: item } };
184
+ return item;
185
+ });
186
+ }
187
+ /** wire 段数组 → canonical Segment[](包括所有媒体的 `data.media` 归一)。 */
188
+ export function toCanonicalSegments(content) {
189
+ return asMessageSegments(content).map((seg) => normalizeSegment(seg));
190
+ }
@@ -1,9 +1,6 @@
1
1
  /**
2
- * 出站 `html` 消息段兜底:未装 html-renderer 或转图失败时,自动剥离为 text 段。
2
+ * Convert unresolved `html` segments to portable text content.
3
+ * Canonical outbound rendering owns when this fallback is applied.
3
4
  */
4
- import type { Plugin } from '../plugin.js';
5
5
  import type { SendContent } from '../types.js';
6
6
  export declare function coerceHtmlSegmentsToText(content: SendContent): SendContent;
7
- /** 注册链尾 before.sendMessage:将未转换的 html 段降级为 text */
8
- export declare function registerHtmlSegmentFallback(plugin: Plugin): () => void;
9
- //# sourceMappingURL=html-segment-fallback.d.ts.map
@@ -32,19 +32,3 @@ export function coerceHtmlSegmentsToText(content) {
32
32
  return out[0];
33
33
  return out;
34
34
  }
35
- /** 注册链尾 before.sendMessage:将未转换的 html 段降级为 text */
36
- export function registerHtmlSegmentFallback(plugin) {
37
- const handler = (options) => {
38
- const content = options.content;
39
- if (content == null)
40
- return options;
41
- const items = asArray(content);
42
- if (!items.some((item) => typeof item !== 'string' && item?.type === 'html')) {
43
- return options;
44
- }
45
- return { ...options, content: coerceHtmlSegmentsToText(content) };
46
- };
47
- plugin.root.on('before.sendMessage', handler);
48
- return () => plugin.root.off('before.sendMessage', handler);
49
- }
50
- //# sourceMappingURL=html-segment-fallback.js.map
@@ -14,4 +14,3 @@ export declare function htmlToPlainTextWithBlockBreaks(html: string, options?: H
14
14
  * HTML 卡片出站回退:块级换行 + 语义标题轻量 markdown 前缀。
15
15
  */
16
16
  export declare function htmlToFallbackText(html: string, options?: HtmlToPlainTextOptions): string;
17
- //# sourceMappingURL=html-to-text.d.ts.map
@@ -79,20 +79,21 @@ function stripRemainingTags(html) {
79
79
  return out;
80
80
  }
81
81
  function decodeCommonEntities(text) {
82
- return text
83
- .replace(/&nbsp;/gi, ' ')
84
- .replace(/&amp;/g, '&')
85
- .replace(/&lt;/g, '<')
86
- .replace(/&gt;/g, '>')
87
- .replace(/&quot;/g, '"')
88
- .replace(/&#39;/g, "'")
89
- .replace(/&apos;/g, "'")
90
- .replace(/&#(\d+);/g, (_, code) => {
91
- const n = Number(code);
92
- return Number.isFinite(n) && n >= 0 && n <= 0x10ffff ? String.fromCodePoint(n) : '';
93
- })
94
- .replace(/&#x([0-9a-fA-F]+);/g, (_, hex) => {
95
- const n = parseInt(hex, 16);
82
+ return text.replace(/&(#x[0-9a-fA-F]+|#\d+|nbsp|amp|lt|gt|quot|apos);/gi, (entity) => {
83
+ const key = entity.slice(1, -1).toLowerCase();
84
+ if (key === 'nbsp')
85
+ return ' ';
86
+ if (key === 'amp')
87
+ return '&';
88
+ if (key === 'lt')
89
+ return '<';
90
+ if (key === 'gt')
91
+ return '>';
92
+ if (key === 'quot')
93
+ return '"';
94
+ if (key === 'apos')
95
+ return "'";
96
+ const n = key.startsWith('#x') ? parseInt(key.slice(2), 16) : Number(key.slice(1));
96
97
  return Number.isFinite(n) && n >= 0 && n <= 0x10ffff ? String.fromCodePoint(n) : '';
97
98
  });
98
99
  }
@@ -163,4 +164,3 @@ export function htmlToFallbackText(html, options) {
163
164
  .replace(/\n{3,}/g, '\n\n')
164
165
  .trim();
165
166
  }
166
- //# sourceMappingURL=html-to-text.js.map
@@ -0,0 +1,17 @@
1
+ import type { Message } from '../../message.js';
2
+ import type { MessageElement } from '../../types.js';
3
+ import { type ActionSegmentData } from './types.js';
4
+ export declare function actionSegment(data: ActionSegmentData): MessageElement;
5
+ export declare function getActionFromMessage(message: Message<any>): ActionSegmentData | undefined;
6
+ /** 入站互动 action(按钮点击等),不应计入用户发言/消息统计 */
7
+ export declare function isActionMessage(message: Message<any>): boolean;
8
+ /** 去掉 @bot、XML at 段、首尾空白(QQ 指令预填文本归一化) */
9
+ export declare function stripInteractiveCommandText(raw: string): string;
10
+ /** 从文本降级输入解析 payload(需在 active session 的 fallback.map 中查找) */
11
+ export declare function resolveTextFallbackPayload(raw: string, map: Record<string, string>): string | undefined;
12
+ /**
13
+ * 从用户文本入站解析 interactive payload:
14
+ * 归一化 → 直接匹配 prefix:session:id → fallback 数字映射
15
+ */
16
+ export declare function resolvePayloadFromText(raw: string, map?: Record<string, string>): string | undefined;
17
+ export declare function formatActionAsRaw(data: ActionSegmentData): string;