import {z} from 'zod' export type GetApiApiV1UsersContextUserIdArgs = {user_id: unknown | unknown, max_token_size?: number | undefined, prefer_topics?: Array | undefined, only_topics?: Array | undefined, max_subtopic_size?: number | undefined, topic_limits_json?: string | undefined, profile_event_ratio?: number | undefined, require_event_summary?: boolean | undefined, chats_str?: string | undefined, event_similarity_threshold?: number | undefined, time_range_in_days?: number | undefined, customize_context_prompt?: string | undefined, full_profile_and_only_search_event?: boolean | undefined, fill_window_with_events?: boolean | undefined}; export type GetApiApiV1UsersContextUserIdOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const contextData = z.object({context: z.string()}); 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 userContextDataResponse = z.object({data: contextData.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 Context * * GET /api/v1/users/context/{user_id} */ export const getApiApiV1UsersContextUserId = async (args: GetApiApiV1UsersContextUserIdArgs, options?: GetApiApiV1UsersContextUserIdOptions) => { 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.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.profile_event_ratio != null) query.append("profile_event_ratio", String(args.profile_event_ratio)) if (args.require_event_summary != null) query.append("require_event_summary", String(args.require_event_summary)) if (args.chats_str != null) query.append("chats_str", String(args.chats_str)) if (args.event_similarity_threshold != null) query.append("event_similarity_threshold", String(args.event_similarity_threshold)) if (args.time_range_in_days != null) query.append("time_range_in_days", String(args.time_range_in_days)) if (args.customize_context_prompt != null) query.append("customize_context_prompt", String(args.customize_context_prompt)) if (args.full_profile_and_only_search_event != null) query.append("full_profile_and_only_search_event", String(args.full_profile_and_only_search_event)) if (args.fill_window_with_events != null) query.append("fill_window_with_events", String(args.fill_window_with_events)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/users/context/${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(userContextDataResponse, await res.json()) };