@marktoflow/gui 2.0.0-alpha.4 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (194) hide show
  1. package/README.md +48 -170
  2. package/client.log +0 -0
  3. package/dist/client/assets/index-DQeR1ew6.css +1 -0
  4. package/dist/client/assets/index-LbIVPHbD.js +833 -0
  5. package/dist/client/assets/index-LbIVPHbD.js.map +1 -0
  6. package/dist/client/index.html +2 -2
  7. package/dist/client/marktoflow-logo.png +0 -0
  8. package/dist/server/{server/index.js → index.js} +53 -6
  9. package/dist/server/index.js.map +1 -0
  10. package/dist/server/routes/admin.js +95 -0
  11. package/dist/server/routes/admin.js.map +1 -0
  12. package/dist/server/{server/routes → routes}/ai.js +2 -2
  13. package/dist/server/{server/routes → routes}/ai.js.map +1 -1
  14. package/dist/server/routes/collaboration.js +104 -0
  15. package/dist/server/routes/collaboration.js.map +1 -0
  16. package/dist/server/routes/execute.js +230 -0
  17. package/dist/server/routes/execute.js.map +1 -0
  18. package/dist/server/routes/executions.js +125 -0
  19. package/dist/server/routes/executions.js.map +1 -0
  20. package/dist/server/routes/form.js +160 -0
  21. package/dist/server/routes/form.js.map +1 -0
  22. package/dist/server/routes/settings.js +90 -0
  23. package/dist/server/routes/settings.js.map +1 -0
  24. package/dist/server/routes/templates.js +106 -0
  25. package/dist/server/routes/templates.js.map +1 -0
  26. package/dist/server/routes/versions.js +101 -0
  27. package/dist/server/routes/versions.js.map +1 -0
  28. package/dist/server/{server/routes → routes}/workflows.js +37 -1
  29. package/dist/server/routes/workflows.js.map +1 -0
  30. package/dist/server/services/AIService.js +152 -0
  31. package/dist/server/services/AIService.js.map +1 -0
  32. package/dist/server/services/ExecutionManager.js +571 -0
  33. package/dist/server/services/ExecutionManager.js.map +1 -0
  34. package/dist/server/services/VersionService.js +65 -0
  35. package/dist/server/services/VersionService.js.map +1 -0
  36. package/dist/server/{server/services → services}/WorkflowService.js +166 -17
  37. package/dist/server/services/WorkflowService.js.map +1 -0
  38. package/dist/server/{server/services → services}/agents/copilot-provider.js +32 -0
  39. package/dist/server/services/agents/copilot-provider.js.map +1 -0
  40. package/dist/server/{server/websocket → websocket}/index.js +54 -0
  41. package/dist/server/websocket/index.js.map +1 -0
  42. package/dist/{server/shared → shared}/constants.js +9 -0
  43. package/dist/shared/constants.js.map +1 -0
  44. package/dist/shared/settings.js +51 -0
  45. package/dist/shared/settings.js.map +1 -0
  46. package/package.json +32 -14
  47. package/public/marktoflow-logo.png +0 -0
  48. package/scripts/flatten-dist.js +69 -0
  49. package/server.log +0 -0
  50. package/tests/integration/fixtures/test-workflow.md +6 -0
  51. package/.turbo/turbo-build.log +0 -26
  52. package/dist/client/assets/index-C90Y_aBX.js +0 -678
  53. package/dist/client/assets/index-C90Y_aBX.js.map +0 -1
  54. package/dist/client/assets/index-CRWeQ3NN.css +0 -1
  55. package/dist/server/server/index.js.map +0 -1
  56. package/dist/server/server/routes/execute.js +0 -63
  57. package/dist/server/server/routes/execute.js.map +0 -1
  58. package/dist/server/server/routes/workflows.js.map +0 -1
  59. package/dist/server/server/services/AIService.js +0 -69
  60. package/dist/server/server/services/AIService.js.map +0 -1
  61. package/dist/server/server/services/WorkflowService.js.map +0 -1
  62. package/dist/server/server/services/agents/copilot-provider.js.map +0 -1
  63. package/dist/server/server/websocket/index.js.map +0 -1
  64. package/dist/server/shared/constants.js.map +0 -1
  65. package/playwright.config.ts +0 -27
  66. package/postcss.config.js +0 -6
  67. package/src/client/App.tsx +0 -520
  68. package/src/client/components/Canvas/Canvas.tsx +0 -423
  69. package/src/client/components/Canvas/ExecutionOverlay.tsx +0 -847
  70. package/src/client/components/Canvas/ForEachNode.tsx +0 -128
  71. package/src/client/components/Canvas/IfElseNode.tsx +0 -126
  72. package/src/client/components/Canvas/NodeContextMenu.tsx +0 -188
  73. package/src/client/components/Canvas/OutputNode.tsx +0 -111
  74. package/src/client/components/Canvas/ParallelNode.tsx +0 -140
  75. package/src/client/components/Canvas/StepNode.tsx +0 -106
  76. package/src/client/components/Canvas/SubWorkflowNode.tsx +0 -141
  77. package/src/client/components/Canvas/SwitchNode.tsx +0 -164
  78. package/src/client/components/Canvas/Toolbar.tsx +0 -189
  79. package/src/client/components/Canvas/TransformNode.tsx +0 -185
  80. package/src/client/components/Canvas/TriggerNode.tsx +0 -128
  81. package/src/client/components/Canvas/TryCatchNode.tsx +0 -164
  82. package/src/client/components/Canvas/WhileNode.tsx +0 -129
  83. package/src/client/components/Canvas/index.ts +0 -24
  84. package/src/client/components/Editor/InputsEditor.tsx +0 -458
  85. package/src/client/components/Editor/NewStepWizard.tsx +0 -344
  86. package/src/client/components/Editor/StepEditor.tsx +0 -532
  87. package/src/client/components/Editor/YamlEditor.tsx +0 -160
  88. package/src/client/components/Panels/PropertiesPanel.tsx +0 -589
  89. package/src/client/components/Prompt/ChangePreview.tsx +0 -281
  90. package/src/client/components/Prompt/PromptHistoryPanel.tsx +0 -209
  91. package/src/client/components/Prompt/PromptInput.tsx +0 -108
  92. package/src/client/components/Sidebar/Sidebar.tsx +0 -343
  93. package/src/client/components/common/Breadcrumb.tsx +0 -40
  94. package/src/client/components/common/Button.tsx +0 -68
  95. package/src/client/components/common/ContextMenu.tsx +0 -202
  96. package/src/client/components/common/KeyboardShortcuts.tsx +0 -143
  97. package/src/client/components/common/Modal.tsx +0 -93
  98. package/src/client/components/common/Tabs.tsx +0 -57
  99. package/src/client/components/common/ThemeToggle.tsx +0 -63
  100. package/src/client/components/index.ts +0 -32
  101. package/src/client/hooks/index.ts +0 -4
  102. package/src/client/hooks/useAIPrompt.ts +0 -108
  103. package/src/client/hooks/useCanvas.ts +0 -247
  104. package/src/client/hooks/useWebSocket.ts +0 -164
  105. package/src/client/hooks/useWorkflow.ts +0 -138
  106. package/src/client/main.tsx +0 -10
  107. package/src/client/stores/canvasStore.ts +0 -348
  108. package/src/client/stores/editorStore.ts +0 -133
  109. package/src/client/stores/executionStore.ts +0 -440
  110. package/src/client/stores/index.ts +0 -4
  111. package/src/client/stores/layoutStore.ts +0 -103
  112. package/src/client/stores/navigationStore.ts +0 -49
  113. package/src/client/stores/promptStore.ts +0 -113
  114. package/src/client/stores/themeStore.ts +0 -75
  115. package/src/client/stores/workflowStore.ts +0 -177
  116. package/src/client/styles/globals.css +0 -346
  117. package/src/client/utils/cn.ts +0 -9
  118. package/src/client/utils/index.ts +0 -4
  119. package/src/client/utils/serviceIcons.tsx +0 -97
  120. package/src/client/utils/stepValidation.ts +0 -155
  121. package/src/client/utils/workflowToGraph.ts +0 -299
  122. package/src/server/index.ts +0 -114
  123. package/src/server/routes/ai.ts +0 -91
  124. package/src/server/routes/execute.ts +0 -71
  125. package/src/server/routes/tools.ts +0 -970
  126. package/src/server/routes/workflows.ts +0 -106
  127. package/src/server/services/AIService.ts +0 -105
  128. package/src/server/services/FileWatcher.ts +0 -69
  129. package/src/server/services/WorkflowService.ts +0 -441
  130. package/src/server/services/agents/claude-code-provider.ts +0 -320
  131. package/src/server/services/agents/claude-provider.ts +0 -248
  132. package/src/server/services/agents/codex-provider.ts +0 -398
  133. package/src/server/services/agents/copilot-provider.ts +0 -311
  134. package/src/server/services/agents/demo-provider.ts +0 -184
  135. package/src/server/services/agents/index.ts +0 -31
  136. package/src/server/services/agents/ollama-provider.ts +0 -267
  137. package/src/server/services/agents/prompts.ts +0 -509
  138. package/src/server/services/agents/registry.ts +0 -310
  139. package/src/server/services/agents/types.ts +0 -146
  140. package/src/server/websocket/index.ts +0 -104
  141. package/src/shared/constants.ts +0 -180
  142. package/src/shared/types.ts +0 -179
  143. package/tailwind.config.ts +0 -73
  144. package/tests/e2e/app.spec.ts +0 -90
  145. package/tests/e2e/canvas.spec.ts +0 -128
  146. package/tests/e2e/workflow.spec.ts +0 -185
  147. package/tests/integration/api.test.ts +0 -452
  148. package/tests/integration/testApp.ts +0 -31
  149. package/tests/setup.ts +0 -72
  150. package/tests/unit/ForEachNode.test.tsx +0 -218
  151. package/tests/unit/IfElseNode.test.tsx +0 -188
  152. package/tests/unit/ParallelNode.test.tsx +0 -264
  153. package/tests/unit/SwitchNode.test.tsx +0 -252
  154. package/tests/unit/TransformNode.test.tsx +0 -386
  155. package/tests/unit/TryCatchNode.test.tsx +0 -243
  156. package/tests/unit/WhileNode.test.tsx +0 -226
  157. package/tests/unit/canvasStore.test.ts +0 -502
  158. package/tests/unit/codexProvider.test.ts +0 -399
  159. package/tests/unit/components.test.tsx +0 -151
  160. package/tests/unit/executionStore.test.ts +0 -527
  161. package/tests/unit/layoutStore.test.ts +0 -194
  162. package/tests/unit/navigationStore.test.ts +0 -152
  163. package/tests/unit/serviceIcons.test.ts +0 -197
  164. package/tests/unit/stepValidation.test.ts +0 -226
  165. package/tests/unit/themeStore.test.ts +0 -141
  166. package/tests/unit/workflowToGraph.test.ts +0 -289
  167. package/tsconfig.json +0 -29
  168. package/tsconfig.server.json +0 -28
  169. package/vite.config.ts +0 -31
  170. package/vitest.config.ts +0 -26
  171. /package/dist/server/{server/routes → routes}/tools.js +0 -0
  172. /package/dist/server/{server/routes → routes}/tools.js.map +0 -0
  173. /package/dist/server/{server/services → services}/FileWatcher.js +0 -0
  174. /package/dist/server/{server/services → services}/FileWatcher.js.map +0 -0
  175. /package/dist/server/{server/services → services}/agents/claude-code-provider.js +0 -0
  176. /package/dist/server/{server/services → services}/agents/claude-code-provider.js.map +0 -0
  177. /package/dist/server/{server/services → services}/agents/claude-provider.js +0 -0
  178. /package/dist/server/{server/services → services}/agents/claude-provider.js.map +0 -0
  179. /package/dist/server/{server/services → services}/agents/codex-provider.js +0 -0
  180. /package/dist/server/{server/services → services}/agents/codex-provider.js.map +0 -0
  181. /package/dist/server/{server/services → services}/agents/demo-provider.js +0 -0
  182. /package/dist/server/{server/services → services}/agents/demo-provider.js.map +0 -0
  183. /package/dist/server/{server/services → services}/agents/index.js +0 -0
  184. /package/dist/server/{server/services → services}/agents/index.js.map +0 -0
  185. /package/dist/server/{server/services → services}/agents/ollama-provider.js +0 -0
  186. /package/dist/server/{server/services → services}/agents/ollama-provider.js.map +0 -0
  187. /package/dist/server/{server/services → services}/agents/prompts.js +0 -0
  188. /package/dist/server/{server/services → services}/agents/prompts.js.map +0 -0
  189. /package/dist/server/{server/services → services}/agents/registry.js +0 -0
  190. /package/dist/server/{server/services → services}/agents/registry.js.map +0 -0
  191. /package/dist/server/{server/services → services}/agents/types.js +0 -0
  192. /package/dist/server/{server/services → services}/agents/types.js.map +0 -0
  193. /package/dist/{server/shared → shared}/types.js +0 -0
  194. /package/dist/{server/shared → shared}/types.js.map +0 -0
@@ -1,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
- }