mindee 4.31.1 → 4.33.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 -1
- package/README.md +7 -7
- package/package.json +9 -9
- package/src/clientV2.js +2 -2
- package/src/errors/mindeeError.d.ts +5 -2
- package/src/errors/mindeeError.js +6 -4
- package/src/http/mindeeApiV2.d.ts +1 -1
- package/src/http/mindeeApiV2.js +10 -5
- package/src/index.d.ts +1 -1
- package/src/index.js +2 -1
- package/src/input/sources/localInputSource.d.ts +16 -0
- package/src/input/sources/localInputSource.js +35 -21
- package/src/parsing/v2/errorItem.d.ts +15 -0
- package/src/parsing/v2/errorItem.js +15 -0
- package/src/parsing/v2/errorResponse.d.ts +25 -3
- package/src/parsing/v2/errorResponse.js +12 -0
- package/src/parsing/v2/index.d.ts +3 -1
- package/src/parsing/v2/index.js +5 -1
- package/src/parsing/v2/inferenceResult.d.ts +5 -0
- package/src/parsing/v2/inferenceResult.js +4 -0
- package/src/parsing/v2/ragMetadata.d.ts +8 -0
- package/src/parsing/v2/ragMetadata.js +9 -0
- package/src/pdf/pdfOperation.d.ts +5 -0
- package/src/pdf/pdfOperation.js +5 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
## v4.33.0 - 2025-10-27
|
|
4
|
+
### Changes
|
|
5
|
+
* :sparkles: add more details to V2 errors
|
|
6
|
+
* :sparkles: add RAG metadata in V2 results
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
## v4.32.0 - 2025-10-13
|
|
10
|
+
### Changes
|
|
11
|
+
* :sparkles: add getting page count of a local source
|
|
12
|
+
|
|
13
|
+
|
|
3
14
|
## v4.31.1 - 2025-10-08
|
|
4
15
|
### Fixes
|
|
5
16
|
* :bug: make sure input sources are only initialized once
|
|
@@ -7,7 +18,7 @@
|
|
|
7
18
|
|
|
8
19
|
## v4.31.0 - 2025-10-07
|
|
9
20
|
### Changes
|
|
10
|
-
* :sparkles: allow comparing
|
|
21
|
+
* :sparkles: allow comparing V2 field confidence
|
|
11
22
|
* :coffin: remove obsolete US Mail V2
|
|
12
23
|
|
|
13
24
|
|
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
[](https://opensource.org/licenses/MIT) [](https://opensource.org/licenses/MIT) [](https://github.com/mindee/mindee-api-nodejs) [](https://www.npmjs.com/package/mindee) [](https://www.npmjs.com/package/mindee)
|
|
2
2
|
|
|
3
3
|
# Mindee API Helper Library for Node.js
|
|
4
4
|
Quickly and easily connect to Mindee's API services using Node.js.
|
|
@@ -6,26 +6,26 @@ Quickly and easily connect to Mindee's API services using Node.js.
|
|
|
6
6
|
## Mindee API Versions
|
|
7
7
|
This client library has support for both Mindee platform versions.
|
|
8
8
|
|
|
9
|
-
###
|
|
10
|
-
This is the
|
|
9
|
+
### V2 - Latest
|
|
10
|
+
This is the latest platform located here:
|
|
11
11
|
|
|
12
12
|
https://app.mindee.com
|
|
13
13
|
|
|
14
14
|
It uses **API version 2**.
|
|
15
15
|
|
|
16
16
|
Consult the
|
|
17
|
-
**[
|
|
17
|
+
**[V2 Documentation](https://docs.mindee.com/integrations/client-libraries-sdk)**
|
|
18
18
|
|
|
19
19
|
|
|
20
|
-
###
|
|
21
|
-
This is the
|
|
20
|
+
### V1
|
|
21
|
+
This is the platform located here:
|
|
22
22
|
|
|
23
23
|
https://platform.mindee.com/
|
|
24
24
|
|
|
25
25
|
It uses **API version 1**.
|
|
26
26
|
|
|
27
27
|
Consult the
|
|
28
|
-
**[
|
|
28
|
+
**[V1 Documentation](https://docs.mindee.com/v1/libraries/nodejs-sdk)**
|
|
29
29
|
|
|
30
30
|
## Additional Information
|
|
31
31
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mindee",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.33.0",
|
|
4
4
|
"description": "Mindee Client Library for Node.js",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"bin": "bin/mindee.js",
|
|
@@ -44,16 +44,16 @@
|
|
|
44
44
|
"@types/mocha": "^10.0.10",
|
|
45
45
|
"@types/node": "^18.15.13",
|
|
46
46
|
"@types/tmp": "^0.2.6",
|
|
47
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
48
|
-
"@typescript-eslint/parser": "^8.
|
|
49
|
-
"chai": "^4.
|
|
50
|
-
"eslint": "^9.
|
|
51
|
-
"eslint-plugin-jsdoc": "^50.
|
|
52
|
-
"mocha": "^11.7.
|
|
47
|
+
"@typescript-eslint/eslint-plugin": "^8.42.1",
|
|
48
|
+
"@typescript-eslint/parser": "^8.42.1",
|
|
49
|
+
"chai": "^4.4.1",
|
|
50
|
+
"eslint": "^9.20.1",
|
|
51
|
+
"eslint-plugin-jsdoc": "^50.6.17",
|
|
52
|
+
"mocha": "^11.7.4",
|
|
53
53
|
"nock": "^13.5.6",
|
|
54
54
|
"ts-node": "^10.9.2",
|
|
55
|
-
"typedoc": "~0.28.
|
|
56
|
-
"typescript": "^5.
|
|
55
|
+
"typedoc": "~0.28.14",
|
|
56
|
+
"typescript": "^5.7.3"
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
59
|
"@cantoo/pdf-lib": "^2.3.2",
|
package/src/clientV2.js
CHANGED
|
@@ -105,7 +105,7 @@ class ClientV2 {
|
|
|
105
105
|
return this.getInference(pollResults.job.id);
|
|
106
106
|
}
|
|
107
107
|
logger_1.logger.debug(`Polling server for parsing result with queueId: ${queueId}.
|
|
108
|
-
Attempt
|
|
108
|
+
Attempt no. ${retryCounter} of ${validatedAsyncParams.maxRetries}.
|
|
109
109
|
Job status: ${pollResults.job.status}.`);
|
|
110
110
|
await (0, promises_1.setTimeout)(validatedAsyncParams.delaySec * 1000, undefined, validatedAsyncParams.recurringTimerOptions);
|
|
111
111
|
pollResults = await this.getJob(queueId);
|
|
@@ -113,7 +113,7 @@ Job status: ${pollResults.job.status}.`);
|
|
|
113
113
|
}
|
|
114
114
|
const error = pollResults.job.error;
|
|
115
115
|
if (error) {
|
|
116
|
-
throw new mindeeError_1.MindeeHttpErrorV2(error
|
|
116
|
+
throw new mindeeError_1.MindeeHttpErrorV2(error);
|
|
117
117
|
}
|
|
118
118
|
throw Error("Asynchronous parsing request timed out after " +
|
|
119
119
|
validatedAsyncParams.delaySec * retryCounter +
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ErrorDetails, ErrorResponse } from "../parsing/v2";
|
|
1
2
|
/**
|
|
2
3
|
* Main Mindee Error custom class.
|
|
3
4
|
*/
|
|
@@ -19,8 +20,10 @@ export declare class MindeePdfError extends MindeeError {
|
|
|
19
20
|
export declare class MindeeApiV2Error extends MindeeError {
|
|
20
21
|
constructor(message: string);
|
|
21
22
|
}
|
|
22
|
-
export declare class MindeeHttpErrorV2 extends MindeeError {
|
|
23
|
+
export declare class MindeeHttpErrorV2 extends MindeeError implements ErrorDetails {
|
|
23
24
|
status: number;
|
|
24
25
|
detail: string;
|
|
25
|
-
|
|
26
|
+
title: string;
|
|
27
|
+
code: string;
|
|
28
|
+
constructor(error: ErrorResponse);
|
|
26
29
|
}
|
|
@@ -43,10 +43,12 @@ class MindeeApiV2Error extends MindeeError {
|
|
|
43
43
|
}
|
|
44
44
|
exports.MindeeApiV2Error = MindeeApiV2Error;
|
|
45
45
|
class MindeeHttpErrorV2 extends MindeeError {
|
|
46
|
-
constructor(
|
|
47
|
-
super(`HTTP ${status} - ${detail}`);
|
|
48
|
-
this.status = status;
|
|
49
|
-
this.detail = detail;
|
|
46
|
+
constructor(error) {
|
|
47
|
+
super(`HTTP ${error.status} :: ${error.title} - ${error.detail}`);
|
|
48
|
+
this.status = error.status;
|
|
49
|
+
this.detail = error.detail;
|
|
50
|
+
this.title = error.title;
|
|
51
|
+
this.code = error.code;
|
|
50
52
|
this.name = "MindeeHttpErrorV2";
|
|
51
53
|
}
|
|
52
54
|
}
|
|
@@ -28,7 +28,7 @@ export declare class MindeeApiV2 {
|
|
|
28
28
|
* Throws an error if the server's response contains one.
|
|
29
29
|
* @param jobId The document's ID in the queue.
|
|
30
30
|
* @category Asynchronous
|
|
31
|
-
* @returns a `Promise` containing
|
|
31
|
+
* @returns a `Promise` containing information on the queue.
|
|
32
32
|
*/
|
|
33
33
|
reqGetJob(jobId: string): Promise<JobResponse>;
|
|
34
34
|
}
|
package/src/http/mindeeApiV2.js
CHANGED
|
@@ -36,8 +36,8 @@ class MindeeApiV2 {
|
|
|
36
36
|
throw new Error("Model ID must be provided");
|
|
37
37
|
}
|
|
38
38
|
const result = await __classPrivateFieldGet(this, _MindeeApiV2_instances, "m", _MindeeApiV2_documentEnqueuePost).call(this, inputSource, params);
|
|
39
|
-
if (result.data.error
|
|
40
|
-
throw new mindeeError_1.MindeeHttpErrorV2(result.data.error
|
|
39
|
+
if (result.data.error !== undefined) {
|
|
40
|
+
throw new mindeeError_1.MindeeHttpErrorV2(result.data.error);
|
|
41
41
|
}
|
|
42
42
|
return __classPrivateFieldGet(this, _MindeeApiV2_instances, "m", _MindeeApiV2_processResponse).call(this, result, v2_1.JobResponse);
|
|
43
43
|
}
|
|
@@ -57,7 +57,7 @@ class MindeeApiV2 {
|
|
|
57
57
|
* Throws an error if the server's response contains one.
|
|
58
58
|
* @param jobId The document's ID in the queue.
|
|
59
59
|
* @category Asynchronous
|
|
60
|
-
* @returns a `Promise` containing
|
|
60
|
+
* @returns a `Promise` containing information on the queue.
|
|
61
61
|
*/
|
|
62
62
|
async reqGetJob(jobId) {
|
|
63
63
|
const queueResponse = await __classPrivateFieldGet(this, _MindeeApiV2_instances, "m", _MindeeApiV2_inferenceResultReqGet).call(this, jobId, "jobs");
|
|
@@ -68,9 +68,14 @@ exports.MindeeApiV2 = MindeeApiV2;
|
|
|
68
68
|
_MindeeApiV2_instances = new WeakSet(), _MindeeApiV2_processResponse = function _MindeeApiV2_processResponse(result, responseType) {
|
|
69
69
|
if (result.messageObj?.statusCode && (result.messageObj?.statusCode > 399 || result.messageObj?.statusCode < 200)) {
|
|
70
70
|
if (result.data?.status !== null) {
|
|
71
|
-
throw new mindeeError_1.MindeeHttpErrorV2(
|
|
71
|
+
throw new mindeeError_1.MindeeHttpErrorV2(new v2_1.ErrorResponse(result.data));
|
|
72
72
|
}
|
|
73
|
-
throw new mindeeError_1.MindeeHttpErrorV2(
|
|
73
|
+
throw new mindeeError_1.MindeeHttpErrorV2(new v2_1.ErrorResponse({
|
|
74
|
+
status: result.messageObj?.statusCode ?? -1,
|
|
75
|
+
title: "Unknown Error",
|
|
76
|
+
detail: result.data?.detail ?? "The server returned an Unknown error.",
|
|
77
|
+
code: `${result.messageObj?.statusCode ?? -1}-000`,
|
|
78
|
+
}));
|
|
74
79
|
}
|
|
75
80
|
try {
|
|
76
81
|
return new responseType(result.data);
|
package/src/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export * as product from "./product";
|
|
|
2
2
|
export { Client, PredictOptions, WorkflowOptions } from "./client";
|
|
3
3
|
export { ClientV2, InferenceParameters, PollingOptions } from "./clientV2";
|
|
4
4
|
export { AsyncPredictResponse, PredictResponse, Inference, Prediction, Document, Page, } from "./parsing/common";
|
|
5
|
-
export { InferenceFile, InferenceResponse, JobResponse, RawText, } from "./parsing/v2";
|
|
5
|
+
export { InferenceFile, InferenceResponse, JobResponse, RawText, RagMetadata, } from "./parsing/v2";
|
|
6
6
|
export { InputSource, Base64Input, BufferInput, BytesInput, PathInput, StreamInput, UrlInput, PageOptions, PageOptionsOperation, LocalResponse } from "./input";
|
|
7
7
|
export * as internal from "./internal";
|
|
8
8
|
export * as imageOperations from "./imageOperations";
|
package/src/index.js
CHANGED
|
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.imageOperations = exports.internal = exports.LocalResponse = exports.PageOptionsOperation = exports.UrlInput = exports.StreamInput = exports.PathInput = exports.BytesInput = exports.BufferInput = exports.Base64Input = exports.InputSource = exports.RawText = exports.JobResponse = exports.InferenceResponse = exports.InferenceFile = exports.Page = exports.Document = exports.Prediction = exports.Inference = exports.PredictResponse = exports.AsyncPredictResponse = exports.ClientV2 = exports.Client = exports.product = void 0;
|
|
36
|
+
exports.imageOperations = exports.internal = exports.LocalResponse = exports.PageOptionsOperation = exports.UrlInput = exports.StreamInput = exports.PathInput = exports.BytesInput = exports.BufferInput = exports.Base64Input = exports.InputSource = exports.RagMetadata = exports.RawText = exports.JobResponse = exports.InferenceResponse = exports.InferenceFile = exports.Page = exports.Document = exports.Prediction = exports.Inference = exports.PredictResponse = exports.AsyncPredictResponse = exports.ClientV2 = exports.Client = exports.product = void 0;
|
|
37
37
|
exports.product = __importStar(require("./product"));
|
|
38
38
|
var client_1 = require("./client");
|
|
39
39
|
Object.defineProperty(exports, "Client", { enumerable: true, get: function () { return client_1.Client; } });
|
|
@@ -51,6 +51,7 @@ Object.defineProperty(exports, "InferenceFile", { enumerable: true, get: functio
|
|
|
51
51
|
Object.defineProperty(exports, "InferenceResponse", { enumerable: true, get: function () { return v2_1.InferenceResponse; } });
|
|
52
52
|
Object.defineProperty(exports, "JobResponse", { enumerable: true, get: function () { return v2_1.JobResponse; } });
|
|
53
53
|
Object.defineProperty(exports, "RawText", { enumerable: true, get: function () { return v2_1.RawText; } });
|
|
54
|
+
Object.defineProperty(exports, "RagMetadata", { enumerable: true, get: function () { return v2_1.RagMetadata; } });
|
|
54
55
|
var input_1 = require("./input");
|
|
55
56
|
Object.defineProperty(exports, "InputSource", { enumerable: true, get: function () { return input_1.InputSource; } });
|
|
56
57
|
Object.defineProperty(exports, "Base64Input", { enumerable: true, get: function () { return input_1.Base64Input; } });
|
|
@@ -11,6 +11,16 @@ export declare abstract class LocalInputSource extends InputSource {
|
|
|
11
11
|
*/
|
|
12
12
|
protected constructor({ inputType }: InputConstructor);
|
|
13
13
|
protected checkMimetype(): Promise<string>;
|
|
14
|
+
/**
|
|
15
|
+
* Returns the file object as a Buffer.
|
|
16
|
+
* @returns Buffer representation of the file object
|
|
17
|
+
* @protected
|
|
18
|
+
*/
|
|
19
|
+
protected getBuffer(): Buffer;
|
|
20
|
+
/**
|
|
21
|
+
* Determines whether the current file is a PDF.
|
|
22
|
+
* @returns {boolean} Returns true if the file is a PDF; otherwise, returns false.
|
|
23
|
+
*/
|
|
14
24
|
isPdf(): boolean;
|
|
15
25
|
/**
|
|
16
26
|
* Cut PDF pages.
|
|
@@ -41,4 +51,10 @@ export declare abstract class LocalInputSource extends InputSource {
|
|
|
41
51
|
* @return boolean
|
|
42
52
|
*/
|
|
43
53
|
hasSourceText(): Promise<boolean>;
|
|
54
|
+
/**
|
|
55
|
+
* Returns the number of pages in the input source.
|
|
56
|
+
* For PDFs, returns the actual page count. For images, returns 1.
|
|
57
|
+
* @return Promise<number> The number of pages
|
|
58
|
+
*/
|
|
59
|
+
getPageCount(): Promise<number>;
|
|
44
60
|
}
|
|
@@ -104,6 +104,21 @@ class LocalInputSource extends inputSource_1.InputSource {
|
|
|
104
104
|
logger_1.logger.debug(`File is of type: ${mimeType}`);
|
|
105
105
|
return mimeType;
|
|
106
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* Returns the file object as a Buffer.
|
|
109
|
+
* @returns Buffer representation of the file object
|
|
110
|
+
* @protected
|
|
111
|
+
*/
|
|
112
|
+
getBuffer() {
|
|
113
|
+
if (typeof this.fileObject === "string") {
|
|
114
|
+
return Buffer.from(this.fileObject);
|
|
115
|
+
}
|
|
116
|
+
return this.fileObject;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Determines whether the current file is a PDF.
|
|
120
|
+
* @returns {boolean} Returns true if the file is a PDF; otherwise, returns false.
|
|
121
|
+
*/
|
|
107
122
|
isPdf() {
|
|
108
123
|
if (!this.initialized) {
|
|
109
124
|
throw new Error("The `init()` method must be called before calling `isPdf()`.");
|
|
@@ -115,13 +130,9 @@ class LocalInputSource extends inputSource_1.InputSource {
|
|
|
115
130
|
* @param pageOptions
|
|
116
131
|
*/
|
|
117
132
|
async applyPageOptions(pageOptions) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
if (!(this.fileObject instanceof Buffer)) {
|
|
122
|
-
throw new Error(`Cannot modify an input source of type ${this.inputType}.`);
|
|
123
|
-
}
|
|
124
|
-
const processedPdf = await (0, pdf_2.extractPages)(this.fileObject, pageOptions);
|
|
133
|
+
await this.init();
|
|
134
|
+
const buffer = this.getBuffer();
|
|
135
|
+
const processedPdf = await (0, pdf_2.extractPages)(buffer, pageOptions);
|
|
125
136
|
this.fileObject = processedPdf.file;
|
|
126
137
|
}
|
|
127
138
|
/**
|
|
@@ -145,16 +156,8 @@ class LocalInputSource extends inputSource_1.InputSource {
|
|
|
145
156
|
* @returns A Promise that resolves when the compression is complete.
|
|
146
157
|
*/
|
|
147
158
|
async compress(quality = 85, maxWidth = null, maxHeight = null, forceSourceText = false, disableSourceText = true) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
let buffer;
|
|
152
|
-
if (typeof this.fileObject === "string") {
|
|
153
|
-
buffer = Buffer.from(this.fileObject);
|
|
154
|
-
}
|
|
155
|
-
else {
|
|
156
|
-
buffer = this.fileObject;
|
|
157
|
-
}
|
|
159
|
+
await this.init();
|
|
160
|
+
const buffer = this.getBuffer();
|
|
158
161
|
if (this.isPdf()) {
|
|
159
162
|
this.fileObject = await (0, pdf_1.compressPdf)(buffer, quality, forceSourceText, disableSourceText);
|
|
160
163
|
}
|
|
@@ -167,14 +170,25 @@ class LocalInputSource extends inputSource_1.InputSource {
|
|
|
167
170
|
* @return boolean
|
|
168
171
|
*/
|
|
169
172
|
async hasSourceText() {
|
|
170
|
-
|
|
171
|
-
await this.init();
|
|
172
|
-
}
|
|
173
|
+
await this.init();
|
|
173
174
|
if (!this.isPdf()) {
|
|
174
175
|
return false;
|
|
175
176
|
}
|
|
176
|
-
const buffer =
|
|
177
|
+
const buffer = this.getBuffer();
|
|
177
178
|
return (0, pdf_2.hasSourceText)(buffer);
|
|
178
179
|
}
|
|
180
|
+
/**
|
|
181
|
+
* Returns the number of pages in the input source.
|
|
182
|
+
* For PDFs, returns the actual page count. For images, returns 1.
|
|
183
|
+
* @return Promise<number> The number of pages
|
|
184
|
+
*/
|
|
185
|
+
async getPageCount() {
|
|
186
|
+
await this.init();
|
|
187
|
+
if (!this.isPdf()) {
|
|
188
|
+
return 1;
|
|
189
|
+
}
|
|
190
|
+
const buffer = this.getBuffer();
|
|
191
|
+
return (0, pdf_1.countPages)(buffer);
|
|
192
|
+
}
|
|
179
193
|
}
|
|
180
194
|
exports.LocalInputSource = LocalInputSource;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { StringDict } from "../common";
|
|
2
|
+
export declare class ErrorItem {
|
|
3
|
+
/**
|
|
4
|
+
* The HTTP status code returned by the server.
|
|
5
|
+
*/
|
|
6
|
+
pointer?: string;
|
|
7
|
+
/**
|
|
8
|
+
* Explicit information on the issue.
|
|
9
|
+
*/
|
|
10
|
+
detail: string;
|
|
11
|
+
/**
|
|
12
|
+
* @param serverResponse JSON response from the server.
|
|
13
|
+
*/
|
|
14
|
+
constructor(serverResponse: StringDict);
|
|
15
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ErrorItem = void 0;
|
|
4
|
+
class ErrorItem {
|
|
5
|
+
/**
|
|
6
|
+
* @param serverResponse JSON response from the server.
|
|
7
|
+
*/
|
|
8
|
+
constructor(serverResponse) {
|
|
9
|
+
if (serverResponse["pointer"] !== undefined) {
|
|
10
|
+
this.pointer = serverResponse["pointer"];
|
|
11
|
+
}
|
|
12
|
+
this.detail = serverResponse["detail"];
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.ErrorItem = ErrorItem;
|
|
@@ -1,13 +1,35 @@
|
|
|
1
1
|
import { StringDict } from "../common";
|
|
2
|
-
|
|
2
|
+
import { ErrorItem } from "./errorItem";
|
|
3
|
+
export interface ErrorDetails {
|
|
3
4
|
/**
|
|
4
|
-
* The HTTP code
|
|
5
|
+
* The HTTP status code returned by the server.
|
|
5
6
|
*/
|
|
6
7
|
status: number;
|
|
7
8
|
/**
|
|
8
|
-
*
|
|
9
|
+
* A human-readable explanation specific to the occurrence of the problem.
|
|
9
10
|
*/
|
|
10
11
|
detail: string;
|
|
12
|
+
/**
|
|
13
|
+
* A short, human-readable summary of the problem.
|
|
14
|
+
*/
|
|
15
|
+
title: string;
|
|
16
|
+
/**
|
|
17
|
+
* A machine-readable code specific to the occurrence of the problem.
|
|
18
|
+
*/
|
|
19
|
+
code: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Error response detailing a problem. The format adheres to RFC 9457.
|
|
23
|
+
*/
|
|
24
|
+
export declare class ErrorResponse implements ErrorDetails {
|
|
25
|
+
status: number;
|
|
26
|
+
detail: string;
|
|
27
|
+
title: string;
|
|
28
|
+
code: string;
|
|
29
|
+
/**
|
|
30
|
+
* A machine-readable code specific to the occurrence of the problem.
|
|
31
|
+
*/
|
|
32
|
+
errors: ErrorItem[];
|
|
11
33
|
/**
|
|
12
34
|
* @param serverResponse JSON response from the server.
|
|
13
35
|
*/
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ErrorResponse = void 0;
|
|
4
|
+
const errorItem_1 = require("./errorItem");
|
|
5
|
+
/**
|
|
6
|
+
* Error response detailing a problem. The format adheres to RFC 9457.
|
|
7
|
+
*/
|
|
4
8
|
class ErrorResponse {
|
|
5
9
|
/**
|
|
6
10
|
* @param serverResponse JSON response from the server.
|
|
@@ -8,6 +12,14 @@ class ErrorResponse {
|
|
|
8
12
|
constructor(serverResponse) {
|
|
9
13
|
this.status = serverResponse["status"];
|
|
10
14
|
this.detail = serverResponse["detail"];
|
|
15
|
+
this.title = serverResponse["title"];
|
|
16
|
+
this.code = serverResponse["code"];
|
|
17
|
+
if (serverResponse["errors"] !== undefined) {
|
|
18
|
+
this.errors = serverResponse["errors"].map((error) => new errorItem_1.ErrorItem(error));
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
this.errors = [];
|
|
22
|
+
}
|
|
11
23
|
}
|
|
12
24
|
}
|
|
13
25
|
exports.ErrorResponse = ErrorResponse;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { CommonResponse } from "./commonResponse";
|
|
2
|
-
export { ErrorResponse } from "./errorResponse";
|
|
2
|
+
export { ErrorResponse, ErrorDetails } from "./errorResponse";
|
|
3
|
+
export { ErrorItem } from "./errorItem";
|
|
3
4
|
export { Inference } from "./inference";
|
|
4
5
|
export { InferenceActiveOptions } from "./inferenceActiveOptions";
|
|
5
6
|
export { InferenceFile } from "./inferenceFile";
|
|
@@ -10,3 +11,4 @@ export { Job } from "./job";
|
|
|
10
11
|
export { JobResponse } from "./jobResponse";
|
|
11
12
|
export { RawText } from "./rawText";
|
|
12
13
|
export { JobWebhook } from "./jobWebhook";
|
|
14
|
+
export { RagMetadata } from "./ragMetadata";
|
package/src/parsing/v2/index.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.JobWebhook = exports.RawText = exports.JobResponse = exports.Job = exports.InferenceResult = exports.InferenceResponse = exports.InferenceModel = exports.InferenceFile = exports.InferenceActiveOptions = exports.Inference = exports.ErrorResponse = exports.CommonResponse = void 0;
|
|
3
|
+
exports.RagMetadata = exports.JobWebhook = exports.RawText = exports.JobResponse = exports.Job = exports.InferenceResult = exports.InferenceResponse = exports.InferenceModel = exports.InferenceFile = exports.InferenceActiveOptions = exports.Inference = exports.ErrorItem = exports.ErrorResponse = exports.CommonResponse = void 0;
|
|
4
4
|
var commonResponse_1 = require("./commonResponse");
|
|
5
5
|
Object.defineProperty(exports, "CommonResponse", { enumerable: true, get: function () { return commonResponse_1.CommonResponse; } });
|
|
6
6
|
var errorResponse_1 = require("./errorResponse");
|
|
7
7
|
Object.defineProperty(exports, "ErrorResponse", { enumerable: true, get: function () { return errorResponse_1.ErrorResponse; } });
|
|
8
|
+
var errorItem_1 = require("./errorItem");
|
|
9
|
+
Object.defineProperty(exports, "ErrorItem", { enumerable: true, get: function () { return errorItem_1.ErrorItem; } });
|
|
8
10
|
var inference_1 = require("./inference");
|
|
9
11
|
Object.defineProperty(exports, "Inference", { enumerable: true, get: function () { return inference_1.Inference; } });
|
|
10
12
|
var inferenceActiveOptions_1 = require("./inferenceActiveOptions");
|
|
@@ -25,3 +27,5 @@ var rawText_1 = require("./rawText");
|
|
|
25
27
|
Object.defineProperty(exports, "RawText", { enumerable: true, get: function () { return rawText_1.RawText; } });
|
|
26
28
|
var jobWebhook_1 = require("./jobWebhook");
|
|
27
29
|
Object.defineProperty(exports, "JobWebhook", { enumerable: true, get: function () { return jobWebhook_1.JobWebhook; } });
|
|
30
|
+
var ragMetadata_1 = require("./ragMetadata");
|
|
31
|
+
Object.defineProperty(exports, "RagMetadata", { enumerable: true, get: function () { return ragMetadata_1.RagMetadata; } });
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { InferenceFields } from "./field";
|
|
2
2
|
import { StringDict } from "../common";
|
|
3
3
|
import { RawText } from "./rawText";
|
|
4
|
+
import { RagMetadata } from "./ragMetadata";
|
|
4
5
|
export declare class InferenceResult {
|
|
5
6
|
/**
|
|
6
7
|
* Fields contained in the inference.
|
|
@@ -10,6 +11,10 @@ export declare class InferenceResult {
|
|
|
10
11
|
* Raw text extracted from all pages.
|
|
11
12
|
*/
|
|
12
13
|
rawText?: RawText;
|
|
14
|
+
/**
|
|
15
|
+
* RAG metadata.
|
|
16
|
+
*/
|
|
17
|
+
rag?: RagMetadata;
|
|
13
18
|
constructor(serverResponse: StringDict);
|
|
14
19
|
toString(): string;
|
|
15
20
|
}
|
|
@@ -3,12 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.InferenceResult = void 0;
|
|
4
4
|
const field_1 = require("./field");
|
|
5
5
|
const rawText_1 = require("./rawText");
|
|
6
|
+
const ragMetadata_1 = require("./ragMetadata");
|
|
6
7
|
class InferenceResult {
|
|
7
8
|
constructor(serverResponse) {
|
|
8
9
|
this.fields = new field_1.InferenceFields(serverResponse["fields"]);
|
|
9
10
|
if (serverResponse["raw_text"]) {
|
|
10
11
|
this.rawText = new rawText_1.RawText(serverResponse["raw_text"]);
|
|
11
12
|
}
|
|
13
|
+
if (serverResponse["rag"]) {
|
|
14
|
+
this.rag = new ragMetadata_1.RagMetadata(serverResponse["rag"]);
|
|
15
|
+
}
|
|
12
16
|
}
|
|
13
17
|
toString() {
|
|
14
18
|
return `Fields\n======\n${this.fields}`;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RagMetadata = void 0;
|
|
4
|
+
class RagMetadata {
|
|
5
|
+
constructor(serverResponse) {
|
|
6
|
+
this.retrievedDocumentId = serverResponse["retrieved_document_id"] ?? undefined;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
exports.RagMetadata = RagMetadata;
|
|
@@ -10,4 +10,9 @@ export interface SplitPdf {
|
|
|
10
10
|
* @returns the new cut pdf file.
|
|
11
11
|
*/
|
|
12
12
|
export declare function extractPages(file: Buffer, pageOptions: PageOptions): Promise<SplitPdf>;
|
|
13
|
+
/**
|
|
14
|
+
* Count the number of pages in a pdf file.
|
|
15
|
+
* @param file
|
|
16
|
+
* @returns the number of pages in the file.
|
|
17
|
+
*/
|
|
13
18
|
export declare function countPages(file: Buffer): Promise<number>;
|
package/src/pdf/pdfOperation.js
CHANGED
|
@@ -66,6 +66,11 @@ async function extractPages(file, pageOptions) {
|
|
|
66
66
|
const fileBuffer = Buffer.from(await newPdf.save());
|
|
67
67
|
return { file: fileBuffer, totalPagesRemoved: sumRemovedPages };
|
|
68
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Count the number of pages in a pdf file.
|
|
71
|
+
* @param file
|
|
72
|
+
* @returns the number of pages in the file.
|
|
73
|
+
*/
|
|
69
74
|
async function countPages(file) {
|
|
70
75
|
const currentPdf = await pdf_lib_1.PDFDocument.load(file, {
|
|
71
76
|
ignoreEncryption: true,
|