@belticlabs/agent-risk-sdk 0.6.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/dist/ai/index.d.ts +2 -2
- package/dist/ai/index.js +16 -21
- package/dist/chunk-DI3LZR65.js +103 -0
- package/dist/{chunk-ZMPKY7AX.js → chunk-JGVVQUXQ.js} +1 -2
- package/dist/{chunk-77D74TWX.js → chunk-MWXXX35V.js} +53 -23
- package/dist/chunk-P3VZNH5W.js +57 -0
- package/dist/chunk-PDE55ZZV.js +556 -0
- package/dist/client-DFZL4Pt3.d.ts +298 -0
- package/dist/{index-IfY4XCvJ.d.ts → index-CBUSXzgG.d.ts} +177 -138
- package/dist/index.d.ts +3 -3
- package/dist/index.js +562 -171
- package/dist/protocol/index.d.ts +51 -30
- package/dist/protocol/index.js +54 -529
- package/dist/{session-Dcof4UIn.d.ts → session-DTIzd1EQ.d.ts} +119 -44
- package/dist/x402/hono.d.ts +3 -4
- package/dist/x402/hono.js +4 -5
- package/dist/x402/index.d.ts +7 -77
- package/dist/x402/index.js +8 -71
- package/package.json +1 -1
- package/dist/adapter-AjCgj-KM.d.ts +0 -6
- package/dist/chunk-FQDHFTVR.js +0 -29
- package/dist/chunk-IUWC6HT5.js +0 -144
- package/dist/chunk-M4I3FGZG.js +0 -13
- package/dist/client-CgCjOrRP.d.ts +0 -65
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
import { J as JsonValue, e as CatalogQuery, d as CatalogOutput, N as JsonObject, W as PaymentSummary, o as DeclaredIntent } from './index-CBUSXzgG.js';
|
|
2
|
+
import { A as ApiClient, S as Session, b as SessionOptions, a as Decision } from './session-DTIzd1EQ.js';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* One way to pay, as the seller wrote it: the fields a wallet needs are
|
|
7
|
+
* checked, everything else (`extra`, the scheme's own parts) is kept so the
|
|
8
|
+
* chosen entry can be echoed back as `accepted`.
|
|
9
|
+
*/
|
|
10
|
+
declare const Requirement: z.ZodObject<{
|
|
11
|
+
scheme: z.ZodString;
|
|
12
|
+
network: z.ZodString;
|
|
13
|
+
asset: z.ZodString;
|
|
14
|
+
amount: z.ZodString;
|
|
15
|
+
payTo: z.ZodString;
|
|
16
|
+
maxTimeoutSeconds: z.ZodOptional<z.ZodNumber>;
|
|
17
|
+
}, z.core.$loose>;
|
|
18
|
+
type X402Requirement = z.infer<typeof Requirement>;
|
|
19
|
+
/** The whole challenge a quote answers: payment options, the resource, and the request the seller expects (`bazaar` extension). */
|
|
20
|
+
declare const Challenge: z.ZodPipe<z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<unknown, string>>, z.ZodObject<{
|
|
21
|
+
x402Version: z.ZodLiteral<2>;
|
|
22
|
+
accepts: z.ZodArray<z.ZodUnknown>;
|
|
23
|
+
resource: z.ZodCatch<z.ZodOptional<z.ZodObject<{
|
|
24
|
+
url: z.ZodString;
|
|
25
|
+
description: z.ZodCatch<z.ZodOptional<z.ZodString>>;
|
|
26
|
+
}, z.core.$loose>>>;
|
|
27
|
+
extensions: z.ZodCatch<z.ZodOptional<z.ZodObject<{
|
|
28
|
+
bazaar: z.ZodCatch<z.ZodOptional<z.ZodObject<{
|
|
29
|
+
info: z.ZodCatch<z.ZodOptional<z.ZodObject<{
|
|
30
|
+
input: z.ZodCatch<z.ZodOptional<z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>>>;
|
|
31
|
+
}, z.core.$loose>>>;
|
|
32
|
+
schema: z.ZodCatch<z.ZodOptional<z.ZodObject<{
|
|
33
|
+
properties: z.ZodCatch<z.ZodOptional<z.ZodObject<{
|
|
34
|
+
input: z.ZodCatch<z.ZodOptional<z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>>>;
|
|
35
|
+
}, z.core.$loose>>>;
|
|
36
|
+
}, z.core.$loose>>>;
|
|
37
|
+
}, z.core.$loose>>>;
|
|
38
|
+
}, z.core.$loose>>>;
|
|
39
|
+
}, z.core.$loose>>, z.ZodTransform<{
|
|
40
|
+
resource: {
|
|
41
|
+
url: string;
|
|
42
|
+
description: string | undefined;
|
|
43
|
+
} | null;
|
|
44
|
+
accepts: {
|
|
45
|
+
[x: string]: unknown;
|
|
46
|
+
scheme: string;
|
|
47
|
+
network: string;
|
|
48
|
+
asset: string;
|
|
49
|
+
amount: string;
|
|
50
|
+
payTo: string;
|
|
51
|
+
maxTimeoutSeconds?: number | undefined;
|
|
52
|
+
}[];
|
|
53
|
+
input: string | number | boolean | JsonValue[] | {
|
|
54
|
+
[key: string]: JsonValue;
|
|
55
|
+
} | null;
|
|
56
|
+
inputSchema: string | number | boolean | JsonValue[] | {
|
|
57
|
+
[key: string]: JsonValue;
|
|
58
|
+
} | null;
|
|
59
|
+
}, {
|
|
60
|
+
[x: string]: unknown;
|
|
61
|
+
x402Version: 2;
|
|
62
|
+
accepts: unknown[];
|
|
63
|
+
resource?: {
|
|
64
|
+
[x: string]: unknown;
|
|
65
|
+
url: string;
|
|
66
|
+
description?: string | undefined;
|
|
67
|
+
} | undefined;
|
|
68
|
+
extensions?: {
|
|
69
|
+
[x: string]: unknown;
|
|
70
|
+
bazaar?: {
|
|
71
|
+
[x: string]: unknown;
|
|
72
|
+
info?: {
|
|
73
|
+
[x: string]: unknown;
|
|
74
|
+
input?: JsonValue | undefined;
|
|
75
|
+
} | undefined;
|
|
76
|
+
schema?: {
|
|
77
|
+
[x: string]: unknown;
|
|
78
|
+
properties?: {
|
|
79
|
+
[x: string]: unknown;
|
|
80
|
+
input?: JsonValue | undefined;
|
|
81
|
+
} | undefined;
|
|
82
|
+
} | undefined;
|
|
83
|
+
} | undefined;
|
|
84
|
+
} | undefined;
|
|
85
|
+
}>>;
|
|
86
|
+
type X402Challenge = z.output<typeof Challenge>;
|
|
87
|
+
/** The seller's settlement of a paid request (`PAYMENT-RESPONSE`). */
|
|
88
|
+
declare const Settlement: z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<unknown, string>>, z.ZodObject<{
|
|
89
|
+
success: z.ZodBoolean;
|
|
90
|
+
transaction: z.ZodCatch<z.ZodOptional<z.ZodString>>;
|
|
91
|
+
network: z.ZodCatch<z.ZodOptional<z.ZodString>>;
|
|
92
|
+
payer: z.ZodCatch<z.ZodOptional<z.ZodString>>;
|
|
93
|
+
errorReason: z.ZodCatch<z.ZodOptional<z.ZodString>>;
|
|
94
|
+
errorMessage: z.ZodCatch<z.ZodOptional<z.ZodString>>;
|
|
95
|
+
}, z.core.$loose>>;
|
|
96
|
+
type X402Settlement = z.output<typeof Settlement>;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* x402 artifacts → protocol moments (Fraud SDK RFC › Protocol Adapter —
|
|
100
|
+
* x402). The moment is normalized (payee, amount, payer) so both sides of
|
|
101
|
+
* a purchase compare; the artifact travels whole in `raw`. For x402 the
|
|
102
|
+
* currency is `<network>/<asset>` (GAP-49) and the value is the atomic
|
|
103
|
+
* amount as the protocol carries it — `beltic.x402.summary` gives a buyer
|
|
104
|
+
* the same normalization for the payment it is about to evaluate, so what
|
|
105
|
+
* it asks about and what the fetch records are one and the same.
|
|
106
|
+
*/
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* The minimum an `accepts` entry needs to become a moment; unknown parts
|
|
110
|
+
* are named, never dropped.
|
|
111
|
+
*/
|
|
112
|
+
interface AcceptsLike {
|
|
113
|
+
payTo?: string | undefined;
|
|
114
|
+
amount?: string | undefined;
|
|
115
|
+
network?: string | undefined;
|
|
116
|
+
asset?: string | undefined;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* x402 on the buyer half, as `beltic.x402` (Fraud SDK RFC › Protocol
|
|
121
|
+
* Adapter — x402):
|
|
122
|
+
*
|
|
123
|
+
* catalog where to buy: the platform's live search of public x402
|
|
124
|
+
* catalogs (GAP-90)
|
|
125
|
+
* fetch the paying fetch, observed. It sits *inside* the agent's
|
|
126
|
+
* paying fetch, so it sees the 402 → `payment.requested` and the
|
|
127
|
+
* retry carrying the payment → `payment.presented`, into which
|
|
128
|
+
* it injects the session binding (GAP-30). Before a request that
|
|
129
|
+
* presents payment leaves, the session's evidence is flushed: the
|
|
130
|
+
* seller evaluates as soon as it sees the payment (GAP-66). It
|
|
131
|
+
* never pays and never decides.
|
|
132
|
+
* quote the price of a request before paying it: the same request
|
|
133
|
+
* through `fetch` (so the 402 is on record), its challenge read —
|
|
134
|
+
* payment options, resource, the request the seller expects
|
|
135
|
+
* pay the same request again, carrying the payment the wallet
|
|
136
|
+
* signed for the chosen option, and the settlement it answered.
|
|
137
|
+
* Signing is the wallet's: the SDK never holds a key
|
|
138
|
+
* summary an `accepts` entry as the payment `session.decide` takes
|
|
139
|
+
* intent a mandate for x402 spend, its cap in the rail's currency
|
|
140
|
+
*
|
|
141
|
+
* Only x402 v2 is read (GAP-72), and nothing here loads `@x402/*`: a buyer
|
|
142
|
+
* is observed without installing it. The seller half is `attachX402` in
|
|
143
|
+
* `/x402` and the middleware in `/hono`.
|
|
144
|
+
*/
|
|
145
|
+
|
|
146
|
+
/** What `catalog` searches for: `q` is required, `limit` defaults to 8 on the platform (1..20). */
|
|
147
|
+
type CatalogSearch = Omit<CatalogQuery, 'limit'> & {
|
|
148
|
+
limit?: number | undefined;
|
|
149
|
+
};
|
|
150
|
+
/** The request a paid resource is called with; `quote` and the payment send the same one. */
|
|
151
|
+
interface X402Request {
|
|
152
|
+
/** `GET` without a body, `POST` with one, unless given. */
|
|
153
|
+
method?: string | undefined;
|
|
154
|
+
/** Sent as JSON. */
|
|
155
|
+
body?: JsonValue | undefined;
|
|
156
|
+
}
|
|
157
|
+
interface X402Quote {
|
|
158
|
+
/** The status the resource answered the unpaid request with. */
|
|
159
|
+
status: number;
|
|
160
|
+
/** Its v2 challenge when it answered 402 with one; null when it asked for nothing or in a form this does not read. */
|
|
161
|
+
challenge: X402Challenge | null;
|
|
162
|
+
}
|
|
163
|
+
/** A payment the wallet signed: the option it accepted, as the challenge listed it, and the scheme's payload. */
|
|
164
|
+
interface X402Signed {
|
|
165
|
+
accepted: X402Requirement;
|
|
166
|
+
/** Scheme-specific, e.g. `exact` on EVM: `{ authorization, signature }` (EIP-3009). */
|
|
167
|
+
payload: JsonObject;
|
|
168
|
+
}
|
|
169
|
+
interface X402Payment {
|
|
170
|
+
/** The resource's answer to the paid request; its body is unread. */
|
|
171
|
+
response: Response;
|
|
172
|
+
/** The seller's `PAYMENT-RESPONSE`, when it sent one. */
|
|
173
|
+
settlement: X402Settlement | null;
|
|
174
|
+
}
|
|
175
|
+
interface X402IntentInput {
|
|
176
|
+
mandate: string;
|
|
177
|
+
network: string;
|
|
178
|
+
asset: string;
|
|
179
|
+
/** Atomic units of `asset`, as x402 carries amounts — a decimal string or a bigint, never a float. */
|
|
180
|
+
maxAmount: string | bigint;
|
|
181
|
+
validUntil: string | Date;
|
|
182
|
+
merchantAllowlist?: string[] | undefined;
|
|
183
|
+
}
|
|
184
|
+
declare class X402 {
|
|
185
|
+
private readonly api;
|
|
186
|
+
constructor(api: ApiClient);
|
|
187
|
+
/**
|
|
188
|
+
* x402-payable APIs matching `q`, grouped by vendor, as the platform finds
|
|
189
|
+
* them live in public catalogs (GAP-90); with `network`, only what can be
|
|
190
|
+
* paid there. `sources` says which catalogs answered. Null when the
|
|
191
|
+
* platform could not be reached (GAP-70); a rejected query throws.
|
|
192
|
+
*/
|
|
193
|
+
catalog(search: CatalogSearch): Promise<CatalogOutput | null>;
|
|
194
|
+
/**
|
|
195
|
+
* A fetch bound to `session` that records what x402 crosses it. A request
|
|
196
|
+
* made while the session has no stream (the platform could not open one,
|
|
197
|
+
* GAP-70) goes through unrecorded.
|
|
198
|
+
*/
|
|
199
|
+
fetch(session: Session): typeof globalThis.fetch;
|
|
200
|
+
/** The unpaid request, sent as it will be paid, and the challenge it answered. */
|
|
201
|
+
quote(session: Session, url: string, request?: X402Request): Promise<X402Quote>;
|
|
202
|
+
/**
|
|
203
|
+
* The request, sent as it was quoted, carrying `signed` as an x402 v2
|
|
204
|
+
* `PAYMENT-SIGNATURE` through `fetch` — so the presentation is recorded,
|
|
205
|
+
* bound to the session and flushed before it leaves (GAP-66). What the
|
|
206
|
+
* seller settled is read, not recorded (GAP-77).
|
|
207
|
+
*/
|
|
208
|
+
pay(session: Session, url: string, signed: X402Signed, request?: X402Request): Promise<X402Payment>;
|
|
209
|
+
/** An `accepts` entry as the payment `session.decide` takes — the normalization the recorded moments use. */
|
|
210
|
+
summary(accepts: AcceptsLike | undefined, opts?: {
|
|
211
|
+
payer?: string | undefined;
|
|
212
|
+
}): PaymentSummary;
|
|
213
|
+
/**
|
|
214
|
+
* The declared intent for an x402 mandate (Fraud SDK RFC › Session ›
|
|
215
|
+
* `intent.declared`). The cap must be in the currency the rail's moments
|
|
216
|
+
* carry — `<network>/<asset>`, atomic units (GAP-49) — or the platform's
|
|
217
|
+
* spend detectors compare two currencies and never meet.
|
|
218
|
+
*/
|
|
219
|
+
intent(input: X402IntentInput): DeclaredIntent;
|
|
220
|
+
/** The request as `quote` and `pay` send it: `GET` bare, `POST` with a JSON body, unless told otherwise. */
|
|
221
|
+
private static init;
|
|
222
|
+
/** An x402 header value: base64 of the JSON. */
|
|
223
|
+
private static encode;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* One SDK, two halves (Fraud SDK RFC › Summary). `Beltic` is the single
|
|
228
|
+
* client: `session` for the buyer half, `evaluate` for whichever half is
|
|
229
|
+
* about to let a payment through, and `x402` for what the buyer does on
|
|
230
|
+
* that rail — find an API (`catalog`, GAP-90), observe the paying fetch
|
|
231
|
+
* (`fetch`), read a price and pay it (`quote`, `pay`), shape what it asks
|
|
232
|
+
* about (`summary`, `intent`). Integrations that pull an optional peer are plain functions
|
|
233
|
+
* behind subpath exports:
|
|
234
|
+
*
|
|
235
|
+
* @belticlabs/agent-risk-sdk/ai → middleware(session), wrapTools(session, …)
|
|
236
|
+
* @belticlabs/agent-risk-sdk/x402 → attachX402(beltic, …) (seller)
|
|
237
|
+
* @belticlabs/agent-risk-sdk/hono → belticPaymentMiddleware(beltic, …) (seller)
|
|
238
|
+
*
|
|
239
|
+
* Neither half decides risk locally: verdicts are platform-side.
|
|
240
|
+
*
|
|
241
|
+
* A client is configured or it is not constructed — `Beltic.fromEnv()`
|
|
242
|
+
* reads `BELTIC_*`, and there is no disabled client (GAP-78). Evidence is
|
|
243
|
+
* a side channel of the work it observes, so a platform outage never
|
|
244
|
+
* throws into that work (GAP-70): the transport waits it out, `session`
|
|
245
|
+
* runs without a stream, `evaluate` answers `Decision.absent()` — never an
|
|
246
|
+
* invented verdict — and `x402.catalog` answers `null`. What the platform
|
|
247
|
+
* *rejects* (a 4xx, a forked chain) is the client's fault and throws.
|
|
248
|
+
*/
|
|
249
|
+
|
|
250
|
+
declare const SDK_VERSION = "0.8.0";
|
|
251
|
+
interface BelticOptions {
|
|
252
|
+
apiKey: string;
|
|
253
|
+
baseUrl: string;
|
|
254
|
+
/** The agent's 32-byte Ed25519 seed as 64 hex — the buyer half. Without it, `session` is unavailable; the seller half works. */
|
|
255
|
+
agentSeed?: string | undefined;
|
|
256
|
+
}
|
|
257
|
+
declare class Beltic {
|
|
258
|
+
/** x402 for the buyer: `catalog`, `fetch`, `quote`, `pay`, `summary`, `intent`. */
|
|
259
|
+
readonly x402: X402;
|
|
260
|
+
private readonly api;
|
|
261
|
+
private readonly transport;
|
|
262
|
+
/** Open handles by conversation id (GAP-84). */
|
|
263
|
+
private readonly sessions;
|
|
264
|
+
/**
|
|
265
|
+
* The client the environment describes: `BELTIC_API_KEY` and
|
|
266
|
+
* `BELTIC_BASE_URL`, both required, and `BELTIC_AGENT_SEED` (64 hex) for
|
|
267
|
+
* the buyer half. A missing required variable is a configuration error,
|
|
268
|
+
* thrown (GAP-78).
|
|
269
|
+
*/
|
|
270
|
+
static fromEnv(env?: Record<string, string | undefined>): Beltic;
|
|
271
|
+
constructor(opts: BelticOptions);
|
|
272
|
+
/**
|
|
273
|
+
* A conversation: new without an id, resumed with one — the id `session.id()`
|
|
274
|
+
* answered in this or any earlier process (GAP-84). One handle per
|
|
275
|
+
* conversation in-process until it closes; the options count when a
|
|
276
|
+
* session is opened. See `Session`.
|
|
277
|
+
*/
|
|
278
|
+
session(id?: string, opts?: SessionOptions): Session;
|
|
279
|
+
/**
|
|
280
|
+
* The platform's verdict on a payment — the seller's before it verifies,
|
|
281
|
+
* the buyer's before it presents (Fraud SDK RFC › Evaluation Client).
|
|
282
|
+
* Read-your-writes: the session's buffered evidence is flushed first so
|
|
283
|
+
* the platform judges what the caller already saw (GAP-16/88). With a `callId`
|
|
284
|
+
* the platform answers the decision already taken for that call anywhere
|
|
285
|
+
* in the conversation (GAP-84). Absent when the platform could not be
|
|
286
|
+
* reached (GAP-70).
|
|
287
|
+
*/
|
|
288
|
+
evaluate(sessionId: string, payment: PaymentSummary, opts?: {
|
|
289
|
+
callId?: string | undefined;
|
|
290
|
+
}): Promise<Decision>;
|
|
291
|
+
/** Send everything buffered now — every session's — and wait for that attempt. */
|
|
292
|
+
flush(): Promise<void>;
|
|
293
|
+
shutdown(): Promise<void>;
|
|
294
|
+
/** `process.env` where there is a `process` (Node); `{}` on workerd, where the shell passes its `env`. */
|
|
295
|
+
private static processEnv;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
export { type AcceptsLike as A, Beltic as B, type CatalogSearch as C, SDK_VERSION as S, X402 as X, type BelticOptions as a, type X402Challenge as b, type X402IntentInput as c, type X402Payment as d, type X402Quote as e, type X402Request as f, type X402Requirement as g, type X402Settlement as h, type X402Signed as i };
|