Line data Source code
1 : import { isCloud } from '@/platform/distribution/types'
2 : import type { ReleaseModelOptions } from '@/platform/workflowErrors/missingModel/missingModelScan'
3 : import { DEPLOYMENT_LISTING_BACKSTOP_MS } from '@/platform/workspace/api/deploymentListingTimeouts'
4 : import { couldBootOnDeployment } from '@/platform/workspace/composables/waitForDeploymentPick'
5 : import { useDeploymentPickStore } from '@/platform/workspace/stores/deploymentPickStore'
6 : import { isComboInputSpec } from '@comfyorg/object-info-parser/schemas/nodeDefSchemaV2'
7 : import { useNodeDefStore } from '@/stores/nodeDefStore'
8 :
9 : /**
10 : * A loader input's model options in the node catalog this page booted with,
11 : * when it booted on a developer-platform deployment (FE-2434): ingest served
12 : * that catalog from the deployment's Release. Waits for the boot listing
13 : * that says where the page runs, at most `DEPLOYMENT_LISTING_BACKSTOP_MS`
14 : * (its sign-in step can hang before the request timeout starts), or until
15 : * `signal` aborts; undefined on Comfy Cloud, when the listing failed or did
16 : * not answer in time, and when the check was aborted.
17 : */
18 : export const releaseModelOptions: ReleaseModelOptions = async (
19 : nodeType,
20 : widgetName,
21 : signal
22 : ) => {
23 : const deploymentPick = useDeploymentPickStore()
24 : if (deploymentPick.bootDeployment === undefined) {
25 : await settledWithin(
26 : deploymentPick.loadOnce(),
27 : DEPLOYMENT_LISTING_BACKSTOP_MS,
28 : signal
29 : )
30 : }
31 : if (signal?.aborted || !deploymentPick.bootDeployment) return undefined
32 : const input = useNodeDefStore().getNodeDefByName(nodeType)?.inputs[widgetName]
33 : return input && isComboInputSpec(input) ? input.options : undefined
34 : }
35 :
36 : /**
37 : * `releaseModelOptions` on Comfy Cloud unless this page is known to boot on
38 : * Comfy Cloud's own models (`couldBootOnDeployment`), undefined elsewhere
39 : * so a scan never waits on the listing.
40 : */
41 606 : export function cloudReleaseModelOptions(): ReleaseModelOptions | undefined {
42 : return isCloud && couldBootOnDeployment() ? releaseModelOptions : undefined
43 : }
44 :
45 : /**
46 : * Resolves once `work` settles, `ceilingMs` passes or `signal` aborts; never
47 : * rejects.
48 : */
49 : function settledWithin(
50 : work: Promise<void>,
51 : ceilingMs: number,
52 : signal?: AbortSignal
53 : ): Promise<void> {
54 : if (signal?.aborted) return Promise.resolve()
55 : return new Promise((resolve) => {
56 : const ceiling = setTimeout(done, ceilingMs)
57 : signal?.addEventListener('abort', done, { once: true })
58 : work.then(done, done)
59 :
60 : function done() {
61 : clearTimeout(ceiling)
62 : signal?.removeEventListener('abort', done)
63 : resolve()
64 : }
65 : })
66 : }
|