mindee 4.25.0 → 4.27.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 CHANGED
@@ -1,5 +1,18 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## v4.27.0 - 2025-04-23
4
+ ### Changes
5
+ * :sparkles: add support for RAG polling
6
+ * :sparkles: add extras accessor from inference
7
+ ### Fixes
8
+ * :bug: fix improper deserialization of extras in some instances
9
+
10
+
11
+ ## v4.26.0 - 2025-04-16
12
+ ### Changes
13
+ * :sparkles: add support for rag param in workflow executions
14
+
15
+
3
16
  ## v4.25.0 - 2025-04-08
4
17
  ### Changes
5
18
  * :sparkles: add support for Financial Document V1.12
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mindee",
3
- "version": "4.25.0",
3
+ "version": "4.27.0",
4
4
  "description": "Mindee Client Library for Node.js",
5
5
  "main": "src/index.js",
6
6
  "bin": "bin/mindee.js",
@@ -32,7 +32,7 @@
32
32
  },
33
33
  "author": {
34
34
  "name": "Mindee",
35
- "email": "devrel@mindee.com",
35
+ "email": "opensource@mindee.com",
36
36
  "url": "https://mindee.com/"
37
37
  },
38
38
  "bugs": {
package/src/client.d.ts CHANGED
@@ -17,6 +17,10 @@ interface BaseOptions {
17
17
  * This is done before sending the file to the server and is useful to avoid page limitations.
18
18
  */
19
19
  pageOptions?: PageOptions;
20
+ /**
21
+ * If set, will enable Retrieval-Augmented Generation (only works if a valid workflowId is set).
22
+ */
23
+ rag?: boolean;
20
24
  }
21
25
  /**
22
26
  * Options relating to predictions.
@@ -34,6 +38,10 @@ export interface PredictOptions extends BaseOptions {
34
38
  * Whether to include cropper results for each page.
35
39
  */
36
40
  cropper?: boolean;
41
+ /**
42
+ * The ID of the workflow.
43
+ */
44
+ workflowId?: string;
37
45
  }
38
46
  /**
39
47
  * Options relating to workflows.
package/src/client.js CHANGED
@@ -81,6 +81,9 @@ class Client {
81
81
  */
82
82
  async enqueue(productClass, inputSource, params = {}) {
83
83
  const endpoint = params?.endpoint ?? __classPrivateFieldGet(this, _Client_instances, "m", _Client_initializeOTSEndpoint).call(this, productClass);
84
+ if (params.workflowId) {
85
+ endpoint.useWorkflowId(params.workflowId);
86
+ }
84
87
  if (inputSource === undefined) {
85
88
  throw new Error("The 'parse' function requires an input document.");
86
89
  }
@@ -90,6 +93,8 @@ class Client {
90
93
  fullText: this.getBooleanParam(params.fullText),
91
94
  pageOptions: params?.pageOptions,
92
95
  cropper: this.getBooleanParam(params.cropper),
96
+ workflowId: params.workflowId,
97
+ rag: this.getBooleanParam(params.rag)
93
98
  });
94
99
  return new common_1.AsyncPredictResponse(productClass, rawResponse.data);
95
100
  }
@@ -15,6 +15,11 @@ export declare class Endpoint extends BaseEndpoint {
15
15
  /** Product's version, as a string. */
16
16
  version: string;
17
17
  constructor(urlName: string, owner: string, version: string, settings: ApiSettings);
18
+ /**
19
+ * Changes the url to a workflow ID.
20
+ * @param workflowId
21
+ */
22
+ useWorkflowId(workflowId: string): void;
18
23
  /**
19
24
  * Sends a document to the API and parses out the result.
20
25
  * Throws an error if the server's response contains one.
@@ -58,6 +63,7 @@ export declare class Endpoint extends BaseEndpoint {
58
63
  * @param includeWords
59
64
  * @param fullText
60
65
  * @param cropper
66
+ * @param rag
61
67
  */
62
- protected sendFileForPrediction(input: InputSource, predictUrl: string, includeWords?: boolean, fullText?: boolean, cropper?: boolean): Promise<EndpointResponse>;
68
+ protected sendFileForPrediction(input: InputSource, predictUrl: string, includeWords?: boolean, fullText?: boolean, cropper?: boolean, rag?: boolean): Promise<EndpointResponse>;
63
69
  }
@@ -27,6 +27,13 @@ class Endpoint extends baseEndpoint_1.BaseEndpoint {
27
27
  this.urlName = urlName;
28
28
  this.version = version;
29
29
  }
30
+ /**
31
+ * Changes the url to a workflow ID.
32
+ * @param workflowId
33
+ */
34
+ useWorkflowId(workflowId) {
35
+ this.urlRoot = `/v1/workflows/${workflowId}`;
36
+ }
30
37
  /**
31
38
  * Sends a document to the API and parses out the result.
32
39
  * Throws an error if the server's response contains one.
@@ -57,7 +64,7 @@ class Endpoint extends baseEndpoint_1.BaseEndpoint {
57
64
  if (params.pageOptions !== undefined) {
58
65
  await super.cutDocPages(params.inputDoc, params.pageOptions);
59
66
  }
60
- const response = await __classPrivateFieldGet(this, _Endpoint_instances, "m", _Endpoint_predictAsyncReqPost).call(this, params.inputDoc, params.includeWords, params.fullText, params.cropper);
67
+ const response = await __classPrivateFieldGet(this, _Endpoint_instances, "m", _Endpoint_predictAsyncReqPost).call(this, params.inputDoc, params.includeWords, params.fullText, params.cropper, params.rag);
61
68
  if (!(0, responseValidation_1.isValidAsyncResponse)(response)) {
62
69
  (0, error_1.handleError)(this.urlName, response, this.extractStatusMessage(response));
63
70
  }
@@ -129,13 +136,17 @@ class Endpoint extends baseEndpoint_1.BaseEndpoint {
129
136
  * @param includeWords
130
137
  * @param fullText
131
138
  * @param cropper
139
+ * @param rag
132
140
  */
133
- sendFileForPrediction(input, predictUrl, includeWords = false, fullText = false, cropper = false) {
141
+ sendFileForPrediction(input, predictUrl, includeWords = false, fullText = false, cropper = false, rag = false) {
134
142
  return new Promise((resolve, reject) => {
135
143
  const searchParams = new url_1.URLSearchParams();
136
144
  if (cropper) {
137
145
  searchParams.append("cropper", "true");
138
146
  }
147
+ if (rag) {
148
+ searchParams.append("rag", "true");
149
+ }
139
150
  if (fullText) {
140
151
  searchParams.append("full_text_ocr", "true");
141
152
  }
@@ -173,8 +184,8 @@ class Endpoint extends baseEndpoint_1.BaseEndpoint {
173
184
  exports.Endpoint = Endpoint;
174
185
  _Endpoint_instances = new WeakSet(), _Endpoint_predictReqPost = function _Endpoint_predictReqPost(input, includeWords = false, fullText = false, cropper = false) {
175
186
  return this.sendFileForPrediction(input, "predict", includeWords, fullText, cropper);
176
- }, _Endpoint_predictAsyncReqPost = function _Endpoint_predictAsyncReqPost(input, includeWords = false, fullText = false, cropper = false) {
177
- return this.sendFileForPrediction(input, "predict_async", includeWords, fullText, cropper);
187
+ }, _Endpoint_predictAsyncReqPost = function _Endpoint_predictAsyncReqPost(input, includeWords = false, fullText = false, cropper = false, rag = false) {
188
+ return this.sendFileForPrediction(input, "predict_async", includeWords, fullText, cropper, rag);
178
189
  }, _Endpoint_documentQueueReqGet = function _Endpoint_documentQueueReqGet(queueId) {
179
190
  return new Promise((resolve, reject) => {
180
191
  const options = {
@@ -4,10 +4,12 @@ interface HTTPParams {
4
4
  inputDoc: InputSource;
5
5
  fullText: boolean;
6
6
  pageOptions?: PageOptions;
7
+ rag?: boolean;
7
8
  }
8
9
  export interface PredictParams extends HTTPParams {
9
10
  includeWords: boolean;
10
11
  cropper: boolean;
12
+ workflowId?: string;
11
13
  }
12
14
  export interface WorkflowParams extends HTTPParams {
13
15
  alias?: string;
@@ -24,6 +24,7 @@ export declare class WorkflowEndpoint extends BaseEndpoint {
24
24
  * @param priority
25
25
  * @param fullText
26
26
  * @param publicUrl
27
+ * @param rag
27
28
  */
28
- protected sendFileForPrediction(input: InputSource, alias?: string | null, priority?: ExecutionPriority | null, fullText?: boolean, publicUrl?: string | null): Promise<EndpointResponse>;
29
+ protected sendFileForPrediction(input: InputSource, alias?: string | null, priority?: ExecutionPriority | null, fullText?: boolean, publicUrl?: string | null, rag?: boolean | null): Promise<EndpointResponse>;
29
30
  }
@@ -11,9 +11,9 @@ var _WorkflowEndpoint_instances, _WorkflowEndpoint_workflowReqPost;
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.WorkflowEndpoint = void 0;
13
13
  const baseEndpoint_1 = require("./baseEndpoint");
14
+ const input_1 = require("../input");
14
15
  const url_1 = require("url");
15
16
  const form_data_1 = __importDefault(require("form-data"));
16
- const input_1 = require("../input");
17
17
  const responseValidation_1 = require("./responseValidation");
18
18
  const error_1 = require("./error");
19
19
  /**
@@ -36,7 +36,7 @@ class WorkflowEndpoint extends baseEndpoint_1.BaseEndpoint {
36
36
  if (params.pageOptions !== undefined) {
37
37
  await super.cutDocPages(params.inputDoc, params.pageOptions);
38
38
  }
39
- const response = await __classPrivateFieldGet(this, _WorkflowEndpoint_instances, "m", _WorkflowEndpoint_workflowReqPost).call(this, params.inputDoc, params.alias, params.priority, params.fullText, params.publicUrl);
39
+ const response = await __classPrivateFieldGet(this, _WorkflowEndpoint_instances, "m", _WorkflowEndpoint_workflowReqPost).call(this, params);
40
40
  if (!(0, responseValidation_1.isValidSyncResponse)(response)) {
41
41
  (0, error_1.handleError)(this.urlRoot, response, response.messageObj?.statusMessage);
42
42
  }
@@ -49,13 +49,17 @@ class WorkflowEndpoint extends baseEndpoint_1.BaseEndpoint {
49
49
  * @param priority
50
50
  * @param fullText
51
51
  * @param publicUrl
52
+ * @param rag
52
53
  */
53
- sendFileForPrediction(input, alias = null, priority = null, fullText = false, publicUrl = null) {
54
+ sendFileForPrediction(input, alias = null, priority = null, fullText = false, publicUrl = null, rag = null) {
54
55
  return new Promise((resolve, reject) => {
55
56
  const searchParams = new url_1.URLSearchParams();
56
57
  if (fullText) {
57
58
  searchParams.append("full_text_ocr", "true");
58
59
  }
60
+ if (rag) {
61
+ searchParams.append("rag", "true");
62
+ }
59
63
  const form = new form_data_1.default();
60
64
  if (input instanceof input_1.LocalInputSource && input.fileObject instanceof Buffer) {
61
65
  form.append("document", input.fileObject, {
@@ -94,6 +98,6 @@ class WorkflowEndpoint extends baseEndpoint_1.BaseEndpoint {
94
98
  }
95
99
  }
96
100
  exports.WorkflowEndpoint = WorkflowEndpoint;
97
- _WorkflowEndpoint_instances = new WeakSet(), _WorkflowEndpoint_workflowReqPost = function _WorkflowEndpoint_workflowReqPost(input, alias = null, priority = null, fullText = false, publicUrl = null) {
98
- return this.sendFileForPrediction(input, alias, priority, fullText, publicUrl);
101
+ _WorkflowEndpoint_instances = new WeakSet(), _WorkflowEndpoint_workflowReqPost = function _WorkflowEndpoint_workflowReqPost(params) {
102
+ return this.sendFileForPrediction(params.inputDoc, params.alias, params.priority, params.fullText, params.publicUrl, params.rag);
99
103
  };
@@ -11,7 +11,7 @@ export declare class Document<T extends Inference> {
11
11
  filename: string;
12
12
  /** Result of the base inference. */
13
13
  inference: T;
14
- /** Id of the document as sent back by the server. */
14
+ /** ID of the document as sent back by the server. */
15
15
  id: string;
16
16
  /** Potential `Extras` fields sent back along the prediction. */
17
17
  extras?: Extras;
@@ -4,6 +4,7 @@ exports.Document = void 0;
4
4
  const extras_1 = require("./extras");
5
5
  const extras_2 = require("./extras/extras");
6
6
  const ocr_1 = require("./ocr");
7
+ const ragExtra_1 = require("./extras/ragExtra");
7
8
  /**
8
9
  * Document prediction wrapper class. Holds the results of a parsed document.
9
10
  * @typeParam T an extension of an `Inference`. Mandatory in order to properly create an inference.
@@ -30,6 +31,9 @@ class Document {
30
31
  case "full_text_ocr":
31
32
  extras["fullTextOcr"] = new extras_1.FullTextOcrExtra(extraValue);
32
33
  break;
34
+ case "rag":
35
+ extras["rag"] = new ragExtra_1.RAGExtra(extraValue);
36
+ break;
33
37
  }
34
38
  });
35
39
  this.extras = new extras_2.Extras(extras);
@@ -59,8 +63,7 @@ ${this.inference?.toString()}`;
59
63
  return;
60
64
  }
61
65
  const fullTextOcr = rawPrediction["inference"]["pages"].filter((e) => "extras" in e).map((e) => e["extras"]["full_text_ocr"]["content"]).join("\n");
62
- // eslint-disable-next-line @typescript-eslint/naming-convention
63
- const artificialTextObj = { "full_text_ocr": { "content": fullTextOcr.length > 0 ? fullTextOcr : "" } };
66
+ const artificialTextObj = { "content": fullTextOcr.length > 0 ? fullTextOcr : "" };
64
67
  if (!this.extras) {
65
68
  this.extras = new extras_2.Extras({ "fullTextOcr": new extras_1.FullTextOcrExtra(artificialTextObj) });
66
69
  }
@@ -5,9 +5,9 @@ const extras_1 = require("./extras");
5
5
  class FullTextOcrExtra extends extras_1.ExtraField {
6
6
  constructor(rawPrediction) {
7
7
  super();
8
- if (rawPrediction["full_text_ocr"] !== undefined && rawPrediction["full_text_ocr"]["content"]) {
9
- this.content = "content" in rawPrediction["full_text_ocr"] ? rawPrediction["full_text_ocr"]["content"] : "";
10
- this.languages = "languages" in rawPrediction["full_text_ocr"] ? rawPrediction["full_text_ocr"]["languages"] : "";
8
+ if (rawPrediction["content"]) {
9
+ this.content = "content" in rawPrediction ? rawPrediction["content"] : "";
10
+ this.languages = "languages" in rawPrediction ? rawPrediction["languages"] : "";
11
11
  }
12
12
  }
13
13
  /**
@@ -0,0 +1,9 @@
1
+ import { ExtraField } from "./extras";
2
+ import { StringDict } from "../stringDict";
3
+ export declare class RAGExtra extends ExtraField {
4
+ /**
5
+ * ID reference of the document matched by the Retrieval-Augmented Generation.
6
+ */
7
+ matchingDocumentId?: string;
8
+ constructor(rawPrediction: StringDict);
9
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RAGExtra = void 0;
4
+ const extras_1 = require("./extras");
5
+ class RAGExtra extends extras_1.ExtraField {
6
+ constructor(rawPrediction) {
7
+ super();
8
+ if (rawPrediction["matching_document_id"]) {
9
+ this.matchingDocumentId = rawPrediction["matching_document_id"];
10
+ }
11
+ }
12
+ }
13
+ exports.RAGExtra = RAGExtra;
@@ -1,5 +1,5 @@
1
1
  import { StringDict } from "../common";
2
- import { ExtraField } from "./extras/extras";
2
+ import { Extras } from "./extras/extras";
3
3
  import { Page } from "./page";
4
4
  import type { Prediction } from "./prediction";
5
5
  import { Product } from "./product";
@@ -20,7 +20,7 @@ export declare abstract class Inference<DocT extends Prediction = Prediction, Pa
20
20
  /** A document's top-level `Prediction`. */
21
21
  prediction: DocT;
22
22
  /** Extraneous fields relating to specific tools for some APIs. */
23
- extras?: ExtraField[];
23
+ extras?: Extras;
24
24
  /** Name of a document's endpoint. Has a default value for OTS APIs. */
25
25
  endpointName?: string;
26
26
  /** A document's version. Has a default value for OTS APIs. */
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.InferenceFactory = exports.Inference = void 0;
4
+ const extras_1 = require("./extras");
5
+ const ragExtra_1 = require("./extras/ragExtra");
4
6
  /**
5
7
  *
6
8
  * @typeParam DocT an extension of a `Prediction`. Is generic by default to
@@ -12,10 +14,26 @@ class Inference {
12
14
  constructor(rawPrediction) {
13
15
  /** Wrapper for a document's pages prediction. */
14
16
  this.pages = [];
15
- /** Extraneous fields relating to specific tools for some APIs. */
16
- this.extras = [];
17
17
  this.isRotationApplied = rawPrediction?.is_rotation_applied ?? undefined;
18
18
  this.product = rawPrediction?.product;
19
+ if (rawPrediction["extras"] &&
20
+ Object.keys(rawPrediction["extras"].length > 0)) {
21
+ const extras = {};
22
+ Object.entries(rawPrediction["extras"]).forEach(([extraKey, extraValue]) => {
23
+ switch (extraKey) {
24
+ case "cropper":
25
+ extras.cropper = new extras_1.CropperExtra(extraValue);
26
+ break;
27
+ case "full_text_ocr":
28
+ extras.fullTextOcr = new extras_1.FullTextOcrExtra(extraValue);
29
+ break;
30
+ case "rag":
31
+ extras.rag = new ragExtra_1.RAGExtra(extraValue);
32
+ break;
33
+ }
34
+ });
35
+ this.extras = extras;
36
+ }
19
37
  }
20
38
  /**
21
39
  * Default string representation.
@@ -228,7 +228,7 @@ async function rasterizePage(pdfData, index, quality = 85) {
228
228
  return jpegBuffer;
229
229
  }
230
230
  catch (error) {
231
- console.error("Error rasterizing PDF:", error);
231
+ logger_1.logger.error("Error rasterizing PDF:", error);
232
232
  throw error;
233
233
  }
234
234
  finally {