@reinconsole/sdk 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +46 -0
- package/dist/index.cjs +368 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +502 -0
- package/dist/index.d.ts +502 -0
- package/dist/index.js +351 -0
- package/dist/index.js.map +1 -0
- package/package.json +63 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,502 @@
|
|
|
1
|
+
import { Vendor, Asset, Chain, TaskContext, Agent, Policy, Decision, PaymentIntent, Receipt } from '@reinconsole/core';
|
|
2
|
+
export { Decision, PaymentIntent, Receipt, ReceiptSettlement, TaskContext } from '@reinconsole/core';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* x402 wire shapes (spec v1), mock-first: these schemas are what Rein's mock
|
|
7
|
+
* facilitator and tests speak today, and they track the published x402 spec so
|
|
8
|
+
* real vendors parse identically when the live integration lands.
|
|
9
|
+
*/
|
|
10
|
+
/** One way to pay, as offered inside a 402 response body. */
|
|
11
|
+
declare const PaymentRequirement: z.ZodObject<{
|
|
12
|
+
scheme: z.ZodString;
|
|
13
|
+
network: z.ZodString;
|
|
14
|
+
/** Amount in the asset's atomic units (e.g. "10000" = 0.01 USDC at 6 decimals). */
|
|
15
|
+
maxAmountRequired: z.ZodString;
|
|
16
|
+
resource: z.ZodOptional<z.ZodString>;
|
|
17
|
+
description: z.ZodOptional<z.ZodString>;
|
|
18
|
+
mimeType: z.ZodOptional<z.ZodString>;
|
|
19
|
+
payTo: z.ZodString;
|
|
20
|
+
maxTimeoutSeconds: z.ZodOptional<z.ZodNumber>;
|
|
21
|
+
/** Token contract address — or, mock-first, a plain symbol like "USDC". */
|
|
22
|
+
asset: z.ZodString;
|
|
23
|
+
extra: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
24
|
+
}, "strip", z.ZodTypeAny, {
|
|
25
|
+
scheme: string;
|
|
26
|
+
network: string;
|
|
27
|
+
maxAmountRequired: string;
|
|
28
|
+
payTo: string;
|
|
29
|
+
asset: string;
|
|
30
|
+
resource?: string | undefined;
|
|
31
|
+
description?: string | undefined;
|
|
32
|
+
mimeType?: string | undefined;
|
|
33
|
+
maxTimeoutSeconds?: number | undefined;
|
|
34
|
+
extra?: Record<string, unknown> | undefined;
|
|
35
|
+
}, {
|
|
36
|
+
scheme: string;
|
|
37
|
+
network: string;
|
|
38
|
+
maxAmountRequired: string;
|
|
39
|
+
payTo: string;
|
|
40
|
+
asset: string;
|
|
41
|
+
resource?: string | undefined;
|
|
42
|
+
description?: string | undefined;
|
|
43
|
+
mimeType?: string | undefined;
|
|
44
|
+
maxTimeoutSeconds?: number | undefined;
|
|
45
|
+
extra?: Record<string, unknown> | undefined;
|
|
46
|
+
}>;
|
|
47
|
+
type PaymentRequirement = z.infer<typeof PaymentRequirement>;
|
|
48
|
+
/** The full 402 body a paywalled vendor returns. */
|
|
49
|
+
declare const PaymentRequired: z.ZodObject<{
|
|
50
|
+
x402Version: z.ZodNumber;
|
|
51
|
+
accepts: z.ZodArray<z.ZodObject<{
|
|
52
|
+
scheme: z.ZodString;
|
|
53
|
+
network: z.ZodString;
|
|
54
|
+
/** Amount in the asset's atomic units (e.g. "10000" = 0.01 USDC at 6 decimals). */
|
|
55
|
+
maxAmountRequired: z.ZodString;
|
|
56
|
+
resource: z.ZodOptional<z.ZodString>;
|
|
57
|
+
description: z.ZodOptional<z.ZodString>;
|
|
58
|
+
mimeType: z.ZodOptional<z.ZodString>;
|
|
59
|
+
payTo: z.ZodString;
|
|
60
|
+
maxTimeoutSeconds: z.ZodOptional<z.ZodNumber>;
|
|
61
|
+
/** Token contract address — or, mock-first, a plain symbol like "USDC". */
|
|
62
|
+
asset: z.ZodString;
|
|
63
|
+
extra: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
64
|
+
}, "strip", z.ZodTypeAny, {
|
|
65
|
+
scheme: string;
|
|
66
|
+
network: string;
|
|
67
|
+
maxAmountRequired: string;
|
|
68
|
+
payTo: string;
|
|
69
|
+
asset: string;
|
|
70
|
+
resource?: string | undefined;
|
|
71
|
+
description?: string | undefined;
|
|
72
|
+
mimeType?: string | undefined;
|
|
73
|
+
maxTimeoutSeconds?: number | undefined;
|
|
74
|
+
extra?: Record<string, unknown> | undefined;
|
|
75
|
+
}, {
|
|
76
|
+
scheme: string;
|
|
77
|
+
network: string;
|
|
78
|
+
maxAmountRequired: string;
|
|
79
|
+
payTo: string;
|
|
80
|
+
asset: string;
|
|
81
|
+
resource?: string | undefined;
|
|
82
|
+
description?: string | undefined;
|
|
83
|
+
mimeType?: string | undefined;
|
|
84
|
+
maxTimeoutSeconds?: number | undefined;
|
|
85
|
+
extra?: Record<string, unknown> | undefined;
|
|
86
|
+
}>, "many">;
|
|
87
|
+
error: z.ZodOptional<z.ZodString>;
|
|
88
|
+
}, "strip", z.ZodTypeAny, {
|
|
89
|
+
x402Version: number;
|
|
90
|
+
accepts: {
|
|
91
|
+
scheme: string;
|
|
92
|
+
network: string;
|
|
93
|
+
maxAmountRequired: string;
|
|
94
|
+
payTo: string;
|
|
95
|
+
asset: string;
|
|
96
|
+
resource?: string | undefined;
|
|
97
|
+
description?: string | undefined;
|
|
98
|
+
mimeType?: string | undefined;
|
|
99
|
+
maxTimeoutSeconds?: number | undefined;
|
|
100
|
+
extra?: Record<string, unknown> | undefined;
|
|
101
|
+
}[];
|
|
102
|
+
error?: string | undefined;
|
|
103
|
+
}, {
|
|
104
|
+
x402Version: number;
|
|
105
|
+
accepts: {
|
|
106
|
+
scheme: string;
|
|
107
|
+
network: string;
|
|
108
|
+
maxAmountRequired: string;
|
|
109
|
+
payTo: string;
|
|
110
|
+
asset: string;
|
|
111
|
+
resource?: string | undefined;
|
|
112
|
+
description?: string | undefined;
|
|
113
|
+
mimeType?: string | undefined;
|
|
114
|
+
maxTimeoutSeconds?: number | undefined;
|
|
115
|
+
extra?: Record<string, unknown> | undefined;
|
|
116
|
+
}[];
|
|
117
|
+
error?: string | undefined;
|
|
118
|
+
}>;
|
|
119
|
+
type PaymentRequired = z.infer<typeof PaymentRequired>;
|
|
120
|
+
declare function networkToChain(network: string): Chain | undefined;
|
|
121
|
+
/**
|
|
122
|
+
* Resolve a requirement's asset to a symbol Rein knows. Tries, in order: the
|
|
123
|
+
* asset field as a literal symbol (mock-first), `extra.symbol`, then known
|
|
124
|
+
* contract addresses (exact case for Solana, lowercased for EVM), then any
|
|
125
|
+
* caller-supplied address map.
|
|
126
|
+
*/
|
|
127
|
+
declare function resolveAsset(requirement: PaymentRequirement, extraAddresses?: Record<string, Asset>): Asset | undefined;
|
|
128
|
+
/**
|
|
129
|
+
* Convert an atomic-unit amount to a normalized decimal string without floats,
|
|
130
|
+
* e.g. ("10000", 6) -> "0.01". Stablecoins Rein supports all use 6 decimals;
|
|
131
|
+
* a requirement can override via `extra.decimals`.
|
|
132
|
+
*/
|
|
133
|
+
declare function atomicToDecimal(atomic: string, decimals: number): string;
|
|
134
|
+
/**
|
|
135
|
+
* The inverse of {@link atomicToDecimal}: a human-unit decimal string to atomic
|
|
136
|
+
* units without floats, e.g. ("0.05", 6) -> "50000". Throws if the value has
|
|
137
|
+
* more fraction digits than the asset carries (sub-atomic precision is a
|
|
138
|
+
* pricing bug, not something to round silently).
|
|
139
|
+
*/
|
|
140
|
+
declare function decimalToAtomic(decimal: string, decimals: number): string;
|
|
141
|
+
declare function requirementDecimals(requirement: PaymentRequirement): number;
|
|
142
|
+
/** A requirement the guard fully understood, mapped into Rein's domain. */
|
|
143
|
+
interface ResolvedRequirement {
|
|
144
|
+
requirement: PaymentRequirement;
|
|
145
|
+
chain: Chain;
|
|
146
|
+
asset: Asset;
|
|
147
|
+
/** Human-unit decimal amount, e.g. "0.01". */
|
|
148
|
+
amount: string;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Pick the first offer the guard can govern: scheme `exact`, a network that
|
|
152
|
+
* maps to a supported chain, and a resolvable asset. Returns undefined when
|
|
153
|
+
* no offer qualifies — callers must treat that as fail-closed.
|
|
154
|
+
*/
|
|
155
|
+
declare function selectRequirement(accepts: readonly PaymentRequirement[], extraAddresses?: Record<string, Asset>): ResolvedRequirement | undefined;
|
|
156
|
+
/** What the guard submits to the policy engine (the `/v1/evaluate` shape). */
|
|
157
|
+
interface IntentSubmission {
|
|
158
|
+
agentId: string;
|
|
159
|
+
vendor: Vendor;
|
|
160
|
+
resource: string;
|
|
161
|
+
amount: string;
|
|
162
|
+
asset: Asset;
|
|
163
|
+
chain: Chain;
|
|
164
|
+
taskContext?: TaskContext;
|
|
165
|
+
}
|
|
166
|
+
/** Build the evaluate payload for a resolved offer on a given request URL. */
|
|
167
|
+
declare function toIntentSubmission(resolved: ResolvedRequirement, url: string, agentId: string, taskContext: TaskContext | undefined): IntentSubmission;
|
|
168
|
+
|
|
169
|
+
/** Any fetch-compatible function (global fetch, undici, or a test double). */
|
|
170
|
+
type FetchLike = (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
|
|
171
|
+
declare const Health: z.ZodObject<{
|
|
172
|
+
status: z.ZodString;
|
|
173
|
+
publicKey: z.ZodString;
|
|
174
|
+
}, "strip", z.ZodTypeAny, {
|
|
175
|
+
status: string;
|
|
176
|
+
publicKey: string;
|
|
177
|
+
}, {
|
|
178
|
+
status: string;
|
|
179
|
+
publicKey: string;
|
|
180
|
+
}>;
|
|
181
|
+
declare const EvaluateResponse: z.ZodObject<{
|
|
182
|
+
intent: z.ZodObject<{
|
|
183
|
+
id: z.ZodString;
|
|
184
|
+
agentId: z.ZodString;
|
|
185
|
+
vendor: z.ZodObject<{
|
|
186
|
+
host: z.ZodString;
|
|
187
|
+
address: z.ZodString;
|
|
188
|
+
erc8004Id: z.ZodOptional<z.ZodString>;
|
|
189
|
+
}, "strip", z.ZodTypeAny, {
|
|
190
|
+
address: string;
|
|
191
|
+
host: string;
|
|
192
|
+
erc8004Id?: string | undefined;
|
|
193
|
+
}, {
|
|
194
|
+
address: string;
|
|
195
|
+
host: string;
|
|
196
|
+
erc8004Id?: string | undefined;
|
|
197
|
+
}>;
|
|
198
|
+
resource: z.ZodString;
|
|
199
|
+
amount: z.ZodString;
|
|
200
|
+
asset: z.ZodEnum<["USDC", "USDT", "EURC"]>;
|
|
201
|
+
chain: z.ZodEnum<["base", "solana", "polygon", "bnb"]>;
|
|
202
|
+
taskContext: z.ZodDefault<z.ZodObject<{
|
|
203
|
+
taskId: z.ZodOptional<z.ZodString>;
|
|
204
|
+
parentRunId: z.ZodOptional<z.ZodString>;
|
|
205
|
+
purpose: z.ZodOptional<z.ZodString>;
|
|
206
|
+
}, "strip", z.ZodTypeAny, {
|
|
207
|
+
taskId?: string | undefined;
|
|
208
|
+
parentRunId?: string | undefined;
|
|
209
|
+
purpose?: string | undefined;
|
|
210
|
+
}, {
|
|
211
|
+
taskId?: string | undefined;
|
|
212
|
+
parentRunId?: string | undefined;
|
|
213
|
+
purpose?: string | undefined;
|
|
214
|
+
}>>;
|
|
215
|
+
nonce: z.ZodString;
|
|
216
|
+
createdAt: z.ZodDate;
|
|
217
|
+
}, "strip", z.ZodTypeAny, {
|
|
218
|
+
chain: "base" | "solana" | "polygon" | "bnb";
|
|
219
|
+
id: string;
|
|
220
|
+
createdAt: Date;
|
|
221
|
+
agentId: string;
|
|
222
|
+
vendor: {
|
|
223
|
+
address: string;
|
|
224
|
+
host: string;
|
|
225
|
+
erc8004Id?: string | undefined;
|
|
226
|
+
};
|
|
227
|
+
resource: string;
|
|
228
|
+
amount: string;
|
|
229
|
+
asset: "USDC" | "USDT" | "EURC";
|
|
230
|
+
taskContext: {
|
|
231
|
+
taskId?: string | undefined;
|
|
232
|
+
parentRunId?: string | undefined;
|
|
233
|
+
purpose?: string | undefined;
|
|
234
|
+
};
|
|
235
|
+
nonce: string;
|
|
236
|
+
}, {
|
|
237
|
+
chain: "base" | "solana" | "polygon" | "bnb";
|
|
238
|
+
id: string;
|
|
239
|
+
createdAt: Date;
|
|
240
|
+
agentId: string;
|
|
241
|
+
vendor: {
|
|
242
|
+
address: string;
|
|
243
|
+
host: string;
|
|
244
|
+
erc8004Id?: string | undefined;
|
|
245
|
+
};
|
|
246
|
+
resource: string;
|
|
247
|
+
amount: string;
|
|
248
|
+
asset: "USDC" | "USDT" | "EURC";
|
|
249
|
+
nonce: string;
|
|
250
|
+
taskContext?: {
|
|
251
|
+
taskId?: string | undefined;
|
|
252
|
+
parentRunId?: string | undefined;
|
|
253
|
+
purpose?: string | undefined;
|
|
254
|
+
} | undefined;
|
|
255
|
+
}>;
|
|
256
|
+
decision: z.ZodObject<{
|
|
257
|
+
id: z.ZodString;
|
|
258
|
+
intentId: z.ZodString;
|
|
259
|
+
intentHash: z.ZodString;
|
|
260
|
+
outcome: z.ZodEnum<["allow", "deny", "escalate"]>;
|
|
261
|
+
matchedRules: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
262
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
263
|
+
policyId: z.ZodString;
|
|
264
|
+
policyVersion: z.ZodString;
|
|
265
|
+
prevHash: z.ZodString;
|
|
266
|
+
hash: z.ZodString;
|
|
267
|
+
signature: z.ZodString;
|
|
268
|
+
latencyMs: z.ZodNumber;
|
|
269
|
+
decidedAt: z.ZodDate;
|
|
270
|
+
}, "strip", z.ZodTypeAny, {
|
|
271
|
+
id: string;
|
|
272
|
+
intentId: string;
|
|
273
|
+
intentHash: string;
|
|
274
|
+
outcome: "allow" | "deny" | "escalate";
|
|
275
|
+
matchedRules: string[];
|
|
276
|
+
policyId: string;
|
|
277
|
+
policyVersion: string;
|
|
278
|
+
prevHash: string;
|
|
279
|
+
hash: string;
|
|
280
|
+
signature: string;
|
|
281
|
+
latencyMs: number;
|
|
282
|
+
decidedAt: Date;
|
|
283
|
+
reason?: string | undefined;
|
|
284
|
+
}, {
|
|
285
|
+
id: string;
|
|
286
|
+
intentId: string;
|
|
287
|
+
intentHash: string;
|
|
288
|
+
outcome: "allow" | "deny" | "escalate";
|
|
289
|
+
policyId: string;
|
|
290
|
+
policyVersion: string;
|
|
291
|
+
prevHash: string;
|
|
292
|
+
hash: string;
|
|
293
|
+
signature: string;
|
|
294
|
+
latencyMs: number;
|
|
295
|
+
decidedAt: Date;
|
|
296
|
+
matchedRules?: string[] | undefined;
|
|
297
|
+
reason?: string | undefined;
|
|
298
|
+
}>;
|
|
299
|
+
}, "strip", z.ZodTypeAny, {
|
|
300
|
+
intent: {
|
|
301
|
+
chain: "base" | "solana" | "polygon" | "bnb";
|
|
302
|
+
id: string;
|
|
303
|
+
createdAt: Date;
|
|
304
|
+
agentId: string;
|
|
305
|
+
vendor: {
|
|
306
|
+
address: string;
|
|
307
|
+
host: string;
|
|
308
|
+
erc8004Id?: string | undefined;
|
|
309
|
+
};
|
|
310
|
+
resource: string;
|
|
311
|
+
amount: string;
|
|
312
|
+
asset: "USDC" | "USDT" | "EURC";
|
|
313
|
+
taskContext: {
|
|
314
|
+
taskId?: string | undefined;
|
|
315
|
+
parentRunId?: string | undefined;
|
|
316
|
+
purpose?: string | undefined;
|
|
317
|
+
};
|
|
318
|
+
nonce: string;
|
|
319
|
+
};
|
|
320
|
+
decision: {
|
|
321
|
+
id: string;
|
|
322
|
+
intentId: string;
|
|
323
|
+
intentHash: string;
|
|
324
|
+
outcome: "allow" | "deny" | "escalate";
|
|
325
|
+
matchedRules: string[];
|
|
326
|
+
policyId: string;
|
|
327
|
+
policyVersion: string;
|
|
328
|
+
prevHash: string;
|
|
329
|
+
hash: string;
|
|
330
|
+
signature: string;
|
|
331
|
+
latencyMs: number;
|
|
332
|
+
decidedAt: Date;
|
|
333
|
+
reason?: string | undefined;
|
|
334
|
+
};
|
|
335
|
+
}, {
|
|
336
|
+
intent: {
|
|
337
|
+
chain: "base" | "solana" | "polygon" | "bnb";
|
|
338
|
+
id: string;
|
|
339
|
+
createdAt: Date;
|
|
340
|
+
agentId: string;
|
|
341
|
+
vendor: {
|
|
342
|
+
address: string;
|
|
343
|
+
host: string;
|
|
344
|
+
erc8004Id?: string | undefined;
|
|
345
|
+
};
|
|
346
|
+
resource: string;
|
|
347
|
+
amount: string;
|
|
348
|
+
asset: "USDC" | "USDT" | "EURC";
|
|
349
|
+
nonce: string;
|
|
350
|
+
taskContext?: {
|
|
351
|
+
taskId?: string | undefined;
|
|
352
|
+
parentRunId?: string | undefined;
|
|
353
|
+
purpose?: string | undefined;
|
|
354
|
+
} | undefined;
|
|
355
|
+
};
|
|
356
|
+
decision: {
|
|
357
|
+
id: string;
|
|
358
|
+
intentId: string;
|
|
359
|
+
intentHash: string;
|
|
360
|
+
outcome: "allow" | "deny" | "escalate";
|
|
361
|
+
policyId: string;
|
|
362
|
+
policyVersion: string;
|
|
363
|
+
prevHash: string;
|
|
364
|
+
hash: string;
|
|
365
|
+
signature: string;
|
|
366
|
+
latencyMs: number;
|
|
367
|
+
decidedAt: Date;
|
|
368
|
+
matchedRules?: string[] | undefined;
|
|
369
|
+
reason?: string | undefined;
|
|
370
|
+
};
|
|
371
|
+
}>;
|
|
372
|
+
type EvaluateResponse = z.infer<typeof EvaluateResponse>;
|
|
373
|
+
interface EngineClientOptions {
|
|
374
|
+
/** Base URL of the policy engine, e.g. "http://localhost:8787". */
|
|
375
|
+
baseUrl: string;
|
|
376
|
+
/** Override the transport (tests, custom agents). Defaults to global fetch. */
|
|
377
|
+
fetch?: FetchLike;
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Thin typed client for the policy-engine HTTP API. Every response is parsed
|
|
381
|
+
* through the @reinconsole/core schemas, so wire drift fails loudly at the boundary.
|
|
382
|
+
*/
|
|
383
|
+
declare class EngineClient {
|
|
384
|
+
private readonly baseUrl;
|
|
385
|
+
private readonly fetchImpl;
|
|
386
|
+
constructor(options: EngineClientOptions);
|
|
387
|
+
private request;
|
|
388
|
+
health(): Promise<z.infer<typeof Health>>;
|
|
389
|
+
registerAgent(input: {
|
|
390
|
+
orgId: string;
|
|
391
|
+
name: string;
|
|
392
|
+
erc8004Id?: string;
|
|
393
|
+
wallets?: Agent['wallets'];
|
|
394
|
+
}): Promise<Agent>;
|
|
395
|
+
listAgents(): Promise<Agent[]>;
|
|
396
|
+
freeze(agentId: string): Promise<void>;
|
|
397
|
+
unfreeze(agentId: string): Promise<void>;
|
|
398
|
+
addPolicy(policy: z.input<typeof Policy>): Promise<Policy>;
|
|
399
|
+
listPolicies(): Promise<Policy[]>;
|
|
400
|
+
/** The hot path: submit an intent, get the normalized intent + signed decision. */
|
|
401
|
+
evaluate(submission: IntentSubmission): Promise<EvaluateResponse>;
|
|
402
|
+
decisions(): Promise<Decision[]>;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* Builds the `X-PAYMENT` header for an allowed intent. Mock payers and the
|
|
407
|
+
* local EIP-3009 payer ignore the decision; the session-key signer tier
|
|
408
|
+
* requires it — the {intent, decision} pair is the engine-signed voucher the
|
|
409
|
+
* signer verifies before any key is put to work.
|
|
410
|
+
*/
|
|
411
|
+
type Payer = (requirement: PaymentRequirement, intent: PaymentIntent, decision: Decision) => string | Promise<string>;
|
|
412
|
+
interface GuardOptions {
|
|
413
|
+
/** Policy engine base URL, e.g. "http://localhost:8787". */
|
|
414
|
+
engineUrl: string;
|
|
415
|
+
/** The agent this guard speaks for (must be registered with the engine). */
|
|
416
|
+
agentId: string;
|
|
417
|
+
/** Base fetch the guard wraps by default (vendor-facing). Defaults to global fetch. */
|
|
418
|
+
fetch?: FetchLike;
|
|
419
|
+
/** Transport for talking to the policy engine. Defaults to global fetch. */
|
|
420
|
+
engineFetch?: FetchLike;
|
|
421
|
+
/** Task context attached to every intent unless overridden via withTask(). */
|
|
422
|
+
taskContext?: TaskContext;
|
|
423
|
+
/**
|
|
424
|
+
* What a blocked payment looks like to the caller: 'throw' (default) raises
|
|
425
|
+
* PaymentBlockedError; 'respond' returns a synthetic 402 JSON response, for
|
|
426
|
+
* agent loops that prefer inspecting responses over catching.
|
|
427
|
+
*/
|
|
428
|
+
onBlocked?: 'throw' | 'respond';
|
|
429
|
+
/** If set, the guard settles allowed payments itself (pay + retry). */
|
|
430
|
+
payer?: Payer;
|
|
431
|
+
/** Extra token-address -> symbol mappings for asset resolution. */
|
|
432
|
+
assetAddresses?: Record<string, Asset>;
|
|
433
|
+
/** Called once per receipt, as it is recorded. */
|
|
434
|
+
onReceipt?: (receipt: Receipt) => void;
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* The Rein guard: wrap an agent's fetch once, and every x402 paywall it hits
|
|
438
|
+
* is policy-checked before any payment exists, with a receipt either way.
|
|
439
|
+
*
|
|
440
|
+
* Layering: the guard wraps the BASE fetch, underneath any x402 payment
|
|
441
|
+
* library. The first (unpaid) request surfaces the 402; the guard evaluates
|
|
442
|
+
* it and either blocks — so the payment layer never sees the paywall — or
|
|
443
|
+
* releases the 402 upward. The payment layer's `X-PAYMENT` retry then flows
|
|
444
|
+
* back through the guard, which attaches the settlement to the receipt.
|
|
445
|
+
* Alternatively, pass a `payer` and the guard completes the payment itself.
|
|
446
|
+
*/
|
|
447
|
+
declare class Guard {
|
|
448
|
+
readonly client: EngineClient;
|
|
449
|
+
private readonly options;
|
|
450
|
+
private readonly baseFetch;
|
|
451
|
+
private readonly task;
|
|
452
|
+
private readonly log;
|
|
453
|
+
/** Allowed-but-unsettled receipts awaiting the payment layer's retry, by URL. */
|
|
454
|
+
private readonly pendingByUrl;
|
|
455
|
+
constructor(options: GuardOptions);
|
|
456
|
+
/** Every receipt this guard has recorded, oldest first. */
|
|
457
|
+
receipts(): readonly Receipt[];
|
|
458
|
+
/** Run `fn` with a task context attached to every intent submitted inside it. */
|
|
459
|
+
withTask<T>(context: TaskContext, fn: () => T): T;
|
|
460
|
+
/**
|
|
461
|
+
* The one-liner: returns a fetch-compatible function that enforces policy on
|
|
462
|
+
* every x402 paywall. Wraps the guard's base fetch unless one is passed.
|
|
463
|
+
*/
|
|
464
|
+
wrap(fetchImpl?: FetchLike): FetchLike;
|
|
465
|
+
private record;
|
|
466
|
+
private settlePending;
|
|
467
|
+
}
|
|
468
|
+
/** Convenience factory mirroring the docs: `const guard = createGuard({...})`. */
|
|
469
|
+
declare function createGuard(options: GuardOptions): Guard;
|
|
470
|
+
|
|
471
|
+
/** Base class for everything the SDK throws, so callers can catch broadly. */
|
|
472
|
+
declare class ReinError extends Error {
|
|
473
|
+
constructor(message: string);
|
|
474
|
+
}
|
|
475
|
+
/** The policy engine answered with a non-2xx status. */
|
|
476
|
+
declare class EngineError extends ReinError {
|
|
477
|
+
readonly status: number;
|
|
478
|
+
readonly body: unknown;
|
|
479
|
+
constructor(status: number, body: unknown, message?: string);
|
|
480
|
+
}
|
|
481
|
+
/**
|
|
482
|
+
* The engine evaluated the intent and did NOT allow it (deny or escalate —
|
|
483
|
+
* v0.1 blocks both; escalation approval flows land later). The payment was
|
|
484
|
+
* never constructed, so no funds moved. Carries the full evidence trail.
|
|
485
|
+
*/
|
|
486
|
+
declare class PaymentBlockedError extends ReinError {
|
|
487
|
+
readonly intent: PaymentIntent;
|
|
488
|
+
readonly decision: Decision;
|
|
489
|
+
readonly receipt: Receipt;
|
|
490
|
+
constructor(intent: PaymentIntent, decision: Decision, receipt: Receipt);
|
|
491
|
+
}
|
|
492
|
+
/**
|
|
493
|
+
* The vendor's 402 was x402-shaped but offered no requirement the guard can
|
|
494
|
+
* govern (unknown scheme/network/asset). The guard fails closed rather than
|
|
495
|
+
* letting an ungoverned payment through.
|
|
496
|
+
*/
|
|
497
|
+
declare class UnsupportedRequirementError extends ReinError {
|
|
498
|
+
readonly url: string;
|
|
499
|
+
constructor(url: string);
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
export { EngineClient, type EngineClientOptions, EngineError, EvaluateResponse, type FetchLike, Guard, type GuardOptions, type IntentSubmission, type Payer, PaymentBlockedError, PaymentRequired, PaymentRequirement, ReinError, type ResolvedRequirement, UnsupportedRequirementError, atomicToDecimal, createGuard, decimalToAtomic, networkToChain, requirementDecimals, resolveAsset, selectRequirement, toIntentSubmission };
|