@danypops/vehicle-core 0.18.3 → 0.18.5
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/dist/index.d.ts +6 -4
- package/dist/index.js +6 -4
- package/dist/resource-pool/bounded-resource-pool.d.ts +139 -0
- package/dist/resource-pool/bounded-resource-pool.js +427 -0
- package/dist/resource-pool/errors.d.ts +24 -0
- package/dist/resource-pool/errors.js +44 -0
- package/dist/resource-pool/index.d.ts +3 -0
- package/dist/resource-pool/index.js +3 -0
- package/dist/resource-pool/resource-policy.d.ts +28 -0
- package/dist/resource-pool/resource-policy.js +1 -0
- package/dist/schemas/presentation.d.ts +4 -2
- package/dist/schemas/presentation.js +3 -1
- package/package.json +1 -1
- package/src/index.ts +6 -4
- package/src/resource-pool/bounded-resource-pool.ts +506 -0
- package/src/resource-pool/errors.ts +45 -0
- package/src/resource-pool/index.ts +3 -0
- package/src/resource-pool/resource-policy.ts +29 -0
- package/src/schemas/presentation.ts +4 -2
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/** Raised when no idle resource can be evicted to admit a new one within the current ceiling. */
|
|
2
|
+
export class ResourceCapacityExceeded extends Error {
|
|
3
|
+
constructor(
|
|
4
|
+
readonly partitionKey: string,
|
|
5
|
+
readonly maxActive: number,
|
|
6
|
+
readonly partitionLimit: number,
|
|
7
|
+
) {
|
|
8
|
+
super(
|
|
9
|
+
`no idle resource can be evicted to admit partition "${partitionKey}" within global capacity ${maxActive} and partition capacity ${partitionLimit}`,
|
|
10
|
+
);
|
|
11
|
+
this.name = "ResourceCapacityExceeded";
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Raised by releaseOwnerIfIdle when at least one of the owner's own resources still has an active lease. */
|
|
16
|
+
export class ResourceInUse extends Error {
|
|
17
|
+
constructor(readonly ownerKey: string) {
|
|
18
|
+
super(`cannot release owner "${ownerKey}": a pooled resource for it still has an active lease`);
|
|
19
|
+
this.name = "ResourceInUse";
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Raised when background admission is already waiting at maxQueuedBackgroundAdmissions -- fails fast rather than growing the wait queue without bound. */
|
|
24
|
+
export class ResourceAdmissionQueueFull extends Error {
|
|
25
|
+
constructor(
|
|
26
|
+
readonly partitionKey: string,
|
|
27
|
+
readonly maxQueued: number,
|
|
28
|
+
) {
|
|
29
|
+
super(`background admission for partition "${partitionKey}" is already waiting at capacity (${maxQueued} queued); retry later`);
|
|
30
|
+
this.name = "ResourceAdmissionQueueFull";
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Raised when a queued background admission waits past backgroundAdmissionQueueTimeoutMs without a slot freeing. */
|
|
35
|
+
export class ResourceAdmissionQueueTimedOut extends Error {
|
|
36
|
+
constructor(
|
|
37
|
+
readonly partitionKey: string,
|
|
38
|
+
readonly timeoutMs: number,
|
|
39
|
+
) {
|
|
40
|
+
super(
|
|
41
|
+
`background admission for partition "${partitionKey}" waited ${timeoutMs}ms for a resource-pool slot and gave up -- foreground demand is holding every admittable slot`,
|
|
42
|
+
);
|
|
43
|
+
this.name = "ResourceAdmissionQueueTimedOut";
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** Which ceiling actually constrained the most recent admission decision. */
|
|
2
|
+
export type ResourcePoolActiveCeilingSource = "configured" | "resource-budget" | "absolute-cap";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Optional plug point letting a real resource budget (memory, /proc-sampled process cost, ...)
|
|
6
|
+
* drive admission and retention decisions beyond the pool's own configured counts. A pool without
|
|
7
|
+
* one falls back to its configured maxActive/absoluteMaxActive alone -- this interface exists so a
|
|
8
|
+
* caller CAN plug in something smarter, not because every caller needs to.
|
|
9
|
+
*
|
|
10
|
+
* `Status` is left to the caller (default `unknown`) rather than fixed to one shape: the pool
|
|
11
|
+
* itself never inspects or reshapes what `status()` returns, only forwards it verbatim in its own
|
|
12
|
+
* status() report -- a caller with an existing status shape (its own field names, units, wire
|
|
13
|
+
* contract) plugs it in unchanged, no adapter required.
|
|
14
|
+
*/
|
|
15
|
+
export interface ResourcePoolResourcePolicy<Status = unknown> {
|
|
16
|
+
canAdmit(activePartitions: readonly string[], requestedPartition: string): boolean;
|
|
17
|
+
isOverBudget(activePartitions: readonly string[]): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* A conservative, count-shaped ceiling derived from a real budget and worst-case known
|
|
20
|
+
* per-partition cost -- lets a larger real budget actually raise how many resources the pool
|
|
21
|
+
* will try to keep active, instead of a fixed configured count being the permanent bottleneck
|
|
22
|
+
* regardless of how much is genuinely available. Never authoritative on its own: canAdmit's own
|
|
23
|
+
* precise per-attempt check still gates the actual admission. Returns undefined on any metric
|
|
24
|
+
* loss -- fails closed, never treated as "unlimited room."
|
|
25
|
+
*/
|
|
26
|
+
softActiveCeiling(activePartitions: readonly string[]): number | undefined;
|
|
27
|
+
maxIdleMs(configuredMaxIdleMs: number, activePartitions: readonly string[]): number;
|
|
28
|
+
status(activePartitions: readonly string[]): Status;
|
|
29
|
+
}
|
|
@@ -21,8 +21,10 @@ export function isVehicleCredentialFieldName(name: string): boolean {
|
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* JSON Schema property annotation consumed by human-facing Vehicle adapters.
|
|
24
|
-
* `omit` hides the field; `summarize` may show shape/size but never its value
|
|
24
|
+
* `omit` hides the field; `summarize` may show shape/size but never its value;
|
|
25
|
+
* `stream` exposes a string through a bounded, tail-following call preview while
|
|
26
|
+
* the host receives partial tool arguments, then collapses it to a size summary.
|
|
25
27
|
* Standard `writeOnly: true` and `format: "password"` always imply omission.
|
|
26
28
|
*/
|
|
27
29
|
export const VEHICLE_SCHEMA_PRESENTATION_EXTENSION = "x-vehicle-presentation" as const;
|
|
28
|
-
export type VehicleSchemaPresentation = "omit" | "summarize";
|
|
30
|
+
export type VehicleSchemaPresentation = "omit" | "summarize" | "stream";
|