Line data Source code
1 : <template>
2 50 : <div class="px-3">
3 : <div
4 : v-if="showGatedModelsHint"
5 : :id="gatedHintId"
6 : data-testid="missing-model-gated-hint"
7 : role="note"
8 : class="mb-2 flex gap-2 rounded-md border border-warning/30 bg-warning/10 p-2.5 text-warning"
9 : >
10 : <i aria-hidden="true" class="mt-0.5 icon-[lucide--lock]" />
11 : <p class="m-0 text-xs/relaxed">
12 : <span class="font-semibold">
13 : {{ t('rightSidePanel.missingModels.gatedModelsHintLabel') }}
14 : </span>
15 : {{ t('rightSidePanel.missingModels.gatedModelsHint', gatedModelCount) }}
16 : </p>
17 : </div>
18 : <span role="status" aria-live="polite" class="sr-only">
19 : {{ gatedModelsAnnouncement }}
20 : </span>
21 :
22 : <div
23 : v-if="downloadableModels.length > 0"
24 : data-testid="missing-model-actions"
25 : class="mb-2 flex items-center"
26 : >
27 : <Button
28 : data-testid="missing-model-download-all"
29 : variant="secondary"
30 : size="sm"
31 : class="h-8 min-w-0 flex-1 rounded-md"
32 : :aria-describedby="showGatedModelsHint ? gatedHintId : undefined"
33 : @click="downloadAllModels"
34 : >
35 : <i aria-hidden="true" class="icon-[lucide--download]" />
36 : <span class="truncate">{{ downloadAllLabel }}</span>
37 : </Button>
38 : </div>
39 :
40 : <div
41 : v-if="importableModelRows.length > 0"
42 : data-testid="missing-model-importable-rows"
43 : class="-mx-1.5 flex flex-col gap-1 overflow-hidden px-1.5"
44 : >
45 50 : <MissingModelRow
46 : v-for="row in importableModelRows"
47 : :key="row.key"
48 : :model="row.model"
49 : :directory="row.directory"
50 : :is-asset-supported="row.isAssetSupported"
51 : :can-cloud-import="!onDeployment"
52 : :highlighted="isRowHighlighted(row)"
53 : @locate-model="emit('locateModel', $event)"
54 : />
55 : </div>
56 :
57 : <div
58 : v-if="unsupportedModelRows.length > 0"
59 : data-testid="missing-model-import-not-supported-section"
60 : class="flex flex-col gap-1 border-t border-secondary pt-3"
61 : >
62 : <div class="mb-1">
63 : <p class="m-0 text-sm font-semibold text-warning">
64 : {{ t('rightSidePanel.missingModels.importNotSupported') }}
65 : </p>
66 : <p class="m-0 mt-1 text-xs/relaxed text-muted-foreground">
67 : {{ t('rightSidePanel.missingModels.customNodeDownloadDisabled') }}
68 : </p>
69 : </div>
70 0 : <MissingModelRow
71 : v-for="row in unsupportedModelRows"
72 : :key="row.key"
73 : :model="row.model"
74 : :directory="row.directory"
75 : :is-asset-supported="row.isAssetSupported"
76 : :can-cloud-import="false"
77 : :highlighted="isRowHighlighted(row)"
78 : @locate-model="emit('locateModel', $event)"
79 : />
80 : </div>
81 : </div>
82 : </template>
83 :
84 : <script setup lang="ts">
85 : import { computed, ref, useId, watch } from 'vue'
86 : import { useI18n } from 'vue-i18n'
87 : import type { MissingModelGroup } from '@/platform/workflowErrors/missingModel/types'
88 : import { isCloud } from '@/platform/distribution/types'
89 : import MissingModelRow from '@/platform/workflowErrors/missingModel/components/MissingModelRow.vue'
90 : import Button from '@comfyorg/design-system/button/Button'
91 : import { useDownloadAllMissingModels } from '@/platform/workflowErrors/missingModel/composables/useDownloadAllMissingModels'
92 :
93 : interface MissingModelRowEntry {
94 : key: string
95 : model: MissingModelGroup['models'][number]
96 : directory: string | null
97 : isAssetSupported: boolean
98 : }
99 :
100 35 : const MODEL_TYPE_SORT_ORDER = [
101 : 'checkpoints',
102 : 'loras',
103 : 'vae',
104 : 'text_encoders',
105 : 'diffusion_models'
106 : ] as const
107 :
108 : const {
109 : missingModelGroups,
110 : highlightedNodeIds,
111 : onDeployment = false
112 : } = defineProps<{
113 : missingModelGroups: MissingModelGroup[]
114 : /** Execution node ids to emphasize (current canvas selection). */
115 : highlightedNodeIds?: Set<string>
116 : /** Lists every model in one list, with no Comfy Cloud import. */
117 : onDeployment?: boolean
118 : }>()
119 :
120 35 : const emit = defineEmits<{
121 : locateModel: [nodeId: string]
122 : }>()
123 :
124 35 : const { t } = useI18n()
125 35 : const gatedHintId = useId()
126 35 : const {
127 : downloadableModels,
128 : gatedModelCount,
129 : downloadAllLabel,
130 : downloadAllModels
131 : } = useDownloadAllMissingModels(() => missingModelGroups)
132 :
133 35 : const sortedModelRows = computed(() =>
134 : missingModelGroups
135 : .flatMap((group) =>
136 : group.models.map((model, index) => ({
137 : key: getModelRowKey(group, model, index),
138 : model,
139 : directory: group.directory,
140 : isAssetSupported: group.isAssetSupported
141 : }))
142 : )
143 : .sort((a, b) => compareModelRows(a, b))
144 : )
145 :
146 35 : const importableModelRows = computed(() =>
147 : sortedModelRows.value.filter(
148 : (row) => onDeployment || !isCloud || canCloudImport(row)
149 : )
150 : )
151 :
152 35 : const unsupportedModelRows = computed(() =>
153 : isCloud && !onDeployment
154 : ? sortedModelRows.value.filter((row) => !canCloudImport(row))
155 : : []
156 : )
157 :
158 35 : const showGatedModelsHint = computed(() => gatedModelCount.value > 0)
159 35 : const gatedModelsAnnouncement = ref('')
160 :
161 35 : watch(showGatedModelsHint, (isVisible, wasVisible) => {
162 0 : if (!isVisible) {
163 0 : gatedModelsAnnouncement.value = ''
164 0 : return
165 : }
166 0 : if (wasVisible) return
167 :
168 0 : gatedModelsAnnouncement.value = `${t(
169 : 'rightSidePanel.missingModels.gatedModelsHintLabel'
170 : )} ${t(
171 : 'rightSidePanel.missingModels.gatedModelsHint',
172 : gatedModelCount.value
173 : )}`
174 : })
175 :
176 37 : function getModelRowKey(
177 : group: MissingModelGroup,
178 : model: MissingModelGroup['models'][number],
179 : index: number
180 : ) {
181 : const supportKey = group.isAssetSupported ? 'supported' : 'unsupported'
182 37 : return [
183 : supportKey,
184 : group.directory ?? '__unknown__',
185 : model.name,
186 : String(index)
187 : ].join('::')
188 : }
189 :
190 0 : function compareModelRows(a: MissingModelRowEntry, b: MissingModelRowEntry) {
191 0 : return (
192 : getModelTypeSortIndex(a.directory) - getModelTypeSortIndex(b.directory) ||
193 : (a.directory ?? '').localeCompare(b.directory ?? '') ||
194 : a.model.name.localeCompare(b.model.name)
195 : )
196 : }
197 :
198 0 : function getModelTypeSortIndex(directory: string | null) {
199 0 : if (directory === null) return Number.MAX_SAFE_INTEGER
200 0 : const index = MODEL_TYPE_SORT_ORDER.indexOf(
201 : directory as (typeof MODEL_TYPE_SORT_ORDER)[number]
202 : )
203 0 : return index === -1 ? MODEL_TYPE_SORT_ORDER.length : index
204 : }
205 :
206 : function canCloudImport(row: MissingModelRowEntry) {
207 : return row.isAssetSupported && row.directory !== null
208 : }
209 :
210 50 : function isRowHighlighted(row: MissingModelRowEntry) {
211 50 : if (!highlightedNodeIds?.size) return false
212 15 : return row.model.referencingNodes.some((ref) =>
213 : highlightedNodeIds.has(String(ref.nodeId))
214 : )
215 : }
216 : </script>
|