@marktoflow/gui 2.0.0-alpha.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/.turbo/turbo-build.log +26 -0
- package/.turbo/turbo-test.log +22 -0
- package/README.md +179 -0
- package/dist/client/assets/index-DwTI8opO.js +608 -0
- package/dist/client/assets/index-DwTI8opO.js.map +1 -0
- package/dist/client/assets/index-RoEdL6gO.css +1 -0
- package/dist/client/index.html +20 -0
- package/dist/client/vite.svg +9 -0
- package/dist/server/index.d.ts +3 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +56 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/routes/ai.js +50 -0
- package/dist/server/routes/ai.js.map +1 -0
- package/dist/server/routes/execute.js +62 -0
- package/dist/server/routes/execute.js.map +1 -0
- package/dist/server/routes/workflows.js +99 -0
- package/dist/server/routes/workflows.js.map +1 -0
- package/dist/server/server/index.js +95 -0
- package/dist/server/server/index.js.map +1 -0
- package/dist/server/server/routes/ai.js +87 -0
- package/dist/server/server/routes/ai.js.map +1 -0
- package/dist/server/server/routes/execute.js +63 -0
- package/dist/server/server/routes/execute.js.map +1 -0
- package/dist/server/server/routes/tools.js +518 -0
- package/dist/server/server/routes/tools.js.map +1 -0
- package/dist/server/server/routes/workflows.js +99 -0
- package/dist/server/server/routes/workflows.js.map +1 -0
- package/dist/server/server/services/AIService.js +69 -0
- package/dist/server/server/services/AIService.js.map +1 -0
- package/dist/server/server/services/FileWatcher.js +60 -0
- package/dist/server/server/services/FileWatcher.js.map +1 -0
- package/dist/server/server/services/WorkflowService.js +363 -0
- package/dist/server/server/services/WorkflowService.js.map +1 -0
- package/dist/server/server/services/agents/claude-code-provider.js +250 -0
- package/dist/server/server/services/agents/claude-code-provider.js.map +1 -0
- package/dist/server/server/services/agents/claude-provider.js +204 -0
- package/dist/server/server/services/agents/claude-provider.js.map +1 -0
- package/dist/server/server/services/agents/copilot-provider.js +227 -0
- package/dist/server/server/services/agents/copilot-provider.js.map +1 -0
- package/dist/server/server/services/agents/demo-provider.js +167 -0
- package/dist/server/server/services/agents/demo-provider.js.map +1 -0
- package/dist/server/server/services/agents/index.js +31 -0
- package/dist/server/server/services/agents/index.js.map +1 -0
- package/dist/server/server/services/agents/ollama-provider.js +220 -0
- package/dist/server/server/services/agents/ollama-provider.js.map +1 -0
- package/dist/server/server/services/agents/prompts.js +436 -0
- package/dist/server/server/services/agents/prompts.js.map +1 -0
- package/dist/server/server/services/agents/registry.js +242 -0
- package/dist/server/server/services/agents/registry.js.map +1 -0
- package/dist/server/server/services/agents/types.js +6 -0
- package/dist/server/server/services/agents/types.js.map +1 -0
- package/dist/server/server/websocket/index.js +85 -0
- package/dist/server/server/websocket/index.js.map +1 -0
- package/dist/server/services/AIService.d.ts +30 -0
- package/dist/server/services/AIService.d.ts.map +1 -0
- package/dist/server/services/AIService.js +216 -0
- package/dist/server/services/AIService.js.map +1 -0
- package/dist/server/services/FileWatcher.d.ts +10 -0
- package/dist/server/services/FileWatcher.d.ts.map +1 -0
- package/dist/server/services/FileWatcher.js +62 -0
- package/dist/server/services/FileWatcher.js.map +1 -0
- package/dist/server/services/WorkflowService.d.ts +54 -0
- package/dist/server/services/WorkflowService.d.ts.map +1 -0
- package/dist/server/services/WorkflowService.js +323 -0
- package/dist/server/services/WorkflowService.js.map +1 -0
- package/dist/server/shared/constants.js +175 -0
- package/dist/server/shared/constants.js.map +1 -0
- package/dist/server/shared/types.js +3 -0
- package/dist/server/shared/types.js.map +1 -0
- package/dist/server/websocket/index.d.ts +10 -0
- package/dist/server/websocket/index.d.ts.map +1 -0
- package/dist/server/websocket/index.js +85 -0
- package/dist/server/websocket/index.js.map +1 -0
- package/index.html +19 -0
- package/package.json +96 -0
- package/playwright.config.ts +27 -0
- package/postcss.config.js +6 -0
- package/public/vite.svg +9 -0
- package/src/client/App.tsx +520 -0
- package/src/client/components/Canvas/Canvas.tsx +405 -0
- package/src/client/components/Canvas/ExecutionOverlay.tsx +847 -0
- package/src/client/components/Canvas/NodeContextMenu.tsx +188 -0
- package/src/client/components/Canvas/OutputNode.tsx +111 -0
- package/src/client/components/Canvas/StepNode.tsx +106 -0
- package/src/client/components/Canvas/SubWorkflowNode.tsx +141 -0
- package/src/client/components/Canvas/Toolbar.tsx +189 -0
- package/src/client/components/Canvas/TriggerNode.tsx +128 -0
- package/src/client/components/Editor/InputsEditor.tsx +458 -0
- package/src/client/components/Editor/NewStepWizard.tsx +344 -0
- package/src/client/components/Editor/StepEditor.tsx +532 -0
- package/src/client/components/Editor/YamlEditor.tsx +160 -0
- package/src/client/components/Panels/PropertiesPanel.tsx +589 -0
- package/src/client/components/Prompt/ChangePreview.tsx +281 -0
- package/src/client/components/Prompt/PromptHistoryPanel.tsx +209 -0
- package/src/client/components/Prompt/PromptInput.tsx +108 -0
- package/src/client/components/Sidebar/Sidebar.tsx +343 -0
- package/src/client/components/common/Breadcrumb.tsx +40 -0
- package/src/client/components/common/Button.tsx +68 -0
- package/src/client/components/common/ContextMenu.tsx +202 -0
- package/src/client/components/common/KeyboardShortcuts.tsx +143 -0
- package/src/client/components/common/Modal.tsx +93 -0
- package/src/client/components/common/Tabs.tsx +57 -0
- package/src/client/components/common/ThemeToggle.tsx +63 -0
- package/src/client/components/index.ts +32 -0
- package/src/client/hooks/index.ts +4 -0
- package/src/client/hooks/useAIPrompt.ts +108 -0
- package/src/client/hooks/useCanvas.ts +247 -0
- package/src/client/hooks/useWebSocket.ts +164 -0
- package/src/client/hooks/useWorkflow.ts +138 -0
- package/src/client/main.tsx +10 -0
- package/src/client/stores/canvasStore.ts +348 -0
- package/src/client/stores/editorStore.ts +133 -0
- package/src/client/stores/executionStore.ts +440 -0
- package/src/client/stores/index.ts +4 -0
- package/src/client/stores/layoutStore.ts +103 -0
- package/src/client/stores/navigationStore.ts +49 -0
- package/src/client/stores/promptStore.ts +113 -0
- package/src/client/stores/themeStore.ts +75 -0
- package/src/client/stores/workflowStore.ts +177 -0
- package/src/client/styles/globals.css +346 -0
- package/src/client/utils/cn.ts +9 -0
- package/src/client/utils/index.ts +4 -0
- package/src/client/utils/serviceIcons.tsx +64 -0
- package/src/client/utils/stepValidation.ts +155 -0
- package/src/client/utils/workflowToGraph.ts +299 -0
- package/src/server/index.ts +114 -0
- package/src/server/routes/ai.ts +91 -0
- package/src/server/routes/execute.ts +71 -0
- package/src/server/routes/tools.ts +564 -0
- package/src/server/routes/workflows.ts +106 -0
- package/src/server/services/AIService.ts +105 -0
- package/src/server/services/FileWatcher.ts +69 -0
- package/src/server/services/WorkflowService.ts +441 -0
- package/src/server/services/agents/claude-code-provider.ts +320 -0
- package/src/server/services/agents/claude-provider.ts +248 -0
- package/src/server/services/agents/copilot-provider.ts +311 -0
- package/src/server/services/agents/demo-provider.ts +184 -0
- package/src/server/services/agents/index.ts +31 -0
- package/src/server/services/agents/ollama-provider.ts +267 -0
- package/src/server/services/agents/prompts.ts +482 -0
- package/src/server/services/agents/registry.ts +289 -0
- package/src/server/services/agents/types.ts +146 -0
- package/src/server/websocket/index.ts +104 -0
- package/src/shared/constants.ts +180 -0
- package/src/shared/types.ts +179 -0
- package/tailwind.config.ts +73 -0
- package/tests/e2e/app.spec.ts +90 -0
- package/tests/e2e/canvas.spec.ts +128 -0
- package/tests/e2e/workflow.spec.ts +185 -0
- package/tests/integration/api.test.ts +250 -0
- package/tests/integration/testApp.ts +31 -0
- package/tests/setup.ts +37 -0
- package/tests/unit/canvasStore.test.ts +502 -0
- package/tests/unit/components.test.tsx +151 -0
- package/tests/unit/executionStore.test.ts +527 -0
- package/tests/unit/layoutStore.test.ts +194 -0
- package/tests/unit/navigationStore.test.ts +152 -0
- package/tests/unit/stepValidation.test.ts +226 -0
- package/tests/unit/themeStore.test.ts +141 -0
- package/tests/unit/workflowToGraph.test.ts +289 -0
- package/tsconfig.json +29 -0
- package/tsconfig.server.json +28 -0
- package/vite.config.ts +31 -0
- package/vitest.config.ts +26 -0
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
import { readdir, readFile, writeFile, unlink, mkdir } from 'fs/promises';
|
|
2
|
+
import { join, relative, dirname } from 'path';
|
|
3
|
+
import { existsSync } from 'fs';
|
|
4
|
+
import { stringify as yamlStringify } from 'yaml';
|
|
5
|
+
// Import from @marktoflow/core for proper parsing
|
|
6
|
+
import { parseFile as coreParseFile } from '@marktoflow/core';
|
|
7
|
+
|
|
8
|
+
interface WorkflowListItem {
|
|
9
|
+
path: string;
|
|
10
|
+
name: string;
|
|
11
|
+
description?: string;
|
|
12
|
+
version?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface WorkflowMetadata {
|
|
16
|
+
id: string;
|
|
17
|
+
name: string;
|
|
18
|
+
version?: string;
|
|
19
|
+
description?: string;
|
|
20
|
+
author?: string;
|
|
21
|
+
tags?: string[];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface WorkflowStep {
|
|
25
|
+
id: string;
|
|
26
|
+
name?: string;
|
|
27
|
+
action?: string;
|
|
28
|
+
workflow?: string;
|
|
29
|
+
inputs: Record<string, unknown>;
|
|
30
|
+
outputVariable?: string;
|
|
31
|
+
conditions?: string[];
|
|
32
|
+
errorHandling?: {
|
|
33
|
+
action: 'stop' | 'continue' | 'retry';
|
|
34
|
+
maxRetries?: number;
|
|
35
|
+
retryDelay?: number;
|
|
36
|
+
fallbackStep?: string;
|
|
37
|
+
};
|
|
38
|
+
timeout?: number;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
interface Workflow {
|
|
42
|
+
metadata: WorkflowMetadata;
|
|
43
|
+
steps: WorkflowStep[];
|
|
44
|
+
tools?: Record<string, unknown>;
|
|
45
|
+
inputs?: Record<string, unknown>;
|
|
46
|
+
triggers?: unknown[];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export class WorkflowService {
|
|
50
|
+
private workflowDir: string;
|
|
51
|
+
|
|
52
|
+
constructor(workflowDir?: string) {
|
|
53
|
+
this.workflowDir = workflowDir || process.env.WORKFLOW_DIR || process.cwd();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async listWorkflows(): Promise<WorkflowListItem[]> {
|
|
57
|
+
const workflows: WorkflowListItem[] = [];
|
|
58
|
+
const baseDir = this.workflowDir;
|
|
59
|
+
|
|
60
|
+
async function scanDirectory(dir: string) {
|
|
61
|
+
try {
|
|
62
|
+
const entries = await readdir(dir, { withFileTypes: true });
|
|
63
|
+
|
|
64
|
+
for (const entry of entries) {
|
|
65
|
+
const fullPath = join(dir, entry.name);
|
|
66
|
+
|
|
67
|
+
// Skip hidden directories and node_modules
|
|
68
|
+
if (entry.name.startsWith('.') || entry.name === 'node_modules' || entry.name === 'dist') {
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (entry.isDirectory()) {
|
|
73
|
+
await scanDirectory(fullPath);
|
|
74
|
+
} else if (
|
|
75
|
+
entry.isFile() &&
|
|
76
|
+
(entry.name.endsWith('.md') || entry.name.endsWith('.yaml') || entry.name.endsWith('.yml'))
|
|
77
|
+
) {
|
|
78
|
+
// Check if it's a workflow file by looking for frontmatter
|
|
79
|
+
try {
|
|
80
|
+
const content = await readFile(fullPath, 'utf-8');
|
|
81
|
+
if (content.includes('workflow:') || content.includes('steps:')) {
|
|
82
|
+
const relativePath = relative(baseDir, fullPath);
|
|
83
|
+
const workflowInfo = extractWorkflowInfo(content, entry.name);
|
|
84
|
+
workflows.push({
|
|
85
|
+
path: relativePath,
|
|
86
|
+
...workflowInfo,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
} catch {
|
|
90
|
+
// Skip files that can't be read
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
} catch {
|
|
95
|
+
// Skip directories we can't read
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
await scanDirectory(this.workflowDir);
|
|
100
|
+
return workflows.sort((a, b) => a.name.localeCompare(b.name));
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
async getWorkflow(workflowPath: string): Promise<Workflow | null> {
|
|
104
|
+
const fullPath = this.resolvePath(workflowPath);
|
|
105
|
+
|
|
106
|
+
if (!existsSync(fullPath)) {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
try {
|
|
111
|
+
// Use core parser for proper workflow parsing
|
|
112
|
+
const result = await coreParseFile(fullPath);
|
|
113
|
+
if (result.warnings && result.warnings.length > 0) {
|
|
114
|
+
console.warn(`Workflow ${workflowPath} has parsing warnings:`, result.warnings);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Convert core Workflow type to GUI Workflow type
|
|
118
|
+
return this.convertCoreWorkflow(result.workflow, workflowPath);
|
|
119
|
+
} catch (error) {
|
|
120
|
+
console.error(`Error parsing workflow ${workflowPath}:`, error);
|
|
121
|
+
// Fallback to local parsing if core parser fails
|
|
122
|
+
try {
|
|
123
|
+
const content = await readFile(fullPath, 'utf-8');
|
|
124
|
+
return this.parseWorkflow(content, workflowPath);
|
|
125
|
+
} catch {
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
private convertCoreWorkflow(coreWorkflow: any, path: string): Workflow {
|
|
132
|
+
return {
|
|
133
|
+
metadata: {
|
|
134
|
+
id: coreWorkflow.metadata?.id || path,
|
|
135
|
+
name: coreWorkflow.metadata?.name || path,
|
|
136
|
+
version: coreWorkflow.metadata?.version,
|
|
137
|
+
description: coreWorkflow.metadata?.description,
|
|
138
|
+
author: coreWorkflow.metadata?.author,
|
|
139
|
+
tags: coreWorkflow.metadata?.tags,
|
|
140
|
+
},
|
|
141
|
+
steps: (coreWorkflow.steps || []).map((step: any) => ({
|
|
142
|
+
id: step.id,
|
|
143
|
+
name: step.name,
|
|
144
|
+
action: step.action,
|
|
145
|
+
workflow: step.workflow,
|
|
146
|
+
inputs: step.inputs || {},
|
|
147
|
+
outputVariable: step.outputVariable || step.output_variable,
|
|
148
|
+
conditions: step.conditions,
|
|
149
|
+
errorHandling: step.errorHandling || step.error_handling,
|
|
150
|
+
timeout: step.timeout,
|
|
151
|
+
})),
|
|
152
|
+
tools: coreWorkflow.tools,
|
|
153
|
+
inputs: coreWorkflow.inputs,
|
|
154
|
+
triggers: coreWorkflow.triggers,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
async createWorkflow(name: string, template?: string): Promise<WorkflowListItem> {
|
|
159
|
+
const filename = name.toLowerCase().replace(/\s+/g, '-').replace(/[^a-z0-9-]/g, '') + '.md';
|
|
160
|
+
const workflowPath = join('workflows', filename);
|
|
161
|
+
const fullPath = join(this.workflowDir, workflowPath);
|
|
162
|
+
|
|
163
|
+
// Ensure directory exists
|
|
164
|
+
await mkdir(dirname(fullPath), { recursive: true });
|
|
165
|
+
|
|
166
|
+
const content = template || this.generateWorkflowTemplate(name);
|
|
167
|
+
await writeFile(fullPath, content, 'utf-8');
|
|
168
|
+
|
|
169
|
+
return {
|
|
170
|
+
path: workflowPath,
|
|
171
|
+
name,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
async updateWorkflow(workflowPath: string, workflow: Workflow): Promise<Workflow> {
|
|
176
|
+
const fullPath = this.resolvePath(workflowPath);
|
|
177
|
+
|
|
178
|
+
// Read original file to preserve markdown content
|
|
179
|
+
let markdownContent = '';
|
|
180
|
+
if (existsSync(fullPath)) {
|
|
181
|
+
const originalContent = await readFile(fullPath, 'utf-8');
|
|
182
|
+
const match = originalContent.match(/^---\n[\s\S]*?\n---\n([\s\S]*)$/);
|
|
183
|
+
if (match) {
|
|
184
|
+
markdownContent = match[1];
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const content = this.serializeWorkflow(workflow, markdownContent);
|
|
189
|
+
await writeFile(fullPath, content, 'utf-8');
|
|
190
|
+
return workflow;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
async deleteWorkflow(workflowPath: string): Promise<void> {
|
|
194
|
+
const fullPath = this.resolvePath(workflowPath);
|
|
195
|
+
if (existsSync(fullPath)) {
|
|
196
|
+
await unlink(fullPath);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
async getExecutionHistory(_workflowPath: string): Promise<unknown[]> {
|
|
201
|
+
// TODO: Query state store for execution history
|
|
202
|
+
// This will integrate with @marktoflow/core StateStore
|
|
203
|
+
return [];
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
private resolvePath(workflowPath: string): string {
|
|
207
|
+
// Handle both absolute and relative paths
|
|
208
|
+
if (workflowPath.startsWith('/')) {
|
|
209
|
+
return workflowPath;
|
|
210
|
+
}
|
|
211
|
+
return join(this.workflowDir, workflowPath);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
private parseWorkflow(content: string, path: string): Workflow {
|
|
215
|
+
// Extract YAML frontmatter
|
|
216
|
+
const frontmatterMatch = content.match(/^---\n([\s\S]*?)\n---/);
|
|
217
|
+
|
|
218
|
+
if (!frontmatterMatch) {
|
|
219
|
+
return {
|
|
220
|
+
metadata: { id: path, name: path },
|
|
221
|
+
steps: [],
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const yaml = frontmatterMatch[1];
|
|
226
|
+
|
|
227
|
+
// Parse the YAML manually for now (will use @marktoflow/core parser when integrated)
|
|
228
|
+
const workflow: Workflow = {
|
|
229
|
+
metadata: { id: path, name: path },
|
|
230
|
+
steps: [],
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
// Extract workflow metadata
|
|
234
|
+
const workflowSection = yaml.match(/workflow:\s*\n((?: .*\n)*)/);
|
|
235
|
+
if (workflowSection) {
|
|
236
|
+
const idMatch = workflowSection[1].match(/id:\s*(\S+)/);
|
|
237
|
+
const nameMatch = workflowSection[1].match(/name:\s*["']?(.+?)["']?\s*$/m);
|
|
238
|
+
const versionMatch = workflowSection[1].match(/version:\s*["']?(.+?)["']?\s*$/m);
|
|
239
|
+
const descMatch = workflowSection[1].match(/description:\s*["']?(.+?)["']?\s*$/m);
|
|
240
|
+
const authorMatch = workflowSection[1].match(/author:\s*["']?(.+?)["']?\s*$/m);
|
|
241
|
+
|
|
242
|
+
if (idMatch) workflow.metadata.id = idMatch[1].trim();
|
|
243
|
+
if (nameMatch) workflow.metadata.name = nameMatch[1].trim();
|
|
244
|
+
if (versionMatch) workflow.metadata.version = versionMatch[1].trim();
|
|
245
|
+
if (descMatch) workflow.metadata.description = descMatch[1].trim();
|
|
246
|
+
if (authorMatch) workflow.metadata.author = authorMatch[1].trim();
|
|
247
|
+
|
|
248
|
+
// Extract tags
|
|
249
|
+
const tagsMatch = workflowSection[1].match(/tags:\s*\[(.*?)\]/);
|
|
250
|
+
if (tagsMatch) {
|
|
251
|
+
workflow.metadata.tags = tagsMatch[1]
|
|
252
|
+
.split(',')
|
|
253
|
+
.map((t) => t.trim().replace(/["']/g, ''))
|
|
254
|
+
.filter(Boolean);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// Extract steps using regex to find step blocks
|
|
259
|
+
const stepsSection = yaml.match(/steps:\s*\n((?: - [\s\S]*?)(?=\n\w|$))/);
|
|
260
|
+
if (stepsSection) {
|
|
261
|
+
const stepBlocks = stepsSection[1].split(/\n - /).filter(Boolean);
|
|
262
|
+
|
|
263
|
+
for (const block of stepBlocks) {
|
|
264
|
+
const stepText = block.startsWith('id:') ? block : block;
|
|
265
|
+
const step = this.parseStep(stepText);
|
|
266
|
+
if (step) {
|
|
267
|
+
workflow.steps.push(step);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// Extract tools
|
|
273
|
+
const toolsMatch = yaml.match(/tools:\s*\n((?: .*\n)*)/);
|
|
274
|
+
if (toolsMatch) {
|
|
275
|
+
// Simple extraction - will be enhanced with proper YAML parser
|
|
276
|
+
workflow.tools = {};
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// Extract inputs
|
|
280
|
+
const inputsMatch = yaml.match(/inputs:\s*\n((?: .*\n)*)/);
|
|
281
|
+
if (inputsMatch) {
|
|
282
|
+
workflow.inputs = {};
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
return workflow;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
private parseStep(stepText: string): WorkflowStep | null {
|
|
289
|
+
const idMatch = stepText.match(/id:\s*(\S+)/);
|
|
290
|
+
if (!idMatch) return null;
|
|
291
|
+
|
|
292
|
+
const step: WorkflowStep = {
|
|
293
|
+
id: idMatch[1],
|
|
294
|
+
inputs: {},
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
const nameMatch = stepText.match(/name:\s*["']?(.+?)["']?\s*$/m);
|
|
298
|
+
if (nameMatch) step.name = nameMatch[1];
|
|
299
|
+
|
|
300
|
+
const actionMatch = stepText.match(/action:\s*(\S+)/);
|
|
301
|
+
if (actionMatch) step.action = actionMatch[1];
|
|
302
|
+
|
|
303
|
+
const workflowMatch = stepText.match(/workflow:\s*(\S+)/);
|
|
304
|
+
if (workflowMatch) step.workflow = workflowMatch[1];
|
|
305
|
+
|
|
306
|
+
const outputMatch = stepText.match(/output_variable:\s*(\S+)/);
|
|
307
|
+
if (outputMatch) step.outputVariable = outputMatch[1];
|
|
308
|
+
|
|
309
|
+
const timeoutMatch = stepText.match(/timeout:\s*(\d+)/);
|
|
310
|
+
if (timeoutMatch) step.timeout = parseInt(timeoutMatch[1], 10);
|
|
311
|
+
|
|
312
|
+
// Parse inputs (simplified)
|
|
313
|
+
const inputsMatch = stepText.match(/inputs:\s*\n((?: .*\n)*)/);
|
|
314
|
+
if (inputsMatch) {
|
|
315
|
+
const inputLines = inputsMatch[1].split('\n').filter(Boolean);
|
|
316
|
+
for (const line of inputLines) {
|
|
317
|
+
const kvMatch = line.match(/^\s*(\w+):\s*(.+)$/);
|
|
318
|
+
if (kvMatch) {
|
|
319
|
+
let value: unknown = kvMatch[2].trim();
|
|
320
|
+
// Remove quotes if present
|
|
321
|
+
if ((value as string).startsWith("'") && (value as string).endsWith("'")) {
|
|
322
|
+
value = (value as string).slice(1, -1);
|
|
323
|
+
} else if ((value as string).startsWith('"') && (value as string).endsWith('"')) {
|
|
324
|
+
value = (value as string).slice(1, -1);
|
|
325
|
+
}
|
|
326
|
+
step.inputs[kvMatch[1]] = value;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
return step;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
private serializeWorkflow(workflow: Workflow, markdownContent: string = ''): string {
|
|
335
|
+
const frontmatter: Record<string, unknown> = {
|
|
336
|
+
workflow: {
|
|
337
|
+
id: workflow.metadata.id,
|
|
338
|
+
name: workflow.metadata.name,
|
|
339
|
+
version: workflow.metadata.version || '1.0.0',
|
|
340
|
+
description: workflow.metadata.description || '',
|
|
341
|
+
author: workflow.metadata.author || '',
|
|
342
|
+
tags: workflow.metadata.tags || [],
|
|
343
|
+
},
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
if (workflow.tools && Object.keys(workflow.tools).length > 0) {
|
|
347
|
+
frontmatter.tools = workflow.tools;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
if (workflow.inputs && Object.keys(workflow.inputs).length > 0) {
|
|
351
|
+
frontmatter.inputs = workflow.inputs;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
if (workflow.triggers && workflow.triggers.length > 0) {
|
|
355
|
+
frontmatter.triggers = workflow.triggers;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// Serialize steps
|
|
359
|
+
frontmatter.steps = workflow.steps.map((step) => {
|
|
360
|
+
const stepObj: Record<string, unknown> = {
|
|
361
|
+
id: step.id,
|
|
362
|
+
};
|
|
363
|
+
|
|
364
|
+
if (step.name) stepObj.name = step.name;
|
|
365
|
+
if (step.action) stepObj.action = step.action;
|
|
366
|
+
if (step.workflow) stepObj.workflow = step.workflow;
|
|
367
|
+
if (Object.keys(step.inputs).length > 0) stepObj.inputs = step.inputs;
|
|
368
|
+
if (step.outputVariable) stepObj.output_variable = step.outputVariable;
|
|
369
|
+
if (step.conditions && step.conditions.length > 0) stepObj.conditions = step.conditions;
|
|
370
|
+
if (step.errorHandling) stepObj.error_handling = step.errorHandling;
|
|
371
|
+
if (step.timeout) stepObj.timeout = step.timeout;
|
|
372
|
+
|
|
373
|
+
return stepObj;
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
const yaml = yamlStringify(frontmatter, {
|
|
377
|
+
indent: 2,
|
|
378
|
+
lineWidth: 0,
|
|
379
|
+
defaultKeyType: 'PLAIN',
|
|
380
|
+
defaultStringType: 'QUOTE_DOUBLE',
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
// Generate markdown if not provided
|
|
384
|
+
if (!markdownContent.trim()) {
|
|
385
|
+
markdownContent = `\n# ${workflow.metadata.name}\n\n${workflow.metadata.description || ''}\n`;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
return `---\n${yaml}---${markdownContent}`;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
private generateWorkflowTemplate(name: string): string {
|
|
392
|
+
const id = name.toLowerCase().replace(/\s+/g, '-').replace(/[^a-z0-9-]/g, '');
|
|
393
|
+
|
|
394
|
+
return `---
|
|
395
|
+
workflow:
|
|
396
|
+
id: ${id}
|
|
397
|
+
name: "${name}"
|
|
398
|
+
version: "1.0.0"
|
|
399
|
+
description: ""
|
|
400
|
+
author: ""
|
|
401
|
+
tags: []
|
|
402
|
+
|
|
403
|
+
inputs: {}
|
|
404
|
+
|
|
405
|
+
steps:
|
|
406
|
+
- id: step-1
|
|
407
|
+
name: "First Step"
|
|
408
|
+
action: http.request
|
|
409
|
+
inputs:
|
|
410
|
+
url: "https://api.example.com"
|
|
411
|
+
method: "GET"
|
|
412
|
+
output_variable: result
|
|
413
|
+
---
|
|
414
|
+
|
|
415
|
+
# ${name}
|
|
416
|
+
|
|
417
|
+
Describe your workflow here.
|
|
418
|
+
|
|
419
|
+
## Steps
|
|
420
|
+
|
|
421
|
+
### Step 1: First Step
|
|
422
|
+
|
|
423
|
+
This step makes an HTTP request to the API.
|
|
424
|
+
`;
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
function extractWorkflowInfo(
|
|
429
|
+
content: string,
|
|
430
|
+
filename: string
|
|
431
|
+
): { name: string; description?: string; version?: string } {
|
|
432
|
+
const nameMatch = content.match(/name:\s*["']?(.+?)["']?\s*$/m);
|
|
433
|
+
const descMatch = content.match(/description:\s*["']?(.+?)["']?\s*$/m);
|
|
434
|
+
const versionMatch = content.match(/version:\s*["']?(.+?)["']?\s*$/m);
|
|
435
|
+
|
|
436
|
+
return {
|
|
437
|
+
name: nameMatch?.[1]?.trim() || filename.replace(/\.(md|yaml|yml)$/, '').replace(/-/g, ' '),
|
|
438
|
+
description: descMatch?.[1]?.trim(),
|
|
439
|
+
version: versionMatch?.[1]?.trim(),
|
|
440
|
+
};
|
|
441
|
+
}
|