@marktoflow/gui 2.0.0-alpha.5 → 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.
- package/README.md +48 -180
- package/client.log +0 -0
- package/dist/client/assets/index-DQeR1ew6.css +1 -0
- package/dist/client/assets/index-LbIVPHbD.js +833 -0
- package/dist/client/assets/index-LbIVPHbD.js.map +1 -0
- package/dist/client/index.html +2 -2
- package/dist/client/marktoflow-logo.png +0 -0
- package/dist/server/index.js +31 -5
- package/dist/server/index.js.map +1 -1
- package/dist/server/routes/admin.js +95 -0
- package/dist/server/routes/admin.js.map +1 -0
- package/dist/server/routes/ai.js +2 -2
- package/dist/server/routes/ai.js.map +1 -1
- package/dist/server/routes/collaboration.js +104 -0
- package/dist/server/routes/collaboration.js.map +1 -0
- package/dist/server/routes/execute.js +181 -14
- package/dist/server/routes/execute.js.map +1 -1
- package/dist/server/routes/form.js +160 -0
- package/dist/server/routes/form.js.map +1 -0
- package/dist/server/routes/settings.js +90 -0
- package/dist/server/routes/settings.js.map +1 -0
- package/dist/server/routes/templates.js +106 -0
- package/dist/server/routes/templates.js.map +1 -0
- package/dist/server/routes/versions.js +101 -0
- package/dist/server/routes/versions.js.map +1 -0
- package/dist/server/services/AIService.js +85 -2
- package/dist/server/services/AIService.js.map +1 -1
- package/dist/server/services/ExecutionManager.js +571 -0
- package/dist/server/services/ExecutionManager.js.map +1 -0
- package/dist/server/services/VersionService.js +65 -0
- package/dist/server/services/VersionService.js.map +1 -0
- package/dist/server/services/WorkflowService.js +8 -2
- package/dist/server/services/WorkflowService.js.map +1 -1
- package/dist/server/services/agents/copilot-provider.js +32 -0
- package/dist/server/services/agents/copilot-provider.js.map +1 -1
- package/dist/server/websocket/index.js +42 -0
- package/dist/server/websocket/index.js.map +1 -1
- package/dist/shared/constants.js +9 -0
- package/dist/shared/constants.js.map +1 -1
- package/dist/shared/settings.js +51 -0
- package/dist/shared/settings.js.map +1 -0
- package/package.json +14 -10
- package/public/marktoflow-logo.png +0 -0
- package/server.log +0 -0
- package/tests/integration/fixtures/test-workflow.md +6 -0
- package/.turbo/turbo-build.log +0 -42
- package/dist/client/assets/index-CM44OayM.js +0 -704
- package/dist/client/assets/index-CM44OayM.js.map +0 -1
- package/dist/client/assets/index-Dru63gi6.css +0 -1
- package/marktoflow-gui-2.0.0-alpha.5.tgz +0 -0
- package/playwright.config.ts +0 -27
- package/postcss.config.js +0 -6
- package/src/client/App.tsx +0 -520
- package/src/client/components/Canvas/Canvas.tsx +0 -425
- package/src/client/components/Canvas/ExecutionOverlay.tsx +0 -935
- package/src/client/components/Canvas/ForEachNode.tsx +0 -152
- package/src/client/components/Canvas/IfElseNode.tsx +0 -141
- package/src/client/components/Canvas/NodeContextMenu.tsx +0 -192
- package/src/client/components/Canvas/OutputNode.tsx +0 -111
- package/src/client/components/Canvas/ParallelNode.tsx +0 -157
- package/src/client/components/Canvas/StepNode.tsx +0 -106
- package/src/client/components/Canvas/SubWorkflowNode.tsx +0 -141
- package/src/client/components/Canvas/SwitchNode.tsx +0 -185
- package/src/client/components/Canvas/Toolbar.tsx +0 -227
- package/src/client/components/Canvas/TransformNode.tsx +0 -194
- package/src/client/components/Canvas/TriggerNode.tsx +0 -128
- package/src/client/components/Canvas/TryCatchNode.tsx +0 -164
- package/src/client/components/Canvas/WhileNode.tsx +0 -161
- package/src/client/components/Canvas/index.ts +0 -24
- package/src/client/components/Debug/VariableInspector.tsx +0 -148
- package/src/client/components/Editor/InputsEditor.tsx +0 -458
- package/src/client/components/Editor/NewStepWizard.tsx +0 -344
- package/src/client/components/Editor/StepEditor.tsx +0 -532
- package/src/client/components/Editor/YamlEditor.tsx +0 -160
- package/src/client/components/Panels/PropertiesPanel.tsx +0 -589
- package/src/client/components/Prompt/ChangePreview.tsx +0 -281
- package/src/client/components/Prompt/PromptHistoryPanel.tsx +0 -209
- package/src/client/components/Prompt/PromptInput.tsx +0 -110
- package/src/client/components/Settings/ProviderSwitcher.tsx +0 -228
- package/src/client/components/Sidebar/ImportDialog.tsx +0 -257
- package/src/client/components/Sidebar/Sidebar.tsx +0 -362
- package/src/client/components/common/Breadcrumb.tsx +0 -40
- package/src/client/components/common/Button.tsx +0 -68
- package/src/client/components/common/ContextMenu.tsx +0 -202
- package/src/client/components/common/KeyboardShortcuts.tsx +0 -149
- package/src/client/components/common/Modal.tsx +0 -93
- package/src/client/components/common/Tabs.tsx +0 -57
- package/src/client/components/common/ThemeToggle.tsx +0 -63
- package/src/client/components/index.ts +0 -32
- package/src/client/hooks/index.ts +0 -4
- package/src/client/hooks/useAIPrompt.ts +0 -108
- package/src/client/hooks/useCanvas.ts +0 -247
- package/src/client/hooks/useWebSocket.ts +0 -164
- package/src/client/hooks/useWorkflow.ts +0 -138
- package/src/client/main.tsx +0 -10
- package/src/client/stores/agentStore.ts +0 -109
- package/src/client/stores/canvasStore.ts +0 -348
- package/src/client/stores/editorStore.ts +0 -133
- package/src/client/stores/executionStore.ts +0 -502
- package/src/client/stores/index.ts +0 -4
- package/src/client/stores/layoutStore.ts +0 -103
- package/src/client/stores/navigationStore.ts +0 -49
- package/src/client/stores/promptStore.ts +0 -113
- package/src/client/stores/themeStore.ts +0 -75
- package/src/client/stores/workflowStore.ts +0 -185
- package/src/client/styles/globals.css +0 -452
- package/src/client/utils/cn.ts +0 -9
- package/src/client/utils/index.ts +0 -4
- package/src/client/utils/platform.ts +0 -46
- package/src/client/utils/serviceIcons.tsx +0 -97
- package/src/client/utils/stepValidation.ts +0 -155
- package/src/client/utils/workflowToGraph.ts +0 -523
- package/src/server/index.ts +0 -137
- package/src/server/routes/ai.ts +0 -91
- package/src/server/routes/execute.ts +0 -71
- package/src/server/routes/executions.ts +0 -136
- package/src/server/routes/tools.ts +0 -970
- package/src/server/routes/workflows.ts +0 -147
- package/src/server/services/AIService.ts +0 -105
- package/src/server/services/FileWatcher.ts +0 -69
- package/src/server/services/WorkflowService.ts +0 -601
- package/src/server/services/agents/claude-code-provider.ts +0 -320
- package/src/server/services/agents/claude-provider.ts +0 -248
- package/src/server/services/agents/codex-provider.ts +0 -398
- package/src/server/services/agents/copilot-provider.ts +0 -311
- package/src/server/services/agents/demo-provider.ts +0 -184
- package/src/server/services/agents/index.ts +0 -31
- package/src/server/services/agents/ollama-provider.ts +0 -267
- package/src/server/services/agents/prompts.ts +0 -509
- package/src/server/services/agents/registry.ts +0 -310
- package/src/server/services/agents/types.ts +0 -146
- package/src/server/websocket/index.ts +0 -117
- package/src/shared/constants.ts +0 -180
- package/src/shared/types.ts +0 -179
- package/tailwind.config.ts +0 -73
- package/tests/e2e/app.spec.ts +0 -90
- package/tests/e2e/canvas.spec.ts +0 -128
- package/tests/e2e/workflow.spec.ts +0 -185
- package/tests/integration/api.test.ts +0 -452
- package/tests/integration/testApp.ts +0 -31
- package/tests/setup.ts +0 -72
- package/tests/unit/ForEachNode.test.tsx +0 -308
- package/tests/unit/IfElseNode.test.tsx +0 -235
- package/tests/unit/ParallelNode.test.tsx +0 -344
- package/tests/unit/SwitchNode.test.tsx +0 -327
- package/tests/unit/TransformNode.test.tsx +0 -386
- package/tests/unit/TryCatchNode.test.tsx +0 -243
- package/tests/unit/WhileNode.test.tsx +0 -230
- package/tests/unit/agentStore.test.ts +0 -218
- package/tests/unit/canvasStore.test.ts +0 -502
- package/tests/unit/codexProvider.test.ts +0 -399
- package/tests/unit/components.test.tsx +0 -151
- package/tests/unit/executionStore.test.ts +0 -567
- package/tests/unit/layoutStore.test.ts +0 -194
- package/tests/unit/navigationStore.test.ts +0 -152
- package/tests/unit/platform.test.ts +0 -118
- package/tests/unit/serviceIcons.test.ts +0 -197
- package/tests/unit/stepValidation.test.ts +0 -226
- package/tests/unit/themeStore.test.ts +0 -141
- package/tests/unit/workflowToGraph.test.ts +0 -311
- package/tsconfig.json +0 -29
- package/tsconfig.server.json +0 -28
- package/vite.config.ts +0 -31
- package/vitest.config.ts +0 -26
|
@@ -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,523 +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
|
-
type?: 'while' | 'for_each' | 'for' | 'switch' | 'parallel' | 'try' | 'if' | 'map' | 'filter' | 'reduce';
|
|
9
|
-
condition?: string;
|
|
10
|
-
items?: string;
|
|
11
|
-
maxIterations?: number;
|
|
12
|
-
inputs: Record<string, unknown>;
|
|
13
|
-
outputVariable?: string;
|
|
14
|
-
conditions?: string[];
|
|
15
|
-
steps?: WorkflowStep[];
|
|
16
|
-
variables?: Record<string, { initial: unknown }>;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
interface WorkflowTrigger {
|
|
20
|
-
type: 'manual' | 'schedule' | 'webhook' | 'event';
|
|
21
|
-
cron?: string;
|
|
22
|
-
path?: string;
|
|
23
|
-
events?: string[];
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
interface Workflow {
|
|
27
|
-
metadata: {
|
|
28
|
-
id: string;
|
|
29
|
-
name: string;
|
|
30
|
-
};
|
|
31
|
-
steps: WorkflowStep[];
|
|
32
|
-
triggers?: WorkflowTrigger[];
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
interface GraphResult {
|
|
36
|
-
nodes: Node[];
|
|
37
|
-
edges: Edge[];
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Parse control flow constructs from raw markdown content
|
|
42
|
-
* This is a temporary solution until the core parser supports control flow
|
|
43
|
-
*/
|
|
44
|
-
function extractControlFlowFromMarkdown(markdown?: string): WorkflowStep[] {
|
|
45
|
-
if (!markdown) return [];
|
|
46
|
-
|
|
47
|
-
const controlFlowSteps: WorkflowStep[] = [];
|
|
48
|
-
// Match YAML code blocks that contain control flow types
|
|
49
|
-
const codeBlockRegex = /```yaml\s*\n([\s\S]*?)\n```/g;
|
|
50
|
-
let match;
|
|
51
|
-
let stepIndex = 0;
|
|
52
|
-
|
|
53
|
-
while ((match = codeBlockRegex.exec(markdown)) !== null) {
|
|
54
|
-
const yamlContent = match[1];
|
|
55
|
-
|
|
56
|
-
// Check if this is a control flow block
|
|
57
|
-
const typeMatch = yamlContent.match(/^type:\s*(while|for_each|for|switch|parallel|try|if|map|filter|reduce)/m);
|
|
58
|
-
if (typeMatch) {
|
|
59
|
-
const type = typeMatch[1] as WorkflowStep['type'];
|
|
60
|
-
const id = `control-flow-${type}-${stepIndex++}`;
|
|
61
|
-
|
|
62
|
-
// Extract common properties
|
|
63
|
-
const conditionMatch = yamlContent.match(/condition:\s*["'](.+?)["']/);
|
|
64
|
-
const itemsMatch = yamlContent.match(/items:\s*["'](.+?)["']/);
|
|
65
|
-
const maxIterMatch = yamlContent.match(/max_iterations:\s*(\d+)/);
|
|
66
|
-
const expressionMatch = yamlContent.match(/expression:\s*["'](.+?)["']/);
|
|
67
|
-
const itemVarMatch = yamlContent.match(/item_variable:\s*(\w+)/);
|
|
68
|
-
|
|
69
|
-
// Extract switch expression
|
|
70
|
-
const switchExprMatch = yamlContent.match(/expression:\s*["'](.+?)["']/);
|
|
71
|
-
|
|
72
|
-
// Extract variables for while loops
|
|
73
|
-
const variables: Record<string, { initial: unknown }> = {};
|
|
74
|
-
const varsMatch = yamlContent.match(/variables:\s*\n((?: .*\n)*)/);
|
|
75
|
-
if (varsMatch) {
|
|
76
|
-
const varsContent = varsMatch[1];
|
|
77
|
-
const varLines = varsContent.split('\n').filter(Boolean);
|
|
78
|
-
varLines.forEach(line => {
|
|
79
|
-
const varMatch = line.match(/^\s+(\w+):\s*$/);
|
|
80
|
-
if (varMatch) {
|
|
81
|
-
const varName = varMatch[1];
|
|
82
|
-
// Try to find initial value on next line
|
|
83
|
-
const initMatch = varsContent.match(new RegExp(`${varName}:\\s*\\n\\s+initial:\\s*(.+)`));
|
|
84
|
-
if (initMatch) {
|
|
85
|
-
try {
|
|
86
|
-
variables[varName] = { initial: JSON.parse(initMatch[1]) };
|
|
87
|
-
} catch {
|
|
88
|
-
variables[varName] = { initial: initMatch[1].trim() };
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// Build step data based on type
|
|
96
|
-
const step: WorkflowStep = {
|
|
97
|
-
id,
|
|
98
|
-
type,
|
|
99
|
-
name: type === 'map' ? 'Map Transform' :
|
|
100
|
-
type === 'filter' ? 'Filter Transform' :
|
|
101
|
-
type === 'reduce' ? 'Reduce Transform' :
|
|
102
|
-
type === 'switch' ? 'Switch/Case' :
|
|
103
|
-
type === 'parallel' ? 'Parallel Execution' :
|
|
104
|
-
type === 'try' ? 'Try/Catch' :
|
|
105
|
-
type === 'if' ? 'If/Else' :
|
|
106
|
-
`${type.charAt(0).toUpperCase() + type.slice(1)} Loop`,
|
|
107
|
-
inputs: {},
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
// Add type-specific properties
|
|
111
|
-
if (conditionMatch) step.condition = conditionMatch[1];
|
|
112
|
-
if (itemsMatch) step.items = itemsMatch[1];
|
|
113
|
-
if (maxIterMatch) step.maxIterations = parseInt(maxIterMatch[1], 10);
|
|
114
|
-
if (Object.keys(variables).length > 0) step.variables = variables;
|
|
115
|
-
|
|
116
|
-
// Transform-specific properties
|
|
117
|
-
if (type === 'map' || type === 'filter' || type === 'reduce') {
|
|
118
|
-
if (itemVarMatch) {
|
|
119
|
-
step.inputs = { ...step.inputs, itemVariable: itemVarMatch[1] };
|
|
120
|
-
}
|
|
121
|
-
if (expressionMatch) {
|
|
122
|
-
step.inputs = { ...step.inputs, expression: expressionMatch[1] };
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// Switch-specific properties
|
|
127
|
-
if (type === 'switch' && switchExprMatch) {
|
|
128
|
-
step.inputs = { ...step.inputs, expression: switchExprMatch[1] };
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
controlFlowSteps.push(step);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return controlFlowSteps;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Converts a marktoflow Workflow to React Flow nodes and edges
|
|
140
|
-
*/
|
|
141
|
-
export function workflowToGraph(workflow: Workflow & { markdown?: string }): GraphResult {
|
|
142
|
-
const nodes: Node[] = [];
|
|
143
|
-
const edges: Edge[] = [];
|
|
144
|
-
|
|
145
|
-
const VERTICAL_SPACING = 180;
|
|
146
|
-
const HORIZONTAL_OFFSET = 250;
|
|
147
|
-
let currentY = 0;
|
|
148
|
-
|
|
149
|
-
// Try to extract control flow from markdown if available
|
|
150
|
-
const controlFlowSteps = extractControlFlowFromMarkdown(workflow.markdown);
|
|
151
|
-
const allSteps = [...workflow.steps, ...controlFlowSteps];
|
|
152
|
-
|
|
153
|
-
// Add trigger node if triggers are defined
|
|
154
|
-
if (workflow.triggers && workflow.triggers.length > 0) {
|
|
155
|
-
const trigger = workflow.triggers[0]; // Primary trigger
|
|
156
|
-
const triggerId = `trigger-${workflow.metadata.id}`;
|
|
157
|
-
|
|
158
|
-
nodes.push({
|
|
159
|
-
id: triggerId,
|
|
160
|
-
type: 'trigger',
|
|
161
|
-
position: { x: HORIZONTAL_OFFSET, y: currentY },
|
|
162
|
-
data: {
|
|
163
|
-
id: triggerId,
|
|
164
|
-
name: workflow.metadata.name,
|
|
165
|
-
type: trigger.type || 'manual',
|
|
166
|
-
cron: trigger.cron,
|
|
167
|
-
path: trigger.path,
|
|
168
|
-
events: trigger.events,
|
|
169
|
-
active: true,
|
|
170
|
-
},
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
currentY += VERTICAL_SPACING;
|
|
174
|
-
|
|
175
|
-
// Edge from trigger to first step
|
|
176
|
-
if (allSteps.length > 0) {
|
|
177
|
-
edges.push({
|
|
178
|
-
id: `e-${triggerId}-${allSteps[0].id}`,
|
|
179
|
-
source: triggerId,
|
|
180
|
-
target: allSteps[0].id,
|
|
181
|
-
type: 'smoothstep',
|
|
182
|
-
animated: false,
|
|
183
|
-
style: { stroke: '#ff6d5a', strokeWidth: 2 },
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
// Create nodes for each step
|
|
189
|
-
allSteps.forEach((step, index) => {
|
|
190
|
-
const isSubWorkflow = !!step.workflow;
|
|
191
|
-
const isControlFlow = !!step.type && ['while', 'for_each', 'for', 'switch', 'parallel', 'try', 'if', 'map', 'filter', 'reduce'].includes(step.type);
|
|
192
|
-
|
|
193
|
-
let nodeType = 'step';
|
|
194
|
-
if (isSubWorkflow) {
|
|
195
|
-
nodeType = 'subworkflow';
|
|
196
|
-
} else if (isControlFlow) {
|
|
197
|
-
nodeType = step.type!;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
// Build node data based on type
|
|
201
|
-
const baseData = {
|
|
202
|
-
id: step.id,
|
|
203
|
-
name: step.name,
|
|
204
|
-
action: step.action,
|
|
205
|
-
workflowPath: step.workflow,
|
|
206
|
-
status: 'pending' as const,
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
// Add control-flow specific data
|
|
210
|
-
let nodeData = { ...baseData };
|
|
211
|
-
if (step.type === 'while') {
|
|
212
|
-
nodeData = {
|
|
213
|
-
...baseData,
|
|
214
|
-
condition: step.condition || 'true',
|
|
215
|
-
maxIterations: step.maxIterations || 100,
|
|
216
|
-
variables: step.variables,
|
|
217
|
-
};
|
|
218
|
-
} else if (step.type === 'for_each' || step.type === 'for') {
|
|
219
|
-
nodeData = {
|
|
220
|
-
...baseData,
|
|
221
|
-
items: step.items || '[]',
|
|
222
|
-
itemVariable: step.inputs?.itemVariable as string,
|
|
223
|
-
};
|
|
224
|
-
} else if (step.type === 'switch') {
|
|
225
|
-
nodeData = {
|
|
226
|
-
...baseData,
|
|
227
|
-
expression: step.inputs?.expression as string || step.condition || '',
|
|
228
|
-
cases: {},
|
|
229
|
-
hasDefault: true,
|
|
230
|
-
};
|
|
231
|
-
} else if (step.type === 'parallel') {
|
|
232
|
-
nodeData = {
|
|
233
|
-
...baseData,
|
|
234
|
-
branches: [],
|
|
235
|
-
maxConcurrent: 0,
|
|
236
|
-
};
|
|
237
|
-
} else if (step.type === 'try') {
|
|
238
|
-
nodeData = {
|
|
239
|
-
...baseData,
|
|
240
|
-
hasCatch: true,
|
|
241
|
-
hasFinally: false,
|
|
242
|
-
};
|
|
243
|
-
} else if (step.type === 'if') {
|
|
244
|
-
nodeData = {
|
|
245
|
-
...baseData,
|
|
246
|
-
condition: step.condition || 'true',
|
|
247
|
-
hasElse: true,
|
|
248
|
-
};
|
|
249
|
-
} else if (step.type === 'map' || step.type === 'filter' || step.type === 'reduce') {
|
|
250
|
-
nodeData = {
|
|
251
|
-
...baseData,
|
|
252
|
-
transformType: step.type,
|
|
253
|
-
items: step.items || '[]',
|
|
254
|
-
itemVariable: step.inputs?.itemVariable as string,
|
|
255
|
-
expression: step.inputs?.expression as string,
|
|
256
|
-
condition: step.condition,
|
|
257
|
-
};
|
|
258
|
-
} else {
|
|
259
|
-
// Regular step
|
|
260
|
-
nodeData = {
|
|
261
|
-
...baseData,
|
|
262
|
-
condition: step.condition,
|
|
263
|
-
items: step.items,
|
|
264
|
-
maxIterations: step.maxIterations,
|
|
265
|
-
variables: step.variables,
|
|
266
|
-
};
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
const node: Node = {
|
|
270
|
-
id: step.id,
|
|
271
|
-
type: nodeType,
|
|
272
|
-
position: {
|
|
273
|
-
x: HORIZONTAL_OFFSET,
|
|
274
|
-
y: currentY + index * VERTICAL_SPACING,
|
|
275
|
-
},
|
|
276
|
-
data: nodeData,
|
|
277
|
-
};
|
|
278
|
-
|
|
279
|
-
nodes.push(node);
|
|
280
|
-
|
|
281
|
-
// Create edge to next step
|
|
282
|
-
if (index < allSteps.length - 1) {
|
|
283
|
-
const nextStep = allSteps[index + 1];
|
|
284
|
-
const edge: Edge = {
|
|
285
|
-
id: `e-${step.id}-${nextStep.id}`,
|
|
286
|
-
source: step.id,
|
|
287
|
-
target: nextStep.id,
|
|
288
|
-
type: 'smoothstep',
|
|
289
|
-
animated: false,
|
|
290
|
-
style: { stroke: '#ff6d5a', strokeWidth: 2 },
|
|
291
|
-
};
|
|
292
|
-
|
|
293
|
-
// Add condition label if present
|
|
294
|
-
if (nextStep.conditions && nextStep.conditions.length > 0) {
|
|
295
|
-
edge.label = 'conditional';
|
|
296
|
-
edge.labelStyle = { fill: '#a0a0c0', fontSize: 10 };
|
|
297
|
-
edge.labelBgStyle = { fill: '#232340' };
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
edges.push(edge);
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
// Add loop-back edge for loops
|
|
304
|
-
if (step.type === 'while' || step.type === 'for_each' || step.type === 'for') {
|
|
305
|
-
const loopColor = step.type === 'while' ? '#fb923c' : '#f093fb';
|
|
306
|
-
edges.push({
|
|
307
|
-
id: `e-${step.id}-loop-back`,
|
|
308
|
-
source: step.id,
|
|
309
|
-
target: step.id,
|
|
310
|
-
sourceHandle: 'loop-back',
|
|
311
|
-
type: 'smoothstep',
|
|
312
|
-
animated: true,
|
|
313
|
-
style: {
|
|
314
|
-
stroke: loopColor,
|
|
315
|
-
strokeWidth: 2,
|
|
316
|
-
strokeDasharray: '5,5',
|
|
317
|
-
},
|
|
318
|
-
label: step.type === 'while' ? 'while true' : 'for each item',
|
|
319
|
-
labelStyle: { fill: loopColor, fontSize: 9 },
|
|
320
|
-
labelBgStyle: { fill: '#1a1a2e', fillOpacity: 0.9 },
|
|
321
|
-
});
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
// Add iteration indicator for transform operations (map/filter/reduce)
|
|
325
|
-
if (step.type === 'map' || step.type === 'filter' || step.type === 'reduce') {
|
|
326
|
-
const transformColor = '#14b8a6';
|
|
327
|
-
const label = step.type === 'map' ? 'transform each' :
|
|
328
|
-
step.type === 'filter' ? 'test each' :
|
|
329
|
-
'accumulate';
|
|
330
|
-
edges.push({
|
|
331
|
-
id: `e-${step.id}-transform-flow`,
|
|
332
|
-
source: step.id,
|
|
333
|
-
target: step.id,
|
|
334
|
-
sourceHandle: 'loop-back',
|
|
335
|
-
type: 'smoothstep',
|
|
336
|
-
animated: true,
|
|
337
|
-
style: {
|
|
338
|
-
stroke: transformColor,
|
|
339
|
-
strokeWidth: 1.5,
|
|
340
|
-
strokeDasharray: '3,3',
|
|
341
|
-
},
|
|
342
|
-
label,
|
|
343
|
-
labelStyle: { fill: transformColor, fontSize: 8 },
|
|
344
|
-
labelBgStyle: { fill: '#1a1a2e', fillOpacity: 0.9 },
|
|
345
|
-
});
|
|
346
|
-
}
|
|
347
|
-
});
|
|
348
|
-
|
|
349
|
-
// Add output node at the end
|
|
350
|
-
if (allSteps.length > 0) {
|
|
351
|
-
const outputId = `output-${workflow.metadata.id}`;
|
|
352
|
-
const lastStep = allSteps[allSteps.length - 1];
|
|
353
|
-
const outputY = currentY + allSteps.length * VERTICAL_SPACING;
|
|
354
|
-
|
|
355
|
-
// Collect all output variables
|
|
356
|
-
const outputVariables = allSteps
|
|
357
|
-
.filter((s) => s.outputVariable)
|
|
358
|
-
.map((s) => s.outputVariable as string);
|
|
359
|
-
|
|
360
|
-
nodes.push({
|
|
361
|
-
id: outputId,
|
|
362
|
-
type: 'output',
|
|
363
|
-
position: { x: HORIZONTAL_OFFSET, y: outputY },
|
|
364
|
-
data: {
|
|
365
|
-
id: outputId,
|
|
366
|
-
name: 'Workflow Output',
|
|
367
|
-
variables: outputVariables,
|
|
368
|
-
status: 'pending',
|
|
369
|
-
},
|
|
370
|
-
});
|
|
371
|
-
|
|
372
|
-
// Edge from last step to output
|
|
373
|
-
edges.push({
|
|
374
|
-
id: `e-${lastStep.id}-${outputId}`,
|
|
375
|
-
source: lastStep.id,
|
|
376
|
-
target: outputId,
|
|
377
|
-
type: 'smoothstep',
|
|
378
|
-
animated: false,
|
|
379
|
-
style: { stroke: '#ff6d5a', strokeWidth: 2 },
|
|
380
|
-
});
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
// Add data flow edges based on variable references
|
|
384
|
-
const variableEdges = findVariableDependencies(allSteps);
|
|
385
|
-
edges.push(...variableEdges);
|
|
386
|
-
|
|
387
|
-
return { nodes, edges };
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
/**
|
|
391
|
-
* Finds variable dependencies between steps
|
|
392
|
-
* Creates additional edges showing data flow
|
|
393
|
-
*/
|
|
394
|
-
function findVariableDependencies(steps: WorkflowStep[]): Edge[] {
|
|
395
|
-
const edges: Edge[] = [];
|
|
396
|
-
const outputVariables = new Map<string, string>(); // variable name -> step id
|
|
397
|
-
|
|
398
|
-
// First pass: collect all output variables
|
|
399
|
-
steps.forEach((step) => {
|
|
400
|
-
if (step.outputVariable) {
|
|
401
|
-
outputVariables.set(step.outputVariable, step.id);
|
|
402
|
-
}
|
|
403
|
-
});
|
|
404
|
-
|
|
405
|
-
// Second pass: find references in inputs
|
|
406
|
-
steps.forEach((step) => {
|
|
407
|
-
const references = findTemplateVariables(step.inputs);
|
|
408
|
-
|
|
409
|
-
references.forEach((ref) => {
|
|
410
|
-
// Extract the root variable name (e.g., "pr_details" from "pr_details.title")
|
|
411
|
-
const rootVar = ref.split('.')[0];
|
|
412
|
-
|
|
413
|
-
// Check if this references an output variable
|
|
414
|
-
const sourceStepId = outputVariables.get(rootVar);
|
|
415
|
-
if (sourceStepId && sourceStepId !== step.id) {
|
|
416
|
-
// Create data flow edge
|
|
417
|
-
const edgeId = `data-${sourceStepId}-${step.id}-${rootVar}`;
|
|
418
|
-
|
|
419
|
-
// Check if edge already exists
|
|
420
|
-
if (!edges.find((e) => e.id === edgeId)) {
|
|
421
|
-
edges.push({
|
|
422
|
-
id: edgeId,
|
|
423
|
-
source: sourceStepId,
|
|
424
|
-
target: step.id,
|
|
425
|
-
type: 'smoothstep',
|
|
426
|
-
animated: true,
|
|
427
|
-
style: {
|
|
428
|
-
stroke: '#5bc0de',
|
|
429
|
-
strokeWidth: 1,
|
|
430
|
-
strokeDasharray: '5,5',
|
|
431
|
-
},
|
|
432
|
-
label: rootVar,
|
|
433
|
-
labelStyle: { fill: '#5bc0de', fontSize: 9 },
|
|
434
|
-
labelBgStyle: { fill: '#1a1a2e', fillOpacity: 0.8 },
|
|
435
|
-
});
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
});
|
|
439
|
-
});
|
|
440
|
-
|
|
441
|
-
return edges;
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
/**
|
|
445
|
-
* Extracts template variable references from inputs
|
|
446
|
-
*/
|
|
447
|
-
function findTemplateVariables(inputs: Record<string, unknown>): string[] {
|
|
448
|
-
const variables: string[] = [];
|
|
449
|
-
const templateRegex = /\{\{\s*([^}]+)\s*\}\}/g;
|
|
450
|
-
|
|
451
|
-
function extractFromValue(value: unknown): void {
|
|
452
|
-
if (typeof value === 'string') {
|
|
453
|
-
let match;
|
|
454
|
-
while ((match = templateRegex.exec(value)) !== null) {
|
|
455
|
-
// Extract variable name, removing any method calls
|
|
456
|
-
const varExpr = match[1].trim();
|
|
457
|
-
const varName = varExpr.split('.')[0].replace(/\[.*\]/, '');
|
|
458
|
-
|
|
459
|
-
// Filter out 'inputs' as those are workflow inputs, not step outputs
|
|
460
|
-
if (varName !== 'inputs' && !variables.includes(varName)) {
|
|
461
|
-
variables.push(varName);
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
} else if (Array.isArray(value)) {
|
|
465
|
-
value.forEach(extractFromValue);
|
|
466
|
-
} else if (value && typeof value === 'object') {
|
|
467
|
-
Object.values(value).forEach(extractFromValue);
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
Object.values(inputs).forEach(extractFromValue);
|
|
472
|
-
return variables;
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
/**
|
|
476
|
-
* Converts React Flow nodes and edges back to a Workflow
|
|
477
|
-
*/
|
|
478
|
-
export function graphToWorkflow(
|
|
479
|
-
nodes: Node[],
|
|
480
|
-
_edges: Edge[],
|
|
481
|
-
metadata: Workflow['metadata']
|
|
482
|
-
): Workflow {
|
|
483
|
-
// Filter out trigger and output nodes, sort by vertical position
|
|
484
|
-
const stepNodes = nodes
|
|
485
|
-
.filter((node) => node.type === 'step' || node.type === 'subworkflow')
|
|
486
|
-
.sort((a, b) => a.position.y - b.position.y);
|
|
487
|
-
|
|
488
|
-
// Extract trigger info if present
|
|
489
|
-
const triggerNode = nodes.find((node) => node.type === 'trigger');
|
|
490
|
-
const triggers: WorkflowTrigger[] = [];
|
|
491
|
-
|
|
492
|
-
if (triggerNode) {
|
|
493
|
-
const data = triggerNode.data as Record<string, unknown>;
|
|
494
|
-
triggers.push({
|
|
495
|
-
type: (data.type as WorkflowTrigger['type']) || 'manual',
|
|
496
|
-
cron: data.cron as string | undefined,
|
|
497
|
-
path: data.path as string | undefined,
|
|
498
|
-
events: data.events as string[] | undefined,
|
|
499
|
-
});
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
const steps: WorkflowStep[] = stepNodes.map((node) => {
|
|
503
|
-
const data = node.data as Record<string, unknown>;
|
|
504
|
-
const step: WorkflowStep = {
|
|
505
|
-
id: (data.id as string) || node.id,
|
|
506
|
-
inputs: (data.inputs as Record<string, unknown>) || {},
|
|
507
|
-
};
|
|
508
|
-
|
|
509
|
-
if (data.name) step.name = data.name as string;
|
|
510
|
-
if (data.action) step.action = data.action as string;
|
|
511
|
-
if (data.workflowPath) step.workflow = data.workflowPath as string;
|
|
512
|
-
if (data.outputVariable) step.outputVariable = data.outputVariable as string;
|
|
513
|
-
if (data.conditions) step.conditions = data.conditions as string[];
|
|
514
|
-
|
|
515
|
-
return step;
|
|
516
|
-
});
|
|
517
|
-
|
|
518
|
-
return {
|
|
519
|
-
metadata,
|
|
520
|
-
steps,
|
|
521
|
-
triggers: triggers.length > 0 ? triggers : undefined,
|
|
522
|
-
};
|
|
523
|
-
}
|