import {z} from 'zod' export type DeleteApiV1AudioVoicesVoiceIdArgs = {voice_id: string}; export type DeleteApiV1AudioVoicesVoiceIdOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const voiceKind = z.enum(["ivc", "pvc"]); export const voiceResponse = z.object({name: z.string(), slug: z.string().nullable().optional(), languages: z.array(z.string()).optional(), gender: z.string().nullable().optional(), age: z.number().int().nullable().optional(), tags: z.array(z.string()).nullable().optional(), color: z.string().nullable().optional(), description: z.string().max(500).nullable().optional(), retention_notice: z.number().int().optional(), id: z.string(), created_at: z.string(), user_id: z.string().nullable(), trimmed_seconds: z.number().nullable().optional(), kind: voiceKind.optional(), type: z.enum(["preset", "custom"])}); 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 custom voice * * DELETE /v1/audio/voices/{voice_id} */ export const deleteApiV1AudioVoicesVoiceId = async (args: DeleteApiV1AudioVoicesVoiceIdArgs, options?: DeleteApiV1AudioVoicesVoiceIdOptions) => { const {baseUrl = "https://api.mistral.ai", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (ApiKey !== undefined) headers.set('authorization', `Bearer ${ApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/audio/voices/${encodeURIComponent(String(args.voice_id))}${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(voiceResponse, await res.json()) };