import {z} from 'zod' export type GetApiV1ImportsContextsContextIdExtractionReviewsArgs = {contextId: string, status?: ('PENDING_REVIEW' | 'APPROVED' | 'REJECTED') | undefined, limit?: number | undefined, cursor?: string | undefined}; export type GetApiV1ImportsContextsContextIdExtractionReviewsOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const candidateFieldResponse = z.object({canonicalKey: z.string(), confidence: z.number().gte(0).lte(1), page: z.number().int(), region: z.string().optional(), value: z.string()}); export const candidateResponse = z.object({fields: z.array(candidateFieldResponse).nullable(), source: z.string()}); export const extractionReviewResponse = z.object({candidates: z.array(candidateResponse).nullable(), contextId: z.string(), createdAt: z.string(), id: z.string(), ingestionJobId: z.string().optional(), rejectReason: z.string().optional(), reviewerId: z.string().optional(), sourceId: z.string(), status: z.string(), updatedAt: z.string(), version: z.number().int()}); export const extractionReviewListResponse = z.object({items: z.array(extractionReviewResponse).nullable(), limit: z.number().int(), nextCursor: z.string().optional(), prevCursor: 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 }; /** * List AI extraction reviews (the human-review queue) * * GET /v1/imports/contexts/{contextId}/extraction-reviews */ export const getApiV1ImportsContextsContextIdExtractionReviews = async (args: GetApiV1ImportsContextsContextIdExtractionReviewsArgs, options?: GetApiV1ImportsContextsContextIdExtractionReviewsOptions) => { const {baseUrl = "https://identity.sandbox.lerian.net", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.status != null) query.append("status", String(args.status)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.cursor != null) query.append("cursor", String(args.cursor)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/imports/contexts/${encodeURIComponent(String(args.contextId))}/extraction-reviews${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(extractionReviewListResponse, await res.json()) };