import {z} from 'zod' export type MediaAssetReference = {media_asset_id: string, source?: 'media_asset' | undefined}; export type UriReference = {source?: 'uri' | undefined, uri: string}; export type DataBase64Reference = {data_base64: string, extension?: (string | null) | undefined, source?: 'data_base64' | undefined}; export type PanoDepthToRgbRequest = {depth_pano_image: MediaAssetReference | UriReference | DataBase64Reference, seed?: (number | null) | undefined, text_prompt: string, z_max?: (number | null) | undefined, z_min?: (number | null) | undefined}; export type CreateApiMarbleV1PanoDepthToRgbArgs = {body: PanoDepthToRgbRequest}; export type CreateApiMarbleV1PanoDepthToRgbOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const operationCostLineItem = z.object({credits: z.number().int(), name: z.string()}); export const operationCost = z.object({line_items: z.array(operationCostLineItem).optional(), total_credits: z.number().int()}); export const operationError = z.object({code: z.number().int().nullable().optional(), message: z.string().nullable().optional()}); export const panoDepthToRgbResult = z.object({pano_url: z.string().nullable().optional()}); export const operationPanoDepthToRgbResult = z.object({cost: operationCost.nullable().optional(), created_at: z.string().nullable().optional(), done: z.boolean(), error: operationError.nullable().optional(), expires_at: z.string().nullable().optional(), metadata: z.record(z.string(), z.unknown()).nullable().optional(), operation_id: z.string(), response: panoDepthToRgbResult.nullable().optional(), updated_at: z.string().nullable().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 }; /** * Pano Depth To Rgb * * POST /marble/v1/pano:depth_to_rgb */ export const createApiMarbleV1PanoDepthToRgb = async (args: CreateApiMarbleV1PanoDepthToRgbArgs, options?: CreateApiMarbleV1PanoDepthToRgbOptions) => { const {baseUrl = "https://api.worldlabs.ai", 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("WLT-Api-Key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/marble/v1/pano:depth_to_rgb${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(operationPanoDepthToRgbResult, await res.json()) };