comfy-ts 2.13.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/cli.js +3 -3
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/{run-serve-DlRBv_Nk.js → run-serve-DUqcn0h3.js} +211 -59
- package/dist/run-serve-DUqcn0h3.js.map +1 -0
- package/dist/{run-tui-B5uxm2_l.js → run-tui-D-LaSqgB.js} +2 -2
- package/dist/{run-tui-B5uxm2_l.js.map → run-tui-D-LaSqgB.js.map} +1 -1
- package/dist/serve-web.js +146 -71
- package/dist/{state-CUp2J1Zy.js → state-BytbdZ8s.js} +2 -2
- package/dist/{state-CUp2J1Zy.js.map → state-BytbdZ8s.js.map} +1 -1
- package/dist/web.js +1 -1
- package/package.json +1 -1
- package/src/cli/serve/ServeApp.ts +90 -82
- package/src/cli/serve/resultHistory.ts +125 -0
- package/src/cli/serve/runError.ts +23 -0
- package/src/cli/serve/serveSettings.ts +17 -1
- package/src/cli/serve/web/api.ts +29 -2
- package/src/cli/serve/web/components/App.tsx +6 -4
- package/src/cli/serve/web/components/Gallery.tsx +33 -8
- package/src/cli/serve/web/components/Icon.tsx +4 -0
- package/src/cli/serve/web/components/MemoryBudget.tsx +98 -0
- 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 +14 -0
- package/src/cli/serve/web/components/VarsForm.tsx +71 -53
- package/src/cli/serve/web/components/controls/BasicControls.tsx +8 -1
- package/src/cli/serve/web/components/controls/LorasControl.tsx +6 -3
- package/src/cli/serve/web/promptEditor/promptExtensions.ts +3 -1
- package/src/cli/serve/web/state/RunSt.ts +61 -3
- package/src/cli/serve/web/state/WebSt.ts +26 -2
- package/src/cli/serve/web/state/formRows.ts +9 -0
- 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/shortcutCatalog.ts +100 -0
- package/src/cli/serve/web/state/shortcuts.ts +10 -0
- package/src/cli/serve/web/styles.ts +98 -24
- package/dist/run-serve-DlRBv_Nk.js.map +0 -1
package/dist/cli.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { I as fetchLoraList, M as writeLoraMirror, O as readLoraMirror, U as lmModelName, q as lmTrainedWords, v as buildLoraMirror } from "./schemaDrift-E95iTF7E.js";
|
|
3
|
-
import { a as ComfySchema, r as readableStringify, t as ComfyTS } from "./state-
|
|
3
|
+
import { a as ComfySchema, r as readableStringify, t as ComfyTS } from "./state-BytbdZ8s.js";
|
|
4
4
|
import { spawnSync } from "node:child_process";
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
6
6
|
import { existsSync, mkdirSync, readFileSync, readdirSync, rmdirSync, writeFileSync } from "node:fs";
|
|
@@ -278,10 +278,10 @@ async function main() {
|
|
|
278
278
|
console.error(`[comfy-ts ${cmd}] bun not found (${res.error.message}) — continuing under node: the examples packaged in node_modules cannot load here, and your own .cflow.ts modules rely on node's type stripping`);
|
|
279
279
|
}
|
|
280
280
|
if (cmd === "serve") {
|
|
281
|
-
const { runServe } = await import("./run-serve-
|
|
281
|
+
const { runServe } = await import("./run-serve-DUqcn0h3.js");
|
|
282
282
|
return runServe(rest);
|
|
283
283
|
}
|
|
284
|
-
const { runTui } = await import("./run-tui-
|
|
284
|
+
const { runTui } = await import("./run-tui-D-LaSqgB.js");
|
|
285
285
|
return runTui(rest);
|
|
286
286
|
}
|
|
287
287
|
console.log(HELP);
|
package/dist/index.cjs
CHANGED
package/dist/index.js
CHANGED
|
@@ -674,13 +674,112 @@ function stringMap(raw) {
|
|
|
674
674
|
}
|
|
675
675
|
return out;
|
|
676
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
|
+
};
|
|
677
769
|
//#endregion
|
|
678
770
|
//#region src/cli/serve/serveSettings.ts
|
|
679
771
|
const DEFAULT_SERVE_SETTINGS = {
|
|
680
772
|
saveToDisk: true,
|
|
681
773
|
hostOverride: {},
|
|
682
|
-
savePrefix: {}
|
|
774
|
+
savePrefix: {},
|
|
775
|
+
memoryBudgetMb: 100
|
|
683
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
|
+
}
|
|
684
783
|
/** null when no comfyts is registered yet: a ServeApp can be constructed before the global
|
|
685
784
|
* exists (tests do), and reading a setting must degrade to defaults, never throw */
|
|
686
785
|
function settingsPath() {
|
|
@@ -729,7 +828,8 @@ function readServeSettings() {
|
|
|
729
828
|
return {
|
|
730
829
|
saveToDisk: typeof o.saveToDisk === "boolean" ? o.saveToDisk : DEFAULT_SERVE_SETTINGS.saveToDisk,
|
|
731
830
|
hostOverride: stringMap(o.hostOverride),
|
|
732
|
-
savePrefix: cleanValues(stringMap(o.savePrefix), validSavePrefix)
|
|
831
|
+
savePrefix: cleanValues(stringMap(o.savePrefix), validSavePrefix),
|
|
832
|
+
memoryBudgetMb: validMemoryBudgetMb(o.memoryBudgetMb) ?? DEFAULT_SERVE_SETTINGS.memoryBudgetMb
|
|
733
833
|
};
|
|
734
834
|
}
|
|
735
835
|
function writeServeSettings(next) {
|
|
@@ -744,6 +844,25 @@ function writeServeSettings(next) {
|
|
|
744
844
|
}, null, 2));
|
|
745
845
|
}
|
|
746
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
|
|
747
866
|
//#region src/cli/serve/web/state/draftTabs.ts
|
|
748
867
|
/** where the serve process keeps them, under .comfy-ts/: draft names are private, so this file
|
|
749
868
|
* must stay gitignored (tests/serve-tabs.test.ts runs git check-ignore on it) */
|
|
@@ -819,6 +938,7 @@ const INPUT_DOWNLOAD_TIMEOUT_MS = 6e4;
|
|
|
819
938
|
/** the danbooru list is ~3.5 MB; ten times that is still a tag list, beyond is a wrong url */
|
|
820
939
|
const TAG_LIST_CAP = 4e7;
|
|
821
940
|
const TAG_LIST_TIMEOUT_MS = 12e4;
|
|
941
|
+
const MB = 1024 * 1024;
|
|
822
942
|
/** read a reply STREAMING, aborting the moment it passes the cap. `arrayBuffer()` buffers the
|
|
823
943
|
* whole body first, so a chunked reply with no content-length could exhaust the process before
|
|
824
944
|
* anything checked its size, the cap then reported a number nobody survived to read. */
|
|
@@ -931,13 +1051,14 @@ const USAGE = [
|
|
|
931
1051
|
"PUT /prompt-enhancers/<name> with {\"text\"} — write one · DELETE /prompt-enhancers/<name> — remove it",
|
|
932
1052
|
"GET /llm-configs — the enhancer LLM configs (.comfy-ts/llm-configs/*.json)",
|
|
933
1053
|
"PUT /llm-configs/<name> with {provider, baseUrl, model, effort, thinkingOnly} · DELETE /llm-configs/<name>",
|
|
934
|
-
"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",
|
|
935
1055
|
"GET /hosts — every host this process knows · PUT /hosts/<module> with {\"host\"} — run that workflow elsewhere",
|
|
936
1056
|
"POST /hosts/<hostId>/<interrupt|clear-queue|restart|refresh-loras|refresh-schema> — act on a ComfyUI host",
|
|
937
1057
|
"GET /hosts/<hostId>/ping — is that host answering right now (restart watch)",
|
|
938
1058
|
"GET /hosts/<hostId>/logs — the last lines of that host console",
|
|
939
1059
|
"GET /images/<promptId>/<ix> — an in-memory output (saving off), while the process lives",
|
|
940
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",
|
|
941
1062
|
"GET /outputs/<path> — generated files"
|
|
942
1063
|
];
|
|
943
1064
|
/** content hash of the bundle, so the script URL CHANGES whenever the code does. no-store
|
|
@@ -972,15 +1093,18 @@ var ServeApp = class {
|
|
|
972
1093
|
set settings(next) {
|
|
973
1094
|
this.settingsCache = next;
|
|
974
1095
|
}
|
|
1096
|
+
get kept() {
|
|
1097
|
+
this.keptCache ??= new ResultHistory(this.settings.memoryBudgetMb * MB);
|
|
1098
|
+
return this.keptCache;
|
|
1099
|
+
}
|
|
975
1100
|
constructor(modules, opts = {}) {
|
|
976
1101
|
this.modules = modules;
|
|
977
1102
|
this.opts = opts;
|
|
978
1103
|
this.seedState = /* @__PURE__ */ new Map();
|
|
979
1104
|
this.chains = /* @__PURE__ */ new Map();
|
|
980
1105
|
this.settingsCache = null;
|
|
981
|
-
this.
|
|
1106
|
+
this.keptCache = null;
|
|
982
1107
|
this.tagsByModule = /* @__PURE__ */ new Map();
|
|
983
|
-
this.MEMORY_IMAGE_CAP = 60;
|
|
984
1108
|
this.tabs = null;
|
|
985
1109
|
this.tagSources = new TagSources({
|
|
986
1110
|
cacheDir: () => join(comfyts.baseFolder, "cache", "tags"),
|
|
@@ -1042,6 +1166,10 @@ var ServeApp = class {
|
|
|
1042
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"));
|
|
1043
1167
|
if (segs[0] === "images" && segs.length === 3 && segs[1] != null && segs[2] != null) return this.replyMemoryImage(`${segs[1]}/${segs[2]}`);
|
|
1044
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
|
+
});
|
|
1045
1173
|
if (segs[0] === "outputs") return this.replyOutput(segs.slice(1));
|
|
1046
1174
|
return json(404, {
|
|
1047
1175
|
error: `no route: GET ${path}`,
|
|
@@ -1058,6 +1186,11 @@ var ServeApp = class {
|
|
|
1058
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);
|
|
1059
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]);
|
|
1060
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
|
+
}
|
|
1061
1194
|
if (req.method === "PUT" && segs[0] === "tabs" && segs.length === 1) return this.replySaveTabs(req);
|
|
1062
1195
|
if (req.method === "PUT" && segs[0] === "hosts" && segs.length === 2 && segs[1] != null) return this.replySetHost(segs[1], req);
|
|
1063
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]);
|
|
@@ -1689,21 +1822,16 @@ var ServeApp = class {
|
|
|
1689
1822
|
overrides: this.settings.hostOverride
|
|
1690
1823
|
});
|
|
1691
1824
|
}
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1825
|
+
memoryBlob(key, bytes, filename) {
|
|
1826
|
+
return {
|
|
1827
|
+
key,
|
|
1695
1828
|
bytes,
|
|
1696
|
-
contentType
|
|
1697
|
-
}
|
|
1698
|
-
while (this.memoryImages.size > this.MEMORY_IMAGE_CAP) {
|
|
1699
|
-
const oldest = this.memoryImages.keys().next();
|
|
1700
|
-
if (oldest.done === true) break;
|
|
1701
|
-
this.memoryImages.delete(oldest.value);
|
|
1702
|
-
}
|
|
1829
|
+
contentType: CONTENT_TYPES[extname(filename).toLowerCase()] ?? sniffImageContentType(bytes)
|
|
1830
|
+
};
|
|
1703
1831
|
}
|
|
1704
1832
|
replyMemoryImage(key) {
|
|
1705
|
-
const hit = this.
|
|
1706
|
-
if (hit == null) return json(404, { error: `no in-memory output '${key}' — it
|
|
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.` });
|
|
1707
1835
|
return {
|
|
1708
1836
|
status: 200,
|
|
1709
1837
|
contentType: hit.contentType,
|
|
@@ -1723,7 +1851,7 @@ var ServeApp = class {
|
|
|
1723
1851
|
} catch (e) {
|
|
1724
1852
|
return json(400, { error: `body is not valid json: ${extractErrorMessage(e)}` });
|
|
1725
1853
|
}
|
|
1726
|
-
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 }" });
|
|
1727
1855
|
const wanted = parsed;
|
|
1728
1856
|
let next = this.settings;
|
|
1729
1857
|
if (wanted.saveToDisk != null) {
|
|
@@ -1749,8 +1877,17 @@ var ServeApp = class {
|
|
|
1749
1877
|
savePrefix: prefixes
|
|
1750
1878
|
};
|
|
1751
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
|
+
}
|
|
1752
1888
|
const saveToDisk = next.saveToDisk;
|
|
1753
1889
|
this.settings = next;
|
|
1890
|
+
this.kept.setBudget(next.memoryBudgetMb * MB);
|
|
1754
1891
|
try {
|
|
1755
1892
|
writeServeSettings(this.settings);
|
|
1756
1893
|
} catch (e) {
|
|
@@ -2088,14 +2225,15 @@ var ServeApp = class {
|
|
|
2088
2225
|
}
|
|
2089
2226
|
const durationMs = Date.now() - t0;
|
|
2090
2227
|
if (execution.status === "Failure") {
|
|
2091
|
-
|
|
2228
|
+
const error = describeRunError(execution.data.error);
|
|
2229
|
+
console.error(`[serve] 🔴 ${mod.key}/${draft} failed after ${durationMs}ms: ${error}`);
|
|
2092
2230
|
return json(500, {
|
|
2093
2231
|
ok: false,
|
|
2094
2232
|
module: mod.key,
|
|
2095
2233
|
draft,
|
|
2096
2234
|
promptId: execution.data.id,
|
|
2097
2235
|
durationMs,
|
|
2098
|
-
error
|
|
2236
|
+
error
|
|
2099
2237
|
});
|
|
2100
2238
|
}
|
|
2101
2239
|
const produced = [`${execution.images.length} image(s)`];
|
|
@@ -2103,20 +2241,57 @@ var ServeApp = class {
|
|
|
2103
2241
|
if (audios.length > 0) produced.push(`${audios.length} audio(s)`);
|
|
2104
2242
|
if ((execution.texts ?? []).length > 0) produced.push(`${(execution.texts ?? []).length} text(s)`);
|
|
2105
2243
|
console.log(`[serve] 🟢 ${mod.key}/${draft} done in ${(durationMs / 1e3).toFixed(1)}s · ${produced.join(" · ")}`);
|
|
2106
|
-
const
|
|
2107
|
-
|
|
2108
|
-
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;
|
|
2109
2247
|
const key = `${execution.data.id}/${ix}`;
|
|
2110
|
-
this.
|
|
2111
|
-
|
|
2112
|
-
}
|
|
2113
|
-
const audioKeys =
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
}
|
|
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
|
+
});
|
|
2120
2295
|
const first = execution.images[0];
|
|
2121
2296
|
if (req.accept?.includes("image/") && first != null) {
|
|
2122
2297
|
if (first.absPath != null) return {
|
|
@@ -2124,37 +2299,14 @@ var ServeApp = class {
|
|
|
2124
2299
|
contentType: CONTENT_TYPES[extname(first.absPath).toLowerCase()] ?? "application/octet-stream",
|
|
2125
2300
|
body: new Uint8Array(readFileSync(first.absPath))
|
|
2126
2301
|
};
|
|
2127
|
-
const inMemory = this.
|
|
2302
|
+
const inMemory = this.kept.blob(imageKeys[0] ?? "");
|
|
2128
2303
|
if (inMemory != null) return {
|
|
2129
2304
|
status: 200,
|
|
2130
2305
|
contentType: inMemory.contentType,
|
|
2131
2306
|
body: inMemory.bytes
|
|
2132
2307
|
};
|
|
2133
2308
|
}
|
|
2134
|
-
return json(200,
|
|
2135
|
-
ok: true,
|
|
2136
|
-
module: mod.key,
|
|
2137
|
-
draft,
|
|
2138
|
-
promptId: execution.data.id,
|
|
2139
|
-
durationMs,
|
|
2140
|
-
seeds,
|
|
2141
|
-
savedToDisk: this.settings.saveToDisk,
|
|
2142
|
-
texts: (execution.texts ?? []).map((t) => ({
|
|
2143
|
-
nodeKey: t.nodeKey,
|
|
2144
|
-
text: t.text
|
|
2145
|
-
})),
|
|
2146
|
-
images: execution.images.map((img, ix) => ({
|
|
2147
|
-
filename: img.filename,
|
|
2148
|
-
url: img.absPath != null ? this.outputUrl(img.absPath) : memoryKeys.has(ix) ? `/images/${(memoryKeys.get(ix) ?? "").split("/").map((seg) => encodeURIComponent(seg)).join("/")}` : null,
|
|
2149
|
-
absPath: img.absPath
|
|
2150
|
-
})),
|
|
2151
|
-
audios: audios.map((a, ix) => ({
|
|
2152
|
-
filename: a.filename,
|
|
2153
|
-
mime: a.mime,
|
|
2154
|
-
url: a.absPath != null ? this.outputUrl(a.absPath) : audioKeys.has(ix) ? `/audio/${(audioKeys.get(ix) ?? "").split("/").map((seg) => encodeURIComponent(seg)).join("/")}` : null,
|
|
2155
|
-
absPath: a.absPath
|
|
2156
|
-
}))
|
|
2157
|
-
});
|
|
2309
|
+
return json(200, record);
|
|
2158
2310
|
}
|
|
2159
2311
|
/** everything that touches the module's SHARED vars, under the module mutex */
|
|
2160
2312
|
async prepareAndStart(mod, draft, payload, seeds) {
|
|
@@ -2713,4 +2865,4 @@ function printStartup(app, bind, port) {
|
|
|
2713
2865
|
//#endregion
|
|
2714
2866
|
export { runServe };
|
|
2715
2867
|
|
|
2716
|
-
//# sourceMappingURL=run-serve-
|
|
2868
|
+
//# sourceMappingURL=run-serve-DUqcn0h3.js.map
|