comfy-ts 2.1.0 → 2.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 +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-C-gBk9v7.js → DraftsSt-omWuBSej.js} +2 -2
  5. package/dist/{DraftsSt-C-gBk9v7.js.map → DraftsSt-omWuBSej.js.map} +1 -1
  6. package/dist/cli.js +3 -3
  7. package/dist/index.cjs +54 -6
  8. package/dist/index.cjs.map +1 -1
  9. package/dist/index.d.cts +28 -3
  10. package/dist/index.d.ts +28 -3
  11. package/dist/index.js +54 -7
  12. package/dist/index.js.map +1 -1
  13. package/dist/{run-serve-CnlN_RFH.js → run-serve-CfzOH-AR.js} +174 -126
  14. package/dist/run-serve-CfzOH-AR.js.map +1 -0
  15. package/dist/{run-tui-DXI_Jufu.js → run-tui-_LD0DoGe.js} +49 -50
  16. package/dist/run-tui-_LD0DoGe.js.map +1 -0
  17. package/dist/{state-DC5BcG6d.js → state-C-OOEcp3.js} +54 -8
  18. package/dist/state-C-OOEcp3.js.map +1 -0
  19. package/dist/web.d.ts +28 -3
  20. package/dist/web.js +54 -7
  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 +21 -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/VarsPanel.tsx +2 -2
  32. package/src/cli/tui/state/ExecSt.ts +47 -52
  33. package/src/cli/tui/state/TuiSt.ts +11 -6
  34. package/src/coreExports.ts +1 -0
  35. package/src/host/ComfyHost.ts +55 -3
  36. package/src/runner/ComfyExecution.ts +15 -7
  37. package/src/runner/outputPath.ts +11 -0
  38. package/src/vars/ComfyVars.ts +12 -2
  39. package/dist/DefinedWorkflow-CqNE_kgR.js.map +0 -1
  40. package/dist/run-serve-CnlN_RFH.js.map +0 -1
  41. package/dist/run-tui-DXI_Jufu.js.map +0 -1
  42. package/dist/state-DC5BcG6d.js.map +0 -1
package/dist/web.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
  /**
@@ -16330,7 +16340,20 @@ type ConnectOptions = {
16330
16340
  schema?: 'auto' | 'refresh' | 'cache';
16331
16341
  /** max cache age for 'auto' (default 24h) */
16332
16342
  maxAgeMs?: number;
16343
+ /**
16344
+ * deadline for the FIRST connect, default 30s. 0 or Infinity waits forever.
16345
+ * A refused TCP connection is a ws CLOSE, not a dead transport, so without a
16346
+ * deadline `connect()` sat in the 2s reconnect loop and never settled: scripts
16347
+ * hung with no error and `comfy-ts serve` wedged the module behind its mutex.
16348
+ * Reconnects AFTER a successful connect are untouched and still retry forever.
16349
+ */
16350
+ timeoutMs?: number;
16333
16351
  };
16352
+ /** the host never came up within ConnectOptions.timeoutMs */
16353
+ declare class ComfyHostUnreachableError extends Error {
16354
+ /** name, not instanceof: the cli bundle and dist/index.js each define this class */
16355
+ readonly name = "ComfyHostUnreachableError";
16356
+ }
16334
16357
  type SchemaUpdateResult = Maybe<{
16335
16358
  type: 'success';
16336
16359
  } | {
@@ -16448,6 +16471,8 @@ declare class ComfyHost<ID extends string = string> {
16448
16471
  * - 'cache': never fetch (throws when no cache exists)
16449
16472
  */
16450
16473
  connect: (p?: ConnectOptions) => Promise<void>;
16474
+ private _connectTimer;
16475
+ private clearConnectTimer;
16451
16476
  /** close the websocket (e.g. to let a script exit) */
16452
16477
  disconnect: () => void;
16453
16478
  private markReady;
@@ -17331,5 +17356,5 @@ declare function setLoraKeyword(name: string, keyword: string): void;
17331
17356
  */
17332
17357
  declare function loraTag<N extends string = string>(name: N, strength?: number, clipStrength?: number): string;
17333
17358
  //#endregion
17334
- export { AbsolutePath, type ActiveLora, type ActiveLoraSource, type AnyVar, BaseNode, BaseNodeFactory, BaseNodeInputs, BaseNodeOutputs, type BoundVars, Branded, type CanonicalGroup, type CanonicalInput, type CanonicalLink, type CanonicalNode, type CanonicalOutput, type CanonicalWidgetValues, type CanonicalWorkflow, ChoiceVar, type CodegenOptions, type ComfyApiJson, type ComfyApiNodeJson, ComfyExecution, type ComfyExecutionData, type ComfyExecutionStatus, ComfyHost, ComfyHostAuthError, type ComfyHostData, type ComfyHostID, type ComfyImageName, ComfyManager, ComfyNode, type ComfyNodeId, type ComfyNodeIdMode, type ComfyNodeMetadata, ComfyNodeOutput, type ComfyNodeSchemaJSON, ComfySchema, type ComfySchemaJSON, ComfySdkBase, ComfySdkShape, type ComfyStorage, ComfyTS, type ComfyUnionValue, type ComfyUploadImageResult, ComfyUploader, ComfyVar, ComfyVarBase, ComfyWorkflow, ComfyWorkflowBuilder, type ComfyWorkflowData, type ComfyWorkflowID, type ConnectOptions, ConvertibleImageFormat, DEFAULT_IMAGE_EXTENSIONS, DEFAULT_SIZE_PRESETS, type DefineWorkflowSpec, DefinedWorkflow, Either, EmptyRecord, type ExecutionProgress, type ExecutionSnapshot, Flavor, FloatVar, HTMLContent, ImageVar, ImageVarEmptyError, type ImageVarOpts, IntVar, InvalidPromptError, IsEqual, type LiteGraphJSON, type LoraNameOf, type LoraStrength, type LorasHost, LorasVar, MDContent, Maybe, MediaImage, type MediaImageData, type NodeMode, NodeOf, type ParsedHostBase, PartialOmit, type PluginInstallStatus, type PluginSuggestion, type ProgressReport, type PromptID, type PromptRelated_WsMsg, type PromptValue, PromptVar, type QualifiedNodeKey, RelativePath, type Requirements, ResilientWebSocketClient, Result, ResultFailure, type RunSettings, SaveOptions, SdkForHost, SeedVar, type SizePreset, type SizeValue, SizeVar, Tagged, TextVar, ToggleVar, type VarKind, type VarValues, type VarsSpec, WorkflowConvertError, WorkflowNormalizeError, type WsLike, type WsMessageEvent, type WsMsg, __FAIL, __OK, activeLoras, asAbsolutePath, asHTMLContent, asMDContent, asRelativePath, auto, auto_, codegenSDK, convertFlowToLiteGraphJSON, convertLiteGraphToPrompt, createMemoryStorage, getComfyStorage, getLoraKeyword, hostIdToNamespace, loraTag, normalizeWorkflow, number_Timestamp, parseHostBase, parseWorkflowJson, renderHttpBase, renderWsUrl, resultFailure, resultSuccess, setDefaultComfyStorage, setLoraKeyword, v };
17359
+ export { AbsolutePath, type ActiveLora, type ActiveLoraSource, type AnyVar, BaseNode, BaseNodeFactory, BaseNodeInputs, BaseNodeOutputs, type BoundVars, Branded, type CanonicalGroup, type CanonicalInput, type CanonicalLink, type CanonicalNode, type CanonicalOutput, type CanonicalWidgetValues, type CanonicalWorkflow, ChoiceVar, type CodegenOptions, type ComfyApiJson, type ComfyApiNodeJson, ComfyExecution, type ComfyExecutionData, type ComfyExecutionStatus, ComfyHost, ComfyHostAuthError, type ComfyHostData, type ComfyHostID, ComfyHostUnreachableError, type ComfyImageName, ComfyManager, ComfyNode, type ComfyNodeId, type ComfyNodeIdMode, type ComfyNodeMetadata, ComfyNodeOutput, type ComfyNodeSchemaJSON, ComfySchema, type ComfySchemaJSON, ComfySdkBase, ComfySdkShape, type ComfyStorage, ComfyTS, type ComfyUnionValue, type ComfyUploadImageResult, ComfyUploader, ComfyVar, ComfyVarBase, ComfyWorkflow, ComfyWorkflowBuilder, type ComfyWorkflowData, type ComfyWorkflowID, type ConnectOptions, ConvertibleImageFormat, DEFAULT_IMAGE_EXTENSIONS, DEFAULT_SIZE_PRESETS, type DefineWorkflowSpec, DefinedWorkflow, Either, EmptyRecord, type ExecutionProgress, type ExecutionSnapshot, Flavor, FloatVar, HTMLContent, ImageVar, ImageVarEmptyError, type ImageVarOpts, IntVar, InvalidPromptError, IsEqual, type LiteGraphJSON, type LoraNameOf, type LoraStrength, type LorasHost, LorasVar, MDContent, Maybe, MediaImage, type MediaImageData, type NodeMode, NodeOf, type ParsedHostBase, PartialOmit, type PluginInstallStatus, type PluginSuggestion, type ProgressReport, type PromptID, type PromptRelated_WsMsg, type PromptValue, PromptVar, type QualifiedNodeKey, RelativePath, type Requirements, ResilientWebSocketClient, Result, ResultFailure, type RunSettings, SaveOptions, SdkForHost, SeedVar, type SizePreset, type SizeValue, SizeVar, Tagged, TextVar, ToggleVar, type VarKind, type VarValues, type VarsSpec, WorkflowConvertError, WorkflowNormalizeError, type WsLike, type WsMessageEvent, type WsMsg, __FAIL, __OK, activeLoras, asAbsolutePath, asHTMLContent, asMDContent, asRelativePath, auto, auto_, codegenSDK, convertFlowToLiteGraphJSON, convertLiteGraphToPrompt, createMemoryStorage, getComfyStorage, getLoraKeyword, hostIdToNamespace, loraTag, normalizeWorkflow, number_Timestamp, parseHostBase, parseWorkflowJson, renderHttpBase, renderWsUrl, resultFailure, resultSuccess, setDefaultComfyStorage, setLoraKeyword, v };
17335
17360
  //# sourceMappingURL=web.d.ts.map
package/dist/web.js CHANGED
@@ -101,7 +101,7 @@ function getComfyStorage() {
101
101
  }
102
102
  //#endregion
103
103
  //#region package.json
104
- var version = "2.1.0";
104
+ var version = "2.3.0";
105
105
  //#endregion
106
106
  //#region src/litegraph/LiteGraphLinkID.ts
107
107
  const asLiteGraphLinkID = (id) => id;
@@ -1682,6 +1682,15 @@ const localOutputPath = (p) => {
1682
1682
  ].filter((x) => x != null).join("_") + ext;
1683
1683
  return dir === "" ? name : `${dir}/${name}`;
1684
1684
  };
1685
+ /** REPLACE the extension (never append one): a re-encoded save owns its whole
1686
+ * name now that local naming is ours, so `save: {format:'image/webp'}` writes
1687
+ * `shot_20260731-154210_00001.webp`, not `…_00001.png.webp` — appending
1688
+ * described the bytes twice and the first description was a lie */
1689
+ const withExtension = (path, ext) => {
1690
+ const slash = path.lastIndexOf("/");
1691
+ const dot = path.lastIndexOf(".");
1692
+ return `${dot > slash ? path.slice(0, dot) : path}.${ext}`;
1693
+ };
1685
1694
  /**
1686
1695
  * never-overwrite guard: bump `-2`, `-3`, … while the path exists on disk OR
1687
1696
  * was already CLAIMED by a still-downloading retrieval (two same-second runs
@@ -2164,7 +2173,9 @@ var MediaImage = class MediaImage {
2164
2173
  //#endregion
2165
2174
  //#region src/runner/ComfyExecution.ts
2166
2175
  /** paths claimed by in-flight retrievals: two same-second runs on a
2167
- * counter-resetting cloud host compute the same name before either writes */
2176
+ * counter-resetting cloud host compute the same name before either writes.
2177
+ * A claim is released as soon as the write lands (the file itself then holds
2178
+ * the name) or fails (the name is free again) — the set never accumulates */
2168
2179
  const CLAIMED_OUTPUT_PATHS = /* @__PURE__ */ new Set();
2169
2180
  var ComfyExecution = class {
2170
2181
  get host() {
@@ -2291,14 +2302,18 @@ var ComfyExecution = class {
2291
2302
  filename: p.filename,
2292
2303
  timestamp: runTimestamp(new Date(this.startedAt))
2293
2304
  }));
2294
- if (reencode) absPath += "." + bang(p.sf.format).split("/")[1];
2305
+ if (reencode) absPath = withExtension(absPath, bang(bang(p.sf.format).split("/")[1]));
2295
2306
  const storage = getComfyStorage();
2296
2307
  absPath = uniquifyOutputPath({
2297
2308
  path: absPath,
2298
2309
  exists: (x) => storage.exists(x),
2299
2310
  claimed: CLAIMED_OUTPUT_PATHS
2300
2311
  });
2301
- storage.writeBytes(asAbsolutePath(absPath), bytes);
2312
+ try {
2313
+ storage.writeBytes(asAbsolutePath(absPath), bytes);
2314
+ } finally {
2315
+ CLAIMED_OUTPUT_PATHS.delete(absPath);
2316
+ }
2302
2317
  return {
2303
2318
  path: asAbsolutePath(absPath),
2304
2319
  bytes
@@ -4000,7 +4015,7 @@ var PromptVar = class extends ComfyVarBase {
4000
4015
  constructor(defaultValue, promptOpts = {}) {
4001
4016
  super(defaultValue, promptOpts.label);
4002
4017
  this.promptOpts = promptOpts;
4003
- this.kind = "text";
4018
+ this.kind = "prompt";
4004
4019
  }
4005
4020
  parse(raw) {
4006
4021
  this.set(raw);
@@ -4405,6 +4420,7 @@ var ImageVarEmptyError = class extends Error {
4405
4420
  constructor(varName) {
4406
4421
  super(`image var '${varName}' is empty — pick a file (TUI: activate the var; script: .set('/path/to/image.png'))`);
4407
4422
  this.varName = varName;
4423
+ this.name = "ImageVarEmptyError";
4408
4424
  }
4409
4425
  };
4410
4426
  /** trim + expand a leading `~/` — every ImageVar write funnels through this */
@@ -4543,6 +4559,14 @@ var DefinedWorkflow = class {
4543
4559
  };
4544
4560
  //#endregion
4545
4561
  //#region src/host/ComfyHost.ts
4562
+ /** the host never came up within ConnectOptions.timeoutMs */
4563
+ var ComfyHostUnreachableError = class extends Error {
4564
+ constructor(..._args) {
4565
+ super(..._args);
4566
+ this.name = "ComfyHostUnreachableError";
4567
+ }
4568
+ };
4569
+ const DEFAULT_CONNECT_TIMEOUT_MS = 3e4;
4546
4570
  /** auth failure with a SPECIFIC meaning (per the Comfy Cloud error table):
4547
4571
  * 401 invalid/missing key · 402 insufficient credits · 429 subscription inactive
4548
4572
  * (or plain rate limiting on non-cloud hosts). The key value never appears here. */
@@ -4692,14 +4716,25 @@ var ComfyHost = class {
4692
4716
  this._readyResolve = res;
4693
4717
  this._readyReject = rej;
4694
4718
  });
4719
+ const timeoutMs = p.timeoutMs ?? DEFAULT_CONNECT_TIMEOUT_MS;
4720
+ if (timeoutMs > 0 && Number.isFinite(timeoutMs)) {
4721
+ this._connectTimer = setTimeout(() => {
4722
+ this.markFailed(new ComfyHostUnreachableError(`host '${this.data.id}' did not come up within ${timeoutMs}ms at ${this.getWSUrl()} — is ComfyUI running there ?`));
4723
+ }, timeoutMs);
4724
+ this._connectTimer.unref?.();
4725
+ }
4695
4726
  this.initWebsocket();
4696
4727
  }
4697
4728
  return this._ready;
4698
4729
  };
4730
+ this._connectTimer = null;
4699
4731
  this.disconnect = () => {
4732
+ this.clearConnectTimer();
4700
4733
  this.ws?.disconnectPermanently();
4701
4734
  this.ws = null;
4702
4735
  this._ready = null;
4736
+ this._readyResolve = null;
4737
+ this._readyReject = null;
4703
4738
  };
4704
4739
  this.ws = null;
4705
4740
  this._sessionResolve = null;
@@ -4844,15 +4879,26 @@ var ComfyHost = class {
4844
4879
  get isConnected() {
4845
4880
  return this.ws?.isOpen ?? false;
4846
4881
  }
4882
+ clearConnectTimer() {
4883
+ if (this._connectTimer != null) clearTimeout(this._connectTimer);
4884
+ this._connectTimer = null;
4885
+ }
4847
4886
  markReady() {
4887
+ this.clearConnectTimer();
4848
4888
  this._readyResolve?.();
4849
4889
  this._readyResolve = null;
4850
4890
  this._readyReject = null;
4851
4891
  }
4852
4892
  markFailed(error) {
4853
- this._readyReject?.(error);
4893
+ this.clearConnectTimer();
4894
+ const reject = this._readyReject;
4895
+ if (reject == null) return;
4854
4896
  this._readyResolve = null;
4855
4897
  this._readyReject = null;
4898
+ this._ready = null;
4899
+ this.ws?.disconnectPermanently();
4900
+ this.ws = null;
4901
+ reject(error);
4856
4902
  }
4857
4903
  async writeSDKToDisk() {
4858
4904
  if (this.data.sdkAutoWrite === false) return;
@@ -4977,6 +5023,7 @@ var ComfyHost = class {
4977
5023
  mime: frame.mime
4978
5024
  });
4979
5025
  }
5026
+ if (this.latentPreview != null) URL.revokeObjectURL(this.latentPreview.url);
4980
5027
  const imageBlob = new Blob([frame.bytes], { type: frame.mime });
4981
5028
  this.latentPreview = {
4982
5029
  blob: imageBlob,
@@ -5710,6 +5757,6 @@ function loraTag(name, strength = 1, clipStrength) {
5710
5757
  */
5711
5758
  setDefaultComfyStorage(createMemoryStorage());
5712
5759
  //#endregion
5713
- export { ChoiceVar, ComfyExecution, ComfyHost, ComfyHostAuthError, ComfyManager, ComfyNode, ComfyNodeOutput, ComfySchema, ComfyTS, ComfyUploader, ComfyVar, ComfyVarBase, ComfyWorkflow, ComfyWorkflowBuilder, DEFAULT_IMAGE_EXTENSIONS, DEFAULT_SIZE_PRESETS, DefinedWorkflow, FloatVar, ImageVar, ImageVarEmptyError, IntVar, InvalidPromptError, LorasVar, MediaImage, PromptVar, ResilientWebSocketClient, SeedVar, SizeVar, TextVar, ToggleVar, WorkflowConvertError, WorkflowNormalizeError, __FAIL, __OK, activeLoras, asAbsolutePath, asHTMLContent, asMDContent, asRelativePath, auto, auto_, codegenSDK, convertFlowToLiteGraphJSON, convertLiteGraphToPrompt, createMemoryStorage, getComfyStorage, getLoraKeyword, hostIdToNamespace, loraTag, normalizeWorkflow, parseHostBase, parseWorkflowJson, renderHttpBase, renderWsUrl, resultFailure, resultSuccess, setDefaultComfyStorage, setLoraKeyword, v };
5760
+ export { ChoiceVar, ComfyExecution, ComfyHost, ComfyHostAuthError, ComfyHostUnreachableError, ComfyManager, ComfyNode, ComfyNodeOutput, ComfySchema, ComfyTS, ComfyUploader, ComfyVar, ComfyVarBase, ComfyWorkflow, ComfyWorkflowBuilder, DEFAULT_IMAGE_EXTENSIONS, DEFAULT_SIZE_PRESETS, DefinedWorkflow, FloatVar, ImageVar, ImageVarEmptyError, IntVar, InvalidPromptError, LorasVar, MediaImage, PromptVar, ResilientWebSocketClient, SeedVar, SizeVar, TextVar, ToggleVar, WorkflowConvertError, WorkflowNormalizeError, __FAIL, __OK, activeLoras, asAbsolutePath, asHTMLContent, asMDContent, asRelativePath, auto, auto_, codegenSDK, convertFlowToLiteGraphJSON, convertLiteGraphToPrompt, createMemoryStorage, getComfyStorage, getLoraKeyword, hostIdToNamespace, loraTag, normalizeWorkflow, parseHostBase, parseWorkflowJson, renderHttpBase, renderWsUrl, resultFailure, resultSuccess, setDefaultComfyStorage, setLoraKeyword, v };
5714
5761
 
5715
5762
  //# sourceMappingURL=web.js.map