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,4 +1,4 @@
1
- import { makeAutoObservable, reaction, runInAction } from 'mobx'
1
+ import { makeAutoObservable, reaction } from 'mobx'
2
2
  import { fetchLoraPreviewBytes, fetchLoraPreviewMap, loraPreviewKey } from 'src/host/loraManagerApi.ts'
3
3
  import { imageBufferToAnsi } from 'src/utils/ansiImage.ts'
4
4
  import { extractErrorMessage } from 'src/utils/extractErrorMessage.ts'
@@ -43,6 +43,8 @@ export class LorasSt {
43
43
  this.st.mode = 'overlay-loras'
44
44
  this.ix = 0
45
45
  this.filter = ''
46
+ // fresh overlay starts on the placeholder, never a stale slot image
47
+ this.st.preview.clearOverlayImage()
46
48
  }
47
49
 
48
50
  move(delta: number): void {
@@ -106,26 +108,16 @@ export class LorasSt {
106
108
  return this.filteredNames[this.ix] ?? null
107
109
  }
108
110
 
109
- previewAnsi: string | null = null
110
- /** protocol mode: raw preview bytes for the overlay painter */
111
- previewBytes: Uint8Array | null = null
112
- previewName: string | null = null
113
- /** placeholder line when no image can be shown (missing extension, no preview, video preview…) */
114
- previewNote: string | null = null
115
-
116
111
  /** undefined = not fetched yet · null = extension absent */
117
112
  private previewMap: Map<string, string> | null | undefined = undefined
118
113
  private previewMapHostId: string | null = null
119
114
  private _busy: boolean = false
120
115
 
116
+ /** preview goes through PreviewSt's shared overlay slot (one code path with the image picker) */
121
117
  async refreshPreview(): Promise<void> {
122
118
  if (this.st.mode !== 'overlay-loras') {
123
- runInAction(() => {
124
- this.previewAnsi = null
125
- this.previewBytes = null
126
- this.previewName = null
127
- this.previewNote = null
128
- })
119
+ // debounced close: another overlay may ALREADY own the slot — never wipe its image
120
+ if (!this.st.preview.overlayActive) this.st.preview.clearOverlayImage()
129
121
  return
130
122
  }
131
123
  const name = this.selectedName
@@ -141,12 +133,7 @@ export class LorasSt {
141
133
  const url = map?.get(loraPreviewKey(name))
142
134
  const note = map == null ? 'lora-manager extension not detected' : url == null ? 'no preview available' : null
143
135
  if (url == null) {
144
- runInAction(() => {
145
- this.previewAnsi = null
146
- this.previewBytes = null
147
- this.previewName = name
148
- this.previewNote = note
149
- })
136
+ this.st.preview.setOverlayImage({ bytes: null, ansi: null, name: `lora ${name}`, note })
150
137
  return
151
138
  }
152
139
  const bytes = await fetchLoraPreviewBytes(host, url)
@@ -154,27 +141,18 @@ export class LorasSt {
154
141
  if (bytes == null) throw new Error('no image preview on the server')
155
142
  if (this.st.preview.useNative) {
156
143
  // the overlay painter shows the REAL image — no ansi rendering needed
157
- runInAction(() => {
158
- this.previewBytes = bytes
159
- this.previewAnsi = null
160
- this.previewName = name
161
- this.previewNote = null
162
- })
144
+ this.st.preview.setOverlayImage({ bytes, ansi: null, name: `lora ${name}`, note: null })
163
145
  return
164
146
  }
165
147
  const ansi = await imageBufferToAnsi(bytes, { width: this.st.preview.width, height: this.st.preview.height })
166
- runInAction(() => {
167
- this.previewAnsi = ansi
168
- this.previewName = name
169
- this.previewNote = null
170
- })
148
+ this.st.preview.setOverlayImage({ bytes: null, ansi, name: `lora ${name}`, note: null })
171
149
  } catch (e) {
172
150
  // e.g. video previews sharp can't decode — placeholder, not an incident
173
- runInAction(() => {
174
- this.previewAnsi = null
175
- this.previewBytes = null
176
- this.previewName = name
177
- this.previewNote = extractErrorMessage(e)
151
+ this.st.preview.setOverlayImage({
152
+ bytes: null,
153
+ ansi: null,
154
+ name: `lora ${name}`,
155
+ note: extractErrorMessage(e),
178
156
  })
179
157
  } finally {
180
158
  this._busy = false
@@ -15,6 +15,15 @@ export function protocolCapable(): boolean {
15
15
 
16
16
  type MenuRow = { key: 'panel' | 'renderer' | 'during-run'; label: string; value: string }
17
17
 
18
+ /** what an overlay (loras / image picker) wants the panel to show: real bytes
19
+ * (native renderer), an ansi render (pixel), or a placeholder note */
20
+ export type OverlayImage = {
21
+ bytes: Uint8Array | null
22
+ ansi: string | null
23
+ name: string | null
24
+ note: string | null
25
+ }
26
+
18
27
  /** small-latent corner: fraction of the panel each dimension takes */
19
28
  const CORNER_FRACTION = 0.38
20
29
  /** pixel 'latent small': the sharp-composited thumb takes this fraction of the panel */
@@ -61,6 +70,23 @@ export class PreviewSt {
61
70
  get menuOpen(): boolean {
62
71
  return this.st.mode === 'preview'
63
72
  }
73
+
74
+ // ---- overlay slot: ONE code path for every overlay that previews into the
75
+ // panel (loras + image picker write it; the panel and the protocol painter
76
+ // read it whenever an overlay mode owns the vars area) ----
77
+ overlay: OverlayImage | null = null
78
+
79
+ get overlayActive(): boolean {
80
+ return this.st.mode === 'overlay-loras' || this.st.mode === 'overlay-image'
81
+ }
82
+
83
+ setOverlayImage(p: OverlayImage): void {
84
+ this.overlay = p
85
+ }
86
+
87
+ clearOverlayImage(): void {
88
+ this.overlay = null
89
+ }
64
90
  /** running + latents wanted + sampling well underway + none arrived = server
65
91
  * sends none. The ≥20% gate keeps healthy runs from red-flashing: the first
66
92
  * progress tick lands a beat before the first preview frame */
@@ -157,7 +183,7 @@ export class PreviewSt {
157
183
  /** what the painter should show RIGHT NOW (native renderer only; mirrors the panel's source) */
158
184
  get protocolImage(): Uint8Array | null {
159
185
  if (!this.useNative || !this.show || this.menuOpen) return null
160
- if (this.st.mode === 'overlay-loras') return this.st.loras.previewBytes
186
+ if (this.overlayActive) return this.overlay?.bytes ?? null
161
187
  if (this.st.exec.running) {
162
188
  if (this.duringRun === 'latent') return this.latentBytes ?? this.outputBytes
163
189
  // latent-small keeps the OUTPUT big (corner carries the latent) — last-output too
@@ -169,7 +195,7 @@ export class PreviewSt {
169
195
  /** small latent painted over the panel's top-right corner (native + 'latent small' only) */
170
196
  get protocolImageCorner(): Uint8Array | null {
171
197
  if (!this.useNative || !this.show || this.menuOpen) return null
172
- if (this.st.mode === 'overlay-loras') return null
198
+ if (this.overlayActive) return null
173
199
  if (this.st.exec.running && this.duringRun === 'latent-small') return this.latentBytes
174
200
  return null
175
201
  }
@@ -3,7 +3,16 @@ import { draftKeyForFile, listDraftsForFile } from 'src/cli/tui/state/DraftsSt.t
3
3
  import type { TuiSt } from 'src/cli/tui/state/TuiSt.ts'
4
4
 
5
5
  export type TreeRow =
6
- | { kind: 'workflow'; file: string; name: string; expanded: boolean; current: boolean; hasDrafts: boolean }
6
+ | { kind: 'section'; label: string } // dim group header (bundled examples), never selectable
7
+ | {
8
+ kind: 'workflow'
9
+ file: string
10
+ name: string
11
+ expanded: boolean
12
+ current: boolean
13
+ hasDrafts: boolean
14
+ error: string | null
15
+ }
7
16
  | { kind: 'draft'; file: string; draft: string; active: boolean }
8
17
 
9
18
  /** the left `(t)ree`: workflows with their drafts nested under them */
@@ -19,7 +28,13 @@ export class TreeSt {
19
28
  void this.st.drafts.version // fs-derived: recompute when drafts change
20
29
  const w = this.st.workflows
21
30
  const rows: TreeRow[] = []
31
+ let sectionPushed = false
22
32
  for (const file of w.files) {
33
+ // bundled examples come LAST in files: one section header before the first
34
+ if (!sectionPushed && w.bundled.has(file)) {
35
+ rows.push({ kind: 'section', label: 'comfy-ts examples' })
36
+ sectionPushed = true
37
+ }
23
38
  const current = file === w.currentPath
24
39
  const expanded = this.expandedFiles.has(file)
25
40
  const drafts = listDraftsForFile(file)
@@ -30,6 +45,7 @@ export class TreeSt {
30
45
  expanded,
31
46
  current,
32
47
  hasDrafts: drafts.length > 0,
48
+ error: w.loadErrors.get(file) ?? null,
33
49
  })
34
50
  if (!expanded) continue
35
51
  for (const draft of drafts) {
@@ -64,16 +80,23 @@ export class TreeSt {
64
80
  }
65
81
 
66
82
  move(delta: number): void {
67
- const len = this.rows.length
83
+ const rows = this.rows
84
+ const len = rows.length
68
85
  if (len === 0) return
69
- this.ix = (this.ix + delta + len) % len
86
+ let ix = this.ix
87
+ // hop over section headers (never selectable); bounded: wraps at most once
88
+ for (let step = 0; step < len; step++) {
89
+ ix = (ix + delta + len) % len
90
+ if (rows[ix]?.kind !== 'section') break
91
+ }
92
+ this.ix = ix
70
93
  }
71
94
 
72
95
  /** →: unfold the workflow under the cursor; on a draft row there is nothing
73
96
  * left to unfold, so → continues rightwards into the vars panel */
74
97
  unfold(): void {
75
98
  const row = this.selected
76
- if (row == null) return
99
+ if (row == null || row.kind === 'section') return
77
100
  if (row.kind === 'workflow') this.expandedFiles.add(row.file)
78
101
  else this.blur()
79
102
  }
@@ -81,7 +104,7 @@ export class TreeSt {
81
104
  /** ←: fold the workflow under the cursor; on a draft row, jump to (and fold) its parent */
82
105
  fold(): void {
83
106
  const row = this.selected
84
- if (row == null) return
107
+ if (row == null || row.kind === 'section') return
85
108
  this.expandedFiles.delete(row.file)
86
109
  if (row.kind === 'draft') {
87
110
  const ix = this.rows.findIndex((r) => r.kind === 'workflow' && r.file === row.file)
@@ -92,7 +115,7 @@ export class TreeSt {
92
115
  /** ⏎: load the workflow (into 'default'), or the exact draft under the cursor */
93
116
  async commit(): Promise<void> {
94
117
  const row = this.selected
95
- if (row == null) return
118
+ if (row == null || row.kind === 'section') return
96
119
  if (row.kind === 'workflow') return this.st.workflows.commit(row.file)
97
120
  return this.st.workflows.commit(row.file, row.draft)
98
121
  }
@@ -100,6 +123,7 @@ export class TreeSt {
100
123
  /** n: new draft — current workflow only (a draft snapshots its LIVE var values) */
101
124
  promptNewDraft(): void {
102
125
  const row = this.selected
126
+ if (row?.kind === 'section') return
103
127
  if (row != null && row.file !== this.st.workflows.currentPath) {
104
128
  this.st.exec.notice = 'load that workflow first (⏎) — a new draft snapshots its live vars'
105
129
  return
@@ -1,5 +1,6 @@
1
1
  import { makeAutoObservable, observable, runInAction } from 'mobx'
2
2
  import type { SeedVar, ToggleVar, AnyVar } from 'src/vars/ComfyVars.ts'
3
+ import { ImagePickerSt } from 'src/cli/tui/imagePicker/ImagePickerSt.ts'
3
4
  import { DraftsSt } from 'src/cli/tui/state/DraftsSt.ts'
4
5
  import { EditorSt } from 'src/cli/tui/state/EditorSt.ts'
5
6
  import { ExecSt } from 'src/cli/tui/state/ExecSt.ts'
@@ -27,6 +28,7 @@ export type TuiMode =
27
28
  | 'overlay-choice'
28
29
  | 'overlay-size'
29
30
  | 'overlay-loras'
31
+ | 'overlay-image'
30
32
  | 'overlay-drafts'
31
33
 
32
34
  /**
@@ -41,6 +43,7 @@ export class TuiSt {
41
43
  editor: EditorSt
42
44
  picker: PickerSt
43
45
  loras: LorasSt
46
+ imagePicker: ImagePickerSt
44
47
  workflows: WorkflowsSt
45
48
  tree: TreeSt
46
49
  drafts: DraftsSt
@@ -55,7 +58,17 @@ export class TuiSt {
55
58
  disposers: (() => void)[] = []
56
59
  onExit: () => void = () => {}
57
60
 
58
- constructor(wf: DefinedWorkflow, opts: { workflowFiles?: string[]; currentFile?: string } = {}) {
61
+ constructor(
62
+ wf: DefinedWorkflow,
63
+ opts: {
64
+ workflowFiles?: string[]
65
+ currentFile?: string
66
+ /** files that came from the PACKAGED examples (grouped apart in the tree) */
67
+ bundledFiles?: Set<string>
68
+ /** modules that failed to load before mount (red rows in the tree) */
69
+ loadErrors?: Map<string, string>
70
+ } = {},
71
+ ) {
59
72
  this.wf = wf
60
73
  // wf: observable.ref so switching workflows re-renders without proxying
61
74
  // the foreign object; children manage their own observability
@@ -65,6 +78,7 @@ export class TuiSt {
65
78
  editor: false,
66
79
  picker: false,
67
80
  loras: false,
81
+ imagePicker: false,
68
82
  workflows: false,
69
83
  tree: false,
70
84
  drafts: false,
@@ -79,7 +93,14 @@ export class TuiSt {
79
93
  this.editor = new EditorSt(this)
80
94
  this.picker = new PickerSt(this)
81
95
  this.loras = new LorasSt(this)
82
- this.workflows = new WorkflowsSt(this, opts.workflowFiles ?? [], opts.currentFile ?? null)
96
+ this.imagePicker = new ImagePickerSt(this)
97
+ this.workflows = new WorkflowsSt(
98
+ this,
99
+ opts.workflowFiles ?? [],
100
+ opts.currentFile ?? null,
101
+ opts.bundledFiles,
102
+ opts.loadErrors,
103
+ )
83
104
  this.tree = new TreeSt(this)
84
105
  this.drafts = new DraftsSt(this)
85
106
  this.exec = new ExecSt(this)
@@ -122,7 +143,9 @@ export class TuiSt {
122
143
  get treeWidth(): number {
123
144
  const longest = Math.max(
124
145
  8,
125
- ...this.tree.rows.map((r) => (r.kind === 'workflow' ? r.name.length : r.draft.length + 3)),
146
+ ...this.tree.rows.map((r) =>
147
+ r.kind === 'workflow' ? r.name.length : r.kind === 'draft' ? r.draft.length + 3 : r.label.length,
148
+ ),
126
149
  )
127
150
  return Math.min(32, longest + 7)
128
151
  }
@@ -154,6 +177,7 @@ export class TuiSt {
154
177
  else if (sel.kind === 'choice') this.picker.beginChoice()
155
178
  else if (sel.kind === 'size') this.picker.beginSize()
156
179
  else if (sel.kind === 'loras') this.loras.begin()
180
+ else if (sel.kind === 'image') this.imagePicker.begin()
157
181
  else this.editor.beginInline() // int / float / seed: type the number
158
182
  }
159
183
 
@@ -12,8 +12,12 @@ export class WorkflowsSt {
12
12
  private st: TuiSt,
13
13
  public files: string[],
14
14
  currentPath: string | null = null,
15
+ bundled: Set<string> = new Set(),
16
+ loadErrors: Map<string, string> = new Map(),
15
17
  ) {
16
18
  this.currentPath = currentPath
19
+ this.bundled = bundled
20
+ this.loadErrors = loadErrors
17
21
  makeAutoObservable<WorkflowsSt, 'st'>(this, { st: false })
18
22
  }
19
23
 
@@ -21,6 +25,13 @@ export class WorkflowsSt {
21
25
  currentPath: string | null
22
26
  loading: boolean = false
23
27
 
28
+ /** the subset of files that came from the PACKAGED examples (grouped apart in the tree) */
29
+ bundled: Set<string>
30
+
31
+ /** per-file load failures (import threw / no DefinedWorkflow export) — red rows in the tree,
32
+ * cleared by a later successful load; ⏎ on the row retries */
33
+ loadErrors: Map<string, string>
34
+
24
35
  /**
25
36
  * every host seen across switches. Modules are import-cached, so a
26
37
  * switched-away host must stay connected (switching back reuses it) — exit
@@ -65,6 +76,7 @@ export class WorkflowsSt {
65
76
  const wf = findDefinedWorkflow(mod)
66
77
  if (wf == null) throw new Error(`${path} exports no DefinedWorkflow`)
67
78
  runInAction(() => {
79
+ this.loadErrors.delete(path)
68
80
  this.loadedHosts.add(this.st.wf.host)
69
81
  this.loadedHosts.add(wf.host)
70
82
  this.st.wf = wf
@@ -81,8 +93,10 @@ export class WorkflowsSt {
81
93
  })
82
94
  } catch (e) {
83
95
  runInAction(() => {
96
+ const msg = extractErrorMessage(e)
97
+ this.loadErrors.set(path, msg)
84
98
  this.st.mode = 'nav'
85
- this.st.exec.error = extractErrorMessage(e)
99
+ this.st.exec.error = msg
86
100
  })
87
101
  } finally {
88
102
  runInAction(() => {
@@ -0,0 +1,56 @@
1
+ import { existsSync, readFileSync } from 'node:fs'
2
+ import { fileURLToPath } from 'node:url'
3
+ import { dirname, join } from 'pathe'
4
+
5
+ /**
6
+ * the examples/ folder shipped in the npm tarball, resolved from THIS module's
7
+ * own location (NEVER cwd): walking up to the nearest NAMED package.json finds
8
+ * <pkg>/examples both from a consumer's node_modules/comfy-ts/dist/ and from
9
+ * this repo's src/. Returns null when the examples are absent (a consumer may
10
+ * prune the folder) or when the nearest named package is not comfy-ts (the lib
11
+ * was inlined into someone else's bundle — its examples are not on disk); no
12
+ * package.json all the way up is a broken install and throws.
13
+ */
14
+ export function bundledExamplesDir(moduleUrl: string = import.meta.url): string | null {
15
+ let dir = dirname(fileURLToPath(moduleUrl))
16
+ let prev = ''
17
+ while (dir !== prev) {
18
+ const pkgPath = join(dir, 'package.json')
19
+ if (existsSync(pkgPath)) {
20
+ let pkg: { name?: string } = {}
21
+ try {
22
+ pkg = JSON.parse(readFileSync(pkgPath, 'utf8'))
23
+ } catch {
24
+ // a malformed package.json on the walk (someone's broken fixture
25
+ // dir) must not take the whole TUI down; treat as unnamed
26
+ }
27
+ if (pkg.name === 'comfy-ts') {
28
+ const examples = join(dir, 'examples')
29
+ return existsSync(examples) ? examples : null
30
+ }
31
+ if (pkg.name != null) return null
32
+ }
33
+ prev = dir
34
+ dir = dirname(dir)
35
+ }
36
+ throw new Error(`[comfy-ts] no package.json found walking up from ${fileURLToPath(moduleUrl)}`)
37
+ }
38
+
39
+ /**
40
+ * absolute path of a bundled `examples/images/` input image, e.g.
41
+ * `exampleImagePath('bear_1024x1024.jpg')` — the out-of-the-box default for
42
+ * i2i/i2v example image vars, valid from this repo AND from a consumer's
43
+ * node_modules/comfy-ts/. Loud throw naming the path when the file is missing
44
+ * or the package's examples/ folder was pruned.
45
+ */
46
+ export function exampleImagePath(name: string): string {
47
+ const examples = bundledExamplesDir()
48
+ if (examples == null) {
49
+ throw new Error(
50
+ `[comfy-ts] cannot resolve bundled example image '${name}': the package's examples/ folder is not on disk`,
51
+ )
52
+ }
53
+ const abs = join(examples, 'images', name)
54
+ if (!existsSync(abs)) throw new Error(`[comfy-ts] bundled example image not found: ${abs}`)
55
+ return abs
56
+ }
@@ -179,7 +179,10 @@ export class ComfyNode<
179
179
  for (const i of this.$schema.inputs) {
180
180
  _done.add(i.nameInComfy)
181
181
  const value = this.serializeValue(i.nameInComfy, promptExt.inputs[i.nameInComfy])
182
- inputs[i.nameInComfy] = value
182
+ // absent optionals (autogrow containers included) stay OUT of the
183
+ // prompt: an `undefined` value would already be dropped by JSON
184
+ // serialization, keeping the key would only lie to Object.keys
185
+ if (value !== undefined) inputs[i.nameInComfy] = value
183
186
  }
184
187
  for (const [nameInComfy, rawVal] of Object.entries(promptExt.inputs)) {
185
188
  if (_done.has(nameInComfy)) continue