@retab/node 1.0.73 → 1.0.75

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.
@@ -1,5 +1,6 @@
1
1
  import { CompositionClient, RequestOptions } from "../../client.js";
2
- import { DocumentExtractRequest, RetabParsedChatCompletion, ParseRequest, ParseResult, DocumentCreateMessageRequest, DocumentMessage, DocumentCreateInputRequest, RetabParsedChatCompletionChunk, EditRequest, EditResponse } from "../../types.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";
3
4
  export default class APIDocuments extends CompositionClient {
4
5
  constructor(client: CompositionClient);
5
6
  extract(params: DocumentExtractRequest, options?: RequestOptions): Promise<RetabParsedChatCompletion>;
@@ -14,13 +15,48 @@ export default class APIDocuments extends CompositionClient {
14
15
  * and filling. It accepts any PDF document and natural language instructions
15
16
  * describing the values to fill in.
16
17
  *
18
+ * Either `document` OR `template_id` must be provided, but not both.
19
+ * - When `document` is provided: OCR + LLM inference to detect and fill form fields
20
+ * - When `template_id` is provided: Uses pre-defined form fields from the template (PDF only)
21
+ *
17
22
  * @param params - EditRequest containing:
18
- * - document: MIMEData object with filename and url (data URI with base64 content)
19
- * - filling_instructions: Natural language instructions for filling
20
- * - model: LLM model for inference (default: "gemini-2.5-pro")
23
+ * - filling_instructions: Natural language instructions for filling (required)
24
+ * - document: MIMEData object, file path, Buffer, or Readable stream (optional, mutually exclusive with template_id)
25
+ * - model: LLM model for inference (default: "retab-small")
26
+ * - template_id: Template ID to use for filling with pre-defined form fields (optional, mutually exclusive with document)
21
27
  * @param options - Optional request options
22
- * @returns EditResponse containing ocr_result, form_data (filled fields), and filled_document (MIMEData)
28
+ * @returns EditResponse containing form_data (filled fields) and filled_document (MIMEData)
23
29
  */
24
30
  edit(params: EditRequest, options?: RequestOptions): Promise<EditResponse>;
31
+ /**
32
+ * Split a document into sections based on provided categories.
33
+ *
34
+ * This method analyzes a multi-page document and classifies pages into
35
+ * user-defined categories, returning the page ranges for each section.
36
+ *
37
+ * @param params - SplitRequest containing:
38
+ * - document: MIMEData object, file path, Buffer, or Readable stream
39
+ * - categories: Array of categories with 'name' and 'description'
40
+ * - model: LLM model for inference (e.g., "retab-small")
41
+ * @param options - Optional request options
42
+ * @returns SplitResponse containing splits array with name, start_page, and end_page for each section
43
+ *
44
+ * @example
45
+ * ```typescript
46
+ * const response = await retab.documents.split({
47
+ * document: "invoice_batch.pdf",
48
+ * model: "retab-small",
49
+ * categories: [
50
+ * { name: "invoice", description: "Invoice documents with billing information" },
51
+ * { name: "receipt", description: "Receipt documents for payments" },
52
+ * { name: "contract", description: "Legal contract documents" },
53
+ * ]
54
+ * });
55
+ * for (const split of response.splits) {
56
+ * console.log(`${split.name}: pages ${split.start_page}-${split.end_page}`);
57
+ * }
58
+ * ```
59
+ */
60
+ split(params: SplitRequest, options?: RequestOptions): Promise<SplitResponse>;
25
61
  }
26
62
  //# 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,MAAM,gBAAgB,CAAC;AAGld,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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8B,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;CAStF"}
@@ -1,5 +1,5 @@
1
1
  import { CompositionClient } from "../../client.js";
2
- import { ZDocumentExtractRequest, ZRetabParsedChatCompletion, ZParseResult, ZParseRequest, ZDocumentMessage, ZDocumentCreateMessageRequest, ZDocumentCreateInputRequest, ZRetabParsedChatCompletionChunk, ZEditRequest, ZEditResponse } from "../../types.js";
2
+ import { ZDocumentExtractRequest, ZRetabParsedChatCompletion, ZParseResult, ZParseRequest, ZDocumentMessage, ZDocumentCreateMessageRequest, ZDocumentCreateInputRequest, ZRetabParsedChatCompletionChunk, ZEditRequest, ZEditResponse, ZSplitRequest, ZSplitResponse } from "../../types.js";
3
3
  export default class APIDocuments extends CompositionClient {
4
4
  constructor(client) {
5
5
  super(client);
@@ -58,12 +58,17 @@ export default class APIDocuments extends CompositionClient {
58
58
  * and filling. It accepts any PDF document and natural language instructions
59
59
  * describing the values to fill in.
60
60
  *
61
+ * Either `document` OR `template_id` must be provided, but not both.
62
+ * - When `document` is provided: OCR + LLM inference to detect and fill form fields
63
+ * - When `template_id` is provided: Uses pre-defined form fields from the template (PDF only)
64
+ *
61
65
  * @param params - EditRequest containing:
62
- * - document: MIMEData object with filename and url (data URI with base64 content)
63
- * - filling_instructions: Natural language instructions for filling
64
- * - model: LLM model for inference (default: "gemini-2.5-pro")
66
+ * - filling_instructions: Natural language instructions for filling (required)
67
+ * - document: MIMEData object, file path, Buffer, or Readable stream (optional, mutually exclusive with template_id)
68
+ * - model: LLM model for inference (default: "retab-small")
69
+ * - template_id: Template ID to use for filling with pre-defined form fields (optional, mutually exclusive with document)
65
70
  * @param options - Optional request options
66
- * @returns EditResponse containing ocr_result, form_data (filled fields), and filled_document (MIMEData)
71
+ * @returns EditResponse containing form_data (filled fields) and filled_document (MIMEData)
67
72
  */
68
73
  async edit(params, options) {
69
74
  return this._fetchJson(ZEditResponse, {
@@ -74,4 +79,42 @@ export default class APIDocuments extends CompositionClient {
74
79
  headers: options?.headers,
75
80
  });
76
81
  }
82
+ /**
83
+ * Split a document into sections based on provided categories.
84
+ *
85
+ * This method analyzes a multi-page document and classifies pages into
86
+ * user-defined categories, returning the page ranges for each section.
87
+ *
88
+ * @param params - SplitRequest containing:
89
+ * - document: MIMEData object, file path, Buffer, or Readable stream
90
+ * - categories: Array of categories with 'name' and 'description'
91
+ * - model: LLM model for inference (e.g., "retab-small")
92
+ * @param options - Optional request options
93
+ * @returns SplitResponse containing splits array with name, start_page, and end_page for each section
94
+ *
95
+ * @example
96
+ * ```typescript
97
+ * const response = await retab.documents.split({
98
+ * document: "invoice_batch.pdf",
99
+ * model: "retab-small",
100
+ * categories: [
101
+ * { name: "invoice", description: "Invoice documents with billing information" },
102
+ * { name: "receipt", description: "Receipt documents for payments" },
103
+ * { name: "contract", description: "Legal contract documents" },
104
+ * ]
105
+ * });
106
+ * for (const split of response.splits) {
107
+ * console.log(`${split.name}: pages ${split.start_page}-${split.end_page}`);
108
+ * }
109
+ * ```
110
+ */
111
+ async split(params, options) {
112
+ return this._fetchJson(ZSplitResponse, {
113
+ url: "/v1/documents/split",
114
+ method: "POST",
115
+ body: { ...(await ZSplitRequest.parseAsync(params)), ...(options?.body || {}) },
116
+ params: options?.params,
117
+ headers: options?.headers,
118
+ });
119
+ }
77
120
  }