import {z} from 'zod' export type GetApiApiV1betaPluginsNameArgs = {name: string, scope?: ('user' | 'project') | undefined, project_root?: string | undefined}; export type GetApiApiV1betaPluginsNameOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const githubComStacklokToolhivePkgPluginsComponentInventory = z.record(z.string(), z.number().int()); export const githubComStacklokToolhivePkgPluginsDependency = z.object({digest: z.string().optional(), name: z.string().optional(), reference: z.string().optional()}); export const githubComStacklokToolhivePkgPluginsPluginMetadata = z.object({author: z.string().optional(), description: z.string().optional(), keywords: z.array(z.string()).optional(), license: z.string().optional(), name: z.string().optional(), version: z.string().optional()}); export const githubComStacklokToolhivePkgPluginsScope = z.enum(["user", "project"]); export const githubComStacklokToolhivePkgPluginsInstallStatus = z.enum(["installed", "pending", "failed"]); export const githubComStacklokToolhivePkgPluginsInstalledPlugin = z.object({clients: z.array(z.string()).optional(), components: githubComStacklokToolhivePkgPluginsComponentInventory.optional(), dependencies: z.array(githubComStacklokToolhivePkgPluginsDependency).optional(), digest: z.string().optional(), installed_at: z.string().optional(), managed: z.boolean().optional(), metadata: githubComStacklokToolhivePkgPluginsPluginMetadata.optional(), project_root: z.string().optional(), reference: z.string().optional(), scope: githubComStacklokToolhivePkgPluginsScope.optional(), signature: z.string().optional(), status: githubComStacklokToolhivePkgPluginsInstallStatus.optional(), tag: z.string().optional()}); export const githubComStacklokToolhivePkgPluginsProvenanceInfo = z.object({cert_issuer: z.string().optional(), provisional: z.boolean().optional(), public_key: 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 githubComStacklokToolhivePkgPluginsComponentType = z.enum(["commands", "agents", "skills", "hooks", "mcpServers", "lspServers"]); export const githubComStacklokToolhivePkgPluginsPluginInfo = z.object({installed_plugin: githubComStacklokToolhivePkgPluginsInstalledPlugin.optional(), metadata: githubComStacklokToolhivePkgPluginsPluginMetadata.optional(), project_scope_degraded_clients: z.array(z.string()).optional(), provenance: githubComStacklokToolhivePkgPluginsProvenanceInfo.optional(), trust_unrecorded: z.boolean().optional(), unmaterialized_components: z.record(z.string(), z.array(githubComStacklokToolhivePkgPluginsComponentType)).optional(), unsigned: z.boolean().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 plugin details * * GET /api/v1beta/plugins/{name} */ export const getApiApiV1betaPluginsName = async (args: GetApiApiV1betaPluginsNameArgs, options: GetApiApiV1betaPluginsNameOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.scope != null) query.append("scope", String(args.scope)) if (args.project_root != null) query.append("project_root", String(args.project_root)) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1beta/plugins/${encodeURIComponent(String(args.name))}${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(githubComStacklokToolhivePkgPluginsPluginInfo, await res.json()) };