@agent-score/commerce 2.0.1 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -11
- package/dist/_core-kI7FRAiZ.d.mts +10 -0
- package/dist/_core-kI7FRAiZ.d.ts +10 -0
- package/dist/challenge/index.d.mts +3 -3
- package/dist/challenge/index.d.ts +3 -3
- package/dist/challenge/index.js +21 -14
- package/dist/challenge/index.js.map +1 -1
- package/dist/challenge/index.mjs +21 -14
- package/dist/challenge/index.mjs.map +1 -1
- package/dist/{checkout-B1JuEcbx.d.ts → checkout-BH-I_Ns8.d.ts} +19 -12
- package/dist/{checkout-BN5i1Fi7.d.mts → checkout-Bd_4aQ6c.d.mts} +19 -12
- package/dist/core.js +1 -1
- package/dist/core.js.map +1 -1
- package/dist/core.mjs +1 -1
- package/dist/core.mjs.map +1 -1
- package/dist/default_rails-BWAquZeu.d.mts +188 -0
- package/dist/default_rails-BxBzcCA1.d.ts +188 -0
- package/dist/discovery/index.d.mts +5 -5
- package/dist/discovery/index.d.ts +5 -5
- package/dist/discovery/index.js +14 -1
- package/dist/discovery/index.js.map +1 -1
- package/dist/discovery/index.mjs +14 -1
- package/dist/discovery/index.mjs.map +1 -1
- package/dist/identity/express.d.mts +7 -3
- package/dist/identity/express.d.ts +7 -3
- package/dist/identity/express.js +39 -96
- package/dist/identity/express.js.map +1 -1
- package/dist/identity/express.mjs +37 -87
- package/dist/identity/express.mjs.map +1 -1
- package/dist/identity/fastify.d.mts +4 -4
- package/dist/identity/fastify.d.ts +4 -4
- package/dist/identity/fastify.js +60 -96
- package/dist/identity/fastify.js.map +1 -1
- package/dist/identity/fastify.mjs +58 -87
- package/dist/identity/fastify.mjs.map +1 -1
- package/dist/identity/hono.d.mts +11 -3
- package/dist/identity/hono.d.ts +11 -3
- package/dist/identity/hono.js +39 -93
- package/dist/identity/hono.js.map +1 -1
- package/dist/identity/hono.mjs +37 -84
- package/dist/identity/hono.mjs.map +1 -1
- package/dist/identity/nextjs.d.mts +10 -3
- package/dist/identity/nextjs.d.ts +10 -3
- package/dist/identity/nextjs.js +49 -93
- package/dist/identity/nextjs.js.map +1 -1
- package/dist/identity/nextjs.mjs +46 -84
- package/dist/identity/nextjs.mjs.map +1 -1
- package/dist/identity/policy.js +220 -129
- package/dist/identity/policy.js.map +1 -1
- package/dist/identity/policy.mjs +222 -131
- package/dist/identity/policy.mjs.map +1 -1
- package/dist/identity/web.d.mts +9 -3
- package/dist/identity/web.d.ts +9 -3
- package/dist/identity/web.js +45 -93
- package/dist/identity/web.js.map +1 -1
- package/dist/identity/web.mjs +42 -84
- package/dist/identity/web.mjs.map +1 -1
- package/dist/index.d.mts +554 -90
- package/dist/index.d.ts +554 -90
- package/dist/index.js +951 -152
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +939 -152
- package/dist/index.mjs.map +1 -1
- package/dist/middleware/express.d.mts +10 -0
- package/dist/middleware/express.d.ts +10 -0
- package/dist/middleware/express.js +128 -0
- package/dist/middleware/express.js.map +1 -0
- package/dist/middleware/express.mjs +91 -0
- package/dist/middleware/express.mjs.map +1 -0
- package/dist/middleware/fastify.d.mts +10 -0
- package/dist/middleware/fastify.d.ts +10 -0
- package/dist/middleware/fastify.js +127 -0
- package/dist/middleware/fastify.js.map +1 -0
- package/dist/middleware/fastify.mjs +90 -0
- package/dist/middleware/fastify.mjs.map +1 -0
- package/dist/middleware/hono.d.mts +10 -0
- package/dist/middleware/hono.d.ts +10 -0
- package/dist/middleware/hono.js +122 -0
- package/dist/middleware/hono.js.map +1 -0
- package/dist/middleware/hono.mjs +85 -0
- package/dist/middleware/hono.mjs.map +1 -0
- package/dist/middleware/nextjs.d.mts +22 -0
- package/dist/middleware/nextjs.d.ts +22 -0
- package/dist/middleware/nextjs.js +143 -0
- package/dist/middleware/nextjs.js.map +1 -0
- package/dist/middleware/nextjs.mjs +105 -0
- package/dist/middleware/nextjs.mjs.map +1 -0
- package/dist/middleware/web.d.mts +25 -0
- package/dist/middleware/web.d.ts +25 -0
- package/dist/middleware/web.js +128 -0
- package/dist/middleware/web.js.map +1 -0
- package/dist/middleware/web.mjs +91 -0
- package/dist/middleware/web.mjs.map +1 -0
- package/dist/payment/index.d.mts +21 -6
- package/dist/payment/index.d.ts +21 -6
- package/dist/payment/index.js +136 -9
- package/dist/payment/index.js.map +1 -1
- package/dist/payment/index.mjs +127 -9
- package/dist/payment/index.mjs.map +1 -1
- package/dist/{pricing-CxzwyiO6.d.mts → pricing-4n5Ota0D.d.mts} +14 -4
- package/dist/{pricing-CQ9DIFaw.d.ts → pricing-DHfH3ogG.d.ts} +14 -4
- package/dist/{rail_spec-XP0wKgJV.d.mts → rail_spec-D6qzh3J0.d.mts} +1 -1
- package/dist/{rail_spec-XP0wKgJV.d.ts → rail_spec-D6qzh3J0.d.ts} +1 -1
- package/dist/stripe-multichain/index.d.mts +150 -47
- package/dist/stripe-multichain/index.d.ts +150 -47
- package/dist/stripe-multichain/index.js +19749 -42
- package/dist/stripe-multichain/index.js.map +1 -1
- package/dist/stripe-multichain/index.mjs +19758 -27
- package/dist/stripe-multichain/index.mjs.map +1 -1
- package/dist/{x402_server-hgQzWQwB.d.mts → x402_server-Ciz2mls2.d.mts} +1 -1
- package/dist/{x402_server-hgQzWQwB.d.ts → x402_server-Ciz2mls2.d.ts} +1 -1
- package/package.json +43 -5
- package/dist/_response-BFYN3b6i.d.mts +0 -142
- package/dist/_response-_iPD5AIj.d.ts +0 -142
- package/dist/solana-Cds87OTu.d.mts +0 -67
- package/dist/solana-Cds87OTu.d.ts +0 -67
package/dist/index.d.ts
CHANGED
|
@@ -1,21 +1,163 @@
|
|
|
1
|
-
|
|
1
|
+
import { VerifyWalletSignerResult, DenialReason } from './core.js';
|
|
2
|
+
export { AccountVerification, AgentIdentity, AgentMemoryHint, AgentScoreCore, AssessResult, CreateSessionOnMissing, DenialCode, EvaluateOutcome, OperatorVerification, PolicyCheck, PolicyResult, SignerVerdict, buildAgentMemoryHint } from './core.js';
|
|
2
3
|
export { P as PaymentSigner, S as SignerNetwork, e as extractPaymentSigner, a as extractPaymentSignerFromAuth, b as extractSignerForPrecheck, r as readX402PaymentHeader } from './signer-3FAit11j.js';
|
|
3
|
-
|
|
4
|
-
|
|
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-B1JuEcbx.js';
|
|
4
|
+
import { r as UCPSigningKey, o as UCPProfile } from './checkout-BH-I_Ns8.js';
|
|
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 CheckoutValidationError, h as ComposeMppxFn, D as DiscoveryProbeConfig, G as GateDenial, I as IsCachedAddressFn, M as MountUcpRoutesOptions, i as MppxComposeOutcome, O as OnSettledFn, P as PreValidateFn, j as PricingFn, k as PricingResult, R as RecipientsFn, l as ReferenceIdFn, m as RunGateFn, S as SettleOutcome, U as UCPCapabilityBinding, n as UCPPaymentHandlerBinding, p as UCPProfileBody, q 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-BH-I_Ns8.js';
|
|
6
6
|
export { EnforcementMode, GateResult, IdentityStatus, PolicyBlock, buildGateFromPolicy, runGateWithEnforcement, shippingCountryAllowed, shippingStateAllowed, validateShippingAgainstPolicy } from './identity/policy.js';
|
|
7
|
-
|
|
8
|
-
export { f as formatUsdCents, l as loadSolanaFeePayer } from './
|
|
9
|
-
import './
|
|
10
|
-
|
|
7
|
+
import { H as HeadersLike } from './default_rails-BxBzcCA1.js';
|
|
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-BxBzcCA1.js';
|
|
9
|
+
import { T as TempoRailSpec, X as X402BaseRailSpec, S as SolanaMppRailSpec, b as StripeRailSpec } from './rail_spec-D6qzh3J0.js';
|
|
10
|
+
export { c as TempoSessionRailSpec } from './rail_spec-D6qzh3J0.js';
|
|
11
|
+
import { Context } from 'hono';
|
|
12
|
+
import './pricing-DHfH3ogG.js';
|
|
13
|
+
import './x402_server-Ciz2mls2.js';
|
|
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
|
+
declare function denialReasonToBody(reason: DenialReason): Record<string, unknown>;
|
|
11
153
|
|
|
12
154
|
/**
|
|
13
155
|
* Google A2A (Agent-to-Agent) v1.0 Agent Card builder.
|
|
14
156
|
*
|
|
15
|
-
* Compose the JSON payload for an A2A v1.0 Agent Card
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
157
|
+
* Compose the JSON payload for an A2A v1.0 Agent Card matching the canonical
|
|
158
|
+
* `AgentCard` type from `@a2a-js/sdk`. Returned object is the unsigned card body —
|
|
159
|
+
* wrap with an `A2AAgentCardSignature` (RFC 7515 JWS) to sign vendor-side before
|
|
160
|
+
* publishing at /.well-known/agent-card.json.
|
|
19
161
|
*
|
|
20
162
|
* Why publish: A2A is a Linux Foundation standard. Signed Agent Cards let any
|
|
21
163
|
* A2A-compatible reader discover an agent's capabilities + protocol bindings without
|
|
@@ -24,41 +166,43 @@ import './x402_server-hgQzWQwB.js';
|
|
|
24
166
|
* so platforms detect UCP support without re-fetching the profile.
|
|
25
167
|
*
|
|
26
168
|
* Spec reference: https://a2a-protocol.org/latest/
|
|
169
|
+
* Authoritative types: https://www.npmjs.com/package/@a2a-js/sdk (interface `AgentCard`).
|
|
27
170
|
*/
|
|
28
171
|
/** Canonical UCP A2A extension URI — verifiers look for this exact URI in
|
|
29
172
|
* `capabilities.extensions[]` to detect UCP support on the agent card. Pinned
|
|
30
173
|
* to the 2026-04-08 spec snapshot. */
|
|
31
174
|
declare const UCP_A2A_EXTENSION_URI = "https://ucp.dev/2026-04-08/specification/reference";
|
|
32
|
-
/**
|
|
33
|
-
*
|
|
175
|
+
/** One transport+URL combination the agent exposes. Lives in `AgentCard.additionalInterfaces[]`
|
|
176
|
+
* for multi-binding agents; the PRIMARY transport+URL pair lives on `AgentCard.url` +
|
|
177
|
+
* `AgentCard.preferredTransport`. */
|
|
34
178
|
interface A2AAgentInterface {
|
|
35
|
-
/** Interface URL (https in production). */
|
|
36
|
-
url: string;
|
|
37
179
|
/** Open string — core values are `JSONRPC`, `GRPC`, `HTTP+JSON`. */
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
|
|
41
|
-
tenant?: string;
|
|
180
|
+
transport: string;
|
|
181
|
+
/** Absolute URL where this transport is available. */
|
|
182
|
+
url: string;
|
|
42
183
|
}
|
|
43
|
-
/**
|
|
184
|
+
/** Org/service that provides the agent. */
|
|
44
185
|
interface A2AAgentProvider {
|
|
45
|
-
url: string;
|
|
46
186
|
organization: string;
|
|
187
|
+
url: string;
|
|
47
188
|
}
|
|
48
|
-
/**
|
|
49
|
-
*
|
|
189
|
+
/** A distinct capability or function the agent performs. Lives at the TOP LEVEL of
|
|
190
|
+
* `AgentCard.skills[]` (not inside `capabilities`). */
|
|
50
191
|
interface A2AAgentSkill {
|
|
51
192
|
id: string;
|
|
52
193
|
name: string;
|
|
53
194
|
description: string;
|
|
54
195
|
tags: string[];
|
|
55
196
|
examples?: string[];
|
|
56
|
-
|
|
57
|
-
|
|
197
|
+
inputModes?: string[];
|
|
198
|
+
outputModes?: string[];
|
|
199
|
+
/** Security schemes scoped to this skill. List = OR of ANDs (each entry is a set of
|
|
200
|
+
* schemes that must all be satisfied). Follows OpenAPI 3.0 Security Requirement Object. */
|
|
201
|
+
security?: Record<string, string[]>[];
|
|
58
202
|
}
|
|
59
|
-
/**
|
|
60
|
-
*
|
|
61
|
-
*
|
|
203
|
+
/** A protocol extension the agent supports. Lives in `capabilities.extensions[]`.
|
|
204
|
+
* Canonical type marks `description` and `required` optional, but we keep them in the
|
|
205
|
+
* builder to make UCP discovery deterministic. */
|
|
62
206
|
interface A2AAgentCardExtension {
|
|
63
207
|
uri: string;
|
|
64
208
|
description: string;
|
|
@@ -83,24 +227,16 @@ declare function ucpA2AExtension(capabilities?: Record<string, Array<{
|
|
|
83
227
|
}>>, options?: {
|
|
84
228
|
required?: boolean;
|
|
85
229
|
}): A2AAgentCardExtension;
|
|
86
|
-
/**
|
|
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. */
|
|
230
|
+
/** Optional capabilities the agent supports. */
|
|
93
231
|
interface A2AAgentCardCapabilities {
|
|
94
|
-
streaming?: boolean;
|
|
95
|
-
push_notifications?: boolean;
|
|
96
232
|
extensions?: A2AAgentCardExtension[];
|
|
97
|
-
|
|
233
|
+
pushNotifications?: boolean;
|
|
234
|
+
stateTransitionHistory?: boolean;
|
|
235
|
+
streaming?: boolean;
|
|
98
236
|
}
|
|
99
|
-
/**
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
* card body without `signatures` to verify each entry. Format follows RFC 7515 JSON
|
|
103
|
-
* Web Signature (JWS). */
|
|
237
|
+
/** JWS signature embedded in an Agent Card. Multiple signatures MAY be attached;
|
|
238
|
+
* verifiers reconstruct the card body without `signatures` to verify each entry.
|
|
239
|
+
* Format follows RFC 7515. */
|
|
104
240
|
interface A2AAgentCardSignature {
|
|
105
241
|
/** Base64url-encoded JSON of the protected JWS header. REQUIRED. */
|
|
106
242
|
protected: string;
|
|
@@ -109,35 +245,38 @@ interface A2AAgentCardSignature {
|
|
|
109
245
|
/** Optional unprotected JWS header values. */
|
|
110
246
|
header?: Record<string, unknown>;
|
|
111
247
|
}
|
|
112
|
-
/**
|
|
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[]`. */
|
|
248
|
+
/** A2A v1.0 Agent Card body, matching `AgentCard` from `@a2a-js/sdk`. */
|
|
118
249
|
interface A2AAgentCard {
|
|
119
250
|
name: string;
|
|
120
251
|
description: string;
|
|
121
|
-
/**
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
|
|
252
|
+
/** Preferred endpoint URL — MUST support `preferredTransport`. */
|
|
253
|
+
url: string;
|
|
254
|
+
/** Transport at the primary `url`. Defaults to `JSONRPC` per spec when omitted by a reader. */
|
|
255
|
+
preferredTransport?: string;
|
|
256
|
+
/** A2A protocol version, e.g. `"1.0"`. Distinct from the agent's own `version`. */
|
|
257
|
+
protocolVersion: string;
|
|
258
|
+
/** Additional transport+URL bindings beyond the primary. */
|
|
259
|
+
additionalInterfaces?: A2AAgentInterface[];
|
|
260
|
+
/** Agent's own version, e.g. `"1.0.0"`. */
|
|
125
261
|
version: string;
|
|
126
262
|
capabilities: A2AAgentCardCapabilities;
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* The convenience builder `buildA2AAgentCard` enforces non-empty. */
|
|
263
|
+
defaultInputModes: string[];
|
|
264
|
+
defaultOutputModes: string[];
|
|
265
|
+
/** REQUIRED non-empty. */
|
|
131
266
|
skills: A2AAgentSkill[];
|
|
132
267
|
provider?: A2AAgentProvider;
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
268
|
+
documentationUrl?: string;
|
|
269
|
+
iconUrl?: string;
|
|
270
|
+
/** Agent can provide an extended card with additional details to authenticated users.
|
|
271
|
+
* Defaults to `false`. */
|
|
272
|
+
supportsAuthenticatedExtendedCard?: boolean;
|
|
273
|
+
/** JWS signatures embedded in the card. Compute over the canonical card body MINUS
|
|
274
|
+
* this field, then attach. */
|
|
138
275
|
signatures?: A2AAgentCardSignature[];
|
|
139
|
-
|
|
140
|
-
|
|
276
|
+
/** OpenAPI 3.0 security requirement objects (OR of ANDs). */
|
|
277
|
+
security?: Record<string, string[]>[];
|
|
278
|
+
/** Map of security scheme definitions (key = scheme name). */
|
|
279
|
+
securitySchemes?: Record<string, unknown>;
|
|
141
280
|
/** Vendor-specific extras merged at top level. */
|
|
142
281
|
[k: string]: unknown;
|
|
143
282
|
}
|
|
@@ -146,55 +285,61 @@ interface BuildA2AAgentCardInput {
|
|
|
146
285
|
name: string;
|
|
147
286
|
/** Agent purpose/description. REQUIRED per spec. */
|
|
148
287
|
description: string;
|
|
149
|
-
/**
|
|
150
|
-
* `
|
|
151
|
-
*
|
|
288
|
+
/** Primary endpoint URL — becomes `AgentCard.url`. The transport at this URL is
|
|
289
|
+
* declared via `preferredTransport` (default `HTTP+JSON`). For multi-binding agents,
|
|
290
|
+
* pass `additionalInterfaces` for the secondary transports. */
|
|
152
291
|
url: string;
|
|
153
292
|
/** Top-level skill declarations — what the agent can do. REQUIRED per spec
|
|
154
293
|
* (proto field 12 [field_behavior=REQUIRED]); must have ≥1 entry. */
|
|
155
294
|
skills: A2AAgentSkill[];
|
|
156
|
-
/** Agent's own version, e.g. `"1.0.0"`. Distinct from the A2A
|
|
295
|
+
/** Agent's own version, e.g. `"1.0.0"`. Distinct from the A2A `protocolVersion`. */
|
|
157
296
|
version?: string;
|
|
297
|
+
/** Transport for the primary `url`. Defaults to `"HTTP+JSON"` for our merchants; the
|
|
298
|
+
* canonical A2A spec default when omitted by a reader is `"JSONRPC"`. */
|
|
299
|
+
preferredTransport?: string;
|
|
300
|
+
/** A2A protocol version. Defaults to `"1.0"`. */
|
|
301
|
+
protocolVersion?: string;
|
|
302
|
+
/** Additional transport+URL bindings beyond the primary. */
|
|
303
|
+
additionalInterfaces?: A2AAgentInterface[];
|
|
158
304
|
/** A2A v1.0 capability extensions. Build the UCP entry with `ucpA2AExtension()`. */
|
|
159
305
|
extensions?: A2AAgentCardExtension[];
|
|
160
|
-
/** Capability flag: agent supports streaming responses. */
|
|
306
|
+
/** Capability flag: agent supports streaming responses (SSE). */
|
|
161
307
|
streaming?: boolean;
|
|
162
308
|
/** Capability flag: agent supports push notifications for async task updates. */
|
|
163
|
-
|
|
164
|
-
/** Capability flag: agent
|
|
165
|
-
|
|
309
|
+
pushNotifications?: boolean;
|
|
310
|
+
/** Capability flag: agent provides task state-transition history. */
|
|
311
|
+
stateTransitionHistory?: boolean;
|
|
312
|
+
/** AgentCard top-level flag: agent serves an extended card to authenticated users. */
|
|
313
|
+
supportsAuthenticatedExtendedCard?: boolean;
|
|
166
314
|
/** Provider org for the agent. */
|
|
167
315
|
provider?: A2AAgentProvider;
|
|
168
316
|
/** URL to additional human-readable documentation. */
|
|
169
|
-
|
|
317
|
+
documentationUrl?: string;
|
|
170
318
|
/** URL to an icon for the agent. */
|
|
171
|
-
|
|
172
|
-
/** JWS signatures embedded in the card
|
|
319
|
+
iconUrl?: string;
|
|
320
|
+
/** JWS signatures embedded in the card. */
|
|
173
321
|
signatures?: A2AAgentCardSignature[];
|
|
174
322
|
/** Default input media types (defaults to `["application/json"]`). */
|
|
175
|
-
|
|
323
|
+
defaultInputModes?: string[];
|
|
176
324
|
/** Default output media types (defaults to `["application/json"]`). */
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
|
|
180
|
-
/** Override the A2A protocol version for the auto-built primary interface (default `"1.0"`). */
|
|
181
|
-
a2a_protocol_version?: string;
|
|
325
|
+
defaultOutputModes?: string[];
|
|
326
|
+
/** OpenAPI 3.0 security requirement objects (OR of ANDs). */
|
|
327
|
+
security?: Record<string, string[]>[];
|
|
182
328
|
/** Per-scheme security details (key = scheme name). */
|
|
183
|
-
|
|
184
|
-
/** Required security requirements for invoking the agent. */
|
|
185
|
-
security_requirements?: unknown[];
|
|
329
|
+
securitySchemes?: Record<string, unknown>;
|
|
186
330
|
/** Vendor-specific extras merged at the card top level. */
|
|
187
331
|
extras?: Record<string, unknown>;
|
|
188
332
|
}
|
|
189
333
|
/**
|
|
190
|
-
* Compose an A2A v1.0 Agent Card body
|
|
334
|
+
* Compose an A2A v1.0 Agent Card body matching `AgentCard` from `@a2a-js/sdk`.
|
|
191
335
|
*
|
|
192
336
|
* Returns the UNSIGNED card. To attach identity claims, sign the serialized body
|
|
193
|
-
* as an RFC 7515 JWS (`
|
|
337
|
+
* as an RFC 7515 JWS (`A2AAgentCardSignature`). Vendors can also add an identity-flavored
|
|
194
338
|
* extension to `capabilities.extensions[]`.
|
|
195
339
|
*
|
|
196
|
-
* The
|
|
197
|
-
* (
|
|
340
|
+
* The `url` argument becomes the top-level `AgentCard.url`; `preferredTransport`
|
|
341
|
+
* declares the transport at that URL (default `HTTP+JSON`). For multi-binding agents,
|
|
342
|
+
* pass `additionalInterfaces`.
|
|
198
343
|
*
|
|
199
344
|
* Example:
|
|
200
345
|
* ```ts
|
|
@@ -214,6 +359,8 @@ interface BuildA2AAgentCardInput {
|
|
|
214
359
|
* ```
|
|
215
360
|
*/
|
|
216
361
|
declare function buildA2AAgentCard(input: BuildA2AAgentCardInput): A2AAgentCard;
|
|
362
|
+
declare const A2A_PROTOCOL_VERSION = "1.0";
|
|
363
|
+
declare const A2A_DEFAULT_TRANSPORT = "JSONRPC";
|
|
217
364
|
|
|
218
365
|
/**
|
|
219
366
|
* UCP profile signing helpers (JWKS + JWS).
|
|
@@ -388,6 +535,7 @@ declare function loadUCPSigningKeyFromEnv({ envJwkVar, envKidVar, envAlgVar, def
|
|
|
388
535
|
* hashes. This helper exposes the canonical hash so every consumer agrees on
|
|
389
536
|
* the shape.
|
|
390
537
|
*/
|
|
538
|
+
|
|
391
539
|
/**
|
|
392
540
|
* sha256 hex digest of a plaintext operator token.
|
|
393
541
|
*
|
|
@@ -396,5 +544,321 @@ declare function loadUCPSigningKeyFromEnv({ envJwkVar, envKidVar, envAlgVar, def
|
|
|
396
544
|
* durable storage.
|
|
397
545
|
*/
|
|
398
546
|
declare function hashOperatorToken(plaintext: string): string;
|
|
547
|
+
type OwnerScope = {
|
|
548
|
+
walletAddress?: string;
|
|
549
|
+
operatorTokenHash?: string;
|
|
550
|
+
};
|
|
551
|
+
/**
|
|
552
|
+
* Pull the canonical owner identity from request headers so caller-scoped
|
|
553
|
+
* lookups never see the plaintext operator token. Reads `X-Wallet-Address` and
|
|
554
|
+
* `X-Operator-Token`; returns the wallet address verbatim and the
|
|
555
|
+
* sha256 hash of the token. Either or both may be undefined.
|
|
556
|
+
*
|
|
557
|
+
* Use at owner-scoped resource queries (`GET /orders/:id`, `GET /receipts/:id`,
|
|
558
|
+
* ...) so persistence + lookup agree on the hashed column shape and plaintext
|
|
559
|
+
* tokens never leave the request.
|
|
560
|
+
*/
|
|
561
|
+
declare function extractOwnerScope(input: Request | HeadersLike): OwnerScope;
|
|
562
|
+
|
|
563
|
+
/**
|
|
564
|
+
* Short-TTL body-hash quote cache for the compute-first + exact-x402 pattern
|
|
565
|
+
* (see {@link computeFirstCheckout}).
|
|
566
|
+
*
|
|
567
|
+
* Standard x402-fetch retry semantics resign the buyer's ORIGINAL request body
|
|
568
|
+
* — there's no `result_id` echo channel through the protocol. The cache is
|
|
569
|
+
* therefore keyed by a stable content-hash of the request body. Same body →
|
|
570
|
+
* same hash → same cache slot. The probe leg writes (run-work → cache); the
|
|
571
|
+
* settle leg reads (cache hit → settle exact at the cached price → return the
|
|
572
|
+
* cached body).
|
|
573
|
+
*
|
|
574
|
+
* Default in-memory `Map`; optional `redisUrl` lazy-imports `ioredis` for
|
|
575
|
+
* multi-instance deployments. `ioredis` is an optional peer dep.
|
|
576
|
+
*/
|
|
577
|
+
interface QuoteCacheOptions {
|
|
578
|
+
/** Quote lifetime in milliseconds. Default `5 * 60_000` (5 min). */
|
|
579
|
+
ttlMs?: number;
|
|
580
|
+
/** Redis connection URL. Default: `process.env.REDIS_URL`. When unset or the
|
|
581
|
+
* lazy `ioredis` import fails, falls back to in-process `Map`. */
|
|
582
|
+
redisUrl?: string;
|
|
583
|
+
/** Per-instance key prefix so multiple caches sharing a Redis don't collide. */
|
|
584
|
+
keyPrefix?: string;
|
|
585
|
+
}
|
|
586
|
+
interface CachedQuote {
|
|
587
|
+
body: Record<string, unknown>;
|
|
588
|
+
priceCents: number;
|
|
589
|
+
/** Per-rail deposit addresses minted on the probe leg. The settle leg replays
|
|
590
|
+
* these instead of re-minting (avoids second Stripe PaymentIntent for the
|
|
591
|
+
* same logical purchase). Empty object when no `mintRecipients` hook is wired. */
|
|
592
|
+
recipients: Record<string, string>;
|
|
593
|
+
}
|
|
594
|
+
interface QuoteCache {
|
|
595
|
+
/** Build a stable content-hash key from a per-merchant prefix and a request body.
|
|
596
|
+
* Property order in the body does NOT affect the hash (keys are sorted recursively). */
|
|
597
|
+
bodyHashKey(prefix: string, body: Record<string, unknown>): string;
|
|
598
|
+
read(key: string): Promise<CachedQuote | null>;
|
|
599
|
+
write(key: string, body: Record<string, unknown>, priceCents: number, recipients?: Record<string, string>): Promise<void>;
|
|
600
|
+
/** Clear all entries. Primarily for tests. */
|
|
601
|
+
clear(): Promise<void>;
|
|
602
|
+
}
|
|
603
|
+
/** Build a fresh cache. Each call owns its own state (memory map + Redis
|
|
604
|
+
* client). */
|
|
605
|
+
declare function createQuoteCache(opts?: QuoteCacheOptions): QuoteCache;
|
|
606
|
+
|
|
607
|
+
/**
|
|
608
|
+
* `computeFirstCheckout` — variable-cost pay-per-result merchant helper using
|
|
609
|
+
* compute-first + exact-x402 (no upto, no Permit2, no Settlement-Overrides).
|
|
610
|
+
*
|
|
611
|
+
* Flow (per request):
|
|
612
|
+
*
|
|
613
|
+
* 1. PROBE leg (no payment header)
|
|
614
|
+
* - Validate input
|
|
615
|
+
* - Look up cache by content-hash of the request body
|
|
616
|
+
* - On cache miss: run `runWork(body)`
|
|
617
|
+
* - 0 results → return 200 immediately with `no_charge` envelope (no 402)
|
|
618
|
+
* - Else → cache `{body, priceCents}` keyed by body hash → emit 402 with
|
|
619
|
+
* EXACT price (`actual_results × unitPriceCents`) on every advertised rail
|
|
620
|
+
* - On cache hit: emit 402 with cached price
|
|
621
|
+
*
|
|
622
|
+
* 2. SETTLE leg (X-Payment / Authorization: Payment header attached)
|
|
623
|
+
* - Look up cache by re-hashing the same body
|
|
624
|
+
* - Cache miss → 400 `stale_quote` with `next_steps.action: 're_probe'`
|
|
625
|
+
* - x402 path → `verifyX402Request` + `processX402Settle({scheme:'exact'})`
|
|
626
|
+
* - MPP path → `composeMppxRequest`
|
|
627
|
+
* - Return cached result body in the canonical 200 envelope
|
|
628
|
+
*
|
|
629
|
+
* Works on every exact-mode rail today (x402-exact Base, tempo/charge,
|
|
630
|
+
* solana/charge, Stripe SPT). The tradeoff vs. upto is that the work runs on
|
|
631
|
+
* the unpaid probe leg — so rate-limiting is load-bearing (use
|
|
632
|
+
* `@agent-score/commerce/middleware/hono` `rateLimitHono` or the per-framework
|
|
633
|
+
* equivalent).
|
|
634
|
+
*/
|
|
635
|
+
|
|
636
|
+
interface WorkOutcome {
|
|
637
|
+
/** Number of billable units returned by `runWork` (results, tokens, bytes, …).
|
|
638
|
+
* Used to compute the exact price `unitPriceCents × resultCount` advertised
|
|
639
|
+
* in the 402. Zero short-circuits the probe to 200 no-charge. */
|
|
640
|
+
resultCount: number;
|
|
641
|
+
/** Body returned to the buyer on the settle leg. Cached verbatim and served
|
|
642
|
+
* from cache on retry; the merchant does NOT re-run `runWork`. */
|
|
643
|
+
body: Record<string, unknown>;
|
|
644
|
+
}
|
|
645
|
+
interface ComputeFirstWorkContext {
|
|
646
|
+
/** Raw Web Fetch `Request` for the probe leg — useful when the work hook
|
|
647
|
+
* needs to dispatch by header (e.g. agent identity) or read query params. */
|
|
648
|
+
request: Request;
|
|
649
|
+
}
|
|
650
|
+
interface ComputeFirstMintContext {
|
|
651
|
+
request: Request;
|
|
652
|
+
body: Record<string, unknown>;
|
|
653
|
+
/** Final price in cents (`unitPriceCents × resultCount`). Useful when minting
|
|
654
|
+
* payment-provider sessions (Stripe Multichain PaymentIntent) that need the
|
|
655
|
+
* exact charge amount up front. */
|
|
656
|
+
priceCents: number;
|
|
657
|
+
}
|
|
658
|
+
interface ComputeFirstMppContext {
|
|
659
|
+
request: Request;
|
|
660
|
+
/** Cached body that will be returned to the buyer on settle success. The
|
|
661
|
+
* merchant doesn't need to re-run the work; it's already done. */
|
|
662
|
+
cachedBody: Record<string, unknown>;
|
|
663
|
+
/** Exact price in cents (`unitPriceCents × resultCount`). Build mppx
|
|
664
|
+
* intents at this amount. */
|
|
665
|
+
priceCents: number;
|
|
666
|
+
/** Dollar-string of the price at the helper's configured precision (e.g.
|
|
667
|
+
* `"0.03"`, `"0.001234"`). Useful for `tempo/charge` / `stripe/charge`
|
|
668
|
+
* intents which take a USD string. */
|
|
669
|
+
priceUsd: string;
|
|
670
|
+
/** Minted (or static) recipients per rail. The merchant uses these to build
|
|
671
|
+
* the per-rail intents. */
|
|
672
|
+
recipients: MintedRecipients;
|
|
673
|
+
}
|
|
674
|
+
interface ComputeFirstSettledContext {
|
|
675
|
+
request: Request;
|
|
676
|
+
/** Which rail family captured the payment. `'x402'` = x402-exact on Base.
|
|
677
|
+
* `'mpp'` = one of Tempo / Solana / Stripe SPT via mppx — disambiguate with
|
|
678
|
+
* `mppMethod` when you need per-MPP-rail dispatch (e.g. firing the Stripe
|
|
679
|
+
* testnet deposit simulator with the right `network`). */
|
|
680
|
+
rail: 'x402' | 'mpp';
|
|
681
|
+
/** When `rail === 'mpp'`, the specific intent that mppx settled
|
|
682
|
+
* (`'tempo/charge'`, `'solana/charge'`, `'stripe/charge'`). Undefined when
|
|
683
|
+
* the receipt method couldn't be extracted or for non-MPP rails. */
|
|
684
|
+
mppMethod?: string;
|
|
685
|
+
/** Cached body that will be returned to the buyer. */
|
|
686
|
+
cachedBody: Record<string, unknown>;
|
|
687
|
+
priceCents: number;
|
|
688
|
+
priceUsd: string;
|
|
689
|
+
recipients: MintedRecipients;
|
|
690
|
+
signer?: {
|
|
691
|
+
address: string;
|
|
692
|
+
network: 'evm' | 'solana';
|
|
693
|
+
};
|
|
694
|
+
paymentIntentId?: string;
|
|
695
|
+
}
|
|
696
|
+
interface MintedRecipients {
|
|
697
|
+
tempo?: string;
|
|
698
|
+
x402_base?: string;
|
|
699
|
+
solana_mpp?: string;
|
|
700
|
+
}
|
|
701
|
+
interface ComputeFirstRails {
|
|
702
|
+
tempo?: TempoRailSpec;
|
|
703
|
+
x402_base?: X402BaseRailSpec;
|
|
704
|
+
solana_mpp?: SolanaMppRailSpec;
|
|
705
|
+
stripe?: StripeRailSpec;
|
|
706
|
+
}
|
|
707
|
+
interface ComputeFirstOptions {
|
|
708
|
+
/** Merchant-facing name (used in cache prefix, response envelope, product id). */
|
|
709
|
+
name: string;
|
|
710
|
+
/** Public URL of the endpoint, including scheme + host. */
|
|
711
|
+
url: string;
|
|
712
|
+
/** Price per billable unit, in cents. Fractional values supported (per-token
|
|
713
|
+
* / per-byte unit pricing); precision is auto-derived from the fractional
|
|
714
|
+
* digits unless `decimals` is set explicitly. */
|
|
715
|
+
unitPriceCents: number;
|
|
716
|
+
/** Override the auto-derived dollar-precision. Default: `2` for integer
|
|
717
|
+
* cents, else `2 + decimal digits of unitPriceCents`. */
|
|
718
|
+
decimals?: number;
|
|
719
|
+
/** Per-rail config. Pass only the rails you support. At least one rail required. */
|
|
720
|
+
rails: ComputeFirstRails;
|
|
721
|
+
/** Required: registered x402 server (from `createX402Server`). The helper
|
|
722
|
+
* uses it to build x402 `accepts[]` entries (correct USDC contract +
|
|
723
|
+
* EIP-712 domain name per network) and to call `processX402Settle` on the
|
|
724
|
+
* settle leg. */
|
|
725
|
+
x402Server: unknown;
|
|
726
|
+
/** MPP compose hook for the Tempo / Solana / Stripe SPT rails. Called on
|
|
727
|
+
* BOTH legs of the round-trip:
|
|
728
|
+
*
|
|
729
|
+
* - **Probe leg** (no payment header): the merchant builds per-rail intents
|
|
730
|
+
* at the exact cached price and calls `composeMppxRequest(mppx, intents,
|
|
731
|
+
* request)` — mppx returns a 402 challenge whose `WWW-Authenticate`
|
|
732
|
+
* header carries the proper per-rail `request=<base64-intent>` values
|
|
733
|
+
* the agent needs to sign. Return `{status: 402, headers}` where
|
|
734
|
+
* `headers` is `mppxChallengeHeaders(result)` — the helper merges them
|
|
735
|
+
* into the 402 response so pay / mppx-clients can settle on any
|
|
736
|
+
* advertised MPP rail.
|
|
737
|
+
* - **Settle leg** (`Authorization: Payment` header attached): mppx
|
|
738
|
+
* verifies + composes. Return `{status: 200, ...}` with `txHash` and
|
|
739
|
+
* signer info for the success envelope.
|
|
740
|
+
*
|
|
741
|
+
* Omit to skip MPP entirely — the helper then advertises only x402-exact
|
|
742
|
+
* in the 402 and rejects MPP-header settles with 503 `mpp_unavailable`. */
|
|
743
|
+
composeMppx?: (ctx: ComputeFirstMppContext) => Promise<{
|
|
744
|
+
status: number;
|
|
745
|
+
raw?: unknown;
|
|
746
|
+
headers?: Record<string, string>;
|
|
747
|
+
txHash?: string;
|
|
748
|
+
signerAddress?: string;
|
|
749
|
+
signerNetwork?: 'evm' | 'solana';
|
|
750
|
+
}>;
|
|
751
|
+
/** Optional side-effect hook fired after a successful settle on either rail
|
|
752
|
+
* (x402 or MPP), before the response is sent. Use this for Stripe testnet
|
|
753
|
+
* deposit simulation, audit logging, captureWallet writeback, or any other
|
|
754
|
+
* post-settle work that shouldn't block the response. Errors are caught
|
|
755
|
+
* and logged but don't fail the request — the buyer still gets their data. */
|
|
756
|
+
onSettled?: (ctx: ComputeFirstSettledContext) => Promise<void> | void;
|
|
757
|
+
/** Optional input validator. Throw a `CheckoutValidationError` for typed
|
|
758
|
+
* 4xx envelopes; any other error becomes a 500. */
|
|
759
|
+
validateInput?: (body: Record<string, unknown>) => void;
|
|
760
|
+
/** The per-request work. Probe leg calls this once; settle leg replays the
|
|
761
|
+
* cached output. */
|
|
762
|
+
runWork: (body: Record<string, unknown>, ctx: ComputeFirstWorkContext) => Promise<WorkOutcome>;
|
|
763
|
+
/** Optional per-call recipient mint hook. Stripe-multichain merchants mint
|
|
764
|
+
* per-PI deposit addresses; static-recipient merchants leave this unset
|
|
765
|
+
* and the rail recipient configured in `rails` is used verbatim. */
|
|
766
|
+
mintRecipients?: (ctx: ComputeFirstMintContext) => Promise<MintedRecipients>;
|
|
767
|
+
/** Quote cache instance. Default: in-memory cache with 5-min TTL. Pass a
|
|
768
|
+
* Redis-backed cache (via `createQuoteCache({redisUrl})`) for multi-task
|
|
769
|
+
* deployments. */
|
|
770
|
+
cache?: QuoteCache;
|
|
771
|
+
/** Override default cache TTL (only used when `cache` is not provided). */
|
|
772
|
+
cacheTtlMs?: number;
|
|
773
|
+
/** App URL used in success `next_steps.order_status_url`. Defaults to the
|
|
774
|
+
* origin of `url` + `/health`. */
|
|
775
|
+
appUrl?: string;
|
|
776
|
+
/** Override the on-success body. Default returns a canonical
|
|
777
|
+
* `{id, endpoint, payment_status, charged_usd, rail, signer?, result, ...}`
|
|
778
|
+
* envelope matching the fixed-price `Checkout` shape. */
|
|
779
|
+
buildSuccessBody?: (args: SuccessBodyArgs) => Record<string, unknown>;
|
|
780
|
+
}
|
|
781
|
+
interface SuccessBodyArgs {
|
|
782
|
+
referenceId: string;
|
|
783
|
+
endpoint: string;
|
|
784
|
+
chargedUsd: string;
|
|
785
|
+
rail: string;
|
|
786
|
+
paymentIntentId?: string;
|
|
787
|
+
signer?: {
|
|
788
|
+
address: string;
|
|
789
|
+
network: 'evm' | 'solana';
|
|
790
|
+
};
|
|
791
|
+
cachedBody: Record<string, unknown>;
|
|
792
|
+
}
|
|
793
|
+
interface ComputeFirstHandler {
|
|
794
|
+
/** Hono adapter — pass `(c) => handler.handleHono(c)` into your route. */
|
|
795
|
+
handleHono(c: Context): Promise<Response>;
|
|
796
|
+
/** Web Fetch adapter — pass `handler.handleWeb` directly as a route handler. */
|
|
797
|
+
handleWeb(req: Request): Promise<Response>;
|
|
798
|
+
}
|
|
799
|
+
declare function computeFirstCheckout(opts: ComputeFirstOptions): ComputeFirstHandler;
|
|
800
|
+
|
|
801
|
+
/** Factory for the standard `onDenied` callback shape used by Checkout's
|
|
802
|
+
* gate config. Replaces the ~100-line switch every consumer codebase
|
|
803
|
+
* (sayer, martin, sandbox) wrote by hand.
|
|
804
|
+
*
|
|
805
|
+
* The shape is framework-neutral (`{status, body, headers?}`) — matches
|
|
806
|
+
* `Checkout`'s `onDenied` signature directly. For per-framework gate
|
|
807
|
+
* middleware (`agentscoreGate(...)`) the merchant adapts at the call site
|
|
808
|
+
* with `c.json(body, status, headers)` / equivalent.
|
|
809
|
+
*/
|
|
810
|
+
|
|
811
|
+
interface CreateDefaultOnDeniedOptions {
|
|
812
|
+
/** Display name used in the wallet_not_trusted body ("Identity check did
|
|
813
|
+
* not satisfy policy for <merchantName>"). */
|
|
814
|
+
merchantName: string;
|
|
815
|
+
/** Support email surfaced in `next_steps.action: "contact_support"`. */
|
|
816
|
+
supportEmail: string;
|
|
817
|
+
/** Optional override for the support-context blurb. Defaults to
|
|
818
|
+
* "Contact support if you believe this denial is in error.". */
|
|
819
|
+
supportContext?: string;
|
|
820
|
+
/** Optional override for the payment_required error message. Defaults to
|
|
821
|
+
* "AgentScore tier does not support assess. Contact support.". */
|
|
822
|
+
paymentRequiredMessage?: string;
|
|
823
|
+
/** Optional override for the wallet_not_trusted (unfixable) error message.
|
|
824
|
+
* Defaults to `"Identity check did not satisfy policy for <merchantName>."`. */
|
|
825
|
+
walletNotTrustedMessage?: string;
|
|
826
|
+
}
|
|
827
|
+
interface DefaultOnDeniedResult {
|
|
828
|
+
status: number;
|
|
829
|
+
body: Record<string, unknown>;
|
|
830
|
+
headers?: Record<string, string>;
|
|
831
|
+
}
|
|
832
|
+
/** Build the canonical `onDenied(ctx, reason)` callback. Returns
|
|
833
|
+
* framework-neutral `{status, body, headers?}` matching `Checkout`'s
|
|
834
|
+
* `onDenied` signature. The `ctx` arg is ignored — pass `_ctx`-style if
|
|
835
|
+
* unused.
|
|
836
|
+
*
|
|
837
|
+
* Branch table (matches the hand-rolled version in every consumer):
|
|
838
|
+
* - `wallet_signer_mismatch` / `wallet_auth_requires_wallet_signing` →
|
|
839
|
+
* `buildSignerMismatchBody(...)`, status 403
|
|
840
|
+
* - `wallet_not_trusted` → custom compliance_denied body + contact-support
|
|
841
|
+
* next steps, status 403
|
|
842
|
+
* - `payment_required` → denial body + compliance_error message, status 403
|
|
843
|
+
* - `token_expired` / `invalid_credential` → 401
|
|
844
|
+
* - `api_error` → 503 + `Cache-Control: no-store`
|
|
845
|
+
* - default → 403
|
|
846
|
+
*/
|
|
847
|
+
declare function createDefaultOnDenied(opts: CreateDefaultOnDeniedOptions): (reason: DenialReason) => DefaultOnDeniedResult;
|
|
848
|
+
/** Canonical `onDenied` for read-only resource gates (e.g. `GET /orders/:id`).
|
|
849
|
+
*
|
|
850
|
+
* Collapses every denial code to **401 `unauthorized`** while still spreading
|
|
851
|
+
* `denialReasonToBody(reason)` so `agent_instructions` / `verify_url` /
|
|
852
|
+
* session-mint fields ride through for the agent's recovery path. Stamps
|
|
853
|
+
* `Cache-Control: no-store` because RFC 7234 makes 4xx responses
|
|
854
|
+
* heuristically cacheable; transient denials (api_error, token_expired)
|
|
855
|
+
* must not be replayed by a shared cache.
|
|
856
|
+
*
|
|
857
|
+
* Pair with `agentscoreGate({ onDenied: defaultReadOnlyOnDenied })` on routes
|
|
858
|
+
* where the resource owner is the only authorized identity (full compliance
|
|
859
|
+
* policy already ran at /purchase time; the read-back leg only needs
|
|
860
|
+
* presence-of-valid-credential).
|
|
861
|
+
*/
|
|
862
|
+
declare function defaultReadOnlyOnDenied(reason: DenialReason): DefaultOnDeniedResult;
|
|
399
863
|
|
|
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 };
|
|
864
|
+
export { type A2AAgentCard, type A2AAgentCardCapabilities, type A2AAgentCardExtension, type A2AAgentCardSignature, type A2AAgentInterface, type A2AAgentProvider, type A2AAgentSkill, A2A_DEFAULT_TRANSPORT, A2A_PROTOCOL_VERSION, type CachedQuote, type ComputeFirstHandler, type ComputeFirstMintContext, type ComputeFirstOptions, type ComputeFirstRails, 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, computeFirstCheckout, createDefaultOnDenied, createQuoteCache, defaultReadOnlyOnDenied, denialReasonStatus, denialReasonToBody, extractOwnerScope, generateUCPSigningKey, hashOperatorToken, isFixableDenial, loadUCPSigningKeyFromEnv, signUCPProfile, ucpA2AExtension, verificationAgentInstructions, verifyUCPProfile };
|