feat(group-agent): 更新卡片 & 过滤机器人消息
This commit is contained in:
parent
9545670a51
commit
056d51f5a7
@ -28,19 +28,19 @@
|
||||
"husky": "^9.1.6",
|
||||
"lint-staged": "^15.2.10",
|
||||
"prettier": "^3.3.3",
|
||||
"typescript-eslint": "^8.8.1"
|
||||
"typescript-eslint": "^8.9.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": "^5.5.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"@dotenvx/dotenvx": "^1.19.0",
|
||||
"@dotenvx/dotenvx": "^1.19.2",
|
||||
"@egg/hooks": "^1.2.0",
|
||||
"@egg/lark-msg-tool": "^1.7.4",
|
||||
"@egg/lark-msg-tool": "^1.8.0",
|
||||
"@egg/logger": "^1.4.4",
|
||||
"@egg/net-tool": "^1.9.2",
|
||||
"@egg/path-tool": "^1.4.1",
|
||||
"@langchain/core": "^0.3.10",
|
||||
"@langchain/core": "^0.3.11",
|
||||
"@langchain/openai": "^0.3.7",
|
||||
"joi": "^17.13.3",
|
||||
"langfuse-langchain": "^3.27.0",
|
||||
|
@ -9,6 +9,11 @@ interface Message {
|
||||
time: string
|
||||
}
|
||||
|
||||
/**
|
||||
* 提取 JSON 数据中的文本内容
|
||||
* @param data - JSON 数据
|
||||
* @returns 提取的文本内容
|
||||
*/
|
||||
const extractTextFromJson = (data: any): string => {
|
||||
let result = ""
|
||||
|
||||
@ -31,6 +36,11 @@ const extractTextFromJson = (data: any): string => {
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取聊天历史记录
|
||||
* @param context - 上下文数据
|
||||
* @returns 聊天消息数组
|
||||
*/
|
||||
const getChatHistory = async ({
|
||||
larkService,
|
||||
larkBody: {
|
||||
@ -100,6 +110,11 @@ const getChatHistory = async ({
|
||||
|
||||
const messages: Message[] = []
|
||||
|
||||
/**
|
||||
* 获取文本消息内容
|
||||
* @param chat - 聊天消息数据
|
||||
* @returns 文本消息内容
|
||||
*/
|
||||
const getText = (chat: LarkServer.MessageData) => {
|
||||
let { text } = parseJsonString(chat.body.content, { text: "" }) as {
|
||||
text: string
|
||||
@ -119,13 +134,22 @@ const getChatHistory = async ({
|
||||
return text.replace(/<[^>]+>/g, "")
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 post 消息内容
|
||||
* @param chat - 聊天消息数据
|
||||
* @returns post 消息内容
|
||||
*/
|
||||
const getPost = (chat: LarkServer.MessageData) => {
|
||||
const content = parseJsonString(chat.body.content, null)
|
||||
if (!content) return ""
|
||||
return extractTextFromJson(content)
|
||||
}
|
||||
|
||||
// 构建消息数组
|
||||
for (const chat of filteredMsg) {
|
||||
// 过滤掉机器人消息
|
||||
const user = mentions.get(chat.sender.id)
|
||||
if (!user) continue
|
||||
messages.push({
|
||||
user: mentions.get(chat.sender.id)!,
|
||||
content: chat.msg_type === "text" ? getText(chat) : getPost(chat),
|
||||
|
Loading…
x
Reference in New Issue
Block a user