@marktoflow/gui 2.0.0-alpha.5 → 2.0.2

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 (162) hide show
  1. package/README.md +48 -180
  2. package/dist/client/assets/index-DQeR1ew6.css +1 -0
  3. package/dist/client/assets/index-LbIVPHbD.js +833 -0
  4. package/dist/client/assets/index-LbIVPHbD.js.map +1 -0
  5. package/dist/client/index.html +2 -2
  6. package/dist/client/marktoflow-logo.png +0 -0
  7. package/dist/server/index.js +31 -5
  8. package/dist/server/index.js.map +1 -1
  9. package/dist/server/routes/admin.js +95 -0
  10. package/dist/server/routes/admin.js.map +1 -0
  11. package/dist/server/routes/ai.js +2 -2
  12. package/dist/server/routes/ai.js.map +1 -1
  13. package/dist/server/routes/collaboration.js +104 -0
  14. package/dist/server/routes/collaboration.js.map +1 -0
  15. package/dist/server/routes/execute.js +181 -14
  16. package/dist/server/routes/execute.js.map +1 -1
  17. package/dist/server/routes/form.js +160 -0
  18. package/dist/server/routes/form.js.map +1 -0
  19. package/dist/server/routes/settings.js +90 -0
  20. package/dist/server/routes/settings.js.map +1 -0
  21. package/dist/server/routes/templates.js +106 -0
  22. package/dist/server/routes/templates.js.map +1 -0
  23. package/dist/server/routes/versions.js +101 -0
  24. package/dist/server/routes/versions.js.map +1 -0
  25. package/dist/server/services/AIService.js +85 -2
  26. package/dist/server/services/AIService.js.map +1 -1
  27. package/dist/server/services/ExecutionManager.js +571 -0
  28. package/dist/server/services/ExecutionManager.js.map +1 -0
  29. package/dist/server/services/VersionService.js +65 -0
  30. package/dist/server/services/VersionService.js.map +1 -0
  31. package/dist/server/services/WorkflowService.js +8 -2
  32. package/dist/server/services/WorkflowService.js.map +1 -1
  33. package/dist/server/services/agents/copilot-provider.js +32 -0
  34. package/dist/server/services/agents/copilot-provider.js.map +1 -1
  35. package/dist/server/websocket/index.js +42 -0
  36. package/dist/server/websocket/index.js.map +1 -1
  37. package/dist/shared/constants.js +9 -0
  38. package/dist/shared/constants.js.map +1 -1
  39. package/dist/shared/settings.js +51 -0
  40. package/dist/shared/settings.js.map +1 -0
  41. package/package.json +14 -10
  42. package/public/marktoflow-logo.png +0 -0
  43. package/tests/integration/fixtures/test-workflow.md +6 -0
  44. package/.turbo/turbo-build.log +0 -42
  45. package/dist/client/assets/index-CM44OayM.js +0 -704
  46. package/dist/client/assets/index-CM44OayM.js.map +0 -1
  47. package/dist/client/assets/index-Dru63gi6.css +0 -1
  48. package/marktoflow-gui-2.0.0-alpha.5.tgz +0 -0
  49. package/playwright.config.ts +0 -27
  50. package/postcss.config.js +0 -6
  51. package/src/client/App.tsx +0 -520
  52. package/src/client/components/Canvas/Canvas.tsx +0 -425
  53. package/src/client/components/Canvas/ExecutionOverlay.tsx +0 -935
  54. package/src/client/components/Canvas/ForEachNode.tsx +0 -152
  55. package/src/client/components/Canvas/IfElseNode.tsx +0 -141
  56. package/src/client/components/Canvas/NodeContextMenu.tsx +0 -192
  57. package/src/client/components/Canvas/OutputNode.tsx +0 -111
  58. package/src/client/components/Canvas/ParallelNode.tsx +0 -157
  59. package/src/client/components/Canvas/StepNode.tsx +0 -106
  60. package/src/client/components/Canvas/SubWorkflowNode.tsx +0 -141
  61. package/src/client/components/Canvas/SwitchNode.tsx +0 -185
  62. package/src/client/components/Canvas/Toolbar.tsx +0 -227
  63. package/src/client/components/Canvas/TransformNode.tsx +0 -194
  64. package/src/client/components/Canvas/TriggerNode.tsx +0 -128
  65. package/src/client/components/Canvas/TryCatchNode.tsx +0 -164
  66. package/src/client/components/Canvas/WhileNode.tsx +0 -161
  67. package/src/client/components/Canvas/index.ts +0 -24
  68. package/src/client/components/Debug/VariableInspector.tsx +0 -148
  69. package/src/client/components/Editor/InputsEditor.tsx +0 -458
  70. package/src/client/components/Editor/NewStepWizard.tsx +0 -344
  71. package/src/client/components/Editor/StepEditor.tsx +0 -532
  72. package/src/client/components/Editor/YamlEditor.tsx +0 -160
  73. package/src/client/components/Panels/PropertiesPanel.tsx +0 -589
  74. package/src/client/components/Prompt/ChangePreview.tsx +0 -281
  75. package/src/client/components/Prompt/PromptHistoryPanel.tsx +0 -209
  76. package/src/client/components/Prompt/PromptInput.tsx +0 -110
  77. package/src/client/components/Settings/ProviderSwitcher.tsx +0 -228
  78. package/src/client/components/Sidebar/ImportDialog.tsx +0 -257
  79. package/src/client/components/Sidebar/Sidebar.tsx +0 -362
  80. package/src/client/components/common/Breadcrumb.tsx +0 -40
  81. package/src/client/components/common/Button.tsx +0 -68
  82. package/src/client/components/common/ContextMenu.tsx +0 -202
  83. package/src/client/components/common/KeyboardShortcuts.tsx +0 -149
  84. package/src/client/components/common/Modal.tsx +0 -93
  85. package/src/client/components/common/Tabs.tsx +0 -57
  86. package/src/client/components/common/ThemeToggle.tsx +0 -63
  87. package/src/client/components/index.ts +0 -32
  88. package/src/client/hooks/index.ts +0 -4
  89. package/src/client/hooks/useAIPrompt.ts +0 -108
  90. package/src/client/hooks/useCanvas.ts +0 -247
  91. package/src/client/hooks/useWebSocket.ts +0 -164
  92. package/src/client/hooks/useWorkflow.ts +0 -138
  93. package/src/client/main.tsx +0 -10
  94. package/src/client/stores/agentStore.ts +0 -109
  95. package/src/client/stores/canvasStore.ts +0 -348
  96. package/src/client/stores/editorStore.ts +0 -133
  97. package/src/client/stores/executionStore.ts +0 -502
  98. package/src/client/stores/index.ts +0 -4
  99. package/src/client/stores/layoutStore.ts +0 -103
  100. package/src/client/stores/navigationStore.ts +0 -49
  101. package/src/client/stores/promptStore.ts +0 -113
  102. package/src/client/stores/themeStore.ts +0 -75
  103. package/src/client/stores/workflowStore.ts +0 -185
  104. package/src/client/styles/globals.css +0 -452
  105. package/src/client/utils/cn.ts +0 -9
  106. package/src/client/utils/index.ts +0 -4
  107. package/src/client/utils/platform.ts +0 -46
  108. package/src/client/utils/serviceIcons.tsx +0 -97
  109. package/src/client/utils/stepValidation.ts +0 -155
  110. package/src/client/utils/workflowToGraph.ts +0 -523
  111. package/src/server/index.ts +0 -137
  112. package/src/server/routes/ai.ts +0 -91
  113. package/src/server/routes/execute.ts +0 -71
  114. package/src/server/routes/executions.ts +0 -136
  115. package/src/server/routes/tools.ts +0 -970
  116. package/src/server/routes/workflows.ts +0 -147
  117. package/src/server/services/AIService.ts +0 -105
  118. package/src/server/services/FileWatcher.ts +0 -69
  119. package/src/server/services/WorkflowService.ts +0 -601
  120. package/src/server/services/agents/claude-code-provider.ts +0 -320
  121. package/src/server/services/agents/claude-provider.ts +0 -248
  122. package/src/server/services/agents/codex-provider.ts +0 -398
  123. package/src/server/services/agents/copilot-provider.ts +0 -311
  124. package/src/server/services/agents/demo-provider.ts +0 -184
  125. package/src/server/services/agents/index.ts +0 -31
  126. package/src/server/services/agents/ollama-provider.ts +0 -267
  127. package/src/server/services/agents/prompts.ts +0 -509
  128. package/src/server/services/agents/registry.ts +0 -310
  129. package/src/server/services/agents/types.ts +0 -146
  130. package/src/server/websocket/index.ts +0 -117
  131. package/src/shared/constants.ts +0 -180
  132. package/src/shared/types.ts +0 -179
  133. package/tailwind.config.ts +0 -73
  134. package/tests/e2e/app.spec.ts +0 -90
  135. package/tests/e2e/canvas.spec.ts +0 -128
  136. package/tests/e2e/workflow.spec.ts +0 -185
  137. package/tests/integration/api.test.ts +0 -452
  138. package/tests/integration/testApp.ts +0 -31
  139. package/tests/setup.ts +0 -72
  140. package/tests/unit/ForEachNode.test.tsx +0 -308
  141. package/tests/unit/IfElseNode.test.tsx +0 -235
  142. package/tests/unit/ParallelNode.test.tsx +0 -344
  143. package/tests/unit/SwitchNode.test.tsx +0 -327
  144. package/tests/unit/TransformNode.test.tsx +0 -386
  145. package/tests/unit/TryCatchNode.test.tsx +0 -243
  146. package/tests/unit/WhileNode.test.tsx +0 -230
  147. package/tests/unit/agentStore.test.ts +0 -218
  148. package/tests/unit/canvasStore.test.ts +0 -502
  149. package/tests/unit/codexProvider.test.ts +0 -399
  150. package/tests/unit/components.test.tsx +0 -151
  151. package/tests/unit/executionStore.test.ts +0 -567
  152. package/tests/unit/layoutStore.test.ts +0 -194
  153. package/tests/unit/navigationStore.test.ts +0 -152
  154. package/tests/unit/platform.test.ts +0 -118
  155. package/tests/unit/serviceIcons.test.ts +0 -197
  156. package/tests/unit/stepValidation.test.ts +0 -226
  157. package/tests/unit/themeStore.test.ts +0 -141
  158. package/tests/unit/workflowToGraph.test.ts +0 -311
  159. package/tsconfig.json +0 -29
  160. package/tsconfig.server.json +0 -28
  161. package/vite.config.ts +0 -31
  162. package/vitest.config.ts +0 -26
@@ -1,226 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { validateStep, getFieldError, hasFieldError } from '../../src/client/utils/stepValidation';
3
-
4
- describe('stepValidation', () => {
5
- describe('validateStep', () => {
6
- it('should pass for valid step with action', () => {
7
- const step = {
8
- id: 'valid-step',
9
- action: 'slack.chat.postMessage',
10
- inputs: {},
11
- };
12
-
13
- const result = validateStep(step);
14
- expect(result.valid).toBe(true);
15
- expect(result.errors).toHaveLength(0);
16
- });
17
-
18
- it('should pass for valid step with workflow', () => {
19
- const step = {
20
- id: 'sub-workflow',
21
- workflow: './path/to/workflow.md',
22
- inputs: {},
23
- };
24
-
25
- const result = validateStep(step);
26
- expect(result.valid).toBe(true);
27
- expect(result.errors).toHaveLength(0);
28
- });
29
-
30
- it('should fail when id is empty', () => {
31
- const step = {
32
- id: '',
33
- action: 'slack.chat.postMessage',
34
- inputs: {},
35
- };
36
-
37
- const result = validateStep(step);
38
- expect(result.valid).toBe(false);
39
- expect(result.errors.some((e) => e.field === 'id')).toBe(true);
40
- });
41
-
42
- it('should fail when id starts with number', () => {
43
- const step = {
44
- id: '123-step',
45
- action: 'slack.chat.postMessage',
46
- inputs: {},
47
- };
48
-
49
- const result = validateStep(step);
50
- expect(result.valid).toBe(false);
51
- expect(result.errors.some((e) => e.field === 'id')).toBe(true);
52
- });
53
-
54
- it('should fail when neither action nor workflow is provided', () => {
55
- const step = {
56
- id: 'empty-step',
57
- inputs: {},
58
- };
59
-
60
- const result = validateStep(step);
61
- expect(result.valid).toBe(false);
62
- expect(result.errors.some((e) => e.field === 'action')).toBe(true);
63
- });
64
-
65
- it('should fail when action is not in correct format', () => {
66
- const step = {
67
- id: 'bad-action',
68
- action: 'invalid',
69
- inputs: {},
70
- };
71
-
72
- const result = validateStep(step);
73
- expect(result.valid).toBe(false);
74
- expect(result.errors.some((e) => e.field === 'action')).toBe(true);
75
- });
76
-
77
- it('should pass for valid action formats', () => {
78
- // Two-part action
79
- let step = {
80
- id: 'step-1',
81
- action: 'http.get',
82
- inputs: {},
83
- };
84
- expect(validateStep(step).valid).toBe(true);
85
-
86
- // Three-part action
87
- step = {
88
- id: 'step-2',
89
- action: 'slack.chat.postMessage',
90
- inputs: {},
91
- };
92
- expect(validateStep(step).valid).toBe(true);
93
- });
94
-
95
- it('should fail for invalid workflow extensions', () => {
96
- const step = {
97
- id: 'sub-workflow',
98
- workflow: './path/to/workflow.txt',
99
- inputs: {},
100
- };
101
-
102
- const result = validateStep(step);
103
- expect(result.valid).toBe(false);
104
- expect(result.errors.some((e) => e.field === 'workflow')).toBe(true);
105
- });
106
-
107
- it('should pass for valid workflow extensions', () => {
108
- const extensions = ['.md', '.yaml', '.yml'];
109
- for (const ext of extensions) {
110
- const step = {
111
- id: 'sub-workflow',
112
- workflow: `./path/to/workflow${ext}`,
113
- inputs: {},
114
- };
115
- expect(validateStep(step).valid).toBe(true);
116
- }
117
- });
118
-
119
- it('should fail for invalid output variable name', () => {
120
- const step = {
121
- id: 'step',
122
- action: 'http.get',
123
- inputs: {},
124
- outputVariable: '123invalid',
125
- };
126
-
127
- const result = validateStep(step);
128
- expect(result.valid).toBe(false);
129
- expect(result.errors.some((e) => e.field === 'outputVariable')).toBe(true);
130
- });
131
-
132
- it('should pass for valid output variable name', () => {
133
- const step = {
134
- id: 'step',
135
- action: 'http.get',
136
- inputs: {},
137
- outputVariable: 'result_data',
138
- };
139
-
140
- expect(validateStep(step).valid).toBe(true);
141
- });
142
-
143
- it('should fail for invalid timeout', () => {
144
- const step = {
145
- id: 'step',
146
- action: 'http.get',
147
- inputs: {},
148
- timeout: -5,
149
- };
150
-
151
- const result = validateStep(step);
152
- expect(result.valid).toBe(false);
153
- expect(result.errors.some((e) => e.field === 'timeout')).toBe(true);
154
- });
155
-
156
- it('should validate error handling', () => {
157
- const step = {
158
- id: 'step',
159
- action: 'http.get',
160
- inputs: {},
161
- errorHandling: {
162
- action: 'invalid' as any,
163
- },
164
- };
165
-
166
- const result = validateStep(step);
167
- expect(result.valid).toBe(false);
168
- expect(result.errors.some((e) => e.field === 'errorHandling.action')).toBe(true);
169
- });
170
-
171
- it('should validate retry settings', () => {
172
- const step = {
173
- id: 'step',
174
- action: 'http.get',
175
- inputs: {},
176
- errorHandling: {
177
- action: 'retry' as const,
178
- maxRetries: 0,
179
- retryDelay: -100,
180
- },
181
- };
182
-
183
- const result = validateStep(step);
184
- expect(result.valid).toBe(false);
185
- expect(result.errors.some((e) => e.field === 'errorHandling.maxRetries')).toBe(true);
186
- expect(result.errors.some((e) => e.field === 'errorHandling.retryDelay')).toBe(true);
187
- });
188
-
189
- it('should fail for empty conditions', () => {
190
- const step = {
191
- id: 'step',
192
- action: 'http.get',
193
- inputs: {},
194
- conditions: ['valid condition', '', 'another'],
195
- };
196
-
197
- const result = validateStep(step);
198
- expect(result.valid).toBe(false);
199
- expect(result.errors.some((e) => e.field === 'conditions[1]')).toBe(true);
200
- });
201
- });
202
-
203
- describe('getFieldError', () => {
204
- it('should return error message for field', () => {
205
- const errors = [
206
- { field: 'id', message: 'ID is required' },
207
- { field: 'action', message: 'Action is invalid' },
208
- ];
209
-
210
- expect(getFieldError(errors, 'id')).toBe('ID is required');
211
- expect(getFieldError(errors, 'action')).toBe('Action is invalid');
212
- expect(getFieldError(errors, 'name')).toBeUndefined();
213
- });
214
- });
215
-
216
- describe('hasFieldError', () => {
217
- it('should return true if field has error', () => {
218
- const errors = [
219
- { field: 'id', message: 'ID is required' },
220
- ];
221
-
222
- expect(hasFieldError(errors, 'id')).toBe(true);
223
- expect(hasFieldError(errors, 'name')).toBe(false);
224
- });
225
- });
226
- });
@@ -1,141 +0,0 @@
1
- import { describe, it, expect, beforeEach, vi } from 'vitest';
2
- import { useThemeStore } from '../../src/client/stores/themeStore';
3
-
4
- // Mock localStorage
5
- const localStorageMock = (() => {
6
- let store: Record<string, string> = {};
7
- return {
8
- getItem: (key: string) => store[key] || null,
9
- setItem: (key: string, value: string) => { store[key] = value; },
10
- removeItem: (key: string) => { delete store[key]; },
11
- clear: () => { store = {}; },
12
- };
13
- })();
14
-
15
- Object.defineProperty(window, 'localStorage', { value: localStorageMock });
16
-
17
- // Mock matchMedia
18
- Object.defineProperty(window, 'matchMedia', {
19
- value: vi.fn().mockImplementation(query => ({
20
- matches: query === '(prefers-color-scheme: dark)',
21
- media: query,
22
- onchange: null,
23
- addListener: vi.fn(),
24
- removeListener: vi.fn(),
25
- addEventListener: vi.fn(),
26
- removeEventListener: vi.fn(),
27
- dispatchEvent: vi.fn(),
28
- })),
29
- });
30
-
31
- describe('themeStore', () => {
32
- beforeEach(() => {
33
- // Reset store state
34
- useThemeStore.setState({
35
- theme: 'dark',
36
- resolvedTheme: 'dark',
37
- });
38
- localStorageMock.clear();
39
-
40
- // Reset document classes
41
- document.documentElement.classList.remove('dark', 'light');
42
- });
43
-
44
- describe('initial state', () => {
45
- it('should default to dark theme', () => {
46
- const state = useThemeStore.getState();
47
- expect(state.theme).toBe('dark');
48
- expect(state.resolvedTheme).toBe('dark');
49
- });
50
- });
51
-
52
- describe('setTheme', () => {
53
- it('should set theme to light', () => {
54
- const { setTheme } = useThemeStore.getState();
55
-
56
- setTheme('light');
57
-
58
- const state = useThemeStore.getState();
59
- expect(state.theme).toBe('light');
60
- expect(state.resolvedTheme).toBe('light');
61
- });
62
-
63
- it('should set theme to dark', () => {
64
- const { setTheme } = useThemeStore.getState();
65
-
66
- setTheme('light');
67
- setTheme('dark');
68
-
69
- const state = useThemeStore.getState();
70
- expect(state.theme).toBe('dark');
71
- expect(state.resolvedTheme).toBe('dark');
72
- });
73
-
74
- it('should resolve system theme', () => {
75
- const { setTheme } = useThemeStore.getState();
76
-
77
- setTheme('system');
78
-
79
- const state = useThemeStore.getState();
80
- expect(state.theme).toBe('system');
81
- // Our mock returns dark for prefers-color-scheme: dark
82
- expect(state.resolvedTheme).toBe('dark');
83
- });
84
-
85
- it('should apply dark class to document', () => {
86
- const { setTheme } = useThemeStore.getState();
87
-
88
- setTheme('dark');
89
-
90
- expect(document.documentElement.classList.contains('dark')).toBe(true);
91
- expect(document.documentElement.classList.contains('light')).toBe(false);
92
- });
93
-
94
- it('should apply light class to document', () => {
95
- const { setTheme } = useThemeStore.getState();
96
-
97
- setTheme('light');
98
-
99
- expect(document.documentElement.classList.contains('light')).toBe(true);
100
- expect(document.documentElement.classList.contains('dark')).toBe(false);
101
- });
102
- });
103
-
104
- describe('toggleTheme', () => {
105
- it('should toggle from dark to light', () => {
106
- const { toggleTheme } = useThemeStore.getState();
107
-
108
- toggleTheme();
109
-
110
- const state = useThemeStore.getState();
111
- expect(state.theme).toBe('light');
112
- expect(state.resolvedTheme).toBe('light');
113
- });
114
-
115
- it('should toggle from light to dark', () => {
116
- const { setTheme, toggleTheme } = useThemeStore.getState();
117
-
118
- setTheme('light');
119
- toggleTheme();
120
-
121
- const state = useThemeStore.getState();
122
- expect(state.theme).toBe('dark');
123
- expect(state.resolvedTheme).toBe('dark');
124
- });
125
-
126
- it('should apply correct classes on toggle', () => {
127
- const { setTheme, toggleTheme } = useThemeStore.getState();
128
-
129
- setTheme('dark');
130
- expect(document.documentElement.classList.contains('dark')).toBe(true);
131
-
132
- toggleTheme();
133
- expect(document.documentElement.classList.contains('light')).toBe(true);
134
- expect(document.documentElement.classList.contains('dark')).toBe(false);
135
-
136
- toggleTheme();
137
- expect(document.documentElement.classList.contains('dark')).toBe(true);
138
- expect(document.documentElement.classList.contains('light')).toBe(false);
139
- });
140
- });
141
- });
@@ -1,311 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { workflowToGraph, graphToWorkflow } from '../../src/client/utils/workflowToGraph';
3
-
4
- describe('workflowToGraph', () => {
5
- describe('basic conversion', () => {
6
- it('should convert a simple workflow to nodes and edges', () => {
7
- const workflow = {
8
- metadata: { id: 'test-1', name: 'Test Workflow' },
9
- steps: [
10
- { id: 'step-1', name: 'Step 1', action: 'http.get', inputs: {} },
11
- { id: 'step-2', name: 'Step 2', action: 'http.post', inputs: {} },
12
- ],
13
- };
14
-
15
- const { nodes, edges } = workflowToGraph(workflow);
16
-
17
- // Should have 2 step nodes + 1 output node
18
- expect(nodes).toHaveLength(3);
19
- expect(nodes[0].id).toBe('step-1');
20
- expect(nodes[0].type).toBe('step');
21
- expect(nodes[1].id).toBe('step-2');
22
- expect(nodes[1].type).toBe('step');
23
- expect(nodes[2].type).toBe('output');
24
-
25
- // Should have edge between steps and to output
26
- expect(edges.length).toBeGreaterThanOrEqual(2);
27
- expect(edges.find(e => e.source === 'step-1' && e.target === 'step-2')).toBeDefined();
28
- });
29
-
30
- it('should create nodes with correct data', () => {
31
- const workflow = {
32
- metadata: { id: 'test-1', name: 'Test Workflow' },
33
- steps: [
34
- {
35
- id: 'fetch',
36
- name: 'Fetch Data',
37
- action: 'github.pulls.get',
38
- inputs: { owner: 'test' },
39
- outputVariable: 'pr_data',
40
- },
41
- ],
42
- };
43
-
44
- const { nodes } = workflowToGraph(workflow);
45
- const stepNode = nodes.find(n => n.id === 'fetch');
46
-
47
- expect(stepNode?.data.id).toBe('fetch');
48
- expect(stepNode?.data.name).toBe('Fetch Data');
49
- expect(stepNode?.data.action).toBe('github.pulls.get');
50
- expect(stepNode?.data.status).toBe('pending');
51
- });
52
-
53
- it('should space steps with 180px vertical spacing', () => {
54
- const workflow = {
55
- metadata: { id: 'test-1', name: 'Test Workflow' },
56
- steps: [
57
- { id: 'step-1', name: 'Step 1', action: 'test', inputs: {} },
58
- { id: 'step-2', name: 'Step 2', action: 'test', inputs: {} },
59
- { id: 'step-3', name: 'Step 3', action: 'test', inputs: {} },
60
- ],
61
- };
62
-
63
- const { nodes } = workflowToGraph(workflow);
64
- const stepNodes = nodes.filter(n => n.type === 'step');
65
-
66
- // Check vertical spacing between steps
67
- const step1Y = stepNodes[0].position.y;
68
- const step2Y = stepNodes[1].position.y;
69
- const step3Y = stepNodes[2].position.y;
70
-
71
- expect(step2Y - step1Y).toBe(180);
72
- expect(step3Y - step2Y).toBe(180);
73
- });
74
- });
75
-
76
- describe('trigger nodes', () => {
77
- it('should add a trigger node when triggers are defined', () => {
78
- const workflow = {
79
- metadata: { id: 'test-1', name: 'Test Workflow' },
80
- steps: [{ id: 'step-1', action: 'http.get', inputs: {} }],
81
- triggers: [{ type: 'webhook' as const, path: '/api/trigger' }],
82
- };
83
-
84
- const { nodes, edges } = workflowToGraph(workflow);
85
-
86
- const triggerNode = nodes.find(n => n.type === 'trigger');
87
- expect(triggerNode).toBeDefined();
88
- expect(triggerNode?.data.type).toBe('webhook');
89
- expect(triggerNode?.data.path).toBe('/api/trigger');
90
-
91
- // Should have edge from trigger to first step
92
- const triggerEdge = edges.find(e => e.source === triggerNode?.id && e.target === 'step-1');
93
- expect(triggerEdge).toBeDefined();
94
- });
95
-
96
- it('should handle schedule trigger with cron', () => {
97
- const workflow = {
98
- metadata: { id: 'test-1', name: 'Test Workflow' },
99
- steps: [{ id: 'step-1', action: 'http.get', inputs: {} }],
100
- triggers: [{ type: 'schedule' as const, cron: '0 9 * * *' }],
101
- };
102
-
103
- const { nodes } = workflowToGraph(workflow);
104
- const triggerNode = nodes.find(n => n.type === 'trigger');
105
-
106
- expect(triggerNode?.data.type).toBe('schedule');
107
- expect(triggerNode?.data.cron).toBe('0 9 * * *');
108
- });
109
- });
110
-
111
- describe('sub-workflow nodes', () => {
112
- it('should create subworkflow nodes for steps with workflow property', () => {
113
- const workflow = {
114
- metadata: { id: 'test-1', name: 'Test Workflow' },
115
- steps: [
116
- { id: 'step-1', action: 'http.get', inputs: {} },
117
- { id: 'sub-1', name: 'Sub Process', workflow: '/workflows/sub.md', inputs: {} },
118
- ],
119
- };
120
-
121
- const { nodes } = workflowToGraph(workflow);
122
- const subNode = nodes.find(n => n.id === 'sub-1');
123
-
124
- expect(subNode?.type).toBe('subworkflow');
125
- expect(subNode?.data.workflowPath).toBe('/workflows/sub.md');
126
- });
127
- });
128
-
129
- describe('output nodes', () => {
130
- it('should add output node at the end', () => {
131
- const workflow = {
132
- metadata: { id: 'test-1', name: 'Test Workflow' },
133
- steps: [
134
- { id: 'step-1', action: 'http.get', inputs: {}, outputVariable: 'result1' },
135
- { id: 'step-2', action: 'http.post', inputs: {}, outputVariable: 'result2' },
136
- ],
137
- };
138
-
139
- const { nodes, edges } = workflowToGraph(workflow);
140
- const outputNode = nodes.find(n => n.type === 'output');
141
-
142
- expect(outputNode).toBeDefined();
143
- expect(outputNode?.data.variables).toEqual(['result1', 'result2']);
144
-
145
- // Should have edge from last step to output
146
- const outputEdge = edges.find(e => e.source === 'step-2' && e.target === outputNode?.id);
147
- expect(outputEdge).toBeDefined();
148
- });
149
- });
150
-
151
- describe('variable dependency edges', () => {
152
- it('should create data flow edges for variable references', () => {
153
- const workflow = {
154
- metadata: { id: 'test-1', name: 'Test Workflow' },
155
- steps: [
156
- { id: 'step-1', action: 'http.get', inputs: {}, outputVariable: 'response' },
157
- { id: 'step-2', action: 'process', inputs: { data: '{{ response.body }}' } },
158
- ],
159
- };
160
-
161
- const { edges } = workflowToGraph(workflow);
162
- const dataEdge = edges.find(e => e.id.startsWith('data-') && e.source === 'step-1' && e.target === 'step-2');
163
-
164
- expect(dataEdge).toBeDefined();
165
- expect(dataEdge?.label).toBe('response');
166
- expect(dataEdge?.animated).toBe(true);
167
- });
168
-
169
- it('should not create edges for inputs references', () => {
170
- const workflow = {
171
- metadata: { id: 'test-1', name: 'Test Workflow' },
172
- steps: [
173
- { id: 'step-1', action: 'http.get', inputs: { url: '{{ inputs.url }}' } },
174
- ],
175
- };
176
-
177
- const { edges } = workflowToGraph(workflow);
178
- const dataEdges = edges.filter(e => e.id.startsWith('data-'));
179
-
180
- expect(dataEdges).toHaveLength(0);
181
- });
182
- });
183
-
184
- describe('conditional edges', () => {
185
- it('should label conditional edges', () => {
186
- const workflow = {
187
- metadata: { id: 'test-1', name: 'Test Workflow' },
188
- steps: [
189
- { id: 'step-1', action: 'check', inputs: {} },
190
- { id: 'step-2', action: 'process', inputs: {}, conditions: ['result.success == true'] },
191
- ],
192
- };
193
-
194
- const { edges } = workflowToGraph(workflow);
195
- const conditionalEdge = edges.find(e => e.source === 'step-1' && e.target === 'step-2');
196
-
197
- expect(conditionalEdge?.label).toBe('conditional');
198
- });
199
- });
200
-
201
- describe('node positioning', () => {
202
- it('should position nodes vertically', () => {
203
- const workflow = {
204
- metadata: { id: 'test-1', name: 'Test Workflow' },
205
- steps: [
206
- { id: 'step-1', action: 'a', inputs: {} },
207
- { id: 'step-2', action: 'b', inputs: {} },
208
- { id: 'step-3', action: 'c', inputs: {} },
209
- ],
210
- };
211
-
212
- const { nodes } = workflowToGraph(workflow);
213
- const stepNodes = nodes.filter(n => n.type === 'step');
214
-
215
- // Each step should be below the previous one
216
- expect(stepNodes[1].position.y).toBeGreaterThan(stepNodes[0].position.y);
217
- expect(stepNodes[2].position.y).toBeGreaterThan(stepNodes[1].position.y);
218
- });
219
- });
220
- });
221
-
222
- describe('graphToWorkflow', () => {
223
- it('should convert nodes back to workflow steps', () => {
224
- const nodes = [
225
- {
226
- id: 'step-1',
227
- type: 'step',
228
- position: { x: 250, y: 0 },
229
- data: { id: 'step-1', name: 'Step 1', action: 'http.get', inputs: {} },
230
- },
231
- {
232
- id: 'step-2',
233
- type: 'step',
234
- position: { x: 250, y: 120 },
235
- data: { id: 'step-2', name: 'Step 2', action: 'http.post', inputs: {}, outputVariable: 'result' },
236
- },
237
- ];
238
-
239
- const edges = [{ id: 'e-1-2', source: 'step-1', target: 'step-2' }];
240
- const metadata = { id: 'test', name: 'Test Workflow' };
241
-
242
- const workflow = graphToWorkflow(nodes, edges, metadata);
243
-
244
- expect(workflow.metadata).toEqual(metadata);
245
- expect(workflow.steps).toHaveLength(2);
246
- expect(workflow.steps[0].id).toBe('step-1');
247
- expect(workflow.steps[0].action).toBe('http.get');
248
- expect(workflow.steps[1].outputVariable).toBe('result');
249
- });
250
-
251
- it('should filter out trigger and output nodes', () => {
252
- const nodes = [
253
- { id: 'trigger-1', type: 'trigger', position: { x: 250, y: 0 }, data: { type: 'manual' } },
254
- { id: 'step-1', type: 'step', position: { x: 250, y: 120 }, data: { id: 'step-1', action: 'test', inputs: {} } },
255
- { id: 'output-1', type: 'output', position: { x: 250, y: 240 }, data: { variables: [] } },
256
- ];
257
-
258
- const workflow = graphToWorkflow(nodes, [], { id: 'test', name: 'Test' });
259
-
260
- expect(workflow.steps).toHaveLength(1);
261
- expect(workflow.steps[0].id).toBe('step-1');
262
- });
263
-
264
- it('should extract trigger info', () => {
265
- const nodes = [
266
- {
267
- id: 'trigger-1',
268
- type: 'trigger',
269
- position: { x: 250, y: 0 },
270
- data: { type: 'webhook', path: '/api/hook' },
271
- },
272
- { id: 'step-1', type: 'step', position: { x: 250, y: 120 }, data: { id: 'step-1', inputs: {} } },
273
- ];
274
-
275
- const workflow = graphToWorkflow(nodes, [], { id: 'test', name: 'Test' });
276
-
277
- expect(workflow.triggers).toHaveLength(1);
278
- expect(workflow.triggers?.[0].type).toBe('webhook');
279
- expect(workflow.triggers?.[0].path).toBe('/api/hook');
280
- });
281
-
282
- it('should sort steps by vertical position', () => {
283
- const nodes = [
284
- { id: 'step-3', type: 'step', position: { x: 250, y: 240 }, data: { id: 'step-3', inputs: {} } },
285
- { id: 'step-1', type: 'step', position: { x: 250, y: 0 }, data: { id: 'step-1', inputs: {} } },
286
- { id: 'step-2', type: 'step', position: { x: 250, y: 120 }, data: { id: 'step-2', inputs: {} } },
287
- ];
288
-
289
- const workflow = graphToWorkflow(nodes, [], { id: 'test', name: 'Test' });
290
-
291
- expect(workflow.steps[0].id).toBe('step-1');
292
- expect(workflow.steps[1].id).toBe('step-2');
293
- expect(workflow.steps[2].id).toBe('step-3');
294
- });
295
-
296
- it('should handle sub-workflow nodes', () => {
297
- const nodes = [
298
- {
299
- id: 'sub-1',
300
- type: 'subworkflow',
301
- position: { x: 250, y: 0 },
302
- data: { id: 'sub-1', name: 'Sub Workflow', workflowPath: '/sub.md', inputs: {} },
303
- },
304
- ];
305
-
306
- const workflow = graphToWorkflow(nodes, [], { id: 'test', name: 'Test' });
307
-
308
- expect(workflow.steps).toHaveLength(1);
309
- expect(workflow.steps[0].workflow).toBe('/sub.md');
310
- });
311
- });