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/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
  /**
@@ -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;
@@ -17344,5 +17369,5 @@ declare function exampleImagePath(name: string): string;
17344
17369
  //#region src/cli/tui-env.d.ts
17345
17370
  declare function isTuiActive(): boolean;
17346
17371
  //#endregion
17347
- 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, exampleImagePath, getComfyStorage, getLoraKeyword, hostIdToNamespace, isTuiActive, loraTag, normalizeWorkflow, number_Timestamp, parseHostBase, parseWorkflowJson, renderHttpBase, renderWsUrl, resultFailure, resultSuccess, setDefaultComfyStorage, setLoraKeyword, v };
17372
+ 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, exampleImagePath, getComfyStorage, getLoraKeyword, hostIdToNamespace, isTuiActive, loraTag, normalizeWorkflow, number_Timestamp, parseHostBase, parseWorkflowJson, renderHttpBase, renderWsUrl, resultFailure, resultSuccess, setDefaultComfyStorage, setLoraKeyword, v };
17348
17373
  //# sourceMappingURL=index.d.cts.map
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
  /**
@@ -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;
@@ -17344,5 +17369,5 @@ declare function exampleImagePath(name: string): string;
17344
17369
  //#region src/cli/tui-env.d.ts
17345
17370
  declare function isTuiActive(): boolean;
17346
17371
  //#endregion
17347
- 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, exampleImagePath, getComfyStorage, getLoraKeyword, hostIdToNamespace, isTuiActive, loraTag, normalizeWorkflow, number_Timestamp, parseHostBase, parseWorkflowJson, renderHttpBase, renderWsUrl, resultFailure, resultSuccess, setDefaultComfyStorage, setLoraKeyword, v };
17372
+ 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, exampleImagePath, getComfyStorage, getLoraKeyword, hostIdToNamespace, isTuiActive, loraTag, normalizeWorkflow, number_Timestamp, parseHostBase, parseWorkflowJson, renderHttpBase, renderWsUrl, resultFailure, resultSuccess, setDefaultComfyStorage, setLoraKeyword, v };
17348
17373
  //# sourceMappingURL=index.d.ts.map
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.1.0";
113
+ var version = "2.3.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 */
@@ -4552,6 +4568,14 @@ var DefinedWorkflow = class {
4552
4568
  };
4553
4569
  //#endregion
4554
4570
  //#region src/host/ComfyHost.ts
4571
+ /** the host never came up within ConnectOptions.timeoutMs */
4572
+ var ComfyHostUnreachableError = class extends Error {
4573
+ constructor(..._args) {
4574
+ super(..._args);
4575
+ this.name = "ComfyHostUnreachableError";
4576
+ }
4577
+ };
4578
+ const DEFAULT_CONNECT_TIMEOUT_MS = 3e4;
4555
4579
  /** auth failure with a SPECIFIC meaning (per the Comfy Cloud error table):
4556
4580
  * 401 invalid/missing key · 402 insufficient credits · 429 subscription inactive
4557
4581
  * (or plain rate limiting on non-cloud hosts). The key value never appears here. */
@@ -4701,14 +4725,25 @@ var ComfyHost = class {
4701
4725
  this._readyResolve = res;
4702
4726
  this._readyReject = rej;
4703
4727
  });
4728
+ const timeoutMs = p.timeoutMs ?? DEFAULT_CONNECT_TIMEOUT_MS;
4729
+ if (timeoutMs > 0 && Number.isFinite(timeoutMs)) {
4730
+ this._connectTimer = setTimeout(() => {
4731
+ this.markFailed(new ComfyHostUnreachableError(`host '${this.data.id}' did not come up within ${timeoutMs}ms at ${this.getWSUrl()} — is ComfyUI running there ?`));
4732
+ }, timeoutMs);
4733
+ this._connectTimer.unref?.();
4734
+ }
4704
4735
  this.initWebsocket();
4705
4736
  }
4706
4737
  return this._ready;
4707
4738
  };
4739
+ this._connectTimer = null;
4708
4740
  this.disconnect = () => {
4741
+ this.clearConnectTimer();
4709
4742
  this.ws?.disconnectPermanently();
4710
4743
  this.ws = null;
4711
4744
  this._ready = null;
4745
+ this._readyResolve = null;
4746
+ this._readyReject = null;
4712
4747
  };
4713
4748
  this.ws = null;
4714
4749
  this._sessionResolve = null;
@@ -4853,15 +4888,26 @@ var ComfyHost = class {
4853
4888
  get isConnected() {
4854
4889
  return this.ws?.isOpen ?? false;
4855
4890
  }
4891
+ clearConnectTimer() {
4892
+ if (this._connectTimer != null) clearTimeout(this._connectTimer);
4893
+ this._connectTimer = null;
4894
+ }
4856
4895
  markReady() {
4896
+ this.clearConnectTimer();
4857
4897
  this._readyResolve?.();
4858
4898
  this._readyResolve = null;
4859
4899
  this._readyReject = null;
4860
4900
  }
4861
4901
  markFailed(error) {
4862
- this._readyReject?.(error);
4902
+ this.clearConnectTimer();
4903
+ const reject = this._readyReject;
4904
+ if (reject == null) return;
4863
4905
  this._readyResolve = null;
4864
4906
  this._readyReject = null;
4907
+ this._ready = null;
4908
+ this.ws?.disconnectPermanently();
4909
+ this.ws = null;
4910
+ reject(error);
4865
4911
  }
4866
4912
  async writeSDKToDisk() {
4867
4913
  if (this.data.sdkAutoWrite === false) return;
@@ -4986,6 +5032,7 @@ var ComfyHost = class {
4986
5032
  mime: frame.mime
4987
5033
  });
4988
5034
  }
5035
+ if (this.latentPreview != null) URL.revokeObjectURL(this.latentPreview.url);
4989
5036
  const imageBlob = new Blob([frame.bytes], { type: frame.mime });
4990
5037
  this.latentPreview = {
4991
5038
  blob: imageBlob,
@@ -5767,6 +5814,6 @@ function isTuiActive() {
5767
5814
  */
5768
5815
  setDefaultComfyStorage(createNodeStorage());
5769
5816
  //#endregion
5770
- 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, exampleImagePath, getComfyStorage, getLoraKeyword, hostIdToNamespace, isTuiActive, loraTag, normalizeWorkflow, parseHostBase, parseWorkflowJson, renderHttpBase, renderWsUrl, resultFailure, resultSuccess, setDefaultComfyStorage, setLoraKeyword, v };
5817
+ 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, exampleImagePath, getComfyStorage, getLoraKeyword, hostIdToNamespace, isTuiActive, loraTag, normalizeWorkflow, parseHostBase, parseWorkflowJson, renderHttpBase, renderWsUrl, resultFailure, resultSuccess, setDefaultComfyStorage, setLoraKeyword, v };
5771
5818
 
5772
5819
  //# sourceMappingURL=index.js.map