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:
balibabu
2026-01-28 12:04:30 +08:00
committed by GitHub
parent 591870eb6e
commit fe99905a2b
4 changed files with 28 additions and 25 deletions

View File

@ -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.',
authMethods: 'Authentication methods',
authType: 'Authentication type',
limit: 'Request limit',
limit: 'Request frequency limit',
per: 'Time period',
maxBodySize: 'Maximum body size',
ipWhitelist: 'IP whitelist',

View File

@ -157,10 +157,10 @@ function AgentCanvas({ drawerVisible, hideDrawer }: IProps) {
currentEventListWithoutMessageById,
clearEventList,
currentMessageId,
currentTaskId,
latestTaskId,
} = useCacheChatLog();
const { stopMessage } = useStopMessageUnmount(chatVisible, currentTaskId);
const { stopMessage } = useStopMessageUnmount(chatVisible, latestTaskId);
const { showLogSheet, logSheetVisible, hideLogSheet } = useShowLogSheet({
setCurrentMessageId,
@ -179,10 +179,10 @@ function AgentCanvas({ drawerVisible, hideDrawer }: IProps) {
useEffect(() => {
if (!chatVisible) {
stopMessage(currentTaskId);
stopMessage(latestTaskId);
clearEventList();
}
}, [chatVisible, clearEventList, currentTaskId, stopMessage]);
}, [chatVisible, clearEventList, latestTaskId, stopMessage]);
const setLastSendLoadingFunc = (loading: boolean, messageId: string) => {
setCurrentSendLoading(!!loading);

View File

@ -3,7 +3,8 @@ import {
INodeEvent,
MessageEventType,
} 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 = [
MessageEventType.Message,
@ -11,15 +12,13 @@ export const ExcludeTypes = [
];
export function useCacheChatLog() {
const [eventList, setEventList] = useState<IEventList>([]);
const [messageIdPool, setMessageIdPool] = useState<
Record<string, IEventList>
>({});
const [latestTaskId, setLatestTaskId] = useState('');
const [currentMessageId, setCurrentMessageId] = useState('');
useEffect(() => {
setMessageIdPool((prev) => ({ ...prev, [currentMessageId]: eventList }));
}, [currentMessageId, eventList]);
const filterEventListByMessageId = useCallback(
(messageId: string) => {
@ -40,16 +39,26 @@ export function useCacheChatLog() {
);
const clearEventList = useCallback(() => {
setEventList([]);
setMessageIdPool({});
}, []);
const addEventList = useCallback((events: IEventList, message_id: string) => {
setEventList((x) => {
const list = [...x, ...events];
setMessageIdPool((prev) => ({ ...prev, [message_id]: list }));
return list;
});
if (!isEmpty(events)) {
const taskId = get(events, '0.task_id');
setLatestTaskId(taskId);
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(() => {
@ -73,21 +82,15 @@ export function useCacheChatLog() {
[messageIdPool],
);
const currentTaskId = useMemo(() => {
return eventList.at(-1)?.task_id;
}, [eventList]);
return {
eventList,
currentEventListWithoutMessage,
currentEventListWithoutMessageById,
setEventList,
clearEventList,
addEventList,
filterEventListByEventType,
filterEventListByMessageId,
setCurrentMessageId,
currentMessageId,
currentTaskId,
latestTaskId,
};
}

View File

@ -22,7 +22,7 @@ import {
import { ITraceData } from '@/interfaces/database/agent';
import { cn } from '@/lib/utils';
import { t } from 'i18next';
import { get, isEmpty, isEqual, uniqWith } from 'lodash';
import { get, isEmpty } from 'lodash';
import { useCallback, useEffect, useMemo } from 'react';
import { Operator } from '../constant';
import { JsonViewer } from '../form/components/json-viewer';
@ -88,7 +88,7 @@ function getInputsOrOutputs(
return inputsOrOutputs[0] || {};
}
return uniqWith(inputsOrOutputs, isEqual); // TODO: Violence should not be used to
return inputsOrOutputs;
}
export const WorkFlowTimeline = ({
currentEventListWithoutMessage,