@flowdrop/flowdrop 1.15.0 → 2.0.0-beta.10

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 (323) hide show
  1. package/CHANGELOG.md +648 -0
  2. package/MIGRATION-2.0.md +642 -0
  3. package/README.md +28 -28
  4. package/dist/adapters/WorkflowAdapter.d.ts +1 -1
  5. package/dist/adapters/WorkflowAdapter.js +18 -13
  6. package/dist/adapters/agentspec/AgentSpecAdapter.js +10 -10
  7. package/dist/adapters/agentspec/defaultNodeTypes.js +9 -9
  8. package/dist/api/enhanced-client.js +6 -11
  9. package/dist/chat/batchFeedback.d.ts +39 -0
  10. package/dist/chat/batchFeedback.js +51 -0
  11. package/dist/commands/executor.js +66 -27
  12. package/dist/commands/storeIntegration.svelte.d.ts +4 -1
  13. package/dist/commands/storeIntegration.svelte.js +36 -21
  14. package/dist/commands/types.d.ts +2 -0
  15. package/dist/commands/types.js +5 -5
  16. package/dist/components/App.svelte +696 -565
  17. package/dist/components/App.svelte.d.ts +63 -16
  18. package/dist/components/Button.stories.svelte +65 -0
  19. package/dist/components/Button.stories.svelte.d.ts +19 -0
  20. package/dist/components/Button.svelte +62 -0
  21. package/dist/components/Button.svelte.d.ts +24 -0
  22. package/dist/components/CanvasIconButton.svelte +76 -0
  23. package/dist/components/CanvasIconButton.svelte.d.ts +18 -0
  24. package/dist/components/ConfigForm.svelte +181 -552
  25. package/dist/components/ConfigForm.svelte.d.ts +24 -7
  26. package/dist/components/ConfigModal.svelte +16 -3
  27. package/dist/components/ConfigPanel.svelte +234 -15
  28. package/dist/components/ConfigPanel.svelte.d.ts +6 -0
  29. package/dist/components/ConnectionLine.svelte +4 -2
  30. package/dist/components/EditorStatusBar.stories.svelte +44 -0
  31. package/dist/components/EditorStatusBar.stories.svelte.d.ts +27 -0
  32. package/dist/components/EditorStatusBar.svelte +99 -0
  33. package/dist/components/EditorStatusBar.svelte.d.ts +15 -0
  34. package/dist/components/IconButton.svelte +80 -0
  35. package/dist/components/IconButton.svelte.d.ts +30 -0
  36. package/dist/components/Input.svelte +74 -0
  37. package/dist/components/Input.svelte.d.ts +17 -0
  38. package/dist/components/LogoWordmark.svelte +113 -0
  39. package/dist/components/LogoWordmark.svelte.d.ts +26 -0
  40. package/dist/components/Navbar.svelte +78 -64
  41. package/dist/components/Navbar.svelte.d.ts +3 -0
  42. package/dist/components/NodeSidebar.svelte +48 -171
  43. package/dist/components/NodeStatusOverlay.svelte +94 -6
  44. package/dist/components/NodeSwapPicker.svelte +22 -38
  45. package/dist/components/PipelineStatus.svelte +22 -68
  46. package/dist/components/PipelineStatus.svelte.d.ts +3 -0
  47. package/dist/components/PortCoordinateTracker.svelte +5 -6
  48. package/dist/components/PortMappingRow.svelte +0 -2
  49. package/dist/components/SchemaForm.stories.svelte +1 -3
  50. package/dist/components/SchemaForm.svelte +22 -39
  51. package/dist/components/SchemaForm.svelte.d.ts +0 -8
  52. package/dist/components/Select.svelte +53 -0
  53. package/dist/components/Select.svelte.d.ts +15 -0
  54. package/dist/components/SettingsModal.svelte +8 -8
  55. package/dist/components/SettingsPanel.svelte +44 -10
  56. package/dist/components/SwapMappingEditor.svelte +67 -49
  57. package/dist/components/SwapMappingEditor.svelte.d.ts +0 -2
  58. package/dist/components/Textarea.svelte +39 -0
  59. package/dist/components/Textarea.svelte.d.ts +12 -0
  60. package/dist/components/ThemeToggle.svelte +15 -94
  61. package/dist/components/UniversalNode.svelte +45 -11
  62. package/dist/components/UniversalNode.svelte.d.ts +1 -1
  63. package/dist/components/WorkflowEditor.svelte +183 -162
  64. package/dist/components/WorkflowEditor.svelte.d.ts +39 -10
  65. package/dist/components/chat/AIChatPanel.svelte +99 -90
  66. package/dist/components/chat/AIChatPanel.svelte.d.ts +0 -4
  67. package/dist/components/chat/CommandPreview.svelte +2 -1
  68. package/dist/components/console/CommandConsole.svelte +7 -5
  69. package/dist/components/console/ConsoleAutocomplete.svelte +11 -12
  70. package/dist/components/console/ConsoleAutocomplete.svelte.d.ts +6 -0
  71. package/dist/components/console/ConsoleInput.svelte +18 -9
  72. package/dist/components/console/ConsoleOutput.svelte +4 -3
  73. package/dist/components/form/FormArray.svelte +42 -182
  74. package/dist/components/form/FormArray.svelte.d.ts +2 -1
  75. package/dist/components/form/FormAutocomplete.svelte +26 -21
  76. package/dist/components/form/FormCheckboxGroup.svelte +1 -5
  77. package/dist/components/form/FormCodeEditor.svelte +9 -7
  78. package/dist/components/form/FormField.svelte +22 -44
  79. package/dist/components/form/FormFieldLight.svelte +56 -50
  80. package/dist/components/form/FormFieldLight.svelte.d.ts +12 -0
  81. package/dist/components/form/FormFieldset.svelte +45 -11
  82. package/dist/components/form/FormMarkdownEditor.svelte +17 -9
  83. package/dist/components/form/FormNumberField.svelte +4 -36
  84. package/dist/components/form/FormPorts.svelte +262 -0
  85. package/dist/components/form/FormPorts.svelte.d.ts +13 -0
  86. package/dist/components/form/FormRangeField.svelte +62 -30
  87. package/dist/components/form/FormSelect.svelte +13 -75
  88. package/dist/components/form/FormTemplateEditor.svelte +17 -7
  89. package/dist/components/form/FormTextField.svelte +3 -35
  90. package/dist/components/form/FormTextarea.svelte +4 -39
  91. package/dist/components/form/FormToggle.svelte +5 -16
  92. package/dist/components/form/FormToggle.svelte.d.ts +4 -2
  93. package/dist/components/form/FormUISchemaRenderer.svelte +3 -1
  94. package/dist/components/form/resolveFieldType.d.ts +24 -0
  95. package/dist/components/form/resolveFieldType.js +55 -0
  96. package/dist/components/form/templateAutocomplete.js +1 -5
  97. package/dist/components/form/types.d.ts +1 -14
  98. package/dist/components/icons/CloseIcon.svelte +6 -0
  99. package/dist/components/icons/CloseIcon.svelte.d.ts +26 -0
  100. package/dist/components/icons/CommandLineIcon.svelte +15 -0
  101. package/dist/components/icons/CommandLineIcon.svelte.d.ts +26 -0
  102. package/dist/components/icons/MenuIcon.svelte +4 -0
  103. package/dist/components/icons/MenuIcon.svelte.d.ts +26 -0
  104. package/dist/components/icons/MenuOpenIcon.svelte +6 -0
  105. package/dist/components/icons/MenuOpenIcon.svelte.d.ts +26 -0
  106. package/dist/components/interrupt/ChoicePrompt.svelte +0 -10
  107. package/dist/components/interrupt/ConfirmationPrompt.svelte +0 -5
  108. package/dist/components/interrupt/FormPrompt.svelte +3 -2
  109. package/dist/components/interrupt/InterruptBubble.svelte +25 -27
  110. package/dist/components/interrupt/ReviewPrompt.svelte +10 -23
  111. package/dist/components/interrupt/TextInputPrompt.svelte +2 -7
  112. package/dist/components/layouts/MainLayout.svelte +24 -18
  113. package/dist/components/layouts/MainLayout.svelte.d.ts +4 -0
  114. package/dist/components/nodes/AtomNode.svelte +70 -72
  115. package/dist/components/nodes/AtomNode.svelte.d.ts +1 -1
  116. package/dist/components/nodes/GatewayNode.svelte +134 -172
  117. package/dist/components/nodes/GatewayNode.svelte.d.ts +1 -1
  118. package/dist/components/nodes/IdeaNode.svelte +79 -98
  119. package/dist/components/nodes/IdeaNode.svelte.d.ts +8 -4
  120. package/dist/components/nodes/NodeConfigButton.svelte +86 -0
  121. package/dist/components/nodes/NodeConfigButton.svelte.d.ts +15 -0
  122. package/dist/components/nodes/NotesNode.svelte +76 -85
  123. package/dist/components/nodes/NotesNode.svelte.d.ts +8 -4
  124. package/dist/components/nodes/SimpleNode.svelte +68 -137
  125. package/dist/components/nodes/SimpleNode.svelte.d.ts +4 -4
  126. package/dist/components/nodes/SquareNode.svelte +122 -169
  127. package/dist/components/nodes/SquareNode.svelte.d.ts +4 -4
  128. package/dist/components/nodes/TerminalNode.svelte +70 -127
  129. package/dist/components/nodes/TerminalNode.svelte.d.ts +4 -4
  130. package/dist/components/nodes/ToolNode.svelte +99 -104
  131. package/dist/components/nodes/ToolNode.svelte.d.ts +6 -6
  132. package/dist/components/nodes/WorkflowNode.svelte +145 -195
  133. package/dist/components/nodes/WorkflowNode.svelte.d.ts +1 -1
  134. package/dist/components/playground/ChatInput.svelte +11 -15
  135. package/dist/components/playground/ChatPanel.svelte +6 -49
  136. package/dist/components/playground/ChatPanel.svelte.d.ts +0 -14
  137. package/dist/components/playground/ControlPanel.svelte +134 -123
  138. package/dist/components/playground/ControlPanel.svelte.d.ts +3 -0
  139. package/dist/components/playground/ExecutionLogs.svelte +11 -9
  140. package/dist/components/playground/InputCollector.svelte +22 -57
  141. package/dist/components/playground/MessageStream.svelte +17 -23
  142. package/dist/components/playground/PipelineKanbanView.svelte +69 -8
  143. package/dist/components/playground/PipelineKanbanView.svelte.d.ts +2 -0
  144. package/dist/components/playground/PipelinePanel.svelte +31 -8
  145. package/dist/components/playground/PipelinePanel.svelte.d.ts +2 -0
  146. package/dist/components/playground/PipelineTableView.svelte +188 -44
  147. package/dist/components/playground/PipelineTableView.svelte.d.ts +2 -0
  148. package/dist/components/playground/Playground.svelte +154 -105
  149. package/dist/components/playground/Playground.svelte.d.ts +5 -0
  150. package/dist/components/playground/PlaygroundApp.svelte +12 -2
  151. package/dist/components/playground/PlaygroundApp.svelte.d.ts +6 -0
  152. package/dist/components/playground/PlaygroundModal.svelte +18 -3
  153. package/dist/components/playground/PlaygroundModal.svelte.d.ts +6 -0
  154. package/dist/components/playground/PlaygroundStudio.svelte +40 -37
  155. package/dist/components/playground/PlaygroundStudio.svelte.d.ts +6 -0
  156. package/dist/components/playground/SessionManager.svelte +9 -12
  157. package/dist/components/playground/pipelineViewUtils.svelte.d.ts +30 -1
  158. package/dist/components/playground/pipelineViewUtils.svelte.js +40 -3
  159. package/dist/components/surfaces/SurfaceOverlay.svelte +153 -0
  160. package/dist/components/surfaces/SurfaceOverlay.svelte.d.ts +14 -0
  161. package/dist/components/surfaces/TabbedSurface.svelte +133 -0
  162. package/dist/components/surfaces/TabbedSurface.svelte.d.ts +27 -0
  163. package/dist/config/endpoints.d.ts +23 -7
  164. package/dist/config/endpoints.js +30 -10
  165. package/dist/core/index.d.ts +6 -7
  166. package/dist/core/index.js +8 -12
  167. package/dist/display/index.d.ts +6 -3
  168. package/dist/display/index.js +7 -5
  169. package/dist/editor/index.d.ts +20 -21
  170. package/dist/editor/index.js +26 -36
  171. package/dist/form/code.d.ts +25 -15
  172. package/dist/form/code.js +44 -41
  173. package/dist/form/fieldRegistry.d.ts +17 -13
  174. package/dist/form/fieldRegistry.js +32 -12
  175. package/dist/form/full.d.ts +19 -14
  176. package/dist/form/full.js +26 -28
  177. package/dist/form/index.d.ts +3 -4
  178. package/dist/form/index.js +6 -5
  179. package/dist/form/markdown.d.ts +13 -8
  180. package/dist/form/markdown.js +22 -23
  181. package/dist/helpers/proximityConnect.d.ts +3 -2
  182. package/dist/helpers/proximityConnect.js +2 -5
  183. package/dist/helpers/workflowEditorHelper.d.ts +14 -5
  184. package/dist/helpers/workflowEditorHelper.js +32 -30
  185. package/dist/index.d.ts +28 -24
  186. package/dist/index.js +27 -50
  187. package/dist/messages/defaults.d.ts +2 -5
  188. package/dist/messages/defaults.js +3 -6
  189. package/dist/messages/index.d.ts +1 -2
  190. package/dist/messages/index.js +1 -2
  191. package/dist/mocks/app-forms.d.ts +6 -2
  192. package/dist/mocks/app-forms.js +11 -4
  193. package/dist/openapi/v1/openapi.yaml +38 -26
  194. package/dist/playground/index.d.ts +4 -5
  195. package/dist/playground/index.js +4 -32
  196. package/dist/playground/mount.d.ts +34 -5
  197. package/dist/playground/mount.js +58 -24
  198. package/dist/registry/{BaseRegistry.d.ts → BaseRegistry.svelte.d.ts} +22 -1
  199. package/dist/registry/{BaseRegistry.js → BaseRegistry.svelte.js} +37 -1
  200. package/dist/registry/builtinFormats.d.ts +9 -18
  201. package/dist/registry/builtinFormats.js +9 -39
  202. package/dist/registry/builtinNodeTypes.d.ts +53 -0
  203. package/dist/registry/builtinNodeTypes.js +67 -0
  204. package/dist/registry/builtinNodes.d.ts +2 -64
  205. package/dist/registry/builtinNodes.js +7 -103
  206. package/dist/registry/index.d.ts +3 -4
  207. package/dist/registry/index.js +4 -6
  208. package/dist/registry/nodeComponentRegistry.d.ts +184 -16
  209. package/dist/registry/nodeComponentRegistry.js +235 -17
  210. package/dist/registry/workflowFormatRegistry.d.ts +14 -9
  211. package/dist/registry/workflowFormatRegistry.js +24 -8
  212. package/dist/{schema → schemas}/index.d.ts +2 -2
  213. package/dist/{schema → schemas}/index.js +2 -2
  214. package/dist/schemas/v1/workflow.schema.json +19 -17
  215. package/dist/services/agentSpecExecutionService.d.ts +0 -2
  216. package/dist/services/agentSpecExecutionService.js +0 -3
  217. package/dist/services/apiVariableService.d.ts +2 -1
  218. package/dist/services/apiVariableService.js +16 -47
  219. package/dist/services/autoSaveService.d.ts +7 -0
  220. package/dist/services/autoSaveService.js +6 -4
  221. package/dist/services/categoriesApi.js +3 -6
  222. package/dist/services/chatService.d.ts +9 -4
  223. package/dist/services/chatService.js +23 -28
  224. package/dist/services/draftStorage.d.ts +129 -13
  225. package/dist/services/draftStorage.js +185 -37
  226. package/dist/services/dynamicSchemaService.d.ts +33 -5
  227. package/dist/services/dynamicSchemaService.js +67 -55
  228. package/dist/services/globalSave.d.ts +13 -12
  229. package/dist/services/globalSave.js +29 -51
  230. package/dist/services/historyService.d.ts +39 -11
  231. package/dist/services/historyService.js +60 -18
  232. package/dist/services/interruptService.d.ts +15 -9
  233. package/dist/services/interruptService.js +35 -37
  234. package/dist/services/nodeExecutionService.d.ts +18 -3
  235. package/dist/services/nodeExecutionService.js +71 -45
  236. package/dist/services/playgroundService.d.ts +16 -10
  237. package/dist/services/playgroundService.js +42 -43
  238. package/dist/services/portConfigApi.js +3 -6
  239. package/dist/services/settingsService.d.ts +9 -4
  240. package/dist/services/settingsService.js +23 -12
  241. package/dist/services/variableService.d.ts +2 -1
  242. package/dist/services/variableService.js +2 -2
  243. package/dist/services/workflowStorage.js +6 -6
  244. package/dist/skins/drafter.d.ts +30 -0
  245. package/dist/skins/drafter.js +198 -0
  246. package/dist/skins/index.d.ts +2 -1
  247. package/dist/skins/index.js +4 -2
  248. package/dist/stores/apiContext.d.ts +56 -0
  249. package/dist/stores/apiContext.js +80 -0
  250. package/dist/stores/categoriesStore.svelte.d.ts +28 -23
  251. package/dist/stores/categoriesStore.svelte.js +69 -64
  252. package/dist/stores/getInstance.svelte.d.ts +39 -0
  253. package/dist/stores/getInstance.svelte.js +65 -0
  254. package/dist/stores/historyStore.svelte.d.ts +89 -91
  255. package/dist/stores/historyStore.svelte.js +159 -158
  256. package/dist/stores/instanceContainer.svelte.d.ts +111 -0
  257. package/dist/stores/instanceContainer.svelte.js +119 -0
  258. package/dist/stores/interruptStore.svelte.d.ts +112 -82
  259. package/dist/stores/interruptStore.svelte.js +253 -226
  260. package/dist/stores/pipelinePanelStore.svelte.d.ts +27 -3
  261. package/dist/stores/pipelinePanelStore.svelte.js +61 -14
  262. package/dist/stores/playgroundStore.svelte.d.ts +169 -222
  263. package/dist/stores/playgroundStore.svelte.js +513 -580
  264. package/dist/stores/portCoordinateStore.svelte.d.ts +57 -51
  265. package/dist/stores/portCoordinateStore.svelte.js +109 -98
  266. package/dist/stores/settingsStore.svelte.d.ts +17 -1
  267. package/dist/stores/settingsStore.svelte.js +79 -12
  268. package/dist/stores/workflowStore.svelte.d.ts +212 -210
  269. package/dist/stores/workflowStore.svelte.js +527 -502
  270. package/dist/stories/EdgeDecorator.svelte +5 -2
  271. package/dist/stories/NodeDecorator.svelte +5 -3
  272. package/dist/styles/base.css +285 -14
  273. package/dist/styles/tokens.css +60 -2
  274. package/dist/svelte-app.d.ts +78 -11
  275. package/dist/svelte-app.js +210 -141
  276. package/dist/themes/drafter.d.ts +2 -0
  277. package/dist/themes/drafter.js +15 -0
  278. package/dist/themes/index.d.ts +2 -1
  279. package/dist/themes/index.js +8 -2
  280. package/dist/types/auth.d.ts +9 -51
  281. package/dist/types/auth.js +4 -54
  282. package/dist/types/events.d.ts +24 -3
  283. package/dist/types/events.js +2 -1
  284. package/dist/types/index.d.ts +117 -32
  285. package/dist/types/index.js +0 -1
  286. package/dist/types/navbar.d.ts +7 -0
  287. package/dist/types/playground.d.ts +18 -3
  288. package/dist/types/settings.d.ts +30 -1
  289. package/dist/types/settings.js +5 -2
  290. package/dist/types/skin.d.ts +1 -1
  291. package/dist/types/theme.d.ts +16 -2
  292. package/dist/types/uischema.d.ts +5 -0
  293. package/dist/utils/colors.d.ts +74 -21
  294. package/dist/utils/colors.js +92 -68
  295. package/dist/utils/connections.d.ts +9 -15
  296. package/dist/utils/connections.js +33 -88
  297. package/dist/utils/duration.d.ts +13 -0
  298. package/dist/utils/duration.js +45 -0
  299. package/dist/utils/edgeStyling.js +9 -5
  300. package/dist/utils/fetchWithAuth.d.ts +36 -15
  301. package/dist/utils/fetchWithAuth.js +53 -23
  302. package/dist/utils/icons.d.ts +5 -2
  303. package/dist/utils/icons.js +6 -5
  304. package/dist/utils/nodeIds.d.ts +1 -1
  305. package/dist/utils/nodeIds.js +1 -1
  306. package/dist/utils/nodeSwap.d.ts +6 -2
  307. package/dist/utils/nodeSwap.js +62 -129
  308. package/dist/utils/nodeTypes.d.ts +17 -8
  309. package/dist/utils/nodeTypes.js +27 -20
  310. package/dist/utils/performanceUtils.js +7 -0
  311. package/dist/utils/portUtils.d.ts +47 -11
  312. package/dist/utils/portUtils.js +67 -14
  313. package/dist/utils/portal.d.ts +18 -0
  314. package/dist/utils/portal.js +34 -0
  315. package/dist/utils/schemaMerge.d.ts +25 -0
  316. package/dist/utils/schemaMerge.js +61 -0
  317. package/package.json +7 -5
  318. package/dist/messages/deprecation.d.ts +0 -20
  319. package/dist/messages/deprecation.js +0 -33
  320. package/dist/registry/plugin.d.ts +0 -215
  321. package/dist/registry/plugin.js +0 -249
  322. package/dist/services/api.d.ts +0 -129
  323. package/dist/services/api.js +0 -217
@@ -5,7 +5,8 @@
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
+ import type { EndpointConfig } from '../config/endpoints.js';
9
10
  /**
10
11
  * Result of a dynamic schema fetch operation
11
12
  */
@@ -14,11 +15,33 @@ export interface DynamicSchemaResult {
14
15
  success: boolean;
15
16
  /** The fetched config schema (if successful) */
16
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;
17
25
  /** Error message (if failed) */
18
26
  error?: string;
19
27
  /** Whether the schema was loaded from cache */
20
28
  fromCache?: boolean;
21
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;
22
45
  /**
23
46
  * Fetches a dynamic configuration schema from a REST endpoint.
24
47
  *
@@ -32,7 +55,7 @@ export interface DynamicSchemaResult {
32
55
  * const endpoint: DynamicSchemaEndpoint = {
33
56
  * url: "/api/nodes/{nodeTypeId}/schema",
34
57
  * method: "GET",
35
- * parameterMapping: { nodeTypeId: "metadata.id" }
58
+ * parameterMapping: { nodeTypeId: "metadata.node_type_id" }
36
59
  * };
37
60
  *
38
61
  * const result = await fetchDynamicSchema(endpoint, node);
@@ -41,7 +64,7 @@ export interface DynamicSchemaResult {
41
64
  * }
42
65
  * ```
43
66
  */
44
- export declare function fetchDynamicSchema(endpoint: DynamicSchemaEndpoint, node: WorkflowNode, workflowId?: string): Promise<DynamicSchemaResult>;
67
+ export declare function fetchDynamicSchema(endpointConfig: EndpointConfig | null, endpoint: DynamicSchemaEndpoint, node: WorkflowNode, workflowId?: string): Promise<DynamicSchemaResult>;
45
68
  /**
46
69
  * Resolves an external edit link URL with template variables.
47
70
  *
@@ -55,7 +78,7 @@ export declare function fetchDynamicSchema(endpoint: DynamicSchemaEndpoint, node
55
78
  * ```typescript
56
79
  * const link: ExternalEditLink = {
57
80
  * url: "https://admin.example.com/nodes/{nodeTypeId}/edit/{instanceId}",
58
- * parameterMapping: { nodeTypeId: "metadata.id", instanceId: "id" }
81
+ * parameterMapping: { nodeTypeId: "metadata.node_type_id", instanceId: "id" }
59
82
  * };
60
83
  *
61
84
  * const url = resolveExternalEditUrl(link, node, workflowId);
@@ -81,10 +104,15 @@ export declare function clearSchemaCache(pattern?: string): void;
81
104
  /**
82
105
  * Invalidates a specific schema cache entry for a node.
83
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
+ *
84
111
  * @param node - The workflow node to invalidate cache for
85
112
  * @param endpoint - The dynamic schema endpoint configuration
113
+ * @param workflowId - Optional workflow ID, matching the fetch context
86
114
  */
87
- export declare function invalidateSchemaCache(node: WorkflowNode, endpoint: DynamicSchemaEndpoint): void;
115
+ export declare function invalidateSchemaCache(node: WorkflowNode, endpoint: DynamicSchemaEndpoint, workflowId?: string): void;
88
116
  /**
89
117
  * Checks if a node has config edit options configured.
90
118
  *
@@ -5,7 +5,6 @@
5
5
  *
6
6
  * @module services/dynamicSchemaService
7
7
  */
8
- import { getEndpointConfig } from './api.js';
9
8
  import { DEFAULT_CACHE_TTL_MS } from '../config/constants.js';
10
9
  /**
11
10
  * Schema cache with TTL support
@@ -16,16 +15,16 @@ const schemaCache = new Map();
16
15
  const DEFAULT_CACHE_TTL = DEFAULT_CACHE_TTL_MS;
17
16
  /**
18
17
  * Resolves a template variable path from the node context.
19
- * Supports dot-notation paths like "metadata.id", "config.apiKey", "id"
18
+ * Supports dot-notation paths like "metadata.node_type_id", "config.apiKey", "id"
20
19
  *
21
20
  * @param context - The node context containing all available data
22
- * @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")
23
22
  * @returns The resolved value as a string, or undefined if not found
24
23
  *
25
24
  * @example
26
25
  * ```typescript
27
- * const context = { id: "node-1", metadata: { id: "llm-node" } };
28
- * 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"
29
28
  * resolveVariablePath(context, "id"); // Returns "node-1"
30
29
  * ```
31
30
  */
@@ -61,8 +60,8 @@ function resolveVariablePath(context, path) {
61
60
  * @example
62
61
  * ```typescript
63
62
  * const url = "/api/nodes/{nodeTypeId}/schema?instance={instanceId}";
64
- * const mapping = { nodeTypeId: "metadata.id", instanceId: "id" };
65
- * 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" } };
66
65
  * resolveTemplate(url, mapping, context);
67
66
  * // Returns "/api/nodes/llm-node/schema?instance=node-1"
68
67
  * ```
@@ -105,6 +104,44 @@ function generateCacheKey(endpoint, context) {
105
104
  const url = resolveTemplate(endpoint.url, endpoint.parameterMapping, context);
106
105
  return `schema:${url}`;
107
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
+ }
108
145
  /**
109
146
  * Checks if a cached schema is still valid (not expired).
110
147
  *
@@ -128,7 +165,7 @@ function isCacheValid(entry, ttl = DEFAULT_CACHE_TTL) {
128
165
  * const endpoint: DynamicSchemaEndpoint = {
129
166
  * url: "/api/nodes/{nodeTypeId}/schema",
130
167
  * method: "GET",
131
- * parameterMapping: { nodeTypeId: "metadata.id" }
168
+ * parameterMapping: { nodeTypeId: "metadata.node_type_id" }
132
169
  * };
133
170
  *
134
171
  * const result = await fetchDynamicSchema(endpoint, node);
@@ -137,16 +174,9 @@ function isCacheValid(entry, ttl = DEFAULT_CACHE_TTL) {
137
174
  * }
138
175
  * ```
139
176
  */
140
- export async function fetchDynamicSchema(endpoint, node, workflowId) {
177
+ export async function fetchDynamicSchema(endpointConfig, endpoint, node, workflowId) {
141
178
  // Build the context from the node
142
- const context = {
143
- id: node.id,
144
- type: node.type,
145
- metadata: node.data.metadata,
146
- config: node.data.config,
147
- extensions: node.data.extensions,
148
- workflowId
149
- };
179
+ const context = buildNodeContext(node, workflowId);
150
180
  // Generate cache key
151
181
  const cacheKey = generateCacheKey(endpoint, context);
152
182
  // Check cache first (if caching is enabled)
@@ -156,6 +186,7 @@ export async function fetchDynamicSchema(endpoint, node, workflowId) {
156
186
  return {
157
187
  success: true,
158
188
  schema: cached.schema,
189
+ uiSchema: cached.uiSchema,
159
190
  fromCache: true
160
191
  };
161
192
  }
@@ -163,13 +194,10 @@ export async function fetchDynamicSchema(endpoint, node, workflowId) {
163
194
  // Resolve the URL with template variables
164
195
  let url = resolveTemplate(endpoint.url, endpoint.parameterMapping, context);
165
196
  // If URL is relative, try to prepend base URL from endpoint config
166
- if (url.startsWith('/')) {
167
- const currentConfig = getEndpointConfig();
168
- if (currentConfig?.baseUrl) {
169
- // Remove trailing slash from base URL and leading slash from relative URL
170
- const baseUrl = currentConfig.baseUrl.replace(/\/$/, '');
171
- url = `${baseUrl}${url}`;
172
- }
197
+ if (url.startsWith('/') && endpointConfig?.baseUrl) {
198
+ // Remove trailing slash from base URL and leading slash from relative URL
199
+ const baseUrl = endpointConfig.baseUrl.replace(/\/$/, '');
200
+ url = `${baseUrl}${url}`;
173
201
  }
174
202
  // Prepare request options
175
203
  const method = endpoint.method ?? 'GET';
@@ -179,19 +207,6 @@ export async function fetchDynamicSchema(endpoint, node, workflowId) {
179
207
  'Content-Type': 'application/json',
180
208
  ...endpoint.headers
181
209
  };
182
- // Add auth headers from endpoint config if available
183
- const currentConfig = getEndpointConfig();
184
- if (currentConfig?.auth) {
185
- if (currentConfig.auth.type === 'bearer' && currentConfig.auth.token) {
186
- headers['Authorization'] = `Bearer ${currentConfig.auth.token}`;
187
- }
188
- else if (currentConfig.auth.type === 'api_key' && currentConfig.auth.apiKey) {
189
- headers['X-API-Key'] = currentConfig.auth.apiKey;
190
- }
191
- else if (currentConfig.auth.type === 'custom' && currentConfig.auth.headers) {
192
- Object.assign(headers, currentConfig.auth.headers);
193
- }
194
- }
195
210
  // Prepare fetch options
196
211
  const fetchOptions = {
197
212
  method,
@@ -249,10 +264,15 @@ export async function fetchDynamicSchema(endpoint, node, workflowId) {
249
264
  error: 'Invalid schema format received from endpoint'
250
265
  };
251
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);
252
271
  // Cache the schema (if caching is enabled)
253
272
  if (endpoint.cacheSchema !== false) {
254
273
  schemaCache.set(cacheKey, {
255
274
  schema,
275
+ uiSchema,
256
276
  cachedAt: Date.now(),
257
277
  cacheKey
258
278
  });
@@ -260,6 +280,7 @@ export async function fetchDynamicSchema(endpoint, node, workflowId) {
260
280
  return {
261
281
  success: true,
262
282
  schema,
283
+ uiSchema,
263
284
  fromCache: false
264
285
  };
265
286
  }
@@ -296,7 +317,7 @@ export async function fetchDynamicSchema(endpoint, node, workflowId) {
296
317
  * ```typescript
297
318
  * const link: ExternalEditLink = {
298
319
  * url: "https://admin.example.com/nodes/{nodeTypeId}/edit/{instanceId}",
299
- * parameterMapping: { nodeTypeId: "metadata.id", instanceId: "id" }
320
+ * parameterMapping: { nodeTypeId: "metadata.node_type_id", instanceId: "id" }
300
321
  * };
301
322
  *
302
323
  * const url = resolveExternalEditUrl(link, node, workflowId);
@@ -305,14 +326,7 @@ export async function fetchDynamicSchema(endpoint, node, workflowId) {
305
326
  */
306
327
  export function resolveExternalEditUrl(link, node, workflowId, callbackUrl) {
307
328
  // Build the context from the node
308
- const context = {
309
- id: node.id,
310
- type: node.type,
311
- metadata: node.data.metadata,
312
- config: node.data.config,
313
- extensions: node.data.extensions,
314
- workflowId
315
- };
329
+ const context = buildNodeContext(node, workflowId);
316
330
  // Resolve the URL with template variables
317
331
  let url = resolveTemplate(link.url, link.parameterMapping, context);
318
332
  // Append callback URL if configured
@@ -384,18 +398,16 @@ export function clearSchemaCache(pattern) {
384
398
  /**
385
399
  * Invalidates a specific schema cache entry for a node.
386
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
+ *
387
405
  * @param node - The workflow node to invalidate cache for
388
406
  * @param endpoint - The dynamic schema endpoint configuration
407
+ * @param workflowId - Optional workflow ID, matching the fetch context
389
408
  */
390
- export function invalidateSchemaCache(node, endpoint) {
391
- const context = {
392
- id: node.id,
393
- type: node.type,
394
- metadata: node.data.metadata,
395
- config: node.data.config,
396
- extensions: node.data.extensions
397
- };
398
- const cacheKey = generateCacheKey(endpoint, context);
409
+ export function invalidateSchemaCache(node, endpoint, workflowId) {
410
+ const cacheKey = generateCacheKey(endpoint, buildNodeContext(node, workflowId));
399
411
  schemaCache.delete(cacheKey);
400
412
  }
401
413
  /**
@@ -7,24 +7,15 @@
7
7
  * reimplementing the logic, ensuring "blur active element" flushing and metadata
8
8
  * construction happen in exactly one place.
9
9
  */
10
+ import { type FlowDropInstance } from '../stores/instanceContainer.svelte.js';
10
11
  import type { Workflow } from '../types/index.js';
11
12
  import type { FlowDropEventHandlers, FlowDropFeatures } from '../types/events.js';
12
- /**
13
- * Minimal interface for the enhanced API client used when an authProvider is present.
14
- * Matches the surface of EnhancedFlowDropApiClient that save needs.
15
- */
16
- export interface SaveApiClient {
17
- saveWorkflow(workflow: Workflow): Promise<Workflow>;
18
- updateWorkflow(id: string, workflow: Workflow): Promise<Workflow>;
19
- }
20
13
  /**
21
14
  * Options accepted by globalSaveWorkflow().
22
15
  * All fields are optional — omitting them falls back to the basic behaviour
23
- * (no event handlers, always show toasts, legacy workflowApi).
16
+ * (no event handlers, always show toasts).
24
17
  */
25
18
  export interface GlobalSaveOptions {
26
- /** Enhanced API client with authProvider support. Falls back to legacy workflowApi when absent. */
27
- apiClient?: SaveApiClient | null;
28
19
  /** Event handler hooks (onBeforeSave, onAfterSave, onSaveError, onApiError). */
29
20
  eventHandlers?: FlowDropEventHandlers;
30
21
  /** Feature flags (showToasts). Defaults to DEFAULT_FEATURES. */
@@ -41,6 +32,11 @@ export interface GlobalSaveOptions {
41
32
  * Use this to update draft storage keys or other ID-dependent state.
42
33
  */
43
34
  onSaved?: (savedWorkflow: Workflow) => void;
35
+ /**
36
+ * The FlowDrop instance whose workflow should be saved.
37
+ * Defaults to the page-default instance when omitted.
38
+ */
39
+ instance?: FlowDropInstance;
44
40
  }
45
41
  /**
46
42
  * Options accepted by globalExportWorkflow().
@@ -48,6 +44,11 @@ export interface GlobalSaveOptions {
48
44
  export interface GlobalExportOptions {
49
45
  /** Feature flags (showToasts). Defaults to DEFAULT_FEATURES. */
50
46
  features?: Partial<FlowDropFeatures>;
47
+ /**
48
+ * The FlowDrop instance whose workflow should be exported.
49
+ * Defaults to the page-default instance when omitted.
50
+ */
51
+ instance?: FlowDropInstance;
51
52
  }
52
53
  /**
53
54
  * Save the current workflow to the backend.
@@ -59,7 +60,7 @@ export interface GlobalExportOptions {
59
60
  * 1. Flush pending form changes (blur active element + tick)
60
61
  * 2. Optionally call onBeforeSave — return false cancels the save
61
62
  * 3. Build the canonical Workflow object (preserving metadata, format, etc.)
62
- * 4. Persist via enhanced apiClient or legacy workflowApi
63
+ * 4. Persist via the instance's API client (fd.api.client)
63
64
  * 5. Update the store if the server assigned a new ID
64
65
  * 6. Call onMarkAsSaved / onAfterSave hooks
65
66
  * 7. Show toast notifications (respecting features.showToasts)
@@ -8,8 +8,7 @@
8
8
  * construction happen in exactly one place.
9
9
  */
10
10
  import { tick } from 'svelte';
11
- import { getWorkflowStore, workflowActions, markAsSaved as storeMarkAsSaved } from '../stores/workflowStore.svelte.js';
12
- import { workflowApi, setEndpointConfig } from './api.js';
11
+ import { getDefaultInstance } from '../stores/instanceContainer.svelte.js';
13
12
  import { createEndpointConfig } from '../config/endpoints.js';
14
13
  import { v4 as uuidv4 } from 'uuid';
15
14
  import { DEFAULT_WORKFLOW_FORMAT } from '../types/index.js';
@@ -19,29 +18,19 @@ import { DEFAULT_FEATURES } from '../types/events.js';
19
18
  // Internal helpers
20
19
  // ---------------------------------------------------------------------------
21
20
  /**
22
- * Ensure API configuration is initialized.
23
- * This is needed when the global save function is called from the layout component
24
- * which doesn't initialize the API configuration like the App component does.
21
+ * Ensure the instance's API context is configured.
22
+ * This is needed when the global save function is called from the layout
23
+ * component which doesn't initialize the API configuration like <App> does.
25
24
  */
26
- async function ensureApiConfiguration() {
27
- try {
28
- const { getEndpointConfig } = await import('./api.js');
29
- const currentConfig = getEndpointConfig();
30
- if (currentConfig && currentConfig.baseUrl) {
31
- return;
32
- }
33
- }
34
- catch {
35
- // Could not check existing API configuration, initializing
25
+ function ensureApiConfiguration(fd) {
26
+ if (fd.api.isConfigured() && fd.api.config?.baseUrl) {
27
+ return;
36
28
  }
37
29
  // API configuration is not initialized — derive URL from window.location when available
38
30
  const apiBaseUrl = typeof window !== 'undefined'
39
31
  ? `${window.location.protocol}//${window.location.host}/api/flowdrop`
40
32
  : '/api/flowdrop';
41
33
  const config = createEndpointConfig(apiBaseUrl, {
42
- auth: {
43
- type: 'none'
44
- },
45
34
  timeout: 10000,
46
35
  retry: {
47
36
  enabled: true,
@@ -50,7 +39,7 @@ async function ensureApiConfiguration() {
50
39
  backoff: 'exponential'
51
40
  }
52
41
  });
53
- setEndpointConfig(config);
42
+ fd.api.configure(config);
54
43
  }
55
44
  /**
56
45
  * Flush any pending form changes by blurring the active element.
@@ -79,18 +68,21 @@ async function flushPendingFormChanges() {
79
68
  * 1. Flush pending form changes (blur active element + tick)
80
69
  * 2. Optionally call onBeforeSave — return false cancels the save
81
70
  * 3. Build the canonical Workflow object (preserving metadata, format, etc.)
82
- * 4. Persist via enhanced apiClient or legacy workflowApi
71
+ * 4. Persist via the instance's API client (fd.api.client)
83
72
  * 5. Update the store if the server assigned a new ID
84
73
  * 6. Call onMarkAsSaved / onAfterSave hooks
85
74
  * 7. Show toast notifications (respecting features.showToasts)
86
75
  */
87
76
  export async function globalSaveWorkflow(options = {}) {
88
- const { apiClient, eventHandlers, onMarkAsSaved, onSaved } = options;
77
+ const { eventHandlers, onMarkAsSaved, onSaved } = options;
89
78
  const features = { ...DEFAULT_FEATURES, ...options.features };
79
+ // Resolve the target instance; defaults to the page-default instance.
80
+ const fd = options.instance ?? getDefaultInstance();
81
+ const readWorkflow = () => fd.workflow.current;
90
82
  // Step 1 — Flush pending form changes (single location for this logic)
91
83
  await flushPendingFormChanges();
92
- // Get current workflow from global store after flush
93
- const currentWorkflow = getWorkflowStore();
84
+ // Get current workflow from the instance's store after flush
85
+ const currentWorkflow = readWorkflow();
94
86
  if (!currentWorkflow) {
95
87
  if (features.showToasts) {
96
88
  apiToasts.error('Save workflow', 'No workflow to save');
@@ -107,7 +99,7 @@ export async function globalSaveWorkflow(options = {}) {
107
99
  const loadingToast = features.showToasts ? apiToasts.loading('Saving workflow') : null;
108
100
  try {
109
101
  // Ensure API configuration is initialised (needed when called outside App.svelte)
110
- await ensureApiConfiguration();
102
+ ensureApiConfiguration(fd);
111
103
  // Step 3 — Build the canonical workflow object.
112
104
  // Preserve all existing metadata fields (format, tags, etc.) so nothing is dropped.
113
105
  //
@@ -124,35 +116,21 @@ export async function globalSaveWorkflow(options = {}) {
124
116
  edges: currentWorkflow.edges || [],
125
117
  metadata: {
126
118
  ...currentWorkflow.metadata,
127
- version: currentWorkflow.metadata?.version || '1.0.0',
119
+ schemaVersion: currentWorkflow.metadata?.schemaVersion || '1.0.0',
128
120
  format: currentWorkflow.metadata?.format || DEFAULT_WORKFLOW_FORMAT,
129
121
  createdAt: currentWorkflow.metadata?.createdAt || new Date().toISOString(),
130
122
  updatedAt: new Date().toISOString()
131
123
  }
132
124
  };
133
- // Step 4 — Persist
134
- let savedWorkflow;
135
- if (apiClient) {
136
- if (isExistingWorkflow) {
137
- savedWorkflow = await apiClient.updateWorkflow(finalWorkflow.id, finalWorkflow);
138
- }
139
- else {
140
- savedWorkflow = await apiClient.saveWorkflow(finalWorkflow);
141
- }
142
- }
143
- else {
144
- // Legacy path
145
- if (isExistingWorkflow) {
146
- savedWorkflow = await workflowApi.updateWorkflow(finalWorkflow.id, finalWorkflow);
147
- }
148
- else {
149
- const { id: _id, ...workflowData } = finalWorkflow;
150
- savedWorkflow = await workflowApi.createWorkflow(workflowData);
151
- }
152
- }
125
+ // Step 4 — Persist via this instance's API client.
126
+ // id-presence (computed above) decides update vs create — never UUID-regex.
127
+ const apiClient = fd.api.client;
128
+ const savedWorkflow = isExistingWorkflow
129
+ ? await apiClient.updateWorkflow(finalWorkflow.id, finalWorkflow)
130
+ : await apiClient.saveWorkflow(finalWorkflow);
153
131
  // Step 5 — If the server assigned a new ID, sync the store
154
132
  if (savedWorkflow.id && savedWorkflow.id !== finalWorkflow.id) {
155
- workflowActions.batchUpdate({
133
+ fd.workflow.batchUpdate({
156
134
  nodes: finalWorkflow.nodes,
157
135
  edges: finalWorkflow.edges,
158
136
  name: finalWorkflow.name,
@@ -167,8 +145,7 @@ export async function globalSaveWorkflow(options = {}) {
167
145
  onMarkAsSaved();
168
146
  }
169
147
  else {
170
- // Fallback: call the store's own markAsSaved if no callback was provided
171
- storeMarkAsSaved();
148
+ fd.workflow.markAsSaved();
172
149
  }
173
150
  // Notify caller with the definitive saved workflow (server-assigned ID)
174
151
  if (onSaved) {
@@ -190,7 +167,7 @@ export async function globalSaveWorkflow(options = {}) {
190
167
  dismissToast(loadingToast);
191
168
  const errorObj = error instanceof Error ? error : new Error('Unknown error occurred');
192
169
  // onSaveError hook
193
- const currentWorkflowForError = getWorkflowStore();
170
+ const currentWorkflowForError = readWorkflow();
194
171
  if (eventHandlers?.onSaveError && currentWorkflowForError) {
195
172
  await eventHandlers.onSaveError(errorObj, currentWorkflowForError);
196
173
  }
@@ -218,7 +195,8 @@ export async function globalExportWorkflow(options = {}) {
218
195
  try {
219
196
  // Flush pending changes before exporting (same discipline as save)
220
197
  await flushPendingFormChanges();
221
- const currentWorkflow = getWorkflowStore();
198
+ const fd = options.instance ?? getDefaultInstance();
199
+ const currentWorkflow = fd.workflow.current;
222
200
  if (!currentWorkflow) {
223
201
  if (features.showToasts) {
224
202
  apiToasts.error('Export workflow', 'No workflow to export');
@@ -234,7 +212,7 @@ export async function globalExportWorkflow(options = {}) {
234
212
  edges: currentWorkflow.edges || [],
235
213
  metadata: {
236
214
  ...currentWorkflow.metadata,
237
- version: currentWorkflow.metadata?.version || '1.0.0',
215
+ schemaVersion: currentWorkflow.metadata?.schemaVersion || '1.0.0',
238
216
  format: currentWorkflow.metadata?.format || DEFAULT_WORKFLOW_FORMAT,
239
217
  createdAt: currentWorkflow.metadata?.createdAt || new Date().toISOString(),
240
218
  updatedAt: new Date().toISOString()
@@ -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
  *
@@ -202,9 +224,15 @@ export declare class HistoryService {
202
224
  private notifyChange;
203
225
  }
204
226
  /**
205
- * Singleton instance of the history service
227
+ * History service of the page-default FlowDrop instance.
228
+ *
229
+ * Kept as a module-level export for backward compatibility (re-exported via
230
+ * `@flowdrop/flowdrop/editor`) — `createFlowDropInstance({ isDefault: true })`
231
+ * adopts this exact object, so legacy `historyService.undo()` calls keep
232
+ * operating on the default editor's history stack. Holds no reactive state,
233
+ * so module-level construction is SSR-safe.
206
234
  *
207
- * Use this for the main workflow editor. For isolated instances,
208
- * create a new HistoryService directly.
235
+ * For additional editor instances, the instance container creates a fresh
236
+ * `new HistoryService()` — use `getInstance().history` in components.
209
237
  */
210
238
  export declare const historyService: HistoryService;