feat: Phase 5 - Visual Workflow Editor (Option B)
Backend (Mini-Backend 1-2h): - Migration 016: ai_prompts.graph_data JSONB column - workflow_executor: graph_data parameter support (backward-compatible) - prompt_executor: execute_workflow_prompt uses graph_data Frontend (Main effort 25-35h): - WorkflowCanvas: React Flow wrapper component - 5 Custom Nodes: Start, End, Analysis, Logic, Join - 4 Config Panels: QuestionAugmentation, LogicExpression, Fallback, Join - workflowValidation: Structural + logical validation - workflowSerializer: Canvas ↔ JSONB conversion - WorkflowEditorPage: Main orchestration (420 LOC) - Route: /workflow-editor/:id - CSS: workflowEditor.css (300 LOC) Architecture: - Option B: ai_prompts.type='workflow' (not separate table) - panels/ subdirectory for clean separation - WorkflowCanvas reusable component - User GUI identical (Workflows = Prompts) - Backward-compatible (type='pipeline' unchanged) Version: v0.9m → v0.9n (Phase 5 complete) Module: workflow 0.5.0 → 0.6.0 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
a7058c30be
commit
dc59596f01
23 files changed
+3010
-48
No files matched your search
@@ -35,10 +35,11 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def execute_workflow(
|
||||
workflow_id: str,
|
||||
profile_id: str,
|
||||
variables: Dict[str, Any],
|
||||
openrouter_call_func, # Callback für LLM-Calls: async (prompt, model) -> str
|
||||
workflow_id: Optional[str] = None,
|
||||
graph_data: Optional[Dict] = None, # Phase 5: Direkt von ai_prompts.graph_data
|
||||
profile_id: str = None,
|
||||
variables: Dict[str, Any] = None,
|
||||
openrouter_call_func = None, # Callback für LLM-Calls: async (prompt, model) -> str
|
||||
enable_debug: bool = False
|
||||
) -> ExecutionResult:
|
||||
"""
|
||||
@@ -47,9 +48,11 @@ async def execute_workflow(
|
||||
Phase 2: Linear execution in topological order.
|
||||
Phase 3: Conditional branching basierend auf logic nodes.
|
||||
Phase 4: Join nodes und path consolidation.
|
||||
Phase 5: Unterstützt graph_data direkt (aus ai_prompts, nicht workflow_definitions)
|
||||
|
||||
Args:
|
||||
workflow_id: UUID des Workflows
|
||||
workflow_id: UUID des Workflows (legacy, für workflow_definitions Tabelle)
|
||||
graph_data: Workflow-Graph als Dict (NEU, für ai_prompts.graph_data)
|
||||
profile_id: UUID des Profils
|
||||
variables: Platzhalter-Werte (z.B. {"name": "Lars", ...})
|
||||
openrouter_call_func: async (prompt, model) -> str
|
||||
@@ -58,36 +61,41 @@ async def execute_workflow(
|
||||
Returns:
|
||||
ExecutionResult mit allen node_states
|
||||
|
||||
Beispiel:
|
||||
Beispiel (Phase 5):
|
||||
>>> result = await execute_workflow(
|
||||
... workflow_id="test-workflow",
|
||||
... graph_data={"nodes": [...], "edges": [...]},
|
||||
... profile_id="test-profile",
|
||||
... variables={"name": "Lars"},
|
||||
... openrouter_call_func=my_llm_func
|
||||
... )
|
||||
>>> result.status
|
||||
'completed'
|
||||
>>> len(result.node_states)
|
||||
3
|
||||
"""
|
||||
execution_id = str(uuid.uuid4())
|
||||
started_at = datetime.utcnow().isoformat()
|
||||
|
||||
logger.info(f"Starting workflow execution: {execution_id} (workflow: {workflow_id})")
|
||||
logger.info(f"Starting workflow execution: {execution_id}")
|
||||
|
||||
try:
|
||||
# 1. Lade Workflow-Definition
|
||||
with get_db() as conn:
|
||||
cur = get_cursor(conn)
|
||||
cur.execute(
|
||||
"SELECT graph FROM workflow_definitions WHERE id = %s AND active = true",
|
||||
(workflow_id,)
|
||||
)
|
||||
row = cur.fetchone()
|
||||
if not row:
|
||||
raise ValueError(f"Workflow not found: {workflow_id}")
|
||||
if graph_data:
|
||||
# Phase 5: Graph direkt aus ai_prompts.graph_data
|
||||
graph_json = json.dumps(graph_data)
|
||||
logger.debug(f"Using provided graph_data")
|
||||
elif workflow_id:
|
||||
# Phase 0-4: Graph aus workflow_definitions Tabelle (legacy)
|
||||
with get_db() as conn:
|
||||
cur = get_cursor(conn)
|
||||
cur.execute(
|
||||
"SELECT graph FROM workflow_definitions WHERE id = %s AND active = true",
|
||||
(workflow_id,)
|
||||
)
|
||||
row = cur.fetchone()
|
||||
if not row:
|
||||
raise ValueError(f"Workflow not found: {workflow_id}")
|
||||
|
||||
graph_json = row['graph']
|
||||
graph_json = row['graph']
|
||||
logger.debug(f"Loaded graph from workflow_definitions: {workflow_id}")
|
||||
else:
|
||||
raise ValueError("Entweder workflow_id oder graph_data muss übergeben werden")
|
||||
|
||||
# 2. Parse Graph
|
||||
graph = parse_workflow_graph(graph_json)
|
||||
|
||||
Reference in new issue
Block a user