diff --git a/bun.lockb b/bun.lockb index 4dc163a..7332b94 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/controller/groupAgent/agent.ts b/controller/groupAgent/agent.ts index 9240c06..86b424d 100644 --- a/controller/groupAgent/agent.ts +++ b/controller/groupAgent/agent.ts @@ -9,7 +9,7 @@ const agent = async (ctx: Context.Data) => { larkCard, larkService, appInfo, - larkBody: { messageId, msgText, chatId, mentions, rawMsgText }, + larkBody: { messageId, msgText, chatId, mentions, rawMsgText, openId }, } = ctx const cardGender = larkCard.child("groupAgent") // 回复一个loading的卡片 @@ -28,12 +28,14 @@ const agent = async (ctx: Context.Data) => { // 更新卡片 updateCard(cardGender.genPendingCard("正在爬楼中,请稍等...")) // 获取聊天记录 - const chatHistory = await getChatHistory(ctx, { - chatId, - startTime, - endTime, - mentions, - }) + const { messages: chatHistory, mentions: historyMentions } = + await getChatHistory(ctx, { + chatId, + startTime, + endTime, + mentions, + senderOpenId: openId, + }) // 如果没有聊天记录,返回错误信息 if (chatHistory.length === 0) { logger.info("No chat history found") @@ -51,6 +53,10 @@ const agent = async (ctx: Context.Data) => { } } + // 获取发送者的名字 + const userName = historyMentions.get(openId || "") ?? "用户" + userInput = `${userName}:${userInput}` + // 调用大模型 try { await updateCard(cardGender.genPendingCard("LLM激情输出中,请稍等...")) diff --git a/controller/groupAgent/chatHistory.ts b/controller/groupAgent/chatHistory.ts index 61e2088..8201821 100644 --- a/controller/groupAgent/chatHistory.ts +++ b/controller/groupAgent/chatHistory.ts @@ -48,14 +48,19 @@ const getChatHistory = async ( chatId, startTime, endTime, + senderOpenId, mentions: targetUsers, }: { chatId: string startTime: string endTime: string + senderOpenId?: string mentions?: LarkEvent.Mention[] } -): Promise => { +): Promise<{ + messages: Message[] + mentions: Map +}> => { // 获取服务器的时区偏移量(以分钟为单位) const serverTimezoneOffset = new Date().getTimezoneOffset() // 上海时区的偏移量(UTC+8,以分钟为单位) @@ -76,7 +81,12 @@ const getChatHistory = async ( String(startTimeTimestamp), String(endTimeTimestamp) ) - if (chatHistory.length === 0) return [] + + if (chatHistory.length === 0) + return { + messages: [], + mentions: new Map(), + } const targetUsersSet = new Set( targetUsers @@ -88,6 +98,8 @@ const getChatHistory = async ( // 取出所有的被AT的人,以及发送者 const mentions: Map = new Map() const senders: Set = new Set() + // 先把提问者加进去 + if (senderOpenId) senders.add(senderOpenId) // 过滤出文本和post消息 const allowedMsgTypes = ["text", "post"] const filteredMsg: typeof chatHistory = [] @@ -194,7 +206,10 @@ const getChatHistory = async ( }) } - return messages + return { + messages, + mentions, + } } export default getChatHistory diff --git a/controller/groupAgent/report.ts b/controller/groupAgent/report.ts index 8838179..1ef2a94 100644 --- a/controller/groupAgent/report.ts +++ b/controller/groupAgent/report.ts @@ -49,7 +49,7 @@ const genReport = async ( const processStart = Date.now() // 获取聊天记录 - const chatHistory = await getChatHistory( + const { messages: chatHistory } = await getChatHistory( { larkService, logger } as Context.Data, { chatId, diff --git a/package.json b/package.json index 81a663e..b472a07 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ }, "dependencies": { "@egg/hooks": "^1.2.0", - "@egg/lark-msg-tool": "^1.17.0", + "@egg/lark-msg-tool": "^1.18.0", "@egg/logger": "^1.6.0", "@egg/net-tool": "^1.19.0", "@egg/path-tool": "^1.4.1",