mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-05 18:40:52 +08:00
feat: single run set datas
This commit is contained in:
parent
33258f1acf
commit
e848c0c1d8
@ -152,7 +152,19 @@ const useOneStepRun = <T>({
|
|||||||
}, [])
|
}, [])
|
||||||
const iterationTimes = iteratorInputKey ? runInputData[iteratorInputKey].length : 0
|
const iterationTimes = iteratorInputKey ? runInputData[iteratorInputKey].length : 0
|
||||||
const loopTimes = loopInputKey ? runInputData[loopInputKey].length : 0
|
const loopTimes = loopInputKey ? runInputData[loopInputKey].length : 0
|
||||||
const [runResult, setRunResult] = useState<NodeRunResult | null>(null)
|
|
||||||
|
const workflowStore = useWorkflowStore()
|
||||||
|
const {
|
||||||
|
setLastRunNodeInfo,
|
||||||
|
setCurrentNodeVars,
|
||||||
|
setShowSingleRunPanel,
|
||||||
|
} = workflowStore.getState()
|
||||||
|
const [runResult, doSetRunResult] = useState<NodeRunResult | null>(null)
|
||||||
|
const setRunResult = useCallback((data: NodeRunResult | null) => {
|
||||||
|
doSetRunResult(data)
|
||||||
|
setLastRunNodeInfo(id, data as any)
|
||||||
|
setCurrentNodeVars(id, data as any)
|
||||||
|
}, [id, setLastRunNodeInfo, setCurrentNodeVars])
|
||||||
|
|
||||||
const { handleNodeDataUpdate }: { handleNodeDataUpdate: (data: any) => void } = useNodeDataUpdate()
|
const { handleNodeDataUpdate }: { handleNodeDataUpdate: (data: any) => void } = useNodeDataUpdate()
|
||||||
const [canShowSingleRun, setCanShowSingleRun] = useState(false)
|
const [canShowSingleRun, setCanShowSingleRun] = useState(false)
|
||||||
@ -186,10 +198,9 @@ const useOneStepRun = <T>({
|
|||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [data._isSingleRun])
|
}, [data._isSingleRun])
|
||||||
|
|
||||||
const workflowStore = useWorkflowStore()
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
workflowStore.getState().setShowSingleRunPanel(!!isShowSingleRun)
|
setShowSingleRunPanel(!!isShowSingleRun)
|
||||||
}, [isShowSingleRun, workflowStore])
|
}, [isShowSingleRun, setShowSingleRunPanel])
|
||||||
|
|
||||||
const hideSingleRun = () => {
|
const hideSingleRun = () => {
|
||||||
handleNodeDataUpdate({
|
handleNodeDataUpdate({
|
||||||
|
@ -33,9 +33,8 @@ const Panel = forwardRef<PanelExposedType, NodePanelProps<LLMNodeType>>(({
|
|||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const {
|
const {
|
||||||
currentVars,
|
currentVars,
|
||||||
getLastRunInfos,
|
|
||||||
} = useCurrentVars()
|
} = useCurrentVars()
|
||||||
// console.log(currentVars, getLastRunInfos())
|
console.log(currentVars)
|
||||||
const {
|
const {
|
||||||
readOnly,
|
readOnly,
|
||||||
inputs,
|
inputs,
|
||||||
|
@ -41,14 +41,15 @@ export const createCurrentVarsSlice: StateCreator<CurrentVarsSliceShape> = (set,
|
|||||||
},
|
},
|
||||||
setCurrentNodeVars: (nodeId, payload) => {
|
setCurrentNodeVars: (nodeId, payload) => {
|
||||||
set((state) => {
|
set((state) => {
|
||||||
const nodes = state.currentNodes.map((node) => {
|
const prevNodes = state.currentNodes
|
||||||
// eslint-disable-next-line curly
|
const nodes = produce(prevNodes, (draft) => {
|
||||||
if (node.node_id === nodeId) {
|
const index = prevNodes.findIndex(node => node.id === nodeId)
|
||||||
return payload
|
if (index === -1)
|
||||||
}
|
draft.push(payload)
|
||||||
|
else
|
||||||
return node
|
draft[index] = payload
|
||||||
})
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
currentNodes: nodes,
|
currentNodes: nodes,
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import type { NodeTracing } from '@/types/workflow'
|
import type { NodeTracing } from '@/types/workflow'
|
||||||
|
import produce from 'immer'
|
||||||
import type { StateCreator } from 'zustand'
|
import type { StateCreator } from 'zustand'
|
||||||
|
|
||||||
type NodeInfo = NodeTracing
|
type NodeInfo = NodeTracing
|
||||||
@ -10,6 +11,7 @@ type LastRunState = {
|
|||||||
type LastRunActions = {
|
type LastRunActions = {
|
||||||
setLastRunInfos: (vars: NodeInfo[]) => void
|
setLastRunInfos: (vars: NodeInfo[]) => void
|
||||||
getLastRunInfos: () => NodeInfo[]
|
getLastRunInfos: () => NodeInfo[]
|
||||||
|
setLastRunNodeInfo: (nodeId: string, payload: NodeInfo) => void
|
||||||
getLastRunNodeInfo: (nodeId: string) => NodeInfo | undefined
|
getLastRunNodeInfo: (nodeId: string) => NodeInfo | undefined
|
||||||
getLastRunVar: (nodeId: string, key: string) => any
|
getLastRunVar: (nodeId: string, key: string) => any
|
||||||
}
|
}
|
||||||
@ -32,6 +34,22 @@ export const createLastRunSlice: StateCreator<LastRunSliceShape> = (set, get) =>
|
|||||||
nodes: [],
|
nodes: [],
|
||||||
}))
|
}))
|
||||||
},
|
},
|
||||||
|
setLastRunNodeInfo: (nodeId, payload) => {
|
||||||
|
set((state) => {
|
||||||
|
const prevNodes = state.nodes
|
||||||
|
const nodes = produce(prevNodes, (draft) => {
|
||||||
|
const index = prevNodes.findIndex(node => node.id === nodeId)
|
||||||
|
if (index === -1)
|
||||||
|
draft.push(payload)
|
||||||
|
else
|
||||||
|
draft[index] = payload
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
nodes,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
getLastRunNodeInfo: (nodeId) => {
|
getLastRunNodeInfo: (nodeId) => {
|
||||||
const nodes = get().nodes
|
const nodes = get().nodes
|
||||||
return nodes.find(node => node.node_id === nodeId)
|
return nodes.find(node => node.node_id === nodeId)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user