diff --git a/docs/code_samples/workflow_execution.txt b/docs/code_samples/workflow_execution.txt deleted file mode 100644 index ee50c82b..00000000 --- a/docs/code_samples/workflow_execution.txt +++ /dev/null @@ -1,31 +0,0 @@ -// ESM or TypeScript (Recommended) -import * as mindee from "mindee"; - -// If you're on CommonJS: -// const mindee = require("mindee"); - -const workflowId: string = "workflow-id"; - -// Init a new client -const mindeeClient = new mindee.v1.Client( - { apiKey: "my-api-key" } -); - -// Load a file from disk -const inputSource = new mindee.PathInput( - { inputPath: "/path/to/the/file.ext" } -); - -// Parse the file asynchronously. -const asyncApiResponse = mindeeClient.executeWorkflow( - inputSource, - workflowId, - // Optionally: send an alias & priority - // { alias: "my-alias", priority: ExecutionPriority.low } -); - -// Handle the response Promise -asyncApiResponse.then((resp) => { - // print the execution id to make sure the request worked - console.log(resp.execution.id); -}); diff --git a/package-lock.json b/package-lock.json index 80794af2..4805066d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -969,9 +969,6 @@ "cpu": [ "arm" ], - "libc": [ - "glibc" - ], "license": "LGPL-3.0-or-later", "optional": true, "os": [ @@ -988,9 +985,6 @@ "cpu": [ "arm64" ], - "libc": [ - "glibc" - ], "license": "LGPL-3.0-or-later", "optional": true, "os": [ @@ -1007,9 +1001,6 @@ "cpu": [ "ppc64" ], - "libc": [ - "glibc" - ], "license": "LGPL-3.0-or-later", "optional": true, "os": [ @@ -1026,9 +1017,6 @@ "cpu": [ "riscv64" ], - "libc": [ - "glibc" - ], "license": "LGPL-3.0-or-later", "optional": true, "os": [ @@ -1045,9 +1033,6 @@ "cpu": [ "s390x" ], - "libc": [ - "glibc" - ], "license": "LGPL-3.0-or-later", "optional": true, "os": [ @@ -1064,9 +1049,6 @@ "cpu": [ "x64" ], - "libc": [ - "glibc" - ], "license": "LGPL-3.0-or-later", "optional": true, "os": [ @@ -1083,9 +1065,6 @@ "cpu": [ "arm64" ], - "libc": [ - "musl" - ], "license": "LGPL-3.0-or-later", "optional": true, "os": [ @@ -1102,9 +1081,6 @@ "cpu": [ "x64" ], - "libc": [ - "musl" - ], "license": "LGPL-3.0-or-later", "optional": true, "os": [ @@ -1121,9 +1097,6 @@ "cpu": [ "arm" ], - "libc": [ - "glibc" - ], "license": "Apache-2.0", "optional": true, "os": [ @@ -1146,9 +1119,6 @@ "cpu": [ "arm64" ], - "libc": [ - "glibc" - ], "license": "Apache-2.0", "optional": true, "os": [ @@ -1171,9 +1141,6 @@ "cpu": [ "ppc64" ], - "libc": [ - "glibc" - ], "license": "Apache-2.0", "optional": true, "os": [ @@ -1196,9 +1163,6 @@ "cpu": [ "riscv64" ], - "libc": [ - "glibc" - ], "license": "Apache-2.0", "optional": true, "os": [ @@ -1221,9 +1185,6 @@ "cpu": [ "s390x" ], - "libc": [ - "glibc" - ], "license": "Apache-2.0", "optional": true, "os": [ @@ -1246,9 +1207,6 @@ "cpu": [ "x64" ], - "libc": [ - "glibc" - ], "license": "Apache-2.0", "optional": true, "os": [ @@ -1271,9 +1229,6 @@ "cpu": [ "arm64" ], - "libc": [ - "musl" - ], "license": "Apache-2.0", "optional": true, "os": [ @@ -1296,9 +1251,6 @@ "cpu": [ "x64" ], - "libc": [ - "musl" - ], "license": "Apache-2.0", "optional": true, "os": [ @@ -1532,9 +1484,6 @@ "arm64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -1552,9 +1501,6 @@ "arm64" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -1572,9 +1518,6 @@ "x64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -1592,9 +1535,6 @@ "x64" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ diff --git a/src/v1/client.ts b/src/v1/client.ts index fce530d6..2495aec8 100644 --- a/src/v1/client.ts +++ b/src/v1/client.ts @@ -20,11 +20,8 @@ import { Inference, PredictResponse, StringDict, - WorkflowResponse, } from "./parsing/common/index.js"; import { InferenceFactory } from "./parsing/common/inference.js"; -import { GeneratedV1 } from "./product/index.js"; -import { WorkflowEndpoint } from "./http/index.js"; /** * Common options for workflows and predictions. @@ -276,34 +273,6 @@ export class Client { return new AsyncPredictResponse(productClass, docResponse.data); } - /** - * Send the document to an asynchronous endpoint and return its ID in the queue. - * @param inputSource file to send to the API. - * @param workflowId ID of the workflow. - * @param params parameters relating to prediction options. - * @category Workflow - * @returns a `Promise` containing the job (queue) corresponding to a document. - */ - async executeWorkflow( - inputSource: InputSource, - workflowId: string, - params: WorkflowOptions = {} - ): Promise> { - const workflowEndpoint = new WorkflowEndpoint(this.apiSettings, workflowId); - if (inputSource === undefined) { - throw new Error("The 'executeWorkflow' function requires an input document."); - } - const rawResponse = await workflowEndpoint.executeWorkflow({ - inputDoc: inputSource, - alias: params.alias, - priority: params.priority, - pageOptions: params?.pageOptions, - fullText: this.getBooleanParam(params.fullText), - }); - - return new WorkflowResponse(GeneratedV1, rawResponse.data); - } - /** * Fetch prediction results from a document already processed. * diff --git a/src/v1/http/index.ts b/src/v1/http/index.ts index 77ff1c36..71a8069d 100644 --- a/src/v1/http/index.ts +++ b/src/v1/http/index.ts @@ -15,5 +15,4 @@ export { MindeeHttp504Error, handleError, } from "./errors.js"; -export { WorkflowEndpoint } from "./workflowEndpoint.js"; export type { PredictParams, WorkflowParams } from "./httpParams.js"; diff --git a/src/v1/http/workflowEndpoint.ts b/src/v1/http/workflowEndpoint.ts deleted file mode 100644 index 306d3f67..00000000 --- a/src/v1/http/workflowEndpoint.ts +++ /dev/null @@ -1,120 +0,0 @@ -import { URLSearchParams } from "node:url"; -import { FormData } from "undici"; - -import { InputSource, LocalInputSource } from "@/input/index.js"; -import { ExecutionPriority } from "@/v1/parsing/common/index.js"; -import { - sendRequestAndReadResponse, - BaseHttpResponse, - RequestOptions, -} from "@/http/apiCore.js"; -import { ApiSettingsV1 } from "./apiSettingsV1.js"; -import { handleError } from "./errors.js"; -import { WorkflowParams } from "./httpParams.js"; -import { isValidSyncResponse } from "./responseValidation.js"; -import { BaseEndpoint } from "@/v1/http/baseEndpoint.js"; - -/** - * Endpoint for a workflow. - */ -export class WorkflowEndpoint extends BaseEndpoint { - - constructor( - settings: ApiSettingsV1, - workflowId: string - ) { - super(settings, `/v1/workflows/${workflowId}/executions`); - } - - /** - * Sends a document to a workflow execution. - * Throws an error if the server's response contains one. - * @param {WorkflowParams} params parameters relating to prediction options. - * @category Synchronous - * @returns a `Promise` containing parsing results. - */ - async executeWorkflow(params: WorkflowParams): Promise { - await params.inputDoc.init(); - if (params.pageOptions !== undefined) { - await this.cutDocPages(params.inputDoc, params.pageOptions); - } - const response = await this.#workflowReqPost(params); - if (!isValidSyncResponse(response)) { - handleError(this.urlRoot, response, response.messageObj?.statusMessage); - } - return response; - } - - /** - * Make a request to POST a document for workflow. - * - * @param {WorkflowParams} params parameters relating to prediction options. - */ - #workflowReqPost(params: WorkflowParams): Promise { - return this.sendFileForPrediction( - params.inputDoc, - params.alias, - params.priority, - params.fullText, - params.publicUrl, - params.rag - ); - } - - /** - * Send a file to a prediction API. - * @param input - * @param alias - * @param priority - * @param fullText - * @param publicUrl - * @param rag - */ - protected async sendFileForPrediction( - input: InputSource, - alias: string | null = null, - priority: ExecutionPriority | null = null, - fullText: boolean = false, - publicUrl: string | null = null, - rag: boolean | null = null, - ): Promise { - const searchParams = new URLSearchParams(); - if (fullText) { - searchParams.set("full_text_ocr", "true"); - } - if (rag) { - searchParams.set("rag", "true"); - } - - const form = new FormData(); - if (input instanceof LocalInputSource && input.fileObject instanceof Buffer) { - form.set("document", new Blob([input.fileObject]), input.filename); - } else { - form.set("document", input.fileObject); - } - if (alias) { - form.set("alias", alias); - } - if (publicUrl) { - form.set("public_url", publicUrl); - } - if (priority) { - form.set("priority", priority.toString()); - } - - let path = this.urlRoot; - if (searchParams.toString().length > 0) { - path += `?${searchParams}`; - } - - const options: RequestOptions = { - method: "POST", - headers: this.settings.baseHeaders, - hostname: this.settings.hostname, - path: path, - timeoutSecs: this.settings.timeoutSecs, - body: form, - }; - return await sendRequestAndReadResponse(this.settings.dispatcher, options); - } -} diff --git a/src/v1/parsing/common/index.ts b/src/v1/parsing/common/index.ts index 4dcedb4c..fdce1498 100644 --- a/src/v1/parsing/common/index.ts +++ b/src/v1/parsing/common/index.ts @@ -15,4 +15,3 @@ export { } from "./summaryHelper.js"; export * as extras from "./extras/index.js"; export { parseDate } from "@/parsing/dateParser.js"; -export { WorkflowResponse } from "./workflowResponse.js"; diff --git a/src/v1/parsing/common/workflowResponse.ts b/src/v1/parsing/common/workflowResponse.ts deleted file mode 100644 index 56c4b6b6..00000000 --- a/src/v1/parsing/common/workflowResponse.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { StringDict } from "@/parsing/stringDict.js"; -import { ApiResponse } from "./apiResponse.js"; -import { Execution } from "./execution.js"; -import { Inference } from "./inference.js"; - - -/** Wrapper for workflow requests. - * - * @category API Response - * @category Workflow - */ -export class WorkflowResponse extends ApiResponse { - /** - * Set the prediction model used to parse the document. - * The response object will be instantiated based on this parameter. - */ - execution: Execution; - - constructor(inferenceClass: new (serverResponse: StringDict) => T, serverResponse: StringDict) { - super(serverResponse); - this.execution = new Execution(inferenceClass, serverResponse["execution"]); - } -} diff --git a/tests/v1/workflows/workflow.integration.ts b/tests/v1/workflows/workflow.integration.ts index c21f6ea7..4cabcb2a 100644 --- a/tests/v1/workflows/workflow.integration.ts +++ b/tests/v1/workflows/workflow.integration.ts @@ -2,7 +2,6 @@ import { beforeEach, describe, it } from "node:test"; import assert from "node:assert"; import path from "node:path"; import * as mindee from "@/index.js"; -import { ExecutionPriority } from "@/v1/parsing/common/index.js"; import { LocalInputSource } from "@/input/index.js"; import { OptionalAsyncOptions } from "@/v1/index.js"; import { FinancialDocumentV1 } from "@/v1/product/index.js"; @@ -26,20 +25,6 @@ describe("MindeeV1 - Integration - Workflow calls", { timeout: 80_000 }, () => { }); }); - it("should retrieve a correct response from the API.", async () => { - const currentDateTime = new Date() - .toISOString() - .replace(/T/, "-") - .replace(/\..+/, ""); - const response = await client.executeWorkflow( - sample, - workflowId, - { alias: `node-${currentDateTime}`, priority: ExecutionPriority.low, rag: true } - ); - assert.strictEqual(response.execution.priority, ExecutionPriority.low); - assert.strictEqual(response.execution.file.alias, `node-${currentDateTime}`); - }); - it("should poll with RAG disabled", async () => { const asyncParams: OptionalAsyncOptions = { workflowId: workflowId diff --git a/tests/v1/workflows/workflow.spec.ts b/tests/v1/workflows/workflow.spec.ts deleted file mode 100644 index 6801b555..00000000 --- a/tests/v1/workflows/workflow.spec.ts +++ /dev/null @@ -1,95 +0,0 @@ -import path from "node:path"; -import assert from "node:assert/strict"; -import { afterEach, beforeEach, describe, it } from "node:test"; -import { promises as fs } from "node:fs"; -import { MockAgent } from "undici"; -import { RESOURCE_PATH, V1_RESOURCE_PATH } from "../../index.js"; -import { Client } from "@/v1/index.js"; -import { PathInput } from "@/index.js"; - -/** - * Creates an interceptor for a given HTTP code and response file. - * @param httpCode HTTP status code. - * @param jsonFilePath Path to the response file. - */ -async function setInterceptor(httpCode: number, jsonFilePath: string): Promise { - const mockAgent = new MockAgent(); - const mockPool = mockAgent.get("https://v1-workflow-host"); - const mockResponse = JSON.parse(await fs.readFile(jsonFilePath, "utf8")); - mockPool - .intercept({ path: /v1\/workflows\/.*/, method: "POST" }) - .reply(httpCode, mockResponse); - return mockAgent; -} - -/** - * Execute a workflow and read the response. - * @param mockAgent Mock agent. - * @param doc Document to send. - * @param workflowId Workflow ID. - */ -async function executeWorkflow(mockAgent: MockAgent, doc: PathInput, workflowId: string) { - const client = new Client({ apiKey: "my-api-key", debug: true, dispatcher: mockAgent }); - return await client.executeWorkflow(doc, workflowId); -} - -describe("MindeeV1 - Workflow executions", () => { - const doc = new PathInput({ - inputPath: path.join(RESOURCE_PATH, "file_types/pdf/blank_1.pdf") - }); - - beforeEach(function() { - process.env.MINDEE_API_HOST = "v1-workflow-host"; - }); - - afterEach(function() { - delete process.env.MINDEE_API_HOST; - }); - - it("should deserialize response correctly when sending a document to an execution", async () => { - const jsonFilePath = path.join(V1_RESOURCE_PATH, "workflows", "success.json"); - const mockAgent = await setInterceptor(202, jsonFilePath); - const mockedExecution = await executeWorkflow( - mockAgent, doc, "07ebf237-ff27-4eee-b6a2-425df4a5cca6" - ); - assert.notStrictEqual(mockedExecution, null); - assert.notStrictEqual(mockedExecution.apiRequest, null); - assert.strictEqual(mockedExecution.execution.batchName, null); - assert.strictEqual(mockedExecution.execution.createdAt, null); - assert.strictEqual(mockedExecution.execution.file.alias, null); - assert.strictEqual(mockedExecution.execution.file.name, "default_sample.jpg"); - assert.strictEqual(mockedExecution.execution.id, "8c75c035-e083-4e77-ba3b-7c3598bd1d8a"); - assert.strictEqual(mockedExecution.execution.inference, null); - assert.strictEqual(mockedExecution.execution.priority, "medium"); - assert.strictEqual(mockedExecution.execution.reviewedAt, null); - assert.strictEqual(mockedExecution.execution.reviewedPrediction, null); - assert.strictEqual(mockedExecution.execution.status, "processing"); - assert.strictEqual(mockedExecution.execution.type, "manual"); - assert.strictEqual(mockedExecution.execution.uploadedAt?.toISOString(), "2024-11-13T13:02:31.699Z"); - assert.strictEqual(mockedExecution.execution.workflowId, "07ebf237-ff27-4eee-b6a2-425df4a5cca6"); - }); - - it("should deserialize response correctly when sending a document to an execution with priority and alias", - async () => { - const jsonFilePath = path.join(V1_RESOURCE_PATH, "workflows", "success_low_priority.json"); - const mockAgent = await setInterceptor(200, jsonFilePath); - const mockedExecution = await executeWorkflow( - mockAgent, doc, "07ebf237-ff27-4eee-b6a2-425df4a5cca6" - ); - assert.notStrictEqual(mockedExecution, null); - assert.notStrictEqual(mockedExecution.apiRequest, null); - assert.strictEqual(mockedExecution.execution.batchName, null); - assert.strictEqual(mockedExecution.execution.createdAt, null); - assert.strictEqual(mockedExecution.execution.file.alias, "low-priority-sample-test"); - assert.strictEqual(mockedExecution.execution.file.name, "default_sample.jpg"); - assert.strictEqual(mockedExecution.execution.id, "b743e123-e18c-4b62-8a07-811a4f72afd3"); - assert.strictEqual(mockedExecution.execution.inference, null); - assert.strictEqual(mockedExecution.execution.priority, "low"); - assert.strictEqual(mockedExecution.execution.reviewedAt, null); - assert.strictEqual(mockedExecution.execution.reviewedPrediction, null); - assert.strictEqual(mockedExecution.execution.status, "processing"); - assert.strictEqual(mockedExecution.execution.type, "manual"); - assert.strictEqual(mockedExecution.execution.uploadedAt?.toISOString(), "2024-11-13T13:17:01.315Z"); - assert.strictEqual(mockedExecution.execution.workflowId, "07ebf237-ff27-4eee-b6a2-425df4a5cca6"); - }); -});