import {z} from 'zod' export type GetApiAdminAiReplySuggestionsArgs = {Offset?: number | undefined, Limit?: number | undefined, ThresholdMin?: number | undefined, ThresholdMax?: number | undefined, conversation_id: string}; export type GetApiAdminAiReplySuggestionsOptions = {baseUrl: string, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const aiReplySuggestion = z.object({confidence_level: z.number().optional(), conversation_id: z.number().int().optional(), created: z.string().optional(), id: z.number().int().optional(), last_message_id: z.number().int().optional(), message: z.number().int().optional(), requesting_user_id: z.number().int().optional(), requesting_user_role: z.string().optional(), suggestion_text: z.string().optional(), updated: z.string().optional()}); export const getApiAdminAiReplySuggestionsResponse = z.array(aiReplySuggestion); 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 }; /** * List AI reply suggestions for a conversation. * * GET /admin/ai-reply-suggestions * * Also accepts auth: API-Key */ export const getApiAdminAiReplySuggestions = async (args: GetApiAdminAiReplySuggestionsArgs, options: GetApiAdminAiReplySuggestionsOptions) => { const {baseUrl, fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.Offset != null) query.append("Offset", String(args.Offset)) if (args.Limit != null) query.append("Limit", String(args.Limit)) if (args.ThresholdMin != null) query.append("ThresholdMin", String(args.ThresholdMin)) if (args.ThresholdMax != null) query.append("ThresholdMax", String(args.ThresholdMax)) if (args.conversation_id != null) query.append("conversation_id", String(args.conversation_id)) if (Bearer !== undefined) headers.set("Authorization", Bearer) const url = `${baseUrl.replace(/\/+$/, '')}/admin/ai-reply-suggestions${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(getApiAdminAiReplySuggestionsResponse, await res.json()) };