From 2a2964cd0b6c0832c257ae3a7cd5f59aaaa890d7 Mon Sep 17 00:00:00 2001 From: zxhlyh Date: Wed, 2 Jul 2025 15:02:57 +0800 Subject: [PATCH] fix --- .../hooks/use-fetch-workflow-inspect-vars.ts | 13 +++-- .../hooks/use-inspect-vars-crud.ts | 49 ++++++++++--------- 2 files changed, 35 insertions(+), 27 deletions(-) diff --git a/web/app/components/workflow-app/hooks/use-fetch-workflow-inspect-vars.ts b/web/app/components/workflow-app/hooks/use-fetch-workflow-inspect-vars.ts index 304c663819..07580c097e 100644 --- a/web/app/components/workflow-app/hooks/use-fetch-workflow-inspect-vars.ts +++ b/web/app/components/workflow-app/hooks/use-fetch-workflow-inspect-vars.ts @@ -6,16 +6,18 @@ import type { Node } from '@/app/components/workflow/types' import { fetchAllInspectVars } from '@/service/workflow' import { useInvalidateConversationVarValues, useInvalidateSysVarValues } from '@/service/use-workflow' import { useNodesInteractionsWithoutSync } from '@/app/components/workflow/hooks/use-nodes-interactions-without-sync' +import { useConfigsMap } from './use-configs-map' export const useSetWorkflowVarsWithValue = () => { const workflowStore = useWorkflowStore() - const { setNodesWithInspectVars, appId } = workflowStore.getState() const store = useStoreApi() - const invalidateConversationVarValues = useInvalidateConversationVarValues(appId) - const invalidateSysVarValues = useInvalidateSysVarValues(appId) + const { conversationVarsUrl, systemVarsUrl } = useConfigsMap() + const invalidateConversationVarValues = useInvalidateConversationVarValues(conversationVarsUrl) + const invalidateSysVarValues = useInvalidateSysVarValues(systemVarsUrl) const { handleCancelAllNodeSuccessStatus } = useNodesInteractionsWithoutSync() const setInspectVarsToStore = useCallback((inspectVars: VarInInspect[]) => { + const { setNodesWithInspectVars } = workflowStore.getState() const { getNodes } = store.getState() const nodeArr = getNodes() const nodesKeyValue: Record = {} @@ -53,15 +55,16 @@ export const useSetWorkflowVarsWithValue = () => { return nodeWithVar }) setNodesWithInspectVars(res) - }, [setNodesWithInspectVars, store]) + }, [workflowStore, store]) const fetchInspectVars = useCallback(async () => { + const { appId } = workflowStore.getState() invalidateConversationVarValues() invalidateSysVarValues() const data = await fetchAllInspectVars(appId) setInspectVarsToStore(data) handleCancelAllNodeSuccessStatus() // to make sure clear node output show the unset status - }, [appId, invalidateConversationVarValues, invalidateSysVarValues, setInspectVarsToStore, handleCancelAllNodeSuccessStatus]) + }, [workflowStore, invalidateConversationVarValues, invalidateSysVarValues, setInspectVarsToStore, handleCancelAllNodeSuccessStatus]) return { fetchInspectVars, } diff --git a/web/app/components/workflow-app/hooks/use-inspect-vars-crud.ts b/web/app/components/workflow-app/hooks/use-inspect-vars-crud.ts index 3a19633399..938b907368 100644 --- a/web/app/components/workflow-app/hooks/use-inspect-vars-crud.ts +++ b/web/app/components/workflow-app/hooks/use-inspect-vars-crud.ts @@ -24,14 +24,6 @@ import { useConfigsMap } from './use-configs-map' export const useInspectVarsCrud = () => { const workflowStore = useWorkflowStore() const appId = useStore(s => s.appId) - const setNodeInspectVars = useStore(s => s.setNodeInspectVars) - const setInspectVarValue = useStore(s => s.setInspectVarValue) - const renameInspectVarNameInStore = useStore(s => s.renameInspectVarName) - const deleteAllInspectVarsInStore = useStore(s => s.deleteAllInspectVars) - const deleteNodeInspectVarsInStore = useStore(s => s.deleteNodeInspectVars) - const deleteInspectVarInStore = useStore(s => s.deleteInspectVar) - const setNodesWithInspectVars = useStore(s => s.setNodesWithInspectVars) - const resetToLastRunVarInStore = useStore(s => s.resetToLastRunVar) const { conversationVarsUrl, systemVarsUrl } = useConfigsMap() const invalidateConversationVarValues = useInvalidateConversationVarValues(conversationVarsUrl) const { mutateAsync: doResetConversationVar } = useResetConversationVar(appId) @@ -90,6 +82,10 @@ export const useInspectVarsCrud = () => { }, [getNodeInspectVars]) const fetchInspectVarValue = useCallback(async (selector: ValueSelector) => { + const { + appId, + setNodeInspectVars, + } = workflowStore.getState() const nodeId = selector[0] const isSystemVar = nodeId === 'sys' const isConversationVar = nodeId === 'conversation' @@ -103,11 +99,14 @@ export const useInspectVarsCrud = () => { } const vars = await fetchNodeInspectVars(appId, nodeId) setNodeInspectVars(nodeId, vars) - }, [appId, invalidateSysVarValues, invalidateConversationVarValues, setNodeInspectVars]) + }, [workflowStore, invalidateSysVarValues, invalidateConversationVarValues]) // after last run would call this const appendNodeInspectVars = useCallback((nodeId: string, payload: VarInInspect[], allNodes: Node[]) => { - const { nodesWithInspectVars } = workflowStore.getState() + const { + nodesWithInspectVars, + setNodesWithInspectVars, + } = workflowStore.getState() const nodes = produce(nodesWithInspectVars, (draft) => { const nodeInfo = allNodes.find(node => node.id === nodeId) if (nodeInfo) { @@ -128,7 +127,7 @@ export const useInspectVarsCrud = () => { }) setNodesWithInspectVars(nodes) handleCancelNodeSuccessStatus(nodeId) - }, [workflowStore, setNodesWithInspectVars, handleCancelNodeSuccessStatus]) + }, [workflowStore, handleCancelNodeSuccessStatus]) const hasNodeInspectVar = useCallback((nodeId: string, varId: string) => { const { nodesWithInspectVars } = workflowStore.getState() @@ -139,11 +138,12 @@ export const useInspectVarsCrud = () => { }, [workflowStore]) const deleteInspectVar = useCallback(async (nodeId: string, varId: string) => { + const { deleteInspectVar } = workflowStore.getState() if(hasNodeInspectVar(nodeId, varId)) { await doDeleteInspectVar(varId) - deleteInspectVarInStore(nodeId, varId) + deleteInspectVar(nodeId, varId) } - }, [doDeleteInspectVar, deleteInspectVarInStore, hasNodeInspectVar]) + }, [doDeleteInspectVar, workflowStore, hasNodeInspectVar]) const resetConversationVar = useCallback(async (varId: string) => { await doResetConversationVar(varId) @@ -151,21 +151,24 @@ export const useInspectVarsCrud = () => { }, [doResetConversationVar, invalidateConversationVarValues]) const deleteNodeInspectorVars = useCallback(async (nodeId: string) => { + const { deleteNodeInspectVars } = workflowStore.getState() if (hasNodeInspectVars(nodeId)) { await doDeleteNodeInspectorVars(nodeId) - deleteNodeInspectVarsInStore(nodeId) + deleteNodeInspectVars(nodeId) } - }, [doDeleteNodeInspectorVars, deleteNodeInspectVarsInStore, hasNodeInspectVars]) + }, [doDeleteNodeInspectorVars, workflowStore, hasNodeInspectVars]) const deleteAllInspectorVars = useCallback(async () => { + const { deleteAllInspectVars } = workflowStore.getState() await doDeleteAllInspectorVars() await invalidateConversationVarValues() await invalidateSysVarValues() - deleteAllInspectVarsInStore() + deleteAllInspectVars() handleEdgeCancelRunningStatus() - }, [doDeleteAllInspectorVars, invalidateConversationVarValues, invalidateSysVarValues, deleteAllInspectVarsInStore, handleEdgeCancelRunningStatus]) + }, [doDeleteAllInspectorVars, invalidateConversationVarValues, invalidateSysVarValues, workflowStore, handleEdgeCancelRunningStatus]) const editInspectVarValue = useCallback(async (nodeId: string, varId: string, value: any) => { + const { setInspectVarValue } = workflowStore.getState() await doEditInspectorVar({ varId, value, @@ -175,9 +178,10 @@ export const useInspectVarsCrud = () => { invalidateConversationVarValues() if (nodeId === VarInInspectType.system) invalidateSysVarValues() - }, [doEditInspectorVar, invalidateConversationVarValues, invalidateSysVarValues, setInspectVarValue]) + }, [doEditInspectorVar, invalidateConversationVarValues, invalidateSysVarValues, workflowStore]) const renameInspectVarName = useCallback(async (nodeId: string, oldName: string, newName: string) => { + const { renameInspectVarName } = workflowStore.getState() const varId = getVarId(nodeId, oldName) if (!varId) return @@ -187,8 +191,8 @@ export const useInspectVarsCrud = () => { varId, name: newName, }) - renameInspectVarNameInStore(nodeId, varId, newSelector) - }, [doEditInspectorVar, getVarId, renameInspectVarNameInStore]) + renameInspectVarName(nodeId, varId, newSelector) + }, [doEditInspectorVar, getVarId, workflowStore]) const isInspectVarEdited = useCallback((nodeId: string, name: string) => { const inspectVar = getInspectVar(nodeId, name) @@ -199,14 +203,15 @@ export const useInspectVarsCrud = () => { }, [getInspectVar]) const resetToLastRunVar = useCallback(async (nodeId: string, varId: string) => { + const { resetToLastRunVar } = workflowStore.getState() const isSysVar = nodeId === 'sys' const data = await doResetToLastRunValue(varId) if(isSysVar) invalidateSysVarValues() else - resetToLastRunVarInStore(nodeId, varId, data.value) - }, [doResetToLastRunValue, invalidateSysVarValues, resetToLastRunVarInStore]) + resetToLastRunVar(nodeId, varId, data.value) + }, [doResetToLastRunValue, invalidateSysVarValues, workflowStore]) return { hasNodeInspectVars,