import {z} from 'zod' export type ModelVideosRemixRequest = {input_reference?: string | undefined, model?: string | undefined, prompt?: string | undefined, seconds: unknown, size?: string | undefined}; export type CreateApiV1VideosVideoIdRemixArgs = {video_id: string, 'Aiproxy-Channel'?: string | undefined, 'X-Aiproxy-Group'?: string | undefined, 'X-Aiproxy-Group-Channel-Mode'?: ('global' | 'own') | undefined, body: ModelVideosRemixRequest}; export type CreateApiV1VideosVideoIdRemixOptions = {baseUrl: string, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const modelVideoStatus = z.enum(["queued", "in_progress", "completed", "succeeded", "failed", "cancelled"]); export const modelVideo = z.object({created_at: z.number().int().optional(), error: z.record(z.string(), z.unknown()).optional(), id: z.string().optional(), model: z.string().optional(), object: z.string().optional(), progress: z.number().int().optional(), prompt: z.string().optional(), seconds: z.number().int().optional(), size: z.string().optional(), status: modelVideoStatus.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 }; /** * Remix video * * POST /v1/videos/{video_id}/remix */ export const createApiV1VideosVideoIdRemix = async (args: CreateApiV1VideosVideoIdRemixArgs, options: CreateApiV1VideosVideoIdRemixOptions) => { const {baseUrl, 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 (args['Aiproxy-Channel'] != null) headers.set("Aiproxy-Channel", String(args['Aiproxy-Channel'])) if (args['X-Aiproxy-Group'] != null) headers.set("X-Aiproxy-Group", String(args['X-Aiproxy-Group'])) if (args['X-Aiproxy-Group-Channel-Mode'] != null) headers.set("X-Aiproxy-Group-Channel-Mode", String(args['X-Aiproxy-Group-Channel-Mode'])) if (ApiKeyAuth !== undefined) headers.set("Authorization", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v1/videos/${encodeURIComponent(String(args.video_id))}/remix${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(modelVideo, await res.json()) };