import {z} from 'zod' export type GetApiRegistryRegistryNameV01XDevToolhivePluginsNamespacePluginNameArgs = {registryName: string, namespace: string, pluginName: string}; export type GetApiRegistryRegistryNameV01XDevToolhivePluginsNamespacePluginNameOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const registrySkillIcon = z.object({label: z.string().optional(), size: z.string().optional(), src: z.string().optional(), type: z.string().optional()}); export const registrySkillPackage = z.object({commit: z.string().optional(), digest: z.string().optional(), identifier: z.string().optional(), mediaType: z.string().optional(), ref: z.string().optional(), registryType: z.string().optional(), subfolder: z.string().optional(), url: z.string().optional()}); export const registryVerifiedAttestation = z.object({predicate: z.unknown(), predicate_type: z.string().optional()}); export const registryProvenance = z.object({attestation: registryVerifiedAttestation.optional(), cert_issuer: z.string().optional(), repository_ref: z.string().optional(), repository_uri: z.string().optional(), runner_environment: z.string().optional(), signer_identity: z.string().optional(), sigstore_url: z.string().optional()}); export const registrySkillRepository = z.object({type: z.string().optional(), url: z.string().optional()}); export const registryPlugin = z.object({_meta: z.record(z.string(), z.unknown()).optional(), description: z.string().optional(), icons: z.array(registrySkillIcon).optional(), license: z.string().optional(), metadata: z.record(z.string(), z.unknown()).optional(), name: z.string().optional(), namespace: z.string().optional(), packages: z.array(registrySkillPackage).optional(), provenance: registryProvenance.optional(), repository: registrySkillRepository.optional(), status: z.string().optional(), title: z.string().optional(), version: z.string().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 }; /** * Get a registry plugin * * GET /registry/{registryName}/v0.1/x/dev.toolhive/plugins/{namespace}/{pluginName} */ export const getApiRegistryRegistryNameV01XDevToolhivePluginsNamespacePluginName = async (args: GetApiRegistryRegistryNameV01XDevToolhivePluginsNamespacePluginNameArgs, options: GetApiRegistryRegistryNameV01XDevToolhivePluginsNamespacePluginNameOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/registry/${encodeURIComponent(String(args.registryName))}/v0.1/x/dev.toolhive/plugins/${encodeURIComponent(String(args.namespace))}/${encodeURIComponent(String(args.pluginName))}${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(registryPlugin, await res.json()) };