comfy-ts 2.17.1 → 2.18.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.
- package/dist/cli.js +3 -3
- package/dist/index.cjs +944 -165
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1154 -408
- package/dist/index.d.ts +1154 -408
- package/dist/index.js +944 -165
- package/dist/index.js.map +1 -1
- package/dist/{run-run-tg82jUIk.js → run-run-Wn7H72Zg.js} +2 -2
- package/dist/{run-run-tg82jUIk.js.map → run-run-Wn7H72Zg.js.map} +1 -1
- package/dist/{run-tui-Bw7BA75d.js → run-tui-VWSj1D_j.js} +2 -2
- package/dist/{run-tui-Bw7BA75d.js.map → run-tui-VWSj1D_j.js.map} +1 -1
- package/dist/serve-web.js +47 -47
- package/dist/{state-zTow5ucI.js → state-DgwWhZWb.js} +945 -166
- package/dist/state-DgwWhZWb.js.map +1 -0
- package/dist/web.d.ts +1172 -426
- package/dist/web.js +944 -165
- package/dist/web.js.map +1 -1
- package/examples/comfy-cloud/ace-step15-t2a.cflow.ts +163 -0
- package/examples/comfy-cloud/anima-t2i-base.cflow.ts +57 -0
- package/examples/comfy-cloud/boogu-t2i.cflow.ts +55 -0
- package/examples/comfy-cloud/chronoedit-i2i.cflow.ts +95 -0
- package/examples/comfy-cloud/ernie-t2i-base.cflow.ts +81 -0
- package/examples/comfy-cloud/flux1-t2i-krea.cflow.ts +63 -0
- package/examples/comfy-cloud/flux2-i2i-dev.cflow.ts +83 -0
- package/examples/comfy-cloud/flux2-t2i-dev.cflow.ts +60 -0
- package/examples/comfy-cloud/hidream-o1-i2i.cflow.ts +71 -0
- package/examples/comfy-cloud/hidream-o1-t2i.cflow.ts +62 -0
- package/examples/comfy-cloud/krea2-i2i.cflow.ts +78 -0
- package/examples/comfy-cloud/ltx2-i2v.cflow.ts +175 -0
- package/examples/comfy-cloud/ltx2-t2v.cflow.ts +143 -0
- package/examples/comfy-cloud/ltx23-i2v.cflow.ts +189 -0
- package/examples/comfy-cloud/ltx23-t2v.cflow.ts +151 -0
- package/examples/comfy-cloud/mage-flow-i2i-turbo.cflow.ts +72 -0
- package/examples/comfy-cloud/mage-flow-i2i.cflow.ts +74 -0
- package/examples/comfy-cloud/mage-flow-t2i-turbo.cflow.ts +60 -0
- package/examples/comfy-cloud/mage-flow-t2i.cflow.ts +60 -0
- package/examples/comfy-cloud/minimax-h3-t2i.cflow.ts +64 -0
- package/examples/comfy-cloud/netayume-t2i.cflow.ts +60 -0
- package/examples/comfy-cloud/qwen-image-i2i-2509.cflow.ts +75 -0
- package/examples/comfy-cloud/qwen-image-t2i-2512.cflow.ts +63 -0
- package/examples/comfy-cloud/sdk.d.ts +21683 -13737
- package/examples/comfy-cloud/stable-audio3-t2a.cflow.ts +96 -0
- package/examples/comfy-cloud/z-image-t2i-base.cflow.ts +54 -0
- package/examples/rvion/04-krea2-turbo-t2i.cflow.ts +1 -1
- package/package.json +2 -2
- package/src/graph/ComfyNode.ts +93 -12
- package/src/host/ComfyHost.ts +31 -10
- package/src/host/ComfyManager.ts +448 -62
- package/src/litegraph/CanonicalWorkflow.ts +3 -0
- package/src/litegraph/LiteGraphJSON.ts +2 -2
- package/src/litegraph/LiteGraphNodeInput.ts +2 -2
- package/src/litegraph/LiteGraphNodeOutput.ts +2 -2
- package/src/litegraph/convertFlowToLiteGraphJSON.ts +112 -37
- package/src/litegraph/expandSubgraphs.ts +14 -0
- package/src/litegraph/normalizeWorkflow.ts +1 -0
- package/src/manager/ComfyRegistry.ts +2 -0
- package/src/manager/generated/KnownComfyCustomNodeName.ts +6354 -1680
- package/src/manager/generated/KnownComfyPluginTitle.ts +718 -356
- package/src/manager/generated/KnownComfyPluginURL.ts +357 -181
- package/src/manager/generated/KnownModel_Base.ts +9 -5
- package/src/manager/generated/KnownModel_FileName.ts +135 -0
- package/src/manager/generated/KnownModel_Name.ts +135 -0
- package/src/manager/generated/KnownModel_SavePath.ts +16 -14
- package/src/manager/generated/KnownModel_Type.ts +15 -13
- package/src/manager/installedView.ts +176 -0
- package/src/manager/json/custom-node-list.json +4018 -2248
- package/src/manager/json/extension-node-map.json +8903 -2964
- package/src/manager/json/github-stats.json +10796 -10036
- package/src/manager/json/model-list.json +298 -1
- package/src/manager/loaders/step4_model-list-loader.ts +1 -0
- package/src/manager/types/ComfyManagerAPIModelList.ts +3 -0
- package/src/manager/types/ComfyManagerAPIPluginList.ts +19 -0
- package/src/runner/ComfyExecution.ts +4 -1
- package/src/runner/ComfyWsApi.ts +82 -15
- package/src/sdk-generator/ComfySchema.ts +10 -1
- package/src/sdk-generator/ComfyUIObjectInfoTypes.ts +4 -1
- package/src/sdk-generator/comfyui-sdk-codegen.ts +61 -20
- package/src/sdk-generator/inputWidgetKind.ts +19 -4
- package/src/sdk-generator/litegraphToApiRequestPayload.ts +141 -33
- package/dist/state-zTow5ucI.js.map +0 -1
package/src/host/ComfyManager.ts
CHANGED
|
@@ -1,49 +1,219 @@
|
|
|
1
1
|
/** 🔶 NAMING DISCLAIMER: I call a "custom node package" => "PLUGIN" */
|
|
2
2
|
|
|
3
|
-
import type
|
|
3
|
+
import { type ArkErrors, type Type, type } from 'arktype'
|
|
4
|
+
import { nanoid } from 'nanoid'
|
|
4
5
|
import type { ComfyRegistry } from 'src/manager/ComfyRegistry.ts'
|
|
5
6
|
import type { KnownComfyPluginTitle } from 'src/manager/generated/KnownComfyPluginTitle.ts'
|
|
6
7
|
import type { KnownModel_Name } from 'src/manager/generated/KnownModel_Name.ts'
|
|
8
|
+
import {
|
|
9
|
+
attributePacks,
|
|
10
|
+
buildModelView,
|
|
11
|
+
buildPluginView,
|
|
12
|
+
type InstalledPacks,
|
|
13
|
+
InstalledPacks_ark,
|
|
14
|
+
type ManagerMirror,
|
|
15
|
+
modelFolders,
|
|
16
|
+
type PackMappings,
|
|
17
|
+
PackMappings_ark,
|
|
18
|
+
packIsInstalled,
|
|
19
|
+
repoPath,
|
|
20
|
+
} from 'src/manager/installedView.ts'
|
|
7
21
|
import type { ComfyManagerAPIFetchPolicy } from 'src/manager/types/ComfyManagerAPIFetchPolicy.ts'
|
|
8
22
|
import {
|
|
9
23
|
type ComfyManagerAPIModelList,
|
|
10
24
|
ComfyManagerAPIModelList_ark,
|
|
11
25
|
} from 'src/manager/types/ComfyManagerAPIModelList.ts'
|
|
12
26
|
import {
|
|
27
|
+
type ComfyManagerAPIPackList,
|
|
28
|
+
ComfyManagerAPIPackList_ark,
|
|
13
29
|
type ComfyManagerAPIPluginList,
|
|
14
30
|
ComfyManagerAPIPluginList_ark,
|
|
15
31
|
} from 'src/manager/types/ComfyManagerAPIPluginList.ts'
|
|
16
32
|
import type { ComfyManagerModelInfo } from 'src/manager/types/ComfyManagerModelInfo.ts'
|
|
17
33
|
import type { ComfyManagerPluginInfo } from 'src/manager/types/ComfyManagerPluginInfo.ts'
|
|
18
34
|
import type { Maybe } from 'src/types/index.ts'
|
|
19
|
-
import { logError
|
|
35
|
+
import { logError, logSuccess } from 'src/utils/log.ts'
|
|
20
36
|
import { softValidate } from 'src/utils/softValidate.ts'
|
|
21
37
|
import type { PluginInstallStatus } from 'src/host/Requirements.ts'
|
|
22
38
|
|
|
39
|
+
/**
|
|
40
|
+
* the three ComfyUI-Manager servers in the field (agent/architecture.md, Manager HTTP client):
|
|
41
|
+
* `v3` the legacy custom node (bare routes), `v4-legacy-ui` the pip package under
|
|
42
|
+
* `--enable-manager-legacy-ui` (/v2), `v4` the pip package with its default ui (/v2, no lists)
|
|
43
|
+
*/
|
|
44
|
+
export type ManagerGeneration = 'v3' | 'v4-legacy-ui' | 'v4'
|
|
45
|
+
export type ManagerApi = { generation: ManagerGeneration; version: string }
|
|
46
|
+
|
|
47
|
+
/** install waits poll the queue; tests pass milliseconds */
|
|
48
|
+
export type ManagerTiming = { pollMs: number; installTimeoutMs: number }
|
|
49
|
+
export const MANAGER_TIMING: ManagerTiming = { pollMs: 1000, installTimeoutMs: 60 * 60_000 }
|
|
50
|
+
|
|
51
|
+
type ManagerRoute =
|
|
52
|
+
| '/manager/version'
|
|
53
|
+
| '/manager/reboot'
|
|
54
|
+
| '/manager/terminal'
|
|
55
|
+
| '/customnode/getlist'
|
|
56
|
+
| '/externalmodel/getlist'
|
|
57
|
+
| '/customnode/installed'
|
|
58
|
+
| '/customnode/getmappings'
|
|
59
|
+
| '/manager/queue/install'
|
|
60
|
+
| '/manager/queue/batch'
|
|
61
|
+
| '/manager/queue/task'
|
|
62
|
+
| '/manager/queue/install_model'
|
|
63
|
+
| '/manager/queue/start'
|
|
64
|
+
| '/manager/queue/status'
|
|
65
|
+
| '/manager/queue/history'
|
|
66
|
+
|
|
67
|
+
/** what each generation does NOT serve (history means the `?ui_id=` form) */
|
|
68
|
+
const NOT_SERVED: Record<ManagerGeneration, ManagerRoute[]> = {
|
|
69
|
+
v3: ['/manager/queue/batch', '/manager/queue/task', '/manager/queue/history'],
|
|
70
|
+
'v4-legacy-ui': ['/manager/queue/install', '/manager/queue/task', '/manager/queue/history', '/manager/terminal'],
|
|
71
|
+
v4: [
|
|
72
|
+
'/customnode/getlist',
|
|
73
|
+
'/externalmodel/getlist',
|
|
74
|
+
'/manager/queue/install',
|
|
75
|
+
'/manager/queue/batch',
|
|
76
|
+
'/manager/terminal',
|
|
77
|
+
],
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** everything that differs between generations beyond a route's spelling */
|
|
81
|
+
type ManagerStrategy = {
|
|
82
|
+
fetchPlugins: (mode: ComfyManagerAPIFetchPolicy, skipUpdate: boolean) => Promise<ComfyManagerAPIPluginList>
|
|
83
|
+
fetchModels: () => Promise<ComfyManagerAPIModelList>
|
|
84
|
+
enqueuePlugin: (plugin: ComfyManagerPluginInfo, uiId: string) => Promise<void>
|
|
85
|
+
/** wait until the queued task ran: resolves when it succeeded, throws with why when not */
|
|
86
|
+
settle: (what: string, uiId: string, landed: () => Promise<boolean>) => Promise<void>
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const QueueStatus_ark = type({
|
|
90
|
+
is_processing: 'boolean',
|
|
91
|
+
'pending_count?': 'number',
|
|
92
|
+
'total_count?': 'number',
|
|
93
|
+
'done_count?': 'number',
|
|
94
|
+
})
|
|
95
|
+
const TaskHistory_ark = type({
|
|
96
|
+
history: { 'status?': { status_str: 'string', 'messages?': 'string[]' }, 'result?': 'string' },
|
|
97
|
+
})
|
|
98
|
+
const ModelFolders_ark = type('string[]')
|
|
99
|
+
|
|
100
|
+
const errorText = (e: unknown): string => (e instanceof Error ? e.message : String(e))
|
|
101
|
+
|
|
23
102
|
export class ComfyManager {
|
|
24
103
|
constructor(
|
|
25
104
|
public host: {
|
|
26
105
|
getServerHostHTTP: () => string
|
|
27
106
|
fetch: (route: string, init?: RequestInit, p?: { apiPrefix?: boolean }) => Promise<Response>
|
|
28
107
|
},
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
108
|
+
public timing: ManagerTiming = { ...MANAGER_TIMING },
|
|
109
|
+
/** the mirror the lists are joined to; the registry by default */
|
|
110
|
+
public mirror: () => ManagerMirror = () => comfyts.registry,
|
|
111
|
+
) {}
|
|
32
112
|
|
|
33
113
|
get registry(): ComfyRegistry {
|
|
34
114
|
return comfyts.registry
|
|
35
115
|
}
|
|
36
116
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
117
|
+
/** identifies install tasks of this client in the Manager queue (4.x requires one) */
|
|
118
|
+
readonly clientId: string = `comfy-ts-${nanoid(8)}`
|
|
119
|
+
|
|
120
|
+
// generation ------------------------------------------------------------------------
|
|
121
|
+
private _api: Promise<ManagerApi> | null = null
|
|
122
|
+
|
|
123
|
+
/** which Manager answers: probed once, remembered, forgotten on failure and on reboot */
|
|
124
|
+
api = (): Promise<ManagerApi> => {
|
|
125
|
+
if (this._api == null) {
|
|
126
|
+
const probe = this.probeApi()
|
|
127
|
+
this._api = probe
|
|
128
|
+
probe.catch(() => {
|
|
129
|
+
if (this._api === probe) this._api = null
|
|
130
|
+
})
|
|
131
|
+
}
|
|
132
|
+
return this._api
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
private probeApi = async (): Promise<ManagerApi> => {
|
|
136
|
+
const v4 = await this.host.fetch('/v2/manager/version')
|
|
137
|
+
if (v4.ok) {
|
|
138
|
+
const version = (await v4.text()).trim()
|
|
139
|
+
const ui = await this.host.fetch('/v2/manager/is_legacy_manager_ui')
|
|
140
|
+
if (!ui.ok) {
|
|
141
|
+
logError(
|
|
142
|
+
`ComfyUI-Manager ${version}: GET /v2/manager/is_legacy_manager_ui → ${ui.status}, assuming the default ui`,
|
|
143
|
+
)
|
|
144
|
+
return { generation: 'v4', version }
|
|
145
|
+
}
|
|
146
|
+
const flag: unknown = await ui.json()
|
|
147
|
+
const legacy =
|
|
148
|
+
typeof flag === 'object' &&
|
|
149
|
+
flag != null &&
|
|
150
|
+
'is_legacy_manager_ui' in flag &&
|
|
151
|
+
flag.is_legacy_manager_ui === true
|
|
152
|
+
return { generation: legacy ? 'v4-legacy-ui' : 'v4', version }
|
|
153
|
+
}
|
|
154
|
+
const v3 = await this.host.fetch('/manager/version')
|
|
155
|
+
if (v3.ok) return { generation: 'v3', version: (await v3.text()).trim() }
|
|
156
|
+
throw new Error(
|
|
157
|
+
`🔴 no ComfyUI-Manager answers at ${this.host.getServerHostHTTP()} ` +
|
|
158
|
+
`(GET /v2/manager/version → ${v4.status}, GET /manager/version → ${v3.status})`,
|
|
159
|
+
)
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** the one place a Manager route gets its generation's spelling */
|
|
163
|
+
private route = (api: ManagerApi, route: ManagerRoute, query: string = ''): string => {
|
|
164
|
+
if (NOT_SERVED[api.generation].includes(route))
|
|
165
|
+
throw new Error(`🔴 ComfyUI-Manager ${api.version} (${api.generation}) does not serve ${route}`)
|
|
166
|
+
return `${api.generation === 'v3' ? '' : '/v2'}${route}${query}`
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** the one place the generations differ beyond a route's spelling */
|
|
170
|
+
private strategy = (api: ManagerApi): ManagerStrategy => {
|
|
171
|
+
switch (api.generation) {
|
|
172
|
+
case 'v3':
|
|
173
|
+
return {
|
|
174
|
+
fetchPlugins: (mode, skipUpdate) => this.listedPlugins(api, mode, skipUpdate),
|
|
175
|
+
fetchModels: () => this.listedModels(api),
|
|
176
|
+
enqueuePlugin: (plugin, uiId) =>
|
|
177
|
+
this.enqueueListedPlugin(api, plugin, uiId, (body) =>
|
|
178
|
+
this.post(this.route(api, '/manager/queue/install'), body),
|
|
179
|
+
),
|
|
180
|
+
settle: (what, _uiId, landed) => this.settleByDrain(api, what, landed),
|
|
181
|
+
}
|
|
182
|
+
case 'v4-legacy-ui':
|
|
183
|
+
return {
|
|
184
|
+
fetchPlugins: (mode, skipUpdate) => this.listedPlugins(api, mode, skipUpdate),
|
|
185
|
+
fetchModels: () => this.listedModels(api),
|
|
186
|
+
enqueuePlugin: (plugin, uiId) =>
|
|
187
|
+
this.enqueueListedPlugin(api, plugin, uiId, async (body) => {
|
|
188
|
+
const route = this.route(api, '/manager/queue/batch')
|
|
189
|
+
const res = await this.post(route, { install: [body] })
|
|
190
|
+
const failed = typeof res === 'object' && res != null && 'failed' in res ? res.failed : null
|
|
191
|
+
if (Array.isArray(failed) && failed.length > 0)
|
|
192
|
+
throw new Error(
|
|
193
|
+
`POST ${route} refused ${JSON.stringify(failed)}: the batch reply carries ids only, ` +
|
|
194
|
+
`the ComfyUI console says why (a 4.x security policy refusal is the usual one)`,
|
|
195
|
+
)
|
|
196
|
+
}),
|
|
197
|
+
settle: (what, _uiId, landed) => this.settleByDrain(api, what, landed),
|
|
198
|
+
}
|
|
199
|
+
case 'v4':
|
|
200
|
+
return {
|
|
201
|
+
fetchPlugins: () => this.installedPluginView(api),
|
|
202
|
+
fetchModels: () => this.installedModelView(),
|
|
203
|
+
enqueuePlugin: (plugin, uiId) => this.enqueuePluginTask(api, plugin, uiId),
|
|
204
|
+
settle: (what, uiId) => this.settleByHistory(api, what, uiId),
|
|
205
|
+
}
|
|
206
|
+
}
|
|
41
207
|
}
|
|
42
208
|
|
|
43
209
|
// -----------
|
|
44
|
-
configureLogging = (mi: boolean): Promise<
|
|
45
|
-
|
|
46
|
-
|
|
210
|
+
configureLogging = async (mi: boolean): Promise<string> => {
|
|
211
|
+
const api = await this.api()
|
|
212
|
+
const route = this.route(api, '/manager/terminal', `?mode=${mi}`)
|
|
213
|
+
const response = await this.host.fetch(route)
|
|
214
|
+
const text = await response.text()
|
|
215
|
+
if (!response.ok) throw new Error(`🔴 GET ${route} → ${response.status} ${text}`)
|
|
216
|
+
return text
|
|
47
217
|
}
|
|
48
218
|
|
|
49
219
|
// utils ------------------------------------------------------------------------------
|
|
@@ -87,18 +257,21 @@ export class ComfyManager {
|
|
|
87
257
|
* reboot the ComfyUI process (ComfyUI-Manager).
|
|
88
258
|
*
|
|
89
259
|
* The server dies mid-request, so a DROPPED CONNECTION is the success shape and the only
|
|
90
|
-
* one most callers ever see. A 404 is not: the route is POST from Manager V3 on
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
260
|
+
* one most callers ever see. A 404 is not: the route is POST from Manager V3 on, and a GET
|
|
261
|
+
* there answers 404 while the process keeps running. Both verbs are tried so a pre-V3
|
|
262
|
+
* Manager still reboots, and anything that is neither a disconnect nor a 404 throws with
|
|
263
|
+
* what the host actually said. The process may come back with another Manager, so the
|
|
264
|
+
* remembered generation is dropped.
|
|
95
265
|
*/
|
|
96
266
|
restartComfyUI = async (): Promise<void> => {
|
|
267
|
+
const api = await this.api()
|
|
268
|
+
this._api = null
|
|
269
|
+
const route = this.route(api, '/manager/reboot')
|
|
97
270
|
const refusals: string[] = []
|
|
98
271
|
for (const method of ['POST', 'GET'] as const) {
|
|
99
272
|
let response: Response
|
|
100
273
|
try {
|
|
101
|
-
response = await this.host.fetch(
|
|
274
|
+
response = await this.host.fetch(route, { method })
|
|
102
275
|
} catch {
|
|
103
276
|
return // connection gone: the process is going down, which is what we asked for
|
|
104
277
|
}
|
|
@@ -108,19 +281,27 @@ export class ComfyManager {
|
|
|
108
281
|
if (response.status !== 404) break
|
|
109
282
|
}
|
|
110
283
|
throw new Error(
|
|
111
|
-
`🔴 ${this.host.getServerHostHTTP()} refused to reboot (${refusals.join(', ')}) — ` +
|
|
112
|
-
`ComfyUI-Manager is not
|
|
284
|
+
`🔴 ${this.host.getServerHostHTTP()} refused to reboot (${route}: ${refusals.join(', ')}) — ` +
|
|
285
|
+
`ComfyUI-Manager ${api.version} is not there any more, or its reboot route moved again`,
|
|
113
286
|
)
|
|
114
287
|
}
|
|
115
288
|
|
|
289
|
+
// LISTS ----------------------------------------------------------------------------
|
|
290
|
+
fetchPluginsAndModels = async (): Promise<void> => {
|
|
291
|
+
const [_pluginList, _modelList] = await Promise.all([this.fetchPlugins(), this.fetchModels()])
|
|
292
|
+
this.pluginList = _pluginList
|
|
293
|
+
this.modelList = _modelList
|
|
294
|
+
}
|
|
295
|
+
|
|
116
296
|
modelList: Maybe<ComfyManagerAPIModelList> = null
|
|
117
297
|
|
|
118
|
-
|
|
119
|
-
|
|
298
|
+
/** what the host has of our model mirror; a model absent from the list reads `unknown` */
|
|
299
|
+
fetchModels = async (): Promise<ComfyManagerAPIModelList> => {
|
|
300
|
+
return this.strategy(await this.api()).fetchModels()
|
|
120
301
|
}
|
|
121
302
|
|
|
122
303
|
fetchLogs = (): Promise<any> => {
|
|
123
|
-
return this.
|
|
304
|
+
return this.getJSON<unknown>('/internal/logs')
|
|
124
305
|
}
|
|
125
306
|
|
|
126
307
|
isModelInstalled = (name: KnownModel_Name): boolean => {
|
|
@@ -129,18 +310,25 @@ export class ComfyManager {
|
|
|
129
310
|
|
|
130
311
|
modelsBeeingInstalled = new Set<KnownModel_Name>()
|
|
131
312
|
|
|
313
|
+
/** queue the install, wait until the Manager ran it; true only once the model is verified installed */
|
|
132
314
|
installModel = async (model: ComfyManagerModelInfo): Promise<boolean> => {
|
|
315
|
+
this.modelsBeeingInstalled.add(model.name)
|
|
133
316
|
try {
|
|
134
|
-
this.
|
|
135
|
-
|
|
317
|
+
return await this.runInstall(`model "${model.name}"`, {
|
|
318
|
+
enqueue: async (api, uiId) => {
|
|
319
|
+
const body = { ...model, ui_id: uiId, client_id: this.clientId }
|
|
320
|
+
await this.post(this.route(api, '/manager/queue/install_model'), body)
|
|
321
|
+
},
|
|
322
|
+
landed: async (s) => {
|
|
323
|
+
// the triple the Manager's own install whitelist matches on
|
|
324
|
+
const row = (await s.fetchModels()).models.find(
|
|
325
|
+
(x) => x.filename === model.filename && x.save_path === model.save_path && x.base === model.base,
|
|
326
|
+
)
|
|
327
|
+
return row?.installed === 'True'
|
|
328
|
+
},
|
|
329
|
+
})
|
|
330
|
+
} finally {
|
|
136
331
|
this.modelsBeeingInstalled.delete(model.name)
|
|
137
|
-
toastSuccess('Model installed')
|
|
138
|
-
return true
|
|
139
|
-
} catch (exception) {
|
|
140
|
-
console.error(`Install failed: ${/*model.title*/ ''} / ${exception}`)
|
|
141
|
-
toastError('Model Installation Failed')
|
|
142
|
-
this.modelsBeeingInstalled.delete(model.name)
|
|
143
|
-
return false
|
|
144
332
|
}
|
|
145
333
|
}
|
|
146
334
|
|
|
@@ -189,63 +377,261 @@ export class ComfyManager {
|
|
|
189
377
|
return status
|
|
190
378
|
}
|
|
191
379
|
|
|
192
|
-
|
|
193
|
-
// https://github.com/ltdrdata/ComfyUI-Manager/blob/4649d216b1842aa48b95d3f064c679a1b698e506/js/custom-nodes-downloader.js#L14C25-L14C88
|
|
380
|
+
/** the host's plugin list in the public `custom_nodes` shape, titled like our mirror; absent = `unknown` */
|
|
194
381
|
fetchPlugins = async (
|
|
195
382
|
/** @default: 'cache' */
|
|
196
383
|
mode: ComfyManagerAPIFetchPolicy = 'cache',
|
|
197
384
|
/** @default: true */
|
|
198
385
|
skipUpdate: boolean = true,
|
|
199
386
|
): Promise<ComfyManagerAPIPluginList> => {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
387
|
+
return this.strategy(await this.api()).fetchPlugins(mode, skipUpdate)
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/** queue the install, wait until the Manager ran it; true only once the pack is verified installed */
|
|
391
|
+
installPlugin = async (plugin: ComfyManagerPluginInfo): Promise<boolean> => {
|
|
392
|
+
return this.runInstall(`plugin "${plugin.title}"`, {
|
|
393
|
+
enqueue: (api, uiId) => this.strategy(api).enqueuePlugin(plugin, uiId),
|
|
394
|
+
landed: async (_s, api) => {
|
|
395
|
+
const data = await this.installedData(api)
|
|
396
|
+
return packIsInstalled(attributePacks(data.installed, data.mappings), plugin)
|
|
397
|
+
},
|
|
398
|
+
})
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
// LIST BUILDERS: one per source, picked by the strategy -------------------------------
|
|
402
|
+
/** the Manager's own getlist (v3, v4 legacy ui), normalized */
|
|
403
|
+
private listedPlugins = async (
|
|
404
|
+
api: ManagerApi,
|
|
405
|
+
mode: ComfyManagerAPIFetchPolicy,
|
|
406
|
+
skipUpdate: boolean,
|
|
407
|
+
): Promise<ComfyManagerAPIPluginList> => {
|
|
408
|
+
const raw = await this.fetchPluginWire(api, mode, skipUpdate)
|
|
409
|
+
if (!('node_packs' in raw)) return raw
|
|
410
|
+
const titleByRepo = new Map<string, KnownComfyPluginTitle>()
|
|
411
|
+
for (const p of this.mirror().plugins_byTitle.values())
|
|
412
|
+
for (const f of p.files) titleByRepo.set(repoPath(f), p.title)
|
|
413
|
+
return {
|
|
414
|
+
chanel: raw.channel,
|
|
415
|
+
custom_nodes: Object.values(raw.node_packs).map((p) => {
|
|
416
|
+
const repo = p.files?.[0]
|
|
417
|
+
return {
|
|
418
|
+
title: (repo != null ? titleByRepo.get(repoPath(repo)) : undefined) ?? p.title,
|
|
419
|
+
installed: p.state !== 'enabled' ? 'False' : p['update-state'] === 'true' ? 'Update' : 'True',
|
|
420
|
+
}
|
|
421
|
+
}),
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
private fetchPluginWire = async (
|
|
426
|
+
api: ManagerApi,
|
|
427
|
+
mode: ComfyManagerAPIFetchPolicy,
|
|
428
|
+
skipUpdate: boolean,
|
|
429
|
+
): Promise<ComfyManagerAPIPackList | ComfyManagerAPIPluginList> => {
|
|
430
|
+
const query = `?mode=${mode}${skipUpdate ? '&skip_update=true' : ''}`
|
|
431
|
+
const json: unknown = await this.getJSON(this.route(api, '/customnode/getlist', query))
|
|
432
|
+
if (typeof json === 'object' && json != null && 'custom_nodes' in json)
|
|
433
|
+
return softValidate(ComfyManagerAPIPluginList_ark, json)
|
|
434
|
+
return softValidate(ComfyManagerAPIPackList_ark, json)
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
private listedModels = async (api: ManagerApi): Promise<ComfyManagerAPIModelList> => {
|
|
438
|
+
return this.getJSON(this.route(api, '/externalmodel/getlist', '?mode=cache'), ComfyManagerAPIModelList_ark)
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
/** what is installed, as the Manager scans it, joined through its own registry id mappings */
|
|
442
|
+
private installedData = async (api: ManagerApi): Promise<{ installed: InstalledPacks; mappings: PackMappings }> => {
|
|
443
|
+
const [installed, mappings] = await Promise.all([
|
|
444
|
+
this.getValid(this.route(api, '/customnode/installed'), InstalledPacks_ark),
|
|
445
|
+
this.getValid(this.route(api, '/customnode/getmappings', '?mode=cache'), PackMappings_ark),
|
|
446
|
+
])
|
|
447
|
+
return { installed, mappings }
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
/** v4 serves no list: our mirror against what is installed */
|
|
451
|
+
private installedPluginView = async (api: ManagerApi): Promise<ComfyManagerAPIPluginList> => {
|
|
452
|
+
const view = buildPluginView({ mirror: this.mirror(), ...(await this.installedData(api)) })
|
|
453
|
+
if (view.unattributed.length > 0)
|
|
454
|
+
logError(
|
|
455
|
+
`ComfyUI-Manager ${api.version} reports installed packs no mirror row can be tied to ` +
|
|
456
|
+
`(${view.unattributed.join(', ')}): the mirror rows they could be read unknown`,
|
|
457
|
+
)
|
|
458
|
+
return view.list
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
/** v4 serves no model list: core ComfyUI's model folders against our mirror */
|
|
462
|
+
private installedModelView = async (): Promise<ComfyManagerAPIModelList> => {
|
|
463
|
+
const models = this.mirror().modelRows
|
|
464
|
+
const registered = new Set(await this.getValid('/models', ModelFolders_ark))
|
|
465
|
+
const folders = [...modelFolders(models)].filter((f) => registered.has(f))
|
|
466
|
+
const lists = await Promise.all(
|
|
467
|
+
folders.map(
|
|
468
|
+
async (f) => [f, await this.getValid(`/models/${encodeURIComponent(f)}`, ModelFolders_ark)] as const,
|
|
469
|
+
),
|
|
470
|
+
)
|
|
471
|
+
return buildModelView({ models, files: new Map(lists) })
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
// INSTALL FLOW: enqueue → start → settle -------------------------------------------
|
|
475
|
+
/** v3 and v4 legacy ui: the Manager's own list row for the pack, sent like its own ui does */
|
|
476
|
+
private enqueueListedPlugin = async (
|
|
477
|
+
api: ManagerApi,
|
|
478
|
+
plugin: ComfyManagerPluginInfo,
|
|
479
|
+
uiId: string,
|
|
480
|
+
send: (body: Record<string, unknown>) => Promise<unknown>,
|
|
481
|
+
): Promise<void> => {
|
|
482
|
+
const url = plugin.files[0] ?? plugin.reference
|
|
483
|
+
const list = await this.fetchPluginWire(api, 'cache', true)
|
|
484
|
+
if (!('node_packs' in list))
|
|
485
|
+
throw new Error(`ComfyUI-Manager ${api.version} lists packs in the pre-V3 shape and has no queue install`)
|
|
486
|
+
const found = Object.entries(list.node_packs).find(([, p]) =>
|
|
487
|
+
(p.files ?? []).some((f) => repoPath(f) === repoPath(url)),
|
|
488
|
+
)
|
|
489
|
+
if (found == null)
|
|
490
|
+
throw new Error(
|
|
491
|
+
`${url} is not in the Manager's own list (channel ${list.channel}), so it refuses to install it`,
|
|
492
|
+
)
|
|
493
|
+
const [key, row] = found
|
|
494
|
+
await send({
|
|
495
|
+
...row,
|
|
496
|
+
id: row.id ?? key,
|
|
497
|
+
channel: list.channel,
|
|
498
|
+
mode: 'cache',
|
|
499
|
+
ui_id: uiId,
|
|
500
|
+
skip_post_install: false,
|
|
501
|
+
})
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
/** v4: no list to take a row from, so the pack goes by repo name at nightly */
|
|
505
|
+
private enqueuePluginTask = async (api: ManagerApi, plugin: ComfyManagerPluginInfo, uiId: string): Promise<void> => {
|
|
506
|
+
const url = plugin.files[0] ?? plugin.reference
|
|
507
|
+
const id = repoPath(url).split('/').pop() ?? url
|
|
508
|
+
const params = {
|
|
509
|
+
id,
|
|
510
|
+
version: 'nightly',
|
|
511
|
+
selected_version: 'nightly',
|
|
512
|
+
repository: url,
|
|
513
|
+
mode: 'cache',
|
|
514
|
+
channel: 'default',
|
|
207
515
|
}
|
|
516
|
+
await this.post(this.route(api, '/manager/queue/task'), {
|
|
517
|
+
ui_id: uiId,
|
|
518
|
+
client_id: this.clientId,
|
|
519
|
+
kind: 'install',
|
|
520
|
+
params,
|
|
521
|
+
})
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
/** v4: the task's own history entry says how it ended */
|
|
525
|
+
private settleByHistory = async (api: ManagerApi, what: string, uiId: string): Promise<void> => {
|
|
526
|
+
const route = this.route(api, '/manager/queue/history', `?ui_id=${encodeURIComponent(uiId)}`)
|
|
527
|
+
const entry = await this.waitFor(what, async () => {
|
|
528
|
+
const status = (await this.getValid(route, TaskHistory_ark)).history.status
|
|
529
|
+
if (status == null) await this.restartIdleQueue(api)
|
|
530
|
+
return status ?? null
|
|
531
|
+
})
|
|
532
|
+
if (entry.status_str === 'success' || entry.status_str === 'skip') return
|
|
533
|
+
const messages = entry.messages ?? []
|
|
534
|
+
// the 4.x worker answers a bare `failed` from its security gate only (4.2.2 and 4.4 source)
|
|
535
|
+
const gate =
|
|
536
|
+
messages.length === 1 && messages[0] === 'failed'
|
|
537
|
+
? ': refused by its security policy, which allows installs only with security_level normal or below ' +
|
|
538
|
+
'AND either ComfyUI listening on localhost or network_mode personal_cloud (the ComfyUI console names the rule)'
|
|
539
|
+
: ''
|
|
540
|
+
throw new Error(`the Manager reports ${entry.status_str}: ${messages.join(' | ')}${gate}`)
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
/**
|
|
544
|
+
* a worker lingers a few seconds after a drain, then exits; a start in that window answers 201
|
|
545
|
+
* "already running" and leaves the new task pending with no worker (seen live on 4.2.2, same loop
|
|
546
|
+
* in V3 and 4.4). So an idle queue that still holds work is started again.
|
|
547
|
+
*/
|
|
548
|
+
private restartIdleQueue = async (api: ManagerApi): Promise<'running' | 'restarted' | 'drained'> => {
|
|
549
|
+
const status = await this.getValid(this.route(api, '/manager/queue/status'), QueueStatus_ark)
|
|
550
|
+
if (status.is_processing) return 'running'
|
|
551
|
+
const waiting = status.pending_count ?? (status.total_count ?? 0) - (status.done_count ?? 0)
|
|
552
|
+
if (waiting <= 0) return 'drained'
|
|
553
|
+
await this.post(this.route(api, '/manager/queue/start'))
|
|
554
|
+
return 'restarted'
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
/** v3, v4 legacy ui: no per item result over http, so wait for the drain and look at the end state */
|
|
558
|
+
private settleByDrain = async (api: ManagerApi, what: string, landed: () => Promise<boolean>): Promise<void> => {
|
|
559
|
+
await this.waitFor(what, async () => ((await this.restartIdleQueue(api)) === 'drained' ? true : null))
|
|
560
|
+
if (!(await landed()))
|
|
561
|
+
throw new Error(
|
|
562
|
+
`the Manager queue drained but it is not installed; ComfyUI-Manager ${api.version} ` +
|
|
563
|
+
`reports why only over its websocket (cm-queue-status) and in the ComfyUI console`,
|
|
564
|
+
)
|
|
208
565
|
}
|
|
209
566
|
|
|
210
|
-
|
|
567
|
+
private runInstall = async (
|
|
568
|
+
what: string,
|
|
569
|
+
p: {
|
|
570
|
+
enqueue: (api: ManagerApi, uiId: string) => Promise<void>
|
|
571
|
+
/** the end state, read when the generation reports no per item result */
|
|
572
|
+
landed: (s: ManagerStrategy, api: ManagerApi) => Promise<boolean>
|
|
573
|
+
},
|
|
574
|
+
): Promise<boolean> => {
|
|
211
575
|
try {
|
|
212
|
-
await this.
|
|
213
|
-
|
|
214
|
-
|
|
576
|
+
const api = await this.api()
|
|
577
|
+
const s = this.strategy(api)
|
|
578
|
+
const uiId = nanoid()
|
|
579
|
+
await p.enqueue(api, uiId)
|
|
580
|
+
await this.post(this.route(api, '/manager/queue/start'))
|
|
581
|
+
await s.settle(what, uiId, () => p.landed(s, api))
|
|
582
|
+
logSuccess(`${what} installed`)
|
|
215
583
|
return true
|
|
216
584
|
} catch (exception) {
|
|
217
|
-
|
|
218
|
-
toastError('Custom Node Installation Failed')
|
|
585
|
+
logError(`${what}: install failed on ${this.host.getServerHostHTTP()}: ${errorText(exception)}`)
|
|
219
586
|
return false
|
|
220
587
|
}
|
|
221
588
|
}
|
|
222
589
|
|
|
590
|
+
/** poll until `check` gives a value, never past `timing.installTimeoutMs` */
|
|
591
|
+
private waitFor = async <T>(what: string, check: () => Promise<T | null>): Promise<T> => {
|
|
592
|
+
const deadline = Date.now() + this.timing.installTimeoutMs
|
|
593
|
+
for (;;) {
|
|
594
|
+
const value = await check()
|
|
595
|
+
if (value != null) return value
|
|
596
|
+
if (Date.now() >= deadline)
|
|
597
|
+
throw new Error(
|
|
598
|
+
`${what} still running after ${this.timing.installTimeoutMs} ms (manager.timing.installTimeoutMs)`,
|
|
599
|
+
)
|
|
600
|
+
await new Promise((resolve) => setTimeout(resolve, this.timing.pollMs))
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
|
|
223
604
|
// --------------------------------------------------------------
|
|
224
|
-
|
|
225
|
-
|
|
605
|
+
/** json POST (the Manager's csrf guard refuses simple form types); the reply json, or null when empty */
|
|
606
|
+
private post = async (route: string, body?: unknown): Promise<unknown> => {
|
|
607
|
+
const response = await this.host.fetch(route, {
|
|
226
608
|
method: 'POST',
|
|
227
609
|
headers: { 'Content-Type': 'application/json' },
|
|
228
|
-
body: JSON.stringify(body),
|
|
610
|
+
body: body === undefined ? undefined : JSON.stringify(body),
|
|
229
611
|
})
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
if (
|
|
233
|
-
|
|
234
|
-
|
|
612
|
+
const text = await response.text()
|
|
613
|
+
if (!response.ok) throw new Error(`POST ${route} → ${response.status} ${text}`.trim())
|
|
614
|
+
if (text === '') return null
|
|
615
|
+
try {
|
|
616
|
+
return JSON.parse(text)
|
|
617
|
+
} catch {
|
|
618
|
+
return text
|
|
619
|
+
}
|
|
235
620
|
}
|
|
236
621
|
|
|
237
|
-
private
|
|
238
|
-
const response = await this.host.fetch(
|
|
239
|
-
if (!response.ok) throw new Error(`GET ${
|
|
622
|
+
private getJSON = async <OUT = unknown>(route: string, validator?: Type<OUT>): Promise<OUT> => {
|
|
623
|
+
const response = await this.host.fetch(route)
|
|
624
|
+
if (!response.ok) throw new Error(`GET ${route} → ${response.status} ${await response.text()}`.trim())
|
|
240
625
|
const jsonResult = await response.json()
|
|
241
626
|
if (validator) return softValidate(validator, jsonResult)
|
|
242
627
|
// wire tolerance (agent/coding.md): unvalidated endpoints return unknown-shaped json
|
|
243
628
|
return jsonResult as OUT
|
|
244
629
|
}
|
|
245
630
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
const
|
|
249
|
-
|
|
631
|
+
/** a GET whose shape the decision depends on: a mismatch throws instead of lying */
|
|
632
|
+
private getValid = async <OUT>(route: string, schema: (json: unknown) => OUT | ArkErrors): Promise<OUT> => {
|
|
633
|
+
const res = schema(await this.getJSON(route))
|
|
634
|
+
if (res instanceof type.errors) throw new Error(`GET ${route}: ${res.summary}`)
|
|
635
|
+
return res
|
|
250
636
|
}
|
|
251
637
|
}
|
|
@@ -51,6 +51,9 @@ export type CanonicalInput = {
|
|
|
51
51
|
type: string
|
|
52
52
|
link: LiteGraphLinkID | null // null = unconnected (incl. omitted key)
|
|
53
53
|
widgetName: string | null // widget.name when widget-backed
|
|
54
|
+
/** an unlinked slot a subgraph input fed while that input had no outer link: it takes the
|
|
55
|
+
* value of the promoted widget, read from this sibling widget input (architecture.md) */
|
|
56
|
+
widgetSource: { nodeId: number; inputName: string } | null
|
|
54
57
|
}
|
|
55
58
|
|
|
56
59
|
export type CanonicalOutput = {
|
|
@@ -18,7 +18,7 @@ export type ComfyWorkflowJSON = LiteGraphJSON
|
|
|
18
18
|
export type LiteGraphJSON = {
|
|
19
19
|
id?: string // uuid (newer serializers)
|
|
20
20
|
revision?: number
|
|
21
|
-
last_node_id?: number // v0.4 (recomputable, absent in v1)
|
|
21
|
+
last_node_id?: number | string // v0.4 (recomputable, absent in v1), a NodeId: the official blueprints write a string
|
|
22
22
|
last_link_id?: number // v0.4
|
|
23
23
|
state?: Record<string, unknown> // v1: {lastNodeId, lastLinkId, …}
|
|
24
24
|
nodes: LiteGraphNode[]
|
|
@@ -41,7 +41,7 @@ export type LiteGraphJSON = {
|
|
|
41
41
|
export const LiteGraphJSON_ark = type({
|
|
42
42
|
'id?': 'string',
|
|
43
43
|
'revision?': 'number',
|
|
44
|
-
'last_node_id?': 'number',
|
|
44
|
+
'last_node_id?': 'number | string',
|
|
45
45
|
'last_link_id?': 'number',
|
|
46
46
|
'state?': type.Record('string', 'unknown'),
|
|
47
47
|
nodes: LiteGraphNode_ark.array(),
|