import {z} from 'zod' export type ImportSkillFromRepositoryRequest = {connection_id?: string | undefined, repository_url?: string | undefined, ref?: string | undefined, subdirectory?: string | undefined, project_id?: string | undefined, path?: string | undefined}; export type CreateApiV2SkillsImportRepositoryArgs = {body: ImportSkillFromRepositoryRequest}; export type CreateApiV2SkillsImportRepositoryOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const skillFile = z.object({path: z.string(), size_bytes: z.string(), sha256: z.string(), content_type: z.string()}); export const skillRepositorySource = z.object({connection_id: z.string().optional(), repository_url: z.string().optional(), ref: z.string().optional(), subdirectory: z.string().optional(), commit_sha: z.string().optional()}); export const skill = z.object({skill_id: z.string(), display_name: z.string(), description: z.string(), tags: z.array(z.string()), project_id: z.string(), path: z.string(), created_at: z.string(), updated_at: z.string(), created_by_id: z.string(), updated_by_id: z.string(), instructions: z.string(), version: z.string(), files: z.array(skillFile).optional(), has_files: z.boolean().optional(), repository_source: skillRepositorySource.optional()}); export const importSkillFromRepositoryResponse = z.object({skill: skill.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 }; /** * Import a skill from a repository * * POST /v2/skills/import/repository */ export const createApiV2SkillsImportRepository = async (args: CreateApiV2SkillsImportRepositoryArgs, options?: CreateApiV2SkillsImportRepositoryOptions) => { const {baseUrl = "https://my.orq.ai", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKey !== undefined) headers.set('authorization', `Bearer ${ApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/skills/import/repository${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(importSkillFromRepositoryResponse, await res.json()) };