@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.
- package/lib/built/roles.d.ts +6 -1
- package/lib/built/roles.js +11 -20
- package/lib/built/segment-contract/validate.d.ts +301 -158
- package/lib/built/user-interaction.js +9 -3
- package/lib/feature/middleware-public-api.d.ts +5 -0
- package/lib/feature/middleware-public-api.js +5 -0
- package/lib/feature/middleware.d.ts +20 -2
- package/lib/feature/middleware.js +6 -2
- package/lib/plugin-runtime/im/contracts.d.ts +14 -0
- package/lib/plugin-runtime/im/contracts.js +3 -1
- package/lib/plugin-runtime/im/conversation-runtime.d.ts +13 -1
- package/lib/plugin-runtime/im/conversation-runtime.js +47 -1
- package/lib/plugin-runtime/im/endpoint-runtime.d.ts +8 -3
- package/lib/plugin-runtime/im/endpoint-runtime.js +46 -3
- package/lib/plugin-runtime/im/im-runtime.d.ts +12 -1
- package/lib/plugin-runtime/im/im-runtime.js +18 -1
- package/lib/plugin-runtime/im/inbound-dedup.d.ts +51 -0
- package/lib/plugin-runtime/im/inbound-dedup.js +184 -0
- package/lib/plugin-runtime/im/inbound-origin.d.ts +101 -0
- package/lib/plugin-runtime/im/inbound-origin.js +76 -0
- package/lib/plugin-runtime/im/inbound-runtime.d.ts +16 -2
- package/lib/plugin-runtime/im/inbound-runtime.js +235 -11
- package/lib/plugin-runtime/im/index.d.ts +3 -1
- package/lib/plugin-runtime/im/index.js +1 -0
- package/lib/plugin-runtime/im/interaction-runtime.d.ts +11 -0
- package/lib/plugin-runtime/im/interaction-runtime.js +17 -0
- package/lib/plugin-runtime/im/interactive-router.d.ts +18 -1
- package/lib/plugin-runtime/im/interactive-router.js +62 -8
- package/lib/plugin-runtime/im/jsx-button-registry.js +6 -2
- package/lib/plugin-runtime/im/message-dispatcher.js +10 -0
- package/lib/plugin-runtime/im/message-events.d.ts +7 -0
- package/lib/plugin-runtime/im/outbound-delivery-runtime.d.ts +2 -0
- package/lib/plugin-runtime/im/outbound-delivery-runtime.js +37 -45
- package/lib/plugin-runtime/im/outbound-ledger.d.ts +24 -0
- package/lib/plugin-runtime/im/outbound-ledger.js +114 -0
- package/lib/plugin-runtime/im/outbound-projection.d.ts +15 -0
- package/lib/plugin-runtime/im/outbound-projection.js +55 -0
- package/lib/plugin-runtime/im/outbound-renderer.d.ts +3 -0
- package/lib/plugin-runtime/im/outbound-renderer.js +18 -0
- package/lib/plugin-runtime/im/outbound-segments.d.ts +3 -0
- package/lib/plugin-runtime/im/outbound-segments.js +34 -5
- package/package.json +19 -30
|
@@ -148,13 +148,14 @@ function adapterTypeName(packageName) {
|
|
|
148
148
|
* - anything else (plain strings, legacy `{ text }` shorthands) passes through.
|
|
149
149
|
*/
|
|
150
150
|
export async function normalizeOutboundPayload(payload, renderer, options) {
|
|
151
|
+
options?.signal?.throwIfAborted();
|
|
151
152
|
const mediaPolicy = options?.mediaPolicy ?? DEFAULT_MEDIA_POLICY;
|
|
152
153
|
if (Array.isArray(payload)) {
|
|
153
154
|
const resolved = await Promise.all(flattenOutboundArray(payload).map((item) => normalizeOneSegment(item, renderer, mediaPolicy, options)));
|
|
154
|
-
return applyOutboundMediaPolicy(resolved, mediaPolicy);
|
|
155
|
+
return applyOutboundMediaPolicy(resolved, mediaPolicy, options?.onFallback);
|
|
155
156
|
}
|
|
156
157
|
if (isOutboundSegment(payload)) {
|
|
157
|
-
return applyOutboundMediaPolicy([await normalizeOneSegment(payload, renderer, mediaPolicy, options)], mediaPolicy);
|
|
158
|
+
return applyOutboundMediaPolicy([await normalizeOneSegment(payload, renderer, mediaPolicy, options)], mediaPolicy, options?.onFallback);
|
|
158
159
|
}
|
|
159
160
|
return payload;
|
|
160
161
|
}
|
|
@@ -181,17 +182,20 @@ async function renderHtmlSegment(segment, renderer, mediaPolicy, options) {
|
|
|
181
182
|
const html = typeof data.html === 'string' ? data.html : '';
|
|
182
183
|
// url-or-text 端点无法投递 base64 图片(本层无上传通道),直接文本降级,跳过渲染。
|
|
183
184
|
if (options?.htmlPolicy === 'text') {
|
|
185
|
+
if (html)
|
|
186
|
+
options.onFallback?.('html_text_policy');
|
|
184
187
|
return { type: 'text', data: { text: htmlSegmentFallbackText(data, html) } };
|
|
185
188
|
}
|
|
186
189
|
if (html && renderer && mediaPolicy !== 'url-or-text') {
|
|
187
190
|
try {
|
|
188
|
-
const result = await renderer.render(html, {
|
|
191
|
+
const result = await awaitHtmlRender(renderer.render(html, {
|
|
192
|
+
...(options?.signal ? { signal: options.signal } : {}),
|
|
189
193
|
width: typeof data.width === 'number' ? data.width : DEFAULT_CARD_WIDTH,
|
|
190
194
|
format: 'png',
|
|
191
195
|
...(typeof data.backgroundColor === 'string'
|
|
192
196
|
? { backgroundColor: data.backgroundColor }
|
|
193
197
|
: {}),
|
|
194
|
-
});
|
|
198
|
+
}), options?.signal);
|
|
195
199
|
if (result.format === 'png' && result.data && typeof result.data === 'object') {
|
|
196
200
|
const base64 = Buffer.from(result.data).toString('base64');
|
|
197
201
|
return {
|
|
@@ -207,22 +211,46 @@ async function renderHtmlSegment(segment, renderer, mediaPolicy, options) {
|
|
|
207
211
|
};
|
|
208
212
|
}
|
|
209
213
|
options?.onHtmlFallback?.('renderer_failed');
|
|
214
|
+
options?.onFallback?.('renderer_failed');
|
|
210
215
|
}
|
|
211
216
|
catch {
|
|
217
|
+
options?.signal?.throwIfAborted();
|
|
212
218
|
options?.onHtmlFallback?.('renderer_failed');
|
|
219
|
+
options?.onFallback?.('renderer_failed');
|
|
213
220
|
}
|
|
214
221
|
}
|
|
215
222
|
else if (html) {
|
|
216
223
|
options?.onHtmlFallback?.(mediaPolicy === 'url-or-text' ? 'media_unsupported' : 'renderer_unavailable');
|
|
224
|
+
options?.onFallback?.(mediaPolicy === 'url-or-text' ? 'media_unsupported' : 'renderer_unavailable');
|
|
217
225
|
}
|
|
218
226
|
return { type: 'text', data: { text: htmlSegmentFallbackText(data, html) } };
|
|
219
227
|
}
|
|
228
|
+
/** Abort the caller promptly even when the optional host cannot cancel its work. */
|
|
229
|
+
async function awaitHtmlRender(work, signal) {
|
|
230
|
+
if (!signal)
|
|
231
|
+
return work;
|
|
232
|
+
let onAbort;
|
|
233
|
+
try {
|
|
234
|
+
return await new Promise((resolve, reject) => {
|
|
235
|
+
onAbort = () => reject(signal.reason);
|
|
236
|
+
signal.addEventListener('abort', onAbort, { once: true });
|
|
237
|
+
// Attach both handlers even when already aborted: late host rejection is
|
|
238
|
+
// observed and cannot become an unhandled rejection after cancellation.
|
|
239
|
+
work.then(resolve, reject);
|
|
240
|
+
if (signal.aborted)
|
|
241
|
+
onAbort();
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
finally {
|
|
245
|
+
signal.removeEventListener('abort', onAbort);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
220
248
|
/**
|
|
221
249
|
* 媒体协商:仅 `url-or-text` 需要在本层动作——媒体段的非 URL MediaRef
|
|
222
250
|
* (base64 / 本地路径)无法投递,降级为文本(alt / file_name 优先)。
|
|
223
251
|
*/
|
|
224
252
|
const MEDIA_SEGMENT_TYPES = new Set(['image', 'audio', 'video', 'file']);
|
|
225
|
-
function applyOutboundMediaPolicy(segments, mediaPolicy) {
|
|
253
|
+
function applyOutboundMediaPolicy(segments, mediaPolicy, onFallback) {
|
|
226
254
|
if (mediaPolicy !== 'url-or-text')
|
|
227
255
|
return segments;
|
|
228
256
|
return segments.map((segment) => {
|
|
@@ -232,6 +260,7 @@ function applyOutboundMediaPolicy(segments, mediaPolicy) {
|
|
|
232
260
|
const media = data.media;
|
|
233
261
|
if (!isMediaRef(media) || media.kind === 'url')
|
|
234
262
|
return segment;
|
|
263
|
+
onFallback?.('media_unsupported');
|
|
235
264
|
const label = typeof data.alt === 'string' && data.alt
|
|
236
265
|
? data.alt
|
|
237
266
|
: typeof data.name === 'string' && data.name
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhin.js/core",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.44",
|
|
4
4
|
"description": "Zhin机器人核心框架",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -8,57 +8,46 @@
|
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
10
10
|
"types": "./lib/index.d.ts",
|
|
11
|
-
"development": "./src/index.ts",
|
|
12
11
|
"import": "./lib/index.js"
|
|
13
12
|
},
|
|
14
13
|
"./queue-im-field-contract": {
|
|
15
14
|
"types": "./lib/built/queue-im-field-contract.d.ts",
|
|
16
|
-
"development": "./src/built/queue-im-field-contract.ts",
|
|
17
15
|
"import": "./lib/built/queue-im-field-contract.js"
|
|
18
16
|
},
|
|
19
17
|
"./runtime": {
|
|
20
18
|
"types": "./lib/plugin-runtime/im/index.d.ts",
|
|
21
|
-
"development": "./src/plugin-runtime/im/index.ts",
|
|
22
19
|
"import": "./lib/plugin-runtime/im/index.js"
|
|
23
20
|
},
|
|
24
21
|
"./jsx": {
|
|
25
22
|
"types": "./lib/jsx.d.ts",
|
|
26
|
-
"development": "./src/jsx.ts",
|
|
27
23
|
"import": "./lib/jsx.js"
|
|
28
24
|
},
|
|
29
25
|
"./jsx-runtime": {
|
|
30
26
|
"types": "./lib/jsx-runtime.d.ts",
|
|
31
|
-
"development": "./src/jsx-runtime.ts",
|
|
32
27
|
"import": "./lib/jsx-runtime.js"
|
|
33
28
|
},
|
|
34
29
|
"./jsx-dev-runtime": {
|
|
35
30
|
"types": "./lib/jsx-dev-runtime.d.ts",
|
|
36
|
-
"development": "./src/jsx-dev-runtime.ts",
|
|
37
31
|
"import": "./lib/jsx-dev-runtime.js"
|
|
38
32
|
},
|
|
39
33
|
"./feature/adapter": {
|
|
40
34
|
"types": "./lib/feature/adapter.d.ts",
|
|
41
|
-
"development": "./src/feature/adapter.ts",
|
|
42
35
|
"import": "./lib/feature/adapter.js"
|
|
43
36
|
},
|
|
44
37
|
"./feature/command": {
|
|
45
38
|
"types": "./lib/feature/command.d.ts",
|
|
46
|
-
"development": "./src/feature/command.ts",
|
|
47
39
|
"import": "./lib/feature/command.js"
|
|
48
40
|
},
|
|
49
41
|
"./feature/component": {
|
|
50
42
|
"types": "./lib/feature/component.d.ts",
|
|
51
|
-
"development": "./src/feature/component.ts",
|
|
52
43
|
"import": "./lib/feature/component.js"
|
|
53
44
|
},
|
|
54
45
|
"./feature/middleware": {
|
|
55
46
|
"types": "./lib/feature/middleware.d.ts",
|
|
56
|
-
"development": "./src/feature/middleware.ts",
|
|
57
47
|
"import": "./lib/feature/middleware.js"
|
|
58
48
|
},
|
|
59
49
|
"./feature/handler": {
|
|
60
50
|
"types": "./lib/feature/handler.d.ts",
|
|
61
|
-
"development": "./src/feature/handler.ts",
|
|
62
51
|
"import": "./lib/feature/handler.js"
|
|
63
52
|
}
|
|
64
53
|
},
|
|
@@ -68,29 +57,29 @@
|
|
|
68
57
|
"dependencies": {
|
|
69
58
|
"qrcode": "^1.5.4",
|
|
70
59
|
"segment-matcher": "^1.0.5",
|
|
71
|
-
"@zhin.js/adapter": "1.1.
|
|
72
|
-
"@zhin.js/
|
|
73
|
-
"@zhin.js/
|
|
74
|
-
"@zhin.js/database": "1.1.
|
|
75
|
-
"@zhin.js/handler": "1.1.
|
|
76
|
-
"@zhin.js/
|
|
77
|
-
"@zhin.js/
|
|
78
|
-
"@zhin.js/
|
|
79
|
-
"@zhin.js/logger": "1.1.
|
|
80
|
-
"@zhin.js/
|
|
81
|
-
"@zhin.js/
|
|
82
|
-
"@zhin.js/
|
|
83
|
-
"@zhin.js/schedule-feature": "1.1.
|
|
84
|
-
"@zhin.js/
|
|
85
|
-
"@zhin.js/
|
|
86
|
-
"@zhin.js/feature-kit": "1.1.
|
|
60
|
+
"@zhin.js/adapter": "1.1.19",
|
|
61
|
+
"@zhin.js/component": "1.1.6",
|
|
62
|
+
"@zhin.js/command": "1.1.7",
|
|
63
|
+
"@zhin.js/database": "1.1.4",
|
|
64
|
+
"@zhin.js/handler": "1.1.5",
|
|
65
|
+
"@zhin.js/interaction": "1.1.2",
|
|
66
|
+
"@zhin.js/kernel": "1.1.4",
|
|
67
|
+
"@zhin.js/im-contract": "1.1.4",
|
|
68
|
+
"@zhin.js/logger": "1.1.2",
|
|
69
|
+
"@zhin.js/permission": "1.1.6",
|
|
70
|
+
"@zhin.js/middleware": "1.1.6",
|
|
71
|
+
"@zhin.js/schema": "1.1.3",
|
|
72
|
+
"@zhin.js/schedule-feature": "1.1.5",
|
|
73
|
+
"@zhin.js/jsx": "1.1.3",
|
|
74
|
+
"@zhin.js/plugin-runtime": "1.1.14",
|
|
75
|
+
"@zhin.js/feature-kit": "1.1.5"
|
|
87
76
|
},
|
|
88
77
|
"devDependencies": {
|
|
89
78
|
"@types/node": "^26.1.2",
|
|
90
79
|
"@types/qrcode": "^1.5.6",
|
|
91
80
|
"ajv": "8.18.0",
|
|
92
81
|
"typescript": "^6.0.3",
|
|
93
|
-
"@zhin.js/ai": "1.1.
|
|
82
|
+
"@zhin.js/ai": "1.1.39"
|
|
94
83
|
},
|
|
95
84
|
"repository": {
|
|
96
85
|
"type": "git",
|
|
@@ -108,7 +97,7 @@
|
|
|
108
97
|
"url": "https://github.com/lc-cn"
|
|
109
98
|
},
|
|
110
99
|
"engines": {
|
|
111
|
-
"node": "
|
|
100
|
+
"node": ">=22.19.0"
|
|
112
101
|
},
|
|
113
102
|
"zhin": {
|
|
114
103
|
"protocol": 1,
|