/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import * as z from "zod/v3"; import { remap as remap$ } from "../../lib/primitives.js"; import { safeParse } from "../../lib/schemas.js"; import { blobLikeSchema } from "../../types/blobs.js"; import { Result as SafeParseResult } from "../../types/fp.js"; import { SDKValidationError } from "../errors/sdkvalidationerror.js"; export type ExtractWithSchemaFile = { fileName: string; content: ReadableStream | Blob | ArrayBuffer | Uint8Array; }; export type ExtractWithSchemaRequestBody = { /** * ID of the model to use for extraction */ model: string; /** * The file to extract structured data from */ file: ExtractWithSchemaFile | Blob; /** * Optional custom system prompt to guide extraction */ prompt?: string | undefined; }; export type ExtractWithSchemaRequest = { schemaId: string; /** * Optional external end-user identifier forwarded by the API gateway. */ xOnBehalfOf?: string | undefined; requestBody: ExtractWithSchemaRequestBody; }; /** @internal */ export const ExtractWithSchemaFile$inboundSchema: z.ZodType< ExtractWithSchemaFile, z.ZodTypeDef, unknown > = z.object({ fileName: z.string(), content: z.union([ z.instanceof(ReadableStream), z.instanceof(Blob), z.instanceof(ArrayBuffer), z.instanceof(Uint8Array), ]), }); /** @internal */ export type ExtractWithSchemaFile$Outbound = { fileName: string; content: ReadableStream | Blob | ArrayBuffer | Uint8Array; }; /** @internal */ export const ExtractWithSchemaFile$outboundSchema: z.ZodType< ExtractWithSchemaFile$Outbound, z.ZodTypeDef, ExtractWithSchemaFile > = z.object({ fileName: z.string(), content: z.union([ z.instanceof(ReadableStream), z.instanceof(Blob), z.instanceof(ArrayBuffer), z.instanceof(Uint8Array), ]), }); export function extractWithSchemaFileToJSON( extractWithSchemaFile: ExtractWithSchemaFile, ): string { return JSON.stringify( ExtractWithSchemaFile$outboundSchema.parse(extractWithSchemaFile), ); } export function extractWithSchemaFileFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => ExtractWithSchemaFile$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'ExtractWithSchemaFile' from JSON`, ); } /** @internal */ export const ExtractWithSchemaRequestBody$inboundSchema: z.ZodType< ExtractWithSchemaRequestBody, z.ZodTypeDef, unknown > = z.object({ model: z.string(), file: z.lazy(() => ExtractWithSchemaFile$inboundSchema), prompt: z.string().optional(), }); /** @internal */ export type ExtractWithSchemaRequestBody$Outbound = { model: string; file: ExtractWithSchemaFile$Outbound | Blob; prompt?: string | undefined; }; /** @internal */ export const ExtractWithSchemaRequestBody$outboundSchema: z.ZodType< ExtractWithSchemaRequestBody$Outbound, z.ZodTypeDef, ExtractWithSchemaRequestBody > = z.object({ model: z.string(), file: z.lazy(() => ExtractWithSchemaFile$outboundSchema).or(blobLikeSchema), prompt: z.string().optional(), }); export function extractWithSchemaRequestBodyToJSON( extractWithSchemaRequestBody: ExtractWithSchemaRequestBody, ): string { return JSON.stringify( ExtractWithSchemaRequestBody$outboundSchema.parse( extractWithSchemaRequestBody, ), ); } export function extractWithSchemaRequestBodyFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => ExtractWithSchemaRequestBody$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'ExtractWithSchemaRequestBody' from JSON`, ); } /** @internal */ export const ExtractWithSchemaRequest$inboundSchema: z.ZodType< ExtractWithSchemaRequest, z.ZodTypeDef, unknown > = z.object({ schema_id: z.string(), "X-On-Behalf-Of": z.string().optional(), RequestBody: z.lazy(() => ExtractWithSchemaRequestBody$inboundSchema), }).transform((v) => { return remap$(v, { "schema_id": "schemaId", "X-On-Behalf-Of": "xOnBehalfOf", "RequestBody": "requestBody", }); }); /** @internal */ export type ExtractWithSchemaRequest$Outbound = { schema_id: string; "X-On-Behalf-Of"?: string | undefined; RequestBody: ExtractWithSchemaRequestBody$Outbound; }; /** @internal */ export const ExtractWithSchemaRequest$outboundSchema: z.ZodType< ExtractWithSchemaRequest$Outbound, z.ZodTypeDef, ExtractWithSchemaRequest > = z.object({ schemaId: z.string(), xOnBehalfOf: z.string().optional(), requestBody: z.lazy(() => ExtractWithSchemaRequestBody$outboundSchema), }).transform((v) => { return remap$(v, { schemaId: "schema_id", xOnBehalfOf: "X-On-Behalf-Of", requestBody: "RequestBody", }); }); export function extractWithSchemaRequestToJSON( extractWithSchemaRequest: ExtractWithSchemaRequest, ): string { return JSON.stringify( ExtractWithSchemaRequest$outboundSchema.parse(extractWithSchemaRequest), ); } export function extractWithSchemaRequestFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => ExtractWithSchemaRequest$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'ExtractWithSchemaRequest' from JSON`, ); }