@zhin.js/core 1.5.16 → 1.7.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 (334) 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 +330 -25
  35. package/lib/built/login-assist.js +1156 -75
  36. package/lib/built/login-captcha.d.ts +62 -0
  37. package/lib/built/login-captcha.js +107 -0
  38. package/lib/built/message-enrich.d.ts +24 -27
  39. package/lib/built/message-enrich.js +53 -49
  40. package/lib/built/outbound-content-arrays.d.ts +4 -0
  41. package/lib/built/outbound-content-arrays.js +32 -0
  42. package/lib/built/outbound-media-trust.d.ts +46 -0
  43. package/lib/built/outbound-media-trust.js +245 -0
  44. package/lib/built/outbound-media-utils.d.ts +5 -3
  45. package/lib/built/outbound-media-utils.js +5 -3
  46. package/lib/built/readable-link.d.ts +4 -0
  47. package/lib/built/readable-link.js +32 -0
  48. package/lib/built/rich-segments/markdown-to-text.d.ts +1 -2
  49. package/lib/built/rich-segments/markdown-to-text.js +141 -17
  50. package/lib/built/roles.d.ts +141 -12
  51. package/lib/built/roles.js +253 -52
  52. package/lib/built/segment-contract/assert.js +8 -2
  53. package/lib/built/segment-contract/delivery.js +1 -0
  54. package/lib/built/segment-contract/index.d.ts +3 -3
  55. package/lib/built/segment-contract/index.js +2 -2
  56. package/lib/built/segment-contract/json-schema.d.ts +39 -5
  57. package/lib/built/segment-contract/json-schema.js +207 -24
  58. package/lib/built/segment-contract/preview.js +8 -1
  59. package/lib/built/segment-contract/text.js +1 -1
  60. package/lib/built/segment-contract/types.d.ts +2 -2
  61. package/lib/built/segment-contract/validate.d.ts +1553 -224
  62. package/lib/built/segment-contract/validate.js +39 -3
  63. package/lib/built/tool-access.d.ts +5 -0
  64. package/lib/built/tool-access.js +17 -0
  65. package/lib/built/user-interaction.d.ts +5 -4
  66. package/lib/built/user-interaction.js +64 -52
  67. package/lib/errors.d.ts +1 -18
  68. package/lib/errors.js +1 -26
  69. package/lib/feature/command-public-api.d.ts +5 -0
  70. package/lib/feature/command-public-api.js +5 -0
  71. package/lib/feature/command.d.ts +2 -0
  72. package/lib/feature/command.js +1 -0
  73. package/lib/feature/component.d.ts +1 -0
  74. package/lib/feature/component.js +1 -0
  75. package/lib/feature/handler.d.ts +13 -7
  76. package/lib/feature/handler.js +2 -1
  77. package/lib/feature/middleware-public-api.d.ts +6 -0
  78. package/lib/feature/middleware-public-api.js +6 -0
  79. package/lib/feature/middleware.d.ts +22 -2
  80. package/lib/feature/middleware.js +7 -2
  81. package/lib/im-scene.d.ts +4 -3
  82. package/lib/im-scene.js +9 -9
  83. package/lib/im-session-id.d.ts +20 -12
  84. package/lib/im-session-id.js +8 -8
  85. package/lib/index.d.ts +20 -48
  86. package/lib/index.js +15 -41
  87. package/lib/jsx/intrinsic-elements.d.ts +83 -0
  88. package/lib/jsx/message-renderer.d.ts +13 -0
  89. package/lib/jsx/message-renderer.js +128 -0
  90. package/lib/jsx/message-tags.d.ts +133 -0
  91. package/lib/jsx/message-tags.js +50 -0
  92. package/lib/jsx-dev-runtime.d.ts +2 -2
  93. package/lib/jsx-dev-runtime.js +1 -2
  94. package/lib/jsx-runtime.d.ts +2 -12
  95. package/lib/jsx-runtime.js +1 -10
  96. package/lib/jsx.d.ts +6 -30
  97. package/lib/jsx.js +3 -93
  98. package/lib/message.d.ts +0 -40
  99. package/lib/message.js +1 -27
  100. package/lib/models/system-log.d.ts +0 -2
  101. package/lib/models/system-log.js +1 -8
  102. package/lib/models/user.d.ts +0 -2
  103. package/lib/models/user.js +1 -7
  104. package/lib/notice.d.ts +38 -33
  105. package/lib/notice.js +23 -7
  106. package/lib/plugin-runtime/im/command-feedback.d.ts +59 -0
  107. package/lib/plugin-runtime/im/command-feedback.js +148 -0
  108. package/lib/plugin-runtime/im/contracts.d.ts +217 -32
  109. package/lib/plugin-runtime/im/contracts.js +141 -23
  110. package/lib/plugin-runtime/im/conversation-runtime.d.ts +42 -0
  111. package/lib/plugin-runtime/im/conversation-runtime.js +451 -0
  112. package/lib/plugin-runtime/im/endpoint-runtime.d.ts +112 -0
  113. package/lib/plugin-runtime/im/endpoint-runtime.js +434 -0
  114. package/lib/plugin-runtime/im/feature-gate.d.ts +21 -0
  115. package/lib/plugin-runtime/im/feature-gate.js +88 -0
  116. package/lib/plugin-runtime/im/host/component-host-installer.d.ts +2 -0
  117. package/lib/plugin-runtime/im/host/component-host-installer.js +14 -0
  118. package/lib/plugin-runtime/im/host/conversation-migration.d.ts +5 -0
  119. package/lib/plugin-runtime/im/host/conversation-migration.js +75 -0
  120. package/lib/plugin-runtime/im/host/database-config.d.ts +10 -0
  121. package/lib/plugin-runtime/im/host/database-config.js +152 -0
  122. package/lib/plugin-runtime/im/host/database-console-schema.d.ts +79 -0
  123. package/lib/plugin-runtime/im/host/database-console-schema.js +477 -0
  124. package/lib/plugin-runtime/im/host/database-console-sql.d.ts +66 -0
  125. package/lib/plugin-runtime/im/host/database-console-sql.js +459 -0
  126. package/lib/plugin-runtime/im/host/database-host-installer.d.ts +60 -0
  127. package/lib/plugin-runtime/im/host/database-host-installer.js +1166 -0
  128. package/lib/plugin-runtime/im/host/database-state.d.ts +9 -0
  129. package/lib/plugin-runtime/im/host/database-state.js +91 -0
  130. package/lib/plugin-runtime/im/host/index.d.ts +8 -0
  131. package/lib/plugin-runtime/im/host/index.js +8 -0
  132. package/lib/plugin-runtime/im/host/locale-host-installer.d.ts +3 -0
  133. package/lib/plugin-runtime/im/host/locale-host-installer.js +60 -0
  134. package/lib/plugin-runtime/im/host/outbound-host-installer.d.ts +8 -0
  135. package/lib/plugin-runtime/im/host/outbound-host-installer.js +153 -0
  136. package/lib/plugin-runtime/im/host/sender-enrichment.d.ts +34 -0
  137. package/lib/plugin-runtime/im/host/sender-enrichment.js +82 -0
  138. package/lib/plugin-runtime/im/im-runtime.d.ts +40 -111
  139. package/lib/plugin-runtime/im/im-runtime.js +235 -1059
  140. package/lib/plugin-runtime/im/inbound-dedup.d.ts +84 -0
  141. package/lib/plugin-runtime/im/inbound-dedup.js +322 -0
  142. package/lib/plugin-runtime/im/inbound-origin.d.ts +150 -0
  143. package/lib/plugin-runtime/im/inbound-origin.js +183 -0
  144. package/lib/plugin-runtime/im/inbound-runtime.d.ts +59 -0
  145. package/lib/plugin-runtime/im/inbound-runtime.js +478 -0
  146. package/lib/plugin-runtime/im/inbound-spine.d.ts +196 -0
  147. package/lib/plugin-runtime/im/inbound-spine.js +335 -0
  148. package/lib/plugin-runtime/im/index.d.ts +15 -4
  149. package/lib/plugin-runtime/im/index.js +11 -4
  150. package/lib/plugin-runtime/im/interaction-runtime.d.ts +50 -0
  151. package/lib/plugin-runtime/im/interaction-runtime.js +390 -0
  152. package/lib/plugin-runtime/im/interactive-router.d.ts +81 -0
  153. package/lib/plugin-runtime/im/interactive-router.js +382 -0
  154. package/lib/plugin-runtime/im/message-diagnostics.d.ts +70 -0
  155. package/lib/plugin-runtime/im/message-diagnostics.js +182 -0
  156. package/lib/plugin-runtime/im/message-dispatcher.d.ts +18 -4
  157. package/lib/plugin-runtime/im/message-dispatcher.js +138 -20
  158. package/lib/plugin-runtime/im/message-events.d.ts +85 -0
  159. package/lib/plugin-runtime/im/message-events.js +113 -0
  160. package/lib/plugin-runtime/im/outbound-delivery-runtime.d.ts +39 -0
  161. package/lib/plugin-runtime/im/outbound-delivery-runtime.js +450 -0
  162. package/lib/plugin-runtime/im/outbound-renderer.d.ts +52 -3
  163. package/lib/plugin-runtime/im/outbound-renderer.js +188 -8
  164. package/lib/plugin-runtime/im/outbound-segments.d.ts +29 -5
  165. package/lib/plugin-runtime/im/outbound-segments.js +130 -36
  166. package/lib/plugin-runtime/im/progressive-reply.d.ts +58 -0
  167. package/lib/plugin-runtime/im/progressive-reply.js +501 -0
  168. package/lib/plugin-runtime/im/public-api.d.ts +1 -1
  169. package/lib/request.d.ts +27 -36
  170. package/lib/request.js +14 -6
  171. package/lib/side-event/base.d.ts +64 -44
  172. package/lib/side-event/base.js +72 -19
  173. package/lib/side-event/index.d.ts +1 -1
  174. package/lib/side-event/index.js +1 -1
  175. package/lib/side-event/normalize.d.ts +7 -38
  176. package/lib/side-event/normalize.js +4 -109
  177. package/lib/side-event/scene-events.d.ts +40 -0
  178. package/lib/side-event/scene-events.js +147 -0
  179. package/lib/side-event/types.d.ts +4 -13
  180. package/lib/side-event/types.js +1 -55
  181. package/lib/system-event.d.ts +17 -12
  182. package/lib/system-event.js +8 -6
  183. package/lib/types.d.ts +23 -167
  184. package/lib/utils.d.ts +50 -33
  185. package/lib/utils.js +12 -185
  186. package/lib/venue/contracts.d.ts +21 -0
  187. package/lib/venue/contracts.js +3 -0
  188. package/lib/venue/floor-controller.d.ts +11 -0
  189. package/lib/venue/floor-controller.js +63 -0
  190. package/lib/venue/index.d.ts +13 -0
  191. package/lib/venue/index.js +11 -0
  192. package/lib/venue/membership-port.d.ts +23 -0
  193. package/lib/venue/membership-port.js +141 -0
  194. package/lib/venue/projector.d.ts +38 -0
  195. package/lib/venue/projector.js +45 -0
  196. package/lib/venue/registry.d.ts +16 -0
  197. package/lib/venue/registry.js +63 -0
  198. package/lib/venue/router.d.ts +19 -0
  199. package/lib/venue/router.js +101 -0
  200. package/lib/venue/send-limiter.d.ts +17 -0
  201. package/lib/venue/send-limiter.js +73 -0
  202. package/lib/venue/validator.d.ts +6 -0
  203. package/lib/venue/validator.js +160 -0
  204. package/package.json +24 -50
  205. package/lib/adapter.d.ts +0 -145
  206. package/lib/adapter.js +0 -377
  207. package/lib/built/adapter-process.d.ts +0 -58
  208. package/lib/built/adapter-process.js +0 -128
  209. package/lib/built/agent-preset.d.ts +0 -64
  210. package/lib/built/agent-preset.js +0 -79
  211. package/lib/built/ai-outbound/adapter-access.d.ts +0 -3
  212. package/lib/built/ai-outbound/adapter-access.js +0 -9
  213. package/lib/built/ai-outbound/extensions/qq-message.d.ts +0 -3
  214. package/lib/built/ai-outbound/extensions/qq-message.js +0 -23
  215. package/lib/built/authorization.d.ts +0 -10
  216. package/lib/built/authorization.js +0 -76
  217. package/lib/built/command.d.ts +0 -72
  218. package/lib/built/command.js +0 -105
  219. package/lib/built/component.d.ts +0 -67
  220. package/lib/built/component.js +0 -97
  221. package/lib/built/config.d.ts +0 -98
  222. package/lib/built/config.js +0 -372
  223. package/lib/built/connect-endpoint-instance.d.ts +0 -17
  224. package/lib/built/connect-endpoint-instance.js +0 -42
  225. package/lib/built/database.d.ts +0 -68
  226. package/lib/built/database.js +0 -106
  227. package/lib/built/dispatcher.d.ts +0 -141
  228. package/lib/built/dispatcher.js +0 -383
  229. package/lib/built/endpoint-commands.d.ts +0 -3
  230. package/lib/built/endpoint-commands.js +0 -99
  231. package/lib/built/endpoint-lifecycle-service.d.ts +0 -28
  232. package/lib/built/endpoint-lifecycle-service.js +0 -242
  233. package/lib/built/endpoint-lifecycle.d.ts +0 -27
  234. package/lib/built/endpoint-lifecycle.js +0 -36
  235. package/lib/built/endpoint-manager.d.ts +0 -34
  236. package/lib/built/html-renderer-loader.d.ts +0 -13
  237. package/lib/built/html-renderer-loader.js +0 -33
  238. package/lib/built/inbound-pipeline.d.ts +0 -37
  239. package/lib/built/inbound-pipeline.js +0 -63
  240. package/lib/built/inbound-runner.d.ts +0 -22
  241. package/lib/built/inbound-runner.js +0 -34
  242. package/lib/built/interactive-segment-contract.d.ts +0 -6
  243. package/lib/built/interactive-segment-contract.js +0 -9
  244. package/lib/built/interactive-segments/fallback-store.d.ts +0 -29
  245. package/lib/built/interactive-segments/fallback-store.js +0 -63
  246. package/lib/built/interactive-segments/handlers.d.ts +0 -16
  247. package/lib/built/interactive-segments/handlers.js +0 -74
  248. package/lib/built/introspection-format.d.ts +0 -10
  249. package/lib/built/introspection-format.js +0 -28
  250. package/lib/built/management-command-guard.d.ts +0 -15
  251. package/lib/built/management-command-guard.js +0 -25
  252. package/lib/built/message-filter.d.ts +0 -176
  253. package/lib/built/message-filter.js +0 -239
  254. package/lib/built/optional-peer-import.d.ts +0 -3
  255. package/lib/built/optional-peer-import.js +0 -33
  256. package/lib/built/outbound-media-contract.d.ts +0 -22
  257. package/lib/built/outbound-media-contract.js +0 -10
  258. package/lib/built/permission.d.ts +0 -51
  259. package/lib/built/permission.js +0 -99
  260. package/lib/built/permit-check.d.ts +0 -7
  261. package/lib/built/permit-check.js +0 -35
  262. package/lib/built/permit-parse.d.ts +0 -16
  263. package/lib/built/permit-parse.js +0 -32
  264. package/lib/built/platform-permit.d.ts +0 -20
  265. package/lib/built/platform-permit.js +0 -91
  266. package/lib/built/queue-im-field-contract.d.ts +0 -32
  267. package/lib/built/queue-im-field-contract.js +0 -67
  268. package/lib/built/rich-segments/adapter-policies.d.ts +0 -9
  269. package/lib/built/rich-segments/adapter-policies.js +0 -27
  270. package/lib/built/rich-segments/base.d.ts +0 -11
  271. package/lib/built/rich-segments/base.js +0 -24
  272. package/lib/built/rich-segments/builtins.d.ts +0 -4
  273. package/lib/built/rich-segments/builtins.js +0 -40
  274. package/lib/built/rich-segments/capabilities.d.ts +0 -6
  275. package/lib/built/rich-segments/capabilities.js +0 -38
  276. package/lib/built/rich-segments/html-segment.d.ts +0 -15
  277. package/lib/built/rich-segments/html-segment.js +0 -62
  278. package/lib/built/rich-segments/index.d.ts +0 -13
  279. package/lib/built/rich-segments/index.js +0 -13
  280. package/lib/built/rich-segments/markdown-segment.d.ts +0 -14
  281. package/lib/built/rich-segments/markdown-segment.js +0 -58
  282. package/lib/built/rich-segments/qrcode-segment.d.ts +0 -18
  283. package/lib/built/rich-segments/qrcode-segment.js +0 -73
  284. package/lib/built/rich-segments/registry.d.ts +0 -16
  285. package/lib/built/rich-segments/registry.js +0 -52
  286. package/lib/built/rich-segments/resolve.d.ts +0 -5
  287. package/lib/built/rich-segments/resolve.js +0 -87
  288. package/lib/built/rich-segments/tts-segment.d.ts +0 -13
  289. package/lib/built/rich-segments/tts-segment.js +0 -51
  290. package/lib/built/rich-segments/types.d.ts +0 -79
  291. package/lib/built/rich-segments/types.js +0 -17
  292. package/lib/built/runtime-io.d.ts +0 -9
  293. package/lib/built/runtime-io.js +0 -67
  294. package/lib/built/schedule.d.ts +0 -54
  295. package/lib/built/schedule.js +0 -112
  296. package/lib/built/schema-endpoint-manager.d.ts +0 -17
  297. package/lib/built/schema-endpoint-manager.js +0 -73
  298. package/lib/built/schema-feature.d.ts +0 -77
  299. package/lib/built/schema-feature.js +0 -130
  300. package/lib/built/skill.d.ts +0 -120
  301. package/lib/built/skill.js +0 -151
  302. package/lib/built/speech-loader.d.ts +0 -14
  303. package/lib/built/speech-loader.js +0 -32
  304. package/lib/built/tool.d.ts +0 -151
  305. package/lib/built/tool.js +0 -388
  306. package/lib/command.d.ts +0 -50
  307. package/lib/command.js +0 -106
  308. package/lib/component.d.ts +0 -26
  309. package/lib/component.js +0 -583
  310. package/lib/endpoint-capabilities.d.ts +0 -46
  311. package/lib/endpoint-capabilities.js +0 -55
  312. package/lib/endpoint.d.ts +0 -19
  313. package/lib/endpoint.js +0 -3
  314. package/lib/host-plugin-registry.d.ts +0 -8
  315. package/lib/host-plugin-registry.js +0 -12
  316. package/lib/plugin-context.d.ts +0 -27
  317. package/lib/plugin-context.js +0 -64
  318. package/lib/plugin-runtime/im/interactive.d.ts +0 -26
  319. package/lib/plugin-runtime/im/interactive.js +0 -46
  320. package/lib/plugin-runtime/im/login-assist-host.d.ts +0 -6
  321. package/lib/plugin-runtime/im/login-assist-host.js +0 -6
  322. package/lib/plugin-runtime/im/message-bus.d.ts +0 -38
  323. package/lib/plugin-runtime/im/message-bus.js +0 -40
  324. package/lib/plugin-runtime/im/service-tokens.d.ts +0 -18
  325. package/lib/plugin-runtime/im/service-tokens.js +0 -13
  326. package/lib/plugin.d.ts +0 -268
  327. package/lib/plugin.js +0 -583
  328. package/lib/schema-interaction.d.ts +0 -117
  329. package/lib/schema-interaction.js +0 -247
  330. package/lib/side-event/dispatch.d.ts +0 -15
  331. package/lib/side-event/dispatch.js +0 -140
  332. package/lib/tool-zod.d.ts +0 -43
  333. package/lib/tool-zod.js +0 -184
  334. /package/lib/{built/endpoint-manager.js → jsx/intrinsic-elements.js} +0 -0
@@ -1,6 +1,3 @@
1
- /**
2
- * 将 HTML 转为纯文本(无回溯密集正则,供 CodeQL / SSRF 工具链使用)。
3
- */
4
1
  export type HtmlToPlainTextOptions = {
5
2
  maxInputLength?: number;
6
3
  };
@@ -1,8 +1,9 @@
1
1
  /**
2
2
  * 将 HTML 转为纯文本(无回溯密集正则,供 CodeQL / SSRF 工具链使用)。
3
3
  */
4
+ import { readableLinkTarget, decodeReadableEntities as decodeCommonEntities } from './readable-link.js';
4
5
  const DEFAULT_MAX_INPUT = 2 * 1024 * 1024;
5
- const BLOCK_TAGS = ['script', 'style', 'svg', 'nav', 'footer', 'header', 'form'];
6
+ const BLOCK_TAGS = ['script', 'style', 'svg', 'nav', 'form'];
6
7
  function findTagClose(html, from) {
7
8
  const gt = html.indexOf('>', from);
8
9
  return gt === -1 ? -1 : gt + 1;
@@ -78,25 +79,6 @@ function stripRemainingTags(html) {
78
79
  }
79
80
  return out;
80
81
  }
81
- function decodeCommonEntities(text) {
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));
97
- return Number.isFinite(n) && n >= 0 && n <= 0x10ffff ? String.fromCodePoint(n) : '';
98
- });
99
- }
100
82
  /**
101
83
  * HTML → 纯文本:先剥离 script/style 等块,再去标签与实体。
102
84
  */
@@ -139,28 +121,137 @@ export function htmlToPlainTextWithBlockBreaks(html, options) {
139
121
  export function htmlToFallbackText(html, options) {
140
122
  const maxLen = options?.maxInputLength ?? DEFAULT_MAX_INPUT;
141
123
  let work = html.length > maxLen ? html.slice(0, maxLen) : html;
142
- work = work
143
- .replace(/<br\s*\/?>/gi, '\n')
144
- .replace(/<h1[^>]*>/gi, '\n# ')
145
- .replace(/<h2[^>]*>/gi, '\n## ')
146
- .replace(/<h3[^>]*>/gi, '\n### ')
147
- .replace(/<h4[^>]*>/gi, '\n#### ')
148
- .replace(/<h5[^>]*>/gi, '\n##### ')
149
- .replace(/<h6[^>]*>/gi, '\n###### ')
150
- .replace(/<li[^>]*>/gi, '\n- ')
151
- .replace(/<\/p>/gi, '\n\n')
152
- .replace(/<\/div>/gi, '\n')
153
- .replace(/<\/li>/gi, '\n')
154
- .replace(/<\/tr>/gi, '\n')
155
- .replace(/<\/h[1-6]>/gi, '\n\n');
156
124
  for (const tag of BLOCK_TAGS) {
157
125
  work = removeBalancedBlocks(work, tag);
158
126
  }
159
127
  work = removeHtmlComments(work);
160
- work = stripRemainingTags(work);
161
- work = decodeCommonEntities(work);
162
- return work
163
- .replace(/[ \t]+/g, ' ')
164
- .replace(/\n{3,}/g, '\n\n')
165
- .trim();
128
+ const out = [];
129
+ const lists = [];
130
+ let anchor;
131
+ let cells = 0;
132
+ let pre = false;
133
+ for (let i = 0; i < work.length;) {
134
+ if (work[i] !== '<') {
135
+ const next = work.indexOf('<', i);
136
+ const text = decodeCommonEntities(work.slice(i, next === -1 ? work.length : next));
137
+ out.push(pre ? text : text.replace(/\s+/gu, ' '));
138
+ i = next === -1 ? work.length : next;
139
+ continue;
140
+ }
141
+ // Respect quoted attributes, so href/title values may contain '>'.
142
+ let end = i + 1;
143
+ let quote = '';
144
+ for (; end < work.length; end++) {
145
+ const character = work[end];
146
+ if (quote) {
147
+ if (character === quote)
148
+ quote = '';
149
+ }
150
+ else if (character === '"' || character === "'")
151
+ quote = character;
152
+ else if (character === '>')
153
+ break;
154
+ }
155
+ if (end === work.length)
156
+ break;
157
+ const token = work.slice(i + 1, end);
158
+ const match = /^\s*(\/?)\s*([a-z][\w:-]*)/iu.exec(token);
159
+ i = end + 1;
160
+ if (!match)
161
+ continue;
162
+ const closing = match[1] === '/';
163
+ const tag = match[2].toLowerCase();
164
+ if (tag === 'a') {
165
+ if (closing) {
166
+ if (anchor) {
167
+ const label = out.slice(anchor.start).join('').trim();
168
+ if (label !== anchor.target)
169
+ out.push(label ? ` (${anchor.target})` : anchor.target);
170
+ }
171
+ anchor = undefined;
172
+ }
173
+ else {
174
+ const target = readableLinkTarget(decodeCommonEntities(readHtmlAttribute(token, 'href') ?? ''));
175
+ anchor = target ? { target, start: out.length } : undefined;
176
+ }
177
+ }
178
+ else if (tag === 'img' && !closing) {
179
+ const alt = decodeCommonEntities(readHtmlAttribute(token, 'alt') ?? '').trim();
180
+ out.push(alt ? `[图片:${alt}]` : '[图片]');
181
+ }
182
+ else if (tag === 'ul' || tag === 'ol') {
183
+ if (closing) {
184
+ lists.pop();
185
+ out.push('\n');
186
+ }
187
+ else {
188
+ const start = Number(readHtmlAttribute(token, 'start'));
189
+ lists.push({ ordered: tag === 'ol', next: Number.isSafeInteger(start) && start > 0 ? start : 1 });
190
+ }
191
+ }
192
+ else if (tag === 'li') {
193
+ if (closing)
194
+ out.push('\n');
195
+ else {
196
+ const list = lists.at(-1);
197
+ out.push(`\n${' '.repeat(Math.min(32, Math.max(0, lists.length - 1)))}${list?.ordered ? `${list.next++}.` : '-'} `);
198
+ }
199
+ }
200
+ else if (tag === 'tr') {
201
+ cells = 0;
202
+ out.push('\n');
203
+ }
204
+ else if ((tag === 'td' || tag === 'th') && !closing) {
205
+ if (cells++)
206
+ out.push(' | ');
207
+ }
208
+ else if (tag === 'pre') {
209
+ pre = !closing;
210
+ out.push('\n');
211
+ }
212
+ else if (tag === 'br' || tag === 'hr')
213
+ out.push('\n');
214
+ else if (/^h[1-6]$/u.test(tag))
215
+ out.push(closing ? '\n\n' : `\n${'#'.repeat(Number(tag[1]))} `);
216
+ else if (['p', 'div', 'section', 'article', 'table', 'blockquote', 'header', 'footer'].includes(tag)) {
217
+ if (closing)
218
+ out.push(tag === 'p' ? '\n\n' : '\n');
219
+ }
220
+ }
221
+ return out.join('').replace(/[ \t]+\n/gu, '\n').replace(/\n{3,}/gu, '\n\n').trim()
222
+ + (html.length > maxLen ? '\n\n[内容过长,已省略后续内容;请缩小查询范围或分页查看。]' : '');
223
+ }
224
+ /** Linear attribute scan, independent of attribute length and quote characters. */
225
+ function readHtmlAttribute(token, requested) {
226
+ let i = token.search(/\s/u);
227
+ if (i < 0)
228
+ return undefined;
229
+ while (i < token.length) {
230
+ while (i < token.length && /[\s/]/u.test(token[i]))
231
+ i++;
232
+ const start = i;
233
+ while (i < token.length && !/[\s=/>]/u.test(token[i]))
234
+ i++;
235
+ const name = token.slice(start, i).toLowerCase();
236
+ while (i < token.length && /\s/u.test(token[i]))
237
+ i++;
238
+ if (token[i] !== '=') {
239
+ if (i === start)
240
+ i++;
241
+ continue;
242
+ }
243
+ i++;
244
+ while (i < token.length && /\s/u.test(token[i]))
245
+ i++;
246
+ const quote = token[i] === '"' || token[i] === "'" ? token[i++] : undefined;
247
+ const valueStart = i;
248
+ while (i < token.length && (quote ? token[i] !== quote : !/[\s>]/u.test(token[i])))
249
+ i++;
250
+ const value = token.slice(valueStart, i);
251
+ if (quote)
252
+ i++;
253
+ if (name === requested)
254
+ return value;
255
+ }
256
+ return undefined;
166
257
  }
@@ -0,0 +1 @@
1
+ export declare const interactionMessages: (locale: import("@zhin.js/plugin-runtime").Locale | undefined, key: "number" | "fallback" | "minLength" | "maxLength" | "pattern" | "integer" | "min" | "max" | "confirmOrCancel" | "select" | "invalidSelection" | "minSelections" | "maxSelections" | "minItems" | "maxItems" | "invalidNumbers" | "invalidBooleans" | "confirm" | "cancel" | "confirmation" | "selection" | "multiple" | "list" | "ended" | "denied" | "expired" | "timeout", values?: import("@zhin.js/plugin-runtime").MessageValues) => string;
@@ -0,0 +1,30 @@
1
+ import { createMessages } from '@zhin.js/plugin-runtime';
2
+ export const interactionMessages = createMessages({
3
+ fallback: { 'zh-CN': '也可以直接回复对应内容。', en: 'You can also reply with the corresponding answer.' },
4
+ minLength: { 'zh-CN': '请至少输入 {count} 个字符', en: 'Enter at least {count} characters' },
5
+ maxLength: { 'zh-CN': '请不要超过 {count} 个字符', en: 'Enter no more than {count} characters' },
6
+ pattern: { 'zh-CN': '输入格式不正确', en: 'The input format is invalid' },
7
+ number: { 'zh-CN': '请输入有效数字', en: 'Enter a valid number' },
8
+ integer: { 'zh-CN': '请输入整数', en: 'Enter an integer' },
9
+ min: { 'zh-CN': '请输入不小于 {count} 的数字', en: 'Enter a number greater than or equal to {count}' },
10
+ max: { 'zh-CN': '请输入不大于 {count} 的数字', en: 'Enter a number less than or equal to {count}' },
11
+ confirmOrCancel: { 'zh-CN': '请选择确认或取消', en: 'Choose confirm or cancel' },
12
+ select: { 'zh-CN': '请选择一个有效选项', en: 'Choose a valid option' },
13
+ invalidSelection: { 'zh-CN': '多选中包含无效选项', en: 'The selection contains an invalid option' },
14
+ minSelections: { 'zh-CN': '请至少选择 {count} 项', en: 'Select at least {count} items' },
15
+ maxSelections: { 'zh-CN': '请最多选择 {count} 项', en: 'Select no more than {count} items' },
16
+ minItems: { 'zh-CN': '请至少输入 {count} 项', en: 'Enter at least {count} items' },
17
+ maxItems: { 'zh-CN': '请最多输入 {count} 项', en: 'Enter no more than {count} items' },
18
+ invalidNumbers: { 'zh-CN': '列表中包含无效数字', en: 'The list contains an invalid number' },
19
+ invalidBooleans: { 'zh-CN': '布尔列表只接受 true/false 或 是/否', en: 'Boolean lists accept only true/false or yes/no' },
20
+ confirm: { 'zh-CN': '确认', en: 'Confirm' },
21
+ cancel: { 'zh-CN': '取消', en: 'Cancel' },
22
+ confirmation: { 'zh-CN': '请选择确认或取消。', en: 'Choose confirm or cancel.' },
23
+ selection: { 'zh-CN': '可以点击按钮,或回复序号/选项名称。', en: 'Click a button, or reply with an option number or name.' },
24
+ multiple: { 'zh-CN': '回复序号或选项名称,多项用“{separator}”分隔。', en: 'Reply with option numbers or names, separated by "{separator}".' },
25
+ list: { 'zh-CN': '多项用“{separator}”分隔。', en: 'Separate items with "{separator}".' },
26
+ ended: { 'zh-CN': '交互已结束', en: 'Interaction ended' },
27
+ denied: { 'zh-CN': '你不能使用这个按钮:{reason}', en: 'You cannot use this button: {reason}' },
28
+ expired: { 'zh-CN': '交互已过期或不可用,请重新发起。', en: 'This interaction has expired or is unavailable. Start a new one.' },
29
+ timeout: { 'zh-CN': '输入超时', en: 'Input timed out' },
30
+ });
@@ -1,10 +1,10 @@
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 ActionSegmentData } from './types.js';
4
4
  export declare function actionSegment(data: ActionSegmentData): MessageElement;
5
- export declare function getActionFromMessage(message: Message<any>): ActionSegmentData | undefined;
5
+ export declare function getActionFromMessage(message: Message): ActionSegmentData | undefined;
6
6
  /** 入站互动 action(按钮点击等),不应计入用户发言/消息统计 */
7
- export declare function isActionMessage(message: Message<any>): boolean;
7
+ export declare function isActionMessage(message: Message): boolean;
8
8
  /** 去掉 @bot、XML at 段、首尾空白(QQ 指令预填文本归一化) */
9
9
  export declare function stripInteractiveCommandText(raw: string): string;
10
10
  /** 从文本降级输入解析 payload(需在 active session 的 fallback.map 中查找) */
@@ -14,4 +14,3 @@ export declare function resolveTextFallbackPayload(raw: string, map: Record<stri
14
14
  * 归一化 → 直接匹配 prefix:session:id → fallback 数字映射
15
15
  */
16
16
  export declare function resolvePayloadFromText(raw: string, map?: Record<string, string>): string | undefined;
17
- export declare function formatActionAsRaw(data: ActionSegmentData): string;
@@ -3,7 +3,7 @@ export function actionSegment(data) {
3
3
  return { type: ACTION_SEGMENT_TYPE, data };
4
4
  }
5
5
  export function getActionFromMessage(message) {
6
- for (const item of message.$content ?? []) {
6
+ for (const item of message.segments ?? []) {
7
7
  if (typeof item === 'string')
8
8
  continue;
9
9
  if (isActionSegment(item))
@@ -44,7 +44,7 @@ export function resolveTextFallbackPayload(raw, map) {
44
44
  const trimmed = raw.trim();
45
45
  if (map[trimmed])
46
46
  return map[trimmed];
47
- const match = trimmed.match(/^(?:ttt\s+)?(\d)$/i);
47
+ const match = trimmed.match(/^(?:ttt\s+)?(\d+)$/i);
48
48
  if (match && map[match[1]])
49
49
  return map[match[1]];
50
50
  return undefined;
@@ -64,6 +64,3 @@ export function resolvePayloadFromText(raw, map) {
64
64
  }
65
65
  return undefined;
66
66
  }
67
- export function formatActionAsRaw(data) {
68
- return data.payload;
69
- }
@@ -2,7 +2,5 @@ export * from './types.js';
2
2
  export * from './button-spec.js';
3
3
  export * from './action.js';
4
4
  export * from './resolve.js';
5
- export * from './handlers.js';
6
- export * from './fallback-store.js';
7
5
  export { KeyboardSegment } from './keyboard-segment.js';
8
6
  export * from './onebot-keyboard.js';
@@ -2,7 +2,5 @@ export * from './types.js';
2
2
  export * from './button-spec.js';
3
3
  export * from './action.js';
4
4
  export * from './resolve.js';
5
- export * from './handlers.js';
6
- export * from './fallback-store.js';
7
5
  export { KeyboardSegment } from './keyboard-segment.js';
8
6
  export * from './onebot-keyboard.js';
@@ -8,4 +8,3 @@ export declare class KeyboardSegment {
8
8
  data: KeyboardSegmentData;
9
9
  };
10
10
  }
11
- /** @deprecated 使用 {@link KeyboardSegment} */
@@ -9,4 +9,3 @@ export class KeyboardSegment {
9
9
  return { type: this.segmentType, data: this.data };
10
10
  }
11
11
  }
12
- /** @deprecated 使用 {@link KeyboardSegment} */
@@ -4,4 +4,3 @@ import { type KeyboardSegmentData } from './types.js';
4
4
  export declare function keyboardToOneBotSegment(data: KeyboardSegmentData): MessageSegment;
5
5
  /** 出站前将 core keyboard 段展开为 OneBot keyboard(保留前置 text 等段) */
6
6
  export declare function expandKeyboardSegmentsInContent(content: SendContent): SendContent;
7
- /** @deprecated 使用 {@link expandKeyboardSegmentsInContent} */
@@ -15,7 +15,6 @@ export function keyboardToOneBotSegment(data) {
15
15
  },
16
16
  };
17
17
  }
18
- /** @deprecated 使用 {@link keyboardToOneBotSegment} */
19
18
  function asKeyboardData(item) {
20
19
  if (item instanceof KeyboardSegment)
21
20
  return item.data;
@@ -48,4 +47,3 @@ export function expandKeyboardSegmentsInContent(content) {
48
47
  return out[0];
49
48
  return out;
50
49
  }
51
- /** @deprecated 使用 {@link expandKeyboardSegmentsInContent} */
@@ -2,14 +2,13 @@ import type { SendContent } from '../../types.js';
2
2
  import { type InteractivePolicy, type KeyboardSegmentData } from './types.js';
3
3
  /**
4
4
  * keyboard 的有效 fallback 映射:显式 `fallback.map` 优先;否则按按钮顺序
5
- * 自动编号(与 {@link renderKeyboardAsText} 的自动编号一致,含 disabled 按钮)。
5
+ * 自动编号(与 {@link renderKeyboardAsText} 一致);disabled 不产生可执行映射。
6
6
  */
7
7
  export declare function effectiveKeyboardFallbackMap(data: KeyboardSegmentData): Record<string, string>;
8
8
  /** 收集 content 中所有 keyboard 段的有效 fallback 映射(文本降级前调用)。 */
9
9
  export declare function collectKeyboardFallbackMaps(content: SendContent | undefined): Record<string, string>[];
10
10
  /** keyboard 段 → 编号文本('text' 策略端点的中央降级渲染)。 */
11
- export declare function renderKeyboardAsText(data: KeyboardSegmentData): string;
11
+ export declare function renderKeyboardAsText(data: KeyboardSegmentData, allocatedMap?: Readonly<Record<string, string>>): string;
12
12
  export declare function hasKeyboardSegment(content: SendContent | undefined): boolean;
13
- /** @deprecated 使用 {@link hasKeyboardSegment} */
14
13
  /** 按 Adapter interactivePolicy 将 keyboard 段转为 native 保留或文本降级 */
15
14
  export declare function resolveKeyboardSegments(content: SendContent, policy: InteractivePolicy): SendContent;
@@ -12,7 +12,7 @@ function toKeyboardElement(data) {
12
12
  return { type: KEYBOARD_SEGMENT_TYPE, data };
13
13
  }
14
14
  function asArray(content) {
15
- return Array.isArray(content) ? content : [content];
15
+ return Array.isArray(content) ? content.flatMap(item => asArray(item)) : [content];
16
16
  }
17
17
  function packSegments(out) {
18
18
  if (out.length === 0)
@@ -23,15 +23,20 @@ function packSegments(out) {
23
23
  }
24
24
  /**
25
25
  * keyboard 的有效 fallback 映射:显式 `fallback.map` 优先;否则按按钮顺序
26
- * 自动编号(与 {@link renderKeyboardAsText} 的自动编号一致,含 disabled 按钮)。
26
+ * 自动编号(与 {@link renderKeyboardAsText} 一致);disabled 不产生可执行映射。
27
27
  */
28
28
  export function effectiveKeyboardFallbackMap(data) {
29
+ const buttons = data.rows.flat();
30
+ const enabled = new Set(buttons.filter(button => !button.disabled).map(button => button.payload));
31
+ // Disabling one presentation does not disable another explicitly enabled button for the same action.
32
+ const disabledOnly = new Set(buttons.filter(button => button.disabled && !enabled.has(button.payload)).map(button => button.payload));
29
33
  const map = data.fallback?.map ?? {};
30
34
  if (Object.keys(map).length > 0)
31
- return { ...map };
35
+ return Object.fromEntries(Object.entries(map).filter(([, payload]) => !disabledOnly.has(payload)));
32
36
  const out = {};
33
- data.rows.flat().forEach((btn, idx) => {
34
- out[String(idx + 1)] = btn.payload;
37
+ buttons.forEach((btn, idx) => {
38
+ if (!btn.disabled)
39
+ out[String(idx + 1)] = btn.payload;
35
40
  });
36
41
  return out;
37
42
  }
@@ -50,24 +55,27 @@ export function collectKeyboardFallbackMaps(content) {
50
55
  return maps;
51
56
  }
52
57
  /** keyboard 段 → 编号文本('text' 策略端点的中央降级渲染)。 */
53
- export function renderKeyboardAsText(data) {
58
+ export function renderKeyboardAsText(data, allocatedMap) {
54
59
  const lines = [];
55
60
  const flat = data.rows.flat();
56
- if (data.fallback?.hint) {
61
+ const entries = Object.entries(allocatedMap ?? effectiveKeyboardFallbackMap(data)).sort(([a], [b]) => Number(a) - Number(b));
62
+ if (!entries.length) {
63
+ lines.push('当前无可用操作。');
64
+ }
65
+ else if (data.fallback?.hint) {
57
66
  lines.push(data.fallback.hint);
58
67
  }
59
68
  else {
60
69
  lines.push('请选择(回复数字):');
61
70
  }
62
- const map = data.fallback?.map ?? {};
63
- const entries = Object.keys(map).length > 0
64
- ? Object.entries(map).sort(([a], [b]) => Number(a) - Number(b))
65
- : flat.map((btn, idx) => [String(idx + 1), btn.payload]);
66
71
  for (const [key, payload] of entries) {
67
- const btn = flat.find((b) => b.payload === payload);
72
+ const btn = flat.find((b) => !b.disabled && b.payload === payload);
68
73
  const label = btn?.label ?? '·';
69
- lines.push(`${key}. ${label}${btn?.disabled ? ' (不可用)' : ''}`);
74
+ lines.push(`${key}. ${label}`);
70
75
  }
76
+ for (const button of flat)
77
+ if (button.disabled)
78
+ lines.push(`— ${button.label} (不可用)`);
71
79
  return lines.join('\n');
72
80
  }
73
81
  export function hasKeyboardSegment(content) {
@@ -79,7 +87,6 @@ export function hasKeyboardSegment(content) {
79
87
  return item instanceof KeyboardSegment || isKeyboardSegment(item);
80
88
  });
81
89
  }
82
- /** @deprecated 使用 {@link hasKeyboardSegment} */
83
90
  /** 按 Adapter interactivePolicy 将 keyboard 段转为 native 保留或文本降级 */
84
91
  export function resolveKeyboardSegments(content, policy) {
85
92
  if (!hasKeyboardSegment(content))
@@ -35,16 +35,11 @@ export type ActionSegmentData = {
35
35
  };
36
36
  export type InteractivePolicy = 'native' | 'text';
37
37
  export declare const DEFAULT_INTERACTIVE_POLICY: InteractivePolicy;
38
- export type InteractiveHandler = (message: import('../../message.js').Message<any>) => Promise<boolean> | boolean;
39
- export interface RegisteredInteractiveHandler {
40
- prefix: string;
41
- handler: InteractiveHandler;
42
- }
43
- export declare function isKeyboardSegment(item: MessageElement): item is MessageElement & {
38
+ export declare function isKeyboardSegment(item: unknown): item is MessageElement & {
44
39
  type: typeof KEYBOARD_SEGMENT_TYPE;
45
40
  data: KeyboardSegmentData;
46
41
  };
47
- export declare function isActionSegment(item: MessageElement): item is MessageElement & {
42
+ export declare function isActionSegment(item: unknown): item is MessageElement & {
48
43
  type: typeof ACTION_SEGMENT_TYPE;
49
44
  data: ActionSegmentData;
50
45
  };
@@ -2,8 +2,28 @@ export const KEYBOARD_SEGMENT_TYPE = 'keyboard';
2
2
  export const ACTION_SEGMENT_TYPE = 'action';
3
3
  export const DEFAULT_INTERACTIVE_POLICY = 'text';
4
4
  export function isKeyboardSegment(item) {
5
- return item != null && typeof item === 'object' && 'type' in item && item.type === KEYBOARD_SEGMENT_TYPE;
5
+ if (!isRecord(item) || item.type !== KEYBOARD_SEGMENT_TYPE || !isRecord(item.data))
6
+ return false;
7
+ const { rows, fallback } = item.data;
8
+ return Array.isArray(rows) && rows.every(row => Array.isArray(row) && row.every(isButtonData))
9
+ && (fallback === undefined || (isRecord(fallback) && typeof fallback.hint === 'string'
10
+ && isRecord(fallback.map) && Object.values(fallback.map).every(value => typeof value === 'string')));
6
11
  }
7
12
  export function isActionSegment(item) {
8
- return item != null && typeof item === 'object' && 'type' in item && item.type === ACTION_SEGMENT_TYPE;
13
+ return isRecord(item) && item.type === ACTION_SEGMENT_TYPE && isRecord(item.data)
14
+ && typeof item.data.id === 'string' && typeof item.data.payload === 'string'
15
+ && (item.data.sourceMessageId === undefined || typeof item.data.sourceMessageId === 'string');
16
+ }
17
+ function isRecord(value) {
18
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
19
+ }
20
+ function isButtonData(value) {
21
+ return isRecord(value) && typeof value.id === 'string' && typeof value.label === 'string'
22
+ && typeof value.payload === 'string'
23
+ && (value.disabled === undefined || typeof value.disabled === 'boolean')
24
+ && (value.style === undefined || value.style === 'primary' || value.style === 'danger' || value.style === 'secondary')
25
+ && (value.mode === undefined || value.mode === 'callback' || value.mode === 'command')
26
+ && (value.command === undefined || (isRecord(value.command)
27
+ && (value.command.enter === undefined || typeof value.command.enter === 'boolean')
28
+ && (value.command.reply === undefined || typeof value.command.reply === 'boolean')));
9
29
  }