feat: Phase 5 - Visual Workflow Editor (Option B)
Deploy Development / deploy (push) Failing after 1s
Build Test / lint-backend (push) Successful in 1s
Build Test / build-frontend (push) Successful in 14s

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:
LarsandClaude Opus 4.6 committed 2026-04-04 17:56:00 +02:00
1 parent a7058c30be
commit dc59596f01
23 files changed
+3010 -48

No files matched your search

+1
View File
@@ -286,6 +286,7 @@ export const api = {
// AI Prompts Management (Issue #28)
listAdminPrompts: () => req('/prompts'),
getPrompt: (id) => req(`/prompts/${id}`),
createPrompt: (d) => req('/prompts', json(d)),
updatePrompt: (id,d) => req(`/prompts/${id}`, jput(d)),
deletePrompt: (id) => req(`/prompts/${id}`, {method:'DELETE'}),
+117
View File
@@ -0,0 +1,117 @@
/**
* Workflow Serialization Utilities
*
* Konvertiert zwischen React Flow (Canvas) und Backend-Format (JSONB).
*/
/**
* Serialisiert React Flow Graph zu Backend-kompatiblem Format
*
* @param {Array} nodes - React Flow nodes
* @param {Array} edges - React Flow edges
* @param {Object} metadata - Zusätzliche Metadaten
* @returns {Object} JSONB-kompatibles Objekt für ai_prompts.graph_data
*/
export function serializeToWorkflowGraph(nodes, edges, metadata = {}) {
const workflowNodes = nodes.map(node => ({
id: node.id,
type: node.type,
label: node.data.label || node.type,
position: { x: node.position.x, y: node.position.y },
// Type-spezifische Felder
...(node.type === 'analysis' && {
prompt_id: node.data.prompt_id || null,
questions: node.data.questions || [],
fallback_strategy: node.data.fallback_strategy || 'conservative_skip'
}),
...(node.type === 'logic' && {
condition: node.data.condition || null,
fallback_strategy: node.data.fallback_strategy || 'conservative_skip'
}),
...(node.type === 'join' && {
join_strategy: node.data.join_strategy || 'wait_all',
skip_handling: node.data.skip_handling || 'ignore_skipped',
min_paths: node.data.min_paths || 2
})
}))
const workflowEdges = edges.map(edge => ({
id: edge.id,
source: edge.source,
target: edge.target,
label: edge.data?.label || null,
sourceHandle: edge.sourceHandle || null,
targetHandle: edge.targetHandle || null
}))
return {
nodes: workflowNodes,
edges: workflowEdges,
metadata: {
created_at: metadata.created_at || new Date().toISOString(),
updated_at: new Date().toISOString(),
version: metadata.version || '1.0'
}
}
}
/**
* Deserialisiert Backend-Format zu React Flow Graph
*
* @param {Object} jsonbData - ai_prompts.graph_data (JSONB)
* @returns {Object} { nodes, edges, metadata }
*/
export function deserializeFromWorkflowGraph(jsonbData) {
if (!jsonbData || !jsonbData.nodes || !jsonbData.edges) {
throw new Error('Invalid workflow graph data')
}
const reactFlowNodes = jsonbData.nodes.map(node => ({
id: node.id,
type: node.type,
position: { x: node.position.x, y: node.position.y },
data: {
label: node.label,
...(node.type === 'analysis' && {
prompt_id: node.prompt_id,
prompt_name: node.prompt_name || null, // Falls vom Backend mitgeliefert
questions: node.questions || [],
fallback_strategy: node.fallback_strategy || 'conservative_skip'
}),
...(node.type === 'logic' && {
condition: node.condition || null,
fallback_strategy: node.fallback_strategy || 'conservative_skip'
}),
...(node.type === 'join' && {
join_strategy: node.join_strategy || 'wait_all',
skip_handling: node.skip_handling || 'ignore_skipped',
min_paths: node.min_paths || 2
})
}
}))
const reactFlowEdges = jsonbData.edges.map(edge => ({
id: edge.id,
source: edge.source,
target: edge.target,
sourceHandle: edge.sourceHandle || null,
targetHandle: edge.targetHandle || null,
data: {
label: edge.label || null
},
type: 'default',
animated: false
}))
return {
nodes: reactFlowNodes,
edges: reactFlowEdges,
metadata: jsonbData.metadata || {}
}
}
+226
View File
@@ -0,0 +1,226 @@
/**
* Workflow Validation Utilities
*
* Validiert Workflow-Graphen (Struktur + Logik).
*/
export function validateWorkflowGraph(nodes, edges) {
const errors = []
const warnings = []
// 1. Strukturelle Validierung
validateStructure(nodes, edges, errors, warnings)
// 2. Logische Validierung
validateLogic(nodes, edges, errors, warnings)
return {
errors,
warnings,
isValid: errors.length === 0
}
}
/**
* Strukturelle Validierung (DAG, START/END, Zyklen)
*/
function validateStructure(nodes, edges, errors, warnings) {
// START Node
const startNodes = nodes.filter(n => n.type === 'start')
if (startNodes.length === 0) {
errors.push({
type: 'structure',
message: 'Kein START-Node vorhanden',
severity: 'error'
})
} else if (startNodes.length > 1) {
errors.push({
type: 'structure',
message: `${startNodes.length} START-Nodes gefunden (max. 1 erlaubt)`,
severity: 'error'
})
}
// END Node
const endNodes = nodes.filter(n => n.type === 'end')
if (endNodes.length === 0) {
errors.push({
type: 'structure',
message: 'Kein END-Node vorhanden',
severity: 'error'
})
}
// Zyklen-Erkennung
if (detectCycles(nodes, edges)) {
errors.push({
type: 'structure',
message: 'Workflow enthält Zyklen (nicht erlaubt)',
severity: 'error'
})
}
// Isolierte Nodes
nodes.forEach(node => {
if (node.type === 'start' || node.type === 'end') return
const hasIncoming = edges.some(e => e.target === node.id)
const hasOutgoing = edges.some(e => e.source === node.id)
if (!hasIncoming || !hasOutgoing) {
warnings.push({
type: 'isolation',
message: `Node "${node.data.label}" ist isoliert (keine/fehlende Verbindungen)`,
nodeId: node.id,
severity: 'warning'
})
}
})
}
/**
* Logische Validierung (Node-Konfiguration)
*/
function validateLogic(nodes, edges, errors, warnings) {
nodes.forEach(node => {
// Analysis Nodes
if (node.type === 'analysis') {
const questions = node.data.questions || []
// Prompt ausgewählt?
if (!node.data.prompt_id) {
errors.push({
type: 'config',
message: `Analysis-Node "${node.data.label}" hat keinen Prompt`,
nodeId: node.id,
severity: 'error'
})
}
// Fragen validieren
questions.forEach((q, idx) => {
if (!q.question?.trim()) {
errors.push({
type: 'config',
message: `Frage ${idx + 1} in "${node.data.label}" hat keinen Text`,
nodeId: node.id,
severity: 'error'
})
}
if (!q.answer_spectrum || q.answer_spectrum.length < 2) {
errors.push({
type: 'config',
message: `Frage ${idx + 1} in "${node.data.label}" braucht mind. 2 Antworten`,
nodeId: node.id,
severity: 'error'
})
}
})
}
// Logic Nodes
if (node.type === 'logic') {
const condition = node.data.condition
if (!condition || !condition.operator) {
errors.push({
type: 'config',
message: `Logic-Node "${node.data.label}" hat keine Bedingung`,
nodeId: node.id,
severity: 'error'
})
} else {
// Bedingung vollständig?
const incomplete = findIncompleteConditions(condition)
if (incomplete.length > 0) {
errors.push({
type: 'config',
message: `Logic-Node "${node.data.label}" hat ${incomplete.length} unvollständige Bedingung(en)`,
nodeId: node.id,
severity: 'error'
})
}
}
// Mind. 2 Outgoing Edges (true/false Pfade)
const outgoing = edges.filter(e => e.source === node.id)
if (outgoing.length < 2) {
warnings.push({
type: 'config',
message: `Logic-Node "${node.data.label}" hat nur ${outgoing.length} Ausgang (sollte mind. 2 haben)`,
nodeId: node.id,
severity: 'warning'
})
}
}
// Join Nodes
if (node.type === 'join') {
const incoming = edges.filter(e => e.target === node.id)
if (incoming.length < 2) {
warnings.push({
type: 'config',
message: `Join-Node "${node.data.label}" hat nur ${incoming.length} eingehende Kante (sollte mind. 2 haben)`,
nodeId: node.id,
severity: 'warning'
})
}
}
})
}
/**
* Zyklen-Erkennung (DFS-basiert)
*/
function detectCycles(nodes, edges) {
const visited = new Set()
const recStack = new Set()
function dfs(nodeId) {
visited.add(nodeId)
recStack.add(nodeId)
const outgoing = edges.filter(e => e.source === nodeId)
for (const edge of outgoing) {
if (!visited.has(edge.target)) {
if (dfs(edge.target)) return true
} else if (recStack.has(edge.target)) {
return true // Cycle detected
}
}
recStack.delete(nodeId)
return false
}
for (const node of nodes) {
if (!visited.has(node.id)) {
if (dfs(node.id)) return true
}
}
return false
}
/**
* Unvollständige Bedingungen finden (rekursiv)
*/
function findIncompleteConditions(condition) {
const incomplete = []
// Verschachtelte Gruppe?
if (condition.operands && Array.isArray(condition.operands)) {
for (const op of condition.operands) {
incomplete.push(...findIncompleteConditions(op))
}
} else {
// Einfache Bedingung: ref, operator, value müssen gesetzt sein
if (!condition.ref || !condition.operator || condition.value === undefined || condition.value === '') {
incomplete.push(condition)
}
}
return incomplete
}