comfy-ts 0.3.0 → 0.4.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 +3 -3
- package/dist/cli.js +1 -1
- package/dist/index.cjs +45 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +48 -0
- package/dist/index.d.ts +48 -0
- package/dist/index.js +45 -2
- package/dist/index.js.map +1 -1
- package/dist/{run-tui-Io8Xea0L.js → run-tui-SDSJo1Qf.js} +638 -82
- package/dist/run-tui-SDSJo1Qf.js.map +1 -0
- package/package.json +2 -3
- package/src/cli/tui/components/Header.tsx +5 -0
- package/src/cli/tui/components/LogsPanel.tsx +23 -0
- package/src/cli/tui/components/PreviewPanel.tsx +52 -7
- package/src/cli/tui/components/StatusBar.tsx +10 -4
- package/src/cli/tui/components/TuiApp.tsx +26 -3
- package/src/cli/tui/protocolImagePainter.ts +54 -18
- package/src/cli/tui/run-tui.tsx +4 -1
- package/src/cli/tui/state/ExecSt.ts +4 -1
- package/src/cli/tui/state/HostSt.ts +124 -1
- package/src/cli/tui/state/LogsSt.ts +107 -0
- package/src/cli/tui/state/PreviewSt.ts +173 -23
- package/src/cli/tui/state/SettingsSt.ts +48 -21
- package/src/cli/tui/state/TuiSt.ts +6 -0
- package/src/cli/tui/state/WorkflowsSt.ts +1 -0
- package/src/host/ComfyHost.ts +44 -0
- package/src/runner/ComfyWsApi.ts +12 -1
- package/src/ssh-host-manager/ssh-manager.ts +0 -15
- package/src/utils/ansi.ts +7 -0
- package/src/utils/mojibake.ts +60 -0
- package/dist/run-tui-Io8Xea0L.js.map +0 -1
|
@@ -6,6 +6,7 @@ import { pathToFileURL } from "node:url";
|
|
|
6
6
|
import { Box, Text, render, useApp, useInput, useStdin } from "ink";
|
|
7
7
|
import { action, makeAutoObservable, makeObservable, observable, reaction, runInAction } from "mobx";
|
|
8
8
|
import sharp from "sharp";
|
|
9
|
+
import { imageMeta } from "image-meta";
|
|
9
10
|
import { observer } from "mobx-react-lite";
|
|
10
11
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
11
12
|
import { spawn } from "node:child_process";
|
|
@@ -623,12 +624,16 @@ function protocolCapable() {
|
|
|
623
624
|
const term = process.env.TERM_PROGRAM ?? "";
|
|
624
625
|
return term === "iTerm.app" || term === "WezTerm" || term === "vscode" || process.env.LC_TERMINAL === "iTerm2";
|
|
625
626
|
}
|
|
627
|
+
/** small-latent corner: fraction of the panel each dimension takes */
|
|
628
|
+
const CORNER_FRACTION = .38;
|
|
629
|
+
/** pixel 'latent small': the sharp-composited thumb takes this fraction of the panel */
|
|
630
|
+
const PIXEL_SMALL_FRACTION = .4;
|
|
626
631
|
/**
|
|
627
|
-
* right-side preview panel
|
|
628
|
-
*
|
|
629
|
-
*
|
|
630
|
-
*
|
|
631
|
-
* lora while the loras overlay is open.
|
|
632
|
+
* right-side preview panel + its `p` settings menu (mode 'preview').
|
|
633
|
+
* Three independent axes live in SettingsSt: panel on/off, renderer
|
|
634
|
+
* native/pixel, and what to show while running (latent / latent small /
|
|
635
|
+
* last output). Sources: live latent while running, last output after,
|
|
636
|
+
* selected lora while the loras overlay is open.
|
|
632
637
|
*/
|
|
633
638
|
var PreviewSt = class {
|
|
634
639
|
constructor(st) {
|
|
@@ -637,45 +642,143 @@ var PreviewSt = class {
|
|
|
637
642
|
this.latentAnsi = null;
|
|
638
643
|
this.outputBytes = null;
|
|
639
644
|
this.latentBytes = null;
|
|
645
|
+
this.latentDims = null;
|
|
646
|
+
this.latentSeenThisRun = false;
|
|
640
647
|
this.lastOutputPath = null;
|
|
648
|
+
this.menuIx = 0;
|
|
641
649
|
this._busy = false;
|
|
642
650
|
makeAutoObservable(this, { st: false });
|
|
643
651
|
}
|
|
644
|
-
get mode() {
|
|
645
|
-
return this.st.settings.previewMode;
|
|
646
|
-
}
|
|
647
652
|
get show() {
|
|
648
|
-
return this.
|
|
653
|
+
return this.st.settings.previewPanel;
|
|
654
|
+
}
|
|
655
|
+
get renderer() {
|
|
656
|
+
return this.st.settings.previewRenderer;
|
|
649
657
|
}
|
|
650
|
-
/** SettingsSt already downgrades native → ansi on incapable terminals */
|
|
651
658
|
get useNative() {
|
|
652
|
-
return this.
|
|
659
|
+
return this.renderer === "native";
|
|
660
|
+
}
|
|
661
|
+
get duringRun() {
|
|
662
|
+
return this.st.settings.previewDuringRun;
|
|
663
|
+
}
|
|
664
|
+
get menuOpen() {
|
|
665
|
+
return this.st.mode === "preview";
|
|
666
|
+
}
|
|
667
|
+
/** running + latents wanted + sampling well underway + none arrived = server
|
|
668
|
+
* sends none. The ≥20% gate keeps healthy runs from red-flashing: the first
|
|
669
|
+
* progress tick lands a beat before the first preview frame */
|
|
670
|
+
get latentsMissing() {
|
|
671
|
+
return this.st.exec.running && this.duringRun !== "last-output" && (this.st.exec.progress?.percent ?? 0) >= 20 && !this.latentSeenThisRun;
|
|
672
|
+
}
|
|
673
|
+
get menuRows() {
|
|
674
|
+
return [
|
|
675
|
+
{
|
|
676
|
+
key: "panel",
|
|
677
|
+
label: "panel",
|
|
678
|
+
value: this.show ? "on" : "off"
|
|
679
|
+
},
|
|
680
|
+
{
|
|
681
|
+
key: "renderer",
|
|
682
|
+
label: "renderer",
|
|
683
|
+
value: this.renderer + (protocolCapable() ? "" : " (no protocol support)")
|
|
684
|
+
},
|
|
685
|
+
{
|
|
686
|
+
key: "during-run",
|
|
687
|
+
label: "while running",
|
|
688
|
+
value: this.duringRun === "latent" ? "latent" : this.duringRun === "latent-small" ? "latent small" : "last output"
|
|
689
|
+
}
|
|
690
|
+
];
|
|
691
|
+
}
|
|
692
|
+
beginMenu() {
|
|
693
|
+
this.st.mode = "preview";
|
|
694
|
+
this.menuIx = 0;
|
|
695
|
+
}
|
|
696
|
+
blurMenu() {
|
|
697
|
+
this.st.mode = "nav";
|
|
698
|
+
}
|
|
699
|
+
menuMove(delta) {
|
|
700
|
+
const len = this.menuRows.length;
|
|
701
|
+
this.menuIx = (this.menuIx + delta + len) % len;
|
|
702
|
+
}
|
|
703
|
+
/** cycle the selected row's value (settings persist via SettingsSt reaction) */
|
|
704
|
+
menuCycle(delta) {
|
|
705
|
+
const row = this.menuRows[this.menuIx];
|
|
706
|
+
if (row == null) return;
|
|
707
|
+
const s = this.st.settings;
|
|
708
|
+
if (row.key === "panel") s.previewPanel = !s.previewPanel;
|
|
709
|
+
else if (row.key === "renderer") {
|
|
710
|
+
if (protocolCapable()) s.previewRenderer = s.previewRenderer === "native" ? "pixel" : "native";
|
|
711
|
+
} else {
|
|
712
|
+
const order = [
|
|
713
|
+
"latent",
|
|
714
|
+
"latent-small",
|
|
715
|
+
"last-output"
|
|
716
|
+
];
|
|
717
|
+
s.previewDuringRun = order[(order.indexOf(s.previewDuringRun) + delta + order.length) % order.length] ?? "latent";
|
|
718
|
+
}
|
|
719
|
+
this.onSettingsChanged();
|
|
653
720
|
}
|
|
654
721
|
reset() {
|
|
655
722
|
this.outputAnsi = null;
|
|
656
723
|
this.latentAnsi = null;
|
|
657
724
|
this.outputBytes = null;
|
|
658
725
|
this.latentBytes = null;
|
|
726
|
+
this.latentDims = null;
|
|
727
|
+
this.latentSeenThisRun = false;
|
|
659
728
|
this.lastOutputPath = null;
|
|
660
729
|
}
|
|
661
730
|
/** run boundary: drop the latents so the next run never shows the previous one's */
|
|
662
731
|
clearLatent() {
|
|
663
732
|
this.latentAnsi = null;
|
|
664
733
|
this.latentBytes = null;
|
|
734
|
+
this.latentDims = null;
|
|
735
|
+
this.latentSeenThisRun = false;
|
|
665
736
|
}
|
|
666
|
-
/** re-render the last output
|
|
667
|
-
|
|
737
|
+
/** re-render the last output for the newly chosen settings */
|
|
738
|
+
onSettingsChanged() {
|
|
668
739
|
this.outputAnsi = null;
|
|
669
740
|
this.outputBytes = null;
|
|
670
|
-
if (this.
|
|
741
|
+
if (this.show && this.lastOutputPath != null) this.renderOutput(this.lastOutputPath);
|
|
671
742
|
}
|
|
672
|
-
/** what the painter should show RIGHT NOW (native
|
|
743
|
+
/** what the painter should show RIGHT NOW (native renderer only; mirrors the panel's source) */
|
|
673
744
|
get protocolImage() {
|
|
674
|
-
if (!this.useNative || !this.show) return null;
|
|
745
|
+
if (!this.useNative || !this.show || this.menuOpen) return null;
|
|
675
746
|
if (this.st.mode === "overlay-loras") return this.st.loras.previewBytes;
|
|
676
|
-
if (this.st.exec.running
|
|
747
|
+
if (this.st.exec.running) {
|
|
748
|
+
if (this.duringRun === "latent") return this.latentBytes ?? this.outputBytes;
|
|
749
|
+
return this.outputBytes;
|
|
750
|
+
}
|
|
677
751
|
return this.outputBytes;
|
|
678
752
|
}
|
|
753
|
+
/** small latent painted over the panel's top-right corner (native + 'latent small' only) */
|
|
754
|
+
get protocolImageCorner() {
|
|
755
|
+
if (!this.useNative || !this.show || this.menuOpen) return null;
|
|
756
|
+
if (this.st.mode === "overlay-loras") return null;
|
|
757
|
+
if (this.st.exec.running && this.duringRun === "latent-small") return this.latentBytes;
|
|
758
|
+
return null;
|
|
759
|
+
}
|
|
760
|
+
/** corner cell box matched to the latent's REAL aspect (a mismatched box
|
|
761
|
+
* letterboxes in iTerm — his repro: "some vertical rectangle"). Cells are
|
|
762
|
+
* ~1:2 (w:h), hence the ×2 when converting image aspect to cells. */
|
|
763
|
+
get cornerBox() {
|
|
764
|
+
let w = Math.max(8, Math.floor(this.width * CORNER_FRACTION));
|
|
765
|
+
const maxH = Math.max(4, Math.floor(this.height * CORNER_FRACTION));
|
|
766
|
+
const dims = this.latentDims;
|
|
767
|
+
if (dims == null || dims.width === 0 || dims.height === 0) return {
|
|
768
|
+
w,
|
|
769
|
+
h: maxH
|
|
770
|
+
};
|
|
771
|
+
const aspect = dims.width / dims.height;
|
|
772
|
+
let h = Math.max(2, Math.round(w / aspect / 2));
|
|
773
|
+
if (h > maxH) {
|
|
774
|
+
h = maxH;
|
|
775
|
+
w = Math.max(4, Math.round(h * aspect * 2));
|
|
776
|
+
}
|
|
777
|
+
return {
|
|
778
|
+
w,
|
|
779
|
+
h
|
|
780
|
+
};
|
|
781
|
+
}
|
|
679
782
|
get width() {
|
|
680
783
|
return Math.max(24, Math.min(80, this.st.termCols - 68 - this.st.treeWidth));
|
|
681
784
|
}
|
|
@@ -684,7 +787,7 @@ var PreviewSt = class {
|
|
|
684
787
|
}
|
|
685
788
|
async renderOutput(path) {
|
|
686
789
|
this.lastOutputPath = path;
|
|
687
|
-
if (this.
|
|
790
|
+
if (!this.show) return;
|
|
688
791
|
try {
|
|
689
792
|
if (this.useNative) {
|
|
690
793
|
const shrunk = await sharp(path).resize(896, 896, {
|
|
@@ -710,15 +813,23 @@ var PreviewSt = class {
|
|
|
710
813
|
}
|
|
711
814
|
}
|
|
712
815
|
async renderLatent(bytes) {
|
|
713
|
-
|
|
816
|
+
runInAction(() => {
|
|
817
|
+
this.latentSeenThisRun = true;
|
|
818
|
+
});
|
|
819
|
+
if (!this.show || this.duringRun === "last-output") return;
|
|
714
820
|
if (this.useNative) {
|
|
821
|
+
const meta = imageMeta(bytes);
|
|
715
822
|
this.latentBytes = bytes;
|
|
823
|
+
this.latentDims = meta.width != null && meta.height != null ? {
|
|
824
|
+
width: meta.width,
|
|
825
|
+
height: meta.height
|
|
826
|
+
} : null;
|
|
716
827
|
return;
|
|
717
828
|
}
|
|
718
829
|
if (this._busy) return;
|
|
719
830
|
this._busy = true;
|
|
720
831
|
try {
|
|
721
|
-
const ansi = await imageBufferToAnsi(bytes, {
|
|
832
|
+
const ansi = this.duringRun === "latent-small" ? await this.renderLatentSmallPixel(bytes) : await imageBufferToAnsi(bytes, {
|
|
722
833
|
width: this.width,
|
|
723
834
|
height: this.height
|
|
724
835
|
});
|
|
@@ -733,46 +844,92 @@ var PreviewSt = class {
|
|
|
733
844
|
this._busy = false;
|
|
734
845
|
}
|
|
735
846
|
}
|
|
847
|
+
/** pixel 'latent small': sharp-composite the latent thumb onto the last
|
|
848
|
+
* output (top-right), then ONE half-block render — a string-level overlay
|
|
849
|
+
* was tried and dropped: its space padding reads as black bars */
|
|
850
|
+
async renderLatentSmallPixel(bytes) {
|
|
851
|
+
const pxW = this.width;
|
|
852
|
+
const pxH = this.height * 2;
|
|
853
|
+
const thumb = await sharp(bytes).resize(Math.max(8, Math.floor(pxW * PIXEL_SMALL_FRACTION)), Math.max(8, Math.floor(pxH * PIXEL_SMALL_FRACTION)), { fit: "inside" }).png().toBuffer();
|
|
854
|
+
const outPath = this.lastOutputPath;
|
|
855
|
+
if (outPath == null) return imageBufferToAnsi(thumb, {
|
|
856
|
+
width: this.width,
|
|
857
|
+
height: this.height
|
|
858
|
+
});
|
|
859
|
+
return imageBufferToAnsi(await sharp(await sharp(outPath).resize(pxW, pxH, { fit: "inside" }).png().toBuffer()).composite([{
|
|
860
|
+
input: thumb,
|
|
861
|
+
gravity: "northeast"
|
|
862
|
+
}]).png().toBuffer(), {
|
|
863
|
+
width: this.width,
|
|
864
|
+
height: this.height
|
|
865
|
+
});
|
|
866
|
+
}
|
|
736
867
|
};
|
|
737
868
|
//#endregion
|
|
738
869
|
//#region src/cli/tui/protocolImagePainter.ts
|
|
870
|
+
const SYNC_BEGIN = "\x1B[?2026h";
|
|
871
|
+
const SYNC_END = "\x1B[?2026l";
|
|
872
|
+
/** below this a write is a terminal query/reply, not a frame — no cells damaged */
|
|
873
|
+
const MIN_FRAME_BYTES = 64;
|
|
739
874
|
/**
|
|
740
875
|
* paints the REAL image (OSC 1337) over the preview panel's cell rect.
|
|
741
876
|
* Protocol images cannot go THROUGH ink (layout shreds the escape) and every
|
|
742
877
|
* ink frame write ERASES the image's cells — so this hooks stdout.write and
|
|
743
|
-
* re-paints
|
|
744
|
-
*
|
|
878
|
+
* re-paints SYNCHRONOUSLY within the same flush, the whole batch wrapped in
|
|
879
|
+
* DEC 2026 synchronized-update markers: the terminal never presents the
|
|
880
|
+
* erased-frame intermediate state. (The previous deferred setImmediate
|
|
881
|
+
* repaint WAS the native-mode flicker — his repro.) A mobx reaction covers
|
|
882
|
+
* byte-only changes (fresh latent/output/lora bytes with no frame write).
|
|
745
883
|
* NOT React: effects only fire for the component that re-rendered, which is
|
|
746
884
|
* why a useEffect painter missed frames (his report: image waited for input).
|
|
747
885
|
*/
|
|
748
886
|
function installProtocolImagePainter(st) {
|
|
749
887
|
if (!protocolCapable() || process.stdout.isTTY !== true) return () => {};
|
|
750
888
|
const original = process.stdout.write.bind(process.stdout);
|
|
751
|
-
const
|
|
752
|
-
const
|
|
753
|
-
|
|
889
|
+
const imageEscape = (bytes, row, col, w, h) => {
|
|
890
|
+
const b64 = Buffer.from(bytes).toString("base64");
|
|
891
|
+
return `\u001b7\u001b[${row};${col}H\u001b]1337;File=inline=1;size=${bytes.byteLength};width=${w};height=${h};preserveAspectRatio=1:${b64}\u0007\u001b8`;
|
|
892
|
+
};
|
|
893
|
+
const CONTENT_ROW = 6;
|
|
894
|
+
/** both images as ONE escape string ('' when nothing to paint) */
|
|
895
|
+
const imageEscapes = () => {
|
|
754
896
|
const pv = st.preview;
|
|
897
|
+
const main = pv.protocolImage;
|
|
898
|
+
const corner = pv.protocolImageCorner;
|
|
899
|
+
if (main == null && corner == null) return "";
|
|
755
900
|
const col = Math.max(1, st.termCols - (pv.width + 4) + 3);
|
|
756
|
-
|
|
757
|
-
|
|
901
|
+
let out = "";
|
|
902
|
+
if (main != null) out += imageEscape(main, CONTENT_ROW, col, pv.width, pv.height);
|
|
903
|
+
if (corner != null) {
|
|
904
|
+
const box = pv.cornerBox;
|
|
905
|
+
out += imageEscape(corner, CONTENT_ROW, col + pv.width - box.w, box.w, box.h);
|
|
906
|
+
}
|
|
907
|
+
return out;
|
|
758
908
|
};
|
|
909
|
+
let disposed = false;
|
|
910
|
+
/** byte-only changes (no frame write erased anything): paint alone, atomically */
|
|
759
911
|
let scheduled = false;
|
|
760
912
|
const schedule = () => {
|
|
761
|
-
if (scheduled) return;
|
|
913
|
+
if (scheduled || disposed) return;
|
|
762
914
|
scheduled = true;
|
|
763
915
|
setImmediate(() => {
|
|
764
|
-
paint();
|
|
765
916
|
scheduled = false;
|
|
917
|
+
if (disposed) return;
|
|
918
|
+
const images = imageEscapes();
|
|
919
|
+
if (images !== "") original(SYNC_BEGIN + images + SYNC_END);
|
|
766
920
|
});
|
|
767
921
|
};
|
|
768
922
|
const patched = ((chunk, encodingOrCb, cb) => {
|
|
923
|
+
const images = !disposed && (typeof chunk === "string" ? chunk.length : chunk.byteLength) >= MIN_FRAME_BYTES ? imageEscapes() : "";
|
|
924
|
+
if (images !== "") original(SYNC_BEGIN);
|
|
769
925
|
const res = typeof encodingOrCb === "function" ? original(chunk, encodingOrCb) : original(chunk, encodingOrCb, cb);
|
|
770
|
-
|
|
926
|
+
if (images !== "") original(images + SYNC_END);
|
|
771
927
|
return res;
|
|
772
928
|
});
|
|
773
929
|
process.stdout.write = patched;
|
|
774
|
-
const disposeReaction = reaction(() => st.preview.protocolImage, schedule);
|
|
930
|
+
const disposeReaction = reaction(() => [st.preview.protocolImage, st.preview.protocolImageCorner], schedule);
|
|
775
931
|
return () => {
|
|
932
|
+
disposed = true;
|
|
776
933
|
process.stdout.write = original;
|
|
777
934
|
disposeReaction();
|
|
778
935
|
};
|
|
@@ -956,6 +1113,11 @@ const MODE_KEYS = {
|
|
|
956
1113
|
["⏎", "run action"],
|
|
957
1114
|
["↑↓", "move"],
|
|
958
1115
|
["h/esc", "back"]
|
|
1116
|
+
],
|
|
1117
|
+
preview: [
|
|
1118
|
+
["←→", "change"],
|
|
1119
|
+
["↑↓", "move"],
|
|
1120
|
+
["⏎/p/esc", "done"]
|
|
959
1121
|
]
|
|
960
1122
|
};
|
|
961
1123
|
/** persistent 2-line keybar: EVERYTHING available right now, always visible */
|
|
@@ -967,13 +1129,13 @@ const KeyBar = observer((p) => {
|
|
|
967
1129
|
["←", "tree"],
|
|
968
1130
|
...kind ? KIND_KEYS[kind] ?? [] : []
|
|
969
1131
|
];
|
|
970
|
-
const globalHints = s.mode === "nav" || s.mode === "tree" || s.mode === "host" ? [
|
|
1132
|
+
const globalHints = s.mode === "nav" || s.mode === "tree" || s.mode === "host" || s.mode === "preview" ? [
|
|
971
1133
|
["r", "run"],
|
|
972
1134
|
["s", "reroll+run"],
|
|
973
1135
|
...s.mode === "nav" ? [["e", "rename draft"]] : [],
|
|
974
|
-
...s.preview.show ? [] : [["p", "preview off"]],
|
|
1136
|
+
...s.preview.show || s.mode === "preview" ? [] : [["p", "preview (off)"]],
|
|
975
1137
|
["o", "open image"],
|
|
976
|
-
...s.mode === "tree" ? [] : [["c/C", "copy wf/api"]],
|
|
1138
|
+
...s.mode === "tree" || s.mode === "preview" ? [] : [["c/C", "copy wf/api"]],
|
|
977
1139
|
["q", "quit"]
|
|
978
1140
|
] : [["⌃R", "run"], ["esc", "back"]];
|
|
979
1141
|
return /* @__PURE__ */ jsxs(Box, {
|
|
@@ -1061,21 +1223,32 @@ const Header = observer((p) => {
|
|
|
1061
1223
|
}),
|
|
1062
1224
|
/* @__PURE__ */ jsx(HeaderBox, {
|
|
1063
1225
|
title: "(h)ost",
|
|
1064
|
-
children: /* @__PURE__ */ jsxs(Text, { children: [
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1226
|
+
children: /* @__PURE__ */ jsxs(Text, { children: [
|
|
1227
|
+
/* @__PURE__ */ jsx(Text, {
|
|
1228
|
+
color: s.host.status === "up" ? "green" : s.host.status === "down" ? "red" : "gray",
|
|
1229
|
+
children: "● "
|
|
1230
|
+
}),
|
|
1231
|
+
/* @__PURE__ */ jsx(Text, {
|
|
1232
|
+
bold: true,
|
|
1233
|
+
color: "green",
|
|
1234
|
+
children: s.wf.host.data.id
|
|
1235
|
+
}),
|
|
1236
|
+
/* @__PURE__ */ jsxs(Text, {
|
|
1237
|
+
color: "gray",
|
|
1238
|
+
children: [
|
|
1239
|
+
" ",
|
|
1240
|
+
"(",
|
|
1241
|
+
s.wf.host.data.host,
|
|
1242
|
+
":",
|
|
1243
|
+
s.wf.host.data.port,
|
|
1244
|
+
")"
|
|
1245
|
+
]
|
|
1246
|
+
}),
|
|
1247
|
+
s.host.status === "down" && /* @__PURE__ */ jsxs(Text, {
|
|
1248
|
+
color: "red",
|
|
1249
|
+
children: [" ", s.host.probing ? s.host.spinner : `↻ ${s.host.retryInS}s`]
|
|
1250
|
+
})
|
|
1251
|
+
] })
|
|
1079
1252
|
})
|
|
1080
1253
|
]
|
|
1081
1254
|
});
|
|
@@ -1281,17 +1454,56 @@ const SizeOverlay = observer((p) => {
|
|
|
1281
1454
|
});
|
|
1282
1455
|
//#endregion
|
|
1283
1456
|
//#region src/cli/tui/components/PreviewPanel.tsx
|
|
1284
|
-
/** right-side panel: selected-lora preview in the loras overlay, live latent while running,
|
|
1457
|
+
/** right-side panel: selected-lora preview in the loras overlay, live latent while running,
|
|
1458
|
+
* last output after — plus the `p` settings menu (mode 'preview') rendered in place.
|
|
1285
1459
|
* protocol terminals: the body is BLANK cells — useProtocolImage paints the real image over them */
|
|
1286
1460
|
const PreviewPanel = observer((p) => {
|
|
1287
1461
|
const s = p.st;
|
|
1288
1462
|
const pv = s.preview;
|
|
1463
|
+
if (pv.menuOpen) return /* @__PURE__ */ jsxs(Box, {
|
|
1464
|
+
borderStyle: "double",
|
|
1465
|
+
paddingX: 1,
|
|
1466
|
+
flexDirection: "column",
|
|
1467
|
+
flexShrink: 0,
|
|
1468
|
+
width: pv.width + 4,
|
|
1469
|
+
children: [
|
|
1470
|
+
/* @__PURE__ */ jsx(Box, {
|
|
1471
|
+
marginTop: -1,
|
|
1472
|
+
children: /* @__PURE__ */ jsx(Text, {
|
|
1473
|
+
color: "gray",
|
|
1474
|
+
children: "(p)review · settings"
|
|
1475
|
+
})
|
|
1476
|
+
}),
|
|
1477
|
+
pv.menuRows.map((row, ix) => {
|
|
1478
|
+
const sel = ix === pv.menuIx;
|
|
1479
|
+
return /* @__PURE__ */ jsxs(Text, {
|
|
1480
|
+
inverse: sel,
|
|
1481
|
+
wrap: "truncate",
|
|
1482
|
+
children: [
|
|
1483
|
+
sel ? "▸ " : " ",
|
|
1484
|
+
row.label.padEnd(14),
|
|
1485
|
+
/* @__PURE__ */ jsx(Text, {
|
|
1486
|
+
bold: true,
|
|
1487
|
+
children: row.value
|
|
1488
|
+
})
|
|
1489
|
+
]
|
|
1490
|
+
}, row.key);
|
|
1491
|
+
}),
|
|
1492
|
+
/* @__PURE__ */ jsx(Text, { children: " " }),
|
|
1493
|
+
/* @__PURE__ */ jsx(Text, {
|
|
1494
|
+
color: "gray",
|
|
1495
|
+
wrap: "truncate",
|
|
1496
|
+
children: "←→ change · ↑↓ move · ⏎/p/esc done"
|
|
1497
|
+
})
|
|
1498
|
+
]
|
|
1499
|
+
});
|
|
1289
1500
|
const loraMode = s.mode === "overlay-loras";
|
|
1290
|
-
const
|
|
1291
|
-
const
|
|
1292
|
-
const
|
|
1293
|
-
const
|
|
1294
|
-
const
|
|
1501
|
+
const wantLatent = s.exec.running && pv.duringRun !== "last-output";
|
|
1502
|
+
const showLatent = !loraMode && wantLatent && (pv.latentAnsi != null || pv.latentBytes != null);
|
|
1503
|
+
const label = loraMode ? `lora ${s.loras.previewName ?? "lora"}` : showLatent ? pv.duringRun === "latent-small" ? "latent small" : "latent" : "output";
|
|
1504
|
+
const placeholder = loraMode ? s.loras.previewNote ?? "(pick a lora)" : pv.latentsMissing ? "(no latents from the server — launch comfy with --preview-method auto)" : "(no image yet)";
|
|
1505
|
+
const content = pv.useNative ? null : loraMode ? s.loras.previewAnsi : showLatent ? pv.latentAnsi ?? pv.outputAnsi : pv.outputAnsi;
|
|
1506
|
+
const reserveRect = pv.useNative && (pv.protocolImage != null || pv.protocolImageCorner != null);
|
|
1295
1507
|
return /* @__PURE__ */ jsxs(Box, {
|
|
1296
1508
|
borderStyle: "round",
|
|
1297
1509
|
paddingX: 1,
|
|
@@ -1303,7 +1515,16 @@ const PreviewPanel = observer((p) => {
|
|
|
1303
1515
|
children: /* @__PURE__ */ jsxs(Text, {
|
|
1304
1516
|
color: "gray",
|
|
1305
1517
|
wrap: "truncate",
|
|
1306
|
-
children: [
|
|
1518
|
+
children: [
|
|
1519
|
+
"(p)review · ",
|
|
1520
|
+
label,
|
|
1521
|
+
" · ",
|
|
1522
|
+
pv.renderer,
|
|
1523
|
+
pv.latentsMissing ? /* @__PURE__ */ jsx(Text, {
|
|
1524
|
+
color: "red",
|
|
1525
|
+
children: " · no latents!"
|
|
1526
|
+
}) : null
|
|
1527
|
+
]
|
|
1307
1528
|
})
|
|
1308
1529
|
}), reserveRect ? Array.from({ length: pv.height }, (_, ix) => /* @__PURE__ */ jsx(Text, { children: " " }, ix)) : content != null ? /* @__PURE__ */ jsx(Text, { children: content }) : /* @__PURE__ */ jsx(Text, {
|
|
1309
1530
|
color: "gray",
|
|
@@ -1359,6 +1580,32 @@ const PromptOverlay = observer((p) => {
|
|
|
1359
1580
|
});
|
|
1360
1581
|
});
|
|
1361
1582
|
//#endregion
|
|
1583
|
+
//#region src/cli/tui/components/LogsPanel.tsx
|
|
1584
|
+
const ERROR_RE = /error|exception|traceback|failed/i;
|
|
1585
|
+
/** last server console lines (LogsSt), below the vars panel */
|
|
1586
|
+
const LogsPanel = observer((p) => {
|
|
1587
|
+
const rows = p.st.logs.tail(p.st.termRows < 30 ? 4 : 8);
|
|
1588
|
+
if (rows.length === 0) return null;
|
|
1589
|
+
return /* @__PURE__ */ jsxs(Box, {
|
|
1590
|
+
borderStyle: "round",
|
|
1591
|
+
borderColor: "gray",
|
|
1592
|
+
paddingX: 1,
|
|
1593
|
+
flexDirection: "column",
|
|
1594
|
+
flexShrink: 0,
|
|
1595
|
+
children: [/* @__PURE__ */ jsx(Box, {
|
|
1596
|
+
marginTop: -1,
|
|
1597
|
+
children: /* @__PURE__ */ jsx(Text, {
|
|
1598
|
+
color: "gray",
|
|
1599
|
+
children: "comfy host logs"
|
|
1600
|
+
})
|
|
1601
|
+
}), rows.map((line, ix) => /* @__PURE__ */ jsx(Text, {
|
|
1602
|
+
color: ERROR_RE.test(line) ? "red" : "gray",
|
|
1603
|
+
wrap: "truncate-end",
|
|
1604
|
+
children: line
|
|
1605
|
+
}, ix))]
|
|
1606
|
+
});
|
|
1607
|
+
});
|
|
1608
|
+
//#endregion
|
|
1362
1609
|
//#region src/cli/tui/components/TextOverlay.tsx
|
|
1363
1610
|
/** modal multiline editor: real newlines, caret rendered per code point.
|
|
1364
1611
|
* The cursor's LOGICAL line is background-highlighted (word wrap hides line
|
|
@@ -1718,7 +1965,7 @@ const TuiApp = observer((p) => {
|
|
|
1718
1965
|
if (input === "s") return s.exec.randomizeSeedAndRun();
|
|
1719
1966
|
if (input === "d") return s.drafts.begin();
|
|
1720
1967
|
if (input === "h") return s.host.begin();
|
|
1721
|
-
if (input === "p") return s.
|
|
1968
|
+
if (input === "p") return s.preview.beginMenu();
|
|
1722
1969
|
if (input === "o") return s.exec.openLastOutput();
|
|
1723
1970
|
if (input === "q") {
|
|
1724
1971
|
s.onExit();
|
|
@@ -1738,6 +1985,24 @@ const TuiApp = observer((p) => {
|
|
|
1738
1985
|
}
|
|
1739
1986
|
return;
|
|
1740
1987
|
}
|
|
1988
|
+
if (s.mode === "preview") {
|
|
1989
|
+
const pv = s.preview;
|
|
1990
|
+
if (key.escape || key.return || input === "p" || input === "v") return pv.blurMenu();
|
|
1991
|
+
if (key.upArrow) return pv.menuMove(-1);
|
|
1992
|
+
if (key.downArrow) return pv.menuMove(1);
|
|
1993
|
+
if (key.leftArrow) return pv.menuCycle(-1);
|
|
1994
|
+
if (key.rightArrow || input === " ") return pv.menuCycle(1);
|
|
1995
|
+
if (input === "r") return void s.exec.run();
|
|
1996
|
+
if (input === "s") return s.exec.randomizeSeedAndRun();
|
|
1997
|
+
if (input === "d") return s.drafts.begin();
|
|
1998
|
+
if (input === "h") return s.host.begin();
|
|
1999
|
+
if (input === "o") return s.exec.openLastOutput();
|
|
2000
|
+
if (input === "q") {
|
|
2001
|
+
s.onExit();
|
|
2002
|
+
return app.exit();
|
|
2003
|
+
}
|
|
2004
|
+
return;
|
|
2005
|
+
}
|
|
1741
2006
|
if (s.mode === "overlay-drafts") {
|
|
1742
2007
|
const d = s.drafts;
|
|
1743
2008
|
if (key.escape) return s.editor.cancel();
|
|
@@ -1768,7 +2033,7 @@ const TuiApp = observer((p) => {
|
|
|
1768
2033
|
if (input === "t" || input === "w") return s.tree.focus();
|
|
1769
2034
|
if (input === "h") return s.host.begin();
|
|
1770
2035
|
if (input === "d") return s.drafts.begin();
|
|
1771
|
-
if (input === "p") return s.
|
|
2036
|
+
if (input === "p") return s.preview.beginMenu();
|
|
1772
2037
|
if (input === "o") return s.exec.openLastOutput();
|
|
1773
2038
|
if (input === "c") return void s.exec.copyWorkflowJson();
|
|
1774
2039
|
if (input === "C") return void s.exec.copyApiJson();
|
|
@@ -1808,10 +2073,11 @@ const TuiApp = observer((p) => {
|
|
|
1808
2073
|
})
|
|
1809
2074
|
]
|
|
1810
2075
|
}, o))
|
|
1811
|
-
})
|
|
2076
|
+
}),
|
|
2077
|
+
!s.mode.startsWith("overlay-") && !(s.mode === "edit" && s.editor.isCustom) && /* @__PURE__ */ jsx(LogsPanel, { st: s })
|
|
1812
2078
|
]
|
|
1813
2079
|
}),
|
|
1814
|
-
s.preview.show && /* @__PURE__ */ jsx(PreviewPanel, { st: s })
|
|
2080
|
+
(s.preview.show || s.preview.menuOpen) && /* @__PURE__ */ jsx(PreviewPanel, { st: s })
|
|
1815
2081
|
]
|
|
1816
2082
|
}),
|
|
1817
2083
|
/* @__PURE__ */ jsx(KeyBar, { st: s })
|
|
@@ -2323,7 +2589,7 @@ var ExecSt = class {
|
|
|
2323
2589
|
this.progress = null;
|
|
2324
2590
|
this.notice = null;
|
|
2325
2591
|
this.currentPromptId = null;
|
|
2326
|
-
this.st.preview.
|
|
2592
|
+
this.st.preview.clearLatent();
|
|
2327
2593
|
host.onLatentPreview = (p) => void this.st.preview.renderLatent(p.bytes);
|
|
2328
2594
|
}
|
|
2329
2595
|
});
|
|
@@ -2432,10 +2698,34 @@ var ExecSt = class {
|
|
|
2432
2698
|
};
|
|
2433
2699
|
//#endregion
|
|
2434
2700
|
//#region src/cli/tui/state/HostSt.ts
|
|
2701
|
+
const PROBE_EVERY_MS = 5e3;
|
|
2702
|
+
const PROBE_TIMEOUT_MS = 3e3;
|
|
2703
|
+
const SPIN_FRAMES = [
|
|
2704
|
+
"⠋",
|
|
2705
|
+
"⠙",
|
|
2706
|
+
"⠹",
|
|
2707
|
+
"⠸",
|
|
2708
|
+
"⠼",
|
|
2709
|
+
"⠴",
|
|
2710
|
+
"⠦",
|
|
2711
|
+
"⠧",
|
|
2712
|
+
"⠇",
|
|
2713
|
+
"⠏"
|
|
2714
|
+
];
|
|
2435
2715
|
/** host panel (`h`): stats about the connected host + maintenance actions */
|
|
2436
2716
|
var HostSt = class {
|
|
2437
2717
|
constructor(st) {
|
|
2438
2718
|
this.st = st;
|
|
2719
|
+
this.status = "unknown";
|
|
2720
|
+
this.statusVia = null;
|
|
2721
|
+
this.probing = false;
|
|
2722
|
+
this.retryInS = 0;
|
|
2723
|
+
this.spinFrame = 0;
|
|
2724
|
+
this.disposed = false;
|
|
2725
|
+
this.probeGen = 0;
|
|
2726
|
+
this.loopTimer = null;
|
|
2727
|
+
this.spinTimer = null;
|
|
2728
|
+
this.countdownTimer = null;
|
|
2439
2729
|
this.ix = 0;
|
|
2440
2730
|
this.running = null;
|
|
2441
2731
|
this.actions = [
|
|
@@ -2457,6 +2747,84 @@ var HostSt = class {
|
|
|
2457
2747
|
}
|
|
2458
2748
|
];
|
|
2459
2749
|
makeAutoObservable(this, { st: false });
|
|
2750
|
+
this.probeLoop();
|
|
2751
|
+
this.st.disposers.push(() => {
|
|
2752
|
+
this.disposed = true;
|
|
2753
|
+
if (this.loopTimer != null) clearTimeout(this.loopTimer);
|
|
2754
|
+
if (this.spinTimer != null) clearInterval(this.spinTimer);
|
|
2755
|
+
if (this.countdownTimer != null) clearInterval(this.countdownTimer);
|
|
2756
|
+
});
|
|
2757
|
+
this.st.disposers.push(reaction(() => this.st.wf, () => {
|
|
2758
|
+
runInAction(() => {
|
|
2759
|
+
this.status = "unknown";
|
|
2760
|
+
this.statusVia = null;
|
|
2761
|
+
});
|
|
2762
|
+
this.probeGen++;
|
|
2763
|
+
if (this.loopTimer != null) clearTimeout(this.loopTimer);
|
|
2764
|
+
if (this.countdownTimer != null) clearInterval(this.countdownTimer);
|
|
2765
|
+
this.probeLoop();
|
|
2766
|
+
}));
|
|
2767
|
+
}
|
|
2768
|
+
get spinner() {
|
|
2769
|
+
return SPIN_FRAMES[this.spinFrame % SPIN_FRAMES.length] ?? "⠋";
|
|
2770
|
+
}
|
|
2771
|
+
/** probe → schedule the next one (setTimeout chain: the countdown is exact) */
|
|
2772
|
+
async probeLoop() {
|
|
2773
|
+
const gen = this.probeGen;
|
|
2774
|
+
await this.probe();
|
|
2775
|
+
if (this.disposed || gen !== this.probeGen) return;
|
|
2776
|
+
const nextAt = Date.now() + PROBE_EVERY_MS;
|
|
2777
|
+
runInAction(() => {
|
|
2778
|
+
this.retryInS = Math.ceil(PROBE_EVERY_MS / 1e3);
|
|
2779
|
+
});
|
|
2780
|
+
if (this.countdownTimer != null) clearInterval(this.countdownTimer);
|
|
2781
|
+
this.countdownTimer = setInterval(() => {
|
|
2782
|
+
runInAction(() => {
|
|
2783
|
+
this.retryInS = Math.max(0, Math.ceil((nextAt - Date.now()) / 1e3));
|
|
2784
|
+
});
|
|
2785
|
+
}, 250);
|
|
2786
|
+
this.countdownTimer.unref?.();
|
|
2787
|
+
this.loopTimer = setTimeout(() => {
|
|
2788
|
+
if (this.countdownTimer != null) clearInterval(this.countdownTimer);
|
|
2789
|
+
this.probeLoop();
|
|
2790
|
+
}, PROBE_EVERY_MS);
|
|
2791
|
+
this.loopTimer.unref?.();
|
|
2792
|
+
}
|
|
2793
|
+
/** http is the ground truth: a half-open ws keeps isOpen=true forever, and
|
|
2794
|
+
* trusting it would re-create the exact silent-death this dot exists to expose */
|
|
2795
|
+
async probe() {
|
|
2796
|
+
const host = this.host;
|
|
2797
|
+
runInAction(() => {
|
|
2798
|
+
this.probing = true;
|
|
2799
|
+
});
|
|
2800
|
+
const spin = setInterval(() => {
|
|
2801
|
+
runInAction(() => {
|
|
2802
|
+
this.spinFrame++;
|
|
2803
|
+
});
|
|
2804
|
+
}, 120);
|
|
2805
|
+
spin.unref?.();
|
|
2806
|
+
this.spinTimer = spin;
|
|
2807
|
+
let ok = false;
|
|
2808
|
+
try {
|
|
2809
|
+
const res = await fetch(`${host.getServerHostHTTP()}/api/prompt`, { signal: AbortSignal.timeout(PROBE_TIMEOUT_MS) });
|
|
2810
|
+
res.body?.cancel();
|
|
2811
|
+
ok = res.ok;
|
|
2812
|
+
} catch {
|
|
2813
|
+
ok = false;
|
|
2814
|
+
} finally {
|
|
2815
|
+
clearInterval(spin);
|
|
2816
|
+
if (this.spinTimer === spin) {
|
|
2817
|
+
this.spinTimer = null;
|
|
2818
|
+
runInAction(() => {
|
|
2819
|
+
this.probing = false;
|
|
2820
|
+
});
|
|
2821
|
+
}
|
|
2822
|
+
}
|
|
2823
|
+
if (this.host !== host) return;
|
|
2824
|
+
runInAction(() => {
|
|
2825
|
+
this.status = ok ? "up" : "down";
|
|
2826
|
+
this.statusVia = ok ? host.isConnected ? "ws" : "http" : null;
|
|
2827
|
+
});
|
|
2460
2828
|
}
|
|
2461
2829
|
get host() {
|
|
2462
2830
|
return this.st.wf.host;
|
|
@@ -2464,6 +2832,10 @@ var HostSt = class {
|
|
|
2464
2832
|
get stats() {
|
|
2465
2833
|
const schema = this.host.schema;
|
|
2466
2834
|
return [
|
|
2835
|
+
{
|
|
2836
|
+
label: "status",
|
|
2837
|
+
value: this.status === "down" ? `down · ${this.probing ? `${this.spinner} probing…` : `retry in ${this.retryInS}s`}` : this.status + (this.statusVia != null ? ` (${this.statusVia})` : "")
|
|
2838
|
+
},
|
|
2467
2839
|
{
|
|
2468
2840
|
label: "node types",
|
|
2469
2841
|
value: String(schema.nodes.length)
|
|
@@ -2549,6 +2921,178 @@ var HostSt = class {
|
|
|
2549
2921
|
}
|
|
2550
2922
|
};
|
|
2551
2923
|
//#endregion
|
|
2924
|
+
//#region src/utils/ansi.ts
|
|
2925
|
+
const codes = {
|
|
2926
|
+
bold: [1, 22],
|
|
2927
|
+
underline: [4, 24],
|
|
2928
|
+
red: [31, 39],
|
|
2929
|
+
green: [32, 39],
|
|
2930
|
+
yellow: [33, 39],
|
|
2931
|
+
blue: [34, 39],
|
|
2932
|
+
greenBright: [92, 39]
|
|
2933
|
+
};
|
|
2934
|
+
function styler(open = "", close = "") {
|
|
2935
|
+
const fn = (s) => open + s + close;
|
|
2936
|
+
return new Proxy(fn, { get(_target, prop) {
|
|
2937
|
+
const c = codes[prop];
|
|
2938
|
+
if (c == null) throw new Error(`unknown ansi style: ${prop}`);
|
|
2939
|
+
return styler(`${open}\x1b[${c[0]}m`, `\x1b[${c[1]}m${close}`);
|
|
2940
|
+
} });
|
|
2941
|
+
}
|
|
2942
|
+
styler();
|
|
2943
|
+
const ANSI_RE = /\x1b\[[0-9;?]*[A-Za-z]|\x1b[A-Za-z]/g;
|
|
2944
|
+
function stripAnsi(s) {
|
|
2945
|
+
return s.replace(ANSI_RE, "");
|
|
2946
|
+
}
|
|
2947
|
+
//#endregion
|
|
2948
|
+
//#region src/utils/mojibake.ts
|
|
2949
|
+
const CP1252_REVERSE = {
|
|
2950
|
+
"€": 128,
|
|
2951
|
+
"‚": 130,
|
|
2952
|
+
ƒ: 131,
|
|
2953
|
+
"„": 132,
|
|
2954
|
+
"…": 133,
|
|
2955
|
+
"†": 134,
|
|
2956
|
+
"‡": 135,
|
|
2957
|
+
ˆ: 136,
|
|
2958
|
+
"‰": 137,
|
|
2959
|
+
Š: 138,
|
|
2960
|
+
"‹": 139,
|
|
2961
|
+
Œ: 140,
|
|
2962
|
+
Ž: 142,
|
|
2963
|
+
"‘": 145,
|
|
2964
|
+
"’": 146,
|
|
2965
|
+
"“": 147,
|
|
2966
|
+
"”": 148,
|
|
2967
|
+
"•": 149,
|
|
2968
|
+
"–": 150,
|
|
2969
|
+
"—": 151,
|
|
2970
|
+
"˜": 152,
|
|
2971
|
+
"™": 153,
|
|
2972
|
+
š: 154,
|
|
2973
|
+
"›": 155,
|
|
2974
|
+
œ: 156,
|
|
2975
|
+
ž: 158,
|
|
2976
|
+
Ÿ: 159
|
|
2977
|
+
};
|
|
2978
|
+
/**
|
|
2979
|
+
* repair UTF-8 that was decoded as cp1252 (a Windows server re-reading its own
|
|
2980
|
+
* output: `█` E2 96 88 arrives as `â–ˆ`). Reverses the cp1252 map back to
|
|
2981
|
+
* bytes and re-decodes as UTF-8; any unmappable char or invalid byte sequence
|
|
2982
|
+
* means the text was NOT mojibake — the original is returned untouched.
|
|
2983
|
+
*/
|
|
2984
|
+
function repairMojibake(s) {
|
|
2985
|
+
let suspicious = false;
|
|
2986
|
+
for (let i = 0; i < s.length; i++) if (s.charCodeAt(i) > 127) {
|
|
2987
|
+
suspicious = true;
|
|
2988
|
+
break;
|
|
2989
|
+
}
|
|
2990
|
+
if (!suspicious) return s;
|
|
2991
|
+
const bytes = new Uint8Array(s.length);
|
|
2992
|
+
for (let i = 0; i < s.length; i++) {
|
|
2993
|
+
const code = s.charCodeAt(i);
|
|
2994
|
+
if (code <= 255) {
|
|
2995
|
+
bytes[i] = code;
|
|
2996
|
+
continue;
|
|
2997
|
+
}
|
|
2998
|
+
const mapped = CP1252_REVERSE[s[i] ?? ""];
|
|
2999
|
+
if (mapped == null) return s;
|
|
3000
|
+
bytes[i] = mapped;
|
|
3001
|
+
}
|
|
3002
|
+
const decoded = Buffer.from(bytes).toString("utf8");
|
|
3003
|
+
return decoded.includes("�") ? s : decoded;
|
|
3004
|
+
}
|
|
3005
|
+
//#endregion
|
|
3006
|
+
//#region src/cli/tui/state/LogsSt.ts
|
|
3007
|
+
const MAX_LINES = 400;
|
|
3008
|
+
/** fold write chunks into p.lines (mutated), returns the new partial tail.
|
|
3009
|
+
* `\n` commits a line, `\r` resets the partial (tqdm redraws collapse to
|
|
3010
|
+
* their last state), ANSI stripped, blank lines dropped. */
|
|
3011
|
+
function assembleLogChunks(p) {
|
|
3012
|
+
let partial = p.partial;
|
|
3013
|
+
for (const entry of p.entries) for (const piece of stripAnsi(repairMojibake(entry.m)).split(/(\r\n|\n|\r)/)) if (piece === "\n" || piece === "\r\n") {
|
|
3014
|
+
if (partial.trim() !== "") p.lines.push(partial);
|
|
3015
|
+
partial = "";
|
|
3016
|
+
} else if (piece === "\r") partial = "";
|
|
3017
|
+
else if (piece !== "") partial += piece;
|
|
3018
|
+
return partial;
|
|
3019
|
+
}
|
|
3020
|
+
/** server console mirror: /internal/logs/raw backfill + ws 'logs' stream.
|
|
3021
|
+
* Entries are write CHUNKS, not lines — assembled here (`\n` commits,
|
|
3022
|
+
* `\r` resets the partial, so tqdm redraws collapse to their last state). */
|
|
3023
|
+
var LogsSt = class {
|
|
3024
|
+
constructor(st) {
|
|
3025
|
+
this.st = st;
|
|
3026
|
+
this.lines = [];
|
|
3027
|
+
this.partial = "";
|
|
3028
|
+
this.attached = null;
|
|
3029
|
+
makeAutoObservable(this, { st: false });
|
|
3030
|
+
this.attach(this.st.wf.host);
|
|
3031
|
+
this.st.disposers.push(() => {
|
|
3032
|
+
if (this.attached != null) {
|
|
3033
|
+
this.attached.onLogs = null;
|
|
3034
|
+
this.attached.onSession = null;
|
|
3035
|
+
}
|
|
3036
|
+
});
|
|
3037
|
+
}
|
|
3038
|
+
/** follow the CURRENT workflow's host (re-called on workflow switch) */
|
|
3039
|
+
attach(host) {
|
|
3040
|
+
if (this.attached === host) return;
|
|
3041
|
+
if (this.attached != null) {
|
|
3042
|
+
this.attached.onLogs = null;
|
|
3043
|
+
this.attached.onSession = null;
|
|
3044
|
+
if (this.attached.isConnected && this.attached.comfySessionId !== "temp") this.attached.subscribeLogs({
|
|
3045
|
+
enabled: false,
|
|
3046
|
+
clientId: this.attached.comfySessionId
|
|
3047
|
+
}).catch(() => {});
|
|
3048
|
+
}
|
|
3049
|
+
this.attached = host;
|
|
3050
|
+
this.lines = [];
|
|
3051
|
+
this.partial = "";
|
|
3052
|
+
host.onLogs = (p) => this.feed(p.entries);
|
|
3053
|
+
host.onSession = (sid) => void this.hydrate(host, sid);
|
|
3054
|
+
if (host.isConnected && host.comfySessionId !== "temp") this.hydrate(host, host.comfySessionId);
|
|
3055
|
+
}
|
|
3056
|
+
/** backfill BEFORE subscribe: entries emitted in the gap are lost, which is
|
|
3057
|
+
* the right trade — the reverse order would clobber streamed entries at the
|
|
3058
|
+
* reset, and the backfill re-covers the recent past anyway */
|
|
3059
|
+
async hydrate(host, sid) {
|
|
3060
|
+
try {
|
|
3061
|
+
const raw = await host.fetchRawLogs();
|
|
3062
|
+
if (this.attached !== host || host.comfySessionId !== sid) return;
|
|
3063
|
+
runInAction(() => {
|
|
3064
|
+
this.lines = [];
|
|
3065
|
+
this.partial = "";
|
|
3066
|
+
});
|
|
3067
|
+
this.feed(raw.entries);
|
|
3068
|
+
await host.subscribeLogs({
|
|
3069
|
+
enabled: true,
|
|
3070
|
+
clientId: sid
|
|
3071
|
+
});
|
|
3072
|
+
} catch (e) {
|
|
3073
|
+
if (this.attached !== host) return;
|
|
3074
|
+
this.feed([{
|
|
3075
|
+
t: "",
|
|
3076
|
+
m: `[comfy-ts] server log stream unavailable: ${extractErrorMessage(e)}\n`
|
|
3077
|
+
}]);
|
|
3078
|
+
}
|
|
3079
|
+
}
|
|
3080
|
+
feed(entries) {
|
|
3081
|
+
runInAction(() => {
|
|
3082
|
+
this.partial = assembleLogChunks({
|
|
3083
|
+
lines: this.lines,
|
|
3084
|
+
partial: this.partial,
|
|
3085
|
+
entries
|
|
3086
|
+
});
|
|
3087
|
+
if (this.lines.length > MAX_LINES) this.lines.splice(0, this.lines.length - MAX_LINES);
|
|
3088
|
+
});
|
|
3089
|
+
}
|
|
3090
|
+
/** last rows to render, live partial included */
|
|
3091
|
+
tail(n) {
|
|
3092
|
+
return (this.partial.trim() !== "" ? [...this.lines, this.partial] : this.lines).slice(-n);
|
|
3093
|
+
}
|
|
3094
|
+
};
|
|
3095
|
+
//#endregion
|
|
2552
3096
|
//#region src/host/loraManagerApi.ts
|
|
2553
3097
|
const lmLoraPage = type({
|
|
2554
3098
|
items: type({
|
|
@@ -2958,35 +3502,37 @@ var QueueSt = class {
|
|
|
2958
3502
|
};
|
|
2959
3503
|
//#endregion
|
|
2960
3504
|
//#region src/cli/tui/state/SettingsSt.ts
|
|
3505
|
+
/** read stored preview settings, migrating the legacy single `previewMode`
|
|
3506
|
+
* (native|ansi|off) into the three independent axes */
|
|
3507
|
+
function migratePreviewSettings(raw, defaults) {
|
|
3508
|
+
const out = { ...defaults };
|
|
3509
|
+
const legacy = raw.previewMode;
|
|
3510
|
+
if (legacy === "native") out.previewRenderer = "native";
|
|
3511
|
+
if (legacy === "ansi") out.previewRenderer = "pixel";
|
|
3512
|
+
if (legacy === "off") out.previewPanel = false;
|
|
3513
|
+
if (typeof raw.previewPanel === "boolean") out.previewPanel = raw.previewPanel;
|
|
3514
|
+
if (raw.previewRenderer === "native" || raw.previewRenderer === "pixel") out.previewRenderer = raw.previewRenderer;
|
|
3515
|
+
if (raw.previewDuringRun === "latent" || raw.previewDuringRun === "latent-small" || raw.previewDuringRun === "last-output") out.previewDuringRun = raw.previewDuringRun;
|
|
3516
|
+
return out;
|
|
3517
|
+
}
|
|
2961
3518
|
/** persisted TUI settings at `.comfy-ts/settings.json` (LOCAL state, gitignored) */
|
|
2962
3519
|
var SettingsSt = class {
|
|
2963
3520
|
constructor(st) {
|
|
2964
3521
|
this.st = st;
|
|
2965
|
-
this.
|
|
3522
|
+
this.previewPanel = true;
|
|
3523
|
+
this.previewRenderer = protocolCapable() ? "native" : "pixel";
|
|
3524
|
+
this.previewDuringRun = "latent";
|
|
2966
3525
|
this.lastDraft = {};
|
|
2967
3526
|
this.load();
|
|
2968
|
-
if (this.
|
|
3527
|
+
if (this.previewRenderer === "native" && !protocolCapable()) this.previewRenderer = "pixel";
|
|
2969
3528
|
makeAutoObservable(this, { st: false });
|
|
2970
3529
|
this.st.disposers.push(reaction(() => JSON.stringify({
|
|
2971
|
-
|
|
3530
|
+
previewPanel: this.previewPanel,
|
|
3531
|
+
previewRenderer: this.previewRenderer,
|
|
3532
|
+
previewDuringRun: this.previewDuringRun,
|
|
2972
3533
|
lastDraft: this.lastDraft
|
|
2973
3534
|
}), (json) => this.write(json), { delay: 300 }));
|
|
2974
3535
|
}
|
|
2975
|
-
setPreviewMode(mode) {
|
|
2976
|
-
this.previewMode = mode;
|
|
2977
|
-
this.st.preview.onModeChanged();
|
|
2978
|
-
}
|
|
2979
|
-
/** `p` cycles native → ansi → off (native skipped when the terminal can't do it) */
|
|
2980
|
-
cyclePreviewMode() {
|
|
2981
|
-
const order = protocolCapable() ? [
|
|
2982
|
-
"native",
|
|
2983
|
-
"ansi",
|
|
2984
|
-
"off"
|
|
2985
|
-
] : ["ansi", "off"];
|
|
2986
|
-
const next = order[(order.indexOf(this.previewMode) + 1) % order.length] ?? "off";
|
|
2987
|
-
this.setPreviewMode(next);
|
|
2988
|
-
this.st.exec.notice = `preview: ${next}`;
|
|
2989
|
-
}
|
|
2990
3536
|
rememberDraft(moduleKey, draft) {
|
|
2991
3537
|
this.lastDraft[moduleKey] = draft;
|
|
2992
3538
|
}
|
|
@@ -2997,7 +3543,14 @@ var SettingsSt = class {
|
|
|
2997
3543
|
const raw = JSON.parse(readFileSync(path, "utf8"));
|
|
2998
3544
|
if (raw == null || typeof raw !== "object") return;
|
|
2999
3545
|
const o = raw;
|
|
3000
|
-
|
|
3546
|
+
const preview = migratePreviewSettings(o, {
|
|
3547
|
+
previewPanel: this.previewPanel,
|
|
3548
|
+
previewRenderer: this.previewRenderer,
|
|
3549
|
+
previewDuringRun: this.previewDuringRun
|
|
3550
|
+
});
|
|
3551
|
+
this.previewPanel = preview.previewPanel;
|
|
3552
|
+
this.previewRenderer = preview.previewRenderer;
|
|
3553
|
+
this.previewDuringRun = preview.previewDuringRun;
|
|
3001
3554
|
if (o.lastDraft != null && typeof o.lastDraft === "object") this.lastDraft = { ...o.lastDraft };
|
|
3002
3555
|
} catch {}
|
|
3003
3556
|
}
|
|
@@ -3169,6 +3722,7 @@ var WorkflowsSt = class {
|
|
|
3169
3722
|
this.loadedHosts.add(wf.host);
|
|
3170
3723
|
this.st.wf = wf;
|
|
3171
3724
|
this.st.queue.attach(wf.host);
|
|
3725
|
+
this.st.logs.attach(wf.host);
|
|
3172
3726
|
this.currentPath = path;
|
|
3173
3727
|
this.st.selIx = 0;
|
|
3174
3728
|
this.st.mode = "nav";
|
|
@@ -3217,6 +3771,7 @@ var TuiSt = class {
|
|
|
3217
3771
|
preview: false,
|
|
3218
3772
|
host: false,
|
|
3219
3773
|
queue: false,
|
|
3774
|
+
logs: false,
|
|
3220
3775
|
settings: false
|
|
3221
3776
|
});
|
|
3222
3777
|
this.settings = new SettingsSt(this);
|
|
@@ -3230,6 +3785,7 @@ var TuiSt = class {
|
|
|
3230
3785
|
this.preview = new PreviewSt(this);
|
|
3231
3786
|
this.host = new HostSt(this);
|
|
3232
3787
|
this.queue = new QueueSt(this);
|
|
3788
|
+
this.logs = new LogsSt(this);
|
|
3233
3789
|
this.drafts.activateRemembered();
|
|
3234
3790
|
if (opts.currentFile != null) this.tree.expandedFiles.add(opts.currentFile);
|
|
3235
3791
|
const onResize = () => {
|
|
@@ -3330,11 +3886,11 @@ async function runTui(args) {
|
|
|
3330
3886
|
st.dispose();
|
|
3331
3887
|
} finally {
|
|
3332
3888
|
uninstallPainter();
|
|
3333
|
-
if (altScreen) process.stdout.write("\x1B[>4;0m\x1B[?1049l");
|
|
3889
|
+
if (altScreen) process.stdout.write("\x1B[0m\x1B[2J\x1B[H\x1B[>4;0m\x1B[?1049l");
|
|
3334
3890
|
}
|
|
3335
3891
|
return 0;
|
|
3336
3892
|
}
|
|
3337
3893
|
//#endregion
|
|
3338
3894
|
export { runTui };
|
|
3339
3895
|
|
|
3340
|
-
//# sourceMappingURL=run-tui-
|
|
3896
|
+
//# sourceMappingURL=run-tui-SDSJo1Qf.js.map
|