import {z} from 'zod' export type VideoEditRequest = {model: string, input: {prompt: string, media: Array<{type: 'video', url: string} | {type: 'reference_image', url: string}>}, parameters?: ({resolution?: ('720P' | '1080P') | undefined, watermark?: boolean | undefined, audio_setting?: ('auto' | 'origin') | undefined, seed?: number | undefined}) | undefined}; export type CreateApiHappyhorseApiV1ServicesAigcVideoGenerationVideoSynthesisArgs = {body: VideoEditRequest}; export type CreateApiHappyhorseApiV1ServicesAigcVideoGenerationVideoSynthesisOptions = {baseUrl?: string | undefined, CustomApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiHappyhorseApiV1ServicesAigcVideoGenerationVideoSynthesisResponse = z.object({output: z.object({task_status: z.enum(["PENDING", "RUNNING", "SUCCEEDED", "FAILED", "CANCELED", "UNKNOWN"]).optional(), task_id: z.string().optional()}), request_id: z.string()}); 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 }; /** * Video Editing - Edit video based on videos and reference images * * POST /happyhorse/api/v1/services/aigc/video-generation/video-synthesis */ export const createApiHappyhorseApiV1ServicesAigcVideoGenerationVideoSynthesis = async (args: CreateApiHappyhorseApiV1ServicesAigcVideoGenerationVideoSynthesisArgs, options?: CreateApiHappyhorseApiV1ServicesAigcVideoGenerationVideoSynthesisOptions) => { const {baseUrl = "https://api.ttapi.io", fetch: fetchFn = fetch, CustomApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (CustomApiKey !== undefined) headers.set("TT-API-KEY", CustomApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/happyhorse/api/v1/services/aigc/video-generation/video-synthesis${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(createApiHappyhorseApiV1ServicesAigcVideoGenerationVideoSynthesisResponse, await res.json()) };