/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. * @generated-id: 9f1e92f79055 */ import * as z from "zod/v4"; import { remap as remap$ } from "../../lib/primitives.js"; import { safeParse } from "../../lib/schemas.js"; import * as discriminatedUnionTypes from "../../types/discriminatedUnion.js"; import { discriminatedUnion } from "../../types/discriminatedUnion.js"; import { Result as SafeParseResult } from "../../types/fp.js"; import { SDKValidationError } from "../errors/sdkvalidationerror.js"; import { OCRAsideTextBlock, OCRAsideTextBlock$inboundSchema, } from "./ocrasidetextblock.js"; import { OCRCaptionBlock, OCRCaptionBlock$inboundSchema, } from "./ocrcaptionblock.js"; import { OCRCodeBlock, OCRCodeBlock$inboundSchema } from "./ocrcodeblock.js"; import { OCREquationBlock, OCREquationBlock$inboundSchema, } from "./ocrequationblock.js"; import { OCRFooterBlock, OCRFooterBlock$inboundSchema, } from "./ocrfooterblock.js"; import { OCRHeaderBlock, OCRHeaderBlock$inboundSchema, } from "./ocrheaderblock.js"; import { OCRImageBlock, OCRImageBlock$inboundSchema } from "./ocrimageblock.js"; import { OCRImageObject, OCRImageObject$inboundSchema, } from "./ocrimageobject.js"; import { OCRListBlock, OCRListBlock$inboundSchema } from "./ocrlistblock.js"; import { OCRPageConfidenceScores, OCRPageConfidenceScores$inboundSchema, } from "./ocrpageconfidencescores.js"; import { OCRPageDimensions, OCRPageDimensions$inboundSchema, } from "./ocrpagedimensions.js"; import { OCRReferencesBlock, OCRReferencesBlock$inboundSchema, } from "./ocrreferencesblock.js"; import { OCRSignatureBlock, OCRSignatureBlock$inboundSchema, } from "./ocrsignatureblock.js"; import { OCRTableBlock, OCRTableBlock$inboundSchema } from "./ocrtableblock.js"; import { OCRTableObject, OCRTableObject$inboundSchema, } from "./ocrtableobject.js"; import { OCRTextBlock, OCRTextBlock$inboundSchema } from "./ocrtextblock.js"; import { OCRTitleBlock, OCRTitleBlock$inboundSchema } from "./ocrtitleblock.js"; export type Block = | OCRAsideTextBlock | OCRCaptionBlock | OCRCodeBlock | OCREquationBlock | OCRFooterBlock | OCRHeaderBlock | OCRImageBlock | OCRListBlock | OCRReferencesBlock | OCRSignatureBlock | OCRTableBlock | OCRTextBlock | OCRTitleBlock | discriminatedUnionTypes.Unknown<"type">; export type OCRPageObject = { /** * The page index in a pdf document starting from 0 */ index: number; /** * The markdown string response of the page */ markdown: string; /** * List of all extracted images in the page */ images: Array; /** * List of all extracted tables in the page */ tables?: Array | undefined; /** * List of all hyperlinks in the page */ hyperlinks?: Array | undefined; /** * Header of the page */ header?: string | null | undefined; /** * Footer of the page */ footer?: string | null | undefined; /** * The dimensions of the PDF Page's screenshot image */ dimensions: OCRPageDimensions | null; /** * Confidence scores for the OCR page (populated when confidence_scores_granularity is set) */ confidenceScores?: OCRPageConfidenceScores | null | undefined; /** * Paragraph-level bounding boxes for all content blocks in reading order (populated when include_blocks is True) */ blocks?: | Array< | OCRAsideTextBlock | OCRCaptionBlock | OCRCodeBlock | OCREquationBlock | OCRFooterBlock | OCRHeaderBlock | OCRImageBlock | OCRListBlock | OCRReferencesBlock | OCRSignatureBlock | OCRTableBlock | OCRTextBlock | OCRTitleBlock | discriminatedUnionTypes.Unknown<"type"> > | null | undefined; }; /** @internal */ export const Block$inboundSchema: z.ZodType = discriminatedUnion("type", { aside_text: OCRAsideTextBlock$inboundSchema, caption: OCRCaptionBlock$inboundSchema, code: OCRCodeBlock$inboundSchema, equation: OCREquationBlock$inboundSchema, footer: OCRFooterBlock$inboundSchema, header: OCRHeaderBlock$inboundSchema, image: OCRImageBlock$inboundSchema, list: OCRListBlock$inboundSchema, references: OCRReferencesBlock$inboundSchema, signature: OCRSignatureBlock$inboundSchema, table: OCRTableBlock$inboundSchema, text: OCRTextBlock$inboundSchema, title: OCRTitleBlock$inboundSchema, }); export function blockFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => Block$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Block' from JSON`, ); } /** @internal */ export const OCRPageObject$inboundSchema: z.ZodType = z .object({ index: z.int(), markdown: z.string(), images: z.array(OCRImageObject$inboundSchema), tables: z.array(OCRTableObject$inboundSchema).optional(), hyperlinks: z.array(z.string()).optional(), header: z.nullable(z.string()).optional(), footer: z.nullable(z.string()).optional(), dimensions: z.nullable(OCRPageDimensions$inboundSchema), confidence_scores: z.nullable(OCRPageConfidenceScores$inboundSchema) .optional(), blocks: z.nullable(z.array(discriminatedUnion("type", { aside_text: OCRAsideTextBlock$inboundSchema, caption: OCRCaptionBlock$inboundSchema, code: OCRCodeBlock$inboundSchema, equation: OCREquationBlock$inboundSchema, footer: OCRFooterBlock$inboundSchema, header: OCRHeaderBlock$inboundSchema, image: OCRImageBlock$inboundSchema, list: OCRListBlock$inboundSchema, references: OCRReferencesBlock$inboundSchema, signature: OCRSignatureBlock$inboundSchema, table: OCRTableBlock$inboundSchema, text: OCRTextBlock$inboundSchema, title: OCRTitleBlock$inboundSchema, }))).optional(), }).transform((v) => { return remap$(v, { "confidence_scores": "confidenceScores", }); }); export function ocrPageObjectFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => OCRPageObject$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'OCRPageObject' from JSON`, ); }