diff --git a/bun.lockb b/bun.lockb index 7332b94..27756fd 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/controller/groupAgent/agent.ts b/controller/groupAgent/agent.ts index a1c18f4..95e4ce2 100644 --- a/controller/groupAgent/agent.ts +++ b/controller/groupAgent/agent.ts @@ -9,7 +9,15 @@ const agent = async (ctx: Context.Data) => { larkCard, larkService, appInfo, - larkBody: { messageId, msgText, chatId, mentions, rawMsgText, openId }, + larkBody: { + messageId, + msgText, + chatId, + mentions, + rawMsgText, + openId, + mentionedRobot, + }, } = ctx const cardGender = larkCard.child("groupAgent") // 回复一个loading的卡片 @@ -36,6 +44,7 @@ const agent = async (ctx: Context.Data) => { mentions, senderOpenId: openId, excludedMessageIds: [message_id, messageId], + excludeMentions: [mentionedRobot?.id?.open_id || ""], }) // 如果没有聊天记录,返回错误信息 if (chatHistory.length === 0) { diff --git a/controller/groupAgent/chatHistory.ts b/controller/groupAgent/chatHistory.ts index 1abfa75..9c4a24a 100644 --- a/controller/groupAgent/chatHistory.ts +++ b/controller/groupAgent/chatHistory.ts @@ -50,14 +50,16 @@ const getChatHistory = async ( endTime, senderOpenId, mentions: targetUsers, - excludedMessageIds = [], // 新增参数 + excludedMessageIds = [], + excludeMentions = [], }: { chatId: string startTime: string endTime: string senderOpenId?: string mentions?: LarkEvent.Mention[] - excludedMessageIds?: string[] // 新增参数类型 + excludedMessageIds?: string[] // 不需要的消息 ID + excludeMentions?: string[] // 不需要的提到的人 } ): Promise<{ messages: Message[] @@ -108,15 +110,27 @@ const getChatHistory = async ( // 遍历历史消息 for (const chat of chatHistory) { - // 过滤掉不需要的消息 ID - if (excludedMessageIds.includes(chat.message_id)) { - continue - } + let hasExcludeMention = false + if (chat.mentions) { for (const mention of chat.mentions) { mentions.set(mention.id, mention.name) + // 过滤掉不需要的提到的人 + if (excludeMentions.includes(mention.id)) { + hasExcludeMention = true + } } } + + // 如果提到了不要包含的人,则跳过该消息 + if (hasExcludeMention) { + continue + } + + // 过滤掉不需要的消息 ID + if (excludedMessageIds.includes(chat.message_id)) { + continue + } // 过滤掉不是文本和post消息的消息 if (!allowedMsgTypes.includes(chat.msg_type)) { continue diff --git a/package.json b/package.json index b472a07..59e888d 100644 --- a/package.json +++ b/package.json @@ -29,20 +29,20 @@ "husky": "^9.1.7", "lint-staged": "^15.2.10", "oxlint": "^0.13.2", - "prettier": "^3.4.1", + "prettier": "^3.4.2", "prisma": "5.22.0", - "typescript-eslint": "^8.16.0" + "typescript-eslint": "^8.17.0" }, "peerDependencies": { "typescript": "^5.5.4" }, "dependencies": { "@egg/hooks": "^1.2.0", - "@egg/lark-msg-tool": "^1.18.0", + "@egg/lark-msg-tool": "^1.19.0", "@egg/logger": "^1.6.0", "@egg/net-tool": "^1.19.0", "@egg/path-tool": "^1.4.1", - "@langchain/core": "^0.3.19", + "@langchain/core": "^0.3.20", "@langchain/openai": "^0.3.14", "@prisma/client": "5.22.0", "joi": "^17.13.3",