From 52180243955ffcf3ce6e03a346ab2fb55aebe29b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20D=C3=B3cs?= Date: Mon, 30 Dec 2024 04:26:03 +0100 Subject: [PATCH] Show workflow templates from custom nodes (#2032) --- .../templates/TemplateWorkflowCard.vue | 75 ++++++++ .../templates/TemplateWorkflowsContent.vue | 174 ++++++++++++------ src/scripts/api.ts | 11 ++ src/stores/workflowTemplatesStore.ts | 30 +++ vite.config.mts | 6 +- 5 files changed, 237 insertions(+), 59 deletions(-) create mode 100644 src/components/templates/TemplateWorkflowCard.vue create mode 100644 src/stores/workflowTemplatesStore.ts diff --git a/src/components/templates/TemplateWorkflowCard.vue b/src/components/templates/TemplateWorkflowCard.vue new file mode 100644 index 000000000..518f51b63 --- /dev/null +++ b/src/components/templates/TemplateWorkflowCard.vue @@ -0,0 +1,75 @@ + + + + + diff --git a/src/components/templates/TemplateWorkflowsContent.vue b/src/components/templates/TemplateWorkflowsContent.vue index 75a5af529..02c1d0f3a 100644 --- a/src/components/templates/TemplateWorkflowsContent.vue +++ b/src/components/templates/TemplateWorkflowsContent.vue @@ -1,81 +1,139 @@ diff --git a/src/scripts/api.ts b/src/scripts/api.ts index 686372481..5b5fe857e 100644 --- a/src/scripts/api.ts +++ b/src/scripts/api.ts @@ -397,6 +397,17 @@ export class ComfyApi extends EventTarget { return await resp.json() } + /** + * Gets the available workflow templates from custom nodes. + * @returns A map of custom_node names and associated template workflow names. + */ + async getWorkflowTemplates(): Promise<{ + [customNodesName: string]: string[] + }> { + const res = await this.fetchApi('/workflow_templates') + return await res.json() + } + /** * Gets a list of embedding names */ diff --git a/src/stores/workflowTemplatesStore.ts b/src/stores/workflowTemplatesStore.ts new file mode 100644 index 000000000..1c5721642 --- /dev/null +++ b/src/stores/workflowTemplatesStore.ts @@ -0,0 +1,30 @@ +import { defineStore } from 'pinia' +import { ref } from 'vue' +import { api } from '@/scripts/api' + +export const useWorkflowTemplatesStore = defineStore( + 'workflowTemplates', + () => { + const items = ref<{ + [customNodesName: string]: string[] + }>({}) + const isLoaded = ref(false) + + async function loadWorkflowTemplates() { + try { + if (!isLoaded.value) { + items.value = await api.getWorkflowTemplates() + isLoaded.value = true + } + } catch (error) { + console.error('Error fetching workflow templates:', error) + } + } + + return { + items, + isLoaded, + loadWorkflowTemplates + } + } +) diff --git a/vite.config.mts b/vite.config.mts index 7d454479b..9d94fe575 100644 --- a/vite.config.mts +++ b/vite.config.mts @@ -119,6 +119,10 @@ export default defineConfig({ ws: true }, + '/workflow_templates': { + target: DEV_SERVER_COMFYUI_URL + }, + '/testsubrouteindex': { target: 'http://localhost:5173', rewrite: (path) => path.substring('/testsubrouteindex'.length) @@ -183,4 +187,4 @@ export default defineConfig({ '@comfyorg/comfyui-electron-types' ] } -}) as UserConfigExport +}) as UserConfigExport \ No newline at end of file