@suwenguang/pi-feishu-bridge 0.0.0-stage → 0.6.2

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 (52) hide show
  1. package/.pi/extensions/feishu/index.ts +11 -0
  2. package/.pi/feishu/debug.pi.log +81 -0
  3. package/.pi/feishu/state.pi.json +12 -0
  4. package/README.md +210 -2
  5. package/package.json +57 -4
  6. package/src/adapters/pi/PiConversationRuntime.ts +1559 -0
  7. package/src/adapters/pi/index.ts +1169 -0
  8. package/src/adapters/pi/setup.ts +108 -0
  9. package/src/feishu/app-register.ts +50 -0
  10. package/src/feishu/ask.ts +388 -0
  11. package/src/feishu/attachment-processor.ts +198 -0
  12. package/src/feishu/attachments.ts +192 -0
  13. package/src/feishu/bridge-runtime.ts +129 -0
  14. package/src/feishu/bridge-store.ts +92 -0
  15. package/src/feishu/card-action-webhook.ts +141 -0
  16. package/src/feishu/card-actions.ts +241 -0
  17. package/src/feishu/card-builder.ts +277 -0
  18. package/src/feishu/cardkit-stream.ts +483 -0
  19. package/src/feishu/cards.ts +413 -0
  20. package/src/feishu/config.ts +427 -0
  21. package/src/feishu/daemon-spec.ts +43 -0
  22. package/src/feishu/debug.ts +51 -0
  23. package/src/feishu/dedupe-store.ts +150 -0
  24. package/src/feishu/delivery.ts +185 -0
  25. package/src/feishu/gateway-lock.ts +256 -0
  26. package/src/feishu/group-trigger.ts +128 -0
  27. package/src/feishu/image-send.ts +256 -0
  28. package/src/feishu/instance.ts +170 -0
  29. package/src/feishu/instances.ts +148 -0
  30. package/src/feishu/interactive-card.ts +236 -0
  31. package/src/feishu/learn-approval.ts +321 -0
  32. package/src/feishu/live-cards.ts +128 -0
  33. package/src/feishu/message-handler.ts +512 -0
  34. package/src/feishu/messages.ts +356 -0
  35. package/src/feishu/oversize-progress-card.ts +101 -0
  36. package/src/feishu/progress-channel.ts +154 -0
  37. package/src/feishu/progress-note.ts +371 -0
  38. package/src/feishu/prompt-timeout.ts +81 -0
  39. package/src/feishu/reply-card-options.ts +73 -0
  40. package/src/feishu/reply-card.ts +498 -0
  41. package/src/feishu/restart.ts +286 -0
  42. package/src/feishu/retry.ts +102 -0
  43. package/src/feishu/rich-text.ts +387 -0
  44. package/src/feishu/runtime-config.ts +286 -0
  45. package/src/feishu/runtime.ts +110 -0
  46. package/src/feishu/slash-commands.ts +239 -0
  47. package/src/feishu/thinking.ts +24 -0
  48. package/src/feishu/transport.ts +792 -0
  49. package/src/feishu/types.ts +183 -0
  50. package/src/feishu/ui-notify.ts +44 -0
  51. package/src/feishu/user-name.ts +121 -0
  52. package/src/feishu/workspace.ts +42 -0
@@ -0,0 +1,498 @@
1
+ /**
2
+ * 回复呈现:
3
+ * - 默认 CardKit streaming_mode:客户端逐字打印(print_step=1)
4
+ * - 关闭流式时:先「回复中」卡,结束一次写入全文
5
+ * - 不展示工具/阶段过程
6
+ */
7
+ import { randomUUID } from "node:crypto";
8
+ import {
9
+ buildReplyCard,
10
+ defaultFinalNote,
11
+ type ReplyCardFinalStatus,
12
+ type ReplyCardStatus,
13
+ } from "./card-builder.ts";
14
+ import { CardKitStream, type CardKitTarget } from "./cardkit-stream.ts";
15
+ import { ProgressTracker, progressNeedsElement } from "./progress-note.ts";
16
+ import { resolveStreamOptions, type ReplyCardStreamOptions } from "./reply-card-options.ts";
17
+ import { loadConfig } from "./config.ts";
18
+ import { debugLog } from "./debug.ts";
19
+ import { registerLiveCard, unregisterLiveCard } from "./live-cards.ts";
20
+ import { flushLocalImages, stripLocalImageMarkdown } from "./image-send.ts";
21
+
22
+ export type { ReplyCardStatus, ReplyCardFinalStatus } from "./card-builder.ts";
23
+ export {
24
+ buildReplyCard,
25
+ parseStopTaskActionValue,
26
+ STOP_ACTION,
27
+ } from "./card-builder.ts";
28
+
29
+ /**
30
+ * 这张卡发到哪里。
31
+ * chatId 优先(平铺一条新消息);话题群/回复链必须用 replyToMessageId。
32
+ */
33
+ export type ReplyCardTarget =
34
+ | (CardKitTarget & { replyInThread?: boolean })
35
+ | { chatId: string; replyToMessageId?: string; replyInThread?: boolean };
36
+
37
+ /** 路由快照:只取 resolveCardTarget 需要的字段,便于单测 */
38
+ export type CardRouteLike = {
39
+ chatId: string;
40
+ chatType: "p2p" | "group";
41
+ threadMessageId?: string;
42
+ lastMessageId: string;
43
+ };
44
+
45
+ /**
46
+ * 决定卡片发到哪里(**唯一入口**,所有发卡路径都必须走它)。
47
+ *
48
+ * 回归背景:回答卡与选择题卡都 reply 同一条用户消息时,飞书把它们归成同一个
49
+ * 回复簇,主聊天流只留最后一条预览 —— 先到的卡看起来被后到的「刷掉」了。
50
+ * 因此普通会话改成平铺发新消息;只有话题群/回复链必须留在 reply 里,
51
+ * 否则 create 会另开一个话题。
52
+ */
53
+ export function resolveCardTarget(route: CardRouteLike): ReplyCardTarget {
54
+ // replyInThread 必须跟着走:话题群里 reply 不带它,图片会落到群主消息流,
55
+ // 用户在话题里看不到(文字卡片是 CardKit reply,不受影响,于是只丢图)
56
+ if (route.threadMessageId) {
57
+ return { replyToMessageId: route.lastMessageId, replyInThread: true };
58
+ }
59
+ return { chatId: route.chatId };
60
+ }
61
+
62
+ export type ReplyCardSink = {
63
+ readonly runId: string;
64
+ readonly bodyText: string;
65
+ /** 当前工具执行过程清单(停止回调要把同样的内容放回响应卡,否则清单会被刷没) */
66
+ readonly progressText: string;
67
+ /** 是否停在「等用户选择」的暂停态(askUser 出临界区前必须为 false) */
68
+ readonly paused: boolean;
69
+ updateFromEvent(event: unknown): void;
70
+ stopImmediately(note?: string): Promise<void>;
71
+ finish(status: ReplyCardFinalStatus, note?: string): Promise<void>;
72
+ append(delta: string): void;
73
+ ensureFinal(text: string): void;
74
+ /** 进入选择题等待:定格当前段,不再往这张卡写正文 */
75
+ pauseForAsk(note?: string): Promise<void>;
76
+ /** 问答结束:把暂停卡翻成「已选择」,再开一段新的回复卡 */
77
+ resume(): Promise<void>;
78
+ };
79
+
80
+ /** 转发给外部:卡片流式与过程展示的参数都在 reply-card-options.ts 里解析 */
81
+ export type { ReplyCardStreamOptions } from "./reply-card-options.ts";
82
+
83
+ type ReplyCardTransport = {
84
+ replyCard(messageId: string, card: object): Promise<string | undefined>;
85
+ updateCard(messageId: string, card: object): Promise<void>;
86
+ /** 平铺发送一张卡片(非话题群默认路径) */
87
+ createCard?(chatId: string, card: object): Promise<string | undefined>;
88
+ replyPlainText?(messageId: string, text: string): Promise<string | undefined>;
89
+ updateText?(messageId: string, text: string): Promise<void>;
90
+ /** 记录本 bot 出站消息,供 groupAlsoOnReply */
91
+ rememberOutboundMessageId?(messageId: string): void;
92
+ /** 把本地图片发到回复链上(正文写了 `![](/绝对路径.png)` 时调用) */
93
+ replyLocalImage?(
94
+ messageId: string,
95
+ filePath: string,
96
+ replyInThread?: boolean,
97
+ ): Promise<string | undefined>;
98
+ /** 平铺发本地图片(话题群/无回复锚点时用) */
99
+ sendLocalImage?(chatId: string, filePath: string): Promise<string | undefined>;
100
+ };
101
+
102
+ export class ReplyCard implements ReplyCardSink {
103
+ readonly runId = randomUUID();
104
+ private status: ReplyCardStatus = "running";
105
+ private body = "";
106
+ private note: string | undefined;
107
+ /** 续段的标题覆盖(「回复(接上条)」) */
108
+ private title: string | undefined;
109
+ /**
110
+ * 分段记账(feishu_ask 等待会把一轮切成多段,每段一张卡):
111
+ * segmentStart 是本段在整轮文本里的起点,segmentDeltaChars 是本段已累计的 delta 字符数。
112
+ * 轮末拿到整轮全量文本时靠这两个值切出本段正文,否则新段会把上一段重印一遍。
113
+ */
114
+ private segmentStart = 0;
115
+ private segmentDeltaChars = 0;
116
+ private readonly segments: { messageId?: string; text: string }[] = [];
117
+ /** 当前段的卡片消息 ID(超时/收尾刷新用) */
118
+ private segmentMessageId: string | undefined;
119
+ get bodyText() { return this.body; }
120
+ /** 停在「等用户选择」的中间态;askUser 出临界区前必须消掉 */
121
+ get paused() { return this.status === "paused"; }
122
+ private cardkit: CardKitStream | undefined;
123
+ /** 工具执行过程清单;off 档也建一个但不能渲染,省得到处判空 */
124
+ private readonly tracker: ProgressTracker;
125
+ /** 收尾后冻结:轮末还会来事件,不能再改清单,否则定格的执行记录会变 */
126
+ private trackerFrozen = false;
127
+ private readonly streamOpts: ReturnType<typeof resolveStreamOptions>;
128
+ private readonly key: string;
129
+ private readonly target: ReplyCardTarget;
130
+ private readonly transport: ReplyCardTransport;
131
+
132
+ constructor(
133
+ key: string,
134
+ target: string | ReplyCardTarget,
135
+ transport: ReplyCardTransport,
136
+ streamOptions?: ReplyCardStreamOptions,
137
+ ) {
138
+ this.key = key;
139
+ // 兼容旧的「传消息 ID」写法:等价于 reply 到那条消息
140
+ this.target = typeof target === "string" ? { replyToMessageId: target } : target;
141
+ this.transport = transport;
142
+ this.streamOpts = resolveStreamOptions(streamOptions);
143
+ this.tracker = new ProgressTracker({
144
+ mode: this.streamOpts.progressMode,
145
+ maxLines: this.streamOpts.progressMaxLines,
146
+ timeoutSeconds: this.streamOpts.progressTimeoutSeconds,
147
+ });
148
+ }
149
+
150
+ /** 当前过程清单文本(停止回调里要把同样的内容放回响应卡,否则清单会闪没) */
151
+ get progressText(): string {
152
+ return this.tracker.render() ?? "";
153
+ }
154
+
155
+ get messageId() {
156
+ return this.segmentMessageId;
157
+ }
158
+
159
+ async start() {
160
+ const cfg = loadConfig();
161
+ if (this.streamOpts.enabled && cfg?.appId && cfg?.appSecret) {
162
+ this.cardkit = new CardKitStream(
163
+ cfg.appId,
164
+ cfg.appSecret,
165
+ cfg.domain === "lark" ? "lark" : "feishu",
166
+ this.target,
167
+ async (text) => {
168
+ // CardKit 失败:回落为普通最终卡片
169
+ const id = await this.sendCard(
170
+ buildReplyCard({
171
+ key: this.key,
172
+ runId: this.runId,
173
+ status: "done",
174
+ body: text,
175
+ title: this.title,
176
+ }),
177
+ );
178
+ this.segmentMessageId = id;
179
+ },
180
+ {
181
+ printFrequencyMs: this.streamOpts.printFrequencyMs,
182
+ printStep: this.streamOpts.printStep,
183
+ pushIntervalMs: this.streamOpts.pushIntervalMs,
184
+ conversationKey: this.key,
185
+ runId: this.runId,
186
+ title: this.title,
187
+ note: this.note,
188
+ progressEnabled: progressNeedsElement(this.streamOpts.progressMode),
189
+ // steps 档清单可能几十行,收进折叠面板;action / timeout 档只有一行,展开更直接
190
+ progressCollapsed: this.streamOpts.progressMode === "steps",
191
+ onOutboundMessageId: (id) => {
192
+ this.segmentMessageId = id;
193
+ this.transport.rememberOutboundMessageId?.(id);
194
+ },
195
+ },
196
+ );
197
+ // 清单由 tick 驱动刷新:Pi 在单个工具运行期间不发任何事件,
198
+ // 只有让 CardKitStream 每次 tick 主动取数,timeout 档的「已执行 Ns」才会长。
199
+ // title 是折叠面板收起后唯一能看到的一行,必须跟 body 一起取。
200
+ this.cardkit.setProgressSource(() => ({
201
+ title: this.tracker.renderTitle(),
202
+ body: this.tracker.render() ?? "",
203
+ }));
204
+ debugLog("feishu.reply_card.cardkit_ready", {
205
+ key: this.key,
206
+ runId: this.runId,
207
+ ...this.streamOpts,
208
+ });
209
+ // 先让飞书看到「回复中」,不等待 Pi 产出第一段正文;失败仍会在结束时回落为普通回复卡。
210
+ void this.cardkit.startImmediately();
211
+ // 登记在册:进程被 kill(重启)时由退出收尾统一翻成「已停止」,
212
+ // 否则这张卡会永久停在「正在回复…」
213
+ registerLiveCard(this);
214
+ return;
215
+ }
216
+
217
+ // 非流式:先出「回复中」占位卡
218
+ this.segmentMessageId = await this.sendCard(
219
+ buildReplyCard({
220
+ key: this.key,
221
+ runId: this.runId,
222
+ status: "running",
223
+ note: this.note,
224
+ title: this.title,
225
+ body: "",
226
+ }),
227
+ );
228
+ debugLog("feishu.reply_card.started_static", {
229
+ key: this.key,
230
+ runId: this.runId,
231
+ cardMessageId: this.segmentMessageId,
232
+ });
233
+ registerLiveCard(this);
234
+ }
235
+
236
+ /** 按 target 决定平铺(create)还是回复(reply) */
237
+ private async sendCard(card: object): Promise<string | undefined> {
238
+ const target = this.target;
239
+ if ("chatId" in target && target.chatId && this.transport.createCard) {
240
+ return this.transport.createCard(target.chatId, card);
241
+ }
242
+ if ("replyToMessageId" in target && target.replyToMessageId) {
243
+ return this.transport.replyCard(target.replyToMessageId, card);
244
+ }
245
+ if ("chatId" in target && target.chatId) {
246
+ // 传输层不支持平铺(旧实现):退回复路径,宁可多一条回复也不能把卡丢了
247
+ const fallbackId = (target as { replyToMessageId?: string }).replyToMessageId;
248
+ if (fallbackId) return this.transport.replyCard(fallbackId, card);
249
+ }
250
+ throw new Error("卡片发送目标缺失:既没有 chatId 也没有 replyToMessageId");
251
+ }
252
+
253
+ /**
254
+ * 处理 Pi 会话事件,维护工具执行清单(本改造的核心)。
255
+ *
256
+ * 只更新内存里的清单状态,不发网络请求:
257
+ * 卡片推送交给 CardKitStream 的 tick 定时器节流,避免工具密集切换时打爆卡片接口。
258
+ */
259
+ updateFromEvent(event: unknown) {
260
+ if (this.trackerFrozen || this.tracker.mode === "off") return;
261
+ if (!event || typeof event !== "object") return;
262
+ const e = event as {
263
+ type?: string;
264
+ toolCallId?: string;
265
+ toolName?: string;
266
+ args?: unknown;
267
+ isError?: boolean;
268
+ };
269
+ if (e.type === "tool_execution_start") {
270
+ this.tracker.start(String(e.toolCallId ?? ""), String(e.toolName ?? "tool"), e.args);
271
+ debugLog("feishu.progress.tool_start", {
272
+ key: this.key,
273
+ runId: this.runId,
274
+ toolCallId: e.toolCallId,
275
+ toolName: e.toolName,
276
+ steps: this.tracker.size,
277
+ });
278
+ return;
279
+ }
280
+ if (e.type === "tool_execution_end") {
281
+ this.tracker.end(String(e.toolCallId ?? ""), e.isError !== true);
282
+ return;
283
+ }
284
+ // 其余事件(text_delta / message_end 等)与过程清单无关
285
+ }
286
+
287
+ append(delta: string) {
288
+ if (this.status !== "running" || !delta) return;
289
+ this.body += delta;
290
+ this.segmentDeltaChars += delta.length;
291
+ this.cardkit?.append(delta);
292
+ }
293
+
294
+ /**
295
+ * 轮末的全量文本。
296
+ *
297
+ * 注意:调用方给的是**最后一条 assistant 消息**的正文,不一定是整轮文本。
298
+ * - 长度与 delta 累加对得上(= 整轮)→ 按本段 offset 切开,否则续段会把上一段重印一遍
299
+ * - 对不上(只是最后一条消息)→ 沿用「谁长用谁」:宁可以 delta 累加为准,也不能丢字
300
+ */
301
+ ensureFinal(text: string) {
302
+ if (!text) return;
303
+ const deltaTotal = this.segmentStart + this.segmentDeltaChars;
304
+ if (deltaTotal === text.length || this.segmentDeltaChars === 0) {
305
+ const tail = text.slice(this.segmentStart);
306
+ if (!this.body.trim() || tail.length >= this.body.length) this.body = tail;
307
+ } else {
308
+ debugLog("feishu.reply_card.segment_offset_mismatch", {
309
+ key: this.key,
310
+ runId: this.runId,
311
+ segmentStart: this.segmentStart,
312
+ segmentDeltaChars: this.segmentDeltaChars,
313
+ finalLength: text.length,
314
+ });
315
+ if (!this.body.trim() || text.length >= this.body.length) this.body = text;
316
+ }
317
+ this.cardkit?.ensureFinal(this.body);
318
+ }
319
+
320
+ /**
321
+ * feishu_ask 等待期间调用:把当前这一段定格成「等你选择」。
322
+ * 之后 append 会被 status 守卫挡住,正文不会再写进这张卡;
323
+ * 用户答完/超时后由 resume() 开新的一段(新消息)继续输出。
324
+ */
325
+ async pauseForAsk(note = "等你选择") {
326
+ if (this.status !== "running") return;
327
+ this.status = "paused";
328
+ this.note = note;
329
+ // 定格本段:下一段的 offset 从这里开始
330
+ this.segmentStart += this.segmentDeltaChars;
331
+ this.segmentDeltaChars = 0;
332
+ this.segments.push({ messageId: this.segmentMessageId, text: this.body });
333
+ debugLog("feishu.reply_card.paused", {
334
+ key: this.key,
335
+ runId: this.runId,
336
+ segmentStart: this.segmentStart,
337
+ bodyLength: this.body.length,
338
+ });
339
+
340
+ if (this.cardkit) {
341
+ await this.cardkit.close(this.body, "paused", note);
342
+ return;
343
+ }
344
+ if (this.segmentMessageId) {
345
+ try {
346
+ await this.transport.updateCard(
347
+ this.segmentMessageId,
348
+ buildReplyCard({
349
+ key: this.key,
350
+ runId: this.runId,
351
+ status: "paused",
352
+ note,
353
+ body: stripLocalImageMarkdown(this.body),
354
+ title: this.title,
355
+ }),
356
+ );
357
+ } catch (error) {
358
+ debugLog("feishu.reply_card.pause_static_error", {
359
+ error: error instanceof Error ? error.message : String(error),
360
+ });
361
+ }
362
+ }
363
+ }
364
+
365
+ /**
366
+ * 问答结束(作答或超时)后调用:先把暂停的那张卡翻成「已选择」,
367
+ * 再开一段新的「回复中」卡继续输出。
368
+ * 新段标题写「回复(接上条)」,让用户知道它接的是哪一段。
369
+ */
370
+ async resume() {
371
+ if (this.status !== "paused") return;
372
+ await this.markAnswered();
373
+ this.body = "";
374
+ this.note = "承接上一条回复";
375
+ this.title = "回复(接上条)";
376
+ this.status = "running";
377
+ await this.start();
378
+ }
379
+
380
+ /** 把暂停卡翻成「已选择」:否则它会永远停在「等你选择」 */
381
+ private async markAnswered() {
382
+ if (this.cardkit) {
383
+ await this.cardkit.updateFinal("answered", this.note);
384
+ return;
385
+ }
386
+ if (!this.segmentMessageId) return;
387
+ try {
388
+ await this.transport.updateCard(
389
+ this.segmentMessageId,
390
+ buildReplyCard({
391
+ key: this.key,
392
+ runId: this.runId,
393
+ status: "answered",
394
+ note: this.note,
395
+ body: stripLocalImageMarkdown(this.body),
396
+ title: this.title,
397
+ }),
398
+ );
399
+ } catch (error) {
400
+ debugLog("feishu.reply_card.answered_static_error", {
401
+ error: error instanceof Error ? error.message : String(error),
402
+ });
403
+ }
404
+ }
405
+
406
+ async stopImmediately(note = "已停止") {
407
+ await this.finishFinal("stopped", note);
408
+ }
409
+
410
+ async finish(status: ReplyCardFinalStatus, note?: string) {
411
+ await this.finishFinal(status, note);
412
+ }
413
+
414
+ async completeWithAnswer(answer: string) {
415
+ this.ensureFinal(answer || "(无内容)");
416
+ await this.finishFinal("done", undefined);
417
+ }
418
+
419
+ private async finishFinal(
420
+ status: ReplyCardFinalStatus,
421
+ note: string | undefined,
422
+ ) {
423
+ // paused 也要允许收尾:否则「等你选择」的卡永远停在中间态
424
+ if (this.status !== "running" && this.status !== "paused") return;
425
+ await this.renderFinal(status, note);
426
+ // 卡片定稿之后再发图:图挂在下面,不打断流式更新
427
+ const replyToMessageId =
428
+ "replyToMessageId" in this.target ? this.target.replyToMessageId : undefined;
429
+ const chatId = "chatId" in this.target ? this.target.chatId : undefined;
430
+ const replyInThread = "replyInThread" in this.target ? this.target.replyInThread : undefined;
431
+ await flushLocalImages({
432
+ // 这里必须传原文:卡片正文那边已各自 stripLocalImageMarkdown,而 flushLocalImages
433
+ // 要靠 `![](路径)` 才能抽出本地图片。传 strip 后的文本会让它永远抽不到图
434
+ // (2026-10-28 实测:debug.pi.log 里 feishu.reply_card.local_images 事件为 0 次,
435
+ // 用户连续三次反馈「怎么没看到图」)。
436
+ body: this.body,
437
+ status,
438
+ target: { replyToMessageId, chatId, replyInThread },
439
+ transport: this.transport,
440
+ });
441
+ }
442
+
443
+ private async renderFinal(
444
+ status: ReplyCardFinalStatus,
445
+ note: string | undefined,
446
+ ) {
447
+ // 已到终态:退出收尾不该再动它(用户可能已经看到完整的最终卡)
448
+ unregisterLiveCard(this);
449
+ const wasPaused = this.status === "paused";
450
+ this.status = status;
451
+ this.note = note ?? defaultFinalNote(status);
452
+ // 中断兜底(必需):session.abort() 不保证发出 tool_execution_end,
453
+ // 不收尾的话用户按了停止,清单还显示 ⏳,看起来仍在跑。
454
+ // 冻结在 abortAll 之后:轮末残留事件不得再改这份定格的执行记录。
455
+ if (this.tracker.abortAll() > 0) {
456
+ debugLog("feishu.reply_card.progress_aborted", {
457
+ key: this.key,
458
+ runId: this.runId,
459
+ status,
460
+ steps: this.tracker.size,
461
+ });
462
+ }
463
+ this.trackerFrozen = true;
464
+
465
+ if (this.cardkit) {
466
+ const mapped = status === "failed" ? "failed" : status === "stopped" ? "stopped" : "done";
467
+ if (wasPaused) {
468
+ // 暂停时就已经收过尾(streaming 已关),这里只需再刷一次 header/正文
469
+ await this.cardkit.updateFinal(mapped, this.note);
470
+ return;
471
+ }
472
+ // 同一张 CardKit 卡上关闭流式并更新 header(回复/已停止/出错了)
473
+ await this.cardkit.close(this.body, mapped, this.note);
474
+ return;
475
+ }
476
+
477
+ // 静态卡路径
478
+ if (this.segmentMessageId) {
479
+ try {
480
+ await this.transport.updateCard(
481
+ this.segmentMessageId,
482
+ buildReplyCard({
483
+ key: this.key,
484
+ runId: this.runId,
485
+ status,
486
+ note: status === "done" ? undefined : this.note,
487
+ body: stripLocalImageMarkdown(this.body),
488
+ title: this.title,
489
+ }),
490
+ );
491
+ } catch (error) {
492
+ debugLog("feishu.reply_card.static_final_error", {
493
+ error: error instanceof Error ? error.message : String(error),
494
+ });
495
+ }
496
+ }
497
+ }
498
+ }