import {z} from 'zod' export type PILImage = {format?: string | undefined, format_description?: string | undefined}; export type SpritePose = {animation_prompt?: string | undefined, margin_ratio?: number | undefined, margin_ratio_mode?: string | undefined, name?: string | undefined, prompt?: string | undefined}; export type Sprite3DRender = {style_id?: string | undefined, style_version?: number | undefined, style_params?: Record | undefined, params?: Record | undefined, perspective?: string | undefined, direction?: string | undefined, animation_name?: string | undefined, fps?: number | undefined, keep_horizontal_travel?: boolean | undefined, keep_vertical_travel?: boolean | undefined, pixel_block?: number | undefined, generated_model?: Record | undefined}; export type GameImage = {tags?: Array | undefined, id?: string | undefined, image_id?: string | undefined, url?: string | undefined, type?: string | undefined, final_score?: number | undefined, nsfw_prob?: number | undefined, similarity?: number | undefined, width?: number | undefined, height?: number | undefined, game_id?: string | undefined, hosted_filename?: string | undefined, icon?: boolean | undefined, targetSize?: number | undefined, seed?: number | undefined, embedded?: boolean | undefined, analysed?: boolean | undefined, image?: string | undefined, image_type?: string | undefined, prompt?: string | undefined, motion_prompt?: string | undefined, request_id?: string | undefined, hints?: Array | undefined, selected_genres?: Array | undefined, selected_colors?: Array | undefined, selected_style?: string | undefined, selected_perspective?: string | undefined, is_safe?: boolean | undefined, platform?: string | undefined, loading?: boolean | undefined, original_hints?: Array | undefined, genres?: Array | undefined, edit_mask?: string | undefined, edit_mode?: string | undefined, camera_rotation?: number | undefined, camera_elevation?: number | undefined, edit_mask_pil_image?: PILImage | undefined, pil_image?: PILImage | undefined, nsfw?: number | undefined, pose?: SpritePose | undefined, render_3d?: Sprite3DRender | undefined, pixel_grid?: (Array | null) | undefined, pixel_size?: number | undefined, model?: string | undefined, normals?: string | undefined}; export type ImageNormalMapPayload = {image: GameImage}; export type CreateApiImagesNormalMapArgs = {body: ImageNormalMapPayload}; export type CreateApiImagesNormalMapOptions = {baseUrl: string, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const pILImage = z.object({format: z.string().optional(), format_description: z.string().optional()}); export const spritePose = z.object({animation_prompt: z.string().optional(), margin_ratio: z.number().optional(), margin_ratio_mode: z.string().optional(), name: z.string().optional(), prompt: z.string().optional()}); export const sprite3DRender = z.object({style_id: z.string().optional(), style_version: z.number().int().optional(), style_params: z.object({}).optional(), params: z.object({}).optional(), perspective: z.string().optional(), direction: z.string().optional(), animation_name: z.string().optional(), fps: z.number().optional(), keep_horizontal_travel: z.boolean().optional(), keep_vertical_travel: z.boolean().optional(), pixel_block: z.number().int().optional(), generated_model: z.object({}).optional()}); export const gameImage = z.object({tags: z.array(z.string()).optional(), id: z.string().optional(), image_id: z.string().optional(), url: z.string().optional(), type: z.string().optional(), final_score: z.number().optional(), nsfw_prob: z.number().optional(), similarity: z.number().optional(), width: z.number().int().optional(), height: z.number().int().optional(), game_id: z.string().optional(), hosted_filename: z.string().optional(), icon: z.boolean().optional(), targetSize: z.number().int().optional(), seed: z.number().int().optional(), embedded: z.boolean().optional(), analysed: z.boolean().optional(), image: z.string().optional(), image_type: z.string().optional(), prompt: z.string().optional(), motion_prompt: z.string().optional(), request_id: z.string().optional(), hints: z.array(z.string()).optional(), selected_genres: z.array(z.string()).optional(), selected_colors: z.array(z.string()).optional(), selected_style: z.string().optional(), selected_perspective: z.string().optional(), is_safe: z.boolean().optional(), platform: z.string().optional(), loading: z.boolean().optional(), original_hints: z.array(z.string()).optional(), genres: z.array(z.string()).optional(), edit_mask: z.string().optional(), edit_mode: z.string().optional(), camera_rotation: z.number().int().gte(-180).lte(180).optional(), camera_elevation: z.number().int().gte(-30).lte(60).optional(), edit_mask_pil_image: pILImage.optional(), pil_image: pILImage.optional(), nsfw: z.number().optional(), pose: spritePose.optional(), render_3d: sprite3DRender.optional(), pixel_grid: z.array(z.number().int()).nullable().optional(), pixel_size: z.number().optional(), model: z.string().optional(), normals: z.string().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 }; /** * Makes the normal map of an image, synchronously, and answers the image with it in `normals`. Free (Roles: user) * * POST /images/normal-map */ export const createApiImagesNormalMap = async (args: CreateApiImagesNormalMapArgs, options: CreateApiImagesNormalMapOptions) => { const {baseUrl, fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Bearer !== undefined) headers.set("Authorization", Bearer) const url = `${baseUrl.replace(/\/+$/, '')}/images/normal-map${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(gameImage, await res.json()) };