@zhin.js/core 1.5.16 → 1.6.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 (328) hide show
  1. package/README.md +78 -195
  2. package/lib/ai-completion-contract.d.ts +135 -0
  3. package/lib/ai-completion-contract.js +69 -0
  4. package/lib/built/ai-access.d.ts +2 -21
  5. package/lib/built/ai-access.js +1 -46
  6. package/lib/built/ai-outbound/index.d.ts +0 -2
  7. package/lib/built/ai-outbound/index.js +0 -2
  8. package/lib/built/ai-outbound/prompt.d.ts +2 -0
  9. package/lib/built/ai-outbound/prompt.js +2 -0
  10. package/lib/built/ai-outbound/types.d.ts +1 -10
  11. package/lib/built/ai-trigger.d.ts +39 -78
  12. package/lib/built/ai-trigger.js +3 -254
  13. package/lib/built/common-adapter-tools.d.ts +21 -6
  14. package/lib/built/common-adapter-tools.js +28 -17
  15. package/lib/built/generic-segment-mapper.js +4 -1
  16. package/lib/built/html-segment-fallback.d.ts +6 -7
  17. package/lib/built/html-segment-fallback.js +1 -16
  18. package/lib/built/html-to-text.d.ts +0 -3
  19. package/lib/built/html-to-text.js +131 -40
  20. package/lib/built/interaction-messages.d.ts +1 -0
  21. package/lib/built/interaction-messages.js +30 -0
  22. package/lib/built/interactive-segments/action.d.ts +3 -4
  23. package/lib/built/interactive-segments/action.js +2 -5
  24. package/lib/built/interactive-segments/index.d.ts +0 -2
  25. package/lib/built/interactive-segments/index.js +0 -2
  26. package/lib/built/interactive-segments/keyboard-segment.d.ts +0 -1
  27. package/lib/built/interactive-segments/keyboard-segment.js +0 -1
  28. package/lib/built/interactive-segments/onebot-keyboard.d.ts +0 -1
  29. package/lib/built/interactive-segments/onebot-keyboard.js +0 -2
  30. package/lib/built/interactive-segments/resolve.d.ts +2 -3
  31. package/lib/built/interactive-segments/resolve.js +21 -14
  32. package/lib/built/interactive-segments/types.d.ts +2 -7
  33. package/lib/built/interactive-segments/types.js +22 -2
  34. package/lib/built/login-assist.d.ts +13 -11
  35. package/lib/built/login-assist.js +32 -26
  36. package/lib/built/message-enrich.d.ts +24 -27
  37. package/lib/built/message-enrich.js +53 -49
  38. package/lib/built/outbound-content-arrays.d.ts +4 -0
  39. package/lib/built/outbound-content-arrays.js +32 -0
  40. package/lib/built/outbound-media-trust.d.ts +46 -0
  41. package/lib/built/outbound-media-trust.js +245 -0
  42. package/lib/built/outbound-media-utils.d.ts +5 -3
  43. package/lib/built/outbound-media-utils.js +5 -3
  44. package/lib/built/readable-link.d.ts +4 -0
  45. package/lib/built/readable-link.js +32 -0
  46. package/lib/built/rich-segments/markdown-to-text.d.ts +1 -2
  47. package/lib/built/rich-segments/markdown-to-text.js +141 -17
  48. package/lib/built/roles.d.ts +141 -12
  49. package/lib/built/roles.js +253 -52
  50. package/lib/built/segment-contract/assert.js +8 -2
  51. package/lib/built/segment-contract/delivery.js +1 -0
  52. package/lib/built/segment-contract/index.d.ts +3 -3
  53. package/lib/built/segment-contract/index.js +2 -2
  54. package/lib/built/segment-contract/json-schema.d.ts +39 -5
  55. package/lib/built/segment-contract/json-schema.js +207 -24
  56. package/lib/built/segment-contract/preview.js +8 -1
  57. package/lib/built/segment-contract/text.js +1 -1
  58. package/lib/built/segment-contract/types.d.ts +2 -2
  59. package/lib/built/segment-contract/validate.d.ts +1553 -224
  60. package/lib/built/segment-contract/validate.js +39 -3
  61. package/lib/built/tool-access.d.ts +5 -0
  62. package/lib/built/tool-access.js +17 -0
  63. package/lib/built/user-interaction.d.ts +5 -4
  64. package/lib/built/user-interaction.js +64 -52
  65. package/lib/errors.d.ts +1 -18
  66. package/lib/errors.js +1 -26
  67. package/lib/feature/command-public-api.d.ts +5 -0
  68. package/lib/feature/command-public-api.js +5 -0
  69. package/lib/feature/command.d.ts +2 -0
  70. package/lib/feature/command.js +1 -0
  71. package/lib/feature/component.d.ts +1 -0
  72. package/lib/feature/component.js +1 -0
  73. package/lib/feature/handler.d.ts +13 -7
  74. package/lib/feature/handler.js +2 -1
  75. package/lib/feature/middleware-public-api.d.ts +6 -0
  76. package/lib/feature/middleware-public-api.js +6 -0
  77. package/lib/feature/middleware.d.ts +22 -2
  78. package/lib/feature/middleware.js +7 -2
  79. package/lib/im-scene.d.ts +4 -3
  80. package/lib/im-scene.js +9 -9
  81. package/lib/im-session-id.d.ts +20 -12
  82. package/lib/im-session-id.js +8 -8
  83. package/lib/index.d.ts +19 -48
  84. package/lib/index.js +14 -41
  85. package/lib/jsx/intrinsic-elements.d.ts +83 -0
  86. package/lib/jsx/message-renderer.d.ts +13 -0
  87. package/lib/jsx/message-renderer.js +128 -0
  88. package/lib/jsx/message-tags.d.ts +133 -0
  89. package/lib/jsx/message-tags.js +50 -0
  90. package/lib/jsx-dev-runtime.d.ts +2 -2
  91. package/lib/jsx-dev-runtime.js +1 -2
  92. package/lib/jsx-runtime.d.ts +2 -12
  93. package/lib/jsx-runtime.js +1 -10
  94. package/lib/jsx.d.ts +6 -30
  95. package/lib/jsx.js +3 -93
  96. package/lib/message.d.ts +0 -40
  97. package/lib/message.js +1 -27
  98. package/lib/models/system-log.d.ts +0 -2
  99. package/lib/models/system-log.js +1 -8
  100. package/lib/models/user.d.ts +0 -2
  101. package/lib/models/user.js +1 -7
  102. package/lib/notice.d.ts +38 -33
  103. package/lib/notice.js +23 -7
  104. package/lib/plugin-runtime/im/command-feedback.d.ts +59 -0
  105. package/lib/plugin-runtime/im/command-feedback.js +148 -0
  106. package/lib/plugin-runtime/im/contracts.d.ts +217 -32
  107. package/lib/plugin-runtime/im/contracts.js +141 -23
  108. package/lib/plugin-runtime/im/conversation-runtime.d.ts +42 -0
  109. package/lib/plugin-runtime/im/conversation-runtime.js +451 -0
  110. package/lib/plugin-runtime/im/endpoint-runtime.d.ts +89 -0
  111. package/lib/plugin-runtime/im/endpoint-runtime.js +381 -0
  112. package/lib/plugin-runtime/im/feature-gate.d.ts +21 -0
  113. package/lib/plugin-runtime/im/feature-gate.js +88 -0
  114. package/lib/plugin-runtime/im/host/component-host-installer.d.ts +2 -0
  115. package/lib/plugin-runtime/im/host/component-host-installer.js +14 -0
  116. package/lib/plugin-runtime/im/host/conversation-migration.d.ts +5 -0
  117. package/lib/plugin-runtime/im/host/conversation-migration.js +75 -0
  118. package/lib/plugin-runtime/im/host/database-config.d.ts +10 -0
  119. package/lib/plugin-runtime/im/host/database-config.js +114 -0
  120. package/lib/plugin-runtime/im/host/database-host-installer.d.ts +29 -0
  121. package/lib/plugin-runtime/im/host/database-host-installer.js +442 -0
  122. package/lib/plugin-runtime/im/host/database-state.d.ts +9 -0
  123. package/lib/plugin-runtime/im/host/database-state.js +91 -0
  124. package/lib/plugin-runtime/im/host/index.d.ts +8 -0
  125. package/lib/plugin-runtime/im/host/index.js +8 -0
  126. package/lib/plugin-runtime/im/host/locale-host-installer.d.ts +3 -0
  127. package/lib/plugin-runtime/im/host/locale-host-installer.js +60 -0
  128. package/lib/plugin-runtime/im/host/outbound-host-installer.d.ts +8 -0
  129. package/lib/plugin-runtime/im/host/outbound-host-installer.js +153 -0
  130. package/lib/plugin-runtime/im/host/sender-enrichment.d.ts +34 -0
  131. package/lib/plugin-runtime/im/host/sender-enrichment.js +82 -0
  132. package/lib/plugin-runtime/im/im-runtime.d.ts +40 -111
  133. package/lib/plugin-runtime/im/im-runtime.js +234 -1059
  134. package/lib/plugin-runtime/im/inbound-dedup.d.ts +84 -0
  135. package/lib/plugin-runtime/im/inbound-dedup.js +322 -0
  136. package/lib/plugin-runtime/im/inbound-origin.d.ts +150 -0
  137. package/lib/plugin-runtime/im/inbound-origin.js +183 -0
  138. package/lib/plugin-runtime/im/inbound-runtime.d.ts +59 -0
  139. package/lib/plugin-runtime/im/inbound-runtime.js +478 -0
  140. package/lib/plugin-runtime/im/inbound-spine.d.ts +196 -0
  141. package/lib/plugin-runtime/im/inbound-spine.js +335 -0
  142. package/lib/plugin-runtime/im/index.d.ts +15 -4
  143. package/lib/plugin-runtime/im/index.js +11 -4
  144. package/lib/plugin-runtime/im/interaction-runtime.d.ts +50 -0
  145. package/lib/plugin-runtime/im/interaction-runtime.js +390 -0
  146. package/lib/plugin-runtime/im/interactive-router.d.ts +81 -0
  147. package/lib/plugin-runtime/im/interactive-router.js +382 -0
  148. package/lib/plugin-runtime/im/message-diagnostics.d.ts +70 -0
  149. package/lib/plugin-runtime/im/message-diagnostics.js +182 -0
  150. package/lib/plugin-runtime/im/message-dispatcher.d.ts +18 -4
  151. package/lib/plugin-runtime/im/message-dispatcher.js +138 -20
  152. package/lib/plugin-runtime/im/message-events.d.ts +85 -0
  153. package/lib/plugin-runtime/im/message-events.js +113 -0
  154. package/lib/plugin-runtime/im/outbound-delivery-runtime.d.ts +39 -0
  155. package/lib/plugin-runtime/im/outbound-delivery-runtime.js +450 -0
  156. package/lib/plugin-runtime/im/outbound-renderer.d.ts +52 -3
  157. package/lib/plugin-runtime/im/outbound-renderer.js +188 -8
  158. package/lib/plugin-runtime/im/outbound-segments.d.ts +29 -5
  159. package/lib/plugin-runtime/im/outbound-segments.js +130 -36
  160. package/lib/plugin-runtime/im/progressive-reply.d.ts +58 -0
  161. package/lib/plugin-runtime/im/progressive-reply.js +501 -0
  162. package/lib/plugin-runtime/im/public-api.d.ts +1 -1
  163. package/lib/request.d.ts +27 -36
  164. package/lib/request.js +14 -6
  165. package/lib/side-event/base.d.ts +64 -44
  166. package/lib/side-event/base.js +72 -19
  167. package/lib/side-event/index.d.ts +1 -1
  168. package/lib/side-event/index.js +1 -1
  169. package/lib/side-event/normalize.d.ts +7 -38
  170. package/lib/side-event/normalize.js +4 -109
  171. package/lib/side-event/scene-events.d.ts +40 -0
  172. package/lib/side-event/scene-events.js +147 -0
  173. package/lib/side-event/types.d.ts +4 -13
  174. package/lib/side-event/types.js +1 -55
  175. package/lib/system-event.d.ts +17 -12
  176. package/lib/system-event.js +8 -6
  177. package/lib/types.d.ts +23 -167
  178. package/lib/utils.d.ts +50 -33
  179. package/lib/utils.js +12 -185
  180. package/lib/venue/contracts.d.ts +21 -0
  181. package/lib/venue/contracts.js +3 -0
  182. package/lib/venue/floor-controller.d.ts +11 -0
  183. package/lib/venue/floor-controller.js +63 -0
  184. package/lib/venue/index.d.ts +13 -0
  185. package/lib/venue/index.js +11 -0
  186. package/lib/venue/membership-port.d.ts +23 -0
  187. package/lib/venue/membership-port.js +141 -0
  188. package/lib/venue/projector.d.ts +38 -0
  189. package/lib/venue/projector.js +45 -0
  190. package/lib/venue/registry.d.ts +16 -0
  191. package/lib/venue/registry.js +63 -0
  192. package/lib/venue/router.d.ts +19 -0
  193. package/lib/venue/router.js +101 -0
  194. package/lib/venue/send-limiter.d.ts +17 -0
  195. package/lib/venue/send-limiter.js +73 -0
  196. package/lib/venue/validator.d.ts +6 -0
  197. package/lib/venue/validator.js +160 -0
  198. package/package.json +24 -50
  199. package/lib/adapter.d.ts +0 -145
  200. package/lib/adapter.js +0 -377
  201. package/lib/built/adapter-process.d.ts +0 -58
  202. package/lib/built/adapter-process.js +0 -128
  203. package/lib/built/agent-preset.d.ts +0 -64
  204. package/lib/built/agent-preset.js +0 -79
  205. package/lib/built/ai-outbound/adapter-access.d.ts +0 -3
  206. package/lib/built/ai-outbound/adapter-access.js +0 -9
  207. package/lib/built/ai-outbound/extensions/qq-message.d.ts +0 -3
  208. package/lib/built/ai-outbound/extensions/qq-message.js +0 -23
  209. package/lib/built/authorization.d.ts +0 -10
  210. package/lib/built/authorization.js +0 -76
  211. package/lib/built/command.d.ts +0 -72
  212. package/lib/built/command.js +0 -105
  213. package/lib/built/component.d.ts +0 -67
  214. package/lib/built/component.js +0 -97
  215. package/lib/built/config.d.ts +0 -98
  216. package/lib/built/config.js +0 -372
  217. package/lib/built/connect-endpoint-instance.d.ts +0 -17
  218. package/lib/built/connect-endpoint-instance.js +0 -42
  219. package/lib/built/database.d.ts +0 -68
  220. package/lib/built/database.js +0 -106
  221. package/lib/built/dispatcher.d.ts +0 -141
  222. package/lib/built/dispatcher.js +0 -383
  223. package/lib/built/endpoint-commands.d.ts +0 -3
  224. package/lib/built/endpoint-commands.js +0 -99
  225. package/lib/built/endpoint-lifecycle-service.d.ts +0 -28
  226. package/lib/built/endpoint-lifecycle-service.js +0 -242
  227. package/lib/built/endpoint-lifecycle.d.ts +0 -27
  228. package/lib/built/endpoint-lifecycle.js +0 -36
  229. package/lib/built/endpoint-manager.d.ts +0 -34
  230. package/lib/built/html-renderer-loader.d.ts +0 -13
  231. package/lib/built/html-renderer-loader.js +0 -33
  232. package/lib/built/inbound-pipeline.d.ts +0 -37
  233. package/lib/built/inbound-pipeline.js +0 -63
  234. package/lib/built/inbound-runner.d.ts +0 -22
  235. package/lib/built/inbound-runner.js +0 -34
  236. package/lib/built/interactive-segment-contract.d.ts +0 -6
  237. package/lib/built/interactive-segment-contract.js +0 -9
  238. package/lib/built/interactive-segments/fallback-store.d.ts +0 -29
  239. package/lib/built/interactive-segments/fallback-store.js +0 -63
  240. package/lib/built/interactive-segments/handlers.d.ts +0 -16
  241. package/lib/built/interactive-segments/handlers.js +0 -74
  242. package/lib/built/introspection-format.d.ts +0 -10
  243. package/lib/built/introspection-format.js +0 -28
  244. package/lib/built/management-command-guard.d.ts +0 -15
  245. package/lib/built/management-command-guard.js +0 -25
  246. package/lib/built/message-filter.d.ts +0 -176
  247. package/lib/built/message-filter.js +0 -239
  248. package/lib/built/optional-peer-import.d.ts +0 -3
  249. package/lib/built/optional-peer-import.js +0 -33
  250. package/lib/built/outbound-media-contract.d.ts +0 -22
  251. package/lib/built/outbound-media-contract.js +0 -10
  252. package/lib/built/permission.d.ts +0 -51
  253. package/lib/built/permission.js +0 -99
  254. package/lib/built/permit-check.d.ts +0 -7
  255. package/lib/built/permit-check.js +0 -35
  256. package/lib/built/permit-parse.d.ts +0 -16
  257. package/lib/built/permit-parse.js +0 -32
  258. package/lib/built/platform-permit.d.ts +0 -20
  259. package/lib/built/platform-permit.js +0 -91
  260. package/lib/built/queue-im-field-contract.d.ts +0 -32
  261. package/lib/built/queue-im-field-contract.js +0 -67
  262. package/lib/built/rich-segments/adapter-policies.d.ts +0 -9
  263. package/lib/built/rich-segments/adapter-policies.js +0 -27
  264. package/lib/built/rich-segments/base.d.ts +0 -11
  265. package/lib/built/rich-segments/base.js +0 -24
  266. package/lib/built/rich-segments/builtins.d.ts +0 -4
  267. package/lib/built/rich-segments/builtins.js +0 -40
  268. package/lib/built/rich-segments/capabilities.d.ts +0 -6
  269. package/lib/built/rich-segments/capabilities.js +0 -38
  270. package/lib/built/rich-segments/html-segment.d.ts +0 -15
  271. package/lib/built/rich-segments/html-segment.js +0 -62
  272. package/lib/built/rich-segments/index.d.ts +0 -13
  273. package/lib/built/rich-segments/index.js +0 -13
  274. package/lib/built/rich-segments/markdown-segment.d.ts +0 -14
  275. package/lib/built/rich-segments/markdown-segment.js +0 -58
  276. package/lib/built/rich-segments/qrcode-segment.d.ts +0 -18
  277. package/lib/built/rich-segments/qrcode-segment.js +0 -73
  278. package/lib/built/rich-segments/registry.d.ts +0 -16
  279. package/lib/built/rich-segments/registry.js +0 -52
  280. package/lib/built/rich-segments/resolve.d.ts +0 -5
  281. package/lib/built/rich-segments/resolve.js +0 -87
  282. package/lib/built/rich-segments/tts-segment.d.ts +0 -13
  283. package/lib/built/rich-segments/tts-segment.js +0 -51
  284. package/lib/built/rich-segments/types.d.ts +0 -79
  285. package/lib/built/rich-segments/types.js +0 -17
  286. package/lib/built/runtime-io.d.ts +0 -9
  287. package/lib/built/runtime-io.js +0 -67
  288. package/lib/built/schedule.d.ts +0 -54
  289. package/lib/built/schedule.js +0 -112
  290. package/lib/built/schema-endpoint-manager.d.ts +0 -17
  291. package/lib/built/schema-endpoint-manager.js +0 -73
  292. package/lib/built/schema-feature.d.ts +0 -77
  293. package/lib/built/schema-feature.js +0 -130
  294. package/lib/built/skill.d.ts +0 -120
  295. package/lib/built/skill.js +0 -151
  296. package/lib/built/speech-loader.d.ts +0 -14
  297. package/lib/built/speech-loader.js +0 -32
  298. package/lib/built/tool.d.ts +0 -151
  299. package/lib/built/tool.js +0 -388
  300. package/lib/command.d.ts +0 -50
  301. package/lib/command.js +0 -106
  302. package/lib/component.d.ts +0 -26
  303. package/lib/component.js +0 -583
  304. package/lib/endpoint-capabilities.d.ts +0 -46
  305. package/lib/endpoint-capabilities.js +0 -55
  306. package/lib/endpoint.d.ts +0 -19
  307. package/lib/endpoint.js +0 -3
  308. package/lib/host-plugin-registry.d.ts +0 -8
  309. package/lib/host-plugin-registry.js +0 -12
  310. package/lib/plugin-context.d.ts +0 -27
  311. package/lib/plugin-context.js +0 -64
  312. package/lib/plugin-runtime/im/interactive.d.ts +0 -26
  313. package/lib/plugin-runtime/im/interactive.js +0 -46
  314. package/lib/plugin-runtime/im/login-assist-host.d.ts +0 -6
  315. package/lib/plugin-runtime/im/login-assist-host.js +0 -6
  316. package/lib/plugin-runtime/im/message-bus.d.ts +0 -38
  317. package/lib/plugin-runtime/im/message-bus.js +0 -40
  318. package/lib/plugin-runtime/im/service-tokens.d.ts +0 -18
  319. package/lib/plugin-runtime/im/service-tokens.js +0 -13
  320. package/lib/plugin.d.ts +0 -268
  321. package/lib/plugin.js +0 -583
  322. package/lib/schema-interaction.d.ts +0 -117
  323. package/lib/schema-interaction.js +0 -247
  324. package/lib/side-event/dispatch.d.ts +0 -15
  325. package/lib/side-event/dispatch.js +0 -140
  326. package/lib/tool-zod.d.ts +0 -43
  327. package/lib/tool-zod.js +0 -184
  328. /package/lib/{built/endpoint-manager.js → jsx/intrinsic-elements.js} +0 -0
@@ -1,4 +1,5 @@
1
1
  export const AI_OUTBOUND_JSON_EXAMPLE = '{"mentions":["researcher","210723495"],"text":"正文"}';
2
+ /** @deprecated Legacy `{mentions,text}` format; Agent replies use the canonical `{segments}` contract (`buildAiOutboundJsonSchema`). */
2
3
  export function buildCoreAiOutboundPromptHint(capabilities) {
3
4
  const lines = [
4
5
  'When your reply must @ peers, send rich media, buttons, or delegate — output JSON only (no Markdown wrapper):',
@@ -14,6 +15,7 @@ export function buildCoreAiOutboundPromptHint(capabilities) {
14
15
  }
15
16
  return lines.join('\n');
16
17
  }
18
+ /** @deprecated Legacy `{mentions,text}` format; Agent replies use the canonical `{segments}` contract (`buildAiOutboundJsonSchema`). */
17
19
  export function buildAiOutboundPromptHint(input) {
18
20
  const lines = [];
19
21
  if (input.rosterLines?.length) {
@@ -1,4 +1,4 @@
1
- import type { Message } from '../../message.js';
1
+ import type { Message } from '../../plugin-runtime/im/contracts.js';
2
2
  import type { MessageElement } from '../../types.js';
3
3
  import type { InteractivePolicy } from '../interactive-segments/types.js';
4
4
  import type { Segment } from '../segment-contract/types.js';
@@ -9,15 +9,6 @@ export interface ZhinAiOutboundPayload {
9
9
  segments?: Segment[];
10
10
  extensions?: Record<string, unknown>;
11
11
  }
12
- /**
13
- * @deprecated 使用 canonical `Segment`(`type` + `data` + 可选 `platform`)。
14
- * 历史 `kind` → `type`;`mode` 已删除。
15
- */
16
- export interface AiOutboundSegment {
17
- kind: string;
18
- mode?: string;
19
- data?: Record<string, unknown>;
20
- }
21
12
  export interface AiOutboundCapabilities {
22
13
  mentions?: boolean;
23
14
  richSegments?: readonly string[];
@@ -1,16 +1,39 @@
1
1
  /**
2
- * AI Trigger 工具函数
3
- * 提供 AI 触发相关的工具函数,可在插件中直接使用
2
+ * AI trigger configuration contract (`ai.trigger`).
4
3
  *
5
- * 触发方式:
6
- * 1. @机器人 - 群/频道共享会话中**仅** @ 触发 AI(前缀/关键词不在群内触发)
7
- * 2. 前缀触发 - 私聊等单人会话使用配置的前缀(如 # 或 AI:)
8
- * 3. 私聊直接对话 - 私聊时直接对话
9
- * 4. 关键词触发 - 非群/频道场景下匹配关键词时触发
10
- */
11
- import { Message } from "../message.js";
12
- import type { MessageElement, ToolScope } from "../types.js";
13
- import { type SenderRole } from './roles.js';
4
+ * The trigger decision itself lives in `@zhin.js/agent`; core only owns the config shape.
5
+ */
6
+ /**
7
+ * Ambient group engagement config. Declared structurally so core's published types do not
8
+ * depend on `@zhin.js/ai`; `@zhin.js/ai` `AmbientEngagementConfig` is the documented source.
9
+ */
10
+ export interface AmbientEngagementConfig {
11
+ /** Groups that may be joined unprompted, as `platform:groupId`; `*` for every group. Default: none. */
12
+ conversations?: string[];
13
+ /** Outside a conversation, judge a group at most this often (default 30000). */
14
+ judgeIntervalMs?: number;
15
+ /** Wait for the group to be quiet this long before judging a burst of messages (default 4000). */
16
+ quietMs?: number;
17
+ /** Minimum gap between two unprompted interjections in a group (default 120000). */
18
+ cooldownMs?: number;
19
+ /** Unprompted interjections per group per rolling hour (default 3). */
20
+ maxPerHour?: number;
21
+ /** After the bot spoke, the group is in a conversation with it for this long (default 180000). */
22
+ conversationWindowMs?: number;
23
+ /** Judge confidence required to engage, 0..1 (default 0.7). */
24
+ minConfidence?: number;
25
+ /** `shadow` logs the judgment without replying (default `active`). */
26
+ mode?: 'active' | 'shadow';
27
+ }
28
+ /** Scene-event wake config (#996); structurally identical to `@zhin.js/ai` `SceneEventWakeConfig`. */
29
+ export interface SceneEventWakeConfig {
30
+ /** Groups/channels whose high-priority events may wake the bot, as `platform:sceneId`; `*` for all. */
31
+ conversations?: string[];
32
+ /** Coalesce window per scene in ms, clamped to 3000–5000 (default 4000). */
33
+ coalesceMs?: number;
34
+ /** Minimum gap between two wakes in one scene in ms (default 15000). */
35
+ minIntervalMs?: number;
36
+ }
14
37
  /**
15
38
  * AI 触发配置
16
39
  */
@@ -31,72 +54,10 @@ export interface AITriggerConfig {
31
54
  timeout?: number;
32
55
  /** 思考中提示(可选) */
33
56
  thinkingMessage?: string;
34
- /** 错误消息模板 */
57
+ /** 入口层错误提示模板(可选;不配置时用聊天口吻,主人额外看到原因) */
35
58
  errorTemplate?: string;
36
- /** 全局 master(trigger 级,赋予 master 角色) */
37
- masters?: string[];
38
- /** 全局 trusted(trigger 级) */
39
- trusted?: string[];
40
- }
41
- /**
42
- * AI 触发检查结果
43
- */
44
- export interface AITriggerResult {
45
- triggered: boolean;
46
- content: string;
47
- }
48
- /** shouldTriggerAI 可选参数(如适配器提供的平台 @ ID) */
49
- export interface AITriggerOptions {
50
- /** 用于 @ 匹配的 Endpoint 标识符(默认仅 message.$endpoint) */
51
- endpointAtIds?: string[];
59
+ /** 群聊旁听:没人叫机器人时,由判断模型决定是否接话 */
60
+ ambient?: AmbientEngagementConfig;
61
+ /** 状态感知(#996):高优先社交事件独立唤醒回合(debounce + 限频) */
62
+ sceneEvents?: SceneEventWakeConfig;
52
63
  }
53
- /** 发送者角色解析结果 */
54
- export interface SenderRolesResult {
55
- scope: ToolScope;
56
- roles: SenderRole[];
57
- }
58
- export declare const DEFAULT_AI_TRIGGER_CONFIG: Required<AITriggerConfig>;
59
- /**
60
- * 收集用于 @ 匹配的 Endpoint 标识符
61
- */
62
- export declare function collectEndpointAtIds<T extends object>(message: Message<T>, extraIds?: string[]): string[];
63
- /**
64
- * 检查消息是否 @ 了 Endpoint
65
- */
66
- export declare function isAtEndpoint<T extends object>(message: Message<T>, endpointAtIds?: string[]): boolean;
67
- /**
68
- * 提取消息文本内容(保留富媒体信息)
69
- * 使用 segment.toString 将 MessageElement 转为 XML 格式
70
- */
71
- export declare function extractTextContent<T extends object>(message: Message<T>): string;
72
- /**
73
- * 为群/频道消息构建发送者前缀(与 sender-extra.ts buildSenderPrefix 格式对齐)
74
- * 私聊消息返回 null
75
- */
76
- export declare function buildSenderPrefixForMessage<T extends object>(message: Message<T>, roles: SenderRole[]): string | null;
77
- /**
78
- * 解析 AI 回复中的富媒体内容
79
- * 将字符串中的 XML-like 标签解析为 MessageElement
80
- */
81
- export declare function parseRichMediaContent(content: string): MessageElement[];
82
- /**
83
- * 移除 @ Endpoint 的部分
84
- */
85
- export declare function removeAtEndpoint<T extends object>(message: Message<T>, endpointAtIds?: string[]): MessageElement[];
86
- /** Endpoint 配置(adapter endpoints[].$config) */
87
- export interface EndpointConfigRoles {
88
- master?: unknown;
89
- trusted?: unknown;
90
- }
91
- /**
92
- * 解析发送者角色集合(IM 群角色 + trigger + endpoints[].$config)
93
- */
94
- export declare function resolveSenderRoles<T extends object>(message: Message<T>, config: AITriggerConfig, endpointConfig?: EndpointConfigRoles | Record<string, unknown> | null): SenderRolesResult;
95
- /**
96
- * 检查消息是否应该触发 AI
97
- */
98
- export declare function shouldTriggerAI<T extends object>(message: Message<T>, config: AITriggerConfig, options?: AITriggerOptions): AITriggerResult;
99
- /**
100
- * 合并配置
101
- */
102
- export declare function mergeAITriggerConfig(config: AITriggerConfig): Required<AITriggerConfig>;
@@ -1,257 +1,6 @@
1
1
  /**
2
- * AI Trigger 工具函数
3
- * 提供 AI 触发相关的工具函数,可在插件中直接使用
2
+ * AI trigger configuration contract (`ai.trigger`).
4
3
  *
5
- * 触发方式:
6
- * 1. @机器人 - 群/频道共享会话中**仅** @ 触发 AI(前缀/关键词不在群内触发)
7
- * 2. 前缀触发 - 私聊等单人会话使用配置的前缀(如 # 或 AI:)
8
- * 3. 私聊直接对话 - 私聊时直接对话
9
- * 4. 关键词触发 - 非群/频道场景下匹配关键词时触发
4
+ * The trigger decision itself lives in `@zhin.js/agent`; core only owns the config shape.
10
5
  */
11
- import { segment } from "../utils.js";
12
- import { readMentionSegmentTarget } from './segment-contract/mention.js';
13
- import { normalizeSenderRoles, } from './roles.js';
14
- // ============================================================================
15
- // 默认配置
16
- // ============================================================================
17
- export const DEFAULT_AI_TRIGGER_CONFIG = {
18
- enabled: true,
19
- prefixes: ['#', 'AI:', 'ai:'],
20
- respondToAt: true,
21
- respondToPrivate: true,
22
- keywords: [],
23
- ignorePrefixes: ['/', '!', '!'],
24
- timeout: 60000,
25
- thinkingMessage: '',
26
- errorTemplate: '❌ AI 处理失败: {error}',
27
- masters: [],
28
- trusted: [],
29
- };
30
- // ============================================================================
31
- // 工具函数
32
- // ============================================================================
33
- function normalizeAtIds(endpointAtIds) {
34
- const ids = endpointAtIds?.length ? endpointAtIds : [];
35
- return [...new Set(ids.map((id) => String(id)).filter(Boolean))];
36
- }
37
- function segmentAtUserId(seg) {
38
- return readMentionSegmentTarget(seg);
39
- }
40
- function isAtSegmentForEndpoint(seg, endpointKeys) {
41
- if (seg.type !== 'at' && seg.type !== 'mention')
42
- return false;
43
- const uid = segmentAtUserId(seg);
44
- return uid !== '' && endpointKeys.includes(uid);
45
- }
46
- function textMentionsEndpoint(text, endpointKeys) {
47
- for (const id of endpointKeys) {
48
- const re = new RegExp(`@${id.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}(?:\\s|$|[\\u200b\\uFEFF])`);
49
- if (re.test(text))
50
- return true;
51
- }
52
- return false;
53
- }
54
- function stripTextAtEndpoint(text, endpointKeys) {
55
- let result = text;
56
- for (const id of endpointKeys) {
57
- const re = new RegExp(`@${id.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}(?:\\s|[\\u200b\\uFEFF])?`, 'g');
58
- result = result.replace(re, '');
59
- }
60
- return result;
61
- }
62
- /**
63
- * 收集用于 @ 匹配的 Endpoint 标识符
64
- */
65
- export function collectEndpointAtIds(message, extraIds) {
66
- const ids = new Set([String(message.$endpoint)]);
67
- for (const id of extraIds ?? []) {
68
- if (id)
69
- ids.add(String(id));
70
- }
71
- return [...ids];
72
- }
73
- /**
74
- * 检查消息是否 @ 了 Endpoint
75
- */
76
- export function isAtEndpoint(message, endpointAtIds) {
77
- const endpointKeys = normalizeAtIds(endpointAtIds?.length ? endpointAtIds : collectEndpointAtIds(message));
78
- if (message.$content.some((seg) => isAtSegmentForEndpoint(seg, endpointKeys))) {
79
- return true;
80
- }
81
- for (const seg of message.$content) {
82
- if (seg.type === 'text' && seg.data?.text && textMentionsEndpoint(seg.data.text, endpointKeys)) {
83
- return true;
84
- }
85
- }
86
- return false;
87
- }
88
- /**
89
- * 提取消息文本内容(保留富媒体信息)
90
- * 使用 segment.toString 将 MessageElement 转为 XML 格式
91
- */
92
- export function extractTextContent(message) {
93
- return segment.toString(message.$content);
94
- }
95
- /**
96
- * 为群/频道消息构建发送者前缀(与 sender-extra.ts buildSenderPrefix 格式对齐)
97
- * 私聊消息返回 null
98
- */
99
- export function buildSenderPrefixForMessage(message, roles) {
100
- const scope = message.$channel?.type || 'private';
101
- if (scope !== 'group' && scope !== 'channel')
102
- return null;
103
- const rawId = String(message.$sender?.id ?? 'unknown');
104
- const id = rawId.trim().replace(/[\]\s]+/g, '_').slice(0, 64) || 'unknown';
105
- const rawName = message.$sender?.name;
106
- const name = (rawName?.trim() || 'unknown').replace(/[\]\s]+/g, '_').slice(0, 64);
107
- const nonUserRoles = roles.filter((r) => r !== 'user');
108
- const roleStr = nonUserRoles.join(',') || 'user';
109
- return `[sender:id=${id} name=${name} roles=${roleStr}]`;
110
- }
111
- /**
112
- * 解析 AI 回复中的富媒体内容
113
- * 将字符串中的 XML-like 标签解析为 MessageElement
114
- */
115
- export function parseRichMediaContent(content) {
116
- try {
117
- const parsed = segment.from(content);
118
- const elements = Array.isArray(parsed) ? parsed : [parsed];
119
- return elements.map(el => {
120
- if (typeof el === 'string') {
121
- return { type: 'text', data: { text: el } };
122
- }
123
- return el;
124
- });
125
- }
126
- catch (error) {
127
- return [{ type: 'text', data: { text: content } }];
128
- }
129
- }
130
- /**
131
- * 移除 @ Endpoint 的部分
132
- */
133
- export function removeAtEndpoint(message, endpointAtIds) {
134
- const endpointKeys = normalizeAtIds(endpointAtIds?.length ? endpointAtIds : collectEndpointAtIds(message));
135
- return message.$content
136
- .filter((seg) => !isAtSegmentForEndpoint(seg, endpointKeys))
137
- .map((seg) => {
138
- if (seg.type !== 'text' || !seg.data?.text)
139
- return seg;
140
- const stripped = stripTextAtEndpoint(seg.data.text, endpointKeys).trim();
141
- if (!stripped)
142
- return null;
143
- return { ...seg, data: { ...seg.data, text: stripped } };
144
- })
145
- .filter((seg) => seg != null);
146
- }
147
- function normalizeEndpointIdList(input) {
148
- if (Array.isArray(input))
149
- return input.map((v) => String(v)).filter(Boolean);
150
- if (typeof input === 'string') {
151
- return input.split(/[\s,]+/).map((v) => v.trim()).filter(Boolean);
152
- }
153
- return [];
154
- }
155
- function collectEndpointTrustedIds(endpointConfig) {
156
- if (!endpointConfig)
157
- return [];
158
- return normalizeEndpointIdList(endpointConfig.trusted);
159
- }
160
- /**
161
- * 解析发送者角色集合(IM 群角色 + trigger + endpoints[].$config)
162
- */
163
- export function resolveSenderRoles(message, config, endpointConfig) {
164
- const scope = message.$channel?.type || 'private';
165
- // process 适配器(stdin/本机 CLI):操作者即宿主用户,恒为 master
166
- if (message.$adapter === 'process') {
167
- return {
168
- scope,
169
- roles: normalizeSenderRoles(['master']),
170
- };
171
- }
172
- const senderId = String(message.$sender.id);
173
- const roles = [];
174
- const masters = config.masters || [];
175
- const globalTrusted = config.trusted || [];
176
- const cfg = endpointConfig;
177
- const endpointMaster = cfg?.master != null ? String(cfg.master) : undefined;
178
- const endpointTrustedIds = collectEndpointTrustedIds(cfg);
179
- if (masters.includes(senderId) || (endpointMaster != null && senderId === endpointMaster)) {
180
- roles.push('master');
181
- }
182
- else if (globalTrusted.includes(senderId) || endpointTrustedIds.includes(senderId)) {
183
- roles.push('trusted');
184
- }
185
- return {
186
- scope,
187
- roles: normalizeSenderRoles(roles),
188
- };
189
- }
190
- /**
191
- * 检查消息是否应该触发 AI
192
- */
193
- export function shouldTriggerAI(message, config, options) {
194
- const fullConfig = { ...DEFAULT_AI_TRIGGER_CONFIG, ...config };
195
- const endpointAtIds = collectEndpointAtIds(message, options?.endpointAtIds);
196
- if (!fullConfig.enabled) {
197
- return { triggered: false, content: '' };
198
- }
199
- const text = extractTextContent(message);
200
- const scope = message.$channel?.type || 'private';
201
- const isSharedSession = scope === 'group' || scope === 'channel';
202
- /** 对群/频道触发结果附加发送者前缀(与 DB 历史的 buildSenderPrefix 格式对齐) */
203
- const withSenderPrefix = (content) => {
204
- if (!isSharedSession)
205
- return content;
206
- const { roles } = resolveSenderRoles(message, config);
207
- const prefix = buildSenderPrefixForMessage(message, roles);
208
- if (!prefix)
209
- return content;
210
- return content ? `${prefix} ${content}` : prefix;
211
- };
212
- // 检查忽略前缀
213
- for (const prefix of fullConfig.ignorePrefixes) {
214
- if (text.startsWith(prefix)) {
215
- return { triggered: false, content: '' };
216
- }
217
- }
218
- // 1. 前缀触发(群/频道共享 session 不走此前缀,仅 @ 触发 AI)
219
- if (!isSharedSession) {
220
- for (const prefix of fullConfig.prefixes) {
221
- if (text.startsWith(prefix)) {
222
- return { triggered: true, content: text.slice(prefix.length).trim() };
223
- }
224
- }
225
- }
226
- // 2. 检查 @ 触发(群/频道主路径;仅 @ 无正文时也触发,由 Agent 处理空输入)
227
- if (fullConfig.respondToAt && isAtEndpoint(message, endpointAtIds)) {
228
- const content = removeAtEndpoint(message, endpointAtIds);
229
- const body = content.length ? segment.toString(content).trim() : '';
230
- return {
231
- triggered: true,
232
- content: withSenderPrefix(body),
233
- };
234
- }
235
- // 3. 检查私聊触发
236
- if (fullConfig.respondToPrivate && message.$channel?.type === 'private') {
237
- if (text.trim()) {
238
- return { triggered: true, content: text.trim() };
239
- }
240
- }
241
- // 4. 关键词触发(群/频道不启用,避免旁听消息误触发)
242
- if (!isSharedSession && fullConfig.keywords.length > 0) {
243
- const lowerText = text.toLowerCase();
244
- for (const keyword of fullConfig.keywords) {
245
- if (lowerText.includes(keyword.toLowerCase())) {
246
- return { triggered: true, content: text };
247
- }
248
- }
249
- }
250
- return { triggered: false, content: '' };
251
- }
252
- /**
253
- * 合并配置
254
- */
255
- export function mergeAITriggerConfig(config) {
256
- return { ...DEFAULT_AI_TRIGGER_CONFIG, ...config };
257
- }
6
+ export {};
@@ -34,7 +34,8 @@ export interface SceneManagementMethodSpec {
34
34
  toolSuffix: string;
35
35
  description: string;
36
36
  keywords: string[];
37
- permit?: string;
37
+ /** Platform standing the sender needs in the conversation (`platform:<standing>` permit, ADR 0056 §5). */
38
+ permit?: 'admin' | 'owner';
38
39
  extraParams: Record<string, {
39
40
  type: string;
40
41
  description: string;
@@ -46,15 +47,29 @@ export interface SceneManagementMethodSpec {
46
47
  export declare const SCENE_MANAGEMENT_METHOD_SPECS: SceneManagementMethodSpec[];
47
48
  export declare const SCENE_MANAGEMENT_SKILL_TAGS: string[];
48
49
  export declare const SCENE_MANAGEMENT_SKILL_KEYWORDS: string[];
50
+ /**
51
+ * Message the tool runs for. Only its endpoint / conversation are read: platform (`platform:*`) and
52
+ * Bot (`bot:*`) permits are judged in that conversation, so the target always comes from it.
53
+ */
54
+ export interface SceneManagementInvocation {
55
+ readonly endpointId?: string;
56
+ readonly conversation?: {
57
+ readonly id: string;
58
+ readonly endpoint?: {
59
+ readonly id: string;
60
+ };
61
+ };
62
+ }
49
63
  export interface SceneManagementToolFactory<T> {
50
- (spec: SceneManagementMethodSpec, prefix: string, execute: (args: Record<string, any>) => Promise<any>): T;
64
+ (spec: SceneManagementMethodSpec, prefix: string, execute: (args: Record<string, any>, message?: SceneManagementInvocation) => Promise<any>): T;
51
65
  }
52
- export declare function defaultScenePermitResolver(adapterPrefix: string): (logicalPerm: string) => string;
66
+ /** Platform standing permits for a spec: the sender's and the Bot's own (ADR 0056 §5). */
67
+ export declare function sceneManagementSpecPermits(spec: Pick<SceneManagementMethodSpec, 'permit'>): string[] | undefined;
68
+ /** Default: the sender's normalized platform standing (`platform:admin` / `platform:owner`). */
69
+ export declare function defaultScenePermitResolver(_adapterPrefix?: string): (logicalPerm: string) => string;
53
70
  export interface CreateSceneManagementToolsOptions {
54
- /** 将 SCENE_MANAGEMENT_METHOD_SPECS 逻辑 perm(scene_admin/scene_owner)映射为 platform(...) 字符串 */
71
+ /** 将 SCENE_MANAGEMENT_METHOD_SPECS 的平台地位(admin / owner)映射为 permit 字符串(缺省 `platform:<地位>`) */
55
72
  permitResolver?: (logicalPerm: string) => string | undefined;
56
- /** 是否注册默认 QQ 系 scene checker(默认 true) */
57
- registerChecker?: boolean;
58
73
  }
59
74
  export declare function createSceneManagementTools(adapter: ISceneManagement, prefix: string, options?: CreateSceneManagementToolsOptions): Tool[];
60
75
  export declare function createSceneManagementToolsRaw<T>(adapter: ISceneManagement, prefix: string, factory: SceneManagementToolFactory<T>): T[];
@@ -12,14 +12,13 @@
12
12
  * tools.forEach(t => this.addTool(t));
13
13
  * // 另:包内 skills/<name>/SKILL.md 供 Agent 发现
14
14
  */
15
- import { registerDefaultScenePlatformPermitChecker } from './platform-permit.js';
16
15
  export const SCENE_MANAGEMENT_METHOD_SPECS = [
17
16
  {
18
17
  method: 'removeMember',
19
18
  toolSuffix: 'remove_member',
20
19
  description: '将成员移出当前 IM 场景。适用于严重违规、广告号等需要移除的场景。如果只需要用户名而没有 user_id,请先调用 list_members 查询',
21
20
  keywords: ['踢', 'kick', '移除', '踢出'],
22
- permit: 'scene_admin',
21
+ permit: 'admin',
23
22
  extraParams: {
24
23
  user_id: { type: 'string', description: '目标用户 ID(如果只有昵称,先用 list_members 查询获取)' },
25
24
  },
@@ -30,7 +29,7 @@ export const SCENE_MANAGEMENT_METHOD_SPECS = [
30
29
  toolSuffix: 'mute_member',
31
30
  description: '禁言或解除禁言群成员。适用于违规发言、刷屏、骚扰他人等需要临时限制发言的场景。duration 单位为秒,传 0 表示解除禁言。默认禁言 10 分钟(600秒)。如果只有昵称而没有 user_id,请先调用 list_members 查询',
32
31
  keywords: ['禁言', 'mute', '静音', '解除禁言', '解禁', '闭嘴'],
33
- permit: 'scene_admin',
32
+ permit: 'admin',
34
33
  extraParams: {
35
34
  user_id: { type: 'string', description: '目标用户 ID(如果只有昵称,先用 list_members 查询获取)' },
36
35
  duration: { type: 'number', description: '禁言时长(秒),0=解除禁言,默认600(10分钟)。常用值:60=1分钟, 600=10分钟, 3600=1小时, 86400=1天', default: 600 },
@@ -42,7 +41,7 @@ export const SCENE_MANAGEMENT_METHOD_SPECS = [
42
41
  toolSuffix: 'set_nickname',
43
42
  description: '设置群成员的群昵称/名片。仅修改群内显示名称,不影响用户的全局昵称。如果只有昵称而没有 user_id,请先调用 list_members 查询',
44
43
  keywords: ['昵称', '名片', 'nickname', 'card', '改名片'],
45
- permit: 'scene_admin',
44
+ permit: 'admin',
46
45
  extraParams: {
47
46
  user_id: { type: 'string', description: '目标用户 ID(如果只有昵称,先用 list_members 查询获取)' },
48
47
  nickname: { type: 'string', description: '新的群昵称/名片' },
@@ -54,7 +53,7 @@ export const SCENE_MANAGEMENT_METHOD_SPECS = [
54
53
  toolSuffix: 'set_moderator',
55
54
  description: '设置或取消场景管理员。注意:此操作通常需要场景所有者权限。enable=true 为设置管理员,enable=false 为取消管理员。如果只有昵称而没有 user_id,请先调用 list_members 查询',
56
55
  keywords: ['管理员', 'admin', '设置管理', '取消管理', '提升管理', '撤销管理'],
57
- permit: 'scene_owner',
56
+ permit: 'owner',
58
57
  extraParams: {
59
58
  user_id: { type: 'string', description: '目标用户 ID(如果只有昵称,先用 list_members 查询获取)' },
60
59
  enable: { type: 'boolean', description: 'true=设置为管理员,false=取消管理员身份', default: true },
@@ -74,7 +73,7 @@ export const SCENE_MANAGEMENT_METHOD_SPECS = [
74
73
  toolSuffix: 'ban_member',
75
74
  description: '永久封禁成员(拉入黑名单)。与踢人(kick)不同,封禁后该成员无法再加入群聊。适用于恶意用户、严重违规等需要永久禁止的场景。如果只有昵称而没有 user_id,请先调用 list_members 查询',
76
75
  keywords: ['封禁', 'ban', '拉黑', '黑名单'],
77
- permit: 'scene_admin',
76
+ permit: 'admin',
78
77
  extraParams: {
79
78
  user_id: { type: 'string', description: '目标用户 ID(如果只有昵称,先用 list_members 查询获取)' },
80
79
  reason: { type: 'string', description: '封禁原因(将记录在封禁日志中)' },
@@ -86,7 +85,7 @@ export const SCENE_MANAGEMENT_METHOD_SPECS = [
86
85
  toolSuffix: 'unban_member',
87
86
  description: '解除封禁,将成员从黑名单中移除。解除后该成员可以重新加入群聊。如果只有昵称而没有 user_id,请先调用 list_members 查询',
88
87
  keywords: ['解封', 'unban', '解除封禁', '移出黑名单'],
89
- permit: 'scene_admin',
88
+ permit: 'admin',
90
89
  extraParams: {
91
90
  user_id: { type: 'string', description: '目标用户 ID(如果只有昵称,先用 list_members 查询获取)' },
92
91
  },
@@ -97,7 +96,7 @@ export const SCENE_MANAGEMENT_METHOD_SPECS = [
97
96
  toolSuffix: 'rename_scene',
98
97
  description: '修改 IM 场景名称。修改后所有成员立即可见新名称',
99
98
  keywords: ['群名', '改名', 'group name', '修改群名'],
100
- permit: 'scene_admin',
99
+ permit: 'admin',
101
100
  extraParams: {
102
101
  name: { type: 'string', description: '新群名称' },
103
102
  },
@@ -108,7 +107,7 @@ export const SCENE_MANAGEMENT_METHOD_SPECS = [
108
107
  toolSuffix: 'set_scene_muted',
109
108
  description: '开启或关闭场景全员禁言。开启后除管理员外所有成员都无法发言。适用于紧急维护、重要通知、聊天秩序混乱等场景。enable=true 开启,enable=false 解除',
110
109
  keywords: ['全员禁言', 'mute all', '全体禁言', '全体解禁'],
111
- permit: 'scene_admin',
110
+ permit: 'admin',
112
111
  extraParams: {
113
112
  enable: { type: 'boolean', description: 'true=开启全员禁言,false=解除全员禁言', default: true },
114
113
  },
@@ -130,20 +129,26 @@ export const SCENE_MANAGEMENT_SKILL_KEYWORDS = [
130
129
  '场景治理', '群管理', '踢人', '禁言', '封禁', '管理员', '群名',
131
130
  '成员', 'kick', 'mute', 'ban', 'admin', 'members',
132
131
  ];
133
- export function defaultScenePermitResolver(adapterPrefix) {
134
- return (logicalPerm) => `platform(${adapterPrefix},${logicalPerm})`;
132
+ /** Platform standing permits for a spec: the sender's and the Bot's own (ADR 0056 §5). */
133
+ export function sceneManagementSpecPermits(spec) {
134
+ return spec.permit ? [`platform:${spec.permit}`, `bot:${spec.permit}`] : undefined;
135
+ }
136
+ /** Default: the sender's normalized platform standing (`platform:admin` / `platform:owner`). */
137
+ export function defaultScenePermitResolver(_adapterPrefix) {
138
+ return (logicalPerm) => `platform:${logicalPerm}`;
135
139
  }
136
140
  function resolveSpecPermit(specPerm, prefix, permitResolver) {
137
141
  if (!specPerm)
138
142
  return undefined;
139
143
  const resolved = permitResolver(specPerm);
140
- return resolved ? [resolved] : undefined;
144
+ // ADR 0056 §5: the sender's platform standing and the Bot's own standing are both required — the
145
+ // Bot performs the action, so it must hold the same standing in the conversation.
146
+ const bot = specPerm === 'owner' || specPerm === 'admin' ? `bot:${specPerm}` : undefined;
147
+ const permits = [...(resolved ? [resolved] : []), ...(bot ? [bot] : [])];
148
+ return permits.length ? permits : undefined;
141
149
  }
142
150
  export function createSceneManagementTools(adapter, prefix, options = {}) {
143
151
  const permitResolver = options.permitResolver ?? defaultScenePermitResolver(prefix);
144
- if (options.registerChecker !== false) {
145
- registerDefaultScenePlatformPermitChecker(prefix);
146
- }
147
152
  return createSceneManagementToolsRaw(adapter, prefix, (spec, prefix, execute) => {
148
153
  const specPermissions = resolveSpecPermit(spec.permit, prefix, permitResolver);
149
154
  return {
@@ -174,8 +179,14 @@ export function createSceneManagementToolsRaw(adapter, prefix, factory) {
174
179
  if (typeof fn !== 'function')
175
180
  continue;
176
181
  const boundFn = fn.bind(adapter);
177
- const execute = async (args) => {
178
- const { endpoint_id, scene_id, ...rest } = args;
182
+ const execute = async (args, message) => {
183
+ const { endpoint_id: _endpoint, scene_id: _scene, ...rest } = args;
184
+ // The target is the conversation the permits were judged in; model-supplied ids are ignored.
185
+ const scene_id = message?.conversation?.id;
186
+ const endpoint_id = message?.endpointId ?? message?.conversation?.endpoint?.id;
187
+ if (!scene_id || !endpoint_id) {
188
+ throw new Error(`${prefix}_${spec.toolSuffix} only acts on the current conversation`);
189
+ }
179
190
  const methodArgs = buildSceneMethodArgs(spec.method, endpoint_id, scene_id, rest);
180
191
  return boundFn.apply(adapter, methodArgs);
181
192
  };
@@ -85,7 +85,8 @@ function normalizeReply(seg) {
85
85
  const messageId = String(data.message_id ?? data.id ?? '').trim();
86
86
  if (!messageId)
87
87
  return seg;
88
- return { type: 'reply', data: { message_id: messageId } };
88
+ const platform = readPlatform(seg);
89
+ return { type: 'reply', data: { message_id: messageId }, ...(platform ? { platform } : {}) };
89
90
  }
90
91
  function normalizeLink(seg) {
91
92
  const data = seg.data;
@@ -161,6 +162,8 @@ function normalizeMarkdown(seg) {
161
162
  function normalizeSegment(seg) {
162
163
  if (seg.type === 'at' || seg.type === 'mention')
163
164
  return normalizeMention(seg);
165
+ if (seg.type === 'record' || seg.type === 'voice')
166
+ return normalizeMedia({ ...seg, type: 'audio' });
164
167
  if (MEDIA_SEGMENT_TYPES.has(seg.type))
165
168
  return normalizeMedia(seg);
166
169
  if (seg.type === 'reply')
@@ -1,9 +1,8 @@
1
1
  /**
2
- * 出站 `html` 消息段兜底:等价于 Adapter policy `html:'text'`。
3
- * 出站渲染首选 `resolveRichSegments`(renderSendMessage 首步)。
2
+ * Convert unresolved `html` segments to portable text content.
3
+ * Canonical outbound rendering owns when this fallback is applied.
4
4
  */
5
- import type { Plugin } from '../plugin.js';
6
- import type { SendContent } from '../types.js';
7
- export declare function coerceHtmlSegmentsToText(content: SendContent): SendContent;
8
- /** 注册链尾 before.sendMessage:将未转换的 html 段降级为 text */
9
- export declare function registerHtmlSegmentFallback(plugin: Plugin): () => void;
5
+ import type { MessageElement } from '../types.js';
6
+ type SegmentContent = string | MessageElement | readonly SegmentContent[];
7
+ export declare function coerceHtmlSegmentsToText(content: SegmentContent): SegmentContent;
8
+ export {};
@@ -1,7 +1,7 @@
1
1
  import { segment } from '../utils.js';
2
2
  import { htmlToFallbackText } from './html-to-text.js';
3
3
  function asArray(content) {
4
- return Array.isArray(content) ? content : [content];
4
+ return Array.isArray(content) ? content.flatMap(item => asArray(item)) : [content];
5
5
  }
6
6
  function resolveHtmlSegmentText(data) {
7
7
  if (typeof data.text === 'string' && data.text.length > 0)
@@ -32,18 +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
- }