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.

1.2 KB
Raw Blame
import type { WorkflowFinishedResponse } from '@/types/workflow'
import { produce } from 'immer'
import { useCallback } from 'react'
import { getFilesInLogs } from '@/app/components/base/file-uploader/utils'
import { useWorkflowStore } from '@/app/components/workflow/store'

export const useWorkflowFinished = () => {
  const workflowStore = useWorkflowStore()

  const handleWorkflowFinished = useCallback(
    (params: WorkflowFinishedResponse) => {
      const { data } = params
      const { workflowRunningData, setWorkflowRunningData } = workflowStore.getState()

      const isStringOutput =
        data.outputs &&
        Object.keys(data.outputs).length === 1 &&
        typeof data.outputs[Object.keys(data.outputs)[0]!] === 'string'

      setWorkflowRunningData(
        produce(workflowRunningData!, (draft) => {
          draft.result = {
            ...draft.result,
            ...data,
            files: getFilesInLogs(data.outputs),
          } as any
          if (isStringOutput) {
            draft.resultTabActive = true
            draft.resultText = data.outputs[Object.keys(data.outputs)[0]!]
          }
        }),
      )
    },
    [workflowStore],
  )

  return {
    handleWorkflowFinished,
  }
}