From 831ca8513b31f25d2a2b89a5b95ee8931107a3f1 Mon Sep 17 00:00:00 2001 From: Joel Date: Sun, 27 Apr 2025 16:51:58 +0800 Subject: [PATCH] chore: handle inspect var edit --- .../workflow/hooks/use-inspect-vars-crud.ts | 16 ++++++---------- .../store/workflow/debug/inspect-vars-slice.ts | 16 +++++++++++++--- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/web/app/components/workflow/hooks/use-inspect-vars-crud.ts b/web/app/components/workflow/hooks/use-inspect-vars-crud.ts index 48acd913a4..af2e179854 100644 --- a/web/app/components/workflow/hooks/use-inspect-vars-crud.ts +++ b/web/app/components/workflow/hooks/use-inspect-vars-crud.ts @@ -1,6 +1,6 @@ import { fetchNodeInspectVars } from '@/service/workflow' import { useWorkflowStore } from '../store' -import type { ValueSelector, VarType } from '../types' +import type { ValueSelector } from '../types' import { useConversationVarValues, useDeleteAllInspectorVars, @@ -18,12 +18,12 @@ const useInspectVarsCrud = () => { appId, nodesWithInspectVars, setNodeInspectVars, - getInspectVar, setInspectVarValue, renameInspectVarName: renameInspectVarNameInStore, deleteAllInspectVars: deleteAllInspectVarsInStore, deleteNodeInspectVars: deleteNodeInspectVarsInStore, deleteInspectVar: deleteInspectVarInStore, + isInspectVarEdited, getLastRunVar, } = workflowStore.getState() @@ -90,21 +90,17 @@ const useInspectVarsCrud = () => { renameInspectVarNameInStore(nodeId, varId, selector) } - const editInspectVarValueType = (varId: string, valueType: VarType) => { - console.log('edit var value type', varId, valueType) - } - - const isInspectVarEdited = (nodeId: string, key: string) => { - return getInspectVar(nodeId, key) !== getLastRunVar(nodeId, key) + const editInspectVarValueType = (nodeId: string) => { + deleteNodeInspectorVars(nodeId) } const resetToLastRunVar = (nodeId: string, key: string) => { const lastRunVar = getLastRunVar(nodeId, key) if (lastRunVar) - setInspectVarValue(nodeId, key, lastRunVar) + editInspectVarValue(nodeId, key, lastRunVar) } - console.log(conversationVars, systemVars) + // console.log(conversationVars, systemVars) return { conversationVars: conversationVars || [], diff --git a/web/app/components/workflow/store/workflow/debug/inspect-vars-slice.ts b/web/app/components/workflow/store/workflow/debug/inspect-vars-slice.ts index c09d24acb3..3942e5e36a 100644 --- a/web/app/components/workflow/store/workflow/debug/inspect-vars-slice.ts +++ b/web/app/components/workflow/store/workflow/debug/inspect-vars-slice.ts @@ -23,7 +23,8 @@ type InspectVarsActions = { setInspectVarValue: (nodeId: string, name: string, value: any) => void renameInspectVarName: (nodeId: string, varId: string, selector: ValueSelector) => void deleteInspectVar: (nodeId: string, varId: string) => void - getInspectVar: (nodeId: string, name: string) => any // The big value is null + getInspectVar: (nodeId: string, name: string) => any + isInspectVarEdited: (nodeId: string, name: string) => boolean } export type InspectVarsSliceShape = InspectVarsState & InspectVarsActions @@ -104,8 +105,10 @@ export const createInspectVarsSlice: StateCreator = (set, const needChangeVarIndex = draft.vars.findIndex((varItem) => { return varItem.id === varId }) - if (needChangeVarIndex !== -1) + if (needChangeVarIndex !== -1) { draft.vars[needChangeVarIndex].value = value + draft.vars[needChangeVarIndex].edited = true + } }) } return node @@ -147,7 +150,7 @@ export const createInspectVarsSlice: StateCreator = (set, state.nodesWithInspectVars = nodes })) }, - getInspectVar(nodeId, name) { + getInspectVar: (nodeId, name) => { const node = get().getNodeInspectVars(nodeId) if (!node) return undefined @@ -157,5 +160,12 @@ export const createInspectVarsSlice: StateCreator = (set, })?.value return variable }, + isInspectVarEdited: (nodeId, name) => { + const inspectVar = get().getInspectVar(nodeId, name) + if (!inspectVar) + return false + + return inspectVar.edited + }, }) }