@zhin.js/core 1.1.35 → 1.1.38

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 (197) hide show
  1. package/README.md +79 -193
  2. package/lib/built/ai-outbound/index.d.ts +0 -1
  3. package/lib/built/ai-outbound/index.js +0 -1
  4. package/lib/built/ai-outbound/types.d.ts +0 -9
  5. package/lib/built/ai-trigger.d.ts +0 -5
  6. package/lib/built/ai-trigger.js +1 -27
  7. package/lib/built/common-adapter-tools.d.ts +0 -2
  8. package/lib/built/common-adapter-tools.js +0 -4
  9. package/lib/built/html-segment-fallback.d.ts +2 -5
  10. package/lib/built/html-segment-fallback.js +0 -15
  11. package/lib/built/interactive-segments/index.d.ts +0 -2
  12. package/lib/built/interactive-segments/index.js +0 -2
  13. package/lib/built/interactive-segments/keyboard-segment.d.ts +0 -1
  14. package/lib/built/interactive-segments/keyboard-segment.js +0 -1
  15. package/lib/built/interactive-segments/onebot-keyboard.d.ts +0 -1
  16. package/lib/built/interactive-segments/onebot-keyboard.js +0 -2
  17. package/lib/built/interactive-segments/resolve.d.ts +0 -1
  18. package/lib/built/interactive-segments/resolve.js +0 -1
  19. package/lib/built/interactive-segments/types.d.ts +0 -5
  20. package/lib/built/login-assist.d.ts +1 -8
  21. package/lib/built/message-enrich.d.ts +2 -8
  22. package/lib/built/message-enrich.js +3 -11
  23. package/lib/built/segment-contract/assert.js +2 -1
  24. package/lib/built/segment-contract/delivery.js +1 -0
  25. package/lib/built/segment-contract/index.d.ts +2 -2
  26. package/lib/built/segment-contract/index.js +1 -1
  27. package/lib/built/segment-contract/json-schema.d.ts +1 -1
  28. package/lib/built/segment-contract/json-schema.js +33 -2
  29. package/lib/built/segment-contract/preview.js +7 -0
  30. package/lib/built/segment-contract/types.d.ts +2 -2
  31. package/lib/built/segment-contract/validate.d.ts +43 -2
  32. package/lib/built/segment-contract/validate.js +37 -3
  33. package/lib/built/tool-access.d.ts +5 -0
  34. package/lib/built/tool-access.js +17 -0
  35. package/lib/built/user-interaction.js +0 -4
  36. package/lib/feature/handler.d.ts +1 -5
  37. package/lib/index.d.ts +4 -45
  38. package/lib/index.js +3 -39
  39. package/lib/message.d.ts +1 -2
  40. package/lib/models/system-log.d.ts +0 -2
  41. package/lib/models/system-log.js +1 -8
  42. package/lib/models/user.d.ts +0 -2
  43. package/lib/models/user.js +1 -7
  44. package/lib/notice.d.ts +1 -2
  45. package/lib/plugin-runtime/im/conversation-runtime.d.ts +19 -0
  46. package/lib/plugin-runtime/im/conversation-runtime.js +312 -0
  47. package/lib/plugin-runtime/im/endpoint-runtime.d.ts +79 -0
  48. package/lib/plugin-runtime/im/endpoint-runtime.js +162 -0
  49. package/lib/plugin-runtime/im/im-runtime.d.ts +13 -106
  50. package/lib/plugin-runtime/im/im-runtime.js +58 -1061
  51. package/lib/plugin-runtime/im/inbound-runtime.d.ts +31 -0
  52. package/lib/plugin-runtime/im/inbound-runtime.js +252 -0
  53. package/lib/plugin-runtime/im/index.d.ts +4 -2
  54. package/lib/plugin-runtime/im/index.js +2 -2
  55. package/lib/plugin-runtime/im/ingress-route.d.ts +10 -0
  56. package/lib/plugin-runtime/im/ingress-route.js +10 -0
  57. package/lib/plugin-runtime/im/interaction-runtime.d.ts +23 -0
  58. package/lib/plugin-runtime/im/interaction-runtime.js +181 -0
  59. package/lib/plugin-runtime/im/interactive-router.d.ts +17 -0
  60. package/lib/plugin-runtime/im/interactive-router.js +98 -0
  61. package/lib/plugin-runtime/im/message-bus.d.ts +3 -3
  62. package/lib/plugin-runtime/im/message-bus.js +3 -3
  63. package/lib/plugin-runtime/im/message-events.d.ts +26 -0
  64. package/lib/plugin-runtime/im/message-events.js +61 -0
  65. package/lib/plugin-runtime/im/outbound-delivery-runtime.d.ts +19 -0
  66. package/lib/plugin-runtime/im/outbound-delivery-runtime.js +165 -0
  67. package/lib/plugin-runtime/im/outbound-segments.d.ts +2 -3
  68. package/lib/plugin-runtime/im/outbound-segments.js +3 -4
  69. package/lib/plugin-runtime/im/runtime-middleware.d.ts +3 -0
  70. package/lib/plugin-runtime/im/runtime-middleware.js +13 -0
  71. package/lib/request.d.ts +1 -2
  72. package/lib/side-event/base.d.ts +1 -2
  73. package/lib/side-event/normalize.d.ts +1 -5
  74. package/lib/side-event/normalize.js +1 -11
  75. package/lib/system-event.d.ts +1 -2
  76. package/lib/types.d.ts +9 -116
  77. package/lib/utils.d.ts +51 -24
  78. package/lib/utils.js +11 -23
  79. package/package.json +18 -28
  80. package/lib/adapter.d.ts +0 -145
  81. package/lib/adapter.js +0 -377
  82. package/lib/built/adapter-process.d.ts +0 -58
  83. package/lib/built/adapter-process.js +0 -128
  84. package/lib/built/agent-preset.d.ts +0 -64
  85. package/lib/built/agent-preset.js +0 -79
  86. package/lib/built/ai-outbound/adapter-access.d.ts +0 -3
  87. package/lib/built/ai-outbound/adapter-access.js +0 -9
  88. package/lib/built/authorization.d.ts +0 -10
  89. package/lib/built/authorization.js +0 -76
  90. package/lib/built/command.d.ts +0 -72
  91. package/lib/built/command.js +0 -105
  92. package/lib/built/component.d.ts +0 -67
  93. package/lib/built/component.js +0 -97
  94. package/lib/built/config.d.ts +0 -98
  95. package/lib/built/config.js +0 -372
  96. package/lib/built/connect-endpoint-instance.d.ts +0 -17
  97. package/lib/built/connect-endpoint-instance.js +0 -42
  98. package/lib/built/database.d.ts +0 -68
  99. package/lib/built/database.js +0 -106
  100. package/lib/built/dispatcher.d.ts +0 -141
  101. package/lib/built/dispatcher.js +0 -383
  102. package/lib/built/endpoint-commands.d.ts +0 -3
  103. package/lib/built/endpoint-commands.js +0 -99
  104. package/lib/built/endpoint-lifecycle-service.d.ts +0 -28
  105. package/lib/built/endpoint-lifecycle-service.js +0 -242
  106. package/lib/built/endpoint-lifecycle.d.ts +0 -27
  107. package/lib/built/endpoint-lifecycle.js +0 -36
  108. package/lib/built/endpoint-manager.d.ts +0 -34
  109. package/lib/built/endpoint-manager.js +0 -1
  110. package/lib/built/html-renderer-loader.d.ts +0 -13
  111. package/lib/built/html-renderer-loader.js +0 -33
  112. package/lib/built/inbound-pipeline.d.ts +0 -37
  113. package/lib/built/inbound-pipeline.js +0 -63
  114. package/lib/built/inbound-runner.d.ts +0 -22
  115. package/lib/built/inbound-runner.js +0 -34
  116. package/lib/built/interactive-segment-contract.d.ts +0 -6
  117. package/lib/built/interactive-segment-contract.js +0 -9
  118. package/lib/built/interactive-segments/fallback-store.d.ts +0 -29
  119. package/lib/built/interactive-segments/fallback-store.js +0 -63
  120. package/lib/built/interactive-segments/handlers.d.ts +0 -16
  121. package/lib/built/interactive-segments/handlers.js +0 -74
  122. package/lib/built/introspection-format.d.ts +0 -10
  123. package/lib/built/introspection-format.js +0 -28
  124. package/lib/built/management-command-guard.d.ts +0 -15
  125. package/lib/built/management-command-guard.js +0 -25
  126. package/lib/built/message-filter.d.ts +0 -176
  127. package/lib/built/message-filter.js +0 -239
  128. package/lib/built/optional-peer-import.d.ts +0 -3
  129. package/lib/built/optional-peer-import.js +0 -33
  130. package/lib/built/outbound-media-contract.d.ts +0 -22
  131. package/lib/built/outbound-media-contract.js +0 -10
  132. package/lib/built/permission.d.ts +0 -51
  133. package/lib/built/permission.js +0 -99
  134. package/lib/built/permit-check.d.ts +0 -7
  135. package/lib/built/permit-check.js +0 -35
  136. package/lib/built/permit-parse.d.ts +0 -16
  137. package/lib/built/permit-parse.js +0 -32
  138. package/lib/built/platform-permit.d.ts +0 -20
  139. package/lib/built/platform-permit.js +0 -91
  140. package/lib/built/rich-segments/adapter-policies.d.ts +0 -9
  141. package/lib/built/rich-segments/adapter-policies.js +0 -27
  142. package/lib/built/rich-segments/base.d.ts +0 -11
  143. package/lib/built/rich-segments/base.js +0 -24
  144. package/lib/built/rich-segments/builtins.d.ts +0 -4
  145. package/lib/built/rich-segments/builtins.js +0 -40
  146. package/lib/built/rich-segments/capabilities.d.ts +0 -6
  147. package/lib/built/rich-segments/capabilities.js +0 -38
  148. package/lib/built/rich-segments/html-segment.d.ts +0 -15
  149. package/lib/built/rich-segments/html-segment.js +0 -62
  150. package/lib/built/rich-segments/index.d.ts +0 -13
  151. package/lib/built/rich-segments/index.js +0 -13
  152. package/lib/built/rich-segments/markdown-segment.d.ts +0 -14
  153. package/lib/built/rich-segments/markdown-segment.js +0 -58
  154. package/lib/built/rich-segments/qrcode-segment.d.ts +0 -18
  155. package/lib/built/rich-segments/qrcode-segment.js +0 -73
  156. package/lib/built/rich-segments/registry.d.ts +0 -16
  157. package/lib/built/rich-segments/registry.js +0 -52
  158. package/lib/built/rich-segments/resolve.d.ts +0 -5
  159. package/lib/built/rich-segments/resolve.js +0 -87
  160. package/lib/built/rich-segments/tts-segment.d.ts +0 -13
  161. package/lib/built/rich-segments/tts-segment.js +0 -51
  162. package/lib/built/rich-segments/types.d.ts +0 -79
  163. package/lib/built/rich-segments/types.js +0 -17
  164. package/lib/built/runtime-io.d.ts +0 -9
  165. package/lib/built/runtime-io.js +0 -67
  166. package/lib/built/schedule.d.ts +0 -54
  167. package/lib/built/schedule.js +0 -112
  168. package/lib/built/schema-endpoint-manager.d.ts +0 -17
  169. package/lib/built/schema-endpoint-manager.js +0 -73
  170. package/lib/built/schema-feature.d.ts +0 -77
  171. package/lib/built/schema-feature.js +0 -130
  172. package/lib/built/skill.d.ts +0 -120
  173. package/lib/built/skill.js +0 -151
  174. package/lib/built/speech-loader.d.ts +0 -14
  175. package/lib/built/speech-loader.js +0 -32
  176. package/lib/built/tool.d.ts +0 -151
  177. package/lib/built/tool.js +0 -388
  178. package/lib/command.d.ts +0 -50
  179. package/lib/command.js +0 -106
  180. package/lib/endpoint-capabilities.d.ts +0 -46
  181. package/lib/endpoint-capabilities.js +0 -55
  182. package/lib/endpoint.d.ts +0 -19
  183. package/lib/endpoint.js +0 -3
  184. package/lib/host-plugin-registry.d.ts +0 -8
  185. package/lib/host-plugin-registry.js +0 -12
  186. package/lib/plugin-context.d.ts +0 -27
  187. package/lib/plugin-context.js +0 -64
  188. package/lib/plugin-runtime/im/interactive.d.ts +0 -26
  189. package/lib/plugin-runtime/im/interactive.js +0 -46
  190. package/lib/plugin-runtime/im/service-tokens.d.ts +0 -18
  191. package/lib/plugin-runtime/im/service-tokens.js +0 -13
  192. package/lib/plugin.d.ts +0 -268
  193. package/lib/plugin.js +0 -583
  194. package/lib/schema-interaction.d.ts +0 -117
  195. package/lib/schema-interaction.js +0 -247
  196. package/lib/tool-zod.d.ts +0 -43
  197. package/lib/tool-zod.js +0 -184
@@ -1,6 +1,7 @@
1
1
  import { isStrictCanonicalSegment } from './validate.js';
2
2
  const STRICT_CANONICAL_TYPES = new Set([
3
- 'text', 'mention', 'image', 'audio', 'video', 'file', 'reply', 'forward', 'face', 'dice', 'rps',
3
+ 'text', 'mention', 'image', 'audio', 'video', 'file', 'reply', 'forward',
4
+ 'face', 'dice', 'rps', 'share',
4
5
  ]);
5
6
  // These are Core-owned wire extensions rather than canonical data types. Keep
6
7
  // their gradual contracts isolated here; third-party extensions must be
@@ -15,6 +15,7 @@ const IM_VISIBLE_TYPES = new Set([
15
15
  'link',
16
16
  'dice',
17
17
  'rps',
18
+ 'share',
18
19
  'markdown',
19
20
  'html',
20
21
  'qrcode',
@@ -1,5 +1,5 @@
1
- export type { Segment, SegmentBase, MediaRef, TextSegment, MentionSegment, ImageSegment, AudioSegment, VideoSegment, FileSegment, ReplySegment, ForwardSegment, FaceSegment, DiceSegment, RpsSegment, } from './types.js';
2
- export { mediaRefSchema, textSegmentSchema, mentionSegmentSchema, imageSegmentSchema, audioSegmentSchema, videoSegmentSchema, fileSegmentSchema, replySegmentSchema, forwardSegmentSchema, faceSegmentSchema, diceSegmentSchema, rpsSegmentSchema, canonicalSegmentSchema, segmentArraySchema, } from './validate.js';
1
+ export type { Segment, SegmentBase, MediaRef, TextSegment, MentionSegment, ImageSegment, AudioSegment, VideoSegment, FileSegment, ReplySegment, ForwardSegment, ShareSegment, FaceSegment, DiceSegment, RpsSegment, } from './types.js';
2
+ export { mediaRefSchema, textSegmentSchema, mentionSegmentSchema, imageSegmentSchema, audioSegmentSchema, videoSegmentSchema, fileSegmentSchema, replySegmentSchema, forwardSegmentSchema, faceSegmentSchema, diceSegmentSchema, rpsSegmentSchema, shareSegmentSchema, canonicalSegmentSchema, segmentArraySchema, } from './validate.js';
3
3
  export { assertCanonicalSegments, isCanonicalSegment } from './assert.js';
4
4
  export { mediaRefJsonSchema, outboundSegmentJsonSchema, aiOutboundJsonSchema, STRICT_OUTBOUND_SEGMENT_TYPES, } from './json-schema.js';
5
5
  export { segmentsForImDelivery } from './delivery.js';
@@ -1,4 +1,4 @@
1
- export { mediaRefSchema, textSegmentSchema, mentionSegmentSchema, imageSegmentSchema, audioSegmentSchema, videoSegmentSchema, fileSegmentSchema, replySegmentSchema, forwardSegmentSchema, faceSegmentSchema, diceSegmentSchema, rpsSegmentSchema, canonicalSegmentSchema, segmentArraySchema, } from './validate.js';
1
+ export { mediaRefSchema, textSegmentSchema, mentionSegmentSchema, imageSegmentSchema, audioSegmentSchema, videoSegmentSchema, fileSegmentSchema, replySegmentSchema, forwardSegmentSchema, faceSegmentSchema, diceSegmentSchema, rpsSegmentSchema, shareSegmentSchema, canonicalSegmentSchema, segmentArraySchema, } from './validate.js';
2
2
  export { assertCanonicalSegments, isCanonicalSegment } from './assert.js';
3
3
  export { mediaRefJsonSchema, outboundSegmentJsonSchema, aiOutboundJsonSchema, STRICT_OUTBOUND_SEGMENT_TYPES, } from './json-schema.js';
4
4
  export { segmentsForImDelivery } from './delivery.js';
@@ -13,7 +13,7 @@ type JsonSchemaObject = Record<string, unknown>;
13
13
  /** MediaRef(canonical 媒体引用):types.ts 的 MediaRef 接口 */
14
14
  export declare const mediaRefJsonSchema: JsonSchemaObject;
15
15
  /** 严格段类型集合(SSOT:assert.ts STRICT_CANONICAL_TYPES) */
16
- export declare const STRICT_OUTBOUND_SEGMENT_TYPES: readonly ["text", "mention", "image", "reply", "forward", "face", "dice", "rps"];
16
+ export declare const STRICT_OUTBOUND_SEGMENT_TYPES: readonly ["text", "mention", "image", "audio", "video", "file", "reply", "forward", "face", "dice", "rps", "share"];
17
17
  /**
18
18
  * 单条 outbound 消息段的 JSON Schema。
19
19
  * 严格段镜像 validate.ts 的 data 约束;宽松段走 generic 分支。
@@ -50,7 +50,7 @@ const looseBranch = {
50
50
  properties: {
51
51
  type: {
52
52
  type: 'string',
53
- enum: ['video', 'audio', 'voice', 'record', 'file', 'link', 'markdown', 'html', 'keyboard', 'action'],
53
+ enum: ['voice', 'record', 'link', 'markdown', 'html', 'keyboard', 'action'],
54
54
  },
55
55
  data: { type: 'object' },
56
56
  platform: platformJsonSchema,
@@ -60,7 +60,8 @@ const looseBranch = {
60
60
  };
61
61
  /** 严格段类型集合(SSOT:assert.ts STRICT_CANONICAL_TYPES) */
62
62
  export const STRICT_OUTBOUND_SEGMENT_TYPES = [
63
- 'text', 'mention', 'image', 'reply', 'forward', 'face', 'dice', 'rps',
63
+ 'text', 'mention', 'image', 'audio', 'video', 'file', 'reply', 'forward',
64
+ 'face', 'dice', 'rps', 'share',
64
65
  ];
65
66
  /**
66
67
  * 单条 outbound 消息段的 JSON Schema。
@@ -80,6 +81,19 @@ export const outboundSegmentJsonSchema = {
80
81
  media: mediaRefJsonSchema,
81
82
  alt: { type: 'string' },
82
83
  }, ['media'])),
84
+ strictBranch('audio', dataObject({
85
+ media: mediaRefJsonSchema,
86
+ duration: { type: 'number' },
87
+ }, ['media'])),
88
+ strictBranch('video', dataObject({
89
+ media: mediaRefJsonSchema,
90
+ duration: { type: 'number' },
91
+ alt: { type: 'string' },
92
+ }, ['media'])),
93
+ strictBranch('file', dataObject({
94
+ media: mediaRefJsonSchema,
95
+ name: { type: 'string' },
96
+ }, ['media'])),
83
97
  strictBranch('reply', dataObject({
84
98
  message_id: { type: 'string', description: '被引用消息的平台消息 id' },
85
99
  }, ['message_id'])),
@@ -98,6 +112,23 @@ export const outboundSegmentJsonSchema = {
98
112
  strictBranch('rps', dataObject({
99
113
  result: { type: 'number' },
100
114
  }, [])),
115
+ strictBranch('share', dataObject({
116
+ url: { type: 'string', description: '分享跳转地址' },
117
+ title: { type: 'string', description: '分享标题' },
118
+ description: { type: 'string', description: '分享摘要' },
119
+ image: { type: 'string', description: '预览图地址' },
120
+ audio: { type: 'string', description: '音频地址' },
121
+ content: { type: 'string', description: '消息列表中的显示文字' },
122
+ artist: { type: 'string', description: '音乐分享的艺术家' },
123
+ duration: { type: 'number', description: '音频时长(秒)' },
124
+ config: dataObject({
125
+ appid: { type: 'number' },
126
+ package: { type: 'string' },
127
+ sign: { type: 'string' },
128
+ icon: { type: 'string' },
129
+ version: { type: 'string' },
130
+ }, ['appid']),
131
+ }, ['url', 'title'])),
101
132
  looseBranch,
102
133
  ],
103
134
  };
@@ -106,6 +106,13 @@ export function formatSegmentPreview(item) {
106
106
  return clip(`${text} <${url}>`);
107
107
  return clip(url || text || '[link]');
108
108
  }
109
+ case 'share': {
110
+ const url = typeof data.url === 'string' ? data.url : '';
111
+ const title = typeof data.title === 'string' ? data.title : '';
112
+ if (title && url)
113
+ return clip(`[share] ${title} <${url}>`);
114
+ return clip(title || url || '[share]');
115
+ }
109
116
  case 'dice':
110
117
  return data.result != null ? `{dice}(${data.result})` : '{dice}';
111
118
  case 'rps':
@@ -1,6 +1,6 @@
1
1
  /** Canonical Segment SSOT lives in @zhin.js/im-contract. */
2
2
  import type { MediaRef, SegmentBase } from '@zhin.js/im-contract';
3
- export type { ForwardSegment, MediaRef, MentionSegment, ReplySegment, Segment, SegmentBase, TextSegment, } from '@zhin.js/im-contract';
3
+ export type { ForwardSegment, MediaRef, MentionSegment, ReplySegment, ShareSegment, Segment, SegmentBase, TextSegment, } from '@zhin.js/im-contract';
4
4
  /**
5
5
  * 媒体引用占位(全框架唯一媒体表达)。
6
6
  * kind=file:平台侧不透明文件引用(如 Telegram file_id、Milky resource_id),
@@ -54,5 +54,5 @@ export interface RpsSegment extends SegmentBase {
54
54
  result?: number;
55
55
  };
56
56
  }
57
- /** 规范态 segment(严格校验 text / mention / image / audio / video / file / reply / forward / face / dice / rps) */
57
+ /** 规范态 segment(严格校验 text / mention / image / audio / video / file / reply / forward / face / dice / rps / share) */
58
58
  export type LegacySpecificSegment = ImageSegment | AudioSegment | VideoSegment | FileSegment | FaceSegment | DiceSegment | RpsSegment;
@@ -1,5 +1,6 @@
1
1
  import { Schema } from '@zhin.js/schema';
2
- import type { MediaRef, Segment } from './types.js';
2
+ import type { Segment } from './types.js';
3
+ export { isMediaRef } from '@zhin.js/im-contract';
3
4
  export declare const mediaRefSchema: Schema<{
4
5
  kind?: any;
5
6
  value?: string | undefined;
@@ -222,8 +223,48 @@ export declare const rpsSegmentSchema: Schema<{
222
223
  } | undefined;
223
224
  platform?: Record<string, any> | undefined;
224
225
  }>;
226
+ export declare const shareSegmentSchema: Schema<{
227
+ type?: "share" | undefined;
228
+ data?: {
229
+ url?: string | undefined;
230
+ title?: string | undefined;
231
+ description?: string | undefined;
232
+ image?: string | undefined;
233
+ audio?: string | undefined;
234
+ content?: string | undefined;
235
+ artist?: string | undefined;
236
+ duration?: number | undefined;
237
+ config?: {
238
+ appid?: number | undefined;
239
+ package?: string | undefined;
240
+ sign?: string | undefined;
241
+ icon?: string | undefined;
242
+ version?: string | undefined;
243
+ } | undefined;
244
+ } | undefined;
245
+ platform?: Record<string, any> | undefined;
246
+ }, {
247
+ type?: "share" | undefined;
248
+ data?: {
249
+ url?: string | undefined;
250
+ title?: string | undefined;
251
+ description?: string | undefined;
252
+ image?: string | undefined;
253
+ audio?: string | undefined;
254
+ content?: string | undefined;
255
+ artist?: string | undefined;
256
+ duration?: number | undefined;
257
+ config?: {
258
+ appid?: number | undefined;
259
+ package?: string | undefined;
260
+ sign?: string | undefined;
261
+ icon?: string | undefined;
262
+ version?: string | undefined;
263
+ } | undefined;
264
+ } | undefined;
265
+ platform?: Record<string, any> | undefined;
266
+ }>;
225
267
  export declare const canonicalSegmentSchema: Schema<any, any>;
226
268
  export declare const segmentArraySchema: Schema<any[], any[]>;
227
- export declare function isMediaRef(value: unknown): value is MediaRef;
228
269
  /** 严格 canonical 段校验(@zhin.js/schema validate-only) */
229
270
  export declare function isStrictCanonicalSegment(value: unknown): value is Segment;
@@ -1,4 +1,5 @@
1
1
  import { Schema } from '@zhin.js/schema';
2
+ export { isMediaRef } from '@zhin.js/im-contract';
2
3
  const platformSchema = Schema.dict(Schema.any());
3
4
  const mediaKindSchema = Schema.union([
4
5
  Schema.const('url'),
@@ -95,6 +96,28 @@ export const rpsSegmentSchema = Schema.object({
95
96
  data: Schema.object({ result: Schema.number() }).required(),
96
97
  platform: platformSchema,
97
98
  });
99
+ const shareConfigSchema = Schema.object({
100
+ appid: Schema.number().required(),
101
+ package: Schema.string(),
102
+ sign: Schema.string(),
103
+ icon: Schema.string(),
104
+ version: Schema.string(),
105
+ });
106
+ export const shareSegmentSchema = Schema.object({
107
+ type: Schema.const('share'),
108
+ data: Schema.object({
109
+ url: Schema.string().required(),
110
+ title: Schema.string().required(),
111
+ description: Schema.string(),
112
+ image: Schema.string(),
113
+ audio: Schema.string(),
114
+ content: Schema.string(),
115
+ artist: Schema.string(),
116
+ duration: Schema.number(),
117
+ config: shareConfigSchema,
118
+ }).required(),
119
+ platform: platformSchema,
120
+ });
98
121
  export const canonicalSegmentSchema = Schema.discriminatedUnion('type', {
99
122
  text: {
100
123
  data: Schema.object({ text: Schema.string().required() }).required(),
@@ -163,11 +186,22 @@ export const canonicalSegmentSchema = Schema.discriminatedUnion('type', {
163
186
  data: Schema.object({ result: Schema.number() }).required(),
164
187
  platform: platformSchema,
165
188
  },
189
+ share: {
190
+ data: Schema.object({
191
+ url: Schema.string().required(),
192
+ title: Schema.string().required(),
193
+ description: Schema.string(),
194
+ image: Schema.string(),
195
+ audio: Schema.string(),
196
+ content: Schema.string(),
197
+ artist: Schema.string(),
198
+ duration: Schema.number(),
199
+ config: shareConfigSchema,
200
+ }).required(),
201
+ platform: platformSchema,
202
+ },
166
203
  });
167
204
  export const segmentArraySchema = Schema.list(canonicalSegmentSchema);
168
- export function isMediaRef(value) {
169
- return mediaRefSchema.safeParse(value).success;
170
- }
171
205
  /** 严格 canonical 段校验(@zhin.js/schema validate-only) */
172
206
  export function isStrictCanonicalSegment(value) {
173
207
  return canonicalSegmentSchema.safeParse(value).success;
@@ -0,0 +1,5 @@
1
+ import { type PermissionHost } from '@zhin.js/permission';
2
+ import type { Message } from '../message.js';
3
+ import type { Tool } from '../types.js';
4
+ /** Checks whether a Tool is visible to the current IM message context. */
5
+ export declare function canAccessTool(tool: Tool, message?: Message<any>, host?: PermissionHost | null): Promise<boolean>;
@@ -0,0 +1,17 @@
1
+ import { toPermissionSubject } from '@zhin.js/permission';
2
+ /** Checks whether a Tool is visible to the current IM message context. */
3
+ export async function canAccessTool(tool, message, host) {
4
+ if (!message)
5
+ return !tool.platforms?.length && !tool.scopes?.length && !tool.permissions?.length;
6
+ const adapter = String(message.$adapter);
7
+ const scope = (message.$channel?.type || 'private');
8
+ if (tool.platforms?.length && !tool.platforms.includes(adapter))
9
+ return false;
10
+ if (tool.scopes?.length && !tool.scopes.includes(scope))
11
+ return false;
12
+ if (!tool.permissions?.length)
13
+ return true;
14
+ if (!host)
15
+ return false;
16
+ return host.checkAll(tool.permissions, toPermissionSubject(message));
17
+ }
@@ -14,14 +14,10 @@ export function assertUserInteractionRequest(request) {
14
14
  if (request.type === 'select' || request.type === 'multiselect') {
15
15
  if (request.options.length === 0)
16
16
  throw new TypeError('User interaction options must not be empty');
17
- const labels = new Set();
18
17
  for (const option of request.options) {
19
18
  const label = option.label.trim().toLocaleLowerCase();
20
19
  if (!label)
21
20
  throw new TypeError('User interaction option label must not be empty');
22
- if (labels.has(label))
23
- throw new TypeError(`Duplicate user interaction option label: ${option.label}`);
24
- labels.add(label);
25
21
  }
26
22
  }
27
23
  if (request.type === 'multiselect') {
@@ -1,17 +1,13 @@
1
1
  /** Authoring API for Handler Feature — implementation in `@zhin.js/handler`. */
2
2
  export { parseHandlerDefinition, HandlerIndex, isHandlerIndex, handlerFeatureId, handlerFeature, handlerEventFromLocalName, resolveHandlerEvent, type HandlerEventMap, type HandlerDefinition, type HandlerDescriptor, type HandlerContext, type HandlerDispatchOptions, } from '@zhin.js/handler';
3
3
  import { type HandlerContext, type HandlerDefinition, type HandlerEventMap } from '@zhin.js/handler';
4
- import type { Plugin } from '../plugin.js';
5
4
  import type { Message } from '../plugin-runtime/im/contracts.js';
6
5
  import type { Notice } from '../notice.js';
7
6
  import type { Request } from '../request.js';
8
7
  import type { SystemEvent } from '../system-event.js';
9
8
  import type { AdapterClient, AdapterEvents, EndpointEvent, EndpointIdentity, PlatformEvent, RegisteredAdapterName } from '@zhin.js/adapter';
10
- type KnownKeys<T> = {
11
- [K in keyof T as string extends K ? never : number extends K ? never : K]: T[K];
12
- };
13
9
  declare module '@zhin.js/handler' {
14
- interface HandlerEventMap extends KnownKeys<Omit<Plugin.Lifecycle, 'message.receive' | 'notice.receive' | 'request.receive' | 'system.receive'>> {
10
+ interface HandlerEventMap {
15
11
  'message.receive': [event: EndpointEvent<Message>];
16
12
  'notice.receive': [event: EndpointEvent<Notice>];
17
13
  'request.receive': [event: EndpointEvent<Request>];
package/lib/index.d.ts CHANGED
@@ -2,82 +2,41 @@
2
2
  * Canonical IM messages, Endpoints, rendering, and plugin-facing core types.
3
3
  * @module @zhin.js/core
4
4
  */
5
- export * from './endpoint.js';
6
- export * from './endpoint-capabilities.js';
7
- export * from './plugin.js';
8
- export * from './command.js';
9
5
  export * from './component.js';
10
- export * from './adapter.js';
11
6
  export * from './message.js';
12
7
  export * from './im-scene.js';
13
8
  export * from './notice.js';
14
9
  export * from './request.js';
15
10
  export * from './system-event.js';
16
11
  export * from './side-event/index.js';
17
- export * from './schema-interaction.js';
18
12
  export type * from '@zhin.js/interaction';
19
13
  export * from './types.js';
20
14
  export * from './utils.js';
21
15
  export * from './errors.js';
22
- export * from './built/config.js';
23
- export * from './built/command.js';
24
- export * from './built/schedule.js';
25
- export type { ScheduleDescriptor, ScheduleHandle, ScheduleContextExtensions } from './built/schedule.js';
26
16
  export * from './models/system-log.js';
27
17
  export * from './models/user.js';
28
- export * from './built/permit-parse.js';
29
- export * from './built/permit-check.js';
30
- export * from './built/platform-permit.js';
31
- export * from './built/authorization.js';
32
18
  export * from './built/message-enrich.js';
33
19
  export type { AgentTurnMessage, SyntheticMessageInput } from './built/message-enrich.js';
34
- export * from './built/runtime-io.js';
35
- export * from './built/database.js';
36
- export * from './built/message-filter.js';
37
- export * from './built/tool.js';
38
- export * from './built/skill.js';
39
- export * from './built/agent-preset.js';
20
+ export * from './built/tool-access.js';
40
21
  export * from './built/common-adapter-tools.js';
41
22
  export * from './built/roles.js';
42
23
  export * from './im-session-id.js';
43
24
  export * from './built/ai-trigger.js';
44
25
  export * from './built/ai-access.js';
45
- export * from './built/dispatcher.js';
46
- export * from './built/schema-feature.js';
47
26
  export * from './built/login-assist.js';
48
27
  export * from './built/generated-qrcode.js';
49
- export * from './built/rich-segments/index.js';
28
+ export { markdownToPlainText } from './built/rich-segments/markdown-to-text.js';
50
29
  export * from './built/interactive-segments/index.js';
51
30
  export * from './built/user-interaction.js';
52
31
  export * from './built/ai-outbound/index.js';
53
- export { loadHtmlRenderer, seedHtmlRenderer, HTML_RENDERER_PACKAGE } from './built/html-renderer-loader.js';
54
- export { loadSpeechPipeline, seedSpeechPipeline, SPEECH_PACKAGE } from './built/speech-loader.js';
55
32
  export * from './built/outbound-media-utils.js';
56
- export * from './built/outbound-media-contract.js';
57
- export * from './built/interactive-segment-contract.js';
58
33
  export * from './built/segment-contract/index.js';
59
34
  export type { SegmentMediaRef } from './built/segment-contract/media.js';
60
35
  export * from './built/generic-segment-mapper.js';
61
- export * from './built/adapter-process.js';
62
- export * from './built/component.js';
63
- export * from './built/inbound-runner.js';
64
- export type { RunInboundMessageOptions, InboundRunResult } from './built/inbound-runner.js';
65
- export * from './built/connect-endpoint-instance.js';
66
- export type { ConnectEndpointInstanceOptions } from './built/connect-endpoint-instance.js';
67
- export * from './built/endpoint-lifecycle.js';
68
- export type { EndpointLifecycleKind, EndpointLifecyclePayload } from './built/endpoint-lifecycle.js';
69
- export * from './built/endpoint-manager.js';
70
- export type { EndpointConfigRecord, EndpointManager, ProvisionContext } from './built/endpoint-manager.js';
71
- export * from './built/endpoint-lifecycle-service.js';
72
- export * from './built/schema-endpoint-manager.js';
73
- export * from './built/endpoint-commands.js';
74
- export * from './built/introspection-format.js';
75
- export * from './built/management-command-guard.js';
76
36
  export * from './built/html-to-text.js';
77
37
  export * from './built/html-segment-fallback.js';
78
38
  export * from '@zhin.js/database';
79
39
  export * from '@zhin.js/logger';
80
40
  export { Schema } from '@zhin.js/schema';
81
- export type { PluginLike } from '@zhin.js/kernel';
82
- export { Feature, ScheduleEngine, getScheduleEngine, setScheduleEngine, Scheduler, getScheduler, setScheduler, } from '@zhin.js/kernel';
83
- export type { FeatureJSON, FeatureListener, Schedule, JobPayload, JobState, ScheduledJob, JobStore, JobCallback, AddJobOptions, IScheduler, SchedulerOptions, ScheduleFireCallback, MemoryScheduleRegistration, ScheduleEngineOptions, JobContext, ResolvedJob, ScheduleKind, } from '@zhin.js/kernel';
41
+ export { ScheduleEngine, Scheduler, } from '@zhin.js/kernel';
42
+ export type { Schedule, JobPayload, JobState, ScheduledJob, JobStore, JobCallback, AddJobOptions, IScheduler, SchedulerOptions, ScheduleFireCallback, MemoryScheduleRegistration, ScheduleEngineOptions, JobContext, ResolvedJob, ScheduleKind, } from '@zhin.js/kernel';
package/lib/index.js CHANGED
@@ -2,76 +2,40 @@
2
2
  * Canonical IM messages, Endpoints, rendering, and plugin-facing core types.
3
3
  * @module @zhin.js/core
4
4
  */
5
- // ── Core 类模块 ──────────────────────────────────────────────────────
6
- export * from './endpoint.js';
7
- export * from './endpoint-capabilities.js';
8
- export * from './plugin.js';
9
- export * from './command.js';
10
5
  export * from './component.js';
11
- export * from './adapter.js';
12
6
  export * from './message.js';
13
7
  export * from './im-scene.js';
14
8
  export * from './notice.js';
15
9
  export * from './request.js';
16
10
  export * from './system-event.js';
17
11
  export * from './side-event/index.js';
18
- export * from './schema-interaction.js';
19
12
  export * from './types.js';
20
13
  export * from './utils.js';
21
14
  export * from './errors.js';
22
15
  // ── Built 模块 ──────────────────────────────────────────────────────
23
- export * from './built/config.js';
24
- export * from './built/command.js';
25
- export * from './built/schedule.js';
26
16
  // Models
27
17
  export * from './models/system-log.js';
28
18
  export * from './models/user.js';
29
- export * from './built/permit-parse.js';
30
- export * from './built/permit-check.js';
31
- export * from './built/platform-permit.js';
32
- export * from './built/authorization.js';
33
19
  export * from './built/message-enrich.js';
34
- export * from './built/runtime-io.js';
35
- export * from './built/database.js';
36
- export * from './built/message-filter.js';
37
- export * from './built/tool.js';
38
- export * from './built/skill.js';
39
- export * from './built/agent-preset.js';
20
+ export * from './built/tool-access.js';
40
21
  export * from './built/common-adapter-tools.js';
41
22
  export * from './built/roles.js';
42
23
  export * from './im-session-id.js';
43
24
  export * from './built/ai-trigger.js';
44
25
  export * from './built/ai-access.js';
45
- export * from './built/dispatcher.js';
46
- export * from './built/schema-feature.js';
47
26
  export * from './built/login-assist.js';
48
27
  export * from './built/generated-qrcode.js';
49
- export * from './built/rich-segments/index.js';
28
+ export { markdownToPlainText } from './built/rich-segments/markdown-to-text.js';
50
29
  export * from './built/interactive-segments/index.js';
51
30
  export * from './built/user-interaction.js';
52
31
  export * from './built/ai-outbound/index.js';
53
- export { loadHtmlRenderer, seedHtmlRenderer, HTML_RENDERER_PACKAGE } from './built/html-renderer-loader.js';
54
- export { loadSpeechPipeline, seedSpeechPipeline, SPEECH_PACKAGE } from './built/speech-loader.js';
55
32
  export * from './built/outbound-media-utils.js';
56
- export * from './built/outbound-media-contract.js';
57
- export * from './built/interactive-segment-contract.js';
58
33
  export * from './built/segment-contract/index.js';
59
34
  export * from './built/generic-segment-mapper.js';
60
- export * from './built/adapter-process.js';
61
- export * from './built/component.js';
62
- export * from './built/inbound-runner.js';
63
- export * from './built/connect-endpoint-instance.js';
64
- export * from './built/endpoint-lifecycle.js';
65
- export * from './built/endpoint-manager.js';
66
- export * from './built/endpoint-lifecycle-service.js';
67
- export * from './built/schema-endpoint-manager.js';
68
- export * from './built/endpoint-commands.js';
69
- export * from './built/introspection-format.js';
70
- export * from './built/management-command-guard.js';
71
35
  export * from './built/html-to-text.js';
72
36
  export * from './built/html-segment-fallback.js';
73
37
  // ── 外部库 re-export ──────────────────────────────────────────────────
74
38
  export * from '@zhin.js/database';
75
39
  export * from '@zhin.js/logger';
76
40
  export { Schema } from '@zhin.js/schema';
77
- export { Feature, ScheduleEngine, getScheduleEngine, setScheduleEngine, Scheduler, getScheduler, setScheduler, } from '@zhin.js/kernel';
41
+ export { ScheduleEngine, Scheduler, } from '@zhin.js/kernel';
package/lib/message.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import type { MessageElement, MessageSender, SendContent } from "./types.js";
2
2
  import { Component } from "./component.js";
3
- import { Adapters } from "./adapter.js";
4
3
  /**
5
4
  * 消息组件类型:用于自定义消息结构
6
5
  */
@@ -35,7 +34,7 @@ export type MessageType = 'group' | 'private' | 'channel';
35
34
  */
36
35
  export interface MessageBase {
37
36
  $id: string;
38
- $adapter: keyof Adapters;
37
+ $adapter: string;
39
38
  $endpoint: string;
40
39
  $content: MessageElement[];
41
40
  $sender: MessageSender;
@@ -1,4 +1,3 @@
1
- import { Definition } from '@zhin.js/database';
2
1
  export interface SystemLog {
3
2
  id?: number;
4
3
  level: string;
@@ -7,4 +6,3 @@ export interface SystemLog {
7
6
  source: string;
8
7
  timestamp: Date;
9
8
  }
10
- export declare const SystemLogDefinition: Definition<SystemLog>;
@@ -1,8 +1 @@
1
- export const SystemLogDefinition = {
2
- id: { type: 'integer', autoIncrement: true, primary: true },
3
- level: { type: 'text', nullable: false },
4
- name: { type: 'text', nullable: false },
5
- message: { type: 'text', nullable: false },
6
- source: { type: 'text', nullable: false },
7
- timestamp: { type: 'date', nullable: false }
8
- };
1
+ export {};
@@ -1,4 +1,3 @@
1
- import { Definition } from '@zhin.js/database';
2
1
  export interface User {
3
2
  id: string;
4
3
  name?: string;
@@ -6,4 +5,3 @@ export interface User {
6
5
  third_part: string[];
7
6
  permissions?: string[];
8
7
  }
9
- export declare const UserDefinition: Definition<User>;
@@ -1,7 +1 @@
1
- export const UserDefinition = {
2
- id: { type: "text", nullable: false },
3
- name: { type: 'text', nullable: true },
4
- password: { type: 'text', nullable: true },
5
- third_part: { type: 'json', default: [] },
6
- permissions: { type: 'json', default: [] }
7
- };
1
+ export {};
package/lib/notice.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import type { Adapters } from './adapter.js';
2
1
  import type { NoticeKind } from './side-event/types.js';
3
2
  import type { SideEventBase } from './side-event/base.js';
4
3
  export type { NoticeKind, ComposedNoticeName } from './side-event/types.js';
@@ -26,7 +25,7 @@ export { composeSideEventName, formatSideEventName, matchesSideEventName, parseS
26
25
  * ```
27
26
  */
28
27
  export interface NoticeBase extends SideEventBase {
29
- $adapter: keyof Adapters;
28
+ $adapter: string;
30
29
  $type: NoticeKind;
31
30
  }
32
31
  /**
@@ -0,0 +1,19 @@
1
+ import { type ConversationContextBlock, type ConversationEventReader, type ConversationEventStore, type ConversationReference, type ConversationResolution, type ConversationRef, type DeliveryReceipt } from '@zhin.js/im-contract';
2
+ import type { Notice } from '../../notice.js';
3
+ import type { IncomingMessage, MessageSenderRef, SendRequest } from './contracts.js';
4
+ /** Owns one ImRuntime's conversation fact store, projections, and consumer cursors. */
5
+ export declare class ConversationRuntime {
6
+ #private;
7
+ constructor(events?: ConversationEventStore);
8
+ get reader(): ConversationEventReader;
9
+ replaceStore(events: ConversationEventStore): void;
10
+ resolveLocal(reference: ConversationReference): Promise<ConversationResolution | undefined>;
11
+ readContext(conversation: ConversationRef, consumer: string, throughSequence: number, limit?: number, excludeMessageId?: string): Promise<Readonly<{
12
+ blocks: readonly ConversationContextBlock[];
13
+ cursor: number;
14
+ }>>;
15
+ commitContext(conversation: ConversationRef, consumer: string, cursor: number): Promise<void>;
16
+ recordIncoming(input: IncomingMessage, sender: MessageSenderRef | undefined): Promise<number | undefined>;
17
+ recordOutbound(request: SendRequest, receipt: DeliveryReceipt): Promise<void>;
18
+ recordNotice(notice: Notice): Promise<void>;
19
+ }