import {z} from 'zod' export type DeleteApiV2SkillsArgs = {skill_id: string, path?: string | undefined}; export type DeleteApiV2SkillsOptions = {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 deleteSkillFileResponse = 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 }; /** * Delete a skill file * * DELETE /v2/skills/** */ export const deleteApiV2Skills = async (args: DeleteApiV2SkillsArgs, options?: DeleteApiV2SkillsOptions) => { const {baseUrl = "https://my.orq.ai", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.path != null) query.append("path", String(args.path)) if (ApiKey !== undefined) headers.set('authorization', `Bearer ${ApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/skills/**${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "DELETE", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(deleteSkillFileResponse, await res.json()) };