@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,320 +0,0 @@
1
- /**
2
- * Claude Code AI agent provider
3
- * Uses the @anthropic-ai/claude-agent-sdk for AI capabilities
4
- * Authentication is handled automatically by the SDK (via Claude CLI auth)
5
- */
6
-
7
- import { createRequire } from 'node:module';
8
- import { parse as yamlParse } from 'yaml';
9
- import type {
10
- AgentProvider,
11
- AgentCapabilities,
12
- AgentConfig,
13
- PromptResult,
14
- Workflow,
15
- } from './types.js';
16
- import { buildPrompt, generateSuggestions } from './prompts.js';
17
-
18
- // Polyfill require for ESM environments (needed by Claude SDK)
19
- if (typeof globalThis.require === 'undefined') {
20
- (globalThis as unknown as { require: NodeRequire }).require = createRequire(import.meta.url);
21
- }
22
-
23
- // Dynamic import types for Claude Agent SDK
24
- interface SDKMessage {
25
- type: string;
26
- message?: {
27
- content: string | Array<{ type: string; text?: string }>;
28
- };
29
- result?: string;
30
- error?: string;
31
- session_id?: string;
32
- duration_ms?: number;
33
- total_cost_usd?: number;
34
- usage?: {
35
- input_tokens?: number;
36
- output_tokens?: number;
37
- };
38
- }
39
-
40
- interface AgentQuery extends AsyncGenerator<SDKMessage, void, unknown> {
41
- interrupt(): Promise<void>;
42
- }
43
-
44
- // The SDK exports a query function directly
45
- type QueryFunction = (params: { prompt: string; options?: Record<string, unknown> }) => AgentQuery;
46
-
47
- export class ClaudeCodeProvider implements AgentProvider {
48
- readonly id = 'claude-code';
49
- readonly name = 'Claude Code (SDK)';
50
- readonly capabilities: AgentCapabilities = {
51
- streaming: true,
52
- toolUse: true,
53
- codeExecution: true,
54
- systemPrompts: true,
55
- models: ['claude-sonnet-4-20250514', 'claude-opus-4-20250514', 'claude-3-5-haiku-20241022'],
56
- };
57
-
58
- private queryFn: QueryFunction | null = null;
59
- private model: string = 'claude-sonnet-4-20250514';
60
- private ready: boolean = false;
61
- private error: string | undefined;
62
- private currentQuery: AgentQuery | null = null;
63
- private maxTurns: number = 50;
64
- private cwd?: string;
65
-
66
- async initialize(config: AgentConfig): Promise<void> {
67
- try {
68
- // Try to import the Claude Agent SDK (dynamic import with webpackIgnore to avoid bundling issues)
69
- const sdkModule = await import(/* webpackIgnore: true */ '@anthropic-ai/claude-agent-sdk').catch(
70
- () => null
71
- );
72
- if (!sdkModule || !sdkModule.query) {
73
- this.ready = false;
74
- this.error = 'Claude Agent SDK not installed. Run: npm install @anthropic-ai/claude-agent-sdk';
75
- return;
76
- }
77
-
78
- this.queryFn = sdkModule.query as QueryFunction;
79
-
80
- if (config.model) {
81
- this.model = config.model;
82
- }
83
- if (config.options?.maxTurns) {
84
- this.maxTurns = config.options.maxTurns as number;
85
- }
86
- if (config.options?.cwd) {
87
- this.cwd = config.options.cwd as string;
88
- }
89
-
90
- // Test SDK availability - the SDK handles authentication automatically
91
- // via the Claude CLI's auth mechanism
92
- this.ready = true;
93
- this.error = undefined;
94
- } catch (err) {
95
- this.ready = false;
96
- this.error = err instanceof Error ? err.message : 'Unknown error initializing Claude Code';
97
- }
98
- }
99
-
100
- isReady(): boolean {
101
- return this.ready;
102
- }
103
-
104
- getStatus(): { ready: boolean; model?: string; error?: string } {
105
- return {
106
- ready: this.ready,
107
- model: this.model,
108
- error: this.error,
109
- };
110
- }
111
-
112
- async processPrompt(
113
- prompt: string,
114
- workflow: Workflow,
115
- context?: { selectedStepId?: string; recentHistory?: string[] }
116
- ): Promise<PromptResult> {
117
- if (!this.queryFn || !this.ready) {
118
- return {
119
- explanation: 'Claude Code SDK not available.',
120
- error: this.error || 'Provider not initialized',
121
- };
122
- }
123
-
124
- try {
125
- // Build context-aware prompts
126
- const { systemPrompt, userPrompt } = buildPrompt(prompt, workflow, context);
127
-
128
- // Combine system prompt and user prompt for the SDK
129
- const fullPrompt = `${systemPrompt}\n\n---\n\nUser request: ${userPrompt}`;
130
-
131
- const response = await this.runQuery(fullPrompt);
132
- return this.parseAIResponse(response, workflow);
133
- } catch (err) {
134
- return {
135
- explanation: '',
136
- error: err instanceof Error ? err.message : 'Unknown error',
137
- };
138
- }
139
- }
140
-
141
- private async runQuery(prompt: string): Promise<string> {
142
- if (!this.queryFn) {
143
- throw new Error('SDK not initialized');
144
- }
145
-
146
- const options: Record<string, unknown> = {
147
- model: this.model,
148
- maxTurns: this.maxTurns,
149
- // Restrict tools to read-only for safety in workflow editing context
150
- allowedTools: ['Read', 'Glob', 'Grep'],
151
- };
152
-
153
- if (this.cwd) {
154
- options.cwd = this.cwd;
155
- }
156
-
157
- this.currentQuery = this.queryFn({
158
- prompt,
159
- options,
160
- });
161
-
162
- let resultText = '';
163
-
164
- try {
165
- for await (const message of this.currentQuery) {
166
- if (message.type === 'result') {
167
- resultText = message.result || '';
168
- break;
169
- } else if (message.type === 'assistant' && message.message) {
170
- // Extract text from assistant messages
171
- const content = message.message.content;
172
- if (typeof content === 'string') {
173
- resultText = content;
174
- } else if (Array.isArray(content)) {
175
- resultText = content
176
- .filter((c) => c.type === 'text' && c.text)
177
- .map((c) => c.text)
178
- .join('\n');
179
- }
180
- }
181
- }
182
- } finally {
183
- this.currentQuery = null;
184
- }
185
-
186
- return resultText;
187
- }
188
-
189
- async streamPrompt(
190
- prompt: string,
191
- workflow: Workflow,
192
- onChunk: (chunk: string) => void,
193
- context?: { selectedStepId?: string; recentHistory?: string[] }
194
- ): Promise<PromptResult> {
195
- if (!this.queryFn || !this.ready) {
196
- return this.processPrompt(prompt, workflow, context);
197
- }
198
-
199
- const { systemPrompt, userPrompt } = buildPrompt(prompt, workflow, context);
200
- const fullPrompt = `${systemPrompt}\n\n---\n\nUser request: ${userPrompt}`;
201
- let fullResponse = '';
202
-
203
- try {
204
- const options: Record<string, unknown> = {
205
- model: this.model,
206
- maxTurns: this.maxTurns,
207
- allowedTools: ['Read', 'Glob', 'Grep'],
208
- };
209
-
210
- if (this.cwd) {
211
- options.cwd = this.cwd;
212
- }
213
-
214
- this.currentQuery = this.queryFn({
215
- prompt: fullPrompt,
216
- options,
217
- });
218
-
219
- for await (const message of this.currentQuery) {
220
- if (message.type === 'assistant' && message.message) {
221
- const content = message.message.content;
222
- if (typeof content === 'string') {
223
- const newContent = content.slice(fullResponse.length);
224
- if (newContent) {
225
- fullResponse = content;
226
- onChunk(newContent);
227
- }
228
- } else if (Array.isArray(content)) {
229
- const text = content
230
- .filter((c) => c.type === 'text' && c.text)
231
- .map((c) => c.text)
232
- .join('\n');
233
- const newContent = text.slice(fullResponse.length);
234
- if (newContent) {
235
- fullResponse = text;
236
- onChunk(newContent);
237
- }
238
- }
239
- } else if (message.type === 'result') {
240
- fullResponse = message.result || fullResponse;
241
- break;
242
- }
243
- }
244
-
245
- return this.parseAIResponse(fullResponse, workflow);
246
- } catch (err) {
247
- return {
248
- explanation: '',
249
- error: err instanceof Error ? err.message : 'Unknown error',
250
- };
251
- } finally {
252
- this.currentQuery = null;
253
- }
254
- }
255
-
256
- async getSuggestions(workflow: Workflow, selectedStepId?: string): Promise<string[]> {
257
- return generateSuggestions(workflow, selectedStepId);
258
- }
259
-
260
- async cancel(): Promise<void> {
261
- if (this.currentQuery) {
262
- await this.currentQuery.interrupt();
263
- this.currentQuery = null;
264
- }
265
- }
266
-
267
- private parseAIResponse(responseText: string, originalWorkflow: Workflow): PromptResult {
268
- const yamlMatch = responseText.match(/```yaml\n([\s\S]*?)\n```/);
269
- let modifiedWorkflow: Workflow | undefined;
270
- let explanation = responseText;
271
-
272
- if (yamlMatch) {
273
- try {
274
- const parsedYaml = yamlParse(yamlMatch[1]);
275
- if (parsedYaml && (parsedYaml.steps || parsedYaml.metadata)) {
276
- modifiedWorkflow = parsedYaml as Workflow;
277
- const explanationMatch = responseText.match(/^([\s\S]*?)```yaml/);
278
- if (explanationMatch) {
279
- explanation = explanationMatch[1].trim();
280
- }
281
- }
282
- } catch {
283
- // Failed to parse YAML
284
- }
285
- }
286
-
287
- let diff: string | undefined;
288
- if (modifiedWorkflow) {
289
- diff = this.generateDiff(originalWorkflow, modifiedWorkflow);
290
- }
291
-
292
- return { explanation, workflow: modifiedWorkflow, diff };
293
- }
294
-
295
- private generateDiff(original: Workflow, modified: Workflow): string {
296
- const originalStepIds = new Set(original.steps?.map((s) => s.id) || []);
297
- const modifiedStepIds = new Set(modified.steps?.map((s) => s.id) || []);
298
-
299
- const added = modified.steps?.filter((s) => !originalStepIds.has(s.id)) || [];
300
- const removed = original.steps?.filter((s) => !modifiedStepIds.has(s.id)) || [];
301
-
302
- let diff = '';
303
- if (added.length > 0) {
304
- diff += `+ Added ${added.length} step(s): ${added.map((s) => s.name || s.id).join(', ')}\n`;
305
- }
306
- if (removed.length > 0) {
307
- diff += `- Removed ${removed.length} step(s): ${removed.map((s) => s.name || s.id).join(', ')}\n`;
308
- }
309
-
310
- return diff || 'No structural changes detected';
311
- }
312
- }
313
-
314
- export function createClaudeCodeProvider(config?: AgentConfig): ClaudeCodeProvider {
315
- const provider = new ClaudeCodeProvider();
316
- if (config) {
317
- provider.initialize(config);
318
- }
319
- return provider;
320
- }
@@ -1,248 +0,0 @@
1
- /**
2
- * Claude/Anthropic AI agent provider
3
- * Uses the Anthropic SDK for AI capabilities
4
- */
5
-
6
- import Anthropic from '@anthropic-ai/sdk';
7
- import { parse as yamlParse } from 'yaml';
8
- import type {
9
- AgentProvider,
10
- AgentCapabilities,
11
- AgentConfig,
12
- PromptResult,
13
- Workflow,
14
- } from './types.js';
15
- import { buildPrompt, generateSuggestions } from './prompts.js';
16
-
17
- export class ClaudeProvider implements AgentProvider {
18
- readonly id = 'claude';
19
- readonly name = 'Claude (Anthropic)';
20
- readonly capabilities: AgentCapabilities = {
21
- streaming: true,
22
- toolUse: true,
23
- codeExecution: false,
24
- systemPrompts: true,
25
- maxContextLength: 200000,
26
- models: [
27
- 'claude-sonnet-4-20250514',
28
- 'claude-opus-4-20250514',
29
- 'claude-3-5-sonnet-20241022',
30
- 'claude-3-5-haiku-20241022',
31
- ],
32
- };
33
-
34
- private client: Anthropic | null = null;
35
- private model: string = 'claude-sonnet-4-20250514';
36
- private ready: boolean = false;
37
- private error: string | undefined;
38
-
39
- async initialize(config: AgentConfig): Promise<void> {
40
- try {
41
- const apiKey = config.apiKey || process.env.ANTHROPIC_API_KEY;
42
- if (!apiKey) {
43
- this.ready = false;
44
- this.error = 'No API key configured';
45
- return;
46
- }
47
-
48
- this.client = new Anthropic({
49
- apiKey,
50
- baseURL: config.baseUrl,
51
- timeout: config.timeout,
52
- });
53
-
54
- if (config.model) {
55
- this.model = config.model;
56
- }
57
-
58
- this.ready = true;
59
- this.error = undefined;
60
- } catch (err) {
61
- this.ready = false;
62
- this.error = err instanceof Error ? err.message : 'Unknown error';
63
- }
64
- }
65
-
66
- isReady(): boolean {
67
- return this.ready;
68
- }
69
-
70
- getStatus(): { ready: boolean; model?: string; error?: string } {
71
- return {
72
- ready: this.ready,
73
- model: this.model,
74
- error: this.error,
75
- };
76
- }
77
-
78
- async processPrompt(
79
- prompt: string,
80
- workflow: Workflow,
81
- context?: { selectedStepId?: string; recentHistory?: string[] }
82
- ): Promise<PromptResult> {
83
- if (!this.client) {
84
- return {
85
- explanation: 'Claude provider not initialized. Running in demo mode.',
86
- workflow: this.simulateResponse(prompt, workflow),
87
- };
88
- }
89
-
90
- try {
91
- // Build context-aware prompts
92
- const { systemPrompt, userPrompt } = buildPrompt(prompt, workflow, context);
93
-
94
- const response = await this.client.messages.create({
95
- model: this.model,
96
- max_tokens: 4096,
97
- system: systemPrompt,
98
- messages: [
99
- {
100
- role: 'user',
101
- content: userPrompt,
102
- },
103
- ],
104
- });
105
-
106
- const responseText = response.content
107
- .filter((block): block is Anthropic.TextBlock => block.type === 'text')
108
- .map((block) => block.text)
109
- .join('');
110
-
111
- return this.parseAIResponse(responseText, workflow);
112
- } catch (err) {
113
- return {
114
- explanation: '',
115
- error: err instanceof Error ? err.message : 'Unknown error',
116
- };
117
- }
118
- }
119
-
120
- async getSuggestions(workflow: Workflow, selectedStepId?: string): Promise<string[]> {
121
- // Use the prompt engineering module for context-aware suggestions
122
- return generateSuggestions(workflow, selectedStepId);
123
- }
124
-
125
- async streamPrompt(
126
- prompt: string,
127
- workflow: Workflow,
128
- onChunk: (chunk: string) => void,
129
- context?: { selectedStepId?: string; recentHistory?: string[] }
130
- ): Promise<PromptResult> {
131
- if (!this.client) {
132
- return this.processPrompt(prompt, workflow, context);
133
- }
134
-
135
- // Build context-aware prompts
136
- const { systemPrompt, userPrompt } = buildPrompt(prompt, workflow, context);
137
- let fullResponse = '';
138
-
139
- try {
140
- const stream = await this.client.messages.create({
141
- model: this.model,
142
- max_tokens: 4096,
143
- system: systemPrompt,
144
- stream: true,
145
- messages: [
146
- {
147
- role: 'user',
148
- content: userPrompt,
149
- },
150
- ],
151
- });
152
-
153
- for await (const event of stream) {
154
- if (
155
- event.type === 'content_block_delta' &&
156
- event.delta.type === 'text_delta'
157
- ) {
158
- const text = event.delta.text;
159
- fullResponse += text;
160
- onChunk(text);
161
- }
162
- }
163
-
164
- return this.parseAIResponse(fullResponse, workflow);
165
- } catch (err) {
166
- return {
167
- explanation: '',
168
- error: err instanceof Error ? err.message : 'Unknown error',
169
- };
170
- }
171
- }
172
-
173
- private parseAIResponse(responseText: string, originalWorkflow: Workflow): PromptResult {
174
- const yamlMatch = responseText.match(/```yaml\n([\s\S]*?)\n```/);
175
- let modifiedWorkflow: Workflow | undefined;
176
- let explanation = responseText;
177
-
178
- if (yamlMatch) {
179
- try {
180
- const parsedYaml = yamlParse(yamlMatch[1]);
181
- if (parsedYaml && (parsedYaml.steps || parsedYaml.metadata)) {
182
- modifiedWorkflow = parsedYaml as Workflow;
183
- const explanationMatch = responseText.match(/^([\s\S]*?)```yaml/);
184
- if (explanationMatch) {
185
- explanation = explanationMatch[1].trim();
186
- }
187
- }
188
- } catch {
189
- // Failed to parse YAML
190
- }
191
- }
192
-
193
- let diff: string | undefined;
194
- if (modifiedWorkflow) {
195
- diff = this.generateDiff(originalWorkflow, modifiedWorkflow);
196
- }
197
-
198
- return { explanation, workflow: modifiedWorkflow, diff };
199
- }
200
-
201
- private generateDiff(original: Workflow, modified: Workflow): string {
202
- const originalStepIds = new Set(original.steps?.map((s) => s.id) || []);
203
- const modifiedStepIds = new Set(modified.steps?.map((s) => s.id) || []);
204
-
205
- const added = modified.steps?.filter((s) => !originalStepIds.has(s.id)) || [];
206
- const removed = original.steps?.filter((s) => !modifiedStepIds.has(s.id)) || [];
207
-
208
- let diff = '';
209
- if (added.length > 0) {
210
- diff += `+ Added ${added.length} step(s): ${added.map((s) => s.name || s.id).join(', ')}\n`;
211
- }
212
- if (removed.length > 0) {
213
- diff += `- Removed ${removed.length} step(s): ${removed.map((s) => s.name || s.id).join(', ')}\n`;
214
- }
215
-
216
- return diff || 'No structural changes detected';
217
- }
218
-
219
- private simulateResponse(prompt: string, workflow: Workflow): Workflow {
220
- const promptLower = prompt.toLowerCase();
221
- const modifiedWorkflow = { ...workflow, steps: [...(workflow.steps || [])] };
222
-
223
- if (promptLower.includes('add') && promptLower.includes('slack')) {
224
- modifiedWorkflow.steps.push({
225
- id: `slack-${Date.now()}`,
226
- name: 'Send Slack Notification',
227
- action: 'slack.chat.postMessage',
228
- inputs: { channel: '#general', text: 'Workflow completed!' },
229
- outputVariable: 'slack_result',
230
- });
231
- } else if (promptLower.includes('add') && promptLower.includes('error')) {
232
- modifiedWorkflow.steps = modifiedWorkflow.steps.map((step) => ({
233
- ...step,
234
- errorHandling: { action: 'retry' as const, maxRetries: 3 },
235
- }));
236
- }
237
-
238
- return modifiedWorkflow;
239
- }
240
- }
241
-
242
- export function createClaudeProvider(config?: AgentConfig): ClaudeProvider {
243
- const provider = new ClaudeProvider();
244
- if (config) {
245
- provider.initialize(config);
246
- }
247
- return provider;
248
- }