import {z} from 'zod' export type CreateApiGenerationWanxHappyhorse10Ref2videoArgs = {body: {input: {prompt: string, duration?: number | undefined, aspectRatio?: ('1:1' | '4:3' | '3:4' | '16:9' | '9:16') | undefined, resolution?: ('720P' | '1080P') | undefined, seed?: number | undefined, videoNum?: number | undefined, refs?: (Array<{type: 'image', name: string, image: string, order: number, avatarId?: string | undefined} | {type: 'subject', name: string, images: Array<{url: string, order: number}>, subjectId: string} | {type: 'video', name: string, video: string, order: number} | {type: 'audio', name: string, audio: string, order: number}>) | undefined, imageMeta?: (Array<{name?: string | undefined, url: string, order: number, cropper?: {url: string, detail: {x: number, y: number, width: number, height: number, rotate: number, scaleX: number, scaleY: number}, height: number, width: number} | undefined}>) | undefined}, webhookUrl?: string | undefined, clientSource?: string | undefined}}; export type CreateApiGenerationWanxHappyhorse10Ref2videoOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiGenerationWanxHappyhorse10Ref2videoResponse = z.object({taskId: z.string(), status: z.enum(["waiting", "succeed", "failed", "processing"])}); 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 }; /** * create reference video * * POST /generation/wanx/happyhorse-1.0/ref2video */ export const createApiGenerationWanxHappyhorse10Ref2video = async (args: CreateApiGenerationWanxHappyhorse10Ref2videoArgs, options?: CreateApiGenerationWanxHappyhorse10Ref2videoOptions) => { const {baseUrl = "https://pollo.ai/api/platform", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("x-api-key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/generation/wanx/happyhorse-1.0/ref2video${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(createApiGenerationWanxHappyhorse10Ref2videoResponse, await res.json()) };