@proofoftech/flowsafe 0.8.0 → 0.10.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 +44 -0
- package/README.md +8 -6
- package/dist/agent-host/approval-resumer.d.ts +7 -2
- package/dist/agent-host/approval-resumer.d.ts.map +1 -1
- package/dist/agent-host/approval-resumer.js +20 -10
- package/dist/agent-host/approval-resumer.js.map +1 -1
- package/dist/agent-host/catalog.d.ts.map +1 -1
- package/dist/agent-host/catalog.js +97 -1
- package/dist/agent-host/catalog.js.map +1 -1
- package/dist/agent-host/index.d.ts +3 -3
- package/dist/agent-host/index.d.ts.map +1 -1
- package/dist/agent-host/index.js +1 -1
- package/dist/agent-host/index.js.map +1 -1
- package/dist/agent-host/thread-host.d.ts +20 -1
- package/dist/agent-host/thread-host.d.ts.map +1 -1
- package/dist/agent-host/thread-host.js +87 -35
- package/dist/agent-host/thread-host.js.map +1 -1
- package/dist/agent-host/trusted-context.d.ts +0 -1
- package/dist/agent-host/trusted-context.d.ts.map +1 -1
- package/dist/agent-host/trusted-context.js +9 -11
- package/dist/agent-host/trusted-context.js.map +1 -1
- package/dist/agent-host/types.d.ts +38 -2
- package/dist/agent-host/types.d.ts.map +1 -1
- package/dist/agent-runner/agent-run-state.d.ts +11 -3
- package/dist/agent-runner/agent-run-state.d.ts.map +1 -1
- package/dist/agent-runner/agent-run-state.js +10 -20
- package/dist/agent-runner/agent-run-state.js.map +1 -1
- package/dist/agent-runner/approval-shapes.d.ts +16 -4
- package/dist/agent-runner/approval-shapes.d.ts.map +1 -1
- package/dist/agent-runner/approval-shapes.js +16 -6
- package/dist/agent-runner/approval-shapes.js.map +1 -1
- package/dist/agent-runner/durable-agent-runner.d.ts +10 -9
- package/dist/agent-runner/durable-agent-runner.d.ts.map +1 -1
- package/dist/agent-runner/durable-agent-runner.js +12 -10
- package/dist/agent-runner/durable-agent-runner.js.map +1 -1
- package/dist/agent-runner/index.d.ts +1 -1
- package/dist/agent-runner/index.d.ts.map +1 -1
- package/dist/agent-runner/index.js +1 -1
- package/dist/agent-runner/index.js.map +1 -1
- package/dist/approval-api/contract.d.ts +1 -1
- package/dist/approval-api/contract.d.ts.map +1 -1
- package/dist/approval-api/contract.js +1 -1
- package/dist/approval-api/contract.js.map +1 -1
- package/dist/approval-api/d1-store.d.ts.map +1 -1
- package/dist/approval-api/d1-store.js +57 -20
- package/dist/approval-api/d1-store.js.map +1 -1
- package/dist/approval-api/grants.d.ts +5 -9
- package/dist/approval-api/grants.d.ts.map +1 -1
- package/dist/approval-api/grants.js +98 -55
- package/dist/approval-api/grants.js.map +1 -1
- package/dist/approval-api/index.d.ts +5 -3
- package/dist/approval-api/index.d.ts.map +1 -1
- package/dist/approval-api/index.js +9 -2
- package/dist/approval-api/index.js.map +1 -1
- package/dist/approval-api/principal.d.ts +214 -0
- package/dist/approval-api/principal.d.ts.map +1 -0
- package/dist/approval-api/principal.js +391 -0
- package/dist/approval-api/principal.js.map +1 -0
- package/dist/approval-api/router.d.ts +6 -4
- package/dist/approval-api/router.d.ts.map +1 -1
- package/dist/approval-api/router.js +7 -3
- package/dist/approval-api/router.js.map +1 -1
- package/dist/approval-api/service.d.ts +43 -2
- package/dist/approval-api/service.d.ts.map +1 -1
- package/dist/approval-api/service.js +185 -16
- package/dist/approval-api/service.js.map +1 -1
- package/dist/approval-api/store.d.ts +1 -1
- package/dist/approval-api/store.js +1 -1
- package/dist/approval-api/tenant-context.d.ts +7 -0
- package/dist/approval-api/tenant-context.d.ts.map +1 -1
- package/dist/approval-api/tenant-context.js +14 -3
- package/dist/approval-api/tenant-context.js.map +1 -1
- package/dist/approval-api/types.d.ts +54 -3
- package/dist/approval-api/types.d.ts.map +1 -1
- package/dist/approval-api/types.js.map +1 -1
- package/dist/do-runner/breakwater-keys.d.ts +4 -6
- package/dist/do-runner/breakwater-keys.d.ts.map +1 -1
- package/dist/do-runner/breakwater-keys.js +4 -6
- package/dist/do-runner/breakwater-keys.js.map +1 -1
- package/dist/do-runner/execution-context.d.ts.map +1 -1
- package/dist/do-runner/execution-context.js +3 -2
- package/dist/do-runner/execution-context.js.map +1 -1
- package/dist/do-runner/index.d.ts +1 -1
- package/dist/do-runner/index.d.ts.map +1 -1
- package/dist/do-runner/index.js +1 -1
- package/dist/do-runner/index.js.map +1 -1
- package/dist/do-runner/mastra-registry.d.ts +7 -0
- package/dist/do-runner/mastra-registry.d.ts.map +1 -0
- package/dist/do-runner/mastra-registry.js +21 -0
- package/dist/do-runner/mastra-registry.js.map +1 -0
- package/dist/do-runner/runtime.d.ts +10 -1
- package/dist/do-runner/runtime.d.ts.map +1 -1
- package/dist/do-runner/runtime.js +57 -5
- package/dist/do-runner/runtime.js.map +1 -1
- package/dist/do-runner/thread-do.d.ts +12 -1
- package/dist/do-runner/thread-do.d.ts.map +1 -1
- package/dist/do-runner/thread-do.js +30 -21
- package/dist/do-runner/thread-do.js.map +1 -1
- package/dist/do-runner/thread-header.d.ts +17 -4
- package/dist/do-runner/thread-header.d.ts.map +1 -1
- package/dist/do-runner/thread-header.js +17 -4
- package/dist/do-runner/thread-header.js.map +1 -1
- package/dist/host-kit/approval-bridge.d.ts +12 -7
- package/dist/host-kit/approval-bridge.d.ts.map +1 -1
- package/dist/host-kit/approval-bridge.js +79 -25
- package/dist/host-kit/approval-bridge.js.map +1 -1
- package/dist/host-kit/flowsafe-worker.js +2 -2
- package/dist/host-kit/flowsafe-worker.js.map +1 -1
- package/dist/host-kit/host-approval-service.d.ts +10 -5
- package/dist/host-kit/host-approval-service.d.ts.map +1 -1
- package/dist/host-kit/host-approval-service.js +10 -10
- package/dist/host-kit/host-approval-service.js.map +1 -1
- package/dist/host-kit/index.d.ts +1 -1
- package/dist/host-kit/index.d.ts.map +1 -1
- package/dist/host-kit/index.js +1 -1
- package/dist/host-kit/index.js.map +1 -1
- package/dist/host-kit/run-router.d.ts.map +1 -1
- package/dist/host-kit/run-router.js +1 -6
- package/dist/host-kit/run-router.js.map +1 -1
- package/dist/host-kit/thread-topology.d.ts +1 -1
- package/dist/host-kit/thread-topology.d.ts.map +1 -1
- package/dist/host-kit/thread-topology.js +29 -5
- package/dist/host-kit/thread-topology.js.map +1 -1
- package/dist/signal-providers/delivery.d.ts +1 -1
- package/dist/signal-providers/delivery.d.ts.map +1 -1
- package/dist/signal-providers/delivery.js +9 -3
- package/dist/signal-providers/delivery.js.map +1 -1
- package/dist/signals/thread-do-routes.d.ts +9 -3
- package/dist/signals/thread-do-routes.d.ts.map +1 -1
- package/dist/signals/thread-do-routes.js +10 -10
- package/dist/signals/thread-do-routes.js.map +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// ExecutionPrincipal — WHO is executing, as opposed to who approved.
|
|
3
|
+
//
|
|
4
|
+
// Before this existed the platform had one identity, ApprovalActor, whose only
|
|
5
|
+
// authority vocabulary is a human ApprovalRole. Every automated path therefore
|
|
6
|
+
// fabricated a human: the schedule tick, cron maintenance, signal-provider
|
|
7
|
+
// delivery, and the suspension-reconcile bridge all minted `role: 'operator'`.
|
|
8
|
+
// That loses provenance (nothing records WHY the call exists) and, worse, hands
|
|
9
|
+
// autonomous execution whatever an operator may do.
|
|
10
|
+
//
|
|
11
|
+
// ApprovalActor is deliberately NOT replaced. It stays exactly what it always
|
|
12
|
+
// was: the identity of an authenticated human at the HTTP boundary and of a
|
|
13
|
+
// reviewer deciding an approval. A human approving an agent's request is still
|
|
14
|
+
// attributed to that human — `decidedBy` is unaffected by anything here.
|
|
15
|
+
//
|
|
16
|
+
// This lives in approval-api rather than contract.ts because contract.ts is the
|
|
17
|
+
// breakwater wire contract, mirrored by value and pinned by the cross-package
|
|
18
|
+
// tests. A principal is a host concept: breakwater learns only the KIND (its
|
|
19
|
+
// `PrincipalKind`), never the tenant or the purpose.
|
|
20
|
+
import { APPROVAL_ROLES, } from './contract.js';
|
|
21
|
+
export const EXECUTION_PRINCIPAL_KINDS = [
|
|
22
|
+
'human',
|
|
23
|
+
'service',
|
|
24
|
+
'agent',
|
|
25
|
+
'system',
|
|
26
|
+
];
|
|
27
|
+
/** Automated kinds — everything that is not a logged-in person. */
|
|
28
|
+
export const AUTOMATED_PRINCIPAL_KINDS = [
|
|
29
|
+
'service',
|
|
30
|
+
'agent',
|
|
31
|
+
'system',
|
|
32
|
+
];
|
|
33
|
+
/** Upper bound on the free-text provenance fields, so audit rows stay bounded. */
|
|
34
|
+
const MAX_PURPOSE_LENGTH = 200;
|
|
35
|
+
const MAX_PRINCIPAL_ID_LENGTH = 200;
|
|
36
|
+
/**
|
|
37
|
+
* The trusted-automation brand, following the TENANT_BOUND idiom for the same
|
|
38
|
+
* reason: TypeScript is structural, so a parameter typed plain
|
|
39
|
+
* `ExecutionPrincipal` is satisfied by any object literal. Without this, the
|
|
40
|
+
* service's automated entries authorize on the CALLER'S OWN ASSERTION that it
|
|
41
|
+
* is a robot — which would give automation strictly more create authority than
|
|
42
|
+
* a human `viewer`.
|
|
43
|
+
*
|
|
44
|
+
* The symbol is exported because declaration emit cannot reference a
|
|
45
|
+
* module-private name from an exported type. It is deliberately absent from the
|
|
46
|
+
* package barrel, but that is API-surface hygiene, NOT a capability boundary:
|
|
47
|
+
* the brand is recoverable by reflection from any vouched principal
|
|
48
|
+
* (`Object.getOwnPropertySymbols(maintenancePrincipal('x'))`), so in-process
|
|
49
|
+
* code that means to forge one still can. That residual is the same one
|
|
50
|
+
* TENANT_BOUND accepts, and it is deliberate — a TCB bypass on par with an `as`
|
|
51
|
+
* cast. What the brand eliminates is accidental satisfaction and the rushed fix
|
|
52
|
+
* that hands a request-derived principal to a trusted entry.
|
|
53
|
+
*/
|
|
54
|
+
export const TRUSTED_AUTOMATION = Symbol('flowsafe.trustedAutomation');
|
|
55
|
+
/**
|
|
56
|
+
* Vouch for an automated principal. Calling this IS the trust assertion, which
|
|
57
|
+
* is why it is a named function rather than a cast: it should be greppable, and
|
|
58
|
+
* it should never appear on a path that took the principal from a request.
|
|
59
|
+
*
|
|
60
|
+
* Throws on a human or a malformed principal — those must use the
|
|
61
|
+
* role-authorized entries.
|
|
62
|
+
*
|
|
63
|
+
* Returns a CANONICAL CLONE, branded and frozen. Validating the caller's object
|
|
64
|
+
* and handing the same reference back made the vouch time-of-check/time-of-use:
|
|
65
|
+
* the caller kept a mutable alias, so a validated `system` principal could be
|
|
66
|
+
* rewritten into `{kind:'human', role:'admin'}` after the check and before the
|
|
67
|
+
* service read it — and `#authorizeAutomated` re-reads `kind`. The clone comes
|
|
68
|
+
* from `canonicalPrincipal`, so it holds the exact values that were validated
|
|
69
|
+
* and no extra property rides into the trusted computing base; the brand lets
|
|
70
|
+
* consumers prove the value came from here, and the freeze keeps both true for
|
|
71
|
+
* the object's whole life.
|
|
72
|
+
*/
|
|
73
|
+
export function trustAutomationPrincipal(principal) {
|
|
74
|
+
// The brand is stamped onto the CANONICAL SNAPSHOT, never onto the argument.
|
|
75
|
+
// Validating one object and minting from another is how a value that passed
|
|
76
|
+
// the automated check came back out as a human admin; taking both from the
|
|
77
|
+
// same read makes that impossible rather than merely difficult.
|
|
78
|
+
const canonical = canonicalPrincipal(principal);
|
|
79
|
+
if (canonical === undefined || canonical.kind === 'human') {
|
|
80
|
+
throw new Error('execution principal: only a valid automated principal can be trusted for platform work');
|
|
81
|
+
}
|
|
82
|
+
return Object.freeze({
|
|
83
|
+
...canonical,
|
|
84
|
+
[TRUSTED_AUTOMATION]: true,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Read one field as an OWN DATA property, or `undefined`.
|
|
89
|
+
*
|
|
90
|
+
* Every principal field is read through this rather than by `value.kind`,
|
|
91
|
+
* because a plain read is not a stable observation of a value someone else
|
|
92
|
+
* built: it walks the prototype chain, so an inherited getter answers it, and
|
|
93
|
+
* an own accessor's getter can answer differently each time. `Object.freeze`
|
|
94
|
+
* is no substitute — it constrains a value's own data properties and says
|
|
95
|
+
* nothing about accessors, inherited fields, or virtual ones.
|
|
96
|
+
*
|
|
97
|
+
* This does NOT by itself prove the field cannot lie: over a Proxy with an
|
|
98
|
+
* extensible target, `Object.getOwnPropertyDescriptor` is a trap as
|
|
99
|
+
* unconstrained as `get`. What closes the class is that the single read is
|
|
100
|
+
* captured — see `canonicalPrincipal`, which returns a snapshot built from
|
|
101
|
+
* these reads, so nothing downstream re-reads the caller's object at all.
|
|
102
|
+
*
|
|
103
|
+
* The minter emits plain own data properties, so this refuses nothing real.
|
|
104
|
+
*/
|
|
105
|
+
function ownField(value, key) {
|
|
106
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
107
|
+
return descriptor !== undefined && 'value' in descriptor
|
|
108
|
+
? descriptor.value
|
|
109
|
+
: undefined;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Does this value carry the brand AND still hold a valid automated shape?
|
|
113
|
+
*
|
|
114
|
+
* The parameter type alone proves nothing at runtime — TypeScript is erased,
|
|
115
|
+
* and the ways in that remain (an `as` cast, a value rebuilt from storage or a
|
|
116
|
+
* structured clone across a boundary) all produce something the type accepts.
|
|
117
|
+
* This is the check that makes the brand load-bearing rather than decorative,
|
|
118
|
+
* so the trusted service entries call it instead of trusting their signature.
|
|
119
|
+
*
|
|
120
|
+
* Deliberately NOT on the package barrel: it is the enforcement half of an
|
|
121
|
+
* internal invariant, and exporting it would put a runtime shape check into the
|
|
122
|
+
* public API that consumers would have to keep working across minor versions.
|
|
123
|
+
*/
|
|
124
|
+
export function isTrustedAutomationPrincipal(value) {
|
|
125
|
+
if (value === null || typeof value !== 'object')
|
|
126
|
+
return false;
|
|
127
|
+
return (canonicalAutomatedPrincipal(value) !== undefined &&
|
|
128
|
+
// The brand is read as an OWN DATA property for the same reason every other
|
|
129
|
+
// field is: a plain read would accept one inherited from a prototype, which
|
|
130
|
+
// nobody stamped.
|
|
131
|
+
ownField(value, TRUSTED_AUTOMATION) === true &&
|
|
132
|
+
// A branded-but-UNFROZEN principal is by definition one somebody stamped
|
|
133
|
+
// onto a live mutable object rather than minting. It is also what forces a
|
|
134
|
+
// Proxy's descriptor and `get` channels to agree, since the spec invariants
|
|
135
|
+
// only bind over a non-extensible target.
|
|
136
|
+
Object.isFrozen(value));
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Validate and return a canonical principal that is not a person.
|
|
140
|
+
*
|
|
141
|
+
* The returned snapshot contains the exact values that passed validation, so
|
|
142
|
+
* callers never need to re-read a mutable or adversarial input. Kept off the
|
|
143
|
+
* package barrel: this is an internal enforcement helper, not public API.
|
|
144
|
+
*/
|
|
145
|
+
export function canonicalAutomatedPrincipal(value) {
|
|
146
|
+
const principal = canonicalPrincipal(value);
|
|
147
|
+
return principal !== undefined && principal.kind !== 'human'
|
|
148
|
+
? principal
|
|
149
|
+
: undefined;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Bounded, non-empty, and free of control characters.
|
|
153
|
+
*
|
|
154
|
+
* Not an injection barrier for the wire — the principal travels through
|
|
155
|
+
* `JSON.stringify`, which escapes U+0000–U+001F. It matters because these
|
|
156
|
+
* fields do not stop at the wire: `id` becomes `requestedBy`/`decidedBy` in D1
|
|
157
|
+
* and the actor on every audit row, and `purpose` rides into the SIEM export.
|
|
158
|
+
* The bounds keep an audit row bounded; the control-character refusal keeps
|
|
159
|
+
* those strings clean at the boundary rather than downstream. Mirrors the
|
|
160
|
+
* `containsHeaderControl` check `createTenantResolver` applies to an actor id.
|
|
161
|
+
*/
|
|
162
|
+
function boundedText(value, max) {
|
|
163
|
+
if (typeof value !== 'string' || value.trim() === '' || value.length > max) {
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
for (const character of value) {
|
|
167
|
+
const code = character.charCodeAt(0);
|
|
168
|
+
if (code <= 0x1f || code === 0x7f)
|
|
169
|
+
return false;
|
|
170
|
+
}
|
|
171
|
+
return true;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Validate AND canonicalize in one pass: every field is read exactly once, and
|
|
175
|
+
* the result is a fresh plain object built from THOSE reads.
|
|
176
|
+
*
|
|
177
|
+
* Validating a caller's object and then reading it again is the mistake this
|
|
178
|
+
* module keeps re-learning. The first version handed back the caller's own
|
|
179
|
+
* mutable reference; the second cloned but re-read plainly, which an accessor
|
|
180
|
+
* or a prototype getter could answer differently; reading through descriptors
|
|
181
|
+
* narrows the channel but does not close it, because
|
|
182
|
+
* `Object.getOwnPropertyDescriptor` is itself a Proxy trap and, over an
|
|
183
|
+
* extensible target, is as unconstrained as `get`.
|
|
184
|
+
*
|
|
185
|
+
* Returning the snapshot ends the class rather than narrowing it: "validated"
|
|
186
|
+
* and "used" become the same values, so no consumer can be handed something
|
|
187
|
+
* other than what was checked, whatever the input was built from.
|
|
188
|
+
*
|
|
189
|
+
* Fields are picked EXPLICITLY. tsc catches a new kind (the returns stop being
|
|
190
|
+
* exhaustive) and a new REQUIRED field (the literal stops matching), but NOT a
|
|
191
|
+
* new optional one — that compiles clean and is silently dropped, so add it to
|
|
192
|
+
* the pick by hand (`delegatedBy` is the existing example).
|
|
193
|
+
*/
|
|
194
|
+
function canonicalPrincipal(value) {
|
|
195
|
+
if (value === null || typeof value !== 'object')
|
|
196
|
+
return undefined;
|
|
197
|
+
const id = ownField(value, 'id');
|
|
198
|
+
const tenantId = ownField(value, 'tenantId');
|
|
199
|
+
const kind = ownField(value, 'kind');
|
|
200
|
+
if (!boundedText(id, MAX_PRINCIPAL_ID_LENGTH) ||
|
|
201
|
+
typeof tenantId !== 'string' ||
|
|
202
|
+
tenantId === '') {
|
|
203
|
+
return undefined;
|
|
204
|
+
}
|
|
205
|
+
if (kind === 'human') {
|
|
206
|
+
const role = ownField(value, 'role');
|
|
207
|
+
return typeof role === 'string' &&
|
|
208
|
+
APPROVAL_ROLES.includes(role)
|
|
209
|
+
? { kind: 'human', id, tenantId, role: role }
|
|
210
|
+
: undefined;
|
|
211
|
+
}
|
|
212
|
+
if (kind !== 'service' && kind !== 'agent' && kind !== 'system') {
|
|
213
|
+
return undefined;
|
|
214
|
+
}
|
|
215
|
+
const purpose = ownField(value, 'purpose');
|
|
216
|
+
if (!boundedText(purpose, MAX_PURPOSE_LENGTH))
|
|
217
|
+
return undefined;
|
|
218
|
+
const delegatedBy = ownField(value, 'delegatedBy');
|
|
219
|
+
if (delegatedBy !== undefined) {
|
|
220
|
+
return kind === 'agent' && boundedText(delegatedBy, MAX_PRINCIPAL_ID_LENGTH)
|
|
221
|
+
? { kind: 'agent', id, tenantId, purpose, delegatedBy }
|
|
222
|
+
: undefined;
|
|
223
|
+
}
|
|
224
|
+
if (kind === 'agent')
|
|
225
|
+
return { kind: 'agent', id, tenantId, purpose };
|
|
226
|
+
if (kind === 'service')
|
|
227
|
+
return { kind: 'service', id, tenantId, purpose };
|
|
228
|
+
return { kind: 'system', id, tenantId, purpose };
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Structural validation only. The TENANT binding is checked separately by
|
|
232
|
+
* `assertExecutionPrincipal`, because "is this shaped like a principal" and "is
|
|
233
|
+
* this principal allowed here" are different questions and conflating them
|
|
234
|
+
* produces call sites that answer neither.
|
|
235
|
+
*
|
|
236
|
+
* This answers only "was a valid principal readable from this value". It does
|
|
237
|
+
* NOT promise a later plain read returns what was validated — nothing can, for
|
|
238
|
+
* an object built to lie. Anything that goes on to USE the fields must take
|
|
239
|
+
* them from `canonicalPrincipal`'s snapshot (as `trustAutomationPrincipal` and
|
|
240
|
+
* `assertExecutionPrincipal` do) rather than from the argument.
|
|
241
|
+
*/
|
|
242
|
+
export function isExecutionPrincipal(value) {
|
|
243
|
+
return canonicalPrincipal(value) !== undefined;
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Validate a principal AND bind it to the tenant that is about to act on it.
|
|
247
|
+
*
|
|
248
|
+
* `tenantId` on a decoded principal crosses an authentication boundary exactly
|
|
249
|
+
* as `ApprovalActor.tenantId` does — the type says `string`, and the type system
|
|
250
|
+
* has no authority over a value read back out of D1 or a DO's storage.
|
|
251
|
+
*
|
|
252
|
+
* Returns the canonical snapshot, not the argument: the tenant that was
|
|
253
|
+
* compared and the tenant the caller goes on to use are then the same string.
|
|
254
|
+
*/
|
|
255
|
+
export function assertExecutionPrincipal(value, expectedTenantId, label) {
|
|
256
|
+
const principal = canonicalPrincipal(value);
|
|
257
|
+
if (principal === undefined) {
|
|
258
|
+
throw new Error(`execution principal: ${label} is malformed`);
|
|
259
|
+
}
|
|
260
|
+
if (principal.tenantId !== expectedTenantId) {
|
|
261
|
+
throw new Error(`execution principal: ${label} belongs to tenant '${principal.tenantId}', not '${expectedTenantId}'`);
|
|
262
|
+
}
|
|
263
|
+
return principal;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Structural equality across every kind-specific field.
|
|
267
|
+
*
|
|
268
|
+
* Cast-free: the union narrows on `kind`, so a future variant with a new
|
|
269
|
+
* discriminating field becomes a compile error here rather than silently
|
|
270
|
+
* comparing equal. Three rebinding guards depend on that.
|
|
271
|
+
*/
|
|
272
|
+
export function samePrincipal(left, right) {
|
|
273
|
+
if (left.id !== right.id || left.tenantId !== right.tenantId)
|
|
274
|
+
return false;
|
|
275
|
+
if (left.kind === 'human' || right.kind === 'human') {
|
|
276
|
+
return (left.kind === 'human' &&
|
|
277
|
+
right.kind === 'human' &&
|
|
278
|
+
left.role === right.role);
|
|
279
|
+
}
|
|
280
|
+
return (left.kind === right.kind &&
|
|
281
|
+
left.purpose === right.purpose &&
|
|
282
|
+
left.delegatedBy === right.delegatedBy);
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* The role an automated principal projects into breakwater's `Actor`.
|
|
286
|
+
*
|
|
287
|
+
* `Actor.role` is required, so an automated principal must carry SOME label.
|
|
288
|
+
* breakwater's gate does not consult the role allowlist for a non-human kind,
|
|
289
|
+
* making this value inert there — it is the least-privileged role precisely so
|
|
290
|
+
* that any consumer which reads `actor.role` WITHOUT understanding `kind` gets
|
|
291
|
+
* the minimum rather than the `operator` these paths used to fabricate.
|
|
292
|
+
*
|
|
293
|
+
* `viewer` also holds no decider role, so an automated principal projected onto
|
|
294
|
+
* `ApprovalService` can never satisfy DECIDER_ROLES and approve anything.
|
|
295
|
+
*/
|
|
296
|
+
export const AUTOMATED_PROJECTED_ROLE = 'viewer';
|
|
297
|
+
/**
|
|
298
|
+
* Project a principal onto the approval-service identity.
|
|
299
|
+
*
|
|
300
|
+
* Automated principals keep their own id — attribution stays truthful — while
|
|
301
|
+
* borrowing the least-privileged role so that the approval service's own role
|
|
302
|
+
* gates (CAN_CREATE, DECIDER_ROLES) treat them as read-only.
|
|
303
|
+
*/
|
|
304
|
+
export function principalActor(principal) {
|
|
305
|
+
const { id, role } = breakwaterActorFor(principal);
|
|
306
|
+
return { id, role, tenantId: principal.tenantId };
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* The principal as breakwater's `Actor`. The ONE place the projection rule is
|
|
310
|
+
* written; `principalActor` and the trusted request context both go through it
|
|
311
|
+
* so the breakwater-facing and approval-facing identities cannot disagree.
|
|
312
|
+
*/
|
|
313
|
+
export function breakwaterActorFor(principal) {
|
|
314
|
+
return {
|
|
315
|
+
id: principal.id,
|
|
316
|
+
role: principal.kind === 'human' ? principal.role : AUTOMATED_PROJECTED_ROLE,
|
|
317
|
+
kind: principal.kind,
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Serialize a principal for the trusted thread header. Every field is already
|
|
322
|
+
* bounded and header-control-free (`boundedText`), so plain JSON is safe and
|
|
323
|
+
* stays readable in a trace.
|
|
324
|
+
*/
|
|
325
|
+
export function encodeExecutionPrincipal(principal) {
|
|
326
|
+
return JSON.stringify(principal.kind === 'human'
|
|
327
|
+
? { kind: 'human', id: principal.id, role: principal.role }
|
|
328
|
+
: {
|
|
329
|
+
kind: principal.kind,
|
|
330
|
+
id: principal.id,
|
|
331
|
+
purpose: principal.purpose,
|
|
332
|
+
...(principal.delegatedBy !== undefined
|
|
333
|
+
? { delegatedBy: principal.delegatedBy }
|
|
334
|
+
: {}),
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Rebuild a principal from the trusted header, binding it to the tenant the DO
|
|
339
|
+
* already authenticated. Fields are picked EXPLICITLY rather than spread, so an
|
|
340
|
+
* attacker-supplied extra property cannot ride into DO storage or D1.
|
|
341
|
+
*
|
|
342
|
+
* Returns undefined on anything malformed; the caller fails closed.
|
|
343
|
+
*/
|
|
344
|
+
export function decodeExecutionPrincipal(header, tenantId) {
|
|
345
|
+
let parsed;
|
|
346
|
+
try {
|
|
347
|
+
parsed = JSON.parse(header);
|
|
348
|
+
}
|
|
349
|
+
catch {
|
|
350
|
+
return undefined;
|
|
351
|
+
}
|
|
352
|
+
if (parsed === null || typeof parsed !== 'object')
|
|
353
|
+
return undefined;
|
|
354
|
+
const fields = parsed;
|
|
355
|
+
const candidate = fields.kind === 'human'
|
|
356
|
+
? { kind: 'human', id: fields.id, tenantId, role: fields.role }
|
|
357
|
+
: {
|
|
358
|
+
kind: fields.kind,
|
|
359
|
+
id: fields.id,
|
|
360
|
+
tenantId,
|
|
361
|
+
purpose: fields.purpose,
|
|
362
|
+
...(fields.delegatedBy !== undefined
|
|
363
|
+
? { delegatedBy: fields.delegatedBy }
|
|
364
|
+
: {}),
|
|
365
|
+
};
|
|
366
|
+
return isExecutionPrincipal(candidate) ? candidate : undefined;
|
|
367
|
+
}
|
|
368
|
+
/** An authenticated human at the HTTP boundary, as an execution principal. */
|
|
369
|
+
export function humanPrincipal(actor) {
|
|
370
|
+
return {
|
|
371
|
+
kind: 'human',
|
|
372
|
+
id: actor.id,
|
|
373
|
+
tenantId: actor.tenantId,
|
|
374
|
+
role: actor.role,
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
/** Correlation fields carried into every audit event for this principal. */
|
|
378
|
+
export function principalAuditFields(principal) {
|
|
379
|
+
if (principal.kind === 'human') {
|
|
380
|
+
return { principalKind: 'human', principalId: principal.id };
|
|
381
|
+
}
|
|
382
|
+
return {
|
|
383
|
+
principalKind: principal.kind,
|
|
384
|
+
principalId: principal.id,
|
|
385
|
+
purpose: principal.purpose,
|
|
386
|
+
...(principal.kind === 'agent' && principal.delegatedBy !== undefined
|
|
387
|
+
? { delegatedBy: principal.delegatedBy }
|
|
388
|
+
: {}),
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
//# sourceMappingURL=principal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"principal.js","sourceRoot":"","sources":["../../src/approval-api/principal.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,qEAAqE;AACrE,EAAE;AACF,+EAA+E;AAC/E,+EAA+E;AAC/E,2EAA2E;AAC3E,+EAA+E;AAC/E,gFAAgF;AAChF,oDAAoD;AACpD,EAAE;AACF,8EAA8E;AAC9E,4EAA4E;AAC5E,+EAA+E;AAC/E,yEAAyE;AACzE,EAAE;AACF,gFAAgF;AAChF,8EAA8E;AAC9E,6EAA6E;AAC7E,qDAAqD;AAErD,OAAO,EACL,cAAc,GAGf,MAAM,eAAe,CAAC;AASvB,MAAM,CAAC,MAAM,yBAAyB,GAAsC;IAC1E,OAAO;IACP,SAAS;IACT,OAAO;IACP,QAAQ;CACT,CAAC;AAEF,mEAAmE;AACnE,MAAM,CAAC,MAAM,yBAAyB,GAAsC;IAC1E,SAAS;IACT,OAAO;IACP,QAAQ;CACT,CAAC;AAIF,kFAAkF;AAClF,MAAM,kBAAkB,GAAG,GAAG,CAAC;AAC/B,MAAM,uBAAuB,GAAG,GAAG,CAAC;AA8CpC;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAkB,MAAM,CACrD,4BAA4B,CAC7B,CAAC;AAsBF;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,wBAAwB,CACtC,SAA6B;IAE7B,6EAA6E;IAC7E,4EAA4E;IAC5E,2EAA2E;IAC3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C,IAAI,KAAK,OAAO,IAAI,SAAS,CAAC,WAAW,KAAK,SAAS;YACnE,CAAC,CAAC,EAAE,WAAW,EAAE,SAAS,CAAC,WAAW,EAAE;YACxC,CAAC,CAAC,EAAE,CAAC;KACR,CAAC;AACJ,CAAC"}
|
|
@@ -6,15 +6,17 @@ import { type TenantResolver } from './tenant-context.js';
|
|
|
6
6
|
*
|
|
7
7
|
* - `connectors` IS the minted grant — an approved record's connectors become
|
|
8
8
|
* the requestContext grant the write gate checks.
|
|
9
|
+
* - `grantScope` is persisted capability metadata. It is record-only, but is
|
|
10
|
+
* named here so an attempted body field is rejected rather than ignored.
|
|
11
|
+
* - `toolCallId` narrows a durable-agent grant to one persisted tool call.
|
|
9
12
|
* - `runScoped` turns a step-less record into a standing grant on every leg.
|
|
10
13
|
* - `stepPath`, `suspendedAt`, `resumedAt`, `resumeCount` select WHICH leg a
|
|
11
|
-
* grant mints on.
|
|
12
|
-
*
|
|
13
|
-
* `connectors` alone is insufficient — reject the whole set.
|
|
14
|
+
* grant mints on. Rejecting `connectors` alone is insufficient because a
|
|
15
|
+
* future trusted merge must never inherit client-selected identity.
|
|
14
16
|
* - `requestedBy` is the field decide()'s separation-of-duties check compares
|
|
15
17
|
* against; spoofing it lets one principal approve their own request.
|
|
16
18
|
*/
|
|
17
|
-
export declare const TCB_ONLY_CREATE_FIELDS: readonly ["connectors", "stepPath", "suspendedAt", "resumedAt", "resumeCount", "runScoped", "requestedBy", "resumeTarget"];
|
|
19
|
+
export declare const TCB_ONLY_CREATE_FIELDS: readonly ["connectors", "grantScope", "toolCallId", "stepPath", "suspendedAt", "resumedAt", "resumeCount", "runScoped", "requestedBy", "resumeTarget"];
|
|
18
20
|
/**
|
|
19
21
|
* The complement: what a request body MAY set. The create route copies ONLY
|
|
20
22
|
* these fields off the body — an allowlist, so a field added to
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/approval-api/router.ts"],"names":[],"mappings":"AAsBA,OAAO,EAEL,KAAK,cAAc,EACpB,MAAM,qBAAqB,CAAC;AAe7B
|
|
1
|
+
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/approval-api/router.ts"],"names":[],"mappings":"AAsBA,OAAO,EAEL,KAAK,cAAc,EACpB,MAAM,qBAAqB,CAAC;AAe7B;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,sBAAsB,wJAWzB,CAAC;AAEX;;;;;;;;;GASG;AACH,eAAO,MAAM,oBAAoB,2FAW9B,CAAC;AAEJ,MAAM,WAAW,qBAAqB;IACpC;;;;;OAKG;IACH,OAAO,EAAE,cAAc,CAAC;IACxB,+CAA+C;IAC/C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;;;;OAOG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC;AAyI5E,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,qBAAqB,GAC7B,cAAc,CAmHhB"}
|
|
@@ -23,16 +23,20 @@ import { APPROVAL_LIST_ORDERS, APPROVAL_STATUSES, approvalListOrder, MAX_APPROVA
|
|
|
23
23
|
*
|
|
24
24
|
* - `connectors` IS the minted grant — an approved record's connectors become
|
|
25
25
|
* the requestContext grant the write gate checks.
|
|
26
|
+
* - `grantScope` is persisted capability metadata. It is record-only, but is
|
|
27
|
+
* named here so an attempted body field is rejected rather than ignored.
|
|
28
|
+
* - `toolCallId` narrows a durable-agent grant to one persisted tool call.
|
|
26
29
|
* - `runScoped` turns a step-less record into a standing grant on every leg.
|
|
27
30
|
* - `stepPath`, `suspendedAt`, `resumedAt`, `resumeCount` select WHICH leg a
|
|
28
|
-
* grant mints on.
|
|
29
|
-
*
|
|
30
|
-
* `connectors` alone is insufficient — reject the whole set.
|
|
31
|
+
* grant mints on. Rejecting `connectors` alone is insufficient because a
|
|
32
|
+
* future trusted merge must never inherit client-selected identity.
|
|
31
33
|
* - `requestedBy` is the field decide()'s separation-of-duties check compares
|
|
32
34
|
* against; spoofing it lets one principal approve their own request.
|
|
33
35
|
*/
|
|
34
36
|
export const TCB_ONLY_CREATE_FIELDS = [
|
|
35
37
|
'connectors',
|
|
38
|
+
'grantScope',
|
|
39
|
+
'toolCallId',
|
|
36
40
|
'stepPath',
|
|
37
41
|
'suspendedAt',
|
|
38
42
|
'resumedAt',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.js","sourceRoot":"","sources":["../../src/approval-api/router.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,yEAAyE;AACzE,sEAAsE;AACtE,EAAE;AACF,0EAA0E;AAC1E,wEAAwE;AACxE,4EAA4E;AAC5E,wEAAwE;AACxE,mDAAmD;AACnD,EAAE;AACF,6EAA6E;AAC7E,wEAAwE;AACxE,4EAA4E;AAC5E,6EAA6E;AAC7E,uBAAuB;AAEvB,OAAO,EACL,kBAAkB,EAClB,qBAAqB,EACrB,yBAAyB,EACzB,oBAAoB,GACrB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,qBAAqB,GAEtB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EAKjB,iBAAiB,EAEjB,uBAAuB,EACvB,mBAAmB,EACnB,sBAAsB,GACvB,MAAM,YAAY,CAAC;AAEpB
|
|
1
|
+
{"version":3,"file":"router.js","sourceRoot":"","sources":["../../src/approval-api/router.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,yEAAyE;AACzE,sEAAsE;AACtE,EAAE;AACF,0EAA0E;AAC1E,wEAAwE;AACxE,4EAA4E;AAC5E,wEAAwE;AACxE,mDAAmD;AACnD,EAAE;AACF,6EAA6E;AAC7E,wEAAwE;AACxE,4EAA4E;AAC5E,6EAA6E;AAC7E,uBAAuB;AAEvB,OAAO,EACL,kBAAkB,EAClB,qBAAqB,EAC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,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ApprovalActor, ApprovalAuditSink, ApprovalNotificationSink, ApprovalRole, ApprovalStreamSink } from './contract.js';
|
|
2
|
+
import { type AutomatedExecutionPrincipal, type TrustedAutomationPrincipal } from './principal.js';
|
|
2
3
|
import type { SystemApprovalStore, TenantBoundApprovalStore } from './tenant-brand.js';
|
|
3
4
|
import { type ApprovalDecision, type ApprovalListFilter, type ApprovalMetrics, type ApprovalRecord, type ApprovalResumeTarget, type ApprovalStatus, type BatchDecideResult, type CreateApprovalInput, type DecideResult } from './types.js';
|
|
4
5
|
/** Requester failed role authorization — HTTP 403. */
|
|
@@ -88,11 +89,37 @@ export interface ApprovalServiceOptions {
|
|
|
88
89
|
}
|
|
89
90
|
export declare class ApprovalService {
|
|
90
91
|
#private;
|
|
92
|
+
/**
|
|
93
|
+
* The tenant this service is bound to. Exposed so the host-kit bridges can
|
|
94
|
+
* mint their own bookkeeping principal against it instead of making every
|
|
95
|
+
* host construct one and vouch for it.
|
|
96
|
+
*/
|
|
97
|
+
get tenantId(): string;
|
|
91
98
|
constructor(options: ApprovalServiceOptions);
|
|
92
99
|
create(input: CreateApprovalInput, actor: ApprovalActor, resumeTarget?: ApprovalResumeTarget): Promise<{
|
|
93
100
|
record: ApprovalRecord;
|
|
94
101
|
created: boolean;
|
|
95
102
|
}>;
|
|
103
|
+
/**
|
|
104
|
+
* File an approval on behalf of an AUTOMATED principal — the trusted entry
|
|
105
|
+
* for platform bridges (suspension reconcile, agent host) that have no person
|
|
106
|
+
* behind them.
|
|
107
|
+
*
|
|
108
|
+
* These callers used to fabricate `role: 'operator'` to satisfy CAN_CREATE.
|
|
109
|
+
* They cannot simply project onto a role instead: automated principals
|
|
110
|
+
* project to the least-privileged role precisely so they can never decide,
|
|
111
|
+
* and `viewer` is not in CAN_CREATE. So the role gate is replaced here — not
|
|
112
|
+
* widened — by a kind-and-tenant check.
|
|
113
|
+
*
|
|
114
|
+
* There is deliberately NO principal-taking claim/decide/delegate. Filing a
|
|
115
|
+
* request is trusted platform work; deciding one is a human judgement, and an
|
|
116
|
+
* automated principal approving its own request is the separation-of-duties
|
|
117
|
+
* hole this whole model exists to close.
|
|
118
|
+
*/
|
|
119
|
+
createAsPrincipal(input: CreateApprovalInput, principal: TrustedAutomationPrincipal, resumeTarget?: ApprovalResumeTarget): Promise<{
|
|
120
|
+
record: ApprovalRecord;
|
|
121
|
+
created: boolean;
|
|
122
|
+
}>;
|
|
96
123
|
get(id: string, actor: ApprovalActor): Promise<ApprovalRecord>;
|
|
97
124
|
list(filter: ApprovalListFilter, actor: ApprovalActor): Promise<ApprovalRecord[]>;
|
|
98
125
|
claim(id: string, actor: ApprovalActor): Promise<ApprovalRecord>;
|
|
@@ -130,7 +157,7 @@ export declare class ApprovalService {
|
|
|
130
157
|
* with declined semantics via #resume(), and a stale record must die
|
|
131
158
|
* WITHOUT touching a run that is already suspended at a DIFFERENT
|
|
132
159
|
* (current) fingerprint — this method never calls #resume(). 'rejected'
|
|
133
|
-
* (not 'approved') is the deliberate terminal choice:
|
|
160
|
+
* (not 'approved') is the deliberate terminal choice: connectorGrantsForLeg
|
|
134
161
|
* (grants.ts) reads ONLY status: 'approved' records when deriving a leg's
|
|
135
162
|
* grants, so a superseded record is excluded by its STATUS alone, not
|
|
136
163
|
* merely by its stale fingerprint — it can never mint even if a future
|
|
@@ -153,6 +180,16 @@ export declare class ApprovalService {
|
|
|
153
180
|
* contract sweepSLA uses for its own store-level CAS.
|
|
154
181
|
*/
|
|
155
182
|
supersedeStale(id: string, actor: ApprovalActor, reason: string): Promise<ApprovalRecord | null>;
|
|
183
|
+
/**
|
|
184
|
+
* Supersede on behalf of an AUTOMATED principal — the reconcile bridge's
|
|
185
|
+
* half of `createAsPrincipal`, and authorized the same way.
|
|
186
|
+
*
|
|
187
|
+
* Superseding is bookkeeping, not a decision: the record's suspension
|
|
188
|
+
* fingerprint no longer matches the run, so it can never be resumed and is
|
|
189
|
+
* closed to stop it shadowing the fresh filing. It is deliberately not
|
|
190
|
+
* reachable through `decide`, so this does not give automation a decision.
|
|
191
|
+
*/
|
|
192
|
+
supersedeStaleAsPrincipal(id: string, principal: TrustedAutomationPrincipal, reason: string): Promise<ApprovalRecord | null>;
|
|
156
193
|
delegate(id: string, input: {
|
|
157
194
|
to: string;
|
|
158
195
|
}, actor: ApprovalActor): Promise<ApprovalRecord>;
|
|
@@ -165,8 +202,12 @@ export interface SweepSLAOptions {
|
|
|
165
202
|
* Attribution only — the sweep runs inside the trusted computing base
|
|
166
203
|
* (cron), so there is no role check: the TYPE of the store argument is the
|
|
167
204
|
* authorization (a SystemApprovalStore is unobtainable from request scope).
|
|
205
|
+
*
|
|
206
|
+
* Automated kinds only, and REFUSED at runtime as well: a human here would
|
|
207
|
+
* stamp `principalKind: 'human'` onto cross-tenant cron escalations, which is
|
|
208
|
+
* the synthetic operator this whole model exists to remove.
|
|
168
209
|
*/
|
|
169
|
-
|
|
210
|
+
systemPrincipal: AutomatedExecutionPrincipal;
|
|
170
211
|
audit?: ApprovalAuditSink;
|
|
171
212
|
/** Fired for each record escalated. */
|
|
172
213
|
onEscalation?: (record: ApprovalRecord) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../src/approval-api/service.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EACV,aAAa,EACb,iBAAiB,EAEjB,wBAAwB,EACxB,YAAY,EAEZ,kBAAkB,EACnB,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../src/approval-api/service.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EACV,aAAa,EACb,iBAAiB,EAEjB,wBAAwB,EACxB,YAAY,EAEZ,kBAAkB,EACnB,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,KAAK,2BAA2B,EAMhC,KAAK,0BAA0B,EAChC,MAAM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