mindee 4.26.0 → 4.27.1

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,19 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## v4.27.1 - 2025-04-23
4
+ ### Fixes
5
+ * :bug: fix workflow polling not working when ran with ts-node
6
+ * :memo: add example script for workflow polling
7
+
8
+
9
+ ## v4.27.0 - 2025-04-23
10
+ ### Changes
11
+ * :sparkles: add support for RAG polling
12
+ * :sparkles: add extras accessor from inference
13
+ ### Fixes
14
+ * :bug: fix improper deserialization of extras in some instances
15
+
16
+
3
17
  ## v4.26.0 - 2025-04-16
4
18
  ### Changes
5
19
  * :sparkles: add support for rag param in workflow executions
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mindee",
3
- "version": "4.26.0",
3
+ "version": "4.27.1",
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.
@@ -52,10 +60,6 @@ export interface WorkflowOptions extends BaseOptions {
52
60
  * A unique, encrypted URL for accessing the document validation interface without requiring authentication.
53
61
  */
54
62
  publicUrl?: string;
55
- /**
56
- * Whether to enable Retrieval-Augmented Generation.
57
- */
58
- rag?: boolean;
59
63
  }
60
64
  /**
61
65
  * Asynchronous polling parameters.
package/src/client.js CHANGED
@@ -90,6 +90,8 @@ class Client {
90
90
  fullText: this.getBooleanParam(params.fullText),
91
91
  pageOptions: params?.pageOptions,
92
92
  cropper: this.getBooleanParam(params.cropper),
93
+ rag: this.getBooleanParam(params.rag),
94
+ workflowId: params.workflowId
93
95
  });
94
96
  return new common_1.AsyncPredictResponse(productClass, rawResponse.data);
95
97
  }
@@ -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,8 @@ export declare class Endpoint extends BaseEndpoint {
58
63
  * @param includeWords
59
64
  * @param fullText
60
65
  * @param cropper
66
+ * @param rag
67
+ * @param workflowId
61
68
  */
62
- protected sendFileForPrediction(input: InputSource, predictUrl: string, includeWords?: boolean, fullText?: boolean, cropper?: boolean): Promise<EndpointResponse>;
69
+ protected sendFileForPrediction(input: InputSource, predictUrl: string, includeWords?: boolean, fullText?: boolean, cropper?: boolean, rag?: boolean, workflowId?: string | undefined): Promise<EndpointResponse>;
63
70
  }
@@ -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, params.workflowId);
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,18 @@ class Endpoint extends baseEndpoint_1.BaseEndpoint {
129
136
  * @param includeWords
130
137
  * @param fullText
131
138
  * @param cropper
139
+ * @param rag
140
+ * @param workflowId
132
141
  */
133
- sendFileForPrediction(input, predictUrl, includeWords = false, fullText = false, cropper = false) {
142
+ sendFileForPrediction(input, predictUrl, includeWords = false, fullText = false, cropper = false, rag = false, workflowId = undefined) {
134
143
  return new Promise((resolve, reject) => {
135
144
  const searchParams = new url_1.URLSearchParams();
136
145
  if (cropper) {
137
146
  searchParams.append("cropper", "true");
138
147
  }
148
+ if (rag) {
149
+ searchParams.append("rag", "true");
150
+ }
139
151
  if (fullText) {
140
152
  searchParams.append("full_text_ocr", "true");
141
153
  }
@@ -152,7 +164,13 @@ class Endpoint extends baseEndpoint_1.BaseEndpoint {
152
164
  form.append("include_mvision", "true");
153
165
  }
154
166
  const headers = { ...this.settings.baseHeaders, ...form.getHeaders() };
155
- let path = `${this.urlRoot}/${predictUrl}`;
167
+ let path;
168
+ if (workflowId === undefined) {
169
+ path = `${this.urlRoot}/${predictUrl}`;
170
+ }
171
+ else {
172
+ path = `/v1/workflows/${workflowId}/predict_async`;
173
+ }
156
174
  if (searchParams.toString().length > 0) {
157
175
  path += `?${searchParams}`;
158
176
  }
@@ -173,8 +191,18 @@ class Endpoint extends baseEndpoint_1.BaseEndpoint {
173
191
  exports.Endpoint = Endpoint;
174
192
  _Endpoint_instances = new WeakSet(), _Endpoint_predictReqPost = function _Endpoint_predictReqPost(input, includeWords = false, fullText = false, cropper = false) {
175
193
  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);
194
+ }, _Endpoint_predictAsyncReqPost = function _Endpoint_predictAsyncReqPost(
195
+ /**
196
+ * Make a request to POST a document for async prediction.
197
+ * @param input
198
+ * @param includeWords
199
+ * @param fullText
200
+ * @param cropper
201
+ * @param rag
202
+ * @param workflowId
203
+ */
204
+ input, includeWords = false, fullText = false, cropper = false, rag = false, workflowId = undefined) {
205
+ return this.sendFileForPrediction(input, "predict_async", includeWords, fullText, cropper, rag, workflowId);
178
206
  }, _Endpoint_documentQueueReqGet = function _Endpoint_documentQueueReqGet(queueId) {
179
207
  return new Promise((resolve, reject) => {
180
208
  const options = {
@@ -4,15 +4,16 @@ 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;
14
16
  priority?: ExecutionPriority;
15
17
  publicUrl?: string;
16
- rag?: boolean;
17
18
  }
18
19
  export {};
@@ -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
29
  protected sendFileForPrediction(input: InputSource, alias?: string | null, priority?: ExecutionPriority | null, fullText?: boolean, publicUrl?: string | null, rag?: boolean | null): Promise<EndpointResponse>;
29
30
  }
@@ -49,6 +49,7 @@ class WorkflowEndpoint extends baseEndpoint_1.BaseEndpoint {
49
49
  * @param priority
50
50
  * @param fullText
51
51
  * @param publicUrl
52
+ * @param rag
52
53
  */
53
54
  sendFileForPrediction(input, alias = null, priority = null, fullText = false, publicUrl = null, rag = null) {
54
55
  return new Promise((resolve, reject) => {
@@ -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 {