@zhin.js/core 1.1.34 → 1.1.35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (386) hide show
  1. package/README.md +121 -65
  2. package/lib/adapter.d.ts +72 -23
  3. package/lib/adapter.js +222 -62
  4. package/lib/built/adapter-process.d.ts +20 -5
  5. package/lib/built/adapter-process.js +54 -7
  6. package/lib/built/agent-preset.d.ts +1 -2
  7. package/lib/built/agent-preset.js +1 -2
  8. package/lib/built/ai-access.d.ts +36 -0
  9. package/lib/built/ai-access.js +46 -0
  10. package/lib/built/ai-outbound/adapter-access.d.ts +3 -0
  11. package/lib/built/ai-outbound/adapter-access.js +9 -0
  12. package/lib/built/ai-outbound/extensions/onebot-keyboard.d.ts +2 -0
  13. package/lib/built/ai-outbound/extensions/onebot-keyboard.js +67 -0
  14. package/lib/built/ai-outbound/extensions/qq-message.d.ts +3 -0
  15. package/lib/built/ai-outbound/extensions/qq-message.js +23 -0
  16. package/lib/built/ai-outbound/index.d.ts +9 -0
  17. package/lib/built/ai-outbound/index.js +9 -0
  18. package/lib/built/ai-outbound/parse.d.ts +13 -0
  19. package/lib/built/ai-outbound/parse.js +104 -0
  20. package/lib/built/ai-outbound/plain-mention-rewrite.d.ts +6 -0
  21. package/lib/built/ai-outbound/plain-mention-rewrite.js +37 -0
  22. package/lib/built/ai-outbound/prompt.d.ts +11 -0
  23. package/lib/built/ai-outbound/prompt.js +44 -0
  24. package/lib/built/ai-outbound/resolve.d.ts +4 -0
  25. package/lib/built/ai-outbound/resolve.js +64 -0
  26. package/lib/built/ai-outbound/structured-detect.d.ts +3 -0
  27. package/lib/built/ai-outbound/structured-detect.js +6 -0
  28. package/lib/built/ai-outbound/types.d.ts +58 -0
  29. package/lib/built/ai-outbound/types.js +5 -0
  30. package/lib/built/ai-trigger.d.ts +17 -17
  31. package/lib/built/ai-trigger.js +65 -70
  32. package/lib/built/authorization.d.ts +10 -0
  33. package/lib/built/authorization.js +76 -0
  34. package/lib/built/command.d.ts +9 -5
  35. package/lib/built/command.js +20 -7
  36. package/lib/built/common-adapter-tools.d.ts +35 -29
  37. package/lib/built/common-adapter-tools.js +83 -67
  38. package/lib/built/component.d.ts +1 -3
  39. package/lib/built/component.js +2 -4
  40. package/lib/built/config.d.ts +4 -5
  41. package/lib/built/config.js +26 -9
  42. package/lib/built/connect-endpoint-instance.d.ts +17 -0
  43. package/lib/built/connect-endpoint-instance.js +42 -0
  44. package/lib/built/database.d.ts +5 -3
  45. package/lib/built/database.js +10 -4
  46. package/lib/built/dispatcher.d.ts +10 -8
  47. package/lib/built/dispatcher.js +31 -9
  48. package/lib/built/endpoint-commands.d.ts +3 -0
  49. package/lib/built/endpoint-commands.js +99 -0
  50. package/lib/built/endpoint-lifecycle-service.d.ts +28 -0
  51. package/lib/built/endpoint-lifecycle-service.js +242 -0
  52. package/lib/built/endpoint-lifecycle.d.ts +27 -0
  53. package/lib/built/endpoint-lifecycle.js +36 -0
  54. package/lib/built/endpoint-manager.d.ts +34 -0
  55. package/lib/built/endpoint-manager.js +1 -0
  56. package/lib/built/generated-qrcode.d.ts +24 -0
  57. package/lib/built/generated-qrcode.js +45 -0
  58. package/lib/built/generic-segment-mapper.d.ts +4 -0
  59. package/lib/built/generic-segment-mapper.js +190 -0
  60. package/lib/built/html-renderer-loader.d.ts +13 -0
  61. package/lib/built/html-renderer-loader.js +33 -0
  62. package/lib/built/html-segment-fallback.d.ts +2 -2
  63. package/lib/built/html-segment-fallback.js +0 -1
  64. package/lib/built/html-to-text.d.ts +0 -1
  65. package/lib/built/html-to-text.js +15 -15
  66. package/lib/built/inbound-pipeline.d.ts +37 -0
  67. package/lib/built/inbound-pipeline.js +63 -0
  68. package/lib/built/inbound-runner.d.ts +0 -1
  69. package/lib/built/inbound-runner.js +0 -3
  70. package/lib/built/interactive-segment-contract.d.ts +6 -0
  71. package/lib/built/interactive-segment-contract.js +9 -0
  72. package/lib/built/interactive-segments/action.d.ts +17 -0
  73. package/lib/built/interactive-segments/action.js +69 -0
  74. package/lib/built/interactive-segments/button-spec.d.ts +10 -0
  75. package/lib/built/interactive-segments/button-spec.js +21 -0
  76. package/lib/built/interactive-segments/fallback-store.d.ts +29 -0
  77. package/lib/built/interactive-segments/fallback-store.js +63 -0
  78. package/lib/built/interactive-segments/handlers.d.ts +16 -0
  79. package/lib/built/interactive-segments/handlers.js +74 -0
  80. package/lib/built/interactive-segments/index.d.ts +8 -0
  81. package/lib/built/interactive-segments/index.js +8 -0
  82. package/lib/built/interactive-segments/keyboard-segment.d.ts +11 -0
  83. package/lib/built/interactive-segments/keyboard-segment.js +12 -0
  84. package/lib/built/interactive-segments/onebot-keyboard.d.ts +7 -0
  85. package/lib/built/interactive-segments/onebot-keyboard.js +51 -0
  86. package/lib/built/interactive-segments/resolve.d.ts +15 -0
  87. package/lib/built/interactive-segments/resolve.js +110 -0
  88. package/lib/built/interactive-segments/types.d.ts +50 -0
  89. package/lib/built/interactive-segments/types.js +9 -0
  90. package/lib/built/introspection-format.d.ts +10 -0
  91. package/lib/built/introspection-format.js +28 -0
  92. package/lib/built/login-assist.d.ts +43 -9
  93. package/lib/built/login-assist.js +113 -11
  94. package/lib/built/management-command-guard.d.ts +15 -0
  95. package/lib/built/management-command-guard.js +25 -0
  96. package/lib/built/message-enrich.d.ts +38 -0
  97. package/lib/built/message-enrich.js +75 -0
  98. package/lib/built/message-filter.d.ts +4 -5
  99. package/lib/built/message-filter.js +5 -7
  100. package/lib/built/optional-peer-import.d.ts +3 -0
  101. package/lib/built/optional-peer-import.js +33 -0
  102. package/lib/built/outbound-media-contract.d.ts +22 -0
  103. package/lib/built/outbound-media-contract.js +10 -0
  104. package/lib/built/outbound-media-utils.d.ts +9 -0
  105. package/lib/built/outbound-media-utils.js +62 -0
  106. package/lib/built/permission.d.ts +3 -7
  107. package/lib/built/permission.js +39 -52
  108. package/lib/built/permit-check.d.ts +7 -0
  109. package/lib/built/permit-check.js +35 -0
  110. package/lib/built/permit-parse.d.ts +16 -0
  111. package/lib/built/permit-parse.js +32 -0
  112. package/lib/built/platform-permit.d.ts +20 -0
  113. package/lib/built/platform-permit.js +91 -0
  114. package/lib/built/queue-im-field-contract.d.ts +7 -2
  115. package/lib/built/queue-im-field-contract.js +13 -4
  116. package/lib/built/rich-segments/adapter-policies.d.ts +9 -0
  117. package/lib/built/rich-segments/adapter-policies.js +27 -0
  118. package/lib/built/rich-segments/base.d.ts +11 -0
  119. package/lib/built/rich-segments/base.js +24 -0
  120. package/lib/built/rich-segments/builtins.d.ts +4 -0
  121. package/lib/built/rich-segments/builtins.js +40 -0
  122. package/lib/built/rich-segments/capabilities.d.ts +6 -0
  123. package/lib/built/rich-segments/capabilities.js +38 -0
  124. package/lib/built/rich-segments/html-segment.d.ts +15 -0
  125. package/lib/built/rich-segments/html-segment.js +62 -0
  126. package/lib/built/rich-segments/index.d.ts +13 -0
  127. package/lib/built/rich-segments/index.js +13 -0
  128. package/lib/built/rich-segments/markdown-segment.d.ts +14 -0
  129. package/lib/built/rich-segments/markdown-segment.js +58 -0
  130. package/lib/built/rich-segments/markdown-to-text.d.ts +3 -0
  131. package/lib/built/rich-segments/markdown-to-text.js +27 -0
  132. package/lib/built/rich-segments/qrcode-segment.d.ts +18 -0
  133. package/lib/built/rich-segments/qrcode-segment.js +73 -0
  134. package/lib/built/rich-segments/registry.d.ts +16 -0
  135. package/lib/built/rich-segments/registry.js +52 -0
  136. package/lib/built/rich-segments/resolve.d.ts +5 -0
  137. package/lib/built/rich-segments/resolve.js +87 -0
  138. package/lib/built/rich-segments/tts-segment.d.ts +13 -0
  139. package/lib/built/rich-segments/tts-segment.js +51 -0
  140. package/lib/built/rich-segments/types.d.ts +79 -0
  141. package/lib/built/rich-segments/types.js +17 -0
  142. package/lib/built/roles.d.ts +4 -5
  143. package/lib/built/roles.js +4 -5
  144. package/lib/built/runtime-io.d.ts +0 -1
  145. package/lib/built/runtime-io.js +0 -1
  146. package/lib/built/schedule.d.ts +54 -0
  147. package/lib/built/schedule.js +112 -0
  148. package/lib/built/schema-endpoint-manager.d.ts +17 -0
  149. package/lib/built/schema-endpoint-manager.js +73 -0
  150. package/lib/built/schema-feature.d.ts +0 -1
  151. package/lib/built/schema-feature.js +1 -3
  152. package/lib/built/segment-contract/assert.d.ts +7 -0
  153. package/lib/built/segment-contract/assert.js +39 -0
  154. package/lib/built/segment-contract/delivery.d.ts +5 -0
  155. package/lib/built/segment-contract/delivery.js +40 -0
  156. package/lib/built/segment-contract/image.d.ts +5 -0
  157. package/lib/built/segment-contract/image.js +10 -0
  158. package/lib/built/segment-contract/index.d.ts +10 -0
  159. package/lib/built/segment-contract/index.js +9 -0
  160. package/lib/built/segment-contract/json-schema.d.ts +28 -0
  161. package/lib/built/segment-contract/json-schema.js +128 -0
  162. package/lib/built/segment-contract/media.d.ts +12 -0
  163. package/lib/built/segment-contract/media.js +22 -0
  164. package/lib/built/segment-contract/mention.d.ts +10 -0
  165. package/lib/built/segment-contract/mention.js +26 -0
  166. package/lib/built/segment-contract/preview.d.ts +3 -0
  167. package/lib/built/segment-contract/preview.js +159 -0
  168. package/lib/built/segment-contract/text.d.ts +7 -0
  169. package/lib/built/segment-contract/text.js +34 -0
  170. package/lib/built/segment-contract/types.d.ts +58 -0
  171. package/lib/built/segment-contract/types.js +1 -0
  172. package/lib/built/segment-contract/validate.d.ts +229 -0
  173. package/lib/built/segment-contract/validate.js +174 -0
  174. package/lib/built/skill.d.ts +0 -1
  175. package/lib/built/skill.js +0 -1
  176. package/lib/built/speech-loader.d.ts +14 -0
  177. package/lib/built/speech-loader.js +32 -0
  178. package/lib/built/tool.d.ts +14 -13
  179. package/lib/built/tool.js +30 -25
  180. package/lib/built/user-interaction.d.ts +30 -0
  181. package/lib/built/user-interaction.js +248 -0
  182. package/lib/command.d.ts +19 -11
  183. package/lib/command.js +42 -11
  184. package/lib/component.d.ts +0 -1
  185. package/lib/component.js +30 -14
  186. package/lib/endpoint-capabilities.d.ts +46 -0
  187. package/lib/endpoint-capabilities.js +55 -0
  188. package/lib/endpoint.d.ts +19 -0
  189. package/lib/endpoint.js +3 -0
  190. package/lib/errors.d.ts +2 -3
  191. package/lib/errors.js +4 -5
  192. package/lib/feature/adapter.d.ts +2 -0
  193. package/lib/feature/adapter.js +2 -0
  194. package/lib/feature/command.d.ts +2 -0
  195. package/lib/feature/command.js +2 -0
  196. package/lib/feature/component.d.ts +2 -0
  197. package/lib/feature/component.js +2 -0
  198. package/lib/feature/handler.d.ts +52 -0
  199. package/lib/feature/handler.js +26 -0
  200. package/lib/feature/middleware.d.ts +2 -0
  201. package/lib/feature/middleware.js +2 -0
  202. package/lib/host-plugin-registry.d.ts +8 -0
  203. package/lib/host-plugin-registry.js +12 -0
  204. package/lib/im-scene.d.ts +29 -0
  205. package/lib/im-scene.js +75 -0
  206. package/lib/im-session-id.d.ts +39 -0
  207. package/lib/im-session-id.js +47 -0
  208. package/lib/index.d.ts +59 -25
  209. package/lib/index.js +53 -31
  210. package/lib/jsx-dev-runtime.d.ts +0 -1
  211. package/lib/jsx-dev-runtime.js +0 -1
  212. package/lib/jsx-runtime.d.ts +1 -1
  213. package/lib/jsx-runtime.js +0 -1
  214. package/lib/jsx.d.ts +19 -22
  215. package/lib/jsx.js +0 -1
  216. package/lib/message.d.ts +16 -10
  217. package/lib/message.js +16 -13
  218. package/lib/models/system-log.d.ts +0 -1
  219. package/lib/models/system-log.js +0 -1
  220. package/lib/models/user.d.ts +0 -1
  221. package/lib/models/user.js +0 -1
  222. package/lib/notice.d.ts +16 -59
  223. package/lib/notice.js +1 -4
  224. package/lib/plugin-context.d.ts +27 -0
  225. package/lib/plugin-context.js +64 -0
  226. package/lib/plugin-runtime/im/contracts.d.ts +191 -0
  227. package/lib/plugin-runtime/im/contracts.js +169 -0
  228. package/lib/plugin-runtime/im/im-runtime.d.ts +177 -0
  229. package/lib/plugin-runtime/im/im-runtime.js +1204 -0
  230. package/lib/plugin-runtime/im/index.d.ts +9 -0
  231. package/lib/plugin-runtime/im/index.js +9 -0
  232. package/lib/plugin-runtime/im/interactive.d.ts +26 -0
  233. package/lib/plugin-runtime/im/interactive.js +46 -0
  234. package/lib/plugin-runtime/im/login-assist-host.d.ts +6 -0
  235. package/lib/plugin-runtime/im/login-assist-host.js +6 -0
  236. package/lib/plugin-runtime/im/message-bus.d.ts +38 -0
  237. package/lib/plugin-runtime/im/message-bus.js +40 -0
  238. package/lib/plugin-runtime/im/message-dispatcher.d.ts +18 -0
  239. package/lib/plugin-runtime/im/message-dispatcher.js +107 -0
  240. package/lib/plugin-runtime/im/outbound-renderer.d.ts +7 -0
  241. package/lib/plugin-runtime/im/outbound-renderer.js +70 -0
  242. package/lib/plugin-runtime/im/outbound-segments.d.ts +72 -0
  243. package/lib/plugin-runtime/im/outbound-segments.js +220 -0
  244. package/lib/plugin-runtime/im/public-api.d.ts +6 -0
  245. package/lib/plugin-runtime/im/public-api.js +6 -0
  246. package/lib/plugin-runtime/im/service-tokens.d.ts +18 -0
  247. package/lib/plugin-runtime/im/service-tokens.js +13 -0
  248. package/lib/plugin.d.ts +34 -24
  249. package/lib/plugin.js +119 -224
  250. package/lib/request.d.ts +17 -61
  251. package/lib/request.js +0 -4
  252. package/lib/{prompt.d.ts → schema-interaction.d.ts} +6 -7
  253. package/lib/{prompt.js → schema-interaction.js} +20 -17
  254. package/lib/side-event/base.d.ts +52 -0
  255. package/lib/side-event/base.js +30 -0
  256. package/lib/side-event/dispatch.d.ts +15 -0
  257. package/lib/side-event/dispatch.js +140 -0
  258. package/lib/side-event/index.d.ts +4 -0
  259. package/lib/side-event/index.js +4 -0
  260. package/lib/side-event/normalize.d.ts +42 -0
  261. package/lib/side-event/normalize.js +121 -0
  262. package/lib/side-event/types.d.ts +23 -0
  263. package/lib/side-event/types.js +55 -0
  264. package/lib/system-event.d.ts +15 -0
  265. package/lib/system-event.js +7 -0
  266. package/lib/tool-zod.d.ts +18 -3
  267. package/lib/tool-zod.js +140 -54
  268. package/lib/types.d.ts +44 -95
  269. package/lib/types.js +0 -1
  270. package/lib/utils.d.ts +61 -13
  271. package/lib/utils.js +66 -25
  272. package/package.json +98 -10
  273. package/lib/adapter.d.ts.map +0 -1
  274. package/lib/adapter.js.map +0 -1
  275. package/lib/agent-prompt.d.ts +0 -37
  276. package/lib/agent-prompt.d.ts.map +0 -1
  277. package/lib/agent-prompt.js +0 -2
  278. package/lib/agent-prompt.js.map +0 -1
  279. package/lib/bot.d.ts +0 -38
  280. package/lib/bot.d.ts.map +0 -1
  281. package/lib/bot.js +0 -2
  282. package/lib/bot.js.map +0 -1
  283. package/lib/built/adapter-process.d.ts.map +0 -1
  284. package/lib/built/adapter-process.js.map +0 -1
  285. package/lib/built/agent-preset.d.ts.map +0 -1
  286. package/lib/built/agent-preset.js.map +0 -1
  287. package/lib/built/ai-trigger.d.ts.map +0 -1
  288. package/lib/built/ai-trigger.js.map +0 -1
  289. package/lib/built/command.d.ts.map +0 -1
  290. package/lib/built/command.js.map +0 -1
  291. package/lib/built/common-adapter-tools.d.ts.map +0 -1
  292. package/lib/built/common-adapter-tools.js.map +0 -1
  293. package/lib/built/component.d.ts.map +0 -1
  294. package/lib/built/component.js.map +0 -1
  295. package/lib/built/config.d.ts.map +0 -1
  296. package/lib/built/config.js.map +0 -1
  297. package/lib/built/cron.d.ts +0 -75
  298. package/lib/built/cron.d.ts.map +0 -1
  299. package/lib/built/cron.js +0 -122
  300. package/lib/built/cron.js.map +0 -1
  301. package/lib/built/database.d.ts.map +0 -1
  302. package/lib/built/database.js.map +0 -1
  303. package/lib/built/dispatcher.d.ts.map +0 -1
  304. package/lib/built/dispatcher.js.map +0 -1
  305. package/lib/built/html-segment-fallback.d.ts.map +0 -1
  306. package/lib/built/html-segment-fallback.js.map +0 -1
  307. package/lib/built/html-to-text.d.ts.map +0 -1
  308. package/lib/built/html-to-text.js.map +0 -1
  309. package/lib/built/inbound-runner.d.ts.map +0 -1
  310. package/lib/built/inbound-runner.js.map +0 -1
  311. package/lib/built/login-assist.d.ts.map +0 -1
  312. package/lib/built/login-assist.js.map +0 -1
  313. package/lib/built/mcp-mesh-registrar.d.ts +0 -9
  314. package/lib/built/mcp-mesh-registrar.d.ts.map +0 -1
  315. package/lib/built/mcp-mesh-registrar.js +0 -17
  316. package/lib/built/mcp-mesh-registrar.js.map +0 -1
  317. package/lib/built/message-filter.d.ts.map +0 -1
  318. package/lib/built/message-filter.js.map +0 -1
  319. package/lib/built/permission.d.ts.map +0 -1
  320. package/lib/built/permission.js.map +0 -1
  321. package/lib/built/prepend-quote-context.d.ts +0 -35
  322. package/lib/built/prepend-quote-context.d.ts.map +0 -1
  323. package/lib/built/prepend-quote-context.js +0 -131
  324. package/lib/built/prepend-quote-context.js.map +0 -1
  325. package/lib/built/queue-im-field-contract.d.ts.map +0 -1
  326. package/lib/built/queue-im-field-contract.js.map +0 -1
  327. package/lib/built/roles.d.ts.map +0 -1
  328. package/lib/built/roles.js.map +0 -1
  329. package/lib/built/runtime-io.d.ts.map +0 -1
  330. package/lib/built/runtime-io.js.map +0 -1
  331. package/lib/built/schema-feature.d.ts.map +0 -1
  332. package/lib/built/schema-feature.js.map +0 -1
  333. package/lib/built/skill.d.ts.map +0 -1
  334. package/lib/built/skill.js.map +0 -1
  335. package/lib/built/tool.d.ts.map +0 -1
  336. package/lib/built/tool.js.map +0 -1
  337. package/lib/command.d.ts.map +0 -1
  338. package/lib/command.js.map +0 -1
  339. package/lib/component.d.ts.map +0 -1
  340. package/lib/component.js.map +0 -1
  341. package/lib/errors.d.ts.map +0 -1
  342. package/lib/errors.js.map +0 -1
  343. package/lib/index.d.ts.map +0 -1
  344. package/lib/index.js.map +0 -1
  345. package/lib/jsx-dev-runtime.d.ts.map +0 -1
  346. package/lib/jsx-dev-runtime.js.map +0 -1
  347. package/lib/jsx-runtime.d.ts.map +0 -1
  348. package/lib/jsx-runtime.js.map +0 -1
  349. package/lib/jsx.d.ts.map +0 -1
  350. package/lib/jsx.js.map +0 -1
  351. package/lib/message-quote.d.ts +0 -11
  352. package/lib/message-quote.d.ts.map +0 -1
  353. package/lib/message-quote.js +0 -91
  354. package/lib/message-quote.js.map +0 -1
  355. package/lib/message.d.ts.map +0 -1
  356. package/lib/message.js.map +0 -1
  357. package/lib/models/system-log.d.ts.map +0 -1
  358. package/lib/models/system-log.js.map +0 -1
  359. package/lib/models/user.d.ts.map +0 -1
  360. package/lib/models/user.js.map +0 -1
  361. package/lib/notice.d.ts.map +0 -1
  362. package/lib/notice.js.map +0 -1
  363. package/lib/plugin.d.ts.map +0 -1
  364. package/lib/plugin.js.map +0 -1
  365. package/lib/prompt.d.ts.map +0 -1
  366. package/lib/prompt.js.map +0 -1
  367. package/lib/request.d.ts.map +0 -1
  368. package/lib/request.js.map +0 -1
  369. package/lib/scheduler/scheduler.d.ts +0 -49
  370. package/lib/scheduler/scheduler.d.ts.map +0 -1
  371. package/lib/scheduler/scheduler.js +0 -352
  372. package/lib/scheduler/scheduler.js.map +0 -1
  373. package/lib/scheduler/types.d.ts +0 -71
  374. package/lib/scheduler/types.d.ts.map +0 -1
  375. package/lib/scheduler/types.js +0 -8
  376. package/lib/scheduler/types.js.map +0 -1
  377. package/lib/tool-zod.d.ts.map +0 -1
  378. package/lib/tool-zod.js.map +0 -1
  379. package/lib/types-generator.d.ts +0 -6
  380. package/lib/types-generator.d.ts.map +0 -1
  381. package/lib/types-generator.js +0 -72
  382. package/lib/types-generator.js.map +0 -1
  383. package/lib/types.d.ts.map +0 -1
  384. package/lib/types.js.map +0 -1
  385. package/lib/utils.d.ts.map +0 -1
  386. package/lib/utils.js.map +0 -1
package/lib/component.js CHANGED
@@ -176,24 +176,41 @@ function parseAttributeValue(str, startIndex, context) {
176
176
  function evaluateQuotedExpression(quotedValue, context) {
177
177
  if (!context)
178
178
  return quotedValue;
179
- // 处理引号内的表达式,将 {expr} 格式转换为 ${expr} 格式
180
- let result = quotedValue;
181
- const expressionRegex = /\{([^}]+)\}/g;
182
- let match;
183
- while ((match = expressionRegex.exec(quotedValue)) !== null) {
184
- const expr = match[1];
179
+ let result = '';
180
+ let cursor = 0;
181
+ for (const match of readBraceExpressions(quotedValue)) {
182
+ result += quotedValue.slice(cursor, match.start);
185
183
  try {
186
- const value = context.getValue(expr);
187
- if (value !== undefined && value !== expr) {
184
+ const value = context.getValue(match.expr);
185
+ if (value !== undefined && value !== match.expr) {
188
186
  const stringValue = typeof value === 'string' ? value : JSON.stringify(value);
189
- result = result.replace(match[0], stringValue);
187
+ result += stringValue;
188
+ }
189
+ else {
190
+ result += quotedValue.slice(match.start, match.end);
190
191
  }
191
192
  }
192
193
  catch (error) {
193
- // 如果求值失败,保持原始表达式
194
+ result += quotedValue.slice(match.start, match.end);
194
195
  }
196
+ cursor = match.end;
195
197
  }
196
- return result;
198
+ return result + quotedValue.slice(cursor);
199
+ }
200
+ function readBraceExpressions(value) {
201
+ const matches = [];
202
+ let cursor = 0;
203
+ while (cursor < value.length) {
204
+ const start = value.indexOf('{', cursor);
205
+ if (start < 0)
206
+ break;
207
+ const end = value.indexOf('}', start + 1);
208
+ if (end < 0)
209
+ break;
210
+ matches.push({ start, end: end + 1, expr: value.slice(start + 1, end) });
211
+ cursor = end + 1;
212
+ }
213
+ return matches;
197
214
  }
198
215
  /**
199
216
  * 解析表达式值
@@ -546,7 +563,7 @@ export async function renderComponents(componentMap, options, customContext) {
546
563
  }
547
564
  // 内置组件
548
565
  export const Fragment = defineComponent(async (props, context) => {
549
- let children = props.children || '';
566
+ const children = props.children || '';
550
567
  if (Array.isArray(children)) {
551
568
  return children.join('');
552
569
  }
@@ -562,6 +579,5 @@ export const Fragment = defineComponent(async (props, context) => {
562
579
  return String(children);
563
580
  }, 'Fragment');
564
581
  export const Fetch = defineComponent(async ({ url }) => {
565
- return await fetch(url).then((r) => r.text());
582
+ return await fetch(url, { signal: AbortSignal.timeout(30_000) }).then((r) => r.text());
566
583
  }, 'fetch');
567
- //# sourceMappingURL=component.js.map
@@ -0,0 +1,46 @@
1
+ import type { Message } from './message.js';
2
+ import type { Notice } from './notice.js';
3
+ import type { Request } from './request.js';
4
+ import type { SendOptions } from './types.js';
5
+ import type { AIAccessScopeConfig } from './built/ai-access.js';
6
+ export type EndpointCapability = 'inbound' | 'outbound';
7
+ export declare const DEFAULT_ENDPOINT_CAPABILITIES: readonly EndpointCapability[];
8
+ /** 入站能力:含连接生命周期 */
9
+ export interface InboundEndpoint<Config extends object = object, Event extends object = object> {
10
+ $id: string;
11
+ $config: Config;
12
+ $connected: boolean;
13
+ $formatMessage(event: Event): Message<Event>;
14
+ $formatNotice?(event: unknown): Notice;
15
+ $formatRequest?(event: unknown): Request;
16
+ $connect(): Promise<void>;
17
+ $disconnect(): Promise<void>;
18
+ }
19
+ /** 出站能力:无连接方法 */
20
+ export interface OutboundEndpoint<Config extends object = object> {
21
+ $id: string;
22
+ $config: Config;
23
+ $connected: boolean;
24
+ $sendMessage(options: SendOptions): Promise<string>;
25
+ }
26
+ export type FullEndpoint<Config extends object = object, Event extends object = object> = InboundEndpoint<Config, Event> & OutboundEndpoint<Config>;
27
+ export type CapableEndpoint<Config extends object, Event extends object, Caps extends readonly EndpointCapability[]> = ('inbound' extends Caps[number] ? InboundEndpoint<Config, Event> : object) & ('outbound' extends Caps[number] ? OutboundEndpoint<Config> : object);
28
+ export declare class OutboundNotSupportedError extends Error {
29
+ constructor(endpointKey?: string);
30
+ }
31
+ export declare class InboundNotSupportedError extends Error {
32
+ constructor(endpointKey?: string);
33
+ }
34
+ export declare function registerEndpointCapabilities(endpoint: object, caps: readonly EndpointCapability[]): void;
35
+ export declare function getEndpointCapabilities(endpoint: object): readonly EndpointCapability[] | undefined;
36
+ export declare function resolveEndpointCapabilities(adapterCaps: readonly EndpointCapability[], endpointConfigCaps?: readonly EndpointCapability[]): readonly EndpointCapability[];
37
+ export declare function getAdapterCapabilities(adapter: object): readonly EndpointCapability[];
38
+ export declare function hasInbound(endpoint: object): boolean;
39
+ export declare function hasOutbound(endpoint: object): boolean;
40
+ export declare function assertInbound(endpoint: InboundEndpoint | OutboundEndpoint): asserts endpoint is InboundEndpoint;
41
+ export declare function assertOutbound(endpoint: InboundEndpoint | OutboundEndpoint): asserts endpoint is OutboundEndpoint;
42
+ export interface EndpointCapabilitiesConfig {
43
+ capabilities?: EndpointCapability[];
44
+ /** 本 Endpoint 的 AI 访问控制(覆盖 ai.access 全局默认) */
45
+ aiAccess?: AIAccessScopeConfig;
46
+ }
@@ -0,0 +1,55 @@
1
+ export const DEFAULT_ENDPOINT_CAPABILITIES = ['inbound', 'outbound'];
2
+ export class OutboundNotSupportedError extends Error {
3
+ constructor(endpointKey) {
4
+ super(endpointKey ? `Endpoint ${endpointKey} does not support outbound` : 'Outbound not supported');
5
+ this.name = 'OutboundNotSupportedError';
6
+ }
7
+ }
8
+ export class InboundNotSupportedError extends Error {
9
+ constructor(endpointKey) {
10
+ super(endpointKey ? `Endpoint ${endpointKey} does not support inbound` : 'Inbound not supported');
11
+ this.name = 'InboundNotSupportedError';
12
+ }
13
+ }
14
+ const endpointCapabilitiesRegistry = new WeakMap();
15
+ export function registerEndpointCapabilities(endpoint, caps) {
16
+ endpointCapabilitiesRegistry.set(endpoint, caps);
17
+ }
18
+ export function getEndpointCapabilities(endpoint) {
19
+ return endpointCapabilitiesRegistry.get(endpoint);
20
+ }
21
+ export function resolveEndpointCapabilities(adapterCaps, endpointConfigCaps) {
22
+ const resolved = endpointConfigCaps?.length ? [...endpointConfigCaps] : [...adapterCaps];
23
+ if (resolved.length === 0) {
24
+ throw new Error('Endpoint must declare at least one capability (inbound and/or outbound)');
25
+ }
26
+ for (const cap of resolved) {
27
+ if (!adapterCaps.includes(cap)) {
28
+ throw new Error(`Endpoint capability "${cap}" exceeds adapter capabilities [${adapterCaps.join(', ')}]`);
29
+ }
30
+ }
31
+ return resolved;
32
+ }
33
+ export function getAdapterCapabilities(adapter) {
34
+ const ctor = adapter.constructor;
35
+ const caps = ctor.capabilities;
36
+ return caps?.length ? caps : DEFAULT_ENDPOINT_CAPABILITIES;
37
+ }
38
+ export function hasInbound(endpoint) {
39
+ const caps = getEndpointCapabilities(endpoint);
40
+ return caps ? caps.includes('inbound') : true;
41
+ }
42
+ export function hasOutbound(endpoint) {
43
+ const caps = getEndpointCapabilities(endpoint);
44
+ return caps ? caps.includes('outbound') : true;
45
+ }
46
+ export function assertInbound(endpoint) {
47
+ if (!hasInbound(endpoint)) {
48
+ throw new InboundNotSupportedError('$id' in endpoint ? String(endpoint.$id) : undefined);
49
+ }
50
+ }
51
+ export function assertOutbound(endpoint) {
52
+ if (!hasOutbound(endpoint)) {
53
+ throw new OutboundNotSupportedError('$id' in endpoint ? String(endpoint.$id) : undefined);
54
+ }
55
+ }
@@ -0,0 +1,19 @@
1
+ import type { Adapters, Adapter } from './adapter.js';
2
+ import type { EndpointCapabilitiesConfig, FullEndpoint } from './endpoint-capabilities.js';
3
+ import type { EndpointWithControl, EndpointWithManagement } from '@zhin.js/adapter';
4
+ export type { EndpointChannel, EndpointChannelParent, EndpointFriend, EndpointGroup, EndpointManagement, EndpointWithManagement, EndpointManagementCapability, } from '@zhin.js/adapter';
5
+ export { endpointManagementCapabilityIds, listEndpointManagementCapabilities, resolveEndpointManagement, } from '@zhin.js/adapter';
6
+ export type { EndpointControl, EndpointWithControl } from '@zhin.js/adapter';
7
+ export { endpointControlOf } from '@zhin.js/adapter';
8
+ export type { EndpointCapability, EndpointCapabilitiesConfig, InboundEndpoint, OutboundEndpoint, FullEndpoint, CapableEndpoint, } from './endpoint-capabilities.js';
9
+ export { DEFAULT_ENDPOINT_CAPABILITIES, OutboundNotSupportedError, InboundNotSupportedError, resolveEndpointCapabilities, registerEndpointCapabilities, getEndpointCapabilities, getAdapterCapabilities, hasInbound, hasOutbound, assertInbound, assertOutbound, } from './endpoint-capabilities.js';
10
+ /**
11
+ * Endpoint 接口:全双工平台机器人(入站 + 出站)。
12
+ * 纯入站 / 纯出站请实现 InboundEndpoint / OutboundEndpoint。
13
+ */
14
+ export type Endpoint<Config extends object = object, Event extends object = object> = FullEndpoint<Config, Event> & EndpointWithManagement & EndpointWithControl;
15
+ export declare namespace Endpoint {
16
+ type Config<K extends keyof Adapters = keyof Adapters> = Adapter.EndpointConfig<Adapter.InferEndpoint<Adapters[K]>> & EndpointCapabilitiesConfig & {
17
+ context: K;
18
+ };
19
+ }
@@ -0,0 +1,3 @@
1
+ export { endpointManagementCapabilityIds, listEndpointManagementCapabilities, resolveEndpointManagement, } from '@zhin.js/adapter';
2
+ export { endpointControlOf } from '@zhin.js/adapter';
3
+ export { DEFAULT_ENDPOINT_CAPABILITIES, OutboundNotSupportedError, InboundNotSupportedError, resolveEndpointCapabilities, registerEndpointCapabilities, getEndpointCapabilities, getAdapterCapabilities, hasInbound, hasOutbound, assertInbound, assertOutbound, } from './endpoint-capabilities.js';
package/lib/errors.d.ts CHANGED
@@ -8,8 +8,8 @@ import { ZhinError } from '@zhin.js/kernel';
8
8
  */
9
9
  export declare class AdapterError extends ZhinError {
10
10
  readonly adapterName: string;
11
- readonly botName?: string;
12
- constructor(message: string, adapterName: string, botName?: string, context?: Record<string, any>);
11
+ readonly endpointKey?: string;
12
+ constructor(message: string, adapterName: string, endpointKey?: string, context?: Record<string, any>);
13
13
  }
14
14
  /**
15
15
  * 消息处理错误
@@ -19,4 +19,3 @@ export declare class MessageError extends ZhinError {
19
19
  readonly channelId?: string;
20
20
  constructor(message: string, messageId?: string, channelId?: string, context?: Record<string, any>);
21
21
  }
22
- //# sourceMappingURL=errors.d.ts.map
package/lib/errors.js CHANGED
@@ -8,11 +8,11 @@ import { ZhinError } from '@zhin.js/kernel';
8
8
  */
9
9
  export class AdapterError extends ZhinError {
10
10
  adapterName;
11
- botName;
12
- constructor(message, adapterName, botName, context) {
13
- super(message, 'ADAPTER_ERROR', { ...context, adapterName, botName });
11
+ endpointKey;
12
+ constructor(message, adapterName, endpointKey, context) {
13
+ super(message, 'ADAPTER_ERROR', { ...context, adapterName, endpointKey });
14
14
  this.adapterName = adapterName;
15
- this.botName = botName;
15
+ this.endpointKey = endpointKey;
16
16
  }
17
17
  }
18
18
  /**
@@ -27,4 +27,3 @@ export class MessageError extends ZhinError {
27
27
  this.channelId = channelId;
28
28
  }
29
29
  }
30
- //# sourceMappingURL=errors.js.map
@@ -0,0 +1,2 @@
1
+ /** Authoring API for Adapter Feature — implementation in `@zhin.js/adapter`. */
2
+ export * from '@zhin.js/adapter';
@@ -0,0 +1,2 @@
1
+ /** Authoring API for Adapter Feature — implementation in `@zhin.js/adapter`. */
2
+ export * from '@zhin.js/adapter';
@@ -0,0 +1,2 @@
1
+ /** Authoring API for Command Feature — implementation in `@zhin.js/command`. */
2
+ export * from '@zhin.js/command';
@@ -0,0 +1,2 @@
1
+ /** Authoring API for Command Feature — implementation in `@zhin.js/command`. */
2
+ export * from '@zhin.js/command';
@@ -0,0 +1,2 @@
1
+ /** Authoring API for Component Feature — implementation in `@zhin.js/component`. */
2
+ export * from '@zhin.js/component';
@@ -0,0 +1,2 @@
1
+ /** Authoring API for Component Feature — implementation in `@zhin.js/component`. */
2
+ export * from '@zhin.js/component';
@@ -0,0 +1,52 @@
1
+ /** Authoring API for Handler Feature — implementation in `@zhin.js/handler`. */
2
+ export { parseHandlerDefinition, HandlerIndex, isHandlerIndex, handlerFeatureId, handlerFeature, handlerEventFromLocalName, resolveHandlerEvent, type HandlerEventMap, type HandlerDefinition, type HandlerDescriptor, type HandlerContext, type HandlerDispatchOptions, } from '@zhin.js/handler';
3
+ import { type HandlerContext, type HandlerDefinition, type HandlerEventMap } from '@zhin.js/handler';
4
+ import type { Plugin } from '../plugin.js';
5
+ import type { Message } from '../plugin-runtime/im/contracts.js';
6
+ import type { Notice } from '../notice.js';
7
+ import type { Request } from '../request.js';
8
+ import type { SystemEvent } from '../system-event.js';
9
+ 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
+ declare module '@zhin.js/handler' {
14
+ interface HandlerEventMap extends KnownKeys<Omit<Plugin.Lifecycle, 'message.receive' | 'notice.receive' | 'request.receive' | 'system.receive'>> {
15
+ 'message.receive': [event: EndpointEvent<Message>];
16
+ 'notice.receive': [event: EndpointEvent<Notice>];
17
+ 'request.receive': [event: EndpointEvent<Request>];
18
+ 'system.receive': [event: EndpointEvent<SystemEvent>];
19
+ 'platform.receive': [event: EndpointEvent<PlatformEvent>];
20
+ }
21
+ }
22
+ type NativeEventName<TAdapter extends RegisteredAdapterName> = Extract<keyof AdapterEvents<TAdapter>, string>;
23
+ /** Fully inferred native platform event exposed to plugin handlers. */
24
+ export interface ClientHandlerEvent<TAdapter extends RegisteredAdapterName, TName extends NativeEventName<TAdapter> = NativeEventName<TAdapter>> {
25
+ readonly name: TName;
26
+ readonly event: AdapterEvents<TAdapter>[TName];
27
+ readonly endpoint: EndpointIdentity;
28
+ readonly client: AdapterClient<TAdapter>;
29
+ }
30
+ export interface ClientHandlerOptions<TAdapter extends RegisteredAdapterName, TName extends NativeEventName<TAdapter>> {
31
+ readonly adapter: TAdapter;
32
+ readonly event: TName;
33
+ handle(this: HandlerContext, event: ClientHandlerEvent<TAdapter, TName>): void | Promise<void>;
34
+ }
35
+ export interface ClientHandlerWildcardEvent<TAdapter extends RegisteredAdapterName> {
36
+ readonly name: string;
37
+ readonly event: unknown;
38
+ readonly endpoint: EndpointIdentity;
39
+ readonly client: AdapterClient<TAdapter>;
40
+ }
41
+ export interface ClientHandlerWildcardOptions<TAdapter extends RegisteredAdapterName> {
42
+ readonly adapter: TAdapter;
43
+ readonly event: '*';
44
+ handle(this: HandlerContext, event: ClientHandlerWildcardEvent<TAdapter>): void | Promise<void>;
45
+ }
46
+ export declare function defineHandler<TAdapter extends RegisteredAdapterName, TName extends NativeEventName<TAdapter>>(options: ClientHandlerOptions<TAdapter, TName>): Readonly<HandlerDefinition<'platform.receive'>>;
47
+ /** Handle every native event from one Client without pretending unknown payloads are typed. */
48
+ export declare function defineHandler<TAdapter extends RegisteredAdapterName>(options: ClientHandlerWildcardOptions<TAdapter>): Readonly<HandlerDefinition<'platform.receive'>>;
49
+ export declare function defineHandler<K extends keyof HandlerEventMap & string>(options: {
50
+ readonly event: K;
51
+ handle(this: HandlerContext, ...args: HandlerEventMap[K] extends unknown[] ? HandlerEventMap[K] : unknown[]): void | Promise<void>;
52
+ }): Readonly<HandlerDefinition<K>>;
@@ -0,0 +1,26 @@
1
+ /** Authoring API for Handler Feature — implementation in `@zhin.js/handler`. */
2
+ export { parseHandlerDefinition, HandlerIndex, isHandlerIndex, handlerFeatureId, handlerFeature, handlerEventFromLocalName, resolveHandlerEvent, } from '@zhin.js/handler';
3
+ import { defineHandler as defineHandlerFeature, } from '@zhin.js/handler';
4
+ export function defineHandler(options) {
5
+ if (!('adapter' in options) || typeof options.adapter !== 'string') {
6
+ return defineHandlerFeature(options);
7
+ }
8
+ const adapter = options.adapter;
9
+ const expectedName = options.event === '*' ? undefined : options.event;
10
+ return defineHandlerFeature({
11
+ event: 'platform.receive',
12
+ async handle(source) {
13
+ if (source.endpoint.adapter !== adapter)
14
+ return;
15
+ if (expectedName !== undefined && source.payload.name !== expectedName)
16
+ return;
17
+ const event = Object.freeze({
18
+ name: source.payload.name,
19
+ event: source.payload.event,
20
+ endpoint: source.endpoint,
21
+ client: source.client,
22
+ });
23
+ await options.handle.call(this, event);
24
+ },
25
+ });
26
+ }
@@ -0,0 +1,2 @@
1
+ /** Authoring API for Middleware Feature — implementation in `@zhin.js/middleware`. */
2
+ export * from '@zhin.js/middleware';
@@ -0,0 +1,2 @@
1
+ /** Authoring API for Middleware Feature — implementation in `@zhin.js/middleware`. */
2
+ export * from '@zhin.js/middleware';
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @deprecated **已删除**。全局根插件注册表已移除;服务通过 Scope+Token 提供。
3
+ * 保留 no-op 签名供编译期过渡。
4
+ */
5
+ /** @deprecated 已删除——不做任何事。 */
6
+ export declare function setHostRootPlugin(_plugin: unknown): void;
7
+ /** @deprecated 已删除——总是返回 null。 */
8
+ export declare function getHostRootPlugin(): null;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @deprecated **已删除**。全局根插件注册表已移除;服务通过 Scope+Token 提供。
3
+ * 保留 no-op 签名供编译期过渡。
4
+ */
5
+ /** @deprecated 已删除——不做任何事。 */
6
+ export function setHostRootPlugin(_plugin) {
7
+ // no-op: legacy host root plugin registry has been removed
8
+ }
9
+ /** @deprecated 已删除——总是返回 null。 */
10
+ export function getHostRootPlugin() {
11
+ return null;
12
+ }
@@ -0,0 +1,29 @@
1
+ import type { Message, MessageType } from './message.js';
2
+ import type { SendContent, SendOptions } from './types.js';
3
+ export type IMSceneKind = MessageType;
4
+ /** Parent scene kind (distinct from sub-channel MessageType.channel). */
5
+ export type IMSceneParentKind = 'group' | 'guild';
6
+ export interface IMSceneParentRef {
7
+ kind: IMSceneParentKind;
8
+ sceneId: string;
9
+ }
10
+ export interface IMSceneRef {
11
+ platform: string;
12
+ endpointKey: string;
13
+ sceneId: string;
14
+ kind: IMSceneKind;
15
+ senderId?: string;
16
+ parent?: IMSceneParentRef;
17
+ }
18
+ export interface IMDeliveryTarget {
19
+ channel: 'im';
20
+ scene: IMSceneRef;
21
+ threadId?: string;
22
+ quoteId?: string;
23
+ }
24
+ /** Normalize legacy parent.type channel → guild. */
25
+ export declare function normalizeIMSceneParentKind(value: unknown): IMSceneParentKind | undefined;
26
+ export declare function sceneRefFromMessage(message: Partial<Message<any>>): IMSceneRef | undefined;
27
+ export declare function sceneRefToSendOptions(target: IMDeliveryTarget, content: SendContent): SendOptions;
28
+ export declare function resolveIMSceneSessionId(scene: IMSceneRef): string;
29
+ export declare function messageToIMDeliveryTarget(message: Partial<Message<any>>): IMDeliveryTarget | undefined;
@@ -0,0 +1,75 @@
1
+ import { resolveIMSceneSessionId as resolveIMSceneSessionIdKernel, } from '@zhin.js/kernel';
2
+ function nonEmptyString(value) {
3
+ return typeof value === 'string' && value.trim() ? value.trim() : undefined;
4
+ }
5
+ /** Normalize legacy parent.type channel → guild. */
6
+ export function normalizeIMSceneParentKind(value) {
7
+ if (value === 'group' || value === 'guild')
8
+ return value;
9
+ if (value === 'channel')
10
+ return 'guild';
11
+ return undefined;
12
+ }
13
+ export function sceneRefFromMessage(message) {
14
+ const platform = nonEmptyString(message.$adapter);
15
+ const endpointKey = nonEmptyString(message.$endpoint);
16
+ const kind = message.$channel?.type;
17
+ if (!platform || !endpointKey || !kind)
18
+ return undefined;
19
+ const senderId = nonEmptyString(message.$sender?.id);
20
+ const channelId = nonEmptyString(message.$channel?.id);
21
+ const sceneId = kind === 'private'
22
+ ? senderId ?? channelId
23
+ : channelId ?? senderId;
24
+ if (!sceneId)
25
+ return undefined;
26
+ const parentKind = message.$channel?.parent
27
+ ? normalizeIMSceneParentKind(message.$channel.parent.type)
28
+ : undefined;
29
+ const parent = parentKind && message.$channel?.parent
30
+ ? {
31
+ kind: parentKind,
32
+ sceneId: String(message.$channel.parent.id),
33
+ }
34
+ : undefined;
35
+ return {
36
+ platform,
37
+ endpointKey,
38
+ sceneId,
39
+ kind,
40
+ ...(senderId ? { senderId } : {}),
41
+ ...(parent ? { parent } : {}),
42
+ };
43
+ }
44
+ export function sceneRefToSendOptions(target, content) {
45
+ const { scene } = target;
46
+ return {
47
+ context: scene.platform,
48
+ endpoint: scene.endpointKey,
49
+ id: scene.sceneId,
50
+ type: scene.kind,
51
+ parent: scene.parent
52
+ ? { type: scene.parent.kind, id: scene.parent.sceneId }
53
+ : undefined,
54
+ content,
55
+ ...(target.quoteId ? { quoteId: target.quoteId } : {}),
56
+ ...(target.threadId ? { threadId: target.threadId } : {}),
57
+ };
58
+ }
59
+ export function resolveIMSceneSessionId(scene) {
60
+ return resolveIMSceneSessionIdKernel({
61
+ platform: scene.platform,
62
+ endpointKey: scene.endpointKey,
63
+ sceneId: scene.sceneId,
64
+ kind: scene.kind,
65
+ });
66
+ }
67
+ export function messageToIMDeliveryTarget(message) {
68
+ const scene = sceneRefFromMessage(message);
69
+ if (!scene)
70
+ return undefined;
71
+ return {
72
+ channel: 'im',
73
+ scene,
74
+ };
75
+ }
@@ -0,0 +1,39 @@
1
+ /**
2
+ * IM 会话 ID 解析(SSOT 在 @zhin.js/kernel + im-scene)
3
+ *
4
+ * 格式:`platform:endpointKey:kind:sceneId`
5
+ */
6
+ import { type ResolveIMSessionIdInput } from '@zhin.js/kernel';
7
+ import { type IMSceneKind, type IMSceneRef } from './im-scene.js';
8
+ export type { IMSceneKind, ResolveIMSessionIdInput };
9
+ export declare function resolveIMSessionId(input: ResolveIMSessionIdInput): string;
10
+ export declare function resolveIMSessionIdFromScene(scene: IMSceneRef): string;
11
+ export declare function resolveIMSceneIdForSession(kind: IMSceneKind, sceneId?: string, senderId?: string): string;
12
+ export declare function resolveIMSessionIdFromMessage(message: {
13
+ $adapter?: string;
14
+ $endpoint?: string;
15
+ $channel?: {
16
+ type?: IMSceneKind;
17
+ id?: string;
18
+ };
19
+ $sender?: {
20
+ id?: string;
21
+ };
22
+ }): string;
23
+ /** Canonical scene fields for transcript / session persistence (ADR 0028 SSOT). */
24
+ export declare function resolveSceneFieldsFromMessage(message: {
25
+ $adapter?: string;
26
+ $endpoint?: string;
27
+ $channel?: {
28
+ type?: IMSceneKind;
29
+ id?: string;
30
+ };
31
+ $sender?: {
32
+ id?: string;
33
+ };
34
+ }): {
35
+ platform: string;
36
+ endpointKey: string;
37
+ sceneId: string;
38
+ sceneType: IMSceneKind;
39
+ };
@@ -0,0 +1,47 @@
1
+ /**
2
+ * IM 会话 ID 解析(SSOT 在 @zhin.js/kernel + im-scene)
3
+ *
4
+ * 格式:`platform:endpointKey:kind:sceneId`
5
+ */
6
+ import { resolveIMSceneIdForSession as resolveIMSceneIdForSessionKernel, resolveIMSessionId as resolveIMSessionIdKernel, } from '@zhin.js/kernel';
7
+ import { resolveIMSceneSessionId, sceneRefFromMessage, } from './im-scene.js';
8
+ export function resolveIMSessionId(input) {
9
+ return resolveIMSessionIdKernel(input);
10
+ }
11
+ export function resolveIMSessionIdFromScene(scene) {
12
+ return resolveIMSceneSessionId(scene);
13
+ }
14
+ export function resolveIMSceneIdForSession(kind, sceneId, senderId) {
15
+ return resolveIMSceneIdForSessionKernel(kind, sceneId, senderId);
16
+ }
17
+ export function resolveIMSessionIdFromMessage(message) {
18
+ const scene = sceneRefFromMessage(message);
19
+ if (scene)
20
+ return resolveIMSceneSessionId(scene);
21
+ const kind = (message.$channel?.type || 'private');
22
+ return resolveIMSessionId({
23
+ platform: String(message.$adapter || ''),
24
+ endpointKey: String(message.$endpoint || ''),
25
+ kind,
26
+ sceneId: resolveIMSceneIdForSession(kind, message.$channel?.id, message.$sender?.id),
27
+ });
28
+ }
29
+ /** Canonical scene fields for transcript / session persistence (ADR 0028 SSOT). */
30
+ export function resolveSceneFieldsFromMessage(message) {
31
+ const scene = sceneRefFromMessage(message);
32
+ if (scene) {
33
+ return {
34
+ platform: scene.platform,
35
+ endpointKey: scene.endpointKey,
36
+ sceneId: scene.sceneId,
37
+ sceneType: scene.kind,
38
+ };
39
+ }
40
+ const sceneType = (message.$channel?.type || 'private');
41
+ return {
42
+ platform: String(message.$adapter || ''),
43
+ endpointKey: String(message.$endpoint || ''),
44
+ sceneType,
45
+ sceneId: resolveIMSceneIdForSession(sceneType, message.$channel?.id, message.$sender?.id),
46
+ };
47
+ }