comfy-ts 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) 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 +4171 -0
  6. package/dist/index.cjs.map +1 -0
  7. package/dist/index.d.cts +9910 -0
  8. package/dist/index.d.ts +9894 -58
  9. package/dist/index.js +4092 -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-SDSJo1Qf.js +3896 -0
  14. package/dist/run-tui-SDSJo1Qf.js.map +1 -0
  15. package/package.json +103 -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 +56 -0
  22. package/src/cli/tui/components/HostPanel.tsx +37 -0
  23. package/src/cli/tui/components/LogsPanel.tsx +23 -0
  24. package/src/cli/tui/components/LorasOverlay.tsx +49 -0
  25. package/src/cli/tui/components/OverlayList.tsx +25 -0
  26. package/src/cli/tui/components/PickerOverlays.tsx +66 -0
  27. package/src/cli/tui/components/PreviewPanel.tsx +78 -0
  28. package/src/cli/tui/components/PromptOverlay.tsx +16 -0
  29. package/src/cli/tui/components/StatusBar.tsx +171 -0
  30. package/src/cli/tui/components/TextOverlay.tsx +72 -0
  31. package/src/cli/tui/components/TreePanel.tsx +51 -0
  32. package/src/cli/tui/components/TuiApp.tsx +246 -0
  33. package/src/cli/tui/components/VarsPanel.tsx +86 -0
  34. package/src/cli/tui/findDefinedWorkflow.ts +16 -0
  35. package/src/cli/tui/keys.ts +20 -0
  36. package/src/cli/tui/protocolImagePainter.ts +95 -0
  37. package/src/cli/tui/run-tui.tsx +76 -0
  38. package/src/cli/tui/state/DraftsSt.ts +273 -0
  39. package/src/cli/tui/state/EditorSt.ts +289 -0
  40. package/src/cli/tui/state/ExecSt.ts +173 -0
  41. package/src/cli/tui/state/HostSt.ts +230 -0
  42. package/src/cli/tui/state/LogsSt.ts +107 -0
  43. package/src/cli/tui/state/LorasSt.ts +185 -0
  44. package/src/cli/tui/state/PickerSt.ts +112 -0
  45. package/src/cli/tui/state/PreviewSt.ts +288 -0
  46. package/src/cli/tui/state/QueueSt.ts +59 -0
  47. package/src/cli/tui/state/SettingsSt.ts +100 -0
  48. package/src/cli/tui/state/TreeSt.ts +122 -0
  49. package/src/cli/tui/state/TuiSt.ts +175 -0
  50. package/src/cli/tui/state/WorkflowsSt.ts +93 -0
  51. package/src/cli/tui-env.ts +8 -0
  52. package/src/errors/InvalidPromptError.ts +12 -0
  53. package/src/graph/ComfyNode.ts +403 -0
  54. package/src/graph/ComfyNodeID.ts +28 -0
  55. package/src/graph/ComfyNodeOutput.ts +16 -0
  56. package/src/graph/NodeSlotSize.ts +4 -0
  57. package/src/graph/autoValue.ts +17 -0
  58. package/src/host/ComfyHost.ts +690 -0
  59. package/src/host/ComfyInstallType.ts +15 -0
  60. package/src/host/ComfyManager.ts +232 -0
  61. package/src/host/ComfyUploader.ts +110 -0
  62. package/src/host/ComfyWorkflowBuilder.ts +60 -0
  63. package/src/host/Requirements.ts +55 -0
  64. package/src/host/ResilientWebsocket.ts +147 -0
  65. package/src/host/loraManagerApi.ts +98 -0
  66. package/src/image-utils/_getPngMetadata.ts +53 -0
  67. package/src/image-utils/_getWebpMetadata.ts +38 -0
  68. package/src/image-utils/_parseExifData.ts +53 -0
  69. package/src/index.ts +89 -0
  70. package/src/litegraph/LiteGraphGroup.ts +22 -0
  71. package/src/litegraph/LiteGraphJSON.ts +46 -0
  72. package/src/litegraph/LiteGraphLink.ts +23 -0
  73. package/src/litegraph/LiteGraphLinkID.ts +6 -0
  74. package/src/litegraph/LiteGraphNode.ts +69 -0
  75. package/src/litegraph/LiteGraphNodeInput.ts +27 -0
  76. package/src/litegraph/LiteGraphNodeOutput.ts +23 -0
  77. package/src/litegraph/LiteGraphSlotIndex.ts +6 -0
  78. package/src/litegraph/convertFlowToLiteGraphJSON.ts +114 -0
  79. package/src/manager/ComfyRegistry.ts +124 -0
  80. package/src/manager/generated/KnownComfyCustomNodeName.ts +19280 -0
  81. package/src/manager/generated/KnownComfyPluginTitle.ts +5130 -0
  82. package/src/manager/generated/KnownComfyPluginURL.ts +2589 -0
  83. package/src/manager/generated/KnownModel_Base.ts +126 -0
  84. package/src/manager/generated/KnownModel_FileName.ts +2287 -0
  85. package/src/manager/generated/KnownModel_Name.ts +2287 -0
  86. package/src/manager/generated/KnownModel_SavePath.ts +263 -0
  87. package/src/manager/generated/KnownModel_Type.ts +97 -0
  88. package/src/manager/json/alter-list.json +224 -0
  89. package/src/manager/json/custom-node-list.extra.ts +13 -0
  90. package/src/manager/json/custom-node-list.json +21948 -0
  91. package/src/manager/json/extension-node-map.json +31282 -0
  92. package/src/manager/json/github-stats.json +12602 -0
  93. package/src/manager/json/model-list.extra.ts +26 -0
  94. package/src/manager/json/model-list.json +5052 -0
  95. package/src/manager/loaders/step1_downloadComfyManagerJSONs.ts +56 -0
  96. package/src/manager/loaders/step2_custom-node-list-loader.ts +149 -0
  97. package/src/manager/loaders/step3_extension-node-map-loader.ts +189 -0
  98. package/src/manager/loaders/step4_model-list-loader.ts +159 -0
  99. package/src/manager/script-update-manager.bun.ts +18 -0
  100. package/src/manager/types/ComfyManagerAPIFetchPolicy.ts +9 -0
  101. package/src/manager/types/ComfyManagerAPIModelList.ts +10 -0
  102. package/src/manager/types/ComfyManagerAPIPluginList.ts +11 -0
  103. package/src/manager/types/ComfyManagerFileModelInfo.ts +5 -0
  104. package/src/manager/types/ComfyManagerFilePluginContent.ts +13 -0
  105. package/src/manager/types/ComfyManagerFilePluginList.ts +5 -0
  106. package/src/manager/types/ComfyManagerModelInfo.ts +18 -0
  107. package/src/manager/types/ComfyManagerPluginContentMetadata.ts +16 -0
  108. package/src/manager/types/ComfyManagerPluginEnums.ts +8 -0
  109. package/src/manager/types/ComfyManagerPluginInfo.ts +50 -0
  110. package/src/runner/ComfyExecution.ts +301 -0
  111. package/src/runner/ComfyExecutionStatus.ts +2 -0
  112. package/src/runner/ComfyWorkflow.ts +395 -0
  113. package/src/runner/ComfyWorkflowLayout.ts +96 -0
  114. package/src/runner/ComfyWsApi.ts +170 -0
  115. package/src/runner/MediaImage.ts +262 -0
  116. package/src/sdk-generator/ComfyNodeSchema.ts +79 -0
  117. package/src/sdk-generator/ComfySchema.ts +369 -0
  118. package/src/sdk-generator/ComfyUIObjectInfoTypes.ts +95 -0
  119. package/src/sdk-generator/Primitives.ts +76 -0
  120. package/src/sdk-generator/_getUnionNameBasedOnFirstFoundEnumName.ts +39 -0
  121. package/src/sdk-generator/_pythonModuleToNamespace.ts +27 -0
  122. package/src/sdk-generator/_toQualifiedNodeKey.ts +5 -0
  123. package/src/sdk-generator/comfy-api-json.ts +16 -0
  124. package/src/sdk-generator/comfyui-sdk-codegen.ts +287 -0
  125. package/src/sdk-generator/comfyui-types.ts +56 -0
  126. package/src/sdk-generator/litegraphToApiRequestPayload.ts +157 -0
  127. package/src/ssh-host-manager/ssh-config-manager.ts +89 -0
  128. package/src/ssh-host-manager/ssh-config.windows.md +32 -0
  129. package/src/ssh-host-manager/ssh-manager.ts +114 -0
  130. package/src/state.ts +136 -0
  131. package/src/types/comfy-sdk.ts +106 -0
  132. package/src/types/index.ts +55 -0
  133. package/src/utils/CodeBuffer.ts +61 -0
  134. package/src/utils/ComfyColors.ts +38 -0
  135. package/src/utils/ansi.ts +33 -0
  136. package/src/utils/ansiImage.ts +36 -0
  137. package/src/utils/bang.ts +39 -0
  138. package/src/utils/deepCopyNaive.ts +1 -0
  139. package/src/utils/downloadFile.ts +77 -0
  140. package/src/utils/escapeJSKey.ts +32 -0
  141. package/src/utils/exhaust.ts +4 -0
  142. package/src/utils/extractErrorMessage.ts +11 -0
  143. package/src/utils/fuzzyMatch.ts +8 -0
  144. package/src/utils/githubRegexes.ts +2 -0
  145. package/src/utils/hashArrayBuffer.ts +6 -0
  146. package/src/utils/log.ts +9 -0
  147. package/src/utils/loraTag.ts +10 -0
  148. package/src/utils/mojibake.ts +60 -0
  149. package/src/utils/printArkResultInConsole.ts +16 -0
  150. package/src/utils/softValidate.ts +8 -0
  151. package/src/utils/stringifyReadable.ts +32 -0
  152. package/src/utils/toposort.ts +59 -0
  153. package/src/utils/tryExtracting.ts +41 -0
  154. package/src/utils/writeFile.ts +16 -0
  155. package/src/vars/ComfyVars.ts +531 -0
  156. package/src/vars/DefinedWorkflow.ts +112 -0
  157. package/src/vars/loraKeywords.ts +56 -0
  158. package/dist/index.d.mts +0 -74
  159. package/dist/index.mjs +0 -3
  160. package/dist/index.mjs.map +0 -1
  161. package/readme.md +0 -40
@@ -0,0 +1,124 @@
1
+ import { ansi as chalk } from 'src/utils/ansi.ts'
2
+ import type { NodeNameInComfy, QualifiedNodeKey } from 'src/sdk-generator/comfyui-types.ts'
3
+ import type { KnownComfyCustomNodeName } from 'src/manager/generated/KnownComfyCustomNodeName.ts'
4
+ import type { KnownComfyPluginTitle } from 'src/manager/generated/KnownComfyPluginTitle.ts'
5
+ import type { KnownComfyPluginURL } from 'src/manager/generated/KnownComfyPluginURL.ts'
6
+ import type { KnownModel_Name } from 'src/manager/generated/KnownModel_Name.ts'
7
+ import { DownloadComfyManagerJSONs } from 'src/manager/loaders/step1_downloadComfyManagerJSONs.ts'
8
+ import { _getKnownPlugins } from 'src/manager/loaders/step2_custom-node-list-loader.ts'
9
+ import { _getCustomNodeRegistry } from 'src/manager/loaders/step3_extension-node-map-loader.ts'
10
+ import { _getKnownModels } from 'src/manager/loaders/step4_model-list-loader.ts'
11
+ import type { ComfyManagerModelInfo } from 'src/manager/types/ComfyManagerModelInfo.ts'
12
+ import type { ComfyManagerPluginInfo } from 'src/manager/types/ComfyManagerPluginInfo.ts'
13
+
14
+ const log = (...args: unknown[]) => console.log(`[📘 registry]`, ...args)
15
+
16
+ export class ComfyRegistry {
17
+ // plugins, indexed
18
+ plugins_byTitle = new Map<KnownComfyPluginTitle, ComfyManagerPluginInfo>()
19
+ plugins_byFile = new Map<KnownComfyPluginURL, ComfyManagerPluginInfo>()
20
+ plugins_byNodeNameInComfy = new Map<NodeNameInComfy, ComfyManagerPluginInfo[]>()
21
+ plugins_byNodeKey = new Map<QualifiedNodeKey, ComfyManagerPluginInfo[]>()
22
+
23
+ // custom nodes
24
+ customNodes_byPluginName = new Map<KnownComfyPluginTitle, KnownComfyCustomNodeName[]>()
25
+
26
+ // Models
27
+ knownModels = new Map<KnownModel_Name, ComfyManagerModelInfo>()
28
+
29
+ static async DownloadAndUpdate(download: boolean): Promise<ComfyRegistry> {
30
+ if (download) {
31
+ log(chalk.bold(`1. Downloading comfy-manager JSONs...`))
32
+ await DownloadComfyManagerJSONs()
33
+ } else {
34
+ log(`1. Downloading comfy-manager JSONs... ${chalk.bold('[SKIPPED]')}`)
35
+ }
36
+ // should take care of the code generation
37
+ return new ComfyRegistry({
38
+ check: true,
39
+ genTypes: true,
40
+ })
41
+ }
42
+
43
+ constructor(
44
+ public opts: {
45
+ check?: boolean
46
+ genTypes?: boolean
47
+ } = {},
48
+ ) {
49
+ this.plugins_byFile.set('https://github.com/comfyanonymous/ComfyUI' as any, {
50
+ id: 'nodes',
51
+ author: 'comfyanonymous',
52
+ description: 'built-in',
53
+ title: 'built-in' as any,
54
+ files: [],
55
+ reference: 'https://github.com/comfyanonymous/ComfyUI',
56
+ install_type: '',
57
+ })
58
+
59
+ log(`loading src/manager/json/${chalk.yellow('custom-node-list.json')}...`)
60
+ _getKnownPlugins(this)
61
+
62
+ log(`loading src/manager/json/${chalk.yellow('extension-node-map.json')}...`)
63
+ _getCustomNodeRegistry(this)
64
+
65
+ log(`loading src/manager/json/${chalk.yellow('model-list.json')}...`)
66
+ _getKnownModels(this)
67
+ }
68
+
69
+ getKnownCheckpoints = (): ComfyManagerModelInfo[] => {
70
+ const allKnownModels = [...this.knownModels.values()]
71
+ const allKnownCheckpoints = allKnownModels.filter((i) => i.type === 'checkpoint')
72
+ // console.log(`[🤠] allKnownCheckpoints`, allKnownCheckpoints)
73
+ // for (const mi of knownModels.values()) {
74
+ // console.log(`[🧐] `, mi.type === 'checkpoint' ? '✅' : '❌', mi.name)
75
+ // }
76
+ return allKnownCheckpoints
77
+ }
78
+
79
+ /**
80
+ * try to replicate the logic of ComfyUIManager to extract the final
81
+ * file path of a downloaded managed model
82
+ */
83
+ getModelInfoFinalFilePath = (mi: ComfyManagerModelInfo): string => {
84
+ /**
85
+ * the wide data-lt once told:
86
+ *
87
+ * | if save_path is 'default'
88
+ * | models/type'/filename
89
+ *
90
+ * | if type is "checkpoint"
91
+ * | models/checkpoints/filename
92
+ *
93
+ * | if save_path not starting with custom node
94
+ * | base path is models
95
+ * | e.g. save_path is "checkpoints/SD1.5"
96
+ * | models/checkpoints/SD1.5/filename
97
+ * | save_path is "custom_nodes/AAA/models"
98
+ * | custom_nodes/AAA/models/filename
99
+ *
100
+ */
101
+ if (mi.save_path === 'default') return `models/${mi.type}/${mi.filename}`
102
+ if (mi.type === 'checkpoint') return `models/checkpoints/${mi.filename}`
103
+ if (mi.save_path.startsWith('custom_nodes')) return `${mi.save_path}/${mi.filename}`
104
+ else return `models/${mi.save_path}/${mi.filename}`
105
+ }
106
+
107
+ getModelInfoEnumName = (mi: ComfyManagerModelInfo, prefix: string = ''): { win: string; nix: string } => {
108
+ const relPath = this.getModelInfoFinalFilePath(mi)
109
+
110
+ const winPath = relPath.replace(/\//g, '\\')
111
+ const winPrefix = prefix?.replace(/\//g, '\\')
112
+ const isUnderPrefixWin = winPath.startsWith(winPrefix)
113
+
114
+ const nixPath = relPath.replace(/\\/g, '/')
115
+ const nixPrefix = prefix?.replace(/\//g, '\\')
116
+ const isUnderPrefixNix = nixPath.startsWith(nixPrefix)
117
+
118
+ const isUnderPrefix = isUnderPrefixNix || isUnderPrefixWin
119
+ return {
120
+ win: isUnderPrefix ? winPath.slice(winPrefix.length) : mi.filename /* winRel */,
121
+ nix: isUnderPrefix ? nixPath.slice(nixPrefix.length) : mi.filename /* nixRel */,
122
+ }
123
+ }
124
+ }