mirror of https://github.com/langgenius/dify.git
fix(workflow): gate “publish as tool” on published user input node validity
This commit is contained in:
parent
34b7e5cbca
commit
2ccb20bf3a
|
|
@ -64,6 +64,7 @@ export type AppPublisherProps = {
|
|||
toolPublished?: boolean
|
||||
inputs?: InputVar[]
|
||||
onRefreshData?: () => void
|
||||
workflowToolAvailable?: boolean
|
||||
}
|
||||
|
||||
const PUBLISH_SHORTCUT = ['ctrl', '⇧', 'P']
|
||||
|
|
@ -82,6 +83,7 @@ const AppPublisher = ({
|
|||
toolPublished,
|
||||
inputs,
|
||||
onRefreshData,
|
||||
workflowToolAvailable = true,
|
||||
}: AppPublisherProps) => {
|
||||
const { t } = useTranslation()
|
||||
const [published, setPublished] = useState(false)
|
||||
|
|
@ -178,6 +180,10 @@ const AppPublisher = ({
|
|||
handlePublish()
|
||||
}, { exactMatch: true, useCapture: true })
|
||||
|
||||
const hasPublishedVersion = !!publishedAt
|
||||
const workflowToolDisabled = !hasPublishedVersion || !workflowToolAvailable
|
||||
const workflowToolMessage = workflowToolDisabled ? t('workflow.common.workflowAsToolDisabledHint') : undefined
|
||||
|
||||
return (
|
||||
<>
|
||||
<PortalToFollowElem
|
||||
|
|
@ -366,7 +372,7 @@ const AppPublisher = ({
|
|||
</SuggestedAction>
|
||||
{appDetail?.mode === 'workflow' && (
|
||||
<WorkflowToolConfigureButton
|
||||
disabled={!publishedAt}
|
||||
disabled={workflowToolDisabled}
|
||||
published={!!toolPublished}
|
||||
detailNeedUpdate={!!toolPublished && published}
|
||||
workflowAppId={appDetail?.id}
|
||||
|
|
@ -379,6 +385,7 @@ const AppPublisher = ({
|
|||
inputs={inputs}
|
||||
handlePublish={handlePublish}
|
||||
onRefreshData={onRefreshData}
|
||||
disabledReason={workflowToolMessage}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ type Props = {
|
|||
inputs?: InputVar[]
|
||||
handlePublish: (params?: PublishWorkflowParams) => Promise<void>
|
||||
onRefreshData?: () => void
|
||||
disabledReason?: string
|
||||
}
|
||||
|
||||
const WorkflowToolConfigureButton = ({
|
||||
|
|
@ -41,6 +42,7 @@ const WorkflowToolConfigureButton = ({
|
|||
inputs,
|
||||
handlePublish,
|
||||
onRefreshData,
|
||||
disabledReason,
|
||||
}: Props) => {
|
||||
const { t } = useTranslation()
|
||||
const router = useRouter()
|
||||
|
|
@ -200,7 +202,8 @@ const WorkflowToolConfigureButton = ({
|
|||
{t('workflow.common.configureRequired')}
|
||||
</span>
|
||||
)}
|
||||
</div>)
|
||||
</div>
|
||||
)
|
||||
: (
|
||||
<div
|
||||
className='flex items-center justify-start gap-2 p-2 pl-2.5'
|
||||
|
|
@ -214,6 +217,11 @@ const WorkflowToolConfigureButton = ({
|
|||
</div>
|
||||
</div>
|
||||
)}
|
||||
{disabledReason && (
|
||||
<div className='mt-1 px-2.5 pb-2 text-xs leading-[18px] text-text-tertiary'>
|
||||
{disabledReason}
|
||||
</div>
|
||||
)}
|
||||
{published && (
|
||||
<div className='border-t-[0.5px] border-divider-regular px-2.5 py-2'>
|
||||
<div className='flex justify-between gap-x-2'>
|
||||
|
|
@ -221,7 +229,7 @@ const WorkflowToolConfigureButton = ({
|
|||
size='small'
|
||||
className='w-[140px]'
|
||||
onClick={() => setShowModal(true)}
|
||||
disabled={!isCurrentWorkspaceManager}
|
||||
disabled={!isCurrentWorkspaceManager || disabled}
|
||||
>
|
||||
{t('workflow.common.configure')}
|
||||
{outdated && <Indicator className='ml-1' color={'yellow'} />}
|
||||
|
|
@ -230,14 +238,17 @@ const WorkflowToolConfigureButton = ({
|
|||
size='small'
|
||||
className='w-[140px]'
|
||||
onClick={() => router.push('/tools?category=workflow')}
|
||||
disabled={disabled}
|
||||
>
|
||||
{t('workflow.common.manageInTools')}
|
||||
<RiArrowRightUpLine className='ml-1 h-4 w-4' />
|
||||
</Button>
|
||||
</div>
|
||||
{outdated && <div className='mt-1 text-xs leading-[18px] text-text-warning'>
|
||||
{t('workflow.common.workflowAsToolTip')}
|
||||
</div>}
|
||||
{outdated && (
|
||||
<div className='mt-1 text-xs leading-[18px] text-text-warning'>
|
||||
{t('workflow.common.workflowAsToolTip')}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -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])
|
||||
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ export type ToolSliceShape = {
|
|||
setMcpTools: (tools: ToolWithProvider[]) => void
|
||||
toolPublished: boolean
|
||||
setToolPublished: (toolPublished: boolean) => void
|
||||
lastPublishedHasUserInput: boolean
|
||||
setLastPublishedHasUserInput: (hasUserInput: boolean) => void
|
||||
}
|
||||
|
||||
export const createToolSlice: StateCreator<ToolSliceShape> = set => ({
|
||||
|
|
@ -27,4 +29,6 @@ export const createToolSlice: StateCreator<ToolSliceShape> = set => ({
|
|||
setMcpTools: mcpTools => set(() => ({ mcpTools })),
|
||||
toolPublished: false,
|
||||
setToolPublished: toolPublished => set(() => ({ toolPublished })),
|
||||
lastPublishedHasUserInput: false,
|
||||
setLastPublishedHasUserInput: hasUserInput => set(() => ({ lastPublishedHasUserInput: hasUserInput })),
|
||||
})
|
||||
|
|
|
|||
|
|
@ -88,6 +88,7 @@ const translation = {
|
|||
configure: 'Configure',
|
||||
manageInTools: 'Manage in Tools',
|
||||
workflowAsToolTip: 'Tool reconfiguration is required after the workflow update.',
|
||||
workflowAsToolDisabledHint: 'Publish the latest workflow and ensure a connected User Input node before configuring it as a tool.',
|
||||
viewDetailInTracingPanel: 'View details',
|
||||
syncingData: 'Syncing data, just a few seconds.',
|
||||
importDSL: 'Import DSL',
|
||||
|
|
|
|||
|
|
@ -83,6 +83,7 @@ const translation = {
|
|||
configure: '設定',
|
||||
manageInTools: 'ツールページで管理',
|
||||
workflowAsToolTip: 'ワークフロー更新後はツールの再設定が必要です',
|
||||
workflowAsToolDisabledHint: '最新のワークフローを公開し、接続済みの User Input ノードを用意してからツールとして設定してください。',
|
||||
viewDetailInTracingPanel: '詳細を表示',
|
||||
syncingData: 'データ同期中。。。',
|
||||
importDSL: 'DSL をインポート',
|
||||
|
|
|
|||
|
|
@ -86,6 +86,7 @@ const translation = {
|
|||
configure: '配置',
|
||||
manageInTools: '访问工具页',
|
||||
workflowAsToolTip: '工作流更新后需要重新配置工具参数',
|
||||
workflowAsToolDisabledHint: '请先发布最新的工作流,并确保已连接的 User Input 节点后再配置为工具。',
|
||||
viewDetailInTracingPanel: '查看详细信息',
|
||||
syncingData: '同步数据中,只需几秒钟。',
|
||||
importDSL: '导入 DSL',
|
||||
|
|
|
|||
Loading…
Reference in New Issue