refactor: streamline edge building and node filtering in workflow graph

This commit is contained in:
zhsama 2025-12-22 18:59:08 +08:00
parent 035f51ad58
commit 22f25731e8
5 changed files with 6 additions and 18 deletions

View File

@ -130,15 +130,12 @@ class Graph:
@classmethod
def _build_edges(
cls,
edge_configs: list[dict[str, object]],
valid_node_ids: set[str] | None = None,
cls, edge_configs: list[dict[str, object]]
) -> tuple[dict[str, Edge], dict[str, list[str]], dict[str, list[str]]]:
"""
Build edge objects and mappings from edge configurations.
:param edge_configs: list of edge configurations
:param valid_node_ids: optional set of valid node IDs to filter edges
:return: tuple of (edges dict, in_edges dict, out_edges dict)
"""
edges: dict[str, Edge] = {}
@ -308,16 +305,7 @@ class Graph:
if not node_configs:
raise ValueError("Graph must have at least one node")
# Filter out UI-only nodes that should not participate in workflow execution
# Check both node.type (ReactFlow type) and node.data.type (business type)
ui_only_node_types = {"custom-note"}
ui_only_data_types = {"group"}
node_configs = [
node_config
for node_config in node_configs
if node_config.get("type", "") not in ui_only_node_types
and node_config.get("data", {}).get("type", "") not in ui_only_data_types
]
node_configs = [node_config for node_config in node_configs if node_config.get("type", "") != "custom-note"]
# Parse node configurations
node_configs_map = cls._parse_node_configs(node_configs)

View File

@ -4,7 +4,7 @@ import type { FC } from 'react'
import { memo } from 'react'
import { Handle, Position } from 'reactflow'
import type { CustomGroupExitPortNodeData } from './types'
import cn from '@/utils/classnames'
import { cn } from '@/utils/classnames'
type CustomGroupExitPortNodeProps = {
id: string

View File

@ -4,7 +4,7 @@ import type { FC } from 'react'
import { memo } from 'react'
import { Handle, Position } from 'reactflow'
import type { CustomGroupInputNodeData } from './types'
import cn from '@/utils/classnames'
import { cn } from '@/utils/classnames'
type CustomGroupInputNodeProps = {
id: string

View File

@ -4,7 +4,7 @@ import type { FC } from 'react'
import { memo } from 'react'
import { Handle, Position } from 'reactflow'
import type { CustomGroupNodeData } from './types'
import cn from '@/utils/classnames'
import { cn } from '@/utils/classnames'
type CustomGroupNodeProps = {
id: string

View File

@ -4,7 +4,7 @@ import BlockIcon from '@/app/components/workflow/block-icon'
import type { NodeProps } from '@/app/components/workflow/types'
import type { GroupHandler, GroupMember, GroupNodeData } from './types'
import type { BlockEnum } from '@/app/components/workflow/types'
import cn from '@/utils/classnames'
import { cn } from '@/utils/classnames'
const MAX_MEMBER_ICONS = 12