@flowdrop/flowdrop 2.0.0-beta.1 → 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 (228) hide show
  1. package/CHANGELOG.md +173 -0
  2. package/MIGRATION-2.0.md +173 -3
  3. package/README.md +5 -5
  4. package/dist/adapters/WorkflowAdapter.js +4 -5
  5. package/dist/adapters/agentspec/AgentSpecAdapter.js +3 -3
  6. package/dist/adapters/agentspec/defaultNodeTypes.js +9 -9
  7. package/dist/api/enhanced-client.js +6 -11
  8. package/dist/commands/executor.js +51 -26
  9. package/dist/commands/storeIntegration.svelte.js +11 -1
  10. package/dist/commands/types.js +5 -5
  11. package/dist/components/App.svelte +547 -386
  12. package/dist/components/App.svelte.d.ts +16 -8
  13. package/dist/components/Button.stories.svelte +65 -0
  14. package/dist/components/Button.stories.svelte.d.ts +19 -0
  15. package/dist/components/Button.svelte +62 -0
  16. package/dist/components/Button.svelte.d.ts +24 -0
  17. package/dist/components/CanvasIconButton.svelte +76 -0
  18. package/dist/components/CanvasIconButton.svelte.d.ts +18 -0
  19. package/dist/components/ConfigForm.svelte +167 -562
  20. package/dist/components/ConfigForm.svelte.d.ts +24 -7
  21. package/dist/components/ConfigModal.svelte +9 -1
  22. package/dist/components/ConfigPanel.svelte +234 -15
  23. package/dist/components/ConfigPanel.svelte.d.ts +6 -0
  24. package/dist/components/EditorStatusBar.stories.svelte +44 -0
  25. package/dist/components/EditorStatusBar.stories.svelte.d.ts +27 -0
  26. package/dist/components/EditorStatusBar.svelte +99 -0
  27. package/dist/components/EditorStatusBar.svelte.d.ts +15 -0
  28. package/dist/components/IconButton.svelte +80 -0
  29. package/dist/components/IconButton.svelte.d.ts +30 -0
  30. package/dist/components/Input.svelte +74 -0
  31. package/dist/components/Input.svelte.d.ts +17 -0
  32. package/dist/components/LogoWordmark.svelte +113 -0
  33. package/dist/components/LogoWordmark.svelte.d.ts +26 -0
  34. package/dist/components/Navbar.svelte +17 -63
  35. package/dist/components/Navbar.svelte.d.ts +3 -0
  36. package/dist/components/NodeSidebar.svelte +21 -126
  37. package/dist/components/NodeSwapPicker.svelte +12 -30
  38. package/dist/components/PipelineStatus.svelte +6 -1
  39. package/dist/components/PipelineStatus.svelte.d.ts +3 -0
  40. package/dist/components/PortMappingRow.svelte +0 -2
  41. package/dist/components/SchemaForm.svelte +4 -14
  42. package/dist/components/Select.svelte +53 -0
  43. package/dist/components/Select.svelte.d.ts +15 -0
  44. package/dist/components/SettingsModal.svelte +0 -5
  45. package/dist/components/SettingsPanel.svelte +24 -6
  46. package/dist/components/Textarea.svelte +39 -0
  47. package/dist/components/Textarea.svelte.d.ts +12 -0
  48. package/dist/components/ThemeToggle.svelte +15 -94
  49. package/dist/components/UniversalNode.svelte +36 -4
  50. package/dist/components/UniversalNode.svelte.d.ts +1 -1
  51. package/dist/components/WorkflowEditor.svelte +66 -52
  52. package/dist/components/WorkflowEditor.svelte.d.ts +21 -0
  53. package/dist/components/chat/AIChatPanel.svelte +7 -2
  54. package/dist/components/console/ConsoleAutocomplete.svelte +1 -1
  55. package/dist/components/console/ConsoleInput.svelte +3 -3
  56. package/dist/components/console/ConsoleOutput.svelte +2 -2
  57. package/dist/components/form/FormArray.svelte +37 -173
  58. package/dist/components/form/FormAutocomplete.svelte +18 -15
  59. package/dist/components/form/FormCheckboxGroup.svelte +1 -5
  60. package/dist/components/form/FormCodeEditor.svelte +9 -7
  61. package/dist/components/form/FormField.svelte +18 -42
  62. package/dist/components/form/FormFieldLight.svelte +52 -48
  63. package/dist/components/form/FormFieldLight.svelte.d.ts +12 -0
  64. package/dist/components/form/FormFieldset.svelte +45 -11
  65. package/dist/components/form/FormMarkdownEditor.svelte +8 -5
  66. package/dist/components/form/FormNumberField.svelte +4 -36
  67. package/dist/components/form/FormPorts.svelte +262 -0
  68. package/dist/components/form/FormPorts.svelte.d.ts +13 -0
  69. package/dist/components/form/FormRangeField.svelte +61 -30
  70. package/dist/components/form/FormSelect.svelte +13 -75
  71. package/dist/components/form/FormTemplateEditor.svelte +6 -4
  72. package/dist/components/form/FormTextField.svelte +3 -35
  73. package/dist/components/form/FormTextarea.svelte +4 -39
  74. package/dist/components/form/FormToggle.svelte +0 -4
  75. package/dist/components/form/FormUISchemaRenderer.svelte +3 -1
  76. package/dist/components/form/resolveFieldType.d.ts +24 -0
  77. package/dist/components/form/resolveFieldType.js +55 -0
  78. package/dist/components/icons/CloseIcon.svelte +6 -0
  79. package/dist/components/icons/CloseIcon.svelte.d.ts +26 -0
  80. package/dist/components/icons/CommandLineIcon.svelte +15 -0
  81. package/dist/components/icons/CommandLineIcon.svelte.d.ts +26 -0
  82. package/dist/components/icons/MenuIcon.svelte +4 -0
  83. package/dist/components/icons/MenuIcon.svelte.d.ts +26 -0
  84. package/dist/components/icons/MenuOpenIcon.svelte +6 -0
  85. package/dist/components/icons/MenuOpenIcon.svelte.d.ts +26 -0
  86. package/dist/components/interrupt/ChoicePrompt.svelte +0 -10
  87. package/dist/components/interrupt/ConfirmationPrompt.svelte +0 -5
  88. package/dist/components/interrupt/InterruptBubble.svelte +11 -12
  89. package/dist/components/interrupt/ReviewPrompt.svelte +0 -20
  90. package/dist/components/interrupt/TextInputPrompt.svelte +0 -6
  91. package/dist/components/layouts/MainLayout.svelte +4 -5
  92. package/dist/components/nodes/AtomNode.svelte +62 -76
  93. package/dist/components/nodes/AtomNode.svelte.d.ts +1 -1
  94. package/dist/components/nodes/GatewayNode.svelte +117 -164
  95. package/dist/components/nodes/GatewayNode.svelte.d.ts +1 -1
  96. package/dist/components/nodes/IdeaNode.svelte +72 -98
  97. package/dist/components/nodes/IdeaNode.svelte.d.ts +8 -4
  98. package/dist/components/nodes/NodeConfigButton.svelte +86 -0
  99. package/dist/components/nodes/NodeConfigButton.svelte.d.ts +15 -0
  100. package/dist/components/nodes/NotesNode.svelte +76 -85
  101. package/dist/components/nodes/NotesNode.svelte.d.ts +8 -4
  102. package/dist/components/nodes/SimpleNode.svelte +59 -133
  103. package/dist/components/nodes/SimpleNode.svelte.d.ts +4 -4
  104. package/dist/components/nodes/SquareNode.svelte +110 -164
  105. package/dist/components/nodes/SquareNode.svelte.d.ts +4 -4
  106. package/dist/components/nodes/TerminalNode.svelte +62 -124
  107. package/dist/components/nodes/TerminalNode.svelte.d.ts +4 -4
  108. package/dist/components/nodes/ToolNode.svelte +92 -103
  109. package/dist/components/nodes/ToolNode.svelte.d.ts +6 -6
  110. package/dist/components/nodes/WorkflowNode.svelte +132 -191
  111. package/dist/components/nodes/WorkflowNode.svelte.d.ts +1 -1
  112. package/dist/components/playground/ChatInput.svelte +0 -1
  113. package/dist/components/playground/InputCollector.svelte +11 -48
  114. package/dist/components/playground/PipelineKanbanView.svelte +6 -4
  115. package/dist/components/playground/PipelineKanbanView.svelte.d.ts +2 -0
  116. package/dist/components/playground/PipelinePanel.svelte +20 -3
  117. package/dist/components/playground/PipelinePanel.svelte.d.ts +2 -0
  118. package/dist/components/playground/PipelineTableView.svelte +6 -4
  119. package/dist/components/playground/PipelineTableView.svelte.d.ts +2 -0
  120. package/dist/components/playground/Playground.svelte +76 -25
  121. package/dist/components/playground/Playground.svelte.d.ts +3 -0
  122. package/dist/components/playground/PlaygroundApp.svelte +6 -1
  123. package/dist/components/playground/PlaygroundApp.svelte.d.ts +3 -0
  124. package/dist/components/playground/PlaygroundModal.svelte +5 -0
  125. package/dist/components/playground/PlaygroundModal.svelte.d.ts +3 -0
  126. package/dist/components/playground/PlaygroundStudio.svelte +7 -6
  127. package/dist/components/playground/PlaygroundStudio.svelte.d.ts +3 -0
  128. package/dist/components/playground/pipelineViewUtils.svelte.d.ts +2 -1
  129. package/dist/components/playground/pipelineViewUtils.svelte.js +2 -2
  130. package/dist/components/surfaces/SurfaceOverlay.svelte +153 -0
  131. package/dist/components/surfaces/SurfaceOverlay.svelte.d.ts +14 -0
  132. package/dist/components/surfaces/TabbedSurface.svelte +133 -0
  133. package/dist/components/surfaces/TabbedSurface.svelte.d.ts +27 -0
  134. package/dist/config/endpoints.d.ts +23 -0
  135. package/dist/config/endpoints.js +28 -0
  136. package/dist/core/index.d.ts +2 -3
  137. package/dist/core/index.js +2 -6
  138. package/dist/display/index.d.ts +6 -1
  139. package/dist/display/index.js +9 -1
  140. package/dist/editor/index.d.ts +1 -1
  141. package/dist/editor/index.js +1 -1
  142. package/dist/form/full.d.ts +2 -1
  143. package/dist/form/full.js +4 -1
  144. package/dist/form/index.d.ts +0 -1
  145. package/dist/form/index.js +3 -2
  146. package/dist/helpers/workflowEditorHelper.d.ts +4 -2
  147. package/dist/helpers/workflowEditorHelper.js +8 -8
  148. package/dist/messages/index.d.ts +1 -1
  149. package/dist/messages/index.js +1 -1
  150. package/dist/openapi/v1/openapi.yaml +35 -23
  151. package/dist/playground/index.d.ts +2 -2
  152. package/dist/playground/index.js +2 -2
  153. package/dist/playground/mount.d.ts +19 -5
  154. package/dist/playground/mount.js +16 -8
  155. package/dist/registry/builtinNodeTypes.d.ts +53 -0
  156. package/dist/registry/builtinNodeTypes.js +67 -0
  157. package/dist/registry/builtinNodes.d.ts +2 -39
  158. package/dist/registry/builtinNodes.js +6 -53
  159. package/dist/registry/nodeComponentRegistry.d.ts +2 -1
  160. package/dist/schemas/v1/workflow.schema.json +16 -14
  161. package/dist/services/agentSpecExecutionService.d.ts +0 -2
  162. package/dist/services/agentSpecExecutionService.js +0 -2
  163. package/dist/services/apiVariableService.js +12 -26
  164. package/dist/services/categoriesApi.js +3 -6
  165. package/dist/services/chatService.d.ts +4 -3
  166. package/dist/services/chatService.js +13 -18
  167. package/dist/services/dynamicSchemaService.d.ts +31 -4
  168. package/dist/services/dynamicSchemaService.js +62 -33
  169. package/dist/services/historyService.d.ts +30 -8
  170. package/dist/services/historyService.js +51 -15
  171. package/dist/services/interruptService.d.ts +7 -6
  172. package/dist/services/interruptService.js +19 -21
  173. package/dist/services/playgroundService.d.ts +9 -8
  174. package/dist/services/playgroundService.js +23 -25
  175. package/dist/services/portConfigApi.js +3 -6
  176. package/dist/services/settingsService.d.ts +9 -4
  177. package/dist/services/settingsService.js +23 -12
  178. package/dist/skins/drafter.d.ts +30 -0
  179. package/dist/skins/drafter.js +198 -0
  180. package/dist/skins/index.d.ts +2 -1
  181. package/dist/skins/index.js +4 -2
  182. package/dist/stores/apiContext.d.ts +11 -0
  183. package/dist/stores/apiContext.js +15 -0
  184. package/dist/stores/categoriesStore.svelte.js +0 -1
  185. package/dist/stores/historyStore.svelte.d.ts +17 -3
  186. package/dist/stores/historyStore.svelte.js +30 -3
  187. package/dist/stores/instanceContainer.svelte.js +5 -0
  188. package/dist/stores/playgroundStore.svelte.js +1 -3
  189. package/dist/stores/settingsStore.svelte.d.ts +13 -0
  190. package/dist/stores/settingsStore.svelte.js +32 -0
  191. package/dist/stores/workflowStore.svelte.d.ts +42 -5
  192. package/dist/stores/workflowStore.svelte.js +109 -32
  193. package/dist/styles/base.css +285 -14
  194. package/dist/styles/tokens.css +60 -2
  195. package/dist/svelte-app.d.ts +18 -1
  196. package/dist/svelte-app.js +75 -110
  197. package/dist/themes/drafter.d.ts +2 -0
  198. package/dist/themes/drafter.js +15 -0
  199. package/dist/themes/index.d.ts +2 -1
  200. package/dist/themes/index.js +8 -2
  201. package/dist/types/auth.d.ts +9 -51
  202. package/dist/types/auth.js +4 -54
  203. package/dist/types/events.d.ts +18 -0
  204. package/dist/types/events.js +2 -1
  205. package/dist/types/index.d.ts +84 -29
  206. package/dist/types/index.js +0 -1
  207. package/dist/types/settings.d.ts +17 -1
  208. package/dist/types/settings.js +4 -2
  209. package/dist/types/skin.d.ts +1 -1
  210. package/dist/types/theme.d.ts +16 -2
  211. package/dist/types/uischema.d.ts +5 -0
  212. package/dist/utils/colors.d.ts +27 -0
  213. package/dist/utils/colors.js +23 -0
  214. package/dist/utils/connections.js +20 -56
  215. package/dist/utils/edgeStyling.js +9 -5
  216. package/dist/utils/fetchWithAuth.d.ts +36 -15
  217. package/dist/utils/fetchWithAuth.js +53 -23
  218. package/dist/utils/nodeIds.d.ts +1 -1
  219. package/dist/utils/nodeIds.js +1 -1
  220. package/dist/utils/nodeSwap.js +3 -6
  221. package/dist/utils/nodeTypes.js +1 -1
  222. package/dist/utils/portUtils.d.ts +47 -11
  223. package/dist/utils/portUtils.js +67 -14
  224. package/dist/utils/portal.d.ts +18 -0
  225. package/dist/utils/portal.js +34 -0
  226. package/dist/utils/schemaMerge.d.ts +25 -0
  227. package/dist/utils/schemaMerge.js +61 -0
  228. package/package.json +2 -1
@@ -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
  *
@@ -18,6 +18,13 @@ import { logger } from '../utils/logger.js';
18
18
  * a complete copy of the workflow state. This trades memory for simplicity
19
19
  * and reliability.
20
20
  *
21
+ * Snapshot model: the undo stack holds *committed* states, and its **top is the
22
+ * current live state**. `initialize()` seeds it with the starting state, and each
23
+ * mutation pushes the state *after* the change. One `undo()` moves the top back by
24
+ * exactly one committed change, and `redo()` restores the state that was undone.
25
+ * (Callers must push the post-change state — pushing pre-change snapshots makes a
26
+ * single undo skip a step once there are ≥2 sequential edits; see issue #39.)
27
+ *
21
28
  * @example
22
29
  * ```typescript
23
30
  * const historyService = new HistoryService();
@@ -25,7 +32,7 @@ import { logger } from '../utils/logger.js';
25
32
  * // Initialize with current workflow
26
33
  * historyService.initialize(workflow);
27
34
  *
28
- * // Push state before making changes
35
+ * // Push state AFTER making changes (the new committed state)
29
36
  * historyService.push(workflow, { description: "Add node" });
30
37
  *
31
38
  * // Undo/Redo
@@ -82,12 +89,13 @@ export class HistoryService {
82
89
  this.notifyChange();
83
90
  }
84
91
  /**
85
- * Push the current state to history before making changes
92
+ * Push a new committed state to history
86
93
  *
87
- * Call this BEFORE modifying the workflow to capture the "before" state.
94
+ * Call this AFTER modifying the workflow, with the resulting ("after") state:
95
+ * the stack top is the current live state, so one undo == one committed change.
88
96
  * The redo stack is cleared when new changes are pushed.
89
97
  *
90
- * @param workflow - The current workflow state (before changes)
98
+ * @param workflow - The workflow state after the change
91
99
  * @param options - Options for this history entry
92
100
  */
93
101
  push(workflow, options = {}) {
@@ -109,6 +117,15 @@ export class HistoryService {
109
117
  * @returns The previous workflow state, or null if cannot undo
110
118
  */
111
119
  undo() {
120
+ // A transaction is the store's to finalize (it holds the live state), and it
121
+ // must do so BEFORE calling undo — the facade and command dispatch both
122
+ // finalize first, and the editor's blur commits earlier still. If one is
123
+ // still open here, the caller violated that contract; abandon it (rather than
124
+ // guess a snapshot to commit) so the flag can't wedge future pushes, and warn.
125
+ if (this.inTransaction) {
126
+ logger.warn('HistoryService: undo() called with an open transaction; finalize the edit session first. Abandoning it.');
127
+ this.clearTransaction();
128
+ }
112
129
  // Need at least 2 entries to undo (initial + 1 change)
113
130
  if (this.undoStack.length <= 1) {
114
131
  return null;
@@ -131,6 +148,13 @@ export class HistoryService {
131
148
  * @returns The next workflow state, or null if cannot redo
132
149
  */
133
150
  redo() {
151
+ // Same contract as undo(): the caller must finalize any open edit session
152
+ // first. A dangling transaction here is a caller bug — abandon it and warn
153
+ // rather than committing a state we don't have.
154
+ if (this.inTransaction) {
155
+ logger.warn('HistoryService: redo() called with an open transaction; finalize the edit session first. Abandoning it.');
156
+ this.clearTransaction();
157
+ }
134
158
  if (this.redoStack.length === 0) {
135
159
  return null;
136
160
  }
@@ -147,9 +171,13 @@ export class HistoryService {
147
171
  * Start a transaction for grouping multiple changes
148
172
  *
149
173
  * All changes made during a transaction are combined into a single undo entry.
150
- * Useful for operations like "delete node" which also removes connected edges.
174
+ * Useful for operations like "delete node" which also removes connected edges,
175
+ * or coalescing a burst of live config edits into one step. While open, `push()`
176
+ * is suppressed; `commitTransaction()` records a single post-change entry.
151
177
  *
152
- * @param workflow - The current workflow state (before changes)
178
+ * @param workflow - The current workflow state at transaction start. Retained so
179
+ * {@link cancelTransaction} can restore it; the committed entry is the *final*
180
+ * state passed to {@link commitTransaction}, not this snapshot.
153
181
  * @param description - Description for the combined change
154
182
  */
155
183
  startTransaction(workflow, description) {
@@ -164,19 +192,23 @@ export class HistoryService {
164
192
  /**
165
193
  * Commit the current transaction
166
194
  *
167
- * Pushes the state captured at transaction start to the history stack.
195
+ * Records the transaction's *post-change* state as a single history entry, so
196
+ * one undo reverts the whole grouped operation and redo restores its result.
197
+ *
198
+ * The final state is required: the transaction's owner (the store) holds the
199
+ * live workflow and must supply it. There is deliberately no "commit whatever
200
+ * you captured at start" fallback — that would silently record a pre-change
201
+ * snapshot and reintroduce the off-by-one this model exists to prevent (#39).
202
+ *
203
+ * @param finalWorkflow - The workflow state after the grouped change.
168
204
  */
169
- commitTransaction() {
205
+ commitTransaction(finalWorkflow) {
170
206
  if (!this.inTransaction || !this.transactionSnapshot) {
171
207
  logger.warn('HistoryService: No transaction in progress, ignoring commitTransaction');
172
208
  return;
173
209
  }
174
- // Push the snapshot captured at transaction start
175
- this.pushInternal(this.transactionSnapshot, this.transactionDescription ?? undefined);
176
- // Clear transaction state
177
- this.inTransaction = false;
178
- this.transactionSnapshot = null;
179
- this.transactionDescription = null;
210
+ this.pushInternal(finalWorkflow, this.transactionDescription ?? undefined);
211
+ this.clearTransaction();
180
212
  }
181
213
  /**
182
214
  * Cancel the current transaction without committing
@@ -187,10 +219,14 @@ export class HistoryService {
187
219
  */
188
220
  cancelTransaction() {
189
221
  const snapshot = this.transactionSnapshot;
222
+ this.clearTransaction();
223
+ return snapshot;
224
+ }
225
+ /** Reset the in-progress transaction bookkeeping. */
226
+ clearTransaction() {
190
227
  this.inTransaction = false;
191
228
  this.transactionSnapshot = null;
192
229
  this.transactionDescription = null;
193
- return snapshot;
194
230
  }
195
231
  /**
196
232
  * Clear all history
@@ -9,6 +9,7 @@
9
9
  */
10
10
  import type { Interrupt, InterruptPollingConfig } from '../types/interrupt.js';
11
11
  import type { EndpointConfig } from '../config/endpoints.js';
12
+ import type { AuthProvider } from '../types/auth.js';
12
13
  /**
13
14
  * Interrupt Service class
14
15
  *
@@ -75,7 +76,7 @@ export declare class InterruptService {
75
76
  * @param interruptId - The interrupt UUID
76
77
  * @returns The interrupt details
77
78
  */
78
- getInterrupt(endpointConfig: EndpointConfig | null, interruptId: string): Promise<Interrupt>;
79
+ getInterrupt(endpointConfig: EndpointConfig | null, interruptId: string, authProvider?: AuthProvider): Promise<Interrupt>;
79
80
  /**
80
81
  * Resolve an interrupt with user response
81
82
  *
@@ -83,28 +84,28 @@ export declare class InterruptService {
83
84
  * @param value - The user's response value
84
85
  * @returns The updated interrupt
85
86
  */
86
- resolveInterrupt(endpointConfig: EndpointConfig | null, interruptId: string, value: unknown): Promise<Interrupt>;
87
+ resolveInterrupt(endpointConfig: EndpointConfig | null, interruptId: string, value: unknown, authProvider?: AuthProvider): Promise<Interrupt>;
87
88
  /**
88
89
  * Cancel a pending interrupt
89
90
  *
90
91
  * @param interruptId - The interrupt UUID
91
92
  * @returns The updated interrupt
92
93
  */
93
- cancelInterrupt(endpointConfig: EndpointConfig | null, interruptId: string): Promise<Interrupt>;
94
+ cancelInterrupt(endpointConfig: EndpointConfig | null, interruptId: string, authProvider?: AuthProvider): Promise<Interrupt>;
94
95
  /**
95
96
  * List interrupts for a playground session
96
97
  *
97
98
  * @param sessionId - The session UUID
98
99
  * @returns Array of interrupts for the session
99
100
  */
100
- listSessionInterrupts(endpointConfig: EndpointConfig | null, sessionId: string): Promise<Interrupt[]>;
101
+ listSessionInterrupts(endpointConfig: EndpointConfig | null, sessionId: string, authProvider?: AuthProvider): Promise<Interrupt[]>;
101
102
  /**
102
103
  * List interrupts for a pipeline
103
104
  *
104
105
  * @param pipelineId - The pipeline UUID
105
106
  * @returns Array of interrupts for the pipeline
106
107
  */
107
- listPipelineInterrupts(endpointConfig: EndpointConfig | null, pipelineId: string): Promise<Interrupt[]>;
108
+ listPipelineInterrupts(endpointConfig: EndpointConfig | null, pipelineId: string, authProvider?: AuthProvider): Promise<Interrupt[]>;
108
109
  /**
109
110
  * Start polling for interrupts in a session
110
111
  *
@@ -114,7 +115,7 @@ export declare class InterruptService {
114
115
  * @param sessionId - The session UUID to poll
115
116
  * @param callback - Callback function to handle new interrupts
116
117
  */
117
- startPolling(endpointConfig: EndpointConfig | null, sessionId: string, callback: (interrupts: Interrupt[]) => void): void;
118
+ startPolling(endpointConfig: EndpointConfig | null, sessionId: string, callback: (interrupts: Interrupt[]) => void, authProvider?: AuthProvider): void;
118
119
  /**
119
120
  * Stop polling for interrupts
120
121
  */
@@ -8,7 +8,8 @@
8
8
  * @module services/interruptService
9
9
  */
10
10
  import { defaultInterruptPollingConfig } from '../types/interrupt.js';
11
- import { buildEndpointUrl, getEndpointHeaders } from '../config/endpoints.js';
11
+ import { buildEndpointUrl } from '../config/endpoints.js';
12
+ import { authenticatedFetch } from '../utils/fetchWithAuth.js';
12
13
  import { logger } from '../utils/logger.js';
13
14
  /**
14
15
  * Interrupt Service class
@@ -92,14 +93,11 @@ export class InterruptService {
92
93
  * @param options - Fetch options
93
94
  * @returns The parsed JSON response
94
95
  */
95
- async request(config, url, options = {}) {
96
- const headers = getEndpointHeaders(config, 'interrupts');
97
- const response = await fetch(url, {
98
- ...options,
99
- headers: {
100
- ...headers,
101
- ...options.headers
102
- }
96
+ async request(config, url, options = {}, authProvider) {
97
+ const response = await authenticatedFetch(url, options, {
98
+ config,
99
+ endpointKey: 'interrupts',
100
+ authProvider
103
101
  });
104
102
  if (!response.ok) {
105
103
  const errorData = await response.json().catch(() => ({}));
@@ -119,12 +117,12 @@ export class InterruptService {
119
117
  * @param interruptId - The interrupt UUID
120
118
  * @returns The interrupt details
121
119
  */
122
- async getInterrupt(endpointConfig, interruptId) {
120
+ async getInterrupt(endpointConfig, interruptId, authProvider) {
123
121
  const config = this.getConfig(endpointConfig);
124
122
  const url = buildEndpointUrl(config, config.endpoints.interrupts.get, {
125
123
  interruptId
126
124
  });
127
- const response = await this.request(config, url);
125
+ const response = await this.request(config, url, {}, authProvider);
128
126
  if (!response.data) {
129
127
  throw new Error('Interrupt not found');
130
128
  }
@@ -137,7 +135,7 @@ export class InterruptService {
137
135
  * @param value - The user's response value
138
136
  * @returns The updated interrupt
139
137
  */
140
- async resolveInterrupt(endpointConfig, interruptId, value) {
138
+ async resolveInterrupt(endpointConfig, interruptId, value, authProvider) {
141
139
  const config = this.getConfig(endpointConfig);
142
140
  const url = buildEndpointUrl(config, config.endpoints.interrupts.resolve, {
143
141
  interruptId
@@ -146,7 +144,7 @@ export class InterruptService {
146
144
  const response = await this.request(config, url, {
147
145
  method: 'POST',
148
146
  body: JSON.stringify(resolution)
149
- });
147
+ }, authProvider);
150
148
  if (!response.data) {
151
149
  throw new Error('Failed to resolve interrupt: No data returned');
152
150
  }
@@ -158,14 +156,14 @@ export class InterruptService {
158
156
  * @param interruptId - The interrupt UUID
159
157
  * @returns The updated interrupt
160
158
  */
161
- async cancelInterrupt(endpointConfig, interruptId) {
159
+ async cancelInterrupt(endpointConfig, interruptId, authProvider) {
162
160
  const config = this.getConfig(endpointConfig);
163
161
  const url = buildEndpointUrl(config, config.endpoints.interrupts.cancel, {
164
162
  interruptId
165
163
  });
166
164
  const response = await this.request(config, url, {
167
165
  method: 'POST'
168
- });
166
+ }, authProvider);
169
167
  if (!response.data) {
170
168
  throw new Error('Failed to cancel interrupt: No data returned');
171
169
  }
@@ -177,12 +175,12 @@ export class InterruptService {
177
175
  * @param sessionId - The session UUID
178
176
  * @returns Array of interrupts for the session
179
177
  */
180
- async listSessionInterrupts(endpointConfig, sessionId) {
178
+ async listSessionInterrupts(endpointConfig, sessionId, authProvider) {
181
179
  const config = this.getConfig(endpointConfig);
182
180
  const url = buildEndpointUrl(config, config.endpoints.interrupts.listBySession, {
183
181
  sessionId
184
182
  });
185
- const response = await this.request(config, url);
183
+ const response = await this.request(config, url, {}, authProvider);
186
184
  return response.data ?? [];
187
185
  }
188
186
  /**
@@ -191,12 +189,12 @@ export class InterruptService {
191
189
  * @param pipelineId - The pipeline UUID
192
190
  * @returns Array of interrupts for the pipeline
193
191
  */
194
- async listPipelineInterrupts(endpointConfig, pipelineId) {
192
+ async listPipelineInterrupts(endpointConfig, pipelineId, authProvider) {
195
193
  const config = this.getConfig(endpointConfig);
196
194
  const url = buildEndpointUrl(config, config.endpoints.interrupts.listByPipeline, {
197
195
  pipelineId
198
196
  });
199
- const response = await this.request(config, url);
197
+ const response = await this.request(config, url, {}, authProvider);
200
198
  return response.data ?? [];
201
199
  }
202
200
  // =========================================================================
@@ -211,7 +209,7 @@ export class InterruptService {
211
209
  * @param sessionId - The session UUID to poll
212
210
  * @param callback - Callback function to handle new interrupts
213
211
  */
214
- startPolling(endpointConfig, sessionId, callback) {
212
+ startPolling(endpointConfig, sessionId, callback, authProvider) {
215
213
  if (!this.pollingConfig.enabled) {
216
214
  logger.warn('[InterruptService] Polling is disabled. Enable via setPollingConfig().');
217
215
  return;
@@ -225,7 +223,7 @@ export class InterruptService {
225
223
  return;
226
224
  }
227
225
  try {
228
- const interrupts = await this.listSessionInterrupts(endpointConfig, sessionId);
226
+ const interrupts = await this.listSessionInterrupts(endpointConfig, sessionId, authProvider);
229
227
  const pendingInterrupts = interrupts.filter((i) => i.status === 'pending');
230
228
  // Reset backoff on successful request
231
229
  this.currentBackoff = this.pollingConfig.interval ?? defaultInterruptPollingConfig.interval;
@@ -8,6 +8,7 @@
8
8
  */
9
9
  import type { PlaygroundSession, PlaygroundMessage, PlaygroundMessagesApiResponse, PlaygroundSessionStatus } from '../types/playground.js';
10
10
  import type { EndpointConfig } from '../config/endpoints.js';
11
+ import type { AuthProvider } from '../types/auth.js';
11
12
  /**
12
13
  * Pagination options for {@link PlaygroundService.getMessages}.
13
14
  * `since`, `before`, and `latest` are mutually exclusive.
@@ -70,7 +71,7 @@ export declare class PlaygroundService {
70
71
  listSessions(endpointConfig: EndpointConfig | null, workflowId: string, options?: {
71
72
  limit?: number;
72
73
  offset?: number;
73
- }): Promise<PlaygroundSession[]>;
74
+ }, authProvider?: AuthProvider): Promise<PlaygroundSession[]>;
74
75
  /**
75
76
  * Create a new playground session
76
77
  *
@@ -79,20 +80,20 @@ export declare class PlaygroundService {
79
80
  * @param metadata - Optional session metadata
80
81
  * @returns The created session
81
82
  */
82
- createSession(endpointConfig: EndpointConfig | null, workflowId: string, name?: string, metadata?: Record<string, unknown>): Promise<PlaygroundSession>;
83
+ createSession(endpointConfig: EndpointConfig | null, workflowId: string, name?: string, metadata?: Record<string, unknown>, authProvider?: AuthProvider): Promise<PlaygroundSession>;
83
84
  /**
84
85
  * Get a playground session by ID
85
86
  *
86
87
  * @param sessionId - The session UUID
87
88
  * @returns The session details
88
89
  */
89
- getSession(endpointConfig: EndpointConfig | null, sessionId: string): Promise<PlaygroundSession>;
90
+ getSession(endpointConfig: EndpointConfig | null, sessionId: string, authProvider?: AuthProvider): Promise<PlaygroundSession>;
90
91
  /**
91
92
  * Delete a playground session
92
93
  *
93
94
  * @param sessionId - The session UUID
94
95
  */
95
- deleteSession(endpointConfig: EndpointConfig | null, sessionId: string): Promise<void>;
96
+ deleteSession(endpointConfig: EndpointConfig | null, sessionId: string, authProvider?: AuthProvider): Promise<void>;
96
97
  /**
97
98
  * Get messages from a playground session.
98
99
  *
@@ -106,7 +107,7 @@ export declare class PlaygroundService {
106
107
  * @param options - Pagination options
107
108
  * @returns Messages and session status
108
109
  */
109
- getMessages(endpointConfig: EndpointConfig | null, sessionId: string, options?: GetMessagesOptions): Promise<PlaygroundMessagesApiResponse>;
110
+ getMessages(endpointConfig: EndpointConfig | null, sessionId: string, options?: GetMessagesOptions, authProvider?: AuthProvider): Promise<PlaygroundMessagesApiResponse>;
110
111
  /**
111
112
  * Send a message to a playground session
112
113
  *
@@ -115,13 +116,13 @@ export declare class PlaygroundService {
115
116
  * @param inputs - Optional additional inputs for workflow nodes
116
117
  * @returns The created message
117
118
  */
118
- sendMessage(endpointConfig: EndpointConfig | null, sessionId: string, content: string, inputs?: Record<string, unknown>): Promise<PlaygroundMessage>;
119
+ sendMessage(endpointConfig: EndpointConfig | null, sessionId: string, content: string, inputs?: Record<string, unknown>, authProvider?: AuthProvider): Promise<PlaygroundMessage>;
119
120
  /**
120
121
  * Stop execution in a playground session
121
122
  *
122
123
  * @param sessionId - The session UUID
123
124
  */
124
- stopExecution(endpointConfig: EndpointConfig | null, sessionId: string): Promise<void>;
125
+ stopExecution(endpointConfig: EndpointConfig | null, sessionId: string, authProvider?: AuthProvider): Promise<void>;
125
126
  /**
126
127
  * Start polling for new messages
127
128
  *
@@ -131,7 +132,7 @@ export declare class PlaygroundService {
131
132
  * @param shouldStopPolling - Optional override for stop conditions (default: defaultShouldStopPolling)
132
133
  * @param initialSequenceNumber - Optional sequence number to seed polling from (avoids re-fetching already loaded messages)
133
134
  */
134
- startPolling(endpointConfig: EndpointConfig | null, sessionId: string, callback: (response: PlaygroundMessagesApiResponse) => void, interval?: number, shouldStopPolling?: (status: PlaygroundSessionStatus) => boolean, initialSequenceNumber?: number | null): void;
135
+ startPolling(endpointConfig: EndpointConfig | null, sessionId: string, callback: (response: PlaygroundMessagesApiResponse) => void, interval?: number, shouldStopPolling?: (status: PlaygroundSessionStatus) => boolean, initialSequenceNumber?: number | null, authProvider?: AuthProvider): void;
135
136
  /**
136
137
  * Stop polling for messages
137
138
  */
@@ -7,7 +7,8 @@
7
7
  * @module services/playgroundService
8
8
  */
9
9
  import { defaultShouldStopPolling } from '../types/playground.js';
10
- import { buildEndpointUrl, getEndpointHeaders } from '../config/endpoints.js';
10
+ import { buildEndpointUrl } from '../config/endpoints.js';
11
+ import { authenticatedFetch } from '../utils/fetchWithAuth.js';
11
12
  import { logger } from '../utils/logger.js';
12
13
  /**
13
14
  * Default polling interval in milliseconds
@@ -64,14 +65,11 @@ export class PlaygroundService {
64
65
  * @param options - Fetch options
65
66
  * @returns The parsed JSON response
66
67
  */
67
- async request(config, url, options = {}) {
68
- const headers = getEndpointHeaders(config, 'playground');
69
- const response = await fetch(url, {
70
- ...options,
71
- headers: {
72
- ...headers,
73
- ...options.headers
74
- }
68
+ async request(config, url, options = {}, authProvider) {
69
+ const response = await authenticatedFetch(url, options, {
70
+ config,
71
+ endpointKey: 'playground',
72
+ authProvider
75
73
  });
76
74
  if (!response.ok) {
77
75
  const errorData = await response.json().catch(() => ({}));
@@ -92,7 +90,7 @@ export class PlaygroundService {
92
90
  * @param options - Optional pagination parameters
93
91
  * @returns Array of playground sessions
94
92
  */
95
- async listSessions(endpointConfig, workflowId, options) {
93
+ async listSessions(endpointConfig, workflowId, options, authProvider) {
96
94
  const config = this.getConfig(endpointConfig);
97
95
  let url = buildEndpointUrl(config, config.endpoints.playground.listSessions, {
98
96
  id: workflowId
@@ -109,7 +107,7 @@ export class PlaygroundService {
109
107
  if (queryString) {
110
108
  url = `${url}?${queryString}`;
111
109
  }
112
- const response = await this.request(config, url);
110
+ const response = await this.request(config, url, {}, authProvider);
113
111
  return response.data ?? [];
114
112
  }
115
113
  /**
@@ -120,7 +118,7 @@ export class PlaygroundService {
120
118
  * @param metadata - Optional session metadata
121
119
  * @returns The created session
122
120
  */
123
- async createSession(endpointConfig, workflowId, name, metadata) {
121
+ async createSession(endpointConfig, workflowId, name, metadata, authProvider) {
124
122
  const config = this.getConfig(endpointConfig);
125
123
  const url = buildEndpointUrl(config, config.endpoints.playground.createSession, {
126
124
  id: workflowId
@@ -128,7 +126,7 @@ export class PlaygroundService {
128
126
  const response = await this.request(config, url, {
129
127
  method: 'POST',
130
128
  body: JSON.stringify({ name, metadata })
131
- });
129
+ }, authProvider);
132
130
  if (!response.data) {
133
131
  throw new Error('Failed to create session: No data returned');
134
132
  }
@@ -140,12 +138,12 @@ export class PlaygroundService {
140
138
  * @param sessionId - The session UUID
141
139
  * @returns The session details
142
140
  */
143
- async getSession(endpointConfig, sessionId) {
141
+ async getSession(endpointConfig, sessionId, authProvider) {
144
142
  const config = this.getConfig(endpointConfig);
145
143
  const url = buildEndpointUrl(config, config.endpoints.playground.getSession, {
146
144
  sessionId
147
145
  });
148
- const response = await this.request(config, url);
146
+ const response = await this.request(config, url, {}, authProvider);
149
147
  if (!response.data) {
150
148
  throw new Error('Session not found');
151
149
  }
@@ -156,14 +154,14 @@ export class PlaygroundService {
156
154
  *
157
155
  * @param sessionId - The session UUID
158
156
  */
159
- async deleteSession(endpointConfig, sessionId) {
157
+ async deleteSession(endpointConfig, sessionId, authProvider) {
160
158
  const config = this.getConfig(endpointConfig);
161
159
  const url = buildEndpointUrl(config, config.endpoints.playground.deleteSession, {
162
160
  sessionId
163
161
  });
164
162
  await this.request(config, url, {
165
163
  method: 'DELETE'
166
- });
164
+ }, authProvider);
167
165
  }
168
166
  // =========================================================================
169
167
  // Message Handling
@@ -181,7 +179,7 @@ export class PlaygroundService {
181
179
  * @param options - Pagination options
182
180
  * @returns Messages and session status
183
181
  */
184
- async getMessages(endpointConfig, sessionId, options = {}) {
182
+ async getMessages(endpointConfig, sessionId, options = {}, authProvider) {
185
183
  const config = this.getConfig(endpointConfig);
186
184
  let url = buildEndpointUrl(config, config.endpoints.playground.getMessages, {
187
185
  sessionId
@@ -203,7 +201,7 @@ export class PlaygroundService {
203
201
  if (queryString) {
204
202
  url = `${url}?${queryString}`;
205
203
  }
206
- return this.request(config, url);
204
+ return this.request(config, url, {}, authProvider);
207
205
  }
208
206
  /**
209
207
  * Send a message to a playground session
@@ -213,7 +211,7 @@ export class PlaygroundService {
213
211
  * @param inputs - Optional additional inputs for workflow nodes
214
212
  * @returns The created message
215
213
  */
216
- async sendMessage(endpointConfig, sessionId, content, inputs) {
214
+ async sendMessage(endpointConfig, sessionId, content, inputs, authProvider) {
217
215
  const config = this.getConfig(endpointConfig);
218
216
  const url = buildEndpointUrl(config, config.endpoints.playground.sendMessage, {
219
217
  sessionId
@@ -225,7 +223,7 @@ export class PlaygroundService {
225
223
  const response = await this.request(config, url, {
226
224
  method: 'POST',
227
225
  body: JSON.stringify(requestBody)
228
- });
226
+ }, authProvider);
229
227
  if (!response.data) {
230
228
  throw new Error('Failed to send message: No data returned');
231
229
  }
@@ -236,14 +234,14 @@ export class PlaygroundService {
236
234
  *
237
235
  * @param sessionId - The session UUID
238
236
  */
239
- async stopExecution(endpointConfig, sessionId) {
237
+ async stopExecution(endpointConfig, sessionId, authProvider) {
240
238
  const config = this.getConfig(endpointConfig);
241
239
  const url = buildEndpointUrl(config, config.endpoints.playground.stopExecution, {
242
240
  sessionId
243
241
  });
244
242
  await this.request(config, url, {
245
243
  method: 'POST'
246
- });
244
+ }, authProvider);
247
245
  }
248
246
  // =========================================================================
249
247
  // Polling
@@ -257,7 +255,7 @@ export class PlaygroundService {
257
255
  * @param shouldStopPolling - Optional override for stop conditions (default: defaultShouldStopPolling)
258
256
  * @param initialSequenceNumber - Optional sequence number to seed polling from (avoids re-fetching already loaded messages)
259
257
  */
260
- startPolling(endpointConfig, sessionId, callback, interval = DEFAULT_POLLING_INTERVAL, shouldStopPolling, initialSequenceNumber) {
258
+ startPolling(endpointConfig, sessionId, callback, interval = DEFAULT_POLLING_INTERVAL, shouldStopPolling, initialSequenceNumber, authProvider) {
261
259
  // Stop any existing polling
262
260
  this.stopPolling();
263
261
  this.pollingSessionId = sessionId;
@@ -271,7 +269,7 @@ export class PlaygroundService {
271
269
  try {
272
270
  const response = await this.getMessages(endpointConfig, sessionId, {
273
271
  since: this.lastSequenceNumber ?? undefined
274
- });
272
+ }, authProvider);
275
273
  // Update last sequence number cursor
276
274
  if (response.data && response.data.length > 0) {
277
275
  const lastMessage = response.data[response.data.length - 1];
@@ -2,7 +2,8 @@
2
2
  * Port Configuration API Service
3
3
  * Handles fetching port configuration 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_PORT_CONFIG } from '../config/defaultPortConfig.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 fetchPortConfig(endpointConfig, authProvider) {
12
13
  try {
13
14
  const url = buildEndpointUrl(endpointConfig, endpointConfig.endpoints.portConfig);
14
- const configHeaders = getEndpointHeaders(endpointConfig, 'portConfig');
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: 'portConfig', authProvider });
19
16
  if (!response.ok) {
20
17
  throw new Error(`HTTP ${response.status}: ${response.statusText}`);
21
18
  }