35 lines
870 B
Python
35 lines
870 B
Python
from abc import ABC, abstractmethod
|
|
from typing import Optional, Any
|
|
from app.context import FlowContext
|
|
|
|
|
|
class NodeExecutor(ABC):
|
|
"""Base class for all node executors"""
|
|
|
|
@abstractmethod
|
|
async def execute(
|
|
self,
|
|
config: dict,
|
|
context: FlowContext,
|
|
session: Any
|
|
) -> Optional[str]:
|
|
"""
|
|
Execute the node logic.
|
|
Returns: branch name for routing (e.g., "default", "true", "false")
|
|
or "wait" to pause execution
|
|
"""
|
|
pass
|
|
|
|
|
|
class NodeRegistry:
|
|
"""Registry of all available node executors"""
|
|
_executors: dict = {}
|
|
|
|
@classmethod
|
|
def register(cls, node_type: str, executor: NodeExecutor):
|
|
cls._executors[node_type] = executor
|
|
|
|
@classmethod
|
|
def get(cls, node_type: str) -> Optional[NodeExecutor]:
|
|
return cls._executors.get(node_type)
|