@zhin.js/core 1.5.15 → 1.6.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 (328) 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 +13 -11
  35. package/lib/built/login-assist.js +32 -26
  36. package/lib/built/message-enrich.d.ts +24 -27
  37. package/lib/built/message-enrich.js +53 -49
  38. package/lib/built/outbound-content-arrays.d.ts +4 -0
  39. package/lib/built/outbound-content-arrays.js +32 -0
  40. package/lib/built/outbound-media-trust.d.ts +46 -0
  41. package/lib/built/outbound-media-trust.js +245 -0
  42. package/lib/built/outbound-media-utils.d.ts +5 -3
  43. package/lib/built/outbound-media-utils.js +5 -3
  44. package/lib/built/readable-link.d.ts +4 -0
  45. package/lib/built/readable-link.js +32 -0
  46. package/lib/built/rich-segments/markdown-to-text.d.ts +1 -2
  47. package/lib/built/rich-segments/markdown-to-text.js +141 -17
  48. package/lib/built/roles.d.ts +141 -12
  49. package/lib/built/roles.js +253 -52
  50. package/lib/built/segment-contract/assert.js +8 -2
  51. package/lib/built/segment-contract/delivery.js +1 -0
  52. package/lib/built/segment-contract/index.d.ts +3 -3
  53. package/lib/built/segment-contract/index.js +2 -2
  54. package/lib/built/segment-contract/json-schema.d.ts +39 -5
  55. package/lib/built/segment-contract/json-schema.js +207 -24
  56. package/lib/built/segment-contract/preview.js +8 -1
  57. package/lib/built/segment-contract/text.js +1 -1
  58. package/lib/built/segment-contract/types.d.ts +2 -2
  59. package/lib/built/segment-contract/validate.d.ts +1553 -224
  60. package/lib/built/segment-contract/validate.js +39 -3
  61. package/lib/built/tool-access.d.ts +5 -0
  62. package/lib/built/tool-access.js +17 -0
  63. package/lib/built/user-interaction.d.ts +5 -4
  64. package/lib/built/user-interaction.js +64 -52
  65. package/lib/errors.d.ts +1 -18
  66. package/lib/errors.js +1 -26
  67. package/lib/feature/command-public-api.d.ts +5 -0
  68. package/lib/feature/command-public-api.js +5 -0
  69. package/lib/feature/command.d.ts +2 -0
  70. package/lib/feature/command.js +1 -0
  71. package/lib/feature/component.d.ts +1 -0
  72. package/lib/feature/component.js +1 -0
  73. package/lib/feature/handler.d.ts +13 -7
  74. package/lib/feature/handler.js +2 -1
  75. package/lib/feature/middleware-public-api.d.ts +6 -0
  76. package/lib/feature/middleware-public-api.js +6 -0
  77. package/lib/feature/middleware.d.ts +22 -2
  78. package/lib/feature/middleware.js +7 -2
  79. package/lib/im-scene.d.ts +4 -3
  80. package/lib/im-scene.js +9 -9
  81. package/lib/im-session-id.d.ts +20 -12
  82. package/lib/im-session-id.js +8 -8
  83. package/lib/index.d.ts +19 -48
  84. package/lib/index.js +14 -41
  85. package/lib/jsx/intrinsic-elements.d.ts +83 -0
  86. package/lib/jsx/message-renderer.d.ts +13 -0
  87. package/lib/jsx/message-renderer.js +128 -0
  88. package/lib/jsx/message-tags.d.ts +133 -0
  89. package/lib/jsx/message-tags.js +50 -0
  90. package/lib/jsx-dev-runtime.d.ts +2 -2
  91. package/lib/jsx-dev-runtime.js +1 -2
  92. package/lib/jsx-runtime.d.ts +2 -12
  93. package/lib/jsx-runtime.js +1 -10
  94. package/lib/jsx.d.ts +6 -30
  95. package/lib/jsx.js +3 -93
  96. package/lib/message.d.ts +0 -40
  97. package/lib/message.js +1 -27
  98. package/lib/models/system-log.d.ts +0 -2
  99. package/lib/models/system-log.js +1 -8
  100. package/lib/models/user.d.ts +0 -2
  101. package/lib/models/user.js +1 -7
  102. package/lib/notice.d.ts +38 -33
  103. package/lib/notice.js +23 -7
  104. package/lib/plugin-runtime/im/command-feedback.d.ts +59 -0
  105. package/lib/plugin-runtime/im/command-feedback.js +148 -0
  106. package/lib/plugin-runtime/im/contracts.d.ts +217 -32
  107. package/lib/plugin-runtime/im/contracts.js +141 -23
  108. package/lib/plugin-runtime/im/conversation-runtime.d.ts +42 -0
  109. package/lib/plugin-runtime/im/conversation-runtime.js +451 -0
  110. package/lib/plugin-runtime/im/endpoint-runtime.d.ts +89 -0
  111. package/lib/plugin-runtime/im/endpoint-runtime.js +381 -0
  112. package/lib/plugin-runtime/im/feature-gate.d.ts +21 -0
  113. package/lib/plugin-runtime/im/feature-gate.js +88 -0
  114. package/lib/plugin-runtime/im/host/component-host-installer.d.ts +2 -0
  115. package/lib/plugin-runtime/im/host/component-host-installer.js +14 -0
  116. package/lib/plugin-runtime/im/host/conversation-migration.d.ts +5 -0
  117. package/lib/plugin-runtime/im/host/conversation-migration.js +75 -0
  118. package/lib/plugin-runtime/im/host/database-config.d.ts +10 -0
  119. package/lib/plugin-runtime/im/host/database-config.js +114 -0
  120. package/lib/plugin-runtime/im/host/database-host-installer.d.ts +29 -0
  121. package/lib/plugin-runtime/im/host/database-host-installer.js +442 -0
  122. package/lib/plugin-runtime/im/host/database-state.d.ts +9 -0
  123. package/lib/plugin-runtime/im/host/database-state.js +91 -0
  124. package/lib/plugin-runtime/im/host/index.d.ts +8 -0
  125. package/lib/plugin-runtime/im/host/index.js +8 -0
  126. package/lib/plugin-runtime/im/host/locale-host-installer.d.ts +3 -0
  127. package/lib/plugin-runtime/im/host/locale-host-installer.js +60 -0
  128. package/lib/plugin-runtime/im/host/outbound-host-installer.d.ts +8 -0
  129. package/lib/plugin-runtime/im/host/outbound-host-installer.js +153 -0
  130. package/lib/plugin-runtime/im/host/sender-enrichment.d.ts +34 -0
  131. package/lib/plugin-runtime/im/host/sender-enrichment.js +82 -0
  132. package/lib/plugin-runtime/im/im-runtime.d.ts +40 -111
  133. package/lib/plugin-runtime/im/im-runtime.js +234 -1059
  134. package/lib/plugin-runtime/im/inbound-dedup.d.ts +84 -0
  135. package/lib/plugin-runtime/im/inbound-dedup.js +322 -0
  136. package/lib/plugin-runtime/im/inbound-origin.d.ts +150 -0
  137. package/lib/plugin-runtime/im/inbound-origin.js +183 -0
  138. package/lib/plugin-runtime/im/inbound-runtime.d.ts +59 -0
  139. package/lib/plugin-runtime/im/inbound-runtime.js +478 -0
  140. package/lib/plugin-runtime/im/inbound-spine.d.ts +196 -0
  141. package/lib/plugin-runtime/im/inbound-spine.js +335 -0
  142. package/lib/plugin-runtime/im/index.d.ts +15 -4
  143. package/lib/plugin-runtime/im/index.js +11 -4
  144. package/lib/plugin-runtime/im/interaction-runtime.d.ts +50 -0
  145. package/lib/plugin-runtime/im/interaction-runtime.js +390 -0
  146. package/lib/plugin-runtime/im/interactive-router.d.ts +81 -0
  147. package/lib/plugin-runtime/im/interactive-router.js +382 -0
  148. package/lib/plugin-runtime/im/message-diagnostics.d.ts +70 -0
  149. package/lib/plugin-runtime/im/message-diagnostics.js +182 -0
  150. package/lib/plugin-runtime/im/message-dispatcher.d.ts +18 -4
  151. package/lib/plugin-runtime/im/message-dispatcher.js +138 -20
  152. package/lib/plugin-runtime/im/message-events.d.ts +85 -0
  153. package/lib/plugin-runtime/im/message-events.js +113 -0
  154. package/lib/plugin-runtime/im/outbound-delivery-runtime.d.ts +39 -0
  155. package/lib/plugin-runtime/im/outbound-delivery-runtime.js +450 -0
  156. package/lib/plugin-runtime/im/outbound-renderer.d.ts +52 -3
  157. package/lib/plugin-runtime/im/outbound-renderer.js +188 -8
  158. package/lib/plugin-runtime/im/outbound-segments.d.ts +29 -5
  159. package/lib/plugin-runtime/im/outbound-segments.js +130 -36
  160. package/lib/plugin-runtime/im/progressive-reply.d.ts +58 -0
  161. package/lib/plugin-runtime/im/progressive-reply.js +501 -0
  162. package/lib/plugin-runtime/im/public-api.d.ts +1 -1
  163. package/lib/request.d.ts +27 -36
  164. package/lib/request.js +14 -6
  165. package/lib/side-event/base.d.ts +64 -44
  166. package/lib/side-event/base.js +72 -19
  167. package/lib/side-event/index.d.ts +1 -1
  168. package/lib/side-event/index.js +1 -1
  169. package/lib/side-event/normalize.d.ts +7 -38
  170. package/lib/side-event/normalize.js +4 -109
  171. package/lib/side-event/scene-events.d.ts +40 -0
  172. package/lib/side-event/scene-events.js +147 -0
  173. package/lib/side-event/types.d.ts +4 -13
  174. package/lib/side-event/types.js +1 -55
  175. package/lib/system-event.d.ts +17 -12
  176. package/lib/system-event.js +8 -6
  177. package/lib/types.d.ts +23 -167
  178. package/lib/utils.d.ts +50 -33
  179. package/lib/utils.js +12 -185
  180. package/lib/venue/contracts.d.ts +21 -0
  181. package/lib/venue/contracts.js +3 -0
  182. package/lib/venue/floor-controller.d.ts +11 -0
  183. package/lib/venue/floor-controller.js +63 -0
  184. package/lib/venue/index.d.ts +13 -0
  185. package/lib/venue/index.js +11 -0
  186. package/lib/venue/membership-port.d.ts +23 -0
  187. package/lib/venue/membership-port.js +141 -0
  188. package/lib/venue/projector.d.ts +38 -0
  189. package/lib/venue/projector.js +45 -0
  190. package/lib/venue/registry.d.ts +16 -0
  191. package/lib/venue/registry.js +63 -0
  192. package/lib/venue/router.d.ts +19 -0
  193. package/lib/venue/router.js +101 -0
  194. package/lib/venue/send-limiter.d.ts +17 -0
  195. package/lib/venue/send-limiter.js +73 -0
  196. package/lib/venue/validator.d.ts +6 -0
  197. package/lib/venue/validator.js +160 -0
  198. package/package.json +24 -50
  199. package/lib/adapter.d.ts +0 -145
  200. package/lib/adapter.js +0 -377
  201. package/lib/built/adapter-process.d.ts +0 -58
  202. package/lib/built/adapter-process.js +0 -128
  203. package/lib/built/agent-preset.d.ts +0 -64
  204. package/lib/built/agent-preset.js +0 -79
  205. package/lib/built/ai-outbound/adapter-access.d.ts +0 -3
  206. package/lib/built/ai-outbound/adapter-access.js +0 -9
  207. package/lib/built/ai-outbound/extensions/qq-message.d.ts +0 -3
  208. package/lib/built/ai-outbound/extensions/qq-message.js +0 -23
  209. package/lib/built/authorization.d.ts +0 -10
  210. package/lib/built/authorization.js +0 -76
  211. package/lib/built/command.d.ts +0 -72
  212. package/lib/built/command.js +0 -105
  213. package/lib/built/component.d.ts +0 -67
  214. package/lib/built/component.js +0 -97
  215. package/lib/built/config.d.ts +0 -98
  216. package/lib/built/config.js +0 -372
  217. package/lib/built/connect-endpoint-instance.d.ts +0 -17
  218. package/lib/built/connect-endpoint-instance.js +0 -42
  219. package/lib/built/database.d.ts +0 -68
  220. package/lib/built/database.js +0 -106
  221. package/lib/built/dispatcher.d.ts +0 -141
  222. package/lib/built/dispatcher.js +0 -383
  223. package/lib/built/endpoint-commands.d.ts +0 -3
  224. package/lib/built/endpoint-commands.js +0 -99
  225. package/lib/built/endpoint-lifecycle-service.d.ts +0 -28
  226. package/lib/built/endpoint-lifecycle-service.js +0 -242
  227. package/lib/built/endpoint-lifecycle.d.ts +0 -27
  228. package/lib/built/endpoint-lifecycle.js +0 -36
  229. package/lib/built/endpoint-manager.d.ts +0 -34
  230. package/lib/built/html-renderer-loader.d.ts +0 -13
  231. package/lib/built/html-renderer-loader.js +0 -33
  232. package/lib/built/inbound-pipeline.d.ts +0 -37
  233. package/lib/built/inbound-pipeline.js +0 -63
  234. package/lib/built/inbound-runner.d.ts +0 -22
  235. package/lib/built/inbound-runner.js +0 -34
  236. package/lib/built/interactive-segment-contract.d.ts +0 -6
  237. package/lib/built/interactive-segment-contract.js +0 -9
  238. package/lib/built/interactive-segments/fallback-store.d.ts +0 -29
  239. package/lib/built/interactive-segments/fallback-store.js +0 -63
  240. package/lib/built/interactive-segments/handlers.d.ts +0 -16
  241. package/lib/built/interactive-segments/handlers.js +0 -74
  242. package/lib/built/introspection-format.d.ts +0 -10
  243. package/lib/built/introspection-format.js +0 -28
  244. package/lib/built/management-command-guard.d.ts +0 -15
  245. package/lib/built/management-command-guard.js +0 -25
  246. package/lib/built/message-filter.d.ts +0 -176
  247. package/lib/built/message-filter.js +0 -239
  248. package/lib/built/optional-peer-import.d.ts +0 -3
  249. package/lib/built/optional-peer-import.js +0 -33
  250. package/lib/built/outbound-media-contract.d.ts +0 -22
  251. package/lib/built/outbound-media-contract.js +0 -10
  252. package/lib/built/permission.d.ts +0 -51
  253. package/lib/built/permission.js +0 -99
  254. package/lib/built/permit-check.d.ts +0 -7
  255. package/lib/built/permit-check.js +0 -35
  256. package/lib/built/permit-parse.d.ts +0 -16
  257. package/lib/built/permit-parse.js +0 -32
  258. package/lib/built/platform-permit.d.ts +0 -20
  259. package/lib/built/platform-permit.js +0 -91
  260. package/lib/built/queue-im-field-contract.d.ts +0 -32
  261. package/lib/built/queue-im-field-contract.js +0 -67
  262. package/lib/built/rich-segments/adapter-policies.d.ts +0 -9
  263. package/lib/built/rich-segments/adapter-policies.js +0 -27
  264. package/lib/built/rich-segments/base.d.ts +0 -11
  265. package/lib/built/rich-segments/base.js +0 -24
  266. package/lib/built/rich-segments/builtins.d.ts +0 -4
  267. package/lib/built/rich-segments/builtins.js +0 -40
  268. package/lib/built/rich-segments/capabilities.d.ts +0 -6
  269. package/lib/built/rich-segments/capabilities.js +0 -38
  270. package/lib/built/rich-segments/html-segment.d.ts +0 -15
  271. package/lib/built/rich-segments/html-segment.js +0 -62
  272. package/lib/built/rich-segments/index.d.ts +0 -13
  273. package/lib/built/rich-segments/index.js +0 -13
  274. package/lib/built/rich-segments/markdown-segment.d.ts +0 -14
  275. package/lib/built/rich-segments/markdown-segment.js +0 -58
  276. package/lib/built/rich-segments/qrcode-segment.d.ts +0 -18
  277. package/lib/built/rich-segments/qrcode-segment.js +0 -73
  278. package/lib/built/rich-segments/registry.d.ts +0 -16
  279. package/lib/built/rich-segments/registry.js +0 -52
  280. package/lib/built/rich-segments/resolve.d.ts +0 -5
  281. package/lib/built/rich-segments/resolve.js +0 -87
  282. package/lib/built/rich-segments/tts-segment.d.ts +0 -13
  283. package/lib/built/rich-segments/tts-segment.js +0 -51
  284. package/lib/built/rich-segments/types.d.ts +0 -79
  285. package/lib/built/rich-segments/types.js +0 -17
  286. package/lib/built/runtime-io.d.ts +0 -9
  287. package/lib/built/runtime-io.js +0 -67
  288. package/lib/built/schedule.d.ts +0 -54
  289. package/lib/built/schedule.js +0 -112
  290. package/lib/built/schema-endpoint-manager.d.ts +0 -17
  291. package/lib/built/schema-endpoint-manager.js +0 -73
  292. package/lib/built/schema-feature.d.ts +0 -77
  293. package/lib/built/schema-feature.js +0 -130
  294. package/lib/built/skill.d.ts +0 -120
  295. package/lib/built/skill.js +0 -151
  296. package/lib/built/speech-loader.d.ts +0 -14
  297. package/lib/built/speech-loader.js +0 -32
  298. package/lib/built/tool.d.ts +0 -151
  299. package/lib/built/tool.js +0 -388
  300. package/lib/command.d.ts +0 -50
  301. package/lib/command.js +0 -106
  302. package/lib/component.d.ts +0 -26
  303. package/lib/component.js +0 -583
  304. package/lib/endpoint-capabilities.d.ts +0 -46
  305. package/lib/endpoint-capabilities.js +0 -55
  306. package/lib/endpoint.d.ts +0 -19
  307. package/lib/endpoint.js +0 -3
  308. package/lib/host-plugin-registry.d.ts +0 -8
  309. package/lib/host-plugin-registry.js +0 -12
  310. package/lib/plugin-context.d.ts +0 -27
  311. package/lib/plugin-context.js +0 -64
  312. package/lib/plugin-runtime/im/interactive.d.ts +0 -26
  313. package/lib/plugin-runtime/im/interactive.js +0 -46
  314. package/lib/plugin-runtime/im/login-assist-host.d.ts +0 -6
  315. package/lib/plugin-runtime/im/login-assist-host.js +0 -6
  316. package/lib/plugin-runtime/im/message-bus.d.ts +0 -38
  317. package/lib/plugin-runtime/im/message-bus.js +0 -40
  318. package/lib/plugin-runtime/im/service-tokens.d.ts +0 -18
  319. package/lib/plugin-runtime/im/service-tokens.js +0 -13
  320. package/lib/plugin.d.ts +0 -268
  321. package/lib/plugin.js +0 -583
  322. package/lib/schema-interaction.d.ts +0 -117
  323. package/lib/schema-interaction.js +0 -247
  324. package/lib/side-event/dispatch.d.ts +0 -15
  325. package/lib/side-event/dispatch.js +0 -140
  326. package/lib/tool-zod.d.ts +0 -43
  327. package/lib/tool-zod.js +0 -184
  328. /package/lib/{built/endpoint-manager.js → jsx/intrinsic-elements.js} +0 -0
@@ -1,32 +0,0 @@
1
- import type { MessageType } from '../message.js';
2
- import type { SendContent, SendOptions } from '../types.js';
3
- import { type IMDeliveryTarget } from '../im-scene.js';
4
- export interface QueueEnvelope<TDetail extends Record<string, unknown> = Record<string, unknown>> {
5
- kind: string;
6
- type: string;
7
- detail: TDetail;
8
- ts?: number | string;
9
- }
10
- export interface NormalizedQueueOutboundDetail {
11
- context: string;
12
- endpoint: string;
13
- channelId: string;
14
- channelType: MessageType;
15
- content: SendContent;
16
- senderId?: string;
17
- }
18
- export declare class QueueIMFieldContractError extends Error {
19
- readonly code: 'missing_field' | 'invalid_type';
20
- readonly field: string;
21
- constructor(message: string, code: 'missing_field' | 'invalid_type', field: string);
22
- }
23
- export declare function isMessageType(value: unknown): value is MessageType;
24
- /** Normalize queue outbound detail into the canonical queue-IM shape. */
25
- export declare function normalizeQueueOutboundDetail(record: Record<string, unknown>): NormalizedQueueOutboundDetail;
26
- export declare function toSendOptions(detail: NormalizedQueueOutboundDetail): SendOptions;
27
- export interface QueueIMSceneTargetDetail {
28
- target: IMDeliveryTarget;
29
- content: SendContent;
30
- }
31
- export declare function sceneTargetToSendOptions(detail: QueueIMSceneTargetDetail): SendOptions;
32
- export declare function normalizeRecordToSendOptions(record: Record<string, unknown>): SendOptions;
@@ -1,67 +0,0 @@
1
- import { sceneRefToSendOptions } from '../im-scene.js';
2
- export class QueueIMFieldContractError extends Error {
3
- code;
4
- field;
5
- constructor(message, code, field) {
6
- super(message);
7
- this.code = code;
8
- this.field = field;
9
- this.name = 'QueueIMFieldContractError';
10
- }
11
- }
12
- const MESSAGE_TYPES = new Set(['group', 'private', 'channel']);
13
- export function isMessageType(value) {
14
- return typeof value === 'string' && MESSAGE_TYPES.has(value);
15
- }
16
- function requireString(value, field) {
17
- if (typeof value === 'string' && value.length > 0)
18
- return value;
19
- throw new QueueIMFieldContractError(`Missing required queue IM field: ${field}`, 'missing_field', field);
20
- }
21
- function requireContent(value) {
22
- if (value == null) {
23
- throw new QueueIMFieldContractError('Missing required queue IM field: content', 'missing_field', 'content');
24
- }
25
- return value;
26
- }
27
- /** Normalize queue outbound detail into the canonical queue-IM shape. */
28
- export function normalizeQueueOutboundDetail(record) {
29
- const context = requireString(record.context, 'context');
30
- const endpoint = requireString(record.endpoint, 'endpoint');
31
- const channelId = requireString(record.channelId, 'channelId');
32
- const channelTypeValue = record.channelType;
33
- if (!isMessageType(channelTypeValue)) {
34
- throw new QueueIMFieldContractError(`Invalid queue IM field channelType: ${String(channelTypeValue)}`, 'invalid_type', 'channelType');
35
- }
36
- const normalized = {
37
- context,
38
- endpoint,
39
- channelId,
40
- channelType: channelTypeValue,
41
- content: requireContent(record.content),
42
- };
43
- if (typeof record.senderId === 'string')
44
- normalized.senderId = record.senderId;
45
- return normalized;
46
- }
47
- export function toSendOptions(detail) {
48
- return {
49
- context: detail.context,
50
- endpoint: detail.endpoint,
51
- id: detail.channelId,
52
- type: detail.channelType,
53
- content: detail.content,
54
- };
55
- }
56
- export function sceneTargetToSendOptions(detail) {
57
- return sceneRefToSendOptions(detail.target, detail.content);
58
- }
59
- export function normalizeRecordToSendOptions(record) {
60
- if (record.target && typeof record.target === 'object') {
61
- return sceneTargetToSendOptions({
62
- target: record.target,
63
- content: requireContent(record.content),
64
- });
65
- }
66
- return toSendOptions(normalizeQueueOutboundDetail(record));
67
- }
@@ -1,9 +0,0 @@
1
- import { type OutboundRichSegmentPolicy } from './types.js';
2
- /** 全功能 IM:html/markdown/qrcode→image,tts→audio */
3
- export declare const OUTBOUND_RICH_SEGMENT_POLICY_IM_FULL: OutboundRichSegmentPolicy;
4
- /** 仅文本降级(无富媒体出站能力) */
5
- export declare const OUTBOUND_RICH_SEGMENT_POLICY_TEXT_ONLY: OutboundRichSegmentPolicy;
6
- /** 默认 registry 等价(html/markdown 文本,qrcode 图片,tts 音频) */
7
- export declare const OUTBOUND_RICH_SEGMENT_POLICY_IM_DEFAULT: OutboundRichSegmentPolicy;
8
- /** 无音频出站(tts 降级 text) */
9
- export declare const OUTBOUND_RICH_SEGMENT_POLICY_NO_AUDIO: OutboundRichSegmentPolicy;
@@ -1,27 +0,0 @@
1
- import { BUILTIN_RICH_SEGMENT_KINDS, RICH_SEGMENT_MODE } from './types.js';
2
- /** 全功能 IM:html/markdown/qrcode→image,tts→audio */
3
- export const OUTBOUND_RICH_SEGMENT_POLICY_IM_FULL = {
4
- [BUILTIN_RICH_SEGMENT_KINDS.QRCODE]: RICH_SEGMENT_MODE.IMAGE,
5
- [BUILTIN_RICH_SEGMENT_KINDS.HTML]: RICH_SEGMENT_MODE.IMAGE,
6
- [BUILTIN_RICH_SEGMENT_KINDS.MARKDOWN]: RICH_SEGMENT_MODE.IMAGE,
7
- [BUILTIN_RICH_SEGMENT_KINDS.TTS]: RICH_SEGMENT_MODE.AUDIO,
8
- };
9
- /** 仅文本降级(无富媒体出站能力) */
10
- export const OUTBOUND_RICH_SEGMENT_POLICY_TEXT_ONLY = {
11
- [BUILTIN_RICH_SEGMENT_KINDS.QRCODE]: RICH_SEGMENT_MODE.TEXT,
12
- [BUILTIN_RICH_SEGMENT_KINDS.HTML]: RICH_SEGMENT_MODE.TEXT,
13
- [BUILTIN_RICH_SEGMENT_KINDS.MARKDOWN]: RICH_SEGMENT_MODE.TEXT,
14
- [BUILTIN_RICH_SEGMENT_KINDS.TTS]: RICH_SEGMENT_MODE.TEXT,
15
- };
16
- /** 默认 registry 等价(html/markdown 文本,qrcode 图片,tts 音频) */
17
- export const OUTBOUND_RICH_SEGMENT_POLICY_IM_DEFAULT = {
18
- [BUILTIN_RICH_SEGMENT_KINDS.QRCODE]: RICH_SEGMENT_MODE.IMAGE,
19
- [BUILTIN_RICH_SEGMENT_KINDS.HTML]: RICH_SEGMENT_MODE.TEXT,
20
- [BUILTIN_RICH_SEGMENT_KINDS.MARKDOWN]: RICH_SEGMENT_MODE.TEXT,
21
- [BUILTIN_RICH_SEGMENT_KINDS.TTS]: RICH_SEGMENT_MODE.AUDIO,
22
- };
23
- /** 无音频出站(tts 降级 text) */
24
- export const OUTBOUND_RICH_SEGMENT_POLICY_NO_AUDIO = {
25
- ...OUTBOUND_RICH_SEGMENT_POLICY_IM_FULL,
26
- [BUILTIN_RICH_SEGMENT_KINDS.TTS]: RICH_SEGMENT_MODE.TEXT,
27
- };
@@ -1,11 +0,0 @@
1
- import type { MessageElement } from '../../types.js';
2
- import type { RichSegmentRenderContext, RichSegmentRenderResult } from './types.js';
3
- export declare abstract class RichSegment<TData> {
4
- readonly data: TData;
5
- abstract readonly segmentType: string;
6
- constructor(data: TData);
7
- abstract render(mode: string, ctx?: RichSegmentRenderContext): Promise<RichSegmentRenderResult>;
8
- toJSON(): MessageElement;
9
- }
10
- export declare function isRichSegment(item: unknown): item is RichSegment<unknown>;
11
- export declare function richSegmentKind(item: MessageElement | string): string | null;
@@ -1,24 +0,0 @@
1
- import { richSegmentRegistry } from './registry.js';
2
- export class RichSegment {
3
- data;
4
- constructor(data) {
5
- this.data = data;
6
- }
7
- toJSON() {
8
- return { type: this.segmentType, data: this.data };
9
- }
10
- }
11
- export function isRichSegment(item) {
12
- return item instanceof RichSegment;
13
- }
14
- export function richSegmentKind(item) {
15
- if (typeof item === 'string')
16
- return null;
17
- const type = item.type;
18
- if (typeof type !== 'string')
19
- return null;
20
- if (richSegmentRegistry.has(type)) {
21
- return type;
22
- }
23
- return null;
24
- }
@@ -1,4 +0,0 @@
1
- /** 内置 kind 的默认出站 policy(由 registry 生成,增 kind 时自动包含) */
2
- export declare const DEFAULT_OUTBOUND_RICH_SEGMENT_POLICY: import("./types.js").OutboundRichSegmentPolicy;
3
- /** 测试:清空 registry 后重新注册内置 kind */
4
- export declare function resetBuiltinRichSegmentKindsForTests(): void;
@@ -1,40 +0,0 @@
1
- import { registerRichSegmentKind, richSegmentRegistry } from './registry.js';
2
- import { wrapQrcodeSegment } from './qrcode-segment.js';
3
- import { wrapHtmlSegment } from './html-segment.js';
4
- import { wrapMarkdownSegment } from './markdown-segment.js';
5
- import { wrapTtsSegment } from './tts-segment.js';
6
- import { BUILTIN_RICH_SEGMENT_KINDS, RICH_SEGMENT_MODE } from './types.js';
7
- function registerBuiltinRichSegmentKinds() {
8
- registerRichSegmentKind({
9
- kind: BUILTIN_RICH_SEGMENT_KINDS.QRCODE,
10
- defaultMode: RICH_SEGMENT_MODE.IMAGE,
11
- modes: [RICH_SEGMENT_MODE.IMAGE, RICH_SEGMENT_MODE.TEXT, RICH_SEGMENT_MODE.ORIGIN],
12
- wrap: wrapQrcodeSegment,
13
- });
14
- registerRichSegmentKind({
15
- kind: BUILTIN_RICH_SEGMENT_KINDS.HTML,
16
- defaultMode: RICH_SEGMENT_MODE.TEXT,
17
- modes: [RICH_SEGMENT_MODE.IMAGE, RICH_SEGMENT_MODE.TEXT, RICH_SEGMENT_MODE.ORIGIN],
18
- wrap: wrapHtmlSegment,
19
- });
20
- registerRichSegmentKind({
21
- kind: BUILTIN_RICH_SEGMENT_KINDS.MARKDOWN,
22
- defaultMode: RICH_SEGMENT_MODE.TEXT,
23
- modes: [RICH_SEGMENT_MODE.IMAGE, RICH_SEGMENT_MODE.TEXT, RICH_SEGMENT_MODE.ORIGIN],
24
- wrap: wrapMarkdownSegment,
25
- });
26
- registerRichSegmentKind({
27
- kind: BUILTIN_RICH_SEGMENT_KINDS.TTS,
28
- defaultMode: RICH_SEGMENT_MODE.AUDIO,
29
- modes: [RICH_SEGMENT_MODE.ORIGIN, RICH_SEGMENT_MODE.AUDIO, RICH_SEGMENT_MODE.TEXT],
30
- wrap: wrapTtsSegment,
31
- });
32
- }
33
- registerBuiltinRichSegmentKinds();
34
- /** 内置 kind 的默认出站 policy(由 registry 生成,增 kind 时自动包含) */
35
- export const DEFAULT_OUTBOUND_RICH_SEGMENT_POLICY = richSegmentRegistry.buildDefaultPolicy();
36
- /** 测试:清空 registry 后重新注册内置 kind */
37
- export function resetBuiltinRichSegmentKindsForTests() {
38
- richSegmentRegistry.clearForTests();
39
- registerBuiltinRichSegmentKinds();
40
- }
@@ -1,6 +0,0 @@
1
- import type { RichSegmentCapabilityLoader, RichSegmentCapabilityLoaderOptions, RichSegmentRenderContext } from './types.js';
2
- /** 注册 optional 包能力(如 html-renderer、未来 media-pipeline) */
3
- export declare function registerRichSegmentCapabilityLoader(id: string, loader: RichSegmentCapabilityLoader): void;
4
- /** 测试隔离 */
5
- export declare function resetRichSegmentCapabilityLoadersForTests(): void;
6
- export declare function createRichSegmentRenderContext(options?: RichSegmentCapabilityLoaderOptions): RichSegmentRenderContext;
@@ -1,38 +0,0 @@
1
- import { loadHtmlRenderer } from '../html-renderer-loader.js';
2
- import { loadSpeechPipeline } from '../speech-loader.js';
3
- const capabilityLoaders = new Map();
4
- /** 注册 optional 包能力(如 html-renderer、未来 media-pipeline) */
5
- export function registerRichSegmentCapabilityLoader(id, loader) {
6
- capabilityLoaders.set(id, loader);
7
- }
8
- /** 测试隔离 */
9
- export function resetRichSegmentCapabilityLoadersForTests() {
10
- capabilityLoaders.clear();
11
- registerCoreRichSegmentCapabilityLoaders();
12
- }
13
- function registerCoreRichSegmentCapabilityLoaders() {
14
- registerRichSegmentCapabilityLoader('html-renderer', async (options) => loadHtmlRenderer({
15
- getConfig: options.getConfig,
16
- warn: options.warn,
17
- }));
18
- registerRichSegmentCapabilityLoader('speech', async (options) => loadSpeechPipeline({
19
- getConfig: options.getConfig,
20
- warn: options.warn,
21
- }));
22
- }
23
- registerCoreRichSegmentCapabilityLoaders();
24
- export function createRichSegmentRenderContext(options = {}) {
25
- const cache = new Map();
26
- const resolveCapability = async (id) => {
27
- if (!cache.has(id)) {
28
- const loader = capabilityLoaders.get(id);
29
- cache.set(id, loader ? loader(options) : Promise.resolve(undefined));
30
- }
31
- return cache.get(id);
32
- };
33
- return {
34
- resolveCapability,
35
- warn: options.warn,
36
- logContentChain: options.logContentChain,
37
- };
38
- }
@@ -1,15 +0,0 @@
1
- import { RichSegment } from './base.js';
2
- import { type RichSegmentRenderContext, type RichSegmentRenderResult } from './types.js';
3
- export interface HtmlSegmentData {
4
- html: string;
5
- text?: string;
6
- width?: number;
7
- backgroundColor?: string;
8
- fileName?: string;
9
- }
10
- export declare class HtmlSegment extends RichSegment<HtmlSegmentData> {
11
- readonly segmentType: "html";
12
- readonly type: "html";
13
- render(mode: string, ctx?: RichSegmentRenderContext): Promise<RichSegmentRenderResult>;
14
- }
15
- export declare function wrapHtmlSegment(data: Record<string, unknown>): HtmlSegment;
@@ -1,62 +0,0 @@
1
- import { segment } from '../../utils.js';
2
- import { htmlToFallbackText } from '../html-to-text.js';
3
- import { RichSegment } from './base.js';
4
- import { RICH_SEGMENT_MODE } from './types.js';
5
- async function resolveHtmlRenderer(ctx) {
6
- if (!ctx)
7
- return undefined;
8
- return ctx.resolveCapability('html-renderer');
9
- }
10
- export class HtmlSegment extends RichSegment {
11
- segmentType = 'html';
12
- type = 'html';
13
- async render(mode, ctx) {
14
- if (mode === RICH_SEGMENT_MODE.ORIGIN) {
15
- return this.toJSON();
16
- }
17
- if (mode === RICH_SEGMENT_MODE.TEXT) {
18
- if (typeof this.data.text === 'string' && this.data.text.length > 0) {
19
- return segment.text(this.data.text);
20
- }
21
- const html = typeof this.data.html === 'string' ? this.data.html : '';
22
- return segment.text(html ? htmlToFallbackText(html) : '');
23
- }
24
- if (mode === RICH_SEGMENT_MODE.IMAGE) {
25
- const html = typeof this.data.html === 'string' ? this.data.html : '';
26
- if (!html) {
27
- return segment.text('');
28
- }
29
- const renderer = await resolveHtmlRenderer(ctx);
30
- if (!renderer) {
31
- return this.render(RICH_SEGMENT_MODE.TEXT, ctx);
32
- }
33
- try {
34
- const result = await renderer.render(html, {
35
- width: typeof this.data.width === 'number' ? this.data.width : 540,
36
- format: 'png',
37
- backgroundColor: typeof this.data.backgroundColor === 'string' ? this.data.backgroundColor : '#d8dce3',
38
- });
39
- if (result.format !== 'png' || typeof result.data !== 'object') {
40
- return this.render(RICH_SEGMENT_MODE.TEXT, ctx);
41
- }
42
- const base64 = Buffer.from(result.data).toString('base64');
43
- const fileName = typeof this.data.fileName === 'string' ? this.data.fileName : 'card.png';
44
- return segment('image', { url: `base64://${base64}`, name: fileName });
45
- }
46
- catch {
47
- return this.render(RICH_SEGMENT_MODE.TEXT, ctx);
48
- }
49
- }
50
- return this.render(RICH_SEGMENT_MODE.TEXT, ctx);
51
- }
52
- }
53
- export function wrapHtmlSegment(data) {
54
- const html = typeof data.html === 'string' ? data.html : '';
55
- return new HtmlSegment({
56
- html,
57
- text: typeof data.text === 'string' ? data.text : undefined,
58
- width: typeof data.width === 'number' ? data.width : undefined,
59
- backgroundColor: typeof data.backgroundColor === 'string' ? data.backgroundColor : undefined,
60
- fileName: typeof data.fileName === 'string' ? data.fileName : undefined,
61
- });
62
- }
@@ -1,13 +0,0 @@
1
- import './builtins.js';
2
- export * from './types.js';
3
- export * from './registry.js';
4
- export * from './capabilities.js';
5
- export { DEFAULT_OUTBOUND_RICH_SEGMENT_POLICY, resetBuiltinRichSegmentKindsForTests, } from './builtins.js';
6
- export * from './base.js';
7
- export * from './qrcode-segment.js';
8
- export * from './html-segment.js';
9
- export * from './markdown-segment.js';
10
- export * from './tts-segment.js';
11
- export * from './markdown-to-text.js';
12
- export * from './resolve.js';
13
- export * from './adapter-policies.js';
@@ -1,13 +0,0 @@
1
- import './builtins.js';
2
- export * from './types.js';
3
- export * from './registry.js';
4
- export * from './capabilities.js';
5
- export { DEFAULT_OUTBOUND_RICH_SEGMENT_POLICY, resetBuiltinRichSegmentKindsForTests, } from './builtins.js';
6
- export * from './base.js';
7
- export * from './qrcode-segment.js';
8
- export * from './html-segment.js';
9
- export * from './markdown-segment.js';
10
- export * from './tts-segment.js';
11
- export * from './markdown-to-text.js';
12
- export * from './resolve.js';
13
- export * from './adapter-policies.js';
@@ -1,14 +0,0 @@
1
- import { RichSegment } from './base.js';
2
- import { type RichSegmentRenderContext, type RichSegmentRenderResult } from './types.js';
3
- export interface MarkdownSegmentData {
4
- content: string;
5
- width?: number;
6
- backgroundColor?: string;
7
- fileName?: string;
8
- }
9
- export declare class MarkdownSegment extends RichSegment<MarkdownSegmentData> {
10
- readonly segmentType: "markdown";
11
- readonly type: "markdown";
12
- render(mode: string, ctx?: RichSegmentRenderContext): Promise<RichSegmentRenderResult>;
13
- }
14
- export declare function wrapMarkdownSegment(data: Record<string, unknown>): MarkdownSegment;
@@ -1,58 +0,0 @@
1
- import { segment } from '../../utils.js';
2
- import { RichSegment } from './base.js';
3
- import { markdownToHtmlForRender, markdownToPlainText } from './markdown-to-text.js';
4
- import { RICH_SEGMENT_MODE } from './types.js';
5
- async function resolveHtmlRenderer(ctx) {
6
- if (!ctx)
7
- return undefined;
8
- return ctx.resolveCapability('html-renderer');
9
- }
10
- export class MarkdownSegment extends RichSegment {
11
- segmentType = 'markdown';
12
- type = 'markdown';
13
- async render(mode, ctx) {
14
- if (mode === RICH_SEGMENT_MODE.ORIGIN) {
15
- return { type: 'markdown', data: { content: this.data.content } };
16
- }
17
- if (mode === RICH_SEGMENT_MODE.TEXT) {
18
- return segment.text(markdownToPlainText(this.data.content));
19
- }
20
- if (mode === RICH_SEGMENT_MODE.IMAGE) {
21
- const renderer = await resolveHtmlRenderer(ctx);
22
- if (!renderer) {
23
- return this.render(RICH_SEGMENT_MODE.TEXT, ctx);
24
- }
25
- try {
26
- const html = markdownToHtmlForRender(this.data.content);
27
- const result = await renderer.render(html, {
28
- width: typeof this.data.width === 'number' ? this.data.width : 540,
29
- format: 'png',
30
- backgroundColor: typeof this.data.backgroundColor === 'string' ? this.data.backgroundColor : '#ffffff',
31
- });
32
- if (result.format !== 'png' || typeof result.data !== 'object') {
33
- return this.render(RICH_SEGMENT_MODE.TEXT, ctx);
34
- }
35
- const base64 = Buffer.from(result.data).toString('base64');
36
- const fileName = typeof this.data.fileName === 'string' ? this.data.fileName : 'markdown.png';
37
- return segment('image', { url: `base64://${base64}`, name: fileName });
38
- }
39
- catch {
40
- return this.render(RICH_SEGMENT_MODE.TEXT, ctx);
41
- }
42
- }
43
- return this.render(RICH_SEGMENT_MODE.TEXT, ctx);
44
- }
45
- }
46
- export function wrapMarkdownSegment(data) {
47
- const content = typeof data.content === 'string'
48
- ? data.content
49
- : typeof data.text === 'string'
50
- ? data.text
51
- : '';
52
- return new MarkdownSegment({
53
- content,
54
- width: typeof data.width === 'number' ? data.width : undefined,
55
- backgroundColor: typeof data.backgroundColor === 'string' ? data.backgroundColor : undefined,
56
- fileName: typeof data.fileName === 'string' ? data.fileName : undefined,
57
- });
58
- }
@@ -1,18 +0,0 @@
1
- import type { MessageElement } from '../../types.js';
2
- import { type GenerateQrCodeOptions } from '../generated-qrcode.js';
3
- import { RichSegment } from './base.js';
4
- import { type RichSegmentRenderContext, type RichSegmentRenderResult } from './types.js';
5
- export interface QrcodeSegmentData extends GenerateQrCodeOptions {
6
- text: string;
7
- /** process origin 模式终端渲染时使用 */
8
- small?: boolean;
9
- }
10
- export declare function readQrcodeSegmentData(data: Record<string, unknown>): QrcodeSegmentData;
11
- export declare class QrcodeSegment extends RichSegment<QrcodeSegmentData> {
12
- readonly segmentType: "qrcode";
13
- readonly type: "qrcode";
14
- render(mode: string, _ctx?: RichSegmentRenderContext): Promise<RichSegmentRenderResult>;
15
- }
16
- export declare function wrapQrcodeSegment(data: Record<string, unknown>): QrcodeSegment;
17
- /** process endpoint:origin qrcode 段 → 终端 ASCII + 文本占位 */
18
- export declare function interpretOriginQrcodeForProcess(content: MessageElement | string | (MessageElement | string)[]): Promise<MessageElement | string | (MessageElement | string)[]>;
@@ -1,73 +0,0 @@
1
- import { segment } from '../../utils.js';
2
- import { GeneratedQrCode } from '../generated-qrcode.js';
3
- import { RichSegment } from './base.js';
4
- import { RICH_SEGMENT_MODE } from './types.js';
5
- export function readQrcodeSegmentData(data) {
6
- const text = typeof data.text === 'string' ? data.text : '';
7
- if (!text) {
8
- throw new Error('qrcode segment: missing data.text');
9
- }
10
- return {
11
- text,
12
- width: typeof data.width === 'number' ? data.width : undefined,
13
- margin: typeof data.margin === 'number' ? data.margin : undefined,
14
- errorCorrectionLevel: data.errorCorrectionLevel === 'L'
15
- || data.errorCorrectionLevel === 'M'
16
- || data.errorCorrectionLevel === 'Q'
17
- || data.errorCorrectionLevel === 'H'
18
- ? data.errorCorrectionLevel
19
- : undefined,
20
- small: data.small === true ? true : undefined,
21
- };
22
- }
23
- export class QrcodeSegment extends RichSegment {
24
- segmentType = 'qrcode';
25
- type = 'qrcode';
26
- async render(mode, _ctx) {
27
- if (mode === RICH_SEGMENT_MODE.ORIGIN) {
28
- return this.toJSON();
29
- }
30
- if (mode === RICH_SEGMENT_MODE.TEXT) {
31
- return segment.text(`[二维码] ${this.data.text}`);
32
- }
33
- if (mode === RICH_SEGMENT_MODE.IMAGE) {
34
- const qr = await GeneratedQrCode.generate(this.data.text, this.data);
35
- return segment('image', {
36
- url: qr.toDataUrl(),
37
- base64: qr.toString('base64'),
38
- });
39
- }
40
- return this.render(RICH_SEGMENT_MODE.TEXT, _ctx);
41
- }
42
- }
43
- export function wrapQrcodeSegment(data) {
44
- return new QrcodeSegment(readQrcodeSegmentData(data));
45
- }
46
- /** process endpoint:origin qrcode 段 → 终端 ASCII + 文本占位 */
47
- export async function interpretOriginQrcodeForProcess(content) {
48
- const items = Array.isArray(content) ? content : [content];
49
- const out = [];
50
- let changed = false;
51
- for (const item of items) {
52
- if (typeof item === 'string') {
53
- out.push(item);
54
- continue;
55
- }
56
- if (item.type !== 'qrcode') {
57
- out.push(item);
58
- continue;
59
- }
60
- changed = true;
61
- const payload = readQrcodeSegmentData(item.data ?? {});
62
- const qr = await GeneratedQrCode.generate(payload.text, payload);
63
- await qr.printToTerminal({ small: payload.small ?? true });
64
- out.push(segment.text(`[二维码] ${payload.text}`));
65
- }
66
- if (!changed)
67
- return content;
68
- if (out.length === 0)
69
- return segment.text('');
70
- if (out.length === 1)
71
- return out[0];
72
- return out;
73
- }
@@ -1,16 +0,0 @@
1
- import type { OutboundRichSegmentPolicy, RichSegmentKindDefinition } from './types.js';
2
- export declare class RichSegmentRegistry {
3
- #private;
4
- register(definition: RichSegmentKindDefinition): void;
5
- has(kind: string): boolean;
6
- get(kind: string): RichSegmentKindDefinition | undefined;
7
- list(): RichSegmentKindDefinition[];
8
- buildDefaultPolicy(): OutboundRichSegmentPolicy;
9
- resolveMode(policy: OutboundRichSegmentPolicy, kind: string): string;
10
- wrap(kind: string, data: Record<string, unknown>): import("./types.js").RichSegmentLike;
11
- /** 测试隔离:清空后需重新 register builtins */
12
- clearForTests(): void;
13
- }
14
- export declare const RICH_SEGMENT_FALLBACK_MODE = "origin";
15
- export declare const richSegmentRegistry: RichSegmentRegistry;
16
- export declare function registerRichSegmentKind(definition: RichSegmentKindDefinition): void;
@@ -1,52 +0,0 @@
1
- export class RichSegmentRegistry {
2
- #kinds = new Map();
3
- register(definition) {
4
- if (this.#kinds.has(definition.kind)) {
5
- throw new Error(`Rich segment kind already registered: ${definition.kind}`);
6
- }
7
- if (!definition.modes.includes(definition.defaultMode)) {
8
- throw new Error(`Rich segment ${definition.kind}: defaultMode "${definition.defaultMode}" not in modes`);
9
- }
10
- this.#kinds.set(definition.kind, definition);
11
- }
12
- has(kind) {
13
- return this.#kinds.has(kind);
14
- }
15
- get(kind) {
16
- return this.#kinds.get(kind);
17
- }
18
- list() {
19
- return [...this.#kinds.values()];
20
- }
21
- buildDefaultPolicy() {
22
- const policy = {};
23
- for (const def of this.#kinds.values()) {
24
- policy[def.kind] = def.defaultMode;
25
- }
26
- return policy;
27
- }
28
- resolveMode(policy, kind) {
29
- const def = this.#kinds.get(kind);
30
- const requested = policy[kind] ?? def?.defaultMode ?? RICH_SEGMENT_FALLBACK_MODE;
31
- if (def && !def.modes.includes(requested)) {
32
- return def.defaultMode;
33
- }
34
- return requested;
35
- }
36
- wrap(kind, data) {
37
- const def = this.#kinds.get(kind);
38
- if (!def) {
39
- throw new Error(`Unknown rich segment kind: ${kind}`);
40
- }
41
- return def.wrap(data);
42
- }
43
- /** 测试隔离:清空后需重新 register builtins */
44
- clearForTests() {
45
- this.#kinds.clear();
46
- }
47
- }
48
- export const RICH_SEGMENT_FALLBACK_MODE = 'origin';
49
- export const richSegmentRegistry = new RichSegmentRegistry();
50
- export function registerRichSegmentKind(definition) {
51
- richSegmentRegistry.register(definition);
52
- }
@@ -1,5 +0,0 @@
1
- import type { SendContent } from '../../types.js';
2
- import { type OutboundRichSegmentPolicy, type RichSegmentRenderContext } from './types.js';
3
- export declare function hasRichSegment(content: SendContent | undefined): boolean;
4
- /** 按 Adapter 出站策略在 renderSendMessage 首步统一渲染富媒体段 */
5
- export declare function resolveRichSegments(content: SendContent, policy: OutboundRichSegmentPolicy, ctx?: RichSegmentRenderContext): Promise<SendContent>;