@gemina/sdk 0.17.1 → 0.17.2
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/README.md +22 -8
- package/dist/index.cjs +34 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +34 -13
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -37,22 +37,36 @@ const client = new GeminaClient(process.env.GEMINA_API_KEY!);
|
|
|
37
37
|
const buf = await readFile("./invoice.png");
|
|
38
38
|
const result = await client.processDocument(
|
|
39
39
|
new Blob([buf], { type: "image/png" }),
|
|
40
|
-
["invoice_headers"],
|
|
40
|
+
["invoice_headers", "invoice_line_items"],
|
|
41
41
|
);
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
// One entry per requested type, in no fixed order: pick each by its type.
|
|
44
|
+
const extractions = result.data?.extractions ?? [];
|
|
45
|
+
const header = extractions.find((e) => e.meta.extractionType === "invoice_headers");
|
|
46
|
+
const lineItems = extractions.find((e) => e.meta.extractionType === "invoice_line_items");
|
|
47
|
+
|
|
48
|
+
// `result.status` is the document's outcome. Any extraction's `values` can be
|
|
49
|
+
// null when that type found nothing, and any single field can be null, so
|
|
50
|
+
// guard each one.
|
|
51
|
+
const fields = header?.values;
|
|
52
|
+
console.log("supplier:", fields?.vendorName?.value ?? "not found");
|
|
53
|
+
console.log("total:", fields?.totalAmount?.value ?? "not found", fields?.currency?.value ?? "");
|
|
54
|
+
console.log("date:", fields?.invoiceDate?.value ?? "not found");
|
|
55
|
+
// The line-item list is under `line_items` (snake_case, unlike the header fields).
|
|
56
|
+
console.log("line items:", lineItems?.values?.line_items?.length ?? "unavailable");
|
|
47
57
|
```
|
|
48
58
|
|
|
49
59
|
Processing a document by URL works the same way — pass `{ url }` instead of a file:
|
|
50
60
|
|
|
51
61
|
```ts
|
|
62
|
+
import { GeminaClient } from "@gemina/sdk";
|
|
63
|
+
|
|
64
|
+
const client = new GeminaClient(process.env.GEMINA_API_KEY!);
|
|
52
65
|
const result = await client.processDocument(
|
|
53
|
-
{ url: "https://
|
|
54
|
-
["invoice_headers"],
|
|
66
|
+
{ url: "https://api.gemina.co/api/v1/users/tutorial-samples/invoice/2/sample-invoice-1.png" },
|
|
67
|
+
["invoice_headers", "invoice_line_items"],
|
|
55
68
|
);
|
|
69
|
+
console.log("status:", result.status); // read result.data.extractions as above
|
|
56
70
|
```
|
|
57
71
|
|
|
58
72
|
## What you get back
|
|
@@ -60,7 +74,7 @@ const result = await client.processDocument(
|
|
|
60
74
|
`processDocument` resolves to a `DocumentProcessingResultOutDTO`:
|
|
61
75
|
|
|
62
76
|
- `status` — `"success" | "partial" | "empty" | "failed"`. `partial` and `empty` still resolve (they carry usable data/meta); `failed` throws a `GeminaProcessingError` instead.
|
|
63
|
-
- `data.extractions` — one entry per requested extraction type. Each entry has `meta.extractionType`, its own `status`, and `values` — the extracted payload. For `invoice_headers`, `values` fields (e.g. `vendorName`, `invoiceNumber`, `invoiceDate`, `totalAmount`, `currency`) are each `{ value, coordinates, confidence }` or `null` when not found.
|
|
77
|
+
- `data.extractions` — one entry per requested extraction type, in no fixed order (find the one you want by `meta.extractionType`). Each entry has `meta.extractionType`, its own `status`, and `values` — the extracted payload. For `invoice_headers`, `values` fields (e.g. `vendorName`, `invoiceNumber`, `invoiceDate`, `totalAmount`, `currency`) are each `{ value, coordinates, confidence }` or `null` when not found.
|
|
64
78
|
- `meta.documentId` — the stored document's ID (use it with `client.documents`).
|
|
65
79
|
- `meta.correlationId` — the async processing correlation ID.
|
|
66
80
|
|
package/dist/index.cjs
CHANGED
|
@@ -12769,18 +12769,21 @@ var GeminaClient = class _GeminaClient {
|
|
|
12769
12769
|
let submitted;
|
|
12770
12770
|
if (typeof Blob !== "undefined" && source instanceof Blob) {
|
|
12771
12771
|
try {
|
|
12772
|
-
submitted = await this.documents.createDocumentProcessingRequest(
|
|
12773
|
-
|
|
12774
|
-
|
|
12775
|
-
|
|
12776
|
-
|
|
12777
|
-
|
|
12778
|
-
|
|
12779
|
-
|
|
12780
|
-
|
|
12781
|
-
|
|
12782
|
-
|
|
12783
|
-
|
|
12772
|
+
submitted = await this.documents.createDocumentProcessingRequest(
|
|
12773
|
+
{
|
|
12774
|
+
file: await normalizeBlobSource(source),
|
|
12775
|
+
externalId,
|
|
12776
|
+
extractionTypes,
|
|
12777
|
+
templateId: options.templateId,
|
|
12778
|
+
modelType: options.modelType,
|
|
12779
|
+
thinking: options.thinking,
|
|
12780
|
+
evaluation: options.evaluation,
|
|
12781
|
+
correction: options.correction,
|
|
12782
|
+
includeCoordinates: options.includeCoordinates,
|
|
12783
|
+
endUserId: options.endUserId
|
|
12784
|
+
},
|
|
12785
|
+
sendExtractionTypesAsSeparateParts(extractionTypes)
|
|
12786
|
+
);
|
|
12784
12787
|
} catch (error) {
|
|
12785
12788
|
throw await asProcessingErrorIfFailedResult(error);
|
|
12786
12789
|
}
|
|
@@ -12909,6 +12912,24 @@ function finalizeTerminal(result) {
|
|
|
12909
12912
|
}
|
|
12910
12913
|
return result;
|
|
12911
12914
|
}
|
|
12915
|
+
function sendExtractionTypesAsSeparateParts(extractionTypes) {
|
|
12916
|
+
return async ({ init }) => {
|
|
12917
|
+
const body = init.body;
|
|
12918
|
+
if (!isFormDataLike(body)) {
|
|
12919
|
+
throw new GeminaError(
|
|
12920
|
+
"Internal error: the generated document upload did not build a FormData body"
|
|
12921
|
+
);
|
|
12922
|
+
}
|
|
12923
|
+
body.delete("extraction_types");
|
|
12924
|
+
for (const extractionType of extractionTypes) {
|
|
12925
|
+
body.append("extraction_types", extractionType);
|
|
12926
|
+
}
|
|
12927
|
+
return { body: init.body };
|
|
12928
|
+
};
|
|
12929
|
+
}
|
|
12930
|
+
function isFormDataLike(body) {
|
|
12931
|
+
return typeof body === "object" && body !== null && typeof body.append === "function" && typeof body.delete === "function";
|
|
12932
|
+
}
|
|
12912
12933
|
async function asProcessingErrorIfFailedResult(error) {
|
|
12913
12934
|
if (!(error instanceof ResponseError)) {
|
|
12914
12935
|
return error;
|
|
@@ -13107,7 +13128,7 @@ async function unwrapWebhook(body, headers, secret, options = {}) {
|
|
|
13107
13128
|
}
|
|
13108
13129
|
|
|
13109
13130
|
// src/version.ts
|
|
13110
|
-
var VERSION = "0.17.
|
|
13131
|
+
var VERSION = "0.17.2";
|
|
13111
13132
|
// Annotate the CommonJS export names for ESM import in node:
|
|
13112
13133
|
0 && (module.exports = {
|
|
13113
13134
|
AddExtractionsInDTOFromJSON,
|