@zhin.js/core 1.1.34 → 1.1.37

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 (326) hide show
  1. package/README.md +84 -142
  2. package/lib/built/ai-access.d.ts +36 -0
  3. package/lib/built/ai-access.js +46 -0
  4. package/lib/built/ai-outbound/extensions/onebot-keyboard.d.ts +2 -0
  5. package/lib/built/ai-outbound/extensions/onebot-keyboard.js +67 -0
  6. package/lib/built/ai-outbound/extensions/qq-message.d.ts +3 -0
  7. package/lib/built/ai-outbound/extensions/qq-message.js +23 -0
  8. package/lib/built/ai-outbound/index.d.ts +8 -0
  9. package/lib/built/ai-outbound/index.js +8 -0
  10. package/lib/built/ai-outbound/parse.d.ts +13 -0
  11. package/lib/built/ai-outbound/parse.js +104 -0
  12. package/lib/built/ai-outbound/plain-mention-rewrite.d.ts +6 -0
  13. package/lib/built/ai-outbound/plain-mention-rewrite.js +37 -0
  14. package/lib/built/ai-outbound/prompt.d.ts +11 -0
  15. package/lib/built/ai-outbound/prompt.js +44 -0
  16. package/lib/built/ai-outbound/resolve.d.ts +4 -0
  17. package/lib/built/ai-outbound/resolve.js +64 -0
  18. package/lib/built/ai-outbound/structured-detect.d.ts +3 -0
  19. package/lib/built/ai-outbound/structured-detect.js +6 -0
  20. package/lib/built/ai-outbound/types.d.ts +49 -0
  21. package/lib/built/ai-outbound/types.js +5 -0
  22. package/lib/built/ai-trigger.d.ts +12 -17
  23. package/lib/built/ai-trigger.js +39 -70
  24. package/lib/built/common-adapter-tools.d.ts +33 -29
  25. package/lib/built/common-adapter-tools.js +79 -67
  26. package/lib/built/generated-qrcode.d.ts +24 -0
  27. package/lib/built/generated-qrcode.js +45 -0
  28. package/lib/built/generic-segment-mapper.d.ts +4 -0
  29. package/lib/built/generic-segment-mapper.js +190 -0
  30. package/lib/built/html-segment-fallback.d.ts +2 -5
  31. package/lib/built/html-segment-fallback.js +0 -16
  32. package/lib/built/html-to-text.d.ts +0 -1
  33. package/lib/built/html-to-text.js +15 -15
  34. package/lib/built/interactive-segments/action.d.ts +17 -0
  35. package/lib/built/interactive-segments/action.js +69 -0
  36. package/lib/built/interactive-segments/button-spec.d.ts +10 -0
  37. package/lib/built/interactive-segments/button-spec.js +21 -0
  38. package/lib/built/interactive-segments/index.d.ts +6 -0
  39. package/lib/built/interactive-segments/index.js +6 -0
  40. package/lib/built/interactive-segments/keyboard-segment.d.ts +10 -0
  41. package/lib/built/interactive-segments/keyboard-segment.js +11 -0
  42. package/lib/built/interactive-segments/onebot-keyboard.d.ts +6 -0
  43. package/lib/built/interactive-segments/onebot-keyboard.js +49 -0
  44. package/lib/built/interactive-segments/resolve.d.ts +14 -0
  45. package/lib/built/interactive-segments/resolve.js +109 -0
  46. package/lib/built/interactive-segments/types.d.ts +45 -0
  47. package/lib/built/interactive-segments/types.js +9 -0
  48. package/lib/built/login-assist.d.ts +43 -16
  49. package/lib/built/login-assist.js +113 -11
  50. package/lib/built/message-enrich.d.ts +32 -0
  51. package/lib/built/message-enrich.js +67 -0
  52. package/lib/built/outbound-media-utils.d.ts +9 -0
  53. package/lib/built/outbound-media-utils.js +62 -0
  54. package/lib/built/queue-im-field-contract.d.ts +7 -2
  55. package/lib/built/queue-im-field-contract.js +13 -4
  56. package/lib/built/rich-segments/markdown-to-text.d.ts +3 -0
  57. package/lib/built/rich-segments/markdown-to-text.js +27 -0
  58. package/lib/built/roles.d.ts +4 -5
  59. package/lib/built/roles.js +4 -5
  60. package/lib/built/segment-contract/assert.d.ts +7 -0
  61. package/lib/built/segment-contract/assert.js +39 -0
  62. package/lib/built/segment-contract/delivery.d.ts +5 -0
  63. package/lib/built/segment-contract/delivery.js +40 -0
  64. package/lib/built/segment-contract/image.d.ts +5 -0
  65. package/lib/built/segment-contract/image.js +10 -0
  66. package/lib/built/segment-contract/index.d.ts +10 -0
  67. package/lib/built/segment-contract/index.js +9 -0
  68. package/lib/built/segment-contract/json-schema.d.ts +28 -0
  69. package/lib/built/segment-contract/json-schema.js +128 -0
  70. package/lib/built/segment-contract/media.d.ts +12 -0
  71. package/lib/built/segment-contract/media.js +22 -0
  72. package/lib/built/segment-contract/mention.d.ts +10 -0
  73. package/lib/built/segment-contract/mention.js +26 -0
  74. package/lib/built/segment-contract/preview.d.ts +3 -0
  75. package/lib/built/segment-contract/preview.js +159 -0
  76. package/lib/built/segment-contract/text.d.ts +7 -0
  77. package/lib/built/segment-contract/text.js +34 -0
  78. package/lib/built/segment-contract/types.d.ts +58 -0
  79. package/lib/built/segment-contract/types.js +1 -0
  80. package/lib/built/segment-contract/validate.d.ts +229 -0
  81. package/lib/built/segment-contract/validate.js +172 -0
  82. package/lib/built/tool-access.d.ts +5 -0
  83. package/lib/built/tool-access.js +17 -0
  84. package/lib/built/user-interaction.d.ts +30 -0
  85. package/lib/built/user-interaction.js +244 -0
  86. package/lib/component.d.ts +0 -1
  87. package/lib/component.js +30 -14
  88. package/lib/errors.d.ts +2 -3
  89. package/lib/errors.js +4 -5
  90. package/lib/feature/adapter.d.ts +2 -0
  91. package/lib/feature/adapter.js +2 -0
  92. package/lib/feature/command.d.ts +2 -0
  93. package/lib/feature/command.js +2 -0
  94. package/lib/feature/component.d.ts +2 -0
  95. package/lib/feature/component.js +2 -0
  96. package/lib/feature/handler.d.ts +48 -0
  97. package/lib/feature/handler.js +26 -0
  98. package/lib/feature/middleware.d.ts +2 -0
  99. package/lib/feature/middleware.js +2 -0
  100. package/lib/im-scene.d.ts +29 -0
  101. package/lib/im-scene.js +75 -0
  102. package/lib/im-session-id.d.ts +39 -0
  103. package/lib/im-session-id.js +47 -0
  104. package/lib/index.d.ts +29 -36
  105. package/lib/index.js +27 -41
  106. package/lib/jsx-dev-runtime.d.ts +0 -1
  107. package/lib/jsx-dev-runtime.js +0 -1
  108. package/lib/jsx-runtime.d.ts +1 -1
  109. package/lib/jsx-runtime.js +0 -1
  110. package/lib/jsx.d.ts +19 -22
  111. package/lib/jsx.js +0 -1
  112. package/lib/message.d.ts +17 -12
  113. package/lib/message.js +16 -13
  114. package/lib/models/system-log.d.ts +0 -3
  115. package/lib/models/system-log.js +1 -9
  116. package/lib/models/user.d.ts +0 -3
  117. package/lib/models/user.js +1 -8
  118. package/lib/notice.d.ts +16 -60
  119. package/lib/notice.js +1 -4
  120. package/lib/plugin-runtime/im/contracts.d.ts +191 -0
  121. package/lib/plugin-runtime/im/contracts.js +169 -0
  122. package/lib/plugin-runtime/im/conversation-runtime.d.ts +19 -0
  123. package/lib/plugin-runtime/im/conversation-runtime.js +312 -0
  124. package/lib/plugin-runtime/im/endpoint-runtime.d.ts +79 -0
  125. package/lib/plugin-runtime/im/endpoint-runtime.js +162 -0
  126. package/lib/plugin-runtime/im/im-runtime.d.ts +84 -0
  127. package/lib/plugin-runtime/im/im-runtime.js +201 -0
  128. package/lib/plugin-runtime/im/inbound-runtime.d.ts +31 -0
  129. package/lib/plugin-runtime/im/inbound-runtime.js +252 -0
  130. package/lib/plugin-runtime/im/index.d.ts +11 -0
  131. package/lib/plugin-runtime/im/index.js +9 -0
  132. package/lib/plugin-runtime/im/ingress-route.d.ts +10 -0
  133. package/lib/plugin-runtime/im/ingress-route.js +10 -0
  134. package/lib/plugin-runtime/im/interaction-runtime.d.ts +23 -0
  135. package/lib/plugin-runtime/im/interaction-runtime.js +181 -0
  136. package/lib/plugin-runtime/im/interactive-router.d.ts +17 -0
  137. package/lib/plugin-runtime/im/interactive-router.js +98 -0
  138. package/lib/plugin-runtime/im/login-assist-host.d.ts +6 -0
  139. package/lib/plugin-runtime/im/login-assist-host.js +6 -0
  140. package/lib/plugin-runtime/im/message-bus.d.ts +38 -0
  141. package/lib/plugin-runtime/im/message-bus.js +40 -0
  142. package/lib/plugin-runtime/im/message-dispatcher.d.ts +18 -0
  143. package/lib/plugin-runtime/im/message-dispatcher.js +107 -0
  144. package/lib/plugin-runtime/im/message-events.d.ts +26 -0
  145. package/lib/plugin-runtime/im/message-events.js +61 -0
  146. package/lib/plugin-runtime/im/outbound-delivery-runtime.d.ts +19 -0
  147. package/lib/plugin-runtime/im/outbound-delivery-runtime.js +165 -0
  148. package/lib/plugin-runtime/im/outbound-renderer.d.ts +7 -0
  149. package/lib/plugin-runtime/im/outbound-renderer.js +70 -0
  150. package/lib/plugin-runtime/im/outbound-segments.d.ts +71 -0
  151. package/lib/plugin-runtime/im/outbound-segments.js +219 -0
  152. package/lib/plugin-runtime/im/public-api.d.ts +6 -0
  153. package/lib/plugin-runtime/im/public-api.js +6 -0
  154. package/lib/plugin-runtime/im/runtime-middleware.d.ts +3 -0
  155. package/lib/plugin-runtime/im/runtime-middleware.js +13 -0
  156. package/lib/request.d.ts +17 -62
  157. package/lib/request.js +0 -4
  158. package/lib/side-event/base.d.ts +51 -0
  159. package/lib/side-event/base.js +30 -0
  160. package/lib/side-event/dispatch.d.ts +15 -0
  161. package/lib/side-event/dispatch.js +140 -0
  162. package/lib/side-event/index.d.ts +4 -0
  163. package/lib/side-event/index.js +4 -0
  164. package/lib/side-event/normalize.d.ts +38 -0
  165. package/lib/side-event/normalize.js +111 -0
  166. package/lib/side-event/types.d.ts +23 -0
  167. package/lib/side-event/types.js +55 -0
  168. package/lib/system-event.d.ts +14 -0
  169. package/lib/system-event.js +7 -0
  170. package/lib/types.d.ts +35 -193
  171. package/lib/types.js +0 -1
  172. package/lib/utils.d.ts +81 -6
  173. package/lib/utils.js +54 -25
  174. package/package.json +94 -16
  175. package/lib/adapter.d.ts +0 -96
  176. package/lib/adapter.d.ts.map +0 -1
  177. package/lib/adapter.js +0 -217
  178. package/lib/adapter.js.map +0 -1
  179. package/lib/agent-prompt.d.ts +0 -37
  180. package/lib/agent-prompt.d.ts.map +0 -1
  181. package/lib/agent-prompt.js +0 -2
  182. package/lib/agent-prompt.js.map +0 -1
  183. package/lib/bot.d.ts +0 -38
  184. package/lib/bot.d.ts.map +0 -1
  185. package/lib/bot.js +0 -2
  186. package/lib/bot.js.map +0 -1
  187. package/lib/built/adapter-process.d.ts +0 -43
  188. package/lib/built/adapter-process.d.ts.map +0 -1
  189. package/lib/built/adapter-process.js +0 -81
  190. package/lib/built/adapter-process.js.map +0 -1
  191. package/lib/built/agent-preset.d.ts +0 -65
  192. package/lib/built/agent-preset.d.ts.map +0 -1
  193. package/lib/built/agent-preset.js +0 -80
  194. package/lib/built/agent-preset.js.map +0 -1
  195. package/lib/built/ai-trigger.d.ts.map +0 -1
  196. package/lib/built/ai-trigger.js.map +0 -1
  197. package/lib/built/command.d.ts +0 -68
  198. package/lib/built/command.d.ts.map +0 -1
  199. package/lib/built/command.js +0 -92
  200. package/lib/built/command.js.map +0 -1
  201. package/lib/built/common-adapter-tools.d.ts.map +0 -1
  202. package/lib/built/common-adapter-tools.js.map +0 -1
  203. package/lib/built/component.d.ts +0 -69
  204. package/lib/built/component.d.ts.map +0 -1
  205. package/lib/built/component.js +0 -99
  206. package/lib/built/component.js.map +0 -1
  207. package/lib/built/config.d.ts +0 -99
  208. package/lib/built/config.d.ts.map +0 -1
  209. package/lib/built/config.js +0 -355
  210. package/lib/built/config.js.map +0 -1
  211. package/lib/built/cron.d.ts +0 -75
  212. package/lib/built/cron.d.ts.map +0 -1
  213. package/lib/built/cron.js +0 -122
  214. package/lib/built/cron.js.map +0 -1
  215. package/lib/built/database.d.ts +0 -66
  216. package/lib/built/database.d.ts.map +0 -1
  217. package/lib/built/database.js +0 -100
  218. package/lib/built/database.js.map +0 -1
  219. package/lib/built/dispatcher.d.ts +0 -139
  220. package/lib/built/dispatcher.d.ts.map +0 -1
  221. package/lib/built/dispatcher.js +0 -361
  222. package/lib/built/dispatcher.js.map +0 -1
  223. package/lib/built/html-segment-fallback.d.ts.map +0 -1
  224. package/lib/built/html-segment-fallback.js.map +0 -1
  225. package/lib/built/html-to-text.d.ts.map +0 -1
  226. package/lib/built/html-to-text.js.map +0 -1
  227. package/lib/built/inbound-runner.d.ts +0 -23
  228. package/lib/built/inbound-runner.d.ts.map +0 -1
  229. package/lib/built/inbound-runner.js +0 -37
  230. package/lib/built/inbound-runner.js.map +0 -1
  231. package/lib/built/login-assist.d.ts.map +0 -1
  232. package/lib/built/login-assist.js.map +0 -1
  233. package/lib/built/mcp-mesh-registrar.d.ts +0 -9
  234. package/lib/built/mcp-mesh-registrar.d.ts.map +0 -1
  235. package/lib/built/mcp-mesh-registrar.js +0 -17
  236. package/lib/built/mcp-mesh-registrar.js.map +0 -1
  237. package/lib/built/message-filter.d.ts +0 -177
  238. package/lib/built/message-filter.d.ts.map +0 -1
  239. package/lib/built/message-filter.js +0 -241
  240. package/lib/built/message-filter.js.map +0 -1
  241. package/lib/built/permission.d.ts +0 -55
  242. package/lib/built/permission.d.ts.map +0 -1
  243. package/lib/built/permission.js +0 -112
  244. package/lib/built/permission.js.map +0 -1
  245. package/lib/built/prepend-quote-context.d.ts +0 -35
  246. package/lib/built/prepend-quote-context.d.ts.map +0 -1
  247. package/lib/built/prepend-quote-context.js +0 -131
  248. package/lib/built/prepend-quote-context.js.map +0 -1
  249. package/lib/built/queue-im-field-contract.d.ts.map +0 -1
  250. package/lib/built/queue-im-field-contract.js.map +0 -1
  251. package/lib/built/roles.d.ts.map +0 -1
  252. package/lib/built/roles.js.map +0 -1
  253. package/lib/built/runtime-io.d.ts +0 -10
  254. package/lib/built/runtime-io.d.ts.map +0 -1
  255. package/lib/built/runtime-io.js +0 -68
  256. package/lib/built/runtime-io.js.map +0 -1
  257. package/lib/built/schema-feature.d.ts +0 -78
  258. package/lib/built/schema-feature.d.ts.map +0 -1
  259. package/lib/built/schema-feature.js +0 -132
  260. package/lib/built/schema-feature.js.map +0 -1
  261. package/lib/built/skill.d.ts +0 -121
  262. package/lib/built/skill.d.ts.map +0 -1
  263. package/lib/built/skill.js +0 -152
  264. package/lib/built/skill.js.map +0 -1
  265. package/lib/built/tool.d.ts +0 -150
  266. package/lib/built/tool.d.ts.map +0 -1
  267. package/lib/built/tool.js +0 -383
  268. package/lib/built/tool.js.map +0 -1
  269. package/lib/command.d.ts +0 -42
  270. package/lib/command.d.ts.map +0 -1
  271. package/lib/command.js +0 -75
  272. package/lib/command.js.map +0 -1
  273. package/lib/component.d.ts.map +0 -1
  274. package/lib/component.js.map +0 -1
  275. package/lib/errors.d.ts.map +0 -1
  276. package/lib/errors.js.map +0 -1
  277. package/lib/index.d.ts.map +0 -1
  278. package/lib/index.js.map +0 -1
  279. package/lib/jsx-dev-runtime.d.ts.map +0 -1
  280. package/lib/jsx-dev-runtime.js.map +0 -1
  281. package/lib/jsx-runtime.d.ts.map +0 -1
  282. package/lib/jsx-runtime.js.map +0 -1
  283. package/lib/jsx.d.ts.map +0 -1
  284. package/lib/jsx.js.map +0 -1
  285. package/lib/message-quote.d.ts +0 -11
  286. package/lib/message-quote.d.ts.map +0 -1
  287. package/lib/message-quote.js +0 -91
  288. package/lib/message-quote.js.map +0 -1
  289. package/lib/message.d.ts.map +0 -1
  290. package/lib/message.js.map +0 -1
  291. package/lib/models/system-log.d.ts.map +0 -1
  292. package/lib/models/system-log.js.map +0 -1
  293. package/lib/models/user.d.ts.map +0 -1
  294. package/lib/models/user.js.map +0 -1
  295. package/lib/notice.d.ts.map +0 -1
  296. package/lib/notice.js.map +0 -1
  297. package/lib/plugin.d.ts +0 -258
  298. package/lib/plugin.d.ts.map +0 -1
  299. package/lib/plugin.js +0 -688
  300. package/lib/plugin.js.map +0 -1
  301. package/lib/prompt.d.ts +0 -118
  302. package/lib/prompt.d.ts.map +0 -1
  303. package/lib/prompt.js +0 -244
  304. package/lib/prompt.js.map +0 -1
  305. package/lib/request.d.ts.map +0 -1
  306. package/lib/request.js.map +0 -1
  307. package/lib/scheduler/scheduler.d.ts +0 -49
  308. package/lib/scheduler/scheduler.d.ts.map +0 -1
  309. package/lib/scheduler/scheduler.js +0 -352
  310. package/lib/scheduler/scheduler.js.map +0 -1
  311. package/lib/scheduler/types.d.ts +0 -71
  312. package/lib/scheduler/types.d.ts.map +0 -1
  313. package/lib/scheduler/types.js +0 -8
  314. package/lib/scheduler/types.js.map +0 -1
  315. package/lib/tool-zod.d.ts +0 -28
  316. package/lib/tool-zod.d.ts.map +0 -1
  317. package/lib/tool-zod.js +0 -98
  318. package/lib/tool-zod.js.map +0 -1
  319. package/lib/types-generator.d.ts +0 -6
  320. package/lib/types-generator.d.ts.map +0 -1
  321. package/lib/types-generator.js +0 -72
  322. package/lib/types-generator.js.map +0 -1
  323. package/lib/types.d.ts.map +0 -1
  324. package/lib/types.js.map +0 -1
  325. package/lib/utils.d.ts.map +0 -1
  326. package/lib/utils.js.map +0 -1
package/lib/request.js CHANGED
@@ -1,11 +1,7 @@
1
1
  export var Request;
2
2
  (function (Request) {
3
- /**
4
- * 工具方法:合并自定义字段与基础请求结构
5
- */
6
3
  function from(input, format) {
7
4
  return Object.assign(input, format);
8
5
  }
9
6
  Request.from = from;
10
7
  })(Request || (Request = {}));
11
- //# sourceMappingURL=request.js.map
@@ -0,0 +1,51 @@
1
+ import type { MessageSender } from '../types.js';
2
+ /**
3
+ * Side Event 共享基础结构(Notice 与 Request 共用)。
4
+ * 字段统一为 `$foo_bar` 命名。
5
+ *
6
+ * 完整事件名:`${$type}.${$scene_type}.${$sub_type}`(见 `formatSideEventName`)。
7
+ */
8
+ export interface SideEventBase {
9
+ /** 平台侧去重键 / flag(非 DB 行 id) */
10
+ $id: string;
11
+ $adapter: string;
12
+ $endpoint: string;
13
+ /** 命名空间:`notice` 或 `request` */
14
+ $type: string;
15
+ /** 平台场景 ID(群号、用户号、频道 ID 等) */
16
+ $scene_id: string;
17
+ /** 场景域(如 group、friend、channel、endpoint) */
18
+ $scene_type?: string;
19
+ /** 动作子类型(如 member_increase、add、poke) */
20
+ $sub_type?: string;
21
+ /** 主参与者(原 Notice.$operator / Request.$sender) */
22
+ $actor?: MessageSender;
23
+ /** 被操作对象 */
24
+ $target?: MessageSender;
25
+ /** 毫秒时间戳 */
26
+ $timestamp: number;
27
+ /** Canonical relation fields populated by the Adapter boundary. */
28
+ $message_id?: string;
29
+ $reaction?: string;
30
+ $operation?: 'added' | 'removed';
31
+ $duration_seconds?: number;
32
+ $role?: string;
33
+ $enabled?: boolean;
34
+ }
35
+ /** 组合 Side Event 完整类型名 */
36
+ export declare function composeSideEventName(type: string, sceneType: string | undefined, subType: string | undefined): string;
37
+ /** 从 Side Event 字段生成完整类型名 */
38
+ export declare function formatSideEventName(event: Pick<SideEventBase, '$type' | '$scene_type' | '$sub_type'>): string;
39
+ /** 判断 Side Event 是否匹配完整类型名(如 `notice.group.member_increase`) */
40
+ export declare function matchesSideEventName(event: Pick<SideEventBase, '$type' | '$scene_type' | '$sub_type'>, fullName: string): boolean;
41
+ /** 解析完整类型名为三段 */
42
+ export declare function parseSideEventName(fullName: string): {
43
+ type: string;
44
+ scene_type?: string;
45
+ sub_type?: string;
46
+ };
47
+ /** 将 Side Event 场景映射为 IM 发送通道(group-suite 等消费者用) */
48
+ export declare function sideEventSendChannel(event: Pick<SideEventBase, '$scene_type' | '$scene_id'>): {
49
+ id: string;
50
+ type: 'group' | 'private' | 'channel';
51
+ };
@@ -0,0 +1,30 @@
1
+ /** 组合 Side Event 完整类型名 */
2
+ export function composeSideEventName(type, sceneType, subType) {
3
+ return [type, sceneType, subType].filter((p) => !!p).join('.');
4
+ }
5
+ /** 从 Side Event 字段生成完整类型名 */
6
+ export function formatSideEventName(event) {
7
+ return composeSideEventName(event.$type, event.$scene_type, event.$sub_type);
8
+ }
9
+ /** 判断 Side Event 是否匹配完整类型名(如 `notice.group.member_increase`) */
10
+ export function matchesSideEventName(event, fullName) {
11
+ return formatSideEventName(event) === fullName;
12
+ }
13
+ /** 解析完整类型名为三段 */
14
+ export function parseSideEventName(fullName) {
15
+ const parts = fullName.split('.');
16
+ return {
17
+ type: parts[0] ?? '',
18
+ scene_type: parts[1],
19
+ sub_type: parts.slice(2).join('.') || undefined,
20
+ };
21
+ }
22
+ /** 将 Side Event 场景映射为 IM 发送通道(group-suite 等消费者用) */
23
+ export function sideEventSendChannel(event) {
24
+ const domain = event.$scene_type ?? 'private';
25
+ if (domain === 'group')
26
+ return { id: event.$scene_id, type: 'group' };
27
+ if (domain === 'channel')
28
+ return { id: event.$scene_id, type: 'channel' };
29
+ return { id: event.$scene_id, type: 'private' };
30
+ }
@@ -0,0 +1,15 @@
1
+ import type { EndpointEventEmitter } from '@zhin.js/adapter';
2
+ import { type OneBotLikeRawEvent, type SideEventPlatform } from './normalize.js';
3
+ export interface OneBotLikeSideEventInput {
4
+ readonly adapter: string;
5
+ readonly endpointKey: string;
6
+ readonly platform?: SideEventPlatform;
7
+ readonly raw: OneBotLikeRawEvent;
8
+ readonly approve?: (flag: string, remark?: string) => void | Promise<void>;
9
+ readonly reject?: (flag: string, reason?: string) => void | Promise<void>;
10
+ }
11
+ /**
12
+ * Normalize OneBot / icqq-style notice|request|meta payloads and feed Endpoint.emit().
13
+ * Returns which kind was dispatched, or null when the payload is not a side event.
14
+ */
15
+ export declare function receiveOneBotLikeSideEvent(emit: EndpointEventEmitter, input: OneBotLikeSideEventInput): Promise<'notice' | 'request' | 'system' | null>;
@@ -0,0 +1,140 @@
1
+ import { buildNotice, buildRequest, buildSystem, mapNoticeParts, mapRequestParts, resolveSideEventDedupeKey, senderFromId, } from './normalize.js';
2
+ /**
3
+ * Normalize OneBot / icqq-style notice|request|meta payloads and feed Endpoint.emit().
4
+ * Returns which kind was dispatched, or null when the payload is not a side event.
5
+ */
6
+ export async function receiveOneBotLikeSideEvent(emit, input) {
7
+ const raw = input.raw;
8
+ const platform = input.platform ?? 'onebot';
9
+ const postType = String(raw.post_type ?? raw.type ?? '');
10
+ if (postType === 'notice' || postType.startsWith('notice.')) {
11
+ const noticeType = String(raw.notice_type ?? (postType.replace(/^notice\.?/, '') || 'unknown'));
12
+ const parts = mapNoticeParts(platform, noticeType, {
13
+ sub_type: raw.sub_type != null ? String(raw.sub_type) : undefined,
14
+ is_group: raw.group_id != null,
15
+ });
16
+ const id = resolveSideEventDedupeKey(raw, 'notice');
17
+ const memberEvent = ['member_increase', 'member_decrease', 'ban', 'admin_change'].includes(parts.sub_type);
18
+ const actorId = raw.operator_id
19
+ ?? (!memberEvent ? raw.user_id : undefined);
20
+ const targetId = memberEvent
21
+ ? raw.user_id
22
+ : parts.sub_type === 'poke'
23
+ ? raw.target_id ?? raw.self_id
24
+ : raw.user_id != null && String(raw.user_id) !== String(raw.operator_id ?? '')
25
+ ? raw.user_id
26
+ : undefined;
27
+ const notice = buildNotice(raw, {
28
+ $id: id,
29
+ $adapter: input.adapter,
30
+ $endpoint: input.endpointKey,
31
+ $type: 'notice',
32
+ $scene_id: String(raw.group_id ?? raw.user_id ?? input.endpointKey),
33
+ $scene_type: parts.scene_type,
34
+ $sub_type: parts.sub_type,
35
+ $actor: senderFromId(actorId),
36
+ $target: senderFromId(targetId),
37
+ $timestamp: toMillis(raw.time),
38
+ ...(raw.message_id != null ? { $message_id: String(raw.message_id) } : {}),
39
+ ...(raw.emoji_id != null || raw.code != null
40
+ ? { $reaction: String(raw.emoji_id ?? raw.code) }
41
+ : {}),
42
+ ...(parts.sub_type === 'emoji_reaction'
43
+ ? { $operation: /delete|remove/i.test(String(raw.sub_type ?? noticeType)) ? 'removed' : 'added' }
44
+ : {}),
45
+ ...(raw.duration != null ? { $duration_seconds: Math.max(0, Number(raw.duration) || 0) } : {}),
46
+ ...(parts.sub_type === 'admin_change'
47
+ ? { $role: 'admin', $enabled: String(raw.sub_type ?? '') === 'set' }
48
+ : {}),
49
+ });
50
+ await emit('notice.receive', notice);
51
+ return 'notice';
52
+ }
53
+ if (postType === 'request' || postType.startsWith('request.')) {
54
+ const requestType = String(raw.request_type ?? (postType.replace(/^request\.?/, '') || 'friend'));
55
+ const parts = mapRequestParts(platform, requestType, raw.sub_type != null ? String(raw.sub_type) : undefined);
56
+ const flag = raw.flag != null ? String(raw.flag) : '';
57
+ const id = flag || resolveSideEventDedupeKey(raw, 'request');
58
+ const actor = senderFromId(raw.user_id);
59
+ if (!actor)
60
+ return null;
61
+ const approve = input.approve;
62
+ const reject = input.reject;
63
+ let active = true;
64
+ const actions = new Set();
65
+ const requireActiveAction = () => {
66
+ if (!active)
67
+ throw new Error('Request action port expired with its generation operation');
68
+ };
69
+ const runAction = (action) => {
70
+ requireActiveAction();
71
+ const operation = Promise.resolve().then(action);
72
+ actions.add(operation);
73
+ void operation.then(() => actions.delete(operation), () => actions.delete(operation));
74
+ return operation;
75
+ };
76
+ const request = buildRequest(raw, {
77
+ $id: id,
78
+ $adapter: input.adapter,
79
+ $endpoint: input.endpointKey,
80
+ $type: 'request',
81
+ $scene_id: String(raw.group_id ?? raw.user_id ?? input.endpointKey),
82
+ $scene_type: parts.scene_type,
83
+ $sub_type: parts.sub_type,
84
+ $actor: actor,
85
+ $comment: raw.comment != null ? String(raw.comment) : undefined,
86
+ $timestamp: toMillis(raw.time),
87
+ async $approve(remark) {
88
+ if (!approve || !flag)
89
+ throw new Error('Request approve is not available');
90
+ await runAction(() => approve(flag, remark));
91
+ },
92
+ async $reject(reason) {
93
+ if (!reject || !flag)
94
+ throw new Error('Request reject is not available');
95
+ await runAction(() => reject(flag, reason));
96
+ },
97
+ });
98
+ try {
99
+ await emit('request.receive', request);
100
+ }
101
+ finally {
102
+ active = false;
103
+ await Promise.allSettled([...actions]);
104
+ }
105
+ return 'request';
106
+ }
107
+ if (postType === 'meta_event'
108
+ || postType === 'meta'
109
+ || postType.startsWith('meta.')
110
+ || postType.startsWith('system.')) {
111
+ const metaType = String(raw.meta_event_type
112
+ ?? raw.detail_type
113
+ ?? (postType.replace(/^(meta_event|meta|system)\.?/, '') || 'unknown'));
114
+ const subType = raw.sub_type != null ? String(raw.sub_type) : undefined;
115
+ const sceneType = postType.startsWith('system.')
116
+ ? (postType.split('.')[1] ?? 'system')
117
+ : metaType === 'lifecycle' || metaType === 'heartbeat'
118
+ ? metaType
119
+ : 'meta';
120
+ const system = buildSystem(raw, {
121
+ $id: `system:${toMillis(raw.time)}_${metaType}_${subType ?? ''}`,
122
+ $adapter: input.adapter,
123
+ $endpoint: input.endpointKey,
124
+ $type: 'system',
125
+ $scene_id: String(raw.self_id ?? input.endpointKey),
126
+ $scene_type: sceneType,
127
+ $sub_type: subType ?? metaType,
128
+ $timestamp: toMillis(raw.time),
129
+ });
130
+ await emit('system.receive', system);
131
+ return 'system';
132
+ }
133
+ return null;
134
+ }
135
+ function toMillis(time) {
136
+ const seconds = Number(time);
137
+ return Number.isFinite(seconds) && seconds > 0
138
+ ? (seconds < 1e12 ? seconds * 1000 : seconds)
139
+ : Date.now();
140
+ }
@@ -0,0 +1,4 @@
1
+ export * from './base.js';
2
+ export * from './types.js';
3
+ export * from './normalize.js';
4
+ export * from './dispatch.js';
@@ -0,0 +1,4 @@
1
+ export * from './base.js';
2
+ export * from './types.js';
3
+ export * from './normalize.js';
4
+ export * from './dispatch.js';
@@ -0,0 +1,38 @@
1
+ import { Notice, type NoticeBase } from '../notice.js';
2
+ import { Request, type RequestBase } from '../request.js';
3
+ import { SystemEvent, type SystemEventBase } from '../system-event.js';
4
+ import { type SideEventParts } from './types.js';
5
+ export type SideEventPlatform = 'onebot' | 'icqq' | 'napcat' | 'kook' | (string & {});
6
+ export interface OneBotLikeRawEvent {
7
+ notice_type?: string;
8
+ request_type?: string;
9
+ sub_type?: string;
10
+ group_id?: number | string;
11
+ user_id?: number | string;
12
+ operator_id?: number | string;
13
+ flag?: string;
14
+ time?: number;
15
+ self_id?: number | string;
16
+ [key: string]: unknown;
17
+ }
18
+ /** 去重用:notice / request 无稳定 id 时组合键 */
19
+ export declare function resolveSideEventDedupeKey(data: OneBotLikeRawEvent, kind: 'notice' | 'request'): string;
20
+ /**
21
+ * 将平台原始 notice_type 映射为标准 `$scene_type` + `$sub_type`。
22
+ */
23
+ export declare function mapNoticeParts(platform: SideEventPlatform, raw: string, options?: {
24
+ sub_type?: string;
25
+ is_group?: boolean;
26
+ notify_handler?: (subType: string | undefined, isGroup: boolean) => SideEventParts;
27
+ }): SideEventParts;
28
+ /**
29
+ * 将平台原始 request_type 映射为标准 `$scene_type` + `$sub_type`。
30
+ */
31
+ export declare function mapRequestParts(_platform: SideEventPlatform, raw: string, subType?: string): SideEventParts;
32
+ export declare function senderFromId(id: unknown, name?: string): {
33
+ id: string;
34
+ name: string;
35
+ } | undefined;
36
+ export declare function buildNotice<T extends object>(input: T, format: NoticeBase): Notice<T>;
37
+ export declare function buildRequest<T extends object>(input: T, format: RequestBase): Request<T>;
38
+ export declare function buildSystem<T extends object>(input: T, format: SystemEventBase): SystemEvent<T>;
@@ -0,0 +1,111 @@
1
+ import { Notice } from '../notice.js';
2
+ import { Request } from '../request.js';
3
+ import { SystemEvent } from '../system-event.js';
4
+ import { parseSideEventName } from './base.js';
5
+ import { KOOK_NOTICE_PARTS_MAP, ONEBOT_NOTICE_PARTS_MAP, SLACK_NOTICE_PARTS_MAP } from './types.js';
6
+ /** 去重用:notice / request 无稳定 id 时组合键 */
7
+ export function resolveSideEventDedupeKey(data, kind) {
8
+ if (data.flag != null && String(data.flag) !== '') {
9
+ return `${kind}:${data.flag}`;
10
+ }
11
+ const time = data.time ?? 0;
12
+ const type = data.notice_type ?? data.request_type ?? kind;
13
+ const scope = data.group_id ?? data.user_id ?? '';
14
+ const sub = data.sub_type ?? '';
15
+ return `${kind}:${time}_${type}_${scope}_${sub}`;
16
+ }
17
+ function resolveNotifyNoticeParts(subType, isGroup) {
18
+ if (subType === 'poke') {
19
+ return isGroup
20
+ ? { scene_type: 'group', sub_type: 'poke' }
21
+ : { scene_type: 'friend', sub_type: 'poke' };
22
+ }
23
+ if (subType === 'input_status')
24
+ return { scene_type: 'notify', sub_type: 'input_status' };
25
+ if (subType === 'title')
26
+ return { scene_type: 'notify', sub_type: 'title_change' };
27
+ if (subType === 'profile_like')
28
+ return { scene_type: 'notify', sub_type: 'profile_like' };
29
+ return { scene_type: 'notify', sub_type: subType ?? 'unknown' };
30
+ }
31
+ function resolveEssenceNoticeParts(subType) {
32
+ return subType === 'add'
33
+ ? { scene_type: 'group', sub_type: 'essence_add' }
34
+ : { scene_type: 'group', sub_type: 'essence_delete' };
35
+ }
36
+ /**
37
+ * 将平台原始 notice_type 映射为标准 `$scene_type` + `$sub_type`。
38
+ */
39
+ export function mapNoticeParts(platform, raw, options) {
40
+ const subType = options?.sub_type;
41
+ const isGroup = options?.is_group ?? false;
42
+ if (platform === 'kook') {
43
+ return KOOK_NOTICE_PARTS_MAP[raw] ?? { scene_type: 'kook', sub_type: raw };
44
+ }
45
+ if (platform === 'slack') {
46
+ return SLACK_NOTICE_PARTS_MAP[raw] ?? { scene_type: 'slack', sub_type: raw };
47
+ }
48
+ if (raw === 'notify') {
49
+ const handler = options?.notify_handler ?? resolveNotifyNoticeParts;
50
+ return handler(subType, isGroup);
51
+ }
52
+ if (raw === 'essence') {
53
+ return resolveEssenceNoticeParts(subType);
54
+ }
55
+ if (ONEBOT_NOTICE_PARTS_MAP[raw]) {
56
+ return ONEBOT_NOTICE_PARTS_MAP[raw];
57
+ }
58
+ if (raw.startsWith('notice.')) {
59
+ const parsed = parseSideEventName(raw);
60
+ if (parsed.scene_type && parsed.sub_type) {
61
+ return { scene_type: parsed.scene_type, sub_type: parsed.sub_type };
62
+ }
63
+ const suffix = raw.slice('notice.'.length).replace(/\./g, '_');
64
+ if (ONEBOT_NOTICE_PARTS_MAP[suffix])
65
+ return ONEBOT_NOTICE_PARTS_MAP[suffix];
66
+ return { scene_type: parsed.scene_type ?? 'unknown', sub_type: parsed.sub_type ?? suffix };
67
+ }
68
+ if (platform === 'icqq' || platform === 'onebot' || platform === 'napcat') {
69
+ const dotted = raw.replace(/_/g, '.');
70
+ const parsed = parseSideEventName(`notice.${dotted}`);
71
+ return {
72
+ scene_type: parsed.scene_type ?? dotted.split('.')[0] ?? 'unknown',
73
+ sub_type: parsed.sub_type ?? (dotted.split('.').slice(1).join('.') || raw),
74
+ };
75
+ }
76
+ return { scene_type: platform, sub_type: raw };
77
+ }
78
+ /**
79
+ * 将平台原始 request_type 映射为标准 `$scene_type` + `$sub_type`。
80
+ */
81
+ export function mapRequestParts(_platform, raw, subType) {
82
+ if (raw === 'friend' || raw.startsWith('friend')) {
83
+ return { scene_type: 'friend', sub_type: 'add' };
84
+ }
85
+ if (raw === 'group' || raw.startsWith('group')) {
86
+ return { scene_type: 'group', sub_type: subType === 'invite' ? 'invite' : 'add' };
87
+ }
88
+ if (raw.startsWith('request.')) {
89
+ const parsed = parseSideEventName(raw);
90
+ return {
91
+ scene_type: parsed.scene_type ?? 'unknown',
92
+ sub_type: parsed.sub_type ?? 'unknown',
93
+ };
94
+ }
95
+ return { scene_type: raw, sub_type: subType ?? 'unknown' };
96
+ }
97
+ export function senderFromId(id, name) {
98
+ if (id == null || id === '')
99
+ return undefined;
100
+ const s = String(id);
101
+ return { id: s, name: name ?? s };
102
+ }
103
+ export function buildNotice(input, format) {
104
+ return Notice.from(input, format);
105
+ }
106
+ export function buildRequest(input, format) {
107
+ return Request.from(input, format);
108
+ }
109
+ export function buildSystem(input, format) {
110
+ return SystemEvent.from(input, format);
111
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Side Event 标准类型。
3
+ * 运行时 `$type` 仅存命名空间(`notice` / `request` / `system`);
4
+ * 完整名由 `${$type}.${$scene_type}.${$sub_type}` 组合。
5
+ */
6
+ export type SideEventKind = 'notice' | 'request' | 'system';
7
+ export type NoticeKind = 'notice';
8
+ export type RequestKind = 'request';
9
+ export type SystemKind = 'system';
10
+ /** 完整组合名(测试 / 文档 / 消费者匹配用) */
11
+ export type ComposedNoticeName = 'notice.group.member_increase' | 'notice.group.member_decrease' | 'notice.group.admin_change' | 'notice.group.ban' | 'notice.group.recall' | 'notice.group.poke' | 'notice.group.transfer' | 'notice.group.upload' | 'notice.group.emoji_reaction' | 'notice.group.card_change' | 'notice.group.essence_add' | 'notice.group.essence_delete' | 'notice.friend.recall' | 'notice.friend.increase' | 'notice.friend.poke' | 'notice.endpoint.lifecycle' | (string & {});
12
+ export type ComposedRequestName = 'request.friend.add' | 'request.group.add' | 'request.group.invite' | (string & {});
13
+ export type ComposedSystemName = 'system.login.qrcode' | 'system.login.slider' | 'system.login.device' | 'system.login.error' | 'system.login.auth' | 'system.offline' | 'system.offline.network' | 'system.offline.kickoff' | 'system.online' | (string & {});
14
+ export interface SideEventParts {
15
+ scene_type: string;
16
+ sub_type: string;
17
+ }
18
+ /** OneBot / icqq 等平台 notice_type 原始值 → 标准 scene_type + sub_type */
19
+ export declare const ONEBOT_NOTICE_PARTS_MAP: Record<string, SideEventParts>;
20
+ /** KOOK extra.type 原始值 → 标准 scene_type + sub_type */
21
+ export declare const KOOK_NOTICE_PARTS_MAP: Record<string, SideEventParts>;
22
+ /** Slack event type 原始值 → 标准 scene_type + sub_type */
23
+ export declare const SLACK_NOTICE_PARTS_MAP: Record<string, SideEventParts>;
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Side Event 标准类型。
3
+ * 运行时 `$type` 仅存命名空间(`notice` / `request` / `system`);
4
+ * 完整名由 `${$type}.${$scene_type}.${$sub_type}` 组合。
5
+ */
6
+ /** OneBot / icqq 等平台 notice_type 原始值 → 标准 scene_type + sub_type */
7
+ export const ONEBOT_NOTICE_PARTS_MAP = {
8
+ group_increase: { scene_type: 'group', sub_type: 'member_increase' },
9
+ group_decrease: { scene_type: 'group', sub_type: 'member_decrease' },
10
+ group_admin: { scene_type: 'group', sub_type: 'admin_change' },
11
+ group_ban: { scene_type: 'group', sub_type: 'ban' },
12
+ group_recall: { scene_type: 'group', sub_type: 'recall' },
13
+ friend_recall: { scene_type: 'friend', sub_type: 'recall' },
14
+ friend_add: { scene_type: 'friend', sub_type: 'increase' },
15
+ group_upload: { scene_type: 'group', sub_type: 'upload' },
16
+ group_transfer: { scene_type: 'group', sub_type: 'transfer' },
17
+ group_card: { scene_type: 'group', sub_type: 'card_change' },
18
+ group_msg_emoji_like: { scene_type: 'group', sub_type: 'emoji_reaction' },
19
+ 'group.increase': { scene_type: 'group', sub_type: 'member_increase' },
20
+ 'group.decrease': { scene_type: 'group', sub_type: 'member_decrease' },
21
+ 'group.admin': { scene_type: 'group', sub_type: 'admin_change' },
22
+ 'group.ban': { scene_type: 'group', sub_type: 'ban' },
23
+ 'group.recall': { scene_type: 'group', sub_type: 'recall' },
24
+ 'friend.increase': { scene_type: 'friend', sub_type: 'increase' },
25
+ 'friend.decrease': { scene_type: 'friend', sub_type: 'recall' },
26
+ 'friend.recall': { scene_type: 'friend', sub_type: 'recall' },
27
+ };
28
+ /** KOOK extra.type 原始值 → 标准 scene_type + sub_type */
29
+ export const KOOK_NOTICE_PARTS_MAP = {
30
+ joined_guild: { scene_type: 'group', sub_type: 'member_increase' },
31
+ exited_guild: { scene_type: 'group', sub_type: 'member_decrease' },
32
+ deleted_message: { scene_type: 'group', sub_type: 'recall' },
33
+ deleted_private_message: { scene_type: 'friend', sub_type: 'recall' },
34
+ added_reaction: { scene_type: 'group', sub_type: 'emoji_reaction' },
35
+ deleted_reaction: { scene_type: 'group', sub_type: 'emoji_reaction' },
36
+ private_added_reaction: { scene_type: 'group', sub_type: 'emoji_reaction' },
37
+ private_deleted_reaction: { scene_type: 'group', sub_type: 'emoji_reaction' },
38
+ };
39
+ /** Slack event type 原始值 → 标准 scene_type + sub_type */
40
+ export const SLACK_NOTICE_PARTS_MAP = {
41
+ member_joined_channel: { scene_type: 'group', sub_type: 'member_increase' },
42
+ member_left_channel: { scene_type: 'group', sub_type: 'member_decrease' },
43
+ reaction_added: { scene_type: 'group', sub_type: 'emoji_reaction' },
44
+ reaction_removed: { scene_type: 'group', sub_type: 'emoji_reaction' },
45
+ message_deleted: { scene_type: 'group', sub_type: 'recall' },
46
+ channel_archive: { scene_type: 'slack', sub_type: 'channel_archive' },
47
+ channel_unarchive: { scene_type: 'slack', sub_type: 'channel_unarchive' },
48
+ channel_rename: { scene_type: 'slack', sub_type: 'channel_rename' },
49
+ channel_created: { scene_type: 'slack', sub_type: 'channel_created' },
50
+ channel_deleted: { scene_type: 'slack', sub_type: 'channel_deleted' },
51
+ pin_added: { scene_type: 'slack', sub_type: 'pin_added' },
52
+ pin_removed: { scene_type: 'slack', sub_type: 'pin_removed' },
53
+ app_home_opened: { scene_type: 'slack', sub_type: 'app_home_opened' },
54
+ team_join: { scene_type: 'friend', sub_type: 'increase' },
55
+ };
@@ -0,0 +1,14 @@
1
+ import type { SideEventBase } from './side-event/base.js';
2
+ /**
3
+ * 系统/登录侧事件(扫码、滑块、掉线等)。
4
+ * `$scene_type`:`login` / `offline` / `online` 等;
5
+ * `$sub_type`:`qrcode` / `slider` / `device` / `kickoff` / `network` 等。
6
+ */
7
+ export interface SystemEventBase extends SideEventBase {
8
+ $adapter: string;
9
+ $type: 'system';
10
+ }
11
+ export type SystemEvent<T extends object = {}> = SystemEventBase & T;
12
+ export declare namespace SystemEvent {
13
+ function from<T extends object>(input: T, format: SystemEventBase): SystemEvent<T>;
14
+ }
@@ -0,0 +1,7 @@
1
+ export var SystemEvent;
2
+ (function (SystemEvent) {
3
+ function from(input, format) {
4
+ return Object.assign(input, format);
5
+ }
6
+ SystemEvent.from = from;
7
+ })(SystemEvent || (SystemEvent = {}));