import { Dispatcher } from "undici"; import { InputSource, PageOptions } from "../input/index.js"; import { ApiSettingsV1, Endpoint } from "./http/index.js"; import { AsyncPredictResponse, FeedbackResponse, Inference, PredictResponse, StringDict } from "./parsing/common/index.js"; /** * Common options for workflows and predictions. */ interface BaseOptions { /** * Whether to include the full ocr text. Only available on compatible APIs. */ fullText?: boolean; /** * If set, remove pages from the document as specified. * This is done before sending the file to the server and is useful to avoid page limitations. */ pageOptions?: PageOptions; /** * If set, will enable Retrieval-Augmented Generation (only works if a valid workflowId is set). */ rag?: boolean; } /** * Options relating to predictions. */ export interface PredictOptions extends BaseOptions { /** * A custom endpoint. */ endpoint?: Endpoint; /** * Whether to include the full text for each page. * * This performs a full OCR operation on the server and will increase response time. */ allWords?: boolean; /** * Whether to include cropper results for each page. */ cropper?: boolean; /** * The ID of the workflow. */ workflowId?: string; } /** * Timer options forwarded to `setTimeout` in polling loops. */ export interface TimerOptions { /** * Whether the timer should keep the event loop active. */ ref?: boolean; /** * Optional signal used to abort timer waits. */ signal?: AbortSignal; } /** * Asynchronous polling parameters. */ export interface OptionalAsyncOptions extends PredictOptions { /** * Delay in seconds before the first polling attempt. */ initialDelaySec?: number; /** * Delay in seconds between polling attempts. */ delaySec?: number; /** * Maximum number of polling attempts. */ maxRetries?: number; /** * Timer options used for the first delay. */ initialTimerOptions?: TimerOptions; /** * Timer options used for recurring polling delays. */ recurringTimerOptions?: TimerOptions; } export interface AsyncOptions extends PredictOptions { initialDelaySec: number; delaySec: number; maxRetries: number; initialTimerOptions?: TimerOptions; recurringTimerOptions?: TimerOptions; } export interface ClientOptions { /** * Your API key for all endpoints. */ apiKey?: string; /** * Raise an `Error` on errors. */ throwOnError?: boolean; /** * Log debug messages. */ debug?: boolean; /** * Custom dispatcher for HTTP requests. */ dispatcher?: Dispatcher; } /** * Mindee Client class that centralizes most basic operations. * * @category Client */ export declare class Client { #private; /** * Mindee V1 API settings. */ protected apiSettings: ApiSettingsV1; /** * @param {ClientOptions} options options for the initialization of a client. */ constructor({ apiKey, throwOnError, debug, dispatcher }?: ClientOptions); /** * Send a document to a synchronous endpoint and parse the predictions. * * @param productClass product class to use for calling the API and parsing the response. * @param inputSource file to parse. * @param params parameters relating to prediction options. * @typeParam T an extension of an `Inference`. Can be omitted as it will be inferred from the `productClass`. * @category Synchronous * @returns a `Promise` containing parsing results. */ parse(productClass: new (httpResponse: StringDict) => T, inputSource: InputSource, params?: PredictOptions): Promise>; /** * Send the document to an asynchronous endpoint and return its ID in the queue. * @param productClass product class to use for calling the API and parsing the response. * @param inputSource file to parse. * @param params parameters relating to prediction options. * @category Asynchronous * @returns a `Promise` containing the job (queue) corresponding to a document. */ enqueue(productClass: new (httpResponse: StringDict) => T, inputSource: InputSource, params?: PredictOptions): Promise>; /** * Polls a queue and returns its status as well as the prediction results if the parsing is done. * * @param productClass product class to use for calling the API and parsing the response. * @param queueId id of the queue to poll. * @param params parameters relating to prediction options. * @typeParam T an extension of an `Inference`. Can be omitted as it will be inferred from the `productClass`. * @category Asynchronous * @returns a `Promise` containing a `Job`, which also contains a `Document` if the * parsing is complete. */ parseQueued(productClass: new (httpResponse: StringDict) => T, queueId: string, params?: PredictOptions): Promise>; /** * Fetch prediction results from a document already processed. * * @param productClass product class to use for calling the API and parsing the response. * @param documentId id of the document to fetch. * @param params optional parameters. * @param params.endpoint Endpoint, only specify if using a custom product. * @typeParam T an extension of an `Inference`. Can be omitted as it will be inferred from the `productClass`. * @category Synchronous * @returns a `Promise` containing parsing results. */ getDocument(productClass: new (httpResponse: StringDict) => T, documentId: string, params?: { endpoint?: Endpoint; }): Promise>; /** * Send feedback for a document. * * @param productClass product class to use for calling the API and parsing the response. * @param documentId id of the document to send feedback for. * @param feedback the feedback to send. * @param params optional parameters. * @param params.endpoint Endpoint, only specify if using a custom product. * @typeParam T an extension of an `Inference`. Can be omitted as it will be inferred from the `productClass`. * @category Synchronous * @returns a `Promise` containing feedback results. */ sendFeedback(productClass: new (httpResponse: StringDict) => T, documentId: string, feedback: StringDict, params?: { endpoint?: Endpoint; }): Promise; /** * Send a document to an asynchronous endpoint and poll the server until the result is sent or * until the maximum number of tries is reached. * * @param productClass product class to use for calling the API and parsing the response. * @param inputSource document to parse. * @param asyncParams parameters relating to prediction options. * * @typeParam T an extension of an `Inference`. Can be omitted as it will be inferred from the `productClass`. * @category Synchronous * @returns a `Promise` containing parsing results. */ enqueueAndParse(productClass: new (httpResponse: StringDict) => T, inputSource: InputSource, asyncParams?: OptionalAsyncOptions): Promise>; /** * Forces boolean coercion on truthy/falsy parameters. * @param param input parameter to check. * @returns a strict boolean value. */ protected getBooleanParam(param?: boolean): boolean; /** * Creates a custom endpoint with the given values. Raises an error if the endpoint is invalid. * @param endpointName Name of the custom Endpoint. * @param accountName Name of the account tied to the Endpoint. * @param endpointVersion Version of the custom Endpoint. * @typeParam T an extension of an `Inference`. Can be omitted as it will be inferred from the `productClass`. * * @returns Endpoint a new product endpoint */ createEndpoint(endpointName: string, accountName: string, endpointVersion?: string): Endpoint; } export {};