comfy-ts 2.15.0 → 2.17.0
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/README.md +23 -0
- package/dist/{run-serve-B5PfIuhK.js → ServeApp-BSA5yzxZ.js} +28 -446
- package/dist/ServeApp-BSA5yzxZ.js.map +1 -0
- package/dist/cli.js +18 -5
- package/dist/cli.js.map +1 -1
- package/dist/exampleAssets-BfWzygoM.js +38 -0
- package/dist/exampleAssets-BfWzygoM.js.map +1 -0
- package/dist/{LogsSt-C3UIWR-o.js → findDefinedWorkflow-0lG-VTEd.js} +201 -201
- package/dist/findDefinedWorkflow-0lG-VTEd.js.map +1 -0
- package/dist/index.cjs +202 -62
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +115 -14
- package/dist/index.d.ts +115 -14
- package/dist/index.js +202 -62
- package/dist/index.js.map +1 -1
- package/dist/run-run-DnaMLCFn.js +450 -0
- package/dist/run-run-DnaMLCFn.js.map +1 -0
- package/dist/run-serve-CbKxIu6i.js +418 -0
- package/dist/run-serve-CbKxIu6i.js.map +1 -0
- package/dist/{run-tui-D-N4_yyX.js → run-tui-B0AQWbad.js} +6 -37
- package/dist/run-tui-B0AQWbad.js.map +1 -0
- package/dist/{schemaDrift-BkN8rLiZ.js → schemaDrift-CbsABBuk.js} +59 -5
- package/dist/schemaDrift-CbsABBuk.js.map +1 -0
- package/dist/serve-web.js +48 -48
- package/dist/{state-CZsYJqB6.js → state-C2oDiQ26.js} +146 -60
- package/dist/state-C2oDiQ26.js.map +1 -0
- package/dist/web.d.ts +115 -14
- package/dist/web.js +202 -62
- package/dist/web.js.map +1 -1
- package/examples/README.md +2 -0
- package/examples/media/README.md +6 -5
- package/examples/media/voice_en_6s.flac +0 -0
- package/examples/rvion/04-krea2-turbo-t2i.cflow.ts +9 -1
- package/examples/rvion/10-anima-t2i.cflow.ts +8 -1
- package/examples/rvion/15-tts-voice-clone.cflow.ts +111 -0
- package/examples/rvion/16-tts-voice-design.cflow.ts +71 -0
- package/guide-for-agents.md +5 -1
- package/package.json +2 -2
- package/src/cli/comfy-ts-cli.ts +14 -1
- package/src/cli/run/findModules.ts +36 -0
- package/src/cli/run/flagValue.ts +61 -0
- package/src/cli/run/outputPaths.ts +41 -0
- package/src/cli/run/pickModule.ts +41 -0
- package/src/cli/run/run-run.ts +250 -0
- package/src/cli/run/runArgs.ts +61 -0
- package/src/cli/run/sidecar.ts +27 -0
- package/src/cli/serve/ServeApp.ts +28 -42
- package/src/cli/serve/web/components/DraftTabs.tsx +10 -3
- package/src/cli/serve/web/components/Gallery.tsx +2 -1
- package/src/cli/serve/web/components/HistoryPicker.tsx +5 -3
- package/src/cli/serve/web/components/MenuButton.tsx +2 -4
- package/src/cli/serve/web/components/Omnibox.tsx +2 -1
- package/src/cli/serve/web/components/PromptEnhancer.tsx +4 -3
- package/src/cli/serve/web/components/ShortcutsModal.tsx +2 -1
- package/src/cli/serve/web/components/SideMenu.tsx +2 -1
- package/src/cli/serve/web/components/controls/LorasControl.tsx +4 -3
- package/src/cli/serve/web/components/controls/PresetPicker.tsx +2 -1
- package/src/cli/serve/web/components/controls/PromptControl.tsx +2 -1
- package/src/cli/serve/web/components/controls/SizeControl.tsx +2 -1
- package/src/cli/serve/web/state/draftTabs.ts +12 -0
- package/src/cli/serve/web/state/escape.ts +16 -0
- package/src/cli/serve/web/state/shortcutCatalog.ts +1 -0
- package/src/coreExports.ts +12 -1
- package/src/host/ComfyHost.ts +73 -40
- package/src/host/previewMethod.ts +29 -0
- package/src/runner/ComfyExecution.ts +45 -1
- package/src/runner/ComfyWorkflow.ts +6 -1
- package/src/runner/ComfyWsApi.ts +1 -1
- package/src/runner/wsBinaryFrame.ts +48 -25
- package/src/vars/ComfyVars.ts +86 -13
- package/src/vars/DefinedWorkflow.ts +36 -2
- package/dist/LogsSt-C3UIWR-o.js.map +0 -1
- package/dist/run-serve-B5PfIuhK.js.map +0 -1
- package/dist/run-tui-D-N4_yyX.js.map +0 -1
- package/dist/schemaDrift-BkN8rLiZ.js.map +0 -1
- package/dist/state-CZsYJqB6.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -110,7 +110,7 @@ function createNodeStorage() {
|
|
|
110
110
|
}
|
|
111
111
|
//#endregion
|
|
112
112
|
//#region package.json
|
|
113
|
-
var version = "2.
|
|
113
|
+
var version = "2.17.0";
|
|
114
114
|
//#endregion
|
|
115
115
|
//#region src/litegraph/LiteGraphLinkID.ts
|
|
116
116
|
const asLiteGraphLinkID = (id) => id;
|
|
@@ -660,21 +660,41 @@ const normalizeGroup = (g) => {
|
|
|
660
660
|
};
|
|
661
661
|
};
|
|
662
662
|
//#endregion
|
|
663
|
-
//#region src/
|
|
664
|
-
function
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
663
|
+
//#region src/host/previewMethod.ts
|
|
664
|
+
function isPreviewMethod(x) {
|
|
665
|
+
return x === "none" || x === "auto" || x === "latent2rgb" || x === "taesd";
|
|
666
|
+
}
|
|
667
|
+
/** the preview method a host was launched with, from its /system_stats payload. `'none'` when
|
|
668
|
+
* the flag is absent (ComfyUI's default), null when the payload carries no argv to read (a cloud
|
|
669
|
+
* host) or the flag holds a value this parser does not know */
|
|
670
|
+
function previewMethodFromSystemStats(stats) {
|
|
671
|
+
if (stats == null || typeof stats !== "object" || !("system" in stats)) return null;
|
|
672
|
+
const system = stats.system;
|
|
673
|
+
if (system == null || typeof system !== "object" || !("argv" in system)) return null;
|
|
674
|
+
const argv = system.argv;
|
|
675
|
+
if (!Array.isArray(argv)) return null;
|
|
676
|
+
for (let i = 0; i < argv.length; i++) {
|
|
677
|
+
const arg = argv[i];
|
|
678
|
+
if (typeof arg !== "string") continue;
|
|
679
|
+
const value = arg === "--preview-method" ? argv[i + 1] : arg.startsWith("--preview-method=") ? arg.slice(17) : void 0;
|
|
680
|
+
if (value === void 0) continue;
|
|
681
|
+
return isPreviewMethod(value) ? value : null;
|
|
675
682
|
}
|
|
683
|
+
return "none";
|
|
684
|
+
}
|
|
685
|
+
/** the frame's event type, read in place: deciding whether anyone wants a frame costs no copy */
|
|
686
|
+
function binaryFrameType(data) {
|
|
687
|
+
if (data.byteLength < 4) return -1;
|
|
688
|
+
return new DataView(data).getUint32(0);
|
|
689
|
+
}
|
|
690
|
+
function isPreviewFrameType(eventType) {
|
|
691
|
+
return eventType === 1 || eventType === 4;
|
|
692
|
+
}
|
|
693
|
+
function parseBinaryWsFrame(data) {
|
|
694
|
+
const eventType = binaryFrameType(data);
|
|
695
|
+
if (isPreviewFrameType(eventType)) return parsePreviewFrame(data);
|
|
676
696
|
if (eventType === 3) {
|
|
677
|
-
const nodeIdLen =
|
|
697
|
+
const nodeIdLen = new DataView(data).getUint32(4);
|
|
678
698
|
const decoder = new TextDecoder();
|
|
679
699
|
return {
|
|
680
700
|
kind: "text",
|
|
@@ -682,25 +702,41 @@ function parseBinaryWsFrame(data) {
|
|
|
682
702
|
text: decoder.decode(data.slice(8 + nodeIdLen))
|
|
683
703
|
};
|
|
684
704
|
}
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
705
|
+
return {
|
|
706
|
+
kind: "unknown",
|
|
707
|
+
eventType
|
|
708
|
+
};
|
|
709
|
+
}
|
|
710
|
+
/** a type 1 or type 4 frame; the caller checked the type with `isPreviewFrameType` */
|
|
711
|
+
function parsePreviewFrame(data) {
|
|
712
|
+
const view = new DataView(data);
|
|
713
|
+
if (view.getUint32(0) === 1) {
|
|
714
|
+
const imageType = view.getUint32(4);
|
|
692
715
|
return {
|
|
693
716
|
kind: "preview",
|
|
694
|
-
bytes,
|
|
695
|
-
mime:
|
|
696
|
-
metadata
|
|
717
|
+
bytes: new Uint8Array(data.slice(8)),
|
|
718
|
+
mime: imageType === 2 ? "image/png" : "image/jpeg",
|
|
719
|
+
metadata: null
|
|
697
720
|
};
|
|
698
721
|
}
|
|
722
|
+
const metadataLen = view.getUint32(4);
|
|
723
|
+
let metadata = null;
|
|
724
|
+
try {
|
|
725
|
+
metadata = JSON.parse(new TextDecoder().decode(data.slice(8, 8 + metadataLen)));
|
|
726
|
+
} catch {}
|
|
727
|
+
const bytes = new Uint8Array(data.slice(8 + metadataLen));
|
|
699
728
|
return {
|
|
700
|
-
kind: "
|
|
701
|
-
|
|
729
|
+
kind: "preview",
|
|
730
|
+
bytes,
|
|
731
|
+
mime: bytes[0] === 137 && bytes[1] === 80 ? "image/png" : "image/jpeg",
|
|
732
|
+
metadata
|
|
702
733
|
};
|
|
703
734
|
}
|
|
735
|
+
/** the node a type 4 frame names (`node_id` in its metadata), null when absent or malformed */
|
|
736
|
+
function previewMetadataNodeId(metadata) {
|
|
737
|
+
if (metadata == null || typeof metadata !== "object" || !("node_id" in metadata)) return null;
|
|
738
|
+
return typeof metadata.node_id === "string" && metadata.node_id !== "" ? metadata.node_id : null;
|
|
739
|
+
}
|
|
704
740
|
//#endregion
|
|
705
741
|
//#region src/sdk-generator/Primitives.ts
|
|
706
742
|
const ComfyPrimitiveMapping = {
|
|
@@ -2350,6 +2386,7 @@ var ComfyExecution = class {
|
|
|
2350
2386
|
this.ephemeral = false;
|
|
2351
2387
|
this.snapshot = null;
|
|
2352
2388
|
this.onProgress = null;
|
|
2389
|
+
this.onPreview = null;
|
|
2353
2390
|
this.logProgress = false;
|
|
2354
2391
|
this.startedAt = Date.now();
|
|
2355
2392
|
this._lastLoggedLine = "";
|
|
@@ -2363,6 +2400,7 @@ var ComfyExecution = class {
|
|
|
2363
2400
|
bytes: msg.bytes,
|
|
2364
2401
|
mime: msg.mime
|
|
2365
2402
|
});
|
|
2403
|
+
else this.onPreviewFrame(msg);
|
|
2366
2404
|
return;
|
|
2367
2405
|
}
|
|
2368
2406
|
if (msg.type === "execution_start") return;
|
|
@@ -2609,6 +2647,7 @@ var ComfyExecution = class {
|
|
|
2609
2647
|
this.scrubHistory = init.scrubHistory ?? false;
|
|
2610
2648
|
this.ephemeral = init.ephemeral ?? false;
|
|
2611
2649
|
this.onProgress = init.onProgress ?? null;
|
|
2650
|
+
this.onPreview = init.onPreview ?? null;
|
|
2612
2651
|
this.logProgress = init.logProgress ?? false;
|
|
2613
2652
|
this.host.executions.set(data.id, this);
|
|
2614
2653
|
this.onCreate();
|
|
@@ -2689,6 +2728,28 @@ var ComfyExecution = class {
|
|
|
2689
2728
|
if (uid == null) return false;
|
|
2690
2729
|
return (this.snapshot?.apiJson ?? this.workflow.apiJson)[uid]?.class_type === "SaveImageWebsocket";
|
|
2691
2730
|
}
|
|
2731
|
+
/** @internal a live preview frame of this run; never an output (the host routes ws saver frames
|
|
2732
|
+
* to onWsImageOutput before they get here) */
|
|
2733
|
+
onPreviewFrame(p) {
|
|
2734
|
+
const listener = this.onPreview;
|
|
2735
|
+
if (listener == null) return;
|
|
2736
|
+
const current = this.workflow.currentExecutingNode;
|
|
2737
|
+
const nodeId = previewMetadataNodeId(p.metadata) ?? current?.uid ?? null;
|
|
2738
|
+
const apiJson = this.snapshot?.apiJson ?? this.workflow.apiJson;
|
|
2739
|
+
const counter = current != null && current.uid === nodeId ? current.progress : null;
|
|
2740
|
+
listener({
|
|
2741
|
+
promptId: this.data.id,
|
|
2742
|
+
bytes: p.bytes,
|
|
2743
|
+
mime: p.mime,
|
|
2744
|
+
nodeId,
|
|
2745
|
+
nodeName: nodeId != null ? apiJson[nodeId]?.class_type ?? null : null,
|
|
2746
|
+
step: counter != null ? {
|
|
2747
|
+
value: counter.value,
|
|
2748
|
+
max: counter.max
|
|
2749
|
+
} : null,
|
|
2750
|
+
metadata: p.metadata
|
|
2751
|
+
});
|
|
2752
|
+
}
|
|
2692
2753
|
/** @internal a live-text frame for one node */
|
|
2693
2754
|
onProgressText(p) {
|
|
2694
2755
|
this.progressTexts.set(p.nodeId, p.text);
|
|
@@ -3028,6 +3089,7 @@ var ComfyWorkflow = class {
|
|
|
3028
3089
|
ephemeral: p.ephemeral ?? false,
|
|
3029
3090
|
scrubHistory: p.scrubHistory ?? p.ephemeral ?? false,
|
|
3030
3091
|
onProgress: p.onProgress,
|
|
3092
|
+
onPreview: p.onPreview,
|
|
3031
3093
|
logProgress: p.log ?? false
|
|
3032
3094
|
});
|
|
3033
3095
|
};
|
|
@@ -5022,12 +5084,46 @@ var ToggleVar = class extends ComfyVar {
|
|
|
5022
5084
|
return this.value ? "ON" : "OFF";
|
|
5023
5085
|
}
|
|
5024
5086
|
};
|
|
5087
|
+
/** a fixed list, or the host's list for one slot once bindHost ran */
|
|
5088
|
+
var ChoiceList = class {
|
|
5089
|
+
constructor(source) {
|
|
5090
|
+
this.source = source;
|
|
5091
|
+
this.resolved = null;
|
|
5092
|
+
}
|
|
5093
|
+
get slot() {
|
|
5094
|
+
return isChoiceList(this.source) ? null : this.source;
|
|
5095
|
+
}
|
|
5096
|
+
get choices() {
|
|
5097
|
+
if (isChoiceList(this.source)) return this.source;
|
|
5098
|
+
if (this.resolved == null) throw new Error(`v.model('${this.source.slot}') is host-bound — it only works inside defineWorkflow({ vars }) (pass a name list to v.choice otherwise)`);
|
|
5099
|
+
return this.resolved;
|
|
5100
|
+
}
|
|
5101
|
+
/** cast: whitelist family 1 (agent/coding.md) — stringValues() returns the runtime values of
|
|
5102
|
+
* the SAME object_info enum the generated slot union comes from */
|
|
5103
|
+
bind(host) {
|
|
5104
|
+
const src = this.slot;
|
|
5105
|
+
if (src == null) return;
|
|
5106
|
+
const all = host.schema.stringValues(src.slot);
|
|
5107
|
+
const filter = src.filter == null ? null : statelessRegex(src.filter);
|
|
5108
|
+
this.resolved = filter == null ? all : all.filter((n) => filter.test(n));
|
|
5109
|
+
}
|
|
5110
|
+
};
|
|
5025
5111
|
var ChoiceVar = class extends ComfyVar {
|
|
5026
5112
|
constructor(choices, defaultValue, label) {
|
|
5027
5113
|
super(defaultValue, label);
|
|
5028
|
-
this.choices = choices;
|
|
5029
5114
|
this.kind = "choice";
|
|
5030
5115
|
this.select = "one";
|
|
5116
|
+
this.list = new ChoiceList(choices);
|
|
5117
|
+
}
|
|
5118
|
+
get choices() {
|
|
5119
|
+
return this.list.choices;
|
|
5120
|
+
}
|
|
5121
|
+
/** set for `v.model`: the loader input this choice lists */
|
|
5122
|
+
get hostSlot() {
|
|
5123
|
+
return this.list.slot;
|
|
5124
|
+
}
|
|
5125
|
+
bindHost(host) {
|
|
5126
|
+
this.list.bind(host);
|
|
5031
5127
|
}
|
|
5032
5128
|
next(delta = 1) {
|
|
5033
5129
|
const nextIx = (this.choices.indexOf(this.value) + delta + this.choices.length) % this.choices.length;
|
|
@@ -5044,9 +5140,18 @@ var ChoiceVar = class extends ComfyVar {
|
|
|
5044
5140
|
var OptionalChoiceVar = class extends ComfyVar {
|
|
5045
5141
|
constructor(choices, defaultValue, label) {
|
|
5046
5142
|
super(defaultValue, label);
|
|
5047
|
-
this.choices = choices;
|
|
5048
5143
|
this.kind = "choice";
|
|
5049
5144
|
this.select = "zero-or-one";
|
|
5145
|
+
this.list = new ChoiceList(choices);
|
|
5146
|
+
}
|
|
5147
|
+
get choices() {
|
|
5148
|
+
return this.list.choices;
|
|
5149
|
+
}
|
|
5150
|
+
get hostSlot() {
|
|
5151
|
+
return this.list.slot;
|
|
5152
|
+
}
|
|
5153
|
+
bindHost(host) {
|
|
5154
|
+
this.list.bind(host);
|
|
5050
5155
|
}
|
|
5051
5156
|
/** pick `c`, or clear it when it is already the one picked */
|
|
5052
5157
|
toggle(c) {
|
|
@@ -5124,6 +5229,14 @@ function choice(choices, defaultValue, opts) {
|
|
|
5124
5229
|
if (defaultValue == null) throw new Error("a 'one' choice needs a default: use { select: 'zero-or-one' } for none");
|
|
5125
5230
|
return new ChoiceVar(choices, defaultValue, o.label);
|
|
5126
5231
|
}
|
|
5232
|
+
function model(slot, opts) {
|
|
5233
|
+
const source = {
|
|
5234
|
+
slot,
|
|
5235
|
+
filter: opts.filter
|
|
5236
|
+
};
|
|
5237
|
+
if (opts.default == null) return new OptionalChoiceVar(source, null, opts.label);
|
|
5238
|
+
return new ChoiceVar(source, opts.default, opts.label);
|
|
5239
|
+
}
|
|
5127
5240
|
/** normalize a loras record into what a standard LoraLoader chain consumes */
|
|
5128
5241
|
function activeLoras(loras) {
|
|
5129
5242
|
const out = [];
|
|
@@ -5538,7 +5651,7 @@ var VideoVar = class extends MediaVar {
|
|
|
5538
5651
|
return await this.loadVia(wf);
|
|
5539
5652
|
}
|
|
5540
5653
|
};
|
|
5541
|
-
/** the var constructors: v.text / v.prompt / v.int / v.float / v.seed / v.toggle / v.choice / v.loras / v.size / v.image / v.audio / v.video */
|
|
5654
|
+
/** the var constructors: v.text / v.prompt / v.int / v.float / v.seed / v.toggle / v.choice / v.model / v.loras / v.size / v.image / v.audio / v.video */
|
|
5542
5655
|
const v = {
|
|
5543
5656
|
text: (defaultValue, opts = {}) => new TextVar(defaultValue, typeof opts === "string" ? { label: opts } : opts),
|
|
5544
5657
|
prompt: (defaultValue, opts = {}) => new PromptVar(defaultValue, opts),
|
|
@@ -5553,6 +5666,8 @@ const v = {
|
|
|
5553
5666
|
choice,
|
|
5554
5667
|
loras: (options, initial = {}, label) => new LorasVar(options, initial, label),
|
|
5555
5668
|
size: (defaultValue, opts = {}) => new SizeVar(defaultValue, opts.presets ?? sizePresetsFor(defaultValue), opts.label, opts.image, opts.starred),
|
|
5669
|
+
/** host-bound: only inside defineWorkflow({ vars: (v) => … }), typed per slot there */
|
|
5670
|
+
model,
|
|
5556
5671
|
image: (defaultValue, opts = {}) => new ImageVar(defaultValue, opts),
|
|
5557
5672
|
audio: (defaultValue, opts = {}) => new AudioVar(defaultValue, opts),
|
|
5558
5673
|
video: (defaultValue, opts = {}) => new VideoVar(defaultValue, opts)
|
|
@@ -5646,7 +5761,8 @@ var DefinedWorkflow = class {
|
|
|
5646
5761
|
scrubHistory: settings.scrubHistory,
|
|
5647
5762
|
idMode: settings.idMode,
|
|
5648
5763
|
log: settings.log,
|
|
5649
|
-
onProgress: settings.onProgress
|
|
5764
|
+
onProgress: settings.onProgress,
|
|
5765
|
+
onPreview: settings.onPreview
|
|
5650
5766
|
});
|
|
5651
5767
|
this.lastExecution = execution;
|
|
5652
5768
|
return execution;
|
|
@@ -5951,6 +6067,11 @@ var ComfyHost = class {
|
|
|
5951
6067
|
this.clearHistory = () => {
|
|
5952
6068
|
return this.postJSON_("/history", { clear: true });
|
|
5953
6069
|
};
|
|
6070
|
+
this.fetchPreviewMethod = async () => {
|
|
6071
|
+
const res = await this.fetch("/system_stats", {});
|
|
6072
|
+
if (!res.ok) throw new Error(`GET /system_stats failed: ${res.status}`);
|
|
6073
|
+
return previewMethodFromSystemStats(await res.json());
|
|
6074
|
+
};
|
|
5954
6075
|
this.fetchRawLogs = async () => {
|
|
5955
6076
|
const res = await this.fetch("/internal/logs/raw", {}, { apiPrefix: false });
|
|
5956
6077
|
if (!res.ok) throw new Error(`GET /internal/logs/raw failed: ${res.status}`);
|
|
@@ -6027,7 +6148,8 @@ var ComfyHost = class {
|
|
|
6027
6148
|
this.executions = /* @__PURE__ */ new Map();
|
|
6028
6149
|
this._pendingMsgs = /* @__PURE__ */ new Map();
|
|
6029
6150
|
this.activePromptID = null;
|
|
6030
|
-
this.
|
|
6151
|
+
this._latentFrame = null;
|
|
6152
|
+
this._latentPreview = null;
|
|
6031
6153
|
this.onLatentPreview = null;
|
|
6032
6154
|
this.onProgressText = null;
|
|
6033
6155
|
this.onStatus = null;
|
|
@@ -6204,42 +6326,60 @@ var ComfyHost = class {
|
|
|
6204
6326
|
}
|
|
6205
6327
|
prompt.onPromptRelatedMessage(msg);
|
|
6206
6328
|
}
|
|
6329
|
+
/** the latent image beeing generated, in case you want to display it. Built on read: a
|
|
6330
|
+
* session that never reads it never decodes a frame nor holds an object url */
|
|
6331
|
+
get latentPreview() {
|
|
6332
|
+
if (this._latentPreview != null || this._latentFrame == null) return this._latentPreview;
|
|
6333
|
+
const frame = parsePreviewFrame(this._latentFrame.data);
|
|
6334
|
+
const blob = new Blob([frame.bytes], { type: frame.mime });
|
|
6335
|
+
this._latentPreview = {
|
|
6336
|
+
blob,
|
|
6337
|
+
url: URL.createObjectURL(blob),
|
|
6338
|
+
receivedAt: this._latentFrame.receivedAt,
|
|
6339
|
+
promptID: this._latentFrame.promptID
|
|
6340
|
+
};
|
|
6341
|
+
return this._latentPreview;
|
|
6342
|
+
}
|
|
6343
|
+
/** a type 1 or 4 frame. Parsed only when someone wants it, in this order (architecture.md,
|
|
6344
|
+
* Live previews): the ws saver's output, the pre-registration buffer, the run's onPreview,
|
|
6345
|
+
* the host hook. Nobody listening = the frame is kept by reference and never copied */
|
|
6346
|
+
onPreviewFrame(data) {
|
|
6347
|
+
let parsed = null;
|
|
6348
|
+
const frame = () => parsed ??= parsePreviewFrame(data);
|
|
6349
|
+
const promptID = this.activePromptID;
|
|
6350
|
+
const activeExec = promptID != null ? this.executions.get(promptID) : null;
|
|
6351
|
+
if (activeExec?.wsOutputNodeExecuting) return activeExec.onWsImageOutput({
|
|
6352
|
+
bytes: frame().bytes,
|
|
6353
|
+
mime: frame().mime
|
|
6354
|
+
});
|
|
6355
|
+
const pending = promptID != null ? this._pendingMsgs.get(promptID) : void 0;
|
|
6356
|
+
if (pending != null) pending.push({
|
|
6357
|
+
type: "binary_preview_frame",
|
|
6358
|
+
bytes: frame().bytes,
|
|
6359
|
+
mime: frame().mime,
|
|
6360
|
+
metadata: frame().metadata
|
|
6361
|
+
});
|
|
6362
|
+
if (this._latentPreview != null) URL.revokeObjectURL(this._latentPreview.url);
|
|
6363
|
+
this._latentPreview = null;
|
|
6364
|
+
this._latentFrame = {
|
|
6365
|
+
data,
|
|
6366
|
+
promptID,
|
|
6367
|
+
receivedAt: Date.now()
|
|
6368
|
+
};
|
|
6369
|
+
if (activeExec?.onPreview != null) activeExec.onPreviewFrame(frame());
|
|
6370
|
+
if (this.onLatentPreview != null) this.onLatentPreview({
|
|
6371
|
+
bytes: frame().bytes,
|
|
6372
|
+
mime: frame().mime,
|
|
6373
|
+
promptID
|
|
6374
|
+
});
|
|
6375
|
+
}
|
|
6207
6376
|
onMessage(e) {
|
|
6208
6377
|
this.lastWsMessageAt = Date.now();
|
|
6209
6378
|
if (this.data.onWsMessageAny) this.data.onWsMessageAny(e);
|
|
6210
6379
|
if (e.data instanceof ArrayBuffer) {
|
|
6380
|
+
if (isPreviewFrameType(binaryFrameType(e.data))) return this.onPreviewFrame(e.data);
|
|
6211
6381
|
const frame = parseBinaryWsFrame(e.data);
|
|
6212
|
-
if (frame.kind === "
|
|
6213
|
-
const activeExec = this.activePromptID != null ? this.executions.get(this.activePromptID) : null;
|
|
6214
|
-
if (activeExec?.wsOutputNodeExecuting) {
|
|
6215
|
-
activeExec.onWsImageOutput({
|
|
6216
|
-
bytes: frame.bytes,
|
|
6217
|
-
mime: frame.mime
|
|
6218
|
-
});
|
|
6219
|
-
return;
|
|
6220
|
-
}
|
|
6221
|
-
if (this.activePromptID != null) {
|
|
6222
|
-
const pending = this._pendingMsgs.get(this.activePromptID);
|
|
6223
|
-
if (pending != null) pending.push({
|
|
6224
|
-
type: "binary_preview_frame",
|
|
6225
|
-
bytes: frame.bytes,
|
|
6226
|
-
mime: frame.mime
|
|
6227
|
-
});
|
|
6228
|
-
}
|
|
6229
|
-
if (this.latentPreview != null) URL.revokeObjectURL(this.latentPreview.url);
|
|
6230
|
-
const imageBlob = new Blob([frame.bytes], { type: frame.mime });
|
|
6231
|
-
this.latentPreview = {
|
|
6232
|
-
blob: imageBlob,
|
|
6233
|
-
url: URL.createObjectURL(imageBlob),
|
|
6234
|
-
receivedAt: Date.now(),
|
|
6235
|
-
promptID: this.activePromptID
|
|
6236
|
-
};
|
|
6237
|
-
this.onLatentPreview?.({
|
|
6238
|
-
bytes: frame.bytes,
|
|
6239
|
-
mime: frame.mime,
|
|
6240
|
-
promptID: this.activePromptID
|
|
6241
|
-
});
|
|
6242
|
-
} else if (frame.kind === "unknown" && !this._unknownBinaryFrameTypes.has(frame.eventType)) {
|
|
6382
|
+
if (frame.kind === "unknown" && !this._unknownBinaryFrameTypes.has(frame.eventType)) {
|
|
6243
6383
|
this._unknownBinaryFrameTypes.add(frame.eventType);
|
|
6244
6384
|
console.error(`🔴 unknown binary ws frame type ${frame.eventType} from host ${this.data.id} — ignored`);
|
|
6245
6385
|
}
|