feat: introduce trigger functionality (#27644)

Signed-off-by: lyzno1 <yuanyouhuilyz@gmail.com>
Co-authored-by: Stream <Stream_2@qq.com>
Co-authored-by: lyzno1 <92089059+lyzno1@users.noreply.github.com>
Co-authored-by: zhsama <torvalds@linux.do>
Co-authored-by: Harry <xh001x@hotmail.com>
Co-authored-by: lyzno1 <yuanyouhuilyz@gmail.com>
Co-authored-by: yessenia <yessenia.contact@gmail.com>
Co-authored-by: hjlarry <hjlarry@163.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: WTW0313 <twwu@dify.ai>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Yeuoly
2025-11-12 17:59:37 +08:00
committed by GitHub
parent ca7794305b
commit b76e17b25d
785 changed files with 41186 additions and 3725 deletions

View File

@@ -18,7 +18,20 @@ import {
import type { FetchWorkflowDraftResponse } from '@/types/workflow'
import { useWorkflowConfig } from '@/service/use-workflow'
import type { FileUploadConfigResponse } from '@/models/common'
import type { Edge, Node } from '@/app/components/workflow/types'
import { BlockEnum } from '@/app/components/workflow/types'
import { AppModeEnum } from '@/types/app'
const hasConnectedUserInput = (nodes: Node[] = [], edges: Edge[] = []): boolean => {
const startNodeIds = nodes
.filter(node => node?.data?.type === BlockEnum.Start)
.map(node => node.id)
if (!startNodeIds.length)
return false
return edges.some(edge => startNodeIds.includes(edge.source))
}
export const useWorkflowInit = () => {
const workflowStore = useWorkflowStore()
const {
@@ -53,6 +66,7 @@ export const useWorkflowInit = () => {
}, {} as Record<string, string>),
environmentVariables: res.environment_variables?.map(env => env.value_type === 'secret' ? { ...env, value: '[__HIDDEN__]' } : env) || [],
conversationVariables: res.conversation_variables || [],
isWorkflowDataLoaded: true,
})
setSyncWorkflowDraftHash(res.hash)
setIsLoading(false)
@@ -61,13 +75,22 @@ export const useWorkflowInit = () => {
if (error && error.json && !error.bodyUsed && appDetail) {
error.json().then((err: any) => {
if (err.code === 'draft_workflow_not_exist') {
workflowStore.setState({ notInitialWorkflow: true })
const isAdvancedChat = appDetail.mode === AppModeEnum.ADVANCED_CHAT
workflowStore.setState({
notInitialWorkflow: true,
showOnboarding: !isAdvancedChat,
shouldAutoOpenStartNodeSelector: !isAdvancedChat,
hasShownOnboarding: false,
})
const nodesData = isAdvancedChat ? nodesTemplate : []
const edgesData = isAdvancedChat ? edgesTemplate : []
syncWorkflowDraft({
url: `/apps/${appDetail.id}/workflows/draft`,
params: {
graph: {
nodes: nodesTemplate,
edges: edgesTemplate,
nodes: nodesData,
edges: edgesData,
},
features: {
retriever_resource: { enabled: true },
@@ -101,9 +124,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])