async-bulkhead-llm 3.16.0 → 3.17.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +127 -4
- package/README.md +28 -2
- package/dist/cjs/bulkhead.cjs +119 -1666
- package/dist/cjs/bulkhead.cjs.map +1 -1
- package/dist/cjs/engine/acquire.cjs +144 -0
- package/dist/cjs/engine/acquire.cjs.map +1 -0
- package/dist/cjs/engine/admission-counts.cjs +92 -0
- package/dist/cjs/engine/admission-counts.cjs.map +1 -0
- package/dist/cjs/engine/admission-request.cjs +28 -0
- package/dist/cjs/engine/admission-request.cjs.map +1 -0
- package/dist/cjs/engine/admitted-run.cjs +100 -0
- package/dist/cjs/engine/admitted-run.cjs.map +1 -0
- package/dist/cjs/engine/admitted-token.cjs +192 -0
- package/dist/cjs/engine/admitted-token.cjs.map +1 -0
- package/dist/cjs/engine/bypass.cjs +162 -0
- package/dist/cjs/engine/bypass.cjs.map +1 -0
- package/dist/cjs/engine/capacity.cjs +89 -0
- package/dist/cjs/engine/capacity.cjs.map +1 -0
- package/dist/cjs/engine/class-limits.cjs +101 -0
- package/dist/cjs/engine/class-limits.cjs.map +1 -0
- package/dist/cjs/engine/class-slots.cjs +49 -0
- package/dist/cjs/engine/class-slots.cjs.map +1 -0
- package/dist/cjs/engine/dedup-flow.cjs +207 -0
- package/dist/cjs/engine/dedup-flow.cjs.map +1 -0
- package/dist/cjs/engine/events.cjs +35 -0
- package/dist/cjs/engine/events.cjs.map +1 -0
- package/dist/cjs/engine/limits.cjs +313 -0
- package/dist/cjs/engine/limits.cjs.map +1 -0
- package/dist/cjs/engine/observe-stats.cjs +43 -0
- package/dist/cjs/engine/observe-stats.cjs.map +1 -0
- package/dist/cjs/engine/options.cjs +79 -0
- package/dist/cjs/engine/options.cjs.map +1 -0
- package/dist/cjs/engine/reject-detail.cjs +103 -0
- package/dist/cjs/engine/reject-detail.cjs.map +1 -0
- package/dist/cjs/engine/reservation.cjs +55 -0
- package/dist/cjs/engine/reservation.cjs.map +1 -0
- package/dist/cjs/engine/run-options.cjs +59 -0
- package/dist/cjs/engine/run-options.cjs.map +1 -0
- package/dist/cjs/engine/run.cjs +76 -0
- package/dist/cjs/engine/run.cjs.map +1 -0
- package/dist/cjs/engine/shared-usage.cjs +70 -0
- package/dist/cjs/engine/shared-usage.cjs.map +1 -0
- package/dist/cjs/engine/shared.cjs +17 -0
- package/dist/cjs/engine/shared.cjs.map +1 -0
- package/dist/cjs/engine/shutdown.cjs +58 -0
- package/dist/cjs/engine/shutdown.cjs.map +1 -0
- package/dist/cjs/engine/stats.cjs +92 -0
- package/dist/cjs/engine/stats.cjs.map +1 -0
- package/dist/cjs/engine/token-ledger.cjs +117 -0
- package/dist/cjs/engine/token-ledger.cjs.map +1 -0
- package/dist/cjs/engine/usage-report.cjs +95 -0
- package/dist/cjs/engine/usage-report.cjs.map +1 -0
- package/dist/cjs/engine/would-admit.cjs +37 -0
- package/dist/cjs/engine/would-admit.cjs.map +1 -0
- package/dist/cjs/errors.cjs +22 -1
- package/dist/cjs/errors.cjs.map +1 -1
- package/dist/cjs/index.cjs +11 -2
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/bulkhead.js +119 -1666
- package/dist/esm/bulkhead.js.map +1 -1
- package/dist/esm/engine/acquire.js +141 -0
- package/dist/esm/engine/acquire.js.map +1 -0
- package/dist/esm/engine/admission-counts.js +89 -0
- package/dist/esm/engine/admission-counts.js.map +1 -0
- package/dist/esm/engine/admission-request.js +25 -0
- package/dist/esm/engine/admission-request.js.map +1 -0
- package/dist/esm/engine/admitted-run.js +97 -0
- package/dist/esm/engine/admitted-run.js.map +1 -0
- package/dist/esm/engine/admitted-token.js +189 -0
- package/dist/esm/engine/admitted-token.js.map +1 -0
- package/dist/esm/engine/bypass.js +159 -0
- package/dist/esm/engine/bypass.js.map +1 -0
- package/dist/esm/engine/capacity.js +86 -0
- package/dist/esm/engine/capacity.js.map +1 -0
- package/dist/esm/engine/class-limits.js +95 -0
- package/dist/esm/engine/class-limits.js.map +1 -0
- package/dist/esm/engine/class-slots.js +46 -0
- package/dist/esm/engine/class-slots.js.map +1 -0
- package/dist/esm/engine/dedup-flow.js +204 -0
- package/dist/esm/engine/dedup-flow.js.map +1 -0
- package/dist/esm/engine/events.js +32 -0
- package/dist/esm/engine/events.js.map +1 -0
- package/dist/esm/engine/limits.js +310 -0
- package/dist/esm/engine/limits.js.map +1 -0
- package/dist/esm/engine/observe-stats.js +40 -0
- package/dist/esm/engine/observe-stats.js.map +1 -0
- package/dist/esm/engine/options.js +76 -0
- package/dist/esm/engine/options.js.map +1 -0
- package/dist/esm/engine/reject-detail.js +100 -0
- package/dist/esm/engine/reject-detail.js.map +1 -0
- package/dist/esm/engine/reservation.js +52 -0
- package/dist/esm/engine/reservation.js.map +1 -0
- package/dist/esm/engine/run-options.js +55 -0
- package/dist/esm/engine/run-options.js.map +1 -0
- package/dist/esm/engine/run.js +73 -0
- package/dist/esm/engine/run.js.map +1 -0
- package/dist/esm/engine/shared-usage.js +67 -0
- package/dist/esm/engine/shared-usage.js.map +1 -0
- package/dist/esm/engine/shared.js +14 -0
- package/dist/esm/engine/shared.js.map +1 -0
- package/dist/esm/engine/shutdown.js +55 -0
- package/dist/esm/engine/shutdown.js.map +1 -0
- package/dist/esm/engine/stats.js +89 -0
- package/dist/esm/engine/stats.js.map +1 -0
- package/dist/esm/engine/token-ledger.js +114 -0
- package/dist/esm/engine/token-ledger.js.map +1 -0
- package/dist/esm/engine/usage-report.js +86 -0
- package/dist/esm/engine/usage-report.js.map +1 -0
- package/dist/esm/engine/would-admit.js +34 -0
- package/dist/esm/engine/would-admit.js.map +1 -0
- package/dist/esm/errors.js +20 -0
- package/dist/esm/errors.js.map +1 -1
- package/dist/esm/index.js +10 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/types/bulkhead.d.ts +33 -6
- package/dist/types/bulkhead.d.ts.map +1 -1
- package/dist/types/engine/acquire.d.ts +25 -0
- package/dist/types/engine/acquire.d.ts.map +1 -0
- package/dist/types/engine/admission-counts.d.ts +30 -0
- package/dist/types/engine/admission-counts.d.ts.map +1 -0
- package/dist/types/engine/admission-request.d.ts +12 -0
- package/dist/types/engine/admission-request.d.ts.map +1 -0
- package/dist/types/engine/admitted-run.d.ts +19 -0
- package/dist/types/engine/admitted-run.d.ts.map +1 -0
- package/dist/types/engine/admitted-token.d.ts +42 -0
- package/dist/types/engine/admitted-token.d.ts.map +1 -0
- package/dist/types/engine/bypass.d.ts +17 -0
- package/dist/types/engine/bypass.d.ts.map +1 -0
- package/dist/types/engine/capacity.d.ts +36 -0
- package/dist/types/engine/capacity.d.ts.map +1 -0
- package/dist/types/engine/class-limits.d.ts +20 -0
- package/dist/types/engine/class-limits.d.ts.map +1 -0
- package/dist/types/engine/class-slots.d.ts +20 -0
- package/dist/types/engine/class-slots.d.ts.map +1 -0
- package/dist/types/engine/dedup-flow.d.ts +41 -0
- package/dist/types/engine/dedup-flow.d.ts.map +1 -0
- package/dist/types/engine/events.d.ts +13 -0
- package/dist/types/engine/events.d.ts.map +1 -0
- package/dist/types/engine/limits.d.ts +45 -0
- package/dist/types/engine/limits.d.ts.map +1 -0
- package/dist/types/engine/observe-stats.d.ts +14 -0
- package/dist/types/engine/observe-stats.d.ts.map +1 -0
- package/dist/types/engine/options.d.ts +21 -0
- package/dist/types/engine/options.d.ts.map +1 -0
- package/dist/types/engine/reject-detail.d.ts +25 -0
- package/dist/types/engine/reject-detail.d.ts.map +1 -0
- package/dist/types/engine/reservation.d.ts +13 -0
- package/dist/types/engine/reservation.d.ts.map +1 -0
- package/dist/types/engine/run-options.d.ts +25 -0
- package/dist/types/engine/run-options.d.ts.map +1 -0
- package/dist/types/engine/run.d.ts +28 -0
- package/dist/types/engine/run.d.ts.map +1 -0
- package/dist/types/engine/shared-usage.d.ts +28 -0
- package/dist/types/engine/shared-usage.d.ts.map +1 -0
- package/dist/types/engine/shared.d.ts +63 -0
- package/dist/types/engine/shared.d.ts.map +1 -0
- package/dist/types/engine/shutdown.d.ts +20 -0
- package/dist/types/engine/shutdown.d.ts.map +1 -0
- package/dist/types/engine/stats.d.ts +28 -0
- package/dist/types/engine/stats.d.ts.map +1 -0
- package/dist/types/engine/token-ledger.d.ts +40 -0
- package/dist/types/engine/token-ledger.d.ts.map +1 -0
- package/dist/types/engine/usage-report.d.ts +63 -0
- package/dist/types/engine/usage-report.d.ts.map +1 -0
- package/dist/types/engine/would-admit.d.ts +16 -0
- package/dist/types/engine/would-admit.d.ts.map +1 -0
- package/dist/types/errors.d.ts +15 -2
- package/dist/types/errors.d.ts.map +1 -1
- package/dist/types/index.d.ts +11 -3
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/types.d.ts +74 -1
- package/dist/types/types.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"class-limits.d.ts","sourceRoot":"","sources":["../../../src/engine/class-limits.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAG3D,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAK9E;AAED,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,OAAO,EACd,KAAK,EAAE,MAAM,EACb,kBAAkB,EAAE,OAAO,GAC1B,uBAAuB,CA6DzB;AAED,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,QAAQ,CAAC,uBAAuB,CAAC,EACzC,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,MAAM,GAAG,SAAS,EAC/B,KAAK,EAAE,MAAM,GACZ,IAAI,CAiBN;AAED;;;;;;GAMG;AACH,wBAAgB,8BAA8B,CAC5C,QAAQ,EAAE,OAAO,EACjB,QAAQ,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,EACvC,kBAAkB,EAAE,OAAO,GAC1B,GAAG,CAAC,MAAM,EAAE,uBAAuB,CAAC,GAAG,SAAS,CA4ClD"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Owner of the per-class concurrency slot counts.
|
|
3
|
+
*
|
|
4
|
+
* The global slot count is not kept here: it lives inside the concurrency
|
|
5
|
+
* gate (`createReconfigurableBulkhead`), which grants and takes back the
|
|
6
|
+
* slot itself. This module only records which class a granted slot belongs
|
|
7
|
+
* to. Nothing outside this file writes these counts; a class is always
|
|
8
|
+
* named by its id.
|
|
9
|
+
*/
|
|
10
|
+
export declare function createClassSlots(classIds: Iterable<string>): {
|
|
11
|
+
occupy: (classId: string | undefined, borrowed: boolean) => void;
|
|
12
|
+
vacate: (classId: string | undefined) => void;
|
|
13
|
+
/** Slots one class holds right now. */
|
|
14
|
+
inFlight: (classId: string) => number;
|
|
15
|
+
/** A live read of one class's held slots, without a lookup per read. */
|
|
16
|
+
reader: (classId: string) => (() => number);
|
|
17
|
+
totalBorrowedAdmissions: (classId: string) => number;
|
|
18
|
+
};
|
|
19
|
+
export type ClassSlots = ReturnType<typeof createClassSlots>;
|
|
20
|
+
//# sourceMappingURL=class-slots.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"class-slots.d.ts","sourceRoot":"","sources":["../../../src/engine/class-slots.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AASH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC;sBAUhC,MAAM,GAAG,SAAS,YAAY,OAAO,KAAG,IAAI;sBAQ5C,MAAM,GAAG,SAAS,KAAG,IAAI;IAShD,uCAAuC;wBACnB,MAAM,KAAG,MAAM;IACnC,wEAAwE;sBACtD,MAAM,KAAG,CAAC,MAAM,MAAM,CAAC;uCAIN,MAAM,KAAG,MAAM;EAGrD;AAED,MAAM,MAAM,UAAU,GAAG,UAAU,CAAC,OAAO,gBAAgB,CAAC,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-flight deduplication for `run()`: one caller leads a shared call and
|
|
3
|
+
* later identical callers follow it instead of asking for capacity.
|
|
4
|
+
*
|
|
5
|
+
* Owner of the in-flight map and of the `dedupHits` count; nothing
|
|
6
|
+
* outside this file touches either. The pure key and share-safety
|
|
7
|
+
* helpers live in `src/dedup.ts`.
|
|
8
|
+
*/
|
|
9
|
+
import type { AcquireOptions } from "async-bulkhead-ts";
|
|
10
|
+
import type { LLMBulkheadOptions, LLMRequest } from "../types.js";
|
|
11
|
+
import { LLMBulkheadRejectedError } from "../errors.js";
|
|
12
|
+
import type { AdmissionCounts } from "./admission-counts.js";
|
|
13
|
+
import type { EventHub } from "./events.js";
|
|
14
|
+
import type { Limits } from "./limits.js";
|
|
15
|
+
type Deps = {
|
|
16
|
+
options: LLMBulkheadOptions["deduplication"];
|
|
17
|
+
limits: Limits;
|
|
18
|
+
counts: AdmissionCounts;
|
|
19
|
+
events: EventHub;
|
|
20
|
+
};
|
|
21
|
+
export declare function createDedup(deps: Deps): {
|
|
22
|
+
keyFor: (request: LLMRequest, perCallDedup: boolean | undefined, dedupScope: string | undefined, classId: string | undefined) => string;
|
|
23
|
+
join: <T>(key: string, request: LLMRequest, classId: string | undefined) => Promise<T> | undefined;
|
|
24
|
+
follow: <T>(shared: Promise<T>, request: LLMRequest, ao: AcquireOptions, classId: string | undefined) => Promise<T>;
|
|
25
|
+
lead: <T>(key: string) => {
|
|
26
|
+
/** Followers settle with `work`; the leader gets the shared promise. */
|
|
27
|
+
publish(work: Promise<T>): Promise<T>;
|
|
28
|
+
/** The leader failed before it had work to publish. */
|
|
29
|
+
fail(err: unknown): Promise<T>;
|
|
30
|
+
};
|
|
31
|
+
/** True for errors raised because a follower's own wait ended early. */
|
|
32
|
+
isWaitRejection: (error: LLMBulkheadRejectedError) => boolean;
|
|
33
|
+
/** Detached counts; `undefined` when deduplication is disabled. */
|
|
34
|
+
stats: () => {
|
|
35
|
+
active: number;
|
|
36
|
+
hits: number;
|
|
37
|
+
} | undefined;
|
|
38
|
+
};
|
|
39
|
+
export type Dedup = ReturnType<typeof createDedup>;
|
|
40
|
+
export {};
|
|
41
|
+
//# sourceMappingURL=dedup-flow.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dedup-flow.d.ts","sourceRoot":"","sources":["../../../src/engine/dedup-flow.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,KAAK,EACV,kBAAkB,EAElB,UAAU,EACX,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AAExD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,kBAAkB,CAAC,eAAe,CAAC,CAAC;IAC7C,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,eAAe,CAAC;IACxB,MAAM,EAAE,QAAQ,CAAC;CAClB,CAAC;AAoGF,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI;sBA2DzB,UAAU,gBACL,OAAO,GAAG,SAAS,cACrB,MAAM,GAAG,SAAS,WACrB,MAAM,GAAG,SAAS,KAC1B,MAAM;WAsBK,CAAC,OACR,MAAM,WACF,UAAU,WACV,MAAM,GAAG,SAAS,KAC1B,OAAO,CAAC,CAAC,CAAC,GAAG,SAAS;aAYT,CAAC,UACP,OAAO,CAAC,CAAC,CAAC,WACT,UAAU,MACf,cAAc,WACT,MAAM,GAAG,SAAS,KAC1B,OAAO,CAAC,CAAC,CAAC;WAUC,CAAC,OAAO,MAAM;QAexB,wEAAwE;sBAC1D,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;QAOrC,uDAAuD;kBAC7C,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC;;IAYhC,wEAAwE;6BAC/C,wBAAwB,KAAG,OAAO;IAE3D,mEAAmE;iBACxD;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS;EAG1D;AAED,MAAM,MAAM,KAAK,GAAG,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lifecycle event listeners: registration and synchronous delivery.
|
|
3
|
+
*
|
|
4
|
+
* Listeners run inside the bulkhead's own control flow, so an exception
|
|
5
|
+
* from one must never reach the caller that triggered the event.
|
|
6
|
+
*/
|
|
7
|
+
import type { Listener, LLMEventMap, LLMEventType } from "../types.js";
|
|
8
|
+
export declare function createEventHub(): {
|
|
9
|
+
emit: <K extends LLMEventType>(event: K, payload: LLMEventMap[K]) => void;
|
|
10
|
+
on: <K extends LLMEventType>(event: K, listener: Listener<K>) => () => void;
|
|
11
|
+
};
|
|
12
|
+
export type EventHub = ReturnType<typeof createEventHub>;
|
|
13
|
+
//# sourceMappingURL=events.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../../src/engine/events.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEvE,wBAAgB,cAAc;WAcd,CAAC,SAAS,YAAY,SAC3B,CAAC,WACC,WAAW,CAAC,CAAC,CAAC,KACtB,IAAI;SAUK,CAAC,SAAS,YAAY,SACzB,CAAC,YACE,QAAQ,CAAC,CAAC,CAAC,KACpB,MAAM,IAAI;EAQd;AAED,MAAM,MAAM,QAAQ,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Owner of the admission limits that change at runtime: the limit
|
|
3
|
+
* revision, the token budget, the high-priority reserve, and each class's
|
|
4
|
+
* floors and ceilings.
|
|
5
|
+
*
|
|
6
|
+
* The two concurrency ceilings (`maxConcurrent`, `maxQueue`) live in the
|
|
7
|
+
* concurrency gate; this module installs them there as the last step of
|
|
8
|
+
* one synchronous update. Nothing outside this file writes a limit.
|
|
9
|
+
*/
|
|
10
|
+
import type { LLMAdmissionClassLimits, LLMAdmissionLimits, LLMApplyLimitsResult, LLMPriority, TokenBudgetOptions } from "../types.js";
|
|
11
|
+
import type { EventHub } from "./events.js";
|
|
12
|
+
import type { ResolvedOptions } from "./options.js";
|
|
13
|
+
import type { ConcurrencyGate } from "./shared.js";
|
|
14
|
+
/** One class's limits with the protected floors defaulted to 0. */
|
|
15
|
+
export type ClassLimits = {
|
|
16
|
+
protectedConcurrent: number;
|
|
17
|
+
maxConcurrent: number | undefined;
|
|
18
|
+
protectedInFlightTokens: number;
|
|
19
|
+
maxInFlightTokens: number | undefined;
|
|
20
|
+
};
|
|
21
|
+
export declare function createLimits(config: ResolvedOptions,
|
|
22
|
+
/** `tokenBudget` as supplied. Token accounting is on when it is set. */
|
|
23
|
+
budget: TokenBudgetOptions | undefined, concurrency: ConcurrencyGate, events: EventHub): {
|
|
24
|
+
/** Class used when a call omits `admissionClass`. */
|
|
25
|
+
defaultClass: string | undefined;
|
|
26
|
+
/** The fixed class table, in construction order. */
|
|
27
|
+
classIds: readonly string[];
|
|
28
|
+
/** Read-only view of one class's current limits. */
|
|
29
|
+
classLimit: (id: string) => Readonly<ClassLimits>;
|
|
30
|
+
/** One class's limits in their public shape. */
|
|
31
|
+
publicClassLimit: (id: string) => LLMAdmissionClassLimits;
|
|
32
|
+
revision: () => number;
|
|
33
|
+
/** Current budget ceiling; `undefined` when no token budget is configured. */
|
|
34
|
+
budget: () => number | undefined;
|
|
35
|
+
highPriorityReserve: () => number;
|
|
36
|
+
effectiveBudget: (priority: LLMPriority) => number;
|
|
37
|
+
protectedConcurrentTotal: () => number;
|
|
38
|
+
protectedTokensTotal: () => number;
|
|
39
|
+
resolveClass: (requested: string | undefined) => string | undefined;
|
|
40
|
+
snapshot: () => LLMAdmissionLimits;
|
|
41
|
+
apply: (next: LLMAdmissionLimits) => LLMApplyLimitsResult;
|
|
42
|
+
setBudget: (tokens: number) => void;
|
|
43
|
+
};
|
|
44
|
+
export type Limits = ReturnType<typeof createLimits>;
|
|
45
|
+
//# sourceMappingURL=limits.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"limits.d.ts","sourceRoot":"","sources":["../../../src/engine/limits.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EACV,uBAAuB,EACvB,kBAAkB,EAClB,oBAAoB,EACpB,WAAW,EACX,kBAAkB,EACnB,MAAM,aAAa,CAAC;AAOrB,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD,mEAAmE;AACnE,MAAM,MAAM,WAAW,GAAG;IACxB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,aAAa,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,uBAAuB,EAAE,MAAM,CAAC;IAChC,iBAAiB,EAAE,MAAM,GAAG,SAAS,CAAC;CACvC,CAAC;AAuNF,wBAAgB,YAAY,CAC1B,MAAM,EAAE,eAAe;AACvB,wEAAwE;AACxE,MAAM,EAAE,kBAAkB,GAAG,SAAS,EACtC,WAAW,EAAE,eAAe,EAC5B,MAAM,EAAE,QAAQ;IAkJd,qDAAqD;;IAErD,oDAAoD;;IAEpD,oDAAoD;qBAtK1C,MAAM,KAAG,QAAQ,CAAC,WAAW,CAAC;IAwKxC,gDAAgD;2BAvK9B,MAAM,KAAG,uBAAuB;oBAyKpC,MAAM;IACpB,8EAA8E;kBAClE,MAAM,GAAG,SAAS;+BACL,MAAM;gCA3HE,WAAW,KAAG,MAAM;oCAxHlB,MAAM;gCAQV,MAAM;8BAaX,MAAM,GAAG,SAAS,KAAG,MAAM,GAAG,SAAS;oBA2G9C,kBAAkB;kBAkClB,kBAAkB,KAAG,oBAAoB;wBA4CnC,MAAM,KAAG,IAAI;EA8CzC;AAED,MAAM,MAAM,MAAM,GAAG,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Owner of the observe-mode counters: how many callbacks ran without
|
|
3
|
+
* holding capacity, why, and the usage they reported. Bypassed work never
|
|
4
|
+
* touches the token, slot or admission counts, so these stand alone.
|
|
5
|
+
* Nothing outside this file writes them.
|
|
6
|
+
*/
|
|
7
|
+
import type { LLMObserveStats, LLMShadowableRejectReason, TokenUsage } from "../types.js";
|
|
8
|
+
export declare function createObserveStats(): {
|
|
9
|
+
noteBypass: (reason: LLMShadowableRejectReason, raced: boolean) => void;
|
|
10
|
+
noteUsage: (usage: TokenUsage) => void;
|
|
11
|
+
snapshot: () => LLMObserveStats | undefined;
|
|
12
|
+
};
|
|
13
|
+
export type ObserveStats = ReturnType<typeof createObserveStats>;
|
|
14
|
+
//# sourceMappingURL=observe-stats.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"observe-stats.d.ts","sourceRoot":"","sources":["../../../src/engine/observe-stats.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EACV,eAAe,EACf,yBAAyB,EACzB,UAAU,EACX,MAAM,aAAa,CAAC;AAErB,wBAAgB,kBAAkB;yBAcJ,yBAAyB,SAAS,OAAO,KAAG,IAAI;uBAQlD,UAAU,KAAG,IAAI;oBAOtB,eAAe,GAAG,SAAS;EAajD;AAED,MAAM,MAAM,YAAY,GAAG,UAAU,CAAC,OAAO,kBAAkB,CAAC,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Construction-time option validation and resolution for
|
|
3
|
+
* `createLLMBulkhead`.
|
|
4
|
+
*
|
|
5
|
+
* Runs once, before any engine part exists, and throws on the first
|
|
6
|
+
* invalid option. The order of the checks decides which error a caller
|
|
7
|
+
* sees when several options are wrong, so it is part of the behavior.
|
|
8
|
+
*/
|
|
9
|
+
import type { LLMAdmissionClassLimits, LLMBulkheadOptions } from "../types.js";
|
|
10
|
+
export type ResolvedOptions = {
|
|
11
|
+
readonly maxQueue: number;
|
|
12
|
+
/** Bulkhead-level queue-wait timeout, applied when a call passes none. */
|
|
13
|
+
readonly timeoutMs: number | undefined;
|
|
14
|
+
readonly initialRevision: number;
|
|
15
|
+
/** Class used when a call omits `admissionClass`. */
|
|
16
|
+
readonly defaultClass: string | undefined;
|
|
17
|
+
/** The fixed class table in construction order; empty without classes. */
|
|
18
|
+
readonly classLimits: ReadonlyMap<string, LLMAdmissionClassLimits>;
|
|
19
|
+
};
|
|
20
|
+
export declare function resolveOptions(opts: LLMBulkheadOptions): ResolvedOptions;
|
|
21
|
+
//# sourceMappingURL=options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../../src/engine/options.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EACV,uBAAuB,EACvB,kBAAkB,EACnB,MAAM,aAAa,CAAC;AAYrB,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,0EAA0E;IAC1E,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IACvC,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,qDAAqD;IACrD,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1C,0EAA0E;IAC1E,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC,MAAM,EAAE,uBAAuB,CAAC,CAAC;CACpE,CAAC;AAiFF,wBAAgB,cAAc,CAAC,IAAI,EAAE,kBAAkB,GAAG,eAAe,CA6BxE"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The capacity snapshot attached to rejection results, events and errors,
|
|
3
|
+
* and to `wouldAdmit({ detail: true })`.
|
|
4
|
+
*
|
|
5
|
+
* Read-only: it describes the capacity a decision was made against and
|
|
6
|
+
* never takes part in the decision itself.
|
|
7
|
+
*/
|
|
8
|
+
import type { LLMCapacityConstraint, LLMPriority, LLMRejectDetail } from "../types.js";
|
|
9
|
+
import type { ClassSlots } from "./class-slots.js";
|
|
10
|
+
import type { Limits } from "./limits.js";
|
|
11
|
+
import type { ConcurrencyGate } from "./shared.js";
|
|
12
|
+
import type { SharedUsage } from "./shared-usage.js";
|
|
13
|
+
import type { TokenLedger } from "./token-ledger.js";
|
|
14
|
+
type Deps = {
|
|
15
|
+
budgetEnabled: boolean;
|
|
16
|
+
concurrency: ConcurrencyGate;
|
|
17
|
+
limits: Limits;
|
|
18
|
+
ledger: TokenLedger;
|
|
19
|
+
slots: ClassSlots;
|
|
20
|
+
usage: SharedUsage;
|
|
21
|
+
};
|
|
22
|
+
export declare function createRejectDetail(deps: Deps): (requested: number, priority: LLMPriority, classId: string | undefined, constraint?: LLMCapacityConstraint) => LLMRejectDetail;
|
|
23
|
+
export type BuildRejectDetail = ReturnType<typeof createRejectDetail>;
|
|
24
|
+
export {};
|
|
25
|
+
//# sourceMappingURL=reject-detail.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reject-detail.d.ts","sourceRoot":"","sources":["../../../src/engine/reject-detail.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EACV,qBAAqB,EACrB,WAAW,EACX,eAAe,EAChB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD,KAAK,IAAI,GAAG;IACV,aAAa,EAAE,OAAO,CAAC;IACvB,WAAW,EAAE,eAAe,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,WAAW,CAAC;IACpB,KAAK,EAAE,UAAU,CAAC;IAClB,KAAK,EAAE,WAAW,CAAC;CACpB,CAAC;AAgHF,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,IAAI,IAGzC,WAAW,MAAM,EACjB,UAAU,WAAW,EACrB,SAAS,MAAM,GAAG,SAAS,EAC3B,aAAa,qBAAqB,KACjC,eAAe,CAoCnB;AAED,MAAM,MAAM,iBAAiB,GAAG,UAAU,CAAC,OAAO,kBAAkB,CAAC,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Token reservation for one request: what admission will hold against the
|
|
3
|
+
* budget. The value comes from the caller's per-call override when one is
|
|
4
|
+
* given, otherwise from the configured estimator.
|
|
5
|
+
*/
|
|
6
|
+
import type { LLMBulkheadOptions, LLMRequest, LLMReservationEstimate, LLMReservationOverride, TokenBudgetOptions } from "../types.js";
|
|
7
|
+
import type { ReservationParts } from "./shared.js";
|
|
8
|
+
export declare function createReservations(budget: TokenBudgetOptions | undefined, opts: Pick<LLMBulkheadOptions, "model">): {
|
|
9
|
+
resolve: (request: LLMRequest, override: LLMReservationOverride | undefined) => ReservationParts | null;
|
|
10
|
+
estimate: (request: LLMRequest) => LLMReservationEstimate | null;
|
|
11
|
+
};
|
|
12
|
+
export type Reservations = ReturnType<typeof createReservations>;
|
|
13
|
+
//# sourceMappingURL=reservation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reservation.d.ts","sourceRoot":"","sources":["../../../src/engine/reservation.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EACV,kBAAkB,EAClB,UAAU,EACV,sBAAsB,EACtB,sBAAsB,EACtB,kBAAkB,EACnB,MAAM,aAAa,CAAC;AAOrB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpD,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,kBAAkB,GAAG,SAAS,EACtC,IAAI,EAAE,IAAI,CAAC,kBAAkB,EAAE,OAAO,CAAC;uBAiB5B,UAAU,YACT,sBAAsB,GAAG,SAAS,KAC3C,gBAAgB,GAAG,IAAI;wBAgCC,UAAU,KAAG,sBAAsB,GAAG,IAAI;EAMtE;AAED,MAAM,MAAM,YAAY,GAAG,UAAU,CAAC,OAAO,kBAAkB,CAAC,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reading the options of one `run()` call: what belongs to `run()` itself
|
|
3
|
+
* (usage extraction, observe mode, deduplication, the borrowed-slot
|
|
4
|
+
* deadline) and what is passed on to admission. Invalid values throw.
|
|
5
|
+
*/
|
|
6
|
+
import type { LLMAdmissionMode, LLMRejectReason, LLMRunOptions, LLMShadowableRejectReason } from "../types.js";
|
|
7
|
+
/** May observe mode turn a rejection for this reason into a bypass? */
|
|
8
|
+
export declare function shouldBypass(reason: LLMRejectReason, configured: ReadonlySet<LLMShadowableRejectReason>): reason is LLMShadowableRejectReason;
|
|
9
|
+
export declare function readRunOptions<T>(ao: LLMRunOptions<T>): {
|
|
10
|
+
getUsage: ((result: T) => import("../types.js").TokenUsage | undefined) | undefined;
|
|
11
|
+
mode: LLMAdmissionMode;
|
|
12
|
+
shadowReasons: ReadonlySet<LLMShadowableRejectReason>;
|
|
13
|
+
dedupScope: string | undefined;
|
|
14
|
+
perCallDedup: boolean | undefined;
|
|
15
|
+
borrowedConcurrencyDeadlineMs: number | undefined;
|
|
16
|
+
/** Everything else: the options admission itself understands. */
|
|
17
|
+
acquireOpts: {
|
|
18
|
+
signal?: AbortSignal;
|
|
19
|
+
timeoutMs?: number;
|
|
20
|
+
priority?: import("../types.js").LLMPriority;
|
|
21
|
+
admissionClass?: string;
|
|
22
|
+
reservation?: import("../types.js").LLMReservationOverride;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=run-options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-options.d.ts","sourceRoot":"","sources":["../../../src/engine/run-options.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,EACf,aAAa,EACb,yBAAyB,EAC1B,MAAM,aAAa,CAAC;AAwCrB,uEAAuE;AACvE,wBAAgB,YAAY,CAC1B,MAAM,EAAE,eAAe,EACvB,UAAU,EAAE,WAAW,CAAC,yBAAyB,CAAC,GACjD,MAAM,IAAI,yBAAyB,CAKrC;AAED,wBAAgB,cAAc,CAAC,CAAC,EAAE,EAAE,EAAE,aAAa,CAAC,CAAC,CAAC;;;;;;;IA6BlD,iEAAiE;;;;;;;;EAGpE"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `run()`: the order in which one call meets deduplication, observe mode,
|
|
3
|
+
* admission and execution. Each of those lives in its own module; this
|
|
4
|
+
* file only decides which one a call goes to next.
|
|
5
|
+
*
|
|
6
|
+
* The two `await`s here (following a shared call, and admission) are the
|
|
7
|
+
* only points where `run()` itself yields. The helpers it calls either
|
|
8
|
+
* finish synchronously or hand back a promise that is returned as is.
|
|
9
|
+
*/
|
|
10
|
+
import type { LLMRequest, LLMRunContext, LLMRunOptions } from "../types.js";
|
|
11
|
+
import type { Acquire } from "./acquire.js";
|
|
12
|
+
import type { ResolveAdmission } from "./admission-request.js";
|
|
13
|
+
import type { RunBypassed } from "./bypass.js";
|
|
14
|
+
import type { Dedup } from "./dedup-flow.js";
|
|
15
|
+
import type { Limits } from "./limits.js";
|
|
16
|
+
import type { BulkheadSignal } from "./shared.js";
|
|
17
|
+
import type { WouldAdmitResolved } from "./would-admit.js";
|
|
18
|
+
type Deps = {
|
|
19
|
+
limits: Limits;
|
|
20
|
+
dedup: Dedup;
|
|
21
|
+
resolveAdmission: ResolveAdmission;
|
|
22
|
+
wouldAdmitResolved: WouldAdmitResolved;
|
|
23
|
+
acquire: Acquire;
|
|
24
|
+
runBypassed: RunBypassed;
|
|
25
|
+
};
|
|
26
|
+
export declare function createRun(deps: Deps): <T>(request: LLMRequest, fn: (signal?: BulkheadSignal, ctx?: LLMRunContext) => Promise<T>, ao?: LLMRunOptions<T>) => Promise<T>;
|
|
27
|
+
export {};
|
|
28
|
+
//# sourceMappingURL=run.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../../src/engine/run.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EACV,UAAU,EACV,aAAa,EACb,aAAa,EAGd,MAAM,aAAa,CAAC;AAErB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE/D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,KAAK,EAAE,cAAc,EAAqB,MAAM,aAAa,CAAC;AACrE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAE3D,KAAK,IAAI,GAAG;IACV,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,KAAK,CAAC;IACb,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,kBAAkB,EAAE,kBAAkB,CAAC;IACvC,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE,WAAW,CAAC;CAC1B,CAAC;AAaF,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,IAIR,CAAC,EACzB,SAAS,UAAU,EACnB,IAAI,CAAC,MAAM,CAAC,EAAE,cAAc,EAAE,GAAG,CAAC,EAAE,aAAa,KAAK,OAAO,CAAC,CAAC,CAAC,EAChE,KAAI,aAAa,CAAC,CAAC,CAAM,KACxB,OAAO,CAAC,CAAC,CAAC,CA0Hd"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Protected versus shared usage: how much of what a class holds sits
|
|
3
|
+
* inside its own floor, how much is borrowed from the shared remainder,
|
|
4
|
+
* and what one more call would have to borrow.
|
|
5
|
+
*
|
|
6
|
+
* Read-only. Every number is read live from its owner (limits, token
|
|
7
|
+
* ledger, class slots, concurrency gate); no value is cached here.
|
|
8
|
+
*/
|
|
9
|
+
import type { ClassSlots } from "./class-slots.js";
|
|
10
|
+
import type { Limits } from "./limits.js";
|
|
11
|
+
import type { ConcurrencyGate } from "./shared.js";
|
|
12
|
+
import type { TokenLedger } from "./token-ledger.js";
|
|
13
|
+
export declare function createSharedUsage(deps: {
|
|
14
|
+
concurrency: ConcurrencyGate;
|
|
15
|
+
limits: Limits;
|
|
16
|
+
ledger: TokenLedger;
|
|
17
|
+
slots: ClassSlots;
|
|
18
|
+
}): {
|
|
19
|
+
protectedConcurrentInUse: (classId: string) => number;
|
|
20
|
+
protectedTokensInUse: (classId: string) => number;
|
|
21
|
+
protectedConcurrentInUseTotal: () => number;
|
|
22
|
+
sharedConcurrentInUse: () => number;
|
|
23
|
+
sharedTokensInUse: () => number;
|
|
24
|
+
requestedBorrowedConcurrent: (classId: string | undefined) => number;
|
|
25
|
+
requestedBorrowedTokens: (classId: string | undefined, reserved: number) => number;
|
|
26
|
+
};
|
|
27
|
+
export type SharedUsage = ReturnType<typeof createSharedUsage>;
|
|
28
|
+
//# sourceMappingURL=shared-usage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared-usage.d.ts","sourceRoot":"","sources":["../../../src/engine/shared-usage.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAe,MAAM,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAYrD,wBAAgB,iBAAiB,CAAC,IAAI,EAAE;IACtC,WAAW,EAAE,eAAe,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,WAAW,CAAC;IACpB,KAAK,EAAE,UAAU,CAAC;CACnB;wCAgB4C,MAAM,KAAG,MAAM;oCAMnB,MAAM,KAAG,MAAM;yCAMZ,MAAM;iCAQd,MAAM;6BAOV,MAAM;2CAYU,MAAM,GAAG,SAAS,KAAG,MAAM;uCAQ9D,MAAM,GAAG,SAAS,YACjB,MAAM,KACf,MAAM;EAmBV;AAED,MAAM,MAAM,WAAW,GAAG,UAAU,CAAC,OAAO,iBAAiB,CAAC,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal types and constants shared by the engine modules.
|
|
3
|
+
*
|
|
4
|
+
* Nothing under `src/engine` is part of the public API: the package entry
|
|
5
|
+
* point re-exports only what `src/index.ts` lists.
|
|
6
|
+
*/
|
|
7
|
+
import type { AcquireOptions } from "async-bulkhead-ts";
|
|
8
|
+
import type { createReconfigurableBulkhead } from "../reconfigurable-bulkhead.js";
|
|
9
|
+
import type { LLMAcquireResult, LLMAdmissionResources, LLMBorrowedConcurrencyAbandonCause, LLMCapacityConstraint, LLMPriority, LLMRejectReason, LLMReservationEstimate, LLMToken } from "../types.js";
|
|
10
|
+
/** Abort signal accepted by the underlying concurrency acquire. */
|
|
11
|
+
export type BulkheadSignal = NonNullable<AcquireOptions["signal"]>;
|
|
12
|
+
/**
|
|
13
|
+
* The reconfigurable concurrency gate. It owns the global slot count and
|
|
14
|
+
* the queue; the engine reads both through `stats()` and never mirrors
|
|
15
|
+
* them.
|
|
16
|
+
*/
|
|
17
|
+
export type ConcurrencyGate = ReturnType<typeof createReconfigurableBulkhead>;
|
|
18
|
+
/** Estimate parts kept per-token so streaming reports can re-derive holds. */
|
|
19
|
+
export type ReservationParts = LLMReservationEstimate;
|
|
20
|
+
/**
|
|
21
|
+
* What one call asks for, after its options are resolved.
|
|
22
|
+
*
|
|
23
|
+
* An admission class always travels as its id. The numbers that belong to
|
|
24
|
+
* a class stay with the engine part that owns them.
|
|
25
|
+
*/
|
|
26
|
+
export type ResolvedAdmission = {
|
|
27
|
+
priority: LLMPriority;
|
|
28
|
+
admissionClass: string | undefined;
|
|
29
|
+
parts: ReservationParts | null;
|
|
30
|
+
reserved: number;
|
|
31
|
+
};
|
|
32
|
+
export type CapacityFailure = {
|
|
33
|
+
reason: Extract<LLMRejectReason, "budget_limit" | "concurrency_limit">;
|
|
34
|
+
constraint: LLMCapacityConstraint;
|
|
35
|
+
};
|
|
36
|
+
export type CapacityReservationResult = {
|
|
37
|
+
readonly ok: false;
|
|
38
|
+
readonly failure: CapacityFailure;
|
|
39
|
+
} | {
|
|
40
|
+
readonly ok: true;
|
|
41
|
+
readonly resources: LLMAdmissionResources;
|
|
42
|
+
};
|
|
43
|
+
export declare const NO_ADMISSION_RESOURCES: LLMAdmissionResources;
|
|
44
|
+
/**
|
|
45
|
+
* Internal view of a wrapped token. `run()` must attribute a lease expiry
|
|
46
|
+
* distinctly from an application's own abandonment without widening the
|
|
47
|
+
* public `LLMToken` surface, where a caller-supplied cause would be
|
|
48
|
+
* unverifiable telemetry. The key is an engine-private symbol, never
|
|
49
|
+
* exported from the package entry point, so the capability is unreachable
|
|
50
|
+
* from a published token.
|
|
51
|
+
*/
|
|
52
|
+
export declare const ABANDON_WITH_CAUSE: unique symbol;
|
|
53
|
+
export type WrappedLLMToken = LLMToken & {
|
|
54
|
+
[ABANDON_WITH_CAUSE](cause: LLMBorrowedConcurrencyAbandonCause): boolean;
|
|
55
|
+
};
|
|
56
|
+
export type InternalAcquireResult = (Extract<LLMAcquireResult, {
|
|
57
|
+
ok: true;
|
|
58
|
+
}> & {
|
|
59
|
+
token: WrappedLLMToken;
|
|
60
|
+
}) | Extract<LLMAcquireResult, {
|
|
61
|
+
ok: false;
|
|
62
|
+
}>;
|
|
63
|
+
//# sourceMappingURL=shared.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../../src/engine/shared.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,+BAA+B,CAAC;AAClF,OAAO,KAAK,EACV,gBAAgB,EAChB,qBAAqB,EACrB,kCAAkC,EAClC,qBAAqB,EACrB,WAAW,EACX,eAAe,EACf,sBAAsB,EACtB,QAAQ,EACT,MAAM,aAAa,CAAC;AAErB,mEAAmE;AACnE,MAAM,MAAM,cAAc,GAAG,WAAW,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,CAAC;AAEnE;;;;GAIG;AACH,MAAM,MAAM,eAAe,GAAG,UAAU,CAAC,OAAO,4BAA4B,CAAC,CAAC;AAE9E,8EAA8E;AAC9E,MAAM,MAAM,gBAAgB,GAAG,sBAAsB,CAAC;AAEtD;;;;;GAKG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,EAAE,WAAW,CAAC;IACtB,cAAc,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC,KAAK,EAAE,gBAAgB,GAAG,IAAI,CAAC;IAC/B,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,MAAM,EAAE,OAAO,CAAC,eAAe,EAAE,cAAc,GAAG,mBAAmB,CAAC,CAAC;IACvE,UAAU,EAAE,qBAAqB,CAAC;CACnC,CAAC;AAEF,MAAM,MAAM,yBAAyB,GACjC;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAA;CAAE,GACzD;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,SAAS,EAAE,qBAAqB,CAAA;CAAE,CAAC;AAErE,eAAO,MAAM,sBAAsB,EAAE,qBAGnC,CAAC;AAEH;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,eAAgD,CAAC;AAEhF,MAAM,MAAM,eAAe,GAAG,QAAQ,GAAG;IACvC,CAAC,kBAAkB,CAAC,CAAC,KAAK,EAAE,kCAAkC,GAAG,OAAO,CAAC;CAC1E,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAC7B,CAAC,OAAO,CAAC,gBAAgB,EAAE;IAAE,EAAE,EAAE,IAAI,CAAA;CAAE,CAAC,GAAG;IAAE,KAAK,EAAE,eAAe,CAAA;CAAE,CAAC,GACtE,OAAO,CAAC,gBAAgB,EAAE;IAAE,EAAE,EAAE,KAAK,CAAA;CAAE,CAAC,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shutdown: closing admission and waiting for work to finish.
|
|
3
|
+
*
|
|
4
|
+
* `drain()` waits for two things: the concurrency gate to empty, and every
|
|
5
|
+
* admitted call to reach final settlement. The second matters because a
|
|
6
|
+
* call that abandoned its borrowed slot no longer holds one, yet still
|
|
7
|
+
* holds tokens until it releases.
|
|
8
|
+
*/
|
|
9
|
+
import type { LLMDrainResult } from "../types.js";
|
|
10
|
+
import type { AdmissionCounts } from "./admission-counts.js";
|
|
11
|
+
import type { ConcurrencyGate } from "./shared.js";
|
|
12
|
+
export declare function createShutdown(concurrency: ConcurrencyGate, counts: AdmissionCounts): {
|
|
13
|
+
settleDrainWaiters: () => void;
|
|
14
|
+
close: () => void;
|
|
15
|
+
drain: (opts?: {
|
|
16
|
+
timeoutMs?: number;
|
|
17
|
+
}) => Promise<void> | Promise<LLMDrainResult>;
|
|
18
|
+
};
|
|
19
|
+
export type Shutdown = ReturnType<typeof createShutdown>;
|
|
20
|
+
//# sourceMappingURL=shutdown.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shutdown.d.ts","sourceRoot":"","sources":["../../../src/engine/shutdown.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD,wBAAgB,cAAc,CAC5B,WAAW,EAAE,eAAe,EAC5B,MAAM,EAAE,eAAe;8BAKQ,IAAI;iBAajB,IAAI;mBAIA;QACpB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,KAAG,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,cAAc,CAAC;EA+B5C;AAED,MAAM,MAAM,QAAQ,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `stats()`: one detached snapshot assembled from every owner. Read-only;
|
|
3
|
+
* each section is a copy, so a caller cannot reach engine state through
|
|
4
|
+
* the result.
|
|
5
|
+
*/
|
|
6
|
+
import type { LLMStats } from "../types.js";
|
|
7
|
+
import type { AdmissionCounts } from "./admission-counts.js";
|
|
8
|
+
import type { ClassSlots } from "./class-slots.js";
|
|
9
|
+
import type { Dedup } from "./dedup-flow.js";
|
|
10
|
+
import type { Limits } from "./limits.js";
|
|
11
|
+
import type { ObserveStats } from "./observe-stats.js";
|
|
12
|
+
import type { ConcurrencyGate } from "./shared.js";
|
|
13
|
+
import type { SharedUsage } from "./shared-usage.js";
|
|
14
|
+
import type { TokenLedger } from "./token-ledger.js";
|
|
15
|
+
type Deps = {
|
|
16
|
+
budgetEnabled: boolean;
|
|
17
|
+
concurrency: ConcurrencyGate;
|
|
18
|
+
limits: Limits;
|
|
19
|
+
ledger: TokenLedger;
|
|
20
|
+
slots: ClassSlots;
|
|
21
|
+
counts: AdmissionCounts;
|
|
22
|
+
usage: SharedUsage;
|
|
23
|
+
observeStats: ObserveStats;
|
|
24
|
+
dedup: Dedup;
|
|
25
|
+
};
|
|
26
|
+
export declare function createStats(deps: Deps): () => LLMStats;
|
|
27
|
+
export {};
|
|
28
|
+
//# sourceMappingURL=stats.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stats.d.ts","sourceRoot":"","sources":["../../../src/engine/stats.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAGV,QAAQ,EACT,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD,KAAK,IAAI,GAAG;IACV,aAAa,EAAE,OAAO,CAAC;IACvB,WAAW,EAAE,eAAe,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,WAAW,CAAC;IACpB,KAAK,EAAE,UAAU,CAAC;IAClB,MAAM,EAAE,eAAe,CAAC;IACxB,KAAK,EAAE,WAAW,CAAC;IACnB,YAAY,EAAE,YAAY,CAAC;IAC3B,KAAK,EAAE,KAAK,CAAC;CACd,CAAC;AAuEF,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,SAIX,QAAQ,CAwClC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Owner of the token counters: tokens held in flight and the cumulative
|
|
3
|
+
* reserved, consumed, refunded and overrun totals.
|
|
4
|
+
*
|
|
5
|
+
* Every counter exists once for the whole pool and once per admission
|
|
6
|
+
* class. Each function below moves a pool counter and the same counter of
|
|
7
|
+
* the class the call belongs to, so the two can never drift apart. Nothing
|
|
8
|
+
* outside this file writes them; a class is always named by its id.
|
|
9
|
+
*/
|
|
10
|
+
import type { TokenUsage } from "../types.js";
|
|
11
|
+
type TokenCounters = {
|
|
12
|
+
inFlightTokens: number;
|
|
13
|
+
totalReserved: number;
|
|
14
|
+
totalConsumed: number;
|
|
15
|
+
totalRefunded: number;
|
|
16
|
+
totalOverrun: number;
|
|
17
|
+
};
|
|
18
|
+
type ClassTokenCounters = TokenCounters & {
|
|
19
|
+
/** Reservation tokens placed in shared capacity at admission time. */
|
|
20
|
+
totalBorrowedTokensReserved: number;
|
|
21
|
+
};
|
|
22
|
+
export declare function createTokenLedger(budgetEnabled: boolean, classIds: Iterable<string>): {
|
|
23
|
+
reserve: (classId: string | undefined, reserved: number, borrowedTokens: number) => void;
|
|
24
|
+
grow: (classId: string | undefined, delta: number) => void;
|
|
25
|
+
shrink: (classId: string | undefined, refund: number) => void;
|
|
26
|
+
settle: (classId: string | undefined, held: number, usage: TokenUsage | undefined) => number;
|
|
27
|
+
/** Tokens currently held across the whole pool. */
|
|
28
|
+
inFlight: () => number;
|
|
29
|
+
/** Tokens currently held by one class. */
|
|
30
|
+
classInFlight: (classId: string) => number;
|
|
31
|
+
/** A live read of one class's held tokens, without a lookup per read. */
|
|
32
|
+
classReader: (classId: string) => (() => number);
|
|
33
|
+
/** Detached copy of the pool counters. */
|
|
34
|
+
totals: () => TokenCounters;
|
|
35
|
+
/** Detached copy of one class's counters. */
|
|
36
|
+
classTotals: (classId: string) => ClassTokenCounters;
|
|
37
|
+
};
|
|
38
|
+
export type TokenLedger = ReturnType<typeof createTokenLedger>;
|
|
39
|
+
export {};
|
|
40
|
+
//# sourceMappingURL=token-ledger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token-ledger.d.ts","sourceRoot":"","sources":["../../../src/engine/token-ledger.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,KAAK,aAAa,GAAG;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,KAAK,kBAAkB,GAAG,aAAa,GAAG;IACxC,sEAAsE;IACtE,2BAA2B,EAAE,MAAM,CAAC;CACrC,CAAC;AAEF,wBAAgB,iBAAiB,CAC/B,aAAa,EAAE,OAAO,EACtB,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC;uBA8Bf,MAAM,GAAG,SAAS,YACjB,MAAM,kBACA,MAAM,KACrB,IAAI;oBAgBgB,MAAM,GAAG,SAAS,SAAS,MAAM,KAAG,IAAI;sBAWtC,MAAM,GAAG,SAAS,UAAU,MAAM,KAAG,IAAI;sBAevD,MAAM,GAAG,SAAS,QACrB,MAAM,SACL,UAAU,GAAG,SAAS,KAC5B,MAAM;IA6BP,mDAAmD;oBACrC,MAAM;IACpB,0CAA0C;6BACjB,MAAM,KAAG,MAAM;IAExC,yEAAyE;2BAClD,MAAM,KAAG,CAAC,MAAM,MAAM,CAAC;IAI9C,0CAA0C;kBAC9B,aAAa;IAOzB,6CAA6C;2BACtB,MAAM,KAAG,kBAAkB;EAIrD;AAED,MAAM,MAAM,WAAW,GAAG,UAAU,CAAC,OAAO,iBAAiB,CAAC,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Usage-report arithmetic shared by admitted and bypassed calls: checking
|
|
3
|
+
* a progressive reconciliation, keeping cumulative usage monotonic,
|
|
4
|
+
* working out the hold a report implies, and building the `UsageReport`
|
|
5
|
+
* snapshot. Everything here works on one call's own values.
|
|
6
|
+
*/
|
|
7
|
+
import type { ProgressiveReconciliationOptions, TokenUsage, UsageReport } from "../types.js";
|
|
8
|
+
import type { ReservationParts } from "./shared.js";
|
|
9
|
+
/**
|
|
10
|
+
* Holds one call's cumulative reported usage.
|
|
11
|
+
*
|
|
12
|
+
* The first report stores the caller's own usage object, so reading one of
|
|
13
|
+
* its fields can run caller code, which may report again on the same call.
|
|
14
|
+
* The functions below therefore read `cell.reported` afresh at every use
|
|
15
|
+
* and never keep a copy of it across a field read.
|
|
16
|
+
*/
|
|
17
|
+
export type UsageCell = {
|
|
18
|
+
reported: TokenUsage | undefined;
|
|
19
|
+
};
|
|
20
|
+
export declare function assertReconciliation(reconciliation: ProgressiveReconciliationOptions | undefined, parts: ReservationParts | null): void;
|
|
21
|
+
/**
|
|
22
|
+
* Clamp to monotonic non-decreasing per field — cumulative stream usage
|
|
23
|
+
* never shrinks; a lower report is stale.
|
|
24
|
+
*/
|
|
25
|
+
export declare function mergeUsage(previous: TokenUsage | undefined, valid: TokenUsage): TokenUsage;
|
|
26
|
+
/** Did the report just merged into the cell move either field? */
|
|
27
|
+
export declare function usageChanged(cell: UsageCell, previous: TokenUsage | undefined): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Tokens a call should hold after a usage report.
|
|
30
|
+
*
|
|
31
|
+
* Legacy mode holds known input plus the full output reservation.
|
|
32
|
+
* Progressive mode is opt-in and may be used only after prefill is
|
|
33
|
+
* known complete: it holds the caller-declared future output plus an
|
|
34
|
+
* explicit safety margin. Output beyond the configured cap is added
|
|
35
|
+
* back as overrun protection.
|
|
36
|
+
*/
|
|
37
|
+
export declare function holdAfterReport(parts: ReservationParts, cell: UsageCell, reconciliation: ProgressiveReconciliationOptions | undefined): number;
|
|
38
|
+
/** Event fields that mark a report as a progressive reconciliation. */
|
|
39
|
+
export declare function progressiveFields(reconciliation: ProgressiveReconciliationOptions | undefined): {
|
|
40
|
+
progressive?: true;
|
|
41
|
+
remainingOutputTokens?: number;
|
|
42
|
+
safetyMarginTokens?: number;
|
|
43
|
+
};
|
|
44
|
+
/** Cumulative tokens a call has reported so far. */
|
|
45
|
+
export declare function consumedTokens(cell: UsageCell): number;
|
|
46
|
+
/**
|
|
47
|
+
* Build the `UsageReport` for one call.
|
|
48
|
+
*
|
|
49
|
+
* The caller works out `consumed` (with `consumedTokens`) and `outputCap`
|
|
50
|
+
* first, and only then reads the call's `sequence` and `held`.
|
|
51
|
+
*/
|
|
52
|
+
export declare function usageSnapshot(call: {
|
|
53
|
+
admissionId: string;
|
|
54
|
+
limitRevision: number;
|
|
55
|
+
admissionClass: string | undefined;
|
|
56
|
+
parts: ReservationParts | null;
|
|
57
|
+
cell: UsageCell;
|
|
58
|
+
consumed: number;
|
|
59
|
+
outputCap: number | null;
|
|
60
|
+
sequence: number;
|
|
61
|
+
held: number;
|
|
62
|
+
}): UsageReport;
|
|
63
|
+
//# sourceMappingURL=usage-report.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usage-report.d.ts","sourceRoot":"","sources":["../../../src/engine/usage-report.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EACV,gCAAgC,EAChC,UAAU,EACV,WAAW,EACZ,MAAM,aAAa,CAAC;AAKrB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpD;;;;;;;GAOG;AACH,MAAM,MAAM,SAAS,GAAG;IAAE,QAAQ,EAAE,UAAU,GAAG,SAAS,CAAA;CAAE,CAAC;AAE7D,wBAAgB,oBAAoB,CAClC,cAAc,EAAE,gCAAgC,GAAG,SAAS,EAC5D,KAAK,EAAE,gBAAgB,GAAG,IAAI,GAC7B,IAAI,CAkBN;AAED;;;GAGG;AACH,wBAAgB,UAAU,CACxB,QAAQ,EAAE,UAAU,GAAG,SAAS,EAChC,KAAK,EAAE,UAAU,GAChB,UAAU,CAOZ;AAED,kEAAkE;AAClE,wBAAgB,YAAY,CAC1B,IAAI,EAAE,SAAS,EACf,QAAQ,EAAE,UAAU,GAAG,SAAS,GAC/B,OAAO,CAMT;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,gBAAgB,EACvB,IAAI,EAAE,SAAS,EACf,cAAc,EAAE,gCAAgC,GAAG,SAAS,GAC3D,MAAM,CAOR;AAED,uEAAuE;AACvE,wBAAgB,iBAAiB,CAC/B,cAAc,EAAE,gCAAgC,GAAG,SAAS,GAC3D;IACD,WAAW,CAAC,EAAE,IAAI,CAAC;IACnB,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B,CAQA;AAED,oDAAoD;AACpD,wBAAgB,cAAc,CAAC,IAAI,EAAE,SAAS,GAAG,MAAM,CAEtD;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE;IAClC,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC,KAAK,EAAE,gBAAgB,GAAG,IAAI,CAAC;IAC/B,IAAI,EAAE,SAAS,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;CACd,GAAG,WAAW,CAmBd"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The advisory dry run behind `wouldAdmit()` and observe mode: would this
|
|
3
|
+
* call be admitted right now? It reserves nothing and changes nothing, so
|
|
4
|
+
* the answer can be stale by the time a real `acquire()` lands.
|
|
5
|
+
*/
|
|
6
|
+
import type { LLMWouldAdmitResult } from "../types.js";
|
|
7
|
+
import type { Capacity } from "./capacity.js";
|
|
8
|
+
import type { BuildRejectDetail } from "./reject-detail.js";
|
|
9
|
+
import type { ConcurrencyGate, ResolvedAdmission } from "./shared.js";
|
|
10
|
+
export declare function createWouldAdmit(deps: {
|
|
11
|
+
concurrency: ConcurrencyGate;
|
|
12
|
+
capacity: Capacity;
|
|
13
|
+
buildRejectDetail: BuildRejectDetail;
|
|
14
|
+
}): (admission: ResolvedAdmission, includeDetail: boolean) => LLMWouldAdmitResult;
|
|
15
|
+
export type WouldAdmitResolved = ReturnType<typeof createWouldAdmit>;
|
|
16
|
+
//# sourceMappingURL=would-admit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"would-admit.d.ts","sourceRoot":"","sources":["../../../src/engine/would-admit.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAyB,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAC9E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,KAAK,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEtE,wBAAgB,gBAAgB,CAAC,IAAI,EAAE;IACrC,WAAW,EAAE,eAAe,CAAC;IAC7B,QAAQ,EAAE,QAAQ,CAAC;IACnB,iBAAiB,EAAE,iBAAiB,CAAC;CACtC,IAIG,WAAW,iBAAiB,EAC5B,eAAe,OAAO,KACrB,mBAAmB,CA+CvB;AAED,MAAM,MAAM,kBAAkB,GAAG,UAAU,CAAC,OAAO,gBAAgB,CAAC,CAAC"}
|
package/dist/types/errors.d.ts
CHANGED
|
@@ -1,9 +1,22 @@
|
|
|
1
|
-
/**
|
|
2
|
-
import type { LLMRejectDetail, LLMRejectReason } from "./types.js";
|
|
1
|
+
/** Typed errors returned by `run()` for admission rejection and lease expiry. */
|
|
2
|
+
import type { LLMAdmissionResources, LLMRejectDetail, LLMRejectReason } from "./types.js";
|
|
3
3
|
export declare class LLMBulkheadRejectedError extends Error {
|
|
4
4
|
readonly reason: LLMRejectReason;
|
|
5
5
|
readonly code: "LLM_BULKHEAD_REJECTED";
|
|
6
6
|
readonly detail: LLMRejectDetail | undefined;
|
|
7
7
|
constructor(reason: LLMRejectReason, detail?: LLMRejectDetail);
|
|
8
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* Returned by `run()` when an admitted borrowed concurrency slot reaches its
|
|
11
|
+
* wall-clock deadline. The local slot has been returned, but token accounting
|
|
12
|
+
* remains held until the underlying callback actually settles.
|
|
13
|
+
*/
|
|
14
|
+
export declare class LLMBorrowedConcurrencyDeadlineError extends Error {
|
|
15
|
+
readonly deadlineMs: number;
|
|
16
|
+
readonly admissionId: string;
|
|
17
|
+
readonly resources: LLMAdmissionResources;
|
|
18
|
+
readonly admissionClass?: string | undefined;
|
|
19
|
+
readonly code: "LLM_BORROWED_CONCURRENCY_DEADLINE";
|
|
20
|
+
constructor(deadlineMs: number, admissionId: string, resources: LLMAdmissionResources, admissionClass?: string | undefined);
|
|
21
|
+
}
|
|
9
22
|
//# sourceMappingURL=errors.d.ts.map
|