@bian-womp/spark-remote 0.2.32 → 0.2.33

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
@@ -525,191 +525,189 @@ async function createRuntimeAdapter(createRegistry, send, extensions) {
525
525
  extData,
526
526
  });
527
527
  // Original implementations - define as separate functions first to allow cross-references
528
- const originals = {};
529
- // Define methods that can reference each other
530
- originals.coerce = async (from, to, value) => {
531
- const resolved = registry.resolveCoercion(from, to);
532
- if (!resolved)
533
- return value;
534
- if (resolved.kind === "sync")
535
- return resolved.convert(value);
536
- const ac = new AbortController();
537
- return await resolved.convertAsync(value, ac.signal);
538
- };
539
- originals.getEnvironment = () => {
540
- return graphRuntime?.getEnvironment?.() ?? {};
541
- };
542
- originals.applyRegistry = async (deltas) => {
543
- // Pause runtime if exists
544
- // Apply each delta to the live registry
545
- for (const d of deltas || []) {
546
- if (!d || typeof d !== "object")
547
- continue;
548
- if (d.kind === "register-enum") {
549
- registry.registerEnum({
550
- id: d.id,
551
- displayName: d.displayName,
552
- options: d.options || [],
553
- bakeTarget: d.bakeTarget,
554
- opts: d.opts,
555
- });
528
+ const originalApi = {
529
+ coerce: async (from, to, value) => {
530
+ const resolved = registry.resolveCoercion(from, to);
531
+ if (!resolved)
532
+ return value;
533
+ if (resolved.kind === "sync")
534
+ return resolved.convert(value);
535
+ const ac = new AbortController();
536
+ return await resolved.convertAsync(value, ac.signal);
537
+ },
538
+ getEnvironment: () => {
539
+ return graphRuntime?.getEnvironment?.() ?? {};
540
+ },
541
+ applyRegistry: async (deltas) => {
542
+ // Pause runtime if exists
543
+ // Apply each delta to the live registry
544
+ for (const d of deltas || []) {
545
+ if (!d || typeof d !== "object")
546
+ continue;
547
+ if (d.kind === "register-enum") {
548
+ registry.registerEnum({
549
+ id: d.id,
550
+ displayName: d.displayName,
551
+ options: d.options || [],
552
+ bakeTarget: d.bakeTarget,
553
+ opts: d.opts,
554
+ });
555
+ }
556
+ else if (d.kind === "register-type") {
557
+ registry.registerType({
558
+ id: d.id,
559
+ displayName: d.displayName,
560
+ bakeTarget: d.bakeTarget,
561
+ validate: (_v) => true,
562
+ });
563
+ }
564
+ else if (d.kind === "register-node") {
565
+ const desc = d.desc || {};
566
+ registry.registerNode({
567
+ id: String(desc.id || ""),
568
+ categoryId: String(desc.categoryId || "compute"),
569
+ displayName: desc.displayName,
570
+ inputs: desc.inputs || {},
571
+ outputs: desc.outputs || {},
572
+ // impl must be empty per frontend registration contract
573
+ impl: () => { },
574
+ });
575
+ }
556
576
  }
557
- else if (d.kind === "register-type") {
558
- registry.registerType({
559
- id: d.id,
560
- displayName: d.displayName,
561
- bakeTarget: d.bakeTarget,
562
- validate: (_v) => true,
563
- });
577
+ // Notify clients (include deltas in invalidate payload)
578
+ send({
579
+ message: {
580
+ type: "invalidate",
581
+ payload: { reason: "registry-changed", deltas },
582
+ },
583
+ });
584
+ },
585
+ build: async (def, opts) => {
586
+ const env = opts || {};
587
+ graphRuntime = builder.build(def, { environment: env });
588
+ graphRuntime.on("value", (p) => send({ message: { type: "value", payload: p } }));
589
+ graphRuntime.on("invalidate", (p) => send({ message: { type: "invalidate", payload: p } }));
590
+ graphRuntime.on("error", (p) => send({ message: { type: "error", payload: p } }));
591
+ graphRuntime.on("stats", (p) => send({ message: { type: "stats", payload: p } }));
592
+ },
593
+ setExtData: (data) => {
594
+ if (!data || typeof data !== "object") {
595
+ extData = {};
596
+ return;
564
597
  }
565
- else if (d.kind === "register-node") {
566
- const desc = d.desc || {};
567
- registry.registerNode({
568
- id: String(desc.id || ""),
569
- categoryId: String(desc.categoryId || "compute"),
570
- displayName: desc.displayName,
571
- inputs: desc.inputs || {},
572
- outputs: desc.outputs || {},
573
- // impl must be empty per frontend registration contract
574
- impl: () => { },
575
- });
598
+ // Replace to keep semantics deterministic
599
+ extData = { ...data };
600
+ },
601
+ getExtData: () => {
602
+ return extData;
603
+ },
604
+ snapshot: () => {
605
+ const inputs = {};
606
+ const outputs = {};
607
+ if (!graphRuntime)
608
+ return { inputs, outputs };
609
+ const nodes = graphRuntime.getNodeIds();
610
+ for (const nodeId of nodes) {
611
+ const data = graphRuntime.getNodeData(nodeId);
612
+ if (data?.inputs && Object.keys(data.inputs).length > 0) {
613
+ inputs[nodeId] = { ...data.inputs };
614
+ }
615
+ if (data?.outputs && Object.keys(data.outputs).length > 0) {
616
+ outputs[nodeId] = { ...data.outputs };
617
+ }
576
618
  }
577
- }
578
- // Notify clients (include deltas in invalidate payload)
579
- send({
580
- message: {
581
- type: "invalidate",
582
- payload: { reason: "registry-changed", deltas },
583
- },
584
- });
585
- };
586
- originals.build = async (def, opts) => {
587
- const env = opts || {};
588
- graphRuntime = builder.build(def, { environment: env });
589
- graphRuntime.on("value", (p) => send({ message: { type: "value", payload: p } }));
590
- graphRuntime.on("invalidate", (p) => send({ message: { type: "invalidate", payload: p } }));
591
- graphRuntime.on("error", (p) => send({ message: { type: "error", payload: p } }));
592
- graphRuntime.on("stats", (p) => send({ message: { type: "stats", payload: p } }));
593
- };
594
- originals.setExtData = (data) => {
595
- if (!data || typeof data !== "object") {
596
- extData = {};
597
- return;
598
- }
599
- // Replace to keep semantics deterministic
600
- extData = { ...data };
601
- };
602
- originals.getExtData = () => {
603
- return extData;
604
- };
605
- originals.snapshot = () => {
606
- const inputs = {};
607
- const outputs = {};
608
- if (!graphRuntime)
609
619
  return { inputs, outputs };
610
- const nodes = graphRuntime.getNodeIds();
611
- for (const nodeId of nodes) {
612
- const data = graphRuntime.getNodeData(nodeId);
613
- if (data?.inputs && Object.keys(data.inputs).length > 0) {
614
- inputs[nodeId] = { ...data.inputs };
615
- }
616
- if (data?.outputs && Object.keys(data.outputs).length > 0) {
617
- outputs[nodeId] = { ...data.outputs };
618
- }
619
- }
620
- return { inputs, outputs };
621
- };
622
- originals.snapshotFull = () => {
623
- const snap = originals.snapshot();
624
- const env = graphRuntime?.getEnvironment?.() ?? {};
625
- const def = graphRuntime?.getGraphDef();
626
- return {
627
- def,
628
- environment: env,
629
- inputs: snap.inputs,
630
- outputs: snap.outputs,
631
- };
632
- };
633
- originals.applySnapshotFull = async (payload) => {
634
- const def = payload.def;
635
- if (!def)
636
- return;
637
- await originals.build(def, payload.environment);
638
- // Hydrate inputs/outputs exactly, then re-emit outputs without scheduling runs
639
- graphRuntime?.hydrate({ inputs: payload.inputs, outputs: payload.outputs }, { reemit: true });
640
- };
641
- originals.describeRegistry = () => {
642
- // types (include enum options when available)
643
- const types = Array.from(registry.types.entries()).map(([id, d]) => {
644
- const en = registry.enums.get(id);
620
+ },
621
+ snapshotFull: () => {
622
+ const snap = originalApi.snapshot();
623
+ const env = graphRuntime?.getEnvironment?.() ?? {};
624
+ const def = graphRuntime?.getGraphDef();
645
625
  return {
646
- id,
647
- displayName: d.displayName,
648
- bakeTarget: d.bakeTarget,
649
- ...(en ? { options: en.options } : {}),
626
+ def,
627
+ environment: env,
628
+ inputs: snap.inputs,
629
+ outputs: snap.outputs,
650
630
  };
651
- });
652
- // categories: not directly enumerable; derive from node descriptors
653
- const nodeDescs = Array.from(registry.nodes.values());
654
- const catIds = new Set(nodeDescs.map((n) => n.categoryId));
655
- const categories = Array.from(catIds).map((id) => {
656
- const cat = registry.categories.get?.(id);
657
- return { id, displayName: cat?.displayName };
658
- });
659
- const nodes = nodeDescs.map((n) => ({
660
- id: n.id,
661
- categoryId: n.categoryId,
662
- displayName: n.displayName,
663
- inputs: n.inputs || {},
664
- outputs: n.outputs || {},
665
- inputDefaults: n.inputDefaults || {},
666
- }));
667
- const coercions = registry.listCoercions();
668
- return { types, categories, nodes, coercions, schemaVersion: 4 };
669
- };
670
- originals.update = async (def) => {
671
- if (!graphRuntime)
672
- return;
673
- graphRuntime.update(def, registry);
674
- send({
675
- message: {
676
- type: "invalidate",
677
- payload: { reason: "graph-updated" },
678
- },
679
- });
680
- };
681
- originals.setEnvironment = (env, opts) => {
682
- if (!graphRuntime)
683
- return;
684
- if (opts?.merge) {
685
- const current = graphRuntime.getEnvironment();
686
- const next = { ...(current || {}), ...(env || {}) };
687
- graphRuntime.setEnvironment(next);
688
- return;
689
- }
690
- graphRuntime.setEnvironment(env);
691
- };
692
- originals.setInput = (nodeId, handle, value) => {
693
- graphRuntime?.setInput(nodeId, handle, value);
694
- };
695
- originals.setInputs = (nodeId, inputs) => {
696
- graphRuntime?.setInputs(nodeId, inputs);
697
- };
698
- originals.triggerExternal = (nodeId, event) => {
699
- graphRuntime?.triggerExternal(nodeId, event);
700
- };
701
- originals.launch = (invalidate) => {
702
- graphRuntime?.launch(invalidate);
703
- };
704
- originals.whenIdle = () => {
705
- return graphRuntime?.whenIdle?.() ?? Promise.resolve();
706
- };
707
- originals.dispose = () => {
708
- graphRuntime?.dispose?.();
709
- graphRuntime = undefined;
631
+ },
632
+ applySnapshotFull: async (payload) => {
633
+ const def = payload.def;
634
+ if (!def)
635
+ return;
636
+ await originalApi.build(def, payload.environment);
637
+ // Hydrate inputs/outputs exactly, then re-emit outputs without scheduling runs
638
+ graphRuntime?.hydrate({ inputs: payload.inputs, outputs: payload.outputs }, { reemit: true });
639
+ },
640
+ describeRegistry: () => {
641
+ // types (include enum options when available)
642
+ const types = Array.from(registry.types.entries()).map(([id, d]) => {
643
+ const en = registry.enums.get(id);
644
+ return {
645
+ id,
646
+ displayName: d.displayName,
647
+ bakeTarget: d.bakeTarget,
648
+ ...(en ? { options: en.options } : {}),
649
+ };
650
+ });
651
+ // categories: not directly enumerable; derive from node descriptors
652
+ const nodeDescs = Array.from(registry.nodes.values());
653
+ const catIds = new Set(nodeDescs.map((n) => n.categoryId));
654
+ const categories = Array.from(catIds).map((id) => {
655
+ const cat = registry.categories.get?.(id);
656
+ return { id, displayName: cat?.displayName };
657
+ });
658
+ const nodes = nodeDescs.map((n) => ({
659
+ id: n.id,
660
+ categoryId: n.categoryId,
661
+ displayName: n.displayName,
662
+ inputs: n.inputs || {},
663
+ outputs: n.outputs || {},
664
+ inputDefaults: n.inputDefaults || {},
665
+ }));
666
+ const coercions = registry.listCoercions();
667
+ return { types, categories, nodes, coercions, schemaVersion: 4 };
668
+ },
669
+ update: async (def) => {
670
+ if (!graphRuntime)
671
+ return;
672
+ graphRuntime.update(def, registry);
673
+ send({
674
+ message: {
675
+ type: "invalidate",
676
+ payload: { reason: "graph-updated" },
677
+ },
678
+ });
679
+ },
680
+ setEnvironment: (env, opts) => {
681
+ if (!graphRuntime)
682
+ return;
683
+ if (opts?.merge) {
684
+ const current = graphRuntime.getEnvironment();
685
+ const next = { ...(current || {}), ...(env || {}) };
686
+ graphRuntime.setEnvironment(next);
687
+ return;
688
+ }
689
+ graphRuntime.setEnvironment(env);
690
+ },
691
+ setInput: (nodeId, handle, value) => {
692
+ graphRuntime?.setInput(nodeId, handle, value);
693
+ },
694
+ setInputs: (nodeId, inputs) => {
695
+ graphRuntime?.setInputs(nodeId, inputs);
696
+ },
697
+ triggerExternal: (nodeId, event) => {
698
+ graphRuntime?.triggerExternal(nodeId, event);
699
+ },
700
+ launch: (invalidate) => {
701
+ graphRuntime?.launch(invalidate);
702
+ },
703
+ whenIdle: () => {
704
+ return graphRuntime?.whenIdle?.() ?? Promise.resolve();
705
+ },
706
+ dispose: () => {
707
+ graphRuntime?.dispose?.();
708
+ graphRuntime = undefined;
709
+ },
710
710
  };
711
- // Cast to RuntimeApi now that all methods are defined
712
- const originalsApi = originals;
713
711
  // Helper to wrap a method with extension support
714
712
  const wrapMethod = (key, original) => {
715
713
  const extension = extensions?.[key];
@@ -721,27 +719,27 @@ async function createRuntimeAdapter(createRegistry, send, extensions) {
721
719
  });
722
720
  };
723
721
  // Create API with extensions applied
724
- const api = {
725
- coerce: wrapMethod("coerce", originalsApi.coerce),
726
- getEnvironment: wrapMethod("getEnvironment", originalsApi.getEnvironment),
727
- applyRegistry: wrapMethod("applyRegistry", originalsApi.applyRegistry),
728
- build: wrapMethod("build", originalsApi.build),
729
- setExtData: wrapMethod("setExtData", originalsApi.setExtData),
730
- getExtData: wrapMethod("getExtData", originalsApi.getExtData),
731
- snapshot: wrapMethod("snapshot", originalsApi.snapshot),
732
- snapshotFull: wrapMethod("snapshotFull", originalsApi.snapshotFull),
733
- applySnapshotFull: wrapMethod("applySnapshotFull", originalsApi.applySnapshotFull),
734
- describeRegistry: wrapMethod("describeRegistry", originalsApi.describeRegistry),
735
- update: wrapMethod("update", originalsApi.update),
736
- setEnvironment: wrapMethod("setEnvironment", originalsApi.setEnvironment),
737
- setInput: wrapMethod("setInput", originalsApi.setInput),
738
- setInputs: wrapMethod("setInputs", originalsApi.setInputs),
739
- triggerExternal: wrapMethod("triggerExternal", originalsApi.triggerExternal),
740
- launch: wrapMethod("launch", originalsApi.launch),
741
- whenIdle: wrapMethod("whenIdle", originalsApi.whenIdle),
742
- dispose: wrapMethod("dispose", originalsApi.dispose),
722
+ const extendedApi = {
723
+ coerce: wrapMethod("coerce", originalApi.coerce),
724
+ getEnvironment: wrapMethod("getEnvironment", originalApi.getEnvironment),
725
+ applyRegistry: wrapMethod("applyRegistry", originalApi.applyRegistry),
726
+ build: wrapMethod("build", originalApi.build),
727
+ setExtData: wrapMethod("setExtData", originalApi.setExtData),
728
+ getExtData: wrapMethod("getExtData", originalApi.getExtData),
729
+ snapshot: wrapMethod("snapshot", originalApi.snapshot),
730
+ snapshotFull: wrapMethod("snapshotFull", originalApi.snapshotFull),
731
+ applySnapshotFull: wrapMethod("applySnapshotFull", originalApi.applySnapshotFull),
732
+ describeRegistry: wrapMethod("describeRegistry", originalApi.describeRegistry),
733
+ update: wrapMethod("update", originalApi.update),
734
+ setEnvironment: wrapMethod("setEnvironment", originalApi.setEnvironment),
735
+ setInput: wrapMethod("setInput", originalApi.setInput),
736
+ setInputs: wrapMethod("setInputs", originalApi.setInputs),
737
+ triggerExternal: wrapMethod("triggerExternal", originalApi.triggerExternal),
738
+ launch: wrapMethod("launch", originalApi.launch),
739
+ whenIdle: wrapMethod("whenIdle", originalApi.whenIdle),
740
+ dispose: wrapMethod("dispose", originalApi.dispose),
743
741
  };
744
- return api;
742
+ return extendedApi;
745
743
  }
746
744
 
747
745
  exports.HttpPollingTransport = HttpPollingTransport;