@foresthubai/workflow-builder 0.3.0

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 (496) hide show
  1. package/LICENSE +661 -0
  2. package/NOTICE +16 -0
  3. package/README.md +93 -0
  4. package/dist/BuilderLayout.d.ts +34 -0
  5. package/dist/BuilderLayout.d.ts.map +1 -0
  6. package/dist/BuilderLayout.js +172 -0
  7. package/dist/BuilderLayout.js.map +1 -0
  8. package/dist/Canvas.d.ts +23 -0
  9. package/dist/Canvas.d.ts.map +1 -0
  10. package/dist/Canvas.js +141 -0
  11. package/dist/Canvas.js.map +1 -0
  12. package/dist/CanvasEditor.d.ts +46 -0
  13. package/dist/CanvasEditor.d.ts.map +1 -0
  14. package/dist/CanvasEditor.js +57 -0
  15. package/dist/CanvasEditor.js.map +1 -0
  16. package/dist/CanvasTabsToolbar.d.ts +11 -0
  17. package/dist/CanvasTabsToolbar.d.ts.map +1 -0
  18. package/dist/CanvasTabsToolbar.js +101 -0
  19. package/dist/CanvasTabsToolbar.js.map +1 -0
  20. package/dist/RightConfigPanel.d.ts +27 -0
  21. package/dist/RightConfigPanel.d.ts.map +1 -0
  22. package/dist/RightConfigPanel.js +102 -0
  23. package/dist/RightConfigPanel.js.map +1 -0
  24. package/dist/WorkflowBuilder.d.ts +62 -0
  25. package/dist/WorkflowBuilder.d.ts.map +1 -0
  26. package/dist/WorkflowBuilder.js +275 -0
  27. package/dist/WorkflowBuilder.js.map +1 -0
  28. package/dist/cn.d.ts +3 -0
  29. package/dist/cn.d.ts.map +1 -0
  30. package/dist/cn.js +6 -0
  31. package/dist/cn.js.map +1 -0
  32. package/dist/components/ui/add-button.d.ts +16 -0
  33. package/dist/components/ui/add-button.d.ts.map +1 -0
  34. package/dist/components/ui/add-button.js +21 -0
  35. package/dist/components/ui/add-button.js.map +1 -0
  36. package/dist/components/ui/alert-dialog.d.ts +21 -0
  37. package/dist/components/ui/alert-dialog.d.ts.map +1 -0
  38. package/dist/components/ui/alert-dialog.js +30 -0
  39. package/dist/components/ui/alert-dialog.js.map +1 -0
  40. package/dist/components/ui/alert.d.ts +9 -0
  41. package/dist/components/ui/alert.d.ts.map +1 -0
  42. package/dist/components/ui/alert.js +23 -0
  43. package/dist/components/ui/alert.js.map +1 -0
  44. package/dist/components/ui/badge.d.ts +10 -0
  45. package/dist/components/ui/badge.d.ts.map +1 -0
  46. package/dist/components/ui/badge.js +21 -0
  47. package/dist/components/ui/badge.js.map +1 -0
  48. package/dist/components/ui/button.d.ts +13 -0
  49. package/dist/components/ui/button.d.ts.map +1 -0
  50. package/dist/components/ui/button.js +40 -0
  51. package/dist/components/ui/button.js.map +1 -0
  52. package/dist/components/ui/card.d.ts +9 -0
  53. package/dist/components/ui/card.d.ts.map +1 -0
  54. package/dist/components/ui/card.js +17 -0
  55. package/dist/components/ui/card.js.map +1 -0
  56. package/dist/components/ui/checkbox.d.ts +5 -0
  57. package/dist/components/ui/checkbox.d.ts.map +1 -0
  58. package/dist/components/ui/checkbox.js +9 -0
  59. package/dist/components/ui/checkbox.js.map +1 -0
  60. package/dist/components/ui/collapsible.d.ts +6 -0
  61. package/dist/components/ui/collapsible.d.ts.map +1 -0
  62. package/dist/components/ui/collapsible.js +6 -0
  63. package/dist/components/ui/collapsible.js.map +1 -0
  64. package/dist/components/ui/command.d.ts +82 -0
  65. package/dist/components/ui/command.d.ts.map +1 -0
  66. package/dist/components/ui/command.js +29 -0
  67. package/dist/components/ui/command.js.map +1 -0
  68. package/dist/components/ui/delete-button.d.ts +11 -0
  69. package/dist/components/ui/delete-button.d.ts.map +1 -0
  70. package/dist/components/ui/delete-button.js +14 -0
  71. package/dist/components/ui/delete-button.js.map +1 -0
  72. package/dist/components/ui/dialog.d.ts +22 -0
  73. package/dist/components/ui/dialog.d.ts.map +1 -0
  74. package/dist/components/ui/dialog.js +27 -0
  75. package/dist/components/ui/dialog.js.map +1 -0
  76. package/dist/components/ui/dropdown-menu.d.ts +28 -0
  77. package/dist/components/ui/dropdown-menu.d.ts.map +1 -0
  78. package/dist/components/ui/dropdown-menu.js +36 -0
  79. package/dist/components/ui/dropdown-menu.js.map +1 -0
  80. package/dist/components/ui/input.d.ts +13 -0
  81. package/dist/components/ui/input.d.ts.map +1 -0
  82. package/dist/components/ui/input.js +34 -0
  83. package/dist/components/ui/input.js.map +1 -0
  84. package/dist/components/ui/label.d.ts +6 -0
  85. package/dist/components/ui/label.d.ts.map +1 -0
  86. package/dist/components/ui/label.js +10 -0
  87. package/dist/components/ui/label.js.map +1 -0
  88. package/dist/components/ui/readonly-banner.d.ts +7 -0
  89. package/dist/components/ui/readonly-banner.d.ts.map +1 -0
  90. package/dist/components/ui/readonly-banner.js +12 -0
  91. package/dist/components/ui/readonly-banner.js.map +1 -0
  92. package/dist/components/ui/resizable.d.ts +24 -0
  93. package/dist/components/ui/resizable.d.ts.map +1 -0
  94. package/dist/components/ui/resizable.js +9 -0
  95. package/dist/components/ui/resizable.js.map +1 -0
  96. package/dist/components/ui/scroll-area.d.ts +45 -0
  97. package/dist/components/ui/scroll-area.d.ts.map +1 -0
  98. package/dist/components/ui/scroll-area.js +27 -0
  99. package/dist/components/ui/scroll-area.js.map +1 -0
  100. package/dist/components/ui/select.d.ts +14 -0
  101. package/dist/components/ui/select.d.ts.map +1 -0
  102. package/dist/components/ui/select.js +30 -0
  103. package/dist/components/ui/select.js.map +1 -0
  104. package/dist/components/ui/separator.d.ts +5 -0
  105. package/dist/components/ui/separator.d.ts.map +1 -0
  106. package/dist/components/ui/separator.js +8 -0
  107. package/dist/components/ui/separator.js.map +1 -0
  108. package/dist/components/ui/switch.d.ts +5 -0
  109. package/dist/components/ui/switch.d.ts.map +1 -0
  110. package/dist/components/ui/switch.js +8 -0
  111. package/dist/components/ui/switch.js.map +1 -0
  112. package/dist/components/ui/textarea.d.ts +12 -0
  113. package/dist/components/ui/textarea.d.ts.map +1 -0
  114. package/dist/components/ui/textarea.js +34 -0
  115. package/dist/components/ui/textarea.js.map +1 -0
  116. package/dist/components/ui/toast.d.ts +16 -0
  117. package/dist/components/ui/toast.d.ts.map +1 -0
  118. package/dist/components/ui/toast.js +34 -0
  119. package/dist/components/ui/toast.js.map +1 -0
  120. package/dist/components/ui/toaster.d.ts +2 -0
  121. package/dist/components/ui/toaster.d.ts.map +1 -0
  122. package/dist/components/ui/toaster.js +10 -0
  123. package/dist/components/ui/toaster.js.map +1 -0
  124. package/dist/components/ui/toggle-group.d.ts +13 -0
  125. package/dist/components/ui/toggle-group.d.ts.map +1 -0
  126. package/dist/components/ui/toggle-group.js +21 -0
  127. package/dist/components/ui/toggle-group.js.map +1 -0
  128. package/dist/components/ui/toggle.d.ts +13 -0
  129. package/dist/components/ui/toggle.d.ts.map +1 -0
  130. package/dist/components/ui/toggle.js +26 -0
  131. package/dist/components/ui/toggle.js.map +1 -0
  132. package/dist/components/ui/tooltip.d.ts +8 -0
  133. package/dist/components/ui/tooltip.d.ts.map +1 -0
  134. package/dist/components/ui/tooltip.js +14 -0
  135. package/dist/components/ui/tooltip.js.map +1 -0
  136. package/dist/dialogs/NodePickerDialog.d.ts +10 -0
  137. package/dist/dialogs/NodePickerDialog.d.ts.map +1 -0
  138. package/dist/dialogs/NodePickerDialog.js +39 -0
  139. package/dist/dialogs/NodePickerDialog.js.map +1 -0
  140. package/dist/dialogs/ValidationDialog.d.ts +17 -0
  141. package/dist/dialogs/ValidationDialog.d.ts.map +1 -0
  142. package/dist/dialogs/ValidationDialog.js +29 -0
  143. package/dist/dialogs/ValidationDialog.js.map +1 -0
  144. package/dist/graph/BaseNode.d.ts +9 -0
  145. package/dist/graph/BaseNode.d.ts.map +1 -0
  146. package/dist/graph/BaseNode.js +318 -0
  147. package/dist/graph/BaseNode.js.map +1 -0
  148. package/dist/graph/CustomEdge.d.ts +14 -0
  149. package/dist/graph/CustomEdge.d.ts.map +1 -0
  150. package/dist/graph/CustomEdge.js +107 -0
  151. package/dist/graph/CustomEdge.js.map +1 -0
  152. package/dist/graph/CustomNode.d.ts +3 -0
  153. package/dist/graph/CustomNode.d.ts.map +1 -0
  154. package/dist/graph/CustomNode.js +15 -0
  155. package/dist/graph/CustomNode.js.map +1 -0
  156. package/dist/graph/FunctionCallNode.d.ts +3 -0
  157. package/dist/graph/FunctionCallNode.d.ts.map +1 -0
  158. package/dist/graph/FunctionCallNode.js +25 -0
  159. package/dist/graph/FunctionCallNode.js.map +1 -0
  160. package/dist/graph/PortHandle.d.ts +21 -0
  161. package/dist/graph/PortHandle.d.ts.map +1 -0
  162. package/dist/graph/PortHandle.js +113 -0
  163. package/dist/graph/PortHandle.js.map +1 -0
  164. package/dist/graph/reactFlowRegistry.d.ts +65 -0
  165. package/dist/graph/reactFlowRegistry.d.ts.map +1 -0
  166. package/dist/graph/reactFlowRegistry.js +24 -0
  167. package/dist/graph/reactFlowRegistry.js.map +1 -0
  168. package/dist/hooks/use-toast.d.ts +47 -0
  169. package/dist/hooks/use-toast.d.ts.map +1 -0
  170. package/dist/hooks/use-toast.js +95 -0
  171. package/dist/hooks/use-toast.js.map +1 -0
  172. package/dist/hooks/useAvailableVariables.d.ts +12 -0
  173. package/dist/hooks/useAvailableVariables.d.ts.map +1 -0
  174. package/dist/hooks/useAvailableVariables.js +16 -0
  175. package/dist/hooks/useAvailableVariables.js.map +1 -0
  176. package/dist/hooks/useCanvasHistory.d.ts +14 -0
  177. package/dist/hooks/useCanvasHistory.d.ts.map +1 -0
  178. package/dist/hooks/useCanvasHistory.js +20 -0
  179. package/dist/hooks/useCanvasHistory.js.map +1 -0
  180. package/dist/hooks/useCanvasTabs.d.ts +23 -0
  181. package/dist/hooks/useCanvasTabs.d.ts.map +1 -0
  182. package/dist/hooks/useCanvasTabs.js +136 -0
  183. package/dist/hooks/useCanvasTabs.js.map +1 -0
  184. package/dist/hooks/useFunctionDiagnosticsSync.d.ts +14 -0
  185. package/dist/hooks/useFunctionDiagnosticsSync.d.ts.map +1 -0
  186. package/dist/hooks/useFunctionDiagnosticsSync.js +38 -0
  187. package/dist/hooks/useFunctionDiagnosticsSync.js.map +1 -0
  188. package/dist/hooks/useFunctionRegistry.d.ts +15 -0
  189. package/dist/hooks/useFunctionRegistry.d.ts.map +1 -0
  190. package/dist/hooks/useFunctionRegistry.js +22 -0
  191. package/dist/hooks/useFunctionRegistry.js.map +1 -0
  192. package/dist/hooks/useFunctions.d.ts +15 -0
  193. package/dist/hooks/useFunctions.d.ts.map +1 -0
  194. package/dist/hooks/useFunctions.js +34 -0
  195. package/dist/hooks/useFunctions.js.map +1 -0
  196. package/dist/hooks/useGraph.d.ts +40 -0
  197. package/dist/hooks/useGraph.d.ts.map +1 -0
  198. package/dist/hooks/useGraph.js +102 -0
  199. package/dist/hooks/useGraph.js.map +1 -0
  200. package/dist/hooks/useNodeDefinitions.d.ts +17 -0
  201. package/dist/hooks/useNodeDefinitions.d.ts.map +1 -0
  202. package/dist/hooks/useNodeDefinitions.js +65 -0
  203. package/dist/hooks/useNodeDefinitions.js.map +1 -0
  204. package/dist/hooks/useParamErrors.d.ts +12 -0
  205. package/dist/hooks/useParamErrors.d.ts.map +1 -0
  206. package/dist/hooks/useParamErrors.js +28 -0
  207. package/dist/hooks/useParamErrors.js.map +1 -0
  208. package/dist/hooks/useResolvedTheme.d.ts +10 -0
  209. package/dist/hooks/useResolvedTheme.d.ts.map +1 -0
  210. package/dist/hooks/useResolvedTheme.js +29 -0
  211. package/dist/hooks/useResolvedTheme.js.map +1 -0
  212. package/dist/hooks/useResourceDiagnosticsSync.d.ts +40 -0
  213. package/dist/hooks/useResourceDiagnosticsSync.d.ts.map +1 -0
  214. package/dist/hooks/useResourceDiagnosticsSync.js +39 -0
  215. package/dist/hooks/useResourceDiagnosticsSync.js.map +1 -0
  216. package/dist/hooks/useSuppressThemeTransition.d.ts +32 -0
  217. package/dist/hooks/useSuppressThemeTransition.d.ts.map +1 -0
  218. package/dist/hooks/useSuppressThemeTransition.js +75 -0
  219. package/dist/hooks/useSuppressThemeTransition.js.map +1 -0
  220. package/dist/hooks/useWorkflowSerialization.d.ts +24 -0
  221. package/dist/hooks/useWorkflowSerialization.d.ts.map +1 -0
  222. package/dist/hooks/useWorkflowSerialization.js +113 -0
  223. package/dist/hooks/useWorkflowSerialization.js.map +1 -0
  224. package/dist/i18n/index.d.ts +4 -0
  225. package/dist/i18n/index.d.ts.map +1 -0
  226. package/dist/i18n/index.js +46 -0
  227. package/dist/i18n/index.js.map +1 -0
  228. package/dist/i18n/locales/de.json +501 -0
  229. package/dist/i18n/locales/en.json +557 -0
  230. package/dist/index.d.ts +9 -0
  231. package/dist/index.d.ts.map +1 -0
  232. package/dist/index.js +12 -0
  233. package/dist/index.js.map +1 -0
  234. package/dist/inputs/ExpressionInput.d.ts +12 -0
  235. package/dist/inputs/ExpressionInput.d.ts.map +1 -0
  236. package/dist/inputs/ExpressionInput.js +203 -0
  237. package/dist/inputs/ExpressionInput.js.map +1 -0
  238. package/dist/inputs/ParameterEditor.d.ts +13 -0
  239. package/dist/inputs/ParameterEditor.d.ts.map +1 -0
  240. package/dist/inputs/ParameterEditor.js +204 -0
  241. package/dist/inputs/ParameterEditor.js.map +1 -0
  242. package/dist/inputs/PortSection.d.ts +31 -0
  243. package/dist/inputs/PortSection.d.ts.map +1 -0
  244. package/dist/inputs/PortSection.js +26 -0
  245. package/dist/inputs/PortSection.js.map +1 -0
  246. package/dist/panels/BuilderSidebar.d.ts +24 -0
  247. package/dist/panels/BuilderSidebar.d.ts.map +1 -0
  248. package/dist/panels/BuilderSidebar.js +202 -0
  249. package/dist/panels/BuilderSidebar.js.map +1 -0
  250. package/dist/panels/ChannelConfigPanel.d.ts +8 -0
  251. package/dist/panels/ChannelConfigPanel.d.ts.map +1 -0
  252. package/dist/panels/ChannelConfigPanel.js +26 -0
  253. package/dist/panels/ChannelConfigPanel.js.map +1 -0
  254. package/dist/panels/ChannelsPanel.d.ts +2 -0
  255. package/dist/panels/ChannelsPanel.d.ts.map +1 -0
  256. package/dist/panels/ChannelsPanel.js +16 -0
  257. package/dist/panels/ChannelsPanel.js.map +1 -0
  258. package/dist/panels/DebugConsolePanel.d.ts +2 -0
  259. package/dist/panels/DebugConsolePanel.d.ts.map +1 -0
  260. package/dist/panels/DebugConsolePanel.js +32 -0
  261. package/dist/panels/DebugConsolePanel.js.map +1 -0
  262. package/dist/panels/DebugContextPanel.d.ts +2 -0
  263. package/dist/panels/DebugContextPanel.d.ts.map +1 -0
  264. package/dist/panels/DebugContextPanel.js +32 -0
  265. package/dist/panels/DebugContextPanel.js.map +1 -0
  266. package/dist/panels/DebugExternalIOPanel.d.ts +9 -0
  267. package/dist/panels/DebugExternalIOPanel.d.ts.map +1 -0
  268. package/dist/panels/DebugExternalIOPanel.js +66 -0
  269. package/dist/panels/DebugExternalIOPanel.js.map +1 -0
  270. package/dist/panels/DiagnosticsPanel.d.ts +8 -0
  271. package/dist/panels/DiagnosticsPanel.d.ts.map +1 -0
  272. package/dist/panels/DiagnosticsPanel.js +86 -0
  273. package/dist/panels/DiagnosticsPanel.js.map +1 -0
  274. package/dist/panels/EdgeConfigPanel.d.ts +14 -0
  275. package/dist/panels/EdgeConfigPanel.d.ts.map +1 -0
  276. package/dist/panels/EdgeConfigPanel.js +34 -0
  277. package/dist/panels/EdgeConfigPanel.js.map +1 -0
  278. package/dist/panels/FunctionConfigPanel.d.ts +16 -0
  279. package/dist/panels/FunctionConfigPanel.d.ts.map +1 -0
  280. package/dist/panels/FunctionConfigPanel.js +62 -0
  281. package/dist/panels/FunctionConfigPanel.js.map +1 -0
  282. package/dist/panels/FunctionListPanel.d.ts +14 -0
  283. package/dist/panels/FunctionListPanel.d.ts.map +1 -0
  284. package/dist/panels/FunctionListPanel.js +25 -0
  285. package/dist/panels/FunctionListPanel.js.map +1 -0
  286. package/dist/panels/MemoryConfigPanel.d.ts +8 -0
  287. package/dist/panels/MemoryConfigPanel.d.ts.map +1 -0
  288. package/dist/panels/MemoryConfigPanel.js +22 -0
  289. package/dist/panels/MemoryConfigPanel.js.map +1 -0
  290. package/dist/panels/MemoryPanel.d.ts +2 -0
  291. package/dist/panels/MemoryPanel.d.ts.map +1 -0
  292. package/dist/panels/MemoryPanel.js +25 -0
  293. package/dist/panels/MemoryPanel.js.map +1 -0
  294. package/dist/panels/ModelConfigPanel.d.ts +8 -0
  295. package/dist/panels/ModelConfigPanel.d.ts.map +1 -0
  296. package/dist/panels/ModelConfigPanel.js +14 -0
  297. package/dist/panels/ModelConfigPanel.js.map +1 -0
  298. package/dist/panels/ModelsPanel.d.ts +8 -0
  299. package/dist/panels/ModelsPanel.d.ts.map +1 -0
  300. package/dist/panels/ModelsPanel.js +24 -0
  301. package/dist/panels/ModelsPanel.js.map +1 -0
  302. package/dist/panels/NodeConfigPanel.d.ts +16 -0
  303. package/dist/panels/NodeConfigPanel.d.ts.map +1 -0
  304. package/dist/panels/NodeConfigPanel.js +248 -0
  305. package/dist/panels/NodeConfigPanel.js.map +1 -0
  306. package/dist/panels/NodeLibrary.d.ts +16 -0
  307. package/dist/panels/NodeLibrary.d.ts.map +1 -0
  308. package/dist/panels/NodeLibrary.js +125 -0
  309. package/dist/panels/NodeLibrary.js.map +1 -0
  310. package/dist/panels/ResourceConfigPanel.d.ts +37 -0
  311. package/dist/panels/ResourceConfigPanel.d.ts.map +1 -0
  312. package/dist/panels/ResourceConfigPanel.js +35 -0
  313. package/dist/panels/ResourceConfigPanel.js.map +1 -0
  314. package/dist/panels/ResourceListPanel.d.ts +35 -0
  315. package/dist/panels/ResourceListPanel.d.ts.map +1 -0
  316. package/dist/panels/ResourceListPanel.js +35 -0
  317. package/dist/panels/ResourceListPanel.js.map +1 -0
  318. package/dist/panels/VariableConfigPanel.d.ts +9 -0
  319. package/dist/panels/VariableConfigPanel.d.ts.map +1 -0
  320. package/dist/panels/VariableConfigPanel.js +50 -0
  321. package/dist/panels/VariableConfigPanel.js.map +1 -0
  322. package/dist/panels/VariablesPanel.d.ts +7 -0
  323. package/dist/panels/VariablesPanel.d.ts.map +1 -0
  324. package/dist/panels/VariablesPanel.js +56 -0
  325. package/dist/panels/VariablesPanel.js.map +1 -0
  326. package/dist/stores/canvasStore.d.ts +41 -0
  327. package/dist/stores/canvasStore.d.ts.map +1 -0
  328. package/dist/stores/canvasStore.js +187 -0
  329. package/dist/stores/canvasStore.js.map +1 -0
  330. package/dist/stores/debugStore.d.ts +42 -0
  331. package/dist/stores/debugStore.d.ts.map +1 -0
  332. package/dist/stores/debugStore.js +22 -0
  333. package/dist/stores/debugStore.js.map +1 -0
  334. package/dist/stores/diagnosticsStore.d.ts +41 -0
  335. package/dist/stores/diagnosticsStore.d.ts.map +1 -0
  336. package/dist/stores/diagnosticsStore.js +67 -0
  337. package/dist/stores/diagnosticsStore.js.map +1 -0
  338. package/dist/stores/editorStore.d.ts +76 -0
  339. package/dist/stores/editorStore.d.ts.map +1 -0
  340. package/dist/stores/editorStore.js +116 -0
  341. package/dist/stores/editorStore.js.map +1 -0
  342. package/dist/utils/categoryConstants.d.ts +4 -0
  343. package/dist/utils/categoryConstants.d.ts.map +1 -0
  344. package/dist/utils/categoryConstants.js +24 -0
  345. package/dist/utils/categoryConstants.js.map +1 -0
  346. package/dist/utils/channelOperations.d.ts +21 -0
  347. package/dist/utils/channelOperations.d.ts.map +1 -0
  348. package/dist/utils/channelOperations.js +84 -0
  349. package/dist/utils/channelOperations.js.map +1 -0
  350. package/dist/utils/connectionRules.d.ts +15 -0
  351. package/dist/utils/connectionRules.d.ts.map +1 -0
  352. package/dist/utils/connectionRules.js +113 -0
  353. package/dist/utils/connectionRules.js.map +1 -0
  354. package/dist/utils/functionOperations.d.ts +27 -0
  355. package/dist/utils/functionOperations.d.ts.map +1 -0
  356. package/dist/utils/functionOperations.js +140 -0
  357. package/dist/utils/functionOperations.js.map +1 -0
  358. package/dist/utils/graphOperations.d.ts +54 -0
  359. package/dist/utils/graphOperations.d.ts.map +1 -0
  360. package/dist/utils/graphOperations.js +461 -0
  361. package/dist/utils/graphOperations.js.map +1 -0
  362. package/dist/utils/history.d.ts +76 -0
  363. package/dist/utils/history.d.ts.map +1 -0
  364. package/dist/utils/history.js +93 -0
  365. package/dist/utils/history.js.map +1 -0
  366. package/dist/utils/memoryOperations.d.ts +14 -0
  367. package/dist/utils/memoryOperations.d.ts.map +1 -0
  368. package/dist/utils/memoryOperations.js +55 -0
  369. package/dist/utils/memoryOperations.js.map +1 -0
  370. package/dist/utils/migrateFunctionNodes.d.ts +9 -0
  371. package/dist/utils/migrateFunctionNodes.d.ts.map +1 -0
  372. package/dist/utils/migrateFunctionNodes.js +89 -0
  373. package/dist/utils/migrateFunctionNodes.js.map +1 -0
  374. package/dist/utils/modelOperations.d.ts +13 -0
  375. package/dist/utils/modelOperations.d.ts.map +1 -0
  376. package/dist/utils/modelOperations.js +53 -0
  377. package/dist/utils/modelOperations.js.map +1 -0
  378. package/dist/utils/paramDisplay.d.ts +12 -0
  379. package/dist/utils/paramDisplay.d.ts.map +1 -0
  380. package/dist/utils/paramDisplay.js +56 -0
  381. package/dist/utils/paramDisplay.js.map +1 -0
  382. package/dist/utils/resourceHelpers.d.ts +17 -0
  383. package/dist/utils/resourceHelpers.d.ts.map +1 -0
  384. package/dist/utils/resourceHelpers.js +32 -0
  385. package/dist/utils/resourceHelpers.js.map +1 -0
  386. package/dist/utils/translation.d.ts +20 -0
  387. package/dist/utils/translation.d.ts.map +1 -0
  388. package/dist/utils/translation.js +23 -0
  389. package/dist/utils/translation.js.map +1 -0
  390. package/dist/utils/variableOperations.d.ts +15 -0
  391. package/dist/utils/variableOperations.d.ts.map +1 -0
  392. package/dist/utils/variableOperations.js +71 -0
  393. package/dist/utils/variableOperations.js.map +1 -0
  394. package/package.json +79 -0
  395. package/src/BuilderLayout.tsx +345 -0
  396. package/src/Canvas.tsx +261 -0
  397. package/src/CanvasEditor.tsx +142 -0
  398. package/src/CanvasTabsToolbar.tsx +176 -0
  399. package/src/RightConfigPanel.tsx +266 -0
  400. package/src/WorkflowBuilder.tsx +412 -0
  401. package/src/cn.ts +6 -0
  402. package/src/components/ui/add-button.tsx +39 -0
  403. package/src/components/ui/alert-dialog.tsx +141 -0
  404. package/src/components/ui/alert.tsx +59 -0
  405. package/src/components/ui/badge.tsx +36 -0
  406. package/src/components/ui/button.tsx +85 -0
  407. package/src/components/ui/card.tsx +79 -0
  408. package/src/components/ui/checkbox.tsx +28 -0
  409. package/src/components/ui/collapsible.tsx +9 -0
  410. package/src/components/ui/command.tsx +153 -0
  411. package/src/components/ui/delete-button.tsx +23 -0
  412. package/src/components/ui/dialog.tsx +125 -0
  413. package/src/components/ui/dropdown-menu.tsx +198 -0
  414. package/src/components/ui/input.tsx +55 -0
  415. package/src/components/ui/label.tsx +24 -0
  416. package/src/components/ui/readonly-banner.tsx +15 -0
  417. package/src/components/ui/resizable.tsx +43 -0
  418. package/src/components/ui/scroll-area.tsx +102 -0
  419. package/src/components/ui/select.tsx +160 -0
  420. package/src/components/ui/separator.tsx +29 -0
  421. package/src/components/ui/switch.tsx +27 -0
  422. package/src/components/ui/textarea.tsx +51 -0
  423. package/src/components/ui/toast.tsx +127 -0
  424. package/src/components/ui/toaster.tsx +33 -0
  425. package/src/components/ui/toggle-group.tsx +59 -0
  426. package/src/components/ui/toggle.tsx +43 -0
  427. package/src/components/ui/tooltip.tsx +32 -0
  428. package/src/dialogs/NodePickerDialog.tsx +84 -0
  429. package/src/dialogs/ValidationDialog.tsx +184 -0
  430. package/src/graph/BaseNode.tsx +557 -0
  431. package/src/graph/CustomEdge.tsx +185 -0
  432. package/src/graph/CustomNode.tsx +16 -0
  433. package/src/graph/FunctionCallNode.tsx +30 -0
  434. package/src/graph/PortHandle.tsx +189 -0
  435. package/src/graph/reactFlowRegistry.ts +26 -0
  436. package/src/hooks/use-toast.ts +125 -0
  437. package/src/hooks/useAvailableVariables.ts +20 -0
  438. package/src/hooks/useCanvasHistory.ts +22 -0
  439. package/src/hooks/useCanvasTabs.ts +168 -0
  440. package/src/hooks/useFunctionDiagnosticsSync.ts +40 -0
  441. package/src/hooks/useFunctionRegistry.ts +26 -0
  442. package/src/hooks/useFunctions.ts +44 -0
  443. package/src/hooks/useGraph.ts +161 -0
  444. package/src/hooks/useNodeDefinitions.ts +82 -0
  445. package/src/hooks/useParamErrors.ts +26 -0
  446. package/src/hooks/useResolvedTheme.ts +30 -0
  447. package/src/hooks/useResourceDiagnosticsSync.ts +58 -0
  448. package/src/hooks/useSuppressThemeTransition.ts +79 -0
  449. package/src/hooks/useWorkflowSerialization.ts +127 -0
  450. package/src/i18n/index.ts +53 -0
  451. package/src/i18n/locales/de.json +501 -0
  452. package/src/i18n/locales/en.json +557 -0
  453. package/src/index.ts +27 -0
  454. package/src/inputs/ExpressionInput.tsx +297 -0
  455. package/src/inputs/ParameterEditor.tsx +515 -0
  456. package/src/inputs/PortSection.tsx +144 -0
  457. package/src/panels/BuilderSidebar.tsx +301 -0
  458. package/src/panels/ChannelConfigPanel.tsx +49 -0
  459. package/src/panels/ChannelsPanel.tsx +28 -0
  460. package/src/panels/DebugConsolePanel.tsx +73 -0
  461. package/src/panels/DebugContextPanel.tsx +77 -0
  462. package/src/panels/DebugExternalIOPanel.tsx +180 -0
  463. package/src/panels/DiagnosticsPanel.tsx +170 -0
  464. package/src/panels/EdgeConfigPanel.tsx +104 -0
  465. package/src/panels/FunctionConfigPanel.tsx +179 -0
  466. package/src/panels/FunctionListPanel.tsx +45 -0
  467. package/src/panels/MemoryConfigPanel.tsx +55 -0
  468. package/src/panels/MemoryPanel.tsx +40 -0
  469. package/src/panels/ModelConfigPanel.tsx +41 -0
  470. package/src/panels/ModelsPanel.tsx +36 -0
  471. package/src/panels/NodeConfigPanel.tsx +630 -0
  472. package/src/panels/NodeLibrary.tsx +288 -0
  473. package/src/panels/ResourceConfigPanel.tsx +132 -0
  474. package/src/panels/ResourceListPanel.tsx +113 -0
  475. package/src/panels/VariableConfigPanel.tsx +161 -0
  476. package/src/panels/VariablesPanel.tsx +145 -0
  477. package/src/stores/canvasStore.test.ts +44 -0
  478. package/src/stores/canvasStore.ts +245 -0
  479. package/src/stores/debugStore.ts +74 -0
  480. package/src/stores/diagnosticsStore.ts +130 -0
  481. package/src/stores/editorStore.ts +202 -0
  482. package/src/styles/index.css +526 -0
  483. package/src/utils/categoryConstants.ts +26 -0
  484. package/src/utils/channelOperations.ts +86 -0
  485. package/src/utils/connectionRules.ts +137 -0
  486. package/src/utils/functionOperations.ts +179 -0
  487. package/src/utils/graphOperations.ts +550 -0
  488. package/src/utils/history.ts +207 -0
  489. package/src/utils/memoryOperations.ts +57 -0
  490. package/src/utils/migrateFunctionNodes.ts +107 -0
  491. package/src/utils/modelOperations.ts +55 -0
  492. package/src/utils/paramDisplay.ts +71 -0
  493. package/src/utils/resourceHelpers.ts +32 -0
  494. package/src/utils/translation.ts +28 -0
  495. package/src/utils/variableOperations.ts +75 -0
  496. package/tailwind-preset.ts +166 -0
@@ -0,0 +1,161 @@
1
+ import { useEffect, useState } from "react";
2
+ import { useTranslation } from "react-i18next";
3
+ import { Button } from "../components/ui/button";
4
+ import { Input } from "../components/ui/input";
5
+ import { Separator } from "../components/ui/separator";
6
+ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../components/ui/select";
7
+ import { ChevronRight } from "lucide-react";
8
+ import type { DeclaredVariable } from "@foresthubai/workflow-core/variable";
9
+ import type { DataType } from "@foresthubai/workflow-core";
10
+ import { useEditorStore } from "../stores/editorStore";
11
+ import { isReadOnly } from "../WorkflowBuilder";
12
+ import { ReadOnlyBanner } from "../components/ui/readonly-banner";
13
+ import { DeleteButton } from "../components/ui/delete-button";
14
+ import { deleteDeclaredVariable, setDeclaredVariableType, updateDeclaredVariable } from "../utils/variableOperations";
15
+
16
+ interface VariableConfigPanelProps {
17
+ canvasId: string;
18
+ variable: DeclaredVariable;
19
+ onClose: () => void;
20
+ }
21
+
22
+ const DATA_TYPES: DataType[] = ["int", "float", "bool", "string"];
23
+
24
+ export const VariableConfigPanel = ({ canvasId, variable, onClose }: VariableConfigPanelProps) => {
25
+ const { t } = useTranslation();
26
+ const readOnly = useEditorStore((s) => isReadOnly(s.builderMode));
27
+
28
+ // Local name state mirrors the other config panels — preserves cursor position
29
+ // while typing and resets when a different variable is opened.
30
+ const [localName, setLocalName] = useState(variable.name);
31
+ useEffect(() => {
32
+ setLocalName(variable.name);
33
+ }, [variable.uid, variable.name]);
34
+
35
+ const isEmptyName = variable.name.trim() === "";
36
+
37
+ // The initial-value widget is chosen by dataType: declared variables store
38
+ // `initialValue?: unknown` and the type is enforced here at the input layer,
39
+ // not in the data model (untyped DOM input + JSON round-trip would defeat a
40
+ // discriminated union). Switching dataType clears the value.
41
+ const renderInitialValueInput = () => {
42
+ switch (variable.dataType) {
43
+ case "bool":
44
+ return (
45
+ <Select
46
+ value={variable.initialValue != null ? String(variable.initialValue) : "false"}
47
+ onValueChange={(v) => updateDeclaredVariable(canvasId, variable.uid, { initialValue: v === "true" })}
48
+ >
49
+ <SelectTrigger className="h-8 text-sm">
50
+ <SelectValue />
51
+ </SelectTrigger>
52
+ <SelectContent>
53
+ <SelectItem value="false">false</SelectItem>
54
+ <SelectItem value="true">true</SelectItem>
55
+ </SelectContent>
56
+ </Select>
57
+ );
58
+ case "string":
59
+ return (
60
+ <Input
61
+ className="h-8 text-sm"
62
+ value={(variable.initialValue as string) ?? ""}
63
+ onChange={(e) => updateDeclaredVariable(canvasId, variable.uid, { initialValue: e.target.value })}
64
+ placeholder='""'
65
+ />
66
+ );
67
+ case "int":
68
+ case "float":
69
+ return (
70
+ <Input
71
+ type="number"
72
+ step={variable.dataType === "float" ? "any" : 1}
73
+ className="h-8 text-sm"
74
+ value={variable.initialValue != null ? Number(variable.initialValue) : ""}
75
+ onChange={(e) => {
76
+ const num = variable.dataType === "float" ? parseFloat(e.target.value) : parseInt(e.target.value, 10);
77
+ updateDeclaredVariable(canvasId, variable.uid, { initialValue: isNaN(num) ? undefined : num });
78
+ }}
79
+ placeholder="0"
80
+ />
81
+ );
82
+ default:
83
+ return null;
84
+ }
85
+ };
86
+
87
+ return (
88
+ <div className="p-4">
89
+ <div className="space-y-4">
90
+ <div className="flex items-center justify-between gap-2">
91
+ <div className="flex-1 min-w-0">
92
+ <div className="group flex items-center gap-1.5 rounded-md border border-transparent px-1.5 -mx-1.5 hover:border-input focus-within:border-input transition-colors">
93
+ <input
94
+ type="text"
95
+ title={t("variableName", "Variable name")}
96
+ className="font-semibold text-lg font-mono bg-transparent w-full outline-none cursor-text py-0.5"
97
+ value={localName}
98
+ readOnly={readOnly}
99
+ onChange={(e) => {
100
+ setLocalName(e.target.value);
101
+ updateDeclaredVariable(canvasId, variable.uid, { name: e.target.value });
102
+ }}
103
+ />
104
+ </div>
105
+ <p className="text-sm text-muted-foreground">
106
+ {t("variableDescription", "A declared variable you can read and write across this canvas")}
107
+ </p>
108
+ {isEmptyName && (
109
+ <p className="text-xs text-destructive mt-1">{t("variableNameRequired", "Name is required")}</p>
110
+ )}
111
+ </div>
112
+ <Button variant="ghost" size="icon" className="shrink-0" onClick={onClose}>
113
+ <ChevronRight className="h-4 w-4" />
114
+ </Button>
115
+ </div>
116
+
117
+ {readOnly && <ReadOnlyBanner />}
118
+
119
+ <Separator />
120
+
121
+ <div className={`space-y-4 ${readOnly ? "pointer-events-none opacity-60" : ""}`}>
122
+ <div className="space-y-1.5">
123
+ <label className="text-xs font-medium text-foreground/80">{t("dataType", "Data type")}</label>
124
+ <Select
125
+ value={variable.dataType}
126
+ onValueChange={(v) => setDeclaredVariableType(canvasId, variable.uid, v as DataType)}
127
+ >
128
+ <SelectTrigger className="h-8 text-sm">
129
+ <SelectValue />
130
+ </SelectTrigger>
131
+ <SelectContent>
132
+ {DATA_TYPES.map((dt) => (
133
+ <SelectItem key={dt} value={dt}>
134
+ {dt}
135
+ </SelectItem>
136
+ ))}
137
+ </SelectContent>
138
+ </Select>
139
+ </div>
140
+
141
+ <div className="space-y-1.5">
142
+ <label className="text-xs font-medium text-foreground/80">
143
+ {t("initialValue")}{" "}
144
+ <span className="font-normal text-muted-foreground">({t("optional", "optional")})</span>
145
+ </label>
146
+ {renderInitialValueInput()}
147
+ </div>
148
+ </div>
149
+
150
+ {!readOnly && (
151
+ <>
152
+ <Separator />
153
+ <DeleteButton onClick={() => deleteDeclaredVariable(canvasId, variable.uid)}>
154
+ {t("deleteVariable", "Delete variable")}
155
+ </DeleteButton>
156
+ </>
157
+ )}
158
+ </div>
159
+ </div>
160
+ );
161
+ };
@@ -0,0 +1,145 @@
1
+ import React from "react";
2
+ import { useTranslation } from "react-i18next";
3
+ import { AddButton } from "../components/ui/add-button";
4
+ import { Variable as VariableIcon } from "lucide-react";
5
+ import { cn } from "../cn";
6
+ import { useEditorStore } from "../stores/editorStore";
7
+ import { isReadOnly } from "../WorkflowBuilder";
8
+ import { useAvailableVariables } from "../hooks/useAvailableVariables";
9
+ import { getOrCreateCanvasStore, MAIN_CANVAS_ID } from "../stores/canvasStore";
10
+ import { type Variable, type DeclaredVariable } from "@foresthubai/workflow-core/variable";
11
+ import { addDeclaredVariable } from "../utils/variableOperations";
12
+
13
+ interface VariablesPanelProps {
14
+ canvasId: string;
15
+ onSelectNode: (nodeId: string) => void;
16
+ }
17
+
18
+ export const VariablesPanel = ({ canvasId, onSelectNode }: VariablesPanelProps) => {
19
+ const readOnly = useEditorStore((s) => isReadOnly(s.builderMode));
20
+ const { t } = useTranslation();
21
+ const { list: variables } = useAvailableVariables(canvasId);
22
+ const selection = useEditorStore((s) => s.selection);
23
+ const selectVariable = useEditorStore((s) => s.selectVariable);
24
+
25
+ const store = getOrCreateCanvasStore(canvasId);
26
+ const allVariables = store((s) => s.variables);
27
+ const isMainCanvas = canvasId === MAIN_CANVAS_ID;
28
+
29
+ // Extract declared variables from the unified record
30
+ const declaredVariables = React.useMemo(() => {
31
+ const result: { uid: string; var: DeclaredVariable }[] = [];
32
+ for (const v of Object.values(allVariables)) {
33
+ if (v.kind === "declared") {
34
+ result.push({ uid: v.uid, var: v });
35
+ }
36
+ }
37
+ return result;
38
+ }, [allVariables]);
39
+
40
+ // Create a declared variable and immediately open its config panel.
41
+ const handleAddVariable = () => {
42
+ const uid = addDeclaredVariable(canvasId);
43
+ selectVariable(uid);
44
+ };
45
+
46
+ // Filter variables into groups (each canvas is self-contained — no main-canvas leakage)
47
+ const functionArgs = variables.filter((v) => v.kind === "fnarg");
48
+ const nodeOutputs = variables.filter((v) => v.kind === "node");
49
+
50
+ const hasContent = functionArgs.length > 0 || nodeOutputs.length > 0 || declaredVariables.length > 0;
51
+
52
+ if (!hasContent) {
53
+ return (
54
+ <div className="flex flex-col items-center justify-center py-8 text-center">
55
+ <VariableIcon className="w-10 h-10 text-muted-foreground/50 mb-3" />
56
+ <p className="text-sm text-muted-foreground">{t("noVariables")}</p>
57
+ <p className="text-xs text-muted-foreground/70 mt-1">{t("addNodesForVariables")}</p>
58
+ {!readOnly && (
59
+ <div className="mt-3 w-full px-2">
60
+ <AddButton onClick={handleAddVariable}>{t("addVariable")}</AddButton>
61
+ </div>
62
+ )}
63
+ </div>
64
+ );
65
+ }
66
+
67
+ const renderVariableItem = (ref: Variable, onClick?: () => void, isSelected = false) => {
68
+ const clickable = !!onClick;
69
+
70
+ return (
71
+ <div
72
+ key={
73
+ ref.kind === "node"
74
+ ? `${ref.nodeId}-${ref.outputId}`
75
+ : ref.kind === "declared"
76
+ ? `declared-${ref.uid}`
77
+ : `fnarg-${ref.uid}`
78
+ }
79
+ onClick={onClick}
80
+ className={cn(
81
+ "p-3 rounded-lg transition-all",
82
+ isSelected
83
+ ? "bg-accent shadow-md border border-primary/40 ring-1 ring-primary/40"
84
+ : "bg-card shadow-sm border border-border",
85
+ clickable ? "hover:shadow-md cursor-pointer" : "cursor-default",
86
+ )}
87
+ >
88
+ <div className="flex items-center justify-between">
89
+ <div className="flex items-center gap-2">
90
+ <VariableIcon className="w-4 h-4 text-muted-foreground" />
91
+ <span className="font-mono text-sm text-foreground">{ref.name}</span>
92
+ </div>
93
+ <span className="text-[10px] font-medium px-1.5 py-0.5 rounded border border-border/50 text-muted-foreground shrink-0">
94
+ {ref.dataType}
95
+ </span>
96
+ </div>
97
+ </div>
98
+ );
99
+ };
100
+
101
+ const SectionHeader = ({ title }: { title: string }) => (
102
+ <div className="flex items-center justify-between px-1 mb-2">
103
+ <span className="text-sm font-medium text-foreground/80">{title}</span>
104
+ </div>
105
+ );
106
+
107
+ return (
108
+ <div className="space-y-5">
109
+ {/* Function Arguments (function canvas only) — read-only, arrive by value */}
110
+ {!isMainCanvas && functionArgs.length > 0 && (
111
+ <div>
112
+ <SectionHeader title={t("functionArguments")} />
113
+ <div className="space-y-1.5">{functionArgs.map((v) => renderVariableItem(v))}</div>
114
+ </div>
115
+ )}
116
+
117
+ {/* Node Output Variables — click opens the emitting node */}
118
+ {nodeOutputs.length > 0 && (
119
+ <div>
120
+ <SectionHeader title={t("nodeOutputVariables")} />
121
+ <div className="space-y-1.5">
122
+ {nodeOutputs.map((v) =>
123
+ renderVariableItem(v, v.kind === "node" ? () => onSelectNode(v.nodeId) : undefined),
124
+ )}
125
+ </div>
126
+ </div>
127
+ )}
128
+
129
+ {/* Defined Variables — click opens the VariableConfigPanel */}
130
+ <div>
131
+ <SectionHeader title={t("definedVariables")} />
132
+ <div className="space-y-1.5">
133
+ {declaredVariables.map(({ uid, var: dv }) =>
134
+ renderVariableItem(
135
+ dv,
136
+ readOnly ? undefined : () => selectVariable(uid),
137
+ selection.kind === "variable" && selection.uid === uid,
138
+ ),
139
+ )}
140
+ {!readOnly && <AddButton onClick={handleAddVariable}>{t("addVariable")}</AddButton>}
141
+ </div>
142
+ </div>
143
+ </div>
144
+ );
145
+ };
@@ -0,0 +1,44 @@
1
+ import { afterEach, describe, expect, it } from "vitest";
2
+ import {
3
+ clearAllCanvasStores,
4
+ getAllCanvasStores,
5
+ getCanvasStore,
6
+ getOrCreateCanvasStore,
7
+ subscribeCanvasRegistryChanges,
8
+ MAIN_CANVAS_ID,
9
+ } from "./canvasStore";
10
+
11
+ // Reset the module-level registry between tests (it's a singleton).
12
+ afterEach(() => clearAllCanvasStores());
13
+
14
+ describe("clearAllCanvasStores", () => {
15
+ it("re-seeds an empty main canvas and drops the rest", () => {
16
+ const mainBefore = getOrCreateCanvasStore(MAIN_CANVAS_ID);
17
+ getOrCreateCanvasStore("fn-1"); // a function canvas
18
+ expect(Object.keys(getAllCanvasStores())).toEqual(expect.arrayContaining([MAIN_CANVAS_ID, "fn-1"]));
19
+
20
+ clearAllCanvasStores();
21
+
22
+ const mainAfter = getCanvasStore(MAIN_CANVAS_ID);
23
+ expect(mainAfter).toBeDefined(); // "main always exists" invariant holds
24
+ expect(mainAfter).not.toBe(mainBefore); // it's a fresh, empty instance
25
+ expect(mainAfter?.getState().nodes).toEqual([]);
26
+ expect(getCanvasStore("fn-1")).toBeUndefined(); // function canvas removed
27
+ });
28
+
29
+ it("notifies registry listeners with main already present", () => {
30
+ // Regression guard: the notification must fire AFTER main is re-seeded, not
31
+ // while the registry is empty — otherwise subscribers (onChange / history)
32
+ // snapshot an empty set and never re-attach to the recreated main canvas, so
33
+ // edits after New/clear wouldn't mark the workflow dirty.
34
+ let mainPresentAtNotify = false;
35
+ const unsubscribe = subscribeCanvasRegistryChanges(() => {
36
+ mainPresentAtNotify = MAIN_CANVAS_ID in getAllCanvasStores();
37
+ });
38
+
39
+ clearAllCanvasStores();
40
+ unsubscribe();
41
+
42
+ expect(mainPresentAtNotify).toBe(true);
43
+ });
44
+ });
@@ -0,0 +1,245 @@
1
+ import { create, UseBoundStore, StoreApi } from "zustand";
2
+ import { Node, Edge, Viewport } from "@xyflow/react";
3
+ import { NodeCategory, type NodeData } from "@foresthubai/workflow-core/node";
4
+ import type { EdgeData } from "@foresthubai/workflow-core/edge";
5
+ import { history, History, type HistoryData, type MutationCount } from "../utils/history";
6
+ import { generateId } from "@foresthubai/workflow-core/id";
7
+ import { fnargKey, type Variable, type ApiVariable } from "@foresthubai/workflow-core/variable";
8
+ import { computeVariablesFromNodes } from "@foresthubai/workflow-core/workflow";
9
+
10
+ /**
11
+ * Sync fnarg:* entries in a canvas's variables to match a function's arguments.
12
+ * fnarg variables are *derived* from the (project-scoped) function declaration —
13
+ * they are not authored canvas state, so the source of truth is `editorStore`;
14
+ * callers pass the declaration's argument list here. Removes stale fnarg entries
15
+ * and adds the current ones.
16
+ */
17
+ export function syncFunctionArgVariables(store: CanvasStore, args: readonly ApiVariable[]): void {
18
+ store.getState().setVariables((vars) => {
19
+ const updated = { ...vars };
20
+ // Remove all existing fnarg entries
21
+ for (const key of Object.keys(updated)) {
22
+ if (key.startsWith("fnarg:")) delete updated[key];
23
+ }
24
+ // Add current args
25
+ for (const arg of args) {
26
+ updated[fnargKey(arg.uid)] = { kind: "fnarg", uid: arg.uid, name: arg.name, dataType: arg.dataType };
27
+ }
28
+ return updated;
29
+ });
30
+ }
31
+
32
+ export { MAIN_CANVAS_ID } from "@foresthubai/workflow-core/workflow";
33
+ import { MAIN_CANVAS_ID } from "@foresthubai/workflow-core/workflow";
34
+ const HISTORY_LIMIT = 50 as const;
35
+
36
+ // ============================================================================
37
+ // Canvas Registry Change Notification System
38
+ // ============================================================================
39
+
40
+ // Listeners notified when the *set* of canvas stores changes (a store is created,
41
+ // deleted, or the whole registry is cleared/retained). This is decoupled from
42
+ // function definitions — those now live in editorStore. Its sole consumer is
43
+ // WorkflowBuilder, which re-subscribes to every live store's mutationCount/history
44
+ // when the set changes so newly created (or dropped) canvases are watched.
45
+ const canvasRegistryListeners = new Set<() => void>();
46
+
47
+ // Notify subscribers that the canvas store set changed.
48
+ export function notifyCanvasRegistryChange(): void {
49
+ canvasRegistryListeners.forEach((listener) => listener());
50
+ }
51
+
52
+ // Subscribe to canvas registry (store set) changes.
53
+ export function subscribeCanvasRegistryChanges(listener: () => void): () => void {
54
+ canvasRegistryListeners.add(listener);
55
+ return () => canvasRegistryListeners.delete(listener);
56
+ }
57
+
58
+ // ============================================================================
59
+ // Canvas Store Registry
60
+ // ============================================================================
61
+
62
+ // Registry - Module-level map of independent store instances
63
+ const canvasStores = new Map<string, CanvasStore>();
64
+
65
+ canvasStores.set(MAIN_CANVAS_ID, createCanvasStore()); // Always exists
66
+
67
+ export interface CanvasState {
68
+ nodes: Node<NodeData>[];
69
+ edges: Edge<EdgeData>[];
70
+ // Unified variable record: node outputs (nodeId:outputId), declared (declared:uid), fn args (fnarg:uid).
71
+ // fnarg:* entries are derived from the project-scoped function declaration (editorStore) via
72
+ // syncFunctionArgVariables — they are not authored here.
73
+ variables: Record<string, Variable>;
74
+ // Session-only pan/zoom of the canvas viewport. View state, NOT workflow content:
75
+ // kept out of partialize (no history/serialization) so it never enters the contract,
76
+ // and lost on reload like selection. Persisted across tab switches so re-entering a
77
+ // canvas restores its view via defaultViewport instead of a post-paint fitView jump.
78
+ // null until first visited (then fitView seeds it).
79
+ viewport: Viewport | null;
80
+
81
+ setNodes: (updater: (nodes: Node<NodeData>[]) => Node<NodeData>[]) => void;
82
+ setEdges: (updater: (edges: Edge<EdgeData>[]) => Edge<EdgeData>[]) => void;
83
+ setVariables: (updater: (variables: Record<string, Variable>) => Record<string, Variable>) => void;
84
+ setViewport: (viewport: Viewport) => void;
85
+ /**
86
+ * Visual-only: set ReactFlow selected flags on nodes AND edges in one atomic update.
87
+ * This will call a single re-render and a single onSelectionChange callback.
88
+ * Not an update of domain state, so it can be used in read-only mode.
89
+ */
90
+ setRFselect: (nodeIds: string[], edgeIds: string[]) => void;
91
+ initialize: (nodes: Node<NodeData>[], edges: Edge<EdgeData>[]) => void;
92
+ }
93
+
94
+ // Canvas store is a Zustand store + history (undo/redo capabilities) + mutation count.
95
+ export type CanvasStore = UseBoundStore<StoreApi<CanvasState & MutationCount>> & History;
96
+
97
+ function createCanvasStore(): CanvasStore {
98
+ // Create base store with history middleware
99
+ const baseStore = create(
100
+ history<CanvasState>({
101
+ limit: HISTORY_LIMIT,
102
+ partialize: (state) => ({
103
+ nodes: state.nodes,
104
+ edges: state.edges,
105
+ variables: state.variables,
106
+ }),
107
+ equality: (before, after) => before.nodes === after.nodes && before.edges === after.edges && before.variables === after.variables,
108
+ })((set) => ({
109
+ nodes: [],
110
+ edges: [],
111
+ variables: {},
112
+ viewport: null,
113
+
114
+ setNodes: (updater) =>
115
+ set((state) => {
116
+ const next = updater(state.nodes);
117
+ if (next === state.nodes) return state;
118
+ return { nodes: next };
119
+ }),
120
+
121
+ setEdges: (updater) =>
122
+ set((state) => {
123
+ const next = updater(state.edges);
124
+ if (next === state.edges) return state;
125
+ return { edges: next };
126
+ }),
127
+
128
+ setVariables: (updater) =>
129
+ set((state) => {
130
+ const next = updater(state.variables);
131
+ if (next === state.variables) return state;
132
+ return { variables: next };
133
+ }),
134
+
135
+ // View-only — outside partialize, so it neither takes a checkpoint nor bumps
136
+ // mutationCount (no spurious dirty dot / onChange from panning).
137
+ setViewport: (viewport) => set({ viewport }),
138
+
139
+ setRFselect: (nodeIds, edgeIds) => {
140
+ const nodeIdSet = new Set(nodeIds);
141
+ const edgeIdSet = new Set(edgeIds);
142
+ set((state) => ({
143
+ nodes: state.nodes.map((n) => {
144
+ const shouldSelect = nodeIdSet.has(n.id);
145
+ return n.selected === shouldSelect ? n : { ...n, selected: shouldSelect };
146
+ }),
147
+ edges: state.edges.map((e) => {
148
+ const shouldSelect = edgeIdSet.has(e.id);
149
+ return e.selected === shouldSelect ? e : { ...e, selected: shouldSelect };
150
+ }),
151
+ }));
152
+ },
153
+
154
+ initialize: (nodes, edges) => {
155
+ // Build node-output variables. fnarg entries (for function canvases) are
156
+ // seeded separately via syncFunctionArgVariables from the editorStore
157
+ // declaration, since the canvas store no longer owns the signature.
158
+ // computeVariablesFromNodes is the core (NodeData[]) variant; peel the
159
+ // React Flow wrapper at the call site.
160
+ const vars: Record<string, Variable> = computeVariablesFromNodes(nodes.map((n) => n.data));
161
+ set({ nodes, edges, variables: vars });
162
+ },
163
+ })),
164
+ );
165
+
166
+ // Bind history methods from state to CanvasStore object
167
+ // This makes them accessible as store.undo() instead of store.getState().undo()
168
+ const store = baseStore as unknown as CanvasStore;
169
+
170
+ store.takeCheckpoint = () => baseStore.getState().takeCheckpoint();
171
+ store.withCheckpoint = <R>(operation: () => R): R => baseStore.getState().withCheckpoint(operation);
172
+ store.undo = () => baseStore.getState().undo();
173
+ store.redo = () => baseStore.getState().redo();
174
+ store.clearHistory = () => baseStore.getState().clearHistory();
175
+ store.canUndo = () => baseStore.getState().canUndo();
176
+ store.canRedo = () => baseStore.getState().canRedo();
177
+ store.exportHistory = () => baseStore.getState().exportHistory();
178
+ store.importHistory = (data: HistoryData) => baseStore.getState().importHistory(data);
179
+
180
+ return store;
181
+ }
182
+
183
+ // ============================================================================
184
+ // Store Access API
185
+ // ============================================================================
186
+
187
+ // Get a canvas store by ID, or undefined if not exists
188
+ export function getCanvasStore(canvasId: string): CanvasStore | undefined {
189
+ return canvasStores.get(canvasId);
190
+ }
191
+
192
+ // Get or create a canvas store by ID
193
+ // Non-main canvases (function canvases) are initialized with an OnFunctionCall node
194
+ export function getOrCreateCanvasStore(canvasId: string): CanvasStore {
195
+ if (!canvasStores.has(canvasId)) {
196
+ const store = createCanvasStore();
197
+
198
+ // Initialize function canvases with OnFunctionCall trigger node
199
+ if (canvasId !== MAIN_CANVAS_ID) {
200
+ const nodeId = generateId();
201
+ const initialNode: Node<NodeData> = {
202
+ id: nodeId,
203
+ type: NodeCategory.Trigger,
204
+ position: { x: 100, y: 100 },
205
+ data: {
206
+ id: nodeId,
207
+ type: "OnFunctionCall",
208
+ arguments: {},
209
+ } as NodeData,
210
+ };
211
+ store.getState().initialize([initialNode], []);
212
+ }
213
+
214
+ canvasStores.set(canvasId, store);
215
+ }
216
+ return canvasStores.get(canvasId)!;
217
+ }
218
+
219
+ // Get all canvas stores
220
+ export function getAllCanvasStores(): Record<string, CanvasStore> {
221
+ const result: Record<string, CanvasStore> = {};
222
+ canvasStores.forEach((store, id) => {
223
+ result[id] = store;
224
+ });
225
+ return result;
226
+ }
227
+
228
+ // Delete a canvas store by ID. Cannot delete the main canvas.
229
+ export function deleteCanvasStore(canvasId: string): void {
230
+ if (canvasId === MAIN_CANVAS_ID) return;
231
+ canvasStores.delete(canvasId);
232
+ notifyCanvasRegistryChange();
233
+ }
234
+
235
+ // Clear all canvas stores, including the main canvas.
236
+ export function clearAllCanvasStores(): void {
237
+ canvasStores.clear();
238
+ // Re-seed an empty main canvas BEFORE notifying. Two reasons: it preserves the
239
+ // "main always exists" invariant, and — critically — subscribers re-subscribe to
240
+ // the live store set on this notification. If main were absent here, they'd
241
+ // snapshot an empty registry and never attach to the lazily-recreated main, so
242
+ // edits after New/clear wouldn't fire onChange (no dirty dot, stale undo state).
243
+ canvasStores.set(MAIN_CANVAS_ID, createCanvasStore());
244
+ notifyCanvasRegistryChange();
245
+ }
@@ -0,0 +1,74 @@
1
+ import { create } from "zustand";
2
+
3
+ // ---------------------------------------------------------------------------
4
+ // Session Phase State Machine
5
+ // ---------------------------------------------------------------------------
6
+
7
+ export type DebugSessionPhase =
8
+ | { status: "inactive" }
9
+ | { status: "building"; abortController: AbortController }
10
+ | { status: "idle"; sessionId: string }
11
+ | { status: "paused"; sessionId: string; cursorNodeId: string }
12
+ | { status: "stepping"; sessionId: string; cursorNodeId: string }
13
+ | { status: "error"; message: string };
14
+
15
+ // ---------------------------------------------------------------------------
16
+ // Console
17
+ // ---------------------------------------------------------------------------
18
+
19
+ export interface ConsoleEntry {
20
+ id: number;
21
+ timestamp: number;
22
+ type: "message" | "error" | "system";
23
+ text: string;
24
+ }
25
+
26
+ // ---------------------------------------------------------------------------
27
+ // Store
28
+ // ---------------------------------------------------------------------------
29
+
30
+ interface DebugState {
31
+ phase: DebugSessionPhase;
32
+ /** Workflow variable values — client-owned, sent with each step request */
33
+ context: Record<string, unknown>;
34
+ console: ConsoleEntry[];
35
+ nextConsoleId: number;
36
+
37
+ // Actions
38
+ setPhase: (phase: DebugSessionPhase) => void;
39
+ setContext: (ctx: Record<string, unknown>) => void;
40
+ updateContextVar: (key: string, value: unknown) => void;
41
+ appendConsole: (type: ConsoleEntry["type"], text: string) => void;
42
+ clearConsole: () => void;
43
+ reset: () => void;
44
+ }
45
+
46
+ export const useDebugStore = create<DebugState>((set) => ({
47
+ phase: { status: "inactive" },
48
+ context: {},
49
+ console: [],
50
+ nextConsoleId: 0,
51
+
52
+ setPhase: (phase) => set({ phase }),
53
+
54
+ setContext: (ctx) => set({ context: ctx }),
55
+
56
+ updateContextVar: (key, value) =>
57
+ set((s) => ({ context: { ...s.context, [key]: value } })),
58
+
59
+ appendConsole: (type, text) =>
60
+ set((s) => ({
61
+ console: [...s.console, { id: s.nextConsoleId, timestamp: Date.now(), type, text }],
62
+ nextConsoleId: s.nextConsoleId + 1,
63
+ })),
64
+
65
+ clearConsole: () => set({ console: [], nextConsoleId: 0 }),
66
+
67
+ reset: () =>
68
+ set({
69
+ phase: { status: "inactive" },
70
+ context: {},
71
+ console: [],
72
+ nextConsoleId: 0,
73
+ }),
74
+ }));