@bivelio/savings-layer 0.3.1 → 0.4.1
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 +99 -126
- package/dist/index.d.ts +122 -4
- package/dist/index.js +20 -20
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,31 +1,61 @@
|
|
|
1
|
-
#
|
|
1
|
+
# BV‑SALA — the savings layer for your LLM bill
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
provider
|
|
5
|
-
|
|
3
|
+
<p align="center">
|
|
4
|
+
<img src="https://savings.bivelio.com/en/how-it-works/opengraph-image" alt="Your application → BV-SALA → provider API. The bill drops from $330 to $160 a month, measured." width="720">
|
|
5
|
+
</p>
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
<p align="center">
|
|
8
|
+
<a href="https://www.npmjs.com/package/@bivelio/savings-layer"><img src="https://img.shields.io/npm/v/%40bivelio%2Fsavings-layer?color=2F63D8&label=npm" alt="npm version"></a>
|
|
9
|
+
<img src="https://img.shields.io/badge/node-%E2%89%A520-14A06F" alt="Node ≥ 20">
|
|
10
|
+
<img src="https://img.shields.io/badge/license-commercial-0F1218" alt="Commercial license">
|
|
11
|
+
</p>
|
|
12
|
+
|
|
13
|
+
**One layer inside your code, right where your app calls the OpenAI or Anthropic API.**
|
|
14
|
+
For every request it picks the cheapest execution that still meets your quality bar —
|
|
15
|
+
avoiding calls that don't need to happen and trimming what must be sent — and hands
|
|
16
|
+
you an auditable `SavingsReport`. Your bill drops, and you can verify why.
|
|
9
17
|
|
|
10
18
|
> **Commercial software — © 2026 BiVelio Inc.** Free to install, **paid to run**:
|
|
11
|
-
> BV‑SALA is
|
|
12
|
-
>
|
|
13
|
-
>
|
|
14
|
-
>
|
|
15
|
-
|
|
19
|
+
> BV‑SALA is fail‑closed and executes only with an active BiVelio license key.
|
|
20
|
+
> License checks are **offline** and **your prompts never leave your infrastructure** —
|
|
21
|
+
> only counts and cost are ever reported. Use is governed by the [LICENSE](./LICENSE)
|
|
22
|
+
> and the BiVelio Terms. Not a wrapper around any third‑party library.
|
|
23
|
+
|
|
24
|
+
## Where it installs
|
|
25
|
+
|
|
26
|
+
Your application → **BV‑SALA** → provider API. Traffic always goes straight from
|
|
27
|
+
your app to your provider — BV‑SALA is a library inside your code, never a
|
|
28
|
+
middleman server, and it works with any OpenAI‑compatible endpoint (OpenAI, Azure,
|
|
29
|
+
vLLM, SGLang, a gateway) as well as Anthropic.
|
|
30
|
+
|
|
31
|
+
**Only use ChatGPT or Claude?** Then there is nothing to install: those products
|
|
32
|
+
charge a flat subscription, so there is no per‑token bill to cut. BV‑SALA is for
|
|
33
|
+
applications that call the API with their own key. The whole story, in plain words:
|
|
34
|
+
**[Where does the saving install?](https://savings.bivelio.com/en/how-it-works)**
|
|
35
|
+
|
|
36
|
+
## Try it before you install
|
|
37
|
+
|
|
38
|
+
Run the real optimizer **free in your browser** — pick an example or paste your own
|
|
39
|
+
data and watch the meter — at **[savings.bivelio.com](https://savings.bivelio.com)**.
|
|
16
40
|
|
|
17
|
-
## Install
|
|
41
|
+
## Install in three steps
|
|
42
|
+
|
|
43
|
+
**1 · The package**
|
|
18
44
|
|
|
19
45
|
```bash
|
|
20
46
|
pnpm add @bivelio/savings-layer
|
|
21
47
|
# or: npm i @bivelio/savings-layer · yarn add @bivelio/savings-layer
|
|
22
48
|
```
|
|
23
49
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
50
|
+
**2 · The license** — from your [dashboard](https://savings.bivelio.com/dashboard/install)
|
|
51
|
+
(**€4 / seat / month** or **€39 / seat / year**, EUR)
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
export BIVELIO_LICENSE_KEY=… # your license key
|
|
55
|
+
export BIVELIO_SERVICE_KEY=… # service-account key: auto-renewal + seat metering
|
|
56
|
+
```
|
|
27
57
|
|
|
28
|
-
|
|
58
|
+
**3 · Wrap the call** — this is the entire code change:
|
|
29
59
|
|
|
30
60
|
```ts
|
|
31
61
|
import { createSavingsLayer, OpenAICompatibleProvider } from "@bivelio/savings-layer";
|
|
@@ -54,8 +84,30 @@ console.log(report.calls.avoidedLlm); // → whole calls you never paid for
|
|
|
54
84
|
console.log(report.cost.netSavings); // → verified savings, per request
|
|
55
85
|
```
|
|
56
86
|
|
|
57
|
-
|
|
58
|
-
|
|
87
|
+
That's it. From the first request, `report` carries the saving — measured, not
|
|
88
|
+
estimated.
|
|
89
|
+
|
|
90
|
+
## What you get on every request
|
|
91
|
+
|
|
92
|
+
A `SavingsReport` with the numbers behind every claim, kept in **four separate
|
|
93
|
+
ledgers** that are never summed into one flattering figure:
|
|
94
|
+
|
|
95
|
+
| Ledger | Meaning |
|
|
96
|
+
| --- | --- |
|
|
97
|
+
| `avoided_calls` | LLM / retrieval / tool calls that never executed |
|
|
98
|
+
| `eliminated_tokens` | information dropped because it was not needed |
|
|
99
|
+
| `compressed_tokens` | information kept, but encoded with fewer tokens |
|
|
100
|
+
| `provider_cached_tokens` | tokens still in the prompt, billed/processed more cheaply |
|
|
101
|
+
|
|
102
|
+
And a promise you can hold it to: **never worse than your JSON.** Payload encodings
|
|
103
|
+
are chosen by counting real tokens with the destination model's own tokenizer, and
|
|
104
|
+
BV‑SALA only moves away from plain JSON when the saving clearly clears the bar —
|
|
105
|
+
`report.serialization` shows what was chosen and what each candidate would have cost.
|
|
106
|
+
|
|
107
|
+
<details>
|
|
108
|
+
<summary><b>Structured output — validated <code>data</code>, not just text</b></summary>
|
|
109
|
+
|
|
110
|
+
Ask for a response contract and you also get `data`, validated against your schema:
|
|
59
111
|
|
|
60
112
|
```ts
|
|
61
113
|
const { data, text } = await layer.generate<{ answer: number }>({
|
|
@@ -76,42 +128,10 @@ const { data, text } = await layer.generate<{ answer: number }>({
|
|
|
76
128
|
console.log(data.answer); // 8
|
|
77
129
|
```
|
|
78
130
|
|
|
79
|
-
|
|
80
|
-
product and **refuses to run unlicensed, expired, or tampered** (it throws
|
|
81
|
-
`LicenseError` at the `generate()` entry, carrying a `status` of `none`,
|
|
82
|
-
`invalid`, `expired`, `grace`, `revoked` or `stale`). Your key — and this snippet
|
|
83
|
-
with the key already filled in — is at
|
|
84
|
-
[savings.bivelio.com/dashboard/install](https://savings.bivelio.com/dashboard/install).
|
|
85
|
-
|
|
86
|
-
> **Set `serviceAccountKey` on every long‑running deployment.** Your licence token
|
|
87
|
-
> expires at the end of the billing period; each renewal mints a **new** token. With
|
|
88
|
-
> a service‑account key (`bvk_…`, same dashboard) the SDK picks the renewed token up
|
|
89
|
-
> by itself and swaps it in without a restart. **Without it there is no machine
|
|
90
|
-
> pickup**, so somebody has to paste the new token by hand every cycle — and if
|
|
91
|
-
> nobody does, the deployment stops with `LicenseError` once the grace period ends,
|
|
92
|
-
> while the subscription is paid and current. The key also enables seat metering
|
|
93
|
-
> (counts only — never prompts or completions).
|
|
94
|
-
|
|
95
|
-
### Seats (how you are billed)
|
|
96
|
-
|
|
97
|
-
A **seat is a machine**, never a person. The SDK derives a stable, opaque id per
|
|
98
|
-
machine + service-account key and reports it with the counts; the control plane
|
|
99
|
-
bills a seat only once it has been seen on **3 separate days**.
|
|
100
|
-
|
|
101
|
-
**Set `BVSALA_SEAT_ID` (one value per replica or service) whenever the machine
|
|
102
|
-
identity can't be deduced** — Kubernetes, or any fleet where the hostname is
|
|
103
|
-
assigned dynamically. Without it, every pod of a deployment shares one fingerprint
|
|
104
|
-
and the whole deployment counts as a **single** seat. It is also the way to keep
|
|
105
|
-
seat ids stable across an SDK upgrade: the fingerprint changed in v0.1.x, so a
|
|
106
|
-
fleet that never set it may be counted twice in the month it upgrades.
|
|
107
|
-
|
|
108
|
-
```bash
|
|
109
|
-
BVSALA_SEAT_ID=worker-03 # stable per replica; [A-Za-z0-9._:/-], max 128 chars
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
CI runners are auto-detected and excluded from billable seats.
|
|
131
|
+
</details>
|
|
113
132
|
|
|
114
|
-
|
|
133
|
+
<details>
|
|
134
|
+
<summary><b>Tool calls</b></summary>
|
|
115
135
|
|
|
116
136
|
When you pass `tools` and the model asks to invoke one, the reply is not the final
|
|
117
137
|
answer: `text` is empty by design and the request is in `toolCalls`. Execute it,
|
|
@@ -155,92 +175,45 @@ if (res.toolCalls?.length) {
|
|
|
155
175
|
A tool‑call turn is never served from cache and never counted as an avoided call:
|
|
156
176
|
an action that has not run yet cannot be a saving.
|
|
157
177
|
|
|
158
|
-
>
|
|
159
|
-
> **only when building from source** (this repo's tests and benchmarks). They are
|
|
160
|
-
> **disabled in this published package** — a valid `licenseKey` is the only way to
|
|
161
|
-
> run it. They are not a way to use the product for free.
|
|
162
|
-
|
|
163
|
-
Every component ships with an in‑memory default and is independently swappable:
|
|
164
|
-
plug in your own cache, vector store, tokenizer, compressor or constraint backend
|
|
165
|
-
behind the same interfaces.
|
|
166
|
-
|
|
167
|
-
## The optimization order (cheapest first)
|
|
178
|
+
</details>
|
|
168
179
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
3. **Eliminate unnecessary context** before trying to shrink what remains.
|
|
172
|
-
4. **Shrink** the tokens that genuinely must be sent.
|
|
173
|
-
5. **Constrain generation** to emit only the structure and length required.
|
|
180
|
+
<details>
|
|
181
|
+
<summary><b>Running a fleet? Seats and renewals</b></summary>
|
|
174
182
|
|
|
175
|
-
|
|
183
|
+
- **A seat is a machine, never a person.** A seat is billed only once it has been
|
|
184
|
+
seen on 3 separate days, and CI runners are auto‑detected and excluded.
|
|
185
|
+
- **Set `serviceAccountKey` on every long‑running deployment.** Renewals mint a new
|
|
186
|
+
license token each billing period; with the service‑account key (`bvk_…`, same
|
|
187
|
+
dashboard) the SDK picks the renewed token up by itself, without a restart.
|
|
188
|
+
- **Set `BVSALA_SEAT_ID` (one stable value per replica) on Kubernetes or any fleet
|
|
189
|
+
with dynamic hostnames**, so each replica counts as what it is:
|
|
176
190
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
## Four separate ledgers (never summed)
|
|
181
|
-
|
|
182
|
-
Mixing these produces misleading metrics, so BV‑SALA keeps them apart:
|
|
183
|
-
|
|
184
|
-
| Ledger | Meaning |
|
|
185
|
-
| --- | --- |
|
|
186
|
-
| `avoided_calls` | LLM / retrieval / tool calls that never executed |
|
|
187
|
-
| `eliminated_tokens` | information dropped because it was not needed |
|
|
188
|
-
| `compressed_tokens` | information kept, but encoded with fewer tokens |
|
|
189
|
-
| `provider_cached_tokens` | tokens still in the prompt, billed/processed more cheaply |
|
|
190
|
-
|
|
191
|
-
A cache hit removes a whole call. A re‑encode makes a payload smaller. Compression
|
|
192
|
-
drops redundant words. A prefix cache makes tokens cheaper without removing them.
|
|
193
|
-
Four different things — summing them would lie to you, so the report never does.
|
|
194
|
-
|
|
195
|
-
## The decision cascade
|
|
196
|
-
|
|
197
|
-
```
|
|
198
|
-
Request
|
|
199
|
-
→ Canonicalize + Policy (risk & freshness)
|
|
200
|
-
→ Deterministic resolvers ─────────────► answer (0 calls)
|
|
201
|
-
→ Exact cache ─────────────────────────► answer (0 calls)
|
|
202
|
-
→ Concurrent duplicates coalesced ─────► answer (0 calls)
|
|
203
|
-
→ Near-duplicate reuse ────────────► answer (0 calls)
|
|
204
|
-
→ Execution planning (how much work this really needs)
|
|
205
|
-
→ Context reduction (only when it pays for itself)
|
|
206
|
-
→ Payload encoding chosen by measurement, not by default
|
|
207
|
-
→ Output contract enforced
|
|
208
|
-
→ ONE primary LLM call
|
|
209
|
-
→ Structural + semantic validation (+ ≤1 repair)
|
|
210
|
-
→ Local render / transcode / cache write
|
|
211
|
-
→ SavingsReport + traces
|
|
191
|
+
```bash
|
|
192
|
+
BVSALA_SEAT_ID=worker-03 # stable per replica; [A-Za-z0-9._:/-], max 128 chars
|
|
212
193
|
```
|
|
213
194
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
A compact encoding can be *larger* than plain JSON on nested or non‑uniform data,
|
|
217
|
-
so BV‑SALA never assumes one. It counts the candidates with the destination
|
|
218
|
-
model's own tokenizer — including the cost of explaining the encoding to the
|
|
219
|
-
model — and only moves away from JSON when the saving clears a margin worth the
|
|
220
|
-
change.
|
|
221
|
-
|
|
222
|
-
On a wide, uniform table that is a large reduction. On a small nested object it
|
|
223
|
-
leaves JSON alone. Whichever it picks, `report.serialization` tells you what was
|
|
224
|
-
chosen and what each candidate would have cost, so the decision is auditable
|
|
225
|
-
rather than promised.
|
|
195
|
+
</details>
|
|
226
196
|
|
|
227
|
-
|
|
197
|
+
<details>
|
|
198
|
+
<summary><b>Requirements</b></summary>
|
|
228
199
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
200
|
+
- **Node ≥ 20.** The package is **ESM‑only** (`"type": "module"`); from CommonJS,
|
|
201
|
+
`require()` works on Node ≥ 22.
|
|
202
|
+
- Optional peer `gpt-tokenizer` for exact OpenAI token counts — without it a
|
|
203
|
+
built‑in estimator is used, so it is not required to get started.
|
|
204
|
+
- Every component (cache, vector store, tokenizer, compressor, constraint backend)
|
|
205
|
+
ships with an in‑memory default and is independently swappable behind the same
|
|
206
|
+
interfaces.
|
|
233
207
|
|
|
234
|
-
|
|
235
|
-
the token counts behind it.
|
|
208
|
+
</details>
|
|
236
209
|
|
|
237
210
|
## Licensing & privacy
|
|
238
211
|
|
|
239
212
|
BV‑SALA is commercial, per‑seat software (**€4 / seat / month** or **€39 / seat /
|
|
240
213
|
year**, EUR). The license is a signed token your SDK verifies **offline**; the
|
|
241
|
-
managed control plane
|
|
242
|
-
|
|
243
|
-
|
|
214
|
+
managed control plane and the revocation kill‑switch are served from BiVelio. Your
|
|
215
|
+
LLM traffic goes **straight to your provider** — BiVelio sees counts and cost,
|
|
216
|
+
never prompts or completions.
|
|
244
217
|
|
|
245
218
|
Get a key and read the terms at **[savings.bivelio.com](https://savings.bivelio.com)**.
|
|
246
219
|
Onboarding & general questions: **support@bivelio.com** · licensing & compliance:
|
package/dist/index.d.ts
CHANGED
|
@@ -1348,7 +1348,21 @@ interface SemanticHit {
|
|
|
1348
1348
|
ageMs: number;
|
|
1349
1349
|
}
|
|
1350
1350
|
interface SemanticCacheOptions {
|
|
1351
|
-
|
|
1351
|
+
/**
|
|
1352
|
+
* How text becomes a vector. OPTIONAL: omit it and {@link embebedorLocal} is
|
|
1353
|
+
* used — no network, no API key, no per-call cost.
|
|
1354
|
+
*
|
|
1355
|
+
* It used to be required, and the package shipped NO implementation, so this
|
|
1356
|
+
* cache could not be constructed without bringing your own embedding provider.
|
|
1357
|
+
* That is why the benchmark reported it as unmeasurable run after run: not that
|
|
1358
|
+
* it saved little, but that it never got to run at all.
|
|
1359
|
+
*
|
|
1360
|
+
* Pass your own for true semantics; the local one only sees LEXICAL closeness.
|
|
1361
|
+
* Either way the deterministic guard below still rejects a candidate whose
|
|
1362
|
+
* numbers, negation or entities differ, so a weaker vector can only cost you a
|
|
1363
|
+
* cache miss — never a wrong answer.
|
|
1364
|
+
*/
|
|
1365
|
+
embed?: EmbeddingFn;
|
|
1352
1366
|
verify?: SemanticVerifier;
|
|
1353
1367
|
/** Cosine similarity floor for a candidate to be considered at all. */
|
|
1354
1368
|
similarityThreshold?: number;
|
|
@@ -1376,7 +1390,7 @@ declare class InMemorySemanticCache {
|
|
|
1376
1390
|
private readonly ttlMs;
|
|
1377
1391
|
private readonly maxRecords;
|
|
1378
1392
|
private readonly now;
|
|
1379
|
-
constructor(opts
|
|
1393
|
+
constructor(opts?: SemanticCacheOptions);
|
|
1380
1394
|
/**
|
|
1381
1395
|
* Find a safe hit for a canonical request, or null. Metadata filters run
|
|
1382
1396
|
* FIRST and hard — a candidate from another tenant, scope, or knowledge epoch
|
|
@@ -1389,6 +1403,63 @@ declare class InMemorySemanticCache {
|
|
|
1389
1403
|
get size(): number;
|
|
1390
1404
|
}
|
|
1391
1405
|
|
|
1406
|
+
/**
|
|
1407
|
+
* A LOCAL EMBEDDING FUNCTION — no network, no API key, no per-call cost.
|
|
1408
|
+
*
|
|
1409
|
+
* The semantic cache needs a way to compare meaning. Wiring it to a hosted
|
|
1410
|
+
* embedding endpoint is the obvious answer and a bad default: it makes every
|
|
1411
|
+
* miss cost a network round-trip and money, and it forces a provider choice onto
|
|
1412
|
+
* a customer who never asked for one. So the cache shipped with no embedder at
|
|
1413
|
+
* all, which means it never matched anything.
|
|
1414
|
+
*
|
|
1415
|
+
* This is the third option: a deterministic bag-of-features vector computed in
|
|
1416
|
+
* microseconds from the text itself. It captures LEXICAL closeness — the same
|
|
1417
|
+
* question asked with different filler words — which is the overwhelming majority
|
|
1418
|
+
* of real repeat traffic. It does NOT capture deep semantics: "what is a CDN"
|
|
1419
|
+
* and "explain content delivery networks" share no tokens and will not match.
|
|
1420
|
+
*
|
|
1421
|
+
* WHY THAT IS SAFE, AND THIS IS THE PART THAT MATTERS. A semantic cache's one
|
|
1422
|
+
* unforgivable failure is confidently answering a NEARBY BUT DIFFERENT question.
|
|
1423
|
+
* This vector never gets the chance: the cache runs a deterministic precision
|
|
1424
|
+
* guard beneath the embedding — matching numbers and dates, negation parity and a
|
|
1425
|
+
* content-overlap floor — and every isolation field (tenant, principal, model,
|
|
1426
|
+
* schema, attached data) is a hard filter applied before similarity is scored.
|
|
1427
|
+
* A weak embedding can only cause a MISS, which costs one real call. It cannot
|
|
1428
|
+
* produce a wrong answer.
|
|
1429
|
+
*
|
|
1430
|
+
* Pass your own `embed` to {@link InMemorySemanticCache} to get true semantics.
|
|
1431
|
+
* This one exists so that the feature is worth something with zero setup.
|
|
1432
|
+
*/
|
|
1433
|
+
/**
|
|
1434
|
+
* The vector for a piece of text.
|
|
1435
|
+
*
|
|
1436
|
+
* Features are unigrams plus adjacent bigrams: bigrams are what keep word ORDER
|
|
1437
|
+
* from being free. Without them "does A cause B" and "does B cause A" are the
|
|
1438
|
+
* same point in space.
|
|
1439
|
+
*
|
|
1440
|
+
* Term weight is sublinear (`1 + log tf`) so a word repeated forty times does not
|
|
1441
|
+
* dominate the direction of the vector, and the result is L2-normalised so cosine
|
|
1442
|
+
* similarity is a plain dot product.
|
|
1443
|
+
*/
|
|
1444
|
+
declare function vectorLocal(texto: string): number[];
|
|
1445
|
+
/**
|
|
1446
|
+
* The default embedding function for {@link InMemorySemanticCache}.
|
|
1447
|
+
*
|
|
1448
|
+
* Synchronous by design — it returns the array, not a promise — so a cache lookup
|
|
1449
|
+
* adds no await and no latency to the request path.
|
|
1450
|
+
*/
|
|
1451
|
+
declare function embebedorLocal(texto: string): number[];
|
|
1452
|
+
/**
|
|
1453
|
+
* The similarity floor this embedder is calibrated for.
|
|
1454
|
+
*
|
|
1455
|
+
* A lexical vector sits lower than a sentence-transformer on genuine paraphrases,
|
|
1456
|
+
* so the 0.9 default that suits a hosted embedder would reject almost everything
|
|
1457
|
+
* here. This value was measured on paraphrase pairs against near-miss pairs, not
|
|
1458
|
+
* guessed — see `test/embebedor-local.test.ts`, which fails if the two
|
|
1459
|
+
* populations stop being separable.
|
|
1460
|
+
*/
|
|
1461
|
+
declare const UMBRAL_LOCAL = 0.72;
|
|
1462
|
+
|
|
1392
1463
|
/**
|
|
1393
1464
|
* Deterministic resolvers.
|
|
1394
1465
|
*
|
|
@@ -2231,6 +2302,18 @@ interface AnthropicOptions {
|
|
|
2231
2302
|
* pointless: the extra breakpoints are rejected by the API, not ignored.
|
|
2232
2303
|
*/
|
|
2233
2304
|
maxCacheBreakpoints?: number;
|
|
2305
|
+
/**
|
|
2306
|
+
* Whether a request carrying BOTH the caller's tools and an output contract
|
|
2307
|
+
* may send `tool_choice: {type: "any"}`, which obliges the model to answer
|
|
2308
|
+
* through SOME tool — its pick — instead of writing prose.
|
|
2309
|
+
*
|
|
2310
|
+
* Defaults to `true`, and the default is the point: without it this exact
|
|
2311
|
+
* combination measured 62% MORE expensive than sending no layer at all, every
|
|
2312
|
+
* single time, because prose forces a second full call to repair. Turning it
|
|
2313
|
+
* off restores the old behaviour for a caller who genuinely needs a plain-text
|
|
2314
|
+
* turn to be reachable while a contract is attached.
|
|
2315
|
+
*/
|
|
2316
|
+
forceAnswerThroughTool?: boolean;
|
|
2234
2317
|
}
|
|
2235
2318
|
declare class AnthropicProvider implements Provider {
|
|
2236
2319
|
readonly id: string;
|
|
@@ -2919,6 +3002,41 @@ interface SavingsLayerConfig {
|
|
|
2919
3002
|
defaultCostModel?: CostModel;
|
|
2920
3003
|
/** TTL for exact-cache writes, in ms. */
|
|
2921
3004
|
exactCacheTtlMs?: number;
|
|
3005
|
+
/**
|
|
3006
|
+
* Refuse the single repair retry when paying for it would push this request's
|
|
3007
|
+
* cost above what it would have cost WITHOUT the layer. The invalid answer is
|
|
3008
|
+
* then returned as-is with `constraints.structurallyValid: false`, plus a
|
|
3009
|
+
* warning naming the three figures.
|
|
3010
|
+
*
|
|
3011
|
+
* OFF by default, and the default is a deliberate, measured choice rather than
|
|
3012
|
+
* caution — read this before turning it on.
|
|
3013
|
+
*
|
|
3014
|
+
* The bound sounds narrow ("only the worst case") and is not. The baseline of
|
|
3015
|
+
* a call that ran is reconstructed EXCLUDING the repair (see `estimateCost`:
|
|
3016
|
+
* `actualInput - repairInput`), precisely so a retry cannot pay for itself in
|
|
3017
|
+
* the report. That makes the threshold unreachable by construction: the repair
|
|
3018
|
+
* only ever moves `actual`, never the baseline, so ANY repair breaches it
|
|
3019
|
+
* whenever the layer's other books came out flat. On a request where nothing
|
|
3020
|
+
* was compressed, cached or eliminated, `baseline === actual` exactly and the
|
|
3021
|
+
* gate suppresses every repair, however cheap.
|
|
3022
|
+
*
|
|
3023
|
+
* So this is not "cap the tail", it is "stop repairing unless the layer has
|
|
3024
|
+
* already banked more than the repair will cost". That is a real quality
|
|
3025
|
+
* policy, not a rounding rule, and it is the caller's contract to decide on —
|
|
3026
|
+
* hence opt-in.
|
|
3027
|
+
*
|
|
3028
|
+
* There is no threshold that fires on the pathological case and spares the
|
|
3029
|
+
* flat one; they are the same arithmetic at different magnitudes. And there is
|
|
3030
|
+
* a genuine argument on the other side: an answer that misses its contract is
|
|
3031
|
+
* a MODEL failure, so the no-layer path would have had to pay for its own
|
|
3032
|
+
* second call too — charging the whole retry against the layer compares one
|
|
3033
|
+
* valid answer to one invalid answer.
|
|
3034
|
+
*
|
|
3035
|
+
* Turn it on when a hard per-request ceiling matters more than contract
|
|
3036
|
+
* compliance — a batch backfill, a cost-capped tenant. Leave it off when the
|
|
3037
|
+
* caller relies on the shape being right.
|
|
3038
|
+
*/
|
|
3039
|
+
skipRepairAboveBaseline?: boolean;
|
|
2922
3040
|
/**
|
|
2923
3041
|
* Reliability contract. When true (the default), ANY internal optimizer error
|
|
2924
3042
|
* (a resolver, cache, format selector, compressor, or accounting bug) is
|
|
@@ -3075,6 +3193,6 @@ declare function createSavingsLayer(config: Omit<SavingsLayerConfig, "tokenizer"
|
|
|
3075
3193
|
* constant to package.json so the two can never drift.
|
|
3076
3194
|
*/
|
|
3077
3195
|
|
|
3078
|
-
declare const BV_SALA_VERSION = "0.
|
|
3196
|
+
declare const BV_SALA_VERSION = "0.4.1";
|
|
3079
3197
|
|
|
3080
|
-
export { type AnthropicOptions, AnthropicProvider, BV_SALA_VERSION, type BivelioHandoff, CATALOGO, COMPACT_ROWS_INSTRUCTION, type CacheOutcome, type CacheTier, type CachedAnswer, type CanonicalRequest, type ChatMessage, type CompactRowsDecodeOptions, type CompactRowsOptions, type CompactVerification, type CompressionEconomics, type CompressionPolicyInput, type CompressionRequest, type CompressionResult, type Compressor, type ConstraintBackend, type ConstraintBackendId, type ConstraintPlan, type ConversationState, type CostBasis, type CostModel, DEFAULT_COST_MODEL, type DeferredExecutionReport, type DeterministicResolver, EMBEDDED_PUBLIC_KEY, type EmbeddingFn, type EvidenceDoc, type ExactCache, ExactTokenizer, type ExecutionClass, ExecutionRouter, type FormatChoice, FormatSelector, type FormatSelectorOptions, type HandoffFact, HeuristicEstimator, InMemoryExactCache, InMemorySemanticCache, type JsonSchema, LicenseError, type LicenseGate, type LicenseKeyset, type LicenseStatus, type LicenseTokenPayload, type LocalClassifier, MODELOS_POR_CODIFICACION, MODELS_BY_ENCODING, type MemoryDelta, type MessageRole, MockProvider, type MockProviderOptions, type ModelCascadeMode, type ModelCascadeReport, type ModelCascadeSettings, type OpenAICompatibleOptions, OpenAICompatibleProvider, type OutputContract, PRECIOS_AL_DIA, type Policy, type ProtectedSpan, type Provider, type ProviderRequest, type ProviderResponse, type ProviderUsage, QUALITY_STATUSES, type QualityStatus, type RequestContext, type Reranker, type ResolvedDeps, type ResolvedGate, type ResolvedLicense, ResolverRegistry, type ResolverResult, type RetrievalOptions, type RetrievalOutcome, type RetrievalPlan, type Retriever, type RevocationListBody, type RevocationListVerification, type RevocationPollEvent, RevocationPoller, type RevocationPollerOptions, RevocationSnapshot, type RouteDecision, type SavingsLayer, type SavingsLayerConfig, SavingsLedger, type SavingsReport, type SavingsRequest, type SavingsResult, type SavingsToggles, SchemaRegistry, type SemanticCacheOptions, type SemanticHit, type SemanticRecord, type SemanticVerifier, type SerializationFormat, type Serializer, Singleflight, type TokenEstimator, TokenizerRegistry, type ToolCallRequest, type ToolDescriptor, type ToolRisk, type ToolSelection, ToolSelector, type ToolSelectorOptions, TraceCollector, type TraceEvent, UsageEmitter, type UsageEmitterOptions, type ValidationError, type ValidationResult, adaptiveK, arithmeticResolver, buildExactKey, buildInflightKey, canonicalize, compactRowsSerializer, computeNextDelay, cosine, createCompactRowsSerializer, createDefaultResolvers, createHandoff, createMockProvider, createSavingsLayer, csvSerializer, decodeCompactRows, dedupe, defaultTokenizerRegistry, deriveSeatId, deriveStatus, detectCi, emptyState, encodeCompactRows, evalArithmetic, evaluatePolicy, executeRetrievalPlan, gateFromKey, heuristicEstimator, isKeyset, isStrictCompatible, jsonCompactSerializer, keyTokensMatch, liveGateFromKey, mergeDelta, modelFamilyOf, noopCompressor, normalizeText, precioDeLista, projectContext, providerNativeBackend, randomId, registerExactTokenizer, registrarTokenizadorExacto, renderState, resolveConstraintBackend, resolveDependencies, resolveLicense, sha256, shouldCompress, stableStringify, uniformColumns, validateAgainstSchema, verifyCompactSignature, verifyLicenseToken, verifyRevocationList, withProtectedSpans };
|
|
3198
|
+
export { type AnthropicOptions, AnthropicProvider, BV_SALA_VERSION, type BivelioHandoff, CATALOGO, COMPACT_ROWS_INSTRUCTION, type CacheOutcome, type CacheTier, type CachedAnswer, type CanonicalRequest, type ChatMessage, type CompactRowsDecodeOptions, type CompactRowsOptions, type CompactVerification, type CompressionEconomics, type CompressionPolicyInput, type CompressionRequest, type CompressionResult, type Compressor, type ConstraintBackend, type ConstraintBackendId, type ConstraintPlan, type ConversationState, type CostBasis, type CostModel, DEFAULT_COST_MODEL, type DeferredExecutionReport, type DeterministicResolver, EMBEDDED_PUBLIC_KEY, type EmbeddingFn, type EvidenceDoc, type ExactCache, ExactTokenizer, type ExecutionClass, ExecutionRouter, type FormatChoice, FormatSelector, type FormatSelectorOptions, type HandoffFact, HeuristicEstimator, InMemoryExactCache, InMemorySemanticCache, type JsonSchema, LicenseError, type LicenseGate, type LicenseKeyset, type LicenseStatus, type LicenseTokenPayload, type LocalClassifier, MODELOS_POR_CODIFICACION, MODELS_BY_ENCODING, type MemoryDelta, type MessageRole, MockProvider, type MockProviderOptions, type ModelCascadeMode, type ModelCascadeReport, type ModelCascadeSettings, type OpenAICompatibleOptions, OpenAICompatibleProvider, type OutputContract, PRECIOS_AL_DIA, type Policy, type ProtectedSpan, type Provider, type ProviderRequest, type ProviderResponse, type ProviderUsage, QUALITY_STATUSES, type QualityStatus, type RequestContext, type Reranker, type ResolvedDeps, type ResolvedGate, type ResolvedLicense, ResolverRegistry, type ResolverResult, type RetrievalOptions, type RetrievalOutcome, type RetrievalPlan, type Retriever, type RevocationListBody, type RevocationListVerification, type RevocationPollEvent, RevocationPoller, type RevocationPollerOptions, RevocationSnapshot, type RouteDecision, type SavingsLayer, type SavingsLayerConfig, SavingsLedger, type SavingsReport, type SavingsRequest, type SavingsResult, type SavingsToggles, SchemaRegistry, type SemanticCacheOptions, type SemanticHit, type SemanticRecord, type SemanticVerifier, type SerializationFormat, type Serializer, Singleflight, type TokenEstimator, TokenizerRegistry, type ToolCallRequest, type ToolDescriptor, type ToolRisk, type ToolSelection, ToolSelector, type ToolSelectorOptions, TraceCollector, type TraceEvent, UMBRAL_LOCAL, UsageEmitter, type UsageEmitterOptions, type ValidationError, type ValidationResult, adaptiveK, arithmeticResolver, buildExactKey, buildInflightKey, canonicalize, compactRowsSerializer, computeNextDelay, cosine, createCompactRowsSerializer, createDefaultResolvers, createHandoff, createMockProvider, createSavingsLayer, csvSerializer, decodeCompactRows, dedupe, defaultTokenizerRegistry, deriveSeatId, deriveStatus, detectCi, embebedorLocal, emptyState, encodeCompactRows, evalArithmetic, evaluatePolicy, executeRetrievalPlan, gateFromKey, heuristicEstimator, isKeyset, isStrictCompatible, jsonCompactSerializer, keyTokensMatch, liveGateFromKey, mergeDelta, modelFamilyOf, noopCompressor, normalizeText, precioDeLista, projectContext, providerNativeBackend, randomId, registerExactTokenizer, registrarTokenizadorExacto, renderState, resolveConstraintBackend, resolveDependencies, resolveLicense, sha256, shouldCompress, stableStringify, uniformColumns, validateAgainstSchema, vectorLocal, verifyCompactSignature, verifyLicenseToken, verifyRevocationList, withProtectedSpans };
|