@bian-womp/spark-graph 0.2.30 → 0.2.31

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.
@@ -1 +1 @@
1
- {"version":3,"file":"GraphRuntime.d.ts","sourceRoot":"","sources":["../../../../src/runtime/GraphRuntime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,iBAAiB,EACjB,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,eAAe,EAIhB,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAIV,gBAAgB,EACjB,MAAM,eAAe,CAAC;AAQvB,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAE/C,MAAM,MAAM,oBAAoB,CAAC,CAAC,SAAS,gBAAgB,IAAI,CAC7D,CAAC,EAAE,eAAe,CAAC,CAAC,CAAC,KAClB,IAAI,CAAC;AAUV,MAAM,MAAM,gBAAgB,GAAG,OAAO,GAAG,YAAY,GAAG,OAAO,GAAG,OAAO,CAAC;AAE1E,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,YAAY,CAAC;IACpB,UAAU,EAAE,iBAAiB,CAAC;IAC9B,KAAK,EAAE,YAAY,CAAC;IACpB,KAAK,EAAE,YAAY,CAAC;CACrB;AA+BD,qBAAa,YAAY;IACvB,OAAO,CAAC,KAAK,CAAuC;IACpD,OAAO,CAAC,KAAK,CAAqB;IAElC,OAAO,CAAC,QAAQ,CAAC,CAAW;IAE5B,OAAO,CAAC,cAAc,CAAsC;IAC5D,OAAO,CAAC,SAAS,CAGb;IACJ,OAAO,CAAC,WAAW,CAA+B;IAElD,OAAO,CAAC,oBAAoB,CAA6B;IACzD,OAAO,CAAC,MAAM,CAAS;IAIvB,OAAO,CAAC,iBAAiB,CAGrB;IAGJ,OAAO,CAAC,WAAW;IAanB,MAAM,CAAC,MAAM,CACX,GAAG,EAAE,eAAe,EACpB,QAAQ,EAAE,QAAQ,EAClB,IAAI,CAAC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E,MAAM,GAAG,IAAI;IAKpD,OAAO,CACL,OAAO,EAAE;QACP,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;QACjD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;KACnD,EACD,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,OAAO,CAAA;KAAE,GAC1B,IAAI;IAsEP,MAAM,CAAC,GAAG,EAAE,eAAe,EAAE,QAAQ,EAAE,QAAQ,GAAG,IAAI;IAqRtD,OAAO,CAAC,wBAAwB;YAWlB,uBAAuB;CA0DtC"}
package/lib/esm/index.js CHANGED
@@ -571,57 +571,67 @@ class GraphRuntime {
571
571
  return node?.outputs[output];
572
572
  }
573
573
  static buildEdgeConverters(srcDeclared, dstDeclared, registry) {
574
- let convert;
575
- let convertAsync;
576
- if (dstDeclared && srcDeclared) {
577
- if (Array.isArray(srcDeclared)) {
578
- const srcTypes = srcDeclared;
579
- const anyAsync = srcTypes.some((s) => {
580
- const res = registry.resolveCoercion(s, dstDeclared);
581
- return res?.kind === "async";
582
- });
583
- if (anyAsync) {
584
- convertAsync = async (v, signal) => {
585
- const typeId = getTypedOutputTypeId(v);
586
- if (!typeId)
587
- throw new Error(`Typed output required for union source; allowed: ${srcTypes.join("|")}`);
588
- if (!srcTypes.includes(typeId))
589
- throw new Error(`Invalid typed output ${typeId}; allowed: ${srcTypes.join("|")}`);
590
- const payload = getTypedOutputValue(v);
591
- const res = registry.resolveCoercion(typeId, dstDeclared);
592
- if (!res)
593
- return payload;
594
- if (res.kind === "async")
595
- return await res.convertAsync(payload, signal);
596
- return res.convert(payload);
597
- };
574
+ if (!dstDeclared || !srcDeclared) {
575
+ return {};
576
+ }
577
+ const isUnion = Array.isArray(srcDeclared);
578
+ const srcTypes = isUnion ? srcDeclared : [srcDeclared];
579
+ // Helper to get the coercion for a specific type
580
+ const getCoercion = (typeId) => {
581
+ return registry.resolveCoercion(typeId, dstDeclared);
582
+ };
583
+ // Resolve coercions for all source types
584
+ const coercions = srcTypes.map(getCoercion);
585
+ const hasAsync = coercions.some((r) => r?.kind === "async");
586
+ // Helper to extract and validate typed output for unions
587
+ const extractPayload = (v) => {
588
+ const typeId = getTypedOutputTypeId(v);
589
+ const payload = getTypedOutputValue(v);
590
+ if (isUnion) {
591
+ if (!typeId) {
592
+ throw new Error(`Typed output required for union source; allowed: ${srcTypes.join("|")}`);
598
593
  }
599
- else {
600
- convert = (v) => {
601
- const typeId = getTypedOutputTypeId(v);
602
- if (!typeId)
603
- throw new Error(`Typed output required for union source; allowed: ${srcTypes.join("|")}`);
604
- if (!srcTypes.includes(typeId))
605
- throw new Error(`Invalid typed output ${typeId}; allowed: ${srcTypes.join("|")}`);
606
- const payload = getTypedOutputValue(v);
607
- const res = registry.resolveCoercion(typeId, dstDeclared);
608
- if (!res)
609
- return payload;
610
- if (res.kind === "async")
611
- throw new Error("Async coercion required but convert used");
612
- return res.convert(payload);
613
- };
594
+ if (!srcTypes.includes(typeId)) {
595
+ throw new Error(`Invalid typed output ${typeId}; allowed: ${srcTypes.join("|")}`);
614
596
  }
615
597
  }
616
- else {
617
- const res = registry.resolveCoercion(srcDeclared, dstDeclared);
618
- if (res?.kind === "async")
619
- convertAsync = res.convertAsync;
620
- else if (res?.kind === "sync")
621
- convert = res.convert;
598
+ else if (typeId) {
599
+ // Warn if typed output is used for non-union source
600
+ console.warn(`Typed output ${typeId} is fed even though source is not union: ${srcDeclared} -> ${dstDeclared}`);
622
601
  }
602
+ return { typeId: typeId || srcTypes[0], payload };
603
+ };
604
+ if (hasAsync) {
605
+ return {
606
+ convertAsync: async (v, signal) => {
607
+ const { typeId, payload } = extractPayload(v);
608
+ const res = getCoercion(typeId);
609
+ if (!res)
610
+ return payload;
611
+ if (res.kind === "async") {
612
+ return await res.convertAsync(payload, signal);
613
+ }
614
+ return res.convert(payload);
615
+ },
616
+ };
617
+ }
618
+ // Sync path
619
+ const firstCoercion = coercions.find((r) => r?.kind === "sync");
620
+ if (!firstCoercion) {
621
+ return {};
623
622
  }
624
- return { convert, convertAsync };
623
+ return {
624
+ convert: (v) => {
625
+ const { typeId, payload } = extractPayload(v);
626
+ const res = getCoercion(typeId);
627
+ if (!res)
628
+ return payload;
629
+ if (res.kind === "async") {
630
+ throw new Error("Async coercion required but convert used");
631
+ }
632
+ return res.convert(payload);
633
+ },
634
+ };
625
635
  }
626
636
  scheduleInputsChanged(nodeId) {
627
637
  const node = this.nodes.get(nodeId);
@@ -825,6 +835,9 @@ class GraphRuntime {
825
835
  const dstNode = this.nodes.get(e.target.nodeId);
826
836
  if (!dstNode)
827
837
  return;
838
+ // Skip writing to unresolved handles - wait for handle resolution
839
+ if (e.dstDeclared === undefined)
840
+ return;
828
841
  const dstIsArray = typeof e.dstDeclared === "string" && e.dstDeclared.endsWith("[]");
829
842
  let next = v;
830
843
  // If target input is an array type, merge per-edge contributions deterministically
@@ -1033,6 +1046,7 @@ class GraphRuntime {
1033
1046
  for (const e of this.edges) {
1034
1047
  let srcDeclared = e.effectiveTypeId; // Use effectiveTypeId as fallback
1035
1048
  let dstDeclared = e.dstDeclared;
1049
+ const oldDstDeclared = dstDeclared; // Track old value to detect resolution
1036
1050
  if (e.source.nodeId === nodeId) {
1037
1051
  const resolved = this.resolvedByNode.get(nodeId);
1038
1052
  srcDeclared = resolved
@@ -1055,6 +1069,19 @@ class GraphRuntime {
1055
1069
  const conv = GraphRuntime.buildEdgeConverters(srcDeclared, dstDeclared, registry);
1056
1070
  e.convert = conv.convert;
1057
1071
  e.convertAsync = conv.convertAsync;
1072
+ // If target handle was just resolved (was undefined, now has a type), re-propagate values
1073
+ if (e.target.nodeId === nodeId &&
1074
+ oldDstDeclared === undefined &&
1075
+ dstDeclared !== undefined) {
1076
+ const srcNode = this.nodes.get(e.source.nodeId);
1077
+ if (srcNode) {
1078
+ const srcValue = srcNode.outputs[e.source.handle];
1079
+ if (srcValue !== undefined) {
1080
+ // Re-propagate through the now-resolved edge converter
1081
+ this.propagate(e.source.nodeId, e.source.handle, srcValue);
1082
+ }
1083
+ }
1084
+ }
1058
1085
  }
1059
1086
  // Invalidate downstream for this node so UI refreshes
1060
1087
  this.invalidateDownstream(nodeId);