@foresthubai/workflow-builder 0.3.0 → 0.4.1

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 (124) hide show
  1. package/LICENSE +661 -661
  2. package/NOTICE +16 -16
  3. package/README.md +110 -93
  4. package/dist/components/ui/command.d.ts +2 -2
  5. package/dist/components/ui/input.d.ts +1 -1
  6. package/dist/components/ui/resizable.d.ts +1 -1
  7. package/dist/components/ui/textarea.d.ts +1 -1
  8. package/dist/graph/BaseNode.js +10 -10
  9. package/dist/graph/reactFlowRegistry.d.ts.map +1 -1
  10. package/dist/lib/utils.d.ts +3 -0
  11. package/dist/lib/utils.d.ts.map +1 -0
  12. package/dist/lib/utils.js +6 -0
  13. package/dist/lib/utils.js.map +1 -0
  14. package/dist/stores/editorStore.d.ts +0 -1
  15. package/dist/stores/editorStore.d.ts.map +1 -1
  16. package/dist/stores/editorStore.js +1 -11
  17. package/dist/stores/editorStore.js.map +1 -1
  18. package/dist/toolbars/CanvasTabsToolbar.d.ts +11 -0
  19. package/dist/toolbars/CanvasTabsToolbar.d.ts.map +1 -0
  20. package/dist/toolbars/CanvasTabsToolbar.js +101 -0
  21. package/dist/toolbars/CanvasTabsToolbar.js.map +1 -0
  22. package/package.json +2 -2
  23. package/src/BuilderLayout.tsx +345 -345
  24. package/src/Canvas.tsx +261 -261
  25. package/src/CanvasEditor.tsx +142 -142
  26. package/src/CanvasTabsToolbar.tsx +176 -176
  27. package/src/RightConfigPanel.tsx +266 -266
  28. package/src/WorkflowBuilder.tsx +412 -412
  29. package/src/cn.ts +6 -6
  30. package/src/components/ui/add-button.tsx +39 -39
  31. package/src/components/ui/alert-dialog.tsx +141 -141
  32. package/src/components/ui/alert.tsx +59 -59
  33. package/src/components/ui/badge.tsx +36 -36
  34. package/src/components/ui/button.tsx +85 -85
  35. package/src/components/ui/card.tsx +79 -79
  36. package/src/components/ui/checkbox.tsx +28 -28
  37. package/src/components/ui/collapsible.tsx +9 -9
  38. package/src/components/ui/command.tsx +153 -153
  39. package/src/components/ui/delete-button.tsx +23 -23
  40. package/src/components/ui/dialog.tsx +125 -125
  41. package/src/components/ui/dropdown-menu.tsx +198 -198
  42. package/src/components/ui/input.tsx +55 -55
  43. package/src/components/ui/label.tsx +24 -24
  44. package/src/components/ui/readonly-banner.tsx +15 -15
  45. package/src/components/ui/resizable.tsx +43 -43
  46. package/src/components/ui/scroll-area.tsx +102 -102
  47. package/src/components/ui/select.tsx +160 -160
  48. package/src/components/ui/separator.tsx +29 -29
  49. package/src/components/ui/switch.tsx +27 -27
  50. package/src/components/ui/textarea.tsx +51 -51
  51. package/src/components/ui/toast.tsx +127 -127
  52. package/src/components/ui/toaster.tsx +33 -33
  53. package/src/components/ui/toggle-group.tsx +59 -59
  54. package/src/components/ui/toggle.tsx +43 -43
  55. package/src/components/ui/tooltip.tsx +32 -32
  56. package/src/dialogs/NodePickerDialog.tsx +84 -84
  57. package/src/dialogs/ValidationDialog.tsx +184 -184
  58. package/src/graph/BaseNode.tsx +557 -557
  59. package/src/graph/CustomEdge.tsx +185 -185
  60. package/src/graph/CustomNode.tsx +16 -16
  61. package/src/graph/FunctionCallNode.tsx +30 -30
  62. package/src/graph/PortHandle.tsx +189 -189
  63. package/src/graph/reactFlowRegistry.ts +26 -26
  64. package/src/hooks/use-toast.ts +125 -125
  65. package/src/hooks/useAvailableVariables.ts +20 -20
  66. package/src/hooks/useCanvasHistory.ts +22 -22
  67. package/src/hooks/useCanvasTabs.ts +168 -168
  68. package/src/hooks/useFunctionDiagnosticsSync.ts +40 -40
  69. package/src/hooks/useFunctionRegistry.ts +26 -26
  70. package/src/hooks/useFunctions.ts +44 -44
  71. package/src/hooks/useGraph.ts +161 -161
  72. package/src/hooks/useNodeDefinitions.ts +82 -82
  73. package/src/hooks/useParamErrors.ts +26 -26
  74. package/src/hooks/useResolvedTheme.ts +30 -30
  75. package/src/hooks/useResourceDiagnosticsSync.ts +58 -58
  76. package/src/hooks/useSuppressThemeTransition.ts +79 -79
  77. package/src/hooks/useWorkflowSerialization.ts +127 -127
  78. package/src/i18n/index.ts +53 -53
  79. package/src/i18n/locales/de.json +501 -501
  80. package/src/i18n/locales/en.json +557 -557
  81. package/src/index.ts +27 -27
  82. package/src/inputs/ExpressionInput.tsx +297 -297
  83. package/src/inputs/ParameterEditor.tsx +515 -515
  84. package/src/inputs/PortSection.tsx +144 -144
  85. package/src/panels/BuilderSidebar.tsx +301 -301
  86. package/src/panels/ChannelConfigPanel.tsx +49 -49
  87. package/src/panels/ChannelsPanel.tsx +28 -28
  88. package/src/panels/DebugConsolePanel.tsx +73 -73
  89. package/src/panels/DebugContextPanel.tsx +77 -77
  90. package/src/panels/DebugExternalIOPanel.tsx +180 -180
  91. package/src/panels/DiagnosticsPanel.tsx +170 -170
  92. package/src/panels/EdgeConfigPanel.tsx +104 -104
  93. package/src/panels/FunctionConfigPanel.tsx +179 -179
  94. package/src/panels/FunctionListPanel.tsx +45 -45
  95. package/src/panels/MemoryConfigPanel.tsx +55 -55
  96. package/src/panels/MemoryPanel.tsx +40 -40
  97. package/src/panels/ModelConfigPanel.tsx +41 -41
  98. package/src/panels/ModelsPanel.tsx +36 -36
  99. package/src/panels/NodeConfigPanel.tsx +630 -630
  100. package/src/panels/NodeLibrary.tsx +288 -288
  101. package/src/panels/ResourceConfigPanel.tsx +132 -132
  102. package/src/panels/ResourceListPanel.tsx +113 -113
  103. package/src/panels/VariableConfigPanel.tsx +161 -161
  104. package/src/panels/VariablesPanel.tsx +145 -145
  105. package/src/stores/canvasStore.test.ts +44 -44
  106. package/src/stores/canvasStore.ts +245 -245
  107. package/src/stores/debugStore.ts +74 -74
  108. package/src/stores/diagnosticsStore.ts +130 -130
  109. package/src/stores/editorStore.ts +190 -202
  110. package/src/styles/index.css +526 -526
  111. package/src/utils/categoryConstants.ts +26 -26
  112. package/src/utils/channelOperations.ts +86 -86
  113. package/src/utils/connectionRules.ts +137 -137
  114. package/src/utils/functionOperations.ts +179 -179
  115. package/src/utils/graphOperations.ts +550 -550
  116. package/src/utils/history.ts +207 -207
  117. package/src/utils/memoryOperations.ts +57 -57
  118. package/src/utils/migrateFunctionNodes.ts +107 -107
  119. package/src/utils/modelOperations.ts +55 -55
  120. package/src/utils/paramDisplay.ts +71 -71
  121. package/src/utils/resourceHelpers.ts +32 -32
  122. package/src/utils/translation.ts +28 -28
  123. package/src/utils/variableOperations.ts +75 -75
  124. package/tailwind-preset.ts +166 -166
@@ -1,202 +1,190 @@
1
- import { create } from "zustand";
2
- import { getCanvasStore, getOrCreateCanvasStore, MAIN_CANVAS_ID } from "./canvasStore";
3
- import type { Channel } from "@foresthubai/workflow-core/channel";
4
- import type { Memory } from "@foresthubai/workflow-core/memory";
5
- import type { Model, ModelInfo } from "@foresthubai/workflow-core/model";
6
- import type { FunctionDeclaration } from "@foresthubai/workflow-core/function";
7
-
8
- // ---------------------------------------------------------------------------
9
- // Default Channelsevery workflow starts pre-initialized with a UART
10
- // port so nodes that need a serial port (SerialRead/Write, OnSerialReceive)
11
- // have something to bind to out of the box. Domain shape only — the driver
12
- // binding is supplied at deploy time via the DeploymentMapping, not here.
13
- // ---------------------------------------------------------------------------
14
-
15
- export function createDefaultChannels(): Record<string, Channel> {
16
- const uart: Channel = { id: "uart0", label: "Serial", type: "UART", arguments: {} };
17
- return { [uart.id]: uart };
18
- }
19
-
20
- import type { BuilderMode } from "../WorkflowBuilder";
21
- // Type-only (erased) the active left-sidebar tab lives here so non-sidebar code
22
- // (e.g. validation navigation) can open a specific panel. No runtime cycle.
23
- import type { SidebarTab } from "../panels/BuilderSidebar";
24
-
25
- // ---------------------------------------------------------------------------
26
- // Selection
27
- // ---------------------------------------------------------------------------
28
-
29
- /**
30
- * What the editor is focused on, driving right-side config-panel visibility.
31
- * A discriminated union so exclusivity is structural: at most one primitive is
32
- * ever selected, except nodes+edges which coexist under `graph` (box-select can
33
- * grab both). The only way to mutate it is the select* / clearSelection actions,
34
- * each of which replaces the whole value — no field can drift out of sync.
35
- */
36
- export type Selection =
37
- | { kind: "none" }
38
- | { kind: "graph"; nodeIds: string[]; edgeIds: string[] }
39
- | { kind: "channel"; id: string }
40
- | { kind: "memory"; id: string }
41
- | { kind: "model"; id: string }
42
- | { kind: "function"; id: string }
43
- | { kind: "variable"; uid: string };
44
-
45
- const NO_SELECTION: Selection = { kind: "none" };
46
-
47
- // Drop ReactFlow's visual selection on a canvas so previously-glowing nodes/edges
48
- // stop glowing. Peek (never create) — clearing selection must not resurrect a
49
- // canvas store that was just dropped (e.g. after clearAllCanvasStores).
50
- function clearRFselect(canvasId: string): void {
51
- getCanvasStore(canvasId)?.getState().setRFselect([], []);
52
- }
53
-
54
- // ---------------------------------------------------------------------------
55
- // Store
56
- // ---------------------------------------------------------------------------
57
-
58
- interface EditorState {
59
- activeCanvasId: string;
60
- activeSidebarTab: SidebarTab;
61
- builderMode: BuilderMode;
62
- selection: Selection;
63
- // Project-scoped channels (pins, buses) shared across all canvases
64
- channels: Record<string, Channel>;
65
- // Project-scoped memory primitives (memory files + vector databases) — shared
66
- // across all canvases, referenced from nodes by id.
67
- memory: Record<string, Memory>;
68
- // Project-scoped declared custom/self-hosted models (channel-like) referenced
69
- // from nodes by id, mapped to llmproxy providers at deploy.
70
- models: Record<string, Model>;
71
- // Project-scoped function declarations (signature + bundled output assignments).
72
- // The body of each lives in the matching canvas store (id === fn.id). Like the
73
- // other resources above, edits here are NOT undo-tracked.
74
- functions: Record<string, FunctionDeclaration>;
75
- // The static model catalog (what the llmproxy supports), supplied by the
76
- // embedder via WorkflowBuilderProps.models. Not workflow state config only.
77
- availableModels: ModelInfo[];
78
- /**
79
- * Monotonic counter bumped on project-scoped domain mutations
80
- * (channels/memory/models). Mirrors canvasStores' history mutationCount so the
81
- * builder can fire a single onChange event from either source.
82
- */
83
- mutationCount: number;
84
- setActiveCanvas: (canvasId: string) => void;
85
- setBuilderMode: (mode: BuilderMode) => void;
86
- /** Programmatic graph selection (change selection and pushes into ReactFlow). */
87
- selectGraph: (nodeIds: string[], edgeIds: string[]) => void;
88
- /** ReactFlow-origin graph selection fires onSelectionChange which needs to update the editor state without pushing back to ReactFlow. */
89
- syncSelectionFromRF: (nodeIds: string[], edgeIds: string[]) => void;
90
- selectChannel: (id: string) => void;
91
- selectMemory: (id: string) => void;
92
- selectModel: (id: string) => void;
93
- /** Select a function AND switch the active canvas to its body (id === canvasId), so
94
- * the config panel's return-expression editors resolve against the body's scope. */
95
- selectFunction: (id: string) => void;
96
- selectVariable: (uid: string) => void;
97
- clearSelection: () => void;
98
- setActiveSidebarTab: (tab: SidebarTab) => void;
99
- setChannels: (updater: (vars: Record<string, Channel>) => Record<string, Channel>) => void;
100
- setMemory: (updater: (mem: Record<string, Memory>) => Record<string, Memory>) => void;
101
- setModels: (updater: (models: Record<string, Model>) => Record<string, Model>) => void;
102
- setFunctions: (updater: (funcs: Record<string, FunctionDeclaration>) => Record<string, FunctionDeclaration>) => void;
103
- setAvailableModels: (models: ModelInfo[]) => void;
104
- }
105
-
106
- export const useEditorStore = create<EditorState>((set, get) => ({
107
- activeCanvasId: MAIN_CANVAS_ID,
108
- builderMode: { type: "edit" },
109
- selection: NO_SELECTION,
110
- activeSidebarTab: "nodes",
111
- channels: createDefaultChannels(),
112
- memory: {},
113
- models: {},
114
- functions: {},
115
- availableModels: [],
116
- mutationCount: 0,
117
- // A `variable` selection is canvas-local; its uid would resolve to nothing (or,
118
- // worse, a collision) on the new canvas, so drop it. A `function` selection is
119
- // tied to being on that function's body canvas (selectFunction switches to it),
120
- // so leaving that canvas drops it too switching INTO a function tab instead
121
- // routes through selectFunction (see useCanvasTabs.setActiveTabId), not here.
122
- // Project-scoped channel/memory/model selections survive the switch.
123
- setActiveCanvas: (canvasId: string) =>
124
- set((state) => ({
125
- activeCanvasId: canvasId,
126
- selection:
127
- state.selection.kind === "variable" || state.selection.kind === "function" ? NO_SELECTION : state.selection,
128
- })),
129
- setBuilderMode: (mode: BuilderMode) => set({ builderMode: mode }),
130
- selectGraph: (nodeIds, edgeIds) => {
131
- set({ selection: nodeIds.length || edgeIds.length ? { kind: "graph", nodeIds, edgeIds } : NO_SELECTION });
132
- // Programmatic pick — mirror it into ReactFlow so the canvas reflects it.
133
- getOrCreateCanvasStore(get().activeCanvasId).getState().setRFselect(nodeIds, edgeIds);
134
- },
135
- syncSelectionFromRF: (nodeIds, edgeIds) => {
136
- if (nodeIds.length || edgeIds.length) {
137
- // A selection made on the canvas (click, box-drag) is hoisted into the editor state.
138
- // A programmatic selectGraph also round-trips here via onSelectionChange; that just re-sets an
139
- // equal value (one benign re-render), so it needs no special-casing.
140
- set({ selection: { kind: "graph", nodeIds, edgeIds } });
141
- } else if (get().selection.kind === "graph") {
142
- // Empty while a graph selection was active = user deselected on the canvas.
143
- set({ selection: NO_SELECTION });
144
- }
145
- // Empty + non-graph kind = echo of the canvas-clear we triggered when picking
146
- // a channel/memory/etc; ignore it, or it would wipe that pick.
147
- },
148
- selectChannel: (id) => {
149
- set({ selection: { kind: "channel", id } });
150
- clearRFselect(get().activeCanvasId);
151
- },
152
- selectMemory: (id) => {
153
- set({ selection: { kind: "memory", id } });
154
- clearRFselect(get().activeCanvasId);
155
- },
156
- selectModel: (id) => {
157
- set({ selection: { kind: "model", id } });
158
- clearRFselect(get().activeCanvasId);
159
- },
160
- selectFunction: (id) => {
161
- // Drop the outgoing canvas's RF selection, then focus the function: select it
162
- // AND make its body the active canvas so the config panel's expression editors
163
- // resolve against the function's local variable scope.
164
- clearRFselect(get().activeCanvasId);
165
- set({ selection: { kind: "function", id }, activeCanvasId: id });
166
- },
167
- selectVariable: (uid) => {
168
- set({ selection: { kind: "variable", uid } });
169
- clearRFselect(get().activeCanvasId);
170
- },
171
- clearSelection: () => {
172
- set({ selection: NO_SELECTION });
173
- clearRFselect(get().activeCanvasId);
174
- },
175
- setActiveSidebarTab: (tab) => set({ activeSidebarTab: tab }),
176
- setChannels: (updater) =>
177
- set((state) => {
178
- const next = updater(state.channels);
179
- if (next === state.channels) return state;
180
- return { channels: next, mutationCount: state.mutationCount + 1 };
181
- }),
182
- setMemory: (updater) =>
183
- set((state) => {
184
- const next = updater(state.memory);
185
- if (next === state.memory) return state;
186
- return { memory: next, mutationCount: state.mutationCount + 1 };
187
- }),
188
- setModels: (updater) =>
189
- set((state) => {
190
- const next = updater(state.models);
191
- if (next === state.models) return state;
192
- return { models: next, mutationCount: state.mutationCount + 1 };
193
- }),
194
- setFunctions: (updater) =>
195
- set((state) => {
196
- const next = updater(state.functions);
197
- if (next === state.functions) return state;
198
- return { functions: next, mutationCount: state.mutationCount + 1 };
199
- }),
200
- // Catalog is config (from props), not workflow content — never bumps mutationCount.
201
- setAvailableModels: (models) => set({ availableModels: models }),
202
- }));
1
+ import { create } from "zustand";
2
+ import { getCanvasStore, getOrCreateCanvasStore, MAIN_CANVAS_ID } from "./canvasStore";
3
+ import type { Channel } from "@foresthubai/workflow-core/channel";
4
+ import type { Memory } from "@foresthubai/workflow-core/memory";
5
+ import type { Model, ModelInfo } from "@foresthubai/workflow-core/model";
6
+ import type { FunctionDeclaration } from "@foresthubai/workflow-core/function";
7
+
8
+ import type { BuilderMode } from "../WorkflowBuilder";
9
+ // Type-only (erased)the active left-sidebar tab lives here so non-sidebar code
10
+ // (e.g. validation navigation) can open a specific panel. No runtime cycle.
11
+ import type { SidebarTab } from "../panels/BuilderSidebar";
12
+
13
+ // ---------------------------------------------------------------------------
14
+ // Selection
15
+ // ---------------------------------------------------------------------------
16
+
17
+ /**
18
+ * What the editor is focused on, driving right-side config-panel visibility.
19
+ * A discriminated union so exclusivity is structural: at most one primitive is
20
+ * ever selected, except nodes+edges which coexist under `graph` (box-select can
21
+ * grab both). The only way to mutate it is the select* / clearSelection actions,
22
+ * each of which replaces the whole value no field can drift out of sync.
23
+ */
24
+ export type Selection =
25
+ | { kind: "none" }
26
+ | { kind: "graph"; nodeIds: string[]; edgeIds: string[] }
27
+ | { kind: "channel"; id: string }
28
+ | { kind: "memory"; id: string }
29
+ | { kind: "model"; id: string }
30
+ | { kind: "function"; id: string }
31
+ | { kind: "variable"; uid: string };
32
+
33
+ const NO_SELECTION: Selection = { kind: "none" };
34
+
35
+ // Drop ReactFlow's visual selection on a canvas so previously-glowing nodes/edges
36
+ // stop glowing. Peek (never create) — clearing selection must not resurrect a
37
+ // canvas store that was just dropped (e.g. after clearAllCanvasStores).
38
+ function clearRFselect(canvasId: string): void {
39
+ getCanvasStore(canvasId)?.getState().setRFselect([], []);
40
+ }
41
+
42
+ // ---------------------------------------------------------------------------
43
+ // Store
44
+ // ---------------------------------------------------------------------------
45
+
46
+ interface EditorState {
47
+ activeCanvasId: string;
48
+ activeSidebarTab: SidebarTab;
49
+ builderMode: BuilderMode;
50
+ selection: Selection;
51
+ // Project-scoped channels (pins, buses) — shared across all canvases
52
+ channels: Record<string, Channel>;
53
+ // Project-scoped memory primitives (memory files + vector databases) — shared
54
+ // across all canvases, referenced from nodes by id.
55
+ memory: Record<string, Memory>;
56
+ // Project-scoped declared custom/self-hosted models (channel-like) — referenced
57
+ // from nodes by id, mapped to llmproxy providers at deploy.
58
+ models: Record<string, Model>;
59
+ // Project-scoped function declarations (signature + bundled output assignments).
60
+ // The body of each lives in the matching canvas store (id === fn.id). Like the
61
+ // other resources above, edits here are NOT undo-tracked.
62
+ functions: Record<string, FunctionDeclaration>;
63
+ // The static model catalog (what the llmproxy supports), supplied by the
64
+ // embedder via WorkflowBuilderProps.models. Not workflow state — config only.
65
+ availableModels: ModelInfo[];
66
+ /**
67
+ * Monotonic counter bumped on project-scoped domain mutations
68
+ * (channels/memory/models). Mirrors canvasStores' history mutationCount so the
69
+ * builder can fire a single onChange event from either source.
70
+ */
71
+ mutationCount: number;
72
+ setActiveCanvas: (canvasId: string) => void;
73
+ setBuilderMode: (mode: BuilderMode) => void;
74
+ /** Programmatic graph selection (change selection and pushes into ReactFlow). */
75
+ selectGraph: (nodeIds: string[], edgeIds: string[]) => void;
76
+ /** ReactFlow-origin graph selection fires onSelectionChange which needs to update the editor state without pushing back to ReactFlow. */
77
+ syncSelectionFromRF: (nodeIds: string[], edgeIds: string[]) => void;
78
+ selectChannel: (id: string) => void;
79
+ selectMemory: (id: string) => void;
80
+ selectModel: (id: string) => void;
81
+ /** Select a function AND switch the active canvas to its body (id === canvasId), so
82
+ * the config panel's return-expression editors resolve against the body's scope. */
83
+ selectFunction: (id: string) => void;
84
+ selectVariable: (uid: string) => void;
85
+ clearSelection: () => void;
86
+ setActiveSidebarTab: (tab: SidebarTab) => void;
87
+ setChannels: (updater: (vars: Record<string, Channel>) => Record<string, Channel>) => void;
88
+ setMemory: (updater: (mem: Record<string, Memory>) => Record<string, Memory>) => void;
89
+ setModels: (updater: (models: Record<string, Model>) => Record<string, Model>) => void;
90
+ setFunctions: (updater: (funcs: Record<string, FunctionDeclaration>) => Record<string, FunctionDeclaration>) => void;
91
+ setAvailableModels: (models: ModelInfo[]) => void;
92
+ }
93
+
94
+ export const useEditorStore = create<EditorState>((set, get) => ({
95
+ activeCanvasId: MAIN_CANVAS_ID,
96
+ builderMode: { type: "edit" },
97
+ selection: NO_SELECTION,
98
+ activeSidebarTab: "nodes",
99
+ channels: {},
100
+ memory: {},
101
+ models: {},
102
+ functions: {},
103
+ availableModels: [],
104
+ mutationCount: 0,
105
+ // A `variable` selection is canvas-local; its uid would resolve to nothing (or,
106
+ // worse, a collision) on the new canvas, so drop it. A `function` selection is
107
+ // tied to being on that function's body canvas (selectFunction switches to it),
108
+ // so leaving that canvas drops it too — switching INTO a function tab instead
109
+ // routes through selectFunction (see useCanvasTabs.setActiveTabId), not here.
110
+ // Project-scoped channel/memory/model selections survive the switch.
111
+ setActiveCanvas: (canvasId: string) =>
112
+ set((state) => ({
113
+ activeCanvasId: canvasId,
114
+ selection:
115
+ state.selection.kind === "variable" || state.selection.kind === "function" ? NO_SELECTION : state.selection,
116
+ })),
117
+ setBuilderMode: (mode: BuilderMode) => set({ builderMode: mode }),
118
+ selectGraph: (nodeIds, edgeIds) => {
119
+ set({ selection: nodeIds.length || edgeIds.length ? { kind: "graph", nodeIds, edgeIds } : NO_SELECTION });
120
+ // Programmatic pick mirror it into ReactFlow so the canvas reflects it.
121
+ getOrCreateCanvasStore(get().activeCanvasId).getState().setRFselect(nodeIds, edgeIds);
122
+ },
123
+ syncSelectionFromRF: (nodeIds, edgeIds) => {
124
+ if (nodeIds.length || edgeIds.length) {
125
+ // A selection made on the canvas (click, box-drag) is hoisted into the editor state.
126
+ // A programmatic selectGraph also round-trips here via onSelectionChange; that just re-sets an
127
+ // equal value (one benign re-render), so it needs no special-casing.
128
+ set({ selection: { kind: "graph", nodeIds, edgeIds } });
129
+ } else if (get().selection.kind === "graph") {
130
+ // Empty while a graph selection was active = user deselected on the canvas.
131
+ set({ selection: NO_SELECTION });
132
+ }
133
+ // Empty + non-graph kind = echo of the canvas-clear we triggered when picking
134
+ // a channel/memory/etc; ignore it, or it would wipe that pick.
135
+ },
136
+ selectChannel: (id) => {
137
+ set({ selection: { kind: "channel", id } });
138
+ clearRFselect(get().activeCanvasId);
139
+ },
140
+ selectMemory: (id) => {
141
+ set({ selection: { kind: "memory", id } });
142
+ clearRFselect(get().activeCanvasId);
143
+ },
144
+ selectModel: (id) => {
145
+ set({ selection: { kind: "model", id } });
146
+ clearRFselect(get().activeCanvasId);
147
+ },
148
+ selectFunction: (id) => {
149
+ // Drop the outgoing canvas's RF selection, then focus the function: select it
150
+ // AND make its body the active canvas so the config panel's expression editors
151
+ // resolve against the function's local variable scope.
152
+ clearRFselect(get().activeCanvasId);
153
+ set({ selection: { kind: "function", id }, activeCanvasId: id });
154
+ },
155
+ selectVariable: (uid) => {
156
+ set({ selection: { kind: "variable", uid } });
157
+ clearRFselect(get().activeCanvasId);
158
+ },
159
+ clearSelection: () => {
160
+ set({ selection: NO_SELECTION });
161
+ clearRFselect(get().activeCanvasId);
162
+ },
163
+ setActiveSidebarTab: (tab) => set({ activeSidebarTab: tab }),
164
+ setChannels: (updater) =>
165
+ set((state) => {
166
+ const next = updater(state.channels);
167
+ if (next === state.channels) return state;
168
+ return { channels: next, mutationCount: state.mutationCount + 1 };
169
+ }),
170
+ setMemory: (updater) =>
171
+ set((state) => {
172
+ const next = updater(state.memory);
173
+ if (next === state.memory) return state;
174
+ return { memory: next, mutationCount: state.mutationCount + 1 };
175
+ }),
176
+ setModels: (updater) =>
177
+ set((state) => {
178
+ const next = updater(state.models);
179
+ if (next === state.models) return state;
180
+ return { models: next, mutationCount: state.mutationCount + 1 };
181
+ }),
182
+ setFunctions: (updater) =>
183
+ set((state) => {
184
+ const next = updater(state.functions);
185
+ if (next === state.functions) return state;
186
+ return { functions: next, mutationCount: state.mutationCount + 1 };
187
+ }),
188
+ // Catalog is config (from props), not workflow content — never bumps mutationCount.
189
+ setAvailableModels: (models) => set({ availableModels: models }),
190
+ }));