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/dist/types.d.ts
CHANGED
|
@@ -88,12 +88,22 @@ export type ServerVersions = Record<string, string>;
|
|
|
88
88
|
* - anything else is `invalid_input`
|
|
89
89
|
*/
|
|
90
90
|
export type ConvertInput = Uint8Array;
|
|
91
|
-
/**
|
|
91
|
+
/**
|
|
92
|
+
* Use `ConvertInput`; images are accepted as well.
|
|
93
|
+
* @deprecated
|
|
94
|
+
*/
|
|
92
95
|
export type PdfInput = ConvertInput;
|
|
93
96
|
/** Supported conversion pipeline backend. */
|
|
94
97
|
export type Pipeline = 'standard' | 'vlm';
|
|
95
98
|
/** PDF text extraction backend used by docling. */
|
|
96
99
|
export type PdfBackend = 'docling_parse' | 'pypdfium2';
|
|
100
|
+
/**
|
|
101
|
+
* **OCR engine preset sent as `ocr_preset`**.
|
|
102
|
+
*
|
|
103
|
+
* - known engines autocomplete; any other non-empty preset id is accepted and sent as is
|
|
104
|
+
* - installed engines: `stages.ocr.presets` of `client.capabilities()`
|
|
105
|
+
*/
|
|
106
|
+
export type OcrEngine = 'auto' | 'rapidocr' | 'easyocr' | 'tesseract' | 'tesserocr' | 'ocrmac' | (string & {});
|
|
97
107
|
/** docling conversion options; set as factory defaults and/or per call. */
|
|
98
108
|
export type DoclingOptions = {
|
|
99
109
|
/** Nests headings by bookmarks, numbering, and font style; without it every heading has level 1. Default `true`. */
|
|
@@ -120,6 +130,8 @@ export type DoclingOptions = {
|
|
|
120
130
|
* - ignored for image input: it has no text layer, and full-page OCR there merges words (`stepsand`)
|
|
121
131
|
*/
|
|
122
132
|
forceOcr?: boolean;
|
|
133
|
+
/** OCR engine preset (`ocr_preset`); an engine the server lacks fails the conversion. Default `'auto'`. */
|
|
134
|
+
ocrEngine?: OcrEngine;
|
|
123
135
|
};
|
|
124
136
|
/** docling options of the factory: every per-call option plus the factory-only ones, applied to every call. */
|
|
125
137
|
export type ClientOptions = DoclingOptions & {
|
|
@@ -266,6 +278,50 @@ export type ConvertedDocument = {
|
|
|
266
278
|
/** Server versions that produced the output; `null` if the server omitted them. */
|
|
267
279
|
versions: ServerVersions | null;
|
|
268
280
|
};
|
|
281
|
+
/**
|
|
282
|
+
* **Conversion settings exactly as sent in the multipart request**.
|
|
283
|
+
*
|
|
284
|
+
* - every key is the camelCase name of a docling-serve form field (`ocrPreset` = `ocr_preset`)
|
|
285
|
+
* - `null`: field not sent (md-only fields of json output, unused presets, unset factory options)
|
|
286
|
+
* - `ocrLang`: empty means not sent, i.e. engine default
|
|
287
|
+
* - server-side configuration not covered by request fields (e.g. layout model) is not included
|
|
288
|
+
*/
|
|
289
|
+
export type DoclingSettings = {
|
|
290
|
+
fromFormats: 'pdf' | 'image';
|
|
291
|
+
toFormats: 'md' | 'json';
|
|
292
|
+
imageExportMode: 'embedded' | 'placeholder';
|
|
293
|
+
includeImages: boolean;
|
|
294
|
+
includePageImages: boolean;
|
|
295
|
+
imagesScale: number;
|
|
296
|
+
mdCompactTables: boolean | null;
|
|
297
|
+
mdPageBreakPlaceholder: string | null;
|
|
298
|
+
doOcr: boolean;
|
|
299
|
+
forceOcr: boolean;
|
|
300
|
+
ocrPreset: string;
|
|
301
|
+
ocrLang: string[];
|
|
302
|
+
pdfBackend: PdfBackend;
|
|
303
|
+
pipeline: Pipeline;
|
|
304
|
+
vlmPipelinePreset: string | null;
|
|
305
|
+
doTableStructure: boolean;
|
|
306
|
+
tableMode: 'accurate';
|
|
307
|
+
tableStructurePreset: string;
|
|
308
|
+
tableCellMatching: boolean;
|
|
309
|
+
doPdfHeadingHierarchy: boolean;
|
|
310
|
+
doFormulaEnrichment: boolean;
|
|
311
|
+
doCodeEnrichment: boolean;
|
|
312
|
+
codeFormulaPreset: string | null;
|
|
313
|
+
doChartExtraction: boolean;
|
|
314
|
+
chartExtractionPreset: string | null;
|
|
315
|
+
doPictureClassification: boolean;
|
|
316
|
+
doPictureDescription: boolean;
|
|
317
|
+
pageRange: [from: number, to: number] | null;
|
|
318
|
+
documentTimeout: number | null;
|
|
319
|
+
abortOnError: boolean;
|
|
320
|
+
};
|
|
321
|
+
/** Sync conversion result plus the settings sent with its request. */
|
|
322
|
+
export type WithSettings<T> = T & {
|
|
323
|
+
settings: DoclingSettings;
|
|
324
|
+
};
|
|
269
325
|
/** Image handling of a md job, applied when `check()` picks up the result. */
|
|
270
326
|
export type MarkdownJobOutput = {
|
|
271
327
|
images: 'extract';
|
|
@@ -279,15 +335,21 @@ export type MarkdownJob = {
|
|
|
279
335
|
/** Server-side task id. */
|
|
280
336
|
id: string;
|
|
281
337
|
output: MarkdownJobOutput;
|
|
338
|
+
/** Settings sent with the submission; `check()` neither needs nor returns them. */
|
|
339
|
+
settings: DoclingSettings;
|
|
282
340
|
};
|
|
283
341
|
/** Handle of a document conversion, returned by `submitDocument()`; plain JSON, safe to store. */
|
|
284
342
|
export type DocumentJob = {
|
|
285
343
|
kind: 'document';
|
|
286
344
|
/** Server-side task id. */
|
|
287
345
|
id: string;
|
|
346
|
+
/** Settings sent with the submission; `check()` neither needs nor returns them. */
|
|
347
|
+
settings: DoclingSettings;
|
|
288
348
|
};
|
|
289
|
-
/** Any job handle
|
|
349
|
+
/** Any job handle returned by `submit*()`. */
|
|
290
350
|
export type Job = MarkdownJob | DocumentJob;
|
|
351
|
+
/** Job handle accepted by `check()`; `settings` may be dropped when storing the job. */
|
|
352
|
+
export type JobRef = Omit<MarkdownJob, 'settings'> | Omit<DocumentJob, 'settings'>;
|
|
291
353
|
/** State of an async job; `done` carries the conversion result. */
|
|
292
354
|
export type JobState<T> =
|
|
293
355
|
/** Pending in server queue; `position` is 1-based when reported by server. */
|
|
@@ -303,6 +365,55 @@ export type JobState<T> =
|
|
|
303
365
|
| ({
|
|
304
366
|
status: 'done';
|
|
305
367
|
} & T);
|
|
368
|
+
/** Model or engine preset a pipeline stage offers; `id` is the value of the stage's form field. */
|
|
369
|
+
export type CapabilityPreset = {
|
|
370
|
+
id: string;
|
|
371
|
+
name: string;
|
|
372
|
+
description: string | null;
|
|
373
|
+
/** Origin, e.g. `'docling'` or `'default'` (server default alias). */
|
|
374
|
+
source: string;
|
|
375
|
+
};
|
|
376
|
+
/** Pipeline stage (OCR, table structure, VLM, ...) with its form field and installed presets. */
|
|
377
|
+
export type CapabilityStage = {
|
|
378
|
+
/** Form field selecting the preset, e.g. `'ocr_preset'`. */
|
|
379
|
+
option: string;
|
|
380
|
+
customConfigOption: string | null;
|
|
381
|
+
/** Preset used when the field is not sent. */
|
|
382
|
+
default: string;
|
|
383
|
+
presets: CapabilityPreset[];
|
|
384
|
+
};
|
|
385
|
+
/** Server limits; `null` means unlimited or not reported. */
|
|
386
|
+
export type CapabilityLimits = {
|
|
387
|
+
maxDocumentTimeout: number | null;
|
|
388
|
+
maxImagesScale: number | null;
|
|
389
|
+
maxSourcesPerRequest: number | null;
|
|
390
|
+
maxNumPages: number | null;
|
|
391
|
+
maxFileSize: number | null;
|
|
392
|
+
};
|
|
393
|
+
/**
|
|
394
|
+
* **What the docling-serve instance offers (`GET /v1/capabilities`)**.
|
|
395
|
+
*
|
|
396
|
+
* - snake_case keys of the server payload converted to camelCase; `stages` keys stay as sent (e.g. `table_structure`)
|
|
397
|
+
* - missing or mistyped fields become empty lists, `''`, `null` or `false`
|
|
398
|
+
* - diagnostics only: conversions never query it
|
|
399
|
+
*/
|
|
400
|
+
export type ServerCapabilities = {
|
|
401
|
+
versions: ServerVersions;
|
|
402
|
+
stages: Record<string, CapabilityStage>;
|
|
403
|
+
sources: string[];
|
|
404
|
+
targets: {
|
|
405
|
+
allowed: string[];
|
|
406
|
+
default: string;
|
|
407
|
+
};
|
|
408
|
+
outputFormats: string[];
|
|
409
|
+
imageExportModes: string[];
|
|
410
|
+
limits: CapabilityLimits;
|
|
411
|
+
features: {
|
|
412
|
+
apiKeyRequired: boolean;
|
|
413
|
+
artifactStorage: boolean;
|
|
414
|
+
websocket: boolean;
|
|
415
|
+
};
|
|
416
|
+
};
|
|
306
417
|
/** Configuration passed to `createDoclingClient`. */
|
|
307
418
|
export type DoclingConfig = {
|
|
308
419
|
/** docling-serve base URL, e.g. `'http://127.0.0.1:5001'`; trailing `/` are removed. */
|
|
@@ -324,12 +435,12 @@ export type DoclingConfig = {
|
|
|
324
435
|
*/
|
|
325
436
|
export type DoclingClient = {
|
|
326
437
|
/** PDF or image to docling's md; images as placeholders, removed or extracted. */
|
|
327
|
-
convertMarkdown(input: ConvertInput, options?: MarkdownOptions): Promise<Result<ConvertedMarkdown
|
|
438
|
+
convertMarkdown(input: ConvertInput, options?: MarkdownOptions): Promise<Result<WithSettings<ConvertedMarkdown>>>;
|
|
328
439
|
/** PDF or image to docling's DoclingDocument. */
|
|
329
|
-
convertDocument(input: ConvertInput, options?: DocumentOptions): Promise<Result<ConvertedDocument
|
|
330
|
-
/** Starts an async md conversion. */
|
|
440
|
+
convertDocument(input: ConvertInput, options?: DocumentOptions): Promise<Result<WithSettings<ConvertedDocument>>>;
|
|
441
|
+
/** Starts an async md conversion; the job carries the sent settings. */
|
|
331
442
|
submitMarkdown(input: ConvertInput, options?: MarkdownOptions): Promise<Result<MarkdownJob>>;
|
|
332
|
-
/** Starts an async document conversion. */
|
|
443
|
+
/** Starts an async document conversion; the job carries the sent settings. */
|
|
333
444
|
submitDocument(input: ConvertInput, options?: DocumentOptions): Promise<Result<DocumentJob>>;
|
|
334
445
|
/**
|
|
335
446
|
* **Polls a job; fetches its result once done**.
|
|
@@ -337,9 +448,12 @@ export type DoclingClient = {
|
|
|
337
448
|
* - docling-serve deletes a result `DOCLING_SERVE_RESULT_REMOVAL_DELAY` seconds (default 300) after its first
|
|
338
449
|
* fetch: a `check` whose result download failed can be repeated within that time, later it returns
|
|
339
450
|
* `not_found`; persist `done` data, or start docling-serve with `DOCLING_SERVE_SINGLE_USE_RESULTS=false`
|
|
451
|
+
* - `done` carries no settings: they are on the job
|
|
340
452
|
*/
|
|
341
|
-
check(job: MarkdownJob, options?: CallOptions): Promise<Result<JobState<ConvertedMarkdown>>>;
|
|
342
|
-
check(job: DocumentJob, options?: CallOptions): Promise<Result<JobState<ConvertedDocument>>>;
|
|
343
|
-
check(job:
|
|
453
|
+
check(job: Omit<MarkdownJob, 'settings'>, options?: CallOptions): Promise<Result<JobState<ConvertedMarkdown>>>;
|
|
454
|
+
check(job: Omit<DocumentJob, 'settings'>, options?: CallOptions): Promise<Result<JobState<ConvertedDocument>>>;
|
|
455
|
+
check(job: JobRef, options?: CallOptions): Promise<Result<JobState<ConvertedMarkdown | ConvertedDocument>>>;
|
|
456
|
+
/** Installed presets, limits and features of the server; on demand only, never used by conversions. */
|
|
457
|
+
capabilities(options?: CallOptions): Promise<Result<ServerCapabilities>>;
|
|
344
458
|
};
|
|
345
459
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRo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CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC;IAC/G,KAAK,CAAC,GAAG,EAAE,IAAI,CAAC,WAAW,EAAE,UAAU,CAAC,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC;IAC/G,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,iBAAiB,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAAC;IAC5G,uGAAuG;IACvG,YAAY,CAAC,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC,CAAC;CAC5E,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "docling-serve-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Typed docling-serve client: PDF to docling Markdown or DoclingDocument JSON, sync and async. In-memory, zero-dependency, never throws.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pdf",
|
|
@@ -66,9 +66,9 @@
|
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
68
|
"@arethetypeswrong/cli": "^0.18.5",
|
|
69
|
-
"@biomejs/biome": "2.5.
|
|
70
|
-
"@types/bun": "^1.4.
|
|
71
|
-
"@types/node": "^22.
|
|
69
|
+
"@biomejs/biome": "2.5.15",
|
|
70
|
+
"@types/bun": "^1.4.3",
|
|
71
|
+
"@types/node": "^22.20.5",
|
|
72
72
|
"bun-test-runner": "latest",
|
|
73
73
|
"smartin": "latest",
|
|
74
74
|
"typescript": "^7.0.2"
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// Copyright 2026 Martin Winkler
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { ERR, fail, ok } from './core/result.js';
|
|
5
|
+
import { isPlainObject } from './core/validate.js';
|
|
6
|
+
import type { CapabilityLimits, CapabilityPreset, CapabilityStage, Result, ServerCapabilities } from './types.js';
|
|
7
|
+
|
|
8
|
+
// -------------------------------------------------------------------
|
|
9
|
+
// --- 1. Types
|
|
10
|
+
// -------------------------------------------------------------------
|
|
11
|
+
|
|
12
|
+
/** Loosely read JSON object; every field is checked before use. */
|
|
13
|
+
type JsonObject = Record<string, unknown>;
|
|
14
|
+
|
|
15
|
+
// -------------------------------------------------------------------
|
|
16
|
+
// --- 2. Exported Functions
|
|
17
|
+
// -------------------------------------------------------------------
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* **Maps the `GET /v1/capabilities` payload to camelCase `ServerCapabilities`**.
|
|
21
|
+
*
|
|
22
|
+
* - lenient per field: missing or mistyped values become `[]`, `''`, `null` or `false`, so new server fields or
|
|
23
|
+
* removed ones never fail the call
|
|
24
|
+
* - non-object body: `invalid_response`
|
|
25
|
+
*/
|
|
26
|
+
export function readCapabilities(body: unknown): Result<ServerCapabilities> {
|
|
27
|
+
if (!isPlainObject(body)) {
|
|
28
|
+
return fail(ERR.INVALID_RESPONSE('Capabilities response is not a JSON object'));
|
|
29
|
+
}
|
|
30
|
+
const targets = objectOf(body.targets);
|
|
31
|
+
const features = objectOf(body.features);
|
|
32
|
+
return ok({
|
|
33
|
+
versions: Object.fromEntries(
|
|
34
|
+
Object.entries(objectOf(body.versions)).filter(
|
|
35
|
+
(entry): entry is [string, string] => typeof entry[1] === 'string',
|
|
36
|
+
),
|
|
37
|
+
),
|
|
38
|
+
stages: Object.fromEntries(
|
|
39
|
+
Object.entries(objectOf(body.stages)).map(([name, stage]) => [name, readStage(objectOf(stage))]),
|
|
40
|
+
),
|
|
41
|
+
sources: stringsOf(body.sources),
|
|
42
|
+
targets: { allowed: stringsOf(targets.allowed), default: stringOf(targets.default) },
|
|
43
|
+
outputFormats: stringsOf(body.output_formats),
|
|
44
|
+
imageExportModes: stringsOf(body.image_export_modes),
|
|
45
|
+
limits: readLimits(objectOf(body.limits)),
|
|
46
|
+
features: {
|
|
47
|
+
apiKeyRequired: features.api_key_required === true,
|
|
48
|
+
artifactStorage: features.artifact_storage === true,
|
|
49
|
+
websocket: features.websocket === true,
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// -------------------------------------------------------------------
|
|
55
|
+
// --- 3. Internal Functions
|
|
56
|
+
// -------------------------------------------------------------------
|
|
57
|
+
|
|
58
|
+
/** Pipeline stage; presets without a string `id` are dropped. */
|
|
59
|
+
function readStage(stage: JsonObject): CapabilityStage {
|
|
60
|
+
const presets: CapabilityPreset[] = [];
|
|
61
|
+
for (const item of Array.isArray(stage.presets) ? stage.presets : []) {
|
|
62
|
+
const preset = objectOf(item);
|
|
63
|
+
if (typeof preset.id === 'string') {
|
|
64
|
+
presets.push({
|
|
65
|
+
id: preset.id,
|
|
66
|
+
name: stringOf(preset.name),
|
|
67
|
+
description: typeof preset.description === 'string' ? preset.description : null,
|
|
68
|
+
source: stringOf(preset.source),
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
option: stringOf(stage.option),
|
|
74
|
+
customConfigOption: typeof stage.custom_config_option === 'string' ? stage.custom_config_option : null,
|
|
75
|
+
default: stringOf(stage.default),
|
|
76
|
+
presets,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Server limits; non-numbers become `null`. */
|
|
81
|
+
function readLimits(limits: JsonObject): CapabilityLimits {
|
|
82
|
+
return {
|
|
83
|
+
maxDocumentTimeout: numberOf(limits.max_document_timeout),
|
|
84
|
+
maxImagesScale: numberOf(limits.max_images_scale),
|
|
85
|
+
maxSourcesPerRequest: numberOf(limits.max_sources_per_request),
|
|
86
|
+
maxNumPages: numberOf(limits.max_num_pages),
|
|
87
|
+
maxFileSize: numberOf(limits.max_file_size),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Plain object, or `{}` for anything else. */
|
|
92
|
+
function objectOf(value: unknown): JsonObject {
|
|
93
|
+
return isPlainObject(value) ? value : {};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** String entries of an array; `[]` for a non-array. */
|
|
97
|
+
function stringsOf(value: unknown): string[] {
|
|
98
|
+
return Array.isArray(value) ? value.filter((item): item is string => typeof item === 'string') : [];
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** String, or `''` for anything else. */
|
|
102
|
+
function stringOf(value: unknown): string {
|
|
103
|
+
return typeof value === 'string' ? value : '';
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** Finite number, or `null` for anything else. */
|
|
107
|
+
function numberOf(value: unknown): number | null {
|
|
108
|
+
return typeof value === 'number' && Number.isFinite(value) ? value : null;
|
|
109
|
+
}
|