comfy-ts 1.2.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 (42) hide show
  1. package/README.md +40 -0
  2. package/dist/DefinedWorkflow-gpknV-5f.js +686 -0
  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 +15 -5
  7. package/dist/cli.js.map +1 -1
  8. package/dist/index.cjs +132 -21
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.d.cts +5 -0
  11. package/dist/index.d.ts +23 -18
  12. package/dist/index.js +132 -21
  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-BAdizWsO.js → run-tui-BtjaOXRh.js} +244 -440
  17. package/dist/run-tui-BtjaOXRh.js.map +1 -0
  18. package/dist/{state-BYbxDgfr.js → state-DKCPy105.js} +130 -698
  19. package/dist/state-DKCPy105.js.map +1 -0
  20. package/package.json +3 -2
  21. package/src/cli/comfy-ts-cli.ts +15 -5
  22. package/src/cli/serve/ServeApp.ts +378 -0
  23. package/src/cli/serve/applyVarPayload.ts +119 -0
  24. package/src/cli/serve/describeVar.ts +74 -0
  25. package/src/cli/serve/run-serve.ts +169 -0
  26. package/src/cli/tui/components/StatusBar.tsx +1 -0
  27. package/src/cli/tui/components/TreePanel.tsx +17 -3
  28. package/src/cli/tui/components/TuiApp.tsx +7 -2
  29. package/src/cli/tui/components/VarsPanel.tsx +67 -34
  30. package/src/cli/tui/imageClipboard.ts +39 -0
  31. package/src/cli/tui/listWindow.ts +36 -0
  32. package/src/cli/tui/state/ExecSt.ts +48 -0
  33. package/src/cli/tui/state/TreeSt.ts +25 -0
  34. package/src/cli/tui/state/TuiSt.ts +34 -0
  35. package/src/litegraph/convertFlowToLiteGraphJSON.ts +11 -7
  36. package/src/runner/ComfyExecution.ts +21 -4
  37. package/src/runner/outputPath.ts +75 -0
  38. package/src/sdk-generator/inputWidgetKind.ts +50 -11
  39. package/src/sdk-generator/litegraphToApiRequestPayload.ts +14 -7
  40. package/src/vars/ComfyVars.ts +8 -0
  41. package/dist/run-tui-BAdizWsO.js.map +0 -1
  42. package/dist/state-BYbxDgfr.js.map +0 -1
package/dist/index.d.cts CHANGED
@@ -15973,6 +15973,9 @@ declare class SeedVar extends ComfyVar<number> {
15973
15973
  /** move the seed to what the NEXT run should use, per mode */
15974
15974
  advance(): this;
15975
15975
  afterRun(): void;
15976
+ /** mode is part of the seed's state: a reset must not keep a caller's `?`/`+` alive
15977
+ * ('=' is the construction default; drafts restore their own mode via loadJSON) */
15978
+ reset(): this;
15976
15979
  /** parse `+` `- 12` `= 5` `?` or a bare number (=> fixed). Keeps the current number when none given */
15977
15980
  parse(raw: string): boolean;
15978
15981
  display(): string;
@@ -16149,11 +16152,13 @@ declare const v: {
16149
16152
  type AnyVar = {
16150
16153
  readonly kind: VarKind;
16151
16154
  readonly value: unknown;
16155
+ readonly defaultValue: unknown;
16152
16156
  readonly label?: string;
16153
16157
  /** the vars-spec key — DefinedWorkflow writes it at define time */
16154
16158
  name?: string;
16155
16159
  parse(raw: string): boolean;
16156
16160
  loadJSON(value: unknown): unknown;
16161
+ reset(): unknown;
16157
16162
  toJSON(): unknown;
16158
16163
  outValue(): unknown;
16159
16164
  display(): string;
package/dist/index.d.ts CHANGED
@@ -11897,16 +11897,9 @@ declare const types$1: import("arktype").Module<{
11897
11897
  };
11898
11898
  PromptID: PromptID;
11899
11899
  PromptRelated_WsMsg: {
11900
- type: "progress";
11901
- data: {
11902
- value: number;
11903
- max: number;
11904
- };
11905
- } | {
11906
- type: "executing";
11900
+ type: "execution_start";
11907
11901
  data: {
11908
11902
  prompt_id: PromptID;
11909
- node?: ComfyNodeId | null | undefined;
11910
11903
  };
11911
11904
  } | {
11912
11905
  type: "execution_cached";
@@ -11915,9 +11908,16 @@ declare const types$1: import("arktype").Module<{
11915
11908
  prompt_id: PromptID;
11916
11909
  };
11917
11910
  } | {
11918
- type: "execution_start";
11911
+ type: "executing";
11919
11912
  data: {
11920
11913
  prompt_id: PromptID;
11914
+ node?: ComfyNodeId | null | undefined;
11915
+ };
11916
+ } | {
11917
+ type: "progress";
11918
+ data: {
11919
+ value: number;
11920
+ max: number;
11921
11921
  };
11922
11922
  } | {
11923
11923
  type: "progress_state";
@@ -11972,16 +11972,9 @@ declare const types$1: import("arktype").Module<{
11972
11972
  data: string;
11973
11973
  };
11974
11974
  WsMsg: {
11975
- type: "progress";
11976
- data: {
11977
- value: number;
11978
- max: number;
11979
- };
11980
- } | {
11981
- type: "executing";
11975
+ type: "execution_start";
11982
11976
  data: {
11983
11977
  prompt_id: PromptID;
11984
- node?: ComfyNodeId | null | undefined;
11985
11978
  };
11986
11979
  } | {
11987
11980
  type: "execution_cached";
@@ -11990,9 +11983,16 @@ declare const types$1: import("arktype").Module<{
11990
11983
  prompt_id: PromptID;
11991
11984
  };
11992
11985
  } | {
11993
- type: "execution_start";
11986
+ type: "executing";
11994
11987
  data: {
11995
11988
  prompt_id: PromptID;
11989
+ node?: ComfyNodeId | null | undefined;
11990
+ };
11991
+ } | {
11992
+ type: "progress";
11993
+ data: {
11994
+ value: number;
11995
+ max: number;
11996
11996
  };
11997
11997
  } | {
11998
11998
  type: "progress_state";
@@ -15973,6 +15973,9 @@ declare class SeedVar extends ComfyVar<number> {
15973
15973
  /** move the seed to what the NEXT run should use, per mode */
15974
15974
  advance(): this;
15975
15975
  afterRun(): void;
15976
+ /** mode is part of the seed's state: a reset must not keep a caller's `?`/`+` alive
15977
+ * ('=' is the construction default; drafts restore their own mode via loadJSON) */
15978
+ reset(): this;
15976
15979
  /** parse `+` `- 12` `= 5` `?` or a bare number (=> fixed). Keeps the current number when none given */
15977
15980
  parse(raw: string): boolean;
15978
15981
  display(): string;
@@ -16149,11 +16152,13 @@ declare const v: {
16149
16152
  type AnyVar = {
16150
16153
  readonly kind: VarKind;
16151
16154
  readonly value: unknown;
16155
+ readonly defaultValue: unknown;
16152
16156
  readonly label?: string;
16153
16157
  /** the vars-spec key — DefinedWorkflow writes it at define time */
16154
16158
  name?: string;
16155
16159
  parse(raw: string): boolean;
16156
16160
  loadJSON(value: unknown): unknown;
16161
+ reset(): unknown;
16157
16162
  toJSON(): unknown;
16158
16163
  outValue(): unknown;
16159
16164
  display(): string;
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.2.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") {
@@ -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+)?$/);