@docling/docling-client 0.1.0 → 0.3.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/dist/index.cjs +46 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +13 -13
- package/dist/index.d.ts +13 -13
- package/dist/index.js +45 -22
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -51,11 +51,11 @@ __export(index_exports, {
|
|
|
51
51
|
DoclingUsageLimitExceededError: () => DoclingUsageLimitExceededError,
|
|
52
52
|
FetchTransport: () => FetchTransport,
|
|
53
53
|
MAX_CONCURRENCY_LIMIT: () => MAX_CONCURRENCY_LIMIT,
|
|
54
|
+
appendFormValue: () => appendFormValue,
|
|
54
55
|
applyPageLimits: () => applyPageLimits,
|
|
55
56
|
documentFromBundle: () => documentFromBundle,
|
|
56
57
|
documentFromJson: () => documentFromJson,
|
|
57
58
|
fileSourceFromBinary: () => fileSourceFromBinary,
|
|
58
|
-
formValue: () => formValue,
|
|
59
59
|
materializePresignedResult: () => materializePresignedResult,
|
|
60
60
|
normalizeSourceInput: () => normalizeSourceInput,
|
|
61
61
|
preflightFileSize: () => preflightFileSize,
|
|
@@ -1181,14 +1181,16 @@ function preflightFileSize(source, maxFileSize) {
|
|
|
1181
1181
|
}
|
|
1182
1182
|
return `File size ${source.descriptor.file_size} exceeds the configured limit of ${maxFileSize} bytes`;
|
|
1183
1183
|
}
|
|
1184
|
-
function
|
|
1185
|
-
if (
|
|
1186
|
-
|
|
1187
|
-
}
|
|
1188
|
-
|
|
1189
|
-
|
|
1184
|
+
function appendFormValue(form, key, value) {
|
|
1185
|
+
if (Array.isArray(value)) {
|
|
1186
|
+
value.forEach((item) => appendFormValue(form, key, item));
|
|
1187
|
+
} else if (typeof value === "string") {
|
|
1188
|
+
form.append(key, value);
|
|
1189
|
+
} else if (typeof value === "number" || typeof value === "boolean") {
|
|
1190
|
+
form.append(key, String(value));
|
|
1191
|
+
} else {
|
|
1192
|
+
form.append(key, JSON.stringify(value));
|
|
1190
1193
|
}
|
|
1191
|
-
return JSON.stringify(value);
|
|
1192
1194
|
}
|
|
1193
1195
|
async function fileSourceFromBinary(source, signal) {
|
|
1194
1196
|
throwIfAborted(signal);
|
|
@@ -2465,7 +2467,8 @@ var DoclingClient = class {
|
|
|
2465
2467
|
const payload = {
|
|
2466
2468
|
options: convertOptions,
|
|
2467
2469
|
sources: structuredClone(request.sources),
|
|
2468
|
-
target: structuredClone(request.target),
|
|
2470
|
+
...request.target !== void 0 ? { target: structuredClone(request.target) } : {},
|
|
2471
|
+
...request.targets !== void 0 ? { targets: structuredClone(request.targets) } : {},
|
|
2469
2472
|
callbacks: structuredClone(request.callbacks ?? [])
|
|
2470
2473
|
};
|
|
2471
2474
|
throwIfAborted2(options.signal);
|
|
@@ -2476,7 +2479,8 @@ var DoclingClient = class {
|
|
|
2476
2479
|
signal: options.signal
|
|
2477
2480
|
})
|
|
2478
2481
|
);
|
|
2479
|
-
const
|
|
2482
|
+
const effectiveTargetList = request.targets?.length ? request.targets : request.target !== void 0 ? [request.target] : [];
|
|
2483
|
+
const loader = effectiveTargetList.some(isStorageTarget) ? (taskId, lastStatus, signal) => this.#fetchCountsResult(taskId, lastStatus, signal) : (taskId, lastStatus, signal) => this.#fetchPresignedResult(taskId, lastStatus, signal);
|
|
2480
2484
|
return new DoclingJob(
|
|
2481
2485
|
this,
|
|
2482
2486
|
status,
|
|
@@ -2586,12 +2590,12 @@ var DoclingClient = class {
|
|
|
2586
2590
|
);
|
|
2587
2591
|
for (const [key, value] of Object.entries(convertOptions)) {
|
|
2588
2592
|
if (value !== void 0 && value !== null) {
|
|
2589
|
-
form
|
|
2593
|
+
appendFormValue(form, `convert_${key}`, value);
|
|
2590
2594
|
}
|
|
2591
2595
|
}
|
|
2592
2596
|
for (const [key, value] of Object.entries(request.chunking_options ?? {})) {
|
|
2593
2597
|
if (key !== "chunker" && value !== void 0 && value !== null) {
|
|
2594
|
-
form
|
|
2598
|
+
appendFormValue(form, `chunking_${key}`, value);
|
|
2595
2599
|
}
|
|
2596
2600
|
}
|
|
2597
2601
|
form.append(
|
|
@@ -2906,13 +2910,14 @@ var DoclingClient = class {
|
|
|
2906
2910
|
);
|
|
2907
2911
|
}
|
|
2908
2912
|
async #submitNormalizedForTarget(source, options, target, requestOptions) {
|
|
2913
|
+
const callbacks = requestOptions.callbacks ?? [];
|
|
2909
2914
|
if (source.kind === "json") {
|
|
2910
2915
|
return this.#submitRequestForTarget(
|
|
2911
2916
|
{
|
|
2912
2917
|
options,
|
|
2913
2918
|
sources: [source.source],
|
|
2914
2919
|
target,
|
|
2915
|
-
callbacks
|
|
2920
|
+
callbacks
|
|
2916
2921
|
},
|
|
2917
2922
|
requestOptions
|
|
2918
2923
|
);
|
|
@@ -2924,7 +2929,7 @@ var DoclingClient = class {
|
|
|
2924
2929
|
options,
|
|
2925
2930
|
sources: [fileSource],
|
|
2926
2931
|
target,
|
|
2927
|
-
callbacks
|
|
2932
|
+
callbacks
|
|
2928
2933
|
},
|
|
2929
2934
|
requestOptions
|
|
2930
2935
|
);
|
|
@@ -2932,9 +2937,13 @@ var DoclingClient = class {
|
|
|
2932
2937
|
const form = new FormData();
|
|
2933
2938
|
for (const [key, value] of Object.entries(options)) {
|
|
2934
2939
|
if (value !== void 0 && value !== null) {
|
|
2935
|
-
form
|
|
2940
|
+
appendFormValue(form, key, value);
|
|
2936
2941
|
}
|
|
2937
2942
|
}
|
|
2943
|
+
validateCallbacks(callbacks);
|
|
2944
|
+
for (const callback of callbacks) {
|
|
2945
|
+
form.append("callbacks", JSON.stringify(callback));
|
|
2946
|
+
}
|
|
2938
2947
|
form.append("target_type", target.kind);
|
|
2939
2948
|
form.append("files", source.blob, source.descriptor.filename);
|
|
2940
2949
|
const status = parseTaskStatus(
|
|
@@ -3396,6 +3405,7 @@ function parsePresignedResponse(value) {
|
|
|
3396
3405
|
"text",
|
|
3397
3406
|
"doctags",
|
|
3398
3407
|
"doclang",
|
|
3408
|
+
"dclx",
|
|
3399
3409
|
"resource_bundle"
|
|
3400
3410
|
].includes(String(artifact.artifact_type))) {
|
|
3401
3411
|
throw schemaMismatch(`${artifactPath}.artifact_type is unsupported`);
|
|
@@ -3692,8 +3702,8 @@ function shouldFallbackFromPresigned(error) {
|
|
|
3692
3702
|
function targetNeedsJson(target) {
|
|
3693
3703
|
return target.kind === "inbody";
|
|
3694
3704
|
}
|
|
3695
|
-
function
|
|
3696
|
-
return target.kind
|
|
3705
|
+
function isStorageTarget(target) {
|
|
3706
|
+
return target.kind !== "presigned_url";
|
|
3697
3707
|
}
|
|
3698
3708
|
function validateBatchRequest(request) {
|
|
3699
3709
|
if (!Array.isArray(request.sources) || request.sources.length === 0) {
|
|
@@ -3708,15 +3718,28 @@ function validateBatchRequest(request) {
|
|
|
3708
3718
|
}
|
|
3709
3719
|
validateKnownConnector(source, "source");
|
|
3710
3720
|
}
|
|
3711
|
-
if (
|
|
3712
|
-
throw new DoclingProtocolError(
|
|
3721
|
+
if (request.target === void 0 && (request.targets === void 0 || request.targets.length === 0)) {
|
|
3722
|
+
throw new DoclingProtocolError(
|
|
3723
|
+
"Batch conversion requires either 'target' or 'targets'"
|
|
3724
|
+
);
|
|
3713
3725
|
}
|
|
3714
|
-
if (
|
|
3726
|
+
if (request.target !== void 0 && request.targets !== void 0 && request.targets.length > 0) {
|
|
3715
3727
|
throw new DoclingProtocolError(
|
|
3716
|
-
|
|
3728
|
+
"Batch conversion received both 'target' and 'targets'; supply only one"
|
|
3717
3729
|
);
|
|
3718
3730
|
}
|
|
3719
|
-
|
|
3731
|
+
const effectiveTargets = request.targets && request.targets.length > 0 ? request.targets : request.target !== void 0 ? [request.target] : [];
|
|
3732
|
+
for (const target of effectiveTargets) {
|
|
3733
|
+
if (!isRecord4(target) || typeof target.kind !== "string" || target.kind === "") {
|
|
3734
|
+
throw new DoclingProtocolError("Batch target kind must not be empty");
|
|
3735
|
+
}
|
|
3736
|
+
if (["inbody", "zip", "put"].includes(target.kind)) {
|
|
3737
|
+
throw new DoclingProtocolError(
|
|
3738
|
+
`Batch conversion does not accept ${target.kind} targets`
|
|
3739
|
+
);
|
|
3740
|
+
}
|
|
3741
|
+
validateKnownConnector(target, "target");
|
|
3742
|
+
}
|
|
3720
3743
|
validateCallbacks(request.callbacks);
|
|
3721
3744
|
}
|
|
3722
3745
|
function validateChunkRequestOptions(request) {
|
|
@@ -4144,11 +4167,11 @@ function isRecord4(value) {
|
|
|
4144
4167
|
DoclingUsageLimitExceededError,
|
|
4145
4168
|
FetchTransport,
|
|
4146
4169
|
MAX_CONCURRENCY_LIMIT,
|
|
4170
|
+
appendFormValue,
|
|
4147
4171
|
applyPageLimits,
|
|
4148
4172
|
documentFromBundle,
|
|
4149
4173
|
documentFromJson,
|
|
4150
4174
|
fileSourceFromBinary,
|
|
4151
|
-
formValue,
|
|
4152
4175
|
materializePresignedResult,
|
|
4153
4176
|
normalizeSourceInput,
|
|
4154
4177
|
preflightFileSize,
|