import {z} from 'zod' export type GetApiApiPublicV2SkillCollectionsIdentifierArgs = {identifier: string, format?: 'zip' | undefined, label?: string | undefined, version?: number | undefined}; export type GetApiApiPublicV2SkillCollectionsIdentifierOptions = {baseUrl: string, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const externalId = z.object({source: z.string().min(1).max(128), external_id: z.string().min(1).max(512)}); export const skillCollection = z.object({id: z.string().optional(), workspace_id: z.number().int().optional(), folder_id: z.number().int().nullable().optional(), root_path: z.string().optional(), name: z.string().optional(), provider: z.string().nullable().optional(), is_deleted: z.boolean().optional(), created_by: z.number().int().nullable().optional(), created_at: z.string().optional(), updated_by: z.number().int().nullable().optional(), updated_at: z.string().optional(), external_ids: z.array(externalId).optional()}); export const skillCollectionVersion = z.object({id: z.string().optional(), skill_collection_id: z.string().optional(), workspace_id: z.number().int().optional(), number: z.number().int().optional(), root_path_at_version: z.string().optional(), provider: z.string().nullable().optional(), file_paths: z.array(z.string()).optional(), commit_message: z.string().nullable().optional(), release_label: z.string().nullable().optional(), archived: z.boolean().optional(), created_by: z.number().int().nullable().optional(), user_email: z.string().nullable().optional(), created_at: z.string().optional()}); export const getSkillCollectionResponse = z.object({success: z.literal(true), skill_collection: skillCollection, files: z.record(z.string(), z.string()), version: skillCollectionVersion.nullable()}); 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 Skill Collection * * GET /api/public/v2/skill-collections/{identifier} */ export const getApiApiPublicV2SkillCollectionsIdentifier = async (args: GetApiApiPublicV2SkillCollectionsIdentifierArgs, options: GetApiApiPublicV2SkillCollectionsIdentifierOptions) => { const {baseUrl, fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.format != null) query.append("format", String(args.format)) if (args.label != null) query.append("label", String(args.label)) if (args.version != null) query.append("version", String(args.version)) if (ApiKeyAuth !== undefined) headers.set("X-API-KEY", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/api/public/v2/skill-collections/${encodeURIComponent(String(args.identifier))}${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(getSkillCollectionResponse, await res.json()) };