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

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 (141) hide show
  1. package/README.md +380 -14
  2. package/client.log +0 -0
  3. package/dist/client/assets/{index-CM44OayM.js → index-CIvjE2Ts.js} +144 -145
  4. package/dist/client/assets/index-CIvjE2Ts.js.map +1 -0
  5. package/dist/client/assets/index-Cu3CHOQw.css +1 -0
  6. package/dist/client/index.html +2 -2
  7. package/dist/server/index.js +10 -2
  8. package/dist/server/index.js.map +1 -1
  9. package/dist/server/routes/ai.js +2 -2
  10. package/dist/server/routes/ai.js.map +1 -1
  11. package/dist/server/routes/execute.js +181 -14
  12. package/dist/server/routes/execute.js.map +1 -1
  13. package/dist/server/services/AIService.js +39 -2
  14. package/dist/server/services/AIService.js.map +1 -1
  15. package/dist/server/services/ExecutionManager.js +428 -0
  16. package/dist/server/services/ExecutionManager.js.map +1 -0
  17. package/package.json +2 -4
  18. package/server.log +0 -0
  19. package/tests/integration/fixtures/test-workflow.md +6 -0
  20. package/.marktoflow/state/workflow-state.db +0 -0
  21. package/.marktoflow/state/workflow-state.db-shm +0 -0
  22. package/.marktoflow/state/workflow-state.db-wal +0 -0
  23. package/.turbo/turbo-build.log +0 -42
  24. package/.turbo/turbo-test.log +0 -38
  25. package/dist/client/assets/index-CM44OayM.js.map +0 -1
  26. package/dist/client/assets/index-Dru63gi6.css +0 -1
  27. package/marktoflow-gui-2.0.0-alpha.12.tgz +0 -0
  28. package/playwright.config.ts +0 -27
  29. package/postcss.config.js +0 -6
  30. package/src/client/App.tsx +0 -520
  31. package/src/client/components/Canvas/Canvas.tsx +0 -425
  32. package/src/client/components/Canvas/ExecutionOverlay.tsx +0 -935
  33. package/src/client/components/Canvas/ForEachNode.tsx +0 -152
  34. package/src/client/components/Canvas/IfElseNode.tsx +0 -141
  35. package/src/client/components/Canvas/NodeContextMenu.tsx +0 -192
  36. package/src/client/components/Canvas/OutputNode.tsx +0 -111
  37. package/src/client/components/Canvas/ParallelNode.tsx +0 -157
  38. package/src/client/components/Canvas/StepNode.tsx +0 -106
  39. package/src/client/components/Canvas/SubWorkflowNode.tsx +0 -141
  40. package/src/client/components/Canvas/SwitchNode.tsx +0 -185
  41. package/src/client/components/Canvas/Toolbar.tsx +0 -227
  42. package/src/client/components/Canvas/TransformNode.tsx +0 -194
  43. package/src/client/components/Canvas/TriggerNode.tsx +0 -128
  44. package/src/client/components/Canvas/TryCatchNode.tsx +0 -164
  45. package/src/client/components/Canvas/WhileNode.tsx +0 -161
  46. package/src/client/components/Canvas/index.ts +0 -24
  47. package/src/client/components/Debug/VariableInspector.tsx +0 -148
  48. package/src/client/components/Editor/InputsEditor.tsx +0 -458
  49. package/src/client/components/Editor/NewStepWizard.tsx +0 -344
  50. package/src/client/components/Editor/StepEditor.tsx +0 -532
  51. package/src/client/components/Editor/YamlEditor.tsx +0 -160
  52. package/src/client/components/Panels/PropertiesPanel.tsx +0 -589
  53. package/src/client/components/Prompt/ChangePreview.tsx +0 -281
  54. package/src/client/components/Prompt/PromptHistoryPanel.tsx +0 -209
  55. package/src/client/components/Prompt/PromptInput.tsx +0 -110
  56. package/src/client/components/Settings/ProviderSwitcher.tsx +0 -228
  57. package/src/client/components/Sidebar/ImportDialog.tsx +0 -257
  58. package/src/client/components/Sidebar/Sidebar.tsx +0 -362
  59. package/src/client/components/common/Breadcrumb.tsx +0 -40
  60. package/src/client/components/common/Button.tsx +0 -68
  61. package/src/client/components/common/ContextMenu.tsx +0 -202
  62. package/src/client/components/common/KeyboardShortcuts.tsx +0 -149
  63. package/src/client/components/common/Modal.tsx +0 -93
  64. package/src/client/components/common/Tabs.tsx +0 -57
  65. package/src/client/components/common/ThemeToggle.tsx +0 -63
  66. package/src/client/components/index.ts +0 -32
  67. package/src/client/hooks/index.ts +0 -4
  68. package/src/client/hooks/useAIPrompt.ts +0 -108
  69. package/src/client/hooks/useCanvas.ts +0 -247
  70. package/src/client/hooks/useWebSocket.ts +0 -164
  71. package/src/client/hooks/useWorkflow.ts +0 -138
  72. package/src/client/main.tsx +0 -10
  73. package/src/client/stores/agentStore.ts +0 -109
  74. package/src/client/stores/canvasStore.ts +0 -348
  75. package/src/client/stores/editorStore.ts +0 -133
  76. package/src/client/stores/executionStore.ts +0 -502
  77. package/src/client/stores/index.ts +0 -4
  78. package/src/client/stores/layoutStore.ts +0 -103
  79. package/src/client/stores/navigationStore.ts +0 -49
  80. package/src/client/stores/promptStore.ts +0 -113
  81. package/src/client/stores/themeStore.ts +0 -75
  82. package/src/client/stores/workflowStore.ts +0 -185
  83. package/src/client/styles/globals.css +0 -452
  84. package/src/client/utils/cn.ts +0 -9
  85. package/src/client/utils/index.ts +0 -4
  86. package/src/client/utils/platform.ts +0 -46
  87. package/src/client/utils/serviceIcons.tsx +0 -97
  88. package/src/client/utils/stepValidation.ts +0 -155
  89. package/src/client/utils/workflowToGraph.ts +0 -523
  90. package/src/server/index.ts +0 -137
  91. package/src/server/routes/ai.ts +0 -91
  92. package/src/server/routes/execute.ts +0 -71
  93. package/src/server/routes/executions.ts +0 -136
  94. package/src/server/routes/tools.ts +0 -970
  95. package/src/server/routes/workflows.ts +0 -147
  96. package/src/server/services/AIService.ts +0 -105
  97. package/src/server/services/FileWatcher.ts +0 -69
  98. package/src/server/services/WorkflowService.ts +0 -601
  99. package/src/server/services/agents/claude-code-provider.ts +0 -320
  100. package/src/server/services/agents/claude-provider.ts +0 -248
  101. package/src/server/services/agents/codex-provider.ts +0 -398
  102. package/src/server/services/agents/copilot-provider.ts +0 -311
  103. package/src/server/services/agents/demo-provider.ts +0 -184
  104. package/src/server/services/agents/index.ts +0 -31
  105. package/src/server/services/agents/ollama-provider.ts +0 -267
  106. package/src/server/services/agents/prompts.ts +0 -509
  107. package/src/server/services/agents/registry.ts +0 -310
  108. package/src/server/services/agents/types.ts +0 -146
  109. package/src/server/websocket/index.ts +0 -117
  110. package/src/shared/constants.ts +0 -180
  111. package/src/shared/types.ts +0 -179
  112. package/tailwind.config.ts +0 -73
  113. package/tests/e2e/app.spec.ts +0 -90
  114. package/tests/e2e/canvas.spec.ts +0 -128
  115. package/tests/e2e/workflow.spec.ts +0 -185
  116. package/tests/integration/api.test.ts +0 -452
  117. package/tests/integration/testApp.ts +0 -31
  118. package/tests/setup.ts +0 -72
  119. package/tests/unit/ForEachNode.test.tsx +0 -308
  120. package/tests/unit/IfElseNode.test.tsx +0 -235
  121. package/tests/unit/ParallelNode.test.tsx +0 -344
  122. package/tests/unit/SwitchNode.test.tsx +0 -327
  123. package/tests/unit/TransformNode.test.tsx +0 -386
  124. package/tests/unit/TryCatchNode.test.tsx +0 -243
  125. package/tests/unit/WhileNode.test.tsx +0 -230
  126. package/tests/unit/agentStore.test.ts +0 -218
  127. package/tests/unit/canvasStore.test.ts +0 -502
  128. package/tests/unit/codexProvider.test.ts +0 -399
  129. package/tests/unit/components.test.tsx +0 -151
  130. package/tests/unit/executionStore.test.ts +0 -567
  131. package/tests/unit/layoutStore.test.ts +0 -194
  132. package/tests/unit/navigationStore.test.ts +0 -152
  133. package/tests/unit/platform.test.ts +0 -118
  134. package/tests/unit/serviceIcons.test.ts +0 -197
  135. package/tests/unit/stepValidation.test.ts +0 -226
  136. package/tests/unit/themeStore.test.ts +0 -141
  137. package/tests/unit/workflowToGraph.test.ts +0 -311
  138. package/tsconfig.json +0 -29
  139. package/tsconfig.server.json +0 -28
  140. package/vite.config.ts +0 -31
  141. package/vitest.config.ts +0 -26
@@ -1,310 +0,0 @@
1
- /**
2
- * Agent Provider Registry
3
- * Manages all available AI agent providers and provides a unified interface
4
- */
5
-
6
- import type {
7
- AgentProvider,
8
- AgentProviderEntry,
9
- AgentConfig,
10
- PromptResult,
11
- PromptHistoryItem,
12
- Workflow,
13
- } from './types.js';
14
- import { createClaudeProvider } from './claude-provider.js';
15
- import { createClaudeCodeProvider } from './claude-code-provider.js';
16
- import { createCopilotProvider } from './copilot-provider.js';
17
- import { createCodexProvider } from './codex-provider.js';
18
- import { createDemoProvider } from './demo-provider.js';
19
- import { createOllamaProvider } from './ollama-provider.js';
20
-
21
- /**
22
- * Registry of all available agent providers
23
- */
24
- export class AgentRegistry {
25
- private providers: Map<string, AgentProvider> = new Map();
26
- private activeProviderId: string = 'demo';
27
- private history: PromptHistoryItem[] = [];
28
-
29
- constructor() {
30
- // Register built-in providers
31
- // SDK-based providers with automatic CLI authentication (recommended)
32
- this.registerProvider({
33
- id: 'claude-code',
34
- name: 'Claude Code (SDK)',
35
- factory: createClaudeCodeProvider,
36
- });
37
- this.registerProvider({
38
- id: 'copilot',
39
- name: 'GitHub Copilot (SDK)',
40
- factory: createCopilotProvider,
41
- });
42
- this.registerProvider({
43
- id: 'codex',
44
- name: 'OpenAI Codex (SDK)',
45
- factory: createCodexProvider,
46
- });
47
- // API key-based providers
48
- this.registerProvider({
49
- id: 'claude',
50
- name: 'Claude (API Key)',
51
- factory: createClaudeProvider,
52
- });
53
- // Local providers
54
- this.registerProvider({
55
- id: 'ollama',
56
- name: 'Ollama (Local)',
57
- factory: createOllamaProvider,
58
- });
59
- // Demo mode (always available)
60
- this.registerProvider({
61
- id: 'demo',
62
- name: 'Demo Mode',
63
- factory: createDemoProvider,
64
- });
65
- }
66
-
67
- /**
68
- * Register a new provider
69
- */
70
- registerProvider(entry: AgentProviderEntry): void {
71
- const provider = entry.factory(entry.defaultConfig);
72
- this.providers.set(entry.id, provider);
73
- }
74
-
75
- /**
76
- * Get all registered providers
77
- */
78
- getProviders(): Array<{ id: string; name: string; ready: boolean }> {
79
- return Array.from(this.providers.entries()).map(([id, provider]) => ({
80
- id,
81
- name: provider.name,
82
- ready: provider.isReady(),
83
- }));
84
- }
85
-
86
- /**
87
- * Get a specific provider
88
- */
89
- getProvider(id: string): AgentProvider | undefined {
90
- return this.providers.get(id);
91
- }
92
-
93
- /**
94
- * Get the active provider
95
- */
96
- getActiveProvider(): AgentProvider {
97
- return this.providers.get(this.activeProviderId) || this.providers.get('demo')!;
98
- }
99
-
100
- /**
101
- * Set the active provider
102
- */
103
- async setActiveProvider(id: string, config?: AgentConfig): Promise<boolean> {
104
- const provider = this.providers.get(id);
105
- if (!provider) {
106
- return false;
107
- }
108
-
109
- if (config) {
110
- await provider.initialize(config);
111
- }
112
-
113
- if (provider.isReady()) {
114
- this.activeProviderId = id;
115
- return true;
116
- }
117
-
118
- return false;
119
- }
120
-
121
- /**
122
- * Get the active provider ID
123
- */
124
- getActiveProviderId(): string {
125
- return this.activeProviderId;
126
- }
127
-
128
- /**
129
- * Auto-detect and set the best available provider
130
- * Priority: SDK-based (auto-auth) > API key-based > Local > Demo
131
- */
132
- async autoDetectProvider(): Promise<string> {
133
- // Try Claude Code SDK first (uses automatic CLI authentication)
134
- const claudeCodeProvider = this.providers.get('claude-code');
135
- if (claudeCodeProvider) {
136
- await claudeCodeProvider.initialize({
137
- options: {
138
- cwd: process.cwd(),
139
- },
140
- });
141
- if (claudeCodeProvider.isReady()) {
142
- this.activeProviderId = 'claude-code';
143
- return 'claude-code';
144
- }
145
- }
146
-
147
- // Try GitHub Copilot SDK (uses automatic CLI authentication)
148
- const copilotProvider = this.providers.get('copilot');
149
- if (copilotProvider) {
150
- await copilotProvider.initialize({
151
- baseUrl: process.env.COPILOT_CLI_URL,
152
- options: {
153
- cliPath: process.env.COPILOT_CLI_PATH,
154
- },
155
- });
156
- if (copilotProvider.isReady()) {
157
- this.activeProviderId = 'copilot';
158
- return 'copilot';
159
- }
160
- }
161
-
162
- // Try OpenAI Codex SDK (uses OPENAI_API_KEY)
163
- const codexProvider = this.providers.get('codex');
164
- if (codexProvider) {
165
- await codexProvider.initialize({
166
- apiKey: process.env.OPENAI_API_KEY,
167
- options: {
168
- cwd: process.cwd(),
169
- },
170
- });
171
- if (codexProvider.isReady()) {
172
- this.activeProviderId = 'codex';
173
- return 'codex';
174
- }
175
- }
176
-
177
- // Try Claude with API key (requires ANTHROPIC_API_KEY)
178
- const claudeProvider = this.providers.get('claude');
179
- if (claudeProvider) {
180
- await claudeProvider.initialize({
181
- apiKey: process.env.ANTHROPIC_API_KEY,
182
- });
183
- if (claudeProvider.isReady()) {
184
- this.activeProviderId = 'claude';
185
- return 'claude';
186
- }
187
- }
188
-
189
- // Try Ollama (if running locally)
190
- const ollamaProvider = this.providers.get('ollama');
191
- if (ollamaProvider) {
192
- await ollamaProvider.initialize({
193
- baseUrl: process.env.OLLAMA_BASE_URL || 'http://localhost:11434',
194
- });
195
- if (ollamaProvider.isReady()) {
196
- this.activeProviderId = 'ollama';
197
- return 'ollama';
198
- }
199
- }
200
-
201
- // Fall back to demo mode
202
- this.activeProviderId = 'demo';
203
- return 'demo';
204
- }
205
-
206
- /**
207
- * Process a prompt using the active provider
208
- */
209
- async processPrompt(prompt: string, workflow: Workflow): Promise<PromptResult> {
210
- const provider = this.getActiveProvider();
211
- const result = await provider.processPrompt(prompt, workflow);
212
-
213
- // Record in history
214
- this.history.unshift({
215
- prompt,
216
- response: result.explanation,
217
- timestamp: new Date(),
218
- success: !result.error,
219
- provider: provider.id,
220
- });
221
-
222
- // Keep only last 50 items
223
- if (this.history.length > 50) {
224
- this.history = this.history.slice(0, 50);
225
- }
226
-
227
- return result;
228
- }
229
-
230
- /**
231
- * Get suggestions using the active provider
232
- */
233
- async getSuggestions(workflow: Workflow, selectedStepId?: string): Promise<string[]> {
234
- const provider = this.getActiveProvider();
235
- return provider.getSuggestions(workflow, selectedStepId);
236
- }
237
-
238
- /**
239
- * Stream a prompt using the active provider (if supported)
240
- */
241
- async streamPrompt(
242
- prompt: string,
243
- workflow: Workflow,
244
- onChunk: (chunk: string) => void
245
- ): Promise<PromptResult> {
246
- const provider = this.getActiveProvider();
247
-
248
- if (provider.streamPrompt) {
249
- const result = await provider.streamPrompt(prompt, workflow, onChunk);
250
-
251
- this.history.unshift({
252
- prompt,
253
- response: result.explanation,
254
- timestamp: new Date(),
255
- success: !result.error,
256
- provider: provider.id,
257
- });
258
-
259
- return result;
260
- }
261
-
262
- // Fall back to non-streaming
263
- return this.processPrompt(prompt, workflow);
264
- }
265
-
266
- /**
267
- * Get prompt history
268
- */
269
- getHistory(limit: number = 20): PromptHistoryItem[] {
270
- return this.history.slice(0, limit);
271
- }
272
-
273
- /**
274
- * Clear history
275
- */
276
- clearHistory(): void {
277
- this.history = [];
278
- }
279
-
280
- /**
281
- * Get provider status
282
- */
283
- getStatus(): {
284
- activeProvider: string;
285
- providers: Array<{ id: string; name: string; ready: boolean; model?: string; error?: string }>;
286
- } {
287
- return {
288
- activeProvider: this.activeProviderId,
289
- providers: Array.from(this.providers.entries()).map(([id, provider]) => ({
290
- id,
291
- name: provider.name,
292
- ...provider.getStatus(),
293
- })),
294
- };
295
- }
296
- }
297
-
298
- // Singleton instance
299
- let registryInstance: AgentRegistry | null = null;
300
-
301
- export function getAgentRegistry(): AgentRegistry {
302
- if (!registryInstance) {
303
- registryInstance = new AgentRegistry();
304
- }
305
- return registryInstance;
306
- }
307
-
308
- export function createAgentRegistry(): AgentRegistry {
309
- return new AgentRegistry();
310
- }
@@ -1,146 +0,0 @@
1
- /**
2
- * Abstract types for AI agent providers
3
- * Allows the GUI to work with any agent backend (Claude, OpenCode, Ollama, etc.)
4
- */
5
-
6
- export interface Workflow {
7
- metadata: Record<string, unknown>;
8
- steps: WorkflowStep[];
9
- tools?: Record<string, unknown>;
10
- inputs?: Record<string, unknown>;
11
- }
12
-
13
- export interface WorkflowStep {
14
- id: string;
15
- name?: string;
16
- action?: string;
17
- inputs?: Record<string, unknown>;
18
- outputVariable?: string;
19
- errorHandling?: {
20
- action: 'stop' | 'continue' | 'retry';
21
- maxRetries?: number;
22
- };
23
- conditions?: string[];
24
- }
25
-
26
- export interface PromptResult {
27
- explanation: string;
28
- workflow?: Workflow;
29
- diff?: string;
30
- error?: string;
31
- }
32
-
33
- export interface PromptHistoryItem {
34
- prompt: string;
35
- response: string;
36
- timestamp: Date;
37
- success: boolean;
38
- provider: string;
39
- }
40
-
41
- export interface AgentCapabilities {
42
- /** Whether the provider supports streaming responses */
43
- streaming: boolean;
44
- /** Whether the provider supports tool use */
45
- toolUse: boolean;
46
- /** Whether the provider supports code execution */
47
- codeExecution: boolean;
48
- /** Whether the provider supports system prompts */
49
- systemPrompts: boolean;
50
- /** Maximum context length in tokens */
51
- maxContextLength?: number;
52
- /** List of available models */
53
- models: string[];
54
- }
55
-
56
- export interface AgentConfig {
57
- /** API key or authentication token */
58
- apiKey?: string;
59
- /** Base URL for API requests */
60
- baseUrl?: string;
61
- /** Default model to use */
62
- model?: string;
63
- /** Request timeout in milliseconds */
64
- timeout?: number;
65
- /** Additional provider-specific options */
66
- options?: Record<string, unknown>;
67
- }
68
-
69
- /**
70
- * Abstract interface for AI agent providers
71
- * Each provider (Claude, OpenCode, Ollama) implements this interface
72
- */
73
- export interface AgentProvider {
74
- /** Unique identifier for this provider */
75
- readonly id: string;
76
- /** Human-readable name */
77
- readonly name: string;
78
- /** Provider capabilities */
79
- readonly capabilities: AgentCapabilities;
80
-
81
- /**
82
- * Initialize the provider with configuration
83
- * @param config - Provider configuration
84
- */
85
- initialize(config: AgentConfig): Promise<void>;
86
-
87
- /**
88
- * Check if the provider is ready and properly configured
89
- */
90
- isReady(): boolean;
91
-
92
- /**
93
- * Process a natural language prompt to modify a workflow
94
- * @param prompt - User's natural language request
95
- * @param workflow - Current workflow to modify
96
- */
97
- processPrompt(prompt: string, workflow: Workflow): Promise<PromptResult>;
98
-
99
- /**
100
- * Get suggested prompts based on the current workflow
101
- * @param workflow - Current workflow
102
- * @param selectedStepId - Optional selected step ID
103
- */
104
- getSuggestions(workflow: Workflow, selectedStepId?: string): Promise<string[]>;
105
-
106
- /**
107
- * Stream a response (if supported)
108
- * @param prompt - User prompt
109
- * @param workflow - Current workflow
110
- * @param onChunk - Callback for each chunk
111
- */
112
- streamPrompt?(
113
- prompt: string,
114
- workflow: Workflow,
115
- onChunk: (chunk: string) => void
116
- ): Promise<PromptResult>;
117
-
118
- /**
119
- * Cancel any ongoing request
120
- */
121
- cancel?(): Promise<void>;
122
-
123
- /**
124
- * Get provider-specific health status
125
- */
126
- getStatus(): {
127
- ready: boolean;
128
- model?: string;
129
- error?: string;
130
- };
131
- }
132
-
133
- /**
134
- * Factory function type for creating agent providers
135
- */
136
- export type AgentProviderFactory = (config?: AgentConfig) => AgentProvider;
137
-
138
- /**
139
- * Registry entry for agent providers
140
- */
141
- export interface AgentProviderEntry {
142
- id: string;
143
- name: string;
144
- factory: AgentProviderFactory;
145
- defaultConfig?: AgentConfig;
146
- }
@@ -1,117 +0,0 @@
1
- import type { Server as SocketIOServer, Socket } from 'socket.io';
2
-
3
- interface ClientState {
4
- subscribedWorkflows: Set<string>;
5
- subscribedExecutions: Set<string>;
6
- }
7
-
8
- const clients = new Map<string, ClientState>();
9
-
10
- export function setupWebSocket(io: SocketIOServer) {
11
- io.on('connection', (socket: Socket) => {
12
- console.log(`Client connected: ${socket.id}`);
13
-
14
- // Initialize client state
15
- clients.set(socket.id, {
16
- subscribedWorkflows: new Set(),
17
- subscribedExecutions: new Set(),
18
- });
19
-
20
- // Handle workflow subscription
21
- socket.on('workflow:subscribe', (workflowPath: string) => {
22
- const state = clients.get(socket.id);
23
- if (state) {
24
- state.subscribedWorkflows.add(workflowPath);
25
- socket.join(`workflow:${workflowPath}`);
26
- console.log(`Client ${socket.id} subscribed to workflow: ${workflowPath}`);
27
- }
28
- });
29
-
30
- socket.on('workflow:unsubscribe', (workflowPath: string) => {
31
- const state = clients.get(socket.id);
32
- if (state) {
33
- state.subscribedWorkflows.delete(workflowPath);
34
- socket.leave(`workflow:${workflowPath}`);
35
- }
36
- });
37
-
38
- // Handle execution subscription
39
- socket.on('execution:subscribe', (runId: string) => {
40
- const state = clients.get(socket.id);
41
- if (state) {
42
- state.subscribedExecutions.add(runId);
43
- socket.join(`execution:${runId}`);
44
- console.log(`Client ${socket.id} subscribed to execution: ${runId}`);
45
- }
46
- });
47
-
48
- socket.on('execution:unsubscribe', (runId: string) => {
49
- const state = clients.get(socket.id);
50
- if (state) {
51
- state.subscribedExecutions.delete(runId);
52
- socket.leave(`execution:${runId}`);
53
- }
54
- });
55
-
56
- // Handle disconnect
57
- socket.on('disconnect', () => {
58
- console.log(`Client disconnected: ${socket.id}`);
59
- clients.delete(socket.id);
60
- });
61
- });
62
-
63
- // Helper functions to emit events
64
- return {
65
- // Emit to all clients subscribed to a workflow
66
- emitWorkflowUpdate(workflowPath: string, data: any) {
67
- io.to(`workflow:${workflowPath}`).emit('workflow:updated', {
68
- path: workflowPath,
69
- ...data,
70
- });
71
- },
72
-
73
- // Emit execution started
74
- emitExecutionStarted(runId: string, data: any) {
75
- io.to(`execution:${runId}`).emit('execution:started', {
76
- runId,
77
- ...data,
78
- });
79
- // Also broadcast to all clients for global execution history updates
80
- io.emit('execution:new', {
81
- runId,
82
- ...data,
83
- });
84
- },
85
-
86
- // Emit execution step update
87
- emitExecutionStep(runId: string, data: any) {
88
- io.to(`execution:${runId}`).emit('execution:step', {
89
- runId,
90
- ...data,
91
- });
92
- },
93
-
94
- // Emit execution completed
95
- emitExecutionCompleted(runId: string, data: any) {
96
- io.to(`execution:${runId}`).emit('execution:completed', {
97
- runId,
98
- ...data,
99
- });
100
- },
101
-
102
- // Emit AI processing status
103
- emitAIProcessing(socketId: string, processing: boolean) {
104
- io.to(socketId).emit('ai:processing', { processing });
105
- },
106
-
107
- // Emit AI response
108
- emitAIResponse(socketId: string, response: any) {
109
- io.to(socketId).emit('ai:response', response);
110
- },
111
-
112
- // Broadcast to all clients
113
- broadcast(event: string, data: any) {
114
- io.emit(event, data);
115
- },
116
- };
117
- }