import {z} from 'zod' export type DeleteVoiceReq = {voice_id: string, voice_type?: ('system_voice' | 'voice_cloning' | 'voice_generation' | 'music_generation' | 'voice_slots') | undefined}; export type CreateApiV1DeleteVoiceArgs = {body: DeleteVoiceReq}; export type CreateApiV1DeleteVoiceOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const deleteVoiceResp = z.object({voice_id: z.string().optional(), description: z.array(z.string()).optional(), created_time: z.string().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 }; /** * Delete Voice * * POST /v1/delete_voice */ export const createApiV1DeleteVoice = async (args: CreateApiV1DeleteVoiceArgs, options?: CreateApiV1DeleteVoiceOptions) => { const {baseUrl = "https://api.minimax.io", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/delete_voice${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(deleteVoiceResp, await res.json()) };