comfy-ts 2.14.0 → 2.16.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 (75) hide show
  1. package/README.md +1 -0
  2. package/dist/{LogsSt-CUeo843w.js → LogsSt-Ct7Le0S_.js} +2 -2
  3. package/dist/{LogsSt-CUeo843w.js.map → LogsSt-Ct7Le0S_.js.map} +1 -1
  4. package/dist/cli.js +4 -4
  5. package/dist/index.cjs +268 -55
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.d.cts +176 -26
  8. package/dist/index.d.ts +176 -26
  9. package/dist/index.js +262 -56
  10. package/dist/index.js.map +1 -1
  11. package/dist/{run-serve-DUqcn0h3.js → run-serve-C78hD7t9.js} +119 -40
  12. package/dist/run-serve-C78hD7t9.js.map +1 -0
  13. package/dist/{run-tui-D-LaSqgB.js → run-tui-nPETFRmk.js} +15 -9
  14. package/dist/run-tui-nPETFRmk.js.map +1 -0
  15. package/dist/{schemaDrift-E95iTF7E.js → schemaDrift-wb5XkrHV.js} +218 -27
  16. package/dist/schemaDrift-wb5XkrHV.js.map +1 -0
  17. package/dist/serve-web.js +64 -50
  18. package/dist/{state-BytbdZ8s.js → state-BMW57_M0.js} +45 -35
  19. package/dist/state-BMW57_M0.js.map +1 -0
  20. package/dist/web.d.ts +173 -26
  21. package/dist/web.js +251 -53
  22. package/dist/web.js.map +1 -1
  23. package/examples/README.md +1 -0
  24. package/examples/media/README.md +9 -0
  25. package/examples/media/sine_440hz_3s.flac +0 -0
  26. package/examples/media/testsrc_256x256_3s.mp4 +0 -0
  27. package/examples/media/voice_en_6s.flac +0 -0
  28. package/examples/rvion/04-krea2-turbo-t2i.cflow.ts +9 -1
  29. package/examples/rvion/10-anima-t2i.cflow.ts +8 -1
  30. package/examples/rvion/14-video-soundtrack.cflow.ts +47 -0
  31. package/examples/rvion/15-tts-voice-clone.cflow.ts +111 -0
  32. package/guide-for-agents.md +3 -1
  33. package/package.json +2 -2
  34. package/src/cli/serve/ServeApp.ts +115 -32
  35. package/src/cli/serve/applyVarPayload.ts +5 -3
  36. package/src/cli/serve/describeVar.ts +5 -3
  37. package/src/cli/serve/resultHistory.ts +22 -6
  38. package/src/cli/serve/run-serve.ts +4 -1
  39. package/src/cli/serve/web/api.ts +4 -0
  40. package/src/cli/serve/web/components/DraftTabs.tsx +2 -1
  41. package/src/cli/serve/web/components/Gallery.tsx +86 -5
  42. package/src/cli/serve/web/components/HistoryPicker.tsx +5 -3
  43. package/src/cli/serve/web/components/MenuButton.tsx +2 -4
  44. package/src/cli/serve/web/components/Omnibox.tsx +2 -1
  45. package/src/cli/serve/web/components/PromptEnhancer.tsx +4 -3
  46. package/src/cli/serve/web/components/ShortcutsModal.tsx +2 -1
  47. package/src/cli/serve/web/components/SideMenu.tsx +2 -1
  48. package/src/cli/serve/web/components/VarsForm.tsx +5 -3
  49. package/src/cli/serve/web/components/controls/LorasControl.tsx +4 -3
  50. package/src/cli/serve/web/components/controls/MediaControl.tsx +111 -0
  51. package/src/cli/serve/web/components/controls/PresetPicker.tsx +2 -1
  52. package/src/cli/serve/web/components/controls/PromptControl.tsx +2 -1
  53. package/src/cli/serve/web/components/controls/SizeControl.tsx +2 -1
  54. package/src/cli/serve/web/state/FormSt.ts +70 -2
  55. package/src/cli/serve/web/state/escape.ts +16 -0
  56. package/src/cli/serve/web/state/host.ts +2 -0
  57. package/src/cli/serve/web/state/mediaDrop.ts +76 -0
  58. package/src/cli/serve/web/styles.ts +16 -2
  59. package/src/cli/tui/imagePicker/ImagePickerOverlay.tsx +4 -1
  60. package/src/cli/tui/imagePicker/ImagePickerSt.ts +15 -6
  61. package/src/cli/tui/state/TuiSt.ts +1 -1
  62. package/src/coreExports.ts +20 -1
  63. package/src/exampleAssets.ts +13 -3
  64. package/src/host/ComfyUploader.ts +34 -27
  65. package/src/index.ts +1 -1
  66. package/src/runner/ComfyExecution.ts +38 -20
  67. package/src/runner/ComfyWsApi.ts +3 -0
  68. package/src/runner/mediaKinds.ts +51 -0
  69. package/src/vars/ComfyVars.ts +178 -34
  70. package/src/vars/DefinedWorkflow.ts +35 -2
  71. package/dist/run-serve-DUqcn0h3.js.map +0 -1
  72. package/dist/run-tui-D-LaSqgB.js.map +0 -1
  73. package/dist/schemaDrift-E95iTF7E.js.map +0 -1
  74. package/dist/state-BytbdZ8s.js.map +0 -1
  75. package/src/cli/serve/web/components/controls/ImageControl.tsx +0 -72
@@ -168,6 +168,83 @@ const extractErrorMessage = (error) => {
168
168
  return String(error);
169
169
  };
170
170
  //#endregion
171
+ //#region src/utils/hashArrayBuffer.ts
172
+ const hashArrayBuffer = (buffer) => {
173
+ return sha1Hex(buffer);
174
+ };
175
+ //#endregion
176
+ //#region src/runner/mediaKinds.ts
177
+ const MEDIA_KINDS = [
178
+ "image",
179
+ "audio",
180
+ "video"
181
+ ];
182
+ /** picker defaults per kind, lowercase without dots */
183
+ const DEFAULT_MEDIA_EXTENSIONS = {
184
+ image: [
185
+ "png",
186
+ "jpg",
187
+ "jpeg",
188
+ "webp",
189
+ "gif"
190
+ ],
191
+ audio: [
192
+ "wav",
193
+ "flac",
194
+ "mp3",
195
+ "ogg",
196
+ "opus",
197
+ "m4a"
198
+ ],
199
+ video: [
200
+ "mp4",
201
+ "webm",
202
+ "mov",
203
+ "mkv",
204
+ "m4v"
205
+ ]
206
+ };
207
+ const MIMES = {
208
+ png: "image/png",
209
+ jpg: "image/jpeg",
210
+ jpeg: "image/jpeg",
211
+ webp: "image/webp",
212
+ gif: "image/gif",
213
+ flac: "audio/flac",
214
+ mp3: "audio/mpeg",
215
+ opus: "audio/ogg",
216
+ ogg: "audio/ogg",
217
+ wav: "audio/wav",
218
+ m4a: "audio/mp4",
219
+ aac: "audio/aac",
220
+ mp4: "video/mp4",
221
+ m4v: "video/mp4",
222
+ webm: "video/webm",
223
+ mov: "video/quicktime",
224
+ mkv: "video/x-matroska",
225
+ avi: "video/x-msvideo"
226
+ };
227
+ /** video containers an output node can name. An animated webp or gif is an IMAGE: the
228
+ * extension decides, never the `animated` flag */
229
+ const VIDEO_EXTENSIONS = /* @__PURE__ */ new Set([
230
+ "mp4",
231
+ "m4v",
232
+ "webm",
233
+ "mov",
234
+ "mkv",
235
+ "avi"
236
+ ]);
237
+ function extensionOf(filename) {
238
+ const dot = filename.lastIndexOf(".");
239
+ return dot < 0 ? "" : filename.slice(dot + 1).toLowerCase();
240
+ }
241
+ function isVideoFilename(filename) {
242
+ return VIDEO_EXTENSIONS.has(extensionOf(filename));
243
+ }
244
+ function mediaMime(filename) {
245
+ return MIMES[extensionOf(filename)] ?? "application/octet-stream";
246
+ }
247
+ //#endregion
171
248
  //#region src/utils/ansi.ts
172
249
  const codes = {
173
250
  bold: [1, 22],
@@ -1326,12 +1403,46 @@ var ToggleVar = class extends ComfyVar {
1326
1403
  return this.value ? "ON" : "OFF";
1327
1404
  }
1328
1405
  };
1406
+ /** a fixed list, or the host's list for one slot once bindHost ran */
1407
+ var ChoiceList = class {
1408
+ constructor(source) {
1409
+ this.source = source;
1410
+ this.resolved = null;
1411
+ }
1412
+ get slot() {
1413
+ return isChoiceList(this.source) ? null : this.source;
1414
+ }
1415
+ get choices() {
1416
+ if (isChoiceList(this.source)) return this.source;
1417
+ if (this.resolved == null) throw new Error(`v.model('${this.source.slot}') is host-bound — it only works inside defineWorkflow({ vars }) (pass a name list to v.choice otherwise)`);
1418
+ return this.resolved;
1419
+ }
1420
+ /** cast: whitelist family 1 (agent/coding.md) — stringValues() returns the runtime values of
1421
+ * the SAME object_info enum the generated slot union comes from */
1422
+ bind(host) {
1423
+ const src = this.slot;
1424
+ if (src == null) return;
1425
+ const all = host.schema.stringValues(src.slot);
1426
+ const filter = src.filter == null ? null : statelessRegex(src.filter);
1427
+ this.resolved = filter == null ? all : all.filter((n) => filter.test(n));
1428
+ }
1429
+ };
1329
1430
  var ChoiceVar = class extends ComfyVar {
1330
1431
  constructor(choices, defaultValue, label) {
1331
1432
  super(defaultValue, label);
1332
- this.choices = choices;
1333
1433
  this.kind = "choice";
1334
1434
  this.select = "one";
1435
+ this.list = new ChoiceList(choices);
1436
+ }
1437
+ get choices() {
1438
+ return this.list.choices;
1439
+ }
1440
+ /** set for `v.model`: the loader input this choice lists */
1441
+ get hostSlot() {
1442
+ return this.list.slot;
1443
+ }
1444
+ bindHost(host) {
1445
+ this.list.bind(host);
1335
1446
  }
1336
1447
  next(delta = 1) {
1337
1448
  const nextIx = (this.choices.indexOf(this.value) + delta + this.choices.length) % this.choices.length;
@@ -1348,9 +1459,18 @@ var ChoiceVar = class extends ComfyVar {
1348
1459
  var OptionalChoiceVar = class extends ComfyVar {
1349
1460
  constructor(choices, defaultValue, label) {
1350
1461
  super(defaultValue, label);
1351
- this.choices = choices;
1352
1462
  this.kind = "choice";
1353
1463
  this.select = "zero-or-one";
1464
+ this.list = new ChoiceList(choices);
1465
+ }
1466
+ get choices() {
1467
+ return this.list.choices;
1468
+ }
1469
+ get hostSlot() {
1470
+ return this.list.slot;
1471
+ }
1472
+ bindHost(host) {
1473
+ this.list.bind(host);
1354
1474
  }
1355
1475
  /** pick `c`, or clear it when it is already the one picked */
1356
1476
  toggle(c) {
@@ -1428,6 +1548,14 @@ function choice(choices, defaultValue, opts) {
1428
1548
  if (defaultValue == null) throw new Error("a 'one' choice needs a default: use { select: 'zero-or-one' } for none");
1429
1549
  return new ChoiceVar(choices, defaultValue, o.label);
1430
1550
  }
1551
+ function model(slot, opts) {
1552
+ const source = {
1553
+ slot,
1554
+ filter: opts.filter
1555
+ };
1556
+ if (opts.default == null) return new OptionalChoiceVar(source, null, opts.label);
1557
+ return new ChoiceVar(source, opts.default, opts.label);
1558
+ }
1431
1559
  /**
1432
1560
  * multi-select lora stack over a DYNAMIC options list — a RegExp resolves
1433
1561
  * against the host's loras at define time (DefinedWorkflow calls bindHost),
@@ -1700,42 +1828,53 @@ var SizeVar = class extends ComfyVar {
1700
1828
  return `${width}×${height}${hit ? ` (${hit.label})` : ""}`;
1701
1829
  }
1702
1830
  };
1703
- const DEFAULT_IMAGE_EXTENSIONS = [
1704
- "png",
1705
- "jpg",
1706
- "jpeg",
1707
- "webp",
1708
- "gif"
1709
- ];
1710
- /** empty image var consumed at build time — typed so drivers surface it apart from real crashes */
1711
- var ImageVarEmptyError = class extends Error {
1712
- constructor(varName) {
1713
- super(`image var '${varName}' is empty — pick a file (TUI: activate the var; script: .set('/path/to/image.png'))`);
1831
+ DEFAULT_MEDIA_EXTENSIONS.image;
1832
+ DEFAULT_MEDIA_EXTENSIONS.audio;
1833
+ DEFAULT_MEDIA_EXTENSIONS.video;
1834
+ /** empty media var consumed at build time — typed so drivers surface it apart from real crashes */
1835
+ var MediaVarEmptyError = class extends Error {
1836
+ constructor(varName, media = "image") {
1837
+ super(`${media} var '${varName}' is empty — pick a file (TUI: activate the var; script: .set('/path/to/file'))`);
1714
1838
  this.varName = varName;
1715
- this.name = "ImageVarEmptyError";
1839
+ this.media = media;
1840
+ this.name = "MediaVarEmptyError";
1716
1841
  }
1717
1842
  };
1718
- /** trim + expand a leading `~/` — every ImageVar write funnels through this */
1843
+ /** trim + expand a leading `~/` — every media var write funnels through this */
1719
1844
  function expandUserPath(raw) {
1720
1845
  const trimmed = raw.trim();
1721
1846
  return trimmed.startsWith("~/") ? join(getComfyStorage().homedir(), trimmed.slice(2)) : trimmed;
1722
1847
  }
1848
+ /** the loader node each medium goes through, and its file input */
1849
+ const MEDIA_LOADERS = {
1850
+ image: {
1851
+ node: "LoadImage",
1852
+ input: "image"
1853
+ },
1854
+ audio: {
1855
+ node: "LoadAudio",
1856
+ input: "audio"
1857
+ },
1858
+ video: {
1859
+ node: "LoadVideo",
1860
+ input: "file"
1861
+ }
1862
+ };
1723
1863
  /**
1724
- * a local image path. The VALUE is a PLAIN PATH STRING — text-encodable,
1864
+ * a local media file path. The VALUE is a PLAIN PATH STRING — text-encodable,
1725
1865
  * drafts persist it verbatim (toJSON = the string), hand-editable in the
1726
- * draft json. Empty = unset: outValue()/absPath() throw ImageVarEmptyError,
1727
- * so a build never runs on a silent placeholder. The TUI opens the image
1728
- * picker overlay for kind 'image'.
1866
+ * draft json. Empty = unset: outValue()/absPath() throw MediaVarEmptyError,
1867
+ * so a build never runs on a silent placeholder. The TUI opens the file
1868
+ * picker overlay for every media kind.
1729
1869
  */
1730
- var ImageVar = class extends ComfyVar {
1870
+ var MediaVar = class extends ComfyVar {
1731
1871
  constructor(defaultValue, opts = {}) {
1732
1872
  super(expandUserPath(defaultValue), opts.label);
1733
1873
  this.opts = opts;
1734
- this.kind = "image";
1735
1874
  }
1736
1875
  /** what the picker lists (lowercase, no dots) */
1737
1876
  get extensions() {
1738
- return this.opts.extensions ?? DEFAULT_IMAGE_EXTENSIONS;
1877
+ return this.opts.extensions ?? DEFAULT_MEDIA_EXTENSIONS[this.kind];
1739
1878
  }
1740
1879
  set(value) {
1741
1880
  return super.set(expandUserPath(value));
@@ -1748,7 +1887,7 @@ var ImageVar = class extends ComfyVar {
1748
1887
  return this.value !== "";
1749
1888
  }
1750
1889
  emptyError() {
1751
- return new ImageVarEmptyError(this.name ?? this.label ?? "image");
1890
+ return new MediaVarEmptyError(this.name ?? this.label ?? this.kind, this.kind);
1752
1891
  }
1753
1892
  /** the ONE resolution helper: absolute kept as-is, relative resolved against opts.folder, else cwd */
1754
1893
  absPath() {
@@ -1766,8 +1905,56 @@ var ImageVar = class extends ComfyVar {
1766
1905
  const home = getComfyStorage().homedir();
1767
1906
  return this.value.startsWith(`${home}/`) ? `~${this.value.slice(home.length)}` : this.value;
1768
1907
  }
1908
+ /** upload the file hash-named (reruns dedupe) and add this medium's loader node. A dry
1909
+ * build names the file by its hash and uploads nothing */
1910
+ async loadVia(wf) {
1911
+ const loader = MEDIA_LOADERS[this.kind];
1912
+ const factory = wf.builderBase[loader.node];
1913
+ if (factory == null) throw new Error(`host '${wf.host.data.id}' has no ${loader.node} node: ${this.kind} var '${this.name ?? "?"}' cannot load`);
1914
+ const abs = this.absPath();
1915
+ const bytes = getComfyStorage().readBytes(abs);
1916
+ const ext = extensionOf(abs);
1917
+ const name = `${hashArrayBuffer(bytes)}${ext === "" ? "" : `.${ext}`}`;
1918
+ const onHost = wf.dry ? name : await wf.host.uploader.uploadInput({
1919
+ blob: new Blob([bytes], { type: mediaMime(abs) }),
1920
+ name,
1921
+ slot: `${loader.node}.${loader.input}`,
1922
+ type: "input"
1923
+ });
1924
+ return factory({ [loader.input]: onHost });
1925
+ }
1926
+ };
1927
+ /** a local image path, loaded through LoadImage */
1928
+ var ImageVar = class extends MediaVar {
1929
+ constructor(..._args2) {
1930
+ super(..._args2);
1931
+ this.kind = "image";
1932
+ }
1933
+ async loadInWorkflow(wf) {
1934
+ return await this.loadVia(wf);
1935
+ }
1936
+ };
1937
+ /** a local audio path, loaded through LoadAudio */
1938
+ var AudioVar = class extends MediaVar {
1939
+ constructor(..._args3) {
1940
+ super(..._args3);
1941
+ this.kind = "audio";
1942
+ }
1943
+ async loadInWorkflow(wf) {
1944
+ return await this.loadVia(wf);
1945
+ }
1946
+ };
1947
+ /** a local video path, loaded through LoadVideo */
1948
+ var VideoVar = class extends MediaVar {
1949
+ constructor(..._args4) {
1950
+ super(..._args4);
1951
+ this.kind = "video";
1952
+ }
1953
+ async loadInWorkflow(wf) {
1954
+ return await this.loadVia(wf);
1955
+ }
1769
1956
  };
1770
- /** the var constructors: v.text / v.prompt / v.int / v.float / v.seed / v.toggle / v.choice / v.loras / v.size / v.image */
1957
+ /** the var constructors: v.text / v.prompt / v.int / v.float / v.seed / v.toggle / v.choice / v.model / v.loras / v.size / v.image / v.audio / v.video */
1771
1958
  const v = {
1772
1959
  text: (defaultValue, opts = {}) => new TextVar(defaultValue, typeof opts === "string" ? { label: opts } : opts),
1773
1960
  prompt: (defaultValue, opts = {}) => new PromptVar(defaultValue, opts),
@@ -1782,7 +1969,11 @@ const v = {
1782
1969
  choice,
1783
1970
  loras: (options, initial = {}, label) => new LorasVar(options, initial, label),
1784
1971
  size: (defaultValue, opts = {}) => new SizeVar(defaultValue, opts.presets ?? sizePresetsFor(defaultValue), opts.label, opts.image, opts.starred),
1785
- image: (defaultValue, opts = {}) => new ImageVar(defaultValue, opts)
1972
+ /** host-bound: only inside defineWorkflow({ vars: (v) => … }), typed per slot there */
1973
+ model,
1974
+ image: (defaultValue, opts = {}) => new ImageVar(defaultValue, opts),
1975
+ audio: (defaultValue, opts = {}) => new AudioVar(defaultValue, opts),
1976
+ video: (defaultValue, opts = {}) => new VideoVar(defaultValue, opts)
1786
1977
  };
1787
1978
  function varValues(vars) {
1788
1979
  const out = {};
@@ -1980,6 +2171,6 @@ function summarizeDrift(d) {
1980
2171
  return parts.join(", ");
1981
2172
  }
1982
2173
  //#endregion
1983
- export { stripAnsi as $, refreshLoraInfoCacheIfChanged as A, lmFilePath as B, getLoraTriggerWords as C, lorasMissingFromMirror as D, loraMirrorEntries as E, fetchLoraExampleImages as F, lmSha256 as G, lmFolder as H, fetchLoraList as I, loraBasename as J, lmTags as K, fetchLoraPreviewBytes as L, writeLoraMirror as M, fetchLoraCivitai as N, readLoraMirror as O, fetchLoraDescription as P, colorsAvailable as Q, lmBaseModel as R, getLoraPreviewUrl as S, loraMatchesFilter as T, lmModelName as U, lmFileSize as V, lmNotes as W, loraPreviewMapFrom as X, loraKey as Y, ansi as Z, setLoraKeyword as _, DefinedWorkflow as a, isQuiet as at, getLoraDisplayName as b, PromptVar as c, logSuccess as ct, isPromptInput as d, sha1HexOfString as dt, extractErrorMessage as et, isLoraStrength as f, loraKeywordFromMirror as g, isLoraKeywordFromMirror as h, summarizeDrift as i, resolveComfyStorage as it, reloadLoraInfoCache as j, recordCivitaiMiss as k, isLoraLanes as l, statelessRegex as lt, getLoraKeyword as m, diffSchemas as n, bang as nt, DEFAULT_IMAGE_EXTENSIONS as o, logError as ot, clearLoraKeywordOverride as p, lmTrainedWords as q, driftChanged as r, getComfyStorage as rt, LorasVar as s, logInfo as st, MODEL_LISTS as t, isRecord as tt, isLorasInput as u, sha1Hex as ut, buildLoraMirror as v, getLoraTriggers as w, getLoraInfo as x, getLoraAddedAt as y, lmCivitai as z };
2174
+ export { DEFAULT_MEDIA_EXTENSIONS as $, reloadLoraInfoCache as A, lmFileSize as B, getLoraTriggers as C, readLoraMirror as D, lorasMissingFromMirror as E, fetchLoraList as F, lmTags as G, lmModelName as H, fetchLoraPreviewBytes as I, loraKey as J, lmTrainedWords as K, lmBaseModel as L, fetchLoraCivitai as M, fetchLoraDescription as N, recordCivitaiMiss as O, fetchLoraExampleImages as P, stripAnsi as Q, lmCivitai as R, getLoraTriggerWords as S, loraMirrorEntries as T, lmNotes as U, lmFolder as V, lmSha256 as W, ansi as X, loraPreviewMapFrom as Y, colorsAvailable as Z, buildLoraMirror as _, DefinedWorkflow as a, extractErrorMessage as at, getLoraInfo as b, isLoraLanes as c, getComfyStorage as ct, isLoraStrength as d, logError as dt, MEDIA_KINDS as et, clearLoraKeywordOverride as f, logInfo as ft, setLoraKeyword as g, loraKeywordFromMirror as h, sha1HexOfString as ht, summarizeDrift as i, hashArrayBuffer as it, writeLoraMirror as j, refreshLoraInfoCacheIfChanged as k, isLorasInput as l, resolveComfyStorage as lt, isLoraKeywordFromMirror as m, statelessRegex as mt, diffSchemas as n, isVideoFilename as nt, LorasVar as o, isRecord as ot, getLoraKeyword as p, logSuccess as pt, loraBasename as q, driftChanged as r, mediaMime as rt, PromptVar as s, bang as st, MODEL_LISTS as t, extensionOf as tt, isPromptInput as u, isQuiet as ut, getLoraAddedAt as v, loraMatchesFilter as w, getLoraPreviewUrl as x, getLoraDisplayName as y, lmFilePath as z };
1984
2175
 
1985
- //# sourceMappingURL=schemaDrift-E95iTF7E.js.map
2176
+ //# sourceMappingURL=schemaDrift-wb5XkrHV.js.map