@agent-custody/receipts 0.8.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -7
- package/dist/check.d.ts +19 -0
- package/dist/check.js +288 -0
- package/dist/cli.js +119 -11
- package/dist/config.d.ts +1 -0
- package/dist/config.js +3 -0
- package/dist/console-page.d.ts +4 -0
- package/dist/console-page.js +342 -0
- package/dist/console.d.ts +20 -0
- package/dist/console.js +522 -0
- package/dist/gateway-http.js +1 -1
- package/dist/gateway.d.ts +18 -0
- package/dist/gateway.js +196 -48
- package/dist/index.d.ts +6 -2
- package/dist/index.js +4 -1
- package/dist/issue.d.ts +31 -1
- package/dist/issue.js +261 -10
- package/dist/log-store.d.ts +3 -2
- package/dist/log-store.js +2 -0
- package/dist/policy.d.ts +4 -0
- package/dist/policy.js +15 -0
- package/dist/portal.d.ts +78 -4
- package/dist/portal.js +517 -26
- package/dist/simulate.d.ts +7 -1
- package/dist/simulate.js +27 -2
- package/dist/sso.d.ts +47 -0
- package/dist/sso.js +161 -0
- package/dist/verify.js +8 -4
- package/docs/codex-recovery.md +132 -0
- package/docs/configuration.md +226 -0
- package/docs/console.md +78 -0
- package/docs/policies.md +4 -1
- package/docs/threat-model.md +13 -0
- package/docs/tutorials.md +4 -0
- package/docs/usage.md +38 -4
- package/package.json +8 -2
- package/vectors/audit.json +27 -27
- package/vectors/receipts.json +1135 -929
package/dist/gateway.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// The MCP gateway: sits between an agent and its upstreams, MCP servers or REST APIs, enforces scope + Cedar policy,
|
|
2
2
|
// and emits a signed, logged receipt for every tool call, allowed or denied.
|
|
3
3
|
import { randomUUID } from "node:crypto";
|
|
4
|
-
import { existsSync, readFileSync, renameSync, statSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { appendFileSync, closeSync, existsSync, fstatSync, mkdirSync, openSync, readFileSync, renameSync, statSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { join } from "node:path";
|
|
5
6
|
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
6
7
|
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
7
8
|
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
@@ -11,18 +12,20 @@ import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprot
|
|
|
11
12
|
import { digestOf, dsseVerifiers, dsseVerify, loadPrivateKey, loadPublicKey } from "./crypto.js";
|
|
12
13
|
import { delegationValidAt, grantChainDigests, verifyDelegation } from "./delegation.js";
|
|
13
14
|
import { APPROVAL_META_KEY, DEFAULT_APPROVAL_LIFETIME_SECONDS, consumeApproval, verifyApproval, verifyApprovalStatement } from "./approval.js";
|
|
14
|
-
import { createIssuer } from "./issue.js";
|
|
15
|
+
import { createIssuer, ReceiptPending } from "./issue.js";
|
|
15
16
|
import { openLog } from "./log-sink.js";
|
|
16
17
|
import { openExporter } from "./otel.js";
|
|
17
18
|
import { upstreamEvidenceOf } from "./upstream.js";
|
|
18
19
|
import { restUpstream } from "./rest.js";
|
|
19
20
|
import { a2aUpstream } from "./a2a.js";
|
|
20
21
|
import { captureKeyFrom, effectiveRule } from "./capture.js";
|
|
21
|
-
import { evaluate, policyDigest } from "./policy.js";
|
|
22
|
+
import { evaluate, hasPermitRule, policyDigest, policyParseErrors } from "./policy.js";
|
|
22
23
|
import { OPERATION_META_KEY, OperationStore, ownerAlive } from "./operations.js";
|
|
23
24
|
export const GATEWAY_VERSION = "0.1.0";
|
|
24
25
|
export const RECEIPT_META_KEY = "agent-custody/receipt";
|
|
25
26
|
export const MODEL_META_KEY = "agent-custody/model";
|
|
27
|
+
/** true on a result whose receipt is signed and kept in the outbox, and not yet in the log */
|
|
28
|
+
export const LOG_PENDING_META_KEY = "agent-custody/log-pending";
|
|
26
29
|
/** Set by the gateway on the answer to a retry of a financial operation: the receipt of the retry itself. `agent-custody/receipt` stays the receipt that holds the operation's outcome. */
|
|
27
30
|
export const RETRY_RECEIPT_META_KEY = "agent-custody/retry-receipt";
|
|
28
31
|
/** Set by the gateway on the call it forwards upstream: the receipt id, and the agent and principal from the attested grant. */
|
|
@@ -92,8 +95,95 @@ export async function createGatewayHost(cfg, options = {}) {
|
|
|
92
95
|
const trusted = cfg.trustedPrincipalKeys.map(loadPublicKey);
|
|
93
96
|
const approvalKeys = cfg.approvals?.trustedKeys.map(loadPublicKey) ?? [];
|
|
94
97
|
const approvalRule = (tool) => cfg.approvals?.tools.find((rule) => rule.tool === tool) ?? cfg.approvals?.tools.find((rule) => rule.tool === "*");
|
|
95
|
-
|
|
96
|
-
|
|
98
|
+
// The Cedar policy, re-read whenever the file changes, like the revocation list. A call is evaluated under the policy
|
|
99
|
+
// in force when it starts, and its receipt names that policy's digest. A changed file that cannot be read or does not
|
|
100
|
+
// parse is refused and the policy in force stays: never an allow, and never a fall back to no policy. Every change
|
|
101
|
+
// and every refusal is printed and appended to receiptsDir/policy-reloads.jsonl with both digests and the time.
|
|
102
|
+
// The bytes and the metadata come from one open file, so a rename between reading and stat'ing cannot pair them wrongly.
|
|
103
|
+
// ctime is in the key because a program can set mtime back but not ctime, and every write moves it. A file written in
|
|
104
|
+
// the last two seconds may still be being written within one timestamp tick, so its key is not kept: it is re-read on
|
|
105
|
+
// each call until it settles, and a half-written file read meanwhile is replaced by the finished one.
|
|
106
|
+
const keyOf = (st) => `${st.dev}:${st.ino}:${st.mtimeMs}:${st.ctimeMs}:${st.size}`;
|
|
107
|
+
const settled = (st) => Date.now() - Math.max(st.mtimeMs, st.ctimeMs) >= 2000;
|
|
108
|
+
const readPolicy = () => {
|
|
109
|
+
const fd = openSync(cfg.policyFile, "r");
|
|
110
|
+
try {
|
|
111
|
+
const st = fstatSync(fd);
|
|
112
|
+
const text = readFileSync(fd, "utf8");
|
|
113
|
+
return { text, seen: settled(st) ? keyOf(st) : "" };
|
|
114
|
+
}
|
|
115
|
+
finally {
|
|
116
|
+
closeSync(fd);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
const policyStat = () => keyOf(statSync(cfg.policyFile));
|
|
120
|
+
const initialPolicy = readPolicy();
|
|
121
|
+
let policyNow = { text: initialPolicy.text, digest: policyDigest(initialPolicy.text) };
|
|
122
|
+
let policySeen = initialPolicy.seen;
|
|
123
|
+
// A file that cannot be read is retried on every call, since restoring access changes none of its metadata; this
|
|
124
|
+
// keeps the refusal from being printed and recorded on each of those calls.
|
|
125
|
+
let unreadableSeen = "";
|
|
126
|
+
// A file still settling is re-read on each call; a refusal is recorded once for the same bytes.
|
|
127
|
+
let refusedDigest = "";
|
|
128
|
+
const policyReloads = join(cfg.receiptsDir, "policy-reloads.jsonl");
|
|
129
|
+
const recordReload = (entry) => {
|
|
130
|
+
try {
|
|
131
|
+
mkdirSync(cfg.receiptsDir, { recursive: true });
|
|
132
|
+
appendFileSync(policyReloads, JSON.stringify({ at: new Date().toISOString(), file: cfg.policyFile, ...entry }) + "\n");
|
|
133
|
+
}
|
|
134
|
+
catch (e) {
|
|
135
|
+
console.error(`agent-custody gateway: cannot record the policy change in ${policyReloads}: ${e instanceof Error ? e.message : String(e)}`);
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
const refuseReload = (to, errors) => {
|
|
139
|
+
console.error(`agent-custody gateway: POLICY NOT RELOADED: ${cfg.policyFile} ${errors.join("; ")}; policy ${policyNow.digest} stays in force`);
|
|
140
|
+
recordReload({ event: "refused", from: policyNow.digest, to, errors });
|
|
141
|
+
};
|
|
142
|
+
const currentPolicy = () => {
|
|
143
|
+
const unreadable = (seen, e) => {
|
|
144
|
+
if (unreadableSeen !== seen)
|
|
145
|
+
refuseReload(null, [`cannot be read (${e instanceof Error ? e.message : String(e)})`]);
|
|
146
|
+
unreadableSeen = seen;
|
|
147
|
+
return policyNow;
|
|
148
|
+
};
|
|
149
|
+
let seen;
|
|
150
|
+
try {
|
|
151
|
+
seen = policyStat();
|
|
152
|
+
}
|
|
153
|
+
catch (e) {
|
|
154
|
+
return unreadable("missing", e);
|
|
155
|
+
}
|
|
156
|
+
if (seen === policySeen)
|
|
157
|
+
return policyNow;
|
|
158
|
+
let read;
|
|
159
|
+
try {
|
|
160
|
+
read = readPolicy();
|
|
161
|
+
}
|
|
162
|
+
catch (e) {
|
|
163
|
+
return unreadable(seen, e);
|
|
164
|
+
}
|
|
165
|
+
unreadableSeen = "";
|
|
166
|
+
policySeen = read.seen;
|
|
167
|
+
const text = read.text;
|
|
168
|
+
const digest = policyDigest(text);
|
|
169
|
+
if (digest === policyNow.digest)
|
|
170
|
+
return policyNow;
|
|
171
|
+
if (digest === refusedDigest)
|
|
172
|
+
return policyNow;
|
|
173
|
+
const errors = policyParseErrors(text);
|
|
174
|
+
if (errors.length > 0) {
|
|
175
|
+
refusedDigest = digest;
|
|
176
|
+
refuseReload(digest, [`does not parse: ${errors.join("; ")}`]);
|
|
177
|
+
return policyNow;
|
|
178
|
+
}
|
|
179
|
+
refusedDigest = "";
|
|
180
|
+
// a policy with no permit rule parses and denies every call: fail-closed, but never a reload to pass over quietly
|
|
181
|
+
const warnings = hasPermitRule(text) ? [] : ["no permit rule: every call is denied"];
|
|
182
|
+
console.error(`agent-custody gateway: policy reloaded from ${cfg.policyFile}: ${policyNow.digest} -> ${digest}${warnings.length ? `; WARNING: ${warnings.join("; ")}` : ""}`);
|
|
183
|
+
recordReload({ event: "reloaded", from: policyNow.digest, to: digest, ...(warnings.length ? { warnings } : {}) });
|
|
184
|
+
policyNow = { text, digest };
|
|
185
|
+
return policyNow;
|
|
186
|
+
};
|
|
97
187
|
// Private evidence: the key that encrypts withheld fields, read once; a rule in mode encrypted without it is a config error.
|
|
98
188
|
const captureKey = cfg.captureKeyEnv ? captureKeyFrom(process.env[cfg.captureKeyEnv] ?? (() => { throw new Error(`capture key: environment variable ${cfg.captureKeyEnv} is not set`); })()) : undefined;
|
|
99
189
|
for (const [tool, rule] of Object.entries(cfg.capture ?? {})) {
|
|
@@ -156,41 +246,62 @@ export async function createGatewayHost(cfg, options = {}) {
|
|
|
156
246
|
const upstreams = new Map();
|
|
157
247
|
const owner = new Map();
|
|
158
248
|
const advertised = [];
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
249
|
+
const cancelled = options.signal
|
|
250
|
+
? new Promise((_, reject) => {
|
|
251
|
+
const stop = () => reject(new Error("the gateway start was cancelled"));
|
|
252
|
+
if (options.signal.aborted)
|
|
253
|
+
stop();
|
|
254
|
+
else
|
|
255
|
+
options.signal.addEventListener("abort", stop, { once: true });
|
|
256
|
+
})
|
|
257
|
+
: null;
|
|
258
|
+
cancelled?.catch(() => { });
|
|
259
|
+
/** a connection that hangs must not hold the start: it loses the race to a cancel */
|
|
260
|
+
const guard = (p) => (cancelled ? Promise.race([p, cancelled]) : p);
|
|
261
|
+
try {
|
|
262
|
+
for (const { name, cfg: u } of upstreamConfigs) {
|
|
263
|
+
options.signal?.throwIfAborted();
|
|
264
|
+
let client;
|
|
265
|
+
if ("rest" in u) {
|
|
266
|
+
client = restUpstream(name, { ...u.rest, tools: u.rest.tools.map((tool) => {
|
|
267
|
+
const rule = operationRule(tool.name);
|
|
268
|
+
return rule ? { ...tool, idempotencyHeader: rule.idempotencyHeader } : tool;
|
|
269
|
+
}) });
|
|
270
|
+
upstreams.set(name, client);
|
|
271
|
+
}
|
|
272
|
+
else if ("a2a" in u) {
|
|
273
|
+
client = a2aUpstream(name, u.a2a);
|
|
274
|
+
upstreams.set(name, client);
|
|
275
|
+
}
|
|
276
|
+
else if ("url" in u) {
|
|
277
|
+
client = new Client({ name: "agent-custody-gateway", version: GATEWAY_VERSION });
|
|
278
|
+
upstreams.set(name, client);
|
|
279
|
+
const token = u.tokenEnv ? process.env[u.tokenEnv] : undefined;
|
|
280
|
+
if (u.tokenEnv && !token)
|
|
281
|
+
throw new Error(`upstream ${name}: environment variable ${u.tokenEnv} is not set`);
|
|
282
|
+
await guard(client.connect(new StreamableHTTPClientTransport(new URL(u.url), token ? { requestInit: { headers: { authorization: `Bearer ${token}` } } } : {})));
|
|
283
|
+
}
|
|
284
|
+
else {
|
|
285
|
+
client = new Client({ name: "agent-custody-gateway", version: GATEWAY_VERSION });
|
|
286
|
+
upstreams.set(name, client);
|
|
287
|
+
await guard(client.connect(new StdioClientTransport({ command: u.command, args: u.args, env: upstreamEnv(u.env), stderr: "inherit" })));
|
|
288
|
+
}
|
|
289
|
+
const { tools } = await guard(client.listTools());
|
|
290
|
+
for (const t of tools) {
|
|
291
|
+
const other = owner.get(t.name);
|
|
292
|
+
if (other)
|
|
293
|
+
throw new Error(`tool "${t.name}" is offered by both upstream "${other}" and upstream "${name}"; a gateway needs one owner per tool`);
|
|
294
|
+
owner.set(t.name, name);
|
|
295
|
+
advertised.push(t);
|
|
189
296
|
}
|
|
190
|
-
owner.set(t.name, name);
|
|
191
|
-
advertised.push(t);
|
|
192
297
|
}
|
|
193
298
|
}
|
|
299
|
+
catch (e) {
|
|
300
|
+
// an upstream that was started stays running unless it is closed here: a failed or cancelled start leaves nothing behind
|
|
301
|
+
for (const c of upstreams.values())
|
|
302
|
+
await c.close().catch(() => { });
|
|
303
|
+
throw e;
|
|
304
|
+
}
|
|
194
305
|
for (const rule of cfg.operations?.tools ?? []) {
|
|
195
306
|
const via = upstreamConfigs.find((u) => u.name === owner.get(rule.tool));
|
|
196
307
|
const readVia = upstreamConfigs.find((u) => u.name === owner.get(rule.reconcile.tool));
|
|
@@ -299,6 +410,7 @@ export async function createGatewayHost(cfg, options = {}) {
|
|
|
299
410
|
};
|
|
300
411
|
async function handleCall(params) {
|
|
301
412
|
const tool = params.name;
|
|
413
|
+
const { text: policyText, digest: pDigest } = currentPolicy();
|
|
302
414
|
// An embedding caller can mutate its objects while a lookup or log append is awaited. Snapshot the call and
|
|
303
415
|
// approval before the first await, so the approved bytes are the bytes evaluated, logged, and forwarded. A caller
|
|
304
416
|
// also cannot change the payment after its reservation was bound.
|
|
@@ -546,18 +658,30 @@ export async function createGatewayHost(cfg, options = {}) {
|
|
|
546
658
|
operation = operations.update(operation.id, { status: "failed", unsent: undefined });
|
|
547
659
|
if (operation)
|
|
548
660
|
head.operation = operationEvidence(operation, operation.status === "submitted" && !createdOperation ? "unknown" : operation.status);
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
661
|
+
// The call is done, so a log outage now must not tell the agent it failed: the receipt waits in the outbox. An
|
|
662
|
+
// operation keeps the old order, because its record holds the bundle and its retry is idempotent.
|
|
663
|
+
let issued;
|
|
664
|
+
let logPending = false;
|
|
665
|
+
try {
|
|
666
|
+
issued = await issuer.issue({
|
|
667
|
+
...head,
|
|
668
|
+
...(approval ? { approval } : {}),
|
|
669
|
+
session: { id: null, toolUseId: null, provenance: "claimed" },
|
|
670
|
+
model: { id: typeof modelClaim === "string" ? modelClaim : null, provenance: "claimed" },
|
|
671
|
+
policy: { ...policy, provenance: "observed" },
|
|
672
|
+
...(authorization ? { authorization } : {}),
|
|
673
|
+
execution,
|
|
674
|
+
}, captureCtx, undefined, { deferLog: !operation });
|
|
675
|
+
}
|
|
676
|
+
catch (e) {
|
|
677
|
+
if (!(e instanceof ReceiptPending))
|
|
678
|
+
throw e;
|
|
679
|
+
console.error(`agent-custody gateway: ${e.message}`);
|
|
680
|
+
logPending = true;
|
|
681
|
+
}
|
|
558
682
|
if (operation && createdOperation && attemptedOperation)
|
|
559
683
|
operations.update(operation.id, { original: issued });
|
|
560
|
-
const meta = { [RECEIPT_META_KEY]: receiptId, ...(head.operation ? { [OPERATION_META_KEY]: head.operation } : {}) };
|
|
684
|
+
const meta = { [RECEIPT_META_KEY]: receiptId, ...(head.operation ? { [OPERATION_META_KEY]: head.operation } : {}), ...(logPending ? { [LOG_PENDING_META_KEY]: true } : {}) };
|
|
561
685
|
const refuse = (text) => ({ isError: true, content: [{ type: "text", text: `${text} (receipt ${receiptId})` }], _meta: meta });
|
|
562
686
|
switch (execution.status) {
|
|
563
687
|
// the agent gets the real result, the real reason, and the real error: what is withheld is withheld from the receipt
|
|
@@ -589,10 +713,29 @@ export async function createGatewayHost(cfg, options = {}) {
|
|
|
589
713
|
},
|
|
590
714
|
};
|
|
591
715
|
}
|
|
716
|
+
if (cfg.log && !cfg.precommit.length)
|
|
717
|
+
console.error("agent-custody gateway: a remote log is set and precommit is empty: every call is forwarded before its receipt is logged. Name the consequential tools in precommit, or [\"*\"]; requirePrecommit makes this an error");
|
|
718
|
+
let flushing;
|
|
719
|
+
const flushOutbox = () => flushing ??= (async () => {
|
|
720
|
+
const r = await issuer.flushOutbox();
|
|
721
|
+
if (r.setAside)
|
|
722
|
+
console.error(`agent-custody gateway: ${r.setAside} outbox entr${r.setAside === 1 ? "y is" : "ies are"} damaged, or not signed under its file name; renamed to .bad and not appended`);
|
|
723
|
+
if (r.foreign)
|
|
724
|
+
console.error(`agent-custody gateway: ${r.foreign} outbox entr${r.foreign === 1 ? "y is" : "ies are"} signed by a key other than ${issuer.keyid.slice(0, 12)}; left in the outbox and not appended. Restore the key that signed them, or move them away`);
|
|
725
|
+
if (r.error)
|
|
726
|
+
console.error(`agent-custody gateway: ${r.pending} receipt(s) wait in the outbox: ${r.error}`);
|
|
727
|
+
return r;
|
|
728
|
+
})().finally(() => { flushing = undefined; });
|
|
729
|
+
const autoFlush = () => void flushOutbox().catch((e) => console.error(`agent-custody gateway: the outbox flush failed: ${e instanceof Error ? e.message : String(e)}`));
|
|
730
|
+
const outboxTimer = options.autoFlush ? setInterval(autoFlush, 30_000).unref() : undefined;
|
|
731
|
+
if (options.autoFlush)
|
|
732
|
+
autoFlush();
|
|
592
733
|
return {
|
|
593
734
|
keyid: issuer.keyid,
|
|
594
735
|
open,
|
|
595
736
|
revoke,
|
|
737
|
+
policyDigest: () => currentPolicy().digest,
|
|
738
|
+
tools: () => advertised.map((t) => t.name),
|
|
596
739
|
revoked: () => {
|
|
597
740
|
reloadRevoked();
|
|
598
741
|
return [...revokedSet];
|
|
@@ -653,7 +796,7 @@ export async function createGatewayHost(cfg, options = {}) {
|
|
|
653
796
|
principal: initial.principal, agent: initial.agent, delegation: initial.delegation,
|
|
654
797
|
session: { id: null, toolUseId: null, provenance: "claimed" }, model: { id: null, provenance: "claimed" },
|
|
655
798
|
tool: initial.tool, request: { args: lookup.args, argsDigest: digestOf(lookup.args), provenance: "claimed" },
|
|
656
|
-
facts: {}, policy: { decision: "allow", reasons: ["reconciliation: the gateway read the provider record and evaluated no policy"], errors: [], policyDigest:
|
|
799
|
+
facts: {}, policy: { decision: "allow", reasons: ["reconciliation: the gateway read the provider record and evaluated no policy"], errors: [], policyDigest: currentPolicy().digest, provenance: "observed" },
|
|
657
800
|
operation: operationEvidence(op, status), reconciliation: { original, lookup },
|
|
658
801
|
execution: { status: "executed", result, resultDigest: digestOf(result), provenance: "observed" },
|
|
659
802
|
};
|
|
@@ -668,7 +811,12 @@ export async function createGatewayHost(cfg, options = {}) {
|
|
|
668
811
|
operations.update(op.id, { status: intent.predicate.operation.status, reconciliation: { ...retained, bundle }, result: intent.predicate.execution.result, unsent: undefined });
|
|
669
812
|
return bundle;
|
|
670
813
|
},
|
|
814
|
+
flushOutbox,
|
|
815
|
+
pendingReceipts: () => issuer.pending(),
|
|
671
816
|
async close() {
|
|
817
|
+
if (outboxTimer)
|
|
818
|
+
clearInterval(outboxTimer);
|
|
819
|
+
await flushing?.catch(() => { });
|
|
672
820
|
for (const c of upstreams.values())
|
|
673
821
|
await c.close();
|
|
674
822
|
operations?.close();
|
package/dist/index.d.ts
CHANGED
|
@@ -4,11 +4,15 @@ export type { GatewayOptions } from "./gateway.ts";
|
|
|
4
4
|
export { buildRequest, restUpstream } from "./rest.ts";
|
|
5
5
|
export { openExporter, otlpExporter, spanFor } from "./otel.ts";
|
|
6
6
|
export { hecEvent, splunkExporter } from "./splunk.ts";
|
|
7
|
+
export { serveConsole, type ConsoleOptions, type RunningConsole } from "./console.ts";
|
|
8
|
+
export { checkConfig, formatFindings, type CheckFinding, type CheckOptions } from "./check.ts";
|
|
7
9
|
export { GRANT_HEADER, grantHeader, parseGrantHeader, serveHttp } from "./gateway-http.ts";
|
|
8
10
|
export * from "./capture.ts";
|
|
9
11
|
export { A2A_CARD_PATH, A2A_RECEIPT_METADATA_KEY, A2A_STREAM_META_KEY, a2aUpstream, fetchAgentCard, serveA2a, textOf } from "./a2a.ts";
|
|
10
|
-
export { deliverMail, founderNote, PortalStore, portalHandler, readSession, sendFollowUps, servePortal, signSession, stripeRequest, verifyStripeSignature } from "./portal.ts";
|
|
11
|
-
export type { MailOptions, OAuthOptions, PortalOptions, PortalUser, Profile, RunningPortal, StripeOptions } from "./portal.ts";
|
|
12
|
+
export { deliverMail, founderNote, PortalStore, portalHandler, readSession, readSessionVia, sendFollowUps, servePortal, signSession, SsoRefusedError, stripeRequest, verifyStripeSignature } from "./portal.ts";
|
|
13
|
+
export type { MailOptions, OAuthOptions, PortalOptions, PortalUser, Profile, RunningPortal, SsoSetting, StripeOptions } from "./portal.ts";
|
|
14
|
+
export { oidcAuthorizeUrl, oidcExchange, pkce, samlAuthorizeUrl, samlValidate } from "./sso.ts";
|
|
15
|
+
export type { OidcConfig, SamlConfig, SsoIdentity } from "./sso.ts";
|
|
12
16
|
export type { HttpGatewayOptions, RunningHttpGateway } from "./gateway-http.ts";
|
|
13
17
|
export type { A2aServerOptions, AgentCard, ResolvedCard, RunningA2aServer } from "./a2a.ts";
|
|
14
18
|
export { exportLog, formatExport } from "./log-export.ts";
|
package/dist/index.js
CHANGED
|
@@ -3,10 +3,13 @@ export { AUTHORIZATION_PREDICATE_TYPE, buildAuthorizationStatement } from "./rec
|
|
|
3
3
|
export { buildRequest, restUpstream } from "./rest.js";
|
|
4
4
|
export { openExporter, otlpExporter, spanFor } from "./otel.js";
|
|
5
5
|
export { hecEvent, splunkExporter } from "./splunk.js";
|
|
6
|
+
export { serveConsole } from "./console.js";
|
|
7
|
+
export { checkConfig, formatFindings } from "./check.js";
|
|
6
8
|
export { GRANT_HEADER, grantHeader, parseGrantHeader, serveHttp } from "./gateway-http.js";
|
|
7
9
|
export * from "./capture.js";
|
|
8
10
|
export { A2A_CARD_PATH, A2A_RECEIPT_METADATA_KEY, A2A_STREAM_META_KEY, a2aUpstream, fetchAgentCard, serveA2a, textOf } from "./a2a.js";
|
|
9
|
-
export { deliverMail, founderNote, PortalStore, portalHandler, readSession, sendFollowUps, servePortal, signSession, stripeRequest, verifyStripeSignature } from "./portal.js";
|
|
11
|
+
export { deliverMail, founderNote, PortalStore, portalHandler, readSession, readSessionVia, sendFollowUps, servePortal, signSession, SsoRefusedError, stripeRequest, verifyStripeSignature } from "./portal.js";
|
|
12
|
+
export { oidcAuthorizeUrl, oidcExchange, pkce, samlAuthorizeUrl, samlValidate } from "./sso.js";
|
|
10
13
|
export { exportLog, formatExport } from "./log-export.js";
|
|
11
14
|
export { fileBackend, importLogFile, PostgresLog, PostgresTenancy, RateLimiter } from "./log-store.js";
|
|
12
15
|
export { PLAN_QUOTAS, PLANS } from "./log-store.js";
|
package/dist/issue.d.ts
CHANGED
|
@@ -8,6 +8,24 @@ export interface PreparedReceipt {
|
|
|
8
8
|
envelope: Envelope;
|
|
9
9
|
view: PrivateView<ReceiptPredicate>;
|
|
10
10
|
}
|
|
11
|
+
/** The receipts whose log append failed wait here, signed, until `flushOutbox` appends them. */
|
|
12
|
+
export declare const OUTBOX_DIR = "outbox";
|
|
13
|
+
/** What one `flushOutbox` did. `foreign` entries are signed by another key and stay in the outbox. */
|
|
14
|
+
export interface FlushResult {
|
|
15
|
+
sent: number;
|
|
16
|
+
pending: number;
|
|
17
|
+
setAside: number;
|
|
18
|
+
foreign: number;
|
|
19
|
+
error?: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Thrown by `issue` with `deferLog` when the log did not take the receipt. The signed receipt is kept in the outbox and
|
|
23
|
+
* no bundle is written yet: `flushOutbox` appends it later and then writes the bundle.
|
|
24
|
+
*/
|
|
25
|
+
export declare class ReceiptPending extends Error {
|
|
26
|
+
readonly receiptId: string;
|
|
27
|
+
constructor(receiptId: string, cause: unknown);
|
|
28
|
+
}
|
|
11
29
|
export interface Issuer {
|
|
12
30
|
keyid: string;
|
|
13
31
|
log: LogSink;
|
|
@@ -16,9 +34,21 @@ export interface Issuer {
|
|
|
16
34
|
* bundle. Rejects if the log refuses the leaf; no bundle is written then. The predicate is the call in full; what
|
|
17
35
|
* is signed, written, and exported is the view.
|
|
18
36
|
*/
|
|
19
|
-
issue(predicate: ReceiptPredicate, ctx?: CaptureContext, retainPrepared?: (prepared: PreparedReceipt) => PreparedReceipt
|
|
37
|
+
issue(predicate: ReceiptPredicate, ctx?: CaptureContext, retainPrepared?: (prepared: PreparedReceipt) => PreparedReceipt, opts?: {
|
|
38
|
+
deferLog?: boolean;
|
|
39
|
+
}): Promise<ReceiptBundle>;
|
|
20
40
|
/** The same for an authorization, signed and committed before a consequential call is forwarded. Rejects if the log refuses; the caller must then not forward. */
|
|
21
41
|
authorize(predicate: AuthorizationPredicate, ctx?: CaptureContext): Promise<AuthorizationBundle>;
|
|
42
|
+
/**
|
|
43
|
+
* Appends each receipt in the outbox, oldest statement first, and writes its bundle. A log refusal stops the flush;
|
|
44
|
+
* another failure is reported in `error` and the flush goes on. One flush runs at a time in a process, and a lock
|
|
45
|
+
* file in the outbox keeps other processes out: when another process holds it, nothing is done. An entry that is
|
|
46
|
+
* damaged, or that this issuer's key signed under another receipt id, is renamed to `<name>.bad` and counted in
|
|
47
|
+
* `setAside`. An entry signed by another key stays in the outbox and is counted in `foreign`.
|
|
48
|
+
*/
|
|
49
|
+
flushOutbox(): Promise<FlushResult>;
|
|
50
|
+
/** the receipts in the outbox */
|
|
51
|
+
pending(): number;
|
|
22
52
|
}
|
|
23
53
|
export interface IssuerOptions {
|
|
24
54
|
/** told about every receipt after it is written; an exporter's failure never reaches the caller */
|