[feat] Implement getNodeByComfyNodeName API integration (#4343)

This commit is contained in:
Christian Byrne
2025-07-03 17:59:21 -07:00
committed by GitHub
parent 1b4ad61e7f
commit 44bbfa9f39
4 changed files with 137 additions and 10 deletions

View File

@@ -26,7 +26,7 @@ const CORE_NODES_PACK_NAME = 'comfy-core'
export const useWorkflowPacks = (options: UseNodePacksOptions = {}) => {
const nodeDefStore = useNodeDefStore()
const systemStatsStore = useSystemStatsStore()
const { search } = useComfyRegistryStore()
const { inferPackFromNodeName } = useComfyRegistryStore()
const workflowPacks = ref<WorkflowPack[]>([])
@@ -70,18 +70,19 @@ export const useWorkflowPacks = (options: UseNodePacksOptions = {}) => {
}
}
// Search the registry for non-core nodes
const searchResult = await search.call({
comfy_node_search: nodeName,
limit: 1
})
if (searchResult?.nodes?.length) {
const pack = searchResult.nodes[0]
// Query the registry to find which pack provides this node
const pack = await inferPackFromNodeName.call(nodeName)
if (pack) {
return {
id: pack.id,
version: pack.latest_version?.version ?? SelectedVersion.NIGHTLY
}
}
// No pack found - this node doesn't exist in the registry or couldn't be
// extracted from the parent node pack successfully
return undefined
}
/**

View File

@@ -318,6 +318,47 @@ export const useComfyRegistryService = () => {
)
}
/**
* Get the node pack that contains a specific ComfyUI node by its name.
* This method queries the registry to find which pack provides the given node.
*
* When multiple packs contain a node with the same name, the API returns the best match based on:
* 1. Preemption match - If the node name matches any in the pack's preempted_comfy_node_names array
* 2. Search ranking - Lower search_ranking values are preferred
* 3. Total installs - Higher installation counts are preferred as a tiebreaker
*
* @param nodeName - The name of the ComfyUI node (e.g., 'KSampler', 'CLIPTextEncode')
* @param signal - Optional AbortSignal for request cancellation
* @returns The node pack containing the specified node, or null if not found or on error
*
* @example
* ```typescript
* const pack = await inferPackFromNodeName('KSampler')
* if (pack) {
* console.log(`Node found in pack: ${pack.name}`)
* }
* ```
*/
const inferPackFromNodeName = async (
nodeName: operations['getNodeByComfyNodeName']['parameters']['path']['comfyNodeName'],
signal?: AbortSignal
) => {
const endpoint = `/comfy-nodes/${nodeName}/node`
const errorContext = 'Failed to infer pack from comfy node name'
const routeSpecificErrors = {
404: `Comfy node not found: The node with name ${nodeName} does not exist in the registry`
}
return executeApiRequest(
() =>
registryApiClient.get<components['schemas']['Node']>(endpoint, {
signal
}),
errorContext,
routeSpecificErrors
)
}
return {
isLoading,
error,
@@ -330,6 +371,7 @@ export const useComfyRegistryService = () => {
getPublisherById,
listPacksForPublisher,
getNodeDefs,
postPackReview
postPackReview,
inferPackFromNodeName
}
}

View File

@@ -104,6 +104,17 @@ export const useComfyRegistryStore = defineStore('comfyRegistry', () => {
ListPacksResult
>(registryService.search, { maxSize: PACK_LIST_CACHE_SIZE })
/**
* Get the node pack that contains a specific ComfyUI node by its name.
* Results are cached to avoid redundant API calls.
*
* @see {@link useComfyRegistryService.inferPackFromNodeName} for details on the ranking algorithm
*/
const inferPackFromNodeName = useCachedRequest<
operations['getNodeByComfyNodeName']['parameters']['path']['comfyNodeName'],
NodePack
>(registryService.inferPackFromNodeName, { maxSize: PACK_BY_ID_CACHE_SIZE })
/**
* Clear all cached data
*/
@@ -111,6 +122,7 @@ export const useComfyRegistryStore = defineStore('comfyRegistry', () => {
getNodeDefs.clear()
listAllPacks.clear()
getPackById.clear()
inferPackFromNodeName.clear()
}
/**
@@ -120,6 +132,7 @@ export const useComfyRegistryStore = defineStore('comfyRegistry', () => {
getNodeDefs.cancel()
listAllPacks.cancel()
getPackById.cancel()
inferPackFromNodeName.cancel()
getPacksByIdController?.abort()
}
@@ -132,6 +145,7 @@ export const useComfyRegistryStore = defineStore('comfyRegistry', () => {
},
getNodeDefs,
search,
inferPackFromNodeName,
clearCache,
cancelRequests,