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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/package.json +1 -3
  2. package/.marktoflow/state/workflow-state.db +0 -0
  3. package/.marktoflow/state/workflow-state.db-shm +0 -0
  4. package/.marktoflow/state/workflow-state.db-wal +0 -0
  5. package/.turbo/turbo-build.log +0 -42
  6. package/.turbo/turbo-test.log +0 -38
  7. package/marktoflow-gui-2.0.0-alpha.12.tgz +0 -0
  8. package/playwright.config.ts +0 -27
  9. package/postcss.config.js +0 -6
  10. package/src/client/App.tsx +0 -520
  11. package/src/client/components/Canvas/Canvas.tsx +0 -425
  12. package/src/client/components/Canvas/ExecutionOverlay.tsx +0 -935
  13. package/src/client/components/Canvas/ForEachNode.tsx +0 -152
  14. package/src/client/components/Canvas/IfElseNode.tsx +0 -141
  15. package/src/client/components/Canvas/NodeContextMenu.tsx +0 -192
  16. package/src/client/components/Canvas/OutputNode.tsx +0 -111
  17. package/src/client/components/Canvas/ParallelNode.tsx +0 -157
  18. package/src/client/components/Canvas/StepNode.tsx +0 -106
  19. package/src/client/components/Canvas/SubWorkflowNode.tsx +0 -141
  20. package/src/client/components/Canvas/SwitchNode.tsx +0 -185
  21. package/src/client/components/Canvas/Toolbar.tsx +0 -227
  22. package/src/client/components/Canvas/TransformNode.tsx +0 -194
  23. package/src/client/components/Canvas/TriggerNode.tsx +0 -128
  24. package/src/client/components/Canvas/TryCatchNode.tsx +0 -164
  25. package/src/client/components/Canvas/WhileNode.tsx +0 -161
  26. package/src/client/components/Canvas/index.ts +0 -24
  27. package/src/client/components/Debug/VariableInspector.tsx +0 -148
  28. package/src/client/components/Editor/InputsEditor.tsx +0 -458
  29. package/src/client/components/Editor/NewStepWizard.tsx +0 -344
  30. package/src/client/components/Editor/StepEditor.tsx +0 -532
  31. package/src/client/components/Editor/YamlEditor.tsx +0 -160
  32. package/src/client/components/Panels/PropertiesPanel.tsx +0 -589
  33. package/src/client/components/Prompt/ChangePreview.tsx +0 -281
  34. package/src/client/components/Prompt/PromptHistoryPanel.tsx +0 -209
  35. package/src/client/components/Prompt/PromptInput.tsx +0 -110
  36. package/src/client/components/Settings/ProviderSwitcher.tsx +0 -228
  37. package/src/client/components/Sidebar/ImportDialog.tsx +0 -257
  38. package/src/client/components/Sidebar/Sidebar.tsx +0 -362
  39. package/src/client/components/common/Breadcrumb.tsx +0 -40
  40. package/src/client/components/common/Button.tsx +0 -68
  41. package/src/client/components/common/ContextMenu.tsx +0 -202
  42. package/src/client/components/common/KeyboardShortcuts.tsx +0 -149
  43. package/src/client/components/common/Modal.tsx +0 -93
  44. package/src/client/components/common/Tabs.tsx +0 -57
  45. package/src/client/components/common/ThemeToggle.tsx +0 -63
  46. package/src/client/components/index.ts +0 -32
  47. package/src/client/hooks/index.ts +0 -4
  48. package/src/client/hooks/useAIPrompt.ts +0 -108
  49. package/src/client/hooks/useCanvas.ts +0 -247
  50. package/src/client/hooks/useWebSocket.ts +0 -164
  51. package/src/client/hooks/useWorkflow.ts +0 -138
  52. package/src/client/main.tsx +0 -10
  53. package/src/client/stores/agentStore.ts +0 -109
  54. package/src/client/stores/canvasStore.ts +0 -348
  55. package/src/client/stores/editorStore.ts +0 -133
  56. package/src/client/stores/executionStore.ts +0 -502
  57. package/src/client/stores/index.ts +0 -4
  58. package/src/client/stores/layoutStore.ts +0 -103
  59. package/src/client/stores/navigationStore.ts +0 -49
  60. package/src/client/stores/promptStore.ts +0 -113
  61. package/src/client/stores/themeStore.ts +0 -75
  62. package/src/client/stores/workflowStore.ts +0 -185
  63. package/src/client/styles/globals.css +0 -452
  64. package/src/client/utils/cn.ts +0 -9
  65. package/src/client/utils/index.ts +0 -4
  66. package/src/client/utils/platform.ts +0 -46
  67. package/src/client/utils/serviceIcons.tsx +0 -97
  68. package/src/client/utils/stepValidation.ts +0 -155
  69. package/src/client/utils/workflowToGraph.ts +0 -523
  70. package/src/server/index.ts +0 -137
  71. package/src/server/routes/ai.ts +0 -91
  72. package/src/server/routes/execute.ts +0 -71
  73. package/src/server/routes/executions.ts +0 -136
  74. package/src/server/routes/tools.ts +0 -970
  75. package/src/server/routes/workflows.ts +0 -147
  76. package/src/server/services/AIService.ts +0 -105
  77. package/src/server/services/FileWatcher.ts +0 -69
  78. package/src/server/services/WorkflowService.ts +0 -601
  79. package/src/server/services/agents/claude-code-provider.ts +0 -320
  80. package/src/server/services/agents/claude-provider.ts +0 -248
  81. package/src/server/services/agents/codex-provider.ts +0 -398
  82. package/src/server/services/agents/copilot-provider.ts +0 -311
  83. package/src/server/services/agents/demo-provider.ts +0 -184
  84. package/src/server/services/agents/index.ts +0 -31
  85. package/src/server/services/agents/ollama-provider.ts +0 -267
  86. package/src/server/services/agents/prompts.ts +0 -509
  87. package/src/server/services/agents/registry.ts +0 -310
  88. package/src/server/services/agents/types.ts +0 -146
  89. package/src/server/websocket/index.ts +0 -117
  90. package/src/shared/constants.ts +0 -180
  91. package/src/shared/types.ts +0 -179
  92. package/tailwind.config.ts +0 -73
  93. package/tests/e2e/app.spec.ts +0 -90
  94. package/tests/e2e/canvas.spec.ts +0 -128
  95. package/tests/e2e/workflow.spec.ts +0 -185
  96. package/tests/integration/api.test.ts +0 -452
  97. package/tests/integration/testApp.ts +0 -31
  98. package/tests/setup.ts +0 -72
  99. package/tests/unit/ForEachNode.test.tsx +0 -308
  100. package/tests/unit/IfElseNode.test.tsx +0 -235
  101. package/tests/unit/ParallelNode.test.tsx +0 -344
  102. package/tests/unit/SwitchNode.test.tsx +0 -327
  103. package/tests/unit/TransformNode.test.tsx +0 -386
  104. package/tests/unit/TryCatchNode.test.tsx +0 -243
  105. package/tests/unit/WhileNode.test.tsx +0 -230
  106. package/tests/unit/agentStore.test.ts +0 -218
  107. package/tests/unit/canvasStore.test.ts +0 -502
  108. package/tests/unit/codexProvider.test.ts +0 -399
  109. package/tests/unit/components.test.tsx +0 -151
  110. package/tests/unit/executionStore.test.ts +0 -567
  111. package/tests/unit/layoutStore.test.ts +0 -194
  112. package/tests/unit/navigationStore.test.ts +0 -152
  113. package/tests/unit/platform.test.ts +0 -118
  114. package/tests/unit/serviceIcons.test.ts +0 -197
  115. package/tests/unit/stepValidation.test.ts +0 -226
  116. package/tests/unit/themeStore.test.ts +0 -141
  117. package/tests/unit/workflowToGraph.test.ts +0 -311
  118. package/tsconfig.json +0 -29
  119. package/tsconfig.server.json +0 -28
  120. package/vite.config.ts +0 -31
  121. package/vitest.config.ts +0 -26
@@ -1,601 +0,0 @@
1
- import { readdir, readFile, writeFile, unlink, mkdir } from 'fs/promises';
2
- import { join, relative, dirname, basename, extname } from 'path';
3
- import { existsSync } from 'fs';
4
- import { stringify as yamlStringify, parse as yamlParse } from 'yaml';
5
- import AdmZip from 'adm-zip';
6
- // Import from @marktoflow/core for proper parsing
7
- import { parseFile as coreParseFile, type ExecutionRecord } from '@marktoflow/core';
8
- import { getStateStore } from '../index.js';
9
-
10
- interface WorkflowListItem {
11
- path: string;
12
- name: string;
13
- description?: string;
14
- version?: string;
15
- }
16
-
17
- interface WorkflowMetadata {
18
- id: string;
19
- name: string;
20
- version?: string;
21
- description?: string;
22
- author?: string;
23
- tags?: string[];
24
- }
25
-
26
- interface WorkflowStep {
27
- id: string;
28
- name?: string;
29
- action?: string;
30
- workflow?: string;
31
- inputs: Record<string, unknown>;
32
- outputVariable?: string;
33
- conditions?: string[];
34
- errorHandling?: {
35
- action: 'stop' | 'continue' | 'retry';
36
- maxRetries?: number;
37
- retryDelay?: number;
38
- fallbackStep?: string;
39
- };
40
- timeout?: number;
41
- }
42
-
43
- interface Workflow {
44
- metadata: WorkflowMetadata;
45
- steps: WorkflowStep[];
46
- tools?: Record<string, unknown>;
47
- inputs?: Record<string, unknown>;
48
- triggers?: unknown[];
49
- markdown?: string;
50
- }
51
-
52
- export class WorkflowService {
53
- private workflowDir: string;
54
-
55
- constructor(workflowDir?: string) {
56
- this.workflowDir = workflowDir || process.env.WORKFLOW_DIR || process.cwd();
57
- }
58
-
59
- async listWorkflows(): Promise<WorkflowListItem[]> {
60
- const workflows: WorkflowListItem[] = [];
61
- const baseDir = this.workflowDir;
62
-
63
- async function scanDirectory(dir: string) {
64
- try {
65
- const entries = await readdir(dir, { withFileTypes: true });
66
-
67
- for (const entry of entries) {
68
- const fullPath = join(dir, entry.name);
69
-
70
- // Skip hidden directories and node_modules
71
- if (entry.name.startsWith('.') || entry.name === 'node_modules' || entry.name === 'dist') {
72
- continue;
73
- }
74
-
75
- if (entry.isDirectory()) {
76
- await scanDirectory(fullPath);
77
- } else if (
78
- entry.isFile() &&
79
- (entry.name.endsWith('.md') || entry.name.endsWith('.yaml') || entry.name.endsWith('.yml'))
80
- ) {
81
- // Skip README files (they're documentation, not workflows)
82
- if (entry.name.toLowerCase() === 'readme.md') {
83
- continue;
84
- }
85
-
86
- // Check if it's a workflow file by verifying YAML frontmatter
87
- try {
88
- const content = await readFile(fullPath, 'utf-8');
89
-
90
- // For markdown files, verify it has YAML frontmatter
91
- if (entry.name.endsWith('.md')) {
92
- if (!content.trimStart().startsWith('---\n')) {
93
- continue;
94
- }
95
- const frontmatterMatch = content.match(/^---\n[\s\S]*?\n---/);
96
- if (!frontmatterMatch) {
97
- continue;
98
- }
99
- const frontmatter = frontmatterMatch[0];
100
- if (!frontmatter.includes('workflow:') && !frontmatter.includes('steps:')) {
101
- continue;
102
- }
103
- } else {
104
- // For YAML files, check if they contain workflow structure
105
- if (!content.includes('workflow:') && !content.includes('steps:')) {
106
- continue;
107
- }
108
- }
109
-
110
- const relativePath = relative(baseDir, fullPath);
111
- const workflowInfo = extractWorkflowInfo(content, entry.name);
112
- workflows.push({
113
- path: relativePath,
114
- ...workflowInfo,
115
- });
116
- } catch {
117
- // Skip files that can't be read
118
- }
119
- }
120
- }
121
- } catch {
122
- // Skip directories we can't read
123
- }
124
- }
125
-
126
- await scanDirectory(this.workflowDir);
127
- return workflows.sort((a, b) => a.name.localeCompare(b.name));
128
- }
129
-
130
- async getWorkflow(workflowPath: string): Promise<Workflow | null> {
131
- const fullPath = this.resolvePath(workflowPath);
132
-
133
- if (!existsSync(fullPath)) {
134
- return null;
135
- }
136
-
137
- try {
138
- // Read the raw markdown content for GUI parser
139
- const rawContent = await readFile(fullPath, 'utf-8');
140
-
141
- // Use core parser for proper workflow parsing
142
- const result = await coreParseFile(fullPath);
143
- if (result.warnings && result.warnings.length > 0) {
144
- console.warn(`Workflow ${workflowPath} has parsing warnings:`, result.warnings);
145
- }
146
-
147
- // Convert core Workflow type to GUI Workflow type
148
- const workflow = this.convertCoreWorkflow(result.workflow, workflowPath);
149
-
150
- // Add raw markdown for GUI control flow parsing
151
- return {
152
- ...workflow,
153
- markdown: rawContent,
154
- };
155
- } catch (error) {
156
- console.error(`Error parsing workflow ${workflowPath}:`, error);
157
- // Fallback to local parsing if core parser fails
158
- try {
159
- const content = await readFile(fullPath, 'utf-8');
160
- return this.parseWorkflow(content, workflowPath);
161
- } catch {
162
- return null;
163
- }
164
- }
165
- }
166
-
167
- private convertCoreWorkflow(coreWorkflow: any, path: string): Workflow {
168
- return {
169
- metadata: {
170
- id: coreWorkflow.metadata?.id || path,
171
- name: coreWorkflow.metadata?.name || path,
172
- version: coreWorkflow.metadata?.version,
173
- description: coreWorkflow.metadata?.description,
174
- author: coreWorkflow.metadata?.author,
175
- tags: coreWorkflow.metadata?.tags,
176
- },
177
- steps: (coreWorkflow.steps || []).map((step: any) => ({
178
- id: step.id,
179
- name: step.name,
180
- action: step.action,
181
- workflow: step.workflow,
182
- inputs: step.inputs || {},
183
- outputVariable: step.outputVariable || step.output_variable,
184
- conditions: step.conditions,
185
- errorHandling: step.errorHandling || step.error_handling,
186
- timeout: step.timeout,
187
- })),
188
- tools: coreWorkflow.tools,
189
- inputs: coreWorkflow.inputs,
190
- triggers: coreWorkflow.triggers,
191
- };
192
- }
193
-
194
- async createWorkflow(name: string, template?: string): Promise<WorkflowListItem> {
195
- const filename = name.toLowerCase().replace(/\s+/g, '-').replace(/[^a-z0-9-]/g, '') + '.md';
196
- const workflowPath = join('workflows', filename);
197
- const fullPath = join(this.workflowDir, workflowPath);
198
-
199
- // Ensure directory exists
200
- await mkdir(dirname(fullPath), { recursive: true });
201
-
202
- const content = template || this.generateWorkflowTemplate(name);
203
- await writeFile(fullPath, content, 'utf-8');
204
-
205
- return {
206
- path: workflowPath,
207
- name,
208
- };
209
- }
210
-
211
- async updateWorkflow(workflowPath: string, workflow: Workflow): Promise<Workflow> {
212
- const fullPath = this.resolvePath(workflowPath);
213
-
214
- // Read original file to preserve markdown content
215
- let markdownContent = '';
216
- if (existsSync(fullPath)) {
217
- const originalContent = await readFile(fullPath, 'utf-8');
218
- const match = originalContent.match(/^---\n[\s\S]*?\n---\n([\s\S]*)$/);
219
- if (match) {
220
- markdownContent = match[1];
221
- }
222
- }
223
-
224
- const content = this.serializeWorkflow(workflow, markdownContent);
225
- await writeFile(fullPath, content, 'utf-8');
226
- return workflow;
227
- }
228
-
229
- async deleteWorkflow(workflowPath: string): Promise<void> {
230
- const fullPath = this.resolvePath(workflowPath);
231
- if (existsSync(fullPath)) {
232
- await unlink(fullPath);
233
- }
234
- }
235
-
236
- async getExecutionHistory(workflowPath: string): Promise<ExecutionRecord[]> {
237
- try {
238
- const stateStore = getStateStore();
239
- // Use the workflow path as the workflow ID for querying
240
- const executions = stateStore.listExecutions({
241
- workflowId: workflowPath,
242
- limit: 50,
243
- });
244
- return executions;
245
- } catch (error) {
246
- console.error('Error getting execution history:', error);
247
- return [];
248
- }
249
- }
250
-
251
- async importWorkflow(
252
- fileBuffer: Buffer,
253
- originalFilename: string
254
- ): Promise<{ success: boolean; results?: Array<{ success: boolean; filename: string; message?: string }>; filename?: string; message?: string }> {
255
- const ext = extname(originalFilename).toLowerCase();
256
-
257
- try {
258
- // Handle ZIP files - extract and import all workflow files
259
- if (ext === '.zip') {
260
- return await this.importZipBundle(fileBuffer);
261
- }
262
-
263
- // Handle single workflow files (.md, .yaml, .yml)
264
- if (['.md', '.yaml', '.yml'].includes(ext)) {
265
- const content = fileBuffer.toString('utf-8');
266
- await this.importSingleWorkflow(content, originalFilename);
267
-
268
- return {
269
- success: true,
270
- filename: originalFilename,
271
- message: 'Workflow imported successfully',
272
- };
273
- }
274
-
275
- throw new Error('Unsupported file type');
276
- } catch (error) {
277
- console.error('Import error:', error);
278
- throw error;
279
- }
280
- }
281
-
282
- private async importSingleWorkflow(content: string, filename: string): Promise<void> {
283
- // Validate workflow content
284
- try {
285
- // Basic validation - try to parse YAML frontmatter or direct YAML
286
- if (filename.endsWith('.md')) {
287
- const frontmatterMatch = content.match(/^---\n([\s\S]*?)\n---/);
288
- if (frontmatterMatch) {
289
- yamlParse(frontmatterMatch[1]);
290
- } else {
291
- throw new Error('Invalid markdown workflow: missing YAML frontmatter');
292
- }
293
- } else {
294
- yamlParse(content);
295
- }
296
- } catch (error) {
297
- throw new Error(`Invalid workflow format: ${error instanceof Error ? error.message : 'Unknown error'}`);
298
- }
299
-
300
- // Check for filename conflicts
301
- let targetFilename = filename;
302
- let fullPath = this.resolvePath(targetFilename);
303
- let counter = 1;
304
-
305
- while (existsSync(fullPath)) {
306
- const nameWithoutExt = basename(filename, extname(filename));
307
- targetFilename = `${nameWithoutExt}-${counter}${extname(filename)}`;
308
- fullPath = this.resolvePath(targetFilename);
309
- counter++;
310
- }
311
-
312
- // Write file
313
- await writeFile(fullPath, content, 'utf-8');
314
- }
315
-
316
- private async importZipBundle(zipBuffer: Buffer): Promise<{ success: boolean; results: Array<{ success: boolean; filename: string; message?: string }> }> {
317
- const results: Array<{ success: boolean; filename: string; message?: string }> = [];
318
-
319
- try {
320
- const zip = new AdmZip(zipBuffer);
321
- const zipEntries = zip.getEntries();
322
-
323
- for (const entry of zipEntries) {
324
- // Skip directories and non-workflow files
325
- if (entry.isDirectory) continue;
326
-
327
- const filename = basename(entry.entryName);
328
- const ext = extname(filename).toLowerCase();
329
-
330
- if (!['.md', '.yaml', '.yml'].includes(ext)) {
331
- results.push({
332
- success: false,
333
- filename,
334
- message: 'Skipped: not a workflow file',
335
- });
336
- continue;
337
- }
338
-
339
- try {
340
- const content = entry.getData().toString('utf-8');
341
- await this.importSingleWorkflow(content, filename);
342
-
343
- results.push({
344
- success: true,
345
- filename,
346
- message: 'Imported successfully',
347
- });
348
- } catch (error) {
349
- results.push({
350
- success: false,
351
- filename,
352
- message: error instanceof Error ? error.message : 'Unknown error',
353
- });
354
- }
355
- }
356
-
357
- return {
358
- success: results.some(r => r.success),
359
- results,
360
- };
361
- } catch (error) {
362
- throw new Error(`Failed to extract ZIP file: ${error instanceof Error ? error.message : 'Unknown error'}`);
363
- }
364
- }
365
-
366
- private resolvePath(workflowPath: string): string {
367
- // Handle both absolute and relative paths
368
- if (workflowPath.startsWith('/')) {
369
- return workflowPath;
370
- }
371
- return join(this.workflowDir, workflowPath);
372
- }
373
-
374
- private parseWorkflow(content: string, path: string): Workflow {
375
- // Extract YAML frontmatter
376
- const frontmatterMatch = content.match(/^---\n([\s\S]*?)\n---/);
377
-
378
- if (!frontmatterMatch) {
379
- return {
380
- metadata: { id: path, name: path },
381
- steps: [],
382
- };
383
- }
384
-
385
- const yaml = frontmatterMatch[1];
386
-
387
- // Parse the YAML manually for now (will use @marktoflow/core parser when integrated)
388
- const workflow: Workflow = {
389
- metadata: { id: path, name: path },
390
- steps: [],
391
- };
392
-
393
- // Extract workflow metadata
394
- const workflowSection = yaml.match(/workflow:\s*\n((?: .*\n)*)/);
395
- if (workflowSection) {
396
- const idMatch = workflowSection[1].match(/id:\s*(\S+)/);
397
- const nameMatch = workflowSection[1].match(/name:\s*["']?(.+?)["']?\s*$/m);
398
- const versionMatch = workflowSection[1].match(/version:\s*["']?(.+?)["']?\s*$/m);
399
- const descMatch = workflowSection[1].match(/description:\s*["']?(.+?)["']?\s*$/m);
400
- const authorMatch = workflowSection[1].match(/author:\s*["']?(.+?)["']?\s*$/m);
401
-
402
- if (idMatch) workflow.metadata.id = idMatch[1].trim();
403
- if (nameMatch) workflow.metadata.name = nameMatch[1].trim();
404
- if (versionMatch) workflow.metadata.version = versionMatch[1].trim();
405
- if (descMatch) workflow.metadata.description = descMatch[1].trim();
406
- if (authorMatch) workflow.metadata.author = authorMatch[1].trim();
407
-
408
- // Extract tags
409
- const tagsMatch = workflowSection[1].match(/tags:\s*\[(.*?)\]/);
410
- if (tagsMatch) {
411
- workflow.metadata.tags = tagsMatch[1]
412
- .split(',')
413
- .map((t) => t.trim().replace(/["']/g, ''))
414
- .filter(Boolean);
415
- }
416
- }
417
-
418
- // Extract steps using regex to find step blocks
419
- const stepsSection = yaml.match(/steps:\s*\n((?: - [\s\S]*?)(?=\n\w|$))/);
420
- if (stepsSection) {
421
- const stepBlocks = stepsSection[1].split(/\n - /).filter(Boolean);
422
-
423
- for (const block of stepBlocks) {
424
- const stepText = block.startsWith('id:') ? block : block;
425
- const step = this.parseStep(stepText);
426
- if (step) {
427
- workflow.steps.push(step);
428
- }
429
- }
430
- }
431
-
432
- // Extract tools
433
- const toolsMatch = yaml.match(/tools:\s*\n((?: .*\n)*)/);
434
- if (toolsMatch) {
435
- // Simple extraction - will be enhanced with proper YAML parser
436
- workflow.tools = {};
437
- }
438
-
439
- // Extract inputs
440
- const inputsMatch = yaml.match(/inputs:\s*\n((?: .*\n)*)/);
441
- if (inputsMatch) {
442
- workflow.inputs = {};
443
- }
444
-
445
- return workflow;
446
- }
447
-
448
- private parseStep(stepText: string): WorkflowStep | null {
449
- const idMatch = stepText.match(/id:\s*(\S+)/);
450
- if (!idMatch) return null;
451
-
452
- const step: WorkflowStep = {
453
- id: idMatch[1],
454
- inputs: {},
455
- };
456
-
457
- const nameMatch = stepText.match(/name:\s*["']?(.+?)["']?\s*$/m);
458
- if (nameMatch) step.name = nameMatch[1];
459
-
460
- const actionMatch = stepText.match(/action:\s*(\S+)/);
461
- if (actionMatch) step.action = actionMatch[1];
462
-
463
- const workflowMatch = stepText.match(/workflow:\s*(\S+)/);
464
- if (workflowMatch) step.workflow = workflowMatch[1];
465
-
466
- const outputMatch = stepText.match(/output_variable:\s*(\S+)/);
467
- if (outputMatch) step.outputVariable = outputMatch[1];
468
-
469
- const timeoutMatch = stepText.match(/timeout:\s*(\d+)/);
470
- if (timeoutMatch) step.timeout = parseInt(timeoutMatch[1], 10);
471
-
472
- // Parse inputs (simplified)
473
- const inputsMatch = stepText.match(/inputs:\s*\n((?: .*\n)*)/);
474
- if (inputsMatch) {
475
- const inputLines = inputsMatch[1].split('\n').filter(Boolean);
476
- for (const line of inputLines) {
477
- const kvMatch = line.match(/^\s*(\w+):\s*(.+)$/);
478
- if (kvMatch) {
479
- let value: unknown = kvMatch[2].trim();
480
- // Remove quotes if present
481
- if ((value as string).startsWith("'") && (value as string).endsWith("'")) {
482
- value = (value as string).slice(1, -1);
483
- } else if ((value as string).startsWith('"') && (value as string).endsWith('"')) {
484
- value = (value as string).slice(1, -1);
485
- }
486
- step.inputs[kvMatch[1]] = value;
487
- }
488
- }
489
- }
490
-
491
- return step;
492
- }
493
-
494
- private serializeWorkflow(workflow: Workflow, markdownContent: string = ''): string {
495
- const frontmatter: Record<string, unknown> = {
496
- workflow: {
497
- id: workflow.metadata.id,
498
- name: workflow.metadata.name,
499
- version: workflow.metadata.version || '1.0.0',
500
- description: workflow.metadata.description || '',
501
- author: workflow.metadata.author || '',
502
- tags: workflow.metadata.tags || [],
503
- },
504
- };
505
-
506
- if (workflow.tools && Object.keys(workflow.tools).length > 0) {
507
- frontmatter.tools = workflow.tools;
508
- }
509
-
510
- if (workflow.inputs && Object.keys(workflow.inputs).length > 0) {
511
- frontmatter.inputs = workflow.inputs;
512
- }
513
-
514
- if (workflow.triggers && workflow.triggers.length > 0) {
515
- frontmatter.triggers = workflow.triggers;
516
- }
517
-
518
- // Serialize steps
519
- frontmatter.steps = workflow.steps.map((step) => {
520
- const stepObj: Record<string, unknown> = {
521
- id: step.id,
522
- };
523
-
524
- if (step.name) stepObj.name = step.name;
525
- if (step.action) stepObj.action = step.action;
526
- if (step.workflow) stepObj.workflow = step.workflow;
527
- if (Object.keys(step.inputs).length > 0) stepObj.inputs = step.inputs;
528
- if (step.outputVariable) stepObj.output_variable = step.outputVariable;
529
- if (step.conditions && step.conditions.length > 0) stepObj.conditions = step.conditions;
530
- if (step.errorHandling) stepObj.error_handling = step.errorHandling;
531
- if (step.timeout) stepObj.timeout = step.timeout;
532
-
533
- return stepObj;
534
- });
535
-
536
- const yaml = yamlStringify(frontmatter, {
537
- indent: 2,
538
- lineWidth: 0,
539
- defaultKeyType: 'PLAIN',
540
- defaultStringType: 'QUOTE_DOUBLE',
541
- });
542
-
543
- // Generate markdown if not provided
544
- if (!markdownContent.trim()) {
545
- markdownContent = `\n# ${workflow.metadata.name}\n\n${workflow.metadata.description || ''}\n`;
546
- }
547
-
548
- return `---\n${yaml}---${markdownContent}`;
549
- }
550
-
551
- private generateWorkflowTemplate(name: string): string {
552
- const id = name.toLowerCase().replace(/\s+/g, '-').replace(/[^a-z0-9-]/g, '');
553
-
554
- return `---
555
- workflow:
556
- id: ${id}
557
- name: "${name}"
558
- version: "1.0.0"
559
- description: ""
560
- author: ""
561
- tags: []
562
-
563
- inputs: {}
564
-
565
- steps:
566
- - id: step-1
567
- name: "First Step"
568
- action: http.request
569
- inputs:
570
- url: "https://api.example.com"
571
- method: "GET"
572
- output_variable: result
573
- ---
574
-
575
- # ${name}
576
-
577
- Describe your workflow here.
578
-
579
- ## Steps
580
-
581
- ### Step 1: First Step
582
-
583
- This step makes an HTTP request to the API.
584
- `;
585
- }
586
- }
587
-
588
- function extractWorkflowInfo(
589
- content: string,
590
- filename: string
591
- ): { name: string; description?: string; version?: string } {
592
- const nameMatch = content.match(/name:\s*["']?(.+?)["']?\s*$/m);
593
- const descMatch = content.match(/description:\s*["']?(.+?)["']?\s*$/m);
594
- const versionMatch = content.match(/version:\s*["']?(.+?)["']?\s*$/m);
595
-
596
- return {
597
- name: nameMatch?.[1]?.trim() || filename.replace(/\.(md|yaml|yml)$/, '').replace(/-/g, ' '),
598
- description: descMatch?.[1]?.trim(),
599
- version: versionMatch?.[1]?.trim(),
600
- };
601
- }