@agent-score/commerce 2.0.2 → 2.1.1

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 (116) hide show
  1. package/README.md +26 -11
  2. package/dist/_core-kI7FRAiZ.d.mts +10 -0
  3. package/dist/_core-kI7FRAiZ.d.ts +10 -0
  4. package/dist/challenge/index.d.mts +3 -3
  5. package/dist/challenge/index.d.ts +3 -3
  6. package/dist/challenge/index.js +21 -14
  7. package/dist/challenge/index.js.map +1 -1
  8. package/dist/challenge/index.mjs +21 -14
  9. package/dist/challenge/index.mjs.map +1 -1
  10. package/dist/{checkout-jNUIql6D.d.mts → checkout-BRw_caGr.d.mts} +13 -33
  11. package/dist/{checkout-DhSj_h94.d.ts → checkout-CuSNUJFX.d.ts} +13 -33
  12. package/dist/core.js +1 -1
  13. package/dist/core.js.map +1 -1
  14. package/dist/core.mjs +1 -1
  15. package/dist/core.mjs.map +1 -1
  16. package/dist/default_rails-C5gKZJMI.d.ts +198 -0
  17. package/dist/default_rails-XFCuRddA.d.mts +198 -0
  18. package/dist/discovery/index.d.mts +5 -5
  19. package/dist/discovery/index.d.ts +5 -5
  20. package/dist/discovery/index.js +14 -1
  21. package/dist/discovery/index.js.map +1 -1
  22. package/dist/discovery/index.mjs +14 -1
  23. package/dist/discovery/index.mjs.map +1 -1
  24. package/dist/identity/express.d.mts +7 -3
  25. package/dist/identity/express.d.ts +7 -3
  26. package/dist/identity/express.js +39 -96
  27. package/dist/identity/express.js.map +1 -1
  28. package/dist/identity/express.mjs +37 -87
  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 +60 -96
  33. package/dist/identity/fastify.js.map +1 -1
  34. package/dist/identity/fastify.mjs +58 -87
  35. package/dist/identity/fastify.mjs.map +1 -1
  36. package/dist/identity/hono.d.mts +11 -3
  37. package/dist/identity/hono.d.ts +11 -3
  38. package/dist/identity/hono.js +39 -93
  39. package/dist/identity/hono.js.map +1 -1
  40. package/dist/identity/hono.mjs +37 -84
  41. package/dist/identity/hono.mjs.map +1 -1
  42. package/dist/identity/nextjs.d.mts +10 -3
  43. package/dist/identity/nextjs.d.ts +10 -3
  44. package/dist/identity/nextjs.js +49 -93
  45. package/dist/identity/nextjs.js.map +1 -1
  46. package/dist/identity/nextjs.mjs +46 -84
  47. package/dist/identity/nextjs.mjs.map +1 -1
  48. package/dist/identity/policy.js +22 -23317
  49. package/dist/identity/policy.js.map +1 -1
  50. package/dist/identity/policy.mjs +1 -23320
  51. package/dist/identity/policy.mjs.map +1 -1
  52. package/dist/identity/web.d.mts +9 -3
  53. package/dist/identity/web.d.ts +9 -3
  54. package/dist/identity/web.js +45 -93
  55. package/dist/identity/web.js.map +1 -1
  56. package/dist/identity/web.mjs +42 -84
  57. package/dist/identity/web.mjs.map +1 -1
  58. package/dist/index.d.mts +621 -90
  59. package/dist/index.d.ts +621 -90
  60. package/dist/index.js +1202 -328
  61. package/dist/index.js.map +1 -1
  62. package/dist/index.mjs +1188 -327
  63. package/dist/index.mjs.map +1 -1
  64. package/dist/middleware/express.d.mts +10 -0
  65. package/dist/middleware/express.d.ts +10 -0
  66. package/dist/middleware/express.js +128 -0
  67. package/dist/middleware/express.js.map +1 -0
  68. package/dist/middleware/express.mjs +91 -0
  69. package/dist/middleware/express.mjs.map +1 -0
  70. package/dist/middleware/fastify.d.mts +10 -0
  71. package/dist/middleware/fastify.d.ts +10 -0
  72. package/dist/middleware/fastify.js +127 -0
  73. package/dist/middleware/fastify.js.map +1 -0
  74. package/dist/middleware/fastify.mjs +90 -0
  75. package/dist/middleware/fastify.mjs.map +1 -0
  76. package/dist/middleware/hono.d.mts +10 -0
  77. package/dist/middleware/hono.d.ts +10 -0
  78. package/dist/middleware/hono.js +122 -0
  79. package/dist/middleware/hono.js.map +1 -0
  80. package/dist/middleware/hono.mjs +85 -0
  81. package/dist/middleware/hono.mjs.map +1 -0
  82. package/dist/middleware/nextjs.d.mts +22 -0
  83. package/dist/middleware/nextjs.d.ts +22 -0
  84. package/dist/middleware/nextjs.js +143 -0
  85. package/dist/middleware/nextjs.js.map +1 -0
  86. package/dist/middleware/nextjs.mjs +105 -0
  87. package/dist/middleware/nextjs.mjs.map +1 -0
  88. package/dist/middleware/web.d.mts +25 -0
  89. package/dist/middleware/web.d.ts +25 -0
  90. package/dist/middleware/web.js +128 -0
  91. package/dist/middleware/web.js.map +1 -0
  92. package/dist/middleware/web.mjs +91 -0
  93. package/dist/middleware/web.mjs.map +1 -0
  94. package/dist/payment/index.d.mts +32 -21
  95. package/dist/payment/index.d.ts +32 -21
  96. package/dist/payment/index.js +215 -12
  97. package/dist/payment/index.js.map +1 -1
  98. package/dist/payment/index.mjs +205 -12
  99. package/dist/payment/index.mjs.map +1 -1
  100. package/dist/{pricing-CxzwyiO6.d.mts → pricing-4n5Ota0D.d.mts} +14 -4
  101. package/dist/{pricing-CQ9DIFaw.d.ts → pricing-DHfH3ogG.d.ts} +14 -4
  102. package/dist/{rail_spec-XP0wKgJV.d.mts → rail_spec-D6qzh3J0.d.mts} +1 -1
  103. package/dist/{rail_spec-XP0wKgJV.d.ts → rail_spec-D6qzh3J0.d.ts} +1 -1
  104. package/dist/stripe-multichain/index.d.mts +150 -47
  105. package/dist/stripe-multichain/index.d.ts +150 -47
  106. package/dist/stripe-multichain/index.js +19799 -43
  107. package/dist/stripe-multichain/index.js.map +1 -1
  108. package/dist/stripe-multichain/index.mjs +19808 -28
  109. package/dist/stripe-multichain/index.mjs.map +1 -1
  110. package/dist/{x402_server-hgQzWQwB.d.mts → x402_server-Ciz2mls2.d.mts} +1 -1
  111. package/dist/{x402_server-hgQzWQwB.d.ts → x402_server-Ciz2mls2.d.ts} +1 -1
  112. package/package.json +43 -5
  113. package/dist/_response-BFYN3b6i.d.mts +0 -142
  114. package/dist/_response-_iPD5AIj.d.ts +0 -142
  115. package/dist/solana-Cds87OTu.d.mts +0 -67
  116. package/dist/solana-Cds87OTu.d.ts +0 -67
package/dist/index.d.mts CHANGED
@@ -1,21 +1,198 @@
1
- export { AccountVerification, AgentIdentity, AgentMemoryHint, AgentScoreCore, AssessResult, CreateSessionOnMissing, DenialCode, DenialReason, EvaluateOutcome, OperatorVerification, PolicyCheck, PolicyResult, SignerVerdict, VerifyWalletSignerResult, buildAgentMemoryHint } from './core.mjs';
1
+ import { VerifyWalletSignerResult, DenialReason } from './core.mjs';
2
+ export { AccountVerification, AgentIdentity, AgentMemoryHint, AgentScoreCore, AssessResult, CreateSessionOnMissing, DenialCode, EvaluateOutcome, OperatorVerification, PolicyCheck, PolicyResult, SignerVerdict, buildAgentMemoryHint } from './core.mjs';
2
3
  export { P as PaymentSigner, S as SignerNetwork, e as extractPaymentSigner, a as extractPaymentSignerFromAuth, b as extractSignerForPrecheck, r as readX402PaymentHeader } from './signer-3FAit11j.mjs';
3
- export { F as FIXABLE_DENIAL_REASONS, b as buildContactSupportNextSteps, a as buildSignerMismatchBody, d as denialReasonStatus, c as denialReasonToBody, i as isFixableDenial, v as verificationAgentInstructions } from './_response-BFYN3b6i.mjs';
4
- import { U as UCPSigningKey, a as UCPProfile } from './checkout-jNUIql6D.mjs';
5
- export { A as AGENTSCORE_UCP_CAPABILITY, b as AgentScoreGatePolicy, C as Checkout, c as CheckoutContext, d as CheckoutGateConfig, e as CheckoutRailSpec, f as CheckoutRequest, g as CheckoutResult, h as CheckoutValidationError, i as ComposeMppxFn, D as DiscoveryProbeConfig, G as GateDenial, I as IsCachedAddressFn, M as MountUcpRoutesOptions, j as MppxComposeOutcome, O as OnSettledFn, P as PreValidateFn, k as PricingFn, l as PricingResult, R as RecipientsFn, m as ReferenceIdFn, n as RunGateFn, S as SettleOutcome, o as UCPCapabilityBinding, p as UCPPaymentHandlerBinding, q as UCPProfileBody, r as UCPServiceBinding, s as buildUCPProfile, t as getIdentityStatus, u as makeMppxComposeHook, v as mppPaymentHandler, w as pricingResult, x as stripeSptPaymentHandler, y as validationEnvelope, z as validationResponseExpress, B as validationResponseFastify, E as validationResponseHono, F as validationResponseNextjs, H as validationResponseWeb, J as x402PaymentHandler } from './checkout-jNUIql6D.mjs';
4
+ import { q as UCPSigningKey, n as UCPProfile } from './checkout-BRw_caGr.mjs';
5
+ export { A as AGENTSCORE_UCP_CAPABILITY, a as AgentScoreGatePolicy, C as Checkout, b as CheckoutContext, c as CheckoutGateConfig, d as CheckoutRailSpec, e as CheckoutRequest, f as CheckoutResult, g as ComposeMppxFn, D as DiscoveryProbeConfig, G as GateDenial, I as IsCachedAddressFn, M as MountUcpRoutesOptions, h as MppxComposeOutcome, O as OnSettledFn, P as PreValidateFn, i as PricingFn, j as PricingResult, R as RecipientsFn, k as ReferenceIdFn, l as RunGateFn, S as SettleOutcome, U as UCPCapabilityBinding, m as UCPPaymentHandlerBinding, o as UCPProfileBody, p as UCPServiceBinding, r as buildUCPProfile, s as getIdentityStatus, t as makeMppxComposeHook, u as mppPaymentHandler, v as pricingResult, w as stripeSptPaymentHandler, x as validationEnvelope, y as validationResponseExpress, z as validationResponseFastify, B as validationResponseHono, E as validationResponseNextjs, F as validationResponseWeb, H as x402PaymentHandler } from './checkout-BRw_caGr.mjs';
6
6
  export { EnforcementMode, GateResult, IdentityStatus, PolicyBlock, buildGateFromPolicy, runGateWithEnforcement, shippingCountryAllowed, shippingStateAllowed, validateShippingAgainstPolicy } from './identity/policy.mjs';
7
- export { S as SolanaMppRailSpec, b as StripeRailSpec, T as TempoRailSpec, a as TempoSessionRailSpec, X as X402BaseRailSpec } from './rail_spec-XP0wKgJV.mjs';
8
- export { f as formatUsdCents, l as loadSolanaFeePayer } from './solana-Cds87OTu.mjs';
9
- import './pricing-CxzwyiO6.mjs';
10
- import './x402_server-hgQzWQwB.mjs';
7
+ import { H as HeadersLike } from './default_rails-XFCuRddA.mjs';
8
+ export { c as buildDefaultCheckoutRails, d as buildMppxComposeRails, f as formatUsdCents, h as hasMppxHeader, e as hasPaymentHeader, g as hasX402Header, l as loadSolanaFeePayer } from './default_rails-XFCuRddA.mjs';
9
+ import { T as TempoRailSpec, X as X402BaseRailSpec, S as SolanaMppRailSpec, b as StripeRailSpec } from './rail_spec-D6qzh3J0.mjs';
10
+ export { c as TempoSessionRailSpec } from './rail_spec-D6qzh3J0.mjs';
11
+ import { Context } from 'hono';
12
+ import './pricing-4n5Ota0D.mjs';
13
+ import './x402_server-Ciz2mls2.mjs';
14
+
15
+ /**
16
+ * Universal denial helpers shared across every adapter.
17
+ *
18
+ * What lives here:
19
+ * - `FIXABLE_DENIAL_REASONS` / `isFixableDenial` — classifier for compliance reasons that can
20
+ * be resolved by re-completing KYC (vs sanctions / age failures which are permanent).
21
+ * - `denialReasonStatus` — picks the right HTTP status code per denial code (401 for credential
22
+ * problems, 503 for transient API errors, 403 for everything else).
23
+ * - `buildSignerMismatchBody` — produces the standard 403 body for a non-pass signer_match
24
+ * verdict (read via `getSignerVerdict`).
25
+ * - `buildContactSupportNextSteps` — standard `next_steps.action: "contact_support"` shape for
26
+ * unfixable compliance denials.
27
+ * - `verificationAgentInstructions` — the canned `agent_instructions` block for
28
+ * identity-verification 403s. Vendors can override individual fields.
29
+ *
30
+ * Adapters use `denialReasonStatus` inside their default `onDenied` so vendors get the right
31
+ * status code for free. The body builders are exported from each adapter so vendors who write
32
+ * a custom `onDenied` can compose them without copy-paste.
33
+ */
34
+
35
+ /**
36
+ * Compliance denial reasons that can be resolved by re-completing KYC. The API emits these
37
+ * when KYC is missing/pending/failed; the user can re-verify and retry.
38
+ *
39
+ * `jurisdiction_restricted` is NOT in this set — the API only emits it AFTER KYC is verified,
40
+ * meaning the user's KYC'd country is in the merchant's blocked list (or absent from the
41
+ * allowed list). Re-doing KYC won't change the country, so it's permanent. Same shape as
42
+ * `sanctions_flagged` and `age_insufficient` — surface contact_support, don't waste a
43
+ * /v1/sessions mint.
44
+ */
45
+ declare const FIXABLE_DENIAL_REASONS: ReadonlySet<string>;
46
+ /**
47
+ * Returns true when a `wallet_not_trusted` denial's reasons are all fixable via KYC
48
+ * re-verification. False when any reason is permanent (sanctions, age, jurisdiction_restricted).
49
+ *
50
+ * Empty reasons returns false — without a known reason we can't promise a fix, so default to
51
+ * the bare denial path (vendors can override via custom onDenied if they want different
52
+ * behavior on empty reasons).
53
+ */
54
+ declare function isFixableDenial(reasons: readonly string[] | undefined): boolean;
55
+ /**
56
+ * The right HTTP status code for a denial. `defaultOnDenied` in every adapter uses this so
57
+ * vendors get correct status codes without writing per-code branches.
58
+ *
59
+ * - 401 for credential problems the agent can recover from (`token_expired`, `invalid_credential`)
60
+ * - 503 for transient `api_error`
61
+ * - 403 for everything else (identity required, compliance fail, signer mismatch, etc.)
62
+ */
63
+ declare function denialReasonStatus(reason: DenialReason): 401 | 403 | 503;
64
+ /**
65
+ * Standard 403 body for a non-pass signer-match verdict. Returns null for `pass` so vendors
66
+ * can call it unconditionally:
67
+ *
68
+ * const verdict = getSignerVerdict(c);
69
+ * if (verdict?.signer_match) {
70
+ * const mismatchBody = buildSignerMismatchBody({ result: verdict.signer_match });
71
+ * if (mismatchBody) return c.json(mismatchBody, 403);
72
+ * }
73
+ *
74
+ * Body shape mirrors the gate's denial bodies: top-level error.code, all signer-match fields
75
+ * (`claimed_operator`, `actual_signer_operator`, `expected_signer`, `actual_signer`,
76
+ * `linked_wallets`), plus a `next_steps` action describing the recovery path.
77
+ */
78
+ declare function buildSignerMismatchBody({ result, userMessage, learnMoreUrl, }: {
79
+ /** Projected signer_match verdict (from `getSignerVerdict(ctx).signer_match`). Only non-pass
80
+ * kinds produce a body. */
81
+ result: VerifyWalletSignerResult;
82
+ /** Optional override for the human-facing `next_steps.user_message`. */
83
+ userMessage?: string;
84
+ /** Optional override for `next_steps.learn_more_url`. Default: AgentScore agent-identity guide. */
85
+ learnMoreUrl?: string;
86
+ }): Record<string, unknown> | null;
87
+ /**
88
+ * Standard `next_steps` block for unfixable compliance denials (sanctions, age, etc.). Vendors
89
+ * spread this into a 403 body alongside the usual `error`/`reasons` fields.
90
+ *
91
+ * return c.json({
92
+ * error: { code: 'compliance_denied', message: '...' },
93
+ * reasons,
94
+ * next_steps: buildContactSupportNextSteps('support@example.com'),
95
+ * }, 403);
96
+ */
97
+ declare function buildContactSupportNextSteps(supportEmail: string, message?: string): {
98
+ action: 'contact_support';
99
+ support_email: string;
100
+ user_message: string;
101
+ };
102
+ /**
103
+ * The canonical `agent_instructions` block for identity-verification 403s. Tells the agent how to
104
+ * present the verify_url, poll for the operator_token, and retry the original request. Universal
105
+ * across every AgentScore-gated merchant — overrides let vendors add merchant-specific steps
106
+ * (e.g. "include order_id when retrying").
107
+ */
108
+ declare function verificationAgentInstructions({ userAction, retryStep, extraSteps, pollIntervalSeconds, timeoutSeconds, orderTtl, extra, }?: {
109
+ /** Override the user-facing message. */
110
+ userAction?: string;
111
+ /** Replace the generic "Retry the original merchant request..." step with a merchant-specific
112
+ * one (e.g. "Retry POST /purchase with X-Operator-Token AND include order_id..."). When set,
113
+ * this REPLACES baseSteps[4] rather than appending — use it instead of `extraSteps[0]` when
114
+ * your retry instruction is a refinement of the canonical retry, not an additional step. */
115
+ retryStep?: string;
116
+ /** Append additional steps after the retry step. Use this for genuinely additional steps
117
+ * (e.g. "After payment the same call returns 200 with the order"), not for re-stating the
118
+ * retry — use `retryStep` for that. */
119
+ extraSteps?: string[];
120
+ /** Override the poll cadence. Default 5 seconds. */
121
+ pollIntervalSeconds?: number;
122
+ /** Override how long the agent should keep polling. Default 3600 seconds (1 hour). */
123
+ timeoutSeconds?: number;
124
+ /** Optional `order_ttl` note describing how long pending orders survive. */
125
+ orderTtl?: string;
126
+ /** Arbitrary additional fields merged into the instructions object. */
127
+ extra?: Record<string, unknown>;
128
+ }): {
129
+ action: 'poll_for_credential';
130
+ user_action: string;
131
+ steps: string[];
132
+ poll_interval_seconds: number;
133
+ poll_secret_header: 'X-Poll-Secret';
134
+ retry_token_header: 'X-Operator-Token';
135
+ timeout_seconds: number;
136
+ order_ttl?: string;
137
+ [key: string]: unknown;
138
+ };
139
+
140
+ /**
141
+ * Shared DenialReason → response body serialization for all adapters.
142
+ *
143
+ * Keeps Hono / Express / Fastify / Web / Next.js defaults aligned — a field added
144
+ * here shows up in every adapter's 403 body automatically, and there's one place
145
+ * to test the marshaling.
146
+ *
147
+ * Body shape: `{ error: { code, message }, ... }` — matches the canonical AgentScore
148
+ * error envelope so downstream agents see one consistent `error.code` +
149
+ * `error.message` pair regardless of which layer produced the denial.
150
+ */
151
+
152
+ /**
153
+ * Build the canonical 4xx body shape for `identity_verification_required`.
154
+ *
155
+ * Every merchant maps the gate's auto-minted session fields (verify_url,
156
+ * session_id, poll_secret, poll_url, agent_instructions) into their own
157
+ * envelope with a merchant-specific message + error code. This collapses that
158
+ * mapping into one call:
159
+ *
160
+ * ```ts
161
+ * if (reason.code === 'identity_verification_required') {
162
+ * return {
163
+ * status: 403,
164
+ * body: buildVerificationRequiredBody(reason, {
165
+ * message: 'Identity verification is required to call this endpoint.',
166
+ * agentInstructions: VERIFICATION_AGENT_INSTRUCTIONS,
167
+ * }),
168
+ * };
169
+ * }
170
+ * ```
171
+ *
172
+ * Goods merchants that surface an `order_id` (or similar) from
173
+ * `createSessionOnMissing.onBeforeSession` get it for free via
174
+ * `denialReasonToBody(reason)`'s `reason.extra` passthrough — but can also
175
+ * pass `opts.extra` for fallbacks (e.g. when invoked outside the auto-mint
176
+ * path and order_id needs to come from the validated context).
177
+ */
178
+ declare function buildVerificationRequiredBody(reason: DenialReason, opts?: {
179
+ /** Override the `error.message`. Defaults to the canonical copy. */
180
+ message?: string;
181
+ /** Replace `agent_instructions` with merchant-specific copy. When omitted,
182
+ * the gate-supplied or default instructions ride through. */
183
+ agentInstructions?: string;
184
+ /** Additional fields spread into the body (e.g. fallback `order_id`). */
185
+ extra?: Record<string, unknown>;
186
+ }): Record<string, unknown>;
187
+ declare function denialReasonToBody(reason: DenialReason): Record<string, unknown>;
11
188
 
12
189
  /**
13
190
  * Google A2A (Agent-to-Agent) v1.0 Agent Card builder.
14
191
  *
15
- * Compose the JSON payload for an A2A v1.0 Agent Card per the canonical proto at
16
- * https://github.com/a2aproject/A2A/blob/main/specification/a2a.proto. Returned object
17
- * is the unsigned card body — wrap with an A2A `AgentCardSignature` (RFC 7515 JWS)
18
- * to sign vendor-side before publishing at /.well-known/agent-card.json.
192
+ * Compose the JSON payload for an A2A v1.0 Agent Card matching the canonical
193
+ * `AgentCard` type from `@a2a-js/sdk`. Returned object is the unsigned card body —
194
+ * wrap with an `A2AAgentCardSignature` (RFC 7515 JWS) to sign vendor-side before
195
+ * publishing at /.well-known/agent-card.json.
19
196
  *
20
197
  * Why publish: A2A is a Linux Foundation standard. Signed Agent Cards let any
21
198
  * A2A-compatible reader discover an agent's capabilities + protocol bindings without
@@ -24,41 +201,43 @@ import './x402_server-hgQzWQwB.mjs';
24
201
  * so platforms detect UCP support without re-fetching the profile.
25
202
  *
26
203
  * Spec reference: https://a2a-protocol.org/latest/
204
+ * Authoritative types: https://www.npmjs.com/package/@a2a-js/sdk (interface `AgentCard`).
27
205
  */
28
206
  /** Canonical UCP A2A extension URI — verifiers look for this exact URI in
29
207
  * `capabilities.extensions[]` to detect UCP support on the agent card. Pinned
30
208
  * to the 2026-04-08 spec snapshot. */
31
209
  declare const UCP_A2A_EXTENSION_URI = "https://ucp.dev/2026-04-08/specification/reference";
32
- /** Per spec §4.4.6. Each entry advertises one protocol binding the agent supports.
33
- * `supported_interfaces[0]` is the preferred binding (ordered list). */
210
+ /** One transport+URL combination the agent exposes. Lives in `AgentCard.additionalInterfaces[]`
211
+ * for multi-binding agents; the PRIMARY transport+URL pair lives on `AgentCard.url` +
212
+ * `AgentCard.preferredTransport`. */
34
213
  interface A2AAgentInterface {
35
- /** Interface URL (https in production). */
36
- url: string;
37
214
  /** Open string — core values are `JSONRPC`, `GRPC`, `HTTP+JSON`. */
38
- protocol_binding: string;
39
- /** A2A protocol version, e.g. `"1.0"`. Distinct from the agent's own version. */
40
- protocol_version: string;
41
- tenant?: string;
215
+ transport: string;
216
+ /** Absolute URL where this transport is available. */
217
+ url: string;
42
218
  }
43
- /** Per spec §4.4.2. The org/service that provides the agent. */
219
+ /** Org/service that provides the agent. */
44
220
  interface A2AAgentProvider {
45
- url: string;
46
221
  organization: string;
222
+ url: string;
47
223
  }
48
- /** Per spec §4.4.5. A distinct capability or function the agent performs.
49
- * Lives at the TOP LEVEL of AgentCard (not inside `capabilities`). */
224
+ /** A distinct capability or function the agent performs. Lives at the TOP LEVEL of
225
+ * `AgentCard.skills[]` (not inside `capabilities`). */
50
226
  interface A2AAgentSkill {
51
227
  id: string;
52
228
  name: string;
53
229
  description: string;
54
230
  tags: string[];
55
231
  examples?: string[];
56
- input_modes?: string[];
57
- output_modes?: string[];
232
+ inputModes?: string[];
233
+ outputModes?: string[];
234
+ /** Security schemes scoped to this skill. List = OR of ANDs (each entry is a set of
235
+ * schemes that must all be satisfied). Follows OpenAPI 3.0 Security Requirement Object. */
236
+ security?: Record<string, string[]>[];
58
237
  }
59
- /** Per spec §4.4.4. A protocol extension the agent supports.
60
- * Lives in `capabilities.extensions[]`. `description` and `required` are
61
- * spec-mandated fields, not optional. */
238
+ /** A protocol extension the agent supports. Lives in `capabilities.extensions[]`.
239
+ * Canonical type marks `description` and `required` optional, but we keep them in the
240
+ * builder to make UCP discovery deterministic. */
62
241
  interface A2AAgentCardExtension {
63
242
  uri: string;
64
243
  description: string;
@@ -83,24 +262,16 @@ declare function ucpA2AExtension(capabilities?: Record<string, Array<{
83
262
  }>>, options?: {
84
263
  required?: boolean;
85
264
  }): A2AAgentCardExtension;
86
- /** Per spec §4.4.3. Optional capabilities the agent supports.
87
- *
88
- * Per the canonical proto, `capabilities` declares: streaming, push_notifications,
89
- * extensions (the protocol extensions the agent supports), and extended_agent_card.
90
- * REST-style endpoint metadata does NOT belong here — A2A uses `supported_interfaces`
91
- * on the AgentCard for protocol bindings, and `skills` (top-level) for capability
92
- * descriptions. */
265
+ /** Optional capabilities the agent supports. */
93
266
  interface A2AAgentCardCapabilities {
94
- streaming?: boolean;
95
- push_notifications?: boolean;
96
267
  extensions?: A2AAgentCardExtension[];
97
- extended_agent_card?: boolean;
268
+ pushNotifications?: boolean;
269
+ stateTransitionHistory?: boolean;
270
+ streaming?: boolean;
98
271
  }
99
- /** Per spec §4.4.7. JWS signature embedded in an Agent Card.
100
- *
101
- * Multiple signatures MAY be attached to a single card. Verifiers reconstruct the
102
- * card body without `signatures` to verify each entry. Format follows RFC 7515 JSON
103
- * Web Signature (JWS). */
272
+ /** JWS signature embedded in an Agent Card. Multiple signatures MAY be attached;
273
+ * verifiers reconstruct the card body without `signatures` to verify each entry.
274
+ * Format follows RFC 7515. */
104
275
  interface A2AAgentCardSignature {
105
276
  /** Base64url-encoded JSON of the protected JWS header. REQUIRED. */
106
277
  protected: string;
@@ -109,35 +280,38 @@ interface A2AAgentCardSignature {
109
280
  /** Optional unprotected JWS header values. */
110
281
  header?: Record<string, unknown>;
111
282
  }
112
- /** Per spec §4.4.1. A2A v1.0 Agent Card body.
113
- *
114
- * Per spec §4.4.7, JWS signatures may be embedded directly in the card via the
115
- * `signatures` field; verifiers reconstruct the card body without `signatures` and
116
- * verify each entry. Per-vendor identity attestation can also be expressed via a
117
- * vendor extension entry inside `capabilities.extensions[]`. */
283
+ /** A2A v1.0 Agent Card body, matching `AgentCard` from `@a2a-js/sdk`. */
118
284
  interface A2AAgentCard {
119
285
  name: string;
120
286
  description: string;
121
- /** Ordered; first entry is preferred. */
122
- supported_interfaces: A2AAgentInterface[];
123
- /** Agent's own version, e.g. `"1.0.0"`. Distinct from the A2A protocol version,
124
- * which lives on each `A2AAgentInterface.protocol_version`. */
287
+ /** Preferred endpoint URL MUST support `preferredTransport`. */
288
+ url: string;
289
+ /** Transport at the primary `url`. Defaults to `JSONRPC` per spec when omitted by a reader. */
290
+ preferredTransport?: string;
291
+ /** A2A protocol version, e.g. `"1.0"`. Distinct from the agent's own `version`. */
292
+ protocolVersion: string;
293
+ /** Additional transport+URL bindings beyond the primary. */
294
+ additionalInterfaces?: A2AAgentInterface[];
295
+ /** Agent's own version, e.g. `"1.0.0"`. */
125
296
  version: string;
126
297
  capabilities: A2AAgentCardCapabilities;
127
- default_input_modes: string[];
128
- default_output_modes: string[];
129
- /** Per spec §4.4.1 (proto field 12, REQUIRED): the agent must declare ≥1 skill.
130
- * The convenience builder `buildA2AAgentCard` enforces non-empty. */
298
+ defaultInputModes: string[];
299
+ defaultOutputModes: string[];
300
+ /** REQUIRED non-empty. */
131
301
  skills: A2AAgentSkill[];
132
302
  provider?: A2AAgentProvider;
133
- documentation_url?: string;
134
- /** Per spec §4.4.1 (proto field 14, optional): URL to an icon for the agent. */
135
- icon_url?: string;
136
- /** Per spec §4.4.1 (proto field 13, optional) + §4.4.7: JWS signatures embedded
137
- * in the card. Compute over the canonical card body MINUS this field, then attach. */
303
+ documentationUrl?: string;
304
+ iconUrl?: string;
305
+ /** Agent can provide an extended card with additional details to authenticated users.
306
+ * Defaults to `false`. */
307
+ supportsAuthenticatedExtendedCard?: boolean;
308
+ /** JWS signatures embedded in the card. Compute over the canonical card body MINUS
309
+ * this field, then attach. */
138
310
  signatures?: A2AAgentCardSignature[];
139
- security_schemes?: Record<string, unknown>;
140
- security_requirements?: unknown[];
311
+ /** OpenAPI 3.0 security requirement objects (OR of ANDs). */
312
+ security?: Record<string, string[]>[];
313
+ /** Map of security scheme definitions (key = scheme name). */
314
+ securitySchemes?: Record<string, unknown>;
141
315
  /** Vendor-specific extras merged at top level. */
142
316
  [k: string]: unknown;
143
317
  }
@@ -146,55 +320,61 @@ interface BuildA2AAgentCardInput {
146
320
  name: string;
147
321
  /** Agent purpose/description. REQUIRED per spec. */
148
322
  description: string;
149
- /** The primary interface URL — becomes `supported_interfaces[0].url` (with
150
- * `protocol_binding=HTTP+JSON`, `protocol_version=1.0` by default). For
151
- * multi-binding agents, construct `A2AAgentCard` directly. */
323
+ /** Primary endpoint URL — becomes `AgentCard.url`. The transport at this URL is
324
+ * declared via `preferredTransport` (default `HTTP+JSON`). For multi-binding agents,
325
+ * pass `additionalInterfaces` for the secondary transports. */
152
326
  url: string;
153
327
  /** Top-level skill declarations — what the agent can do. REQUIRED per spec
154
328
  * (proto field 12 [field_behavior=REQUIRED]); must have ≥1 entry. */
155
329
  skills: A2AAgentSkill[];
156
- /** Agent's own version, e.g. `"1.0.0"`. Distinct from the A2A protocol version. */
330
+ /** Agent's own version, e.g. `"1.0.0"`. Distinct from the A2A `protocolVersion`. */
157
331
  version?: string;
332
+ /** Transport for the primary `url`. Defaults to `"HTTP+JSON"` for our merchants; the
333
+ * canonical A2A spec default when omitted by a reader is `"JSONRPC"`. */
334
+ preferredTransport?: string;
335
+ /** A2A protocol version. Defaults to `"1.0"`. */
336
+ protocolVersion?: string;
337
+ /** Additional transport+URL bindings beyond the primary. */
338
+ additionalInterfaces?: A2AAgentInterface[];
158
339
  /** A2A v1.0 capability extensions. Build the UCP entry with `ucpA2AExtension()`. */
159
340
  extensions?: A2AAgentCardExtension[];
160
- /** Capability flag: agent supports streaming responses. */
341
+ /** Capability flag: agent supports streaming responses (SSE). */
161
342
  streaming?: boolean;
162
343
  /** Capability flag: agent supports push notifications for async task updates. */
163
- push_notifications?: boolean;
164
- /** Capability flag: agent serves an extended (more detailed) card when authenticated. */
165
- extended_agent_card?: boolean;
344
+ pushNotifications?: boolean;
345
+ /** Capability flag: agent provides task state-transition history. */
346
+ stateTransitionHistory?: boolean;
347
+ /** AgentCard top-level flag: agent serves an extended card to authenticated users. */
348
+ supportsAuthenticatedExtendedCard?: boolean;
166
349
  /** Provider org for the agent. */
167
350
  provider?: A2AAgentProvider;
168
351
  /** URL to additional human-readable documentation. */
169
- documentation_url?: string;
352
+ documentationUrl?: string;
170
353
  /** URL to an icon for the agent. */
171
- icon_url?: string;
172
- /** JWS signatures embedded in the card (per spec §4.4.7). */
354
+ iconUrl?: string;
355
+ /** JWS signatures embedded in the card. */
173
356
  signatures?: A2AAgentCardSignature[];
174
357
  /** Default input media types (defaults to `["application/json"]`). */
175
- default_input_modes?: string[];
358
+ defaultInputModes?: string[];
176
359
  /** Default output media types (defaults to `["application/json"]`). */
177
- default_output_modes?: string[];
178
- /** Override the protocol binding for the auto-built primary interface (default `"HTTP+JSON"`). */
179
- protocol_binding?: string;
180
- /** Override the A2A protocol version for the auto-built primary interface (default `"1.0"`). */
181
- a2a_protocol_version?: string;
360
+ defaultOutputModes?: string[];
361
+ /** OpenAPI 3.0 security requirement objects (OR of ANDs). */
362
+ security?: Record<string, string[]>[];
182
363
  /** Per-scheme security details (key = scheme name). */
183
- security_schemes?: Record<string, unknown>;
184
- /** Required security requirements for invoking the agent. */
185
- security_requirements?: unknown[];
364
+ securitySchemes?: Record<string, unknown>;
186
365
  /** Vendor-specific extras merged at the card top level. */
187
366
  extras?: Record<string, unknown>;
188
367
  }
189
368
  /**
190
- * Compose an A2A v1.0 Agent Card body per the canonical proto.
369
+ * Compose an A2A v1.0 Agent Card body matching `AgentCard` from `@a2a-js/sdk`.
191
370
  *
192
371
  * Returns the UNSIGNED card. To attach identity claims, sign the serialized body
193
- * as an RFC 7515 JWS (`AgentCardSignature`). Vendors can also add an identity-flavored
372
+ * as an RFC 7515 JWS (`A2AAgentCardSignature`). Vendors can also add an identity-flavored
194
373
  * extension to `capabilities.extensions[]`.
195
374
  *
196
- * The single `url` argument becomes the primary `supported_interfaces[0].url`
197
- * (with `protocol_binding=HTTP+JSON`, `protocol_version=1.0` by default).
375
+ * The `url` argument becomes the top-level `AgentCard.url`; `preferredTransport`
376
+ * declares the transport at that URL (default `HTTP+JSON`). For multi-binding agents,
377
+ * pass `additionalInterfaces`.
198
378
  *
199
379
  * Example:
200
380
  * ```ts
@@ -214,6 +394,8 @@ interface BuildA2AAgentCardInput {
214
394
  * ```
215
395
  */
216
396
  declare function buildA2AAgentCard(input: BuildA2AAgentCardInput): A2AAgentCard;
397
+ declare const A2A_PROTOCOL_VERSION = "1.0";
398
+ declare const A2A_DEFAULT_TRANSPORT = "JSONRPC";
217
399
 
218
400
  /**
219
401
  * UCP profile signing helpers (JWKS + JWS).
@@ -388,6 +570,7 @@ declare function loadUCPSigningKeyFromEnv({ envJwkVar, envKidVar, envAlgVar, def
388
570
  * hashes. This helper exposes the canonical hash so every consumer agrees on
389
571
  * the shape.
390
572
  */
573
+
391
574
  /**
392
575
  * sha256 hex digest of a plaintext operator token.
393
576
  *
@@ -396,5 +579,353 @@ declare function loadUCPSigningKeyFromEnv({ envJwkVar, envKidVar, envAlgVar, def
396
579
  * durable storage.
397
580
  */
398
581
  declare function hashOperatorToken(plaintext: string): string;
582
+ type OwnerScope = {
583
+ walletAddress?: string;
584
+ operatorTokenHash?: string;
585
+ };
586
+ /**
587
+ * Pull the canonical owner identity from request headers so caller-scoped
588
+ * lookups never see the plaintext operator token. Reads `X-Wallet-Address` and
589
+ * `X-Operator-Token`; returns the wallet address verbatim and the
590
+ * sha256 hash of the token. Either or both may be undefined.
591
+ *
592
+ * Use at owner-scoped resource queries (`GET /orders/:id`, `GET /receipts/:id`,
593
+ * ...) so persistence + lookup agree on the hashed column shape and plaintext
594
+ * tokens never leave the request.
595
+ */
596
+ declare function extractOwnerScope(input: Request | HeadersLike): OwnerScope;
597
+
598
+ /**
599
+ * Cross-module typed errors.
600
+ *
601
+ * Lives in its own module so `payment/` and `stripe-multichain/` helpers can
602
+ * throw `CheckoutValidationError` without importing from `checkout.ts`. (In
603
+ * the python sibling this avoids a checkout → payment → checkout cycle; in
604
+ * node it sidesteps tsup's per-entry class duplication.)
605
+ *
606
+ * Re-exported from `checkout.ts` and the top-level entry to preserve the
607
+ * public import path.
608
+ */
609
+ /**
610
+ * Raised to short-circuit a Checkout flow with a 4xx/5xx envelope. The
611
+ * framework catches this at request-flow boundaries (`preValidate`, recipient
612
+ * minting, settlement dispatch) and emits `{ error, next_steps }` via
613
+ * `buildValidationError` so merchants don't construct response bodies
614
+ * themselves.
615
+ */
616
+ declare class CheckoutValidationError extends Error {
617
+ readonly code: string;
618
+ readonly action: string;
619
+ readonly status: number;
620
+ readonly extra: Record<string, unknown> | undefined;
621
+ constructor(opts: {
622
+ code: string;
623
+ message: string;
624
+ action?: string;
625
+ status?: number;
626
+ extra?: Record<string, unknown>;
627
+ });
628
+ }
629
+
630
+ /**
631
+ * Short-TTL body-hash quote cache for the compute-first + exact-x402 pattern
632
+ * (see {@link computeFirstCheckout}).
633
+ *
634
+ * Standard x402-fetch retry semantics resign the buyer's ORIGINAL request body
635
+ * — there's no `result_id` echo channel through the protocol. The cache is
636
+ * therefore keyed by a stable content-hash of the request body. Same body →
637
+ * same hash → same cache slot. The probe leg writes (run-work → cache); the
638
+ * settle leg reads (cache hit → settle exact at the cached price → return the
639
+ * cached body).
640
+ *
641
+ * Default in-memory `Map`; optional `redisUrl` lazy-imports `ioredis` for
642
+ * multi-instance deployments. `ioredis` is an optional peer dep.
643
+ */
644
+ interface QuoteCacheOptions {
645
+ /** Quote lifetime in milliseconds. Default `5 * 60_000` (5 min). */
646
+ ttlMs?: number;
647
+ /** Redis connection URL. Default: `process.env.REDIS_URL`. When unset or the
648
+ * lazy `ioredis` import fails, falls back to in-process `Map`. */
649
+ redisUrl?: string;
650
+ /** Per-instance key prefix so multiple caches sharing a Redis don't collide. */
651
+ keyPrefix?: string;
652
+ }
653
+ interface CachedQuote {
654
+ body: Record<string, unknown>;
655
+ priceCents: number;
656
+ /** Per-rail deposit addresses minted on the probe leg. The settle leg replays
657
+ * these instead of re-minting (avoids second Stripe PaymentIntent for the
658
+ * same logical purchase). Empty object when no `mintRecipients` hook is wired. */
659
+ recipients: Record<string, string>;
660
+ }
661
+ interface QuoteCache {
662
+ /** Build a stable content-hash key from a per-merchant prefix and a request body.
663
+ * Property order in the body does NOT affect the hash (keys are sorted recursively). */
664
+ bodyHashKey(prefix: string, body: Record<string, unknown>): string;
665
+ read(key: string): Promise<CachedQuote | null>;
666
+ write(key: string, body: Record<string, unknown>, priceCents: number, recipients?: Record<string, string>): Promise<void>;
667
+ /** Clear all entries. Primarily for tests. */
668
+ clear(): Promise<void>;
669
+ }
670
+ /** Build a fresh cache. Each call owns its own state (memory map + Redis
671
+ * client). */
672
+ declare function createQuoteCache(opts?: QuoteCacheOptions): QuoteCache;
673
+
674
+ /**
675
+ * `computeFirstCheckout` — variable-cost pay-per-result merchant helper using
676
+ * compute-first + exact-x402 (no upto, no Permit2, no Settlement-Overrides).
677
+ *
678
+ * Flow (per request):
679
+ *
680
+ * 1. PROBE leg (no payment header)
681
+ * - Validate input
682
+ * - Look up cache by content-hash of the request body
683
+ * - On cache miss: run `runWork(body)`
684
+ * - 0 results → return 200 immediately with `no_charge` envelope (no 402)
685
+ * - Else → cache `{body, priceCents}` keyed by body hash → emit 402 with
686
+ * EXACT price (`actual_results × unitPriceCents`) on every advertised rail
687
+ * - On cache hit: emit 402 with cached price
688
+ *
689
+ * 2. SETTLE leg (X-Payment / Authorization: Payment header attached)
690
+ * - Look up cache by re-hashing the same body
691
+ * - Cache miss → 400 `stale_quote` with `next_steps.action: 're_probe'`
692
+ * - x402 path → `verifyX402Request` + `processX402Settle({scheme:'exact'})`
693
+ * - MPP path → `composeMppxRequest`
694
+ * - Return cached result body in the canonical 200 envelope
695
+ *
696
+ * Works on every exact-mode rail today (x402-exact Base, tempo/charge,
697
+ * solana/charge, Stripe SPT). The tradeoff vs. upto is that the work runs on
698
+ * the unpaid probe leg — so rate-limiting is load-bearing (use
699
+ * `@agent-score/commerce/middleware/hono` `rateLimitHono` or the per-framework
700
+ * equivalent).
701
+ */
702
+
703
+ interface WorkOutcome {
704
+ /** Number of billable units returned by `runWork` (results, tokens, bytes, …).
705
+ * Used to compute the exact price `unitPriceCents × resultCount` advertised
706
+ * in the 402. Zero short-circuits the probe to 200 no-charge. */
707
+ resultCount: number;
708
+ /** Body returned to the buyer on the settle leg. Cached verbatim and served
709
+ * from cache on retry; the merchant does NOT re-run `runWork`. */
710
+ body: Record<string, unknown>;
711
+ }
712
+ interface ComputeFirstWorkContext {
713
+ /** Raw Web Fetch `Request` for the probe leg — useful when the work hook
714
+ * needs to dispatch by header (e.g. agent identity) or read query params. */
715
+ request: Request;
716
+ }
717
+ interface ComputeFirstMintContext {
718
+ request: Request;
719
+ body: Record<string, unknown>;
720
+ /** Final price in cents (`unitPriceCents × resultCount`). Useful when minting
721
+ * payment-provider sessions (Stripe Multichain PaymentIntent) that need the
722
+ * exact charge amount up front. */
723
+ priceCents: number;
724
+ }
725
+ interface ComputeFirstMppContext {
726
+ request: Request;
727
+ /** Cached body that will be returned to the buyer on settle success. The
728
+ * merchant doesn't need to re-run the work; it's already done. */
729
+ cachedBody: Record<string, unknown>;
730
+ /** Exact price in cents (`unitPriceCents × resultCount`). Build mppx
731
+ * intents at this amount. */
732
+ priceCents: number;
733
+ /** Dollar-string of the price at the helper's configured precision (e.g.
734
+ * `"0.03"`, `"0.001234"`). Useful for `tempo/charge` / `stripe/charge`
735
+ * intents which take a USD string. */
736
+ priceUsd: string;
737
+ /** Minted (or static) recipients per rail. The merchant uses these to build
738
+ * the per-rail intents. */
739
+ recipients: MintedRecipients;
740
+ }
741
+ interface ComputeFirstSettledContext {
742
+ request: Request;
743
+ /** Which rail family captured the payment. `'x402'` = x402-exact on Base.
744
+ * `'mpp'` = one of Tempo / Solana / Stripe SPT via mppx — disambiguate with
745
+ * `mppMethod` when you need per-MPP-rail dispatch (e.g. firing the Stripe
746
+ * testnet deposit simulator with the right `network`). */
747
+ rail: 'x402' | 'mpp';
748
+ /** When `rail === 'mpp'`, the specific intent that mppx settled
749
+ * (`'tempo/charge'`, `'solana/charge'`, `'stripe/charge'`). Undefined when
750
+ * the receipt method couldn't be extracted or for non-MPP rails. */
751
+ mppMethod?: string;
752
+ /** Cached body that will be returned to the buyer. */
753
+ cachedBody: Record<string, unknown>;
754
+ priceCents: number;
755
+ priceUsd: string;
756
+ recipients: MintedRecipients;
757
+ signer?: {
758
+ address: string;
759
+ network: 'evm' | 'solana';
760
+ };
761
+ paymentIntentId?: string;
762
+ }
763
+ interface MintedRecipients {
764
+ tempo?: string;
765
+ x402_base?: string;
766
+ solana_mpp?: string;
767
+ }
768
+ interface ComputeFirstRails {
769
+ tempo?: TempoRailSpec;
770
+ x402_base?: X402BaseRailSpec;
771
+ solana_mpp?: SolanaMppRailSpec;
772
+ stripe?: StripeRailSpec;
773
+ }
774
+ interface ComputeFirstOptions {
775
+ /** Merchant-facing name (used in cache prefix, response envelope, product id). */
776
+ name: string;
777
+ /** Public URL of the endpoint, including scheme + host. */
778
+ url: string;
779
+ /** Price per billable unit, in cents. Fractional values supported (per-token
780
+ * / per-byte unit pricing); precision is auto-derived from the fractional
781
+ * digits unless `decimals` is set explicitly. */
782
+ unitPriceCents: number;
783
+ /** Override the auto-derived dollar-precision. Default: `2` for integer
784
+ * cents, else `2 + decimal digits of unitPriceCents`. */
785
+ decimals?: number;
786
+ /** Per-rail config. Pass only the rails you support. At least one rail required. */
787
+ rails: ComputeFirstRails;
788
+ /** Required: registered x402 server (from `createX402Server`). The helper
789
+ * uses it to build x402 `accepts[]` entries (correct USDC contract +
790
+ * EIP-712 domain name per network) and to call `processX402Settle` on the
791
+ * settle leg. */
792
+ x402Server: unknown;
793
+ /** MPP compose hook for the Tempo / Solana / Stripe SPT rails. Called on
794
+ * BOTH legs of the round-trip:
795
+ *
796
+ * - **Probe leg** (no payment header): the merchant builds per-rail intents
797
+ * at the exact cached price and calls `composeMppxRequest(mppx, intents,
798
+ * request)` — mppx returns a 402 challenge whose `WWW-Authenticate`
799
+ * header carries the proper per-rail `request=<base64-intent>` values
800
+ * the agent needs to sign. Return `{status: 402, headers}` where
801
+ * `headers` is `mppxChallengeHeaders(result)` — the helper merges them
802
+ * into the 402 response so pay / mppx-clients can settle on any
803
+ * advertised MPP rail.
804
+ * - **Settle leg** (`Authorization: Payment` header attached): mppx
805
+ * verifies + composes. Return `{status: 200, ...}` with `txHash` and
806
+ * signer info for the success envelope.
807
+ *
808
+ * Omit to skip MPP entirely — the helper then advertises only x402-exact
809
+ * in the 402 and rejects MPP-header settles with 503 `mpp_unavailable`. */
810
+ composeMppx?: (ctx: ComputeFirstMppContext) => Promise<{
811
+ status: number;
812
+ raw?: unknown;
813
+ headers?: Record<string, string>;
814
+ txHash?: string;
815
+ signerAddress?: string;
816
+ signerNetwork?: 'evm' | 'solana';
817
+ }>;
818
+ /** Optional side-effect hook fired after a successful settle on either rail
819
+ * (x402 or MPP), before the response is sent. Use this for Stripe testnet
820
+ * deposit simulation, audit logging, captureWallet writeback, or any other
821
+ * post-settle work that shouldn't block the response. Errors are caught
822
+ * and logged but don't fail the request — the buyer still gets their data. */
823
+ onSettled?: (ctx: ComputeFirstSettledContext) => Promise<void> | void;
824
+ /** Optional input validator. Throw a `CheckoutValidationError` for typed
825
+ * 4xx envelopes; any other error becomes a 500. */
826
+ validateInput?: (body: Record<string, unknown>) => void;
827
+ /** The per-request work. Probe leg calls this once; settle leg replays the
828
+ * cached output. */
829
+ runWork: (body: Record<string, unknown>, ctx: ComputeFirstWorkContext) => Promise<WorkOutcome>;
830
+ /** Optional per-call recipient mint hook. Stripe-multichain merchants mint
831
+ * per-PI deposit addresses; static-recipient merchants leave this unset
832
+ * and the rail recipient configured in `rails` is used verbatim. */
833
+ mintRecipients?: (ctx: ComputeFirstMintContext) => Promise<MintedRecipients>;
834
+ /** Quote cache instance. Default: in-memory cache with 5-min TTL. Pass a
835
+ * Redis-backed cache (via `createQuoteCache({redisUrl})`) for multi-task
836
+ * deployments. */
837
+ cache?: QuoteCache;
838
+ /** Override default cache TTL (only used when `cache` is not provided). */
839
+ cacheTtlMs?: number;
840
+ /** App URL used in success `next_steps.order_status_url`. Defaults to the
841
+ * origin of `url` + `/health`. */
842
+ appUrl?: string;
843
+ /** Override the on-success body. Default returns a canonical
844
+ * `{id, endpoint, payment_status, charged_usd, rail, signer?, result, ...}`
845
+ * envelope matching the fixed-price `Checkout` shape. */
846
+ buildSuccessBody?: (args: SuccessBodyArgs) => Record<string, unknown>;
847
+ }
848
+ interface SuccessBodyArgs {
849
+ referenceId: string;
850
+ endpoint: string;
851
+ chargedUsd: string;
852
+ rail: string;
853
+ paymentIntentId?: string;
854
+ signer?: {
855
+ address: string;
856
+ network: 'evm' | 'solana';
857
+ };
858
+ cachedBody: Record<string, unknown>;
859
+ }
860
+ interface ComputeFirstHandler {
861
+ /** Hono adapter — pass `(c) => handler.handleHono(c)` into your route. */
862
+ handleHono(c: Context): Promise<Response>;
863
+ /** Web Fetch adapter — pass `handler.handleWeb` directly as a route handler. */
864
+ handleWeb(req: Request): Promise<Response>;
865
+ }
866
+ declare function computeFirstCheckout(opts: ComputeFirstOptions): ComputeFirstHandler;
867
+
868
+ /** Factory for the standard `onDenied` callback shape used by Checkout's
869
+ * gate config. Replaces the ~100-line switch every consumer codebase
870
+ * (sayer, martin, sandbox) wrote by hand.
871
+ *
872
+ * The shape is framework-neutral (`{status, body, headers?}`) — matches
873
+ * `Checkout`'s `onDenied` signature directly. For per-framework gate
874
+ * middleware (`agentscoreGate(...)`) the merchant adapts at the call site
875
+ * with `c.json(body, status, headers)` / equivalent.
876
+ */
877
+
878
+ interface CreateDefaultOnDeniedOptions {
879
+ /** Display name used in the wallet_not_trusted body ("Identity check did
880
+ * not satisfy policy for <merchantName>"). */
881
+ merchantName: string;
882
+ /** Support email surfaced in `next_steps.action: "contact_support"`. */
883
+ supportEmail: string;
884
+ /** Optional override for the support-context blurb. Defaults to
885
+ * "Contact support if you believe this denial is in error.". */
886
+ supportContext?: string;
887
+ /** Optional override for the payment_required error message. Defaults to
888
+ * "AgentScore tier does not support assess. Contact support.". */
889
+ paymentRequiredMessage?: string;
890
+ /** Optional override for the wallet_not_trusted (unfixable) error message.
891
+ * Defaults to `"Identity check did not satisfy policy for <merchantName>."`. */
892
+ walletNotTrustedMessage?: string;
893
+ }
894
+ interface DefaultOnDeniedResult {
895
+ status: number;
896
+ body: Record<string, unknown>;
897
+ headers?: Record<string, string>;
898
+ }
899
+ /** Build the canonical `onDenied(ctx, reason)` callback. Returns
900
+ * framework-neutral `{status, body, headers?}` matching `Checkout`'s
901
+ * `onDenied` signature. The `ctx` arg is ignored — pass `_ctx`-style if
902
+ * unused.
903
+ *
904
+ * Branch table (matches the hand-rolled version in every consumer):
905
+ * - `wallet_signer_mismatch` / `wallet_auth_requires_wallet_signing` →
906
+ * `buildSignerMismatchBody(...)`, status 403
907
+ * - `wallet_not_trusted` → custom compliance_denied body + contact-support
908
+ * next steps, status 403
909
+ * - `payment_required` → denial body + compliance_error message, status 403
910
+ * - `token_expired` / `invalid_credential` → 401
911
+ * - `api_error` → 503 + `Cache-Control: no-store`
912
+ * - default → 403
913
+ */
914
+ declare function createDefaultOnDenied(opts: CreateDefaultOnDeniedOptions): (reason: DenialReason) => DefaultOnDeniedResult;
915
+ /** Canonical `onDenied` for read-only resource gates (e.g. `GET /orders/:id`).
916
+ *
917
+ * Collapses every denial code to **401 `unauthorized`** while still spreading
918
+ * `denialReasonToBody(reason)` so `agent_instructions` / `verify_url` /
919
+ * session-mint fields ride through for the agent's recovery path. Stamps
920
+ * `Cache-Control: no-store` because RFC 7234 makes 4xx responses
921
+ * heuristically cacheable; transient denials (api_error, token_expired)
922
+ * must not be replayed by a shared cache.
923
+ *
924
+ * Pair with `agentscoreGate({ onDenied: defaultReadOnlyOnDenied })` on routes
925
+ * where the resource owner is the only authorized identity (full compliance
926
+ * policy already ran at /purchase time; the read-back leg only needs
927
+ * presence-of-valid-credential).
928
+ */
929
+ declare function defaultReadOnlyOnDenied(reason: DenialReason): DefaultOnDeniedResult;
399
930
 
400
- export { type A2AAgentCard, type A2AAgentCardCapabilities, type A2AAgentCardExtension, type A2AAgentCardSignature, type A2AAgentInterface, type A2AAgentProvider, type A2AAgentSkill, type GeneratedUCPKey, type JWKSResponse, type SignedUCPProfile, UCPProfile, UCPSigningKey, UCPVerificationError, UCP_A2A_EXTENSION_URI, buildA2AAgentCard, buildJWKSResponse, generateUCPSigningKey, hashOperatorToken, loadUCPSigningKeyFromEnv, signUCPProfile, ucpA2AExtension, verifyUCPProfile };
931
+ export { type A2AAgentCard, type A2AAgentCardCapabilities, type A2AAgentCardExtension, type A2AAgentCardSignature, type A2AAgentInterface, type A2AAgentProvider, type A2AAgentSkill, A2A_DEFAULT_TRANSPORT, A2A_PROTOCOL_VERSION, type CachedQuote, CheckoutValidationError, type ComputeFirstHandler, type ComputeFirstMintContext, type ComputeFirstMppContext, type ComputeFirstOptions, type ComputeFirstRails, type ComputeFirstSettledContext, type ComputeFirstWorkContext, type CreateDefaultOnDeniedOptions, type DefaultOnDeniedResult, DenialReason, FIXABLE_DENIAL_REASONS, type GeneratedUCPKey, type JWKSResponse, type MintedRecipients, type OwnerScope, type QuoteCache, type QuoteCacheOptions, type SignedUCPProfile, SolanaMppRailSpec, StripeRailSpec, type SuccessBodyArgs, TempoRailSpec, UCPProfile, UCPSigningKey, UCPVerificationError, UCP_A2A_EXTENSION_URI, VerifyWalletSignerResult, type WorkOutcome, X402BaseRailSpec, buildA2AAgentCard, buildContactSupportNextSteps, buildJWKSResponse, buildSignerMismatchBody, buildVerificationRequiredBody, computeFirstCheckout, createDefaultOnDenied, createQuoteCache, defaultReadOnlyOnDenied, denialReasonStatus, denialReasonToBody, extractOwnerScope, generateUCPSigningKey, hashOperatorToken, isFixableDenial, loadUCPSigningKeyFromEnv, signUCPProfile, ucpA2AExtension, verificationAgentInstructions, verifyUCPProfile };