comfy-ts 2.12.0 → 2.14.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/dist/{LogsSt-U1H0mP1m.js → LogsSt-CUeo843w.js} +18 -4
- package/dist/LogsSt-CUeo843w.js.map +1 -0
- package/dist/cli.js +4 -4
- package/dist/index.cjs +123 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +96 -16
- package/dist/index.d.ts +96 -16
- package/dist/index.js +123 -12
- package/dist/index.js.map +1 -1
- package/dist/{run-serve-BeAznay5.js → run-serve-DUqcn0h3.js} +477 -63
- package/dist/run-serve-DUqcn0h3.js.map +1 -0
- package/dist/{run-tui-BTGjvnKk.js → run-tui-D-LaSqgB.js} +4 -4
- package/dist/{run-tui-BTGjvnKk.js.map → run-tui-D-LaSqgB.js.map} +1 -1
- package/dist/{schemaDrift-Cg39vs53.js → schemaDrift-E95iTF7E.js} +4 -1
- package/dist/{schemaDrift-Cg39vs53.js.map → schemaDrift-E95iTF7E.js.map} +1 -1
- package/dist/serve-web.js +378 -141
- package/dist/{state-C7REnHan.js → state-BytbdZ8s.js} +122 -14
- package/dist/state-BytbdZ8s.js.map +1 -0
- package/dist/web.d.ts +96 -16
- package/dist/web.js +123 -12
- package/dist/web.js.map +1 -1
- package/examples/comfy-cloud/sdk.d.ts +163 -163
- package/examples/rvion/10-anima-t2i.cflow.ts +48 -25
- package/examples/rvion/11-yue2-t2a.cflow.ts +105 -0
- package/examples/rvion/12-stable-audio-3-t2a.cflow.ts +78 -0
- package/examples/rvion/13-ace-step-15-xl-t2a.cflow.ts +153 -0
- package/examples/rvion/stableAudio3Prompts.ts +19 -0
- package/package.json +2 -2
- package/src/cli/serve/ServeApp.ts +224 -77
- package/src/cli/serve/byteRange.ts +48 -0
- package/src/cli/serve/resultHistory.ts +125 -0
- package/src/cli/serve/run-serve.ts +12 -3
- package/src/cli/serve/runError.ts +23 -0
- package/src/cli/serve/serveSettings.ts +17 -1
- package/src/cli/serve/web/api.ts +53 -2
- package/src/cli/serve/web/components/App.tsx +311 -160
- package/src/cli/serve/web/components/DraftTabs.tsx +167 -0
- package/src/cli/serve/web/components/Gallery.tsx +75 -25
- package/src/cli/serve/web/components/Icon.tsx +44 -0
- package/src/cli/serve/web/components/MemoryBudget.tsx +98 -0
- package/src/cli/serve/web/components/Omnibox.tsx +70 -20
- package/src/cli/serve/web/components/RunError.tsx +19 -0
- package/src/cli/serve/web/components/ShortcutsModal.tsx +54 -0
- package/src/cli/serve/web/components/SideMenu.tsx +428 -0
- package/src/cli/serve/web/components/TooltipLayer.tsx +3 -2
- package/src/cli/serve/web/components/VarsForm.tsx +141 -404
- package/src/cli/serve/web/components/controls/BasicControls.tsx +8 -1
- package/src/cli/serve/web/components/controls/LorasControl.tsx +30 -25
- package/src/cli/serve/web/promptEditor/promptExtensions.ts +9 -4
- package/src/cli/serve/web/state/EnhancerSt.ts +17 -2
- package/src/cli/serve/web/state/FormSt.ts +22 -2
- package/src/cli/serve/web/state/OmniboxSt.ts +3 -1
- package/src/cli/serve/web/state/RunSt.ts +61 -3
- package/src/cli/serve/web/state/WebSt.ts +198 -35
- package/src/cli/serve/web/state/draftNames.ts +16 -0
- package/src/cli/serve/web/state/draftTabs.ts +75 -0
- package/src/cli/serve/web/state/formRows.ts +9 -0
- package/src/cli/serve/web/state/generateButton.ts +1 -1
- package/src/cli/serve/web/state/keptResults.ts +26 -0
- package/src/cli/serve/web/state/lightbox.ts +17 -0
- package/src/cli/serve/web/state/omnibox.ts +82 -18
- package/src/cli/serve/web/state/shortcutCatalog.ts +100 -0
- package/src/cli/serve/web/state/shortcuts.ts +66 -7
- package/src/cli/serve/web/styles.ts +327 -93
- package/src/cli/serve/workflowTags.ts +42 -0
- package/src/cli/serve/workspaceLabels.ts +23 -0
- package/src/cli/tui/state/DraftsSt.ts +10 -6
- package/src/coreExports.ts +1 -0
- package/src/host/ComfyHost.ts +17 -2
- package/src/host/ResilientWebsocket.ts +54 -4
- package/src/runner/ComfyExecution.ts +60 -0
- package/src/runner/ComfyWorkflow.ts +4 -0
- package/src/runner/ComfyWsApi.ts +2 -0
- package/src/runner/MediaImage.ts +2 -2
- package/src/sdk-generator/ComfyUIObjectInfoTypes.ts +5 -5
- package/src/sdk-generator/comfyui-sdk-codegen.ts +1 -1
- package/src/utils/copyName.ts +12 -0
- package/src/vars/DefinedWorkflow.ts +7 -1
- package/dist/LogsSt-U1H0mP1m.js.map +0 -1
- package/dist/run-serve-BeAznay5.js.map +0 -1
- package/dist/state-C7REnHan.js.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { $ as stripAnsi, A as refreshLoraInfoCacheIfChanged, B as lmFilePath, C as getLoraTriggerWords, D as lorasMissingFromMirror, E as loraMirrorEntries, F as fetchLoraExampleImages, G as lmSha256, H as lmFolder, I as fetchLoraList, K as lmTags, L as fetchLoraPreviewBytes, M as writeLoraMirror, N as fetchLoraCivitai, P as fetchLoraDescription, Q as colorsAvailable, R as lmBaseModel, S as getLoraPreviewUrl, V as lmFileSize, W as lmNotes, X as loraPreviewMapFrom, Y as loraKey, Z as ansi, b as getLoraDisplayName, d as isPromptInput, dt as sha1HexOfString, et as extractErrorMessage, f as isLoraStrength, i as summarizeDrift, j as reloadLoraInfoCache, k as recordCivitaiMiss, l as isLoraLanes, lt as statelessRegex, m as getLoraKeyword, nt as bang, o as DEFAULT_IMAGE_EXTENSIONS, r as driftChanged, u as isLorasInput, v as buildLoraMirror, w as getLoraTriggers, x as getLoraInfo, y as getLoraAddedAt, z as lmCivitai } from "./schemaDrift-
|
|
2
|
-
import { a as draftsDirForFile, c as isDraftMetaKey, f as findDefinedWorkflow, i as draftKeyForFile, m as scanCflowFiles, n as assembleLogChunks, o as listDraftsForFile, s as ENHANCE_KEY } from "./LogsSt-
|
|
1
|
+
import { $ as stripAnsi, A as refreshLoraInfoCacheIfChanged, B as lmFilePath, C as getLoraTriggerWords, D as lorasMissingFromMirror, E as loraMirrorEntries, F as fetchLoraExampleImages, G as lmSha256, H as lmFolder, I as fetchLoraList, K as lmTags, L as fetchLoraPreviewBytes, M as writeLoraMirror, N as fetchLoraCivitai, P as fetchLoraDescription, Q as colorsAvailable, R as lmBaseModel, S as getLoraPreviewUrl, V as lmFileSize, W as lmNotes, X as loraPreviewMapFrom, Y as loraKey, Z as ansi, b as getLoraDisplayName, d as isPromptInput, dt as sha1HexOfString, et as extractErrorMessage, f as isLoraStrength, i as summarizeDrift, j as reloadLoraInfoCache, k as recordCivitaiMiss, l as isLoraLanes, lt as statelessRegex, m as getLoraKeyword, nt as bang, o as DEFAULT_IMAGE_EXTENSIONS, r as driftChanged, u as isLorasInput, v as buildLoraMirror, w as getLoraTriggers, x as getLoraInfo, y as getLoraAddedAt, z as lmCivitai } from "./schemaDrift-E95iTF7E.js";
|
|
2
|
+
import { a as draftsDirForFile, c as isDraftMetaKey, f as findDefinedWorkflow, i as draftKeyForFile, m as scanCflowFiles, n as assembleLogChunks, o as listDraftsForFile, s as ENHANCE_KEY } from "./LogsSt-CUeo843w.js";
|
|
3
3
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
4
4
|
import { closeSync, existsSync, mkdirSync, openSync, readFileSync, readSync, readdirSync, realpathSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
5
5
|
import { basename, dirname, extname, isAbsolute, join, resolve } from "pathe";
|
|
@@ -609,6 +609,63 @@ var TagSources = class {
|
|
|
609
609
|
//#region src/cli/serve/favicon.ts
|
|
610
610
|
const FAVICON_DATA_URI = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAACXBIWXMAAAPoAAAD6AG1e1JrAAAKUklEQVR42u1aaWxU1xW2DWEJZCENNgaK8iNRU5UAAYKBWW1ImwbaoqiuQkrUVlRdlDZSGpqAcTKrFyAoJRCRKmpRidKA98Sm0MQhRClOs7CIggiTtniZN4sZe8AeL/Puvef23LeMnwePQdWwhTnS9XvP8zzvft/5znfPfXJW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A4HrZ8LHY1TUXbiXcUtHHbeWRTpvj7D1XvsO7qspw5NhsH4wVYB3KuwYNmAZw5UvS3bh8brW4gvvRKL/zlQKfSiEqCcaR/HnWzfWfZMX6snq1evtMZCITmchEJjKRiUxkIhM3ZfwPK9dyLD4coj4AAAAASUVORK5CYII=";
|
|
611
611
|
//#endregion
|
|
612
|
+
//#region src/cli/serve/workflowTags.ts
|
|
613
|
+
/** display order: what the workflow makes first, then how it works, then free tags */
|
|
614
|
+
const MEDIA_BY_TYPE = {
|
|
615
|
+
IMAGE: "image",
|
|
616
|
+
AUDIO: "audio",
|
|
617
|
+
VIDEO: "video",
|
|
618
|
+
STRING: "text"
|
|
619
|
+
};
|
|
620
|
+
const MEDIA_ORDER = [
|
|
621
|
+
"image",
|
|
622
|
+
"audio",
|
|
623
|
+
"video",
|
|
624
|
+
"text"
|
|
625
|
+
];
|
|
626
|
+
function workflowTags(p) {
|
|
627
|
+
const byId = new Map(p.nodes.map((n) => [n.id, n]));
|
|
628
|
+
const media = /* @__PURE__ */ new Set();
|
|
629
|
+
for (const node of p.nodes) {
|
|
630
|
+
if (!node.outputNode) continue;
|
|
631
|
+
for (const [producerId, ix] of node.links) {
|
|
632
|
+
const type = byId.get(producerId)?.outputTypes[ix];
|
|
633
|
+
const tag = type == null ? void 0 : MEDIA_BY_TYPE[type];
|
|
634
|
+
if (tag != null) media.add(tag);
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
const out = MEDIA_ORDER.filter((t) => media.has(t));
|
|
638
|
+
if (p.nodes.some((n) => /textgenerate/i.test(n.classType))) out.push("llm");
|
|
639
|
+
if (p.varKinds.includes("image")) out.push("edit");
|
|
640
|
+
for (const tag of p.extra ?? []) {
|
|
641
|
+
const t = tag.trim().toLowerCase();
|
|
642
|
+
if (t !== "" && !out.includes(t)) out.push(t);
|
|
643
|
+
}
|
|
644
|
+
return out;
|
|
645
|
+
}
|
|
646
|
+
//#endregion
|
|
647
|
+
//#region src/cli/serve/workspaceLabels.ts
|
|
648
|
+
function tilde(path, home) {
|
|
649
|
+
if (home === "" || home === "/") return path;
|
|
650
|
+
if (path === home) return "~";
|
|
651
|
+
return path.startsWith(`${home}/`) ? `~${path.slice(home.length)}` : path;
|
|
652
|
+
}
|
|
653
|
+
function workspaceLabels(p) {
|
|
654
|
+
const ws = p.workspace.replace(/\/+$/, "");
|
|
655
|
+
const root = p.root.replace(/\/+$/, "");
|
|
656
|
+
const rootLabel = root === ws ? "." : root.startsWith(`${ws}/`) ? root.slice(ws.length + 1) : tilde(root, p.home);
|
|
657
|
+
return {
|
|
658
|
+
workspace: {
|
|
659
|
+
path: ws,
|
|
660
|
+
label: tilde(ws, p.home)
|
|
661
|
+
},
|
|
662
|
+
root: {
|
|
663
|
+
path: root,
|
|
664
|
+
label: rootLabel
|
|
665
|
+
}
|
|
666
|
+
};
|
|
667
|
+
}
|
|
668
|
+
//#endregion
|
|
612
669
|
//#region src/utils/stringMap.ts
|
|
613
670
|
function stringMap(raw) {
|
|
614
671
|
const out = {};
|
|
@@ -617,13 +674,112 @@ function stringMap(raw) {
|
|
|
617
674
|
}
|
|
618
675
|
return out;
|
|
619
676
|
}
|
|
677
|
+
var ResultHistory = class {
|
|
678
|
+
constructor(budgetBytes) {
|
|
679
|
+
this.budgetBytes = budgetBytes;
|
|
680
|
+
this.runs = [];
|
|
681
|
+
this.blobs = /* @__PURE__ */ new Map();
|
|
682
|
+
this.used = 0;
|
|
683
|
+
}
|
|
684
|
+
add(p) {
|
|
685
|
+
this.remove(p.record.promptId);
|
|
686
|
+
for (const b of p.blobs) {
|
|
687
|
+
this.blobs.set(b.key, {
|
|
688
|
+
bytes: b.bytes,
|
|
689
|
+
contentType: b.contentType
|
|
690
|
+
});
|
|
691
|
+
this.used += b.bytes.byteLength;
|
|
692
|
+
}
|
|
693
|
+
this.runs = [{
|
|
694
|
+
record: p.record,
|
|
695
|
+
imageKeys: p.imageKeys,
|
|
696
|
+
audioKeys: p.audioKeys
|
|
697
|
+
}, ...this.runs];
|
|
698
|
+
for (const dropped of this.runs.slice(50)) this.freeRun(dropped);
|
|
699
|
+
this.runs = this.runs.slice(0, 50);
|
|
700
|
+
this.evict();
|
|
701
|
+
}
|
|
702
|
+
blob(key) {
|
|
703
|
+
return this.blobs.get(key) ?? null;
|
|
704
|
+
}
|
|
705
|
+
/** an output whose bytes were evicted lists with url null: the panel says it is gone */
|
|
706
|
+
list() {
|
|
707
|
+
return this.runs.map((k) => ({
|
|
708
|
+
...k.record,
|
|
709
|
+
images: k.record.images.map((img, ix) => this.withLiveUrl(img, k.imageKeys[ix])),
|
|
710
|
+
audios: k.record.audios.map((a, ix) => this.withLiveUrl(a, k.audioKeys[ix]))
|
|
711
|
+
}));
|
|
712
|
+
}
|
|
713
|
+
remove(promptId) {
|
|
714
|
+
const hit = this.runs.find((k) => k.record.promptId === promptId);
|
|
715
|
+
if (hit == null) return;
|
|
716
|
+
this.freeRun(hit);
|
|
717
|
+
this.runs = this.runs.filter((k) => k !== hit);
|
|
718
|
+
}
|
|
719
|
+
clear() {
|
|
720
|
+
this.runs = [];
|
|
721
|
+
this.blobs.clear();
|
|
722
|
+
this.used = 0;
|
|
723
|
+
}
|
|
724
|
+
setBudget(bytes) {
|
|
725
|
+
this.budgetBytes = bytes;
|
|
726
|
+
this.evict();
|
|
727
|
+
}
|
|
728
|
+
usage() {
|
|
729
|
+
return {
|
|
730
|
+
usedBytes: this.used,
|
|
731
|
+
budgetBytes: this.budgetBytes,
|
|
732
|
+
outputs: this.blobs.size,
|
|
733
|
+
runs: this.runs.length
|
|
734
|
+
};
|
|
735
|
+
}
|
|
736
|
+
withLiveUrl(out, key) {
|
|
737
|
+
if (key == null || this.blobs.has(key)) return out;
|
|
738
|
+
return {
|
|
739
|
+
...out,
|
|
740
|
+
url: null
|
|
741
|
+
};
|
|
742
|
+
}
|
|
743
|
+
freeRun(k) {
|
|
744
|
+
for (const key of [...k.imageKeys, ...k.audioKeys]) {
|
|
745
|
+
if (key == null) continue;
|
|
746
|
+
const b = this.blobs.get(key);
|
|
747
|
+
if (b == null) continue;
|
|
748
|
+
this.used -= b.bytes.byteLength;
|
|
749
|
+
this.blobs.delete(key);
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
/** the NEWEST output always stays, even alone over budget: the run that just finished must
|
|
753
|
+
* not reply with a url that already 404s */
|
|
754
|
+
evict() {
|
|
755
|
+
while (this.used > this.budgetBytes && this.blobs.size > 1) {
|
|
756
|
+
const oldest = this.blobs.entries().next();
|
|
757
|
+
if (oldest.done === true) break;
|
|
758
|
+
this.used -= oldest.value[1].bytes.byteLength;
|
|
759
|
+
this.blobs.delete(oldest.value[0]);
|
|
760
|
+
}
|
|
761
|
+
this.runs = this.runs.filter((k) => {
|
|
762
|
+
const live = (keys) => keys.some((key) => key == null || this.blobs.has(key));
|
|
763
|
+
const hasText = k.record.texts.length > 0;
|
|
764
|
+
const hasNothing = k.record.images.length === 0 && k.record.audios.length === 0;
|
|
765
|
+
return hasText || hasNothing || live(k.imageKeys) || live(k.audioKeys);
|
|
766
|
+
});
|
|
767
|
+
}
|
|
768
|
+
};
|
|
620
769
|
//#endregion
|
|
621
770
|
//#region src/cli/serve/serveSettings.ts
|
|
622
771
|
const DEFAULT_SERVE_SETTINGS = {
|
|
623
772
|
saveToDisk: true,
|
|
624
773
|
hostOverride: {},
|
|
625
|
-
savePrefix: {}
|
|
774
|
+
savePrefix: {},
|
|
775
|
+
memoryBudgetMb: 100
|
|
626
776
|
};
|
|
777
|
+
/** null = not a budget. A hand-written file goes through the same gate as PUT /settings */
|
|
778
|
+
function validMemoryBudgetMb(raw) {
|
|
779
|
+
if (typeof raw !== "number" || !Number.isFinite(raw)) return null;
|
|
780
|
+
if (raw < 1 || raw > 1e5) return null;
|
|
781
|
+
return Math.round(raw);
|
|
782
|
+
}
|
|
627
783
|
/** null when no comfyts is registered yet: a ServeApp can be constructed before the global
|
|
628
784
|
* exists (tests do), and reading a setting must degrade to defaults, never throw */
|
|
629
785
|
function settingsPath() {
|
|
@@ -672,7 +828,8 @@ function readServeSettings() {
|
|
|
672
828
|
return {
|
|
673
829
|
saveToDisk: typeof o.saveToDisk === "boolean" ? o.saveToDisk : DEFAULT_SERVE_SETTINGS.saveToDisk,
|
|
674
830
|
hostOverride: stringMap(o.hostOverride),
|
|
675
|
-
savePrefix: cleanValues(stringMap(o.savePrefix), validSavePrefix)
|
|
831
|
+
savePrefix: cleanValues(stringMap(o.savePrefix), validSavePrefix),
|
|
832
|
+
memoryBudgetMb: validMemoryBudgetMb(o.memoryBudgetMb) ?? DEFAULT_SERVE_SETTINGS.memoryBudgetMb
|
|
676
833
|
};
|
|
677
834
|
}
|
|
678
835
|
function writeServeSettings(next) {
|
|
@@ -687,6 +844,48 @@ function writeServeSettings(next) {
|
|
|
687
844
|
}, null, 2));
|
|
688
845
|
}
|
|
689
846
|
//#endregion
|
|
847
|
+
//#region src/cli/serve/runError.ts
|
|
848
|
+
function describeRunError(error) {
|
|
849
|
+
if (error == null) return "execution failed";
|
|
850
|
+
if (typeof error === "string") return error;
|
|
851
|
+
if (error instanceof Error) return error.message;
|
|
852
|
+
if (typeof error === "object") {
|
|
853
|
+
const data = error.data;
|
|
854
|
+
if (typeof data === "object" && data !== null) {
|
|
855
|
+
const d = data;
|
|
856
|
+
if (typeof d.exception_message === "string") return `${typeof d.node_type === "string" ? `${d.node_type} (node ${String(d.node_id)}): ` : ""}${typeof d.exception_type === "string" && d.exception_type !== "" ? `${d.exception_type}: ` : ""}${d.exception_message.trim()}`;
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
try {
|
|
860
|
+
return JSON.stringify(error);
|
|
861
|
+
} catch {
|
|
862
|
+
return String(error);
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
//#endregion
|
|
866
|
+
//#region src/cli/serve/web/state/draftTabs.ts
|
|
867
|
+
/** where the serve process keeps them, under .comfy-ts/: draft names are private, so this file
|
|
868
|
+
* must stay gitignored (tests/serve-tabs.test.ts runs git check-ignore on it) */
|
|
869
|
+
const SERVE_TABS_FILE = "serve-tabs.json";
|
|
870
|
+
const same = (a, b) => a.module === b.module && a.draft === b.draft;
|
|
871
|
+
/** a stored list, shape-checked, keeping only drafts that still exist */
|
|
872
|
+
function readTabs(raw, modules) {
|
|
873
|
+
if (!Array.isArray(raw)) return [];
|
|
874
|
+
const out = [];
|
|
875
|
+
for (const x of raw) {
|
|
876
|
+
if (x == null || typeof x !== "object") continue;
|
|
877
|
+
const o = x;
|
|
878
|
+
if (typeof o.module !== "string" || typeof o.draft !== "string") continue;
|
|
879
|
+
const t = {
|
|
880
|
+
module: o.module,
|
|
881
|
+
draft: o.draft
|
|
882
|
+
};
|
|
883
|
+
if (!modules.some((m) => m.module === t.module && m.drafts.includes(t.draft))) continue;
|
|
884
|
+
if (!out.some((y) => same(y, t))) out.push(t);
|
|
885
|
+
}
|
|
886
|
+
return out;
|
|
887
|
+
}
|
|
888
|
+
//#endregion
|
|
690
889
|
//#region src/cli/serve/ServeApp.ts
|
|
691
890
|
/** what serve will read off the disk and upload. Wider than the picker default: ComfyUI's
|
|
692
891
|
* LoadImage takes bmp and tiff too, and a var declaring one of those must not be refused */
|
|
@@ -739,6 +938,7 @@ const INPUT_DOWNLOAD_TIMEOUT_MS = 6e4;
|
|
|
739
938
|
/** the danbooru list is ~3.5 MB; ten times that is still a tag list, beyond is a wrong url */
|
|
740
939
|
const TAG_LIST_CAP = 4e7;
|
|
741
940
|
const TAG_LIST_TIMEOUT_MS = 12e4;
|
|
941
|
+
const MB = 1024 * 1024;
|
|
742
942
|
/** read a reply STREAMING, aborting the moment it passes the cap. `arrayBuffer()` buffers the
|
|
743
943
|
* whole body first, so a chunked reply with no content-length could exhaust the process before
|
|
744
944
|
* anything checked its size, the cap then reported a number nobody survived to read. */
|
|
@@ -793,6 +993,12 @@ const CONTENT_TYPES = {
|
|
|
793
993
|
".gif": "image/gif",
|
|
794
994
|
".mp4": "video/mp4",
|
|
795
995
|
".webm": "video/webm",
|
|
996
|
+
".flac": "audio/flac",
|
|
997
|
+
".mp3": "audio/mpeg",
|
|
998
|
+
".opus": "audio/ogg",
|
|
999
|
+
".ogg": "audio/ogg",
|
|
1000
|
+
".wav": "audio/wav",
|
|
1001
|
+
".m4a": "audio/mp4",
|
|
796
1002
|
".json": "application/json",
|
|
797
1003
|
".txt": "text/plain"
|
|
798
1004
|
};
|
|
@@ -845,12 +1051,14 @@ const USAGE = [
|
|
|
845
1051
|
"PUT /prompt-enhancers/<name> with {\"text\"} — write one · DELETE /prompt-enhancers/<name> — remove it",
|
|
846
1052
|
"GET /llm-configs — the enhancer LLM configs (.comfy-ts/llm-configs/*.json)",
|
|
847
1053
|
"PUT /llm-configs/<name> with {provider, baseUrl, model, effort, thinkingOnly} · DELETE /llm-configs/<name>",
|
|
848
|
-
"GET /settings — { saveToDisk } · PUT /settings with {\"saveToDisk\"} — write outputs to disk, or keep them in memory",
|
|
1054
|
+
"GET /settings — { saveToDisk, memoryBudgetMb } · PUT /settings with {\"saveToDisk\"} — write outputs to disk, or keep them in memory; {\"memoryBudgetMb\"} caps what memory keeps",
|
|
849
1055
|
"GET /hosts — every host this process knows · PUT /hosts/<module> with {\"host\"} — run that workflow elsewhere",
|
|
850
1056
|
"POST /hosts/<hostId>/<interrupt|clear-queue|restart|refresh-loras|refresh-schema> — act on a ComfyUI host",
|
|
851
1057
|
"GET /hosts/<hostId>/ping — is that host answering right now (restart watch)",
|
|
852
1058
|
"GET /hosts/<hostId>/logs — the last lines of that host console",
|
|
853
1059
|
"GET /images/<promptId>/<ix> — an in-memory output (saving off), while the process lives",
|
|
1060
|
+
"GET /audio/<promptId>/<ix> — the same for an in-memory audio output",
|
|
1061
|
+
"GET /results — the last runs this process kept, for a reload · DELETE /results[/<promptId>] — forget them, freeing their memory",
|
|
854
1062
|
"GET /outputs/<path> — generated files"
|
|
855
1063
|
];
|
|
856
1064
|
/** content hash of the bundle, so the script URL CHANGES whenever the code does. no-store
|
|
@@ -885,14 +1093,19 @@ var ServeApp = class {
|
|
|
885
1093
|
set settings(next) {
|
|
886
1094
|
this.settingsCache = next;
|
|
887
1095
|
}
|
|
1096
|
+
get kept() {
|
|
1097
|
+
this.keptCache ??= new ResultHistory(this.settings.memoryBudgetMb * MB);
|
|
1098
|
+
return this.keptCache;
|
|
1099
|
+
}
|
|
888
1100
|
constructor(modules, opts = {}) {
|
|
889
1101
|
this.modules = modules;
|
|
890
1102
|
this.opts = opts;
|
|
891
1103
|
this.seedState = /* @__PURE__ */ new Map();
|
|
892
1104
|
this.chains = /* @__PURE__ */ new Map();
|
|
893
1105
|
this.settingsCache = null;
|
|
894
|
-
this.
|
|
895
|
-
this.
|
|
1106
|
+
this.keptCache = null;
|
|
1107
|
+
this.tagsByModule = /* @__PURE__ */ new Map();
|
|
1108
|
+
this.tabs = null;
|
|
896
1109
|
this.tagSources = new TagSources({
|
|
897
1110
|
cacheDir: () => join(comfyts.baseFolder, "cache", "tags"),
|
|
898
1111
|
fetchText: async (url) => {
|
|
@@ -934,7 +1147,7 @@ var ServeApp = class {
|
|
|
934
1147
|
headers: NO_STORE
|
|
935
1148
|
};
|
|
936
1149
|
}
|
|
937
|
-
if (segs.length === 0 || segs[0] === "drafts" && segs.length === 1) return this.replyIndex();
|
|
1150
|
+
if (segs.length === 0 || segs[0] === "drafts" && segs.length === 1) return await this.replyIndex();
|
|
938
1151
|
if (segs[0] === "web" && segs[1] === "app.js" && segs.length === 2) return await this.replyWebJs();
|
|
939
1152
|
if (segs[0] === "drafts" && segs.length === 3 && segs[1] != null && segs[2] != null) return this.replyDraft(segs[1], segs[2]);
|
|
940
1153
|
if (segs[0] === "run" && segs.length === 2 && segs[1] != null) return this.replyRunStatus(segs[1]);
|
|
@@ -946,11 +1159,17 @@ var ServeApp = class {
|
|
|
946
1159
|
if (segs[0] === "llm-configs" && segs.length === 1) return this.replyLlmConfigs();
|
|
947
1160
|
if (segs[0] === "tags" && segs.length === 3 && segs[1] != null && segs[2] != null) return await this.replyTags(segs[1], segs[2], req.url);
|
|
948
1161
|
if (segs[0] === "settings" && segs.length === 1) return this.replySettings();
|
|
1162
|
+
if (segs[0] === "tabs" && segs.length === 1) return this.replyTabs();
|
|
949
1163
|
if (segs[0] === "hosts" && segs.length === 1) return this.replyHosts();
|
|
950
1164
|
if (segs[0] === "hosts" && segs.length === 3 && segs[1] != null && segs[2] === "logs") return await this.replyHostLogs(segs[1]);
|
|
951
1165
|
if (segs[0] === "hosts" && segs.length === 3 && segs[1] != null && segs[2] === "ping") return await this.replyHostPing(segs[1]);
|
|
952
1166
|
if (segs[0] === "hosts" && segs.length === 3 && segs[1] != null && segs[2] === "drift") return await this.replyHostDrift(segs[1], req.url.includes("full=1"));
|
|
953
1167
|
if (segs[0] === "images" && segs.length === 3 && segs[1] != null && segs[2] != null) return this.replyMemoryImage(`${segs[1]}/${segs[2]}`);
|
|
1168
|
+
if (segs[0] === "audio" && segs.length === 3 && segs[1] != null && segs[2] != null) return this.replyMemoryImage(`audio/${segs[1]}/${segs[2]}`);
|
|
1169
|
+
if (segs[0] === "results" && segs.length === 1) return json(200, {
|
|
1170
|
+
runs: this.kept.list(),
|
|
1171
|
+
memory: this.kept.usage()
|
|
1172
|
+
});
|
|
954
1173
|
if (segs[0] === "outputs") return this.replyOutput(segs.slice(1));
|
|
955
1174
|
return json(404, {
|
|
956
1175
|
error: `no route: GET ${path}`,
|
|
@@ -967,6 +1186,12 @@ var ServeApp = class {
|
|
|
967
1186
|
if (req.method === "PUT" && segs[0] === "drafts" && segs.length === 3 && segs[1] != null && segs[2] != null) return await this.replySaveDraft(segs[1], segs[2], req);
|
|
968
1187
|
if (req.method === "DELETE" && segs[0] === "drafts" && segs.length === 3 && segs[1] != null && segs[2] != null) return await this.replyDeleteDraft(segs[1], segs[2]);
|
|
969
1188
|
if (req.method === "PUT" && segs[0] === "settings" && segs.length === 1) return this.replySaveSettings(req);
|
|
1189
|
+
if (req.method === "DELETE" && segs[0] === "results" && segs.length <= 2) {
|
|
1190
|
+
if (segs[1] == null) this.kept.clear();
|
|
1191
|
+
else this.kept.remove(segs[1]);
|
|
1192
|
+
return json(200, { memory: this.kept.usage() });
|
|
1193
|
+
}
|
|
1194
|
+
if (req.method === "PUT" && segs[0] === "tabs" && segs.length === 1) return this.replySaveTabs(req);
|
|
970
1195
|
if (req.method === "PUT" && segs[0] === "hosts" && segs.length === 2 && segs[1] != null) return this.replySetHost(segs[1], req);
|
|
971
1196
|
if (req.method === "POST" && segs[0] === "hosts" && segs.length === 3 && segs[1] != null && segs[2] != null) return await this.replyHostAction(segs[1], segs[2]);
|
|
972
1197
|
if (req.method === "POST" && segs[0] === "hosts" && segs.length === 4 && segs[1] != null && segs[2] === "lora-civitai" && segs[3] != null) return await this.replyLoraCivitaiFetch(segs[1], segs[3]);
|
|
@@ -1115,14 +1340,50 @@ var ServeApp = class {
|
|
|
1115
1340
|
drafts: this.draftsFor(mod),
|
|
1116
1341
|
routes: this.draftsFor(mod).map((d) => `POST /generate/${encodeURIComponent(mod.key)}/${encodeURIComponent(d)}`),
|
|
1117
1342
|
vars,
|
|
1118
|
-
previews: Object.keys(mod.dw.spec.previews ?? {})
|
|
1343
|
+
previews: Object.keys(mod.dw.spec.previews ?? {}),
|
|
1344
|
+
tags: this.tagsByModule.get(mod.key) ?? mod.dw.spec.tags ?? []
|
|
1119
1345
|
};
|
|
1120
1346
|
}
|
|
1121
|
-
|
|
1347
|
+
async tagsFor(mod) {
|
|
1348
|
+
const known = this.tagsByModule.get(mod.key);
|
|
1349
|
+
if (known != null) return known;
|
|
1350
|
+
const extra = mod.dw.spec.tags ?? [];
|
|
1351
|
+
const varKinds = mod.dw.entries().map(([, varDef]) => varDef.kind);
|
|
1352
|
+
let tags;
|
|
1353
|
+
try {
|
|
1354
|
+
tags = workflowTags({
|
|
1355
|
+
nodes: (await mod.dw.build({ dry: true })).nodes.map((n) => ({
|
|
1356
|
+
id: n.uid,
|
|
1357
|
+
classType: n.json.class_type,
|
|
1358
|
+
outputNode: n.$schema.raw.output_node,
|
|
1359
|
+
outputTypes: n.$schema.outputs.map((o) => o.typeName),
|
|
1360
|
+
links: Object.values(n.json.inputs).flatMap((v) => Array.isArray(v) && v.length === 2 && typeof v[1] === "number" ? [[String(v[0]), v[1]]] : [])
|
|
1361
|
+
})),
|
|
1362
|
+
varKinds,
|
|
1363
|
+
extra
|
|
1364
|
+
});
|
|
1365
|
+
} catch (e) {
|
|
1366
|
+
console.error(`[serve] 🔴 tags for ${mod.key}: dry build failed, spec tags only: ${extractErrorMessage(e)}`);
|
|
1367
|
+
tags = workflowTags({
|
|
1368
|
+
nodes: [],
|
|
1369
|
+
varKinds,
|
|
1370
|
+
extra
|
|
1371
|
+
});
|
|
1372
|
+
}
|
|
1373
|
+
this.tagsByModule.set(mod.key, tags);
|
|
1374
|
+
return tags;
|
|
1375
|
+
}
|
|
1376
|
+
async replyIndex() {
|
|
1377
|
+
for (const m of this.modules) await this.tagsFor(m);
|
|
1122
1378
|
return json(200, {
|
|
1123
1379
|
server: "comfy-ts serve",
|
|
1124
1380
|
usage: USAGE,
|
|
1125
1381
|
workflows: this.modules.map((m) => this.describeModule(m)),
|
|
1382
|
+
...this.opts.workspace == null ? {} : workspaceLabels({
|
|
1383
|
+
workspace: this.opts.workspace,
|
|
1384
|
+
root: this.opts.root ?? this.opts.workspace,
|
|
1385
|
+
home: process.env.HOME ?? ""
|
|
1386
|
+
}),
|
|
1126
1387
|
...this.opts.loadErrors != null && Object.keys(this.opts.loadErrors).length > 0 ? { loadErrors: this.opts.loadErrors } : {}
|
|
1127
1388
|
});
|
|
1128
1389
|
}
|
|
@@ -1561,21 +1822,16 @@ var ServeApp = class {
|
|
|
1561
1822
|
overrides: this.settings.hostOverride
|
|
1562
1823
|
});
|
|
1563
1824
|
}
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1825
|
+
memoryBlob(key, bytes, filename) {
|
|
1826
|
+
return {
|
|
1827
|
+
key,
|
|
1567
1828
|
bytes,
|
|
1568
|
-
contentType
|
|
1569
|
-
}
|
|
1570
|
-
while (this.memoryImages.size > this.MEMORY_IMAGE_CAP) {
|
|
1571
|
-
const oldest = this.memoryImages.keys().next();
|
|
1572
|
-
if (oldest.done === true) break;
|
|
1573
|
-
this.memoryImages.delete(oldest.value);
|
|
1574
|
-
}
|
|
1829
|
+
contentType: CONTENT_TYPES[extname(filename).toLowerCase()] ?? sniffImageContentType(bytes)
|
|
1830
|
+
};
|
|
1575
1831
|
}
|
|
1576
1832
|
replyMemoryImage(key) {
|
|
1577
|
-
const hit = this.
|
|
1578
|
-
if (hit == null) return json(404, { error: `no in-memory
|
|
1833
|
+
const hit = this.kept.blob(key);
|
|
1834
|
+
if (hit == null) return json(404, { error: `no in-memory output '${key}' — it was deleted, dropped past the ${this.settings.memoryBudgetMb} MB memory budget, or the server restarted. Turn saving on to keep outputs.` });
|
|
1579
1835
|
return {
|
|
1580
1836
|
status: 200,
|
|
1581
1837
|
contentType: hit.contentType,
|
|
@@ -1595,7 +1851,7 @@ var ServeApp = class {
|
|
|
1595
1851
|
} catch (e) {
|
|
1596
1852
|
return json(400, { error: `body is not valid json: ${extractErrorMessage(e)}` });
|
|
1597
1853
|
}
|
|
1598
|
-
if (parsed == null || typeof parsed !== "object" || Array.isArray(parsed)) return json(400, { error: "body must be { \"saveToDisk\"?: true | false, \"savePrefix\"?: { \"<module>\": \"path\" } }" });
|
|
1854
|
+
if (parsed == null || typeof parsed !== "object" || Array.isArray(parsed)) return json(400, { error: "body must be { \"saveToDisk\"?: true | false, \"savePrefix\"?: { \"<module>\": \"path\" }, \"memoryBudgetMb\"?: number }" });
|
|
1599
1855
|
const wanted = parsed;
|
|
1600
1856
|
let next = this.settings;
|
|
1601
1857
|
if (wanted.saveToDisk != null) {
|
|
@@ -1621,8 +1877,17 @@ var ServeApp = class {
|
|
|
1621
1877
|
savePrefix: prefixes
|
|
1622
1878
|
};
|
|
1623
1879
|
}
|
|
1880
|
+
if (wanted.memoryBudgetMb != null) {
|
|
1881
|
+
const mb = validMemoryBudgetMb(wanted.memoryBudgetMb);
|
|
1882
|
+
if (mb == null) return json(400, { error: "\"memoryBudgetMb\" must be a number of MB, 1 to 100000" });
|
|
1883
|
+
next = {
|
|
1884
|
+
...next,
|
|
1885
|
+
memoryBudgetMb: mb
|
|
1886
|
+
};
|
|
1887
|
+
}
|
|
1624
1888
|
const saveToDisk = next.saveToDisk;
|
|
1625
1889
|
this.settings = next;
|
|
1890
|
+
this.kept.setBudget(next.memoryBudgetMb * MB);
|
|
1626
1891
|
try {
|
|
1627
1892
|
writeServeSettings(this.settings);
|
|
1628
1893
|
} catch (e) {
|
|
@@ -1639,6 +1904,52 @@ var ServeApp = class {
|
|
|
1639
1904
|
effectivePrefix: Object.fromEntries(this.modules.map((m) => [m.key, this.savePrefixFor(m.key)]))
|
|
1640
1905
|
});
|
|
1641
1906
|
}
|
|
1907
|
+
tabsFile() {
|
|
1908
|
+
return join(comfyts.baseFolder, SERVE_TABS_FILE);
|
|
1909
|
+
}
|
|
1910
|
+
/** only drafts that still exist: a tab whose file was deleted elsewhere is dropped on read */
|
|
1911
|
+
liveTabs(raw) {
|
|
1912
|
+
return readTabs(raw, this.modules.map((m) => ({
|
|
1913
|
+
module: m.key,
|
|
1914
|
+
drafts: this.draftsFor(m)
|
|
1915
|
+
})));
|
|
1916
|
+
}
|
|
1917
|
+
replyTabs() {
|
|
1918
|
+
if (this.tabs == null) {
|
|
1919
|
+
const path = this.tabsFile();
|
|
1920
|
+
let raw = [];
|
|
1921
|
+
try {
|
|
1922
|
+
if (existsSync(path)) raw = JSON.parse(readFileSync(path, "utf8"));
|
|
1923
|
+
} catch (e) {
|
|
1924
|
+
console.error(`[serve] 🔴 open tabs unreadable (${path}), starting with none:`, e);
|
|
1925
|
+
}
|
|
1926
|
+
this.tabs = this.liveTabs(raw);
|
|
1927
|
+
}
|
|
1928
|
+
this.tabs = this.liveTabs(this.tabs);
|
|
1929
|
+
return json(200, { tabs: this.tabs });
|
|
1930
|
+
}
|
|
1931
|
+
replySaveTabs(req) {
|
|
1932
|
+
let parsed;
|
|
1933
|
+
try {
|
|
1934
|
+
parsed = JSON.parse(req.body ?? "");
|
|
1935
|
+
} catch (e) {
|
|
1936
|
+
return json(400, { error: `body is not valid json: ${extractErrorMessage(e)}` });
|
|
1937
|
+
}
|
|
1938
|
+
const raw = parsed != null && typeof parsed === "object" ? parsed.tabs : void 0;
|
|
1939
|
+
if (!Array.isArray(raw) || raw.length > 100) return json(400, { error: "expects { \"tabs\": [{ \"module\", \"draft\" }, …] }" });
|
|
1940
|
+
this.tabs = this.liveTabs(raw);
|
|
1941
|
+
try {
|
|
1942
|
+
mkdirSync(comfyts.baseFolder, { recursive: true });
|
|
1943
|
+
writeFileSync(this.tabsFile(), JSON.stringify(this.tabs, null, 2));
|
|
1944
|
+
} catch (e) {
|
|
1945
|
+
console.error(`[serve] 🔴 open tabs not saved to ${this.tabsFile()}:`, e);
|
|
1946
|
+
return json(200, {
|
|
1947
|
+
tabs: this.tabs,
|
|
1948
|
+
warning: `not saved: ${extractErrorMessage(e)}`
|
|
1949
|
+
});
|
|
1950
|
+
}
|
|
1951
|
+
return json(200, { tabs: this.tabs });
|
|
1952
|
+
}
|
|
1642
1953
|
async replyTags(modKey, varName, url) {
|
|
1643
1954
|
const mod = this.moduleByKey(modKey);
|
|
1644
1955
|
if (mod == null) return json(404, { error: `unknown workflow '${modKey}'` });
|
|
@@ -1914,26 +2225,73 @@ var ServeApp = class {
|
|
|
1914
2225
|
}
|
|
1915
2226
|
const durationMs = Date.now() - t0;
|
|
1916
2227
|
if (execution.status === "Failure") {
|
|
1917
|
-
|
|
2228
|
+
const error = describeRunError(execution.data.error);
|
|
2229
|
+
console.error(`[serve] 🔴 ${mod.key}/${draft} failed after ${durationMs}ms: ${error}`);
|
|
1918
2230
|
return json(500, {
|
|
1919
2231
|
ok: false,
|
|
1920
2232
|
module: mod.key,
|
|
1921
2233
|
draft,
|
|
1922
2234
|
promptId: execution.data.id,
|
|
1923
2235
|
durationMs,
|
|
1924
|
-
error
|
|
2236
|
+
error
|
|
1925
2237
|
});
|
|
1926
2238
|
}
|
|
1927
2239
|
const produced = [`${execution.images.length} image(s)`];
|
|
2240
|
+
const audios = execution.audios ?? [];
|
|
2241
|
+
if (audios.length > 0) produced.push(`${audios.length} audio(s)`);
|
|
1928
2242
|
if ((execution.texts ?? []).length > 0) produced.push(`${(execution.texts ?? []).length} text(s)`);
|
|
1929
2243
|
console.log(`[serve] 🟢 ${mod.key}/${draft} done in ${(durationMs / 1e3).toFixed(1)}s · ${produced.join(" · ")}`);
|
|
1930
|
-
const
|
|
1931
|
-
|
|
1932
|
-
if (img.absPath != null || img.buffer == null)
|
|
2244
|
+
const blobs = [];
|
|
2245
|
+
const imageKeys = execution.images.map((img, ix) => {
|
|
2246
|
+
if (img.absPath != null || img.buffer == null) return null;
|
|
1933
2247
|
const key = `${execution.data.id}/${ix}`;
|
|
1934
|
-
this.
|
|
1935
|
-
|
|
1936
|
-
}
|
|
2248
|
+
blobs.push(this.memoryBlob(key, img.buffer, img.filename));
|
|
2249
|
+
return key;
|
|
2250
|
+
});
|
|
2251
|
+
const audioKeys = audios.map((a, ix) => {
|
|
2252
|
+
if (a.absPath != null) return null;
|
|
2253
|
+
const key = `audio/${execution.data.id}/${ix}`;
|
|
2254
|
+
blobs.push(this.memoryBlob(key, a.bytes, a.filename));
|
|
2255
|
+
return key;
|
|
2256
|
+
});
|
|
2257
|
+
const memoryUrl = (route, key) => `/${route}/${key.split("/").slice(route === "audio" ? 1 : 0).map((seg) => encodeURIComponent(seg)).join("/")}`;
|
|
2258
|
+
const record = {
|
|
2259
|
+
ok: true,
|
|
2260
|
+
module: mod.key,
|
|
2261
|
+
draft,
|
|
2262
|
+
promptId: execution.data.id,
|
|
2263
|
+
durationMs,
|
|
2264
|
+
finishedAt: Date.now(),
|
|
2265
|
+
seeds,
|
|
2266
|
+
savedToDisk: this.settings.saveToDisk,
|
|
2267
|
+
texts: (execution.texts ?? []).map((t) => ({
|
|
2268
|
+
nodeKey: t.nodeKey,
|
|
2269
|
+
text: t.text
|
|
2270
|
+
})),
|
|
2271
|
+
images: execution.images.map((img, ix) => {
|
|
2272
|
+
const key = imageKeys[ix];
|
|
2273
|
+
return {
|
|
2274
|
+
filename: img.filename,
|
|
2275
|
+
url: img.absPath != null ? this.outputUrl(img.absPath) : key != null ? memoryUrl("images", key) : null,
|
|
2276
|
+
absPath: img.absPath
|
|
2277
|
+
};
|
|
2278
|
+
}),
|
|
2279
|
+
audios: audios.map((a, ix) => {
|
|
2280
|
+
const key = audioKeys[ix];
|
|
2281
|
+
return {
|
|
2282
|
+
filename: a.filename,
|
|
2283
|
+
mime: a.mime,
|
|
2284
|
+
url: a.absPath != null ? this.outputUrl(a.absPath) : key != null ? memoryUrl("audio", key) : null,
|
|
2285
|
+
absPath: a.absPath
|
|
2286
|
+
};
|
|
2287
|
+
})
|
|
2288
|
+
};
|
|
2289
|
+
this.kept.add({
|
|
2290
|
+
record,
|
|
2291
|
+
imageKeys,
|
|
2292
|
+
audioKeys,
|
|
2293
|
+
blobs
|
|
2294
|
+
});
|
|
1937
2295
|
const first = execution.images[0];
|
|
1938
2296
|
if (req.accept?.includes("image/") && first != null) {
|
|
1939
2297
|
if (first.absPath != null) return {
|
|
@@ -1941,31 +2299,14 @@ var ServeApp = class {
|
|
|
1941
2299
|
contentType: CONTENT_TYPES[extname(first.absPath).toLowerCase()] ?? "application/octet-stream",
|
|
1942
2300
|
body: new Uint8Array(readFileSync(first.absPath))
|
|
1943
2301
|
};
|
|
1944
|
-
const inMemory = this.
|
|
2302
|
+
const inMemory = this.kept.blob(imageKeys[0] ?? "");
|
|
1945
2303
|
if (inMemory != null) return {
|
|
1946
2304
|
status: 200,
|
|
1947
2305
|
contentType: inMemory.contentType,
|
|
1948
2306
|
body: inMemory.bytes
|
|
1949
2307
|
};
|
|
1950
2308
|
}
|
|
1951
|
-
return json(200,
|
|
1952
|
-
ok: true,
|
|
1953
|
-
module: mod.key,
|
|
1954
|
-
draft,
|
|
1955
|
-
promptId: execution.data.id,
|
|
1956
|
-
durationMs,
|
|
1957
|
-
seeds,
|
|
1958
|
-
savedToDisk: this.settings.saveToDisk,
|
|
1959
|
-
texts: (execution.texts ?? []).map((t) => ({
|
|
1960
|
-
nodeKey: t.nodeKey,
|
|
1961
|
-
text: t.text
|
|
1962
|
-
})),
|
|
1963
|
-
images: execution.images.map((img, ix) => ({
|
|
1964
|
-
filename: img.filename,
|
|
1965
|
-
url: img.absPath != null ? this.outputUrl(img.absPath) : memoryKeys.has(ix) ? `/images/${(memoryKeys.get(ix) ?? "").split("/").map((seg) => encodeURIComponent(seg)).join("/")}` : null,
|
|
1966
|
-
absPath: img.absPath
|
|
1967
|
-
}))
|
|
1968
|
-
});
|
|
2309
|
+
return json(200, record);
|
|
1969
2310
|
}
|
|
1970
2311
|
/** everything that touches the module's SHARED vars, under the module mutex */
|
|
1971
2312
|
async prepareAndStart(mod, draft, payload, seeds) {
|
|
@@ -2041,17 +2382,21 @@ var ServeApp = class {
|
|
|
2041
2382
|
const seedVar = varDef;
|
|
2042
2383
|
const stateKey = `${mod.key}/${draft}/${k}`;
|
|
2043
2384
|
const draftValue = draftSeedValues.get(k) ?? seedVar.value;
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2385
|
+
const prev = this.seedState.get(stateKey);
|
|
2386
|
+
const continues = !(k in payload) && (seedVar.mode === "+" || seedVar.mode === "-") && prev != null && (prev.draftBase === draftValue || prev.served.includes(draftValue));
|
|
2387
|
+
if (!(k in payload) && seedVar.mode === "?") seedVar.randomize();
|
|
2388
|
+
if (continues) {
|
|
2389
|
+
seedVar.set(prev.last + (seedVar.mode === "+" ? 1 : -1));
|
|
2390
|
+
const served = [...prev.served, seedVar.value].slice(-256);
|
|
2391
|
+
this.seedState.set(stateKey, {
|
|
2392
|
+
last: seedVar.value,
|
|
2393
|
+
draftBase: prev.draftBase,
|
|
2394
|
+
served
|
|
2395
|
+
});
|
|
2396
|
+
} else this.seedState.set(stateKey, {
|
|
2053
2397
|
last: seedVar.value,
|
|
2054
|
-
draftBase: draftValue
|
|
2398
|
+
draftBase: draftValue,
|
|
2399
|
+
served: [seedVar.value]
|
|
2055
2400
|
});
|
|
2056
2401
|
seeds[k] = seedVar.value;
|
|
2057
2402
|
}
|
|
@@ -2114,6 +2459,68 @@ var ServeApp = class {
|
|
|
2114
2459
|
}
|
|
2115
2460
|
};
|
|
2116
2461
|
//#endregion
|
|
2462
|
+
//#region src/cli/serve/byteRange.ts
|
|
2463
|
+
/** one range, the only kind media players send: `bytes=a-b`, `bytes=a-`, `bytes=-n` */
|
|
2464
|
+
function parseRange(header, size) {
|
|
2465
|
+
const m = /^bytes=(\d*)-(\d*)$/.exec(header.trim());
|
|
2466
|
+
if (m == null) return null;
|
|
2467
|
+
const a = m[1] ?? "";
|
|
2468
|
+
const b = m[2] ?? "";
|
|
2469
|
+
if (a === "" && b === "") return null;
|
|
2470
|
+
if (a === "") {
|
|
2471
|
+
const n = Number(b);
|
|
2472
|
+
if (n === 0) return "unsatisfiable";
|
|
2473
|
+
return {
|
|
2474
|
+
start: Math.max(0, size - n),
|
|
2475
|
+
end: size - 1
|
|
2476
|
+
};
|
|
2477
|
+
}
|
|
2478
|
+
const start = Number(a);
|
|
2479
|
+
const end = b === "" ? size - 1 : Math.min(Number(b), size - 1);
|
|
2480
|
+
if (start >= size || start > end) return "unsatisfiable";
|
|
2481
|
+
return {
|
|
2482
|
+
start,
|
|
2483
|
+
end
|
|
2484
|
+
};
|
|
2485
|
+
}
|
|
2486
|
+
/** a whole 200 binary reply gets its length and `accept-ranges`; a range request gets 206 with
|
|
2487
|
+
* those bytes, or 416 past the end. Text replies and errors pass through untouched */
|
|
2488
|
+
function withByteRange(reply, req) {
|
|
2489
|
+
if (req.method !== "GET" || reply.status !== 200 || typeof reply.body === "string") return reply;
|
|
2490
|
+
const size = reply.body.length;
|
|
2491
|
+
const base = {
|
|
2492
|
+
...reply.headers,
|
|
2493
|
+
"accept-ranges": "bytes"
|
|
2494
|
+
};
|
|
2495
|
+
const range = req.range == null ? null : parseRange(req.range, size);
|
|
2496
|
+
if (range == null) return {
|
|
2497
|
+
...reply,
|
|
2498
|
+
headers: {
|
|
2499
|
+
...base,
|
|
2500
|
+
"content-length": String(size)
|
|
2501
|
+
}
|
|
2502
|
+
};
|
|
2503
|
+
if (range === "unsatisfiable") return {
|
|
2504
|
+
status: 416,
|
|
2505
|
+
contentType: reply.contentType,
|
|
2506
|
+
body: /* @__PURE__ */ new Uint8Array(0),
|
|
2507
|
+
headers: {
|
|
2508
|
+
...base,
|
|
2509
|
+
"content-range": `bytes */${size}`
|
|
2510
|
+
}
|
|
2511
|
+
};
|
|
2512
|
+
return {
|
|
2513
|
+
status: 206,
|
|
2514
|
+
contentType: reply.contentType,
|
|
2515
|
+
body: reply.body.subarray(range.start, range.end + 1),
|
|
2516
|
+
headers: {
|
|
2517
|
+
...base,
|
|
2518
|
+
"content-range": `bytes ${range.start}-${range.end}/${size}`,
|
|
2519
|
+
"content-length": String(range.end - range.start + 1)
|
|
2520
|
+
}
|
|
2521
|
+
};
|
|
2522
|
+
}
|
|
2523
|
+
//#endregion
|
|
2117
2524
|
//#region src/cli/serve/startupPrint.ts
|
|
2118
2525
|
const RULE_WIDTH = 64;
|
|
2119
2526
|
/** 100.64.0.0/10 is the CGNAT range tailscale hands out — worth naming, it is the one
|
|
@@ -2347,7 +2754,12 @@ function makeRequestListener(app) {
|
|
|
2347
2754
|
url: req.url ?? "/",
|
|
2348
2755
|
accept: req.headers.accept,
|
|
2349
2756
|
body: Buffer.concat(chunks).toString("utf8")
|
|
2350
|
-
}).then((
|
|
2757
|
+
}).then((whole) => {
|
|
2758
|
+
const range = req.headers.range;
|
|
2759
|
+
const reply = withByteRange(whole, {
|
|
2760
|
+
method: req.method ?? "GET",
|
|
2761
|
+
range
|
|
2762
|
+
});
|
|
2351
2763
|
res.writeHead(reply.status, {
|
|
2352
2764
|
"content-type": reply.contentType,
|
|
2353
2765
|
...reply.headers,
|
|
@@ -2402,7 +2814,9 @@ async function runServe(args) {
|
|
|
2402
2814
|
}
|
|
2403
2815
|
const app = new ServeApp(modules, {
|
|
2404
2816
|
loadErrors,
|
|
2405
|
-
webJs: loadOrBuildWebJs
|
|
2817
|
+
webJs: loadOrBuildWebJs,
|
|
2818
|
+
workspace: typeof comfyts === "undefined" ? process.cwd() : comfyts.rootPath,
|
|
2819
|
+
root: statSync(target).isDirectory() ? target : dirname(target)
|
|
2406
2820
|
});
|
|
2407
2821
|
printStartup(app, parsed.bind, parsed.port);
|
|
2408
2822
|
const server = createServer(makeRequestListener(app));
|
|
@@ -2451,4 +2865,4 @@ function printStartup(app, bind, port) {
|
|
|
2451
2865
|
//#endregion
|
|
2452
2866
|
export { runServe };
|
|
2453
2867
|
|
|
2454
|
-
//# sourceMappingURL=run-serve-
|
|
2868
|
+
//# sourceMappingURL=run-serve-DUqcn0h3.js.map
|