import {z} from 'zod' export type GetApiV1AvatarsAvatarIdArgs = {avatar_id: string}; export type GetApiV1AvatarsAvatarIdOptions = {baseUrl?: string | undefined, ApiKeyBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const avatar = z.object({id: z.string().optional(), object: z.string().optional(), name: z.string().optional(), kind: z.enum(["prompt", "photo"]).optional(), status: z.string().optional(), ready: z.boolean().optional(), gender: z.string().optional(), preview_image_url: z.string().optional(), preview_video_url: z.string().optional(), looks: z.array(z.record(z.string(), z.unknown())).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 }; /** * Avatar training status * * GET /v1/avatars/{avatar_id} */ export const getApiV1AvatarsAvatarId = async (args: GetApiV1AvatarsAvatarIdArgs, options?: GetApiV1AvatarsAvatarIdOptions) => { const {baseUrl = "https://api.vivideo.ai", fetch: fetchFn = fetch, ApiKeyBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (ApiKeyBearer !== undefined) headers.set('authorization', `Bearer ${ApiKeyBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/avatars/${encodeURIComponent(String(args.avatar_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(avatar, await res.json()) };