mindee 4.34.0 → 4.36.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/CHANGELOG.md +12 -0
- package/package.json +2 -2
- package/src/clientV2.d.ts +12 -1
- package/src/clientV2.js +13 -0
- package/src/http/mindeeApiV2.js +3 -0
- package/src/imageOperations/common/extractedImage.d.ts +7 -0
- package/src/imageOperations/common/extractedImage.js +55 -2
- package/src/imageOperations/common/imageExtractor.js +12 -3
- package/src/input/dataSchema.d.ts +73 -0
- package/src/input/dataSchema.js +88 -0
- package/src/input/index.d.ts +2 -1
- package/src/input/index.js +7 -3
- package/src/input/sources/localInputSource.d.ts +1 -0
- package/src/input/sources/localInputSource.js +4 -4
- package/src/parsing/v2/dataSchemaActiveOption.d.ts +12 -0
- package/src/parsing/v2/dataSchemaActiveOption.js +15 -0
- package/src/parsing/v2/inferenceActiveOptions.d.ts +5 -0
- package/src/parsing/v2/inferenceActiveOptions.js +5 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
## v4.36.0 - 2025-12-19
|
|
4
|
+
### Changes
|
|
5
|
+
* :sparkles: add support for dataschema param
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
## v4.35.0 - 2025-12-16
|
|
9
|
+
### Changes
|
|
10
|
+
* :sparkles: add multi-receipt custom file saving formats
|
|
11
|
+
### Fixes
|
|
12
|
+
* :bug: fix image extractor dropping quality of extracted PDFs
|
|
13
|
+
|
|
14
|
+
|
|
3
15
|
## v4.34.0 - 2025-12-02
|
|
4
16
|
### Changes
|
|
5
17
|
* :sparkles: add support for text context
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mindee",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.36.0",
|
|
4
4
|
"description": "Mindee Client Library for Node.js",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"bin": "bin/mindee.js",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"CHANGELOG.md"
|
|
25
25
|
],
|
|
26
26
|
"engines": {
|
|
27
|
-
"node": ">=
|
|
27
|
+
"node": ">= 18"
|
|
28
28
|
},
|
|
29
29
|
"repository": {
|
|
30
30
|
"type": "git",
|
package/src/clientV2.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { InputSource } from "./input";
|
|
1
|
+
import { DataSchema, InputSource } from "./input";
|
|
2
2
|
import { InferenceResponse, JobResponse } from "./parsing/v2";
|
|
3
3
|
import { MindeeApiV2 } from "./http/mindeeApiV2";
|
|
4
|
+
import { StringDict } from "./parsing/common";
|
|
4
5
|
/**
|
|
5
6
|
* Parameters for the internal polling loop in {@link ClientV2.enqueueAndGetInference | enqueueAndGetInference()} .
|
|
6
7
|
*
|
|
@@ -88,6 +89,11 @@ export interface InferenceParameters {
|
|
|
88
89
|
/** By default, the file is closed once the upload is finished.
|
|
89
90
|
* Set to `false` to keep it open. */
|
|
90
91
|
closeFile?: boolean;
|
|
92
|
+
/**
|
|
93
|
+
* Dynamic changes to the data schema of the model for this inference.
|
|
94
|
+
* Not recommended, for specific use only.
|
|
95
|
+
*/
|
|
96
|
+
dataSchema?: DataSchema | StringDict | string;
|
|
91
97
|
}
|
|
92
98
|
/**
|
|
93
99
|
* Options for the V2 Mindee Client.
|
|
@@ -121,6 +127,11 @@ export declare class ClientV2 {
|
|
|
121
127
|
* @param {ClientOptions} options options for the initialization of a client.
|
|
122
128
|
*/
|
|
123
129
|
constructor({ apiKey, throwOnError, debug }?: ClientOptions);
|
|
130
|
+
/**
|
|
131
|
+
* Checks the Data Schema.
|
|
132
|
+
* @param params Input Inference parameters.
|
|
133
|
+
*/
|
|
134
|
+
validateDataSchema(params: InferenceParameters): void;
|
|
124
135
|
/**
|
|
125
136
|
* Send the document to an asynchronous endpoint and return its ID in the queue.
|
|
126
137
|
* @param inputSource file or URL to parse.
|
package/src/clientV2.js
CHANGED
|
@@ -7,6 +7,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
7
7
|
var _ClientV2_instances, _ClientV2_setAsyncParams;
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.ClientV2 = void 0;
|
|
10
|
+
const input_1 = require("./input");
|
|
10
11
|
const handler_1 = require("./errors/handler");
|
|
11
12
|
const logger_1 = require("./logger");
|
|
12
13
|
const promises_1 = require("node:timers/promises");
|
|
@@ -35,6 +36,17 @@ class ClientV2 {
|
|
|
35
36
|
: logger_1.LOG_LEVELS["warn"];
|
|
36
37
|
logger_1.logger.debug("ClientV2 initialized");
|
|
37
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Checks the Data Schema.
|
|
41
|
+
* @param params Input Inference parameters.
|
|
42
|
+
*/
|
|
43
|
+
validateDataSchema(params) {
|
|
44
|
+
if (params.dataSchema !== undefined && params.dataSchema !== null) {
|
|
45
|
+
if (!(params.dataSchema instanceof input_1.DataSchema)) {
|
|
46
|
+
params.dataSchema = new input_1.DataSchema(params.dataSchema);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
38
50
|
/**
|
|
39
51
|
* Send the document to an asynchronous endpoint and return its ID in the queue.
|
|
40
52
|
* @param inputSource file or URL to parse.
|
|
@@ -46,6 +58,7 @@ class ClientV2 {
|
|
|
46
58
|
if (inputSource === undefined) {
|
|
47
59
|
throw new Error("The 'enqueue' function requires an input document.");
|
|
48
60
|
}
|
|
61
|
+
this.validateDataSchema(params);
|
|
49
62
|
await inputSource.init();
|
|
50
63
|
return await this.mindeeApi.reqPostInferenceEnqueue(inputSource, params);
|
|
51
64
|
}
|
package/src/http/mindeeApiV2.js
CHANGED
|
@@ -102,6 +102,9 @@ _MindeeApiV2_instances = new WeakSet(), _MindeeApiV2_processResponse = function
|
|
|
102
102
|
if (params.textContext !== undefined && params.textContext !== null) {
|
|
103
103
|
form.append("text_context", params.textContext);
|
|
104
104
|
}
|
|
105
|
+
if (params.dataSchema !== undefined && params.dataSchema !== null) {
|
|
106
|
+
form.append("data_schema", params.dataSchema.toString());
|
|
107
|
+
}
|
|
105
108
|
if (params.webhookIds && params.webhookIds.length > 0) {
|
|
106
109
|
form.append("webhook_ids", params.webhookIds.join(","));
|
|
107
110
|
}
|
|
@@ -12,6 +12,13 @@ export declare class ExtractedImage {
|
|
|
12
12
|
*
|
|
13
13
|
* @param outputPath Path to save the file to.
|
|
14
14
|
*/
|
|
15
|
+
saveToFileAsync(outputPath: string): Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* Attempts to saves the document to a file synchronously.
|
|
18
|
+
* Throws an error if the file extension is not supported or if the file could not be saved to disk for some reason.
|
|
19
|
+
*
|
|
20
|
+
* @param outputPath Path to save the file to.
|
|
21
|
+
*/
|
|
15
22
|
saveToFile(outputPath: string): void;
|
|
16
23
|
/**
|
|
17
24
|
* Return the file as a Mindee-compatible BufferInput source.
|
|
@@ -10,6 +10,9 @@ const node_fs_1 = require("node:fs");
|
|
|
10
10
|
const node_path_1 = __importDefault(require("node:path"));
|
|
11
11
|
const logger_1 = require("../../logger");
|
|
12
12
|
const input_1 = require("../../input");
|
|
13
|
+
const localInputSource_1 = require("../../input/sources/localInputSource");
|
|
14
|
+
const node_poppler_1 = require("node-poppler");
|
|
15
|
+
const promises_1 = require("fs/promises");
|
|
13
16
|
/**
|
|
14
17
|
* Generic class for image extraction
|
|
15
18
|
*/
|
|
@@ -23,9 +26,33 @@ class ExtractedImage {
|
|
|
23
26
|
*
|
|
24
27
|
* @param outputPath Path to save the file to.
|
|
25
28
|
*/
|
|
26
|
-
|
|
29
|
+
async saveToFileAsync(outputPath) {
|
|
30
|
+
const fileExt = node_path_1.default.extname(outputPath).toLowerCase();
|
|
31
|
+
if (!localInputSource_1.MIMETYPES.has(fileExt)) {
|
|
32
|
+
throw new errors_1.MindeeError(`Unsupported file extension: ${fileExt}`);
|
|
33
|
+
}
|
|
27
34
|
try {
|
|
28
|
-
|
|
35
|
+
let outputBuffer = this.buffer;
|
|
36
|
+
if (fileExt !== ".pdf") {
|
|
37
|
+
const poppler = new node_poppler_1.Poppler();
|
|
38
|
+
const options = {
|
|
39
|
+
firstPageToConvert: 1,
|
|
40
|
+
lastPageToConvert: 1,
|
|
41
|
+
singleFile: true,
|
|
42
|
+
};
|
|
43
|
+
if (fileExt === ".png") {
|
|
44
|
+
options.pngFile = true;
|
|
45
|
+
}
|
|
46
|
+
else if (fileExt === ".jpg" || fileExt === ".jpeg") {
|
|
47
|
+
options.jpegFile = true;
|
|
48
|
+
}
|
|
49
|
+
else if (fileExt === ".tiff" || fileExt === ".tif") {
|
|
50
|
+
options.tiffFile = true;
|
|
51
|
+
}
|
|
52
|
+
const result = await poppler.pdfToCairo(this.buffer, undefined, options);
|
|
53
|
+
outputBuffer = node_buffer_1.Buffer.from(result, "latin1");
|
|
54
|
+
}
|
|
55
|
+
await (0, promises_1.writeFile)(node_path_1.default.resolve(outputPath), outputBuffer);
|
|
29
56
|
logger_1.logger.info(`File saved successfully to ${node_path_1.default.resolve(outputPath)}.`);
|
|
30
57
|
}
|
|
31
58
|
catch (e) {
|
|
@@ -37,6 +64,32 @@ class ExtractedImage {
|
|
|
37
64
|
}
|
|
38
65
|
}
|
|
39
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Attempts to saves the document to a file synchronously.
|
|
69
|
+
* Throws an error if the file extension is not supported or if the file could not be saved to disk for some reason.
|
|
70
|
+
*
|
|
71
|
+
* @param outputPath Path to save the file to.
|
|
72
|
+
*/
|
|
73
|
+
saveToFile(outputPath) {
|
|
74
|
+
const fileExt = node_path_1.default.extname(outputPath).toLowerCase();
|
|
75
|
+
if (fileExt !== ".pdf") {
|
|
76
|
+
throw new errors_1.MindeeError(`Unsupported file extension: ${fileExt}. For image formats, use saveToFileAsync() instead.`);
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
try {
|
|
80
|
+
(0, node_fs_1.writeFileSync)(node_path_1.default.resolve(outputPath), this.buffer);
|
|
81
|
+
logger_1.logger.info(`File saved successfully to ${node_path_1.default.resolve(outputPath)}.`);
|
|
82
|
+
}
|
|
83
|
+
catch (e) {
|
|
84
|
+
if (e instanceof TypeError) {
|
|
85
|
+
throw new errors_1.MindeeError("Invalid path/filename provided.");
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
throw e;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
40
93
|
/**
|
|
41
94
|
* Return the file as a Mindee-compatible BufferInput source.
|
|
42
95
|
*
|
|
@@ -12,6 +12,9 @@ const geometry_1 = require("../../geometry");
|
|
|
12
12
|
async function extractFromPage(pdfPage, polygons) {
|
|
13
13
|
const { width, height } = pdfPage.getSize();
|
|
14
14
|
const extractedElements = [];
|
|
15
|
+
// Manual upscale.
|
|
16
|
+
// Fixes issues with the OCR.
|
|
17
|
+
const qualityScale = 300 / 72;
|
|
15
18
|
for (const polygon of polygons) {
|
|
16
19
|
const tempPdf = await pdf_lib_1.PDFDocument.create();
|
|
17
20
|
const newWidth = width * ((0, geometry_1.getMinMaxX)(polygon).max - (0, geometry_1.getMinMaxX)(polygon).min);
|
|
@@ -22,10 +25,16 @@ async function extractFromPage(pdfPage, polygons) {
|
|
|
22
25
|
top: height - ((0, geometry_1.getMinMaxY)(polygon).min * height),
|
|
23
26
|
bottom: height - ((0, geometry_1.getMinMaxY)(polygon).max * height),
|
|
24
27
|
});
|
|
25
|
-
const samplePage = tempPdf.addPage([newWidth, newHeight]);
|
|
28
|
+
const samplePage = tempPdf.addPage([newWidth * qualityScale, newHeight * qualityScale]);
|
|
29
|
+
samplePage.drawRectangle({
|
|
30
|
+
x: 0,
|
|
31
|
+
y: 0,
|
|
32
|
+
width: newWidth * qualityScale,
|
|
33
|
+
height: newHeight * qualityScale,
|
|
34
|
+
});
|
|
26
35
|
samplePage.drawPage(cropped, {
|
|
27
|
-
width: newWidth,
|
|
28
|
-
height: newHeight,
|
|
36
|
+
width: newWidth * qualityScale,
|
|
37
|
+
height: newHeight * qualityScale,
|
|
29
38
|
});
|
|
30
39
|
extractedElements.push(await tempPdf.save());
|
|
31
40
|
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { StringDict } from "../parsing/common";
|
|
2
|
+
export declare class DataSchemaField {
|
|
3
|
+
/**
|
|
4
|
+
* Display name for the field, also impacts inference results.
|
|
5
|
+
*/
|
|
6
|
+
title: string;
|
|
7
|
+
/**
|
|
8
|
+
* Name of the field in the data schema.
|
|
9
|
+
*/
|
|
10
|
+
name: string;
|
|
11
|
+
/**
|
|
12
|
+
* Whether this field can contain multiple values.
|
|
13
|
+
*/
|
|
14
|
+
isArray: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Data type of the field.
|
|
17
|
+
*/
|
|
18
|
+
type: string;
|
|
19
|
+
/**
|
|
20
|
+
* Allowed values when type is `classification`. Leave empty for other types.
|
|
21
|
+
*/
|
|
22
|
+
classificationValues?: Array<string>;
|
|
23
|
+
/**
|
|
24
|
+
* Whether to remove duplicate values in the array.
|
|
25
|
+
* Only applicable if `is_array` is True.
|
|
26
|
+
*/
|
|
27
|
+
uniqueValues?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Detailed description of what this field represents.
|
|
30
|
+
*/
|
|
31
|
+
description?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Optional extraction guidelines.
|
|
34
|
+
*/
|
|
35
|
+
guidelines?: string;
|
|
36
|
+
/**
|
|
37
|
+
* Subfields when type is `nested_object`. Leave empty for other types.
|
|
38
|
+
*/
|
|
39
|
+
nestedFields?: StringDict;
|
|
40
|
+
constructor(fields: StringDict);
|
|
41
|
+
toJSON(): Record<string, unknown>;
|
|
42
|
+
toString(): string;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The structure to completely replace the data schema of the model.
|
|
46
|
+
*/
|
|
47
|
+
export declare class DataSchemaReplace {
|
|
48
|
+
/**
|
|
49
|
+
* List of fields in the Data Schema.
|
|
50
|
+
*/
|
|
51
|
+
fields: Array<DataSchemaField>;
|
|
52
|
+
constructor(dataSchemaReplace: StringDict);
|
|
53
|
+
toJSON(): {
|
|
54
|
+
fields: Record<string, unknown>[];
|
|
55
|
+
};
|
|
56
|
+
toString(): string;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Modify the Data Schema.
|
|
60
|
+
*/
|
|
61
|
+
export declare class DataSchema {
|
|
62
|
+
/**
|
|
63
|
+
* If set, completely replaces the data schema of the model.
|
|
64
|
+
*/
|
|
65
|
+
replace?: DataSchemaReplace;
|
|
66
|
+
constructor(dataSchema: StringDict | string);
|
|
67
|
+
toJSON(): {
|
|
68
|
+
replace: {
|
|
69
|
+
fields: Record<string, unknown>[];
|
|
70
|
+
} | undefined;
|
|
71
|
+
};
|
|
72
|
+
toString(): string;
|
|
73
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DataSchema = exports.DataSchemaReplace = exports.DataSchemaField = void 0;
|
|
4
|
+
const errors_1 = require("../errors");
|
|
5
|
+
class DataSchemaField {
|
|
6
|
+
constructor(fields) {
|
|
7
|
+
this.name = fields["name"];
|
|
8
|
+
this.title = fields["title"];
|
|
9
|
+
this.isArray = fields["is_array"];
|
|
10
|
+
this.type = fields["type"];
|
|
11
|
+
this.classificationValues = fields["classification_values"];
|
|
12
|
+
this.uniqueValues = fields["unique_values"];
|
|
13
|
+
this.description = fields["description"];
|
|
14
|
+
this.guidelines = fields["guidelines"];
|
|
15
|
+
this.nestedFields = fields["nested_fields"];
|
|
16
|
+
}
|
|
17
|
+
toJSON() {
|
|
18
|
+
const out = {
|
|
19
|
+
name: this.name,
|
|
20
|
+
title: this.title,
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention,camelcase
|
|
22
|
+
is_array: this.isArray,
|
|
23
|
+
type: this.type,
|
|
24
|
+
};
|
|
25
|
+
// eslint-disable-next-line camelcase
|
|
26
|
+
if (this.classificationValues !== undefined)
|
|
27
|
+
out.classification_values = this.classificationValues;
|
|
28
|
+
// eslint-disable-next-line camelcase
|
|
29
|
+
if (this.uniqueValues !== undefined)
|
|
30
|
+
out.unique_values = this.uniqueValues;
|
|
31
|
+
if (this.description !== undefined)
|
|
32
|
+
out.description = this.description;
|
|
33
|
+
if (this.guidelines !== undefined)
|
|
34
|
+
out.guidelines = this.guidelines;
|
|
35
|
+
// eslint-disable-next-line camelcase
|
|
36
|
+
if (this.nestedFields !== undefined)
|
|
37
|
+
out.nested_fields = this.nestedFields;
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
40
|
+
toString() {
|
|
41
|
+
return JSON.stringify(this.toJSON());
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.DataSchemaField = DataSchemaField;
|
|
45
|
+
/**
|
|
46
|
+
* The structure to completely replace the data schema of the model.
|
|
47
|
+
*/
|
|
48
|
+
class DataSchemaReplace {
|
|
49
|
+
constructor(dataSchemaReplace) {
|
|
50
|
+
if (!dataSchemaReplace || !dataSchemaReplace.fields) {
|
|
51
|
+
throw new errors_1.MindeeError("Invalid Data Schema provided.");
|
|
52
|
+
}
|
|
53
|
+
if (dataSchemaReplace["fields"].length === 0) {
|
|
54
|
+
throw new TypeError("Data Schema replacement fields cannot be empty.");
|
|
55
|
+
}
|
|
56
|
+
this.fields = dataSchemaReplace["fields"].map((field) => (new DataSchemaField(field)));
|
|
57
|
+
}
|
|
58
|
+
toJSON() {
|
|
59
|
+
return { fields: this.fields.map(e => e.toJSON()) };
|
|
60
|
+
}
|
|
61
|
+
toString() {
|
|
62
|
+
return JSON.stringify(this.toJSON());
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.DataSchemaReplace = DataSchemaReplace;
|
|
66
|
+
/**
|
|
67
|
+
* Modify the Data Schema.
|
|
68
|
+
*/
|
|
69
|
+
class DataSchema {
|
|
70
|
+
constructor(dataSchema) {
|
|
71
|
+
if (typeof dataSchema === "string") {
|
|
72
|
+
this.replace = new DataSchemaReplace(JSON.parse(dataSchema)["replace"]);
|
|
73
|
+
}
|
|
74
|
+
else if (dataSchema["replace"] instanceof DataSchemaReplace) {
|
|
75
|
+
this.replace = dataSchema["replace"];
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
this.replace = new DataSchemaReplace(dataSchema["replace"]);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
toJSON() {
|
|
82
|
+
return { replace: this.replace?.toJSON() };
|
|
83
|
+
}
|
|
84
|
+
toString() {
|
|
85
|
+
return JSON.stringify(this.toJSON());
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
exports.DataSchema = DataSchema;
|
package/src/input/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { DataSchema, DataSchemaField, DataSchemaReplace } from "./dataSchema";
|
|
2
2
|
export * from "./sources";
|
|
3
3
|
export { LocalResponse } from "./localResponse";
|
|
4
|
+
export { PageOptions, PageOptionsOperation } from "./pageOptions";
|
package/src/input/index.js
CHANGED
|
@@ -14,9 +14,13 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.LocalResponse = exports.
|
|
18
|
-
var
|
|
19
|
-
Object.defineProperty(exports, "
|
|
17
|
+
exports.PageOptionsOperation = exports.LocalResponse = exports.DataSchemaReplace = exports.DataSchemaField = exports.DataSchema = void 0;
|
|
18
|
+
var dataSchema_1 = require("./dataSchema");
|
|
19
|
+
Object.defineProperty(exports, "DataSchema", { enumerable: true, get: function () { return dataSchema_1.DataSchema; } });
|
|
20
|
+
Object.defineProperty(exports, "DataSchemaField", { enumerable: true, get: function () { return dataSchema_1.DataSchemaField; } });
|
|
21
|
+
Object.defineProperty(exports, "DataSchemaReplace", { enumerable: true, get: function () { return dataSchema_1.DataSchemaReplace; } });
|
|
20
22
|
__exportStar(require("./sources"), exports);
|
|
21
23
|
var localResponse_1 = require("./localResponse");
|
|
22
24
|
Object.defineProperty(exports, "LocalResponse", { enumerable: true, get: function () { return localResponse_1.LocalResponse; } });
|
|
25
|
+
var pageOptions_1 = require("./pageOptions");
|
|
26
|
+
Object.defineProperty(exports, "PageOptionsOperation", { enumerable: true, get: function () { return pageOptions_1.PageOptionsOperation; } });
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PageOptions } from "../pageOptions";
|
|
2
2
|
import { InputSource, InputConstructor } from "./inputSource";
|
|
3
|
+
export declare const MIMETYPES: Map<string, string>;
|
|
3
4
|
export declare abstract class LocalInputSource extends InputSource {
|
|
4
5
|
inputType: string;
|
|
5
6
|
filename: string;
|
|
@@ -36,7 +36,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.LocalInputSource = void 0;
|
|
39
|
+
exports.LocalInputSource = exports.MIMETYPES = void 0;
|
|
40
40
|
const handler_1 = require("../../errors/handler");
|
|
41
41
|
const logger_1 = require("../../logger");
|
|
42
42
|
const imageOperations_1 = require("../../imageOperations");
|
|
@@ -45,7 +45,7 @@ const path_1 = __importDefault(require("path"));
|
|
|
45
45
|
const fileType = __importStar(require("file-type"));
|
|
46
46
|
const pdf_2 = require("../../pdf");
|
|
47
47
|
const inputSource_1 = require("./inputSource");
|
|
48
|
-
|
|
48
|
+
exports.MIMETYPES = new Map([
|
|
49
49
|
[".pdf", "application/pdf"],
|
|
50
50
|
[".heic", "image/heic"],
|
|
51
51
|
[".jpg", "image/jpeg"],
|
|
@@ -85,7 +85,7 @@ class LocalInputSource extends inputSource_1.InputSource {
|
|
|
85
85
|
let mimeType;
|
|
86
86
|
const fileExt = path_1.default.extname(this.filename);
|
|
87
87
|
if (fileExt) {
|
|
88
|
-
mimeType = MIMETYPES.get(fileExt.toLowerCase()) || "";
|
|
88
|
+
mimeType = exports.MIMETYPES.get(fileExt.toLowerCase()) || "";
|
|
89
89
|
}
|
|
90
90
|
else {
|
|
91
91
|
const guess = await fileType.fromBuffer(this.fileObject);
|
|
@@ -97,7 +97,7 @@ class LocalInputSource extends inputSource_1.InputSource {
|
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
if (!mimeType) {
|
|
100
|
-
const allowed = Array.from(MIMETYPES.keys()).join(", ");
|
|
100
|
+
const allowed = Array.from(exports.MIMETYPES.keys()).join(", ");
|
|
101
101
|
const err = new Error(`Invalid file type, must be one of ${allowed}.`);
|
|
102
102
|
handler_1.errorHandler.throw(err);
|
|
103
103
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { StringDict } from "../common";
|
|
2
|
+
/**
|
|
3
|
+
* Data schema options activated during the inference.
|
|
4
|
+
*/
|
|
5
|
+
export declare class DataSchemaActiveOption {
|
|
6
|
+
/**
|
|
7
|
+
* Whether to replace the data schema.
|
|
8
|
+
*/
|
|
9
|
+
replace: boolean;
|
|
10
|
+
constructor(serverResponse: StringDict);
|
|
11
|
+
toString(): string;
|
|
12
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DataSchemaActiveOption = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Data schema options activated during the inference.
|
|
6
|
+
*/
|
|
7
|
+
class DataSchemaActiveOption {
|
|
8
|
+
constructor(serverResponse) {
|
|
9
|
+
this.replace = serverResponse["replace"];
|
|
10
|
+
}
|
|
11
|
+
toString() {
|
|
12
|
+
return `Data Schema\n-----------\n:Replace: ${this.replace ? "True" : "False"}`;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.DataSchemaActiveOption = DataSchemaActiveOption;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { StringDict } from "../common";
|
|
2
|
+
import { DataSchemaActiveOption } from "./dataSchemaActiveOption";
|
|
2
3
|
export declare class InferenceActiveOptions {
|
|
3
4
|
/**
|
|
4
5
|
* Whether the RAG feature was activated.
|
|
@@ -20,6 +21,10 @@ export declare class InferenceActiveOptions {
|
|
|
20
21
|
* Whether the text context feature was activated.
|
|
21
22
|
*/
|
|
22
23
|
textContext: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Data schema options provided for the inference.
|
|
26
|
+
*/
|
|
27
|
+
dataSchema: DataSchemaActiveOption;
|
|
23
28
|
constructor(serverResponse: StringDict);
|
|
24
29
|
toString(): string;
|
|
25
30
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.InferenceActiveOptions = void 0;
|
|
4
|
+
const dataSchemaActiveOption_1 = require("./dataSchemaActiveOption");
|
|
4
5
|
class InferenceActiveOptions {
|
|
5
6
|
constructor(serverResponse) {
|
|
6
7
|
this.rag = serverResponse["rag"];
|
|
@@ -8,6 +9,7 @@ class InferenceActiveOptions {
|
|
|
8
9
|
this.polygon = serverResponse["polygon"];
|
|
9
10
|
this.confidence = serverResponse["confidence"];
|
|
10
11
|
this.textContext = serverResponse["text_context"];
|
|
12
|
+
this.dataSchema = new dataSchemaActiveOption_1.DataSchemaActiveOption(serverResponse["data_schema"]);
|
|
11
13
|
}
|
|
12
14
|
toString() {
|
|
13
15
|
return "Active Options\n" +
|
|
@@ -15,7 +17,9 @@ class InferenceActiveOptions {
|
|
|
15
17
|
`:Raw Text: ${this.rawText ? "True" : "False"}\n` +
|
|
16
18
|
`:Polygon: ${this.polygon ? "True" : "False"}\n` +
|
|
17
19
|
`:Confidence: ${this.confidence ? "True" : "False"}\n` +
|
|
18
|
-
`:RAG: ${this.rag ? "True" : "False"}\n
|
|
20
|
+
`:RAG: ${this.rag ? "True" : "False"}\n` +
|
|
21
|
+
`:Text Context: ${this.textContext ? "True" : "False"}\n\n` +
|
|
22
|
+
`${this.dataSchema}\n`;
|
|
19
23
|
}
|
|
20
24
|
}
|
|
21
25
|
exports.InferenceActiveOptions = InferenceActiveOptions;
|