@marktoflow/gui 2.0.0-alpha.12 → 2.0.0-alpha.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/package.json +1 -3
  2. package/.marktoflow/state/workflow-state.db +0 -0
  3. package/.marktoflow/state/workflow-state.db-shm +0 -0
  4. package/.marktoflow/state/workflow-state.db-wal +0 -0
  5. package/.turbo/turbo-build.log +0 -42
  6. package/.turbo/turbo-test.log +0 -38
  7. package/marktoflow-gui-2.0.0-alpha.12.tgz +0 -0
  8. package/playwright.config.ts +0 -27
  9. package/postcss.config.js +0 -6
  10. package/src/client/App.tsx +0 -520
  11. package/src/client/components/Canvas/Canvas.tsx +0 -425
  12. package/src/client/components/Canvas/ExecutionOverlay.tsx +0 -935
  13. package/src/client/components/Canvas/ForEachNode.tsx +0 -152
  14. package/src/client/components/Canvas/IfElseNode.tsx +0 -141
  15. package/src/client/components/Canvas/NodeContextMenu.tsx +0 -192
  16. package/src/client/components/Canvas/OutputNode.tsx +0 -111
  17. package/src/client/components/Canvas/ParallelNode.tsx +0 -157
  18. package/src/client/components/Canvas/StepNode.tsx +0 -106
  19. package/src/client/components/Canvas/SubWorkflowNode.tsx +0 -141
  20. package/src/client/components/Canvas/SwitchNode.tsx +0 -185
  21. package/src/client/components/Canvas/Toolbar.tsx +0 -227
  22. package/src/client/components/Canvas/TransformNode.tsx +0 -194
  23. package/src/client/components/Canvas/TriggerNode.tsx +0 -128
  24. package/src/client/components/Canvas/TryCatchNode.tsx +0 -164
  25. package/src/client/components/Canvas/WhileNode.tsx +0 -161
  26. package/src/client/components/Canvas/index.ts +0 -24
  27. package/src/client/components/Debug/VariableInspector.tsx +0 -148
  28. package/src/client/components/Editor/InputsEditor.tsx +0 -458
  29. package/src/client/components/Editor/NewStepWizard.tsx +0 -344
  30. package/src/client/components/Editor/StepEditor.tsx +0 -532
  31. package/src/client/components/Editor/YamlEditor.tsx +0 -160
  32. package/src/client/components/Panels/PropertiesPanel.tsx +0 -589
  33. package/src/client/components/Prompt/ChangePreview.tsx +0 -281
  34. package/src/client/components/Prompt/PromptHistoryPanel.tsx +0 -209
  35. package/src/client/components/Prompt/PromptInput.tsx +0 -110
  36. package/src/client/components/Settings/ProviderSwitcher.tsx +0 -228
  37. package/src/client/components/Sidebar/ImportDialog.tsx +0 -257
  38. package/src/client/components/Sidebar/Sidebar.tsx +0 -362
  39. package/src/client/components/common/Breadcrumb.tsx +0 -40
  40. package/src/client/components/common/Button.tsx +0 -68
  41. package/src/client/components/common/ContextMenu.tsx +0 -202
  42. package/src/client/components/common/KeyboardShortcuts.tsx +0 -149
  43. package/src/client/components/common/Modal.tsx +0 -93
  44. package/src/client/components/common/Tabs.tsx +0 -57
  45. package/src/client/components/common/ThemeToggle.tsx +0 -63
  46. package/src/client/components/index.ts +0 -32
  47. package/src/client/hooks/index.ts +0 -4
  48. package/src/client/hooks/useAIPrompt.ts +0 -108
  49. package/src/client/hooks/useCanvas.ts +0 -247
  50. package/src/client/hooks/useWebSocket.ts +0 -164
  51. package/src/client/hooks/useWorkflow.ts +0 -138
  52. package/src/client/main.tsx +0 -10
  53. package/src/client/stores/agentStore.ts +0 -109
  54. package/src/client/stores/canvasStore.ts +0 -348
  55. package/src/client/stores/editorStore.ts +0 -133
  56. package/src/client/stores/executionStore.ts +0 -502
  57. package/src/client/stores/index.ts +0 -4
  58. package/src/client/stores/layoutStore.ts +0 -103
  59. package/src/client/stores/navigationStore.ts +0 -49
  60. package/src/client/stores/promptStore.ts +0 -113
  61. package/src/client/stores/themeStore.ts +0 -75
  62. package/src/client/stores/workflowStore.ts +0 -185
  63. package/src/client/styles/globals.css +0 -452
  64. package/src/client/utils/cn.ts +0 -9
  65. package/src/client/utils/index.ts +0 -4
  66. package/src/client/utils/platform.ts +0 -46
  67. package/src/client/utils/serviceIcons.tsx +0 -97
  68. package/src/client/utils/stepValidation.ts +0 -155
  69. package/src/client/utils/workflowToGraph.ts +0 -523
  70. package/src/server/index.ts +0 -137
  71. package/src/server/routes/ai.ts +0 -91
  72. package/src/server/routes/execute.ts +0 -71
  73. package/src/server/routes/executions.ts +0 -136
  74. package/src/server/routes/tools.ts +0 -970
  75. package/src/server/routes/workflows.ts +0 -147
  76. package/src/server/services/AIService.ts +0 -105
  77. package/src/server/services/FileWatcher.ts +0 -69
  78. package/src/server/services/WorkflowService.ts +0 -601
  79. package/src/server/services/agents/claude-code-provider.ts +0 -320
  80. package/src/server/services/agents/claude-provider.ts +0 -248
  81. package/src/server/services/agents/codex-provider.ts +0 -398
  82. package/src/server/services/agents/copilot-provider.ts +0 -311
  83. package/src/server/services/agents/demo-provider.ts +0 -184
  84. package/src/server/services/agents/index.ts +0 -31
  85. package/src/server/services/agents/ollama-provider.ts +0 -267
  86. package/src/server/services/agents/prompts.ts +0 -509
  87. package/src/server/services/agents/registry.ts +0 -310
  88. package/src/server/services/agents/types.ts +0 -146
  89. package/src/server/websocket/index.ts +0 -117
  90. package/src/shared/constants.ts +0 -180
  91. package/src/shared/types.ts +0 -179
  92. package/tailwind.config.ts +0 -73
  93. package/tests/e2e/app.spec.ts +0 -90
  94. package/tests/e2e/canvas.spec.ts +0 -128
  95. package/tests/e2e/workflow.spec.ts +0 -185
  96. package/tests/integration/api.test.ts +0 -452
  97. package/tests/integration/testApp.ts +0 -31
  98. package/tests/setup.ts +0 -72
  99. package/tests/unit/ForEachNode.test.tsx +0 -308
  100. package/tests/unit/IfElseNode.test.tsx +0 -235
  101. package/tests/unit/ParallelNode.test.tsx +0 -344
  102. package/tests/unit/SwitchNode.test.tsx +0 -327
  103. package/tests/unit/TransformNode.test.tsx +0 -386
  104. package/tests/unit/TryCatchNode.test.tsx +0 -243
  105. package/tests/unit/WhileNode.test.tsx +0 -230
  106. package/tests/unit/agentStore.test.ts +0 -218
  107. package/tests/unit/canvasStore.test.ts +0 -502
  108. package/tests/unit/codexProvider.test.ts +0 -399
  109. package/tests/unit/components.test.tsx +0 -151
  110. package/tests/unit/executionStore.test.ts +0 -567
  111. package/tests/unit/layoutStore.test.ts +0 -194
  112. package/tests/unit/navigationStore.test.ts +0 -152
  113. package/tests/unit/platform.test.ts +0 -118
  114. package/tests/unit/serviceIcons.test.ts +0 -197
  115. package/tests/unit/stepValidation.test.ts +0 -226
  116. package/tests/unit/themeStore.test.ts +0 -141
  117. package/tests/unit/workflowToGraph.test.ts +0 -311
  118. package/tsconfig.json +0 -29
  119. package/tsconfig.server.json +0 -28
  120. package/vite.config.ts +0 -31
  121. package/vitest.config.ts +0 -26
@@ -1,157 +0,0 @@
1
- import { memo } from 'react';
2
- import { Handle, Position, type Node, type NodeProps } from '@xyflow/react';
3
- import { Layers, CheckCircle, XCircle, Clock, AlertTriangle } from 'lucide-react';
4
-
5
- export interface ParallelNodeData extends Record<string, unknown> {
6
- id: string;
7
- name?: string;
8
- branches: Array<{ id: string; name?: string }>;
9
- maxConcurrent?: number;
10
- onError?: 'stop' | 'continue';
11
- status?: 'pending' | 'running' | 'completed' | 'failed' | 'skipped';
12
- activeBranches?: string[];
13
- completedBranches?: string[];
14
- failedBranches?: string[];
15
- maxConcurrentExceeded?: boolean;
16
- }
17
-
18
- export type ParallelNodeType = Node<ParallelNodeData, 'parallel'>;
19
-
20
- function ParallelNodeComponent({ data, selected }: NodeProps<ParallelNodeType>) {
21
- const statusConfig: Record<
22
- NonNullable<ParallelNodeData['status']>,
23
- { icon: typeof Clock; color: string; bgColor: string; animate?: boolean }
24
- > = {
25
- pending: { icon: Clock, color: 'text-gray-400', bgColor: 'bg-gray-400/10' },
26
- running: {
27
- icon: Layers,
28
- color: 'text-green-400',
29
- bgColor: 'bg-green-400/10',
30
- animate: true,
31
- },
32
- completed: {
33
- icon: CheckCircle,
34
- color: 'text-success',
35
- bgColor: 'bg-success/10',
36
- },
37
- failed: { icon: XCircle, color: 'text-error', bgColor: 'bg-error/10' },
38
- skipped: {
39
- icon: XCircle,
40
- color: 'text-gray-500',
41
- bgColor: 'bg-gray-500/10',
42
- },
43
- };
44
-
45
- const status = data.status || 'pending';
46
- const config = statusConfig[status];
47
- const StatusIcon = config.icon;
48
-
49
- return (
50
- <div
51
- className={`control-flow-node parallel-node p-0 ${selected ? 'selected' : ''} ${status === 'running' ? 'running' : ''} ${status === 'completed' ? 'completed' : ''} ${status === 'failed' ? 'failed' : ''}`}
52
- style={{
53
- background: 'linear-gradient(135deg, #4facfe 0%, #00f2fe 100%)',
54
- }}
55
- >
56
- {/* Input handle */}
57
- <Handle
58
- type="target"
59
- position={Position.Top}
60
- className="!w-3 !h-3 !bg-primary !border-2 !border-node-bg"
61
- />
62
-
63
- {/* Node header */}
64
- <div className="flex items-center gap-3 p-3 border-b border-white/20">
65
- <div className="w-8 h-8 rounded-lg bg-white/20 flex items-center justify-center">
66
- <Layers className="w-5 h-5 text-white" />
67
- </div>
68
- <div className="flex-1 min-w-0">
69
- <div className="text-sm font-medium text-white">
70
- {data.name || 'Parallel'}
71
- </div>
72
- <div className="text-xs text-white/70">Concurrent Execution</div>
73
- </div>
74
- <div
75
- className={`w-6 h-6 rounded-full ${config.bgColor} flex items-center justify-center`}
76
- >
77
- <StatusIcon
78
- className={`w-4 h-4 ${config.color} ${config.animate ? 'animate-pulse' : ''}`}
79
- />
80
- </div>
81
- </div>
82
-
83
- {/* Node body */}
84
- <div className="p-3 bg-white/10">
85
- {/* Max concurrent warning */}
86
- {data.maxConcurrentExceeded && (
87
- <div className="mb-3 p-2 bg-yellow-500/20 border border-yellow-500/30 rounded flex items-center gap-2">
88
- <AlertTriangle className="w-4 h-4 text-yellow-200" />
89
- <span className="text-xs text-yellow-200 font-medium">
90
- Rate limiting active
91
- </span>
92
- </div>
93
- )}
94
-
95
- <div className="text-xs text-white/90 mb-3">
96
- <span className="text-white/60">Branches:</span>{' '}
97
- <span className="font-medium">{data.branches?.length || 0}</span>
98
- {data.maxConcurrent && (
99
- <>
100
- {' '}
101
- <span className="text-white/60">• Max Concurrent:</span>{' '}
102
- <span className={`font-medium ${data.maxConcurrentExceeded ? 'text-yellow-300' : ''}`}>
103
- {data.maxConcurrent}
104
- </span>
105
- </>
106
- )}
107
- </div>
108
-
109
- {/* Branch indicators */}
110
- <div className="flex flex-wrap gap-2 mb-3">
111
- {data.branches?.slice(0, 6).map((branch) => {
112
- const isActive = data.activeBranches?.includes(branch.id);
113
- const isCompleted = data.completedBranches?.includes(branch.id);
114
- const isFailed = data.failedBranches?.includes(branch.id);
115
- return (
116
- <div
117
- key={branch.id}
118
- className={`px-2 py-1 rounded text-xs font-medium transition-colors ${
119
- isFailed
120
- ? 'bg-red-500/30 text-red-200'
121
- : isCompleted
122
- ? 'bg-green-500/30 text-green-200'
123
- : isActive
124
- ? 'bg-blue-500/30 text-blue-200 animate-pulse'
125
- : 'bg-white/10 text-white/60'
126
- }`}
127
- title={branch.name || branch.id}
128
- >
129
- {branch.name || `B${branch.id.slice(-2)}`}
130
- </div>
131
- );
132
- })}
133
- {data.branches && data.branches.length > 6 && (
134
- <div className="px-2 py-1 rounded text-xs font-medium bg-white/10 text-white/60">
135
- +{data.branches.length - 6}
136
- </div>
137
- )}
138
- </div>
139
-
140
- {/* Error handling */}
141
- <div className="text-xs text-white/50 flex items-center gap-1">
142
- <span>On Error:</span>
143
- <span className="font-medium">{data.onError || 'stop'}</span>
144
- </div>
145
- </div>
146
-
147
- {/* Output handle */}
148
- <Handle
149
- type="source"
150
- position={Position.Bottom}
151
- className="!w-3 !h-3 !bg-primary !border-2 !border-node-bg"
152
- />
153
- </div>
154
- );
155
- }
156
-
157
- export const ParallelNode = memo(ParallelNodeComponent);
@@ -1,106 +0,0 @@
1
- import { memo } from 'react';
2
- import { Handle, Position, type Node, type NodeProps } from '@xyflow/react';
3
- import { Play, CheckCircle, XCircle, Clock, AlertCircle } from 'lucide-react';
4
- import { getServiceIcon } from '../../utils/serviceIcons';
5
-
6
- export interface StepNodeData extends Record<string, unknown> {
7
- id: string;
8
- name?: string;
9
- action: string;
10
- status?: 'pending' | 'running' | 'completed' | 'failed' | 'skipped';
11
- retryCount?: number;
12
- error?: string;
13
- }
14
-
15
- export type StepNodeType = Node<StepNodeData, 'step'>;
16
-
17
- function StepNodeComponent({ data, selected }: NodeProps<StepNodeType>) {
18
- const serviceName = data.action?.split('.')[0] || 'unknown';
19
- const methodName = data.action?.split('.').slice(1).join('.') || data.action;
20
- const ServiceIcon = getServiceIcon(serviceName);
21
-
22
- const statusConfig: Record<
23
- NonNullable<StepNodeData['status']>,
24
- { icon: typeof Clock; color: string; bgColor: string; animate?: boolean }
25
- > = {
26
- pending: { icon: Clock, color: 'text-gray-400', bgColor: 'bg-gray-400/10' },
27
- running: {
28
- icon: Play,
29
- color: 'text-warning',
30
- bgColor: 'bg-warning/10',
31
- animate: true,
32
- },
33
- completed: {
34
- icon: CheckCircle,
35
- color: 'text-success',
36
- bgColor: 'bg-success/10',
37
- },
38
- failed: { icon: XCircle, color: 'text-error', bgColor: 'bg-error/10' },
39
- skipped: {
40
- icon: AlertCircle,
41
- color: 'text-gray-500',
42
- bgColor: 'bg-gray-500/10',
43
- },
44
- };
45
-
46
- const status = data.status || 'pending';
47
- const config = statusConfig[status];
48
- const StatusIcon = config.icon;
49
-
50
- return (
51
- <div
52
- className={`step-node p-0 ${selected ? 'selected' : ''} ${status === 'running' ? 'running' : ''} ${status === 'completed' ? 'completed' : ''} ${status === 'failed' ? 'failed' : ''}`}
53
- >
54
- {/* Input handle */}
55
- <Handle
56
- type="target"
57
- position={Position.Top}
58
- className="!w-3 !h-3 !bg-primary !border-2 !border-node-bg"
59
- />
60
-
61
- {/* Node header */}
62
- <div className="flex items-center gap-3 p-3 border-b border-node-border">
63
- <div className="w-8 h-8 rounded-lg bg-primary/10 flex items-center justify-center">
64
- <ServiceIcon className="w-5 h-5 text-primary" />
65
- </div>
66
- <div className="flex-1 min-w-0">
67
- <div className="text-sm font-medium text-white truncate">
68
- {data.name || data.id}
69
- </div>
70
- <div className="text-xs text-gray-400 truncate">{serviceName}</div>
71
- </div>
72
- <div
73
- className={`w-6 h-6 rounded-full ${config.bgColor} flex items-center justify-center`}
74
- >
75
- <StatusIcon
76
- className={`w-4 h-4 ${config.color} ${config.animate ? 'animate-pulse' : ''}`}
77
- />
78
- </div>
79
- </div>
80
-
81
- {/* Node body */}
82
- <div className="p-3">
83
- <div className="text-xs text-gray-300 font-mono truncate">
84
- {methodName}
85
- </div>
86
- {data.retryCount && data.retryCount > 0 && (
87
- <div className="mt-2 text-xs text-warning">
88
- Retry #{data.retryCount}
89
- </div>
90
- )}
91
- {data.error && (
92
- <div className="mt-2 text-xs text-error truncate">{data.error}</div>
93
- )}
94
- </div>
95
-
96
- {/* Output handle */}
97
- <Handle
98
- type="source"
99
- position={Position.Bottom}
100
- className="!w-3 !h-3 !bg-primary !border-2 !border-node-bg"
101
- />
102
- </div>
103
- );
104
- }
105
-
106
- export const StepNode = memo(StepNodeComponent);
@@ -1,141 +0,0 @@
1
- import { memo, useState, useCallback } from 'react';
2
- import { Handle, Position, type Node, type NodeProps } from '@xyflow/react';
3
- import {
4
- FolderOpen,
5
- ChevronDown,
6
- ChevronRight,
7
- ExternalLink,
8
- ArrowRight,
9
- } from 'lucide-react';
10
- import { useNavigationStore } from '../../stores/navigationStore';
11
- import { useWorkflowStore } from '../../stores/workflowStore';
12
-
13
- export interface SubWorkflowNodeData extends Record<string, unknown> {
14
- id: string;
15
- name?: string;
16
- workflowPath: string;
17
- stepCount?: number;
18
- status?: 'pending' | 'running' | 'completed' | 'failed';
19
- }
20
-
21
- export type SubWorkflowNodeType = Node<SubWorkflowNodeData, 'subworkflow'>;
22
-
23
- function SubWorkflowNodeComponent({
24
- data,
25
- selected,
26
- }: NodeProps<SubWorkflowNodeType>) {
27
- const [expanded, setExpanded] = useState(false);
28
- const { pushWorkflow, breadcrumbs, setRootWorkflow } = useNavigationStore();
29
- const { loadWorkflow, selectedWorkflow, currentWorkflow } = useWorkflowStore();
30
-
31
- // Handle drilling down into sub-workflow
32
- const handleDrillDown = useCallback(() => {
33
- // If this is the first navigation, set the current workflow as root
34
- if (breadcrumbs.length === 0 && selectedWorkflow && currentWorkflow) {
35
- setRootWorkflow({
36
- id: selectedWorkflow,
37
- name: currentWorkflow.metadata?.name || 'Main Workflow',
38
- path: selectedWorkflow,
39
- });
40
- }
41
-
42
- // Push the sub-workflow onto the navigation stack
43
- pushWorkflow({
44
- id: data.id,
45
- name: data.name || data.id,
46
- path: data.workflowPath,
47
- });
48
-
49
- // Load the sub-workflow
50
- loadWorkflow(data.workflowPath);
51
- }, [data, pushWorkflow, breadcrumbs, setRootWorkflow, selectedWorkflow, currentWorkflow, loadWorkflow]);
52
-
53
- const statusColors = {
54
- pending: 'border-node-border',
55
- running: 'border-warning',
56
- completed: 'border-success',
57
- failed: 'border-error',
58
- };
59
-
60
- const status = data.status || 'pending';
61
-
62
- return (
63
- <div
64
- className={`step-node p-0 min-w-[250px] ${selected ? 'selected' : ''} ${statusColors[status]}`}
65
- >
66
- {/* Input handle */}
67
- <Handle
68
- type="target"
69
- position={Position.Top}
70
- className="!w-3 !h-3 !bg-info !border-2 !border-node-bg"
71
- />
72
-
73
- {/* Node header */}
74
- <div className="flex items-center gap-3 p-3 border-b border-node-border bg-info/5">
75
- <button
76
- onClick={() => setExpanded(!expanded)}
77
- className="w-6 h-6 rounded flex items-center justify-center hover:bg-white/10 transition-colors"
78
- >
79
- {expanded ? (
80
- <ChevronDown className="w-4 h-4 text-info" />
81
- ) : (
82
- <ChevronRight className="w-4 h-4 text-info" />
83
- )}
84
- </button>
85
- <div className="w-8 h-8 rounded-lg bg-info/10 flex items-center justify-center">
86
- <FolderOpen className="w-5 h-5 text-info" />
87
- </div>
88
- <div className="flex-1 min-w-0">
89
- <div className="text-sm font-medium text-white truncate">
90
- {data.name || data.id}
91
- </div>
92
- <div className="text-xs text-gray-400">Sub-workflow</div>
93
- </div>
94
- <button
95
- onClick={handleDrillDown}
96
- className="w-6 h-6 rounded flex items-center justify-center hover:bg-info/20 transition-colors"
97
- title="Drill into sub-workflow"
98
- >
99
- <ArrowRight className="w-4 h-4 text-info" />
100
- </button>
101
- </div>
102
-
103
- {/* Node body */}
104
- <div className="p-3">
105
- <div className="text-xs text-gray-400 font-mono truncate">
106
- {data.workflowPath}
107
- </div>
108
- {data.stepCount !== undefined && (
109
- <div className="mt-2 flex items-center gap-2">
110
- <span className="text-xs px-2 py-0.5 rounded-full bg-info/10 text-info">
111
- {data.stepCount} steps
112
- </span>
113
- </div>
114
- )}
115
- </div>
116
-
117
- {/* Expanded content */}
118
- {expanded && (
119
- <div className="border-t border-node-border p-3 bg-black/20">
120
- <button
121
- onClick={handleDrillDown}
122
- className="w-full flex items-center justify-center gap-2 px-3 py-2 bg-info/10 hover:bg-info/20 rounded text-sm text-info transition-colors"
123
- >
124
- <FolderOpen className="w-4 h-4" />
125
- Open Sub-workflow
126
- <ArrowRight className="w-4 h-4" />
127
- </button>
128
- </div>
129
- )}
130
-
131
- {/* Output handle */}
132
- <Handle
133
- type="source"
134
- position={Position.Bottom}
135
- className="!w-3 !h-3 !bg-info !border-2 !border-node-bg"
136
- />
137
- </div>
138
- );
139
- }
140
-
141
- export const SubWorkflowNode = memo(SubWorkflowNodeComponent);
@@ -1,185 +0,0 @@
1
- import { memo } from 'react';
2
- import { Handle, Position, type Node, type NodeProps } from '@xyflow/react';
3
- import { GitFork, CheckCircle, XCircle, Clock } from 'lucide-react';
4
-
5
- export interface SwitchNodeData extends Record<string, unknown> {
6
- id: string;
7
- name?: string;
8
- expression: string;
9
- cases: Record<string, unknown>;
10
- hasDefault?: boolean;
11
- status?: 'pending' | 'running' | 'completed' | 'failed' | 'skipped';
12
- activeCase?: string | null;
13
- skippedBranches?: string[];
14
- }
15
-
16
- export type SwitchNodeType = Node<SwitchNodeData, 'switch'>;
17
-
18
- function SwitchNodeComponent({ data, selected }: NodeProps<SwitchNodeType>) {
19
- const statusConfig: Record<
20
- NonNullable<SwitchNodeData['status']>,
21
- { icon: typeof Clock; color: string; bgColor: string; animate?: boolean }
22
- > = {
23
- pending: { icon: Clock, color: 'text-gray-400', bgColor: 'bg-gray-400/10' },
24
- running: {
25
- icon: GitFork,
26
- color: 'text-purple-400',
27
- bgColor: 'bg-purple-400/10',
28
- animate: true,
29
- },
30
- completed: {
31
- icon: CheckCircle,
32
- color: 'text-success',
33
- bgColor: 'bg-success/10',
34
- },
35
- failed: { icon: XCircle, color: 'text-error', bgColor: 'bg-error/10' },
36
- skipped: {
37
- icon: XCircle,
38
- color: 'text-gray-500',
39
- bgColor: 'bg-gray-500/10',
40
- },
41
- };
42
-
43
- const status = data.status || 'pending';
44
- const config = statusConfig[status];
45
- const StatusIcon = config.icon;
46
-
47
- const caseKeys = Object.keys(data.cases || {});
48
- const displayCases = caseKeys.slice(0, 4); // Show up to 4 cases
49
- const hasMore = caseKeys.length > 4;
50
-
51
- // Calculate handle positions to avoid overlap
52
- const totalHandles = Math.min(caseKeys.length, 4) + (data.hasDefault ? 1 : 0);
53
- const getHandlePosition = (index: number) => {
54
- if (totalHandles === 1) return 50;
55
- return ((index + 1) / (totalHandles + 1)) * 100;
56
- };
57
-
58
- return (
59
- <div
60
- className={`control-flow-node switch-node p-0 ${selected ? 'selected' : ''} ${status === 'running' ? 'running' : ''} ${status === 'completed' ? 'completed' : ''} ${status === 'failed' ? 'failed' : ''}`}
61
- style={{
62
- background: 'linear-gradient(135deg, #a855f7 0%, #ec4899 100%)',
63
- }}
64
- >
65
- {/* Input handle */}
66
- <Handle
67
- type="target"
68
- position={Position.Top}
69
- className="!w-3 !h-3 !bg-primary !border-2 !border-node-bg"
70
- />
71
-
72
- {/* Node header */}
73
- <div className="flex items-center gap-3 p-3 border-b border-white/20">
74
- <div className="w-8 h-8 rounded-lg bg-white/20 flex items-center justify-center">
75
- <GitFork className="w-5 h-5 text-white" />
76
- </div>
77
- <div className="flex-1 min-w-0">
78
- <div className="text-sm font-medium text-white">
79
- {data.name || 'Switch'}
80
- </div>
81
- <div className="text-xs text-white/70">Multi-Branch Router</div>
82
- </div>
83
- <div
84
- className={`w-6 h-6 rounded-full ${config.bgColor} flex items-center justify-center`}
85
- >
86
- <StatusIcon
87
- className={`w-4 h-4 ${config.color} ${config.animate ? 'animate-pulse' : ''}`}
88
- />
89
- </div>
90
- </div>
91
-
92
- {/* Node body */}
93
- <div className="p-3 bg-white/10">
94
- <div className="text-xs text-white/90 mb-3">
95
- <span className="text-white/60">Expression:</span>{' '}
96
- <span className="font-mono">{data.expression || 'Not set'}</span>
97
- </div>
98
-
99
- {/* Case list */}
100
- <div className="space-y-2">
101
- <div className="text-xs text-white/70 font-medium mb-1">Cases:</div>
102
- {displayCases.map((caseKey, index) => {
103
- const isActive = data.activeCase === caseKey;
104
- const isSkipped = data.skippedBranches?.includes(caseKey);
105
- const handlePosition = getHandlePosition(index);
106
-
107
- return (
108
- <div key={caseKey} className="relative">
109
- <div
110
- className={`text-xs px-2 py-1.5 rounded font-medium transition-colors relative ${
111
- isActive
112
- ? 'bg-purple-500/30 text-purple-200 ring-1 ring-purple-400/50'
113
- : isSkipped
114
- ? 'bg-gray-500/20 text-gray-400 line-through'
115
- : 'bg-white/5 text-white/70'
116
- }`}
117
- >
118
- {caseKey}
119
- {isSkipped && (
120
- <span className="ml-2 text-[8px] px-1 py-0.5 rounded bg-gray-500/30">
121
- SKIPPED
122
- </span>
123
- )}
124
- </div>
125
- </div>
126
- );
127
- })}
128
-
129
- {hasMore && (
130
- <div className="text-xs px-2 py-1 rounded bg-white/5 text-white/60 text-center">
131
- +{caseKeys.length - 4} more cases
132
- </div>
133
- )}
134
-
135
- {/* Default case */}
136
- {data.hasDefault && (
137
- <div className="relative">
138
- <div
139
- className={`text-xs px-2 py-1.5 rounded font-medium transition-colors ${
140
- data.activeCase === 'default'
141
- ? 'bg-gray-500/30 text-gray-200 ring-1 ring-gray-400/50'
142
- : 'bg-white/5 text-white/70'
143
- }`}
144
- >
145
- default
146
- </div>
147
- </div>
148
- )}
149
- </div>
150
-
151
- {/* Case count */}
152
- <div className="mt-3 text-xs text-white/50 flex items-center gap-2">
153
- <span>ℹ️</span>
154
- <span>
155
- {caseKeys.length} case{caseKeys.length !== 1 ? 's' : ''}
156
- {data.hasDefault ? ' + default' : ''}
157
- </span>
158
- </div>
159
- </div>
160
-
161
- {/* Output handles - positioned independently to avoid overlap */}
162
- {displayCases.map((caseKey, index) => (
163
- <Handle
164
- key={`handle-${caseKey}`}
165
- type="source"
166
- position={Position.Bottom}
167
- id={`case-${caseKey}`}
168
- style={{ left: `${getHandlePosition(index)}%` }}
169
- className="!w-2.5 !h-2.5 !bg-purple-400 !border-2 !border-node-bg"
170
- />
171
- ))}
172
- {data.hasDefault && (
173
- <Handle
174
- type="source"
175
- position={Position.Bottom}
176
- id="case-default"
177
- style={{ left: `${getHandlePosition(displayCases.length)}%` }}
178
- className="!w-2.5 !h-2.5 !bg-gray-400 !border-2 !border-node-bg"
179
- />
180
- )}
181
- </div>
182
- );
183
- }
184
-
185
- export const SwitchNode = memo(SwitchNodeComponent);