import {z} from 'zod' export type AnnotationContentDatapointContent = {value?: string | undefined, normalized_value?: (string | null) | undefined, page?: (number | null) | undefined, position?: (Array | null) | undefined, rir_text?: (string | null) | undefined, rir_raw_text?: (string | null) | undefined, rir_page?: (number | null) | undefined, rir_position?: (Array | null) | undefined, rir_confidence?: (number | null) | undefined, connector_text?: (string | null) | undefined, connector_position?: (Array | null) | undefined, ocr_text?: (string | null) | undefined, ocr_raw_text?: (string | null) | undefined, ocr_position?: (Array | null) | undefined}; export type ValidationSource = 'score' | 'checks' | 'not_found' | 'data_matching' | 'history' | 'connector' | 'table_suggester' | 'rules' | 'einvoicing' | 'human' | 'non_required' | 'NA'; export type ValidationSources = Array; export type AnnotationContentDatapoint = {id: number, url: string, schema_id: string, category: 'datapoint', hidden?: boolean | undefined, content: AnnotationContentDatapointContent, validation_sources: ValidationSources, time_spent: number, time_spent_overall: number, no_recalculation?: boolean | undefined}; export type AnnotationContentGrid = {parts?: (Array<{page?: number | undefined, columns?: (Array<{left_position?: number | undefined, schema_id?: (string | null) | undefined, header_texts?: Array | undefined}>) | undefined, rows?: (Array<{top_position?: number | undefined, tuple_id?: (number | null) | undefined, type?: (string | null) | undefined}>) | undefined, width?: number | undefined, height?: number | undefined}>) | undefined}; export type AnnotationContentSection = {id: number, url: string, schema_id: string, category: 'section', children: Array<{id: number, url: string, schema_id: string, category: 'multivalue', hidden?: boolean | undefined, children: Array<{id: number, url: string, schema_id: string, category: 'tuple', hidden?: boolean | undefined, children: Array} | {id: number, url: string, schema_id: string, category: 'datapoint', hidden?: boolean | undefined, content: AnnotationContentDatapointContent, validation_sources: ValidationSources, time_spent: number, time_spent_overall: number, no_recalculation?: boolean | undefined}>, grid: AnnotationContentGrid, time_spent: number, time_spent_overall: number, time_spent_grid: number, time_spent_grid_overall: number} | {id: number, url: string, schema_id: string, category: 'tuple', hidden?: boolean | undefined, children: Array} | {id: number, url: string, schema_id: string, category: 'datapoint', hidden?: boolean | undefined, content: AnnotationContentDatapointContent, validation_sources: ValidationSources, time_spent: number, time_spent_overall: number, no_recalculation?: boolean | undefined}>}; export type AnnotationContent = {content?: Array | undefined}; export type PatchApiApiV1AnnotationsAnnotationIDContentArgs = {annotationID: number, body: AnnotationContent}; export type PatchApiApiV1AnnotationsAnnotationIDContentOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const annotationContentDatapointContent = z.object({value: z.string().optional(), normalized_value: z.string().nullable().optional(), page: z.number().int().nullable().optional(), position: z.array(z.number()).nullable().optional(), rir_text: z.string().nullable().optional(), rir_raw_text: z.string().nullable().optional(), rir_page: z.number().int().nullable().optional(), rir_position: z.array(z.number()).nullable().optional(), rir_confidence: z.number().nullable().optional(), connector_text: z.string().nullable().optional(), connector_position: z.array(z.number()).nullable().optional(), ocr_text: z.string().nullable().optional(), ocr_raw_text: z.string().nullable().optional(), ocr_position: z.array(z.number()).nullable().optional()}); export const validationSource = z.enum(["score", "checks", "not_found", "data_matching", "history", "connector", "table_suggester", "rules", "einvoicing", "human", "non_required", "NA"]); export const validationSources = z.array(validationSource); export const annotationContentDatapoint = z.object({id: z.number().int(), url: z.string(), schema_id: z.string(), category: z.literal("datapoint"), hidden: z.boolean().optional(), content: annotationContentDatapointContent, validation_sources: validationSources, time_spent: z.number(), time_spent_overall: z.number(), no_recalculation: z.boolean().optional()}); export const annotationContentGrid = z.object({parts: z.array(z.object({page: z.number().optional(), columns: z.array(z.object({left_position: z.number().optional(), schema_id: z.string().nullable().optional(), header_texts: z.array(z.string()).optional()})).optional(), rows: z.array(z.object({top_position: z.number().optional(), tuple_id: z.number().nullable().optional(), type: z.string().nullable().optional()})).optional(), width: z.number().optional(), height: z.number().optional()})).optional()}); export const annotationContentSection = z.object({id: z.number().int(), url: z.string(), schema_id: z.string(), category: z.literal("section"), children: z.array(z.union([z.object({id: z.number().int(), url: z.string(), schema_id: z.string(), category: z.literal("multivalue"), hidden: z.boolean().optional(), children: z.array(z.union([z.object({id: z.number().int(), url: z.string(), schema_id: z.string(), category: z.literal("tuple"), hidden: z.boolean().optional(), children: z.array(annotationContentDatapoint)}), z.object({id: z.number().int(), url: z.string(), schema_id: z.string(), category: z.literal("datapoint"), hidden: z.boolean().optional(), content: annotationContentDatapointContent, validation_sources: validationSources, time_spent: z.number(), time_spent_overall: z.number(), no_recalculation: z.boolean().optional()})])), grid: annotationContentGrid, time_spent: z.number(), time_spent_overall: z.number(), time_spent_grid: z.number(), time_spent_grid_overall: z.number()}), z.object({id: z.number().int(), url: z.string(), schema_id: z.string(), category: z.literal("tuple"), hidden: z.boolean().optional(), children: z.array(annotationContentDatapoint)}), z.object({id: z.number().int(), url: z.string(), schema_id: z.string(), category: z.literal("datapoint"), hidden: z.boolean().optional(), content: annotationContentDatapointContent, validation_sources: validationSources, time_spent: z.number(), time_spent_overall: z.number(), no_recalculation: z.boolean().optional()})]))}); export const annotationContent = z.object({content: z.array(annotationContentSection).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 }; /** * Update annotation content * * PATCH /api/v1/annotations/{annotationID}/content */ export const patchApiApiV1AnnotationsAnnotationIDContent = async (args: PatchApiApiV1AnnotationsAnnotationIDContentArgs, options?: PatchApiApiV1AnnotationsAnnotationIDContentOptions) => { const {baseUrl = "https://example.rossum.app", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/annotations/${encodeURIComponent(String(args.annotationID))}/content${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(annotationContent, await res.json()) };