@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
@@ -11,15 +11,17 @@
11
11
  *
12
12
  * Extends BaseRegistry for shared mechanics (subscribe, onClear, etc.).
13
13
  */
14
- import { BaseRegistry } from './BaseRegistry.js';
14
+ import { BaseRegistry } from './BaseRegistry.svelte.js';
15
15
  /**
16
- * Central registry for workflow format adapters.
17
- * Singleton — extends BaseRegistry for shared mechanics.
16
+ * Per-instance registry for workflow format adapters.
17
+ * Extends BaseRegistry for shared mechanics; seeded with the built-in
18
+ * adapters at construction (see `createFlowDropInstance`). Reach it via
19
+ * `fd.formats`, or supply adapters through the `formatAdapters` mount option.
18
20
  *
19
21
  * @example
20
22
  * ```typescript
21
23
  * // Register a custom format
22
- * workflowFormatRegistry.register({
24
+ * fd.formats.register({
23
25
  * id: 'n8n',
24
26
  * name: 'n8n Workflow',
25
27
  * export: (workflow) => JSON.stringify(convertToN8n(workflow)),
@@ -27,10 +29,23 @@ import { BaseRegistry } from './BaseRegistry.js';
27
29
  * });
28
30
  *
29
31
  * // Get an adapter
30
- * const adapter = workflowFormatRegistry.get('n8n');
32
+ * const adapter = fd.formats.get('n8n');
31
33
  * ```
32
34
  */
33
- class WorkflowFormatRegistry extends BaseRegistry {
35
+ export class WorkflowFormatRegistry extends BaseRegistry {
36
+ /**
37
+ * @param seed - Optional initial format adapters. When omitted the registry
38
+ * starts empty; instances created via `createFlowDropInstance` pass the
39
+ * built-in flowdrop + agentspec adapters (see `builtinFormats.ts`).
40
+ */
41
+ constructor(seed) {
42
+ super();
43
+ if (seed) {
44
+ for (const adapter of seed) {
45
+ this.register(adapter, true);
46
+ }
47
+ }
48
+ }
34
49
  /**
35
50
  * Register a workflow format adapter.
36
51
  *
@@ -44,6 +59,7 @@ class WorkflowFormatRegistry extends BaseRegistry {
44
59
  `Use overwrite: true to replace it.`);
45
60
  }
46
61
  this.items.set(adapter.id, adapter);
62
+ this.touch();
47
63
  this.notifyListeners();
48
64
  }
49
65
  /**
@@ -61,6 +77,7 @@ class WorkflowFormatRegistry extends BaseRegistry {
61
77
  * @returns Array of NodeMetadata from all format adapters
62
78
  */
63
79
  getAllFormatNodes() {
80
+ this.trackVersion(); // reactive dependency (reads items directly)
64
81
  const allNodes = [];
65
82
  for (const adapter of this.items.values()) {
66
83
  if (adapter.nodes && adapter.nodes.length > 0) {
@@ -76,6 +93,7 @@ class WorkflowFormatRegistry extends BaseRegistry {
76
93
  * @returns Array of NodeMetadata for the format, or empty array
77
94
  */
78
95
  getFormatNodes(formatId) {
96
+ this.trackVersion(); // reactive dependency (reads items directly)
79
97
  const adapter = this.items.get(formatId);
80
98
  return adapter?.nodes ?? [];
81
99
  }
@@ -92,5 +110,3 @@ class WorkflowFormatRegistry extends BaseRegistry {
92
110
  }));
93
111
  }
94
112
  }
95
- /** Singleton instance of the workflow format registry */
96
- export const workflowFormatRegistry = new WorkflowFormatRegistry();
@@ -15,9 +15,9 @@
15
15
  * const valid = validate(myWorkflow);
16
16
  * ```
17
17
  *
18
- * @module schema
18
+ * @module schemas
19
19
  */
20
- import workflowSchema from '../schemas/v1/workflow.schema.json';
20
+ import workflowSchema from './v1/workflow.schema.json';
21
21
  /** Current workflow schema format version */
22
22
  export declare const WORKFLOW_SCHEMA_VERSION = "1.0.0";
23
23
  export { workflowSchema };
@@ -15,9 +15,9 @@
15
15
  * const valid = validate(myWorkflow);
16
16
  * ```
17
17
  *
18
- * @module schema
18
+ * @module schemas
19
19
  */
20
- import workflowSchema from '../schemas/v1/workflow.schema.json';
20
+ import workflowSchema from './v1/workflow.schema.json';
21
21
  /** Current workflow schema format version */
22
22
  export const WORKFLOW_SCHEMA_VERSION = '1.0.0';
23
23
  export { workflowSchema };
@@ -560,9 +560,9 @@
560
560
  },
561
561
  "NodeMetadata": {
562
562
  "type": "object",
563
- "description": "Complete metadata for a node type including ports, configuration schema, and extensions.\n\n## Dynamic Port Support\n\nNodes can support user-defined dynamic ports through their configSchema:\n- Add `dynamicInputs` array property to allow custom input handles\n- Add `dynamicOutputs` array property to allow custom output handles\n- Add `branches` array property for gateway nodes with conditional paths\n\n## Extensions Support\n\nThe `extensions` property allows storing UI settings and 3rd party data:\n- Use `extensions.ui.hideUnconnectedHandles` to hide unconnected ports by default\n- Use namespaced keys for custom integrations (e.g., \"myapp:settings\")\n",
563
+ "description": "Complete metadata for a node type including ports, configuration schema, and extensions.\n\n## Dynamic Port Support\n\nNodes can support user-defined dynamic ports through their configSchema:\n- Add `dynamicInputs` array property to allow custom input handles\n- Add `dynamicOutputs` array property to allow custom output handles\n- Add `branches` array property for gateway nodes with conditional paths\n\n## Extensions Support\n\nThe `extensions` property allows storing UI settings and 3rd party data:\n- Use `extensions.ui.style` for custom per-node styling\n- Use namespaced keys for custom integrations (e.g., \"myapp:settings\")\n(Port order + exposure live in `config.ports`, not here.)\n",
564
564
  "properties": {
565
- "id": {
565
+ "node_type_id": {
566
566
  "type": "string",
567
567
  "description": "Node type unique identifier"
568
568
  },
@@ -650,7 +650,7 @@
650
650
  }
651
651
  },
652
652
  "required": [
653
- "id",
653
+ "node_type_id",
654
654
  "name",
655
655
  "description",
656
656
  "category",
@@ -695,6 +695,16 @@
695
695
  "defaultValue": {
696
696
  "description": "Default value used when no connection provides data"
697
697
  },
698
+ "exposedByDefault": {
699
+ "type": "boolean",
700
+ "default": true,
701
+ "description": "Whether the port is exposed when the instance sets no explicit exposure\nfor it (in `data.config.ports`). Defaults to true — a missing override\nreads as exposed. Reserved ports that ship hidden until an author opts in\n(e.g. the `error` output) carry false. In v2 exposure is semantic: a\nnot-exposed port is hidden on the canvas, not wireable, and not\nruntime-overridable.\n"
702
+ },
703
+ "displayOrder": {
704
+ "type": "integer",
705
+ "default": 0,
706
+ "description": "Default sort weight for the port's render position, ascending; ties\nbreak on declaration order. Author-declared ports default to 0. Reserved\nports (the `error` output and `trigger`/`tool` control ports) need no\nvalue — the renderer sinks them to the bottom automatically; set this\nonly to override that. Cosmetic only. The instance's `config.ports`\norder overrides this when present.\n"
707
+ },
698
708
  "schema": {
699
709
  "allOf": [
700
710
  {
@@ -726,16 +736,12 @@
726
736
  "idea",
727
737
  "default"
728
738
  ],
729
- "description": "Visual rendering type for the node.\n\nBuilt-in types:\n- `note` - Sticky note with markdown support\n- `simple` - Compact layout with header and description\n- `square` - Minimal square node with centered icon\n- `atom` - Minimal label-only pill/rectangle for value/transform nodes (uses extensions.ui.atom)\n- `tool` - Specialized node for agent tools\n- `gateway` - Branching control flow with dynamic branches (uses config.branches)\n- `terminal` - Circular node for workflow start/end/exit points\n- `idea` - Conceptual idea node for BPMN-like flow diagrams\n- `default` - Full-featured workflow node with dynamic port support\n\n## Dynamic Port Support\n\nThe `default` and `gateway` node types support dynamic ports:\n\n- **default**: Supports `config.dynamicInputs` and `config.dynamicOutputs`\n for user-defined input/output handles\n- **gateway**: Supports `config.branches` for conditional branching paths\n\n## UI Extensions\n\nAll node types support `extensions.ui.hideUnconnectedHandles` to control\nvisibility of unconnected ports.\n"
739
+ "description": "Visual rendering type for the node.\n\nBuilt-in types:\n- `note` - Sticky note with markdown support\n- `simple` - Compact layout with header and description\n- `square` - Minimal square node with centered icon\n- `atom` - Minimal label-only pill/rectangle for value/transform nodes (uses extensions.ui.atom)\n- `tool` - Specialized node for agent tools\n- `gateway` - Branching control flow with dynamic branches (uses config.branches)\n- `terminal` - Circular node for workflow start/end/exit points\n- `idea` - Conceptual idea node for BPMN-like flow diagrams\n- `default` - Full-featured workflow node with dynamic port support\n\n## Dynamic Port Support\n\nThe `default` and `gateway` node types support dynamic ports:\n\n- **default**: Supports `config.dynamicInputs` and `config.dynamicOutputs`\n for user-defined input/output handles\n- **gateway**: Supports `config.branches` for conditional branching paths\n\n## Port order + exposure\n\nRender order and exposure are controlled per instance via `config.ports`\n(a per-direction ordered list of `{id, exposed?}`), over each port's metadata\n`displayOrder` / `exposedByDefault` defaults. Order is cosmetic; a not-exposed\nport is hidden, not wireable, and not runtime-overridable.\n"
730
740
  },
731
741
  "NodeUIExtensions": {
732
742
  "type": "object",
733
743
  "description": "UI-related extension settings for nodes.\nUsed to control visual behavior in the workflow editor.\n\nThese settings can be defined at two levels:\n1. **Node Type Level** (`metadata.extensions.ui`): Default settings for all instances\n2. **Instance Level** (`data.extensions.ui`): Override for specific node instances\n\nInstance-level settings take precedence over type-level defaults.\n",
734
744
  "properties": {
735
- "hideUnconnectedHandles": {
736
- "type": "boolean",
737
- "description": "Show/hide unconnected handles (ports) to reduce visual noise.\nWhen true, only ports with active connections are displayed.\nUseful for nodes with many optional ports.\n"
738
- },
739
745
  "atom": {
740
746
  "$ref": "#/$defs/AtomUIConfig"
741
747
  },
@@ -1053,9 +1059,9 @@
1053
1059
  "WorkflowMetadata": {
1054
1060
  "type": "object",
1055
1061
  "properties": {
1056
- "version": {
1062
+ "schemaVersion": {
1057
1063
  "type": "string",
1058
- "description": "Workflow version"
1064
+ "description": "Workflow schema format version — identifies the document format, not the workflow's own revision."
1059
1065
  },
1060
1066
  "createdAt": {
1061
1067
  "type": "string",
@@ -1093,7 +1099,7 @@
1093
1099
  }
1094
1100
  },
1095
1101
  "required": [
1096
- "version",
1102
+ "schemaVersion",
1097
1103
  "createdAt",
1098
1104
  "updatedAt"
1099
1105
  ]
@@ -1109,7 +1115,7 @@
1109
1115
  },
1110
1116
  "type": {
1111
1117
  "type": "string",
1112
- "description": "Node type ID (references NodeMetadata.id)"
1118
+ "description": "Node type ID (references NodeMetadata.node_type_id)"
1113
1119
  },
1114
1120
  "position": {
1115
1121
  "$ref": "#/$defs/Position"
@@ -1139,10 +1145,6 @@
1139
1145
  "type": "string",
1140
1146
  "description": "Error message if node execution failed"
1141
1147
  },
1142
- "nodeId": {
1143
- "type": "string",
1144
- "description": "Alternative node ID"
1145
- },
1146
1148
  "executionInfo": {
1147
1149
  "$ref": "#/$defs/NodeExecutionInfo"
1148
1150
  },
@@ -1152,7 +1154,7 @@
1152
1154
  "$ref": "#/$defs/NodeExtensions"
1153
1155
  },
1154
1156
  {
1155
- "description": "Per-instance extension properties for 3rd party integrations.\nOverrides or extends the node type extensions defined in metadata.extensions.\nUse for instance-specific UI states or custom data.\n\nCommon use cases:\n- `extensions.ui.hideUnconnectedHandles`: Hide ports without connections\n- `extensions.ui.style`: Custom styling for this node instance\n"
1157
+ "description": "Per-instance extension properties for 3rd party integrations.\nOverrides or extends the node type extensions defined in metadata.extensions.\nUse for instance-specific UI states or custom data.\n\nCommon use cases:\n- `extensions.ui.style`: Custom styling for this node instance\n(Port order + exposure live in `config.ports`, not here.)\n"
1156
1158
  }
1157
1159
  ]
1158
1160
  }
@@ -102,5 +102,3 @@ export declare class AgentSpecExecutionService {
102
102
  private mapSingleNodeStatus;
103
103
  private mapToFlowDropStatus;
104
104
  }
105
- /** Singleton instance */
106
- export declare const agentSpecExecutionService: AgentSpecExecutionService;
@@ -227,7 +227,6 @@ export class AgentSpecExecutionService {
227
227
  /** Get the config, throwing if not configured */
228
228
  getConfig() {
229
229
  this.ensureConfigured();
230
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
231
230
  return this.config;
232
231
  }
233
232
  startPolling(executionId, nameToNodeId, onNodeUpdate, onComplete, onError, intervalMs = 2000) {
@@ -333,5 +332,3 @@ export class AgentSpecExecutionService {
333
332
  }
334
333
  }
335
334
  }
336
- /** Singleton instance */
337
- export const agentSpecExecutionService = AgentSpecExecutionService.getInstance();
@@ -6,6 +6,7 @@
6
6
  * @module services/apiVariableService
7
7
  */
8
8
  import type { VariableSchema, ApiVariablesConfig, AuthProvider } from '../types/index.js';
9
+ import type { EndpointConfig } from '../config/endpoints.js';
9
10
  /**
10
11
  * Context for variable API requests
11
12
  */
@@ -71,7 +72,7 @@ export declare function resolveEndpointUrl(template: string, context: VariableCo
71
72
  * }
72
73
  * ```
73
74
  */
74
- export declare function fetchVariableSchema(workflowId: string | undefined, nodeId: string, config: ApiVariablesConfig, authProvider?: AuthProvider): Promise<ApiVariableResult>;
75
+ export declare function fetchVariableSchema(endpointConfig: EndpointConfig | null, workflowId: string | undefined, nodeId: string, config: ApiVariablesConfig, authProvider?: AuthProvider): Promise<ApiVariableResult>;
75
76
  /**
76
77
  * Clears the variable schema cache.
77
78
  * Can optionally clear only entries matching a specific pattern.
@@ -5,9 +5,8 @@
5
5
  *
6
6
  * @module services/apiVariableService
7
7
  */
8
- import { getEndpointConfig } from './api.js';
9
- import { logger } from '../utils/logger.js';
10
8
  import { DEFAULT_CACHE_TTL_MS } from '../config/constants.js';
9
+ import { authenticatedFetch } from '../utils/fetchWithAuth.js';
11
10
  /**
12
11
  * Variable schema cache with TTL support
13
12
  * Key format: `variables:{workflowId}:{nodeId}`
@@ -116,7 +115,7 @@ function resolveBodyTemplates(body, context) {
116
115
  * }
117
116
  * ```
118
117
  */
119
- export async function fetchVariableSchema(workflowId, nodeId, config, authProvider) {
118
+ export async function fetchVariableSchema(endpointConfig, workflowId, nodeId, config, authProvider) {
120
119
  const endpoint = config.endpoint;
121
120
  const context = { workflowId, nodeId };
122
121
  // Generate cache key
@@ -136,48 +135,16 @@ export async function fetchVariableSchema(workflowId, nodeId, config, authProvid
136
135
  // Resolve the URL with template variables
137
136
  let url = resolveEndpointUrl(endpoint.url, context);
138
137
  // If URL is relative, prepend base URL from endpoint config
139
- if (url.startsWith('/')) {
140
- const currentConfig = getEndpointConfig();
141
- if (currentConfig?.baseUrl) {
142
- const baseUrl = currentConfig.baseUrl.replace(/\/$/, '');
143
- url = `${baseUrl}${url}`;
144
- }
138
+ if (url.startsWith('/') && endpointConfig?.baseUrl) {
139
+ const baseUrl = endpointConfig.baseUrl.replace(/\/$/, '');
140
+ url = `${baseUrl}${url}`;
145
141
  }
146
142
  // Prepare request options
147
143
  const method = endpoint.method ?? 'GET';
148
144
  const timeout = endpoint.timeout ?? 30000;
149
- const headers = {
150
- Accept: 'application/json',
151
- 'Content-Type': 'application/json',
152
- ...endpoint.headers
153
- };
154
- // Add auth headers from AuthProvider if available
155
- if (authProvider) {
156
- try {
157
- const authHeaders = await authProvider.getAuthHeaders();
158
- Object.assign(headers, authHeaders);
159
- }
160
- catch (error) {
161
- logger.warn('Failed to get auth headers:', error);
162
- }
163
- }
164
- // Add auth headers from endpoint config as fallback
165
- const currentConfig = getEndpointConfig();
166
- if (currentConfig?.auth) {
167
- if (currentConfig.auth.type === 'bearer' && currentConfig.auth.token) {
168
- headers['Authorization'] = headers['Authorization'] ?? `Bearer ${currentConfig.auth.token}`;
169
- }
170
- else if (currentConfig.auth.type === 'api_key' && currentConfig.auth.apiKey) {
171
- headers['X-API-Key'] = headers['X-API-Key'] ?? currentConfig.auth.apiKey;
172
- }
173
- else if (currentConfig.auth.type === 'custom' && currentConfig.auth.headers) {
174
- Object.assign(headers, currentConfig.auth.headers);
175
- }
176
- }
177
145
  // Prepare fetch options
178
146
  const fetchOptions = {
179
147
  method,
180
- headers,
181
148
  signal: AbortSignal.timeout(timeout)
182
149
  };
183
150
  // Add body for non-GET requests
@@ -186,7 +153,16 @@ export async function fetchVariableSchema(workflowId, nodeId, config, authProvid
186
153
  fetchOptions.body = JSON.stringify(resolvedBody);
187
154
  }
188
155
  try {
189
- 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
+ });
190
166
  // Handle 404 as "no variables available"
191
167
  if (response.status === 404) {
192
168
  return {
@@ -196,15 +172,8 @@ export async function fetchVariableSchema(workflowId, nodeId, config, authProvid
196
172
  };
197
173
  }
198
174
  if (!response.ok) {
199
- // Handle authentication errors
175
+ // Auth errors remain after the provider's refresh attempt.
200
176
  if (response.status === 401 || response.status === 403) {
201
- if (authProvider?.onUnauthorized) {
202
- const refreshed = await authProvider.onUnauthorized();
203
- if (refreshed) {
204
- // Retry with refreshed auth
205
- return fetchVariableSchema(workflowId, nodeId, config, authProvider);
206
- }
207
- }
208
177
  return {
209
178
  success: false,
210
179
  error: 'Authentication failed'
@@ -23,6 +23,12 @@ interface AutoSaveOptions {
23
23
  * Optional callback for successful saves
24
24
  */
25
25
  onSuccess?: () => void;
26
+ /**
27
+ * Dirty-state probe for the owning FlowDrop instance, e.g.
28
+ * `() => fd.workflow.isDirty`. Defaults to the page-default
29
+ * instance's dirty state when omitted.
30
+ */
31
+ isDirty?: () => boolean;
26
32
  }
27
33
  /**
28
34
  * Initialize auto-save functionality based on user settings
@@ -68,6 +74,7 @@ export declare class AutoSaveManager {
68
74
  private onSave;
69
75
  private onError?;
70
76
  private onSuccess?;
77
+ private isDirtyProbe;
71
78
  /**
72
79
  * Create a new AutoSaveManager
73
80
  *
@@ -7,7 +7,7 @@
7
7
  * @module services/autoSaveService
8
8
  */
9
9
  import { getBehaviorSettings, onSettingsChange } from '../stores/settingsStore.svelte.js';
10
- import { isDirty } from '../stores/workflowStore.svelte.js';
10
+ import { getDefaultInstance } from '../stores/instanceContainer.svelte.js';
11
11
  import { logger } from '../utils/logger.js';
12
12
  /**
13
13
  * Initialize auto-save functionality based on user settings
@@ -40,7 +40,7 @@ import { logger } from '../utils/logger.js';
40
40
  * ```
41
41
  */
42
42
  export function initAutoSave(options) {
43
- const { onSave, onError, onSuccess } = options;
43
+ const { onSave, onError, onSuccess, isDirty: isDirtyProbe = () => getDefaultInstance().workflow.isDirty } = options;
44
44
  const state = {
45
45
  intervalId: null,
46
46
  isSaving: false,
@@ -52,7 +52,7 @@ export function initAutoSave(options) {
52
52
  */
53
53
  async function performAutoSave() {
54
54
  // Skip if already saving or not dirty
55
- if (state.isSaving || !isDirty()) {
55
+ if (state.isSaving || !isDirtyProbe()) {
56
56
  return;
57
57
  }
58
58
  state.isSaving = true;
@@ -127,6 +127,7 @@ export class AutoSaveManager {
127
127
  onSave;
128
128
  onError;
129
129
  onSuccess;
130
+ isDirtyProbe;
130
131
  /**
131
132
  * Create a new AutoSaveManager
132
133
  *
@@ -136,6 +137,7 @@ export class AutoSaveManager {
136
137
  this.onSave = options.onSave;
137
138
  this.onError = options.onError;
138
139
  this.onSuccess = options.onSuccess;
140
+ this.isDirtyProbe = options.isDirty ?? (() => getDefaultInstance().workflow.isDirty);
139
141
  }
140
142
  /**
141
143
  * Start the auto-save manager
@@ -207,7 +209,7 @@ export class AutoSaveManager {
207
209
  * Perform the save operation
208
210
  */
209
211
  async performSave() {
210
- if (this.isSaving || !isDirty()) {
212
+ if (this.isSaving || !this.isDirtyProbe()) {
211
213
  return;
212
214
  }
213
215
  this.isSaving = true;
@@ -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
  }
@@ -7,6 +7,8 @@
7
7
  * @module services/chatService
8
8
  */
9
9
  import type { ChatRequest, ChatResponse, ChatHistoryMessage } from '../types/chat.js';
10
+ import type { EndpointConfig } from '../config/endpoints.js';
11
+ import type { AuthProvider } from '../types/auth.js';
10
12
  /**
11
13
  * Chat Service class
12
14
  *
@@ -23,7 +25,9 @@ export declare class ChatService {
23
25
  */
24
26
  static getInstance(): ChatService;
25
27
  /**
26
- * Get the endpoint configuration
28
+ * Validate and return the caller-supplied endpoint configuration.
29
+ *
30
+ * Callers thread the config from `getInstance().api.config`.
27
31
  *
28
32
  * @throws Error if endpoint configuration is not set
29
33
  * @returns The endpoint configuration
@@ -32,6 +36,7 @@ export declare class ChatService {
32
36
  /**
33
37
  * Generic API request helper
34
38
  *
39
+ * @param config - The endpoint configuration
35
40
  * @param url - The URL to fetch
36
41
  * @param options - Fetch options
37
42
  * @returns The parsed JSON response
@@ -44,20 +49,20 @@ export declare class ChatService {
44
49
  * @param request - The chat request payload
45
50
  * @returns The chat response from the LLM
46
51
  */
47
- sendMessage(workflowId: string, request: ChatRequest): Promise<ChatResponse>;
52
+ sendMessage(endpointConfig: EndpointConfig | null, workflowId: string, request: ChatRequest, authProvider?: AuthProvider): Promise<ChatResponse>;
48
53
  /**
49
54
  * Get conversation history for a workflow
50
55
  *
51
56
  * @param workflowId - The workflow ID
52
57
  * @returns Array of chat history messages
53
58
  */
54
- getHistory(workflowId: string): Promise<ChatHistoryMessage[]>;
59
+ getHistory(endpointConfig: EndpointConfig | null, workflowId: string, authProvider?: AuthProvider): Promise<ChatHistoryMessage[]>;
55
60
  /**
56
61
  * Clear conversation history for a workflow
57
62
  *
58
63
  * @param workflowId - The workflow ID
59
64
  */
60
- clearHistory(workflowId: string): Promise<void>;
65
+ clearHistory(endpointConfig: EndpointConfig | null, workflowId: string, authProvider?: AuthProvider): Promise<void>;
61
66
  }
62
67
  /**
63
68
  * Pre-instantiated ChatService singleton
@@ -6,8 +6,8 @@
6
6
  *
7
7
  * @module services/chatService
8
8
  */
9
- import { buildEndpointUrl, getEndpointHeaders } from '../config/endpoints.js';
10
- import { getEndpointConfig } from './api.js';
9
+ import { buildEndpointUrl } from '../config/endpoints.js';
10
+ import { authenticatedFetch } from '../utils/fetchWithAuth.js';
11
11
  import { logger } from '../utils/logger.js';
12
12
  /**
13
13
  * Chat Service class
@@ -30,34 +30,32 @@ export class ChatService {
30
30
  return ChatService.instance;
31
31
  }
32
32
  /**
33
- * Get the endpoint configuration
33
+ * Validate and return the caller-supplied endpoint configuration.
34
+ *
35
+ * Callers thread the config from `getInstance().api.config`.
34
36
  *
35
37
  * @throws Error if endpoint configuration is not set
36
38
  * @returns The endpoint configuration
37
39
  */
38
- getConfig() {
39
- const config = getEndpointConfig();
40
+ getConfig(config) {
40
41
  if (!config) {
41
- throw new Error('Endpoint configuration not set. Call setEndpointConfig() first.');
42
+ throw new Error('Endpoint configuration not set. Configure the instance via fd.api.configure().');
42
43
  }
43
44
  return config;
44
45
  }
45
46
  /**
46
47
  * Generic API request helper
47
48
  *
49
+ * @param config - The endpoint configuration
48
50
  * @param url - The URL to fetch
49
51
  * @param options - Fetch options
50
52
  * @returns The parsed JSON response
51
53
  */
52
- async request(url, options = {}) {
53
- const config = this.getConfig();
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,16 +81,16 @@ 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(workflowId, request) {
87
- const config = this.getConfig();
84
+ async sendMessage(endpointConfig, workflowId, request, authProvider) {
85
+ const config = this.getConfig(endpointConfig);
88
86
  const url = buildEndpointUrl(config, config.endpoints.chat.sendMessage, {
89
87
  id: workflowId
90
88
  });
91
89
  logger.debug('[ChatService] Sending message to', url);
92
- return this.request(url, {
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(workflowId) {
104
- const config = this.getConfig();
101
+ async getHistory(endpointConfig, workflowId, authProvider) {
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(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(workflowId) {
117
- const config = this.getConfig();
114
+ async clearHistory(endpointConfig, workflowId, authProvider) {
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
  /**