@lumifai/harness-tool-pack-docling 0.1.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 +81 -0
- package/dist/converter.d.ts +33 -0
- package/dist/converter.js +282 -0
- package/dist/converter.js.map +1 -0
- package/dist/docling.d.ts +14 -0
- package/dist/docling.js +97 -0
- package/dist/docling.js.map +1 -0
- package/dist/document-processor.d.ts +69 -0
- package/dist/document-processor.js +208 -0
- package/dist/document-processor.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/package.json +42 -0
- package/skills/docling/SKILL.md +33 -0
package/README.md
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# @lumifai/harness-tool-pack-docling
|
|
2
|
+
|
|
3
|
+
Convert supported workspace files through a user-configured Docling Serve endpoint.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { createDoclingToolPack } from '@lumifai/harness-tool-pack-docling';
|
|
7
|
+
|
|
8
|
+
const doclingPack = createDoclingToolPack({
|
|
9
|
+
serviceUrl: process.env.DOCLING_SERVICE_URL!,
|
|
10
|
+
apiKey: process.env.DOCLING_API_KEY,
|
|
11
|
+
});
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Register the pack with the preset tools:
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
createPresetTools({ packs: [doclingPack] });
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
The pack exposes `process_file`. It reads a file from the workspace, sends it to
|
|
21
|
+
`POST /v1/convert/file`, and writes the selected result to `processed/`.
|
|
22
|
+
Markdown is the default output format; JSON, HTML, text, and doctags are also
|
|
23
|
+
available. Docling automatically determines the input type from the uploaded file.
|
|
24
|
+
|
|
25
|
+
The pack is disabled by default and requires `ask` permission. Configure the
|
|
26
|
+
service URL and credentials when constructing the pack. Credentials are never
|
|
27
|
+
part of the model-visible tool input. Use `headers` for services that require
|
|
28
|
+
authentication other than Docling's `X-Api-Key` header.
|
|
29
|
+
|
|
30
|
+
For broker or parser integrations that already have file bytes, use the shared
|
|
31
|
+
converter API. It sends one Docling request and can return every requested
|
|
32
|
+
representation without writing through the workspace:
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
import { createDoclingConverter } from '@lumifai/harness-tool-pack-docling';
|
|
36
|
+
|
|
37
|
+
const converter = createDoclingConverter({
|
|
38
|
+
serviceUrl: process.env.DOCLING_SERVICE_URL!,
|
|
39
|
+
apiKey: process.env.DOCLING_API_KEY,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const result = await converter.convertFile({
|
|
43
|
+
bytes,
|
|
44
|
+
filename: 'report.pdf',
|
|
45
|
+
mimeType: 'application/pdf',
|
|
46
|
+
outputFormats: ['md', 'json', 'html', 'text', 'doctags'],
|
|
47
|
+
});
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
The converter returns structured JSON content, status, processing time, and
|
|
51
|
+
errors. `process_file` remains the agent-facing wrapper for workspace paths and
|
|
52
|
+
writes one selected representation under `processed/`.
|
|
53
|
+
|
|
54
|
+
For reusable application integrations that need shared defaults, normalization,
|
|
55
|
+
or workspace persistence, use the high-level processor:
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
import { createDoclingDocumentProcessor } from '@lumifai/harness-tool-pack-docling';
|
|
59
|
+
|
|
60
|
+
const processor = createDoclingDocumentProcessor({
|
|
61
|
+
serviceUrl: process.env.DOCLING_SERVICE_URL!,
|
|
62
|
+
apiKey: process.env.DOCLING_API_KEY,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const parsed = await processor.parse({
|
|
66
|
+
filename: 'report.pdf',
|
|
67
|
+
bytes,
|
|
68
|
+
mimeType: 'application/pdf',
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
const workspaceParsed = await processor.parseWorkspaceFile('/uploads/report.pdf', {
|
|
72
|
+
filesystem,
|
|
73
|
+
persistArtifacts: true,
|
|
74
|
+
});
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Programmatic parsing returns `processorId: 'docling'` and defaults to Markdown, JSON, HTML, text, and doctags with
|
|
78
|
+
OCR enabled, accurate tables, the standard pipeline, and placeholder images.
|
|
79
|
+
Callers can override these options per request. Workspace filesystems are
|
|
80
|
+
provided per call, so local, mounted, and object-backed filesystem providers can
|
|
81
|
+
use the same processor.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export type DoclingOutputFormat = 'md' | 'json' | 'html' | 'text' | 'doctags';
|
|
2
|
+
export type DoclingConversionStatus = 'success' | 'partial_success' | 'skipped' | 'failure';
|
|
3
|
+
export type DoclingFormValue = string | number | boolean | readonly (string | number | boolean)[];
|
|
4
|
+
export interface DoclingToolPackOptions {
|
|
5
|
+
serviceUrl: string;
|
|
6
|
+
apiKey?: string;
|
|
7
|
+
headers?: Record<string, string>;
|
|
8
|
+
timeoutMs?: number;
|
|
9
|
+
fetchFn?: typeof fetch;
|
|
10
|
+
}
|
|
11
|
+
export interface DoclingConvertFileInput {
|
|
12
|
+
bytes: Uint8Array;
|
|
13
|
+
filename: string;
|
|
14
|
+
mimeType?: string;
|
|
15
|
+
outputFormats: readonly DoclingOutputFormat[];
|
|
16
|
+
doOcr?: boolean;
|
|
17
|
+
forceOcr?: boolean;
|
|
18
|
+
tableMode?: 'fast' | 'accurate';
|
|
19
|
+
imageExportMode?: 'placeholder' | 'embedded' | 'referenced';
|
|
20
|
+
pipeline?: 'standard' | 'vlm';
|
|
21
|
+
/** Additional Docling Serve form fields not covered by convenience options. */
|
|
22
|
+
formOptions?: Readonly<Record<string, DoclingFormValue | null | undefined>>;
|
|
23
|
+
}
|
|
24
|
+
export interface DoclingConversionResult {
|
|
25
|
+
outputs: Partial<Record<DoclingOutputFormat, unknown>>;
|
|
26
|
+
status: DoclingConversionStatus;
|
|
27
|
+
processingTimeSec?: number;
|
|
28
|
+
errors: unknown[];
|
|
29
|
+
}
|
|
30
|
+
export interface DoclingConverter {
|
|
31
|
+
convertFile(input: DoclingConvertFileInput): Promise<DoclingConversionResult>;
|
|
32
|
+
}
|
|
33
|
+
export declare function createDoclingConverter(options: DoclingToolPackOptions): DoclingConverter;
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createDoclingConverter = createDoclingConverter;
|
|
4
|
+
const DEFAULT_DOCLING_TIMEOUT_MS = 120_000;
|
|
5
|
+
const SUPPORTED_OUTPUT_FORMATS = new Set([
|
|
6
|
+
'md',
|
|
7
|
+
'json',
|
|
8
|
+
'html',
|
|
9
|
+
'text',
|
|
10
|
+
'doctags',
|
|
11
|
+
]);
|
|
12
|
+
function createDoclingConverter(options) {
|
|
13
|
+
const serviceUrl = normalizeServiceUrl(options.serviceUrl);
|
|
14
|
+
const timeoutMs = normalizeTimeout(options.timeoutMs);
|
|
15
|
+
const fetchFn = options.fetchFn ?? globalThis.fetch;
|
|
16
|
+
if (!fetchFn) {
|
|
17
|
+
throw new Error('Docling processing requires a fetch implementation.');
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
convertFile: (input) => convertFile(serviceUrl, timeoutMs, fetchFn, options, normalizeInput(input)),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
async function convertFile(serviceUrl, timeoutMs, fetchFn, options, input) {
|
|
24
|
+
const form = new FormData();
|
|
25
|
+
const fileBytes = new Uint8Array(input.bytes.byteLength);
|
|
26
|
+
fileBytes.set(input.bytes);
|
|
27
|
+
form.append('files', new Blob([fileBytes], {
|
|
28
|
+
type: input.mimeType ?? resolveMimeType(input.filename),
|
|
29
|
+
}), input.filename);
|
|
30
|
+
for (const outputFormat of input.outputFormats) {
|
|
31
|
+
form.append('to_formats', outputFormat);
|
|
32
|
+
}
|
|
33
|
+
const convenienceOptions = {
|
|
34
|
+
do_ocr: input.doOcr,
|
|
35
|
+
force_ocr: input.forceOcr,
|
|
36
|
+
table_mode: input.tableMode,
|
|
37
|
+
image_export_mode: input.imageExportMode,
|
|
38
|
+
pipeline: input.pipeline,
|
|
39
|
+
};
|
|
40
|
+
appendFormOptions(form, input.formOptions, convenienceOptions);
|
|
41
|
+
for (const [key, value] of Object.entries(convenienceOptions)) {
|
|
42
|
+
appendOptionalFormValue(form, key, value);
|
|
43
|
+
}
|
|
44
|
+
const controller = new AbortController();
|
|
45
|
+
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
46
|
+
try {
|
|
47
|
+
let response;
|
|
48
|
+
try {
|
|
49
|
+
response = await fetchFn(`${serviceUrl}/v1/convert/file`, {
|
|
50
|
+
method: 'POST',
|
|
51
|
+
headers: createRequestHeaders(options),
|
|
52
|
+
body: form,
|
|
53
|
+
signal: controller.signal,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
if (controller.signal.aborted) {
|
|
58
|
+
throw new Error(`Docling request timed out after ${timeoutMs} ms.`, { cause: error });
|
|
59
|
+
}
|
|
60
|
+
throw new Error(`Docling request failed: ${redactSecrets(errorMessage(error), options)}`, {
|
|
61
|
+
cause: error,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
if (!response.ok) {
|
|
65
|
+
const responseText = await readResponseText(response, controller.signal);
|
|
66
|
+
throw new Error(redactSecrets(`Docling request failed with HTTP ${response.status}${responseText ? `: ${responseText}` : '.'}`, options));
|
|
67
|
+
}
|
|
68
|
+
const payload = await parseDoclingResponse(response, options, controller.signal);
|
|
69
|
+
const status = normalizeStatus(payload.status);
|
|
70
|
+
const outputs = extractOutputs(payload, input.outputFormats);
|
|
71
|
+
const outputValues = Object.values(outputs);
|
|
72
|
+
if ((status === 'failure' || status === 'skipped') && outputValues.length === 0) {
|
|
73
|
+
throw new Error(redactSecrets(formatConversionError(status, payload.errors), options));
|
|
74
|
+
}
|
|
75
|
+
const missingFormats = input.outputFormats.filter((format) => outputs[format] === undefined);
|
|
76
|
+
if (status === 'success' && missingFormats.length > 0) {
|
|
77
|
+
throw new Error(redactSecrets(`Docling returned no ${missingFormats.join(', ')} content for ${input.filename}.`, options));
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
outputs,
|
|
81
|
+
status,
|
|
82
|
+
processingTimeSec: payload.processing_time,
|
|
83
|
+
errors: payload.errors ?? [],
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
if (controller.signal.aborted &&
|
|
88
|
+
!(error instanceof Error && /timed out after/i.test(error.message))) {
|
|
89
|
+
throw new Error(`Docling request timed out after ${timeoutMs} ms.`, { cause: error });
|
|
90
|
+
}
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
finally {
|
|
94
|
+
clearTimeout(timeout);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function normalizeInput(input) {
|
|
98
|
+
const filename = input.filename.trim().split(/[\\/]/).pop()?.trim();
|
|
99
|
+
if (!filename) {
|
|
100
|
+
throw new Error('Docling filename is required.');
|
|
101
|
+
}
|
|
102
|
+
if (input.bytes.byteLength === 0) {
|
|
103
|
+
throw new Error(`Docling file ${filename} is empty.`);
|
|
104
|
+
}
|
|
105
|
+
const outputFormats = [...new Set(input.outputFormats)];
|
|
106
|
+
if (outputFormats.length === 0) {
|
|
107
|
+
throw new Error('Docling outputFormats must contain at least one format.');
|
|
108
|
+
}
|
|
109
|
+
for (const format of outputFormats) {
|
|
110
|
+
if (!SUPPORTED_OUTPUT_FORMATS.has(format)) {
|
|
111
|
+
throw new Error(`Unsupported Docling output format: ${format}`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return { ...input, filename, outputFormats };
|
|
115
|
+
}
|
|
116
|
+
function normalizeServiceUrl(serviceUrl) {
|
|
117
|
+
if (typeof serviceUrl !== 'string' || serviceUrl.trim().length === 0) {
|
|
118
|
+
throw new Error('Docling serviceUrl is required.');
|
|
119
|
+
}
|
|
120
|
+
let parsed;
|
|
121
|
+
try {
|
|
122
|
+
parsed = new URL(serviceUrl);
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
throw new Error('Docling serviceUrl must be a valid HTTP or HTTPS URL.');
|
|
126
|
+
}
|
|
127
|
+
if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {
|
|
128
|
+
throw new Error('Docling serviceUrl must use HTTP or HTTPS.');
|
|
129
|
+
}
|
|
130
|
+
return serviceUrl.trim().replace(/\/+$/, '');
|
|
131
|
+
}
|
|
132
|
+
function normalizeTimeout(timeoutMs) {
|
|
133
|
+
if (timeoutMs === undefined) {
|
|
134
|
+
return DEFAULT_DOCLING_TIMEOUT_MS;
|
|
135
|
+
}
|
|
136
|
+
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {
|
|
137
|
+
throw new Error('Docling timeoutMs must be a positive finite number.');
|
|
138
|
+
}
|
|
139
|
+
return timeoutMs;
|
|
140
|
+
}
|
|
141
|
+
function createRequestHeaders(options) {
|
|
142
|
+
const headers = new Headers(options.headers);
|
|
143
|
+
if (options.apiKey && !headers.has('X-Api-Key')) {
|
|
144
|
+
headers.set('X-Api-Key', options.apiKey);
|
|
145
|
+
}
|
|
146
|
+
// Fetch must generate the multipart boundary. A caller-supplied content type
|
|
147
|
+
// would replace it and make the upload invalid.
|
|
148
|
+
headers.delete('content-type');
|
|
149
|
+
return headers;
|
|
150
|
+
}
|
|
151
|
+
function appendOptionalFormValue(form, name, value) {
|
|
152
|
+
if (value !== undefined) {
|
|
153
|
+
appendFormValue(form, name, value);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
function appendFormOptions(form, options, convenienceOptions) {
|
|
157
|
+
for (const [name, value] of Object.entries(options ?? {})) {
|
|
158
|
+
if (name === 'to_formats' || convenienceOptions[name] !== undefined || value == null) {
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
appendFormValue(form, name, value);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
function appendFormValue(form, name, value) {
|
|
165
|
+
if (Array.isArray(value)) {
|
|
166
|
+
for (const item of value) {
|
|
167
|
+
form.append(name, String(item));
|
|
168
|
+
}
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
form.append(name, String(value));
|
|
172
|
+
}
|
|
173
|
+
function extractOutputs(payload, outputFormats) {
|
|
174
|
+
return Object.fromEntries(outputFormats
|
|
175
|
+
.map((format) => {
|
|
176
|
+
const content = payload.document?.[`${format}_content`];
|
|
177
|
+
return content === undefined || content === null ? undefined : [format, content];
|
|
178
|
+
})
|
|
179
|
+
.filter((entry) => entry !== undefined));
|
|
180
|
+
}
|
|
181
|
+
function normalizeStatus(status) {
|
|
182
|
+
if (status === 'success' ||
|
|
183
|
+
status === 'partial_success' ||
|
|
184
|
+
status === 'skipped' ||
|
|
185
|
+
status === 'failure') {
|
|
186
|
+
return status;
|
|
187
|
+
}
|
|
188
|
+
// Fail closed: missing/unknown Docling statuses must not be treated as success.
|
|
189
|
+
return 'failure';
|
|
190
|
+
}
|
|
191
|
+
const MAX_DOCLING_RESPONSE_BYTES = 32 * 1024 * 1024;
|
|
192
|
+
async function parseDoclingResponse(response, options, signal) {
|
|
193
|
+
let payload;
|
|
194
|
+
try {
|
|
195
|
+
const text = await readResponseBody(response, MAX_DOCLING_RESPONSE_BYTES, signal);
|
|
196
|
+
payload = JSON.parse(text);
|
|
197
|
+
}
|
|
198
|
+
catch (error) {
|
|
199
|
+
if (signal?.aborted)
|
|
200
|
+
throw error;
|
|
201
|
+
throw new Error(redactSecrets(`Docling returned invalid JSON: ${errorMessage(error)}`, options), {
|
|
202
|
+
cause: error,
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
if (!isDoclingResponse(payload)) {
|
|
206
|
+
throw new Error('Docling returned an unexpected response shape.');
|
|
207
|
+
}
|
|
208
|
+
return payload;
|
|
209
|
+
}
|
|
210
|
+
function isDoclingResponse(value) {
|
|
211
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
212
|
+
}
|
|
213
|
+
async function readResponseText(response, signal) {
|
|
214
|
+
try {
|
|
215
|
+
return (await readResponseBody(response, 2_000, signal)).slice(0, 2_000);
|
|
216
|
+
}
|
|
217
|
+
catch {
|
|
218
|
+
return '';
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
async function readResponseBody(response, maxBytes, signal) {
|
|
222
|
+
if (!response.body) {
|
|
223
|
+
const text = await response.text();
|
|
224
|
+
if (text.length > maxBytes) {
|
|
225
|
+
throw new Error(`Docling response exceeded the ${maxBytes} byte safety limit.`);
|
|
226
|
+
}
|
|
227
|
+
return text;
|
|
228
|
+
}
|
|
229
|
+
const reader = response.body.getReader();
|
|
230
|
+
const chunks = [];
|
|
231
|
+
let total = 0;
|
|
232
|
+
try {
|
|
233
|
+
while (true) {
|
|
234
|
+
if (signal?.aborted) {
|
|
235
|
+
throw new Error('Docling response read was aborted.');
|
|
236
|
+
}
|
|
237
|
+
const { done, value } = await reader.read();
|
|
238
|
+
if (done)
|
|
239
|
+
break;
|
|
240
|
+
if (!value)
|
|
241
|
+
continue;
|
|
242
|
+
total += value.byteLength;
|
|
243
|
+
if (total > maxBytes) {
|
|
244
|
+
await reader.cancel();
|
|
245
|
+
throw new Error(`Docling response exceeded the ${maxBytes} byte safety limit.`);
|
|
246
|
+
}
|
|
247
|
+
chunks.push(value);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
finally {
|
|
251
|
+
reader.releaseLock();
|
|
252
|
+
}
|
|
253
|
+
return Buffer.concat(chunks.map((chunk) => Buffer.from(chunk))).toString('utf8');
|
|
254
|
+
}
|
|
255
|
+
function formatConversionError(status, errors) {
|
|
256
|
+
const details = errors && errors.length > 0 ? `: ${JSON.stringify(errors)}` : '.';
|
|
257
|
+
return `Docling conversion ${status}${details}`;
|
|
258
|
+
}
|
|
259
|
+
function errorMessage(error) {
|
|
260
|
+
return error instanceof Error ? error.message : String(error);
|
|
261
|
+
}
|
|
262
|
+
function redactSecrets(message, options) {
|
|
263
|
+
const secrets = [options.apiKey, ...Object.values(options.headers ?? {})].filter((value) => Boolean(value));
|
|
264
|
+
return secrets.reduce((redacted, secret) => redacted.split(secret).join('[REDACTED]'), message);
|
|
265
|
+
}
|
|
266
|
+
function resolveMimeType(filename) {
|
|
267
|
+
const extension = filename.slice(filename.lastIndexOf('.') + 1).toLowerCase();
|
|
268
|
+
const mimeTypes = {
|
|
269
|
+
csv: 'text/csv',
|
|
270
|
+
doc: 'application/msword',
|
|
271
|
+
docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
272
|
+
html: 'text/html',
|
|
273
|
+
md: 'text/markdown',
|
|
274
|
+
pdf: 'application/pdf',
|
|
275
|
+
ppt: 'application/vnd.ms-powerpoint',
|
|
276
|
+
pptx: 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
|
277
|
+
xls: 'application/vnd.ms-excel',
|
|
278
|
+
xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
279
|
+
};
|
|
280
|
+
return mimeTypes[extension] ?? 'application/octet-stream';
|
|
281
|
+
}
|
|
282
|
+
//# sourceMappingURL=converter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"converter.js","sourceRoot":"","sources":["../src/converter.ts"],"names":[],"mappings":";;AAwDA,wDAaC;AArED,MAAM,0BAA0B,GAAG,OAAO,CAAC;AAE3C,MAAM,wBAAwB,GAAG,IAAI,GAAG,CAAsB;IAC5D,IAAI;IACJ,MAAM;IACN,MAAM;IACN,MAAM;IACN,SAAS;CACV,CAAC,CAAC;AAgDH,SAAgB,sBAAsB,CAAC,OAA+B;IACpE,MAAM,UAAU,GAAG,mBAAmB,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IAC3D,MAAM,SAAS,GAAG,gBAAgB,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACtD,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,UAAU,CAAC,KAAK,CAAC;IAE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AK,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,EAAE,OAAO,CAAC,CAAC;AAClG,CAAC;AAED,SAAS,eAAe,CAAC,QAAgB;IACvC,MAAM,SAAS,GAAG,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;IAC9E,MAAM,SAAS,GAA2B;QACxC,GAAG,EAAE,UAAU;QACf,GAAG,EAAE,oBAAoB;QACzB,IAAI,EAAE,yEAAyE;QAC/E,IAAI,EAAE,WAAW;QACjB,EAAE,EAAE,eAAe;QACnB,GAAG,EAAE,iBAAiB;QACtB,GAAG,EAAE,+BAA+B;QACpC,IAAI,EAAE,2EAA2E;QACjF,GAAG,EAAE,0BAA0B;QAC/B,IAAI,EAAE,mEAAmE;KAC1E,CAAC;IAEF,OAAO,SAAS,CAAC,SAAS,CAAC,IAAI,0BAA0B,CAAC;AAC5D,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ToolsInput } from '@mastra/core/agent';
|
|
2
|
+
import { type DoclingDocumentProcessorOptions, type DocumentParseOutput } from './document-processor';
|
|
3
|
+
import type { DoclingOutputFormat } from './converter';
|
|
4
|
+
export interface DoclingProcessResult {
|
|
5
|
+
source_path: string;
|
|
6
|
+
output_path: string;
|
|
7
|
+
output_format: DoclingOutputFormat;
|
|
8
|
+
status: DocumentParseOutput['status'];
|
|
9
|
+
processing_time?: number;
|
|
10
|
+
errors: unknown[];
|
|
11
|
+
}
|
|
12
|
+
export declare function resolveDoclingSkillPath(): string;
|
|
13
|
+
export declare function createDoclingTools(options: DoclingDocumentProcessorOptions): ToolsInput;
|
|
14
|
+
export declare function createDoclingToolPack(options: DoclingDocumentProcessorOptions): import("@lumifai/harness-tool-packs").ToolPack;
|
package/dist/docling.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.resolveDoclingSkillPath = resolveDoclingSkillPath;
|
|
7
|
+
exports.createDoclingTools = createDoclingTools;
|
|
8
|
+
exports.createDoclingToolPack = createDoclingToolPack;
|
|
9
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
10
|
+
const tools_1 = require("@mastra/core/tools");
|
|
11
|
+
const zod_1 = require("zod");
|
|
12
|
+
const harness_tool_packs_1 = require("@lumifai/harness-tool-packs");
|
|
13
|
+
const document_processor_1 = require("./document-processor");
|
|
14
|
+
const DEFAULT_OUTPUT_FORMAT = 'md';
|
|
15
|
+
const outputFormatSchema = zod_1.z.enum(['md', 'json', 'html', 'text', 'doctags']);
|
|
16
|
+
const processFileInputSchema = zod_1.z
|
|
17
|
+
.object({
|
|
18
|
+
path: zod_1.z
|
|
19
|
+
.string()
|
|
20
|
+
.min(1)
|
|
21
|
+
.describe('Workspace-relative path to a supported file, e.g. documents/report.pdf'),
|
|
22
|
+
output_format: outputFormatSchema
|
|
23
|
+
.optional()
|
|
24
|
+
.describe('Output format to write. Defaults to Markdown.'),
|
|
25
|
+
do_ocr: zod_1.z.boolean().optional().describe('Enable OCR for scanned documents.'),
|
|
26
|
+
force_ocr: zod_1.z.boolean().optional().describe('Force OCR even when text is available.'),
|
|
27
|
+
table_mode: zod_1.z.enum(['fast', 'accurate']).optional().describe('Table extraction mode.'),
|
|
28
|
+
image_export_mode: zod_1.z
|
|
29
|
+
.enum(['placeholder', 'embedded', 'referenced'])
|
|
30
|
+
.optional()
|
|
31
|
+
.describe('How images are represented in the exported document.'),
|
|
32
|
+
pipeline: zod_1.z
|
|
33
|
+
.enum(['standard', 'vlm'])
|
|
34
|
+
.optional()
|
|
35
|
+
.describe('Docling processing pipeline to use.'),
|
|
36
|
+
})
|
|
37
|
+
.strict();
|
|
38
|
+
function resolveDoclingSkillPath() {
|
|
39
|
+
const packageRoot = node_path_1.default.dirname(require.resolve('@lumifai/harness-tool-pack-docling/package.json'));
|
|
40
|
+
return node_path_1.default.join(packageRoot, 'skills', 'docling');
|
|
41
|
+
}
|
|
42
|
+
function createDoclingTools(options) {
|
|
43
|
+
const processor = (0, document_processor_1.createDoclingDocumentProcessor)(options);
|
|
44
|
+
const processFileTool = (0, tools_1.createTool)({
|
|
45
|
+
id: 'process_file',
|
|
46
|
+
description: 'Convert a supported workspace file through Docling and write the selected result under processed/. Supports PDF, Office documents, spreadsheets, CSV, HTML, Markdown, images, and other formats supported by the configured Docling service.',
|
|
47
|
+
inputSchema: processFileInputSchema,
|
|
48
|
+
execute: async (input, context) => processFile(processor, input, context),
|
|
49
|
+
});
|
|
50
|
+
return { process_file: processFileTool };
|
|
51
|
+
}
|
|
52
|
+
function createDoclingToolPack(options) {
|
|
53
|
+
return (0, harness_tool_packs_1.defineToolPack)({
|
|
54
|
+
id: 'docling',
|
|
55
|
+
description: 'Docling document conversion for supported workspace files.',
|
|
56
|
+
enabledByDefault: false,
|
|
57
|
+
skills: [resolveDoclingSkillPath()],
|
|
58
|
+
tools: createDoclingTools(options),
|
|
59
|
+
toolConfig: {
|
|
60
|
+
process_file: { permissionPolicy: 'ask' },
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
async function processFile(processor, input, context) {
|
|
65
|
+
const filesystem = context.workspace?.filesystem;
|
|
66
|
+
if (!filesystem) {
|
|
67
|
+
throw new Error('Docling processing requires a workspace filesystem.');
|
|
68
|
+
}
|
|
69
|
+
const outputFormat = input.output_format ?? DEFAULT_OUTPUT_FORMAT;
|
|
70
|
+
const result = await processor.parseWorkspaceFile(input.path, {
|
|
71
|
+
filesystem,
|
|
72
|
+
persistArtifacts: true,
|
|
73
|
+
options: {
|
|
74
|
+
outputFormats: [outputFormat],
|
|
75
|
+
...(input.do_ocr === undefined ? {} : { doOcr: input.do_ocr }),
|
|
76
|
+
...(input.force_ocr === undefined ? {} : { forceOcr: input.force_ocr }),
|
|
77
|
+
...(input.table_mode === undefined ? {} : { tableMode: input.table_mode }),
|
|
78
|
+
...(input.image_export_mode === undefined
|
|
79
|
+
? {}
|
|
80
|
+
: { imageExportMode: input.image_export_mode }),
|
|
81
|
+
...(input.pipeline === undefined ? {} : { pipeline: input.pipeline }),
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
const outputPath = result.artifactPaths?.[outputFormat];
|
|
85
|
+
if (!outputPath) {
|
|
86
|
+
throw new Error(`Docling returned no ${outputFormat} content for ${result.sourcePath}.`);
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
source_path: result.sourcePath,
|
|
90
|
+
output_path: outputPath,
|
|
91
|
+
output_format: outputFormat,
|
|
92
|
+
status: result.status,
|
|
93
|
+
processing_time: result.processingTimeSec,
|
|
94
|
+
errors: result.errors,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=docling.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"docling.js","sourceRoot":"","sources":["../src/docling.ts"],"names":[],"mappings":";;;;;AAuDA,0DAKC;AAED,gDAYC;AAED,sDAWC;AAvFD,0DAA6B;AAI7B,8CAAgD;AAChD,6BAAwB;AAExB,oEAA6D;AAE7D,6DAK8B;AAG9B,MAAM,qBAAqB,GAAwB,IAAI,CAAC;AAExD,MAAM,kBAAkB,GAAG,OAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;AAE7E,MAAM,sBAAsB,GAAG,OAAC;KAC7B,MAAM,CAAC;IACN,IAAI,EAAE,OAAC;SACJ,MAAM,EAAE;SACR,GAAG,CAAC,CAAC,CAAC;SACN,QAAQ,CAAC,wEAAwE,CAAC;IACrF,aAAa,EAAE,kBAAkB;SAC9B,QAAQ,EAAE;SACV,QAAQ,C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,CAAC,UAAU,EAAE,CAAC;YAC1E,GAAG,CAAC,KAAK,CAAC,iBAAiB,KAAK,SAAS;gBACvC,CAAC,CAAC,EAAE;gBACJ,CAAC,CAAC,EAAE,eAAe,EAAE,KAAK,CAAC,iBAAiB,EAAE,CAAC;YACjD,GAAG,CAAC,KAAK,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC;SAC5B;KAC5C,CAAC,CAAC;IACH,MAAM,UAAU,GAAG,MAAM,CAAC,aAAa,EAAE,CAAC,YAAY,CAAC,CAAC;IAExD,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,uBAAuB,YAAY,gBAAgB,MAAM,CAAC,UAAU,GAAG,CAAC,CAAC;IAC3F,CAAC;IAED,OAAO;QACL,WAAW,EAAE,MAAM,CAAC,UAAU;QAC9B,WAAW,EAAE,UAAU;QACvB,aAAa,EAAE,YAAY;QAC3B,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,eAAe,EAAE,MAAM,CAAC,iBAAiB;QACzC,MAAM,EAAE,MAAM,CAAC,MAAM;KACtB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { WorkspaceFilesystem } from '@mastra/core/workspace';
|
|
2
|
+
import { type DoclingFormValue, type DoclingOutputFormat, type DoclingToolPackOptions } from './converter';
|
|
3
|
+
export type DocumentParseStatus = 'success' | 'partial_success' | 'skipped' | 'failure';
|
|
4
|
+
export interface DocumentParseInput {
|
|
5
|
+
filename: string;
|
|
6
|
+
bytes: Uint8Array;
|
|
7
|
+
mimeType?: string;
|
|
8
|
+
options?: Partial<DoclingDocumentOptions>;
|
|
9
|
+
}
|
|
10
|
+
export interface DocumentParseOutput {
|
|
11
|
+
processorId: string;
|
|
12
|
+
sourcePath: string;
|
|
13
|
+
markdown?: string;
|
|
14
|
+
json?: unknown;
|
|
15
|
+
extras: {
|
|
16
|
+
html?: string;
|
|
17
|
+
text?: string;
|
|
18
|
+
doctags?: string;
|
|
19
|
+
};
|
|
20
|
+
status: DocumentParseStatus;
|
|
21
|
+
processingTimeSec?: number;
|
|
22
|
+
errors: unknown[];
|
|
23
|
+
artifactPaths?: Partial<Record<DoclingOutputFormat, string>>;
|
|
24
|
+
}
|
|
25
|
+
export interface DocumentArtifactPathInput {
|
|
26
|
+
sourcePath: string;
|
|
27
|
+
filename: string;
|
|
28
|
+
format: DoclingOutputFormat;
|
|
29
|
+
}
|
|
30
|
+
export type DocumentArtifactPathResolver = (input: DocumentArtifactPathInput) => string;
|
|
31
|
+
export interface DocumentWorkspaceParseOptions {
|
|
32
|
+
filesystem: WorkspaceFilesystem;
|
|
33
|
+
mimeType?: string;
|
|
34
|
+
options?: Partial<DoclingDocumentOptions>;
|
|
35
|
+
persistArtifacts?: boolean;
|
|
36
|
+
artifactPathResolver?: DocumentArtifactPathResolver;
|
|
37
|
+
}
|
|
38
|
+
export interface DocumentProcessor {
|
|
39
|
+
readonly processorId: string;
|
|
40
|
+
parse(input: DocumentParseInput): Promise<DocumentParseOutput>;
|
|
41
|
+
parseWorkspaceFile(path: string, options: DocumentWorkspaceParseOptions): Promise<DocumentParseOutput>;
|
|
42
|
+
}
|
|
43
|
+
export interface DoclingDocumentOptions {
|
|
44
|
+
outputFormats: readonly DoclingOutputFormat[];
|
|
45
|
+
doOcr: boolean;
|
|
46
|
+
forceOcr: boolean;
|
|
47
|
+
tableMode: 'fast' | 'accurate';
|
|
48
|
+
imageExportMode: 'placeholder' | 'embedded' | 'referenced';
|
|
49
|
+
pipeline: 'standard' | 'vlm';
|
|
50
|
+
ocrEngine: string;
|
|
51
|
+
pdfBackend: string;
|
|
52
|
+
abortOnError: boolean;
|
|
53
|
+
returnAsFile: boolean;
|
|
54
|
+
doCodeEnrichment: boolean;
|
|
55
|
+
doFormulaEnrichment: boolean;
|
|
56
|
+
doPictureClassification: boolean;
|
|
57
|
+
doPictureDescription: boolean;
|
|
58
|
+
normalizeEmbeddedImages: boolean;
|
|
59
|
+
imagePlaceholder: string;
|
|
60
|
+
formOptions: Readonly<Record<string, DoclingFormValue | null | undefined>>;
|
|
61
|
+
}
|
|
62
|
+
export interface DoclingDocumentProcessorOptions extends DoclingToolPackOptions {
|
|
63
|
+
defaults?: Partial<DoclingDocumentOptions>;
|
|
64
|
+
}
|
|
65
|
+
export declare const DOCLING_PROCESSOR_ID = "docling";
|
|
66
|
+
export declare const DEFAULT_DOCLING_DOCUMENT_OPTIONS: Readonly<DoclingDocumentOptions>;
|
|
67
|
+
export declare const IMAGE_PLACEHOLDER = "[Image]";
|
|
68
|
+
export declare function createDoclingDocumentProcessor(options: DoclingDocumentProcessorOptions): DocumentProcessor;
|
|
69
|
+
export declare function replaceEmbeddedImagesWithPlaceholder(markdown: string, placeholder?: string): string;
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IMAGE_PLACEHOLDER = exports.DEFAULT_DOCLING_DOCUMENT_OPTIONS = exports.DOCLING_PROCESSOR_ID = void 0;
|
|
4
|
+
exports.createDoclingDocumentProcessor = createDoclingDocumentProcessor;
|
|
5
|
+
exports.replaceEmbeddedImagesWithPlaceholder = replaceEmbeddedImagesWithPlaceholder;
|
|
6
|
+
const harness_tool_packs_1 = require("@lumifai/harness-tool-packs");
|
|
7
|
+
const converter_1 = require("./converter");
|
|
8
|
+
exports.DOCLING_PROCESSOR_ID = 'docling';
|
|
9
|
+
exports.DEFAULT_DOCLING_DOCUMENT_OPTIONS = {
|
|
10
|
+
outputFormats: ['md', 'json', 'html', 'text', 'doctags'],
|
|
11
|
+
imageExportMode: 'placeholder',
|
|
12
|
+
pipeline: 'standard',
|
|
13
|
+
doOcr: true,
|
|
14
|
+
forceOcr: false,
|
|
15
|
+
ocrEngine: 'auto',
|
|
16
|
+
pdfBackend: 'docling_parse',
|
|
17
|
+
tableMode: 'accurate',
|
|
18
|
+
abortOnError: false,
|
|
19
|
+
returnAsFile: false,
|
|
20
|
+
doCodeEnrichment: false,
|
|
21
|
+
doFormulaEnrichment: false,
|
|
22
|
+
doPictureClassification: false,
|
|
23
|
+
doPictureDescription: false,
|
|
24
|
+
normalizeEmbeddedImages: true,
|
|
25
|
+
imagePlaceholder: '[Image]',
|
|
26
|
+
formOptions: {},
|
|
27
|
+
};
|
|
28
|
+
const DEFAULT_ARTIFACT_PATH_RESOLVER = ({ filename, format }) => `processed/${filename}.${format}`;
|
|
29
|
+
exports.IMAGE_PLACEHOLDER = '[Image]';
|
|
30
|
+
function createDoclingDocumentProcessor(options) {
|
|
31
|
+
const converter = (0, converter_1.createDoclingConverter)(options);
|
|
32
|
+
const defaults = resolveDocumentOptions(options.defaults);
|
|
33
|
+
return {
|
|
34
|
+
processorId: exports.DOCLING_PROCESSOR_ID,
|
|
35
|
+
parse: (input) => parseBytes(converter, defaults, input, input.filename),
|
|
36
|
+
parseWorkspaceFile: (path, workspaceOptions) => parseWorkspaceFile(converter, defaults, path, workspaceOptions),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function replaceEmbeddedImagesWithPlaceholder(markdown, placeholder = exports.IMAGE_PLACEHOLDER) {
|
|
40
|
+
return markdown
|
|
41
|
+
.replace(/!\[[^\]]*\]\(data:image\/[^)]+\)/gi, placeholder)
|
|
42
|
+
.replace(/!\[[^\]]*\]\(data:image\/[A-Za-z0-9+/=\s]*$/gim, placeholder)
|
|
43
|
+
.replace(/<img\b[^>]*\bsrc=["']data:image\/[^"']+["'][^>]*>/gi, placeholder);
|
|
44
|
+
}
|
|
45
|
+
async function parseBytes(converter, defaults, input, sourcePath) {
|
|
46
|
+
const documentOptions = resolveDocumentOptions(defaults, input.options);
|
|
47
|
+
const filename = normalizeFilename(input.filename);
|
|
48
|
+
const conversion = await converter.convertFile({
|
|
49
|
+
bytes: input.bytes,
|
|
50
|
+
filename,
|
|
51
|
+
mimeType: input.mimeType,
|
|
52
|
+
outputFormats: documentOptions.outputFormats,
|
|
53
|
+
doOcr: documentOptions.doOcr,
|
|
54
|
+
forceOcr: documentOptions.forceOcr,
|
|
55
|
+
tableMode: documentOptions.tableMode,
|
|
56
|
+
imageExportMode: documentOptions.imageExportMode,
|
|
57
|
+
pipeline: documentOptions.pipeline,
|
|
58
|
+
formOptions: toFormOptions(documentOptions),
|
|
59
|
+
});
|
|
60
|
+
return mapConversionResult(sourcePath, conversion, documentOptions);
|
|
61
|
+
}
|
|
62
|
+
async function parseWorkspaceFile(converter, defaults, inputPath, workspaceOptions) {
|
|
63
|
+
const filesystem = workspaceOptions.filesystem;
|
|
64
|
+
if (!filesystem?.readFile) {
|
|
65
|
+
throw new Error(`Docling processing requires a workspace filesystem to read ${inputPath}.`);
|
|
66
|
+
}
|
|
67
|
+
const workspace = (0, harness_tool_packs_1.createWorkspaceFiles)();
|
|
68
|
+
const context = { workspace: { filesystem } };
|
|
69
|
+
const file = await workspace.read(context, inputPath);
|
|
70
|
+
const filename = getFilename(file.path);
|
|
71
|
+
const result = await parseBytes(converter, defaults, {
|
|
72
|
+
filename,
|
|
73
|
+
bytes: file.bytes,
|
|
74
|
+
mimeType: workspaceOptions.mimeType,
|
|
75
|
+
options: workspaceOptions.options,
|
|
76
|
+
}, file.path);
|
|
77
|
+
if (!workspaceOptions.persistArtifacts) {
|
|
78
|
+
return result;
|
|
79
|
+
}
|
|
80
|
+
return persistArtifacts(result, file.path, filename, workspace, context, workspaceOptions.artifactPathResolver ?? DEFAULT_ARTIFACT_PATH_RESOLVER);
|
|
81
|
+
}
|
|
82
|
+
function mapConversionResult(sourcePath, conversion, options) {
|
|
83
|
+
const markdown = asStringOutput(conversion.outputs.md);
|
|
84
|
+
const normalizedMarkdown = markdown !== undefined && options.normalizeEmbeddedImages
|
|
85
|
+
? replaceEmbeddedImagesWithPlaceholder(markdown, options.imagePlaceholder)
|
|
86
|
+
: markdown;
|
|
87
|
+
return {
|
|
88
|
+
processorId: exports.DOCLING_PROCESSOR_ID,
|
|
89
|
+
sourcePath,
|
|
90
|
+
markdown: normalizedMarkdown,
|
|
91
|
+
json: conversion.outputs.json,
|
|
92
|
+
extras: {
|
|
93
|
+
html: asStringOutput(conversion.outputs.html),
|
|
94
|
+
text: asStringOutput(conversion.outputs.text),
|
|
95
|
+
doctags: asStringOutput(conversion.outputs.doctags),
|
|
96
|
+
},
|
|
97
|
+
status: conversion.status,
|
|
98
|
+
processingTimeSec: conversion.processingTimeSec,
|
|
99
|
+
errors: conversion.errors,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
async function persistArtifacts(result, sourcePath, filename, workspace, context, pathResolver) {
|
|
103
|
+
const values = [
|
|
104
|
+
['md', result.markdown],
|
|
105
|
+
['json', result.json],
|
|
106
|
+
['html', result.extras.html],
|
|
107
|
+
['text', result.extras.text],
|
|
108
|
+
['doctags', result.extras.doctags],
|
|
109
|
+
];
|
|
110
|
+
const artifactPaths = {};
|
|
111
|
+
for (const [format, value] of values) {
|
|
112
|
+
if (value === undefined)
|
|
113
|
+
continue;
|
|
114
|
+
const artifactPath = (0, harness_tool_packs_1.normalizeWorkspacePath)(pathResolver({ sourcePath, filename, format }));
|
|
115
|
+
await workspace.write(context, artifactPath, serializeOutput(format, value), {
|
|
116
|
+
overwrite: true,
|
|
117
|
+
});
|
|
118
|
+
artifactPaths[format] = artifactPath;
|
|
119
|
+
}
|
|
120
|
+
return { ...result, artifactPaths };
|
|
121
|
+
}
|
|
122
|
+
function resolveDocumentOptions(...overrides) {
|
|
123
|
+
const merged = overrides.reduce((current, override) => ({
|
|
124
|
+
...current,
|
|
125
|
+
...(override ?? {}),
|
|
126
|
+
formOptions: {
|
|
127
|
+
...current.formOptions,
|
|
128
|
+
...(override?.formOptions ?? {}),
|
|
129
|
+
},
|
|
130
|
+
}), { ...exports.DEFAULT_DOCLING_DOCUMENT_OPTIONS, formOptions: {} });
|
|
131
|
+
const outputFormats = normalizeOutputFormats(merged.outputFormats);
|
|
132
|
+
if (typeof merged.doOcr !== 'boolean' || typeof merged.forceOcr !== 'boolean') {
|
|
133
|
+
throw new Error('Docling OCR options must be boolean values.');
|
|
134
|
+
}
|
|
135
|
+
if (merged.tableMode !== 'fast' && merged.tableMode !== 'accurate') {
|
|
136
|
+
throw new Error(`Unsupported Docling tableMode: ${String(merged.tableMode)}`);
|
|
137
|
+
}
|
|
138
|
+
if (!['placeholder', 'embedded', 'referenced'].includes(merged.imageExportMode)) {
|
|
139
|
+
throw new Error(`Unsupported Docling imageExportMode: ${String(merged.imageExportMode)}`);
|
|
140
|
+
}
|
|
141
|
+
if (!['standard', 'vlm'].includes(merged.pipeline)) {
|
|
142
|
+
throw new Error(`Unsupported Docling pipeline: ${String(merged.pipeline)}`);
|
|
143
|
+
}
|
|
144
|
+
for (const name of ['ocrEngine', 'pdfBackend', 'imagePlaceholder']) {
|
|
145
|
+
if (typeof merged[name] !== 'string' || merged[name].trim().length === 0) {
|
|
146
|
+
throw new Error(`Docling ${name} must be a non-empty string.`);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
for (const name of [
|
|
150
|
+
'abortOnError',
|
|
151
|
+
'returnAsFile',
|
|
152
|
+
'doCodeEnrichment',
|
|
153
|
+
'doFormulaEnrichment',
|
|
154
|
+
'doPictureClassification',
|
|
155
|
+
'doPictureDescription',
|
|
156
|
+
'normalizeEmbeddedImages',
|
|
157
|
+
]) {
|
|
158
|
+
if (typeof merged[name] !== 'boolean') {
|
|
159
|
+
throw new Error(`Docling ${name} must be a boolean value.`);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return { ...merged, outputFormats };
|
|
163
|
+
}
|
|
164
|
+
function normalizeOutputFormats(value) {
|
|
165
|
+
if (!Array.isArray(value) || value.length === 0) {
|
|
166
|
+
throw new Error('Docling outputFormats must contain at least one format.');
|
|
167
|
+
}
|
|
168
|
+
const formats = [...new Set(value)];
|
|
169
|
+
for (const format of formats) {
|
|
170
|
+
if (!['md', 'json', 'html', 'text', 'doctags'].includes(format)) {
|
|
171
|
+
throw new Error(`Unsupported Docling output format: ${String(format)}`);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return formats;
|
|
175
|
+
}
|
|
176
|
+
function toFormOptions(options) {
|
|
177
|
+
return {
|
|
178
|
+
...options.formOptions,
|
|
179
|
+
ocr_engine: options.ocrEngine,
|
|
180
|
+
pdf_backend: options.pdfBackend,
|
|
181
|
+
abort_on_error: options.abortOnError,
|
|
182
|
+
return_as_file: options.returnAsFile,
|
|
183
|
+
do_code_enrichment: options.doCodeEnrichment,
|
|
184
|
+
do_formula_enrichment: options.doFormulaEnrichment,
|
|
185
|
+
do_picture_classification: options.doPictureClassification,
|
|
186
|
+
do_picture_description: options.doPictureDescription,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
function asStringOutput(value) {
|
|
190
|
+
if (value === undefined || value === null)
|
|
191
|
+
return undefined;
|
|
192
|
+
return typeof value === 'string' ? value : JSON.stringify(value);
|
|
193
|
+
}
|
|
194
|
+
function serializeOutput(format, value) {
|
|
195
|
+
if (format !== 'json' && typeof value === 'string')
|
|
196
|
+
return value;
|
|
197
|
+
return JSON.stringify(value, null, 2);
|
|
198
|
+
}
|
|
199
|
+
function normalizeFilename(inputPath) {
|
|
200
|
+
const filename = inputPath.trim().split(/[\\/]/).pop()?.trim();
|
|
201
|
+
if (!filename)
|
|
202
|
+
throw new Error('Docling filename is required.');
|
|
203
|
+
return filename;
|
|
204
|
+
}
|
|
205
|
+
function getFilename(normalizedPath) {
|
|
206
|
+
return normalizeFilename(normalizedPath);
|
|
207
|
+
}
|
|
208
|
+
//# sourceMappingURL=document-processor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"document-processor.js","sourceRoot":"","sources":["../src/document-processor.ts"],"names":[],"mappings":";;;AAkHA,wEAYC;AAED,oFAQC;AAvID,oEAA2F;AAG3F,2CAOqB;AA4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WAAW,CAAC,cAAsB;IACzC,OAAO,iBAAiB,CAAC,cAAc,CAAC,CAAC;AAC3C,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { createDoclingTools, createDoclingToolPack, resolveDoclingSkillPath } from './docling';
|
|
2
|
+
export type { DoclingProcessResult } from './docling';
|
|
3
|
+
export { createDoclingDocumentProcessor, DEFAULT_DOCLING_DOCUMENT_OPTIONS, DOCLING_PROCESSOR_ID, IMAGE_PLACEHOLDER, replaceEmbeddedImagesWithPlaceholder, type DoclingDocumentOptions, type DoclingDocumentProcessorOptions, type DocumentArtifactPathInput, type DocumentArtifactPathResolver, type DocumentParseInput, type DocumentParseOutput, type DocumentParseStatus, type DocumentProcessor, type DocumentWorkspaceParseOptions, } from './document-processor';
|
|
4
|
+
export { createDoclingConverter, type DoclingConvertFileInput, type DoclingConversionResult, type DoclingConversionStatus, type DoclingConverter, type DoclingFormValue, type DoclingOutputFormat, type DoclingToolPackOptions, } from './converter';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createDoclingConverter = exports.replaceEmbeddedImagesWithPlaceholder = exports.IMAGE_PLACEHOLDER = exports.DOCLING_PROCESSOR_ID = exports.DEFAULT_DOCLING_DOCUMENT_OPTIONS = exports.createDoclingDocumentProcessor = exports.resolveDoclingSkillPath = exports.createDoclingToolPack = exports.createDoclingTools = void 0;
|
|
4
|
+
var docling_1 = require("./docling");
|
|
5
|
+
Object.defineProperty(exports, "createDoclingTools", { enumerable: true, get: function () { return docling_1.createDoclingTools; } });
|
|
6
|
+
Object.defineProperty(exports, "createDoclingToolPack", { enumerable: true, get: function () { return docling_1.createDoclingToolPack; } });
|
|
7
|
+
Object.defineProperty(exports, "resolveDoclingSkillPath", { enumerable: true, get: function () { return docling_1.resolveDoclingSkillPath; } });
|
|
8
|
+
var document_processor_1 = require("./document-processor");
|
|
9
|
+
Object.defineProperty(exports, "createDoclingDocumentProcessor", { enumerable: true, get: function () { return document_processor_1.createDoclingDocumentProcessor; } });
|
|
10
|
+
Object.defineProperty(exports, "DEFAULT_DOCLING_DOCUMENT_OPTIONS", { enumerable: true, get: function () { return document_processor_1.DEFAULT_DOCLING_DOCUMENT_OPTIONS; } });
|
|
11
|
+
Object.defineProperty(exports, "DOCLING_PROCESSOR_ID", { enumerable: true, get: function () { return document_processor_1.DOCLING_PROCESSOR_ID; } });
|
|
12
|
+
Object.defineProperty(exports, "IMAGE_PLACEHOLDER", { enumerable: true, get: function () { return document_processor_1.IMAGE_PLACEHOLDER; } });
|
|
13
|
+
Object.defineProperty(exports, "replaceEmbeddedImagesWithPlaceholder", { enumerable: true, get: function () { return document_processor_1.replaceEmbeddedImagesWithPlaceholder; } });
|
|
14
|
+
var converter_1 = require("./converter");
|
|
15
|
+
Object.defineProperty(exports, "createDoclingConverter", { enumerable: true, get: function () { return converter_1.createDoclingConverter; } });
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,qCAA+F;AAAtF,6GAAA,kBAAkB,OAAA;AAAE,gHAAA,qBAAqB,OAAA;AAAE,kHAAA,uBAAuB,OAAA;AAE3E,2DAe8B;AAd5B,oIAAA,8BAA8B,OAAA;AAC9B,sIAAA,gCAAgC,OAAA;AAChC,0HAAA,oBAAoB,OAAA;AACpB,uHAAA,iBAAiB,OAAA;AACjB,0IAAA,oCAAoC,OAAA;AAWtC,yCASqB;AARnB,mHAAA,sBAAsB,OAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lumifai/harness-tool-pack-docling",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "UNLICENSED",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/Lumif-ai/lumif-harness.git",
|
|
8
|
+
"directory": "packages/tool-packs/docling"
|
|
9
|
+
},
|
|
10
|
+
"engines": {
|
|
11
|
+
"node": ">=22.13.0"
|
|
12
|
+
},
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"import": "./dist/index.js",
|
|
17
|
+
"require": "./dist/index.js",
|
|
18
|
+
"default": "./dist/index.js"
|
|
19
|
+
},
|
|
20
|
+
"./package.json": "./package.json"
|
|
21
|
+
},
|
|
22
|
+
"main": "dist/index.js",
|
|
23
|
+
"types": "dist/index.d.ts",
|
|
24
|
+
"files": [
|
|
25
|
+
"dist",
|
|
26
|
+
"!dist/**/*.test.*",
|
|
27
|
+
"skills"
|
|
28
|
+
],
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@lumifai/harness-tool-packs": "0.2.0",
|
|
31
|
+
"@mastra/core": "1.67.0",
|
|
32
|
+
"zod": "^4.4.3"
|
|
33
|
+
},
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public",
|
|
36
|
+
"registry": "https://registry.npmjs.org/"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "tsc -p tsconfig.json",
|
|
40
|
+
"test": "vitest run --root ../../../ packages/tool-packs/docling/src"
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: docling
|
|
3
|
+
description: Convert supported workspace files through the configured Docling service
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
tags:
|
|
6
|
+
- docling
|
|
7
|
+
- file-processing
|
|
8
|
+
- pdf
|
|
9
|
+
- office
|
|
10
|
+
- spreadsheets
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
# Docling File Processing
|
|
14
|
+
|
|
15
|
+
Use `process_file` to convert a workspace file through the configured Docling
|
|
16
|
+
Serve endpoint. The tool supports the formats enabled by that Docling service,
|
|
17
|
+
including PDF, DOC/DOCX, PPT/PPTX, XLS/XLSX, CSV, HTML, Markdown, images, and
|
|
18
|
+
other Docling-supported formats.
|
|
19
|
+
|
|
20
|
+
## Workflow
|
|
21
|
+
|
|
22
|
+
1. Call `process_file` with an workspace-relative path.
|
|
23
|
+
2. Select `output_format` when Markdown is not appropriate.
|
|
24
|
+
3. Use the returned `output_path` to read the converted file.
|
|
25
|
+
|
|
26
|
+
Results are written under `processed/` and the converted content is not
|
|
27
|
+
returned inline. Service credentials are configured by the host when the
|
|
28
|
+
tool-pack is constructed; never request credentials from the user or model.
|
|
29
|
+
|
|
30
|
+
Application integrations that already have bytes or need structured outputs
|
|
31
|
+
should use `createDoclingDocumentProcessor`. It shares the same Docling defaults
|
|
32
|
+
as the tool, returns Markdown/JSON/extras with status and timing metadata, and
|
|
33
|
+
can read and persist files through an explicitly supplied workspace filesystem.
|