@bian-womp/spark-remote 0.2.31 → 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
@@ -221,8 +221,10 @@ class RemoteEngine {
221
221
  this.emit("stats", msg.payload);
222
222
  }
223
223
  }
224
- launch() {
225
- this.transport.send({ message: { type: "Launch" } });
224
+ launch(invalidate) {
225
+ this.transport.send({
226
+ message: { type: "Launch", payload: { invalidate } },
227
+ });
226
228
  }
227
229
  setInput(nodeId, handle, value) {
228
230
  this.transport.send({
@@ -439,7 +441,7 @@ async function handleCommand(label, env, runtimeApi, ack) {
439
441
  }
440
442
  case "Launch": {
441
443
  console.debug(`[${label}] rx Launch seq=${env.seq}`);
442
- runtimeApi.launch();
444
+ runtimeApi.launch(msg.payload.invalidate);
443
445
  ack();
444
446
  break;
445
447
  }
@@ -523,191 +525,189 @@ async function createRuntimeAdapter(createRegistry, send, extensions) {
523
525
  extData,
524
526
  });
525
527
  // 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
- });
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
+ }
554
576
  }
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
- });
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;
562
597
  }
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
- });
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
+ }
574
618
  }
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
619
  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);
620
+ },
621
+ snapshotFull: () => {
622
+ const snap = originalApi.snapshot();
623
+ const env = graphRuntime?.getEnvironment?.() ?? {};
624
+ const def = graphRuntime?.getGraphDef();
643
625
  return {
644
- id,
645
- displayName: d.displayName,
646
- bakeTarget: d.bakeTarget,
647
- ...(en ? { options: en.options } : {}),
626
+ def,
627
+ environment: env,
628
+ inputs: snap.inputs,
629
+ outputs: snap.outputs,
648
630
  };
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 = () => {
700
- graphRuntime?.launch();
701
- };
702
- originals.whenIdle = () => {
703
- return graphRuntime?.whenIdle?.() ?? Promise.resolve();
704
- };
705
- originals.dispose = () => {
706
- graphRuntime?.dispose?.();
707
- 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
+ },
708
710
  };
709
- // Cast to RuntimeApi now that all methods are defined
710
- const originalsApi = originals;
711
711
  // Helper to wrap a method with extension support
712
712
  const wrapMethod = (key, original) => {
713
713
  const extension = extensions?.[key];
@@ -719,27 +719,27 @@ async function createRuntimeAdapter(createRegistry, send, extensions) {
719
719
  });
720
720
  };
721
721
  // 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),
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),
741
741
  };
742
- return api;
742
+ return extendedApi;
743
743
  }
744
744
 
745
745
  exports.HttpPollingTransport = HttpPollingTransport;