fix chat log list api (#4700)

This commit is contained in:
heheer
2025-04-28 17:51:57 +08:00
committed by GitHub
parent 433e7ed911
commit 3a911c5130
5 changed files with 114 additions and 47 deletions

View File

@@ -6,6 +6,7 @@
"back_to_text": "Text input", "back_to_text": "Text input",
"chat.quote.No Data": "The file cannot be found", "chat.quote.No Data": "The file cannot be found",
"chat.quote.deleted": "This data has been deleted ~", "chat.quote.deleted": "This data has been deleted ~",
"chat.waiting_for_response": "Please wait for the conversation to complete",
"chat_history": "Conversation History", "chat_history": "Conversation History",
"chat_input_guide_lexicon_is_empty": "Lexicon not configured yet", "chat_input_guide_lexicon_is_empty": "Lexicon not configured yet",
"chat_test_app": "Debug-{{name}}", "chat_test_app": "Debug-{{name}}",

View File

@@ -6,6 +6,7 @@
"back_to_text": "返回输入", "back_to_text": "返回输入",
"chat.quote.No Data": "找不到该文件", "chat.quote.No Data": "找不到该文件",
"chat.quote.deleted": "该数据已被删除~", "chat.quote.deleted": "该数据已被删除~",
"chat.waiting_for_response": "请等待对话完成",
"chat_history": "聊天记录", "chat_history": "聊天记录",
"chat_input_guide_lexicon_is_empty": "还没有配置词库", "chat_input_guide_lexicon_is_empty": "还没有配置词库",
"chat_test_app": "调试-{{name}}", "chat_test_app": "调试-{{name}}",

View File

@@ -6,6 +6,7 @@
"back_to_text": "返回輸入", "back_to_text": "返回輸入",
"chat.quote.No Data": "找不到該文件", "chat.quote.No Data": "找不到該文件",
"chat.quote.deleted": "該資料已被刪除~", "chat.quote.deleted": "該資料已被刪除~",
"chat.waiting_for_response": "請等待對話完成",
"chat_history": "對話紀錄", "chat_history": "對話紀錄",
"chat_input_guide_lexicon_is_empty": "尚未設定詞彙庫", "chat_input_guide_lexicon_is_empty": "尚未設定詞彙庫",
"chat_test_app": "除錯-{{name}}", "chat_test_app": "除錯-{{name}}",

View File

@@ -28,6 +28,7 @@ import dayjs from 'dayjs';
import { ChatItemContext } from '@/web/core/chat/context/chatItemContext'; import { ChatItemContext } from '@/web/core/chat/context/chatItemContext';
import { eventBus, EventNameEnum } from '@/web/common/utils/eventbus'; import { eventBus, EventNameEnum } from '@/web/common/utils/eventbus';
import { addStatisticalDataToHistoryItem } from '@/global/core/chat/utils'; import { addStatisticalDataToHistoryItem } from '@/global/core/chat/utils';
import { useToast } from '@fastgpt/web/hooks/useToast';
const colorMap = { const colorMap = {
[ChatStatusEnum.loading]: { [ChatStatusEnum.loading]: {
@@ -117,6 +118,7 @@ const ChatItem = (props: Props) => {
const { type, avatar, statusBoxData, children, isLastChild, questionGuides = [], chat } = props; const { type, avatar, statusBoxData, children, isLastChild, questionGuides = [], chat } = props;
const { isPc } = useSystem(); const { isPc } = useSystem();
const { toast } = useToast();
const styleMap: BoxProps = { const styleMap: BoxProps = {
...(type === ChatRoleEnum.Human ...(type === ChatRoleEnum.Human
@@ -237,6 +239,11 @@ const ChatItem = (props: Props) => {
quoteId?: string; quoteId?: string;
}) => { }) => {
if (!setQuoteData) return; if (!setQuoteData) return;
if (isChatting)
return toast({
title: t('chat:chat.waiting_for_response'),
status: 'info'
});
const collectionIdList = collectionId const collectionIdList = collectionId
? [collectionId] ? [collectionId]
@@ -269,7 +276,18 @@ const ChatItem = (props: Props) => {
} }
}); });
}, },
[setQuoteData, quoteList, isShowReadRawSource, appId, chatId, chat.dataId, outLinkAuthData] [
setQuoteData,
isChatting,
toast,
t,
quoteList,
isShowReadRawSource,
appId,
chatId,
chat.dataId,
outLinkAuthData
]
); );
useEffect(() => { useEffect(() => {

View File

@@ -57,9 +57,6 @@ async function handler(
{ $match: where }, { $match: where },
{ {
$sort: { $sort: {
userBadFeedbackCount: -1,
userGoodFeedbackCount: -1,
customFeedbacksCount: -1,
updateTime: -1 updateTime: -1
} }
}, },
@@ -68,68 +65,117 @@ async function handler(
{ {
$lookup: { $lookup: {
from: ChatItemCollectionName, from: ChatItemCollectionName,
let: { chatId: '$chatId' }, let: { chatId: '$chatId', appId: new Types.ObjectId(appId) },
pipeline: [
{
$match: {
$expr: {
$and: [{ $eq: ['$appId', '$$appId'] }, { $eq: ['$chatId', '$$chatId'] }]
}
}
},
{ $count: 'messageCount' }
],
as: 'messageCountData'
}
},
{
$lookup: {
from: ChatItemCollectionName,
let: { chatId: '$chatId', appId: new Types.ObjectId(appId) },
pipeline: [ pipeline: [
{ {
$match: { $match: {
$expr: { $expr: {
$and: [ $and: [
{ $eq: ['$appId', new Types.ObjectId(appId)] }, { $eq: ['$appId', '$$appId'] },
{ $eq: ['$chatId', '$$chatId'] } { $eq: ['$chatId', '$$chatId'] },
{ $eq: ['$userGoodFeedback', true] }
] ]
} }
} }
}, },
{ { $count: 'count' }
$project: {
userGoodFeedback: 1,
userBadFeedback: 1,
customFeedbacks: 1,
adminFeedback: 1
}
}
], ],
as: 'chatitems' as: 'userGoodFeedbackData'
}
},
{
$lookup: {
from: ChatItemCollectionName,
let: { chatId: '$chatId', appId: new Types.ObjectId(appId) },
pipeline: [
{
$match: {
$expr: {
$and: [
{ $eq: ['$appId', '$$appId'] },
{ $eq: ['$chatId', '$$chatId'] },
{ $eq: ['$userBadFeedback', true] }
]
}
}
},
{ $count: 'count' }
],
as: 'userBadFeedbackData'
}
},
{
$lookup: {
from: ChatItemCollectionName,
let: { chatId: '$chatId', appId: new Types.ObjectId(appId) },
pipeline: [
{
$match: {
$expr: {
$and: [
{ $eq: ['$appId', '$$appId'] },
{ $eq: ['$chatId', '$$chatId'] },
{ $gt: [{ $size: { $ifNull: ['$customFeedbacks', []] } }, 0] }
]
}
}
},
{ $count: 'count' }
],
as: 'customFeedbacksData'
}
},
{
$lookup: {
from: ChatItemCollectionName,
let: { chatId: '$chatId', appId: new Types.ObjectId(appId) },
pipeline: [
{
$match: {
$expr: {
$and: [
{ $eq: ['$appId', '$$appId'] },
{ $eq: ['$chatId', '$$chatId'] },
{ $eq: ['$adminFeedback', true] }
]
}
}
},
{ $count: 'count' }
],
as: 'markData'
} }
}, },
{ {
$addFields: { $addFields: {
userGoodFeedbackCount: { userGoodFeedbackCount: {
$size: { $ifNull: [{ $arrayElemAt: ['$userGoodFeedbackData.count', 0] }, 0]
$filter: {
input: '$chatitems',
as: 'item',
cond: { $ifNull: ['$$item.userGoodFeedback', false] }
}
}
}, },
userBadFeedbackCount: { userBadFeedbackCount: {
$size: { $ifNull: [{ $arrayElemAt: ['$userBadFeedbackData.count', 0] }, 0]
$filter: {
input: '$chatitems',
as: 'item',
cond: { $ifNull: ['$$item.userBadFeedback', false] }
}
}
}, },
customFeedbacksCount: { customFeedbacksCount: {
$size: { $ifNull: [{ $arrayElemAt: ['$customFeedbacksData.count', 0] }, 0]
$filter: {
input: '$chatitems',
as: 'item',
cond: { $gt: [{ $size: { $ifNull: ['$$item.customFeedbacks', []] } }, 0] }
}
}
}, },
markCount: { markCount: { $ifNull: [{ $arrayElemAt: ['$markData.count', 0] }, 0] },
$size: { messageCount: { $ifNull: [{ $arrayElemAt: ['$messageCountData.messageCount', 0] }, 0] }
$filter: {
input: '$chatitems',
as: 'item',
cond: { $ifNull: ['$$item.adminFeedback', false] }
}
}
}
} }
}, },
{ {
@@ -141,7 +187,7 @@ async function handler(
source: 1, source: 1,
sourceName: 1, sourceName: 1,
time: '$updateTime', time: '$updateTime',
messageCount: { $size: '$chatitems' }, messageCount: 1,
userGoodFeedbackCount: 1, userGoodFeedbackCount: 1,
userBadFeedbackCount: 1, userBadFeedbackCount: 1,
customFeedbacksCount: 1, customFeedbacksCount: 1,