@cotal-ai/registry 0.0.0-bootstrap.0 → 0.135.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 ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,43 @@
1
+ /**
2
+ * The registry's `endpoints` answer (SPEC 13.20), over an injected read seam so the logic is the
3
+ * same whichever process hosts it. On an authed mesh the caller's generation comes from the
4
+ * broker-authenticated subject, its recorded ceiling from a disclosure read of the issued evidence,
5
+ * and each registered endpoint's commands from its digest-verified root cluster document. Endpoints
6
+ * the ceiling covers no command of are left out before anything is returned. A failed read reaches
7
+ * the caller as a fixed message; its detail goes to the registry's log.
8
+ */
9
+ import { type EpServeContext, type IssuedAuthorityRef, type IssuedEvidence, type RegistryEndpointsInput, type RegistryEndpointsOutput } from "@cotal-ai/core";
10
+ /** What the answer reads. Every method reads live state; nothing is cached across requests here
11
+ * except what the seam itself caches by an immutable key (a contract artifact by its digest). */
12
+ export interface RegistryReads {
13
+ /** The recorded ceiling of a live generation (`IssuedStore.observe`); throws when it is not one. */
14
+ observe(ref: IssuedAuthorityRef): Promise<IssuedEvidence>;
15
+ /** Every registered `(endpoint, instanceId)`, from the records store's key list. */
16
+ instances(): Promise<{
17
+ endpoint: string;
18
+ instanceId: string;
19
+ }[]>;
20
+ /** The instance's registered cluster closure digests, or `undefined` when its record is gone. */
21
+ clusterDigests(endpoint: string, instanceId: string): Promise<string[] | undefined>;
22
+ /** The instance's recorded serving state, or `null` when it has none. */
23
+ state(endpoint: string, instanceId: string): Promise<string | null>;
24
+ /** A contract artifact's JSON value by digest, or `undefined` when the store has none. Throws
25
+ * {@link ContractInvalidError} when the store holds bytes for the digest that do not verify. */
26
+ artifact(digest: string): Promise<unknown>;
27
+ }
28
+ export interface RegistryAnswerOptions {
29
+ space: string;
30
+ /** `open`: no permission system, every registered endpoint is callable. */
31
+ mode: "authed" | "open";
32
+ reads: RegistryReads;
33
+ /** Where a failed read's detail goes. The caller is told only that the read failed. */
34
+ log: (line: string) => void;
35
+ }
36
+ /** The most bytes one page is built to. The serve layer also caps it at the connection's ceiling. */
37
+ export declare const REGISTRY_PAGE_BYTES: number;
38
+ /**
39
+ * Answer one `endpoints` request. A legacy-rail request on an authed mesh carries no generation
40
+ * and is refused, as a command requiring issued caller authority refuses it (SPEC 13.15).
41
+ */
42
+ export declare function answerEndpoints(opts: RegistryAnswerOptions, ctx: Pick<EpServeContext, "subject" | "replyFits">, input: RegistryEndpointsInput): Promise<RegistryEndpointsOutput>;
43
+ //# sourceMappingURL=answer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"answer.d.ts","sourceRoot":"","sources":["../src/answer.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAYL,KAAK,cAAc,EACnB,KAAK,kBAAkB,EACvB,KAAK,cAAc,EAGnB,KAAK,sBAAsB,EAC3B,KAAK,uBAAuB,EAE7B,MAAM,gBAAgB,CAAC;AAExB;kGACkG;AAClG,MAAM,WAAW,aAAa;IAC5B,oGAAoG;IACpG,OAAO,CAAC,GAAG,EAAE,kBAAkB,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;IAC1D,oFAAoF;IACpF,SAAS,IAAI,OAAO,CAAC;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC,CAAC;IACjE,iGAAiG;IACjG,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,GAAG,SAAS,CAAC,CAAC;IACpF,yEAAyE;IACzE,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IACpE;qGACiG;IACjG,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAC5C;AAED,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,MAAM,CAAC;IACd,2EAA2E;IAC3E,IAAI,EAAE,QAAQ,GAAG,MAAM,CAAC;IACxB,KAAK,EAAE,aAAa,CAAC;IACrB,uFAAuF;IACvF,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CAC7B;AAED,qGAAqG;AACrG,eAAO,MAAM,mBAAmB,QAAa,CAAC;AA+E9C;;;GAGG;AACH,wBAAsB,eAAe,CAAC,IAAI,EAAE,qBAAqB,EAAE,GAAG,EAAE,IAAI,CAAC,cAAc,EAAE,SAAS,GAAG,WAAW,CAAC,EAAE,KAAK,EAAE,sBAAsB,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAwCtL"}
package/dist/answer.js ADDED
@@ -0,0 +1,140 @@
1
+ /**
2
+ * The registry's `endpoints` answer (SPEC 13.20), over an injected read seam so the logic is the
3
+ * same whichever process hosts it. On an authed mesh the caller's generation comes from the
4
+ * broker-authenticated subject, its recorded ceiling from a disclosure read of the issued evidence,
5
+ * and each registered endpoint's commands from its digest-verified root cluster document. Endpoints
6
+ * the ceiling covers no command of are left out before anything is returned. A failed read reaches
7
+ * the caller as a fixed message; its detail goes to the registry's log.
8
+ */
9
+ import { canonicalJson, ContractInvalidError, CoverageLimitError, EpEnvelopeError, EP_UNBOUND_CALLER_AUTHORITY, isIssuedCaller, projectCommandCoverage, REGISTRY_PAGE_LIMIT, verifyClusterManifest, verifyClusterRoot, } from "@cotal-ai/core";
10
+ /** The most bytes one page is built to. The serve layer also caps it at the connection's ceiling. */
11
+ export const REGISTRY_PAGE_BYTES = 512 * 1024;
12
+ /** `undefined` when the instance's record is gone (deregistered between the key list and the read). */
13
+ async function declarations(reads, endpoint, instanceId) {
14
+ const digests = await reads.clusterDigests(endpoint, instanceId);
15
+ if (digests === undefined)
16
+ return undefined;
17
+ const commands = [];
18
+ try {
19
+ for (const digest of digests) {
20
+ const manifest = await reads.artifact(digest.replace(/^sha256:/, ""));
21
+ if (manifest === undefined)
22
+ return { commands: [], artifacts: "missing" };
23
+ const root = verifyClusterManifest(digest, manifest).root;
24
+ const document = await reads.artifact(root.replace(/^sha256:/, ""));
25
+ if (document === undefined)
26
+ return { commands: [], artifacts: "missing" };
27
+ commands.push(...verifyClusterRoot(root, document).commands);
28
+ }
29
+ }
30
+ catch (e) {
31
+ if (e instanceof ContractInvalidError)
32
+ return { commands: [], artifacts: "invalid" };
33
+ throw e;
34
+ }
35
+ // A name declared in two of its clusters is an ambiguous surface, which never authorizes (SPEC 13.7).
36
+ if (new Set(commands.map((c) => c.name)).size !== commands.length)
37
+ return { commands: [], artifacts: "invalid" };
38
+ return { commands, artifacts: "verified" };
39
+ }
40
+ async function endpointRow(opts, endpoint, instanceIds, ceiling, caller) {
41
+ const instances = [];
42
+ // Keyed by name and by what coverage reads: instances may declare one name differently.
43
+ const declared = new Map();
44
+ for (const instanceId of instanceIds) {
45
+ const found = await declarations(opts.reads, endpoint, instanceId);
46
+ if (found === undefined)
47
+ continue;
48
+ instances.push({ instanceId, state: await opts.reads.state(endpoint, instanceId), artifacts: found.artifacts });
49
+ for (const command of found.commands) {
50
+ const key = canonicalJson([command.name, command.class, command.targeted, [...(command.modes ?? [])].sort()]);
51
+ const seen = declared.get(key);
52
+ if (seen)
53
+ seen.instances.push(instanceId);
54
+ else
55
+ declared.set(key, { command, instances: [instanceId] });
56
+ }
57
+ }
58
+ const commands = [];
59
+ const unprojected = new Set();
60
+ const ordered = [...declared.values()].sort((a, b) => a.command.name.localeCompare(b.command.name) || a.instances[0].localeCompare(b.instances[0]));
61
+ for (const { command, instances: by } of ordered) {
62
+ const name = command.name;
63
+ const partial = by.length < instances.length ? { instances: by } : {};
64
+ if (ceiling === undefined) {
65
+ commands.push({ name, class: command.class, forms: [], ...partial });
66
+ continue;
67
+ }
68
+ try {
69
+ const forms = projectCommandCoverage(opts.space, ceiling.evidence.permissions.publish, {
70
+ endpoint, command, caller, generation: ceiling.generation, instances: by,
71
+ });
72
+ if (forms.length > 0)
73
+ commands.push({ name, class: command.class, forms: forms.map((f) => ({ ...f, literals: { ...f.literals }, covered: f.covered.map((c) => ({ ...c })) })), ...partial });
74
+ }
75
+ catch (e) {
76
+ if (!(e instanceof CoverageLimitError))
77
+ throw e;
78
+ if (e.covered)
79
+ unprojected.add(name);
80
+ }
81
+ }
82
+ if (instances.length === 0)
83
+ return undefined;
84
+ // An unprojected command's forms are not listed, whichever of its declarations went past the limit.
85
+ const listed = commands.filter((c) => !unprojected.has(c.name));
86
+ if (ceiling !== undefined && listed.length === 0 && unprojected.size === 0)
87
+ return undefined;
88
+ return { endpoint, instances, commands: listed, ...(unprojected.size ? { unprojected: [...unprojected].sort() } : {}) };
89
+ }
90
+ const detail = (e) => (e instanceof Error ? e.message : String(e));
91
+ /**
92
+ * Answer one `endpoints` request. A legacy-rail request on an authed mesh carries no generation
93
+ * and is refused, as a command requiring issued caller authority refuses it (SPEC 13.15).
94
+ */
95
+ export async function answerEndpoints(opts, ctx, input) {
96
+ const caller = ctx.subject.caller;
97
+ const triple = { owner: caller.owner, actor: caller.actor, uid: caller.uid };
98
+ let ceiling;
99
+ if (opts.mode === "authed") {
100
+ if (!isIssuedCaller(caller))
101
+ throw new EpEnvelopeError("permission-denied", "the endpoints listing rides the versioned rail under a listing or issued generation; this credential has no listing binding (SPEC 13.15)", [{ kind: EP_UNBOUND_CALLER_AUTHORITY, owner: caller.owner, actor: caller.actor, uid: caller.uid }]);
102
+ try {
103
+ ceiling = { evidence: await opts.reads.observe({ space: opts.space, ...triple, generation: caller.generation }), generation: caller.generation };
104
+ }
105
+ catch (e) {
106
+ opts.log(`registry: the ceiling read failed: ${detail(e)}`);
107
+ if (e instanceof EpEnvelopeError && e.code === "permission-denied")
108
+ throw new EpEnvelopeError("permission-denied", "this connection's listing generation is not live; a new credential gets a fresh one");
109
+ throw new EpEnvelopeError("unavailable", "the registry could not read this connection's recorded ceiling");
110
+ }
111
+ }
112
+ const recordsFailed = (e) => {
113
+ opts.log(`registry: a records read failed: ${detail(e)}`);
114
+ throw new EpEnvelopeError("unavailable", "the registry could not read the space's endpoint records; nothing is listed");
115
+ };
116
+ const limit = input.limit ?? REGISTRY_PAGE_LIMIT;
117
+ const byEndpoint = new Map();
118
+ for (const { endpoint, instanceId } of await opts.reads.instances().catch(recordsFailed))
119
+ byEndpoint.set(endpoint, [...(byEndpoint.get(endpoint) ?? []), instanceId]);
120
+ const names = [...byEndpoint.keys()].filter((name) => input.after === undefined || name > input.after).sort();
121
+ const source = opts.mode === "authed" ? "recorded-ceiling" : "no-permission-system";
122
+ const rows = [];
123
+ for (let i = 0; i < names.length; i++) {
124
+ const name = names[i];
125
+ if (rows.length === limit)
126
+ return { rows, next: rows[rows.length - 1].endpoint, source };
127
+ const row = await endpointRow(opts, name, byEndpoint.get(name).sort(), ceiling, triple).catch(recordsFailed);
128
+ if (row === undefined)
129
+ continue;
130
+ const page = { rows: [...rows, row], next: name, source };
131
+ if (ctx.replyFits !== undefined && !ctx.replyFits(page, REGISTRY_PAGE_BYTES)) {
132
+ if (rows.length === 0)
133
+ throw new EpEnvelopeError("resource-exhausted", `the row for ${name} does not fit in one reply`);
134
+ return { rows, next: rows[rows.length - 1].endpoint, source };
135
+ }
136
+ rows.push(row);
137
+ }
138
+ return { rows, source };
139
+ }
140
+ //# sourceMappingURL=answer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"answer.js","sourceRoot":"","sources":["../src/answer.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EACL,aAAa,EACb,oBAAoB,EACpB,kBAAkB,EAClB,eAAe,EACf,2BAA2B,EAC3B,cAAc,EACd,sBAAsB,EACtB,mBAAmB,EACnB,qBAAqB,EACrB,iBAAiB,GAUlB,MAAM,gBAAgB,CAAC;AA2BxB,qGAAqG;AACrG,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAA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+ export * from "./serve.js";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export * from "./answer.js";
2
+ export * from "./reads.js";
3
+ export * from "./serve.js";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { NatsConnection } from "@nats-io/transport-node";
2
+ import type { RegistryReads } from "./answer.js";
3
+ export declare function natsRegistryReads(nc: NatsConnection, space: string): Promise<RegistryReads>;
4
+ //# sourceMappingURL=reads.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reads.d.ts","sourceRoot":"","sources":["../src/reads.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAkB9D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAIjD,wBAAsB,iBAAiB,CAAC,EAAE,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CA2DjG"}
package/dist/reads.js ADDED
@@ -0,0 +1,76 @@
1
+ /**
2
+ * The registry's reads over one connection holding the `registry` credential (SPEC Appendix B):
3
+ * the records store's key list by `STREAM.INFO` (keys outside `svc` are never read), each `svc`
4
+ * spec and status by per-key `DIRECT.GET`, contract artifacts by digest, and the disclosure read of
5
+ * issued evidence. A failed read is an error, never an absence.
6
+ */
7
+ import { jetstream, jetstreamManager } from "@nats-io/jetstream";
8
+ import { Kvm } from "@nats-io/kv";
9
+ import { assertLifecycleToken, ContractInvalidError, ContractStoreCorruptError, contractStoreContext, EpEnvelopeError, endpointNameOf, endpointToken, assertIssuedStoreConfig, fetchContractArtifact, issuedBucket, openIssuedStore, parseServiceSpec, parseServiceStatus, recordsBucket, } from "@cotal-ai/core";
10
+ const dec = new TextDecoder("utf-8", { fatal: true });
11
+ export async function natsRegistryReads(nc, space) {
12
+ const jsm = await jetstreamManager(nc, { checkAPI: false });
13
+ // The evidence store's shape is verified before any first-message read is trusted (SPEC 13.15).
14
+ assertIssuedStoreConfig((await jsm.streams.info(`KV_${issuedBucket(space)}`)).config, space, issuedBucket(space));
15
+ const store = openIssuedStore(await new Kvm(jetstream(nc, { checkAPI: false })).open(issuedBucket(space)), jsm, space);
16
+ const bucket = recordsBucket(space);
17
+ const prefix = `$KV.${bucket}.`;
18
+ const contracts = await contractStoreContext(nc, space);
19
+ const artifacts = new Map();
20
+ /** One `svc` key, read per key. `undefined`: never written, deleted or purged. */
21
+ const svcKey = async (key) => {
22
+ const reply = await nc.request(`$JS.API.DIRECT.GET.KV_${bucket}.${prefix}${key}`, new Uint8Array(0), { timeout: 3000 });
23
+ const code = reply.headers?.code ?? 0;
24
+ const status = reply.headers?.get("Status") ?? "";
25
+ if (code === 404 || status.startsWith("404"))
26
+ return undefined;
27
+ if (code >= 400 || status !== "")
28
+ throw new EpEnvelopeError("unavailable", `the registry read of ${key} failed (${code || status})`);
29
+ if (reply.headers?.get("KV-Operation"))
30
+ return undefined;
31
+ return JSON.parse(dec.decode(reply.data));
32
+ };
33
+ return {
34
+ observe: async (ref) => (await store.observe(ref)).evidence,
35
+ instances: async () => {
36
+ const info = await jsm.streams.info(`KV_${bucket}`, { subjects_filter: `${prefix}svc.*.*.spec` });
37
+ const out = [];
38
+ for (const subject of Object.keys(info.state.subjects ?? {})) {
39
+ const [kind, token, instanceId, part, extra] = subject.slice(prefix.length).split(".");
40
+ if (!subject.startsWith(prefix) || kind !== "svc" || !token || !instanceId || part !== "spec" || extra !== undefined)
41
+ throw new EpEnvelopeError("internal", "the records store listed a service key outside its grammar; the listing was not inferred");
42
+ endpointToken(endpointNameOf(token));
43
+ out.push({ endpoint: endpointNameOf(token), instanceId: assertLifecycleToken(instanceId, "instanceId") });
44
+ }
45
+ return out;
46
+ },
47
+ clusterDigests: async (endpoint, instanceId) => {
48
+ const raw = await svcKey(`svc.${endpointToken(endpoint)}.${instanceId}.spec`);
49
+ return raw === undefined ? undefined : parseServiceSpec(raw, { endpoint }).clusterDigests;
50
+ },
51
+ state: async (endpoint, instanceId) => {
52
+ const raw = await svcKey(`svc.${endpointToken(endpoint)}.${instanceId}.status`);
53
+ return raw === undefined ? null : parseServiceStatus(raw).state;
54
+ },
55
+ artifact: async (hex) => {
56
+ if (artifacts.has(hex))
57
+ return artifacts.get(hex);
58
+ let bytes;
59
+ try {
60
+ bytes = await fetchContractArtifact(contracts, hex, { lastOnly: true });
61
+ }
62
+ catch (e) {
63
+ // Bytes at the digest that do not verify are an invalid declaration, not a failed read.
64
+ if (e instanceof ContractStoreCorruptError)
65
+ throw new ContractInvalidError(e.message);
66
+ throw e;
67
+ }
68
+ if (bytes === undefined)
69
+ return undefined;
70
+ const value = JSON.parse(dec.decode(bytes));
71
+ artifacts.set(hex, value);
72
+ return value;
73
+ },
74
+ };
75
+ }
76
+ //# sourceMappingURL=reads.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reads.js","sourceRoot":"","sources":["../src/reads.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAyB,MAAM,oBAAoB,CAAC;AACxF,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAElC,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,yBAAyB,EACzB,oBAAoB,EACpB,eAAe,EACf,cAAc,EACd,aAAa,EACb,uBAAuB,EACvB,qBAAqB,EACrB,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,kBAAk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ClD,IAAI,KAA6B,CAAC;YAClC,IAAI,CAAC;gBACH,KAAK,GAAG,MAAM,qBAAqB,CAAC,SAAS,EAAE,GAAG,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;YAC1E,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,wFAAwF;gBACxF,IAAI,CAAC,YAAY,yBAAyB;oBAAE,MAAM,IAAI,oBAAoB,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;gBACtF,MAAM,CAAC,CAAC;YACV,CAAC;YACD,IAAI,KAAK,KAAK,SAAS;gBAAE,OAAO,SAAS,CAAC;YAC1C,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAY,CAAC;YACvD,SAAS,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YAC1B,OAAO,KAAK,CAAC;QACf,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * The registry's served commands over a registry-authorized serve grant (SPEC 13.9). Both rails are
3
+ * subscribed, as for any endpoint; `answerEndpoints` refuses the legacy rail on an authed mesh.
4
+ * `describe` is public: it names the one command and its contract, which every caller may see.
5
+ */
6
+ import type { NatsConnection } from "@nats-io/transport-node";
7
+ import { type EpCommandDef, type EpServeGrant, type EpServeHandle } from "@cotal-ai/core";
8
+ import { type RegistryAnswerOptions } from "./answer.js";
9
+ export declare function registryCommandDefs(opts: RegistryAnswerOptions): EpCommandDef[];
10
+ export declare function serveRegistry(nc: NatsConnection, grant: EpServeGrant, opts: RegistryAnswerOptions): EpServeHandle;
11
+ //# sourceMappingURL=serve.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["../src/serve.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAKL,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,aAAa,EAEnB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAmB,KAAK,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAE1E,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,qBAAqB,GAAG,YAAY,EAAE,CAM/E;AAED,wBAAgB,aAAa,CAAC,EAAE,EAAE,cAAc,EAAE,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,qBAAqB,GAAG,aAAa,CAGjH"}
package/dist/serve.js ADDED
@@ -0,0 +1,15 @@
1
+ import { REGISTRY_CONTRACTS, REGISTRY_ENDPOINT, REGISTRY_ENDPOINTS_COMMAND, serveEndpoint, } from "@cotal-ai/core";
2
+ import { answerEndpoints } from "./answer.js";
3
+ export function registryCommandDefs(opts) {
4
+ return [{
5
+ command: REGISTRY_ENDPOINTS_COMMAND,
6
+ contract: REGISTRY_CONTRACTS[REGISTRY_ENDPOINTS_COMMAND],
7
+ handler: (ctx) => answerEndpoints(opts, ctx, (ctx.request.args ?? {})),
8
+ }];
9
+ }
10
+ export function serveRegistry(nc, grant, opts) {
11
+ if (grant.endpoint !== REGISTRY_ENDPOINT)
12
+ throw new Error(`a registry serves "${REGISTRY_ENDPOINT}", not "${grant.endpoint}"`);
13
+ return serveEndpoint(nc, opts.space, grant, registryCommandDefs(opts), { public: true });
14
+ }
15
+ //# sourceMappingURL=serve.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serve.js","sourceRoot":"","sources":["../src/serve.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,0BAA0B,EAC1B,aAAa,GAKd,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,eAAe,EAA8B,MAAM,aAAa,CAAC;AAE1E,MAAM,UAAU,mBAAmB,CAAC,IAA2B;IAC7D,OAAO,CAAC;YACN,OAAO,EAAE,0BAA0B;YACnC,QAAQ,EAAE,kBAAkB,CAAC,0BAA0B,CAAE;YACzD,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,eAAe,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,IAAI,EAAE,CAA2B,CAAC;SACjG,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,EAAkB,EAAE,KAAmB,EAAE,IAA2B;IAChG,IAAI,KAAK,CAAC,QAAQ,KAAK,iBAAiB;QAAE,MAAM,IAAI,KAAK,CAAC,sBAAsB,iBAAiB,WAAW,KAAK,CAAC,QAAQ,GAAG,CAAC,CAAC;IAC/H,OAAO,aAAa,CAAC,EAAE,EAAE,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,mBAAmB,CAAC,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;AAC3F,CAAC"}
package/package.json CHANGED
@@ -1,15 +1,40 @@
1
1
  {
2
2
  "name": "@cotal-ai/registry",
3
- "version": "0.0.0-bootstrap.0",
4
- "description": "Bootstrap placeholder for configuring npm trusted publishing. Not a functional release.",
3
+ "description": "Cotal registry: the registered endpoint that answers discovery questions, starting with the endpoints a caller's recorded grants cover.",
4
+ "version": "0.135.0",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
7
7
  "type": "git",
8
- "url": "git+https://github.com/Cotal-AI/Cotal.git",
8
+ "url": "https://github.com/Cotal-AI/Cotal.git",
9
9
  "directory": "implementations/registry"
10
10
  },
11
+ "type": "module",
12
+ "main": "./dist/index.js",
13
+ "types": "./dist/index.d.ts",
14
+ "exports": {
15
+ ".": {
16
+ "types": "./dist/index.d.ts",
17
+ "import": "./dist/index.js"
18
+ }
19
+ },
20
+ "dependencies": {
21
+ "@cotal-ai/core": "0.135.0",
22
+ "@nats-io/jetstream": "^3.4.0",
23
+ "@nats-io/transport-node": "^3.4.0",
24
+ "@nats-io/kv": "^3.4.0"
25
+ },
26
+ "files": [
27
+ "dist"
28
+ ],
11
29
  "publishConfig": {
12
- "access": "public",
13
- "tag": "bootstrap"
30
+ "access": "public"
31
+ },
32
+ "devDependencies": {
33
+ "@cotal-ai/smoke-kit": "0.0.0"
34
+ },
35
+ "scripts": {
36
+ "typecheck": "tsc -p tsconfig.json --noEmit && tsc -p tsconfig.smoke.json",
37
+ "build": "tsc -p tsconfig.json",
38
+ "test": "tsx smoke/registry-answer-live.smoke.ts && tsx smoke/registry-listing-e2e-live.smoke.ts"
14
39
  }
15
- }
40
+ }