sinfactura-types 1.10.341 → 1.10.342

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
@@ -295,5 +295,175 @@ declare global {
295
295
  * of it.
296
296
  */
297
297
  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_TOO_LONG' | 'DOC_EXTRACT_GENERATION_FAILED';
298
+ /**
299
+ * One suggested line.
300
+ *
301
+ * ⚠️ `sku` and `name` are read off the store's OWN product row by the
302
+ * server, never echoed from the model, so they always describe the real
303
+ * catalogue entry behind `productId`. `productId` itself is guaranteed to
304
+ * exist, to belong to the authenticated store and to be sale-eligible — the
305
+ * server refuses the WHOLE draft rather than returning a line it cannot
306
+ * prove all three of.
307
+ */
308
+ interface QuoteDraftLine {
309
+ /** `PROD` + digits — a real, enabled, sale-eligible product of this store. */
310
+ productId: string;
311
+ sku: string;
312
+ name: string;
313
+ /** A whole number of units, 1–999. Never `0`, never fractional, never clamped from something else. */
314
+ quantity: number;
315
+ /**
316
+ * One sentence on why this product answers the request, at most 200
317
+ * characters. Model-generated prose — display it, never parse it.
318
+ */
319
+ rationale: string;
320
+ }
321
+ interface QuoteDraftRequest {
322
+ /**
323
+ * The operator's request, in their own words — 3 to 600 characters.
324
+ *
325
+ * ⚠️ Do NOT put customer data in here. It reaches the model, and this
326
+ * endpoint's whole input-minimisation posture is that nothing personal
327
+ * does (Ley 25.326).
328
+ */
329
+ request: string;
330
+ /**
331
+ * `CUST` + 6–10 digits.
332
+ *
333
+ * ⚠️ ECHOED BACK, never read. The server does not fetch the customer, does
334
+ * not validate it beyond that shape, and never sends it to the model — who
335
+ * a quote is for changes nothing about which products match. It exists so
336
+ * a client can round-trip the quote form's state through the call. The
337
+ * presupuesto CREATE path is what validates the customer.
338
+ */
339
+ customerId?: string;
340
+ }
341
+ /**
342
+ * `data` payload of the success envelope — the body is
343
+ * `{ message, data: QuoteDraftResponse }`.
344
+ *
345
+ * ⚠️ `lines` is never empty on a 200. A draft with no lines is a refusal
346
+ * instead, and WHICH refusal says whether it cost anything — see
347
+ * `QuoteDraftErrorCode`.
348
+ */
349
+ interface QuoteDraftResponse {
350
+ lines: QuoteDraftLine[];
351
+ /**
352
+ * How many catalogue rows the model was actually shown.
353
+ *
354
+ * ⚠️ Read this WITH `truncated`, never instead of it: it is the size of
355
+ * the grounded subset, not the number of products that matched.
356
+ */
357
+ candidateCount: number;
358
+ /**
359
+ * How many of the store's products matched the request and survived
360
+ * eligibility, BEFORE the candidate cap — the denominator `truncated`
361
+ * is a fact about.
362
+ *
363
+ * ⚠️ Read it WITH `candidateCount`: the pair is what lets a client say
364
+ * "60 of 137" rather than the useless "60, and there were more". It is
365
+ * `>= candidateCount` always, and EQUAL to it whenever `truncated` is
366
+ * false. It is a count of matches, NOT of the catalogue — a store with
367
+ * 5 000 products whose request matched 3 reports `3`.
368
+ */
369
+ matchedCount: number;
370
+ /**
371
+ * `true` when MORE of the store's catalogue matched the request than was
372
+ * shown to the model — because the request reduced to more search terms
373
+ * than are searched, because one term's matches were cut, because the
374
+ * union exceeded the candidate cap, or because a term's read spent its
375
+ * page/wall-clock budget before it filled.
376
+ *
377
+ * ⚠️ It means "there may be a better line we never offered", NOT "no
378
+ * match" — those are different answers and the empty case never reaches a
379
+ * 200 at all. A client should surface this as a prompt to narrow the
380
+ * request, and must not present a truncated draft as an exhaustive read of
381
+ * the catalogue.
382
+ */
383
+ truncated: boolean;
384
+ /** The model that produced it. */
385
+ model: string;
386
+ /** Echoed from the request when it was sent — see `QuoteDraftRequest.customerId`. */
387
+ customerId?: string;
388
+ }
389
+ /**
390
+ * The `error` codes this endpoint answers. Bare SCREAMING_SNAKE, no prefix.
391
+ *
392
+ * Three refusal FAMILIES, split on WHO PAID, the same reasoning
393
+ * `SupplierDocExtractErrorCode` records:
394
+ *
395
+ * · FREE — `VALIDATION_FAILED`, `QUOTE_DRAFT_NO_MATCH`,
396
+ * `COST_CEILING_EXCEEDED`, `AI_OPT_OUT`. No model call was made and nothing
397
+ * was metered.
398
+ * · METERED, ordinary — `QUOTE_DRAFT_AMBIGUOUS`. The call ran and the model
399
+ * legitimately found nothing to suggest.
400
+ * · METERED, model fault — `QUOTE_DRAFT_BLOCKED`,
401
+ * `QUOTE_DRAFT_GENERATION_FAILED`, `QUOTE_DRAFT_UNGROUNDED`,
402
+ * `QUOTE_DRAFT_INVALID_QUANTITY`, `QUOTE_DRAFT_DUPLICATE_LINE`,
403
+ * `QUOTE_DRAFT_TOO_MANY_LINES`. The call ran and its output was refused.
404
+ * Retrying spends again and rarely helps.
405
+ *
406
+ * Per member:
407
+ * - `VALIDATION_FAILED` · 400 — the request body failed its schema: `request`
408
+ * outside 3–600 characters after trimming, or a `customerId` that is not
409
+ * `CUST` + 6–10 digits. ⚠️ Listed HERE rather than left to `GatingErrorCode`
410
+ * because it is not a member of that union — it comes from the shared
411
+ * request validator, and the domain unions that can answer it
412
+ * (`PresupuestoErrorCode` among them) each carry it.
413
+ * - `QUOTE_DRAFT_NO_MATCH` · 422 — nothing in the catalogue matched the
414
+ * request at all, so no model call was made. ⚠️ NOT the same answer as
415
+ * `QUOTE_DRAFT_AMBIGUOUS`: this one is free and is fixed by naming a
416
+ * product the store actually sells.
417
+ * - `QUOTE_DRAFT_AMBIGUOUS` · 422 — candidates existed, the model saw them,
418
+ * and it proposed no line. The call WAS metered. Fixed by a more specific
419
+ * request, not by retrying the same one.
420
+ * - `COST_CEILING_EXCEEDED` · 403 OR 503, and the app must switch on which.
421
+ * 403 is the TENANT's own ceiling and carries `feature: 'aiFeatures'`; 503
422
+ * is the platform-wide ceiling and is an operator hard-stop no tenant
423
+ * action clears. ⚠️ Both carry `period: 'daily' | 'monthly'`, and on the
424
+ * 403 `upsell` is TRUE only for `monthly` — a daily ceiling is a single
425
+ * app-scope value applying to every tier, so no upgrade clears it and it
426
+ * resets at midnight instead. ⚠️ The code lands in BOTH `error` and
427
+ * `message`, matching the shipped ceiling mapper: `message` is NOT prose on
428
+ * this member and must not be shown to a user verbatim.
429
+ * - `AI_OPT_OUT` · 403 — this store switched AI off, explicitly. The same code
430
+ * the sibling AI endpoints use, not a second spelling of it. ⚠️ A store read
431
+ * that THREW does NOT answer this: the gate is fail-closed in that it never
432
+ * proceeds, but it RETHROWS, so the wire answer is the wrapper's 500, not a
433
+ * 403. Do not treat this code as covering "AI may be off".
434
+ * - `QUOTE_DRAFT_BLOCKED` · 422 — the guardrail refused the request. ⚠️
435
+ * Carries one DOCUMENTED EXTRA key, `reason: string` — the guardrail's
436
+ * filter TYPE NAMES, never the blocked content. It is the only member with
437
+ * it, so read it optionally rather than off the union.
438
+ * - `QUOTE_DRAFT_GENERATION_FAILED` · 502 — the model answered in a shape
439
+ * that does not parse.
440
+ * - `QUOTE_DRAFT_UNGROUNDED` · 502 — the model named a product that is not in
441
+ * this store's candidate set: an invented id, another store's id, a
442
+ * disabled product, or one that is not sale-eligible. ⚠️ The WHOLE draft is
443
+ * refused, never just the offending line. A silently shorter list is
444
+ * indistinguishable from a complete one, and a model that ignored a closed
445
+ * set it was handed has tainted the ids that happened to be valid too.
446
+ * - `QUOTE_DRAFT_INVALID_QUANTITY` · 502 — a proposed quantity was not a whole
447
+ * number in 1–999. Refused, never clamped and never defaulted to 1:
448
+ * substituting a plausible number hides the misread from the one human who
449
+ * could catch it.
450
+ * - `QUOTE_DRAFT_DUPLICATE_LINE` · 502 — the same product was proposed twice.
451
+ * - `QUOTE_DRAFT_TOO_MANY_LINES` · 502 — more than 20 lines were proposed.
452
+ *
453
+ * ⚠️ Both of those two are REACHABLE, and keeping them so is a constraint on
454
+ * the server rather than a fact about it. They were briefly shadowed: the
455
+ * same two bounds also sat on the model's forced tool schema, which is
456
+ * `safeParse`d BEFORE the belt runs, so an out-of-range quantity or a 21st
457
+ * line was rejected a step earlier and reached the wire as the generic
458
+ * `QUOTE_DRAFT_GENERATION_FAILED`. The bounds now live on the belt alone.
459
+ * ⛔ A client may build a distinct affordance for each; putting either bound
460
+ * back on the tool schema would collapse it again without failing any type.
461
+ *
462
+ * ⚠️ Cross-cutting refusals are NOT listed here and are still reachable —
463
+ * `PLAN_UPGRADE_REQUIRED` above all, since the endpoint is `aiFeatures`-
464
+ * entitled, and `IMPERSONATION_READONLY`, since it is an AI-spend route.
465
+ * Check `GatingErrorCode` IN ADDITION to this union, never instead of it.
466
+ */
467
+ type QuoteDraftErrorCode = 'VALIDATION_FAILED' | 'QUOTE_DRAFT_NO_MATCH' | 'QUOTE_DRAFT_AMBIGUOUS' | 'COST_CEILING_EXCEEDED' | 'AI_OPT_OUT' | 'QUOTE_DRAFT_BLOCKED' | 'QUOTE_DRAFT_GENERATION_FAILED' | 'QUOTE_DRAFT_UNGROUNDED' | 'QUOTE_DRAFT_INVALID_QUANTITY' | 'QUOTE_DRAFT_DUPLICATE_LINE' | 'QUOTE_DRAFT_TOO_MANY_LINES';
298
468
  }
299
469
  export {};
package/dist/ai.js CHANGED
@@ -1,5 +1,6 @@
1
1
  // AI contracts — the MANAGER platform-spend report, plus the tenant-facing
2
2
  // AI suggestion endpoints (product enrichment, supplier-invoice document
3
- // extraction). Every suggestion endpoint here is SUGGESTION-ONLY: each
3
+ // extraction, presupuesto line drafting). Every suggestion endpoint here is
4
+ // SUGGESTION-ONLY: each
4
5
  // section below restates what its own call does not persist.
5
6
  export {};
package/dist/cjs/ai.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  // AI contracts — the MANAGER platform-spend report, plus the tenant-facing
3
3
  // AI suggestion endpoints (product enrichment, supplier-invoice document
4
- // extraction). Every suggestion endpoint here is SUGGESTION-ONLY: each
4
+ // extraction, presupuesto line drafting). Every suggestion endpoint here is
5
+ // SUGGESTION-ONLY: each
5
6
  // section below restates what its own call does not persist.
6
7
  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.341",
3
+ "version": "1.10.342",
4
4
  "description": "Shared wire and entity contracts for the SINFACTURA platform.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",