@bian-womp/spark-graph 0.3.4 → 0.3.5

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
@@ -1560,9 +1560,18 @@ class NodeExecutor {
1560
1560
  console.warn("NodeExecutor.execute: no runMode, skipping execution");
1561
1561
  return;
1562
1562
  }
1563
+ // In manual mode, require runContextIds unless autoRun policy is set
1563
1564
  if (runMode === "manual" && (!runContextIds || runContextIds.size === 0)) {
1564
- console.warn("NodeExecutor.execute: no runContextIds provided in manual mode, skipping execution");
1565
- return;
1565
+ // If autoRun is true, auto-generate a run context (similar to createExecutionContext pattern)
1566
+ if (node.policy?.autoRun === true) {
1567
+ runContextIds = new Set([
1568
+ this.runContextManager.createRunContext(nodeId),
1569
+ ]);
1570
+ }
1571
+ else {
1572
+ console.warn("NodeExecutor.execute: no runContextIds provided in manual mode, skipping execution");
1573
+ return;
1574
+ }
1566
1575
  }
1567
1576
  if (runMode === "auto" && runContextIds && runContextIds.size > 0) {
1568
1577
  console.warn("NodeExecutor.execute: runContextIds provided in auto mode, ignoring");
@@ -2109,9 +2118,12 @@ class GraphRuntime {
2109
2118
  }
2110
2119
  }
2111
2120
  // In auto mode, input updates can trigger execution; in manual mode they never should.
2121
+ // However, if autoRun policy is set, nodes run automatically even in manual mode.
2112
2122
  if (anyChanged) {
2113
2123
  this.handleResolver.scheduleRecomputeHandles(nodeId);
2114
- if (this.runMode === "auto" && this.graph.allInboundHaveValue(nodeId)) {
2124
+ const node = this.graph.getNode(nodeId);
2125
+ const shouldAutoRun = this.runMode === "auto" || node?.policy?.autoRun === true;
2126
+ if (shouldAutoRun && this.graph.allInboundHaveValue(nodeId)) {
2115
2127
  this.execute(nodeId);
2116
2128
  }
2117
2129
  }
@@ -2385,6 +2397,14 @@ class GraphRuntime {
2385
2397
  }
2386
2398
  else {
2387
2399
  existing.params = n.params;
2400
+ // Re-merge policy when params change (params.policy can override descriptor/category policy)
2401
+ const desc = registry.nodes.get(existing.typeId);
2402
+ const cat = registry.categories.get(desc?.categoryId ?? "");
2403
+ existing.policy = {
2404
+ ...cat?.policy,
2405
+ ...desc?.policy,
2406
+ ...n.params?.policy,
2407
+ };
2388
2408
  if (!existing.stats) {
2389
2409
  existing.stats = {
2390
2410
  runs: 0,
@@ -3242,6 +3262,7 @@ function setupBasicGraphRegistry(id) {
3242
3262
  categoryId: "compute",
3243
3263
  inputs: { Value: "base.float" },
3244
3264
  outputs: { Result: "base.float" },
3265
+ policy: { autoRun: true },
3245
3266
  impl: (ins) => ({ Result: Number(ins.Value) }),
3246
3267
  });
3247
3268
  registry.registerNode({
@@ -3249,6 +3270,7 @@ function setupBasicGraphRegistry(id) {
3249
3270
  categoryId: "compute",
3250
3271
  inputs: { Value: "base.string" },
3251
3272
  outputs: { Result: "base.string" },
3273
+ policy: { autoRun: true },
3252
3274
  impl: (ins) => ({ Result: String(ins.Value) }),
3253
3275
  });
3254
3276
  registry.registerNode({
@@ -3256,6 +3278,7 @@ function setupBasicGraphRegistry(id) {
3256
3278
  categoryId: "compute",
3257
3279
  inputs: { Value: "base.bool" },
3258
3280
  outputs: { Result: "base.bool" },
3281
+ policy: { autoRun: true },
3259
3282
  impl: (ins) => ({ Result: Boolean(ins.Value) }),
3260
3283
  });
3261
3284
  registry.registerNode({
@@ -3263,6 +3286,7 @@ function setupBasicGraphRegistry(id) {
3263
3286
  categoryId: "compute",
3264
3287
  inputs: { Value: "base.object" },
3265
3288
  outputs: { Result: "base.object" },
3289
+ policy: { autoRun: true },
3266
3290
  impl: (ins) => ({ Result: ins.Value }),
3267
3291
  });
3268
3292
  registry.registerNode({
@@ -3270,6 +3294,7 @@ function setupBasicGraphRegistry(id) {
3270
3294
  categoryId: "compute",
3271
3295
  inputs: { Value: "base.vec3" },
3272
3296
  outputs: { Result: "base.vec3" },
3297
+ policy: { autoRun: true },
3273
3298
  impl: (ins) => ({ Result: ins.Value }),
3274
3299
  });
3275
3300
  // JSON parser node: base.stringToObject