Line data Source code
1 : import { uniqBy } from 'es-toolkit'
2 :
3 : import type { MissingModelCandidate } from '@/platform/workflowErrors/missingModel/types'
4 : import type { MissingNodeType } from '@/platform/workflowErrors/nodeReplacement/types'
5 : import type {
6 : MissingBuildModel,
7 : MissingBuildPack
8 : } from '@/platform/workspace/deploymentBuildBrief'
9 :
10 2355 : const CORE_PACK_ID = 'comfy-core'
11 :
12 : /** The class name of a missing node type. */
13 0 : export function missingNodeTypeName(nodeType: MissingNodeType): string {
14 0 : return typeof nodeType === 'string' ? nodeType : nodeType.type
15 : }
16 :
17 : /** Missing custom node types the editor found no replacement for, which only their pack can run. */
18 0 : export function nodesNeedingDeployment(
19 : nodeTypes: readonly MissingNodeType[]
20 : ): MissingNodeType[] {
21 0 : return nodeTypes.filter(
22 : (nodeType) =>
23 : typeof nodeType !== 'string' &&
24 : nodeType.isReplaceable === false &&
25 : nodeType.cnrId !== CORE_PACK_ID
26 : )
27 : }
28 :
29 : /** Missing node types by registry pack, with unknown-pack types last. */
30 0 : export function missingPacksOf(
31 : nodeTypes: readonly MissingNodeType[]
32 : ): MissingBuildPack[] {
33 0 : const byPack = new Map<string | null, string[]>()
34 0 : for (const nodeType of nodeTypes) {
35 0 : const packId = typeof nodeType === 'string' ? null : nodeType.cnrId || null
36 0 : const names = byPack.get(packId) ?? []
37 0 : const name = missingNodeTypeName(nodeType)
38 0 : if (!names.includes(name)) byPack.set(packId, [...names, name])
39 : }
40 0 : return [...byPack]
41 : .map(([packId, names]) => ({ packId, nodeTypes: names }))
42 : .sort((a, b) => Number(a.packId === null) - Number(b.packId === null))
43 : }
44 :
45 : /** Missing models as a deployment needs them: each file once per models folder. */
46 0 : export function missingModelsOf(
47 : candidates: readonly MissingModelCandidate[]
48 : ): MissingBuildModel[] {
49 0 : return uniqBy(
50 : candidates,
51 : (candidate) => `${candidate.directory ?? ''}/${candidate.name}`
52 : ).map((candidate) => ({
53 : name: candidate.name,
54 : directory: candidate.directory ?? null,
55 : url: candidate.url
56 : }))
57 : }
|