sinfactura-types 1.10.294 → 1.10.295

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/ai.d.ts CHANGED
@@ -62,5 +62,219 @@ declare global {
62
62
  model: string;
63
63
  cached: boolean;
64
64
  }
65
+ /**
66
+ * One line item read off the document.
67
+ *
68
+ * ⚠️ `quantity` and `unitPrice` are optional and their ABSENCE is the
69
+ * uncertainty signal — see `SupplierDocExtractSuggestion`. Absent means the
70
+ * extractor could not read that number on that line; it is never emitted as
71
+ * `0`, because `0` is a value an operator would accept without checking.
72
+ */
73
+ interface SupplierDocExtractItem {
74
+ /**
75
+ * The line's description as printed.
76
+ *
77
+ * ⚠️ May carry personal data — never log it, never put it in an error
78
+ * `message`, never attach it to a Sentry tag.
79
+ */
80
+ description: string;
81
+ /** Units as printed. Absent when illegible — never `0` as a stand-in. */
82
+ quantity?: number;
83
+ /**
84
+ * Per-unit price as printed, in the document's OWN currency — the
85
+ * extractor never converts, and never divides a line total by a quantity
86
+ * to synthesize one. Absent when illegible.
87
+ */
88
+ unitPrice?: number;
89
+ }
90
+ /**
91
+ * One per-alícuota IVA bucket read off the document's tax summary.
92
+ *
93
+ * `id` is the ARCA IVA codeset id — the SAME numbering `InvoiceAlicuota.id`
94
+ * uses, NOT a percentage: 3 = 0 % · 4 = 10,5 % · 5 = 21 % · 6 = 27 % ·
95
+ * 8 = 5 % · 9 = 2,5 %. A rate the extractor cannot map onto one of those six
96
+ * is dropped server-side rather than guessed, so `id` on the wire is always
97
+ * one of them.
98
+ *
99
+ * ⚠️ Deliberately NOT `InvoiceAlicuota`, though the codeset is shared and
100
+ * single-sourced there. `InvoiceAlicuota` is the AUTHORITATIVE breakdown of a
101
+ * voucher THIS store issued and requires both amounts; this is a partial
102
+ * reading of a voucher somebody else issued. Reusing it would force a bucket
103
+ * where only one of the two amounts was legible to be dropped whole — losing
104
+ * "there IS a 21 % line here" — and would tie a compras guess to a ventas
105
+ * shape that the CAE path may reshape for reasons of its own.
106
+ *
107
+ * ⚠️ MAPPING GAP the app must handle: `SupplierInvoice` carries only the
108
+ * 10,5 / 21 / 27 rate slots (`neto10`/`iva10`, `neto21`/`iva21`,
109
+ * `neto27`/`iva27`). Ids 3, 8 and 9 have NO slot on that row, so a bucket
110
+ * carrying one cannot be pre-filled anywhere — surface it to the operator
111
+ * instead of discarding it, or the booked total silently stops matching the
112
+ * voucher.
113
+ */
114
+ interface SupplierDocExtractIvaBucket {
115
+ /** ARCA IVA codeset id — 3, 4, 5, 6, 8 or 9. */
116
+ id: number;
117
+ /** Neto gravado at this rate, as printed. Absent when illegible. */
118
+ baseImp?: number;
119
+ /**
120
+ * IVA liquidado at this rate, as printed. Absent when illegible; `0` is a
121
+ * real, declarable value at the 0 % rate and is not a placeholder.
122
+ */
123
+ importe?: number;
124
+ }
125
+ /**
126
+ * The extracted candidate. Nothing here is persisted by the call that
127
+ * produced it — see the section header.
128
+ *
129
+ * ⚠️ THERE IS NO CONFIDENCE SCORE, per field or per row, and that is a
130
+ * decision rather than an omission. A model's self-reported confidence is
131
+ * uncalibrated — it is generated text, not a measured probability — and
132
+ * publishing one invites exactly the client the suggestion-only posture
133
+ * exists to prevent: one that auto-accepts everything above a threshold and
134
+ * shows the operator only what scored low. The uncertainty signal is ABSENCE
135
+ * instead: every extracted NUMBER is optional, and an absent number means
136
+ * "not legible", never "zero". An app deciding what to highlight for review
137
+ * should highlight every absent field — and treat the whole suggestion as
138
+ * unreviewed until the operator confirms it, because a confidently-read
139
+ * wrong number looks exactly like a confidently-read right one.
140
+ *
141
+ * Both arrays are ALWAYS PRESENT and MAY BE EMPTY — an empty `items` means no
142
+ * line table was readable, and the app still renders the section. ⚠️ This is
143
+ * the opposite convention from `ProductEnrichSuggestion.attributes`
144
+ * (absent-or-non-empty) on purpose: that one feeds optional form slots, these
145
+ * feed two sections the supplier-invoice form always shows.
146
+ */
147
+ interface SupplierDocExtractSuggestion {
148
+ items: SupplierDocExtractItem[];
149
+ ivaBreakdown: SupplierDocExtractIvaBucket[];
150
+ /**
151
+ * Conceptos NO GRAVADOS total, as printed. Document-level rather than an
152
+ * `ivaBreakdown` row on purpose — ARCA's Ids 1 (No Gravado) and 2 (Exento)
153
+ * are Códigos de Operación, not alícuotas, and are rejected inside an IVA
154
+ * array; `InvoiceAlicuota` documents the same rule. Pre-fills
155
+ * `SupplierInvoice.noGravado`. Absent when the document prints no such
156
+ * line, or prints one that is not legible.
157
+ */
158
+ noGravado?: number;
159
+ /**
160
+ * Operaciones EXENTAS total, as printed — same rationale as `noGravado`.
161
+ * Pre-fills `SupplierInvoice.exento`.
162
+ */
163
+ exento?: number;
164
+ }
165
+ /**
166
+ * Request body of the supplier-invoice document-extraction endpoint.
167
+ *
168
+ * ⚠️ There is deliberately no `filename` here, unlike
169
+ * `SupportFileAttachmentUpload`. The server pins a fixed, neutral document
170
+ * name on the model request; a caller-supplied filename would put tenant text
171
+ * into the one field the model transport itself flags as readable as
172
+ * instructions.
173
+ */
174
+ interface SupplierDocExtractRequest {
175
+ /**
176
+ * Declared document format — only `'pdf'` is accepted today, and widening
177
+ * it later is additive. ⚠️ The declaration is VERIFIED against the decoded
178
+ * bytes' magic number: a body declaring `'pdf'` whose bytes are not a PDF
179
+ * is refused `UNSUPPORTED_MEDIA_TYPE` and never reaches the model on
180
+ * trust.
181
+ */
182
+ format: 'pdf';
183
+ /**
184
+ * The document itself, as BARE base64 (no `data:` URI prefix) — the same
185
+ * transport as `SupportFileAttachmentUpload.data`, which is this API's
186
+ * shipped file-ingress shape; there is no presigned-upload route to use
187
+ * instead.
188
+ *
189
+ * Decoded maximum 4 MiB. ⚠️ That ingress cap sits STRICTLY BELOW the model
190
+ * transport's own per-document byte cap, so size is only ever refused
191
+ * here, as `CONTENT_TOO_LARGE` — the larger downstream limit is
192
+ * unreachable from this endpoint and no code reports it.
193
+ *
194
+ * ⚠️ Never logged and never echoed back.
195
+ */
196
+ data: string;
197
+ /**
198
+ * Page count of the document, COUNTED BY THE CALLER.
199
+ *
200
+ * ⚠️ Send it whenever you can. The page cap is only enforceable pre-flight
201
+ * when it is DECLARED — omit it and the check does not run at all: the
202
+ * document is sent, the call is made, the tenant's ceiling is charged for
203
+ * it, and the model provider enforces its own page limit opaquely, so the
204
+ * caller gets a generic upstream failure instead of
205
+ * `DOCUMENT_TOO_MANY_PAGES`. A caller that can cheaply count pages (the
206
+ * app already parses the PDF to preview it) should ALWAYS send this:
207
+ * omitting it buys nothing and gives up the one free refusal.
208
+ *
209
+ * A declared count above the cap is refused before any model call, so
210
+ * nothing is spent.
211
+ */
212
+ pageCount?: number;
213
+ }
214
+ /**
215
+ * `data` payload of the success envelope — the body is
216
+ * `{ message, data: SupplierDocExtractResponse }`, the same envelope
217
+ * `ProductEnrichResponse` rides in.
218
+ *
219
+ * There is no `cached` flag, unlike `ProductEnrichResponse`: every call
220
+ * extracts afresh.
221
+ */
222
+ interface SupplierDocExtractResponse {
223
+ suggestion: SupplierDocExtractSuggestion;
224
+ /** The model that actually produced the extraction. */
225
+ model: string;
226
+ }
227
+ /**
228
+ * The `error` codes this endpoint answers. Bare SCREAMING_SNAKE, no prefix.
229
+ *
230
+ * Three refusal FAMILIES, deliberately not collapsed, because they differ in
231
+ * who paid and what the operator should do next:
232
+ *
233
+ * · INGRESS — `INVALID_BASE64`, `UNSUPPORTED_MEDIA_TYPE`,
234
+ * `CONTENT_TOO_LARGE`, `DOCUMENT_TOO_MANY_PAGES`. The document NEVER
235
+ * REACHED THE MODEL: no call was made, nothing was metered, nothing was
236
+ * billed. The operator fixes the file and retries at once, for free.
237
+ * · BUDGET — `COST_CEILING_EXCEEDED`. A spend ceiling, not a problem with the
238
+ * document. The same file can succeed later, unchanged.
239
+ * · MODEL — `DOC_EXTRACT_BLOCKED`, `DOC_EXTRACT_GENERATION_FAILED`. The
240
+ * document DID reach the model and the call WAS metered. Retrying spends
241
+ * again and rarely helps on the same file.
242
+ *
243
+ * Collapsing an ingress refusal into a model failure is the mistake this
244
+ * split exists to prevent: it tells an operator a call was paid for when
245
+ * none was made, and it hides the one class of failure they can fix.
246
+ *
247
+ * Per member:
248
+ * - `INVALID_BASE64` · 400 — `data` is not well-formed base64.
249
+ * - `UNSUPPORTED_MEDIA_TYPE` · 415 — the decoded bytes are not a PDF,
250
+ * whatever `format` declared.
251
+ * - `CONTENT_TOO_LARGE` · 413 — decoded size over the 4 MiB ingress cap.
252
+ * - `DOCUMENT_TOO_MANY_PAGES` · 413 — the DECLARED `pageCount` exceeds the
253
+ * model's page limit. ⚠️ Reachable ONLY when the caller declared one — see
254
+ * `SupplierDocExtractRequest.pageCount`.
255
+ * - `COST_CEILING_EXCEEDED` · 403 OR 503, and the app must switch on which.
256
+ * 403 is the TENANT's own ceiling and carries `upsell: true` plus
257
+ * `feature: 'aiFeatures'`; 503 is the platform-wide ceiling, carries
258
+ * neither, and is an operator hard-stop that no tenant action clears.
259
+ * ⚠️ The code lands in BOTH `error` and `message`, matching the shipped
260
+ * ceiling mapper — `message` is NOT prose on this member and must not be
261
+ * shown to a user verbatim.
262
+ * - `AI_DOC_EXTRACT_DISABLED` · 503 — the platform kill-switch for this
263
+ * feature is off. Distinct from a ceiling: nothing was spent and no budget
264
+ * is exhausted.
265
+ * - `AI_OPT_OUT` · 403 — this store switched AI off. Fail-closed, so a store
266
+ * read that THREW answers this too; the same code the enrichment endpoint
267
+ * uses, not a second spelling of it.
268
+ * - `DOC_EXTRACT_BLOCKED` · 422 — the model's guardrail refused the document.
269
+ * - `DOC_EXTRACT_GENERATION_FAILED` · 502 — the model answered but not in a
270
+ * shape that parses. Named for symmetry with `ENRICH_GENERATION_FAILED`,
271
+ * which is the same failure on the sibling endpoint.
272
+ *
273
+ * ⚠️ Cross-cutting refusals are NOT listed here and are still reachable —
274
+ * `PLAN_UPGRADE_REQUIRED` above all, since the endpoint is `aiFeatures`-
275
+ * entitled. Check `GatingErrorCode` IN ADDITION to this union, never instead
276
+ * of it.
277
+ */
278
+ type SupplierDocExtractErrorCode = 'INVALID_BASE64' | 'UNSUPPORTED_MEDIA_TYPE' | 'CONTENT_TOO_LARGE' | 'DOCUMENT_TOO_MANY_PAGES' | 'COST_CEILING_EXCEEDED' | 'AI_DOC_EXTRACT_DISABLED' | 'AI_OPT_OUT' | 'DOC_EXTRACT_BLOCKED' | 'DOC_EXTRACT_GENERATION_FAILED';
65
279
  }
66
280
  export {};
package/dist/ai.js CHANGED
@@ -1,2 +1,5 @@
1
- // AI platform-spend contracts (MANAGER dashboard).
1
+ // AI contracts — the MANAGER platform-spend report, plus the tenant-facing
2
+ // AI suggestion endpoints (product enrichment, supplier-invoice document
3
+ // extraction). Every suggestion endpoint here is SUGGESTION-ONLY: each
4
+ // section below restates what its own call does not persist.
2
5
  export {};
package/dist/cjs/ai.js CHANGED
@@ -1,3 +1,6 @@
1
1
  "use strict";
2
- // AI platform-spend contracts (MANAGER dashboard).
2
+ // AI contracts — the MANAGER platform-spend report, plus the tenant-facing
3
+ // AI suggestion endpoints (product enrichment, supplier-invoice document
4
+ // extraction). Every suggestion endpoint here is SUGGESTION-ONLY: each
5
+ // section below restates what its own call does not persist.
3
6
  Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sinfactura-types",
3
- "version": "1.10.294",
3
+ "version": "1.10.295",
4
4
  "description": "Shared wire and entity contracts for the SINFACTURA platform.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",