MCPcopy Create free account
hub / github.com/FlowiseAI/Flowise / validateFlow

Function validateFlow

packages/agentflow/src/core/validation/flowValidation.ts:12–83  ·  view source on GitHub ↗
(nodes: FlowNode[], edges: FlowEdge[], availableNodes?: NodeDataSchema[])

Source from the content-addressed store, hash-verified

10 * Validate the flow structure
11 */
12export function validateFlow(nodes: FlowNode[], edges: FlowEdge[], availableNodes?: NodeDataSchema[]): ValidationResult {
13 const errors: ValidationError[] = []
14
15 // Check for empty flow
16 if (nodes.length === 0) {
17 errors.push({
18 message: 'Flow is empty - add at least one node',
19 type: 'error'
20 })
21 return { valid: false, errors }
22 }
23
24 // Check for start node
25 const startNode = nodes.find((n) => n.data.name === 'startAgentflow')
26 if (!startNode) {
27 errors.push({
28 message: 'Flow must have a start node',
29 type: 'error'
30 })
31 }
32
33 // Check for multiple start nodes
34 const startNodes = nodes.filter((n) => n.data.name === 'startAgentflow')
35 if (startNodes.length > 1) {
36 errors.push({
37 message: 'Flow can only have one start node',
38 type: 'error'
39 })
40 }
41
42 // Check for disconnected nodes (matching server-side pattern)
43 const connectedNodes = new Set<string>()
44 edges.forEach((edge) => {
45 connectedNodes.add(edge.source)
46 connectedNodes.add(edge.target)
47 })
48
49 const nonStickyNodes = nodes.filter((n) => n.data.name !== 'stickyNoteAgentflow')
50 nonStickyNodes.forEach((node) => {
51 if (!connectedNodes.has(node.id)) {
52 errors.push({
53 nodeId: node.id,
54 message: 'This node is not connected to anything',
55 type: 'warning'
56 })
57 }
58 })
59
60 // Check for cycles (should be handled during connection, but double-check)
61 const hasCycle = detectCycle(nodes, edges)
62 if (hasCycle) {
63 errors.push({
64 message: 'Flow contains a cycle - this may cause infinite loops',
65 type: 'error'
66 })
67 }
68
69 // Validate each node's inputs

Callers 4

AgentflowCanvasFunction · 0.90
useAgentflowFunction · 0.90

Calls 4

detectCycleFunction · 0.85
validateNodeFunction · 0.85
detectHangingEdgesFunction · 0.85
addMethod · 0.45

Tested by

no test coverage detected