From a863e9f674cc3906710354434034cfc1eed7cad6 Mon Sep 17 00:00:00 2001 From: zxhlyh Date: Fri, 27 Dec 2024 17:21:39 +0800 Subject: [PATCH] refact workflow run log --- .../nodes/_base/hooks/use-one-step-run.ts | 53 +++++++++++----- .../workflow/nodes/iteration/panel.tsx | 61 ++++++++++++------- .../iteration-log/iteration-log-trigger.tsx | 41 ++++--------- 3 files changed, 91 insertions(+), 64 deletions(-) diff --git a/web/app/components/workflow/nodes/_base/hooks/use-one-step-run.ts b/web/app/components/workflow/nodes/_base/hooks/use-one-step-run.ts index 3f7bf1987d..d8a2b745db 100644 --- a/web/app/components/workflow/nodes/_base/hooks/use-one-step-run.ts +++ b/web/app/components/workflow/nodes/_base/hooks/use-one-step-run.ts @@ -142,7 +142,7 @@ const useOneStepRun = ({ const { handleNodeDataUpdate }: { handleNodeDataUpdate: (data: any) => void } = useNodeDataUpdate() const [canShowSingleRun, setCanShowSingleRun] = useState(false) const isShowSingleRun = data._isSingleRun && canShowSingleRun - const [iterationRunResult, setIterationRunResult] = useState([]) + const [iterationRunResult, setIterationRunResult] = useState([]) useEffect(() => { if (!checkValid) { @@ -173,7 +173,7 @@ const useOneStepRun = ({ const workflowStore = useWorkflowStore() useEffect(() => { workflowStore.getState().setShowSingleRunPanel(!!isShowSingleRun) - }, [isShowSingleRun]) + }, [isShowSingleRun, workflowStore]) const hideSingleRun = () => { handleNodeDataUpdate({ @@ -211,7 +211,7 @@ const useOneStepRun = ({ } else { setIterationRunResult([]) - let _iterationResult: NodeTracing[][] = [] + let _iterationResult: NodeTracing[] = [] let _runResult: any = null ssePost( getIterationSingleNodeRunUrl(isChatMode, appId!, id), @@ -231,27 +231,43 @@ const useOneStepRun = ({ _runResult.created_by = iterationData.created_by.name setRunResult(_runResult) }, - onIterationNext: () => { - // iteration next trigger time is triggered one more time than iterationTimes - if (_iterationResult.length >= iterationTimes!) - return - + onIterationStart: (params) => { const newIterationRunResult = produce(_iterationResult, (draft) => { - draft.push([]) + draft.push({ + ...params.data, + status: NodeRunningStatus.Running, + }) }) _iterationResult = newIterationRunResult setIterationRunResult(newIterationRunResult) }, + onIterationNext: () => { + // iteration next trigger time is triggered one more time than iterationTimes + if (_iterationResult.length >= iterationTimes!) + return _iterationResult.length >= iterationTimes! + }, onIterationFinish: (params) => { _runResult = params.data setRunResult(_runResult) + const iterationRunResult = _iterationResult + const currentIndex = iterationRunResult.findIndex(trace => trace.id === params.data.id) + const newIterationRunResult = produce(iterationRunResult, (draft) => { + if (currentIndex > -1) { + draft[currentIndex] = { + ...draft[currentIndex], + ...data, + } + } + }) + _iterationResult = newIterationRunResult + setIterationRunResult(newIterationRunResult) }, onNodeStarted: (params) => { const newIterationRunResult = produce(_iterationResult, (draft) => { - draft[draft.length - 1].push({ + draft.push({ ...params.data, status: NodeRunningStatus.Running, - } as NodeTracing) + }) }) _iterationResult = newIterationRunResult setIterationRunResult(newIterationRunResult) @@ -260,18 +276,25 @@ const useOneStepRun = ({ const iterationRunResult = _iterationResult const { data } = params - const currentIndex = iterationRunResult[iterationRunResult.length - 1].findIndex(trace => trace.node_id === data.node_id) + const currentIndex = iterationRunResult.findIndex(trace => trace.id === data.id) const newIterationRunResult = produce(iterationRunResult, (draft) => { if (currentIndex > -1) { - draft[draft.length - 1][currentIndex] = { + draft[currentIndex] = { + ...draft[currentIndex], ...data, - status: NodeRunningStatus.Succeeded, - } as NodeTracing + } } }) _iterationResult = newIterationRunResult setIterationRunResult(newIterationRunResult) }, + onNodeRetry: (params) => { + const newIterationRunResult = produce(_iterationResult, (draft) => { + draft.push(params.data) + }) + _iterationResult = newIterationRunResult + setIterationRunResult(newIterationRunResult) + }, onError: () => { handleNodeDataUpdate({ id, diff --git a/web/app/components/workflow/nodes/iteration/panel.tsx b/web/app/components/workflow/nodes/iteration/panel.tsx index 83402e9cad..89f4d59734 100644 --- a/web/app/components/workflow/nodes/iteration/panel.tsx +++ b/web/app/components/workflow/nodes/iteration/panel.tsx @@ -1,13 +1,9 @@ import type { FC } from 'react' import React from 'react' import { useTranslation } from 'react-i18next' -import { - RiArrowRightSLine, -} from '@remixicon/react' import VarReferencePicker from '../_base/components/variable/var-reference-picker' import Split from '../_base/components/split' import ResultPanel from '../../run/result-panel' -import { IterationResultPanel } from '../../run/iteration-log' import { MAX_ITERATION_PARALLEL_NUM, MIN_ITERATION_PARALLEL_NUM } from '../../constants' import type { IterationNodeType } from './types' import useConfig from './use-config' @@ -18,6 +14,12 @@ import Switch from '@/app/components/base/switch' import Select from '@/app/components/base/select' import Slider from '@/app/components/base/slider' import Input from '@/app/components/base/input' +import formatTracing from '@/app/components/workflow/run/utils/format-log' +import { + IterationLogTrigger, + IterationResultPanel, +} from '@/app/components/workflow/run/iteration-log' +import { useLogs } from '@/app/components/workflow/run/hooks' const i18nPrefix = 'workflow.nodes.iteration' @@ -50,9 +52,6 @@ const Panel: FC> = ({ handleOutputVarChange, isShowSingleRun, hideSingleRun, - isShowIterationDetail, - backToSingleRun, - showIterationDetail, runningStatus, handleRun, handleStop, @@ -69,6 +68,14 @@ const Panel: FC> = ({ changeParallelNums, } = useConfig(id, data) + const nodeInfo = formatTracing(iterationRunResult, t)[0] + const { + showIteratingDetail, + iterationResultList, + setShowIteratingDetailFalse, + handleShowIterationResultList, + } = useLogs() + return (
@@ -165,24 +172,36 @@ const Panel: FC> = ({ onStop={handleStop} result={
-
-
-
{t(`${i18nPrefix}.iteration`, { count: iterationRunResult.length })}
- -
- -
- + { + !showIteratingDetail && ( + <> + { + nodeInfo && ( +
+ + +
+ ) + } + + + ) + } + { + showIteratingDetail && ( + + ) + }
} /> )} - {isShowIterationDetail && ( - - )}
) } diff --git a/web/app/components/workflow/run/iteration-log/iteration-log-trigger.tsx b/web/app/components/workflow/run/iteration-log/iteration-log-trigger.tsx index 350c15c2b8..93c6495216 100644 --- a/web/app/components/workflow/run/iteration-log/iteration-log-trigger.tsx +++ b/web/app/components/workflow/run/iteration-log/iteration-log-trigger.tsx @@ -6,17 +6,14 @@ import type { NodeTracing, } from '@/types/workflow' import { Iteration } from '@/app/components/base/icons/src/vender/workflow' -import Split from '@/app/components/workflow/nodes/_base/components/split' type IterationLogTriggerProps = { nodeInfo: NodeTracing onShowIterationResultList: (iterationResultList: NodeTracing[][], iterationResultDurationMap: IterationDurationMap) => void - justShowIterationNavArrow?: boolean } const IterationLogTrigger = ({ nodeInfo, onShowIterationResultList, - justShowIterationNavArrow, }: IterationLogTriggerProps) => { const { t } = useTranslation() const getErrorCount = (details: NodeTracing[][] | undefined) => { @@ -41,31 +38,19 @@ const IterationLogTrigger = ({ onShowIterationResultList(nodeInfo.details || [], nodeInfo?.iterDurationMap || nodeInfo.execution_metadata?.iteration_duration_map || {}) } return ( -
- - -
+ ) }