@ekwo-ai/document-reading 0.0.0-stage → 0.20.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 +18 -0
- package/LICENSE +21 -0
- package/README.md +155 -2
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/model.d.ts +100 -0
- package/dist/model.d.ts.map +1 -0
- package/dist/model.js +434 -0
- package/dist/model.js.map +1 -0
- package/dist/purchase.d.ts +123 -0
- package/dist/purchase.d.ts.map +1 -0
- package/dist/purchase.js +184 -0
- package/dist/purchase.js.map +1 -0
- package/dist/structured.d.ts +29 -0
- package/dist/structured.d.ts.map +1 -0
- package/dist/structured.js +51 -0
- package/dist/structured.js.map +1 -0
- package/package.json +62 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented here. The format follows
|
|
4
|
+
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project adheres to
|
|
5
|
+
[Semantic Versioning](https://semver.org/).
|
|
6
|
+
|
|
7
|
+
## [Unreleased]
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
- **The package.** `readStructured()` reads a CII, UBL or Factur-X file
|
|
11
|
+
exactly into the EN 16931 `ReceivedInvoice`. `readingSchema()`,
|
|
12
|
+
`readingPrompt()` and `readingOf()` are the model path as data: the JSON
|
|
13
|
+
schema and the words a caller sends to a vision model, and the check of its
|
|
14
|
+
answer into the same `ReceivedInvoice` (`syntax: 'model'`), with what was
|
|
15
|
+
not printed in `missing`, what was not of its shape in `rejected`, a
|
|
16
|
+
confidence per field and per line, and the caller's extension returned
|
|
17
|
+
untouched. `purchaseDraftOf()` turns either into the draft of a purchase
|
|
18
|
+
document in the columns of Ekwo OS.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 EKWO OÜ, trading as Ekwo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,156 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @ekwo-ai/document-reading
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
One reader for received invoices. A structured e-invoice — CII, UBL, a PDF
|
|
4
|
+
carrying its Factur-X or ZUGFeRD XML — is read exactly. A photograph or a
|
|
5
|
+
plain PDF is read by a vision model **you** call, with the JSON schema and
|
|
6
|
+
the prompt this package publishes, and its answer is checked here. Both
|
|
7
|
+
arrive as the same EN 16931 `ReceivedInvoice`, and become the same purchase
|
|
8
|
+
draft.
|
|
9
|
+
|
|
10
|
+
MIT. No database, no network, no model call: the package reads bytes and
|
|
11
|
+
JSON, and returns objects.
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npm install @ekwo-ai/document-reading
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## How a product chains it
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import {
|
|
21
|
+
READING_VERSION,
|
|
22
|
+
purchaseDraftOf,
|
|
23
|
+
readStructured,
|
|
24
|
+
readingOf,
|
|
25
|
+
readingPrompt,
|
|
26
|
+
readingSchema,
|
|
27
|
+
} from '@ekwo-ai/document-reading';
|
|
28
|
+
|
|
29
|
+
// 1. A structured e-invoice is read exactly, and no model is called.
|
|
30
|
+
const structured = await readStructured(bytes);
|
|
31
|
+
let invoice = structured?.invoice;
|
|
32
|
+
|
|
33
|
+
// 2. Anything else is read by a vision model: one call, one schema.
|
|
34
|
+
if (invoice === undefined) {
|
|
35
|
+
const answer = await yourModel({
|
|
36
|
+
system: readingPrompt(),
|
|
37
|
+
file: bytes, // the image or the PDF, as your provider takes it
|
|
38
|
+
format: { type: 'json_schema', schema: readingSchema() },
|
|
39
|
+
});
|
|
40
|
+
const reading = readingOf(JSON.parse(answer.text));
|
|
41
|
+
// reading is undefined when the page is not a purchase document.
|
|
42
|
+
invoice = reading?.invoice;
|
|
43
|
+
log({ reading: READING_VERSION, missing: reading?.missing, rejected: reading?.rejected });
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// 3. The draft of a purchase, in the columns of Ekwo OS.
|
|
47
|
+
if (invoice !== undefined) {
|
|
48
|
+
const draft = purchaseDraftOf(invoice);
|
|
49
|
+
// Choose the supplier, the account and the tax in your books, then create_document.
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
**The model call, its key, its timeout and its metering stay in the
|
|
54
|
+
product.** This package names no provider and holds no secret; the schema is
|
|
55
|
+
a plain JSON schema with every object closed and every property required, as
|
|
56
|
+
the structured outputs of the main providers take it.
|
|
57
|
+
|
|
58
|
+
## The exact path: `readStructured(bytes, options?)`
|
|
59
|
+
|
|
60
|
+
Tells a PDF from XML by the first bytes and CII from UBL by the root, and
|
|
61
|
+
reads with `readFacturX()` / `readCii()` of
|
|
62
|
+
[`@ekwo-ai/factur-x`](../formats/factur-x/) or `readUbl()` of
|
|
63
|
+
[`@ekwo-ai/peppol-ubl`](../formats/peppol-ubl/). Returns their
|
|
64
|
+
`{ invoice, violations }`, or `undefined` for a file that holds no
|
|
65
|
+
e-invoice — a photograph, a PDF without XML, an XML that is not an invoice,
|
|
66
|
+
a file over the limits — so the caller reads it the other way. The readers
|
|
67
|
+
are imported when a file needs them.
|
|
68
|
+
|
|
69
|
+
## The model path: `readingSchema()`, `readingPrompt()`, `readingOf()`
|
|
70
|
+
|
|
71
|
+
The model is told to **copy, never compute**, and to **leave empty rather
|
|
72
|
+
than guess**. It returns, as printed:
|
|
73
|
+
|
|
74
|
+
- what the page is: `invoice`, `credit_note`, `receipt` (already paid), or
|
|
75
|
+
`other` (read as nothing);
|
|
76
|
+
- the number, the issue, due and tax-point dates, and the currency **as
|
|
77
|
+
printed** — empty where the page prints none, never the currency of a
|
|
78
|
+
country;
|
|
79
|
+
- the supplier and the customer: legal and trade name, VAT identifier,
|
|
80
|
+
registration number, address;
|
|
81
|
+
- the references (customer, order, contract, the invoice a credit note
|
|
82
|
+
corrects), the invoicing period, the IBAN, BIC, payment reference and terms;
|
|
83
|
+
- each line: name, description, quantity, the unit as printed and its UN/ECE
|
|
84
|
+
Recommendation 20 code, net price, net amount, VAT category (UNTDID 5305)
|
|
85
|
+
and rate, and its own period;
|
|
86
|
+
- each VAT group of the summary: category, rate, base, tax, the amount
|
|
87
|
+
including tax where printed;
|
|
88
|
+
- the totals: lines, without VAT, VAT, with VAT, prepaid, payable;
|
|
89
|
+
- a confidence (`high`, `medium`, `low`) for each field of
|
|
90
|
+
`CONFIDENCE_FIELDS`, and for each line.
|
|
91
|
+
|
|
92
|
+
`readingOf(answer)` checks it into a `ReceivedInvoice` with
|
|
93
|
+
`syntax: 'model'`, and returns beside it:
|
|
94
|
+
|
|
95
|
+
| Field | What it holds |
|
|
96
|
+
|---|---|
|
|
97
|
+
| `missing` | The fields EN 16931 requires that the page did not print, by path (`number`, `totals.payable`, `lines[2].net_amount`). Each is `''` in the invoice. |
|
|
98
|
+
| `rejected` | The fields the model filled with something not of their shape — a date that is no day, a rate in words. Each is emptied. |
|
|
99
|
+
| `violations` | The arithmetic of EN 16931 the printed figures break, checked only when every figure it reads was read. |
|
|
100
|
+
| `confidence` | By field and by line (`lines[n]`), `null` where the model said nothing usable. |
|
|
101
|
+
| `taxInclusiveByGroup` | Per VAT group, the amount including tax the page prints, which EN 16931 does not carry. |
|
|
102
|
+
| `extension` | The caller's own fields, untouched. |
|
|
103
|
+
|
|
104
|
+
Nothing is computed, defaulted or corrected: a total that is not printed
|
|
105
|
+
stays empty, a lone comma is read as a decimal separator and anything else
|
|
106
|
+
that is not a decimal is rejected.
|
|
107
|
+
|
|
108
|
+
## Extending the schema
|
|
109
|
+
|
|
110
|
+
A caller that needs more than an invoice adds its own properties, read in
|
|
111
|
+
the same call:
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
const extension = {
|
|
115
|
+
properties: {
|
|
116
|
+
meter: { type: 'string', description: 'The meter number, as printed.' },
|
|
117
|
+
contract_type: { type: 'string', description: 'The contract type, as printed.' },
|
|
118
|
+
},
|
|
119
|
+
instructions: 'The meter number is printed near the address of supply.',
|
|
120
|
+
};
|
|
121
|
+
const schema = readingSchema(extension); // adds a closed `extension` object
|
|
122
|
+
const prompt = readingPrompt(extension); // adds the instructions after the package's words
|
|
123
|
+
const reading = readingOf<{ meter: string; contract_type: string }>(answer);
|
|
124
|
+
reading?.extension; // as the model answered it: check your own fields
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
The invoice is read once; the extension's fields come back beside it, and
|
|
128
|
+
the PDF is never read a second time.
|
|
129
|
+
|
|
130
|
+
## The purchase draft: `purchaseDraftOf(invoice)`
|
|
131
|
+
|
|
132
|
+
The fields of `documents` and `document_lines` of Ekwo OS, from either path:
|
|
133
|
+
|
|
134
|
+
- `doc_type` (`purchase_invoice` or `purchase_credit_note`), the dates, the
|
|
135
|
+
supplier's number as `supplier_reference`, `currency_code` (null where it
|
|
136
|
+
was not read), the references, `payment_reference`, `payee_iban`;
|
|
137
|
+
- the supplier as the invoice names it, to be found among the contacts or
|
|
138
|
+
added;
|
|
139
|
+
- one line per line, then one per allowance (negative) or charge of the
|
|
140
|
+
whole document, each with its `unit_code`, its VAT category and rate.
|
|
141
|
+
|
|
142
|
+
A line keeps its quantity, unit code and price where they make its amount
|
|
143
|
+
at the decimals of its currency, as `amount_untaxed` is computed —
|
|
144
|
+
`1234 kWh × 0.1834 = 226.3156`, which rounds to the `226.32` printed.
|
|
145
|
+
Otherwise it is one unit (`C62`) at its amount, and the invoice's own
|
|
146
|
+
figures go in `attributes` (`invoiced_quantity`, `invoiced_unit_code`,
|
|
147
|
+
`invoiced_net_price`). The period of a line goes in `attributes` as
|
|
148
|
+
`period_start` and `period_end`; the period of the invoice goes on each line
|
|
149
|
+
without its own, and is returned as `invoicing_period`.
|
|
150
|
+
|
|
151
|
+
The supplier, the account and the tax are chosen by the caller, in its own
|
|
152
|
+
books and country pack: this package knows no chart and no rate.
|
|
153
|
+
|
|
154
|
+
## Licence
|
|
155
|
+
|
|
156
|
+
MIT. See [`LICENSE`](LICENSE).
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@ekwo-ai/document-reading` — one reader for received invoices.
|
|
3
|
+
*
|
|
4
|
+
* - `readStructured()`: a CII, UBL or Factur-X file, read exactly.
|
|
5
|
+
* - `readingSchema()`, `readingPrompt()`, `readingOf()`: a photograph or a
|
|
6
|
+
* plain PDF, read by a vision model the caller calls, into the same shape.
|
|
7
|
+
* - `purchaseDraftOf()`: either, as the draft of a purchase document.
|
|
8
|
+
*
|
|
9
|
+
* The shape is `ReceivedInvoice` of `@ekwo-ai/factur-x` (EN 16931), re-exported
|
|
10
|
+
* here so a caller needs this package alone.
|
|
11
|
+
*/
|
|
12
|
+
export { fileKind, readStructured, type FileKind } from './structured.js';
|
|
13
|
+
export { CONFIDENCE_FIELDS, CONFIDENCES, READING_PROMPT, READING_VERSION, VAT_CATEGORIES, readingOf, readingPrompt, readingSchema, type Confidence, type ConfidenceField, type DocumentKind, type ModelReading, type ReadingExtension, } from './model.js';
|
|
14
|
+
export { LINE_ATTRIBUTES, currencyDigits, makesAmount, purchaseDraftOf, type Period, type PurchaseDraft, type PurchaseDraftLine, } from './purchase.js';
|
|
15
|
+
export type { DateText, DecimalText, ReadOptions, ReceivedAccount, ReceivedAddress, ReceivedAllowanceCharge, ReceivedAttachment, ReceivedContact, ReceivedIdentifier, ReceivedInvoice, ReceivedInvoiceFile, ReceivedLine, ReceivedParty, ReceivedPaymentMeans, ReceivedTax, ReceivedTotals, ReceivedViolation, } from '@ekwo-ai/factur-x';
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,KAAK,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC1E,OAAO,EACL,iBAAiB,EACjB,WAAW,EACX,cAAc,EACd,eAAe,EACf,cAAc,EACd,SAAS,EACT,aAAa,EACb,aAAa,EACb,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,gBAAgB,GACtB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,eAAe,EACf,cAAc,EACd,WAAW,EACX,eAAe,EACf,KAAK,MAAM,EACX,KAAK,aAAa,EAClB,KAAK,iBAAiB,GACvB,MAAM,eAAe,CAAC;AACvB,YAAY,EACV,QAAQ,EACR,WAAW,EACX,WAAW,EACX,eAAe,EACf,eAAe,EACf,uBAAuB,EACvB,kBAAkB,EAClB,eAAe,EACf,kBAAkB,EAClB,eAAe,EACf,mBAAmB,EACnB,YAAY,EACZ,aAAa,EACb,oBAAoB,EACpB,WAAW,EACX,cAAc,EACd,iBAAiB,GAClB,MAAM,mBAAmB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@ekwo-ai/document-reading` — one reader for received invoices.
|
|
3
|
+
*
|
|
4
|
+
* - `readStructured()`: a CII, UBL or Factur-X file, read exactly.
|
|
5
|
+
* - `readingSchema()`, `readingPrompt()`, `readingOf()`: a photograph or a
|
|
6
|
+
* plain PDF, read by a vision model the caller calls, into the same shape.
|
|
7
|
+
* - `purchaseDraftOf()`: either, as the draft of a purchase document.
|
|
8
|
+
*
|
|
9
|
+
* The shape is `ReceivedInvoice` of `@ekwo-ai/factur-x` (EN 16931), re-exported
|
|
10
|
+
* here so a caller needs this package alone.
|
|
11
|
+
*/
|
|
12
|
+
export { fileKind, readStructured } from './structured.js';
|
|
13
|
+
export { CONFIDENCE_FIELDS, CONFIDENCES, READING_PROMPT, READING_VERSION, VAT_CATEGORIES, readingOf, readingPrompt, readingSchema, } from './model.js';
|
|
14
|
+
export { LINE_ATTRIBUTES, currencyDigits, makesAmount, purchaseDraftOf, } from './purchase.js';
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAiB,MAAM,iBAAiB,CAAC;AAC1E,OAAO,EACL,iBAAiB,EACjB,WAAW,EACX,cAAc,EACd,eAAe,EACf,cAAc,EACd,SAAS,EACT,aAAa,EACb,aAAa,GAMd,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,eAAe,EACf,cAAc,EACd,WAAW,EACX,eAAe,GAIhB,MAAM,eAAe,CAAC"}
|
package/dist/model.d.ts
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The model path: a photograph or a plain PDF, read by a vision model.
|
|
3
|
+
*
|
|
4
|
+
* This package calls no model. It publishes what a caller sends to one — the
|
|
5
|
+
* JSON schema the answer is held to (`readingSchema()`) and the words that go
|
|
6
|
+
* with it (`readingPrompt()`) — and checks what comes back (`readingOf()`)
|
|
7
|
+
* into the `ReceivedInvoice` the exact readers return, so that whatever turns
|
|
8
|
+
* an invoice into a purchase does it once for a Factur-X file and for a
|
|
9
|
+
* photograph of a till receipt. The call, its key, its timeout and what it
|
|
10
|
+
* costs stay with the product that makes it.
|
|
11
|
+
*
|
|
12
|
+
* The model copies; it never computes. Every figure is the text the page
|
|
13
|
+
* prints, every code one the page prints or that names, in a published list,
|
|
14
|
+
* a word the page prints. A field the page does not print is left empty, and
|
|
15
|
+
* `readingOf()` keeps it empty: `null` where `ReceivedInvoice` allows it,
|
|
16
|
+
* `''` where EN 16931 requires a value, named then in `missing`. Nothing is
|
|
17
|
+
* defaulted — not the currency, not the date, not a quantity of one.
|
|
18
|
+
*
|
|
19
|
+
* A caller may ask for more than an invoice: an energy layer asks for the
|
|
20
|
+
* meter, the bands and the contract type. It hands an `extension` — its own
|
|
21
|
+
* properties, in JSON schema — and gets them back, untouched, beside the
|
|
22
|
+
* invoice. The same call reads both.
|
|
23
|
+
*/
|
|
24
|
+
import { type DecimalText, type ReceivedInvoice, type ReceivedViolation } from '@ekwo-ai/factur-x';
|
|
25
|
+
/** Changed with every change of the schema or of the words below; a product writes it in the log of every reading. */
|
|
26
|
+
export declare const READING_VERSION = "2026-10-22";
|
|
27
|
+
/** How sure the model is of what it copied into a field. */
|
|
28
|
+
export type Confidence = 'high' | 'medium' | 'low';
|
|
29
|
+
export declare const CONFIDENCES: readonly Confidence[];
|
|
30
|
+
/** What the model says the page is. `other` is anything that is not a purchase document, and is read as nothing. */
|
|
31
|
+
export type DocumentKind = 'invoice' | 'credit_note' | 'receipt' | 'other';
|
|
32
|
+
/**
|
|
33
|
+
* The fields of the document the model rates its confidence in, one by one.
|
|
34
|
+
* A line rates itself (`lines[n]`).
|
|
35
|
+
*/
|
|
36
|
+
export declare const CONFIDENCE_FIELDS: readonly ["document", "number", "issue_date", "due_date", "currency", "seller", "seller_vat_id", "seller_legal_id", "buyer", "invoicing_period", "taxes", "totals", "payment"];
|
|
37
|
+
export type ConfidenceField = (typeof CONFIDENCE_FIELDS)[number];
|
|
38
|
+
/**
|
|
39
|
+
* The categories of VAT EN 16931 names (UNTDID 5305, the subset of BT-118):
|
|
40
|
+
* standard, zero, exempt, reverse charge, intra-Community, export, outside the
|
|
41
|
+
* scope, and the two of the Canary Islands, Ceuta and Melilla.
|
|
42
|
+
*/
|
|
43
|
+
export declare const VAT_CATEGORIES: readonly string[];
|
|
44
|
+
/**
|
|
45
|
+
* What a caller adds to the schema: its own properties, read in the same call
|
|
46
|
+
* and returned untouched in `ModelReading.extension`.
|
|
47
|
+
*/
|
|
48
|
+
export interface ReadingExtension {
|
|
49
|
+
/** JSON schema of each property, as the model's structured output takes it. */
|
|
50
|
+
properties: Record<string, Record<string, unknown>>;
|
|
51
|
+
/** Defaults to every property: a structured output wants each one answered, empty where not printed. */
|
|
52
|
+
required?: string[];
|
|
53
|
+
/** Said to the model after the words of this package: what the properties are and where they are printed. */
|
|
54
|
+
instructions?: string;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The JSON schema of the answer, as a structured output takes it: every
|
|
58
|
+
* object closed, every property required and answered — with an empty text,
|
|
59
|
+
* an empty list — where the page does not print it.
|
|
60
|
+
*/
|
|
61
|
+
export declare function readingSchema(extension?: ReadingExtension): Record<string, unknown>;
|
|
62
|
+
/** The words that go with the schema. Nothing in them names a country, a currency or a language. */
|
|
63
|
+
export declare const READING_PROMPT = "You read one purchase document for a company's books: an invoice, a credit note or a receipt, as a photograph or a PDF. Answer with what is printed on it, in the JSON format required.\n\nCopy, never compute. Every amount, quantity, price and rate is the one printed, with a dot as the decimal separator, no grouping and no currency sign. Never add, multiply, convert or round a figure, and never fill a total from its parts: a total that is not printed stays empty.\n\nLeave empty rather than guess. A field the page does not print is an empty text or an empty list. The currency is the one the page prints by code, symbol or name; when it prints none, or a symbol several currencies share, leave it empty. A code (a country, a unit, a VAT category) is given only where the page prints it or prints words that name exactly one.\n\nDates are YYYY-MM-DD. Give one entry in lines per line printed, with its own period where it prints one, and one entry in taxes per rate of the tax summary. For each field of confidence, say how sure you are of what you copied there.\n\nIf the page is not a purchase document, answer document \"other\" and leave every other field empty.";
|
|
64
|
+
/** The words, with the caller's own instructions for its extension after them. */
|
|
65
|
+
export declare function readingPrompt(extension?: ReadingExtension): string;
|
|
66
|
+
/** What `readingOf()` returns: the invoice, and what the model's answer did not give. */
|
|
67
|
+
export interface ModelReading<E = unknown> {
|
|
68
|
+
/** What the model says the page is. A receipt is an invoice already paid. */
|
|
69
|
+
document: Exclude<DocumentKind, 'other'>;
|
|
70
|
+
/** The page as EN 16931 says it, `syntax: 'model'`. */
|
|
71
|
+
invoice: ReceivedInvoice;
|
|
72
|
+
/**
|
|
73
|
+
* The arithmetic of EN 16931 (BR-CO-10 to BR-CO-17) the printed figures
|
|
74
|
+
* break, as the exact readers report it. Checked only where every total,
|
|
75
|
+
* every line amount and every tax group was read: on a partial reading a
|
|
76
|
+
* rule would only measure what is missing.
|
|
77
|
+
*/
|
|
78
|
+
violations: ReceivedViolation[];
|
|
79
|
+
/** The fields EN 16931 requires that the page did not print, by their path: `number`, `totals.payable`, `lines[2].net_amount`. Each is `''` in the invoice. */
|
|
80
|
+
missing: string[];
|
|
81
|
+
/** The fields the model filled with something that is not of their shape — a date that is not a day, a rate in words. Each is left empty and its path named here. */
|
|
82
|
+
rejected: string[];
|
|
83
|
+
/** The model's confidence, by field (`CONFIDENCE_FIELDS`) and by line (`lines[n]`); `null` where it said nothing usable. */
|
|
84
|
+
confidence: Record<string, Confidence | null>;
|
|
85
|
+
/** Per group of `invoice.taxes`, in order: the amount including tax the page prints at that rate, which EN 16931 does not carry. */
|
|
86
|
+
taxInclusiveByGroup: (DecimalText | null)[];
|
|
87
|
+
/** The properties of the caller's extension, as the model answered them; `null` where it answered none. Not checked here: the caller checks its own. */
|
|
88
|
+
extension: E | null;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* The model's answer, parsed from its JSON, checked into a `ReceivedInvoice`.
|
|
92
|
+
*
|
|
93
|
+
* Anything not of the shape the schema asks for is left empty and named in
|
|
94
|
+
* `rejected`; anything EN 16931 requires and the answer leaves empty is `''`
|
|
95
|
+
* and named in `missing`. Nothing is computed, defaulted or corrected.
|
|
96
|
+
* `undefined` where the answer is not an object, or says the page is not a
|
|
97
|
+
* purchase document.
|
|
98
|
+
*/
|
|
99
|
+
export declare function readingOf<E = unknown>(answer: unknown): ModelReading<E> | undefined;
|
|
100
|
+
//# sourceMappingURL=model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAIL,KAAK,WAAW,EAEhB,KAAK,eAAe,EAKpB,KAAK,iBAAiB,EACvB,MAAM,mBAAmB,CAAC;AAE3B,sHAAsH;AACtH,eAAO,MAAM,eAAe,eAAe,CAAC;AAE5C,4DAA4D;AAC5D,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAC;AAEnD,eAAO,MAAM,WAAW,EAAE,SAAS,UAAU,EAA8B,CAAC;AAE5E,oHAAoH;AACpH,MAAM,MAAM,YAAY,GAAG,SAAS,GAAG,aAAa,GAAG,SAAS,GAAG,OAAO,CAAC;AAE3E;;;GAGG;AACH,eAAO,MAAM,iBAAiB,gLAcpB,CAAC;AAEX,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEjE;;;;GAIG;AACH,eAAO,MAAM,cAAc,EAAE,SAAS,MAAM,EAAmD,CAAC;AAEhG;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,+EAA+E;IAC/E,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACpD,wGAAwG;IACxG,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,6GAA6G;IAC7G,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AA+ED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,SAAS,CAAC,EAAE,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAkEnF;AAED,oGAAoG;AACpG,eAAO,MAAM,cAAc,qpCAQwE,CAAC;AAEpG,kFAAkF;AAClF,wBAAgB,aAAa,CAAC,SAAS,CAAC,EAAE,gBAAgB,GAAG,MAAM,CAKlE;AAMD,yFAAyF;AACzF,MAAM,WAAW,YAAY,CAAC,CAAC,GAAG,OAAO;IACvC,6EAA6E;IAC7E,QAAQ,EAAE,OAAO,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IACzC,uDAAuD;IACvD,OAAO,EAAE,eAAe,CAAC;IACzB;;;;;OAKG;IACH,UAAU,EAAE,iBAAiB,EAAE,CAAC;IAChC,+JAA+J;IAC/J,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,qKAAqK;IACrK,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,4HAA4H;IAC5H,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI,CAAC,CAAC;IAC9C,oIAAoI;IACpI,mBAAmB,EAAE,CAAC,WAAW,GAAG,IAAI,CAAC,EAAE,CAAC;IAC5C,wJAAwJ;IACxJ,SAAS,EAAE,CAAC,GAAG,IAAI,CAAC;CACrB;AAmGD;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,CAAC,GAAG,OAAO,EAAE,MAAM,EAAE,OAAO,GAAG,YAAY,CAAC,CAAC,CAAC,GAAG,SAAS,CAuJnF"}
|