@bian-womp/spark-graph 0.3.86 → 0.3.87

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 (31) hide show
  1. package/lib/cjs/index.cjs +39 -77
  2. package/lib/cjs/index.cjs.map +1 -1
  3. package/lib/cjs/src/core/types.d.ts +0 -1
  4. package/lib/cjs/src/core/types.d.ts.map +1 -1
  5. package/lib/cjs/src/runtime/Engine.d.ts +1 -3
  6. package/lib/cjs/src/runtime/Engine.d.ts.map +1 -1
  7. package/lib/cjs/src/runtime/GraphRuntime.d.ts +2 -1
  8. package/lib/cjs/src/runtime/GraphRuntime.d.ts.map +1 -1
  9. package/lib/cjs/src/runtime/LocalEngine.d.ts +1 -5
  10. package/lib/cjs/src/runtime/LocalEngine.d.ts.map +1 -1
  11. package/lib/cjs/src/runtime/components/EdgePropagator.d.ts +0 -4
  12. package/lib/cjs/src/runtime/components/EdgePropagator.d.ts.map +1 -1
  13. package/lib/cjs/src/runtime/components/NodeExecutor.d.ts.map +1 -1
  14. package/lib/cjs/src/runtime/components/RunContextManager.d.ts +0 -2
  15. package/lib/cjs/src/runtime/components/RunContextManager.d.ts.map +1 -1
  16. package/lib/esm/index.js +39 -77
  17. package/lib/esm/index.js.map +1 -1
  18. package/lib/esm/src/core/types.d.ts +0 -1
  19. package/lib/esm/src/core/types.d.ts.map +1 -1
  20. package/lib/esm/src/runtime/Engine.d.ts +1 -3
  21. package/lib/esm/src/runtime/Engine.d.ts.map +1 -1
  22. package/lib/esm/src/runtime/GraphRuntime.d.ts +2 -1
  23. package/lib/esm/src/runtime/GraphRuntime.d.ts.map +1 -1
  24. package/lib/esm/src/runtime/LocalEngine.d.ts +1 -5
  25. package/lib/esm/src/runtime/LocalEngine.d.ts.map +1 -1
  26. package/lib/esm/src/runtime/components/EdgePropagator.d.ts +0 -4
  27. package/lib/esm/src/runtime/components/EdgePropagator.d.ts.map +1 -1
  28. package/lib/esm/src/runtime/components/NodeExecutor.d.ts.map +1 -1
  29. package/lib/esm/src/runtime/components/RunContextManager.d.ts +0 -2
  30. package/lib/esm/src/runtime/components/RunContextManager.d.ts.map +1 -1
  31. package/package.json +2 -2
package/lib/cjs/index.cjs CHANGED
@@ -1884,7 +1884,6 @@ class RunContextManager {
1884
1884
  pendingEdges: 0,
1885
1885
  pendingResolvers: 0,
1886
1886
  pendingQueued: 0,
1887
- skipPropagateValues: options?.skipPropagateValues ?? false,
1888
1887
  propagate: options?.propagate ?? true,
1889
1888
  resolve: options?.resolve,
1890
1889
  };
@@ -1892,7 +1891,6 @@ class RunContextManager {
1892
1891
  this.logger.info("create-run-context", {
1893
1892
  id,
1894
1893
  startNodeId,
1895
- skipPropagateValues: ctx.skipPropagateValues,
1896
1894
  propagate: ctx.propagate,
1897
1895
  });
1898
1896
  return id;
@@ -2943,12 +2941,11 @@ class EdgePropagator {
2943
2941
  if (!shouldExecute) {
2944
2942
  return; // No change and no reason to rerun
2945
2943
  }
2946
- // Set input value (respecting skipPropagateValues)
2947
- const shouldSetValue = this.shouldSetInputValue(effectiveRunContexts);
2948
- if (shouldSetValue && valueChanged) {
2944
+ // Set input value
2945
+ if (valueChanged) {
2949
2946
  this.runtime.setTargetInput(edge, processedValue, "applyToTarget");
2950
2947
  }
2951
- else if (shouldSetValue && !valueChanged) {
2948
+ else {
2952
2949
  // Even if value didn't change, update timestamp if we're forcing execution
2953
2950
  const now = Date.now();
2954
2951
  this.graph.updateNodeLastInputAt(edge.target.nodeId, edge.target.handle, now);
@@ -2986,22 +2983,6 @@ class EdgePropagator {
2986
2983
  }
2987
2984
  return merged;
2988
2985
  }
2989
- /**
2990
- * Check if input value should be set (respecting skipPropagateValues)
2991
- */
2992
- shouldSetInputValue(effectiveRunContexts) {
2993
- if (!effectiveRunContexts) {
2994
- return true; // Auto mode always sets values
2995
- }
2996
- // Check skipPropagateValues (only in run-context mode)
2997
- for (const id of effectiveRunContexts) {
2998
- const ctx = this.runContextManager.getRunContext(id);
2999
- if (ctx && ctx.skipPropagateValues) {
3000
- return false;
3001
- }
3002
- }
3003
- return true;
3004
- }
3005
2986
  /**
3006
2987
  * Execute downstream if conditions are met
3007
2988
  */
@@ -3090,8 +3071,6 @@ class EdgePropagator {
3090
3071
  * If undefined or empty, behaves like auto mode (always propagates values and execution).
3091
3072
  */
3092
3073
  propagate(srcNodeId, srcHandle, value, runContextIds) {
3093
- if (this.runtime.isPaused())
3094
- return;
3095
3074
  // Set source output
3096
3075
  if (!this.setSourceOutput(srcNodeId, srcHandle, value)) {
3097
3076
  return; // Node was removed
@@ -3108,8 +3087,6 @@ class EdgePropagator {
3108
3087
  * Only re-emits outputs that are valid according to resolved handles
3109
3088
  */
3110
3089
  invalidateDownstream(nodeId) {
3111
- if (this.runtime.isPaused())
3112
- return;
3113
3090
  const node = this.graph.getNode(nodeId);
3114
3091
  if (!node)
3115
3092
  return;
@@ -3952,29 +3929,36 @@ class GraphRuntime {
3952
3929
  const e = event;
3953
3930
  return e.action === "invalidate";
3954
3931
  }
3932
+ withRunContext(nodeId, options, run) {
3933
+ const runContextId = this.runContextManager.createRunContext(nodeId, options);
3934
+ try {
3935
+ return run(new Set([runContextId]));
3936
+ }
3937
+ finally {
3938
+ this.runContextManager.releaseScheduling(runContextId);
3939
+ }
3940
+ }
3941
+ withManualNoPropagateContext(nodeId, run) {
3942
+ if (this.runMode !== "manual") {
3943
+ run(undefined);
3944
+ return;
3945
+ }
3946
+ this.withRunContext(nodeId, { propagate: false }, (runContextIds) => {
3947
+ run(runContextIds);
3948
+ });
3949
+ }
3955
3950
  executeNodeAutoRun(nodeId, opts) {
3956
3951
  const node = this.graph.getNode(nodeId);
3957
3952
  const shouldAutoRun = this.runMode === "auto" || node?.policy?.autoRun === true;
3958
3953
  const canExecute = this.graph.allInboundHaveValue(nodeId);
3959
3954
  if (!shouldAutoRun || !canExecute)
3960
3955
  return;
3961
- let runContextIdsToUse = undefined;
3962
- let runContextIdToRelease;
3963
- if (this.runMode === "manual") {
3964
- runContextIdToRelease = this.runContextManager.createRunContext(nodeId, { propagate: false });
3965
- runContextIdsToUse = new Set([runContextIdToRelease]);
3966
- }
3967
- try {
3956
+ this.withManualNoPropagateContext(nodeId, (runContextIds) => {
3968
3957
  this.execute(nodeId, {
3969
- runContextIds: runContextIdsToUse,
3958
+ runContextIds,
3970
3959
  reason: opts?.reason ?? "executeNodeAutoRun",
3971
3960
  });
3972
- }
3973
- finally {
3974
- if (runContextIdToRelease) {
3975
- this.runContextManager.releaseScheduling(runContextIdToRelease);
3976
- }
3977
- }
3961
+ });
3978
3962
  }
3979
3963
  setInputs(nodeId, inputs) {
3980
3964
  const node = this.graph.getNode(nodeId);
@@ -4203,20 +4187,19 @@ class GraphRuntime {
4203
4187
  if (!node)
4204
4188
  return;
4205
4189
  return new Promise((resolve) => {
4206
- const id = this.runContextManager.createRunContext(startNodeId, {
4207
- resolve,
4190
+ this.withRunContext(startNodeId, {
4208
4191
  ...opts,
4209
- });
4210
- this.graph.addNodeRunContextId(startNodeId, id);
4211
- try {
4192
+ resolve,
4193
+ }, (runContextIds) => {
4194
+ const [runContextId] = runContextIds;
4195
+ if (runContextId) {
4196
+ this.graph.addNodeRunContextId(startNodeId, runContextId);
4197
+ }
4212
4198
  this.execute(startNodeId, {
4213
- runContextIds: new Set([id]),
4199
+ runContextIds,
4214
4200
  reason: opts?.reason ?? "runFromHereContext",
4215
4201
  });
4216
- }
4217
- finally {
4218
- this.runContextManager.releaseScheduling(id);
4219
- }
4202
+ });
4220
4203
  });
4221
4204
  }
4222
4205
  setRunMode(runMode) {
@@ -4276,18 +4259,13 @@ class GraphRuntime {
4276
4259
  this.handleResolver.scheduleRecomputeHandles(toNodeId);
4277
4260
  if (options?.dry) {
4278
4261
  // Dry copy should propagate values only, never schedule node execution.
4279
- const runContextId = this.runContextManager.createRunContext(toNodeId, { propagate: false });
4280
- const runContextIds = new Set([runContextId]);
4281
- try {
4262
+ this.withRunContext(toNodeId, { propagate: false }, (runContextIds) => {
4282
4263
  for (const [handle, value] of Object.entries(fromNode.outputs || {})) {
4283
4264
  if (value !== undefined) {
4284
4265
  this.propagate(toNodeId, handle, value, runContextIds);
4285
4266
  }
4286
4267
  }
4287
- }
4288
- finally {
4289
- this.runContextManager.releaseScheduling(runContextId);
4290
- }
4268
+ });
4291
4269
  return;
4292
4270
  }
4293
4271
  this.executeNodeAutoRun(toNodeId, { reason: "copyOutputs" });
@@ -4553,22 +4531,9 @@ class GraphRuntime {
4553
4531
  if (!setsEqual(beforeTargetSet, afterTargetSet)) {
4554
4532
  const val = this.getOutput(nodeId, handle);
4555
4533
  if (val !== undefined) {
4556
- let runContextIdsToUse = undefined;
4557
- let runContextIdToRelease;
4558
- if (this.runMode === "manual") {
4559
- runContextIdToRelease = this.runContextManager.createRunContext(nodeId, {
4560
- propagate: false,
4561
- });
4562
- runContextIdsToUse = new Set([runContextIdToRelease]);
4563
- }
4564
- try {
4565
- this.propagate(nodeId, handle, val, runContextIdsToUse);
4566
- }
4567
- finally {
4568
- if (runContextIdToRelease) {
4569
- this.runContextManager.releaseScheduling(runContextIdToRelease);
4570
- }
4571
- }
4534
+ this.withManualNoPropagateContext(nodeId, (runContextIds) => {
4535
+ this.propagate(nodeId, handle, val, runContextIds);
4536
+ });
4572
4537
  }
4573
4538
  }
4574
4539
  }
@@ -4941,12 +4906,9 @@ class LocalEngine {
4941
4906
  * Run only this node, no downstream propagation.
4942
4907
  * Works in both modes, but typically only used in manual mode.
4943
4908
  * @param nodeId - The node to run
4944
- * @param options - Execution options
4945
- * @param options.skipPropagateValues - If true, don't set inputs of linked nodes (default: false)
4946
4909
  */
4947
- async computeNode(nodeId, options) {
4910
+ async computeNode(nodeId) {
4948
4911
  await this.graphRuntime.runFromHereContext(nodeId, {
4949
- skipPropagateValues: options?.skipPropagateValues ?? false,
4950
4912
  propagate: false, // Don't schedule downstream nodes
4951
4913
  reason: "computeNode",
4952
4914
  });