import {z} from 'zod' export type ImportSkillBundleRequest = {project_id?: string | undefined, path?: string | undefined, bundle: unknown}; export type CreateApiV2SkillsImportArgs = {body: ImportSkillBundleRequest}; export type CreateApiV2SkillsImportOptions = {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 importSkillBundleResponse = z.object({skill: skill}); 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 bundle * * POST /v2/skills/import */ export const createApiV2SkillsImport = async (args: CreateApiV2SkillsImportArgs, options?: CreateApiV2SkillsImportOptions) => { 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${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(importSkillBundleResponse, await res.json()) };