async-bulkhead-llm 3.7.0 → 3.8.0
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 +145 -3
- package/dist/cjs/adaptive.cjs +128 -0
- package/dist/cjs/adaptive.cjs.map +1 -0
- package/dist/cjs/bulkhead.cjs +838 -0
- package/dist/cjs/bulkhead.cjs.map +1 -0
- package/dist/cjs/dedup.cjs +111 -0
- package/dist/cjs/dedup.cjs.map +1 -0
- package/dist/cjs/errors.cjs +16 -0
- package/dist/cjs/errors.cjs.map +1 -0
- package/dist/cjs/estimators.cjs +205 -0
- package/dist/cjs/estimators.cjs.map +1 -0
- package/dist/cjs/index.cjs +27 -1123
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/profiles.cjs +16 -0
- package/dist/cjs/profiles.cjs.map +1 -0
- package/dist/cjs/types.cjs +3 -0
- package/dist/cjs/types.cjs.map +1 -0
- package/dist/cjs/validation.cjs +39 -0
- package/dist/cjs/validation.cjs.map +1 -0
- package/dist/esm/adaptive.js +125 -0
- package/dist/esm/adaptive.js.map +1 -0
- package/dist/esm/bulkhead.js +835 -0
- package/dist/esm/bulkhead.js.map +1 -0
- package/dist/esm/dedup.js +106 -0
- package/dist/esm/dedup.js.map +1 -0
- package/dist/esm/errors.js +12 -0
- package/dist/esm/errors.js.map +1 -0
- package/dist/esm/estimators.js +200 -0
- package/dist/esm/estimators.js.map +1 -0
- package/dist/esm/index.js +19 -1117
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/profiles.js +13 -0
- package/dist/esm/profiles.js.map +1 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/validation.js +32 -0
- package/dist/esm/validation.js.map +1 -0
- package/dist/types/adaptive.d.ts +109 -0
- package/dist/types/adaptive.d.ts.map +1 -0
- package/dist/types/bulkhead.d.ts +59 -0
- package/dist/types/bulkhead.d.ts.map +1 -0
- package/dist/types/dedup.d.ts +32 -0
- package/dist/types/dedup.d.ts.map +1 -0
- package/dist/types/errors.d.ts +9 -0
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/estimators.d.ts +91 -0
- package/dist/types/estimators.d.ts.map +1 -0
- package/dist/types/index.d.ts +27 -660
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/profiles.d.ts +11 -0
- package/dist/types/profiles.d.ts.map +1 -0
- package/dist/types/types.d.ts +566 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/validation.d.ts +12 -0
- package/dist/types/validation.d.ts.map +1 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,YAAY,EACV,YAAY,EACZ,oBAAoB,EACpB,iBAAiB,EACjB,gBAAgB,EAChB,kBAAkB,EAClB,cAAc,EACd,WAAW,EACX,YAAY,EACZ,UAAU,EACV,WAAW,EACX,eAAe,EACf,eAAe,EACf,UAAU,EACV,eAAe,EACf,sBAAsB,EACtB,sBAAsB,EACtB,aAAa,EACb,QAAQ,EACR,QAAQ,EACR,mBAAmB,EACnB,kBAAkB,EAClB,gBAAgB,EAChB,kBAAkB,EAClB,aAAa,EACb,cAAc,EACd,UAAU,EACV,WAAW,GACZ,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAEvD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,YAAY,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAEvD,OAAO,EACL,8BAA8B,EAC9B,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,iBAAiB,CAAC;AACzB,YAAY,EACV,0BAA0B,EAC1B,iBAAiB,GAClB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,4BAA4B,EAAE,MAAM,eAAe,CAAC;AAC7D,YAAY,EACV,uBAAuB,EACvB,sBAAsB,EACtB,6BAA6B,GAC9B,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,YAAY,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Opinionated option presets (`profile: "interactive" | "batch"`). */
|
|
2
|
+
export type LLMBulkheadPreset = {
|
|
3
|
+
maxQueue?: number;
|
|
4
|
+
timeoutMs?: number;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Built-in presets for common deployment patterns.
|
|
8
|
+
* Explicit options always override preset defaults.
|
|
9
|
+
*/
|
|
10
|
+
export declare const PROFILES: Record<"interactive" | "batch", LLMBulkheadPreset>;
|
|
11
|
+
//# sourceMappingURL=profiles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profiles.d.ts","sourceRoot":"","sources":["../../src/profiles.ts"],"names":[],"mappings":"AAAA,uEAAuE;AAKvE,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,QAAQ,EAAE,MAAM,CAAC,aAAa,GAAG,OAAO,EAAE,iBAAiB,CAGvE,CAAC"}
|
|
@@ -0,0 +1,566 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public request, result, options, stats, and event types shared across
|
|
3
|
+
* the library. Type declarations only — no runtime code lives here.
|
|
4
|
+
*/
|
|
5
|
+
import type { AcquireOptions, Stats, RejectReason as BaseRejectReason } from "async-bulkhead-ts";
|
|
6
|
+
import type { LLMBulkheadPreset } from "./profiles.js";
|
|
7
|
+
/**
|
|
8
|
+
* A text content block. The only block type that contributes to
|
|
9
|
+
* character-based token estimation.
|
|
10
|
+
*/
|
|
11
|
+
export type TextContentBlock = {
|
|
12
|
+
type: "text";
|
|
13
|
+
text: string;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* A non-text content block (image, tool_result, document, etc.).
|
|
17
|
+
*
|
|
18
|
+
* By default, built-in estimators ignore non-text blocks — token
|
|
19
|
+
* estimates for multimodal requests should then be treated as a lower
|
|
20
|
+
* bound. To charge a fixed reservation per opaque block instead, use
|
|
21
|
+
* `createModelAwareTokenEstimator`'s `opaqueBlockTokens` option, or
|
|
22
|
+
* carry a caller-computed total in `LLMRequest.extraInputTokens`, or
|
|
23
|
+
* provide a custom estimator.
|
|
24
|
+
*/
|
|
25
|
+
export type OpaqueContentBlock = {
|
|
26
|
+
type: string;
|
|
27
|
+
[key: string]: unknown;
|
|
28
|
+
};
|
|
29
|
+
export type ContentBlock = TextContentBlock | OpaqueContentBlock;
|
|
30
|
+
/**
|
|
31
|
+
* Minimal message shape shared across estimators.
|
|
32
|
+
*
|
|
33
|
+
* `content` may be a plain string (backward-compatible with v1) or
|
|
34
|
+
* an array of content blocks for multimodal requests.
|
|
35
|
+
*/
|
|
36
|
+
export type LLMMessage = {
|
|
37
|
+
role: string;
|
|
38
|
+
content: string | ContentBlock[];
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Minimal request shape.
|
|
42
|
+
*
|
|
43
|
+
* `model` is optional at the request level. When present, the estimator
|
|
44
|
+
* uses it for ratio lookup instead of the bulkhead-level default.
|
|
45
|
+
* This supports A/B testing, canary deployments, and mixed-model routing
|
|
46
|
+
* through a single bulkhead.
|
|
47
|
+
*/
|
|
48
|
+
export type LLMRequest = {
|
|
49
|
+
model?: string;
|
|
50
|
+
messages: LLMMessage[];
|
|
51
|
+
max_tokens?: number;
|
|
52
|
+
/**
|
|
53
|
+
* Optional system prompt (v3.7). Counted by the built-in estimators
|
|
54
|
+
* exactly like message content: a plain string, or an array of content
|
|
55
|
+
* blocks (text blocks counted by characters, non-text blocks subject
|
|
56
|
+
* to the model-aware estimator's `opaqueBlockTokens` surcharge).
|
|
57
|
+
*
|
|
58
|
+
* Before v3.7, callers had to fold the system prompt into a synthetic
|
|
59
|
+
* message for it to participate in estimation — which also distorted
|
|
60
|
+
* events, logs, and deduplication keys. Carry it here instead.
|
|
61
|
+
*/
|
|
62
|
+
system?: string | ContentBlock[];
|
|
63
|
+
/**
|
|
64
|
+
* Additional input tokens the character-based estimators cannot see
|
|
65
|
+
* (v3.7) — e.g. provider-side cost of tool schemas kept outside
|
|
66
|
+
* `messages`, or media priced by out-of-band rules. Built-in
|
|
67
|
+
* estimators add this verbatim to their input estimate; custom
|
|
68
|
+
* estimators may honor or ignore it.
|
|
69
|
+
*
|
|
70
|
+
* Must be a non-negative integer when present. Participates in the
|
|
71
|
+
* default deduplication key like any other request field, so requests
|
|
72
|
+
* differing only here are never conflated.
|
|
73
|
+
*/
|
|
74
|
+
extraInputTokens?: number;
|
|
75
|
+
};
|
|
76
|
+
export type TokenEstimate = {
|
|
77
|
+
input: number;
|
|
78
|
+
maxOutput: number;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Exact token reservation the bulkhead will use for admission.
|
|
82
|
+
*
|
|
83
|
+
* `null` is returned by `bulkhead.estimate()` when `tokenBudget` is not
|
|
84
|
+
* configured, because no token reservation participates in admission in
|
|
85
|
+
* that mode.
|
|
86
|
+
*/
|
|
87
|
+
export type LLMReservationEstimate = {
|
|
88
|
+
readonly input: number;
|
|
89
|
+
readonly maxOutput: number;
|
|
90
|
+
readonly reserved: number;
|
|
91
|
+
};
|
|
92
|
+
export type TokenEstimator = (request: LLMRequest) => TokenEstimate;
|
|
93
|
+
/**
|
|
94
|
+
* Accepted shape for the per-call `reservation` override (v3.8).
|
|
95
|
+
*
|
|
96
|
+
* Structurally this is a `TokenEstimate` plus an optional `reserved`
|
|
97
|
+
* field, which means the object returned by `bulkhead.estimate()`
|
|
98
|
+
* (an `LLMReservationEstimate`) can be passed back verbatim — no need
|
|
99
|
+
* to strip `reserved` first. When `reserved` is present it is treated
|
|
100
|
+
* as a consistency check: it must equal `input + maxOutput`, otherwise
|
|
101
|
+
* admission throws. This catches hand-built overrides whose fields
|
|
102
|
+
* drifted apart (e.g. a cached `reserved` paired with edited parts).
|
|
103
|
+
*/
|
|
104
|
+
export type LLMReservationOverride = TokenEstimate & {
|
|
105
|
+
/** Optional cross-check; must equal `input + maxOutput` when present. */
|
|
106
|
+
reserved?: number;
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Result of `wouldAdmit()` (v3.8: optional capacity snapshot).
|
|
110
|
+
*
|
|
111
|
+
* `detail` is present only when the call passed `detail: true`. It is
|
|
112
|
+
* the same `LLMRejectDetail` snapshot attached to real rejections —
|
|
113
|
+
* including on an `admit: true` result, where it describes the capacity
|
|
114
|
+
* the request *would* be admitted against. Like the boolean itself, it
|
|
115
|
+
* is advisory: capacity can change before a subsequent `acquire()`.
|
|
116
|
+
*/
|
|
117
|
+
export type LLMWouldAdmitResult = {
|
|
118
|
+
admit: boolean;
|
|
119
|
+
reason?: LLMRejectReason;
|
|
120
|
+
detail?: LLMRejectDetail;
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* Result of `drain({ timeoutMs })` (v3.8).
|
|
124
|
+
*
|
|
125
|
+
* `drained: true` means all in-flight work and pending waiters
|
|
126
|
+
* completed within the deadline (`inFlight`/`pending` are then 0).
|
|
127
|
+
* `drained: false` means the deadline elapsed first; `inFlight` and
|
|
128
|
+
* `pending` report what was still outstanding at that moment.
|
|
129
|
+
*/
|
|
130
|
+
export type LLMDrainResult = {
|
|
131
|
+
drained: boolean;
|
|
132
|
+
inFlight: number;
|
|
133
|
+
pending: number;
|
|
134
|
+
};
|
|
135
|
+
/**
|
|
136
|
+
* Actual token usage returned by the provider after a call completes.
|
|
137
|
+
*
|
|
138
|
+
* In v2, this drives the refund mechanism: when usage is reported at
|
|
139
|
+
* release time, the difference between the pre-admission reservation
|
|
140
|
+
* and actual consumption is returned to the budget immediately.
|
|
141
|
+
*/
|
|
142
|
+
export type TokenUsage = {
|
|
143
|
+
input: number;
|
|
144
|
+
output: number;
|
|
145
|
+
};
|
|
146
|
+
/**
|
|
147
|
+
* Rejection reasons.
|
|
148
|
+
*
|
|
149
|
+
* `"unshareable_result"` (v3.5) is raised only for deduplication
|
|
150
|
+
* *followers*: the shared call resolved to a single-consumer value
|
|
151
|
+
* (stream, `Response` with a body, async iterable) that cannot be
|
|
152
|
+
* safely handed to more than one caller, and no
|
|
153
|
+
* `deduplication.shareResult` hook was configured. The leader always
|
|
154
|
+
* receives the original result unaffected.
|
|
155
|
+
*/
|
|
156
|
+
export type LLMRejectReason = BaseRejectReason | "budget_limit" | "unshareable_result";
|
|
157
|
+
/**
|
|
158
|
+
* Admission priority.
|
|
159
|
+
*
|
|
160
|
+
* `"high"` requests may use the full token budget. `"normal"` requests
|
|
161
|
+
* (the default) are rejected once available budget drops to
|
|
162
|
+
* `tokenBudget.highPriorityReserve`, keeping headroom for high-priority
|
|
163
|
+
* traffic. Priority has no effect when `tokenBudget` is not configured
|
|
164
|
+
* or `highPriorityReserve` is 0/unset.
|
|
165
|
+
*/
|
|
166
|
+
export type LLMPriority = "high" | "normal";
|
|
167
|
+
/**
|
|
168
|
+
* Capacity snapshot attached to rejections so callers (e.g. gateways)
|
|
169
|
+
* can build informative 429/503 responses.
|
|
170
|
+
*
|
|
171
|
+
* Note: no retry-after estimate is provided — a fail-fast bulkhead has
|
|
172
|
+
* no honest ETA for capacity. Expose these numbers instead.
|
|
173
|
+
*/
|
|
174
|
+
export type LLMRejectDetail = {
|
|
175
|
+
inFlight: number;
|
|
176
|
+
maxConcurrent: number;
|
|
177
|
+
pending: number;
|
|
178
|
+
maxQueue: number;
|
|
179
|
+
tokenBudget?: {
|
|
180
|
+
/** Configured budget ceiling. */
|
|
181
|
+
budget: number;
|
|
182
|
+
/** Tokens currently held by in-flight reservations. */
|
|
183
|
+
inFlightTokens: number;
|
|
184
|
+
/** Budget this request was admitted against (priority-adjusted). */
|
|
185
|
+
effectiveBudget: number;
|
|
186
|
+
/** Tokens available at this priority (clamped at 0). */
|
|
187
|
+
available: number;
|
|
188
|
+
/** Tokens this request needed. */
|
|
189
|
+
requested: number;
|
|
190
|
+
};
|
|
191
|
+
};
|
|
192
|
+
/** Options accepted by `acquire()` / `run()` (base options + priority). */
|
|
193
|
+
export type LLMAcquireOptions = AcquireOptions & {
|
|
194
|
+
priority?: LLMPriority;
|
|
195
|
+
/**
|
|
196
|
+
* Per-call token reservation override (v3.7).
|
|
197
|
+
*
|
|
198
|
+
* When provided and `tokenBudget` is configured, admission reserves
|
|
199
|
+
* `input + maxOutput` from this value verbatim and the bulkhead's
|
|
200
|
+
* estimator is not consulted for this call. Intended for callers —
|
|
201
|
+
* typically gateways — that already compute a more accurate estimate
|
|
202
|
+
* from the full provider request (tool schemas, response formats,
|
|
203
|
+
* provider-priced media) than any character-ratio estimator could.
|
|
204
|
+
*
|
|
205
|
+
* Both fields must be non-negative integers. Ignored when
|
|
206
|
+
* `tokenBudget` is not configured (no reservation participates in
|
|
207
|
+
* admission in that mode). Not reflected by `estimate()`, which
|
|
208
|
+
* always previews the estimator path.
|
|
209
|
+
*
|
|
210
|
+
* v3.8: the object returned by `bulkhead.estimate()` can be passed
|
|
211
|
+
* here directly. When a `reserved` field is present it must equal
|
|
212
|
+
* `input + maxOutput` (see `LLMReservationOverride`).
|
|
213
|
+
*/
|
|
214
|
+
reservation?: LLMReservationOverride;
|
|
215
|
+
};
|
|
216
|
+
export type LLMRequestStats = {
|
|
217
|
+
/** Successful LLM admissions (slot + budget acquired). */
|
|
218
|
+
admitted: number;
|
|
219
|
+
/** Successful LLM releases via the wrapped LLM token. */
|
|
220
|
+
released: number;
|
|
221
|
+
/** Total LLM-layer rejections. */
|
|
222
|
+
rejected: number;
|
|
223
|
+
/** LLM-layer rejections by reason. */
|
|
224
|
+
rejectedByReason: Partial<Record<LLMRejectReason, number>>;
|
|
225
|
+
};
|
|
226
|
+
export type LLMStats = {
|
|
227
|
+
/** Underlying async-bulkhead-ts stats. */
|
|
228
|
+
bulkhead: Stats;
|
|
229
|
+
/** LLM-layer request stats. */
|
|
230
|
+
llm: LLMRequestStats;
|
|
231
|
+
/** Present only when `tokenBudget` is configured. */
|
|
232
|
+
tokenBudget?: {
|
|
233
|
+
budget: number;
|
|
234
|
+
inFlightTokens: number;
|
|
235
|
+
available: number;
|
|
236
|
+
/**
|
|
237
|
+
* Cumulative tokens reserved at admission across all successful
|
|
238
|
+
* admissions. Monotonically increasing.
|
|
239
|
+
*/
|
|
240
|
+
totalReserved: number;
|
|
241
|
+
/**
|
|
242
|
+
* Cumulative actual tokens consumed (`usage.input + usage.output`),
|
|
243
|
+
* summed across releases that reported `TokenUsage`. Releases without
|
|
244
|
+
* usage contribute 0 — `totalConsumed` is meaningful only when
|
|
245
|
+
* `getUsage` is wired up consistently. Not clamped: over-consumption
|
|
246
|
+
* (actual > reserved) is reported as-is.
|
|
247
|
+
*/
|
|
248
|
+
totalConsumed: number;
|
|
249
|
+
/**
|
|
250
|
+
* Cumulative tokens returned to the budget via the refund mechanism —
|
|
251
|
+
* both early refunds from `reportUsage()` and refunds at release.
|
|
252
|
+
*/
|
|
253
|
+
totalRefunded: number;
|
|
254
|
+
/**
|
|
255
|
+
* Cumulative tokens held *beyond* original reservations because
|
|
256
|
+
* `reportUsage()` reported consumption exceeding the reserved hold.
|
|
257
|
+
* Overrun expands `inFlightTokens` (possibly above `budget`), which
|
|
258
|
+
* correctly blocks new admissions until the overrunning work releases.
|
|
259
|
+
*/
|
|
260
|
+
totalOverrun: number;
|
|
261
|
+
/** Budget headroom reserved for `priority: "high"` requests. */
|
|
262
|
+
highPriorityReserve: number;
|
|
263
|
+
};
|
|
264
|
+
/** Present only when deduplication is enabled. */
|
|
265
|
+
deduplication?: {
|
|
266
|
+
/** Number of distinct in-flight deduplication keys. */
|
|
267
|
+
active: number;
|
|
268
|
+
/** Cumulative requests that shared an existing in-flight call. */
|
|
269
|
+
hits: number;
|
|
270
|
+
};
|
|
271
|
+
};
|
|
272
|
+
export type LLMEventMap = {
|
|
273
|
+
/** Fired after a request is admitted (slot + budget acquired). */
|
|
274
|
+
admit: {
|
|
275
|
+
request: LLMRequest;
|
|
276
|
+
admissionId: string;
|
|
277
|
+
priority: LLMPriority;
|
|
278
|
+
reservedTokens: number;
|
|
279
|
+
};
|
|
280
|
+
/** Fired when a request is rejected at any stage. */
|
|
281
|
+
reject: {
|
|
282
|
+
request: LLMRequest;
|
|
283
|
+
reason: LLMRejectReason;
|
|
284
|
+
/** Capacity snapshot; absent for dedup-wait rejections. */
|
|
285
|
+
detail?: LLMRejectDetail;
|
|
286
|
+
};
|
|
287
|
+
/**
|
|
288
|
+
* Fired when a slot is released.
|
|
289
|
+
*
|
|
290
|
+
* `reservedTokens` is the pre-admission reservation (input estimate +
|
|
291
|
+
* `max_tokens` reservation). `refundedTokens` is what was returned to
|
|
292
|
+
* the budget — non-zero only when `usage` was reported and
|
|
293
|
+
* `usage.input + usage.output < reservedTokens`.
|
|
294
|
+
*
|
|
295
|
+
* Per-request actual consumption: `usage ? usage.input + usage.output : null`.
|
|
296
|
+
* The library does not pre-derive this onto the event payload — `null`
|
|
297
|
+
* (no usage reported) and `0` (genuinely zero usage) are different
|
|
298
|
+
* states that observers should distinguish.
|
|
299
|
+
*
|
|
300
|
+
* For cumulative consumption across all releases, prefer
|
|
301
|
+
* `stats().tokenBudget.totalConsumed` over aggregating these events.
|
|
302
|
+
*/
|
|
303
|
+
release: {
|
|
304
|
+
request: LLMRequest;
|
|
305
|
+
admissionId: string;
|
|
306
|
+
priority: LLMPriority;
|
|
307
|
+
reservedTokens: number;
|
|
308
|
+
/** Tokens held immediately before release returned them. */
|
|
309
|
+
heldTokens: number;
|
|
310
|
+
refundedTokens: number;
|
|
311
|
+
/** Last emitted usage-event sequence for this admission. */
|
|
312
|
+
usageSequence: number;
|
|
313
|
+
usage?: TokenUsage;
|
|
314
|
+
};
|
|
315
|
+
/**
|
|
316
|
+
* Fired after an effective cumulative `reportUsage()` update.
|
|
317
|
+
*
|
|
318
|
+
* Stale or duplicate reports that do not increase either cumulative
|
|
319
|
+
* usage field are ignored and do not emit an event. `sequence` starts at
|
|
320
|
+
* 1 per admission and increases monotonically, allowing external
|
|
321
|
+
* coordinators to reject duplicate or out-of-order updates.
|
|
322
|
+
*/
|
|
323
|
+
usage: {
|
|
324
|
+
request: LLMRequest;
|
|
325
|
+
admissionId: string;
|
|
326
|
+
priority: LLMPriority;
|
|
327
|
+
sequence: number;
|
|
328
|
+
reservedTokens: number;
|
|
329
|
+
previousHeldTokens: number;
|
|
330
|
+
heldTokens: number;
|
|
331
|
+
deltaTokens: number;
|
|
332
|
+
usage: TokenUsage;
|
|
333
|
+
outputCap: number | null;
|
|
334
|
+
outputRemaining: number | null;
|
|
335
|
+
overReservation: boolean;
|
|
336
|
+
};
|
|
337
|
+
/** Fired when a request joins an existing in-flight call via dedup. */
|
|
338
|
+
dedup: {
|
|
339
|
+
request: LLMRequest;
|
|
340
|
+
};
|
|
341
|
+
};
|
|
342
|
+
export type LLMEventType = keyof LLMEventMap;
|
|
343
|
+
export type Listener<K extends LLMEventType> = (payload: LLMEventMap[K]) => void;
|
|
344
|
+
export type TokenBudgetOptions = {
|
|
345
|
+
/**
|
|
346
|
+
* Maximum tokens allowed in-flight simultaneously across all active requests.
|
|
347
|
+
* Admission is always fail-fast when this ceiling is reached,
|
|
348
|
+
* independent of concurrency headroom and independent of `profile`.
|
|
349
|
+
*
|
|
350
|
+
* Must be a non-negative integer. `0` is valid and intentional — it
|
|
351
|
+
* represents a pool with no budget to grant this cycle (e.g. a lease
|
|
352
|
+
* ledger reporting exhaustion) and results in every budget-gated
|
|
353
|
+
* admission being rejected with `"budget_limit"` until the ceiling is
|
|
354
|
+
* raised (via `setBudget()`) or `tokenBudget` admits a zero-token
|
|
355
|
+
* request.
|
|
356
|
+
*/
|
|
357
|
+
budget: number;
|
|
358
|
+
/**
|
|
359
|
+
* Estimator used to calculate token reservation pre-admission.
|
|
360
|
+
* Defaults to `createModelAwareTokenEstimator` seeded with the bulkhead's `model`.
|
|
361
|
+
*/
|
|
362
|
+
estimator?: TokenEstimator;
|
|
363
|
+
/**
|
|
364
|
+
* Fallback output reservation when `request.max_tokens` is absent.
|
|
365
|
+
* Default: 2048.
|
|
366
|
+
*/
|
|
367
|
+
outputCap?: number;
|
|
368
|
+
/**
|
|
369
|
+
* Tokens of budget headroom reserved for `priority: "high"` requests.
|
|
370
|
+
*
|
|
371
|
+
* Normal-priority admission is checked against
|
|
372
|
+
* `budget - highPriorityReserve`; high-priority admission is checked
|
|
373
|
+
* against the full `budget`. This lets interactive traffic keep
|
|
374
|
+
* admitting while batch traffic has saturated the shared pool.
|
|
375
|
+
*
|
|
376
|
+
* Must satisfy `0 <= highPriorityReserve <= budget`. Default: 0
|
|
377
|
+
* (priority has no effect).
|
|
378
|
+
*/
|
|
379
|
+
highPriorityReserve?: number;
|
|
380
|
+
};
|
|
381
|
+
export type DeduplicationOptions = {
|
|
382
|
+
/**
|
|
383
|
+
* Custom function to derive a deduplication key from a request.
|
|
384
|
+
* Requests with the same key that arrive while a matching call is
|
|
385
|
+
* already in-flight share that call.
|
|
386
|
+
*
|
|
387
|
+
* Default (v3.4): a key-order-stable serialization of the **entire
|
|
388
|
+
* request object**. Any own enumerable property difference —
|
|
389
|
+
* `temperature`, `tools`, `system`, etc., not just `messages` /
|
|
390
|
+
* `max_tokens` / `model` — prevents conflation. The tradeoff: volatile
|
|
391
|
+
* per-request fields (request IDs, timestamps) also defeat
|
|
392
|
+
* deduplication. If your requests carry such fields, supply a `keyFn`
|
|
393
|
+
* that omits them. Non-serializable values (functions, symbols) are
|
|
394
|
+
* dropped by JSON serialization and do not distinguish requests.
|
|
395
|
+
*
|
|
396
|
+
* Keys are SHA-256 hashed before being stored, so the in-flight map
|
|
397
|
+
* never retains prompt text and per-entry key memory is bounded.
|
|
398
|
+
*
|
|
399
|
+
* Deduplication applies to `run()` only — `acquire()` never
|
|
400
|
+
* deduplicates.
|
|
401
|
+
*
|
|
402
|
+
* **Multi-tenant callers:** the default key has no tenant dimension.
|
|
403
|
+
* Two tenants sending byte-identical requests would share one
|
|
404
|
+
* response. Pass `dedupScope` (per-call, on `run()` options) or bake
|
|
405
|
+
* the tenant into a custom `keyFn` to prevent cross-tenant sharing.
|
|
406
|
+
*
|
|
407
|
+
* Return an empty string to opt a specific request out of deduplication.
|
|
408
|
+
*/
|
|
409
|
+
keyFn?: (request: LLMRequest) => string;
|
|
410
|
+
/**
|
|
411
|
+
* Fan-out hook for delivering a shared in-flight result to
|
|
412
|
+
* deduplication *followers* (v3.5).
|
|
413
|
+
*
|
|
414
|
+
* Called once per follower with the leader's resolved result; the
|
|
415
|
+
* return value is what that follower receives. The leader always
|
|
416
|
+
* receives the original result — `shareResult` is never called for
|
|
417
|
+
* the leader.
|
|
418
|
+
*
|
|
419
|
+
* Why this exists: without it, followers receive the *same object*
|
|
420
|
+
* the leader does. For plain JSON results that is fine (and remains
|
|
421
|
+
* the default), but single-consumer values — `ReadableStream`,
|
|
422
|
+
* Node `Readable`, async iterables, `Response` bodies — can only be
|
|
423
|
+
* consumed once. Whichever caller reads first wins; the rest get a
|
|
424
|
+
* locked or drained stream. The library cannot tee arbitrary stream
|
|
425
|
+
* types on your behalf, so it provides this seam instead:
|
|
426
|
+
*
|
|
427
|
+
* ```ts
|
|
428
|
+
* // fetch Response: hand each follower an independent clone.
|
|
429
|
+
* // (clone() must be called before any consumer reads the body —
|
|
430
|
+
* // guaranteed here, since fan-out happens at resolution time.)
|
|
431
|
+
* deduplication: { shareResult: (r) => (r as Response).clone() }
|
|
432
|
+
* ```
|
|
433
|
+
*
|
|
434
|
+
* When `shareResult` is provided it is called for **every** follower
|
|
435
|
+
* delivery, including safe (non-stream) results — it is a general
|
|
436
|
+
* fan-out policy, usable e.g. for defensive deep-cloning.
|
|
437
|
+
*
|
|
438
|
+
* If `shareResult` throws, that follower's `run()` rejects with the
|
|
439
|
+
* thrown error as-is; the leader and other followers are unaffected.
|
|
440
|
+
*
|
|
441
|
+
* When `shareResult` is **not** provided and the shared result is
|
|
442
|
+
* detected as single-consumer, followers are rejected with
|
|
443
|
+
* `LLMBulkheadRejectedError("unshareable_result")` rather than being
|
|
444
|
+
* silently handed a stream they cannot read. Detection is shallow:
|
|
445
|
+
* it inspects the result value itself, not nested properties — a
|
|
446
|
+
* stream buried inside `{ stream: ... }` is not detected and will be
|
|
447
|
+
* shared by reference as before.
|
|
448
|
+
*/
|
|
449
|
+
shareResult?: (result: unknown) => unknown;
|
|
450
|
+
};
|
|
451
|
+
export type LLMBulkheadOptions = {
|
|
452
|
+
/**
|
|
453
|
+
* Model identifier. Used by the default estimator for ratio lookup.
|
|
454
|
+
*
|
|
455
|
+
* One bulkhead per model is the strongly recommended deployment pattern.
|
|
456
|
+
* When routing multiple models through one bulkhead, set `model` on
|
|
457
|
+
* individual `LLMRequest` objects for accurate estimation.
|
|
458
|
+
*/
|
|
459
|
+
model: string;
|
|
460
|
+
/** Maximum number of requests in-flight simultaneously. */
|
|
461
|
+
maxConcurrent: number;
|
|
462
|
+
/**
|
|
463
|
+
* Maximum number of requests waiting for admission.
|
|
464
|
+
* Default: 0 (fail-fast). Prefer setting via `profile`.
|
|
465
|
+
*/
|
|
466
|
+
maxQueue?: number;
|
|
467
|
+
/**
|
|
468
|
+
* Waiting timeout in milliseconds. Applies to queued requests only.
|
|
469
|
+
* Has no effect when `maxQueue` is 0.
|
|
470
|
+
*/
|
|
471
|
+
timeoutMs?: number;
|
|
472
|
+
/**
|
|
473
|
+
* Opinionated defaults for common deployment patterns.
|
|
474
|
+
* Explicit options always override profile defaults.
|
|
475
|
+
*/
|
|
476
|
+
profile?: "interactive" | "batch" | LLMBulkheadPreset;
|
|
477
|
+
/**
|
|
478
|
+
* Token budget enforcement. Admission fails fast when the in-flight token
|
|
479
|
+
* ceiling is reached, regardless of concurrency headroom or `profile`.
|
|
480
|
+
* Omit to disable token-aware admission.
|
|
481
|
+
*/
|
|
482
|
+
tokenBudget?: TokenBudgetOptions;
|
|
483
|
+
/**
|
|
484
|
+
* Enable in-flight request deduplication.
|
|
485
|
+
*
|
|
486
|
+
* - `true` — use the default key function
|
|
487
|
+
* - `DeduplicationOptions` — customize the key function
|
|
488
|
+
* - `false` / omitted — disabled
|
|
489
|
+
*/
|
|
490
|
+
deduplication?: boolean | DeduplicationOptions;
|
|
491
|
+
};
|
|
492
|
+
/**
|
|
493
|
+
* Snapshot returned by `LLMToken.reportUsage()`.
|
|
494
|
+
*
|
|
495
|
+
* `outputCap` / `outputRemaining` are `null` when `tokenBudget` is not
|
|
496
|
+
* configured (there is no reservation to measure against).
|
|
497
|
+
*/
|
|
498
|
+
export type UsageReport = {
|
|
499
|
+
/** Stable identifier of the admission this usage belongs to. */
|
|
500
|
+
admissionId: string;
|
|
501
|
+
/**
|
|
502
|
+
* Last effective usage-update sequence for this admission.
|
|
503
|
+
* Starts at 0 before any effective report, increments only when either
|
|
504
|
+
* cumulative usage field increases, and remains stable for stale reports.
|
|
505
|
+
*/
|
|
506
|
+
sequence: number;
|
|
507
|
+
/** Original pre-admission reservation (0 when budget disabled). */
|
|
508
|
+
reserved: number;
|
|
509
|
+
/** Tokens currently held against the budget for this request. */
|
|
510
|
+
held: number;
|
|
511
|
+
/** Cumulative reported consumption (`input + output`). */
|
|
512
|
+
consumed: number;
|
|
513
|
+
/** Output tokens reserved for this request (`max_tokens`/`outputCap`). */
|
|
514
|
+
outputCap: number | null;
|
|
515
|
+
/** Output reservation remaining before the stream overruns it. */
|
|
516
|
+
outputRemaining: number | null;
|
|
517
|
+
/** True once cumulative consumption exceeds the original reservation. */
|
|
518
|
+
overReservation: boolean;
|
|
519
|
+
};
|
|
520
|
+
/** Context passed to `run()` callbacks for mid-flight usage reporting. */
|
|
521
|
+
export type LLMRunContext = {
|
|
522
|
+
/** Stable identifier for this successful admission. */
|
|
523
|
+
readonly admissionId: string;
|
|
524
|
+
/** Exact reservation used at admission, or `null` without a token budget. */
|
|
525
|
+
readonly reservation: LLMReservationEstimate | null;
|
|
526
|
+
reportUsage(usage: TokenUsage): UsageReport;
|
|
527
|
+
};
|
|
528
|
+
/**
|
|
529
|
+
* Admission token returned by `acquire()`.
|
|
530
|
+
*
|
|
531
|
+
* Call `release()` exactly once when the request completes.
|
|
532
|
+
* Pass `TokenUsage` to enable the refund mechanism — the bulkhead
|
|
533
|
+
* returns the difference between the pre-admission reservation and
|
|
534
|
+
* actual consumption to the budget immediately.
|
|
535
|
+
*
|
|
536
|
+
* For streaming workloads, call `reportUsage()` with *cumulative* usage
|
|
537
|
+
* as stream events arrive:
|
|
538
|
+
*
|
|
539
|
+
* - If the reported input is lower than the pre-admission estimate, the
|
|
540
|
+
* surplus is refunded to the budget immediately (the full output
|
|
541
|
+
* reservation is retained).
|
|
542
|
+
* - If reported consumption exceeds the hold, the hold expands (overrun),
|
|
543
|
+
* which blocks new admissions until this request releases.
|
|
544
|
+
* - Reports are clamped to be monotonically non-decreasing per field.
|
|
545
|
+
* - If `release()` is later called without usage, the last reported
|
|
546
|
+
* usage is used for the final refund.
|
|
547
|
+
*/
|
|
548
|
+
export type LLMToken = {
|
|
549
|
+
/** Stable identifier for this successful admission. */
|
|
550
|
+
readonly admissionId: string;
|
|
551
|
+
/** Exact reservation used at admission, or `null` without a token budget. */
|
|
552
|
+
readonly reservation: LLMReservationEstimate | null;
|
|
553
|
+
release(usage?: TokenUsage): void;
|
|
554
|
+
reportUsage(usage: TokenUsage): UsageReport;
|
|
555
|
+
};
|
|
556
|
+
export type LLMAcquireResult = {
|
|
557
|
+
ok: true;
|
|
558
|
+
admissionId: string;
|
|
559
|
+
reservation: LLMReservationEstimate | null;
|
|
560
|
+
token: LLMToken;
|
|
561
|
+
} | {
|
|
562
|
+
ok: false;
|
|
563
|
+
reason: LLMRejectReason;
|
|
564
|
+
detail?: LLMRejectDetail;
|
|
565
|
+
};
|
|
566
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
2
|
+
* Internal numeric guards and estimate/usage validators, shared by the
|
|
3
|
+
* estimators, the adaptive estimator, and the bulkhead. Not part of the
|
|
4
|
+
* public API — nothing here is re-exported from the package entry point.
|
|
5
|
+
*/
|
|
6
|
+
import type { TokenEstimate, TokenUsage } from "./types.js";
|
|
7
|
+
export declare function assertNonNegativeInteger(value: number, name: string): void;
|
|
8
|
+
export declare function assertPositiveInteger(value: number, name: string): void;
|
|
9
|
+
export declare function assertOptionalNonNegativeInteger(value: number | undefined, name: string): void;
|
|
10
|
+
export declare function validateTokenEstimate(estimate: TokenEstimate): number;
|
|
11
|
+
export declare function validateTokenUsage(usage: TokenUsage): TokenUsage;
|
|
12
|
+
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/validation.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAM5D,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAI1E;AAED,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAIvE;AAED,wBAAgB,gCAAgC,CAC9C,KAAK,EAAE,MAAM,GAAG,SAAS,EACzB,IAAI,EAAE,MAAM,GACX,IAAI,CAEN;AAED,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,aAAa,GAAG,MAAM,CAMrE;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU,CAMhE"}
|