mindee 5.4.0 → 5.5.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 +7 -0
- package/package.json +1 -1
- package/src/http/apiCore.d.ts +1 -0
- package/src/http/apiCore.js +21 -3
- package/src/image/extractedImage.d.ts +5 -5
- package/src/image/extractedImage.js +2 -2
- package/src/image/imageExtractor.d.ts +2 -2
- package/src/image/imageExtractor.js +4 -3
- package/src/pdf/extractedPdf.d.ts +3 -2
- package/src/pdf/extractedPdf.js +4 -3
- package/src/pdf/pdfExtractor.d.ts +2 -2
- package/src/pdf/pdfExtractor.js +1 -1
- package/src/v1/extraction/invoiceSplitterExtractor/extractedInvoiceSplitterImage.d.ts +3 -3
- package/src/v1/extraction/invoiceSplitterExtractor/extractedInvoiceSplitterImage.js +4 -4
- package/src/v1/extraction/multiReceiptsExtractor/extractedMultiReceiptImage.js +1 -1
- package/src/v2/client.d.ts +9 -1
- package/src/v2/client.js +17 -8
- package/src/v2/clientOptions/baseParameters.d.ts +3 -2
- package/src/v2/clientOptions/pollingOptions.d.ts +1 -1
- package/src/v2/clientOptions/pollingOptions.js +2 -2
- package/src/v2/fileOperations/crop.js +1 -3
- package/src/v2/fileOperations/split.js +1 -1
- package/src/v2/http/mindeeApiV2.d.ts +23 -10
- package/src/v2/http/mindeeApiV2.js +79 -68
- package/src/v2/parsing/search/index.d.ts +4 -0
- package/src/v2/parsing/search/index.js +4 -0
- package/src/v2/parsing/search/modelWebhook.d.ts +19 -0
- package/src/v2/parsing/search/modelWebhook.js +10 -0
- package/src/v2/parsing/search/paginationMetadata.d.ts +24 -0
- package/src/v2/parsing/search/paginationMetadata.js +19 -0
- package/src/v2/parsing/search/searchModel.d.ts +25 -0
- package/src/v2/parsing/search/searchModel.js +19 -0
- package/src/v2/parsing/search/searchResponse.d.ts +19 -0
- package/src/v2/parsing/search/searchResponse.js +24 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Mindee Node.js API Library Changelog
|
|
2
2
|
|
|
3
|
+
## v5.5.0 - 2026-07-01
|
|
4
|
+
### Fixes
|
|
5
|
+
* :memo: minor tweak to SKILL file
|
|
6
|
+
* :bug: retry once on connection error
|
|
7
|
+
* :recycle: rework and fix extractors (:boom: some **undocumented** functions break)
|
|
8
|
+
|
|
9
|
+
|
|
3
10
|
## v5.4.0 - 2026-06-22
|
|
4
11
|
### Fixes
|
|
5
12
|
* :bug: :boom: harmonize Crop and Split extraction (now ready for public use)
|
package/package.json
CHANGED
package/src/http/apiCore.d.ts
CHANGED
package/src/http/apiCore.js
CHANGED
|
@@ -20,14 +20,32 @@ export async function cutDocPages(inputDoc, pageOptions) {
|
|
|
20
20
|
* @returns the processed request.
|
|
21
21
|
*/
|
|
22
22
|
export async function sendRequestAndReadResponse(dispatcher, options, url) {
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
const requestUrl = new URL(url ?? `https://${options.hostname}${options.path}`);
|
|
24
|
+
if (options.queryParams) {
|
|
25
|
+
for (const [key, value] of Object.entries(options.queryParams)) {
|
|
26
|
+
requestUrl.searchParams.set(key, value);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const requestParams = {
|
|
25
30
|
method: options.method,
|
|
26
31
|
headers: options.headers,
|
|
27
32
|
headersTimeout: options.timeoutSecs * 1000,
|
|
28
33
|
body: options.body,
|
|
29
34
|
dispatcher: dispatcher,
|
|
30
|
-
}
|
|
35
|
+
};
|
|
36
|
+
let response;
|
|
37
|
+
try {
|
|
38
|
+
response = await request(requestUrl, requestParams);
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
// shenanigans in networking or freezing/thawing of the process in serverless environments
|
|
42
|
+
if (err.code === "UND_ERR_SOCKET" || err.code === "UND_ERR_CONNECT_TIMEOUT" || err.code === "ECONNRESET") {
|
|
43
|
+
logger.warn(`Socket error (${err.code}), retrying with a fresh connection...`);
|
|
44
|
+
response = await request(requestUrl, requestParams);
|
|
45
|
+
}
|
|
46
|
+
else
|
|
47
|
+
throw err;
|
|
48
|
+
}
|
|
31
49
|
logger.debug("Parsing the response ...");
|
|
32
50
|
let responseBody = await response.body.text();
|
|
33
51
|
// handle empty responses from server, for example, in the case of redirects
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { Buffer } from "node:buffer";
|
|
2
2
|
import { BufferInput } from "../input/index.js";
|
|
3
3
|
/**
|
|
4
|
-
* Generic class for image extraction
|
|
4
|
+
* Generic class for image extraction.
|
|
5
5
|
*/
|
|
6
6
|
export declare class ExtractedImage {
|
|
7
7
|
buffer: Buffer;
|
|
8
8
|
filename: string;
|
|
9
|
-
pageId
|
|
10
|
-
elementId
|
|
11
|
-
constructor(buffer: Uint8Array, fileName: string, pageId
|
|
9
|
+
readonly pageId: number;
|
|
10
|
+
readonly elementId: number;
|
|
11
|
+
constructor(buffer: Uint8Array, fileName: string, pageId: number, elementId: number);
|
|
12
12
|
/**
|
|
13
13
|
* Saves the document to a file.
|
|
14
14
|
*
|
|
@@ -27,5 +27,5 @@ export declare class ExtractedImage {
|
|
|
27
27
|
*
|
|
28
28
|
* @returns A BufferInput source.
|
|
29
29
|
*/
|
|
30
|
-
|
|
30
|
+
asInputSource(): BufferInput;
|
|
31
31
|
}
|
|
@@ -7,7 +7,7 @@ import { BufferInput, MIMETYPES } from "../input/index.js";
|
|
|
7
7
|
import { logger } from "../logger.js";
|
|
8
8
|
import { loadOptionalDependency } from "../dependency/index.js";
|
|
9
9
|
/**
|
|
10
|
-
* Generic class for image extraction
|
|
10
|
+
* Generic class for image extraction.
|
|
11
11
|
*/
|
|
12
12
|
export class ExtractedImage {
|
|
13
13
|
constructor(buffer, fileName, pageId, elementId) {
|
|
@@ -92,7 +92,7 @@ export class ExtractedImage {
|
|
|
92
92
|
*
|
|
93
93
|
* @returns A BufferInput source.
|
|
94
94
|
*/
|
|
95
|
-
|
|
95
|
+
asInputSource() {
|
|
96
96
|
return new BufferInput({
|
|
97
97
|
buffer: this.buffer,
|
|
98
98
|
filename: this.filename,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Polygon } from "../geometry/index.js";
|
|
2
|
-
import {
|
|
2
|
+
import { ExtractedImages } from "../image/extractedImages.js";
|
|
3
3
|
import { LocalInputSource } from "../input/index.js";
|
|
4
4
|
import type * as pdfLibTypes from "@cantoo/pdf-lib";
|
|
5
5
|
/**
|
|
@@ -8,7 +8,7 @@ import type * as pdfLibTypes from "@cantoo/pdf-lib";
|
|
|
8
8
|
* @param polygonsPerPage List of polygons to extract from per page.
|
|
9
9
|
* @param quality JPEG quality of extracted images.
|
|
10
10
|
*/
|
|
11
|
-
export declare function extractImagesFromPolygon(inputSource: LocalInputSource, polygonsPerPage: Map<number, Polygon[]>, quality?: number): Promise<
|
|
11
|
+
export declare function extractImagesFromPolygon(inputSource: LocalInputSource, polygonsPerPage: Map<number, Polygon[]>, quality?: number): Promise<ExtractedImages>;
|
|
12
12
|
/**
|
|
13
13
|
* Extracts elements from a page based off of a list of bounding boxes.
|
|
14
14
|
*
|
|
@@ -3,6 +3,7 @@ import { MindeeImageError } from "../errors/index.js";
|
|
|
3
3
|
import { getMinMaxX, getMinMaxY } from "../geometry/index.js";
|
|
4
4
|
import { adjustForRotation } from "../geometry/polygonUtils.js";
|
|
5
5
|
import { ExtractedImage } from "../image/extractedImage.js";
|
|
6
|
+
import { ExtractedImages } from "../image/extractedImages.js";
|
|
6
7
|
import { logger } from "../logger.js";
|
|
7
8
|
import { createPdfFromInputSource } from "../pdf/pdfOperation.js";
|
|
8
9
|
import { rasterizePage } from "../pdf/pdfUtils.js";
|
|
@@ -21,13 +22,13 @@ async function getPdfLib() {
|
|
|
21
22
|
* @param quality JPEG quality of extracted images.
|
|
22
23
|
*/
|
|
23
24
|
export async function extractImagesFromPolygon(inputSource, polygonsPerPage, quality) {
|
|
24
|
-
const allExtractedImages =
|
|
25
|
+
const allExtractedImages = new ExtractedImages();
|
|
25
26
|
const pdfDoc = await createPdfFromInputSource(inputSource);
|
|
26
27
|
for (const [pageId, polygons] of polygonsPerPage) {
|
|
27
28
|
logger.debug(`Extracting images from page ${pageId}`);
|
|
28
29
|
const pdfPage = pdfDoc.getPage(pageId);
|
|
29
|
-
const extractions =
|
|
30
|
-
const extractedImages = extractions.map((
|
|
30
|
+
const extractions = await extractFromPage(pdfPage, polygons, true, quality);
|
|
31
|
+
const extractedImages = extractions.map((buffer, elementId) => new ExtractedImage(buffer, inputSource.filename + `_page-${pageId}-item-${elementId}.jpg`, pageId, elementId));
|
|
31
32
|
allExtractedImages.push(...extractedImages);
|
|
32
33
|
}
|
|
33
34
|
return allExtractedImages;
|
|
@@ -4,7 +4,8 @@ export declare class ExtractedPdf {
|
|
|
4
4
|
readonly buffer: Buffer;
|
|
5
5
|
readonly filename: string;
|
|
6
6
|
readonly pageCount: number;
|
|
7
|
-
|
|
7
|
+
readonly pageIndexes: number[];
|
|
8
|
+
constructor(pdfData: Buffer<ArrayBufferLike>, filename: string, pageIndexes: number[]);
|
|
8
9
|
/**
|
|
9
10
|
* Saves the document to a file.
|
|
10
11
|
*
|
|
@@ -21,5 +22,5 @@ export declare class ExtractedPdf {
|
|
|
21
22
|
*
|
|
22
23
|
* @returns A BufferInput source.
|
|
23
24
|
*/
|
|
24
|
-
|
|
25
|
+
asInputSource(): BufferInput;
|
|
25
26
|
}
|
package/src/pdf/extractedPdf.js
CHANGED
|
@@ -5,10 +5,11 @@ import { writeFile } from "fs/promises";
|
|
|
5
5
|
import { logger } from "../logger.js";
|
|
6
6
|
import { writeFileSync } from "node:fs";
|
|
7
7
|
export class ExtractedPdf {
|
|
8
|
-
constructor(pdfData, filename,
|
|
8
|
+
constructor(pdfData, filename, pageIndexes) {
|
|
9
9
|
this.buffer = pdfData;
|
|
10
10
|
this.filename = filename;
|
|
11
|
-
this.pageCount =
|
|
11
|
+
this.pageCount = pageIndexes.length;
|
|
12
|
+
this.pageIndexes = pageIndexes;
|
|
12
13
|
}
|
|
13
14
|
/**
|
|
14
15
|
* Saves the document to a file.
|
|
@@ -56,7 +57,7 @@ export class ExtractedPdf {
|
|
|
56
57
|
*
|
|
57
58
|
* @returns A BufferInput source.
|
|
58
59
|
*/
|
|
59
|
-
|
|
60
|
+
asInputSource() {
|
|
60
61
|
return new BufferInput({
|
|
61
62
|
buffer: this.buffer,
|
|
62
63
|
filename: this.filename,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LocalInputSource } from "../input/index.js";
|
|
2
|
-
import {
|
|
2
|
+
import { ExtractedPdfs } from "../pdf/extractedPdfs.js";
|
|
3
3
|
export declare class PdfExtractor {
|
|
4
4
|
/**
|
|
5
5
|
* Buffer containing the PDF data.
|
|
@@ -42,5 +42,5 @@ export declare class PdfExtractor {
|
|
|
42
42
|
* Extracts pages from the PDF.
|
|
43
43
|
* @param pageIndexes
|
|
44
44
|
*/
|
|
45
|
-
extractSubDocuments(pageIndexes: number[][]): Promise<
|
|
45
|
+
extractSubDocuments(pageIndexes: number[][]): Promise<ExtractedPdfs>;
|
|
46
46
|
}
|
package/src/pdf/pdfExtractor.js
CHANGED
|
@@ -121,7 +121,7 @@ export class PdfExtractor {
|
|
|
121
121
|
const endPage = String(pageRange[pageRange.length - 1] + 1).padStart(3, "0");
|
|
122
122
|
const fieldFilename = `${splitName}_page_${startPage}-${endPage}.pdf`;
|
|
123
123
|
const page = await extractPages(this.sourcePdf, pageOptions);
|
|
124
|
-
this.extractedPdfs.push(new ExtractedPdf(page.file, fieldFilename, pageRange
|
|
124
|
+
this.extractedPdfs.push(new ExtractedPdf(page.file, fieldFilename, pageRange));
|
|
125
125
|
}
|
|
126
126
|
return this.extractedPdfs;
|
|
127
127
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ExtractedPdf } from "../../../pdf/index.js";
|
|
2
2
|
/**
|
|
3
3
|
* Wrapper class for extracted invoice pages.
|
|
4
4
|
*/
|
|
5
|
-
export declare class ExtractedInvoiceSplitterImage extends
|
|
5
|
+
export declare class ExtractedInvoiceSplitterImage extends ExtractedPdf {
|
|
6
6
|
readonly pageIdMin: number;
|
|
7
7
|
readonly pageIdMax: number;
|
|
8
|
-
constructor(
|
|
8
|
+
constructor(bytes: Uint8Array, pageIndices: [number, number]);
|
|
9
9
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ExtractedPdf } from "../../../pdf/index.js";
|
|
2
2
|
/**
|
|
3
3
|
* Wrapper class for extracted invoice pages.
|
|
4
4
|
*/
|
|
5
|
-
export class ExtractedInvoiceSplitterImage extends
|
|
6
|
-
constructor(
|
|
7
|
-
super(
|
|
5
|
+
export class ExtractedInvoiceSplitterImage extends ExtractedPdf {
|
|
6
|
+
constructor(bytes, pageIndices) {
|
|
7
|
+
super(Buffer.from(bytes), `invoice_p_${pageIndices[0]}-${pageIndices[1]}.pdf`, pageIndices);
|
|
8
8
|
this.pageIdMin = pageIndices[0];
|
|
9
9
|
this.pageIdMax = pageIndices[1];
|
|
10
10
|
}
|
|
@@ -4,7 +4,7 @@ import { ExtractedImage } from "../../../image/index.js";
|
|
|
4
4
|
*/
|
|
5
5
|
export class ExtractedMultiReceiptImage extends ExtractedImage {
|
|
6
6
|
constructor(buffer, pageId, receiptId) {
|
|
7
|
-
super(buffer, `receipt_p${pageId}_${receiptId}.pdf
|
|
7
|
+
super(buffer, `receipt_p${pageId}_${receiptId}.pdf`, pageId, receiptId);
|
|
8
8
|
this.pageId = pageId;
|
|
9
9
|
this.receiptId = receiptId;
|
|
10
10
|
}
|
package/src/v2/client.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Dispatcher } from "undici";
|
|
2
2
|
import { InputSource } from "../input/index.js";
|
|
3
3
|
import { JobResponse } from "./parsing/index.js";
|
|
4
|
+
import { SearchResponse } from "./parsing/search/index.js";
|
|
4
5
|
import { MindeeApiV2 } from "./http/mindeeApiV2.js";
|
|
5
6
|
import { PollingOptions, PollingOptionsConstructor } from "./clientOptions/index.js";
|
|
6
7
|
import { BaseProduct } from "../v2/product/baseProduct.js";
|
|
@@ -31,6 +32,13 @@ export declare class Client {
|
|
|
31
32
|
* @param {ClientOptions} options options for the initialization of a client.
|
|
32
33
|
*/
|
|
33
34
|
constructor({ apiKey, debug, dispatcher }?: ClientOptions);
|
|
35
|
+
/**
|
|
36
|
+
* Search for models available to the account.
|
|
37
|
+
* @param name Optional name filter.
|
|
38
|
+
* @param modelType Optional model type filter.
|
|
39
|
+
* @returns a `Promise` containing the search response.
|
|
40
|
+
*/
|
|
41
|
+
searchModels(name?: string, modelType?: string): Promise<SearchResponse>;
|
|
34
42
|
enqueue<P extends typeof BaseProduct>(product: P, inputSource: InputSource, params: InstanceType<P["parametersClass"]> | ConstructorParameters<P["parametersClass"]>[0]): Promise<JobResponse>;
|
|
35
43
|
/**
|
|
36
44
|
* Retrieves the result of a previously enqueued request.
|
|
@@ -79,5 +87,5 @@ export declare class Client {
|
|
|
79
87
|
* until the maximum number of tries is reached.
|
|
80
88
|
* @protected
|
|
81
89
|
*/
|
|
82
|
-
protected pollForResult<P extends typeof BaseProduct>(product: typeof BaseProduct, pollingOptions: PollingOptions,
|
|
90
|
+
protected pollForResult<P extends typeof BaseProduct>(product: typeof BaseProduct, pollingOptions: PollingOptions, jobResponse: JobResponse): Promise<InstanceType<P["responseClass"]>>;
|
|
83
91
|
}
|
package/src/v2/client.js
CHANGED
|
@@ -25,6 +25,15 @@ export class Client {
|
|
|
25
25
|
: LOG_LEVELS["warn"];
|
|
26
26
|
logger.debug("Client V2 Initialized");
|
|
27
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Search for models available to the account.
|
|
30
|
+
* @param name Optional name filter.
|
|
31
|
+
* @param modelType Optional model type filter.
|
|
32
|
+
* @returns a `Promise` containing the search response.
|
|
33
|
+
*/
|
|
34
|
+
async searchModels(name, modelType) {
|
|
35
|
+
return await this.mindeeApi.reqGetSearchModel(name, modelType);
|
|
36
|
+
}
|
|
28
37
|
async enqueue(product, inputSource, params) {
|
|
29
38
|
if (inputSource === undefined) {
|
|
30
39
|
throw new MindeeError("An input document is required.");
|
|
@@ -33,7 +42,7 @@ export class Client {
|
|
|
33
42
|
? params
|
|
34
43
|
: new product.parametersClass(params);
|
|
35
44
|
await inputSource.init();
|
|
36
|
-
const jobResponse = await this.mindeeApi.
|
|
45
|
+
const jobResponse = await this.mindeeApi.reqPostProductEnqueue(product, inputSource, paramsInstance);
|
|
37
46
|
if (jobResponse.job.id === undefined || jobResponse.job.id.length === 0) {
|
|
38
47
|
logger.error(`Failed enqueueing:\n${jobResponse.getRawHttp()}`);
|
|
39
48
|
throw new MindeeError("Enqueueing of the document failed.");
|
|
@@ -51,7 +60,7 @@ export class Client {
|
|
|
51
60
|
*/
|
|
52
61
|
async getResult(product, inferenceId) {
|
|
53
62
|
logger.debug(`Attempting to get inference with ID: ${inferenceId} using response type: ${product.name}`);
|
|
54
|
-
return await this.mindeeApi.
|
|
63
|
+
return await this.mindeeApi.reqGetProductResultById(product, inferenceId);
|
|
55
64
|
}
|
|
56
65
|
/**
|
|
57
66
|
* Retrieves the result of a previously enqueued request.
|
|
@@ -64,7 +73,7 @@ export class Client {
|
|
|
64
73
|
*/
|
|
65
74
|
async getResultByUrl(product, url) {
|
|
66
75
|
logger.debug(`Attempting to get inference from: ${url} using response type: ${product.name}`);
|
|
67
|
-
return await this.mindeeApi.
|
|
76
|
+
return await this.mindeeApi.reqGetProductResultByUrl(product, url);
|
|
68
77
|
}
|
|
69
78
|
/**
|
|
70
79
|
* Get the processing status of a previously enqueued request.
|
|
@@ -76,7 +85,7 @@ export class Client {
|
|
|
76
85
|
* parsing is complete.
|
|
77
86
|
*/
|
|
78
87
|
async getJob(jobId) {
|
|
79
|
-
return await this.mindeeApi.
|
|
88
|
+
return await this.mindeeApi.reqGetJobById(jobId);
|
|
80
89
|
}
|
|
81
90
|
/**
|
|
82
91
|
* Enqueue a request and poll the server until the result is sent or
|
|
@@ -94,22 +103,22 @@ export class Client {
|
|
|
94
103
|
const paramsInstance = new product.parametersClass(params);
|
|
95
104
|
const pollingOptionsInstance = new PollingOptions(pollingOptions);
|
|
96
105
|
const jobResponse = await this.enqueue(product, inputSource, paramsInstance);
|
|
97
|
-
return await this.pollForResult(product, pollingOptionsInstance, jobResponse
|
|
106
|
+
return await this.pollForResult(product, pollingOptionsInstance, jobResponse);
|
|
98
107
|
}
|
|
99
108
|
/**
|
|
100
109
|
* Send a document to an endpoint and poll the server until the result is sent or
|
|
101
110
|
* until the maximum number of tries is reached.
|
|
102
111
|
* @protected
|
|
103
112
|
*/
|
|
104
|
-
async pollForResult(product, pollingOptions,
|
|
113
|
+
async pollForResult(product, pollingOptions, jobResponse) {
|
|
105
114
|
logger.debug(`Waiting ${pollingOptions.initialDelaySec} seconds before polling.`);
|
|
106
115
|
await setTimeout(pollingOptions.initialDelaySec * 1000, undefined, pollingOptions.initialTimerOptions);
|
|
107
|
-
logger.debug(`Start polling for inference using job ID: ${
|
|
116
|
+
logger.debug(`Start polling for inference using job ID: ${jobResponse.job.id}.`);
|
|
108
117
|
let retryCounter = 1;
|
|
109
118
|
let pollResults;
|
|
110
119
|
while (retryCounter < pollingOptions.maxRetries + 1) {
|
|
111
120
|
logger.debug(`Attempt ${retryCounter} of ${pollingOptions.maxRetries}`);
|
|
112
|
-
pollResults = await this.
|
|
121
|
+
pollResults = await this.mindeeApi.reqGetJobByUrl(jobResponse.job.pollingUrl);
|
|
113
122
|
const error = pollResults.job.error;
|
|
114
123
|
if (error) {
|
|
115
124
|
throw new MindeeHttpErrorV2(error);
|
|
@@ -28,8 +28,9 @@ export declare abstract class BaseParameters {
|
|
|
28
28
|
*/
|
|
29
29
|
modelId: string;
|
|
30
30
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
31
|
+
* Optional: a free-form string to tag the request with your own identifier.
|
|
32
|
+
* For example, an internal document ID, reference number, or database key.
|
|
33
|
+
* If set, it will be included in the job and result responses.
|
|
33
34
|
*/
|
|
34
35
|
alias?: string;
|
|
35
36
|
/**
|
|
@@ -51,6 +51,6 @@ export declare class PollingOptions {
|
|
|
51
51
|
/** Options passed to every recurring `setTimeout()`. */
|
|
52
52
|
recurringTimerOptions?: TimerOptions;
|
|
53
53
|
constructor(params?: PollingOptionsConstructor);
|
|
54
|
-
|
|
54
|
+
validateSettings(): void;
|
|
55
55
|
toString(): string;
|
|
56
56
|
}
|
|
@@ -62,10 +62,10 @@ export class PollingOptions {
|
|
|
62
62
|
if (params.recurringTimerOptions) {
|
|
63
63
|
this.recurringTimerOptions = params.recurringTimerOptions;
|
|
64
64
|
}
|
|
65
|
-
this.
|
|
65
|
+
this.validateSettings();
|
|
66
66
|
logger.debug(`Polling options initialized: ${this.toString()}`);
|
|
67
67
|
}
|
|
68
|
-
|
|
68
|
+
validateSettings() {
|
|
69
69
|
if (this.delaySec < minDelaySec) {
|
|
70
70
|
throw new MindeeConfigurationError(`Cannot set auto-parsing delay to less than ${minDelaySec} second(s).`);
|
|
71
71
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { MindeeError } from "../../errors/index.js";
|
|
2
2
|
import { extractImagesFromPolygon } from "../../image/imageExtractor.js";
|
|
3
|
-
import { ExtractedImages } from "../../image/index.js";
|
|
4
3
|
import { logger } from "../../logger.js";
|
|
5
4
|
/**
|
|
6
5
|
* Extracts a single specified crop from a given input source.
|
|
@@ -32,6 +31,5 @@ export async function extractMultipleCrops(inputSource, crops, quality) {
|
|
|
32
31
|
}
|
|
33
32
|
polygonsByPage.get(pageId).push(crop.location.polygon);
|
|
34
33
|
}
|
|
35
|
-
|
|
36
|
-
return new ExtractedImages(...extractedCrops);
|
|
34
|
+
return await extractImagesFromPolygon(inputSource, polygonsByPage, quality);
|
|
37
35
|
}
|
|
@@ -32,7 +32,7 @@ export async function extractMultipleSplits(inputSource, splits) {
|
|
|
32
32
|
}
|
|
33
33
|
const pageCount = await pdfExtractor.getPageCount();
|
|
34
34
|
if (splits.length === 1 && splits[0].at(-1) === pageCount - 1) {
|
|
35
|
-
return new ExtractedPdfs(new ExtractedPdf(inputSource.fileObject, inputSource.filename,
|
|
35
|
+
return new ExtractedPdfs(new ExtractedPdf(inputSource.fileObject, inputSource.filename, splits[0]));
|
|
36
36
|
}
|
|
37
37
|
const subDocuments = await pdfExtractor.extractSubDocuments(pageGroups);
|
|
38
38
|
return new ExtractedPdfs(...subDocuments);
|
|
@@ -4,6 +4,7 @@ import { BaseParameters } from "../../v2/index.js";
|
|
|
4
4
|
import { JobResponse } from "../../v2/parsing/index.js";
|
|
5
5
|
import { InputSource } from "../../input/index.js";
|
|
6
6
|
import { BaseProduct } from "../../v2/product/baseProduct.js";
|
|
7
|
+
import { SearchResponse } from "../../v2/parsing/search/index.js";
|
|
7
8
|
/**
|
|
8
9
|
* Mindee V2 API handler.
|
|
9
10
|
*/
|
|
@@ -12,21 +13,33 @@ export declare class MindeeApiV2 {
|
|
|
12
13
|
settings: ApiSettings;
|
|
13
14
|
constructor(dispatcher?: Dispatcher, apiKey?: string);
|
|
14
15
|
/**
|
|
15
|
-
*
|
|
16
|
-
* @param
|
|
17
|
-
* @param
|
|
16
|
+
* Search for models available to the account.
|
|
17
|
+
* @param name Optional name filter.
|
|
18
|
+
* @param modelType Optional model type filter.
|
|
19
|
+
* @returns a `Promise` containing the search response.
|
|
20
|
+
*/
|
|
21
|
+
reqGetSearchModel(name?: string, modelType?: string): Promise<SearchResponse>;
|
|
22
|
+
/**
|
|
23
|
+
* Sends a document to the inference queue.
|
|
24
|
+
* @param product Product to enqueue.
|
|
25
|
+
* @param inputSource Local or remote file as an input.
|
|
18
26
|
* @param params {ExtractionParameters} parameters relating to the enqueueing options.
|
|
19
|
-
* @throws Error if the server's response contains an error.
|
|
20
|
-
* @returns a `Promise` containing a job response.
|
|
21
27
|
*/
|
|
22
|
-
|
|
28
|
+
reqPostProductEnqueue(product: typeof BaseProduct, inputSource: InputSource, params: BaseParameters): Promise<JobResponse>;
|
|
23
29
|
/**
|
|
24
|
-
* Get the specified Job.
|
|
30
|
+
* Get the specified Job by its ID.
|
|
25
31
|
* Throws an error if the server's response contains an error.
|
|
26
32
|
* @param jobId The Job ID as returned by the enqueue request.
|
|
27
33
|
* @returns a `Promise` containing the job response.
|
|
28
34
|
*/
|
|
29
|
-
|
|
35
|
+
reqGetJobById(jobId: string): Promise<JobResponse>;
|
|
36
|
+
/**
|
|
37
|
+
* Get the specified Job from a polling URL.
|
|
38
|
+
* Throws an error if the server's response contains an error.
|
|
39
|
+
* @param pollingUrl The polling URL as returned by a Job's pollingUrl property.
|
|
40
|
+
* @returns a `Promise` containing the job response.
|
|
41
|
+
*/
|
|
42
|
+
reqGetJobByUrl(pollingUrl: string): Promise<JobResponse>;
|
|
30
43
|
/**
|
|
31
44
|
* Get the result of a queued document from the API.
|
|
32
45
|
* Throws an error if the server's response contains an error.
|
|
@@ -34,7 +47,7 @@ export declare class MindeeApiV2 {
|
|
|
34
47
|
* @param inferenceId The inference ID for the result.
|
|
35
48
|
* @returns a `Promise` containing the parsed result.
|
|
36
49
|
*/
|
|
37
|
-
|
|
50
|
+
reqGetProductResultById<P extends typeof BaseProduct>(product: P, inferenceId: string): Promise<InstanceType<P["responseClass"]>>;
|
|
38
51
|
/**
|
|
39
52
|
* Get the result of a queued document from the API.
|
|
40
53
|
* Throws an error if the server's response contains an error.
|
|
@@ -42,5 +55,5 @@ export declare class MindeeApiV2 {
|
|
|
42
55
|
* @param url The URL as returned by a Job's resultUrl property.
|
|
43
56
|
* @returns a `Promise` containing the parsed result.
|
|
44
57
|
*/
|
|
45
|
-
|
|
58
|
+
reqGetProductResultByUrl<P extends typeof BaseProduct>(product: P, url: string): Promise<InstanceType<P["responseClass"]>>;
|
|
46
59
|
}
|
|
@@ -3,7 +3,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
3
3
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
4
4
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
5
|
};
|
|
6
|
-
var _MindeeApiV2_instances, _MindeeApiV2_processResponse
|
|
6
|
+
var _MindeeApiV2_instances, _MindeeApiV2_processResponse;
|
|
7
7
|
import { ApiSettings } from "./apiSettings.js";
|
|
8
8
|
import { ErrorResponse, JobResponse, } from "../../v2/parsing/index.js";
|
|
9
9
|
import { sendRequestAndReadResponse } from "../../http/apiCore.js";
|
|
@@ -11,6 +11,7 @@ import { LocalInputSource } from "../../input/index.js";
|
|
|
11
11
|
import { MindeeDeserializationError, MindeeError } from "../../errors/index.js";
|
|
12
12
|
import { MindeeHttpErrorV2 } from "./errors.js";
|
|
13
13
|
import { logger } from "../../logger.js";
|
|
14
|
+
import { SearchResponse } from "../../v2/parsing/search/index.js";
|
|
14
15
|
/**
|
|
15
16
|
* Mindee V2 API handler.
|
|
16
17
|
*/
|
|
@@ -20,29 +21,82 @@ export class MindeeApiV2 {
|
|
|
20
21
|
this.settings = new ApiSettings({ dispatcher: dispatcher, apiKey: apiKey });
|
|
21
22
|
}
|
|
22
23
|
/**
|
|
23
|
-
*
|
|
24
|
-
* @param
|
|
25
|
-
* @param
|
|
24
|
+
* Search for models available to the account.
|
|
25
|
+
* @param name Optional name filter.
|
|
26
|
+
* @param modelType Optional model type filter.
|
|
27
|
+
* @returns a `Promise` containing the search response.
|
|
28
|
+
*/
|
|
29
|
+
async reqGetSearchModel(name, modelType) {
|
|
30
|
+
const queryParams = {};
|
|
31
|
+
if (name)
|
|
32
|
+
queryParams["name"] = name;
|
|
33
|
+
if (modelType)
|
|
34
|
+
queryParams["model_type"] = modelType;
|
|
35
|
+
const options = {
|
|
36
|
+
method: "GET",
|
|
37
|
+
headers: this.settings.baseHeaders,
|
|
38
|
+
hostname: this.settings.hostname,
|
|
39
|
+
path: "/v2/search/models",
|
|
40
|
+
queryParams: queryParams,
|
|
41
|
+
timeoutSecs: this.settings.timeoutSecs,
|
|
42
|
+
};
|
|
43
|
+
const response = await sendRequestAndReadResponse(this.settings.dispatcher, options);
|
|
44
|
+
return __classPrivateFieldGet(this, _MindeeApiV2_instances, "m", _MindeeApiV2_processResponse).call(this, response, SearchResponse);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Sends a document to the inference queue.
|
|
48
|
+
* @param product Product to enqueue.
|
|
49
|
+
* @param inputSource Local or remote file as an input.
|
|
26
50
|
* @param params {ExtractionParameters} parameters relating to the enqueueing options.
|
|
27
|
-
* @throws Error if the server's response contains an error.
|
|
28
|
-
* @returns a `Promise` containing a job response.
|
|
29
51
|
*/
|
|
30
|
-
async
|
|
31
|
-
|
|
32
|
-
|
|
52
|
+
async reqPostProductEnqueue(product, inputSource, params) {
|
|
53
|
+
const form = params.getFormData();
|
|
54
|
+
if (inputSource instanceof LocalInputSource) {
|
|
55
|
+
form.set("file", new Blob([inputSource.fileObject]), inputSource.filename);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
form.set("url", inputSource.url);
|
|
59
|
+
}
|
|
60
|
+
const path = `/v2/products/${product.slug}/enqueue`;
|
|
61
|
+
const options = {
|
|
62
|
+
method: "POST",
|
|
63
|
+
headers: this.settings.baseHeaders,
|
|
64
|
+
hostname: this.settings.hostname,
|
|
65
|
+
path: path,
|
|
66
|
+
body: form,
|
|
67
|
+
timeoutSecs: this.settings.timeoutSecs,
|
|
68
|
+
};
|
|
69
|
+
const result = await sendRequestAndReadResponse(this.settings.dispatcher, options);
|
|
33
70
|
if (result.data.error !== undefined) {
|
|
34
71
|
throw new MindeeHttpErrorV2(result.data.error);
|
|
35
72
|
}
|
|
36
73
|
return __classPrivateFieldGet(this, _MindeeApiV2_instances, "m", _MindeeApiV2_processResponse).call(this, result, JobResponse);
|
|
37
74
|
}
|
|
38
75
|
/**
|
|
39
|
-
* Get the specified Job.
|
|
76
|
+
* Get the specified Job by its ID.
|
|
40
77
|
* Throws an error if the server's response contains an error.
|
|
41
78
|
* @param jobId The Job ID as returned by the enqueue request.
|
|
42
79
|
* @returns a `Promise` containing the job response.
|
|
43
80
|
*/
|
|
44
|
-
async
|
|
45
|
-
|
|
81
|
+
async reqGetJobById(jobId) {
|
|
82
|
+
return this.reqGetJobByUrl(`https://${this.settings.hostname}/v2/jobs/${jobId}`);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Get the specified Job from a polling URL.
|
|
86
|
+
* Throws an error if the server's response contains an error.
|
|
87
|
+
* @param pollingUrl The polling URL as returned by a Job's pollingUrl property.
|
|
88
|
+
* @returns a `Promise` containing the job response.
|
|
89
|
+
*/
|
|
90
|
+
async reqGetJobByUrl(pollingUrl) {
|
|
91
|
+
if (!pollingUrl.startsWith("https://")) {
|
|
92
|
+
throw new MindeeError(`Invalid URL: ${pollingUrl}`);
|
|
93
|
+
}
|
|
94
|
+
const options = {
|
|
95
|
+
method: "GET",
|
|
96
|
+
headers: this.settings.baseHeaders,
|
|
97
|
+
timeoutSecs: this.settings.timeoutSecs,
|
|
98
|
+
};
|
|
99
|
+
const response = await sendRequestAndReadResponse(this.settings.dispatcher, options, pollingUrl);
|
|
46
100
|
return __classPrivateFieldGet(this, _MindeeApiV2_instances, "m", _MindeeApiV2_processResponse).call(this, response, JobResponse);
|
|
47
101
|
}
|
|
48
102
|
/**
|
|
@@ -52,9 +106,8 @@ export class MindeeApiV2 {
|
|
|
52
106
|
* @param inferenceId The inference ID for the result.
|
|
53
107
|
* @returns a `Promise` containing the parsed result.
|
|
54
108
|
*/
|
|
55
|
-
async
|
|
56
|
-
|
|
57
|
-
return __classPrivateFieldGet(this, _MindeeApiV2_instances, "m", _MindeeApiV2_processResponse).call(this, queueResponse, product.responseClass);
|
|
109
|
+
async reqGetProductResultById(product, inferenceId) {
|
|
110
|
+
return this.reqGetProductResultByUrl(product, `https://${this.settings.hostname}/v2/products/${product.slug}/results/${inferenceId}`);
|
|
58
111
|
}
|
|
59
112
|
/**
|
|
60
113
|
* Get the result of a queued document from the API.
|
|
@@ -63,9 +116,17 @@ export class MindeeApiV2 {
|
|
|
63
116
|
* @param url The URL as returned by a Job's resultUrl property.
|
|
64
117
|
* @returns a `Promise` containing the parsed result.
|
|
65
118
|
*/
|
|
66
|
-
async
|
|
67
|
-
const
|
|
68
|
-
|
|
119
|
+
async reqGetProductResultByUrl(product, url) {
|
|
120
|
+
const options = {
|
|
121
|
+
method: "GET",
|
|
122
|
+
headers: this.settings.baseHeaders,
|
|
123
|
+
timeoutSecs: this.settings.timeoutSecs,
|
|
124
|
+
};
|
|
125
|
+
if (!url.startsWith("https://")) {
|
|
126
|
+
throw new MindeeError(`Invalid URL: ${url}`);
|
|
127
|
+
}
|
|
128
|
+
const response = await sendRequestAndReadResponse(this.settings.dispatcher, options, url);
|
|
129
|
+
return __classPrivateFieldGet(this, _MindeeApiV2_instances, "m", _MindeeApiV2_processResponse).call(this, response, product.responseClass);
|
|
69
130
|
}
|
|
70
131
|
}
|
|
71
132
|
_MindeeApiV2_instances = new WeakSet(), _MindeeApiV2_processResponse = function _MindeeApiV2_processResponse(result, responseClass) {
|
|
@@ -88,54 +149,4 @@ _MindeeApiV2_instances = new WeakSet(), _MindeeApiV2_processResponse = function
|
|
|
88
149
|
logger.error(`Raised '${e}' Couldn't deserialize response object:\n${JSON.stringify(result.data)}`);
|
|
89
150
|
throw new MindeeDeserializationError("Couldn't deserialize response object.");
|
|
90
151
|
}
|
|
91
|
-
}, _MindeeApiV2_reqPostProductEnqueue =
|
|
92
|
-
/**
|
|
93
|
-
* Sends a document to the inference queue.
|
|
94
|
-
* @param product Product to enqueue.
|
|
95
|
-
* @param inputSource Local or remote file as an input.
|
|
96
|
-
* @param params {ExtractionParameters} parameters relating to the enqueueing options.
|
|
97
|
-
*/
|
|
98
|
-
async function _MindeeApiV2_reqPostProductEnqueue(product, inputSource, params) {
|
|
99
|
-
const form = params.getFormData();
|
|
100
|
-
if (inputSource instanceof LocalInputSource) {
|
|
101
|
-
form.set("file", new Blob([inputSource.fileObject]), inputSource.filename);
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
form.set("url", inputSource.url);
|
|
105
|
-
}
|
|
106
|
-
const path = `/v2/products/${product.slug}/enqueue`;
|
|
107
|
-
const options = {
|
|
108
|
-
method: "POST",
|
|
109
|
-
headers: this.settings.baseHeaders,
|
|
110
|
-
hostname: this.settings.hostname,
|
|
111
|
-
path: path,
|
|
112
|
-
body: form,
|
|
113
|
-
timeoutSecs: this.settings.timeoutSecs,
|
|
114
|
-
};
|
|
115
|
-
return await sendRequestAndReadResponse(this.settings.dispatcher, options);
|
|
116
|
-
}, _MindeeApiV2_reqGetJob = async function _MindeeApiV2_reqGetJob(jobId) {
|
|
117
|
-
const options = {
|
|
118
|
-
method: "GET",
|
|
119
|
-
headers: this.settings.baseHeaders,
|
|
120
|
-
hostname: this.settings.hostname,
|
|
121
|
-
path: `/v2/jobs/${jobId}`,
|
|
122
|
-
timeoutSecs: this.settings.timeoutSecs,
|
|
123
|
-
};
|
|
124
|
-
return await sendRequestAndReadResponse(this.settings.dispatcher, options);
|
|
125
|
-
}, _MindeeApiV2_reqGetProductResult =
|
|
126
|
-
/**
|
|
127
|
-
* Make a request to GET the status of a document in the queue.
|
|
128
|
-
* @param url URL path to the result.
|
|
129
|
-
* @returns a `Promise` containing the parsed result.
|
|
130
|
-
*/
|
|
131
|
-
async function _MindeeApiV2_reqGetProductResult(url) {
|
|
132
|
-
const options = {
|
|
133
|
-
method: "GET",
|
|
134
|
-
headers: this.settings.baseHeaders,
|
|
135
|
-
timeoutSecs: this.settings.timeoutSecs,
|
|
136
|
-
};
|
|
137
|
-
if (!url.startsWith("https://")) {
|
|
138
|
-
throw new MindeeError(`Invalid URL: ${url}`);
|
|
139
|
-
}
|
|
140
|
-
return await sendRequestAndReadResponse(this.settings.dispatcher, options, url);
|
|
141
152
|
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { StringDict } from "../../../parsing/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Model webhook info.
|
|
4
|
+
*/
|
|
5
|
+
export declare class ModelWebhook {
|
|
6
|
+
/**
|
|
7
|
+
* ID of the webhook.
|
|
8
|
+
*/
|
|
9
|
+
id: string;
|
|
10
|
+
/**
|
|
11
|
+
* Name of the webhook.
|
|
12
|
+
*/
|
|
13
|
+
name: string;
|
|
14
|
+
/**
|
|
15
|
+
* URL of the webhook.
|
|
16
|
+
*/
|
|
17
|
+
url: string;
|
|
18
|
+
constructor(serverResponse: StringDict);
|
|
19
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { StringDict } from "../../../parsing/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* PaginationMetadata data associated with model search.
|
|
4
|
+
*/
|
|
5
|
+
export declare class PaginationMetadata {
|
|
6
|
+
/**
|
|
7
|
+
* Number of items per page.
|
|
8
|
+
*/
|
|
9
|
+
perPage: number;
|
|
10
|
+
/**
|
|
11
|
+
* 1-indexed page number.
|
|
12
|
+
*/
|
|
13
|
+
page: number;
|
|
14
|
+
/**
|
|
15
|
+
* Total items.
|
|
16
|
+
*/
|
|
17
|
+
totalItems: number;
|
|
18
|
+
/**
|
|
19
|
+
* Total number of pages.
|
|
20
|
+
*/
|
|
21
|
+
totalPages: number;
|
|
22
|
+
constructor(serverResponse: StringDict);
|
|
23
|
+
toString(): string;
|
|
24
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PaginationMetadata data associated with model search.
|
|
3
|
+
*/
|
|
4
|
+
export class PaginationMetadata {
|
|
5
|
+
constructor(serverResponse) {
|
|
6
|
+
this.perPage = serverResponse["per_page"];
|
|
7
|
+
this.page = serverResponse["page"];
|
|
8
|
+
this.totalItems = serverResponse["total_items"];
|
|
9
|
+
this.totalPages = serverResponse["total_pages"];
|
|
10
|
+
}
|
|
11
|
+
toString() {
|
|
12
|
+
return [
|
|
13
|
+
`:Per Page: ${this.perPage}`,
|
|
14
|
+
`:Page: ${this.page}`,
|
|
15
|
+
`:Total Items: ${this.totalItems}`,
|
|
16
|
+
`:Total Pages: ${this.totalPages}`,
|
|
17
|
+
].join("\n");
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { StringDict } from "../../../parsing/index.js";
|
|
2
|
+
import { ModelWebhook } from "./modelWebhook.js";
|
|
3
|
+
/**
|
|
4
|
+
* Models search response.
|
|
5
|
+
*/
|
|
6
|
+
export declare class SearchModel {
|
|
7
|
+
/**
|
|
8
|
+
* ID of the model.
|
|
9
|
+
*/
|
|
10
|
+
id: string;
|
|
11
|
+
/**
|
|
12
|
+
* Name of the model.
|
|
13
|
+
*/
|
|
14
|
+
name: string;
|
|
15
|
+
/**
|
|
16
|
+
* Type of the model.
|
|
17
|
+
*/
|
|
18
|
+
modelType: string;
|
|
19
|
+
/**
|
|
20
|
+
* Webhooks associated with the model.
|
|
21
|
+
*/
|
|
22
|
+
webhooks: ModelWebhook[];
|
|
23
|
+
constructor(serverResponse: StringDict);
|
|
24
|
+
toString(): string;
|
|
25
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ModelWebhook } from "./modelWebhook.js";
|
|
2
|
+
/**
|
|
3
|
+
* Models search response.
|
|
4
|
+
*/
|
|
5
|
+
export class SearchModel {
|
|
6
|
+
constructor(serverResponse) {
|
|
7
|
+
this.id = serverResponse["id"];
|
|
8
|
+
this.name = serverResponse["name"];
|
|
9
|
+
this.modelType = serverResponse["model_type"];
|
|
10
|
+
this.webhooks = (serverResponse["webhooks"] ?? []).map((webhook) => new ModelWebhook(webhook));
|
|
11
|
+
}
|
|
12
|
+
toString() {
|
|
13
|
+
return [
|
|
14
|
+
`:Name: ${this.name}`,
|
|
15
|
+
`:ID: ${this.id}`,
|
|
16
|
+
`:Model Type: ${this.modelType}`,
|
|
17
|
+
].join("\n");
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { StringDict } from "../../../parsing/index.js";
|
|
2
|
+
import { BaseResponse } from "../../../v2/parsing/baseResponse.js";
|
|
3
|
+
import { PaginationMetadata } from "./paginationMetadata.js";
|
|
4
|
+
import { SearchModel } from "./searchModel.js";
|
|
5
|
+
/**
|
|
6
|
+
* Models search response.
|
|
7
|
+
*/
|
|
8
|
+
export declare class SearchResponse extends BaseResponse {
|
|
9
|
+
/**
|
|
10
|
+
* List of models returned by the search.
|
|
11
|
+
*/
|
|
12
|
+
models: SearchModel[];
|
|
13
|
+
/**
|
|
14
|
+
* Pagination metadata.
|
|
15
|
+
*/
|
|
16
|
+
pagination: PaginationMetadata;
|
|
17
|
+
constructor(serverResponse: StringDict);
|
|
18
|
+
toString(): string;
|
|
19
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { BaseResponse } from "../../../v2/parsing/baseResponse.js";
|
|
2
|
+
import { PaginationMetadata } from "./paginationMetadata.js";
|
|
3
|
+
import { SearchModel } from "./searchModel.js";
|
|
4
|
+
/**
|
|
5
|
+
* Models search response.
|
|
6
|
+
*/
|
|
7
|
+
export class SearchResponse extends BaseResponse {
|
|
8
|
+
constructor(serverResponse) {
|
|
9
|
+
super(serverResponse);
|
|
10
|
+
this.models = (serverResponse["models"] ?? []).map((model) => new SearchModel(model));
|
|
11
|
+
this.pagination = new PaginationMetadata(serverResponse["pagination"]);
|
|
12
|
+
}
|
|
13
|
+
toString() {
|
|
14
|
+
const lines = ["Models", "#######"];
|
|
15
|
+
for (const model of this.models) {
|
|
16
|
+
lines.push(`* :Name: ${model.name}`);
|
|
17
|
+
lines.push(` :ID: ${model.id}`);
|
|
18
|
+
lines.push(` :Model Type: ${model.modelType}`);
|
|
19
|
+
}
|
|
20
|
+
lines.push("Pagination", "##########");
|
|
21
|
+
lines.push(this.pagination.toString());
|
|
22
|
+
return lines.join("\n");
|
|
23
|
+
}
|
|
24
|
+
}
|