dsh-im-lark 0.1.7 → 0.1.8
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/src/host/bridge.js +30 -8
- package/lib/src/shared/version.js +1 -1
- package/package.json +1 -1
package/lib/src/host/bridge.js
CHANGED
|
@@ -69,9 +69,14 @@ export function createLarkBridge(deps) {
|
|
|
69
69
|
let coreHandle = null;
|
|
70
70
|
let capabilities = LARK_CAPABILITIES;
|
|
71
71
|
let disposed = false;
|
|
72
|
-
/**
|
|
72
|
+
/**
|
|
73
|
+
* 已交付的记录:PATCH 终态与 supersedes 都要回看原文。
|
|
74
|
+
*
|
|
75
|
+
* `delivery` 是**渲染用**的那份(见 `presented`),不是核心原样:重画必须和首屏一致,
|
|
76
|
+
* 否则作答后「参考」段会凭空冒出来。
|
|
77
|
+
*/
|
|
73
78
|
const delivered = new Map();
|
|
74
|
-
/**
|
|
79
|
+
/** 流式交付的当前修订:低于它的修订不再产生平台操作。`quoted` 记首屏有没有引用气泡。 */
|
|
75
80
|
const streams = new Map();
|
|
76
81
|
/** 卡片装不下的流:已用分条消息发过一次,后续修订不再原地 PATCH,避免消息瀑布。 */
|
|
77
82
|
const detachedStreams = new Map();
|
|
@@ -117,7 +122,7 @@ export function createLarkBridge(deps) {
|
|
|
117
122
|
return { deliveryId, status: 'sent', bridgeMessageId: current.messageId, messagesSent: 0 };
|
|
118
123
|
}
|
|
119
124
|
if (current !== undefined) {
|
|
120
|
-
const card = renderDeliveryCard(delivery, { interactive: false });
|
|
125
|
+
const card = renderDeliveryCard(presented(delivery, current.quoted), { interactive: false });
|
|
121
126
|
if (!cardFits(card)) {
|
|
122
127
|
// 这次修订装不进卡片:只发一次分条最终稿,并把这条流标记为「不再原地更新」。
|
|
123
128
|
streamOversized = true;
|
|
@@ -126,7 +131,7 @@ export function createLarkBridge(deps) {
|
|
|
126
131
|
else {
|
|
127
132
|
try {
|
|
128
133
|
await deps.api.patchCard({ messageId: current.messageId, card });
|
|
129
|
-
remember(streams, stream.id, { revision: stream.revision, messageId: current.messageId }, MAX_DELIVERED);
|
|
134
|
+
remember(streams, stream.id, { revision: stream.revision, messageId: current.messageId, quoted: current.quoted }, MAX_DELIVERED);
|
|
130
135
|
markDone();
|
|
131
136
|
return { deliveryId, status: 'sent', bridgeMessageId: current.messageId, messagesSent: 0 };
|
|
132
137
|
}
|
|
@@ -144,14 +149,16 @@ export function createLarkBridge(deps) {
|
|
|
144
149
|
bytes: Buffer.from(image.data, 'base64'),
|
|
145
150
|
fileName: image.name ?? `图片.${extensionOf(image.mediaType)}`,
|
|
146
151
|
}));
|
|
147
|
-
const
|
|
152
|
+
const replyTarget = delivery.inReplyTo === undefined ? undefined : inbound.get(delivery.inReplyTo);
|
|
153
|
+
// 引用气泡已经定位到原消息,卡片里不用再列一遍 `refs`(见 presented)。
|
|
154
|
+
const quoted = replyTarget !== undefined;
|
|
155
|
+
const card = renderDeliveryCard(presented(delivery, quoted), { interactive: delivery.interaction !== undefined });
|
|
148
156
|
const useCard = cardFits(card);
|
|
149
157
|
// 交互卡装不下时明确降级:内容照发,回执里带 error 说明;状态仍是 sent,避免核心重投。
|
|
150
158
|
const interactionDropped = delivery.interaction !== undefined && !useCard;
|
|
151
159
|
const fallbackNote = interactionDropped
|
|
152
160
|
? '\n\n(内容超过卡片上限,交互已降级为纯文本卡片;可直接回复文字作答,或到 Web 端处理。)'
|
|
153
161
|
: '';
|
|
154
|
-
const replyTarget = delivery.inReplyTo === undefined ? undefined : inbound.get(delivery.inReplyTo);
|
|
155
162
|
let receipt;
|
|
156
163
|
try {
|
|
157
164
|
receipt = await outbound.deliver({
|
|
@@ -183,13 +190,14 @@ export function createLarkBridge(deps) {
|
|
|
183
190
|
markDone();
|
|
184
191
|
const messageId = receipt.messageIds[0];
|
|
185
192
|
if (messageId !== undefined) {
|
|
186
|
-
|
|
193
|
+
// 存渲染副本:作答/过期重画要和首屏一致,不能再把「参考」段补回来。
|
|
194
|
+
remember(delivered, deliveryId, { delivery: presented(delivery, quoted), messageId }, MAX_DELIVERED);
|
|
187
195
|
if (stream !== undefined) {
|
|
188
196
|
if (streamOversized || !cardFits(card)) {
|
|
189
197
|
remember(detachedStreams, stream.id, messageId, MAX_DELIVERED);
|
|
190
198
|
}
|
|
191
199
|
else {
|
|
192
|
-
remember(streams, stream.id, { revision: stream.revision, messageId }, MAX_DELIVERED);
|
|
200
|
+
remember(streams, stream.id, { revision: stream.revision, messageId, quoted }, MAX_DELIVERED);
|
|
193
201
|
}
|
|
194
202
|
}
|
|
195
203
|
}
|
|
@@ -261,6 +269,20 @@ export function createLarkBridge(deps) {
|
|
|
261
269
|
// 显式给会话 id 的调用方(一致性测试、命令行)原样放行。
|
|
262
270
|
return recipient.startsWith('oc_') ? recipient : undefined;
|
|
263
271
|
}
|
|
272
|
+
/**
|
|
273
|
+
* 交给卡片渲染的那份交付。
|
|
274
|
+
*
|
|
275
|
+
* 只有这次**真的用引用回复**定位到了原消息,才把 `refs` 去掉:「参考」段是给没有
|
|
276
|
+
* 引用气泡的消息用的(告诉用户这是哪个会话),引用气泡已经交代清楚了,再列一遍
|
|
277
|
+
* 会话标题只是噪音。判据必须是 `replyTarget` 解析成功而不是 `inReplyTo` 有值——
|
|
278
|
+
* `inbound` 只是内存缓存,插件重启后一律解析不到(重启孤儿通知正是这种),那时
|
|
279
|
+
* 消息没有引用气泡,「参考」是唯一的定位线索。
|
|
280
|
+
*
|
|
281
|
+
* 返回的是渲染副本,核心原交付不动(`completes`、`interaction` 都原样保留)。
|
|
282
|
+
*/
|
|
283
|
+
function presented(delivery, quoted) {
|
|
284
|
+
return quoted ? { ...delivery, refs: undefined } : delivery;
|
|
285
|
+
}
|
|
264
286
|
/** 旧卡改成终态;失败只记日志,不能让新交付因此失败。 */
|
|
265
287
|
async function supersede(deliveryId) {
|
|
266
288
|
const record = delivered.get(deliveryId);
|