Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(feishu): preserve mention targets on first independently sent block
  • Loading branch information
xialonglee committed Jun 30, 2026
commit 428b4754be91a3ee4983f2d3c2f45f654c1a4e6a
69 changes: 69 additions & 0 deletions extensions/feishu/src/reply-dispatcher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,75 @@ describe("createFeishuReplyDispatcher streaming behavior", () => {
expect(sendStructuredCardFeishuMock).not.toHaveBeenCalled();
});

it("preserves mention targets on the first independently sent block", async () => {
resolveFeishuAccountMock.mockReturnValue({
accountId: "main",
appId: "app_id",
appSecret: "app_secret",
domain: "feishu",
config: {
renderMode: "auto",
streaming: false,
blockStreaming: true,
},
});

const { options } = createDispatcherHarness({
runtime: createRuntimeLogger(),
mentionTargets: [{ openId: "ou_target", name: "Target User", key: "@_user_1" }],
});

await options.deliver({ text: "first block" }, { kind: "block" });
await options.deliver({ text: "second block" }, { kind: "block" });
await options.onIdle?.();

expect(streamingInstances).toHaveLength(0);
expect(sendMessageFeishuMock).toHaveBeenCalledTimes(2);
// First block carries mentions
expectMockArgFields(sendMessageFeishuMock, "first block with mentions", {
text: "first block",
mentions: [{ openId: "ou_target", name: "Target User", key: "@_user_1" }],
});
// Second block does NOT carry mentions
expectMockArgFields(
sendMessageFeishuMock,
"second block without mentions",
{
text: "second block",
},
1,
);
const secondCallArg = sendMessageFeishuMock.mock.calls[1][0];
expect(secondCallArg).not.toHaveProperty("mentions");
expect(sendStructuredCardFeishuMock).not.toHaveBeenCalled();
});

it("does not attach mentions to block when mentionTargets is empty", async () => {
resolveFeishuAccountMock.mockReturnValue({
accountId: "main",
appId: "app_id",
appSecret: "app_secret",
domain: "feishu",
config: {
renderMode: "auto",
streaming: false,
blockStreaming: true,
},
});

const { options } = createDispatcherHarness({
runtime: createRuntimeLogger(),
mentionTargets: [],
});

await options.deliver({ text: "block text" }, { kind: "block" });
await options.onIdle?.();

expect(sendMessageFeishuMock).toHaveBeenCalledTimes(1);
const callArg = sendMessageFeishuMock.mock.calls[0][0];
expect(callArg).not.toHaveProperty("mentions");
});

it("does not prepend automatic mentions to streaming card closes", async () => {
const overrides = {
runtime: createRuntimeLogger(),
Expand Down
4 changes: 4 additions & 0 deletions extensions/feishu/src/reply-dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,9 @@ export function createFeishuReplyDispatcher(params: CreateFeishuReplyDispatcherP
if (coreBlockStreamingEnabled) {
// Send block text as an independent Feishu message for
// true progressive delivery without card-side playback.
// Preserve mention targets on the first block so @mentioned
// users receive a notification.
const isFirstBlock = sentBlockText === "";
await sendMessageFeishu({
cfg,
to: chatId,
Expand All @@ -702,6 +705,7 @@ export function createFeishuReplyDispatcher(params: CreateFeishuReplyDispatcherP
replyInThread: effectiveReplyInThread,
allowTopLevelReplyFallback,
accountId,
...(isFirstBlock && mentionTargets?.length ? { mentions: mentionTargets } : {}),
});
sentBlockText += text;
markVisibleReplySent();
Expand Down
Loading