/** * Extended ExtractRuns client with polling utilities and typed responses. * * For typed schema support, use: * - `client.extract()` for synchronous extraction (waits for completion) * - `client.extractRuns.createAndPoll()` for async extraction with polling * * @example * ```typescript * import { ExtendClient, extendDate, extendCurrency } from "extend-ai"; * import { z } from "zod"; * * const client = new ExtendClient({ token: "..." }); * * // Option 1: Use extract() for sync processing (waits for completion) * const result = await client.extract({ * file: { url: "https://example.com/invoice.pdf" }, * config: { * schema: z.object({ * invoice_number: z.string().nullable().describe("The invoice number"), * invoice_date: extendDate().describe("The invoice date"), * total: extendCurrency().describe("Total amount"), * }), * baseProcessor: "extraction_performance", * }, * }); * * // Option 2: Use createAndPoll() for async with polling * const result = await client.extractRuns.createAndPoll({ * file: { url: "https://example.com/invoice.pdf" }, * config: { * schema: z.object({ * invoice_number: z.string().nullable(), * total: extendCurrency(), * }), * baseProcessor: "extraction_performance", * }, * }); * * // output.value is fully typed! * console.log(result.output.value.invoice_number); // string | null * console.log(result.output.value.total.amount); // number | null * ``` */ import { z } from "zod"; import { ExtractRunsClient as GeneratedExtractRunsClient } from "../../../api/resources/extractRuns/client/Client"; import * as Extend from "../../../api"; import { PollingOptions, PollingTimeoutError } from "../../utilities/polling"; import { TypedExtractConfig } from "../../schema/configConversion"; export { PollingTimeoutError }; export interface CreateAndPollOptions extends PollingOptions { /** * Request options passed to both create and retrieve calls. */ requestOptions?: GeneratedExtractRunsClient.RequestOptions; } /** * Extractor reference with typed overrideConfig. * Use this when overriding an existing extractor's config with a typed schema. */ export interface TypedExtractorReference { /** The ID of the extractor to use (e.g., "extractor_abc123"). */ id: string; /** * Optional version of the extractor to use. * If not provided, the latest published version will be used. */ version?: Extend.ProcessorVersionString; /** * Typed configuration override for this extractor. * The extraction output will be fully typed based on the schema you provide. */ overrideConfig: TypedExtractConfig; } /** * Request type for typed extraction with inline config. * Use this when providing a typed schema directly via `config.schema`. */ export interface TypedExtractRunsCreateRequestWithConfig extends Omit { /** * Inline extract configuration with typed schema. * The extraction output will be fully typed based on the schema you provide. */ config: TypedExtractConfig; extractor?: never; } /** * Request type for typed extraction with extractor.overrideConfig. * Use this when overriding an existing extractor's config with a typed schema. */ export interface TypedExtractRunsCreateRequestWithExtractor extends Omit { /** * Reference to an existing extractor with typed configuration override. * The extraction output will be fully typed based on the schema in overrideConfig. */ extractor: TypedExtractorReference; config?: never; } /** * Union of both typed request forms. */ export type TypedExtractRunsCreateRequest = TypedExtractRunsCreateRequestWithConfig | TypedExtractRunsCreateRequestWithExtractor; /** * Typed extract output where value matches the schema. */ export interface TypedExtractOutput { value: T; metadata: Extend.ExtractOutputMetadata; } /** * Typed extract run with output matching the schema. */ export interface TypedExtractRun extends Omit { output: TypedExtractOutput | null; initialOutput: TypedExtractOutput | null; reviewedOutput: TypedExtractOutput | null; } export declare class ExtractRunsClient extends GeneratedExtractRunsClient { /** * Creates an extract run and polls until it reaches a terminal state. * * This is a convenience method that combines `create()` and polling via * `retrieve()` with exponential backoff and jitter. * * Terminal states: PROCESSED, FAILED, CANCELLED * * @param request - The extract run creation request * @param options - Polling and request options * @returns The final extract run when processing is complete * @throws {PollingTimeoutError} If the run doesn't complete within maxWaitMs * * @example * ```typescript * // Basic usage (untyped) * const result = await client.extractRuns.createAndPoll({ * file: { url: "https://example.com/doc.pdf" }, * extractor: { id: "extractor_abc123" } * }); * * // With typed inline config (zod schema) * const result = await client.extractRuns.createAndPoll({ * file: { url: "..." }, * config: { * schema: z.object({ * name: z.string().nullable(), * amount: extendCurrency(), * }), * baseProcessor: "extraction_performance", * }, * }); * * // result.output.value is typed! * console.log(result.output.value.name); // string | null * console.log(result.output.value.amount.amount); // number | null * ``` */ createAndPoll(request: TypedExtractRunsCreateRequestWithConfig, options?: CreateAndPollOptions): Promise>>>; createAndPoll(request: TypedExtractRunsCreateRequestWithExtractor, options?: CreateAndPollOptions): Promise>>>; createAndPoll(request: Extend.ExtractRunsCreateRequest, options?: CreateAndPollOptions): Promise; /** * Converts a potentially typed request to the standard API request format. */ private convertToApiRequest; }