import {z} from 'zod' export type GetApiApiV1AnalyzeTextUnitClassifierSuggestionsIdArgs = {id: string, jq_filters?: {[key: string]: string} | undefined}; export type GetApiApiV1AnalyzeTextUnitClassifierSuggestionsIdOptions = {baseUrl: string, AuthToken?: string | undefined, fetch?: typeof fetch | undefined}; export const textUnitClassifierSuggestion = z.object({pk: z.number().int().optional(), text_unit__document__pk: z.string().optional(), text_unit__document__name: z.string().optional(), text_unit__document__document_type: z.string().optional(), text_unit__document__description: z.string().optional(), text_unit__pk: z.string().optional(), class_name: z.string().max(1024), class_value: z.string().max(1024), classifier_run: z.string().optional(), classifier_confidence: z.number().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 /api/v1/analyze/text-unit-classifier-suggestions/{id}/ */ export const getApiApiV1AnalyzeTextUnitClassifierSuggestionsId = async (args: GetApiApiV1AnalyzeTextUnitClassifierSuggestionsIdArgs, options: GetApiApiV1AnalyzeTextUnitClassifierSuggestionsIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, AuthToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.jq_filters != null) query.append("jq_filters", JSON.stringify(args.jq_filters)) if (AuthToken !== undefined) headers.set("Authorization", AuthToken) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/analyze/text-unit-classifier-suggestions/${encodeURIComponent(String(args.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(textUnitClassifierSuggestion, await res.json()) };