import {z} from 'zod' export type ModelChoices = 'gpt-5-nano' | 'gpt-5.4-nano' | 'gpt-5.6-luna'; export type GetApiApiV1AiCommentArgs = {amount_of_comments?: number | undefined, context?: string | undefined, generate_images?: boolean | undefined, generate_replies?: boolean | undefined, max_reply_depth?: number | undefined, model?: ModelChoices | undefined, temperature?: number | undefined, max_tokens?: number | undefined, top_p?: number | undefined, frequency_penalty?: number | undefined, presence_penalty?: number | undefined}; export type GetApiApiV1AiCommentOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const getApiApiV1AiCommentResponse = z.unknown(); 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 Comment * * GET /api/v1/ai/comment */ export const getApiApiV1AiComment = async (args: GetApiApiV1AiCommentArgs, options: GetApiApiV1AiCommentOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.amount_of_comments != null) query.append("amount_of_comments", String(args.amount_of_comments)) if (args.context != null) query.append("context", String(args.context)) if (args.generate_images != null) query.append("generate_images", String(args.generate_images)) if (args.generate_replies != null) query.append("generate_replies", String(args.generate_replies)) if (args.max_reply_depth != null) query.append("max_reply_depth", String(args.max_reply_depth)) if (args.model != null) query.append("model", String(args.model)) if (args.temperature != null) query.append("temperature", String(args.temperature)) if (args.max_tokens != null) query.append("max_tokens", String(args.max_tokens)) if (args.top_p != null) query.append("top_p", String(args.top_p)) if (args.frequency_penalty != null) query.append("frequency_penalty", String(args.frequency_penalty)) if (args.presence_penalty != null) query.append("presence_penalty", String(args.presence_penalty)) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/ai/comment${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(getApiApiV1AiCommentResponse, await res.json()) };