import {z} from 'zod' export type VoiceUpdateRequest = {name?: (string | null) | undefined, languages?: (Array | null) | undefined, gender?: (string | null) | undefined, age?: (number | null) | undefined, tags?: (Array | null) | undefined, description?: (string | null) | undefined, retention_notice?: (number | null) | undefined}; export type PatchApiV1AudioVoicesVoiceIdArgs = {voice_id: string, body: VoiceUpdateRequest}; export type PatchApiV1AudioVoicesVoiceIdOptions = {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 }; /** * Update voice metadata * * PATCH /v1/audio/voices/{voice_id} */ export const patchApiV1AudioVoicesVoiceId = async (args: PatchApiV1AudioVoicesVoiceIdArgs, options?: PatchApiV1AudioVoicesVoiceIdOptions) => { const {baseUrl = "https://api.mistral.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(/\/+$/, '')}/v1/audio/voices/${encodeURIComponent(String(args.voice_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(voiceResponse, await res.json()) };