@zhin.js/core 1.1.33 → 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 (380) hide show
  1. package/README.md +140 -61
  2. package/lib/adapter.d.ts +72 -23
  3. package/lib/adapter.js +222 -58
  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 +9 -0
  63. package/lib/built/html-segment-fallback.js +49 -0
  64. package/lib/built/html-to-text.d.ts +4 -1
  65. package/lib/built/html-to-text.js +47 -16
  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 +67 -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 -21
  209. package/lib/index.js +53 -28
  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 -85
  269. package/lib/types.js +0 -1
  270. package/lib/utils.d.ts +68 -1
  271. package/lib/utils.js +73 -11
  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-to-text.d.ts.map +0 -1
  306. package/lib/built/html-to-text.js.map +0 -1
  307. package/lib/built/inbound-runner.d.ts.map +0 -1
  308. package/lib/built/inbound-runner.js.map +0 -1
  309. package/lib/built/login-assist.d.ts.map +0 -1
  310. package/lib/built/login-assist.js.map +0 -1
  311. package/lib/built/message-filter.d.ts.map +0 -1
  312. package/lib/built/message-filter.js.map +0 -1
  313. package/lib/built/permission.d.ts.map +0 -1
  314. package/lib/built/permission.js.map +0 -1
  315. package/lib/built/prepend-quote-context.d.ts +0 -33
  316. package/lib/built/prepend-quote-context.d.ts.map +0 -1
  317. package/lib/built/prepend-quote-context.js +0 -129
  318. package/lib/built/prepend-quote-context.js.map +0 -1
  319. package/lib/built/queue-im-field-contract.d.ts.map +0 -1
  320. package/lib/built/queue-im-field-contract.js.map +0 -1
  321. package/lib/built/roles.d.ts.map +0 -1
  322. package/lib/built/roles.js.map +0 -1
  323. package/lib/built/runtime-io.d.ts.map +0 -1
  324. package/lib/built/runtime-io.js.map +0 -1
  325. package/lib/built/schema-feature.d.ts.map +0 -1
  326. package/lib/built/schema-feature.js.map +0 -1
  327. package/lib/built/skill.d.ts.map +0 -1
  328. package/lib/built/skill.js.map +0 -1
  329. package/lib/built/tool.d.ts.map +0 -1
  330. package/lib/built/tool.js.map +0 -1
  331. package/lib/command.d.ts.map +0 -1
  332. package/lib/command.js.map +0 -1
  333. package/lib/component.d.ts.map +0 -1
  334. package/lib/component.js.map +0 -1
  335. package/lib/errors.d.ts.map +0 -1
  336. package/lib/errors.js.map +0 -1
  337. package/lib/index.d.ts.map +0 -1
  338. package/lib/index.js.map +0 -1
  339. package/lib/jsx-dev-runtime.d.ts.map +0 -1
  340. package/lib/jsx-dev-runtime.js.map +0 -1
  341. package/lib/jsx-runtime.d.ts.map +0 -1
  342. package/lib/jsx-runtime.js.map +0 -1
  343. package/lib/jsx.d.ts.map +0 -1
  344. package/lib/jsx.js.map +0 -1
  345. package/lib/message-quote.d.ts +0 -11
  346. package/lib/message-quote.d.ts.map +0 -1
  347. package/lib/message-quote.js +0 -91
  348. package/lib/message-quote.js.map +0 -1
  349. package/lib/message.d.ts.map +0 -1
  350. package/lib/message.js.map +0 -1
  351. package/lib/models/system-log.d.ts.map +0 -1
  352. package/lib/models/system-log.js.map +0 -1
  353. package/lib/models/user.d.ts.map +0 -1
  354. package/lib/models/user.js.map +0 -1
  355. package/lib/notice.d.ts.map +0 -1
  356. package/lib/notice.js.map +0 -1
  357. package/lib/plugin.d.ts.map +0 -1
  358. package/lib/plugin.js.map +0 -1
  359. package/lib/prompt.d.ts.map +0 -1
  360. package/lib/prompt.js.map +0 -1
  361. package/lib/request.d.ts.map +0 -1
  362. package/lib/request.js.map +0 -1
  363. package/lib/scheduler/scheduler.d.ts +0 -49
  364. package/lib/scheduler/scheduler.d.ts.map +0 -1
  365. package/lib/scheduler/scheduler.js +0 -352
  366. package/lib/scheduler/scheduler.js.map +0 -1
  367. package/lib/scheduler/types.d.ts +0 -71
  368. package/lib/scheduler/types.d.ts.map +0 -1
  369. package/lib/scheduler/types.js +0 -8
  370. package/lib/scheduler/types.js.map +0 -1
  371. package/lib/tool-zod.d.ts.map +0 -1
  372. package/lib/tool-zod.js.map +0 -1
  373. package/lib/types-generator.d.ts +0 -6
  374. package/lib/types-generator.d.ts.map +0 -1
  375. package/lib/types-generator.js +0 -72
  376. package/lib/types-generator.js.map +0 -1
  377. package/lib/types.d.ts.map +0 -1
  378. package/lib/types.js.map +0 -1
  379. package/lib/utils.d.ts.map +0 -1
  380. package/lib/utils.js.map +0 -1
package/lib/plugin.js CHANGED
@@ -6,15 +6,18 @@
6
6
  * - 生命周期事件类型安全(Plugin.Lifecycle)
7
7
  * - 中间件系统、适配器管理、useContext 等
8
8
  */
9
- import { AsyncLocalStorage } from "node:async_hooks";
10
9
  import * as fs from "node:fs";
11
10
  import * as path from "node:path";
12
- import { fileURLToPath, pathToFileURL } from "node:url";
11
+ import { pathToFileURL } from "node:url";
13
12
  import { formatCompact } from "@zhin.js/logger";
14
13
  import { compose, remove, resolveEntry } from "./utils.js";
14
+ import { ensureInteractiveMiddleware, registerInteractiveHandler as registerInteractiveHandlerCore, } from "./built/interactive-segments/handlers.js";
15
15
  import { Adapter } from "./adapter.js";
16
- import { Feature } from "@zhin.js/kernel";
17
- import { PluginBase, resolvePluginResolveDir as _resolvePluginResolveDir, pluginCreateRequire as _pluginCreateRequire, getFileHash, watchFile, registerExtension, unregisterExtensions, installExtensionProxy, } from "@zhin.js/kernel";
16
+ import { Feature, PluginBase, resolvePluginResolveDir as _resolvePluginResolveDir, pluginCreateRequire as _pluginCreateRequire, getFileHash, watchFile, registerExtension, unregisterExtensions, installExtensionProxy } from '@zhin.js/kernel';
17
+ import { storage } from "./plugin-context.js";
18
+ export { getPlugin, markPluginRuntimeActive, isPluginRuntimeActive, resetPluginRuntimeFlag } from "./plugin-context.js";
19
+ export { storage, getCurrentFile } from "./plugin-context.js";
20
+ export { setHostRootPlugin, getHostRootPlugin } from "./host-plugin-registry.js";
18
21
  const contextsKey = Symbol("contexts");
19
22
  function resolvePluginResolveDir(parent) {
20
23
  return _resolvePluginResolveDir(parent);
@@ -23,68 +26,13 @@ const loadedModules = new Map();
23
26
  function pluginCreateRequire() {
24
27
  return _pluginCreateRequire();
25
28
  }
26
- // ============================================================================
27
- // AsyncLocalStorage 上下文
28
- // ============================================================================
29
- export const storage = new AsyncLocalStorage();
30
29
  /**
31
- * 获取当前文件路径(调用者)
32
- */
33
- function getCurrentFile(metaUrl = import.meta.url) {
34
- if (typeof metaUrl !== "string" || metaUrl.length === 0) {
35
- return path.join(process.cwd(), "__zhin_edge_bootstrap__.mjs");
36
- }
37
- const previousPrepareStackTrace = Error.prepareStackTrace;
38
- Error.prepareStackTrace = function (_, stack) {
39
- return stack;
40
- };
41
- const stack = new Error().stack;
42
- Error.prepareStackTrace = previousPrepareStackTrace;
43
- const stackFiles = Array.from(new Set(stack.map((site) => site.getFileName())));
44
- const idx = stackFiles.findIndex((f) => f === fileURLToPath(metaUrl) || f === metaUrl);
45
- const result = stackFiles[idx + 1];
46
- if (!result) {
47
- return path.join(process.cwd(), "__zhin_edge_bootstrap__.mjs");
48
- }
49
- try {
50
- return fileURLToPath(result);
51
- }
52
- catch {
53
- return result;
54
- }
55
- }
56
- /**
57
- * usePlugin - 获取或创建当前插件实例
58
- * 类似 React Hooks 的设计,根据调用文件自动创建插件树
59
- * 同一上下文中同一文件多次调用返回同一实例
30
+ * @deprecated **已删除**。请使用 `definePlugin` + 约定目录(`zhin runtime start`)。
31
+ * @throws 总是抛出——仅保留签名供编译期过渡。
60
32
  */
61
33
  export function usePlugin() {
62
- const callerFile = getCurrentFile();
63
- // 如果当前 store 已是同一文件创建的插件,直接返回
64
- const current = storage.getStore();
65
- if (current && current.filePath.replace(/\?t=\d+$/, '') === callerFile.replace(/\?t=\d+$/, '')) {
66
- return current;
67
- }
68
- const parentPlugin = current;
69
- const newPlugin = new Plugin(callerFile, parentPlugin);
70
- try {
71
- storage.enterWith(newPlugin);
72
- }
73
- catch {
74
- // Cloudflare Workers 等环境未实现 enterWith;调用方须用 storage.run()
75
- }
76
- return newPlugin;
77
- }
78
- /**
79
- * getPlugin - 获取当前 AsyncLocalStorage 中的插件实例
80
- * 用于 extensions 等场景,不创建新插件
81
- */
82
- export function getPlugin() {
83
- const plugin = storage.getStore();
84
- if (!plugin) {
85
- throw new Error('getPlugin() must be called within a plugin context');
86
- }
87
- return plugin;
34
+ throw new Error('usePlugin() has been removed. Use `definePlugin` + convention directories instead. '
35
+ + 'See docs/contributing/public-api-surface.md');
88
36
  }
89
37
  /**
90
38
  * Plugin 类 - IM 特化插件,继承 PluginBase
@@ -106,33 +54,14 @@ export class Plugin extends PluginBase {
106
54
  get root() {
107
55
  return super.root;
108
56
  }
109
- // 插件功能
110
- #messageMiddleware = async (message, next) => {
111
- const commandService = this.inject('command');
112
- if (!commandService)
113
- return await next();
114
- const result = await commandService.handle(message, this);
115
- if (result === undefined || result === null)
116
- return await next();
117
- const adapter = this.inject(message.$adapter);
118
- if (!adapter || !(adapter instanceof Adapter))
119
- return await next();
120
- await message.$reply(result);
57
+ // 默认中间件:将入站消息交给 compose 链末端的 MessageDispatcher(命令/AI 路由在 dispatcher 内完成)
58
+ #messageMiddleware = async (_message, next) => {
59
+ await next();
121
60
  };
122
61
  #middlewares = [this.#messageMiddleware];
123
- // Feature 贡献追踪
124
- #featureContributions = new Map();
125
- // 统一的清理函数集合
126
- #disposables = new Set();
127
62
  get middleware() {
128
63
  return compose(this.#middlewares);
129
64
  }
130
- recordFeatureContribution(featureName, itemName) {
131
- if (!this.#featureContributions.has(featureName)) {
132
- this.#featureContributions.set(featureName, new Set());
133
- }
134
- this.#featureContributions.get(featureName).add(itemName);
135
- }
136
65
  /**
137
66
  * 构造函数
138
67
  */
@@ -152,11 +81,17 @@ export class Plugin extends PluginBase {
152
81
  */
153
82
  addMiddleware(middleware, name) {
154
83
  this.#middlewares.push(middleware);
155
- const dispose = () => {
156
- remove(this.#middlewares, middleware);
157
- this.#disposables.delete(dispose);
158
- };
159
- this.#disposables.add(dispose);
84
+ const dispose = () => remove(this.#middlewares, middleware);
85
+ this.onDispose(dispose);
86
+ return dispose;
87
+ }
88
+ /**
89
+ * 注册交互式 action 回调处理器(自动安装根中间件,优先于 Dispatcher)
90
+ */
91
+ registerInteractiveHandler(prefix, handler) {
92
+ ensureInteractiveMiddleware((mw) => this.root.addMiddleware(mw));
93
+ const dispose = registerInteractiveHandlerCore(prefix, handler);
94
+ this.onDispose(dispose);
160
95
  return dispose;
161
96
  }
162
97
  /**
@@ -165,15 +100,20 @@ export class Plugin extends PluginBase {
165
100
  get name() {
166
101
  if (this.#cachedName)
167
102
  return this.#cachedName;
168
- this.#cachedName = path
103
+ let name = path
169
104
  .relative(process.cwd(), this.filePath)
170
105
  .replace(/\?t=\d+$/, "")
171
106
  .replace(/\\/g, "/")
172
107
  .replace(/\/index\.(js|ts)x?$/, "")
173
- .replace(/\/(lib|src|dist)$/, "")
174
- .replace(/.*\/node_modules\//, "")
175
- .replace(/.*\//, "")
176
- .replace(/\.(js|ts)x?$/, "");
108
+ .replace(/\/(lib|src|dist)$/, "");
109
+ const nodeModulesIndex = name.indexOf("node_modules/");
110
+ if (nodeModulesIndex !== -1)
111
+ name = name.slice(nodeModulesIndex + "node_modules/".length);
112
+ const slash = name.lastIndexOf("/");
113
+ if (slash !== -1)
114
+ name = name.slice(slash + 1);
115
+ name = name.replace(/\.(js|ts)x?$/, "");
116
+ this.#cachedName = name;
177
117
  return this.#cachedName;
178
118
  }
179
119
  /**
@@ -248,10 +188,9 @@ export class Plugin extends PluginBase {
248
188
  sideEffect.finished = false;
249
189
  };
250
190
  this.on('context.dispose', disposeFn);
251
- // 确保 dispose 时清理监听器(只注册一次)
252
191
  const cleanupOnDispose = () => {
253
192
  this.off('context.dispose', disposeFn);
254
- dispose(this.inject(args[0]));
193
+ dispose(this.inject(contexts[0]));
255
194
  };
256
195
  this.once('dispose', cleanupOnDispose);
257
196
  };
@@ -268,7 +207,8 @@ export class Plugin extends PluginBase {
268
207
  contextReadyCallback();
269
208
  }
270
209
  inject(name) {
271
- const context = this.root.contexts.get(name);
210
+ const resolved = name === 'cron' ? 'schedule' : name;
211
+ const context = this.root.contexts.get(resolved);
272
212
  return context?.value;
273
213
  }
274
214
  injectAdapter(name) {
@@ -293,44 +233,41 @@ export class Plugin extends PluginBase {
293
233
  // ============================================================================
294
234
  /**
295
235
  * 启动插件
236
+ * 覆盖 PluginBase.start() 以支持 Context 挂载失败回滚
296
237
  */
297
238
  async start(t) {
298
239
  if (this.started)
299
240
  return;
300
- // 挂载所有 Context,支持部分失败回滚
241
+ // 先挂载所有 Context(带回滚),再标记 started
242
+ await this.mountAllContexts();
243
+ this.started = true;
244
+ await this.broadcast("mounted");
245
+ for (const child of this.children) {
246
+ await child.start(t);
247
+ }
248
+ if (t) {
249
+ this.logger.debug(formatCompact({ name: this.name, reload_ms: Date.now() - t }));
250
+ }
251
+ }
252
+ /**
253
+ * 覆盖 mountAllContexts:支持部分失败回滚
254
+ */
255
+ async mountAllContexts() {
301
256
  const mountedContexts = [];
302
257
  for (const [name, context] of this.$contexts) {
303
258
  try {
304
- if (typeof context.mounted === "function") {
305
- const result = await context.mounted(this);
306
- // 仅在没有预设 value 时才用 mounted 返回值赋值
307
- if (!context.value) {
308
- context.value = result;
309
- }
310
- }
311
- // 注册扩展方法到共享 registry
312
- if (context.extensions) {
313
- installExtensionProxy(Plugin.prototype);
314
- for (const [extName, fn] of Object.entries(context.extensions)) {
315
- if (typeof fn === 'function') {
316
- registerExtension(extName, fn);
317
- }
318
- }
319
- }
259
+ await this.mountContext(context);
320
260
  mountedContexts.push({ name, context });
321
261
  }
322
262
  catch (e) {
323
- // 回滚已挂载的 Context(逆序 dispose)
324
263
  this.logger.warn(`Context "${name}" mount failed: ${e}, rolling back ${mountedContexts.length} mounted contexts`);
325
264
  for (let i = mountedContexts.length - 1; i >= 0; i--) {
326
265
  const { name: mName, context: mCtx } = mountedContexts[i];
327
266
  try {
328
- if (mCtx.extensions) {
267
+ if (mCtx.extensions)
329
268
  unregisterExtensions(Object.keys(mCtx.extensions));
330
- }
331
- if (typeof mCtx.dispose === 'function') {
269
+ if (typeof mCtx.dispose === 'function')
332
270
  await mCtx.dispose(mCtx.value);
333
- }
334
271
  }
335
272
  catch (disposeErr) {
336
273
  this.logger.warn(`Rollback dispose for "${mName}" failed: ${disposeErr}`);
@@ -339,22 +276,9 @@ export class Plugin extends PluginBase {
339
276
  throw e;
340
277
  }
341
278
  }
342
- // 所有 Context 成功挂载后,才标记为已启动
343
- this.started = true;
344
279
  for (const { name } of mountedContexts) {
345
280
  this.dispatch('context.mounted', name);
346
281
  }
347
- await this.broadcast("mounted");
348
- // 先启动子插件,再打印当前插件启动日志
349
- for (const child of this.children) {
350
- await child.start(t);
351
- }
352
- if (t) {
353
- this.logger.debug(formatCompact({
354
- name: this.name,
355
- reload_ms: Date.now() - t,
356
- }));
357
- }
358
282
  }
359
283
  /**
360
284
  * 获取插件提供的功能
@@ -363,11 +287,11 @@ export class Plugin extends PluginBase {
363
287
  get features() {
364
288
  const commandService = this.inject('command');
365
289
  const componentService = this.inject('component');
366
- const cronService = this.inject('cron');
290
+ const scheduleService = this.inject('schedule');
367
291
  return {
368
292
  commands: commandService ? commandService.items.map(c => c.pattern) : [],
369
293
  components: componentService ? componentService.getAllNames() : [],
370
- crons: cronService ? cronService.items.map(c => c.cronExpression) : [],
294
+ schedules: scheduleService ? scheduleService.items.map(s => s.id) : [],
371
295
  middlewares: this.#middlewares.map((m, i) => m.name || `middleware_${i}`),
372
296
  };
373
297
  }
@@ -382,8 +306,8 @@ export class Plugin extends PluginBase {
382
306
  result.push({ name: 'command', count: f.commands.length });
383
307
  if (f.components.length > 0)
384
308
  result.push({ name: 'component', count: f.components.length });
385
- if (f.crons.length > 0)
386
- result.push({ name: 'cron', count: f.crons.length });
309
+ if (f.schedules.length > 0)
310
+ result.push({ name: 'schedule', count: f.schedules.length });
387
311
  // #middlewares includes the default command middleware, only count user-added ones
388
312
  const userMiddlewareCount = this.#middlewares.length - 1; // subtract default #messageMiddleware
389
313
  if (userMiddlewareCount > 0)
@@ -401,63 +325,16 @@ export class Plugin extends PluginBase {
401
325
  }
402
326
  /**
403
327
  * 停止插件
328
+ * 委托 PluginBase.stop() 处理通用清理,仅补充 IM 特化逻辑
404
329
  */
405
330
  async stop() {
406
331
  if (!this.started)
407
332
  return;
408
333
  this.logger.debug(`Stopping plugin "${this.name}"`);
409
- this.started = false;
410
- // 停止子插件
411
- for (const child of this.children) {
412
- await child.stop();
413
- }
414
- this.children = [];
415
- // 停止服务
416
- for (const [name, context] of this.$contexts) {
417
- remove(Plugin[contextsKey], name);
418
- // 从共享 registry 注销扩展方法(引用计数,不影响其他提供者)
419
- if (context.extensions) {
420
- unregisterExtensions(Object.keys(context.extensions));
421
- }
422
- if (typeof context.dispose === "function") {
423
- await context.dispose(context.value);
424
- }
425
- }
426
- // 清理 contexts Map
427
- this.$contexts.clear();
428
- // 清空缓存的名称
429
- this.#cachedName = undefined;
430
- // 触发 dispose 事件
431
- this.emit("dispose");
432
- // 执行所有清理函数
433
- for (const dispose of this.#disposables) {
434
- try {
435
- await dispose();
436
- }
437
- catch (e) {
438
- this.logger.warn(`Dispose callback failed: ${e}`);
439
- }
440
- }
441
- this.#disposables.clear();
442
- // 清空 middlewares 数组(保留默认的消息中间件)
334
+ // 通用清理(子插件、contexts、disposables、loadedModules 等)
335
+ await super.stop();
336
+ // IM 特化:重置中间件(保留默认消息中间件)
443
337
  this.#middlewares.length = 1;
444
- // 清理 feature 贡献记录
445
- this.#featureContributions.clear();
446
- if (this.parent) {
447
- remove(this.parent?.children, this);
448
- }
449
- // 从全局 loadedModules Map 中移除,防止内存泄漏
450
- if (this.filePath) {
451
- try {
452
- const realPath = fs.realpathSync(this.filePath);
453
- loadedModules.delete(realPath);
454
- }
455
- catch {
456
- // 文件可能已不存在,忽略错误
457
- }
458
- }
459
- this.removeAllListeners();
460
- this.logger.debug(`Plugin "${this.name}" stopped`);
461
338
  }
462
339
  // ============================================================================
463
340
  // 生命周期钩子
@@ -465,12 +342,7 @@ export class Plugin extends PluginBase {
465
342
  onMounted(callback) {
466
343
  this.on("mounted", callback);
467
344
  }
468
- onDispose(callback) {
469
- this.#disposables.add(callback);
470
- return () => {
471
- this.#disposables.delete(callback);
472
- };
473
- }
345
+ // onDispose 继承自 PluginBase
474
346
  // ============================================================================
475
347
  // 事件广播
476
348
  // ============================================================================
@@ -584,30 +456,42 @@ export class Plugin extends PluginBase {
584
456
  */
585
457
  async reload(plugin = this) {
586
458
  const p = plugin;
587
- this.logger.info(formatCompact({ name: p.name, reload: true }));
588
- const now = Date.now();
589
- if (!p.parent) {
590
- // 根插件重载 = 退出进程(由 CLI 重启)
591
- return process.exit(51);
592
- }
593
- const entry = p.filePath;
594
- const parent = p.parent;
595
- await p.stop();
596
- let fresh;
459
+ // A burst of file events for one logical save (or an overlapping edit
460
+ // while a reload is still in flight) must not start a second concurrent
461
+ // stop()+import() cycle for the same plugin.
462
+ if (p._reloading)
463
+ return;
464
+ p._reloading = true;
597
465
  try {
598
- fresh = await parent.import(entry, now);
466
+ this.logger.info(formatCompact({ name: p.name, reload: true }));
467
+ const now = Date.now();
468
+ if (!p.parent) {
469
+ // 根插件重载 = 退出进程(由 CLI 重启)
470
+ process.exit(51);
471
+ return;
472
+ }
473
+ const entry = p.filePath;
474
+ const parent = p.parent;
475
+ await p.stop();
476
+ let fresh;
477
+ try {
478
+ fresh = await parent.import(entry, now);
479
+ }
480
+ catch (err) {
481
+ this.logger.error(formatCompact({
482
+ name: p.name,
483
+ reload: false,
484
+ error: err instanceof Error ? err.message : String(err),
485
+ hint: 'full_restart',
486
+ }));
487
+ throw err;
488
+ }
489
+ await fresh.broadcast('mounted');
490
+ this.logger.debug(formatCompact({ name: fresh.name, reload_ms: Date.now() - now }));
599
491
  }
600
- catch (err) {
601
- this.logger.error(formatCompact({
602
- name: p.name,
603
- reload: false,
604
- error: err instanceof Error ? err.message : String(err),
605
- hint: 'full_restart',
606
- }));
607
- throw err;
492
+ finally {
493
+ p._reloading = false;
608
494
  }
609
- await fresh.broadcast('mounted');
610
- this.logger.debug(formatCompact({ name: fresh.name, reload_ms: Date.now() - now }));
611
495
  }
612
496
  /**
613
497
  * 监听文件变化(Plugin 类型窄化版本)
@@ -615,14 +499,22 @@ export class Plugin extends PluginBase {
615
499
  watch(callback, recursive = false) {
616
500
  if (!this.filePath || this.filePath.includes("node_modules"))
617
501
  return;
618
- const unwatch = watchFile(this.filePath, () => {
619
- const newHash = getFileHash(this.filePath);
620
- if (newHash === this.fileHash)
621
- return;
622
- this.logger.debug(`Plugin "${this.name}" file changed, reloading...`);
623
- callback(this);
624
- this.fileHash = newHash;
625
- });
502
+ const unwatch = watchFile(this.filePath, (() => {
503
+ let debounceTimer = null;
504
+ return () => {
505
+ if (debounceTimer)
506
+ clearTimeout(debounceTimer);
507
+ debounceTimer = setTimeout(() => {
508
+ debounceTimer = null;
509
+ const newHash = getFileHash(this.filePath);
510
+ if (newHash === this.fileHash)
511
+ return;
512
+ this.logger.debug(`Plugin "${this.name}" file changed, reloading...`);
513
+ callback(this);
514
+ this.fileHash = newHash;
515
+ }, 300);
516
+ };
517
+ })());
626
518
  this.on("dispose", unwatch);
627
519
  if (recursive) {
628
520
  for (const child of this.children) {
@@ -676,6 +568,10 @@ export class Plugin extends PluginBase {
676
568
  plugin.fileHash = getFileHash(entryFile);
677
569
  // 先记录,防止循环依赖时重复加载
678
570
  loadedModules.set(realPath, plugin);
571
+ // 注意:?t= cache-busting 会导致 Node ESM 模块缓存累积旧条目。
572
+ // 这是 Node.js ESM 的已知限制——没有公开 API 可以逐出 ESM 模块缓存。
573
+ // 在生产环境中插件只加载一次,不会触发此问题;
574
+ // 开发环境中热重载会累积,但仅影响开发进程,重启即释放。
679
575
  await storage.run(plugin, async () => {
680
576
  await import(`${pathToFileURL(entryFile).href}?t=${Date.now()}`);
681
577
  });
@@ -685,4 +581,3 @@ export class Plugin extends PluginBase {
685
581
  export function defineContext(options) {
686
582
  return options;
687
583
  }
688
- //# sourceMappingURL=plugin.js.map
package/lib/request.d.ts CHANGED
@@ -1,85 +1,41 @@
1
- import { Adapters } from './adapter.js';
2
- import type { MessageSender, MaybePromise } from './types.js';
1
+ import type { MaybePromise } from './types.js';
2
+ import type { Adapters } from './adapter.js';
3
+ import type { RequestKind } from './side-event/types.js';
4
+ import type { SideEventBase } from './side-event/base.js';
5
+ export type { RequestKind, ComposedRequestName } from './side-event/types.js';
3
6
  /**
4
- * 请求类型枚举
5
- *
6
- * 常见 IM 请求事件分类:
7
- * - friend_add: 好友添加请求
8
- * - group_add: 主动申请入群
9
- * - group_invite: 邀请入群请求
10
- *
11
- * 适配器可自行扩展更多子类型
12
- */
13
- export type RequestType = 'friend_add' | 'group_add' | 'group_invite' | (string & {});
14
- /**
15
- * 请求频道信息
16
- */
17
- export interface RequestChannel {
18
- id: string;
19
- type: 'group' | 'private' | 'channel';
20
- }
21
- /**
22
- * 请求基础结构
23
- *
24
- * 与 MessageBase / NoticeBase 同构设计。
25
- * 核心区别:Request 提供 `$approve()` 和 `$reject()` 方法,用于快速处理请求。
7
+ * 请求基础结构 — 继承 SideEventBase,附加审批方法。
26
8
  *
27
9
  * @example
28
10
  * ```typescript
29
- * // 适配器中格式化请求
30
11
  * const request = Request.from(rawEvent, {
31
12
  * $id: rawEvent.flag,
32
13
  * $adapter: 'icqq',
33
- * $bot: botName,
34
- * $type: 'group_invite',
35
- * $channel: { id: groupId, type: 'group' },
36
- * $sender: { id: userId, name: '邀请者' },
14
+ * $endpoint: endpointKey,
15
+ * $type: 'request',
16
+ * $scene_id: groupId,
17
+ * $scene_type: 'group',
18
+ * $sub_type: 'invite',
19
+ * $actor: { id: userId, name: '邀请者' },
37
20
  * $comment: '请求加群消息',
38
21
  * $timestamp: Date.now(),
39
22
  * $approve: async (remark?) => { await api.approve(flag, remark); },
40
23
  * $reject: async (reason?) => { await api.reject(flag, reason); },
41
24
  * });
25
+ * // formatSideEventName(request) === 'request.group.invite'
42
26
  * this.adapter.emit('request.receive', request);
43
27
  * ```
44
28
  */
45
- export interface RequestBase {
46
- /** 请求唯一 ID / flag(平台提供的请求标识,用于后续处理) */
47
- $id: string;
48
- /** 适配器名称 */
29
+ export interface RequestBase extends SideEventBase {
49
30
  $adapter: keyof Adapters;
50
- /** Bot 名称 */
51
- $bot: string;
52
- /** 请求类型 */
53
- $type: RequestType;
54
- /** 请求子类型 */
55
- $subType?: string;
56
- /** 请求发生的频道/群/会话 */
57
- $channel: RequestChannel;
58
- /** 请求发送者 */
59
- $sender: MessageSender;
60
- /** 请求附言/验证消息 */
31
+ $type: RequestKind;
32
+ /** 主参与者(必填) */
33
+ $actor: NonNullable<SideEventBase['$actor']>;
61
34
  $comment?: string;
62
- /** 请求时间戳 */
63
- $timestamp: number;
64
- /**
65
- * 同意请求
66
- * @param remark 备注信息(如好友备注)
67
- */
68
35
  $approve(remark?: string): MaybePromise<void>;
69
- /**
70
- * 拒绝请求
71
- * @param reason 拒绝原因
72
- */
73
36
  $reject(reason?: string): MaybePromise<void>;
74
37
  }
75
- /**
76
- * 完整请求类型,支持平台原始数据扩展
77
- */
78
38
  export type Request<T extends object = {}> = RequestBase & T;
79
39
  export declare namespace Request {
80
- /**
81
- * 工具方法:合并自定义字段与基础请求结构
82
- */
83
40
  function from<T extends object>(input: T, format: RequestBase): Request<T>;
84
41
  }
85
- //# sourceMappingURL=request.d.ts.map
package/lib/request.js CHANGED
@@ -1,11 +1,7 @@
1
1
  export var Request;
2
2
  (function (Request) {
3
- /**
4
- * 工具方法:合并自定义字段与基础请求结构
5
- */
6
3
  function from(input, format) {
7
4
  return Object.assign(input, format);
8
5
  }
9
6
  Request.from = from;
10
7
  })(Request || (Request = {}));
11
- //# sourceMappingURL=request.js.map
@@ -5,10 +5,10 @@ import { Schema } from '@zhin.js/schema';
5
5
  /**
6
6
  * Prompt类:用于实现机器人与用户的交互式提问与输入收集。
7
7
  * 支持文本、数字、确认、列表、选项、Schema等多种输入类型,自动处理超时、默认值、格式化等。
8
- * 典型用法:await new Prompt(plugin, event).text('请输入内容')
8
+ * 典型用法:await new SchemaInteraction(plugin, event).text('请输入内容')
9
9
  * @template P 适配器类型
10
10
  */
11
- export declare class Prompt<P extends RegisteredAdapter> {
11
+ export declare class SchemaInteraction<P extends RegisteredAdapter> {
12
12
  private plugin;
13
13
  private event;
14
14
  /**
@@ -25,7 +25,7 @@ export declare class Prompt<P extends RegisteredAdapter> {
25
25
  * 通用提问方法,支持自定义格式化、超时、默认值等
26
26
  * @param config 提问配置
27
27
  */
28
- private prompt;
28
+ private collect;
29
29
  /**
30
30
  * 注册一次性消息中间件,等待用户输入或超时
31
31
  * @param callback 输入回调
@@ -52,7 +52,7 @@ export declare class Prompt<P extends RegisteredAdapter> {
52
52
  /**
53
53
  * 列表输入,支持多值分隔
54
54
  */
55
- list<T extends Prompt.SingleType = 'text'>(tips: string, config?: Prompt.ListConfig<T>, timeoutText?: string): Promise<Prompt.Result<T>[]>;
55
+ list<T extends SchemaInteraction.SingleType = 'text'>(tips: string, config?: SchemaInteraction.ListConfig<T>, timeoutText?: string): Promise<SchemaInteraction.Result<T>[]>;
56
56
  /**
57
57
  * 返回常量值(用于Schema)
58
58
  */
@@ -60,7 +60,7 @@ export declare class Prompt<P extends RegisteredAdapter> {
60
60
  /**
61
61
  * 选项选择,支持单选/多选
62
62
  */
63
- pick<T extends Prompt.SingleType, M extends boolean = false>(tips: string, config: Prompt.PickConfig<T, M>, timeoutText?: string): Promise<Prompt.PickResult<T, M>>;
63
+ pick<T extends SchemaInteraction.SingleType, M extends boolean = false>(tips: string, config: SchemaInteraction.PickConfig<T, M>, timeoutText?: string): Promise<SchemaInteraction.PickResult<T, M>>;
64
64
  /**
65
65
  * 基于Schema的选项选择
66
66
  */
@@ -79,7 +79,7 @@ export declare class Prompt<P extends RegisteredAdapter> {
79
79
  /**
80
80
  * Prompt命名空间:类型辅助定义
81
81
  */
82
- export declare namespace Prompt {
82
+ export declare namespace SchemaInteraction {
83
83
  interface SingleMap {
84
84
  text: string;
85
85
  number: number;
@@ -115,4 +115,3 @@ export declare namespace Prompt {
115
115
  };
116
116
  export {};
117
117
  }
118
- //# sourceMappingURL=prompt.d.ts.map