import {z} from 'zod' export type FreepikMagnificRelightRequest = {advanced_settings?: ({blacks?: number | undefined, brightness?: number | undefined, contrast?: number | undefined, engine?: ('automatic' | 'balanced' | 'cool' | 'real' | 'illusio' | 'fairy' | 'colorful_anime' | 'hard_transform' | 'softy') | undefined, fixed_generation?: boolean | undefined, saturation?: number | undefined, transfer_light_a?: ('automatic' | 'low' | 'medium' | 'normal' | 'high' | 'high_on_faces') | undefined, transfer_light_b?: ('automatic' | 'composition' | 'straight' | 'smooth_in' | 'smooth_out' | 'smooth_both' | 'reverse_both' | 'soft_in' | 'soft_out' | 'soft_mid' | 'strong_mid' | 'style_shift' | 'strong_shift') | undefined, whites?: number | undefined}) | undefined, change_background?: boolean | undefined, image: string, interpolate_from_original?: boolean | undefined, light_transfer_strength?: number | undefined, preserve_details?: boolean | undefined, prompt?: string | undefined, style?: ('standard' | 'darker_but_realistic' | 'clean' | 'smooth' | 'brighter' | 'contrasted_n_hdr' | 'just_composition') | undefined, transfer_light_from_lightmap?: string | undefined, transfer_light_from_reference_image?: string | undefined, webhook_url?: string | undefined}; export type CreateApiProxyFreepikV1AiImageRelightArgs = {body: FreepikMagnificRelightRequest}; export type CreateApiProxyFreepikV1AiImageRelightOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const freepikTaskData = z.object({generated: z.array(z.string()).optional(), status: z.enum(["CREATED", "IN_PROGRESS", "COMPLETED", "FAILED"]).optional(), task_id: z.string().optional()}); export const freepikTaskResponse = z.object({data: freepikTaskData}); 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 }; /** * Relight an image * * POST /proxy/freepik/v1/ai/image-relight */ export const createApiProxyFreepikV1AiImageRelight = async (args: CreateApiProxyFreepikV1AiImageRelightArgs, options?: CreateApiProxyFreepikV1AiImageRelightOptions) => { const {baseUrl = "https://api.comfy.org", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/proxy/freepik/v1/ai/image-relight${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(freepikTaskResponse, await res.json()) };