@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 +201 -201
- package/lib/cjs/index.cjs.map +1 -1
- package/lib/cjs/src/RemoteEngine.d.ts +1 -1
- package/lib/cjs/src/RemoteEngine.d.ts.map +1 -1
- package/lib/cjs/src/server/runtime.d.ts +1 -1
- package/lib/cjs/src/server/runtime.d.ts.map +1 -1
- package/lib/cjs/src/transport/Transport.d.ts +1 -1
- package/lib/esm/index.js +201 -201
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/src/RemoteEngine.d.ts +1 -1
- package/lib/esm/src/RemoteEngine.d.ts.map +1 -1
- package/lib/esm/src/server/runtime.d.ts +1 -1
- package/lib/esm/src/server/runtime.d.ts.map +1 -1
- package/lib/esm/src/transport/Transport.d.ts +1 -1
- package/package.json +3 -3
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({
|
|
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
|
|
527
|
-
|
|
528
|
-
|
|
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
|
-
}
|
|
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
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
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
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
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
|
-
|
|
609
|
-
|
|
610
|
-
const
|
|
611
|
-
|
|
612
|
-
|
|
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
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
626
|
+
def,
|
|
627
|
+
environment: env,
|
|
628
|
+
inputs: snap.inputs,
|
|
629
|
+
outputs: snap.outputs,
|
|
648
630
|
};
|
|
649
|
-
}
|
|
650
|
-
|
|
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
|
-
const
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
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
|
|
723
|
-
coerce: wrapMethod("coerce",
|
|
724
|
-
getEnvironment: wrapMethod("getEnvironment",
|
|
725
|
-
applyRegistry: wrapMethod("applyRegistry",
|
|
726
|
-
build: wrapMethod("build",
|
|
727
|
-
setExtData: wrapMethod("setExtData",
|
|
728
|
-
getExtData: wrapMethod("getExtData",
|
|
729
|
-
snapshot: wrapMethod("snapshot",
|
|
730
|
-
snapshotFull: wrapMethod("snapshotFull",
|
|
731
|
-
applySnapshotFull: wrapMethod("applySnapshotFull",
|
|
732
|
-
describeRegistry: wrapMethod("describeRegistry",
|
|
733
|
-
update: wrapMethod("update",
|
|
734
|
-
setEnvironment: wrapMethod("setEnvironment",
|
|
735
|
-
setInput: wrapMethod("setInput",
|
|
736
|
-
setInputs: wrapMethod("setInputs",
|
|
737
|
-
triggerExternal: wrapMethod("triggerExternal",
|
|
738
|
-
launch: wrapMethod("launch",
|
|
739
|
-
whenIdle: wrapMethod("whenIdle",
|
|
740
|
-
dispose: wrapMethod("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
|
|
742
|
+
return extendedApi;
|
|
743
743
|
}
|
|
744
744
|
|
|
745
745
|
exports.HttpPollingTransport = HttpPollingTransport;
|