Line data Source code
1 : <template>
2 0 : <div
3 : data-testid="deployment-build-actions"
4 : class="flex flex-col gap-2 px-2 pb-2"
5 : >
6 : <template v-if="changeSinceBootMessage">
7 : <p
8 : role="status"
9 : class="m-0 text-xs text-pretty text-muted-foreground"
10 : data-testid="deployment-build-changed"
11 : >
12 : {{ changeSinceBootMessage }}
13 : </p>
14 : <Button
15 : variant="secondary"
16 : size="md"
17 : class="w-full"
18 : data-testid="deployment-build-reload"
19 : :disabled="isSwitching"
20 : @click="reloadOntoCurrent()"
21 : >
22 : <i class="icon-[lucide--refresh-cw]" aria-hidden="true" />
23 : {{ $t('deploymentSwitcher.reload') }}
24 : </Button>
25 : </template>
26 : <template v-else>
27 : <Button
28 : variant="inverted"
29 : size="md"
30 : as="a"
31 : :href="buildUrl"
32 : target="_blank"
33 : rel="noopener noreferrer"
34 : class="w-full no-underline"
35 : data-testid="deployment-build-platform"
36 : >
37 : {{
38 : deployment.build_id
39 : ? $t('rightSidePanel.editBuildOnPlatform')
40 : : $t('rightSidePanel.openBuildsOnPlatform')
41 : }}
42 : <i
43 : class="icon-[lucide--square-arrow-out-up-right]"
44 : aria-hidden="true"
45 : />
46 : </Button>
47 : <Button
48 : variant="secondary"
49 : size="md"
50 : :class="cn('w-full', !copied && 'gap-3')"
51 : data-testid="deployment-build-agent"
52 : :loading="isCopying"
53 : @click="copy(brief())"
54 : >
55 : <template v-if="copied">
56 : <i class="icon-[lucide--check]" aria-hidden="true" />
57 : {{ $t('deployToComfyApi.copied') }}
58 : </template>
59 : <template v-else>
60 : <AgentMarks class="h-6 w-auto" />
61 : {{ $t('deployToComfyApi.deployWithAgent') }}
62 : </template>
63 : </Button>
64 : </template>
65 : </div>
66 : </template>
67 :
68 : <script setup lang="ts">
69 : import { cn } from '@comfyorg/tailwind-utils'
70 : import { useEventListener } from '@vueuse/core'
71 : import { storeToRefs } from 'pinia'
72 : import { computed } from 'vue'
73 :
74 : import type { MissingPackGroup } from '@/platform/workflowErrors/panel/useErrorGroups'
75 : import Button from '@comfyorg/design-system/button/Button'
76 : import { getComfyPlatformBaseUrl } from '@/config/comfyApi'
77 : import type { MissingModelGroup } from '@/platform/workflowErrors/missingModel/types'
78 : import AgentMarks from '@/platform/workflow/deploy/components/AgentMarks.vue'
79 : import { DEPLOYMENT_LISTING_FOCUS_RETRY_MS } from '@/platform/workspace/api/deploymentListingTimeouts'
80 : import type { WorkspaceDeployment } from '@/platform/workspace/api/workspaceApi'
81 : import { useBriefCopy } from '@/platform/workspace/composables/useBriefCopy'
82 : import { useDeploymentLabels } from '@/platform/workspace/composables/useDeploymentLabels'
83 : import { useDeploymentSwitchGuard } from '@/platform/workspace/composables/useDeploymentSwitchGuard'
84 : import type { MissingBuildPack } from '@/platform/workspace/deploymentBuildBrief'
85 : import { deploymentBuildBrief } from '@/platform/workspace/deploymentBuildBrief'
86 : import { missingNodeTypeName } from '@/platform/workspace/missingForDeployment'
87 : import { useDeploymentPickStore } from '@/platform/workspace/stores/deploymentPickStore'
88 :
89 : const { deployment, missingPackGroups, missingModelGroups } = defineProps<{
90 : deployment: WorkspaceDeployment
91 : missingPackGroups: readonly MissingPackGroup[]
92 : missingModelGroups: readonly MissingModelGroup[]
93 : }>()
94 :
95 0 : const deploymentPick = useDeploymentPickStore()
96 0 : const { isSwitching } = storeToRefs(deploymentPick)
97 0 : const { changeSinceBootMessage } = useDeploymentLabels()
98 0 : const { reloadOntoCurrent } = useDeploymentSwitchGuard()
99 0 : const { isCopying, copied, copy } = useBriefCopy()
100 :
101 0 : let lastListingRefreshAt = -Infinity
102 0 : useEventListener(window, 'focus', () => {
103 0 : if (Date.now() - lastListingRefreshAt < DEPLOYMENT_LISTING_FOCUS_RETRY_MS)
104 0 : return
105 0 : lastListingRefreshAt = Date.now()
106 0 : void deploymentPick.load()
107 : })
108 :
109 0 : const buildsUrl = `${getComfyPlatformBaseUrl()}/profile/builds`
110 0 : const buildUrl = computed(() =>
111 : deployment.build_id
112 : ? `${buildsUrl}/${encodeURIComponent(deployment.build_id)}`
113 : : buildsUrl
114 : )
115 :
116 0 : function buildPack(group: MissingPackGroup): MissingBuildPack {
117 0 : const pack = {
118 : packId: group.packId,
119 : nodeTypes: group.nodeTypes.map(missingNodeTypeName)
120 : }
121 0 : const unsupported =
122 : group.packId !== null
123 : ? deploymentPick.unsupportedPackFor(group.packId)
124 : : undefined
125 0 : return unsupported
126 : ? { ...pack, loadFailure: { cause: unsupported.cause } }
127 : : pack
128 : }
129 :
130 0 : function brief(): string {
131 0 : return deploymentBuildBrief(
132 : deployment,
133 : missingPackGroups.map(buildPack),
134 : missingModelGroups.flatMap((group) =>
135 : group.models.map((model) => ({
136 : name: model.name,
137 : directory: model.representative.directory || group.directory,
138 : url: model.representative.url
139 : }))
140 : )
141 : )
142 : }
143 : </script>
|