import {z} from 'zod' export type GetApiV1AvatarVideosIdArgs = {id: string}; export type GetApiV1AvatarVideosIdOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const avatarVideo = z.object({id: z.string(), status: z.enum(["pending", "running", "finalizing", "completed", "failed", "cancelled"]), completionReason: z.enum(["script_completed", "max_duration_reached", "cancelled", "null"]).nullable().optional(), truncated: z.boolean(), durationSeconds: z.number().nullable().optional(), effectiveMaxDurationSeconds: z.number().int(), sessionId: z.string().nullable().optional(), region: z.enum(["eu", "us", "null"]).nullable(), zeroDataRetention: z.boolean(), content: z.object({available: z.boolean(), deleteAt: z.string().nullable(), url: z.string().optional(), expiresAt: z.string().optional()}), failure: z.object({code: z.string().optional(), message: z.string().optional(), retryable: z.boolean().optional()}).nullable().optional(), retryOf: z.string().nullable().optional(), createdAt: z.string(), startedAt: z.string().nullable().optional(), completedAt: z.string().nullable().optional(), metadata: z.record(z.string(), z.unknown())}); 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 }; /** * Get an avatar video * * GET /v1/avatar-videos/{id} */ export const getApiV1AvatarVideosId = async (args: GetApiV1AvatarVideosIdArgs, options?: GetApiV1AvatarVideosIdOptions) => { const {baseUrl = "https://api.anam.ai", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/avatar-videos/${encodeURIComponent(String(args.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(avatarVideo, await res.json()) };