comfy-ts 0.4.0 → 1.1.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 (158) hide show
  1. package/README.md +385 -255
  2. package/dist/DefinedWorkflow-BYyu5dK9.js +669 -0
  3. package/dist/DefinedWorkflow-BYyu5dK9.js.map +1 -0
  4. package/dist/cli.js +4106 -152
  5. package/dist/cli.js.map +1 -1
  6. package/dist/index.cjs +1560 -333
  7. package/dist/index.cjs.map +1 -1
  8. package/dist/index.d.cts +7826 -467
  9. package/dist/index.d.ts +7808 -449
  10. package/dist/index.js +1550 -333
  11. package/dist/index.js.map +1 -1
  12. package/dist/{run-tui-SDSJo1Qf.js → run-tui-DZ22HDHI.js} +631 -657
  13. package/dist/run-tui-DZ22HDHI.js.map +1 -0
  14. package/examples/01-txt2img.cflow.ts +50 -0
  15. package/examples/02-img2img-upload.cflow.ts +55 -0
  16. package/examples/03-export-workflow-json.cflow.ts +56 -0
  17. package/examples/04-krea2-turbo-t2i.cflow.ts +125 -0
  18. package/examples/05-comfy-cloud.cflow.ts +51 -0
  19. package/examples/README.md +30 -0
  20. package/examples/comfy-cloud/ace-step-t2a.cflow.ts +79 -0
  21. package/examples/comfy-cloud/anima-t2i.cflow.ts +57 -0
  22. package/examples/comfy-cloud/boogu-i2i.cflow.ts +76 -0
  23. package/examples/comfy-cloud/capybara-i2i.cflow.ts +85 -0
  24. package/examples/comfy-cloud/capybara-i2v.cflow.ts +90 -0
  25. package/examples/comfy-cloud/capybara-t2i.cflow.ts +67 -0
  26. package/examples/comfy-cloud/chatterbox-t2a.cflow.ts +79 -0
  27. package/examples/comfy-cloud/chroma-t2i.cflow.ts +62 -0
  28. package/examples/comfy-cloud/cloudHost.ts +41 -0
  29. package/examples/comfy-cloud/ernie-t2i.cflow.ts +59 -0
  30. package/examples/comfy-cloud/firered-i2i.cflow.ts +74 -0
  31. package/examples/comfy-cloud/flux1-i2i.cflow.ts +76 -0
  32. package/examples/comfy-cloud/flux1-t2i.cflow.ts +63 -0
  33. package/examples/comfy-cloud/flux2-i2i.cflow.ts +80 -0
  34. package/examples/comfy-cloud/flux2-t2i.cflow.ts +57 -0
  35. package/examples/comfy-cloud/hidream-i2i.cflow.ts +89 -0
  36. package/examples/comfy-cloud/hidream-t2i.cflow.ts +65 -0
  37. package/examples/comfy-cloud/hunyuan-video-i2v.cflow.ts +93 -0
  38. package/examples/comfy-cloud/hunyuan-video-t2v.cflow.ts +74 -0
  39. package/examples/comfy-cloud/ideogram4-t2i.cflow.ts +80 -0
  40. package/examples/comfy-cloud/kandinsky5-i2v.cflow.ts +95 -0
  41. package/examples/comfy-cloud/kandinsky5-t2i.cflow.ts +60 -0
  42. package/examples/comfy-cloud/kandinsky5-t2v.cflow.ts +78 -0
  43. package/examples/comfy-cloud/krea2-t2i.cflow.ts +59 -0
  44. package/examples/comfy-cloud/lens-t2i.cflow.ts +62 -0
  45. package/examples/comfy-cloud/longcat-i2i.cflow.ts +74 -0
  46. package/examples/comfy-cloud/longcat-t2i.cflow.ts +65 -0
  47. package/examples/comfy-cloud/ltxv-i2v.cflow.ts +92 -0
  48. package/examples/comfy-cloud/ltxv-t2v.cflow.ts +78 -0
  49. package/examples/comfy-cloud/newbie-t2i.cflow.ts +67 -0
  50. package/examples/comfy-cloud/omnigen2-i2i.cflow.ts +86 -0
  51. package/examples/comfy-cloud/omnigen2-t2i.cflow.ts +62 -0
  52. package/examples/comfy-cloud/ovis-t2i.cflow.ts +56 -0
  53. package/examples/comfy-cloud/pixeldit-t2i.cflow.ts +63 -0
  54. package/examples/comfy-cloud/qwen-image-i2i.cflow.ts +69 -0
  55. package/examples/comfy-cloud/qwen-image-t2i.cflow.ts +55 -0
  56. package/examples/comfy-cloud/sd35-t2i.cflow.ts +48 -0
  57. package/examples/comfy-cloud/sdk.d.ts +123062 -0
  58. package/examples/comfy-cloud/sdxl-t2i.cflow.ts +69 -0
  59. package/examples/comfy-cloud/stable-audio-t2a.cflow.ts +53 -0
  60. package/examples/comfy-cloud/svd-i2v.cflow.ts +75 -0
  61. package/examples/comfy-cloud/wan21-i2v.cflow.ts +83 -0
  62. package/examples/comfy-cloud/wan21-t2v.cflow.ts +64 -0
  63. package/examples/comfy-cloud/wan22-5b-t2v.cflow.ts +69 -0
  64. package/examples/comfy-cloud/wan22-i2v.cflow.ts +107 -0
  65. package/examples/comfy-cloud/wan22-t2v.cflow.ts +98 -0
  66. package/examples/comfy-cloud/z-image-t2i.cflow.ts +62 -0
  67. package/examples/images/README.md +18 -0
  68. package/examples/images/bear_1024x1024.jpg +0 -0
  69. package/examples/images/deer_768x1344.jpg +0 -0
  70. package/examples/images/dog_512x512.jpg +0 -0
  71. package/examples/images/lioness_768x768.jpg +0 -0
  72. package/examples/images/pug_200x300.jpg +0 -0
  73. package/examples/images/walrus_1344x768.jpg +0 -0
  74. package/guide-for-agents.md +172 -0
  75. package/package.json +20 -4
  76. package/src/cli/comfy-ts-cli.ts +19 -2
  77. package/src/cli/gen.ts +21 -12
  78. package/src/cli/tui/components/PreviewPanel.tsx +9 -8
  79. package/src/cli/tui/components/StatusBar.tsx +11 -0
  80. package/src/cli/tui/components/TreePanel.tsx +15 -2
  81. package/src/cli/tui/components/TuiApp.tsx +18 -0
  82. package/src/cli/tui/discoverWorkflows.ts +45 -0
  83. package/src/cli/tui/imagePicker/ImagePickerOverlay.tsx +72 -0
  84. package/src/cli/tui/imagePicker/ImagePickerSt.ts +288 -0
  85. package/src/cli/tui/imagePicker/fsListing.ts +46 -0
  86. package/src/cli/tui/imagePicker/pickerPrefs.ts +78 -0
  87. package/src/cli/tui/run-tui.tsx +52 -23
  88. package/src/cli/tui/state/HostSt.ts +2 -3
  89. package/src/cli/tui/state/LorasSt.ts +14 -36
  90. package/src/cli/tui/state/PreviewSt.ts +28 -2
  91. package/src/cli/tui/state/TreeSt.ts +30 -6
  92. package/src/cli/tui/state/TuiSt.ts +27 -3
  93. package/src/cli/tui/state/WorkflowsSt.ts +15 -1
  94. package/src/exampleAssets.ts +56 -0
  95. package/src/graph/ComfyNode.ts +4 -1
  96. package/src/host/ComfyHost.ts +203 -77
  97. package/src/host/ComfyManager.ts +10 -9
  98. package/src/host/ComfyUploader.ts +1 -2
  99. package/src/host/ResilientWebsocket.ts +3 -1
  100. package/src/host/hostUrl.ts +59 -0
  101. package/src/host/loraManagerApi.ts +5 -4
  102. package/src/index.ts +27 -1
  103. package/src/litegraph/CanonicalWorkflow.ts +77 -0
  104. package/src/litegraph/LiteGraphGroup.ts +9 -7
  105. package/src/litegraph/LiteGraphJSON.ts +34 -13
  106. package/src/litegraph/LiteGraphLink.ts +32 -2
  107. package/src/litegraph/LiteGraphNode.ts +18 -33
  108. package/src/litegraph/LiteGraphNodeInput.ts +10 -8
  109. package/src/litegraph/LiteGraphNodeOutput.ts +2 -3
  110. package/src/litegraph/LiteGraphSubgraphDef.ts +74 -0
  111. package/src/litegraph/convertFlowToLiteGraphJSON.ts +4 -4
  112. package/src/litegraph/expandSubgraphs.ts +352 -0
  113. package/src/litegraph/normalizeWorkflow.ts +141 -0
  114. package/src/manager/ComfyRegistry.ts +37 -9
  115. package/src/manager/generated/KnownComfyCustomNodeName.ts +23852 -1926
  116. package/src/manager/generated/KnownComfyPluginTitle.ts +6854 -236
  117. package/src/manager/generated/KnownComfyPluginURL.ts +3425 -111
  118. package/src/manager/generated/KnownModel_Base.ts +23 -7
  119. package/src/manager/generated/KnownModel_FileName.ts +421 -0
  120. package/src/manager/generated/KnownModel_Name.ts +421 -0
  121. package/src/manager/generated/KnownModel_SavePath.ts +34 -8
  122. package/src/manager/generated/KnownModel_Type.ts +18 -14
  123. package/src/manager/json/alter-list.json +221 -221
  124. package/src/manager/json/custom-node-list.json +61020 -21946
  125. package/src/manager/json/extension-node-map.json +81077 -31176
  126. package/src/manager/json/github-stats.json +29321 -12601
  127. package/src/manager/json/model-list.json +5935 -4997
  128. package/src/manager/loaders/parseReport.ts +55 -0
  129. package/src/manager/loaders/step1_downloadComfyManagerJSONs.ts +15 -49
  130. package/src/manager/loaders/step2_custom-node-list-loader.ts +38 -83
  131. package/src/manager/loaders/step3_extension-node-map-loader.ts +36 -142
  132. package/src/manager/loaders/step4_model-list-loader.ts +25 -36
  133. package/src/manager/loaders/step5_alter-list-loader.ts +29 -0
  134. package/src/manager/loaders/step6_github-stats-loader.ts +23 -0
  135. package/src/manager/script-update-manager.bun.ts +9 -1
  136. package/src/manager/types/ComfyManagerAlterInfo.ts +13 -0
  137. package/src/manager/types/ComfyManagerFileModelInfo.ts +7 -3
  138. package/src/manager/types/ComfyManagerFilePluginContent.ts +6 -9
  139. package/src/manager/types/ComfyManagerFilePluginList.ts +3 -3
  140. package/src/manager/types/ComfyManagerGithubStats.ts +9 -0
  141. package/src/manager/types/ComfyManagerPluginContentMetadata.ts +2 -3
  142. package/src/manager/types/ComfyManagerPluginInfo.ts +48 -34
  143. package/src/runner/ComfyExecution.ts +4 -5
  144. package/src/runner/ComfyWorkflow.ts +2 -2
  145. package/src/runner/wsBinaryFrame.ts +48 -0
  146. package/src/sdk-generator/ComfySchema.ts +14 -1
  147. package/src/sdk-generator/Primitives.ts +6 -24
  148. package/src/sdk-generator/comfy-api-json.ts +3 -1
  149. package/src/sdk-generator/comfyui-sdk-codegen.ts +15 -0
  150. package/src/sdk-generator/inputWidgetKind.ts +196 -0
  151. package/src/sdk-generator/litegraphToApiRequestPayload.ts +372 -96
  152. package/src/state.ts +13 -2
  153. package/src/vars/ComfyVars.ts +82 -2
  154. package/src/vars/DefinedWorkflow.ts +7 -2
  155. package/dist/log-CdfgILde.js +0 -10
  156. package/dist/log-CdfgILde.js.map +0 -1
  157. package/dist/run-tui-SDSJo1Qf.js.map +0 -1
  158. package/src/utils/tryExtracting.ts +0 -41
@@ -1,10 +1,12 @@
1
1
  // Vars: the standard "tweak & re-run" contract. A workflow defined via
2
2
  // host.defineWorkflow({ vars, build }) rebuilds its graph from current var
3
3
  // values on every run — drivers (scripts, the TUI) edit vars between runs.
4
+ import { homedir } from 'node:os'
4
5
  import { action, makeObservable, observable } from 'mobx'
6
+ import { isAbsolute, join, resolve } from 'pathe'
5
7
  import { getLoraKeyword } from 'src/vars/loraKeywords.ts'
6
8
 
7
- export type VarKind = 'text' | 'int' | 'float' | 'seed' | 'toggle' | 'choice' | 'loras' | 'size'
9
+ export type VarKind = 'text' | 'int' | 'float' | 'seed' | 'toggle' | 'choice' | 'loras' | 'size' | 'image'
8
10
 
9
11
  /**
10
12
  * full base: T is what's STORED/edited, Out what the GRAPH consumes at build
@@ -14,6 +16,8 @@ export type VarKind = 'text' | 'int' | 'float' | 'seed' | 'toggle' | 'choice' |
14
16
  */
15
17
  export abstract class ComfyVarBase<T, Out> {
16
18
  abstract readonly kind: VarKind
19
+ /** the vars-spec key, stamped by DefinedWorkflow at define time — error messages name the var with it */
20
+ name?: string
17
21
  value: T
18
22
  constructor(
19
23
  public readonly defaultValue: T,
@@ -474,7 +478,80 @@ export class SizeVar extends ComfyVar<SizeValue> {
474
478
  }
475
479
  }
476
480
 
477
- /** the var constructors: v.text / v.prompt / v.int / v.float / v.seed / v.toggle / v.choice / v.loras / v.size */
481
+ export type ImageVarOpts = {
482
+ /** where the TUI picker starts browsing AND what relative values resolve against (absPath) */
483
+ folder?: string
484
+ /** picker listing filter, lowercase without dots; never affects the value */
485
+ extensions?: readonly string[]
486
+ label?: string
487
+ }
488
+
489
+ export const DEFAULT_IMAGE_EXTENSIONS: readonly string[] = ['png', 'jpg', 'jpeg', 'webp', 'gif']
490
+
491
+ /** empty image var consumed at build time — typed so drivers surface it apart from real crashes */
492
+ export class ImageVarEmptyError extends Error {
493
+ constructor(public readonly varName: string) {
494
+ super(`image var '${varName}' is empty — pick a file (TUI: activate the var; script: .set('/path/to/image.png'))`)
495
+ }
496
+ }
497
+
498
+ /** trim + expand a leading `~/` — every ImageVar write funnels through this */
499
+ function expandUserPath(raw: string): string {
500
+ const trimmed = raw.trim()
501
+ return trimmed.startsWith('~/') ? join(homedir(), trimmed.slice(2)) : trimmed
502
+ }
503
+
504
+ /**
505
+ * a local image path. The VALUE is a PLAIN PATH STRING — text-encodable,
506
+ * drafts persist it verbatim (toJSON = the string), hand-editable in the
507
+ * draft json. Empty = unset: outValue()/absPath() throw ImageVarEmptyError,
508
+ * so a build never runs on a silent placeholder. The TUI opens the image
509
+ * picker overlay for kind 'image'.
510
+ */
511
+ export class ImageVar extends ComfyVar<string> {
512
+ readonly kind = 'image' as const
513
+ constructor(
514
+ defaultValue: string,
515
+ public opts: ImageVarOpts = {},
516
+ ) {
517
+ super(expandUserPath(defaultValue), opts.label)
518
+ }
519
+ /** what the picker lists (lowercase, no dots) */
520
+ get extensions(): readonly string[] {
521
+ return this.opts.extensions ?? DEFAULT_IMAGE_EXTENSIONS
522
+ }
523
+ override set(value: string): this {
524
+ return super.set(expandUserPath(value))
525
+ }
526
+ parse(raw: string): boolean {
527
+ this.set(raw)
528
+ return true
529
+ }
530
+ isSet(): boolean {
531
+ return this.value !== ''
532
+ }
533
+ private emptyError(): ImageVarEmptyError {
534
+ return new ImageVarEmptyError(this.name ?? this.label ?? 'image')
535
+ }
536
+ /** the ONE resolution helper: absolute kept as-is, relative resolved against opts.folder, else cwd */
537
+ absPath(): string {
538
+ if (!this.isSet()) throw this.emptyError()
539
+ if (isAbsolute(this.value)) return this.value
540
+ return resolve(this.opts.folder ?? process.cwd(), this.value)
541
+ }
542
+ /** empty = unset: the build fails LOUD here (varValues calls outValue) */
543
+ override outValue(): string {
544
+ if (!this.isSet()) throw this.emptyError()
545
+ return this.value
546
+ }
547
+ override display(): string {
548
+ if (!this.isSet()) return '(unset) pick a file'
549
+ const home = homedir()
550
+ return this.value.startsWith(`${home}/`) ? `~${this.value.slice(home.length)}` : this.value
551
+ }
552
+ }
553
+
554
+ /** the var constructors: v.text / v.prompt / v.int / v.float / v.seed / v.toggle / v.choice / v.loras / v.size / v.image */
478
555
  export const v = {
479
556
  text: (defaultValue: string, label?: string): TextVar => new TextVar(defaultValue, label),
480
557
  prompt: (defaultValue: string, opts: { label?: string; loraKeywordsFrom?: ActiveLoraSource } = {}): PromptVar =>
@@ -494,6 +571,7 @@ export const v = {
494
571
  ): LorasVar<T> => new LorasVar(options, initial, label),
495
572
  size: (defaultValue?: SizeValue, opts: { presets?: SizePreset[]; label?: string } = {}): SizeVar =>
496
573
  new SizeVar(defaultValue, opts.presets, opts.label),
574
+ image: (defaultValue: string, opts: ImageVarOpts = {}): ImageVar => new ImageVar(defaultValue, opts),
497
575
  }
498
576
 
499
577
  /**
@@ -505,6 +583,8 @@ export type AnyVar = {
505
583
  readonly kind: VarKind
506
584
  readonly value: unknown
507
585
  readonly label?: string
586
+ /** the vars-spec key — DefinedWorkflow writes it at define time */
587
+ name?: string
508
588
  parse(raw: string): boolean
509
589
  loadJSON(value: unknown): unknown
510
590
  toJSON(): unknown
@@ -70,8 +70,13 @@ export class DefinedWorkflow<ID extends string = string, V extends VarsSpec = Va
70
70
  // factory BoundVars describes; the regex-loras typing claim it adds is
71
71
  // resolved from the same object_info enum via bindHost below
72
72
  this.vars = isVarsThunk(spec.vars) ? spec.vars(v as BoundVars<ID>) : spec.vars
73
- // host-dependent vars (v.loras(regex)) resolve NOW, at define time
74
- for (const [, varDef] of this.entries()) varDef.bindHost?.(this.host)
73
+ // define-time var wiring: the spec key becomes the var's name (error
74
+ // messages name the var with it), host-dependent vars (v.loras(regex))
75
+ // resolve their options
76
+ for (const [key, varDef] of this.entries()) {
77
+ varDef.name = key
78
+ varDef.bindHost?.(this.host)
79
+ }
75
80
  }
76
81
 
77
82
  /** [name, var] pairs, for drivers that enumerate the knobs */
@@ -1,10 +0,0 @@
1
- //#region src/utils/log.ts
2
- const isQuiet = () => process.env.COMFY_TS_QUIET === "1";
3
- const logInfo = (msg) => {
4
- if (!isQuiet()) console.log(msg);
5
- };
6
- const logError = (msg) => console.error(`[comfy-ts] 🔴 ${msg}`);
7
- //#endregion
8
- export { logInfo as n, logError as t };
9
-
10
- //# sourceMappingURL=log-CdfgILde.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"log-CdfgILde.js","names":[],"sources":["../src/utils/log.ts"],"sourcesContent":["// loud console logging; errors must be observable to human AND LLM.\n// COMFY_TS_QUIET=1 (set by drivers like the TUI) silences INFO chatter only —\n// errors always print.\nexport const isQuiet = (): boolean => process.env.COMFY_TS_QUIET === '1'\nexport const logInfo = (msg: string): void => {\n if (!isQuiet()) console.log(msg)\n}\nexport const logError = (msg: string): void => console.error(`[comfy-ts] 🔴 ${msg}`)\nexport const logSuccess = (msg: string): void => console.log(`[comfy-ts] 🟢 ${msg}`)\n"],"mappings":";AAGA,MAAa,gBAAyB,QAAQ,IAAI,mBAAmB;AACrE,MAAa,WAAW,QAAsB;CAC3C,IAAI,CAAC,QAAQ,GAAG,QAAQ,IAAI,GAAG;AAClC;AACA,MAAa,YAAY,QAAsB,QAAQ,MAAM,iBAAiB,KAAK"}