"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AIWorkflowBuilder = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
/**
 * AI Workflow Builder - Visual workflow creation and automation component
 * Features: Drag-and-drop workflow design, AI agent integration, execution monitoring
 */
const react_1 = require("react");
const useAIConversation_1 = require("../../hooks/useAIConversation");
const useRealtimeCollaboration_1 = require("../../hooks/useRealtimeCollaboration");
// Default node templates
const NODE_TEMPLATES = [
    {
        type: 'trigger',
        data: {
            title: 'Manual Trigger',
            description: 'Start workflow manually',
            config: {},
            inputs: [],
            outputs: [{ id: 'trigger', name: 'Trigger Output', type: 'object' }]
        }
    },
    {
        type: 'ai-agent',
        data: {
            title: 'AI Agent',
            description: 'Execute AI-powered task',
            config: { temperature: 0.7, maxTokens: 1000 },
            inputs: [
                { id: 'prompt', name: 'Prompt', type: 'string', required: true },
                { id: 'context', name: 'Context', type: 'object', required: false }
            ],
            outputs: [
                { id: 'response', name: 'AI Response', type: 'string' },
                { id: 'metadata', name: 'Metadata', type: 'object' }
            ],
            aiPrompt: 'You are a helpful AI assistant. Process the input and provide a useful response.',
            model: 'gpt-4',
            provider: 'openai'
        }
    },
    {
        type: 'condition',
        data: {
            title: 'Condition',
            description: 'Branch workflow based on condition',
            config: {},
            inputs: [{ id: 'value', name: 'Input Value', type: 'string', required: true }],
            outputs: [
                { id: 'true', name: 'True Branch', type: 'object' },
                { id: 'false', name: 'False Branch', type: 'object' }
            ]
        }
    },
    {
        type: 'data-transform',
        data: {
            title: 'Data Transform',
            description: 'Transform or manipulate data',
            config: { transformation: 'identity' },
            inputs: [{ id: 'input', name: 'Input Data', type: 'object', required: true }],
            outputs: [{ id: 'output', name: 'Transformed Data', type: 'object' }]
        }
    },
    {
        type: 'delay',
        data: {
            title: 'Delay',
            description: 'Wait for specified duration',
            config: { duration: 1000 },
            inputs: [{ id: 'trigger', name: 'Trigger', type: 'object', required: true }],
            outputs: [{ id: 'output', name: 'Output', type: 'object' }]
        }
    },
    {
        type: 'webhook',
        data: {
            title: 'Webhook',
            description: 'Send HTTP request',
            config: { method: 'POST', url: '' },
            inputs: [
                { id: 'url', name: 'URL', type: 'string', required: true },
                { id: 'data', name: 'Request Data', type: 'object', required: false }
            ],
            outputs: [
                { id: 'response', name: 'Response', type: 'object' },
                { id: 'status', name: 'Status Code', type: 'number' }
            ]
        }
    }
];
const AIWorkflowBuilder = ({ workflowId, initialWorkflow, onWorkflowChanged, onExecutionStarted, onExecutionCompleted, enableCollaboration = true, enableAIAssistant = true, width = 1200, height = 800, className = '', style = {} }) => {
    // Workflow state
    const [workflow, setWorkflow] = (0, react_1.useState)({
        id: workflowId || `workflow-${Date.now()}`,
        name: initialWorkflow?.name || 'New Workflow',
        description: initialWorkflow?.description || '',
        nodes: initialWorkflow?.nodes || [],
        connections: initialWorkflow?.connections || [],
        triggers: initialWorkflow?.triggers || [{ type: 'manual', config: {} }],
        variables: initialWorkflow?.variables || [],
        status: initialWorkflow?.status || 'draft',
        metadata: {
            createdAt: new Date(),
            updatedAt: new Date(),
            version: 1,
            executionCount: 0,
            successRate: 1,
            ...initialWorkflow?.metadata
        }
    });
    const [selectedNode, setSelectedNode] = (0, react_1.useState)(null);
    const [selectedConnection, setSelectedConnection] = (0, react_1.useState)(null);
    const [isDragging, setIsDragging] = (0, react_1.useState)(false);
    const [dragOffset, setDragOffset] = (0, react_1.useState)({ x: 0, y: 0 });
    const [isConnecting, setIsConnecting] = (0, react_1.useState)(false);
    const [connectionStart, setConnectionStart] = (0, react_1.useState)(null);
    const [showNodePanel, setShowNodePanel] = (0, react_1.useState)(false);
    const [currentExecution, setCurrentExecution] = (0, react_1.useState)(null);
    const [executionHistory, setExecutionHistory] = (0, react_1.useState)([]);
    // Refs
    const canvasRef = (0, react_1.useRef)(null);
    const svgRef = (0, react_1.useRef)(null);
    // AI Assistant for workflow optimization
    const aiAssistant = (0, useAIConversation_1.useAIConversation)({
        conversationId: `workflow-assistant-${workflow.id}`,
        provider: 'auto',
        model: 'auto'
    });
    // Collaboration
    const collaboration = (0, useRealtimeCollaboration_1.useRealtimeCollaboration)({
        enabled: enableCollaboration,
        conversationId: workflow.id,
        onEventReceived: handleCollaborationEvent
    });
    // Handle collaboration events
    function handleCollaborationEvent(event) {
        switch (event.type) {
            case 'workflow-node-added':
                addNode(event.data.node, false);
                break;
            case 'workflow-node-updated':
                updateNode(event.data.node, false);
                break;
            case 'workflow-node-deleted':
                deleteNode(event.data.nodeId, false);
                break;
            case 'workflow-connection-added':
                addConnection(event.data.connection, false);
                break;
            case 'workflow-connection-deleted':
                deleteConnection(event.data.connectionId, false);
                break;
        }
    }
    // Add node to workflow
    const addNode = (0, react_1.useCallback)((node, broadcast = true) => {
        const newNode = {
            ...node,
            id: node.id || `node-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
            status: 'idle',
            metadata: {
                createdAt: new Date(),
                updatedAt: new Date(),
                executionCount: 0,
                ...node.metadata
            }
        };
        setWorkflow(prev => {
            const updated = {
                ...prev,
                nodes: [...prev.nodes, newNode],
                metadata: {
                    ...prev.metadata,
                    updatedAt: new Date(),
                    version: prev.metadata.version + 1
                }
            };
            onWorkflowChanged?.(updated);
            return updated;
        });
        if (broadcast && enableCollaboration) {
            collaboration.broadcastEvent({
                type: 'workflow-node-added',
                data: { node: newNode }
            });
        }
    }, [onWorkflowChanged, enableCollaboration, collaboration]);
    // Update node
    const updateNode = (0, react_1.useCallback)((updatedNode, broadcast = true) => {
        setWorkflow(prev => {
            const updated = {
                ...prev,
                nodes: prev.nodes.map(node => node.id === updatedNode.id ? { ...updatedNode, metadata: { ...updatedNode.metadata, updatedAt: new Date() } } : node),
                metadata: {
                    ...prev.metadata,
                    updatedAt: new Date(),
                    version: prev.metadata.version + 1
                }
            };
            onWorkflowChanged?.(updated);
            return updated;
        });
        if (broadcast && enableCollaboration) {
            collaboration.broadcastEvent({
                type: 'workflow-node-updated',
                data: { node: updatedNode }
            });
        }
    }, [onWorkflowChanged, enableCollaboration, collaboration]);
    // Delete node
    const deleteNode = (0, react_1.useCallback)((nodeId, broadcast = true) => {
        setWorkflow(prev => {
            const updated = {
                ...prev,
                nodes: prev.nodes.filter(node => node.id !== nodeId),
                connections: prev.connections.filter(conn => conn.sourceNodeId !== nodeId && conn.targetNodeId !== nodeId),
                metadata: {
                    ...prev.metadata,
                    updatedAt: new Date(),
                    version: prev.metadata.version + 1
                }
            };
            onWorkflowChanged?.(updated);
            return updated;
        });
        if (broadcast && enableCollaboration) {
            collaboration.broadcastEvent({
                type: 'workflow-node-deleted',
                data: { nodeId }
            });
        }
    }, [onWorkflowChanged, enableCollaboration, collaboration]);
    // Add connection
    const addConnection = (0, react_1.useCallback)((connection, broadcast = true) => {
        const newConnection = {
            ...connection,
            id: connection.id || `conn-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`
        };
        setWorkflow(prev => {
            const updated = {
                ...prev,
                connections: [...prev.connections, newConnection],
                metadata: {
                    ...prev.metadata,
                    updatedAt: new Date(),
                    version: prev.metadata.version + 1
                }
            };
            onWorkflowChanged?.(updated);
            return updated;
        });
        if (broadcast && enableCollaboration) {
            collaboration.broadcastEvent({
                type: 'workflow-connection-added',
                data: { connection: newConnection }
            });
        }
    }, [onWorkflowChanged, enableCollaboration, collaboration]);
    // Delete connection
    const deleteConnection = (0, react_1.useCallback)((connectionId, broadcast = true) => {
        setWorkflow(prev => {
            const updated = {
                ...prev,
                connections: prev.connections.filter(conn => conn.id !== connectionId),
                metadata: {
                    ...prev.metadata,
                    updatedAt: new Date(),
                    version: prev.metadata.version + 1
                }
            };
            onWorkflowChanged?.(updated);
            return updated;
        });
        if (broadcast && enableCollaboration) {
            collaboration.broadcastEvent({
                type: 'workflow-connection-deleted',
                data: { connectionId }
            });
        }
    }, [onWorkflowChanged, enableCollaboration, collaboration]);
    // Execute workflow
    const executeWorkflow = (0, react_1.useCallback)(async () => {
        const execution = {
            id: `exec-${Date.now()}`,
            workflowId: workflow.id,
            status: 'running',
            startedAt: new Date(),
            nodeExecutions: [],
            triggeredBy: collaboration.currentUser?.id || 'manual'
        };
        setCurrentExecution(execution);
        onExecutionStarted?.(execution);
        try {
            // Execute nodes in topological order
            const executionOrder = getExecutionOrder(workflow.nodes, workflow.connections);
            for (const nodeId of executionOrder) {
                const node = workflow.nodes.find(n => n.id === nodeId);
                if (!node)
                    continue;
                const nodeExecution = {
                    nodeId,
                    status: 'running',
                    startedAt: new Date(),
                    input: {}, // Would gather actual input from previous nodes
                };
                execution.nodeExecutions.push(nodeExecution);
                // Update node status
                updateNode({ ...node, status: 'running' }, false);
                try {
                    // Simulate node execution
                    const result = await executeNode(node, {});
                    nodeExecution.status = 'completed';
                    nodeExecution.completedAt = new Date();
                    nodeExecution.output = result;
                    nodeExecution.duration = nodeExecution.completedAt.getTime() - nodeExecution.startedAt.getTime();
                    updateNode({ ...node, status: 'completed' }, false);
                }
                catch (error) {
                    nodeExecution.status = 'failed';
                    nodeExecution.completedAt = new Date();
                    nodeExecution.error = error instanceof Error ? error.message : 'Unknown error';
                    updateNode({ ...node, status: 'failed' }, false);
                    throw error;
                }
            }
            execution.status = 'completed';
            execution.completedAt = new Date();
            execution.totalDuration = execution.completedAt.getTime() - execution.startedAt.getTime();
        }
        catch (error) {
            execution.status = 'failed';
            execution.completedAt = new Date();
            execution.error = error instanceof Error ? error.message : 'Workflow execution failed';
        }
        setExecutionHistory(prev => [execution, ...prev.slice(0, 9)]); // Keep last 10 executions
        setCurrentExecution(null);
        onExecutionCompleted?.(execution);
        // Reset node statuses
        workflow.nodes.forEach(node => {
            updateNode({ ...node, status: 'idle' }, false);
        });
    }, [workflow, collaboration.currentUser, onExecutionStarted, onExecutionCompleted, updateNode]);
    // Get execution order using topological sort
    const getExecutionOrder = (0, react_1.useCallback)((nodes, connections) => {
        const graph = new Map();
        const inDegree = new Map();
        // Initialize graph
        nodes.forEach(node => {
            graph.set(node.id, []);
            inDegree.set(node.id, 0);
        });
        // Build graph from connections
        connections.forEach(conn => {
            graph.get(conn.sourceNodeId)?.push(conn.targetNodeId);
            inDegree.set(conn.targetNodeId, (inDegree.get(conn.targetNodeId) || 0) + 1);
        });
        // Topological sort
        const queue = [];
        const result = [];
        // Find nodes with no incoming edges
        inDegree.forEach((degree, nodeId) => {
            if (degree === 0)
                queue.push(nodeId);
        });
        while (queue.length > 0) {
            const nodeId = queue.shift();
            result.push(nodeId);
            graph.get(nodeId)?.forEach(neighbor => {
                const newDegree = (inDegree.get(neighbor) || 0) - 1;
                inDegree.set(neighbor, newDegree);
                if (newDegree === 0)
                    queue.push(neighbor);
            });
        }
        return result;
    }, []);
    // Execute individual node
    const executeNode = (0, react_1.useCallback)(async (node, input) => {
        switch (node.type) {
            case 'trigger':
                return { triggered: true, timestamp: new Date() };
            case 'ai-agent':
                if (enableAIAssistant && node.data.aiPrompt) {
                    const response = await aiAssistant.sendMessage({
                        role: 'user',
                        content: node.data.aiPrompt,
                        metadata: { nodeId: node.id, input }
                    });
                    return { response: response.content, metadata: { nodeId: node.id } };
                }
                return { response: 'AI agent response simulated', metadata: {} };
            case 'condition':
                // Simplified condition evaluation
                const conditionValue = input?.value || false;
                return { result: Boolean(conditionValue), value: conditionValue };
            case 'data-transform':
                // Simplified data transformation
                return { ...input, transformed: true, timestamp: new Date() };
            case 'delay':
                const duration = node.data.config.duration || 1000;
                await new Promise(resolve => setTimeout(resolve, duration));
                return { delayed: true, duration };
            case 'webhook':
                // Simulate webhook call
                return {
                    status: 200,
                    response: { success: true, url: node.data.config.url },
                    timestamp: new Date()
                };
            default:
                return { success: true };
        }
    }, [enableAIAssistant, aiAssistant]);
    // Handle drag and drop for nodes
    const handleNodeDrop = (0, react_1.useCallback)((e, template) => {
        e.preventDefault();
        const rect = canvasRef.current?.getBoundingClientRect();
        if (!rect)
            return;
        const position = {
            x: e.clientX - rect.left - 75, // Center the node
            y: e.clientY - rect.top - 40
        };
        const newNode = {
            id: `node-${Date.now()}`,
            position,
            status: 'idle',
            metadata: {
                createdAt: new Date(),
                updatedAt: new Date(),
                executionCount: 0
            },
            ...template
        };
        addNode(newNode);
    }, [addNode]);
    // Render workflow connections
    const renderConnections = (0, react_1.useMemo)(() => {
        return workflow.connections.map(connection => {
            const sourceNode = workflow.nodes.find(n => n.id === connection.sourceNodeId);
            const targetNode = workflow.nodes.find(n => n.id === connection.targetNodeId);
            if (!sourceNode || !targetNode)
                return null;
            const startX = sourceNode.position.x + 150;
            const startY = sourceNode.position.y + 40;
            const endX = targetNode.position.x;
            const endY = targetNode.position.y + 40;
            const midX = (startX + endX) / 2;
            return ((0, jsx_runtime_1.jsxs)("g", { children: [(0, jsx_runtime_1.jsx)("path", { d: `M ${startX} ${startY} C ${midX} ${startY} ${midX} ${endY} ${endX} ${endY}`, stroke: selectedConnection === connection.id ? '#007bff' : '#666', strokeWidth: "2", fill: "none", markerEnd: "url(#arrowhead)", onClick: () => setSelectedConnection(connection.id), style: { cursor: 'pointer' } }), connection.condition && ((0, jsx_runtime_1.jsx)("circle", { cx: midX, cy: (startY + endY) / 2, r: "8", fill: "#ffc107", stroke: "#fff", strokeWidth: "2" }))] }, connection.id));
        });
    }, [workflow.connections, workflow.nodes, selectedConnection]);
    return ((0, jsx_runtime_1.jsxs)("div", { className: `ai-workflow-builder ${className}`, style: { width, height, ...style }, children: [(0, jsx_runtime_1.jsxs)("div", { className: "workflow-toolbar", children: [(0, jsx_runtime_1.jsxs)("div", { className: "toolbar-section", children: [(0, jsx_runtime_1.jsx)("button", { onClick: () => setShowNodePanel(!showNodePanel), children: "\uD83E\uDDE9 Add Node" }), (0, jsx_runtime_1.jsx)("button", { onClick: executeWorkflow, disabled: currentExecution !== null, children: currentExecution ? '⏸️ Running...' : '▶️ Execute' }), (0, jsx_runtime_1.jsx)("button", { onClick: () => setWorkflow(prev => ({ ...prev, status: prev.status === 'active' ? 'paused' : 'active' })), children: workflow.status === 'active' ? '⏸️ Pause' : '▶️ Activate' })] }), (0, jsx_runtime_1.jsxs)("div", { className: "toolbar-section", children: [(0, jsx_runtime_1.jsx)("span", { className: `status-indicator status-indicator--${workflow.status}`, children: workflow.status.charAt(0).toUpperCase() + workflow.status.slice(1) }), (0, jsx_runtime_1.jsxs)("span", { children: ["Nodes: ", workflow.nodes.length] }), (0, jsx_runtime_1.jsxs)("span", { children: ["Connections: ", workflow.connections.length] }), enableCollaboration && ((0, jsx_runtime_1.jsxs)("span", { children: ["Users: ", collaboration.collaborators.length] }))] })] }), (0, jsx_runtime_1.jsxs)("div", { className: "workflow-main", children: [showNodePanel && ((0, jsx_runtime_1.jsxs)("div", { className: "node-palette", children: [(0, jsx_runtime_1.jsxs)("div", { className: "palette-header", children: [(0, jsx_runtime_1.jsx)("h3", { children: "Node Types" }), (0, jsx_runtime_1.jsx)("button", { onClick: () => setShowNodePanel(false), children: "\u00D7" })] }), (0, jsx_runtime_1.jsx)("div", { className: "palette-nodes", children: NODE_TEMPLATES.map((template, index) => ((0, jsx_runtime_1.jsxs)("div", { className: `palette-node palette-node--${template.type}`, draggable: true, onDragStart: (e) => {
                                        e.dataTransfer.setData('application/json', JSON.stringify(template));
                                    }, children: [(0, jsx_runtime_1.jsxs)("div", { className: "node-icon", children: [template.type === 'trigger' && '⚡', template.type === 'ai-agent' && '🤖', template.type === 'condition' && '❓', template.type === 'data-transform' && '🔄', template.type === 'delay' && '⏰', template.type === 'webhook' && '🌐'] }), (0, jsx_runtime_1.jsx)("div", { className: "node-label", children: template.data?.title })] }, index))) })] })), (0, jsx_runtime_1.jsxs)("div", { ref: canvasRef, className: "workflow-canvas", onDrop: (e) => {
                            const template = JSON.parse(e.dataTransfer.getData('application/json'));
                            handleNodeDrop(e, template);
                        }, onDragOver: (e) => e.preventDefault(), children: [(0, jsx_runtime_1.jsxs)("svg", { ref: svgRef, width: "100%", height: "100%", className: "workflow-svg", children: [(0, jsx_runtime_1.jsx)("defs", { children: (0, jsx_runtime_1.jsx)("marker", { id: "arrowhead", markerWidth: "10", markerHeight: "7", refX: "9", refY: "3.5", orient: "auto", children: (0, jsx_runtime_1.jsx)("polygon", { points: "0 0, 10 3.5, 0 7", fill: "#666" }) }) }), renderConnections] }), workflow.nodes.map(node => ((0, jsx_runtime_1.jsxs)("div", { className: `workflow-node workflow-node--${node.type} workflow-node--${node.status} ${selectedNode === node.id ? 'workflow-node--selected' : ''}`, style: {
                                    position: 'absolute',
                                    left: node.position.x,
                                    top: node.position.y,
                                    width: 150,
                                    height: 80
                                }, onClick: () => setSelectedNode(node.id), onMouseDown: (e) => {
                                    setIsDragging(true);
                                    setDragOffset({
                                        x: e.clientX - node.position.x,
                                        y: e.clientY - node.position.y
                                    });
                                }, children: [(0, jsx_runtime_1.jsxs)("div", { className: "node-header", children: [(0, jsx_runtime_1.jsxs)("div", { className: "node-icon", children: [node.type === 'trigger' && '⚡', node.type === 'ai-agent' && '🤖', node.type === 'condition' && '❓', node.type === 'data-transform' && '🔄', node.type === 'delay' && '⏰', node.type === 'webhook' && '🌐'] }), (0, jsx_runtime_1.jsx)("div", { className: "node-title", children: node.data.title }), (0, jsx_runtime_1.jsxs)("div", { className: `node-status node-status--${node.status}`, children: [node.status === 'idle' && '○', node.status === 'running' && '🔄', node.status === 'completed' && '✅', node.status === 'failed' && '❌'] })] }), (0, jsx_runtime_1.jsx)("div", { className: "node-body", children: (0, jsx_runtime_1.jsx)("div", { className: "node-description", children: node.data.description }) }), (0, jsx_runtime_1.jsx)("div", { className: "node-inputs", children: node.data.inputs.map(input => ((0, jsx_runtime_1.jsx)("div", { className: "connection-point connection-point--input" }, input.id))) }), (0, jsx_runtime_1.jsx)("div", { className: "node-outputs", children: node.data.outputs.map(output => ((0, jsx_runtime_1.jsx)("div", { className: "connection-point connection-point--output", onClick: () => {
                                                if (connectionStart) {
                                                    // Complete connection
                                                    const newConnection = {
                                                        id: `conn-${Date.now()}`,
                                                        sourceNodeId: connectionStart.nodeId,
                                                        sourceOutputId: connectionStart.outputId,
                                                        targetNodeId: node.id,
                                                        targetInputId: node.data.inputs[0]?.id || 'default'
                                                    };
                                                    addConnection(newConnection);
                                                    setConnectionStart(null);
                                                    setIsConnecting(false);
                                                }
                                                else {
                                                    // Start connection
                                                    setConnectionStart({ nodeId: node.id, outputId: output.id });
                                                    setIsConnecting(true);
                                                }
                                            } }, output.id))) })] }, node.id))), enableCollaboration && collaboration.userCursors.map(cursor => ((0, jsx_runtime_1.jsxs)("div", { className: "user-cursor", style: {
                                    position: 'absolute',
                                    left: cursor.x,
                                    top: cursor.y,
                                    pointerEvents: 'none',
                                    zIndex: 1000
                                }, children: [(0, jsx_runtime_1.jsx)("div", { style: {
                                            width: 12,
                                            height: 12,
                                            backgroundColor: cursor.color,
                                            borderRadius: '50%',
                                            border: '2px solid white'
                                        } }), (0, jsx_runtime_1.jsx)("div", { style: {
                                            position: 'absolute',
                                            top: 16,
                                            left: 0,
                                            padding: '2px 6px',
                                            backgroundColor: cursor.color,
                                            color: 'white',
                                            fontSize: '12px',
                                            borderRadius: '4px',
                                            whiteSpace: 'nowrap'
                                        }, children: cursor.userName })] }, cursor.userId)))] })] }), selectedNode && ((0, jsx_runtime_1.jsx)("div", { className: "workflow-properties", children: (() => {
                    const node = workflow.nodes.find(n => n.id === selectedNode);
                    if (!node)
                        return null;
                    return ((0, jsx_runtime_1.jsxs)("div", { className: "properties-panel", children: [(0, jsx_runtime_1.jsxs)("div", { className: "properties-header", children: [(0, jsx_runtime_1.jsx)("h3", { children: "Node Properties" }), (0, jsx_runtime_1.jsx)("button", { onClick: () => setSelectedNode(null), children: "\u00D7" })] }), (0, jsx_runtime_1.jsxs)("div", { className: "properties-content", children: [(0, jsx_runtime_1.jsxs)("div", { className: "property-group", children: [(0, jsx_runtime_1.jsx)("label", { children: "Title" }), (0, jsx_runtime_1.jsx)("input", { type: "text", value: node.data.title, onChange: (e) => {
                                                    updateNode({
                                                        ...node,
                                                        data: { ...node.data, title: e.target.value }
                                                    });
                                                } })] }), (0, jsx_runtime_1.jsxs)("div", { className: "property-group", children: [(0, jsx_runtime_1.jsx)("label", { children: "Description" }), (0, jsx_runtime_1.jsx)("textarea", { value: node.data.description, onChange: (e) => {
                                                    updateNode({
                                                        ...node,
                                                        data: { ...node.data, description: e.target.value }
                                                    });
                                                } })] }), node.type === 'ai-agent' && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)("div", { className: "property-group", children: [(0, jsx_runtime_1.jsx)("label", { children: "AI Prompt" }), (0, jsx_runtime_1.jsx)("textarea", { value: node.data.aiPrompt || '', onChange: (e) => {
                                                            updateNode({
                                                                ...node,
                                                                data: { ...node.data, aiPrompt: e.target.value }
                                                            });
                                                        }, rows: 4 })] }), (0, jsx_runtime_1.jsxs)("div", { className: "property-group", children: [(0, jsx_runtime_1.jsx)("label", { children: "Model" }), (0, jsx_runtime_1.jsxs)("select", { value: node.data.model || 'gpt-4', onChange: (e) => {
                                                            updateNode({
                                                                ...node,
                                                                data: { ...node.data, model: e.target.value }
                                                            });
                                                        }, children: [(0, jsx_runtime_1.jsx)("option", { value: "gpt-4", children: "GPT-4" }), (0, jsx_runtime_1.jsx)("option", { value: "gpt-3.5-turbo", children: "GPT-3.5 Turbo" }), (0, jsx_runtime_1.jsx)("option", { value: "claude-3", children: "Claude 3" }), (0, jsx_runtime_1.jsx)("option", { value: "gemini-pro", children: "Gemini Pro" })] })] })] })), (0, jsx_runtime_1.jsx)("div", { className: "property-actions", children: (0, jsx_runtime_1.jsx)("button", { onClick: () => deleteNode(node.id), className: "button-danger", children: "Delete Node" }) })] })] }));
                })() })), currentExecution && ((0, jsx_runtime_1.jsxs)("div", { className: "execution-monitor", children: [(0, jsx_runtime_1.jsxs)("div", { className: "monitor-header", children: [(0, jsx_runtime_1.jsx)("h3", { children: "Execution Monitor" }), (0, jsx_runtime_1.jsxs)("div", { className: "execution-progress", children: [currentExecution.nodeExecutions.filter(ne => ne.status === 'completed').length, " / ", workflow.nodes.length] })] }), (0, jsx_runtime_1.jsx)("div", { className: "monitor-content", children: currentExecution.nodeExecutions.map(nodeExec => {
                            const node = workflow.nodes.find(n => n.id === nodeExec.nodeId);
                            return ((0, jsx_runtime_1.jsxs)("div", { className: `execution-item execution-item--${nodeExec.status}`, children: [(0, jsx_runtime_1.jsx)("div", { className: "execution-node", children: node?.data.title }), (0, jsx_runtime_1.jsx)("div", { className: "execution-status", children: nodeExec.status }), nodeExec.duration && ((0, jsx_runtime_1.jsxs)("div", { className: "execution-duration", children: [nodeExec.duration, "ms"] }))] }, nodeExec.nodeId));
                        }) })] }))] }));
};
exports.AIWorkflowBuilder = AIWorkflowBuilder;
exports.default = exports.AIWorkflowBuilder;
//# sourceMappingURL=AIWorkflowBuilder.js.map