@aldus-runtime/gate-engine 0.1.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/LICENSE +201 -0
- package/NOTICE +21 -0
- package/dist/binding.d.ts +82 -0
- package/dist/binding.d.ts.map +1 -0
- package/dist/binding.js +129 -0
- package/dist/binding.js.map +1 -0
- package/dist/definition.d.ts +187 -0
- package/dist/definition.d.ts.map +1 -0
- package/dist/definition.js +231 -0
- package/dist/definition.js.map +1 -0
- package/dist/engine.d.ts +194 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +361 -0
- package/dist/engine.js.map +1 -0
- package/dist/errors.d.ts +61 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +57 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/dist/money.d.ts +52 -0
- package/dist/money.d.ts.map +1 -0
- package/dist/money.js +116 -0
- package/dist/money.js.map +1 -0
- package/dist/ports.d.ts +60 -0
- package/dist/ports.d.ts.map +1 -0
- package/dist/ports.js +51 -0
- package/dist/ports.js.map +1 -0
- package/dist/spend.d.ts +127 -0
- package/dist/spend.d.ts.map +1 -0
- package/dist/spend.js +154 -0
- package/dist/spend.js.map +1 -0
- package/package.json +48 -0
- package/src/binding.ts +179 -0
- package/src/definition.ts +380 -0
- package/src/engine.ts +544 -0
- package/src/errors.ts +66 -0
- package/src/index.ts +102 -0
- package/src/money.ts +146 -0
- package/src/ports.ts +87 -0
- package/src/spend.ts +240 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "{}"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
Aldus
|
|
2
|
+
Copyright 2026 Jam Chen
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
5
|
+
this software except in compliance with the License. You may obtain a copy of
|
|
6
|
+
the License in the LICENSE file distributed with this software, or at:
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Aldus is currently owned as personal work and has not been assigned to a
|
|
11
|
+
separate legal entity. If ownership is transferred, this file and the related
|
|
12
|
+
copyright statements will be updated at that time.
|
|
13
|
+
|
|
14
|
+
No third-party code is bundled, inlined, or vendored into any published Aldus
|
|
15
|
+
package. Dependencies are resolved at install time and reach the consumer under
|
|
16
|
+
their own licenses, from their own publishers. The dependency audit is recorded
|
|
17
|
+
in THIRD-PARTY-NOTICES.md.
|
|
18
|
+
|
|
19
|
+
This NOTICE file exists by the project's choice rather than by obligation:
|
|
20
|
+
Apache-2.0 section 4(d) governs the preservation of a NOTICE file when the work
|
|
21
|
+
already carries one, and does not itself require that one be created.
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Binding a decision to exact inputs (architecture contract §13).
|
|
3
|
+
*
|
|
4
|
+
* Contract §3.6: a decision must be "tied to exact inputs". §13.1 and §13.2 turn that into a
|
|
5
|
+
* requirement — a Content Freeze is void once the content changes, and a TTS authorization "MUST
|
|
6
|
+
* be invalidated if any bound value changes". `GateDecision.subjectHashes` is the mechanism.
|
|
7
|
+
*
|
|
8
|
+
* Two design choices here are load-bearing.
|
|
9
|
+
*
|
|
10
|
+
* **The stored hashes are the raw content digests, not digests of `key + value`.** Hashing the
|
|
11
|
+
* pair would bind the key association more tightly, but it would also make a `subjectHash`
|
|
12
|
+
* unmatchable against an `ArtifactRef.sha256`, and §20 requires production trace to answer which
|
|
13
|
+
* inputs produced a result. Interoperability with the artifact record is worth more than the
|
|
14
|
+
* marginal strength, because the key association is recovered below anyway.
|
|
15
|
+
*
|
|
16
|
+
* **Comparison is over a sorted multiset, and there is no sidecar record of key-to-hash.** A
|
|
17
|
+
* separate record mapping keys to hashes could drift from the decision it describes, and a
|
|
18
|
+
* safety check that depends on two records agreeing fails open the day they disagree. Instead the
|
|
19
|
+
* check is a direct comparison against `subjectHashes`, and the key-level explanation is
|
|
20
|
+
* *derived* by diffing current subjects against that same list. If the explanation is imperfect
|
|
21
|
+
* the check is still exact — the ordering that matters.
|
|
22
|
+
*/
|
|
23
|
+
import type { GateDecision } from "@aldus-runtime/core";
|
|
24
|
+
import type { ResolvedGateDefinition } from "./definition.js";
|
|
25
|
+
/** One named input a gate binds, and the digest of its current value. */
|
|
26
|
+
export interface GateSubject {
|
|
27
|
+
/**
|
|
28
|
+
* What this subject is, e.g. a spoken-text hash or a request plan (contract §13.2).
|
|
29
|
+
*
|
|
30
|
+
* An OPEN string. What a gate binds is adopter process (§4.3), so Core names no subject keys.
|
|
31
|
+
*/
|
|
32
|
+
key: string;
|
|
33
|
+
/** Lowercase hex SHA-256 of the subject's current value. */
|
|
34
|
+
sha256: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Digest an arbitrary value for use as a subject.
|
|
38
|
+
*
|
|
39
|
+
* Serialisation is canonical — object keys sorted at every depth — so that two structurally
|
|
40
|
+
* identical settings objects produce the same digest regardless of how they were built. Without
|
|
41
|
+
* that, re-serialising an unchanged voice-settings object in a different key order would read as
|
|
42
|
+
* a changed bound value and void a valid authorization (§13.2).
|
|
43
|
+
*/
|
|
44
|
+
export declare function digestSubjectValue(value: unknown): string;
|
|
45
|
+
/** Digest raw bytes or text for use as a subject. */
|
|
46
|
+
export declare function digestBytes(value: string | Uint8Array): string;
|
|
47
|
+
/**
|
|
48
|
+
* Check that the supplied subjects cover exactly what the gate binds, and are well formed.
|
|
49
|
+
*
|
|
50
|
+
* A missing subject is refused rather than treated as unchanged. §13.2 requires the operator to
|
|
51
|
+
* approve every listed value, so an authorization that silently omitted one would bind less than
|
|
52
|
+
* the contract requires while still reading as valid.
|
|
53
|
+
*
|
|
54
|
+
* @throws {AldusError} `ALDUS_GATE_SUBJECTS_INCOMPLETE`
|
|
55
|
+
*/
|
|
56
|
+
export declare function assertSubjectsCover(gate: ResolvedGateDefinition, subjects: readonly GateSubject[]): void;
|
|
57
|
+
/**
|
|
58
|
+
* The canonical `subjectHashes` for a set of subjects.
|
|
59
|
+
*
|
|
60
|
+
* Sorted so that the order subjects were supplied in cannot change the stored value, and kept as
|
|
61
|
+
* a list rather than a set so two subjects that happen to share a value stay two subjects.
|
|
62
|
+
*/
|
|
63
|
+
export declare function toSubjectHashes(subjects: readonly GateSubject[]): string[];
|
|
64
|
+
/** Why a decision no longer binds the current inputs. */
|
|
65
|
+
export interface SubjectDrift {
|
|
66
|
+
/** Subject keys whose current digest is not among the approved hashes. */
|
|
67
|
+
changed: string[];
|
|
68
|
+
/** Approved hashes no longer matched by any current subject. */
|
|
69
|
+
orphanedHashes: string[];
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Compare current subjects against what a decision approved.
|
|
73
|
+
*
|
|
74
|
+
* Returns `undefined` when they match exactly. Otherwise names the keys whose values moved, which
|
|
75
|
+
* is what an operator needs in order to know what to re-approve.
|
|
76
|
+
*
|
|
77
|
+
* The key attribution is best-effort by design: it is derived from the hashes rather than stored
|
|
78
|
+
* alongside them, so an exotic case — two subjects sharing one value, one of which changed — may
|
|
79
|
+
* name both. The *detection* is exact regardless, and detection is what §13.2 requires.
|
|
80
|
+
*/
|
|
81
|
+
export declare function detectDrift(decision: GateDecision, subjects: readonly GateSubject[]): SubjectDrift | undefined;
|
|
82
|
+
//# sourceMappingURL=binding.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"binding.d.ts","sourceRoot":"","sources":["../src/binding.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAIH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAExD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAG9D,yEAAyE;AACzE,MAAM,WAAW,WAAW;IAC1B;;;;OAIG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ,4DAA4D;IAC5D,MAAM,EAAE,MAAM,CAAC;CAChB;AAKD;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAEzD;AAED,qDAAqD;AACrD,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,GAAG,MAAM,CAE9D;AAaD;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,sBAAsB,EAC5B,QAAQ,EAAE,SAAS,WAAW,EAAE,GAC/B,IAAI,CAoCN;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,SAAS,WAAW,EAAE,GAAG,MAAM,EAAE,CAE1E;AAED,yDAAyD;AACzD,MAAM,WAAW,YAAY;IAC3B,0EAA0E;IAC1E,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,gEAAgE;IAChE,cAAc,EAAE,MAAM,EAAE,CAAC;CAC1B;AAED;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CACzB,QAAQ,EAAE,YAAY,EACtB,QAAQ,EAAE,SAAS,WAAW,EAAE,GAC/B,YAAY,GAAG,SAAS,CAwB1B"}
|
package/dist/binding.js
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Binding a decision to exact inputs (architecture contract §13).
|
|
3
|
+
*
|
|
4
|
+
* Contract §3.6: a decision must be "tied to exact inputs". §13.1 and §13.2 turn that into a
|
|
5
|
+
* requirement — a Content Freeze is void once the content changes, and a TTS authorization "MUST
|
|
6
|
+
* be invalidated if any bound value changes". `GateDecision.subjectHashes` is the mechanism.
|
|
7
|
+
*
|
|
8
|
+
* Two design choices here are load-bearing.
|
|
9
|
+
*
|
|
10
|
+
* **The stored hashes are the raw content digests, not digests of `key + value`.** Hashing the
|
|
11
|
+
* pair would bind the key association more tightly, but it would also make a `subjectHash`
|
|
12
|
+
* unmatchable against an `ArtifactRef.sha256`, and §20 requires production trace to answer which
|
|
13
|
+
* inputs produced a result. Interoperability with the artifact record is worth more than the
|
|
14
|
+
* marginal strength, because the key association is recovered below anyway.
|
|
15
|
+
*
|
|
16
|
+
* **Comparison is over a sorted multiset, and there is no sidecar record of key-to-hash.** A
|
|
17
|
+
* separate record mapping keys to hashes could drift from the decision it describes, and a
|
|
18
|
+
* safety check that depends on two records agreeing fails open the day they disagree. Instead the
|
|
19
|
+
* check is a direct comparison against `subjectHashes`, and the key-level explanation is
|
|
20
|
+
* *derived* by diffing current subjects against that same list. If the explanation is imperfect
|
|
21
|
+
* the check is still exact — the ordering that matters.
|
|
22
|
+
*/
|
|
23
|
+
import { createHash } from "node:crypto";
|
|
24
|
+
import { GateEngineErrorCodes, gateEngineError } from "./errors.js";
|
|
25
|
+
/** Matches Core's `sha256Hex`: lowercase only, so digests compare by equality. */
|
|
26
|
+
const SHA256_PATTERN = /^[0-9a-f]{64}$/;
|
|
27
|
+
/**
|
|
28
|
+
* Digest an arbitrary value for use as a subject.
|
|
29
|
+
*
|
|
30
|
+
* Serialisation is canonical — object keys sorted at every depth — so that two structurally
|
|
31
|
+
* identical settings objects produce the same digest regardless of how they were built. Without
|
|
32
|
+
* that, re-serialising an unchanged voice-settings object in a different key order would read as
|
|
33
|
+
* a changed bound value and void a valid authorization (§13.2).
|
|
34
|
+
*/
|
|
35
|
+
export function digestSubjectValue(value) {
|
|
36
|
+
return createHash("sha256").update(canonicalJson(value), "utf8").digest("hex");
|
|
37
|
+
}
|
|
38
|
+
/** Digest raw bytes or text for use as a subject. */
|
|
39
|
+
export function digestBytes(value) {
|
|
40
|
+
return createHash("sha256").update(value).digest("hex");
|
|
41
|
+
}
|
|
42
|
+
/** JSON with object keys sorted at every depth. */
|
|
43
|
+
function canonicalJson(value) {
|
|
44
|
+
if (value === null || typeof value !== "object")
|
|
45
|
+
return JSON.stringify(value) ?? "null";
|
|
46
|
+
if (Array.isArray(value))
|
|
47
|
+
return `[${value.map(canonicalJson).join(",")}]`;
|
|
48
|
+
const entries = Object.entries(value)
|
|
49
|
+
.filter(([, entryValue]) => entryValue !== undefined)
|
|
50
|
+
.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
|
|
51
|
+
.map(([key, entryValue]) => `${JSON.stringify(key)}:${canonicalJson(entryValue)}`);
|
|
52
|
+
return `{${entries.join(",")}}`;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Check that the supplied subjects cover exactly what the gate binds, and are well formed.
|
|
56
|
+
*
|
|
57
|
+
* A missing subject is refused rather than treated as unchanged. §13.2 requires the operator to
|
|
58
|
+
* approve every listed value, so an authorization that silently omitted one would bind less than
|
|
59
|
+
* the contract requires while still reading as valid.
|
|
60
|
+
*
|
|
61
|
+
* @throws {AldusError} `ALDUS_GATE_SUBJECTS_INCOMPLETE`
|
|
62
|
+
*/
|
|
63
|
+
export function assertSubjectsCover(gate, subjects) {
|
|
64
|
+
const supplied = new Map();
|
|
65
|
+
for (const subject of subjects) {
|
|
66
|
+
if (!SHA256_PATTERN.test(subject.sha256)) {
|
|
67
|
+
throw gateEngineError(GateEngineErrorCodes.GATE_SUBJECTS_INCOMPLETE, `Subject "${subject.key}" for gate "${gate.gateId}" is not a lowercase hex SHA-256. ` +
|
|
68
|
+
"Mixed-case or truncated digests would compare unequal to an identical value.", { category: "validation", details: { gateId: gate.gateId, key: subject.key } });
|
|
69
|
+
}
|
|
70
|
+
if (supplied.has(subject.key)) {
|
|
71
|
+
throw gateEngineError(GateEngineErrorCodes.GATE_SUBJECTS_INCOMPLETE, `Subject "${subject.key}" was supplied twice for gate "${gate.gateId}".`, { category: "validation", details: { gateId: gate.gateId, key: subject.key } });
|
|
72
|
+
}
|
|
73
|
+
supplied.set(subject.key, subject.sha256);
|
|
74
|
+
}
|
|
75
|
+
const missing = gate.binds.filter((key) => !supplied.has(key));
|
|
76
|
+
const unexpected = [...supplied.keys()].filter((key) => !gate.binds.includes(key));
|
|
77
|
+
if (missing.length > 0 || unexpected.length > 0) {
|
|
78
|
+
throw gateEngineError(GateEngineErrorCodes.GATE_SUBJECTS_INCOMPLETE, `Gate "${gate.gateId}" binds [${gate.binds.join(", ")}], but was given ` +
|
|
79
|
+
`[${[...supplied.keys()].join(", ")}]. Contract §13.2 requires an authorization to bind ` +
|
|
80
|
+
"every listed value; binding a different set is not the same approval.", {
|
|
81
|
+
category: "validation",
|
|
82
|
+
details: { gateId: gate.gateId, missing, unexpected, binds: [...gate.binds] },
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* The canonical `subjectHashes` for a set of subjects.
|
|
88
|
+
*
|
|
89
|
+
* Sorted so that the order subjects were supplied in cannot change the stored value, and kept as
|
|
90
|
+
* a list rather than a set so two subjects that happen to share a value stay two subjects.
|
|
91
|
+
*/
|
|
92
|
+
export function toSubjectHashes(subjects) {
|
|
93
|
+
return subjects.map((subject) => subject.sha256).sort();
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Compare current subjects against what a decision approved.
|
|
97
|
+
*
|
|
98
|
+
* Returns `undefined` when they match exactly. Otherwise names the keys whose values moved, which
|
|
99
|
+
* is what an operator needs in order to know what to re-approve.
|
|
100
|
+
*
|
|
101
|
+
* The key attribution is best-effort by design: it is derived from the hashes rather than stored
|
|
102
|
+
* alongside them, so an exotic case — two subjects sharing one value, one of which changed — may
|
|
103
|
+
* name both. The *detection* is exact regardless, and detection is what §13.2 requires.
|
|
104
|
+
*/
|
|
105
|
+
export function detectDrift(decision, subjects) {
|
|
106
|
+
const approved = [...decision.subjectHashes].sort();
|
|
107
|
+
const current = toSubjectHashes(subjects);
|
|
108
|
+
if (approved.length === current.length && approved.every((hash, i) => hash === current[i])) {
|
|
109
|
+
return undefined;
|
|
110
|
+
}
|
|
111
|
+
const approvedCounts = new Map();
|
|
112
|
+
for (const hash of approved)
|
|
113
|
+
approvedCounts.set(hash, (approvedCounts.get(hash) ?? 0) + 1);
|
|
114
|
+
const changed = [];
|
|
115
|
+
for (const subject of subjects) {
|
|
116
|
+
const remaining = approvedCounts.get(subject.sha256) ?? 0;
|
|
117
|
+
if (remaining > 0)
|
|
118
|
+
approvedCounts.set(subject.sha256, remaining - 1);
|
|
119
|
+
else
|
|
120
|
+
changed.push(subject.key);
|
|
121
|
+
}
|
|
122
|
+
const orphanedHashes = [];
|
|
123
|
+
for (const [hash, count] of approvedCounts) {
|
|
124
|
+
for (let i = 0; i < count; i += 1)
|
|
125
|
+
orphanedHashes.push(hash);
|
|
126
|
+
}
|
|
127
|
+
return { changed, orphanedHashes: orphanedHashes.sort() };
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=binding.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"binding.js","sourceRoot":"","sources":["../src/binding.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAKzC,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAcpE,kFAAkF;AAClF,MAAM,cAAc,GAAG,gBAAgB,CAAC;AAExC;;;;;;;GAOG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAc;IAC/C,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACjF,CAAC;AAED,qDAAqD;AACrD,MAAM,UAAU,WAAW,CAAC,KAA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IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IAE3F,MAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,MAAM,SAAS,GAAG,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC1D,IAAI,SAAS,GAAG,CAAC;YAAE,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,SAAS,GAAG,CAAC,CAAC,CAAC;;YAChE,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACjC,CAAC;IAED,MAAM,cAAc,GAAa,EAAE,CAAC;IACpC,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,cAAc,EAAE,CAAC;QAC3C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,IAAI,CAAC;YAAE,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC/D,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,cAAc,CAAC,IAAI,EAAE,EAAE,CAAC;AAC5D,CAAC"}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gate definitions (architecture contract §12, §13).
|
|
3
|
+
*
|
|
4
|
+
* A definition is **configuration**: what a gate binds to, what it depends on, how strongly it
|
|
5
|
+
* blocks, and who may decide it. A {@link GateDecision} is a **record**: what someone decided,
|
|
6
|
+
* when, and against which exact inputs. Keeping them apart is what lets a decision stay a
|
|
7
|
+
* faithful historical fact while the configuration around it evolves.
|
|
8
|
+
*
|
|
9
|
+
* Contract §13 names four gates — Content Freeze (§13.1), Performance Freeze (§13.2), Human Ear
|
|
10
|
+
* (§13.3), Final Release (§13.4). None of them is hardcoded here. §4.2 keeps show-specific
|
|
11
|
+
* process out of Core's reach and §4.3 gives adopters their own gates, so `gateId` and the
|
|
12
|
+
* subject keys are open strings and the contract's four gates are simply the definitions an
|
|
13
|
+
* adopter is most likely to write. The tests construct them to show the model expresses §13, not
|
|
14
|
+
* because the engine knows their names.
|
|
15
|
+
*/
|
|
16
|
+
import type { ActorKind } from "@aldus-runtime/core";
|
|
17
|
+
/**
|
|
18
|
+
* The four quality levels of contract §12.
|
|
19
|
+
*
|
|
20
|
+
* These describe *what kind of judgement* a gate represents, which is independent of how
|
|
21
|
+
* strongly it blocks. §12's own table pairs them freely: a hard gate blocks, an advisory signal
|
|
22
|
+
* does not, and a model-assisted review may do either depending on whether it has been
|
|
23
|
+
* calibrated (§12.1).
|
|
24
|
+
*/
|
|
25
|
+
export declare const GATE_LEVELS: readonly [
|
|
26
|
+
/** Blocks on an objectively testable failure (§12 level 1). */
|
|
27
|
+
"hard_gate",
|
|
28
|
+
/** Reports a possible issue without blocking (§12 level 2). */
|
|
29
|
+
"advisory_signal",
|
|
30
|
+
/** Evaluates meaning, stance, style, or claims under uncertainty (§12 level 3). */
|
|
31
|
+
"model_assisted",
|
|
32
|
+
/** A human owns the judgement, because it is subjective or asymmetric-risk (§12 level 4). */
|
|
33
|
+
"human_oracle"];
|
|
34
|
+
/** @see GATE_LEVELS */
|
|
35
|
+
export type GateLevel = (typeof GATE_LEVELS)[number];
|
|
36
|
+
/**
|
|
37
|
+
* Whether a gate stops work or merely reports.
|
|
38
|
+
*
|
|
39
|
+
* Deliberately a two-state enumeration rather than a boolean. Contract §12.1 permits an
|
|
40
|
+
* evaluator to *become* blocking only after calibration, which makes this a promotion with
|
|
41
|
+
* evidence behind it — and a field named `blocking: boolean` invites someone to flip it in a
|
|
42
|
+
* config file without producing any.
|
|
43
|
+
*/
|
|
44
|
+
export declare const GATE_ENFORCEMENTS: readonly ["blocking", "advisory"];
|
|
45
|
+
/** @see GATE_ENFORCEMENTS */
|
|
46
|
+
export type GateEnforcement = (typeof GATE_ENFORCEMENTS)[number];
|
|
47
|
+
/**
|
|
48
|
+
* Evidence that a model-assisted evaluator was calibrated before it was allowed to block.
|
|
49
|
+
*
|
|
50
|
+
* Contract §12.1: "An evaluator MAY become blocking only after it is calibrated against
|
|
51
|
+
* human-labeled examples." The metrics themselves belong to WP-10; this is the reference a
|
|
52
|
+
* definition must carry to claim they exist, and {@link validateGateDefinition} refuses a
|
|
53
|
+
* blocking model-assisted gate without one.
|
|
54
|
+
*
|
|
55
|
+
* `scope` matters as much as the numbers. §12.1 lists show, host, voice, model, and script-form
|
|
56
|
+
* scope among what promotion must consider, because an evaluator calibrated on one host says
|
|
57
|
+
* nothing about another. Dimensions are caller-supplied (§4.2), consistent with WP-09's packs.
|
|
58
|
+
*/
|
|
59
|
+
export interface PromotionEvidence {
|
|
60
|
+
/** Identifier of the calibration report that justified promotion (WP-10). */
|
|
61
|
+
reportRef: string;
|
|
62
|
+
/** Scope the calibration covers, e.g. `{ host: "example-host", voice: "voice-a" }`. */
|
|
63
|
+
scope: Record<string, string>;
|
|
64
|
+
/** Known blind spots recorded at promotion time (§12.1, §9.3). */
|
|
65
|
+
knownBlindSpots?: string[];
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* One configured gate.
|
|
69
|
+
*
|
|
70
|
+
* @see GateDecision for the record a decision on this gate produces.
|
|
71
|
+
*/
|
|
72
|
+
export interface GateDefinition {
|
|
73
|
+
/**
|
|
74
|
+
* Identity of the gate.
|
|
75
|
+
*
|
|
76
|
+
* An OPEN string. Contract §13's four gates are examples an adopter configures, not a set Core
|
|
77
|
+
* fixes (§4.2). Do not narrow this to a union.
|
|
78
|
+
*/
|
|
79
|
+
gateId: string;
|
|
80
|
+
/** Operator-facing name. */
|
|
81
|
+
title?: string;
|
|
82
|
+
/** What kind of judgement this gate represents (§12). */
|
|
83
|
+
level: GateLevel;
|
|
84
|
+
/** Whether it stops work or merely reports (§12). */
|
|
85
|
+
enforcement: GateEnforcement;
|
|
86
|
+
/**
|
|
87
|
+
* Named subjects a decision on this gate must bind.
|
|
88
|
+
*
|
|
89
|
+
* For a Performance Freeze these are §13.2's list — spoken-text hash, PerformanceScript hash,
|
|
90
|
+
* voice/model/settings, request plan or segment scope, maximum authorized cost — but the keys
|
|
91
|
+
* are caller-supplied strings, because what a gate binds is adopter process (§4.3).
|
|
92
|
+
*
|
|
93
|
+
* A decision that does not cover every key here is refused: §13.2 requires the operator to
|
|
94
|
+
* approve *all* of the listed values, and an authorization missing one of them binds less than
|
|
95
|
+
* the contract requires.
|
|
96
|
+
*/
|
|
97
|
+
binds: readonly string[];
|
|
98
|
+
/**
|
|
99
|
+
* Gates whose invalidation invalidates this one (contract §13.1).
|
|
100
|
+
*
|
|
101
|
+
* §13.1 requires a content-changing edit to invalidate the Content Freeze "and downstream
|
|
102
|
+
* approvals". This edge is what "downstream" means, stated per gate rather than inferred, so
|
|
103
|
+
* an adopter's own gates participate in the cascade without the engine guessing an order.
|
|
104
|
+
*/
|
|
105
|
+
dependsOn?: readonly string[];
|
|
106
|
+
/**
|
|
107
|
+
* Actor kinds permitted to decide this gate.
|
|
108
|
+
*
|
|
109
|
+
* Defaults to human-only for `human_oracle`, and to any actor otherwise. §13.3 keeps final
|
|
110
|
+
* performance approval human-owned "until a scoped evaluator is demonstrably reliable", and
|
|
111
|
+
* §12 forbids presenting a machine pass as semantic correctness.
|
|
112
|
+
*/
|
|
113
|
+
permittedActorKinds?: readonly ActorKind[];
|
|
114
|
+
/**
|
|
115
|
+
* Default for {@link GateDecision.expiresOnChange} on this gate.
|
|
116
|
+
*
|
|
117
|
+
* Defaults to `true`. §13.1 and §13.2 both require invalidation on change, and a gate that
|
|
118
|
+
* silently defaulted to carrying a stale approval forward would be the failure those sections
|
|
119
|
+
* exist to prevent.
|
|
120
|
+
*/
|
|
121
|
+
expiresOnChange?: boolean;
|
|
122
|
+
/** Calibration evidence, required when a model-assisted gate is blocking (§12.1). */
|
|
123
|
+
promotionEvidence?: PromotionEvidence;
|
|
124
|
+
/**
|
|
125
|
+
* Operations this gate authorizes, if any.
|
|
126
|
+
*
|
|
127
|
+
* Contract §13.4: "Uploading and making public SHOULD be separate operations." Naming the
|
|
128
|
+
* operations a gate grants is how that separation is expressed — an approval on one gate
|
|
129
|
+
* authorizes exactly the operations it names and nothing else, so a single decision cannot
|
|
130
|
+
* quietly cover both upload and publication.
|
|
131
|
+
*/
|
|
132
|
+
grants?: readonly string[];
|
|
133
|
+
}
|
|
134
|
+
/** A definition with every default resolved. */
|
|
135
|
+
export interface ResolvedGateDefinition extends GateDefinition {
|
|
136
|
+
dependsOn: readonly string[];
|
|
137
|
+
permittedActorKinds: readonly ActorKind[];
|
|
138
|
+
expiresOnChange: boolean;
|
|
139
|
+
grants: readonly string[];
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Resolve defaults and refuse an internally inconsistent definition.
|
|
143
|
+
*
|
|
144
|
+
* @throws {AldusError} `ALDUS_GATE_DEFINITION_INVALID`
|
|
145
|
+
*/
|
|
146
|
+
export declare function validateGateDefinition(definition: GateDefinition): ResolvedGateDefinition;
|
|
147
|
+
/**
|
|
148
|
+
* A validated set of gates and the dependency graph between them.
|
|
149
|
+
*
|
|
150
|
+
* Built once and reused: cycle detection and unknown-dependency checks run at construction, so a
|
|
151
|
+
* misconfiguration surfaces when the registry is assembled rather than when an operator is
|
|
152
|
+
* waiting on an approval.
|
|
153
|
+
*/
|
|
154
|
+
export declare class GateRegistry {
|
|
155
|
+
#private;
|
|
156
|
+
private constructor();
|
|
157
|
+
/**
|
|
158
|
+
* Validate a set of definitions and the graph they form.
|
|
159
|
+
*
|
|
160
|
+
* @throws {AldusError} `ALDUS_GATE_DEFINITION_INVALID` for an invalid or duplicate definition,
|
|
161
|
+
* or an edge naming a gate that does not exist.
|
|
162
|
+
* @throws {AldusError} `ALDUS_GATE_DEPENDENCY_CYCLE` if the dependency edges form a cycle.
|
|
163
|
+
*/
|
|
164
|
+
static from(definitions: readonly GateDefinition[]): GateRegistry;
|
|
165
|
+
/** Every gate, in definition order. */
|
|
166
|
+
list(): ResolvedGateDefinition[];
|
|
167
|
+
/** True if the gate is registered. */
|
|
168
|
+
has(gateId: string): boolean;
|
|
169
|
+
/** A gate definition, or `undefined` if it is not registered. */
|
|
170
|
+
get(gateId: string): ResolvedGateDefinition | undefined;
|
|
171
|
+
/**
|
|
172
|
+
* A gate definition.
|
|
173
|
+
*
|
|
174
|
+
* @throws {AldusError} `ALDUS_GATE_NOT_FOUND`
|
|
175
|
+
*/
|
|
176
|
+
require(gateId: string): ResolvedGateDefinition;
|
|
177
|
+
/** Gates that directly depend on `gateId`. */
|
|
178
|
+
dependentsOf(gateId: string): ResolvedGateDefinition[];
|
|
179
|
+
/**
|
|
180
|
+
* Gates that transitively depend on `gateId`, nearest first, excluding `gateId` itself.
|
|
181
|
+
*
|
|
182
|
+
* This is the reach of contract §13.1's cascade: invalidating a Content Freeze invalidates
|
|
183
|
+
* every approval downstream of it.
|
|
184
|
+
*/
|
|
185
|
+
downstreamOf(gateId: string): string[];
|
|
186
|
+
}
|
|
187
|
+
//# sourceMappingURL=definition.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definition.d.ts","sourceRoot":"","sources":["../src/definition.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAIrD;;;;;;;GAOG;AACH,eAAO,MAAM,WAAW;AACtB,+DAA+D;AAC/D,WAAW;AACX,+DAA+D;AAC/D,iBAAiB;AACjB,mFAAmF;AACnF,gBAAgB;AAChB,6FAA6F;AAC7F,cAAc,CACN,CAAC;AAEX,uBAAuB;AACvB,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AAErD;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB,YAAI,UAAU,EAAE,UAAU,CAAU,CAAC;AAEnE,6BAA6B;AAC7B,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,iB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