docling-serve-client 0.4.0 → 0.5.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 +270 -29
- package/dist/capabilities.d.ts +10 -0
- package/dist/capabilities.d.ts.map +1 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/core/input.d.ts +1 -1
- package/dist/core/pdf.d.ts +2 -2
- package/dist/core/validate.d.ts +2 -2
- package/dist/core/validate.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 +146 -52
- package/dist/index.js.map +11 -10
- package/dist/options.d.ts +15 -5
- package/dist/options.d.ts.map +1 -1
- package/dist/types.d.ts +123 -9
- package/dist/types.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/capabilities.ts +109 -0
- package/src/client.ts +132 -65
- package/src/core/input.ts +3 -3
- package/src/core/pdf.ts +2 -2
- package/src/core/validate.ts +2 -2
- package/src/images.ts +4 -4
- package/src/index.ts +8 -0
- package/src/options.ts +23 -7
- package/src/response.ts +1 -1
- package/src/types.ts +136 -10
package/src/types.ts
CHANGED
|
@@ -103,7 +103,10 @@ export type ServerVersions = Record<string, string>;
|
|
|
103
103
|
*/
|
|
104
104
|
export type ConvertInput = Uint8Array;
|
|
105
105
|
|
|
106
|
-
/**
|
|
106
|
+
/**
|
|
107
|
+
* Use `ConvertInput`; images are accepted as well.
|
|
108
|
+
* @deprecated
|
|
109
|
+
*/
|
|
107
110
|
export type PdfInput = ConvertInput;
|
|
108
111
|
|
|
109
112
|
/** Supported conversion pipeline backend. */
|
|
@@ -112,6 +115,14 @@ export type Pipeline = 'standard' | 'vlm';
|
|
|
112
115
|
/** PDF text extraction backend used by docling. */
|
|
113
116
|
export type PdfBackend = 'docling_parse' | 'pypdfium2';
|
|
114
117
|
|
|
118
|
+
/**
|
|
119
|
+
* **OCR engine preset sent as `ocr_preset`**.
|
|
120
|
+
*
|
|
121
|
+
* - known engines autocomplete; any other non-empty preset id is accepted and sent as is
|
|
122
|
+
* - installed engines: `stages.ocr.presets` of `client.capabilities()`
|
|
123
|
+
*/
|
|
124
|
+
export type OcrEngine = 'auto' | 'rapidocr' | 'easyocr' | 'tesseract' | 'tesserocr' | 'ocrmac' | (string & {});
|
|
125
|
+
|
|
115
126
|
/** docling conversion options; set as factory defaults and/or per call. */
|
|
116
127
|
export type DoclingOptions = {
|
|
117
128
|
/** Nests headings by bookmarks, numbering, and font style; without it every heading has level 1. Default `true`. */
|
|
@@ -138,6 +149,8 @@ export type DoclingOptions = {
|
|
|
138
149
|
* - ignored for image input: it has no text layer, and full-page OCR there merges words (`stepsand`)
|
|
139
150
|
*/
|
|
140
151
|
forceOcr?: boolean;
|
|
152
|
+
/** OCR engine preset (`ocr_preset`); an engine the server lacks fails the conversion. Default `'auto'`. */
|
|
153
|
+
ocrEngine?: OcrEngine;
|
|
141
154
|
};
|
|
142
155
|
|
|
143
156
|
/** docling options of the factory: every per-call option plus the factory-only ones, applied to every call. */
|
|
@@ -305,6 +318,52 @@ export type ConvertedDocument = {
|
|
|
305
318
|
versions: ServerVersions | null;
|
|
306
319
|
};
|
|
307
320
|
|
|
321
|
+
/**
|
|
322
|
+
* **Conversion settings exactly as sent in the multipart request**.
|
|
323
|
+
*
|
|
324
|
+
* - every key is the camelCase name of a docling-serve form field (`ocrPreset` = `ocr_preset`)
|
|
325
|
+
* - `null`: field not sent (md-only fields of json output, unused presets, unset factory options)
|
|
326
|
+
* - `ocrLang`: empty means not sent, i.e. engine default
|
|
327
|
+
* - server-side configuration not covered by request fields (e.g. layout model) is not included
|
|
328
|
+
*/
|
|
329
|
+
export type DoclingSettings = {
|
|
330
|
+
fromFormats: 'pdf' | 'image';
|
|
331
|
+
toFormats: 'md' | 'json';
|
|
332
|
+
imageExportMode: 'embedded' | 'placeholder';
|
|
333
|
+
includeImages: boolean;
|
|
334
|
+
includePageImages: boolean;
|
|
335
|
+
imagesScale: number;
|
|
336
|
+
mdCompactTables: boolean | null;
|
|
337
|
+
mdPageBreakPlaceholder: string | null;
|
|
338
|
+
doOcr: boolean;
|
|
339
|
+
forceOcr: boolean;
|
|
340
|
+
ocrPreset: string;
|
|
341
|
+
ocrLang: string[];
|
|
342
|
+
pdfBackend: PdfBackend;
|
|
343
|
+
pipeline: Pipeline;
|
|
344
|
+
vlmPipelinePreset: string | null;
|
|
345
|
+
doTableStructure: boolean;
|
|
346
|
+
tableMode: 'accurate';
|
|
347
|
+
tableStructurePreset: string;
|
|
348
|
+
tableCellMatching: boolean;
|
|
349
|
+
doPdfHeadingHierarchy: boolean;
|
|
350
|
+
doFormulaEnrichment: boolean;
|
|
351
|
+
doCodeEnrichment: boolean;
|
|
352
|
+
codeFormulaPreset: string | null;
|
|
353
|
+
doChartExtraction: boolean;
|
|
354
|
+
chartExtractionPreset: string | null;
|
|
355
|
+
doPictureClassification: boolean;
|
|
356
|
+
doPictureDescription: boolean;
|
|
357
|
+
pageRange: [from: number, to: number] | null;
|
|
358
|
+
documentTimeout: number | null;
|
|
359
|
+
abortOnError: boolean;
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
/** Sync conversion result plus the settings sent with its request. */
|
|
363
|
+
export type WithSettings<T> = T & {
|
|
364
|
+
settings: DoclingSettings;
|
|
365
|
+
};
|
|
366
|
+
|
|
308
367
|
// -------------------------------------------------------------------
|
|
309
368
|
// --- 4. Asynchronous Jobs
|
|
310
369
|
// -------------------------------------------------------------------
|
|
@@ -320,6 +379,8 @@ export type MarkdownJob = {
|
|
|
320
379
|
/** Server-side task id. */
|
|
321
380
|
id: string;
|
|
322
381
|
output: MarkdownJobOutput;
|
|
382
|
+
/** Settings sent with the submission; `check()` neither needs nor returns them. */
|
|
383
|
+
settings: DoclingSettings;
|
|
323
384
|
};
|
|
324
385
|
|
|
325
386
|
/** Handle of a document conversion, returned by `submitDocument()`; plain JSON, safe to store. */
|
|
@@ -327,11 +388,16 @@ export type DocumentJob = {
|
|
|
327
388
|
kind: 'document';
|
|
328
389
|
/** Server-side task id. */
|
|
329
390
|
id: string;
|
|
391
|
+
/** Settings sent with the submission; `check()` neither needs nor returns them. */
|
|
392
|
+
settings: DoclingSettings;
|
|
330
393
|
};
|
|
331
394
|
|
|
332
|
-
/** Any job handle
|
|
395
|
+
/** Any job handle returned by `submit*()`. */
|
|
333
396
|
export type Job = MarkdownJob | DocumentJob;
|
|
334
397
|
|
|
398
|
+
/** Job handle accepted by `check()`; `settings` may be dropped when storing the job. */
|
|
399
|
+
export type JobRef = Omit<MarkdownJob, 'settings'> | Omit<DocumentJob, 'settings'>;
|
|
400
|
+
|
|
335
401
|
/** State of an async job; `done` carries the conversion result. */
|
|
336
402
|
export type JobState<T> =
|
|
337
403
|
/** Pending in server queue; `position` is 1-based when reported by server. */
|
|
@@ -342,7 +408,64 @@ export type JobState<T> =
|
|
|
342
408
|
| ({ status: 'done' } & T);
|
|
343
409
|
|
|
344
410
|
// -------------------------------------------------------------------
|
|
345
|
-
// --- 5.
|
|
411
|
+
// --- 5. Server Capabilities
|
|
412
|
+
// -------------------------------------------------------------------
|
|
413
|
+
|
|
414
|
+
/** Model or engine preset a pipeline stage offers; `id` is the value of the stage's form field. */
|
|
415
|
+
export type CapabilityPreset = {
|
|
416
|
+
id: string;
|
|
417
|
+
name: string;
|
|
418
|
+
description: string | null;
|
|
419
|
+
/** Origin, e.g. `'docling'` or `'default'` (server default alias). */
|
|
420
|
+
source: string;
|
|
421
|
+
};
|
|
422
|
+
|
|
423
|
+
/** Pipeline stage (OCR, table structure, VLM, ...) with its form field and installed presets. */
|
|
424
|
+
export type CapabilityStage = {
|
|
425
|
+
/** Form field selecting the preset, e.g. `'ocr_preset'`. */
|
|
426
|
+
option: string;
|
|
427
|
+
customConfigOption: string | null;
|
|
428
|
+
/** Preset used when the field is not sent. */
|
|
429
|
+
default: string;
|
|
430
|
+
presets: CapabilityPreset[];
|
|
431
|
+
};
|
|
432
|
+
|
|
433
|
+
/** Server limits; `null` means unlimited or not reported. */
|
|
434
|
+
export type CapabilityLimits = {
|
|
435
|
+
maxDocumentTimeout: number | null;
|
|
436
|
+
maxImagesScale: number | null;
|
|
437
|
+
maxSourcesPerRequest: number | null;
|
|
438
|
+
maxNumPages: number | null;
|
|
439
|
+
maxFileSize: number | null;
|
|
440
|
+
};
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* **What the docling-serve instance offers (`GET /v1/capabilities`)**.
|
|
444
|
+
*
|
|
445
|
+
* - snake_case keys of the server payload converted to camelCase; `stages` keys stay as sent (e.g. `table_structure`)
|
|
446
|
+
* - missing or mistyped fields become empty lists, `''`, `null` or `false`
|
|
447
|
+
* - diagnostics only: conversions never query it
|
|
448
|
+
*/
|
|
449
|
+
export type ServerCapabilities = {
|
|
450
|
+
versions: ServerVersions;
|
|
451
|
+
stages: Record<string, CapabilityStage>;
|
|
452
|
+
sources: string[];
|
|
453
|
+
targets: {
|
|
454
|
+
allowed: string[];
|
|
455
|
+
default: string;
|
|
456
|
+
};
|
|
457
|
+
outputFormats: string[];
|
|
458
|
+
imageExportModes: string[];
|
|
459
|
+
limits: CapabilityLimits;
|
|
460
|
+
features: {
|
|
461
|
+
apiKeyRequired: boolean;
|
|
462
|
+
artifactStorage: boolean;
|
|
463
|
+
websocket: boolean;
|
|
464
|
+
};
|
|
465
|
+
};
|
|
466
|
+
|
|
467
|
+
// -------------------------------------------------------------------
|
|
468
|
+
// --- 6. Client
|
|
346
469
|
// -------------------------------------------------------------------
|
|
347
470
|
|
|
348
471
|
/** Configuration passed to `createDoclingClient`. */
|
|
@@ -367,12 +490,12 @@ export type DoclingConfig = {
|
|
|
367
490
|
*/
|
|
368
491
|
export type DoclingClient = {
|
|
369
492
|
/** PDF or image to docling's md; images as placeholders, removed or extracted. */
|
|
370
|
-
convertMarkdown(input: ConvertInput, options?: MarkdownOptions): Promise<Result<ConvertedMarkdown
|
|
493
|
+
convertMarkdown(input: ConvertInput, options?: MarkdownOptions): Promise<Result<WithSettings<ConvertedMarkdown>>>;
|
|
371
494
|
/** PDF or image to docling's DoclingDocument. */
|
|
372
|
-
convertDocument(input: ConvertInput, options?: DocumentOptions): Promise<Result<ConvertedDocument
|
|
373
|
-
/** Starts an async md conversion. */
|
|
495
|
+
convertDocument(input: ConvertInput, options?: DocumentOptions): Promise<Result<WithSettings<ConvertedDocument>>>;
|
|
496
|
+
/** Starts an async md conversion; the job carries the sent settings. */
|
|
374
497
|
submitMarkdown(input: ConvertInput, options?: MarkdownOptions): Promise<Result<MarkdownJob>>;
|
|
375
|
-
/** Starts an async document conversion. */
|
|
498
|
+
/** Starts an async document conversion; the job carries the sent settings. */
|
|
376
499
|
submitDocument(input: ConvertInput, options?: DocumentOptions): Promise<Result<DocumentJob>>;
|
|
377
500
|
/**
|
|
378
501
|
* **Polls a job; fetches its result once done**.
|
|
@@ -380,8 +503,11 @@ export type DoclingClient = {
|
|
|
380
503
|
* - docling-serve deletes a result `DOCLING_SERVE_RESULT_REMOVAL_DELAY` seconds (default 300) after its first
|
|
381
504
|
* fetch: a `check` whose result download failed can be repeated within that time, later it returns
|
|
382
505
|
* `not_found`; persist `done` data, or start docling-serve with `DOCLING_SERVE_SINGLE_USE_RESULTS=false`
|
|
506
|
+
* - `done` carries no settings: they are on the job
|
|
383
507
|
*/
|
|
384
|
-
check(job: MarkdownJob, options?: CallOptions): Promise<Result<JobState<ConvertedMarkdown>>>;
|
|
385
|
-
check(job: DocumentJob, options?: CallOptions): Promise<Result<JobState<ConvertedDocument>>>;
|
|
386
|
-
check(job:
|
|
508
|
+
check(job: Omit<MarkdownJob, 'settings'>, options?: CallOptions): Promise<Result<JobState<ConvertedMarkdown>>>;
|
|
509
|
+
check(job: Omit<DocumentJob, 'settings'>, options?: CallOptions): Promise<Result<JobState<ConvertedDocument>>>;
|
|
510
|
+
check(job: JobRef, options?: CallOptions): Promise<Result<JobState<ConvertedMarkdown | ConvertedDocument>>>;
|
|
511
|
+
/** Installed presets, limits and features of the server; on demand only, never used by conversions. */
|
|
512
|
+
capabilities(options?: CallOptions): Promise<Result<ServerCapabilities>>;
|
|
387
513
|
};
|