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