fix(workflow): gate “publish as tool” on published user input node validity

This commit is contained in:
lyzno1
2025-10-15 20:26:12 +08:00
parent 34b7e5cbca
commit 2ccb20bf3a
8 changed files with 61 additions and 8 deletions

View File

@ -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,
}}
/>

View File

@ -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])