@zhin.js/core 1.1.42 → 1.1.44

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 (42) hide show
  1. package/lib/built/roles.d.ts +6 -1
  2. package/lib/built/roles.js +11 -20
  3. package/lib/built/segment-contract/validate.d.ts +301 -158
  4. package/lib/built/user-interaction.js +9 -3
  5. package/lib/feature/middleware-public-api.d.ts +5 -0
  6. package/lib/feature/middleware-public-api.js +5 -0
  7. package/lib/feature/middleware.d.ts +20 -2
  8. package/lib/feature/middleware.js +6 -2
  9. package/lib/plugin-runtime/im/contracts.d.ts +14 -0
  10. package/lib/plugin-runtime/im/contracts.js +3 -1
  11. package/lib/plugin-runtime/im/conversation-runtime.d.ts +13 -1
  12. package/lib/plugin-runtime/im/conversation-runtime.js +47 -1
  13. package/lib/plugin-runtime/im/endpoint-runtime.d.ts +8 -3
  14. package/lib/plugin-runtime/im/endpoint-runtime.js +46 -3
  15. package/lib/plugin-runtime/im/im-runtime.d.ts +12 -1
  16. package/lib/plugin-runtime/im/im-runtime.js +18 -1
  17. package/lib/plugin-runtime/im/inbound-dedup.d.ts +51 -0
  18. package/lib/plugin-runtime/im/inbound-dedup.js +184 -0
  19. package/lib/plugin-runtime/im/inbound-origin.d.ts +101 -0
  20. package/lib/plugin-runtime/im/inbound-origin.js +76 -0
  21. package/lib/plugin-runtime/im/inbound-runtime.d.ts +16 -2
  22. package/lib/plugin-runtime/im/inbound-runtime.js +235 -11
  23. package/lib/plugin-runtime/im/index.d.ts +3 -1
  24. package/lib/plugin-runtime/im/index.js +1 -0
  25. package/lib/plugin-runtime/im/interaction-runtime.d.ts +11 -0
  26. package/lib/plugin-runtime/im/interaction-runtime.js +17 -0
  27. package/lib/plugin-runtime/im/interactive-router.d.ts +18 -1
  28. package/lib/plugin-runtime/im/interactive-router.js +62 -8
  29. package/lib/plugin-runtime/im/jsx-button-registry.js +6 -2
  30. package/lib/plugin-runtime/im/message-dispatcher.js +10 -0
  31. package/lib/plugin-runtime/im/message-events.d.ts +7 -0
  32. package/lib/plugin-runtime/im/outbound-delivery-runtime.d.ts +2 -0
  33. package/lib/plugin-runtime/im/outbound-delivery-runtime.js +37 -45
  34. package/lib/plugin-runtime/im/outbound-ledger.d.ts +24 -0
  35. package/lib/plugin-runtime/im/outbound-ledger.js +114 -0
  36. package/lib/plugin-runtime/im/outbound-projection.d.ts +15 -0
  37. package/lib/plugin-runtime/im/outbound-projection.js +55 -0
  38. package/lib/plugin-runtime/im/outbound-renderer.d.ts +3 -0
  39. package/lib/plugin-runtime/im/outbound-renderer.js +18 -0
  40. package/lib/plugin-runtime/im/outbound-segments.d.ts +3 -0
  41. package/lib/plugin-runtime/im/outbound-segments.js +34 -5
  42. package/package.json +19 -30
@@ -10,5 +10,10 @@ export declare function roleSatisfies(callerRoles: Iterable<SenderRole>, require
10
10
  export declare function normalizeSenderRoles(roles: Iterable<SenderRole>): SenderRole[];
11
11
  export declare function hasSenderRole(roles: Iterable<SenderRole>, role: SenderRole): boolean;
12
12
  export declare function formatSenderRolesForLabel(roles: readonly SenderRole[]): string;
13
- /** 剥离用户正文里自造的发送者前缀 */
13
+ /**
14
+ * 转义用户正文里所有自造的 `[sender:` / `[origin:` 标签(任意位置、大小写不敏感,
15
+ * 容忍 `[ sender :`、零宽字符、全角冒号)。命中时把开头的 ASCII `[` 换成全角 `[`,
16
+ * 其余原样保留:模型仍能看出这是用户文本,但它不再是权威标签。
17
+ * 幂等(已转义文本再次调用不变),不再剥离开头,也不 trim 原文空白。
18
+ */
14
19
  export declare function stripUserSpoofedSenderPrefix(rawContent: string): string;
@@ -38,25 +38,16 @@ export function hasSenderRole(roles, role) {
38
38
  export function formatSenderRolesForLabel(roles) {
39
39
  return roles.filter((r) => r !== 'user').join(',') || 'user';
40
40
  }
41
- /** 剥离用户正文里自造的发送者前缀 */
41
+ // 空白与零宽字符(不含 U+200D:会破坏 emoji ZWJ 序列)。
42
+ const SPOOF_GAP = '[\\s\\u200B\\u200C\\u2060\\uFEFF]';
43
+ const spoofWord = (word) => word.split('').join(`${SPOOF_GAP}*`);
44
+ const SPOOFED_LABEL_RE = new RegExp(`\\[(?=${SPOOF_GAP}*(?:${spoofWord('sender')}|${spoofWord('origin')})${SPOOF_GAP}*[::])`, 'gi');
45
+ /**
46
+ * 转义用户正文里所有自造的 `[sender:` / `[origin:` 标签(任意位置、大小写不敏感,
47
+ * 容忍 `[ sender :`、零宽字符、全角冒号)。命中时把开头的 ASCII `[` 换成全角 `[`,
48
+ * 其余原样保留:模型仍能看出这是用户文本,但它不再是权威标签。
49
+ * 幂等(已转义文本再次调用不变),不再剥离开头,也不 trim 原文空白。
50
+ */
42
51
  export function stripUserSpoofedSenderPrefix(rawContent) {
43
- let text = rawContent.trimStart();
44
- const prefixRe = /^\[sender:(?:id=[^\]]*|[^\]]*)\]\s*/i;
45
- const rolesRe = /^\[sender:id=[^\s\]]+(?:\s+name=[^\]]+)?\s+roles=[^\]]+\]\s*/i;
46
- let changed = true;
47
- while (changed) {
48
- changed = false;
49
- const m1 = text.match(prefixRe);
50
- if (m1) {
51
- text = text.slice(m1[0].length);
52
- changed = true;
53
- continue;
54
- }
55
- const m2 = text.match(rolesRe);
56
- if (m2) {
57
- text = text.slice(m2[0].length);
58
- changed = true;
59
- }
60
- }
61
- return text;
52
+ return rawContent.replace(SPOOFED_LABEL_RE, '\uFF3B');
62
53
  }
@@ -1,267 +1,410 @@
1
1
  import { Schema } from '@zhin.js/schema';
2
2
  import type { Segment } from './types.js';
3
3
  export { isMediaRef } from '@zhin.js/im-contract';
4
- export declare const mediaRefSchema: Schema<{
4
+ export declare const mediaRefSchema: Schema<Schema.InputRecord<{
5
+ kind: Schema;
6
+ value: Schema<string, string> & Schema.Present & Schema.Required;
7
+ mime_type: Schema<string, string>;
8
+ file_name: Schema<string, string>;
9
+ size: Schema<number, number>;
10
+ }>, {
11
+ value: string;
12
+ } & {
5
13
  kind?: any;
6
- value?: string | undefined;
7
- mime_type?: string | undefined;
8
- file_name?: string | undefined;
9
- size?: number | undefined;
10
- }, {
11
- kind?: any;
12
- value?: string | undefined;
13
14
  mime_type?: string | undefined;
14
15
  file_name?: string | undefined;
15
16
  size?: number | undefined;
16
17
  }>;
17
- export declare const textSegmentSchema: Schema<{
18
- type?: "text" | undefined;
19
- data?: {
20
- text?: string | undefined;
21
- } | undefined;
22
- platform?: Record<string, any> | undefined;
23
- }, {
24
- type?: "text" | undefined;
25
- data?: {
26
- text?: string | undefined;
27
- } | undefined;
18
+ export declare const textSegmentSchema: Schema<Schema.InputRecord<{
19
+ type: Schema<"text", "text"> & Schema.Present;
20
+ data: Schema<Schema.InputRecord<{
21
+ text: Schema<string, string> & Schema.Present & Schema.Required;
22
+ }>, {
23
+ text: string;
24
+ } & {}> & Schema.Present & Schema.Required;
25
+ platform: Schema<Record<string, any>, Record<string, any>>;
26
+ }>, {
27
+ type: "text";
28
+ data: {
29
+ text: string;
30
+ } & {};
31
+ } & {
28
32
  platform?: Record<string, any> | undefined;
29
33
  }>;
30
- export declare const mentionSegmentSchema: Schema<{
31
- type?: "mention" | undefined;
32
- data?: {
33
- target?: string | undefined;
34
+ export declare const mentionSegmentSchema: Schema<Schema.InputRecord<{
35
+ type: Schema<"mention", "mention"> & Schema.Present;
36
+ data: Schema<Schema.InputRecord<{
37
+ target: Schema<string, string> & Schema.Present & Schema.Required;
38
+ name: Schema<string, string>;
39
+ }>, {
40
+ target: string;
41
+ } & {
34
42
  name?: string | undefined;
35
- } | undefined;
36
- platform?: Record<string, any> | undefined;
37
- }, {
38
- type?: "mention" | undefined;
39
- data?: {
40
- target?: string | undefined;
43
+ }> & Schema.Present & Schema.Required;
44
+ platform: Schema<Record<string, any>, Record<string, any>>;
45
+ }>, {
46
+ type: "mention";
47
+ data: {
48
+ target: string;
49
+ } & {
41
50
  name?: string | undefined;
42
- } | undefined;
51
+ };
52
+ } & {
43
53
  platform?: Record<string, any> | undefined;
44
54
  }>;
45
- export declare const imageSegmentSchema: Schema<{
46
- type?: "image" | undefined;
47
- data?: {
48
- media?: {
55
+ export declare const imageSegmentSchema: Schema<Schema.InputRecord<{
56
+ type: Schema<"image", "image"> & Schema.Present;
57
+ data: Schema<Schema.InputRecord<{
58
+ media: Schema<Schema.InputRecord<{
59
+ kind: Schema;
60
+ value: Schema<string, string> & Schema.Present & Schema.Required;
61
+ mime_type: Schema<string, string>;
62
+ file_name: Schema<string, string>;
63
+ size: Schema<number, number>;
64
+ }>, {
65
+ value: string;
66
+ } & {
67
+ kind?: any;
68
+ mime_type?: string | undefined;
69
+ file_name?: string | undefined;
70
+ size?: number | undefined;
71
+ }> & Schema.Present & Schema.Required;
72
+ alt: Schema<string, string>;
73
+ }>, {
74
+ media: {
75
+ value: string;
76
+ } & {
49
77
  kind?: any;
50
- value?: string | undefined;
51
78
  mime_type?: string | undefined;
52
79
  file_name?: string | undefined;
53
80
  size?: number | undefined;
54
- } | undefined;
81
+ };
82
+ } & {
55
83
  alt?: string | undefined;
56
- } | undefined;
57
- platform?: Record<string, any> | undefined;
58
- }, {
59
- type?: "image" | undefined;
60
- data?: {
61
- media?: {
84
+ }> & Schema.Present & Schema.Required;
85
+ platform: Schema<Record<string, any>, Record<string, any>>;
86
+ }>, {
87
+ type: "image";
88
+ data: {
89
+ media: {
90
+ value: string;
91
+ } & {
62
92
  kind?: any;
63
- value?: string | undefined;
64
93
  mime_type?: string | undefined;
65
94
  file_name?: string | undefined;
66
95
  size?: number | undefined;
67
- } | undefined;
96
+ };
97
+ } & {
68
98
  alt?: string | undefined;
69
- } | undefined;
99
+ };
100
+ } & {
70
101
  platform?: Record<string, any> | undefined;
71
102
  }>;
72
- export declare const audioSegmentSchema: Schema<{
73
- type?: "audio" | undefined;
74
- data?: {
75
- media?: {
103
+ export declare const audioSegmentSchema: Schema<Schema.InputRecord<{
104
+ type: Schema<"audio", "audio"> & Schema.Present;
105
+ data: Schema<Schema.InputRecord<{
106
+ media: Schema<Schema.InputRecord<{
107
+ kind: Schema;
108
+ value: Schema<string, string> & Schema.Present & Schema.Required;
109
+ mime_type: Schema<string, string>;
110
+ file_name: Schema<string, string>;
111
+ size: Schema<number, number>;
112
+ }>, {
113
+ value: string;
114
+ } & {
115
+ kind?: any;
116
+ mime_type?: string | undefined;
117
+ file_name?: string | undefined;
118
+ size?: number | undefined;
119
+ }> & Schema.Present & Schema.Required;
120
+ duration: Schema<number, number>;
121
+ }>, {
122
+ media: {
123
+ value: string;
124
+ } & {
76
125
  kind?: any;
77
- value?: string | undefined;
78
126
  mime_type?: string | undefined;
79
127
  file_name?: string | undefined;
80
128
  size?: number | undefined;
81
- } | undefined;
129
+ };
130
+ } & {
82
131
  duration?: number | undefined;
83
- } | undefined;
84
- platform?: Record<string, any> | undefined;
85
- }, {
86
- type?: "audio" | undefined;
87
- data?: {
88
- media?: {
132
+ }> & Schema.Present & Schema.Required;
133
+ platform: Schema<Record<string, any>, Record<string, any>>;
134
+ }>, {
135
+ type: "audio";
136
+ data: {
137
+ media: {
138
+ value: string;
139
+ } & {
89
140
  kind?: any;
90
- value?: string | undefined;
91
141
  mime_type?: string | undefined;
92
142
  file_name?: string | undefined;
93
143
  size?: number | undefined;
94
- } | undefined;
144
+ };
145
+ } & {
95
146
  duration?: number | undefined;
96
- } | undefined;
147
+ };
148
+ } & {
97
149
  platform?: Record<string, any> | undefined;
98
150
  }>;
99
- export declare const videoSegmentSchema: Schema<{
100
- type?: "video" | undefined;
101
- data?: {
102
- media?: {
151
+ export declare const videoSegmentSchema: Schema<Schema.InputRecord<{
152
+ type: Schema<"video", "video"> & Schema.Present;
153
+ data: Schema<Schema.InputRecord<{
154
+ media: Schema<Schema.InputRecord<{
155
+ kind: Schema;
156
+ value: Schema<string, string> & Schema.Present & Schema.Required;
157
+ mime_type: Schema<string, string>;
158
+ file_name: Schema<string, string>;
159
+ size: Schema<number, number>;
160
+ }>, {
161
+ value: string;
162
+ } & {
163
+ kind?: any;
164
+ mime_type?: string | undefined;
165
+ file_name?: string | undefined;
166
+ size?: number | undefined;
167
+ }> & Schema.Present & Schema.Required;
168
+ duration: Schema<number, number>;
169
+ alt: Schema<string, string>;
170
+ }>, {
171
+ media: {
172
+ value: string;
173
+ } & {
103
174
  kind?: any;
104
- value?: string | undefined;
105
175
  mime_type?: string | undefined;
106
176
  file_name?: string | undefined;
107
177
  size?: number | undefined;
108
- } | undefined;
178
+ };
179
+ } & {
109
180
  duration?: number | undefined;
110
181
  alt?: string | undefined;
111
- } | undefined;
112
- platform?: Record<string, any> | undefined;
113
- }, {
114
- type?: "video" | undefined;
115
- data?: {
116
- media?: {
182
+ }> & Schema.Present & Schema.Required;
183
+ platform: Schema<Record<string, any>, Record<string, any>>;
184
+ }>, {
185
+ type: "video";
186
+ data: {
187
+ media: {
188
+ value: string;
189
+ } & {
117
190
  kind?: any;
118
- value?: string | undefined;
119
191
  mime_type?: string | undefined;
120
192
  file_name?: string | undefined;
121
193
  size?: number | undefined;
122
- } | undefined;
194
+ };
195
+ } & {
123
196
  duration?: number | undefined;
124
197
  alt?: string | undefined;
125
- } | undefined;
198
+ };
199
+ } & {
126
200
  platform?: Record<string, any> | undefined;
127
201
  }>;
128
- export declare const fileSegmentSchema: Schema<{
129
- type?: "file" | undefined;
130
- data?: {
131
- media?: {
202
+ export declare const fileSegmentSchema: Schema<Schema.InputRecord<{
203
+ type: Schema<"file", "file"> & Schema.Present;
204
+ data: Schema<Schema.InputRecord<{
205
+ media: Schema<Schema.InputRecord<{
206
+ kind: Schema;
207
+ value: Schema<string, string> & Schema.Present & Schema.Required;
208
+ mime_type: Schema<string, string>;
209
+ file_name: Schema<string, string>;
210
+ size: Schema<number, number>;
211
+ }>, {
212
+ value: string;
213
+ } & {
214
+ kind?: any;
215
+ mime_type?: string | undefined;
216
+ file_name?: string | undefined;
217
+ size?: number | undefined;
218
+ }> & Schema.Present & Schema.Required;
219
+ name: Schema<string, string>;
220
+ }>, {
221
+ media: {
222
+ value: string;
223
+ } & {
132
224
  kind?: any;
133
- value?: string | undefined;
134
225
  mime_type?: string | undefined;
135
226
  file_name?: string | undefined;
136
227
  size?: number | undefined;
137
- } | undefined;
228
+ };
229
+ } & {
138
230
  name?: string | undefined;
139
- } | undefined;
140
- platform?: Record<string, any> | undefined;
141
- }, {
142
- type?: "file" | undefined;
143
- data?: {
144
- media?: {
231
+ }> & Schema.Present & Schema.Required;
232
+ platform: Schema<Record<string, any>, Record<string, any>>;
233
+ }>, {
234
+ type: "file";
235
+ data: {
236
+ media: {
237
+ value: string;
238
+ } & {
145
239
  kind?: any;
146
- value?: string | undefined;
147
240
  mime_type?: string | undefined;
148
241
  file_name?: string | undefined;
149
242
  size?: number | undefined;
150
- } | undefined;
243
+ };
244
+ } & {
151
245
  name?: string | undefined;
152
- } | undefined;
246
+ };
247
+ } & {
153
248
  platform?: Record<string, any> | undefined;
154
249
  }>;
155
- export declare const replySegmentSchema: Schema<{
156
- type?: "reply" | undefined;
157
- data?: {
158
- message_id?: string | undefined;
159
- } | undefined;
160
- platform?: Record<string, any> | undefined;
161
- }, {
162
- type?: "reply" | undefined;
163
- data?: {
164
- message_id?: string | undefined;
165
- } | undefined;
250
+ export declare const replySegmentSchema: Schema<Schema.InputRecord<{
251
+ type: Schema<"reply", "reply"> & Schema.Present;
252
+ data: Schema<Schema.InputRecord<{
253
+ message_id: Schema<string, string> & Schema.Present & Schema.Required;
254
+ }>, {
255
+ message_id: string;
256
+ } & {}> & Schema.Present & Schema.Required;
257
+ platform: Schema<Record<string, any>, Record<string, any>>;
258
+ }>, {
259
+ type: "reply";
260
+ data: {
261
+ message_id: string;
262
+ } & {};
263
+ } & {
166
264
  platform?: Record<string, any> | undefined;
167
265
  }>;
168
- export declare const forwardSegmentSchema: Schema<{
169
- type?: "forward" | undefined;
170
- data?: {
171
- forward_id?: string | undefined;
266
+ export declare const forwardSegmentSchema: Schema<Schema.InputRecord<{
267
+ type: Schema<"forward", "forward"> & Schema.Present;
268
+ data: Schema<Schema.InputRecord<{
269
+ forward_id: Schema<string, string> & Schema.Present & Schema.Required;
270
+ title: Schema<string, string>;
271
+ messages: Schema<any[][], any[][]>;
272
+ }>, {
273
+ forward_id: string;
274
+ } & {
172
275
  title?: string | undefined;
173
276
  messages?: any[][] | undefined;
174
- } | undefined;
175
- platform?: Record<string, any> | undefined;
176
- }, {
177
- type?: "forward" | undefined;
178
- data?: {
179
- forward_id?: string | undefined;
277
+ }> & Schema.Present & Schema.Required;
278
+ platform: Schema<Record<string, any>, Record<string, any>>;
279
+ }>, {
280
+ type: "forward";
281
+ data: {
282
+ forward_id: string;
283
+ } & {
180
284
  title?: string | undefined;
181
285
  messages?: any[][] | undefined;
182
- } | undefined;
286
+ };
287
+ } & {
183
288
  platform?: Record<string, any> | undefined;
184
289
  }>;
185
- export declare const faceSegmentSchema: Schema<{
186
- type?: "face" | undefined;
187
- data?: {
290
+ export declare const faceSegmentSchema: Schema<Schema.InputRecord<{
291
+ type: Schema<"face", "face"> & Schema.Present;
292
+ data: Schema<Schema.InputRecord<{
293
+ id: Schema;
294
+ name: Schema<string, string>;
295
+ }>, {} & {
188
296
  id?: any;
189
297
  name?: string | undefined;
190
- } | undefined;
191
- platform?: Record<string, any> | undefined;
192
- }, {
193
- type?: "face" | undefined;
194
- data?: {
298
+ }> & Schema.Present & Schema.Required;
299
+ platform: Schema<Record<string, any>, Record<string, any>>;
300
+ }>, {
301
+ type: "face";
302
+ data: {} & {
195
303
  id?: any;
196
304
  name?: string | undefined;
197
- } | undefined;
305
+ };
306
+ } & {
198
307
  platform?: Record<string, any> | undefined;
199
308
  }>;
200
- export declare const diceSegmentSchema: Schema<{
201
- type?: "dice" | undefined;
202
- data?: {
309
+ export declare const diceSegmentSchema: Schema<Schema.InputRecord<{
310
+ type: Schema<"dice", "dice"> & Schema.Present;
311
+ data: Schema<Schema.InputRecord<{
312
+ result: Schema<number, number>;
313
+ }>, {} & {
203
314
  result?: number | undefined;
204
- } | undefined;
205
- platform?: Record<string, any> | undefined;
206
- }, {
207
- type?: "dice" | undefined;
208
- data?: {
315
+ }> & Schema.Present & Schema.Required;
316
+ platform: Schema<Record<string, any>, Record<string, any>>;
317
+ }>, {
318
+ type: "dice";
319
+ data: {} & {
209
320
  result?: number | undefined;
210
- } | undefined;
321
+ };
322
+ } & {
211
323
  platform?: Record<string, any> | undefined;
212
324
  }>;
213
- export declare const rpsSegmentSchema: Schema<{
214
- type?: "rps" | undefined;
215
- data?: {
325
+ export declare const rpsSegmentSchema: Schema<Schema.InputRecord<{
326
+ type: Schema<"rps", "rps"> & Schema.Present;
327
+ data: Schema<Schema.InputRecord<{
328
+ result: Schema<number, number>;
329
+ }>, {} & {
216
330
  result?: number | undefined;
217
- } | undefined;
218
- platform?: Record<string, any> | undefined;
219
- }, {
220
- type?: "rps" | undefined;
221
- data?: {
331
+ }> & Schema.Present & Schema.Required;
332
+ platform: Schema<Record<string, any>, Record<string, any>>;
333
+ }>, {
334
+ type: "rps";
335
+ data: {} & {
222
336
  result?: number | undefined;
223
- } | undefined;
337
+ };
338
+ } & {
224
339
  platform?: Record<string, any> | undefined;
225
340
  }>;
226
- export declare const shareSegmentSchema: Schema<{
227
- type?: "share" | undefined;
228
- data?: {
229
- url?: string | undefined;
230
- title?: string | undefined;
341
+ export declare const shareSegmentSchema: Schema<Schema.InputRecord<{
342
+ type: Schema<"share", "share"> & Schema.Present;
343
+ data: Schema<Schema.InputRecord<{
344
+ url: Schema<string, string> & Schema.Present & Schema.Required;
345
+ title: Schema<string, string> & Schema.Present & Schema.Required;
346
+ description: Schema<string, string>;
347
+ image: Schema<string, string>;
348
+ audio: Schema<string, string>;
349
+ content: Schema<string, string>;
350
+ artist: Schema<string, string>;
351
+ duration: Schema<number, number>;
352
+ config: Schema<Schema.InputRecord<{
353
+ appid: Schema<number, number> & Schema.Present & Schema.Required;
354
+ package: Schema<string, string>;
355
+ sign: Schema<string, string>;
356
+ icon: Schema<string, string>;
357
+ version: Schema<string, string>;
358
+ }>, {
359
+ appid: number;
360
+ } & {
361
+ package?: string | undefined;
362
+ sign?: string | undefined;
363
+ icon?: string | undefined;
364
+ version?: string | undefined;
365
+ }>;
366
+ }>, {
367
+ url: string;
368
+ title: string;
369
+ } & {
231
370
  description?: string | undefined;
232
371
  image?: string | undefined;
233
372
  audio?: string | undefined;
234
373
  content?: string | undefined;
235
374
  artist?: string | undefined;
236
375
  duration?: number | undefined;
237
- config?: {
238
- appid?: number | undefined;
376
+ config?: ({
377
+ appid: number;
378
+ } & {
239
379
  package?: string | undefined;
240
380
  sign?: string | undefined;
241
381
  icon?: string | undefined;
242
382
  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;
383
+ }) | undefined;
384
+ }> & Schema.Present & Schema.Required;
385
+ platform: Schema<Record<string, any>, Record<string, any>>;
386
+ }>, {
387
+ type: "share";
388
+ data: {
389
+ url: string;
390
+ title: string;
391
+ } & {
251
392
  description?: string | undefined;
252
393
  image?: string | undefined;
253
394
  audio?: string | undefined;
254
395
  content?: string | undefined;
255
396
  artist?: string | undefined;
256
397
  duration?: number | undefined;
257
- config?: {
258
- appid?: number | undefined;
398
+ config?: ({
399
+ appid: number;
400
+ } & {
259
401
  package?: string | undefined;
260
402
  sign?: string | undefined;
261
403
  icon?: string | undefined;
262
404
  version?: string | undefined;
263
- } | undefined;
264
- } | undefined;
405
+ }) | undefined;
406
+ };
407
+ } & {
265
408
  platform?: Record<string, any> | undefined;
266
409
  }>;
267
410
  export declare const canonicalSegmentSchema: Schema<any, any>;
@@ -191,14 +191,20 @@ function instructionFor(request) {
191
191
  }
192
192
  }
193
193
  function renderOptions(options) {
194
- return options.map((option, index) => `${index + 1}. ${option.label}${option.description ? ` — ${option.description}` : ''}`).join('\n');
194
+ return options.map((option, index) => {
195
+ const aliases = option.aliases?.length ? `(${option.aliases.join(' / ')})` : '';
196
+ const description = option.description ? ` — ${option.description}` : '';
197
+ return `${index + 1}. ${option.label}${aliases}${description}`;
198
+ }).join('\n');
195
199
  }
196
200
  function resolveOption(options, raw) {
197
201
  const index = Number(raw);
198
202
  if (Number.isInteger(index) && index >= 1 && index <= options.length)
199
203
  return options[index - 1];
200
- const normalized = raw.toLocaleLowerCase();
201
- return options.find((option) => option.label.trim().toLocaleLowerCase() === normalized);
204
+ const normalized = raw.trim().toLocaleLowerCase();
205
+ const matches = (candidate) => candidate.trim().toLocaleLowerCase() === normalized;
206
+ return options.find((option) => matches(option.label))
207
+ ?? options.find((option) => option.aliases?.some(matches));
202
208
  }
203
209
  function uniqueOptions(options) {
204
210
  const result = [];
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Incoming Message and outbound envelope middleware authoring contracts.
3
+ * @module zhin.js/middleware
4
+ */
5
+ export { defineMiddleware, type MiddlewareContext, type MiddlewareContinuation, type MiddlewareDefinition, type MiddlewareDefinitionBase, type MiddlewareNext, type MiddlewarePhase, type MiddlewareTarget, type OutboundMiddlewareNext, } from './middleware.js';
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Incoming Message and outbound envelope middleware authoring contracts.
3
+ * @module zhin.js/middleware
4
+ */
5
+ export { defineMiddleware, } from './middleware.js';