import {z} from 'zod' export type GetApiApiV1UsersProfileUserIdArgs = {user_id: unknown | unknown, topk?: number | undefined, max_token_size?: number | undefined, prefer_topics?: Array | undefined, only_topics?: Array | undefined, max_subtopic_size?: number | undefined, topic_limits_json?: string | undefined, chats_str?: string | undefined}; export type GetApiApiV1UsersProfileUserIdOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const profileData = z.object({id: z.union([z.string(), z.string()]), content: z.string(), created_at: z.string().optional(), updated_at: z.string().optional(), attributes: z.record(z.string(), z.unknown()).nullable().optional()}); export const userProfilesData = z.object({profiles: z.array(profileData)}); export const cODE = z.union([z.literal(0), z.literal(400), z.literal(401), z.literal(403), z.literal(404), z.literal(405), z.literal(409), z.literal(422), z.literal(500), z.literal(501), z.literal(502), z.literal(503), z.literal(504), z.literal(520)]); export const userProfileResponse = z.object({data: userProfilesData.nullable().optional(), errno: cODE.optional(), errmsg: 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 }; /** * Get User Profile * * GET /api/v1/users/profile/{user_id} */ export const getApiApiV1UsersProfileUserId = async (args: GetApiApiV1UsersProfileUserIdArgs, options?: GetApiApiV1UsersProfileUserIdOptions) => { const {baseUrl = "https://api.memobase.dev", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.topk != null) query.append("topk", String(args.topk)) if (args.max_token_size != null) query.append("max_token_size", String(args.max_token_size)) for (const item of args.prefer_topics ?? []) query.append("prefer_topics", String(item)) for (const item of args.only_topics ?? []) query.append("only_topics", String(item)) if (args.max_subtopic_size != null) query.append("max_subtopic_size", String(args.max_subtopic_size)) if (args.topic_limits_json != null) query.append("topic_limits_json", String(args.topic_limits_json)) if (args.chats_str != null) query.append("chats_str", String(args.chats_str)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/users/profile/${encodeURIComponent(String(args.user_id))}${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(userProfileResponse, await res.json()) };