import {z} from 'zod' export type GetApiPublicV1ClonesCloneIdProfileArgs = {cloneId: string}; export type GetApiPublicV1ClonesCloneIdProfileOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const cloneHeadshot = z.object({large: z.string().optional(), medium: z.string().optional(), small: z.string().optional()}); export const cloneProfileState = z.object({voice: z.enum(["none", "generating", "ready", "error"]), headshot: z.enum(["none", "generating", "ready", "error"])}); export const cloneProfile = z.object({id: z.string(), name: z.string(), screenName: z.string(), status: z.string(), generation: z.string(), occupation: z.string().optional(), birthdate: z.string().optional(), gender: z.string().optional(), races: z.array(z.string()).optional(), language: z.string().optional(), nationality: z.string().optional(), currentCity: z.string().optional(), hometown: z.string().optional(), maritalStatus: z.string().optional(), headshot: cloneHeadshot.optional(), voiceUrl: z.string().optional(), state: cloneProfileState.optional(), appearanceDesc: z.string().optional(), careerDesc: z.string().optional(), educationDesc: z.string().optional(), principlesDesc: z.string().optional(), interestsDesc: z.string().optional(), familyDesc: z.string().optional(), childhoodDesc: z.string().optional(), socialCircleDesc: z.string().optional(), lifestyleDesc: z.string().optional(), sportsDesc: z.string().optional(), travelDesc: z.string().optional(), financesDesc: z.string().optional(), socialHobbiesDesc: z.string().optional(), unusualHobbiesDesc: z.string().optional(), isEnabled: z.boolean().optional(), createdAt: z.string(), updatedAt: 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 }; /** * Get clone profile * * GET /public/v1/clones/{cloneId}/profile */ export const getApiPublicV1ClonesCloneIdProfile = async (args: GetApiPublicV1ClonesCloneIdProfileArgs, options?: GetApiPublicV1ClonesCloneIdProfileOptions) => { const {baseUrl = "https://api.cloneforce.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/public/v1/clones/${encodeURIComponent(String(args.cloneId))}/profile${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(cloneProfile, await res.json()) };