From 8e0d8fdb3f4c6ff4844a34e81208cfae8a316fca Mon Sep 17 00:00:00 2001 From: Joel Date: Thu, 21 Mar 2024 16:06:35 +0800 Subject: [PATCH 1/2] feat: other nodes support rename and fix knonw set var bug --- .../components/workflow/hooks/use-workflow.ts | 2 +- .../nodes/_base/components/variable/utils.ts | 78 +++++++++++++++++++ .../nodes/knowledge-retrieval/use-config.ts | 3 +- 3 files changed, 81 insertions(+), 2 deletions(-) diff --git a/web/app/components/workflow/hooks/use-workflow.ts b/web/app/components/workflow/hooks/use-workflow.ts index 0a7f71973c60a7..85bfbf9df81fff 100644 --- a/web/app/components/workflow/hooks/use-workflow.ts +++ b/web/app/components/workflow/hooks/use-workflow.ts @@ -216,7 +216,7 @@ export const useWorkflow = () => { const { getNodes, setNodes } = store.getState() const afterNodes = getAfterNodesInSameBranch(nodeId) const effectNodes = findUsedVarNodes(oldValeSelector, afterNodes) - console.log(effectNodes) + // console.log(effectNodes) if (effectNodes.length > 0) { // debugger const newNodes = getNodes().map((node) => { diff --git a/web/app/components/workflow/nodes/_base/components/variable/utils.ts b/web/app/components/workflow/nodes/_base/components/variable/utils.ts index 73bc790e895198..4e45b90d4e65d5 100644 --- a/web/app/components/workflow/nodes/_base/components/variable/utils.ts +++ b/web/app/components/workflow/nodes/_base/components/variable/utils.ts @@ -336,6 +336,84 @@ export const updateNodeVars = (oldNode: Node, oldVarSelector: ValueSelector, new break } + case BlockEnum.KnowledgeRetrieval: { + const payload = data as KnowledgeRetrievalNodeType + if (payload.query_variable_selector.join('.') === oldVarSelector.join('.')) + payload.query_variable_selector = newVarSelector + break + } + case BlockEnum.IfElse: { + const payload = data as IfElseNodeType + if (payload.conditions) { + payload.conditions = payload.conditions.map((c) => { + if (c.variable_selector.join('.') === oldVarSelector.join('.')) + c.variable_selector = newVarSelector + return c + }) + } + break + } + case BlockEnum.Code: { + const payload = data as CodeNodeType + if (payload.variables) { + payload.variables = payload.variables.map((v) => { + if (v.value_selector.join('.') === oldVarSelector.join('.')) + v.value_selector = newVarSelector + return v + }) + } + break + } + case BlockEnum.TemplateTransform: { + const payload = data as TemplateTransformNodeType + if (payload.variables) { + payload.variables = payload.variables.map((v: any) => { + if (v.value_selector.join('.') === oldVarSelector.join('.')) + v.value_selector = newVarSelector + return v + }) + } + break + } + case BlockEnum.QuestionClassifier: { + const payload = data as QuestionClassifierNodeType + if (payload.query_variable_selector.join('.') === oldVarSelector.join('.')) + payload.query_variable_selector = newVarSelector + break + } + case BlockEnum.HttpRequest: { + const payload = data as HttpNodeType + if (payload.variables) { + payload.variables = payload.variables.map((v) => { + if (v.value_selector.join('.') === oldVarSelector.join('.')) + v.value_selector = newVarSelector + return v + }) + } + break + } + case BlockEnum.Tool: { + const payload = data as ToolNodeType + if (payload.tool_parameters) { + payload.tool_parameters = payload.tool_parameters.map((v) => { + if (v.value_selector?.join('.') === oldVarSelector.join('.')) + v.value_selector = newVarSelector + return v + }) + } + break + } + case BlockEnum.VariableAssigner: { + const payload = data as VariableAssignerNodeType + if (payload.variables) { + payload.variables = payload.variables.map((v) => { + if (v.join('.') === oldVarSelector.join('.')) + v = newVarSelector + return v + }) + } + break + } } }) return newNode diff --git a/web/app/components/workflow/nodes/knowledge-retrieval/use-config.ts b/web/app/components/workflow/nodes/knowledge-retrieval/use-config.ts index efa1274bc2b89f..b9c312e9fac52c 100644 --- a/web/app/components/workflow/nodes/knowledge-retrieval/use-config.ts +++ b/web/app/components/workflow/nodes/knowledge-retrieval/use-config.ts @@ -182,6 +182,7 @@ const useConfig = (id: string, payload: KnowledgeRetrievalNodeType) => { const [selectedDatasets, setSelectedDatasets] = useState([]) useEffect(() => { (async () => { + const inputs = inputRef.current const datasetIds = inputs.dataset_ids if (datasetIds?.length > 0) { const { data: dataSetsWithDetail } = await fetchDatasets({ url: '/datasets', params: { page: 1, ids: datasetIds } }) @@ -196,7 +197,7 @@ const useConfig = (id: string, payload: KnowledgeRetrievalNodeType) => { }, []) useEffect(() => { - let query_variable_selector: ValueSelector = [] + let query_variable_selector: ValueSelector = inputs.query_variable_selector if (isChatMode && inputs.query_variable_selector.length === 0 && startNodeId) query_variable_selector = [startNodeId, 'sys.query'] From e366e12be0a83c6af1a1c086fd5f6e0d3e805df4 Mon Sep 17 00:00:00 2001 From: StyleZhang Date: Thu, 21 Mar 2024 16:12:38 +0800 Subject: [PATCH 2/2] fix: running line --- .../workflow/hooks/use-workflow-run.ts | 11 +++++++--- .../components/workflow/nodes/answer/node.tsx | 2 +- web/app/components/workflow/panel/record.tsx | 21 +++++++++++-------- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/web/app/components/workflow/hooks/use-workflow-run.ts b/web/app/components/workflow/hooks/use-workflow-run.ts index 057e20fe94b30a..0462ef3e7d677a 100644 --- a/web/app/components/workflow/hooks/use-workflow-run.ts +++ b/web/app/components/workflow/hooks/use-workflow-run.ts @@ -130,7 +130,6 @@ export const useWorkflowRun = () => { params: any, callback?: IOtherOptions, ) => { - handleLoadBackupDraft() const { onWorkflowStarted, onWorkflowFinished, @@ -154,6 +153,8 @@ export const useWorkflowRun = () => { if (appDetail?.mode === 'workflow') url = `/apps/${appDetail.id}/workflows/draft/run` + let prevNodeId = '' + ssePost( url, { @@ -203,6 +204,8 @@ export const useWorkflowRun = () => { } })) + prevNodeId = '' + if (onWorkflowFinished) onWorkflowFinished(params) }, @@ -244,7 +247,7 @@ export const useWorkflowRun = () => { }) setNodes(newNodes) const newEdges = produce(edges, (draft) => { - const edge = draft.find(edge => edge.target === data.node_id) + const edge = draft.find(edge => edge.target === data.node_id && edge.source === prevNodeId) if (edge) edge.data = { ...edge.data, _runned: true } as any @@ -279,13 +282,15 @@ export const useWorkflowRun = () => { }) setNodes(newNodes) + prevNodeId = data.node_id + if (onNodeFinished) onNodeFinished(params) }, ...restCallback, }, ) - }, [store, reactflow, workflowStore, handleLoadBackupDraft]) + }, [store, reactflow, workflowStore]) const handleStopRun = useCallback((taskId: string) => { const appId = useAppStore.getState().appDetail?.id diff --git a/web/app/components/workflow/nodes/answer/node.tsx b/web/app/components/workflow/nodes/answer/node.tsx index 348eac5eb6c3cc..4f1e3e1219b3f6 100644 --- a/web/app/components/workflow/nodes/answer/node.tsx +++ b/web/app/components/workflow/nodes/answer/node.tsx @@ -11,7 +11,7 @@ const Node: FC> = ({ const { t } = useTranslation() return ( -
+
) diff --git a/web/app/components/workflow/panel/record.tsx b/web/app/components/workflow/panel/record.tsx index efe691df5fda24..b372cccc603236 100644 --- a/web/app/components/workflow/panel/record.tsx +++ b/web/app/components/workflow/panel/record.tsx @@ -1,23 +1,26 @@ -import { memo, useCallback } from 'react' +import { + memo, + // useCallback, +} from 'react' import { useIsChatMode, - useWorkflow, + // useWorkflow, } from '../hooks' import Run from '../run' import { useStore } from '../store' import ChatRecord from './chat-record' -import type { WorkflowRunDetailResponse } from '@/models/log' +// import type { WorkflowRunDetailResponse } from '@/models/log' const Record = () => { const isChatMode = useIsChatMode() - const { renderTreeFromRecord } = useWorkflow() + // const { renderTreeFromRecord } = useWorkflow() const historyWorkflowData = useStore(s => s.historyWorkflowData) - const getResultCallback = useCallback((res: WorkflowRunDetailResponse) => { - const { graph } = res + // const getResultCallback = useCallback((res: WorkflowRunDetailResponse) => { + // const { graph } = res - renderTreeFromRecord(graph.nodes, graph.edges, graph.viewport) - }, [renderTreeFromRecord]) + // renderTreeFromRecord(graph.nodes, graph.edges, graph.viewport) + // }, [renderTreeFromRecord]) return (
{ : ( ) }