mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-05 05:10:36 +08:00
32 lines
1.0 KiB
TypeScript
32 lines
1.0 KiB
TypeScript
import { useCurrentVarsStore } from '../current-vars-store/store'
|
|
import { useLastRunStore } from '../last-run-store/store'
|
|
const useCurrentVars = () => {
|
|
const currentVars = useCurrentVarsStore(state => state.nodes)
|
|
const getCurrentVar = useCurrentVarsStore(state => state.getVar)
|
|
const getLastRunVar = useLastRunStore(state => state.getVar)
|
|
const setCurrentVar = useCurrentVarsStore(state => state.setVar)
|
|
const clearCurrentVars = useCurrentVarsStore(state => state.clearVars)
|
|
const clearNodeVars = useCurrentVarsStore(state => state.clearNodeVars)
|
|
|
|
const isVarChanged = (nodeId: string, key: string) => {
|
|
return getCurrentVar(nodeId, key) !== getLastRunVar(nodeId, key)
|
|
}
|
|
|
|
const resetToLastRunVar = (nodeId: string, key: string) => {
|
|
const lastRunVar = getLastRunVar(nodeId, key)
|
|
if (lastRunVar)
|
|
setCurrentVar(nodeId, key, lastRunVar)
|
|
}
|
|
|
|
return {
|
|
currentVars,
|
|
isVarChanged,
|
|
clearCurrentVars,
|
|
clearNodeVars,
|
|
setCurrentVar,
|
|
resetToLastRunVar,
|
|
}
|
|
}
|
|
|
|
export default useCurrentVars
|