@zhin.js/core 1.1.34 → 1.1.35

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 (386) hide show
  1. package/README.md +121 -65
  2. package/lib/adapter.d.ts +72 -23
  3. package/lib/adapter.js +222 -62
  4. package/lib/built/adapter-process.d.ts +20 -5
  5. package/lib/built/adapter-process.js +54 -7
  6. package/lib/built/agent-preset.d.ts +1 -2
  7. package/lib/built/agent-preset.js +1 -2
  8. package/lib/built/ai-access.d.ts +36 -0
  9. package/lib/built/ai-access.js +46 -0
  10. package/lib/built/ai-outbound/adapter-access.d.ts +3 -0
  11. package/lib/built/ai-outbound/adapter-access.js +9 -0
  12. package/lib/built/ai-outbound/extensions/onebot-keyboard.d.ts +2 -0
  13. package/lib/built/ai-outbound/extensions/onebot-keyboard.js +67 -0
  14. package/lib/built/ai-outbound/extensions/qq-message.d.ts +3 -0
  15. package/lib/built/ai-outbound/extensions/qq-message.js +23 -0
  16. package/lib/built/ai-outbound/index.d.ts +9 -0
  17. package/lib/built/ai-outbound/index.js +9 -0
  18. package/lib/built/ai-outbound/parse.d.ts +13 -0
  19. package/lib/built/ai-outbound/parse.js +104 -0
  20. package/lib/built/ai-outbound/plain-mention-rewrite.d.ts +6 -0
  21. package/lib/built/ai-outbound/plain-mention-rewrite.js +37 -0
  22. package/lib/built/ai-outbound/prompt.d.ts +11 -0
  23. package/lib/built/ai-outbound/prompt.js +44 -0
  24. package/lib/built/ai-outbound/resolve.d.ts +4 -0
  25. package/lib/built/ai-outbound/resolve.js +64 -0
  26. package/lib/built/ai-outbound/structured-detect.d.ts +3 -0
  27. package/lib/built/ai-outbound/structured-detect.js +6 -0
  28. package/lib/built/ai-outbound/types.d.ts +58 -0
  29. package/lib/built/ai-outbound/types.js +5 -0
  30. package/lib/built/ai-trigger.d.ts +17 -17
  31. package/lib/built/ai-trigger.js +65 -70
  32. package/lib/built/authorization.d.ts +10 -0
  33. package/lib/built/authorization.js +76 -0
  34. package/lib/built/command.d.ts +9 -5
  35. package/lib/built/command.js +20 -7
  36. package/lib/built/common-adapter-tools.d.ts +35 -29
  37. package/lib/built/common-adapter-tools.js +83 -67
  38. package/lib/built/component.d.ts +1 -3
  39. package/lib/built/component.js +2 -4
  40. package/lib/built/config.d.ts +4 -5
  41. package/lib/built/config.js +26 -9
  42. package/lib/built/connect-endpoint-instance.d.ts +17 -0
  43. package/lib/built/connect-endpoint-instance.js +42 -0
  44. package/lib/built/database.d.ts +5 -3
  45. package/lib/built/database.js +10 -4
  46. package/lib/built/dispatcher.d.ts +10 -8
  47. package/lib/built/dispatcher.js +31 -9
  48. package/lib/built/endpoint-commands.d.ts +3 -0
  49. package/lib/built/endpoint-commands.js +99 -0
  50. package/lib/built/endpoint-lifecycle-service.d.ts +28 -0
  51. package/lib/built/endpoint-lifecycle-service.js +242 -0
  52. package/lib/built/endpoint-lifecycle.d.ts +27 -0
  53. package/lib/built/endpoint-lifecycle.js +36 -0
  54. package/lib/built/endpoint-manager.d.ts +34 -0
  55. package/lib/built/endpoint-manager.js +1 -0
  56. package/lib/built/generated-qrcode.d.ts +24 -0
  57. package/lib/built/generated-qrcode.js +45 -0
  58. package/lib/built/generic-segment-mapper.d.ts +4 -0
  59. package/lib/built/generic-segment-mapper.js +190 -0
  60. package/lib/built/html-renderer-loader.d.ts +13 -0
  61. package/lib/built/html-renderer-loader.js +33 -0
  62. package/lib/built/html-segment-fallback.d.ts +2 -2
  63. package/lib/built/html-segment-fallback.js +0 -1
  64. package/lib/built/html-to-text.d.ts +0 -1
  65. package/lib/built/html-to-text.js +15 -15
  66. package/lib/built/inbound-pipeline.d.ts +37 -0
  67. package/lib/built/inbound-pipeline.js +63 -0
  68. package/lib/built/inbound-runner.d.ts +0 -1
  69. package/lib/built/inbound-runner.js +0 -3
  70. package/lib/built/interactive-segment-contract.d.ts +6 -0
  71. package/lib/built/interactive-segment-contract.js +9 -0
  72. package/lib/built/interactive-segments/action.d.ts +17 -0
  73. package/lib/built/interactive-segments/action.js +69 -0
  74. package/lib/built/interactive-segments/button-spec.d.ts +10 -0
  75. package/lib/built/interactive-segments/button-spec.js +21 -0
  76. package/lib/built/interactive-segments/fallback-store.d.ts +29 -0
  77. package/lib/built/interactive-segments/fallback-store.js +63 -0
  78. package/lib/built/interactive-segments/handlers.d.ts +16 -0
  79. package/lib/built/interactive-segments/handlers.js +74 -0
  80. package/lib/built/interactive-segments/index.d.ts +8 -0
  81. package/lib/built/interactive-segments/index.js +8 -0
  82. package/lib/built/interactive-segments/keyboard-segment.d.ts +11 -0
  83. package/lib/built/interactive-segments/keyboard-segment.js +12 -0
  84. package/lib/built/interactive-segments/onebot-keyboard.d.ts +7 -0
  85. package/lib/built/interactive-segments/onebot-keyboard.js +51 -0
  86. package/lib/built/interactive-segments/resolve.d.ts +15 -0
  87. package/lib/built/interactive-segments/resolve.js +110 -0
  88. package/lib/built/interactive-segments/types.d.ts +50 -0
  89. package/lib/built/interactive-segments/types.js +9 -0
  90. package/lib/built/introspection-format.d.ts +10 -0
  91. package/lib/built/introspection-format.js +28 -0
  92. package/lib/built/login-assist.d.ts +43 -9
  93. package/lib/built/login-assist.js +113 -11
  94. package/lib/built/management-command-guard.d.ts +15 -0
  95. package/lib/built/management-command-guard.js +25 -0
  96. package/lib/built/message-enrich.d.ts +38 -0
  97. package/lib/built/message-enrich.js +75 -0
  98. package/lib/built/message-filter.d.ts +4 -5
  99. package/lib/built/message-filter.js +5 -7
  100. package/lib/built/optional-peer-import.d.ts +3 -0
  101. package/lib/built/optional-peer-import.js +33 -0
  102. package/lib/built/outbound-media-contract.d.ts +22 -0
  103. package/lib/built/outbound-media-contract.js +10 -0
  104. package/lib/built/outbound-media-utils.d.ts +9 -0
  105. package/lib/built/outbound-media-utils.js +62 -0
  106. package/lib/built/permission.d.ts +3 -7
  107. package/lib/built/permission.js +39 -52
  108. package/lib/built/permit-check.d.ts +7 -0
  109. package/lib/built/permit-check.js +35 -0
  110. package/lib/built/permit-parse.d.ts +16 -0
  111. package/lib/built/permit-parse.js +32 -0
  112. package/lib/built/platform-permit.d.ts +20 -0
  113. package/lib/built/platform-permit.js +91 -0
  114. package/lib/built/queue-im-field-contract.d.ts +7 -2
  115. package/lib/built/queue-im-field-contract.js +13 -4
  116. package/lib/built/rich-segments/adapter-policies.d.ts +9 -0
  117. package/lib/built/rich-segments/adapter-policies.js +27 -0
  118. package/lib/built/rich-segments/base.d.ts +11 -0
  119. package/lib/built/rich-segments/base.js +24 -0
  120. package/lib/built/rich-segments/builtins.d.ts +4 -0
  121. package/lib/built/rich-segments/builtins.js +40 -0
  122. package/lib/built/rich-segments/capabilities.d.ts +6 -0
  123. package/lib/built/rich-segments/capabilities.js +38 -0
  124. package/lib/built/rich-segments/html-segment.d.ts +15 -0
  125. package/lib/built/rich-segments/html-segment.js +62 -0
  126. package/lib/built/rich-segments/index.d.ts +13 -0
  127. package/lib/built/rich-segments/index.js +13 -0
  128. package/lib/built/rich-segments/markdown-segment.d.ts +14 -0
  129. package/lib/built/rich-segments/markdown-segment.js +58 -0
  130. package/lib/built/rich-segments/markdown-to-text.d.ts +3 -0
  131. package/lib/built/rich-segments/markdown-to-text.js +27 -0
  132. package/lib/built/rich-segments/qrcode-segment.d.ts +18 -0
  133. package/lib/built/rich-segments/qrcode-segment.js +73 -0
  134. package/lib/built/rich-segments/registry.d.ts +16 -0
  135. package/lib/built/rich-segments/registry.js +52 -0
  136. package/lib/built/rich-segments/resolve.d.ts +5 -0
  137. package/lib/built/rich-segments/resolve.js +87 -0
  138. package/lib/built/rich-segments/tts-segment.d.ts +13 -0
  139. package/lib/built/rich-segments/tts-segment.js +51 -0
  140. package/lib/built/rich-segments/types.d.ts +79 -0
  141. package/lib/built/rich-segments/types.js +17 -0
  142. package/lib/built/roles.d.ts +4 -5
  143. package/lib/built/roles.js +4 -5
  144. package/lib/built/runtime-io.d.ts +0 -1
  145. package/lib/built/runtime-io.js +0 -1
  146. package/lib/built/schedule.d.ts +54 -0
  147. package/lib/built/schedule.js +112 -0
  148. package/lib/built/schema-endpoint-manager.d.ts +17 -0
  149. package/lib/built/schema-endpoint-manager.js +73 -0
  150. package/lib/built/schema-feature.d.ts +0 -1
  151. package/lib/built/schema-feature.js +1 -3
  152. package/lib/built/segment-contract/assert.d.ts +7 -0
  153. package/lib/built/segment-contract/assert.js +39 -0
  154. package/lib/built/segment-contract/delivery.d.ts +5 -0
  155. package/lib/built/segment-contract/delivery.js +40 -0
  156. package/lib/built/segment-contract/image.d.ts +5 -0
  157. package/lib/built/segment-contract/image.js +10 -0
  158. package/lib/built/segment-contract/index.d.ts +10 -0
  159. package/lib/built/segment-contract/index.js +9 -0
  160. package/lib/built/segment-contract/json-schema.d.ts +28 -0
  161. package/lib/built/segment-contract/json-schema.js +128 -0
  162. package/lib/built/segment-contract/media.d.ts +12 -0
  163. package/lib/built/segment-contract/media.js +22 -0
  164. package/lib/built/segment-contract/mention.d.ts +10 -0
  165. package/lib/built/segment-contract/mention.js +26 -0
  166. package/lib/built/segment-contract/preview.d.ts +3 -0
  167. package/lib/built/segment-contract/preview.js +159 -0
  168. package/lib/built/segment-contract/text.d.ts +7 -0
  169. package/lib/built/segment-contract/text.js +34 -0
  170. package/lib/built/segment-contract/types.d.ts +58 -0
  171. package/lib/built/segment-contract/types.js +1 -0
  172. package/lib/built/segment-contract/validate.d.ts +229 -0
  173. package/lib/built/segment-contract/validate.js +174 -0
  174. package/lib/built/skill.d.ts +0 -1
  175. package/lib/built/skill.js +0 -1
  176. package/lib/built/speech-loader.d.ts +14 -0
  177. package/lib/built/speech-loader.js +32 -0
  178. package/lib/built/tool.d.ts +14 -13
  179. package/lib/built/tool.js +30 -25
  180. package/lib/built/user-interaction.d.ts +30 -0
  181. package/lib/built/user-interaction.js +248 -0
  182. package/lib/command.d.ts +19 -11
  183. package/lib/command.js +42 -11
  184. package/lib/component.d.ts +0 -1
  185. package/lib/component.js +30 -14
  186. package/lib/endpoint-capabilities.d.ts +46 -0
  187. package/lib/endpoint-capabilities.js +55 -0
  188. package/lib/endpoint.d.ts +19 -0
  189. package/lib/endpoint.js +3 -0
  190. package/lib/errors.d.ts +2 -3
  191. package/lib/errors.js +4 -5
  192. package/lib/feature/adapter.d.ts +2 -0
  193. package/lib/feature/adapter.js +2 -0
  194. package/lib/feature/command.d.ts +2 -0
  195. package/lib/feature/command.js +2 -0
  196. package/lib/feature/component.d.ts +2 -0
  197. package/lib/feature/component.js +2 -0
  198. package/lib/feature/handler.d.ts +52 -0
  199. package/lib/feature/handler.js +26 -0
  200. package/lib/feature/middleware.d.ts +2 -0
  201. package/lib/feature/middleware.js +2 -0
  202. package/lib/host-plugin-registry.d.ts +8 -0
  203. package/lib/host-plugin-registry.js +12 -0
  204. package/lib/im-scene.d.ts +29 -0
  205. package/lib/im-scene.js +75 -0
  206. package/lib/im-session-id.d.ts +39 -0
  207. package/lib/im-session-id.js +47 -0
  208. package/lib/index.d.ts +59 -25
  209. package/lib/index.js +53 -31
  210. package/lib/jsx-dev-runtime.d.ts +0 -1
  211. package/lib/jsx-dev-runtime.js +0 -1
  212. package/lib/jsx-runtime.d.ts +1 -1
  213. package/lib/jsx-runtime.js +0 -1
  214. package/lib/jsx.d.ts +19 -22
  215. package/lib/jsx.js +0 -1
  216. package/lib/message.d.ts +16 -10
  217. package/lib/message.js +16 -13
  218. package/lib/models/system-log.d.ts +0 -1
  219. package/lib/models/system-log.js +0 -1
  220. package/lib/models/user.d.ts +0 -1
  221. package/lib/models/user.js +0 -1
  222. package/lib/notice.d.ts +16 -59
  223. package/lib/notice.js +1 -4
  224. package/lib/plugin-context.d.ts +27 -0
  225. package/lib/plugin-context.js +64 -0
  226. package/lib/plugin-runtime/im/contracts.d.ts +191 -0
  227. package/lib/plugin-runtime/im/contracts.js +169 -0
  228. package/lib/plugin-runtime/im/im-runtime.d.ts +177 -0
  229. package/lib/plugin-runtime/im/im-runtime.js +1204 -0
  230. package/lib/plugin-runtime/im/index.d.ts +9 -0
  231. package/lib/plugin-runtime/im/index.js +9 -0
  232. package/lib/plugin-runtime/im/interactive.d.ts +26 -0
  233. package/lib/plugin-runtime/im/interactive.js +46 -0
  234. package/lib/plugin-runtime/im/login-assist-host.d.ts +6 -0
  235. package/lib/plugin-runtime/im/login-assist-host.js +6 -0
  236. package/lib/plugin-runtime/im/message-bus.d.ts +38 -0
  237. package/lib/plugin-runtime/im/message-bus.js +40 -0
  238. package/lib/plugin-runtime/im/message-dispatcher.d.ts +18 -0
  239. package/lib/plugin-runtime/im/message-dispatcher.js +107 -0
  240. package/lib/plugin-runtime/im/outbound-renderer.d.ts +7 -0
  241. package/lib/plugin-runtime/im/outbound-renderer.js +70 -0
  242. package/lib/plugin-runtime/im/outbound-segments.d.ts +72 -0
  243. package/lib/plugin-runtime/im/outbound-segments.js +220 -0
  244. package/lib/plugin-runtime/im/public-api.d.ts +6 -0
  245. package/lib/plugin-runtime/im/public-api.js +6 -0
  246. package/lib/plugin-runtime/im/service-tokens.d.ts +18 -0
  247. package/lib/plugin-runtime/im/service-tokens.js +13 -0
  248. package/lib/plugin.d.ts +34 -24
  249. package/lib/plugin.js +119 -224
  250. package/lib/request.d.ts +17 -61
  251. package/lib/request.js +0 -4
  252. package/lib/{prompt.d.ts → schema-interaction.d.ts} +6 -7
  253. package/lib/{prompt.js → schema-interaction.js} +20 -17
  254. package/lib/side-event/base.d.ts +52 -0
  255. package/lib/side-event/base.js +30 -0
  256. package/lib/side-event/dispatch.d.ts +15 -0
  257. package/lib/side-event/dispatch.js +140 -0
  258. package/lib/side-event/index.d.ts +4 -0
  259. package/lib/side-event/index.js +4 -0
  260. package/lib/side-event/normalize.d.ts +42 -0
  261. package/lib/side-event/normalize.js +121 -0
  262. package/lib/side-event/types.d.ts +23 -0
  263. package/lib/side-event/types.js +55 -0
  264. package/lib/system-event.d.ts +15 -0
  265. package/lib/system-event.js +7 -0
  266. package/lib/tool-zod.d.ts +18 -3
  267. package/lib/tool-zod.js +140 -54
  268. package/lib/types.d.ts +44 -95
  269. package/lib/types.js +0 -1
  270. package/lib/utils.d.ts +61 -13
  271. package/lib/utils.js +66 -25
  272. package/package.json +98 -10
  273. package/lib/adapter.d.ts.map +0 -1
  274. package/lib/adapter.js.map +0 -1
  275. package/lib/agent-prompt.d.ts +0 -37
  276. package/lib/agent-prompt.d.ts.map +0 -1
  277. package/lib/agent-prompt.js +0 -2
  278. package/lib/agent-prompt.js.map +0 -1
  279. package/lib/bot.d.ts +0 -38
  280. package/lib/bot.d.ts.map +0 -1
  281. package/lib/bot.js +0 -2
  282. package/lib/bot.js.map +0 -1
  283. package/lib/built/adapter-process.d.ts.map +0 -1
  284. package/lib/built/adapter-process.js.map +0 -1
  285. package/lib/built/agent-preset.d.ts.map +0 -1
  286. package/lib/built/agent-preset.js.map +0 -1
  287. package/lib/built/ai-trigger.d.ts.map +0 -1
  288. package/lib/built/ai-trigger.js.map +0 -1
  289. package/lib/built/command.d.ts.map +0 -1
  290. package/lib/built/command.js.map +0 -1
  291. package/lib/built/common-adapter-tools.d.ts.map +0 -1
  292. package/lib/built/common-adapter-tools.js.map +0 -1
  293. package/lib/built/component.d.ts.map +0 -1
  294. package/lib/built/component.js.map +0 -1
  295. package/lib/built/config.d.ts.map +0 -1
  296. package/lib/built/config.js.map +0 -1
  297. package/lib/built/cron.d.ts +0 -75
  298. package/lib/built/cron.d.ts.map +0 -1
  299. package/lib/built/cron.js +0 -122
  300. package/lib/built/cron.js.map +0 -1
  301. package/lib/built/database.d.ts.map +0 -1
  302. package/lib/built/database.js.map +0 -1
  303. package/lib/built/dispatcher.d.ts.map +0 -1
  304. package/lib/built/dispatcher.js.map +0 -1
  305. package/lib/built/html-segment-fallback.d.ts.map +0 -1
  306. package/lib/built/html-segment-fallback.js.map +0 -1
  307. package/lib/built/html-to-text.d.ts.map +0 -1
  308. package/lib/built/html-to-text.js.map +0 -1
  309. package/lib/built/inbound-runner.d.ts.map +0 -1
  310. package/lib/built/inbound-runner.js.map +0 -1
  311. package/lib/built/login-assist.d.ts.map +0 -1
  312. package/lib/built/login-assist.js.map +0 -1
  313. package/lib/built/mcp-mesh-registrar.d.ts +0 -9
  314. package/lib/built/mcp-mesh-registrar.d.ts.map +0 -1
  315. package/lib/built/mcp-mesh-registrar.js +0 -17
  316. package/lib/built/mcp-mesh-registrar.js.map +0 -1
  317. package/lib/built/message-filter.d.ts.map +0 -1
  318. package/lib/built/message-filter.js.map +0 -1
  319. package/lib/built/permission.d.ts.map +0 -1
  320. package/lib/built/permission.js.map +0 -1
  321. package/lib/built/prepend-quote-context.d.ts +0 -35
  322. package/lib/built/prepend-quote-context.d.ts.map +0 -1
  323. package/lib/built/prepend-quote-context.js +0 -131
  324. package/lib/built/prepend-quote-context.js.map +0 -1
  325. package/lib/built/queue-im-field-contract.d.ts.map +0 -1
  326. package/lib/built/queue-im-field-contract.js.map +0 -1
  327. package/lib/built/roles.d.ts.map +0 -1
  328. package/lib/built/roles.js.map +0 -1
  329. package/lib/built/runtime-io.d.ts.map +0 -1
  330. package/lib/built/runtime-io.js.map +0 -1
  331. package/lib/built/schema-feature.d.ts.map +0 -1
  332. package/lib/built/schema-feature.js.map +0 -1
  333. package/lib/built/skill.d.ts.map +0 -1
  334. package/lib/built/skill.js.map +0 -1
  335. package/lib/built/tool.d.ts.map +0 -1
  336. package/lib/built/tool.js.map +0 -1
  337. package/lib/command.d.ts.map +0 -1
  338. package/lib/command.js.map +0 -1
  339. package/lib/component.d.ts.map +0 -1
  340. package/lib/component.js.map +0 -1
  341. package/lib/errors.d.ts.map +0 -1
  342. package/lib/errors.js.map +0 -1
  343. package/lib/index.d.ts.map +0 -1
  344. package/lib/index.js.map +0 -1
  345. package/lib/jsx-dev-runtime.d.ts.map +0 -1
  346. package/lib/jsx-dev-runtime.js.map +0 -1
  347. package/lib/jsx-runtime.d.ts.map +0 -1
  348. package/lib/jsx-runtime.js.map +0 -1
  349. package/lib/jsx.d.ts.map +0 -1
  350. package/lib/jsx.js.map +0 -1
  351. package/lib/message-quote.d.ts +0 -11
  352. package/lib/message-quote.d.ts.map +0 -1
  353. package/lib/message-quote.js +0 -91
  354. package/lib/message-quote.js.map +0 -1
  355. package/lib/message.d.ts.map +0 -1
  356. package/lib/message.js.map +0 -1
  357. package/lib/models/system-log.d.ts.map +0 -1
  358. package/lib/models/system-log.js.map +0 -1
  359. package/lib/models/user.d.ts.map +0 -1
  360. package/lib/models/user.js.map +0 -1
  361. package/lib/notice.d.ts.map +0 -1
  362. package/lib/notice.js.map +0 -1
  363. package/lib/plugin.d.ts.map +0 -1
  364. package/lib/plugin.js.map +0 -1
  365. package/lib/prompt.d.ts.map +0 -1
  366. package/lib/prompt.js.map +0 -1
  367. package/lib/request.d.ts.map +0 -1
  368. package/lib/request.js.map +0 -1
  369. package/lib/scheduler/scheduler.d.ts +0 -49
  370. package/lib/scheduler/scheduler.d.ts.map +0 -1
  371. package/lib/scheduler/scheduler.js +0 -352
  372. package/lib/scheduler/scheduler.js.map +0 -1
  373. package/lib/scheduler/types.d.ts +0 -71
  374. package/lib/scheduler/types.d.ts.map +0 -1
  375. package/lib/scheduler/types.js +0 -8
  376. package/lib/scheduler/types.js.map +0 -1
  377. package/lib/tool-zod.d.ts.map +0 -1
  378. package/lib/tool-zod.js.map +0 -1
  379. package/lib/types-generator.d.ts +0 -6
  380. package/lib/types-generator.d.ts.map +0 -1
  381. package/lib/types-generator.js +0 -72
  382. package/lib/types-generator.js.map +0 -1
  383. package/lib/types.d.ts.map +0 -1
  384. package/lib/types.js.map +0 -1
  385. package/lib/utils.d.ts.map +0 -1
  386. package/lib/utils.js.map +0 -1
@@ -0,0 +1,16 @@
1
+ import type { Message } from '../../message.js';
2
+ import type { MessageMiddleware } from '../../types.js';
3
+ import type { InteractiveHandler, RegisteredInteractiveHandler } from './types.js';
4
+ /** 旧轨频道键:与出站降级(Adapter.renderSendMessage)及 game-kit channelKey 一致。 */
5
+ export declare function interactiveChannelKey(message: Message<any>): string;
6
+ /**
7
+ * 文本回跳解析:中央 fallback map(裸数字)→ payload;
8
+ * 或 QQ 指令预填等直出 `prefix:session:id` payload。
9
+ */
10
+ export declare function resolveInboundTextPayload(message: Message<any>): string | undefined;
11
+ export declare function registerInteractiveHandler(prefix: string, handler: InteractiveHandler): () => void;
12
+ export declare function getInteractiveHandlers(): readonly RegisteredInteractiveHandler[];
13
+ export declare function resetInteractiveHandlersForTests(): void;
14
+ /** 在根插件上安装一次性 action 路由中间件(幂等) */
15
+ export declare function ensureInteractiveMiddleware(addMiddleware: (mw: MessageMiddleware) => () => void): void;
16
+ export declare function dispatchInteractiveAction(message: Message<any>): Promise<boolean>;
@@ -0,0 +1,74 @@
1
+ import { getActionFromMessage, resolvePayloadFromText } from './action.js';
2
+ import { keyboardFallbackStore } from './fallback-store.js';
3
+ const handlers = [];
4
+ let middlewareInstalled = false;
5
+ function findHandler(payload) {
6
+ let match;
7
+ for (const entry of handlers) {
8
+ if (payload.startsWith(entry.prefix)) {
9
+ if (!match || entry.prefix.length > match.prefix.length) {
10
+ match = entry;
11
+ }
12
+ }
13
+ }
14
+ return match?.handler;
15
+ }
16
+ /** 旧轨频道键:与出站降级(Adapter.renderSendMessage)及 game-kit channelKey 一致。 */
17
+ export function interactiveChannelKey(message) {
18
+ return `${String(message.$adapter)}-${message.$endpoint}-${message.$channel.type}:${message.$channel.id}`;
19
+ }
20
+ /**
21
+ * 文本回跳解析:中央 fallback map(裸数字)→ payload;
22
+ * 或 QQ 指令预填等直出 `prefix:session:id` payload。
23
+ */
24
+ export function resolveInboundTextPayload(message) {
25
+ const raw = message.$raw?.trim() ?? '';
26
+ if (!raw)
27
+ return undefined;
28
+ return resolvePayloadFromText(raw, keyboardFallbackStore.mapFor(interactiveChannelKey(message)));
29
+ }
30
+ export function registerInteractiveHandler(prefix, handler) {
31
+ const entry = { prefix, handler };
32
+ handlers.push(entry);
33
+ const dispose = () => {
34
+ const idx = handlers.indexOf(entry);
35
+ if (idx >= 0)
36
+ handlers.splice(idx, 1);
37
+ };
38
+ return dispose;
39
+ }
40
+ export function getInteractiveHandlers() {
41
+ return handlers;
42
+ }
43
+ export function resetInteractiveHandlersForTests() {
44
+ handlers.length = 0;
45
+ middlewareInstalled = false;
46
+ }
47
+ /** 在根插件上安装一次性 action 路由中间件(幂等) */
48
+ export function ensureInteractiveMiddleware(addMiddleware) {
49
+ if (middlewareInstalled)
50
+ return;
51
+ middlewareInstalled = true;
52
+ addMiddleware(async (message, next) => {
53
+ const payload = getActionFromMessage(message)?.payload
54
+ ?? resolveInboundTextPayload(message);
55
+ if (!payload)
56
+ return next();
57
+ const handler = findHandler(payload);
58
+ if (!handler)
59
+ return next();
60
+ const handled = await handler(message);
61
+ if (handled)
62
+ return;
63
+ return next();
64
+ });
65
+ }
66
+ export async function dispatchInteractiveAction(message) {
67
+ const action = getActionFromMessage(message);
68
+ if (!action)
69
+ return false;
70
+ const handler = findHandler(action.payload);
71
+ if (!handler)
72
+ return false;
73
+ return !!(await handler(message));
74
+ }
@@ -0,0 +1,8 @@
1
+ export * from './types.js';
2
+ export * from './button-spec.js';
3
+ export * from './action.js';
4
+ export * from './resolve.js';
5
+ export * from './handlers.js';
6
+ export * from './fallback-store.js';
7
+ export { KeyboardSegment } from './keyboard-segment.js';
8
+ export * from './onebot-keyboard.js';
@@ -0,0 +1,8 @@
1
+ export * from './types.js';
2
+ export * from './button-spec.js';
3
+ export * from './action.js';
4
+ export * from './resolve.js';
5
+ export * from './handlers.js';
6
+ export * from './fallback-store.js';
7
+ export { KeyboardSegment } from './keyboard-segment.js';
8
+ export * from './onebot-keyboard.js';
@@ -0,0 +1,11 @@
1
+ import { type KeyboardSegmentData } from './types.js';
2
+ export declare class KeyboardSegment {
3
+ readonly data: KeyboardSegmentData;
4
+ readonly segmentType: "keyboard";
5
+ constructor(data: KeyboardSegmentData);
6
+ toElement(): {
7
+ type: "keyboard";
8
+ data: KeyboardSegmentData;
9
+ };
10
+ }
11
+ /** @deprecated 使用 {@link KeyboardSegment} */
@@ -0,0 +1,12 @@
1
+ import { KEYBOARD_SEGMENT_TYPE } from './types.js';
2
+ export class KeyboardSegment {
3
+ data;
4
+ segmentType = KEYBOARD_SEGMENT_TYPE;
5
+ constructor(data) {
6
+ this.data = data;
7
+ }
8
+ toElement() {
9
+ return { type: this.segmentType, data: this.data };
10
+ }
11
+ }
12
+ /** @deprecated 使用 {@link KeyboardSegment} */
@@ -0,0 +1,7 @@
1
+ import type { MessageSegment, SendContent } from '../../types.js';
2
+ import { type KeyboardSegmentData } from './types.js';
3
+ /** OneBot / QQ 系 keyboard 段(各 adapter 在 $sendMessage 中识别) */
4
+ export declare function keyboardToOneBotSegment(data: KeyboardSegmentData): MessageSegment;
5
+ /** 出站前将 core keyboard 段展开为 OneBot keyboard(保留前置 text 等段) */
6
+ export declare function expandKeyboardSegmentsInContent(content: SendContent): SendContent;
7
+ /** @deprecated 使用 {@link expandKeyboardSegmentsInContent} */
@@ -0,0 +1,51 @@
1
+ import { isKeyboardSegment } from './types.js';
2
+ import { KeyboardSegment } from './keyboard-segment.js';
3
+ /** OneBot / QQ 系 keyboard 段(各 adapter 在 $sendMessage 中识别) */
4
+ export function keyboardToOneBotSegment(data) {
5
+ return {
6
+ type: 'keyboard',
7
+ data: {
8
+ rows: data.rows.map((row) => row.map((btn) => ({
9
+ label: btn.label,
10
+ data: btn.payload,
11
+ enter: false,
12
+ action_type: 'callback',
13
+ disable: !!btn.disabled,
14
+ }))),
15
+ },
16
+ };
17
+ }
18
+ /** @deprecated 使用 {@link keyboardToOneBotSegment} */
19
+ function asKeyboardData(item) {
20
+ if (item instanceof KeyboardSegment)
21
+ return item.data;
22
+ if (isKeyboardSegment(item))
23
+ return item.data;
24
+ return null;
25
+ }
26
+ /** 出站前将 core keyboard 段展开为 OneBot keyboard(保留前置 text 等段) */
27
+ export function expandKeyboardSegmentsInContent(content) {
28
+ const items = Array.isArray(content) ? content : [content];
29
+ const out = [];
30
+ for (const item of items) {
31
+ if (typeof item === 'string') {
32
+ out.push(item);
33
+ continue;
34
+ }
35
+ if (typeof item.type !== 'string') {
36
+ continue;
37
+ }
38
+ const data = asKeyboardData(item);
39
+ if (data) {
40
+ out.push(keyboardToOneBotSegment(data));
41
+ continue;
42
+ }
43
+ out.push(item);
44
+ }
45
+ if (out.length === 0)
46
+ return { type: 'text', data: { text: '' } };
47
+ if (out.length === 1)
48
+ return out[0];
49
+ return out;
50
+ }
51
+ /** @deprecated 使用 {@link expandKeyboardSegmentsInContent} */
@@ -0,0 +1,15 @@
1
+ import type { SendContent } from '../../types.js';
2
+ import { type InteractivePolicy, type KeyboardSegmentData } from './types.js';
3
+ /**
4
+ * keyboard 的有效 fallback 映射:显式 `fallback.map` 优先;否则按按钮顺序
5
+ * 自动编号(与 {@link renderKeyboardAsText} 的自动编号一致,含 disabled 按钮)。
6
+ */
7
+ export declare function effectiveKeyboardFallbackMap(data: KeyboardSegmentData): Record<string, string>;
8
+ /** 收集 content 中所有 keyboard 段的有效 fallback 映射(文本降级前调用)。 */
9
+ export declare function collectKeyboardFallbackMaps(content: SendContent | undefined): Record<string, string>[];
10
+ /** keyboard 段 → 编号文本('text' 策略端点的中央降级渲染)。 */
11
+ export declare function renderKeyboardAsText(data: KeyboardSegmentData): string;
12
+ export declare function hasKeyboardSegment(content: SendContent | undefined): boolean;
13
+ /** @deprecated 使用 {@link hasKeyboardSegment} */
14
+ /** 按 Adapter interactivePolicy 将 keyboard 段转为 native 保留或文本降级 */
15
+ export declare function resolveKeyboardSegments(content: SendContent, policy: InteractivePolicy): SendContent;
@@ -0,0 +1,110 @@
1
+ import { segment } from '../../utils.js';
2
+ import { KeyboardSegment } from './keyboard-segment.js';
3
+ import { KEYBOARD_SEGMENT_TYPE, isKeyboardSegment, } from './types.js';
4
+ function asKeyboardData(item) {
5
+ if (item instanceof KeyboardSegment)
6
+ return item.data;
7
+ if (isKeyboardSegment(item))
8
+ return item.data;
9
+ return null;
10
+ }
11
+ function toKeyboardElement(data) {
12
+ return { type: KEYBOARD_SEGMENT_TYPE, data };
13
+ }
14
+ function asArray(content) {
15
+ return Array.isArray(content) ? content : [content];
16
+ }
17
+ function packSegments(out) {
18
+ if (out.length === 0)
19
+ return { type: 'text', data: { text: '' } };
20
+ if (out.length === 1)
21
+ return out[0];
22
+ return out;
23
+ }
24
+ /**
25
+ * keyboard 的有效 fallback 映射:显式 `fallback.map` 优先;否则按按钮顺序
26
+ * 自动编号(与 {@link renderKeyboardAsText} 的自动编号一致,含 disabled 按钮)。
27
+ */
28
+ export function effectiveKeyboardFallbackMap(data) {
29
+ const map = data.fallback?.map ?? {};
30
+ if (Object.keys(map).length > 0)
31
+ return { ...map };
32
+ const out = {};
33
+ data.rows.flat().forEach((btn, idx) => {
34
+ out[String(idx + 1)] = btn.payload;
35
+ });
36
+ return out;
37
+ }
38
+ /** 收集 content 中所有 keyboard 段的有效 fallback 映射(文本降级前调用)。 */
39
+ export function collectKeyboardFallbackMaps(content) {
40
+ if (content == null)
41
+ return [];
42
+ const maps = [];
43
+ for (const item of asArray(content)) {
44
+ if (typeof item === 'string')
45
+ continue;
46
+ const data = asKeyboardData(item);
47
+ if (data)
48
+ maps.push(effectiveKeyboardFallbackMap(data));
49
+ }
50
+ return maps;
51
+ }
52
+ /** keyboard 段 → 编号文本('text' 策略端点的中央降级渲染)。 */
53
+ export function renderKeyboardAsText(data) {
54
+ const lines = [];
55
+ const flat = data.rows.flat();
56
+ if (data.fallback?.hint) {
57
+ lines.push(data.fallback.hint);
58
+ }
59
+ else {
60
+ lines.push('请选择(回复数字):');
61
+ }
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
+ for (const [key, payload] of entries) {
67
+ const btn = flat.find((b) => b.payload === payload);
68
+ const label = btn?.label ?? '·';
69
+ lines.push(`${key}. ${label}${btn?.disabled ? ' (不可用)' : ''}`);
70
+ }
71
+ return lines.join('\n');
72
+ }
73
+ export function hasKeyboardSegment(content) {
74
+ if (content == null)
75
+ return false;
76
+ return asArray(content).some((item) => {
77
+ if (typeof item === 'string')
78
+ return false;
79
+ return item instanceof KeyboardSegment || isKeyboardSegment(item);
80
+ });
81
+ }
82
+ /** @deprecated 使用 {@link hasKeyboardSegment} */
83
+ /** 按 Adapter interactivePolicy 将 keyboard 段转为 native 保留或文本降级 */
84
+ export function resolveKeyboardSegments(content, policy) {
85
+ if (!hasKeyboardSegment(content))
86
+ return content;
87
+ const items = asArray(content);
88
+ const out = [];
89
+ for (const item of items) {
90
+ if (typeof item === 'string') {
91
+ out.push(item);
92
+ continue;
93
+ }
94
+ const data = item instanceof KeyboardSegment
95
+ ? item.data
96
+ : isKeyboardSegment(item)
97
+ ? item.data
98
+ : null;
99
+ if (!data) {
100
+ out.push(item);
101
+ continue;
102
+ }
103
+ if (policy === 'native') {
104
+ out.push(toKeyboardElement(data));
105
+ continue;
106
+ }
107
+ out.push(segment.text(renderKeyboardAsText(data)));
108
+ }
109
+ return packSegments(out);
110
+ }
@@ -0,0 +1,50 @@
1
+ import type { MessageElement } from '../../types.js';
2
+ export declare const KEYBOARD_SEGMENT_TYPE: "keyboard";
3
+ export declare const ACTION_SEGMENT_TYPE: "action";
4
+ export type ButtonStyle = 'primary' | 'danger' | 'secondary';
5
+ /** callback:平台回调 action 入站;command:QQ 指令预填后文本入站 */
6
+ export type ButtonInteractionMode = 'callback' | 'command';
7
+ export interface ButtonCommandOptions {
8
+ /** QQ action.enter — 仅单聊;预填后自动发送 */
9
+ enter?: boolean;
10
+ /** QQ action.reply — 预填时引用原消息 */
11
+ reply?: boolean;
12
+ }
13
+ export type ButtonData = {
14
+ id: string;
15
+ label: string;
16
+ payload: string;
17
+ disabled?: boolean;
18
+ style?: ButtonStyle;
19
+ /** 默认 callback */
20
+ mode?: ButtonInteractionMode;
21
+ command?: ButtonCommandOptions;
22
+ };
23
+ export type KeyboardFallback = {
24
+ hint: string;
25
+ map: Record<string, string>;
26
+ };
27
+ export type KeyboardSegmentData = {
28
+ rows: ButtonData[][];
29
+ fallback?: KeyboardFallback;
30
+ };
31
+ export type ActionSegmentData = {
32
+ id: string;
33
+ payload: string;
34
+ sourceMessageId?: string;
35
+ };
36
+ export type InteractivePolicy = 'native' | 'text';
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 & {
44
+ type: typeof KEYBOARD_SEGMENT_TYPE;
45
+ data: KeyboardSegmentData;
46
+ };
47
+ export declare function isActionSegment(item: MessageElement): item is MessageElement & {
48
+ type: typeof ACTION_SEGMENT_TYPE;
49
+ data: ActionSegmentData;
50
+ };
@@ -0,0 +1,9 @@
1
+ export const KEYBOARD_SEGMENT_TYPE = 'keyboard';
2
+ export const ACTION_SEGMENT_TYPE = 'action';
3
+ export const DEFAULT_INTERACTIVE_POLICY = 'text';
4
+ export function isKeyboardSegment(item) {
5
+ return item != null && typeof item === 'object' && 'type' in item && item.type === KEYBOARD_SEGMENT_TYPE;
6
+ }
7
+ export function isActionSegment(item) {
8
+ return item != null && typeof item === 'object' && 'type' in item && item.type === ACTION_SEGMENT_TYPE;
9
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * IM 内省指令格式化(/cmd、/endpoints 等)
3
+ */
4
+ export interface EndpointRow {
5
+ adapter: string;
6
+ name: string;
7
+ online: boolean;
8
+ }
9
+ export declare function formatEndpointsList(endpoints: EndpointRow[]): string;
10
+ export declare function endpointHelpText(): string;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * IM 内省指令格式化(/cmd、/endpoints 等)
3
+ */
4
+ export function formatEndpointsList(endpoints) {
5
+ if (endpoints.length === 0)
6
+ return '🤖 暂无 Endpoint 实例';
7
+ const lines = ['🤖 Endpoint 列表 (' + endpoints.length + ')', ''];
8
+ for (const b of [...endpoints].sort((a, c) => a.adapter.localeCompare(c.adapter) || a.name.localeCompare(c.name))) {
9
+ const mark = b.online ? '● online' : '○ offline';
10
+ lines.push(` ${mark} ${b.adapter}/${b.name}`);
11
+ }
12
+ return lines.join('\n');
13
+ }
14
+ export function endpointHelpText() {
15
+ return [
16
+ 'Endpoint 运行时管理:',
17
+ '',
18
+ ' /endpoint add [adapter] — 添加 endpoint(adapter 交互或 schema 向导)',
19
+ ' /endpoint remove <adapter> <name>',
20
+ ' /endpoint edit <adapter> <name>',
21
+ ' /endpoint start <adapter> <name>',
22
+ ' /endpoint stop <adapter> <name>',
23
+ ' /endpoint cancel — 取消进行中的添加/绑定',
24
+ ' /endpoint sync — 将内存 endpoint 写回 zhin.config',
25
+ ' /endpoint help',
26
+ ' /endpoints — 查看运行时在线状态',
27
+ ].join('\n');
28
+ }
@@ -6,10 +6,12 @@
6
6
  * 待办未消费前会一直保留,刷新页面后仍可继续消费。
7
7
  *
8
8
  * 事件:
9
- * bot.login.pending — 有新待办时触发,payload: PendingLoginTask
9
+ * endpoint.login.pending — 有新待办时触发,payload: PendingLoginTask
10
+ * endpoint.login.expired — 超时自动取消时触发,payload: PendingLoginTask
10
11
  */
11
- import type { Plugin } from '../plugin.js';
12
- export type LoginAssistType = 'qrcode' | 'sms' | 'slider' | 'device' | 'other';
12
+ export type LoginAssistType = 'qrcode' | 'sms' | 'slider' | 'device' | 'auth' | 'other';
13
+ /** 默认 5 分钟;扫码/滑块长期挂起会泄漏 Promise Map 条目 */
14
+ export declare const DEFAULT_LOGIN_ASSIST_TIMEOUT_MS: number;
13
15
  export interface PendingLoginTaskPayload {
14
16
  /** 说明文案(如「请扫码登录」) */
15
17
  message?: string;
@@ -23,20 +25,48 @@ export interface PendingLoginTaskPayload {
23
25
  export interface PendingLoginTask {
24
26
  id: string;
25
27
  adapter: string;
26
- botId: string;
28
+ endpointKey: string;
27
29
  type: LoginAssistType;
28
30
  payload: PendingLoginTaskPayload;
29
31
  createdAt: number;
32
+ /** 到期时间戳(ms);无超时则为 undefined */
33
+ expiresAt?: number;
34
+ }
35
+ export interface WaitForInputOptions {
36
+ /** Endpoint-instance owner. Only this owner may cancel the task during rollback/retirement. */
37
+ owner: object;
38
+ /**
39
+ * 超时毫秒。默认 {@link DEFAULT_LOGIN_ASSIST_TIMEOUT_MS}。
40
+ * 传 `0` / `Infinity` / 负数表示不超时(仅测试或显式长驻场景)。
41
+ */
42
+ timeoutMs?: number;
43
+ }
44
+ export type LoginAssistEventName = 'endpoint.login.pending' | 'endpoint.login.resolved' | 'endpoint.login.expired';
45
+ /** Minimal bus — Plugin Runtime / classic Plugin / test EventEmitter all qualify. */
46
+ export interface LoginAssistBus {
47
+ emit(name: LoginAssistEventName, task: PendingLoginTask): void;
30
48
  }
31
49
  export declare class LoginAssist {
32
- private readonly plugin;
50
+ #private;
51
+ private readonly bus;
33
52
  private readonly pending;
53
+ private readonly local;
34
54
  private idSeq;
35
- constructor(plugin: Plugin);
55
+ /** 构造时默认超时;可被 waitForInput options 覆盖 */
56
+ private readonly defaultTimeoutMs;
57
+ constructor(bus?: LoginAssistBus | null, options?: {
58
+ defaultTimeoutMs?: number;
59
+ });
36
60
  /**
37
- * 生产者:等待用户输入后 resolve。会发出 bot.login.pending 事件,未消费前可被 listPending 拉取(刷新后可继续消费)。
61
+ * Subscribe without requiring a Plugin EventEmitter.
62
+ * Returns unsubscribe.
38
63
  */
39
- waitForInput(adapter: string, botId: string, type: LoginAssistType, payload?: PendingLoginTaskPayload): Promise<string | Record<string, unknown>>;
64
+ subscribe(name: LoginAssistEventName, listener: (task: PendingLoginTask) => void): () => void;
65
+ /**
66
+ * 生产者:等待用户输入后 resolve。会发出 endpoint.login.pending 事件,未消费前可被 listPending 拉取(刷新后可继续消费)。
67
+ * 超时后 reject 并 emit `endpoint.login.expired`。
68
+ */
69
+ waitForInput(adapter: string, endpointKey: string, type: LoginAssistType, payload: PendingLoginTaskPayload, options: WaitForInputOptions): Promise<string | Record<string, unknown>>;
40
70
  /**
41
71
  * 消费者:提交结果,对应 waitForInput 的 Promise 会 resolve。
42
72
  */
@@ -45,10 +75,15 @@ export declare class LoginAssist {
45
75
  * 消费者:取消某条待办,对应 Promise 会 reject。
46
76
  */
47
77
  cancel(id: string, reason?: string): boolean;
78
+ /**
79
+ * Cancel pending tasks created by one exact Endpoint instance.
80
+ */
81
+ cancelOwned(owner: object, reason?: string): number;
48
82
  /**
49
83
  * 列出未消费的待办(供 Web/CLI 展示,刷新后仍可拉取同一列表)。
50
84
  */
51
85
  listPending(): PendingLoginTask[];
86
+ hasPending(adapter?: string, endpointKey?: string): boolean;
52
87
  dispose(): void;
53
88
  }
54
89
  declare module '../plugin.js' {
@@ -58,4 +93,3 @@ declare module '../plugin.js' {
58
93
  }
59
94
  }
60
95
  }
61
- //# sourceMappingURL=login-assist.d.ts.map