@bian-womp/spark-workbench 0.3.2 → 0.3.3

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 (45) hide show
  1. package/lib/cjs/index.cjs +253 -131
  2. package/lib/cjs/index.cjs.map +1 -1
  3. package/lib/cjs/src/core/InMemoryWorkbench.d.ts +53 -0
  4. package/lib/cjs/src/core/InMemoryWorkbench.d.ts.map +1 -1
  5. package/lib/cjs/src/core/contracts.d.ts +16 -0
  6. package/lib/cjs/src/core/contracts.d.ts.map +1 -1
  7. package/lib/cjs/src/misc/WorkbenchCanvas.d.ts.map +1 -1
  8. package/lib/cjs/src/misc/WorkbenchStudio.d.ts.map +1 -1
  9. package/lib/cjs/src/misc/context/WorkbenchContext.d.ts +0 -3
  10. package/lib/cjs/src/misc/context/WorkbenchContext.d.ts.map +1 -1
  11. package/lib/cjs/src/misc/context/WorkbenchContext.provider.d.ts.map +1 -1
  12. package/lib/cjs/src/misc/load.d.ts.map +1 -1
  13. package/lib/cjs/src/misc/mapping.d.ts +7 -0
  14. package/lib/cjs/src/misc/mapping.d.ts.map +1 -1
  15. package/lib/cjs/src/runtime/AbstractGraphRunner.d.ts +6 -4
  16. package/lib/cjs/src/runtime/AbstractGraphRunner.d.ts.map +1 -1
  17. package/lib/cjs/src/runtime/IGraphRunner.d.ts +5 -3
  18. package/lib/cjs/src/runtime/IGraphRunner.d.ts.map +1 -1
  19. package/lib/cjs/src/runtime/LocalGraphRunner.d.ts +7 -0
  20. package/lib/cjs/src/runtime/LocalGraphRunner.d.ts.map +1 -1
  21. package/lib/cjs/src/runtime/RemoteGraphRunner.d.ts +4 -0
  22. package/lib/cjs/src/runtime/RemoteGraphRunner.d.ts.map +1 -1
  23. package/lib/esm/index.js +254 -132
  24. package/lib/esm/index.js.map +1 -1
  25. package/lib/esm/src/core/InMemoryWorkbench.d.ts +53 -0
  26. package/lib/esm/src/core/InMemoryWorkbench.d.ts.map +1 -1
  27. package/lib/esm/src/core/contracts.d.ts +16 -0
  28. package/lib/esm/src/core/contracts.d.ts.map +1 -1
  29. package/lib/esm/src/misc/WorkbenchCanvas.d.ts.map +1 -1
  30. package/lib/esm/src/misc/WorkbenchStudio.d.ts.map +1 -1
  31. package/lib/esm/src/misc/context/WorkbenchContext.d.ts +0 -3
  32. package/lib/esm/src/misc/context/WorkbenchContext.d.ts.map +1 -1
  33. package/lib/esm/src/misc/context/WorkbenchContext.provider.d.ts.map +1 -1
  34. package/lib/esm/src/misc/load.d.ts.map +1 -1
  35. package/lib/esm/src/misc/mapping.d.ts +7 -0
  36. package/lib/esm/src/misc/mapping.d.ts.map +1 -1
  37. package/lib/esm/src/runtime/AbstractGraphRunner.d.ts +6 -4
  38. package/lib/esm/src/runtime/AbstractGraphRunner.d.ts.map +1 -1
  39. package/lib/esm/src/runtime/IGraphRunner.d.ts +5 -3
  40. package/lib/esm/src/runtime/IGraphRunner.d.ts.map +1 -1
  41. package/lib/esm/src/runtime/LocalGraphRunner.d.ts +7 -0
  42. package/lib/esm/src/runtime/LocalGraphRunner.d.ts.map +1 -1
  43. package/lib/esm/src/runtime/RemoteGraphRunner.d.ts +4 -0
  44. package/lib/esm/src/runtime/RemoteGraphRunner.d.ts.map +1 -1
  45. package/package.json +4 -4
package/lib/cjs/index.cjs CHANGED
@@ -146,6 +146,7 @@ class InMemoryWorkbench extends AbstractWorkbench {
146
146
  edges: [],
147
147
  };
148
148
  this.nodeNames = {};
149
+ this.customData = {};
149
150
  this.runtimeState = null;
150
151
  this.viewport = null;
151
152
  this.historyState = undefined;
@@ -174,6 +175,17 @@ class InMemoryWorkbench extends AbstractWorkbench {
174
175
  const filteredSizes = Object.fromEntries(Object.entries(this.sizes).filter(([id]) => defNodeIds.has(id)));
175
176
  const filteredNodes = this.selection.nodes.filter((id) => defNodeIds.has(id));
176
177
  const filteredEdges = this.selection.edges.filter((id) => defEdgeIds.has(id));
178
+ // Clean up extData for removed nodes/edges
179
+ if (this.customData.nodes) {
180
+ const filteredExtNodes = Object.fromEntries(Object.entries(this.customData.nodes).filter(([id]) => defNodeIds.has(id)));
181
+ this.customData.nodes =
182
+ Object.keys(filteredExtNodes).length > 0 ? filteredExtNodes : undefined;
183
+ }
184
+ if (this.customData.edges) {
185
+ const filteredExtEdges = Object.fromEntries(Object.entries(this.customData.edges).filter(([id]) => defEdgeIds.has(id)));
186
+ this.customData.edges =
187
+ Object.keys(filteredExtEdges).length > 0 ? filteredExtEdges : undefined;
188
+ }
177
189
  this.positions = filteredPositions;
178
190
  this.sizes = filteredSizes;
179
191
  this.selection = { nodes: filteredNodes, edges: filteredEdges };
@@ -851,6 +863,107 @@ class InMemoryWorkbench extends AbstractWorkbench {
851
863
  ...options,
852
864
  });
853
865
  }
866
+ /**
867
+ * Get custom data for a specific node.
868
+ */
869
+ getCustomNodeData(nodeId) {
870
+ return this.customData.nodes?.[nodeId];
871
+ }
872
+ /**
873
+ * Set custom data for a specific node.
874
+ */
875
+ setCustomNodeData(nodeId, data, options) {
876
+ if (!this.customData.nodes) {
877
+ this.customData.nodes = {};
878
+ }
879
+ if (data === undefined) {
880
+ delete this.customData.nodes[nodeId];
881
+ if (Object.keys(this.customData.nodes).length === 0) {
882
+ delete this.customData.nodes;
883
+ }
884
+ }
885
+ else {
886
+ this.customData.nodes[nodeId] = data;
887
+ }
888
+ this.emit("graphUiChanged", {
889
+ change: { type: "customNodeData", nodeId, data },
890
+ ...options,
891
+ });
892
+ }
893
+ /**
894
+ * Get custom data for a specific edge.
895
+ */
896
+ getCustomEdgeData(edgeId) {
897
+ return this.customData.edges?.[edgeId];
898
+ }
899
+ /**
900
+ * Set custom data for a specific edge.
901
+ */
902
+ setCustomEdgeData(edgeId, data, options) {
903
+ if (!this.customData.edges) {
904
+ this.customData.edges = {};
905
+ }
906
+ if (data === undefined) {
907
+ delete this.customData.edges[edgeId];
908
+ if (Object.keys(this.customData.edges).length === 0) {
909
+ delete this.customData.edges;
910
+ }
911
+ }
912
+ else {
913
+ this.customData.edges[edgeId] = data;
914
+ }
915
+ this.emit("graphUiChanged", {
916
+ change: { type: "customEdgeData", edgeId, data },
917
+ ...options,
918
+ });
919
+ }
920
+ /**
921
+ * Get custom metadata.
922
+ */
923
+ getCustomMetaData() {
924
+ return this.customData.meta;
925
+ }
926
+ /**
927
+ * Set custom metadata.
928
+ */
929
+ setCustomMetaData(meta, options) {
930
+ if (meta === undefined) {
931
+ delete this.customData.meta;
932
+ }
933
+ else {
934
+ this.customData.meta = meta;
935
+ }
936
+ this.emit("graphUiChanged", {
937
+ change: { type: "customMetaData", meta },
938
+ ...options,
939
+ });
940
+ }
941
+ /**
942
+ * Get all custom data.
943
+ */
944
+ getCustomData() {
945
+ return { ...this.customData };
946
+ }
947
+ /**
948
+ * Set all custom data.
949
+ */
950
+ setCustomData(custom, options) {
951
+ if (custom === undefined) {
952
+ this.customData = {};
953
+ }
954
+ else {
955
+ this.customData = lod.pick(custom, ["nodes", "edges", "meta"]);
956
+ }
957
+ this.emit("graphUiChanged", {
958
+ change: {
959
+ type: "customData",
960
+ nodes: custom?.nodes,
961
+ edges: custom?.edges,
962
+ meta: custom?.meta,
963
+ },
964
+ ...options,
965
+ });
966
+ }
854
967
  }
855
968
 
856
969
  class CLIWorkbench {
@@ -911,36 +1024,14 @@ class AbstractGraphRunner {
911
1024
  this.stagedInputs = {};
912
1025
  this.runnerId = "";
913
1026
  }
914
- launch(def, opts) {
915
- // Auto-stop if engine is already running
916
- if (this.engine) {
917
- this.stop();
918
- }
919
- }
920
1027
  async whenIdle() {
921
1028
  await this.engine?.whenIdle();
922
1029
  }
923
- stop() {
924
- if (!this.engine)
925
- return;
926
- // Dispose engine (cleans up timers, listeners, etc.)
927
- this.engine.dispose();
928
- this.engine = undefined;
929
- // Emit status but keep runtime alive
930
- if (this.runMode) {
931
- this.runMode = undefined;
932
- this.emit("status", { running: false, runMode: undefined });
933
- }
934
- }
935
1030
  setRunMode(runMode) {
936
- if (!this.engine) {
937
- throw new Error("Cannot set run mode: engine not running");
1031
+ if (this.engine) {
1032
+ this.engine.setRunMode(runMode);
1033
+ this.emit("status", { running: true, runMode });
938
1034
  }
939
- // Update engine run mode (this will update pause/resume state)
940
- this.engine.setRunMode(runMode);
941
- // Update local state and emit status event
942
- this.runMode = runMode;
943
- this.emit("status", { running: true, runMode: this.runMode });
944
1035
  }
945
1036
  getInputDefaults(def) {
946
1037
  const out = {};
@@ -970,17 +1061,10 @@ class AbstractGraphRunner {
970
1061
  this.engine = undefined;
971
1062
  this.runtime?.dispose();
972
1063
  this.runtime = undefined;
973
- if (this.runMode) {
974
- this.runMode = undefined;
975
- this.emit("status", { running: false, runMode: undefined });
976
- }
977
1064
  }
978
1065
  isRunning() {
979
1066
  return !!this.engine;
980
1067
  }
981
- getRunMode() {
982
- return this.runMode;
983
- }
984
1068
  // Optional undo/redo support
985
1069
  async undo() {
986
1070
  return false;
@@ -999,6 +1083,7 @@ let localRunnerCounter = 0;
999
1083
  class LocalGraphRunner extends AbstractGraphRunner {
1000
1084
  constructor(registry) {
1001
1085
  super(registry, { kind: "local" });
1086
+ this.extData = {};
1002
1087
  this.setEnvironment = (env, opts) => {
1003
1088
  if (!this.runtime)
1004
1089
  return;
@@ -1047,7 +1132,10 @@ class LocalGraphRunner extends AbstractGraphRunner {
1047
1132
  }
1048
1133
  }
1049
1134
  launch(def, opts) {
1050
- super.launch(def, opts);
1135
+ if (this.engine) {
1136
+ this.engine.dispose();
1137
+ this.engine = undefined;
1138
+ }
1051
1139
  this.build(def);
1052
1140
  if (!this.runtime)
1053
1141
  throw new Error("Runtime not built");
@@ -1074,8 +1162,8 @@ class LocalGraphRunner extends AbstractGraphRunner {
1074
1162
  this.engine.on("invalidate", (e) => this.emit("invalidate", e));
1075
1163
  this.engine.on("stats", (e) => this.emit("stats", e));
1076
1164
  this.engine.launch(opts?.invalidate);
1077
- this.runMode = opts?.runMode ?? "manual";
1078
- this.emit("status", { running: true, runMode: this.runMode });
1165
+ const runMode = opts?.runMode ?? "manual";
1166
+ this.emit("status", { running: true, runMode });
1079
1167
  for (const [nodeId, map] of Object.entries(this.stagedInputs)) {
1080
1168
  this.engine.setInputs(nodeId, map);
1081
1169
  }
@@ -1169,6 +1257,24 @@ class LocalGraphRunner extends AbstractGraphRunner {
1169
1257
  this.engine.copyOutputs(fromNodeId, toNodeId, options);
1170
1258
  }
1171
1259
  }
1260
+ async setExtData(data) {
1261
+ if (!data || typeof data !== "object") {
1262
+ this.extData = {};
1263
+ return;
1264
+ }
1265
+ this.extData = { ...this.extData, ...data };
1266
+ }
1267
+ async updateExtData(updates) {
1268
+ if (!this.extData ||
1269
+ typeof this.extData !== "object" ||
1270
+ Array.isArray(this.extData)) {
1271
+ this.extData = {};
1272
+ }
1273
+ for (const { path, value } of updates) {
1274
+ const pathSegments = sparkGraph.parseJsonPath(path);
1275
+ sparkGraph.setValueAtPathWithCreation(this.extData, pathSegments, value);
1276
+ }
1277
+ }
1172
1278
  async snapshotFull() {
1173
1279
  const def = undefined; // UI will supply def/positions on download for local
1174
1280
  const inputs = this.getInputs(this.runtime
@@ -1190,7 +1296,8 @@ class LocalGraphRunner extends AbstractGraphRunner {
1190
1296
  }
1191
1297
  : { nodes: [], edges: [] });
1192
1298
  const environment = this.getEnvironment() || {};
1193
- return { def, environment, inputs, outputs };
1299
+ const extData = this.extData;
1300
+ return { def, environment, inputs, outputs, extData };
1194
1301
  }
1195
1302
  async applySnapshotFull(payload, options) {
1196
1303
  if (payload.def && !options?.skipBuild) {
@@ -1198,6 +1305,9 @@ class LocalGraphRunner extends AbstractGraphRunner {
1198
1305
  }
1199
1306
  this.setEnvironment?.(payload.environment || {}, { merge: false });
1200
1307
  this.hydrate(payload, { dry: options?.dry });
1308
+ if (payload.extData) {
1309
+ await this.setExtData(payload.extData);
1310
+ }
1201
1311
  }
1202
1312
  hydrate(snapshot, opts) {
1203
1313
  // Hydrate via runtime for exact restore (this emits events on runtime emitter)
@@ -1567,7 +1677,10 @@ class RemoteGraphRunner extends AbstractGraphRunner {
1567
1677
  }
1568
1678
  }
1569
1679
  launch(def, opts) {
1570
- super.launch(def, opts);
1680
+ if (this.engine) {
1681
+ this.engine.dispose();
1682
+ this.engine = undefined;
1683
+ }
1571
1684
  // Remote: build remotely then launch
1572
1685
  this.ensureClient().then(async (client) => {
1573
1686
  await client.api.build(def);
@@ -1623,8 +1736,8 @@ class RemoteGraphRunner extends AbstractGraphRunner {
1623
1736
  this.listenersBound = true;
1624
1737
  }
1625
1738
  this.engine = eng;
1626
- this.runMode = opts?.runMode ?? "manual";
1627
- this.emit("status", { running: true, runMode: this.runMode });
1739
+ const runMode = opts?.runMode ?? "manual";
1740
+ this.emit("status", { running: true, runMode });
1628
1741
  // Re-apply staged inputs using client.setInputs for consistency
1629
1742
  for (const [nodeId, map] of Object.entries(this.stagedInputs)) {
1630
1743
  await eng.setInputs(nodeId, map, undefined).catch(() => {
@@ -1640,7 +1753,10 @@ class RemoteGraphRunner extends AbstractGraphRunner {
1640
1753
  * the runtime state that was just restored.
1641
1754
  */
1642
1755
  launchExisting(def, opts) {
1643
- super.launch(def, opts);
1756
+ if (this.engine) {
1757
+ this.engine.dispose();
1758
+ this.engine = undefined;
1759
+ }
1644
1760
  // Remote: attach to existing runtime and launch (do NOT rebuild)
1645
1761
  this.ensureClient().then(async (client) => {
1646
1762
  // NOTE: We do NOT call client.build(def) here because the backend runtime
@@ -1651,14 +1767,10 @@ class RemoteGraphRunner extends AbstractGraphRunner {
1651
1767
  });
1652
1768
  }
1653
1769
  setRunMode(runMode) {
1654
- if (!this.engine) {
1655
- throw new Error("Cannot set run mode: engine not running");
1770
+ if (this.engine) {
1771
+ this.engine.setRunMode(runMode);
1772
+ this.emit("status", { running: true, runMode });
1656
1773
  }
1657
- // Update engine run mode (sends SetRunMode command to backend)
1658
- this.engine.setRunMode(runMode);
1659
- // Update local state and emit status event
1660
- this.runMode = runMode;
1661
- this.emit("status", { running: true, runMode: this.runMode });
1662
1774
  }
1663
1775
  async computeNode(nodeId, options) {
1664
1776
  const client = await this.ensureClient();
@@ -1721,6 +1833,10 @@ class RemoteGraphRunner extends AbstractGraphRunner {
1721
1833
  const client = await this.ensureClient();
1722
1834
  await client.api.setExtData(data);
1723
1835
  }
1836
+ async updateExtData(updates) {
1837
+ const client = await this.ensureClient();
1838
+ await client.api.updateExtData(updates);
1839
+ }
1724
1840
  async commit(reason) {
1725
1841
  const client = await this.ensureClient();
1726
1842
  try {
@@ -2592,35 +2708,40 @@ function toReactFlow(def, positions, sizes, registry, opts) {
2592
2708
  }));
2593
2709
  const handleLayout = geom.handleLayout;
2594
2710
  const handles = geom.handles;
2711
+ const baseData = {
2712
+ typeId: n.typeId,
2713
+ params: n.params,
2714
+ inputHandles,
2715
+ outputHandles,
2716
+ inputConnected: Object.fromEntries(inputHandles.map((h) => [
2717
+ h.id,
2718
+ !!connectedInputs[n.nodeId]?.has(h.id),
2719
+ ])),
2720
+ handleLayout,
2721
+ showValues: opts.showValues,
2722
+ renderWidth,
2723
+ renderHeight,
2724
+ initialWidth: initialGeom.width,
2725
+ initialHeight: initialGeom.height,
2726
+ inputValues: opts.inputs?.[n.nodeId],
2727
+ inputDefaults: opts.inputDefaults?.[n.nodeId],
2728
+ outputValues: opts.outputs?.[n.nodeId],
2729
+ status: opts.nodeStatus?.[n.nodeId],
2730
+ validation: {
2731
+ inputs: opts.nodeValidation?.inputs?.[n.nodeId] ?? [],
2732
+ outputs: opts.nodeValidation?.outputs?.[n.nodeId] ?? [],
2733
+ issues: opts.nodeValidation?.issues?.[n.nodeId] ?? [],
2734
+ },
2735
+ toString: opts.toString,
2736
+ toElement: opts.toElement,
2737
+ };
2738
+ const customNodeData = opts.customData?.nodes;
2739
+ const mergedData = customNodeData?.[n.nodeId]
2740
+ ? { ...baseData, custom: customNodeData[n.nodeId] }
2741
+ : baseData;
2595
2742
  return {
2596
2743
  id: n.nodeId,
2597
- data: {
2598
- typeId: n.typeId,
2599
- params: n.params,
2600
- inputHandles,
2601
- outputHandles,
2602
- inputConnected: Object.fromEntries(inputHandles.map((h) => [
2603
- h.id,
2604
- !!connectedInputs[n.nodeId]?.has(h.id),
2605
- ])),
2606
- handleLayout,
2607
- showValues: opts.showValues,
2608
- renderWidth,
2609
- renderHeight,
2610
- initialWidth: initialGeom.width,
2611
- initialHeight: initialGeom.height,
2612
- inputValues: opts.inputs?.[n.nodeId],
2613
- inputDefaults: opts.inputDefaults?.[n.nodeId],
2614
- outputValues: opts.outputs?.[n.nodeId],
2615
- status: opts.nodeStatus?.[n.nodeId],
2616
- validation: {
2617
- inputs: opts.nodeValidation?.inputs?.[n.nodeId] ?? [],
2618
- outputs: opts.nodeValidation?.outputs?.[n.nodeId] ?? [],
2619
- issues: opts.nodeValidation?.issues?.[n.nodeId] ?? [],
2620
- },
2621
- toString: opts.toString,
2622
- toElement: opts.toElement,
2623
- },
2744
+ data: mergedData,
2624
2745
  position: positions[n.nodeId] ?? { x: 0, y: 0 },
2625
2746
  type: opts.resolveNodeType?.(n.typeId) ?? "spark-default",
2626
2747
  selected: opts.selectedNodeIds
@@ -2663,6 +2784,25 @@ function toReactFlow(def, positions, sizes, registry, opts) {
2663
2784
  const targetHandleTypeId = targetHandles?.inputs[e.target.handle]
2664
2785
  ? sparkGraph.getInputTypeId(targetHandles.inputs, e.target.handle) ?? "unknown"
2665
2786
  : "unknown";
2787
+ const baseEdgeData = {
2788
+ sourceNodeId: e.source.nodeId,
2789
+ sourceNodeTypeId: sourceNode?.typeId || "unknown",
2790
+ sourceHandle: e.source.handle,
2791
+ sourceHandleTypeId,
2792
+ targetNodeId: e.target.nodeId,
2793
+ targetNodeTypeId: targetNode?.typeId || "unknown",
2794
+ targetHandle: e.target.handle,
2795
+ targetHandleTypeId,
2796
+ edgeTypeId,
2797
+ isRunning,
2798
+ hasError,
2799
+ isInvalid: isInvalidEdge,
2800
+ isMissing,
2801
+ };
2802
+ const customEdgeData = opts.customData?.edges;
2803
+ const mergedEdgeData = customEdgeData?.[e.id]
2804
+ ? { ...baseEdgeData, custom: customEdgeData[e.id] }
2805
+ : baseEdgeData;
2666
2806
  return {
2667
2807
  id: e.id,
2668
2808
  source: e.source.nodeId,
@@ -2676,21 +2816,7 @@ function toReactFlow(def, positions, sizes, registry, opts) {
2676
2816
  style,
2677
2817
  label: edgeTypeId,
2678
2818
  type: "default",
2679
- data: {
2680
- sourceNodeId: e.source.nodeId,
2681
- sourceNodeTypeId: sourceNode?.typeId || "unknown",
2682
- sourceHandle: e.source.handle,
2683
- sourceHandleTypeId,
2684
- targetNodeId: e.target.nodeId,
2685
- targetNodeTypeId: targetNode?.typeId || "unknown",
2686
- targetHandle: e.target.handle,
2687
- targetHandleTypeId,
2688
- edgeTypeId,
2689
- isRunning,
2690
- hasError,
2691
- isInvalid: isInvalidEdge,
2692
- isMissing,
2693
- },
2819
+ data: mergedEdgeData,
2694
2820
  };
2695
2821
  });
2696
2822
  return { nodes, edges };
@@ -2846,6 +2972,9 @@ async function upload(parsed, wb, runner) {
2846
2972
  if (extData.runtime && typeof extData.runtime === "object") {
2847
2973
  wb.setRuntimeState(extData.runtime);
2848
2974
  }
2975
+ if (extData.custom && typeof extData.custom === "object") {
2976
+ wb.setCustomData(extData.custom);
2977
+ }
2849
2978
  if (runner.isRunning()) {
2850
2979
  await runner.applySnapshotFull({
2851
2980
  def: wb.def,
@@ -2862,6 +2991,9 @@ async function upload(parsed, wb, runner) {
2862
2991
  runner.setInputs(nodeId, map, { dry: true });
2863
2992
  }
2864
2993
  }
2994
+ if (extData) {
2995
+ await runner.setExtData(extData);
2996
+ }
2865
2997
  }
2866
2998
  }
2867
2999
 
@@ -3658,15 +3790,7 @@ function WorkbenchProvider({ wb, runner, overrides, uiVersion, children, }) {
3658
3790
  const graphUiTick = useWorkbenchGraphUiTick(wb);
3659
3791
  const versionTick = useWorkbenchVersionTick(runner);
3660
3792
  const valuesTick = versionTick + graphTick + graphUiTick;
3661
- // Keep local runMode state loosely in sync with runner status.
3662
- // - Seed from runner.getRunMode() on mount if available.
3663
- // - On status events, update only when a non-undefined runMode is reported,
3664
- // so the UI preserves the last selected mode after stop().
3665
3793
  React.useEffect(() => {
3666
- const initialMode = runner.getRunMode();
3667
- if (initialMode) {
3668
- setRunModeState(initialMode);
3669
- }
3670
3794
  const offRunnerStatus = runner.on("status", (status) => {
3671
3795
  if (status.runMode) {
3672
3796
  setRunModeState(status.runMode);
@@ -3826,12 +3950,13 @@ function WorkbenchProvider({ wb, runner, overrides, uiVersion, children, }) {
3826
3950
  workbench.setRuntimeState(metadata);
3827
3951
  const fullUiState = workbench.getUIState();
3828
3952
  const uiWithoutViewport = excludeViewportFromUIState(fullUiState);
3829
- await graphRunner.setExtData?.({
3830
- ...(Object.keys(uiWithoutViewport || {}).length > 0
3831
- ? { ui: uiWithoutViewport }
3832
- : {}),
3833
- runtime: metadata,
3834
- });
3953
+ // Use updateExtData for efficient batched partial updates
3954
+ const updates = [];
3955
+ if (Object.keys(uiWithoutViewport || {}).length > 0) {
3956
+ updates.push({ path: "ui", value: uiWithoutViewport });
3957
+ }
3958
+ updates.push({ path: "runtime", value: metadata });
3959
+ await graphRunner.updateExtData(updates);
3835
3960
  }
3836
3961
  catch (err) {
3837
3962
  console.warn("[WorkbenchContext] Failed to save runtime metadata:", err);
@@ -4264,6 +4389,18 @@ function WorkbenchProvider({ wb, runner, overrides, uiVersion, children, }) {
4264
4389
  else if (changeType === "selection") {
4265
4390
  reason = "selection";
4266
4391
  }
4392
+ else if (changeType === "customNodeData") {
4393
+ reason = "custom-node-data";
4394
+ }
4395
+ else if (changeType === "customEdgeData") {
4396
+ reason = "custom-edge-data";
4397
+ }
4398
+ else if (changeType === "customMetaData") {
4399
+ reason = "custom-meta";
4400
+ }
4401
+ else if (changeType === "customData") {
4402
+ reason = "custom";
4403
+ }
4267
4404
  }
4268
4405
  await saveUiRuntimeMetadata(wb, runner);
4269
4406
  const history = await runner
@@ -4369,27 +4506,11 @@ function WorkbenchProvider({ wb, runner, overrides, uiVersion, children, }) {
4369
4506
  };
4370
4507
  }, [runner, wb]);
4371
4508
  const isRunning = React.useCallback(() => runner.isRunning(), [runner]);
4372
- const getRunMode = React.useCallback(() => runner.getRunMode(), [runner]);
4373
- const stop = React.useCallback(() => runner.stop(), [runner]);
4374
- // Run mode actions
4375
4509
  const setRunMode = React.useCallback((mode) => {
4376
4510
  if (mode === runMode)
4377
4511
  return;
4378
- const wasRunning = runner.isRunning();
4379
- if (wasRunning) {
4380
- // Use setRunMode to change run mode without rebuilding
4381
- try {
4382
- runner.setRunMode(mode);
4383
- setRunModeState(mode);
4384
- }
4385
- catch (err) {
4386
- console.error("Failed to set run mode:", err);
4387
- }
4388
- }
4389
- else {
4390
- // Just update state if not running (will be applied on next launch)
4391
- setRunModeState(mode);
4392
- }
4512
+ runner.setRunMode(mode);
4513
+ setRunModeState(mode);
4393
4514
  }, [runMode, runner]);
4394
4515
  const runNodeAction = React.useCallback(async (nodeId) => {
4395
4516
  await runner.computeNode(nodeId);
@@ -4491,8 +4612,6 @@ function WorkbenchProvider({ wb, runner, overrides, uiVersion, children, }) {
4491
4612
  removeRegistryError,
4492
4613
  removeInputValidationError,
4493
4614
  isRunning,
4494
- getRunMode,
4495
- stop,
4496
4615
  runMode,
4497
4616
  setRunMode,
4498
4617
  runNode: runNodeAction,
@@ -4533,8 +4652,6 @@ function WorkbenchProvider({ wb, runner, overrides, uiVersion, children, }) {
4533
4652
  events,
4534
4653
  clearEvents,
4535
4654
  isRunning,
4536
- getRunMode,
4537
- stop,
4538
4655
  runMode,
4539
4656
  setRunMode,
4540
4657
  runNodeAction,
@@ -5568,6 +5685,7 @@ const WorkbenchCanvas = React.forwardRef(({ showValues, toString, toElement, get
5568
5685
  status: n.data.status,
5569
5686
  validation: n.data.validation,
5570
5687
  inputConnected: n.data.inputConnected,
5688
+ custom: n.data.custom,
5571
5689
  },
5572
5690
  });
5573
5691
  return lod.isEqual(pick(a), pick(b));
@@ -5583,6 +5701,14 @@ const WorkbenchCanvas = React.forwardRef(({ showValues, toString, toElement, get
5583
5701
  style: e.style,
5584
5702
  label: e.label,
5585
5703
  type: e.type,
5704
+ data: e.data && {
5705
+ edgeTypeId: e.data.edgeTypeId,
5706
+ isRunning: e.data.isRunning,
5707
+ hasError: e.data.hasError,
5708
+ isInvalid: e.data.isInvalid,
5709
+ isMissing: e.data.isMissing,
5710
+ custom: e.data.custom,
5711
+ },
5586
5712
  });
5587
5713
  return lod.isEqual(pick(a), pick(b));
5588
5714
  };
@@ -5670,6 +5796,7 @@ const WorkbenchCanvas = React.forwardRef(({ showValues, toString, toElement, get
5670
5796
  selectedEdgeIds: new Set(sel.edges),
5671
5797
  getDefaultNodeSize,
5672
5798
  ui,
5799
+ customData: wb.getCustomData(),
5673
5800
  });
5674
5801
  // Retain references for unchanged items
5675
5802
  const stableNodes = retainStabilityById(prevNodesRef.current, out.nodes, isSameNode);
@@ -6225,9 +6352,6 @@ function WorkbenchStudioCanvas({ autoScroll, onAutoScrollChange, example, onExam
6225
6352
  if (isConnecting) {
6226
6353
  return (jsxRuntime.jsxs("button", { className: "border rounded px-2 py-1.5 text-gray-500 border-gray-400 flex items-center gap-1 disabled:opacity-50", disabled: true, title: "Connecting to backend...", children: [jsxRuntime.jsx(react$1.ClockClockwiseIcon, { size: 16, className: "animate-spin" }), jsxRuntime.jsx("span", { className: "font-medium ml-1", children: "Connecting..." })] }));
6227
6354
  }
6228
- if (isGraphRunning) {
6229
- return (jsxRuntime.jsxs("button", { className: "border rounded px-2 py-1.5 text-red-700 border-red-600 flex items-center gap-1 disabled:opacity-50 disabled:text-gray-400 disabled:border-gray-300", onClick: () => runner.stop(), disabled: !canControl, title: canControl ? "Stop engine" : "Waiting for connection", children: [jsxRuntime.jsx(react$1.StopIcon, { size: 16, weight: "fill" }), jsxRuntime.jsx("span", { className: "font-medium ml-1", children: "Stop" })] }));
6230
- }
6231
6355
  return (jsxRuntime.jsxs("button", { className: "border rounded px-2 py-1.5 text-green-700 border-green-600 flex items-center gap-1 disabled:text-gray-400 disabled:border-gray-300 disabled:opacity-50", onClick: (evt) => {
6232
6356
  if (evt.shiftKey && !confirm("Invalidate and re-run graph?"))
6233
6357
  return;
@@ -6614,9 +6738,7 @@ function WorkbenchStudioCanvas({ autoScroll, onAutoScrollChange, example, onExam
6614
6738
  if (mode !== runMode) {
6615
6739
  await setRunMode(mode);
6616
6740
  }
6617
- }, disabled: isGraphRunning, title: isGraphRunning
6618
- ? "Stop before switching run mode"
6619
- : "Select run mode", children: [jsxRuntime.jsx("option", { value: "manual", children: "Manual" }), jsxRuntime.jsx("option", { value: "auto", children: "Auto" })] }), renderStartStopButton(), jsxRuntime.jsx("button", { className: "border border-gray-300 rounded p-1", onClick: runAutoLayout, children: jsxRuntime.jsx(react$1.TreeStructureIcon, { size: 24 }) }), jsxRuntime.jsx("button", { className: "border border-gray-300 rounded p-1", onClick: () => canvasRef.current?.fitView?.(), title: "Fit View", children: jsxRuntime.jsx(react$1.CornersOutIcon, { size: 24 }) }), jsxRuntime.jsx("button", { className: "border border-gray-300 rounded p-1", onClick: download$1, children: jsxRuntime.jsx(react$1.DownloadIcon, { size: 24 }) }), jsxRuntime.jsx("input", { ref: uploadInputRef, type: "file", accept: "application/json,.json", className: "hidden", onChange: onUploadPicked }), jsxRuntime.jsx("button", { className: "border border-gray-300 rounded p-1", onClick: triggerUpload, children: jsxRuntime.jsx(react$1.UploadIcon, { size: 24 }) }), jsxRuntime.jsx("button", { className: "border border-gray-300 rounded p-1", onClick: async () => {
6741
+ }, title: "Select run mode", children: [jsxRuntime.jsx("option", { value: "manual", children: "Manual" }), jsxRuntime.jsx("option", { value: "auto", children: "Auto" })] }), renderStartStopButton(), jsxRuntime.jsx("button", { className: "border border-gray-300 rounded p-1", onClick: runAutoLayout, children: jsxRuntime.jsx(react$1.TreeStructureIcon, { size: 24 }) }), jsxRuntime.jsx("button", { className: "border border-gray-300 rounded p-1", onClick: () => canvasRef.current?.fitView?.(), title: "Fit View", children: jsxRuntime.jsx(react$1.CornersOutIcon, { size: 24 }) }), jsxRuntime.jsx("button", { className: "border border-gray-300 rounded p-1", onClick: download$1, children: jsxRuntime.jsx(react$1.DownloadIcon, { size: 24 }) }), jsxRuntime.jsx("input", { ref: uploadInputRef, type: "file", accept: "application/json,.json", className: "hidden", onChange: onUploadPicked }), jsxRuntime.jsx("button", { className: "border border-gray-300 rounded p-1", onClick: triggerUpload, children: jsxRuntime.jsx(react$1.UploadIcon, { size: 24 }) }), jsxRuntime.jsx("button", { className: "border border-gray-300 rounded p-1", onClick: async () => {
6620
6742
  await downloadCanvasThumbnail(canvasContainerRef.current);
6621
6743
  }, title: "Download Flow Thumbnail (SVG)", children: jsxRuntime.jsx(react$1.ImageIcon, { size: 24 }) }), jsxRuntime.jsxs("label", { className: "flex items-center gap-1", children: [jsxRuntime.jsx("input", { type: "checkbox", checked: debug, onChange: (e) => onDebugChange(e.target.checked) }), jsxRuntime.jsx(react$1.BugBeetleIcon, { size: 24, weight: debug ? "fill" : undefined })] }), jsxRuntime.jsxs("label", { className: "flex items-center gap-1", children: [jsxRuntime.jsx("input", { type: "checkbox", checked: showValues, onChange: (e) => onShowValuesChange(e.target.checked) }), jsxRuntime.jsx(react$1.ListBulletsIcon, { size: 24, weight: showValues ? "fill" : undefined })] })] }), jsxRuntime.jsxs("div", { className: "flex flex-1 min-h-0", children: [jsxRuntime.jsx("div", { className: "flex-1 min-w-0", ref: canvasContainerRef, children: jsxRuntime.jsx(WorkbenchCanvas, { ref: canvasRef, showValues: showValues, toString: toString, toElement: toElement, getDefaultNodeSize: overrides?.getDefaultNodeSize }) }), jsxRuntime.jsx(Inspector, { setInput: setInput, debug: debug, autoScroll: autoScroll, hideWorkbench: hideWorkbench, onAutoScrollChange: onAutoScrollChange, onHideWorkbenchChange: onHideWorkbenchChange, toString: toString, contextPanel: overrides?.contextPanel })] })] }));
6622
6744
  }