mirror of
https://github.com/langgenius/dify.git
synced 2026-05-04 01:18:05 +08:00
fix(workflow): gate “publish as tool” on published user input node validity
This commit is contained in:
@ -50,9 +50,12 @@ const FeaturesTrigger = () => {
|
||||
const publishedAt = useStore(s => s.publishedAt)
|
||||
const draftUpdatedAt = useStore(s => s.draftUpdatedAt)
|
||||
const toolPublished = useStore(s => s.toolPublished)
|
||||
const lastPublishedHasUserInput = useStore(s => s.lastPublishedHasUserInput)
|
||||
const startVariables = useReactflowStore(
|
||||
s => s.getNodes().find(node => node.data.type === BlockEnum.Start)?.data.variables,
|
||||
)
|
||||
const nodes = useNodes<CommonNodeType>()
|
||||
const edges = useEdges<CommonEdgeType>()
|
||||
const fileSettings = useFeatures(s => s.features.file)
|
||||
const variables = useMemo(() => {
|
||||
const data = startVariables || []
|
||||
@ -74,6 +77,15 @@ const FeaturesTrigger = () => {
|
||||
const { handleCheckBeforePublish } = useChecklistBeforePublish()
|
||||
const { handleSyncWorkflowDraft } = useNodesSyncDraft()
|
||||
const { notify } = useToastContext()
|
||||
const startNodeIds = useMemo(
|
||||
() => nodes.filter(node => node.data.type === BlockEnum.Start).map(node => node.id),
|
||||
[nodes],
|
||||
)
|
||||
const hasUserInputNode = useMemo(() => {
|
||||
if (!startNodeIds.length)
|
||||
return false
|
||||
return edges.some(edge => startNodeIds.includes(edge.source))
|
||||
}, [edges, startNodeIds])
|
||||
|
||||
const resetWorkflowVersionHistory = useResetWorkflowVersionHistory()
|
||||
const invalidateAppTriggers = useInvalidateAppTriggers()
|
||||
@ -101,8 +113,6 @@ const FeaturesTrigger = () => {
|
||||
|
||||
const { mutateAsync: publishWorkflow } = usePublishWorkflow()
|
||||
// const { validateBeforeRun } = useWorkflowRunValidation()
|
||||
const nodes = useNodes<CommonNodeType>()
|
||||
const edges = useEdges<CommonEdgeType>()
|
||||
const needWarningNodes = useChecklist(nodes, edges)
|
||||
|
||||
const updatePublishedWorkflow = useInvalidateAppWorkflow()
|
||||
@ -130,6 +140,7 @@ const FeaturesTrigger = () => {
|
||||
updateAppDetail()
|
||||
invalidateAppTriggers(appID!)
|
||||
workflowStore.getState().setPublishedAt(res.created_at)
|
||||
workflowStore.getState().setLastPublishedHasUserInput(hasUserInputNode)
|
||||
resetWorkflowVersionHistory()
|
||||
}
|
||||
}
|
||||
@ -172,6 +183,7 @@ const FeaturesTrigger = () => {
|
||||
onRefreshData: handleToolConfigureUpdate,
|
||||
onPublish,
|
||||
onToggle: onPublisherToggle,
|
||||
workflowToolAvailable: lastPublishedHasUserInput,
|
||||
crossAxisOffset: 4,
|
||||
}}
|
||||
/>
|
||||
|
||||
@ -18,7 +18,18 @@ import {
|
||||
import type { FetchWorkflowDraftResponse } from '@/types/workflow'
|
||||
import { useWorkflowConfig } from '@/service/use-workflow'
|
||||
import type { FileUploadConfigResponse } from '@/models/common'
|
||||
import { BlockEnum } from '@/app/components/workflow/types'
|
||||
|
||||
const hasConnectedUserInput = (nodes: any[] = [], edges: any[] = []) => {
|
||||
const startNodeIds = nodes
|
||||
.filter(node => node?.data?.type === BlockEnum.Start)
|
||||
.map((node: any) => node.id)
|
||||
|
||||
if (!startNodeIds.length)
|
||||
return false
|
||||
|
||||
return edges?.some((edge: any) => startNodeIds.includes(edge.source))
|
||||
}
|
||||
export const useWorkflowInit = () => {
|
||||
const workflowStore = useWorkflowStore()
|
||||
const {
|
||||
@ -110,9 +121,14 @@ export const useWorkflowInit = () => {
|
||||
}, {} as Record<string, any>),
|
||||
})
|
||||
workflowStore.getState().setPublishedAt(publishedWorkflow?.created_at)
|
||||
const graph = publishedWorkflow?.graph
|
||||
workflowStore.getState().setLastPublishedHasUserInput(
|
||||
hasConnectedUserInput(graph?.nodes, graph?.edges),
|
||||
)
|
||||
}
|
||||
catch (e) {
|
||||
console.error(e)
|
||||
workflowStore.getState().setLastPublishedHasUserInput(false)
|
||||
}
|
||||
}, [workflowStore, appDetail])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user