import {z} from 'zod' export type ExportWorldRequest = {asset_type: 'splats' | 'mesh', format: 'ply' | 'glb', mesh_variant?: ('textured' | 'vertex_colored') | undefined, resolution?: ('full_res' | '500k' | '150k' | '100k') | undefined}; export type CreateApiMarbleV1WorldsWorldIdExportArgs = {world_id: string, body: ExportWorldRequest}; export type CreateApiMarbleV1WorldsWorldIdExportOptions = {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 exportWorldResult = z.object({asset_type: z.enum(["splats", "mesh"]), format: z.enum(["ply", "glb"]), mesh_variant: z.enum(["textured", "vertex_colored"]).nullable().optional(), resolution: z.string().nullable().optional(), url: z.string()}); export const exportWorldResponse = 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: exportWorldResult.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 }; /** * Export World * * POST /marble/v1/worlds/{world_id}:export */ export const createApiMarbleV1WorldsWorldIdExport = async (args: CreateApiMarbleV1WorldsWorldIdExportArgs, options?: CreateApiMarbleV1WorldsWorldIdExportOptions) => { 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/worlds/${encodeURIComponent(String(args.world_id))}:export${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(exportWorldResponse, await res.json()) };