import {z} from 'zod' export type MemoryScoringWeightsUpdate = {favourite?: (number | null) | undefined, known_people?: (number | null) | undefined, event_strength?: (number | null) | undefined, face_presence?: (number | null) | undefined, semantic_confidence?: (number | null) | undefined, gps_novelty?: (number | null) | undefined, in_album?: (number | null) | undefined}; export type MemoriesPreferencesUpdate = {enabled?: (boolean | null) | undefined, notifications_enabled?: (boolean | null) | undefined, story_music_enabled?: (boolean | null) | undefined, slide_duration_seconds?: (number | null) | undefined, include_videos?: (boolean | null) | undefined, min_images?: (number | null) | undefined, max_images?: (number | null) | undefined, weights?: (MemoryScoringWeightsUpdate | null) | undefined}; export type UpdateUserPreferencesRequest = {YOLO_model_size?: ('nano' | 'small' | 'medium' | null) | undefined, GPU_Acceleration?: (boolean | null) | undefined, Video_Frame_Interval?: (number | null) | undefined, Video_Face_Detection?: (boolean | null) | undefined, Metadata_Export?: (boolean | null) | undefined, memories?: (MemoriesPreferencesUpdate | null) | undefined}; export type UpdateApiUserPreferencesArgs = {body: UpdateUserPreferencesRequest}; export type UpdateApiUserPreferencesOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const memoryScoringWeights = z.object({favourite: z.number().gte(0).lte(1).optional(), known_people: z.number().gte(0).lte(1).optional(), event_strength: z.number().gte(0).lte(1).optional(), face_presence: z.number().gte(0).lte(1).optional(), semantic_confidence: z.number().gte(0).lte(1).optional(), gps_novelty: z.number().gte(0).lte(1).optional(), in_album: z.number().gte(0).lte(1).optional()}); export const memoriesPreferences = z.object({enabled: z.boolean().optional(), notifications_enabled: z.boolean().optional(), story_music_enabled: z.boolean().optional(), slide_duration_seconds: z.number().gte(1).lte(30).optional(), include_videos: z.boolean().optional(), min_images: z.number().int().gte(2).lte(50).optional(), max_images: z.number().int().gte(5).lte(100).optional(), weights: memoryScoringWeights.optional()}); export const userPreferencesData = z.object({YOLO_model_size: z.enum(["nano", "small", "medium"]).optional(), GPU_Acceleration: z.boolean().optional(), Video_Frame_Interval: z.number().gte(0.5).lte(300).optional(), Video_Face_Detection: z.boolean().optional(), Metadata_Export: z.boolean().optional(), memories: memoriesPreferences.optional()}); export const updateUserPreferencesResponse = z.object({success: z.boolean(), message: z.string(), user_preferences: userPreferencesData}); 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 }; /** * Update User Preferences * * PUT /user-preferences/ */ export const updateApiUserPreferences = async (args: UpdateApiUserPreferencesArgs, options?: UpdateApiUserPreferencesOptions) => { const {baseUrl = "http://localhost:52123", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/user-preferences/${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(updateUserPreferencesResponse, await res.json()) };