Skip to content

Commit 60e8043

Browse files
VickyVicky
authored andcommitted
fix(feishu): strip leaked thinking content from streaming output (#26466)
1 parent 6fd9d2f commit 60e8043

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

extensions/feishu/src/reply-dispatcher.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ import { FeishuStreamingSession, mergeStreamingText } from "./streaming-card.js"
2323
import { resolveReceiveIdType } from "./targets.js";
2424
import { addTypingIndicator, removeTypingIndicator, type TypingIndicatorState } from "./typing.js";
2525

26+
/**
27+
* Strip leaked thinking/thought content that should never reach the user.
28+
*/
29+
function stripLeakedThinkingContent(text: string): string {
30+
let cleaned = text.replace(
31+
/<(thinking|thought|antthinking)\b[^>]*>[\s\S]*?<\/\1>/gi,
32+
"",
33+
);
34+
cleaned = cleaned.replace(/<(thinking|thought|antthinking)\b[^>]*>[\s\S]*$/gi, "");
35+
return cleaned;
36+
}
37+
2638
/** Detect if text contains markdown elements that benefit from card rendering */
2739
function shouldUseCard(text: string): boolean {
2840
return /```[\s\S]*?```/.test(text) || /\|.+\|[\r\n]+\|[-:| ]+\|/.test(text);
@@ -485,7 +497,11 @@ export function createFeishuReplyDispatcher(params: CreateFeishuReplyDispatcherP
485497
if (!payload.text) {
486498
return;
487499
}
488-
queueStreamingUpdate(payload.text, {
500+
const cleaned = stripLeakedThinkingContent(payload.text);
501+
if (!cleaned) {
502+
return;
503+
}
504+
queueStreamingUpdate(cleaned, {
489505
dedupeWithLastPartial: true,
490506
mode: "snapshot",
491507
});

0 commit comments

Comments
 (0)