UNPKG

mindee

Version:

Mindee Client Library for Node.js

216 lines (215 loc) 8.85 kB
import { Dispatcher } from "undici"; import { InputSource, PageOptions } from "../input/index.js"; import { ApiSettingsV1, Endpoint } from "./http/index.js"; import { AsyncPredictResponse, ExecutionPriority, FeedbackResponse, Inference, PredictResponse, StringDict, WorkflowResponse } from "./parsing/common/index.js"; import { GeneratedV1 } from "./product/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; } /** * Options relating to workflows. * @category Workflow */ export interface WorkflowOptions extends BaseOptions { /** * Alias to give to the document. */ alias?: string; /** * Priority to give to the document. */ priority?: ExecutionPriority; /** * A unique, encrypted URL for accessing the document validation interface without requiring authentication. */ publicUrl?: string; } /** * Asynchronous polling parameters. */ export interface OptionalAsyncOptions extends PredictOptions { initialDelaySec?: number; delaySec?: number; maxRetries?: number; initialTimerOptions?: { ref?: boolean; signal?: AbortSignal; }; recurringTimerOptions?: { ref?: boolean; signal?: AbortSignal; }; } export interface AsyncOptions extends PredictOptions { initialDelaySec: number; delaySec: number; maxRetries: number; initialTimerOptions?: { ref?: boolean; signal?: AbortSignal; }; recurringTimerOptions?: { ref?: boolean; signal?: AbortSignal; }; } 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<T extends Inference>(productClass: new (httpResponse: StringDict) => T, inputSource: InputSource, params?: PredictOptions): Promise<PredictResponse<T>>; /** * 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<T extends Inference>(productClass: new (httpResponse: StringDict) => T, inputSource: InputSource, params?: PredictOptions): Promise<AsyncPredictResponse<T>>; /** * 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<T extends Inference>(productClass: new (httpResponse: StringDict) => T, queueId: string, params?: PredictOptions): Promise<AsyncPredictResponse<T>>; /** * Send the document to an asynchronous endpoint and return its ID in the queue. * @param inputSource file to send to the API. * @param workflowId ID of the workflow. * @param params parameters relating to prediction options. * @category Workflow * @returns a `Promise` containing the job (queue) corresponding to a document. */ executeWorkflow(inputSource: InputSource, workflowId: string, params?: WorkflowOptions): Promise<WorkflowResponse<GeneratedV1>>; /** * 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<T extends Inference>(productClass: new (httpResponse: StringDict) => T, documentId: string, params?: { endpoint?: Endpoint; }): Promise<PredictResponse<T>>; /** * 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<T extends Inference>(productClass: new (httpResponse: StringDict) => T, documentId: string, feedback: StringDict, params?: { endpoint?: Endpoint; }): Promise<FeedbackResponse>; /** * 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<T extends Inference>(productClass: new (httpResponse: StringDict) => T, inputSource: InputSource, asyncParams?: OptionalAsyncOptions): Promise<AsyncPredictResponse<T>>; /** * 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 {};