comfy-ts 1.2.0 → 1.4.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 (72) hide show
  1. package/README.md +66 -0
  2. package/dist/DefinedWorkflow-C_QAxKr3.js +737 -0
  3. package/dist/DefinedWorkflow-C_QAxKr3.js.map +1 -0
  4. package/dist/DraftsSt-DcOTn0QR.js +434 -0
  5. package/dist/DraftsSt-DcOTn0QR.js.map +1 -0
  6. package/dist/cli.js +15 -5
  7. package/dist/cli.js.map +1 -1
  8. package/dist/index.cjs +476 -202
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.d.cts +98 -40
  11. package/dist/index.d.ts +117 -59
  12. package/dist/index.js +468 -193
  13. package/dist/index.js.map +1 -1
  14. package/dist/run-serve-CN0DhrsA.js +638 -0
  15. package/dist/run-serve-CN0DhrsA.js.map +1 -0
  16. package/dist/{run-tui-BAdizWsO.js → run-tui-bN2hSD5i.js} +250 -447
  17. package/dist/run-tui-bN2hSD5i.js.map +1 -0
  18. package/dist/state-COlKYipO.js +4743 -0
  19. package/dist/state-COlKYipO.js.map +1 -0
  20. package/dist/web.d.ts +17340 -0
  21. package/dist/{state-BYbxDgfr.js → web.js} +1903 -1592
  22. package/dist/web.js.map +1 -0
  23. package/examples/web/example.ts +71 -0
  24. package/examples/web/index.html +77 -0
  25. package/examples/web/serve.ts +42 -0
  26. package/examples/web/tsconfig.json +15 -0
  27. package/package.json +10 -3
  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/StatusBar.tsx +1 -0
  34. package/src/cli/tui/components/TreePanel.tsx +17 -3
  35. package/src/cli/tui/components/TuiApp.tsx +7 -2
  36. package/src/cli/tui/components/VarsPanel.tsx +67 -34
  37. package/src/cli/tui/imageClipboard.ts +39 -0
  38. package/src/cli/tui/listWindow.ts +36 -0
  39. package/src/cli/tui/state/ExecSt.ts +48 -0
  40. package/src/cli/tui/state/TreeSt.ts +25 -0
  41. package/src/cli/tui/state/TuiSt.ts +34 -0
  42. package/src/coreExports.ts +118 -0
  43. package/src/host/ComfyHost.ts +23 -23
  44. package/src/host/ResilientWebsocket.ts +93 -47
  45. package/src/host/hostUrl.ts +2 -1
  46. package/src/host/loraManagerApi.ts +6 -7
  47. package/src/index.ts +8 -107
  48. package/src/litegraph/convertFlowToLiteGraphJSON.ts +11 -7
  49. package/src/manager/loaders/step2_custom-node-list-loader.ts +4 -4
  50. package/src/manager/loaders/step3_extension-node-map-loader.ts +3 -3
  51. package/src/manager/loaders/step4_model-list-loader.ts +7 -7
  52. package/src/manager/loaders/step5_alter-list-loader.ts +2 -2
  53. package/src/manager/loaders/step6_github-stats-loader.ts +2 -2
  54. package/src/runner/ComfyExecution.ts +32 -12
  55. package/src/runner/MediaImage.ts +18 -30
  56. package/src/runner/outputPath.ts +75 -0
  57. package/src/sdk-generator/ComfySchema.ts +2 -2
  58. package/src/sdk-generator/inputWidgetKind.ts +50 -11
  59. package/src/sdk-generator/litegraphToApiRequestPayload.ts +14 -7
  60. package/src/state.ts +13 -9
  61. package/src/storage/ComfyStorage.ts +144 -0
  62. package/src/storage/nodeStorage.ts +9 -0
  63. package/src/utils/downloadFile.ts +11 -69
  64. package/src/utils/hashArrayBuffer.ts +3 -4
  65. package/src/utils/lazySharp.ts +25 -0
  66. package/src/utils/sha1.ts +69 -0
  67. package/src/vars/ComfyVars.ts +13 -6
  68. package/src/vars/loraKeywords.ts +6 -6
  69. package/src/web.ts +13 -0
  70. package/dist/run-tui-BAdizWsO.js.map +0 -1
  71. package/dist/state-BYbxDgfr.js.map +0 -1
  72. package/src/utils/writeFile.ts +0 -16
package/dist/index.d.cts CHANGED
@@ -1,4 +1,3 @@
1
- import WebSocket, { CloseEvent, Event, MessageEvent } from "ws";
2
1
  import { ImageMeta } from "image-meta";
3
2
  import { Sharp } from "sharp";
4
3
  //#region src/manager/generated/KnownComfyPluginTitle.d.ts
@@ -12632,8 +12631,6 @@ declare class MediaImage {
12632
12631
  fn: (sharp: Sharp) => Sharp,
12633
12632
  /** where to save the resulting image */
12634
12633
  path?: AbsolutePath) => Promise<MediaImage>;
12635
- generatePreview: (targetPath: string) => Promise<void>;
12636
- generateMiniPreview: () => Promise<string>;
12637
12634
  }
12638
12635
  //#endregion
12639
12636
  //#region src/runner/ComfyExecution.d.ts
@@ -15788,11 +15785,30 @@ declare function parseHostBase(p: {
15788
15785
  }): ParsedHostBase;
15789
15786
  /** http(s) base, port omitted when it is the scheme default */
15790
15787
  declare function renderHttpBase(p: ParsedHostBase): string;
15791
- /** ws(s) endpoint; auth NEVER rides the query string (headers own it) */
15788
+ /** ws(s) endpoint; auth rides the upgrade headers — EXCEPT headerless
15789
+ * transports (browser), where the ws client remaps X-API-Key to ?token= */
15792
15790
  declare function renderWsUrl(p: ParsedHostBase): string;
15793
15791
  //#endregion
15794
15792
  //#region src/host/ResilientWebsocket.d.ts
15795
- type Message = string | Buffer;
15793
+ type Message = string | Uint8Array;
15794
+ /** structural face of both transports (ws package AND browser WebSocket) */
15795
+ type WsLike = {
15796
+ binaryType: string;
15797
+ onmessage: ((event: WsMessageEvent) => void) | null;
15798
+ onopen: ((event: unknown) => void) | null;
15799
+ onclose: ((event: WsCloseEvent) => void) | null;
15800
+ onerror: ((event: unknown) => void) | null;
15801
+ send(data: Message): void;
15802
+ close(): void;
15803
+ };
15804
+ /** what both transports deliver with binaryType 'arraybuffer': string or ArrayBuffer in `data` */
15805
+ type WsMessageEvent = {
15806
+ data: unknown;
15807
+ };
15808
+ type WsCloseEvent = {
15809
+ code: number;
15810
+ reason: string;
15811
+ };
15796
15812
  type WsDebugMessage = {
15797
15813
  type: 'info' | 'error';
15798
15814
  timestamp: number;
@@ -15801,11 +15817,16 @@ type WsDebugMessage = {
15801
15817
  declare class ResilientWebSocketClient {
15802
15818
  options: {
15803
15819
  url: () => string;
15804
- /** upgrade-request headers (auth: X-API-Key & co) — a thunk, re-read on every reconnect */
15820
+ /** upgrade-request headers (auth: X-API-Key & co) — a thunk, re-read on every reconnect.
15821
+ * On a headerless transport (browser) X-API-Key rides `?token=` instead
15822
+ * (the probed Comfy Cloud contract); other headers throw loud. */
15805
15823
  headers?: () => Record<string, string>;
15806
- onMessage: (event: MessageEvent) => void;
15824
+ onMessage: (event: WsMessageEvent) => void;
15807
15825
  onConnectOrReconnect: () => void;
15808
15826
  onClose: () => void;
15827
+ /** transport unrecoverable (no ws package AND no global WebSocket, or ctor threw):
15828
+ * reported here ONCE, the client goes permanently closed — never a retry storm */
15829
+ onTransportDead?: (error: unknown) => void;
15809
15830
  };
15810
15831
  private url;
15811
15832
  private currentWS?;
@@ -15816,34 +15837,27 @@ declare class ResilientWebSocketClient {
15816
15837
  private addError;
15817
15838
  constructor(options: {
15818
15839
  url: () => string;
15819
- /** upgrade-request headers (auth: X-API-Key & co) — a thunk, re-read on every reconnect */
15840
+ /** upgrade-request headers (auth: X-API-Key & co) — a thunk, re-read on every reconnect.
15841
+ * On a headerless transport (browser) X-API-Key rides `?token=` instead
15842
+ * (the probed Comfy Cloud contract); other headers throw loud. */
15820
15843
  headers?: () => Record<string, string>;
15821
- onMessage: (event: MessageEvent) => void;
15844
+ onMessage: (event: WsMessageEvent) => void;
15822
15845
  onConnectOrReconnect: () => void;
15823
15846
  onClose: () => void;
15847
+ /** transport unrecoverable (no ws package AND no global WebSocket, or ctor threw):
15848
+ * reported here ONCE, the client goes permanently closed — never a retry storm */
15849
+ onTransportDead?: (error: unknown) => void;
15824
15850
  });
15825
15851
  private reconnectTimeout?;
15826
15852
  private permanentlyClosed;
15827
15853
  /** close and stop reconnecting (lets a script exit cleanly) */
15828
15854
  disconnectPermanently(): void;
15855
+ /** headerless transports carry the api key as ?token= — everything else is refused loud */
15856
+ private headerlessUrl;
15829
15857
  private connect;
15830
15858
  send(message: Message): void;
15831
15859
  private flushMessageBuffer;
15832
- /** forward WebSocket add event listeners to the current WebSocket instance */
15833
- addEventListener<K extends keyof WebSocketEventMap>(type: K, listener: ((event: WebSocket.WebSocketEventMap[K]) => void) | {
15834
- handleEvent(event: WebSocket.WebSocketEventMap[K]): void;
15835
- }, options?: WebSocket.EventListenerOptions): void;
15836
- /** forward WebSocket remove event listeners to the current WebSocket instance */
15837
- removeEventListener<K extends keyof WebSocketEventMap>(type: K, listener: ((event: WebSocket.WebSocketEventMap[K]) => void) | {
15838
- handleEvent(event: WebSocket.WebSocketEventMap[K]): void;
15839
- }): void;
15840
15860
  }
15841
- type WebSocketEventMap = {
15842
- open: Event;
15843
- close: CloseEvent;
15844
- error: Event;
15845
- message: MessageEvent;
15846
- };
15847
15861
  //#endregion
15848
15862
  //#region src/vars/ComfyVars.d.ts
15849
15863
  type VarKind = 'text' | 'int' | 'float' | 'seed' | 'toggle' | 'choice' | 'loras' | 'size' | 'image';
@@ -15973,6 +15987,9 @@ declare class SeedVar extends ComfyVar<number> {
15973
15987
  /** move the seed to what the NEXT run should use, per mode */
15974
15988
  advance(): this;
15975
15989
  afterRun(): void;
15990
+ /** mode is part of the seed's state: a reset must not keep a caller's `?`/`+` alive
15991
+ * ('=' is the construction default; drafts restore their own mode via loadJSON) */
15992
+ reset(): this;
15976
15993
  /** parse `+` `- 12` `= 5` `?` or a bare number (=> fixed). Keeps the current number when none given */
15977
15994
  parse(raw: string): boolean;
15978
15995
  display(): string;
@@ -16149,11 +16166,13 @@ declare const v: {
16149
16166
  type AnyVar = {
16150
16167
  readonly kind: VarKind;
16151
16168
  readonly value: unknown;
16169
+ readonly defaultValue: unknown;
16152
16170
  readonly label?: string;
16153
16171
  /** the vars-spec key — DefinedWorkflow writes it at define time */
16154
16172
  name?: string;
16155
16173
  parse(raw: string): boolean;
16156
16174
  loadJSON(value: unknown): unknown;
16175
+ reset(): unknown;
16157
16176
  toJSON(): unknown;
16158
16177
  outValue(): unknown;
16159
16178
  display(): string;
@@ -16256,7 +16275,7 @@ type ComfyHostData = {
16256
16275
  /** extra headers merged into every request + the ws upgrade (Modal-style auth pairs) */
16257
16276
  headers?: Record<string, string>;
16258
16277
  installType?: ComfyInstallType;
16259
- onWsMessageAny?: (e: MessageEvent) => void;
16278
+ onWsMessageAny?: (e: WsMessageEvent) => void;
16260
16279
  onWsMessageArrayBuffer?: (e: ArrayBuffer) => void;
16261
16280
  onWsMessageJSON?: (e: WsMsg) => void;
16262
16281
  };
@@ -16537,7 +16556,7 @@ declare class ComfyHost<ID extends string = string> {
16537
16556
  * sockets keep streaming (a half-open socket receives nothing, so this
16538
16557
  * never revives one) */
16539
16558
  lastWsMessageAt: number | null;
16540
- onMessage(e: MessageEvent): void;
16559
+ onMessage(e: WsMessageEvent): void;
16541
16560
  }
16542
16561
  //#endregion
16543
16562
  //#region src/litegraph/LiteGraphGroup.d.ts
@@ -17021,12 +17040,50 @@ type SdkForHost<ID extends string> = [keyof Comfy.Hosts] extends [never] ? Comfy
17021
17040
  /** the typed node K of host ID (falls back to BaseNode when unknown) */
17022
17041
  type NodeOf<ID extends string, K extends string> = SdkForHost<ID>['Node'] extends (infer N) ? K extends keyof N ? N[K] : BaseNode : BaseNode;
17023
17042
  //#endregion
17043
+ //#region src/storage/ComfyStorage.d.ts
17044
+ type ComfyStorage = {
17045
+ /** backend name, for error messages */
17046
+ kind: string;
17047
+ /** throws when missing */
17048
+ readText(path: string): string;
17049
+ readTextIfExists(path: string): string | null;
17050
+ /** throws when missing */
17051
+ readBytes(path: string): Uint8Array;
17052
+ /** parents are created (mkdirp implied) */
17053
+ writeText(path: string, text: string): void;
17054
+ /** parents are created (mkdirp implied) */
17055
+ writeBytes(path: string, bytes: Uint8Array): void;
17056
+ exists(path: string): boolean;
17057
+ mkdirp(path: string): void;
17058
+ /** file mtime in ms; null when missing */
17059
+ mtimeMs(path: string): number | null;
17060
+ homedir(): string;
17061
+ cwd(): string;
17062
+ };
17063
+ /** in-memory backend: the web default, also handy for hermetic tests.
17064
+ * Paths are LITERAL keys (no normalization — core callers resolve through
17065
+ * pathe/comfyts already). exists() knows written files and EXPLICIT mkdirp
17066
+ * dirs only, never implicit parents. Bytes are copied in AND out so neither
17067
+ * side can mutate the store. */
17068
+ declare function createMemoryStorage(p?: {
17069
+ homedir?: string;
17070
+ cwd?: string;
17071
+ }): ComfyStorage;
17072
+ /** entries call this at import time: index.ts installs node, web.ts memory */
17073
+ declare function setDefaultComfyStorage(storage: ComfyStorage): void;
17074
+ /** the ONE accessor call sites use: the instance's storage when the global
17075
+ * exists, the resolved default otherwise (vars constructed before create()) */
17076
+ declare function getComfyStorage(): ComfyStorage;
17077
+ //#endregion
17024
17078
  //#region src/state.d.ts
17025
17079
  /** singleton */
17026
17080
  declare class ComfyTS {
17027
17081
  version: string;
17082
+ /** the storage seam (architecture item 13): node fs by default, in-memory on web */
17083
+ storage: ComfyStorage;
17028
17084
  constructor(p?: {
17029
17085
  rootPath?: string;
17086
+ storage?: ComfyStorage;
17030
17087
  });
17031
17088
  /**
17032
17089
  * multi-module entrypoint: returns the existing global instance or creates
@@ -17035,6 +17092,7 @@ declare class ComfyTS {
17035
17092
  */
17036
17093
  static create(p?: {
17037
17094
  rootPath?: string;
17095
+ storage?: ComfyStorage;
17038
17096
  }): ComfyTS;
17039
17097
  /** every host created through host(), keyed by id — one instance (and one ws) per id */
17040
17098
  hosts: Map<string, ComfyHost>;
@@ -17048,7 +17106,7 @@ declare class ComfyTS {
17048
17106
  */
17049
17107
  private _registry;
17050
17108
  get registry(): ComfyRegistry;
17051
- /** root path used to resolve things */
17109
+ /** root path used to resolve things (set in the constructor, storage.cwd() default) */
17052
17110
  rootPath: AbsolutePath;
17053
17111
  /**
17054
17112
  * every repo using comfy-ts gets ONE `.comfy-ts/` folder:
@@ -17131,16 +17189,6 @@ type AUTO = Branded<{
17131
17189
  declare const auto: <T>() => T;
17132
17190
  declare const auto_: AUTO;
17133
17191
  //#endregion
17134
- //#region src/exampleAssets.d.ts
17135
- /**
17136
- * absolute path of a bundled `examples/images/` input image, e.g.
17137
- * `exampleImagePath('bear_1024x1024.jpg')` — the out-of-the-box default for
17138
- * i2i/i2v example image vars, valid from this repo AND from a consumer's
17139
- * node_modules/comfy-ts/. Loud throw naming the path when the file is missing
17140
- * or the package's examples/ folder was pruned.
17141
- */
17142
- declare function exampleImagePath(name: string): string;
17143
- //#endregion
17144
17192
  //#region src/litegraph/convertFlowToLiteGraphJSON.d.ts
17145
17193
  declare const convertFlowToLiteGraphJSON: (graph: ComfyWorkflow) => LiteGraphJSON;
17146
17194
  //#endregion
@@ -17278,9 +17326,6 @@ declare function getLoraKeyword(name: string): string;
17278
17326
  /** empty keyword deletes the entry; every set writes the file (tiny, rare) */
17279
17327
  declare function setLoraKeyword(name: string, keyword: string): void;
17280
17328
  //#endregion
17281
- //#region src/cli/tui-env.d.ts
17282
- declare function isTuiActive(): boolean;
17283
- //#endregion
17284
17329
  //#region src/utils/loraTag.d.ts
17285
17330
  /**
17286
17331
  * build a LoraManager-style lora tag: `<lora:name:strength>` or
@@ -17291,5 +17336,18 @@ declare function isTuiActive(): boolean;
17291
17336
  */
17292
17337
  declare function loraTag<N extends string = string>(name: N, strength?: number, clipStrength?: number): string;
17293
17338
  //#endregion
17294
- 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, 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, ImageSaveFormat, 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, SdkForHost, SeedVar, type SizePreset, type SizeValue, SizeVar, Tagged, TextVar, ToggleVar, type VarKind, type VarValues, type VarsSpec, WorkflowConvertError, WorkflowNormalizeError, type WsMsg, __FAIL, __OK, activeLoras, asAbsolutePath, asHTMLContent, asMDContent, asRelativePath, auto, auto_, codegenSDK, convertFlowToLiteGraphJSON, convertLiteGraphToPrompt, exampleImagePath, getLoraKeyword, hostIdToNamespace, isTuiActive, loraTag, normalizeWorkflow, number_Timestamp, parseHostBase, parseWorkflowJson, renderHttpBase, renderWsUrl, resultFailure, resultSuccess, setLoraKeyword, v };
17339
+ //#region src/exampleAssets.d.ts
17340
+ /**
17341
+ * absolute path of a bundled `examples/images/` input image, e.g.
17342
+ * `exampleImagePath('bear_1024x1024.jpg')` — the out-of-the-box default for
17343
+ * i2i/i2v example image vars, valid from this repo AND from a consumer's
17344
+ * node_modules/comfy-ts/. Loud throw naming the path when the file is missing
17345
+ * or the package's examples/ folder was pruned.
17346
+ */
17347
+ declare function exampleImagePath(name: string): string;
17348
+ //#endregion
17349
+ //#region src/cli/tui-env.d.ts
17350
+ declare function isTuiActive(): boolean;
17351
+ //#endregion
17352
+ 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, ImageSaveFormat, 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, 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 };
17295
17353
  //# sourceMappingURL=index.d.cts.map
package/dist/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
- import { Sharp } from "sharp";
2
1
  import { ImageMeta } from "image-meta";
3
- import WebSocket, { CloseEvent, Event, MessageEvent } from "ws";
2
+ import { Sharp } from "sharp";
4
3
  //#region src/manager/generated/KnownComfyPluginTitle.d.ts
5
4
  type KnownComfyPluginTitle =
6
5
  /** ComfyUI-Light-N-Color - https://github.com/KAVVATARE/ComfyUI-Light-N-Color */
@@ -11897,16 +11896,9 @@ declare const types$1: import("arktype").Module<{
11897
11896
  };
11898
11897
  PromptID: PromptID;
11899
11898
  PromptRelated_WsMsg: {
11900
- type: "progress";
11901
- data: {
11902
- value: number;
11903
- max: number;
11904
- };
11905
- } | {
11906
- type: "executing";
11899
+ type: "execution_start";
11907
11900
  data: {
11908
11901
  prompt_id: PromptID;
11909
- node?: ComfyNodeId | null | undefined;
11910
11902
  };
11911
11903
  } | {
11912
11904
  type: "execution_cached";
@@ -11915,9 +11907,16 @@ declare const types$1: import("arktype").Module<{
11915
11907
  prompt_id: PromptID;
11916
11908
  };
11917
11909
  } | {
11918
- type: "execution_start";
11910
+ type: "executing";
11919
11911
  data: {
11920
11912
  prompt_id: PromptID;
11913
+ node?: ComfyNodeId | null | undefined;
11914
+ };
11915
+ } | {
11916
+ type: "progress";
11917
+ data: {
11918
+ value: number;
11919
+ max: number;
11921
11920
  };
11922
11921
  } | {
11923
11922
  type: "progress_state";
@@ -11972,16 +11971,9 @@ declare const types$1: import("arktype").Module<{
11972
11971
  data: string;
11973
11972
  };
11974
11973
  WsMsg: {
11975
- type: "progress";
11976
- data: {
11977
- value: number;
11978
- max: number;
11979
- };
11980
- } | {
11981
- type: "executing";
11974
+ type: "execution_start";
11982
11975
  data: {
11983
11976
  prompt_id: PromptID;
11984
- node?: ComfyNodeId | null | undefined;
11985
11977
  };
11986
11978
  } | {
11987
11979
  type: "execution_cached";
@@ -11990,9 +11982,16 @@ declare const types$1: import("arktype").Module<{
11990
11982
  prompt_id: PromptID;
11991
11983
  };
11992
11984
  } | {
11993
- type: "execution_start";
11985
+ type: "executing";
11994
11986
  data: {
11995
11987
  prompt_id: PromptID;
11988
+ node?: ComfyNodeId | null | undefined;
11989
+ };
11990
+ } | {
11991
+ type: "progress";
11992
+ data: {
11993
+ value: number;
11994
+ max: number;
11996
11995
  };
11997
11996
  } | {
11998
11997
  type: "progress_state";
@@ -12632,8 +12631,6 @@ declare class MediaImage {
12632
12631
  fn: (sharp: Sharp) => Sharp,
12633
12632
  /** where to save the resulting image */
12634
12633
  path?: AbsolutePath) => Promise<MediaImage>;
12635
- generatePreview: (targetPath: string) => Promise<void>;
12636
- generateMiniPreview: () => Promise<string>;
12637
12634
  }
12638
12635
  //#endregion
12639
12636
  //#region src/runner/ComfyExecution.d.ts
@@ -15788,11 +15785,30 @@ declare function parseHostBase(p: {
15788
15785
  }): ParsedHostBase;
15789
15786
  /** http(s) base, port omitted when it is the scheme default */
15790
15787
  declare function renderHttpBase(p: ParsedHostBase): string;
15791
- /** ws(s) endpoint; auth NEVER rides the query string (headers own it) */
15788
+ /** ws(s) endpoint; auth rides the upgrade headers — EXCEPT headerless
15789
+ * transports (browser), where the ws client remaps X-API-Key to ?token= */
15792
15790
  declare function renderWsUrl(p: ParsedHostBase): string;
15793
15791
  //#endregion
15794
15792
  //#region src/host/ResilientWebsocket.d.ts
15795
- type Message = string | Buffer;
15793
+ type Message = string | Uint8Array;
15794
+ /** structural face of both transports (ws package AND browser WebSocket) */
15795
+ type WsLike = {
15796
+ binaryType: string;
15797
+ onmessage: ((event: WsMessageEvent) => void) | null;
15798
+ onopen: ((event: unknown) => void) | null;
15799
+ onclose: ((event: WsCloseEvent) => void) | null;
15800
+ onerror: ((event: unknown) => void) | null;
15801
+ send(data: Message): void;
15802
+ close(): void;
15803
+ };
15804
+ /** what both transports deliver with binaryType 'arraybuffer': string or ArrayBuffer in `data` */
15805
+ type WsMessageEvent = {
15806
+ data: unknown;
15807
+ };
15808
+ type WsCloseEvent = {
15809
+ code: number;
15810
+ reason: string;
15811
+ };
15796
15812
  type WsDebugMessage = {
15797
15813
  type: 'info' | 'error';
15798
15814
  timestamp: number;
@@ -15801,11 +15817,16 @@ type WsDebugMessage = {
15801
15817
  declare class ResilientWebSocketClient {
15802
15818
  options: {
15803
15819
  url: () => string;
15804
- /** upgrade-request headers (auth: X-API-Key & co) — a thunk, re-read on every reconnect */
15820
+ /** upgrade-request headers (auth: X-API-Key & co) — a thunk, re-read on every reconnect.
15821
+ * On a headerless transport (browser) X-API-Key rides `?token=` instead
15822
+ * (the probed Comfy Cloud contract); other headers throw loud. */
15805
15823
  headers?: () => Record<string, string>;
15806
- onMessage: (event: MessageEvent) => void;
15824
+ onMessage: (event: WsMessageEvent) => void;
15807
15825
  onConnectOrReconnect: () => void;
15808
15826
  onClose: () => void;
15827
+ /** transport unrecoverable (no ws package AND no global WebSocket, or ctor threw):
15828
+ * reported here ONCE, the client goes permanently closed — never a retry storm */
15829
+ onTransportDead?: (error: unknown) => void;
15809
15830
  };
15810
15831
  private url;
15811
15832
  private currentWS?;
@@ -15816,34 +15837,27 @@ declare class ResilientWebSocketClient {
15816
15837
  private addError;
15817
15838
  constructor(options: {
15818
15839
  url: () => string;
15819
- /** upgrade-request headers (auth: X-API-Key & co) — a thunk, re-read on every reconnect */
15840
+ /** upgrade-request headers (auth: X-API-Key & co) — a thunk, re-read on every reconnect.
15841
+ * On a headerless transport (browser) X-API-Key rides `?token=` instead
15842
+ * (the probed Comfy Cloud contract); other headers throw loud. */
15820
15843
  headers?: () => Record<string, string>;
15821
- onMessage: (event: MessageEvent) => void;
15844
+ onMessage: (event: WsMessageEvent) => void;
15822
15845
  onConnectOrReconnect: () => void;
15823
15846
  onClose: () => void;
15847
+ /** transport unrecoverable (no ws package AND no global WebSocket, or ctor threw):
15848
+ * reported here ONCE, the client goes permanently closed — never a retry storm */
15849
+ onTransportDead?: (error: unknown) => void;
15824
15850
  });
15825
15851
  private reconnectTimeout?;
15826
15852
  private permanentlyClosed;
15827
15853
  /** close and stop reconnecting (lets a script exit cleanly) */
15828
15854
  disconnectPermanently(): void;
15855
+ /** headerless transports carry the api key as ?token= — everything else is refused loud */
15856
+ private headerlessUrl;
15829
15857
  private connect;
15830
15858
  send(message: Message): void;
15831
15859
  private flushMessageBuffer;
15832
- /** forward WebSocket add event listeners to the current WebSocket instance */
15833
- addEventListener<K extends keyof WebSocketEventMap>(type: K, listener: ((event: WebSocket.WebSocketEventMap[K]) => void) | {
15834
- handleEvent(event: WebSocket.WebSocketEventMap[K]): void;
15835
- }, options?: WebSocket.EventListenerOptions): void;
15836
- /** forward WebSocket remove event listeners to the current WebSocket instance */
15837
- removeEventListener<K extends keyof WebSocketEventMap>(type: K, listener: ((event: WebSocket.WebSocketEventMap[K]) => void) | {
15838
- handleEvent(event: WebSocket.WebSocketEventMap[K]): void;
15839
- }): void;
15840
15860
  }
15841
- type WebSocketEventMap = {
15842
- open: Event;
15843
- close: CloseEvent;
15844
- error: Event;
15845
- message: MessageEvent;
15846
- };
15847
15861
  //#endregion
15848
15862
  //#region src/vars/ComfyVars.d.ts
15849
15863
  type VarKind = 'text' | 'int' | 'float' | 'seed' | 'toggle' | 'choice' | 'loras' | 'size' | 'image';
@@ -15973,6 +15987,9 @@ declare class SeedVar extends ComfyVar<number> {
15973
15987
  /** move the seed to what the NEXT run should use, per mode */
15974
15988
  advance(): this;
15975
15989
  afterRun(): void;
15990
+ /** mode is part of the seed's state: a reset must not keep a caller's `?`/`+` alive
15991
+ * ('=' is the construction default; drafts restore their own mode via loadJSON) */
15992
+ reset(): this;
15976
15993
  /** parse `+` `- 12` `= 5` `?` or a bare number (=> fixed). Keeps the current number when none given */
15977
15994
  parse(raw: string): boolean;
15978
15995
  display(): string;
@@ -16149,11 +16166,13 @@ declare const v: {
16149
16166
  type AnyVar = {
16150
16167
  readonly kind: VarKind;
16151
16168
  readonly value: unknown;
16169
+ readonly defaultValue: unknown;
16152
16170
  readonly label?: string;
16153
16171
  /** the vars-spec key — DefinedWorkflow writes it at define time */
16154
16172
  name?: string;
16155
16173
  parse(raw: string): boolean;
16156
16174
  loadJSON(value: unknown): unknown;
16175
+ reset(): unknown;
16157
16176
  toJSON(): unknown;
16158
16177
  outValue(): unknown;
16159
16178
  display(): string;
@@ -16256,7 +16275,7 @@ type ComfyHostData = {
16256
16275
  /** extra headers merged into every request + the ws upgrade (Modal-style auth pairs) */
16257
16276
  headers?: Record<string, string>;
16258
16277
  installType?: ComfyInstallType;
16259
- onWsMessageAny?: (e: MessageEvent) => void;
16278
+ onWsMessageAny?: (e: WsMessageEvent) => void;
16260
16279
  onWsMessageArrayBuffer?: (e: ArrayBuffer) => void;
16261
16280
  onWsMessageJSON?: (e: WsMsg) => void;
16262
16281
  };
@@ -16537,7 +16556,7 @@ declare class ComfyHost<ID extends string = string> {
16537
16556
  * sockets keep streaming (a half-open socket receives nothing, so this
16538
16557
  * never revives one) */
16539
16558
  lastWsMessageAt: number | null;
16540
- onMessage(e: MessageEvent): void;
16559
+ onMessage(e: WsMessageEvent): void;
16541
16560
  }
16542
16561
  //#endregion
16543
16562
  //#region src/litegraph/LiteGraphGroup.d.ts
@@ -17021,12 +17040,50 @@ type SdkForHost<ID extends string> = [keyof Comfy.Hosts] extends [never] ? Comfy
17021
17040
  /** the typed node K of host ID (falls back to BaseNode when unknown) */
17022
17041
  type NodeOf<ID extends string, K extends string> = SdkForHost<ID>['Node'] extends (infer N) ? K extends keyof N ? N[K] : BaseNode : BaseNode;
17023
17042
  //#endregion
17043
+ //#region src/storage/ComfyStorage.d.ts
17044
+ type ComfyStorage = {
17045
+ /** backend name, for error messages */
17046
+ kind: string;
17047
+ /** throws when missing */
17048
+ readText(path: string): string;
17049
+ readTextIfExists(path: string): string | null;
17050
+ /** throws when missing */
17051
+ readBytes(path: string): Uint8Array;
17052
+ /** parents are created (mkdirp implied) */
17053
+ writeText(path: string, text: string): void;
17054
+ /** parents are created (mkdirp implied) */
17055
+ writeBytes(path: string, bytes: Uint8Array): void;
17056
+ exists(path: string): boolean;
17057
+ mkdirp(path: string): void;
17058
+ /** file mtime in ms; null when missing */
17059
+ mtimeMs(path: string): number | null;
17060
+ homedir(): string;
17061
+ cwd(): string;
17062
+ };
17063
+ /** in-memory backend: the web default, also handy for hermetic tests.
17064
+ * Paths are LITERAL keys (no normalization — core callers resolve through
17065
+ * pathe/comfyts already). exists() knows written files and EXPLICIT mkdirp
17066
+ * dirs only, never implicit parents. Bytes are copied in AND out so neither
17067
+ * side can mutate the store. */
17068
+ declare function createMemoryStorage(p?: {
17069
+ homedir?: string;
17070
+ cwd?: string;
17071
+ }): ComfyStorage;
17072
+ /** entries call this at import time: index.ts installs node, web.ts memory */
17073
+ declare function setDefaultComfyStorage(storage: ComfyStorage): void;
17074
+ /** the ONE accessor call sites use: the instance's storage when the global
17075
+ * exists, the resolved default otherwise (vars constructed before create()) */
17076
+ declare function getComfyStorage(): ComfyStorage;
17077
+ //#endregion
17024
17078
  //#region src/state.d.ts
17025
17079
  /** singleton */
17026
17080
  declare class ComfyTS {
17027
17081
  version: string;
17082
+ /** the storage seam (architecture item 13): node fs by default, in-memory on web */
17083
+ storage: ComfyStorage;
17028
17084
  constructor(p?: {
17029
17085
  rootPath?: string;
17086
+ storage?: ComfyStorage;
17030
17087
  });
17031
17088
  /**
17032
17089
  * multi-module entrypoint: returns the existing global instance or creates
@@ -17035,6 +17092,7 @@ declare class ComfyTS {
17035
17092
  */
17036
17093
  static create(p?: {
17037
17094
  rootPath?: string;
17095
+ storage?: ComfyStorage;
17038
17096
  }): ComfyTS;
17039
17097
  /** every host created through host(), keyed by id — one instance (and one ws) per id */
17040
17098
  hosts: Map<string, ComfyHost>;
@@ -17048,7 +17106,7 @@ declare class ComfyTS {
17048
17106
  */
17049
17107
  private _registry;
17050
17108
  get registry(): ComfyRegistry;
17051
- /** root path used to resolve things */
17109
+ /** root path used to resolve things (set in the constructor, storage.cwd() default) */
17052
17110
  rootPath: AbsolutePath;
17053
17111
  /**
17054
17112
  * every repo using comfy-ts gets ONE `.comfy-ts/` folder:
@@ -17131,16 +17189,6 @@ type AUTO = Branded<{
17131
17189
  declare const auto: <T>() => T;
17132
17190
  declare const auto_: AUTO;
17133
17191
  //#endregion
17134
- //#region src/exampleAssets.d.ts
17135
- /**
17136
- * absolute path of a bundled `examples/images/` input image, e.g.
17137
- * `exampleImagePath('bear_1024x1024.jpg')` — the out-of-the-box default for
17138
- * i2i/i2v example image vars, valid from this repo AND from a consumer's
17139
- * node_modules/comfy-ts/. Loud throw naming the path when the file is missing
17140
- * or the package's examples/ folder was pruned.
17141
- */
17142
- declare function exampleImagePath(name: string): string;
17143
- //#endregion
17144
17192
  //#region src/litegraph/convertFlowToLiteGraphJSON.d.ts
17145
17193
  declare const convertFlowToLiteGraphJSON: (graph: ComfyWorkflow) => LiteGraphJSON;
17146
17194
  //#endregion
@@ -17278,9 +17326,6 @@ declare function getLoraKeyword(name: string): string;
17278
17326
  /** empty keyword deletes the entry; every set writes the file (tiny, rare) */
17279
17327
  declare function setLoraKeyword(name: string, keyword: string): void;
17280
17328
  //#endregion
17281
- //#region src/cli/tui-env.d.ts
17282
- declare function isTuiActive(): boolean;
17283
- //#endregion
17284
17329
  //#region src/utils/loraTag.d.ts
17285
17330
  /**
17286
17331
  * build a LoraManager-style lora tag: `<lora:name:strength>` or
@@ -17291,5 +17336,18 @@ declare function isTuiActive(): boolean;
17291
17336
  */
17292
17337
  declare function loraTag<N extends string = string>(name: N, strength?: number, clipStrength?: number): string;
17293
17338
  //#endregion
17294
- 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, 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, ImageSaveFormat, 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, SdkForHost, SeedVar, type SizePreset, type SizeValue, SizeVar, Tagged, TextVar, ToggleVar, type VarKind, type VarValues, type VarsSpec, WorkflowConvertError, WorkflowNormalizeError, type WsMsg, __FAIL, __OK, activeLoras, asAbsolutePath, asHTMLContent, asMDContent, asRelativePath, auto, auto_, codegenSDK, convertFlowToLiteGraphJSON, convertLiteGraphToPrompt, exampleImagePath, getLoraKeyword, hostIdToNamespace, isTuiActive, loraTag, normalizeWorkflow, number_Timestamp, parseHostBase, parseWorkflowJson, renderHttpBase, renderWsUrl, resultFailure, resultSuccess, setLoraKeyword, v };
17339
+ //#region src/exampleAssets.d.ts
17340
+ /**
17341
+ * absolute path of a bundled `examples/images/` input image, e.g.
17342
+ * `exampleImagePath('bear_1024x1024.jpg')` — the out-of-the-box default for
17343
+ * i2i/i2v example image vars, valid from this repo AND from a consumer's
17344
+ * node_modules/comfy-ts/. Loud throw naming the path when the file is missing
17345
+ * or the package's examples/ folder was pruned.
17346
+ */
17347
+ declare function exampleImagePath(name: string): string;
17348
+ //#endregion
17349
+ //#region src/cli/tui-env.d.ts
17350
+ declare function isTuiActive(): boolean;
17351
+ //#endregion
17352
+ 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, ImageSaveFormat, 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, 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 };
17295
17353
  //# sourceMappingURL=index.d.ts.map