@agent-score/commerce 1.8.1 → 2.0.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.
Files changed (90) hide show
  1. package/README.md +73 -9
  2. package/dist/{_response-9yp6Fit2.d.mts → _response-BFYN3b6i.d.mts} +17 -19
  3. package/dist/{_response-CC6jNb8q.d.ts → _response-_iPD5AIj.d.ts} +17 -19
  4. package/dist/challenge/index.d.mts +106 -198
  5. package/dist/challenge/index.d.ts +106 -198
  6. package/dist/challenge/index.js +238 -111
  7. package/dist/challenge/index.js.map +1 -1
  8. package/dist/challenge/index.mjs +238 -111
  9. package/dist/challenge/index.mjs.map +1 -1
  10. package/dist/checkout-BoFwnVsj.d.ts +931 -0
  11. package/dist/checkout-DRbQ0Fsh.d.mts +931 -0
  12. package/dist/core.d.mts +2 -2
  13. package/dist/core.d.ts +2 -2
  14. package/dist/core.js +1 -1
  15. package/dist/core.js.map +1 -1
  16. package/dist/core.mjs +1 -1
  17. package/dist/core.mjs.map +1 -1
  18. package/dist/discovery/index.d.mts +453 -51
  19. package/dist/discovery/index.d.ts +453 -51
  20. package/dist/discovery/index.js +1092 -58
  21. package/dist/discovery/index.js.map +1 -1
  22. package/dist/discovery/index.mjs +1060 -57
  23. package/dist/discovery/index.mjs.map +1 -1
  24. package/dist/identity/express.d.mts +3 -3
  25. package/dist/identity/express.d.ts +3 -3
  26. package/dist/identity/express.js +30 -19
  27. package/dist/identity/express.js.map +1 -1
  28. package/dist/identity/express.mjs +30 -19
  29. package/dist/identity/express.mjs.map +1 -1
  30. package/dist/identity/fastify.d.mts +4 -4
  31. package/dist/identity/fastify.d.ts +4 -4
  32. package/dist/identity/fastify.js +30 -19
  33. package/dist/identity/fastify.js.map +1 -1
  34. package/dist/identity/fastify.mjs +30 -19
  35. package/dist/identity/fastify.mjs.map +1 -1
  36. package/dist/identity/hono.d.mts +3 -3
  37. package/dist/identity/hono.d.ts +3 -3
  38. package/dist/identity/hono.js +30 -19
  39. package/dist/identity/hono.js.map +1 -1
  40. package/dist/identity/hono.mjs +30 -19
  41. package/dist/identity/hono.mjs.map +1 -1
  42. package/dist/identity/nextjs.d.mts +6 -7
  43. package/dist/identity/nextjs.d.ts +6 -7
  44. package/dist/identity/nextjs.js +30 -19
  45. package/dist/identity/nextjs.js.map +1 -1
  46. package/dist/identity/nextjs.mjs +30 -19
  47. package/dist/identity/nextjs.mjs.map +1 -1
  48. package/dist/identity/policy.d.mts +41 -4
  49. package/dist/identity/policy.d.ts +41 -4
  50. package/dist/identity/policy.js +3662 -18
  51. package/dist/identity/policy.js.map +1 -1
  52. package/dist/identity/policy.mjs +3648 -3
  53. package/dist/identity/policy.mjs.map +1 -1
  54. package/dist/identity/web.d.mts +3 -3
  55. package/dist/identity/web.d.ts +3 -3
  56. package/dist/identity/web.js +30 -19
  57. package/dist/identity/web.js.map +1 -1
  58. package/dist/identity/web.mjs +30 -19
  59. package/dist/identity/web.mjs.map +1 -1
  60. package/dist/index.d.mts +72 -329
  61. package/dist/index.d.ts +72 -329
  62. package/dist/index.js +3651 -373
  63. package/dist/index.js.map +1 -1
  64. package/dist/index.mjs +3628 -361
  65. package/dist/index.mjs.map +1 -1
  66. package/dist/payment/index.d.mts +256 -265
  67. package/dist/payment/index.d.ts +256 -265
  68. package/dist/payment/index.js +586 -149
  69. package/dist/payment/index.js.map +1 -1
  70. package/dist/payment/index.mjs +573 -148
  71. package/dist/payment/index.mjs.map +1 -1
  72. package/dist/{agent_instructions-DiMSGkdm.d.mts → pricing-CQ9DIFaw.d.ts} +109 -56
  73. package/dist/{agent_instructions-DiMSGkdm.d.ts → pricing-CxzwyiO6.d.mts} +109 -56
  74. package/dist/rail_spec-XP0wKgJV.d.mts +132 -0
  75. package/dist/rail_spec-XP0wKgJV.d.ts +132 -0
  76. package/dist/{signer-CFVQsWjL.d.mts → signer-3FAit11j.d.mts} +27 -1
  77. package/dist/{signer-CFVQsWjL.d.ts → signer-3FAit11j.d.ts} +27 -1
  78. package/dist/solana-Cds87OTu.d.mts +67 -0
  79. package/dist/solana-Cds87OTu.d.ts +67 -0
  80. package/dist/stripe-multichain/index.d.mts +55 -66
  81. package/dist/stripe-multichain/index.d.ts +55 -66
  82. package/dist/stripe-multichain/index.js +68 -42
  83. package/dist/stripe-multichain/index.js.map +1 -1
  84. package/dist/stripe-multichain/index.mjs +68 -41
  85. package/dist/stripe-multichain/index.mjs.map +1 -1
  86. package/dist/{wwwauthenticate-CU1eNvMQ.d.mts → wwwauthenticate-D_FMnPgU.d.mts} +9 -10
  87. package/dist/{wwwauthenticate-CU1eNvMQ.d.ts → wwwauthenticate-D_FMnPgU.d.ts} +9 -10
  88. package/dist/x402_server-hgQzWQwB.d.mts +81 -0
  89. package/dist/x402_server-hgQzWQwB.d.ts +81 -0
  90. package/package.json +9 -7
@@ -1,9 +1,10 @@
1
- import { A as AgentInstructions } from '../agent_instructions-DiMSGkdm.mjs';
2
- export { B as BuildAgentInstructionsInput, a as BuildHowToPayInput, C as CompatibleClients, H as HowToPayBlock, b as HowToPayRailEntry, c as HowToPayStripeEntry, R as RailKey, d as buildAgentInstructions, e as buildHowToPay, f as compatibleClientsByRails } from '../agent_instructions-DiMSGkdm.mjs';
1
+ import { T as TempoRailSpec, X as X402BaseRailSpec, S as SolanaMppRailSpec, b as StripeRailSpec } from '../rail_spec-XP0wKgJV.mjs';
2
+ import { A as AgentInstructions, P as PricingBlock } from '../pricing-CxzwyiO6.mjs';
3
+ export { C as CompatibleClients, H as HowToPayBlock, a as HowToPayRailEntry, b as HowToPayRails, c as HowToPayStripeEntry, R as RailKey, d as buildAgentInstructions, e as buildHowToPay, f as buildPricingBlock, g as compatibleClientsByRails } from '../pricing-CxzwyiO6.mjs';
3
4
  import { AgentMemoryHint } from '../core.mjs';
4
5
  export { buildAgentMemoryHint } from '../core.mjs';
5
- import { P as PaymentRequiredHeaderInput } from '../wwwauthenticate-CU1eNvMQ.mjs';
6
- import '../signer-CFVQsWjL.mjs';
6
+ import { p as paymentRequiredHeader } from '../wwwauthenticate-D_FMnPgU.mjs';
7
+ import '../signer-3FAit11j.mjs';
7
8
 
8
9
  interface TempoMethodEntry {
9
10
  method: 'tempo/charge';
@@ -30,7 +31,6 @@ interface SolanaMppMethodEntry {
30
31
  symbol: string;
31
32
  decimals: number;
32
33
  pay_to: string;
33
- fee_payer_key?: string;
34
34
  }
35
35
  interface StripeMethodEntry {
36
36
  method: 'stripe/charge';
@@ -38,42 +38,19 @@ interface StripeMethodEntry {
38
38
  profile_id: string | null;
39
39
  }
40
40
  type AcceptedMethodEntry = TempoMethodEntry | X402MethodEntry | SolanaMppMethodEntry | StripeMethodEntry;
41
- interface BuildAcceptedMethodsInput {
42
- tempo?: {
43
- recipient: string;
44
- network?: string;
45
- chainId?: number;
46
- token?: string;
47
- symbol?: string;
48
- decimals?: number;
49
- };
50
- x402_base?: {
51
- recipient: string;
52
- network?: string;
53
- chainId?: number;
54
- token?: string;
55
- symbol?: string;
56
- decimals?: number;
57
- };
58
- solana_mpp?: {
59
- recipient: string;
60
- network?: string;
61
- token?: string;
62
- symbol?: string;
63
- decimals?: number;
64
- feePayerKey?: string;
65
- };
66
- stripe?: {
67
- profileId?: string | null;
68
- rails?: ('card' | 'link' | 'shared_payment_token')[];
69
- };
70
- }
71
41
  /**
72
- * Build the `accepted_methods[]` array for an enriched 402 body. Each rail entry is
73
- * conditionally included based on whether the vendor passed it. Per-rail shapes follow
74
- * a canonical 402 shape across rails.
42
+ * Build the `accepted_methods[]` array for an enriched 402 body. Each rail entry
43
+ * is conditionally included when the vendor passes a `*RailSpec` for that rail.
44
+ * Each spec's `recipient` is resolved via `resolveRecipient` so per-order
45
+ * factories (e.g. Stripe-multichain mints fresh deposits per PaymentIntent)
46
+ * flow through identically to static-treasury strings.
75
47
  */
76
- declare function buildAcceptedMethods(input: BuildAcceptedMethodsInput): AcceptedMethodEntry[];
48
+ declare function buildAcceptedMethods({ tempo, x402_base, solana_mpp, stripe, }: {
49
+ tempo?: TempoRailSpec;
50
+ x402_base?: X402BaseRailSpec;
51
+ solana_mpp?: SolanaMppRailSpec;
52
+ stripe?: StripeRailSpec;
53
+ }): Promise<AcceptedMethodEntry[]>;
77
54
 
78
55
  type IdentityMode = 'wallet' | 'operator_token';
79
56
  interface SignerMatchResultLike {
@@ -82,18 +59,6 @@ interface SignerMatchResultLike {
82
59
  actualSigner?: string;
83
60
  linkedWallets?: string[];
84
61
  }
85
- interface IdentityMetadataInput {
86
- /** Current request's identity mode. */
87
- mode: IdentityMode;
88
- /** Claimed wallet address (when mode === 'wallet'). */
89
- wallet?: string;
90
- /** Projected signer_match verdict (from `getSignerVerdict(ctx).signer_match`). */
91
- signerMatchResult?: SignerMatchResultLike;
92
- /** Same-operator linked wallets (from assess response). */
93
- linkedWallets?: string[];
94
- /** Optional explicit constraint description (overrides the auto-generated one). */
95
- signerConstraint?: string;
96
- }
97
62
  interface IdentityMetadataBlock {
98
63
  identity_mode: IdentityMode;
99
64
  required_signer?: string;
@@ -106,7 +71,13 @@ interface IdentityMetadataBlock {
106
71
  * before signing — specifically, on wallet-auth rails the agent MUST sign with one
107
72
  * of the wallets in linked_wallets (all resolve to the same operator).
108
73
  */
109
- declare function buildIdentityMetadata(input: IdentityMetadataInput): IdentityMetadataBlock;
74
+ declare function buildIdentityMetadata({ mode, wallet, signerMatchResult, linkedWallets, signerConstraint, }: {
75
+ mode: IdentityMode;
76
+ wallet?: string;
77
+ signerMatchResult?: SignerMatchResultLike;
78
+ linkedWallets?: string[];
79
+ signerConstraint?: string;
80
+ }): IdentityMetadataBlock;
110
81
 
111
82
  /**
112
83
  * Helpers for emitting the cross-merchant `agent_memory` hint on merchant 402 responses.
@@ -129,14 +100,6 @@ declare function buildIdentityMetadata(input: IdentityMetadataInput): IdentityMe
129
100
  * every merchant emits the same shape.
130
101
  */
131
102
 
132
- interface FirstEncounterAgentMemoryInput {
133
- /**
134
- * Whether this is a first encounter for this operator/wallet/IP at this merchant.
135
- * Merchant-determined (DB lookup, cache flag, etc.). Pass `false` to suppress emission
136
- * cleanly without wrapping the call in an `if`.
137
- */
138
- firstEncounter: boolean;
139
- }
140
103
  /**
141
104
  * Returns the `agent_memory` hint when this is a first encounter, otherwise `undefined`.
142
105
  * Use directly with the `agentMemory` field of `build402Body`:
@@ -150,77 +113,27 @@ interface FirstEncounterAgentMemoryInput {
150
113
  * });
151
114
  * ```
152
115
  *
153
- * Returning `undefined` means `build402Body` cleanly skips the field instead of emitting
154
- * `agent_memory: null` (which would imply "I tried but failed" rather than "didn't apply").
116
+ * `firstEncounter` is merchant-determined (DB lookup, cache flag, etc.); pass `false` to
117
+ * suppress emission cleanly without wrapping the call in an `if`. Returning `undefined`
118
+ * means `build402Body` cleanly skips the field instead of emitting `agent_memory: null`
119
+ * (which would imply "I tried but failed" rather than "didn't apply").
155
120
  */
156
- declare function firstEncounterAgentMemory(input: FirstEncounterAgentMemoryInput): AgentMemoryHint | undefined;
121
+ declare function firstEncounterAgentMemory({ firstEncounter, }: {
122
+ firstEncounter: boolean;
123
+ }): AgentMemoryHint | undefined;
157
124
 
158
125
  /**
159
- * Pricing block builder + canonical type.
160
- *
161
- * Composes the cents-denominated price components into the dollar-string shape that
162
- * 402 challenge bodies advertise. Standardizes the pricing block so every merchant
163
- * — current and future commerce-platform plugins (Commerce7, WooCommerce, Shopify) —
164
- * surfaces the same shape to agents.
165
- *
166
- * Shipping is included by default because most physical-goods merchants carry it; pass
167
- * `shippingCents: 0` (or omit) for digital goods / services. Tax is optional for
168
- * merchants outside taxable jurisdictions.
169
- */
170
- interface PricingBlock {
171
- /** Pre-tax, pre-shipping subtotal as a dollar-string (e.g. `"250.00"`). */
172
- subtotal: string;
173
- /** Tax amount as a dollar-string. Always present even if `"0.00"`. */
174
- tax: string;
175
- /** Shipping cost as a dollar-string. Always present even if `"0.00"`. */
176
- shipping?: string;
177
- /** Final total = subtotal + tax + shipping, dollar-string. */
178
- total: string;
179
- /** Tax rate as a decimal fraction (e.g. `0.0775` for 7.75%). Optional — omit for tax-free merchants. */
180
- tax_rate?: number;
181
- /** ISO-3166-2 state code or jurisdiction name used for tax calc. Optional. */
182
- tax_state?: string;
183
- /** ISO-4217 currency code. Default `"USD"`. */
184
- currency?: string;
185
- }
186
- interface BuildPricingBlockInput {
187
- /** Pre-tax, pre-shipping subtotal in the smallest currency unit (cents, satoshi, etc.). */
188
- subtotalCents: number;
189
- /** Tax amount in the smallest currency unit. Default `0`. */
190
- taxCents?: number;
191
- /** Shipping cost in the smallest currency unit. Default `0`. */
192
- shippingCents?: number;
193
- /** Override the computed total. By default `subtotalCents + taxCents + shippingCents`. */
194
- totalCents?: number;
195
- /** Tax rate as a decimal fraction (e.g. `0.0775`). */
196
- taxRate?: number;
197
- /** Tax jurisdiction (state code, country, etc.). */
198
- taxState?: string;
199
- /** ISO-4217 currency. Default `"USD"`. */
200
- currency?: string;
201
- }
202
- /**
203
- * Compose a `PricingBlock` from cents-denominated inputs. Handles the cents → dollar-string
204
- * conversion (always 2 decimals) and computes the total when not explicitly provided.
205
- *
206
- * Example:
207
- * ```ts
208
- * const pricing = buildPricingBlock({
209
- * subtotalCents: 25000,
210
- * taxCents: 1875,
211
- * shippingCents: 999,
212
- * taxRate: 0.075,
213
- * taxState: 'CA',
214
- * });
215
- * // → { subtotal: '250.00', tax: '18.75', shipping: '9.99', total: '278.74', tax_rate: 0.075, tax_state: 'CA' }
216
- * ```
126
+ * Assemble the full enriched 402 response body. Combines accepted_methods, agent_instructions,
127
+ * identity metadata, pricing, x402 compliance fields, and any vendor-specific extras into a
128
+ * single object suitable for `JSON.stringify`. Vendors pass only what they have; the builder
129
+ * conditionally includes each section.
217
130
  *
218
- * Pass `shippingCents: 0` for digital goods if you want the field present (it's then `"0.00"`);
219
- * omit entirely if you don't want shipping in the response shape at all.
131
+ * Pair this with a Response that sets:
132
+ * - 'content-type: application/json'
133
+ * - 'www-authenticate: <wwwAuthenticateHeader([...])>' from `payment/wwwauthenticate`
134
+ * - 'PAYMENT-REQUIRED: <paymentRequiredHeader({...})>' for x402 clients
220
135
  */
221
- declare function buildPricingBlock(input: BuildPricingBlockInput): PricingBlock;
222
-
223
- interface Build402BodyInput {
136
+ declare function build402Body({ acceptedMethods, agentInstructions, identityMetadata, agentMemory, pricing, amountUsd, currency, orderId, product, retryBody, recommended, x402, extra, }: {
224
137
  /** From buildAcceptedMethods — list of MPP method entries. */
225
138
  acceptedMethods: AcceptedMethodEntry[];
226
139
  /** From buildAgentInstructions — wraps how_to_pay + warnings + recommended_tools. */
@@ -250,58 +163,58 @@ interface Build402BodyInput {
250
163
  x402?: {
251
164
  accepts: unknown[];
252
165
  version?: 1 | 2;
166
+ /** x402 spec `extensions` field. Per-endpoint declared extensions (e.g.
167
+ * `bazaar` discovery schema from `createBazaarDiscovery({...})`). Surfaces
168
+ * on the 402 body as `extensions` so spec-compliant crawlers can read it. */
169
+ extensions?: Record<string, unknown>;
253
170
  };
254
171
  /** Vendor-specific extra fields merged at the top level. */
255
172
  extra?: Record<string, unknown>;
256
- }
257
- /**
258
- * Assemble the full enriched 402 response body. Combines accepted_methods, agent_instructions,
259
- * identity metadata, pricing, x402 compliance fields, and any vendor-specific extras into a
260
- * single object suitable for `JSON.stringify`. Vendors pass only what they have; the builder
261
- * conditionally includes each section.
262
- *
263
- * Pair this with a Response that sets:
264
- * - 'content-type: application/json'
265
- * - 'www-authenticate: <wwwAuthenticateHeader([...])>' from `payment/wwwauthenticate`
266
- * - 'PAYMENT-REQUIRED: <paymentRequiredHeader({...})>' for x402 clients
267
- */
268
- declare function build402Body(input: Build402BodyInput): Record<string, unknown>;
173
+ }): Record<string, unknown>;
269
174
 
270
175
  /**
271
- * Canonical order-receipt shape returned to agents on the 200 after a successful settlement.
176
+ * Canonical receipt shape returned to agents on the 200 after settlement.
177
+ *
178
+ * Universal across vendor types: goods merchants populate the shipping +
179
+ * fulfillment slots, API merchants populate only the core fields (id,
180
+ * created_at, pricing, payment_status, next_steps). All goods-only fields are
181
+ * optional.
272
182
  *
273
- * Merchants own their order schema, but converging on this shape across AgentScore-gated
274
- * merchants means agents can render and post-process orders consistently. Lift this type,
275
- * fill the fields you care about, and ignore (or extend via `extras`) what you don't.
183
+ * Merchants own their order schema, but converging on this shape across
184
+ * AgentScore-gated merchants means agents can render and post-process receipts
185
+ * consistently regardless of whether the seller ships product or returns API
186
+ * output. Lift this type, fill the fields you care about, and ignore (or
187
+ * extend via `extras`) what you don't.
276
188
  *
277
- * All money fields are dollar-strings (e.g. `"250.00"`). Use `buildPricingBlock` from
278
- * `@agent-score/commerce/challenge` to compose the pricing fields from cents.
189
+ * All money fields are dollar-strings (e.g. `"250.00"`). Use
190
+ * `buildPricingBlock` from `@agent-score/commerce/challenge` to compose the
191
+ * pricing fields from cents.
279
192
  */
280
193
 
281
- interface OrderReceipt {
282
- /** Stable order id UUID, slug, or platform-native (Commerce7 order id, etc.). */
194
+ interface Receipt {
195
+ /** Stable receipt id; order UUID for goods, request id for API merchants. */
283
196
  id: string;
284
- /** ISO-8601 timestamp of order creation. */
197
+ /** ISO-8601 timestamp of settlement. */
285
198
  created_at: string;
286
- /** Quantity purchased. */
199
+ /** Goods: units purchased. API: usage count (calls, tokens, requests). */
287
200
  quantity?: number;
288
- /** Product info the agent confirmed they were buying this in the 402, surface again on receipt. */
201
+ /** Goods-shaped product info. Omit for API merchants (per-call billing has no product concept). */
289
202
  product?: {
290
203
  id?: string;
291
204
  name?: string;
292
205
  slug?: string;
293
206
  };
294
- /** Pricing block same shape as the 402 advertised. Use `buildPricingBlock` to compose. */
207
+ /** Pricing block; same shape as the 402 advertised. Use `buildPricingBlock` to compose. */
295
208
  pricing?: PricingBlock;
296
209
  /** Buyer email if provided. */
297
210
  email?: string;
298
- /** Payment status typically `"completed"`, `"pending"`, `"failed"`. */
211
+ /** Payment status; typically `"completed"`, `"pending"`, `"failed"`. */
299
212
  payment_status?: string;
300
- /** Fulfillment status — typically `"pending"`, `"shipped"`, `"delivered"`, `"cancelled"`. */
213
+ /** Goods-only. Typically `"pending"`, `"shipped"`, `"delivered"`, `"cancelled"`. */
301
214
  fulfillment_status?: string;
302
- /** Carrier tracking number when fulfillment_status >= shipped. */
215
+ /** Goods-only. Carrier tracking number when fulfillment_status >= shipped. */
303
216
  tracking_number?: string | null;
304
- /** Shipping address — physical-goods merchants. Omit for digital goods. */
217
+ /** Goods-only. Omit for digital goods, services, or API receipts. */
305
218
  shipping?: {
306
219
  name?: string;
307
220
  address_1?: string;
@@ -311,12 +224,13 @@ interface OrderReceipt {
311
224
  zip?: string;
312
225
  country?: string;
313
226
  };
314
- /** Optional gift note / order memo. */
227
+ /** Goods-only. Omit for API receipts. */
315
228
  gift_note?: string | null;
316
- /** Vendor-specific extras merged at the top level (loyalty points, warranty, etc.). */
229
+ /** Vendor-specific extras merged at the top level (loyalty points, warranty, per-call usage breakdown, etc.). */
317
230
  extras?: Record<string, unknown>;
318
- /** Next-steps block guiding the agent on what to do post-purchase. */
231
+ /** Next-steps block guiding the agent post-settlement. Matches the shape returned by `buildSuccessNextSteps` so vendors can spread that helper's output verbatim. `order_status_url` works for both: goods → order detail route, API → usage / billing dashboard. `fulfillment_eta` is goods-only. */
319
232
  next_steps?: {
233
+ action?: string;
320
234
  user_message?: string;
321
235
  order_status_url?: string;
322
236
  fulfillment_eta?: string;
@@ -331,43 +245,46 @@ interface OrderReceipt {
331
245
  * The seam is fiddly enough to get wrong by hand:
332
246
  * - mppx's `compose()(req)` returns a 402 Response with WWW-Authenticate directives
333
247
  * whose ids mppx's server-side validator REMEMBERS — they round-trip in client
334
- * credentials. Overwriting that header (e.g. with `buildPaymentHeaders` output)
335
- * breaks the round-trip.
248
+ * credentials. Overwriting that header breaks the round-trip.
336
249
  * - x402 needs the binary-friendly `PAYMENT-REQUIRED` header (base64-encoded JSON
337
250
  * of `{x402Version, accepts, resource}`) — mppx doesn't emit it.
338
251
  * - Merchants want a richer JSON body (pricing, identity metadata, agent_instructions,
339
252
  * agent_memory, retry_body, accepted_methods cross-reference) than the bare mppx body.
340
253
  *
341
- * `respond402` composes all three in one call:
342
- * - PRESERVES mppx's WWW-Authenticate verbatim
343
- * - ADDS PAYMENT-REQUIRED when x402 entries are present
344
- * - REPLACES the body with the rich body via `build402Body`
254
+ * `respond402` composes all three and returns a framework-neutral `Respond402Result`
255
+ * (body + headers + status) that the merchant wraps in their framework's response shape.
345
256
  *
346
257
  * Usage:
347
258
  * ```ts
348
- * const result = await m.compose(['tempo/charge', {...}], ['stripe/charge', {...}])(c.req.raw);
349
- * if (result.status === 402) {
350
- * return commerce.respond402({
351
- * mppxChallenge: result.challenge,
352
- * x402: { version: 2, accepts: x402Accepts, resource: { url: c.req.url, mimeType: 'application/json' } },
353
- * body: { acceptedMethods, agentInstructions, identityMetadata, pricing, agentMemory, retryBody, ... },
259
+ * const challenge = await m.compose(['tempo/charge', {...}], ['stripe/charge', {...}])(c.req.raw);
260
+ * if (challenge.status === 402) {
261
+ * const result = respond402({
262
+ * mppxChallengeHeaders: Object.fromEntries(challenge.headers),
263
+ * body: build402Body({ ... }),
264
+ * x402: { x402Version: 2, accepts: x402Accepts, resource: { url: c.req.url, mimeType: 'application/json' } },
354
265
  * });
266
+ * return new Response(JSON.stringify(result.body), { status: result.status, headers: result.headers });
355
267
  * }
356
268
  * ```
357
269
  */
358
270
 
359
- interface Respond402Input {
360
- /** The 402 Response returned by `mppx.compose()(req)`. Its WWW-Authenticate header
361
- * is preserved verbatim — mppx's server-side validator matches credentials to the
362
- * directive ids it generated, so overwriting breaks the round-trip. */
363
- mppxChallenge: Response;
364
- /** Inputs to `build402Body` — the rich JSON body sent to the agent. */
365
- body: Build402BodyInput;
271
+ /** Framework-neutral 402 response shape — body + headers + status. */
272
+ interface Respond402Result {
273
+ body: Record<string, unknown>;
274
+ headers: Record<string, string>;
275
+ status: 402;
276
+ }
277
+ declare function respond402({ mppxChallengeHeaders, body, x402, }: {
278
+ /** Headers from mppx's 402 Response (`Object.fromEntries(challenge.headers)`). The
279
+ * `WWW-Authenticate` directives are preserved verbatim — mppx's server-side validator
280
+ * matches credentials to the ids it generated. */
281
+ mppxChallengeHeaders: Record<string, string>;
282
+ /** The already-built 402 body — call `build402Body({...})` to construct it. */
283
+ body: Record<string, unknown>;
366
284
  /** When set, layers on the x402 PAYMENT-REQUIRED header (base64-encoded JSON).
367
285
  * Omit for merchants that don't accept x402 (Base/Solana) — mppx-only setups. */
368
- x402?: PaymentRequiredHeaderInput;
369
- }
370
- declare function respond402(input: Respond402Input): Response;
286
+ x402?: Parameters<typeof paymentRequiredHeader>[0];
287
+ }): Respond402Result;
371
288
 
372
289
  /**
373
290
  * Build a structured 4xx validation-error body that pairs cleanly with the
@@ -380,22 +297,6 @@ declare function respond402(input: Respond402Input): Response;
380
297
  * `Response.json(body, {status: 400})` for the Web Fetch path, etc.). Status
381
298
  * stays the merchant's call because the same shape works for 400/404/409/422.
382
299
  */
383
- interface BuildValidationErrorInput {
384
- /** Machine-readable error code (e.g. 'bad_request', 'not_found', 'out_of_stock'). */
385
- code: string;
386
- /** Human-readable message — surfaced directly to the user via the agent. */
387
- message: string;
388
- /** Optional schema description of required body fields, keyed by field name. Surfaced
389
- * so agents can self-correct without fetching docs. */
390
- requiredFields?: Record<string, string>;
391
- /** Optional concrete example body. Pairs with `requiredFields` for max self-serve. */
392
- exampleBody?: unknown;
393
- /** Optional next-step hint block (`{action, user_message?, ...vendor_extras}`). */
394
- nextSteps?: Record<string, unknown>;
395
- /** Vendor-specific top-level fields merged into the body (e.g. `available`,
396
- * `blocked_states`, `max_length`). */
397
- extra?: Record<string, unknown>;
398
- }
399
300
  interface ValidationErrorBody {
400
301
  error: {
401
302
  code: string;
@@ -421,6 +322,13 @@ interface ValidationErrorBody {
421
322
  * }), 400);
422
323
  * ```
423
324
  */
424
- declare function buildValidationError(input: BuildValidationErrorInput): ValidationErrorBody;
325
+ declare function buildValidationError({ code, message, requiredFields, exampleBody, nextSteps, extra, }: {
326
+ code: string;
327
+ message: string;
328
+ requiredFields?: Record<string, string>;
329
+ exampleBody?: unknown;
330
+ nextSteps?: Record<string, unknown>;
331
+ extra?: Record<string, unknown>;
332
+ }): ValidationErrorBody;
425
333
 
426
- export { type AcceptedMethodEntry, AgentInstructions, AgentMemoryHint, type Build402BodyInput, type BuildAcceptedMethodsInput, type BuildPricingBlockInput, type BuildValidationErrorInput, type FirstEncounterAgentMemoryInput, type IdentityMetadataBlock, type IdentityMetadataInput, type IdentityMode, type OrderReceipt, type PricingBlock, type Respond402Input, type SignerMatchResultLike, type SolanaMppMethodEntry, type StripeMethodEntry, type TempoMethodEntry, type ValidationErrorBody, type X402MethodEntry, build402Body, buildAcceptedMethods, buildIdentityMetadata, buildPricingBlock, buildValidationError, firstEncounterAgentMemory, respond402 };
334
+ export { type AcceptedMethodEntry, AgentInstructions, AgentMemoryHint, type IdentityMetadataBlock, type IdentityMode, PricingBlock, type Receipt, type Respond402Result, type SignerMatchResultLike, type SolanaMppMethodEntry, type StripeMethodEntry, type TempoMethodEntry, type ValidationErrorBody, type X402MethodEntry, build402Body, buildAcceptedMethods, buildIdentityMetadata, buildValidationError, firstEncounterAgentMemory, respond402 };