@agent-custody/receipts 0.7.0 → 0.8.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 +16 -10
- package/dist/approval.d.ts +74 -0
- package/dist/approval.js +196 -0
- package/dist/capture.js +49 -1
- package/dist/cli.js +124 -3
- package/dist/config.d.ts +85 -0
- package/dist/config.js +72 -2
- package/dist/gateway.d.ts +5 -0
- package/dist/gateway.js +285 -17
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/issue.d.ts +8 -3
- package/dist/issue.js +13 -4
- package/dist/operations.d.ts +101 -0
- package/dist/operations.js +239 -0
- package/dist/otel.js +12 -5
- package/dist/receipt.d.ts +36 -1
- package/dist/rest.js +14 -1
- package/dist/simulate.d.ts +58 -0
- package/dist/simulate.js +204 -0
- package/dist/splunk.js +11 -4
- package/dist/verify.d.ts +2 -0
- package/dist/verify.js +237 -5
- package/docs/approvals.md +107 -0
- package/docs/financial-operations.md +99 -0
- package/docs/policies.md +22 -0
- package/docs/tutorials.md +5 -0
- package/docs/usage.md +28 -2
- package/docs/verification.md +26 -8
- package/package.json +1 -1
- package/vectors/audit.json +27 -27
- package/vectors/canonical.json +5 -5
- package/vectors/receipts.json +2653 -457
package/dist/config.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ declare const RestToolSchema: z.ZodObject<{
|
|
|
16
16
|
json: "json";
|
|
17
17
|
none: "none";
|
|
18
18
|
}>>;
|
|
19
|
+
idempotencyHeader: z.ZodOptional<z.ZodString>;
|
|
19
20
|
inputSchema: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
20
21
|
}, z.core.$strip>;
|
|
21
22
|
export type RestToolConfig = z.infer<typeof RestToolSchema>;
|
|
@@ -41,6 +42,7 @@ declare const RestUpstreamSchema: z.ZodObject<{
|
|
|
41
42
|
json: "json";
|
|
42
43
|
none: "none";
|
|
43
44
|
}>>;
|
|
45
|
+
idempotencyHeader: z.ZodOptional<z.ZodString>;
|
|
44
46
|
inputSchema: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
45
47
|
}, z.core.$strip>>;
|
|
46
48
|
}, z.core.$strip>;
|
|
@@ -83,6 +85,7 @@ declare const UpstreamSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
|
83
85
|
json: "json";
|
|
84
86
|
none: "none";
|
|
85
87
|
}>>;
|
|
88
|
+
idempotencyHeader: z.ZodOptional<z.ZodString>;
|
|
86
89
|
inputSchema: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
87
90
|
}, z.core.$strip>>;
|
|
88
91
|
}, z.core.$strip>;
|
|
@@ -103,6 +106,48 @@ declare const FactSchema: z.ZodObject<{
|
|
|
103
106
|
forTools: z.ZodArray<z.ZodString>;
|
|
104
107
|
optional: z.ZodDefault<z.ZodBoolean>;
|
|
105
108
|
}, z.core.$strip>;
|
|
109
|
+
declare const OperationToolSchema: z.ZodObject<{
|
|
110
|
+
tool: z.ZodString;
|
|
111
|
+
budget: z.ZodString;
|
|
112
|
+
amountField: z.ZodDefault<z.ZodString>;
|
|
113
|
+
currencyField: z.ZodDefault<z.ZodString>;
|
|
114
|
+
idempotencyHeader: z.ZodDefault<z.ZodString>;
|
|
115
|
+
reconcile: z.ZodObject<{
|
|
116
|
+
tool: z.ZodString;
|
|
117
|
+
args: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
118
|
+
statusPath: z.ZodString;
|
|
119
|
+
identityPath: z.ZodDefault<z.ZodString>;
|
|
120
|
+
confirmed: z.ZodArray<z.ZodString>;
|
|
121
|
+
failed: z.ZodArray<z.ZodString>;
|
|
122
|
+
pending: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
123
|
+
}, z.core.$strip>;
|
|
124
|
+
}, z.core.$strip>;
|
|
125
|
+
declare const OperationsSchema: z.ZodObject<{
|
|
126
|
+
database: z.ZodString;
|
|
127
|
+
budgets: z.ZodArray<z.ZodObject<{
|
|
128
|
+
id: z.ZodString;
|
|
129
|
+
currency: z.ZodString;
|
|
130
|
+
limit: z.ZodNumber;
|
|
131
|
+
}, z.core.$strip>>;
|
|
132
|
+
tools: z.ZodArray<z.ZodObject<{
|
|
133
|
+
tool: z.ZodString;
|
|
134
|
+
budget: z.ZodString;
|
|
135
|
+
amountField: z.ZodDefault<z.ZodString>;
|
|
136
|
+
currencyField: z.ZodDefault<z.ZodString>;
|
|
137
|
+
idempotencyHeader: z.ZodDefault<z.ZodString>;
|
|
138
|
+
reconcile: z.ZodObject<{
|
|
139
|
+
tool: z.ZodString;
|
|
140
|
+
args: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
141
|
+
statusPath: z.ZodString;
|
|
142
|
+
identityPath: z.ZodDefault<z.ZodString>;
|
|
143
|
+
confirmed: z.ZodArray<z.ZodString>;
|
|
144
|
+
failed: z.ZodArray<z.ZodString>;
|
|
145
|
+
pending: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
146
|
+
}, z.core.$strip>;
|
|
147
|
+
}, z.core.$strip>>;
|
|
148
|
+
}, z.core.$strip>;
|
|
149
|
+
export type OperationsConfig = z.infer<typeof OperationsSchema>;
|
|
150
|
+
export type OperationToolConfig = z.infer<typeof OperationToolSchema>;
|
|
106
151
|
export declare const GatewayConfigSchema: z.ZodObject<{
|
|
107
152
|
identity: z.ZodObject<{
|
|
108
153
|
keyFile: z.ZodString;
|
|
@@ -136,6 +181,7 @@ export declare const GatewayConfigSchema: z.ZodObject<{
|
|
|
136
181
|
json: "json";
|
|
137
182
|
none: "none";
|
|
138
183
|
}>>;
|
|
184
|
+
idempotencyHeader: z.ZodOptional<z.ZodString>;
|
|
139
185
|
inputSchema: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
140
186
|
}, z.core.$strip>>;
|
|
141
187
|
}, z.core.$strip>;
|
|
@@ -177,6 +223,7 @@ export declare const GatewayConfigSchema: z.ZodObject<{
|
|
|
177
223
|
json: "json";
|
|
178
224
|
none: "none";
|
|
179
225
|
}>>;
|
|
226
|
+
idempotencyHeader: z.ZodOptional<z.ZodString>;
|
|
180
227
|
inputSchema: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
181
228
|
}, z.core.$strip>>;
|
|
182
229
|
}, z.core.$strip>;
|
|
@@ -202,6 +249,44 @@ export declare const GatewayConfigSchema: z.ZodObject<{
|
|
|
202
249
|
optional: z.ZodDefault<z.ZodBoolean>;
|
|
203
250
|
}, z.core.$strip>>>;
|
|
204
251
|
precommit: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
252
|
+
approvals: z.ZodOptional<z.ZodObject<{
|
|
253
|
+
trustedKeys: z.ZodArray<z.ZodString>;
|
|
254
|
+
usedDir: z.ZodString;
|
|
255
|
+
maxLifetimeSeconds: z.ZodOptional<z.ZodNumber>;
|
|
256
|
+
tools: z.ZodArray<z.ZodObject<{
|
|
257
|
+
tool: z.ZodString;
|
|
258
|
+
minApprovers: z.ZodDefault<z.ZodUnion<readonly [z.ZodLiteral<1>, z.ZodLiteral<2>]>>;
|
|
259
|
+
fields: z.ZodOptional<z.ZodObject<{
|
|
260
|
+
amount: z.ZodOptional<z.ZodString>;
|
|
261
|
+
currency: z.ZodOptional<z.ZodString>;
|
|
262
|
+
beneficiary: z.ZodOptional<z.ZodString>;
|
|
263
|
+
}, z.core.$strip>>;
|
|
264
|
+
}, z.core.$strip>>;
|
|
265
|
+
}, z.core.$strip>>;
|
|
266
|
+
operations: z.ZodOptional<z.ZodObject<{
|
|
267
|
+
database: z.ZodString;
|
|
268
|
+
budgets: z.ZodArray<z.ZodObject<{
|
|
269
|
+
id: z.ZodString;
|
|
270
|
+
currency: z.ZodString;
|
|
271
|
+
limit: z.ZodNumber;
|
|
272
|
+
}, z.core.$strip>>;
|
|
273
|
+
tools: z.ZodArray<z.ZodObject<{
|
|
274
|
+
tool: z.ZodString;
|
|
275
|
+
budget: z.ZodString;
|
|
276
|
+
amountField: z.ZodDefault<z.ZodString>;
|
|
277
|
+
currencyField: z.ZodDefault<z.ZodString>;
|
|
278
|
+
idempotencyHeader: z.ZodDefault<z.ZodString>;
|
|
279
|
+
reconcile: z.ZodObject<{
|
|
280
|
+
tool: z.ZodString;
|
|
281
|
+
args: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
282
|
+
statusPath: z.ZodString;
|
|
283
|
+
identityPath: z.ZodDefault<z.ZodString>;
|
|
284
|
+
confirmed: z.ZodArray<z.ZodString>;
|
|
285
|
+
failed: z.ZodArray<z.ZodString>;
|
|
286
|
+
pending: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
287
|
+
}, z.core.$strip>;
|
|
288
|
+
}, z.core.$strip>>;
|
|
289
|
+
}, z.core.$strip>>;
|
|
205
290
|
revokedGrants: z.ZodOptional<z.ZodString>;
|
|
206
291
|
capture: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
207
292
|
args: z.ZodOptional<z.ZodObject<{
|
package/dist/config.js
CHANGED
|
@@ -22,6 +22,8 @@ const RestToolSchema = z.object({
|
|
|
22
22
|
query: z.array(z.string().min(1)).optional(),
|
|
23
23
|
/** "none" sends no body even on POST */
|
|
24
24
|
body: z.enum(["json", "none"]).default("json"),
|
|
25
|
+
/** The gateway supplies its durable operation key in this header; callers cannot choose or override it. */
|
|
26
|
+
idempotencyHeader: z.string().regex(/^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/).optional(),
|
|
25
27
|
/** the JSON Schema the agent sees; default accepts any object */
|
|
26
28
|
inputSchema: z.record(z.string(), z.unknown()).default({ type: "object" }),
|
|
27
29
|
});
|
|
@@ -64,6 +66,67 @@ const FactSchema = z.object({
|
|
|
64
66
|
/** when true and a "$args.<key>" the template needs is absent from the call, the lookup is skipped and the fact is simply not present */
|
|
65
67
|
optional: z.boolean().default(false),
|
|
66
68
|
});
|
|
69
|
+
/** Signed human approvals are independent of Cedar: an approving artifact binds the whole call and is used once. */
|
|
70
|
+
const ApprovalsSchema = z.object({
|
|
71
|
+
trustedKeys: z.array(z.string().min(1)).min(1),
|
|
72
|
+
usedDir: z.string().min(1),
|
|
73
|
+
/** The longest lifetime (expiresAt minus issuedAt) that the gateway accepts. The signer chooses the expiry, and this caps it. Default: 3600. */
|
|
74
|
+
maxLifetimeSeconds: z.number().int().positive().optional(),
|
|
75
|
+
tools: z.array(z.object({
|
|
76
|
+
tool: z.string().min(1),
|
|
77
|
+
minApprovers: z.union([z.literal(1), z.literal(2)]).default(1),
|
|
78
|
+
/** Argument names carrying these values; omitted names default to amount, currency, and beneficiary. */
|
|
79
|
+
fields: z.object({ amount: z.string().min(1).optional(), currency: z.string().min(1).optional(), beneficiary: z.string().min(1).optional() }).optional(),
|
|
80
|
+
})).min(1).refine((tools) => new Set(tools.map((t) => t.tool)).size === tools.length, { message: "approval tool names must be unique" }),
|
|
81
|
+
});
|
|
82
|
+
/** Amounts and limits are integer minor units; one budget is shared by every principal and agent on this database. */
|
|
83
|
+
const OperationBudgetSchema = z.object({ id: z.string().min(1).max(128), currency: z.string().regex(/^[A-Z]{3}$/), limit: z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER) });
|
|
84
|
+
const OperationReconcileSchema = z.object({
|
|
85
|
+
tool: z.string().min(1),
|
|
86
|
+
/** Only the gateway-derived idempotency key may be substituted. The agent's operation id never reaches a receipt, and reconciliation never takes new caller arguments. */
|
|
87
|
+
args: z.record(z.string(), z.string()).refine((args) => Object.values(args).every((v) => !v.startsWith("$") || v === "$operation.idempotencyKey"), { message: "reconciliation templates only support $operation.idempotencyKey" }),
|
|
88
|
+
statusPath: z.string().min(1).max(512).refine((path) => path.split(".").every((part) => part.length > 0), { message: "reconciliation statusPath must have nonempty dot-separated parts" }),
|
|
89
|
+
/** The provider record must echo this operation's idempotency key before it may close the reservation. */
|
|
90
|
+
identityPath: z.string().min(1).max(512).refine((path) => path.split(".").every((part) => part.length > 0), { message: "reconciliation identityPath must have nonempty dot-separated parts" }).default("idempotencyKey"),
|
|
91
|
+
confirmed: z.array(z.string().min(1).max(128)).min(1),
|
|
92
|
+
failed: z.array(z.string().min(1).max(128)).min(1),
|
|
93
|
+
pending: z.array(z.string().min(1)).default([]),
|
|
94
|
+
}).refine((r) => {
|
|
95
|
+
const statuses = [...r.confirmed, ...r.failed, ...(r.pending ?? [])];
|
|
96
|
+
return new Set(statuses).size === statuses.length;
|
|
97
|
+
}, { message: "reconciliation statuses must be distinct" });
|
|
98
|
+
const OperationToolSchema = z.object({
|
|
99
|
+
tool: z.string().min(1),
|
|
100
|
+
budget: z.string().min(1),
|
|
101
|
+
amountField: z.string().min(1).default("amount"),
|
|
102
|
+
currencyField: z.string().min(1).default("currency"),
|
|
103
|
+
idempotencyHeader: z.string().regex(/^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/).default("Idempotency-Key"),
|
|
104
|
+
reconcile: OperationReconcileSchema,
|
|
105
|
+
});
|
|
106
|
+
const OperationsSchema = z.object({
|
|
107
|
+
database: z.string().min(1),
|
|
108
|
+
budgets: z.array(OperationBudgetSchema).min(1),
|
|
109
|
+
tools: z.array(OperationToolSchema).min(1),
|
|
110
|
+
}).superRefine((operations, ctx) => {
|
|
111
|
+
const budgets = new Set();
|
|
112
|
+
for (const [i, budget] of operations.budgets.entries()) {
|
|
113
|
+
if (budgets.has(budget.id))
|
|
114
|
+
ctx.addIssue({ code: "custom", path: ["budgets", i, "id"], message: "duplicate operation budget" });
|
|
115
|
+
budgets.add(budget.id);
|
|
116
|
+
}
|
|
117
|
+
const tools = new Set();
|
|
118
|
+
for (const [i, tool] of operations.tools.entries()) {
|
|
119
|
+
if (tools.has(tool.tool))
|
|
120
|
+
ctx.addIssue({ code: "custom", path: ["tools", i, "tool"], message: "duplicate financial operation tool" });
|
|
121
|
+
tools.add(tool.tool);
|
|
122
|
+
if (!budgets.has(tool.budget))
|
|
123
|
+
ctx.addIssue({ code: "custom", path: ["tools", i, "budget"], message: "unknown operation budget" });
|
|
124
|
+
}
|
|
125
|
+
for (const [i, tool] of operations.tools.entries()) {
|
|
126
|
+
if (tools.has(tool.reconcile.tool))
|
|
127
|
+
ctx.addIssue({ code: "custom", path: ["tools", i, "reconcile", "tool"], message: "a reconciliation read cannot be a financial operation tool" });
|
|
128
|
+
}
|
|
129
|
+
});
|
|
67
130
|
export const GatewayConfigSchema = z.object({
|
|
68
131
|
identity: z.object({ keyFile: z.string() }),
|
|
69
132
|
/** the upstream: an MCP server to spawn over stdio, an MCP URL to reach over Streamable HTTP with an optional bearer token from the environment, or a REST API described as tools */
|
|
@@ -80,6 +143,10 @@ export const GatewayConfigSchema = z.object({
|
|
|
80
143
|
* authorization to the log and refuses the call if the log will not take it. Evidence then precedes the side effect.
|
|
81
144
|
*/
|
|
82
145
|
precommit: z.array(z.string().min(1)).default([]),
|
|
146
|
+
/** Tools that require a signed, unexpired, single-use approval, in every mode; "*" covers all agent calls. */
|
|
147
|
+
approvals: ApprovalsSchema.optional(),
|
|
148
|
+
/** Durable idempotency, daily budget reservations, and provider reconciliation for financial operations. */
|
|
149
|
+
operations: OperationsSchema.optional(),
|
|
83
150
|
/** a JSON file listing digests of revoked grant envelopes (`agent-custody revoke` appends to it); re-read whenever it changes, checked on every call */
|
|
84
151
|
revokedGrants: z.string().min(1).optional(),
|
|
85
152
|
/** private evidence: what the receipt file carries of each tool's arguments, result, and facts */
|
|
@@ -87,7 +154,7 @@ export const GatewayConfigSchema = z.object({
|
|
|
87
154
|
/** the environment variable holding the 32-byte key (hex or base64) that encrypts withheld fields in mode encrypted; read at startup, never in the file */
|
|
88
155
|
captureKeyEnv: z.string().min(1).optional(),
|
|
89
156
|
/**
|
|
90
|
-
* "enforce" (the default when absent) denies what the policy denies. "observe" forwards every call the grant
|
|
157
|
+
* "enforce" (the default when absent) denies what the policy denies. "observe" forwards every call the grant and required human approval allow and records the
|
|
91
158
|
* decision the policy would have made, with `enforced: false` on the receipt: the way to run a new policy against
|
|
92
159
|
* real traffic before turning it on. A log that refuses a consequential call's authorization does not withhold the
|
|
93
160
|
* call in observe mode; it is printed.
|
|
@@ -101,7 +168,8 @@ export const GatewayConfigSchema = z.object({
|
|
|
101
168
|
}).refine(hasOneLog, oneLog).refine((c) => (c.upstream ? 1 : 0) + (c.upstreams ? 1 : 0) === 1, { message: "exactly one of upstream or upstreams is required" })
|
|
102
169
|
// a key fetched from the log itself proves nothing about a log that is dishonest from the start, so a remote log that
|
|
103
170
|
// gates consequential calls must have its keys pinned in the config (issue #99)
|
|
104
|
-
.refine((c) => !c.log || !c.precommit.length || !!c.log.keys?.length, { message: "precommit with a remote log needs log.keys: the log's public key files, pinned, to check its answer before a consequential call is forwarded" })
|
|
171
|
+
.refine((c) => !c.log || (!c.precommit.length && !c.operations) || !!c.log.keys?.length, { message: "precommit with a remote log needs log.keys: the log's public key files, pinned, to check its answer before a consequential call is forwarded" })
|
|
172
|
+
.refine((c) => !c.operations || !c.facts.some((fact) => c.operations.tools.some((tool) => tool.tool === fact.tool)), { message: "a fact lookup cannot invoke a financial operation tool" });
|
|
105
173
|
/** Loads a config file and resolves every path relative to the file's directory. */
|
|
106
174
|
export function loadConfig(path) {
|
|
107
175
|
const cfg = GatewayConfigSchema.parse(JSON.parse(readFileSync(path, "utf8")));
|
|
@@ -117,6 +185,8 @@ export function loadConfig(path) {
|
|
|
117
185
|
...(cfg.logFile ? { logFile: r(cfg.logFile) } : {}),
|
|
118
186
|
...(cfg.log?.keys ? { log: { ...cfg.log, keys: cfg.log.keys.map(r) } } : {}),
|
|
119
187
|
...(cfg.revokedGrants ? { revokedGrants: r(cfg.revokedGrants) } : {}),
|
|
188
|
+
...(cfg.approvals ? { approvals: { ...cfg.approvals, trustedKeys: cfg.approvals.trustedKeys.map(r), usedDir: r(cfg.approvals.usedDir) } } : {}),
|
|
189
|
+
...(cfg.operations ? { operations: { ...cfg.operations, database: r(cfg.operations.database) } } : {}),
|
|
120
190
|
};
|
|
121
191
|
}
|
|
122
192
|
export const SdkConfigSchema = z.object({
|
package/dist/gateway.d.ts
CHANGED
|
@@ -4,9 +4,12 @@ import { type Envelope } from "./crypto.ts";
|
|
|
4
4
|
import { type Delegation } from "./delegation.ts";
|
|
5
5
|
import { type LogSink } from "./log-sink.ts";
|
|
6
6
|
import { type ReceiptExporter } from "./otel.ts";
|
|
7
|
+
import type { ReceiptBundle } from "./receipt.ts";
|
|
7
8
|
export declare const GATEWAY_VERSION = "0.1.0";
|
|
8
9
|
export declare const RECEIPT_META_KEY = "agent-custody/receipt";
|
|
9
10
|
export declare const MODEL_META_KEY = "agent-custody/model";
|
|
11
|
+
/** 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. */
|
|
12
|
+
export declare const RETRY_RECEIPT_META_KEY = "agent-custody/retry-receipt";
|
|
10
13
|
/** Set by the gateway on the call it forwards upstream: the receipt id, and the agent and principal from the attested grant. */
|
|
11
14
|
export declare const AGENT_META_KEY = "agent-custody/agent";
|
|
12
15
|
export declare const PRINCIPAL_META_KEY = "agent-custody/principal";
|
|
@@ -54,6 +57,8 @@ export interface GatewayHost {
|
|
|
54
57
|
revoke(grantDigest: string): void;
|
|
55
58
|
/** the digests revoked so far */
|
|
56
59
|
revoked(): string[];
|
|
60
|
+
/** Operator-only provider lookup. Never exposed as an agent tool. Unknown/pending reservations remain held until a terminal reconciliation receipt is committed. */
|
|
61
|
+
reconcile(operationId: string): Promise<ReceiptBundle>;
|
|
57
62
|
/** closes the upstreams; every session opened from this host is finished with */
|
|
58
63
|
close(): Promise<void>;
|
|
59
64
|
}
|