@flowdrop/flowdrop 2.0.0-beta.1 → 2.0.0-beta.11

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 (270) hide show
  1. package/CHANGELOG.md +210 -0
  2. package/MIGRATION-2.0.md +173 -3
  3. package/README.md +5 -5
  4. package/dist/adapters/WorkflowAdapter.js +4 -5
  5. package/dist/adapters/agentspec/AgentSpecAdapter.js +3 -3
  6. package/dist/adapters/agentspec/defaultNodeTypes.js +9 -9
  7. package/dist/api/enhanced-client.js +6 -11
  8. package/dist/chat/batchFeedback.js +1 -1
  9. package/dist/chat/commandClassifier.d.ts +11 -0
  10. package/dist/chat/commandClassifier.js +20 -0
  11. package/dist/chat/historyBuilder.d.ts +39 -0
  12. package/dist/chat/historyBuilder.js +82 -0
  13. package/dist/chat/index.d.ts +2 -1
  14. package/dist/chat/index.js +2 -1
  15. package/dist/chat/responseParser.js +16 -12
  16. package/dist/commands/executor.js +51 -26
  17. package/dist/commands/parser.d.ts +12 -0
  18. package/dist/commands/parser.js +33 -6
  19. package/dist/commands/storeIntegration.svelte.js +11 -1
  20. package/dist/commands/types.js +5 -5
  21. package/dist/components/App.svelte +547 -386
  22. package/dist/components/App.svelte.d.ts +16 -8
  23. package/dist/components/Button.stories.svelte +65 -0
  24. package/dist/components/Button.stories.svelte.d.ts +19 -0
  25. package/dist/components/Button.svelte +62 -0
  26. package/dist/components/Button.svelte.d.ts +24 -0
  27. package/dist/components/CanvasIconButton.svelte +76 -0
  28. package/dist/components/CanvasIconButton.svelte.d.ts +18 -0
  29. package/dist/components/ConfigForm.svelte +194 -565
  30. package/dist/components/ConfigForm.svelte.d.ts +24 -7
  31. package/dist/components/ConfigModal.svelte +9 -1
  32. package/dist/components/ConfigPanel.svelte +234 -15
  33. package/dist/components/ConfigPanel.svelte.d.ts +6 -0
  34. package/dist/components/EditorStatusBar.stories.svelte +44 -0
  35. package/dist/components/EditorStatusBar.stories.svelte.d.ts +27 -0
  36. package/dist/components/EditorStatusBar.svelte +99 -0
  37. package/dist/components/EditorStatusBar.svelte.d.ts +15 -0
  38. package/dist/components/IconButton.svelte +80 -0
  39. package/dist/components/IconButton.svelte.d.ts +30 -0
  40. package/dist/components/Input.svelte +74 -0
  41. package/dist/components/Input.svelte.d.ts +17 -0
  42. package/dist/components/LogoWordmark.svelte +113 -0
  43. package/dist/components/LogoWordmark.svelte.d.ts +26 -0
  44. package/dist/components/Navbar.svelte +17 -63
  45. package/dist/components/Navbar.svelte.d.ts +3 -0
  46. package/dist/components/NodeSidebar.svelte +21 -126
  47. package/dist/components/NodeSwapPicker.svelte +12 -30
  48. package/dist/components/PipelineStatus.svelte +6 -1
  49. package/dist/components/PipelineStatus.svelte.d.ts +3 -0
  50. package/dist/components/PortMappingRow.svelte +0 -2
  51. package/dist/components/SchemaForm.svelte +4 -14
  52. package/dist/components/Select.svelte +53 -0
  53. package/dist/components/Select.svelte.d.ts +15 -0
  54. package/dist/components/SettingsModal.svelte +0 -5
  55. package/dist/components/SettingsPanel.svelte +33 -6
  56. package/dist/components/Textarea.svelte +39 -0
  57. package/dist/components/Textarea.svelte.d.ts +12 -0
  58. package/dist/components/ThemeToggle.svelte +15 -94
  59. package/dist/components/UniversalNode.svelte +36 -4
  60. package/dist/components/UniversalNode.svelte.d.ts +1 -1
  61. package/dist/components/WorkflowEditor.svelte +71 -54
  62. package/dist/components/WorkflowEditor.svelte.d.ts +21 -0
  63. package/dist/components/chat/AIChatPanel.svelte +49 -8
  64. package/dist/components/chat/CommandPreview.svelte +10 -1
  65. package/dist/components/console/ConsoleAutocomplete.svelte +1 -1
  66. package/dist/components/console/ConsoleInput.svelte +3 -3
  67. package/dist/components/console/ConsoleOutput.svelte +2 -2
  68. package/dist/components/form/FormArray.svelte +37 -173
  69. package/dist/components/form/FormAutocomplete.svelte +18 -15
  70. package/dist/components/form/FormCheckboxGroup.svelte +1 -5
  71. package/dist/components/form/FormCodeEditor.svelte +9 -7
  72. package/dist/components/form/FormField.svelte +18 -42
  73. package/dist/components/form/FormFieldLight.svelte +52 -48
  74. package/dist/components/form/FormFieldLight.svelte.d.ts +12 -0
  75. package/dist/components/form/FormFieldset.svelte +45 -11
  76. package/dist/components/form/FormMarkdownEditor.svelte +8 -5
  77. package/dist/components/form/FormNumberField.svelte +4 -36
  78. package/dist/components/form/FormPorts.svelte +280 -0
  79. package/dist/components/form/FormPorts.svelte.d.ts +13 -0
  80. package/dist/components/form/FormRangeField.svelte +63 -30
  81. package/dist/components/form/FormSelect.svelte +13 -75
  82. package/dist/components/form/FormTemplateEditor.svelte +6 -4
  83. package/dist/components/form/FormTextField.svelte +3 -35
  84. package/dist/components/form/FormTextarea.svelte +4 -39
  85. package/dist/components/form/FormToggle.svelte +27 -6
  86. package/dist/components/form/FormToggle.svelte.d.ts +5 -0
  87. package/dist/components/form/FormUISchemaRenderer.svelte +3 -1
  88. package/dist/components/form/resolveFieldType.d.ts +24 -0
  89. package/dist/components/form/resolveFieldType.js +55 -0
  90. package/dist/components/icons/CloseIcon.svelte +6 -0
  91. package/dist/components/icons/CloseIcon.svelte.d.ts +26 -0
  92. package/dist/components/icons/CommandLineIcon.svelte +15 -0
  93. package/dist/components/icons/CommandLineIcon.svelte.d.ts +26 -0
  94. package/dist/components/icons/MenuIcon.svelte +4 -0
  95. package/dist/components/icons/MenuIcon.svelte.d.ts +26 -0
  96. package/dist/components/icons/MenuOpenIcon.svelte +6 -0
  97. package/dist/components/icons/MenuOpenIcon.svelte.d.ts +26 -0
  98. package/dist/components/interrupt/ChoicePrompt.svelte +0 -10
  99. package/dist/components/interrupt/ConfirmationPrompt.svelte +0 -5
  100. package/dist/components/interrupt/InterruptBubble.svelte +11 -12
  101. package/dist/components/interrupt/ReviewPrompt.svelte +0 -20
  102. package/dist/components/interrupt/TextInputPrompt.svelte +0 -6
  103. package/dist/components/layouts/MainLayout.svelte +4 -5
  104. package/dist/components/nodes/AtomNode.svelte +62 -76
  105. package/dist/components/nodes/AtomNode.svelte.d.ts +1 -1
  106. package/dist/components/nodes/GatewayNode.svelte +117 -164
  107. package/dist/components/nodes/GatewayNode.svelte.d.ts +1 -1
  108. package/dist/components/nodes/IdeaNode.svelte +72 -98
  109. package/dist/components/nodes/IdeaNode.svelte.d.ts +8 -4
  110. package/dist/components/nodes/NodeConfigButton.svelte +86 -0
  111. package/dist/components/nodes/NodeConfigButton.svelte.d.ts +15 -0
  112. package/dist/components/nodes/NotesNode.svelte +76 -85
  113. package/dist/components/nodes/NotesNode.svelte.d.ts +8 -4
  114. package/dist/components/nodes/SimpleNode.svelte +59 -133
  115. package/dist/components/nodes/SimpleNode.svelte.d.ts +4 -4
  116. package/dist/components/nodes/SquareNode.svelte +110 -164
  117. package/dist/components/nodes/SquareNode.svelte.d.ts +4 -4
  118. package/dist/components/nodes/TerminalNode.svelte +62 -124
  119. package/dist/components/nodes/TerminalNode.svelte.d.ts +4 -4
  120. package/dist/components/nodes/ToolNode.svelte +92 -103
  121. package/dist/components/nodes/ToolNode.svelte.d.ts +6 -6
  122. package/dist/components/nodes/WorkflowNode.svelte +132 -191
  123. package/dist/components/nodes/WorkflowNode.svelte.d.ts +1 -1
  124. package/dist/components/playground/ChatInput.svelte +316 -27
  125. package/dist/components/playground/ChatInput.svelte.d.ts +31 -1
  126. package/dist/components/playground/ControlPanel.svelte +22 -0
  127. package/dist/components/playground/ControlPanel.svelte.d.ts +13 -0
  128. package/dist/components/playground/InputCollector.svelte +11 -48
  129. package/dist/components/playground/PipelineKanbanView.svelte +6 -4
  130. package/dist/components/playground/PipelineKanbanView.svelte.d.ts +2 -0
  131. package/dist/components/playground/PipelinePanel.svelte +20 -3
  132. package/dist/components/playground/PipelinePanel.svelte.d.ts +2 -0
  133. package/dist/components/playground/PipelineTableView.svelte +6 -4
  134. package/dist/components/playground/PipelineTableView.svelte.d.ts +2 -0
  135. package/dist/components/playground/Playground.svelte +292 -28
  136. package/dist/components/playground/Playground.svelte.d.ts +3 -0
  137. package/dist/components/playground/PlaygroundApp.svelte +6 -1
  138. package/dist/components/playground/PlaygroundApp.svelte.d.ts +3 -0
  139. package/dist/components/playground/PlaygroundModal.svelte +5 -0
  140. package/dist/components/playground/PlaygroundModal.svelte.d.ts +3 -0
  141. package/dist/components/playground/PlaygroundStudio.svelte +7 -6
  142. package/dist/components/playground/PlaygroundStudio.svelte.d.ts +3 -0
  143. package/dist/components/playground/pipelineViewUtils.svelte.d.ts +2 -1
  144. package/dist/components/playground/pipelineViewUtils.svelte.js +2 -2
  145. package/dist/components/surfaces/SurfaceOverlay.svelte +153 -0
  146. package/dist/components/surfaces/SurfaceOverlay.svelte.d.ts +14 -0
  147. package/dist/components/surfaces/TabbedSurface.svelte +133 -0
  148. package/dist/components/surfaces/TabbedSurface.svelte.d.ts +27 -0
  149. package/dist/config/endpoints.d.ts +71 -1
  150. package/dist/config/endpoints.js +46 -5
  151. package/dist/core/index.d.ts +2 -3
  152. package/dist/core/index.js +2 -6
  153. package/dist/display/index.d.ts +6 -1
  154. package/dist/display/index.js +9 -1
  155. package/dist/editor/index.d.ts +1 -1
  156. package/dist/editor/index.js +1 -1
  157. package/dist/form/full.d.ts +2 -1
  158. package/dist/form/full.js +4 -1
  159. package/dist/form/index.d.ts +0 -1
  160. package/dist/form/index.js +3 -2
  161. package/dist/helpers/workflowEditorHelper.d.ts +4 -2
  162. package/dist/helpers/workflowEditorHelper.js +8 -8
  163. package/dist/messages/defaults.d.ts +98 -0
  164. package/dist/messages/defaults.js +58 -1
  165. package/dist/messages/index.d.ts +1 -1
  166. package/dist/messages/index.js +1 -1
  167. package/dist/openapi/v1/openapi.yaml +35 -23
  168. package/dist/playground/commands/args.d.ts +32 -0
  169. package/dist/playground/commands/args.js +50 -0
  170. package/dist/playground/commands/dispatch.d.ts +143 -0
  171. package/dist/playground/commands/dispatch.js +162 -0
  172. package/dist/playground/commands/index.d.ts +14 -0
  173. package/dist/playground/commands/index.js +10 -0
  174. package/dist/playground/commands/parser.d.ts +38 -0
  175. package/dist/playground/commands/parser.js +163 -0
  176. package/dist/playground/commands/registry.d.ts +42 -0
  177. package/dist/playground/commands/registry.js +122 -0
  178. package/dist/playground/commands/suggest.d.ts +37 -0
  179. package/dist/playground/commands/suggest.js +46 -0
  180. package/dist/playground/commands/types.d.ts +111 -0
  181. package/dist/playground/commands/types.js +15 -0
  182. package/dist/playground/index.d.ts +21 -2
  183. package/dist/playground/index.js +27 -2
  184. package/dist/playground/mount.d.ts +19 -5
  185. package/dist/playground/mount.js +16 -8
  186. package/dist/playground/runAction.d.ts +48 -0
  187. package/dist/playground/runAction.js +31 -0
  188. package/dist/registry/builtinNodeTypes.d.ts +53 -0
  189. package/dist/registry/builtinNodeTypes.js +67 -0
  190. package/dist/registry/builtinNodes.d.ts +2 -39
  191. package/dist/registry/builtinNodes.js +6 -53
  192. package/dist/registry/nodeComponentRegistry.d.ts +2 -1
  193. package/dist/schemas/v1/workflow.schema.json +16 -14
  194. package/dist/services/agentSpecExecutionService.d.ts +0 -2
  195. package/dist/services/agentSpecExecutionService.js +0 -2
  196. package/dist/services/apiVariableService.js +12 -26
  197. package/dist/services/categoriesApi.js +3 -6
  198. package/dist/services/chatService.d.ts +4 -3
  199. package/dist/services/chatService.js +13 -18
  200. package/dist/services/dynamicSchemaService.d.ts +31 -4
  201. package/dist/services/dynamicSchemaService.js +62 -33
  202. package/dist/services/historyService.d.ts +30 -8
  203. package/dist/services/historyService.js +51 -15
  204. package/dist/services/interruptService.d.ts +7 -6
  205. package/dist/services/interruptService.js +19 -21
  206. package/dist/services/pipelineSignalService.d.ts +97 -0
  207. package/dist/services/pipelineSignalService.js +94 -0
  208. package/dist/services/playgroundService.d.ts +21 -8
  209. package/dist/services/playgroundService.js +45 -25
  210. package/dist/services/portConfigApi.js +3 -6
  211. package/dist/services/settingsService.d.ts +9 -4
  212. package/dist/services/settingsService.js +23 -12
  213. package/dist/services/workflowLaunchService.d.ts +74 -0
  214. package/dist/services/workflowLaunchService.js +74 -0
  215. package/dist/skins/drafter.d.ts +30 -0
  216. package/dist/skins/drafter.js +198 -0
  217. package/dist/skins/index.d.ts +2 -1
  218. package/dist/skins/index.js +4 -2
  219. package/dist/stores/apiContext.d.ts +11 -0
  220. package/dist/stores/apiContext.js +15 -0
  221. package/dist/stores/categoriesStore.svelte.js +0 -1
  222. package/dist/stores/historyStore.svelte.d.ts +17 -3
  223. package/dist/stores/historyStore.svelte.js +30 -3
  224. package/dist/stores/instanceContainer.svelte.js +5 -0
  225. package/dist/stores/playgroundStore.svelte.js +1 -3
  226. package/dist/stores/settingsStore.svelte.d.ts +13 -0
  227. package/dist/stores/settingsStore.svelte.js +32 -0
  228. package/dist/stores/workflowStore.svelte.d.ts +42 -5
  229. package/dist/stores/workflowStore.svelte.js +109 -32
  230. package/dist/styles/base.css +285 -14
  231. package/dist/styles/tokens.css +60 -2
  232. package/dist/svelte-app.d.ts +18 -1
  233. package/dist/svelte-app.js +75 -110
  234. package/dist/themes/drafter.d.ts +2 -0
  235. package/dist/themes/drafter.js +15 -0
  236. package/dist/themes/index.d.ts +2 -1
  237. package/dist/themes/index.js +8 -2
  238. package/dist/types/auth.d.ts +9 -51
  239. package/dist/types/auth.js +4 -54
  240. package/dist/types/chat.d.ts +5 -1
  241. package/dist/types/events.d.ts +18 -0
  242. package/dist/types/events.js +2 -1
  243. package/dist/types/index.d.ts +84 -29
  244. package/dist/types/index.js +0 -1
  245. package/dist/types/settings.d.ts +28 -1
  246. package/dist/types/settings.js +6 -3
  247. package/dist/types/skin.d.ts +1 -1
  248. package/dist/types/theme.d.ts +16 -2
  249. package/dist/types/uischema.d.ts +5 -0
  250. package/dist/utils/canvasSelection.d.ts +25 -0
  251. package/dist/utils/canvasSelection.js +37 -0
  252. package/dist/utils/colors.d.ts +27 -0
  253. package/dist/utils/colors.js +23 -0
  254. package/dist/utils/connections.js +20 -56
  255. package/dist/utils/edgeStyling.js +9 -5
  256. package/dist/utils/fetchWithAuth.d.ts +36 -15
  257. package/dist/utils/fetchWithAuth.js +53 -23
  258. package/dist/utils/nodeFormSchema.d.ts +51 -0
  259. package/dist/utils/nodeFormSchema.js +87 -0
  260. package/dist/utils/nodeIds.d.ts +1 -1
  261. package/dist/utils/nodeIds.js +1 -1
  262. package/dist/utils/nodeSwap.js +3 -6
  263. package/dist/utils/nodeTypes.js +1 -1
  264. package/dist/utils/portUtils.d.ts +47 -11
  265. package/dist/utils/portUtils.js +67 -14
  266. package/dist/utils/portal.d.ts +18 -0
  267. package/dist/utils/portal.js +34 -0
  268. package/dist/utils/schemaMerge.d.ts +25 -0
  269. package/dist/utils/schemaMerge.js +61 -0
  270. package/package.json +2 -1
@@ -5,8 +5,8 @@
5
5
  *
6
6
  * @module services/apiVariableService
7
7
  */
8
- import { logger } from '../utils/logger.js';
9
8
  import { DEFAULT_CACHE_TTL_MS } from '../config/constants.js';
9
+ import { authenticatedFetch } from '../utils/fetchWithAuth.js';
10
10
  /**
11
11
  * Variable schema cache with TTL support
12
12
  * Key format: `variables:{workflowId}:{nodeId}`
@@ -142,25 +142,9 @@ export async function fetchVariableSchema(endpointConfig, workflowId, nodeId, co
142
142
  // Prepare request options
143
143
  const method = endpoint.method ?? 'GET';
144
144
  const timeout = endpoint.timeout ?? 30000;
145
- const headers = {
146
- Accept: 'application/json',
147
- 'Content-Type': 'application/json',
148
- ...endpoint.headers
149
- };
150
- // Add auth headers from AuthProvider if available
151
- if (authProvider) {
152
- try {
153
- const authHeaders = await authProvider.getAuthHeaders();
154
- Object.assign(headers, authHeaders);
155
- }
156
- catch (error) {
157
- logger.warn('Failed to get auth headers:', error);
158
- }
159
- }
160
145
  // Prepare fetch options
161
146
  const fetchOptions = {
162
147
  method,
163
- headers,
164
148
  signal: AbortSignal.timeout(timeout)
165
149
  };
166
150
  // Add body for non-GET requests
@@ -169,7 +153,16 @@ export async function fetchVariableSchema(endpointConfig, workflowId, nodeId, co
169
153
  fetchOptions.body = JSON.stringify(resolvedBody);
170
154
  }
171
155
  try {
172
- const response = await fetch(url, fetchOptions);
156
+ // authenticatedFetch merges auth headers and transparently refreshes +
157
+ // retries once on 401 via the provider's onUnauthorized hook.
158
+ const response = await authenticatedFetch(url, fetchOptions, {
159
+ authProvider,
160
+ baseHeaders: {
161
+ Accept: 'application/json',
162
+ 'Content-Type': 'application/json',
163
+ ...endpoint.headers
164
+ }
165
+ });
173
166
  // Handle 404 as "no variables available"
174
167
  if (response.status === 404) {
175
168
  return {
@@ -179,15 +172,8 @@ export async function fetchVariableSchema(endpointConfig, workflowId, nodeId, co
179
172
  };
180
173
  }
181
174
  if (!response.ok) {
182
- // Handle authentication errors
175
+ // Auth errors remain after the provider's refresh attempt.
183
176
  if (response.status === 401 || response.status === 403) {
184
- if (authProvider?.onUnauthorized) {
185
- const refreshed = await authProvider.onUnauthorized();
186
- if (refreshed) {
187
- // Retry with refreshed auth
188
- return fetchVariableSchema(endpointConfig, workflowId, nodeId, config, authProvider);
189
- }
190
- }
191
177
  return {
192
178
  success: false,
193
179
  error: 'Authentication failed'
@@ -2,7 +2,8 @@
2
2
  * Categories API Service
3
3
  * Handles fetching category definitions from the backend
4
4
  */
5
- import { buildEndpointUrl, getEndpointHeaders } from '../config/endpoints.js';
5
+ import { buildEndpointUrl } from '../config/endpoints.js';
6
+ import { authenticatedFetch } from '../utils/fetchWithAuth.js';
6
7
  import { DEFAULT_CATEGORIES } from '../config/defaultCategories.js';
7
8
  import { logger } from '../utils/logger.js';
8
9
  /**
@@ -11,11 +12,7 @@ import { logger } from '../utils/logger.js';
11
12
  export async function fetchCategories(endpointConfig, authProvider) {
12
13
  try {
13
14
  const url = buildEndpointUrl(endpointConfig, endpointConfig.endpoints.categories);
14
- const configHeaders = getEndpointHeaders(endpointConfig, 'categories');
15
- const authHeaders = authProvider ? await authProvider.getAuthHeaders() : {};
16
- const response = await fetch(url, {
17
- headers: { ...configHeaders, ...authHeaders }
18
- });
15
+ const response = await authenticatedFetch(url, {}, { config: endpointConfig, endpointKey: 'categories', authProvider });
19
16
  if (!response.ok) {
20
17
  throw new Error(`HTTP ${response.status}: ${response.statusText}`);
21
18
  }
@@ -8,6 +8,7 @@
8
8
  */
9
9
  import type { ChatRequest, ChatResponse, ChatHistoryMessage } from '../types/chat.js';
10
10
  import type { EndpointConfig } from '../config/endpoints.js';
11
+ import type { AuthProvider } from '../types/auth.js';
11
12
  /**
12
13
  * Chat Service class
13
14
  *
@@ -48,20 +49,20 @@ export declare class ChatService {
48
49
  * @param request - The chat request payload
49
50
  * @returns The chat response from the LLM
50
51
  */
51
- sendMessage(endpointConfig: EndpointConfig | null, workflowId: string, request: ChatRequest): Promise<ChatResponse>;
52
+ sendMessage(endpointConfig: EndpointConfig | null, workflowId: string, request: ChatRequest, authProvider?: AuthProvider): Promise<ChatResponse>;
52
53
  /**
53
54
  * Get conversation history for a workflow
54
55
  *
55
56
  * @param workflowId - The workflow ID
56
57
  * @returns Array of chat history messages
57
58
  */
58
- getHistory(endpointConfig: EndpointConfig | null, workflowId: string): Promise<ChatHistoryMessage[]>;
59
+ getHistory(endpointConfig: EndpointConfig | null, workflowId: string, authProvider?: AuthProvider): Promise<ChatHistoryMessage[]>;
59
60
  /**
60
61
  * Clear conversation history for a workflow
61
62
  *
62
63
  * @param workflowId - The workflow ID
63
64
  */
64
- clearHistory(endpointConfig: EndpointConfig | null, workflowId: string): Promise<void>;
65
+ clearHistory(endpointConfig: EndpointConfig | null, workflowId: string, authProvider?: AuthProvider): Promise<void>;
65
66
  }
66
67
  /**
67
68
  * Pre-instantiated ChatService singleton
@@ -6,7 +6,8 @@
6
6
  *
7
7
  * @module services/chatService
8
8
  */
9
- import { buildEndpointUrl, getEndpointHeaders } from '../config/endpoints.js';
9
+ import { buildEndpointUrl } from '../config/endpoints.js';
10
+ import { authenticatedFetch } from '../utils/fetchWithAuth.js';
10
11
  import { logger } from '../utils/logger.js';
11
12
  /**
12
13
  * Chat Service class
@@ -50,14 +51,11 @@ export class ChatService {
50
51
  * @param options - Fetch options
51
52
  * @returns The parsed JSON response
52
53
  */
53
- async request(config, url, options = {}) {
54
- const headers = getEndpointHeaders(config, 'chat');
55
- const response = await fetch(url, {
56
- ...options,
57
- headers: {
58
- ...headers,
59
- ...options.headers
60
- }
54
+ async request(config, url, options = {}, authProvider) {
55
+ const response = await authenticatedFetch(url, options, {
56
+ config,
57
+ endpointKey: 'chat',
58
+ authProvider
61
59
  });
62
60
  if (!response.ok) {
63
61
  const errorData = await response.json().catch(() => ({}));
@@ -83,7 +81,7 @@ export class ChatService {
83
81
  * @param request - The chat request payload
84
82
  * @returns The chat response from the LLM
85
83
  */
86
- async sendMessage(endpointConfig, workflowId, request) {
84
+ async sendMessage(endpointConfig, workflowId, request, authProvider) {
87
85
  const config = this.getConfig(endpointConfig);
88
86
  const url = buildEndpointUrl(config, config.endpoints.chat.sendMessage, {
89
87
  id: workflowId
@@ -92,7 +90,7 @@ export class ChatService {
92
90
  return this.request(config, url, {
93
91
  method: 'POST',
94
92
  body: JSON.stringify(request)
95
- });
93
+ }, authProvider);
96
94
  }
97
95
  /**
98
96
  * Get conversation history for a workflow
@@ -100,29 +98,26 @@ export class ChatService {
100
98
  * @param workflowId - The workflow ID
101
99
  * @returns Array of chat history messages
102
100
  */
103
- async getHistory(endpointConfig, workflowId) {
101
+ async getHistory(endpointConfig, workflowId, authProvider) {
104
102
  const config = this.getConfig(endpointConfig);
105
103
  const url = buildEndpointUrl(config, config.endpoints.chat.getHistory, {
106
104
  id: workflowId
107
105
  });
108
106
  logger.debug('[ChatService] Getting history from', url);
109
- return this.request(config, url);
107
+ return this.request(config, url, {}, authProvider);
110
108
  }
111
109
  /**
112
110
  * Clear conversation history for a workflow
113
111
  *
114
112
  * @param workflowId - The workflow ID
115
113
  */
116
- async clearHistory(endpointConfig, workflowId) {
114
+ async clearHistory(endpointConfig, workflowId, authProvider) {
117
115
  const config = this.getConfig(endpointConfig);
118
116
  const url = buildEndpointUrl(config, config.endpoints.chat.clearHistory, {
119
117
  id: workflowId
120
118
  });
121
119
  logger.debug('[ChatService] Clearing history at', url);
122
- await fetch(url, {
123
- method: 'DELETE',
124
- headers: getEndpointHeaders(config, 'chat')
125
- });
120
+ await authenticatedFetch(url, { method: 'DELETE' }, { config, endpointKey: 'chat', authProvider });
126
121
  }
127
122
  }
128
123
  /**
@@ -5,7 +5,7 @@
5
5
  *
6
6
  * @module services/dynamicSchemaService
7
7
  */
8
- import type { ConfigSchema, DynamicSchemaEndpoint, ExternalEditLink, ConfigEditOptions, WorkflowNode } from '../types/index.js';
8
+ import type { ConfigSchema, DynamicSchemaEndpoint, ExternalEditLink, ConfigEditOptions, UISchemaElement, WorkflowNode } from '../types/index.js';
9
9
  import type { EndpointConfig } from '../config/endpoints.js';
10
10
  /**
11
11
  * Result of a dynamic schema fetch operation
@@ -15,11 +15,33 @@ export interface DynamicSchemaResult {
15
15
  success: boolean;
16
16
  /** The fetched config schema (if successful) */
17
17
  schema?: ConfigSchema;
18
+ /**
19
+ * The fetched uiSchema, when the endpoint returns one alongside the schema.
20
+ * Lets a server-hydrated response carry its own field grouping/layout so the
21
+ * form isn't stuck with the node's static-metadata uiSchema (which only
22
+ * references the static schema's properties).
23
+ */
24
+ uiSchema?: UISchemaElement;
18
25
  /** Error message (if failed) */
19
26
  error?: string;
20
27
  /** Whether the schema was loaded from cache */
21
28
  fromCache?: boolean;
22
29
  }
30
+ /**
31
+ * Resolves the fetch key for a node's dynamic-schema endpoint: the endpoint URL
32
+ * with all template variables substituted from the node context.
33
+ *
34
+ * The key changes whenever a config value the endpoint's `parameterMapping`
35
+ * references changes (e.g. a trigger node's `event_type`). Callers watch it to
36
+ * refetch the schema when the inputs that shape it change, keeping the rendered
37
+ * form in step with the current configuration.
38
+ *
39
+ * @param endpoint - The dynamic schema endpoint configuration
40
+ * @param node - The workflow node instance
41
+ * @param workflowId - Optional workflow ID for context
42
+ * @returns The resolved endpoint URL, used as a reactive refetch key
43
+ */
44
+ export declare function resolveDynamicSchemaKey(endpoint: DynamicSchemaEndpoint, node: WorkflowNode, workflowId?: string): string;
23
45
  /**
24
46
  * Fetches a dynamic configuration schema from a REST endpoint.
25
47
  *
@@ -33,7 +55,7 @@ export interface DynamicSchemaResult {
33
55
  * const endpoint: DynamicSchemaEndpoint = {
34
56
  * url: "/api/nodes/{nodeTypeId}/schema",
35
57
  * method: "GET",
36
- * parameterMapping: { nodeTypeId: "metadata.id" }
58
+ * parameterMapping: { nodeTypeId: "metadata.node_type_id" }
37
59
  * };
38
60
  *
39
61
  * const result = await fetchDynamicSchema(endpoint, node);
@@ -56,7 +78,7 @@ export declare function fetchDynamicSchema(endpointConfig: EndpointConfig | null
56
78
  * ```typescript
57
79
  * const link: ExternalEditLink = {
58
80
  * url: "https://admin.example.com/nodes/{nodeTypeId}/edit/{instanceId}",
59
- * parameterMapping: { nodeTypeId: "metadata.id", instanceId: "id" }
81
+ * parameterMapping: { nodeTypeId: "metadata.node_type_id", instanceId: "id" }
60
82
  * };
61
83
  *
62
84
  * const url = resolveExternalEditUrl(link, node, workflowId);
@@ -82,10 +104,15 @@ export declare function clearSchemaCache(pattern?: string): void;
82
104
  /**
83
105
  * Invalidates a specific schema cache entry for a node.
84
106
  *
107
+ * The workflow ID must match the value passed when the schema was fetched:
108
+ * endpoints whose URL references `{workflowId}` resolve to a different cache key
109
+ * without it, so omitting it here would miss the entry the fetch created.
110
+ *
85
111
  * @param node - The workflow node to invalidate cache for
86
112
  * @param endpoint - The dynamic schema endpoint configuration
113
+ * @param workflowId - Optional workflow ID, matching the fetch context
87
114
  */
88
- export declare function invalidateSchemaCache(node: WorkflowNode, endpoint: DynamicSchemaEndpoint): void;
115
+ export declare function invalidateSchemaCache(node: WorkflowNode, endpoint: DynamicSchemaEndpoint, workflowId?: string): void;
89
116
  /**
90
117
  * Checks if a node has config edit options configured.
91
118
  *
@@ -15,16 +15,16 @@ const schemaCache = new Map();
15
15
  const DEFAULT_CACHE_TTL = DEFAULT_CACHE_TTL_MS;
16
16
  /**
17
17
  * Resolves a template variable path from the node context.
18
- * Supports dot-notation paths like "metadata.id", "config.apiKey", "id"
18
+ * Supports dot-notation paths like "metadata.node_type_id", "config.apiKey", "id"
19
19
  *
20
20
  * @param context - The node context containing all available data
21
- * @param path - Dot-notation path to resolve (e.g., "metadata.id")
21
+ * @param path - Dot-notation path to resolve (e.g., "metadata.node_type_id")
22
22
  * @returns The resolved value as a string, or undefined if not found
23
23
  *
24
24
  * @example
25
25
  * ```typescript
26
- * const context = { id: "node-1", metadata: { id: "llm-node" } };
27
- * resolveVariablePath(context, "metadata.id"); // Returns "llm-node"
26
+ * const context = { id: "node-1", metadata: { node_type_id: "llm-node" } };
27
+ * resolveVariablePath(context, "metadata.node_type_id"); // Returns "llm-node"
28
28
  * resolveVariablePath(context, "id"); // Returns "node-1"
29
29
  * ```
30
30
  */
@@ -60,8 +60,8 @@ function resolveVariablePath(context, path) {
60
60
  * @example
61
61
  * ```typescript
62
62
  * const url = "/api/nodes/{nodeTypeId}/schema?instance={instanceId}";
63
- * const mapping = { nodeTypeId: "metadata.id", instanceId: "id" };
64
- * const context = { id: "node-1", metadata: { id: "llm-node" } };
63
+ * const mapping = { nodeTypeId: "metadata.node_type_id", instanceId: "id" };
64
+ * const context = { id: "node-1", metadata: { node_type_id: "llm-node" } };
65
65
  * resolveTemplate(url, mapping, context);
66
66
  * // Returns "/api/nodes/llm-node/schema?instance=node-1"
67
67
  * ```
@@ -104,6 +104,44 @@ function generateCacheKey(endpoint, context) {
104
104
  const url = resolveTemplate(endpoint.url, endpoint.parameterMapping, context);
105
105
  return `schema:${url}`;
106
106
  }
107
+ /**
108
+ * Builds the template-resolution context for a node.
109
+ *
110
+ * Shared by every function that resolves a dynamic-schema URL, external-edit
111
+ * URL, or cache key, so they all read identical values — and therefore compute
112
+ * matching keys — from a single place.
113
+ *
114
+ * @param node - The workflow node instance
115
+ * @param workflowId - Optional workflow ID for context
116
+ * @returns The node context used for template resolution
117
+ */
118
+ function buildNodeContext(node, workflowId) {
119
+ return {
120
+ id: node.id,
121
+ type: node.type,
122
+ metadata: node.data.metadata,
123
+ config: node.data.config,
124
+ extensions: node.data.extensions,
125
+ workflowId
126
+ };
127
+ }
128
+ /**
129
+ * Resolves the fetch key for a node's dynamic-schema endpoint: the endpoint URL
130
+ * with all template variables substituted from the node context.
131
+ *
132
+ * The key changes whenever a config value the endpoint's `parameterMapping`
133
+ * references changes (e.g. a trigger node's `event_type`). Callers watch it to
134
+ * refetch the schema when the inputs that shape it change, keeping the rendered
135
+ * form in step with the current configuration.
136
+ *
137
+ * @param endpoint - The dynamic schema endpoint configuration
138
+ * @param node - The workflow node instance
139
+ * @param workflowId - Optional workflow ID for context
140
+ * @returns The resolved endpoint URL, used as a reactive refetch key
141
+ */
142
+ export function resolveDynamicSchemaKey(endpoint, node, workflowId) {
143
+ return resolveTemplate(endpoint.url, endpoint.parameterMapping, buildNodeContext(node, workflowId));
144
+ }
107
145
  /**
108
146
  * Checks if a cached schema is still valid (not expired).
109
147
  *
@@ -127,7 +165,7 @@ function isCacheValid(entry, ttl = DEFAULT_CACHE_TTL) {
127
165
  * const endpoint: DynamicSchemaEndpoint = {
128
166
  * url: "/api/nodes/{nodeTypeId}/schema",
129
167
  * method: "GET",
130
- * parameterMapping: { nodeTypeId: "metadata.id" }
168
+ * parameterMapping: { nodeTypeId: "metadata.node_type_id" }
131
169
  * };
132
170
  *
133
171
  * const result = await fetchDynamicSchema(endpoint, node);
@@ -138,14 +176,7 @@ function isCacheValid(entry, ttl = DEFAULT_CACHE_TTL) {
138
176
  */
139
177
  export async function fetchDynamicSchema(endpointConfig, endpoint, node, workflowId) {
140
178
  // Build the context from the node
141
- const context = {
142
- id: node.id,
143
- type: node.type,
144
- metadata: node.data.metadata,
145
- config: node.data.config,
146
- extensions: node.data.extensions,
147
- workflowId
148
- };
179
+ const context = buildNodeContext(node, workflowId);
149
180
  // Generate cache key
150
181
  const cacheKey = generateCacheKey(endpoint, context);
151
182
  // Check cache first (if caching is enabled)
@@ -155,6 +186,7 @@ export async function fetchDynamicSchema(endpointConfig, endpoint, node, workflo
155
186
  return {
156
187
  success: true,
157
188
  schema: cached.schema,
189
+ uiSchema: cached.uiSchema,
158
190
  fromCache: true
159
191
  };
160
192
  }
@@ -232,10 +264,15 @@ export async function fetchDynamicSchema(endpointConfig, endpoint, node, workflo
232
264
  error: 'Invalid schema format received from endpoint'
233
265
  };
234
266
  }
267
+ // A companion uiSchema may ride alongside the schema (server-hydrated
268
+ // forms). Look for it next to wherever the schema was found — sibling of
269
+ // the envelope, or nested in the same `data`/`schema` wrapper.
270
+ const uiSchema = (data.uiSchema ?? data.data?.uiSchema ?? data.schema?.uiSchema);
235
271
  // Cache the schema (if caching is enabled)
236
272
  if (endpoint.cacheSchema !== false) {
237
273
  schemaCache.set(cacheKey, {
238
274
  schema,
275
+ uiSchema,
239
276
  cachedAt: Date.now(),
240
277
  cacheKey
241
278
  });
@@ -243,6 +280,7 @@ export async function fetchDynamicSchema(endpointConfig, endpoint, node, workflo
243
280
  return {
244
281
  success: true,
245
282
  schema,
283
+ uiSchema,
246
284
  fromCache: false
247
285
  };
248
286
  }
@@ -279,7 +317,7 @@ export async function fetchDynamicSchema(endpointConfig, endpoint, node, workflo
279
317
  * ```typescript
280
318
  * const link: ExternalEditLink = {
281
319
  * url: "https://admin.example.com/nodes/{nodeTypeId}/edit/{instanceId}",
282
- * parameterMapping: { nodeTypeId: "metadata.id", instanceId: "id" }
320
+ * parameterMapping: { nodeTypeId: "metadata.node_type_id", instanceId: "id" }
283
321
  * };
284
322
  *
285
323
  * const url = resolveExternalEditUrl(link, node, workflowId);
@@ -288,14 +326,7 @@ export async function fetchDynamicSchema(endpointConfig, endpoint, node, workflo
288
326
  */
289
327
  export function resolveExternalEditUrl(link, node, workflowId, callbackUrl) {
290
328
  // Build the context from the node
291
- const context = {
292
- id: node.id,
293
- type: node.type,
294
- metadata: node.data.metadata,
295
- config: node.data.config,
296
- extensions: node.data.extensions,
297
- workflowId
298
- };
329
+ const context = buildNodeContext(node, workflowId);
299
330
  // Resolve the URL with template variables
300
331
  let url = resolveTemplate(link.url, link.parameterMapping, context);
301
332
  // Append callback URL if configured
@@ -367,18 +398,16 @@ export function clearSchemaCache(pattern) {
367
398
  /**
368
399
  * Invalidates a specific schema cache entry for a node.
369
400
  *
401
+ * The workflow ID must match the value passed when the schema was fetched:
402
+ * endpoints whose URL references `{workflowId}` resolve to a different cache key
403
+ * without it, so omitting it here would miss the entry the fetch created.
404
+ *
370
405
  * @param node - The workflow node to invalidate cache for
371
406
  * @param endpoint - The dynamic schema endpoint configuration
407
+ * @param workflowId - Optional workflow ID, matching the fetch context
372
408
  */
373
- export function invalidateSchemaCache(node, endpoint) {
374
- const context = {
375
- id: node.id,
376
- type: node.type,
377
- metadata: node.data.metadata,
378
- config: node.data.config,
379
- extensions: node.data.extensions
380
- };
381
- const cacheKey = generateCacheKey(endpoint, context);
409
+ export function invalidateSchemaCache(node, endpoint, workflowId) {
410
+ const cacheKey = generateCacheKey(endpoint, buildNodeContext(node, workflowId));
382
411
  schemaCache.delete(cacheKey);
383
412
  }
384
413
  /**
@@ -49,6 +49,13 @@ export interface PushOptions {
49
49
  * a complete copy of the workflow state. This trades memory for simplicity
50
50
  * and reliability.
51
51
  *
52
+ * Snapshot model: the undo stack holds *committed* states, and its **top is the
53
+ * current live state**. `initialize()` seeds it with the starting state, and each
54
+ * mutation pushes the state *after* the change. One `undo()` moves the top back by
55
+ * exactly one committed change, and `redo()` restores the state that was undone.
56
+ * (Callers must push the post-change state — pushing pre-change snapshots makes a
57
+ * single undo skip a step once there are ≥2 sequential edits; see issue #39.)
58
+ *
52
59
  * @example
53
60
  * ```typescript
54
61
  * const historyService = new HistoryService();
@@ -56,7 +63,7 @@ export interface PushOptions {
56
63
  * // Initialize with current workflow
57
64
  * historyService.initialize(workflow);
58
65
  *
59
- * // Push state before making changes
66
+ * // Push state AFTER making changes (the new committed state)
60
67
  * historyService.push(workflow, { description: "Add node" });
61
68
  *
62
69
  * // Undo/Redo
@@ -95,12 +102,13 @@ export declare class HistoryService {
95
102
  */
96
103
  initialize(workflow: Workflow): void;
97
104
  /**
98
- * Push the current state to history before making changes
105
+ * Push a new committed state to history
99
106
  *
100
- * Call this BEFORE modifying the workflow to capture the "before" state.
107
+ * Call this AFTER modifying the workflow, with the resulting ("after") state:
108
+ * the stack top is the current live state, so one undo == one committed change.
101
109
  * The redo stack is cleared when new changes are pushed.
102
110
  *
103
- * @param workflow - The current workflow state (before changes)
111
+ * @param workflow - The workflow state after the change
104
112
  * @param options - Options for this history entry
105
113
  */
106
114
  push(workflow: Workflow, options?: PushOptions): void;
@@ -124,18 +132,30 @@ export declare class HistoryService {
124
132
  * Start a transaction for grouping multiple changes
125
133
  *
126
134
  * All changes made during a transaction are combined into a single undo entry.
127
- * Useful for operations like "delete node" which also removes connected edges.
135
+ * Useful for operations like "delete node" which also removes connected edges,
136
+ * or coalescing a burst of live config edits into one step. While open, `push()`
137
+ * is suppressed; `commitTransaction()` records a single post-change entry.
128
138
  *
129
- * @param workflow - The current workflow state (before changes)
139
+ * @param workflow - The current workflow state at transaction start. Retained so
140
+ * {@link cancelTransaction} can restore it; the committed entry is the *final*
141
+ * state passed to {@link commitTransaction}, not this snapshot.
130
142
  * @param description - Description for the combined change
131
143
  */
132
144
  startTransaction(workflow: Workflow, description?: string): void;
133
145
  /**
134
146
  * Commit the current transaction
135
147
  *
136
- * Pushes the state captured at transaction start to the history stack.
148
+ * Records the transaction's *post-change* state as a single history entry, so
149
+ * one undo reverts the whole grouped operation and redo restores its result.
150
+ *
151
+ * The final state is required: the transaction's owner (the store) holds the
152
+ * live workflow and must supply it. There is deliberately no "commit whatever
153
+ * you captured at start" fallback — that would silently record a pre-change
154
+ * snapshot and reintroduce the off-by-one this model exists to prevent (#39).
155
+ *
156
+ * @param finalWorkflow - The workflow state after the grouped change.
137
157
  */
138
- commitTransaction(): void;
158
+ commitTransaction(finalWorkflow: Workflow): void;
139
159
  /**
140
160
  * Cancel the current transaction without committing
141
161
  *
@@ -144,6 +164,8 @@ export declare class HistoryService {
144
164
  * can restore the store to its pre-transaction state.
145
165
  */
146
166
  cancelTransaction(): Workflow | null;
167
+ /** Reset the in-progress transaction bookkeeping. */
168
+ private clearTransaction;
147
169
  /**
148
170
  * Clear all history
149
171
  *