@bivelio/savings-layer 0.4.26 → 0.4.29
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 +118 -13
- package/dist/adapters/ai-sdk.js +73 -73
- package/dist/adapters/anthropic-sdk.js +67 -66
- package/dist/adapters/langchain.js +60 -58
- package/dist/adapters/mastra.js +65 -65
- package/dist/gateway/bin.js +604 -593
- package/dist/index.d.ts +312 -10
- package/dist/index.js +1308 -1200
- package/package.json +4 -1
package/dist/index.d.ts
CHANGED
|
@@ -311,7 +311,7 @@ declare function precioDeLista(model: string, at?: Date | number): CostModel | u
|
|
|
311
311
|
* on the customer's machine. `test/version-declarada.test.ts` ties this
|
|
312
312
|
* constant to package.json so the two can never drift.
|
|
313
313
|
*/
|
|
314
|
-
declare const BV_SALA_VERSION = "0.4.
|
|
314
|
+
declare const BV_SALA_VERSION = "0.4.29";
|
|
315
315
|
|
|
316
316
|
/**
|
|
317
317
|
* Environment-agnostic UUID generation.
|
|
@@ -457,19 +457,38 @@ interface ChatMessage {
|
|
|
457
457
|
* The provider tool loop needs it: OpenAI's Chat Completions rejects a
|
|
458
458
|
* `role: "tool"` message that does not carry `tool_call_id` and does not follow
|
|
459
459
|
* an assistant turn with `tool_calls` (a 400). Pass the `id` from the
|
|
460
|
-
* {@link ToolCallRequest} the model asked for.
|
|
461
|
-
*
|
|
460
|
+
* {@link ToolCallRequest} the model asked for.
|
|
461
|
+
*
|
|
462
|
+
* Anthropic's Messages API needs it too: with it, the Anthropic adapter sends
|
|
463
|
+
* the result as a `tool_result` block paired with the call's `tool_use` block.
|
|
464
|
+
* Without it (or without the ids in the assistant turn's `toolCalls`), the
|
|
465
|
+
* exchange is sent as plain text and the adapter warns once.
|
|
462
466
|
*/
|
|
463
467
|
toolCallId?: string;
|
|
468
|
+
/**
|
|
469
|
+
* For `role: "tool"`: the tool failed, and `content` says how.
|
|
470
|
+
*
|
|
471
|
+
* The Anthropic adapter sends it as `is_error: true` on the `tool_result`, so
|
|
472
|
+
* the model reads the content as an error rather than as data. Providers
|
|
473
|
+
* without such a flag (OpenAI's Chat Completions) send the content unchanged,
|
|
474
|
+
* so write the error into `content` either way.
|
|
475
|
+
*/
|
|
476
|
+
isError?: boolean;
|
|
464
477
|
/**
|
|
465
478
|
* For `role: "assistant"`: the tool calls the model requested on that turn.
|
|
466
479
|
*
|
|
467
480
|
* Send it back with the assistant turn when you continue a tool conversation,
|
|
468
481
|
* so the following `role: "tool"` messages are valid. These are the same
|
|
469
|
-
* {@link ToolCallRequest}s that came back in {@link SavingsResult.toolCalls}
|
|
482
|
+
* {@link ToolCallRequest}s that came back in {@link SavingsResult.toolCalls},
|
|
483
|
+
* ids included.
|
|
470
484
|
*/
|
|
471
485
|
toolCalls?: ToolCallRequest[];
|
|
472
|
-
/**
|
|
486
|
+
/**
|
|
487
|
+
* Opaque provider metadata; never used for the exact-cache key. The one
|
|
488
|
+
* exception is `tool_call_id` on a `role: "tool"` message: the OpenAI
|
|
489
|
+
* adapter still sends it as the call id when `toolCallId` is absent,
|
|
490
|
+
* so the key reads it as that same field.
|
|
491
|
+
*/
|
|
473
492
|
metadata?: Record<string, unknown>;
|
|
474
493
|
}
|
|
475
494
|
/** How a request is classified by the execution router. */
|
|
@@ -1107,6 +1126,14 @@ interface SavingsResult<T = unknown> {
|
|
|
1107
1126
|
* (caché/resolver), que solo sirven respuestas finales completas.
|
|
1108
1127
|
*/
|
|
1109
1128
|
finishReason?: string;
|
|
1129
|
+
/**
|
|
1130
|
+
* The refusal message the model returned instead of an answer (OpenAI
|
|
1131
|
+
* Structured Outputs: `message.refusal`, with `finish_reason: "stop"` and no
|
|
1132
|
+
* content). When present, the request was refused: `text` is empty and no
|
|
1133
|
+
* output contract was met. It is measured like any call, and it is never
|
|
1134
|
+
* repaired, cached or replayed.
|
|
1135
|
+
*/
|
|
1136
|
+
refusal?: string;
|
|
1110
1137
|
report: SavingsReport;
|
|
1111
1138
|
}
|
|
1112
1139
|
/** One event of a streamed answer. */
|
|
@@ -1281,8 +1308,12 @@ interface QualityRepairCheck {
|
|
|
1281
1308
|
* sending the request without the layer (opt-in, `skipRepairAboveBaseline`).
|
|
1282
1309
|
* - `decode_time_constraint`: generation was already constrained, so a retry
|
|
1283
1310
|
* would not change the outcome.
|
|
1311
|
+
* - `provider_refusal`: the provider refused the request (`finishReason:
|
|
1312
|
+
* "content_filter"`, Anthropic's `stop_reason: "refusal"`, or OpenAI's
|
|
1313
|
+
* `message.refusal`); a repair on the same model would be refused, and may
|
|
1314
|
+
* be billed, again.
|
|
1284
1315
|
*/
|
|
1285
|
-
skipReason?: "output_truncated" | "schema_defect" | "would_cost_more_than_no_layer" | "decode_time_constraint";
|
|
1316
|
+
skipReason?: "output_truncated" | "schema_defect" | "would_cost_more_than_no_layer" | "decode_time_constraint" | "provider_refusal";
|
|
1286
1317
|
}
|
|
1287
1318
|
/** Whether the provider stopped because it reached the output limit. */
|
|
1288
1319
|
interface QualityTruncationCheck {
|
|
@@ -1832,6 +1863,25 @@ interface CanonicalRequest {
|
|
|
1832
1863
|
normalizedText: string;
|
|
1833
1864
|
systemPromptHash: string;
|
|
1834
1865
|
toolsetHash: string;
|
|
1866
|
+
/**
|
|
1867
|
+
* Hash of the tool-loop fields of the conversation, the part of each turn
|
|
1868
|
+
* that `normalizedText` does not carry: the calls on an assistant turn (name,
|
|
1869
|
+
* arguments and id) and, on a `role: "tool"` message, the call it answers,
|
|
1870
|
+
* its error flag and its name. Part of the exact key, the in-flight key and
|
|
1871
|
+
* the semantic filter, so two conversations that differ only there never
|
|
1872
|
+
* share an answer.
|
|
1873
|
+
*
|
|
1874
|
+
* Call ids count by what they pair, not by their value: results matched to
|
|
1875
|
+
* other calls give another hash, while the same conversation with its ids
|
|
1876
|
+
* consistently renamed (a new run of the same agent loop gets fresh ids from
|
|
1877
|
+
* the provider) keeps it.
|
|
1878
|
+
*
|
|
1879
|
+
* Absent when the request carries none of them: the keys are then built from
|
|
1880
|
+
* exactly the same material as before this field existed. A field that is
|
|
1881
|
+
* present but empty or false (`toolCalls: []`, `isError: false`, `name: ""`)
|
|
1882
|
+
* reaches the provider exactly as an absent one, and counts as absent.
|
|
1883
|
+
*/
|
|
1884
|
+
toolTurnsHash?: string;
|
|
1835
1885
|
/** Hash of the structured payload; part of the cache key so different data never collides. */
|
|
1836
1886
|
structuredDataHash: string;
|
|
1837
1887
|
schemaVersion: string;
|
|
@@ -1878,6 +1928,15 @@ declare function stableStringify(value: unknown): string;
|
|
|
1878
1928
|
declare function modelFamilyOf(model: string): string;
|
|
1879
1929
|
declare function canonicalize(request: SavingsRequest): CanonicalRequest;
|
|
1880
1930
|
|
|
1931
|
+
/**
|
|
1932
|
+
* Thrown by `importCalibration` / `exportCalibration` when a calibration state
|
|
1933
|
+
* cannot be used as-is: another embedder, verifier, judge or configuration, a
|
|
1934
|
+
* newer format, or numbers that do not add up.
|
|
1935
|
+
*/
|
|
1936
|
+
declare class CalibrationStateError extends Error {
|
|
1937
|
+
constructor(message: string);
|
|
1938
|
+
}
|
|
1939
|
+
|
|
1881
1940
|
/**
|
|
1882
1941
|
* Decides whether a stored answer would have been right for a new request,
|
|
1883
1942
|
* given the answer your provider just produced for it. `true` = the stored
|
|
@@ -1929,6 +1988,70 @@ interface SemanticCalibrationOptions {
|
|
|
1929
1988
|
perRecordFloors?: boolean;
|
|
1930
1989
|
/** Source of randomness for audits, in [0, 1). Default `Math.random`. */
|
|
1931
1990
|
random?: () => number;
|
|
1991
|
+
/**
|
|
1992
|
+
* Names your `judge` (e.g. `"support-answers-v2"`), so that a saved
|
|
1993
|
+
* calibration is only ever restored under the same definition of a wrong
|
|
1994
|
+
* reuse. Required to export a calibration when you pass your own judge.
|
|
1995
|
+
*/
|
|
1996
|
+
judgeId?: string;
|
|
1997
|
+
}
|
|
1998
|
+
|
|
1999
|
+
/**
|
|
2000
|
+
* A calibration saved with `exportCalibration`, to be restored with
|
|
2001
|
+
* `importCalibration` after a restart. Plain JSON: store it as is.
|
|
2002
|
+
*
|
|
2003
|
+
* It carries the whole experiment, not a summary: both halves of the labels
|
|
2004
|
+
* (the half that proposes floors and the half kept apart to test them), how
|
|
2005
|
+
* many tests have already spent the confidence budget, and the floor in force.
|
|
2006
|
+
* Restoring it continues the same calibration, so the bound keeps holding
|
|
2007
|
+
* across restarts; it never starts the budget over.
|
|
2008
|
+
*
|
|
2009
|
+
* It describes itself: who scored the requests (`embedder`, `verifier`), who
|
|
2010
|
+
* judged the answers (`judge`) and the numbers of the test (`config`). A cache
|
|
2011
|
+
* with any of them different refuses it.
|
|
2012
|
+
*/
|
|
2013
|
+
interface SemanticCalibrationState {
|
|
2014
|
+
format: "bvsala.semantic-calibration";
|
|
2015
|
+
/** Format and method version. A newer SDK may read an older state; never the other way round. */
|
|
2016
|
+
version: 1;
|
|
2017
|
+
/** `built_in:<version>` for the embedder shipped with the SDK, `custom:<embedderId>` for yours. */
|
|
2018
|
+
embedder: string;
|
|
2019
|
+
/** `null` without a verifier, `custom:<verifierId>` with yours. */
|
|
2020
|
+
verifier: string | null;
|
|
2021
|
+
/** `built_in:<version>` for {@link sameAnswer}, `custom:<judgeId>` for yours. */
|
|
2022
|
+
judge: string;
|
|
2023
|
+
config: {
|
|
2024
|
+
maxErrorRate: number;
|
|
2025
|
+
confidence: number;
|
|
2026
|
+
/** Only candidates at or above it are labeled, so it is part of what the labels mean. */
|
|
2027
|
+
similarityThreshold: number;
|
|
2028
|
+
/** Candidate floors are tested on a fixed grid of `grid + 1` values in [0, 1]. */
|
|
2029
|
+
grid: number;
|
|
2030
|
+
};
|
|
2031
|
+
/** One calibration per traffic segment; a segment with no state yet is absent. */
|
|
2032
|
+
segments: {
|
|
2033
|
+
single_shot?: SemanticCalibrationSegmentState;
|
|
2034
|
+
agentic?: SemanticCalibrationSegmentState;
|
|
2035
|
+
};
|
|
2036
|
+
}
|
|
2037
|
+
/** The calibration of one traffic segment. Grid indices are scores times `grid`. */
|
|
2038
|
+
interface SemanticCalibrationSegmentState {
|
|
2039
|
+
/** Labels recorded. They alternate by arrival between the two halves below. */
|
|
2040
|
+
labeled: number;
|
|
2041
|
+
/** Tests already run. It follows from `labeled`, and a state where it does not is refused. */
|
|
2042
|
+
looks: number;
|
|
2043
|
+
/** The floor the next test starts from (a grid index), or null. */
|
|
2044
|
+
previousCandidate: number | null;
|
|
2045
|
+
/** The floor in force and the held-out labels that certified it, or null. */
|
|
2046
|
+
certified: {
|
|
2047
|
+
floorIndex: number;
|
|
2048
|
+
heldOut: number;
|
|
2049
|
+
wrong: number;
|
|
2050
|
+
} | null;
|
|
2051
|
+
/** The half that proposes floors: `[gridIndex, labels, wrong]` where there are labels. */
|
|
2052
|
+
selection: [number, number, number][];
|
|
2053
|
+
/** The half kept apart to test them, in the same shape. */
|
|
2054
|
+
heldOut: [number, number, number][];
|
|
1932
2055
|
}
|
|
1933
2056
|
/** One labeled reuse decision: the score the cache would have served on, and whether the stored answer was right. */
|
|
1934
2057
|
interface CalibrationObservation {
|
|
@@ -2032,6 +2155,13 @@ interface SemanticRecord {
|
|
|
2032
2155
|
safetyPolicyVersion: string;
|
|
2033
2156
|
/** Hash of the declared tool catalog (ids, risk and parameters). */
|
|
2034
2157
|
toolsetHash: string;
|
|
2158
|
+
/**
|
|
2159
|
+
* Hash of the tool-loop fields of the conversation (tool calls, the call each
|
|
2160
|
+
* tool result answers, its error flag and name); absent when it had none.
|
|
2161
|
+
* Compared for equality like the other identity fields: similarity is scored
|
|
2162
|
+
* on text only, and never decides between two tool loops.
|
|
2163
|
+
*/
|
|
2164
|
+
toolTurnsHash?: string;
|
|
2035
2165
|
/** Sampling temperature of the request, or null when it set none. */
|
|
2036
2166
|
temperature: number | null;
|
|
2037
2167
|
/** Sampling seed of the request, or null when it set none. */
|
|
@@ -2100,7 +2230,16 @@ interface SemanticCacheOptions {
|
|
|
2100
2230
|
* cache miss — never a wrong answer.
|
|
2101
2231
|
*/
|
|
2102
2232
|
embed?: EmbeddingFn;
|
|
2233
|
+
/**
|
|
2234
|
+
* Names your `embed` function: model and version, e.g.
|
|
2235
|
+
* `"text-embedding-3-small@1536"`. A saved calibration carries it, and one
|
|
2236
|
+
* recorded under another embedder is refused on import. Required to export a
|
|
2237
|
+
* calibration when you pass your own `embed`.
|
|
2238
|
+
*/
|
|
2239
|
+
embedderId?: string;
|
|
2103
2240
|
verify?: SemanticVerifier;
|
|
2241
|
+
/** Names your `verify` function, like {@link embedderId}. Required to export a calibration when you pass one. */
|
|
2242
|
+
verifierId?: string;
|
|
2104
2243
|
/** Cosine similarity floor for a candidate to be considered at all. */
|
|
2105
2244
|
similarityThreshold?: number;
|
|
2106
2245
|
/** Verifier score floor for acceptance. */
|
|
@@ -2140,6 +2279,7 @@ declare class InMemorySemanticCache {
|
|
|
2140
2279
|
private readonly embebedorPropio;
|
|
2141
2280
|
private readonly calibracion;
|
|
2142
2281
|
private readonly estados;
|
|
2282
|
+
private readonly nombres;
|
|
2143
2283
|
private readonly pendientes;
|
|
2144
2284
|
private readonly aceptacionExplicita;
|
|
2145
2285
|
constructor(opts?: SemanticCacheOptions);
|
|
@@ -2184,6 +2324,38 @@ declare class InMemorySemanticCache {
|
|
|
2184
2324
|
settled(): Promise<void>;
|
|
2185
2325
|
/** Where the calibration of a traffic segment stands, or null without calibration. */
|
|
2186
2326
|
calibrationStatus(segment?: SemanticProbe["segment"]): SemanticCalibrationStatus | null;
|
|
2327
|
+
/**
|
|
2328
|
+
* The calibration's full state, to restore it with {@link importCalibration}
|
|
2329
|
+
* in a later process: after a deploy, or in the next serverless invocation.
|
|
2330
|
+
* Plain JSON. Call it after `await cache.settled()` so labels still being
|
|
2331
|
+
* judged are included.
|
|
2332
|
+
*
|
|
2333
|
+
* The bound holds along one line of history: restore the latest state you
|
|
2334
|
+
* saved and keep saving from where it went. Processes that continue the same
|
|
2335
|
+
* state at the same time each spend its remaining confidence again. Each one
|
|
2336
|
+
* keeps its own bound, but the chance that some process certifies a wrong
|
|
2337
|
+
* floor grows with how many do it, and whichever saves last overwrites the
|
|
2338
|
+
* labels of the others.
|
|
2339
|
+
*
|
|
2340
|
+
* Throws {@link CalibrationStateError} without calibration, and when you
|
|
2341
|
+
* passed your own `embed`, `verify` or `judge` without naming it
|
|
2342
|
+
* (`embedderId`, `verifierId`, `calibration.judgeId`).
|
|
2343
|
+
*/
|
|
2344
|
+
exportCalibration(): SemanticCalibrationState;
|
|
2345
|
+
/**
|
|
2346
|
+
* Restore a state saved with {@link exportCalibration} (the object, or its
|
|
2347
|
+
* JSON text), right after constructing the cache. The calibration continues
|
|
2348
|
+
* exactly where it was: the same labels in the same two halves, the same
|
|
2349
|
+
* tests already run and the same floor in force.
|
|
2350
|
+
*
|
|
2351
|
+
* All or nothing. Throws {@link CalibrationStateError}, and changes nothing,
|
|
2352
|
+
* when the state comes from another embedder, verifier, judge or
|
|
2353
|
+
* configuration, from a newer SDK, when its numbers do not add up, or when
|
|
2354
|
+
* this cache has already recorded labels in a segment the state carries
|
|
2355
|
+
* (merging two histories would count some labels twice).
|
|
2356
|
+
*/
|
|
2357
|
+
importCalibration(state: SemanticCalibrationState | string | unknown): void;
|
|
2358
|
+
private identidad;
|
|
2187
2359
|
private estadoDe;
|
|
2188
2360
|
store(c: CanonicalRequest, answer: CachedAnswer): Promise<void>;
|
|
2189
2361
|
/** Drop every record for a knowledge epoch (invalidation on re-index). */
|
|
@@ -2191,6 +2363,55 @@ declare class InMemorySemanticCache {
|
|
|
2191
2363
|
get size(): number;
|
|
2192
2364
|
}
|
|
2193
2365
|
|
|
2366
|
+
/**
|
|
2367
|
+
* Where the layer keeps what it learned about your prompt-cache reuse
|
|
2368
|
+
* (`cacheBreakpoints: "auto"`), when it must outlive a single instance.
|
|
2369
|
+
*
|
|
2370
|
+
* By default that measurement lives in the layer's memory, which is enough for
|
|
2371
|
+
* a long-running server. On serverless platforms, where an instance serves one
|
|
2372
|
+
* request or lives a few minutes, memory is gone before the measurement means
|
|
2373
|
+
* anything, so the layer never gets past its fixed placement. Pass a store
|
|
2374
|
+
* shared by your instances (Redis, a KV) and every instance reads and extends
|
|
2375
|
+
* the same measurement.
|
|
2376
|
+
*
|
|
2377
|
+
* What is stored, per traffic class (model, tools, output contract and system
|
|
2378
|
+
* header): prompt-prefix fingerprints, the times they were sent, reuse counts
|
|
2379
|
+
* and how many predicted cache reads the provider confirmed (with
|
|
2380
|
+
* `cacheMissDiagnostics`, also the provider's response ids). Never prompt text
|
|
2381
|
+
* or any other content. Values are opaque JSON strings, one key per traffic
|
|
2382
|
+
* class, rewritten after each request of that class. A client that hands them
|
|
2383
|
+
* back already parsed (as some Redis and KV clients do) works as well.
|
|
2384
|
+
*
|
|
2385
|
+
* The interface is deliberately minimal so any key-value store can back it.
|
|
2386
|
+
* The layer awaits `get` before placing breakpoints and `get` + `set` after the
|
|
2387
|
+
* provider answers, so a slow store adds its latency to those requests. A store
|
|
2388
|
+
* that fails is treated as empty for that request, and nothing is written
|
|
2389
|
+
* back: the placement falls back to what a fresh process would do.
|
|
2390
|
+
*/
|
|
2391
|
+
interface CacheBreakpointStore {
|
|
2392
|
+
/** The value last `set` for `key` (the string, or the same JSON already parsed), or null/undefined when there is none. */
|
|
2393
|
+
get(key: string): Promise<unknown>;
|
|
2394
|
+
/** `ttlMs`: drop the value if no request of its traffic class rewrites it for this long. What it resolves to is ignored. */
|
|
2395
|
+
set(key: string, value: string, ttlMs: number): Promise<unknown>;
|
|
2396
|
+
}
|
|
2397
|
+
/**
|
|
2398
|
+
* In-memory {@link CacheBreakpointStore}, with TTL and a size bound. Useful for
|
|
2399
|
+
* tests and for several layers in one process; across processes, back the
|
|
2400
|
+
* interface with a shared store.
|
|
2401
|
+
*/
|
|
2402
|
+
declare class InMemoryCacheBreakpointStore implements CacheBreakpointStore {
|
|
2403
|
+
private readonly entradas;
|
|
2404
|
+
private readonly maxEntries;
|
|
2405
|
+
private readonly now;
|
|
2406
|
+
constructor(opts?: {
|
|
2407
|
+
maxEntries?: number;
|
|
2408
|
+
now?: () => number;
|
|
2409
|
+
});
|
|
2410
|
+
get(key: string): Promise<string | null>;
|
|
2411
|
+
set(key: string, value: string, ttlMs: number): Promise<void>;
|
|
2412
|
+
get size(): number;
|
|
2413
|
+
}
|
|
2414
|
+
|
|
2194
2415
|
/**
|
|
2195
2416
|
* Singleflight (in-flight coalescing).
|
|
2196
2417
|
*
|
|
@@ -2834,6 +3055,16 @@ interface ProviderRequest {
|
|
|
2834
3055
|
* Absent: the adapter's fixed placement.
|
|
2835
3056
|
*/
|
|
2836
3057
|
cachePlacement?: CachePlacement;
|
|
3058
|
+
/**
|
|
3059
|
+
* Ask the provider to compare this request's prompt prefix with the one of
|
|
3060
|
+
* an earlier response and report where they diverged (Anthropic cache
|
|
3061
|
+
* diagnostics, Claude API only). `previousMessageId: null` opts in without a
|
|
3062
|
+
* comparison, so that a later request can be compared with this one.
|
|
3063
|
+
* Adapters without the feature, or talking to another host, ignore it.
|
|
3064
|
+
*/
|
|
3065
|
+
cacheDiagnostics?: {
|
|
3066
|
+
previousMessageId: string | null;
|
|
3067
|
+
};
|
|
2837
3068
|
}
|
|
2838
3069
|
/** See {@link ProviderRequest.toolSearch}. */
|
|
2839
3070
|
interface ProviderToolSearch {
|
|
@@ -2850,6 +3081,15 @@ interface ProviderToolSearchUsage {
|
|
|
2850
3081
|
loaded: string[];
|
|
2851
3082
|
/** Searches that came back as an error result instead of references. */
|
|
2852
3083
|
errors: number;
|
|
3084
|
+
/**
|
|
3085
|
+
* Search results from earlier turns that the adapter sent back in this request's history,
|
|
3086
|
+
* so the model could call the tools they loaded without searching again: how many results,
|
|
3087
|
+
* and which tools. Absent when none were sent back.
|
|
3088
|
+
*/
|
|
3089
|
+
resent?: {
|
|
3090
|
+
results: number;
|
|
3091
|
+
tools: string[];
|
|
3092
|
+
};
|
|
2853
3093
|
}
|
|
2854
3094
|
/**
|
|
2855
3095
|
* Breakpoint placement decided by the layer from the reuse it measured on your
|
|
@@ -2938,6 +3178,17 @@ interface ProviderResponse {
|
|
|
2938
3178
|
* podía distinguirlo y hacía exactamente eso.
|
|
2939
3179
|
*/
|
|
2940
3180
|
finishReason?: "stop" | "length" | "content_filter" | "tool_calls" | (string & {});
|
|
3181
|
+
/**
|
|
3182
|
+
* The refusal message the model returned INSTEAD of an answer, exactly as the
|
|
3183
|
+
* provider wrote it: OpenAI's `message.refusal` (Chat Completions with
|
|
3184
|
+
* Structured Outputs), which arrives with `finish_reason: "stop"` and no
|
|
3185
|
+
* `content`. Present only when non-empty.
|
|
3186
|
+
*
|
|
3187
|
+
* The layer treats it like `finishReason: "content_filter"`: the call is
|
|
3188
|
+
* measured, and the answer is never repaired against its contract, cached, or
|
|
3189
|
+
* replayed by reference. `text` and `finishReason` stay what the provider said.
|
|
3190
|
+
*/
|
|
3191
|
+
refusal?: string;
|
|
2941
3192
|
/**
|
|
2942
3193
|
* Llamadas a herramienta que pidió el modelo, tal cual las devolvió el
|
|
2943
3194
|
* proveedor.
|
|
@@ -2986,6 +3237,22 @@ interface ProviderResponse {
|
|
|
2986
3237
|
* read what the search did. The layer only reports it; it credits nothing for it.
|
|
2987
3238
|
*/
|
|
2988
3239
|
toolSearch?: ProviderToolSearchUsage;
|
|
3240
|
+
/** The provider's own id for this response (Anthropic `id`), when it gave one. */
|
|
3241
|
+
providerMessageId?: string;
|
|
3242
|
+
/**
|
|
3243
|
+
* The provider's answer to {@link ProviderRequest.cacheDiagnostics}, when the
|
|
3244
|
+
* request asked for a comparison. `missReason` is the provider's
|
|
3245
|
+
* `cache_miss_reason.type` (`model_changed`, `system_changed`,
|
|
3246
|
+
* `tools_changed`, `messages_changed`, `previous_message_not_found`,
|
|
3247
|
+
* `unavailable`), `"none"` when it compared and found no divergence, or
|
|
3248
|
+
* `"pending"` when the comparison had not finished. `missedInputTokens` is the
|
|
3249
|
+
* provider's estimate of the input after the divergence: a magnitude, not a
|
|
3250
|
+
* billing number.
|
|
3251
|
+
*/
|
|
3252
|
+
cacheDiagnostics?: {
|
|
3253
|
+
missReason: string;
|
|
3254
|
+
missedInputTokens?: number;
|
|
3255
|
+
};
|
|
2989
3256
|
raw?: unknown;
|
|
2990
3257
|
}
|
|
2991
3258
|
/** One event of a provider-level stream. */
|
|
@@ -3277,6 +3544,35 @@ interface SavingsLayerConfig {
|
|
|
3277
3544
|
* causes, one-hour writes at 2x included, is charged to `cost.actual`.
|
|
3278
3545
|
*/
|
|
3279
3546
|
cacheBreakpoints?: "fixed" | "auto";
|
|
3547
|
+
/**
|
|
3548
|
+
* Where `cacheBreakpoints: "auto"` keeps its reuse measurement when it must
|
|
3549
|
+
* outlive a single instance. Optional: without it the measurement lives in this
|
|
3550
|
+
* layer's memory, exactly as before.
|
|
3551
|
+
*
|
|
3552
|
+
* On serverless platforms (one instance per request, or instances that live
|
|
3553
|
+
* a few minutes) memory never gathers enough samples, so `"auto"` stays on
|
|
3554
|
+
* the fixed placement. Pass a store your instances share and each one reads
|
|
3555
|
+
* and extends the same measurement: what one instance learned, the next one
|
|
3556
|
+
* uses. Only prompt-prefix fingerprints, timestamps and counts are stored,
|
|
3557
|
+
* never content. See {@link CacheBreakpointStore}.
|
|
3558
|
+
*/
|
|
3559
|
+
cacheBreakpointStore?: CacheBreakpointStore;
|
|
3560
|
+
/**
|
|
3561
|
+
* With `cacheBreakpoints: "auto"` on Anthropic's own API: when the layer
|
|
3562
|
+
* expects a request to read the cache entry an earlier response wrote, ask
|
|
3563
|
+
* Anthropic to compare the two requests (cache diagnostics), and when that
|
|
3564
|
+
* read does not arrive, publish the provider's `cache_miss_reason` in the
|
|
3565
|
+
* `prefix-cache-placement` trace (`system_changed`, `tools_changed`,
|
|
3566
|
+
* `messages_changed`…, or `none` when the requests matched and the entry was
|
|
3567
|
+
* simply gone). Off by default.
|
|
3568
|
+
*
|
|
3569
|
+
* Each request that opts in makes Anthropic keep a fingerprint of it for a
|
|
3570
|
+
* short time (hashes and token-count estimates, never prompt text), scoped to
|
|
3571
|
+
* your organization and workspace; check it against your data-retention
|
|
3572
|
+
* terms before switching this on. Not sent through Bedrock, Vertex or any
|
|
3573
|
+
* other host. It costs nothing and changes no bill.
|
|
3574
|
+
*/
|
|
3575
|
+
cacheMissDiagnostics?: boolean;
|
|
3280
3576
|
/**
|
|
3281
3577
|
* Signed BiVelio license token (from your paid subscription). This is the
|
|
3282
3578
|
* primary way to license the SDK: `createSavingsLayer` verifies it offline
|
|
@@ -3479,7 +3775,8 @@ interface SavingsLayerConfig {
|
|
|
3479
3775
|
* revocation list going stale. Nothing here throws and nothing here changes
|
|
3480
3776
|
* what the layer does — turning it on only removes the console noise, so set
|
|
3481
3777
|
* it when you have your own observability. Applies to the pipeline, the usage
|
|
3482
|
-
* emitter
|
|
3778
|
+
* emitter, the revocation poller and the provider adapters shipped in this
|
|
3779
|
+
* package alike.
|
|
3483
3780
|
*/
|
|
3484
3781
|
silenceWarnings?: boolean;
|
|
3485
3782
|
/**
|
|
@@ -3859,7 +4156,8 @@ declare const registrarTokenizadorExacto: typeof registerExactTokenizer;
|
|
|
3859
4156
|
*
|
|
3860
4157
|
* A hash of the user text alone is NOT a safe cache key. Two requests may share
|
|
3861
4158
|
* text but differ in tenant, permission scope, model version, system prompt,
|
|
3862
|
-
* schema, toolset,
|
|
4159
|
+
* schema, toolset, tool-loop fields (tool calls, the call a tool result answers,
|
|
4160
|
+
* its error flag), locale, sampling, knowledge epoch or safety policy — any of
|
|
3863
4161
|
* which can change the correct answer. The exact key includes all of them.
|
|
3864
4162
|
*
|
|
3865
4163
|
* `servedModel` CARRIES THE MODEL THAT WILL ACTUALLY ANSWER, not the one the
|
|
@@ -4395,6 +4693,7 @@ declare class AnthropicProvider implements Provider {
|
|
|
4395
4693
|
readonly id: string;
|
|
4396
4694
|
private readonly opts;
|
|
4397
4695
|
private readonly fetchImpl;
|
|
4696
|
+
private readonly busquedas;
|
|
4398
4697
|
constructor(opts?: AnthropicOptions);
|
|
4399
4698
|
/** The id Anthropic's API sees: bare at `api.anthropic.com`, as written elsewhere. */
|
|
4400
4699
|
private modeloEnElCable;
|
|
@@ -4411,8 +4710,12 @@ declare class AnthropicProvider implements Provider {
|
|
|
4411
4710
|
generateStream(req: ProviderRequest, options?: ProviderStreamOptions): AsyncGenerator<ProviderStreamEvent, void, undefined>;
|
|
4412
4711
|
private enviar;
|
|
4413
4712
|
private construirCuerpo;
|
|
4713
|
+
private reenvioDeBusquedas;
|
|
4714
|
+
private recordarBusquedas;
|
|
4715
|
+
private avisar;
|
|
4414
4716
|
private marcarCache;
|
|
4415
4717
|
private leer;
|
|
4718
|
+
private diagnosticoDe;
|
|
4416
4719
|
private leerMensaje;
|
|
4417
4720
|
}
|
|
4418
4721
|
|
|
@@ -4652,7 +4955,6 @@ declare class RevocationPoller {
|
|
|
4652
4955
|
private consecutiveFailures;
|
|
4653
4956
|
private stopped;
|
|
4654
4957
|
private started;
|
|
4655
|
-
private warnedNoFetch;
|
|
4656
4958
|
/** ETag of the last 200; sent as If-None-Match so an unchanged list 304s (cheap no-op). */
|
|
4657
4959
|
private lastEtag;
|
|
4658
4960
|
/** 304 seguidos; al llegar al tope se fuerza una descarga firmada. */
|
|
@@ -5290,4 +5592,4 @@ declare function toCsv(rows: readonly Readonly<Record<string, CsvValue>>[], opti
|
|
|
5290
5592
|
columns?: readonly string[];
|
|
5291
5593
|
}): string;
|
|
5292
5594
|
|
|
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 };
|
|
5595
|
+
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 CacheBreakpointStore, type CacheOutcome, type CachePlacement, type CacheTier, type CacheWriteReport, type CachedAnswer, type CalibrationObservation, CalibrationStateError, 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, InMemoryCacheBreakpointStore, 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 SemanticCalibrationSegmentState, type SemanticCalibrationState, 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 };
|