comfy-ts 1.1.0 → 1.3.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 (66) hide show
  1. package/README.md +61 -8
  2. package/dist/{DefinedWorkflow-BYyu5dK9.js → DefinedWorkflow-gpknV-5f.js} +52 -35
  3. package/dist/DefinedWorkflow-gpknV-5f.js.map +1 -0
  4. package/dist/DraftsSt-DmA0jWGl.js +434 -0
  5. package/dist/DraftsSt-DmA0jWGl.js.map +1 -0
  6. package/dist/cli.js +17 -4555
  7. package/dist/cli.js.map +1 -1
  8. package/dist/index.cjs +184 -32
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.d.cts +54 -23
  11. package/dist/index.d.ts +36 -5
  12. package/dist/index.js +184 -32
  13. package/dist/index.js.map +1 -1
  14. package/dist/run-serve-Bn6yIJB0.js +638 -0
  15. package/dist/run-serve-Bn6yIJB0.js.map +1 -0
  16. package/dist/{run-tui-DZ22HDHI.js → run-tui-BtjaOXRh.js} +791 -395
  17. package/dist/run-tui-BtjaOXRh.js.map +1 -0
  18. package/dist/state-DKCPy105.js +4690 -0
  19. package/dist/state-DKCPy105.js.map +1 -0
  20. package/examples/README.md +6 -4
  21. package/examples/{01-txt2img.cflow.ts → rvion/01-txt2img.cflow.ts} +1 -1
  22. package/examples/{02-img2img-upload.cflow.ts → rvion/02-img2img-upload.cflow.ts} +1 -1
  23. package/examples/{03-export-workflow-json.cflow.ts → rvion/03-export-workflow-json.cflow.ts} +1 -1
  24. package/examples/{04-krea2-turbo-t2i.cflow.ts → rvion/04-krea2-turbo-t2i.cflow.ts} +2 -2
  25. package/examples/{05-comfy-cloud.cflow.ts → rvion/05-comfy-cloud.cflow.ts} +2 -2
  26. package/examples/rvion/06-qwen-image-edit.cflow.ts +89 -0
  27. package/package.json +6 -2
  28. package/src/cli/comfy-ts-cli.ts +15 -5
  29. package/src/cli/serve/ServeApp.ts +378 -0
  30. package/src/cli/serve/applyVarPayload.ts +119 -0
  31. package/src/cli/serve/describeVar.ts +74 -0
  32. package/src/cli/serve/run-serve.ts +169 -0
  33. package/src/cli/tui/components/CopyOverlay.tsx +25 -0
  34. package/src/cli/tui/components/Header.tsx +9 -4
  35. package/src/cli/tui/components/HostPanel.tsx +3 -2
  36. package/src/cli/tui/components/HostsOverlay.tsx +33 -0
  37. package/src/cli/tui/components/StatusBar.tsx +29 -9
  38. package/src/cli/tui/components/TreePanel.tsx +33 -9
  39. package/src/cli/tui/components/TuiApp.tsx +54 -7
  40. package/src/cli/tui/components/VarsPanel.tsx +67 -34
  41. package/src/cli/tui/imageClipboard.ts +39 -0
  42. package/src/cli/tui/imagePicker/fsListing.ts +6 -4
  43. package/src/cli/tui/listWindow.ts +36 -0
  44. package/src/cli/tui/run-tui.tsx +47 -7
  45. package/src/cli/tui/state/DraftsSt.ts +3 -2
  46. package/src/cli/tui/state/ExecSt.ts +156 -12
  47. package/src/cli/tui/state/HostSt.ts +94 -10
  48. package/src/cli/tui/state/PickerSt.ts +8 -2
  49. package/src/cli/tui/state/QueueSt.ts +2 -2
  50. package/src/cli/tui/state/SettingsSt.ts +25 -7
  51. package/src/cli/tui/state/TreeSt.ts +164 -36
  52. package/src/cli/tui/state/TuiSt.ts +81 -6
  53. package/src/cli/tui/state/WorkflowsSt.ts +14 -2
  54. package/src/cli/tui/treeRows.ts +165 -0
  55. package/src/host/ComfyHost.ts +7 -0
  56. package/src/litegraph/convertFlowToLiteGraphJSON.ts +11 -7
  57. package/src/runner/ComfyExecution.ts +21 -4
  58. package/src/runner/ComfyWorkflowLayout.ts +6 -4
  59. package/src/runner/outputPath.ts +75 -0
  60. package/src/sdk-generator/inputWidgetKind.ts +50 -11
  61. package/src/sdk-generator/litegraphToApiRequestPayload.ts +14 -7
  62. package/src/state.ts +7 -1
  63. package/src/vars/ComfyVars.ts +33 -4
  64. package/src/vars/DefinedWorkflow.ts +21 -8
  65. package/dist/DefinedWorkflow-BYyu5dK9.js.map +0 -1
  66. package/dist/run-tui-DZ22HDHI.js.map +0 -1
package/dist/index.js CHANGED
@@ -12,7 +12,7 @@ import https from "node:https";
12
12
  import { stdout } from "node:process";
13
13
  import { fileURLToPath } from "node:url";
14
14
  //#region package.json
15
- var version = "1.1.0";
15
+ var version = "1.3.0";
16
16
  //#endregion
17
17
  //#region src/litegraph/LiteGraphLinkID.ts
18
18
  const asLiteGraphLinkID = (id) => id;
@@ -726,6 +726,25 @@ const containerInstanceSlotType = (opts) => {
726
726
  if (subs.length !== 1 || first == null || typeof first.type !== "string") return null;
727
727
  return first.type;
728
728
  };
729
+ /**
730
+ * frontend-registered widgets whose object_info opts carry NO config signal —
731
+ * the one exception to config-only classification (architecture.md rule 8).
732
+ * Every entry must quote the frontend widget-creation source.
733
+ *
734
+ * LOAD_3D (ComfyUI_frontend src/extensions/core/load3d.ts, verified
735
+ * 2026-07-31): the LOAD_3D custom widget handler runs
736
+ * node.addWidget('button', 'upload 3d model', 'upload3dmodel', …)
737
+ * node.addWidget('button', 'upload extra resources', 'uploadExtraResources', …)
738
+ * node.addWidget('button', 'clear', 'clear', …)
739
+ * THEN creates the scene widget, so the serialized run is
740
+ * [btn, btn, btn, value] with the real value LAST. Lax domain: '' in saved
741
+ * files, an {image, mask, normal, camera_info, …} dict at queue time.
742
+ */
743
+ const EMPTY_CONFIG_FRONTEND_WIDGETS = { LOAD_3D: { prefixValues: [
744
+ "upload3dmodel",
745
+ "uploadExtraResources",
746
+ "clear"
747
+ ] } };
729
748
  const classifyWidgetInput = (p) => {
730
749
  const o = isRecord(p.opts) ? p.opts : null;
731
750
  if (o?.["forceInput"] === true) return { kind: "slot" };
@@ -734,7 +753,8 @@ const classifyWidgetInput = (p) => {
734
753
  return {
735
754
  kind: "widget",
736
755
  consumes: controlConsumes(o, tn, p.name),
737
- strictValues: true
756
+ strictValues: true,
757
+ prefixValues: []
738
758
  };
739
759
  }
740
760
  if (typeof p.type !== "string") return { kind: "slot" };
@@ -742,7 +762,8 @@ const classifyWidgetInput = (p) => {
742
762
  if (ComfyPrimitiveMapping[widgetTypeName] != null) return {
743
763
  kind: "widget",
744
764
  consumes: controlConsumes(o, widgetTypeName, p.name),
745
- strictValues: true
765
+ strictValues: true,
766
+ prefixValues: []
746
767
  };
747
768
  const options = o?.["options"];
748
769
  if (Array.isArray(options)) {
@@ -759,7 +780,8 @@ const classifyWidgetInput = (p) => {
759
780
  return {
760
781
  kind: "widget",
761
782
  consumes: controlConsumes(o, p.type, p.name),
762
- strictValues: true
783
+ strictValues: true,
784
+ prefixValues: []
763
785
  };
764
786
  }
765
787
  const template = o?.["template"];
@@ -770,7 +792,15 @@ const classifyWidgetInput = (p) => {
770
792
  if (o?.["socketless"] === true) return {
771
793
  kind: "widget",
772
794
  consumes: 1,
773
- strictValues: false
795
+ strictValues: false,
796
+ prefixValues: []
797
+ };
798
+ const emptyConfigEntry = EMPTY_CONFIG_FRONTEND_WIDGETS[widgetTypeName];
799
+ if (emptyConfigEntry != null) return {
800
+ kind: "widget",
801
+ consumes: emptyConfigEntry.prefixValues.length + 1,
802
+ strictValues: false,
803
+ prefixValues: emptyConfigEntry.prefixValues
774
804
  };
775
805
  return { kind: "slot" };
776
806
  };
@@ -780,11 +810,6 @@ const classifySchemaInput = (input) => classifyWidgetInput({
780
810
  opts: input.opts,
781
811
  isEnumUnion: input.isEnum
782
812
  });
783
- /** how many widgets_values entries this schema input consumes (export path + positional walks) */
784
- const howManyWidgetValuesForThisSchemaType = (input) => {
785
- const kind = classifySchemaInput(input);
786
- return kind.kind === "widget" ? kind.consumes : 0;
787
- };
788
813
  /**
789
814
  * what ComfyUI's frontend gives a widget created with no serialized value
790
815
  * (`getWidgetDefaultValue` semantics), used when a positional array is
@@ -886,15 +911,15 @@ const convertLiteGraphToPrompt = (schema, workflow, opts = {}) => {
886
911
  if (!p.strict && isRecord(value)) return value;
887
912
  throw new WorkflowConvertError("invalid-widget-value", `node ${node.id}(${node.type}) has an invalid widget value for "${p.promptName}": ${JSON.stringify(value)}`, node);
888
913
  };
889
- /** named wins, then positional cursor; filled=true when both miss (caller falls back to the schema default) */
914
+ /** named wins, then positional cursor (+prefixLen skips leading button values, LOAD_3D); filled=true when both miss (caller falls back to the schema default) */
890
915
  const resolveWidgetValue = (p) => {
891
916
  let value;
892
917
  let has = false;
893
918
  if (Object.hasOwn(named, p.promptName)) {
894
919
  value = named[p.promptName];
895
920
  has = true;
896
- } else if (offset < positional.length) {
897
- value = positional[offset];
921
+ } else if (offset + p.prefixLen < positional.length) {
922
+ value = positional[offset + p.prefixLen];
898
923
  has = true;
899
924
  }
900
925
  if (positional.length > 0) offset += p.consumes;
@@ -906,7 +931,8 @@ const convertLiteGraphToPrompt = (schema, workflow, opts = {}) => {
906
931
  const consumePlainWidget = (p) => {
907
932
  const r = resolveWidgetValue({
908
933
  promptName: p.promptName,
909
- consumes: p.consumes
934
+ consumes: p.consumes,
935
+ prefixLen: p.prefixLen
910
936
  });
911
937
  const raw = r.filled ? defaultValueForWidget({
912
938
  type: p.typeName,
@@ -925,7 +951,8 @@ const convertLiteGraphToPrompt = (schema, workflow, opts = {}) => {
925
951
  const consumeDynamicCombo = (p) => {
926
952
  const r = resolveWidgetValue({
927
953
  promptName: p.path,
928
- consumes: 1
954
+ consumes: 1,
955
+ prefixLen: 0
929
956
  });
930
957
  const key = r.filled ? p.defaultKey : r.value;
931
958
  if (typeof key !== "string") throw new WorkflowConvertError("invalid-widget-value", `node ${node.id}(${node.type}): dynamic combo "${p.path}" key is not a string: ${JSON.stringify(key)}`, node);
@@ -953,6 +980,7 @@ const convertLiteGraphToPrompt = (schema, workflow, opts = {}) => {
953
980
  typeName: typeof sub.type === "string" ? sub.type : "COMBO",
954
981
  opts: sub.opts,
955
982
  consumes: kind.consumes,
983
+ prefixLen: kind.prefixValues.length,
956
984
  strict: kind.strictValues,
957
985
  enumValues: inlineEnum,
958
986
  linkedInput: inputsInNodeJSON.find((i) => i.name === subPath)
@@ -964,13 +992,15 @@ const convertLiteGraphToPrompt = (schema, workflow, opts = {}) => {
964
992
  if (kind.kind === "slot" && input?.widgetName != null) kind = {
965
993
  kind: "widget",
966
994
  consumes: howManyWidgetValuesForThisInputType(input.type, field.nameInComfy) === 2 ? 2 : 1,
967
- strictValues: true
995
+ strictValues: true,
996
+ prefixValues: []
968
997
  };
969
998
  if (kind.kind === "widget") consumePlainWidget({
970
999
  promptName: field.nameInComfy,
971
1000
  typeName: field.typeName,
972
1001
  opts: field.opts,
973
1002
  consumes: kind.consumes,
1003
+ prefixLen: kind.prefixValues.length,
974
1004
  strict: kind.strictValues,
975
1005
  linkedInput: input
976
1006
  });
@@ -1470,7 +1500,7 @@ const convertNodeToLiteGraphNode = (ctx, node) => {
1470
1500
  const widgets_values = [];
1471
1501
  for (const ipt of node.$schema.inputs) {
1472
1502
  const raw = node.serializeValue(ipt.nameInComfy, node.json.inputs[ipt.nameInComfy]);
1473
- const isWidget = howManyWidgetValuesForThisSchemaType(ipt) > 0;
1503
+ const kind = classifySchemaInput(ipt);
1474
1504
  if (_isLink(raw)) {
1475
1505
  const nodeUidNumber = bang(ctx.graph.nodes.find((n) => n.uid === raw[0])?.uidNumber, `link target node "${raw[0]}" not found in graph`);
1476
1506
  inputs.push({
@@ -1478,9 +1508,10 @@ const convertNodeToLiteGraphNode = (ctx, node) => {
1478
1508
  type: ipt.typeName,
1479
1509
  link: ctx.allocateLink(nodeUidNumber, raw[1], node.uidNumber, asLiteGraphSlotIndex(inputs.length), ipt.typeName)
1480
1510
  });
1481
- } else if (isWidget) {
1482
- widgets_values.push(raw);
1483
- if (ipt.typeName === "INT" && (ipt.nameInComfy === "seed" || ipt.nameInComfy === "noise_seed")) widgets_values.push(false);
1511
+ } else if (kind.kind === "widget") {
1512
+ widgets_values.push(...kind.prefixValues, raw);
1513
+ const phantoms = kind.consumes - 1 - kind.prefixValues.length;
1514
+ for (let i = 0; i < phantoms; i++) widgets_values.push(false);
1484
1515
  } else inputs.push({
1485
1516
  name: ipt.nameInComfy,
1486
1517
  type: ipt.typeName,
@@ -1526,6 +1557,65 @@ var LiteGraphCtx = class {
1526
1557
  }
1527
1558
  };
1528
1559
  //#endregion
1560
+ //#region src/runner/outputPath.ts
1561
+ /**
1562
+ * local output naming, relative to `.comfy-ts/outputs/` (his repro
1563
+ * 2026-07-31): the server filename is NOT unique — cloud hosts reset the
1564
+ * `_00001_` counter every run, so trusting it overwrote the same file — and
1565
+ * a `foo/krea/` prefix means the DIRECTORY foo/krea/, not a `krea_` name
1566
+ * prefix. Local names are ours: dir from the prompt's own filename_prefix
1567
+ * (or an explicit saveFormat.prefix override), then
1568
+ * `<stem>_<timestamp>_<counter><ext>` so every run sorts chronologically
1569
+ * per stem and nothing ever collides.
1570
+ */
1571
+ const localOutputPath = (p) => {
1572
+ const dot = p.filename.lastIndexOf(".");
1573
+ const ext = dot === -1 ? "" : p.filename.slice(dot);
1574
+ const base = dot === -1 ? p.filename : p.filename.slice(0, dot);
1575
+ const counterMatch = /_(\d+)_$/.exec(base);
1576
+ const counter = counterMatch?.[1];
1577
+ const serverStem = counterMatch != null ? base.slice(0, base.length - counterMatch[0].length) : base;
1578
+ let dir;
1579
+ let stem;
1580
+ if (p.filenamePrefix != null && p.filenamePrefix !== "") {
1581
+ const slash = p.filenamePrefix.lastIndexOf("/");
1582
+ dir = slash === -1 ? "" : p.filenamePrefix.slice(0, slash);
1583
+ stem = slash === -1 ? p.filenamePrefix : p.filenamePrefix.slice(slash + 1);
1584
+ } else {
1585
+ dir = p.subfolder;
1586
+ stem = serverStem;
1587
+ }
1588
+ if (p.localDir != null) dir = p.localDir;
1589
+ const name = [
1590
+ stem === "" ? null : stem,
1591
+ p.timestamp,
1592
+ counter
1593
+ ].filter((x) => x != null).join("_") + ext;
1594
+ return dir === "" ? name : `${dir}/${name}`;
1595
+ };
1596
+ /**
1597
+ * never-overwrite guard: bump `-2`, `-3`, … while the path exists on disk OR
1598
+ * was already CLAIMED by a still-downloading retrieval (two same-second runs
1599
+ * on a counter-resetting cloud host compute the same name — reviewer catch).
1600
+ * The chosen path is claimed before returning.
1601
+ */
1602
+ const uniquifyOutputPath = (p) => {
1603
+ let out = p.path;
1604
+ if (p.exists(out) || p.claimed.has(out)) {
1605
+ const dot = out.lastIndexOf(".");
1606
+ const stem = dot === -1 ? out : out.slice(0, dot);
1607
+ const ext = dot === -1 ? "" : out.slice(dot);
1608
+ for (let n = 2; p.exists(out) || p.claimed.has(out); n++) out = `${stem}-${n}${ext}`;
1609
+ }
1610
+ p.claimed.add(out);
1611
+ return out;
1612
+ };
1613
+ /** YYYYMMDD-HHmmss, local time — sortable, text-encodable, no colons for filesystems */
1614
+ const runTimestamp = (d) => {
1615
+ const pad = (n) => String(n).padStart(2, "0");
1616
+ return `${d.getFullYear()}${pad(d.getMonth() + 1)}${pad(d.getDate())}-${pad(d.getHours())}${pad(d.getMinutes())}${pad(d.getSeconds())}`;
1617
+ };
1618
+ //#endregion
1529
1619
  //#region src/types/index.ts
1530
1620
  const asAbsolutePath = (path) => path;
1531
1621
  const asRelativePath = (path) => path;
@@ -1871,6 +1961,9 @@ var MediaImage = class MediaImage {
1871
1961
  };
1872
1962
  //#endregion
1873
1963
  //#region src/runner/ComfyExecution.ts
1964
+ /** paths claimed by in-flight retrievals: two same-second runs on a
1965
+ * counter-resetting cloud host compute the same name before either writes */
1966
+ const CLAIMED_OUTPUT_PATHS = /* @__PURE__ */ new Set();
1874
1967
  var ComfyExecution = class {
1875
1968
  get host() {
1876
1969
  return this.workflow.host;
@@ -1936,11 +2029,23 @@ var ComfyExecution = class {
1936
2029
  if (promptNode == null) throw new Error(`❌ invariant violation: promptNode is null`);
1937
2030
  const imgRoute = "/view?" + new URLSearchParams(comfyImageInfo).toString();
1938
2031
  const sf = this.saveFormat;
1939
- let absPath = comfyts.resolveFromOutput(join(sf?.prefix ?? comfyImageInfo.subfolder, comfyImageInfo.filename));
2032
+ const promptPrefix = promptNode.inputs["filename_prefix"];
2033
+ let absPath = comfyts.resolveFromOutput(localOutputPath({
2034
+ localDir: sf?.prefix,
2035
+ filenamePrefix: typeof promptPrefix === "string" ? promptPrefix : void 0,
2036
+ subfolder: comfyImageInfo.subfolder,
2037
+ filename: comfyImageInfo.filename,
2038
+ timestamp: runTimestamp(new Date(this.startedAt))
2039
+ }));
1940
2040
  if (sf?.format && sf.format !== "raw") {
1941
2041
  const extension = sf.format.split("/")[1];
1942
2042
  absPath += "." + extension;
1943
2043
  }
2044
+ absPath = uniquifyOutputPath({
2045
+ path: absPath,
2046
+ exists: existsSync,
2047
+ claimed: CLAIMED_OUTPUT_PATHS
2048
+ });
1944
2049
  mkdirSync(dirname(absPath), { recursive: true });
1945
2050
  let img;
1946
2051
  if (sf && sf.format !== "raw") {
@@ -2183,8 +2288,8 @@ function comfyWorkflowAutoLayout(p) {
2183
2288
  if (cols[at]) cols[at].push(node);
2184
2289
  else cols[at] = [node];
2185
2290
  }
2186
- const HSEP = p?.node_hsep ?? 20;
2187
- const VSEP = p?.node_vsep ?? 20;
2291
+ const HSEP = p?.node_hsep ?? 100;
2292
+ const VSEP = p?.node_vsep ?? 40;
2188
2293
  let colX = 0;
2189
2294
  let maxY = 0;
2190
2295
  for (const col of cols) {
@@ -3694,6 +3799,12 @@ var SeedVar = class extends ComfyVar {
3694
3799
  afterRun() {
3695
3800
  this.advance();
3696
3801
  }
3802
+ /** mode is part of the seed's state: a reset must not keep a caller's `?`/`+` alive
3803
+ * ('=' is the construction default; drafts restore their own mode via loadJSON) */
3804
+ reset() {
3805
+ this.setMode("=");
3806
+ return super.reset();
3807
+ }
3697
3808
  /** parse `+` `- 12` `= 5` `?` or a bare number (=> fixed). Keeps the current number when none given */
3698
3809
  parse(raw) {
3699
3810
  const m = raw.trim().match(/^([+\-=?])?\s*(\d+)?$/);
@@ -3915,16 +4026,38 @@ const DEFAULT_SIZE_PRESETS = [
3915
4026
  height: 1344
3916
4027
  }
3917
4028
  ];
3918
- /** width/height picker: presets + free `WxH` entry */
4029
+ /** width/height picker: presets + free `WxH` entry + optionally the LIVE
4030
+ * size of a linked image var (his ask 2026-07-30: the widget shows
4031
+ * `WxH size of image '<name>'` as a pickable row) */
3919
4032
  var SizeVar = class extends ComfyVar {
3920
4033
  constructor(defaultValue = {
3921
4034
  width: 1024,
3922
4035
  height: 1024
3923
- }, presets = DEFAULT_SIZE_PRESETS, label) {
4036
+ }, presets = DEFAULT_SIZE_PRESETS, label, imageVar) {
3924
4037
  super(defaultValue, label);
3925
4038
  this.presets = presets;
4039
+ this.imageVar = imageVar;
3926
4040
  this.kind = "size";
3927
4041
  }
4042
+ /** current dimensions of the linked image var — null when no link, unset
4043
+ * path, or an unreadable/undecodable file (those errors belong to the
4044
+ * image var itself, the size row simply disappears) */
4045
+ imageSize() {
4046
+ const iv = this.imageVar;
4047
+ if (iv == null || iv.value === "") return null;
4048
+ try {
4049
+ const abs = iv.absPath();
4050
+ const meta = imageMeta(new Uint8Array(readFileSync(abs)));
4051
+ if (meta.width == null || meta.height == null) return null;
4052
+ return {
4053
+ width: meta.width,
4054
+ height: meta.height,
4055
+ name: basename(abs)
4056
+ };
4057
+ } catch {
4058
+ return null;
4059
+ }
4060
+ }
3928
4061
  /** accepts '1024x768' / '1024×768' / a preset label */
3929
4062
  parse(raw) {
3930
4063
  const m = raw.trim().match(/^(\d+)\s*[x×]\s*(\d+)$/);
@@ -4027,7 +4160,7 @@ const v = {
4027
4160
  toggle: (defaultValue, label) => new ToggleVar(defaultValue, label),
4028
4161
  choice: (choices, defaultValue, label) => new ChoiceVar(choices, defaultValue, label),
4029
4162
  loras: (options, initial = {}, label) => new LorasVar(options, initial, label),
4030
- size: (defaultValue, opts = {}) => new SizeVar(defaultValue, opts.presets, opts.label),
4163
+ size: (defaultValue, opts = {}) => new SizeVar(defaultValue, opts.presets, opts.label, opts.image),
4031
4164
  image: (defaultValue, opts = {}) => new ImageVar(defaultValue, opts)
4032
4165
  };
4033
4166
  function varValues(vars) {
@@ -4066,10 +4199,12 @@ var DefinedWorkflow = class {
4066
4199
  * (set by run()) fires each var's afterRun() right after snapshotting the
4067
4200
  * values — atomically, before any await — so the graph uses this run's seed
4068
4201
  * while the var moves to the next (queued runs get distinct seeds; a bare
4069
- * build() for copy/export never advances).
4202
+ * build() for copy/export never advances). `p.host` substitutes the host
4203
+ * the graph is built against (TUI host override): node/model availability
4204
+ * there surfaces as workflow.problems / server validation, by design.
4070
4205
  */
4071
4206
  async build(p = {}) {
4072
- const wf = this.host.workflow({ id: this.spec.id });
4207
+ const wf = (p.host ?? this.host).workflow({ id: this.spec.id });
4073
4208
  const values = varValues(this.vars);
4074
4209
  if (p.advance) for (const varDef of Object.values(this.vars)) varDef.afterRun();
4075
4210
  await this.spec.build(wf.builder, values, wf);
@@ -4077,10 +4212,20 @@ var DefinedWorkflow = class {
4077
4212
  return wf;
4078
4213
  }
4079
4214
  /** build a fresh graph from the current var values, send it, wait for outputs.
4080
- * connects first (idempotent) — modules can import offline from the schema cache */
4215
+ * connects first (idempotent) — modules can import offline from the schema cache.
4216
+ * `settings.host` runs against THAT host instead of the defining one. */
4081
4217
  async run(settings = {}) {
4082
- await this.host.connect();
4083
- const execution = await (await this.build({ advance: true })).run(settings);
4218
+ const host = settings.host ?? this.host;
4219
+ await host.connect();
4220
+ const execution = await (await this.build({
4221
+ advance: true,
4222
+ host
4223
+ })).run({
4224
+ saveFormat: settings.saveFormat,
4225
+ idMode: settings.idMode,
4226
+ log: settings.log,
4227
+ onProgress: settings.onProgress
4228
+ });
4084
4229
  this.lastExecution = execution;
4085
4230
  return execution;
4086
4231
  }
@@ -4337,6 +4482,7 @@ var ComfyHost = class {
4337
4482
  this.comfySessionId = "temp";
4338
4483
  this._unknownBinaryFrameTypes = /* @__PURE__ */ new Set();
4339
4484
  this.status = null;
4485
+ this.lastWsMessageAt = null;
4340
4486
  this.base = parseHostBase(this.data);
4341
4487
  /** folder where file related to the host config will be cached */
4342
4488
  this.cacheFolder = comfyts.resolveFromHosts(this.data.id);
@@ -4490,6 +4636,7 @@ var ComfyHost = class {
4490
4636
  prompt.onPromptRelatedMessage(msg);
4491
4637
  }
4492
4638
  onMessage(e) {
4639
+ this.lastWsMessageAt = Date.now();
4493
4640
  if (this.data.onWsMessageAny) this.data.onWsMessageAny(e);
4494
4641
  if (e.data instanceof ArrayBuffer) {
4495
4642
  const frame = parseBinaryWsFrame(e.data);
@@ -5154,6 +5301,11 @@ var ComfyRegistry = class ComfyRegistry {
5154
5301
  };
5155
5302
  //#endregion
5156
5303
  //#region src/state.ts
5304
+ /** the ONE settings-file location rule — run-tui reads it BEFORE any module
5305
+ * import creates the comfyts global, so the path logic cannot live on the instance only */
5306
+ function settingsPathFor(root) {
5307
+ return asAbsolutePath(join(root, ".comfy-ts", "settings.json"));
5308
+ }
5157
5309
  /** singleton */
5158
5310
  var ComfyTS = class ComfyTS {
5159
5311
  constructor(p = {}) {
@@ -5222,7 +5374,7 @@ var ComfyTS = class ComfyTS {
5222
5374
  }
5223
5375
  /** local TUI settings (preview mode, last draft per workflow) — gitignored */
5224
5376
  get settingsPath() {
5225
- return asAbsolutePath(join(this.baseFolder, "settings.json"));
5377
+ return settingsPathFor(this.rootPath);
5226
5378
  }
5227
5379
  resolveFromHosts(relativePath) {
5228
5380
  return asAbsolutePath(join(this.hostsFolder, relativePath));