@zhin.js/core 1.1.37 → 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.
@@ -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;
@@ -223,6 +223,47 @@ export declare const rpsSegmentSchema: Schema<{
223
223
  } | undefined;
224
224
  platform?: Record<string, any> | undefined;
225
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
+ }>;
226
267
  export declare const canonicalSegmentSchema: Schema<any, any>;
227
268
  export declare const segmentArraySchema: Schema<any[], any[]>;
228
269
  /** 严格 canonical 段校验(@zhin.js/schema validate-only) */
@@ -96,6 +96,28 @@ export const rpsSegmentSchema = Schema.object({
96
96
  data: Schema.object({ result: Schema.number() }).required(),
97
97
  platform: platformSchema,
98
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
+ });
99
121
  export const canonicalSegmentSchema = Schema.discriminatedUnion('type', {
100
122
  text: {
101
123
  data: Schema.object({ text: Schema.string().required() }).required(),
@@ -164,6 +186,20 @@ export const canonicalSegmentSchema = Schema.discriminatedUnion('type', {
164
186
  data: Schema.object({ result: Schema.number() }).required(),
165
187
  platform: platformSchema,
166
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
+ },
167
203
  });
168
204
  export const segmentArraySchema = Schema.list(canonicalSegmentSchema);
169
205
  /** 严格 canonical 段校验(@zhin.js/schema validate-only) */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhin.js/core",
3
- "version": "1.1.37",
3
+ "version": "1.1.38",
4
4
  "description": "Zhin机器人核心框架",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",
@@ -68,19 +68,19 @@
68
68
  "dependencies": {
69
69
  "qrcode": "^1.5.4",
70
70
  "segment-matcher": "^1.0.5",
71
- "@zhin.js/adapter": "1.1.14",
72
- "@zhin.js/command": "1.1.1",
73
- "@zhin.js/component": "1.1.1",
74
- "@zhin.js/database": "1.1.1",
75
- "@zhin.js/handler": "1.1.1",
76
- "@zhin.js/im-contract": "1.1.1",
71
+ "@zhin.js/adapter": "1.1.15",
72
+ "@zhin.js/component": "1.1.2",
73
+ "@zhin.js/database": "1.1.2",
74
+ "@zhin.js/handler": "1.1.2",
75
+ "@zhin.js/im-contract": "1.1.2",
77
76
  "@zhin.js/interaction": "1.1.0",
78
77
  "@zhin.js/kernel": "1.1.1",
79
78
  "@zhin.js/logger": "1.1.1",
80
- "@zhin.js/middleware": "1.1.1",
81
- "@zhin.js/permission": "1.1.1",
82
- "@zhin.js/plugin-runtime": "1.1.10",
83
- "@zhin.js/schedule-feature": "1.1.1",
79
+ "@zhin.js/middleware": "1.1.2",
80
+ "@zhin.js/permission": "1.1.2",
81
+ "@zhin.js/command": "1.1.2",
82
+ "@zhin.js/plugin-runtime": "1.1.11",
83
+ "@zhin.js/schedule-feature": "1.1.2",
84
84
  "@zhin.js/schema": "1.1.0"
85
85
  },
86
86
  "devDependencies": {
@@ -88,7 +88,7 @@
88
88
  "@types/qrcode": "^1.5.6",
89
89
  "ajv": "8.18.0",
90
90
  "typescript": "^6.0.3",
91
- "@zhin.js/ai": "1.1.34"
91
+ "@zhin.js/ai": "1.1.35"
92
92
  },
93
93
  "repository": {
94
94
  "type": "git",