@aldus-runtime/gate-engine 0.2.0-next.20 → 0.2.0-next.21
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/engine.js +2 -2
- package/dist/engine.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/spend.d.ts +126 -6
- package/dist/spend.d.ts.map +1 -1
- package/dist/spend.js +122 -6
- package/dist/spend.js.map +1 -1
- package/package.json +4 -4
- package/src/engine.ts +2 -2
- package/src/index.ts +6 -1
- package/src/spend.ts +248 -6
package/dist/engine.js
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
import { SCHEMA_VERSION, newEventId, newGateDecisionId, validate } from "@aldus-runtime/core";
|
|
19
19
|
import { assertSubjectsCover, detectDrift, } from "./binding.js";
|
|
20
20
|
import { GateEngineErrorCodes, gateEngineError } from "./errors.js";
|
|
21
|
-
import { checkSpend,
|
|
21
|
+
import { checkSpend, grantTermsDigest, } from "./spend.js";
|
|
22
22
|
/**
|
|
23
23
|
* What a gate currently is.
|
|
24
24
|
*
|
|
@@ -358,7 +358,7 @@ export class GateEngine {
|
|
|
358
358
|
"does not carry forward (§13.2).",
|
|
359
359
|
};
|
|
360
360
|
}
|
|
361
|
-
if (!decision.subjectHashes.includes(
|
|
361
|
+
if (!decision.subjectHashes.includes(grantTermsDigest(grant))) {
|
|
362
362
|
return {
|
|
363
363
|
authorized: false,
|
|
364
364
|
statuses: [status],
|
package/dist/engine.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine.js","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAGH,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAE9F,OAAO,EACL,mBAA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,CAAC;QAED,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;YAC9D,OAAO;gBACL,UAAU,EAAE,KAAK;gBACjB,QAAQ,EAAE,CAAC,MAAM,CAAC;gBAClB,WAAW,EACT,6BAA6B,KAAK,CAAC,QAAQ,CAAC,MAAM,IAAI,KAAK,CAAC,QAAQ,CAAC,QAAQ,UAAU;oBACvF,wBAAwB,QAAQ,CAAC,UAAU,uCAAuC;oBAClF,uFAAuF;oBACvF,uBAAuB;aAC1B,CAAC;QACJ,CAAC;QAED,MAAM,QAAQ,GAAG,KAAK,IAAI,CAAC,IAAI,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;QAC3F,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;QACnD,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;YACnB,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,CAAC,WAAW,EAAE,QAAQ,EAAE,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC;QAC1F,CAAC;QAED,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;IACrE,CAAC;CACF"}
|
package/dist/index.d.ts
CHANGED
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
export { GATE_ENFORCEMENTS, GATE_LEVELS, GateRegistry, validateGateDefinition, type GateDefinition, type GateEnforcement, type GateLevel, type PromotionEvidence, type ResolvedGateDefinition, } from "./definition.js";
|
|
31
31
|
export { assertSubjectsCover, detectDrift, digestBytes, digestSubjectValue, toSubjectHashes, type GateSubject, type SubjectDrift, } from "./binding.js";
|
|
32
32
|
export { GATE_STATES, GateEngine, type AuthorizationGrant, type AuthorizationRefusal, type AuthorizationResult, type DecideInput, type GateEngineOptions, type GateState, type GateStatus, type SpendAuthorization, type SubjectsByGate, } from "./engine.js";
|
|
33
|
-
export { SPEND_LIMIT_SUBJECT_KEY, checkSpend, computeLedger, consumesBudget, costRecordDraw,
|
|
33
|
+
export { SPEND_LIMIT_SUBJECT_KEY, availableAuthorization, checkSpendScope, unestimatedPolicyIsSatisfiable, checkSpend, computeLedger, consumesBudget, costRecordDraw, grantTermsDigest, type SpendAvailability, type SpendScopeRefusal, type SpendCheck, type SpendGrant, type SpendLedger, type SpendRefusalReason, type SpendRequest, } from "./spend.js";
|
|
34
34
|
export { addMoney, assertMoney, compareMoney, formatMoney, isNegativeMoney, isPositiveMoney, subtractMoney, sumMoney, zeroMoney, } from "./money.js";
|
|
35
35
|
export { MemoryCostReader, MemoryGateDecisionStore, MemoryGateEventSink, type CostReader, type GateDecisionStore, type GateEventSink, } from "./ports.js";
|
|
36
36
|
export { GateEngineErrorCodes, gateEngineError, type GateEngineErrorCode } from "./errors.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,EACL,iBAAiB,EACjB,WAAW,EACX,YAAY,EACZ,sBAAsB,EACtB,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,SAAS,EACd,KAAK,iBAAiB,EACtB,KAAK,sBAAsB,GAC5B,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,mBAAmB,EACnB,WAAW,EACX,WAAW,EACX,kBAAkB,EAClB,eAAe,EACf,KAAK,WAAW,EAChB,KAAK,YAAY,GAClB,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,WAAW,EACX,UAAU,EACV,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EACxB,KAAK,WAAW,EAChB,KAAK,iBAAiB,EACtB,KAAK,SAAS,EACd,KAAK,UAAU,EACf,KAAK,kBAAkB,EACvB,KAAK,cAAc,GACpB,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,uBAAuB,EACvB,UAAU,EACV,aAAa,EACb,cAAc,EACd,cAAc,EACd,iBAAiB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,EACL,iBAAiB,EACjB,WAAW,EACX,YAAY,EACZ,sBAAsB,EACtB,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,SAAS,EACd,KAAK,iBAAiB,EACtB,KAAK,sBAAsB,GAC5B,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,mBAAmB,EACnB,WAAW,EACX,WAAW,EACX,kBAAkB,EAClB,eAAe,EACf,KAAK,WAAW,EAChB,KAAK,YAAY,GAClB,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,WAAW,EACX,UAAU,EACV,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EACxB,KAAK,WAAW,EAChB,KAAK,iBAAiB,EACtB,KAAK,SAAS,EACd,KAAK,UAAU,EACf,KAAK,kBAAkB,EACvB,KAAK,cAAc,GACpB,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,uBAAuB,EACvB,sBAAsB,EACtB,eAAe,EACf,8BAA8B,EAC9B,UAAU,EACV,aAAa,EACb,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACvB,KAAK,YAAY,GAClB,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,WAAW,EACX,eAAe,EACf,eAAe,EACf,aAAa,EACb,QAAQ,EACR,SAAS,GACV,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,gBAAgB,EAChB,uBAAuB,EACvB,mBAAmB,EACnB,KAAK,UAAU,EACf,KAAK,iBAAiB,EACtB,KAAK,aAAa,GACnB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,KAAK,mBAAmB,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
export { GATE_ENFORCEMENTS, GATE_LEVELS, GateRegistry, validateGateDefinition, } from "./definition.js";
|
|
31
31
|
export { assertSubjectsCover, detectDrift, digestBytes, digestSubjectValue, toSubjectHashes, } from "./binding.js";
|
|
32
32
|
export { GATE_STATES, GateEngine, } from "./engine.js";
|
|
33
|
-
export { SPEND_LIMIT_SUBJECT_KEY, checkSpend, computeLedger, consumesBudget, costRecordDraw,
|
|
33
|
+
export { SPEND_LIMIT_SUBJECT_KEY, availableAuthorization, checkSpendScope, unestimatedPolicyIsSatisfiable, checkSpend, computeLedger, consumesBudget, costRecordDraw, grantTermsDigest, } from "./spend.js";
|
|
34
34
|
export { addMoney, assertMoney, compareMoney, formatMoney, isNegativeMoney, isPositiveMoney, subtractMoney, sumMoney, zeroMoney, } from "./money.js";
|
|
35
35
|
export { MemoryCostReader, MemoryGateDecisionStore, MemoryGateEventSink, } from "./ports.js";
|
|
36
36
|
export { GateEngineErrorCodes, gateEngineError } from "./errors.js";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,EACL,iBAAiB,EACjB,WAAW,EACX,YAAY,EACZ,sBAAsB,GAMvB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,mBAAmB,EACnB,WAAW,EACX,WAAW,EACX,kBAAkB,EAClB,eAAe,GAGhB,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,WAAW,EACX,UAAU,GAUX,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,uBAAuB,EACvB,UAAU,EACV,aAAa,EACb,cAAc,EACd,cAAc,EACd,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,EACL,iBAAiB,EACjB,WAAW,EACX,YAAY,EACZ,sBAAsB,GAMvB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,mBAAmB,EACnB,WAAW,EACX,WAAW,EACX,kBAAkB,EAClB,eAAe,GAGhB,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,WAAW,EACX,UAAU,GAUX,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,uBAAuB,EACvB,sBAAsB,EACtB,eAAe,EACf,8BAA8B,EAC9B,UAAU,EACV,aAAa,EACb,cAAc,EACd,cAAc,EACd,gBAAgB,GAQjB,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,WAAW,EACX,eAAe,EACf,eAAe,EACf,aAAa,EACb,QAAQ,EACR,SAAS,GACV,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,gBAAgB,EAChB,uBAAuB,EACvB,mBAAmB,GAIpB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAA4B,MAAM,aAAa,CAAC"}
|
package/dist/spend.d.ts
CHANGED
|
@@ -11,12 +11,12 @@
|
|
|
11
11
|
* `GateDecision` stores only digests. Carrying the limit in a record beside the decision would
|
|
12
12
|
* let someone raise the ceiling without touching the approval.
|
|
13
13
|
*
|
|
14
|
-
* So a grant does both: it holds the values, and {@link
|
|
14
|
+
* So a grant does both: it holds the values, and {@link grantTermsDigest} is included among the
|
|
15
15
|
* gate's bound subjects. Raising a limit changes that digest, which drifts from `subjectHashes`,
|
|
16
16
|
* which voids the authorization exactly as §13.2 requires. The ceiling cannot move without an
|
|
17
17
|
* operator re-approving it.
|
|
18
18
|
*/
|
|
19
|
-
import type
|
|
19
|
+
import { type CostRecord, type Money, type SpendReservation } from "@aldus-runtime/core";
|
|
20
20
|
/**
|
|
21
21
|
* The subject key under which a grant's limits are bound.
|
|
22
22
|
*
|
|
@@ -40,18 +40,50 @@ export interface SpendGrant {
|
|
|
40
40
|
* back to the approval that permitted it (§19.3 "explicit spend authorization").
|
|
41
41
|
*/
|
|
42
42
|
decisionId: string;
|
|
43
|
+
/**
|
|
44
|
+
* What this grant authorizes spending **on** (§13.2, §4.2).
|
|
45
|
+
*
|
|
46
|
+
* Operation names are adopter-defined open strings — `"agent.execute"`, `"tts.synthesize"`.
|
|
47
|
+
* Core names none.
|
|
48
|
+
*
|
|
49
|
+
* Present so that handing the wrong grant to an execution gateway cannot authorize an unrelated
|
|
50
|
+
* operation. Without it, "a grant" is a pool of money with no statement about what it is for,
|
|
51
|
+
* and the only thing keeping agent spend out of a synthesis ledger is which `decisionId` each
|
|
52
|
+
* happened to carry.
|
|
53
|
+
*/
|
|
54
|
+
scope: {
|
|
55
|
+
operations: readonly string[];
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Whether an execution with no estimate may be dispatched (§13.2, §19.3; ADR-0044).
|
|
59
|
+
*
|
|
60
|
+
* Operator-approved policy, so it lives on the grant and is bound by
|
|
61
|
+
* {@link grantTermsDigest} — changing it invalidates the approval exactly as changing a ceiling
|
|
62
|
+
* or the scope does. It must never be supplied by an execution input or an adapter: a caller
|
|
63
|
+
* that could assert its own permission is the shape #107 exists to prevent.
|
|
64
|
+
*
|
|
65
|
+
* A closed pair rather than a boolean. `permitUnestimated: true` invites being flipped in a
|
|
66
|
+
* config file; naming the reservation it implies makes the consequence part of the decision.
|
|
67
|
+
*
|
|
68
|
+
* Absent reads as `"refuse"`.
|
|
69
|
+
*/
|
|
70
|
+
unestimatedExecution?: "refuse" | "reserve_max_per_request";
|
|
43
71
|
/** Maximum total spend authorized across the Run (§13.2 "maximum authorized cost"). */
|
|
44
72
|
maxTotal: Money;
|
|
45
73
|
/** Maximum spend authorized for any single request (§19.3 "per-request ... limits"). */
|
|
46
74
|
maxPerRequest?: Money;
|
|
47
75
|
}
|
|
48
76
|
/**
|
|
49
|
-
* The digest a gate must bind for the grant's
|
|
77
|
+
* The digest a gate must bind for the grant's **terms** to be tamper-evident (§13.2).
|
|
78
|
+
*
|
|
79
|
+
* Was `grantTermsDigest`, covering the ceilings alone. Scope is now a term too: changing a grant
|
|
80
|
+
* from agent-only to TTS-capable widens what an approval permits exactly as raising its ceiling
|
|
81
|
+
* does, and an approval that survives that change did not bind what it appeared to bind.
|
|
50
82
|
*
|
|
51
|
-
* Only the
|
|
52
|
-
*
|
|
83
|
+
* Only the terms are digested, not the grant's identity: re-issuing an identical grant under a new
|
|
84
|
+
* `grantId` should not read as the operator having approved something different.
|
|
53
85
|
*/
|
|
54
|
-
export declare function
|
|
86
|
+
export declare function grantTermsDigest(grant: SpendGrant): string;
|
|
55
87
|
/**
|
|
56
88
|
* Whether a cost record consumes budget.
|
|
57
89
|
*
|
|
@@ -118,6 +150,94 @@ export declare function isUnresolvedUnknownCharge(record: CostRecord): boolean;
|
|
|
118
150
|
* silently absorbing it would make one gate's ceiling depend on another's spending.
|
|
119
151
|
*/
|
|
120
152
|
export declare function computeLedger(grant: SpendGrant, costs: readonly CostRecord[]): SpendLedger;
|
|
153
|
+
/**
|
|
154
|
+
* Authorization available to commit, derived rather than maintained (ADR-0044; #155).
|
|
155
|
+
*
|
|
156
|
+
* ```text
|
|
157
|
+
* available = authorized maximum − settled charges − active reservations
|
|
158
|
+
* ```
|
|
159
|
+
*
|
|
160
|
+
* Derived on every read, never stored as a balance. A maintained counter is a second source of
|
|
161
|
+
* truth about money, reconciled by hand against the records it summarises — and every defect this
|
|
162
|
+
* repository has fixed in the cost path has been a value asserting more than what established it.
|
|
163
|
+
*/
|
|
164
|
+
export interface SpendAvailability {
|
|
165
|
+
/** The ceiling the operator approved. */
|
|
166
|
+
authorized: Money;
|
|
167
|
+
/** Charges already recorded against it. */
|
|
168
|
+
settled: Money;
|
|
169
|
+
/** Authorization committed to effects that have not settled. */
|
|
170
|
+
reserved: Money;
|
|
171
|
+
/**
|
|
172
|
+
* What may still be committed. Never negative.
|
|
173
|
+
*
|
|
174
|
+
* **Read {@link SpendAvailability.determinate} before spending against this.** The figure is the
|
|
175
|
+
* arithmetic over what is known, and while an unresolved charge of unknown size stands, what is
|
|
176
|
+
* known is not all there is.
|
|
177
|
+
*/
|
|
178
|
+
available: Money;
|
|
179
|
+
/** Whether {@link SpendAvailability.available} is an amount anyone may commit against. */
|
|
180
|
+
determinate: boolean;
|
|
181
|
+
/**
|
|
182
|
+
* Why it is not, where it is not.
|
|
183
|
+
*
|
|
184
|
+
* Two independent sources, kept apart because they carry different evidence:
|
|
185
|
+
*
|
|
186
|
+
* - reservations in `billing_unknown` whose exposure is not bounded by an enforced ceiling;
|
|
187
|
+
* - cost records of unknown size with no reservation at all, which is every such record written
|
|
188
|
+
* before this protocol existed (#150).
|
|
189
|
+
*/
|
|
190
|
+
indeterminate: {
|
|
191
|
+
unboundedReservations: SpendReservation[];
|
|
192
|
+
unreservedUnknownCharges: CostRecord[];
|
|
193
|
+
};
|
|
194
|
+
/**
|
|
195
|
+
* Reserved-but-unsettled amounts, per **authorization** currency (ADR-0044).
|
|
196
|
+
*
|
|
197
|
+
* Not the provider's billing currency. This states what Aldus set aside; what a provider charged,
|
|
198
|
+
* and in what currency, is a separate fact that may not exist yet. A report may say "USD 2.00
|
|
199
|
+
* remains reserved because billing is unresolved"; it must never restate that as "the provider
|
|
200
|
+
* made an unknown USD charge".
|
|
201
|
+
*/
|
|
202
|
+
reservedUnknownByCurrency: Record<string, string>;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Derive what a grant still authorizes (§19.3; ADR-0044).
|
|
206
|
+
*
|
|
207
|
+
* Composes with #150 rather than replacing it. A charge of unknown size still makes the grant
|
|
208
|
+
* indeterminate — what a reservation adds is the possibility of a *bound*, and only when the
|
|
209
|
+
* execution that produced the charge was actually dispatched under an enforced ceiling. A backend
|
|
210
|
+
* that declares enforcement today is not evidence about a request dispatched by an earlier version
|
|
211
|
+
* (ADR-0030).
|
|
212
|
+
*/
|
|
213
|
+
export declare function availableAuthorization(grant: SpendGrant, costs: readonly CostRecord[], reservations?: readonly SpendReservation[]): SpendAvailability;
|
|
214
|
+
/**
|
|
215
|
+
* Whether a grant can truthfully permit an unestimated execution (ADR-0044; #155).
|
|
216
|
+
*
|
|
217
|
+
* `reserve_max_per_request` promises to reserve the per-request ceiling. A grant that permits it
|
|
218
|
+
* and states no such ceiling promises an amount it does not have — and reserving zero instead
|
|
219
|
+
* would make unestimated executions invisible to concurrency control, which is the case most
|
|
220
|
+
* likely to be dispatched in a loop.
|
|
221
|
+
*
|
|
222
|
+
* Checked at decode **and** before dispatch: a grant assembled from configuration never passes
|
|
223
|
+
* through the constructor that would have caught it.
|
|
224
|
+
*/
|
|
225
|
+
export declare function unestimatedPolicyIsSatisfiable(grant: SpendGrant): string | undefined;
|
|
226
|
+
/** Why a grant does not authorize an operation. */
|
|
227
|
+
export interface SpendScopeRefusal {
|
|
228
|
+
operation: string;
|
|
229
|
+
authorized: readonly string[];
|
|
230
|
+
explanation: string;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Whether a grant authorizes an operation (§13.2, §4.2; #155).
|
|
234
|
+
*
|
|
235
|
+
* Checked before reserving, so handing the wrong grant to an execution gateway cannot authorize
|
|
236
|
+
* unrelated work. Without it a grant is a pool of money with no statement about what it is for,
|
|
237
|
+
* and the only thing separating agent spend from a synthesis ledger is which decision each
|
|
238
|
+
* happened to name.
|
|
239
|
+
*/
|
|
240
|
+
export declare function checkSpendScope(grant: SpendGrant, operation: string): SpendScopeRefusal | undefined;
|
|
121
241
|
/** A request to spend against a grant. */
|
|
122
242
|
export interface SpendRequest {
|
|
123
243
|
/** The amount about to be committed. */
|
package/dist/spend.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spend.d.ts","sourceRoot":"","sources":["../src/spend.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"spend.d.ts","sourceRoot":"","sources":["../src/spend.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAGL,KAAK,UAAU,EACf,KAAK,KAAK,EACV,KAAK,gBAAgB,EACtB,MAAM,qBAAqB,CAAC;AAa7B;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB,eAAe,CAAC;AAEpD,8FAA8F;AAC9F,MAAM,WAAW,UAAU;IACzB,8BAA8B;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,gCAAgC;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,iDAAiD;IACjD,MAAM,EAAE,MAAM,CAAC;IACf;;;;;OAKG;IACH,UAAU,EAAE,MAAM,CAAC;IACnB;;;;;;;;;;OAUG;IACH,KAAK,EAAE;QACL,UAAU,EAAE,SAAS,MAAM,EAAE,CAAC;KAC/B,CAAC;IACF;;;;;;;;;;;;OAYG;IACH,oBAAoB,CAAC,EAAE,QAAQ,GAAG,yBAAyB,CAAC;IAC5D,uFAAuF;IACvF,QAAQ,EAAE,KAAK,CAAC;IAChB,wFAAwF;IACxF,aAAa,CAAC,EAAE,KAAK,CAAC;CACvB;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAS1D;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAE1D;AAED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
|
|
|
11
11
|
* `GateDecision` stores only digests. Carrying the limit in a record beside the decision would
|
|
12
12
|
* let someone raise the ceiling without touching the approval.
|
|
13
13
|
*
|
|
14
|
-
* So a grant does both: it holds the values, and {@link
|
|
14
|
+
* So a grant does both: it holds the values, and {@link grantTermsDigest} is included among the
|
|
15
15
|
* gate's bound subjects. Raising a limit changes that digest, which drifts from `subjectHashes`,
|
|
16
16
|
* which voids the authorization exactly as §13.2 requires. The ceiling cannot move without an
|
|
17
17
|
* operator re-approving it.
|
|
18
18
|
*/
|
|
19
|
+
import { reservationExposureIsBounded, reservationIsActive, } from "@aldus-runtime/core";
|
|
19
20
|
import { digestSubjectValue } from "./binding.js";
|
|
20
|
-
import { addMoney, compareMoney, formatMoney, isNegativeMoney, subtractMoney, zeroMoney, } from "./money.js";
|
|
21
|
+
import { addMoney, compareMoney, formatMoney, isNegativeMoney, isPositiveMoney, subtractMoney, zeroMoney, } from "./money.js";
|
|
21
22
|
/**
|
|
22
23
|
* The subject key under which a grant's limits are bound.
|
|
23
24
|
*
|
|
@@ -27,13 +28,21 @@ import { addMoney, compareMoney, formatMoney, isNegativeMoney, subtractMoney, ze
|
|
|
27
28
|
*/
|
|
28
29
|
export const SPEND_LIMIT_SUBJECT_KEY = "spendLimit";
|
|
29
30
|
/**
|
|
30
|
-
* The digest a gate must bind for the grant's
|
|
31
|
+
* The digest a gate must bind for the grant's **terms** to be tamper-evident (§13.2).
|
|
31
32
|
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
33
|
+
* Was `grantTermsDigest`, covering the ceilings alone. Scope is now a term too: changing a grant
|
|
34
|
+
* from agent-only to TTS-capable widens what an approval permits exactly as raising its ceiling
|
|
35
|
+
* does, and an approval that survives that change did not bind what it appeared to bind.
|
|
36
|
+
*
|
|
37
|
+
* Only the terms are digested, not the grant's identity: re-issuing an identical grant under a new
|
|
38
|
+
* `grantId` should not read as the operator having approved something different.
|
|
34
39
|
*/
|
|
35
|
-
export function
|
|
40
|
+
export function grantTermsDigest(grant) {
|
|
36
41
|
return digestSubjectValue({
|
|
42
|
+
// Sorted, because the *set* of authorized operations is the term, not the order an adopter
|
|
43
|
+
// listed them in — the same reason ADR-0033 sorts release input hashes.
|
|
44
|
+
scope: { operations: [...grant.scope.operations].sort() },
|
|
45
|
+
unestimatedExecution: grant.unestimatedExecution ?? "refuse",
|
|
37
46
|
maxTotal: grant.maxTotal,
|
|
38
47
|
maxPerRequest: grant.maxPerRequest ?? null,
|
|
39
48
|
});
|
|
@@ -106,6 +115,113 @@ export function computeLedger(grant, costs) {
|
|
|
106
115
|
remainingIsDeterminate: unresolvedUnknown.length === 0,
|
|
107
116
|
};
|
|
108
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* Derive what a grant still authorizes (§19.3; ADR-0044).
|
|
120
|
+
*
|
|
121
|
+
* Composes with #150 rather than replacing it. A charge of unknown size still makes the grant
|
|
122
|
+
* indeterminate — what a reservation adds is the possibility of a *bound*, and only when the
|
|
123
|
+
* execution that produced the charge was actually dispatched under an enforced ceiling. A backend
|
|
124
|
+
* that declares enforcement today is not evidence about a request dispatched by an earlier version
|
|
125
|
+
* (ADR-0030).
|
|
126
|
+
*/
|
|
127
|
+
export function availableAuthorization(grant, costs, reservations = []) {
|
|
128
|
+
const currency = grant.maxTotal.currency;
|
|
129
|
+
const ledger = computeLedger(grant, costs);
|
|
130
|
+
// Per grant, never per decision. The grant is the budget pool; the decision is who authorized
|
|
131
|
+
// its terms. One decision may establish several grants — an episode-level ceiling above an agent
|
|
132
|
+
// grant and a TTS grant — and deriving availability per decision would silently aggregate them.
|
|
133
|
+
const mine = reservations.filter((reservation) => reservation.grantId === grant.grantId);
|
|
134
|
+
const active = mine.filter(reservationIsActive);
|
|
135
|
+
// Settled reservations are already represented by the cost records that settled them. Counting
|
|
136
|
+
// both would double-count the same money against the ceiling.
|
|
137
|
+
let reserved = zeroMoney(currency);
|
|
138
|
+
const reservedUnknownByCurrency = new Map();
|
|
139
|
+
for (const reservation of active) {
|
|
140
|
+
if (reservation.reserved.currency === currency) {
|
|
141
|
+
reserved = addMoney(reserved, reservation.reserved);
|
|
142
|
+
}
|
|
143
|
+
if (reservation.status === "billing_unknown") {
|
|
144
|
+
const running = reservedUnknownByCurrency.get(reservation.reserved.currency) ??
|
|
145
|
+
zeroMoney(reservation.reserved.currency);
|
|
146
|
+
reservedUnknownByCurrency.set(reservation.reserved.currency, addMoney(running, reservation.reserved));
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
const unboundedReservations = active.filter((reservation) => reservation.status === "billing_unknown" && !reservationExposureIsBounded(reservation));
|
|
150
|
+
// #150's rule, narrowed by what a reservation can now establish. A record of unknown size whose
|
|
151
|
+
// reservation is bounded is accounted for; one with no reservation is not, and that is every
|
|
152
|
+
// such record written before this protocol.
|
|
153
|
+
const boundedReservationIds = new Set(active
|
|
154
|
+
.filter((reservation) => reservationExposureIsBounded(reservation))
|
|
155
|
+
.map((reservation) => reservation.reservationId));
|
|
156
|
+
// `computeLedger` filters cost records by `authorizationId`, which is the legacy link and stays
|
|
157
|
+
// correct: a record written before reservations existed has no `reservationId` to reach a grant
|
|
158
|
+
// through, and its decision is the only thing tying it to an authorization (#155).
|
|
159
|
+
const unreservedUnknownCharges = ledger.counted.filter((record) => isUnresolvedUnknownCharge(record) &&
|
|
160
|
+
(record.reservationId === undefined || !boundedReservationIds.has(record.reservationId)));
|
|
161
|
+
const headroom = subtractMoney(subtractMoney(grant.maxTotal, ledger.consumed), reserved);
|
|
162
|
+
return {
|
|
163
|
+
authorized: grant.maxTotal,
|
|
164
|
+
settled: ledger.consumed,
|
|
165
|
+
reserved,
|
|
166
|
+
available: isNegativeMoney(headroom) ? zeroMoney(currency) : headroom,
|
|
167
|
+
determinate: unboundedReservations.length === 0 && unreservedUnknownCharges.length === 0,
|
|
168
|
+
indeterminate: { unboundedReservations, unreservedUnknownCharges },
|
|
169
|
+
reservedUnknownByCurrency: Object.fromEntries([...reservedUnknownByCurrency.entries()]
|
|
170
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
171
|
+
.map(([code, money]) => [code, money.amount])),
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Whether a grant can truthfully permit an unestimated execution (ADR-0044; #155).
|
|
176
|
+
*
|
|
177
|
+
* `reserve_max_per_request` promises to reserve the per-request ceiling. A grant that permits it
|
|
178
|
+
* and states no such ceiling promises an amount it does not have — and reserving zero instead
|
|
179
|
+
* would make unestimated executions invisible to concurrency control, which is the case most
|
|
180
|
+
* likely to be dispatched in a loop.
|
|
181
|
+
*
|
|
182
|
+
* Checked at decode **and** before dispatch: a grant assembled from configuration never passes
|
|
183
|
+
* through the constructor that would have caught it.
|
|
184
|
+
*/
|
|
185
|
+
export function unestimatedPolicyIsSatisfiable(grant) {
|
|
186
|
+
if ((grant.unestimatedExecution ?? "refuse") !== "reserve_max_per_request")
|
|
187
|
+
return undefined;
|
|
188
|
+
const ceiling = grant.maxPerRequest;
|
|
189
|
+
if (ceiling === undefined) {
|
|
190
|
+
return (`Grant "${grant.grantId}" permits unestimated execution by reserving its per-request ` +
|
|
191
|
+
"ceiling, and states no ceiling. There is no truthful amount to reserve, so this cannot be " +
|
|
192
|
+
"dispatched (§13.2, §19.3).");
|
|
193
|
+
}
|
|
194
|
+
if (!isPositiveMoney(ceiling)) {
|
|
195
|
+
return (`Grant "${grant.grantId}" permits unestimated execution by reserving its per-request ` +
|
|
196
|
+
`ceiling, and that ceiling is ${formatMoney(ceiling)}. Reserving zero would make an ` +
|
|
197
|
+
"unestimated execution invisible to concurrency control.");
|
|
198
|
+
}
|
|
199
|
+
if (ceiling.currency !== grant.maxTotal.currency) {
|
|
200
|
+
return (`Grant "${grant.grantId}" states a per-request ceiling in ${ceiling.currency} and a total ` +
|
|
201
|
+
`in ${grant.maxTotal.currency}. A reservation is denominated in the grant's currency, and ` +
|
|
202
|
+
"converting implicitly is not something this runtime does (ADR-0044).");
|
|
203
|
+
}
|
|
204
|
+
return undefined;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Whether a grant authorizes an operation (§13.2, §4.2; #155).
|
|
208
|
+
*
|
|
209
|
+
* Checked before reserving, so handing the wrong grant to an execution gateway cannot authorize
|
|
210
|
+
* unrelated work. Without it a grant is a pool of money with no statement about what it is for,
|
|
211
|
+
* and the only thing separating agent spend from a synthesis ledger is which decision each
|
|
212
|
+
* happened to name.
|
|
213
|
+
*/
|
|
214
|
+
export function checkSpendScope(grant, operation) {
|
|
215
|
+
if (grant.scope.operations.includes(operation))
|
|
216
|
+
return undefined;
|
|
217
|
+
return {
|
|
218
|
+
operation,
|
|
219
|
+
authorized: [...grant.scope.operations],
|
|
220
|
+
explanation: `Grant "${grant.grantId}" authorizes ${grant.scope.operations.map((entry) => `"${entry}"`).join(", ") || "nothing"} ` +
|
|
221
|
+
`and this operation is "${operation}". A grant states what it may be spent on as well as ` +
|
|
222
|
+
"how much, so passing the wrong one to a gateway cannot authorize unrelated work (§13.2).",
|
|
223
|
+
};
|
|
224
|
+
}
|
|
109
225
|
/**
|
|
110
226
|
* Decide whether a spend may proceed (§19.3 stop-on-budget).
|
|
111
227
|
*
|
package/dist/spend.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spend.js","sourceRoot":"","sources":["../src/spend.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;
|
|
1
|
+
{"version":3,"file":"spend.js","sourceRoot":"","sources":["../src/spend.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EACL,4BAA4B,EAC5B,mBAAmB,GAIpB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EACL,QAAQ,EACR,YAAY,EACZ,WAAW,EACX,eAAe,EACf,eAAe,EACf,aAAa,EACb,SAAS,GACV,MAAM,YAAY,CAAC;AAEpB;;;;;;GAMG;AACH,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AAE,CAAC;QAC/F,OAAO;YACL,OAAO,EAAE,KAAK;YACd,MAAM,EAAE,mBAAmB;YAC3B,MAAM;YACN,WAAW,EACT,uBAAuB,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC,oCAAoC;gBACtF,GAAG,WAAW,CAAC,KAAK,CAAC,aAAa,CAAC,WAAW;SACjD,CAAC;IACJ,CAAC;IAED,MAAM,SAAS,GAAG,QAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IAC5D,IAAI,YAAY,CAAC,SAAS,EAAE,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QAChD,OAAO;YACL,OAAO,EAAE,KAAK;YACd,MAAM,EAAE,aAAa;YACrB,MAAM;YACN,WAAW,EACT,YAAY,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC,4BAA4B;gBACnE,GAAG,WAAW,CAAC,SAAS,CAAC,mCAAmC;gBAC5D,GAAG,WAAW,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,WAAW,CAAC,MAAM,CAAC,SAAS,CAAC,mBAAmB;SACtF,CAAC;IACJ,CAAC;IAED,OAAO;QACL,OAAO,EAAE,IAAI;QACb,MAAM;QACN,cAAc,EAAE,aAAa,CAAC,KAAK,CAAC,QAAQ,EAAE,SAAS,CAAC;KACzD,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aldus-runtime/gate-engine",
|
|
3
|
-
"version": "0.2.0-next.
|
|
3
|
+
"version": "0.2.0-next.21",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"description": "Aldus Gate Engine
|
|
5
|
+
"description": "Aldus Gate Engine — hash-bound human gates, cascading invalidation, and spend authorization.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
@@ -33,10 +33,10 @@
|
|
|
33
33
|
"typecheck:test": "tsc -p tsconfig.test.json"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@aldus-runtime/core": "0.2.0-next.
|
|
36
|
+
"@aldus-runtime/core": "0.2.0-next.21"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@aldus-runtime/testkit": "0.2.0-next.
|
|
39
|
+
"@aldus-runtime/testkit": "0.2.0-next.21",
|
|
40
40
|
"@types/node": "^26.2.0",
|
|
41
41
|
"typescript": "^7.0.2",
|
|
42
42
|
"vitest": "^4.1.10"
|
package/src/engine.ts
CHANGED
|
@@ -35,7 +35,7 @@ import { GateEngineErrorCodes, gateEngineError } from "./errors.js";
|
|
|
35
35
|
import type { CostReader, GateDecisionStore, GateEventSink } from "./ports.js";
|
|
36
36
|
import {
|
|
37
37
|
checkSpend,
|
|
38
|
-
|
|
38
|
+
grantTermsDigest,
|
|
39
39
|
type SpendCheck,
|
|
40
40
|
type SpendGrant,
|
|
41
41
|
type SpendRequest,
|
|
@@ -551,7 +551,7 @@ export class GateEngine {
|
|
|
551
551
|
};
|
|
552
552
|
}
|
|
553
553
|
|
|
554
|
-
if (!decision.subjectHashes.includes(
|
|
554
|
+
if (!decision.subjectHashes.includes(grantTermsDigest(grant))) {
|
|
555
555
|
return {
|
|
556
556
|
authorized: false,
|
|
557
557
|
statuses: [status],
|
package/src/index.ts
CHANGED
|
@@ -66,11 +66,16 @@ export {
|
|
|
66
66
|
|
|
67
67
|
export {
|
|
68
68
|
SPEND_LIMIT_SUBJECT_KEY,
|
|
69
|
+
availableAuthorization,
|
|
70
|
+
checkSpendScope,
|
|
71
|
+
unestimatedPolicyIsSatisfiable,
|
|
69
72
|
checkSpend,
|
|
70
73
|
computeLedger,
|
|
71
74
|
consumesBudget,
|
|
72
75
|
costRecordDraw,
|
|
73
|
-
|
|
76
|
+
grantTermsDigest,
|
|
77
|
+
type SpendAvailability,
|
|
78
|
+
type SpendScopeRefusal,
|
|
74
79
|
type SpendCheck,
|
|
75
80
|
type SpendGrant,
|
|
76
81
|
type SpendLedger,
|
package/src/spend.ts
CHANGED
|
@@ -11,13 +11,19 @@
|
|
|
11
11
|
* `GateDecision` stores only digests. Carrying the limit in a record beside the decision would
|
|
12
12
|
* let someone raise the ceiling without touching the approval.
|
|
13
13
|
*
|
|
14
|
-
* So a grant does both: it holds the values, and {@link
|
|
14
|
+
* So a grant does both: it holds the values, and {@link grantTermsDigest} is included among the
|
|
15
15
|
* gate's bound subjects. Raising a limit changes that digest, which drifts from `subjectHashes`,
|
|
16
16
|
* which voids the authorization exactly as §13.2 requires. The ceiling cannot move without an
|
|
17
17
|
* operator re-approving it.
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
|
-
import
|
|
20
|
+
import {
|
|
21
|
+
reservationExposureIsBounded,
|
|
22
|
+
reservationIsActive,
|
|
23
|
+
type CostRecord,
|
|
24
|
+
type Money,
|
|
25
|
+
type SpendReservation,
|
|
26
|
+
} from "@aldus-runtime/core";
|
|
21
27
|
|
|
22
28
|
import { digestSubjectValue } from "./binding.js";
|
|
23
29
|
import {
|
|
@@ -25,6 +31,7 @@ import {
|
|
|
25
31
|
compareMoney,
|
|
26
32
|
formatMoney,
|
|
27
33
|
isNegativeMoney,
|
|
34
|
+
isPositiveMoney,
|
|
28
35
|
subtractMoney,
|
|
29
36
|
zeroMoney,
|
|
30
37
|
} from "./money.js";
|
|
@@ -53,6 +60,34 @@ export interface SpendGrant {
|
|
|
53
60
|
* back to the approval that permitted it (§19.3 "explicit spend authorization").
|
|
54
61
|
*/
|
|
55
62
|
decisionId: string;
|
|
63
|
+
/**
|
|
64
|
+
* What this grant authorizes spending **on** (§13.2, §4.2).
|
|
65
|
+
*
|
|
66
|
+
* Operation names are adopter-defined open strings — `"agent.execute"`, `"tts.synthesize"`.
|
|
67
|
+
* Core names none.
|
|
68
|
+
*
|
|
69
|
+
* Present so that handing the wrong grant to an execution gateway cannot authorize an unrelated
|
|
70
|
+
* operation. Without it, "a grant" is a pool of money with no statement about what it is for,
|
|
71
|
+
* and the only thing keeping agent spend out of a synthesis ledger is which `decisionId` each
|
|
72
|
+
* happened to carry.
|
|
73
|
+
*/
|
|
74
|
+
scope: {
|
|
75
|
+
operations: readonly string[];
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Whether an execution with no estimate may be dispatched (§13.2, §19.3; ADR-0044).
|
|
79
|
+
*
|
|
80
|
+
* Operator-approved policy, so it lives on the grant and is bound by
|
|
81
|
+
* {@link grantTermsDigest} — changing it invalidates the approval exactly as changing a ceiling
|
|
82
|
+
* or the scope does. It must never be supplied by an execution input or an adapter: a caller
|
|
83
|
+
* that could assert its own permission is the shape #107 exists to prevent.
|
|
84
|
+
*
|
|
85
|
+
* A closed pair rather than a boolean. `permitUnestimated: true` invites being flipped in a
|
|
86
|
+
* config file; naming the reservation it implies makes the consequence part of the decision.
|
|
87
|
+
*
|
|
88
|
+
* Absent reads as `"refuse"`.
|
|
89
|
+
*/
|
|
90
|
+
unestimatedExecution?: "refuse" | "reserve_max_per_request";
|
|
56
91
|
/** Maximum total spend authorized across the Run (§13.2 "maximum authorized cost"). */
|
|
57
92
|
maxTotal: Money;
|
|
58
93
|
/** Maximum spend authorized for any single request (§19.3 "per-request ... limits"). */
|
|
@@ -60,13 +95,21 @@ export interface SpendGrant {
|
|
|
60
95
|
}
|
|
61
96
|
|
|
62
97
|
/**
|
|
63
|
-
* The digest a gate must bind for the grant's
|
|
98
|
+
* The digest a gate must bind for the grant's **terms** to be tamper-evident (§13.2).
|
|
64
99
|
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
100
|
+
* Was `grantTermsDigest`, covering the ceilings alone. Scope is now a term too: changing a grant
|
|
101
|
+
* from agent-only to TTS-capable widens what an approval permits exactly as raising its ceiling
|
|
102
|
+
* does, and an approval that survives that change did not bind what it appeared to bind.
|
|
103
|
+
*
|
|
104
|
+
* Only the terms are digested, not the grant's identity: re-issuing an identical grant under a new
|
|
105
|
+
* `grantId` should not read as the operator having approved something different.
|
|
67
106
|
*/
|
|
68
|
-
export function
|
|
107
|
+
export function grantTermsDigest(grant: SpendGrant): string {
|
|
69
108
|
return digestSubjectValue({
|
|
109
|
+
// Sorted, because the *set* of authorized operations is the term, not the order an adopter
|
|
110
|
+
// listed them in — the same reason ADR-0033 sorts release input hashes.
|
|
111
|
+
scope: { operations: [...grant.scope.operations].sort() },
|
|
112
|
+
unestimatedExecution: grant.unestimatedExecution ?? "refuse",
|
|
70
113
|
maxTotal: grant.maxTotal,
|
|
71
114
|
maxPerRequest: grant.maxPerRequest ?? null,
|
|
72
115
|
});
|
|
@@ -178,6 +221,205 @@ export function computeLedger(grant: SpendGrant, costs: readonly CostRecord[]):
|
|
|
178
221
|
};
|
|
179
222
|
}
|
|
180
223
|
|
|
224
|
+
/**
|
|
225
|
+
* Authorization available to commit, derived rather than maintained (ADR-0044; #155).
|
|
226
|
+
*
|
|
227
|
+
* ```text
|
|
228
|
+
* available = authorized maximum − settled charges − active reservations
|
|
229
|
+
* ```
|
|
230
|
+
*
|
|
231
|
+
* Derived on every read, never stored as a balance. A maintained counter is a second source of
|
|
232
|
+
* truth about money, reconciled by hand against the records it summarises — and every defect this
|
|
233
|
+
* repository has fixed in the cost path has been a value asserting more than what established it.
|
|
234
|
+
*/
|
|
235
|
+
export interface SpendAvailability {
|
|
236
|
+
/** The ceiling the operator approved. */
|
|
237
|
+
authorized: Money;
|
|
238
|
+
/** Charges already recorded against it. */
|
|
239
|
+
settled: Money;
|
|
240
|
+
/** Authorization committed to effects that have not settled. */
|
|
241
|
+
reserved: Money;
|
|
242
|
+
/**
|
|
243
|
+
* What may still be committed. Never negative.
|
|
244
|
+
*
|
|
245
|
+
* **Read {@link SpendAvailability.determinate} before spending against this.** The figure is the
|
|
246
|
+
* arithmetic over what is known, and while an unresolved charge of unknown size stands, what is
|
|
247
|
+
* known is not all there is.
|
|
248
|
+
*/
|
|
249
|
+
available: Money;
|
|
250
|
+
/** Whether {@link SpendAvailability.available} is an amount anyone may commit against. */
|
|
251
|
+
determinate: boolean;
|
|
252
|
+
/**
|
|
253
|
+
* Why it is not, where it is not.
|
|
254
|
+
*
|
|
255
|
+
* Two independent sources, kept apart because they carry different evidence:
|
|
256
|
+
*
|
|
257
|
+
* - reservations in `billing_unknown` whose exposure is not bounded by an enforced ceiling;
|
|
258
|
+
* - cost records of unknown size with no reservation at all, which is every such record written
|
|
259
|
+
* before this protocol existed (#150).
|
|
260
|
+
*/
|
|
261
|
+
indeterminate: {
|
|
262
|
+
unboundedReservations: SpendReservation[];
|
|
263
|
+
unreservedUnknownCharges: CostRecord[];
|
|
264
|
+
};
|
|
265
|
+
/**
|
|
266
|
+
* Reserved-but-unsettled amounts, per **authorization** currency (ADR-0044).
|
|
267
|
+
*
|
|
268
|
+
* Not the provider's billing currency. This states what Aldus set aside; what a provider charged,
|
|
269
|
+
* and in what currency, is a separate fact that may not exist yet. A report may say "USD 2.00
|
|
270
|
+
* remains reserved because billing is unresolved"; it must never restate that as "the provider
|
|
271
|
+
* made an unknown USD charge".
|
|
272
|
+
*/
|
|
273
|
+
reservedUnknownByCurrency: Record<string, string>;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Derive what a grant still authorizes (§19.3; ADR-0044).
|
|
278
|
+
*
|
|
279
|
+
* Composes with #150 rather than replacing it. A charge of unknown size still makes the grant
|
|
280
|
+
* indeterminate — what a reservation adds is the possibility of a *bound*, and only when the
|
|
281
|
+
* execution that produced the charge was actually dispatched under an enforced ceiling. A backend
|
|
282
|
+
* that declares enforcement today is not evidence about a request dispatched by an earlier version
|
|
283
|
+
* (ADR-0030).
|
|
284
|
+
*/
|
|
285
|
+
export function availableAuthorization(
|
|
286
|
+
grant: SpendGrant,
|
|
287
|
+
costs: readonly CostRecord[],
|
|
288
|
+
reservations: readonly SpendReservation[] = [],
|
|
289
|
+
): SpendAvailability {
|
|
290
|
+
const currency = grant.maxTotal.currency;
|
|
291
|
+
const ledger = computeLedger(grant, costs);
|
|
292
|
+
|
|
293
|
+
// Per grant, never per decision. The grant is the budget pool; the decision is who authorized
|
|
294
|
+
// its terms. One decision may establish several grants — an episode-level ceiling above an agent
|
|
295
|
+
// grant and a TTS grant — and deriving availability per decision would silently aggregate them.
|
|
296
|
+
const mine = reservations.filter((reservation) => reservation.grantId === grant.grantId);
|
|
297
|
+
const active = mine.filter(reservationIsActive);
|
|
298
|
+
|
|
299
|
+
// Settled reservations are already represented by the cost records that settled them. Counting
|
|
300
|
+
// both would double-count the same money against the ceiling.
|
|
301
|
+
let reserved = zeroMoney(currency);
|
|
302
|
+
const reservedUnknownByCurrency = new Map<string, Money>();
|
|
303
|
+
for (const reservation of active) {
|
|
304
|
+
if (reservation.reserved.currency === currency) {
|
|
305
|
+
reserved = addMoney(reserved, reservation.reserved);
|
|
306
|
+
}
|
|
307
|
+
if (reservation.status === "billing_unknown") {
|
|
308
|
+
const running =
|
|
309
|
+
reservedUnknownByCurrency.get(reservation.reserved.currency) ??
|
|
310
|
+
zeroMoney(reservation.reserved.currency);
|
|
311
|
+
reservedUnknownByCurrency.set(
|
|
312
|
+
reservation.reserved.currency,
|
|
313
|
+
addMoney(running, reservation.reserved),
|
|
314
|
+
);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
const unboundedReservations = active.filter(
|
|
319
|
+
(reservation) =>
|
|
320
|
+
reservation.status === "billing_unknown" && !reservationExposureIsBounded(reservation),
|
|
321
|
+
);
|
|
322
|
+
// #150's rule, narrowed by what a reservation can now establish. A record of unknown size whose
|
|
323
|
+
// reservation is bounded is accounted for; one with no reservation is not, and that is every
|
|
324
|
+
// such record written before this protocol.
|
|
325
|
+
const boundedReservationIds = new Set(
|
|
326
|
+
active
|
|
327
|
+
.filter((reservation) => reservationExposureIsBounded(reservation))
|
|
328
|
+
.map((reservation) => reservation.reservationId),
|
|
329
|
+
);
|
|
330
|
+
// `computeLedger` filters cost records by `authorizationId`, which is the legacy link and stays
|
|
331
|
+
// correct: a record written before reservations existed has no `reservationId` to reach a grant
|
|
332
|
+
// through, and its decision is the only thing tying it to an authorization (#155).
|
|
333
|
+
const unreservedUnknownCharges = ledger.counted.filter(
|
|
334
|
+
(record) =>
|
|
335
|
+
isUnresolvedUnknownCharge(record) &&
|
|
336
|
+
(record.reservationId === undefined || !boundedReservationIds.has(record.reservationId)),
|
|
337
|
+
);
|
|
338
|
+
|
|
339
|
+
const headroom = subtractMoney(subtractMoney(grant.maxTotal, ledger.consumed), reserved);
|
|
340
|
+
return {
|
|
341
|
+
authorized: grant.maxTotal,
|
|
342
|
+
settled: ledger.consumed,
|
|
343
|
+
reserved,
|
|
344
|
+
available: isNegativeMoney(headroom) ? zeroMoney(currency) : headroom,
|
|
345
|
+
determinate: unboundedReservations.length === 0 && unreservedUnknownCharges.length === 0,
|
|
346
|
+
indeterminate: { unboundedReservations, unreservedUnknownCharges },
|
|
347
|
+
reservedUnknownByCurrency: Object.fromEntries(
|
|
348
|
+
[...reservedUnknownByCurrency.entries()]
|
|
349
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
350
|
+
.map(([code, money]) => [code, money.amount]),
|
|
351
|
+
),
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Whether a grant can truthfully permit an unestimated execution (ADR-0044; #155).
|
|
357
|
+
*
|
|
358
|
+
* `reserve_max_per_request` promises to reserve the per-request ceiling. A grant that permits it
|
|
359
|
+
* and states no such ceiling promises an amount it does not have — and reserving zero instead
|
|
360
|
+
* would make unestimated executions invisible to concurrency control, which is the case most
|
|
361
|
+
* likely to be dispatched in a loop.
|
|
362
|
+
*
|
|
363
|
+
* Checked at decode **and** before dispatch: a grant assembled from configuration never passes
|
|
364
|
+
* through the constructor that would have caught it.
|
|
365
|
+
*/
|
|
366
|
+
export function unestimatedPolicyIsSatisfiable(grant: SpendGrant): string | undefined {
|
|
367
|
+
if ((grant.unestimatedExecution ?? "refuse") !== "reserve_max_per_request") return undefined;
|
|
368
|
+
const ceiling = grant.maxPerRequest;
|
|
369
|
+
if (ceiling === undefined) {
|
|
370
|
+
return (
|
|
371
|
+
`Grant "${grant.grantId}" permits unestimated execution by reserving its per-request ` +
|
|
372
|
+
"ceiling, and states no ceiling. There is no truthful amount to reserve, so this cannot be " +
|
|
373
|
+
"dispatched (§13.2, §19.3)."
|
|
374
|
+
);
|
|
375
|
+
}
|
|
376
|
+
if (!isPositiveMoney(ceiling)) {
|
|
377
|
+
return (
|
|
378
|
+
`Grant "${grant.grantId}" permits unestimated execution by reserving its per-request ` +
|
|
379
|
+
`ceiling, and that ceiling is ${formatMoney(ceiling)}. Reserving zero would make an ` +
|
|
380
|
+
"unestimated execution invisible to concurrency control."
|
|
381
|
+
);
|
|
382
|
+
}
|
|
383
|
+
if (ceiling.currency !== grant.maxTotal.currency) {
|
|
384
|
+
return (
|
|
385
|
+
`Grant "${grant.grantId}" states a per-request ceiling in ${ceiling.currency} and a total ` +
|
|
386
|
+
`in ${grant.maxTotal.currency}. A reservation is denominated in the grant's currency, and ` +
|
|
387
|
+
"converting implicitly is not something this runtime does (ADR-0044)."
|
|
388
|
+
);
|
|
389
|
+
}
|
|
390
|
+
return undefined;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/** Why a grant does not authorize an operation. */
|
|
394
|
+
export interface SpendScopeRefusal {
|
|
395
|
+
operation: string;
|
|
396
|
+
authorized: readonly string[];
|
|
397
|
+
explanation: string;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* Whether a grant authorizes an operation (§13.2, §4.2; #155).
|
|
402
|
+
*
|
|
403
|
+
* Checked before reserving, so handing the wrong grant to an execution gateway cannot authorize
|
|
404
|
+
* unrelated work. Without it a grant is a pool of money with no statement about what it is for,
|
|
405
|
+
* and the only thing separating agent spend from a synthesis ledger is which decision each
|
|
406
|
+
* happened to name.
|
|
407
|
+
*/
|
|
408
|
+
export function checkSpendScope(
|
|
409
|
+
grant: SpendGrant,
|
|
410
|
+
operation: string,
|
|
411
|
+
): SpendScopeRefusal | undefined {
|
|
412
|
+
if (grant.scope.operations.includes(operation)) return undefined;
|
|
413
|
+
return {
|
|
414
|
+
operation,
|
|
415
|
+
authorized: [...grant.scope.operations],
|
|
416
|
+
explanation:
|
|
417
|
+
`Grant "${grant.grantId}" authorizes ${grant.scope.operations.map((entry) => `"${entry}"`).join(", ") || "nothing"} ` +
|
|
418
|
+
`and this operation is "${operation}". A grant states what it may be spent on as well as ` +
|
|
419
|
+
"how much, so passing the wrong one to a gateway cannot authorize unrelated work (§13.2).",
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
|
|
181
423
|
/** A request to spend against a grant. */
|
|
182
424
|
export interface SpendRequest {
|
|
183
425
|
/** The amount about to be committed. */
|