comfy-ts 1.3.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 (53) hide show
  1. package/README.md +26 -0
  2. package/dist/{DefinedWorkflow-gpknV-5f.js → DefinedWorkflow-C_QAxKr3.js} +64 -13
  3. package/dist/DefinedWorkflow-C_QAxKr3.js.map +1 -0
  4. package/dist/{DraftsSt-DmA0jWGl.js → DraftsSt-DcOTn0QR.js} +2 -2
  5. package/dist/{DraftsSt-DmA0jWGl.js.map → DraftsSt-DcOTn0QR.js.map} +1 -1
  6. package/dist/cli.js +3 -3
  7. package/dist/index.cjs +346 -183
  8. package/dist/index.cjs.map +1 -1
  9. package/dist/index.d.cts +93 -40
  10. package/dist/index.d.ts +94 -41
  11. package/dist/index.js +338 -174
  12. package/dist/index.js.map +1 -1
  13. package/dist/{run-serve-Bn6yIJB0.js → run-serve-CN0DhrsA.js} +3 -3
  14. package/dist/{run-serve-Bn6yIJB0.js.map → run-serve-CN0DhrsA.js.map} +1 -1
  15. package/dist/{run-tui-BtjaOXRh.js → run-tui-bN2hSD5i.js} +10 -11
  16. package/dist/{run-tui-BtjaOXRh.js.map → run-tui-bN2hSD5i.js.map} +1 -1
  17. package/dist/{state-DKCPy105.js → state-COlKYipO.js} +199 -146
  18. package/dist/state-COlKYipO.js.map +1 -0
  19. package/dist/web.d.ts +17340 -0
  20. package/dist/web.js +5569 -0
  21. package/dist/web.js.map +1 -0
  22. package/examples/web/example.ts +71 -0
  23. package/examples/web/index.html +77 -0
  24. package/examples/web/serve.ts +42 -0
  25. package/examples/web/tsconfig.json +15 -0
  26. package/package.json +8 -2
  27. package/src/coreExports.ts +118 -0
  28. package/src/host/ComfyHost.ts +23 -23
  29. package/src/host/ResilientWebsocket.ts +93 -47
  30. package/src/host/hostUrl.ts +2 -1
  31. package/src/host/loraManagerApi.ts +6 -7
  32. package/src/index.ts +8 -107
  33. package/src/manager/loaders/step2_custom-node-list-loader.ts +4 -4
  34. package/src/manager/loaders/step3_extension-node-map-loader.ts +3 -3
  35. package/src/manager/loaders/step4_model-list-loader.ts +7 -7
  36. package/src/manager/loaders/step5_alter-list-loader.ts +2 -2
  37. package/src/manager/loaders/step6_github-stats-loader.ts +2 -2
  38. package/src/runner/ComfyExecution.ts +14 -11
  39. package/src/runner/MediaImage.ts +18 -30
  40. package/src/sdk-generator/ComfySchema.ts +2 -2
  41. package/src/state.ts +13 -9
  42. package/src/storage/ComfyStorage.ts +144 -0
  43. package/src/storage/nodeStorage.ts +9 -0
  44. package/src/utils/downloadFile.ts +11 -69
  45. package/src/utils/hashArrayBuffer.ts +3 -4
  46. package/src/utils/lazySharp.ts +25 -0
  47. package/src/utils/sha1.ts +69 -0
  48. package/src/vars/ComfyVars.ts +5 -6
  49. package/src/vars/loraKeywords.ts +6 -6
  50. package/src/web.ts +13 -0
  51. package/dist/DefinedWorkflow-gpknV-5f.js.map +0 -1
  52. package/dist/state-DKCPy105.js.map +0 -1
  53. 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';
@@ -16261,7 +16275,7 @@ type ComfyHostData = {
16261
16275
  /** extra headers merged into every request + the ws upgrade (Modal-style auth pairs) */
16262
16276
  headers?: Record<string, string>;
16263
16277
  installType?: ComfyInstallType;
16264
- onWsMessageAny?: (e: MessageEvent) => void;
16278
+ onWsMessageAny?: (e: WsMessageEvent) => void;
16265
16279
  onWsMessageArrayBuffer?: (e: ArrayBuffer) => void;
16266
16280
  onWsMessageJSON?: (e: WsMsg) => void;
16267
16281
  };
@@ -16542,7 +16556,7 @@ declare class ComfyHost<ID extends string = string> {
16542
16556
  * sockets keep streaming (a half-open socket receives nothing, so this
16543
16557
  * never revives one) */
16544
16558
  lastWsMessageAt: number | null;
16545
- onMessage(e: MessageEvent): void;
16559
+ onMessage(e: WsMessageEvent): void;
16546
16560
  }
16547
16561
  //#endregion
16548
16562
  //#region src/litegraph/LiteGraphGroup.d.ts
@@ -17026,12 +17040,50 @@ type SdkForHost<ID extends string> = [keyof Comfy.Hosts] extends [never] ? Comfy
17026
17040
  /** the typed node K of host ID (falls back to BaseNode when unknown) */
17027
17041
  type NodeOf<ID extends string, K extends string> = SdkForHost<ID>['Node'] extends (infer N) ? K extends keyof N ? N[K] : BaseNode : BaseNode;
17028
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
17029
17078
  //#region src/state.d.ts
17030
17079
  /** singleton */
17031
17080
  declare class ComfyTS {
17032
17081
  version: string;
17082
+ /** the storage seam (architecture item 13): node fs by default, in-memory on web */
17083
+ storage: ComfyStorage;
17033
17084
  constructor(p?: {
17034
17085
  rootPath?: string;
17086
+ storage?: ComfyStorage;
17035
17087
  });
17036
17088
  /**
17037
17089
  * multi-module entrypoint: returns the existing global instance or creates
@@ -17040,6 +17092,7 @@ declare class ComfyTS {
17040
17092
  */
17041
17093
  static create(p?: {
17042
17094
  rootPath?: string;
17095
+ storage?: ComfyStorage;
17043
17096
  }): ComfyTS;
17044
17097
  /** every host created through host(), keyed by id — one instance (and one ws) per id */
17045
17098
  hosts: Map<string, ComfyHost>;
@@ -17053,7 +17106,7 @@ declare class ComfyTS {
17053
17106
  */
17054
17107
  private _registry;
17055
17108
  get registry(): ComfyRegistry;
17056
- /** root path used to resolve things */
17109
+ /** root path used to resolve things (set in the constructor, storage.cwd() default) */
17057
17110
  rootPath: AbsolutePath;
17058
17111
  /**
17059
17112
  * every repo using comfy-ts gets ONE `.comfy-ts/` folder:
@@ -17136,16 +17189,6 @@ type AUTO = Branded<{
17136
17189
  declare const auto: <T>() => T;
17137
17190
  declare const auto_: AUTO;
17138
17191
  //#endregion
17139
- //#region src/exampleAssets.d.ts
17140
- /**
17141
- * absolute path of a bundled `examples/images/` input image, e.g.
17142
- * `exampleImagePath('bear_1024x1024.jpg')` — the out-of-the-box default for
17143
- * i2i/i2v example image vars, valid from this repo AND from a consumer's
17144
- * node_modules/comfy-ts/. Loud throw naming the path when the file is missing
17145
- * or the package's examples/ folder was pruned.
17146
- */
17147
- declare function exampleImagePath(name: string): string;
17148
- //#endregion
17149
17192
  //#region src/litegraph/convertFlowToLiteGraphJSON.d.ts
17150
17193
  declare const convertFlowToLiteGraphJSON: (graph: ComfyWorkflow) => LiteGraphJSON;
17151
17194
  //#endregion
@@ -17283,9 +17326,6 @@ declare function getLoraKeyword(name: string): string;
17283
17326
  /** empty keyword deletes the entry; every set writes the file (tiny, rare) */
17284
17327
  declare function setLoraKeyword(name: string, keyword: string): void;
17285
17328
  //#endregion
17286
- //#region src/cli/tui-env.d.ts
17287
- declare function isTuiActive(): boolean;
17288
- //#endregion
17289
17329
  //#region src/utils/loraTag.d.ts
17290
17330
  /**
17291
17331
  * build a LoraManager-style lora tag: `<lora:name:strength>` or
@@ -17296,5 +17336,18 @@ declare function isTuiActive(): boolean;
17296
17336
  */
17297
17337
  declare function loraTag<N extends string = string>(name: N, strength?: number, clipStrength?: number): string;
17298
17338
  //#endregion
17299
- 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 };
17300
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 */
@@ -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';
@@ -16261,7 +16275,7 @@ type ComfyHostData = {
16261
16275
  /** extra headers merged into every request + the ws upgrade (Modal-style auth pairs) */
16262
16276
  headers?: Record<string, string>;
16263
16277
  installType?: ComfyInstallType;
16264
- onWsMessageAny?: (e: MessageEvent) => void;
16278
+ onWsMessageAny?: (e: WsMessageEvent) => void;
16265
16279
  onWsMessageArrayBuffer?: (e: ArrayBuffer) => void;
16266
16280
  onWsMessageJSON?: (e: WsMsg) => void;
16267
16281
  };
@@ -16542,7 +16556,7 @@ declare class ComfyHost<ID extends string = string> {
16542
16556
  * sockets keep streaming (a half-open socket receives nothing, so this
16543
16557
  * never revives one) */
16544
16558
  lastWsMessageAt: number | null;
16545
- onMessage(e: MessageEvent): void;
16559
+ onMessage(e: WsMessageEvent): void;
16546
16560
  }
16547
16561
  //#endregion
16548
16562
  //#region src/litegraph/LiteGraphGroup.d.ts
@@ -17026,12 +17040,50 @@ type SdkForHost<ID extends string> = [keyof Comfy.Hosts] extends [never] ? Comfy
17026
17040
  /** the typed node K of host ID (falls back to BaseNode when unknown) */
17027
17041
  type NodeOf<ID extends string, K extends string> = SdkForHost<ID>['Node'] extends (infer N) ? K extends keyof N ? N[K] : BaseNode : BaseNode;
17028
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
17029
17078
  //#region src/state.d.ts
17030
17079
  /** singleton */
17031
17080
  declare class ComfyTS {
17032
17081
  version: string;
17082
+ /** the storage seam (architecture item 13): node fs by default, in-memory on web */
17083
+ storage: ComfyStorage;
17033
17084
  constructor(p?: {
17034
17085
  rootPath?: string;
17086
+ storage?: ComfyStorage;
17035
17087
  });
17036
17088
  /**
17037
17089
  * multi-module entrypoint: returns the existing global instance or creates
@@ -17040,6 +17092,7 @@ declare class ComfyTS {
17040
17092
  */
17041
17093
  static create(p?: {
17042
17094
  rootPath?: string;
17095
+ storage?: ComfyStorage;
17043
17096
  }): ComfyTS;
17044
17097
  /** every host created through host(), keyed by id — one instance (and one ws) per id */
17045
17098
  hosts: Map<string, ComfyHost>;
@@ -17053,7 +17106,7 @@ declare class ComfyTS {
17053
17106
  */
17054
17107
  private _registry;
17055
17108
  get registry(): ComfyRegistry;
17056
- /** root path used to resolve things */
17109
+ /** root path used to resolve things (set in the constructor, storage.cwd() default) */
17057
17110
  rootPath: AbsolutePath;
17058
17111
  /**
17059
17112
  * every repo using comfy-ts gets ONE `.comfy-ts/` folder:
@@ -17136,16 +17189,6 @@ type AUTO = Branded<{
17136
17189
  declare const auto: <T>() => T;
17137
17190
  declare const auto_: AUTO;
17138
17191
  //#endregion
17139
- //#region src/exampleAssets.d.ts
17140
- /**
17141
- * absolute path of a bundled `examples/images/` input image, e.g.
17142
- * `exampleImagePath('bear_1024x1024.jpg')` — the out-of-the-box default for
17143
- * i2i/i2v example image vars, valid from this repo AND from a consumer's
17144
- * node_modules/comfy-ts/. Loud throw naming the path when the file is missing
17145
- * or the package's examples/ folder was pruned.
17146
- */
17147
- declare function exampleImagePath(name: string): string;
17148
- //#endregion
17149
17192
  //#region src/litegraph/convertFlowToLiteGraphJSON.d.ts
17150
17193
  declare const convertFlowToLiteGraphJSON: (graph: ComfyWorkflow) => LiteGraphJSON;
17151
17194
  //#endregion
@@ -17283,9 +17326,6 @@ declare function getLoraKeyword(name: string): string;
17283
17326
  /** empty keyword deletes the entry; every set writes the file (tiny, rare) */
17284
17327
  declare function setLoraKeyword(name: string, keyword: string): void;
17285
17328
  //#endregion
17286
- //#region src/cli/tui-env.d.ts
17287
- declare function isTuiActive(): boolean;
17288
- //#endregion
17289
17329
  //#region src/utils/loraTag.d.ts
17290
17330
  /**
17291
17331
  * build a LoraManager-style lora tag: `<lora:name:strength>` or
@@ -17296,5 +17336,18 @@ declare function isTuiActive(): boolean;
17296
17336
  */
17297
17337
  declare function loraTag<N extends string = string>(name: N, strength?: number, clipStrength?: number): string;
17298
17338
  //#endregion
17299
- 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 };
17300
17353
  //# sourceMappingURL=index.d.ts.map