@cleocode/lafs 2026.3.74 → 2026.4.3
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/LICENSE +0 -0
- package/README.md +97 -68
- package/dist/schemas/v1/agent-card.schema.json +230 -0
- package/dist/schemas/v1/conformance-profiles.json +0 -0
- package/dist/schemas/v1/context-ledger.schema.json +70 -0
- package/dist/schemas/v1/discovery.schema.json +132 -0
- package/dist/schemas/v1/envelope.schema.json +0 -0
- package/dist/schemas/v1/error-registry.json +0 -0
- package/dist/src/a2a/bindings/grpc.d.ts +118 -11
- package/dist/src/a2a/bindings/grpc.d.ts.map +1 -0
- package/dist/src/a2a/bindings/grpc.js +80 -8
- package/dist/src/a2a/bindings/grpc.js.map +1 -0
- package/dist/src/a2a/bindings/http.d.ts +131 -15
- package/dist/src/a2a/bindings/http.d.ts.map +1 -0
- package/dist/src/a2a/bindings/http.js +101 -14
- package/dist/src/a2a/bindings/http.js.map +1 -0
- package/dist/src/a2a/bindings/index.d.ts +83 -9
- package/dist/src/a2a/bindings/index.d.ts.map +1 -0
- package/dist/src/a2a/bindings/index.js +74 -6
- package/dist/src/a2a/bindings/index.js.map +1 -0
- package/dist/src/a2a/bindings/jsonrpc.d.ts +194 -9
- package/dist/src/a2a/bindings/jsonrpc.d.ts.map +1 -0
- package/dist/src/a2a/bindings/jsonrpc.js +155 -10
- package/dist/src/a2a/bindings/jsonrpc.js.map +1 -0
- package/dist/src/a2a/bridge.d.ts +237 -44
- package/dist/src/a2a/bridge.d.ts.map +1 -0
- package/dist/src/a2a/bridge.js +187 -48
- package/dist/src/a2a/bridge.js.map +1 -0
- package/dist/src/a2a/extensions.d.ts +222 -12
- package/dist/src/a2a/extensions.d.ts.map +1 -0
- package/dist/src/a2a/extensions.js +178 -13
- package/dist/src/a2a/extensions.js.map +1 -0
- package/dist/src/a2a/index.d.ts +10 -7
- package/dist/src/a2a/index.d.ts.map +1 -0
- package/dist/src/a2a/index.js +24 -27
- package/dist/src/a2a/index.js.map +1 -0
- package/dist/src/a2a/streaming.d.ts +276 -3
- package/dist/src/a2a/streaming.d.ts.map +1 -0
- package/dist/src/a2a/streaming.js +255 -11
- package/dist/src/a2a/streaming.js.map +1 -0
- package/dist/src/a2a/task-lifecycle.d.ts +341 -20
- package/dist/src/a2a/task-lifecycle.d.ts.map +1 -0
- package/dist/src/a2a/task-lifecycle.js +327 -26
- package/dist/src/a2a/task-lifecycle.js.map +1 -0
- package/dist/src/budgetEnforcement.d.ts +93 -20
- package/dist/src/budgetEnforcement.d.ts.map +1 -0
- package/dist/src/budgetEnforcement.js +146 -31
- package/dist/src/budgetEnforcement.js.map +1 -0
- package/dist/src/circuit-breaker/index.d.ts +260 -10
- package/dist/src/circuit-breaker/index.d.ts.map +1 -0
- package/dist/src/circuit-breaker/index.js +226 -14
- package/dist/src/circuit-breaker/index.js.map +1 -0
- package/dist/src/cli.d.ts +1 -0
- package/dist/src/cli.d.ts.map +1 -0
- package/dist/src/cli.js +12 -11
- package/dist/src/cli.js.map +1 -0
- package/dist/src/compliance.d.ts +180 -3
- package/dist/src/compliance.d.ts.map +1 -0
- package/dist/src/compliance.js +114 -13
- package/dist/src/compliance.js.map +1 -0
- package/dist/src/conformance.d.ts +55 -2
- package/dist/src/conformance.d.ts.map +1 -0
- package/dist/src/conformance.js +124 -76
- package/dist/src/conformance.js.map +1 -0
- package/dist/src/conformanceProfiles.d.ts +68 -1
- package/dist/src/conformanceProfiles.d.ts.map +1 -0
- package/dist/src/conformanceProfiles.js +53 -1
- package/dist/src/conformanceProfiles.js.map +1 -0
- package/dist/src/deprecationRegistry.d.ts +82 -1
- package/dist/src/deprecationRegistry.d.ts.map +1 -0
- package/dist/src/deprecationRegistry.js +58 -7
- package/dist/src/deprecationRegistry.js.map +1 -0
- package/dist/src/discovery.d.ts +347 -65
- package/dist/src/discovery.d.ts.map +1 -0
- package/dist/src/discovery.js +130 -72
- package/dist/src/discovery.js.map +1 -0
- package/dist/src/envelope.d.ts +262 -9
- package/dist/src/envelope.d.ts.map +1 -0
- package/dist/src/envelope.js +179 -15
- package/dist/src/envelope.js.map +1 -0
- package/dist/src/errorRegistry.d.ts +163 -3
- package/dist/src/errorRegistry.d.ts.map +1 -0
- package/dist/src/errorRegistry.js +119 -3
- package/dist/src/errorRegistry.js.map +1 -0
- package/dist/src/fieldExtraction.d.ts +128 -27
- package/dist/src/fieldExtraction.d.ts.map +1 -0
- package/dist/src/fieldExtraction.js +100 -27
- package/dist/src/fieldExtraction.js.map +1 -0
- package/dist/src/flagResolver.d.ts +77 -10
- package/dist/src/flagResolver.d.ts.map +1 -0
- package/dist/src/flagResolver.js +22 -5
- package/dist/src/flagResolver.js.map +1 -0
- package/dist/src/flagSemantics.d.ts +80 -4
- package/dist/src/flagSemantics.d.ts.map +1 -0
- package/dist/src/flagSemantics.js +78 -11
- package/dist/src/flagSemantics.js.map +1 -0
- package/dist/src/health/index.d.ts +103 -9
- package/dist/src/health/index.d.ts.map +1 -0
- package/dist/src/health/index.js +75 -26
- package/dist/src/health/index.js.map +1 -0
- package/dist/src/index.d.ts +34 -23
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +40 -28
- package/dist/src/index.js.map +1 -0
- package/dist/src/mviProjection.d.ts +43 -6
- package/dist/src/mviProjection.d.ts.map +1 -0
- package/dist/src/mviProjection.js +32 -5
- package/dist/src/mviProjection.js.map +1 -0
- package/dist/src/native-loader.d.ts +49 -0
- package/dist/src/native-loader.d.ts.map +1 -0
- package/dist/src/native-loader.js +56 -0
- package/dist/src/native-loader.js.map +1 -0
- package/dist/src/problemDetails.d.ts +71 -4
- package/dist/src/problemDetails.d.ts.map +1 -0
- package/dist/src/problemDetails.js +27 -3
- package/dist/src/problemDetails.js.map +1 -0
- package/dist/src/shutdown/index.d.ts +103 -9
- package/dist/src/shutdown/index.d.ts.map +1 -0
- package/dist/src/shutdown/index.js +78 -12
- package/dist/src/shutdown/index.js.map +1 -0
- package/dist/src/tokenEstimator.d.ts +98 -11
- package/dist/src/tokenEstimator.d.ts.map +1 -0
- package/dist/src/tokenEstimator.js +91 -13
- package/dist/src/tokenEstimator.js.map +1 -0
- package/dist/src/types.d.ts +477 -11
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +76 -2
- package/dist/src/types.js.map +1 -0
- package/dist/src/validateEnvelope.d.ts +61 -2
- package/dist/src/validateEnvelope.d.ts.map +1 -0
- package/dist/src/validateEnvelope.js +81 -14
- package/dist/src/validateEnvelope.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/lafs.md +3 -4
- package/package.json +14 -12
- package/schemas/v1/agent-card.schema.json +0 -0
- package/schemas/v1/conformance-profiles.json +0 -0
- package/schemas/v1/context-ledger.schema.json +0 -0
- package/schemas/v1/discovery.schema.json +0 -0
- package/schemas/v1/envelope.schema.json +0 -0
- package/schemas/v1/error-registry.json +0 -0
- package/dist/src/mcpAdapter.d.ts +0 -28
- package/dist/src/mcpAdapter.js +0 -281
|
@@ -4,32 +4,58 @@
|
|
|
4
4
|
* Middleware for enforcing MVI (Minimal Viable Interface) token budgets on LAFS envelopes.
|
|
5
5
|
* Provides budget checking, truncation, and error generation for exceeded budgets.
|
|
6
6
|
*/
|
|
7
|
-
import
|
|
8
|
-
import type { BudgetEnforcementOptions,
|
|
9
|
-
import { TokenEstimator } from "./tokenEstimator.js";
|
|
7
|
+
import { TokenEstimator } from './tokenEstimator.js';
|
|
8
|
+
import type { BudgetEnforcementOptions, BudgetEnforcementResult, LAFSEnvelope, TokenEstimate } from './types.js';
|
|
10
9
|
/**
|
|
11
|
-
* Budget exceeded error code from LAFS error registry
|
|
10
|
+
* Budget exceeded error code from LAFS error registry.
|
|
11
|
+
*
|
|
12
|
+
* @remarks
|
|
13
|
+
* Used as the `code` field in {@link LAFSError} when a response exceeds
|
|
14
|
+
* its declared MVI token budget.
|
|
12
15
|
*/
|
|
13
16
|
declare const BUDGET_EXCEEDED_CODE = "E_MVI_BUDGET_EXCEEDED";
|
|
14
17
|
/**
|
|
15
18
|
* Apply budget enforcement to an envelope.
|
|
16
19
|
*
|
|
17
20
|
* @param envelope - The LAFS envelope to check
|
|
18
|
-
* @param budget - Maximum allowed
|
|
19
|
-
* @param options - Budget enforcement options
|
|
20
|
-
* @returns
|
|
21
|
+
* @param budget - Maximum allowed token count
|
|
22
|
+
* @param options - Budget enforcement options (truncation, callbacks)
|
|
23
|
+
* @returns Enforcement result with the (possibly modified) envelope, budget status, and token estimates
|
|
24
|
+
*
|
|
25
|
+
* @remarks
|
|
26
|
+
* When the envelope is within budget, the token estimate is attached to metadata.
|
|
27
|
+
* When exceeded, behavior depends on `options.truncateOnExceed`: if enabled,
|
|
28
|
+
* truncation is attempted first; otherwise, the result is replaced with a
|
|
29
|
+
* budget-exceeded error. The `onBudgetExceeded` callback fires before truncation.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* const result = applyBudgetEnforcement(envelope, 1000, { truncateOnExceed: true });
|
|
34
|
+
* if (!result.withinBudget) {
|
|
35
|
+
* console.warn("Budget exceeded:", result.estimatedTokens);
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
21
38
|
*/
|
|
22
39
|
export declare function applyBudgetEnforcement(envelope: LAFSEnvelope, budget: number, options?: BudgetEnforcementOptions): BudgetEnforcementResult;
|
|
23
40
|
/**
|
|
24
|
-
* Type for middleware function
|
|
41
|
+
* Type for envelope middleware function.
|
|
42
|
+
*
|
|
43
|
+
* @remarks
|
|
44
|
+
* Middleware functions receive an envelope and a `next` callback, enabling
|
|
45
|
+
* pre- and post-processing of LAFS envelopes in a pipeline.
|
|
25
46
|
*/
|
|
26
47
|
type EnvelopeMiddleware = (envelope: LAFSEnvelope, next: () => LAFSEnvelope | Promise<LAFSEnvelope>) => Promise<LAFSEnvelope> | LAFSEnvelope;
|
|
27
48
|
/**
|
|
28
49
|
* Create a budget enforcement middleware function.
|
|
29
50
|
*
|
|
30
|
-
* @param budget - Maximum allowed
|
|
31
|
-
* @param options - Budget enforcement options
|
|
32
|
-
* @returns
|
|
51
|
+
* @param budget - Maximum allowed token count for the response
|
|
52
|
+
* @param options - Budget enforcement options (truncation, callbacks)
|
|
53
|
+
* @returns Async middleware function that enforces the token budget
|
|
54
|
+
*
|
|
55
|
+
* @remarks
|
|
56
|
+
* Wraps the next handler in the chain, applying {@link applyBudgetEnforcement}
|
|
57
|
+
* to its output. The returned envelope may be truncated or replaced with an
|
|
58
|
+
* error depending on the enforcement result.
|
|
33
59
|
*
|
|
34
60
|
* @example
|
|
35
61
|
* ```typescript
|
|
@@ -42,8 +68,20 @@ export declare function withBudget(budget: number, options?: BudgetEnforcementOp
|
|
|
42
68
|
* Check if an envelope has exceeded its budget without modifying it.
|
|
43
69
|
*
|
|
44
70
|
* @param envelope - The LAFS envelope to check
|
|
45
|
-
* @param budget - Maximum allowed
|
|
46
|
-
* @returns
|
|
71
|
+
* @param budget - Maximum allowed token count
|
|
72
|
+
* @returns Object with `exceeded` flag, `estimated` token count, and `remaining` budget
|
|
73
|
+
*
|
|
74
|
+
* @remarks
|
|
75
|
+
* A read-only budget check that does not alter the envelope. Useful for
|
|
76
|
+
* pre-flight checks or logging before deciding how to handle overages.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```typescript
|
|
80
|
+
* const { exceeded, estimated, remaining } = checkBudget(envelope, 500);
|
|
81
|
+
* if (exceeded) {
|
|
82
|
+
* console.warn(`Over budget by ${estimated - 500} tokens`);
|
|
83
|
+
* }
|
|
84
|
+
* ```
|
|
47
85
|
*/
|
|
48
86
|
export declare function checkBudget(envelope: LAFSEnvelope, budget: number): {
|
|
49
87
|
exceeded: boolean;
|
|
@@ -53,19 +91,38 @@ export declare function checkBudget(envelope: LAFSEnvelope, budget: number): {
|
|
|
53
91
|
/**
|
|
54
92
|
* Synchronous version of withBudget for non-async contexts.
|
|
55
93
|
*
|
|
56
|
-
* @param budget - Maximum allowed
|
|
57
|
-
* @param options - Budget enforcement options
|
|
58
|
-
* @returns
|
|
94
|
+
* @param budget - Maximum allowed token count for the response
|
|
95
|
+
* @param options - Budget enforcement options (truncation, callbacks)
|
|
96
|
+
* @returns Synchronous middleware function that enforces the token budget
|
|
97
|
+
*
|
|
98
|
+
* @remarks
|
|
99
|
+
* Identical to {@link withBudget} but operates synchronously. Use this when the
|
|
100
|
+
* next handler in the chain is guaranteed to return synchronously.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```typescript
|
|
104
|
+
* const middleware = withBudgetSync(500);
|
|
105
|
+
* const result = middleware(envelope, () => nextEnvelope);
|
|
106
|
+
* ```
|
|
59
107
|
*/
|
|
60
108
|
export declare function withBudgetSync(budget: number, options?: BudgetEnforcementOptions): (envelope: LAFSEnvelope, next: () => LAFSEnvelope) => LAFSEnvelope;
|
|
61
109
|
/**
|
|
62
110
|
* Higher-order function that wraps a handler with budget enforcement.
|
|
63
111
|
*
|
|
64
112
|
* @param handler - The handler function to wrap
|
|
113
|
+
* @typeParam TArgs - Tuple type representing the handler's parameter list
|
|
114
|
+
* @typeParam TResult - Return type of the handler, must extend LAFSEnvelope
|
|
115
|
+
* @param handler - The handler function to wrap with budget enforcement
|
|
65
116
|
* @param budget - Maximum allowed tokens
|
|
66
117
|
* @param options - Budget enforcement options
|
|
67
118
|
* @returns Wrapped handler with budget enforcement
|
|
68
119
|
*
|
|
120
|
+
* @remarks
|
|
121
|
+
* The returned function has the same parameter signature as the original handler
|
|
122
|
+
* but always returns a `Promise<LAFSEnvelope>`. When the budget is exceeded and
|
|
123
|
+
* `truncateOnExceed` is enabled, the envelope is truncated to fit; otherwise an
|
|
124
|
+
* `E_MVI_BUDGET_EXCEEDED` error envelope is returned.
|
|
125
|
+
*
|
|
69
126
|
* @example
|
|
70
127
|
* ```typescript
|
|
71
128
|
* const myHandler = async (request: Request) => ({ success: true, result: { data } });
|
|
@@ -76,9 +133,25 @@ export declare function withBudgetSync(budget: number, options?: BudgetEnforceme
|
|
|
76
133
|
export declare function wrapWithBudget<TArgs extends unknown[], TResult extends LAFSEnvelope>(handler: (...args: TArgs) => TResult | Promise<TResult>, budget: number, options?: BudgetEnforcementOptions): (...args: TArgs) => Promise<LAFSEnvelope>;
|
|
77
134
|
/**
|
|
78
135
|
* Compose multiple middleware functions into a single middleware.
|
|
79
|
-
*
|
|
136
|
+
*
|
|
137
|
+
* @param middlewares - Middleware functions to compose (executed left to right)
|
|
138
|
+
* @returns A single middleware function that chains all provided middlewares
|
|
139
|
+
*
|
|
140
|
+
* @remarks
|
|
141
|
+
* Middleware is executed in array order (left to right). Each middleware receives
|
|
142
|
+
* the envelope and a `next` function that invokes the subsequent middleware.
|
|
143
|
+
* The final middleware's `next` call invokes the original terminal handler.
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* ```typescript
|
|
147
|
+
* const pipeline = composeMiddleware(
|
|
148
|
+
* withBudget(1000),
|
|
149
|
+
* loggingMiddleware,
|
|
150
|
+
* );
|
|
151
|
+
* const result = await pipeline(envelope, () => finalEnvelope);
|
|
152
|
+
* ```
|
|
80
153
|
*/
|
|
81
154
|
export declare function composeMiddleware(...middlewares: EnvelopeMiddleware[]): EnvelopeMiddleware;
|
|
82
|
-
export type { BudgetEnforcementOptions,
|
|
83
|
-
export { TokenEstimator };
|
|
84
|
-
|
|
155
|
+
export type { BudgetEnforcementOptions, BudgetEnforcementResult, TokenEstimate };
|
|
156
|
+
export { BUDGET_EXCEEDED_CODE, TokenEstimator };
|
|
157
|
+
//# sourceMappingURL=budgetEnforcement.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"budgetEnforcement.d.ts","sourceRoot":"","sources":["../../src/budgetEnforcement.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,KAAK,EACV,wBAAwB,EACxB,uBAAuB,EACvB,YAAY,EAIZ,aAAa,EACd,MAA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Y,CAAC,CAM3C;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,WAAW,EAAE,kBAAkB,EAAE,GAAG,kBAAkB,CAsB1F;AAGD,YAAY,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,aAAa,EAAE,CAAC;AACjF,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,CAAC"}
|
|
@@ -4,17 +4,33 @@
|
|
|
4
4
|
* Middleware for enforcing MVI (Minimal Viable Interface) token budgets on LAFS envelopes.
|
|
5
5
|
* Provides budget checking, truncation, and error generation for exceeded budgets.
|
|
6
6
|
*/
|
|
7
|
-
import { TokenEstimator } from
|
|
7
|
+
import { TokenEstimator } from './tokenEstimator.js';
|
|
8
8
|
/**
|
|
9
|
-
* Budget exceeded error code from LAFS error registry
|
|
9
|
+
* Budget exceeded error code from LAFS error registry.
|
|
10
|
+
*
|
|
11
|
+
* @remarks
|
|
12
|
+
* Used as the `code` field in {@link LAFSError} when a response exceeds
|
|
13
|
+
* its declared MVI token budget.
|
|
10
14
|
*/
|
|
11
|
-
const BUDGET_EXCEEDED_CODE =
|
|
15
|
+
const BUDGET_EXCEEDED_CODE = 'E_MVI_BUDGET_EXCEEDED';
|
|
12
16
|
/**
|
|
13
|
-
* Default category for budget exceeded errors
|
|
17
|
+
* Default category for budget exceeded errors.
|
|
18
|
+
*
|
|
19
|
+
* @remarks
|
|
20
|
+
* Budget violations are treated as validation errors since they represent
|
|
21
|
+
* a contract violation between the caller's budget declaration and the response size.
|
|
14
22
|
*/
|
|
15
|
-
const BUDGET_ERROR_CATEGORY =
|
|
23
|
+
const BUDGET_ERROR_CATEGORY = 'VALIDATION';
|
|
16
24
|
/**
|
|
17
|
-
* Create a budget exceeded error object
|
|
25
|
+
* Create a budget exceeded error object.
|
|
26
|
+
*
|
|
27
|
+
* @param estimated - Estimated token count of the response
|
|
28
|
+
* @param budget - Maximum allowed token count
|
|
29
|
+
* @returns A {@link LAFSError} with code `E_MVI_BUDGET_EXCEEDED` and detailed metadata
|
|
30
|
+
*
|
|
31
|
+
* @remarks
|
|
32
|
+
* The error details include the exact token counts, the absolute overage,
|
|
33
|
+
* and the percentage by which the budget was exceeded.
|
|
18
34
|
*/
|
|
19
35
|
function createBudgetExceededError(estimated, budget) {
|
|
20
36
|
return {
|
|
@@ -32,8 +48,17 @@ function createBudgetExceededError(estimated, budget) {
|
|
|
32
48
|
};
|
|
33
49
|
}
|
|
34
50
|
/**
|
|
35
|
-
* Truncate a result to fit within budget.
|
|
36
|
-
*
|
|
51
|
+
* Truncate a result to fit within a token budget.
|
|
52
|
+
*
|
|
53
|
+
* @param result - The result payload (object, array, or `null`)
|
|
54
|
+
* @param targetTokens - Maximum allowed token count
|
|
55
|
+
* @param estimator - Token estimator instance for measuring sizes
|
|
56
|
+
* @returns Object containing the truncated result and a flag indicating if truncation occurred
|
|
57
|
+
*
|
|
58
|
+
* @remarks
|
|
59
|
+
* Delegates to array or object-specific truncation strategies. Arrays are
|
|
60
|
+
* truncated by removing trailing items via binary search; objects are truncated
|
|
61
|
+
* by removing trailing top-level keys.
|
|
37
62
|
*/
|
|
38
63
|
function truncateResult(result, targetTokens, estimator) {
|
|
39
64
|
if (result === null) {
|
|
@@ -52,7 +77,18 @@ function truncateResult(result, targetTokens, estimator) {
|
|
|
52
77
|
return truncateObject(result, targetChars, targetTokens, estimator);
|
|
53
78
|
}
|
|
54
79
|
/**
|
|
55
|
-
* Truncate an array to fit within budget.
|
|
80
|
+
* Truncate an array to fit within a token budget.
|
|
81
|
+
*
|
|
82
|
+
* @param arr - Array of result objects
|
|
83
|
+
* @param targetChars - Target character count (used for sizing heuristic)
|
|
84
|
+
* @param targetTokens - Target token budget
|
|
85
|
+
* @param estimator - Token estimator instance
|
|
86
|
+
* @returns Object containing the truncated array and a flag indicating if truncation occurred
|
|
87
|
+
*
|
|
88
|
+
* @remarks
|
|
89
|
+
* Uses binary search to find the maximum number of items that fit within
|
|
90
|
+
* the budget. Appends `_truncated` and `remainingItems` metadata to the
|
|
91
|
+
* last item when truncation occurs.
|
|
56
92
|
*/
|
|
57
93
|
function truncateArray(arr, targetChars, targetTokens, estimator) {
|
|
58
94
|
if (arr.length === 0) {
|
|
@@ -83,12 +119,14 @@ function truncateArray(arr, targetChars, targetTokens, estimator) {
|
|
|
83
119
|
// If we couldn't fit any items, return minimal response
|
|
84
120
|
if (bestFit === 0 && arr.length > 0) {
|
|
85
121
|
return {
|
|
86
|
-
result: [{ _truncated: true, reason:
|
|
87
|
-
wasTruncated: true
|
|
122
|
+
result: [{ _truncated: true, reason: 'budget_exceeded' }],
|
|
123
|
+
wasTruncated: true,
|
|
88
124
|
};
|
|
89
125
|
}
|
|
90
126
|
// Add truncation indicator to last element if it's an object
|
|
91
|
-
if (bestFit > 0 &&
|
|
127
|
+
if (bestFit > 0 &&
|
|
128
|
+
typeof truncated[bestFit - 1] === 'object' &&
|
|
129
|
+
truncated[bestFit - 1] !== null) {
|
|
92
130
|
const lastItem = truncated[bestFit - 1];
|
|
93
131
|
truncated[bestFit - 1] = {
|
|
94
132
|
...lastItem,
|
|
@@ -99,7 +137,18 @@ function truncateArray(arr, targetChars, targetTokens, estimator) {
|
|
|
99
137
|
return { result: truncated, wasTruncated: true };
|
|
100
138
|
}
|
|
101
139
|
/**
|
|
102
|
-
* Truncate an object to fit within budget.
|
|
140
|
+
* Truncate an object to fit within a token budget.
|
|
141
|
+
*
|
|
142
|
+
* @param obj - Object to truncate
|
|
143
|
+
* @param targetChars - Target character count (used for sizing heuristic)
|
|
144
|
+
* @param targetTokens - Target token budget
|
|
145
|
+
* @param estimator - Token estimator instance
|
|
146
|
+
* @returns Object containing the truncated object and a flag indicating if truncation occurred
|
|
147
|
+
*
|
|
148
|
+
* @remarks
|
|
149
|
+
* Uses binary search over the object's keys to find the maximum number of
|
|
150
|
+
* top-level properties that fit within the budget. Truncated results include
|
|
151
|
+
* `_truncated` and `_truncatedFields` metadata.
|
|
103
152
|
*/
|
|
104
153
|
function truncateObject(obj, targetChars, targetTokens, estimator) {
|
|
105
154
|
const keys = Object.keys(obj);
|
|
@@ -139,8 +188,8 @@ function truncateObject(obj, targetChars, targetTokens, estimator) {
|
|
|
139
188
|
// If we couldn't fit any properties, return minimal response
|
|
140
189
|
if (bestFit === 0) {
|
|
141
190
|
return {
|
|
142
|
-
result: { _truncated: true, reason:
|
|
143
|
-
wasTruncated: true
|
|
191
|
+
result: { _truncated: true, reason: 'budget_exceeded' },
|
|
192
|
+
wasTruncated: true,
|
|
144
193
|
};
|
|
145
194
|
}
|
|
146
195
|
// Add truncation metadata
|
|
@@ -152,9 +201,23 @@ function truncateObject(obj, targetChars, targetTokens, estimator) {
|
|
|
152
201
|
* Apply budget enforcement to an envelope.
|
|
153
202
|
*
|
|
154
203
|
* @param envelope - The LAFS envelope to check
|
|
155
|
-
* @param budget - Maximum allowed
|
|
156
|
-
* @param options - Budget enforcement options
|
|
157
|
-
* @returns
|
|
204
|
+
* @param budget - Maximum allowed token count
|
|
205
|
+
* @param options - Budget enforcement options (truncation, callbacks)
|
|
206
|
+
* @returns Enforcement result with the (possibly modified) envelope, budget status, and token estimates
|
|
207
|
+
*
|
|
208
|
+
* @remarks
|
|
209
|
+
* When the envelope is within budget, the token estimate is attached to metadata.
|
|
210
|
+
* When exceeded, behavior depends on `options.truncateOnExceed`: if enabled,
|
|
211
|
+
* truncation is attempted first; otherwise, the result is replaced with a
|
|
212
|
+
* budget-exceeded error. The `onBudgetExceeded` callback fires before truncation.
|
|
213
|
+
*
|
|
214
|
+
* @example
|
|
215
|
+
* ```typescript
|
|
216
|
+
* const result = applyBudgetEnforcement(envelope, 1000, { truncateOnExceed: true });
|
|
217
|
+
* if (!result.withinBudget) {
|
|
218
|
+
* console.warn("Budget exceeded:", result.estimatedTokens);
|
|
219
|
+
* }
|
|
220
|
+
* ```
|
|
158
221
|
*/
|
|
159
222
|
export function applyBudgetEnforcement(envelope, budget, options = {}) {
|
|
160
223
|
const { truncateOnExceed = false, onBudgetExceeded } = options;
|
|
@@ -189,7 +252,7 @@ export function applyBudgetEnforcement(envelope, budget, options = {}) {
|
|
|
189
252
|
}
|
|
190
253
|
// If truncation is enabled, try to truncate
|
|
191
254
|
if (truncateOnExceed) {
|
|
192
|
-
const { result
|
|
255
|
+
const { result } = truncateResult(envelope.result, budget, estimator);
|
|
193
256
|
const truncatedEstimate = estimator.estimate(result);
|
|
194
257
|
if (truncatedEstimate <= budget) {
|
|
195
258
|
return {
|
|
@@ -233,9 +296,14 @@ export function applyBudgetEnforcement(envelope, budget, options = {}) {
|
|
|
233
296
|
/**
|
|
234
297
|
* Create a budget enforcement middleware function.
|
|
235
298
|
*
|
|
236
|
-
* @param budget - Maximum allowed
|
|
237
|
-
* @param options - Budget enforcement options
|
|
238
|
-
* @returns
|
|
299
|
+
* @param budget - Maximum allowed token count for the response
|
|
300
|
+
* @param options - Budget enforcement options (truncation, callbacks)
|
|
301
|
+
* @returns Async middleware function that enforces the token budget
|
|
302
|
+
*
|
|
303
|
+
* @remarks
|
|
304
|
+
* Wraps the next handler in the chain, applying {@link applyBudgetEnforcement}
|
|
305
|
+
* to its output. The returned envelope may be truncated or replaced with an
|
|
306
|
+
* error depending on the enforcement result.
|
|
239
307
|
*
|
|
240
308
|
* @example
|
|
241
309
|
* ```typescript
|
|
@@ -256,8 +324,20 @@ export function withBudget(budget, options = {}) {
|
|
|
256
324
|
* Check if an envelope has exceeded its budget without modifying it.
|
|
257
325
|
*
|
|
258
326
|
* @param envelope - The LAFS envelope to check
|
|
259
|
-
* @param budget - Maximum allowed
|
|
260
|
-
* @returns
|
|
327
|
+
* @param budget - Maximum allowed token count
|
|
328
|
+
* @returns Object with `exceeded` flag, `estimated` token count, and `remaining` budget
|
|
329
|
+
*
|
|
330
|
+
* @remarks
|
|
331
|
+
* A read-only budget check that does not alter the envelope. Useful for
|
|
332
|
+
* pre-flight checks or logging before deciding how to handle overages.
|
|
333
|
+
*
|
|
334
|
+
* @example
|
|
335
|
+
* ```typescript
|
|
336
|
+
* const { exceeded, estimated, remaining } = checkBudget(envelope, 500);
|
|
337
|
+
* if (exceeded) {
|
|
338
|
+
* console.warn(`Over budget by ${estimated - 500} tokens`);
|
|
339
|
+
* }
|
|
340
|
+
* ```
|
|
261
341
|
*/
|
|
262
342
|
export function checkBudget(envelope, budget) {
|
|
263
343
|
const estimator = new TokenEstimator();
|
|
@@ -271,9 +351,19 @@ export function checkBudget(envelope, budget) {
|
|
|
271
351
|
/**
|
|
272
352
|
* Synchronous version of withBudget for non-async contexts.
|
|
273
353
|
*
|
|
274
|
-
* @param budget - Maximum allowed
|
|
275
|
-
* @param options - Budget enforcement options
|
|
276
|
-
* @returns
|
|
354
|
+
* @param budget - Maximum allowed token count for the response
|
|
355
|
+
* @param options - Budget enforcement options (truncation, callbacks)
|
|
356
|
+
* @returns Synchronous middleware function that enforces the token budget
|
|
357
|
+
*
|
|
358
|
+
* @remarks
|
|
359
|
+
* Identical to {@link withBudget} but operates synchronously. Use this when the
|
|
360
|
+
* next handler in the chain is guaranteed to return synchronously.
|
|
361
|
+
*
|
|
362
|
+
* @example
|
|
363
|
+
* ```typescript
|
|
364
|
+
* const middleware = withBudgetSync(500);
|
|
365
|
+
* const result = middleware(envelope, () => nextEnvelope);
|
|
366
|
+
* ```
|
|
277
367
|
*/
|
|
278
368
|
export function withBudgetSync(budget, options = {}) {
|
|
279
369
|
return (envelope, next) => {
|
|
@@ -286,10 +376,19 @@ export function withBudgetSync(budget, options = {}) {
|
|
|
286
376
|
* Higher-order function that wraps a handler with budget enforcement.
|
|
287
377
|
*
|
|
288
378
|
* @param handler - The handler function to wrap
|
|
379
|
+
* @typeParam TArgs - Tuple type representing the handler's parameter list
|
|
380
|
+
* @typeParam TResult - Return type of the handler, must extend LAFSEnvelope
|
|
381
|
+
* @param handler - The handler function to wrap with budget enforcement
|
|
289
382
|
* @param budget - Maximum allowed tokens
|
|
290
383
|
* @param options - Budget enforcement options
|
|
291
384
|
* @returns Wrapped handler with budget enforcement
|
|
292
385
|
*
|
|
386
|
+
* @remarks
|
|
387
|
+
* The returned function has the same parameter signature as the original handler
|
|
388
|
+
* but always returns a `Promise<LAFSEnvelope>`. When the budget is exceeded and
|
|
389
|
+
* `truncateOnExceed` is enabled, the envelope is truncated to fit; otherwise an
|
|
390
|
+
* `E_MVI_BUDGET_EXCEEDED` error envelope is returned.
|
|
391
|
+
*
|
|
293
392
|
* @example
|
|
294
393
|
* ```typescript
|
|
295
394
|
* const myHandler = async (request: Request) => ({ success: true, result: { data } });
|
|
@@ -306,11 +405,27 @@ export function wrapWithBudget(handler, budget, options = {}) {
|
|
|
306
405
|
}
|
|
307
406
|
/**
|
|
308
407
|
* Compose multiple middleware functions into a single middleware.
|
|
309
|
-
*
|
|
408
|
+
*
|
|
409
|
+
* @param middlewares - Middleware functions to compose (executed left to right)
|
|
410
|
+
* @returns A single middleware function that chains all provided middlewares
|
|
411
|
+
*
|
|
412
|
+
* @remarks
|
|
413
|
+
* Middleware is executed in array order (left to right). Each middleware receives
|
|
414
|
+
* the envelope and a `next` function that invokes the subsequent middleware.
|
|
415
|
+
* The final middleware's `next` call invokes the original terminal handler.
|
|
416
|
+
*
|
|
417
|
+
* @example
|
|
418
|
+
* ```typescript
|
|
419
|
+
* const pipeline = composeMiddleware(
|
|
420
|
+
* withBudget(1000),
|
|
421
|
+
* loggingMiddleware,
|
|
422
|
+
* );
|
|
423
|
+
* const result = await pipeline(envelope, () => finalEnvelope);
|
|
424
|
+
* ```
|
|
310
425
|
*/
|
|
311
426
|
export function composeMiddleware(...middlewares) {
|
|
312
427
|
return async (envelope, next) => {
|
|
313
|
-
|
|
428
|
+
const _index = 0;
|
|
314
429
|
async function dispatch(i) {
|
|
315
430
|
if (i >= middlewares.length) {
|
|
316
431
|
return next();
|
|
@@ -324,5 +439,5 @@ export function composeMiddleware(...middlewares) {
|
|
|
324
439
|
return dispatch(0);
|
|
325
440
|
};
|
|
326
441
|
}
|
|
327
|
-
export { TokenEstimator };
|
|
328
|
-
|
|
442
|
+
export { BUDGET_EXCEEDED_CODE, TokenEstimator };
|
|
443
|
+
//# sourceMappingURL=budgetEnforcement.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"budgetEnforcement.js","sourceRoot":"","sources":["../../src/budgetEnforcement.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAWrD;;;;;;GAMG;AACH,MAAM,oBAAoB,GAAG,uBAAuB,CAAC;AAErD;;;;;;GAMG;AACH,MAAM,qBAAqB,GAAsB,YAAY,CAAC;AAE9D;;;;;;;;;;GAUG;AACH,SAAS,yBAAyB,CAAC,SAAiB,EAAE,MAAc;IAClE,OAAO;QACL,IAAI,EAAE,oBAAoB;QAC1B,OAAO,EAAE,mDAAmD,SAAS,mBAAmB,MAAM,SAAS;QACvG,QAAQ,EAAE,qBAAqB;QAC/B,SAAS,EAAE,KAAK;QAChB,YAAY,EAAE,IAAI;QAClB,OAAO,EAAE;YACP,eAAe,EAAE,SAAS;YAC1B,YAAY,EAAE,MAAM;YACpB,UAAU,EAAE,SAAS,GAAG,MAAM;YAC9B,iBAAiB,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,GAAG,MAAM,CAAC,GAAG,MAAM,CAAC,GAAG,GAAG,CAAC;SACrE;KACF,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,SAAS,cAAc,CACrB,MAAkE,EAClE,YAAoB,EACpB,SAAyB;IAEzB,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;QACpB,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC;IAC/C,CAAC;IAED,MAAM,eAAe,GAAG,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAEnD,iDAAiD;IACjD,IAAI,eAAe,IAAI,YAAY,EAAE,CAAC;QACpC,OAAO,EAAE,MAAM,EAAE,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