comfy-ts 2.20.2 → 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 (89) hide show
  1. package/README.md +17 -1
  2. package/dist/{ServeApp-B469W26E.js → ServeApp-DuxYdaZZ.js} +142 -7
  3. package/dist/ServeApp-DuxYdaZZ.js.map +1 -0
  4. package/dist/cli.js +5 -5
  5. package/dist/{exampleAssets-yBLaKXLq.js → exampleAssets-1NHndnNB.js} +59 -17
  6. package/dist/exampleAssets-1NHndnNB.js.map +1 -0
  7. package/dist/{findDefinedWorkflow-B90-xFxX.js → findDefinedWorkflow-CRsBTTJK.js} +2 -2
  8. package/dist/{findDefinedWorkflow-B90-xFxX.js.map → findDefinedWorkflow-CRsBTTJK.js.map} +1 -1
  9. package/dist/index.cjs +118 -19
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.d.cts +90 -9
  12. package/dist/index.d.ts +90 -9
  13. package/dist/index.js +117 -20
  14. package/dist/index.js.map +1 -1
  15. package/dist/{run-run-C-dDD9Dc.js → run-run-Y5ZI48vV.js} +5 -5
  16. package/dist/{run-run-C-dDD9Dc.js.map → run-run-Y5ZI48vV.js.map} +1 -1
  17. package/dist/{run-serve-CsEYPGm9.js → run-serve-CICU_wTL.js} +4 -4
  18. package/dist/{run-serve-CsEYPGm9.js.map → run-serve-CICU_wTL.js.map} +1 -1
  19. package/dist/{run-tui-bsmja4hi.js → run-tui-CViJXsHL.js} +4 -4
  20. package/dist/{run-tui-bsmja4hi.js.map → run-tui-CViJXsHL.js.map} +1 -1
  21. package/dist/{schemaDrift-DaWsE-mt.js → schemaDrift-CzjaIwZX.js} +53 -20
  22. package/dist/schemaDrift-CzjaIwZX.js.map +1 -0
  23. package/dist/serve-web.js +204 -47
  24. package/dist/web.d.ts +90 -9
  25. package/dist/web.js +117 -20
  26. package/dist/web.js.map +1 -1
  27. package/examples/README.md +2 -0
  28. package/examples/depth-explorer/models.ts +722 -0
  29. package/examples/depth-explorer/serve.ts +140 -0
  30. package/examples/depth-explorer/thumbs/bae.webp +0 -0
  31. package/examples/depth-explorer/thumbs/da3-mono-large.webp +0 -0
  32. package/examples/depth-explorer/thumbs/dav1-vitl.webp +0 -0
  33. package/examples/depth-explorer/thumbs/dav2-vitl.webp +0 -0
  34. package/examples/depth-explorer/thumbs/dsine.webp +0 -0
  35. package/examples/depth-explorer/thumbs/iid-albedo.webp +0 -0
  36. package/examples/depth-explorer/thumbs/iid-metalness.webp +0 -0
  37. package/examples/depth-explorer/thumbs/iid-roughness.webp +0 -0
  38. package/examples/depth-explorer/thumbs/iid-shading.webp +0 -0
  39. package/examples/depth-explorer/thumbs/iid-specular.webp +0 -0
  40. package/examples/depth-explorer/thumbs/leres.webp +0 -0
  41. package/examples/depth-explorer/thumbs/lotus-depth.webp +0 -0
  42. package/examples/depth-explorer/thumbs/marigold2-albedo.webp +0 -0
  43. package/examples/depth-explorer/thumbs/marigold2-depth.webp +0 -0
  44. package/examples/depth-explorer/thumbs/marigold2-normal.webp +0 -0
  45. package/examples/depth-explorer/thumbs/metric3d-depth.webp +0 -0
  46. package/examples/depth-explorer/thumbs/metric3d-normal.webp +0 -0
  47. package/examples/depth-explorer/thumbs/midas-normal.webp +0 -0
  48. package/examples/depth-explorer/thumbs/midas.webp +0 -0
  49. package/examples/depth-explorer/thumbs/moge2-depth.webp +0 -0
  50. package/examples/depth-explorer/thumbs/moge2-normal.webp +0 -0
  51. package/examples/depth-explorer/thumbs/zoe-da.webp +0 -0
  52. package/examples/depth-explorer/thumbs/zoe.webp +0 -0
  53. package/examples/depth-explorer/web/App.tsx +457 -0
  54. package/examples/depth-explorer/web/gl.ts +202 -0
  55. package/examples/depth-explorer/web/index.html +14 -0
  56. package/examples/depth-explorer/web/main.tsx +19 -0
  57. package/examples/depth-explorer/web/pixels.ts +86 -0
  58. package/examples/depth-explorer/web/state.ts +329 -0
  59. package/examples/depth-explorer/web/styles.css +366 -0
  60. package/examples/depth-explorer/web/tsconfig.json +16 -0
  61. package/examples/rvion/17-relight.cflow.ts +110 -0
  62. package/package.json +3 -2
  63. package/src/cli/serve/ServeApp.ts +79 -4
  64. package/src/cli/serve/describeVar.ts +12 -1
  65. package/src/cli/serve/resultHistory.ts +6 -1
  66. package/src/cli/serve/thumbs.ts +66 -0
  67. package/src/cli/serve/web/api.ts +5 -1
  68. package/src/cli/serve/web/components/Gallery.tsx +2 -0
  69. package/src/cli/serve/web/components/controls/BasicControls.tsx +14 -17
  70. package/src/cli/serve/web/components/controls/MediaControl.tsx +62 -9
  71. package/src/cli/serve/web/components/controls/RichSelect.tsx +262 -0
  72. package/src/cli/serve/web/state/RunSt.poll.test.ts +4 -1
  73. package/src/cli/serve/web/state/choiceButtons.ts +26 -2
  74. package/src/cli/serve/web/styles.ts +39 -0
  75. package/src/cli/serve/web/widgets/OutputWidgets.tsx +19 -0
  76. package/src/cli/serve/web/widgets/RelightSt.ts +113 -0
  77. package/src/cli/serve/web/widgets/RelightWidget.tsx +305 -0
  78. package/src/cli/serve/web/widgets/relightGl.ts +305 -0
  79. package/src/cli/serve/web/widgets/widgetStyles.ts +19 -0
  80. package/src/coreExports.ts +9 -0
  81. package/src/host/ComfyHost.ts +21 -0
  82. package/src/host/leastBusy.ts +37 -0
  83. package/src/state.ts +6 -0
  84. package/src/vars/ComfyVars.ts +32 -2
  85. package/src/vars/DefinedWorkflow.ts +42 -21
  86. package/src/vars/outputWidgets.ts +47 -0
  87. package/dist/ServeApp-B469W26E.js.map +0 -1
  88. package/dist/exampleAssets-yBLaKXLq.js.map +0 -1
  89. package/dist/schemaDrift-DaWsE-mt.js.map +0 -1
package/README.md CHANGED
@@ -4,10 +4,12 @@
4
4
 
5
5
  <a href="https://youtu.be/eniEaCp_NS4"><img src="https://raw.githubusercontent.com/rvion/comfy-ts/main/trailer/comfy-ts/thumbnail.jpg" alt="The comfy-ts trailer on YouTube, 1:39" width="640"></a>
6
6
 
7
- [![CI](https://github.com/rvion/comfy-ts/actions/workflows/ci.yml/badge.svg)](https://github.com/rvion/comfy-ts/actions/workflows/ci.yml) [![npm version](https://img.shields.io/npm/v/comfy-ts.svg)](https://www.npmjs.com/package/comfy-ts) [![npm downloads](https://img.shields.io/npm/dm/comfy-ts.svg)](https://www.npmjs.com/package/comfy-ts) [![GitHub release](https://img.shields.io/github/v/release/rvion/comfy-ts)](https://github.com/rvion/comfy-ts/releases) [![types](https://img.shields.io/npm/types/comfy-ts)](https://www.npmjs.com/package/comfy-ts) [![license](https://img.shields.io/npm/l/comfy-ts.svg)](https://github.com/rvion/comfy-ts/blob/main/LICENSE) [![sponsor](https://img.shields.io/github/sponsors/rvion?label=sponsor&logo=githubsponsors)](https://github.com/sponsors/rvion)
7
+ [![CI](https://github.com/rvion/comfy-ts/actions/workflows/ci.yml/badge.svg)](https://github.com/rvion/comfy-ts/actions/workflows/ci.yml) [![npm version](https://img.shields.io/npm/v/comfy-ts.svg)](https://www.npmjs.com/package/comfy-ts) [![npm downloads](https://img.shields.io/npm/dm/comfy-ts.svg)](https://www.npmjs.com/package/comfy-ts) [![GitHub release](https://img.shields.io/github/v/release/rvion/comfy-ts)](https://github.com/rvion/comfy-ts/releases) [![types](https://img.shields.io/npm/types/comfy-ts)](https://www.npmjs.com/package/comfy-ts) [![license](https://img.shields.io/npm/l/comfy-ts.svg)](https://github.com/rvion/comfy-ts/blob/main/LICENSE) [![sponsor](https://img.shields.io/github/sponsors/rvion?label=sponsor&logo=githubsponsors)](https://github.com/sponsors/rvion) [![discord](https://img.shields.io/discord/1087008112969531513?label=discord&logo=discord&logoColor=white)](https://discord.gg/GfAN6hF2ad)
8
8
 
9
9
  Write ComfyUI workflows in TypeScript, then run them from code, one command, a terminal, a browser or an agent. Types come from your own ComfyUI: every node and model it has autocompletes, and a wrong graph is a compile error. Run on your GPU, another machine or Comfy Cloud, and get the images, audio and video back in your code or as files. 73 ready workflows cover 43 model families, from SDXL to Wan video and ACE-Step songs.
10
10
 
11
+ 💬 Questions, help, or something you made with it: come say hi on [the Discord](https://discord.gg/GfAN6hF2ad).
12
+
11
13
  | you want to | start here |
12
14
  | --- | --- |
13
15
  | build and run workflows in code, typed down to the model names of your exact machine | [the SDK](#-the-sdk-workflows-as-code), [the codegen](#-the-codegen-an-sdk-for-your-own-install) |
@@ -438,6 +440,19 @@ Reaching a Comfy that runs on another one of your machines:
438
440
  - **tailscale**: `tailscale serve 8188` on the box gives a stable https url for `url:`. Plain tailnet hostnames work with `host:` too.
439
441
  - **cloudflared**: `cloudflared tunnel --url http://127.0.0.1:8188` prints a temporary public https url. Paste it into `url:`.
440
442
 
443
+ Several GPUs: `comfy.leastBusy` returns the host with the shortest queue, and `run({ host })` runs the workflow there.
444
+
445
+ ```ts
446
+ const gpus = [comfy.host({ id: 'gpu-1' }), comfy.host({ id: 'gpu-2' })]
447
+ const runs = prompts.map(async (prompt) => {
448
+ txt2img.vars.prompt.value = prompt
449
+ return txt2img.run({ host: await comfy.leastBusy(gpus) })
450
+ })
451
+ await Promise.all(runs)
452
+ ```
453
+
454
+ It counts the jobs in each server's queue, from every client, and the runs this process started that the server has not seen yet, so runs started together spread over the hosts. A host that does not answer is skipped. The graph is built against the host it runs on: a model that host does not have fails the run with ComfyUI's own error.
455
+
441
456
  ## 🔌 Custom nodes and models: ComfyUI-Manager
442
457
 
443
458
  The whole ComfyUI-Manager registry is mirrored into generated types: every known custom node pack, plugin title and model is a typed union. The generated files are committed, browsable TypeScript:
@@ -566,6 +581,7 @@ One folder of local state per consumer repo: `hosts/` (schema dumps, the generat
566
581
  | serve web panel: every var as a control, queue, gallery, phone | ✅ |
567
582
  | prompt refiner in the panel (OpenRouter or local Open WebUI) | ✅ |
568
583
  | cloud hosts: `url` + `X-API-Key` auth, Comfy Cloud ran live | ✅ |
584
+ | several GPUs: `comfy.leastBusy(hosts)` picks the shortest queue | 🔶 |
569
585
  | ComfyUI-Manager registry mirror + Known\* ecosystem unions | ✅ |
570
586
  | install custom nodes / models through the ComfyUI-Manager queue (V3.x, 4.x) | 🔶 |
571
587
  | content-addressed local asset cache | 🔶 |
@@ -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-DaWsE-mt.js";
2
- import { d as isDraftMetaKey, l as assembleLogChunks, o as draftsDirForFile, s as listDraftsForFile, u as ENHANCE_KEY } from "./findDefinedWorkflow-B90-xFxX.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-B469W26E.js.map
2655
+ //# sourceMappingURL=ServeApp-DuxYdaZZ.js.map