@belticlabs/agent-risk-sdk 0.3.0 → 0.4.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.
@@ -1,6 +1,6 @@
1
- import { D as Decision } from './verdict-6vCyoAHE.js';
1
+ import { D as Decision } from './verdict-CDAsxktI.js';
2
2
  import { x402ResourceServer, x402HTTPResourceServer } from '@x402/core/server';
3
- import { B as Beltic, n as SessionBorn, a as Session } from './session-DsBWEP8d.js';
3
+ import { B as Beltic, n as SessionBorn, a as Session } from './session-gK51QVAM.js';
4
4
 
5
5
  interface CorrelationContext {
6
6
  path: string;
@@ -1,6 +1,6 @@
1
- import { P as PaymentMomentPayload } from '../verdict-6vCyoAHE.js';
1
+ import { P as PaymentMomentPayload } from '../verdict-CDAsxktI.js';
2
2
  import { LanguageModelMiddleware, Tool, ToolSet } from 'ai';
3
- import { S as SessionSource } from '../session-DsBWEP8d.js';
3
+ import { S as SessionSource } from '../session-gK51QVAM.js';
4
4
  import 'zod';
5
5
 
6
6
  interface PaymentMoments {
package/dist/ai/index.js CHANGED
@@ -2,14 +2,13 @@ import {
2
2
  Sessions,
3
3
  recordCall
4
4
  } from "../chunk-4MG6VNAU.js";
5
- import {
6
- uuidv7
7
- } from "../chunk-X3W2Z5GC.js";
8
- import "../chunk-46QN2KEZ.js";
9
5
  import {
10
6
  toJson,
11
7
  toJsonObject
12
8
  } from "../chunk-FQDHFTVR.js";
9
+ import {
10
+ uuidv7
11
+ } from "../chunk-X3W2Z5GC.js";
13
12
 
14
13
  // src/ai/index.ts
15
14
  var PARAM_KEYS = [
@@ -326,13 +326,6 @@ var EvaluateOutputSchema = z4.strictObject({
326
326
  /** Additive (GAP-21). */
327
327
  decisionId: z4.uuid()
328
328
  });
329
- var AnchorEntrySchema = z4.strictObject({
330
- epoch: z4.string().min(1),
331
- root: Hex64Schema,
332
- sig: z4.string().min(1),
333
- chainRef: z4.string().optional()
334
- });
335
- var AnchorsOutputSchema = z4.strictObject({ entries: z4.array(AnchorEntrySchema) });
336
329
  var CreatePolicyInputSchema = z4.strictObject({ rules: PolicyRulesSchema });
337
330
  var CreatePolicyOutputSchema = z4.strictObject({
338
331
  policyId: z4.uuid(),
@@ -542,8 +535,6 @@ export {
542
535
  EvaluateInputSchema,
543
536
  DecisionSchema,
544
537
  EvaluateOutputSchema,
545
- AnchorEntrySchema,
546
- AnchorsOutputSchema,
547
538
  CreatePolicyInputSchema,
548
539
  CreatePolicyOutputSchema,
549
540
  ApiErrorSchema,
@@ -0,0 +1,177 @@
1
+ import {
2
+ toJsonObject
3
+ } from "./chunk-FQDHFTVR.js";
4
+ import {
5
+ payloadDigest
6
+ } from "./chunk-X3W2Z5GC.js";
7
+
8
+ // src/x402/binding.ts
9
+ var SESSION_EXTENSION = "beltic.sessionId";
10
+ var SESSION_HEADER = "Beltic-Session-Id";
11
+ var DECISION_EXTENSION = "beltic.decisionId";
12
+ function sessionIdOf(extensions) {
13
+ return stringAt(extensions, SESSION_EXTENSION);
14
+ }
15
+ function decisionIdOf(extensions) {
16
+ return stringAt(extensions, DECISION_EXTENSION);
17
+ }
18
+ function stringAt(extensions, key) {
19
+ const v = extensions?.[key];
20
+ return typeof v === "string" && v.length > 0 ? v : null;
21
+ }
22
+
23
+ // src/x402/moments.ts
24
+ function x402Currency(network, asset) {
25
+ return `${network}/${asset}`;
26
+ }
27
+ function x402Summary(accepts, opts = {}) {
28
+ const payer = opts.payer?.toLowerCase();
29
+ return {
30
+ protocol: "x402",
31
+ payee: accepts?.payTo ?? "unknown",
32
+ amount: {
33
+ value: accepts?.amount ?? "0",
34
+ currency: accepts ? x402Currency(accepts.network ?? "unknown", accepts.asset ?? "unknown") : "unknown"
35
+ },
36
+ ...payer ? { payer } : {}
37
+ };
38
+ }
39
+ function fromAccepts(a, artifact, raw, payer) {
40
+ return { ...x402Summary(a, { payer }), artifact, raw };
41
+ }
42
+ function payerOf(payload) {
43
+ const p = payload.payload ?? {};
44
+ const auth = p.authorization;
45
+ const candidates = [
46
+ auth?.from,
47
+ p.from,
48
+ p.payer,
49
+ p.signer,
50
+ p.permit?.owner
51
+ ];
52
+ const hit = candidates.find((c) => typeof c === "string" && c.length > 0);
53
+ return typeof hit === "string" ? hit.toLowerCase() : void 0;
54
+ }
55
+ var x402Moments = {
56
+ /** The 402 challenge as the buyer saw it, from the `PAYMENT-REQUIRED` header. */
57
+ required(required) {
58
+ return fromAccepts(required.accepts?.[0], "http-402", toJsonObject(required));
59
+ },
60
+ /** The requirements the seller's resource server resolved for a request. */
61
+ requirements(req) {
62
+ return fromAccepts(req, "http-402", toJsonObject(req));
63
+ },
64
+ /** A route's static `accepts` config, before any payment header exists. */
65
+ route(route, raw) {
66
+ const accepts = route ?? {};
67
+ const extra = accepts.extra;
68
+ return fromAccepts(
69
+ {
70
+ payTo: typeof accepts.payTo === "string" ? accepts.payTo : "dynamic",
71
+ amount: priceValue(accepts.price),
72
+ network: accepts.network,
73
+ asset: extra?.asset ?? "route"
74
+ },
75
+ "http-402",
76
+ raw
77
+ );
78
+ },
79
+ /** The signed payment the buyer presented, with the requirement it accepted. */
80
+ payload(payload) {
81
+ return fromAccepts(
82
+ payload.accepted,
83
+ "payment-signature",
84
+ toJsonObject(payload),
85
+ payerOf(payload)
86
+ );
87
+ }
88
+ };
89
+ function priceValue(price) {
90
+ if (typeof price === "string") return price.replace(/[^0-9.]/g, "") || "0";
91
+ if (typeof price === "number") return String(price);
92
+ if (price && typeof price === "object" && typeof price.amount === "string")
93
+ return price.amount;
94
+ return "0";
95
+ }
96
+
97
+ // src/x402/adapter.ts
98
+ function attachX402(beltic, server, http, opts = {}) {
99
+ const inFlight = /* @__PURE__ */ new Map();
100
+ const resolveSession = async (bound, ctx) => {
101
+ const key = opts.correlate?.(ctx) ?? null;
102
+ return bound ?? (key ? await beltic.correlation.resolve(key) : null);
103
+ };
104
+ http?.onProtectedRequest(async (ctx, route) => {
105
+ if (ctx.paymentHeader) return;
106
+ const bound = ctx.adapter.getHeader(SESSION_HEADER) ?? ctx.adapter.getHeader(SESSION_HEADER.toLowerCase());
107
+ const sessionId = await resolveSession(bound ?? null, {
108
+ path: ctx.path,
109
+ method: ctx.method,
110
+ header: (n) => ctx.adapter.getHeader(n)
111
+ });
112
+ if (!sessionId) return;
113
+ const session = await beltic.sessions.ensure(sessionId);
114
+ const accepts = Array.isArray(route.accepts) ? route.accepts[0] : route.accepts;
115
+ await session.emit(
116
+ "payment.requested",
117
+ x402Moments.route(accepts, {
118
+ path: ctx.path,
119
+ method: ctx.method,
120
+ route: JSON.parse(JSON.stringify(route))
121
+ })
122
+ );
123
+ });
124
+ server.onBeforeVerify(async (ctx) => {
125
+ const payload = ctx.paymentPayload;
126
+ const requirements = ctx.requirements;
127
+ const sessionId = await resolveSession(sessionIdOf(payload.extensions), {
128
+ path: payload.resource?.url ?? "",
129
+ method: "PAY",
130
+ header: () => void 0
131
+ });
132
+ const session = await beltic.sessions.ensure(sessionId);
133
+ if (session.born === "seller")
134
+ await session.emit("payment.requested", x402Moments.requirements(requirements));
135
+ const presented = x402Moments.payload(payload);
136
+ await session.emit("payment.presented", presented);
137
+ inFlight.set(payloadDigest(payload), session);
138
+ const out = await beltic.evaluate(session.id, presented);
139
+ if (!out) return;
140
+ opts.onDecision?.({
141
+ sessionId: session.id,
142
+ decision: out.decision,
143
+ reasonCodes: out.reasonCodes,
144
+ born: session.born,
145
+ buyerDecisionId: decisionIdOf(payload.extensions)
146
+ });
147
+ if (out.verdict.blocks(beltic.onReview)) {
148
+ return {
149
+ abort: true,
150
+ reason: `BELTIC_${out.verdict.value}`,
151
+ message: out.reasonCodes.join(",")
152
+ };
153
+ }
154
+ return;
155
+ });
156
+ server.onAfterSettle(async (ctx) => {
157
+ const key = payloadDigest(ctx.paymentPayload);
158
+ const session = inFlight.get(key);
159
+ if (!session) return;
160
+ inFlight.delete(key);
161
+ if (ctx.result.success) await session.close("settled", { transaction: ctx.result.transaction });
162
+ });
163
+ return { inFlight };
164
+ }
165
+
166
+ export {
167
+ SESSION_EXTENSION,
168
+ SESSION_HEADER,
169
+ DECISION_EXTENSION,
170
+ sessionIdOf,
171
+ decisionIdOf,
172
+ x402Currency,
173
+ x402Summary,
174
+ payerOf,
175
+ x402Moments,
176
+ attachX402
177
+ };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { a as Session } from './session-DsBWEP8d.js';
2
- export { A as AgentIdentity, b as ApiClient, c as ApiClientOptions, B as Beltic, d as BelticApiError, e as BelticOptions, C as ChainRejectedError, f as CorrelationStore, D as DEFAULT_OPEN_RETRY_MS, g as DEFAULT_TRANSPORT, h as DecideOptions, i as Decision, E as Env, j as Evaluation, H as HumanDecisionInput, M as MemoryCorrelationStore, O as OpenSessionInput, R as RedactFn, k as Run, l as RunOptions, m as SDK_VERSION, n as SessionBorn, S as SessionSource, o as Sessions, p as StartSessionInput, T as ToolCallSpan, q as Transport, r as TransportClosedError, s as TransportOptions, t as createBeltic, u as ephemeralIdentity, v as fileIdentity, w as identityFromSeed } from './session-DsBWEP8d.js';
3
- import { a as PaymentSummary, J as JsonObject, P as PaymentMomentPayload } from './verdict-6vCyoAHE.js';
1
+ import { a as Session } from './session-gK51QVAM.js';
2
+ export { A as AgentIdentity, b as ApiClient, c as ApiClientOptions, B as Beltic, d as BelticApiError, e as BelticOptions, C as ChainRejectedError, f as CorrelationStore, D as DEFAULT_OPEN_RETRY_MS, g as DEFAULT_TRANSPORT, h as DecideOptions, i as Decision, E as Env, j as Evaluation, H as HumanDecisionInput, M as MemoryCorrelationStore, O as OpenSessionInput, R as RedactFn, k as Run, l as RunOptions, m as SDK_VERSION, n as SessionBorn, S as SessionSource, o as Sessions, p as StartSessionInput, T as ToolCallSpan, q as Transport, r as TransportClosedError, s as TransportOptions, t as createBeltic, u as ephemeralIdentity, v as fileIdentity, w as identityFromSeed } from './session-gK51QVAM.js';
3
+ import { a as PaymentSummary, J as JsonObject, P as PaymentMomentPayload } from './verdict-CDAsxktI.js';
4
4
  import 'zod';
5
5
 
6
6
  /**
package/dist/index.js CHANGED
@@ -1,3 +1,6 @@
1
+ import {
2
+ Verdict
3
+ } from "./chunk-4BUUPU3O.js";
1
4
  import {
2
5
  BelticDisabledError,
3
6
  DEFAULT_OPEN_RETRY_MS,
@@ -14,13 +17,6 @@ import {
14
17
  sha256,
15
18
  toHex
16
19
  } from "./chunk-X3W2Z5GC.js";
17
- import {
18
- Verdict
19
- } from "./chunk-46QN2KEZ.js";
20
- import {
21
- presentedFrom,
22
- summaryOf
23
- } from "./chunk-7G5EHNVW.js";
24
20
 
25
21
  // src/core/api-client.ts
26
22
  var BelticApiError = class extends Error {
@@ -144,6 +140,19 @@ function fileIdentity(path, credential) {
144
140
  return identityFromSeed(seed, credential);
145
141
  }
146
142
 
143
+ // src/core/payment-moment.ts
144
+ function summaryOf(m) {
145
+ return {
146
+ protocol: m.protocol,
147
+ payee: m.payee,
148
+ amount: { value: m.amount.value, currency: m.amount.currency },
149
+ ...m.payer ? { payer: m.payer } : {}
150
+ };
151
+ }
152
+ function presentedFrom(summary, raw) {
153
+ return { ...summary, artifact: "payment-signature", raw };
154
+ }
155
+
147
156
  // src/core/decision.ts
148
157
  var Decision = class _Decision {
149
158
  constructor(evaluation) {
@@ -535,7 +544,7 @@ var Transport = class {
535
544
  };
536
545
 
537
546
  // src/client.ts
538
- var SDK_VERSION = "0.3.0";
547
+ var SDK_VERSION = "0.4.0";
539
548
  var ENV_REQUIRED = ["BELTIC_API_KEY", "BELTIC_BASE_URL", "BELTIC_AGENT_SEED"];
540
549
  var ENV_CREDENTIAL = "BELTIC_AGENT_CREDENTIAL";
541
550
  var Beltic = class _Beltic {
@@ -1,5 +1,5 @@
1
- import { b as JsonValue, E as EvidenceSourceAll } from '../verdict-6vCyoAHE.js';
2
- export { A as ALL_SOURCES, c as ANOMALY_TYPES, d as Amount, e as AmountSchema, f as AnchorEntry, g as AnchorEntrySchema, h as AnchorsOutput, i as AnchorsOutputSchema, j as ApiError, k as ApiErrorSchema, C as ChainHead, l as ChainHeadSchema, m as CreatePolicyInput, n as CreatePolicyInputSchema, o as CreatePolicyOutput, p as CreatePolicyOutputSchema, q as CreateSessionInput, r as CreateSessionInputSchema, s as CreateSessionOutput, t as CreateSessionOutputSchema, D as Decision, u as DecisionSchema, v as DeclaredIntent, w as DeclaredIntentSchema, x as DigestedEnvelope, y as EvaluateInput, z as EvaluateInputSchema, B as EvaluateOutput, F as EvaluateOutputSchema, G as EventResult, H as EventResultSchema, I as EventResultStatus, K as EventResultStatusSchema, L as EvidenceAck, M as EvidenceAckSchema, N as EvidenceBatchInput, O as EvidenceBatchInputSchema, Q as EvidenceEnvelope, R as EvidenceEvent, S as EvidenceEventSchema, T as EvidenceKind, U as EvidenceKindSchema, V as EvidenceSource, W as EvidenceSourceAllSchema, X as EvidenceSourceSchema, Y as GatewayDecisionPayload, Z as GatewayDecisionPayloadSchema, _ as Hex64, $ as Hex64Schema, a0 as IntentDeclaredPayload, a1 as IntentDeclaredPayloadSchema, J as JsonObject, a2 as JsonValueSchema, a3 as LlmCallEndPayload, a4 as LlmCallEndPayloadSchema, a5 as LlmCallStartPayload, a6 as LlmCallStartPayloadSchema, a7 as MAX_BATCH_EVENTS, a8 as OnReview, a9 as PAYMENT_ARTIFACTS, aa as PLATFORM_KINDS, ab as PayloadByKind, P as PaymentMomentPayload, ac as PaymentMomentPayloadSchema, a as PaymentSummary, ad as PaymentSummarySchema, ae as PlatformAnomalyPayload, af as PlatformAnomalyPayloadSchema, ag as PlatformEvidenceKind, ah as PlatformEvidenceKindSchema, ai as PlatformObservationPayload, aj as PlatformObservationPayloadSchema, ak as SESSION_CLOSE_REASONS, al as SOURCE_ORDER, am as SeqSchema, an as SessionClosePayload, ao as SessionClosePayloadSchema, ap as SessionIdSchema, aq as SessionOpenPayload, ar as SessionOpenPayloadSchema, as as Sig, at as SigSchema, au as TimestampSchema, av as ToolCallEndPayload, aw as ToolCallEndPayloadSchema, ax as ToolCallStartPayload, ay as ToolCallStartPayloadSchema, az as TransportGapPayload, aA as TransportGapPayloadSchema, aB as Verdict, aC as WIRE_KINDS, aD as WIRE_SOURCES, aE as WireEvidenceKind, aF as WireEvidenceKindSchema, aG as compareBySessionSource, aH as compareBySourceSeq, aI as isPlatformKind, aJ as isWireKind, aK as payloadSchemaFor } from '../verdict-6vCyoAHE.js';
1
+ import { b as JsonValue, E as EvidenceSourceAll } from '../verdict-CDAsxktI.js';
2
+ export { A as ALL_SOURCES, c as ANOMALY_TYPES, d as Amount, e as AmountSchema, f as ApiError, g as ApiErrorSchema, C as ChainHead, h as ChainHeadSchema, i as CreatePolicyInput, j as CreatePolicyInputSchema, k as CreatePolicyOutput, l as CreatePolicyOutputSchema, m as CreateSessionInput, n as CreateSessionInputSchema, o as CreateSessionOutput, p as CreateSessionOutputSchema, D as Decision, q as DecisionSchema, r as DeclaredIntent, s as DeclaredIntentSchema, t as DigestedEnvelope, u as EvaluateInput, v as EvaluateInputSchema, w as EvaluateOutput, x as EvaluateOutputSchema, y as EventResult, z as EventResultSchema, B as EventResultStatus, F as EventResultStatusSchema, G as EvidenceAck, H as EvidenceAckSchema, I as EvidenceBatchInput, K as EvidenceBatchInputSchema, L as EvidenceEnvelope, M as EvidenceEvent, N as EvidenceEventSchema, O as EvidenceKind, Q as EvidenceKindSchema, R as EvidenceSource, S as EvidenceSourceAllSchema, T as EvidenceSourceSchema, U as GatewayDecisionPayload, V as GatewayDecisionPayloadSchema, W as Hex64, X as Hex64Schema, Y as IntentDeclaredPayload, Z as IntentDeclaredPayloadSchema, J as JsonObject, _ as JsonValueSchema, $ as LlmCallEndPayload, a0 as LlmCallEndPayloadSchema, a1 as LlmCallStartPayload, a2 as LlmCallStartPayloadSchema, a3 as MAX_BATCH_EVENTS, a4 as OnReview, a5 as PAYMENT_ARTIFACTS, a6 as PLATFORM_KINDS, a7 as PayloadByKind, P as PaymentMomentPayload, a8 as PaymentMomentPayloadSchema, a as PaymentSummary, a9 as PaymentSummarySchema, aa as PlatformAnomalyPayload, ab as PlatformAnomalyPayloadSchema, ac as PlatformEvidenceKind, ad as PlatformEvidenceKindSchema, ae as PlatformObservationPayload, af as PlatformObservationPayloadSchema, ag as SESSION_CLOSE_REASONS, ah as SOURCE_ORDER, ai as SeqSchema, aj as SessionClosePayload, ak as SessionClosePayloadSchema, al as SessionIdSchema, am as SessionOpenPayload, an as SessionOpenPayloadSchema, ao as Sig, ap as SigSchema, aq as TimestampSchema, ar as ToolCallEndPayload, as as ToolCallEndPayloadSchema, at as ToolCallStartPayload, au as ToolCallStartPayloadSchema, av as TransportGapPayload, aw as TransportGapPayloadSchema, ax as Verdict, ay as WIRE_KINDS, az as WIRE_SOURCES, aA as WireEvidenceKind, aB as WireEvidenceKindSchema, aC as compareBySessionSource, aD as compareBySourceSeq, aE as isPlatformKind, aF as isWireKind, aG as payloadSchemaFor } from '../verdict-CDAsxktI.js';
3
3
  import { z } from 'zod';
4
4
 
5
5
  declare const PRIMITIVES: readonly ["THRESHOLD", "MEMBERSHIP", "MATCH", "PRESENCE", "FRESHNESS"];
@@ -3,8 +3,6 @@ import {
3
3
  ANNOTATION_CODES,
4
4
  ANOMALY_TYPES,
5
5
  AmountSchema,
6
- AnchorEntrySchema,
7
- AnchorsOutputSchema,
8
6
  ApiErrorSchema,
9
7
  COLLECTOR_CODES,
10
8
  ChainHeadSchema,
@@ -73,14 +71,12 @@ import {
73
71
  parseSelectorRef,
74
72
  payloadSchemaFor,
75
73
  walkPath
76
- } from "../chunk-46QN2KEZ.js";
74
+ } from "../chunk-4BUUPU3O.js";
77
75
  export {
78
76
  ALL_SOURCES,
79
77
  ANNOTATION_CODES,
80
78
  ANOMALY_TYPES,
81
79
  AmountSchema,
82
- AnchorEntrySchema,
83
- AnchorsOutputSchema,
84
80
  ApiErrorSchema,
85
81
  COLLECTOR_CODES,
86
82
  ChainHeadSchema,
@@ -1,9 +1,9 @@
1
- import { L as EvidenceAck, G as EventResult, R as EvidenceEvent, B as EvaluateOutput, aB as Verdict, a8 as OnReview, a as PaymentSummary, P as PaymentMomentPayload, D as Decision$1, v as DeclaredIntent, ax as ToolCallStartPayload, b as JsonValue, J as JsonObject, an as SessionClosePayload, V as EvidenceSource, aE as WireEvidenceKind, C as ChainHead, ab as PayloadByKind } from './verdict-6vCyoAHE.js';
1
+ import { G as EvidenceAck, y as EventResult, M as EvidenceEvent, w as EvaluateOutput, ax as Verdict, a4 as OnReview, a as PaymentSummary, P as PaymentMomentPayload, D as Decision$1, r as DeclaredIntent, at as ToolCallStartPayload, b as JsonValue, J as JsonObject, aj as SessionClosePayload, R as EvidenceSource, aA as WireEvidenceKind, C as ChainHead, a7 as PayloadByKind } from './verdict-CDAsxktI.js';
2
2
 
3
3
  /**
4
4
  * The edge signs event digests (Fraud SDK RFC › Modules › Identity Module);
5
- * the platform signs its own PLATFORM chain and epoch anchors. Both are the
6
- * same operation over different keys, so one interface.
5
+ * the platform signs its own PLATFORM chain. Both are the same operation
6
+ * over different keys, so one interface.
7
7
  */
8
8
  interface Signer {
9
9
  /** Raw 32-byte Ed25519 public key. */
@@ -139,8 +139,7 @@ declare class Transport {
139
139
  *
140
140
  * @belticlabs/agent-risk-sdk/ai → middleware(session), wrapTools(session, …)
141
141
  * @belticlabs/agent-risk-sdk/x402 → belticFetch(session), x402Summary(…), attachX402(beltic, …)
142
- * @belticlabs/agent-risk-sdk/hono → belticPaymentMiddleware(beltic, …) (and /express)
143
- * @belticlabs/agent-risk-sdk/mcp → wrapClient(session, …), wrapServer(beltic, …)
142
+ * @belticlabs/agent-risk-sdk/hono → belticPaymentMiddleware(beltic, …)
144
143
  *
145
144
  * Neither half decides risk locally: verdicts are platform-side.
146
145
  *
@@ -159,7 +158,7 @@ declare class Transport {
159
158
  * they are the primitives the fail-open entries are built on.
160
159
  */
161
160
 
162
- declare const SDK_VERSION = "0.3.0";
161
+ declare const SDK_VERSION = "0.4.0";
163
162
  type Env = Record<string, string | undefined>;
164
163
  interface BelticOptions extends Omit<ApiClientOptions, 'userAgent'> {
165
164
  /** Buyer half. Without it, `sessions.start` is unavailable; the seller half works. */
@@ -318,22 +318,6 @@ declare const EvaluateOutputSchema: z.ZodObject<{
318
318
  decisionId: z.ZodUUID;
319
319
  }, z.core.$strict>;
320
320
  type EvaluateOutput = z.infer<typeof EvaluateOutputSchema>;
321
- declare const AnchorEntrySchema: z.ZodObject<{
322
- epoch: z.ZodString;
323
- root: z.ZodString;
324
- sig: z.ZodString;
325
- chainRef: z.ZodOptional<z.ZodString>;
326
- }, z.core.$strict>;
327
- type AnchorEntry = z.infer<typeof AnchorEntrySchema>;
328
- declare const AnchorsOutputSchema: z.ZodObject<{
329
- entries: z.ZodArray<z.ZodObject<{
330
- epoch: z.ZodString;
331
- root: z.ZodString;
332
- sig: z.ZodString;
333
- chainRef: z.ZodOptional<z.ZodString>;
334
- }, z.core.$strict>>;
335
- }, z.core.$strict>;
336
- type AnchorsOutput = z.infer<typeof AnchorsOutputSchema>;
337
321
  /** Non-RFC admin surface (GAP-53). */
338
322
  declare const CreatePolicyInputSchema: z.ZodObject<{
339
323
  rules: z.ZodObject<{
@@ -568,4 +552,4 @@ declare class Verdict {
568
552
  effective(onReview: OnReview): Decision;
569
553
  }
570
554
 
571
- export { Hex64Schema as $, ALL_SOURCES as A, type EvaluateOutput as B, type ChainHead as C, type Decision as D, type EvidenceSourceAll as E, EvaluateOutputSchema as F, type EventResult as G, EventResultSchema as H, type EventResultStatus as I, type JsonObject as J, EventResultStatusSchema as K, type EvidenceAck as L, EvidenceAckSchema as M, type EvidenceBatchInput as N, EvidenceBatchInputSchema as O, type PaymentMomentPayload as P, type EvidenceEnvelope as Q, type EvidenceEvent as R, EvidenceEventSchema as S, type EvidenceKind as T, EvidenceKindSchema as U, type EvidenceSource as V, EvidenceSourceAllSchema as W, EvidenceSourceSchema as X, type GatewayDecisionPayload as Y, GatewayDecisionPayloadSchema as Z, type Hex64 as _, type PaymentSummary as a, type IntentDeclaredPayload as a0, IntentDeclaredPayloadSchema as a1, JsonValueSchema as a2, type LlmCallEndPayload as a3, LlmCallEndPayloadSchema as a4, type LlmCallStartPayload as a5, LlmCallStartPayloadSchema as a6, MAX_BATCH_EVENTS as a7, type OnReview as a8, PAYMENT_ARTIFACTS as a9, TransportGapPayloadSchema as aA, Verdict as aB, WIRE_KINDS as aC, WIRE_SOURCES as aD, type WireEvidenceKind as aE, WireEvidenceKindSchema as aF, compareBySessionSource as aG, compareBySourceSeq as aH, isPlatformKind as aI, isWireKind as aJ, payloadSchemaFor as aK, PLATFORM_KINDS as aa, type PayloadByKind as ab, PaymentMomentPayloadSchema as ac, PaymentSummarySchema as ad, type PlatformAnomalyPayload as ae, PlatformAnomalyPayloadSchema as af, type PlatformEvidenceKind as ag, PlatformEvidenceKindSchema as ah, type PlatformObservationPayload as ai, PlatformObservationPayloadSchema as aj, SESSION_CLOSE_REASONS as ak, SOURCE_ORDER as al, SeqSchema as am, type SessionClosePayload as an, SessionClosePayloadSchema as ao, SessionIdSchema as ap, type SessionOpenPayload as aq, SessionOpenPayloadSchema as ar, type Sig as as, SigSchema as at, TimestampSchema as au, type ToolCallEndPayload as av, ToolCallEndPayloadSchema as aw, type ToolCallStartPayload as ax, ToolCallStartPayloadSchema as ay, type TransportGapPayload as az, type JsonValue as b, ANOMALY_TYPES as c, type Amount as d, AmountSchema as e, type AnchorEntry as f, AnchorEntrySchema as g, type AnchorsOutput as h, AnchorsOutputSchema as i, type ApiError as j, ApiErrorSchema as k, ChainHeadSchema as l, type CreatePolicyInput as m, CreatePolicyInputSchema as n, type CreatePolicyOutput as o, CreatePolicyOutputSchema as p, type CreateSessionInput as q, CreateSessionInputSchema as r, type CreateSessionOutput as s, CreateSessionOutputSchema as t, DecisionSchema as u, type DeclaredIntent as v, DeclaredIntentSchema as w, type DigestedEnvelope as x, type EvaluateInput as y, EvaluateInputSchema as z };
555
+ export { type LlmCallEndPayload as $, ALL_SOURCES as A, type EventResultStatus as B, type ChainHead as C, type Decision as D, type EvidenceSourceAll as E, EventResultStatusSchema as F, type EvidenceAck as G, EvidenceAckSchema as H, type EvidenceBatchInput as I, type JsonObject as J, EvidenceBatchInputSchema as K, type EvidenceEnvelope as L, type EvidenceEvent as M, EvidenceEventSchema as N, type EvidenceKind as O, type PaymentMomentPayload as P, EvidenceKindSchema as Q, type EvidenceSource as R, EvidenceSourceAllSchema as S, EvidenceSourceSchema as T, type GatewayDecisionPayload as U, GatewayDecisionPayloadSchema as V, type Hex64 as W, Hex64Schema as X, type IntentDeclaredPayload as Y, IntentDeclaredPayloadSchema as Z, JsonValueSchema as _, type PaymentSummary as a, LlmCallEndPayloadSchema as a0, type LlmCallStartPayload as a1, LlmCallStartPayloadSchema as a2, MAX_BATCH_EVENTS as a3, type OnReview as a4, PAYMENT_ARTIFACTS as a5, PLATFORM_KINDS as a6, type PayloadByKind as a7, PaymentMomentPayloadSchema as a8, PaymentSummarySchema as a9, type WireEvidenceKind as aA, WireEvidenceKindSchema as aB, compareBySessionSource as aC, compareBySourceSeq as aD, isPlatformKind as aE, isWireKind as aF, payloadSchemaFor as aG, type PlatformAnomalyPayload as aa, PlatformAnomalyPayloadSchema as ab, type PlatformEvidenceKind as ac, PlatformEvidenceKindSchema as ad, type PlatformObservationPayload as ae, PlatformObservationPayloadSchema as af, SESSION_CLOSE_REASONS as ag, SOURCE_ORDER as ah, SeqSchema as ai, type SessionClosePayload as aj, SessionClosePayloadSchema as ak, SessionIdSchema as al, type SessionOpenPayload as am, SessionOpenPayloadSchema as an, type Sig as ao, SigSchema as ap, TimestampSchema as aq, type ToolCallEndPayload as ar, ToolCallEndPayloadSchema as as, type ToolCallStartPayload as at, ToolCallStartPayloadSchema as au, type TransportGapPayload as av, TransportGapPayloadSchema as aw, Verdict as ax, WIRE_KINDS as ay, WIRE_SOURCES as az, type JsonValue as b, ANOMALY_TYPES as c, type Amount as d, AmountSchema as e, type ApiError as f, ApiErrorSchema as g, ChainHeadSchema as h, type CreatePolicyInput as i, CreatePolicyInputSchema as j, type CreatePolicyOutput as k, CreatePolicyOutputSchema as l, type CreateSessionInput as m, CreateSessionInputSchema as n, type CreateSessionOutput as o, CreateSessionOutputSchema as p, DecisionSchema as q, type DeclaredIntent as r, DeclaredIntentSchema as s, type DigestedEnvelope as t, type EvaluateInput as u, EvaluateInputSchema as v, type EvaluateOutput as w, EvaluateOutputSchema as x, type EventResult as y, EventResultSchema as z };
@@ -1,11 +1,22 @@
1
- import { RoutesConfig, x402ResourceServer } from '@x402/core/server';
1
+ import { PaywallConfig, RoutesConfig, x402ResourceServer } from '@x402/core/server';
2
2
  import { MiddlewareHandler } from 'hono';
3
- import { B as Beltic } from '../session-DsBWEP8d.js';
4
- import { G as GuardedMiddlewareOptions } from '../middleware-9gI0ou2i.js';
5
- export { a as attachX402 } from '../adapter-BEpzr2R3.js';
6
- import '../verdict-6vCyoAHE.js';
3
+ import { B as Beltic } from '../session-gK51QVAM.js';
4
+ import { A as AttachOptions } from '../adapter-CLy44CD2.js';
5
+ export { a as attachX402 } from '../adapter-CLy44CD2.js';
6
+ import '../verdict-CDAsxktI.js';
7
7
  import 'zod';
8
8
 
9
+ /**
10
+ * The seller half as one middleware: the framework's `@x402/*` payment
11
+ * middleware over an `x402HTTPResourceServer` with the Beltic hooks
12
+ * attached. `@belticlabs/agent-risk-sdk/hono` hands in its framework's
13
+ * `paymentMiddlewareFromHTTPServer`.
14
+ */
15
+
16
+ type GuardedMiddlewareOptions = AttachOptions & {
17
+ paywall?: PaywallConfig | undefined;
18
+ };
19
+
9
20
  /** Seller half for hono: `@x402/hono`'s payment middleware with the Beltic hooks attached. */
10
21
 
11
22
  declare function belticPaymentMiddleware(beltic: Beltic, routes: RoutesConfig, server: x402ResourceServer, opts?: GuardedMiddlewareOptions): MiddlewareHandler;
package/dist/x402/hono.js CHANGED
@@ -1,17 +1,23 @@
1
- import {
2
- guardedPaymentMiddleware
3
- } from "../chunk-NJVO2WIV.js";
4
1
  import {
5
2
  attachX402
6
- } from "../chunk-OKC6VMFH.js";
7
- import "../chunk-FAQ442YH.js";
8
- import "../chunk-X3W2Z5GC.js";
9
- import "../chunk-46QN2KEZ.js";
10
- import "../chunk-LM4NIYE5.js";
3
+ } from "../chunk-WY5ZX4BD.js";
11
4
  import "../chunk-FQDHFTVR.js";
5
+ import "../chunk-X3W2Z5GC.js";
12
6
 
13
7
  // src/x402/hono.ts
14
8
  import { paymentMiddlewareFromHTTPServer } from "@x402/hono";
9
+
10
+ // src/x402/middleware.ts
11
+ import {
12
+ x402HTTPResourceServer
13
+ } from "@x402/core/server";
14
+ function guardedPaymentMiddleware(fromHTTPServer, beltic, routes, server, opts = {}) {
15
+ const http = new x402HTTPResourceServer(server, routes);
16
+ attachX402(beltic, server, http, opts);
17
+ return fromHTTPServer(http, opts.paywall);
18
+ }
19
+
20
+ // src/x402/hono.ts
15
21
  function belticPaymentMiddleware(beltic, routes, server, opts) {
16
22
  return guardedPaymentMiddleware(paymentMiddlewareFromHTTPServer, beltic, routes, server, opts);
17
23
  }
@@ -1,6 +1,6 @@
1
- export { A as AttachOptions, b as AttachedX402, C as CorrelationContext, a as attachX402 } from '../adapter-BEpzr2R3.js';
2
- import { S as SessionSource } from '../session-DsBWEP8d.js';
3
- import { v as DeclaredIntent, P as PaymentMomentPayload, J as JsonObject, a as PaymentSummary } from '../verdict-6vCyoAHE.js';
1
+ export { A as AttachOptions, b as AttachedX402, C as CorrelationContext, a as attachX402 } from '../adapter-CLy44CD2.js';
2
+ import { S as SessionSource } from '../session-gK51QVAM.js';
3
+ import { r as DeclaredIntent, P as PaymentMomentPayload, J as JsonObject, a as PaymentSummary } from '../verdict-CDAsxktI.js';
4
4
  import '@x402/core/server';
5
5
  import 'zod';
6
6
 
@@ -14,7 +14,6 @@ import 'zod';
14
14
  declare const SESSION_EXTENSION = "beltic.sessionId";
15
15
  declare const SESSION_HEADER = "Beltic-Session-Id";
16
16
  declare const DECISION_EXTENSION = "beltic.decisionId";
17
- declare const DECISION_HEADER = "Beltic-Decision-Id";
18
17
  declare function sessionIdOf(extensions: Readonly<Record<string, unknown>> | undefined): string | null;
19
18
  declare function decisionIdOf(extensions: Readonly<Record<string, unknown>> | undefined): string | null;
20
19
 
@@ -59,20 +58,19 @@ declare function x402Intent(input: X402IntentInput): DeclaredIntent;
59
58
  declare function x402Currency(network: string, asset: string): string;
60
59
  /**
61
60
  * The minimum an `accepts` entry needs to become a moment; unknown parts
62
- * are named, never dropped. v1 spells the amount `maxAmountRequired`.
61
+ * are named, never dropped.
63
62
  */
64
63
  interface AcceptsLike {
65
64
  payTo?: string | undefined;
66
65
  amount?: string | undefined;
67
- maxAmountRequired?: string | undefined;
68
66
  network?: string | undefined;
69
67
  asset?: string | undefined;
70
68
  }
71
69
  /**
72
- * A 402 challenge and a presented payment of either generation, as far as
73
- * a moment needs them. `@x402/core`'s `PaymentRequired` and
74
- * `PaymentPayload` satisfy these structurally, so the seller adapter
75
- * passes its typed values through and the buyer needs no `@x402/*` types.
70
+ * A 402 challenge and a presented payment, as far as a moment needs them.
71
+ * `@x402/core`'s `PaymentRequired` and `PaymentPayload` satisfy these
72
+ * structurally, so the seller adapter passes its typed values through and
73
+ * the buyer needs no `@x402/*` types.
76
74
  */
77
75
  interface PaymentRequiredLike {
78
76
  x402Version?: number | undefined;
@@ -81,8 +79,6 @@ interface PaymentRequiredLike {
81
79
  interface PaymentPayloadLike {
82
80
  x402Version?: number | undefined;
83
81
  accepted?: AcceptsLike | undefined;
84
- /** v1 names the network here, beside the payload, and nowhere else. */
85
- network?: string | undefined;
86
82
  payload?: Readonly<Record<string, unknown>> | undefined;
87
83
  extensions?: Readonly<Record<string, unknown>> | undefined;
88
84
  }
@@ -97,20 +93,14 @@ declare function x402Summary(accepts: AcceptsLike | undefined, opts?: {
97
93
  /** The payer is scheme-specific; the common EVM shapes are read, anything else stays in `raw`. */
98
94
  declare function payerOf(payload: PaymentPayloadLike): string | undefined;
99
95
  declare const x402Moments: {
100
- /** The 402 challenge as the buyer saw it, v2 header or v1 body. */
96
+ /** The 402 challenge as the buyer saw it, from the `PAYMENT-REQUIRED` header. */
101
97
  required(required: PaymentRequiredLike): PaymentMomentPayload;
102
98
  /** The requirements the seller's resource server resolved for a request. */
103
99
  requirements(req: AcceptsLike): PaymentMomentPayload;
104
100
  /** A route's static `accepts` config, before any payment header exists. */
105
101
  route(route: unknown, raw: JsonObject): PaymentMomentPayload;
106
- /** An in-band ask (MRTR `input_required` or a `_meta` envelope) carrying an x402-style `accepts`. */
107
- ask(first: AcceptsLike, raw: JsonObject): PaymentMomentPayload;
108
- /**
109
- * The signed payment the buyer presented. A v2 payload carries the
110
- * requirement it accepted; a v1 payload does not, so the caller passes
111
- * the `accepts` entry it answered.
112
- */
113
- payload(payload: PaymentPayloadLike, accepts?: AcceptsLike | undefined): PaymentMomentPayload;
102
+ /** The signed payment the buyer presented, with the requirement it accepted. */
103
+ payload(payload: PaymentPayloadLike): PaymentMomentPayload;
114
104
  };
115
105
 
116
- export { type AcceptsLike, DECISION_EXTENSION, DECISION_HEADER, type PaymentPayloadLike, type PaymentRequiredLike, SESSION_EXTENSION, SESSION_HEADER, type X402IntentInput, belticFetch, decisionIdOf, payerOf, sessionIdOf, x402Currency, x402Intent, x402Moments, x402Summary };
106
+ export { type AcceptsLike, DECISION_EXTENSION, type PaymentPayloadLike, type PaymentRequiredLike, SESSION_EXTENSION, SESSION_HEADER, type X402IntentInput, belticFetch, decisionIdOf, payerOf, sessionIdOf, x402Currency, x402Intent, x402Moments, x402Summary };