comfy-ts 2.21.0 → 2.23.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/{ServeApp-ByMobrWW.js → ServeApp-DolRCMHj.js} +183 -14
- package/dist/ServeApp-DolRCMHj.js.map +1 -0
- package/dist/cli.js +5 -5
- package/dist/{exampleAssets-B5sMqNia.js → exampleAssets-Duneoq6r.js} +331 -42
- package/dist/exampleAssets-Duneoq6r.js.map +1 -0
- package/dist/{findDefinedWorkflow-BNZgYIww.js → findDefinedWorkflow-DjoJA8y7.js} +2 -2
- package/dist/{findDefinedWorkflow-BNZgYIww.js.map → findDefinedWorkflow-DjoJA8y7.js.map} +1 -1
- package/dist/index.cjs +381 -34
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +201 -24
- package/dist/index.d.ts +201 -24
- package/dist/index.js +380 -35
- package/dist/index.js.map +1 -1
- package/dist/{run-run-CuBSygku.js → run-run-Cr0L9lCK.js} +5 -5
- package/dist/{run-run-CuBSygku.js.map → run-run-Cr0L9lCK.js.map} +1 -1
- package/dist/{run-serve-COk_G0Qz.js → run-serve---qA7o_m.js} +4 -4
- package/dist/{run-serve-COk_G0Qz.js.map → run-serve---qA7o_m.js.map} +1 -1
- package/dist/{run-tui-CB6i_x2y.js → run-tui-DxXiWo5J.js} +4 -4
- package/dist/{run-tui-CB6i_x2y.js.map → run-tui-DxXiWo5J.js.map} +1 -1
- package/dist/{schemaDrift-CHDVYlaj.js → schemaDrift-BTxdABHi.js} +36 -2
- package/dist/schemaDrift-BTxdABHi.js.map +1 -0
- package/dist/serve-web.js +207 -47
- package/dist/web.d.ts +201 -24
- package/dist/web.js +380 -35
- package/dist/web.js.map +1 -1
- package/examples/README.md +2 -0
- package/examples/comfy-cloud/sdk.d.ts +102 -1
- package/examples/depth-explorer/models.ts +722 -0
- package/examples/depth-explorer/serve.ts +140 -0
- package/examples/depth-explorer/thumbs/bae.webp +0 -0
- package/examples/depth-explorer/thumbs/da3-mono-large.webp +0 -0
- package/examples/depth-explorer/thumbs/dav1-vitl.webp +0 -0
- package/examples/depth-explorer/thumbs/dav2-vitl.webp +0 -0
- package/examples/depth-explorer/thumbs/dsine.webp +0 -0
- package/examples/depth-explorer/thumbs/iid-albedo.webp +0 -0
- package/examples/depth-explorer/thumbs/iid-metalness.webp +0 -0
- package/examples/depth-explorer/thumbs/iid-roughness.webp +0 -0
- package/examples/depth-explorer/thumbs/iid-shading.webp +0 -0
- package/examples/depth-explorer/thumbs/iid-specular.webp +0 -0
- package/examples/depth-explorer/thumbs/leres.webp +0 -0
- package/examples/depth-explorer/thumbs/lotus-depth.webp +0 -0
- package/examples/depth-explorer/thumbs/marigold2-albedo.webp +0 -0
- package/examples/depth-explorer/thumbs/marigold2-depth.webp +0 -0
- package/examples/depth-explorer/thumbs/marigold2-normal.webp +0 -0
- package/examples/depth-explorer/thumbs/metric3d-depth.webp +0 -0
- package/examples/depth-explorer/thumbs/metric3d-normal.webp +0 -0
- package/examples/depth-explorer/thumbs/midas-normal.webp +0 -0
- package/examples/depth-explorer/thumbs/midas.webp +0 -0
- package/examples/depth-explorer/thumbs/moge2-depth.webp +0 -0
- package/examples/depth-explorer/thumbs/moge2-normal.webp +0 -0
- package/examples/depth-explorer/thumbs/zoe-da.webp +0 -0
- package/examples/depth-explorer/thumbs/zoe.webp +0 -0
- package/examples/depth-explorer/web/App.tsx +457 -0
- package/examples/depth-explorer/web/gl.ts +202 -0
- package/examples/depth-explorer/web/index.html +14 -0
- package/examples/depth-explorer/web/main.tsx +19 -0
- package/examples/depth-explorer/web/pixels.ts +86 -0
- package/examples/depth-explorer/web/state.ts +329 -0
- package/examples/depth-explorer/web/styles.css +366 -0
- package/examples/depth-explorer/web/tsconfig.json +16 -0
- package/examples/rvion/17-relight.cflow.ts +110 -0
- package/examples/rvion/18-world.cflow.ts +101 -0
- package/examples/world-explorer/serve.ts +171 -0
- package/examples/world-explorer/web/index.html +14 -0
- package/examples/world-explorer/web/main.tsx +200 -0
- package/examples/world-explorer/web/state.ts +212 -0
- package/examples/world-explorer/web/styles.css +131 -0
- package/examples/world-explorer/web/thumb.ts +21 -0
- package/examples/world-explorer/web/tsconfig.json +11 -0
- package/examples/world-explorer/world-state.ts +40 -0
- package/package.json +6 -7
- package/src/cli/serve/ServeApp.ts +106 -6
- package/src/cli/serve/describeVar.ts +12 -1
- package/src/cli/serve/resultHistory.ts +28 -5
- package/src/cli/serve/thumbs.ts +77 -0
- package/src/cli/serve/web/api.ts +9 -1
- package/src/cli/serve/web/components/Gallery.tsx +26 -1
- package/src/cli/serve/web/components/controls/BasicControls.tsx +14 -17
- package/src/cli/serve/web/components/controls/MediaControl.tsx +62 -9
- package/src/cli/serve/web/components/controls/RichSelect.tsx +262 -0
- package/src/cli/serve/web/state/RunSt.poll.test.ts +4 -1
- package/src/cli/serve/web/state/choiceButtons.ts +26 -2
- package/src/cli/serve/web/styles.ts +42 -0
- package/src/cli/serve/web/widgets/OutputWidgets.tsx +19 -0
- package/src/cli/serve/web/widgets/RelightSt.ts +113 -0
- package/src/cli/serve/web/widgets/RelightWidget.tsx +305 -0
- package/src/cli/serve/web/widgets/relightGl.ts +305 -0
- package/src/cli/serve/web/widgets/widgetStyles.ts +19 -0
- package/src/coreExports.ts +10 -0
- package/src/graph/ComfyNode.ts +12 -2
- package/src/host/ComfyHost.ts +153 -2
- package/src/host/ResilientWebsocket.ts +10 -0
- package/src/manager/script-update-manager.bun.ts +0 -7
- package/src/runner/ComfyExecution.ts +165 -20
- package/src/runner/ComfyWsApi.ts +2 -0
- package/src/runner/historyReplay.ts +53 -0
- package/src/runner/outputs3d.ts +18 -0
- package/src/sdk-generator/comfyui-sdk-codegen.ts +7 -2
- package/src/vars/ComfyVars.ts +32 -2
- package/src/vars/DefinedWorkflow.ts +4 -0
- package/src/vars/outputWidgets.ts +47 -0
- package/dist/ServeApp-ByMobrWW.js.map +0 -1
- package/dist/exampleAssets-B5sMqNia.js.map +0 -1
- package/dist/schemaDrift-CHDVYlaj.js.map +0 -1
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { $ as
|
|
2
|
-
import { d as isDraftMetaKey, l as assembleLogChunks, o as draftsDirForFile, s as listDraftsForFile, u as ENHANCE_KEY } from "./findDefinedWorkflow-
|
|
1
|
+
import { $ as MODEL_3D_MIMES, A as reloadLoraInfoCache, B as lmFileSize, C as getLoraTriggers, E as lorasMissingFromMirror, F as fetchLoraList, G as lmTags, I as fetchLoraPreviewBytes, J as loraKey, L as lmBaseModel, M as fetchLoraCivitai, N as fetchLoraDescription, O as recordCivitaiMiss, P as fetchLoraExampleImages, R as lmCivitai, S as getLoraTriggerWords, T as loraMirrorEntries, U as lmNotes, V as lmFolder, W as lmSha256, X as ansi, Y as loraPreviewMapFrom, _ as buildLoraMirror, _t as sha1HexOfString, b as getLoraInfo, c as isLoraLanes, d as isLoraStrength, gt as statelessRegex, i as summarizeDrift, j as writeLoraMirror, k as refreshLoraInfoCacheIfChanged, l as isLorasInput, lt as bang, nt as MEDIA_KINDS, p as getLoraKeyword, r as driftChanged, st as importSharp, tt as DEFAULT_MEDIA_EXTENSIONS, u as isPromptInput, v as getLoraAddedAt, vt as extractErrorMessage, x as getLoraPreviewUrl, y as getLoraDisplayName, z as lmFilePath } from "./schemaDrift-BTxdABHi.js";
|
|
2
|
+
import { d as isDraftMetaKey, l as assembleLogChunks, o as draftsDirForFile, s as listDraftsForFile, u as ENHANCE_KEY } from "./findDefinedWorkflow-DjoJA8y7.js";
|
|
3
3
|
import { homedir } from "node:os";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
import { closeSync, existsSync, mkdirSync, openSync, readFileSync, readSync, readdirSync, realpathSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
6
6
|
import { basename, dirname, extname, isAbsolute, join, resolve } from "pathe";
|
|
7
7
|
import { nanoid } from "nanoid";
|
|
8
|
+
import { createHash } from "node:crypto";
|
|
8
9
|
//#region src/cli/serve/describeVar.ts
|
|
9
10
|
/** an empty list is absent from the json: every var without presets would otherwise carry `[]` */
|
|
10
11
|
function presetsOrUndefined(presets) {
|
|
@@ -110,10 +111,12 @@ function describeVar(varDef) {
|
|
|
110
111
|
case "audio":
|
|
111
112
|
case "video": {
|
|
112
113
|
const v = varDef;
|
|
114
|
+
const presets = v.presets;
|
|
113
115
|
return {
|
|
114
116
|
...base,
|
|
115
117
|
payload: "local file path or http(s) url",
|
|
116
|
-
extensions: v.extensions
|
|
118
|
+
extensions: v.extensions,
|
|
119
|
+
...presets.length > 0 ? { mediaPresets: presets } : {}
|
|
117
120
|
};
|
|
118
121
|
}
|
|
119
122
|
default: {
|
|
@@ -141,6 +144,69 @@ function truncate(s, n) {
|
|
|
141
144
|
return s.length <= n ? s : s.slice(0, n - 1) + "…";
|
|
142
145
|
}
|
|
143
146
|
//#endregion
|
|
147
|
+
//#region src/cli/serve/thumbs.ts
|
|
148
|
+
const isHttpUrl = (s) => /^https?:\/\//i.test(s);
|
|
149
|
+
/** the url the page loads for a local image's preview */
|
|
150
|
+
function thumbUrl(abs, width = 160) {
|
|
151
|
+
return `/thumb?src=${encodeURIComponent(abs)}&w=${width}`;
|
|
152
|
+
}
|
|
153
|
+
/** Bun's own image pipeline when the server runs on Bun, sharp only under Node (the cli runs on
|
|
154
|
+
* both). Both read the EXIF orientation */
|
|
155
|
+
async function webpThumb(path, width) {
|
|
156
|
+
if (typeof Bun !== "undefined") return new Bun.Image(path).resize(width, width, {
|
|
157
|
+
fit: "inside",
|
|
158
|
+
withoutEnlargement: true
|
|
159
|
+
}).webp({ quality: 78 }).bytes();
|
|
160
|
+
const sharp = await importSharp("a thumbnail");
|
|
161
|
+
return new Uint8Array(await sharp(path).rotate().resize({
|
|
162
|
+
width,
|
|
163
|
+
height: width,
|
|
164
|
+
fit: "inside",
|
|
165
|
+
withoutEnlargement: true
|
|
166
|
+
}).webp({ quality: 78 }).toBuffer());
|
|
167
|
+
}
|
|
168
|
+
const MAX_WIDTH = 640;
|
|
169
|
+
const MAX_CACHED = 400;
|
|
170
|
+
var ThumbStore = class {
|
|
171
|
+
constructor() {
|
|
172
|
+
this.allowed = /* @__PURE__ */ new Set();
|
|
173
|
+
this.roots = /* @__PURE__ */ new Set();
|
|
174
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
175
|
+
}
|
|
176
|
+
/** one file a served module declared */
|
|
177
|
+
allow(abs) {
|
|
178
|
+
this.allowed.add(resolve(abs));
|
|
179
|
+
}
|
|
180
|
+
/** every image under this folder */
|
|
181
|
+
allowRoot(dir) {
|
|
182
|
+
this.roots.add(resolve(dir));
|
|
183
|
+
}
|
|
184
|
+
isAllowed(abs) {
|
|
185
|
+
const p = resolve(abs);
|
|
186
|
+
if (this.allowed.has(p)) return true;
|
|
187
|
+
for (const root of this.roots) if (p.startsWith(`${root}/`)) return true;
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
/** a webp at most `width` wide, or why not: 'forbidden' (not declared, not under a root),
|
|
191
|
+
* 'missing' (not on this machine) */
|
|
192
|
+
async render(abs, width) {
|
|
193
|
+
if (!this.isAllowed(abs)) return "forbidden";
|
|
194
|
+
const p = resolve(abs);
|
|
195
|
+
if (!existsSync(p)) return "missing";
|
|
196
|
+
const w = Math.max(16, Math.min(MAX_WIDTH, Math.round(width)));
|
|
197
|
+
const key = `${p}|${statSync(p).mtimeMs}|${w}`;
|
|
198
|
+
const hit = this.cache.get(key);
|
|
199
|
+
if (hit != null) return hit;
|
|
200
|
+
const bytes = await webpThumb(p, w);
|
|
201
|
+
if (this.cache.size >= MAX_CACHED) {
|
|
202
|
+
const oldest = this.cache.keys().next().value;
|
|
203
|
+
if (oldest != null) this.cache.delete(oldest);
|
|
204
|
+
}
|
|
205
|
+
this.cache.set(key, bytes);
|
|
206
|
+
return bytes;
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
//#endregion
|
|
144
210
|
//#region src/cli/serve/applyVarPayload.ts
|
|
145
211
|
function isFiniteNumber(x) {
|
|
146
212
|
return typeof x === "number" && Number.isFinite(x);
|
|
@@ -697,7 +763,8 @@ var ResultHistory = class {
|
|
|
697
763
|
record: p.record,
|
|
698
764
|
imageKeys: p.imageKeys,
|
|
699
765
|
audioKeys: p.audioKeys,
|
|
700
|
-
videoKeys: p.videoKeys ?? []
|
|
766
|
+
videoKeys: p.videoKeys ?? [],
|
|
767
|
+
model3dKeys: p.model3dKeys ?? []
|
|
701
768
|
};
|
|
702
769
|
this.runs = [kept, ...this.runs];
|
|
703
770
|
for (const dropped of this.runs.slice(50)) this.freeRun(dropped);
|
|
@@ -713,7 +780,8 @@ var ResultHistory = class {
|
|
|
713
780
|
...k.record,
|
|
714
781
|
images: k.record.images.map((img, ix) => this.withLiveUrl(img, k.imageKeys[ix])),
|
|
715
782
|
audios: k.record.audios.map((a, ix) => this.withLiveUrl(a, k.audioKeys[ix])),
|
|
716
|
-
videos: (k.record.videos ?? []).map((a, ix) => this.withLiveUrl(a, k.videoKeys[ix]))
|
|
783
|
+
videos: (k.record.videos ?? []).map((a, ix) => this.withLiveUrl(a, k.videoKeys[ix])),
|
|
784
|
+
models3d: (k.record.models3d ?? []).map((a, ix) => this.withLiveUrl(a, k.model3dKeys[ix]))
|
|
717
785
|
}));
|
|
718
786
|
}
|
|
719
787
|
remove(promptId) {
|
|
@@ -750,7 +818,8 @@ var ResultHistory = class {
|
|
|
750
818
|
for (const key of [
|
|
751
819
|
...k.imageKeys,
|
|
752
820
|
...k.audioKeys,
|
|
753
|
-
...k.videoKeys
|
|
821
|
+
...k.videoKeys,
|
|
822
|
+
...k.model3dKeys
|
|
754
823
|
]) {
|
|
755
824
|
if (key == null) continue;
|
|
756
825
|
const b = this.blobs.get(key);
|
|
@@ -771,8 +840,8 @@ var ResultHistory = class {
|
|
|
771
840
|
this.runs = this.runs.filter((k) => {
|
|
772
841
|
const live = (keys) => keys.some((key) => key == null || this.blobs.has(key));
|
|
773
842
|
const hasText = k.record.texts.length > 0;
|
|
774
|
-
const hasNothing = k.record.images.length === 0 && k.record.audios.length === 0 && (k.record.videos ?? []).length === 0;
|
|
775
|
-
return hasText || hasNothing || live(k.imageKeys) || live(k.audioKeys) || live(k.videoKeys);
|
|
843
|
+
const hasNothing = k.record.images.length === 0 && k.record.audios.length === 0 && (k.record.videos ?? []).length === 0 && (k.record.models3d ?? []).length === 0;
|
|
844
|
+
return hasText || hasNothing || live(k.imageKeys) || live(k.audioKeys) || live(k.videoKeys) || live(k.model3dKeys);
|
|
776
845
|
});
|
|
777
846
|
}
|
|
778
847
|
};
|
|
@@ -1023,7 +1092,8 @@ const CONTENT_TYPES = {
|
|
|
1023
1092
|
".wav": "audio/wav",
|
|
1024
1093
|
".m4a": "audio/mp4",
|
|
1025
1094
|
".json": "application/json",
|
|
1026
|
-
".txt": "text/plain"
|
|
1095
|
+
".txt": "text/plain",
|
|
1096
|
+
...Object.fromEntries(Object.entries(MODEL_3D_MIMES).map(([ext, mime]) => [`.${ext}`, mime]))
|
|
1027
1097
|
};
|
|
1028
1098
|
/** magic-byte sniff for the preview proxy — fetchLoraPreviewBytes already guarantees an image */
|
|
1029
1099
|
function sniffImageContentType(bytes) {
|
|
@@ -1089,7 +1159,7 @@ const USAGE = [
|
|
|
1089
1159
|
"DELETE /drafts/<module>/<draft> — delete that draft file",
|
|
1090
1160
|
"GET /run/<module> — live run status · /run/<module>/preview — latent preview bytes",
|
|
1091
1161
|
"POST /upload with {\"name\",\"dataBase64\"} — store a browser file for an image, audio or video var",
|
|
1092
|
-
"GET /images|audio|video/<promptId>/<ix> — an output kept in memory (saving off)",
|
|
1162
|
+
"GET /images|audio|video|model3d/<promptId>/<ix> — an output kept in memory (saving off)",
|
|
1093
1163
|
"GET /tags/<module>/<var>?q=<text>&limit=<n> — tag completion from the list a prompt var declares (`tags`)",
|
|
1094
1164
|
"GET /hosts/<hostId>/drift[?full=1] — what changed on the host since the schema was loaded (model files; node types with full=1)",
|
|
1095
1165
|
"GET /lora-info/<hostId>/<lora> — display name + trigger words (local mirror)",
|
|
@@ -1154,6 +1224,7 @@ var ServeApp = class {
|
|
|
1154
1224
|
this.settingsCache = null;
|
|
1155
1225
|
this.keptCache = null;
|
|
1156
1226
|
this.tagsByModule = /* @__PURE__ */ new Map();
|
|
1227
|
+
this.thumbs = new ThumbStore();
|
|
1157
1228
|
this.tabs = null;
|
|
1158
1229
|
this.tagSources = new TagSources({
|
|
1159
1230
|
cacheDir: () => join(comfyts.baseFolder, "cache", "tags"),
|
|
@@ -1206,6 +1277,7 @@ var ServeApp = class {
|
|
|
1206
1277
|
if (segs[0] === "llm-configs" && segs.length === 1) return this.replyLlmConfigs();
|
|
1207
1278
|
if (segs[0] === "tags" && segs.length === 3 && segs[1] != null && segs[2] != null) return await this.replyTags(segs[1], segs[2], req.url);
|
|
1208
1279
|
if (segs[0] === "settings" && segs.length === 1) return this.replySettings();
|
|
1280
|
+
if (segs[0] === "thumb" && segs.length === 1) return await this.replyThumb(req.url);
|
|
1209
1281
|
if (segs[0] === "tabs" && segs.length === 1) return this.replyTabs();
|
|
1210
1282
|
if (segs[0] === "hosts" && segs.length === 1) return this.replyHosts();
|
|
1211
1283
|
if (segs[0] === "hosts" && segs.length === 3 && segs[1] != null && segs[2] === "logs") return await this.replyHostLogs(segs[1]);
|
|
@@ -1214,6 +1286,7 @@ var ServeApp = class {
|
|
|
1214
1286
|
if (segs[0] === "images" && segs.length === 3 && segs[1] != null && segs[2] != null) return this.replyMemoryImage(`${segs[1]}/${segs[2]}`);
|
|
1215
1287
|
if (segs[0] === "audio" && segs.length === 3 && segs[1] != null && segs[2] != null) return this.replyMemoryImage(`audio/${segs[1]}/${segs[2]}`);
|
|
1216
1288
|
if (segs[0] === "video" && segs.length === 3 && segs[1] != null && segs[2] != null) return this.replyMemoryImage(`video/${segs[1]}/${segs[2]}`);
|
|
1289
|
+
if (segs[0] === "model3d" && segs.length === 3 && segs[1] != null && segs[2] != null) return this.replyMemoryImage(`model3d/${segs[1]}/${segs[2]}`);
|
|
1217
1290
|
if (segs[0] === "results" && segs.length === 1) return json(200, {
|
|
1218
1291
|
runs: this.kept.list(),
|
|
1219
1292
|
memory: this.kept.usage()
|
|
@@ -1326,12 +1399,79 @@ var ServeApp = class {
|
|
|
1326
1399
|
error: "use POST /generate/<module>/<draft> or /generate/<draft>"
|
|
1327
1400
|
};
|
|
1328
1401
|
}
|
|
1402
|
+
/** the pictures of a descriptor made concrete for the page: a local thumb or preset becomes a
|
|
1403
|
+
* /thumb url the store allows, a local preset not on this machine is flagged missing, a url
|
|
1404
|
+
* stays as it is. Relative paths are relative to the workflow file */
|
|
1405
|
+
decorateLooks(desc, mod) {
|
|
1406
|
+
const dir = dirname(mod.file);
|
|
1407
|
+
this.thumbs.allowRoot(dir);
|
|
1408
|
+
this.thumbs.allowRoot(this.outputRoot);
|
|
1409
|
+
const local = (p) => isAbsolute(p) ? p : resolve(dir, p);
|
|
1410
|
+
const options = desc.ui?.options;
|
|
1411
|
+
if (desc.ui != null && options != null) {
|
|
1412
|
+
const looks = {};
|
|
1413
|
+
for (const [value, look] of Object.entries(options)) {
|
|
1414
|
+
if (look.thumb == null || isHttpUrl(look.thumb)) {
|
|
1415
|
+
looks[value] = look;
|
|
1416
|
+
continue;
|
|
1417
|
+
}
|
|
1418
|
+
const abs = local(look.thumb);
|
|
1419
|
+
this.thumbs.allow(abs);
|
|
1420
|
+
looks[value] = {
|
|
1421
|
+
...look,
|
|
1422
|
+
thumb: thumbUrl(abs, 128)
|
|
1423
|
+
};
|
|
1424
|
+
}
|
|
1425
|
+
desc.ui = {
|
|
1426
|
+
...desc.ui,
|
|
1427
|
+
options: looks
|
|
1428
|
+
};
|
|
1429
|
+
}
|
|
1430
|
+
if (desc.mediaPresets != null) desc.mediaPresets = desc.mediaPresets.map((preset) => {
|
|
1431
|
+
if (isHttpUrl(preset.value)) {
|
|
1432
|
+
const cached = this.urlInputPath(preset.value, basename(new URL(preset.value).pathname));
|
|
1433
|
+
return {
|
|
1434
|
+
...preset,
|
|
1435
|
+
thumb: existsSync(cached) ? thumbUrl(cached, 160) : preset.value
|
|
1436
|
+
};
|
|
1437
|
+
}
|
|
1438
|
+
const abs = local(preset.value);
|
|
1439
|
+
this.thumbs.allow(abs);
|
|
1440
|
+
return existsSync(abs) ? {
|
|
1441
|
+
...preset,
|
|
1442
|
+
value: abs,
|
|
1443
|
+
thumb: thumbUrl(abs, 160)
|
|
1444
|
+
} : {
|
|
1445
|
+
...preset,
|
|
1446
|
+
value: abs,
|
|
1447
|
+
missing: true
|
|
1448
|
+
};
|
|
1449
|
+
});
|
|
1450
|
+
if (MEDIA_KINDS.includes(desc.kind) && typeof desc.default === "string" && desc.default !== "") {
|
|
1451
|
+
if (!isHttpUrl(desc.default)) this.thumbs.allow(local(desc.default));
|
|
1452
|
+
}
|
|
1453
|
+
}
|
|
1454
|
+
async replyThumb(url) {
|
|
1455
|
+
const q = new URLSearchParams(url.split("?")[1] ?? "");
|
|
1456
|
+
const src = q.get("src");
|
|
1457
|
+
if (src == null || src === "") return json(400, { error: "thumb needs ?src=<local path>" });
|
|
1458
|
+
const out = await this.thumbs.render(src, Number(q.get("w") ?? 160) || 160);
|
|
1459
|
+
if (out === "forbidden") return json(403, { error: "not a picture a served workflow declared, nor under its folder or the outputs" });
|
|
1460
|
+
if (out === "missing") return json(404, { error: "not on this machine" });
|
|
1461
|
+
return {
|
|
1462
|
+
status: 200,
|
|
1463
|
+
contentType: "image/webp",
|
|
1464
|
+
body: out,
|
|
1465
|
+
headers: { "cache-control": "max-age=300" }
|
|
1466
|
+
};
|
|
1467
|
+
}
|
|
1329
1468
|
describeModule(mod) {
|
|
1330
1469
|
refreshLoraInfoCacheIfChanged();
|
|
1331
1470
|
const hostId = mod.dw.host.data.id;
|
|
1332
1471
|
const vars = {};
|
|
1333
1472
|
for (const [name, varDef] of mod.dw.entries()) {
|
|
1334
1473
|
const desc = describeVar(varDef);
|
|
1474
|
+
this.decorateLooks(desc, mod);
|
|
1335
1475
|
if (desc.kind === "loras" && desc.options != null) {
|
|
1336
1476
|
const labels = {};
|
|
1337
1477
|
for (const option of desc.options) {
|
|
@@ -2274,6 +2414,8 @@ var ServeApp = class {
|
|
|
2274
2414
|
if (audios.length > 0) produced.push(`${audios.length} audio(s)`);
|
|
2275
2415
|
const videos = execution.videos ?? [];
|
|
2276
2416
|
if (videos.length > 0) produced.push(`${videos.length} video(s)`);
|
|
2417
|
+
const models3d = execution.models3d ?? [];
|
|
2418
|
+
if (models3d.length > 0) produced.push(`${models3d.length} 3d model(s)`);
|
|
2277
2419
|
if ((execution.texts ?? []).length > 0) produced.push(`${(execution.texts ?? []).length} text(s)`);
|
|
2278
2420
|
console.log(`[serve] 🟢 ${mod.key}/${draft} done in ${(durationMs / 1e3).toFixed(1)}s · ${produced.join(" · ")}`);
|
|
2279
2421
|
const blobs = [];
|
|
@@ -2295,6 +2437,12 @@ var ServeApp = class {
|
|
|
2295
2437
|
blobs.push(this.memoryBlob(key, a.bytes, a.filename));
|
|
2296
2438
|
return key;
|
|
2297
2439
|
});
|
|
2440
|
+
const model3dKeys = models3d.map((m, ix) => {
|
|
2441
|
+
if (m.absPath != null) return null;
|
|
2442
|
+
const key = `model3d/${execution.data.id}/${ix}`;
|
|
2443
|
+
blobs.push(this.memoryBlob(key, m.bytes, m.filename));
|
|
2444
|
+
return key;
|
|
2445
|
+
});
|
|
2298
2446
|
const memoryUrl = (route, key) => `/${route}/${key.split("/").slice(route === "images" ? 0 : 1).map((seg) => encodeURIComponent(seg)).join("/")}`;
|
|
2299
2447
|
const record = {
|
|
2300
2448
|
ok: true,
|
|
@@ -2314,7 +2462,8 @@ var ServeApp = class {
|
|
|
2314
2462
|
return {
|
|
2315
2463
|
filename: img.filename,
|
|
2316
2464
|
url: img.absPath != null ? this.outputUrl(img.absPath) : key != null ? memoryUrl("images", key) : null,
|
|
2317
|
-
absPath: img.absPath
|
|
2465
|
+
absPath: img.absPath,
|
|
2466
|
+
...img.tags != null && img.tags.length > 0 ? { tags: [...img.tags] } : {}
|
|
2318
2467
|
};
|
|
2319
2468
|
}),
|
|
2320
2469
|
audios: audios.map((a, ix) => {
|
|
@@ -2334,13 +2483,26 @@ var ServeApp = class {
|
|
|
2334
2483
|
url: a.absPath != null ? this.outputUrl(a.absPath) : key != null ? memoryUrl("video", key) : null,
|
|
2335
2484
|
absPath: a.absPath
|
|
2336
2485
|
};
|
|
2337
|
-
})
|
|
2486
|
+
}),
|
|
2487
|
+
models3d: models3d.map((m, ix) => {
|
|
2488
|
+
const key = model3dKeys[ix];
|
|
2489
|
+
return {
|
|
2490
|
+
filename: m.filename,
|
|
2491
|
+
mime: m.mime,
|
|
2492
|
+
format: m.format,
|
|
2493
|
+
size: m.bytes.byteLength,
|
|
2494
|
+
url: m.absPath != null ? this.outputUrl(m.absPath) : key != null ? memoryUrl("model3d", key) : null,
|
|
2495
|
+
absPath: m.absPath
|
|
2496
|
+
};
|
|
2497
|
+
}),
|
|
2498
|
+
...mod.dw.spec.widgets != null && mod.dw.spec.widgets.length > 0 ? { widgets: mod.dw.spec.widgets } : {}
|
|
2338
2499
|
};
|
|
2339
2500
|
this.kept.add({
|
|
2340
2501
|
record,
|
|
2341
2502
|
imageKeys,
|
|
2342
2503
|
audioKeys,
|
|
2343
2504
|
videoKeys,
|
|
2505
|
+
model3dKeys,
|
|
2344
2506
|
blobs
|
|
2345
2507
|
});
|
|
2346
2508
|
const first = execution.images[0];
|
|
@@ -2486,8 +2648,15 @@ var ServeApp = class {
|
|
|
2486
2648
|
this.chains.set(key, next.catch(() => {}));
|
|
2487
2649
|
return next;
|
|
2488
2650
|
}
|
|
2651
|
+
/** one file per url: a preset or a pasted url downloads once per output root, not per run */
|
|
2652
|
+
urlInputPath(url, name) {
|
|
2653
|
+
const hash = createHash("sha1").update(url).digest("hex").slice(0, 16);
|
|
2654
|
+
return join(this.outputRoot, "serve-inputs", `url-${hash}${extname(name)}`);
|
|
2655
|
+
}
|
|
2489
2656
|
/** payload image urls land as local files under outputs/serve-inputs/ */
|
|
2490
2657
|
async downloadInput(url) {
|
|
2658
|
+
const cached = this.urlInputPath(url, basename(new URL(url).pathname));
|
|
2659
|
+
if (existsSync(cached)) return cached;
|
|
2491
2660
|
try {
|
|
2492
2661
|
return await this.fetchInput(url);
|
|
2493
2662
|
} catch (e) {
|
|
@@ -2508,7 +2677,7 @@ var ServeApp = class {
|
|
|
2508
2677
|
if (declared > INPUT_DOWNLOAD_CAP) throw new Error(`download too large (${declared} bytes): ${url}`);
|
|
2509
2678
|
const bytes = await readCapped(res, INPUT_DOWNLOAD_CAP, url);
|
|
2510
2679
|
const name = basename(new URL(url).pathname) || "input";
|
|
2511
|
-
const abs =
|
|
2680
|
+
const abs = this.urlInputPath(url, name);
|
|
2512
2681
|
mkdirSync(dirname(abs), { recursive: true });
|
|
2513
2682
|
writeFileSync(abs, bytes);
|
|
2514
2683
|
return abs;
|
|
@@ -2517,4 +2686,4 @@ var ServeApp = class {
|
|
|
2517
2686
|
//#endregion
|
|
2518
2687
|
export { describeVar as n, renderDescriptorLine as r, ServeApp as t };
|
|
2519
2688
|
|
|
2520
|
-
//# sourceMappingURL=ServeApp-
|
|
2689
|
+
//# sourceMappingURL=ServeApp-DolRCMHj.js.map
|