@foresthubai/workflow-builder 0.4.2 → 0.4.4

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 (123) hide show
  1. package/LICENSE +661 -661
  2. package/NOTICE +16 -16
  3. package/README.md +110 -110
  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/hooks/useWorkflowSerialization.d.ts.map +1 -1
  11. package/dist/hooks/useWorkflowSerialization.js +8 -11
  12. package/dist/hooks/useWorkflowSerialization.js.map +1 -1
  13. package/package.json +2 -2
  14. package/src/BuilderLayout.tsx +345 -345
  15. package/src/Canvas.tsx +261 -261
  16. package/src/CanvasEditor.tsx +142 -142
  17. package/src/CanvasTabsToolbar.tsx +176 -176
  18. package/src/RightConfigPanel.tsx +266 -266
  19. package/src/WorkflowBuilder.tsx +408 -408
  20. package/src/cn.ts +6 -6
  21. package/src/components/ui/add-button.tsx +39 -39
  22. package/src/components/ui/alert-dialog.tsx +141 -141
  23. package/src/components/ui/alert.tsx +59 -59
  24. package/src/components/ui/badge.tsx +36 -36
  25. package/src/components/ui/button.tsx +85 -85
  26. package/src/components/ui/card.tsx +79 -79
  27. package/src/components/ui/checkbox.tsx +28 -28
  28. package/src/components/ui/collapsible.tsx +9 -9
  29. package/src/components/ui/command.tsx +153 -153
  30. package/src/components/ui/delete-button.tsx +23 -23
  31. package/src/components/ui/dialog.tsx +125 -125
  32. package/src/components/ui/dropdown-menu.tsx +198 -198
  33. package/src/components/ui/input.tsx +55 -55
  34. package/src/components/ui/label.tsx +24 -24
  35. package/src/components/ui/readonly-banner.tsx +15 -15
  36. package/src/components/ui/resizable.tsx +43 -43
  37. package/src/components/ui/scroll-area.tsx +102 -102
  38. package/src/components/ui/select.tsx +160 -160
  39. package/src/components/ui/separator.tsx +29 -29
  40. package/src/components/ui/switch.tsx +27 -27
  41. package/src/components/ui/textarea.tsx +51 -51
  42. package/src/components/ui/toast.tsx +127 -127
  43. package/src/components/ui/toaster.tsx +33 -33
  44. package/src/components/ui/toggle-group.tsx +59 -59
  45. package/src/components/ui/toggle.tsx +43 -43
  46. package/src/components/ui/tooltip.tsx +32 -32
  47. package/src/dialogs/NodePickerDialog.tsx +84 -84
  48. package/src/dialogs/ValidationDialog.tsx +184 -184
  49. package/src/graph/BaseNode.tsx +557 -557
  50. package/src/graph/CustomEdge.tsx +185 -185
  51. package/src/graph/CustomNode.tsx +16 -16
  52. package/src/graph/FunctionCallNode.tsx +30 -30
  53. package/src/graph/PortHandle.tsx +189 -189
  54. package/src/graph/reactFlowRegistry.ts +26 -26
  55. package/src/hooks/use-toast.ts +125 -125
  56. package/src/hooks/useAvailableVariables.ts +20 -20
  57. package/src/hooks/useCanvasHistory.ts +22 -22
  58. package/src/hooks/useCanvasTabs.ts +168 -168
  59. package/src/hooks/useFunctionDiagnosticsSync.ts +40 -40
  60. package/src/hooks/useFunctionRegistry.ts +26 -26
  61. package/src/hooks/useFunctions.ts +44 -44
  62. package/src/hooks/useGraph.ts +161 -161
  63. package/src/hooks/useNodeDefinitions.ts +82 -82
  64. package/src/hooks/useParamErrors.ts +26 -26
  65. package/src/hooks/useResolvedTheme.ts +30 -30
  66. package/src/hooks/useResourceDiagnosticsSync.ts +58 -58
  67. package/src/hooks/useSuppressThemeTransition.ts +79 -79
  68. package/src/hooks/useWorkflowSerialization.ts +141 -144
  69. package/src/i18n/index.ts +53 -53
  70. package/src/i18n/locales/de.json +501 -501
  71. package/src/i18n/locales/en.json +557 -557
  72. package/src/index.ts +27 -27
  73. package/src/inputs/ExpressionInput.tsx +297 -297
  74. package/src/inputs/ParameterEditor.tsx +515 -515
  75. package/src/inputs/PortSection.tsx +144 -144
  76. package/src/panels/BuilderSidebar.tsx +301 -301
  77. package/src/panels/ChannelConfigPanel.tsx +49 -49
  78. package/src/panels/ChannelsPanel.tsx +28 -28
  79. package/src/panels/DebugConsolePanel.tsx +73 -73
  80. package/src/panels/DebugContextPanel.tsx +77 -77
  81. package/src/panels/DebugExternalIOPanel.tsx +180 -180
  82. package/src/panels/DiagnosticsPanel.tsx +170 -170
  83. package/src/panels/EdgeConfigPanel.tsx +104 -104
  84. package/src/panels/FunctionConfigPanel.tsx +179 -179
  85. package/src/panels/FunctionListPanel.tsx +45 -45
  86. package/src/panels/MemoryConfigPanel.tsx +55 -55
  87. package/src/panels/MemoryPanel.tsx +40 -40
  88. package/src/panels/ModelConfigPanel.tsx +41 -41
  89. package/src/panels/ModelsPanel.tsx +36 -36
  90. package/src/panels/NodeConfigPanel.tsx +630 -630
  91. package/src/panels/NodeLibrary.tsx +288 -288
  92. package/src/panels/ResourceConfigPanel.tsx +132 -132
  93. package/src/panels/ResourceListPanel.tsx +113 -113
  94. package/src/panels/VariableConfigPanel.tsx +161 -161
  95. package/src/panels/VariablesPanel.tsx +145 -145
  96. package/src/stores/canvasStore.test.ts +44 -44
  97. package/src/stores/canvasStore.ts +245 -245
  98. package/src/stores/debugStore.ts +74 -74
  99. package/src/stores/diagnosticsStore.ts +130 -130
  100. package/src/stores/editorStore.ts +190 -190
  101. package/src/styles/index.css +526 -526
  102. package/src/utils/categoryConstants.ts +26 -26
  103. package/src/utils/channelOperations.ts +86 -86
  104. package/src/utils/connectionRules.ts +137 -137
  105. package/src/utils/functionOperations.ts +179 -179
  106. package/src/utils/graphOperations.ts +550 -550
  107. package/src/utils/history.ts +207 -207
  108. package/src/utils/memoryOperations.ts +57 -57
  109. package/src/utils/migrateFunctionNodes.ts +107 -107
  110. package/src/utils/modelOperations.ts +55 -55
  111. package/src/utils/paramDisplay.ts +71 -71
  112. package/src/utils/resourceHelpers.ts +32 -32
  113. package/src/utils/translation.ts +28 -28
  114. package/src/utils/variableOperations.ts +75 -75
  115. package/tailwind-preset.ts +166 -166
  116. package/dist/lib/utils.d.ts +0 -3
  117. package/dist/lib/utils.d.ts.map +0 -1
  118. package/dist/lib/utils.js +0 -6
  119. package/dist/lib/utils.js.map +0 -1
  120. package/dist/toolbars/CanvasTabsToolbar.d.ts +0 -11
  121. package/dist/toolbars/CanvasTabsToolbar.d.ts.map +0 -1
  122. package/dist/toolbars/CanvasTabsToolbar.js +0 -101
  123. package/dist/toolbars/CanvasTabsToolbar.js.map +0 -1
@@ -1,190 +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
- 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
- }));
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
+ }));