@agent-score/commerce 1.0.3 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/README.md +28 -1
  2. package/dist/agent_instructions-d3UWTdam.d.mts +129 -0
  3. package/dist/agent_instructions-d3UWTdam.d.ts +129 -0
  4. package/dist/challenge/index.d.mts +3 -110
  5. package/dist/challenge/index.d.ts +3 -110
  6. package/dist/challenge/index.js +76 -5
  7. package/dist/challenge/index.js.map +1 -1
  8. package/dist/challenge/index.mjs +82 -5
  9. package/dist/challenge/index.mjs.map +1 -1
  10. package/dist/core.d.mts +28 -1
  11. package/dist/core.d.ts +28 -1
  12. package/dist/core.js +237 -157
  13. package/dist/core.js.map +1 -1
  14. package/dist/core.mjs +246 -157
  15. package/dist/core.mjs.map +1 -1
  16. package/dist/discovery/index.d.mts +120 -1
  17. package/dist/discovery/index.d.ts +120 -1
  18. package/dist/discovery/index.js +204 -0
  19. package/dist/discovery/index.js.map +1 -1
  20. package/dist/discovery/index.mjs +202 -0
  21. package/dist/discovery/index.mjs.map +1 -1
  22. package/dist/identity/express.d.mts +18 -2
  23. package/dist/identity/express.d.ts +18 -2
  24. package/dist/identity/express.js +227 -164
  25. package/dist/identity/express.js.map +1 -1
  26. package/dist/identity/express.mjs +232 -164
  27. package/dist/identity/express.mjs.map +1 -1
  28. package/dist/identity/fastify.d.mts +17 -2
  29. package/dist/identity/fastify.d.ts +17 -2
  30. package/dist/identity/fastify.js +227 -164
  31. package/dist/identity/fastify.js.map +1 -1
  32. package/dist/identity/fastify.mjs +232 -164
  33. package/dist/identity/fastify.mjs.map +1 -1
  34. package/dist/identity/hono.d.mts +22 -2
  35. package/dist/identity/hono.d.ts +22 -2
  36. package/dist/identity/hono.js +227 -164
  37. package/dist/identity/hono.js.map +1 -1
  38. package/dist/identity/hono.mjs +232 -164
  39. package/dist/identity/hono.mjs.map +1 -1
  40. package/dist/identity/nextjs.d.mts +8 -1
  41. package/dist/identity/nextjs.d.ts +8 -1
  42. package/dist/identity/nextjs.js +213 -166
  43. package/dist/identity/nextjs.js.map +1 -1
  44. package/dist/identity/nextjs.mjs +220 -166
  45. package/dist/identity/nextjs.mjs.map +1 -1
  46. package/dist/identity/web.d.mts +15 -1
  47. package/dist/identity/web.d.ts +15 -1
  48. package/dist/identity/web.js +213 -166
  49. package/dist/identity/web.js.map +1 -1
  50. package/dist/identity/web.mjs +220 -166
  51. package/dist/identity/web.mjs.map +1 -1
  52. package/dist/index.js +120 -101
  53. package/dist/index.js.map +1 -1
  54. package/dist/index.mjs +127 -101
  55. package/dist/index.mjs.map +1 -1
  56. package/dist/payment/index.js.map +1 -1
  57. package/dist/payment/index.mjs.map +1 -1
  58. package/dist/stripe-multichain/index.js.map +1 -1
  59. package/dist/stripe-multichain/index.mjs.map +1 -1
  60. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -41,6 +41,9 @@ __export(index_exports, {
41
41
  });
42
42
  module.exports = __toCommonJS(index_exports);
43
43
 
44
+ // src/core.ts
45
+ var import_sdk = require("@agent-score/sdk");
46
+
44
47
  // src/_denial.ts
45
48
  var FIXABLE_DENIAL_REASONS = /* @__PURE__ */ new Set([
46
49
  "kyc_required",
@@ -120,6 +123,123 @@ function verificationAgentInstructions(input = {}) {
120
123
  };
121
124
  }
122
125
 
126
+ // src/_response.ts
127
+ var WALLET_NOT_TRUSTED_INSTRUCTIONS = JSON.stringify({
128
+ action: "contact_support",
129
+ steps: [
130
+ "The wallet's operator failed an UNFIXABLE compliance check (sanctions, age, or jurisdiction). `reasons` lists which: `sanctions_flagged` / `age_insufficient` / `jurisdiction_restricted`. KYC re-verification won't change the outcome \u2014 the policy denial is structural.",
131
+ "Surface the denial to the user with the merchant's support contact. Do not retry the same merchant request; do not hand the user a verify_url (verification won't fix this code path).",
132
+ "Fixable compliance reasons (`kyc_required`, `kyc_pending`, `kyc_failed`) do NOT land on this code \u2014 the gate auto-mints a verification session for those and returns `identity_verification_required` with poll endpoints, same shape as `missing_identity`. `jurisdiction_restricted` IS in the unfixable bucket because the API only emits it after KYC is verified (the user's KYC'd country is in the blocked list \u2014 re-doing KYC won't change the country)."
133
+ ],
134
+ user_message: "This purchase is denied by the merchant's compliance policy and cannot be resolved by re-verifying. Contact the merchant's support if you believe this is in error."
135
+ });
136
+ var PAYMENT_REQUIRED_INSTRUCTIONS = JSON.stringify({
137
+ action: "contact_merchant",
138
+ steps: [
139
+ "The merchant's AgentScore account does not have the assess endpoint enabled, so agent identity cannot be evaluated. This is a merchant-side configuration gap \u2014 there is no agent-side recovery.",
140
+ "Contact the merchant (their support channel \u2014 typically listed in /llms.txt or the OpenAPI servers metadata) so they can resolve the configuration on their side."
141
+ ],
142
+ user_message: "This merchant's identity gate is misconfigured. Contact the merchant \u2014 there's nothing to fix on the agent side."
143
+ });
144
+ var IDENTITY_VERIFICATION_REQUIRED_FALLBACK_INSTRUCTIONS = JSON.stringify({
145
+ action: "deliver_verify_url_and_poll",
146
+ steps: [
147
+ "Share verify_url with the user \u2014 they complete identity verification on AgentScore.",
148
+ "If session_id + poll_secret are present in the body, poll poll_url every 5 seconds with header `X-Poll-Secret: <poll_secret>` until status=verified. The poll returns a one-time operator_token.",
149
+ "Retry the original request with header `X-Operator-Token: <opc_...>`."
150
+ ],
151
+ user_message: "Identity verification is required. Visit verify_url, then poll poll_url for the operator token and retry."
152
+ });
153
+ var API_ERROR_INSTRUCTIONS = JSON.stringify({
154
+ action: "retry_with_backoff",
155
+ steps: [
156
+ "Verification is temporarily unavailable. Retry the request after 5\u201330 seconds with exponential backoff.",
157
+ "This is NOT a compliance denial \u2014 the user does not need to re-verify their identity. Send the same identity headers (X-Wallet-Address or X-Operator-Token) on retry.",
158
+ "If the request continues to fail after 3+ retries (~60 seconds total), surface the error to the user with the merchant's support contact."
159
+ ],
160
+ user_message: "Verification is temporarily unavailable. Please try again in a moment \u2014 this is a transient issue, not a problem with your account."
161
+ });
162
+ var QUOTA_EXCEEDED_INSTRUCTIONS = JSON.stringify({
163
+ action: "contact_merchant",
164
+ steps: [
165
+ "AgentScore identity verification is unavailable for this merchant. This is a merchant-side issue and is NOT recoverable via retry.",
166
+ "Do not retry: the same 503 will be returned until the merchant resolves the issue on their side.",
167
+ "Surface to the user with the merchant's support contact. The merchant (not the agent) needs to act."
168
+ ],
169
+ user_message: "This merchant's identity verification is temporarily unavailable. Try again later, or contact the merchant directly."
170
+ });
171
+ var TOKEN_EXPIRED_FALLBACK_INSTRUCTIONS = JSON.stringify({
172
+ action: "deliver_verify_url_and_poll",
173
+ steps: [
174
+ "The operator token is expired or revoked. AgentScore auto-mints a fresh verification session \u2014 complete it to receive a new opc_...",
175
+ "Share verify_url with the user, then poll poll_url every 5 seconds with header `X-Poll-Secret: <poll_secret>` until status=verified. The poll returns a fresh one-time operator_token.",
176
+ "Retry the original request with header `X-Operator-Token: <new_opc_...>`."
177
+ ],
178
+ user_message: "Operator token is expired or revoked. A new verification session has been minted \u2014 visit verify_url to refresh."
179
+ });
180
+ var DEFAULT_AGENT_INSTRUCTIONS = {
181
+ api_error: API_ERROR_INSTRUCTIONS,
182
+ wallet_not_trusted: WALLET_NOT_TRUSTED_INSTRUCTIONS,
183
+ payment_required: PAYMENT_REQUIRED_INSTRUCTIONS,
184
+ identity_verification_required: IDENTITY_VERIFICATION_REQUIRED_FALLBACK_INSTRUCTIONS,
185
+ token_expired: TOKEN_EXPIRED_FALLBACK_INSTRUCTIONS
186
+ };
187
+ var DEFAULT_MESSAGES = {
188
+ missing_identity: "No identity provided. Send X-Wallet-Address (wallet) or X-Operator-Token (credential).",
189
+ identity_verification_required: "Identity verification is required to access this resource. Visit verify_url to complete KYC.",
190
+ wallet_not_trusted: "The wallet does not meet the merchant compliance policy.",
191
+ api_error: "AgentScore is unreachable. This is transient \u2014 retry in a few seconds.",
192
+ payment_required: "Assess endpoint not enabled for this merchant. Contact support.",
193
+ wallet_signer_mismatch: "Payment signer does not match the wallet claimed via X-Wallet-Address. The signer and the claimed wallet must both resolve to the same AgentScore operator.",
194
+ wallet_auth_requires_wallet_signing: "X-Wallet-Address was sent with a rail that has no wallet signature (Stripe SPT / card). Switch to X-Operator-Token, or use a wallet-signing rail (Tempo MPP, x402).",
195
+ token_expired: "The operator token is expired or revoked. A fresh verification session has been minted \u2014 visit verify_url to mint a new token.",
196
+ invalid_credential: "The operator token is not recognized. Switch to a different stored token, or drop the header to bootstrap a fresh session."
197
+ };
198
+ var RESERVED_FIELDS = /* @__PURE__ */ new Set([
199
+ "error",
200
+ "decision",
201
+ "reasons",
202
+ "verify_url",
203
+ "session_id",
204
+ "poll_secret",
205
+ "poll_url",
206
+ "agent_instructions",
207
+ "agent_memory",
208
+ "claimed_operator",
209
+ "actual_signer_operator",
210
+ "expected_signer",
211
+ "actual_signer",
212
+ "linked_wallets"
213
+ ]);
214
+ function denialReasonToBody(reason) {
215
+ const message = reason.message ?? DEFAULT_MESSAGES[reason.code];
216
+ const body = { error: { code: reason.code, message } };
217
+ if (reason.decision) body.decision = reason.decision;
218
+ if (reason.reasons) body.reasons = reason.reasons;
219
+ if (reason.verify_url) body.verify_url = reason.verify_url;
220
+ if (reason.session_id) body.session_id = reason.session_id;
221
+ if (reason.poll_secret) body.poll_secret = reason.poll_secret;
222
+ if (reason.poll_url) body.poll_url = reason.poll_url;
223
+ const instructions = reason.agent_instructions ?? DEFAULT_AGENT_INSTRUCTIONS[reason.code];
224
+ if (instructions) body.agent_instructions = instructions;
225
+ if (reason.agent_memory) body.agent_memory = reason.agent_memory;
226
+ if (reason.claimed_operator) body.claimed_operator = reason.claimed_operator;
227
+ if (reason.code === "wallet_signer_mismatch") body.actual_signer_operator = reason.actual_signer_operator ?? null;
228
+ if (reason.expected_signer) body.expected_signer = reason.expected_signer;
229
+ if (reason.actual_signer) body.actual_signer = reason.actual_signer;
230
+ if (reason.linked_wallets && reason.linked_wallets.length > 0) body.linked_wallets = reason.linked_wallets;
231
+ if (reason.extra) {
232
+ for (const [key, value] of Object.entries(reason.extra)) {
233
+ if (RESERVED_FIELDS.has(key)) {
234
+ console.warn(`[gate] onBeforeSession returned reserved field "${key}" \u2014 ignoring to preserve gate authority`);
235
+ continue;
236
+ }
237
+ body[key] = value;
238
+ }
239
+ }
240
+ return body;
241
+ }
242
+
123
243
  // src/core.ts
124
244
  var CANONICAL_AGENTSCORE_API = "https://api.agentscore.sh";
125
245
  var WALLET_SIGNER_MISMATCH_INSTRUCTIONS = JSON.stringify({
@@ -222,107 +342,6 @@ function readX402PaymentHeader(request) {
222
342
  return request.headers.get("payment-signature") ?? request.headers.get("x-payment") ?? void 0;
223
343
  }
224
344
 
225
- // src/_response.ts
226
- var WALLET_NOT_TRUSTED_INSTRUCTIONS = JSON.stringify({
227
- action: "contact_support",
228
- steps: [
229
- "The wallet's operator failed an UNFIXABLE compliance check (sanctions, age, or jurisdiction). `reasons` lists which: `sanctions_flagged` / `age_insufficient` / `jurisdiction_restricted`. KYC re-verification won't change the outcome \u2014 the policy denial is structural.",
230
- "Surface the denial to the user with the merchant's support contact. Do not retry the same merchant request; do not hand the user a verify_url (verification won't fix this code path).",
231
- "Fixable compliance reasons (`kyc_required`, `kyc_pending`, `kyc_failed`) do NOT land on this code \u2014 the gate auto-mints a verification session for those and returns `identity_verification_required` with poll endpoints, same shape as `missing_identity`. `jurisdiction_restricted` IS in the unfixable bucket because the API only emits it after KYC is verified (the user's KYC'd country is in the blocked list \u2014 re-doing KYC won't change the country)."
232
- ],
233
- user_message: "This purchase is denied by the merchant's compliance policy and cannot be resolved by re-verifying. Contact the merchant's support if you believe this is in error."
234
- });
235
- var PAYMENT_REQUIRED_INSTRUCTIONS = JSON.stringify({
236
- action: "contact_merchant",
237
- steps: [
238
- "The merchant's AgentScore tier does not include the assess feature, so agent identity cannot be evaluated. This is a merchant-side configuration gap \u2014 there is no agent-side recovery.",
239
- "Contact the merchant (their support channel \u2014 typically listed in /llms.txt or the OpenAPI servers metadata) and request they upgrade their AgentScore plan."
240
- ],
241
- user_message: "This merchant's identity gate is misconfigured (AgentScore tier doesn't support assess). Contact the merchant \u2014 there's nothing to fix on the agent side."
242
- });
243
- var IDENTITY_VERIFICATION_REQUIRED_FALLBACK_INSTRUCTIONS = JSON.stringify({
244
- action: "deliver_verify_url_and_poll",
245
- steps: [
246
- "Share verify_url with the user \u2014 they complete identity verification on AgentScore.",
247
- "If session_id + poll_secret are present in the body, poll poll_url every 5 seconds with header `X-Poll-Secret: <poll_secret>` until status=verified. The poll returns a one-time operator_token.",
248
- "Retry the original request with header `X-Operator-Token: <opc_...>`."
249
- ],
250
- user_message: "Identity verification is required. Visit verify_url, then poll poll_url for the operator token and retry."
251
- });
252
- var TOKEN_EXPIRED_FALLBACK_INSTRUCTIONS = JSON.stringify({
253
- action: "deliver_verify_url_and_poll",
254
- steps: [
255
- "The operator token is expired or revoked. AgentScore auto-mints a fresh verification session \u2014 complete it to receive a new opc_...",
256
- "Share verify_url with the user, then poll poll_url every 5 seconds with header `X-Poll-Secret: <poll_secret>` until status=verified. The poll returns a fresh one-time operator_token.",
257
- "Retry the original request with header `X-Operator-Token: <new_opc_...>`."
258
- ],
259
- user_message: "Operator token is expired or revoked. A new verification session has been minted \u2014 visit verify_url to refresh."
260
- });
261
- var DEFAULT_AGENT_INSTRUCTIONS = {
262
- wallet_not_trusted: WALLET_NOT_TRUSTED_INSTRUCTIONS,
263
- payment_required: PAYMENT_REQUIRED_INSTRUCTIONS,
264
- identity_verification_required: IDENTITY_VERIFICATION_REQUIRED_FALLBACK_INSTRUCTIONS,
265
- token_expired: TOKEN_EXPIRED_FALLBACK_INSTRUCTIONS
266
- };
267
- var DEFAULT_MESSAGES = {
268
- missing_identity: "No identity provided. Send X-Wallet-Address (wallet) or X-Operator-Token (credential).",
269
- identity_verification_required: "Identity verification is required to access this resource. Visit verify_url to complete KYC.",
270
- wallet_not_trusted: "The wallet does not meet the merchant compliance policy.",
271
- api_error: "AgentScore is unreachable. This is transient \u2014 retry in a few seconds.",
272
- payment_required: "AgentScore tier does not support assess. Contact support.",
273
- wallet_signer_mismatch: "Payment signer does not match the wallet claimed via X-Wallet-Address. The signer and the claimed wallet must both resolve to the same AgentScore operator.",
274
- wallet_auth_requires_wallet_signing: "X-Wallet-Address was sent with a rail that has no wallet signature (Stripe SPT / card). Switch to X-Operator-Token, or use a wallet-signing rail (Tempo MPP, x402).",
275
- token_expired: "The operator token is expired or revoked. A fresh verification session has been minted \u2014 visit verify_url to mint a new token.",
276
- invalid_credential: "The operator token is not recognized. Switch to a different stored token, or drop the header to bootstrap a fresh session."
277
- };
278
- var RESERVED_FIELDS = /* @__PURE__ */ new Set([
279
- "error",
280
- "decision",
281
- "reasons",
282
- "verify_url",
283
- "session_id",
284
- "poll_secret",
285
- "poll_url",
286
- "agent_instructions",
287
- "agent_memory",
288
- "claimed_operator",
289
- "actual_signer_operator",
290
- "expected_signer",
291
- "actual_signer",
292
- "linked_wallets"
293
- ]);
294
- function denialReasonToBody(reason) {
295
- const message = reason.message ?? DEFAULT_MESSAGES[reason.code];
296
- const body = { error: { code: reason.code, message } };
297
- if (reason.decision) body.decision = reason.decision;
298
- if (reason.reasons) body.reasons = reason.reasons;
299
- if (reason.verify_url) body.verify_url = reason.verify_url;
300
- if (reason.session_id) body.session_id = reason.session_id;
301
- if (reason.poll_secret) body.poll_secret = reason.poll_secret;
302
- if (reason.poll_url) body.poll_url = reason.poll_url;
303
- const instructions = reason.agent_instructions ?? DEFAULT_AGENT_INSTRUCTIONS[reason.code];
304
- if (instructions) body.agent_instructions = instructions;
305
- if (reason.agent_memory) body.agent_memory = reason.agent_memory;
306
- if (reason.claimed_operator) body.claimed_operator = reason.claimed_operator;
307
- if (reason.code === "wallet_signer_mismatch") body.actual_signer_operator = reason.actual_signer_operator ?? null;
308
- if (reason.expected_signer) body.expected_signer = reason.expected_signer;
309
- if (reason.actual_signer) body.actual_signer = reason.actual_signer;
310
- if (reason.linked_wallets && reason.linked_wallets.length > 0) body.linked_wallets = reason.linked_wallets;
311
- if (reason.code === "api_error" && !(reason.extra && reason.extra.next_steps)) {
312
- body.next_steps = { action: "retry", retry_after_seconds: 5 };
313
- }
314
- if (reason.extra) {
315
- for (const [key, value] of Object.entries(reason.extra)) {
316
- if (RESERVED_FIELDS.has(key)) {
317
- console.warn(`[gate] onBeforeSession returned reserved field "${key}" \u2014 ignoring to preserve gate authority`);
318
- continue;
319
- }
320
- body[key] = value;
321
- }
322
- }
323
- return body;
324
- }
325
-
326
345
  // src/identity/a2a.ts
327
346
  var PROTOCOL_VERSION = "1.0";
328
347
  var CARD_VERSION = 1;