import {z} from 'zod' export type GetApiNodesSearchArgs = {page?: number | undefined, limit?: number | undefined, search?: string | undefined, repository_url_search?: string | undefined, comfy_node_search?: string | undefined, supported_os?: string | undefined, supported_accelerator?: string | undefined, include_banned?: boolean | undefined}; export type GetApiNodesSearchOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const nodeVersionStatus = z.enum(["NodeVersionStatusActive", "NodeVersionStatusDeleted", "NodeVersionStatusBanned", "NodeVersionStatusPending", "NodeVersionStatusFlagged"]); export const nodeVersion = z.object({changelog: z.string().optional(), comfy_node_extract_status: z.string().optional(), createdAt: z.string().optional(), dependencies: z.array(z.string()).optional(), deprecated: z.boolean().optional(), downloadUrl: z.string().optional(), id: z.string().optional(), node_id: z.string().optional(), status: nodeVersionStatus.optional(), status_reason: z.string().optional(), supported_accelerators: z.array(z.string()).optional(), supported_comfyui_frontend_version: z.string().optional(), supported_comfyui_version: z.string().optional(), supported_os: z.array(z.string()).optional(), tags: z.array(z.string()).optional(), tags_admin: z.array(z.string()).optional(), version: z.string().optional()}); export const publisherUser = z.object({email: z.string().optional(), id: z.string().optional(), name: z.string().optional()}); export const publisherMember = z.object({id: z.string().optional(), role: z.string().optional(), user: publisherUser.optional()}); export const publisherStatus = z.enum(["PublisherStatusActive", "PublisherStatusBanned"]); export const publisher = z.object({createdAt: z.string().optional(), description: z.string().optional(), id: z.string().optional(), logo: z.string().optional(), members: z.array(publisherMember).optional(), name: z.string().optional(), source_code_repo: z.string().optional(), status: publisherStatus.optional(), support: z.string().optional(), website: z.string().optional()}); export const nodeStatus = z.enum(["NodeStatusActive", "NodeStatusDeleted", "NodeStatusBanned"]); export const node = z.object({author: z.string().optional(), banner_url: z.string().optional(), category: z.string().optional(), created_at: z.string().optional(), description: z.string().optional(), downloads: z.number().int().optional(), github_stars: z.number().int().optional(), icon: z.string().optional(), id: z.string().optional(), latest_version: nodeVersion.optional(), license: z.string().optional(), name: z.string().optional(), preempted_comfy_node_names: z.array(z.string()).optional(), publisher: publisher.optional(), rating: z.number().optional(), repository: z.string().optional(), search_ranking: z.number().int().optional(), status: nodeStatus.optional(), status_detail: z.string().optional(), supported_accelerators: z.array(z.string()).optional(), supported_comfyui_frontend_version: z.string().optional(), supported_comfyui_version: z.string().optional(), supported_os: z.array(z.string()).optional(), tags: z.array(z.string()).optional(), tags_admin: z.array(z.string()).optional(), translations: z.record(z.string(), z.record(z.string(), z.unknown())).optional()}); export const getApiNodesSearchResponse = z.object({limit: z.number().int().optional(), nodes: z.array(node).optional(), page: z.number().int().optional(), total: z.number().int().optional(), totalPages: z.number().int().optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Retrieves a list of nodes * * GET /nodes/search */ export const getApiNodesSearch = async (args: GetApiNodesSearchArgs, options?: GetApiNodesSearchOptions) => { const {baseUrl = "https://api.comfy.org", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page != null) query.append("page", String(args.page)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.search != null) query.append("search", String(args.search)) if (args.repository_url_search != null) query.append("repository_url_search", String(args.repository_url_search)) if (args.comfy_node_search != null) query.append("comfy_node_search", String(args.comfy_node_search)) if (args.supported_os != null) query.append("supported_os", String(args.supported_os)) if (args.supported_accelerator != null) query.append("supported_accelerator", String(args.supported_accelerator)) if (args.include_banned != null) query.append("include_banned", String(args.include_banned)) const url = `${baseUrl.replace(/\/+$/, '')}/nodes/search${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiNodesSearchResponse, await res.json()) };