From 4d1fe87cf5a57ffcc5e1f56834a4c825ef5f239b Mon Sep 17 00:00:00 2001 From: unclee Date: Thu, 12 Mar 2026 13:11:08 +0800 Subject: [PATCH] fix: skip discussion tool injection when already in a topic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a user @mentions the bot inside an existing Feishu topic (话题), the bot should reply in that topic instead of creating a new discussion thread. Previously, the discussionMcp tool was unconditionally injected into the Chat Agent, allowing it to call start_discussion_thread even when eventThreadId was already present — resulting in duplicate threads. Now, discussionMcp is only created and injected when eventThreadId is absent (i.e., the message is in the main chat, not in a topic). Co-Authored-By: Claude Opus 4.6 --- src/feishu/event-handler.ts | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/feishu/event-handler.ts b/src/feishu/event-handler.ts index 9df455b4..1221c3c1 100644 --- a/src/feishu/event-handler.ts +++ b/src/feishu/event-handler.ts @@ -1744,14 +1744,17 @@ async function executeDirectTask( } } - // discussion MCP server:允许 agent 动态创建话题 - const discussionMcp = createDiscussionMcpServer({ - chatId, userId, messageId, agentId, - onThreadCreated: (info) => { - threadReplyMsgId = info.threadReplyMsgId; - threadId = info.threadId; - }, - }); + // discussion MCP server:允许 agent 动态创建话题(仅在非话题场景下注入) + // 如果消息已经在一个话题中(eventThreadId 存在),不需要再创建新话题 + const discussionMcp = eventThreadId + ? null + : createDiscussionMcpServer({ + chatId, userId, messageId, agentId, + onThreadCreated: (info) => { + threadReplyMsgId = info.threadReplyMsgId; + threadId = info.threadId; + }, + }); const personaPrompt = readPersonaFile(agentId); @@ -1782,7 +1785,7 @@ async function executeDirectTask( // 不需要 workspace-manager 工具(Chat Agent 不切换工作区) disableWorkspaceTool: true, // 注入 discussion-tools MCP server - additionalMcpServers: { 'discussion-tools': discussionMcp }, + ...(discussionMcp ? { additionalMcpServers: { 'discussion-tools': discussionMcp } } : {}), }); // resume 被跳过时清除 _historyDedup,让下次 query 重新注入完整历史