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
@@ -8,7 +8,15 @@ console.clear()
8
8
  console.log(chalk.bold.greenBright('UPDADING COMFY MANAGER JSONS'))
9
9
 
10
10
  // should take care of the code generation
11
- await ComfyRegistry.DownloadAndUpdate(!skipDL)
11
+ const registry = await ComfyRegistry.DownloadAndUpdate(!skipDL)
12
+
13
+ console.log(chalk.bold.greenBright('REGISTRY TOTALS'))
14
+ console.log(` plugins (by title): ${registry.plugins_byTitle.size}`)
15
+ console.log(` plugin repo urls: ${registry.plugins_byFile.size}`)
16
+ console.log(` custom node keys: ${registry.plugins_byNodeKey.size}`)
17
+ console.log(` models: ${registry.knownModels.size}`)
18
+ console.log(` alterations: ${registry.alterations.length}`)
19
+ console.log(` github stats: ${registry.githubStats.size}`)
12
20
 
13
21
  // the generator aligns its own `// x N` comments and emits trailing blank
14
22
  // lines; oxfmt disagrees on both, so WITHOUT this the ci gate goes red right
@@ -0,0 +1,13 @@
1
+ import { type } from 'arktype'
2
+
3
+ /** ONE alter-list.json row (a1111 extension → comfy alternative); `tags` is a comma-separated STRING upstream */
4
+ export type ComfyManagerAlterInfo = typeof ComfyManagerAlterInfo_ark.infer
5
+ export const ComfyManagerAlterInfo_ark = type({
6
+ id: 'string', // "https://github.com/comfyanonymous/ComfyUI"
7
+ tags: 'string', // "SD1.x,SD2.x,SDXL"
8
+ description: 'string',
9
+ })
10
+
11
+ /** root shape only: rows are validated ONE BY ONE */
12
+ export type ComfyManagerFileAlterListRoot = typeof ComfyManagerFileAlterListRoot_ark.infer
13
+ export const ComfyManagerFileAlterListRoot_ark = type({ items: 'unknown[]' })
@@ -1,5 +1,9 @@
1
1
  import { type } from 'arktype'
2
- import { ComfyManagerModelInfo_ark } from 'src/manager/types/ComfyManagerModelInfo.ts'
2
+ import type { ComfyManagerModelInfo } from 'src/manager/types/ComfyManagerModelInfo.ts'
3
3
 
4
- export type ComfyManagerFileModelInfo = typeof ComfyManagerFileModelInfo_ark.infer
5
- export const ComfyManagerFileModelInfo_ark = type({ models: ComfyManagerModelInfo_ark.array() })
4
+ /** root shape only: rows are validated ONE BY ONE against ComfyManagerModelInfo_ark */
5
+ export type ComfyManagerFileModelInfoRoot = typeof ComfyManagerFileModelInfoRoot_ark.infer
6
+ export const ComfyManagerFileModelInfoRoot_ark = type({ models: 'unknown[]' })
7
+
8
+ /** hand-maintained extras (model-list.extra.ts) still declare the full canonical shape */
9
+ export type ComfyManagerFileModelInfo = { models: ComfyManagerModelInfo[] }
@@ -2,12 +2,9 @@ import { type } from 'arktype'
2
2
  import { ComfyManagerPluginContentMetadata_ark } from 'src/manager/types/ComfyManagerPluginContentMetadata.ts'
3
3
  import { ComfyManagerPluginContentNodeName_ark } from 'src/manager/types/ComfyManagerPluginEnums.ts'
4
4
 
5
- export type ComfyManagerFilePluginContent = typeof ComfyManagerFilePluginContent_ark.infer
6
- export const ComfyManagerFilePluginContent_ark = type.Record(
7
- 'string',
8
- type([
9
- //
10
- ComfyManagerPluginContentNodeName_ark.array(),
11
- ComfyManagerPluginContentMetadata_ark,
12
- ]),
13
- )
5
+ /** ONE extension-node-map entry value: [nodeNames, meta]; the file root is a Record of these, validated row by row */
6
+ export type ComfyManagerExtensionNodeMapEntry = typeof ComfyManagerExtensionNodeMapEntry_ark.infer
7
+ export const ComfyManagerExtensionNodeMapEntry_ark = type([
8
+ ComfyManagerPluginContentNodeName_ark.array(),
9
+ ComfyManagerPluginContentMetadata_ark,
10
+ ])
@@ -1,5 +1,5 @@
1
1
  import { type } from 'arktype'
2
- import { ComfyManagerPluginInfo_ark } from 'src/manager/types/ComfyManagerPluginInfo.ts'
3
2
 
4
- export type ComfyManagerFilePluginList = typeof ComfyManagerFilePluginList_ark.infer
5
- export const ComfyManagerFilePluginList_ark = type({ custom_nodes: ComfyManagerPluginInfo_ark.array() })
3
+ /** root shape only: rows are validated ONE BY ONE against ComfyManagerRawPluginInfo_ark */
4
+ export type ComfyManagerFilePluginListRoot = typeof ComfyManagerFilePluginListRoot_ark.infer
5
+ export const ComfyManagerFilePluginListRoot_ark = type({ custom_nodes: 'unknown[]' })
@@ -0,0 +1,9 @@
1
+ import { type } from 'arktype'
2
+
3
+ /** ONE github-stats.json entry, keyed by repo url in the file root (a Record, validated row by row) */
4
+ export type ComfyManagerGithubStatEntry = typeof ComfyManagerGithubStatEntry_ark.infer
5
+ export const ComfyManagerGithubStatEntry_ark = type({
6
+ stars: 'number',
7
+ last_update: 'string', // "2026-07-28 03:14:59"
8
+ author_account_age_days: 'number',
9
+ })
@@ -2,9 +2,8 @@ import { type } from 'arktype'
2
2
 
3
3
  export type ComfyManagerPluginContentMetadata = typeof ComfyManagerPluginContentMetadata_ark.infer
4
4
  export const ComfyManagerPluginContentMetadata_ark = type({
5
- // optional because on damn validation on comfy manager! 😬
6
- // should have been always present
7
- title_aux: type.string.or(type.null), // "Jovimetrix Composition Nodes",
5
+ // absent on 10/5573 upstream rows (2026-07-30), null on others
6
+ 'title_aux?': type.string.or(type.null), // "Jovimetrix Composition Nodes",
8
7
 
9
8
  // optional
10
9
  'author?': 'string', // "amorano",
@@ -3,48 +3,62 @@ import type { KnownComfyPluginTitle } from 'src/manager/generated/KnownComfyPlug
3
3
  import type { KnownComfyPluginURL } from 'src/manager/generated/KnownComfyPluginURL.ts'
4
4
  import type { ComfyManagerPluginID } from 'src/manager/types/ComfyManagerPluginEnums.ts'
5
5
 
6
- export type ComfyManagerPluginInfo = typeof ComfyManagerPluginInfo_ark.infer
7
- export const ComfyManagerPluginInfo_ark = type({
8
- // required
9
- author: 'string', // "Dr.Lt.Data",
10
- title: type.string.as<KnownComfyPluginTitle>(), // "ComfyUI-Manager",
11
- reference: 'string', // "https://github.com/ltdrdata/ComfyUI-Manager",
12
- files: type.string.as<KnownComfyPluginURL>().array(), // ["https://github.com/ltdrdata/ComfyUI-Manager"],
13
- install_type: 'string', // "git-clone",
14
- description: 'string', // "ComfyUI-Manager itself is also a custom node."
6
+ /**
7
+ * loose INPUT schema: what Comfy-Org/ComfyUI-Manager custom-node-list.json
8
+ * actually ships (surveyed 2026-07-30, 5882 rows)
9
+ */
10
+ export type ComfyManagerRawPluginInfo = typeof ComfyManagerRawPluginInfo_ark.infer
11
+ export const ComfyManagerRawPluginInfo_ark = type({
12
+ // always present upstream
13
+ author: 'string',
14
+ title: type.string.as<KnownComfyPluginTitle>(),
15
+ reference: 'string',
16
+ files: type.string.as<KnownComfyPluginURL>().array(),
17
+ install_type: 'string', // 'git-clone' | 'copy' | 'unzip' | stray casings
18
+ description: 'string',
15
19
 
16
- // optional, but shouldn't, so they'll pre-emptively auto-fixed before validation
17
- id: type.string.as<ComfyManagerPluginID>(), // on 2024-11-09, 579 fields are missing this
20
+ // absent on 4471/5882 rows (2026-07-30): recovered at normalization
21
+ 'id?': type.string.as<ComfyManagerPluginID>(),
18
22
 
19
- // optional
23
+ // sparse optional tail
20
24
  'preemptions?': 'string[]',
21
25
  'pip?': 'string[]',
22
26
  'nodename_pattern?': 'string',
23
27
  'apt_dependency?': 'string[]',
24
28
  'js_path?': 'string',
25
29
  'version?': 'string',
30
+ 'tags?': 'string[]',
26
31
 
27
- // optional ?
28
- // (probably not really well specified, sicne some of those only appear one or two times)
29
- 'tags?': 'string[]', // 🔶 as of 2024-11-09, this shows only one time
32
+ // 2025/2026 additions, unconsumed but declared so drift stays visible
33
+ 'reference2?': 'string',
34
+ 'category?': 'string',
35
+ 'name?': 'string',
36
+ 'license?': 'string',
37
+ 'nickname?': 'string',
38
+ 'stars?': 'number',
39
+ 'last_update?': 'string',
40
+ 'badges?': 'string[]',
41
+ 'dependencies?': 'string[]',
30
42
  })
31
43
 
32
- // export type ComfyManagerPluginInfo = {
33
- // // required
34
- // author: string // "Dr.Lt.Data",
35
- // title: KnownComfyPluginTitle // "ComfyUI-Manager",
36
- // reference: string // "https://github.com/ltdrdata/ComfyUI-Manager",
37
- // files: KnownComfyPluginURL[] // ["https://github.com/ltdrdata/ComfyUI-Manager"],
38
- // install_type: string // "git-clone",
39
- // description: string // "ComfyUI-Manager itself is also a custom node."
40
-
41
- // // optional, but shouldn't
42
- // // optional
43
- // id?: ComfyManagerPluginID // Added in 2024-??
44
- // preemptions?: string[] // ❓
45
- // pip?: string[] // [ "ultralytics" ],
46
- // nodename_pattern?: string // "Inspire$",
47
- // apt_dependency?: string[] // [ "rustc", "cargo" ],
48
- // js_path?: string // "strimmlarn",
49
- // version?: string
50
- // }
44
+ /**
45
+ * canonical plugin row: `id` ALWAYS present (normalization recovers it).
46
+ * The optional tail stays optional ON PURPOSE: this object is also the
47
+ * Manager v2 install POST body, where absent and null differ python-side.
48
+ */
49
+ export type ComfyManagerPluginInfo = {
50
+ id: ComfyManagerPluginID
51
+ author: string
52
+ title: KnownComfyPluginTitle
53
+ reference: string
54
+ files: KnownComfyPluginURL[]
55
+ install_type: string
56
+ description: string
57
+ preemptions?: string[]
58
+ pip?: string[]
59
+ nodename_pattern?: string
60
+ apt_dependency?: string[]
61
+ js_path?: string
62
+ version?: string
63
+ tags?: string[]
64
+ }
@@ -201,9 +201,8 @@ export class ComfyExecution {
201
201
  const promptMeta = this.workflow.data.metadata?.[promptNodeID]
202
202
  if (promptNode == null) throw new Error(`❌ invariant violation: promptNode is null`)
203
203
 
204
- // get image url from ComfyUI
205
- const serverURL = this.host.getServerHostHTTP()
206
- const imgUrl = serverURL + '/view?' + new URLSearchParams(comfyImageInfo).toString()
204
+ // image route on the host (cloud answers a 302 signed url — fetchFile follows it unauthed)
205
+ const imgRoute = '/view?' + new URLSearchParams(comfyImageInfo).toString()
207
206
 
208
207
  // target path on disk
209
208
  const sf = this.saveFormat
@@ -222,7 +221,7 @@ export class ComfyExecution {
222
221
 
223
222
  // RE-ENCODE (COMPRESSED)
224
223
  if (sf && sf.format !== 'raw') {
225
- const response = await fetch(imgUrl, { headers: { 'Content-Type': 'image/png' }, method: 'GET' })
224
+ const response = await this.host.fetchFile(imgRoute)
226
225
  const buff = await response.arrayBuffer()
227
226
  let textChunk = {}
228
227
  try {
@@ -257,7 +256,7 @@ export class ComfyExecution {
257
256
 
258
257
  // SAVE RAW ------------------------------------------------------------------------------------------
259
258
  else {
260
- const response = await fetch(imgUrl, { headers: { 'Content-Type': 'image/png' }, method: 'GET' })
259
+ const response = await this.host.fetchFile(imgRoute)
261
260
  const buff = await response.arrayBuffer()
262
261
  const uint8arr = new Uint8Array(buff)
263
262
  writeFileSync(absPath, uint8arr)
@@ -363,9 +363,9 @@ export class ComfyWorkflow<ID extends string = string> {
363
363
  },
364
364
  }
365
365
 
366
- const promptEndpoint = `${this.host.getServerHostHTTP()}/prompt`
367
- const res = await fetch(promptEndpoint, {
366
+ const res = await this.host.fetch('/prompt', {
368
367
  method: 'POST',
368
+ headers: { 'Content-Type': 'application/json' },
369
369
  body: JSON.stringify(out),
370
370
  })
371
371
  const promptInfoJson = await res.json()
@@ -0,0 +1,48 @@
1
+ // pure parser for BINARY ws frames (formats per
2
+ // agent/external-docs/comfy-cloud/api-reference.md, all integers big-endian):
3
+ // 1 PREVIEW_IMAGE 4B type · 4B image_type (1 jpeg, 2 png) · image bytes
4
+ // 3 TEXT 4B type · 4B node_id_len · node_id · progress text
5
+ // 4 PREVIEW_IMAGE_WITH_METADATA 4B type · 4B metadata_len · metadata JSON · image bytes
6
+ // Unknown types come back as 'unknown' — the CALLER logs, never throws: the
7
+ // wire drifts faster than we do (type 4 appeared on the first live cloud run).
8
+
9
+ export type ParsedBinaryWsFrame =
10
+ | { kind: 'preview'; bytes: Uint8Array<ArrayBuffer>; mime: string; metadata: unknown }
11
+ | { kind: 'text'; nodeId: string; text: string }
12
+ | { kind: 'unknown'; eventType: number }
13
+
14
+ export function parseBinaryWsFrame(data: ArrayBuffer): ParsedBinaryWsFrame {
15
+ const view = new DataView(data)
16
+ const eventType = view.getUint32(0)
17
+
18
+ if (eventType === 1) {
19
+ const imageType = view.getUint32(4)
20
+ const bytes = new Uint8Array(data.slice(8))
21
+ const mime = imageType === 2 ? 'image/png' : 'image/jpeg'
22
+ return { kind: 'preview', bytes, mime, metadata: null }
23
+ }
24
+
25
+ if (eventType === 3) {
26
+ const nodeIdLen = view.getUint32(4)
27
+ const decoder = new TextDecoder()
28
+ const nodeId = decoder.decode(data.slice(8, 8 + nodeIdLen))
29
+ const text = decoder.decode(data.slice(8 + nodeIdLen))
30
+ return { kind: 'text', nodeId, text }
31
+ }
32
+
33
+ if (eventType === 4) {
34
+ const metadataLen = view.getUint32(4)
35
+ let metadata: unknown = null
36
+ try {
37
+ metadata = JSON.parse(new TextDecoder().decode(data.slice(8, 8 + metadataLen)))
38
+ } catch {
39
+ // tolerate broken metadata: the image bytes are the payload that matters
40
+ }
41
+ const bytes = new Uint8Array(data.slice(8 + metadataLen))
42
+ // the docs say "raw JPEG/PNG bytes" with no format field — sniff the magic
43
+ const mime = bytes[0] === 0x89 && bytes[1] === 0x50 ? 'image/png' : 'image/jpeg'
44
+ return { kind: 'preview', bytes, mime, metadata }
45
+ }
46
+
47
+ return { kind: 'unknown', eventType }
48
+ }
@@ -4,6 +4,7 @@ import { toQualifiedNodeKey } from 'src/sdk-generator/_toQualifiedNodeKey.ts'
4
4
  import { ComfyNodeSchema } from 'src/sdk-generator/ComfyNodeSchema.ts'
5
5
  import type { ComfyEnumDef, ComfyNodeSchemaJSON, ComfySchemaJSON } from 'src/sdk-generator/ComfyUIObjectInfoTypes.ts'
6
6
  import { codegenSDK } from 'src/sdk-generator/comfyui-sdk-codegen.ts'
7
+ import { classifyWidgetInput, containerInstanceSlotType } from 'src/sdk-generator/inputWidgetKind.ts'
7
8
  import {
8
9
  asComfyNodeSlotName,
9
10
  asComfyNodeSlotTypeName,
@@ -233,9 +234,21 @@ export class ComfySchema {
233
234
  )
234
235
  }
235
236
 
237
+ // autogrow container: the declaration is never a prompt input
238
+ // (instances are `<name>.<inst>` link slots) — never required, and
239
+ // its template sub-input slot type registers like any slot so
240
+ // codegen can type the dotted instance keys (agent/sdk-codegen.md)
241
+ const isAutogrowContainer =
242
+ typeof slotType === 'string' &&
243
+ classifyWidgetInput({ name: ipt.name, type: slotType, opts: slotOpts }).kind === 'dynamic-container'
244
+ if (isAutogrowContainer) {
245
+ const instType = containerInstanceSlotType(slotOpts)
246
+ if (instType != null) this.knownSlotTypes.add(asComfyNodeSlotTypeName(instType))
247
+ }
248
+
236
249
  node.inputs.push({
237
250
  slotName: inputSlotName,
238
- required: ipt.required,
251
+ required: ipt.required && !isAutogrowContainer,
239
252
  nameInComfy: inputNameInComfy,
240
253
  nameInComfyEscaped: escapeJSKey(inputNameInComfy),
241
254
  typeName: inputTypeName,
@@ -1,6 +1,4 @@
1
- import type { LiteGraphNode } from 'src/litegraph/LiteGraphNode.ts'
2
1
  import type { ComfyNodeSchemaJSON } from 'src/sdk-generator/ComfyUIObjectInfoTypes.ts'
3
- import type { NodeInputExt } from 'src/sdk-generator/comfyui-types.ts'
4
2
 
5
3
  export const ComfyPrimitiveMapping: { [key: string]: string } = {
6
4
  // BACK
@@ -20,24 +18,14 @@ export const ComfyPrimitiveMapping: { [key: string]: string } = {
20
18
 
21
19
  export const ComfyPrimitives: string[] = Object.keys(ComfyPrimitiveMapping)
22
20
 
23
- /**
24
- * when a litegraph node has no input for a given ComfyUI node input
25
- * (e.g. a seed or an enum that has not been turned into a primitive)
26
- */
27
- export const howManyWidgetValuesForThisSchemaType = (input: NodeInputExt): number => {
28
- if (input.typeName === 'INT') {
29
- if (input.nameInComfy === 'seed' || input.nameInComfy === 'noise_seed') return 2
30
- }
31
- if (input.isPrimitive) return 1
32
- // 🔴
33
- if (input.typeName.startsWith('E_')) return 1
34
- // console.log(343, input)
35
- return 0
36
- }
21
+ // schema-driven widget counting moved to src/sdk-generator/inputWidgetKind.ts
22
+ // (config-driven classification); what stays below is the LEGACY serialized-
23
+ // type path, used only when an old file carries a widget-marked input whose
24
+ // schema now says slot.
37
25
 
38
26
  /**
39
- * then a litegraph node has an input entry, some convoluted logic seems to be necessary
40
- * to determine how many Field_values need to be consumed for this input
27
+ * when a litegraph node has an input entry with a widget marker, the
28
+ * serialized TYPE string decides how many widgets_values it consumed in that era
41
29
  */
42
30
  export const howManyWidgetValuesForThisInputType = (type: string, nameInComfy: string): number => {
43
31
  if (type === 'INT') {
@@ -68,9 +56,3 @@ export const ComfyDefaultNodeWhenUnknown_Schema: ComfyNodeSchemaJSON = {
68
56
  output_node: false,
69
57
  python_module: 'nodes',
70
58
  }
71
-
72
- export class UnknownCustomNode extends Error {
73
- constructor(public node: LiteGraphNode) {
74
- super(`❌ node ${node.id}(${node.type}) has no known schema; you probably need to install some custom node`)
75
- }
76
- }
@@ -9,8 +9,10 @@ export type ComfyApiJson = {
9
9
 
10
10
  export type ComfyApiNodeJson = {
11
11
  inputs: {
12
+ // object form: custom-widget values pass through verbatim, array widget
13
+ // values ride wrapped as { __value__: [...] } (a bare 2-list is a link)
12
14
  // prettier-ignore
13
- [key: string]: [string, number] | string | number | boolean | null
15
+ [key: string]: [string, number] | string | number | boolean | null | { [key: string]: unknown }
14
16
  }
15
17
  class_type: string
16
18
  }
@@ -4,6 +4,7 @@ import { escapeJSKey } from 'src/utils/escapeJSKey.ts'
4
4
  import type { ComfySchema } from 'src/sdk-generator/ComfySchema.ts'
5
5
 
6
6
  import { type ComfyNodeSchema, wrapQuote } from 'src/sdk-generator/ComfyNodeSchema.ts'
7
+ import { classifySchemaInput, containerInstanceSlotType } from 'src/sdk-generator/inputWidgetKind.ts'
7
8
 
8
9
  /**
9
10
  * convert a host id to the namespace name it gets inside the global `Comfy` namespace
@@ -76,6 +77,20 @@ export function codegenSDK(this: ComfySchema, opts: CodegenOptions): string {
76
77
  for (const n of nodes) {
77
78
  p(`${escapeJSKey(n.nodeKey)}: {`)
78
79
  for (const i of n.inputs) {
80
+ // autogrow container: emit dotted instance keys, never the container
81
+ // decl itself — the backend prompt input is `<name>.<inst>`, the
82
+ // first template.min instances required (agent/sdk-codegen.md)
83
+ const kind = classifySchemaInput(i)
84
+ if (kind.kind === 'dynamic-container') {
85
+ const instType = containerInstanceSlotType(i.opts)
86
+ if (instType != null) {
87
+ kind.instanceNames.forEach((instName, ix) => {
88
+ const opt = ix >= kind.requiredCount ? '?' : ''
89
+ p(` ${escapeJSKey(`${i.nameInComfy}.${instName}`)}${opt}: Accepts[${JSON.stringify(instType)}]`)
90
+ })
91
+ }
92
+ continue
93
+ }
79
94
  const opts_ = typeof i.opts === 'string' ? null : i.opts
80
95
  let type = `Accepts[${JSON.stringify(i.typeName)}]`
81
96
  // COMBO inputs (ComfyUI ≥ 0.3.x) carry literal choices in opts.options
@@ -0,0 +1,196 @@
1
+ import type { NodeInputExt } from 'src/sdk-generator/comfyui-types.ts'
2
+ import { ComfyPrimitiveMapping } from 'src/sdk-generator/Primitives.ts'
3
+
4
+ /**
5
+ * Widget-ness of a schema input, decided from its CONFIG — never from a
6
+ * type-name whitelist (2026 object_info spells widget inputs as arbitrary
7
+ * strings backed by a frontend widget registry we cannot mirror; every
8
+ * registry spelling carries a config signal instead). Signal precedence and
9
+ * their upstream anchors: agent/architecture.md "Widget-ness is decided from
10
+ * the input CONFIG".
11
+ */
12
+ export type InputWidgetKind =
13
+ | { kind: 'slot' }
14
+ | { kind: 'widget'; consumes: 1 | 2; strictValues: boolean }
15
+ | { kind: 'dynamic-combo'; options: DynamicComboOption[]; defaultKey: string }
16
+ | { kind: 'dynamic-container'; instanceNames: string[]; requiredCount: number }
17
+
18
+ /** one raw `[type, opts]` input entry as spelled in object_info (dynamic-combo branches arrive in this raw form) */
19
+ export type RawInputSpecEntry = {
20
+ name: string
21
+ type: string | readonly unknown[]
22
+ opts: unknown
23
+ required: boolean
24
+ }
25
+
26
+ export type DynamicComboOption = { key: string; inputs: RawInputSpecEntry[] }
27
+
28
+ export const isRecord = (x: unknown): x is Record<string, unknown> =>
29
+ typeof x === 'object' && x != null && !Array.isArray(x)
30
+
31
+ /**
32
+ * seed phantom: a TRUTHY `control_after_generate` adds one consumed value.
33
+ * The frontend creates the control widget on truthiness, and real 2026 hosts
34
+ * spell it as `true` OR as a string mode like `'fixed'` (PrimitiveInt.value,
35
+ * SeedNode.seed). When the KEY is absent (2024 era) the INT-named-seed
36
+ * heuristic applies.
37
+ */
38
+ const controlConsumes = (o: Record<string, unknown> | null, typeName: string, name: string): 1 | 2 => {
39
+ if (o != null && 'control_after_generate' in o) return o['control_after_generate'] ? 2 : 1
40
+ if (typeName === 'INT' && (name === 'seed' || name === 'noise_seed')) return 2
41
+ return 1
42
+ }
43
+
44
+ const flattenInputSections = (inputs: Record<string, unknown>): RawInputSpecEntry[] => {
45
+ const out: RawInputSpecEntry[] = []
46
+ for (const section of ['required', 'optional'] as const) {
47
+ const sec = inputs[section]
48
+ if (!isRecord(sec)) continue
49
+ for (const [name, spec] of Object.entries(sec)) {
50
+ if (!Array.isArray(spec) || spec.length === 0) continue
51
+ const t: unknown = spec[0]
52
+ if (typeof t !== 'string' && !Array.isArray(t)) continue
53
+ out.push({ name, type: t, opts: spec[1], required: section === 'required' })
54
+ }
55
+ }
56
+ return out
57
+ }
58
+
59
+ /** null when the options array is NOT the dynamic `{key, inputs}` family (then it is a plain combo) */
60
+ const parseDynamicOptions = (options: unknown[]): DynamicComboOption[] | null => {
61
+ if (options.length === 0) return null
62
+ const out: DynamicComboOption[] = []
63
+ for (const entry of options) {
64
+ if (!isRecord(entry)) return null
65
+ const key = entry['key']
66
+ const inputs = entry['inputs']
67
+ if (typeof key !== 'string' || !isRecord(inputs)) return null
68
+ out.push({ key, inputs: flattenInputSections(inputs) })
69
+ }
70
+ return out
71
+ }
72
+
73
+ /**
74
+ * autogrow (`template` WITH a nested `input` section): instances are always
75
+ * link slots named `decl.<name_i>` (the backend force-inputs widget
76
+ * templates), the first `min` of them required WHEN the template input
77
+ * section is `required` — mirrors `_io.py Autogrow._expand_schema_for_dynamic`.
78
+ */
79
+ const parseContainer = (template: Record<string, unknown>): InputWidgetKind => {
80
+ const input = template['input']
81
+ const min = typeof template['min'] === 'number' ? template['min'] : 1
82
+ const prefix = typeof template['prefix'] === 'string' ? template['prefix'] : ''
83
+ const max = typeof template['max'] === 'number' ? template['max'] : 100
84
+ const rawNames = template['names']
85
+ const names = Array.isArray(rawNames)
86
+ ? rawNames.filter((n): n is string => typeof n === 'string')
87
+ : Array.from({ length: max }, (_, i) => `${prefix}${i}`)
88
+ const templateRequired = isRecord(input) && isRecord(input['required']) && Object.keys(input['required']).length > 0
89
+ return {
90
+ kind: 'dynamic-container',
91
+ instanceNames: names,
92
+ requiredCount: templateRequired ? Math.min(min, names.length) : 0,
93
+ }
94
+ }
95
+
96
+ /**
97
+ * the single template sub-input's slot type of an autogrow container
98
+ * (`'IMAGE'` for TextEncodeBooguEdit.images). null when opts are not an
99
+ * autogrow template or the template has several sub-inputs (corpus-absent
100
+ * 2026-07-30, 27/27 single on the cloud catalog) — then codegen emits no
101
+ * typed instance keys and the container stays builderBase territory.
102
+ */
103
+ export const containerInstanceSlotType = (opts: unknown): string | null => {
104
+ const o = isRecord(opts) ? opts : null
105
+ const template = o?.['template']
106
+ if (!isRecord(template) || !isRecord(template['input'])) return null
107
+ const subs = flattenInputSections(template['input'])
108
+ const first = subs[0]
109
+ if (subs.length !== 1 || first == null || typeof first.type !== 'string') return null
110
+ return first.type
111
+ }
112
+
113
+ export const classifyWidgetInput = (p: {
114
+ name: string
115
+ type: string | readonly unknown[]
116
+ opts: unknown
117
+ /** true when type is a generated `E_*` union name (parsed 2024-era enum) */
118
+ isEnumUnion?: boolean
119
+ }): InputWidgetKind => {
120
+ const o = isRecord(p.opts) ? p.opts : null
121
+ // 1. forceInput gates widget creation upstream, whatever the type says
122
+ if (o?.['forceInput'] === true) return { kind: 'slot' }
123
+ // 2. enum arrays / parsed E_ unions are combo widgets
124
+ if (Array.isArray(p.type) || p.isEnumUnion === true) {
125
+ const tn = typeof p.type === 'string' ? p.type : 'COMBO'
126
+ return { kind: 'widget', consumes: controlConsumes(o, tn, p.name), strictValues: true }
127
+ }
128
+ if (typeof p.type !== 'string') return { kind: 'slot' }
129
+ // 3. widgetType names the widget for multi-type unions (frontend: widgets.get(widgetType ?? type))
130
+ const widgetTypeName = typeof o?.['widgetType'] === 'string' ? o['widgetType'] : p.type
131
+ // 4. primitives
132
+ if (ComfyPrimitiveMapping[widgetTypeName] != null)
133
+ return { kind: 'widget', consumes: controlConsumes(o, widgetTypeName, p.name), strictValues: true }
134
+ // 5. options array: dynamic {key, inputs} family, else plain combo
135
+ const options = o?.['options']
136
+ if (Array.isArray(options)) {
137
+ const dynOptions = parseDynamicOptions(options)
138
+ if (dynOptions != null) {
139
+ const first = dynOptions[0]
140
+ if (first == null) return { kind: 'slot' } // unreachable: parseDynamicOptions rejects empty
141
+ const defaultKey = typeof o?.['default'] === 'string' ? o['default'] : first.key
142
+ return { kind: 'dynamic-combo', options: dynOptions, defaultKey }
143
+ }
144
+ return { kind: 'widget', consumes: controlConsumes(o, p.type, p.name), strictValues: true }
145
+ }
146
+ // 6. template WITH nested input = autogrow container; WITHOUT = matchtype slot typing
147
+ const template = o?.['template']
148
+ if (isRecord(template)) {
149
+ if (isRecord(template['input'])) return parseContainer(template)
150
+ return { kind: 'slot' }
151
+ }
152
+ // 7. socketless: a widget that never has a socket (IMAGECOMPARE, COLOR); value domain unknown
153
+ if (o?.['socketless'] === true) return { kind: 'widget', consumes: 1, strictValues: false }
154
+ return { kind: 'slot' }
155
+ }
156
+
157
+ export const classifySchemaInput = (input: NodeInputExt): InputWidgetKind =>
158
+ classifyWidgetInput({
159
+ name: input.nameInComfy,
160
+ type: input.typeName,
161
+ opts: input.opts,
162
+ isEnumUnion: input.isEnum,
163
+ })
164
+
165
+ /** how many widgets_values entries this schema input consumes (export path + positional walks) */
166
+ export const howManyWidgetValuesForThisSchemaType = (input: NodeInputExt): number => {
167
+ const kind = classifySchemaInput(input)
168
+ return kind.kind === 'widget' ? kind.consumes : 0
169
+ }
170
+
171
+ /**
172
+ * what ComfyUI's frontend gives a widget created with no serialized value
173
+ * (`getWidgetDefaultValue` semantics), used when a positional array is
174
+ * shorter than the schema's widget list. `null` for custom widgets — the
175
+ * backend accepts an explicit null but errors on an ABSENT required key.
176
+ */
177
+ export const defaultValueForWidget = (p: {
178
+ type: string
179
+ opts: unknown
180
+ /** resolved values when the type is a generated E_ union or an inline enum array */
181
+ enumValues?: readonly (string | boolean | number)[]
182
+ }): unknown => {
183
+ const o = isRecord(p.opts) ? p.opts : null
184
+ if (o != null && o['default'] !== undefined) return o['default']
185
+ const widgetTypeName = typeof o?.['widgetType'] === 'string' ? o['widgetType'] : p.type
186
+ if (widgetTypeName === 'INT' || widgetTypeName === 'FLOAT') return 0
187
+ if (widgetTypeName === 'BOOLEAN') return false
188
+ if (widgetTypeName === 'STRING') return ''
189
+ const options = o?.['options']
190
+ if (Array.isArray(options) && options.length > 0) {
191
+ const first: unknown = options[0]
192
+ if (typeof first === 'string' || typeof first === 'number' || typeof first === 'boolean') return first
193
+ }
194
+ if (p.enumValues != null && p.enumValues.length > 0) return p.enumValues[0]
195
+ return null
196
+ }