@bian-womp/spark-workbench 0.2.43 → 0.2.44

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.
package/lib/cjs/index.cjs CHANGED
@@ -736,11 +736,7 @@ class RemoteGraphRunner extends AbstractGraphRunner {
736
736
  /**
737
737
  * Setup event subscriptions for the client.
738
738
  */
739
- setupClientSubscriptions(client, backend) {
740
- // Subscribe to custom events (for additional listeners if needed)
741
- if (backend.onCustomEvent) {
742
- this.customEventUnsubscribe = client.subscribeCustomEvents(backend.onCustomEvent);
743
- }
739
+ setupClientSubscriptions(client) {
744
740
  // Subscribe to transport status changes
745
741
  // Convert RuntimeApiClient.TransportStatus to IGraphRunner.TransportStatus
746
742
  this.transportStatusUnsubscribe = client.onTransportStatus((status) => {
@@ -772,7 +768,7 @@ class RemoteGraphRunner extends AbstractGraphRunner {
772
768
  onCustomEvent: backend.onCustomEvent,
773
769
  });
774
770
  // Setup event subscriptions
775
- this.setupClientSubscriptions(client, backend);
771
+ this.setupClientSubscriptions(client);
776
772
  // Connect the client (this will create and connect transport)
777
773
  await client.connect();
778
774
  this.client = client;
@@ -1126,11 +1122,8 @@ class RemoteGraphRunner extends AbstractGraphRunner {
1126
1122
  super.dispose();
1127
1123
  // Clear client promise if any
1128
1124
  this.clientPromise = undefined;
1129
- // Unsubscribe from custom events and transport status
1130
- if (this.customEventUnsubscribe) {
1131
- this.customEventUnsubscribe();
1132
- this.customEventUnsubscribe = undefined;
1133
- }
1125
+ // Unsubscribe from transport status
1126
+ // Note: Custom events are cleaned up automatically when client is disposed
1134
1127
  if (this.transportStatusUnsubscribe) {
1135
1128
  this.transportStatusUnsubscribe();
1136
1129
  this.transportStatusUnsubscribe = undefined;
@@ -2057,35 +2050,23 @@ function WorkbenchProvider({ wb, runner, registry, setRegistry, overrides, uiVer
2057
2050
  ];
2058
2051
  return next.length > 200 ? next.slice(0, 200) : next;
2059
2052
  });
2060
- // Helper to refresh resolved handles from remote and merge into workbench
2061
- const refreshResolvedHandles = async () => {
2062
- try {
2063
- const snap = await runner.snapshotFull();
2064
- const remoteDef = snap?.def;
2065
- if (remoteDef && Array.isArray(remoteDef.nodes)) {
2066
- // Mutate current def in-place to avoid emitting graphChanged and causing update loop
2067
- const cur = wb.export();
2068
- const byId = new Map((remoteDef.nodes || []).map((n) => [
2069
- n.nodeId,
2070
- n,
2071
- ]));
2072
- let changed = false;
2073
- for (const n of cur.nodes) {
2074
- const rn = byId.get(n.nodeId);
2075
- if (rn && rn.resolvedHandles) {
2076
- const before = JSON.stringify(n.resolvedHandles || {});
2077
- const after = JSON.stringify(rn.resolvedHandles || {});
2078
- if (before !== after) {
2079
- n.resolvedHandles = rn.resolvedHandles;
2080
- changed = true;
2081
- }
2082
- }
2053
+ // Helper to apply resolved handles from event payload to workbench
2054
+ const applyResolvedHandles = (resolvedHandles) => {
2055
+ const cur = wb.export();
2056
+ let changed = false;
2057
+ for (const n of cur.nodes) {
2058
+ const updated = resolvedHandles[n.nodeId];
2059
+ if (updated) {
2060
+ const before = JSON.stringify(n.resolvedHandles || {});
2061
+ const after = JSON.stringify(updated);
2062
+ if (before !== after) {
2063
+ n.resolvedHandles = updated;
2064
+ changed = true;
2083
2065
  }
2084
- if (changed)
2085
- wb.refreshValidation();
2086
2066
  }
2087
2067
  }
2088
- catch { }
2068
+ if (changed)
2069
+ wb.refreshValidation();
2089
2070
  };
2090
2071
  const offRunnerValue = runner.on("value", (e) => {
2091
2072
  if (e?.io === "input") {
@@ -2167,9 +2148,9 @@ function WorkbenchProvider({ wb, runner, registry, setRegistry, overrides, uiVer
2167
2148
  return add("runner", "error")(e);
2168
2149
  });
2169
2150
  const offRunnerInvalidate = runner.on("invalidate", (e) => {
2170
- // After build/update, pull resolved handles and merge in-place (no graphChanged)
2171
- if (e?.reason === "graph-updated" || e?.reason === "graph-built") {
2172
- refreshResolvedHandles();
2151
+ // If resolvedHandles are included in the event, use them directly (more efficient)
2152
+ if (e?.resolvedHandles && Object.keys(e.resolvedHandles).length > 0) {
2153
+ applyResolvedHandles(e.resolvedHandles);
2173
2154
  }
2174
2155
  return add("runner", "invalidate")(e);
2175
2156
  });