comfy-ts 0.2.0 → 0.3.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/LICENSE +21 -0
  2. package/README.md +363 -0
  3. package/dist/cli.js +764 -0
  4. package/dist/cli.js.map +1 -0
  5. package/dist/index.cjs +4128 -0
  6. package/dist/index.cjs.map +1 -0
  7. package/dist/index.d.cts +9862 -0
  8. package/dist/index.d.ts +9846 -58
  9. package/dist/index.js +4049 -2
  10. package/dist/index.js.map +1 -1
  11. package/dist/log-CdfgILde.js +10 -0
  12. package/dist/log-CdfgILde.js.map +1 -0
  13. package/dist/run-tui-Io8Xea0L.js +3340 -0
  14. package/dist/run-tui-Io8Xea0L.js.map +1 -0
  15. package/package.json +104 -75
  16. package/src/cli/comfy-ts-cli.ts +36 -0
  17. package/src/cli/gen.ts +47 -0
  18. package/src/cli/outline.ts +82 -0
  19. package/src/cli/tui/components/DraftsOverlay.tsx +44 -0
  20. package/src/cli/tui/components/EditField.tsx +27 -0
  21. package/src/cli/tui/components/Header.tsx +51 -0
  22. package/src/cli/tui/components/HostPanel.tsx +37 -0
  23. package/src/cli/tui/components/LorasOverlay.tsx +49 -0
  24. package/src/cli/tui/components/OverlayList.tsx +25 -0
  25. package/src/cli/tui/components/PickerOverlays.tsx +66 -0
  26. package/src/cli/tui/components/PreviewPanel.tsx +33 -0
  27. package/src/cli/tui/components/PromptOverlay.tsx +16 -0
  28. package/src/cli/tui/components/StatusBar.tsx +165 -0
  29. package/src/cli/tui/components/TextOverlay.tsx +72 -0
  30. package/src/cli/tui/components/TreePanel.tsx +51 -0
  31. package/src/cli/tui/components/TuiApp.tsx +223 -0
  32. package/src/cli/tui/components/VarsPanel.tsx +86 -0
  33. package/src/cli/tui/findDefinedWorkflow.ts +16 -0
  34. package/src/cli/tui/keys.ts +20 -0
  35. package/src/cli/tui/protocolImagePainter.ts +59 -0
  36. package/src/cli/tui/run-tui.tsx +73 -0
  37. package/src/cli/tui/state/DraftsSt.ts +273 -0
  38. package/src/cli/tui/state/EditorSt.ts +289 -0
  39. package/src/cli/tui/state/ExecSt.ts +170 -0
  40. package/src/cli/tui/state/HostSt.ts +107 -0
  41. package/src/cli/tui/state/LorasSt.ts +185 -0
  42. package/src/cli/tui/state/PickerSt.ts +112 -0
  43. package/src/cli/tui/state/PreviewSt.ts +138 -0
  44. package/src/cli/tui/state/QueueSt.ts +59 -0
  45. package/src/cli/tui/state/SettingsSt.ts +73 -0
  46. package/src/cli/tui/state/TreeSt.ts +122 -0
  47. package/src/cli/tui/state/TuiSt.ts +169 -0
  48. package/src/cli/tui/state/WorkflowsSt.ts +92 -0
  49. package/src/cli/tui-env.ts +8 -0
  50. package/src/errors/InvalidPromptError.ts +12 -0
  51. package/src/graph/ComfyNode.ts +403 -0
  52. package/src/graph/ComfyNodeID.ts +28 -0
  53. package/src/graph/ComfyNodeOutput.ts +16 -0
  54. package/src/graph/NodeSlotSize.ts +4 -0
  55. package/src/graph/autoValue.ts +17 -0
  56. package/src/host/ComfyHost.ts +646 -0
  57. package/src/host/ComfyInstallType.ts +15 -0
  58. package/src/host/ComfyManager.ts +232 -0
  59. package/src/host/ComfyUploader.ts +110 -0
  60. package/src/host/ComfyWorkflowBuilder.ts +60 -0
  61. package/src/host/Requirements.ts +55 -0
  62. package/src/host/ResilientWebsocket.ts +147 -0
  63. package/src/host/loraManagerApi.ts +98 -0
  64. package/src/image-utils/_getPngMetadata.ts +53 -0
  65. package/src/image-utils/_getWebpMetadata.ts +38 -0
  66. package/src/image-utils/_parseExifData.ts +53 -0
  67. package/src/index.ts +89 -0
  68. package/src/litegraph/LiteGraphGroup.ts +22 -0
  69. package/src/litegraph/LiteGraphJSON.ts +46 -0
  70. package/src/litegraph/LiteGraphLink.ts +23 -0
  71. package/src/litegraph/LiteGraphLinkID.ts +6 -0
  72. package/src/litegraph/LiteGraphNode.ts +69 -0
  73. package/src/litegraph/LiteGraphNodeInput.ts +27 -0
  74. package/src/litegraph/LiteGraphNodeOutput.ts +23 -0
  75. package/src/litegraph/LiteGraphSlotIndex.ts +6 -0
  76. package/src/litegraph/convertFlowToLiteGraphJSON.ts +114 -0
  77. package/src/manager/ComfyRegistry.ts +124 -0
  78. package/src/manager/generated/KnownComfyCustomNodeName.ts +19280 -0
  79. package/src/manager/generated/KnownComfyPluginTitle.ts +5130 -0
  80. package/src/manager/generated/KnownComfyPluginURL.ts +2589 -0
  81. package/src/manager/generated/KnownModel_Base.ts +126 -0
  82. package/src/manager/generated/KnownModel_FileName.ts +2287 -0
  83. package/src/manager/generated/KnownModel_Name.ts +2287 -0
  84. package/src/manager/generated/KnownModel_SavePath.ts +263 -0
  85. package/src/manager/generated/KnownModel_Type.ts +97 -0
  86. package/src/manager/json/alter-list.json +224 -0
  87. package/src/manager/json/custom-node-list.extra.ts +13 -0
  88. package/src/manager/json/custom-node-list.json +21948 -0
  89. package/src/manager/json/extension-node-map.json +31282 -0
  90. package/src/manager/json/github-stats.json +12602 -0
  91. package/src/manager/json/model-list.extra.ts +26 -0
  92. package/src/manager/json/model-list.json +5052 -0
  93. package/src/manager/loaders/step1_downloadComfyManagerJSONs.ts +56 -0
  94. package/src/manager/loaders/step2_custom-node-list-loader.ts +149 -0
  95. package/src/manager/loaders/step3_extension-node-map-loader.ts +189 -0
  96. package/src/manager/loaders/step4_model-list-loader.ts +159 -0
  97. package/src/manager/script-update-manager.bun.ts +18 -0
  98. package/src/manager/types/ComfyManagerAPIFetchPolicy.ts +9 -0
  99. package/src/manager/types/ComfyManagerAPIModelList.ts +10 -0
  100. package/src/manager/types/ComfyManagerAPIPluginList.ts +11 -0
  101. package/src/manager/types/ComfyManagerFileModelInfo.ts +5 -0
  102. package/src/manager/types/ComfyManagerFilePluginContent.ts +13 -0
  103. package/src/manager/types/ComfyManagerFilePluginList.ts +5 -0
  104. package/src/manager/types/ComfyManagerModelInfo.ts +18 -0
  105. package/src/manager/types/ComfyManagerPluginContentMetadata.ts +16 -0
  106. package/src/manager/types/ComfyManagerPluginEnums.ts +8 -0
  107. package/src/manager/types/ComfyManagerPluginInfo.ts +50 -0
  108. package/src/runner/ComfyExecution.ts +301 -0
  109. package/src/runner/ComfyExecutionStatus.ts +2 -0
  110. package/src/runner/ComfyWorkflow.ts +395 -0
  111. package/src/runner/ComfyWorkflowLayout.ts +96 -0
  112. package/src/runner/ComfyWsApi.ts +159 -0
  113. package/src/runner/MediaImage.ts +262 -0
  114. package/src/sdk-generator/ComfyNodeSchema.ts +79 -0
  115. package/src/sdk-generator/ComfySchema.ts +369 -0
  116. package/src/sdk-generator/ComfyUIObjectInfoTypes.ts +95 -0
  117. package/src/sdk-generator/Primitives.ts +76 -0
  118. package/src/sdk-generator/_getUnionNameBasedOnFirstFoundEnumName.ts +39 -0
  119. package/src/sdk-generator/_pythonModuleToNamespace.ts +27 -0
  120. package/src/sdk-generator/_toQualifiedNodeKey.ts +5 -0
  121. package/src/sdk-generator/comfy-api-json.ts +16 -0
  122. package/src/sdk-generator/comfyui-sdk-codegen.ts +287 -0
  123. package/src/sdk-generator/comfyui-types.ts +56 -0
  124. package/src/sdk-generator/litegraphToApiRequestPayload.ts +157 -0
  125. package/src/ssh-host-manager/ssh-config-manager.ts +89 -0
  126. package/src/ssh-host-manager/ssh-config.windows.md +32 -0
  127. package/src/ssh-host-manager/ssh-manager.ts +129 -0
  128. package/src/state.ts +136 -0
  129. package/src/types/comfy-sdk.ts +106 -0
  130. package/src/types/index.ts +55 -0
  131. package/src/utils/CodeBuffer.ts +61 -0
  132. package/src/utils/ComfyColors.ts +38 -0
  133. package/src/utils/ansi.ts +26 -0
  134. package/src/utils/ansiImage.ts +36 -0
  135. package/src/utils/bang.ts +39 -0
  136. package/src/utils/deepCopyNaive.ts +1 -0
  137. package/src/utils/downloadFile.ts +77 -0
  138. package/src/utils/escapeJSKey.ts +32 -0
  139. package/src/utils/exhaust.ts +4 -0
  140. package/src/utils/extractErrorMessage.ts +11 -0
  141. package/src/utils/fuzzyMatch.ts +8 -0
  142. package/src/utils/githubRegexes.ts +2 -0
  143. package/src/utils/hashArrayBuffer.ts +6 -0
  144. package/src/utils/log.ts +9 -0
  145. package/src/utils/loraTag.ts +10 -0
  146. package/src/utils/printArkResultInConsole.ts +16 -0
  147. package/src/utils/softValidate.ts +8 -0
  148. package/src/utils/stringifyReadable.ts +32 -0
  149. package/src/utils/toposort.ts +59 -0
  150. package/src/utils/tryExtracting.ts +41 -0
  151. package/src/utils/writeFile.ts +16 -0
  152. package/src/vars/ComfyVars.ts +531 -0
  153. package/src/vars/DefinedWorkflow.ts +112 -0
  154. package/src/vars/loraKeywords.ts +56 -0
  155. package/dist/index.d.mts +0 -74
  156. package/dist/index.mjs +0 -3
  157. package/dist/index.mjs.map +0 -1
  158. package/readme.md +0 -40
@@ -0,0 +1,262 @@
1
+ import { mkdirSync, readFileSync, writeFileSync } from 'node:fs'
2
+ import { type } from 'arktype'
3
+ import { type ImageMeta, imageMeta } from 'image-meta'
4
+ import { basename, dirname } from 'pathe'
5
+ import sharp, { type Sharp } from 'sharp'
6
+ import type { ComfyHost } from 'src/host/ComfyHost.ts'
7
+ import type { ComfyNodeMetadata } from 'src/graph/ComfyNodeID.ts'
8
+ import type { ComfyApiNodeJson } from 'src/sdk-generator/comfy-api-json.ts'
9
+ import type { AbsolutePath, Maybe } from 'src/types/index.ts'
10
+ import type { NodeOf } from 'src/types/comfy-sdk.ts'
11
+ import type { ComfyImageName } from 'src/sdk-generator/comfyui-types.ts'
12
+ import { bang } from 'src/utils/bang.ts'
13
+ import { hashArrayBuffer } from 'src/utils/hashArrayBuffer.ts'
14
+ import type { ComfyExecution } from 'src/runner/ComfyExecution.ts'
15
+ import type { ComfyWorkflow } from 'src/runner/ComfyWorkflow.ts'
16
+ import { type ComfyImageInfo, ComfyImageInfo_ark } from 'src/runner/ComfyWsApi.ts'
17
+
18
+ export type MediaImageData = {
19
+ path: AbsolutePath
20
+
21
+ // to avoid having to read the file if we already have the buffer around
22
+ buffer?: Uint8Array
23
+
24
+ // provenance ?
25
+ execution?: ComfyExecution
26
+ promptNodeID?: string | null
27
+
28
+ comfyUIInfos?: ImageInfos_ComfyGenerated
29
+ }
30
+
31
+ export type ImageInfos_ComfyGenerated = {
32
+ comfyHostHttpURL: string
33
+ comfyImageInfo: ComfyImageInfo
34
+ }
35
+
36
+ export const ImageInfos_ComfyGenerated_ark = type({
37
+ comfyHostHttpURL: 'string',
38
+ comfyImageInfo: ComfyImageInfo_ark,
39
+ })
40
+
41
+ export class MediaImage {
42
+ absPath: AbsolutePath
43
+
44
+ /** the execution this image came from (null when not generated via comfy-ts) */
45
+ execution: Maybe<ComfyExecution>
46
+
47
+ /** return the workflow from which this image was generated */
48
+ get workflow(): ComfyWorkflow | undefined {
49
+ return this.execution?.workflow
50
+ }
51
+
52
+ promptNodeID: Maybe<string>
53
+
54
+ constructor(data: MediaImageData) {
55
+ this.absPath = data.path
56
+ this.execution = data.execution
57
+ this.promptNodeID = data.promptNodeID
58
+ if (data.buffer != null) this.updateBuffer(data.buffer)
59
+ }
60
+
61
+ /** free-form labels; filled from ComfyNodeMetadata.tag(s) when generated via a prompt */
62
+ tags: string[] = []
63
+
64
+ /** the image as a Blob, e.g. to feed FormData uploads */
65
+ getAsBlob(): Blob {
66
+ return new Blob([this.buffer as Uint8Array<ArrayBuffer>], { type: `image/${this.metadata.type ?? 'png'}` })
67
+ }
68
+
69
+ /** return the image filename */
70
+ get filename(): string {
71
+ return basename(this.absPath)
72
+ }
73
+
74
+ get baseNameWithoutExtension(): string {
75
+ const fname = this.filename
76
+ return fname.slice(0, fname.lastIndexOf('.'))
77
+ }
78
+
79
+ /**
80
+ * return file extension including dot
81
+ * e.g. `.png`, or `.webp`
82
+ * */
83
+ get extension(): string {
84
+ const fname = this.filename
85
+ return fname.slice(((fname.lastIndexOf('.') - 1) >>> 0) + 1)
86
+ }
87
+
88
+ /** get the expected enum name (hash) */
89
+ get enumName(): ComfyImageName {
90
+ return `${this.hash}${this.extension}` as ComfyImageName
91
+ }
92
+
93
+ uploadAndReturnEnumName = async (host: ComfyHost): Promise<ComfyImageName> => {
94
+ const finalName = await host.uploader.uploadImage(this, { type: 'input', override: true })
95
+ return finalName
96
+ }
97
+
98
+ /** upload the media (hash-named, deduped) and load it in the given workflow as a `LoadImage` node */
99
+ loadInWorkflow_viaLoadImageNode = async <WID extends string>(
100
+ workflow: ComfyWorkflow<WID>,
101
+ ): Promise<NodeOf<WID, 'LoadImage'>> => {
102
+ const enumName = await this.uploadAndReturnEnumName(workflow.host)
103
+ const img = bang(workflow.builderBase.LoadImage, 'host has no LoadImage node')({ image: enumName })
104
+ // sanctioned cast: uploaded names are runtime-known; the node itself is the host's LoadImage
105
+ return img as NodeOf<WID, 'LoadImage'>
106
+ }
107
+
108
+ /** load an image as mask in a comfy workflow beeing created */
109
+ loadInWorkflowAsMask_viaLoadImageMask = async <WID extends string>(
110
+ /** "alpha" | "blue" | "green" | "red" */
111
+ channel: 'alpha' | 'blue' | 'green' | 'red',
112
+ /** workflow to load image as mask into */
113
+ workflow: ComfyWorkflow<WID>,
114
+ ): Promise<NodeOf<WID, 'LoadImageMask'>> => {
115
+ const enumName = await this.uploadAndReturnEnumName(workflow.host)
116
+ const mask = bang(
117
+ workflow.builderBase.LoadImageMask,
118
+ 'host has no LoadImageMask node',
119
+ )({
120
+ image: enumName,
121
+ channel,
122
+ })
123
+ // sanctioned cast: same as above
124
+ return mask as NodeOf<WID, 'LoadImageMask'>
125
+ }
126
+
127
+ /** return the json of the ComfyNode that led to this image */
128
+ get ComfyNode(): Maybe<ComfyApiNodeJson> {
129
+ const nodeID = this.promptNodeID
130
+ if (nodeID == null) return null
131
+ return this.workflow?.apiJson[nodeID]
132
+ }
133
+
134
+ /**
135
+ * return the metadata of the ComfyNode that led to this image
136
+ * null if not generated by comfy through a ComfyTS prompt
137
+ * null if no metadata associated in the node in ComfyTS
138
+ */
139
+ get ComfyNodeMetadata(): Maybe<ComfyNodeMetadata> {
140
+ const nodeID = this.promptNodeID
141
+ if (nodeID == null) return null
142
+ return this.workflow?.data.metadata[nodeID]
143
+ }
144
+
145
+ get width(): number | undefined {
146
+ return this.metadata.width
147
+ } // biome-ignore format: misc
148
+ get height(): number | undefined {
149
+ return this.metadata.height
150
+ } // biome-ignore format: misc
151
+
152
+ get width_orCrash(): number {
153
+ return bang(this.metadata.width)
154
+ } // biome-ignore format: misc
155
+ get height_orCrash(): number {
156
+ return bang(this.metadata.height)
157
+ } // biome-ignore format: misc
158
+
159
+ /**
160
+ * return the base64 url for this file, regardless of it's exact representation
161
+ * includes the prefix `data:image/<type>;base64,`
162
+ */
163
+ getBase64Url(): string {
164
+ const imgType = this.metadata.type ?? 'png'
165
+ return `data:image/${imgType};base64,${this.getBase64Payload()}`
166
+ }
167
+
168
+ /**
169
+ * return the base64 url for this file, regardless of it's exact representation
170
+ * does not includes the prefix `data:image/png;base64,`
171
+ */
172
+ getBase64Payload(): string {
173
+ const bin = Buffer.from(this.buffer)
174
+ return bin.toString('base64')
175
+ }
176
+
177
+ /** return the ArrayBuffer for this file, regardless it's exact representation */
178
+
179
+ /** lazilly loaded, call recomputeMetadata to expire */
180
+ private _buffer: Maybe<Uint8Array> = null
181
+ get buffer(): Uint8Array {
182
+ if (this._buffer != null) return this._buffer
183
+ const buff: Buffer | ArrayBuffer = readFileSync(this.absPath)
184
+ const uint8arr = new Uint8Array(buff)
185
+ this._buffer = uint8arr
186
+ return this._buffer
187
+ }
188
+ freeBuffer = (): void => void (this._buffer = null)
189
+ updateBuffer = (buff: Uint8Array): void => {
190
+ this._buffer = buff
191
+ this._metadata = null // expire metadata
192
+ this._hash = null // expire hash
193
+ }
194
+ reloadBuffer = (): Uint8Array => {
195
+ this._buffer = null // expire buffer
196
+ this._metadata = null // expire metadata
197
+ this._hash = null // expire hash
198
+ return this.buffer
199
+ }
200
+
201
+ /** lazilly computed, call recomputeMetadata to expire */
202
+ private _metadata: Maybe<ImageMeta> = null
203
+ get metadata(): ImageMeta {
204
+ if (this._metadata != null) return this._metadata
205
+ const buff = readFileSync(this.absPath)
206
+ const uint8arr = new Uint8Array(buff)
207
+ this._metadata = imageMeta(uint8arr)
208
+ return this._metadata
209
+ }
210
+
211
+ private _hash: Maybe<string> = null
212
+ get hash(): string {
213
+ if (this._hash != null) return this._hash
214
+ const buff: Buffer | ArrayBuffer = readFileSync(this.absPath)
215
+ this._hash = hashArrayBuffer(new Uint8Array(buff))
216
+ return this._hash
217
+ }
218
+
219
+ /**
220
+ * Modify the image directly (inplace) by passing it though a `Sharp` pipeline
221
+ * Sharp is a high performance image processing library.
222
+ */
223
+ processWithSharp_inplace = async (
224
+ /** processing function */
225
+ fn: (sharp: Sharp) => Sharp,
226
+ ): Promise<this> => {
227
+ const buff = await fn(sharp(this.absPath)).toBuffer()
228
+ writeFileSync(this.absPath, buff)
229
+ this.updateBuffer(new Uint8Array(buff))
230
+ return this
231
+ }
232
+
233
+ /**
234
+ * Allow to run an image though some `Sharp` pipeline to produce an other image.
235
+ * Sharp is a high performance image processing library.
236
+ * to modify the image directly (inplace), use `processWithSharp_inplace` instead.
237
+ */
238
+ processWithSharp = async (
239
+ /** processing function */
240
+ fn: (sharp: Sharp) => Sharp,
241
+ /** where to save the resulting image */
242
+ path?: AbsolutePath,
243
+ ): Promise<MediaImage> => {
244
+ const res: Sharp = fn(sharp(this.absPath))
245
+ path ??= this.absPath + `.processed-${Date.now()}` + this.extension
246
+ await res.toFile(path)
247
+ const buffer = await res.toBuffer()
248
+ return new MediaImage({ path, buffer })
249
+ }
250
+
251
+ generatePreview = async (targetPath: string): Promise<void> => {
252
+ const img = sharp(this.absPath).rotate().resize(100).jpeg({ mozjpeg: true })
253
+ mkdirSync(dirname(targetPath), { recursive: true })
254
+ await img.toFile(targetPath)
255
+ }
256
+
257
+ generateMiniPreview = async (): Promise<string> => {
258
+ const image2 = await sharp(this.absPath).resize(32, 32, { fit: 'inside' }).webp({ quality: 1 }).toBuffer()
259
+ const x = image2.toString('base64')
260
+ return x
261
+ }
262
+ }
@@ -0,0 +1,79 @@
1
+ import type { Maybe } from 'src/types/index.ts'
2
+ import { CodeBuffer } from 'src/utils/CodeBuffer.ts'
3
+ import { escapeJSKey } from 'src/utils/escapeJSKey.ts'
4
+ import type { ComfyInputOpts, ComfyNodeSchemaJSON } from 'src/sdk-generator/ComfyUIObjectInfoTypes.ts'
5
+ import type { ComfyUnionInfo, NodeInputExt, NodeOutputExt } from 'src/sdk-generator/comfyui-types.ts'
6
+ import { ComfyPrimitiveMapping } from 'src/sdk-generator/Primitives.ts'
7
+
8
+ export type NodeOwnEnum = {
9
+ in: 'input' | 'output'
10
+ ownName: string
11
+ enum: ComfyUnionInfo
12
+ }
13
+
14
+ export class ComfyNodeSchema {
15
+ /** list of types the node has a single output of */
16
+ _singleOutputs: Maybe<NodeOutputExt[]> = null
17
+
18
+ get singleOutputs(): NodeOutputExt[] {
19
+ if (this._singleOutputs != null) return this._singleOutputs
20
+ const x: { [key: string]: number } = {}
21
+ for (const i of this.outputs) x[i.typeName] = (x[i.typeName] ?? 0) + 1
22
+ this._singleOutputs = this.outputs.filter((i) => x[i.typeName] === 1)
23
+ return this._singleOutputs
24
+ }
25
+
26
+ constructor(
27
+ public raw: ComfyNodeSchemaJSON,
28
+ public nameInComfy: string,
29
+ public nodeKey: string, // same but qualified to keep track of pythonNamespace
30
+ public category: string,
31
+ public inputs: NodeInputExt[],
32
+ public outputs: NodeOutputExt[],
33
+ public pythonModule: string,
34
+ ) {
35
+ this.category = this.category.replaceAll('/', '_')
36
+ }
37
+
38
+ codegenUI(): string {
39
+ const b = new CodeBuffer()
40
+ const p = b.w
41
+ p(` ${escapeJSKey(this.nodeKey)}: {`)
42
+ this.inputs.forEach((i, _ix) => {
43
+ // 1/3
44
+ if (i.isPrimitive) {
45
+ const tsType = ComfyPrimitiveMapping[i.typeName]
46
+ if (tsType == null) return console.log(`[🔶] invariant violation`)
47
+ p(` ${escapeJSKey(i.nameInComfy)}: { kind: '${tsType}', type: ${tsType} }`)
48
+ }
49
+ // 2/3
50
+ else if (i.isEnum) {
51
+ p(` ${escapeJSKey(i.nameInComfy)}: { kind: 'enum', type: Union['${i.typeName}'] }`)
52
+ // p(` ${escapeJSKey(i.nameInComfy)}: { kind: 'enum', type: '${this.nodeKey}.${i.nameInComfy}' }`) // prettier-ignore
53
+ }
54
+ // 3/3
55
+ else {
56
+ p(` // ${escapeJSKey(i.nameInComfy)}: { kind: 'object', type: ${i.typeName} }`)
57
+ }
58
+ })
59
+ p(` }`)
60
+ return b.content
61
+ }
62
+
63
+ renderOpts(opts?: ComfyInputOpts): Maybe<string> {
64
+ if (opts == null) return null
65
+ if (typeof opts === 'string') return null
66
+ let out = '/**'
67
+ if (opts.default != null) out += ` default=${JSON.stringify(opts.default)}`
68
+ if (opts.min != null) out += ` min=${JSON.stringify(opts.min)}`
69
+ if (opts.max != null) out += ` max=${JSON.stringify(opts.max)}`
70
+ if (opts.step != null) out += ` step=${JSON.stringify(opts.step)}`
71
+ out += ' */'
72
+ return out
73
+ }
74
+ }
75
+
76
+ export const wrapQuote = (s: string): string => {
77
+ if (s.includes("'")) return `"${s}"`
78
+ return `'${s}'`
79
+ }