Line data Source code
1 5 : <template>
2 : <div class="extension-panel flex flex-col gap-2">
3 : <SearchInput
4 : v-model="searchQuery"
5 : :clear-label="$t('g.clear')"
6 : :accessible-label="
7 : $t('g.searchPlaceholder', { subject: $t('g.extensions') })
8 : "
9 : :placeholder="$t('g.searchPlaceholder', { subject: $t('g.extensions') })"
10 : />
11 : <Message v-if="hasChanges" severity="info" class="max-h-96 overflow-y-auto">
12 : <ul>
13 1 : <li v-for="ext in changedExtensions" :key="ext.name">
14 : <span>
15 : {{ extensionStore.isExtensionEnabled(ext.name) ? '[-]' : '[+]' }}
16 : </span>
17 : {{ ext.name }}
18 : </li>
19 3 : <li v-for="path in changedExtensionPaths" :key="path">
20 : <span>
21 : {{
22 : extensionStore.isExtensionPathEnabledAtBoot(path) ? '[-]' : '[+]'
23 : }}
24 : </span>
25 : {{ extensionNameFromPath(path) }}
26 : </li>
27 : </ul>
28 : <div class="flex justify-end">
29 : <Button
30 : variant="destructive"
31 : :disabled="extensionStore.isSavingExtensionPaths"
32 : @click="applyChanges"
33 : >
34 : {{ $t('g.reloadToApplyChanges') }}
35 : </Button>
36 : </div>
37 : </Message>
38 : <div class="mb-3 flex gap-2">
39 : <ToggleGroup v-model="filterType" type="single" :allow-empty="false">
40 116 : <ToggleGroupItem
41 : v-for="option in filterTypes"
42 : :key="option.value"
43 : :value="option.value"
44 : >
45 : {{ option.label }}
46 : </ToggleGroupItem>
47 : </ToggleGroup>
48 : </div>
49 : <ExtensionPathTable
50 : :paths="extensionStore.extensionPaths"
51 : :enabled-by-path
52 : :disabled="extensionStore.isSavingExtensionPaths"
53 : @set-enabled="handleExtensionPathEnabled"
54 : />
55 : <ExtensionListTable
56 : v-model:direction="nameSortDirection"
57 : :extensions="visibleExtensions"
58 : :selected-names
59 : :enabled-by-name
60 : :select-all-state
61 : :actions
62 : @toggle-all="toggleAllVisible"
63 : @set-selected="setExtensionSelected"
64 : @set-enabled="setExtensionEnabled"
65 : />
66 : </div>
67 : </template>
68 :
69 : <script setup lang="ts">
70 : import type { CheckboxCheckedState } from 'reka-ui'
71 : import { computed, ref, watch } from 'vue'
72 : import { useI18n } from 'vue-i18n'
73 :
74 : import Button from '@comfyorg/design-system/button/Button'
75 : import type { MenuItem } from '@comfyorg/design-system/lib/menu/types'
76 : import Message from '@comfyorg/design-system/message/Message'
77 : import SearchInput from '@comfyorg/design-system/search-input/SearchInput'
78 : import {
79 : filterByQuery,
80 : sortByText
81 : } from '@comfyorg/design-system/lib/table/tableUtils'
82 : import type { TableSortDirection } from '@comfyorg/design-system/lib/table/tableUtils'
83 : import ToggleGroup from '@comfyorg/design-system/toggle-group/ToggleGroup'
84 : import ToggleGroupItem from '@comfyorg/design-system/toggle-group/ToggleGroupItem'
85 : import { useToast } from '@/components/ui/toast/toastStore'
86 : import ExtensionListTable from '@/platform/extensions/components/ExtensionListTable.vue'
87 : import ExtensionPathTable from '@/platform/extensions/components/ExtensionPathTable.vue'
88 : import { useSettingStore } from '@/platform/settings/settingStore'
89 : import { extensionNameFromPath } from '@/platform/settings/utils/extensionPath'
90 : import { useExtensionStore } from '@/platform/extensions/stores/extensionStore'
91 :
92 9 : const { t } = useI18n()
93 :
94 9 : const filterTypeKeys = ['all', 'core', 'custom', 'agentCreated'] as const
95 : type FilterTypeKey = (typeof filterTypeKeys)[number]
96 9 : const filterTypes = computed(() =>
97 : filterTypeKeys.map((key) => ({
98 : label: t(`g.${key}`),
99 : value: key
100 : }))
101 : )
102 9 : const filterType = ref<FilterTypeKey>('all')
103 9 : const selectedNames = ref(new Set<string>())
104 9 : const searchQuery = ref('')
105 9 : const nameSortDirection = ref<TableSortDirection | null>(null)
106 :
107 9 : const extensionStore = useExtensionStore()
108 9 : const settingStore = useSettingStore()
109 9 : const toast = useToast()
110 :
111 9 : const enabledByName = ref<Record<string, boolean>>({})
112 :
113 9 : const filteredExtensions = computed(() => {
114 11 : const extensions = extensionStore.extensions
115 11 : switch (filterType.value) {
116 : case 'core':
117 0 : return extensions.filter((ext) =>
118 : extensionStore.isCoreExtension(ext.name)
119 : )
120 : case 'custom':
121 0 : return extensions.filter(
122 : (ext) => !extensionStore.isCoreExtension(ext.name)
123 : )
124 : case 'agentCreated':
125 1 : return extensionStore.agentExtensions
126 : default:
127 10 : return extensions
128 : }
129 : })
130 :
131 9 : const visibleExtensions = computed(() => {
132 11 : const filtered = filterByQuery(
133 : filteredExtensions.value,
134 : searchQuery.value,
135 : (extension) => [extension.name]
136 : )
137 11 : return sortByText(
138 : filtered,
139 : nameSortDirection.value,
140 : (extension) => extension.name
141 : )
142 : })
143 :
144 9 : const selectAllState = computed<CheckboxCheckedState>(() => {
145 11 : const selectedCount = visibleExtensions.value.filter((extension) =>
146 : selectedNames.value.has(extension.name)
147 : ).length
148 11 : if (selectedCount === 0) return false
149 11 : return selectedCount === visibleExtensions.value.length
150 : ? true
151 : : 'indeterminate'
152 : })
153 :
154 0 : function setExtensionSelected(name: string, selected: CheckboxCheckedState) {
155 0 : const names = new Set(selectedNames.value)
156 0 : if (selected === true) names.add(name)
157 0 : else names.delete(name)
158 0 : selectedNames.value = names
159 : }
160 :
161 0 : function toggleAllVisible(selected: CheckboxCheckedState) {
162 0 : selectedNames.value = new Set(
163 : selected === true
164 : ? visibleExtensions.value.map((extension) => extension.name)
165 : : []
166 : )
167 : }
168 :
169 9 : watch(
170 : () => extensionStore.extensions,
171 : (extensions) => {
172 9 : extensions.forEach((ext) => {
173 321 : if (ext.name in enabledByName.value) return
174 321 : enabledByName.value[ext.name] = extensionStore.isExtensionEnabled(
175 : ext.name
176 : )
177 : })
178 : },
179 : { immediate: true }
180 : )
181 :
182 9 : const enabledByPath = computed(() => {
183 12 : const disabledPaths = new Set(
184 : extensionStore.getCurrentDisabledExtensionPaths()
185 : )
186 12 : return Object.fromEntries(
187 : extensionStore.extensionPaths.map((path) => [
188 : path,
189 : !disabledPaths.has(path)
190 : ])
191 : )
192 : })
193 :
194 9 : const changedExtensions = computed(() => {
195 10 : return extensionStore.extensions.filter(
196 : (ext) =>
197 : enabledByName.value[ext.name] !==
198 : extensionStore.isExtensionEnabled(ext.name)
199 : )
200 : })
201 :
202 9 : const changedExtensionPaths = computed(() => {
203 12 : return extensionStore.extensionPaths.filter(
204 : (path) =>
205 : enabledByPath.value[path] !==
206 : extensionStore.isExtensionPathEnabledAtBoot(path)
207 : )
208 : })
209 :
210 9 : const hasChanges = computed(() => {
211 13 : return (
212 : changedExtensions.value.length > 0 || changedExtensionPaths.value.length > 0
213 : )
214 : })
215 :
216 9 : const updateExtensionStatus = async () => {
217 2 : const editingDisabledExtensionNames = Object.entries(enabledByName.value)
218 : .filter(([_, enabled]) => !enabled)
219 : .map(([name]) => name)
220 :
221 2 : await settingStore.set('Comfy.Extension.Disabled', [
222 : ...extensionStore.inactiveDisabledExtensionNames,
223 : ...editingDisabledExtensionNames
224 : ])
225 : }
226 :
227 0 : async function setExtensionEnabled(name: string, enabled: boolean) {
228 0 : enabledByName.value[name] = enabled
229 0 : await updateExtensionStatus()
230 : }
231 :
232 2 : async function handleExtensionPathEnabled(path: string, enabled: boolean) {
233 2 : const result = await extensionStore.setExtensionPathEnabled(path, enabled)
234 2 : if (result === 'refused') {
235 1 : toast.warning(t('g.warning'), {
236 : description: t('g.extensionPathSaveRefused'),
237 : duration: 5000
238 : })
239 1 : } else if (result === 'unconfirmed' || result === 'indeterminate') {
240 1 : toast.warning(t('g.warning'), {
241 : description: t('g.extensionPathSaveUnconfirmed'),
242 : duration: 5000
243 : })
244 : }
245 : }
246 :
247 9 : const enableAllExtensions = async () => {
248 0 : extensionStore.extensions.forEach((ext) => {
249 0 : if (extensionStore.isExtensionReadOnly(ext.name)) return
250 :
251 0 : enabledByName.value[ext.name] = true
252 : })
253 0 : await updateExtensionStatus()
254 : }
255 :
256 9 : const disableAllExtensions = async () => {
257 0 : extensionStore.extensions.forEach((ext) => {
258 0 : if (extensionStore.isExtensionReadOnly(ext.name)) return
259 :
260 0 : enabledByName.value[ext.name] = false
261 : })
262 0 : await updateExtensionStatus()
263 : }
264 :
265 9 : const disableThirdPartyExtensions = async () => {
266 0 : extensionStore.extensions.forEach((ext) => {
267 0 : if (extensionStore.isCoreExtension(ext.name)) return
268 :
269 0 : enabledByName.value[ext.name] = false
270 : })
271 0 : await updateExtensionStatus()
272 : }
273 :
274 1 : async function disableAgentExtensions() {
275 1 : extensionStore.agentExtensions.forEach((ext) => {
276 1 : if (extensionStore.isExtensionReadOnly(ext.name)) return
277 :
278 1 : enabledByName.value[ext.name] = false
279 : })
280 1 : await updateExtensionStatus()
281 : }
282 :
283 9 : const applyChanges = () => {
284 0 : window.location.reload()
285 : }
286 :
287 9 : const actions = computed<MenuItem[]>(() => [
288 : {
289 : label: t('g.enableSelected'),
290 : icon: 'icon-[lucide--check]',
291 : command: async () => {
292 1 : selectedNames.value.forEach((name) => {
293 0 : if (!extensionStore.isExtensionReadOnly(name)) {
294 0 : enabledByName.value[name] = true
295 : }
296 : })
297 1 : await updateExtensionStatus()
298 : }
299 : },
300 : {
301 : label: t('g.disableSelected'),
302 : icon: 'icon-[lucide--x]',
303 : command: async () => {
304 0 : selectedNames.value.forEach((name) => {
305 0 : if (!extensionStore.isExtensionReadOnly(name)) {
306 0 : enabledByName.value[name] = false
307 : }
308 : })
309 0 : await updateExtensionStatus()
310 : }
311 : },
312 : {
313 : separator: true
314 : },
315 : {
316 : label: t('g.enableAll'),
317 : icon: 'icon-[lucide--check]',
318 : command: enableAllExtensions
319 : },
320 : {
321 : label: t('g.disableAll'),
322 : icon: 'icon-[lucide--x]',
323 : command: disableAllExtensions
324 : },
325 : {
326 : label: t('g.disableThirdParty'),
327 : icon: 'icon-[lucide--x]',
328 : command: disableThirdPartyExtensions,
329 : disabled: !extensionStore.hasThirdPartyExtensions
330 : },
331 : {
332 : label: t('g.disableAgentCreated'),
333 : icon: 'icon-[lucide--x]',
334 : command: disableAgentExtensions,
335 : disabled: !extensionStore.agentExtensions.some(
336 : (extension) => !extensionStore.isExtensionReadOnly(extension.name)
337 : )
338 : }
339 : ])
340 : </script>
|