dify/web/app/components/workflow/nodes/trigger-webhook/default.ts
lyzno1 60c86dd8d1 fix(workflow): replace hardcoded trigger node logic with metadata-driven approach
- Add isStart: true to all trigger nodes (TriggerWebhook, TriggerSchedule, TriggerPlugin)
- Replace hardcoded BlockEnum checks in use-checklist.ts with metadata-driven logic
- Update trigger node tests to validate metadata instead of obsolete methods
- Add webhook URL validation to TriggerWebhook node
- Ensure backward compatibility with existing workflow configurations

This change migrates from hardcoded trigger node identification to a
centralized metadata-driven approach, improving maintainability and
consistency across the workflow system.
2025-09-26 22:35:21 +08:00

62 lines
1.5 KiB
TypeScript

import { BlockEnum } from '../../types'
import type { NodeDefault } from '../../types'
import { genNodeMetaData } from '../../utils'
import type { WebhookTriggerNodeType } from './types'
import { isValidParameterType } from './utils/parameter-type-utils'
const metaData = genNodeMetaData({
sort: 3,
type: BlockEnum.TriggerWebhook,
isStart: true,
})
const nodeDefault: NodeDefault<WebhookTriggerNodeType> = {
metaData,
defaultValue: {
webhook_url: '',
method: 'POST',
content_type: 'application/json',
headers: [],
params: [],
body: [],
async_mode: true,
status_code: 200,
response_body: '',
},
checkValid(payload: WebhookTriggerNodeType, t: any) {
// Require webhook_url to be configured
if (!payload.webhook_url || payload.webhook_url.trim() === '') {
return {
isValid: false,
errorMessage: t('workflow.nodes.triggerWebhook.validation.webhookUrlRequired'),
}
}
// Validate parameter types for params and body
const parametersWithTypes = [
...(payload.params || []),
...(payload.body || []),
]
for (const param of parametersWithTypes) {
// Validate parameter type is valid
if (!isValidParameterType(param.type)) {
return {
isValid: false,
errorMessage: t('workflow.nodes.triggerWebhook.validation.invalidParameterType', {
name: param.name,
type: param.type,
}),
}
}
}
return {
isValid: true,
errorMessage: '',
}
},
}
export default nodeDefault