@retab/node 1.0.75 → 1.0.77
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/dist/api/client.d.ts +2 -0
- package/dist/api/client.d.ts.map +1 -1
- package/dist/api/client.js +2 -0
- package/dist/api/documents/client.d.ts +32 -2
- package/dist/api/documents/client.d.ts.map +1 -1
- package/dist/api/documents/client.js +39 -1
- package/dist/api/workflows/client.d.ts +48 -0
- package/dist/api/workflows/client.d.ts.map +1 -0
- package/dist/api/workflows/client.js +74 -0
- package/dist/generated_types.d.ts +1203 -504
- package/dist/generated_types.d.ts.map +1 -1
- package/dist/generated_types.js +65 -0
- package/dist/types.d.ts +46 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +4 -0
- package/package.json +1 -1
package/dist/api/client.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import APIDocuments from "./documents/client";
|
|
|
4
4
|
import APISchemas from "./schemas/client";
|
|
5
5
|
import APIProjects from "./projects/client";
|
|
6
6
|
import APIExtractions from "./extractions/client";
|
|
7
|
+
import APIWorkflows from "./workflows/client";
|
|
7
8
|
export default class APIV1 extends CompositionClient {
|
|
8
9
|
constructor(client: AbstractClient);
|
|
9
10
|
models: APIModels;
|
|
@@ -11,5 +12,6 @@ export default class APIV1 extends CompositionClient {
|
|
|
11
12
|
schemas: APISchemas;
|
|
12
13
|
projects: APIProjects;
|
|
13
14
|
extractions: APIExtractions;
|
|
15
|
+
workflows: APIWorkflows;
|
|
14
16
|
}
|
|
15
17
|
//# sourceMappingURL=client.d.ts.map
|
package/dist/api/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,SAAS,MAAM,iBAAiB,CAAC;AACxC,OAAO,YAAY,MAAM,oBAAoB,CAAC;AAC9C,OAAO,UAAU,MAAM,kBAAkB,CAAC;AAC1C,OAAO,WAAW,MAAM,mBAAmB,CAAC;AAC5C,OAAO,cAAc,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,SAAS,MAAM,iBAAiB,CAAC;AACxC,OAAO,YAAY,MAAM,oBAAoB,CAAC;AAC9C,OAAO,UAAU,MAAM,kBAAkB,CAAC;AAC1C,OAAO,WAAW,MAAM,mBAAmB,CAAC;AAC5C,OAAO,cAAc,MAAM,sBAAsB,CAAC;AAClD,OAAO,YAAY,MAAM,oBAAoB,CAAC;AAE9C,MAAM,CAAC,OAAO,OAAO,KAAM,SAAQ,iBAAiB;gBACpC,MAAM,EAAE,cAAc;IAGlC,MAAM,YAAuB;IAC7B,SAAS,eAA0B;IACnC,OAAO,aAAwB;IAC/B,QAAQ,cAAyB;IACjC,WAAW,iBAA4B;IACvC,SAAS,eAA0B;CACtC"}
|
package/dist/api/client.js
CHANGED
|
@@ -4,6 +4,7 @@ import APIDocuments from "./documents/client";
|
|
|
4
4
|
import APISchemas from "./schemas/client";
|
|
5
5
|
import APIProjects from "./projects/client";
|
|
6
6
|
import APIExtractions from "./extractions/client";
|
|
7
|
+
import APIWorkflows from "./workflows/client";
|
|
7
8
|
export default class APIV1 extends CompositionClient {
|
|
8
9
|
constructor(client) {
|
|
9
10
|
super(client);
|
|
@@ -12,5 +13,6 @@ export default class APIV1 extends CompositionClient {
|
|
|
12
13
|
this.schemas = new APISchemas(this);
|
|
13
14
|
this.projects = new APIProjects(this);
|
|
14
15
|
this.extractions = new APIExtractions(this);
|
|
16
|
+
this.workflows = new APIWorkflows(this);
|
|
15
17
|
}
|
|
16
18
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CompositionClient, RequestOptions } from "../../client.js";
|
|
2
|
-
import { DocumentExtractRequest, RetabParsedChatCompletion, ParseRequest, ParseResult, DocumentCreateMessageRequest, DocumentMessage, DocumentCreateInputRequest, RetabParsedChatCompletionChunk, EditRequest, EditResponse, SplitRequest } from "../../types.js";
|
|
3
|
-
import type { SplitResponse } from "../../generated_types.js";
|
|
2
|
+
import { DocumentExtractRequest, RetabParsedChatCompletion, ParseRequest, ParseResult, DocumentCreateMessageRequest, DocumentMessage, DocumentCreateInputRequest, RetabParsedChatCompletionChunk, EditRequest, EditResponse, SplitRequest, ClassifyRequest } from "../../types.js";
|
|
3
|
+
import type { SplitResponse, ClassifyResponse } from "../../generated_types.js";
|
|
4
4
|
export default class APIDocuments extends CompositionClient {
|
|
5
5
|
constructor(client: CompositionClient);
|
|
6
6
|
extract(params: DocumentExtractRequest, options?: RequestOptions): Promise<RetabParsedChatCompletion>;
|
|
@@ -58,5 +58,35 @@ export default class APIDocuments extends CompositionClient {
|
|
|
58
58
|
* ```
|
|
59
59
|
*/
|
|
60
60
|
split(params: SplitRequest, options?: RequestOptions): Promise<SplitResponse>;
|
|
61
|
+
/**
|
|
62
|
+
* Classify a document into one of the provided categories.
|
|
63
|
+
*
|
|
64
|
+
* This method analyzes a document and classifies it into exactly one
|
|
65
|
+
* of the user-defined categories, returning the classification with
|
|
66
|
+
* chain-of-thought reasoning explaining the decision.
|
|
67
|
+
*
|
|
68
|
+
* @param params - ClassifyRequest containing:
|
|
69
|
+
* - document: MIMEData object, file path, Buffer, or Readable stream
|
|
70
|
+
* - categories: Array of categories with 'name' and 'description'
|
|
71
|
+
* - model: LLM model for inference (e.g., "retab-small")
|
|
72
|
+
* @param options - Optional request options
|
|
73
|
+
* @returns ClassifyResponse containing result with reasoning and classification
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```typescript
|
|
77
|
+
* const response = await retab.documents.classify({
|
|
78
|
+
* document: "invoice.pdf",
|
|
79
|
+
* model: "retab-small",
|
|
80
|
+
* categories: [
|
|
81
|
+
* { name: "invoice", description: "Invoice documents with billing information" },
|
|
82
|
+
* { name: "receipt", description: "Receipt documents for payments" },
|
|
83
|
+
* { name: "contract", description: "Legal contract documents" },
|
|
84
|
+
* ]
|
|
85
|
+
* });
|
|
86
|
+
* console.log(`Classification: ${response.result.classification}`);
|
|
87
|
+
* console.log(`Reasoning: ${response.result.reasoning}`);
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
classify(params: ClassifyRequest, options?: RequestOptions): Promise<ClassifyResponse>;
|
|
61
91
|
}
|
|
62
92
|
//# sourceMappingURL=client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/api/documents/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACpE,OAAO,EAA2B,sBAAsB,EAAE,yBAAyB,EAA8B,YAAY,EAAE,WAAW,EAA+B,4BAA4B,EAAE,eAAe,EAAmD,0BAA0B,EAA+B,8BAA8B,EAAmC,WAAW,EAAE,YAAY,EAA+B,YAAY,EAAiC,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/api/documents/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACpE,OAAO,EAA2B,sBAAsB,EAAE,yBAAyB,EAA8B,YAAY,EAAE,WAAW,EAA+B,4BAA4B,EAAE,eAAe,EAAmD,0BAA0B,EAA+B,8BAA8B,EAAmC,WAAW,EAAE,YAAY,EAA+B,YAAY,EAAiC,eAAe,EAAuC,MAAM,gBAAgB,CAAC;AACrjB,OAAO,KAAK,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAGhF,MAAM,CAAC,OAAO,OAAO,YAAa,SAAQ,iBAAiB;gBAC3C,MAAM,EAAE,iBAAiB;IAG/B,OAAO,CAAC,MAAM,EAAE,sBAAsB,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,yBAAyB,CAAC;IAUrG,cAAc,CAAC,MAAM,EAAE,sBAAsB,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC,8BAA8B,CAAC,CAAC;IAUjI,KAAK,CAAC,MAAM,EAAE,YAAY,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,WAAW,CAAC;IAS3E,eAAe,CAAC,MAAM,EAAE,4BAA4B,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC;IASzG,aAAa,CAAC,MAAM,EAAE,0BAA0B,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC;IAS3G;;;;;;;;;;;;;;;;;;OAkBG;IACG,IAAI,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,YAAY,CAAC;IAShF;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACG,KAAK,CAAC,MAAM,EAAE,YAAY,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,CAAC;IASnF;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACG,QAAQ,CAAC,MAAM,EAAE,eAAe,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,gBAAgB,CAAC;CAS/F"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CompositionClient } from "../../client.js";
|
|
2
|
-
import { ZDocumentExtractRequest, ZRetabParsedChatCompletion, ZParseResult, ZParseRequest, ZDocumentMessage, ZDocumentCreateMessageRequest, ZDocumentCreateInputRequest, ZRetabParsedChatCompletionChunk, ZEditRequest, ZEditResponse, ZSplitRequest, ZSplitResponse } from "../../types.js";
|
|
2
|
+
import { ZDocumentExtractRequest, ZRetabParsedChatCompletion, ZParseResult, ZParseRequest, ZDocumentMessage, ZDocumentCreateMessageRequest, ZDocumentCreateInputRequest, ZRetabParsedChatCompletionChunk, ZEditRequest, ZEditResponse, ZSplitRequest, ZSplitResponse, ZClassifyRequest, ZClassifyResponse } from "../../types.js";
|
|
3
3
|
export default class APIDocuments extends CompositionClient {
|
|
4
4
|
constructor(client) {
|
|
5
5
|
super(client);
|
|
@@ -117,4 +117,42 @@ export default class APIDocuments extends CompositionClient {
|
|
|
117
117
|
headers: options?.headers,
|
|
118
118
|
});
|
|
119
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
* Classify a document into one of the provided categories.
|
|
122
|
+
*
|
|
123
|
+
* This method analyzes a document and classifies it into exactly one
|
|
124
|
+
* of the user-defined categories, returning the classification with
|
|
125
|
+
* chain-of-thought reasoning explaining the decision.
|
|
126
|
+
*
|
|
127
|
+
* @param params - ClassifyRequest containing:
|
|
128
|
+
* - document: MIMEData object, file path, Buffer, or Readable stream
|
|
129
|
+
* - categories: Array of categories with 'name' and 'description'
|
|
130
|
+
* - model: LLM model for inference (e.g., "retab-small")
|
|
131
|
+
* @param options - Optional request options
|
|
132
|
+
* @returns ClassifyResponse containing result with reasoning and classification
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```typescript
|
|
136
|
+
* const response = await retab.documents.classify({
|
|
137
|
+
* document: "invoice.pdf",
|
|
138
|
+
* model: "retab-small",
|
|
139
|
+
* categories: [
|
|
140
|
+
* { name: "invoice", description: "Invoice documents with billing information" },
|
|
141
|
+
* { name: "receipt", description: "Receipt documents for payments" },
|
|
142
|
+
* { name: "contract", description: "Legal contract documents" },
|
|
143
|
+
* ]
|
|
144
|
+
* });
|
|
145
|
+
* console.log(`Classification: ${response.result.classification}`);
|
|
146
|
+
* console.log(`Reasoning: ${response.result.reasoning}`);
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
async classify(params, options) {
|
|
150
|
+
return this._fetchJson(ZClassifyResponse, {
|
|
151
|
+
url: "/v1/documents/classify",
|
|
152
|
+
method: "POST",
|
|
153
|
+
body: { ...(await ZClassifyRequest.parseAsync(params)), ...(options?.body || {}) },
|
|
154
|
+
params: options?.params,
|
|
155
|
+
headers: options?.headers,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
120
158
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { CompositionClient, RequestOptions } from "../../client.js";
|
|
2
|
+
import { MIMEDataInput, WorkflowRun } from "../../types.js";
|
|
3
|
+
export default class APIWorkflows extends CompositionClient {
|
|
4
|
+
constructor(client: CompositionClient);
|
|
5
|
+
/**
|
|
6
|
+
* Run a workflow with the provided input documents.
|
|
7
|
+
*
|
|
8
|
+
* This creates a workflow run and starts execution in the background.
|
|
9
|
+
* The returned WorkflowRun will have status "running" - use getRun()
|
|
10
|
+
* to check for updates on the run status.
|
|
11
|
+
*
|
|
12
|
+
* @param workflowId - The ID of the workflow to run
|
|
13
|
+
* @param documents - Mapping of start node IDs to their input documents
|
|
14
|
+
* @param options - Optional request options
|
|
15
|
+
* @returns The created workflow run with status "running"
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const run = await client.workflows.run({
|
|
20
|
+
* workflowId: "wf_abc123",
|
|
21
|
+
* documents: {
|
|
22
|
+
* "start-node-1": "./invoice.pdf",
|
|
23
|
+
* "start-node-2": Buffer.from(...)
|
|
24
|
+
* }
|
|
25
|
+
* });
|
|
26
|
+
* console.log(`Run started: ${run.id}, status: ${run.status}`);
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
run({ workflowId, documents, }: {
|
|
30
|
+
workflowId: string;
|
|
31
|
+
documents: Record<string, MIMEDataInput>;
|
|
32
|
+
}, options?: RequestOptions): Promise<WorkflowRun>;
|
|
33
|
+
/**
|
|
34
|
+
* Get a workflow run by ID.
|
|
35
|
+
*
|
|
36
|
+
* @param runId - The ID of the workflow run to retrieve
|
|
37
|
+
* @param options - Optional request options
|
|
38
|
+
* @returns The workflow run
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* const run = await client.workflows.getRun("run_abc123");
|
|
43
|
+
* console.log(`Run status: ${run.status}`);
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
getRun(runId: string, options?: RequestOptions): Promise<WorkflowRun>;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/api/workflows/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACpE,OAAO,EAAE,aAAa,EAAa,WAAW,EAAgB,MAAM,gBAAgB,CAAC;AAErF,MAAM,CAAC,OAAO,OAAO,YAAa,SAAQ,iBAAiB;gBAC3C,MAAM,EAAE,iBAAiB;IAIrC;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACG,GAAG,CAAC,EACN,UAAU,EACV,SAAS,GACZ,EAAE;QACC,UAAU,EAAE,MAAM,CAAC;QACnB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;KAC5C,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,WAAW,CAAC;IA0BlD;;;;;;;;;;;;OAYG;IACG,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,WAAW,CAAC;CAQ9E"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { CompositionClient } from "../../client.js";
|
|
2
|
+
import { ZMIMEData, ZWorkflowRun } from "../../types.js";
|
|
3
|
+
export default class APIWorkflows extends CompositionClient {
|
|
4
|
+
constructor(client) {
|
|
5
|
+
super(client);
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Run a workflow with the provided input documents.
|
|
9
|
+
*
|
|
10
|
+
* This creates a workflow run and starts execution in the background.
|
|
11
|
+
* The returned WorkflowRun will have status "running" - use getRun()
|
|
12
|
+
* to check for updates on the run status.
|
|
13
|
+
*
|
|
14
|
+
* @param workflowId - The ID of the workflow to run
|
|
15
|
+
* @param documents - Mapping of start node IDs to their input documents
|
|
16
|
+
* @param options - Optional request options
|
|
17
|
+
* @returns The created workflow run with status "running"
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* const run = await client.workflows.run({
|
|
22
|
+
* workflowId: "wf_abc123",
|
|
23
|
+
* documents: {
|
|
24
|
+
* "start-node-1": "./invoice.pdf",
|
|
25
|
+
* "start-node-2": Buffer.from(...)
|
|
26
|
+
* }
|
|
27
|
+
* });
|
|
28
|
+
* console.log(`Run started: ${run.id}, status: ${run.status}`);
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
async run({ workflowId, documents, }, options) {
|
|
32
|
+
// Convert each document to MIMEData format expected by backend
|
|
33
|
+
const documentsPayload = {};
|
|
34
|
+
for (const [nodeId, document] of Object.entries(documents)) {
|
|
35
|
+
const parsedDocument = await ZMIMEData.parseAsync(document);
|
|
36
|
+
// Extract base64 content from data URL
|
|
37
|
+
const content = parsedDocument.url.split(",")[1];
|
|
38
|
+
const mimeType = parsedDocument.url.split(";")[0].split(":")[1];
|
|
39
|
+
documentsPayload[nodeId] = {
|
|
40
|
+
filename: parsedDocument.filename,
|
|
41
|
+
content: content,
|
|
42
|
+
mime_type: mimeType,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
return this._fetchJson(ZWorkflowRun, {
|
|
46
|
+
url: `/v1/workflows/${workflowId}/run`,
|
|
47
|
+
method: "POST",
|
|
48
|
+
body: { documents: documentsPayload, ...(options?.body || {}) },
|
|
49
|
+
params: options?.params,
|
|
50
|
+
headers: options?.headers,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Get a workflow run by ID.
|
|
55
|
+
*
|
|
56
|
+
* @param runId - The ID of the workflow run to retrieve
|
|
57
|
+
* @param options - Optional request options
|
|
58
|
+
* @returns The workflow run
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* const run = await client.workflows.getRun("run_abc123");
|
|
63
|
+
* console.log(`Run status: ${run.status}`);
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
async getRun(runId, options) {
|
|
67
|
+
return this._fetchJson(ZWorkflowRun, {
|
|
68
|
+
url: `/v1/workflows/runs/${runId}`,
|
|
69
|
+
method: "GET",
|
|
70
|
+
params: options?.params,
|
|
71
|
+
headers: options?.headers,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|