@marktoflow/gui 2.0.0-alpha.1 → 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 (172) hide show
  1. package/README.md +49 -3
  2. package/dist/client/assets/index-CM44OayM.js +704 -0
  3. package/dist/client/assets/index-CM44OayM.js.map +1 -0
  4. package/dist/client/assets/index-Dru63gi6.css +1 -0
  5. package/dist/client/index.html +2 -2
  6. package/dist/server/index.js +93 -33
  7. package/dist/server/index.js.map +1 -1
  8. package/dist/server/routes/ai.js +38 -1
  9. package/dist/server/routes/ai.js.map +1 -1
  10. package/dist/server/routes/execute.js +23 -22
  11. package/dist/server/routes/execute.js.map +1 -1
  12. package/dist/server/routes/executions.js +125 -0
  13. package/dist/server/routes/executions.js.map +1 -0
  14. package/dist/server/{server/routes → routes}/tools.js +406 -0
  15. package/dist/server/{server/routes → routes}/tools.js.map +1 -1
  16. package/dist/server/routes/workflows.js +41 -5
  17. package/dist/server/routes/workflows.js.map +1 -1
  18. package/dist/server/services/AIService.js +55 -202
  19. package/dist/server/services/AIService.js.map +1 -1
  20. package/dist/server/services/FileWatcher.js +0 -2
  21. package/dist/server/services/FileWatcher.js.map +1 -1
  22. package/dist/server/services/WorkflowService.js +199 -16
  23. package/dist/server/services/WorkflowService.js.map +1 -1
  24. package/dist/server/services/agents/codex-provider.js +270 -0
  25. package/dist/server/services/agents/codex-provider.js.map +1 -0
  26. package/dist/server/{server/services → services}/agents/prompts.js +27 -0
  27. package/dist/server/services/agents/prompts.js.map +1 -0
  28. package/dist/server/{server/services → services}/agents/registry.js +20 -0
  29. package/dist/server/services/agents/registry.js.map +1 -0
  30. package/dist/server/websocket/index.js +12 -0
  31. package/dist/server/websocket/index.js.map +1 -1
  32. package/package.json +19 -7
  33. package/scripts/flatten-dist.js +69 -0
  34. package/.turbo/turbo-build.log +0 -26
  35. package/.turbo/turbo-test.log +0 -22
  36. package/dist/client/assets/index-DwTI8opO.js +0 -608
  37. package/dist/client/assets/index-DwTI8opO.js.map +0 -1
  38. package/dist/client/assets/index-RoEdL6gO.css +0 -1
  39. package/dist/server/index.d.ts +0 -3
  40. package/dist/server/index.d.ts.map +0 -1
  41. package/dist/server/server/index.js +0 -95
  42. package/dist/server/server/index.js.map +0 -1
  43. package/dist/server/server/routes/ai.js +0 -87
  44. package/dist/server/server/routes/ai.js.map +0 -1
  45. package/dist/server/server/routes/execute.js +0 -63
  46. package/dist/server/server/routes/execute.js.map +0 -1
  47. package/dist/server/server/routes/workflows.js +0 -99
  48. package/dist/server/server/routes/workflows.js.map +0 -1
  49. package/dist/server/server/services/AIService.js +0 -69
  50. package/dist/server/server/services/AIService.js.map +0 -1
  51. package/dist/server/server/services/FileWatcher.js +0 -60
  52. package/dist/server/server/services/FileWatcher.js.map +0 -1
  53. package/dist/server/server/services/WorkflowService.js +0 -363
  54. package/dist/server/server/services/WorkflowService.js.map +0 -1
  55. package/dist/server/server/services/agents/prompts.js.map +0 -1
  56. package/dist/server/server/services/agents/registry.js.map +0 -1
  57. package/dist/server/server/websocket/index.js +0 -85
  58. package/dist/server/server/websocket/index.js.map +0 -1
  59. package/dist/server/services/AIService.d.ts +0 -30
  60. package/dist/server/services/AIService.d.ts.map +0 -1
  61. package/dist/server/services/FileWatcher.d.ts +0 -10
  62. package/dist/server/services/FileWatcher.d.ts.map +0 -1
  63. package/dist/server/services/WorkflowService.d.ts +0 -54
  64. package/dist/server/services/WorkflowService.d.ts.map +0 -1
  65. package/dist/server/websocket/index.d.ts +0 -10
  66. package/dist/server/websocket/index.d.ts.map +0 -1
  67. package/playwright.config.ts +0 -27
  68. package/postcss.config.js +0 -6
  69. package/src/client/App.tsx +0 -520
  70. package/src/client/components/Canvas/Canvas.tsx +0 -405
  71. package/src/client/components/Canvas/ExecutionOverlay.tsx +0 -847
  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/StepNode.tsx +0 -106
  75. package/src/client/components/Canvas/SubWorkflowNode.tsx +0 -141
  76. package/src/client/components/Canvas/Toolbar.tsx +0 -189
  77. package/src/client/components/Canvas/TriggerNode.tsx +0 -128
  78. package/src/client/components/Editor/InputsEditor.tsx +0 -458
  79. package/src/client/components/Editor/NewStepWizard.tsx +0 -344
  80. package/src/client/components/Editor/StepEditor.tsx +0 -532
  81. package/src/client/components/Editor/YamlEditor.tsx +0 -160
  82. package/src/client/components/Panels/PropertiesPanel.tsx +0 -589
  83. package/src/client/components/Prompt/ChangePreview.tsx +0 -281
  84. package/src/client/components/Prompt/PromptHistoryPanel.tsx +0 -209
  85. package/src/client/components/Prompt/PromptInput.tsx +0 -108
  86. package/src/client/components/Sidebar/Sidebar.tsx +0 -343
  87. package/src/client/components/common/Breadcrumb.tsx +0 -40
  88. package/src/client/components/common/Button.tsx +0 -68
  89. package/src/client/components/common/ContextMenu.tsx +0 -202
  90. package/src/client/components/common/KeyboardShortcuts.tsx +0 -143
  91. package/src/client/components/common/Modal.tsx +0 -93
  92. package/src/client/components/common/Tabs.tsx +0 -57
  93. package/src/client/components/common/ThemeToggle.tsx +0 -63
  94. package/src/client/components/index.ts +0 -32
  95. package/src/client/hooks/index.ts +0 -4
  96. package/src/client/hooks/useAIPrompt.ts +0 -108
  97. package/src/client/hooks/useCanvas.ts +0 -247
  98. package/src/client/hooks/useWebSocket.ts +0 -164
  99. package/src/client/hooks/useWorkflow.ts +0 -138
  100. package/src/client/main.tsx +0 -10
  101. package/src/client/stores/canvasStore.ts +0 -348
  102. package/src/client/stores/editorStore.ts +0 -133
  103. package/src/client/stores/executionStore.ts +0 -440
  104. package/src/client/stores/index.ts +0 -4
  105. package/src/client/stores/layoutStore.ts +0 -103
  106. package/src/client/stores/navigationStore.ts +0 -49
  107. package/src/client/stores/promptStore.ts +0 -113
  108. package/src/client/stores/themeStore.ts +0 -75
  109. package/src/client/stores/workflowStore.ts +0 -177
  110. package/src/client/styles/globals.css +0 -346
  111. package/src/client/utils/cn.ts +0 -9
  112. package/src/client/utils/index.ts +0 -4
  113. package/src/client/utils/serviceIcons.tsx +0 -64
  114. package/src/client/utils/stepValidation.ts +0 -155
  115. package/src/client/utils/workflowToGraph.ts +0 -299
  116. package/src/server/index.ts +0 -114
  117. package/src/server/routes/ai.ts +0 -91
  118. package/src/server/routes/execute.ts +0 -71
  119. package/src/server/routes/tools.ts +0 -564
  120. package/src/server/routes/workflows.ts +0 -106
  121. package/src/server/services/AIService.ts +0 -105
  122. package/src/server/services/FileWatcher.ts +0 -69
  123. package/src/server/services/WorkflowService.ts +0 -441
  124. package/src/server/services/agents/claude-code-provider.ts +0 -320
  125. package/src/server/services/agents/claude-provider.ts +0 -248
  126. package/src/server/services/agents/copilot-provider.ts +0 -311
  127. package/src/server/services/agents/demo-provider.ts +0 -184
  128. package/src/server/services/agents/index.ts +0 -31
  129. package/src/server/services/agents/ollama-provider.ts +0 -267
  130. package/src/server/services/agents/prompts.ts +0 -482
  131. package/src/server/services/agents/registry.ts +0 -289
  132. package/src/server/services/agents/types.ts +0 -146
  133. package/src/server/websocket/index.ts +0 -104
  134. package/src/shared/constants.ts +0 -180
  135. package/src/shared/types.ts +0 -179
  136. package/tailwind.config.ts +0 -73
  137. package/tests/e2e/app.spec.ts +0 -90
  138. package/tests/e2e/canvas.spec.ts +0 -128
  139. package/tests/e2e/workflow.spec.ts +0 -185
  140. package/tests/integration/api.test.ts +0 -250
  141. package/tests/integration/testApp.ts +0 -31
  142. package/tests/setup.ts +0 -37
  143. package/tests/unit/canvasStore.test.ts +0 -502
  144. package/tests/unit/components.test.tsx +0 -151
  145. package/tests/unit/executionStore.test.ts +0 -527
  146. package/tests/unit/layoutStore.test.ts +0 -194
  147. package/tests/unit/navigationStore.test.ts +0 -152
  148. package/tests/unit/stepValidation.test.ts +0 -226
  149. package/tests/unit/themeStore.test.ts +0 -141
  150. package/tests/unit/workflowToGraph.test.ts +0 -289
  151. package/tsconfig.json +0 -29
  152. package/tsconfig.server.json +0 -28
  153. package/vite.config.ts +0 -31
  154. package/vitest.config.ts +0 -26
  155. /package/dist/server/{server/services → services}/agents/claude-code-provider.js +0 -0
  156. /package/dist/server/{server/services → services}/agents/claude-code-provider.js.map +0 -0
  157. /package/dist/server/{server/services → services}/agents/claude-provider.js +0 -0
  158. /package/dist/server/{server/services → services}/agents/claude-provider.js.map +0 -0
  159. /package/dist/server/{server/services → services}/agents/copilot-provider.js +0 -0
  160. /package/dist/server/{server/services → services}/agents/copilot-provider.js.map +0 -0
  161. /package/dist/server/{server/services → services}/agents/demo-provider.js +0 -0
  162. /package/dist/server/{server/services → services}/agents/demo-provider.js.map +0 -0
  163. /package/dist/server/{server/services → services}/agents/index.js +0 -0
  164. /package/dist/server/{server/services → services}/agents/index.js.map +0 -0
  165. /package/dist/server/{server/services → services}/agents/ollama-provider.js +0 -0
  166. /package/dist/server/{server/services → services}/agents/ollama-provider.js.map +0 -0
  167. /package/dist/server/{server/services → services}/agents/types.js +0 -0
  168. /package/dist/server/{server/services → services}/agents/types.js.map +0 -0
  169. /package/dist/{server/shared → shared}/constants.js +0 -0
  170. /package/dist/{server/shared → shared}/constants.js.map +0 -0
  171. /package/dist/{server/shared → shared}/types.js +0 -0
  172. /package/dist/{server/shared → shared}/types.js.map +0 -0
@@ -1,441 +0,0 @@
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
- }