fix(workflow): validate node compatibility when importing dsl between chatflows and workflows (#28012)

This commit is contained in:
yangzheli
2025-11-20 11:40:24 +08:00
committed by GitHub
parent fa910be0f6
commit 4833d39ab3
4 changed files with 50 additions and 3 deletions

View File

@ -9,6 +9,7 @@ import {
} from 'react'
import { useContext } from 'use-context-selector'
import { useTranslation } from 'react-i18next'
import { load as yamlLoad } from 'js-yaml'
import {
RiAlertFill,
RiCloseLine,
@ -16,8 +17,14 @@ import {
} from '@remixicon/react'
import { WORKFLOW_DATA_UPDATE } from './constants'
import {
BlockEnum,
SupportUploadFileTypes,
} from './types'
import type {
CommonNodeType,
Node,
} from './types'
import { AppModeEnum } from '@/types/app'
import {
initialEdges,
initialNodes,
@ -130,6 +137,33 @@ const UpdateDSLModal = ({
} as any)
}, [eventEmitter])
const validateDSLContent = (content: string): boolean => {
try {
const data = yamlLoad(content) as any
const nodes = data?.workflow?.graph?.nodes ?? []
const invalidNodes = appDetail?.mode === AppModeEnum.ADVANCED_CHAT
? [
BlockEnum.End,
BlockEnum.TriggerWebhook,
BlockEnum.TriggerSchedule,
BlockEnum.TriggerPlugin,
]
: [BlockEnum.Answer]
const hasInvalidNode = nodes.some((node: Node<CommonNodeType>) => {
return invalidNodes.includes(node?.data?.type)
})
if (hasInvalidNode) {
notify({ type: 'error', message: t('workflow.common.importFailure') })
return false
}
return true
}
catch (err: any) {
notify({ type: 'error', message: t('workflow.common.importFailure') })
return false
}
}
const isCreatingRef = useRef(false)
const handleImport: MouseEventHandler = useCallback(async () => {
if (isCreatingRef.current)
@ -138,7 +172,7 @@ const UpdateDSLModal = ({
if (!currentFile)
return
try {
if (appDetail && fileContent) {
if (appDetail && fileContent && validateDSLContent(fileContent)) {
setLoading(true)
const response = await importDSL({ mode: DSLImportMode.YAML_CONTENT, yaml_content: fileContent, app_id: appDetail.id })
const { id, status, app_id, imported_dsl_version, current_dsl_version } = response