Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

988 B
Raw Blame
import type { IterationNextResponse } from '@/types/workflow'
import { produce } from 'immer'
import { useCallback } from 'react'
import { useStoreApi } from 'reactflow'
import { useWorkflowStore } from '@/app/components/workflow/store'

export const useWorkflowNodeIterationNext = () => {
  const store = useStoreApi()
  const workflowStore = useWorkflowStore()

  const handleWorkflowNodeIterationNext = useCallback(
    (params: IterationNextResponse) => {
      const { iterTimes, setIterTimes } = workflowStore.getState()

      const { data } = params
      const { getNodes, setNodes } = store.getState()

      const nodes = getNodes()
      const newNodes = produce(nodes, (draft) => {
        const currentNode = draft.find((node) => node.id === data.node_id)!
        currentNode.data._iterationIndex = iterTimes
        setIterTimes(iterTimes + 1)
      })
      setNodes(newNodes)
    },
    [workflowStore, store],
  )

  return {
    handleWorkflowNodeIterationNext,
  }
}