@bian-womp/spark-graph 0.3.65 → 0.3.67

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
@@ -76,6 +76,7 @@ function mergeInputHandleDescriptors(staticDesc, dynamicDesc) {
76
76
  const merged = {
77
77
  typeId: dynamicObj.typeId ?? staticObj.typeId,
78
78
  private: dynamicObj.private ?? staticObj.private,
79
+ defaultPolicy: dynamicObj.defaultPolicy ?? staticObj.defaultPolicy,
79
80
  };
80
81
  // Merge metadata if either has it
81
82
  if (staticObj.metadata || dynamicObj.metadata) {
@@ -2313,18 +2314,31 @@ function getEffectiveInputs(nodeId, graph, registry) {
2313
2314
  // Build set of inbound handles (wired inputs)
2314
2315
  const inboundEdges = graph.getInboundEdges(nodeId);
2315
2316
  const inbound = new Set(inboundEdges.map((e) => e.target.handle));
2317
+ const getDefaultPolicy = (handle) => {
2318
+ const resolvedDesc = resolved?.inputs?.[handle];
2319
+ const staticDesc = desc.inputs?.[handle];
2320
+ const pick = (d) => d && typeof d === "object" && "typeId" in d ? d.defaultPolicy : undefined;
2321
+ return pick(resolvedDesc) ?? pick(staticDesc);
2322
+ };
2316
2323
  // Apply defaults only for:
2317
2324
  // 1. Unbound handles that have no explicit value
2318
2325
  // 2. Static handles (not dynamically resolved)
2319
2326
  for (const [handle, defaultValue] of Object.entries(mergedDefaults)) {
2320
2327
  if (defaultValue === undefined)
2321
2328
  continue;
2322
- if (inbound.has(handle))
2323
- continue; // Don't override wired inputs
2324
2329
  if (effective[handle] !== undefined)
2325
2330
  continue; // Already has value
2326
2331
  if (dynamicHandles.has(handle))
2327
2332
  continue; // Skip defaults for dynamic handles
2333
+ const policy = getDefaultPolicy(handle);
2334
+ if (policy === "bound") {
2335
+ if (!inbound.has(handle))
2336
+ continue;
2337
+ }
2338
+ else {
2339
+ if (inbound.has(handle))
2340
+ continue;
2341
+ }
2328
2342
  // Clone to avoid shared references
2329
2343
  effective[handle] = structuredClone(defaultValue);
2330
2344
  }
@@ -2947,11 +2961,15 @@ class NodeExecutor {
2947
2961
  this.edgePropagator = edgePropagator;
2948
2962
  this.runtime = runtime;
2949
2963
  this.environment = {};
2964
+ this.customNodeData = {};
2950
2965
  this.environment = environment ?? {};
2951
2966
  }
2952
2967
  setEnvironment(environment) {
2953
2968
  this.environment = environment;
2954
2969
  }
2970
+ setCustomNodeData(customNodeData) {
2971
+ this.customNodeData = customNodeData;
2972
+ }
2955
2973
  /**
2956
2974
  * Compute effective inputs for a node by merging real inputs with defaults
2957
2975
  */
@@ -3020,6 +3038,7 @@ class NodeExecutor {
3020
3038
  },
3021
3039
  getInput: (handle) => inputs[handle],
3022
3040
  environment: this.environment,
3041
+ customNodeData: this.customNodeData[nodeId],
3023
3042
  runId,
3024
3043
  abortSignal,
3025
3044
  reportProgress,
@@ -3638,6 +3657,7 @@ class GraphRuntime {
3638
3657
  constructor() {
3639
3658
  // State
3640
3659
  this.environment = {};
3660
+ this.customNodeData = {};
3641
3661
  this.runMode = null;
3642
3662
  this.pauseRefCount = 0;
3643
3663
  this.persistentPauseToken = null;
@@ -3657,11 +3677,13 @@ class GraphRuntime {
3657
3677
  if (opts?.startPaused)
3658
3678
  gr.pause();
3659
3679
  gr.environment = opts?.environment ?? {};
3680
+ gr.customNodeData = {};
3660
3681
  // Set registry and environment on components
3661
3682
  gr.graph.setRegistry(registry);
3662
3683
  gr.handleResolver.setRegistry(registry);
3663
3684
  gr.handleResolver.setEnvironment(gr.environment);
3664
3685
  gr.nodeExecutor.setEnvironment(gr.environment);
3686
+ gr.nodeExecutor.setCustomNodeData(gr.customNodeData);
3665
3687
  gr.runtimeValidatorManager.setRegistry(registry);
3666
3688
  // Precompute per-node resolved handles (use def-provided overrides; do not compute dynamically here)
3667
3689
  const initial = gr.isPaused()
@@ -3883,6 +3905,13 @@ class GraphRuntime {
3883
3905
  this.handleResolver.scheduleRecomputeHandles(nodeId);
3884
3906
  }
3885
3907
  }
3908
+ setCustomNodeData(customNodeData) {
3909
+ this.customNodeData = { ...customNodeData };
3910
+ this.nodeExecutor.setCustomNodeData(this.customNodeData);
3911
+ }
3912
+ getCustomNodeData() {
3913
+ return { ...this.customNodeData };
3914
+ }
3886
3915
  /**
3887
3916
  * Register a runtime validator that will be called before node execution.
3888
3917
  * Validators are called in registration order - if any returns true, execution is blocked.