@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
@@ -0,0 +1,478 @@
1
+ import { normalizePlatformStanding } from '@zhin.js/im-contract';
2
+ import { formatCompact, getLogger, truncatePreview } from '@zhin.js/logger';
3
+ import { RuntimeMessage, operationEndpoint, } from './contracts.js';
4
+ import { requireAdapters } from './endpoint-runtime.js';
5
+ import { arbitrateRoomInboundDeduplication, dispatchCanonicalEndpointEvent, dispatchInboundHandlers, dispatchInboundInteractive, handlers, interactionResult, messageLocale, resolveIngressRoute, resolveRoomMembership, runInboundMiddlewareAndSpine, withEndpointEventPayload, } from './inbound-spine.js';
6
+ import { defaultCommandPrefixResolver, MessageDispatcher } from './message-dispatcher.js';
7
+ import { formatConversationLog, previewMessageContent, } from './message-events.js';
8
+ const logger = getLogger('im.inbound');
9
+ /** Owns Endpoint ingress normalization, routing, dispatch, and side-event action scopes. */
10
+ export class InboundRuntime {
11
+ context;
12
+ #dispatcher;
13
+ constructor(context, commandPrefix) {
14
+ this.context = context;
15
+ this.#dispatcher = new MessageDispatcher(commandPrefix === undefined
16
+ ? defaultCommandPrefixResolver
17
+ : () => commandPrefix);
18
+ }
19
+ createInteraction(message, bind) {
20
+ return this.context.interactions.createForMessage(message, bind);
21
+ }
22
+ async receive(event, admission) {
23
+ switch (event.name) {
24
+ case 'message.receive':
25
+ return this.context.diagnostics
26
+ ? this.context.diagnostics.run(() => this.#receiveMessage(event, admission))
27
+ : this.#receiveMessage(event, admission);
28
+ case 'notice.receive':
29
+ return this.#receiveCanonicalEndpointEvent(event);
30
+ case 'request.receive':
31
+ return this.#receiveCanonicalEndpointEvent(event);
32
+ case 'system.receive':
33
+ return this.#receiveCanonicalEndpointEvent(event);
34
+ default:
35
+ return this.#receiveSideEvent(event);
36
+ }
37
+ }
38
+ async #receiveMessage(source, admission) {
39
+ const receivedAt = Date.now();
40
+ const lease = this.context.acquire();
41
+ let active = true;
42
+ let commandOperation;
43
+ let endpointLease;
44
+ try {
45
+ const adapter = source.endpoint.id;
46
+ this.context.diagnostics?.begin(lease.value.generation, {
47
+ ...source.payload.conversation,
48
+ endpoint: { id: source.endpoint.id, adapter: source.endpoint.adapter },
49
+ }, source.payload.message?.id);
50
+ const adapters = requireAdapters(lease.value);
51
+ const requester = adapters.owner(adapter);
52
+ endpointLease = adapters.acquireInbound(adapter, source.client);
53
+ const boundEndpoint = endpointLease;
54
+ const adapterInstance = adapters.adapterForEndpoint(adapter);
55
+ if (!adapterInstance)
56
+ throw new Error('Inbound Endpoint has no owning Adapter');
57
+ const operationSignal = AbortSignal.any([lease.stopSignal, boundEndpoint.signal]);
58
+ // Routing identity belongs to the bound Endpoint, never to a protocol
59
+ // normalizer's payload or a Plugin owner inferred from a CapabilityId.
60
+ const conversation = Object.freeze({ ...source.payload.conversation,
61
+ ...(source.payload.conversation.parent ? { parent: Object.freeze({ ...source.payload.conversation.parent }) } : {}),
62
+ endpoint: Object.freeze({ id: source.endpoint.id, adapter: adapters.clientAdapter(adapter) }),
63
+ });
64
+ const sender = adapterSender(source.payload.sender);
65
+ const { sender: _payloadSender, ...payload } = source.payload;
66
+ const input = Object.freeze({ ...payload, conversation,
67
+ ...(sender ? { sender } : {}),
68
+ ...(source.payload.message ? { message: Object.freeze({ ...source.payload.message, conversation }) } : {}),
69
+ });
70
+ this.context.diagnostics?.identify(conversation);
71
+ logger.debug(formatCompact({
72
+ op: 'receive',
73
+ conv: formatConversationLog(conversation),
74
+ sender: `${input.sender?.name || 'undefined'}(${input.sender?.id || 'undefined'})`,
75
+ preview: truncatePreview(input.content),
76
+ }));
77
+ const enrichedSender = this.context.enrichSender
78
+ ? this.context.enrichSender(input.sender, conversation, lease.value)
79
+ : input.sender;
80
+ // Origin is decided only from trusted state (Registry / ledger / membership port),
81
+ // never from payload metadata or message text.
82
+ const roomMembership = resolveRoomMembership(lease.value);
83
+ const classified = this.context.originClassifier?.classify({
84
+ conversation,
85
+ sender: enrichedSender,
86
+ messageId: input.message?.id,
87
+ content: input.content,
88
+ }, roomMembership);
89
+ const origin = classified?.origin;
90
+ this.context.diagnostics?.step('origin', origin ?? 'unclassified');
91
+ if (origin === 'self') {
92
+ this.context.diagnostics?.route('self_echo');
93
+ logger.debug(formatCompact({
94
+ op: 'self_echo',
95
+ conv: formatConversationLog(conversation),
96
+ basis: classified?.basis,
97
+ }));
98
+ return Object.freeze({ matched: false });
99
+ }
100
+ if (typeof roomMembership?.isRoomReady === 'function') {
101
+ const readiness = roomMembership.isRoomReady({
102
+ platform: conversation.endpoint.adapter,
103
+ sceneType: conversation.kind,
104
+ sceneId: conversation.id,
105
+ ...(conversation.threadId !== undefined ? { threadId: conversation.threadId } : {}),
106
+ });
107
+ if (!readiness.ready) {
108
+ logger.warn(formatCompact({
109
+ op: 'venue_unready',
110
+ conv: formatConversationLog(conversation),
111
+ unreadyEndpoints: readiness.unreadyEndpoints?.join(',') ?? '',
112
+ reason: 'Venue member endpoints have not reported selfUserId yet',
113
+ }));
114
+ return Object.freeze({ matched: false });
115
+ }
116
+ }
117
+ const { recordOnly, routedTarget } = await arbitrateRoomInboundDeduplication({
118
+ origin,
119
+ deduper: this.context.deduper,
120
+ roomMembership,
121
+ conversation,
122
+ enrichedSender,
123
+ incoming: input,
124
+ routeRequest: {
125
+ conversation,
126
+ senderId: String(enrichedSender?.id ?? ''),
127
+ input,
128
+ adapters,
129
+ generation: lease.value.generation,
130
+ interactions: this.context.interactions,
131
+ registry: this.context.registry,
132
+ inboundClaimPending: this.context.inboundClaimPending,
133
+ resolveReplyTarget: this.context.resolveReplyTarget,
134
+ },
135
+ });
136
+ const mentioned = routedTarget ? true : input.mentioned;
137
+ const locale = await messageLocale(lease.value, conversation, enrichedSender?.id);
138
+ let operationReplied = false;
139
+ const operationReply = (content, replyRequester = requester, targetConversation) => {
140
+ if (!active)
141
+ throw new Error('Message reply scope has ended');
142
+ boundEndpoint.assertActive();
143
+ operationReplied = true;
144
+ const effectiveConversation = targetConversation
145
+ ? { ...targetConversation, endpoint: conversation.endpoint }
146
+ : conversation;
147
+ const deliver = () => this.context.deliver({
148
+ conversation: effectiveConversation,
149
+ [operationEndpoint]: boundEndpoint,
150
+ requester: replyRequester,
151
+ locale,
152
+ content,
153
+ incoming: {
154
+ sender: enrichedSender,
155
+ content: input.content,
156
+ segments: input.segments,
157
+ messageId: input.message?.id,
158
+ timestamp: receivedAt,
159
+ endpointId: input.endpointId,
160
+ mentioned,
161
+ },
162
+ }, lease.value);
163
+ // A held Message may reply from another async caller while its operation is
164
+ // draining. Restore that Message's private controller, not the caller's scope.
165
+ return commandOperation && this.context.runCommandOperation
166
+ ? this.context.runCommandOperation(commandOperation, deliver) : deliver();
167
+ };
168
+ commandOperation = this.context.commandExecution?.openOperation({
169
+ snapshot: lease.value, conversation, senderId: enrichedSender?.id,
170
+ retirementSignal: operationSignal, locale, reply: (owner, text) => operationReply(text, owner),
171
+ });
172
+ const execute = async () => {
173
+ const segments = input.segments ? Object.freeze([...input.segments]) : undefined;
174
+ const message = new RuntimeMessage({
175
+ conversation,
176
+ content: input.content,
177
+ sender: enrichedSender,
178
+ metadata: Object.freeze({ ...input.metadata }),
179
+ segments,
180
+ message: input.message,
181
+ endpointId: input.endpointId,
182
+ mentioned,
183
+ replyTo: input.replyTo,
184
+ }, {
185
+ generation: lease.value.generation,
186
+ reply: operationReply,
187
+ client: () => {
188
+ if (!active)
189
+ throw new Error('Message Client scope has ended');
190
+ boundEndpoint.assertActive();
191
+ return source.client;
192
+ },
193
+ clientAdapter: adapters.clientAdapter(adapter),
194
+ snapshot: lease.value,
195
+ signal: operationSignal,
196
+ session: {
197
+ adapter: adapterInstance,
198
+ endpoint: boundEndpoint.endpoint,
199
+ adapterName: adapters.clientAdapter(adapter),
200
+ scene: conversation,
201
+ event: input.event,
202
+ signal: operationSignal,
203
+ ...(enrichedSender
204
+ ? {
205
+ sender: Object.freeze({
206
+ id: enrichedSender.id,
207
+ ...(enrichedSender.name !== undefined ? { name: enrichedSender.name } : {}),
208
+ ...(enrichedSender.platform ? { platform: enrichedSender.platform } : {}),
209
+ ...(enrichedSender.chatRole ? { chatRole: enrichedSender.chatRole } : {}),
210
+ ...(enrichedSender.chatRoleLevels ? { chatRoleLevels: enrichedSender.chatRoleLevels } : {}),
211
+ }),
212
+ }
213
+ : {}),
214
+ message: Object.freeze({
215
+ text: input.content,
216
+ receivedAt,
217
+ ...(input.message ? { id: input.message.id, ref: input.message } : {}),
218
+ ...(segments ? { segments } : {}),
219
+ ...(input.platformSentAt !== undefined ? { platformSentAt: input.platformSentAt } : {}),
220
+ ...(mentioned !== undefined ? { mentioned } : {}),
221
+ ...(input.replyTo ? { replyTo: Object.freeze({ ...input.replyTo }) } : {}),
222
+ }),
223
+ },
224
+ captureInteraction: owner => this.context.captureOperation({ target: conversation,
225
+ client: source.client, requester: owner, signal: boundEndpoint.signal }),
226
+ registerOperationView: commandOperation?.bind,
227
+ createOperationResources: request => this.context.createOperationResources?.({ ...request, lease }),
228
+ assertActive: () => {
229
+ if (!active)
230
+ throw new Error('Message author binding scope has ended');
231
+ boundEndpoint.assertActive();
232
+ },
233
+ ...(origin ? { origin } : {}),
234
+ presentation: {
235
+ locale,
236
+ resolveCommands: (message) => this.#dispatcher.commandEnvironment(message, lease.value),
237
+ },
238
+ });
239
+ const conversationSequence = await this.context.recordIncoming(input, enrichedSender);
240
+ let result = Object.freeze({ matched: false });
241
+ let reply;
242
+ if (recordOnly === 'duplicate') {
243
+ this.context.diagnostics?.route('duplicate');
244
+ logger.debug(formatCompact({
245
+ op: 'inbound_duplicate',
246
+ conv: formatConversationLog(conversation),
247
+ basis: recordOnly,
248
+ }));
249
+ return result;
250
+ }
251
+ if (recordOnly === 'dedup_error') {
252
+ this.context.diagnostics?.route('dedup_error');
253
+ this.context.publish({
254
+ direction: 'inbound',
255
+ conversation,
256
+ ...(enrichedSender !== undefined ? { sender: enrichedSender } : {}),
257
+ contentPreview: previewMessageContent(input.content),
258
+ ...(input.message?.id ? { messageId: input.message.id } : {}),
259
+ timestamp: receivedAt,
260
+ });
261
+ return result;
262
+ }
263
+ if (origin === 'member' || origin === 'peer_bot') {
264
+ this.context.diagnostics?.route('bot_origin');
265
+ logger.debug(formatCompact({
266
+ op: 'bot_origin_recorded',
267
+ conv: formatConversationLog(conversation),
268
+ origin,
269
+ basis: classified?.basis,
270
+ }));
271
+ this.context.publish({
272
+ direction: 'inbound',
273
+ conversation,
274
+ ...(enrichedSender !== undefined ? { sender: enrichedSender } : {}),
275
+ contentPreview: previewMessageContent(input.content),
276
+ ...(input.message?.id ? { messageId: input.message.id } : {}),
277
+ timestamp: receivedAt,
278
+ });
279
+ return result;
280
+ }
281
+ const claimed = await this.context.inboundClaim?.(message) === true;
282
+ if (claimed) {
283
+ this.context.diagnostics?.route('interaction');
284
+ result = interactionResult(requester);
285
+ }
286
+ else if (this.context.interactions.resolveClaim(message)) {
287
+ this.context.diagnostics?.route('interaction');
288
+ if (input.message)
289
+ this.context.markInteractionAnswer?.(input.message);
290
+ result = interactionResult(requester);
291
+ }
292
+ else {
293
+ const interactionFactory = (value) => this.context.interactions.createFromUnknown(value);
294
+ const outcome = await runInboundMiddlewareAndSpine({
295
+ message,
296
+ lease,
297
+ requester,
298
+ conversationSequence,
299
+ admission,
300
+ signal: operationSignal,
301
+ interactionFactory,
302
+ ingressRoute: resolveIngressRoute(lease.value),
303
+ diagnostics: this.context.diagnostics,
304
+ runHandlers: () => dispatchInboundHandlers({
305
+ lease,
306
+ event: 'message.receive',
307
+ args: [withEndpointEventPayload(source, message)],
308
+ signal: operationSignal,
309
+ interactions: this.context.interactions,
310
+ deliver: (req, snap) => this.context.deliver(req, snap),
311
+ }),
312
+ dispatchInteractive: () => dispatchInboundInteractive({
313
+ message,
314
+ requester,
315
+ admission,
316
+ snapshot: lease.value,
317
+ interactions: this.context.interactions,
318
+ }),
319
+ dispatchCommand: (observe) => this.#dispatcher.dispatchWithReply(message, lease.value, interactionFactory, observe),
320
+ hasReplied: () => operationReplied,
321
+ findEventHandlerName: (event) => handlers(lease.value)?.list().find(descriptor => descriptor.event === event)?.name,
322
+ }, this.context.diagnostics);
323
+ result = outcome.dispatch;
324
+ reply = outcome.reply;
325
+ }
326
+ this.context.diagnostics?.dispatch(result);
327
+ await commandOperation?.stopProgress();
328
+ if (reply)
329
+ await message.$replyFrom(reply.owner, reply.content);
330
+ if (result.matched) {
331
+ logger.debug(formatCompact({
332
+ op: 'dispatched',
333
+ conv: formatConversationLog(conversation),
334
+ command: result.command,
335
+ }));
336
+ }
337
+ this.context.publish({
338
+ direction: 'inbound',
339
+ conversation,
340
+ ...(enrichedSender !== undefined ? { sender: enrichedSender } : {}),
341
+ contentPreview: previewMessageContent(input.content),
342
+ ...(input.message?.id ? { messageId: input.message.id } : {}),
343
+ timestamp: receivedAt,
344
+ });
345
+ return result;
346
+ };
347
+ return commandOperation && this.context.runCommandOperation
348
+ ? await this.context.runCommandOperation(commandOperation, execute) : await execute();
349
+ }
350
+ finally {
351
+ try {
352
+ await commandOperation?.finish();
353
+ }
354
+ finally {
355
+ active = false;
356
+ try {
357
+ endpointLease?.release();
358
+ }
359
+ finally {
360
+ this.context.release(lease);
361
+ }
362
+ }
363
+ }
364
+ }
365
+ async #receiveCanonicalEndpointEvent(source) {
366
+ const lease = this.context.acquire();
367
+ let active = true;
368
+ let endpointLease;
369
+ try {
370
+ const adapters = requireAdapters(lease.value);
371
+ endpointLease = adapters.acquireInbound(source.endpoint.id, source.client);
372
+ const captured = endpointLease;
373
+ const operationSignal = AbortSignal.any([lease.stopSignal, captured.signal]);
374
+ const assertActive = () => {
375
+ if (!active)
376
+ throw new Error('Endpoint event context expired with its generation operation');
377
+ captured.assertActive();
378
+ };
379
+ const context = {
380
+ endpoint: {
381
+ id: source.endpoint.id,
382
+ adapter: adapters.clientAdapter(source.endpoint.id),
383
+ },
384
+ generation: lease.value.generation,
385
+ client: () => {
386
+ assertActive();
387
+ return source.client;
388
+ },
389
+ };
390
+ const dispatch = async (payload) => {
391
+ await dispatchInboundHandlers({
392
+ lease,
393
+ event: source.name,
394
+ args: [withEndpointEventPayload(source, payload)],
395
+ signal: operationSignal,
396
+ interactions: this.context.interactions,
397
+ deliver: (req, snap) => this.context.deliver(req, snap),
398
+ captureInteraction: (owner, conversation) => {
399
+ assertActive();
400
+ return this.context.captureOperation({ target: conversation, client: source.client, requester: owner, signal: captured.signal });
401
+ },
402
+ });
403
+ };
404
+ await dispatchCanonicalEndpointEvent({
405
+ source,
406
+ context,
407
+ assertActive,
408
+ recordNotice: (notice) => this.context.recordNotice(notice),
409
+ recordRequest: this.context.recordRequest ? (req) => this.context.recordRequest(req) : undefined,
410
+ dispatch,
411
+ });
412
+ }
413
+ finally {
414
+ active = false;
415
+ try {
416
+ endpointLease?.release();
417
+ }
418
+ finally {
419
+ this.context.release(lease);
420
+ }
421
+ }
422
+ }
423
+ async #receiveSideEvent(event) {
424
+ let active = true;
425
+ const lease = this.context.acquire();
426
+ let endpointLease;
427
+ try {
428
+ endpointLease = requireAdapters(lease.value).acquireInbound(event.endpoint.id, event.client);
429
+ const captured = endpointLease;
430
+ const signal = AbortSignal.any([lease.stopSignal, captured.signal]);
431
+ const assertActive = () => {
432
+ if (!active)
433
+ throw new Error('Endpoint event context expired with its generation operation');
434
+ captured.assertActive();
435
+ };
436
+ await dispatchInboundHandlers({
437
+ lease,
438
+ event: event.name,
439
+ args: [withEndpointEventPayload(event, event.payload)],
440
+ signal,
441
+ interactions: this.context.interactions,
442
+ deliver: (req, snap) => this.context.deliver(req, snap),
443
+ captureInteraction: (owner, conversation) => {
444
+ assertActive();
445
+ return this.context.captureOperation({
446
+ target: conversation,
447
+ client: event.client,
448
+ requester: owner,
449
+ signal: captured.signal,
450
+ });
451
+ },
452
+ });
453
+ }
454
+ finally {
455
+ active = false;
456
+ try {
457
+ endpointLease?.release();
458
+ }
459
+ finally {
460
+ this.context.release(lease);
461
+ }
462
+ }
463
+ }
464
+ }
465
+ /**
466
+ * ADR 0056 §1: an Adapter reports `id`, `name` and the normalized `platform` standing only. Any
467
+ * payload `chatRole` / `chatRoleLevels` is dropped here; only the sender enricher sets them.
468
+ */
469
+ function adapterSender(sender) {
470
+ if (!sender || typeof sender !== 'object' || typeof sender.id !== 'string')
471
+ return sender;
472
+ const platform = normalizePlatformStanding(sender.platform);
473
+ return Object.freeze({
474
+ id: sender.id,
475
+ ...(sender.name !== undefined ? { name: sender.name } : {}),
476
+ ...(platform ? { platform } : {}),
477
+ });
478
+ }
@@ -0,0 +1,196 @@
1
+ import type { EndpointEvent } from '@zhin.js/adapter';
2
+ import type { ConversationRef, DeliveryReceipt, UserInteraction, UserInteractionFactory } from '@zhin.js/im-contract';
3
+ import { type InboundTerminalControl } from '@zhin.js/middleware';
4
+ import { type GenerationAdmissionGate, type Locale, type PluginId, type RuntimeSnapshot, type SnapshotLease } from '@zhin.js/plugin-runtime';
5
+ import { HandlerIndex } from '../../feature/handler.js';
6
+ import { type IncomingNotice, type Notice } from '../../notice.js';
7
+ import { type IncomingRequest, type Request } from '../../request.js';
8
+ import type { EndpointEventContext } from '../../side-event/base.js';
9
+ import { type IncomingSystemEvent, type SystemEvent } from '../../system-event.js';
10
+ import { type CapturedEndpointOperation, type Message, type MessageDispatchResult, type SendContent, type SendRequest } from './contracts.js';
11
+ import type { RuntimeInteractionCoordinator } from './interaction-runtime.js';
12
+ import type { RuntimeMessageDiagnostics } from './message-diagnostics.js';
13
+ import type { MessageDispatchOutcome } from './message-dispatcher.js';
14
+ export { arbitrateRoomInboundDeduplication, buildRoomInboundRouteInput, resolveRoomMembership, type InboundRoomRouteRequest, } from './inbound-dedup.js';
15
+ /** Generation-owned hooks before ordinary dispatch and after it misses. */
16
+ export interface IngressRoute {
17
+ preRoute?(message: Message, lease: SnapshotLease, requester: PluginId, conversationSequence: number | undefined): Promise<boolean>;
18
+ shouldRouteBeforeDispatch?(message: Message): boolean;
19
+ route(message: Message, lease: SnapshotLease, requester: PluginId, conversationSequence: number | undefined): Promise<boolean>;
20
+ }
21
+ export declare const ingressRouteToken: import("@zhin.js/plugin-runtime").Token<IngressRoute>;
22
+ export declare function resolveIngressRoute(snapshot: RuntimeSnapshot): IngressRoute | undefined;
23
+ /**
24
+ * 群管违规上报(ADR 0039 §5,切片 E)。
25
+ *
26
+ * content-moderation 等插件只负责「判定违规」,「判定后做什么」交给 Agent host 的群规执行器:
27
+ * 按该群生效规则的阶梯执行提醒 / 警告 / 禁言(以规则批准作硬闸批准)/ 建议踢人(每次人批出卡)。
28
+ * Agent host 在根作用域提供本 token;未装 Agent(没有本资源)时插件只能提醒 / 警告,不能禁言或踢人。
29
+ */
30
+ /** 插件可上报的违规类型(`flood` 由宿主本地检测,不经插件)。 @public */
31
+ export type GroupRuleViolationTrigger = 'advertising' | 'abuse';
32
+ /** @public */
33
+ export interface GroupRuleViolationReport {
34
+ /** Runtime-only authority captured from the actual incoming Client; never persist this object. */
35
+ readonly source: Readonly<{
36
+ client: unknown;
37
+ signal: AbortSignal;
38
+ }>;
39
+ /** 违规消息所在的群会话(`kind` 必须是 `group`)。 */
40
+ readonly conversation: ConversationRef;
41
+ readonly memberId: string;
42
+ readonly memberName?: string;
43
+ /** 违规者在本会话的 zhin 聊天角色(ADR 0056;`owner` 按群规豁免)。 */
44
+ readonly memberChatRole?: 'owner' | 'admin' | 'trusted';
45
+ /** 违规者的平台身份(ADR 0056 §1;群主 / 管理员按群规豁免)。 */
46
+ readonly memberPlatform?: import('@zhin.js/im-contract').PlatformStanding;
47
+ readonly trigger: GroupRuleViolationTrigger;
48
+ /** 原消息发出时间(毫秒)。 */
49
+ readonly sentAt: number;
50
+ readonly messageId?: string;
51
+ /** 命中证据(原文摘录)。 */
52
+ readonly evidence?: readonly string[];
53
+ /**
54
+ * 入群不久即发广告:不按阶梯,直接出一张踢人审批卡(每次人批,绝不自动踢)。
55
+ * 只对 `advertising` 生效。
56
+ */
57
+ readonly newcomer?: boolean;
58
+ /** `remind` / `warn` 档的附加动作:撤回原消息(调用方绑定到这条原消息)。 */
59
+ readonly recall?: () => Promise<void>;
60
+ }
61
+ /**
62
+ * `handled`:执行器已按规则处理(含被控制面 / 豁免 / 冷却跳过),调用方不得再自行提醒或处罚。
63
+ * `no_rule`:该群该类型没有可用规则,调用方可退回只提醒 / 警告。
64
+ * @public
65
+ */
66
+ export type GroupRuleViolationOutcome = 'handled' | 'no_rule';
67
+ /** 迁移结果:`created` 新建了待确认规则;`exists` 该群该类型已有规则(任意状态);`unavailable` 规则存储不可用。 @public */
68
+ export type GroupRuleDefaultOutcome = 'created' | 'exists' | 'unavailable';
69
+ /** @public */
70
+ export interface GroupRuleViolationSink {
71
+ report(violation: GroupRuleViolationReport): Promise<GroupRuleViolationOutcome>;
72
+ /**
73
+ * 迁移:该群该类型还没有任何规则时,按默认模板(提醒 → 警告 → 禁言 600 秒,冷静期 30 分钟)
74
+ * 生成一条 `pending` 规则并在群里出预览卡,等群主 / 管理员确认一次。已有任意状态的规则则不动。
75
+ */
76
+ ensureDefaultRule(input: Readonly<{
77
+ conversation: ConversationRef;
78
+ trigger: GroupRuleViolationTrigger;
79
+ }>): Promise<GroupRuleDefaultOutcome>;
80
+ }
81
+ /** @public */
82
+ export declare const groupRuleViolationToken: import("@zhin.js/plugin-runtime").Token<GroupRuleViolationSink>;
83
+ /**
84
+ * 入群欢迎归属(#1012 A9 方案②)。
85
+ *
86
+ * Agent 会话级欢迎(ADR 0037 切片 A,session-ops `welcome.enabled` + MemberLifecycle)由 Agent host 在根作用域提供本 token。
87
+ * 插件里的旧欢迎(如 group-suite `welcomeMessage`)发送前先问归属:已被会话级欢迎接管的会话,插件不再发送,
88
+ * 欢迎统一走 MemberLifecycle(合并窗口、小时上限、控制面、session-gate),避免同一次入群双发。
89
+ * 未装 Agent(没有本资源)时插件保持原行为。
90
+ */
91
+ /** @public */
92
+ export interface MemberWelcomeOwner {
93
+ /** 该会话的入群欢迎是否已由会话级欢迎接管(session-ops `welcome.enabled`)。只读内存,不发送、不写审计。 */
94
+ ownsWelcome(conversation: ConversationRef): boolean;
95
+ }
96
+ /** @public */
97
+ export declare const memberWelcomeOwnerToken: import("@zhin.js/plugin-runtime").Token<MemberWelcomeOwner>;
98
+ /** Runs the generation-owned middleware projection or the terminal directly. */
99
+ export declare function runRuntimeMiddleware<TInput>(snapshot: RuntimeSnapshot, input: TInput, terminal: () => Promise<void>, target: 'inbound' | 'outbound'): Promise<void>;
100
+ /** Legacy outbound middleware sees one complete reply unless its author explicitly supports revisions. */
101
+ export declare function supportsIncrementalOutbound(snapshot: RuntimeSnapshot, adapter: string): boolean;
102
+ export declare function projectLocale(snapshot: RuntimeSnapshot): Locale;
103
+ /** Resolve once per operation; callbacks retain the original operation's language. */
104
+ export declare function messageLocale(snapshot: RuntimeSnapshot, conversation: Pick<ConversationRef, 'endpoint'>, senderId?: string): Promise<Locale>;
105
+ export type InboundSpineStage = 'pre-route' | 'before-dispatch-route' | 'handlers' | 'interactive' | 'command' | 'agent-ingress' | 'none';
106
+ export type InboundCommandObserve = (stage: 'prefix' | 'dispatch', status: 'mismatch' | 'matched' | 'empty_input' | 'commands_unavailable' | 'started') => void;
107
+ export interface InboundTurnRecord {
108
+ readonly turnId: string;
109
+ readonly conversation: Message['conversation'];
110
+ readonly senderId?: string;
111
+ readonly stage: InboundSpineStage;
112
+ readonly matched: boolean;
113
+ readonly command?: string;
114
+ readonly owner?: PluginId;
115
+ readonly replied: boolean;
116
+ readonly durationMs: number;
117
+ }
118
+ export interface InboundTurnEnvelope {
119
+ readonly turnId?: string;
120
+ readonly message: Message;
121
+ readonly lease: SnapshotLease;
122
+ readonly requester: PluginId;
123
+ readonly conversationSequence: number | undefined;
124
+ readonly admission?: GenerationAdmissionGate;
125
+ readonly signal?: AbortSignal;
126
+ readonly interactionFactory?: UserInteractionFactory;
127
+ readonly ingressRoute?: IngressRoute;
128
+ readonly diagnostics?: Pick<RuntimeMessageDiagnostics, 'route' | 'step'>;
129
+ readonly onTurnComplete?: (record: InboundTurnRecord) => void | Promise<void>;
130
+ runHandlers(): Promise<void>;
131
+ dispatchInteractive(): Promise<MessageDispatchResult | undefined>;
132
+ dispatchCommand(observe: InboundCommandObserve): Promise<MessageDispatchOutcome>;
133
+ hasReplied(): boolean;
134
+ findEventHandlerName?(event: string): string | undefined;
135
+ }
136
+ export interface InboundSpineOutcome {
137
+ readonly dispatch: MessageDispatchResult;
138
+ readonly stage: InboundSpineStage;
139
+ readonly record: InboundTurnRecord;
140
+ readonly reply?: {
141
+ readonly owner: PluginId;
142
+ readonly content: SendContent;
143
+ };
144
+ }
145
+ export declare function executeInboundTurnSpine(envelope: InboundTurnEnvelope, control?: InboundTerminalControl): Promise<InboundSpineOutcome>;
146
+ export type InboundInteractionPort = Pick<RuntimeInteractionCoordinator<GenerationAdmissionGate>, 'create' | 'createForMessage' | 'createFromUnknown' | 'dispatch' | 'resolveClaim'> & Partial<Pick<RuntimeInteractionCoordinator<GenerationAdmissionGate>, 'hasPendingAnswer'>>;
147
+ export interface InboundOutcome {
148
+ readonly dispatch: MessageDispatchResult;
149
+ readonly reply?: {
150
+ readonly owner: PluginId;
151
+ readonly content: SendContent;
152
+ };
153
+ }
154
+ /** Native arguments and cancellation belong to the same already-admitted Root operation. */
155
+ export interface InboundHandlerDispatch {
156
+ readonly lease: SnapshotLease;
157
+ readonly event: string;
158
+ readonly args: readonly unknown[];
159
+ readonly signal?: AbortSignal;
160
+ readonly interactions: InboundInteractionPort;
161
+ readonly deliver: (request: SendRequest, snapshot: RuntimeSnapshot) => Promise<DeliveryReceipt>;
162
+ readonly captureInteraction?: (owner: PluginId, conversation: ConversationRef) => CapturedEndpointOperation;
163
+ }
164
+ /** A side-event interaction uses its admitted author's exact snapshot and cancellation. */
165
+ export interface InboundSideInteractionRequest {
166
+ readonly payload: Notice | Request;
167
+ readonly snapshot: RuntimeSnapshot;
168
+ readonly requester: PluginId;
169
+ readonly signal: AbortSignal;
170
+ readonly interactions: InboundInteractionPort;
171
+ readonly deliver: (request: SendRequest, snapshot: RuntimeSnapshot) => Promise<DeliveryReceipt>;
172
+ readonly retain?: () => CapturedEndpointOperation;
173
+ }
174
+ export interface InboundInteractiveDispatch {
175
+ readonly message: Message;
176
+ readonly requester: PluginId;
177
+ readonly admission?: GenerationAdmissionGate;
178
+ readonly snapshot: RuntimeSnapshot;
179
+ readonly interactions: InboundInteractionPort;
180
+ }
181
+ export declare function runInboundMiddlewareAndSpine(envelope: InboundTurnEnvelope, diagnostics?: RuntimeMessageDiagnostics): Promise<InboundOutcome>;
182
+ export declare function dispatchInboundHandlers({ lease, event, args, signal, interactions, deliver, captureInteraction, }: InboundHandlerDispatch): Promise<void>;
183
+ export declare function createInteractionForSideEvent({ payload, snapshot, requester, signal, interactions, deliver, retain, }: InboundSideInteractionRequest): UserInteraction | undefined;
184
+ export declare function dispatchInboundInteractive({ message, requester, admission, snapshot, interactions, }: InboundInteractiveDispatch): Promise<MessageDispatchResult | undefined>;
185
+ export declare function dispatchCanonicalEndpointEvent(input: {
186
+ readonly source: EndpointEvent<IncomingNotice | IncomingRequest | IncomingSystemEvent>;
187
+ readonly context: EndpointEventContext;
188
+ readonly assertActive: () => void;
189
+ readonly recordNotice: (notice: Notice) => Promise<unknown>;
190
+ readonly recordRequest?: (request: Request) => Promise<unknown>;
191
+ readonly dispatch: (payload: Notice | Request | SystemEvent) => Promise<void>;
192
+ }): Promise<void>;
193
+ export declare function interactionResult(requester: PluginId): MessageDispatchResult;
194
+ export declare function withRequestActionScope(request: IncomingRequest, dispatch: (request: IncomingRequest) => Promise<void>, assertOperation: () => void): Promise<void>;
195
+ export declare function handlers(snapshot: RuntimeSnapshot): HandlerIndex | undefined;
196
+ export declare function withEndpointEventPayload<TPayload, TClient, TName extends string>(source: EndpointEvent<unknown, TClient, TName>, payload: TPayload): EndpointEvent<TPayload, TClient, TName>;