@byollm/control-plane 0.1.0-alpha.58
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 +21 -0
- package/README.md +90 -0
- package/dist/index.d.ts +220 -0
- package/dist/index.js +175 -0
- package/dist/index.js.map +1 -0
- package/dist/store-CzDvurIM.d.ts +121 -0
- package/dist/store-contract.d.ts +68 -0
- package/dist/store-contract.js +165 -0
- package/dist/store-contract.js.map +1 -0
- package/package.json +52 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Of Tomorrow, Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# @byollm/control-plane
|
|
2
|
+
|
|
3
|
+
> **Alpha (`0.1.0-alpha.58`) — under active development. Don't use this yet.**
|
|
4
|
+
|
|
5
|
+
The reference control plane: it resolves a person's mapping and authors one
|
|
6
|
+
signed grant per job, against a policy store it does not own and with a key it
|
|
7
|
+
never sees.
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { ControlPlane, MemoryPolicyStore, keypairSigner } from "@byollm/control-plane";
|
|
11
|
+
import { Relay } from "@byollm/relay";
|
|
12
|
+
|
|
13
|
+
const engine = new ControlPlane({
|
|
14
|
+
store: new MemoryPolicyStore(),
|
|
15
|
+
signer: keypairSigner(keys),
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const relay = new Relay({
|
|
19
|
+
fixture,
|
|
20
|
+
controlPlanePublic: engine.publicKey,
|
|
21
|
+
authorGrant: (input) => engine.authorGrant(input),
|
|
22
|
+
});
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## What this is for
|
|
26
|
+
|
|
27
|
+
A byollm device runs nothing on somebody else's behalf without a **grant**: a
|
|
28
|
+
short-lived, single-use, signed statement that this job, for this person, on
|
|
29
|
+
this device, may run — and which of the owner's services should answer. The
|
|
30
|
+
device verifies it against a key it pinned when it paired, so the party
|
|
31
|
+
routing the job can withhold a grant and cannot forge one.
|
|
32
|
+
|
|
33
|
+
This package is what writes them.
|
|
34
|
+
|
|
35
|
+
## Two things it deliberately does not hold
|
|
36
|
+
|
|
37
|
+
**Your data.** Accounts, consents, memberships and mappings live behind
|
|
38
|
+
[`PolicyStore`](src/store.ts). This package reads; it never owns. That is the
|
|
39
|
+
split that lets a hosted product keep its database while the *rule* over that
|
|
40
|
+
database stays readable — because a rule nobody can read is a rule nobody can
|
|
41
|
+
check.
|
|
42
|
+
|
|
43
|
+
**Your key.** [`GrantSigner`](src/signer.ts) is a function, not a keypair, so
|
|
44
|
+
custody can sit behind a KMS and this code cannot tell.
|
|
45
|
+
|
|
46
|
+
## The contract
|
|
47
|
+
|
|
48
|
+
`@byollm/control-plane/store-contract` is a suite any `PolicyStore` can run
|
|
49
|
+
against itself:
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
import { describePolicyStoreContract } from "@byollm/control-plane/store-contract";
|
|
53
|
+
|
|
54
|
+
describePolicyStoreContract("my store", { make: async () => ({ /* … */ }) });
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
It ships in the package because the implementation that matters most is in
|
|
58
|
+
somebody else's repository, and a contract only its author can run is a
|
|
59
|
+
description.
|
|
60
|
+
|
|
61
|
+
## The law it applies
|
|
62
|
+
|
|
63
|
+
In order, and the order is by whose fact each step is:
|
|
64
|
+
|
|
65
|
+
1. **A device always runs its own owner's work**, and no store is asked. It is
|
|
66
|
+
a law rather than an optimisation — routing it through a store would put it
|
|
67
|
+
somewhere an implementation could get wrong.
|
|
68
|
+
2. The person has **consented** to this site, and has not paused it.
|
|
69
|
+
3. They are a **member** of this device owner's team — asked only about other
|
|
70
|
+
people.
|
|
71
|
+
4. Their **mapping** for this (purpose, kind) names a service.
|
|
72
|
+
5. This device **actually offers** it, for this kind.
|
|
73
|
+
|
|
74
|
+
Any step failing stops the rest, so the reason returned names the first thing
|
|
75
|
+
that was wrong rather than whichever check ran last.
|
|
76
|
+
|
|
77
|
+
## Declining says whether it is forever
|
|
78
|
+
|
|
79
|
+
A relay releases a declined job, and a release can be permanent — never offer
|
|
80
|
+
this job to this device again. Getting that wrong permissively is a
|
|
81
|
+
claim-refuse loop, which announces itself. Getting it wrong strictly is a job
|
|
82
|
+
that can never reach the machine it was always meant for, and no error
|
|
83
|
+
anywhere. So only two reasons are permanent: a person removed from a team, and
|
|
84
|
+
consent withdrawn. An unfilled slot, a mapping that resolved to another
|
|
85
|
+
machine, and a policy store that was briefly unreachable are all states that
|
|
86
|
+
can change, and the job goes back in the queue.
|
|
87
|
+
|
|
88
|
+
## Licence
|
|
89
|
+
|
|
90
|
+
MIT.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { GrantClaims, SignedGrant, StoredKeys, ClaimedStub, CapabilityMatrix } from '@byollm/protocol';
|
|
2
|
+
import { P as PolicyStore, M as Mapping, a as PolicySnapshot } from './store-CzDvurIM.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Whatever holds the key that grants are signed with.
|
|
6
|
+
*
|
|
7
|
+
* A function rather than a key, so custody never enters this package. A
|
|
8
|
+
* self-hoster hands over a keypair; a hosted deployment can put the private
|
|
9
|
+
* half behind a KMS and pass a signer that calls it, and the engine cannot
|
|
10
|
+
* tell the difference — which is the point. Custody of the signing key is one
|
|
11
|
+
* of the two things byollm.cloud keeps, and an engine that had to be given
|
|
12
|
+
* the key could not be run any other way.
|
|
13
|
+
*
|
|
14
|
+
* `publicKey` sits on the same object deliberately. It is the value a relay
|
|
15
|
+
* hands a device at pairing, and it is the value that must verify what
|
|
16
|
+
* `sign` produces. Two separate configuration items would be two things a
|
|
17
|
+
* deployment could set inconsistently — and the failure mode is a fleet that
|
|
18
|
+
* refuses every job while every process reports itself healthy.
|
|
19
|
+
*/
|
|
20
|
+
interface GrantSigner {
|
|
21
|
+
/** The public half, for a relay to hand devices at pairing. */
|
|
22
|
+
readonly publicKey: string;
|
|
23
|
+
sign(claims: GrantClaims): Promise<SignedGrant> | SignedGrant;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Sign with a keypair this process holds.
|
|
27
|
+
*
|
|
28
|
+
* The implementation a self-hoster wants, and the one the tests use. A hosted
|
|
29
|
+
* deployment writes its own against whatever holds its key.
|
|
30
|
+
*/
|
|
31
|
+
declare function keypairSigner(keys: Pick<StoredKeys, "identityPrivate" | "identityPublic">): GrantSigner;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The control plane: one signed grant per job, or a reason there is none.
|
|
35
|
+
*
|
|
36
|
+
* byollm_016 Amendment J and L. This is the open engine behind a relay's
|
|
37
|
+
* `authorGrant` seam. It reads policy from a {@link PolicyStore} it does not
|
|
38
|
+
* own and signs with a {@link GrantSigner} whose key it never sees, so the
|
|
39
|
+
* two things byollm.cloud keeps — the data and the key — sit outside it, and
|
|
40
|
+
* the rule over them is readable by anybody.
|
|
41
|
+
*
|
|
42
|
+
* ## One routes, one authorises, only one signs
|
|
43
|
+
*
|
|
44
|
+
* A relay already filters what it offers a device, by consent and by
|
|
45
|
+
* membership. **That filter is an optimisation and this is the authority.**
|
|
46
|
+
* Everything is checked again here, because the relay's projection can be
|
|
47
|
+
* stale and because a grant asserting "consented, member, admitted" must be
|
|
48
|
+
* true when it is signed rather than when something upstream last looked. If
|
|
49
|
+
* the two disagree, this one wins and refuses.
|
|
50
|
+
*/
|
|
51
|
+
declare class ControlPlane {
|
|
52
|
+
#private;
|
|
53
|
+
constructor(options: {
|
|
54
|
+
readonly store: PolicyStore;
|
|
55
|
+
readonly signer: GrantSigner;
|
|
56
|
+
/** Injectable clock, so tests move time instead of sleeping. */
|
|
57
|
+
readonly now?: () => number;
|
|
58
|
+
/** Injectable id source, so a test can assert what was signed. */
|
|
59
|
+
readonly newGrantId?: () => string;
|
|
60
|
+
});
|
|
61
|
+
/** The key devices pin at pairing, from the same object that signs. */
|
|
62
|
+
get publicKey(): string;
|
|
63
|
+
/**
|
|
64
|
+
* Author a grant for one claimed job, or decline with a reason.
|
|
65
|
+
*
|
|
66
|
+
* The order below is the law, and it is ordered by *whose* fact each step
|
|
67
|
+
* is: the device's own owner first, then the person's consent, then their
|
|
68
|
+
* membership, then their mapping, then this machine's ability to honour it.
|
|
69
|
+
* A step that fails stops the rest, so the reason returned names the first
|
|
70
|
+
* thing that was actually wrong rather than whichever check ran last.
|
|
71
|
+
*/
|
|
72
|
+
authorGrant(input: {
|
|
73
|
+
readonly job: ClaimedStub;
|
|
74
|
+
/** The site's id in this control plane's namespace, not its key id. */
|
|
75
|
+
readonly siteId: string;
|
|
76
|
+
/** The device owner asking. */
|
|
77
|
+
readonly owner: string;
|
|
78
|
+
/**
|
|
79
|
+
* Which of the site's declared purposes this job serves.
|
|
80
|
+
*
|
|
81
|
+
* Supplied by the caller rather than read off the job, because in the
|
|
82
|
+
* release that built this engine the stub does not carry one yet — every
|
|
83
|
+
* job is the site's {@link RESERVED_PURPOSE}. When purposes reach the
|
|
84
|
+
* wire, the caller passes the job's own and nothing here changes.
|
|
85
|
+
*/
|
|
86
|
+
readonly purpose?: string;
|
|
87
|
+
/**
|
|
88
|
+
* What this device advertised it can serve.
|
|
89
|
+
*
|
|
90
|
+
* The control plane resolves a mapping to a service **from what the
|
|
91
|
+
* device said**, never from a name it invented. A mapping naming
|
|
92
|
+
* something this device does not offer is not honoured here — see
|
|
93
|
+
* `resolved-elsewhere`.
|
|
94
|
+
*/
|
|
95
|
+
readonly capabilities: CapabilityMatrix;
|
|
96
|
+
}): Promise<GrantOutcome>;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Why no grant was authored — and, load-bearing, whether that is forever.
|
|
100
|
+
*
|
|
101
|
+
* The distinction exists because a relay releases a declined job, and a
|
|
102
|
+
* release can carry `refused`, which means *never offer this job to this
|
|
103
|
+
* device again*. Getting that wrong in the permissive direction is a
|
|
104
|
+
* claim-refuse loop; getting it wrong in the strict direction is a job that
|
|
105
|
+
* can never reach the machine it was always meant for, and no error anywhere.
|
|
106
|
+
*/
|
|
107
|
+
type DeclineReason =
|
|
108
|
+
/** This person may not use this owner's devices. */
|
|
109
|
+
"not-a-member"
|
|
110
|
+
/** This person has not authorised this site. */
|
|
111
|
+
| "not-consented"
|
|
112
|
+
/** They authorised it and left this slot empty. */
|
|
113
|
+
| "unmapped"
|
|
114
|
+
/** Their mapping names a service this device does not offer. */
|
|
115
|
+
| "resolved-elsewhere"
|
|
116
|
+
/** The policy store could not answer. Says nothing about the job. */
|
|
117
|
+
| "store-unavailable";
|
|
118
|
+
interface Decline {
|
|
119
|
+
readonly reason: DeclineReason;
|
|
120
|
+
/**
|
|
121
|
+
* Never offer this job to this device again.
|
|
122
|
+
*
|
|
123
|
+
* True only for the two facts that a queued job cannot outlive: a person
|
|
124
|
+
* removed from a team, and consent withdrawn. Hole 1 ruled that removal
|
|
125
|
+
* stops future claims *including queued ones*, and this is where that is
|
|
126
|
+
* enforced.
|
|
127
|
+
*
|
|
128
|
+
* Everything else is a state the user can change, or a fault of ours. A
|
|
129
|
+
* permanent mark on those would outlive the condition that caused it.
|
|
130
|
+
*/
|
|
131
|
+
readonly permanent: boolean;
|
|
132
|
+
}
|
|
133
|
+
type GrantOutcome = {
|
|
134
|
+
readonly granted: SignedGrant;
|
|
135
|
+
readonly declined?: undefined;
|
|
136
|
+
} | {
|
|
137
|
+
readonly granted?: undefined;
|
|
138
|
+
readonly declined: Decline;
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* A policy store in a `Map`, for tests and for a single-process self-hoster.
|
|
143
|
+
*
|
|
144
|
+
* It is the reference implementation in the sense that matters: the contract
|
|
145
|
+
* suite runs against it, so it is the thing anybody else's store is compared
|
|
146
|
+
* to. It is not a suggestion about how to build one — a real store is a
|
|
147
|
+
* database, and this one forgets everything when the process ends.
|
|
148
|
+
*/
|
|
149
|
+
declare class MemoryPolicyStore implements PolicyStore {
|
|
150
|
+
#private;
|
|
151
|
+
/**
|
|
152
|
+
* Record a consent, with the mapping it carries.
|
|
153
|
+
*
|
|
154
|
+
* One call because they are one act: the mapping **is** the consent
|
|
155
|
+
* (Amendment L), and a store that let them be written separately would
|
|
156
|
+
* allow a state — consented, no mappings, no way to have got there — that
|
|
157
|
+
* the product cannot produce.
|
|
158
|
+
*
|
|
159
|
+
* Consenting with an empty list is the real signup state, though: a person
|
|
160
|
+
* whose slots all had two candidates and who has not chosen yet.
|
|
161
|
+
*/
|
|
162
|
+
consent(input: {
|
|
163
|
+
siteId: string;
|
|
164
|
+
user: string;
|
|
165
|
+
mappings?: readonly Mapping[];
|
|
166
|
+
}): void;
|
|
167
|
+
/**
|
|
168
|
+
* Pause a consent without withdrawing it.
|
|
169
|
+
*
|
|
170
|
+
* A real product state and not the same as revoking: the mapping survives,
|
|
171
|
+
* so resuming does not ask somebody to author their choices again. What it
|
|
172
|
+
* must not do is let work through — a relay's projection can lag by
|
|
173
|
+
* seconds, and a grant authored in that window would run work whose owner
|
|
174
|
+
* had just stopped it.
|
|
175
|
+
*/
|
|
176
|
+
pause(input: {
|
|
177
|
+
siteId: string;
|
|
178
|
+
user: string;
|
|
179
|
+
}): void;
|
|
180
|
+
/** Let it move again. */
|
|
181
|
+
resume(input: {
|
|
182
|
+
siteId: string;
|
|
183
|
+
user: string;
|
|
184
|
+
}): void;
|
|
185
|
+
/**
|
|
186
|
+
* Withdraw consent, which deletes the mapping with it.
|
|
187
|
+
*
|
|
188
|
+
* Not two operations. "Revoking consent deletes the mapping — the mapping
|
|
189
|
+
* is the consent, so un-consenting unmaps" (hole 2), and a store that could
|
|
190
|
+
* leave one behind would leave a resolution pointing at a service the
|
|
191
|
+
* person no longer authorises anybody to reach.
|
|
192
|
+
*/
|
|
193
|
+
revoke(input: {
|
|
194
|
+
siteId: string;
|
|
195
|
+
user: string;
|
|
196
|
+
}): void;
|
|
197
|
+
/** Add somebody to an owner's team. */
|
|
198
|
+
addMember(input: {
|
|
199
|
+
owner: string;
|
|
200
|
+
user: string;
|
|
201
|
+
}): void;
|
|
202
|
+
/**
|
|
203
|
+
* Remove somebody from an owner's team.
|
|
204
|
+
*
|
|
205
|
+
* There is no "blocked but still a member": a team **is** access to its
|
|
206
|
+
* owner's devices and nothing else, so member-but-blocked is not a deferred
|
|
207
|
+
* feature, it is an empty state (Amendment J).
|
|
208
|
+
*/
|
|
209
|
+
removeMember(input: {
|
|
210
|
+
owner: string;
|
|
211
|
+
user: string;
|
|
212
|
+
}): void;
|
|
213
|
+
read(input: {
|
|
214
|
+
siteId: string;
|
|
215
|
+
user: string;
|
|
216
|
+
owner: string;
|
|
217
|
+
}): Promise<PolicySnapshot>;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
export { ControlPlane, type Decline, type DeclineReason, type GrantOutcome, type GrantSigner, Mapping, MemoryPolicyStore, PolicySnapshot, PolicyStore, keypairSigner };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
// src/engine.ts
|
|
2
|
+
import { randomUUID } from "crypto";
|
|
3
|
+
import {
|
|
4
|
+
RESERVED_PURPOSE
|
|
5
|
+
} from "@byollm/protocol";
|
|
6
|
+
var ControlPlane = class {
|
|
7
|
+
#store;
|
|
8
|
+
#signer;
|
|
9
|
+
#now;
|
|
10
|
+
#newId;
|
|
11
|
+
constructor(options) {
|
|
12
|
+
this.#store = options.store;
|
|
13
|
+
this.#signer = options.signer;
|
|
14
|
+
this.#now = options.now ?? Date.now;
|
|
15
|
+
this.#newId = options.newGrantId ?? (() => `grant_${randomUUID()}`);
|
|
16
|
+
}
|
|
17
|
+
/** The key devices pin at pairing, from the same object that signs. */
|
|
18
|
+
get publicKey() {
|
|
19
|
+
return this.#signer.publicKey;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Author a grant for one claimed job, or decline with a reason.
|
|
23
|
+
*
|
|
24
|
+
* The order below is the law, and it is ordered by *whose* fact each step
|
|
25
|
+
* is: the device's own owner first, then the person's consent, then their
|
|
26
|
+
* membership, then their mapping, then this machine's ability to honour it.
|
|
27
|
+
* A step that fails stops the rest, so the reason returned names the first
|
|
28
|
+
* thing that was actually wrong rather than whichever check ran last.
|
|
29
|
+
*/
|
|
30
|
+
async authorGrant(input) {
|
|
31
|
+
const { job, owner } = input;
|
|
32
|
+
const purpose = input.purpose ?? RESERVED_PURPOSE;
|
|
33
|
+
let snapshot;
|
|
34
|
+
try {
|
|
35
|
+
snapshot = await this.#store.read({
|
|
36
|
+
siteId: input.siteId,
|
|
37
|
+
user: job.owner,
|
|
38
|
+
owner
|
|
39
|
+
});
|
|
40
|
+
} catch {
|
|
41
|
+
return decline("store-unavailable");
|
|
42
|
+
}
|
|
43
|
+
if (!snapshot.consented) return decline("not-consented");
|
|
44
|
+
if (job.owner !== owner && !snapshot.member) return decline("not-a-member");
|
|
45
|
+
const mapped = snapshot.mappings.find(
|
|
46
|
+
(mapping) => mapping.purpose === purpose && mapping.kind === job.kind
|
|
47
|
+
);
|
|
48
|
+
if (!mapped) return decline("unmapped");
|
|
49
|
+
if ((mapped.owner ?? job.owner) !== owner) {
|
|
50
|
+
return decline("resolved-elsewhere");
|
|
51
|
+
}
|
|
52
|
+
const offered = input.capabilities.some(
|
|
53
|
+
(capability) => capability.kind === job.kind && capability.service === mapped.service
|
|
54
|
+
);
|
|
55
|
+
if (!offered) return decline("resolved-elsewhere");
|
|
56
|
+
return {
|
|
57
|
+
granted: await this.#signer.sign({
|
|
58
|
+
grantId: this.#newId(),
|
|
59
|
+
jobId: job.id,
|
|
60
|
+
siteId: input.siteId,
|
|
61
|
+
user: job.owner,
|
|
62
|
+
owner,
|
|
63
|
+
purpose,
|
|
64
|
+
kind: job.kind,
|
|
65
|
+
service: mapped.service,
|
|
66
|
+
issuedAt: this.#now()
|
|
67
|
+
})
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
var PERMANENT = /* @__PURE__ */ new Set([
|
|
72
|
+
"not-a-member",
|
|
73
|
+
"not-consented"
|
|
74
|
+
]);
|
|
75
|
+
function decline(reason) {
|
|
76
|
+
return { declined: { reason, permanent: PERMANENT.has(reason) } };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// src/memory.ts
|
|
80
|
+
var MemoryPolicyStore = class {
|
|
81
|
+
/** (siteId, user) to what that person authorised for that site. */
|
|
82
|
+
#consents = /* @__PURE__ */ new Map();
|
|
83
|
+
/** (siteId, user) pairs whose owner has paused them. */
|
|
84
|
+
#paused = /* @__PURE__ */ new Set();
|
|
85
|
+
/** owner to the people who may use their devices. */
|
|
86
|
+
#members = /* @__PURE__ */ new Map();
|
|
87
|
+
/**
|
|
88
|
+
* Record a consent, with the mapping it carries.
|
|
89
|
+
*
|
|
90
|
+
* One call because they are one act: the mapping **is** the consent
|
|
91
|
+
* (Amendment L), and a store that let them be written separately would
|
|
92
|
+
* allow a state — consented, no mappings, no way to have got there — that
|
|
93
|
+
* the product cannot produce.
|
|
94
|
+
*
|
|
95
|
+
* Consenting with an empty list is the real signup state, though: a person
|
|
96
|
+
* whose slots all had two candidates and who has not chosen yet.
|
|
97
|
+
*/
|
|
98
|
+
consent(input) {
|
|
99
|
+
this.#consents.set(key(input.siteId, input.user), [
|
|
100
|
+
...input.mappings ?? []
|
|
101
|
+
]);
|
|
102
|
+
this.#paused.delete(key(input.siteId, input.user));
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Pause a consent without withdrawing it.
|
|
106
|
+
*
|
|
107
|
+
* A real product state and not the same as revoking: the mapping survives,
|
|
108
|
+
* so resuming does not ask somebody to author their choices again. What it
|
|
109
|
+
* must not do is let work through — a relay's projection can lag by
|
|
110
|
+
* seconds, and a grant authored in that window would run work whose owner
|
|
111
|
+
* had just stopped it.
|
|
112
|
+
*/
|
|
113
|
+
pause(input) {
|
|
114
|
+
this.#paused.add(key(input.siteId, input.user));
|
|
115
|
+
}
|
|
116
|
+
/** Let it move again. */
|
|
117
|
+
resume(input) {
|
|
118
|
+
this.#paused.delete(key(input.siteId, input.user));
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Withdraw consent, which deletes the mapping with it.
|
|
122
|
+
*
|
|
123
|
+
* Not two operations. "Revoking consent deletes the mapping — the mapping
|
|
124
|
+
* is the consent, so un-consenting unmaps" (hole 2), and a store that could
|
|
125
|
+
* leave one behind would leave a resolution pointing at a service the
|
|
126
|
+
* person no longer authorises anybody to reach.
|
|
127
|
+
*/
|
|
128
|
+
revoke(input) {
|
|
129
|
+
this.#consents.delete(key(input.siteId, input.user));
|
|
130
|
+
this.#paused.delete(key(input.siteId, input.user));
|
|
131
|
+
}
|
|
132
|
+
/** Add somebody to an owner's team. */
|
|
133
|
+
addMember(input) {
|
|
134
|
+
const members = this.#members.get(input.owner) ?? /* @__PURE__ */ new Set();
|
|
135
|
+
members.add(input.user);
|
|
136
|
+
this.#members.set(input.owner, members);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Remove somebody from an owner's team.
|
|
140
|
+
*
|
|
141
|
+
* There is no "blocked but still a member": a team **is** access to its
|
|
142
|
+
* owner's devices and nothing else, so member-but-blocked is not a deferred
|
|
143
|
+
* feature, it is an empty state (Amendment J).
|
|
144
|
+
*/
|
|
145
|
+
removeMember(input) {
|
|
146
|
+
this.#members.get(input.owner)?.delete(input.user);
|
|
147
|
+
}
|
|
148
|
+
read(input) {
|
|
149
|
+
const id = key(input.siteId, input.user);
|
|
150
|
+
const mappings = this.#consents.get(id);
|
|
151
|
+
return Promise.resolve({
|
|
152
|
+
consented: mappings !== void 0 && !this.#paused.has(id),
|
|
153
|
+
member: this.#members.get(input.owner)?.has(input.user) ?? false,
|
|
154
|
+
mappings: mappings ?? []
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
var key = (siteId, user) => `${siteId}\0${user}`;
|
|
159
|
+
|
|
160
|
+
// src/signer.ts
|
|
161
|
+
import {
|
|
162
|
+
signGrant
|
|
163
|
+
} from "@byollm/protocol";
|
|
164
|
+
function keypairSigner(keys) {
|
|
165
|
+
return {
|
|
166
|
+
publicKey: keys.identityPublic,
|
|
167
|
+
sign: (claims) => signGrant(keys, claims)
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
export {
|
|
171
|
+
ControlPlane,
|
|
172
|
+
MemoryPolicyStore,
|
|
173
|
+
keypairSigner
|
|
174
|
+
};
|
|
175
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/engine.ts","../src/memory.ts","../src/signer.ts"],"sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport {\n RESERVED_PURPOSE,\n type CapabilityMatrix,\n type ClaimedStub,\n type SignedGrant,\n} from \"@byollm/protocol\";\nimport type { GrantSigner } from \"./signer.js\";\nimport type { PolicyStore } from \"./store.js\";\n\n/**\n * The control plane: one signed grant per job, or a reason there is none.\n *\n * byollm_016 Amendment J and L. This is the open engine behind a relay's\n * `authorGrant` seam. It reads policy from a {@link PolicyStore} it does not\n * own and signs with a {@link GrantSigner} whose key it never sees, so the\n * two things byollm.cloud keeps — the data and the key — sit outside it, and\n * the rule over them is readable by anybody.\n *\n * ## One routes, one authorises, only one signs\n *\n * A relay already filters what it offers a device, by consent and by\n * membership. **That filter is an optimisation and this is the authority.**\n * Everything is checked again here, because the relay's projection can be\n * stale and because a grant asserting \"consented, member, admitted\" must be\n * true when it is signed rather than when something upstream last looked. If\n * the two disagree, this one wins and refuses.\n */\nexport class ControlPlane {\n readonly #store: PolicyStore;\n readonly #signer: GrantSigner;\n readonly #now: () => number;\n readonly #newId: () => string;\n\n constructor(options: {\n readonly store: PolicyStore;\n readonly signer: GrantSigner;\n /** Injectable clock, so tests move time instead of sleeping. */\n readonly now?: () => number;\n /** Injectable id source, so a test can assert what was signed. */\n readonly newGrantId?: () => string;\n }) {\n this.#store = options.store;\n this.#signer = options.signer;\n this.#now = options.now ?? Date.now;\n this.#newId = options.newGrantId ?? (() => `grant_${randomUUID()}`);\n }\n\n /** The key devices pin at pairing, from the same object that signs. */\n get publicKey(): string {\n return this.#signer.publicKey;\n }\n\n /**\n * Author a grant for one claimed job, or decline with a reason.\n *\n * The order below is the law, and it is ordered by *whose* fact each step\n * is: the device's own owner first, then the person's consent, then their\n * membership, then their mapping, then this machine's ability to honour it.\n * A step that fails stops the rest, so the reason returned names the first\n * thing that was actually wrong rather than whichever check ran last.\n */\n async authorGrant(input: {\n readonly job: ClaimedStub;\n /** The site's id in this control plane's namespace, not its key id. */\n readonly siteId: string;\n /** The device owner asking. */\n readonly owner: string;\n /**\n * Which of the site's declared purposes this job serves.\n *\n * Supplied by the caller rather than read off the job, because in the\n * release that built this engine the stub does not carry one yet — every\n * job is the site's {@link RESERVED_PURPOSE}. When purposes reach the\n * wire, the caller passes the job's own and nothing here changes.\n */\n readonly purpose?: string;\n /**\n * What this device advertised it can serve.\n *\n * The control plane resolves a mapping to a service **from what the\n * device said**, never from a name it invented. A mapping naming\n * something this device does not offer is not honoured here — see\n * `resolved-elsewhere`.\n */\n readonly capabilities: CapabilityMatrix;\n }): Promise<GrantOutcome> {\n const { job, owner } = input;\n const purpose = input.purpose ?? RESERVED_PURPOSE;\n\n let snapshot;\n try {\n snapshot = await this.#store.read({\n siteId: input.siteId,\n user: job.owner,\n owner,\n });\n } catch {\n /**\n * A store that could not answer is not a refusal.\n *\n * Failing closed is right — nothing is signed — but the *shape* of the\n * failure matters more than it looks. A permanent refusal here would\n * mean a database blip permanently unpicked a job from a device, and\n * nothing would ever put it back. Transient, therefore, and the job\n * goes back in the queue.\n */\n return decline(\"store-unavailable\");\n }\n\n if (!snapshot.consented) return decline(\"not-consented\");\n\n /**\n * A device always runs its own owner's work, and no store is asked.\n *\n * Not an optimisation. Routing this through the store would put a law\n * somewhere an implementation could get wrong — including by answering\n * `member: false` for somebody's own account and silently stopping their\n * own device. There is no answer a store could give that should change\n * this, so it is not asked the question.\n */\n if (job.owner !== owner && !snapshot.member) return decline(\"not-a-member\");\n\n const mapped = snapshot.mappings.find(\n (mapping) => mapping.purpose === purpose && mapping.kind === job.kind,\n );\n /**\n * An unmapped slot makes a purpose unavailable, never a site broken.\n *\n * Transient, because the remedy is the user's and they may take it: a\n * mapping authored a minute from now should let this job run, and a\n * permanent refusal would have quietly excluded the one device it was\n * about to point at.\n */\n if (!mapped) return decline(\"unmapped\");\n\n /**\n * The device has to actually offer it, for this kind.\n *\n * Two different situations arrive here and this vantage cannot tell them\n * apart: the mapping resolved to a *different* device of this owner's, or\n * its referent is gone entirely — a service renamed or deleted. From one\n * device's capabilities both look identical, so the name says only what\n * is knowable here.\n *\n * Whether it is *no* device is a question for a sweep across the owner's\n * services, which is where the \"your mapping needs updating\" notification\n * belongs — not on the claim path, which sees one machine at a time.\n */\n /**\n * Whose machine, before which service.\n *\n * A service id means something only inside its owner's namespace, so a\n * mapping naming a teammate's `qwen` must not be satisfied by a different\n * teammate's `qwen` — or by the mapper's own. Checked before the\n * capability list, because a device that merely shares a name is not\n * \"the wrong service\" but the wrong machine, and the capabilities of the\n * wrong machine say nothing either way.\n */\n if ((mapped.owner ?? job.owner) !== owner) {\n return decline(\"resolved-elsewhere\");\n }\n\n const offered = input.capabilities.some(\n (capability) =>\n capability.kind === job.kind && capability.service === mapped.service,\n );\n if (!offered) return decline(\"resolved-elsewhere\");\n\n return {\n granted: await this.#signer.sign({\n grantId: this.#newId(),\n jobId: job.id,\n siteId: input.siteId,\n user: job.owner,\n owner,\n purpose,\n kind: job.kind,\n service: mapped.service,\n issuedAt: this.#now(),\n }),\n };\n }\n}\n\n/**\n * Why no grant was authored — and, load-bearing, whether that is forever.\n *\n * The distinction exists because a relay releases a declined job, and a\n * release can carry `refused`, which means *never offer this job to this\n * device again*. Getting that wrong in the permissive direction is a\n * claim-refuse loop; getting it wrong in the strict direction is a job that\n * can never reach the machine it was always meant for, and no error anywhere.\n */\nexport type DeclineReason =\n /** This person may not use this owner's devices. */\n | \"not-a-member\"\n /** This person has not authorised this site. */\n | \"not-consented\"\n /** They authorised it and left this slot empty. */\n | \"unmapped\"\n /** Their mapping names a service this device does not offer. */\n | \"resolved-elsewhere\"\n /** The policy store could not answer. Says nothing about the job. */\n | \"store-unavailable\";\n\nexport interface Decline {\n readonly reason: DeclineReason;\n /**\n * Never offer this job to this device again.\n *\n * True only for the two facts that a queued job cannot outlive: a person\n * removed from a team, and consent withdrawn. Hole 1 ruled that removal\n * stops future claims *including queued ones*, and this is where that is\n * enforced.\n *\n * Everything else is a state the user can change, or a fault of ours. A\n * permanent mark on those would outlive the condition that caused it.\n */\n readonly permanent: boolean;\n}\n\nexport type GrantOutcome =\n | { readonly granted: SignedGrant; readonly declined?: undefined }\n | { readonly granted?: undefined; readonly declined: Decline };\n\nconst PERMANENT: ReadonlySet<DeclineReason> = new Set([\n \"not-a-member\",\n \"not-consented\",\n]);\n\nfunction decline(reason: DeclineReason): GrantOutcome {\n return { declined: { reason, permanent: PERMANENT.has(reason) } };\n}\n","import type { Mapping, PolicySnapshot, PolicyStore } from \"./store.js\";\n\n/**\n * A policy store in a `Map`, for tests and for a single-process self-hoster.\n *\n * It is the reference implementation in the sense that matters: the contract\n * suite runs against it, so it is the thing anybody else's store is compared\n * to. It is not a suggestion about how to build one — a real store is a\n * database, and this one forgets everything when the process ends.\n */\nexport class MemoryPolicyStore implements PolicyStore {\n /** (siteId, user) to what that person authorised for that site. */\n readonly #consents = new Map<string, Mapping[]>();\n /** (siteId, user) pairs whose owner has paused them. */\n readonly #paused = new Set<string>();\n /** owner to the people who may use their devices. */\n readonly #members = new Map<string, Set<string>>();\n\n /**\n * Record a consent, with the mapping it carries.\n *\n * One call because they are one act: the mapping **is** the consent\n * (Amendment L), and a store that let them be written separately would\n * allow a state — consented, no mappings, no way to have got there — that\n * the product cannot produce.\n *\n * Consenting with an empty list is the real signup state, though: a person\n * whose slots all had two candidates and who has not chosen yet.\n */\n consent(input: {\n siteId: string;\n user: string;\n mappings?: readonly Mapping[];\n }): void {\n this.#consents.set(key(input.siteId, input.user), [\n ...(input.mappings ?? []),\n ]);\n this.#paused.delete(key(input.siteId, input.user));\n }\n\n /**\n * Pause a consent without withdrawing it.\n *\n * A real product state and not the same as revoking: the mapping survives,\n * so resuming does not ask somebody to author their choices again. What it\n * must not do is let work through — a relay's projection can lag by\n * seconds, and a grant authored in that window would run work whose owner\n * had just stopped it.\n */\n pause(input: { siteId: string; user: string }): void {\n this.#paused.add(key(input.siteId, input.user));\n }\n\n /** Let it move again. */\n resume(input: { siteId: string; user: string }): void {\n this.#paused.delete(key(input.siteId, input.user));\n }\n\n /**\n * Withdraw consent, which deletes the mapping with it.\n *\n * Not two operations. \"Revoking consent deletes the mapping — the mapping\n * is the consent, so un-consenting unmaps\" (hole 2), and a store that could\n * leave one behind would leave a resolution pointing at a service the\n * person no longer authorises anybody to reach.\n */\n revoke(input: { siteId: string; user: string }): void {\n this.#consents.delete(key(input.siteId, input.user));\n this.#paused.delete(key(input.siteId, input.user));\n }\n\n /** Add somebody to an owner's team. */\n addMember(input: { owner: string; user: string }): void {\n const members = this.#members.get(input.owner) ?? new Set<string>();\n members.add(input.user);\n this.#members.set(input.owner, members);\n }\n\n /**\n * Remove somebody from an owner's team.\n *\n * There is no \"blocked but still a member\": a team **is** access to its\n * owner's devices and nothing else, so member-but-blocked is not a deferred\n * feature, it is an empty state (Amendment J).\n */\n removeMember(input: { owner: string; user: string }): void {\n this.#members.get(input.owner)?.delete(input.user);\n }\n\n read(input: {\n siteId: string;\n user: string;\n owner: string;\n }): Promise<PolicySnapshot> {\n const id = key(input.siteId, input.user);\n const mappings = this.#consents.get(id);\n return Promise.resolve({\n consented: mappings !== undefined && !this.#paused.has(id),\n member: this.#members.get(input.owner)?.has(input.user) ?? false,\n mappings: mappings ?? [],\n });\n }\n}\n\n/**\n * NUL-joined, for the reason `routeKey` is.\n *\n * A composite key is a parser waiting to meet an id containing its separator.\n * NUL cannot appear in either half, so no arrangement of a site id and a user\n * id can spell a different pair.\n */\nconst key = (siteId: string, user: string): string => `${siteId}\\u0000${user}`;\n","import {\n signGrant,\n type GrantClaims,\n type SignedGrant,\n type StoredKeys,\n} from \"@byollm/protocol\";\n\n/**\n * Whatever holds the key that grants are signed with.\n *\n * A function rather than a key, so custody never enters this package. A\n * self-hoster hands over a keypair; a hosted deployment can put the private\n * half behind a KMS and pass a signer that calls it, and the engine cannot\n * tell the difference — which is the point. Custody of the signing key is one\n * of the two things byollm.cloud keeps, and an engine that had to be given\n * the key could not be run any other way.\n *\n * `publicKey` sits on the same object deliberately. It is the value a relay\n * hands a device at pairing, and it is the value that must verify what\n * `sign` produces. Two separate configuration items would be two things a\n * deployment could set inconsistently — and the failure mode is a fleet that\n * refuses every job while every process reports itself healthy.\n */\nexport interface GrantSigner {\n /** The public half, for a relay to hand devices at pairing. */\n readonly publicKey: string;\n sign(claims: GrantClaims): Promise<SignedGrant> | SignedGrant;\n}\n\n/**\n * Sign with a keypair this process holds.\n *\n * The implementation a self-hoster wants, and the one the tests use. A hosted\n * deployment writes its own against whatever holds its key.\n */\nexport function keypairSigner(\n keys: Pick<StoredKeys, \"identityPrivate\" | \"identityPublic\">,\n): GrantSigner {\n return {\n publicKey: keys.identityPublic,\n sign: (claims) => signGrant(keys, claims),\n };\n}\n"],"mappings":";AAAA,SAAS,kBAAkB;AAC3B;AAAA,EACE;AAAA,OAIK;AAsBA,IAAM,eAAN,MAAmB;AAAA,EACf;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAET,YAAY,SAOT;AACD,SAAK,SAAS,QAAQ;AACtB,SAAK,UAAU,QAAQ;AACvB,SAAK,OAAO,QAAQ,OAAO,KAAK;AAChC,SAAK,SAAS,QAAQ,eAAe,MAAM,SAAS,WAAW,CAAC;AAAA,EAClE;AAAA;AAAA,EAGA,IAAI,YAAoB;AACtB,WAAO,KAAK,QAAQ;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,MAAM,YAAY,OAwBQ;AACxB,UAAM,EAAE,KAAK,MAAM,IAAI;AACvB,UAAM,UAAU,MAAM,WAAW;AAEjC,QAAI;AACJ,QAAI;AACF,iBAAW,MAAM,KAAK,OAAO,KAAK;AAAA,QAChC,QAAQ,MAAM;AAAA,QACd,MAAM,IAAI;AAAA,QACV;AAAA,MACF,CAAC;AAAA,IACH,QAAQ;AAUN,aAAO,QAAQ,mBAAmB;AAAA,IACpC;AAEA,QAAI,CAAC,SAAS,UAAW,QAAO,QAAQ,eAAe;AAWvD,QAAI,IAAI,UAAU,SAAS,CAAC,SAAS,OAAQ,QAAO,QAAQ,cAAc;AAE1E,UAAM,SAAS,SAAS,SAAS;AAAA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AAAA,EACE;AAAA,OAIK;AA8BA,SAAS,cACd,MACa;AACb,SAAO;AAAA,IACL,WAAW,KAAK;AAAA,IAChB,MAAM,CAAC,WAAW,UAAU,MAAM,MAAM;AAAA,EAC1C;AACF;","names":[]}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the control plane reads, and never owns.
|
|
3
|
+
*
|
|
4
|
+
* byollm_016 Amendment L. Every fact the engine needs to author one grant —
|
|
5
|
+
* whether a person consented to a site, whether they may use somebody's
|
|
6
|
+
* devices, and which of that owner's services their mapping resolves to —
|
|
7
|
+
* comes from here. The engine holds none of it.
|
|
8
|
+
*
|
|
9
|
+
* ## Why this is an interface rather than a table
|
|
10
|
+
*
|
|
11
|
+
* The policy store is where accounts, consents, memberships, mappings and
|
|
12
|
+
* billing live, and it is the part of byollm.cloud that stays proprietary.
|
|
13
|
+
* The *law* over that data is not: it is the engine, and it is open, so a
|
|
14
|
+
* self-hoster runs the same resolution against their own store and a reader
|
|
15
|
+
* can check what the hosted product does with theirs.
|
|
16
|
+
*
|
|
17
|
+
* The split is drawn where it is because these are genuinely different kinds
|
|
18
|
+
* of thing. Who is on whose team is somebody's data. What that membership
|
|
19
|
+
* *entitles* is a rule, and a rule nobody can read is a rule nobody can
|
|
20
|
+
* check.
|
|
21
|
+
*
|
|
22
|
+
* ## The contract
|
|
23
|
+
*
|
|
24
|
+
* `@byollm/control-plane/store-contract` is a suite any implementation can
|
|
25
|
+
* run against itself. It ships in the package for the reason the routing
|
|
26
|
+
* store's does: the implementation that matters most lives in another
|
|
27
|
+
* repository, and a contract only its author can run is a description.
|
|
28
|
+
*/
|
|
29
|
+
/**
|
|
30
|
+
* One slot a user has filled: this site's purpose, for this kind, runs there.
|
|
31
|
+
*
|
|
32
|
+
* Keyed by (purpose, kind) because a purpose may span kinds — "writing
|
|
33
|
+
* assistant" might use both `llm.chat` and `llm.generate` — and a person may
|
|
34
|
+
* reasonably want different services behind them.
|
|
35
|
+
*
|
|
36
|
+
* `service` is a service id in the **device owner's** namespace, which is why
|
|
37
|
+
* a mapping is only meaningful alongside the owner it was authored against.
|
|
38
|
+
*/
|
|
39
|
+
interface Mapping {
|
|
40
|
+
readonly purpose: string;
|
|
41
|
+
readonly kind: string;
|
|
42
|
+
/** The service id, in {@link Mapping.owner}'s namespace. */
|
|
43
|
+
readonly service: string;
|
|
44
|
+
/**
|
|
45
|
+
* Whose service it is. `null` means the mapper's own.
|
|
46
|
+
*
|
|
47
|
+
* **Not optional decoration.** Service ids are namespace-local: alice may
|
|
48
|
+
* be on two teams that both have a service called `qwen`, and the consent
|
|
49
|
+
* screen shows them as the two different choices they are. A mapping that
|
|
50
|
+
* stored only the name could not tell them apart — so her work would be
|
|
51
|
+
* admitted on whichever of those machines claimed it first, which is
|
|
52
|
+
* exactly the substitution this design exists to forbid.
|
|
53
|
+
*
|
|
54
|
+
* The first draft of this interface had only the name, and the consent
|
|
55
|
+
* screen's own test — "keeps a teammate's identical service name separate
|
|
56
|
+
* from your own" — was already asserting the distinction that the storage
|
|
57
|
+
* could not keep.
|
|
58
|
+
*/
|
|
59
|
+
readonly owner: string | null;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Everything the engine needs about one (site, user, owner) triple.
|
|
63
|
+
*
|
|
64
|
+
* One read rather than three, because this happens on every claim and a
|
|
65
|
+
* control plane that made three round trips per job would be the reason
|
|
66
|
+
* somebody ran their own.
|
|
67
|
+
*/
|
|
68
|
+
interface PolicySnapshot {
|
|
69
|
+
/**
|
|
70
|
+
* May this user's work move for this site **right now**?
|
|
71
|
+
*
|
|
72
|
+
* Three states collapse into this one boolean, and the collapse is
|
|
73
|
+
* deliberate: never authorised, authorised then revoked, and authorised but
|
|
74
|
+
* *paused* are different things to a person and the same thing to a grant.
|
|
75
|
+
* A store must report a paused consent as `false` — a relay's projection
|
|
76
|
+
* can be a few seconds behind, and a grant authored in that window would
|
|
77
|
+
* run work its owner had just stopped.
|
|
78
|
+
*
|
|
79
|
+
* Distinct from having mappings, which is a different real state: a person
|
|
80
|
+
* can consent and leave a slot unmapped, because it had two candidates and
|
|
81
|
+
* they have not chosen. "Not authorised" and "authorised, this slot empty"
|
|
82
|
+
* send them to different places, so the engine is told which.
|
|
83
|
+
*/
|
|
84
|
+
readonly consented: boolean;
|
|
85
|
+
/**
|
|
86
|
+
* May this user's work run on this owner's devices?
|
|
87
|
+
*
|
|
88
|
+
* The store answers for other people. It is **not** consulted for the
|
|
89
|
+
* owner's own work — see {@link PolicyStore.read}.
|
|
90
|
+
*/
|
|
91
|
+
readonly member: boolean;
|
|
92
|
+
/** This user's mappings for this site. Order is not meaningful. */
|
|
93
|
+
readonly mappings: readonly Mapping[];
|
|
94
|
+
}
|
|
95
|
+
interface PolicyStore {
|
|
96
|
+
/**
|
|
97
|
+
* Read the policy for one job's worth of question.
|
|
98
|
+
*
|
|
99
|
+
* **`owner === user` is not asked about here.** A device always runs its
|
|
100
|
+
* own owner's work, and routing that through a store would put a law in a
|
|
101
|
+
* place any implementation could get wrong — including by returning
|
|
102
|
+
* `member: false` for somebody's own account and quietly stopping their
|
|
103
|
+
* device. The engine short-circuits it; this method is only ever asked
|
|
104
|
+
* about other people.
|
|
105
|
+
*
|
|
106
|
+
* Returning a snapshot with `consented: false` is the ordinary answer for a
|
|
107
|
+
* site this user has never authorised. Throwing is for a store that could
|
|
108
|
+
* not answer, which is a different thing and must not be turned into a
|
|
109
|
+
* refusal — see the engine's failure handling.
|
|
110
|
+
*/
|
|
111
|
+
read(input: {
|
|
112
|
+
/** The site's id in the control plane's namespace, not its key id. */
|
|
113
|
+
readonly siteId: string;
|
|
114
|
+
/** Whose job it is. */
|
|
115
|
+
readonly user: string;
|
|
116
|
+
/** Whose device is asking. */
|
|
117
|
+
readonly owner: string;
|
|
118
|
+
}): Promise<PolicySnapshot>;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export type { Mapping as M, PolicyStore as P, PolicySnapshot as a };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { P as PolicyStore, M as Mapping } from './store-CzDvurIM.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The policy store's behaviour, written once and run against every
|
|
5
|
+
* implementation.
|
|
6
|
+
*
|
|
7
|
+
* The same reasoning as `@byollm/relay/store-contract`, and more of it. The
|
|
8
|
+
* implementation that matters most is byollm.cloud's, in another repository
|
|
9
|
+
* and not open — so this is the only way a reader can know that the hosted
|
|
10
|
+
* product's store answers the same questions the same way the reference one
|
|
11
|
+
* does. A contract only its author can run is a description.
|
|
12
|
+
*
|
|
13
|
+
* ## What a store has to do to be tested
|
|
14
|
+
*
|
|
15
|
+
* `PolicyStore` has one method, and it reads. Everything that *writes* —
|
|
16
|
+
* consenting, mapping, adding somebody to a team — is the deployment's own
|
|
17
|
+
* surface, and no two will agree on it. So the contract takes a small harness
|
|
18
|
+
* that performs those acts however the implementation performs them, and
|
|
19
|
+
* asserts only what `read` must then answer.
|
|
20
|
+
*
|
|
21
|
+
* That is the honest boundary: this proves the store's *answers*, not its
|
|
22
|
+
* admin API. A store that passes has the semantics the engine relies on.
|
|
23
|
+
*/
|
|
24
|
+
interface PolicyStoreContractOptions {
|
|
25
|
+
/**
|
|
26
|
+
* A fresh, empty store, its write surface, and how to dispose of it.
|
|
27
|
+
*
|
|
28
|
+
* Arrow-typed rather than methods, for the reason the routing store's
|
|
29
|
+
* contract gives: a method signature lets `this` travel with a call read
|
|
30
|
+
* off an options object, which is exactly where that goes wrong.
|
|
31
|
+
*/
|
|
32
|
+
readonly make: () => Promise<{
|
|
33
|
+
store: PolicyStore;
|
|
34
|
+
consent: (input: {
|
|
35
|
+
siteId: string;
|
|
36
|
+
user: string;
|
|
37
|
+
mappings?: readonly Mapping[];
|
|
38
|
+
}) => Promise<void> | void;
|
|
39
|
+
revoke: (input: {
|
|
40
|
+
siteId: string;
|
|
41
|
+
user: string;
|
|
42
|
+
}) => Promise<void> | void;
|
|
43
|
+
/**
|
|
44
|
+
* Pause a consent without withdrawing it.
|
|
45
|
+
*
|
|
46
|
+
* Optional because not every deployment offers pausing. A store that does
|
|
47
|
+
* not is not asked to prove it — but one that does must prove a paused
|
|
48
|
+
* consent reads as not-consented, which is the case below.
|
|
49
|
+
*/
|
|
50
|
+
pause?: (input: {
|
|
51
|
+
siteId: string;
|
|
52
|
+
user: string;
|
|
53
|
+
}) => Promise<void> | void;
|
|
54
|
+
addMember: (input: {
|
|
55
|
+
owner: string;
|
|
56
|
+
user: string;
|
|
57
|
+
}) => Promise<void> | void;
|
|
58
|
+
removeMember: (input: {
|
|
59
|
+
owner: string;
|
|
60
|
+
user: string;
|
|
61
|
+
}) => Promise<void> | void;
|
|
62
|
+
done: () => Promise<void>;
|
|
63
|
+
}>;
|
|
64
|
+
}
|
|
65
|
+
/** Run the contract. Call inside a suite; it declares its own `describe`. */
|
|
66
|
+
declare function describePolicyStoreContract(name: string, options: PolicyStoreContractOptions): void;
|
|
67
|
+
|
|
68
|
+
export { type PolicyStoreContractOptions, describePolicyStoreContract };
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
// src/store-contract.ts
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
var SITE = "site_demo";
|
|
4
|
+
var OWNER = "bob";
|
|
5
|
+
var USER = "alice";
|
|
6
|
+
var MAPPING = {
|
|
7
|
+
purpose: "writing_assistant",
|
|
8
|
+
kind: "llm.generate",
|
|
9
|
+
service: "qwen",
|
|
10
|
+
owner: null
|
|
11
|
+
};
|
|
12
|
+
function describePolicyStoreContract(name, options) {
|
|
13
|
+
describe(`the policy store \u2014 ${name}`, () => {
|
|
14
|
+
it("says a site nobody authorised is not consented", async () => {
|
|
15
|
+
const { store, done } = await options.make();
|
|
16
|
+
const snapshot = await store.read({
|
|
17
|
+
siteId: SITE,
|
|
18
|
+
user: USER,
|
|
19
|
+
owner: OWNER
|
|
20
|
+
});
|
|
21
|
+
expect(snapshot.consented).toBe(false);
|
|
22
|
+
expect(snapshot.mappings).toEqual([]);
|
|
23
|
+
await done();
|
|
24
|
+
});
|
|
25
|
+
it("returns the mapping the consent carried", async () => {
|
|
26
|
+
const s = await options.make();
|
|
27
|
+
await s.consent({ siteId: SITE, user: USER, mappings: [MAPPING] });
|
|
28
|
+
const snapshot = await s.store.read({
|
|
29
|
+
siteId: SITE,
|
|
30
|
+
user: USER,
|
|
31
|
+
owner: OWNER
|
|
32
|
+
});
|
|
33
|
+
expect(snapshot.consented).toBe(true);
|
|
34
|
+
expect([...snapshot.mappings]).toEqual([MAPPING]);
|
|
35
|
+
await s.done();
|
|
36
|
+
});
|
|
37
|
+
it("distinguishes consented-and-unmapped from never-consented", async () => {
|
|
38
|
+
const s = await options.make();
|
|
39
|
+
await s.consent({ siteId: SITE, user: USER, mappings: [] });
|
|
40
|
+
const snapshot = await s.store.read({
|
|
41
|
+
siteId: SITE,
|
|
42
|
+
user: USER,
|
|
43
|
+
owner: OWNER
|
|
44
|
+
});
|
|
45
|
+
expect(snapshot.consented).toBe(true);
|
|
46
|
+
expect(snapshot.mappings).toEqual([]);
|
|
47
|
+
await s.done();
|
|
48
|
+
});
|
|
49
|
+
it("deletes the mapping when consent is withdrawn", async () => {
|
|
50
|
+
const s = await options.make();
|
|
51
|
+
await s.consent({ siteId: SITE, user: USER, mappings: [MAPPING] });
|
|
52
|
+
await s.revoke({ siteId: SITE, user: USER });
|
|
53
|
+
const snapshot = await s.store.read({
|
|
54
|
+
siteId: SITE,
|
|
55
|
+
user: USER,
|
|
56
|
+
owner: OWNER
|
|
57
|
+
});
|
|
58
|
+
expect(snapshot.consented).toBe(false);
|
|
59
|
+
expect(snapshot.mappings).toEqual([]);
|
|
60
|
+
await s.done();
|
|
61
|
+
});
|
|
62
|
+
it("reads a paused consent as not consented", async () => {
|
|
63
|
+
const s = await options.make();
|
|
64
|
+
if (!s.pause) {
|
|
65
|
+
await s.done();
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
await s.consent({ siteId: SITE, user: USER, mappings: [MAPPING] });
|
|
69
|
+
await s.pause({ siteId: SITE, user: USER });
|
|
70
|
+
const snapshot = await s.store.read({
|
|
71
|
+
siteId: SITE,
|
|
72
|
+
user: USER,
|
|
73
|
+
owner: OWNER
|
|
74
|
+
});
|
|
75
|
+
expect(snapshot.consented).toBe(false);
|
|
76
|
+
await s.done();
|
|
77
|
+
});
|
|
78
|
+
it("keeps one person's consent out of another's", async () => {
|
|
79
|
+
const s = await options.make();
|
|
80
|
+
await s.consent({ siteId: SITE, user: USER, mappings: [MAPPING] });
|
|
81
|
+
const other = await s.store.read({
|
|
82
|
+
siteId: SITE,
|
|
83
|
+
user: "carol",
|
|
84
|
+
owner: OWNER
|
|
85
|
+
});
|
|
86
|
+
expect(other.consented).toBe(false);
|
|
87
|
+
await s.done();
|
|
88
|
+
});
|
|
89
|
+
it("keeps one site's consent out of another's", async () => {
|
|
90
|
+
const s = await options.make();
|
|
91
|
+
await s.consent({ siteId: SITE, user: USER, mappings: [MAPPING] });
|
|
92
|
+
const other = await s.store.read({
|
|
93
|
+
siteId: "site_other",
|
|
94
|
+
user: USER,
|
|
95
|
+
owner: OWNER
|
|
96
|
+
});
|
|
97
|
+
expect(other.consented).toBe(false);
|
|
98
|
+
await s.done();
|
|
99
|
+
});
|
|
100
|
+
it("reports membership per owner, not per person", async () => {
|
|
101
|
+
const s = await options.make();
|
|
102
|
+
await s.addMember({ owner: OWNER, user: USER });
|
|
103
|
+
const mine = await s.store.read({
|
|
104
|
+
siteId: SITE,
|
|
105
|
+
user: USER,
|
|
106
|
+
owner: OWNER
|
|
107
|
+
});
|
|
108
|
+
const theirs = await s.store.read({
|
|
109
|
+
siteId: SITE,
|
|
110
|
+
user: USER,
|
|
111
|
+
owner: "carol"
|
|
112
|
+
});
|
|
113
|
+
expect(mine.member).toBe(true);
|
|
114
|
+
expect(theirs.member).toBe(false);
|
|
115
|
+
await s.done();
|
|
116
|
+
});
|
|
117
|
+
it("stops reporting membership once somebody is removed", async () => {
|
|
118
|
+
const s = await options.make();
|
|
119
|
+
await s.addMember({ owner: OWNER, user: USER });
|
|
120
|
+
await s.removeMember({ owner: OWNER, user: USER });
|
|
121
|
+
const snapshot = await s.store.read({
|
|
122
|
+
siteId: SITE,
|
|
123
|
+
user: USER,
|
|
124
|
+
owner: OWNER
|
|
125
|
+
});
|
|
126
|
+
expect(snapshot.member).toBe(false);
|
|
127
|
+
await s.done();
|
|
128
|
+
});
|
|
129
|
+
it("keeps membership and consent independent", async () => {
|
|
130
|
+
const s = await options.make();
|
|
131
|
+
await s.addMember({ owner: OWNER, user: USER });
|
|
132
|
+
const noConsent = await s.store.read({
|
|
133
|
+
siteId: SITE,
|
|
134
|
+
user: USER,
|
|
135
|
+
owner: OWNER
|
|
136
|
+
});
|
|
137
|
+
expect(noConsent.member).toBe(true);
|
|
138
|
+
expect(noConsent.consented).toBe(false);
|
|
139
|
+
await s.consent({ siteId: SITE, user: "carol", mappings: [MAPPING] });
|
|
140
|
+
const noMembership = await s.store.read({
|
|
141
|
+
siteId: SITE,
|
|
142
|
+
user: "carol",
|
|
143
|
+
owner: OWNER
|
|
144
|
+
});
|
|
145
|
+
expect(noMembership.consented).toBe(true);
|
|
146
|
+
expect(noMembership.member).toBe(false);
|
|
147
|
+
await s.done();
|
|
148
|
+
});
|
|
149
|
+
it("does not let a site id and a user id be confused for each other", async () => {
|
|
150
|
+
const s = await options.make();
|
|
151
|
+
await s.consent({ siteId: "a", user: "b:c", mappings: [MAPPING] });
|
|
152
|
+
const confusable = await s.store.read({
|
|
153
|
+
siteId: "a:b",
|
|
154
|
+
user: "c",
|
|
155
|
+
owner: OWNER
|
|
156
|
+
});
|
|
157
|
+
expect(confusable.consented).toBe(false);
|
|
158
|
+
await s.done();
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
export {
|
|
163
|
+
describePolicyStoreContract
|
|
164
|
+
};
|
|
165
|
+
//# sourceMappingURL=store-contract.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/store-contract.ts"],"sourcesContent":["import { describe, expect, it } from \"vitest\";\nimport type { Mapping, PolicyStore } from \"./store.js\";\n\n/**\n * The policy store's behaviour, written once and run against every\n * implementation.\n *\n * The same reasoning as `@byollm/relay/store-contract`, and more of it. The\n * implementation that matters most is byollm.cloud's, in another repository\n * and not open — so this is the only way a reader can know that the hosted\n * product's store answers the same questions the same way the reference one\n * does. A contract only its author can run is a description.\n *\n * ## What a store has to do to be tested\n *\n * `PolicyStore` has one method, and it reads. Everything that *writes* —\n * consenting, mapping, adding somebody to a team — is the deployment's own\n * surface, and no two will agree on it. So the contract takes a small harness\n * that performs those acts however the implementation performs them, and\n * asserts only what `read` must then answer.\n *\n * That is the honest boundary: this proves the store's *answers*, not its\n * admin API. A store that passes has the semantics the engine relies on.\n */\nexport interface PolicyStoreContractOptions {\n /**\n * A fresh, empty store, its write surface, and how to dispose of it.\n *\n * Arrow-typed rather than methods, for the reason the routing store's\n * contract gives: a method signature lets `this` travel with a call read\n * off an options object, which is exactly where that goes wrong.\n */\n readonly make: () => Promise<{\n store: PolicyStore;\n consent: (input: {\n siteId: string;\n user: string;\n mappings?: readonly Mapping[];\n }) => Promise<void> | void;\n revoke: (input: { siteId: string; user: string }) => Promise<void> | void;\n /**\n * Pause a consent without withdrawing it.\n *\n * Optional because not every deployment offers pausing. A store that does\n * not is not asked to prove it — but one that does must prove a paused\n * consent reads as not-consented, which is the case below.\n */\n pause?: (input: { siteId: string; user: string }) => Promise<void> | void;\n addMember: (input: { owner: string; user: string }) => Promise<void> | void;\n removeMember: (input: {\n owner: string;\n user: string;\n }) => Promise<void> | void;\n done: () => Promise<void>;\n }>;\n}\n\nconst SITE = \"site_demo\";\nconst OWNER = \"bob\";\nconst USER = \"alice\";\nconst MAPPING: Mapping = {\n purpose: \"writing_assistant\",\n kind: \"llm.generate\",\n service: \"qwen\",\n owner: null,\n};\n\n/** Run the contract. Call inside a suite; it declares its own `describe`. */\nexport function describePolicyStoreContract(\n name: string,\n options: PolicyStoreContractOptions,\n): void {\n describe(`the policy store — ${name}`, () => {\n it(\"says a site nobody authorised is not consented\", async () => {\n // The ordinary answer, not an error. A person who has never heard of a\n // site is the common case, and a store that threw here would make the\n // engine treat \"no\" as \"broken\".\n const { store, done } = await options.make();\n const snapshot = await store.read({\n siteId: SITE,\n user: USER,\n owner: OWNER,\n });\n expect(snapshot.consented).toBe(false);\n expect(snapshot.mappings).toEqual([]);\n await done();\n });\n\n it(\"returns the mapping the consent carried\", async () => {\n const s = await options.make();\n await s.consent({ siteId: SITE, user: USER, mappings: [MAPPING] });\n const snapshot = await s.store.read({\n siteId: SITE,\n user: USER,\n owner: OWNER,\n });\n expect(snapshot.consented).toBe(true);\n expect([...snapshot.mappings]).toEqual([MAPPING]);\n await s.done();\n });\n\n it(\"distinguishes consented-and-unmapped from never-consented\", async () => {\n // A real signup state: every slot had two candidates, so nothing\n // auto-mapped and the person has not chosen. It is not the same as\n // never having authorised the site, and it sends them somewhere else.\n const s = await options.make();\n await s.consent({ siteId: SITE, user: USER, mappings: [] });\n const snapshot = await s.store.read({\n siteId: SITE,\n user: USER,\n owner: OWNER,\n });\n expect(snapshot.consented).toBe(true);\n expect(snapshot.mappings).toEqual([]);\n await s.done();\n });\n\n it(\"deletes the mapping when consent is withdrawn\", async () => {\n // Hole 2: the mapping *is* the consent, so un-consenting unmaps. A\n // store that kept the mapping would hold a resolution pointing at a\n // service its author no longer authorises anybody to reach.\n const s = await options.make();\n await s.consent({ siteId: SITE, user: USER, mappings: [MAPPING] });\n await s.revoke({ siteId: SITE, user: USER });\n const snapshot = await s.store.read({\n siteId: SITE,\n user: USER,\n owner: OWNER,\n });\n expect(snapshot.consented).toBe(false);\n expect(snapshot.mappings).toEqual([]);\n await s.done();\n });\n\n it(\"reads a paused consent as not consented\", async () => {\n // Three states, one boolean, on purpose: never authorised, revoked and\n // paused are different to a person and identical to a grant. A relay's\n // projection can lag by seconds, so a store that reported a paused\n // consent as live would let a grant be authored for work its owner had\n // just stopped.\n const s = await options.make();\n if (!s.pause) {\n await s.done();\n return;\n }\n await s.consent({ siteId: SITE, user: USER, mappings: [MAPPING] });\n await s.pause({ siteId: SITE, user: USER });\n const snapshot = await s.store.read({\n siteId: SITE,\n user: USER,\n owner: OWNER,\n });\n expect(snapshot.consented).toBe(false);\n await s.done();\n });\n\n it(\"keeps one person's consent out of another's\", async () => {\n const s = await options.make();\n await s.consent({ siteId: SITE, user: USER, mappings: [MAPPING] });\n const other = await s.store.read({\n siteId: SITE,\n user: \"carol\",\n owner: OWNER,\n });\n expect(other.consented).toBe(false);\n await s.done();\n });\n\n it(\"keeps one site's consent out of another's\", async () => {\n const s = await options.make();\n await s.consent({ siteId: SITE, user: USER, mappings: [MAPPING] });\n const other = await s.store.read({\n siteId: \"site_other\",\n user: USER,\n owner: OWNER,\n });\n expect(other.consented).toBe(false);\n await s.done();\n });\n\n it(\"reports membership per owner, not per person\", async () => {\n // A team is one owner's, and being on one confers nothing about\n // anybody else's devices. A store that kept a global \"alice is a team\n // member\" flag would share every owner's hardware with her.\n const s = await options.make();\n await s.addMember({ owner: OWNER, user: USER });\n const mine = await s.store.read({\n siteId: SITE,\n user: USER,\n owner: OWNER,\n });\n const theirs = await s.store.read({\n siteId: SITE,\n user: USER,\n owner: \"carol\",\n });\n expect(mine.member).toBe(true);\n expect(theirs.member).toBe(false);\n await s.done();\n });\n\n it(\"stops reporting membership once somebody is removed\", async () => {\n // Removal is the whole of it — there is no blocked-but-still-a-member,\n // because a team *is* access to its owner's devices (Amendment J).\n const s = await options.make();\n await s.addMember({ owner: OWNER, user: USER });\n await s.removeMember({ owner: OWNER, user: USER });\n const snapshot = await s.store.read({\n siteId: SITE,\n user: USER,\n owner: OWNER,\n });\n expect(snapshot.member).toBe(false);\n await s.done();\n });\n\n it(\"keeps membership and consent independent\", async () => {\n // Two different questions, and both have to be yes. A store that\n // conflated them would let a team member's work run on a site they\n // never authorised, or refuse a person their own site because nobody\n // had added them to a team.\n const s = await options.make();\n await s.addMember({ owner: OWNER, user: USER });\n const noConsent = await s.store.read({\n siteId: SITE,\n user: USER,\n owner: OWNER,\n });\n expect(noConsent.member).toBe(true);\n expect(noConsent.consented).toBe(false);\n\n await s.consent({ siteId: SITE, user: \"carol\", mappings: [MAPPING] });\n const noMembership = await s.store.read({\n siteId: SITE,\n user: \"carol\",\n owner: OWNER,\n });\n expect(noMembership.consented).toBe(true);\n expect(noMembership.member).toBe(false);\n await s.done();\n });\n\n it(\"does not let a site id and a user id be confused for each other\", async () => {\n // Composite keys are parsers waiting to meet an id containing their\n // separator. These two consents differ only in where the boundary\n // falls, and a store that joined them naively would answer one for the\n // other.\n const s = await options.make();\n await s.consent({ siteId: \"a\", user: \"b:c\", mappings: [MAPPING] });\n const confusable = await s.store.read({\n siteId: \"a:b\",\n user: \"c\",\n owner: OWNER,\n });\n expect(confusable.consented).toBe(false);\n await s.done();\n });\n });\n}\n"],"mappings":";AAAA,SAAS,UAAU,QAAQ,UAAU;AAyDrC,IAAM,OAAO;AACb,IAAM,QAAQ;AACd,IAAM,OAAO;AACb,IAAM,UAAmB;AAAA,EACvB,SAAS;AAAA,EACT,MAAM;AAAA,EACN,SAAS;AAAA,EACT,OAAO;AACT;AAGO,SAAS,4BACd,MACA,SACM;AACN,WAAS,2BAAsB,IAAI,IAAI,MAAM;AAC3C,OAAG,kDAAkD,YAAY;AAI/D,YAAM,EAAE,OAAO,KAAK,IAAI,MAAM,QAAQ,KAAK;AAC3C,YAAM,WAAW,MAAM,MAAM,KAAK;AAAA,QAChC,QAAQ;AAAA,QACR,MAAM;AAAA,QACN,OAAO;AAAA,MACT,CAAC;AACD,aAAO,SAAS,SAAS,EAAE,KAAK,KAAK;AACrC,aAAO,SAAS,QAAQ,EAAE,QAAQ,CAAC,CAAC;AACpC,YAAM,KAAK;AAAA,IACb,CAAC;AAED,OAAG,2CAA2C,YAAY;AACxD,YAAM,IAAI,MAAM,QAAQ,KAAK;AAC7B,YAAM,EAAE,QAAQ,E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A,QACN,OAAO;AAAA,MACT,CAAC;AACD,aAAO,aAAa,SAAS,EAAE,KAAK,IAAI;AACxC,aAAO,aAAa,MAAM,EAAE,KAAK,KAAK;AACtC,YAAM,EAAE,KAAK;AAAA,IACf,CAAC;AAED,OAAG,mEAAmE,YAAY;AAKhF,YAAM,IAAI,MAAM,QAAQ,KAAK;AAC7B,YAAM,EAAE,QAAQ,EAAE,QAAQ,KAAK,MAAM,OAAO,UAAU,CAAC,OAAO,EAAE,CAAC;AACjE,YAAM,aAAa,MAAM,EAAE,MAAM,KAAK;AAAA,QACpC,QAAQ;AAAA,QACR,MAAM;AAAA,QACN,OAAO;AAAA,MACT,CAAC;AACD,aAAO,WAAW,SAAS,EAAE,KAAK,KAAK;AACvC,YAAM,EAAE,KAAK;AAAA,IACf,CAAC;AAAA,EACH,CAAC;AACH;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@byollm/control-plane",
|
|
3
|
+
"version": "0.1.0-alpha.58",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "The reference control plane: resolves a user's mapping and authors one signed grant per job, against a policy store it does not own.",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/oftomorrowinc/byollm.git",
|
|
10
|
+
"directory": "packages/control-plane"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/oftomorrowinc/byollm/tree/main/packages/control-plane",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/oftomorrowinc/byollm/issues"
|
|
15
|
+
},
|
|
16
|
+
"main": "./dist/index.js",
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"import": "./dist/index.js"
|
|
22
|
+
},
|
|
23
|
+
"./store-contract": {
|
|
24
|
+
"types": "./dist/store-contract.d.ts",
|
|
25
|
+
"import": "./dist/store-contract.js"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"dist",
|
|
30
|
+
"README.md"
|
|
31
|
+
],
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@byollm/protocol": "0.1.0-alpha.58"
|
|
34
|
+
},
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"vitest": "^4.1.10"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"vitest": ">=3"
|
|
43
|
+
},
|
|
44
|
+
"peerDependenciesMeta": {
|
|
45
|
+
"vitest": {
|
|
46
|
+
"optional": true
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "tsup"
|
|
51
|
+
}
|
|
52
|
+
}
|