comfy-ts 2.21.0 → 2.22.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.
Files changed (85) hide show
  1. package/dist/{ServeApp-ByMobrWW.js → ServeApp-DuxYdaZZ.js} +142 -7
  2. package/dist/ServeApp-DuxYdaZZ.js.map +1 -0
  3. package/dist/cli.js +5 -5
  4. package/dist/{exampleAssets-B5sMqNia.js → exampleAssets-1NHndnNB.js} +4 -17
  5. package/dist/exampleAssets-1NHndnNB.js.map +1 -0
  6. package/dist/{findDefinedWorkflow-BNZgYIww.js → findDefinedWorkflow-CRsBTTJK.js} +2 -2
  7. package/dist/{findDefinedWorkflow-BNZgYIww.js.map → findDefinedWorkflow-CRsBTTJK.js.map} +1 -1
  8. package/dist/index.cjs +32 -1
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.d.cts +71 -6
  11. package/dist/index.d.ts +71 -6
  12. package/dist/index.js +31 -2
  13. package/dist/index.js.map +1 -1
  14. package/dist/{run-run-CuBSygku.js → run-run-Y5ZI48vV.js} +5 -5
  15. package/dist/{run-run-CuBSygku.js.map → run-run-Y5ZI48vV.js.map} +1 -1
  16. package/dist/{run-serve-COk_G0Qz.js → run-serve-CICU_wTL.js} +4 -4
  17. package/dist/{run-serve-COk_G0Qz.js.map → run-serve-CICU_wTL.js.map} +1 -1
  18. package/dist/{run-tui-CB6i_x2y.js → run-tui-CViJXsHL.js} +4 -4
  19. package/dist/{run-tui-CB6i_x2y.js.map → run-tui-CViJXsHL.js.map} +1 -1
  20. package/dist/{schemaDrift-CHDVYlaj.js → schemaDrift-CzjaIwZX.js} +22 -2
  21. package/dist/schemaDrift-CzjaIwZX.js.map +1 -0
  22. package/dist/serve-web.js +204 -47
  23. package/dist/web.d.ts +71 -6
  24. package/dist/web.js +31 -2
  25. package/dist/web.js.map +1 -1
  26. package/examples/README.md +2 -0
  27. package/examples/depth-explorer/models.ts +722 -0
  28. package/examples/depth-explorer/serve.ts +140 -0
  29. package/examples/depth-explorer/thumbs/bae.webp +0 -0
  30. package/examples/depth-explorer/thumbs/da3-mono-large.webp +0 -0
  31. package/examples/depth-explorer/thumbs/dav1-vitl.webp +0 -0
  32. package/examples/depth-explorer/thumbs/dav2-vitl.webp +0 -0
  33. package/examples/depth-explorer/thumbs/dsine.webp +0 -0
  34. package/examples/depth-explorer/thumbs/iid-albedo.webp +0 -0
  35. package/examples/depth-explorer/thumbs/iid-metalness.webp +0 -0
  36. package/examples/depth-explorer/thumbs/iid-roughness.webp +0 -0
  37. package/examples/depth-explorer/thumbs/iid-shading.webp +0 -0
  38. package/examples/depth-explorer/thumbs/iid-specular.webp +0 -0
  39. package/examples/depth-explorer/thumbs/leres.webp +0 -0
  40. package/examples/depth-explorer/thumbs/lotus-depth.webp +0 -0
  41. package/examples/depth-explorer/thumbs/marigold2-albedo.webp +0 -0
  42. package/examples/depth-explorer/thumbs/marigold2-depth.webp +0 -0
  43. package/examples/depth-explorer/thumbs/marigold2-normal.webp +0 -0
  44. package/examples/depth-explorer/thumbs/metric3d-depth.webp +0 -0
  45. package/examples/depth-explorer/thumbs/metric3d-normal.webp +0 -0
  46. package/examples/depth-explorer/thumbs/midas-normal.webp +0 -0
  47. package/examples/depth-explorer/thumbs/midas.webp +0 -0
  48. package/examples/depth-explorer/thumbs/moge2-depth.webp +0 -0
  49. package/examples/depth-explorer/thumbs/moge2-normal.webp +0 -0
  50. package/examples/depth-explorer/thumbs/zoe-da.webp +0 -0
  51. package/examples/depth-explorer/thumbs/zoe.webp +0 -0
  52. package/examples/depth-explorer/web/App.tsx +457 -0
  53. package/examples/depth-explorer/web/gl.ts +202 -0
  54. package/examples/depth-explorer/web/index.html +14 -0
  55. package/examples/depth-explorer/web/main.tsx +19 -0
  56. package/examples/depth-explorer/web/pixels.ts +86 -0
  57. package/examples/depth-explorer/web/state.ts +329 -0
  58. package/examples/depth-explorer/web/styles.css +366 -0
  59. package/examples/depth-explorer/web/tsconfig.json +16 -0
  60. package/examples/rvion/17-relight.cflow.ts +110 -0
  61. package/package.json +3 -2
  62. package/src/cli/serve/ServeApp.ts +79 -4
  63. package/src/cli/serve/describeVar.ts +12 -1
  64. package/src/cli/serve/resultHistory.ts +6 -1
  65. package/src/cli/serve/thumbs.ts +66 -0
  66. package/src/cli/serve/web/api.ts +5 -1
  67. package/src/cli/serve/web/components/Gallery.tsx +2 -0
  68. package/src/cli/serve/web/components/controls/BasicControls.tsx +14 -17
  69. package/src/cli/serve/web/components/controls/MediaControl.tsx +62 -9
  70. package/src/cli/serve/web/components/controls/RichSelect.tsx +262 -0
  71. package/src/cli/serve/web/state/RunSt.poll.test.ts +4 -1
  72. package/src/cli/serve/web/state/choiceButtons.ts +26 -2
  73. package/src/cli/serve/web/styles.ts +39 -0
  74. package/src/cli/serve/web/widgets/OutputWidgets.tsx +19 -0
  75. package/src/cli/serve/web/widgets/RelightSt.ts +113 -0
  76. package/src/cli/serve/web/widgets/RelightWidget.tsx +305 -0
  77. package/src/cli/serve/web/widgets/relightGl.ts +305 -0
  78. package/src/cli/serve/web/widgets/widgetStyles.ts +19 -0
  79. package/src/coreExports.ts +9 -0
  80. package/src/vars/ComfyVars.ts +32 -2
  81. package/src/vars/DefinedWorkflow.ts +4 -0
  82. package/src/vars/outputWidgets.ts +47 -0
  83. package/dist/ServeApp-ByMobrWW.js.map +0 -1
  84. package/dist/exampleAssets-B5sMqNia.js.map +0 -1
  85. package/dist/schemaDrift-CHDVYlaj.js.map +0 -1
@@ -1,10 +1,11 @@
1
- import { $ as DEFAULT_MEDIA_EXTENSIONS, 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, b as getLoraInfo, c as isLoraLanes, d as isLoraStrength, et as MEDIA_KINDS, ht as extractErrorMessage, i as summarizeDrift, j as writeLoraMirror, k as refreshLoraInfoCacheIfChanged, l as isLorasInput, mt as sha1HexOfString, ot as bang, p as getLoraKeyword, pt as statelessRegex, r as driftChanged, u as isPromptInput, v as getLoraAddedAt, x as getLoraPreviewUrl, y as getLoraDisplayName, z as lmFilePath } from "./schemaDrift-CHDVYlaj.js";
2
- import { d as isDraftMetaKey, l as assembleLogChunks, o as draftsDirForFile, s as listDraftsForFile, u as ENHANCE_KEY } from "./findDefinedWorkflow-BNZgYIww.js";
1
+ import { $ as DEFAULT_MEDIA_EXTENSIONS, 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, at as importSharp, b as getLoraInfo, c as isLoraLanes, d as isLoraStrength, et as MEDIA_KINDS, gt as extractErrorMessage, ht as sha1HexOfString, i as summarizeDrift, j as writeLoraMirror, k as refreshLoraInfoCacheIfChanged, l as isLorasInput, mt as statelessRegex, p as getLoraKeyword, r as driftChanged, st as bang, u as isPromptInput, v as getLoraAddedAt, x as getLoraPreviewUrl, y as getLoraDisplayName, z as lmFilePath } from "./schemaDrift-CzjaIwZX.js";
2
+ import { d as isDraftMetaKey, l as assembleLogChunks, o as draftsDirForFile, s as listDraftsForFile, u as ENHANCE_KEY } from "./findDefinedWorkflow-CRsBTTJK.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,60 @@ 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
+ const MAX_WIDTH = 640;
154
+ const MAX_CACHED = 400;
155
+ var ThumbStore = class {
156
+ constructor() {
157
+ this.allowed = /* @__PURE__ */ new Set();
158
+ this.roots = /* @__PURE__ */ new Set();
159
+ this.cache = /* @__PURE__ */ new Map();
160
+ }
161
+ /** one file a served module declared */
162
+ allow(abs) {
163
+ this.allowed.add(resolve(abs));
164
+ }
165
+ /** every image under this folder */
166
+ allowRoot(dir) {
167
+ this.roots.add(resolve(dir));
168
+ }
169
+ isAllowed(abs) {
170
+ const p = resolve(abs);
171
+ if (this.allowed.has(p)) return true;
172
+ for (const root of this.roots) if (p.startsWith(`${root}/`)) return true;
173
+ return false;
174
+ }
175
+ /** a webp at most `width` wide, or why not: 'forbidden' (not declared, not under a root),
176
+ * 'missing' (not on this machine) */
177
+ async render(abs, width) {
178
+ if (!this.isAllowed(abs)) return "forbidden";
179
+ const p = resolve(abs);
180
+ if (!existsSync(p)) return "missing";
181
+ const w = Math.max(16, Math.min(MAX_WIDTH, Math.round(width)));
182
+ const key = `${p}|${statSync(p).mtimeMs}|${w}`;
183
+ const hit = this.cache.get(key);
184
+ if (hit != null) return hit;
185
+ const sharp = await importSharp("a thumbnail");
186
+ const bytes = new Uint8Array(await sharp(p).rotate().resize({
187
+ width: w,
188
+ height: w,
189
+ fit: "inside",
190
+ withoutEnlargement: true
191
+ }).webp({ quality: 78 }).toBuffer());
192
+ if (this.cache.size >= MAX_CACHED) {
193
+ const oldest = this.cache.keys().next().value;
194
+ if (oldest != null) this.cache.delete(oldest);
195
+ }
196
+ this.cache.set(key, bytes);
197
+ return bytes;
198
+ }
199
+ };
200
+ //#endregion
144
201
  //#region src/cli/serve/applyVarPayload.ts
145
202
  function isFiniteNumber(x) {
146
203
  return typeof x === "number" && Number.isFinite(x);
@@ -1154,6 +1211,7 @@ var ServeApp = class {
1154
1211
  this.settingsCache = null;
1155
1212
  this.keptCache = null;
1156
1213
  this.tagsByModule = /* @__PURE__ */ new Map();
1214
+ this.thumbs = new ThumbStore();
1157
1215
  this.tabs = null;
1158
1216
  this.tagSources = new TagSources({
1159
1217
  cacheDir: () => join(comfyts.baseFolder, "cache", "tags"),
@@ -1206,6 +1264,7 @@ var ServeApp = class {
1206
1264
  if (segs[0] === "llm-configs" && segs.length === 1) return this.replyLlmConfigs();
1207
1265
  if (segs[0] === "tags" && segs.length === 3 && segs[1] != null && segs[2] != null) return await this.replyTags(segs[1], segs[2], req.url);
1208
1266
  if (segs[0] === "settings" && segs.length === 1) return this.replySettings();
1267
+ if (segs[0] === "thumb" && segs.length === 1) return await this.replyThumb(req.url);
1209
1268
  if (segs[0] === "tabs" && segs.length === 1) return this.replyTabs();
1210
1269
  if (segs[0] === "hosts" && segs.length === 1) return this.replyHosts();
1211
1270
  if (segs[0] === "hosts" && segs.length === 3 && segs[1] != null && segs[2] === "logs") return await this.replyHostLogs(segs[1]);
@@ -1326,12 +1385,79 @@ var ServeApp = class {
1326
1385
  error: "use POST /generate/<module>/<draft> or /generate/<draft>"
1327
1386
  };
1328
1387
  }
1388
+ /** the pictures of a descriptor made concrete for the page: a local thumb or preset becomes a
1389
+ * /thumb url the store allows, a local preset not on this machine is flagged missing, a url
1390
+ * stays as it is. Relative paths are relative to the workflow file */
1391
+ decorateLooks(desc, mod) {
1392
+ const dir = dirname(mod.file);
1393
+ this.thumbs.allowRoot(dir);
1394
+ this.thumbs.allowRoot(this.outputRoot);
1395
+ const local = (p) => isAbsolute(p) ? p : resolve(dir, p);
1396
+ const options = desc.ui?.options;
1397
+ if (desc.ui != null && options != null) {
1398
+ const looks = {};
1399
+ for (const [value, look] of Object.entries(options)) {
1400
+ if (look.thumb == null || isHttpUrl(look.thumb)) {
1401
+ looks[value] = look;
1402
+ continue;
1403
+ }
1404
+ const abs = local(look.thumb);
1405
+ this.thumbs.allow(abs);
1406
+ looks[value] = {
1407
+ ...look,
1408
+ thumb: thumbUrl(abs, 128)
1409
+ };
1410
+ }
1411
+ desc.ui = {
1412
+ ...desc.ui,
1413
+ options: looks
1414
+ };
1415
+ }
1416
+ if (desc.mediaPresets != null) desc.mediaPresets = desc.mediaPresets.map((preset) => {
1417
+ if (isHttpUrl(preset.value)) {
1418
+ const cached = this.urlInputPath(preset.value, basename(new URL(preset.value).pathname));
1419
+ return {
1420
+ ...preset,
1421
+ thumb: existsSync(cached) ? thumbUrl(cached, 160) : preset.value
1422
+ };
1423
+ }
1424
+ const abs = local(preset.value);
1425
+ this.thumbs.allow(abs);
1426
+ return existsSync(abs) ? {
1427
+ ...preset,
1428
+ value: abs,
1429
+ thumb: thumbUrl(abs, 160)
1430
+ } : {
1431
+ ...preset,
1432
+ value: abs,
1433
+ missing: true
1434
+ };
1435
+ });
1436
+ if (MEDIA_KINDS.includes(desc.kind) && typeof desc.default === "string" && desc.default !== "") {
1437
+ if (!isHttpUrl(desc.default)) this.thumbs.allow(local(desc.default));
1438
+ }
1439
+ }
1440
+ async replyThumb(url) {
1441
+ const q = new URLSearchParams(url.split("?")[1] ?? "");
1442
+ const src = q.get("src");
1443
+ if (src == null || src === "") return json(400, { error: "thumb needs ?src=<local path>" });
1444
+ const out = await this.thumbs.render(src, Number(q.get("w") ?? 160) || 160);
1445
+ if (out === "forbidden") return json(403, { error: "not a picture a served workflow declared, nor under its folder or the outputs" });
1446
+ if (out === "missing") return json(404, { error: "not on this machine" });
1447
+ return {
1448
+ status: 200,
1449
+ contentType: "image/webp",
1450
+ body: out,
1451
+ headers: { "cache-control": "max-age=300" }
1452
+ };
1453
+ }
1329
1454
  describeModule(mod) {
1330
1455
  refreshLoraInfoCacheIfChanged();
1331
1456
  const hostId = mod.dw.host.data.id;
1332
1457
  const vars = {};
1333
1458
  for (const [name, varDef] of mod.dw.entries()) {
1334
1459
  const desc = describeVar(varDef);
1460
+ this.decorateLooks(desc, mod);
1335
1461
  if (desc.kind === "loras" && desc.options != null) {
1336
1462
  const labels = {};
1337
1463
  for (const option of desc.options) {
@@ -2314,7 +2440,8 @@ var ServeApp = class {
2314
2440
  return {
2315
2441
  filename: img.filename,
2316
2442
  url: img.absPath != null ? this.outputUrl(img.absPath) : key != null ? memoryUrl("images", key) : null,
2317
- absPath: img.absPath
2443
+ absPath: img.absPath,
2444
+ ...img.tags != null && img.tags.length > 0 ? { tags: [...img.tags] } : {}
2318
2445
  };
2319
2446
  }),
2320
2447
  audios: audios.map((a, ix) => {
@@ -2334,7 +2461,8 @@ var ServeApp = class {
2334
2461
  url: a.absPath != null ? this.outputUrl(a.absPath) : key != null ? memoryUrl("video", key) : null,
2335
2462
  absPath: a.absPath
2336
2463
  };
2337
- })
2464
+ }),
2465
+ ...mod.dw.spec.widgets != null && mod.dw.spec.widgets.length > 0 ? { widgets: mod.dw.spec.widgets } : {}
2338
2466
  };
2339
2467
  this.kept.add({
2340
2468
  record,
@@ -2486,8 +2614,15 @@ var ServeApp = class {
2486
2614
  this.chains.set(key, next.catch(() => {}));
2487
2615
  return next;
2488
2616
  }
2617
+ /** one file per url: a preset or a pasted url downloads once per output root, not per run */
2618
+ urlInputPath(url, name) {
2619
+ const hash = createHash("sha1").update(url).digest("hex").slice(0, 16);
2620
+ return join(this.outputRoot, "serve-inputs", `url-${hash}${extname(name)}`);
2621
+ }
2489
2622
  /** payload image urls land as local files under outputs/serve-inputs/ */
2490
2623
  async downloadInput(url) {
2624
+ const cached = this.urlInputPath(url, basename(new URL(url).pathname));
2625
+ if (existsSync(cached)) return cached;
2491
2626
  try {
2492
2627
  return await this.fetchInput(url);
2493
2628
  } catch (e) {
@@ -2508,7 +2643,7 @@ var ServeApp = class {
2508
2643
  if (declared > INPUT_DOWNLOAD_CAP) throw new Error(`download too large (${declared} bytes): ${url}`);
2509
2644
  const bytes = await readCapped(res, INPUT_DOWNLOAD_CAP, url);
2510
2645
  const name = basename(new URL(url).pathname) || "input";
2511
- const abs = join(this.outputRoot, "serve-inputs", `${nanoid(6)}-${name}`);
2646
+ const abs = this.urlInputPath(url, name);
2512
2647
  mkdirSync(dirname(abs), { recursive: true });
2513
2648
  writeFileSync(abs, bytes);
2514
2649
  return abs;
@@ -2517,4 +2652,4 @@ var ServeApp = class {
2517
2652
  //#endregion
2518
2653
  export { describeVar as n, renderDescriptorLine as r, ServeApp as t };
2519
2654
 
2520
- //# sourceMappingURL=ServeApp-ByMobrWW.js.map
2655
+ //# sourceMappingURL=ServeApp-DuxYdaZZ.js.map