mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-02-03 09:05:07 +08:00
Refactor: Remove the brute-force deduplication method for agent logs. (#12864)
### What problem does this PR solve? Refactor: Remove the brute-force deduplication method for agent logs. ### Type of change - [x] Refactoring
This commit is contained in:
@ -2235,7 +2235,7 @@ Important structured information may include: names, dates, locations, events, k
|
|||||||
'Accepted Response: The system returns an acknowledgment immediately after the request is validated, while the workflow continues to execute asynchronously in the background. /Final Response: The system returns a response only after the workflow execution is completed.',
|
'Accepted Response: The system returns an acknowledgment immediately after the request is validated, while the workflow continues to execute asynchronously in the background. /Final Response: The system returns a response only after the workflow execution is completed.',
|
||||||
authMethods: 'Authentication methods',
|
authMethods: 'Authentication methods',
|
||||||
authType: 'Authentication type',
|
authType: 'Authentication type',
|
||||||
limit: 'Request limit',
|
limit: 'Request frequency limit',
|
||||||
per: 'Time period',
|
per: 'Time period',
|
||||||
maxBodySize: 'Maximum body size',
|
maxBodySize: 'Maximum body size',
|
||||||
ipWhitelist: 'IP whitelist',
|
ipWhitelist: 'IP whitelist',
|
||||||
|
|||||||
@ -157,10 +157,10 @@ function AgentCanvas({ drawerVisible, hideDrawer }: IProps) {
|
|||||||
currentEventListWithoutMessageById,
|
currentEventListWithoutMessageById,
|
||||||
clearEventList,
|
clearEventList,
|
||||||
currentMessageId,
|
currentMessageId,
|
||||||
currentTaskId,
|
latestTaskId,
|
||||||
} = useCacheChatLog();
|
} = useCacheChatLog();
|
||||||
|
|
||||||
const { stopMessage } = useStopMessageUnmount(chatVisible, currentTaskId);
|
const { stopMessage } = useStopMessageUnmount(chatVisible, latestTaskId);
|
||||||
|
|
||||||
const { showLogSheet, logSheetVisible, hideLogSheet } = useShowLogSheet({
|
const { showLogSheet, logSheetVisible, hideLogSheet } = useShowLogSheet({
|
||||||
setCurrentMessageId,
|
setCurrentMessageId,
|
||||||
@ -179,10 +179,10 @@ function AgentCanvas({ drawerVisible, hideDrawer }: IProps) {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!chatVisible) {
|
if (!chatVisible) {
|
||||||
stopMessage(currentTaskId);
|
stopMessage(latestTaskId);
|
||||||
clearEventList();
|
clearEventList();
|
||||||
}
|
}
|
||||||
}, [chatVisible, clearEventList, currentTaskId, stopMessage]);
|
}, [chatVisible, clearEventList, latestTaskId, stopMessage]);
|
||||||
|
|
||||||
const setLastSendLoadingFunc = (loading: boolean, messageId: string) => {
|
const setLastSendLoadingFunc = (loading: boolean, messageId: string) => {
|
||||||
setCurrentSendLoading(!!loading);
|
setCurrentSendLoading(!!loading);
|
||||||
|
|||||||
@ -3,7 +3,8 @@ import {
|
|||||||
INodeEvent,
|
INodeEvent,
|
||||||
MessageEventType,
|
MessageEventType,
|
||||||
} from '@/hooks/use-send-message';
|
} from '@/hooks/use-send-message';
|
||||||
import { useCallback, useEffect, useMemo, useState } from 'react';
|
import { get, isEmpty } from 'lodash';
|
||||||
|
import { useCallback, useMemo, useState } from 'react';
|
||||||
|
|
||||||
export const ExcludeTypes = [
|
export const ExcludeTypes = [
|
||||||
MessageEventType.Message,
|
MessageEventType.Message,
|
||||||
@ -11,15 +12,13 @@ export const ExcludeTypes = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
export function useCacheChatLog() {
|
export function useCacheChatLog() {
|
||||||
const [eventList, setEventList] = useState<IEventList>([]);
|
|
||||||
const [messageIdPool, setMessageIdPool] = useState<
|
const [messageIdPool, setMessageIdPool] = useState<
|
||||||
Record<string, IEventList>
|
Record<string, IEventList>
|
||||||
>({});
|
>({});
|
||||||
|
|
||||||
|
const [latestTaskId, setLatestTaskId] = useState('');
|
||||||
|
|
||||||
const [currentMessageId, setCurrentMessageId] = useState('');
|
const [currentMessageId, setCurrentMessageId] = useState('');
|
||||||
useEffect(() => {
|
|
||||||
setMessageIdPool((prev) => ({ ...prev, [currentMessageId]: eventList }));
|
|
||||||
}, [currentMessageId, eventList]);
|
|
||||||
|
|
||||||
const filterEventListByMessageId = useCallback(
|
const filterEventListByMessageId = useCallback(
|
||||||
(messageId: string) => {
|
(messageId: string) => {
|
||||||
@ -40,16 +39,26 @@ export function useCacheChatLog() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const clearEventList = useCallback(() => {
|
const clearEventList = useCallback(() => {
|
||||||
setEventList([]);
|
|
||||||
setMessageIdPool({});
|
setMessageIdPool({});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const addEventList = useCallback((events: IEventList, message_id: string) => {
|
const addEventList = useCallback((events: IEventList, message_id: string) => {
|
||||||
setEventList((x) => {
|
if (!isEmpty(events)) {
|
||||||
const list = [...x, ...events];
|
const taskId = get(events, '0.task_id');
|
||||||
setMessageIdPool((prev) => ({ ...prev, [message_id]: list }));
|
setLatestTaskId(taskId);
|
||||||
return list;
|
|
||||||
});
|
setMessageIdPool((prev) => {
|
||||||
|
const list = [...(prev[message_id] ?? [])];
|
||||||
|
|
||||||
|
events.forEach((event) => {
|
||||||
|
if (!list.some((y) => y === event)) {
|
||||||
|
list.push(event);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return { ...prev, [message_id]: list };
|
||||||
|
});
|
||||||
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const currentEventListWithoutMessage = useMemo(() => {
|
const currentEventListWithoutMessage = useMemo(() => {
|
||||||
@ -73,21 +82,15 @@ export function useCacheChatLog() {
|
|||||||
[messageIdPool],
|
[messageIdPool],
|
||||||
);
|
);
|
||||||
|
|
||||||
const currentTaskId = useMemo(() => {
|
|
||||||
return eventList.at(-1)?.task_id;
|
|
||||||
}, [eventList]);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
eventList,
|
|
||||||
currentEventListWithoutMessage,
|
currentEventListWithoutMessage,
|
||||||
currentEventListWithoutMessageById,
|
currentEventListWithoutMessageById,
|
||||||
setEventList,
|
|
||||||
clearEventList,
|
clearEventList,
|
||||||
addEventList,
|
addEventList,
|
||||||
filterEventListByEventType,
|
filterEventListByEventType,
|
||||||
filterEventListByMessageId,
|
filterEventListByMessageId,
|
||||||
setCurrentMessageId,
|
setCurrentMessageId,
|
||||||
currentMessageId,
|
currentMessageId,
|
||||||
currentTaskId,
|
latestTaskId,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,7 +22,7 @@ import {
|
|||||||
import { ITraceData } from '@/interfaces/database/agent';
|
import { ITraceData } from '@/interfaces/database/agent';
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
import { t } from 'i18next';
|
import { t } from 'i18next';
|
||||||
import { get, isEmpty, isEqual, uniqWith } from 'lodash';
|
import { get, isEmpty } from 'lodash';
|
||||||
import { useCallback, useEffect, useMemo } from 'react';
|
import { useCallback, useEffect, useMemo } from 'react';
|
||||||
import { Operator } from '../constant';
|
import { Operator } from '../constant';
|
||||||
import { JsonViewer } from '../form/components/json-viewer';
|
import { JsonViewer } from '../form/components/json-viewer';
|
||||||
@ -88,7 +88,7 @@ function getInputsOrOutputs(
|
|||||||
return inputsOrOutputs[0] || {};
|
return inputsOrOutputs[0] || {};
|
||||||
}
|
}
|
||||||
|
|
||||||
return uniqWith(inputsOrOutputs, isEqual); // TODO: Violence should not be used to
|
return inputsOrOutputs;
|
||||||
}
|
}
|
||||||
export const WorkFlowTimeline = ({
|
export const WorkFlowTimeline = ({
|
||||||
currentEventListWithoutMessage,
|
currentEventListWithoutMessage,
|
||||||
|
|||||||
Reference in New Issue
Block a user