async-bulkhead-llm 3.17.0 → 3.18.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/CHANGELOG.md +181 -0
- package/README.md +46 -0
- package/dist/cjs/bulkhead.cjs +140 -1817
- 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 +111 -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 +143 -0
- package/dist/cjs/engine/admitted-run.cjs.map +1 -0
- package/dist/cjs/engine/admitted-token.cjs +283 -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 +36 -0
- package/dist/cjs/engine/events.cjs.map +1 -0
- package/dist/cjs/engine/limit-fit.cjs +108 -0
- package/dist/cjs/engine/limit-fit.cjs.map +1 -0
- package/dist/cjs/engine/limits.cjs +334 -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/running-calls.cjs +79 -0
- package/dist/cjs/engine/running-calls.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 +23 -0
- package/dist/cjs/engine/shared.cjs.map +1 -0
- package/dist/cjs/engine/shutdown.cjs +76 -0
- package/dist/cjs/engine/shutdown.cjs.map +1 -0
- package/dist/cjs/engine/stats.cjs +94 -0
- package/dist/cjs/engine/stats.cjs.map +1 -0
- package/dist/cjs/engine/stop-policy.cjs +40 -0
- package/dist/cjs/engine/stop-policy.cjs.map +1 -0
- package/dist/cjs/engine/stop.cjs +91 -0
- package/dist/cjs/engine/stop.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 +96 -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 +25 -1
- package/dist/cjs/errors.cjs.map +1 -1
- package/dist/cjs/index.cjs +14 -3
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/profiles 2.cjs +16 -0
- package/dist/cjs/types 2.cjs +3 -0
- package/dist/cjs/types.cjs 2.map +1 -0
- package/dist/cjs/validation.cjs 2.map +1 -0
- package/dist/esm/bulkhead.js +140 -1817
- 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 +108 -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 +140 -0
- package/dist/esm/engine/admitted-run.js.map +1 -0
- package/dist/esm/engine/admitted-token.js +280 -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 +33 -0
- package/dist/esm/engine/events.js.map +1 -0
- package/dist/esm/engine/limit-fit.js +105 -0
- package/dist/esm/engine/limit-fit.js.map +1 -0
- package/dist/esm/engine/limits.js +331 -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/running-calls.js +76 -0
- package/dist/esm/engine/running-calls.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 +20 -0
- package/dist/esm/engine/shared.js.map +1 -0
- package/dist/esm/engine/shutdown.js +73 -0
- package/dist/esm/engine/shutdown.js.map +1 -0
- package/dist/esm/engine/stats.js +91 -0
- package/dist/esm/engine/stats.js.map +1 -0
- package/dist/esm/engine/stop-policy.js +37 -0
- package/dist/esm/engine/stop-policy.js.map +1 -0
- package/dist/esm/engine/stop.js +88 -0
- package/dist/esm/engine/stop.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 +87 -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 +23 -0
- package/dist/esm/errors.js.map +1 -1
- package/dist/esm/index.js +13 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/types/bulkhead.d.ts +38 -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 +34 -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 +25 -0
- package/dist/types/engine/admitted-run.d.ts.map +1 -0
- package/dist/types/engine/admitted-token.d.ts +49 -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/limit-fit.d.ts +30 -0
- package/dist/types/engine/limit-fit.d.ts.map +1 -0
- package/dist/types/engine/limits.d.ts +47 -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/running-calls.d.ts +55 -0
- package/dist/types/engine/running-calls.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 +76 -0
- package/dist/types/engine/shared.d.ts.map +1 -0
- package/dist/types/engine/shutdown.d.ts +23 -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/stop-policy.d.ts +15 -0
- package/dist/types/engine/stop-policy.d.ts.map +1 -0
- package/dist/types/engine/stop.d.ts +44 -0
- package/dist/types/engine/stop.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 +65 -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 +21 -2
- package/dist/types/errors.d.ts.map +1 -1
- package/dist/types/index.d.ts +14 -4
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/types.d.ts +103 -2
- package/dist/types/types.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capacity.d.ts","sourceRoot":"","sources":["../../../src/engine/capacity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,KAAK,EAAyB,WAAW,EAAE,MAAM,aAAa,CAAC;AACtE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EACV,eAAe,EACf,yBAAyB,EACzB,eAAe,EAChB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD,wBAAgB,cAAc,CAAC,IAAI,EAAE;IACnC,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;sBA4Da,MAAM,YACN,WAAW,WACZ,MAAM,GAAG,SAAS,+BAE1B,eAAe,GAAG,SAAS;2BA0ClB,MAAM,YACN,WAAW,WACZ,MAAM,GAAG,SAAS,KAC1B,yBAAyB;EAuB7B;AAED,MAAM,MAAM,QAAQ,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validators for admission-class ids and class limits.
|
|
3
|
+
*
|
|
4
|
+
* Pure functions: each reads a caller-supplied value and either returns a
|
|
5
|
+
* validated copy or throws. They run at construction and again for every
|
|
6
|
+
* limits snapshot, and they never touch engine state.
|
|
7
|
+
*/
|
|
8
|
+
import type { LLMAdmissionClassLimits } from "../types.js";
|
|
9
|
+
export declare function validateAdmissionClassId(value: unknown, label: string): string;
|
|
10
|
+
export declare function readAdmissionClassLimits(value: unknown, label: string, tokenBudgetEnabled: boolean): LLMAdmissionClassLimits;
|
|
11
|
+
export declare function validateProtectedCapacity(limits: Iterable<LLMAdmissionClassLimits>, maxConcurrent: number, tokenBudget: number | undefined, label: string): void;
|
|
12
|
+
/**
|
|
13
|
+
* Read the `admissionClasses` part of a limits snapshot.
|
|
14
|
+
*
|
|
15
|
+
* `classIds` is the fixed construction-time class table, or `undefined`
|
|
16
|
+
* when the bulkhead has no classes. A snapshot must name exactly those
|
|
17
|
+
* classes: keys cannot be added or removed at runtime.
|
|
18
|
+
*/
|
|
19
|
+
export declare function readAdmissionClassLimitsUpdate(supplied: unknown, classIds: readonly string[] | undefined, tokenBudgetEnabled: boolean): Map<string, LLMAdmissionClassLimits> | undefined;
|
|
20
|
+
//# sourceMappingURL=class-limits.d.ts.map
|
|
@@ -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;WAed,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,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Does running work fit the applied limits, and if not, which call should
|
|
3
|
+
* be stopped next to make it fit?
|
|
4
|
+
*
|
|
5
|
+
* Read-only. Limits come from their owner, slots from the gate and the
|
|
6
|
+
* class slots, and the running calls from the set that owns them. Used by
|
|
7
|
+
* the take-back in `stop.ts`.
|
|
8
|
+
*
|
|
9
|
+
* Token limits are checked against the calls still running. A stopped
|
|
10
|
+
* call keeps its hold in the ledger until it settles, but it cannot be
|
|
11
|
+
* stopped a second time, so it is left out.
|
|
12
|
+
*/
|
|
13
|
+
import type { ClassSlots } from "./class-slots.js";
|
|
14
|
+
import type { Limits } from "./limits.js";
|
|
15
|
+
import type { RunningCall, RunningCalls } from "./running-calls.js";
|
|
16
|
+
import type { ConcurrencyGate } from "./shared.js";
|
|
17
|
+
type Deps = {
|
|
18
|
+
budgetEnabled: boolean;
|
|
19
|
+
concurrency: ConcurrencyGate;
|
|
20
|
+
limits: Limits;
|
|
21
|
+
slots: ClassSlots;
|
|
22
|
+
running: RunningCalls;
|
|
23
|
+
};
|
|
24
|
+
export declare function createLimitFit(deps: Deps): {
|
|
25
|
+
aboveLimits: () => boolean;
|
|
26
|
+
nextToStop: () => RunningCall | undefined;
|
|
27
|
+
};
|
|
28
|
+
export type LimitFit = ReturnType<typeof createLimitFit>;
|
|
29
|
+
export {};
|
|
30
|
+
//# sourceMappingURL=limit-fit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"limit-fit.d.ts","sourceRoot":"","sources":["../../../src/engine/limit-fit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACpE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD,KAAK,IAAI,GAAG;IACV,aAAa,EAAE,OAAO,CAAC;IACvB,WAAW,EAAE,eAAe,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,UAAU,CAAC;IAClB,OAAO,EAAE,YAAY,CAAC;CACvB,CAAC;AAYF,wBAAgB,cAAc,CAAC,IAAI,EAAE,IAAI;uBA2Gf,OAAO;sBAQR,WAAW,GAAG,SAAS;EAU/C;AAED,MAAM,MAAM,QAAQ,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Owner of the admission limits that change at runtime: the limit
|
|
3
|
+
* revision, the token budget, the high-priority reserve, each class's
|
|
4
|
+
* floors and ceilings, and the stop policy.
|
|
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, LLMAdmissionStopPolicy, 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
|
+
/** The applied stop policy; `undefined` when stopping is off. */
|
|
37
|
+
stopPolicy: () => LLMAdmissionStopPolicy | undefined;
|
|
38
|
+
effectiveBudget: (priority: LLMPriority) => number;
|
|
39
|
+
protectedConcurrentTotal: () => number;
|
|
40
|
+
protectedTokensTotal: () => number;
|
|
41
|
+
resolveClass: (requested: string | undefined) => string | undefined;
|
|
42
|
+
snapshot: () => LLMAdmissionLimits;
|
|
43
|
+
apply: (next: LLMAdmissionLimits) => LLMApplyLimitsResult;
|
|
44
|
+
setBudget: (tokens: number) => void;
|
|
45
|
+
};
|
|
46
|
+
export type Limits = ReturnType<typeof createLimits>;
|
|
47
|
+
//# 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,sBAAsB,EACtB,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;AAGnD,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;AAkOF,wBAAgB,YAAY,CAC1B,MAAM,EAAE,eAAe;AACvB,wEAAwE;AACxE,MAAM,EAAE,kBAAkB,GAAG,SAAS,EACtC,WAAW,EAAE,eAAe,EAC5B,MAAM,EAAE,QAAQ;IA2Jd,qDAAqD;;IAErD,oDAAoD;;IAEpD,oDAAoD;qBA/K1C,MAAM,KAAG,QAAQ,CAAC,WAAW,CAAC;IAiLxC,gDAAgD;2BAhL9B,MAAM,KAAG,uBAAuB;oBAkLpC,MAAM;IACpB,8EAA8E;kBAClE,MAAM,GAAG,SAAS;+BACL,MAAM;IAC/B,iEAAiE;sBACjD,sBAAsB,GAAG,SAAS;gCAhIjB,WAAW,KAAG,MAAM;oCA9HlB,MAAM;gCAQV,MAAM;8BAaX,MAAM,GAAG,SAAS,KAAG,MAAM,GAAG,SAAS;oBAiH9C,kBAAkB;kBAmClB,kBAAkB,KAAG,oBAAoB;wBA6CnC,MAAM,KAAG,IAAI;EAiDzC;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,CAiId"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Owner of the set of running calls: every admitted call that has neither
|
|
3
|
+
* reached final settlement nor been stopped, in admission order.
|
|
4
|
+
*
|
|
5
|
+
* The other owners keep counters only, which is enough to admit and
|
|
6
|
+
* release work. Stopping admitted work needs the calls themselves: which
|
|
7
|
+
* ones are still running, what each holds right now, and which to stop
|
|
8
|
+
* first. Nothing outside this file adds to or removes from the set; the
|
|
9
|
+
* admitted token registers its call at admission and removes it at stop or
|
|
10
|
+
* final release.
|
|
11
|
+
*
|
|
12
|
+
* Every admission pays for being registered, whether or not anything is
|
|
13
|
+
* ever stopped, so the set is a linked list threaded through the calls
|
|
14
|
+
* themselves. Adding or removing a call is a few pointer writes: no
|
|
15
|
+
* allocation and no hashing.
|
|
16
|
+
*
|
|
17
|
+
* The stop order is fixed and lives here:
|
|
18
|
+
*
|
|
19
|
+
* 1. calls admitted on borrowed capacity
|
|
20
|
+
* 2. normal priority before high priority
|
|
21
|
+
* 3. on a tie, the call admitted last
|
|
22
|
+
*/
|
|
23
|
+
import type { LLMPriority } from "../types.js";
|
|
24
|
+
/**
|
|
25
|
+
* One running call, as the stop triggers see it: a read-only view of the
|
|
26
|
+
* admitted token's own record. `slotReturned` and `held` are live.
|
|
27
|
+
*/
|
|
28
|
+
export type RunningCall = {
|
|
29
|
+
readonly priority: LLMPriority;
|
|
30
|
+
readonly admissionClass: string | undefined;
|
|
31
|
+
/** Admitted on a slot or on tokens above its class floor. */
|
|
32
|
+
readonly borrowed: boolean;
|
|
33
|
+
/** Tokens reserved at admission; 0 without a token budget. */
|
|
34
|
+
readonly reservedTokens: number;
|
|
35
|
+
/** The concurrency slot went back before final settlement. */
|
|
36
|
+
readonly slotReturned: boolean;
|
|
37
|
+
/** Tokens the call holds against the budget right now. */
|
|
38
|
+
readonly held: number;
|
|
39
|
+
/**
|
|
40
|
+
* Neighbors in admission order. These two belong to the set of running
|
|
41
|
+
* calls: a call starts with both `undefined`, and only this file writes
|
|
42
|
+
* them.
|
|
43
|
+
*/
|
|
44
|
+
admittedBefore: RunningCall | undefined;
|
|
45
|
+
admittedAfter: RunningCall | undefined;
|
|
46
|
+
};
|
|
47
|
+
export declare function createRunningCalls(): {
|
|
48
|
+
add: (call: RunningCall) => void;
|
|
49
|
+
remove: (call: RunningCall) => void;
|
|
50
|
+
firstToStop: (eligible: (call: RunningCall) => boolean) => RunningCall | undefined;
|
|
51
|
+
inStopOrder: () => RunningCall[];
|
|
52
|
+
heldTokens: (classId?: string) => number;
|
|
53
|
+
};
|
|
54
|
+
export type RunningCalls = ReturnType<typeof createRunningCalls>;
|
|
55
|
+
//# sourceMappingURL=running-calls.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"running-calls.d.ts","sourceRoot":"","sources":["../../../src/engine/running-calls.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC;IAC/B,QAAQ,CAAC,cAAc,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5C,6DAA6D;IAC7D,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,8DAA8D;IAC9D,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,8DAA8D;IAC9D,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;IAC/B,0DAA0D;IAC1D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;;;;OAIG;IACH,cAAc,EAAE,WAAW,GAAG,SAAS,CAAC;IACxC,aAAa,EAAE,WAAW,GAAG,SAAS,CAAC;CACxC,CAAC;AAQF,wBAAgB,kBAAkB;gBAKb,WAAW,KAAG,IAAI;mBAYf,WAAW,KAAG,IAAI;4BAa5B,CAAC,IAAI,EAAE,WAAW,KAAK,OAAO,KACvC,WAAW,GAAG,SAAS;uBAYF,WAAW,EAAE;2BAgBP,MAAM,KAAG,MAAM;EAW9C;AAED,MAAM,MAAM,YAAY,GAAG,UAAU,CAAC,OAAO,kBAAkB,CAAC,CAAC"}
|
|
@@ -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,76 @@
|
|
|
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 { LLMAdmissionStoppedError } from "../errors.js";
|
|
9
|
+
import type { createReconfigurableBulkhead } from "../reconfigurable-bulkhead.js";
|
|
10
|
+
import type { LLMAcquireResult, LLMAdmissionResources, LLMBorrowedConcurrencyAbandonCause, LLMCapacityConstraint, LLMPriority, LLMRejectReason, LLMReservationEstimate, LLMToken } from "../types.js";
|
|
11
|
+
/** Abort signal accepted by the underlying concurrency acquire. */
|
|
12
|
+
export type BulkheadSignal = NonNullable<AcquireOptions["signal"]>;
|
|
13
|
+
/**
|
|
14
|
+
* The reconfigurable concurrency gate. It owns the global slot count and
|
|
15
|
+
* the queue; the engine reads both through `stats()` and never mirrors
|
|
16
|
+
* them.
|
|
17
|
+
*/
|
|
18
|
+
export type ConcurrencyGate = ReturnType<typeof createReconfigurableBulkhead>;
|
|
19
|
+
/** Estimate parts kept per-token so streaming reports can re-derive holds. */
|
|
20
|
+
export type ReservationParts = LLMReservationEstimate;
|
|
21
|
+
/**
|
|
22
|
+
* What one call asks for, after its options are resolved.
|
|
23
|
+
*
|
|
24
|
+
* An admission class always travels as its id. The numbers that belong to
|
|
25
|
+
* a class stay with the engine part that owns them.
|
|
26
|
+
*/
|
|
27
|
+
export type ResolvedAdmission = {
|
|
28
|
+
priority: LLMPriority;
|
|
29
|
+
admissionClass: string | undefined;
|
|
30
|
+
parts: ReservationParts | null;
|
|
31
|
+
reserved: number;
|
|
32
|
+
};
|
|
33
|
+
export type CapacityFailure = {
|
|
34
|
+
reason: Extract<LLMRejectReason, "budget_limit" | "concurrency_limit">;
|
|
35
|
+
constraint: LLMCapacityConstraint;
|
|
36
|
+
};
|
|
37
|
+
export type CapacityReservationResult = {
|
|
38
|
+
readonly ok: false;
|
|
39
|
+
readonly failure: CapacityFailure;
|
|
40
|
+
} | {
|
|
41
|
+
readonly ok: true;
|
|
42
|
+
readonly resources: LLMAdmissionResources;
|
|
43
|
+
};
|
|
44
|
+
export declare const NO_ADMISSION_RESOURCES: LLMAdmissionResources;
|
|
45
|
+
/**
|
|
46
|
+
* Internal view of a wrapped token. `run()` must attribute a lease expiry
|
|
47
|
+
* distinctly from an application's own abandonment without widening the
|
|
48
|
+
* public `LLMToken` surface, where a caller-supplied cause would be
|
|
49
|
+
* unverifiable telemetry. The key is an engine-private symbol, never
|
|
50
|
+
* exported from the package entry point, so the capability is unreachable
|
|
51
|
+
* from a published token.
|
|
52
|
+
*/
|
|
53
|
+
export declare const ABANDON_WITH_CAUSE: unique symbol;
|
|
54
|
+
/**
|
|
55
|
+
* How `run()` learns that the engine stopped its call. Engine-private for
|
|
56
|
+
* the same reason as `ABANDON_WITH_CAUSE`: a published token must not let
|
|
57
|
+
* a caller intercept or fake a stop.
|
|
58
|
+
*/
|
|
59
|
+
export declare const ON_STOP: unique symbol;
|
|
60
|
+
export type WrappedLLMToken = LLMToken & {
|
|
61
|
+
[ABANDON_WITH_CAUSE](cause: LLMBorrowedConcurrencyAbandonCause): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Register what to do when the engine stops this call. If the call was
|
|
64
|
+
* already stopped, the handler is not kept and the stop error is
|
|
65
|
+
* returned instead.
|
|
66
|
+
*/
|
|
67
|
+
[ON_STOP](handler: (error: LLMAdmissionStoppedError) => void): LLMAdmissionStoppedError | undefined;
|
|
68
|
+
};
|
|
69
|
+
export type InternalAcquireResult = (Extract<LLMAcquireResult, {
|
|
70
|
+
ok: true;
|
|
71
|
+
}> & {
|
|
72
|
+
token: WrappedLLMToken;
|
|
73
|
+
}) | Extract<LLMAcquireResult, {
|
|
74
|
+
ok: false;
|
|
75
|
+
}>;
|
|
76
|
+
//# 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,wBAAwB,EAAE,MAAM,cAAc,CAAC;AAC7D,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;;;;GAIG;AACH,eAAO,MAAM,OAAO,eAAmB,CAAC;AAExC,MAAM,MAAM,eAAe,GAAG,QAAQ,GAAG;IACvC,CAAC,kBAAkB,CAAC,CAAC,KAAK,EAAE,kCAAkC,GAAG,OAAO,CAAC;IACzE;;;;OAIG;IACH,CAAC,OAAO,CAAC,CACP,OAAO,EAAE,CAAC,KAAK,EAAE,wBAAwB,KAAK,IAAI,GACjD,wBAAwB,GAAG,SAAS,CAAC;CACzC,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,23 @@
|
|
|
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, or was stopped, no longer holds a
|
|
7
|
+
* slot, yet still 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
|
+
/** Stop every running call for a drain deadline; returns how many. */
|
|
14
|
+
stopForDrain: () => number): {
|
|
15
|
+
settleDrainWaiters: () => void;
|
|
16
|
+
close: () => void;
|
|
17
|
+
drain: (opts?: {
|
|
18
|
+
timeoutMs?: number;
|
|
19
|
+
stopOnTimeout?: boolean;
|
|
20
|
+
}) => Promise<void> | Promise<LLMDrainResult>;
|
|
21
|
+
};
|
|
22
|
+
export type Shutdown = ReturnType<typeof createShutdown>;
|
|
23
|
+
//# 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;AACvB,sEAAsE;AACtE,YAAY,EAAE,MAAM,MAAM;8BAKK,IAAI;iBAajB,IAAI;mBAIA;QACpB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,aAAa,CAAC,EAAE,OAAO,CAAC;KACzB,KAAG,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,cAAc,CAAC;EA+C5C;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;AAyEF,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,SAIX,QAAQ,CAwClC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validator for the `stop` part of a limits snapshot.
|
|
3
|
+
*
|
|
4
|
+
* A pure function, like the class-limit validators: it reads a
|
|
5
|
+
* caller-supplied value and either returns a validated, frozen copy or
|
|
6
|
+
* throws. It never touches engine state.
|
|
7
|
+
*/
|
|
8
|
+
import type { LLMAdmissionStopPolicy } from "../types.js";
|
|
9
|
+
/**
|
|
10
|
+
* Read the `stop` part of a limits snapshot. `undefined` means the
|
|
11
|
+
* snapshot carries no stop policy. Each property is read once, so an
|
|
12
|
+
* accessor cannot return one value here and another later.
|
|
13
|
+
*/
|
|
14
|
+
export declare function readStopPolicy(supplied: unknown, tokenBudgetEnabled: boolean): LLMAdmissionStopPolicy | undefined;
|
|
15
|
+
//# sourceMappingURL=stop-policy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stop-policy.d.ts","sourceRoot":"","sources":["../../../src/engine/stop-policy.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAM1D;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,OAAO,EACjB,kBAAkB,EAAE,OAAO,GAC1B,sBAAsB,GAAG,SAAS,CAoCpC"}
|