comfy-ts 2.0.0 → 2.2.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 (47) hide show
  1. package/README.md +65 -225
  2. package/dist/{DefinedWorkflow-CqNE_kgR.js → DefinedWorkflow-CwHInZgn.js} +4 -3
  3. package/dist/DefinedWorkflow-CwHInZgn.js.map +1 -0
  4. package/dist/{DraftsSt-Da4DZUP7.js → DraftsSt-omWuBSej.js} +3 -4
  5. package/dist/DraftsSt-omWuBSej.js.map +1 -0
  6. package/dist/cli.js +3 -3
  7. package/dist/index.cjs +22 -5
  8. package/dist/index.cjs.map +1 -1
  9. package/dist/index.d.cts +12 -2
  10. package/dist/index.d.ts +12 -2
  11. package/dist/index.js +22 -5
  12. package/dist/index.js.map +1 -1
  13. package/dist/{run-serve-BqeXtf8P.js → run-serve-C1oo5ilG.js} +170 -126
  14. package/dist/run-serve-C1oo5ilG.js.map +1 -0
  15. package/dist/{run-tui-CiB7TbYv.js → run-tui-CuVst-nc.js} +298 -103
  16. package/dist/run-tui-CuVst-nc.js.map +1 -0
  17. package/dist/{state-C1g_B8zR.js → state-CvMt0W1-.js} +23 -7
  18. package/dist/state-CvMt0W1-.js.map +1 -0
  19. package/dist/web.d.ts +12 -2
  20. package/dist/web.js +22 -5
  21. package/dist/web.js.map +1 -1
  22. package/examples/README.md +6 -18
  23. package/examples/images/README.md +2 -6
  24. package/guide-for-agents.md +25 -84
  25. package/package.json +1 -1
  26. package/src/cli/serve/ServeApp.ts +17 -11
  27. package/src/cli/serve/applyVarPayload.ts +91 -71
  28. package/src/cli/serve/describeVar.ts +57 -28
  29. package/src/cli/tui/components/StatusBar.tsx +1 -0
  30. package/src/cli/tui/components/TextOverlay.tsx +7 -3
  31. package/src/cli/tui/components/TuiApp.tsx +4 -5
  32. package/src/cli/tui/components/VarsPanel.tsx +42 -4
  33. package/src/cli/tui/imageClipboard.ts +40 -0
  34. package/src/cli/tui/state/DraftsSt.ts +1 -2
  35. package/src/cli/tui/state/ExecSt.ts +146 -98
  36. package/src/cli/tui/state/PreviewSt.ts +12 -11
  37. package/src/cli/tui/state/SettingsSt.ts +13 -0
  38. package/src/cli/tui/state/TuiSt.ts +65 -11
  39. package/src/host/ComfyHost.ts +5 -1
  40. package/src/runner/ComfyExecution.ts +15 -7
  41. package/src/runner/outputPath.ts +11 -0
  42. package/src/vars/ComfyVars.ts +12 -2
  43. package/dist/DefinedWorkflow-CqNE_kgR.js.map +0 -1
  44. package/dist/DraftsSt-Da4DZUP7.js.map +0 -1
  45. package/dist/run-serve-BqeXtf8P.js.map +0 -1
  46. package/dist/run-tui-CiB7TbYv.js.map +0 -1
  47. package/dist/state-C1g_B8zR.js.map +0 -1
package/dist/index.d.cts CHANGED
@@ -15906,7 +15906,15 @@ declare class ResilientWebSocketClient {
15906
15906
  }
15907
15907
  //#endregion
15908
15908
  //#region src/vars/ComfyVars.d.ts
15909
- type VarKind = 'text' | 'int' | 'float' | 'seed' | 'toggle' | 'choice' | 'loras' | 'size' | 'image';
15909
+ /**
15910
+ * the var's CLASS, and the only safe way to discriminate one: `instanceof` compares class
15911
+ * OBJECTS, and the published package hands the same class out twice — a consumer's
15912
+ * `.cflow.ts` imports `comfy-ts` (dist/index.js) while `comfy-ts serve`/`tui` run from the
15913
+ * cli bundle, so every `instanceof XVar` across that boundary is false (his repro
15914
+ * 2026-07-31: "var 'prompt' has unsupported kind 'text'" for EVERY kind). A string tag
15915
+ * crosses bundles; a class identity does not.
15916
+ */
15917
+ type VarKind = 'text' | 'prompt' | 'int' | 'float' | 'seed' | 'toggle' | 'choice' | 'loras' | 'size' | 'image';
15910
15918
  /**
15911
15919
  * full base: T is what's STORED/edited, Out what the GRAPH consumes at build
15912
15920
  * time. They usually coincide — extend `ComfyVar<T>` for that. PromptVar is
@@ -15973,7 +15981,7 @@ declare class PromptVar extends ComfyVarBase<string, PromptValue> {
15973
15981
  label?: string;
15974
15982
  loraKeywordsFrom?: ActiveLoraSource;
15975
15983
  };
15976
- readonly kind: 'text';
15984
+ readonly kind: 'prompt';
15977
15985
  constructor(defaultValue: string, promptOpts?: {
15978
15986
  label?: string;
15979
15987
  loraKeywordsFrom?: ActiveLoraSource;
@@ -16151,6 +16159,8 @@ declare const DEFAULT_IMAGE_EXTENSIONS: readonly string[];
16151
16159
  /** empty image var consumed at build time — typed so drivers surface it apart from real crashes */
16152
16160
  declare class ImageVarEmptyError extends Error {
16153
16161
  readonly varName: string;
16162
+ /** name, not instanceof: the cli bundle and dist/index.js each define this class */
16163
+ readonly name = "ImageVarEmptyError";
16154
16164
  constructor(varName: string);
16155
16165
  }
16156
16166
  /**
package/dist/index.d.ts CHANGED
@@ -15906,7 +15906,15 @@ declare class ResilientWebSocketClient {
15906
15906
  }
15907
15907
  //#endregion
15908
15908
  //#region src/vars/ComfyVars.d.ts
15909
- type VarKind = 'text' | 'int' | 'float' | 'seed' | 'toggle' | 'choice' | 'loras' | 'size' | 'image';
15909
+ /**
15910
+ * the var's CLASS, and the only safe way to discriminate one: `instanceof` compares class
15911
+ * OBJECTS, and the published package hands the same class out twice — a consumer's
15912
+ * `.cflow.ts` imports `comfy-ts` (dist/index.js) while `comfy-ts serve`/`tui` run from the
15913
+ * cli bundle, so every `instanceof XVar` across that boundary is false (his repro
15914
+ * 2026-07-31: "var 'prompt' has unsupported kind 'text'" for EVERY kind). A string tag
15915
+ * crosses bundles; a class identity does not.
15916
+ */
15917
+ type VarKind = 'text' | 'prompt' | 'int' | 'float' | 'seed' | 'toggle' | 'choice' | 'loras' | 'size' | 'image';
15910
15918
  /**
15911
15919
  * full base: T is what's STORED/edited, Out what the GRAPH consumes at build
15912
15920
  * time. They usually coincide — extend `ComfyVar<T>` for that. PromptVar is
@@ -15973,7 +15981,7 @@ declare class PromptVar extends ComfyVarBase<string, PromptValue> {
15973
15981
  label?: string;
15974
15982
  loraKeywordsFrom?: ActiveLoraSource;
15975
15983
  };
15976
- readonly kind: 'text';
15984
+ readonly kind: 'prompt';
15977
15985
  constructor(defaultValue: string, promptOpts?: {
15978
15986
  label?: string;
15979
15987
  loraKeywordsFrom?: ActiveLoraSource;
@@ -16151,6 +16159,8 @@ declare const DEFAULT_IMAGE_EXTENSIONS: readonly string[];
16151
16159
  /** empty image var consumed at build time — typed so drivers surface it apart from real crashes */
16152
16160
  declare class ImageVarEmptyError extends Error {
16153
16161
  readonly varName: string;
16162
+ /** name, not instanceof: the cli bundle and dist/index.js each define this class */
16163
+ readonly name = "ImageVarEmptyError";
16154
16164
  constructor(varName: string);
16155
16165
  }
16156
16166
  /**
package/dist/index.js CHANGED
@@ -110,7 +110,7 @@ function createNodeStorage() {
110
110
  }
111
111
  //#endregion
112
112
  //#region package.json
113
- var version = "2.0.0";
113
+ var version = "2.2.0";
114
114
  //#endregion
115
115
  //#region src/litegraph/LiteGraphLinkID.ts
116
116
  const asLiteGraphLinkID = (id) => id;
@@ -1691,6 +1691,15 @@ const localOutputPath = (p) => {
1691
1691
  ].filter((x) => x != null).join("_") + ext;
1692
1692
  return dir === "" ? name : `${dir}/${name}`;
1693
1693
  };
1694
+ /** REPLACE the extension (never append one): a re-encoded save owns its whole
1695
+ * name now that local naming is ours, so `save: {format:'image/webp'}` writes
1696
+ * `shot_20260731-154210_00001.webp`, not `…_00001.png.webp` — appending
1697
+ * described the bytes twice and the first description was a lie */
1698
+ const withExtension = (path, ext) => {
1699
+ const slash = path.lastIndexOf("/");
1700
+ const dot = path.lastIndexOf(".");
1701
+ return `${dot > slash ? path.slice(0, dot) : path}.${ext}`;
1702
+ };
1694
1703
  /**
1695
1704
  * never-overwrite guard: bump `-2`, `-3`, … while the path exists on disk OR
1696
1705
  * was already CLAIMED by a still-downloading retrieval (two same-second runs
@@ -2173,7 +2182,9 @@ var MediaImage = class MediaImage {
2173
2182
  //#endregion
2174
2183
  //#region src/runner/ComfyExecution.ts
2175
2184
  /** paths claimed by in-flight retrievals: two same-second runs on a
2176
- * counter-resetting cloud host compute the same name before either writes */
2185
+ * counter-resetting cloud host compute the same name before either writes.
2186
+ * A claim is released as soon as the write lands (the file itself then holds
2187
+ * the name) or fails (the name is free again) — the set never accumulates */
2177
2188
  const CLAIMED_OUTPUT_PATHS = /* @__PURE__ */ new Set();
2178
2189
  var ComfyExecution = class {
2179
2190
  get host() {
@@ -2300,14 +2311,18 @@ var ComfyExecution = class {
2300
2311
  filename: p.filename,
2301
2312
  timestamp: runTimestamp(new Date(this.startedAt))
2302
2313
  }));
2303
- if (reencode) absPath += "." + bang(p.sf.format).split("/")[1];
2314
+ if (reencode) absPath = withExtension(absPath, bang(bang(p.sf.format).split("/")[1]));
2304
2315
  const storage = getComfyStorage();
2305
2316
  absPath = uniquifyOutputPath({
2306
2317
  path: absPath,
2307
2318
  exists: (x) => storage.exists(x),
2308
2319
  claimed: CLAIMED_OUTPUT_PATHS
2309
2320
  });
2310
- storage.writeBytes(asAbsolutePath(absPath), bytes);
2321
+ try {
2322
+ storage.writeBytes(asAbsolutePath(absPath), bytes);
2323
+ } finally {
2324
+ CLAIMED_OUTPUT_PATHS.delete(absPath);
2325
+ }
2311
2326
  return {
2312
2327
  path: asAbsolutePath(absPath),
2313
2328
  bytes
@@ -4009,7 +4024,7 @@ var PromptVar = class extends ComfyVarBase {
4009
4024
  constructor(defaultValue, promptOpts = {}) {
4010
4025
  super(defaultValue, promptOpts.label);
4011
4026
  this.promptOpts = promptOpts;
4012
- this.kind = "text";
4027
+ this.kind = "prompt";
4013
4028
  }
4014
4029
  parse(raw) {
4015
4030
  this.set(raw);
@@ -4414,6 +4429,7 @@ var ImageVarEmptyError = class extends Error {
4414
4429
  constructor(varName) {
4415
4430
  super(`image var '${varName}' is empty — pick a file (TUI: activate the var; script: .set('/path/to/image.png'))`);
4416
4431
  this.varName = varName;
4432
+ this.name = "ImageVarEmptyError";
4417
4433
  }
4418
4434
  };
4419
4435
  /** trim + expand a leading `~/` — every ImageVar write funnels through this */
@@ -4986,6 +5002,7 @@ var ComfyHost = class {
4986
5002
  mime: frame.mime
4987
5003
  });
4988
5004
  }
5005
+ if (this.latentPreview != null) URL.revokeObjectURL(this.latentPreview.url);
4989
5006
  const imageBlob = new Blob([frame.bytes], { type: frame.mime });
4990
5007
  this.latentPreview = {
4991
5008
  blob: imageBlob,