@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,4 +1,5 @@
1
1
  import { Schema } from '@zhin.js/schema';
2
+ export { isMediaRef } from '@zhin.js/im-contract';
2
3
  const platformSchema = Schema.dict(Schema.any());
3
4
  const mediaKindSchema = Schema.union([
4
5
  Schema.const('url'),
@@ -95,6 +96,29 @@ export const rpsSegmentSchema = Schema.object({
95
96
  data: Schema.object({ result: Schema.number() }).required(),
96
97
  platform: platformSchema,
97
98
  });
99
+ const shareConfigSchema = Schema.object({
100
+ appid: Schema.number().required(),
101
+ package: Schema.string(),
102
+ sign: Schema.string(),
103
+ icon: Schema.string(),
104
+ version: Schema.string(),
105
+ });
106
+ export const shareSegmentSchema = Schema.object({
107
+ type: Schema.const('share'),
108
+ data: Schema.object({
109
+ url: Schema.string().required(),
110
+ title: Schema.string().required(),
111
+ description: Schema.string(),
112
+ image: Schema.string(),
113
+ audio: Schema.string(),
114
+ content: Schema.string(),
115
+ artist: Schema.string(),
116
+ duration: Schema.number(),
117
+ platform: Schema.string(),
118
+ config: shareConfigSchema,
119
+ }).required(),
120
+ platform: platformSchema,
121
+ });
98
122
  export const canonicalSegmentSchema = Schema.discriminatedUnion('type', {
99
123
  text: {
100
124
  data: Schema.object({ text: Schema.string().required() }).required(),
@@ -163,11 +187,23 @@ export const canonicalSegmentSchema = Schema.discriminatedUnion('type', {
163
187
  data: Schema.object({ result: Schema.number() }).required(),
164
188
  platform: platformSchema,
165
189
  },
190
+ share: {
191
+ data: Schema.object({
192
+ url: Schema.string().required(),
193
+ title: Schema.string().required(),
194
+ description: Schema.string(),
195
+ image: Schema.string(),
196
+ audio: Schema.string(),
197
+ content: Schema.string(),
198
+ artist: Schema.string(),
199
+ duration: Schema.number(),
200
+ platform: Schema.string(),
201
+ config: shareConfigSchema,
202
+ }).required(),
203
+ platform: platformSchema,
204
+ },
166
205
  });
167
206
  export const segmentArraySchema = Schema.list(canonicalSegmentSchema);
168
- export function isMediaRef(value) {
169
- return mediaRefSchema.safeParse(value).success;
170
- }
171
207
  /** 严格 canonical 段校验(@zhin.js/schema validate-only) */
172
208
  export function isStrictCanonicalSegment(value) {
173
209
  return canonicalSegmentSchema.safeParse(value).success;
@@ -0,0 +1,5 @@
1
+ import { type PermissionHost } from '@zhin.js/permission';
2
+ import type { Message } from '../plugin-runtime/im/contracts.js';
3
+ import type { Tool } from '../types.js';
4
+ /** Checks whether a Tool is visible to the current IM message context. */
5
+ export declare function canAccessTool(tool: Tool, message?: Message, host?: PermissionHost | null): Promise<boolean>;
@@ -0,0 +1,17 @@
1
+ import { toPermissionSubject } from '@zhin.js/permission';
2
+ /** Checks whether a Tool is visible to the current IM message context. */
3
+ export async function canAccessTool(tool, message, host) {
4
+ if (!message)
5
+ return !tool.platforms?.length && !tool.scopes?.length && !tool.permissions?.length;
6
+ const adapter = String(message.clientAdapter ?? message.conversation.endpoint.adapter);
7
+ const scope = message.conversation.kind;
8
+ if (tool.platforms?.length && !tool.platforms.includes(adapter))
9
+ return false;
10
+ if (tool.scopes?.length && !tool.scopes.includes(scope))
11
+ return false;
12
+ if (!tool.permissions?.length)
13
+ return true;
14
+ if (!host)
15
+ return false;
16
+ return host.checkAll(tool.permissions, toPermissionSubject(message), { source: message });
17
+ }
@@ -1,4 +1,5 @@
1
- import type { UserInteractionContent, UserInteractionRequest } from '@zhin.js/interaction';
1
+ import type { Locale } from '@zhin.js/plugin-runtime';
2
+ import type { UserInteractionContent, UserInteractionRequest } from '@zhin.js/im-contract';
2
3
  import type { SendContent } from '../plugin-runtime/im/contracts.js';
3
4
  import type { ButtonStyle } from './interactive-segments/types.js';
4
5
  export interface UserInteractionAction {
@@ -23,8 +24,8 @@ export type UserInteractionParseResult = Readonly<{
23
24
  /** Fail early for interaction definitions that could never produce an unambiguous answer. */
24
25
  export declare function assertUserInteractionRequest(request: UserInteractionRequest): void;
25
26
  /** Project semantic content into canonical Markdown + keyboard segments. */
26
- export declare function renderUserInteraction(view: UserInteractionView): SendContent;
27
+ export declare function renderUserInteraction(view: UserInteractionView, actionPayload?: (value: string, index: number) => string, locale?: Locale): SendContent;
27
28
  /** Derive presentation and controls from one discriminated request. */
28
- export declare function projectUserInteraction(request: UserInteractionRequest, progress?: UserInteractionProgress): UserInteractionView;
29
+ export declare function projectUserInteraction(request: UserInteractionRequest, progress?: UserInteractionProgress, locale?: Locale): UserInteractionView;
29
30
  /** Parse and validate one user reply without transport knowledge. */
30
- export declare function parseUserInteractionAnswer(request: UserInteractionRequest, rawInput: string): UserInteractionParseResult;
31
+ export declare function parseUserInteractionAnswer(request: UserInteractionRequest, rawInput: string, locale?: Locale, action?: boolean): UserInteractionParseResult;
@@ -1,3 +1,4 @@
1
+ import { interactionMessages as t } from './interaction-messages.js';
1
2
  /** Fail early for interaction definitions that could never produce an unambiguous answer. */
2
3
  export function assertUserInteractionRequest(request) {
3
4
  if (!request.title.trim())
@@ -14,14 +15,10 @@ export function assertUserInteractionRequest(request) {
14
15
  if (request.type === 'select' || request.type === 'multiselect') {
15
16
  if (request.options.length === 0)
16
17
  throw new TypeError('User interaction options must not be empty');
17
- const labels = new Set();
18
18
  for (const option of request.options) {
19
19
  const label = option.label.trim().toLocaleLowerCase();
20
20
  if (!label)
21
21
  throw new TypeError('User interaction option label must not be empty');
22
- if (labels.has(label))
23
- throw new TypeError(`Duplicate user interaction option label: ${option.label}`);
24
- labels.add(label);
25
22
  }
26
23
  }
27
24
  if (request.type === 'multiselect') {
@@ -40,23 +37,24 @@ export function assertUserInteractionRequest(request) {
40
37
  }
41
38
  }
42
39
  /** Project semantic content into canonical Markdown + keyboard segments. */
43
- export function renderUserInteraction(view) {
40
+ export function renderUserInteraction(view, actionPayload = (value) => value, locale = 'zh-CN') {
44
41
  const markdown = [
45
42
  `### ${view.title}`,
46
43
  view.description?.trim(),
47
44
  view.tip?.trim() ? quoteTip(view.tip.trim()) : undefined,
48
45
  ].filter((part) => !!part).join('\n\n');
49
46
  const actions = view.actions ?? [];
50
- if (actions.length === 0) {
47
+ const hasInlineOptionList = actions.length > 0
48
+ && actions.every((action, index) => view.description?.includes(`${index + 1}. ${action.label}`));
49
+ if (actions.length === 0 || hasInlineOptionList) {
51
50
  return [{ type: 'markdown', data: { content: markdown } }];
52
51
  }
53
52
  const buttons = actions.map((action, index) => ({
54
53
  id: `interaction-${index + 1}`,
55
54
  label: action.label,
56
- payload: action.value,
55
+ payload: actionPayload(action.value, index),
57
56
  ...(action.style ? { style: action.style } : {}),
58
- mode: 'command',
59
- command: { enter: true, reply: false },
57
+ mode: 'callback',
60
58
  }));
61
59
  return [
62
60
  { type: 'markdown', data: { content: markdown } },
@@ -65,23 +63,23 @@ export function renderUserInteraction(view) {
65
63
  data: {
66
64
  rows: chunk(buttons, 5),
67
65
  fallback: {
68
- hint: '也可以直接回复对应内容。',
69
- map: Object.fromEntries(actions.map((action, index) => [String(index + 1), action.value])),
66
+ hint: t(locale, 'fallback'),
67
+ map: Object.fromEntries(buttons.map((button, index) => [String(index + 1), button.payload])),
70
68
  },
71
69
  },
72
70
  },
73
71
  ];
74
72
  }
75
73
  /** Derive presentation and controls from one discriminated request. */
76
- export function projectUserInteraction(request, progress) {
77
- const instruction = instructionFor(request);
74
+ export function projectUserInteraction(request, progress, locale = 'zh-CN') {
75
+ const instruction = instructionFor(request, locale);
78
76
  const optionList = request.type === 'select' || request.type === 'multiselect'
79
77
  ? renderOptions(request.options)
80
78
  : undefined;
81
79
  const optionsHaveDescriptions = request.type === 'select' || request.type === 'multiselect'
82
80
  ? request.options.some((option) => !!option.description)
83
81
  : false;
84
- const actions = actionsFor(request);
82
+ const actions = actionsFor(request, locale);
85
83
  const stepDescription = [
86
84
  progress ? `**${progress.index}/${progress.total} · ${request.title}**` : undefined,
87
85
  request.description,
@@ -97,58 +95,62 @@ export function projectUserInteraction(request, progress) {
97
95
  });
98
96
  }
99
97
  /** Parse and validate one user reply without transport knowledge. */
100
- export function parseUserInteractionAnswer(request, rawInput) {
98
+ export function parseUserInteractionAnswer(request, rawInput, locale = 'zh-CN', action = false) {
101
99
  const raw = rawInput.trim();
102
100
  switch (request.type) {
103
101
  case 'text': {
104
102
  if (raw.length < (request.minLength ?? 0))
105
- return invalid(`请至少输入 ${request.minLength} 个字符`);
103
+ return invalid(t(locale, 'minLength', { count: request.minLength }));
106
104
  if (request.maxLength !== undefined && raw.length > request.maxLength) {
107
- return invalid(`请不要超过 ${request.maxLength} 个字符`);
105
+ return invalid(t(locale, 'maxLength', { count: request.maxLength }));
108
106
  }
109
107
  if (request.pattern) {
110
108
  request.pattern.lastIndex = 0;
111
109
  if (!request.pattern.test(raw))
112
- return invalid('输入格式不正确');
110
+ return invalid(t(locale, 'pattern'));
113
111
  }
114
112
  return valid(raw);
115
113
  }
116
114
  case 'number': {
117
115
  const value = Number(raw);
118
116
  if (!raw || !Number.isFinite(value))
119
- return invalid('请输入有效数字');
117
+ return invalid(t(locale, 'number'));
120
118
  if (request.integer && !Number.isInteger(value))
121
- return invalid('请输入整数');
119
+ return invalid(t(locale, 'integer'));
122
120
  if (request.min !== undefined && value < request.min)
123
- return invalid(`请输入不小于 ${request.min} 的数字`);
121
+ return invalid(t(locale, 'min', { count: request.min }));
124
122
  if (request.max !== undefined && value > request.max)
125
- return invalid(`请输入不大于 ${request.max} 的数字`);
123
+ return invalid(t(locale, 'max', { count: request.max }));
126
124
  return valid(value);
127
125
  }
128
126
  case 'confirm': {
129
- const normalized = raw.toLocaleLowerCase();
127
+ const normalized = raw.toLowerCase();
128
+ if (action && normalized === 'yes')
129
+ return valid(true);
130
+ if (action && normalized === 'no')
131
+ return valid(false);
130
132
  const confirmLabel = request.confirmLabel?.trim().toLocaleLowerCase();
131
133
  const cancelLabel = request.cancelLabel?.trim().toLocaleLowerCase();
132
- if (CONFIRM_VALUES.has(normalized) || (confirmLabel && normalized === confirmLabel))
134
+ if (CONFIRM_VALUES[locale].has(normalized) || (confirmLabel && normalized === confirmLabel))
133
135
  return valid(true);
134
- if (CANCEL_VALUES.has(normalized) || (cancelLabel && normalized === cancelLabel))
136
+ if (CANCEL_VALUES[locale].has(normalized) || (cancelLabel && normalized === cancelLabel))
135
137
  return valid(false);
136
- return invalid('请选择确认或取消');
138
+ return invalid(t(locale, 'confirmOrCancel'));
137
139
  }
138
140
  case 'select': {
139
141
  const option = resolveOption(request.options, raw);
140
- return option ? valid(option.value) : invalid('请选择一个有效选项');
142
+ return option ? valid(option.value) : invalid(t(locale, 'select'));
141
143
  }
142
144
  case 'multiselect': {
143
145
  const separator = request.separator ?? ',';
144
146
  const tokens = raw.split(separator).map((token) => token.trim()).filter(Boolean);
145
147
  const selected = uniqueOptions(tokens.map((token) => resolveOption(request.options, token)));
146
148
  if (selected.length !== tokens.length)
147
- return invalid('多选中包含无效选项');
149
+ return invalid(t(locale, 'invalidSelection'));
148
150
  if (selected.length < (request.minSelections ?? 0))
149
- return invalid(`请至少选择 ${request.minSelections} 项`);
151
+ return invalid(t(locale, 'minSelections', { count: request.minSelections }));
150
152
  if (request.maxSelections !== undefined && selected.length > request.maxSelections) {
151
- return invalid(`请最多选择 ${request.maxSelections} 项`);
153
+ return invalid(t(locale, 'maxSelections', { count: request.maxSelections }));
152
154
  }
153
155
  return valid(Object.freeze(selected.map((option) => option.value)));
154
156
  }
@@ -156,28 +158,28 @@ export function parseUserInteractionAnswer(request, rawInput) {
156
158
  const separator = request.separator ?? ',';
157
159
  const tokens = raw.split(separator).map((token) => token.trim()).filter(Boolean);
158
160
  if (tokens.length < (request.minItems ?? 0))
159
- return invalid(`请至少输入 ${request.minItems} 项`);
161
+ return invalid(t(locale, 'minItems', { count: request.minItems }));
160
162
  if (request.maxItems !== undefined && tokens.length > request.maxItems)
161
- return invalid(`请最多输入 ${request.maxItems} 项`);
163
+ return invalid(t(locale, 'maxItems', { count: request.maxItems }));
162
164
  if (request.valueType === 'number') {
163
165
  const values = tokens.map(Number);
164
- return values.every(Number.isFinite) ? valid(Object.freeze(values)) : invalid('列表中包含无效数字');
166
+ return values.every(Number.isFinite) ? valid(Object.freeze(values)) : invalid(t(locale, 'invalidNumbers'));
165
167
  }
166
168
  if (request.valueType === 'boolean') {
167
- const values = tokens.map(parseBoolean);
169
+ const values = tokens.map(value => parseBoolean(value, locale));
168
170
  return values.every((value) => value !== undefined)
169
171
  ? valid(Object.freeze(values))
170
- : invalid('布尔列表只接受 true/false、yes/no 或 是/否');
172
+ : invalid(t(locale, 'invalidBooleans'));
171
173
  }
172
174
  return valid(Object.freeze(tokens));
173
175
  }
174
176
  }
175
177
  }
176
- function actionsFor(request) {
178
+ function actionsFor(request, locale) {
177
179
  if (request.type === 'confirm') {
178
180
  return [
179
- { label: request.confirmLabel ?? '确认', value: 'yes', style: 'primary' },
180
- { label: request.cancelLabel ?? '取消', value: 'no', style: 'danger' },
181
+ { label: request.confirmLabel ?? t(locale, 'confirm'), value: 'yes', style: 'primary' },
182
+ { label: request.cancelLabel ?? t(locale, 'cancel'), value: 'no', style: 'danger' },
181
183
  ];
182
184
  }
183
185
  if (request.type === 'select' && request.options.length <= 10) {
@@ -185,24 +187,30 @@ function actionsFor(request) {
185
187
  }
186
188
  return undefined;
187
189
  }
188
- function instructionFor(request) {
190
+ function instructionFor(request, locale) {
189
191
  switch (request.type) {
190
- case 'confirm': return '请选择确认或取消。';
191
- case 'select': return '可以点击按钮,或回复序号/选项名称。';
192
- case 'multiselect': return `回复序号或选项名称,多项用“${request.separator ?? ','}”分隔。`;
193
- case 'list': return `多项用“${request.separator ?? ','}”分隔。`;
192
+ case 'confirm': return t(locale, 'confirmation');
193
+ case 'select': return t(locale, 'selection');
194
+ case 'multiselect': return t(locale, 'multiple', { separator: request.separator ?? ',' });
195
+ case 'list': return t(locale, 'list', { separator: request.separator ?? ',' });
194
196
  default: return undefined;
195
197
  }
196
198
  }
197
199
  function renderOptions(options) {
198
- return options.map((option, index) => `${index + 1}. ${option.label}${option.description ? ` — ${option.description}` : ''}`).join('\n');
200
+ return options.map((option, index) => {
201
+ const aliases = option.aliases?.length ? `(${option.aliases.join(' / ')})` : '';
202
+ const description = option.description ? ` — ${option.description}` : '';
203
+ return `${index + 1}. ${option.label}${aliases}${description}`;
204
+ }).join('\n');
199
205
  }
200
206
  function resolveOption(options, raw) {
201
207
  const index = Number(raw);
202
208
  if (Number.isInteger(index) && index >= 1 && index <= options.length)
203
209
  return options[index - 1];
204
- const normalized = raw.toLocaleLowerCase();
205
- return options.find((option) => option.label.trim().toLocaleLowerCase() === normalized);
210
+ const normalized = raw.trim().toLocaleLowerCase();
211
+ const matches = (candidate) => candidate.trim().toLocaleLowerCase() === normalized;
212
+ return options.find((option) => matches(option.label))
213
+ ?? options.find((option) => option.aliases?.some(matches));
206
214
  }
207
215
  function uniqueOptions(options) {
208
216
  const result = [];
@@ -211,11 +219,15 @@ function uniqueOptions(options) {
211
219
  result.push(option);
212
220
  return result;
213
221
  }
214
- function parseBoolean(raw) {
215
- const normalized = raw.toLocaleLowerCase();
216
- if (CONFIRM_VALUES.has(normalized))
222
+ function parseBoolean(raw, locale) {
223
+ const normalized = raw.toLowerCase();
224
+ if (normalized === 'true')
225
+ return true;
226
+ if (normalized === 'false')
227
+ return false;
228
+ if (CONFIRM_VALUES[locale].has(normalized))
217
229
  return true;
218
- if (CANCEL_VALUES.has(normalized))
230
+ if (CANCEL_VALUES[locale].has(normalized))
219
231
  return false;
220
232
  return undefined;
221
233
  }
@@ -238,8 +250,8 @@ function validBounds(minimum, maximum) {
238
250
  && (maximum === undefined || Number.isFinite(maximum))
239
251
  && (minimum === undefined || maximum === undefined || minimum <= maximum);
240
252
  }
241
- const CONFIRM_VALUES = new Set(['1', 'y', 'yes', 'true', '是', '确认', '同意']);
242
- const CANCEL_VALUES = new Set(['2', 'n', 'no', 'false', '否', '取消', '拒绝']);
253
+ const CONFIRM_VALUES = { 'zh-CN': new Set(['1', '是', '确认', '同意']), en: new Set(['1', 'y', 'yes', 'true', 'confirm', 'agree']) };
254
+ const CANCEL_VALUES = { 'zh-CN': new Set(['2', '否', '取消', '拒绝']), en: new Set(['2', 'n', 'no', 'false', 'cancel', 'reject']) };
243
255
  function chunk(items, size) {
244
256
  const rows = [];
245
257
  for (let index = 0; index < items.length; index += size)
package/lib/errors.d.ts CHANGED
@@ -1,21 +1,4 @@
1
1
  /**
2
2
  * Re-export generic errors from @zhin.js/kernel
3
3
  */
4
- export { ZhinError, ConfigError, PluginError, ConnectionError, ContextError, ValidationError, PermissionError, TimeoutError, ErrorManager, RetryManager, CircuitBreaker, } from '@zhin.js/kernel';
5
- import { ZhinError } from '@zhin.js/kernel';
6
- /**
7
- * 适配器相关错误
8
- */
9
- export declare class AdapterError extends ZhinError {
10
- readonly adapterName: string;
11
- readonly endpointKey?: string;
12
- constructor(message: string, adapterName: string, endpointKey?: string, context?: Record<string, any>);
13
- }
14
- /**
15
- * 消息处理错误
16
- */
17
- export declare class MessageError extends ZhinError {
18
- readonly messageId?: string;
19
- readonly channelId?: string;
20
- constructor(message: string, messageId?: string, channelId?: string, context?: Record<string, any>);
21
- }
4
+ export { ZhinError } from '@zhin.js/kernel';
package/lib/errors.js CHANGED
@@ -1,29 +1,4 @@
1
1
  /**
2
2
  * Re-export generic errors from @zhin.js/kernel
3
3
  */
4
- export { ZhinError, ConfigError, PluginError, ConnectionError, ContextError, ValidationError, PermissionError, TimeoutError, ErrorManager, RetryManager, CircuitBreaker, } from '@zhin.js/kernel';
5
- import { ZhinError } from '@zhin.js/kernel';
6
- /**
7
- * 适配器相关错误
8
- */
9
- export class AdapterError extends ZhinError {
10
- adapterName;
11
- endpointKey;
12
- constructor(message, adapterName, endpointKey, context) {
13
- super(message, 'ADAPTER_ERROR', { ...context, adapterName, endpointKey });
14
- this.adapterName = adapterName;
15
- this.endpointKey = endpointKey;
16
- }
17
- }
18
- /**
19
- * 消息处理错误
20
- */
21
- export class MessageError extends ZhinError {
22
- messageId;
23
- channelId;
24
- constructor(message, messageId, channelId, context) {
25
- super(message, 'MESSAGE_ERROR', { ...context, messageId, channelId });
26
- this.messageId = messageId;
27
- this.channelId = channelId;
28
- }
29
- }
4
+ export { ZhinError } from '@zhin.js/kernel';
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Command authoring and Root-selected IM presentation contracts.
3
+ * @module zhin.js/command
4
+ */
5
+ export { defineCommand, commandFeedbackToken, commandMenuPresentationToken, type CommandContext, type CommandConversation, type CommandDefiner, type CommandDefinition, type CommandMessage, type CommandParameterDefinition, type CommandParamSchema, type CommandScene, type CommandSegment, type CommandSender, type CommandSession, type CommandDynamicValue, type CommandParameterType, type CommandParameterValue, type CommandExecutionPolicy, type CommandExecutionLimit, type CommandParams, type CommandOptions, type CommandOptionSchema, type InferCommandParams, type InferCommandOptions, type CommandFeedback, type CommandFeedbackContext, type CommandFeedbackRenderer, type CommandMenuPresentationInput, type CommandMenuPresenter, type CommandMenuPage, type CommandMenuNavigation, type CommandMenuEntry, type CommandMenuAppearance, type CommandValidationIssue, } from './command.js';
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Command authoring and Root-selected IM presentation contracts.
3
+ * @module zhin.js/command
4
+ */
5
+ export { defineCommand, commandFeedbackToken, commandMenuPresentationToken, } from './command.js';
@@ -1,2 +1,4 @@
1
1
  /** Authoring API for Command Feature — implementation in `@zhin.js/command`. */
2
2
  export * from '@zhin.js/command';
3
+ export { commandFeedbackToken, commandMenuPresentationToken } from '../plugin-runtime/im/command-feedback.js';
4
+ export type { CommandFeedback, CommandFeedbackContext, CommandFeedbackRenderer, CommandMenuPresentationInput, CommandMenuPresenter } from '../plugin-runtime/im/command-feedback.js';
@@ -1,2 +1,3 @@
1
1
  /** Authoring API for Command Feature — implementation in `@zhin.js/command`. */
2
2
  export * from '@zhin.js/command';
3
+ export { commandFeedbackToken, commandMenuPresentationToken } from '../plugin-runtime/im/command-feedback.js';
@@ -1,2 +1,3 @@
1
1
  /** Authoring API for Component Feature — implementation in `@zhin.js/component`. */
2
2
  export * from '@zhin.js/component';
3
+ export { component, type ComponentCall } from '../plugin-runtime/im/contracts.js';
@@ -1,2 +1,3 @@
1
1
  /** Authoring API for Component Feature — implementation in `@zhin.js/component`. */
2
2
  export * from '@zhin.js/component';
3
+ export { component } from '../plugin-runtime/im/contracts.js';
@@ -1,17 +1,13 @@
1
1
  /** Authoring API for Handler Feature — implementation in `@zhin.js/handler`. */
2
2
  export { parseHandlerDefinition, HandlerIndex, isHandlerIndex, handlerFeatureId, handlerFeature, handlerEventFromLocalName, resolveHandlerEvent, type HandlerEventMap, type HandlerDefinition, type HandlerDescriptor, type HandlerContext, type HandlerDispatchOptions, } from '@zhin.js/handler';
3
3
  import { type HandlerContext, type HandlerDefinition, type HandlerEventMap } from '@zhin.js/handler';
4
- import type { Plugin } from '../plugin.js';
5
4
  import type { Message } from '../plugin-runtime/im/contracts.js';
6
5
  import type { Notice } from '../notice.js';
7
6
  import type { Request } from '../request.js';
8
7
  import type { SystemEvent } from '../system-event.js';
9
8
  import type { AdapterClient, AdapterEvents, EndpointEvent, EndpointIdentity, PlatformEvent, RegisteredAdapterName } from '@zhin.js/adapter';
10
- type KnownKeys<T> = {
11
- [K in keyof T as string extends K ? never : number extends K ? never : K]: T[K];
12
- };
13
9
  declare module '@zhin.js/handler' {
14
- interface HandlerEventMap extends KnownKeys<Omit<Plugin.Lifecycle, 'message.receive' | 'notice.receive' | 'request.receive' | 'system.receive'>> {
10
+ interface HandlerEventMap {
15
11
  'message.receive': [event: EndpointEvent<Message>];
16
12
  'notice.receive': [event: EndpointEvent<Notice>];
17
13
  'request.receive': [event: EndpointEvent<Request>];
@@ -30,7 +26,7 @@ export interface ClientHandlerEvent<TAdapter extends RegisteredAdapterName, TNam
30
26
  export interface ClientHandlerOptions<TAdapter extends RegisteredAdapterName, TName extends NativeEventName<TAdapter>> {
31
27
  readonly adapter: TAdapter;
32
28
  readonly event: TName;
33
- handle(this: HandlerContext, event: ClientHandlerEvent<TAdapter, TName>): void | Promise<void>;
29
+ handle(this: HandlerContext<unknown, TAdapter>, event: ClientHandlerEvent<TAdapter, TName>): void | Promise<void>;
34
30
  }
35
31
  export interface ClientHandlerWildcardEvent<TAdapter extends RegisteredAdapterName> {
36
32
  readonly name: string;
@@ -41,8 +37,18 @@ export interface ClientHandlerWildcardEvent<TAdapter extends RegisteredAdapterNa
41
37
  export interface ClientHandlerWildcardOptions<TAdapter extends RegisteredAdapterName> {
42
38
  readonly adapter: TAdapter;
43
39
  readonly event: '*';
44
- handle(this: HandlerContext, event: ClientHandlerWildcardEvent<TAdapter>): void | Promise<void>;
40
+ handle(this: HandlerContext<unknown, TAdapter>, event: ClientHandlerWildcardEvent<TAdapter>): void | Promise<void>;
45
41
  }
42
+ type CanonicalHandlerEvent = 'message.receive' | 'notice.receive' | 'request.receive' | 'system.receive' | 'platform.receive';
43
+ type BoundCanonicalHandler<K extends CanonicalHandlerEvent> = {
44
+ [A in RegisteredAdapterName]: {
45
+ readonly adapter: A;
46
+ readonly event: K;
47
+ handle(this: HandlerContext<unknown, A>, ...args: HandlerEventMap[K]): void | Promise<void>;
48
+ };
49
+ }[RegisteredAdapterName];
50
+ /** Canonical messages share the captured operation Session; native callbacks retain their original payload. */
51
+ export declare function defineHandler<K extends CanonicalHandlerEvent>(options: BoundCanonicalHandler<K>): Readonly<HandlerDefinition<K>>;
46
52
  export declare function defineHandler<TAdapter extends RegisteredAdapterName, TName extends NativeEventName<TAdapter>>(options: ClientHandlerOptions<TAdapter, TName>): Readonly<HandlerDefinition<'platform.receive'>>;
47
53
  /** Handle every native event from one Client without pretending unknown payloads are typed. */
48
54
  export declare function defineHandler<TAdapter extends RegisteredAdapterName>(options: ClientHandlerWildcardOptions<TAdapter>): Readonly<HandlerDefinition<'platform.receive'>>;
@@ -2,7 +2,8 @@
2
2
  export { parseHandlerDefinition, HandlerIndex, isHandlerIndex, handlerFeatureId, handlerFeature, handlerEventFromLocalName, resolveHandlerEvent, } from '@zhin.js/handler';
3
3
  import { defineHandler as defineHandlerFeature, } from '@zhin.js/handler';
4
4
  export function defineHandler(options) {
5
- if (!('adapter' in options) || typeof options.adapter !== 'string') {
5
+ if (!('adapter' in options) || typeof options.adapter !== 'string'
6
+ || ['message.receive', 'notice.receive', 'request.receive', 'system.receive', 'platform.receive'].includes(options.event ?? '')) {
6
7
  return defineHandlerFeature(options);
7
8
  }
8
9
  const adapter = options.adapter;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Incoming Message and outbound envelope middleware authoring contracts.
3
+ * @module zhin.js/middleware
4
+ */
5
+ export { defineMiddleware, type MiddlewareContext, type MiddlewareContinuation, type MiddlewareDefinition, type MiddlewareDefinitionBase, type MiddlewareNext, type MiddlewarePhase, type MiddlewareTarget, type OutboundMiddlewareNext, } from './middleware.js';
6
+ export { outboundPresentationToken, type OutboundPresentation, type OutboundPresentationContext, type OutboundPresentationMode, type OutboundPresentationPreferences, } from './middleware.js';
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Incoming Message and outbound envelope middleware authoring contracts.
3
+ * @module zhin.js/middleware
4
+ */
5
+ export { defineMiddleware, } from './middleware.js';
6
+ export { outboundPresentationToken, } from './middleware.js';
@@ -1,2 +1,22 @@
1
- /** Authoring API for Middleware Feature — implementation in `@zhin.js/middleware`. */
2
- export * from '@zhin.js/middleware';
1
+ /**
2
+ * IM authoring defaults; the underlying Feature remains transport independent.
3
+ * @module zhin.js/middleware
4
+ */
5
+ export type { MiddlewareContinuation, MiddlewareDefinitionBase, MiddlewareNext, MiddlewarePhase, MiddlewareTarget, OutboundMiddlewareNext, } from '@zhin.js/middleware';
6
+ import { type MiddlewareAuthoringDefinition, type MiddlewareContext as FeatureMiddlewareContext, type MiddlewareDefinition as FeatureMiddlewareDefinition } from '@zhin.js/middleware';
7
+ import type { Message, OutboundEnvelope } from '../plugin-runtime/im/contracts.js';
8
+ export type MiddlewareContext<TInput = Message, TConfig = unknown, TAdapter extends string | undefined = undefined> = FeatureMiddlewareContext<TInput, TConfig, TAdapter>;
9
+ export type MiddlewareDefinition<TInput = Message, TConfig = unknown, TAdapter extends string | undefined = string | undefined> = FeatureMiddlewareDefinition<TInput, TConfig, TAdapter>;
10
+ /** Incoming IM middleware receives Message; outbound middleware receives its envelope. */
11
+ export declare function defineMiddleware<TInput = OutboundEnvelope, TConfig = unknown>(definition: Extract<MiddlewareAuthoringDefinition<TInput, TConfig>, {
12
+ readonly target: 'outbound';
13
+ }>): Readonly<Extract<FeatureMiddlewareDefinition<TInput, TConfig>, {
14
+ readonly target: 'outbound';
15
+ }>>;
16
+ export declare function defineMiddleware<TInput = Message, TConfig = unknown>(definition: Extract<MiddlewareAuthoringDefinition<TInput, TConfig>, {
17
+ readonly target?: 'inbound';
18
+ }>): Readonly<Extract<FeatureMiddlewareDefinition<TInput, TConfig>, {
19
+ readonly target: 'inbound';
20
+ }>>;
21
+ export { outboundPresentationToken } from '../plugin-runtime/im/outbound-renderer.js';
22
+ export type { OutboundPresentation, OutboundPresentationContext, OutboundPresentationMode, OutboundPresentationPreferences, } from '../plugin-runtime/im/outbound-renderer.js';
@@ -1,2 +1,7 @@
1
- /** Authoring API for Middleware Feature — implementation in `@zhin.js/middleware`. */
2
- export * from '@zhin.js/middleware';
1
+ import { defineMiddleware as defineFeatureMiddleware, } from '@zhin.js/middleware';
2
+ export function defineMiddleware(definition) {
3
+ // Both overloads deliberately delegate the same validation and feature brand.
4
+ const define = defineFeatureMiddleware;
5
+ return define(definition);
6
+ }
7
+ export { outboundPresentationToken } from '../plugin-runtime/im/outbound-renderer.js';
package/lib/im-scene.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import type { Message, MessageType } from './message.js';
1
+ import type { MessageType } from './message.js';
2
+ import type { Message } from './plugin-runtime/im/contracts.js';
2
3
  import type { SendContent, SendOptions } from './types.js';
3
4
  export type IMSceneKind = MessageType;
4
5
  /** Parent scene kind (distinct from sub-channel MessageType.channel). */
@@ -23,7 +24,7 @@ export interface IMDeliveryTarget {
23
24
  }
24
25
  /** Normalize legacy parent.type channel → guild. */
25
26
  export declare function normalizeIMSceneParentKind(value: unknown): IMSceneParentKind | undefined;
26
- export declare function sceneRefFromMessage(message: Partial<Message<any>>): IMSceneRef | undefined;
27
+ export declare function sceneRefFromMessage(message: Partial<Message>): IMSceneRef | undefined;
27
28
  export declare function sceneRefToSendOptions(target: IMDeliveryTarget, content: SendContent): SendOptions;
28
29
  export declare function resolveIMSceneSessionId(scene: IMSceneRef): string;
29
- export declare function messageToIMDeliveryTarget(message: Partial<Message<any>>): IMDeliveryTarget | undefined;
30
+ export declare function messageToIMDeliveryTarget(message: Partial<Message>): IMDeliveryTarget | undefined;
package/lib/im-scene.js CHANGED
@@ -11,25 +11,25 @@ export function normalizeIMSceneParentKind(value) {
11
11
  return undefined;
12
12
  }
13
13
  export function sceneRefFromMessage(message) {
14
- const platform = nonEmptyString(message.$adapter);
15
- const endpointKey = nonEmptyString(message.$endpoint);
16
- const kind = message.$channel?.type;
14
+ const platform = nonEmptyString(message.clientAdapter ?? message.conversation?.endpoint.adapter);
15
+ const endpointKey = nonEmptyString(message.endpointId ?? message.conversation?.endpoint.id);
16
+ const kind = message.conversation?.kind;
17
17
  if (!platform || !endpointKey || !kind)
18
18
  return undefined;
19
- const senderId = nonEmptyString(message.$sender?.id);
20
- const channelId = nonEmptyString(message.$channel?.id);
19
+ const senderId = nonEmptyString(message.sender?.id);
20
+ const channelId = nonEmptyString(message.conversation?.id);
21
21
  const sceneId = kind === 'private'
22
22
  ? senderId ?? channelId
23
23
  : channelId ?? senderId;
24
24
  if (!sceneId)
25
25
  return undefined;
26
- const parentKind = message.$channel?.parent
27
- ? normalizeIMSceneParentKind(message.$channel.parent.type)
26
+ const parentKind = message.conversation?.parent
27
+ ? normalizeIMSceneParentKind(message.conversation.parent.kind)
28
28
  : undefined;
29
- const parent = parentKind && message.$channel?.parent
29
+ const parent = parentKind && message.conversation?.parent
30
30
  ? {
31
31
  kind: parentKind,
32
- sceneId: String(message.$channel.parent.id),
32
+ sceneId: String(message.conversation.parent.id),
33
33
  }
34
34
  : undefined;
35
35
  return {