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