@marktoflow/gui 2.0.0-alpha.4 → 2.0.1

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 (194) hide show
  1. package/README.md +48 -170
  2. package/client.log +0 -0
  3. package/dist/client/assets/index-DQeR1ew6.css +1 -0
  4. package/dist/client/assets/index-LbIVPHbD.js +833 -0
  5. package/dist/client/assets/index-LbIVPHbD.js.map +1 -0
  6. package/dist/client/index.html +2 -2
  7. package/dist/client/marktoflow-logo.png +0 -0
  8. package/dist/server/{server/index.js → index.js} +53 -6
  9. package/dist/server/index.js.map +1 -0
  10. package/dist/server/routes/admin.js +95 -0
  11. package/dist/server/routes/admin.js.map +1 -0
  12. package/dist/server/{server/routes → routes}/ai.js +2 -2
  13. package/dist/server/{server/routes → routes}/ai.js.map +1 -1
  14. package/dist/server/routes/collaboration.js +104 -0
  15. package/dist/server/routes/collaboration.js.map +1 -0
  16. package/dist/server/routes/execute.js +230 -0
  17. package/dist/server/routes/execute.js.map +1 -0
  18. package/dist/server/routes/executions.js +125 -0
  19. package/dist/server/routes/executions.js.map +1 -0
  20. package/dist/server/routes/form.js +160 -0
  21. package/dist/server/routes/form.js.map +1 -0
  22. package/dist/server/routes/settings.js +90 -0
  23. package/dist/server/routes/settings.js.map +1 -0
  24. package/dist/server/routes/templates.js +106 -0
  25. package/dist/server/routes/templates.js.map +1 -0
  26. package/dist/server/routes/versions.js +101 -0
  27. package/dist/server/routes/versions.js.map +1 -0
  28. package/dist/server/{server/routes → routes}/workflows.js +37 -1
  29. package/dist/server/routes/workflows.js.map +1 -0
  30. package/dist/server/services/AIService.js +152 -0
  31. package/dist/server/services/AIService.js.map +1 -0
  32. package/dist/server/services/ExecutionManager.js +571 -0
  33. package/dist/server/services/ExecutionManager.js.map +1 -0
  34. package/dist/server/services/VersionService.js +65 -0
  35. package/dist/server/services/VersionService.js.map +1 -0
  36. package/dist/server/{server/services → services}/WorkflowService.js +166 -17
  37. package/dist/server/services/WorkflowService.js.map +1 -0
  38. package/dist/server/{server/services → services}/agents/copilot-provider.js +32 -0
  39. package/dist/server/services/agents/copilot-provider.js.map +1 -0
  40. package/dist/server/{server/websocket → websocket}/index.js +54 -0
  41. package/dist/server/websocket/index.js.map +1 -0
  42. package/dist/{server/shared → shared}/constants.js +9 -0
  43. package/dist/shared/constants.js.map +1 -0
  44. package/dist/shared/settings.js +51 -0
  45. package/dist/shared/settings.js.map +1 -0
  46. package/package.json +32 -14
  47. package/public/marktoflow-logo.png +0 -0
  48. package/scripts/flatten-dist.js +69 -0
  49. package/server.log +0 -0
  50. package/tests/integration/fixtures/test-workflow.md +6 -0
  51. package/.turbo/turbo-build.log +0 -26
  52. package/dist/client/assets/index-C90Y_aBX.js +0 -678
  53. package/dist/client/assets/index-C90Y_aBX.js.map +0 -1
  54. package/dist/client/assets/index-CRWeQ3NN.css +0 -1
  55. package/dist/server/server/index.js.map +0 -1
  56. package/dist/server/server/routes/execute.js +0 -63
  57. package/dist/server/server/routes/execute.js.map +0 -1
  58. package/dist/server/server/routes/workflows.js.map +0 -1
  59. package/dist/server/server/services/AIService.js +0 -69
  60. package/dist/server/server/services/AIService.js.map +0 -1
  61. package/dist/server/server/services/WorkflowService.js.map +0 -1
  62. package/dist/server/server/services/agents/copilot-provider.js.map +0 -1
  63. package/dist/server/server/websocket/index.js.map +0 -1
  64. package/dist/server/shared/constants.js.map +0 -1
  65. package/playwright.config.ts +0 -27
  66. package/postcss.config.js +0 -6
  67. package/src/client/App.tsx +0 -520
  68. package/src/client/components/Canvas/Canvas.tsx +0 -423
  69. package/src/client/components/Canvas/ExecutionOverlay.tsx +0 -847
  70. package/src/client/components/Canvas/ForEachNode.tsx +0 -128
  71. package/src/client/components/Canvas/IfElseNode.tsx +0 -126
  72. package/src/client/components/Canvas/NodeContextMenu.tsx +0 -188
  73. package/src/client/components/Canvas/OutputNode.tsx +0 -111
  74. package/src/client/components/Canvas/ParallelNode.tsx +0 -140
  75. package/src/client/components/Canvas/StepNode.tsx +0 -106
  76. package/src/client/components/Canvas/SubWorkflowNode.tsx +0 -141
  77. package/src/client/components/Canvas/SwitchNode.tsx +0 -164
  78. package/src/client/components/Canvas/Toolbar.tsx +0 -189
  79. package/src/client/components/Canvas/TransformNode.tsx +0 -185
  80. package/src/client/components/Canvas/TriggerNode.tsx +0 -128
  81. package/src/client/components/Canvas/TryCatchNode.tsx +0 -164
  82. package/src/client/components/Canvas/WhileNode.tsx +0 -129
  83. package/src/client/components/Canvas/index.ts +0 -24
  84. package/src/client/components/Editor/InputsEditor.tsx +0 -458
  85. package/src/client/components/Editor/NewStepWizard.tsx +0 -344
  86. package/src/client/components/Editor/StepEditor.tsx +0 -532
  87. package/src/client/components/Editor/YamlEditor.tsx +0 -160
  88. package/src/client/components/Panels/PropertiesPanel.tsx +0 -589
  89. package/src/client/components/Prompt/ChangePreview.tsx +0 -281
  90. package/src/client/components/Prompt/PromptHistoryPanel.tsx +0 -209
  91. package/src/client/components/Prompt/PromptInput.tsx +0 -108
  92. package/src/client/components/Sidebar/Sidebar.tsx +0 -343
  93. package/src/client/components/common/Breadcrumb.tsx +0 -40
  94. package/src/client/components/common/Button.tsx +0 -68
  95. package/src/client/components/common/ContextMenu.tsx +0 -202
  96. package/src/client/components/common/KeyboardShortcuts.tsx +0 -143
  97. package/src/client/components/common/Modal.tsx +0 -93
  98. package/src/client/components/common/Tabs.tsx +0 -57
  99. package/src/client/components/common/ThemeToggle.tsx +0 -63
  100. package/src/client/components/index.ts +0 -32
  101. package/src/client/hooks/index.ts +0 -4
  102. package/src/client/hooks/useAIPrompt.ts +0 -108
  103. package/src/client/hooks/useCanvas.ts +0 -247
  104. package/src/client/hooks/useWebSocket.ts +0 -164
  105. package/src/client/hooks/useWorkflow.ts +0 -138
  106. package/src/client/main.tsx +0 -10
  107. package/src/client/stores/canvasStore.ts +0 -348
  108. package/src/client/stores/editorStore.ts +0 -133
  109. package/src/client/stores/executionStore.ts +0 -440
  110. package/src/client/stores/index.ts +0 -4
  111. package/src/client/stores/layoutStore.ts +0 -103
  112. package/src/client/stores/navigationStore.ts +0 -49
  113. package/src/client/stores/promptStore.ts +0 -113
  114. package/src/client/stores/themeStore.ts +0 -75
  115. package/src/client/stores/workflowStore.ts +0 -177
  116. package/src/client/styles/globals.css +0 -346
  117. package/src/client/utils/cn.ts +0 -9
  118. package/src/client/utils/index.ts +0 -4
  119. package/src/client/utils/serviceIcons.tsx +0 -97
  120. package/src/client/utils/stepValidation.ts +0 -155
  121. package/src/client/utils/workflowToGraph.ts +0 -299
  122. package/src/server/index.ts +0 -114
  123. package/src/server/routes/ai.ts +0 -91
  124. package/src/server/routes/execute.ts +0 -71
  125. package/src/server/routes/tools.ts +0 -970
  126. package/src/server/routes/workflows.ts +0 -106
  127. package/src/server/services/AIService.ts +0 -105
  128. package/src/server/services/FileWatcher.ts +0 -69
  129. package/src/server/services/WorkflowService.ts +0 -441
  130. package/src/server/services/agents/claude-code-provider.ts +0 -320
  131. package/src/server/services/agents/claude-provider.ts +0 -248
  132. package/src/server/services/agents/codex-provider.ts +0 -398
  133. package/src/server/services/agents/copilot-provider.ts +0 -311
  134. package/src/server/services/agents/demo-provider.ts +0 -184
  135. package/src/server/services/agents/index.ts +0 -31
  136. package/src/server/services/agents/ollama-provider.ts +0 -267
  137. package/src/server/services/agents/prompts.ts +0 -509
  138. package/src/server/services/agents/registry.ts +0 -310
  139. package/src/server/services/agents/types.ts +0 -146
  140. package/src/server/websocket/index.ts +0 -104
  141. package/src/shared/constants.ts +0 -180
  142. package/src/shared/types.ts +0 -179
  143. package/tailwind.config.ts +0 -73
  144. package/tests/e2e/app.spec.ts +0 -90
  145. package/tests/e2e/canvas.spec.ts +0 -128
  146. package/tests/e2e/workflow.spec.ts +0 -185
  147. package/tests/integration/api.test.ts +0 -452
  148. package/tests/integration/testApp.ts +0 -31
  149. package/tests/setup.ts +0 -72
  150. package/tests/unit/ForEachNode.test.tsx +0 -218
  151. package/tests/unit/IfElseNode.test.tsx +0 -188
  152. package/tests/unit/ParallelNode.test.tsx +0 -264
  153. package/tests/unit/SwitchNode.test.tsx +0 -252
  154. package/tests/unit/TransformNode.test.tsx +0 -386
  155. package/tests/unit/TryCatchNode.test.tsx +0 -243
  156. package/tests/unit/WhileNode.test.tsx +0 -226
  157. package/tests/unit/canvasStore.test.ts +0 -502
  158. package/tests/unit/codexProvider.test.ts +0 -399
  159. package/tests/unit/components.test.tsx +0 -151
  160. package/tests/unit/executionStore.test.ts +0 -527
  161. package/tests/unit/layoutStore.test.ts +0 -194
  162. package/tests/unit/navigationStore.test.ts +0 -152
  163. package/tests/unit/serviceIcons.test.ts +0 -197
  164. package/tests/unit/stepValidation.test.ts +0 -226
  165. package/tests/unit/themeStore.test.ts +0 -141
  166. package/tests/unit/workflowToGraph.test.ts +0 -289
  167. package/tsconfig.json +0 -29
  168. package/tsconfig.server.json +0 -28
  169. package/vite.config.ts +0 -31
  170. package/vitest.config.ts +0 -26
  171. /package/dist/server/{server/routes → routes}/tools.js +0 -0
  172. /package/dist/server/{server/routes → routes}/tools.js.map +0 -0
  173. /package/dist/server/{server/services → services}/FileWatcher.js +0 -0
  174. /package/dist/server/{server/services → services}/FileWatcher.js.map +0 -0
  175. /package/dist/server/{server/services → services}/agents/claude-code-provider.js +0 -0
  176. /package/dist/server/{server/services → services}/agents/claude-code-provider.js.map +0 -0
  177. /package/dist/server/{server/services → services}/agents/claude-provider.js +0 -0
  178. /package/dist/server/{server/services → services}/agents/claude-provider.js.map +0 -0
  179. /package/dist/server/{server/services → services}/agents/codex-provider.js +0 -0
  180. /package/dist/server/{server/services → services}/agents/codex-provider.js.map +0 -0
  181. /package/dist/server/{server/services → services}/agents/demo-provider.js +0 -0
  182. /package/dist/server/{server/services → services}/agents/demo-provider.js.map +0 -0
  183. /package/dist/server/{server/services → services}/agents/index.js +0 -0
  184. /package/dist/server/{server/services → services}/agents/index.js.map +0 -0
  185. /package/dist/server/{server/services → services}/agents/ollama-provider.js +0 -0
  186. /package/dist/server/{server/services → services}/agents/ollama-provider.js.map +0 -0
  187. /package/dist/server/{server/services → services}/agents/prompts.js +0 -0
  188. /package/dist/server/{server/services → services}/agents/prompts.js.map +0 -0
  189. /package/dist/server/{server/services → services}/agents/registry.js +0 -0
  190. /package/dist/server/{server/services → services}/agents/registry.js.map +0 -0
  191. /package/dist/server/{server/services → services}/agents/types.js +0 -0
  192. /package/dist/server/{server/services → services}/agents/types.js.map +0 -0
  193. /package/dist/{server/shared → shared}/types.js +0 -0
  194. /package/dist/{server/shared → shared}/types.js.map +0 -0
@@ -1,155 +0,0 @@
1
- import type { WorkflowStep } from '@shared/types';
2
-
3
- export interface ValidationError {
4
- field: string;
5
- message: string;
6
- }
7
-
8
- export interface ValidationResult {
9
- valid: boolean;
10
- errors: ValidationError[];
11
- }
12
-
13
- /**
14
- * Validates a workflow step
15
- */
16
- export function validateStep(step: WorkflowStep): ValidationResult {
17
- const errors: ValidationError[] = [];
18
-
19
- // ID is required
20
- if (!step.id || step.id.trim() === '') {
21
- errors.push({
22
- field: 'id',
23
- message: 'Step ID is required',
24
- });
25
- } else {
26
- // ID must be a valid identifier (letters, numbers, underscores, hyphens)
27
- if (!/^[a-zA-Z][a-zA-Z0-9_-]*$/.test(step.id)) {
28
- errors.push({
29
- field: 'id',
30
- message: 'Step ID must start with a letter and contain only letters, numbers, underscores, and hyphens',
31
- });
32
- }
33
- }
34
-
35
- // Must have either an action or a workflow reference
36
- if (!step.action && !step.workflow) {
37
- errors.push({
38
- field: 'action',
39
- message: 'Step must have either an action or a workflow reference',
40
- });
41
- }
42
-
43
- // Action format validation (service.method or service.namespace.method)
44
- if (step.action) {
45
- const actionParts = step.action.split('.');
46
- if (actionParts.length < 2) {
47
- errors.push({
48
- field: 'action',
49
- message: 'Action must be in format: service.method (e.g., slack.chat.postMessage)',
50
- });
51
- }
52
- }
53
-
54
- // Workflow reference validation
55
- if (step.workflow) {
56
- if (!step.workflow.endsWith('.md') && !step.workflow.endsWith('.yaml') && !step.workflow.endsWith('.yml')) {
57
- errors.push({
58
- field: 'workflow',
59
- message: 'Workflow reference should end with .md, .yaml, or .yml',
60
- });
61
- }
62
- }
63
-
64
- // Output variable name validation
65
- if (step.outputVariable) {
66
- if (!/^[a-zA-Z][a-zA-Z0-9_]*$/.test(step.outputVariable)) {
67
- errors.push({
68
- field: 'outputVariable',
69
- message: 'Output variable must start with a letter and contain only letters, numbers, and underscores',
70
- });
71
- }
72
- }
73
-
74
- // Timeout validation
75
- if (step.timeout !== undefined) {
76
- if (typeof step.timeout !== 'number' || step.timeout <= 0) {
77
- errors.push({
78
- field: 'timeout',
79
- message: 'Timeout must be a positive number',
80
- });
81
- }
82
- }
83
-
84
- // Error handling validation
85
- if (step.errorHandling) {
86
- const validActions = ['stop', 'continue', 'retry'];
87
- if (!validActions.includes(step.errorHandling.action)) {
88
- errors.push({
89
- field: 'errorHandling.action',
90
- message: 'Error action must be one of: stop, continue, retry',
91
- });
92
- }
93
-
94
- if (step.errorHandling.action === 'retry') {
95
- if (step.errorHandling.maxRetries !== undefined) {
96
- if (typeof step.errorHandling.maxRetries !== 'number' || step.errorHandling.maxRetries < 1) {
97
- errors.push({
98
- field: 'errorHandling.maxRetries',
99
- message: 'Max retries must be at least 1',
100
- });
101
- }
102
- }
103
-
104
- if (step.errorHandling.retryDelay !== undefined) {
105
- if (typeof step.errorHandling.retryDelay !== 'number' || step.errorHandling.retryDelay < 0) {
106
- errors.push({
107
- field: 'errorHandling.retryDelay',
108
- message: 'Retry delay must be a non-negative number',
109
- });
110
- }
111
- }
112
- }
113
-
114
- if (step.errorHandling.fallbackStep) {
115
- if (!/^[a-zA-Z][a-zA-Z0-9_-]*$/.test(step.errorHandling.fallbackStep)) {
116
- errors.push({
117
- field: 'errorHandling.fallbackStep',
118
- message: 'Fallback step ID must be a valid identifier',
119
- });
120
- }
121
- }
122
- }
123
-
124
- // Conditions validation
125
- if (step.conditions && step.conditions.length > 0) {
126
- step.conditions.forEach((condition, index) => {
127
- if (!condition || condition.trim() === '') {
128
- errors.push({
129
- field: `conditions[${index}]`,
130
- message: `Condition ${index + 1} cannot be empty`,
131
- });
132
- }
133
- });
134
- }
135
-
136
- return {
137
- valid: errors.length === 0,
138
- errors,
139
- };
140
- }
141
-
142
- /**
143
- * Get validation errors for a specific field
144
- */
145
- export function getFieldError(errors: ValidationError[], field: string): string | undefined {
146
- const error = errors.find((e) => e.field === field);
147
- return error?.message;
148
- }
149
-
150
- /**
151
- * Check if a field has validation errors
152
- */
153
- export function hasFieldError(errors: ValidationError[], field: string): boolean {
154
- return errors.some((e) => e.field === field);
155
- }
@@ -1,299 +0,0 @@
1
- import type { Node, Edge } from '@xyflow/react';
2
-
3
- interface WorkflowStep {
4
- id: string;
5
- name?: string;
6
- action?: string;
7
- workflow?: string;
8
- inputs: Record<string, unknown>;
9
- outputVariable?: string;
10
- conditions?: string[];
11
- }
12
-
13
- interface WorkflowTrigger {
14
- type: 'manual' | 'schedule' | 'webhook' | 'event';
15
- cron?: string;
16
- path?: string;
17
- events?: string[];
18
- }
19
-
20
- interface Workflow {
21
- metadata: {
22
- id: string;
23
- name: string;
24
- };
25
- steps: WorkflowStep[];
26
- triggers?: WorkflowTrigger[];
27
- }
28
-
29
- interface GraphResult {
30
- nodes: Node[];
31
- edges: Edge[];
32
- }
33
-
34
- /**
35
- * Converts a marktoflow Workflow to React Flow nodes and edges
36
- */
37
- export function workflowToGraph(workflow: Workflow): GraphResult {
38
- const nodes: Node[] = [];
39
- const edges: Edge[] = [];
40
-
41
- const VERTICAL_SPACING = 120;
42
- const HORIZONTAL_OFFSET = 250;
43
- let currentY = 0;
44
-
45
- // Add trigger node if triggers are defined
46
- if (workflow.triggers && workflow.triggers.length > 0) {
47
- const trigger = workflow.triggers[0]; // Primary trigger
48
- const triggerId = `trigger-${workflow.metadata.id}`;
49
-
50
- nodes.push({
51
- id: triggerId,
52
- type: 'trigger',
53
- position: { x: HORIZONTAL_OFFSET, y: currentY },
54
- data: {
55
- id: triggerId,
56
- name: workflow.metadata.name,
57
- type: trigger.type || 'manual',
58
- cron: trigger.cron,
59
- path: trigger.path,
60
- events: trigger.events,
61
- active: true,
62
- },
63
- });
64
-
65
- currentY += VERTICAL_SPACING;
66
-
67
- // Edge from trigger to first step
68
- if (workflow.steps.length > 0) {
69
- edges.push({
70
- id: `e-${triggerId}-${workflow.steps[0].id}`,
71
- source: triggerId,
72
- target: workflow.steps[0].id,
73
- type: 'smoothstep',
74
- animated: false,
75
- style: { stroke: '#ff6d5a', strokeWidth: 2 },
76
- });
77
- }
78
- }
79
-
80
- // Create nodes for each step
81
- workflow.steps.forEach((step, index) => {
82
- const isSubWorkflow = !!step.workflow;
83
-
84
- const node: Node = {
85
- id: step.id,
86
- type: isSubWorkflow ? 'subworkflow' : 'step',
87
- position: {
88
- x: HORIZONTAL_OFFSET,
89
- y: currentY + index * VERTICAL_SPACING,
90
- },
91
- data: {
92
- id: step.id,
93
- name: step.name,
94
- action: step.action,
95
- workflowPath: step.workflow,
96
- status: 'pending',
97
- },
98
- };
99
-
100
- nodes.push(node);
101
-
102
- // Create edge to next step
103
- if (index < workflow.steps.length - 1) {
104
- const nextStep = workflow.steps[index + 1];
105
- const edge: Edge = {
106
- id: `e-${step.id}-${nextStep.id}`,
107
- source: step.id,
108
- target: nextStep.id,
109
- type: 'smoothstep',
110
- animated: false,
111
- style: { stroke: '#ff6d5a', strokeWidth: 2 },
112
- };
113
-
114
- // Add condition label if present
115
- if (nextStep.conditions && nextStep.conditions.length > 0) {
116
- edge.label = 'conditional';
117
- edge.labelStyle = { fill: '#a0a0c0', fontSize: 10 };
118
- edge.labelBgStyle = { fill: '#232340' };
119
- }
120
-
121
- edges.push(edge);
122
- }
123
- });
124
-
125
- // Add output node at the end
126
- if (workflow.steps.length > 0) {
127
- const outputId = `output-${workflow.metadata.id}`;
128
- const lastStep = workflow.steps[workflow.steps.length - 1];
129
- const outputY = currentY + workflow.steps.length * VERTICAL_SPACING;
130
-
131
- // Collect all output variables
132
- const outputVariables = workflow.steps
133
- .filter((s) => s.outputVariable)
134
- .map((s) => s.outputVariable as string);
135
-
136
- nodes.push({
137
- id: outputId,
138
- type: 'output',
139
- position: { x: HORIZONTAL_OFFSET, y: outputY },
140
- data: {
141
- id: outputId,
142
- name: 'Workflow Output',
143
- variables: outputVariables,
144
- status: 'pending',
145
- },
146
- });
147
-
148
- // Edge from last step to output
149
- edges.push({
150
- id: `e-${lastStep.id}-${outputId}`,
151
- source: lastStep.id,
152
- target: outputId,
153
- type: 'smoothstep',
154
- animated: false,
155
- style: { stroke: '#ff6d5a', strokeWidth: 2 },
156
- });
157
- }
158
-
159
- // Add data flow edges based on variable references
160
- const variableEdges = findVariableDependencies(workflow.steps);
161
- edges.push(...variableEdges);
162
-
163
- return { nodes, edges };
164
- }
165
-
166
- /**
167
- * Finds variable dependencies between steps
168
- * Creates additional edges showing data flow
169
- */
170
- function findVariableDependencies(steps: WorkflowStep[]): Edge[] {
171
- const edges: Edge[] = [];
172
- const outputVariables = new Map<string, string>(); // variable name -> step id
173
-
174
- // First pass: collect all output variables
175
- steps.forEach((step) => {
176
- if (step.outputVariable) {
177
- outputVariables.set(step.outputVariable, step.id);
178
- }
179
- });
180
-
181
- // Second pass: find references in inputs
182
- steps.forEach((step) => {
183
- const references = findTemplateVariables(step.inputs);
184
-
185
- references.forEach((ref) => {
186
- // Extract the root variable name (e.g., "pr_details" from "pr_details.title")
187
- const rootVar = ref.split('.')[0];
188
-
189
- // Check if this references an output variable
190
- const sourceStepId = outputVariables.get(rootVar);
191
- if (sourceStepId && sourceStepId !== step.id) {
192
- // Create data flow edge
193
- const edgeId = `data-${sourceStepId}-${step.id}-${rootVar}`;
194
-
195
- // Check if edge already exists
196
- if (!edges.find((e) => e.id === edgeId)) {
197
- edges.push({
198
- id: edgeId,
199
- source: sourceStepId,
200
- target: step.id,
201
- type: 'smoothstep',
202
- animated: true,
203
- style: {
204
- stroke: '#5bc0de',
205
- strokeWidth: 1,
206
- strokeDasharray: '5,5',
207
- },
208
- label: rootVar,
209
- labelStyle: { fill: '#5bc0de', fontSize: 9 },
210
- labelBgStyle: { fill: '#1a1a2e', fillOpacity: 0.8 },
211
- });
212
- }
213
- }
214
- });
215
- });
216
-
217
- return edges;
218
- }
219
-
220
- /**
221
- * Extracts template variable references from inputs
222
- */
223
- function findTemplateVariables(inputs: Record<string, unknown>): string[] {
224
- const variables: string[] = [];
225
- const templateRegex = /\{\{\s*([^}]+)\s*\}\}/g;
226
-
227
- function extractFromValue(value: unknown): void {
228
- if (typeof value === 'string') {
229
- let match;
230
- while ((match = templateRegex.exec(value)) !== null) {
231
- // Extract variable name, removing any method calls
232
- const varExpr = match[1].trim();
233
- const varName = varExpr.split('.')[0].replace(/\[.*\]/, '');
234
-
235
- // Filter out 'inputs' as those are workflow inputs, not step outputs
236
- if (varName !== 'inputs' && !variables.includes(varName)) {
237
- variables.push(varName);
238
- }
239
- }
240
- } else if (Array.isArray(value)) {
241
- value.forEach(extractFromValue);
242
- } else if (value && typeof value === 'object') {
243
- Object.values(value).forEach(extractFromValue);
244
- }
245
- }
246
-
247
- Object.values(inputs).forEach(extractFromValue);
248
- return variables;
249
- }
250
-
251
- /**
252
- * Converts React Flow nodes and edges back to a Workflow
253
- */
254
- export function graphToWorkflow(
255
- nodes: Node[],
256
- _edges: Edge[],
257
- metadata: Workflow['metadata']
258
- ): Workflow {
259
- // Filter out trigger and output nodes, sort by vertical position
260
- const stepNodes = nodes
261
- .filter((node) => node.type === 'step' || node.type === 'subworkflow')
262
- .sort((a, b) => a.position.y - b.position.y);
263
-
264
- // Extract trigger info if present
265
- const triggerNode = nodes.find((node) => node.type === 'trigger');
266
- const triggers: WorkflowTrigger[] = [];
267
-
268
- if (triggerNode) {
269
- const data = triggerNode.data as Record<string, unknown>;
270
- triggers.push({
271
- type: (data.type as WorkflowTrigger['type']) || 'manual',
272
- cron: data.cron as string | undefined,
273
- path: data.path as string | undefined,
274
- events: data.events as string[] | undefined,
275
- });
276
- }
277
-
278
- const steps: WorkflowStep[] = stepNodes.map((node) => {
279
- const data = node.data as Record<string, unknown>;
280
- const step: WorkflowStep = {
281
- id: (data.id as string) || node.id,
282
- inputs: (data.inputs as Record<string, unknown>) || {},
283
- };
284
-
285
- if (data.name) step.name = data.name as string;
286
- if (data.action) step.action = data.action as string;
287
- if (data.workflowPath) step.workflow = data.workflowPath as string;
288
- if (data.outputVariable) step.outputVariable = data.outputVariable as string;
289
- if (data.conditions) step.conditions = data.conditions as string[];
290
-
291
- return step;
292
- });
293
-
294
- return {
295
- metadata,
296
- steps,
297
- triggers: triggers.length > 0 ? triggers : undefined,
298
- };
299
- }
@@ -1,114 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import express from 'express';
4
- import cors from 'cors';
5
- import { createServer, type Server } from 'http';
6
- import { Server as SocketIOServer } from 'socket.io';
7
- import { join } from 'path';
8
- import { existsSync } from 'fs';
9
- import { workflowRoutes } from './routes/workflows.js';
10
- import { aiRoutes } from './routes/ai.js';
11
- import { executeRoutes } from './routes/execute.js';
12
- import { toolsRoutes } from './routes/tools.js';
13
- import { setupWebSocket } from './websocket/index.js';
14
- import { FileWatcher } from './services/FileWatcher.js';
15
-
16
- export interface ServerOptions {
17
- port?: number;
18
- workflowDir?: string;
19
- staticDir?: string;
20
- }
21
-
22
- let httpServer: Server | null = null;
23
- let fileWatcher: FileWatcher | null = null;
24
-
25
- /**
26
- * Start the GUI server programmatically
27
- */
28
- export async function startServer(options: ServerOptions = {}): Promise<Server> {
29
- const PORT = options.port || parseInt(process.env.PORT || '3001', 10);
30
- const WORKFLOW_DIR = options.workflowDir || process.env.WORKFLOW_DIR || process.cwd();
31
- const STATIC_DIR = options.staticDir || process.env.STATIC_DIR;
32
-
33
- const app = express();
34
- httpServer = createServer(app);
35
- const io = new SocketIOServer(httpServer, {
36
- cors: {
37
- origin: ['http://localhost:5173', 'http://localhost:3000', `http://localhost:${PORT}`],
38
- methods: ['GET', 'POST'],
39
- },
40
- });
41
-
42
- // Middleware
43
- app.use(cors());
44
- app.use(express.json());
45
-
46
- // Routes
47
- app.use('/api/workflows', workflowRoutes);
48
- app.use('/api/ai', aiRoutes);
49
- app.use('/api/execute', executeRoutes);
50
- app.use('/api/tools', toolsRoutes);
51
-
52
- // Health check
53
- app.get('/api/health', (_req, res) => {
54
- res.json({ status: 'ok', version: '2.0.0-alpha.2' });
55
- });
56
-
57
- // Serve static files if static dir is provided
58
- if (STATIC_DIR && existsSync(STATIC_DIR)) {
59
- app.use(express.static(STATIC_DIR));
60
- // SPA fallback
61
- app.get('*', (_req, res) => {
62
- res.sendFile(join(STATIC_DIR, 'index.html'));
63
- });
64
- }
65
-
66
- // WebSocket
67
- setupWebSocket(io);
68
-
69
- // File watcher for live updates
70
- fileWatcher = new FileWatcher(WORKFLOW_DIR, io);
71
-
72
- return new Promise((resolve) => {
73
- httpServer!.listen(PORT, () => {
74
- console.log(`
75
- ╔══════════════════════════════════════════════════════════╗
76
- ║ ║
77
- ║ Marktoflow GUI Server ║
78
- ║ ║
79
- ║ Server: http://localhost:${String(PORT).padEnd(25)}║
80
- ║ Workflows: ${WORKFLOW_DIR.slice(0, 40).padEnd(40)}║
81
- ║ ║
82
- ╚══════════════════════════════════════════════════════════╝
83
- `);
84
- resolve(httpServer!);
85
- });
86
- });
87
- }
88
-
89
- /**
90
- * Stop the GUI server
91
- */
92
- export function stopServer(): void {
93
- if (fileWatcher) {
94
- fileWatcher.stop();
95
- fileWatcher = null;
96
- }
97
- if (httpServer) {
98
- httpServer.close();
99
- httpServer = null;
100
- }
101
- }
102
-
103
- // Graceful shutdown
104
- process.on('SIGINT', () => {
105
- console.log('\nShutting down...');
106
- stopServer();
107
- process.exit(0);
108
- });
109
-
110
- // Auto-start if run directly
111
- const isDirectRun = process.argv[1]?.endsWith('index.js') || process.argv[1]?.endsWith('index.ts');
112
- if (isDirectRun) {
113
- startServer();
114
- }
@@ -1,91 +0,0 @@
1
- import { Router, type Router as RouterType } from 'express';
2
- import { AIService } from '../services/AIService.js';
3
-
4
- const router: RouterType = Router();
5
- const aiService = new AIService();
6
-
7
- // Process AI prompt
8
- router.post('/prompt', async (req, res) => {
9
- try {
10
- const { prompt, workflow } = req.body;
11
-
12
- if (!prompt) {
13
- return res.status(400).json({ error: 'Prompt is required' });
14
- }
15
-
16
- const result = await aiService.processPrompt(prompt, workflow);
17
- res.json(result);
18
- } catch (error) {
19
- res.status(500).json({
20
- error: 'Failed to process prompt',
21
- message: error instanceof Error ? error.message : 'Unknown error',
22
- });
23
- }
24
- });
25
-
26
- // Get prompt history
27
- router.get('/history', async (_req, res) => {
28
- try {
29
- const history = await aiService.getHistory();
30
- res.json({ history });
31
- } catch (error) {
32
- res.status(500).json({
33
- error: 'Failed to get history',
34
- message: error instanceof Error ? error.message : 'Unknown error',
35
- });
36
- }
37
- });
38
-
39
- // Get AI suggestions for current context
40
- router.post('/suggestions', async (req, res) => {
41
- try {
42
- const { workflow, selectedStepId } = req.body;
43
- const suggestions = await aiService.getSuggestions(workflow, selectedStepId);
44
- res.json({ suggestions });
45
- } catch (error) {
46
- res.status(500).json({
47
- error: 'Failed to get suggestions',
48
- message: error instanceof Error ? error.message : 'Unknown error',
49
- });
50
- }
51
- });
52
-
53
- // Get available AI providers and status
54
- router.get('/providers', async (_req, res) => {
55
- try {
56
- const status = aiService.getStatus();
57
- res.json(status);
58
- } catch (error) {
59
- res.status(500).json({
60
- error: 'Failed to get providers',
61
- message: error instanceof Error ? error.message : 'Unknown error',
62
- });
63
- }
64
- });
65
-
66
- // Set active AI provider
67
- router.post('/providers/:providerId', async (req, res) => {
68
- try {
69
- const { providerId } = req.params;
70
- const { apiKey, baseUrl, model } = req.body;
71
-
72
- const success = await aiService.setProvider(providerId, { apiKey, baseUrl, model });
73
-
74
- if (success) {
75
- const status = aiService.getStatus();
76
- res.json({ success: true, status });
77
- } else {
78
- res.status(400).json({
79
- error: 'Failed to set provider',
80
- message: `Provider "${providerId}" is not available or failed to initialize`,
81
- });
82
- }
83
- } catch (error) {
84
- res.status(500).json({
85
- error: 'Failed to set provider',
86
- message: error instanceof Error ? error.message : 'Unknown error',
87
- });
88
- }
89
- });
90
-
91
- export { router as aiRoutes };