docling-serve-client 0.4.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +466 -164
- package/dist/capabilities.d.ts +10 -0
- package/dist/capabilities.d.ts.map +1 -0
- package/dist/client.d.ts +3 -2
- package/dist/client.d.ts.map +1 -1
- package/dist/core/input.d.ts +1 -1
- package/dist/core/input.d.ts.map +1 -1
- package/dist/core/pdf.d.ts +2 -2
- package/dist/core/pdf.d.ts.map +1 -1
- package/dist/core/validate.d.ts +2 -2
- package/dist/core/validate.d.ts.map +1 -1
- package/dist/document.d.ts.map +1 -1
- package/dist/images.d.ts +6 -3
- package/dist/images.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +272 -78
- package/dist/index.js.map +12 -11
- package/dist/options.d.ts +37 -5
- package/dist/options.d.ts.map +1 -1
- package/dist/types.d.ts +169 -17
- package/dist/types.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/capabilities.ts +109 -0
- package/src/client.ts +254 -81
- package/src/core/http.ts +2 -4
- package/src/core/input.ts +1 -3
- package/src/core/pdf.ts +2 -3
- package/src/core/validate.ts +2 -3
- package/src/document.ts +7 -19
- package/src/images.ts +4 -6
- package/src/index.ts +9 -0
- package/src/options.ts +142 -27
- package/src/response.ts +2 -2
- package/src/types.ts +191 -30
package/src/types.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type { ErrorCode } from './core/result.js';
|
|
|
5
5
|
import type { DoclingDocument } from './document.js';
|
|
6
6
|
|
|
7
7
|
// -------------------------------------------------------------------
|
|
8
|
-
// --- 1.
|
|
8
|
+
// --- 1. Types
|
|
9
9
|
// -------------------------------------------------------------------
|
|
10
10
|
|
|
11
11
|
/** Identifies failure cause across validation, network, HTTP, and conversion. */
|
|
@@ -90,9 +90,7 @@ export type ServerError = {
|
|
|
90
90
|
*/
|
|
91
91
|
export type ServerVersions = Record<string, string>;
|
|
92
92
|
|
|
93
|
-
//
|
|
94
|
-
// --- 2. Options
|
|
95
|
-
// -------------------------------------------------------------------
|
|
93
|
+
// Options
|
|
96
94
|
|
|
97
95
|
/**
|
|
98
96
|
* **Bytes of the file to convert; the format is detected by magic bytes**.
|
|
@@ -103,7 +101,7 @@ export type ServerVersions = Record<string, string>;
|
|
|
103
101
|
*/
|
|
104
102
|
export type ConvertInput = Uint8Array;
|
|
105
103
|
|
|
106
|
-
/**
|
|
104
|
+
/** Deprecated: use `ConvertInput`; images are accepted as well. */
|
|
107
105
|
export type PdfInput = ConvertInput;
|
|
108
106
|
|
|
109
107
|
/** Supported conversion pipeline backend. */
|
|
@@ -112,6 +110,14 @@ export type Pipeline = 'standard' | 'vlm';
|
|
|
112
110
|
/** PDF text extraction backend used by docling. */
|
|
113
111
|
export type PdfBackend = 'docling_parse' | 'pypdfium2';
|
|
114
112
|
|
|
113
|
+
/**
|
|
114
|
+
* **OCR engine preset sent as `ocr_preset`**.
|
|
115
|
+
*
|
|
116
|
+
* - known engines autocomplete; any other non-empty preset id is accepted and sent as is
|
|
117
|
+
* - installed engines: `stages.ocr.presets` of `client.capabilities()`
|
|
118
|
+
*/
|
|
119
|
+
export type OcrEngine = 'auto' | 'rapidocr' | 'easyocr' | 'tesseract' | 'tesserocr' | 'ocrmac' | (string & {});
|
|
120
|
+
|
|
115
121
|
/** docling conversion options; set as factory defaults and/or per call. */
|
|
116
122
|
export type DoclingOptions = {
|
|
117
123
|
/** Nests headings by bookmarks, numbering, and font style; without it every heading has level 1. Default `true`. */
|
|
@@ -135,9 +141,12 @@ export type DoclingOptions = {
|
|
|
135
141
|
/**
|
|
136
142
|
* **OCRs whole PDF pages and drops their text layer**: for PDFs with broken text. Default `false`.
|
|
137
143
|
*
|
|
144
|
+
* - enables OCR even with `ocr: false` (docling skips full-page OCR when `do_ocr=false`)
|
|
138
145
|
* - ignored for image input: it has no text layer, and full-page OCR there merges words (`stepsand`)
|
|
139
146
|
*/
|
|
140
147
|
forceOcr?: boolean;
|
|
148
|
+
/** OCR engine preset (`ocr_preset`); an engine the server lacks fails the conversion. Default `'auto'`. */
|
|
149
|
+
ocrEngine?: OcrEngine;
|
|
141
150
|
};
|
|
142
151
|
|
|
143
152
|
/** docling options of the factory: every per-call option plus the factory-only ones, applied to every call. */
|
|
@@ -156,6 +165,17 @@ export type CallOptions = {
|
|
|
156
165
|
signal?: AbortSignal;
|
|
157
166
|
};
|
|
158
167
|
|
|
168
|
+
/**
|
|
169
|
+
* **Options for job helpers (`runMarkdown`, `runDocument`, `waitForJob`)**.
|
|
170
|
+
*
|
|
171
|
+
* - `signal` covers entire call: submit, status polls, and waits
|
|
172
|
+
* - rejected by `convert*`, `submit*`, and `check`
|
|
173
|
+
*/
|
|
174
|
+
export type PollOptions = CallOptions & {
|
|
175
|
+
/** Delay between status polls in ms (integer `1..2147483647`). Default: factory `pollMs` (`10`). */
|
|
176
|
+
pollMs?: number;
|
|
177
|
+
};
|
|
178
|
+
|
|
159
179
|
/**
|
|
160
180
|
* **Images in the md**.
|
|
161
181
|
*
|
|
@@ -200,9 +220,7 @@ export type DocumentOptions = DoclingOptions &
|
|
|
200
220
|
pageImages?: boolean;
|
|
201
221
|
};
|
|
202
222
|
|
|
203
|
-
//
|
|
204
|
-
// --- 3. Outputs
|
|
205
|
-
// -------------------------------------------------------------------
|
|
223
|
+
// Outputs
|
|
206
224
|
|
|
207
225
|
/** Pixel dimensions of an image. */
|
|
208
226
|
export type ImageSize = {
|
|
@@ -305,9 +323,53 @@ export type ConvertedDocument = {
|
|
|
305
323
|
versions: ServerVersions | null;
|
|
306
324
|
};
|
|
307
325
|
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
326
|
+
/**
|
|
327
|
+
* **Conversion settings exactly as sent in the multipart request**.
|
|
328
|
+
*
|
|
329
|
+
* - every key is the camelCase name of a docling-serve form field (`ocrPreset` = `ocr_preset`)
|
|
330
|
+
* - `null`: field not sent (md-only fields of json output, unused presets, unset factory options)
|
|
331
|
+
* - `ocrLang`: empty means not sent, i.e. engine default
|
|
332
|
+
* - server-side configuration not covered by request fields (e.g. layout model) is not included
|
|
333
|
+
*/
|
|
334
|
+
export type DoclingSettings = {
|
|
335
|
+
fromFormats: 'pdf' | 'image';
|
|
336
|
+
toFormats: 'md' | 'json';
|
|
337
|
+
imageExportMode: 'embedded' | 'placeholder';
|
|
338
|
+
includeImages: boolean;
|
|
339
|
+
includePageImages: boolean;
|
|
340
|
+
imagesScale: number;
|
|
341
|
+
mdCompactTables: boolean | null;
|
|
342
|
+
mdPageBreakPlaceholder: string | null;
|
|
343
|
+
doOcr: boolean;
|
|
344
|
+
forceOcr: boolean;
|
|
345
|
+
ocrPreset: string;
|
|
346
|
+
ocrLang: string[];
|
|
347
|
+
pdfBackend: PdfBackend;
|
|
348
|
+
pipeline: Pipeline;
|
|
349
|
+
vlmPipelinePreset: string | null;
|
|
350
|
+
doTableStructure: boolean;
|
|
351
|
+
tableMode: 'accurate';
|
|
352
|
+
tableStructurePreset: string;
|
|
353
|
+
tableCellMatching: boolean;
|
|
354
|
+
doPdfHeadingHierarchy: boolean;
|
|
355
|
+
doFormulaEnrichment: boolean;
|
|
356
|
+
doCodeEnrichment: boolean;
|
|
357
|
+
codeFormulaPreset: string | null;
|
|
358
|
+
doChartExtraction: boolean;
|
|
359
|
+
chartExtractionPreset: string | null;
|
|
360
|
+
doPictureClassification: boolean;
|
|
361
|
+
doPictureDescription: boolean;
|
|
362
|
+
pageRange: [from: number, to: number] | null;
|
|
363
|
+
documentTimeout: number | null;
|
|
364
|
+
abortOnError: boolean;
|
|
365
|
+
};
|
|
366
|
+
|
|
367
|
+
/** Result of `convert*` and `run*` plus the settings sent with the conversion. */
|
|
368
|
+
export type WithSettings<T> = T & {
|
|
369
|
+
settings: DoclingSettings;
|
|
370
|
+
};
|
|
371
|
+
|
|
372
|
+
// Asynchronous Jobs
|
|
311
373
|
|
|
312
374
|
/** Image handling of a md job, applied when `check()` picks up the result. */
|
|
313
375
|
export type MarkdownJobOutput =
|
|
@@ -320,6 +382,8 @@ export type MarkdownJob = {
|
|
|
320
382
|
/** Server-side task id. */
|
|
321
383
|
id: string;
|
|
322
384
|
output: MarkdownJobOutput;
|
|
385
|
+
/** Settings sent with the submission; `check()` neither needs nor returns them. */
|
|
386
|
+
settings: DoclingSettings;
|
|
323
387
|
};
|
|
324
388
|
|
|
325
389
|
/** Handle of a document conversion, returned by `submitDocument()`; plain JSON, safe to store. */
|
|
@@ -327,11 +391,16 @@ export type DocumentJob = {
|
|
|
327
391
|
kind: 'document';
|
|
328
392
|
/** Server-side task id. */
|
|
329
393
|
id: string;
|
|
394
|
+
/** Settings sent with the submission; `check()` neither needs nor returns them. */
|
|
395
|
+
settings: DoclingSettings;
|
|
330
396
|
};
|
|
331
397
|
|
|
332
|
-
/** Any job handle
|
|
398
|
+
/** Any job handle returned by `submit*()`. */
|
|
333
399
|
export type Job = MarkdownJob | DocumentJob;
|
|
334
400
|
|
|
401
|
+
/** Job handle accepted by `check()`; `settings` may be dropped when storing the job. */
|
|
402
|
+
export type JobRef = Omit<MarkdownJob, 'settings'> | Omit<DocumentJob, 'settings'>;
|
|
403
|
+
|
|
335
404
|
/** State of an async job; `done` carries the conversion result. */
|
|
336
405
|
export type JobState<T> =
|
|
337
406
|
/** Pending in server queue; `position` is 1-based when reported by server. */
|
|
@@ -341,18 +410,73 @@ export type JobState<T> =
|
|
|
341
410
|
/** Completed; carries the conversion result. */
|
|
342
411
|
| ({ status: 'done' } & T);
|
|
343
412
|
|
|
344
|
-
//
|
|
345
|
-
|
|
346
|
-
|
|
413
|
+
// Server Capabilities
|
|
414
|
+
|
|
415
|
+
/** Model or engine preset a pipeline stage offers; `id` is the value of the stage's form field. */
|
|
416
|
+
export type CapabilityPreset = {
|
|
417
|
+
id: string;
|
|
418
|
+
name: string;
|
|
419
|
+
description: string | null;
|
|
420
|
+
/** Origin, e.g. `'docling'` or `'default'` (server default alias). */
|
|
421
|
+
source: string;
|
|
422
|
+
};
|
|
423
|
+
|
|
424
|
+
/** Pipeline stage (OCR, table structure, VLM, ...) with its form field and installed presets. */
|
|
425
|
+
export type CapabilityStage = {
|
|
426
|
+
/** Form field selecting the preset, e.g. `'ocr_preset'`. */
|
|
427
|
+
option: string;
|
|
428
|
+
customConfigOption: string | null;
|
|
429
|
+
/** Preset used when the field is not sent. */
|
|
430
|
+
default: string;
|
|
431
|
+
presets: CapabilityPreset[];
|
|
432
|
+
};
|
|
433
|
+
|
|
434
|
+
/** Server limits; `null` means unlimited or not reported. */
|
|
435
|
+
export type CapabilityLimits = {
|
|
436
|
+
maxDocumentTimeout: number | null;
|
|
437
|
+
maxImagesScale: number | null;
|
|
438
|
+
maxSourcesPerRequest: number | null;
|
|
439
|
+
maxNumPages: number | null;
|
|
440
|
+
maxFileSize: number | null;
|
|
441
|
+
};
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* **What the docling-serve instance offers (`GET /v1/capabilities`)**.
|
|
445
|
+
*
|
|
446
|
+
* - snake_case keys of the server payload converted to camelCase; `stages` keys stay as sent (e.g. `table_structure`)
|
|
447
|
+
* - missing or mistyped fields become empty lists, `''`, `null` or `false`
|
|
448
|
+
* - diagnostics only: conversions never query it
|
|
449
|
+
*/
|
|
450
|
+
export type ServerCapabilities = {
|
|
451
|
+
versions: ServerVersions;
|
|
452
|
+
stages: Record<string, CapabilityStage>;
|
|
453
|
+
sources: string[];
|
|
454
|
+
targets: {
|
|
455
|
+
allowed: string[];
|
|
456
|
+
default: string;
|
|
457
|
+
};
|
|
458
|
+
outputFormats: string[];
|
|
459
|
+
imageExportModes: string[];
|
|
460
|
+
limits: CapabilityLimits;
|
|
461
|
+
features: {
|
|
462
|
+
apiKeyRequired: boolean;
|
|
463
|
+
artifactStorage: boolean;
|
|
464
|
+
websocket: boolean;
|
|
465
|
+
};
|
|
466
|
+
};
|
|
467
|
+
|
|
468
|
+
// Client
|
|
347
469
|
|
|
348
470
|
/** Configuration passed to `createDoclingClient`. */
|
|
349
471
|
export type DoclingConfig = {
|
|
350
|
-
/** docling-serve base URL, e.g. `'http://127.0.0.1:5001'`; trailing `/`
|
|
472
|
+
/** docling-serve base URL, e.g. `'http://127.0.0.1:5001'`; trailing `/` removed; no query, fragment, or credentials. */
|
|
351
473
|
baseUrl: string;
|
|
352
474
|
/** Sent as `X-Api-Key` header. */
|
|
353
475
|
apiKey?: string;
|
|
354
|
-
/**
|
|
476
|
+
/** Time limit per request in ms (integer `1..2147483647`, excludes `/version`); resolves to `aborted` on expiry. */
|
|
355
477
|
timeoutMs?: number;
|
|
478
|
+
/** Delay between job helper status polls in ms (integer `1..2147483647`). Default `10`. */
|
|
479
|
+
pollMs?: number;
|
|
356
480
|
/** Custom fetch implementation for mocking or custom dispatchers. */
|
|
357
481
|
fetch?: typeof fetch;
|
|
358
482
|
/** Defaults for every call; call options override them key by key, except the factory-only ones. */
|
|
@@ -360,28 +484,65 @@ export type DoclingConfig = {
|
|
|
360
484
|
};
|
|
361
485
|
|
|
362
486
|
/**
|
|
363
|
-
* **docling-serve client
|
|
487
|
+
* **docling-serve client**: every call returns a Promise.
|
|
364
488
|
*
|
|
365
|
-
* - `convert
|
|
366
|
-
*
|
|
489
|
+
* - single request (`convert*`): one HTTP request to sync endpoint; answers on `DOCLING_SERVE_SYNC_POLL_INTERVAL`
|
|
490
|
+
* ticks (default 2 s) and returns 504 after `DOCLING_SERVE_MAX_SYNC_WAIT`
|
|
491
|
+
* - job (`submit*` + `check`): async endpoints; caller stores job and polls
|
|
492
|
+
* - job helper (`run*`, `waitForJob`): submits or takes a job and polls every `pollMs` until done
|
|
367
493
|
*/
|
|
368
494
|
export type DoclingClient = {
|
|
369
495
|
/** PDF or image to docling's md; images as placeholders, removed or extracted. */
|
|
370
|
-
convertMarkdown(input: ConvertInput, options?: MarkdownOptions): Promise<Result<ConvertedMarkdown
|
|
496
|
+
convertMarkdown(input: ConvertInput, options?: MarkdownOptions): Promise<Result<WithSettings<ConvertedMarkdown>>>;
|
|
371
497
|
/** PDF or image to docling's DoclingDocument. */
|
|
372
|
-
convertDocument(input: ConvertInput, options?: DocumentOptions): Promise<Result<ConvertedDocument
|
|
373
|
-
/** Starts an async md conversion. */
|
|
498
|
+
convertDocument(input: ConvertInput, options?: DocumentOptions): Promise<Result<WithSettings<ConvertedDocument>>>;
|
|
499
|
+
/** Starts an async md conversion; the job carries the sent settings. */
|
|
374
500
|
submitMarkdown(input: ConvertInput, options?: MarkdownOptions): Promise<Result<MarkdownJob>>;
|
|
375
|
-
/** Starts an async document conversion. */
|
|
501
|
+
/** Starts an async document conversion; the job carries the sent settings. */
|
|
376
502
|
submitDocument(input: ConvertInput, options?: DocumentOptions): Promise<Result<DocumentJob>>;
|
|
377
503
|
/**
|
|
378
504
|
* **Polls a job; fetches its result once done**.
|
|
379
505
|
*
|
|
380
|
-
* - docling-serve deletes
|
|
381
|
-
* fetch: a `check` whose result download failed can be repeated within that
|
|
382
|
-
* `not_found
|
|
506
|
+
* - docling-serve deletes the task `DOCLING_SERVE_RESULT_REMOVAL_DELAY` seconds (default 300) after first
|
|
507
|
+
* result fetch: a `check` whose result download failed can be repeated within that window, later returning
|
|
508
|
+
* `not_found` (`Unknown job id`); persist `done` data, or set `DOCLING_SERVE_SINGLE_USE_RESULTS=false`
|
|
509
|
+
* - `done` carries no settings (stored on the job)
|
|
510
|
+
*/
|
|
511
|
+
check(job: Omit<MarkdownJob, 'settings'>, options?: CallOptions): Promise<Result<JobState<ConvertedMarkdown>>>;
|
|
512
|
+
check(job: Omit<DocumentJob, 'settings'>, options?: CallOptions): Promise<Result<JobState<ConvertedDocument>>>;
|
|
513
|
+
check(job: JobRef, options?: CallOptions): Promise<Result<JobState<ConvertedMarkdown | ConvertedDocument>>>;
|
|
514
|
+
/**
|
|
515
|
+
* **Submits an md job and polls every `pollMs` until done**: same result as `convertMarkdown`.
|
|
516
|
+
*
|
|
517
|
+
* - `signal` covers submit, status polls, and waits; `timeoutMs` limits each HTTP request
|
|
518
|
+
* - first error ends call; job never returned (use `submitMarkdown` + `waitForJob` to keep it)
|
|
519
|
+
* - aborting does not cancel the server-side job
|
|
520
|
+
*/
|
|
521
|
+
runMarkdown(
|
|
522
|
+
input: ConvertInput,
|
|
523
|
+
options?: MarkdownOptions & PollOptions,
|
|
524
|
+
): Promise<Result<WithSettings<ConvertedMarkdown>>>;
|
|
525
|
+
/**
|
|
526
|
+
* **Submits a document job and polls every `pollMs` until done**: same result as `convertDocument`.
|
|
527
|
+
*
|
|
528
|
+
* - `signal` covers submit, status polls, and waits; `timeoutMs` limits each HTTP request
|
|
529
|
+
* - first error ends call; job never returned (use `submitDocument` + `waitForJob` to keep it)
|
|
530
|
+
* - aborting does not cancel the server-side job
|
|
531
|
+
*/
|
|
532
|
+
runDocument(
|
|
533
|
+
input: ConvertInput,
|
|
534
|
+
options?: DocumentOptions & PollOptions,
|
|
535
|
+
): Promise<Result<WithSettings<ConvertedDocument>>>;
|
|
536
|
+
/**
|
|
537
|
+
* **Polls an existing job every `pollMs` until done**.
|
|
538
|
+
*
|
|
539
|
+
* - first status poll runs immediately; already-finished jobs cost one `check`
|
|
540
|
+
* - resolves to `check`'s `done` data without `status`; first error ends call
|
|
541
|
+
* - repeatable after a failed result download within `DOCLING_SERVE_RESULT_REMOVAL_DELAY` (default 300 s)
|
|
383
542
|
*/
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
543
|
+
waitForJob(job: Omit<MarkdownJob, 'settings'>, options?: PollOptions): Promise<Result<ConvertedMarkdown>>;
|
|
544
|
+
waitForJob(job: Omit<DocumentJob, 'settings'>, options?: PollOptions): Promise<Result<ConvertedDocument>>;
|
|
545
|
+
waitForJob(job: JobRef, options?: PollOptions): Promise<Result<ConvertedMarkdown | ConvertedDocument>>;
|
|
546
|
+
/** Installed presets, limits and features of the server; on demand only, never used by conversions. */
|
|
547
|
+
capabilities(options?: CallOptions): Promise<Result<ServerCapabilities>>;
|
|
387
548
|
};
|