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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (270) hide show
  1. package/CHANGELOG.md +210 -0
  2. package/MIGRATION-2.0.md +173 -3
  3. package/README.md +5 -5
  4. package/dist/adapters/WorkflowAdapter.js +4 -5
  5. package/dist/adapters/agentspec/AgentSpecAdapter.js +3 -3
  6. package/dist/adapters/agentspec/defaultNodeTypes.js +9 -9
  7. package/dist/api/enhanced-client.js +6 -11
  8. package/dist/chat/batchFeedback.js +1 -1
  9. package/dist/chat/commandClassifier.d.ts +11 -0
  10. package/dist/chat/commandClassifier.js +20 -0
  11. package/dist/chat/historyBuilder.d.ts +39 -0
  12. package/dist/chat/historyBuilder.js +82 -0
  13. package/dist/chat/index.d.ts +2 -1
  14. package/dist/chat/index.js +2 -1
  15. package/dist/chat/responseParser.js +16 -12
  16. package/dist/commands/executor.js +51 -26
  17. package/dist/commands/parser.d.ts +12 -0
  18. package/dist/commands/parser.js +33 -6
  19. package/dist/commands/storeIntegration.svelte.js +11 -1
  20. package/dist/commands/types.js +5 -5
  21. package/dist/components/App.svelte +547 -386
  22. package/dist/components/App.svelte.d.ts +16 -8
  23. package/dist/components/Button.stories.svelte +65 -0
  24. package/dist/components/Button.stories.svelte.d.ts +19 -0
  25. package/dist/components/Button.svelte +62 -0
  26. package/dist/components/Button.svelte.d.ts +24 -0
  27. package/dist/components/CanvasIconButton.svelte +76 -0
  28. package/dist/components/CanvasIconButton.svelte.d.ts +18 -0
  29. package/dist/components/ConfigForm.svelte +194 -565
  30. package/dist/components/ConfigForm.svelte.d.ts +24 -7
  31. package/dist/components/ConfigModal.svelte +9 -1
  32. package/dist/components/ConfigPanel.svelte +234 -15
  33. package/dist/components/ConfigPanel.svelte.d.ts +6 -0
  34. package/dist/components/EditorStatusBar.stories.svelte +44 -0
  35. package/dist/components/EditorStatusBar.stories.svelte.d.ts +27 -0
  36. package/dist/components/EditorStatusBar.svelte +99 -0
  37. package/dist/components/EditorStatusBar.svelte.d.ts +15 -0
  38. package/dist/components/IconButton.svelte +80 -0
  39. package/dist/components/IconButton.svelte.d.ts +30 -0
  40. package/dist/components/Input.svelte +74 -0
  41. package/dist/components/Input.svelte.d.ts +17 -0
  42. package/dist/components/LogoWordmark.svelte +113 -0
  43. package/dist/components/LogoWordmark.svelte.d.ts +26 -0
  44. package/dist/components/Navbar.svelte +17 -63
  45. package/dist/components/Navbar.svelte.d.ts +3 -0
  46. package/dist/components/NodeSidebar.svelte +21 -126
  47. package/dist/components/NodeSwapPicker.svelte +12 -30
  48. package/dist/components/PipelineStatus.svelte +6 -1
  49. package/dist/components/PipelineStatus.svelte.d.ts +3 -0
  50. package/dist/components/PortMappingRow.svelte +0 -2
  51. package/dist/components/SchemaForm.svelte +4 -14
  52. package/dist/components/Select.svelte +53 -0
  53. package/dist/components/Select.svelte.d.ts +15 -0
  54. package/dist/components/SettingsModal.svelte +0 -5
  55. package/dist/components/SettingsPanel.svelte +33 -6
  56. package/dist/components/Textarea.svelte +39 -0
  57. package/dist/components/Textarea.svelte.d.ts +12 -0
  58. package/dist/components/ThemeToggle.svelte +15 -94
  59. package/dist/components/UniversalNode.svelte +36 -4
  60. package/dist/components/UniversalNode.svelte.d.ts +1 -1
  61. package/dist/components/WorkflowEditor.svelte +71 -54
  62. package/dist/components/WorkflowEditor.svelte.d.ts +21 -0
  63. package/dist/components/chat/AIChatPanel.svelte +49 -8
  64. package/dist/components/chat/CommandPreview.svelte +10 -1
  65. package/dist/components/console/ConsoleAutocomplete.svelte +1 -1
  66. package/dist/components/console/ConsoleInput.svelte +3 -3
  67. package/dist/components/console/ConsoleOutput.svelte +2 -2
  68. package/dist/components/form/FormArray.svelte +37 -173
  69. package/dist/components/form/FormAutocomplete.svelte +18 -15
  70. package/dist/components/form/FormCheckboxGroup.svelte +1 -5
  71. package/dist/components/form/FormCodeEditor.svelte +9 -7
  72. package/dist/components/form/FormField.svelte +18 -42
  73. package/dist/components/form/FormFieldLight.svelte +52 -48
  74. package/dist/components/form/FormFieldLight.svelte.d.ts +12 -0
  75. package/dist/components/form/FormFieldset.svelte +45 -11
  76. package/dist/components/form/FormMarkdownEditor.svelte +8 -5
  77. package/dist/components/form/FormNumberField.svelte +4 -36
  78. package/dist/components/form/FormPorts.svelte +280 -0
  79. package/dist/components/form/FormPorts.svelte.d.ts +13 -0
  80. package/dist/components/form/FormRangeField.svelte +63 -30
  81. package/dist/components/form/FormSelect.svelte +13 -75
  82. package/dist/components/form/FormTemplateEditor.svelte +6 -4
  83. package/dist/components/form/FormTextField.svelte +3 -35
  84. package/dist/components/form/FormTextarea.svelte +4 -39
  85. package/dist/components/form/FormToggle.svelte +27 -6
  86. package/dist/components/form/FormToggle.svelte.d.ts +5 -0
  87. package/dist/components/form/FormUISchemaRenderer.svelte +3 -1
  88. package/dist/components/form/resolveFieldType.d.ts +24 -0
  89. package/dist/components/form/resolveFieldType.js +55 -0
  90. package/dist/components/icons/CloseIcon.svelte +6 -0
  91. package/dist/components/icons/CloseIcon.svelte.d.ts +26 -0
  92. package/dist/components/icons/CommandLineIcon.svelte +15 -0
  93. package/dist/components/icons/CommandLineIcon.svelte.d.ts +26 -0
  94. package/dist/components/icons/MenuIcon.svelte +4 -0
  95. package/dist/components/icons/MenuIcon.svelte.d.ts +26 -0
  96. package/dist/components/icons/MenuOpenIcon.svelte +6 -0
  97. package/dist/components/icons/MenuOpenIcon.svelte.d.ts +26 -0
  98. package/dist/components/interrupt/ChoicePrompt.svelte +0 -10
  99. package/dist/components/interrupt/ConfirmationPrompt.svelte +0 -5
  100. package/dist/components/interrupt/InterruptBubble.svelte +11 -12
  101. package/dist/components/interrupt/ReviewPrompt.svelte +0 -20
  102. package/dist/components/interrupt/TextInputPrompt.svelte +0 -6
  103. package/dist/components/layouts/MainLayout.svelte +4 -5
  104. package/dist/components/nodes/AtomNode.svelte +62 -76
  105. package/dist/components/nodes/AtomNode.svelte.d.ts +1 -1
  106. package/dist/components/nodes/GatewayNode.svelte +117 -164
  107. package/dist/components/nodes/GatewayNode.svelte.d.ts +1 -1
  108. package/dist/components/nodes/IdeaNode.svelte +72 -98
  109. package/dist/components/nodes/IdeaNode.svelte.d.ts +8 -4
  110. package/dist/components/nodes/NodeConfigButton.svelte +86 -0
  111. package/dist/components/nodes/NodeConfigButton.svelte.d.ts +15 -0
  112. package/dist/components/nodes/NotesNode.svelte +76 -85
  113. package/dist/components/nodes/NotesNode.svelte.d.ts +8 -4
  114. package/dist/components/nodes/SimpleNode.svelte +59 -133
  115. package/dist/components/nodes/SimpleNode.svelte.d.ts +4 -4
  116. package/dist/components/nodes/SquareNode.svelte +110 -164
  117. package/dist/components/nodes/SquareNode.svelte.d.ts +4 -4
  118. package/dist/components/nodes/TerminalNode.svelte +62 -124
  119. package/dist/components/nodes/TerminalNode.svelte.d.ts +4 -4
  120. package/dist/components/nodes/ToolNode.svelte +92 -103
  121. package/dist/components/nodes/ToolNode.svelte.d.ts +6 -6
  122. package/dist/components/nodes/WorkflowNode.svelte +132 -191
  123. package/dist/components/nodes/WorkflowNode.svelte.d.ts +1 -1
  124. package/dist/components/playground/ChatInput.svelte +316 -27
  125. package/dist/components/playground/ChatInput.svelte.d.ts +31 -1
  126. package/dist/components/playground/ControlPanel.svelte +22 -0
  127. package/dist/components/playground/ControlPanel.svelte.d.ts +13 -0
  128. package/dist/components/playground/InputCollector.svelte +11 -48
  129. package/dist/components/playground/PipelineKanbanView.svelte +6 -4
  130. package/dist/components/playground/PipelineKanbanView.svelte.d.ts +2 -0
  131. package/dist/components/playground/PipelinePanel.svelte +20 -3
  132. package/dist/components/playground/PipelinePanel.svelte.d.ts +2 -0
  133. package/dist/components/playground/PipelineTableView.svelte +6 -4
  134. package/dist/components/playground/PipelineTableView.svelte.d.ts +2 -0
  135. package/dist/components/playground/Playground.svelte +292 -28
  136. package/dist/components/playground/Playground.svelte.d.ts +3 -0
  137. package/dist/components/playground/PlaygroundApp.svelte +6 -1
  138. package/dist/components/playground/PlaygroundApp.svelte.d.ts +3 -0
  139. package/dist/components/playground/PlaygroundModal.svelte +5 -0
  140. package/dist/components/playground/PlaygroundModal.svelte.d.ts +3 -0
  141. package/dist/components/playground/PlaygroundStudio.svelte +7 -6
  142. package/dist/components/playground/PlaygroundStudio.svelte.d.ts +3 -0
  143. package/dist/components/playground/pipelineViewUtils.svelte.d.ts +2 -1
  144. package/dist/components/playground/pipelineViewUtils.svelte.js +2 -2
  145. package/dist/components/surfaces/SurfaceOverlay.svelte +153 -0
  146. package/dist/components/surfaces/SurfaceOverlay.svelte.d.ts +14 -0
  147. package/dist/components/surfaces/TabbedSurface.svelte +133 -0
  148. package/dist/components/surfaces/TabbedSurface.svelte.d.ts +27 -0
  149. package/dist/config/endpoints.d.ts +71 -1
  150. package/dist/config/endpoints.js +46 -5
  151. package/dist/core/index.d.ts +2 -3
  152. package/dist/core/index.js +2 -6
  153. package/dist/display/index.d.ts +6 -1
  154. package/dist/display/index.js +9 -1
  155. package/dist/editor/index.d.ts +1 -1
  156. package/dist/editor/index.js +1 -1
  157. package/dist/form/full.d.ts +2 -1
  158. package/dist/form/full.js +4 -1
  159. package/dist/form/index.d.ts +0 -1
  160. package/dist/form/index.js +3 -2
  161. package/dist/helpers/workflowEditorHelper.d.ts +4 -2
  162. package/dist/helpers/workflowEditorHelper.js +8 -8
  163. package/dist/messages/defaults.d.ts +98 -0
  164. package/dist/messages/defaults.js +58 -1
  165. package/dist/messages/index.d.ts +1 -1
  166. package/dist/messages/index.js +1 -1
  167. package/dist/openapi/v1/openapi.yaml +35 -23
  168. package/dist/playground/commands/args.d.ts +32 -0
  169. package/dist/playground/commands/args.js +50 -0
  170. package/dist/playground/commands/dispatch.d.ts +143 -0
  171. package/dist/playground/commands/dispatch.js +162 -0
  172. package/dist/playground/commands/index.d.ts +14 -0
  173. package/dist/playground/commands/index.js +10 -0
  174. package/dist/playground/commands/parser.d.ts +38 -0
  175. package/dist/playground/commands/parser.js +163 -0
  176. package/dist/playground/commands/registry.d.ts +42 -0
  177. package/dist/playground/commands/registry.js +122 -0
  178. package/dist/playground/commands/suggest.d.ts +37 -0
  179. package/dist/playground/commands/suggest.js +46 -0
  180. package/dist/playground/commands/types.d.ts +111 -0
  181. package/dist/playground/commands/types.js +15 -0
  182. package/dist/playground/index.d.ts +21 -2
  183. package/dist/playground/index.js +27 -2
  184. package/dist/playground/mount.d.ts +19 -5
  185. package/dist/playground/mount.js +16 -8
  186. package/dist/playground/runAction.d.ts +48 -0
  187. package/dist/playground/runAction.js +31 -0
  188. package/dist/registry/builtinNodeTypes.d.ts +53 -0
  189. package/dist/registry/builtinNodeTypes.js +67 -0
  190. package/dist/registry/builtinNodes.d.ts +2 -39
  191. package/dist/registry/builtinNodes.js +6 -53
  192. package/dist/registry/nodeComponentRegistry.d.ts +2 -1
  193. package/dist/schemas/v1/workflow.schema.json +16 -14
  194. package/dist/services/agentSpecExecutionService.d.ts +0 -2
  195. package/dist/services/agentSpecExecutionService.js +0 -2
  196. package/dist/services/apiVariableService.js +12 -26
  197. package/dist/services/categoriesApi.js +3 -6
  198. package/dist/services/chatService.d.ts +4 -3
  199. package/dist/services/chatService.js +13 -18
  200. package/dist/services/dynamicSchemaService.d.ts +31 -4
  201. package/dist/services/dynamicSchemaService.js +62 -33
  202. package/dist/services/historyService.d.ts +30 -8
  203. package/dist/services/historyService.js +51 -15
  204. package/dist/services/interruptService.d.ts +7 -6
  205. package/dist/services/interruptService.js +19 -21
  206. package/dist/services/pipelineSignalService.d.ts +97 -0
  207. package/dist/services/pipelineSignalService.js +94 -0
  208. package/dist/services/playgroundService.d.ts +21 -8
  209. package/dist/services/playgroundService.js +45 -25
  210. package/dist/services/portConfigApi.js +3 -6
  211. package/dist/services/settingsService.d.ts +9 -4
  212. package/dist/services/settingsService.js +23 -12
  213. package/dist/services/workflowLaunchService.d.ts +74 -0
  214. package/dist/services/workflowLaunchService.js +74 -0
  215. package/dist/skins/drafter.d.ts +30 -0
  216. package/dist/skins/drafter.js +198 -0
  217. package/dist/skins/index.d.ts +2 -1
  218. package/dist/skins/index.js +4 -2
  219. package/dist/stores/apiContext.d.ts +11 -0
  220. package/dist/stores/apiContext.js +15 -0
  221. package/dist/stores/categoriesStore.svelte.js +0 -1
  222. package/dist/stores/historyStore.svelte.d.ts +17 -3
  223. package/dist/stores/historyStore.svelte.js +30 -3
  224. package/dist/stores/instanceContainer.svelte.js +5 -0
  225. package/dist/stores/playgroundStore.svelte.js +1 -3
  226. package/dist/stores/settingsStore.svelte.d.ts +13 -0
  227. package/dist/stores/settingsStore.svelte.js +32 -0
  228. package/dist/stores/workflowStore.svelte.d.ts +42 -5
  229. package/dist/stores/workflowStore.svelte.js +109 -32
  230. package/dist/styles/base.css +285 -14
  231. package/dist/styles/tokens.css +60 -2
  232. package/dist/svelte-app.d.ts +18 -1
  233. package/dist/svelte-app.js +75 -110
  234. package/dist/themes/drafter.d.ts +2 -0
  235. package/dist/themes/drafter.js +15 -0
  236. package/dist/themes/index.d.ts +2 -1
  237. package/dist/themes/index.js +8 -2
  238. package/dist/types/auth.d.ts +9 -51
  239. package/dist/types/auth.js +4 -54
  240. package/dist/types/chat.d.ts +5 -1
  241. package/dist/types/events.d.ts +18 -0
  242. package/dist/types/events.js +2 -1
  243. package/dist/types/index.d.ts +84 -29
  244. package/dist/types/index.js +0 -1
  245. package/dist/types/settings.d.ts +28 -1
  246. package/dist/types/settings.js +6 -3
  247. package/dist/types/skin.d.ts +1 -1
  248. package/dist/types/theme.d.ts +16 -2
  249. package/dist/types/uischema.d.ts +5 -0
  250. package/dist/utils/canvasSelection.d.ts +25 -0
  251. package/dist/utils/canvasSelection.js +37 -0
  252. package/dist/utils/colors.d.ts +27 -0
  253. package/dist/utils/colors.js +23 -0
  254. package/dist/utils/connections.js +20 -56
  255. package/dist/utils/edgeStyling.js +9 -5
  256. package/dist/utils/fetchWithAuth.d.ts +36 -15
  257. package/dist/utils/fetchWithAuth.js +53 -23
  258. package/dist/utils/nodeFormSchema.d.ts +51 -0
  259. package/dist/utils/nodeFormSchema.js +87 -0
  260. package/dist/utils/nodeIds.d.ts +1 -1
  261. package/dist/utils/nodeIds.js +1 -1
  262. package/dist/utils/nodeSwap.js +3 -6
  263. package/dist/utils/nodeTypes.js +1 -1
  264. package/dist/utils/portUtils.d.ts +47 -11
  265. package/dist/utils/portUtils.js +67 -14
  266. package/dist/utils/portal.d.ts +18 -0
  267. package/dist/utils/portal.js +34 -0
  268. package/dist/utils/schemaMerge.d.ts +25 -0
  269. package/dist/utils/schemaMerge.js +61 -0
  270. package/package.json +2 -1
@@ -30,7 +30,7 @@ function buildRegistry() {
30
30
  registry.set('start_node', {
31
31
  componentType: 'start_node',
32
32
  metadata: {
33
- id: `${AGENTSPEC_NS}.start_node`,
33
+ node_type_id: `${AGENTSPEC_NS}.start_node`,
34
34
  name: 'Start',
35
35
  type: 'terminal',
36
36
  description: 'Flow entry point. Defines the initial inputs for the flow.',
@@ -55,7 +55,7 @@ function buildRegistry() {
55
55
  registry.set('end_node', {
56
56
  componentType: 'end_node',
57
57
  metadata: {
58
- id: `${AGENTSPEC_NS}.end_node`,
58
+ node_type_id: `${AGENTSPEC_NS}.end_node`,
59
59
  name: 'End',
60
60
  type: 'terminal',
61
61
  description: 'Flow exit point. Defines the final outputs of the flow.',
@@ -80,7 +80,7 @@ function buildRegistry() {
80
80
  registry.set('llm_node', {
81
81
  componentType: 'llm_node',
82
82
  metadata: {
83
- id: `${AGENTSPEC_NS}.llm_node`,
83
+ node_type_id: `${AGENTSPEC_NS}.llm_node`,
84
84
  name: 'LLM',
85
85
  type: 'default',
86
86
  description: 'Generate text using a large language model with configurable prompts.',
@@ -145,7 +145,7 @@ function buildRegistry() {
145
145
  registry.set('branching_node', {
146
146
  componentType: 'branching_node',
147
147
  metadata: {
148
- id: `${AGENTSPEC_NS}.branching_node`,
148
+ node_type_id: `${AGENTSPEC_NS}.branching_node`,
149
149
  name: 'Branch',
150
150
  type: 'gateway',
151
151
  description: 'Route execution to different paths based on conditions.',
@@ -213,7 +213,7 @@ function buildRegistry() {
213
213
  registry.set('tool_node', {
214
214
  componentType: 'tool_node',
215
215
  metadata: {
216
- id: `${AGENTSPEC_NS}.tool_node`,
216
+ node_type_id: `${AGENTSPEC_NS}.tool_node`,
217
217
  name: 'Tool',
218
218
  type: 'tool',
219
219
  description: 'Execute a tool function with inputs and receive outputs.',
@@ -271,7 +271,7 @@ function buildRegistry() {
271
271
  registry.set('api_node', {
272
272
  componentType: 'api_node',
273
273
  metadata: {
274
- id: `${AGENTSPEC_NS}.api_node`,
274
+ node_type_id: `${AGENTSPEC_NS}.api_node`,
275
275
  name: 'API Call',
276
276
  type: 'default',
277
277
  description: 'Make an HTTP API call with configurable endpoint, method, and headers.',
@@ -342,7 +342,7 @@ function buildRegistry() {
342
342
  registry.set('agent_node', {
343
343
  componentType: 'agent_node',
344
344
  metadata: {
345
- id: `${AGENTSPEC_NS}.agent_node`,
345
+ node_type_id: `${AGENTSPEC_NS}.agent_node`,
346
346
  name: 'Agent',
347
347
  type: 'default',
348
348
  description: 'Run a multi-round agent conversation within the flow.',
@@ -400,7 +400,7 @@ function buildRegistry() {
400
400
  registry.set('flow_node', {
401
401
  componentType: 'flow_node',
402
402
  metadata: {
403
- id: `${AGENTSPEC_NS}.flow_node`,
403
+ node_type_id: `${AGENTSPEC_NS}.flow_node`,
404
404
  name: 'Sub-Flow',
405
405
  type: 'simple',
406
406
  description: 'Execute another flow as a sub-routine within this flow.',
@@ -451,7 +451,7 @@ function buildRegistry() {
451
451
  registry.set('map_node', {
452
452
  componentType: 'map_node',
453
453
  metadata: {
454
- id: `${AGENTSPEC_NS}.map_node`,
454
+ node_type_id: `${AGENTSPEC_NS}.map_node`,
455
455
  name: 'Map',
456
456
  type: 'default',
457
457
  description: 'Apply a flow or operation to each item in a collection (map-reduce).',
@@ -5,7 +5,7 @@
5
5
  *
6
6
  * @module api/enhanced-client
7
7
  */
8
- import { buildEndpointUrl, getEndpointMethod, getEndpointHeaders } from '../config/endpoints.js';
8
+ import { buildEndpointUrl, getEndpointMethod, getRequestHeaders } from '../config/endpoints.js';
9
9
  import { NoAuthProvider } from '../types/auth.js';
10
10
  import { getApiSettings } from '../stores/settingsStore.svelte.js';
11
11
  import { logger } from '../utils/logger.js';
@@ -56,15 +56,12 @@ export class EnhancedFlowDropApiClient {
56
56
  async request(endpointKey, endpointPath, params, options = {}, operation = 'API request') {
57
57
  const url = buildEndpointUrl(this.config, endpointPath, params);
58
58
  const method = options.method ?? getEndpointMethod(this.config, endpointKey);
59
- const configHeaders = getEndpointHeaders(this.config, endpointKey);
60
59
  // Get user settings for timeout and retry
61
60
  const userApiSettings = getApiSettings();
62
- // Get auth headers from provider
63
- const authHeaders = await this.authProvider.getAuthHeaders();
64
- // Merge headers: config headers < auth headers < request-specific headers
61
+ // Merge headers via the shared path: static endpoint headers < auth headers
62
+ // < request-specific headers.
65
63
  const headers = {
66
- ...configHeaders,
67
- ...authHeaders,
64
+ ...(await getRequestHeaders(this.config, endpointKey, this.authProvider)),
68
65
  ...options.headers
69
66
  };
70
67
  // Create AbortController for timeout
@@ -93,11 +90,9 @@ export class EnhancedFlowDropApiClient {
93
90
  if (this.authProvider.onUnauthorized) {
94
91
  const refreshed = await this.authProvider.onUnauthorized();
95
92
  if (refreshed && attempt < maxAttempts) {
96
- // Get new auth headers and retry
97
- const newAuthHeaders = await this.authProvider.getAuthHeaders();
93
+ // Rebuild headers via the shared path to pick up the fresh token.
98
94
  fetchConfig.headers = {
99
- ...configHeaders,
100
- ...newAuthHeaders,
95
+ ...(await getRequestHeaders(this.config, endpointKey, this.authProvider)),
101
96
  ...options.headers
102
97
  };
103
98
  continue; // Retry with new headers
@@ -39,7 +39,7 @@ export function buildRetryFeedback(outcome) {
39
39
  const preview = pe.raw.includes('\n') ? `${firstLine} …` : firstLine;
40
40
  lines.push(` • ${preview}\n reason: ${pe.error}`);
41
41
  }
42
- lines.push('\nNote: multiline values must close with """ on its own line.');
42
+ lines.push('\nNote: a multiline value must be closed by a matching """ (on its own line or at the end of the last content line). Escape a literal triple-quote inside the value as \\""".');
43
43
  }
44
44
  if (rolledBack) {
45
45
  lines.push('\nPlease re-send the full corrected batch to achieve the original goal.');
@@ -17,3 +17,14 @@
17
17
  * @returns true if the command modifies workflow state, false if read-only
18
18
  */
19
19
  export declare function isMutatingCommand(commandType: string): boolean;
20
+ /**
21
+ * Determine whether a DSL command type re-arranges existing node positions.
22
+ *
23
+ * Used by the AI panel to honour the `chatAllowLayoutChanges` behaviour setting:
24
+ * when layout changes are disallowed, these commands are skipped instead of
25
+ * executed so a hand-crafted layout survives an assistant batch (issue #36).
26
+ *
27
+ * @param commandType - The command type string (e.g., "beautify_layout")
28
+ * @returns true if the command repositions existing nodes
29
+ */
30
+ export declare function isLayoutCommand(commandType: string): boolean;
@@ -28,3 +28,23 @@ const READ_ONLY_COMMANDS = new Set([
28
28
  export function isMutatingCommand(commandType) {
29
29
  return !READ_ONLY_COMMANDS.has(commandType);
30
30
  }
31
+ /**
32
+ * Commands that rewrite the position of *existing* nodes.
33
+ *
34
+ * Viewport commands (`canvas fitview`, zoom, pan) are deliberately absent —
35
+ * they only move the camera and leave the stored arrangement intact.
36
+ */
37
+ const LAYOUT_COMMANDS = new Set(['auto_layout', 'beautify_layout']);
38
+ /**
39
+ * Determine whether a DSL command type re-arranges existing node positions.
40
+ *
41
+ * Used by the AI panel to honour the `chatAllowLayoutChanges` behaviour setting:
42
+ * when layout changes are disallowed, these commands are skipped instead of
43
+ * executed so a hand-crafted layout survives an assistant batch (issue #36).
44
+ *
45
+ * @param commandType - The command type string (e.g., "beautify_layout")
46
+ * @returns true if the command repositions existing nodes
47
+ */
48
+ export function isLayoutCommand(commandType) {
49
+ return LAYOUT_COMMANDS.has(commandType);
50
+ }
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Conversation history builder for the AI Assistant.
3
+ *
4
+ * The panel's chat log is tuned for humans: the assistant bubble shows only the
5
+ * explanation (the ```flowdrop block is lifted out into the command preview),
6
+ * and whether the user applied or dismissed that preview lives in UI state.
7
+ * Sending that log verbatim to the backend hides two things from the assistant
8
+ * on the next turn — the commands it emitted, and what became of them. It then
9
+ * has to guess whether its previous change landed, and re-emits `add …` for
10
+ * nodes that already exist (issue #35).
11
+ *
12
+ * This module rebuilds the log into API history: the assistant's *raw* response
13
+ * plus an explicit outcome report for every command it emitted.
14
+ *
15
+ * @module chat/historyBuilder
16
+ */
17
+ import type { ChatHistoryMessage, ChatMessageRole, CommandPreviewItem } from '../types/chat.js';
18
+ /** One entry of the panel's chat log, as far as history building cares. */
19
+ export interface ChatLogEntry {
20
+ role: ChatMessageRole;
21
+ /** What the bubble displays — explanation only for assistant messages. */
22
+ content: string;
23
+ /** The unmodified LLM response, when it differs from {@link content}. */
24
+ rawContent?: string;
25
+ /** Commands extracted from this response, with their live status. */
26
+ commandPreview?: CommandPreviewItem[];
27
+ /** Results of read-only commands auto-executed for this response. */
28
+ readOnlyResults?: string[];
29
+ /** Set when the user dismissed the preview instead of applying it. */
30
+ commandsDismissed?: boolean;
31
+ }
32
+ /**
33
+ * Convert the panel's chat log into the history sent to the chat endpoint.
34
+ *
35
+ * Assistant entries carry their raw response (so the assistant sees the DSL it
36
+ * emitted) followed by an outcome report for each command in it. User entries
37
+ * pass through unchanged.
38
+ */
39
+ export declare function buildApiHistory(log: ChatLogEntry[]): ChatHistoryMessage[];
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Conversation history builder for the AI Assistant.
3
+ *
4
+ * The panel's chat log is tuned for humans: the assistant bubble shows only the
5
+ * explanation (the ```flowdrop block is lifted out into the command preview),
6
+ * and whether the user applied or dismissed that preview lives in UI state.
7
+ * Sending that log verbatim to the backend hides two things from the assistant
8
+ * on the next turn — the commands it emitted, and what became of them. It then
9
+ * has to guess whether its previous change landed, and re-emits `add …` for
10
+ * nodes that already exist (issue #35).
11
+ *
12
+ * This module rebuilds the log into API history: the assistant's *raw* response
13
+ * plus an explicit outcome report for every command it emitted.
14
+ *
15
+ * @module chat/historyBuilder
16
+ */
17
+ /** Longest command echo in an outcome line before it is elided. */
18
+ const MAX_COMMAND_ECHO = 160;
19
+ /** Collapse a (possibly multiline) command to one readable line. */
20
+ function echoCommand(raw) {
21
+ const flat = raw.replace(/\s+/g, ' ').trim();
22
+ return flat.length > MAX_COMMAND_ECHO ? `${flat.slice(0, MAX_COMMAND_ECHO)} …` : flat;
23
+ }
24
+ /** Describe what happened to a single previewed command. */
25
+ function describeOutcome(item, dismissed) {
26
+ const echo = echoCommand(item.raw);
27
+ const reason = item.result ? ` — ${item.result}` : '';
28
+ switch (item.status) {
29
+ case 'success':
30
+ return `APPLIED: ${echo}`;
31
+ case 'error':
32
+ return `FAILED, not applied: ${echo}${reason}`;
33
+ case 'skipped':
34
+ return `SKIPPED, not applied: ${echo}${reason}`;
35
+ // 'pending' / 'executing' — the user never resolved the preview, or is
36
+ // resolving it right now. Either way nothing is committed yet.
37
+ default:
38
+ return dismissed
39
+ ? `DISMISSED by the user, not applied: ${echo}`
40
+ : `NOT APPLIED YET (awaiting the user's approval): ${echo}`;
41
+ }
42
+ }
43
+ /**
44
+ * Build the outcome report appended to an assistant message in API history.
45
+ *
46
+ * Returns an empty string when the message emitted no commands.
47
+ */
48
+ function buildOutcomeReport(entry) {
49
+ const sections = [];
50
+ if (entry.commandPreview && entry.commandPreview.length > 0) {
51
+ const dismissed = entry.commandsDismissed === true;
52
+ sections.push([
53
+ '[command outcomes — authoritative. The workflow state in this request already',
54
+ 'includes every APPLIED command; re-sending one would duplicate it. Only commands',
55
+ 'marked not applied still need to be sent.]'
56
+ ].join('\n'));
57
+ for (const item of entry.commandPreview) {
58
+ sections.push(describeOutcome(item, dismissed));
59
+ }
60
+ }
61
+ if (entry.readOnlyResults && entry.readOnlyResults.length > 0) {
62
+ sections.push('[read-only command results]');
63
+ sections.push(...entry.readOnlyResults);
64
+ }
65
+ return sections.length > 0 ? `\n\n${sections.join('\n')}` : '';
66
+ }
67
+ /**
68
+ * Convert the panel's chat log into the history sent to the chat endpoint.
69
+ *
70
+ * Assistant entries carry their raw response (so the assistant sees the DSL it
71
+ * emitted) followed by an outcome report for each command in it. User entries
72
+ * pass through unchanged.
73
+ */
74
+ export function buildApiHistory(log) {
75
+ return log.map((entry) => {
76
+ if (entry.role !== 'assistant') {
77
+ return { role: entry.role, content: entry.content };
78
+ }
79
+ const base = entry.rawContent ?? entry.content;
80
+ return { role: entry.role, content: `${base}${buildOutcomeReport(entry)}` };
81
+ });
82
+ }
@@ -23,5 +23,6 @@
23
23
  export { default as AIChatPanel } from '../components/chat/AIChatPanel.svelte';
24
24
  export { default as CommandPreview } from '../components/chat/CommandPreview.svelte';
25
25
  export { extractCommands } from './responseParser.js';
26
- export { isMutatingCommand } from './commandClassifier.js';
26
+ export { isMutatingCommand, isLayoutCommand } from './commandClassifier.js';
27
+ export { buildApiHistory, type ChatLogEntry } from './historyBuilder.js';
27
28
  export type { ChatMessageRole, ChatHistoryMessage, ChatRequest, ChatResponse, ExtractedCommands, CommandExecutionStatus, CommandPreviewItem } from '../types/chat.js';
@@ -29,4 +29,5 @@ export { default as CommandPreview } from '../components/chat/CommandPreview.sve
29
29
  // Chat Utilities
30
30
  // ============================================================================
31
31
  export { extractCommands } from './responseParser.js';
32
- export { isMutatingCommand } from './commandClassifier.js';
32
+ export { isMutatingCommand, isLayoutCommand } from './commandClassifier.js';
33
+ export { buildApiHistory } from './historyBuilder.js';
@@ -7,6 +7,7 @@
7
7
  *
8
8
  * @module chat/responseParser
9
9
  */
10
+ import { countTripleQuotes } from '../commands/parser.js';
10
11
  /**
11
12
  * Extract DSL commands from an LLM response string.
12
13
  *
@@ -25,22 +26,25 @@ export function extractCommands(llmResponse) {
25
26
  let isFlowdropBlock = false;
26
27
  let currentExplanation = [];
27
28
  let multilineBuffer = null;
29
+ // Running count of unescaped """ delimiters seen since the buffer opened.
30
+ // The block is closed when the count is even again (issue #35).
31
+ let multilineDelimiters = 0;
28
32
  for (const line of lines) {
29
33
  const trimmed = line.trim();
30
34
  // Handle multiline buffer FIRST — prevents code fences inside """...""" from
31
35
  // closing the outer flowdrop block or being misinterpreted as control lines.
32
36
  if (multilineBuffer !== null) {
33
- // Closing """ must be a standalone line (exact match after trimming).
34
- // This prevents content lines that end with """ from prematurely closing
35
- // the block (e.g. `Use Python """docstrings"""` or JSON ending with """).
36
- if (trimmed === '"""') {
37
- multilineBuffer.push(line);
37
+ multilineBuffer.push(line); // preserve raw indentation inside value
38
+ multilineDelimiters += countTripleQuotes(trimmed);
39
+ // Delimiters balance out — the value ended on this line. Parity (rather
40
+ // than "the line is exactly \"\"\"") lets the closer sit at the end of a
41
+ // content line, which is how LLMs actually write it
42
+ // (`set n.1:t """line one\nline two"""`), while a content line carrying a
43
+ // balanced pair (`Use Python """docstrings"""`) keeps the block open.
44
+ if (multilineDelimiters % 2 === 0) {
38
45
  commands.push(multilineBuffer.join('\n'));
39
46
  multilineBuffer = null;
40
47
  }
41
- else {
42
- multilineBuffer.push(line); // preserve raw indentation inside value
43
- }
44
48
  continue;
45
49
  }
46
50
  // Check for code block fence opening/closing
@@ -68,12 +72,12 @@ export function extractCommands(llmResponse) {
68
72
  if (trimmed === '' || trimmed.startsWith('#') || trimmed.startsWith('//')) {
69
73
  continue;
70
74
  }
71
- // Detect opening triple-quote without a closing one on the same line —
75
+ // An odd number of unescaped """ leaves a value open at end of line —
72
76
  // start accumulating a multiline value block
73
- const tripleOpen = trimmed.indexOf('"""');
74
- if (tripleOpen !== -1 && trimmed.indexOf('"""', tripleOpen + 3) === -1) {
75
- // Opening triple-quote with no closing on this line — start buffer
77
+ const delimiters = countTripleQuotes(trimmed);
78
+ if (delimiters % 2 === 1) {
76
79
  multilineBuffer = [trimmed];
80
+ multilineDelimiters = delimiters;
77
81
  continue;
78
82
  }
79
83
  commands.push(trimmed);
@@ -76,7 +76,7 @@ function executeAddNode(command, context) {
76
76
  };
77
77
  }
78
78
  const position = command.position ?? computeAutoPosition(workflow.nodes);
79
- const nodeId = generateNodeId(metadata.id, workflow.nodes);
79
+ const nodeId = generateNodeId(metadata.node_type_id, workflow.nodes);
80
80
  const config = extractConfigDefaults(metadata.configSchema);
81
81
  const node = {
82
82
  id: nodeId,
@@ -86,8 +86,7 @@ function executeAddNode(command, context) {
86
86
  data: {
87
87
  label: metadata.name,
88
88
  config,
89
- metadata,
90
- nodeId
89
+ metadata
91
90
  }
92
91
  };
93
92
  context.dispatch.addNode(node);
@@ -357,7 +356,7 @@ function executeInfo(command, context) {
357
356
  const resultData = {
358
357
  nodeId: shortId,
359
358
  label: node.data.label ?? metadata?.name ?? '',
360
- type: metadata?.id ? toShortTypeId(metadata.id) : '',
359
+ type: metadata?.node_type_id ? toShortTypeId(metadata.node_type_id) : '',
361
360
  position: node.position,
362
361
  config: node.data.config ?? {},
363
362
  inputs,
@@ -379,38 +378,49 @@ function executeInfo(command, context) {
379
378
  */
380
379
  function findPort(node, portId, preferDirection) {
381
380
  const metadata = node.data?.metadata;
382
- if (!metadata)
381
+ const config = node.data?.config;
382
+ if (!metadata && !config)
383
383
  return null;
384
- const outputPort = metadata.outputs?.find((p) => p.id === portId);
385
- const inputPort = metadata.inputs?.find((p) => p.id === portId);
386
- if (preferDirection === 'output') {
387
- if (outputPort)
388
- return { port: outputPort, direction: 'output' };
389
- if (inputPort)
390
- return { port: inputPort, direction: 'input' };
391
- }
392
- else if (preferDirection === 'input') {
384
+ // Resolve an output port from static metadata or config-driven ports. The
385
+ // latter are not in metadata.outputs: gateway branches live in config.branches
386
+ // and user-defined handles live in config.dynamicOutputs (both keyed by name).
387
+ const resolveOutput = () => {
388
+ const meta = metadata?.outputs?.find((p) => p.id === portId);
389
+ if (meta)
390
+ return meta;
391
+ const branch = config?.branches?.find((b) => b.name === portId);
392
+ if (branch)
393
+ return { id: portId, name: branch.label ?? portId, dataType: 'trigger' };
394
+ const dynamic = config?.dynamicOutputs?.find((p) => p.name === portId);
395
+ if (dynamic)
396
+ return { id: portId, name: dynamic.label ?? portId, dataType: dynamic.dataType };
397
+ return null;
398
+ };
399
+ // Resolve an input port from static metadata or config.dynamicInputs.
400
+ const resolveInput = () => {
401
+ const meta = metadata?.inputs?.find((p) => p.id === portId);
402
+ if (meta)
403
+ return meta;
404
+ const dynamic = config?.dynamicInputs?.find((p) => p.name === portId);
405
+ if (dynamic)
406
+ return { id: portId, name: dynamic.label ?? portId, dataType: dynamic.dataType };
407
+ return null;
408
+ };
409
+ const outputPort = resolveOutput();
410
+ const inputPort = resolveInput();
411
+ if (preferDirection === 'input') {
393
412
  if (inputPort)
394
413
  return { port: inputPort, direction: 'input' };
395
414
  if (outputPort)
396
415
  return { port: outputPort, direction: 'output' };
397
416
  }
398
417
  else {
418
+ // Default and explicit 'output' both prefer the output port first.
399
419
  if (outputPort)
400
420
  return { port: outputPort, direction: 'output' };
401
421
  if (inputPort)
402
422
  return { port: inputPort, direction: 'input' };
403
423
  }
404
- // Gateway nodes have dynamic branch ports stored in config.branches, not metadata.outputs
405
- if (metadata.type === 'gateway') {
406
- const branches = node.data.config?.branches;
407
- if (branches?.some((b) => b.name === portId)) {
408
- return {
409
- port: { id: portId, name: portId, dataType: 'trigger' },
410
- direction: 'output'
411
- };
412
- }
413
- }
414
424
  return null;
415
425
  }
416
426
  function executeConnect(command, context) {
@@ -484,6 +494,21 @@ function executeConnect(command, context) {
484
494
  const targetHandle = buildHandleId(targetNode.id, 'input', command.targetPort);
485
495
  // Generate edge ID
486
496
  const edgeId = `${sourceNode.id}-${sourceHandle}-${targetNode.id}-${targetHandle}`;
497
+ // Idempotency guard: re-applying the same connection (e.g. a second
498
+ // AI-assistant Apply that re-emits an existing edge) must not append a
499
+ // duplicate. Two edges sharing an id crash the canvas with Svelte's
500
+ // `each_key_duplicate`. Treat an existing identical connection as a no-op.
501
+ const alreadyConnected = workflow.edges.some((e) => e.id === edgeId ||
502
+ (e.source === sourceNode.id &&
503
+ e.target === targetNode.id &&
504
+ e.sourceHandle === sourceHandle &&
505
+ e.targetHandle === targetHandle));
506
+ if (alreadyConnected) {
507
+ return {
508
+ ok: true,
509
+ message: `Already connected ${toShortId(sourceNode.id)}:${command.sourcePort} → ${toShortId(targetNode.id)}:${command.targetPort}`
510
+ };
511
+ }
487
512
  // Build edge
488
513
  const edge = {
489
514
  id: edgeId,
@@ -578,7 +603,7 @@ function executeListNodes(context) {
578
603
  const nodes = workflow.nodes.map((n) => ({
579
604
  nodeId: toShortId(n.id),
580
605
  label: n.data.label ?? n.data.metadata?.name ?? '',
581
- type: n.data.metadata?.id ? toShortTypeId(n.data.metadata.id) : ''
606
+ type: n.data.metadata?.node_type_id ? toShortTypeId(n.data.metadata.node_type_id) : ''
582
607
  }));
583
608
  const resultData = { nodes };
584
609
  return {
@@ -610,7 +635,7 @@ function executeListEdges(context) {
610
635
  }
611
636
  function executeListTypes(context) {
612
637
  const types = context.nodeTypes.map((m) => ({
613
- typeId: toShortTypeId(m.id),
638
+ typeId: toShortTypeId(m.node_type_id),
614
639
  name: m.name,
615
640
  category: m.category
616
641
  }));
@@ -7,6 +7,18 @@
7
7
  * @module commands/parser
8
8
  */
9
9
  import type { ParseResult } from './types.js';
10
+ /**
11
+ * Count the `"""` delimiters in a string, ignoring escaped ones.
12
+ *
13
+ * `\"""` is the escape for a literal triple-quote inside a value (unescaped
14
+ * when the value is parsed), so it is content, not a delimiter. Occurrences are
15
+ * counted non-overlapping, left to right — an odd total means a value was left
16
+ * open.
17
+ *
18
+ * Shared with the chat response parser, which uses the same parity rule to
19
+ * decide where a multiline value ends.
20
+ */
21
+ export declare function countTripleQuotes(input: string): number;
10
22
  /**
11
23
  * Parse a command string into a typed Command object.
12
24
  *
@@ -6,6 +6,33 @@
6
6
  *
7
7
  * @module commands/parser
8
8
  */
9
+ /**
10
+ * Count the `"""` delimiters in a string, ignoring escaped ones.
11
+ *
12
+ * `\"""` is the escape for a literal triple-quote inside a value (unescaped
13
+ * when the value is parsed), so it is content, not a delimiter. Occurrences are
14
+ * counted non-overlapping, left to right — an odd total means a value was left
15
+ * open.
16
+ *
17
+ * Shared with the chat response parser, which uses the same parity rule to
18
+ * decide where a multiline value ends.
19
+ */
20
+ export function countTripleQuotes(input) {
21
+ let count = 0;
22
+ let i = 0;
23
+ while (i <= input.length - 3) {
24
+ if (input.startsWith('"""', i)) {
25
+ if (i === 0 || input[i - 1] !== '\\') {
26
+ count++;
27
+ }
28
+ i += 3;
29
+ }
30
+ else {
31
+ i++;
32
+ }
33
+ }
34
+ return count;
35
+ }
9
36
  /**
10
37
  * Parse a coordinate pair like "200,300" or "-50, 100"
11
38
  */
@@ -260,14 +287,14 @@ export function parseCommand(input) {
260
287
  return { ok: false, error: 'Empty command', input };
261
288
  }
262
289
  // Detect an unclosed multiline """ block — common when a low-quality LLM
263
- // omits the closing """ on its own line. The opener pattern is `"""\n`
264
- // (triple-quote followed by a newline), and a well-formed value must end
265
- // with `"""`. If we see the opener but not the closer, surface a clear
266
- // error instead of falling through to a generic "Invalid syntax".
267
- if (trimmed.includes('"""\n') && !trimmed.endsWith('"""')) {
290
+ // omits the closing """. Delimiters come in pairs (escaped `\"""` excluded),
291
+ // so an odd count means a value was left open, whether it was opened on its
292
+ // own line or inline after the key. Surface a clear error instead of falling
293
+ // through to a generic "Invalid syntax".
294
+ if (countTripleQuotes(trimmed) % 2 === 1) {
268
295
  return {
269
296
  ok: false,
270
- error: 'Unclosed """ block — missing closing """ on its own line',
297
+ error: 'Unclosed """ block — no matching closing """',
271
298
  input
272
299
  };
273
300
  }
@@ -32,6 +32,8 @@ export function createStoreCommandContext(nodeTypes, onUIAction, instance) {
32
32
  removeEdge: (edgeId) => actions.removeEdge(edgeId),
33
33
  batchUpdate: (updates) => actions.batchUpdate(updates),
34
34
  undo: () => {
35
+ // Flush a pending edit session into a committed step before undoing it.
36
+ actions.finalizeNodeConfig();
35
37
  const previousState = history.undo();
36
38
  if (previousState) {
37
39
  actions.restoreFromHistory(previousState);
@@ -40,6 +42,7 @@ export function createStoreCommandContext(nodeTypes, onUIAction, instance) {
40
42
  return false;
41
43
  },
42
44
  redo: () => {
45
+ actions.finalizeNodeConfig();
43
46
  const nextState = history.redo();
44
47
  if (nextState) {
45
48
  actions.restoreFromHistory(nextState);
@@ -53,7 +56,14 @@ export function createStoreCommandContext(nodeTypes, onUIAction, instance) {
53
56
  history.startTransaction(currentWorkflow, description);
54
57
  }
55
58
  },
56
- commitTransaction: () => history.commitTransaction(),
59
+ // Commit the transaction's post-change (current) state so one undo reverts
60
+ // the whole batch and redo restores its result (issue #39).
61
+ commitTransaction: () => {
62
+ const currentWorkflow = readWorkflow();
63
+ if (currentWorkflow) {
64
+ history.commitTransaction(currentWorkflow);
65
+ }
66
+ },
57
67
  cancelTransaction: () => {
58
68
  const snapshot = history.cancelTransaction();
59
69
  if (snapshot) {
@@ -24,18 +24,18 @@ export function buildTypeMap(nodeTypes) {
24
24
  const shortIdCounts = new Map();
25
25
  // First pass: register full IDs and count short ID occurrences
26
26
  for (const metadata of nodeTypes) {
27
- map.set(metadata.id, metadata);
28
- const dotIndex = metadata.id.indexOf('.');
27
+ map.set(metadata.node_type_id, metadata);
28
+ const dotIndex = metadata.node_type_id.indexOf('.');
29
29
  if (dotIndex !== -1) {
30
- const shortId = metadata.id.substring(dotIndex + 1);
30
+ const shortId = metadata.node_type_id.substring(dotIndex + 1);
31
31
  shortIdCounts.set(shortId, (shortIdCounts.get(shortId) ?? 0) + 1);
32
32
  }
33
33
  }
34
34
  // Second pass: register unique short IDs
35
35
  for (const metadata of nodeTypes) {
36
- const dotIndex = metadata.id.indexOf('.');
36
+ const dotIndex = metadata.node_type_id.indexOf('.');
37
37
  if (dotIndex !== -1) {
38
- const shortId = metadata.id.substring(dotIndex + 1);
38
+ const shortId = metadata.node_type_id.substring(dotIndex + 1);
39
39
  if (shortIdCounts.get(shortId) === 1) {
40
40
  map.set(shortId, metadata);
41
41
  }