@bian-womp/spark-remote 0.2.32 → 0.2.34
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 +199 -198
- package/lib/cjs/index.cjs.map +1 -1
- package/lib/cjs/src/server/runtime.d.ts.map +1 -1
- package/lib/esm/index.js +199 -198
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/src/server/runtime.d.ts.map +1 -1
- package/package.json +3 -3
package/lib/cjs/index.cjs
CHANGED
|
@@ -525,191 +525,192 @@ 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
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
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
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
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
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
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
|
-
|
|
611
|
-
|
|
612
|
-
const
|
|
613
|
-
|
|
614
|
-
|
|
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
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
626
|
+
def,
|
|
627
|
+
environment: env,
|
|
628
|
+
inputs: snap.inputs,
|
|
629
|
+
outputs: snap.outputs,
|
|
650
630
|
};
|
|
651
|
-
}
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
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({
|
|
639
|
+
inputs: payload.inputs,
|
|
640
|
+
outputs: payload.outputs,
|
|
641
|
+
});
|
|
642
|
+
},
|
|
643
|
+
describeRegistry: () => {
|
|
644
|
+
// types (include enum options when available)
|
|
645
|
+
const types = Array.from(registry.types.entries()).map(([id, d]) => {
|
|
646
|
+
const en = registry.enums.get(id);
|
|
647
|
+
return {
|
|
648
|
+
id,
|
|
649
|
+
displayName: d.displayName,
|
|
650
|
+
bakeTarget: d.bakeTarget,
|
|
651
|
+
...(en ? { options: en.options } : {}),
|
|
652
|
+
};
|
|
653
|
+
});
|
|
654
|
+
// categories: not directly enumerable; derive from node descriptors
|
|
655
|
+
const nodeDescs = Array.from(registry.nodes.values());
|
|
656
|
+
const catIds = new Set(nodeDescs.map((n) => n.categoryId));
|
|
657
|
+
const categories = Array.from(catIds).map((id) => {
|
|
658
|
+
const cat = registry.categories.get?.(id);
|
|
659
|
+
return { id, displayName: cat?.displayName };
|
|
660
|
+
});
|
|
661
|
+
const nodes = nodeDescs.map((n) => ({
|
|
662
|
+
id: n.id,
|
|
663
|
+
categoryId: n.categoryId,
|
|
664
|
+
displayName: n.displayName,
|
|
665
|
+
inputs: n.inputs || {},
|
|
666
|
+
outputs: n.outputs || {},
|
|
667
|
+
inputDefaults: n.inputDefaults || {},
|
|
668
|
+
}));
|
|
669
|
+
const coercions = registry.listCoercions();
|
|
670
|
+
return { types, categories, nodes, coercions, schemaVersion: 4 };
|
|
671
|
+
},
|
|
672
|
+
update: async (def) => {
|
|
673
|
+
if (!graphRuntime)
|
|
674
|
+
return;
|
|
675
|
+
graphRuntime.update(def, registry);
|
|
676
|
+
send({
|
|
677
|
+
message: {
|
|
678
|
+
type: "invalidate",
|
|
679
|
+
payload: { reason: "graph-updated" },
|
|
680
|
+
},
|
|
681
|
+
});
|
|
682
|
+
},
|
|
683
|
+
setEnvironment: (env, opts) => {
|
|
684
|
+
if (!graphRuntime)
|
|
685
|
+
return;
|
|
686
|
+
if (opts?.merge) {
|
|
687
|
+
const current = graphRuntime.getEnvironment();
|
|
688
|
+
const next = { ...(current || {}), ...(env || {}) };
|
|
689
|
+
graphRuntime.setEnvironment(next);
|
|
690
|
+
return;
|
|
691
|
+
}
|
|
692
|
+
graphRuntime.setEnvironment(env);
|
|
693
|
+
},
|
|
694
|
+
setInput: (nodeId, handle, value) => {
|
|
695
|
+
graphRuntime?.setInput(nodeId, handle, value);
|
|
696
|
+
},
|
|
697
|
+
setInputs: (nodeId, inputs) => {
|
|
698
|
+
graphRuntime?.setInputs(nodeId, inputs);
|
|
699
|
+
},
|
|
700
|
+
triggerExternal: (nodeId, event) => {
|
|
701
|
+
graphRuntime?.triggerExternal(nodeId, event);
|
|
702
|
+
},
|
|
703
|
+
launch: (invalidate) => {
|
|
704
|
+
graphRuntime?.launch(invalidate);
|
|
705
|
+
},
|
|
706
|
+
whenIdle: () => {
|
|
707
|
+
return graphRuntime?.whenIdle?.() ?? Promise.resolve();
|
|
708
|
+
},
|
|
709
|
+
dispose: () => {
|
|
710
|
+
graphRuntime?.dispose?.();
|
|
711
|
+
graphRuntime = undefined;
|
|
712
|
+
},
|
|
710
713
|
};
|
|
711
|
-
// Cast to RuntimeApi now that all methods are defined
|
|
712
|
-
const originalsApi = originals;
|
|
713
714
|
// Helper to wrap a method with extension support
|
|
714
715
|
const wrapMethod = (key, original) => {
|
|
715
716
|
const extension = extensions?.[key];
|
|
@@ -721,27 +722,27 @@ async function createRuntimeAdapter(createRegistry, send, extensions) {
|
|
|
721
722
|
});
|
|
722
723
|
};
|
|
723
724
|
// Create API with extensions applied
|
|
724
|
-
const
|
|
725
|
-
coerce: wrapMethod("coerce",
|
|
726
|
-
getEnvironment: wrapMethod("getEnvironment",
|
|
727
|
-
applyRegistry: wrapMethod("applyRegistry",
|
|
728
|
-
build: wrapMethod("build",
|
|
729
|
-
setExtData: wrapMethod("setExtData",
|
|
730
|
-
getExtData: wrapMethod("getExtData",
|
|
731
|
-
snapshot: wrapMethod("snapshot",
|
|
732
|
-
snapshotFull: wrapMethod("snapshotFull",
|
|
733
|
-
applySnapshotFull: wrapMethod("applySnapshotFull",
|
|
734
|
-
describeRegistry: wrapMethod("describeRegistry",
|
|
735
|
-
update: wrapMethod("update",
|
|
736
|
-
setEnvironment: wrapMethod("setEnvironment",
|
|
737
|
-
setInput: wrapMethod("setInput",
|
|
738
|
-
setInputs: wrapMethod("setInputs",
|
|
739
|
-
triggerExternal: wrapMethod("triggerExternal",
|
|
740
|
-
launch: wrapMethod("launch",
|
|
741
|
-
whenIdle: wrapMethod("whenIdle",
|
|
742
|
-
dispose: wrapMethod("dispose",
|
|
725
|
+
const extendedApi = {
|
|
726
|
+
coerce: wrapMethod("coerce", originalApi.coerce),
|
|
727
|
+
getEnvironment: wrapMethod("getEnvironment", originalApi.getEnvironment),
|
|
728
|
+
applyRegistry: wrapMethod("applyRegistry", originalApi.applyRegistry),
|
|
729
|
+
build: wrapMethod("build", originalApi.build),
|
|
730
|
+
setExtData: wrapMethod("setExtData", originalApi.setExtData),
|
|
731
|
+
getExtData: wrapMethod("getExtData", originalApi.getExtData),
|
|
732
|
+
snapshot: wrapMethod("snapshot", originalApi.snapshot),
|
|
733
|
+
snapshotFull: wrapMethod("snapshotFull", originalApi.snapshotFull),
|
|
734
|
+
applySnapshotFull: wrapMethod("applySnapshotFull", originalApi.applySnapshotFull),
|
|
735
|
+
describeRegistry: wrapMethod("describeRegistry", originalApi.describeRegistry),
|
|
736
|
+
update: wrapMethod("update", originalApi.update),
|
|
737
|
+
setEnvironment: wrapMethod("setEnvironment", originalApi.setEnvironment),
|
|
738
|
+
setInput: wrapMethod("setInput", originalApi.setInput),
|
|
739
|
+
setInputs: wrapMethod("setInputs", originalApi.setInputs),
|
|
740
|
+
triggerExternal: wrapMethod("triggerExternal", originalApi.triggerExternal),
|
|
741
|
+
launch: wrapMethod("launch", originalApi.launch),
|
|
742
|
+
whenIdle: wrapMethod("whenIdle", originalApi.whenIdle),
|
|
743
|
+
dispose: wrapMethod("dispose", originalApi.dispose),
|
|
743
744
|
};
|
|
744
|
-
return
|
|
745
|
+
return extendedApi;
|
|
745
746
|
}
|
|
746
747
|
|
|
747
748
|
exports.HttpPollingTransport = HttpPollingTransport;
|