@bivelio/savings-layer 0.4.25 → 0.4.26
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 +215 -11
- package/dist/adapters/anthropic-sdk.js +20 -19
- package/dist/adapters/langchain.js +54 -53
- package/dist/gateway/bin.js +892 -616
- package/dist/index.d.ts +674 -7
- package/dist/index.js +1285 -992
- package/docs/terminales/README.md +59 -11
- package/docs/terminales/aider.md +74 -0
- package/docs/terminales/continue.md +47 -0
- package/docs/terminales/copilot.md +114 -0
- package/docs/terminales/kilo.md +54 -31
- package/docs/terminales/no-soportados.md +41 -0
- package/docs/terminales/opencode.md +33 -11
- package/package.json +21 -3
package/dist/index.d.ts
CHANGED
|
@@ -142,6 +142,14 @@ declare class SavingsLedger {
|
|
|
142
142
|
* not yet billed as verifiable against the invoice).
|
|
143
143
|
*/
|
|
144
144
|
elididoLocal: number;
|
|
145
|
+
/**
|
|
146
|
+
* Tokens (LOCAL ruler) that tool-output compaction removed from the sent
|
|
147
|
+
* prompt. Subtracted from `removedInputLocal` for the same reason as
|
|
148
|
+
* {@link elididoLocal}: the saving is a COUNT in ledger 3 (`compressedInput`)
|
|
149
|
+
* and never enters the reconstructed baseline or the commission, so `basis`
|
|
150
|
+
* stays "measured" and the provider's invoice shows the effect on its own.
|
|
151
|
+
*/
|
|
152
|
+
compactedLocal: number;
|
|
145
153
|
/**
|
|
146
154
|
* ¿El estimador que produjo las dos cifras anteriores cuenta con la regla del
|
|
147
155
|
* proveedor? Lo fija el pipeline al resolver el tokenizador del modelo.
|
|
@@ -303,7 +311,7 @@ declare function precioDeLista(model: string, at?: Date | number): CostModel | u
|
|
|
303
311
|
* on the customer's machine. `test/version-declarada.test.ts` ties this
|
|
304
312
|
* constant to package.json so the two can never drift.
|
|
305
313
|
*/
|
|
306
|
-
declare const BV_SALA_VERSION = "0.4.
|
|
314
|
+
declare const BV_SALA_VERSION = "0.4.26";
|
|
307
315
|
|
|
308
316
|
/**
|
|
309
317
|
* Environment-agnostic UUID generation.
|
|
@@ -517,6 +525,35 @@ interface RetrievalOptions {
|
|
|
517
525
|
maxRounds?: number;
|
|
518
526
|
maxDocuments?: number;
|
|
519
527
|
}
|
|
528
|
+
/**
|
|
529
|
+
* How a request chooses between the provider's native tool search and the layer's
|
|
530
|
+
* tool selector. See {@link SavingsToggles.toolSearch}.
|
|
531
|
+
*
|
|
532
|
+
* - `"off"` (default): the layer's tool selector runs, as without this option.
|
|
533
|
+
* - `"auto"`: native tool search when the adapter talks to the provider's own API host,
|
|
534
|
+
* the catalogue reaches the provider's documented size threshold, and deferring it
|
|
535
|
+
* pays for one search on every request even with a warm prompt cache. Otherwise the
|
|
536
|
+
* selector runs.
|
|
537
|
+
* - `"always"`: native tool search whenever the adapter and model support it, with no
|
|
538
|
+
* size or cost check. Use it when a proxy in front of the provider forwards the
|
|
539
|
+
* search blocks, or when you have measured it on your own traffic.
|
|
540
|
+
*/
|
|
541
|
+
type ToolSearchMode = "off" | "auto" | "always";
|
|
542
|
+
/** The long form of {@link SavingsToggles.toolSearch}. */
|
|
543
|
+
interface ToolSearchOptions {
|
|
544
|
+
mode: ToolSearchMode;
|
|
545
|
+
/**
|
|
546
|
+
* Tool ids sent without deferred loading, so the model can call them without
|
|
547
|
+
* searching first. They are part of the cached prefix: keep the list short and the
|
|
548
|
+
* same on every request. Ids that are not in the request's tools are ignored.
|
|
549
|
+
*/
|
|
550
|
+
alwaysLoaded?: string[];
|
|
551
|
+
/**
|
|
552
|
+
* The provider's search: `"bm25"` (the model writes natural-language queries; the
|
|
553
|
+
* default) or `"regex"` (the model writes regular expressions).
|
|
554
|
+
*/
|
|
555
|
+
variant?: "bm25" | "regex";
|
|
556
|
+
}
|
|
520
557
|
interface SavingsToggles {
|
|
521
558
|
exactCache?: boolean;
|
|
522
559
|
/**
|
|
@@ -563,6 +600,30 @@ interface SavingsToggles {
|
|
|
563
600
|
* and never enters your commission — your invoice stays the source of truth.
|
|
564
601
|
*/
|
|
565
602
|
elision?: boolean;
|
|
603
|
+
/**
|
|
604
|
+
* OPT-IN. Compact the text of `role: "tool"` messages before the request is
|
|
605
|
+
* sent: terminal escape sequences and superseded progress-bar states are
|
|
606
|
+
* removed, whitespace between JSON tokens is removed when the whole output is
|
|
607
|
+
* JSON, and runs of identical consecutive lines are folded into one line plus
|
|
608
|
+
* a count. Nothing is summarised and no word is dropped.
|
|
609
|
+
*
|
|
610
|
+
* IT NEVER REWRITES WHAT THE PROVIDER HAS ALREADY CACHED. The decision for each
|
|
611
|
+
* tool output depends only on its own text and on the call that produced it,
|
|
612
|
+
* so an output compacted on the turn it arrives is re-sent with the same bytes
|
|
613
|
+
* on every later turn and the prefix cache keeps matching. Turn it on for a
|
|
614
|
+
* whole conversation (or layer-wide with `toolOutputCompaction` in
|
|
615
|
+
* `createSavingsLayer`), not halfway through one: the first compacted request
|
|
616
|
+
* of a conversation that started without it rewrites the history once.
|
|
617
|
+
*
|
|
618
|
+
* Outputs of calls whose arguments name a file are left verbatim by default,
|
|
619
|
+
* because an agent that edits files by exact string match copies what it read.
|
|
620
|
+
* `false` switches it off for this request even when the layer enables it.
|
|
621
|
+
*
|
|
622
|
+
* What it removes is a COUNT in `report.tokens.compressedInput`; it is never
|
|
623
|
+
* priced into `cost.netSavings` or your commission — your provider's invoice
|
|
624
|
+
* shows the effect.
|
|
625
|
+
*/
|
|
626
|
+
toolOutputCompaction?: boolean;
|
|
566
627
|
serialization?: boolean | "auto";
|
|
567
628
|
singleflight?: boolean;
|
|
568
629
|
deterministicResolvers?: boolean;
|
|
@@ -656,6 +717,37 @@ interface SavingsToggles {
|
|
|
656
717
|
* action can be lost to a discovery step.
|
|
657
718
|
*/
|
|
658
719
|
toolDiscovery?: boolean;
|
|
720
|
+
/**
|
|
721
|
+
* OPT-IN. Let the PROVIDER search your tool catalogue instead of the layer's tool
|
|
722
|
+
* selector. Defaults to `"off"`. Read {@link ToolSearchMode} for the three modes.
|
|
723
|
+
*
|
|
724
|
+
* With it applied, every tool you pass travels on every request, marked for deferred
|
|
725
|
+
* loading, next to the provider's search tool. The provider keeps deferred definitions
|
|
726
|
+
* out of the prompt prefix; the model searches the catalogue when it needs a tool, and
|
|
727
|
+
* the definitions it finds are added after the prefix. No tool you declared becomes
|
|
728
|
+
* unreachable, and the cached prefix stays the same when the question changes or the
|
|
729
|
+
* catalogue grows.
|
|
730
|
+
*
|
|
731
|
+
* WHERE IT APPLIES. The Anthropic adapter of this package, on a model listed in the
|
|
732
|
+
* provider's tool search compatibility table, with at least one tool to defer.
|
|
733
|
+
* Requests with an output contract, or with the model cascade on, keep the selector.
|
|
734
|
+
* OpenAI documents its tool search for the Responses and Agents APIs, not for Chat
|
|
735
|
+
* Completions, which the OpenAI-compatible adapter speaks, so it keeps the selector too.
|
|
736
|
+
* `report.traces` says which path ran and why (entry `tool-search`).
|
|
737
|
+
*
|
|
738
|
+
* WHAT IT IS WORTH BELONGS TO THE PROVIDER. Your provider's usage counter reflects it
|
|
739
|
+
* directly. The layer credits nothing for it, adds nothing to any ledger for it and
|
|
740
|
+
* charges no commission on it, and a request served this way is never used as the
|
|
741
|
+
* reference to value a later repeat.
|
|
742
|
+
*
|
|
743
|
+
* WHAT CHANGES FOR YOU. Relevance pruning of read tools is off: the model chooses.
|
|
744
|
+
* When your catalogue declares `risk`, write and destructive tools are still withheld
|
|
745
|
+
* from requests the router does not classify as actions, as with the selector. Each
|
|
746
|
+
* search is a short extra step inside the same call, and the definitions it loads are
|
|
747
|
+
* billed as normal input. This adapter sends earlier turns as text, so a later turn
|
|
748
|
+
* that needs a tool searches again.
|
|
749
|
+
*/
|
|
750
|
+
toolSearch?: ToolSearchMode | ToolSearchOptions;
|
|
659
751
|
/**
|
|
660
752
|
* Send the request to a CHEAPER model of the same family, check the answer
|
|
661
753
|
* with a deterministic gate, and fall back to the model you asked for only
|
|
@@ -1236,7 +1328,31 @@ type QualityCacheMatch = {
|
|
|
1236
1328
|
* negation parity and content-word overlap. A hit is never served without it.
|
|
1237
1329
|
*/
|
|
1238
1330
|
factGuard: "passed";
|
|
1331
|
+
/**
|
|
1332
|
+
* Present when the cache runs with `calibration`: the bound this reuse was
|
|
1333
|
+
* served under, and the labels behind it.
|
|
1334
|
+
*/
|
|
1335
|
+
calibration?: SemanticCalibrationBound;
|
|
1239
1336
|
};
|
|
1337
|
+
/**
|
|
1338
|
+
* The bound a calibrated semantic reuse was served under: with probability at
|
|
1339
|
+
* least `confidence`, at most `maxErrorRate` of the reuses served at or above
|
|
1340
|
+
* `floor` are wrong, where "wrong" is what the calibration's judge rejects.
|
|
1341
|
+
* It rests on the labels counted here, which your own traffic produced.
|
|
1342
|
+
*/
|
|
1343
|
+
interface SemanticCalibrationBound {
|
|
1344
|
+
maxErrorRate: number;
|
|
1345
|
+
confidence: number;
|
|
1346
|
+
/** The certified floor this reuse's score cleared. */
|
|
1347
|
+
floor: number;
|
|
1348
|
+
/** Held-out labels at or above the floor that certified it, and how many were wrong reuses. */
|
|
1349
|
+
heldOutAtFloor: number;
|
|
1350
|
+
wrongHeldOutAtFloor: number;
|
|
1351
|
+
/** Labels collected in this traffic segment. */
|
|
1352
|
+
labeled: number;
|
|
1353
|
+
/** Calibrations are kept apart for single-shot and agentic traffic. */
|
|
1354
|
+
segment: "single_shot" | "agentic";
|
|
1355
|
+
}
|
|
1240
1356
|
/** What the model cascade decided on this request. See {@link ModelCascadeReport}. */
|
|
1241
1357
|
interface QualityCascadeCheck {
|
|
1242
1358
|
mode: "shadow" | "on";
|
|
@@ -1402,7 +1518,8 @@ interface SavingsReport {
|
|
|
1402
1518
|
deferred?: DeferredExecutionReport;
|
|
1403
1519
|
/**
|
|
1404
1520
|
* Where the provider was allowed to write its prompt cache. Present whenever
|
|
1405
|
-
* `savings.standalone` is `true`, including when it changed nothing
|
|
1521
|
+
* `savings.standalone` is `true`, including when it changed nothing, and when
|
|
1522
|
+
* `cacheBreakpoints: "auto"` switched this request to explicit mode.
|
|
1406
1523
|
*/
|
|
1407
1524
|
cacheWrites?: CacheWriteReport;
|
|
1408
1525
|
/** How a streamed request was delivered. Present only on results of `generateStream`. */
|
|
@@ -1761,6 +1878,103 @@ declare function stableStringify(value: unknown): string;
|
|
|
1761
1878
|
declare function modelFamilyOf(model: string): string;
|
|
1762
1879
|
declare function canonicalize(request: SavingsRequest): CanonicalRequest;
|
|
1763
1880
|
|
|
1881
|
+
/**
|
|
1882
|
+
* Decides whether a stored answer would have been right for a new request,
|
|
1883
|
+
* given the answer your provider just produced for it. `true` = the stored
|
|
1884
|
+
* answer was reusable.
|
|
1885
|
+
*
|
|
1886
|
+
* It is the definition of "correct" behind every calibrated floor: the bound
|
|
1887
|
+
* holds for what your judge accepts, nothing more. A judge that calls a model
|
|
1888
|
+
* costs money this layer does not see and never subtracts from a saving.
|
|
1889
|
+
*/
|
|
1890
|
+
type AnswerJudge = (stored: CachedAnswer, fresh: CachedAnswer) => boolean | Promise<boolean>;
|
|
1891
|
+
/**
|
|
1892
|
+
* Opt-in calibration of the semantic cache: instead of a fixed acceptance floor,
|
|
1893
|
+
* the cache serves a reworded request only at or above a floor that labeled
|
|
1894
|
+
* traffic has certified, so that at most `maxErrorRate` of the reuses served
|
|
1895
|
+
* from that floor up are wrong, at the stated `confidence`.
|
|
1896
|
+
*
|
|
1897
|
+
* Until a floor is certified the cache serves nothing: every candidate goes to
|
|
1898
|
+
* your provider, exactly as it would without the cache, and the fresh answer is
|
|
1899
|
+
* compared with the stored one to produce a label. Calibration costs reuses,
|
|
1900
|
+
* never an extra provider call.
|
|
1901
|
+
*
|
|
1902
|
+
* Only candidates at or above `similarityThreshold` are labeled, so no floor
|
|
1903
|
+
* below it can be certified: lower it to let the calibration look further down.
|
|
1904
|
+
* Your verifier, if any, still scores every candidate, and the score that is
|
|
1905
|
+
* calibrated is the lower of similarity and its score.
|
|
1906
|
+
*/
|
|
1907
|
+
interface SemanticCalibrationOptions {
|
|
1908
|
+
/** Highest share of wrong reuses you accept, in (0, 0.5]. E.g. 0.02. */
|
|
1909
|
+
maxErrorRate: number;
|
|
1910
|
+
/** Confidence of the bound, in (0.5, 1). Default 0.95. */
|
|
1911
|
+
confidence?: number;
|
|
1912
|
+
/**
|
|
1913
|
+
* How a label is produced. Default {@link sameAnswer}: identical structured
|
|
1914
|
+
* data, or identical text after trimming and collapsing whitespace. For free
|
|
1915
|
+
* text, pass your own: with the default, two differently worded correct
|
|
1916
|
+
* answers count as a wrong reuse, and the floor stays uncertified.
|
|
1917
|
+
*/
|
|
1918
|
+
judge?: AnswerJudge;
|
|
1919
|
+
/**
|
|
1920
|
+
* Share of reuses that clear the floor but are sent to your provider anyway,
|
|
1921
|
+
* to keep labeling above it. In [0, 1). Default 0.05. Without these labels
|
|
1922
|
+
* the floor cannot be re-tested where it serves.
|
|
1923
|
+
*/
|
|
1924
|
+
auditRate?: number;
|
|
1925
|
+
/**
|
|
1926
|
+
* Stop serving a stored answer at or below a score where it was already
|
|
1927
|
+
* judged wrong for another request. It only ever removes reuses. Default true.
|
|
1928
|
+
*/
|
|
1929
|
+
perRecordFloors?: boolean;
|
|
1930
|
+
/** Source of randomness for audits, in [0, 1). Default `Math.random`. */
|
|
1931
|
+
random?: () => number;
|
|
1932
|
+
}
|
|
1933
|
+
/** One labeled reuse decision: the score the cache would have served on, and whether the stored answer was right. */
|
|
1934
|
+
interface CalibrationObservation {
|
|
1935
|
+
score: number;
|
|
1936
|
+
correct: boolean;
|
|
1937
|
+
}
|
|
1938
|
+
/** Where a calibration stands. */
|
|
1939
|
+
interface SemanticCalibrationStatus {
|
|
1940
|
+
maxErrorRate: number;
|
|
1941
|
+
confidence: number;
|
|
1942
|
+
/** Lowest certified score; null while the labels certify none. */
|
|
1943
|
+
floor: number | null;
|
|
1944
|
+
/** Labels collected. */
|
|
1945
|
+
labeled: number;
|
|
1946
|
+
/** Labels kept apart to test the floor (about half). */
|
|
1947
|
+
heldOut: number;
|
|
1948
|
+
/** Held-out labels at or above the floor, and how many of them were wrong reuses. 0 without a floor. */
|
|
1949
|
+
heldOutAtFloor: number;
|
|
1950
|
+
wrongHeldOutAtFloor: number;
|
|
1951
|
+
/**
|
|
1952
|
+
* Held-out labels at or above a floor, all correct, that the next test needs
|
|
1953
|
+
* to certify it: the shortest possible wait, not a promise.
|
|
1954
|
+
*/
|
|
1955
|
+
minHeldOutToCertify: number;
|
|
1956
|
+
/** Online only: the label count at which the floor is re-tested next. Each test comes when the labels have grown by half. */
|
|
1957
|
+
nextTestAt?: number;
|
|
1958
|
+
}
|
|
1959
|
+
/** Default {@link AnswerJudge}: the stored answer counts as right only if it is the same answer. */
|
|
1960
|
+
declare function sameAnswer(stored: CachedAnswer, fresh: CachedAnswer): boolean;
|
|
1961
|
+
/**
|
|
1962
|
+
* Certifies an acceptance floor from labels you already have (your own traffic,
|
|
1963
|
+
* or a labeled set scored with your embedder), with the same test the cache
|
|
1964
|
+
* runs online. Pass the result's `floor` as `acceptThreshold`, or `null` means
|
|
1965
|
+
* these labels do not support any floor at this bound.
|
|
1966
|
+
*
|
|
1967
|
+
* The labels are split at random (fixed seed, independent of their content):
|
|
1968
|
+
* one half proposes candidate floors, the other half tests them, most
|
|
1969
|
+
* conservative first, with an exact binomial test. With probability at least `confidence`, the share of wrong
|
|
1970
|
+
* reuses at or above the returned floor is at most `maxErrorRate`, provided new
|
|
1971
|
+
* requests come from the same distribution as these labels.
|
|
1972
|
+
*/
|
|
1973
|
+
declare function calibrateSemanticFloor(observations: readonly CalibrationObservation[], options: {
|
|
1974
|
+
maxErrorRate: number;
|
|
1975
|
+
confidence?: number;
|
|
1976
|
+
}): SemanticCalibrationStatus;
|
|
1977
|
+
|
|
1764
1978
|
/**
|
|
1765
1979
|
* Semantic cache (safe-by-construction).
|
|
1766
1980
|
*
|
|
@@ -1823,6 +2037,11 @@ interface SemanticRecord {
|
|
|
1823
2037
|
/** Sampling seed of the request, or null when it set none. */
|
|
1824
2038
|
seed: number | null;
|
|
1825
2039
|
storedAtMs: number;
|
|
2040
|
+
/**
|
|
2041
|
+
* With calibration on: the highest score at which this stored answer was
|
|
2042
|
+
* judged wrong for another request. It is never served at or below it.
|
|
2043
|
+
*/
|
|
2044
|
+
failedAtScore?: number;
|
|
1826
2045
|
}
|
|
1827
2046
|
interface SemanticHit {
|
|
1828
2047
|
record: SemanticRecord;
|
|
@@ -1840,6 +2059,30 @@ interface SemanticHit {
|
|
|
1840
2059
|
embedder: "built_in" | "custom";
|
|
1841
2060
|
/** Whether a verifier scored this hit. When false, `verifierScore` equals `similarity`. */
|
|
1842
2061
|
verifierRan: boolean;
|
|
2062
|
+
/** With calibration on: the bound this hit is served under. `acceptFloor` is then the certified floor. */
|
|
2063
|
+
calibration?: SemanticCalibrationBound;
|
|
2064
|
+
}
|
|
2065
|
+
/**
|
|
2066
|
+
* With calibration on, a candidate the cache did not serve: the request goes to
|
|
2067
|
+
* your provider, and {@link InMemorySemanticCache.observe} turns the answer into
|
|
2068
|
+
* a label.
|
|
2069
|
+
*
|
|
2070
|
+
* - `calibrating`: no floor is certified yet in this traffic segment.
|
|
2071
|
+
* - `below_floor`: the candidate's score is under the certified floor.
|
|
2072
|
+
* - `record_floor`: this stored answer was already judged wrong at this score or higher.
|
|
2073
|
+
* - `audit`: the candidate cleared the floor and was sampled to keep testing it.
|
|
2074
|
+
*/
|
|
2075
|
+
interface SemanticProbe {
|
|
2076
|
+
reason: "calibrating" | "below_floor" | "record_floor" | "audit";
|
|
2077
|
+
/** The score the decision was made on: the lower of similarity and your verifier's score. */
|
|
2078
|
+
score: number;
|
|
2079
|
+
segment: "single_shot" | "agentic";
|
|
2080
|
+
record: SemanticRecord;
|
|
2081
|
+
}
|
|
2082
|
+
/** What {@link InMemorySemanticCache.lookup} found: a hit to serve, a candidate to label, or neither. */
|
|
2083
|
+
interface SemanticLookup {
|
|
2084
|
+
hit: SemanticHit | null;
|
|
2085
|
+
probe: SemanticProbe | null;
|
|
1843
2086
|
}
|
|
1844
2087
|
interface SemanticCacheOptions {
|
|
1845
2088
|
/**
|
|
@@ -1865,6 +2108,12 @@ interface SemanticCacheOptions {
|
|
|
1865
2108
|
ttlMs?: number;
|
|
1866
2109
|
maxRecords?: number;
|
|
1867
2110
|
now?: () => number;
|
|
2111
|
+
/**
|
|
2112
|
+
* Opt-in: replace the fixed acceptance floor with one your own labeled
|
|
2113
|
+
* traffic certifies for a wrong-reuse rate you choose. Off by default. See
|
|
2114
|
+
* {@link SemanticCalibrationOptions}.
|
|
2115
|
+
*/
|
|
2116
|
+
calibration?: SemanticCalibrationOptions;
|
|
1868
2117
|
}
|
|
1869
2118
|
declare function cosine(a: number[], b: number[]): number;
|
|
1870
2119
|
declare function numericTokens(s: string): string[];
|
|
@@ -1889,13 +2138,53 @@ declare class InMemorySemanticCache {
|
|
|
1889
2138
|
private readonly maxRecords;
|
|
1890
2139
|
private readonly now;
|
|
1891
2140
|
private readonly embebedorPropio;
|
|
2141
|
+
private readonly calibracion;
|
|
2142
|
+
private readonly estados;
|
|
2143
|
+
private readonly pendientes;
|
|
2144
|
+
private readonly aceptacionExplicita;
|
|
1892
2145
|
constructor(opts?: SemanticCacheOptions);
|
|
2146
|
+
/** Whether this cache runs with `calibration`. */
|
|
2147
|
+
get calibrated(): boolean;
|
|
1893
2148
|
/**
|
|
1894
2149
|
* Find a safe hit for a canonical request, or null. Metadata filters run
|
|
1895
2150
|
* FIRST and hard — a candidate from another tenant, scope, or knowledge epoch
|
|
1896
2151
|
* is never even scored.
|
|
2152
|
+
*
|
|
2153
|
+
* With calibration on, it returns only a hit served under a certified floor
|
|
2154
|
+
* and labels nothing: without {@link lookup} and {@link observe} (the layer
|
|
2155
|
+
* calls both) the calibration never gets a label and never certifies.
|
|
1897
2156
|
*/
|
|
1898
2157
|
find(c: CanonicalRequest): Promise<SemanticHit | null>;
|
|
2158
|
+
/**
|
|
2159
|
+
* The best candidate that passes every hard filter, the similarity floor and
|
|
2160
|
+
* the fact guard. With `conAceptacion`, also the confidence floor (the path
|
|
2161
|
+
* without calibration, unchanged); without it, calibration decides.
|
|
2162
|
+
*/
|
|
2163
|
+
private mejorCandidata;
|
|
2164
|
+
/**
|
|
2165
|
+
* Like {@link find}, and with calibration on it also returns the candidate it
|
|
2166
|
+
* did not serve, so the caller can label it with {@link observe} once the
|
|
2167
|
+
* provider has answered. Without calibration, `probe` is always null.
|
|
2168
|
+
*
|
|
2169
|
+
* `agentic` picks the traffic segment: calibrations are kept apart for
|
|
2170
|
+
* single-shot and agentic requests.
|
|
2171
|
+
*/
|
|
2172
|
+
lookup(c: CanonicalRequest, opts?: {
|
|
2173
|
+
agentic?: boolean;
|
|
2174
|
+
}): Promise<SemanticLookup>;
|
|
2175
|
+
/**
|
|
2176
|
+
* Label a candidate {@link lookup} did not serve, with the answer your provider
|
|
2177
|
+
* produced for that request. Resolves to the judge's verdict, or null when
|
|
2178
|
+
* there is no calibration or the judge failed (no label is recorded then).
|
|
2179
|
+
* It never rejects.
|
|
2180
|
+
*/
|
|
2181
|
+
observe(probe: SemanticProbe, fresh: CachedAnswer): Promise<boolean | null>;
|
|
2182
|
+
private etiquetar;
|
|
2183
|
+
/** Resolves once every pending {@link observe} has recorded its label. */
|
|
2184
|
+
settled(): Promise<void>;
|
|
2185
|
+
/** Where the calibration of a traffic segment stands, or null without calibration. */
|
|
2186
|
+
calibrationStatus(segment?: SemanticProbe["segment"]): SemanticCalibrationStatus | null;
|
|
2187
|
+
private estadoDe;
|
|
1899
2188
|
store(c: CanonicalRequest, answer: CachedAnswer): Promise<void>;
|
|
1900
2189
|
/** Drop every record for a knowledge epoch (invalidation on re-index). */
|
|
1901
2190
|
invalidateEpoch(knowledgeEpoch: string): number;
|
|
@@ -2310,6 +2599,69 @@ declare const noopCompressor: Compressor;
|
|
|
2310
2599
|
*/
|
|
2311
2600
|
declare function compresionFiel(original: string, comprimido: string): boolean;
|
|
2312
2601
|
|
|
2602
|
+
/** A deterministic, content-only transformation applied to a tool output. */
|
|
2603
|
+
type CompactionTransform = "ansi" | "carriage-return" | "json" | "repeated-lines";
|
|
2604
|
+
/** Every transformation, in the order they are applied. */
|
|
2605
|
+
declare const COMPACTION_TRANSFORMS: readonly CompactionTransform[];
|
|
2606
|
+
/**
|
|
2607
|
+
* How tool outputs are compacted. Every field is optional.
|
|
2608
|
+
*
|
|
2609
|
+
* The decision for each tool output depends only on its own text and the tool
|
|
2610
|
+
* call that produced it — never on its position, the size of the prompt or the
|
|
2611
|
+
* model — so an output compacted when it first arrives is re-sent with the same
|
|
2612
|
+
* bytes on every later turn and the provider's prefix cache keeps matching.
|
|
2613
|
+
* Change these settings between conversations, not in the middle of one: a
|
|
2614
|
+
* change rewrites outputs the provider has already cached.
|
|
2615
|
+
*/
|
|
2616
|
+
interface ToolOutputCompactionSettings {
|
|
2617
|
+
/** Which transformations may run. Default: all of {@link COMPACTION_TRANSFORMS}. */
|
|
2618
|
+
transforms?: readonly CompactionTransform[];
|
|
2619
|
+
/**
|
|
2620
|
+
* Leave an output verbatim unless compaction removes at least this many
|
|
2621
|
+
* characters (default 256). Small gains are not worth changing the text the
|
|
2622
|
+
* model sees.
|
|
2623
|
+
*/
|
|
2624
|
+
minSavedChars?: number;
|
|
2625
|
+
/** Tool names whose outputs are never compacted. */
|
|
2626
|
+
exceptTools?: readonly string[];
|
|
2627
|
+
/**
|
|
2628
|
+
* Also compact outputs of tool calls whose arguments name a file (`path`,
|
|
2629
|
+
* `file_path`, `filename`…). Default `false`: an agent that edits files by
|
|
2630
|
+
* exact string match copies what it read, and a compacted view of a file
|
|
2631
|
+
* would not match the file on disk.
|
|
2632
|
+
*/
|
|
2633
|
+
compactFileViews?: boolean;
|
|
2634
|
+
}
|
|
2635
|
+
/** The outcome of compacting one tool output. */
|
|
2636
|
+
interface ToolOutputCompaction {
|
|
2637
|
+
/** The text to send: compacted when `changed`, otherwise the input as-is. */
|
|
2638
|
+
text: string;
|
|
2639
|
+
changed: boolean;
|
|
2640
|
+
/** Transformations that changed the text, in the order they ran. */
|
|
2641
|
+
applied: CompactionTransform[];
|
|
2642
|
+
originalChars: number;
|
|
2643
|
+
compactChars: number;
|
|
2644
|
+
/** Why the output was, or was not, compacted. */
|
|
2645
|
+
reason: string;
|
|
2646
|
+
}
|
|
2647
|
+
/** Default minimum saving, in characters, for an output to be compacted. */
|
|
2648
|
+
declare const DEFAULT_MIN_SAVED_CHARS = 256;
|
|
2649
|
+
/**
|
|
2650
|
+
* Compact one tool output with deterministic, content-only transformations.
|
|
2651
|
+
*
|
|
2652
|
+
* Nothing is summarised and no word is dropped: terminal escape sequences and
|
|
2653
|
+
* superseded progress-bar states are removed, whitespace between JSON tokens is
|
|
2654
|
+
* removed (strings and numbers are kept byte for byte, and the result must parse
|
|
2655
|
+
* to the same value), and runs of identical consecutive lines are folded into
|
|
2656
|
+
* the first line plus a count that expands back to the exact original.
|
|
2657
|
+
*
|
|
2658
|
+
* The same input always produces the same output. Call it where a tool result
|
|
2659
|
+
* is produced, before you append it to your conversation history, and the
|
|
2660
|
+
* history itself holds the compacted text — the provider's prefix cache is
|
|
2661
|
+
* never disturbed.
|
|
2662
|
+
*/
|
|
2663
|
+
declare function compactToolOutput(text: string, settings?: ToolOutputCompactionSettings): ToolOutputCompaction;
|
|
2664
|
+
|
|
2313
2665
|
/** What the layer needs to know about a provider's prefix cache to price a decision. */
|
|
2314
2666
|
interface CacheTier {
|
|
2315
2667
|
/**
|
|
@@ -2468,6 +2820,53 @@ interface ProviderRequest {
|
|
|
2468
2820
|
* letting the provider choose. Others ignore it.
|
|
2469
2821
|
*/
|
|
2470
2822
|
explicitCacheWrites?: boolean;
|
|
2823
|
+
/**
|
|
2824
|
+
* Provider-native tool search, decided by the layer for this request. An adapter that
|
|
2825
|
+
* supports it sends every tool with deferred loading except `alwaysLoaded`, plus the
|
|
2826
|
+
* provider's search tool. The layer sets it only for adapters of this package that
|
|
2827
|
+
* declared the capability; other providers never receive it.
|
|
2828
|
+
*/
|
|
2829
|
+
toolSearch?: ProviderToolSearch;
|
|
2830
|
+
/**
|
|
2831
|
+
* Where the layer's breakpoint placer (`cacheBreakpoints: "auto"`) wants the
|
|
2832
|
+
* provider's prompt cache written, on top of `stablePrefixMessages`. Only
|
|
2833
|
+
* adapters with explicit breakpoints (Anthropic) act on it; others ignore it.
|
|
2834
|
+
* Absent: the adapter's fixed placement.
|
|
2835
|
+
*/
|
|
2836
|
+
cachePlacement?: CachePlacement;
|
|
2837
|
+
}
|
|
2838
|
+
/** See {@link ProviderRequest.toolSearch}. */
|
|
2839
|
+
interface ProviderToolSearch {
|
|
2840
|
+
/** The provider's search: natural-language queries (`"bm25"`) or regular expressions. */
|
|
2841
|
+
variant: "bm25" | "regex";
|
|
2842
|
+
/** Tool ids sent without deferred loading. */
|
|
2843
|
+
alwaysLoaded: string[];
|
|
2844
|
+
}
|
|
2845
|
+
/** What the provider's native tool search did in one call, as its response shows it. */
|
|
2846
|
+
interface ProviderToolSearchUsage {
|
|
2847
|
+
/** Searches the model ran. */
|
|
2848
|
+
searches: number;
|
|
2849
|
+
/** Tool names the searches loaded, in order, without repeats. */
|
|
2850
|
+
loaded: string[];
|
|
2851
|
+
/** Searches that came back as an error result instead of references. */
|
|
2852
|
+
errors: number;
|
|
2853
|
+
}
|
|
2854
|
+
/**
|
|
2855
|
+
* Breakpoint placement decided by the layer from the reuse it measured on your
|
|
2856
|
+
* traffic. See `cacheBreakpoints` in the layer configuration.
|
|
2857
|
+
*/
|
|
2858
|
+
interface CachePlacement {
|
|
2859
|
+
/**
|
|
2860
|
+
* Also mark the last block of the request, so that a continuation of this
|
|
2861
|
+
* exact prompt (the next turn of a conversation or an agent loop) reads all
|
|
2862
|
+
* of it from cache instead of writing it again.
|
|
2863
|
+
*/
|
|
2864
|
+
tail: boolean;
|
|
2865
|
+
/**
|
|
2866
|
+
* Cache lifetime for every breakpoint of this request. On Anthropic a
|
|
2867
|
+
* one-hour write is billed at 2x the input rate, a five-minute one at 1.25x.
|
|
2868
|
+
*/
|
|
2869
|
+
ttl: "5m" | "1h";
|
|
2471
2870
|
}
|
|
2472
2871
|
interface ProviderUsage {
|
|
2473
2872
|
inputTokens: number;
|
|
@@ -2486,6 +2885,13 @@ interface ProviderUsage {
|
|
|
2486
2885
|
* bill INCREASE as a saving.
|
|
2487
2886
|
*/
|
|
2488
2887
|
cacheWriteInputTokens?: number;
|
|
2888
|
+
/**
|
|
2889
|
+
* The part of `cacheWriteInputTokens` written with a ONE-HOUR lifetime
|
|
2890
|
+
* (Anthropic `cache_creation.ephemeral_1h_input_tokens`), billed at 2x the
|
|
2891
|
+
* input rate instead of 1.25x. Absent when the provider did not break the
|
|
2892
|
+
* writes down by lifetime.
|
|
2893
|
+
*/
|
|
2894
|
+
cacheWrite1hInputTokens?: number;
|
|
2489
2895
|
/**
|
|
2490
2896
|
* Output tokens the provider billed for hidden reasoning, already included in
|
|
2491
2897
|
* `outputTokens` (OpenAI `completion_tokens_details.reasoning_tokens`).
|
|
@@ -2575,6 +2981,11 @@ interface ProviderResponse {
|
|
|
2575
2981
|
* replayable.
|
|
2576
2982
|
*/
|
|
2577
2983
|
replayable?: boolean;
|
|
2984
|
+
/**
|
|
2985
|
+
* Present when the request carried {@link ProviderRequest.toolSearch} and the adapter can
|
|
2986
|
+
* read what the search did. The layer only reports it; it credits nothing for it.
|
|
2987
|
+
*/
|
|
2988
|
+
toolSearch?: ProviderToolSearchUsage;
|
|
2578
2989
|
raw?: unknown;
|
|
2579
2990
|
}
|
|
2580
2991
|
/** One event of a provider-level stream. */
|
|
@@ -2819,6 +3230,13 @@ interface SavingsLayerConfig {
|
|
|
2819
3230
|
* with your own measurements to unlock the full decision in both directions.
|
|
2820
3231
|
*/
|
|
2821
3232
|
compressionEconomics?: CompressionEconomics;
|
|
3233
|
+
/**
|
|
3234
|
+
* Compact tool outputs on every request (`true`, or settings), unless a
|
|
3235
|
+
* request sets `savings.toolOutputCompaction: false`. Off by default; a request
|
|
3236
|
+
* can also switch it on alone with `savings.toolOutputCompaction: true`.
|
|
3237
|
+
* See {@link ToolOutputCompactionSettings}.
|
|
3238
|
+
*/
|
|
3239
|
+
toolOutputCompaction?: boolean | ToolOutputCompactionSettings;
|
|
2822
3240
|
retriever?: Retriever;
|
|
2823
3241
|
reranker?: Reranker;
|
|
2824
3242
|
/**
|
|
@@ -2832,6 +3250,33 @@ interface SavingsLayerConfig {
|
|
|
2832
3250
|
* All off by default; a request's own `savings` value always wins.
|
|
2833
3251
|
*/
|
|
2834
3252
|
priceLevers?: PriceLeverSettings;
|
|
3253
|
+
/**
|
|
3254
|
+
* Where the layer writes the provider's prompt cache. Defaults to `"fixed"`.
|
|
3255
|
+
*
|
|
3256
|
+
* `"fixed"`: one breakpoint at the end of the system header and one at the
|
|
3257
|
+
* end of the history before the last user message, subject to the measured
|
|
3258
|
+
* hit-rate gate. Nothing else.
|
|
3259
|
+
*
|
|
3260
|
+
* `"auto"`: the layer watches, per model, tool set and system header, how
|
|
3261
|
+
* often your traffic re-sends each part of the prompt and how long after.
|
|
3262
|
+
* Watching costs nothing — it compares prefixes locally, it does not mark
|
|
3263
|
+
* anything to find out. Once it has enough samples it places breakpoints only
|
|
3264
|
+
* where the reuse beats the write premium: the tail of the prompt when turns
|
|
3265
|
+
* continue each other (agent loops, conversations), the history only when it
|
|
3266
|
+
* is re-sent, and a one-hour lifetime on Anthropic only when your gaps and the
|
|
3267
|
+
* size of this request make it pay. On OpenAI models that bill cache writes
|
|
3268
|
+
* (GPT-5.6 and later, on OpenAI's own API) it switches to explicit mode, with
|
|
3269
|
+
* no write on your question, when continuations are rare; `savings.standalone`
|
|
3270
|
+
* still wins when you set it. Until it has samples it behaves exactly like
|
|
3271
|
+
* `"fixed"`.
|
|
3272
|
+
*
|
|
3273
|
+
* What it did and why is in `report.traces` (`prefix-cache-placement`), and
|
|
3274
|
+
* the effect is read from the provider's own counters (`cachedInputTokens`,
|
|
3275
|
+
* `cacheWriteInputTokens`): if they do not confirm the reads the layer
|
|
3276
|
+
* predicted, it falls back to `"fixed"` for that traffic. The write premium it
|
|
3277
|
+
* causes, one-hour writes at 2x included, is charged to `cost.actual`.
|
|
3278
|
+
*/
|
|
3279
|
+
cacheBreakpoints?: "fixed" | "auto";
|
|
2835
3280
|
/**
|
|
2836
3281
|
* Signed BiVelio license token (from your paid subscription). This is the
|
|
2837
3282
|
* primary way to license the SDK: `createSavingsLayer` verifies it offline
|
|
@@ -3160,6 +3605,195 @@ interface SavingsCallOptions {
|
|
|
3160
3605
|
savings?: SavingsAdapterLevers;
|
|
3161
3606
|
}
|
|
3162
3607
|
|
|
3608
|
+
/** One request of a batch: your id for it, and the same request you would pass to `generate()`. */
|
|
3609
|
+
interface BatchRequest {
|
|
3610
|
+
/**
|
|
3611
|
+
* Your id for this request, unique within one `submit()`: 1 to 64 letters, digits,
|
|
3612
|
+
* `_` or `-`. Results come back in any order and are matched by this id.
|
|
3613
|
+
*/
|
|
3614
|
+
customId: string;
|
|
3615
|
+
/**
|
|
3616
|
+
* The request, as for `generate()`. It is sent as written, translated by the same
|
|
3617
|
+
* provider adapter: the layer's per-request savings (caching, compression, model
|
|
3618
|
+
* cascade, retrieval) do not run on batches, so `retrieval` and `structuredData`
|
|
3619
|
+
* are rejected and `savings` is ignored.
|
|
3620
|
+
*/
|
|
3621
|
+
request: SavingsRequest;
|
|
3622
|
+
}
|
|
3623
|
+
/** Options for `layer.batches.submit()`. */
|
|
3624
|
+
interface BatchSubmitOptions {
|
|
3625
|
+
/**
|
|
3626
|
+
* Anthropic only. Mark the leading system messages of each request as a prompt-cache
|
|
3627
|
+
* prefix, so requests that share them can read it at the cache rate. A cache write
|
|
3628
|
+
* costs more than plain input and, in a batch, hits are best-effort, so this pays
|
|
3629
|
+
* only when many requests share a long system prompt. Defaults to false. OpenAI
|
|
3630
|
+
* caches on its own and ignores it.
|
|
3631
|
+
*/
|
|
3632
|
+
cacheSharedPrefix?: boolean;
|
|
3633
|
+
/**
|
|
3634
|
+
* Upper bound on requests per provider batch, below the provider's own limit, to get
|
|
3635
|
+
* partial results sooner. The layer always splits at the provider limits (and, on
|
|
3636
|
+
* OpenAI, by model).
|
|
3637
|
+
*/
|
|
3638
|
+
maxRequestsPerBatch?: number;
|
|
3639
|
+
/** Cancels the HTTP calls of this submission. Batches already created stay created. */
|
|
3640
|
+
signal?: AbortSignal;
|
|
3641
|
+
}
|
|
3642
|
+
/**
|
|
3643
|
+
* A submitted batch job. Plain JSON: store it and pass it back to `status()`,
|
|
3644
|
+
* `results()` or `cancel()`, from this process or another one. It holds batch ids,
|
|
3645
|
+
* your request ids, model ids and output schemas; never prompts or answers.
|
|
3646
|
+
*/
|
|
3647
|
+
interface BatchJob {
|
|
3648
|
+
kind: "bvsala.batch";
|
|
3649
|
+
version: 1;
|
|
3650
|
+
/** Which batch API holds the job. */
|
|
3651
|
+
provider: "anthropic" | "openai";
|
|
3652
|
+
/** The provider base URL the job was submitted to, without credentials. */
|
|
3653
|
+
endpoint: string;
|
|
3654
|
+
/** One provider batch id per chunk, in submission order. */
|
|
3655
|
+
batchIds: string[];
|
|
3656
|
+
/** ISO 8601. */
|
|
3657
|
+
submittedAt: string;
|
|
3658
|
+
/**
|
|
3659
|
+
* Every submitted request: your id, its model, the index in `batchIds` of the provider
|
|
3660
|
+
* batch that carries it, and its output schema as an index into `schemas`.
|
|
3661
|
+
*/
|
|
3662
|
+
requests: {
|
|
3663
|
+
customId: string;
|
|
3664
|
+
model: string;
|
|
3665
|
+
batch: number;
|
|
3666
|
+
schema?: number;
|
|
3667
|
+
}[];
|
|
3668
|
+
/** The distinct output schemas of the job, stored once each. */
|
|
3669
|
+
schemas: JsonSchema[];
|
|
3670
|
+
}
|
|
3671
|
+
/** Request counts of a job, summed over its provider batches. */
|
|
3672
|
+
interface BatchCounts {
|
|
3673
|
+
processing: number;
|
|
3674
|
+
succeeded: number;
|
|
3675
|
+
errored: number;
|
|
3676
|
+
canceled: number;
|
|
3677
|
+
expired: number;
|
|
3678
|
+
}
|
|
3679
|
+
/** Where a job stands, as its provider reports it. */
|
|
3680
|
+
interface BatchJobStatus {
|
|
3681
|
+
/** `"ended"` once every provider batch of the job has finished, expired, failed or been canceled. */
|
|
3682
|
+
state: "in_progress" | "canceling" | "ended";
|
|
3683
|
+
requestCount: number;
|
|
3684
|
+
/**
|
|
3685
|
+
* As the provider reports them. OpenAI reports only completed and failed while a
|
|
3686
|
+
* batch runs; its canceled and expired requests are counted once it has ended.
|
|
3687
|
+
*/
|
|
3688
|
+
counts: BatchCounts;
|
|
3689
|
+
/** Each provider batch with the status its provider gave, verbatim. */
|
|
3690
|
+
batches: {
|
|
3691
|
+
id: string;
|
|
3692
|
+
status: string;
|
|
3693
|
+
}[];
|
|
3694
|
+
}
|
|
3695
|
+
/** One request's outcome. */
|
|
3696
|
+
interface BatchItemResult<T = unknown> {
|
|
3697
|
+
customId: string;
|
|
3698
|
+
/** The model you asked for. */
|
|
3699
|
+
model: string;
|
|
3700
|
+
/**
|
|
3701
|
+
* `"succeeded"` ran and is billed by the provider. `"errored"`, `"canceled"` and
|
|
3702
|
+
* `"expired"` returned no answer and no usage (Anthropic documents that it does not
|
|
3703
|
+
* bill them). `"missing"` means the provider returned no line for a request of an
|
|
3704
|
+
* ended batch, which should not happen: nothing is assumed about it.
|
|
3705
|
+
*/
|
|
3706
|
+
outcome: "succeeded" | "errored" | "canceled" | "expired" | "missing";
|
|
3707
|
+
text?: string;
|
|
3708
|
+
/** Present when the request had an output contract and the answer met it. */
|
|
3709
|
+
data?: T;
|
|
3710
|
+
/** Whether the answer met the output contract, when the request had one and no tool was called. */
|
|
3711
|
+
contract?: "met" | "missed";
|
|
3712
|
+
toolCalls?: ToolCallRequest[];
|
|
3713
|
+
finishReason?: string;
|
|
3714
|
+
/** The provider's own counter for this request. */
|
|
3715
|
+
usage?: ProviderUsage;
|
|
3716
|
+
/** The processing tier this result was billed at, as read from the provider. */
|
|
3717
|
+
servedTier?: string;
|
|
3718
|
+
/**
|
|
3719
|
+
* What the batch tier was worth on this request: its usage at the standard rate card
|
|
3720
|
+
* minus the same usage at the published batch rate card, component by component.
|
|
3721
|
+
* Present only when credited. It is reported, never metered or billed.
|
|
3722
|
+
*/
|
|
3723
|
+
tierSaving?: PriceLeverSaving;
|
|
3724
|
+
/** Why it was or was not credited, or what failed. One sentence, never empty. */
|
|
3725
|
+
reason: string;
|
|
3726
|
+
/** The provider's error, for `"errored"` results. */
|
|
3727
|
+
error?: {
|
|
3728
|
+
type: string;
|
|
3729
|
+
message: string;
|
|
3730
|
+
};
|
|
3731
|
+
}
|
|
3732
|
+
/** The whole job, added up. */
|
|
3733
|
+
interface BatchSummary {
|
|
3734
|
+
requestCount: number;
|
|
3735
|
+
succeeded: number;
|
|
3736
|
+
errored: number;
|
|
3737
|
+
canceled: number;
|
|
3738
|
+
expired: number;
|
|
3739
|
+
missing: number;
|
|
3740
|
+
/** Requests whose provider batch has not ended yet: not in `items`. */
|
|
3741
|
+
pending: number;
|
|
3742
|
+
/** Succeeded requests with a `tierSaving`. */
|
|
3743
|
+
credited: number;
|
|
3744
|
+
/** Sum of every `tierSaving.amount`. Never more than the sum of each request's published difference. */
|
|
3745
|
+
tierSaving: number;
|
|
3746
|
+
/** The credited requests' usage at the standard rate card. */
|
|
3747
|
+
standardCost: number;
|
|
3748
|
+
/** The same usage at the batch rate card. */
|
|
3749
|
+
appliedCost: number;
|
|
3750
|
+
/** `"measured"` only when every credited request is; `"none"` when nothing was credited. */
|
|
3751
|
+
basis: "measured" | "estimated" | "none";
|
|
3752
|
+
/** YYYY-MM-DD: the oldest check date of the rate cards used. */
|
|
3753
|
+
pricesCheckedOn?: string;
|
|
3754
|
+
/** Always `"none"`: a batch saving is reported next to the ledgers, never folded into them. */
|
|
3755
|
+
creditedLedger: "none";
|
|
3756
|
+
/** One sentence. Never empty. */
|
|
3757
|
+
reason: string;
|
|
3758
|
+
}
|
|
3759
|
+
/** What `layer.batches.results()` returns. */
|
|
3760
|
+
interface BatchResults<T = unknown> {
|
|
3761
|
+
/** False while any provider batch of the job is still running; results then cover only the ones that ended. */
|
|
3762
|
+
ended: boolean;
|
|
3763
|
+
items: BatchItemResult<T>[];
|
|
3764
|
+
summary: BatchSummary;
|
|
3765
|
+
}
|
|
3766
|
+
/**
|
|
3767
|
+
* The provider's asynchronous batch API: requests that can wait hours, billed at the
|
|
3768
|
+
* provider's batch rate card. Anthropic's Message Batches and OpenAI's Batch API
|
|
3769
|
+
* (Chat Completions) through the built-in providers; other providers throw.
|
|
3770
|
+
*/
|
|
3771
|
+
interface SavingsBatches {
|
|
3772
|
+
/**
|
|
3773
|
+
* Send requests to the provider's batch API. Returns as soon as the provider has
|
|
3774
|
+
* accepted them, with nothing priced: a batch is valued only when its results are
|
|
3775
|
+
* read. Throws before sending anything when a request cannot be batched. If a later
|
|
3776
|
+
* chunk fails after earlier ones were created, the thrown error carries the partial
|
|
3777
|
+
* job as `error.job`, so no created batch is lost.
|
|
3778
|
+
*/
|
|
3779
|
+
submit(requests: BatchRequest[], options?: BatchSubmitOptions): Promise<BatchJob>;
|
|
3780
|
+
/** Where the job stands. */
|
|
3781
|
+
status(job: BatchJob, options?: {
|
|
3782
|
+
signal?: AbortSignal;
|
|
3783
|
+
}): Promise<BatchJobStatus>;
|
|
3784
|
+
/**
|
|
3785
|
+
* The results of every provider batch of the job that has ended, one per request,
|
|
3786
|
+
* each valued at the two published rate cards, and the total.
|
|
3787
|
+
*/
|
|
3788
|
+
results<T = unknown>(job: BatchJob, options?: {
|
|
3789
|
+
signal?: AbortSignal;
|
|
3790
|
+
}): Promise<BatchResults<T>>;
|
|
3791
|
+
/** Ask the provider to stop the job. Requests it already processed are still billed. */
|
|
3792
|
+
cancel(job: BatchJob, options?: {
|
|
3793
|
+
signal?: AbortSignal;
|
|
3794
|
+
}): Promise<BatchJobStatus>;
|
|
3795
|
+
}
|
|
3796
|
+
|
|
3163
3797
|
/**
|
|
3164
3798
|
* Tokenizador EXACTO — la regla del proveedor, no una aproximación.
|
|
3165
3799
|
*
|
|
@@ -3660,8 +4294,10 @@ declare class OpenAICompatibleProvider implements Provider {
|
|
|
3660
4294
|
*/
|
|
3661
4295
|
generateStream(req: ProviderRequest, options?: ProviderStreamOptions): AsyncGenerator<ProviderStreamEvent, void, undefined>;
|
|
3662
4296
|
private enviar;
|
|
4297
|
+
private construirCuerpo;
|
|
3663
4298
|
/** Translate a 2xx endpoint response into the provider-neutral shape. */
|
|
3664
4299
|
private leer;
|
|
4300
|
+
private leerJson;
|
|
3665
4301
|
}
|
|
3666
4302
|
|
|
3667
4303
|
/**
|
|
@@ -3713,10 +4349,13 @@ interface AnthropicOptions {
|
|
|
3713
4349
|
/**
|
|
3714
4350
|
* How many `cache_control` breakpoints the adapter may spend.
|
|
3715
4351
|
*
|
|
3716
|
-
* The API caps them at 4 per request. The
|
|
3717
|
-
* (end of system, end of the stable message prefix)
|
|
3718
|
-
*
|
|
3719
|
-
*
|
|
4352
|
+
* The API caps them at 4 per request. The fixed placement never needs more
|
|
4353
|
+
* than 2 (end of system, end of the stable message prefix); the layer's
|
|
4354
|
+
* placer (`cacheBreakpoints: "auto"`) may add a third on the last block. The
|
|
4355
|
+
* cap is exposed so a gateway with a stricter limit can lower it; when it is
|
|
4356
|
+
* short, the system block goes first and the last block second. Raising it
|
|
4357
|
+
* above 4 is pointless: the extra breakpoints are rejected by the API, not
|
|
4358
|
+
* ignored.
|
|
3720
4359
|
*/
|
|
3721
4360
|
maxCacheBreakpoints?: number;
|
|
3722
4361
|
/**
|
|
@@ -3733,6 +4372,10 @@ interface AnthropicOptions {
|
|
|
3733
4372
|
* the whole history at 0.1x — and loses money on one-shot traffic where
|
|
3734
4373
|
* nothing ever reads it back. It is also rejected by legacy Bedrock
|
|
3735
4374
|
* deployments. Turn it on when your traffic is multi-turn.
|
|
4375
|
+
*
|
|
4376
|
+
* Ignored on requests whose breakpoints were placed by the layer's placer
|
|
4377
|
+
* (`cacheBreakpoints: "auto"`): the placer already decides whether the tail is
|
|
4378
|
+
* marked, from the reuse it measured on your traffic.
|
|
3736
4379
|
*/
|
|
3737
4380
|
automaticCache?: boolean;
|
|
3738
4381
|
/**
|
|
@@ -3770,6 +4413,7 @@ declare class AnthropicProvider implements Provider {
|
|
|
3770
4413
|
private construirCuerpo;
|
|
3771
4414
|
private marcarCache;
|
|
3772
4415
|
private leer;
|
|
4416
|
+
private leerMensaje;
|
|
3773
4417
|
}
|
|
3774
4418
|
|
|
3775
4419
|
/**
|
|
@@ -4210,6 +4854,15 @@ interface SavingsLayer {
|
|
|
4210
4854
|
* Await `result` before calling close(), or its usage record may be lost.
|
|
4211
4855
|
*/
|
|
4212
4856
|
generateStream<T = unknown>(request: SavingsRequest, options?: SavingsStreamOptions): SavingsStream<T>;
|
|
4857
|
+
/**
|
|
4858
|
+
* The provider's asynchronous batch API, for requests that can wait hours: submit
|
|
4859
|
+
* them, check on them, and read their results valued at the provider's batch rate
|
|
4860
|
+
* card. Requests are sent as written (the layer's per-request savings do not run on
|
|
4861
|
+
* batches), nothing is metered, and the batch saving is reported, never billed.
|
|
4862
|
+
* Works with the built-in Anthropic and OpenAI providers; needs the same license as
|
|
4863
|
+
* generate().
|
|
4864
|
+
*/
|
|
4865
|
+
readonly batches: SavingsBatches;
|
|
4213
4866
|
/**
|
|
4214
4867
|
* Stop the background revocation poller (when the online call-home was enabled
|
|
4215
4868
|
* via `licenseServerUrl`) and abort any in-flight request, and settle every
|
|
@@ -4253,6 +4906,20 @@ declare class StreamAbortedError extends Error {
|
|
|
4253
4906
|
readonly requestSent: boolean;
|
|
4254
4907
|
constructor(requestSent: boolean);
|
|
4255
4908
|
}
|
|
4909
|
+
/**
|
|
4910
|
+
* Thrown by `layer.batches.submit()` when a chunk fails after earlier chunks were
|
|
4911
|
+
* already created at the provider. Those batches run and are billed: keep `job` and
|
|
4912
|
+
* read it with `results()`, or pass it to `cancel()`.
|
|
4913
|
+
*/
|
|
4914
|
+
declare class BatchSubmitError extends Error {
|
|
4915
|
+
/** The batches that were created, as a job you can read or cancel. `batchIds` may be empty. */
|
|
4916
|
+
readonly job: BatchJob;
|
|
4917
|
+
/** Your ids of the requests that were not sent. */
|
|
4918
|
+
readonly notSubmitted: string[];
|
|
4919
|
+
constructor(message: string, job: BatchJob, notSubmitted: string[], options?: {
|
|
4920
|
+
cause?: unknown;
|
|
4921
|
+
});
|
|
4922
|
+
}
|
|
4256
4923
|
|
|
4257
4924
|
/**
|
|
4258
4925
|
* The parts of a SavingsReport the exporters read. A full SavingsReport
|
|
@@ -4623,4 +5290,4 @@ declare function toCsv(rows: readonly Readonly<Record<string, CsvValue>>[], opti
|
|
|
4623
5290
|
columns?: readonly string[];
|
|
4624
5291
|
}): string;
|
|
4625
5292
|
|
|
4626
|
-
export { type AnswerSource, type AnthropicOptions, AnthropicProvider, BV_SALA_VERSION, type BivelioHandoff, CATALOGO, COMPACT_ROWS_INSTRUCTION, type CacheOutcome, type CacheTier, type CacheWriteReport, 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, type CsvValue, DEFAULT_COST_MODEL, DEFAULT_MAX_STALENESS_SECONDS, type DeferredExecutionReport, type DeterministicResolver, EMBEDDED_PUBLIC_KEY, type EmbeddingFn, type EvidenceDoc, type ExactCache, ExactTokenizer, type ExecutionClass, ExecutionRouter, type FocusExportOptions, type FocusRow, type FormatChoice, FormatSelector, type FormatSelectorOptions, type HandoffFact, HeuristicEstimator, InMemoryExactCache, InMemorySemanticCache, InMemoryToolSetFreezer, type JsonSchema, type LangfuseGenerationUpdate, LicenseError, type LicenseGate, type LicenseKeyShape, 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 PriceLeverSaving, type PriceLeverSettings, type ProtectedSpan, type Provider, type ProviderRequest, type ProviderResponse, type ProviderStreamEvent, type ProviderStreamOptions, type ProviderUsage, QUALITY_STATUSES, type QualityCacheMatch, type QualityCascadeCheck, type QualityLedger, type QualityRepairCheck, type QualitySchemaCheck, type QualityStatus, type QualityTruncationCheck, REFERENCE_MAX_AGE_MS, REFERENCE_MESSAGE_ALLOWANCE, REFERENCE_OUTPUT_SHARE, type ReferenceCredit, type ReferenceRejection, 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 SavingsAdapterLevers, type SavingsAdapterOptions, type SavingsAttributeOptions, type SavingsCallOptions, type SavingsLayer, type SavingsLayerConfig, SavingsLedger, type SavingsRecord, type SavingsReport, type SavingsReportForExport, type SavingsRequest, type SavingsResult, type SavingsSeriesOptions, type SavingsSeriesRow, type SavingsSpanAttributes, type SavingsSpanOptions, type SavingsStream, type SavingsStreamEvent, type SavingsStreamOptions, type SavingsToggles, type SavingsTracingOptions, SchemaRegistry, type SemanticCacheOptions, type SemanticHit, type SemanticRecord, type SemanticVerifier, type SerializationFormat, type Serializer, Singleflight, type SpanAttributeValue, type SpanLike, type SpanStartOptionsLike, StreamAbortedError, type StreamingReport, type TokenEstimator, TokenizerRegistry, type ToolCallRequest, type ToolDescriptor, type ToolRisk, type ToolSelection, ToolSelector, type ToolSelectorOptions, type ToolSetFreezer, TraceCollector, type TraceEvent, type TracerLike, type TracerProviderLike, UMBRAL_LOCAL, UsageEmitter, type UsageEmitterOptions, type ValidationError, type ValidationResult, type VerificationCheck, type VerificationExclusion, type VerificationOutcome, type VerificationReport, type VerificationSettings, type VerificationSide, type VerificationStratum, adaptiveK, arithmeticResolver, buildExactKey, buildInflightKey, canonicalize, compactRowsSerializer, compresionFiel, computeNextDelay, cosine, createCompactRowsSerializer, createDefaultResolvers, createHandoff, createMockProvider, createSavingsLayer, csvSerializer, decodeCompactRows, dedupe, defaultTokenizerRegistry, deriveSeatId, deriveStatus, detectCi, embebedorLocal, emptyState, encodeCompactRows, evalArithmetic, evaluatePolicy, executeRetrievalPlan, gateFromKey, heuristicEstimator, instrumentSavingsLayer, isKeyset, isStrictCompatible, jsonCompactSerializer, keyTokensMatch, licenseKeyShape, liveGateFromKey, mergeDelta, modelFamilyOf, multisetEqual, negationCount, noopCompressor, normalizeLicenseKey, normalizeText, numericTokens, precioDeLista, projectContext, providerNativeBackend, quitarPrefijoDeProveedor, randomId, recordSavingsOnSpan, registerExactTokenizer, registrarTokenizadorExacto, renderState, resolveConstraintBackend, resolveDependencies, resolveLicense, savingsSpanAttributes, sha256, shouldCompress, stableStringify, toCsv, toFocusRows, toLangfuseGeneration, toSavingsSeries, uniformColumns, validateAgainstSchema, vectorLocal, verifyCompactSignature, verifyLicenseToken, verifyRevocationList, withProtectedSpans, words };
|
|
5293
|
+
export { type AnswerJudge, type AnswerSource, type AnthropicOptions, AnthropicProvider, BV_SALA_VERSION, type BatchCounts, type BatchItemResult, type BatchJob, type BatchJobStatus, type BatchRequest, type BatchResults, BatchSubmitError, type BatchSubmitOptions, type BatchSummary, type BivelioHandoff, CATALOGO, COMPACTION_TRANSFORMS, COMPACT_ROWS_INSTRUCTION, type CacheOutcome, type CachePlacement, type CacheTier, type CacheWriteReport, type CachedAnswer, type CalibrationObservation, type CanonicalRequest, type ChatMessage, type CompactRowsDecodeOptions, type CompactRowsOptions, type CompactVerification, type CompactionTransform, type CompressionEconomics, type CompressionPolicyInput, type CompressionRequest, type CompressionResult, type Compressor, type ConstraintBackend, type ConstraintBackendId, type ConstraintPlan, type ConversationState, type CostBasis, type CostModel, type CsvValue, DEFAULT_COST_MODEL, DEFAULT_MAX_STALENESS_SECONDS, DEFAULT_MIN_SAVED_CHARS, type DeferredExecutionReport, type DeterministicResolver, EMBEDDED_PUBLIC_KEY, type EmbeddingFn, type EvidenceDoc, type ExactCache, ExactTokenizer, type ExecutionClass, ExecutionRouter, type FocusExportOptions, type FocusRow, type FormatChoice, FormatSelector, type FormatSelectorOptions, type HandoffFact, HeuristicEstimator, InMemoryExactCache, InMemorySemanticCache, InMemoryToolSetFreezer, type JsonSchema, type LangfuseGenerationUpdate, LicenseError, type LicenseGate, type LicenseKeyShape, 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 PriceLeverSaving, type PriceLeverSettings, type ProtectedSpan, type Provider, type ProviderRequest, type ProviderResponse, type ProviderStreamEvent, type ProviderStreamOptions, type ProviderToolSearch, type ProviderToolSearchUsage, type ProviderUsage, QUALITY_STATUSES, type QualityCacheMatch, type QualityCascadeCheck, type QualityLedger, type QualityRepairCheck, type QualitySchemaCheck, type QualityStatus, type QualityTruncationCheck, REFERENCE_MAX_AGE_MS, REFERENCE_MESSAGE_ALLOWANCE, REFERENCE_OUTPUT_SHARE, type ReferenceCredit, type ReferenceRejection, 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 SavingsAdapterLevers, type SavingsAdapterOptions, type SavingsAttributeOptions, type SavingsBatches, type SavingsCallOptions, type SavingsLayer, type SavingsLayerConfig, SavingsLedger, type SavingsRecord, type SavingsReport, type SavingsReportForExport, type SavingsRequest, type SavingsResult, type SavingsSeriesOptions, type SavingsSeriesRow, type SavingsSpanAttributes, type SavingsSpanOptions, type SavingsStream, type SavingsStreamEvent, type SavingsStreamOptions, type SavingsToggles, type SavingsTracingOptions, SchemaRegistry, type SemanticCacheOptions, type SemanticCalibrationBound, type SemanticCalibrationOptions, type SemanticCalibrationStatus, type SemanticHit, type SemanticLookup, type SemanticProbe, type SemanticRecord, type SemanticVerifier, type SerializationFormat, type Serializer, Singleflight, type SpanAttributeValue, type SpanLike, type SpanStartOptionsLike, StreamAbortedError, type StreamingReport, type TokenEstimator, TokenizerRegistry, type ToolCallRequest, type ToolDescriptor, type ToolOutputCompaction, type ToolOutputCompactionSettings, type ToolRisk, type ToolSearchMode, type ToolSearchOptions, type ToolSelection, ToolSelector, type ToolSelectorOptions, type ToolSetFreezer, TraceCollector, type TraceEvent, type TracerLike, type TracerProviderLike, UMBRAL_LOCAL, UsageEmitter, type UsageEmitterOptions, type ValidationError, type ValidationResult, type VerificationCheck, type VerificationExclusion, type VerificationOutcome, type VerificationReport, type VerificationSettings, type VerificationSide, type VerificationStratum, adaptiveK, arithmeticResolver, buildExactKey, buildInflightKey, calibrateSemanticFloor, canonicalize, compactRowsSerializer, compactToolOutput, compresionFiel, computeNextDelay, cosine, createCompactRowsSerializer, createDefaultResolvers, createHandoff, createMockProvider, createSavingsLayer, csvSerializer, decodeCompactRows, dedupe, defaultTokenizerRegistry, deriveSeatId, deriveStatus, detectCi, embebedorLocal, emptyState, encodeCompactRows, evalArithmetic, evaluatePolicy, executeRetrievalPlan, gateFromKey, heuristicEstimator, instrumentSavingsLayer, isKeyset, isStrictCompatible, jsonCompactSerializer, keyTokensMatch, licenseKeyShape, liveGateFromKey, mergeDelta, modelFamilyOf, multisetEqual, negationCount, noopCompressor, normalizeLicenseKey, normalizeText, numericTokens, precioDeLista, projectContext, providerNativeBackend, quitarPrefijoDeProveedor, randomId, recordSavingsOnSpan, registerExactTokenizer, registrarTokenizadorExacto, renderState, resolveConstraintBackend, resolveDependencies, resolveLicense, sameAnswer, savingsSpanAttributes, sha256, shouldCompress, stableStringify, toCsv, toFocusRows, toLangfuseGeneration, toSavingsSeries, uniformColumns, validateAgainstSchema, vectorLocal, verifyCompactSignature, verifyLicenseToken, verifyRevocationList, withProtectedSpans, words };
|