Line data Source code
1 : <template>
2 0 : <div
3 : data-component-id="ModelInfoPanel"
4 : class="flex scrollbar-custom h-full flex-col"
5 : >
6 : <PropertiesAccordionItem variant="card">
7 : <template #label>
8 : {{ t('assetBrowser.modelInfo.basicInfo') }}
9 : </template>
10 : <ModelInfoField :label="t('assetBrowser.modelInfo.displayName')">
11 : <div class="group flex justify-between">
12 : <EditableText
13 : :model-value="displayName"
14 : :is-editing="isEditingDisplayName"
15 : :class="cn('flex-auto break-all text-muted-foreground')"
16 : @dblclick="isEditingDisplayName = !isImmutable"
17 : @edit="handleDisplayNameEdit"
18 : @cancel="isEditingDisplayName = false"
19 : />
20 : <Button
21 : v-if="!isImmutable && !isEditingDisplayName"
22 : size="icon-sm"
23 : variant="muted-textonly"
24 : class="opacity-0 transition-opacity group-hover:opacity-100"
25 : :aria-label="t('assetBrowser.modelInfo.editDisplayName')"
26 : @click="isEditingDisplayName = !isImmutable"
27 : >
28 : <i class="icon-[lucide--square-pen] self-center" />
29 : </Button>
30 : </div>
31 : </ModelInfoField>
32 : <ModelInfoField :label="t('assetBrowser.modelInfo.fileName')">
33 : <span class="break-all text-muted-foreground">{{
34 : getAssetFilename(asset)
35 : }}</span>
36 : </ModelInfoField>
37 : <ModelInfoField
38 : v-if="sourceUrl"
39 : :label="t('assetBrowser.modelInfo.source')"
40 : >
41 : <a
42 : :href="sourceUrl"
43 : target="_blank"
44 : rel="noopener noreferrer"
45 : class="inline-flex items-center gap-1.5 text-muted-foreground no-underline transition-colors hover:text-foreground"
46 : >
47 : <img
48 : v-if="sourceName === 'Civitai'"
49 : src="/assets/images/civitai.svg"
50 : alt=""
51 : class="size-4 shrink-0"
52 : />
53 : <img
54 : v-else-if="sourceName === 'Hugging Face'"
55 : src="/assets/images/hf-logo.svg"
56 : alt=""
57 : class="size-4 shrink-0"
58 : />
59 : {{ t('assetBrowser.modelInfo.viewOnSource', { source: sourceName }) }}
60 : <i class="icon-[lucide--external-link]" />
61 : </a>
62 : </ModelInfoField>
63 : </PropertiesAccordionItem>
64 :
65 : <PropertiesAccordionItem variant="card">
66 : <template #label>
67 : {{ t('assetBrowser.modelInfo.modelTagging') }}
68 : </template>
69 : <ModelInfoField :label="t('assetBrowser.modelInfo.modelType')">
70 : <Select v-if="isModelTypeEditable" v-model="selectedModelType">
71 : <SelectTrigger>
72 : <SelectValue
73 : :placeholder="t('assetBrowser.modelInfo.selectModelType')"
74 : />
75 : </SelectTrigger>
76 : <SelectContent>
77 0 : <SelectItem
78 : v-for="option in modelTypes"
79 : :key="option.value"
80 : :value="option.value"
81 : >
82 : {{ option.name }}
83 : </SelectItem>
84 : </SelectContent>
85 : </Select>
86 : <template v-else>
87 : <div
88 : aria-disabled="true"
89 : :aria-describedby="modelTypeReadonlyReasonId"
90 : class="cursor-not-allowed p-2 text-muted-foreground"
91 : >
92 : {{
93 : modelTypes.find((o) => o.value === selectedModelType)?.name ??
94 : t('assetBrowser.unknown')
95 : }}
96 : </div>
97 : <span :id="modelTypeReadonlyReasonId" class="sr-only">
98 : {{ modelTypeReadonlyReason }}
99 : </span>
100 : </template>
101 : </ModelInfoField>
102 : <ModelInfoField :label="t('assetBrowser.modelInfo.compatibleBaseModels')">
103 : <TagEditor
104 : v-model="baseModels"
105 : :disabled="isImmutable"
106 : :placeholder="
107 : isImmutable
108 : ? t('assetBrowser.modelInfo.baseModelUnknown')
109 : : t('assetBrowser.modelInfo.addBaseModel')
110 : "
111 : />
112 : </ModelInfoField>
113 : <ModelInfoField :label="t('assetBrowser.modelInfo.additionalTags')">
114 : <TagEditor
115 : v-model="additionalTags"
116 : :disabled="isImmutable"
117 : :placeholder="
118 : isImmutable
119 : ? t('assetBrowser.modelInfo.noAdditionalTags')
120 : : t('assetBrowser.modelInfo.addTag')
121 : "
122 : />
123 : </ModelInfoField>
124 : </PropertiesAccordionItem>
125 :
126 : <PropertiesAccordionItem variant="card">
127 : <template #label>
128 : {{ t('assetBrowser.modelInfo.modelDescription') }}
129 : </template>
130 : <ModelInfoField
131 : v-if="triggerPhrases.length > 0"
132 : :label="t('assetBrowser.modelInfo.triggerPhrases')"
133 : >
134 : <template #label-action>
135 : <Button
136 : variant="muted-textonly"
137 : size="icon-sm"
138 : :title="t('g.copyAll')"
139 : :aria-label="t('g.copyAll')"
140 : @click="copyToClipboard(triggerPhrases.join(', '))"
141 : >
142 : <i class="icon-[lucide--copy] min-h-4 min-w-4 opacity-60" />
143 : </Button>
144 : </template>
145 : <div class="flex flex-wrap gap-1 pt-1">
146 0 : <Button
147 : v-for="phrase in triggerPhrases"
148 : :key="phrase"
149 : variant="muted-textonly"
150 : size="unset"
151 : :title="t('g.copyToClipboard')"
152 : class="text-left text-xs text-pretty whitespace-normal"
153 : @click="copyToClipboard(phrase)"
154 : >
155 : {{ phrase }}
156 : <i class="icon-[lucide--copy] min-h-4 min-w-4 opacity-60" />
157 : </Button>
158 : </div>
159 : </ModelInfoField>
160 : <ModelInfoField
161 : v-if="description"
162 : :label="t('assetBrowser.modelInfo.description')"
163 : >
164 : <p class="whitespace-pre-wrap">{{ description }}</p>
165 : </ModelInfoField>
166 : <ModelInfoField :label="t('assetBrowser.modelInfo.description')">
167 : <textarea
168 : ref="descriptionTextarea"
169 : v-model="userDescription"
170 : :disabled="isImmutable"
171 : :placeholder="
172 : isImmutable
173 : ? t('assetBrowser.modelInfo.descriptionNotSet')
174 : : t('assetBrowser.modelInfo.descriptionPlaceholder')
175 : "
176 : rows="3"
177 : :class="
178 : cn(
179 : 'w-full resize-y scrollbar-gutter-stable rounded-lg border border-transparent bg-transparent px-3 py-2 transition-colors outline-none focus:bg-input',
180 : isImmutable && 'cursor-not-allowed'
181 : )
182 : "
183 : @keydown.escape.stop="descriptionTextarea?.blur()"
184 : />
185 : </ModelInfoField>
186 : </PropertiesAccordionItem>
187 : </div>
188 : </template>
189 :
190 : <script setup lang="ts">
191 : import { useDebounceFn } from '@vueuse/core'
192 : import { computed, ref, useId, useTemplateRef, watch } from 'vue'
193 : import { useI18n } from 'vue-i18n'
194 :
195 : import EditableText from '@comfyorg/design-system/common/EditableText'
196 : import { useCopyToClipboard } from '@/composables/useCopyToClipboard'
197 : import { useFeatureFlags } from '@/composables/useFeatureFlags'
198 : import PropertiesAccordionItem from '@comfyorg/design-system/accordion/PropertiesAccordionItem'
199 : import Button from '@comfyorg/design-system/button/Button'
200 : import Select from '@comfyorg/design-system/select/Select'
201 : import SelectContent from '@comfyorg/design-system/select/SelectContent'
202 : import SelectItem from '@comfyorg/design-system/select/SelectItem'
203 : import SelectTrigger from '@comfyorg/design-system/select/SelectTrigger'
204 : import SelectValue from '@comfyorg/design-system/select/SelectValue'
205 : import TagEditor from '@/components/common/TagEditor.vue'
206 : import type { AssetDisplayItem } from '@/platform/assets/composables/useAssetBrowser'
207 : import { useModelTypes } from '@/platform/assets/composables/useModelTypes'
208 : import { isCloud } from '@/platform/distribution/types'
209 : import { useAssetMetadataStore } from '@/platform/assets/stores/assetMetadataStore'
210 : import {
211 : getAssetAdditionalTags,
212 : getAssetBaseModels,
213 : getAssetDescription,
214 : getAssetDisplayName,
215 : getAssetFilename,
216 : getAssetSourceUrl,
217 : getAssetTriggerPhrases,
218 : getAssetUserDescription,
219 : getEditableModelType,
220 : getSourceName,
221 : resolveModelTypeTagUpdate
222 : } from '@/platform/assets/utils/assetMetadataUtils'
223 : import { useAssetsStore } from '@/stores/assetsStore'
224 : import { cn } from '@comfyorg/tailwind-utils'
225 :
226 : import ModelInfoField from '@comfyorg/design-system/field/ModelInfoField'
227 :
228 0 : const { t } = useI18n()
229 0 : const { copyToClipboard } = useCopyToClipboard()
230 :
231 0 : const descriptionTextarea = useTemplateRef<HTMLTextAreaElement>(
232 : 'descriptionTextarea'
233 : )
234 :
235 : const { asset, cacheKey } = defineProps<{
236 : asset: AssetDisplayItem
237 : cacheKey?: string
238 : }>()
239 :
240 0 : const assetsStore = useAssetsStore()
241 0 : const metadataStore = useAssetMetadataStore()
242 0 : const { flags } = useFeatureFlags()
243 0 : const { modelTypes } = useModelTypes()
244 :
245 0 : const pendingUpdates = computed(() => metadataStore.getPendingUpdates(asset.id))
246 0 : const pendingModelType = ref<string | undefined>(undefined)
247 0 : const isEditingDisplayName = ref(false)
248 :
249 0 : const isImmutable = computed(() => asset.is_immutable ?? true)
250 : // Retagging a model rewrites its asset tags; core is filesystem-backed and does
251 : // not yet move the file to match, so the model type is read-only off-cloud.
252 0 : const isModelTypeEditable = computed(() => !isImmutable.value && isCloud)
253 : // The read-only field is reached for an immutable asset (even on cloud) or on
254 : // core. Immutability is the more specific, actionable reason, so it wins when
255 : // both hold rather than blaming "core" on a cloud deployment.
256 0 : const modelTypeReadonlyReason = computed(() =>
257 : isImmutable.value
258 : ? t('assetBrowser.modelInfo.modelTypeImmutableReadonly')
259 : : t('assetBrowser.modelInfo.modelTypeCoreReadonly')
260 : )
261 0 : const modelTypeReadonlyReasonId = useId()
262 0 : const displayName = computed(
263 : () => pendingUpdates.value.name ?? getAssetDisplayName(asset)
264 : )
265 0 : const sourceUrl = computed(() => getAssetSourceUrl(asset))
266 0 : const sourceName = computed(() =>
267 : sourceUrl.value ? getSourceName(sourceUrl.value) : ''
268 : )
269 0 : const description = computed(() => getAssetDescription(asset))
270 0 : const triggerPhrases = computed(() => getAssetTriggerPhrases(asset))
271 :
272 0 : watch(
273 : () => asset.tags,
274 : () => {
275 0 : pendingModelType.value = undefined
276 : }
277 : )
278 :
279 0 : function handleDisplayNameEdit(newName: string) {
280 0 : isEditingDisplayName.value = false
281 0 : if (newName && newName !== displayName.value) {
282 0 : metadataStore.queueUpdate(asset, { name: newName }, cacheKey)
283 : }
284 : }
285 :
286 0 : const debouncedSaveModelType = useDebounceFn((newModelType: string) => {
287 0 : const newTags = resolveModelTypeTagUpdate(
288 : asset,
289 : newModelType,
290 : isModelTypeEditable.value,
291 : flags.supportsModelTypeTags
292 : )
293 0 : if (newTags) assetsStore.updateAssetTags(asset, newTags, cacheKey)
294 : }, 500)
295 :
296 0 : const baseModels = computed({
297 : get: () => pendingUpdates.value.base_model ?? getAssetBaseModels(asset),
298 : set: (value: string[]) =>
299 : metadataStore.queueUpdate(asset, { base_model: value }, cacheKey)
300 : })
301 :
302 0 : const additionalTags = computed({
303 : get: () =>
304 : pendingUpdates.value.additional_tags ?? getAssetAdditionalTags(asset),
305 : set: (value: string[]) =>
306 : metadataStore.queueUpdate(asset, { additional_tags: value }, cacheKey)
307 : })
308 :
309 0 : const userDescription = computed({
310 : get: () =>
311 : pendingUpdates.value.user_description ?? getAssetUserDescription(asset),
312 : set: (value: string) =>
313 : metadataStore.queueUpdate(asset, { user_description: value }, cacheKey)
314 : })
315 :
316 0 : const selectedModelType = computed({
317 : get: () =>
318 : pendingModelType.value ??
319 : getEditableModelType(asset, flags.supportsModelTypeTags) ??
320 : undefined,
321 : set: (value: string | undefined) => {
322 0 : if (!value) return
323 0 : pendingModelType.value = value
324 0 : debouncedSaveModelType(value)
325 : }
326 : })
327 : </script>
|