comfy-ts 2.2.0 → 2.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 (54) hide show
  1. package/README.md +13 -0
  2. package/dist/{DefinedWorkflow-CwHInZgn.js → DefinedWorkflow-QrhT6V66.js} +441 -9
  3. package/dist/DefinedWorkflow-QrhT6V66.js.map +1 -0
  4. package/dist/{DraftsSt-omWuBSej.js → DraftsSt-D9Fhk4qR.js} +2 -2
  5. package/dist/{DraftsSt-omWuBSej.js.map → DraftsSt-D9Fhk4qR.js.map} +1 -1
  6. package/dist/cli.js +116 -8
  7. package/dist/cli.js.map +1 -1
  8. package/dist/index.cjs +292 -24
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.d.cts +147 -9
  11. package/dist/index.d.ts +147 -9
  12. package/dist/index.js +280 -25
  13. package/dist/index.js.map +1 -1
  14. package/dist/{run-serve-C1oo5ilG.js → run-serve-C9E8dyLP.js} +7 -3
  15. package/dist/run-serve-C9E8dyLP.js.map +1 -0
  16. package/dist/{run-tui-CuVst-nc.js → run-tui-cawSJuuh.js} +60 -121
  17. package/dist/run-tui-cawSJuuh.js.map +1 -0
  18. package/dist/{state-CvMt0W1-.js → state-BbKuSDCV.js} +38 -77
  19. package/dist/state-BbKuSDCV.js.map +1 -0
  20. package/dist/web.d.ts +147 -9
  21. package/dist/web.js +280 -25
  22. package/dist/web.js.map +1 -1
  23. package/guide-for-agents.md +3 -0
  24. package/package.json +2 -1
  25. package/src/cli/comfy-ts-cli.ts +16 -1
  26. package/src/cli/flags.ts +14 -0
  27. package/src/cli/gen.ts +2 -4
  28. package/src/cli/loras.ts +113 -0
  29. package/src/cli/serve/ServeApp.ts +4 -0
  30. package/src/cli/serve/applyVarPayload.ts +1 -1
  31. package/src/cli/tui/components/LorasOverlay.tsx +18 -5
  32. package/src/cli/tui/components/StatusBar.tsx +1 -0
  33. package/src/cli/tui/components/TuiApp.tsx +1 -0
  34. package/src/cli/tui/imageClipboard.ts +3 -3
  35. package/src/cli/tui/protocolImagePainter.ts +1 -1
  36. package/src/cli/tui/run-tui.tsx +2 -2
  37. package/src/cli/tui/state/ExecSt.ts +2 -2
  38. package/src/cli/tui/state/HostSt.ts +1 -1
  39. package/src/cli/tui/state/LorasSt.ts +60 -15
  40. package/src/cli/tui/state/PreviewSt.ts +1 -1
  41. package/src/cli/tui/state/SettingsSt.ts +1 -1
  42. package/src/coreExports.ts +21 -1
  43. package/src/host/ComfyHost.ts +51 -3
  44. package/src/host/loraInfoCache.ts +216 -0
  45. package/src/host/loraManagerApi.ts +131 -27
  46. package/src/runner/ComfyExecution.ts +1 -1
  47. package/src/runner/outputPath.ts +3 -3
  48. package/src/utils/isRecord.ts +4 -0
  49. package/src/vars/ComfyVars.ts +13 -7
  50. package/src/vars/loraKeywords.ts +48 -5
  51. package/dist/DefinedWorkflow-CwHInZgn.js.map +0 -1
  52. package/dist/run-serve-C1oo5ilG.js.map +0 -1
  53. package/dist/run-tui-CuVst-nc.js.map +0 -1
  54. package/dist/state-CvMt0W1-.js.map +0 -1
package/dist/web.d.ts CHANGED
@@ -12719,7 +12719,7 @@ declare class ComfyExecution {
12719
12719
  retrieveImage: (comfyImageInfo: ComfyImageInfo, promptNodeID: ComfyNodeId) => Promise<void>;
12720
12720
  /** re-encode when asked, then write under OUR local naming — never the raw
12721
12721
  * server filename: a cloud host resets its _00001_ counter per run, so the
12722
- * server name overwrote the same local file on every run (his repro 2026-07-31) */
12722
+ * server name overwrote the same local file on every run */
12723
12723
  private encodeAndWrite;
12724
12724
  /** accumulate an output on the prompt; tags from node metadata ride along */
12725
12725
  private pushImage;
@@ -15910,8 +15910,8 @@ declare class ResilientWebSocketClient {
15910
15910
  * the var's CLASS, and the only safe way to discriminate one: `instanceof` compares class
15911
15911
  * OBJECTS, and the published package hands the same class out twice — a consumer's
15912
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
15913
+ * cli bundle, so every `instanceof XVar` across that boundary is false (observed
15914
+ * in a consumer app: "var 'prompt' has unsupported kind 'text'", for EVERY kind). A string tag
15915
15915
  * crosses bundles; a class identity does not.
15916
15916
  */
15917
15917
  type VarKind = 'text' | 'prompt' | 'int' | 'float' | 'seed' | 'toggle' | 'choice' | 'loras' | 'size' | 'image';
@@ -15957,9 +15957,13 @@ declare class TextVar extends ComfyVar<string> {
15957
15957
  readonly kind: 'text';
15958
15958
  parse(raw: string): boolean;
15959
15959
  }
15960
- /** what PromptVar needs from a loras var: covariant face, so LorasVar<'a'|'b'> fits */
15960
+ /** what PromptVar needs from a loras var: covariant face, so LorasVar<'a'|'b'> fits.
15961
+ * `hostId` scopes the keyword lookup: the same file name on two hosts is often a
15962
+ * different model, and injecting the other host's trigger words is a silently
15963
+ * wrong generation. */
15961
15964
  type ActiveLoraSource = {
15962
15965
  activeNames(): string[];
15966
+ hostId?: string;
15963
15967
  };
15964
15968
  /** what a prompt CONTRIBUTES to build: `vars.prompt.positive` / `.negative` */
15965
15969
  type PromptValue = {
@@ -16078,6 +16082,9 @@ type ActiveLora<T extends string> = {
16078
16082
  declare function activeLoras<T extends string>(loras: Partial<Record<T, LoraStrength>>): ActiveLora<T>[];
16079
16083
  /** what LorasVar.bindHost needs — structural, so ComfyVars never imports ComfyHost */
16080
16084
  type LorasHost = {
16085
+ data?: {
16086
+ id?: string;
16087
+ };
16081
16088
  schema: {
16082
16089
  getLoras(filter?: RegExp): string[];
16083
16090
  };
@@ -16095,6 +16102,8 @@ declare class LorasVar<T extends string> extends ComfyVar<Partial<Record<T, Lora
16095
16102
  private prev;
16096
16103
  /** a RegExp source resolves lazily (bindHost) — null until then */
16097
16104
  private resolvedOptions;
16105
+ /** which host these loras live on, so their metadata is read from ITS mirror */
16106
+ hostId: string | undefined;
16098
16107
  constructor(optionsSource: readonly T[] | RegExp, initial?: Partial<Record<T, LoraStrength>>, label?: string);
16099
16108
  get options(): readonly T[];
16100
16109
  /** DefinedWorkflow binds the host at define time: a RegExp source resolves here.
@@ -16129,7 +16138,7 @@ type SizePreset = {
16129
16138
  /** SDXL-style ~1MP buckets, multiples of 64 — safe for most latent models */
16130
16139
  declare const DEFAULT_SIZE_PRESETS: SizePreset[];
16131
16140
  /** width/height picker: presets + free `WxH` entry + optionally the LIVE
16132
- * size of a linked image var (his ask 2026-07-30: the widget shows
16141
+ * size of a linked image var (the widget shows
16133
16142
  * `WxH size of image '<name>'` as a pickable row) */
16134
16143
  declare class SizeVar extends ComfyVar<SizeValue> {
16135
16144
  readonly presets: SizePreset[];
@@ -16340,7 +16349,20 @@ type ConnectOptions = {
16340
16349
  schema?: 'auto' | 'refresh' | 'cache';
16341
16350
  /** max cache age for 'auto' (default 24h) */
16342
16351
  maxAgeMs?: number;
16352
+ /**
16353
+ * deadline for the FIRST connect, default 30s. 0 or Infinity waits forever.
16354
+ * A refused TCP connection is a ws CLOSE, not a dead transport, so without a
16355
+ * deadline `connect()` sat in the 2s reconnect loop and never settled: scripts
16356
+ * hung with no error and `comfy-ts serve` wedged the module behind its mutex.
16357
+ * Reconnects AFTER a successful connect are untouched and still retry forever.
16358
+ */
16359
+ timeoutMs?: number;
16343
16360
  };
16361
+ /** the host never came up within ConnectOptions.timeoutMs */
16362
+ declare class ComfyHostUnreachableError extends Error {
16363
+ /** name, not instanceof: the cli bundle and dist/index.js each define this class */
16364
+ readonly name = "ComfyHostUnreachableError";
16365
+ }
16344
16366
  type SchemaUpdateResult = Maybe<{
16345
16367
  type: 'success';
16346
16368
  } | {
@@ -16458,6 +16480,8 @@ declare class ComfyHost<ID extends string = string> {
16458
16480
  * - 'cache': never fetch (throws when no cache exists)
16459
16481
  */
16460
16482
  connect: (p?: ConnectOptions) => Promise<void>;
16483
+ private _connectTimer;
16484
+ private clearConnectTimer;
16461
16485
  /** close the websocket (e.g. to let a script exit) */
16462
16486
  disconnect: () => void;
16463
16487
  private markReady;
@@ -17327,9 +17351,123 @@ workflow: CanonicalWorkflow, opts?: {
17327
17351
  }) => ComfyApiJson;
17328
17352
  //#endregion
17329
17353
  //#region src/vars/loraKeywords.d.ts
17330
- declare function getLoraKeyword(name: string): string;
17331
- /** empty keyword deletes the entry; every set writes the file (tiny, rare) */
17332
- declare function setLoraKeyword(name: string, keyword: string): void;
17354
+ /** the hand keyword when this lora HAS an entry (`''` included), else the mirror's trigger words */
17355
+ declare function getLoraKeyword(name: string, hostId?: string): string;
17356
+ /** true when the keyword shown comes from the lora-manager mirror, not from ⌃K */
17357
+ declare function isLoraKeywordFromMirror(name: string, hostId?: string): boolean;
17358
+ /** what `clearLoraKeywordOverride` would restore this lora to, `''` when nothing */
17359
+ declare function loraKeywordFromMirror(name: string, hostId?: string): string;
17360
+ /**
17361
+ * drop the hand entry entirely, so the mirror's trigger words apply again.
17362
+ * The way BACK from an empty-string tombstone: without it, clearing a keyword on
17363
+ * a lora that has trigger words was a one-way door only a text editor could undo.
17364
+ */
17365
+ declare function clearLoraKeywordOverride(name: string): void;
17366
+ /**
17367
+ * empty keyword deletes the entry — EXCEPT when the mirror has trigger words for
17368
+ * this lora: there `''` is stored as an explicit tombstone, the only way to say
17369
+ * "inject nothing" about a lora civitai gave words to. Every set writes the file
17370
+ * (tiny, rare).
17371
+ */
17372
+ declare function setLoraKeyword(name: string, keyword: string, hostId?: string): void;
17373
+ //#endregion
17374
+ //#region src/host/loraManagerApi.d.ts
17375
+ /**
17376
+ * client for the OPTIONAL ComfyUI-Lora-Manager extension.
17377
+ * absent extension = normal condition: callers get null/empty and degrade.
17378
+ */
17379
+ /**
17380
+ * one lora exactly as lora-manager sent it. RAW on purpose (agent/architecture
17381
+ * item 8): the mirror on disk keeps every field, including the ones we do not
17382
+ * read yet, so adding `sha256` or `civitai.modelId` to a surface later is an
17383
+ * accessor, not a re-sync. Reading goes through the checked lm* helpers below.
17384
+ */
17385
+ type LmLoraItem = Record<string, unknown>;
17386
+ /**
17387
+ * the ONE key space where a host's object_info spelling of a lora meets
17388
+ * lora-manager's: lowercase, forward slashes, no model extension.
17389
+ * `styles\Aurora.safetensors` and lm's folder `styles` + file_name `aurora`
17390
+ * both become `styles/aurora`.
17391
+ */
17392
+ declare function loraKey(name: string): string;
17393
+ /**
17394
+ * the outcome of a sweep, DISCRIMINATED. A bare `null` for "no loras" conflated
17395
+ * three very different situations, and callers then told the user the wrong one:
17396
+ * a host that is merely DOWN was reported as "extension not detected", and a
17397
+ * sweep cut short mid-collection was indistinguishable from a complete one, so
17398
+ * a partial mirror could overwrite a good one and report success.
17399
+ */
17400
+ type LoraSweep = {
17401
+ status: 'ok';
17402
+ items: LmLoraItem[];
17403
+ } |
17404
+ /** the extension answered, then stopped answering: `items` is INCOMPLETE, never write it over a good mirror */
17405
+ {
17406
+ status: 'partial';
17407
+ items: LmLoraItem[];
17408
+ reason: string;
17409
+ } |
17410
+ /** no ComfyUI-Lora-Manager on this host (404 on the first page) */
17411
+ {
17412
+ status: 'absent';
17413
+ } |
17414
+ /** the host itself could not be reached (down, refused, auth) */
17415
+ {
17416
+ status: 'unreachable';
17417
+ reason: string;
17418
+ };
17419
+ //#endregion
17420
+ //#region src/host/loraInfoCache.d.ts
17421
+ /**
17422
+ * the LOCAL MIRROR of what ComfyUI-Lora-Manager knows about a host's loras
17423
+ * (agent/architecture.md item 8). A ComfyUI host only ever tells us a lora's
17424
+ * file name; the model's real name, its trigger words and its tags live in the
17425
+ * extension. We sweep them once (`comfy-ts loras`) into
17426
+ * `.comfy-ts/hosts/<id>/loras.json` and every surface reads the mirror after.
17427
+ */
17428
+ type LoraMirror = {
17429
+ hostId: string;
17430
+ /** remembered so a later `comfy-ts loras` re-syncs with no flags. NEVER an api key. */
17431
+ hostUrl: string;
17432
+ fetchedAt: string;
17433
+ count: number;
17434
+ /** `loraKey` → the RAW lm item */
17435
+ loras: Record<string, LmLoraItem>;
17436
+ };
17437
+ /**
17438
+ * forget everything loaded, so the next read picks up a fresh `comfy-ts loras`.
17439
+ * A long-lived process (the TUI, `comfy-ts serve`) has no other way to see a
17440
+ * re-sync that happened in another terminal.
17441
+ */
17442
+ declare function reloadLoraInfoCache(): void;
17443
+ /**
17444
+ * the lm item for a raw lora name (`styles\x.safetensors`).
17445
+ * `hostId` picks the mirror that actually describes this host's file; without
17446
+ * it, any host that knows the name answers. null when unsynced/unknown.
17447
+ */
17448
+ declare function getLoraInfo(name: string, hostId?: string): LmLoraItem | null;
17449
+ /** civitai trigger words for this lora, in civitai's order */
17450
+ declare function getLoraTriggerWords(name: string, hostId?: string): string[];
17451
+ /** the human name (`Aurora Ink Wash`), falling back to the file's own name */
17452
+ declare function getLoraDisplayName(name: string, hostId?: string): string;
17453
+ /** server-relative preview url from the mirror, null when unsynced/unknown */
17454
+ declare function getLoraPreviewUrl(name: string, hostId?: string): string | null;
17455
+ /** the lora's NAMES: the file, and the model name a human would call it by */
17456
+ declare function loraSearchNames(name: string, hostId?: string): string[];
17457
+ /** the lora's FREE TEXT: tags, base model, trigger words */
17458
+ declare function loraSearchText(name: string, hostId?: string): string[];
17459
+ /**
17460
+ * the loras overlay filter: find a lora by its human name, not only by the file
17461
+ * name. EVERY whitespace-separated token must be a SUBSTRING of some field — order
17462
+ * free, so `aurora ink`, `ink aurora` and `styles wash` all land on the same
17463
+ * lora. NOT fuzzyMatch: a subsequence match over phrases this long matches
17464
+ * nearly everything. Measured on a real collection, filtering by each lora's
17465
+ * own file name: this rule peaks at 8 hits where fuzzyMatch matched a third of
17466
+ * every lora present.
17467
+ * Fields are matched one by one, never as a concatenated haystack, for the same
17468
+ * reason. `tests/lora-corpus.private.test.ts` keeps that measurement runnable.
17469
+ */
17470
+ declare function loraMatchesFilter(name: string, filter: string, hostId?: string): boolean;
17333
17471
  //#endregion
17334
17472
  //#region src/utils/loraTag.d.ts
17335
17473
  /**
@@ -17341,5 +17479,5 @@ declare function setLoraKeyword(name: string, keyword: string): void;
17341
17479
  */
17342
17480
  declare function loraTag<N extends string = string>(name: N, strength?: number, clipStrength?: number): string;
17343
17481
  //#endregion
17344
- export { AbsolutePath, type ActiveLora, type ActiveLoraSource, type AnyVar, BaseNode, BaseNodeFactory, BaseNodeInputs, BaseNodeOutputs, type BoundVars, Branded, type CanonicalGroup, type CanonicalInput, type CanonicalLink, type CanonicalNode, type CanonicalOutput, type CanonicalWidgetValues, type CanonicalWorkflow, ChoiceVar, type CodegenOptions, type ComfyApiJson, type ComfyApiNodeJson, ComfyExecution, type ComfyExecutionData, type ComfyExecutionStatus, ComfyHost, ComfyHostAuthError, type ComfyHostData, type ComfyHostID, type ComfyImageName, ComfyManager, ComfyNode, type ComfyNodeId, type ComfyNodeIdMode, type ComfyNodeMetadata, ComfyNodeOutput, type ComfyNodeSchemaJSON, ComfySchema, type ComfySchemaJSON, ComfySdkBase, ComfySdkShape, type ComfyStorage, ComfyTS, type ComfyUnionValue, type ComfyUploadImageResult, ComfyUploader, ComfyVar, ComfyVarBase, ComfyWorkflow, ComfyWorkflowBuilder, type ComfyWorkflowData, type ComfyWorkflowID, type ConnectOptions, ConvertibleImageFormat, DEFAULT_IMAGE_EXTENSIONS, DEFAULT_SIZE_PRESETS, type DefineWorkflowSpec, DefinedWorkflow, Either, EmptyRecord, type ExecutionProgress, type ExecutionSnapshot, Flavor, FloatVar, HTMLContent, ImageVar, ImageVarEmptyError, type ImageVarOpts, IntVar, InvalidPromptError, IsEqual, type LiteGraphJSON, type LoraNameOf, type LoraStrength, type LorasHost, LorasVar, MDContent, Maybe, MediaImage, type MediaImageData, type NodeMode, NodeOf, type ParsedHostBase, PartialOmit, type PluginInstallStatus, type PluginSuggestion, type ProgressReport, type PromptID, type PromptRelated_WsMsg, type PromptValue, PromptVar, type QualifiedNodeKey, RelativePath, type Requirements, ResilientWebSocketClient, Result, ResultFailure, type RunSettings, SaveOptions, SdkForHost, SeedVar, type SizePreset, type SizeValue, SizeVar, Tagged, TextVar, ToggleVar, type VarKind, type VarValues, type VarsSpec, WorkflowConvertError, WorkflowNormalizeError, type WsLike, type WsMessageEvent, type WsMsg, __FAIL, __OK, activeLoras, asAbsolutePath, asHTMLContent, asMDContent, asRelativePath, auto, auto_, codegenSDK, convertFlowToLiteGraphJSON, convertLiteGraphToPrompt, createMemoryStorage, getComfyStorage, getLoraKeyword, hostIdToNamespace, loraTag, normalizeWorkflow, number_Timestamp, parseHostBase, parseWorkflowJson, renderHttpBase, renderWsUrl, resultFailure, resultSuccess, setDefaultComfyStorage, setLoraKeyword, v };
17482
+ 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 LmLoraItem, type LoraMirror, type LoraNameOf, type LoraStrength, type LoraSweep, 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_, clearLoraKeywordOverride, codegenSDK, convertFlowToLiteGraphJSON, convertLiteGraphToPrompt, createMemoryStorage, getComfyStorage, getLoraDisplayName, getLoraInfo, getLoraKeyword, getLoraPreviewUrl, getLoraTriggerWords, hostIdToNamespace, isLoraKeywordFromMirror, loraKey, loraKeywordFromMirror, loraMatchesFilter, loraSearchNames, loraSearchText, loraTag, normalizeWorkflow, number_Timestamp, parseHostBase, parseWorkflowJson, reloadLoraInfoCache, renderHttpBase, renderWsUrl, resultFailure, resultSuccess, setDefaultComfyStorage, setLoraKeyword, v };
17345
17483
  //# sourceMappingURL=web.d.ts.map