perf: human check;perf: recursion get node response (#4888)

* perf: human check

* version

* perf: recursion get node response
This commit is contained in:
Archer
2025-05-25 20:55:29 +08:00
committed by GitHub
parent a8673344b1
commit 1dea2b71b4
6 changed files with 24 additions and 43 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "app",
"version": "4.9.9",
"version": "4.9.10",
"private": false,
"scripts": {
"dev": "next dev",

View File

@@ -7,6 +7,7 @@ import { type ChatHistoryItemResType } from '@fastgpt/global/core/chat/type';
import { FlowNodeTypeEnum } from '@fastgpt/global/core/workflow/node/constant';
import { useRequest2 } from '@fastgpt/web/hooks/useRequest';
import { useTranslation } from 'next-i18next';
import { getFlatAppResponses } from '@/global/core/chat/utils';
const isLLMNode = (item: ChatHistoryItemResType) =>
item.moduleType === FlowNodeTypeEnum.chatNode || item.moduleType === FlowNodeTypeEnum.tools;
@@ -16,17 +17,7 @@ const ContextModal = ({ onClose, dataId }: { onClose: () => void; dataId: string
const { loading: isLoading, data: contextModalData } = useRequest2(
() =>
getHistoryResponseData({ dataId }).then((res) => {
const flatResData: ChatHistoryItemResType[] =
res
?.map((item) => {
return [
item,
...(item.pluginDetail || []),
...(item.toolDetail || []),
...(item.loopDetail || [])
];
})
.flat() || [];
const flatResData = getFlatAppResponses(res || []);
return flatResData.find(isLLMNode)?.historyPreview || [];
}),
{ manual: false }

View File

@@ -19,23 +19,25 @@ export function transformPreviewHistories(
});
}
export const getFlatAppResponses = (res: ChatHistoryItemResType[]): ChatHistoryItemResType[] => {
return res
.map((item) => {
return [
item,
...getFlatAppResponses(item.pluginDetail || []),
...getFlatAppResponses(item.toolDetail || []),
...getFlatAppResponses(item.loopDetail || [])
];
})
.flat();
};
export function addStatisticalDataToHistoryItem(historyItem: ChatItemType) {
if (historyItem.obj !== ChatRoleEnum.AI) return historyItem;
if (historyItem.totalQuoteList !== undefined) return historyItem;
if (!historyItem.responseData) return historyItem;
// Flat children
const flatResData: ChatHistoryItemResType[] =
historyItem.responseData
?.map((item) => {
return [
item,
...(item.pluginDetail || []),
...(item.toolDetail || []),
...(item.loopDetail || [])
];
})
.flat() || [];
const flatResData = getFlatAppResponses(historyItem.responseData || []);
return {
...historyItem,

View File

@@ -1,8 +1,4 @@
import {
type AIChatItemType,
type ChatHistoryItemResType,
type ChatSchema
} from '@fastgpt/global/core/chat/type';
import { type ChatHistoryItemResType, type ChatSchema } from '@fastgpt/global/core/chat/type';
import { MongoChat } from '@fastgpt/service/core/chat/chatSchema';
import { type AuthModeType } from '@fastgpt/service/support/permission/type';
import { authOutLink } from './outLink';
@@ -12,6 +8,7 @@ import { AuthUserTypeEnum, ReadPermissionVal } from '@fastgpt/global/support/per
import { authApp } from '@fastgpt/service/support/permission/app/auth';
import { MongoChatItem } from '@fastgpt/service/core/chat/chatItemSchema';
import { DatasetErrEnum } from '@fastgpt/global/common/error/code/dataset';
import { getFlatAppResponses } from '@/global/core/chat/utils';
/*
检查chat的权限
@@ -221,18 +218,7 @@ export const authCollectionInChat = async ({
if (!chatItem) return Promise.reject(DatasetErrEnum.unAuthDatasetCollection);
// 找 responseData 里,是否有该文档 id
const responseData = chatItem.responseData || [];
const flatResData: ChatHistoryItemResType[] =
responseData
?.map((item) => {
return [
item,
...(item.pluginDetail || []),
...(item.toolDetail || []),
...(item.loopDetail || [])
];
})
.flat() || [];
const flatResData = getFlatAppResponses(chatItem.responseData || []);
const quoteListSet = new Set(
flatResData