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",
"chat.quote.No Data": "The file cannot be found",
"chat.quote.deleted": "This data has been deleted ~",
"chat.waiting_for_response": "Please wait for the conversation to complete",
"chat_history": "Conversation History",
"chat_input_guide_lexicon_is_empty": "Lexicon not configured yet",
"chat_test_app": "Debug-{{name}}",

View File

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

View File

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

View File

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

View File

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